diff --git a/mythtv/configure b/mythtv/configure index 7b103ebec31..6cf1b547394 100755 --- a/mythtv/configure +++ b/mythtv/configure @@ -235,7 +235,6 @@ Component options: --disable-pthreads disable pthreads [auto] --disable-w32threads disable Win32 threads [auto] --disable-os2threads disable OS/2 threads [auto] - --enable-x11grab enable X11 grabbing [no] --disable-network disable network support [no] --disable-dct disable DCT code --disable-dwt disable DWT code @@ -244,10 +243,12 @@ Component options: --disable-mdct disable MDCT code --disable-rdft disable RDFT code --disable-fft disable FFT code - --enable-dxva2 enable DXVA2 code - --enable-vaapi enable VAAPI code [autodetect] - --enable-vda enable VDA code [autodetect] - --enable-vdpau enable VDPAU code [autodetect] + +Hardware accelerators: + --disable-dxva2 disable DXVA2 code [autodetect] + --enable-vaapi enable VAAPI code + --enable-vda enable VDA code + --disable-vdpau disable VDPAU code [autodetect] Individual component options: --disable-everything disable all components listed below @@ -288,10 +289,11 @@ Individual component options: 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-libaacplus enable AAC+ encoding via libaacplus [no] --enable-libass enable libass subtitles rendering [no] --enable-libbluray enable BluRay reading using libbluray [no] @@ -330,14 +332,15 @@ External library support: --enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no] --enable-libvorbis enable Vorbis en/decoding via libvorbis, native implementation exists [no] - --enable-libvpx enable VP8 de/encoding via libvpx [no] + --enable-libvpx enable VP8 and VP9 de/encoding via libvpx [no] --enable-libx264 enable H.264 encoding via x264 [no] --enable-libxavs enable AVS encoding via xavs [no] --enable-libxvid enable Xvid encoding via xvidcore, native MPEG-4/Xvid encoder exists [no] --enable-openal enable OpenAL 1.1 capture support [no] --enable-openssl enable openssl [no] - --enable-zlib enable zlib [autodetect] + --enable-x11grab enable X11 grabbing [no] + --disable-zlib disable zlib [autodetect] Advanced options (experts only): --cross-prefix=PREFIX use PREFIX for compilation tools [$cross_prefix] @@ -358,6 +361,7 @@ Advanced options (experts only): --ld=LD use linker LD [$ld_default] --host-cc=HOSTCC use host C compiler HOSTCC --host-cflags=HCFLAGS use HCFLAGS when compiling for host + --host-cppflags=HCPPFLAGS use HCPPFLAGS when compiling for host --host-ld=HOSTLD use host linker HOSTLD --host-ldflags=HLDFLAGS use HLDFLAGS when linking for host --host-libs=HLIBS use libs HLIBS when linking for host @@ -557,14 +561,18 @@ set_weak(){ done } +sanitize_var_name(){ + echo $@ | sed 's/[^A-Za-z0-9_]/_/g' +} + set_safe(){ var=$1 shift - eval $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')='$*' + eval $(sanitize_var_name "$var")='$*' } get_safe(){ - eval echo \$$(echo "$1" | sed 's/[^A-Za-z0-9_]/_/g') + eval echo \$$(sanitize_var_name "$1") } pushvar(){ @@ -802,6 +810,10 @@ add_extralibs(){ prepend extralibs $($ldflags_filter "$@") } +add_host_cppflags(){ + append host_cppflags "$@" +} + add_host_cflags(){ append host_cflags $($host_cflags_filter "$@") } @@ -1124,7 +1136,7 @@ check_type(){ } check_struct(){ - log check_type "$@" + log check_struct "$@" headers=$1 struct=$2 member=$3 @@ -1134,6 +1146,16 @@ check_struct(){ enable_safe "${struct}_${member}" } +check_builtin(){ + log check_builtin "$@" + name=$1 + headers=$2 + builtin=$3 + shift 3 + disable "$name" + check_code ld "$headers" "$builtin" "cc" "$@" && enable "$name" +} + require(){ name="$1" header="$2" @@ -1176,6 +1198,13 @@ check_host_cc(){ check_cmd $host_cc $host_cflags "$@" $HOSTCC_C $(hostcc_o $TMPO) $TMPC } +check_host_cppflags(){ + log check_host_cppflags "$@" + check_host_cc "$@" </dev/null | grep -q Intel; then + elif $_cc --version 2>/dev/null | grep -q ^icc; then _type=icc _ident=$($_cc --version | head -n1) _depflags='-MMD' @@ -3999,16 +4081,9 @@ case $target_os in add_cxxppflags -D_XOPEN_SOURCE=600 ;; openbsd|bitrig) - append CCONFIG "openbsd" - # On OpenBSD 4.5. the compiler does not use PIC unless - # explicitly using -fPIC. FFmpeg builds fine without PIC, - # however the generated executable will not do anything - # (simply quits with exit-code 1, no crash, no output). - # Thus explicitly enable PIC here. - enable pic disable symver SHFLAGS='-shared' - SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBVERSION)' + SLIB_INSTALL_NAME='$(SLIBNAME).$(LIBMAJOR).$(LIBMINOR)' SLIB_INSTALL_LINKS= oss_indev_extralibs="-lossaudio" oss_outdev_extralibs="-lossaudio" @@ -4242,7 +4317,6 @@ case $target_os in network_extralibs='-lbsd' exeobjs=compat/plan9/main.o disable ffserver - ln_s='ln -s -f' cp_f='cp' ;; none) @@ -4254,26 +4328,29 @@ esac # determine libc flavour +# uclibc defines __GLIBC__, so it needs to be checked before glibc. if check_cpp_condition features.h "defined __UCLIBC__"; then libc_type=uclibc add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 elif check_cpp_condition features.h "defined __GLIBC__"; then libc_type=glibc add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 +# MinGW headers can be installed on Cygwin, so check for newlib first. +elif check_cpp_condition newlib.h "defined _NEWLIB_VERSION"; then + libc_type=newlib + add_cppflags -U__STRICT_ANSI__ elif check_header _mingw.h; then libc_type=mingw check_cpp_condition _mingw.h \ "defined (__MINGW64_VERSION_MAJOR) || (__MINGW32_MAJOR_VERSION > 3) || \ (__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION >= 15)" || die "ERROR: MinGW runtime version must be >= 3.15." + add_cppflags -U__STRICT_ANSI__ if check_cpp_condition _mingw.h "defined(__MINGW64_VERSION_MAJOR) && \ __MINGW64_VERSION_MAJOR < 3"; then add_compat msvcrt/snprintf.o add_cflags "-include $source_path/compat/msvcrt/snprintf.h" fi -elif check_cpp_condition newlib.h "defined _NEWLIB_VERSION"; then - libc_type=newlib - add_cppflags -U__STRICT_ANSI__ elif check_func_headers stdlib.h _get_doserrno; then libc_type=msvcrt add_compat strtod.o strtod=avpriv_strtod @@ -4537,9 +4614,8 @@ elif enabled sparc; then elif enabled x86; then - check_code ld intrin.h "__rdtsc()" "cc" && enable rdtsc - - check_code ld mmintrin.h "_mm_empty()" "cc" && enable mm_empty + check_builtin rdtsc intrin.h "__rdtsc()" + check_builtin mm_empty mmintrin.h "_mm_empty()" enable local_aligned_8 local_aligned_16 @@ -4802,6 +4878,7 @@ 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 @@ -4823,12 +4900,16 @@ check_func_headers sys/time.h gettimeofday # check for VDA header if ! disabled vda && ! enabled ppc; then - if check_header VideoDecodeAcceleration/VDADecoder.h; then - enable vda - add_extralibs -framework CoreFoundation -framework VideoDecodeAcceleration -framework QuartzCore - fi + check_header VideoDecodeAcceleration/VDADecoder.h && enable vda fi +# check for VAAPI lib +if ! disabled vaapi; then + check_lib va/va.h vaInitialize -lva && enable vaapi +fi + +#End MythTV check + if ! disabled w32threads && ! enabled pthreads; then check_func_headers "windows.h process.h" _beginthreadex && enable w32threads fi @@ -4900,7 +4981,7 @@ enabled libudev && check_lib2 libudev.h udev_new -ludev || disable libudev check_lib math.h sin -lm && LIBM="-lm" disabled crystalhd || check_lib libcrystalhd/libcrystalhd_if.h DtsCrystalHDVersion -lcrystalhd || disable crystalhd -disabled vaapi || check_lib va/va.h vaInitialize -lva +enabled vaapi && require vaapi va/va.h vaInitialize -lva atan2f_args=2 ldexpf_args=2 @@ -4928,7 +5009,9 @@ enabled libfdk_aac && require libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen -lfdk- 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_pkg_config freetype2 "ft2build.h freetype/freetype.h" FT_Init_FreeType -enabled libgsm && require libgsm gsm/gsm.h gsm_create -lgsm +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 @@ -4958,10 +5041,12 @@ enabled libvo_aacenc && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -l 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_decoder && { check_lib2 "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_dec_init_ver -lvpx || - die "ERROR: libvpx decoder must be installed and version must be >=0.9.1"; } - enabled libvpx_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_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 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 libx264 && require libx264 x264.h x264_encoder_encode -lx264 && { check_cpp_condition x264.h "X264_BUILD >= 118" || die "ERROR: libx264 must be installed and version must be >= 0.118."; } @@ -5145,13 +5230,16 @@ fi enable audio_jack || disable audio_jack -enabled x11grab && -check_header X11/Xlib.h && -check_header X11/extensions/XShm.h && -check_header X11/extensions/Xfixes.h && -check_func XOpenDisplay -lX11 && -check_func XShmCreateImage -lX11 -lXext && -check_func XFixesGetCursorImage -lX11 -lXext -lXfixes +if enabled dxva2; then + enabled dxva2api_h && enabled windows || disable dxva2 +else + disable dxva2 +fi + +enabled x11grab && +require X11 X11/Xlib.h XOpenDisplay -lX11 && +require Xext X11/extensions/XShm.h XShmCreateImage -lXext && +require Xfixes X11/extensions/Xfixes.h XFixesGetCursorImage -lXfixes if ! disabled vaapi; then check_lib va/va.h vaInitialize -lva && { @@ -5160,16 +5248,12 @@ if ! disabled vaapi; then } || disable vaapi fi -if ! disabled vdpau && enabled vdpau_vdpau_h; then +enabled vdpau && check_cpp_condition vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" || - { echolog "Please upgrade to libvdpau >= 0.2 if you would like vdpau support." && disable vdpau; } -fi + disable vdpau -if enabled dxva2; then - enabled dxva2api_h && enabled windows || disable dxva2 -else - disable dxva2 -fi +# 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" enabled debug && add_cxxflags -g"$debuglevel" @@ -5507,12 +5591,13 @@ if enabled icc; then 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 @@ -5526,8 +5611,6 @@ if enabled icc; then # -wd: Disable the following warnings for MythTV # 10159: ignore invalid argument for option '-m' check_ldflags -wd10159 - # Allow to compile with optimizations - check_ldflags -march=$cpu # icc 11.0 and 11.1 work with ebp_available, but don't pass the test enable ebp_available if enabled x86_32; then @@ -5797,52 +5880,6 @@ 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 "libdxva2 enabled ${dxva2-no}" -echo "libva enabled ${vaapi-no}" -echo "libvdpau enabled ${vdpau-no}" -echo "AVISynth enabled ${avisynth-no}" -echo "frei0r enabled ${frei0r-no}" -echo "gnutls enabled ${gnutls-no}" -echo "libaacplus enabled ${libaacplus-no}" -echo "libass enabled ${libass-no}" -echo "libcaca enabled ${libcaca-no}" -echo "libcdio support ${libcdio-no}" -echo "libcelt enabled ${libcelt-no}" -echo "libdc1394 support ${libdc1394-no}" -echo "libfaac enabled ${libfaac-no}" -echo "libfdk-aac enabled ${libfdk_aac-no}" -echo "libgsm enabled ${libgsm-no}" -echo "libiec61883 support ${libiec61883-no}" -echo "libilbc enabled ${libilbc-no}" -echo "libmodplug enabled ${libmodplug-no}" -echo "libmp3lame enabled ${libmp3lame-no}" -echo "libnut enabled ${libnut-no}" -echo "libopencore-amrnb support ${libopencore_amrnb-no}" -echo "libopencore-amrwb support ${libopencore_amrwb-no}" -echo "libopencv support ${libopencv-no}" -echo "libopenjpeg enabled ${libopenjpeg-no}" -echo "libopus enabled ${libopus-no}" -echo "libpulse enabled ${libpulse-no}" -echo "librtmp enabled ${librtmp-no}" -echo "libschroedinger enabled ${libschroedinger-no}" -echo "libsoxr enabled ${libsoxr-no}" -echo "libspeex enabled ${libspeex-no}" -echo "libstagefright-h264 enabled ${libstagefright_h264-no}" -echo "libtheora enabled ${libtheora-no}" -echo "libtwolame enabled ${libtwolame-no}" -echo "libutvideo enabled ${libutvideo-no}" -echo "libv4l2 enabled ${libv4l2-no}" -echo "libvo-aacenc support ${libvo_aacenc-no}" -echo "libvo-amrwbenc support ${libvo_amrwbenc-no}" -echo "libvorbis enabled ${libvorbis-no}" -echo "libvpx enabled ${libvpx-no}" -echo "libx264 enabled ${libx264-no}" -echo "libxavs enabled ${libxavs-no}" -echo "libxvid enabled ${libxvid-no}" -echo "openal enabled ${openal-no}" -echo "openssl enabled ${openssl-no}" -echo "zlib enabled ${zlib-no}" -echo "bzlib enabled ${bzlib-no}" echo "texi2html enabled ${texi2html-no}" echo "perl enabled ${perl-no}" echo "pod2man enabled ${pod2man-no}" @@ -5851,10 +5888,14 @@ test -n "$random_seed" && echo "random seed ${random_seed}" echo +echo "External libraries:" +print_enabled '' $EXTERNAL_LIBRARY_LIST | print_3_columns +echo + for type in decoder encoder hwaccel parser demuxer muxer protocol filter bsf indev outdev; do echo "Enabled ${type}s:" eval list=\$$(toupper $type)_LIST - print_enabled '_*' $list | sort | pr -r -3 -t + print_enabled '_*' $list | print_3_columns echo done @@ -5960,6 +6001,7 @@ fi echo "OpenGL video ${opengl_video-no}" if test x"$target_os" = x"darwin" ; then echo "Quartz video ${quartz_video-no}" + echo "VDA support ${vda-no}" fi if test x"$target_os" = x"mingw32" ; then echo "Windows (Direct3D) yes" @@ -6066,7 +6108,7 @@ CXXPPFLAGS=$CXXPPFLAGS ECXXFLAGS=$ECXXFLAGS LDFLAGS=$LDFLAGS LDFLAGS-ffserver=$FFSERVERLDFLAGS -#SHFLAGS=$SHFLAGS +#SHFLAGS=$(echo $($ldflags_filter $SHFLAGS)) YASMFLAGS=$YASMFLAGS BUILDSUF=$build_suffix PROGSSUF=$progs_suffix @@ -6088,6 +6130,7 @@ AS_DEPFLAGS=$AS_DEPFLAGS HOSTCC=$host_cc HOSTLD=$host_ld HOSTCFLAGS=$host_cflags +HOSTCPPFLAGS=$host_cppflags HOSTEXESUF=$HOSTEXESUF HOSTLDFLAGS=$host_ldflags HOSTLIBS=$host_libs @@ -6134,6 +6177,7 @@ get_version(){ eval ${name}_VERSION=\$${name}_VERSION_MAJOR.\$${name}_VERSION_MINOR.\$${name}_VERSION_MICRO eval echo "${lcname}_VERSION=\$${name}_VERSION" >> $TMPMAK eval echo "${lcname}_VERSION_MAJOR=\$${name}_VERSION_MAJOR" >> $TMPMAK + eval echo "${lcname}_VERSION_MINOR=\$${name}_VERSION_MINOR" >> TMPMAK } map 'get_version $v' $LIBRARY_LIST diff --git a/mythtv/external/FFmpeg/.gitignore b/mythtv/external/FFmpeg/.gitignore index fd85465af80..8473008a936 100644 --- a/mythtv/external/FFmpeg/.gitignore +++ b/mythtv/external/FFmpeg/.gitignore @@ -37,6 +37,7 @@ /doc/examples/filtering_video /doc/examples/metadata /doc/examples/muxing +/doc/examples/pc-uninstalled /doc/examples/resampling_audio /doc/examples/scaling_video /doc/fate.txt @@ -66,5 +67,6 @@ /tools/probetest /tools/qt-faststart /tools/trasher +/tools/seek_print /mythffprobe /mythffserver diff --git a/mythtv/external/FFmpeg/CREDITS b/mythtv/external/FFmpeg/CREDITS index 1d0666b6df3..e29f0b853c9 100644 --- a/mythtv/external/FFmpeg/CREDITS +++ b/mythtv/external/FFmpeg/CREDITS @@ -1,55 +1,6 @@ -This file contains the names of some of the people who have contributed to -FFmpeg. The names are sorted alphabetically by last name. As this file is -currently quite outdated and git serves as a much better tool for determining -authorship, it remains here for historical reasons only. +See the Git history of the project (git://source.ffmpeg.org/ffmpeg) to +get the names of people who have contributed to FFmpeg. -Dénes Balatoni -Michel Bardiaux -Fabrice Bellard -Patrice Bensoussan -Alex Beregszaszi -BERO -Thilo Borgmann -Mario Brito -Ronald Bultje -Alex Converse -Maarten Daniels -Reimar Doeffinger -Tim Ferguson -Brian Foley -Arpad Gereoffy -Philip Gladstone -Vladimir Gneushev -Roine Gustafsson -David Hammerton -Wolfgang Hesseler -Marc Hoffman -Falk Hueffner -Aurélien Jacobs -Steven Johnson -Zdenek Kabelac -Robin Kay -Todd Kirby -Nick Kurshev -Benjamin Larsson -Loïc Le Loarer -Daniel Maas -Mike Melanson -Loren Merritt -Jeff Muizelaar -Michael Niedermayer -François Revol -Peter Ross -Måns Rullgård -Stefano Sabatini -Roman Shaposhnik -Oded Shimon -Dieter Shirley -Konstantin Shishkov -Juan J. Sierralta -Ewald Snel -Sascha Sommer -Leon van Stuivenberg -Roberto Togni -Lionel Ulmer -Reynaldo Verdejo +To check the log, you can type the command "git log" in the FFmpeg +source directory, or browse the online repository at +http://source.ffmpeg.org. diff --git a/mythtv/external/FFmpeg/Changelog b/mythtv/external/FFmpeg/Changelog index b97bdf0eb15..020f5f12712 100644 --- a/mythtv/external/FFmpeg/Changelog +++ b/mythtv/external/FFmpeg/Changelog @@ -1,71 +1,29 @@ Entries are sorted chronologically from oldest to youngest within each release, releases are sorted from youngest to oldest. -version : -- h264: fix deadlocks with broken/fuzzed files -- flvdec: make decoder more robust -- vorbisdec: fix buffer overflow (CVE-2013-0894) -- ac3dec: validate channel output mode against channel count -- doc: minor improvements -- loco: check that there is data left after decoding a plane. -- mov: use the format context for logging. -- lagarith: avoid infinite loop in lag_rac_refill() with corrupted files -- flicvideo: avoid an infinite loop in byte run compression -- av_memcpy_backptr: avoid an infinite loop for back = 0 -- mlpdec: do not try to allocate a zero-sized output buffer. -- qtrle: add more checks against pixel_ptr being negative. -- 4xm: check the return value of read_huffman_tables(). -- cavs: initialize various context tables, avoids crashes with corrupted files -- x86/H.264: Don't use redzone in AVX h264_deblock on Win64 -- VQA video: check chunk sizes before reading chunks -- RoQ video decoder: check dimensions validity -- QDM2: check array index before use, fix out of array accesses -- mpegvideo: Do REBASE_PICTURE with byte pointers -- SVQ3: unbreak decoding -- libopencore-amrwb: Make AMR-WB ifdeffery more precise -- libopencore-amr: Conditionally compile decoder and encoder bits -- arm: Fall back to runtime cpu feature detection via /proc/cpuinfo -- xxan: properly handle odd heights -- msrledec: check bounds before constructing a possibly invalid pointer, -- qtrle: fix the topmost line for 1bit -- aasc: fix output for msrle compression -- yop: check for input overreads -- yop: check that extradata is large enough -- fraps: fix off-by one bug for version 1 -- vf_delogo: fix copying the input frame -- vf_delogo: fix an uninitialized read -- dnxhdenc: fix invalid reads in dnxhd_mb_var_thread() -- ATRAC3: use correct loop variable in add_tonal_components() -- MLP: store the channel layout for each substream -- MLP decoder: TrueHD: use Libav channel order -- x86: ac3: Fix HAVE_MMXEXT condition to only refer to external assembly -- arm: vp8: Fix the plain-armv6 version of vp8_luma_dc_wht -- lavr: call mix_function_init() in ff_audio_mix_set_matrix() -- rtpenc_chain: Use the original AVFormatContext for getting payload type -- rtp: Make sure the output format pointer is set -- rtp: Make sure priv_data is set before reading it -- videodsp_armv5te: remove #if HAVE_ARMV5TE_EXTERNAL -- get_bits: change the failure condition in init_get_bits -- mpegvideo: fix loop condition in draw_line() -- fate: update ref after rv30_loop_filter fix -- RV30: fix masking in rv30_loop_filter() -- libcdio: support recent cdio-paranoia -- Theora: Skip zero-sized headers -- H.264: add 3 pixels below for subpixel filter wait position -- H.264: fix ff_generate_sliding_window_mmcos() prototype -- H.264: don't clobber mmco opcode tables for non-first slice headers -- libx264: use the library specific default rc_initial_buffer_occupancy -- lavc: set the default rc_initial_buffer_occupancy -- lavc: introduce the convenience function init_get_bits8 -- lavc: check for overflow in init_get_bits -- configure: enable pic for shared libs on AArch64 -- zmbv: Reset the decoder on keyframe errors -- VC1 decoder: prevent a crash due missing pred_flag parameter -- matroska: Fix use after free -- VP3: Fix double free in vp3_decode_end() -- Fix a crash on windows platforms related to automatic stack alignment - in libavresample -- Fix memleaks in the Ogg demuxer. Related to CVE-2012-2882 +version 1.2: + +- VDPAU hardware acceleration through normal hwaccel +- SRTP support +- Error diffusion dither in Swscale +- Chained Ogg support +- Theora Midstream reconfiguration support +- EVRC decoder +- audio fade filter +- filtering audio with unknown channel layout +- allpass, bass, bandpass, bandreject, biquad, equalizer, highpass, lowpass + and treble audio filter +- improved showspectrum filter, with multichannel support and sox-like colors +- histogram filter +- tee muxer +- il filter ported from libmpcodecs +- support ID3v2 tags in ASF files +- encrypted TTA stream decoding support +- RF64 support in WAV muxer +- noise filter ported from libmpcodecs +- Subtitles character encoding conversion +- blend filter +- stereo3d filter ported from libmpcodecs version 1.1: diff --git a/mythtv/external/FFmpeg/LICENSE b/mythtv/external/FFmpeg/LICENSE index 9665a2472aa..38b1a5dd6cb 100644 --- a/mythtv/external/FFmpeg/LICENSE +++ b/mythtv/external/FFmpeg/LICENSE @@ -36,13 +36,20 @@ Specifically, the GPL parts of FFmpeg are - vf_hue.c - vf_kerndeint.c - vf_mp.c + - vf_noise.c - vf_pp.c - vf_smartblur.c + - vf_stereo3d.c - vf_super2xsai.c - vf_tinterlace.c - vf_yadif.c - vsrc_mptestsrc.c +Should you, for whatever reason, prefer to use version 3 of the (L)GPL, then +the configure parameter --enable-version3 will activate this licensing option +for you. Read the file COPYING.LGPLv3 or, if you have enabled GPL parts, +COPYING.GPLv3 to learn the exact legal terms that apply in this case. + There are a handful of files under other licensing terms, namely: * The files libavcodec/jfdctfst.c, libavcodec/jfdctint_template.c and @@ -52,11 +59,6 @@ There are a handful of files under other licensing terms, namely: You must also indicate any changes including additions and deletions to those three files in the documentation. -Should you, for whatever reason, prefer to use version 3 of the (L)GPL, then -the configure parameter --enable-version3 will activate this licensing option -for you. Read the file COPYING.LGPLv3 or, if you have enabled GPL parts, -COPYING.GPLv3 to learn the exact legal terms that apply in this case. - external libraries ================== diff --git a/mythtv/external/FFmpeg/MAINTAINERS b/mythtv/external/FFmpeg/MAINTAINERS index b2bccb21594..32efcab3a30 100644 --- a/mythtv/external/FFmpeg/MAINTAINERS +++ b/mythtv/external/FFmpeg/MAINTAINERS @@ -449,7 +449,6 @@ Releases 1.1 Michael Niedermayer 1.0 Michael Niedermayer -If you want to maintain an older release, please contact us GnuPG Fingerprints of maintainers and contributors diff --git a/mythtv/external/FFmpeg/README.sync b/mythtv/external/FFmpeg/README.sync index d5a1ac60971..6d47cecdbe6 100644 --- a/mythtv/external/FFmpeg/README.sync +++ b/mythtv/external/FFmpeg/README.sync @@ -9,6 +9,7 @@ git://source.ffmpeg.org/ffmpeg.git at SHA1 553c9c77 on December 16th, 2012 (jya) git://source.ffmpeg.org/ffmpeg.git at SHA1 057051b8 on February 17th, 2013 (jya) (release/1.1 branch) git://source.ffmpeg.org/ffmpeg.git at SHA1 7c8beec4 on March 7th, 2013 (jya) (release/1.1 branch) git://source.ffmpeg.org/ffmpeg.git at SHA1 fc7071cb on March 30th, 2013 (jya) (release/1.1 branch) +git://source.ffmpeg.org/ffmpeg.git at SHA1 33d699a4 on May 12th, 2013 (jya) (release/1.2 branch) List of files modified from original FFmpeg: Makefile @@ -50,7 +51,7 @@ libavformat/mpegts.c libavformat/mpegts.h libavformat/utils-mythtv.c <- new file libavformat/utils.c -libavformat/rtpdec.c <- header change +libavformat/rtpdec_mpegts.c <- header change libavformat/rtsp.c <- header change libavformat/wtvdec.c <- header change libavutil/bswap.h diff --git a/mythtv/external/FFmpeg/RELEASE b/mythtv/external/FFmpeg/RELEASE index 65087b4f5ec..6085e946503 100644 --- a/mythtv/external/FFmpeg/RELEASE +++ b/mythtv/external/FFmpeg/RELEASE @@ -1 +1 @@ -1.1.4 +1.2.1 diff --git a/mythtv/external/FFmpeg/VERSION b/mythtv/external/FFmpeg/VERSION index 65087b4f5ec..6085e946503 100644 --- a/mythtv/external/FFmpeg/VERSION +++ b/mythtv/external/FFmpeg/VERSION @@ -1 +1 @@ -1.1.4 +1.2.1 diff --git a/mythtv/external/FFmpeg/cmdutils.c b/mythtv/external/FFmpeg/cmdutils.c index d44050fe6f3..2668ee14867 100644 --- a/mythtv/external/FFmpeg/cmdutils.c +++ b/mythtv/external/FFmpeg/cmdutils.c @@ -62,8 +62,8 @@ static int init_report(const char *env); struct SwsContext *sws_opts; -SwrContext *swr_opts; -AVDictionary *format_opts, *codec_opts; +AVDictionary *swr_opts; +AVDictionary *format_opts, *codec_opts, *resample_opts; const int this_year = 2013; @@ -75,9 +75,6 @@ void init_opts(void) if(CONFIG_SWSCALE) sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC, NULL, NULL, NULL); - - if(CONFIG_SWRESAMPLE) - swr_opts = swr_alloc(); } void uninit_opts(void) @@ -87,11 +84,10 @@ void uninit_opts(void) sws_opts = NULL; #endif - if(CONFIG_SWRESAMPLE) - swr_free(&swr_opts); - + av_dict_free(&swr_opts); av_dict_free(&format_opts); av_dict_free(&codec_opts); + av_dict_free(&resample_opts); } void log_callback_help(void *ptr, int level, const char *fmt, va_list vl) @@ -478,6 +474,9 @@ int opt_default(void *optctx, const char *opt, const char *arg) char opt_stripped[128]; const char *p; const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class(); +#if CONFIG_AVRESAMPLE + const AVClass *rc = avresample_get_class(); +#endif const AVClass *sc, *swr_class; if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug")) @@ -516,13 +515,23 @@ int opt_default(void *optctx, const char *opt, const char *arg) #endif #if CONFIG_SWRESAMPLE swr_class = swr_get_class(); - if (!consumed && av_opt_find(&swr_class, opt, NULL, 0, - AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) { - int ret = av_opt_set(swr_opts, opt, arg, 0); + if (!consumed && (o=av_opt_find(&swr_class, opt, NULL, 0, + AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { + struct SwrContext *swr = swr_alloc(); + int ret = av_opt_set(swr, opt, arg, 0); + swr_free(&swr); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt); return ret; } + av_dict_set(&swr_opts, opt, arg, FLAGS); + consumed = 1; + } +#endif +#if CONFIG_AVRESAMPLE + if ((o=av_opt_find(&rc, opt, NULL, 0, + AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { + av_dict_set(&resample_opts, opt, arg, FLAGS); consumed = 1; } #endif @@ -575,9 +584,11 @@ static void finish_group(OptionParseContext *octx, int group_idx, g->swr_opts = swr_opts; g->codec_opts = codec_opts; g->format_opts = format_opts; + g->resample_opts = resample_opts; codec_opts = NULL; format_opts = NULL; + resample_opts = NULL; #if CONFIG_SWSCALE sws_opts = NULL; #endif @@ -635,11 +646,11 @@ void uninit_parse_context(OptionParseContext *octx) av_freep(&l->groups[j].opts); av_dict_free(&l->groups[j].codec_opts); av_dict_free(&l->groups[j].format_opts); + av_dict_free(&l->groups[j].resample_opts); #if CONFIG_SWSCALE sws_freeContext(l->groups[j].sws_opts); #endif - if(CONFIG_SWRESAMPLE) - swr_free(&l->groups[j].swr_opts); + av_dict_free(&l->groups[j].swr_opts); } av_freep(&l->groups); } @@ -656,6 +667,7 @@ int split_commandline(OptionParseContext *octx, int argc, char *argv[], const OptionGroupDef *groups, int nb_groups) { int optindex = 1; + int dashdash = -2; /* perform system-dependent conversions for arguments list */ prepare_app_arguments(&argc, &argv); @@ -670,8 +682,12 @@ int split_commandline(OptionParseContext *octx, int argc, char *argv[], av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt); + if (opt[0] == '-' && opt[1] == '-' && !opt[2]) { + dashdash = optindex; + continue; + } /* unnamed group separators, e.g. output filename */ - if (opt[0] != '-' || !opt[1]) { + if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) { finish_group(octx, 0, opt); av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name); continue; @@ -743,7 +759,7 @@ do { \ return AVERROR_OPTION_NOT_FOUND; } - if (octx->cur_group.nb_opts || codec_opts || format_opts) + if (octx->cur_group.nb_opts || codec_opts || format_opts || resample_opts) av_log(NULL, AV_LOG_WARNING, "Trailing options were found on the " "commandline.\n"); @@ -1612,7 +1628,7 @@ int show_help(void *optctx, const char *opt, const char *arg) int read_yesno(void) { int c = getchar(); - int yesno = (toupper(c) == 'Y'); + int yesno = (av_toupper(c) == 'Y'); while (c != '\n' && c != EOF) c = getchar(); @@ -1733,10 +1749,8 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, if (!codec) codec = s->oformat ? avcodec_find_encoder(codec_id) : avcodec_find_decoder(codec_id); - if (!codec) - return NULL; - switch (codec->type) { + switch (st->codec->codec_type) { case AVMEDIA_TYPE_VIDEO: prefix = 'v'; flags |= AV_OPT_FLAG_VIDEO_PARAM; @@ -1848,12 +1862,6 @@ static int alloc_buffer(FrameBuffer **pool, AVCodecContext *s, FrameBuffer **pbu av_log(s, AV_LOG_ERROR, "alloc_buffer: av_image_alloc() failed\n"); return ret; } - /* XXX this shouldn't be needed, but some tests break without this line - * those decoders are buggy and need to be fixed. - * the following tests fail: - * cdgraphics, ansi - */ - memset(buf->base[0], 128, ret); avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) { diff --git a/mythtv/external/FFmpeg/cmdutils.h b/mythtv/external/FFmpeg/cmdutils.h index f193132f093..6341a2f1cbe 100644 --- a/mythtv/external/FFmpeg/cmdutils.h +++ b/mythtv/external/FFmpeg/cmdutils.h @@ -51,8 +51,8 @@ extern const int this_year; extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB]; extern AVFormatContext *avformat_opts; extern struct SwsContext *sws_opts; -extern struct SwrContext *swr_opts; -extern AVDictionary *format_opts, *codec_opts; +extern AVDictionary *swr_opts; +extern AVDictionary *format_opts, *codec_opts, *resample_opts; /** * Initialize the cmdutils option system, in particular @@ -123,7 +123,7 @@ double parse_number_or_die(const char *context, const char *numstr, int type, * not zero timestr is interpreted as a duration, otherwise as a * date * - * @see parse_date() + * @see av_parse_time() */ int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration); @@ -190,13 +190,13 @@ void show_help_options(const OptionDef *options, const char *msg, int req_flags, void show_help_children(const AVClass *class, int flags); /** - * Per-avtool specific help handler. Implemented in each - * avtool, called by show_help(). + * Per-fftool specific help handler. Implemented in each + * fftool, called by show_help(). */ void show_help_default(const char *opt, const char *arg); /** - * Generic -h handler common to all avtools. + * Generic -h handler common to all fftools. */ int show_help(void *optctx, const char *opt, const char *arg); @@ -253,8 +253,9 @@ typedef struct OptionGroup { AVDictionary *codec_opts; AVDictionary *format_opts; + AVDictionary *resample_opts; struct SwsContext *sws_opts; - struct SwrContext *swr_opts; + AVDictionary *swr_opts; } OptionGroup; /** diff --git a/mythtv/external/FFmpeg/common.mak b/mythtv/external/FFmpeg/common.mak index 8c3d0b3decc..130f1327b01 100644 --- a/mythtv/external/FFmpeg/common.mak +++ b/mythtv/external/FFmpeg/common.mak @@ -32,7 +32,7 @@ ASFLAGS := $(CPPFLAGS) $(ASFLAGS) CXXFLAGS += $(CPPFLAGS) $(CFLAGS) YASMFLAGS += $(IFLAGS:%=%/) -Pconfig.asm -HOSTCCFLAGS = $(IFLAGS) $(HOSTCFLAGS) +HOSTCCFLAGS = $(IFLAGS) $(HOSTCPPFLAGS) $(HOSTCFLAGS) LDFLAGS := $(ALLFFLIBS:%=$(LD_PATH)lib%) $(LDFLAGS) define COMPILE @@ -117,12 +117,12 @@ $(HOSTPROGS): %$(HOSTEXESUF): %.o $(HOSTLD) $(HOSTLDFLAGS) $(HOSTLD_O) $< $(HOSTLIBS) $(OBJS): | $(sort $(dir $(OBJS))) +$(HOBJS): | $(sort $(dir $(HOBJS))) $(HOSTOBJS): | $(sort $(dir $(HOSTOBJS))) $(TESTOBJS): | $(sort $(dir $(TESTOBJS))) -$(HOBJS): | $(sort $(dir $(HOBJS))) $(TOOLOBJS): | tools -OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOSTOBJS) $(TESTOBJS) $(HOBJS)) +OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(TESTOBJS)) CLEANSUFFIXES = *.d *.o *~ *.h.c *.map *.ver *.ho *.gcno *.gcda DISTCLEANSUFFIXES = *.pc diff --git a/mythtv/external/FFmpeg/compat/strtod.c b/mythtv/external/FFmpeg/compat/strtod.c index d0f9b3d41bd..3a9452eac2b 100644 --- a/mythtv/external/FFmpeg/compat/strtod.c +++ b/mythtv/external/FFmpeg/compat/strtod.c @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include #include @@ -49,7 +48,7 @@ double avpriv_strtod(const char *nptr, char **endptr) double res; /* Skip leading spaces */ - while (isspace(*nptr)) + while (av_isspace(*nptr)) nptr++; if (!av_strncasecmp(nptr, "infinity", 8)) { diff --git a/mythtv/external/FFmpeg/configure b/mythtv/external/FFmpeg/configure index 5361855c500..4df96dc764a 100755 --- a/mythtv/external/FFmpeg/configure +++ b/mythtv/external/FFmpeg/configure @@ -130,7 +130,6 @@ Component options: --disable-pthreads disable pthreads [auto] --disable-w32threads disable Win32 threads [auto] --disable-os2threads disable OS/2 threads [auto] - --enable-x11grab enable X11 grabbing [no] --disable-network disable network support [no] --disable-dct disable DCT code --disable-dwt disable DWT code @@ -139,10 +138,12 @@ Component options: --disable-mdct disable MDCT code --disable-rdft disable RDFT code --disable-fft disable FFT code - --enable-dxva2 enable DXVA2 code - --enable-vaapi enable VAAPI code [autodetect] - --enable-vda enable VDA code [autodetect] - --enable-vdpau enable VDPAU code [autodetect] + +Hardware accelerators: + --disable-dxva2 disable DXVA2 code [autodetect] + --enable-vaapi enable VAAPI code + --enable-vda enable VDA code + --disable-vdpau disable VDPAU code [autodetect] Individual component options: --disable-everything disable all components listed below @@ -183,10 +184,11 @@ Individual component options: 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-libaacplus enable AAC+ encoding via libaacplus [no] --enable-libass enable libass subtitles rendering [no] --enable-libbluray enable BluRay reading using libbluray [no] @@ -225,14 +227,15 @@ External library support: --enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no] --enable-libvorbis enable Vorbis en/decoding via libvorbis, native implementation exists [no] - --enable-libvpx enable VP8 de/encoding via libvpx [no] + --enable-libvpx enable VP8 and VP9 de/encoding via libvpx [no] --enable-libx264 enable H.264 encoding via x264 [no] --enable-libxavs enable AVS encoding via xavs [no] --enable-libxvid enable Xvid encoding via xvidcore, native MPEG-4/Xvid encoder exists [no] --enable-openal enable OpenAL 1.1 capture support [no] --enable-openssl enable openssl [no] - --enable-zlib enable zlib [autodetect] + --enable-x11grab enable X11 grabbing [no] + --disable-zlib disable zlib [autodetect] Advanced options (experts only): --cross-prefix=PREFIX use PREFIX for compilation tools [$cross_prefix] @@ -253,6 +256,7 @@ Advanced options (experts only): --ld=LD use linker LD [$ld_default] --host-cc=HOSTCC use host C compiler HOSTCC --host-cflags=HCFLAGS use HCFLAGS when compiling for host + --host-cppflags=HCPPFLAGS use HCPPFLAGS when compiling for host --host-ld=HOSTLD use host linker HOSTLD --host-ldflags=HLDFLAGS use HLDFLAGS when linking for host --host-libs=HLIBS use libs HLIBS when linking for host @@ -452,14 +456,18 @@ set_weak(){ done } +sanitize_var_name(){ + echo $@ | sed 's/[^A-Za-z0-9_]/_/g' +} + set_safe(){ var=$1 shift - eval $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')='$*' + eval $(sanitize_var_name "$var")='$*' } get_safe(){ - eval echo \$$(echo "$1" | sed 's/[^A-Za-z0-9_]/_/g') + eval echo \$$(sanitize_var_name "$1") } pushvar(){ @@ -697,6 +705,10 @@ add_extralibs(){ prepend extralibs $($ldflags_filter "$@") } +add_host_cppflags(){ + append host_cppflags "$@" +} + add_host_cflags(){ append host_cflags $($host_cflags_filter "$@") } @@ -1012,7 +1024,7 @@ check_type(){ } check_struct(){ - log check_type "$@" + log check_struct "$@" headers=$1 struct=$2 member=$3 @@ -1022,6 +1034,16 @@ check_struct(){ enable_safe "${struct}_${member}" } +check_builtin(){ + log check_builtin "$@" + name=$1 + headers=$2 + builtin=$3 + shift 3 + disable "$name" + check_code ld "$headers" "$builtin" "cc" "$@" && enable "$name" +} + require(){ name="$1" header="$2" @@ -1064,6 +1086,13 @@ check_host_cc(){ check_cmd $host_cc $host_cflags "$@" $HOSTCC_C $(hostcc_o $TMPO) $TMPC } +check_host_cppflags(){ + log check_host_cppflags "$@" + check_host_cc "$@" </dev/null | grep -q Intel; then + elif $_cc --version 2>/dev/null | grep -q ^icc; then _type=icc _ident=$($_cc --version | head -n1) _depflags='-MMD' @@ -3150,15 +3230,9 @@ case $target_os in enabled gcc || check_ldflags -Wl,-zmuldefs ;; openbsd|bitrig) - # On OpenBSD 4.5. the compiler does not use PIC unless - # explicitly using -fPIC. FFmpeg builds fine without PIC, - # however the generated executable will not do anything - # (simply quits with exit-code 1, no crash, no output). - # Thus explicitly enable PIC here. - enable pic disable symver SHFLAGS='-shared' - SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBVERSION)' + SLIB_INSTALL_NAME='$(SLIBNAME).$(LIBMAJOR).$(LIBMINOR)' SLIB_INSTALL_LINKS= oss_indev_extralibs="-lossaudio" oss_outdev_extralibs="-lossaudio" @@ -3222,7 +3296,6 @@ case $target_os in objformat="win32" ranlib=: enable dos_paths - add_cppflags -U__STRICT_ANSI__ ;; win32|win64) if enabled shared; then @@ -3337,7 +3410,6 @@ case $target_os in network_extralibs='-lbsd' exeobjs=compat/plan9/main.o disable ffserver - ln_s='ln -s -f' cp_f='cp' ;; none) @@ -3349,26 +3421,29 @@ esac # determine libc flavour +# uclibc defines __GLIBC__, so it needs to be checked before glibc. if check_cpp_condition features.h "defined __UCLIBC__"; then libc_type=uclibc add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 elif check_cpp_condition features.h "defined __GLIBC__"; then libc_type=glibc add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 +# MinGW headers can be installed on Cygwin, so check for newlib first. +elif check_cpp_condition newlib.h "defined _NEWLIB_VERSION"; then + libc_type=newlib + add_cppflags -U__STRICT_ANSI__ elif check_header _mingw.h; then libc_type=mingw check_cpp_condition _mingw.h \ "defined (__MINGW64_VERSION_MAJOR) || (__MINGW32_MAJOR_VERSION > 3) || \ (__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION >= 15)" || die "ERROR: MinGW runtime version must be >= 3.15." + add_cppflags -U__STRICT_ANSI__ if check_cpp_condition _mingw.h "defined(__MINGW64_VERSION_MAJOR) && \ __MINGW64_VERSION_MAJOR < 3"; then add_compat msvcrt/snprintf.o add_cflags "-include $source_path/compat/msvcrt/snprintf.h" fi -elif check_cpp_condition newlib.h "defined _NEWLIB_VERSION"; then - libc_type=newlib - add_cppflags -U__STRICT_ANSI__ elif check_func_headers stdlib.h _get_doserrno; then libc_type=msvcrt add_compat strtod.o strtod=avpriv_strtod @@ -3583,9 +3658,8 @@ elif enabled sparc; then elif enabled x86; then - check_code ld intrin.h "__rdtsc()" "cc" && enable rdtsc - - check_code ld mmintrin.h "_mm_empty()" "cc" && enable mm_empty + check_builtin rdtsc intrin.h "__rdtsc()" + check_builtin mm_empty mmintrin.h "_mm_empty()" enable local_aligned_8 local_aligned_16 @@ -3757,6 +3831,7 @@ 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 #MYTH check_header X11/extensions/XvMClib.h check_header asm/types.h @@ -3764,14 +3839,6 @@ check_header asm/types.h disabled zlib || check_lib zlib.h zlibVersion -lz || disable zlib disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable bzlib -# check for VDA header -if ! disabled vda && ! enabled ppc; then - if check_header VideoDecodeAcceleration/VDADecoder.h; then - enable vda - add_extralibs -framework CoreFoundation -framework VideoDecodeAcceleration -framework QuartzCore - fi -fi - if ! disabled w32threads && ! enabled pthreads; then check_func_headers "windows.h process.h" _beginthreadex && enable w32threads fi @@ -3837,7 +3904,9 @@ enabled libfdk_aac && require libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen -lfdk- 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_pkg_config freetype2 "ft2build.h freetype/freetype.h" FT_Init_FreeType -enabled libgsm && require libgsm gsm/gsm.h gsm_create -lgsm +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 @@ -3867,10 +3936,12 @@ enabled libvo_aacenc && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -l 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_decoder && { check_lib2 "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_dec_init_ver -lvpx || - die "ERROR: libvpx decoder must be installed and version must be >=0.9.1"; } - enabled libvpx_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_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 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 libx264 && require libx264 x264.h x264_encoder_encode -lx264 && { check_cpp_condition x264.h "X264_BUILD >= 118" || die "ERROR: libx264 must be installed and version must be >= 0.118."; } @@ -3980,10 +4051,12 @@ if ! disabled vaapi; then } || disable vaapi fi -if ! disabled vdpau && enabled vdpau_vdpau_h; then +enabled vdpau && check_cpp_condition vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" || - { echolog "Please upgrade to libvdpau >= 0.2 if you would like vdpau support." && disable vdpau; } -fi + disable vdpau + +# 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" enabled coverage && add_cflags "-fprofile-arcs -ftest-coverage" && add_ldflags "-fprofile-arcs -ftest-coverage" @@ -4074,17 +4147,16 @@ if enabled icc; then 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 - # Allow to compile with optimizations - check_ldflags -march=$cpu # icc 11.0 and 11.1 work with ebp_available, but don't pass the test enable ebp_available if enabled x86_32; then @@ -4247,52 +4319,6 @@ 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 "libdxva2 enabled ${dxva2-no}" -echo "libva enabled ${vaapi-no}" -echo "libvdpau enabled ${vdpau-no}" -echo "AVISynth enabled ${avisynth-no}" -echo "frei0r enabled ${frei0r-no}" -echo "gnutls enabled ${gnutls-no}" -echo "libaacplus enabled ${libaacplus-no}" -echo "libass enabled ${libass-no}" -echo "libcaca enabled ${libcaca-no}" -echo "libcdio support ${libcdio-no}" -echo "libcelt enabled ${libcelt-no}" -echo "libdc1394 support ${libdc1394-no}" -echo "libfaac enabled ${libfaac-no}" -echo "libfdk-aac enabled ${libfdk_aac-no}" -echo "libgsm enabled ${libgsm-no}" -echo "libiec61883 support ${libiec61883-no}" -echo "libilbc enabled ${libilbc-no}" -echo "libmodplug enabled ${libmodplug-no}" -echo "libmp3lame enabled ${libmp3lame-no}" -echo "libnut enabled ${libnut-no}" -echo "libopencore-amrnb support ${libopencore_amrnb-no}" -echo "libopencore-amrwb support ${libopencore_amrwb-no}" -echo "libopencv support ${libopencv-no}" -echo "libopenjpeg enabled ${libopenjpeg-no}" -echo "libopus enabled ${libopus-no}" -echo "libpulse enabled ${libpulse-no}" -echo "librtmp enabled ${librtmp-no}" -echo "libschroedinger enabled ${libschroedinger-no}" -echo "libsoxr enabled ${libsoxr-no}" -echo "libspeex enabled ${libspeex-no}" -echo "libstagefright-h264 enabled ${libstagefright_h264-no}" -echo "libtheora enabled ${libtheora-no}" -echo "libtwolame enabled ${libtwolame-no}" -echo "libutvideo enabled ${libutvideo-no}" -echo "libv4l2 enabled ${libv4l2-no}" -echo "libvo-aacenc support ${libvo_aacenc-no}" -echo "libvo-amrwbenc support ${libvo_amrwbenc-no}" -echo "libvorbis enabled ${libvorbis-no}" -echo "libvpx enabled ${libvpx-no}" -echo "libx264 enabled ${libx264-no}" -echo "libxavs enabled ${libxavs-no}" -echo "libxvid enabled ${libxvid-no}" -echo "openal enabled ${openal-no}" -echo "openssl enabled ${openssl-no}" -echo "zlib enabled ${zlib-no}" -echo "bzlib enabled ${bzlib-no}" echo "texi2html enabled ${texi2html-no}" echo "perl enabled ${perl-no}" echo "pod2man enabled ${pod2man-no}" @@ -4301,10 +4327,14 @@ test -n "$random_seed" && echo "random seed ${random_seed}" echo +echo "External libraries:" +print_enabled '' $EXTERNAL_LIBRARY_LIST | print_3_columns +echo + for type in decoder encoder hwaccel parser demuxer muxer protocol filter bsf indev outdev; do echo "Enabled ${type}s:" eval list=\$$(toupper $type)_LIST - print_enabled '_*' $list | sort | pr -r -3 -t + print_enabled '_*' $list | print_3_columns echo done @@ -4381,7 +4411,7 @@ LD_PATH=$LD_PATH DLLTOOL=$dlltool LDFLAGS=$LDFLAGS LDFLAGS-ffserver=$FFSERVERLDFLAGS -SHFLAGS=$SHFLAGS +SHFLAGS=$(echo $($ldflags_filter $SHFLAGS)) YASMFLAGS=$YASMFLAGS BUILDSUF=$build_suffix PROGSSUF=$progs_suffix @@ -4403,6 +4433,7 @@ AS_DEPFLAGS=$AS_DEPFLAGS HOSTCC=$host_cc HOSTLD=$host_ld HOSTCFLAGS=$host_cflags +HOSTCPPFLAGS=$host_cppflags HOSTEXESUF=$HOSTEXESUF HOSTLDFLAGS=$host_ldflags HOSTLIBS=$host_libs @@ -4446,6 +4477,7 @@ get_version(){ 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 + eval echo "${lcname}_VERSION_MINOR=\$${name}_VERSION_MINOR" >> config.mak } map 'get_version $v' $LIBRARY_LIST @@ -4520,7 +4552,7 @@ pkgconfig_generate(){ requires=$5 enabled ${name#lib} || return 0 mkdir -p $name - cat < $name/$name.pc + cat < $name/$name${build_suffix}.pc prefix=$prefix exec_prefix=\${prefix} libdir=$libdir @@ -4556,27 +4588,27 @@ Cflags: -I\${includedir} EOF } -libavfilter_pc_deps="libavutil = $LIBAVUTIL_VERSION" -enabled libavfilter_deps_avcodec && prepend libavfilter_pc_deps "libavcodec = $LIBAVCODEC_VERSION," -enabled libavfilter_deps_avformat && prepend libavfilter_pc_deps "libavformat = $LIBAVFORMAT_VERSION," -enabled libavfilter_deps_avresample && prepend libavfilter_pc_deps "libavresample = $LIBAVRESAMPLE_VERSION," -enabled libavfilter_deps_swscale && prepend libavfilter_pc_deps "libswscale = $LIBSWSCALE_VERSION," -enabled libavfilter_deps_swresample && prepend libavfilter_pc_deps "libswresample = $LIBSWRESAMPLE_VERSION," -enabled libavfilter_deps_postproc && prepend libavfilter_pc_deps "libpostproc = $LIBPOSTPROC_VERSION," +libavfilter_pc_deps="libavutil${build_suffix} = $LIBAVUTIL_VERSION" +enabled libavfilter_deps_avcodec && prepend libavfilter_pc_deps "libavcodec${build_suffix} = $LIBAVCODEC_VERSION," +enabled libavfilter_deps_avformat && prepend libavfilter_pc_deps "libavformat${build_suffix} = $LIBAVFORMAT_VERSION," +enabled libavfilter_deps_avresample && prepend libavfilter_pc_deps "libavresample${build_suffix} = $LIBAVRESAMPLE_VERSION," +enabled libavfilter_deps_swscale && prepend libavfilter_pc_deps "libswscale${build_suffix} = $LIBSWSCALE_VERSION," +enabled libavfilter_deps_swresample && prepend libavfilter_pc_deps "libswresample${build_suffix} = $LIBSWRESAMPLE_VERSION," +enabled libavfilter_deps_postproc && prepend libavfilter_pc_deps "libpostproc${build_suffix} = $LIBPOSTPROC_VERSION," libavfilter_pc_deps=${libavfilter_pc_deps%, } -libavdevice_pc_deps="libavformat = $LIBAVFORMAT_VERSION" -enabled lavfi_indev && prepend libavdevice_pc_deps "libavfilter = $LIBAVFILTER_VERSION," +libavdevice_pc_deps="libavformat${build_suffix} = $LIBAVFORMAT_VERSION" +enabled lavfi_indev && prepend libavdevice_pc_deps "libavfilter${build_suffix} = $LIBAVFILTER_VERSION," pkgconfig_generate libavutil "FFmpeg utility library" "$LIBAVUTIL_VERSION" "$LIBM" -pkgconfig_generate libavcodec "FFmpeg codec library" "$LIBAVCODEC_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION" -pkgconfig_generate libavformat "FFmpeg container format library" "$LIBAVFORMAT_VERSION" "$extralibs" "libavcodec = $LIBAVCODEC_VERSION" +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" "$libavdevice_pc_deps" -pkgconfig_generate libavfilter "FFmpeg video filtering library" "$LIBAVFILTER_VERSION" "$extralibs" "$libavfilter_pc_deps" -pkgconfig_generate libpostproc "FFmpeg postprocessing library" "$LIBPOSTPROC_VERSION" "" "libavutil = $LIBAVUTIL_VERSION" -pkgconfig_generate libavresample "Libav audio resampling library" "$LIBAVRESAMPLE_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION" -pkgconfig_generate libswscale "FFmpeg image rescaling library" "$LIBSWSCALE_VERSION" "$LIBM" "libavutil = $LIBAVUTIL_VERSION" -pkgconfig_generate libswresample "FFmpeg audio resampling library" "$LIBSWRESAMPLE_VERSION" "$LIBM" "libavutil = $LIBAVUTIL_VERSION" +pkgconfig_generate libavfilter "FFmpeg audio/video filtering library" "$LIBAVFILTER_VERSION" "$extralibs" "$libavfilter_pc_deps" +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" fix_ffmpeg_remote(){ git_remote_from=$1 diff --git a/mythtv/external/FFmpeg/doc/APIchanges b/mythtv/external/FFmpeg/doc/APIchanges index 8daaea32601..a1e81808e75 100644 --- a/mythtv/external/FFmpeg/doc/APIchanges +++ b/mythtv/external/FFmpeg/doc/APIchanges @@ -15,7 +15,19 @@ libavutil: 2012-10-22 API changes, most recent first: -2012-12-20 - xxxxxxx - lavfi 3.28.100 - avfilter.h +2013-03-07 - xxxxxx - lavu 52.18.100 - avstring.h,bprint.h + Add av_escape() and av_bprint_escape() API. + +2013-02-24 - xxxxxx - lavfi 3.41.100 - buffersink.h + Add sample_rates field to AVABufferSinkParams. + +2013-01-17 - a1a707f - lavf 54.61.100 + Add av_codec_get_tag2(). + +2013-01-01 - 2eb2e17 - lavfi 3.34.100 + Add avfilter_get_audio_buffer_ref_from_arrays_channels. + +2012-12-20 - 34de47aa - lavfi 3.29.100 - avfilter.h Add AVFilterLink.channels, avfilter_link_get_channels() and avfilter_ref_get_channels(). @@ -132,6 +144,30 @@ API changes, most recent first: 2012-03-26 - a67d9cf - lavfi 2.66.100 Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions. +2013-xx-xx - xxxxxxx - lavfi 3.4.0 - avfiltergraph.h + Add resample_lavr_opts to AVFilterGraph for setting libavresample options + for auto-inserted resample filters. + +2013-xx-xx - xxxxxxx - lavu 52.7.0 - dict.h + Add av_dict_parse_string() to set multiple key/value pairs at once from a + string. + +2013-01-xx - xxxxxxx - lavu 52.6.0 - avstring.h + Add av_strnstr() + +2013-01-xx - xxxxxxx - lavu 52.5.0 - hmac.h + Add AVHMAC. + +2013-01-13 - xxxxxxx - lavc 54.87.100 / 54.36.0 - vdpau.h + Add AVVDPAUContext struct for VDPAU hardware-accelerated decoding. + +2013-01-12 - dae382b / 169fb94 - lavu 52.14.100 / 52.4.0 - pixdesc.h + Add AV_PIX_FMT_VDPAU flag. + +2013-01-07 - 249fca3 / 074a00d - lavr 1.1.0 + Add avresample_set_channel_mapping() for input channel reordering, + duplication, and silencing. + 2012-12-29 - 2ce43b3 / d8fd06c - lavu 52.13.100 / 52.3.0 - avstring.h Add av_basename() and av_dirname(). diff --git a/mythtv/external/FFmpeg/doc/Doxyfile b/mythtv/external/FFmpeg/doc/Doxyfile index 8216a21efde..d3d5e42cfed 100644 --- a/mythtv/external/FFmpeg/doc/Doxyfile +++ b/mythtv/external/FFmpeg/doc/Doxyfile @@ -31,7 +31,7 @@ PROJECT_NAME = FFmpeg # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 1.1.4 +PROJECT_NUMBER = 1.2.1 # With the PROJECT_LOGO tag one can specify an logo or icon that is included # in the documentation. The maximum height of the logo should not exceed 55 diff --git a/mythtv/external/FFmpeg/doc/Makefile b/mythtv/external/FFmpeg/doc/Makefile index f9efe3a9c47..a8616551bea 100644 --- a/mythtv/external/FFmpeg/doc/Makefile +++ b/mythtv/external/FFmpeg/doc/Makefile @@ -62,7 +62,7 @@ doc/%.html: doc/%.texi $(SRC_PATH)/doc/t2h.init $(GENTEXI) $(M)texi2html -I doc -monolithic --init-file $(SRC_PATH)/doc/t2h.init --output $@ $< doc/%.pod: TAG = POD -doc/%.pod: doc/%.texi $(GENTEXI) +doc/%.pod: doc/%.texi $(SRC_PATH)/doc/texi2pod.pl $(GENTEXI) $(Q)$(TEXIDEP) $(M)perl $(SRC_PATH)/doc/texi2pod.pl -Idoc $< $@ diff --git a/mythtv/external/FFmpeg/doc/RELEASE_NOTES b/mythtv/external/FFmpeg/doc/RELEASE_NOTES index 768a747ba2a..2faf40d6563 100644 --- a/mythtv/external/FFmpeg/doc/RELEASE_NOTES +++ b/mythtv/external/FFmpeg/doc/RELEASE_NOTES @@ -1,7 +1,7 @@ Release Notes ============= -* 1.1 "Fire Flower" January, 2013 +* 1.2 "Magic" March, 2013 General notes @@ -14,12 +14,3 @@ accepted. If you are experiencing issues with any formally released version of FFmpeg, please try git master to check if the issue still exists. If it does, make your report against the development code following the usual bug reporting guidelines. - -Of big interest to our Windows users, FFmpeg now supports building with the MSVC -compiler. Since MSVC does not support C99 features used extensively by FFmpeg, -this has been accomplished using a converter that turns C99 code to C89. See the -platform-specific documentation for more detailed documentation on building -FFmpeg with MSVC. - -The used output sample format for several audio decoders has changed, make -sure you always check/use AVCodecContext.sample_fmt or AVFrame.format. diff --git a/mythtv/external/FFmpeg/doc/demuxers.texi b/mythtv/external/FFmpeg/doc/demuxers.texi index 1187b6a01eb..0861287e76a 100644 --- a/mythtv/external/FFmpeg/doc/demuxers.texi +++ b/mythtv/external/FFmpeg/doc/demuxers.texi @@ -6,18 +6,100 @@ multimedia streams from a particular type of file. When you configure your FFmpeg build, all the supported demuxers are enabled by default. You can list all available ones using the -configure option "--list-demuxers". +configure option @code{--list-demuxers}. You can disable all the demuxers using the configure option -"--disable-demuxers", and selectively enable a single demuxer with -the option "--enable-demuxer=@var{DEMUXER}", or disable it -with the option "--disable-demuxer=@var{DEMUXER}". +@code{--disable-demuxers}, and selectively enable a single demuxer with +the option @code{--enable-demuxer=@var{DEMUXER}}, or disable it +with the option @code{--disable-demuxer=@var{DEMUXER}}. -The option "-formats" of the ff* tools will display the list of +The option @code{-formats} of the ff* tools will display the list of enabled demuxers. The description of some of the currently available demuxers follows. +@section applehttp + +Apple HTTP Live Streaming demuxer. + +This demuxer presents all AVStreams from all variant streams. +The id field is set to the bitrate variant index number. By setting +the discard flags on AVStreams (by pressing 'a' or 'v' in ffplay), +the caller can decide which variant streams to actually receive. +The total bitrate of the variant that the stream belongs to is +available in a metadata key named "variant_bitrate". + +@anchor{concat} +@section concat + +Virtual concatenation script demuxer. + +This demuxer reads a list of files and other directives from a text file and +demuxes them one after the other, as if all their packet had been muxed +together. + +The timestamps in the files are adjusted so that the first file starts at 0 +and each next file starts where the previous one finishes. Note that it is +done globally and may cause gaps if all streams do not have exactly the same +length. + +All files must have the same streams (same codecs, same time base, etc.). + +The duration of each file is used to adjust the timestamps of the next file: +if the duration is incorrect (because it was computed using the bit-rate or +because the file is truncated, for example), it can cause artifacts. The +@code{duration} directive can be used to override the duration stored in +each file. + +@subsection Syntax + +The script is a text file in extended-ASCII, with one directive per line. +Empty lines, leading spaces and lines starting with '#' are ignored. The +following directive is recognized: + +@table @option + +@item @code{file @var{path}} +Path to a file to read; special characters and spaces must be escaped with +backslash or single quotes. + +All subsequent directives apply to that file. + +@item @code{ffconcat version 1.0} +Identify the script type and version. It also sets the @option{safe} option +to 1 if it was to its default -1. + +To make FFmpeg recognize the format automatically, this directive must +appears exactly as is (no extra space or byte-order-mark) on the very first +line of the script. + +@item @code{duration @var{dur}} +Duration of the file. This information can be specified from the file; +specifying it here may be more efficient or help if the information from the +file is not available or accurate. + +@end table + +@subsection Options + +This demuxer accepts the following option: + +@table @option + +@item safe +If set to 1, reject unsafe file paths. A file path is considered safe if it +does not contain a protocol specification and is relative and all components +only contain characters from the portable character set (letters, digits, +period, underscore and hyphen) and have no period at the beginning of a +component. + +If set to 0, any file name is accepted. + +The default is -1, it is equivalent to 1 if the format was automatically +probed and 0 otherwise. + +@end table + @section image2 Image file demuxer. @@ -143,16 +225,34 @@ ffmpeg -pattern_type glob -i "*.png" -r 10 out.mkv @end example @end itemize -@section applehttp +@section rawvideo -Apple HTTP Live Streaming demuxer. +Raw video demuxer. -This demuxer presents all AVStreams from all variant streams. -The id field is set to the bitrate variant index number. By setting -the discard flags on AVStreams (by pressing 'a' or 'v' in ffplay), -the caller can decide which variant streams to actually receive. -The total bitrate of the variant that the stream belongs to is -available in a metadata key named "variant_bitrate". +This demuxer allows to read raw video data. Since there is no header +specifying the assumed video parameters, the user must specify them +in order to be able to decode the data correctly. + +This demuxer accepts the following options: +@table @option + +@item framerate +Set input video frame rate. Default value is 25. + +@item pixel_format +Set the input video pixel format. Default value is @code{yuv420p}. + +@item video_size +Set the input video size. This value must be specified explicitly. +@end table + +For example to read a rawvideo file @file{input.raw} with +@command{ffplay}, assuming a pixel format of @code{rgb24}, a video +size of @code{320x240}, and a frame rate of 10 images per second, use +the command: +@example +ffplay -f rawvideo -pixel_format rgb24 -video_size 320x240 -framerate 10 input.raw +@end example @section sbg @@ -184,37 +284,6 @@ the script is directly played, the actual times will match the absolute timestamps up to the sound controller's clock accuracy, but if the user somehow pauses the playback or seeks, all times will be shifted accordingly. -@section concat - -Virtual concatenation script demuxer. - -This demuxer reads a list of files and other directives from a text file and -demuxes them one after the other, as if all their packet had been muxed -together. - -The timestamps in the files are adjusted so that the first file starts at 0 -and each next file starts where the previous one finishes. Note that it is -done globally and may cause gaps if all streams do not have exactly the same -length. - -All files must have the same streams (same codecs, same time base, etc.). - -This script format can currently not be probed, it must be specified explicitly. - -@subsection Syntax - -The script is a text file in extended-ASCII, with one directive per line. -Empty lines, leading spaces and lines starting with '#' are ignored. The -following directive is recognized: - -@table @option - -@item @code{file @var{path}} -Path to a file to read; special characters and spaces must be escaped with -backslash or single quotes. - -@end table - @section tedcaptions JSON captions used for @url{http://www.ted.com/, TED Talks}. @@ -236,4 +305,4 @@ Example: convert the captions to a format most players understand: ffmpeg -i http://www.ted.com/talks/subtitles/id/1/lang/en talk1-en.srt @end example -@c man end INPUT DEVICES +@c man end DEMUXERS diff --git a/mythtv/external/FFmpeg/doc/developer.texi b/mythtv/external/FFmpeg/doc/developer.texi index be1b62a3f36..fe4b40ac4aa 100644 --- a/mythtv/external/FFmpeg/doc/developer.texi +++ b/mythtv/external/FFmpeg/doc/developer.texi @@ -147,29 +147,41 @@ GCC statement expressions (@samp{(x = (@{ int y = 4; y; @})}). @end itemize @subsection Naming conventions -All names are using underscores (_), not CamelCase. For example, @samp{avfilter_get_video_buffer} is -a valid function name and @samp{AVFilterGetVideo} is not. The exception from this are type names, like +All names should be composed with underscores (_), not CamelCase. For example, +@samp{avfilter_get_video_buffer} is an acceptable function name and +@samp{AVFilterGetVideo} is not. The exception from this are type names, like for example structs and enums; they should always be in the CamelCase - -There are following conventions for naming variables and functions: +There are the following conventions for naming variables and functions: @itemize @bullet @item For local variables no prefix is required. @item -For variables and functions declared as @code{static} no prefixes are required. +For variables and functions declared as @code{static} no prefix is required. @item -For variables and functions used internally by the library, @code{ff_} prefix -should be used. -For example, @samp{ff_w64_demuxer}. +For variables and functions used internally by a library an @code{ff_} +prefix should be used, e.g. @samp{ff_w64_demuxer}. @item For variables and functions used internally across multiple libraries, use @code{avpriv_}. For example, @samp{avpriv_aac_parse_header}. @item -For exported names, each library has its own prefixes. Just check the existing -code and name accordingly. +Each library has its own prefix for public symbols, in addition to the +commonly used @code{av_} (@code{avformat_} for libavformat, +@code{avcodec_} for libavcodec, @code{swr_} for libswresample, etc). +Check the existing code and choose names accordingly. +Note that some symbols without these prefixes are also exported for +retro-compatibility reasons. These exceptions are declared in the +@code{lib/lib.v} files. @end itemize +Furthermore, name space reserved for the system should not be invaded. +Identifiers ending in @code{_t} are reserved by +@url{http://pubs.opengroup.org/onlinepubs/007904975/functions/xsh_chap02_02.html#tag_02_02_02, POSIX}. +Also avoid names starting with @code{__} or @code{_} followed by an uppercase +letter as they are reserved by the C standard. Names starting with @code{_} +are reserved at the file level and may not be used for externally visible +symbols. If in doubt, just avoid names starting with @code{_} altogether. + @subsection Miscellaneous conventions @itemize @bullet @item @@ -217,8 +229,13 @@ For Emacs, add these roughly equivalent lines to your @file{.emacs.d/init.el}: @enumerate @item - Contributions should be licensed under the LGPL 2.1, including an - "or any later version" clause, or the MIT license. GPL 2 including + Contributions should be licensed under the + @uref{http://www.gnu.org/licenses/lgpl-2.1.html, LGPL 2.1}, + including an "or any later version" clause, or, if you prefer + a gift-style license, the + @uref{http://www.isc.org/software/license/, ISC} or + @uref{http://mit-license.org/, MIT} license. + @uref{http://www.gnu.org/licenses/gpl-2.0.html, GPL 2} including an "or any later version" clause is also acceptable, but LGPL is preferred. @item @@ -228,6 +245,13 @@ For Emacs, add these roughly equivalent lines to your @file{.emacs.d/init.el}: You can commit unfinished stuff (for testing etc), but it must be disabled (#ifdef etc) by default so it does not interfere with other developers' work. +@item + The commit message should have a short first line in the form of + a @samp{topic: short description} as a header, separated by a newline + from the body consisting of an explanation of why the change is necessary. + If the commit fixes a known bug on the bug tracker, the commit message + should include its bug ID. Referring to the issue on the bug tracker does + not exempt you from writing an excerpt of the bug in the commit message. @item You do not have to over-test things. If it works for you, and you think it should work for others, then commit. If your code has problems @@ -334,8 +358,6 @@ For Emacs, add these roughly equivalent lines to your @file{.emacs.d/init.el}: We think our rules are not too hard. If you have comments, contact us. -Note, these rules are mostly borrowed from the MPlayer project. - @anchor{Submitting patches} @section Submitting patches @@ -358,11 +380,6 @@ The tool is located in the tools directory. Run the @ref{Regression tests} before submitting a patch in order to verify it does not cause unexpected problems. -Patches should be posted as base64 encoded attachments (or any other -encoding which ensures that the patch will not be trashed during -transmission) to the ffmpeg-devel mailing list, see -@url{http://lists.ffmpeg.org/mailman/listinfo/ffmpeg-devel} - It also helps quite a bit if you tell us what the patch does (for example 'replaces lrint by lrintf'), and why (for example '*BSD isn't C99 compliant and has no lrint()') @@ -370,6 +387,13 @@ and has no lrint()') Also please if you send several patches, send each patch as a separate mail, do not attach several unrelated patches to the same mail. +Patches should be posted to the +@uref{http://lists.ffmpeg.org/mailman/listinfo/ffmpeg-devel, ffmpeg-devel} +mailing list. Use @code{git send-email} when possible since it will properly +send patches without requiring extra care. If you cannot, then send patches +as base64-encoded attachments, so your patch is not trashed during +transmission. + Your patch will be reviewed on the mailing list. You will likely be asked to make some changes and are expected to send in an improved version that incorporates the requests from the review. This process may go through @@ -398,7 +422,7 @@ send a reminder by email. Your patch should eventually be dealt with. When adding new codec IDs, also add an entry to the codec descriptor list in @file{libavcodec/codec_desc.c}. @item - If it has a fourCC, did you add it to @file{libavformat/riff.c}, + If it has a FourCC, did you add it to @file{libavformat/riff.c}, even if it is only a decoder? @item Did you add a rule to compile the appropriate files in the Makefile? @@ -451,8 +475,10 @@ send a reminder by email. Your patch should eventually be dealt with. other security issues? @item Did you test your decoder or demuxer against damaged data? If no, see - tools/trasher and the noise bitstream filter. Your decoder or demuxer - should not crash or end in a (near) infinite loop when fed damaged data. + tools/trasher, the noise bitstream filter, and + @uref{http://caca.zoy.org/wiki/zzuf, zzuf}. Your decoder or demuxer + should not crash, end in a (near) infinite loop, or allocate ridiculous + amounts of memory when fed damaged data. @item Does the patch not mix functional and cosmetic changes? @item @@ -496,6 +522,9 @@ send a reminder by email. Your patch should eventually be dealt with. Make sure you check the return values of function and return appropriate error codes. Especially memory allocation functions like @code{av_malloc()} are notoriously left unchecked, which is a serious problem. +@item + Test your code with valgrind and or Address Sanitizer to ensure it's free + of leaks, out of array accesses, etc. @end enumerate @section Patch review process diff --git a/mythtv/external/FFmpeg/doc/encoders.texi b/mythtv/external/FFmpeg/doc/encoders.texi index a5325f45a80..07343eb42b1 100644 --- a/mythtv/external/FFmpeg/doc/encoders.texi +++ b/mythtv/external/FFmpeg/doc/encoders.texi @@ -581,40 +581,175 @@ For more information about libvpx see: @section libx264 -H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 format supported through -libx264. +x264 H.264/MPEG-4 AVC encoder wrapper Requires the presence of the libx264 headers and library during configuration. You need to explicitly configure the build with @code{--enable-libx264}. -@subsection Options - +x264 supports an impressive number of features, including 8x8 and 4x4 adaptive +spatial transform, adaptive B-frame placement, CAVLC/CABAC entropy coding, +interlacing (MBAFF), lossless mode, psy optimizations for detail retention +(adaptive quantization, psy-RD, psy-trellis). + +The FFmpeg wrapper provides a mapping for most of them using global options +that match those of the encoders and provides private options for the unique +encoder options. Additionally an expert override is provided to directly pass +a list of key=value tuples as accepted by x264_param_parse. + +@subsection Option Mapping + +The following options are supported by the x264 wrapper, the x264-equivalent +options follow the FFmpeg ones. + +@multitable @columnfractions .2 .2 +@item b @tab bitrate +FFmpeg @code{b} option is expressed in bits/s, x264 @code{bitrate} in kilobits/s. +@item bf @tab bframes +Maximum number of B-frames. +@item g @tab keyint +Maximum GOP size. +@item qmin @tab qpmin +@item qmax @tab qpmax +@item qdiff @tab qpstep +@item qblur @tab qblur +@item qcomp @tab qcomp +@item refs @tab ref +@item sc_threshold @tab scenecut +@item trellis @tab trellis +@item nr @tab nr +Noise reduction. +@item me_range @tab merange +@item me_method @tab me +@item subq @tab subme +@item b_strategy @tab b-adapt +@item keyint_min @tab keyint-min +@item coder @tab cabac +Set coder to @code{ac} to use CABAC. +@item cmp @tab chroma-me +Set to @code{chroma} to use chroma motion estimation. +@item threads @tab threads +@item thread_type @tab sliced_threads +Set to @code{slice} to use sliced threading instead of frame threading. +@item flags -cgop @tab open-gop +Set @code{-cgop} to use recovery points to close GOPs. +@item rc_init_occupancy @tab vbv-init +Initial buffer occupancy. +@end multitable + +@subsection Private Options @table @option +@item -preset @var{string} +Set the encoding preset (cf. x264 --fullhelp). +@item -tune @var{string} +Tune the encoding params (cf. x264 --fullhelp). +@item -profile @var{string} +Set profile restrictions (cf. x264 --fullhelp). +@item -fastfirstpass @var{integer} +Use fast settings when encoding first pass. +@item -crf @var{float} +Select the quality for constant quality mode. +@item -crf_max @var{float} +In CRF mode, prevents VBV from lowering quality beyond this point. +@item -qp @var{integer} +Constant quantization parameter rate control method. +@item -aq-mode @var{integer} +AQ method + +Possible values: +@table @samp +@item none + +@item variance +Variance AQ (complexity mask). +@item autovariance +Auto-variance AQ (experimental). +@end table +@item -aq-strength @var{float} +AQ strength, reduces blocking and blurring in flat and textured areas. +@item -psy @var{integer} +Use psychovisual optimizations. +@item -psy-rd @var{string} +Strength of psychovisual optimization, in : format. +@item -rc-lookahead @var{integer} +Number of frames to look ahead for frametype and ratecontrol. +@item -weightb @var{integer} +Weighted prediction for B-frames. +@item -weightp @var{integer} +Weighted prediction analysis method. + +Possible values: +@table @samp +@item none + +@item simple + +@item smart -@item preset @var{preset_name} -Set the encoding preset. - -@item tune @var{tune_name} -Tune the encoding params. +@end table +@item -ssim @var{integer} +Calculate and print SSIM stats. +@item -intra-refresh @var{integer} +Use Periodic Intra Refresh instead of IDR frames. +@item -b-bias @var{integer} +Influences how often B-frames are used. +@item -b-pyramid @var{integer} +Keep some B-frames as references. + +Possible values: +@table @samp +@item none + +@item strict +Strictly hierarchical pyramid. +@item normal +Non-strict (not Blu-ray compatible). +@end table +@item -mixed-refs @var{integer} +One reference per partition, as opposed to one reference per macroblock. +@item -8x8dct @var{integer} +High profile 8x8 transform. +@item -fast-pskip @var{integer} +@item -aud @var{integer} +Use access unit delimiters. +@item -mbtree @var{integer} +Use macroblock tree ratecontrol. +@item -deblock @var{string} +Loop filter parameters, in form. +@item -cplxblur @var{float} +Reduce fluctuations in QP (before curve compression). +@item -partitions @var{string} +A comma-separated list of partitions to consider, possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all. +@item -direct-pred @var{integer} +Direct MV prediction mode + +Possible values: +@table @samp +@item none + +@item spatial + +@item temporal + +@item auto -@item fastfirstpass @var{bool} -Use fast settings when encoding first pass, default value is 1. +@end table +@item -slice-max-size @var{integer} +Limit the size of each slice in bytes. +@item -stats @var{string} +Filename for 2 pass stats. +@item -nal-hrd @var{integer} +Signal HRD information (requires vbv-bufsize; cbr not allowed in .mp4). -@item profile @var{profile_name} -Set profile restrictions. +Possible values: +@table @samp +@item none -@item level @var{level} -Specify level (as defined by Annex A). -Deprecated in favor of @var{x264opts}. +@item vbr -@item passlogfile @var{filename} -Specify filename for 2 pass stats. -Deprecated in favor of @var{x264opts} (see @var{stats} libx264 option). +@item cbr -@item wpredp @var{wpred_type} -Specify Weighted prediction for P-frames. -Deprecated in favor of @var{x264opts} (see @var{weightp} libx264 option). +@end table @item x264opts @var{options} Allow to set any x264 option, see @code{x264 --fullhelp} for a list. @@ -623,7 +758,6 @@ Allow to set any x264 option, see @code{x264 --fullhelp} for a list. ":". In @var{filter} and @var{psy-rd} options that use ":" as a separator themselves, use "," instead. They accept it as well since long ago but this is kept undocumented for some reason. -@end table For example to specify libx264 encoding options with @command{ffmpeg}: @example @@ -633,4 +767,14 @@ ffmpeg -i foo.mpg -vcodec libx264 -x264opts keyint=123:min-keyint=20 -an out.mkv For more information about libx264 and the supported options see: @url{http://www.videolan.org/developers/x264.html} +@item -x264-params @var{string} +Override the x264 configuration using a :-separated list of key=value parameters. +@example +-x264-params level=30:bframes=0:weightp=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1:subq=6:8x8dct=0:trellis=0 +@end example +@end table + +Encoding avpresets for common usages are provided so they can be used with the +general presets system (e.g. passing the @code{-pre} option). + @c man end VIDEO ENCODERS diff --git a/mythtv/external/FFmpeg/doc/eval.texi b/mythtv/external/FFmpeg/doc/eval.texi index 1ea89d67558..3b7964ce4cc 100644 --- a/mythtv/external/FFmpeg/doc/eval.texi +++ b/mythtv/external/FFmpeg/doc/eval.texi @@ -20,111 +20,102 @@ The following unary operators are available: @code{+}, @code{-}. The following functions are available: @table @option -@item sinh(x) -Compute hyperbolic sine of @var{x}. +@item abs(x) +Compute absolute value of @var{x}. -@item cosh(x) -Compute hyperbolic cosine of @var{x}. +@item acos(x) +Compute arccosine of @var{x}. -@item tanh(x) -Compute hyperbolic tangent of @var{x}. +@item asin(x) +Compute arcsine of @var{x}. -@item sin(x) -Compute sine of @var{x}. +@item atan(x) +Compute arctangent of @var{x}. + +@item ceil(expr) +Round the value of expression @var{expr} upwards to the nearest +integer. For example, "ceil(1.5)" is "2.0". @item cos(x) Compute cosine of @var{x}. -@item tan(x) -Compute tangent of @var{x}. - -@item atan(x) -Compute arctangent of @var{x}. - -@item asin(x) -Compute arcsine of @var{x}. +@item cosh(x) +Compute hyperbolic cosine of @var{x}. -@item acos(x) -Compute arccosine of @var{x}. +@item eq(x, y) +Return 1 if @var{x} and @var{y} are equivalent, 0 otherwise. @item exp(x) Compute exponential of @var{x} (with base @code{e}, the Euler's number). -@item log(x) -Compute natural logarithm of @var{x}. - -@item abs(x) -Compute absolute value of @var{x}. - -@item squish(x) -Compute expression @code{1/(1 + exp(4*x))}. +@item floor(expr) +Round the value of expression @var{expr} downwards to the nearest +integer. For example, "floor(-1.5)" is "-2.0". @item gauss(x) Compute Gauss function of @var{x}, corresponding to @code{exp(-x*x/2) / sqrt(2*PI)}. -@item isinf(x) -Return 1.0 if @var{x} is +/-INFINITY, 0.0 otherwise. - -@item isnan(x) -Return 1.0 if @var{x} is NAN, 0.0 otherwise. +@item gcd(x, y) +Return the greatest common divisor of @var{x} and @var{y}. If both @var{x} and +@var{y} are 0 or either or both are less than zero then behavior is undefined. -@item mod(x, y) -Compute the remainder of division of @var{x} by @var{y}. +@item gt(x, y) +Return 1 if @var{x} is greater than @var{y}, 0 otherwise. -@item max(x, y) -Return the maximum between @var{x} and @var{y}. +@item gte(x, y) +Return 1 if @var{x} is greater than or equal to @var{y}, 0 otherwise. -@item min(x, y) -Return the maximum between @var{x} and @var{y}. +@item hypot(x, y) +This function is similar to the C function with the same name; it returns +"sqrt(@var{x}*@var{x} + @var{y}*@var{y})", the length of the hypotenuse of a +right triangle with sides of length @var{x} and @var{y}, or the distance of the +point (@var{x}, @var{y}) from the origin. -@item eq(x, y) -Return 1 if @var{x} and @var{y} are equivalent, 0 otherwise. +@item if(x, y) +Evaluate @var{x}, and if the result is non-zero return the result of +the evaluation of @var{y}, return 0 otherwise. -@item gte(x, y) -Return 1 if @var{x} is greater than or equal to @var{y}, 0 otherwise. +@item if(x, y, z) +Evaluate @var{x}, and if the result is non-zero return the evaluation +result of @var{y}, otherwise the evaluation result of @var{z}. -@item gt(x, y) -Return 1 if @var{x} is greater than @var{y}, 0 otherwise. +@item ifnot(x, y) +Evaluate @var{x}, and if the result is zero return the result of the +evaluation of @var{y}, return 0 otherwise. -@item lte(x, y) -Return 1 if @var{x} is lesser than or equal to @var{y}, 0 otherwise. +@item ifnot(x, y, z) +Evaluate @var{x}, and if the result is zero return the evaluation +result of @var{y}, otherwise the evaluation result of @var{z}. -@item lt(x, y) -Return 1 if @var{x} is lesser than @var{y}, 0 otherwise. +@item isinf(x) +Return 1.0 if @var{x} is +/-INFINITY, 0.0 otherwise. -@item st(var, expr) -Allow to store the value of the expression @var{expr} in an internal -variable. @var{var} specifies the number of the variable where to -store the value, and it is a value ranging from 0 to 9. The function -returns the value stored in the internal variable. -Note, Variables are currently not shared between expressions. +@item isnan(x) +Return 1.0 if @var{x} is NAN, 0.0 otherwise. @item ld(var) Allow to load the value of the internal variable with number @var{var}, which was previously stored with st(@var{var}, @var{expr}). The function returns the loaded value. -@item while(cond, expr) -Evaluate expression @var{expr} while the expression @var{cond} is -non-zero, and returns the value of the last @var{expr} evaluation, or -NAN if @var{cond} was always false. +@item log(x) +Compute natural logarithm of @var{x}. -@item ceil(expr) -Round the value of expression @var{expr} upwards to the nearest -integer. For example, "ceil(1.5)" is "2.0". +@item lt(x, y) +Return 1 if @var{x} is lesser than @var{y}, 0 otherwise. -@item floor(expr) -Round the value of expression @var{expr} downwards to the nearest -integer. For example, "floor(-1.5)" is "-2.0". +@item lte(x, y) +Return 1 if @var{x} is lesser than or equal to @var{y}, 0 otherwise. -@item trunc(expr) -Round the value of expression @var{expr} towards zero to the nearest -integer. For example, "trunc(-1.5)" is "-1.0". +@item max(x, y) +Return the maximum between @var{x} and @var{y}. -@item sqrt(expr) -Compute the square root of @var{expr}. This is equivalent to -"(@var{expr})^.5". +@item min(x, y) +Return the maximum between @var{x} and @var{y}. + +@item mod(x, y) +Compute the remainder of division of @var{x} by @var{y}. @item not(expr) Return 1.0 if @var{expr} is zero, 0.0 otherwise. @@ -133,39 +124,83 @@ Return 1.0 if @var{expr} is zero, 0.0 otherwise. Compute the power of @var{x} elevated @var{y}, it is equivalent to "(@var{x})^(@var{y})". +@item print(t) +@item print(t, l) +Print the value of expression @var{t} with loglevel @var{l}. If +@var{l} is not specified then a default log level is used. +Returns the value of the expression printed. + +Prints t with loglevel l + @item random(x) Return a pseudo random value between 0.0 and 1.0. @var{x} is the index of the internal variable which will be used to save the seed/state. -@item hypot(x, y) -This function is similar to the C function with the same name; it returns -"sqrt(@var{x}*@var{x} + @var{y}*@var{y})", the length of the hypotenuse of a -right triangle with sides of length @var{x} and @var{y}, or the distance of the -point (@var{x}, @var{y}) from the origin. +@item root(expr, max) +Find an input value for which the function represented by @var{expr} +with argument @var{ld(0)} is 0 in the interval 0..@var{max}. -@item gcd(x, y) -Return the greatest common divisor of @var{x} and @var{y}. If both @var{x} and -@var{y} are 0 or either or both are less than zero then behavior is undefined. +The expression in @var{expr} must denote a continuous function or the +result is undefined. -@item if(x, y) -Evaluate @var{x}, and if the result is non-zero return the result of -the evaluation of @var{y}, return 0 otherwise. +@var{ld(0)} is used to represent the function input value, which means +that the given expression will be evaluated multiple times with +various input values that the expression can access through +@code{ld(0)}. When the expression evaluates to 0 then the +corresponding input value will be returned. -@item ifnot(x, y) -Evaluate @var{x}, and if the result is zero return the result of the -evaluation of @var{y}, return 0 otherwise. +@item sin(x) +Compute sine of @var{x}. -@item taylor(expr, x) taylor(expr, x, id) -Evaluate a taylor series at x. -expr represents the LD(id)-th derivates of f(x) at 0. If id is not specified -then 0 is assumed. -note, when you have the derivatives at y instead of 0 -taylor(expr, x-y) can be used -When the series does not converge the results are undefined. +@item sinh(x) +Compute hyperbolic sine of @var{x}. -@item root(expr, max) -Finds x where f(x)=0 in the interval 0..max. -f() must be continuous or the result is undefined. +@item sqrt(expr) +Compute the square root of @var{expr}. This is equivalent to +"(@var{expr})^.5". + +@item squish(x) +Compute expression @code{1/(1 + exp(4*x))}. + +@item st(var, expr) +Allow to store the value of the expression @var{expr} in an internal +variable. @var{var} specifies the number of the variable where to +store the value, and it is a value ranging from 0 to 9. The function +returns the value stored in the internal variable. +Note, Variables are currently not shared between expressions. + +@item tan(x) +Compute tangent of @var{x}. + +@item tanh(x) +Compute hyperbolic tangent of @var{x}. + +@item taylor(expr, x) +@item taylor(expr, x, id) +Evaluate a Taylor series at @var{x}, given an expression representing +the @code{ld(id)}-th derivative of a function at 0. + +When the series does not converge the result is undefined. + +@var{ld(id)} is used to represent the derivative order in @var{expr}, +which means that the given expression will be evaluated multiple times +with various input values that the expression can access through +@code{ld(id)}. If @var{id} is not specified then 0 is assumed. + +Note, when you have the derivatives at y instead of 0, +@code{taylor(expr, x-y)} can be used. + +@item time(0) +Return the current (wallclock) time in seconds. + +@item trunc(expr) +Round the value of expression @var{expr} towards zero to the nearest +integer. For example, "trunc(-1.5)" is "-1.0". + +@item while(cond, expr) +Evaluate expression @var{expr} while the expression @var{cond} is +non-zero, and returns the value of the last @var{expr} evaluation, or +NAN if @var{cond} was always false. @end table The following constants are available: @@ -185,68 +220,69 @@ value, note that: @code{+} works like OR -and the construct: +For example the construct: @example -if A then B else C +if (A AND B) then C @end example -is equivalent to +is equivalent to: @example -if(A,B) + ifnot(A,C) +if(A*B, C) @end example In your C code, you can extend the list of unary and binary functions, and define recognized constants, so that they are available for your expressions. -The evaluator also recognizes the International System number -postfixes. If 'i' is appended after the postfix, powers of 2 are used -instead of powers of 10. The 'B' postfix multiplies the value for 8, -and can be appended after another postfix or used alone. This allows -using for example 'KB', 'MiB', 'G' and 'B' as postfix. +The evaluator also recognizes the International System unit prefixes. +If 'i' is appended after the prefix, binary prefixes are used, which +are based on powers of 1024 instead of powers of 1000. +The 'B' postfix multiplies the value by 8, and can be appended after a +unit prefix or used alone. This allows using for example 'KB', 'MiB', +'G' and 'B' as number postfix. -Follows the list of available International System postfixes, with +The list of available International System prefixes follows, with indication of the corresponding powers of 10 and of 2. @table @option @item y --24 / -80 +10^-24 / 2^-80 @item z --21 / -70 +10^-21 / 2^-70 @item a --18 / -60 +10^-18 / 2^-60 @item f --15 / -50 +10^-15 / 2^-50 @item p --12 / -40 +10^-12 / 2^-40 @item n --9 / -30 +10^-9 / 2^-30 @item u --6 / -20 +10^-6 / 2^-20 @item m --3 / -10 +10^-3 / 2^-10 @item c --2 +10^-2 @item d --1 +10^-1 @item h -2 +10^2 @item k -3 / 10 +10^3 / 2^10 @item K -3 / 10 +10^3 / 2^10 @item M -6 / 20 +10^6 / 2^20 @item G -9 / 30 +10^9 / 2^30 @item T -12 / 40 +10^12 / 2^40 @item P -15 / 40 +10^15 / 2^40 @item E -18 / 50 +10^18 / 2^50 @item Z -21 / 60 +10^21 / 2^60 @item Y -24 / 70 +10^24 / 2^70 @end table @c man end diff --git a/mythtv/external/FFmpeg/doc/examples/demuxing.c b/mythtv/external/FFmpeg/doc/examples/demuxing.c index bee21b7b332..8a1b69bcf5e 100644 --- a/mythtv/external/FFmpeg/doc/examples/demuxing.c +++ b/mythtv/external/FFmpeg/doc/examples/demuxing.c @@ -98,7 +98,7 @@ static int decode_packet(int *got_frame, int cached) audio_frame_count++, frame->nb_samples, av_ts2timestr(frame->pts, &audio_dec_ctx->time_base)); - ret = av_samples_alloc(audio_dst_data, &audio_dst_linesize, frame->channels, + ret = av_samples_alloc(audio_dst_data, &audio_dst_linesize, av_frame_get_channels(frame), frame->nb_samples, frame->format, 1); if (ret < 0) { fprintf(stderr, "Could not allocate audio buffer\n"); @@ -107,13 +107,13 @@ static int decode_packet(int *got_frame, int cached) /* TODO: extend return code of the av_samples_* functions so that this call is not needed */ audio_dst_bufsize = - av_samples_get_buffer_size(NULL, frame->channels, + av_samples_get_buffer_size(NULL, av_frame_get_channels(frame), frame->nb_samples, frame->format, 1); /* copy audio data to destination buffer: * this is required since rawaudio expects non aligned data */ av_samples_copy(audio_dst_data, frame->data, 0, 0, - frame->nb_samples, frame->channels, frame->format); + frame->nb_samples, av_frame_get_channels(frame), frame->format); /* write to rawaudio file */ fwrite(audio_dst_data[0], 1, audio_dst_bufsize, audio_dst_file); @@ -292,8 +292,10 @@ int main (int argc, char **argv) printf("Demuxing audio from file '%s' into '%s'\n", src_filename, audio_dst_filename); /* read frames from the file */ - while (av_read_frame(fmt_ctx, &pkt) >= 0) + while (av_read_frame(fmt_ctx, &pkt) >= 0) { decode_packet(&got_frame, 0); + av_free_packet(&pkt); + } /* flush cached frames */ pkt.data = NULL; diff --git a/mythtv/external/FFmpeg/doc/examples/filtering_audio.c b/mythtv/external/FFmpeg/doc/examples/filtering_audio.c index b28e02bfb95..6f70a8df903 100644 --- a/mythtv/external/FFmpeg/doc/examples/filtering_audio.c +++ b/mythtv/external/FFmpeg/doc/examples/filtering_audio.c @@ -169,9 +169,13 @@ int main(int argc, char **argv) { int ret; AVPacket packet; - AVFrame frame; + AVFrame *frame = avcodec_alloc_frame(); int got_frame; + if (!frame) { + perror("Could not allocate frame"); + exit(1); + } if (argc != 2) { fprintf(stderr, "Usage: %s file | %s\n", argv[0], player); exit(1); @@ -193,9 +197,9 @@ int main(int argc, char **argv) break; if (packet.stream_index == audio_stream_index) { - avcodec_get_frame_defaults(&frame); + avcodec_get_frame_defaults(frame); got_frame = 0; - ret = avcodec_decode_audio4(dec_ctx, &frame, &got_frame, &packet); + ret = avcodec_decode_audio4(dec_ctx, frame, &got_frame, &packet); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error decoding audio\n"); continue; @@ -203,7 +207,7 @@ int main(int argc, char **argv) if (got_frame) { /* push the audio data from decoded frame into the filtergraph */ - if (av_buffersrc_add_frame(buffersrc_ctx, &frame, 0) < 0) { + if (av_buffersrc_add_frame(buffersrc_ctx, frame, 0) < 0) { av_log(NULL, AV_LOG_ERROR, "Error while feeding the audio filtergraph\n"); break; } @@ -229,6 +233,7 @@ int main(int argc, char **argv) if (dec_ctx) avcodec_close(dec_ctx); avformat_close_input(&fmt_ctx); + av_freep(&frame); if (ret < 0 && ret != AVERROR_EOF) { char buf[1024]; diff --git a/mythtv/external/FFmpeg/doc/examples/filtering_video.c b/mythtv/external/FFmpeg/doc/examples/filtering_video.c index 90babb6be45..660e52663f1 100644 --- a/mythtv/external/FFmpeg/doc/examples/filtering_video.c +++ b/mythtv/external/FFmpeg/doc/examples/filtering_video.c @@ -173,9 +173,13 @@ int main(int argc, char **argv) { int ret; AVPacket packet; - AVFrame frame; + AVFrame *frame = avcodec_alloc_frame(); int got_frame; + if (!frame) { + perror("Could not allocate frame"); + exit(1); + } if (argc != 2) { fprintf(stderr, "Usage: %s file\n", argv[0]); exit(1); @@ -197,19 +201,19 @@ int main(int argc, char **argv) break; if (packet.stream_index == video_stream_index) { - avcodec_get_frame_defaults(&frame); + avcodec_get_frame_defaults(frame); got_frame = 0; - ret = avcodec_decode_video2(dec_ctx, &frame, &got_frame, &packet); + ret = avcodec_decode_video2(dec_ctx, frame, &got_frame, &packet); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error decoding video\n"); break; } if (got_frame) { - frame.pts = av_frame_get_best_effort_timestamp(&frame); + frame->pts = av_frame_get_best_effort_timestamp(frame); /* push the decoded frame into the filtergraph */ - if (av_buffersrc_add_frame(buffersrc_ctx, &frame, 0) < 0) { + if (av_buffersrc_add_frame(buffersrc_ctx, frame, 0) < 0) { av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n"); break; } @@ -236,6 +240,7 @@ int main(int argc, char **argv) if (dec_ctx) avcodec_close(dec_ctx); avformat_close_input(&fmt_ctx); + av_freep(&frame); if (ret < 0 && ret != AVERROR_EOF) { char buf[1024]; diff --git a/mythtv/external/FFmpeg/doc/examples/muxing.c b/mythtv/external/FFmpeg/doc/examples/muxing.c index 8469b272b52..0a00884859c 100644 --- a/mythtv/external/FFmpeg/doc/examples/muxing.c +++ b/mythtv/external/FFmpeg/doc/examples/muxing.c @@ -86,7 +86,6 @@ static AVStream *add_stream(AVFormatContext *oc, AVCodec **codec, break; case AVMEDIA_TYPE_VIDEO: - avcodec_get_context_defaults3(c, *codec); c->codec_id = codec_id; c->bit_rate = 400000; @@ -396,7 +395,7 @@ int main(int argc, char **argv) AVStream *audio_st, *video_st; AVCodec *audio_codec, *video_codec; double audio_pts, video_pts; - int ret, i; + int ret; /* Initialize libavcodec, and register all codecs and formats. */ av_register_all(); @@ -504,18 +503,12 @@ int main(int argc, char **argv) if (audio_st) close_audio(oc, audio_st); - /* Free the streams. */ - for (i = 0; i < oc->nb_streams; i++) { - av_freep(&oc->streams[i]->codec); - av_freep(&oc->streams[i]); - } - if (!(fmt->flags & AVFMT_NOFILE)) /* Close the output file. */ avio_close(oc->pb); /* free the stream */ - av_free(oc); + avformat_free_context(oc); return 0; } diff --git a/mythtv/external/FFmpeg/doc/examples/scaling_video.c b/mythtv/external/FFmpeg/doc/examples/scaling_video.c index 320f4a063a6..be2c510ffa6 100644 --- a/mythtv/external/FFmpeg/doc/examples/scaling_video.c +++ b/mythtv/external/FFmpeg/doc/examples/scaling_video.c @@ -107,7 +107,7 @@ int main(int argc, char **argv) goto end; } - /* buffer is going to be written to rawvideo file, no alignmnet */ + /* buffer is going to be written to rawvideo file, no alignment */ if ((ret = av_image_alloc(dst_data, dst_linesize, dst_w, dst_h, dst_pix_fmt, 1)) < 0) { fprintf(stderr, "Could not allocate destination image\n"); diff --git a/mythtv/external/FFmpeg/doc/faq.texi b/mythtv/external/FFmpeg/doc/faq.texi index da49d318d7a..ebf21f53702 100644 --- a/mythtv/external/FFmpeg/doc/faq.texi +++ b/mythtv/external/FFmpeg/doc/faq.texi @@ -294,8 +294,12 @@ your format doesn't support file level concatenation. @subsection Concatenating using the concat @emph{protocol} (file level) +FFmpeg has a @url{http://ffmpeg.org/ffmpeg-protocols.html#concat, +@code{concat}} protocol designed specifically for that, with examples in the +documentation. + A few multimedia containers (MPEG-1, MPEG-2 PS, DV) allow to concatenate -video by merely concatenating the files them. +video by merely concatenating the files containing them. Hence you may concatenate your multimedia files by first transcoding them to these privileged formats, then using the humble @code{cat} command (or the diff --git a/mythtv/external/FFmpeg/doc/ffmpeg-codecs.texi b/mythtv/external/FFmpeg/doc/ffmpeg-codecs.texi index b6d123a7da4..db20aec84cb 100644 --- a/mythtv/external/FFmpeg/doc/ffmpeg-codecs.texi +++ b/mythtv/external/FFmpeg/doc/ffmpeg-codecs.texi @@ -1098,6 +1098,9 @@ Set sample format audio decoders should prefer. Default value is @code{none}. @item pkt_timebase @var{rational number} + +@item sub_charenc @var{encoding} (@emph{decoding,subtitles}) +Set the input subtitles character encoding. @end table @c man end CODEC OPTIONS diff --git a/mythtv/external/FFmpeg/doc/ffmpeg-formats.texi b/mythtv/external/FFmpeg/doc/ffmpeg-formats.texi index 03e4f30ac31..30cf415d14f 100644 --- a/mythtv/external/FFmpeg/doc/ffmpeg-formats.texi +++ b/mythtv/external/FFmpeg/doc/ffmpeg-formats.texi @@ -77,7 +77,9 @@ Reduce the latency introduced by optional buffering @end table @item analyzeduration @var{integer} (@emph{input}) -Specify how many microseconds are analyzed to estimate duration. +Specify how many microseconds are analyzed to probe the input. A +higher value will allow to detect more accurate information, but will +increase latency. It defaults to 5,000,000 microseconds = 5 seconds. @item cryptokey @var{hexadecimal string} (@emph{input}) Set decryption key. diff --git a/mythtv/external/FFmpeg/doc/ffmpeg-resampler.texi b/mythtv/external/FFmpeg/doc/ffmpeg-resampler.texi index b348373c923..525907a79ff 100644 --- a/mythtv/external/FFmpeg/doc/ffmpeg-resampler.texi +++ b/mythtv/external/FFmpeg/doc/ffmpeg-resampler.texi @@ -43,7 +43,7 @@ value is not mandatory if the corresponding channel layout @option{out_channel_layout} is set. @item uch, used_channel_count -Set the number of used channels. Default value is 0. This option is +Set the number of used input channels. Default value is 0. This option is only used for special remapping. @item isr, in_sample_rate @@ -60,6 +60,7 @@ Specify the output sample format. It is set by default to @code{none}. @item tsf, internal_sample_fmt Set the internal sample format. Default value is @code{none}. +This will automatically be chosen when it is not explicitly set. @item icl, in_channel_layout Set the input channel layout. @@ -68,15 +69,17 @@ Set the input channel layout. Set the output channel layout. @item clev, center_mix_level -Set center mix level. It is a value expressed in deciBel, and must be -inclusively included between -32 and +32. +Set the center mix level. It is a value expressed in deciBel, and must be +in the interval [-32,32]. @item slev, surround_mix_level -Set surround mix level. It is a value expressed in deciBel, and must -be inclusively included between -32 and +32. +Set the surround mix level. It is a value expressed in deciBel, and must +be in the interval [-32,32]. -@item lfe_mix_evel -Set LFE mix level. +@item lfe_mix_level +Set LFE mix into non LFE level. It is used when there is a LFE input but no +LFE output. It is a value expressed in deciBel, and must +be in the interval [-32,32]. @item rmvol, rematrix_volume Set rematrix volume. Default value is 1.0. @@ -87,7 +90,8 @@ Set flags used by the converter. Default value is 0. It supports the following individual flags: @table @option @item res -force resampling +force resampling, this flag forces resampling to be used even when the +input and output sample rates match. @end table @item dither_scale @@ -104,6 +108,21 @@ select rectangular dither select triangular dither @item triangular_hp select triangular dither with high pass +@item lipshitz +select lipshitz noise shaping dither +@item shibata +select shibata noise shaping dither +@item low_shibata +select low shibata noise shaping dither +@item high_shibata +select high shibata noise shaping dither +@item f_weighted +select f-weighted noise shaping dither +@item modified_e_weighted +select modified-e-weighted noise shaping dither +@item improved_e_weighted +select improved-e-weighted noise shaping dither + @end table @item resampler @@ -124,8 +143,8 @@ case. For swr only, set resampling filter size, default value is 32. @item phase_shift -For swr only, set resampling phase shift, default value is 10, must be included -between 0 and 30. +For swr only, set resampling phase shift, default value is 10, and must be in +the interval [0,30]. @item linear_interp Use Linear Interpolation if set to 1, default value is 0. @@ -153,6 +172,14 @@ may be stretched or squeezed for each second. Default value is 0, thus no compensation is applied to make the samples match the audio timestamps. +@item first_pts +For swr only, assume the first pts should be this value. The time unit is 1 / sample rate. +This allows for padding/trimming at the start of stream. By default, no +assumption is made about the first frame's expected pts, so no padding or +trimming is done. For example, this could be set to 0 to pad the beginning with +silence if an audio stream starts after the video stream or to trim any samples +with a negative pts due to encoder delay. + @item min_comp For swr only, set the minimum difference between timestamps and audio data (in seconds) to trigger stretching/squeezing/filling or trimming of the @@ -208,8 +235,8 @@ select Kaiser Windowed Sinc @end table @item kaiser_beta -For swr only, set Kaiser Window Beta value. Must be an integer included between -2 and 16, default value is 9. +For swr only, set Kaiser Window Beta value. Must be an integer in the +interval [2,16], default value is 9. @end table diff --git a/mythtv/external/FFmpeg/doc/ffmpeg.texi b/mythtv/external/FFmpeg/doc/ffmpeg.texi index 0c3cbc3cde0..75631079f1e 100644 --- a/mythtv/external/FFmpeg/doc/ffmpeg.texi +++ b/mythtv/external/FFmpeg/doc/ffmpeg.texi @@ -256,6 +256,14 @@ libx264, and the 138th audio, which will be encoded with libvorbis. Stop writing the output after its duration reaches @var{duration}. @var{duration} may be a number in seconds, or in @code{hh:mm:ss[.xxx]} form. +-to and -t are mutually exclusive and -t has priority. + +@item -to @var{position} (@emph{output}) +Stop writing the output at @var{position}. +@var{position} may be a number in seconds, or in @code{hh:mm:ss[.xxx]} form. + +-to and -t are mutually exclusive and -t has priority. + @item -fs @var{limit_size} (@emph{output}) Set the file size limit, expressed in bytes. @@ -334,13 +342,21 @@ Stop writing to the stream after @var{framecount} frames. Use fixed quality scale (VBR). The meaning of @var{q} is codec-dependent. +@anchor{filter_option} @item -filter[:@var{stream_specifier}] @var{filter_graph} (@emph{output,per-stream}) +Create the filter graph specified by @var{filter_graph} and use it to +filter the stream. + @var{filter_graph} is a description of the filter graph to apply to -the stream. Use @code{-filters} to show all the available filters -(including also sources and sinks). +the stream, and must have a single input and a single output of the +same type of the stream. In the filter graph, the input is associated +to the label @code{in}, and the output to the label @code{out}. See +the ffmpeg-filters manual for more information about the filtergraph +syntax. + +See the @ref{filter_complex_option,,-filter_complex option} if you +want to create filter graphs with multiple inputs and/or outputs. -See also the @option{-filter_complex} option if you want to create filter graphs -with multiple inputs and/or outputs. @item -pre[:@var{stream_specifier}] @var{preset_name} (@emph{output,per-stream}) Specify the preset for matching stream(s). @@ -395,11 +411,11 @@ will be used. E.g. to extract the first attachment to a file named 'out.ttf': @example -ffmpeg -dump_attachment:t:0 out.ttf INPUT +ffmpeg -dump_attachment:t:0 out.ttf -i INPUT @end example To extract all attachments to files determined by the @code{filename} tag: @example -ffmpeg -dump_attachment:t "" INPUT +ffmpeg -dump_attachment:t "" -i INPUT @end example Technical note -- attachments are implemented as codec extradata, so this @@ -443,21 +459,6 @@ form @var{num}:@var{den}, where @var{num} and @var{den} are the numerator and denominator of the aspect ratio. For example "4:3", "16:9", "1.3333", and "1.7777" are valid argument values. -@item -croptop @var{size} -@item -cropbottom @var{size} -@item -cropleft @var{size} -@item -cropright @var{size} -All the crop options have been removed. Use -vf -crop=width:height:x:y instead. - -@item -padtop @var{size} -@item -padbottom @var{size} -@item -padleft @var{size} -@item -padright @var{size} -@item -padcolor @var{hex_color} -All the pad options have been removed. Use -vf -pad=width:height:x:y:color instead. - @item -vn (@emph{output}) Disable video recording. @@ -487,11 +488,10 @@ stream Set the ISO 639 language code (3 letters) of the current video stream. @item -vf @var{filter_graph} (@emph{output}) -@var{filter_graph} is a description of the filter graph to apply to -the input video. -Use the option "-filters" to show all the available filters (including -also sources and sinks). This is an alias for @code{-filter:v}. +Create the filter graph specified by @var{filter_graph} and use it to +filter the stream. +This is an alias for @code{-filter:v}, see the @ref{filter_option,,-filter option}. @end table @section Advanced Video Options @@ -545,12 +545,58 @@ Force video tag/fourcc. This is an alias for @code{-tag:v}. Show QP histogram @item -vbsf @var{bitstream_filter} Deprecated see -bsf + @item -force_key_frames[:@var{stream_specifier}] @var{time}[,@var{time}...] (@emph{output,per-stream}) +@item -force_key_frames[:@var{stream_specifier}] expr:@var{expr} (@emph{output,per-stream}) Force key frames at the specified timestamps, more precisely at the first frames after each specified time. + +If the argument is prefixed with @code{expr:}, the string @var{expr} +is interpreted like an expression and is evaluated for each frame. A +key frame is forced in case the evaluation is non-zero. + +If one of the times is "@code{chapters}[@var{delta}]", it is expanded into +the time of the beginning of all chapters in the file, shifted by +@var{delta}, expressed as a time in seconds. This option can be useful to ensure that a seek point is present at a chapter mark or any other designated place in the output file. -The timestamps must be specified in ascending order. + +For example, to insert a key frame at 5 minutes, plus key frames 0.1 second +before the beginning of every chapter: +@example +-force_key_frames 0:05:00,chapters-0.1 +@end example + +The expression in @var{expr} can contain the following constants: +@table @option +@item n +the number of current processed frame, starting from 0 +@item n_forced +the number of forced frames +@item prev_forced_n +the number of the previous forced frame, it is @code{NAN} when no +keyframe was forced yet +@item prev_forced_t +the time of the previous forced frame, it is @code{NAN} when no +keyframe was forced yet +@item t +the time of the current processed frame +@end table + +For example to force a key frame every 5 seconds, you can specify: +@example +-force_key_frames expr:gte(t,n_forced*5) +@end example + +To force a key frame 5 seconds after the time of the last forced one, +starting from second 13: +@example +-force_key_frames expr:if(isnan(prev_forced_t),gte(t,13),gte(t,prev_forced_t+5)) +@end example + +Note that forcing too many keyframes is very harmful for the lookahead +algorithms of certain encoders: using fixed-GOP options or similar +would be more efficient. @item -copyinkf[:@var{stream_specifier}] (@emph{output,per-stream}) When doing stream copy, copy also non-key frames found at the @@ -581,11 +627,12 @@ Set the audio codec. This is an alias for @code{-codec:a}. @item -sample_fmt[:@var{stream_specifier}] @var{sample_fmt} (@emph{output,per-stream}) Set the audio sample format. Use @code{-sample_fmts} to get a list of supported sample formats. + @item -af @var{filter_graph} (@emph{output}) -@var{filter_graph} is a description of the filter graph to apply to -the input audio. -Use the option "-filters" to show all the available filters (including -also sources and sinks). This is an alias for @code{-filter:a}. +Create the filter graph specified by @var{filter_graph} and use it to +filter the stream. + +This is an alias for @code{-filter:a}, see the @ref{filter_option,,-filter option}. @end table @section Advanced Audio options: @@ -595,6 +642,12 @@ also sources and sinks). This is an alias for @code{-filter:a}. Force audio tag/fourcc. This is an alias for @code{-tag:a}. @item -absf @var{bitstream_filter} Deprecated, see -bsf +@item -guess_layout_max @var{channels} (@emph{input,per-stream}) +If some input channel layout is not known, try to guess only if it +corresponds to at most the specified number of channels. For example, 2 +tells to @command{ffmpeg} to recognize 1 channel as mono and 2 channels as +stereo but not 6 channels as 5.1. The default is to always try to guess. Use +0 to disable all guessing. @end table @section Subtitle options: @@ -928,6 +981,7 @@ Specify Timecode for writing. @var{SEP} is ':' for non drop timecode and ';' ffmpeg -i input.mpg -timecode 01:02:03.04 -r 30000/1001 -s ntsc output.mpg @end example +@anchor{filter_complex_option} @item -filter_complex @var{filtergraph} (@emph{global}) Define a complex filter graph, i.e. one with arbitrary number of inputs and/or outputs. For simple graphs -- those with one input and one output of the same @@ -972,7 +1026,7 @@ ffmpeg -i video.mkv -i image.png -filter_complex 'overlay' out.mkv To generate 5 seconds of pure red video using lavfi @code{color} source: @example -ffmpeg -filter_complex 'color=red' -t 5 out.mkv +ffmpeg -filter_complex 'color=c=red' -t 5 out.mkv @end example @end table @@ -1284,7 +1338,7 @@ ffmpeg -i src.ext -lmax 21*QP2LAMBDA dst.ext @url{ffmpeg-scaler.html,ffmpeg-scaler}, @url{ffmpeg-resampler.html,ffmpeg-resampler}, @url{ffmpeg-codecs.html,ffmpeg-codecs}, -@url{ffmpeg-bitstream-filters,ffmpeg-bitstream-filters}, +@url{ffmpeg-bitstream-filters.html,ffmpeg-bitstream-filters}, @url{ffmpeg-formats.html,ffmpeg-formats}, @url{ffmpeg-devices.html,ffmpeg-devices}, @url{ffmpeg-protocols.html,ffmpeg-protocols}, diff --git a/mythtv/external/FFmpeg/doc/ffplay.texi b/mythtv/external/FFmpeg/doc/ffplay.texi index 0703a549e9a..8d6abee26cd 100644 --- a/mythtv/external/FFmpeg/doc/ffplay.texi +++ b/mythtv/external/FFmpeg/doc/ffplay.texi @@ -74,10 +74,15 @@ You can interactively cycle through the available show modes by pressing the key @key{w}. @item -vf @var{filter_graph} +Create the filter graph specified by @var{filter_graph} and use it to +filter the video stream. + @var{filter_graph} is a description of the filter graph to apply to -the input video. -Use the option "-filters" to show all the available filters (including -also sources and sinks). +the stream, and must have a single video input and a single video +output. In the filter graph, the input is associated to the label +@code{in}, and the output to the label @code{out}. See the +ffmpeg-filters manual for more information about the filtergraph +syntax. @item -i @var{input_file} Read @var{input_file}. @@ -194,7 +199,7 @@ Seek to percentage in file corresponding to fraction of width. @url{ffmpeg-scaler.html,ffmpeg-scaler}, @url{ffmpeg-resampler.html,ffmpeg-resampler}, @url{ffmpeg-codecs.html,ffmpeg-codecs}, -@url{ffmpeg-bitstream-filters,ffmpeg-bitstream-filters}, +@url{ffmpeg-bitstream-filters.html,ffmpeg-bitstream-filters}, @url{ffmpeg-formats.html,ffmpeg-formats}, @url{ffmpeg-devices.html,ffmpeg-devices}, @url{ffmpeg-protocols.html,ffmpeg-protocols}, diff --git a/mythtv/external/FFmpeg/doc/ffprobe.texi b/mythtv/external/FFmpeg/doc/ffprobe.texi index 82a8630f423..6e30b2f43cf 100644 --- a/mythtv/external/FFmpeg/doc/ffprobe.texi +++ b/mythtv/external/FFmpeg/doc/ffprobe.texi @@ -495,7 +495,7 @@ DV, GXF and AVI timecodes are available in format metadata @url{ffmpeg-scaler.html,ffmpeg-scaler}, @url{ffmpeg-resampler.html,ffmpeg-resampler}, @url{ffmpeg-codecs.html,ffmpeg-codecs}, -@url{ffmpeg-bitstream-filters,ffmpeg-bitstream-filters}, +@url{ffmpeg-bitstream-filters.html,ffmpeg-bitstream-filters}, @url{ffmpeg-formats.html,ffmpeg-formats}, @url{ffmpeg-devices.html,ffmpeg-devices}, @url{ffmpeg-protocols.html,ffmpeg-protocols}, diff --git a/mythtv/external/FFmpeg/doc/ffserver.texi b/mythtv/external/FFmpeg/doc/ffserver.texi index 6fa8dc175b4..f1b75994275 100644 --- a/mythtv/external/FFmpeg/doc/ffserver.texi +++ b/mythtv/external/FFmpeg/doc/ffserver.texi @@ -16,34 +16,28 @@ ffserver [@var{options}] @chapter Description @c man begin DESCRIPTION -ffserver is a streaming server for both audio and video. It supports +@command{ffserver} is a streaming server for both audio and video. It +supports several live feeds, streaming from files and time shifting on +live feeds (you can seek to positions in the past on each live feed, +provided you specify a big enough feed storage in +@file{ffserver.conf}). -several live feeds, streaming from files and time shifting on live feeds -(you can seek to positions in the past on each live feed, provided you -specify a big enough feed storage in ffserver.conf). +@command{ffserver} receives prerecorded files or FFM streams from some +@command{ffmpeg} instance as input, then streams them over +RTP/RTSP/HTTP. -This documentation covers only the streaming aspects of ffserver / -ffmpeg. All questions about parameters for ffmpeg, codec questions, -etc. are not covered here. Read @file{ffmpeg.html} for more -information. +An @command{ffserver} instance will listen on some port as specified +in the configuration file. You can launch one or more instances of +@command{ffmpeg} and send one or more FFM streams to the port where +ffserver is expecting to receive them. Alternately, you can make +@command{ffserver} launch such @command{ffmpeg} instances at startup. -@section How does it work? - -ffserver receives prerecorded files or FFM streams from some ffmpeg -instance as input, then streams them over RTP/RTSP/HTTP. - -An ffserver instance will listen on some port as specified in the -configuration file. You can launch one or more instances of ffmpeg and -send one or more FFM streams to the port where ffserver is expecting -to receive them. Alternately, you can make ffserver launch such ffmpeg -instances at startup. - -Input streams are called feeds, and each one is specified by a -section in the configuration file. +Input streams are called feeds, and each one is specified by a +@code{} section in the configuration file. For each feed you can have different output streams in various -formats, each one specified by a section in the configuration -file. +formats, each one specified by a @code{} section in the +configuration file. @section Status stream @@ -79,14 +73,6 @@ web server can be used to serve up the files just as well. It can stream prerecorded video from .ffm files, though it is somewhat tricky to make it work correctly. -@section What do I need? - -I use Linux on a 900 MHz Duron with a cheap Bt848 based TV capture card. I'm -using stock Linux 2.4.17 with the stock drivers. [Actually that isn't true, -I needed some special drivers for my motherboard-based sound card.] - -I understand that FreeBSD systems work just fine as well. - @section How do I make it work? First, build the kit. It *really* helps to have installed LAME first. Then when @@ -235,7 +221,7 @@ of an infinite movie or a whole movie. FFM is version specific, and there is limited compatibility of FFM files generated by one version of ffmpeg/ffserver and another version of -ffmpeg/ffserver. It may work but its not guaranteed to work. +ffmpeg/ffserver. It may work but it is not guaranteed to work. FFM2 is extensible while maintaining compatibility and should work between differing versions of tools. FFM2 is the default. @@ -269,7 +255,7 @@ The @file{doc/ffserver.conf} example, @url{ffmpeg-scaler.html,ffmpeg-scaler}, @url{ffmpeg-resampler.html,ffmpeg-resampler}, @url{ffmpeg-codecs.html,ffmpeg-codecs}, -@url{ffmpeg-bitstream-filters,ffmpeg-bitstream-filters}, +@url{ffmpeg-bitstream-filters.html,ffmpeg-bitstream-filters}, @url{ffmpeg-formats.html,ffmpeg-formats}, @url{ffmpeg-devices.html,ffmpeg-devices}, @url{ffmpeg-protocols.html,ffmpeg-protocols}, diff --git a/mythtv/external/FFmpeg/doc/filter_design.txt b/mythtv/external/FFmpeg/doc/filter_design.txt index 362fce41469..772ca9dfb05 100644 --- a/mythtv/external/FFmpeg/doc/filter_design.txt +++ b/mythtv/external/FFmpeg/doc/filter_design.txt @@ -15,13 +15,13 @@ Format negotiation the list of supported formats. For video links, that means pixel format. For audio links, that means - channel layout, and sample format (the sample packing is implied by the - sample format). + channel layout, sample format (the sample packing is implied by the sample + format) and sample rate. The lists are not just lists, they are references to shared objects. When the negotiation mechanism computes the intersection of the formats - supported at each ends of a link, all references to both lists are - replaced with a reference to the intersection. And when a single format is + supported at each end of a link, all references to both lists are replaced + with a reference to the intersection. And when a single format is eventually chosen for a link amongst the remaining list, again, all references to the list are updated. @@ -68,15 +68,15 @@ Buffer references ownership and permissions Here are the (fairly obvious) rules for reference ownership: - * A reference received by the start_frame or filter_frame method - belong to the corresponding filter. + * A reference received by the filter_frame method (or its start_frame + deprecated version) belongs to the corresponding filter. Special exception: for video references: the reference may be used internally for automatic copying and must not be destroyed before end_frame; it can be given away to ff_start_frame. - * A reference passed to ff_start_frame or ff_filter_frame is given - away and must no longer be used. + * A reference passed to ff_filter_frame (or the deprecated + ff_start_frame) is given away and must no longer be used. * A reference created with avfilter_ref_buffer belongs to the code that created it. @@ -90,27 +90,11 @@ Buffer references ownership and permissions Link reference fields --------------------- - The AVFilterLink structure has a few AVFilterBufferRef fields. Here are - the rules to handle them: - - * cur_buf is set before the start_frame and filter_frame methods to - the same reference given as argument to the methods and belongs to the - destination filter of the link. If it has not been cleared after - end_frame or filter_frame, libavfilter will automatically destroy - the reference; therefore, any filter that needs to keep the reference - for longer must set cur_buf to NULL. - - * out_buf belongs to the source filter of the link and can be used to - store a reference to the buffer that has been sent to the destination. - If it is not NULL after end_frame or filter_frame, libavfilter will - automatically destroy the reference. - - If a video input pad does not have a start_frame method, the default - method will request a buffer on the first output of the filter, store - the reference in out_buf and push a second reference to the output. - - * src_buf, cur_buf_copy and partial_buf are used by libavfilter - internally and must not be accessed by filters. + The AVFilterLink structure has a few AVFilterBufferRef fields. The + cur_buf and out_buf were used with the deprecated + start_frame/draw_slice/end_frame API and should no longer be used. + src_buf, cur_buf_copy and partial_buf are used by libavfilter internally + and must not be accessed by filters. Reference permissions --------------------- @@ -119,8 +103,10 @@ Buffer references ownership and permissions the code that owns the reference is allowed to do to the buffer data. Different references for the same buffer can have different permissions. - For video filters, the permissions only apply to the parts of the buffer - that have already been covered by the draw_slice method. + For video filters that implement the deprecated + start_frame/draw_slice/end_frame API, the permissions only apply to the + parts of the buffer that have already been covered by the draw_slice + method. The value is a binary OR of the following constants: @@ -179,9 +165,9 @@ Buffer references ownership and permissions with the WRITE permission. * Filters that intend to keep a reference after the filtering process - is finished (after end_frame or filter_frame returns) must have the - PRESERVE permission on it and remove the WRITE permission if they - create a new reference to give it away. + is finished (after filter_frame returns) must have the PRESERVE + permission on it and remove the WRITE permission if they create a new + reference to give it away. * Filters that intend to modify a reference they have kept after the end of the filtering process need the REUSE2 permission and must remove @@ -198,11 +184,11 @@ Frame scheduling Simple filters that output one frame for each input frame should not have to worry about it. - start_frame / filter_frame - ---------------------------- + filter_frame + ------------ - These methods are called when a frame is pushed to the filter's input. - They can be called at any time except in a reentrant way. + This method is called when a frame is pushed to the filter's input. It + can be called at any time except in a reentrant way. If the input frame is enough to produce output, then the filter should push the output frames on the output link immediately. @@ -213,7 +199,7 @@ Frame scheduling filter; these buffered frames must be flushed immediately if a new input produces new output. - (Example: framerate-doubling filter: start_frame must (1) flush the + (Example: framerate-doubling filter: filter_frame must (1) flush the second copy of the previous frame, if it is still there, (2) push the first copy of the incoming frame, (3) keep the second copy for later.) @@ -233,8 +219,8 @@ Frame scheduling This method is called when a frame is wanted on an output. - For an input, it should directly call start_frame or filter_frame on - the corresponding output. + For an input, it should directly call filter_frame on the corresponding + output. For a filter, if there are queued frames already ready, one of these frames should be pushed. If not, the filter should request a frame on @@ -255,7 +241,7 @@ Frame scheduling } while (!frame_pushed) { input = input_where_a_frame_is_most_needed(); - ret = avfilter_request_frame(input); + ret = ff_request_frame(input); if (ret == AVERROR_EOF) { process_eof_on_input(); } else if (ret < 0) { @@ -266,4 +252,14 @@ Frame scheduling Note that, except for filters that can have queued frames, request_frame does not push frames: it requests them to its input, and as a reaction, - the start_frame / filter_frame method will be called and do the work. + the filter_frame method will be called and do the work. + +Legacy API +========== + + Until libavfilter 3.23, the filter_frame method was split: + + - for video filters, it was made of start_frame, draw_slice (that could be + called several times on distinct parts of the frame) and end_frame; + + - for audio filters, it was called filter_samples. diff --git a/mythtv/external/FFmpeg/doc/filters.texi b/mythtv/external/FFmpeg/doc/filters.texi index 9d6c2b86e55..b170f850e7e 100644 --- a/mythtv/external/FFmpeg/doc/filters.texi +++ b/mythtv/external/FFmpeg/doc/filters.texi @@ -266,7 +266,7 @@ or the corresponding number value defined in @file{libavutil/channel_layout.h}. The special parameter "auto", signifies that the filter will automatically select the output format depending on the output filter. -Some examples follow. +@subsection Examples @itemize @item @@ -282,6 +282,386 @@ aconvert=u8:auto @end example @end itemize +@section allpass + +Apply a two-pole all-pass filter with central frequency (in Hz) +@var{frequency}, and filter-width @var{width}. +An all-pass filter changes the audio's frequency to phase relationship +without changing its frequency to amplitude relationship. + +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". + +A description of the accepted parameters follows. + +@table @option +@item frequency, f +Set frequency in Hz. + +@item width_type +Set method to specify band-width of filter. +@table @option +@item h +Hz +@item q +Q-Factor +@item o +octave +@item s +slope +@end table + +@item width, w +Specify the band-width of a filter in width_type units. +@end table + +@section highpass + +Apply a high-pass filter with 3dB point frequency. +The filter can be either single-pole, or double-pole (the default). +The filter roll off at 6dB per pole per octave (20dB per pole per decade). + +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". + +A description of the accepted parameters follows. + +@table @option +@item frequency, f +Set frequency in Hz. Default is 3000. + +@item poles, p +Set number of poles. Default is 2. + +@item width_type +Set method to specify band-width of filter. +@table @option +@item h +Hz +@item q +Q-Factor +@item o +octave +@item s +slope +@end table + +@item width, w +Specify the band-width of a filter in width_type units. +Applies only to double-pole filter. +The default is 0.707q and gives a Butterworth response. +@end table + +@section lowpass + +Apply a low-pass filter with 3dB point frequency. +The filter can be either single-pole or double-pole (the default). +The filter roll off at 6dB per pole per octave (20dB per pole per decade). + +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". + +A description of the accepted parameters follows. + +@table @option +@item frequency, f +Set frequency in Hz. Default is 500. + +@item poles, p +Set number of poles. Default is 2. + +@item width_type +Set method to specify band-width of filter. +@table @option +@item h +Hz +@item q +Q-Factor +@item o +octave +@item s +slope +@end table + +@item width, w +Specify the band-width of a filter in width_type units. +Applies only to double-pole filter. +The default is 0.707q and gives a Butterworth response. +@end table + +@section bass + +Boost or cut the bass (lower) frequencies of the audio using a two-pole +shelving filter with a response similar to that of a standard +hi-fi's tone-controls. This is also known as shelving equalisation (EQ). + +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". + +A description of the accepted parameters follows. + +@table @option +@item gain, g +Give the gain at 0 Hz. Its useful range is about -20 +(for a large cut) to +20 (for a large boost). +Beware of clipping when using a positive gain. + +@item frequency, f +Set the filter's central frequency and so can be used +to extend or reduce the frequency range to be boosted or cut. +The default value is @code{100} Hz. + +@item width_type +Set method to specify band-width of filter. +@table @option +@item h +Hz +@item q +Q-Factor +@item o +octave +@item s +slope +@end table + +@item width, w +Determine how steep is the filter's shelf transition. +@end table + +@section treble + +Boost or cut treble (upper) frequencies of the audio using a two-pole +shelving filter with a response similar to that of a standard +hi-fi's tone-controls. This is also known as shelving equalisation (EQ). + +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". + +A description of the accepted parameters follows. + +@table @option +@item gain, g +Give the gain at whichever is the lower of ~22 kHz and the +Nyquist frequency. Its useful range is about -20 (for a large cut) +to +20 (for a large boost). Beware of clipping when using a positive gain. + +@item frequency, f +Set the filter's central frequency and so can be used +to extend or reduce the frequency range to be boosted or cut. +The default value is @code{3000} Hz. + +@item width_type +Set method to specify band-width of filter. +@table @option +@item h +Hz +@item q +Q-Factor +@item o +octave +@item s +slope +@end table + +@item width, w +Determine how steep is the filter's shelf transition. +@end table + +@section bandpass + +Apply a two-pole Butterworth band-pass filter with central +frequency @var{frequency}, and (3dB-point) band-width width. +The @var{csg} option selects a constant skirt gain (peak gain = Q) +instead of the default: constant 0dB peak gain. +The filter roll off at 6dB per octave (20dB per decade). + +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". + +A description of the accepted parameters follows. + +@table @option +@item frequency, f +Set the filter's central frequency. Default is @code{3000}. + +@item csg +Constant skirt gain if set to 1. Defaults to 0. + +@item width_type +Set method to specify band-width of filter. +@table @option +@item h +Hz +@item q +Q-Factor +@item o +octave +@item s +slope +@end table + +@item width, w +Specify the band-width of a filter in width_type units. +@end table + +@section bandreject + +Apply a two-pole Butterworth band-reject filter with central +frequency @var{frequency}, and (3dB-point) band-width @var{width}. +The filter roll off at 6dB per octave (20dB per decade). + +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". + +A description of the accepted parameters follows. + +@table @option +@item frequency, f +Set the filter's central frequency. Default is @code{3000}. + +@item width_type +Set method to specify band-width of filter. +@table @option +@item h +Hz +@item q +Q-Factor +@item o +octave +@item s +slope +@end table + +@item width, w +Specify the band-width of a filter in width_type units. +@end table + +@section biquad + +Apply a biquad IIR filter with the given coefficients. +Where @var{b0}, @var{b1}, @var{b2} and @var{a0}, @var{a1}, @var{a2} +are the numerator and denominator coefficients respectively. + +@section equalizer + +Apply a two-pole peaking equalisation (EQ) filter. With this +filter, the signal-level at and around a selected frequency can +be increased or decreased, whilst (unlike bandpass and bandreject +filters) that at all other frequencies is unchanged. + +In order to produce complex equalisation curves, this filter can +be given several times, each with a different central frequency. + +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". + +A description of the accepted parameters follows. + +@table @option +@item frequency, f +Set the filter's central frequency in Hz. + +@item width_type +Set method to specify band-width of filter. +@table @option +@item h +Hz +@item q +Q-Factor +@item o +octave +@item s +slope +@end table + +@item width, w +Specify the band-width of a filter in width_type units. + +@item gain, g +Set the required gain or attenuation in dB. +Beware of clipping when using a positive gain. +@end table + +@section afade + +Apply fade-in/out effect to input audio. + +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". + +A description of the accepted parameters follows. + +@table @option +@item type, t +Specify the effect type, can be either @code{in} for fade-in, or +@code{out} for a fade-out effect. Default is @code{in}. + +@item start_sample, ss +Specify the number of the start sample for starting to apply the fade +effect. Default is 0. + +@item nb_samples, ns +Specify the number of samples for which the fade effect has to last. At +the end of the fade-in effect the output audio will have the same +volume as the input audio, at the end of the fade-out transition +the output audio will be silence. Default is 44100. + +@item start_time, st +Specify time in seconds for starting to apply the fade +effect. Default is 0. +If set this option is used instead of @var{start_sample} one. + +@item duration, d +Specify the number of seconds for which the fade effect has to last. At +the end of the fade-in effect the output audio will have the same +volume as the input audio, at the end of the fade-out transition +the output audio will be silence. Default is 0. +If set this option is used instead of @var{nb_samples} one. + +@item curve +Set curve for fade transition. + +It accepts the following values: +@table @option +@item tri +select triangular, linear slope (default) +@item qsin +select quarter of sine wave +@item hsin +select half of sine wave +@item esin +select exponential sine wave +@item log +select logarithmic +@item par +select inverted parabola +@item qua +select quadratic +@item cub +select cubic +@item squ +select square root +@item cbr +select cubic root +@end table +@end table + +@subsection Examples + +@itemize +@item +Fade in first 15 seconds of audio: +@example +afade=t=in:ss=0:d=15 +@end example + +@item +Fade out last 25 seconds of a 900 seconds audio: +@example +afade=t=out:ss=875:d=25 +@end example +@end itemize + @section aformat Set output format constraints for the input audio. The framework will @@ -343,12 +723,17 @@ All inputs must have the same sample rate, and format. If inputs do not have the same duration, the output will stop with the shortest. -Example: merge two mono files into a stereo stream: +@subsection Examples + +@itemize +@item +Merge two mono files into a stereo stream: @example amovie=left.wav [l] ; amovie=right.mp3 [r] ; [l] [r] amerge @end example -Example: multiple merges: +@item +Multiple merges: @example ffmpeg -f lavfi -i " amovie=input.mkv:si=0 [a0]; @@ -359,6 +744,7 @@ amovie=input.mkv:si=4 [a4]; amovie=input.mkv:si=5 [a5]; [a0][a1][a2][a3][a4][a5] amerge=inputs=6" -c:a pcm_s16le output.mkv @end example +@end itemize @section amix @@ -424,16 +810,22 @@ expresses a sample rate and @var{resampler_options} is a list of @var{key}=@var{value} pairs, separated by ":". See the ffmpeg-resampler manual for the complete list of supported options. -For example, to resample the input audio to 44100Hz: +@subsection Examples + +@itemize +@item +Resample the input audio to 44100Hz: @example aresample=44100 @end example -To stretch/squeeze samples to the given timestamps, with a maximum of 1000 +@item +Stretch/squeeze samples to the given timestamps, with a maximum of 1000 samples per second compensation: @example aresample=async=1000 @end example +@end itemize @section asetnsamples @@ -573,15 +965,21 @@ The filter accepts exactly one parameter, the audio tempo. If not specified then the filter will assume nominal 1.0 tempo. Tempo must be in the [0.5, 2.0] range. -For example, to slow down audio to 80% tempo: +@subsection Examples + +@itemize +@item +Slow down audio to 80% tempo: @example atempo=0.8 @end example -For example, to speed up audio to 125% tempo: +@item +To speed up audio to 125% tempo: @example atempo=1.25 @end example +@end itemize @section earwax @@ -703,22 +1101,28 @@ Set noise tolerance. Can be specified in dB (in case "dB" is appended to the specified value) or amplitude ratio. Default is -60dB, or 0.001. @end table +@subsection Examples + +@itemize +@item Detect 5 seconds of silence with -50dB noise tolerance: @example silencedetect=n=-50dB:d=5 @end example +@item Complete example with @command{ffmpeg} to detect silence with 0.0001 noise tolerance in @file{silence.mp3}: @example ffmpeg -f lavfi -i amovie=silence.mp3,silencedetect=noise=0.0001 -f null - @end example +@end itemize @section asyncts Synchronize audio data with timestamps by squeezing/stretching it and/or dropping samples/adding silence when needed. -As an alternative, you can use @ref{aresample} to do squeezing/stretching. +This filter is not built by default, please use @ref{aresample} to do squeezing/stretching. The filter accepts the following named parameters: @table @option @@ -924,6 +1328,8 @@ the samples). All volumes are in decibels relative to the maximum PCM value. +@subsection Examples + Here is an excerpt of the output: @example [Parsed_volumedetect_0 @ 0xa23120] mean_volume: -27 dB @@ -983,9 +1389,15 @@ Either a channel layout name from channel_layout_map in @file{libavutil/channel_layout.c} or its corresponding integer representation from the AV_CH_LAYOUT_* macros in @file{libavutil/channel_layout.h} +@item channels +The number of channels of the incoming audio buffers. +If both @var{channels} and @var{channel_layout} are specified, then they +must be consistent. + @end table -For example: +@subsection Examples + @example abuffer=44100:s16p:stereo @end example @@ -1058,7 +1470,6 @@ sample rate @subsection Examples @itemize - @item Generate silence: @example @@ -1066,7 +1477,6 @@ aevalsrc=0 @end example @item - Generate a sin signal with frequency of 440 Hz, set sample rate to 8000 Hz: @example @@ -1132,14 +1542,21 @@ Set the number of samples per requested frames. @end table -Follow some examples: +@subsection Examples + +@itemize +@item +Set the sample rate to 48000 Hz and the channel layout to AV_CH_LAYOUT_MONO. @example -# set the sample rate to 48000 Hz and the channel layout to AV_CH_LAYOUT_MONO. anullsrc=r=48000:cl=4 +@end example -# same as +@item +Do the same operation with a more obvious syntax: +@example anullsrc=r=48000:cl=mono @end example +@end itemize @section abuffer Buffer audio frames, and make them available to the filter chain. @@ -1394,21 +1811,143 @@ threshold, and defaults to 98. @var{threshold} is the threshold below which a pixel value is considered black, and defaults to 32. +@section blend + +Blend two video frames into each other. + +It takes two input streams and outputs one stream, the first input is the +"top" layer and second input is "bottom" layer. +Output terminates when shortest input terminates. + +This filter accepts a list of options in the form of @var{key}=@var{value} +pairs separated by ":". A description of the accepted options follows. + +@table @option +@item c0_mode +@item c1_mode +@item c2_mode +@item c3_mode +@item all_mode +Set blend mode for specific pixel component or all pixel components in case +of @var{all_mode}. Default value is @code{normal}. + +Available values for component modes are: +@table @samp +@item addition +@item and +@item average +@item burn +@item darken +@item difference +@item divide +@item dodge +@item exclusion +@item hardlight +@item lighten +@item multiply +@item negation +@item normal +@item or +@item overlay +@item phoenix +@item pinlight +@item reflect +@item screen +@item softlight +@item subtract +@item vividlight +@item xor +@end table + +@item c0_opacity +@item c1_opacity +@item c2_opacity +@item c3_opacity +@item all_opacity +Set blend opacity for specific pixel component or all pixel components in case +of @var{all_expr}. Only used in combination with pixel component blend modes. + +@item c0_expr +@item c1_expr +@item c2_expr +@item c3_expr +@item all_expr +Set blend expression for specific pixel component or all pixel components in case +of @var{all_expr}. Note that related mode options will be ignored if those are set. + +The expressions can use the following variables: + +@table @option +@item X +@item Y +the coordinates of the current sample + +@item W +@item H +the width and height of currently filtered plane + +@item SW +@item SH +Width and height scale depending on the currently filtered plane. It is the +ratio between the corresponding luma plane number of pixels and the current +plane ones. E.g. for YUV4:2:0 the values are @code{1,1} for the luma plane, and +@code{0.5,0.5} for chroma planes. + +@item T +Time of the current frame, expressed in seconds. + +@item TOP, A +Value of pixel component at current location for first video frame (top layer). + +@item BOTTOM, B +Value of pixel component at current location for second video frame (bottom layer). +@end table +@end table + +@subsection Examples + +@itemize +@item +Apply transition from bottom layer to top layer in first 10 seconds: +@example +blend=all_expr='A*(if(gte(T,10),1,T/10))+B*(1-(if(gte(T,10),1,T/10)))' +@end example + +@item +Apply 1x1 checkerboard effect: +@example +blend=all_expr='if(eq(mod(X,2),mod(Y,2)),A,B)' +@end example +@end itemize + @section boxblur Apply boxblur algorithm to the input video. -This filter accepts the parameters: -@var{luma_radius}:@var{luma_power}:@var{chroma_radius}:@var{chroma_power}:@var{alpha_radius}:@var{alpha_power} +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". If the key of the first options is omitted, +the arguments are interpreted according to the syntax +@option{luma_radius}:@option{luma_power}:@option{chroma_radius}:@option{chroma_power}:@option{alpha_radius}:@option{alpha_power}. -Chroma and alpha parameters are optional, if not specified they default -to the corresponding values set for @var{luma_radius} and -@var{luma_power}. +A description of the accepted options follows. -@var{luma_radius}, @var{chroma_radius}, and @var{alpha_radius} represent -the radius in pixels of the box used for blurring the corresponding -input plane. They are expressions, and can contain the following -constants: +@table @option +@item luma_radius, lr +@item chroma_radius, cr +@item alpha_radius, ar +Set an expression for the box radius in pixels used for blurring the +corresponding input plane. + +The radius value must be a non-negative number, and must not be +greater than the value of the expression @code{min(w,h)/2} for the +luma and alpha planes, and of @code{min(cw,ch)/2} for the chroma +planes. + +Default value for @option{luma_radius} is "2". If not specified, +@option{chroma_radius} and @option{alpha_radius} default to the +corresponding value set for @option{luma_radius}. + +The expressions can contain the following constants: @table @option @item w, h the input width and height in pixels @@ -1421,18 +1960,22 @@ horizontal and vertical chroma subsample values. For example for the pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1. @end table -The radius must be a non-negative number, and must not be greater than -the value of the expression @code{min(w,h)/2} for the luma and alpha planes, -and of @code{min(cw,ch)/2} for the chroma planes. +@item luma_power, lp +@item chroma_power, cp +@item alpha_power, ap +Specify how many times the boxblur filter is applied to the +corresponding plane. -@var{luma_power}, @var{chroma_power}, and @var{alpha_power} represent -how many times the boxblur filter is applied to the corresponding -plane. +Default value for @option{luma_power} is 2. If not specified, +@option{chroma_power} and @option{alpha_power} default to the +corresponding value set for @option{luma_power}. + +A value of 0 will disable the effect. +@end table -Some examples follow: +@subsection Examples @itemize - @item Apply a boxblur filter with luma, chroma, and alpha radius set to 2: @@ -1441,17 +1984,16 @@ boxblur=2:1 @end example @item -Set luma radius to 2, alpha and chroma radius to 0 +Set luma radius to 2, alpha and chroma radius to 0: @example -boxblur=2:1:0:0:0:0 +boxblur=2:1:cr=0:ar=0 @end example @item -Set luma and chroma radius to a fraction of the video dimension +Set luma and chroma radius to a fraction of the video dimension: @example boxblur=min(h\,w)/10:1:min(cw\,ch)/10:1 @end example - @end itemize @section colormatrix @@ -1566,6 +2108,7 @@ The expression for @var{x} may depend on @var{y}, and the expression for @var{y} may depend on @var{x}. @subsection Examples + @itemize @item Crop area with size 100x100 at position (12,34). @@ -1679,17 +2222,21 @@ playback. @section decimate -This filter drops frames that do not differ greatly from the previous -frame in order to reduce framerate. The main use of this filter is -for very-low-bitrate encoding (e.g. streaming over dialup modem), but -it could in theory be used for fixing movies that were -inverse-telecined incorrectly. +Drop frames that do not differ greatly from the previous frame in +order to reduce framerate. -It accepts the following parameters: -@var{max}:@var{hi}:@var{lo}:@var{frac}. +The main use of this filter is for very-low-bitrate encoding +(e.g. streaming over dialup modem), but it could in theory be used for +fixing movies that were inverse-telecined incorrectly. -@table @option +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". If the key of the first options is omitted, +the arguments are interpreted according to the syntax: +@option{max}:@option{hi}:@option{lo}:@option{frac}. +A description of the accepted options follows. + +@table @option @item max Set the maximum number of consecutive frames which can be dropped (if positive), or the minimum interval between dropped frames (if @@ -1698,20 +2245,22 @@ number of previous sequentially dropped frames. Default value is 0. -@item hi, lo, frac +@item hi +@item lo +@item frac Set the dropping threshold values. -Values for @var{hi} and @var{lo} are for 8x8 pixel blocks and +Values for @option{hi} and @option{lo} are for 8x8 pixel blocks and represent actual pixel value differences, so a threshold of 64 corresponds to 1 unit of difference for each pixel, or the same spread out differently over the block. A frame is a candidate for dropping if no 8x8 blocks differ by more -than a threshold of @var{hi}, and if no more than @var{frac} blocks (1 -meaning the whole image) differ by more than a threshold of @var{lo}. +than a threshold of @option{hi}, and if no more than @option{frac} blocks (1 +meaning the whole image) differ by more than a threshold of @option{lo}. -Default value for @var{hi} is 64*12, default value for @var{lo} is -64*5, and default value for @var{frac} is 0.33. +Default value for @option{hi} is 64*12, default value for @option{lo} is +64*5, and default value for @option{frac} is 0.33. @end table @section delogo @@ -1747,10 +2296,9 @@ finding the right @var{x}, @var{y}, @var{w}, @var{h} parameters, and @end table -Some examples follow. +@subsection Examples @itemize - @item Set a rectangle covering the area with top left corner coordinates 0,0 and size 100x77, setting a band of size 10: @@ -1772,8 +2320,10 @@ Attempt to fix small changes in horizontal and/or vertical shift. This filter helps remove camera shake from hand-holding a camera, bumping a tripod, moving on a vehicle, etc. -The filter accepts parameters as a string of the form -"@var{x}:@var{y}:@var{w}:@var{h}:@var{rx}:@var{ry}:@var{edge}:@var{blocksize}:@var{contrast}:@var{search}:@var{filename}" +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". If the key of the first options is omitted, +the arguments are interpreted according to the syntax +@var{x}:@var{y}:@var{w}:@var{h}:@var{rx}:@var{ry}:@var{edge}:@var{blocksize}:@var{contrast}:@var{search}:@var{filename}. A description of the accepted parameters follows. @@ -1803,19 +2353,18 @@ range 0-64 pixels. Default 16. @item edge Specify how to generate pixels to fill blanks at the edge of the -frame. An integer from 0 to 3 as follows: -@table @option -@item 0 +frame. Available values are: +@table @samp +@item blank, 0 Fill zeroes at blank locations -@item 1 +@item original, 1 Original image at blank locations -@item 2 +@item clamp, 2 Extruded edge value at blank locations -@item 3 +@item mirror, 3 Mirrored edge at blank locations @end table - -The default setting is mirror edge at blank locations. +Default value is @samp{mirror}. @item blocksize Specify the blocksize to use for motion search. Range 4-128 pixels, @@ -1827,8 +2376,14 @@ the specified contrast (difference between darkest and lightest pixels) will be considered. Range 1-255, default 125. @item search -Specify the search strategy 0 = exhaustive search, 1 = less exhaustive -search. Default - exhaustive search. +Specify the search strategy. Available values are: +@table @samp +@item exhaustive, 0 +Set exhaustive search +@item less, 1 +Set less exhaustive search. +@end table +Default value is @samp{exhaustive}. @item filename If set then a detailed log of the motion search is written to the @@ -1840,10 +2395,12 @@ specified file. Draw a colored box on the input image. -The filter accepts parameters as a list of @var{key}=@var{value} pairs, -separated by ":". +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". If the key of the first options is omitted, +the arguments are interpreted according to the syntax +@option{x}:@option{y}:@option{width}:@option{height}:@option{color}:@option{thickness}. -The description of the accepted parameters follows. +A description of the accepted options follows. @table @option @item x, y @@ -1864,13 +2421,8 @@ video with inverted luma. Set the thickness of the box edge. Default value is @code{4}. @end table -If the key of the first options is omitted, the arguments are -interpreted according to the following syntax: -@example -drawbox=@var{x}:@var{y}:@var{width}:@var{height}:@var{color}:@var{thickness} -@end example +@subsection Examples -Some examples follow: @itemize @item Draw a black box around the edge of the input image: @@ -1937,8 +2489,8 @@ See below for the list of accepted constants and functions. @item expansion Select how the @var{text} is expanded. Can be either @code{none}, -@code{strftime} (default for compatibity reasons but deprecated) or -@code{normal}. See the @ref{drawtext_expansion, Text expansion} section +@code{strftime} (deprecated) or +@code{normal} (default). See the @ref{drawtext_expansion, Text expansion} section below for details. @item fix_bounds @@ -2112,14 +2664,14 @@ If libavfilter was built with @code{--enable-fontconfig}, then @anchor{drawtext_expansion} @subsection Text expansion -If @option{expansion} is set to @code{strftime} (which is the default for -now), the filter recognizes strftime() sequences in the provided text and +If @option{expansion} is set to @code{strftime}, +the filter recognizes strftime() sequences in the provided text and expands them accordingly. Check the documentation of strftime(). This feature is deprecated. If @option{expansion} is set to @code{none}, the text is printed verbatim. -If @option{expansion} is set to @code{normal} (which will be the default), +If @option{expansion} is set to @code{normal} (which is the default), the following expansion mechanism is used. The backslash character '\', followed by any character, always expands to @@ -2168,10 +2720,7 @@ The timestamp of the current frame, in seconds, with microsecond accuracy. @subsection Examples -Some examples follow. - @itemize - @item Draw "Test Text" with font FreeSerif, using the default values for the optional parameters. @@ -2236,7 +2785,7 @@ drawtext='fontfile=Linux Libertine O-40\:style=Semibold:text=FFmpeg' @item Print the date of a real-time encoding (see strftime(3)): @example -drawtext='fontfile=FreeSans.ttf:expansion=normal:text=%@{localtime:%a %b %d %Y@}' +drawtext='fontfile=FreeSans.ttf:text=%@{localtime:%a %b %d %Y@}' @end example @end itemize @@ -2278,56 +2827,71 @@ edgedetect=low=0.1:high=0.4 Apply fade-in/out effect to input video. -It accepts the parameters: -@var{type}:@var{start_frame}:@var{nb_frames}[:@var{options}] - -@var{type} specifies if the effect type, can be either "in" for -fade-in, or "out" for a fade-out effect. - -@var{start_frame} specifies the number of the start frame for starting -to apply the fade effect. - -@var{nb_frames} specifies the number of frames for which the fade -effect has to last. At the end of the fade-in effect the output video -will have the same intensity as the input video, at the end of the -fade-out transition the output video will be completely black. +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". If the key of the first options is omitted, +the arguments are interpreted according to the syntax +@var{type}:@var{start_frame}:@var{nb_frames}. -@var{options} is an optional sequence of @var{key}=@var{value} pairs, -separated by ":". The description of the accepted options follows. +A description of the accepted parameters follows. @table @option - @item type, t -See @var{type}. +Specify if the effect type, can be either @code{in} for fade-in, or +@code{out} for a fade-out effect. Default is @code{in}. @item start_frame, s -See @var{start_frame}. +Specify the number of the start frame for starting to apply the fade +effect. Default is 0. @item nb_frames, n -See @var{nb_frames}. +Specify the number of frames for which the fade effect has to last. At +the end of the fade-in effect the output video will have the same +intensity as the input video, at the end of the fade-out transition +the output video will be completely black. Default is 25. @item alpha If set to 1, fade only alpha channel, if one exists on the input. Default value is 0. @end table -A few usage examples follow, usable too as test scenarios. +@subsection Examples + +@itemize +@item +Fade in first 30 frames of video: @example -# fade in first 30 frames of video fade=in:0:30 +@end example -# fade out last 45 frames of a 200-frame video +The command above is equivalent to: +@example +fade=t=in:s=0:n=30 +@end example + +@item +Fade out last 45 frames of a 200-frame video: +@example fade=out:155:45 +@end example -# fade in first 25 frames and fade out last 25 frames of a 1000-frame video +@item +Fade in first 25 frames and fade out last 25 frames of a 1000-frame video: +@example fade=in:0:25, fade=out:975:25 +@end example -# make first 5 frames black, then fade in from frame 5-24 +@item +Make first 5 frames black, then fade in from frame 5-24: +@example fade=in:5:20 +@end example -# fade in alpha over first 25 frames of video +@item +Fade in alpha over first 25 frames of video: +@example fade=in:0:25:alpha=1 @end example +@end itemize @section field @@ -2405,14 +2969,20 @@ the next filter. The filter accepts a list of pixel format names, separated by ":", for example "yuv420p:monow:rgb24". -Some examples follow: +@subsection Examples + +@itemize +@item +Convert the input video to the format @var{yuv420p} @example -# convert the input video to the format "yuv420p" format=yuv420p +@end example -# convert the input video to any of the formats in the list +Convert the input video to any of the formats in the list +@example format=yuv420p:yuv444p:yuv410p @end example +@end itemize @section fps @@ -2491,7 +3061,7 @@ description), a position (specified by the syntax @var{X}/@var{Y}, The number and kind of parameters depend on the loaded effect. If an effect parameter is not specified the default value is set. -Some examples follow: +@subsection Examples @itemize @item @@ -2521,7 +3091,7 @@ For more information see: @section geq -The filter takes one, two or three equations as parameter, separated by ':'. +The filter takes one, two, three or four equations as parameter, separated by ':'. The first equation is mandatory and applies to the luma plane. The two following are respectively for chroma blue and chroma red planes. @@ -2534,11 +3104,14 @@ the luminance expression the chrominance blue expression @item cr_expr the chrominance red expression +@item alpha_expr +the alpha expression @end table If one of the chrominance expression is not defined, it falls back on the other -one. If none of them are specified, they will evaluate the luminance -expression. +one. If no alpha expression is specified it will evaluate to opaque value. +If none of chrominance expressions are +specified, they will evaluate the luminance expression. The expressions can use the following variables and functions: @@ -2571,17 +3144,21 @@ plane. @item cb(x, y) Return the value of the pixel at location (@var{x},@var{y}) of the -blue-difference chroma plane. +blue-difference chroma plane. Returns 0 if there is no such plane. @item cr(x, y) Return the value of the pixel at location (@var{x},@var{y}) of the -red-difference chroma plane. +red-difference chroma plane. Returns 0 if there is no such plane. + +@item alpha(x, y) +Return the value of the pixel at location (@var{x},@var{y}) of the alpha +plane. Returns 0 if there is no such plane. @end table For functions, if @var{x} and @var{y} are outside the area, the value will be automatically clipped to the closer edge. -Some examples follow: +@subsection Examples @itemize @item @@ -2702,6 +3279,121 @@ the histogram. Possible values are @code{none}, @code{weak} or @code{strong}. It defaults to @code{none}. @end table +@section histogram + +Compute and draw a color distribution histogram for the input video. + +The computed histogram is a representation of distribution of color components +in an image. + +The filter accepts the following named parameters: + +@table @option +@item mode +Set histogram mode. + +It accepts the following values: +@table @samp +@item levels +standard histogram that display color components distribution in an image. +Displays color graph for each color component. Shows distribution +of the Y, U, V, A or G, B, R components, depending on input format, +in current frame. Bellow each graph is color component scale meter. + +@item color +chroma values in vectorscope, if brighter more such chroma values are +distributed in an image. +Displays chroma values (U/V color placement) in two dimensional graph +(which is called a vectorscope). It can be used to read of the hue and +saturation of the current frame. At a same time it is a histogram. +The whiter a pixel in the vectorscope, the more pixels of the input frame +correspond to that pixel (that is the more pixels have this chroma value). +The V component is displayed on the horizontal (X) axis, with the leftmost +side being V = 0 and the rightmost side being V = 255. +The U component is displayed on the vertical (Y) axis, with the top +representing U = 0 and the bottom representing U = 255. + +The position of a white pixel in the graph corresponds to the chroma value +of a pixel of the input clip. So the graph can be used to read of the +hue (color flavor) and the saturation (the dominance of the hue in the color). +As the hue of a color changes, it moves around the square. At the center of +the square, the saturation is zero, which means that the corresponding pixel +has no color. If you increase the amount of a specific color, while leaving +the other colors unchanged, the saturation increases, and you move towards +the edge of the square. + +@item color2 +chroma values in vectorscope, similar as @code{color} but actual chroma values +are displayed. + +@item waveform +per row/column color component graph. In row mode graph in the left side represents +color component value 0 and right side represents value = 255. In column mode top +side represents color component value = 0 and bottom side represents value = 255. +@end table +Default value is @code{levels}. + +@item level_height +Set height of level in @code{levels}. Default value is @code{200}. +Allowed range is [50, 2048]. + +@item scale_height +Set height of color scale in @code{levels}. Default value is @code{12}. +Allowed range is [0, 40]. + +@item step +Set step for @code{waveform} mode. Smaller values are useful to find out how much +of same luminance values across input rows/columns are distributed. +Default value is @code{10}. Allowed range is [1, 255]. + +@item waveform_mode +Set mode for @code{waveform}. Can be either @code{row}, or @code{column}. +Default is @code{row}. + +@item display_mode +Set display mode for @code{waveform} and @code{levels}. +It accepts the following values: +@table @samp +@item parade +Display separate graph for the color components side by side in +@code{row} waveform mode or one below other in @code{column} waveform mode +for @code{waveform} histogram mode. For @code{levels} histogram mode +per color component graphs are placed one bellow other. + +This display mode in @code{waveform} histogram mode makes it easy to spot +color casts in the highlights and shadows of an image, by comparing the +contours of the top and the bottom of each waveform. +Since whites, grays, and blacks are characterized by +exactly equal amounts of red, green, and blue, neutral areas of the +picture should display three waveforms of roughly equal width/height. +If not, the correction is easy to make by making adjustments to level the +three waveforms. + +@item overlay +Presents information that's identical to that in the @code{parade}, except +that the graphs representing color components are superimposed directly +over one another. + +This display mode in @code{waveform} histogram mode can make it easier to spot +the relative differences or similarities in overlapping areas of the color +components that are supposed to be identical, such as neutral whites, grays, +or blacks. +@end table +Default is @code{parade}. +@end table + +@subsection Examples + +@itemize + +@item +Calculate and draw histogram: +@example +ffplay -i input -vf histogram +@end example + +@end itemize + @section hqdn3d High precision/quality 3d denoise filter. This filter aims to reduce @@ -2741,7 +3433,7 @@ Specify the hue angle as a number of degrees. It accepts a float number or an expression, and defaults to 0.0. @item H -Specify the hue angle as a number of degrees. It accepts a float +Specify the hue angle as a number of radians. It accepts a float number or an expression, and defaults to 0.0. @item s @@ -2773,7 +3465,8 @@ The options can also be set using the syntax: @var{hue}:@var{saturation} In this case @var{hue} is expressed in degrees. -Some examples follow: +@subsection Examples + @itemize @item Set the hue to 90 degrees and the saturation to 1.0: @@ -2840,13 +3533,53 @@ Modify the hue and/or the saturation of the input video. The command accepts the same named options and syntax than when calling the filter from the command-line. -If a parameter is omitted, it is kept at its current value. +If a parameter is omitted, it is kept at its current value. +@end table + +@section idet + +Detect video interlacing type. + +This filter tries to detect if the input is interlaced or progressive, +top or bottom field first. + +@section il + +Deinterleave or interleave fields. + +This filter allows to process interlaced images fields without +deinterlacing them. Deinterleaving splits the input frame into 2 +fields (so called half pictures). Odd lines are moved to the top +half of the output image, even lines to the bottom half. +You can process (filter) them independently and then re-interleave them. + +It accepts a list of options in the form of @var{key}=@var{value} pairs +separated by ":". A description of the accepted options follows. + +@table @option +@item luma_mode, l +@item chroma_mode, s +@item alpha_mode, a +Available values for @var{luma_mode}, @var{chroma_mode} and +@var{alpha_mode} are: + +@table @samp +@item none +Do nothing. + +@item deinterleave, d +Deinterleave fields, placing one above the other. + +@item interleave, i +Interleave fields. Reverse the effect of deinterleaving. @end table +Default value is @code{none}. -@section idet - -Interlaceing detect filter. This filter tries to detect if the input is -interlaced or progressive. Top or bottom field first. +@item luma_swap, ls +@item chroma_swap, cs +@item alpha_swap, as +Swap luma/chroma/alpha fields. Exchange even & odd lines. Default value is @code{0}. +@end table @section kerndeint @@ -2920,10 +3653,14 @@ corresponding pixel component values. The @var{lut} filter requires either YUV or RGB pixel formats in input, and accepts the options: @table @option -@item @var{c0} (first pixel component) -@item @var{c1} (second pixel component) -@item @var{c2} (third pixel component) -@item @var{c3} (fourth pixel component, corresponds to the alpha component) +@item c0 +set first pixel component expression +@item c1 +set second pixel component expression +@item c2 +set third pixel component expression +@item c3 +set fourth pixel component expression, corresponds to the alpha component @end table The exact component associated to each option depends on the format in @@ -2932,19 +3669,27 @@ input. The @var{lutrgb} filter requires RGB pixel formats in input, and accepts the options: @table @option -@item @var{r} (red component) -@item @var{g} (green component) -@item @var{b} (blue component) -@item @var{a} (alpha component) +@item r +set red component expression +@item g +set green component expression +@item b +set blue component expression +@item a +alpha component expression @end table The @var{lutyuv} filter requires YUV pixel formats in input, and accepts the options: @table @option -@item @var{y} (Y/luminance component) -@item @var{u} (U/Cb component) -@item @var{v} (V/Cr component) -@item @var{a} (alpha component) +@item y +set Y/luminance component expression +@item u +set U/Cb component expression +@item v +set V/Cr component expression +@item a +set alpha component expression @end table The expressions can contain the following constants and functions: @@ -2984,34 +3729,58 @@ expression All expressions default to "val". -Some examples follow: +@subsection Examples + +@itemize +@item +Negate input video: @example -# negate input video lutrgb="r=maxval+minval-val:g=maxval+minval-val:b=maxval+minval-val" lutyuv="y=maxval+minval-val:u=maxval+minval-val:v=maxval+minval-val" +@end example -# the above is the same as +The above is the same as: +@example lutrgb="r=negval:g=negval:b=negval" lutyuv="y=negval:u=negval:v=negval" +@end example -# negate luminance +@item +Negate luminance: +@example lutyuv=y=negval +@end example -# remove chroma components, turns the video into a graytone image +@item +Remove chroma components, turns the video into a graytone image: +@example lutyuv="u=128:v=128" +@end example -# apply a luma burning effect +@item +Apply a luma burning effect: +@example lutyuv="y=2*val" +@end example -# remove green and blue components +@item +Remove green and blue components: +@example lutrgb="g=0:b=0" +@end example -# set a constant alpha channel value on input +@item +Set a constant alpha channel value on input: +@example format=rgba,lutrgb=a="maxval-minval/2" +@end example -# correct luminance gamma by a 0.5 factor +@item +Correct luminance gamma by a 0.5 factor: +@example lutyuv=y=gammaval(0.5) @end example +@end itemize @section mp @@ -3038,18 +3807,14 @@ The list of the currently supported filters follows: @item dint @item divtc @item down3dright -@item dsize @item eq2 @item eq @item fil @item fspp @item harddup -@item il @item ilpack @item ivtc -@item kerndeint @item mcdeint -@item noise @item ow @item perspective @item phase @@ -3058,11 +3823,9 @@ The list of the currently supported filters follows: @item qp @item sab @item softpulldown -@item softskip @item spp @item telecine @item tinterlace -@item unsharp @item uspp @end table @@ -3070,19 +3833,14 @@ The parameter syntax and behavior for the listed filters are the same of the corresponding MPlayer filters. For detailed instructions check the "VIDEO FILTERS" section in the MPlayer manual. -Some examples follow: +@subsection Examples + @itemize @item Adjust gamma, brightness, contrast: @example mp=eq2=1.0:2:0.5 @end example - -@item -Add temporal noise to input video: -@example -mp=noise=20t -@end example @end itemize See also mplayer(1), @url{http://www.mplayerhq.hu/}. @@ -3102,15 +3860,74 @@ input to the next filter. The filter accepts a list of pixel format names, separated by ":", for example "yuv420p:monow:rgb24". -Some examples follow: +@subsection Examples + +@itemize +@item +Force libavfilter to use a format different from @var{yuv420p} for the +input to the vflip filter: @example -# force libavfilter to use a format different from "yuv420p" for the -# input to the vflip filter noformat=yuv420p,vflip +@end example -# convert the input video to any of the formats not contained in the list +@item +Convert the input video to any of the formats not contained in the list: +@example noformat=yuv420p:yuv444p:yuv410p @end example +@end itemize + +@section noise + +Add noise on video input frame. + +This filter accepts a list of options in the form of @var{key}=@var{value} +pairs separated by ":". A description of the accepted options follows. + +@table @option +@item all_seed +@item c0_seed +@item c1_seed +@item c2_seed +@item c3_seed +Set noise seed for specific pixel component or all pixel components in case +of @var{all_seed}. Default value is @code{123457}. + +@item all_strength, alls +@item c0_strength, c0s +@item c1_strength, c1s +@item c2_strength, c2s +@item c3_strength, c3s +Set noise strength for specific pixel component or all pixel components in case +@var{all_strength}. Default value is @code{0}. Allowed range is [0, 100]. + +@item all_flags, allf +@item c0_flags, c0f +@item c1_flags, c1f +@item c2_flags, c2f +@item c3_flags, c3f +Set pixel component flags or set flags for all components if @var{all_flags}. +Available values for component flags are: +@table @samp +@item a +averaged temporal noise (smoother) +@item p +mix random noise with a (semi)regular pattern +@item q +higher quality (slightly better looking, slightly slower) +@item t +temporal noise (noise pattern changes between frames) +@item u +uniform noise (gaussian otherwise) +@end table +@end table + +@subsection Examples + +Add temporal and uniform noise to input video: +@example +noise=alls=20:allf=t+u +@end example @section null @@ -3248,9 +4065,31 @@ overlay input width and height same as @var{overlay_w} and @var{overlay_h} @end table +@item format +Set the format for the output video. + +It accepts the following values: +@table @samp +@item yuv420 +force YUV420 output + +@item yuv444 +force YUV444 output + @item rgb +force RGB output +@end table + +Default value is @samp{yuv420}. + +@item rgb @emph{(deprecated)} If set to 1, force the filter to accept inputs in the RGB -color space. Default value is 0. +color space. Default value is 0. This option is deprecated, use +@option{format} instead. + +@item shortest +If set to 1, force the output to terminate when the shortest input +terminates. Default value is 0. @end table Be aware that frames are taken from each input video in timestamp @@ -3310,6 +4149,18 @@ The above command is the same as: ffplay input.avi -vf 'split[b], pad=iw*2[src], [b]deshake, [src]overlay=w' @end example +@item +Compose output by putting two input videos side to side: +@example +ffmpeg -i left.avi -i right.avi -filter_complex " +nullsrc=size=200x100 [background]; +[0:v] setpts=PTS-STARTPTS, scale=100x100 [left]; +[1:v] setpts=PTS-STARTPTS, scale=100x100 [right]; +[background][left] overlay=shortest=1 [background+left]; +[background+left][right] overlay=shortest=1:x=100 [left+right] +" +@end example + @item Chain several overlays in cascade: @example @@ -3325,14 +4176,50 @@ testsrc=s=100x100, split=4 [in0][in1][in2][in3]; @section pad -Add paddings to the input image, and places the original input at the +Add paddings to the input image, and place the original input at the given coordinates @var{x}, @var{y}. -It accepts the following parameters: +The filter accepts parameters as a list of @var{key}=@var{value} pairs, +separated by ":". + +If the key of the first options is omitted, the arguments are +interpreted according to the syntax @var{width}:@var{height}:@var{x}:@var{y}:@var{color}. -The parameters @var{width}, @var{height}, @var{x}, and @var{y} are -expressions containing the following constants: +A description of the accepted options follows. + +@table @option +@item width, w +@item height, h +Specify an expression for the size of the output image with the +paddings added. If the value for @var{width} or @var{height} is 0, the +corresponding input size is used for the output. + +The @var{width} expression can reference the value set by the +@var{height} expression, and vice versa. + +The default value of @var{width} and @var{height} is 0. + +@item x +@item y +Specify an expression for the offsets where to place the input image +in the padded area with respect to the top/left border of the output +image. + +The @var{x} expression can reference the value set by the @var{y} +expression, and vice versa. + +The default value of @var{x} and @var{y} is 0. + +@item color +Specify the color of the padded area, it can be the name of a color +(case insensitive match) or a 0xRRGGBB[AA] sequence. + +The default value of @var{color} is "black". +@end table + +The value for the @var{width}, @var{height}, @var{x}, and @var{y} +options are expressions containing the following constants: @table @option @item in_w, in_h @@ -3366,39 +4253,6 @@ horizontal and vertical chroma subsample values. For example for the pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1. @end table -Follows the description of the accepted parameters. - -@table @option -@item width, height - -Specify the size of the output image with the paddings added. If the -value for @var{width} or @var{height} is 0, the corresponding input size -is used for the output. - -The @var{width} expression can reference the value set by the -@var{height} expression, and vice versa. - -The default value of @var{width} and @var{height} is 0. - -@item x, y - -Specify the offsets where to place the input image in the padded area -with respect to the top/left border of the output image. - -The @var{x} expression can reference the value set by the @var{y} -expression, and vice versa. - -The default value of @var{x} and @var{y} is 0. - -@item color - -Specify the color of the padded area, it can be the name of a color -(case insensitive match) or a 0xRRGGBB[AA] sequence. - -The default value of @var{color} is "black". - -@end table - @subsection Examples @itemize @@ -3410,6 +4264,11 @@ column 0, row 40: pad=640:480:0:40:violet @end example +The example above is equivalent to the following command: +@example +pad=width=640:height=480:x=0:y=40:color=violet +@end example + @item Pad the input to get an output with dimensions increased by 3/2, and put the input video at the center of the padded area: @@ -4027,6 +4886,127 @@ a pixel should be blurred or not. A value of 0 will filter all the image, a value included in [0,30] will filter flat areas and a value included in [-30,0] will filter edges. +@section stereo3d + +Convert between different stereoscopic image formats. + +This filter accepts the following named options, expressed as a +sequence of @var{key}=@var{value} pairs, separated by ":". + +@table @option +@item in +Set stereoscopic image format of input. + +Available values for input image formats are: +@table @samp +@item sbsl +side by side parallel (left eye left, right eye right) + +@item sbsr +side by side crosseye (right eye left, left eye right) + +@item sbs2l +side by side parallel with half width resolution +(left eye left, right eye right) + +@item sbs2r +side by side crosseye with half width resolution +(right eye left, left eye right) + +@item abl +above-below (left eye above, right eye below) + +@item abr +above-below (right eye above, left eye below) + +@item ab2l +above-below with half height resolution +(left eye above, right eye below) + +@item ab2r +above-below with half height resolution +(right eye above, left eye below) + +Default value is @samp{sbsl}. +@end table + +@item out +Set stereoscopic image format of output. + +Available values for output image formats are all the input formats as well as: +@table @samp +@item arbg +anaglyph red/blue gray +(red filter on left eye, blue filter on right eye) + +@item argg +anaglyph red/green gray +(red filter on left eye, green filter on right eye) + +@item arcg +anaglyph red/cyan gray +(red filter on left eye, cyan filter on right eye) + +@item arch +anaglyph red/cyan half colored +(red filter on left eye, cyan filter on right eye) + +@item arcc +anaglyph red/cyan color +(red filter on left eye, cyan filter on right eye) + +@item arcd +anaglyph red/cyan color optimized with the least squares projection of dubois +(red filter on left eye, cyan filter on right eye) + +@item agmg +anaglyph green/magenta gray +(green filter on left eye, magenta filter on right eye) + +@item agmh +anaglyph green/magenta half colored +(green filter on left eye, magenta filter on right eye) + +@item agmc +anaglyph green/magenta colored +(green filter on left eye, magenta filter on right eye) + +@item agmd +anaglyph green/magenta color optimized with the least squares projection of dubois +(green filter on left eye, magenta filter on right eye) + +@item aybg +anaglyph yellow/blue gray +(yellow filter on left eye, blue filter on right eye) + +@item aybh +anaglyph yellow/blue half colored +(yellow filter on left eye, blue filter on right eye) + +@item aybc +anaglyph yellow/blue colored +(yellow filter on left eye, blue filter on right eye) + +@item aybd +anaglyph yellow/blue color optimized with the least squares projection of dubois +(yellow filter on left eye, blue filter on right eye) + +@item irl +interleaved rows (left eye has top row, right eye starts on next row) + +@item irr +interleaved rows (right eye has top row, left eye starts on next row) + +@item ml +mono output (left eye only) + +@item mr +mono output (right eye only) +@end table + +Default value is @samp{arcd}. +@end table + @anchor{subtitles} @section subtitles @@ -4048,6 +5028,10 @@ Set the filename of the subtitle file to read. It must be specified. Specify the size of the original video, the video for which the ASS file was composed. Due to a misdesign in ASS aspect ratio arithmetic, this is necessary to correctly scale the fonts if the aspect ratio has been changed. + +@item charenc +Set subtitles input character encoding. @code{subtitles} filter only. Only +useful if not UTF-8. @end table If the first key is not specified, it is assumed that the first value @@ -4326,51 +5310,53 @@ transpose=1:portrait Sharpen or blur the input video. -It accepts the following parameters: +This filter accepts parameters as a list of @var{key}=@var{value} pairs, +separated by ":". + +If the key of the first options is omitted, the arguments are +interpreted according to the syntax: @var{luma_msize_x}:@var{luma_msize_y}:@var{luma_amount}:@var{chroma_msize_x}:@var{chroma_msize_y}:@var{chroma_amount} -Negative values for the amount will blur the input video, while positive -values will sharpen. All parameters are optional and default to the -equivalent of the string '5:5:1.0:5:5:0.0'. +A description of the accepted options follows. @table @option - -@item luma_msize_x -Set the luma matrix horizontal size. It can be an integer between 3 -and 13, default value is 5. - -@item luma_msize_y -Set the luma matrix vertical size. It can be an integer between 3 -and 13, default value is 5. - -@item luma_amount -Set the luma effect strength. It can be a float number between -2.0 -and 5.0, default value is 1.0. - -@item chroma_msize_x -Set the chroma matrix horizontal size. It can be an integer between 3 -and 13, default value is 5. - -@item chroma_msize_y -Set the chroma matrix vertical size. It can be an integer between 3 -and 13, default value is 5. - -@item chroma_amount -Set the chroma effect strength. It can be a float number between -2.0 -and 5.0, default value is 0.0. - +@item luma_msize_x, lx +@item chroma_msize_x, cx +Set the luma/chroma matrix horizontal size. It must be an odd integer +between 3 and 63, default value is 5. + +@item luma_msize_y, ly +@item chroma_msize_y, cy +Set the luma/chroma matrix vertical size. It must be an odd integer +between 3 and 63, default value is 5. + +@item luma_amount, la +@item chroma_amount, ca +Set the luma/chroma effect strength. It can be a float number, +reasonable values lay between -1.5 and 1.5. + +Negative values will blur the input video, while positive values will +sharpen it, a value of zero will disable the effect. + +Default value is 1.0 for @option{luma_amount}, 0.0 for +@option{chroma_amount}. @end table +@subsection Examples + +@itemize +@item +Apply strong luma sharpen effect: @example -# Strong luma sharpen effect parameters unsharp=7:7:2.5 +@end example -# Strong blur of both luma and chroma parameters +@item +Apply strong blur of both luma and chroma parameters: +@example unsharp=7:7:-2:7:7:-2 - -# Use the default values with @command{ffmpeg} -ffmpeg -i in.avi -vf "unsharp" out.mp4 @end example +@end itemize @section vflip @@ -5377,6 +6363,13 @@ previous output PTS @item PREV_OUTT previous output time in seconds + +@item RTCTIME +wallclock (RTC) time in microseconds. This is deprecated, use time(0) +instead. + +@item RTCSTART +wallclock (RTC) time at the start of the movie in microseconds @end table @subsection Examples @@ -5417,6 +6410,12 @@ Apply an offset of 10 seconds to the input PTS: @example setpts=PTS+10/TB @end example + +@item +Generate timestamps from a "live source" and rebase onto the current timebase: +@example +setpts='(RTCTIME - RTCSTART) / (TB * 1000000)' +@end example @end itemize @section ebur128 @@ -5456,15 +6455,21 @@ other integer value between this range is allowed. @end table -Example of real-time graph using @command{ffplay}, with a EBU scale meter +18: +@subsection Examples + +@itemize +@item +Real-time graph using @command{ffplay}, with a EBU scale meter +18: @example ffplay -f lavfi -i "amovie=input.mp3,ebur128=video=1:meter=18 [out0][out1]" @end example +@item Run an analysis with @command{ffmpeg}: @example ffmpeg -nostats -i input.mp3 -filter_complex ebur128 -f null - @end example +@end itemize @section settb, asettb @@ -5565,7 +6570,8 @@ explicitly by the user. Different frame rates are acceptable but will result in variable frame rate at output; be sure to configure the output file to handle it. -Examples: +@subsection Examples + @itemize @item Concatenate an opening, an episode and an ending, all in bilingual version @@ -5598,21 +6604,101 @@ spectrum. The filter accepts the following named parameters: @table @option @item size, s -Specify the video size for the output. Default value is @code{640x480}. +Specify the video size for the output. Default value is @code{640x512}. + @item slide Specify if the spectrum should slide along the window. Default value is @code{0}. + +@item mode +Specify display mode. + +It accepts the following values: +@table @samp +@item combined +all channels are displayed in the same row +@item separate +all channels are displayed in separate rows +@end table + +Default value is @samp{combined}. + +@item color +Specify display color mode. + +It accepts the following values: +@table @samp +@item channel +each channel is displayed in a separate color +@item intensity +each channel is is displayed using the same color scheme +@end table + +Default value is @samp{channel}. + +@item scale +Specify scale used for calculating intensity color values. + +It accepts the following values: +@table @samp +@item lin +linear +@item sqrt +square root, default +@item cbrt +cubic root +@item log +logarithmic +@end table + +Default value is @samp{sqrt}. + +@item saturation +Set saturation modifier for displayed colors. Negative values provide +alternative color scheme. @code{0} is no saturation at all. +Saturation must be in [-10.0, 10.0] range. +Default value is @code{1}. @end table The usage is very similar to the showwaves filter; see the examples in that section. +@subsection Examples + +@itemize +@item +Large window with logarithmic color scaling: +@example +showspectrum=s=1280x480:scale=log +@end example + +@item +Complete example for a colored and sliding spectrum per channel using @command{ffplay}: +@example +ffplay -f lavfi 'amovie=input.mp3, asplit [a][out1]; + [a] showspectrum=mode=separate:color=intensity:slide=1:scale=cbrt [out0]' +@end example +@end itemize + @section showwaves Convert input audio to a video output, representing the samples waves. The filter accepts the following named parameters: @table @option +@item mode +Set display mode. + +Available values are: +@table @samp +@item point +Draw a point for each sample. + +@item line +Draw a vertical line for each sample. +@end table + +Default value is @code{point}. @item n Set the number of samples which are printed on the same column. A @@ -5628,7 +6714,8 @@ option @var{n}. Default value is "25". Specify the video size for the output. Default value is "600x240". @end table -Some examples follow. +@subsection Examples + @itemize @item Output the input file audio and the corresponding video representation @@ -5715,7 +6802,7 @@ input -----------> deltapts0 --> overlay --> output movie --> scale--> deltapts1 -------+ @end example -Some examples follow. +@subsection Examples @itemize @item diff --git a/mythtv/external/FFmpeg/doc/general.texi b/mythtv/external/FFmpeg/doc/general.texi index cdbcf8407e3..39b9360c9ea 100644 --- a/mythtv/external/FFmpeg/doc/general.texi +++ b/mythtv/external/FFmpeg/doc/general.texi @@ -814,6 +814,7 @@ following image formats are supported: @item DSP Group TrueSpeech @tab @tab X @item DV audio @tab @tab X @item Enhanced AC-3 @tab X @tab X +@item EVRC (Enhanced Variable Rate Codec) @tab @tab X @item FLAC (Free Lossless Audio Codec) @tab X @tab IX @item G.723.1 @tab X @tab X @item G.729 @tab @tab X diff --git a/mythtv/external/FFmpeg/doc/indevs.texi b/mythtv/external/FFmpeg/doc/indevs.texi index 621e1de9785..cc5d66622ca 100644 --- a/mythtv/external/FFmpeg/doc/indevs.texi +++ b/mythtv/external/FFmpeg/doc/indevs.texi @@ -583,10 +583,16 @@ command: ffmpeg -f sndio -i /dev/audio0 /tmp/oss.wav @end example -@section video4linux2 +@section video4linux2, v4l2 Video4Linux2 input video device. +"v4l2" can be used as alias for "video4linux2". + +If FFmpeg is built with v4l-utils support (by using the +@code{--enable-libv4l2} configure option), the device will always rely +on libv4l2. + The name of the device to grab is a file device node, usually Linux systems tend to automatically create such nodes when the device (e.g. an USB webcam) is plugged into the system, and has a name of the @@ -596,8 +602,8 @@ the device. Video4Linux2 devices usually support a limited set of @var{width}x@var{height} sizes and framerates. You can check which are supported using @command{-list_formats all} for Video4Linux2 devices. - -Some usage examples of the video4linux2 devices with ffmpeg and ffplay: +Some devices, like TV cards, support one or more standards. It is possible +to list all the supported standards using @command{-list_standards all}. The time base for the timestamps is 1 microsecond. Depending on the kernel version and configuration, the timestamps may be derived from the real time @@ -606,19 +612,93 @@ boot time, unaffected by NTP or manual changes to the clock). The @option{-timestamps abs} or @option{-ts abs} option can be used to force conversion into the real time clock. -Note that if FFmpeg is build with v4l-utils support ("--enable-libv4l2" -option), it will always be used. +Some usage examples of the video4linux2 device with @command{ffmpeg} +and @command{ffplay}: +@itemize +@item +Grab and show the input of a video4linux2 device: @example -# Grab and show the input of a video4linux2 device. ffplay -f video4linux2 -framerate 30 -video_size hd720 /dev/video0 +@end example -# Grab and record the input of a video4linux2 device, leave the -framerate and size as previously set. +@item +Grab and record the input of a video4linux2 device, leave the +framerate and size as previously set: +@example ffmpeg -f video4linux2 -input_format mjpeg -i /dev/video0 out.mpeg @end example +@end itemize + +For more information about Video4Linux, check @url{http://linuxtv.org/}. + +@subsection Options + +@table @option +@item standard +Set the standard. Must be the name of a supported standard. To get a +list of the supported standards, use the @option{list_standards} +option. + +@item channel +Set the input channel number. Default to 0. + +@item video_size +Set the video frame size. The argument must be a string in the form +@var{WIDTH}x@var{HEIGHT} or a valid size abbreviation. + +@item pixel_format +Select the pixel format (only valid for raw video input). + +@item input_format +Set the preferred pixel format (for raw video) or a codec name. +This option allows to select the input format, when several are +available. + +@item framerate +Set the preferred video framerate. + +@item list_formats +List available formats (supported pixel formats, codecs, and frame +sizes) and exit. + +Available values are: +@table @samp +@item all +Show all available (compressed and non-compressed) formats. + +@item raw +Show only raw video (non-compressed) formats. + +@item compressed +Show only compressed formats. +@end table -"v4l" and "v4l2" can be used as aliases for the respective "video4linux" and -"video4linux2". +@item list_standards +List supported standards and exit. + +Available values are: +@table @samp +@item all +Show all supported standards. +@end table + +@item timestamps, ts +Set type of timestamps for grabbed frames. + +Available values are: +@table @samp +@item default +Use timestamps from the kernel. + +@item abs +Use absolute timestamps (wall clock). + +@item mono2abs +Force conversion from monotonic to absolute timestamps. +@end table + +Default value is @code{default}. +@end table @section vfwcap diff --git a/mythtv/external/FFmpeg/doc/muxers.texi b/mythtv/external/FFmpeg/doc/muxers.texi index 3c6415f1125..9d119c39a1e 100644 --- a/mythtv/external/FFmpeg/doc/muxers.texi +++ b/mythtv/external/FFmpeg/doc/muxers.texi @@ -241,8 +241,13 @@ ffmpeg -i in.avi -f image2 -frames:v 1 img.jpeg @end example @table @option -@item -start_number @var{number} -Start the sequence from @var{number}. +@item start_number @var{number} +Start the sequence from @var{number}. Default value is 1. Must be a +positive number. + +@item updatefirst 1|0 +If set to 1, update the first written image file again and +again. Default value is 0. @end table The image muxer supports the .Y.U.V image file format. This format is @@ -346,6 +351,8 @@ This option is implicitly set when writing ismv (Smooth Streaming) files. Run a second pass moving the moov atom on top of the file. This operation can take a while, and will not work in various situations such as fragmented output, thus it is not enabled by default. +@item -movflags rtphint +Add RTP hinting tracks to the output file. @end table Smooth Streaming content can be pushed in real time to a publishing @@ -521,9 +528,11 @@ reference stream. The default value is ``auto''. @item segment_format @var{format} Override the inner container format, by default it is guessed by the filename extension. + @item segment_list @var{name} Generate also a listfile named @var{name}. If not specified no listfile is generated. + @item segment_list_flags @var{flags} Set flags affecting the segment list generation. @@ -534,17 +543,15 @@ Allow caching (only affects M3U8 list files). @item live Allow live-friendly file generation. - -This currently only affects M3U8 lists. In particular, write a fake -EXT-X-TARGETDURATION duration field at the top of the file, based on -the specified @var{segment_time}. @end table Default value is @code{cache}. @item segment_list_size @var{size} -Overwrite the listfile once it reaches @var{size} entries. If 0 -the listfile is never overwritten. Default value is 0. +Update the list file so that it contains at most the last @var{size} +segments. If 0 the list file will contain all the segments. Default +value is 0. + @item segment_list type @var{type} Specify the format for the segment list file. @@ -572,19 +579,34 @@ auto-select this format. @code{ext} is deprecated in favor or @code{csv}. +@item ffconcat +Generate an ffconcat file for the created segments. The resulting file +can be read using the FFmpeg @ref{concat} demuxer. + +A list file with the suffix @code{".ffcat"} or @code{".ffconcat"} will +auto-select this format. + @item m3u8 -Generate an extended M3U8 file, version 4, compliant with -@url{http://tools.ietf.org/id/draft-pantos-http-live-streaming-08.txt}. +Generate an extended M3U8 file, version 3, compliant with +@url{http://tools.ietf.org/id/draft-pantos-http-live-streaming}. A list file with the suffix @code{".m3u8"} will auto-select this format. @end table If not specified the type is guessed from the list file name suffix. + @item segment_time @var{time} -Set segment duration to @var{time}. Default value is "2". +Set segment duration to @var{time}, the value must be a duration +specification. Default value is "2". See also the +@option{segment_times} option. + +Note that splitting may not be accurate, unless you force the +reference stream key-frames at the given time. See the introductory +notice and the examples below. + @item segment_time_delta @var{delta} Specify the accuracy time when selecting the start time for a -segment. Default value is "0". +segment, expressed as a duration specification. Default value is "0". When delta is specified a key-frame will start a new segment if its PTS satisfies the relation: @@ -606,7 +628,8 @@ the specified time and the time set by @var{force_key_frames}. @item segment_times @var{times} Specify a list of split points. @var{times} contains a list of comma -separated duration specifications, in increasing order. +separated duration specifications, in increasing order. See also +the @option{segment_time} option. @item segment_frames @var{frames} Specify a list of split video frame numbers. @var{frames} contains a @@ -629,7 +652,7 @@ of the generated segments. May not work with some combinations of muxers/codecs. It is set to @code{0} by default. @end table -@section Examples +@subsection Examples @itemize @item @@ -718,4 +741,54 @@ ffmpeg -i input.mp3 -i cover.png -c copy -map 0 -map 1 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (Front)" out.mp3 @end example +@section ogg + +Ogg container muxer. + +@table @option +@item -page_duration @var{duration} +Preferred page duration, in microseconds. The muxer will attempt to create +pages that are approximately @var{duration} microseconds long. This allows the +user to compromise between seek granularity and container overhead. The default +is 1 second. A value of 0 will fill all segments, making pages as large as +possible. A value of 1 will effectively use 1 packet-per-page in most +situations, giving a small seek granularity at the cost of additional container +overhead. +@end table + +@section tee + +The tee muxer can be used to write the same data to several files or any +other kind of muxer. It can be used, for example, to both stream a video to +the network and save it to disk at the same time. + +It is different from specifying several outputs to the @command{ffmpeg} +command-line tool because the audio and video data will be encoded only once +with the tee muxer; encoding can be a very expensive process. It is not +useful when using the libavformat API directly because it is then possible +to feed the same packets to several muxers directly. + +The slave outputs are specified in the file name given to the muxer, +separated by '|'. If any of the slave name contains the '|' separator, +leading or trailing spaces or any special character, it must be +escaped (see the ``Quoting and escaping'' section in the ffmpeg-utils +manual). + +Options can be specified for each slave by prepending them as a list of +@var{key}=@var{value} pairs separated by ':', between square brackets. If +the options values contain a special character or the ':' separator, they +must be escaped; note that this is a second level escaping. + +Example: encode something and both archive it in a WebM file and stream it +as MPEG-TS over UDP (the streams need to be explicitly mapped): + +@example +ffmpeg -i ... -c:v libx264 -c:a mp2 -f tee -map 0:v -map 0:a + "archive-20121107.mkv|[f=mpegts]udp://10.0.1.255:1234/" +@end example + +Note: some codecs may need different options depending on the output format; +the auto-detection of this can not work with the tee muxer. The main example +is the @option{global_header} flag. + @c man end MUXERS diff --git a/mythtv/external/FFmpeg/doc/optimization.txt b/mythtv/external/FFmpeg/doc/optimization.txt index e3fd32401c9..5a66d6bb3ff 100644 --- a/mythtv/external/FFmpeg/doc/optimization.txt +++ b/mythtv/external/FFmpeg/doc/optimization.txt @@ -148,7 +148,7 @@ Alignment: Some instructions on some architectures have strict alignment restrictions, for example most SSE/SSE2 instructions on x86. The minimum guaranteed alignment is written in the .h files, for example: - void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, UINT8 *pixels/*align 8*/, int line_size); + void (*put_pixels_clamped)(const int16_t *block/*align 16*/, UINT8 *pixels/*align 8*/, int line_size); General Tips: diff --git a/mythtv/external/FFmpeg/doc/protocols.texi b/mythtv/external/FFmpeg/doc/protocols.texi index a36d2a38045..9940b67d576 100644 --- a/mythtv/external/FFmpeg/doc/protocols.texi +++ b/mythtv/external/FFmpeg/doc/protocols.texi @@ -128,6 +128,63 @@ m3u8 files. HTTP (Hyper Text Transfer Protocol). +This protocol accepts the following options. + +@table @option +@item seekable +Control seekability of connection. If set to 1 the resource is +supposed to be seekable, if set to 0 it is assumed not to be seekable, +if set to -1 it will try to autodetect if it is seekable. Default +value is -1. + +@item chunked_post +If set to 1 use chunked transfer-encoding for posts, default is 1. + +@item headers +Set custom HTTP headers, can override built in default headers. The +value must be a string encoding the headers. + +@item content_type +Force a content type. + +@item user-agent +Override User-Agent header. If not specified the protocol will use a +string describing the libavformat build. + +@item multiple_requests +Use persistent connections if set to 1. By default it is 0. + +@item post_data +Set custom HTTP post data. + +@item timeout +Set timeout of socket I/O operations used by the underlying low level +operation. By default it is set to -1, which means that the timeout is +not specified. + +@item mime_type +Set MIME type. + +@item cookies +Set the cookies to be sent in future requests. The format of each cookie is the +same as the value of a Set-Cookie HTTP response field. Multiple cookies can be +delimited by a newline character. +@end table + +@subsection HTTP Cookies + +Some HTTP requests will be denied unless cookie values are passed in with the +request. The @option{cookies} option allows these cookies to be specified. At +the very least, each cookie must specify a value along with a path and domain. +HTTP requests that match both the domain and path will automatically include the +cookie value in the HTTP Cookie header field. Multiple cookies can be delimited +by a newline. + +The required syntax to play a stream specifying a cookie is: +@example +ffplay -cookies "nlqptid=nltid=tsn; path=/; domain=somedomain.com;" http://somedomain.com/somestream.m3u8 +@end example + @section mmst MMS (Microsoft Media Server) protocol over TCP. diff --git a/mythtv/external/FFmpeg/doc/swresample.txt b/mythtv/external/FFmpeg/doc/swresample.txt index 790414793ea..2d192a394ef 100644 --- a/mythtv/external/FFmpeg/doc/swresample.txt +++ b/mythtv/external/FFmpeg/doc/swresample.txt @@ -32,9 +32,9 @@ Special Converter v Output Planar/Packed conversion is done when needed during sample format conversion. -Every step can be skipped without memcpy when its not needed. +Every step can be skipped without memcpy when it is not needed. Either Resampling and Rematrixing can be performed first depending on which -way its faster. +way it is faster. The Buffers are needed for resampling due to resamplng being a process that requires future and past data, it thus also introduces inevitably a delay when used. diff --git a/mythtv/external/FFmpeg/doc/syntax.texi b/mythtv/external/FFmpeg/doc/syntax.texi index a3aabce1e90..af22d6cefd0 100644 --- a/mythtv/external/FFmpeg/doc/syntax.texi +++ b/mythtv/external/FFmpeg/doc/syntax.texi @@ -98,7 +98,7 @@ year-month-day. The accepted syntax is: @example -[-]HH:MM:SS[.m...] +[-][HH:]MM:SS[.m...] [-]S+[.m...] @end example @@ -112,6 +112,22 @@ Specify the size of the sourced video, it may be a string of the form The following abbreviations are recognized: @table @samp +@item ntsc +720x480 +@item pal +720x576 +@item qntsc +352x240 +@item qpal +352x288 +@item sntsc +640x480 +@item spal +768x576 +@item film +352x240 +@item ntsc-film +352x240 @item sqcif 128x96 @item qcif @@ -170,6 +186,18 @@ The following abbreviations are recognized: 1280x720 @item hd1080 1920x1080 +@item 2k +2048x1080 +@item 2kflat +1998x1080 +@item 2kscope +2048x858 +@item 4k +4096x2160 +@item 4kflat +3996x2160 +@item 4kscope +4096x1716 @end table @anchor{video rate syntax} @@ -187,17 +215,17 @@ The following abbreviations are recognized: @item pal 25/1 @item qntsc -30000/1 +30000/1001 @item qpal 25/1 @item sntsc -30000/1 +30000/1001 @item spal 25/1 @item film 24/1 @item ntsc-film -24000/1 +24000/1001 @end table @anchor{ratio syntax} diff --git a/mythtv/external/FFmpeg/doc/t2h.init b/mythtv/external/FFmpeg/doc/t2h.init index bb28d967900..2aab488eed4 100644 --- a/mythtv/external/FFmpeg/doc/t2h.init +++ b/mythtv/external/FFmpeg/doc/t2h.init @@ -68,7 +68,7 @@ $print_page_head = \&FFmpeg_print_page_head; sub FFmpeg_print_page_head($$) { my $fh = shift; - my $longtitle = "$Texi2HTML::THISDOC{'title_no_texi'}"; + my $longtitle = "$Texi2HTML::THISDOC{'fulltitle_no_texi'}"; $longtitle .= ": $Texi2HTML::NO_TEXI{'This'}" if exists $Texi2HTML::NO_TEXI{'This'}; my $description = $DOCUMENT_DESCRIPTION; $description = $longtitle if (!defined($description)); diff --git a/mythtv/external/FFmpeg/doc/texi2pod.pl b/mythtv/external/FFmpeg/doc/texi2pod.pl index 87905631313..697576c185e 100755 --- a/mythtv/external/FFmpeg/doc/texi2pod.pl +++ b/mythtv/external/FFmpeg/doc/texi2pod.pl @@ -169,7 +169,7 @@ } elsif ($ended =~ /^(?:example|smallexample|display)$/) { $shift = ""; $_ = ""; # need a paragraph break - } elsif ($ended =~ /^(?:itemize|enumerate|[fv]?table)$/) { + } elsif ($ended =~ /^(?:itemize|enumerate|(?:multi|[fv])?table)$/) { $_ = "\n=back\n"; $ic = pop @icstack; } else { @@ -269,7 +269,7 @@ $endw = "enumerate"; }; - /^\@([fv]?table)\s+(\@[a-z]+)/ and do { + /^\@((?:multi|[fv])?table)\s+(\@[a-z]+)/ and do { push @endwstack, $endw; push @icstack, $ic; $endw = $1; @@ -278,6 +278,7 @@ $ic =~ s/\@(?:code|kbd)/C/; $ic =~ s/\@(?:dfn|var|emph|cite|i)/I/; $ic =~ s/\@(?:file)/F/; + $ic =~ s/\@(?:columnfractions)//; $_ = "\n=over 4\n"; }; @@ -288,6 +289,21 @@ $_ = ""; # need a paragraph break }; + /^\@item\s+(.*\S)\s*$/ and $endw eq "multitable" and do { + my $columns = $1; + $columns =~ s/\@tab/ : /; + + $_ = "\n=item B<". $columns .">\n"; + }; + + /^\@tab\s+(.*\S)\s*$/ and $endw eq "multitable" and do { + my $columns = $1; + $columns =~ s/\@tab/ : /; + + $_ = " : ". $columns; + $chapter =~ s/\n+\s+$//; + }; + /^\@itemx?\s*(.+)?$/ and do { if (defined $1) { # Entity escapes prevent munging by the <> processing below. @@ -361,6 +377,7 @@ sub postprocess s/\(?\@xref\{(?:[^\}]*)\}(?:[^.<]|(?:<[^<>]*>))*\.\)?//g; s/\s+\(\@pxref\{(?:[^\}]*)\}\)//g; s/;\s+\@pxref\{(?:[^\}]*)\}//g; + s/\@ref\{(?:[^,\}]*,)(?:[^,\}]*,)([^,\}]*).*\}/$1/g; s/\@ref\{([^\}]*)\}/$1/g; s/\@noindent\s*//g; s/\@refill//g; diff --git a/mythtv/external/FFmpeg/ffmpeg.c b/mythtv/external/FFmpeg/ffmpeg.c index e9837bf83a1..2ea36943942 100644 --- a/mythtv/external/FFmpeg/ffmpeg.c +++ b/mythtv/external/FFmpeg/ffmpeg.c @@ -109,8 +109,18 @@ const int program_birth_year = 2000; static FILE *vstats_file; +const char *const forced_keyframes_const_names[] = { + "n", + "n_forced", + "prev_forced_n", + "prev_forced_t", + "t", + NULL +}; + static void do_video_stats(OutputStream *ost, int frame_size); static int64_t getutime(void); +static int64_t getmaxrss(void); static int run_as_daemon = 0; static int64_t video_size = 0; @@ -399,6 +409,11 @@ static void exit_program(void) { int i, j; + if (do_benchmark) { + int maxrss = getmaxrss() / 1024; + printf("bench: maxrss=%ikB\n", maxrss); + } + for (i = 0; i < nb_filtergraphs; i++) { avfilter_graph_free(&filtergraphs[i]->graph); for (j = 0; j < filtergraphs[i]->nb_inputs; j++) { @@ -437,6 +452,7 @@ static void exit_program(void) avcodec_free_frame(&output_streams[i]->filtered_frame); av_freep(&output_streams[i]->forced_keyframes); + av_expr_free(output_streams[i]->forced_keyframes_pexpr); av_freep(&output_streams[i]->avfilter); av_freep(&output_streams[i]->logfile_prefix); av_freep(&output_streams[i]); @@ -449,6 +465,7 @@ static void exit_program(void) avcodec_free_frame(&input_streams[i]->decoded_frame); av_dict_free(&input_streams[i]->opts); free_buffer_pool(&input_streams[i]->buffer_pool); + avsubtitle_free(&input_streams[i]->prev_sub.subtitle); avfilter_unref_bufferp(&input_streams[i]->sub2video.ref); av_freep(&input_streams[i]->filters); av_freep(&input_streams[i]); @@ -664,6 +681,7 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost, } } +#if FF_API_DEINTERLACE static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void **bufp) { AVCodecContext *dec; @@ -674,7 +692,7 @@ static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void * dec = ist->st->codec; /* deinterlace : must be done before any resize */ - if (do_deinterlace) { + if (FF_API_DEINTERLACE && do_deinterlace) { int size; /* create temporary picture */ @@ -704,6 +722,7 @@ static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void * *picture = *picture2; *bufp = buf; } +#endif static void do_subtitle_out(AVFormatContext *s, OutputStream *ost, @@ -872,8 +891,9 @@ static void do_video_out(AVFormatContext *s, video_size += pkt.size; write_frame(s, &pkt, ost); } else { - int got_packet; + int got_packet, forced_keyframe = 0; AVFrame big_picture; + double pts_time; big_picture = *in_picture; /* better than nothing: use input picture interlaced @@ -897,11 +917,41 @@ static void do_video_out(AVFormatContext *s, big_picture.quality = ost->st->codec->global_quality; if (!enc->me_threshold) big_picture.pict_type = 0; + + pts_time = big_picture.pts != AV_NOPTS_VALUE ? + big_picture.pts * av_q2d(enc->time_base) : NAN; if (ost->forced_kf_index < ost->forced_kf_count && big_picture.pts >= ost->forced_kf_pts[ost->forced_kf_index]) { - big_picture.pict_type = AV_PICTURE_TYPE_I; ost->forced_kf_index++; + forced_keyframe = 1; + } else if (ost->forced_keyframes_pexpr) { + double res; + ost->forced_keyframes_expr_const_values[FKF_T] = pts_time; + res = av_expr_eval(ost->forced_keyframes_pexpr, + ost->forced_keyframes_expr_const_values, NULL); + av_dlog(NULL, "force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n", + ost->forced_keyframes_expr_const_values[FKF_N], + ost->forced_keyframes_expr_const_values[FKF_N_FORCED], + ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N], + ost->forced_keyframes_expr_const_values[FKF_T], + ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T], + res); + if (res) { + forced_keyframe = 1; + ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] = + ost->forced_keyframes_expr_const_values[FKF_N]; + ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] = + ost->forced_keyframes_expr_const_values[FKF_T]; + ost->forced_keyframes_expr_const_values[FKF_N_FORCED] += 1; + } + + ost->forced_keyframes_expr_const_values[FKF_N] += 1; } + if (forced_keyframe) { + big_picture.pict_type = AV_PICTURE_TYPE_I; + av_log(NULL, AV_LOG_DEBUG, "Forced keyframe at time %f\n", pts_time); + } + update_benchmark(NULL); ret = avcodec_encode_video2(enc, &pkt, &big_picture, &got_packet); update_benchmark("encode_video %d.%d", ost->file_index, ost->index); @@ -1061,6 +1111,12 @@ static int reap_filters(void) case AVMEDIA_TYPE_AUDIO: avfilter_copy_buf_props(filtered_frame, picref); filtered_frame->pts = frame_pts; + if (!(ost->st->codec->codec->capabilities & CODEC_CAP_PARAM_CHANGE) && + ost->st->codec->channels != av_frame_get_channels(filtered_frame)) { + av_log(NULL, AV_LOG_ERROR, + "Audio filter graph output is not normalized and encoder does not support parameter changes\n"); + break; + } do_audio_out(of->ctx, ost, filtered_frame); break; default: @@ -1167,7 +1223,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti p = psnr(error / scale); snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c:%2.2f ", type[j], p); av_bprintf(&buf_script, "stream_%d_%d_psnr_%c=%2.2f\n", - ost->file_index, ost->index, type[i] | 32, p); + ost->file_index, ost->index, type[j] | 32, p); } p = psnr(error_sum / scale_sum); snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "*:%2.2f ", psnr(error_sum / scale_sum)); @@ -1215,7 +1271,10 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf_script, "drop_frames=%d\n", nb_frames_drop); if (print_stats || is_last_report) { - av_log(NULL, AV_LOG_INFO, "%s \r", buf); + if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { + fprintf(stderr, "%s \r", buf); + } else + av_log(NULL, AV_LOG_INFO, "%s \r", buf); fflush(stderr); } @@ -1442,6 +1501,8 @@ int guess_input_channel_layout(InputStream *ist) if (!dec->channel_layout) { char layout_name[256]; + if (dec->channels > ist->guess_layout_max) + return 0; dec->channel_layout = av_get_default_channel_layout(dec->channels); if (!dec->channel_layout) return 0; @@ -1616,7 +1677,9 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output) } pkt->size = 0; +#if FF_API_DEINTERLACE pre_process_video_frame(ist, (AVPicture *)decoded_frame, &buffer_to_free); +#endif rate_emu_sleep(ist); @@ -1869,7 +1932,7 @@ static int output_packet(InputStream *ist, const AVPacket *pkt) static void print_sdp(void) { - char sdp[2048]; + char sdp[16384]; int i; AVFormatContext **avc = av_malloc(sizeof(*avc) * nb_output_files); @@ -1897,7 +1960,7 @@ static int init_input_stream(int ist_index, char *error, int error_len) return AVERROR(EINVAL); } - ist->dr1 = (codec->capabilities & CODEC_CAP_DR1) && !do_deinterlace; + ist->dr1 = (codec->capabilities & CODEC_CAP_DR1) && !(FF_API_DEINTERLACE && do_deinterlace); if (codec->type == AVMEDIA_TYPE_VIDEO && ist->dr1) { ist->st->codec->get_buffer = codec_get_buffer; ist->st->codec->release_buffer = codec_release_buffer; @@ -1930,19 +1993,25 @@ static InputStream *get_input_stream(OutputStream *ost) return NULL; } +static int compare_int64(const void *a, const void *b) +{ + int64_t va = *(int64_t *)a, vb = *(int64_t *)b; + return va < vb ? -1 : va > vb ? +1 : 0; +} + static void parse_forced_key_frames(char *kf, OutputStream *ost, AVCodecContext *avctx) { char *p; - int n = 1, i; - int64_t t; + int n = 1, i, size, index = 0; + int64_t t, *pts; for (p = kf; *p; p++) if (*p == ',') n++; - ost->forced_kf_count = n; - ost->forced_kf_pts = av_malloc(sizeof(*ost->forced_kf_pts) * n); - if (!ost->forced_kf_pts) { + size = n; + pts = av_malloc(sizeof(*pts) * size); + if (!pts) { av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n"); exit(1); } @@ -1954,11 +2023,43 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, if (next) *next++ = 0; - t = parse_time_or_die("force_key_frames", p, 1); - ost->forced_kf_pts[i] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base); + if (!memcmp(p, "chapters", 8)) { + + AVFormatContext *avf = output_files[ost->file_index]->ctx; + int j; + + if (avf->nb_chapters > INT_MAX - size || + !(pts = av_realloc_f(pts, size += avf->nb_chapters - 1, + sizeof(*pts)))) { + av_log(NULL, AV_LOG_FATAL, + "Could not allocate forced key frames array.\n"); + exit(1); + } + t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0; + t = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base); + + for (j = 0; j < avf->nb_chapters; j++) { + AVChapter *c = avf->chapters[j]; + av_assert1(index < size); + pts[index++] = av_rescale_q(c->start, c->time_base, + avctx->time_base) + t; + } + + } else { + + t = parse_time_or_die("force_key_frames", p, 1); + av_assert1(index < size); + pts[index++] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base); + + } p = next; } + + av_assert0(index == size); + qsort(pts, size, sizeof(*pts), compare_int64); + ost->forced_kf_count = size; + ost->forced_kf_pts = pts; } static void report_new_stream(int input_index, AVPacket *pkt) @@ -2045,9 +2146,10 @@ static int transcode_init(void) codec->codec_type = icodec->codec_type; if (!codec->codec_tag) { + unsigned int codec_tag; if (!oc->oformat->codec_tag || av_codec_get_id (oc->oformat->codec_tag, icodec->codec_tag) == codec->codec_id || - av_codec_get_tag(oc->oformat->codec_tag, icodec->codec_id) <= 0) + !av_codec_get_tag2(oc->oformat->codec_tag, icodec->codec_id, &codec_tag)) codec->codec_tag = icodec->codec_tag; } @@ -2124,7 +2226,7 @@ static int transcode_init(void) codec->frame_size = icodec->frame_size; codec->audio_service_type = icodec->audio_service_type; codec->block_align = icodec->block_align; - if((codec->block_align == 1 || codec->block_align == 1152) && codec->codec_id == AV_CODEC_ID_MP3) + if((codec->block_align == 1 || codec->block_align == 1152 || codec->block_align == 576) && codec->codec_id == AV_CODEC_ID_MP3) codec->block_align= 0; if(codec->codec_id == AV_CODEC_ID_AC3) codec->block_align= 0; @@ -2198,7 +2300,7 @@ static int transcode_init(void) codec->sample_fmt = ost->filter->filter->inputs[0]->format; codec->sample_rate = ost->filter->filter->inputs[0]->sample_rate; codec->channel_layout = ost->filter->filter->inputs[0]->channel_layout; - codec->channels = av_get_channel_layout_nb_channels(codec->channel_layout); + codec->channels = avfilter_link_get_channels(ost->filter->filter->inputs[0]); codec->time_base = (AVRational){ 1, codec->sample_rate }; break; case AVMEDIA_TYPE_VIDEO: @@ -2230,9 +2332,23 @@ static int transcode_init(void) codec->bits_per_raw_sample = frame_bits_per_raw_sample; } - if (ost->forced_keyframes) - parse_forced_key_frames(ost->forced_keyframes, ost, - ost->st->codec); + if (ost->forced_keyframes) { + if (!strncmp(ost->forced_keyframes, "expr:", 5)) { + ret = av_expr_parse(&ost->forced_keyframes_pexpr, ost->forced_keyframes+5, + forced_keyframes_const_names, NULL, NULL, NULL, NULL, 0, NULL); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, + "Invalid force_key_frames expression '%s'\n", ost->forced_keyframes+5); + return ret; + } + ost->forced_keyframes_expr_const_values[FKF_N] = 0; + ost->forced_keyframes_expr_const_values[FKF_N_FORCED] = 0; + ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] = NAN; + ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] = NAN; + } else { + parse_forced_key_frames(ost->forced_keyframes, ost, ost->st->codec); + } + } break; case AVMEDIA_TYPE_SUBTITLE: codec->time_base = (AVRational){1, 1000}; @@ -2321,13 +2437,20 @@ static int transcode_init(void) if (ost->st->codec->me_threshold) input_streams[ost->source_index]->st->codec->debug |= FF_DEBUG_MV; + } else { + av_opt_set_dict(ost->st->codec, &ost->opts); } } /* init input streams */ for (i = 0; i < nb_input_streams; i++) - if ((ret = init_input_stream(i, error, sizeof(error))) < 0) + if ((ret = init_input_stream(i, error, sizeof(error))) < 0) { + for (i = 0; i < nb_output_streams; i++) { + ost = output_streams[i]; + avcodec_close(ost->st->codec); + } goto dump_format; + } /* discard unused programs */ for (i = 0; i < nb_input_files; i++) { @@ -3110,6 +3233,8 @@ static int transcode(void) av_freep(&ost->st->codec->subtitle_header); av_free(ost->forced_kf_pts); av_dict_free(&ost->opts); + av_dict_free(&ost->swr_opts); + av_dict_free(&ost->resample_opts); } } } @@ -3215,8 +3340,7 @@ int main(int argc, char **argv) exit(1); ti = getutime() - ti; if (do_benchmark) { - int maxrss = getmaxrss() / 1024; - printf("bench: utime=%0.3fs maxrss=%ikB\n", ti / 1000000.0, maxrss); + printf("bench: utime=%0.3fs\n", ti / 1000000.0); } exit(received_nb_signals ? 255 : 0); diff --git a/mythtv/external/FFmpeg/ffmpeg.h b/mythtv/external/FFmpeg/ffmpeg.h index 1260563cb8c..d7046fd1e3d 100644 --- a/mythtv/external/FFmpeg/ffmpeg.h +++ b/mythtv/external/FFmpeg/ffmpeg.h @@ -41,6 +41,7 @@ #include "libavutil/avutil.h" #include "libavutil/dict.h" +#include "libavutil/eval.h" #include "libavutil/fifo.h" #include "libavutil/pixfmt.h" #include "libavutil/rational.h" @@ -113,6 +114,7 @@ typedef struct OptionsContext { int chapters_input_file; int64_t recording_time; + int64_t stop_time; uint64_t limit_filesize; float mux_preload; float mux_max_delay; @@ -171,6 +173,8 @@ typedef struct OptionsContext { int nb_pass; SpecifierOpt *passlogfiles; int nb_passlogfiles; + SpecifierOpt *guess_layout_max; + int nb_guess_layout_max; } OptionsContext; typedef struct InputFilter { @@ -195,6 +199,7 @@ typedef struct FilterGraph { const char *graph_desc; AVFilterGraph *graph; + int reconfiguration; InputFilter **inputs; int nb_inputs; @@ -229,6 +234,7 @@ typedef struct InputStream { AVDictionary *opts; AVRational framerate; /* framerate forced with -r */ int top_field_first; + int guess_layout_max; int resample_height; int resample_width; @@ -286,6 +292,17 @@ typedef struct InputFile { #endif } InputFile; +enum forced_keyframes_const { + FKF_N, + FKF_N_FORCED, + FKF_PREV_FORCED_N, + FKF_PREV_FORCED_T, + FKF_T, + FKF_NB +}; + +extern const char *const forced_keyframes_const_names[]; + typedef struct OutputStream { int file_index; /* file index */ int index; /* stream index in the output file */ @@ -317,6 +334,8 @@ typedef struct OutputStream { int forced_kf_count; int forced_kf_index; char *forced_keyframes; + AVExpr *forced_keyframes_pexpr; + double forced_keyframes_expr_const_values[FKF_NB]; /* audio only */ int audio_channels_map[SWR_CH_MAX]; /* list of the channels id to pick from the source stream */ @@ -329,10 +348,9 @@ typedef struct OutputStream { char *avfilter; int64_t sws_flags; - int64_t swr_filter_type; - int64_t swr_dither_method; - double swr_dither_scale; AVDictionary *opts; + AVDictionary *swr_opts; + AVDictionary *resample_opts; int finished; /* no more packets should be written for this stream */ int unavailable; /* true if the steram is unavailable (possibly temporarily) */ int stream_copy; diff --git a/mythtv/external/FFmpeg/ffmpeg_filter.c b/mythtv/external/FFmpeg/ffmpeg_filter.c index 60309307c5c..bdf43638ae8 100644 --- a/mythtv/external/FFmpeg/ffmpeg_filter.c +++ b/mythtv/external/FFmpeg/ffmpeg_filter.c @@ -24,6 +24,8 @@ #include "libavfilter/avfiltergraph.h" #include "libavfilter/buffersink.h" +#include "libavresample/avresample.h" + #include "libavutil/avassert.h" #include "libavutil/avstring.h" #include "libavutil/bprint.h" @@ -139,7 +141,7 @@ static char *choose_ ## var ## s(OutputStream *ost) \ if (ost->st->codec->var != none) { \ get_name(ost->st->codec->var); \ return av_strdup(name); \ - } else if (ost->enc->supported_list) { \ + } else if (ost->enc && ost->enc->supported_list) { \ const type *p; \ AVIOContext *s = NULL; \ uint8_t *ret; \ @@ -367,12 +369,16 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, char *sample_fmts, *sample_rates, *channel_layouts; char name[255]; int ret; + AVABufferSinkParams *params = av_abuffersink_params_alloc(); - + if (!params) + return AVERROR(ENOMEM); + params->all_channel_counts = 1; snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index); ret = avfilter_graph_create_filter(&ofilter->filter, avfilter_get_by_name("ffabuffersink"), - name, NULL, NULL, fg->graph); + name, NULL, params, fg->graph); + av_freep(¶ms); if (ret < 0) return ret; @@ -522,7 +528,7 @@ static int sub2video_prepare(InputStream *ist) /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the palettes for all rectangles are identical or compatible */ - ist->st->codec->pix_fmt = AV_PIX_FMT_RGB32; + ist->resample_pix_fmt = ist->st->codec->pix_fmt = AV_PIX_FMT_RGB32; ret = av_image_alloc(image, linesize, w, h, AV_PIX_FMT_RGB32, 32); if (ret < 0) @@ -620,20 +626,25 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, AVFilter *filter = avfilter_get_by_name("abuffer"); InputStream *ist = ifilter->ist; int pad_idx = in->pad_idx; - char args[255], name[255]; + AVBPrint args; + char name[255]; int ret; - snprintf(args, sizeof(args), "time_base=%d/%d:sample_rate=%d:sample_fmt=%s" - ":channel_layout=0x%"PRIx64, + av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC); + av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s", 1, ist->st->codec->sample_rate, ist->st->codec->sample_rate, - av_get_sample_fmt_name(ist->st->codec->sample_fmt), - ist->st->codec->channel_layout); + av_get_sample_fmt_name(ist->st->codec->sample_fmt)); + if (ist->st->codec->channel_layout) + av_bprintf(&args, ":channel_layout=0x%"PRIx64, + ist->st->codec->channel_layout); + else + av_bprintf(&args, ":channels=%d", ist->st->codec->channels); snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index, ist->file_index, ist->st->index); if ((ret = avfilter_graph_create_filter(&ifilter->filter, filter, - name, args, NULL, + name, args.str, NULL, fg->graph)) < 0) return ret; @@ -664,6 +675,8 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, av_strlcatf(args, sizeof(args), "async=%d", audio_sync_method); if (audio_drift_threshold != 0.1) av_strlcatf(args, sizeof(args), ":min_hard_comp=%f", audio_drift_threshold); + if (!fg->reconfiguration) + av_strlcatf(args, sizeof(args), ":first_pts=0"); AUTO_INSERT_FILTER_INPUT("-async", "aresample", args); } @@ -721,20 +734,29 @@ int configure_filtergraph(FilterGraph *fg) if (simple) { OutputStream *ost = fg->outputs[0]->ost; - char args[255]; + char args[512]; + AVDictionaryEntry *e = NULL; + snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags); fg->graph->scale_sws_opts = av_strdup(args); args[0] = 0; - if (ost->swr_filter_type != SWR_FILTER_TYPE_KAISER) - av_strlcatf(args, sizeof(args), "filter_type=%d:", (int)ost->swr_filter_type); - if (ost->swr_dither_method) - av_strlcatf(args, sizeof(args), "dither_method=%d:", (int)ost->swr_dither_method); - if (ost->swr_dither_scale != 1.0) - av_strlcatf(args, sizeof(args), "dither_scale=%f:", ost->swr_dither_scale); + while ((e = av_dict_get(ost->swr_opts, "", e, + AV_DICT_IGNORE_SUFFIX))) { + av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value); + } if (strlen(args)) args[strlen(args)-1] = 0; av_opt_set(fg->graph, "aresample_swr_opts", args, 0); + + args[0] = '\0'; + while ((e = av_dict_get(fg->outputs[0]->ost->resample_opts, "", e, + AV_DICT_IGNORE_SUFFIX))) { + av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value); + } + if (strlen(args)) + args[strlen(args) - 1] = '\0'; + fg->graph->resample_lavr_opts = av_strdup(args); } if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0) @@ -776,6 +798,7 @@ int configure_filtergraph(FilterGraph *fg) } } + fg->reconfiguration = 1; return 0; } diff --git a/mythtv/external/FFmpeg/ffmpeg_opt.c b/mythtv/external/FFmpeg/ffmpeg_opt.c index dd3f4eda5ff..2d890cfda38 100644 --- a/mythtv/external/FFmpeg/ffmpeg_opt.c +++ b/mythtv/external/FFmpeg/ffmpeg_opt.c @@ -81,7 +81,7 @@ int copy_ts = 0; int copy_tb = -1; int debug_ts = 0; int exit_on_error = 0; -int print_stats = 1; +int print_stats = -1; int qp_hist = 0; int stdin_interaction = 1; int frame_bits_per_raw_sample = 0; @@ -126,6 +126,7 @@ static void uninit_options(OptionsContext *o, int is_input) av_freep(&o->stream_maps); av_freep(&o->audio_channel_maps); av_freep(&o->streamid_map); + av_freep(&o->attachments); if (is_input) recording_time = o->recording_time; @@ -143,24 +144,13 @@ static void init_options(OptionsContext *o, int is_input) "-t is not an input option, keeping it for the next output;" " consider fixing your command line.\n"); } else - o->recording_time = INT64_MAX; + o->recording_time = INT64_MAX; + o->stop_time = INT64_MAX; o->mux_max_delay = 0.7; o->limit_filesize = UINT64_MAX; o->chapters_input_file = INT_MAX; } -static int opt_frame_crop(void *optctx, const char *opt, const char *arg) -{ - av_log(NULL, AV_LOG_FATAL, "Option '%s' has been removed, use the crop filter instead\n", opt); - return AVERROR(EINVAL); -} - -static int opt_pad(void *optctx, const char *opt, const char *arg) -{ - av_log(NULL, AV_LOG_FATAL, "Option '%s' has been removed, use the pad filter instead\n", opt); - return -1; -} - static int opt_sameq(void *optctx, const char *opt, const char *arg) { av_log(NULL, AV_LOG_ERROR, "Option '%s' was removed. " @@ -616,6 +606,8 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) break; case AVMEDIA_TYPE_AUDIO: + ist->guess_layout_max = INT_MAX; + MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st); guess_input_channel_layout(ist); ist->resample_sample_fmt = dec->sample_fmt; @@ -965,6 +957,8 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e preset, ost->file_index, ost->index); exit(1); } + } else { + ost->opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL); } avcodec_get_context_defaults3(st->codec, ost->enc); @@ -1011,9 +1005,12 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER; av_opt_get_int(o->g->sws_opts, "sws_flags", 0, &ost->sws_flags); - av_opt_get_int (o->g->swr_opts, "filter_type" , 0, &ost->swr_filter_type); - av_opt_get_int (o->g->swr_opts, "dither_method", 0, &ost->swr_dither_method); - av_opt_get_double(o->g->swr_opts, "dither_scale" , 0, &ost->swr_dither_scale); + + av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0); + if (ost->enc && av_get_exact_bits_per_sample(ost->enc->id) == 24) + av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0); + + av_dict_copy(&ost->resample_opts, o->g->resample_opts, 0); ost->source_index = source_index; if (source_index >= 0) { @@ -1662,6 +1659,20 @@ static int open_output_file(OptionsContext *o, const char *filename) exit(1); } + if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) { + o->stop_time = INT64_MAX; + av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n"); + } + + if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) { + if (o->stop_time <= o->start_time) { + av_log(NULL, AV_LOG_WARNING, "-to value smaller than -ss; ignoring -to.\n"); + o->stop_time = INT64_MAX; + } else { + o->recording_time = o->stop_time - o->start_time; + } + } + GROW_ARRAY(output_files, nb_output_files); if (!(output_files[nb_output_files - 1] = av_mallocz(sizeof(*output_files[0])))) exit(1); @@ -1695,7 +1706,8 @@ static int open_output_file(OptionsContext *o, const char *filename) print_error(filename, err); exit(1); } - } + } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename)) + assert_file_overwrite(filename); if (o->mux_preload) { uint8_t buf[64]; @@ -2117,12 +2129,14 @@ static int opt_vsync(void *optctx, const char *opt, const char *arg) return 0; } +#if FF_API_DEINTERLACE static int opt_deinterlace(void *optctx, const char *opt, const char *arg) { av_log(NULL, AV_LOG_WARNING, "-%s is deprecated, use -filter:v yadif instead\n", opt); do_deinterlace = 1; return 0; } +#endif static int opt_timecode(void *optctx, const char *opt, const char *arg) { @@ -2297,7 +2311,7 @@ static int open_files(OptionGroupList *l, const char *inout, inout, g->arg); return ret; } - av_log(NULL, AV_LOG_DEBUG, "Successfully openened the file.\n"); + av_log(NULL, AV_LOG_DEBUG, "Successfully opened the file.\n"); } return 0; @@ -2395,6 +2409,8 @@ const OptionDef options[] = { { "t", HAS_ARG | OPT_TIME | OPT_OFFSET, { .off = OFFSET(recording_time) }, "record or transcode \"duration\" seconds of audio/video", "duration" }, + { "to", HAS_ARG | OPT_TIME | OPT_OFFSET, { .off = OFFSET(stop_time) }, + "record or transcode stop time", "time_stop" }, { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET, { .off = OFFSET(limit_filesize) }, "set the limit file size in bytes", "limit_size" }, { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET, { .off = OFFSET(start_time) }, @@ -2461,7 +2477,7 @@ const OptionDef options[] = { { "profile", HAS_ARG | OPT_EXPERT | OPT_PERFILE, { .func_arg = opt_profile }, "set profile", "profile" }, { "filter", HAS_ARG | OPT_STRING | OPT_SPEC, { .off = OFFSET(filters) }, - "set stream filterchain", "filter_list" }, + "set stream filtergraph", "filter_graph" }, { "reinit_filter", HAS_ARG | OPT_INT | OPT_SPEC, { .off = OFFSET(reinit_filters) }, "reinit filtergraph on input parameter changes", "" }, { "filter_complex", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex }, @@ -2488,24 +2504,6 @@ const OptionDef options[] = { "set pixel format", "format" }, { "bits_per_raw_sample", OPT_VIDEO | OPT_INT | HAS_ARG, { &frame_bits_per_raw_sample }, "set the number of bits per raw sample", "number" }, - { "croptop", OPT_VIDEO | HAS_ARG, { .func_arg = opt_frame_crop }, - "Removed, use the crop filter instead", "size" }, - { "cropbottom", OPT_VIDEO | HAS_ARG, { .func_arg = opt_frame_crop }, - "Removed, use the crop filter instead", "size" }, - { "cropleft", OPT_VIDEO | HAS_ARG, { .func_arg = opt_frame_crop }, - "Removed, use the crop filter instead", "size" }, - { "cropright", OPT_VIDEO | HAS_ARG, { .func_arg = opt_frame_crop }, - "Removed, use the crop filter instead", "size" }, - { "padtop", OPT_VIDEO | HAS_ARG, { .func_arg = opt_pad }, - "Removed, use the pad filter instead", "size" }, - { "padbottom", OPT_VIDEO | HAS_ARG, { .func_arg = opt_pad }, - "Removed, use the pad filter instead", "size" }, - { "padleft", OPT_VIDEO | HAS_ARG, { .func_arg = opt_pad }, - "Removed, use the pad filter instead", "size" }, - { "padright", OPT_VIDEO | HAS_ARG, { .func_arg = opt_pad }, - "Removed, use the pad filter instead", "size" }, - { "padcolor", OPT_VIDEO | HAS_ARG, { .func_arg = opt_pad }, - "Removed, use the pad filter instead", "color" }, { "intra", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &intra_only }, "deprecated use -g 1" }, { "vn", OPT_VIDEO | OPT_BOOL | OPT_OFFSET, { .off = OFFSET(video_disable) }, @@ -2526,8 +2524,10 @@ const OptionDef options[] = { "select the pass number (1 to 3)", "n" }, { "passlogfile", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC, { .off = OFFSET(passlogfiles) }, "select two pass log file name prefix", "prefix" }, +#if FF_API_DEINTERLACE { "deinterlace", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_deinterlace }, "this option is deprecated, use the yadif filter instead" }, +#endif { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr }, "calculate PSNR of compressed frames" }, { "vstats", OPT_VIDEO | OPT_EXPERT , { &opt_vstats }, @@ -2535,7 +2535,7 @@ const OptionDef options[] = { { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { opt_vstats_file }, "dump video coding statistics to file", "file" }, { "vf", OPT_VIDEO | HAS_ARG | OPT_PERFILE, { .func_arg = opt_video_filters }, - "video filters", "filter list" }, + "set video filters", "filter_graph" }, { "intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC, { .off = OFFSET(intra_matrices) }, "specify intra matrix coeffs", "matrix" }, { "inter_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC, { .off = OFFSET(inter_matrices) }, @@ -2580,7 +2580,9 @@ const OptionDef options[] = { { "channel_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE, { .func_arg = opt_channel_layout }, "set channel layout", "layout" }, { "af", OPT_AUDIO | HAS_ARG | OPT_PERFILE, { .func_arg = opt_audio_filters }, - "audio filters", "filter list" }, + "set audio filters", "filter_graph" }, + { "guess_layout_max", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT, { .off = OFFSET(guess_layout_max) }, + "set the maximum number of channels to try to guess the channel layout" }, /* subtitle options */ { "sn", OPT_SUBTITLE | OPT_BOOL | OPT_OFFSET, { .off = OFFSET(subtitle_disable) }, diff --git a/mythtv/external/FFmpeg/ffplay.c b/mythtv/external/FFmpeg/ffplay.c index f300f7e567d..7276c4a6e4f 100644 --- a/mythtv/external/FFmpeg/ffplay.c +++ b/mythtv/external/FFmpeg/ffplay.c @@ -86,6 +86,9 @@ const int program_birth_year = 2003; /* we use about AUDIO_DIFF_AVG_NB A-V differences to make the average */ #define AUDIO_DIFF_AVG_NB 20 +/* polls for possible required screen refresh at least this often, should be less than 1/fps */ +#define REFRESH_RATE 0.01 + /* NOTE: the size must be big enough to compensate the hardware audio buffersize size */ /* TODO: We assume that a decoded and resampled frame fits into this buffer */ #define SAMPLE_ARRAY_SIZE (8 * 65536) @@ -116,7 +119,6 @@ typedef struct PacketQueue { typedef struct VideoPicture { double pts; // presentation timestamp for this picture int64_t pos; // byte position in file - int skip; SDL_Overlay *bmp; int width, height; /* source height & width */ AVRational sample_aspect_ratio; @@ -137,7 +139,7 @@ typedef struct SubPicture { typedef struct AudioParams { int freq; int channels; - int channel_layout; + int64_t channel_layout; enum AVSampleFormat fmt; } AudioParams; @@ -150,7 +152,6 @@ enum { typedef struct VideoState { SDL_Thread *read_tid; SDL_Thread *video_tid; - SDL_Thread *refresh_tid; AVInputFormat *iformat; int no_background; int abort_request; @@ -175,6 +176,7 @@ typedef struct VideoState { double external_clock_speed; ///< speed of the external clock double audio_clock; + int audio_clock_serial; double audio_diff_cum; /* used for AV difference average computation */ double audio_diff_avg_coef; double audio_diff_threshold; @@ -182,11 +184,11 @@ typedef struct VideoState { AVStream *audio_st; PacketQueue audioq; int audio_hw_buf_size; - DECLARE_ALIGNED(16,uint8_t,audio_buf2)[AVCODEC_MAX_AUDIO_FRAME_SIZE * 4]; uint8_t silence_buf[SDL_AUDIO_BUFFER_SIZE]; uint8_t *audio_buf; uint8_t *audio_buf1; unsigned int audio_buf_size; /* in bytes */ + unsigned int audio_buf1_size; int audio_buf_index; /* in bytes */ int audio_write_buf_size; AVPacket audio_pkt_temp; @@ -211,6 +213,7 @@ typedef struct VideoState { int rdft_bits; FFTSample *rdft_data; int xpos; + double last_vis_time; SDL_Thread *subtitle_tid; int subtitle_stream; @@ -229,14 +232,14 @@ typedef struct VideoState { double frame_last_returned_time; double frame_last_filter_delay; int64_t frame_last_dropped_pos; - double video_clock; // pts of last decoded frame / predicted pts of next decoded frame int video_stream; AVStream *video_st; PacketQueue videoq; - double video_current_pts; // current displayed pts (different from video_clock if frame fifos are used) + double video_current_pts; // current displayed pts double video_current_pts_drift; // video_current_pts - time (av_gettime) at which we updated video_current_pts - used to have running video pts int64_t video_current_pos; // current displayed file pos double max_frame_duration; // maximum duration of a frame - above this, we consider the jump a timestamp discontinuity + int video_clock_serial; VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE]; int pictq_size, pictq_rindex, pictq_windex; SDL_mutex *pictq_mutex; @@ -257,7 +260,6 @@ typedef struct VideoState { FrameBuffer *buffer_pool; #endif - int refresh; int last_video_stream, last_audio_stream, last_subtitle_stream; SDL_cond *continue_read_thread; @@ -269,10 +271,13 @@ static const char *input_filename; static const char *window_title; static int fs_screen_width; static int fs_screen_height; +static int default_width = 640; +static int default_height = 480; static int screen_width = 0; static int screen_height = 0; static int audio_disable; static int video_disable; +static int subtitle_disable; static int wanted_stream[AVMEDIA_TYPE_NB] = { [AVMEDIA_TYPE_AUDIO] = -1, [AVMEDIA_TYPE_VIDEO] = -1, @@ -304,7 +309,7 @@ static enum ShowMode show_mode = SHOW_MODE_NONE; static const char *audio_codec_name; static const char *subtitle_codec_name; static const char *video_codec_name; -static int rdftspeed = 20; +double rdftspeed = 0.02; static int64_t cursor_last_shown; static int cursor_hidden = 0; #if CONFIG_AVFILTER @@ -318,7 +323,6 @@ static int64_t audio_callback_time; static AVPacket flush_pkt; #define FF_ALLOC_EVENT (SDL_USEREVENT) -#define FF_REFRESH_EVENT (SDL_USEREVENT + 1) #define FF_QUIT_EVENT (SDL_USEREVENT + 2) static SDL_Surface *screen; @@ -971,7 +975,6 @@ static void stream_close(VideoState *is) /* XXX: use a special url_shutdown call to abort parse cleanly */ is->abort_request = 1; SDL_WaitThread(is->read_tid, NULL); - SDL_WaitThread(is->refresh_tid, NULL); packet_queue_destroy(&is->videoq); packet_queue_destroy(&is->audioq); packet_queue_destroy(&is->subtitleq); @@ -993,8 +996,7 @@ static void stream_close(VideoState *is) SDL_DestroyCond(is->subpq_cond); SDL_DestroyCond(is->continue_read_thread); #if !CONFIG_AVFILTER - if (is->img_convert_ctx) - sws_freeContext(is->img_convert_ctx); + sws_freeContext(is->img_convert_ctx); #endif av_free(is); } @@ -1023,29 +1025,30 @@ static void sigterm_handler(int sig) exit(123); } -static int video_open(VideoState *is, int force_set_video_mode) +static int video_open(VideoState *is, int force_set_video_mode, VideoPicture *vp) { int flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL; int w,h; - VideoPicture *vp = &is->pictq[is->pictq_rindex]; SDL_Rect rect; if (is_full_screen) flags |= SDL_FULLSCREEN; else flags |= SDL_RESIZABLE; + if (vp && vp->width) { + calculate_display_rect(&rect, 0, 0, INT_MAX, vp->height, vp); + default_width = rect.w; + default_height = rect.h; + } + if (is_full_screen && fs_screen_width) { w = fs_screen_width; h = fs_screen_height; } else if (!is_full_screen && screen_width) { w = screen_width; h = screen_height; - } else if (vp->width) { - calculate_display_rect(&rect, 0, 0, INT_MAX, vp->height, vp); - w = rect.w; - h = rect.h; } else { - w = 640; - h = 480; + w = default_width; + h = default_height; } if (screen && is->width == screen->w && screen->w == w && is->height== screen->h && screen->h == h && !force_set_video_mode) @@ -1069,33 +1072,18 @@ static int video_open(VideoState *is, int force_set_video_mode) static void video_display(VideoState *is) { if (!screen) - video_open(is, 0); + video_open(is, 0, NULL); if (is->audio_st && is->show_mode != SHOW_MODE_VIDEO) video_audio_display(is); else if (is->video_st) video_image_display(is); } -static int refresh_thread(void *opaque) -{ - VideoState *is= opaque; - while (!is->abort_request) { - SDL_Event event; - event.type = FF_REFRESH_EVENT; - event.user.data1 = opaque; - if (!is->refresh && (!is->paused || is->force_refresh)) { - is->refresh = 1; - SDL_PushEvent(&event); - } - //FIXME ideally we should wait the correct time but SDLs event passing is so slow it would be silly - av_usleep(is->audio_st && is->show_mode != SHOW_MODE_VIDEO ? rdftspeed*1000 : 5000); - } - return 0; -} - /* get the current audio clock value */ static double get_audio_clock(VideoState *is) { + if (is->audio_clock_serial != is->audioq.serial) + return NAN; if (is->paused) { return is->audio_current_pts; } else { @@ -1106,6 +1094,8 @@ static double get_audio_clock(VideoState *is) /* get the current video clock value */ static double get_video_clock(VideoState *is) { + if (is->video_clock_serial != is->videoq.serial) + return NAN; if (is->paused) { return is->video_current_pts; } else { @@ -1167,7 +1157,8 @@ static void update_external_clock_pts(VideoState *is, double pts) } static void check_external_clock_sync(VideoState *is, double pts) { - if (fabs(get_external_clock(is) - pts) > AV_NOSYNC_THRESHOLD) { + double ext_clock = get_external_clock(is); + if (isnan(ext_clock) || fabs(ext_clock - pts) > AV_NOSYNC_THRESHOLD) { update_external_clock_pts(is, pts); } } @@ -1201,6 +1192,7 @@ static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int seek_by_by if (seek_by_bytes) is->seek_flags |= AVSEEK_FLAG_BYTE; is->seek_req = 1; + SDL_CondSignal(is->continue_read_thread); } } @@ -1218,6 +1210,20 @@ static void stream_toggle_pause(VideoState *is) is->paused = !is->paused; } +static void toggle_pause(VideoState *is) +{ + stream_toggle_pause(is); + is->step = 0; +} + +static void step_to_next_frame(VideoState *is) +{ + /* if the stream is paused unpause it, then step */ + if (is->paused) + stream_toggle_pause(is); + is->step = 1; +} + static double compute_target_delay(double delay, VideoState *is) { double sync_threshold, diff; @@ -1232,7 +1238,7 @@ static double compute_target_delay(double delay, VideoState *is) delay to compute the threshold. I still don't know if it is the best guess */ sync_threshold = FFMAX(AV_SYNC_THRESHOLD, delay); - if (fabs(diff) < AV_NOSYNC_THRESHOLD) { + if (!isnan(diff) && fabs(diff) < AV_NOSYNC_THRESHOLD) { if (diff <= -sync_threshold) delay = 0; else if (diff >= sync_threshold) @@ -1257,20 +1263,23 @@ static void pictq_next_picture(VideoState *is) { SDL_UnlockMutex(is->pictq_mutex); } -static void pictq_prev_picture(VideoState *is) { +static int pictq_prev_picture(VideoState *is) { VideoPicture *prevvp; + int ret = 0; /* update queue size and signal for the previous picture */ prevvp = &is->pictq[(is->pictq_rindex + VIDEO_PICTURE_QUEUE_SIZE - 1) % VIDEO_PICTURE_QUEUE_SIZE]; - if (prevvp->allocated && !prevvp->skip) { + if (prevvp->allocated && prevvp->serial == is->videoq.serial) { SDL_LockMutex(is->pictq_mutex); if (is->pictq_size < VIDEO_PICTURE_QUEUE_SIZE - 1) { if (--is->pictq_rindex == -1) is->pictq_rindex = VIDEO_PICTURE_QUEUE_SIZE - 1; is->pictq_size++; + ret = 1; } SDL_CondSignal(is->pictq_cond); SDL_UnlockMutex(is->pictq_mutex); } + return ret; } static void update_video_pts(VideoState *is, double pts, int64_t pos, int serial) { @@ -1280,12 +1289,13 @@ static void update_video_pts(VideoState *is, double pts, int64_t pos, int serial is->video_current_pts_drift = is->video_current_pts - time; is->video_current_pos = pos; is->frame_last_pts = pts; + is->video_clock_serial = serial; if (is->videoq.serial == serial) check_external_clock_sync(is, is->video_current_pts); } /* called to display each frame */ -static void video_refresh(void *opaque) +static void video_refresh(void *opaque, double *remaining_time) { VideoState *is = opaque; VideoPicture *vp; @@ -1296,12 +1306,19 @@ static void video_refresh(void *opaque) if (!is->paused && get_master_sync_type(is) == AV_SYNC_EXTERNAL_CLOCK && is->realtime) check_external_clock_speed(is); - if (!display_disable && is->show_mode != SHOW_MODE_VIDEO && is->audio_st) - video_display(is); + if (!display_disable && is->show_mode != SHOW_MODE_VIDEO && is->audio_st) { + time = av_gettime() / 1000000.0; + if (is->force_refresh || is->last_vis_time + rdftspeed < time) { + video_display(is); + is->last_vis_time = time; + } + *remaining_time = FFMIN(*remaining_time, is->last_vis_time + rdftspeed - time); + } if (is->video_st) { + int redisplay = 0; if (is->force_refresh) - pictq_prev_picture(is); + redisplay = pictq_prev_picture(is); retry: if (is->pictq_size == 0) { SDL_LockMutex(is->pictq_mutex); @@ -1316,8 +1333,9 @@ static void video_refresh(void *opaque) /* dequeue the picture */ vp = &is->pictq[is->pictq_rindex]; - if (vp->skip) { + if (vp->serial != is->videoq.serial) { pictq_next_picture(is); + redisplay = 0; goto retry; } @@ -1333,8 +1351,10 @@ static void video_refresh(void *opaque) delay = compute_target_delay(is->frame_last_duration, is); time= av_gettime()/1000000.0; - if (time < is->frame_timer + delay) + if (time < is->frame_timer + delay) { + *remaining_time = FFMIN(is->frame_timer + delay - time, *remaining_time); return; + } if (delay > 0) is->frame_timer += delay * FFMAX(1, floor((time-is->frame_timer) / delay)); @@ -1346,9 +1366,11 @@ static void video_refresh(void *opaque) if (is->pictq_size > 1) { VideoPicture *nextvp = &is->pictq[(is->pictq_rindex + 1) % VIDEO_PICTURE_QUEUE_SIZE]; duration = nextvp->pts - vp->pts; - if(!is->step && (framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) && time > is->frame_timer + duration){ - is->frame_drops_late++; + if(!is->step && (redisplay || framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) && time > is->frame_timer + duration){ + if (!redisplay) + is->frame_drops_late++; pictq_next_picture(is); + redisplay = 0; goto retry; } } @@ -1459,7 +1481,7 @@ static void alloc_picture(VideoState *is) avfilter_unref_bufferp(&vp->picref); #endif - video_open(is, 0); + video_open(is, 0, vp); vp->bmp = SDL_CreateYUVOverlay(vp->width, vp->height, SDL_YV12_OVERLAY, @@ -1497,29 +1519,13 @@ static void duplicate_right_border_pixels(SDL_Overlay *bmp) { } } -static int queue_picture(VideoState *is, AVFrame *src_frame, double pts1, int64_t pos, int serial) +static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t pos, int serial) { VideoPicture *vp; - double frame_delay, pts = pts1; - - /* compute the exact PTS for the picture if it is omitted in the stream - * pts1 is the dts of the pkt / pts of the frame */ - if (pts != 0) { - /* update video clock with pts, if present */ - is->video_clock = pts; - } else { - pts = is->video_clock; - } - /* update video clock for next frame */ - frame_delay = av_q2d(is->video_st->codec->time_base); - /* for MPEG2, the frame can be repeated, so we update the - clock accordingly */ - frame_delay += src_frame->repeat_pict * (frame_delay * 0.5); - is->video_clock += frame_delay; #if defined(DEBUG_SYNC) && 0 - printf("frame_type=%c clock=%0.3f pts=%0.3f\n", - av_get_picture_type_char(src_frame->pict_type), pts, pts1); + printf("frame_type=%c pts=%0.3f\n", + av_get_picture_type_char(src_frame->pict_type), pts); #endif /* wait until we have space to put a new picture */ @@ -1619,7 +1625,6 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts1, int64_ vp->pts = pts; vp->pos = pos; - vp->skip = 0; vp->serial = serial; /* now we can update the picture count */ @@ -1634,7 +1639,7 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts1, int64_ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacket *pkt, int *serial) { - int got_picture, i; + int got_picture; if (packet_queue_get(&is->videoq, pkt, 1, serial) < 0) return -1; @@ -1644,9 +1649,6 @@ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacke SDL_LockMutex(is->pictq_mutex); // Make sure there are no long delay timers (ideally we should just flush the queue but that's harder) - for (i = 0; i < VIDEO_PICTURE_QUEUE_SIZE; i++) { - is->pictq[i].skip = 1; - } while (is->pictq_size && !is->videoq.abort_request) { SDL_CondWait(is->pictq_cond, is->pictq_mutex); } @@ -1684,7 +1686,7 @@ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacke double clockdiff = get_video_clock(is) - get_master_clock(is); double dpts = av_q2d(is->video_st->time_base) * *pts; double ptsdiff = dpts - is->frame_last_pts; - if (fabs(clockdiff) < AV_NOSYNC_THRESHOLD && + if (!isnan(clockdiff) && fabs(clockdiff) < AV_NOSYNC_THRESHOLD && ptsdiff > 0 && ptsdiff < AV_NOSYNC_THRESHOLD && clockdiff + ptsdiff - is->frame_last_filter_delay < 0) { is->frame_last_dropped_pos = pkt->pos; @@ -1753,6 +1755,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c if (!buffersink_params) return AVERROR(ENOMEM); + av_opt_get_int(sws_opts, "sws_flags", 0, &sws_flags); snprintf(sws_flags_str, sizeof(sws_flags_str), "flags=%"PRId64, sws_flags); graph->scale_sws_opts = av_strdup(sws_flags_str); @@ -1814,6 +1817,7 @@ static int video_thread(void *arg) int last_w = 0; int last_h = 0; enum AVPixelFormat last_format = -2; + int last_serial = -1; if (codec->codec->capabilities & CODEC_CAP_DR1) { is->use_dr1 = 1; @@ -1844,9 +1848,14 @@ static int video_thread(void *arg) #if CONFIG_AVFILTER if ( last_w != frame->width || last_h != frame->height - || last_format != frame->format) { - av_log(NULL, AV_LOG_INFO, "Frame changed from size:%dx%d to size:%dx%d\n", - last_w, last_h, frame->width, frame->height); + || last_format != frame->format + || last_serial != serial) { + av_log(NULL, AV_LOG_DEBUG, + "Video frame changed from size:%dx%d format:%s serial:%d to size:%dx%d format:%s serial:%d\n", + last_w, last_h, + (const char *)av_x_if_null(av_get_pix_fmt_name(last_format), "none"), last_serial, + frame->width, frame->height, + (const char *)av_x_if_null(av_get_pix_fmt_name(frame->format), "none"), serial); avfilter_graph_free(&graph); graph = avfilter_graph_alloc(); if ((ret = configure_video_filters(graph, is, vfilters, frame)) < 0) { @@ -1862,6 +1871,7 @@ static int video_thread(void *arg) last_w = frame->width; last_h = frame->height; last_format = frame->format; + last_serial = serial; } frame->pts = pts_int; @@ -2037,7 +2047,7 @@ static int synchronize_audio(VideoState *is, int nb_samples) diff = get_audio_clock(is) - get_master_clock(is); - if (fabs(diff) < AV_NOSYNC_THRESHOLD) { + if (!isnan(diff) && fabs(diff) < AV_NOSYNC_THRESHOLD) { is->audio_diff_cum = diff + is->audio_diff_avg_coef * is->audio_diff_cum; if (is->audio_diff_avg_count < AUDIO_DIFF_AVG_NB) { /* not enough measures to have a correct estimate */ @@ -2052,9 +2062,9 @@ static int synchronize_audio(VideoState *is, int nb_samples) max_nb_samples = ((nb_samples * (100 + SAMPLE_CORRECTION_PERCENT_MAX) / 100)); wanted_nb_samples = FFMIN(FFMAX(wanted_nb_samples, min_nb_samples), max_nb_samples); } - av_dlog(NULL, "diff=%f adiff=%f sample_diff=%d apts=%0.3f vpts=%0.3f %f\n", + av_dlog(NULL, "diff=%f adiff=%f sample_diff=%d apts=%0.3f %f\n", diff, avg_diff, wanted_nb_samples - nb_samples, - is->audio_clock, is->video_clock, is->audio_diff_threshold); + is->audio_clock, is->audio_diff_threshold); } } else { /* too big difference : may be initial PTS errors, so @@ -2067,8 +2077,14 @@ static int synchronize_audio(VideoState *is, int nb_samples) return wanted_nb_samples; } -/* decode one audio frame and returns its uncompressed size */ -static int audio_decode_frame(VideoState *is, double *pts_ptr) +/** + * Decode one audio frame and return its uncompressed size. + * + * The processed audio frame is decoded, converted if required, and + * stored in is->audio_buf, with size in bytes given by the return + * value. + */ +static int audio_decode_frame(VideoState *is) { AVPacket *pkt_temp = &is->audio_pkt_temp; AVPacket *pkt = &is->audio_pkt; @@ -2076,7 +2092,7 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) int len1, len2, data_size, resampled_data_size; int64_t dec_channel_layout; int got_frame; - double pts; + av_unused double audio_clock0; int new_packet = 0; int flush_complete = 0; int wanted_nb_samples; @@ -2090,6 +2106,9 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) } else avcodec_get_frame_defaults(is->frame); + if (is->audioq.serial != is->audio_pkt_temp_serial) + break; + if (is->paused) return -1; @@ -2112,13 +2131,13 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) flush_complete = 1; continue; } - data_size = av_samples_get_buffer_size(NULL, is->frame->channels, + data_size = av_samples_get_buffer_size(NULL, av_frame_get_channels(is->frame), is->frame->nb_samples, is->frame->format, 1); dec_channel_layout = - (is->frame->channel_layout && is->frame->channels == av_get_channel_layout_nb_channels(is->frame->channel_layout)) ? - is->frame->channel_layout : av_get_default_channel_layout(is->frame->channels); + (is->frame->channel_layout && av_frame_get_channels(is->frame) == av_get_channel_layout_nb_channels(is->frame->channel_layout)) ? + is->frame->channel_layout : av_get_default_channel_layout(av_frame_get_channels(is->frame)); wanted_nb_samples = synchronize_audio(is, is->frame->nb_samples); if (is->frame->format != is->audio_src.fmt || @@ -2132,20 +2151,21 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) 0, NULL); if (!is->swr_ctx || swr_init(is->swr_ctx) < 0) { fprintf(stderr, "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n", - is->frame->sample_rate, av_get_sample_fmt_name(is->frame->format), (int)is->frame->channels, - is->audio_tgt.freq, av_get_sample_fmt_name(is->audio_tgt.fmt), is->audio_tgt.channels); + is->frame->sample_rate, av_get_sample_fmt_name(is->frame->format), av_frame_get_channels(is->frame), + is->audio_tgt.freq, av_get_sample_fmt_name(is->audio_tgt.fmt), is->audio_tgt.channels); break; } is->audio_src.channel_layout = dec_channel_layout; - is->audio_src.channels = is->frame->channels; + is->audio_src.channels = av_frame_get_channels(is->frame); is->audio_src.freq = is->frame->sample_rate; is->audio_src.fmt = is->frame->format; } if (is->swr_ctx) { const uint8_t **in = (const uint8_t **)is->frame->extended_data; - uint8_t *out[] = {is->audio_buf2}; - int out_count = sizeof(is->audio_buf2) / is->audio_tgt.channels / av_get_bytes_per_sample(is->audio_tgt.fmt); + uint8_t **out = &is->audio_buf1; + int out_count = (int64_t)wanted_nb_samples * is->audio_tgt.freq / is->frame->sample_rate + 256; + int out_size = av_samples_get_buffer_size(NULL, is->audio_tgt.channels, out_count, is->audio_tgt.fmt, 0); if (wanted_nb_samples != is->frame->nb_samples) { if (swr_set_compensation(is->swr_ctx, (wanted_nb_samples - is->frame->nb_samples) * is->audio_tgt.freq / is->frame->sample_rate, wanted_nb_samples * is->audio_tgt.freq / is->frame->sample_rate) < 0) { @@ -2153,6 +2173,9 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) break; } } + av_fast_malloc(&is->audio_buf1, &is->audio_buf1_size, out_size); + if (!is->audio_buf1) + return AVERROR(ENOMEM); len2 = swr_convert(is->swr_ctx, out, out_count, in, is->frame->nb_samples); if (len2 < 0) { fprintf(stderr, "swr_convert() failed\n"); @@ -2162,24 +2185,22 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) fprintf(stderr, "warning: audio buffer is probably too small\n"); swr_init(is->swr_ctx); } - is->audio_buf = is->audio_buf2; + is->audio_buf = is->audio_buf1; resampled_data_size = len2 * is->audio_tgt.channels * av_get_bytes_per_sample(is->audio_tgt.fmt); } else { is->audio_buf = is->frame->data[0]; resampled_data_size = data_size; } - /* if no pts, then compute it */ - pts = is->audio_clock; - *pts_ptr = pts; + audio_clock0 = is->audio_clock; is->audio_clock += (double)data_size / - (is->frame->channels * is->frame->sample_rate * av_get_bytes_per_sample(is->frame->format)); + (av_frame_get_channels(is->frame) * is->frame->sample_rate * av_get_bytes_per_sample(is->frame->format)); #ifdef DEBUG { static double last_clock; - printf("audio: delay=%0.3f clock=%0.3f pts=%0.3f\n", + printf("audio: delay=%0.3f clock=%0.3f clock0=%0.3f\n", is->audio_clock - last_clock, - is->audio_clock, pts); + is->audio_clock, audio_clock0); last_clock = is->audio_clock; } #endif @@ -2191,7 +2212,7 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) av_free_packet(pkt); memset(pkt_temp, 0, sizeof(*pkt_temp)); - if (is->paused || is->audioq.abort_request) { + if (is->audioq.abort_request) { return -1; } @@ -2212,6 +2233,7 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) /* if update the audio clock with the pts */ if (pkt->pts != AV_NOPTS_VALUE) { is->audio_clock = av_q2d(is->audio_st->time_base)*pkt->pts; + is->audio_clock_serial = is->audio_pkt_temp_serial; } } } @@ -2223,13 +2245,12 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len) int audio_size, len1; int bytes_per_sec; int frame_size = av_samples_get_buffer_size(NULL, is->audio_tgt.channels, 1, is->audio_tgt.fmt, 1); - double pts; audio_callback_time = av_gettime(); while (len > 0) { if (is->audio_buf_index >= is->audio_buf_size) { - audio_size = audio_decode_frame(is, &pts); + audio_size = audio_decode_frame(is); if (audio_size < 0) { /* if error, just output silence */ is->audio_buf = is->silence_buf; @@ -2254,7 +2275,7 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len) /* Let's assume the audio driver that is used by SDL has two periods. */ is->audio_current_pts = is->audio_clock - (double)(2 * is->audio_hw_buf_size + is->audio_write_buf_size) / bytes_per_sec; is->audio_current_pts_drift = is->audio_current_pts - audio_callback_time / 1000000.0; - if (is->audioq.serial == is->audio_pkt_temp_serial) + if (is->audioq.serial == is->audio_clock_serial) check_external_clock_sync(is, is->audio_current_pts); } @@ -2438,6 +2459,7 @@ static void stream_component_close(VideoState *is, int stream_index) av_free_packet(&is->audio_pkt); swr_free(&is->swr_ctx); av_freep(&is->audio_buf1); + is->audio_buf1_size = 0; is->audio_buf = NULL; avcodec_free_frame(&is->frame); @@ -2614,7 +2636,7 @@ static int read_thread(void *arg) wanted_stream[AVMEDIA_TYPE_AUDIO], st_index[AVMEDIA_TYPE_VIDEO], NULL, 0); - if (!video_disable) + if (!video_disable && !subtitle_disable) st_index[AVMEDIA_TYPE_SUBTITLE] = av_find_best_stream(ic, AVMEDIA_TYPE_SUBTITLE, wanted_stream[AVMEDIA_TYPE_SUBTITLE], @@ -2637,7 +2659,6 @@ static int read_thread(void *arg) if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) { ret = stream_component_open(is, st_index[AVMEDIA_TYPE_VIDEO]); } - is->refresh_tid = SDL_CreateThread(refresh_thread, is); if (is->show_mode == SHOW_MODE_NONE) is->show_mode = ret >= 0 ? SHOW_MODE_VIDEO : SHOW_MODE_RDFT; @@ -2698,14 +2719,15 @@ static int read_thread(void *arg) packet_queue_put(&is->videoq, &flush_pkt); } if (is->seek_flags & AVSEEK_FLAG_BYTE) { - //FIXME: use a cleaner way to signal obsolete external clock... - update_external_clock_pts(is, (double)AV_NOPTS_VALUE); + update_external_clock_pts(is, NAN); } else { update_external_clock_pts(is, seek_target / (double)AV_TIME_BASE); } } is->seek_req = 0; eof = 0; + if (is->paused) + step_to_next_frame(is); } if (is->queue_attachments_req) { avformat_queue_attached_pictures(ic); @@ -2833,11 +2855,12 @@ static VideoState *stream_open(const char *filename, AVInputFormat *iformat) is->continue_read_thread = SDL_CreateCond(); - //FIXME: use a cleaner way to signal obsolete external clock... - update_external_clock_pts(is, (double)AV_NOPTS_VALUE); + update_external_clock_pts(is, NAN); update_external_clock_speed(is, 1.0); is->audio_current_pts_drift = -av_gettime() / 1000000.0; is->video_current_pts_drift = is->audio_current_pts_drift; + is->audio_clock_serial = -1; + is->video_clock_serial = -1; is->av_sync_type = av_sync_type; is->read_tid = SDL_CreateThread(read_thread, is); if (!is->read_tid) { @@ -2914,30 +2937,40 @@ static void toggle_full_screen(VideoState *is) is->pictq[i].reallocate = 1; #endif is_full_screen = !is_full_screen; - video_open(is, 1); -} - -static void toggle_pause(VideoState *is) -{ - stream_toggle_pause(is); - is->step = 0; -} - -static void step_to_next_frame(VideoState *is) -{ - /* if the stream is paused unpause it, then step */ - if (is->paused) - stream_toggle_pause(is); - is->step = 1; + video_open(is, 1, NULL); } static void toggle_audio_display(VideoState *is) { int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); - is->show_mode = (is->show_mode + 1) % SHOW_MODE_NB; - fill_rectangle(screen, - is->xleft, is->ytop, is->width, is->height, - bgcolor, 1); + int next = is->show_mode; + do { + next = (next + 1) % SHOW_MODE_NB; + } while (next != is->show_mode && (next == SHOW_MODE_VIDEO && !is->video_st || next != SHOW_MODE_VIDEO && !is->audio_st)); + if (is->show_mode != next) { + fill_rectangle(screen, + is->xleft, is->ytop, is->width, is->height, + bgcolor, 1); + is->force_refresh = 1; + is->show_mode = next; + } +} + +static void refresh_loop_wait_event(VideoState *is, SDL_Event *event) { + double remaining_time = 0.0; + SDL_PumpEvents(); + while (!SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) { + if (!cursor_hidden && av_gettime() - cursor_last_shown > CURSOR_HIDE_DELAY) { + SDL_ShowCursor(0); + cursor_hidden = 1; + } + if (remaining_time > 0.0) + av_usleep((int64_t)(remaining_time * 1000000.0)); + remaining_time = REFRESH_RATE; + if (is->show_mode != SHOW_MODE_NONE && (!is->paused || is->force_refresh)) + video_refresh(is, &remaining_time); + SDL_PumpEvents(); + } } /* handle an event sent by the GUI */ @@ -2948,7 +2981,7 @@ static void event_loop(VideoState *cur_stream) for (;;) { double x; - SDL_WaitEvent(&event); + refresh_loop_wait_event(cur_stream, &event); switch (event.type) { case SDL_KEYDOWN: if (exit_on_keydown) { @@ -2982,7 +3015,6 @@ static void event_loop(VideoState *cur_stream) break; case SDLK_w: toggle_audio_display(cur_stream); - cur_stream->force_refresh = 1; break; case SDLK_PAGEUP: incr = 600.0; @@ -3017,6 +3049,8 @@ static void event_loop(VideoState *cur_stream) stream_seek(cur_stream, pos, incr, 1); } else { pos = get_master_clock(cur_stream); + if (isnan(pos)) + pos = (double)cur_stream->seek_pos / AV_TIME_BASE; pos += incr; if (cur_stream->ic->start_time != AV_NOPTS_VALUE && pos < cur_stream->ic->start_time / (double)AV_TIME_BASE) pos = cur_stream->ic->start_time / (double)AV_TIME_BASE; @@ -3086,14 +3120,6 @@ static void event_loop(VideoState *cur_stream) case FF_ALLOC_EVENT: alloc_picture(event.user.data1); break; - case FF_REFRESH_EVENT: - if (!cursor_hidden && av_gettime() - cursor_last_shown > CURSOR_HIDE_DELAY) { - SDL_ShowCursor(0); - cursor_hidden = 1; - } - video_refresh(event.user.data1); - cur_stream->refresh = 0; - break; default: break; } @@ -3212,6 +3238,7 @@ static const OptionDef options[] = { { "fs", OPT_BOOL, { &is_full_screen }, "force full screen" }, { "an", OPT_BOOL, { &audio_disable }, "disable audio" }, { "vn", OPT_BOOL, { &video_disable }, "disable video" }, + { "sn", OPT_BOOL, { &subtitle_disable }, "disable subtitling" }, { "ast", OPT_INT | HAS_ARG | OPT_EXPERT, { &wanted_stream[AVMEDIA_TYPE_AUDIO] }, "select desired audio stream", "stream_number" }, { "vst", OPT_INT | HAS_ARG | OPT_EXPERT, { &wanted_stream[AVMEDIA_TYPE_VIDEO] }, "select desired video stream", "stream_number" }, { "sst", OPT_INT | HAS_ARG | OPT_EXPERT, { &wanted_stream[AVMEDIA_TYPE_SUBTITLE] }, "select desired subtitle stream", "stream_number" }, @@ -3241,7 +3268,7 @@ static const OptionDef options[] = { { "infbuf", OPT_BOOL | OPT_EXPERT, { &infinite_buffer }, "don't limit the input buffer size (useful with realtime streams)", "" }, { "window_title", OPT_STRING | HAS_ARG, { &window_title }, "set window title", "window title" }, #if CONFIG_AVFILTER - { "vf", OPT_STRING | HAS_ARG, { &vfilters }, "video filters", "filter list" }, + { "vf", OPT_STRING | HAS_ARG, { &vfilters }, "set video filters", "filter_graph" }, #endif { "rdftspeed", OPT_INT | HAS_ARG| OPT_AUDIO | OPT_EXPERT, { &rdftspeed }, "rdft speed", "msecs" }, { "showmode", HAS_ARG, { .func_arg = opt_show_mode}, "select show mode (0 = video, 1 = waves, 2 = RDFT)", "mode" }, diff --git a/mythtv/external/FFmpeg/ffprobe.c b/mythtv/external/FFmpeg/ffprobe.c index f70c24c0849..940e979848b 100644 --- a/mythtv/external/FFmpeg/ffprobe.c +++ b/mythtv/external/FFmpeg/ffprobe.c @@ -1472,11 +1472,11 @@ static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream, print_time("pkt_pts_time", frame->pkt_pts, &stream->time_base); print_ts ("pkt_dts", frame->pkt_dts); print_time("pkt_dts_time", frame->pkt_dts, &stream->time_base); - print_duration_ts ("pkt_duration", frame->pkt_duration); - print_duration_time("pkt_duration_time", frame->pkt_duration, &stream->time_base); - if (frame->pkt_pos != -1) print_fmt ("pkt_pos", "%"PRId64, frame->pkt_pos); + print_duration_ts ("pkt_duration", av_frame_get_pkt_duration(frame)); + print_duration_time("pkt_duration_time", av_frame_get_pkt_duration(frame), &stream->time_base); + if (av_frame_get_pkt_pos (frame) != -1) print_fmt ("pkt_pos", "%"PRId64, av_frame_get_pkt_pos(frame)); else print_str_opt("pkt_pos", "N/A"); - if (frame->pkt_size != -1) print_fmt ("pkt_size", "%d", av_frame_get_pkt_size(frame)); + if (av_frame_get_pkt_size(frame) != -1) print_fmt ("pkt_size", "%d", av_frame_get_pkt_size(frame)); else print_str_opt("pkt_size", "N/A"); switch (stream->codec->codec_type) { diff --git a/mythtv/external/FFmpeg/ffserver.c b/mythtv/external/FFmpeg/ffserver.c index f2cf67f6945..eee83e5695c 100644 --- a/mythtv/external/FFmpeg/ffserver.c +++ b/mythtv/external/FFmpeg/ffserver.c @@ -1125,7 +1125,7 @@ static int extract_rates(char *rates, int ratelen, const char *request) if (av_strncasecmp(p, "Pragma:", 7) == 0) { const char *q = p + 7; - while (*q && *q != '\n' && isspace(*q)) + while (*q && *q != '\n' && av_isspace(*q)) q++; if (av_strncasecmp(q, "stream-switch-entry=", 20) == 0) { @@ -1147,7 +1147,7 @@ static int extract_rates(char *rates, int ratelen, const char *request) if (stream_no < ratelen && stream_no >= 0) rates[stream_no] = rate_no; - while (*q && *q != '\n' && !isspace(*q)) + while (*q && *q != '\n' && !av_isspace(*q)) q++; } @@ -1258,7 +1258,7 @@ static void get_word(char *buf, int buf_size, const char **pp) p = *pp; skip_spaces(&p); q = buf; - while (!isspace(*p) && *p != '\0') { + while (!av_isspace(*p) && *p != '\0') { if ((q - buf) < buf_size - 1) *q++ = *p; p++; @@ -1275,7 +1275,7 @@ static void get_arg(char *buf, int buf_size, const char **pp) int quote; p = *pp; - while (isspace(*p)) p++; + while (av_isspace(*p)) p++; q = buf; quote = 0; if (*p == '\"' || *p == '\'') @@ -1285,7 +1285,7 @@ static void get_arg(char *buf, int buf_size, const char **pp) if (*p == quote) break; } else { - if (isspace(*p)) + if (av_isspace(*p)) break; } if (*p == '\0') @@ -1389,7 +1389,7 @@ static IPAddressACL* parse_dynamic_acl(FFStream *stream, HTTPContext *c) break; line_num++; p = line; - while (isspace(*p)) + while (av_isspace(*p)) p++; if (*p == '\0' || *p == '#') continue; @@ -1540,7 +1540,7 @@ static int http_parse_request(HTTPContext *c) for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) { if (av_strncasecmp(p, "User-Agent:", 11) == 0) { useragent = p + 11; - if (*useragent && *useragent != '\n' && isspace(*useragent)) + if (*useragent && *useragent != '\n' && av_isspace(*useragent)) useragent++; break; } @@ -1668,7 +1668,7 @@ static int http_parse_request(HTTPContext *c) char *eoh; char hostbuf[260]; - while (isspace(*hostinfo)) + while (av_isspace(*hostinfo)) hostinfo++; eoh = strchr(hostinfo, '\n'); @@ -4100,7 +4100,7 @@ static int parse_ffconfig(const char *filename) break; line_num++; p = line; - while (isspace(*p)) + while (av_isspace(*p)) p++; if (*p == '\0' || *p == '#') continue; @@ -4237,7 +4237,7 @@ static int parse_ffconfig(const char *filename) get_arg(arg, sizeof(arg), &p); p1 = arg; fsize = strtod(p1, &p1); - switch(toupper(*p1)) { + switch(av_toupper(*p1)) { case 'K': fsize *= 1024; break; diff --git a/mythtv/external/FFmpeg/libavcodec/4xm.c b/mythtv/external/FFmpeg/libavcodec/4xm.c index ee20a529eb6..e3d8486941a 100644 --- a/mythtv/external/FFmpeg/libavcodec/4xm.c +++ b/mythtv/external/FFmpeg/libavcodec/4xm.c @@ -130,7 +130,7 @@ typedef struct CFrameBuffer { typedef struct FourXContext { AVCodecContext *avctx; DSPContext dsp; - AVFrame current_picture, last_picture; + AVFrame *current_picture, *last_picture; GetBitContext pre_gb; ///< ac/dc prefix GetBitContext gb; GetByteContext g; @@ -138,7 +138,7 @@ typedef struct FourXContext { int mv[256]; VLC pre_vlc; int last_dc; - DECLARE_ALIGNED(16, DCTELEM, block)[6][64]; + DECLARE_ALIGNED(16, int16_t, block)[6][64]; void *bitstream_buffer; unsigned int bitstream_buffer_size; int version; @@ -153,7 +153,7 @@ typedef struct FourXContext { #define MULTIPLY(var, const) (((var) * (const)) >> 16) -static void idct(DCTELEM block[64]) +static void idct(int16_t block[64]) { int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int tmp10, tmp11, tmp12, tmp13; @@ -261,9 +261,9 @@ static void init_mv(FourXContext *f) for (i = 0; i < 256; i++) { if (f->version > 1) - f->mv[i] = mv[i][0] + mv[i][1] * f->current_picture.linesize[0] / 2; + f->mv[i] = mv[i][0] + mv[i][1] * f->current_picture->linesize[0] / 2; else - f->mv[i] = (i & 15) - 8 + ((i >> 4) - 8) * f->current_picture.linesize[0] / 2; + f->mv[i] = (i & 15) - 8 + ((i >> 4) - 8) * f->current_picture->linesize[0] / 2; } } @@ -340,7 +340,7 @@ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int code = get_vlc2(&f->gb, block_type_vlc[1 - (f->version > 1)][index].table, BLOCK_TYPE_VLC_BITS, 1); - uint16_t *start = (uint16_t *)f->last_picture.data[0]; + uint16_t *start = (uint16_t *)f->last_picture->data[0]; uint16_t *end = start + stride * (f->avctx->height - h + 1) - (1 << log2w); av_assert2(code >= 0 && code <= 6); @@ -409,9 +409,9 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length) int x, y; const int width = f->avctx->width; const int height = f->avctx->height; - uint16_t *src = (uint16_t *)f->last_picture.data[0]; - uint16_t *dst = (uint16_t *)f->current_picture.data[0]; - const int stride = f->current_picture.linesize[0] >> 1; + uint16_t *src = (uint16_t *)f->last_picture->data[0]; + uint16_t *dst = (uint16_t *)f->current_picture->data[0]; + const int stride = f->current_picture->linesize[0] >> 1; unsigned int bitstream_size, bytestream_size, wordstream_size, extra, bytestream_offset, wordstream_offset; @@ -435,7 +435,7 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length) extra > length - bytestream_size - bitstream_size - wordstream_size) { av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", bitstream_size, bytestream_size, wordstream_size, bitstream_size+ bytestream_size+ wordstream_size - length); - return -1; + return AVERROR_INVALIDDATA; } av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size, @@ -471,7 +471,7 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length) * decode block and dequantize. * Note this is almost identical to MJPEG. */ -static int decode_i_block(FourXContext *f, DCTELEM *block) +static int decode_i_block(FourXContext *f, int16_t *block) { int code, i, j, level, val; @@ -521,10 +521,10 @@ static int decode_i_block(FourXContext *f, DCTELEM *block) static inline void idct_put(FourXContext *f, int x, int y) { - DCTELEM (*block)[64] = f->block; - int stride = f->current_picture.linesize[0] >> 1; + int16_t (*block)[64] = f->block; + int stride = f->current_picture->linesize[0] >> 1; int i; - uint16_t *dst = ((uint16_t*)f->current_picture.data[0]) + y * stride + x; + uint16_t *dst = ((uint16_t*)f->current_picture->data[0]) + y * stride + x; for (i = 0; i < 4; i++) { block[i][0] += 0x80 * 8 * 8; @@ -542,7 +542,7 @@ static inline void idct_put(FourXContext *f, int x, int y) * cr = (-1b - 4g + 5r) / 14 */ for (y = 0; y < 8; y++) { for (x = 0; x < 8; x++) { - DCTELEM *temp = block[(x >> 2) + 2 * (y >> 2)] + + int16_t *temp = block[(x >> 2) + 2 * (y >> 2)] + 2 * (x & 3) + 2 * 8 * (y & 3); // FIXME optimize int cb = block[4][x + 8 * y]; int cr = block[5][x + 8 * y]; @@ -567,13 +567,14 @@ static inline void idct_put(FourXContext *f, int x, int y) static int decode_i_mb(FourXContext *f) { + int ret; int i; f->dsp.clear_blocks(f->block[0]); for (i = 0; i < 6; i++) - if (decode_i_block(f, f->block[i]) < 0) - return -1; + if ((ret = decode_i_block(f, f->block[i])) < 0) + return ret; return 0; } @@ -598,8 +599,10 @@ static const uint8_t *read_huffman_tables(FourXContext *f, for (;;) { int i; - if (start <= end && ptr_end - ptr < end - start + 1 + 1) + if (ptr_end - ptr < FFMAX(end - start + 1, 0) + 1) { + av_log(f->avctx, AV_LOG_ERROR, "invalid data in read_huffman_tables\n"); return NULL; + } for (i = start; i <= end; i++) frequency[i] = *ptr++; start = *ptr++; @@ -613,6 +616,11 @@ static const uint8_t *read_huffman_tables(FourXContext *f, while ((ptr - buf) & 3) ptr++; // 4byte align + if (ptr > ptr_end) { + av_log(f->avctx, AV_LOG_ERROR, "ptr overflow in read_huffman_tables\n"); + return NULL; + } + for (j = 257; j < 512; j++) { int min_freq[2] = { 256 * 256, 256 * 256 }; int smallest[2] = { 0, 0 }; @@ -680,8 +688,8 @@ static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length) const int width = f->avctx->width; const int height = f->avctx->height; const int mbs = (FFALIGN(width, 16) >> 4) * (FFALIGN(height, 16) >> 4); - uint16_t *dst = (uint16_t*)f->current_picture.data[0]; - const int stride = f->current_picture.linesize[0]>>1; + uint16_t *dst = (uint16_t*)f->current_picture->data[0]; + const int stride = f->current_picture->linesize[0]>>1; const uint8_t *buf_end = buf + length; GetByteContext g3; @@ -725,7 +733,7 @@ static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length) static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length) { - int x, y; + int x, y, ret; const int width = f->avctx->width; const int height = f->avctx->height; const unsigned int bitstream_size = AV_RL32(buf); @@ -745,7 +753,7 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length) || prestream_size > (1 << 26)) { av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d %d\n", prestream_size, bitstream_size, length); - return -1; + return AVERROR_INVALIDDATA; } prestream = read_huffman_tables(f, prestream, buf + length - prestream); @@ -754,6 +762,8 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length) return AVERROR_INVALIDDATA; } + av_assert0(prestream <= buf + length); + init_get_bits(&f->gb, buf + 4, 8 * bitstream_size); prestream_size = length + buf - prestream; @@ -772,8 +782,8 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length) for (y = 0; y < height; y += 16) { for (x = 0; x < width; x += 16) { - if (decode_i_mb(f) < 0) - return -1; + if ((ret = decode_i_mb(f)) < 0) + return ret; idct_put(f, x, y); } @@ -792,8 +802,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int buf_size = avpkt->size; FourXContext *const f = avctx->priv_data; AVFrame *picture = data; - AVFrame *p, temp; - int i, frame_4cc, frame_size; + AVFrame *p; + int i, frame_4cc, frame_size, ret; if (buf_size < 12) return AVERROR_INVALIDDATA; @@ -845,7 +855,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, // explicit check needed as memcpy below might not catch a NULL if (!cfrm->data) { av_log(f->avctx, AV_LOG_ERROR, "realloc failure\n"); - return -1; + return AVERROR(ENOMEM); } memcpy(cfrm->data + cfrm->size, buf + 20, data_size); @@ -868,49 +878,47 @@ static int decode_frame(AVCodecContext *avctx, void *data, frame_size = buf_size - 12; } - temp = f->current_picture; - f->current_picture = f->last_picture; - f->last_picture = temp; + FFSWAP(AVFrame*, f->current_picture, f->last_picture); - p = &f->current_picture; + p = f->current_picture; avctx->coded_frame = p; // alternatively we would have to use our own buffer management avctx->flags |= CODEC_FLAG_EMU_EDGE; p->reference= 3; - if (avctx->reget_buffer(avctx, p) < 0) { + if ((ret = avctx->reget_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } if (frame_4cc == AV_RL32("ifr2")) { p->pict_type= AV_PICTURE_TYPE_I; - if (decode_i2_frame(f, buf - 4, frame_size + 4) < 0) { + if ((ret = decode_i2_frame(f, buf - 4, frame_size + 4)) < 0) { av_log(f->avctx, AV_LOG_ERROR, "decode i2 frame failed\n"); - return -1; + return ret; } } else if (frame_4cc == AV_RL32("ifrm")) { p->pict_type= AV_PICTURE_TYPE_I; - if (decode_i_frame(f, buf, frame_size) < 0) { + if ((ret = decode_i_frame(f, buf, frame_size)) < 0) { av_log(f->avctx, AV_LOG_ERROR, "decode i frame failed\n"); - return -1; + return ret; } } else if (frame_4cc == AV_RL32("pfrm") || frame_4cc == AV_RL32("pfr2")) { - if (!f->last_picture.data[0]) { - f->last_picture.reference = 3; - if (ff_get_buffer(avctx, &f->last_picture) < 0) { + if (!f->last_picture->data[0]) { + f->last_picture->reference = 3; + if ((ret = ff_get_buffer(avctx, f->last_picture)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } for (i=0; iheight; i++) - memset(f->last_picture.data[0] + i*f->last_picture.linesize[0], 0, 2*avctx->width); + memset(f->last_picture->data[0] + i*f->last_picture->linesize[0], 0, 2*avctx->width); } p->pict_type = AV_PICTURE_TYPE_P; - if (decode_p_frame(f, buf, frame_size) < 0) { + if ((ret = decode_p_frame(f, buf, frame_size)) < 0) { av_log(f->avctx, AV_LOG_ERROR, "decode p frame failed\n"); - return -1; + return ret; } } else if (frame_4cc == AV_RL32("snd_")) { av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n", @@ -930,16 +938,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, return buf_size; } - -static av_cold void common_init(AVCodecContext *avctx) -{ - FourXContext * const f = avctx->priv_data; - - ff_dsputil_init(&f->dsp, avctx); - - f->avctx = avctx; -} - static av_cold int decode_init(AVCodecContext *avctx) { FourXContext * const f = avctx->priv_data; @@ -953,10 +951,9 @@ static av_cold int decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } - avcodec_get_frame_defaults(&f->current_picture); - avcodec_get_frame_defaults(&f->last_picture); f->version = AV_RL32(avctx->extradata) >> 16; - common_init(avctx); + ff_dsputil_init(&f->dsp, avctx); + f->avctx = avctx; init_vlcs(f); if (f->version > 2) @@ -964,6 +961,14 @@ static av_cold int decode_init(AVCodecContext *avctx) else avctx->pix_fmt = AV_PIX_FMT_BGR555; + f->current_picture = avcodec_alloc_frame(); + f->last_picture = avcodec_alloc_frame(); + if (!f->current_picture || !f->last_picture) { + avcodec_free_frame(&f->current_picture); + avcodec_free_frame(&f->last_picture); + return AVERROR(ENOMEM); + } + return 0; } @@ -980,10 +985,12 @@ static av_cold int decode_end(AVCodecContext *avctx) f->cfrm[i].allocated_size = 0; } ff_free_vlc(&f->pre_vlc); - if (f->current_picture.data[0]) - avctx->release_buffer(avctx, &f->current_picture); - if (f->last_picture.data[0]) - avctx->release_buffer(avctx, &f->last_picture); + if (f->current_picture->data[0]) + avctx->release_buffer(avctx, f->current_picture); + if (f->last_picture->data[0]) + avctx->release_buffer(avctx, f->last_picture); + avcodec_free_frame(&f->current_picture); + avcodec_free_frame(&f->last_picture); return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/8bps.c b/mythtv/external/FFmpeg/libavcodec/8bps.c index cfeedb108e6..158e29faeaf 100644 --- a/mythtv/external/FFmpeg/libavcodec/8bps.c +++ b/mythtv/external/FFmpeg/libavcodec/8bps.c @@ -68,15 +68,16 @@ static int decode_frame(AVCodecContext *avctx, void *data, unsigned char count; unsigned int planes = c->planes; unsigned char *planemap = c->planemap; + int ret; if (c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); c->pic.reference = 0; c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; - if (ff_get_buffer(avctx, &c->pic) < 0){ + if ((ret = ff_get_buffer(avctx, &c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } /* Set data pointer after line lengths */ @@ -96,14 +97,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, /* Decode a row of this plane */ while (dlen > 0) { if (dp + 1 >= buf + buf_size) - return -1; + return AVERROR_INVALIDDATA; if ((count = *dp++) <= 127) { count++; dlen -= count + 1; if (pixptr + count * planes > pixptr_end) break; if (dp + count > buf + buf_size) - return -1; + return AVERROR_INVALIDDATA; while (count--) { *pixptr = *dp++; pixptr += planes; @@ -181,7 +182,7 @@ static av_cold int decode_init(AVCodecContext *avctx) default: av_log(avctx, AV_LOG_ERROR, "Error: Unsupported color depth: %u.\n", avctx->bits_per_coded_sample); - return -1; + return AVERROR_INVALIDDATA; } return 0; diff --git a/mythtv/external/FFmpeg/libavcodec/8svx.c b/mythtv/external/FFmpeg/libavcodec/8svx.c index 4bbbeb139f6..d33f73e0395 100644 --- a/mythtv/external/FFmpeg/libavcodec/8svx.c +++ b/mythtv/external/FFmpeg/libavcodec/8svx.c @@ -44,7 +44,6 @@ /** decoder context */ typedef struct EightSvxContext { - AVFrame frame; uint8_t fib_acc[2]; const int8_t *table; @@ -88,6 +87,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { EightSvxContext *esc = avctx->priv_data; + AVFrame *frame = data; int buf_size; int ch, ret; int hdr_size = 2; @@ -135,21 +135,20 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - esc->frame.nb_samples = buf_size * 2; - if ((ret = ff_get_buffer(avctx, &esc->frame)) < 0) { + frame->nb_samples = buf_size * 2; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } for (ch = 0; ch < avctx->channels; ch++) { - delta_decode(esc->frame.data[ch], &esc->data[ch][esc->data_idx], + delta_decode(frame->data[ch], &esc->data[ch][esc->data_idx], buf_size, &esc->fib_acc[ch], esc->table); } esc->data_idx += buf_size; - *got_frame_ptr = 1; - *(AVFrame *)data = esc->frame; + *got_frame_ptr = 1; return ((avctx->frame_number == 0)*hdr_size + buf_size)*avctx->channels; } @@ -172,9 +171,6 @@ static av_cold int eightsvx_decode_init(AVCodecContext *avctx) } avctx->sample_fmt = AV_SAMPLE_FMT_U8P; - avcodec_get_frame_defaults(&esc->frame); - avctx->coded_frame = &esc->frame; - return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/Makefile b/mythtv/external/FFmpeg/libavcodec/Makefile index 082949d9312..edab72c2225 100644 --- a/mythtv/external/FFmpeg/libavcodec/Makefile +++ b/mythtv/external/FFmpeg/libavcodec/Makefile @@ -42,7 +42,6 @@ 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_DWT) += dwt.o snow.o OBJS-$(CONFIG_DXVA2) += dxva2.o OBJS-$(CONFIG_ENCODERS) += faandct.o jfdctfst.o jfdctint.o OBJS-$(CONFIG_ERROR_RESILIENCE) += error_resilience.o @@ -50,8 +49,10 @@ FFT-OBJS-$(CONFIG_HARDCODED_TABLES) += cos_tables.o cos_fixed_tables.o OBJS-$(CONFIG_FFT) += avfft.o fft_fixed.o fft_float.o \ $(FFT-OBJS-yes) OBJS-$(CONFIG_GOLOMB) += golomb.o +OBJS-$(CONFIG_H264CHROMA) += h264chroma.o OBJS-$(CONFIG_H264DSP) += h264dsp.o h264idct.o OBJS-$(CONFIG_H264PRED) += h264pred.o +OBJS-$(CONFIG_H264QPEL) += h264qpel.o OBJS-$(CONFIG_HUFFMAN) += huffman.o OBJS-$(CONFIG_LIBXVID) += libxvid_rc.o OBJS-$(CONFIG_LPC) += lpc.o @@ -159,7 +160,7 @@ OBJS-$(CONFIG_DCA_DECODER) += dcadec.o dca.o dcadsp.o \ dca_parser.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 dwt.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 @@ -189,6 +190,7 @@ OBJS-$(CONFIG_EIGHTSVX_EXP_DECODER) += 8svx.o 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 @@ -219,6 +221,7 @@ OBJS-$(CONFIG_H263_DECODER) += h263dec.o h263.o ituh263dec.o \ mpeg4video.o mpeg4videodec.o flvdec.o\ intelh263dec.o OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o +OBJS-$(CONFIG_H263_VDPAU_HWACCEL) += vdpau_mpeg4.o OBJS-$(CONFIG_H263_ENCODER) += mpeg4videoenc.o mpeg4video.o \ h263.o ituh263enc.o flvenc.o OBJS-$(CONFIG_H264_DECODER) += h264.o \ @@ -229,6 +232,7 @@ 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_VDA_DECODER) += vda_h264_dec.o +OBJS-$(CONFIG_H264_VDPAU_HWACCEL) += vdpau_h264.o OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o huffyuvdec.o OBJS-$(CONFIG_HUFFYUV_ENCODER) += huffyuv.o huffyuvenc.o OBJS-$(CONFIG_IAC_DECODER) += imc.o @@ -285,15 +289,18 @@ OBJS-$(CONFIG_MPC8_DECODER) += mpc8.o mpc.o OBJS-$(CONFIG_MPEGVIDEO_DECODER) += mpeg12.o mpeg12data.o \ mpegvideo.o error_resilience.o OBJS-$(CONFIG_MPEG_XVMC_DECODER) += mpegvideo_xvmc.o +OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL) += vdpau_mpeg12.o OBJS-$(CONFIG_MPEG1VIDEO_DECODER) += mpeg12.o mpeg12data.o OBJS-$(CONFIG_MPEG1VIDEO_ENCODER) += mpeg12enc.o mpeg12.o \ timecode.o OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL) += dxva2_mpeg2.o OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL) += vaapi_mpeg2.o +OBJS-$(CONFIG_MPEG2_VDPAU_HWACCEL) += vdpau_mpeg12.o OBJS-$(CONFIG_MPEG2VIDEO_DECODER) += mpeg12.o mpeg12data.o OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpeg12.o \ timecode.o OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL) += vaapi_mpeg4.o +OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL) += vdpau_mpeg4.o OBJS-$(CONFIG_MPL2_DECODER) += mpl2dec.o ass.o OBJS-$(CONFIG_MSMPEG4V1_DECODER) += msmpeg4.o msmpeg4data.o OBJS-$(CONFIG_MSMPEG4V2_DECODER) += msmpeg4.o msmpeg4data.o h263dec.o \ @@ -390,8 +397,8 @@ OBJS-$(CONFIG_SIPR_DECODER) += sipr.o acelp_pitch_delay.o \ OBJS-$(CONFIG_SMACKAUD_DECODER) += smacker.o OBJS-$(CONFIG_SMACKER_DECODER) += smacker.o OBJS-$(CONFIG_SMC_DECODER) += smc.o -OBJS-$(CONFIG_SNOW_DECODER) += snowdec.o snow.o -OBJS-$(CONFIG_SNOW_ENCODER) += snowenc.o snow.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 @@ -452,12 +459,12 @@ OBJS-$(CONFIG_VC1_DECODER) += vc1dec.o vc1.o vc1data.o vc1dsp.o \ intrax8.o intrax8dsp.o OBJS-$(CONFIG_VC1_DXVA2_HWACCEL) += dxva2_vc1.o OBJS-$(CONFIG_VC1_VAAPI_HWACCEL) += vaapi_vc1.o +OBJS-$(CONFIG_VC1_VDPAU_HWACCEL) += vdpau_vc1.o OBJS-$(CONFIG_VCR1_DECODER) += vcr1.o -OBJS-$(CONFIG_VCR1_ENCODER) += vcr1.o OBJS-$(CONFIG_VMDAUDIO_DECODER) += vmdav.o OBJS-$(CONFIG_VMDVIDEO_DECODER) += vmdav.o OBJS-$(CONFIG_VMNC_DECODER) += vmnc.o -OBJS-$(CONFIG_VORBIS_DECODER) += vorbisdec.o vorbis.o \ +OBJS-$(CONFIG_VORBIS_DECODER) += vorbisdec.o vorbisdsp.o vorbis.o \ vorbis_data.o xiph.o OBJS-$(CONFIG_VORBIS_ENCODER) += vorbisenc.o vorbis.o \ vorbis_data.o @@ -481,10 +488,10 @@ OBJS-$(CONFIG_WMAVOICE_DECODER) += wmavoice.o \ celp_filters.o \ acelp_vectors.o acelp_filters.o OBJS-$(CONFIG_WMV1_DECODER) += msmpeg4.o msmpeg4data.o -OBJS-$(CONFIG_WMV2_DECODER) += wmv2dec.o wmv2.o \ +OBJS-$(CONFIG_WMV2_DECODER) += wmv2dec.o wmv2.o wmv2dsp.o \ msmpeg4.o msmpeg4data.o \ intrax8.o intrax8dsp.o -OBJS-$(CONFIG_WMV2_ENCODER) += wmv2enc.o wmv2.o \ +OBJS-$(CONFIG_WMV2_ENCODER) += wmv2enc.o wmv2.o wmv2dsp.o \ msmpeg4.o msmpeg4enc.o msmpeg4data.o \ mpeg4videodec.o ituh263dec.o h263dec.o OBJS-$(CONFIG_WNV1_DECODER) += wnv1.o @@ -693,8 +700,10 @@ OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o OBJS-$(CONFIG_LIBVORBIS_DECODER) += libvorbisdec.o OBJS-$(CONFIG_LIBVORBIS_ENCODER) += libvorbisenc.o \ vorbis_data.o vorbis_parser.o xiph.o -OBJS-$(CONFIG_LIBVPX_DECODER) += libvpxdec.o -OBJS-$(CONFIG_LIBVPX_ENCODER) += libvpxenc.o +OBJS-$(CONFIG_LIBVPX_VP8_DECODER) += libvpxdec.o +OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o +OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o +OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o OBJS-$(CONFIG_LIBX264_ENCODER) += libx264.o OBJS-$(CONFIG_LIBXAVS_ENCODER) += libxavs.o OBJS-$(CONFIG_LIBXVID_ENCODER) += libxvid.o diff --git a/mythtv/external/FFmpeg/libavcodec/aac.h b/mythtv/external/FFmpeg/libavcodec/aac.h index 9e9fa0ea64f..d586e271dac 100644 --- a/mythtv/external/FFmpeg/libavcodec/aac.h +++ b/mythtv/external/FFmpeg/libavcodec/aac.h @@ -32,7 +32,6 @@ #include "libavutil/float_dsp.h" #include "avcodec.h" -#include "dsputil.h" #include "fft.h" #include "mpeg4audio.h" #include "sbr.h" @@ -260,10 +259,10 @@ typedef struct ChannelElement { /** * main AAC context */ -typedef struct AACContext { +struct AACContext { AVClass *class; AVCodecContext *avctx; - AVFrame frame; + AVFrame *frame; int is_saved; ///< Set if elements have stored overlap from previous frame. DynamicRangeControl che_drc; @@ -292,7 +291,6 @@ typedef struct AACContext { FFTContext mdct; FFTContext mdct_small; FFTContext mdct_ltp; - DSPContext dsp; FmtConvertContext fmt_conv; AVFloatDSPContext fdsp; int random_state; @@ -318,6 +316,18 @@ typedef struct AACContext { OutputConfiguration oc[2]; int warned_num_aac_frames; -} AACContext; + + /* aacdec functions pointers */ + void (*imdct_and_windowing)(AACContext *ac, SingleChannelElement *sce); + void (*apply_ltp)(AACContext *ac, SingleChannelElement *sce); + void (*apply_tns)(float coef[1024], TemporalNoiseShaping *tns, + IndividualChannelStream *ics, int decode); + void (*windowing_and_mdct_ltp)(AACContext *ac, float *out, + float *in, IndividualChannelStream *ics); + void (*update_ltp)(AACContext *ac, SingleChannelElement *sce); + +}; + +void ff_aacdec_init_mips(AACContext *c); #endif /* AVCODEC_AAC_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/aacdec.c b/mythtv/external/FFmpeg/libavcodec/aacdec.c index d782e578a7d..7a871c40227 100644 --- a/mythtv/external/FFmpeg/libavcodec/aacdec.c +++ b/mythtv/external/FFmpeg/libavcodec/aacdec.c @@ -84,7 +84,6 @@ #include "avcodec.h" #include "internal.h" #include "get_bits.h" -#include "dsputil.h" #include "fft.h" #include "fmtconvert.h" #include "lpc.h" @@ -108,6 +107,8 @@ #if ARCH_ARM # include "arm/aac.h" +#elif ARCH_MIPS +# include "mips/aacdec_mips.h" #endif static VLC vlc_scalefactors; @@ -189,8 +190,8 @@ static int frame_configure_elements(AVCodecContext *avctx) } /* get output buffer */ - ac->frame.nb_samples = 2048; - if ((ret = ff_get_buffer(avctx, &ac->frame)) < 0) { + ac->frame->nb_samples = 2048; + if ((ret = ff_get_buffer(avctx, ac->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -198,7 +199,7 @@ static int frame_configure_elements(AVCodecContext *avctx) /* map output channel pointers to AVFrame data */ for (ch = 0; ch < avctx->channels; ch++) { if (ac->output_element[ch]) - ac->output_element[ch]->ret = (float *)ac->frame.extended_data[ch]; + ac->output_element[ch]->ret = (float *)ac->frame->extended_data[ch]; } return 0; @@ -780,13 +781,15 @@ static int decode_audio_specific_config(AACContext *ac, { GetBitContext gb; int i; + int ret; av_dlog(avctx, "audio specific config size %d\n", bit_size >> 3); for (i = 0; i < bit_size >> 3; i++) av_dlog(avctx, "%02x ", data[i]); av_dlog(avctx, "\n"); - init_get_bits(&gb, data, bit_size); + if ((ret = init_get_bits(&gb, data, bit_size)) < 0) + return ret; if ((i = avpriv_mpeg4audio_get_config(m4ac, data, bit_size, sync_extension)) < 0) return -1; @@ -876,6 +879,8 @@ static void reset_predictor_group(PredictorState *ps, int group_num) ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), sizeof(ff_aac_spectral_codes[num][0]), \ size); +static void aacdec_init(AACContext *ac); + static av_cold int aac_decode_init(AVCodecContext *avctx) { AACContext *ac = avctx->priv_data; @@ -883,6 +888,8 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) ac->avctx = avctx; ac->oc[1].m4ac.sample_rate = avctx->sample_rate; + aacdec_init(ac); + avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; if (avctx->extradata_size > 0) { @@ -939,7 +946,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) ff_aac_sbr_init(); - ff_dsputil_init(&ac->dsp, avctx); ff_fmt_convert_init(&ac->fmt_conv, avctx); avpriv_float_dsp_init(&ac->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); @@ -963,9 +969,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) cbrt_tableinit(); - avcodec_get_frame_defaults(&ac->frame); - avctx->coded_frame = &ac->frame; - return 0; } @@ -1405,7 +1408,7 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024], cfo[k] = ac->random_state; } - band_energy = ac->dsp.scalarproduct_float(cfo, cfo, off_len); + band_energy = ac->fdsp.scalarproduct_float(cfo, cfo, off_len); scale = sf[idx] / sqrtf(band_energy); ac->fdsp.vector_fmul_scalar(cfo, cfo, scale, off_len); } @@ -1740,9 +1743,9 @@ static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe) if (cpe->ms_mask[idx] && cpe->ch[0].band_type[idx] < NOISE_BT && cpe->ch[1].band_type[idx] < NOISE_BT) { for (group = 0; group < ics->group_len[g]; group++) { - ac->dsp.butterflies_float(ch0 + group * 128 + offsets[i], - ch1 + group * 128 + offsets[i], - offsets[i+1] - offsets[i]); + ac->fdsp.butterflies_float(ch0 + group * 128 + offsets[i], + ch1 + group * 128 + offsets[i], + offsets[i+1] - offsets[i]); } } } @@ -2142,9 +2145,9 @@ static void windowing_and_mdct_ltp(AACContext *ac, float *out, ac->fdsp.vector_fmul(in + 448, in + 448, swindow_prev, 128); } if (ics->window_sequence[0] != LONG_START_SEQUENCE) { - ac->dsp.vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024); + ac->fdsp.vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024); } else { - ac->dsp.vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128); + ac->fdsp.vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128); memset(in + 1024 + 576, 0, 448 * sizeof(float)); } ac->mdct_ltp.mdct_calc(&ac->mdct_ltp, out, in); @@ -2170,10 +2173,10 @@ static void apply_ltp(AACContext *ac, SingleChannelElement *sce) predTime[i] = sce->ltp_state[i + 2048 - ltp->lag] * ltp->coef; memset(&predTime[i], 0, (2048 - i) * sizeof(float)); - windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics); + ac->windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics); if (sce->tns.present) - apply_tns(predFreq, &sce->tns, &sce->ics, 0); + ac->apply_tns(predFreq, &sce->tns, &sce->ics, 0); for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++) if (ltp->used[sfb]) @@ -2197,17 +2200,17 @@ static void update_ltp(AACContext *ac, SingleChannelElement *sce) if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { memcpy(saved_ltp, saved, 512 * sizeof(float)); memset(saved_ltp + 576, 0, 448 * sizeof(float)); - ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); + ac->fdsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); for (i = 0; i < 64; i++) saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i]; } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { memcpy(saved_ltp, ac->buf_mdct + 512, 448 * sizeof(float)); memset(saved_ltp + 576, 0, 448 * sizeof(float)); - ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); + ac->fdsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); for (i = 0; i < 64; i++) saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i]; } else { // LONG_STOP or ONLY_LONG - ac->dsp.vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, &lwindow[512], 512); + ac->fdsp.vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, &lwindow[512], 512); for (i = 0; i < 512; i++) saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * lwindow[511 - i]; } @@ -2248,35 +2251,35 @@ static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce) */ if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) && (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) { - ac->dsp.vector_fmul_window( out, saved, buf, lwindow_prev, 512); + ac->fdsp.vector_fmul_window( out, saved, buf, lwindow_prev, 512); } else { - memcpy( out, saved, 448 * sizeof(float)); + memcpy( out, saved, 448 * sizeof(float)); if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { - ac->dsp.vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, 64); - ac->dsp.vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, 64); - ac->dsp.vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, 64); - ac->dsp.vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, 64); - ac->dsp.vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, 64); - memcpy( out + 448 + 4*128, temp, 64 * sizeof(float)); + ac->fdsp.vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, 64); + ac->fdsp.vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, 64); + ac->fdsp.vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, 64); + ac->fdsp.vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, 64); + ac->fdsp.vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, 64); + memcpy( out + 448 + 4*128, temp, 64 * sizeof(float)); } else { - ac->dsp.vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64); - memcpy( out + 576, buf + 64, 448 * sizeof(float)); + ac->fdsp.vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64); + memcpy( out + 576, buf + 64, 448 * sizeof(float)); } } // buffer update if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { - memcpy( saved, temp + 64, 64 * sizeof(float)); - ac->dsp.vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64); - ac->dsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64); - ac->dsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64); - memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float)); + memcpy( saved, temp + 64, 64 * sizeof(float)); + ac->fdsp.vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64); + ac->fdsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64); + ac->fdsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64); + memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float)); } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { - memcpy( saved, buf + 512, 448 * sizeof(float)); - memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float)); + memcpy( saved, buf + 512, 448 * sizeof(float)); + memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float)); } else { // LONG_STOP or ONLY_LONG - memcpy( saved, buf + 512, 512 * sizeof(float)); + memcpy( saved, buf + 512, 512 * sizeof(float)); } } @@ -2385,25 +2388,25 @@ static void spectral_to_sample(AACContext *ac) if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) { if (che->ch[0].ics.predictor_present) { if (che->ch[0].ics.ltp.present) - apply_ltp(ac, &che->ch[0]); + ac->apply_ltp(ac, &che->ch[0]); if (che->ch[1].ics.ltp.present && type == TYPE_CPE) - apply_ltp(ac, &che->ch[1]); + ac->apply_ltp(ac, &che->ch[1]); } } if (che->ch[0].tns.present) - apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ics, 1); + ac->apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ics, 1); if (che->ch[1].tns.present) - apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1); + ac->apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1); if (type <= TYPE_CPE) apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, apply_dependent_coupling); if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) { - imdct_and_windowing(ac, &che->ch[0]); + ac->imdct_and_windowing(ac, &che->ch[0]); if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) - update_ltp(ac, &che->ch[0]); + ac->update_ltp(ac, &che->ch[0]); if (type == TYPE_CPE) { - imdct_and_windowing(ac, &che->ch[1]); + ac->imdct_and_windowing(ac, &che->ch[1]); if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) - update_ltp(ac, &che->ch[1]); + ac->update_ltp(ac, &che->ch[1]); } if (ac->oc[1].m4ac.sbr > 0) { ff_sbr_apply(ac, &che->sbr, type, che->ch[0].ret, che->ch[1].ret); @@ -2483,6 +2486,8 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, int samples = 0, multiplier, audio_found = 0, pce_found = 0; int is_dmono, sce_count = 0; + ac->frame = data; + if (show_bits(gb, 12) == 0xfff) { if (parse_adts_frame_header(ac, gb) < 0) { av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\n"); @@ -2554,7 +2559,6 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, if (pce_found) { av_log(avctx, AV_LOG_ERROR, "Not evaluating a further program_config_element as this construct is dubious at best.\n"); - pop_output_configuration(ac); } else { err = output_configure(ac, layout_map, tags, OC_TRIAL_PCE, 1); if (!err) @@ -2603,10 +2607,8 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, is_dmono = ac->dmono_mode && sce_count == 2 && ac->oc[1].channel_layout == (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT); - if (samples) { - ac->frame.nb_samples = samples; - *(AVFrame *)data = ac->frame; - } + if (samples) + ac->frame->nb_samples = samples; *got_frame_ptr = !!samples; if (is_dmono) { @@ -2624,7 +2626,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, if (multiplier) { int side_size; - uint32_t *side = av_packet_get_side_data(avpkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size); + const uint8_t *side = av_packet_get_side_data(avpkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size); if (side && side_size>=4) AV_WL32(side, 2*AV_RL32(side)); } @@ -2676,6 +2678,9 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data, if (ac->force_dmono_mode >= 0) ac->dmono_mode = ac->force_dmono_mode; + if (INT_MAX / 8 <= buf_size) + return AVERROR_INVALIDDATA; + init_get_bits(&gb, buf, buf_size * 8); if ((err = aac_decode_frame_int(avctx, data, got_frame_ptr, &gb, avpkt)) < 0) @@ -2765,7 +2770,7 @@ static int latm_decode_audio_specific_config(struct LATMContext *latmctx, if(latmctx->initialized) { av_log(avctx, AV_LOG_INFO, "audio config changed\n"); } else { - av_log(avctx, AV_LOG_INFO, "initializing latmctx\n"); + av_log(avctx, AV_LOG_DEBUG, "initializing latmctx\n"); } latmctx->initialized = 0; @@ -2926,7 +2931,8 @@ static int latm_decode_frame(AVCodecContext *avctx, void *out, int muxlength, err; GetBitContext gb; - init_get_bits(&gb, avpkt->data, avpkt->size * 8); + if ((err = init_get_bits8(&gb, avpkt->data, avpkt->size)) < 0) + return err; // check for LOAS sync word if (get_bits(&gb, 11) != LOAS_SYNC_WORD) @@ -2980,6 +2986,17 @@ static av_cold int latm_decode_init(AVCodecContext *avctx) return ret; } +static void aacdec_init(AACContext *c) +{ + c->imdct_and_windowing = imdct_and_windowing; + c->apply_ltp = apply_ltp; + c->apply_tns = apply_tns; + c->windowing_and_mdct_ltp = windowing_and_mdct_ltp; + c->update_ltp = update_ltp; + + if(ARCH_MIPS) + ff_aacdec_init_mips(c); +} /** * AVOptions for Japanese DTV specific extensions (ADTS only) */ diff --git a/mythtv/external/FFmpeg/libavcodec/aacenc.c b/mythtv/external/FFmpeg/libavcodec/aacenc.c index 348d3a20d21..420d0ced26b 100644 --- a/mythtv/external/FFmpeg/libavcodec/aacenc.c +++ b/mythtv/external/FFmpeg/libavcodec/aacenc.c @@ -34,7 +34,6 @@ #include "libavutil/opt.h" #include "avcodec.h" #include "put_bits.h" -#include "dsputil.h" #include "internal.h" #include "mpeg4audio.h" #include "kbdwin.h" @@ -183,7 +182,7 @@ static void put_audio_specific_config(AVCodecContext *avctx) } #define WINDOW_FUNC(type) \ -static void apply_ ##type ##_window(DSPContext *dsp, AVFloatDSPContext *fdsp, \ +static void apply_ ##type ##_window(AVFloatDSPContext *fdsp, \ SingleChannelElement *sce, \ const float *audio) @@ -193,8 +192,8 @@ WINDOW_FUNC(only_long) const float *pwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024; float *out = sce->ret_buf; - fdsp->vector_fmul (out, audio, lwindow, 1024); - dsp->vector_fmul_reverse(out + 1024, audio + 1024, pwindow, 1024); + fdsp->vector_fmul (out, audio, lwindow, 1024); + fdsp->vector_fmul_reverse(out + 1024, audio + 1024, pwindow, 1024); } WINDOW_FUNC(long_start) @@ -205,7 +204,7 @@ WINDOW_FUNC(long_start) fdsp->vector_fmul(out, audio, lwindow, 1024); memcpy(out + 1024, audio + 1024, sizeof(out[0]) * 448); - dsp->vector_fmul_reverse(out + 1024 + 448, audio + 1024 + 448, swindow, 128); + fdsp->vector_fmul_reverse(out + 1024 + 448, audio + 1024 + 448, swindow, 128); memset(out + 1024 + 576, 0, sizeof(out[0]) * 448); } @@ -218,7 +217,7 @@ WINDOW_FUNC(long_stop) memset(out, 0, sizeof(out[0]) * 448); fdsp->vector_fmul(out + 448, audio + 448, swindow, 128); memcpy(out + 576, audio + 576, sizeof(out[0]) * 448); - dsp->vector_fmul_reverse(out + 1024, audio + 1024, lwindow, 1024); + fdsp->vector_fmul_reverse(out + 1024, audio + 1024, lwindow, 1024); } WINDOW_FUNC(eight_short) @@ -230,15 +229,15 @@ WINDOW_FUNC(eight_short) int w; for (w = 0; w < 8; w++) { - fdsp->vector_fmul (out, in, w ? pwindow : swindow, 128); + fdsp->vector_fmul (out, in, w ? pwindow : swindow, 128); out += 128; in += 128; - dsp->vector_fmul_reverse(out, in, swindow, 128); + fdsp->vector_fmul_reverse(out, in, swindow, 128); out += 128; } } -static void (*const apply_window[4])(DSPContext *dsp, AVFloatDSPContext *fdsp, +static void (*const apply_window[4])(AVFloatDSPContext *fdsp, SingleChannelElement *sce, const float *audio) = { [ONLY_LONG_SEQUENCE] = apply_only_long_window, @@ -253,7 +252,7 @@ static void apply_window_and_mdct(AACEncContext *s, SingleChannelElement *sce, int i; float *output = sce->ret_buf; - apply_window[sce->ics.window_sequence[0]](&s->dsp, &s->fdsp, sce, audio); + apply_window[sce->ics.window_sequence[0]](&s->fdsp, sce, audio); if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) s->mdct1024.mdct_calc(&s->mdct1024, sce->coeffs, output); @@ -571,10 +570,8 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } start_ch += chans; } - if ((ret = ff_alloc_packet2(avctx, avpkt, 8192 * s->channels))) { - av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); + if ((ret = ff_alloc_packet2(avctx, avpkt, 8192 * s->channels)) < 0) return ret; - } do { int frame_bits; @@ -692,7 +689,6 @@ static av_cold int dsp_init(AVCodecContext *avctx, AACEncContext *s) { int ret = 0; - ff_dsputil_init(&s->dsp, avctx); avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); // window init diff --git a/mythtv/external/FFmpeg/libavcodec/aacenc.h b/mythtv/external/FFmpeg/libavcodec/aacenc.h index fbc3da8879c..386c72f582e 100644 --- a/mythtv/external/FFmpeg/libavcodec/aacenc.h +++ b/mythtv/external/FFmpeg/libavcodec/aacenc.h @@ -25,7 +25,6 @@ #include "libavutil/float_dsp.h" #include "avcodec.h" #include "put_bits.h" -#include "dsputil.h" #include "aac.h" #include "audio_frame_queue.h" @@ -61,7 +60,6 @@ typedef struct AACEncContext { PutBitContext pb; FFTContext mdct1024; ///< long (1024 samples) frame transform context FFTContext mdct128; ///< short (128 samples) frame transform context - DSPContext dsp; AVFloatDSPContext fdsp; float *planar_samples[6]; ///< saved preprocessed input diff --git a/mythtv/external/FFmpeg/libavcodec/aacps.c b/mythtv/external/FFmpeg/libavcodec/aacps.c index 25ed1d0292c..b82001e9675 100644 --- a/mythtv/external/FFmpeg/libavcodec/aacps.c +++ b/mythtv/external/FFmpeg/libavcodec/aacps.c @@ -21,13 +21,13 @@ #include #include "libavutil/common.h" +#include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "avcodec.h" #include "get_bits.h" #include "aacps.h" #include "aacps_tablegen.h" #include "aacpsdata.c" -#include "dsputil.h" #define PS_BASELINE 0 ///< Operate in Baseline PS mode ///< Baseline implies 10 or 20 stereo bands, diff --git a/mythtv/external/FFmpeg/libavcodec/aacpsdsp.c b/mythtv/external/FFmpeg/libavcodec/aacpsdsp.c index e90c50b6a1c..9526d3a4cb6 100644 --- a/mythtv/external/FFmpeg/libavcodec/aacpsdsp.c +++ b/mythtv/external/FFmpeg/libavcodec/aacpsdsp.c @@ -211,4 +211,6 @@ av_cold void ff_psdsp_init(PSDSPContext *s) if (ARCH_ARM) ff_psdsp_init_arm(s); + if (ARCH_MIPS) + ff_psdsp_init_mips(s); } diff --git a/mythtv/external/FFmpeg/libavcodec/aacpsdsp.h b/mythtv/external/FFmpeg/libavcodec/aacpsdsp.h index 93737d26d3a..df01e0bf048 100644 --- a/mythtv/external/FFmpeg/libavcodec/aacpsdsp.h +++ b/mythtv/external/FFmpeg/libavcodec/aacpsdsp.h @@ -49,5 +49,6 @@ typedef struct PSDSPContext { void ff_psdsp_init(PSDSPContext *s); void ff_psdsp_init_arm(PSDSPContext *s); +void ff_psdsp_init_mips(PSDSPContext *s); #endif /* LIBAVCODEC_AACPSDSP_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/aacpsy.c b/mythtv/external/FFmpeg/libavcodec/aacpsy.c index d77b3de4e48..e399be545dd 100644 --- a/mythtv/external/FFmpeg/libavcodec/aacpsy.c +++ b/mythtv/external/FFmpeg/libavcodec/aacpsy.c @@ -541,8 +541,10 @@ static float calc_reduced_thr_3gpp(AacPsyBand *band, float min_snr, float thr = band->thr; if (band->energy > thr) { - thr = powf(thr, 0.25f) + reduction; - thr = powf(thr, 4.0f); + thr = sqrtf(thr); + thr = sqrtf(thr) + reduction; + thr *= thr; + thr *= thr; /* This deviates from the 3GPP spec to match the reference encoder. * It performs min(thr_reduced, max(thr, energy/min_snr)) only for bands @@ -582,13 +584,15 @@ static void psy_3gpp_analyze_channel(FFPsyContext *ctx, int channel, AacPsyBand *band = &pch->band[w+g]; float form_factor = 0.0f; + float Temp; band->energy = 0.0f; for (i = 0; i < band_sizes[g]; i++) { band->energy += coefs[start+i] * coefs[start+i]; form_factor += sqrtf(fabs(coefs[start+i])); } + Temp = band->energy > 0 ? sqrtf((float)band_sizes[g] / band->energy) : 0; band->thr = band->energy * 0.001258925f; - band->nz_lines = band->energy>0 ? form_factor / powf(band->energy / band_sizes[g], 0.25f) : 0; + band->nz_lines = form_factor * sqrtf(Temp); start += band_sizes[g]; } diff --git a/mythtv/external/FFmpeg/libavcodec/aacsbr.c b/mythtv/external/FFmpeg/libavcodec/aacsbr.c index a49631b9b53..8cdf819e23b 100644 --- a/mythtv/external/FFmpeg/libavcodec/aacsbr.c +++ b/mythtv/external/FFmpeg/libavcodec/aacsbr.c @@ -33,6 +33,7 @@ #include "fft.h" #include "aacps.h" #include "sbrdsp.h" +#include "libavutil/internal.h" #include "libavutil/libm.h" #include "libavutil/avassert.h" @@ -43,6 +44,10 @@ #define ENVELOPE_ADJUSTMENT_OFFSET 2 #define NOISE_FLOOR_OFFSET 6.0f +#if ARCH_MIPS +#include "mips/aacsbr_mips.h" +#endif /* ARCH_MIPS */ + /** * SBR VLC tables */ @@ -86,6 +91,8 @@ static const int8_t vlc_sbr_lav[10] = #define SBR_VLC_ROW(name) \ { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) } +static void aacsbr_func_ptr_init(AACSBRContext *c); + av_cold void ff_aac_sbr_init(void) { int n; @@ -154,6 +161,7 @@ av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr) ff_mdct_init(&sbr->mdct_ana, 7, 1, -2.0 * 32768.0); ff_ps_ctx_init(&sbr->ps); ff_sbrdsp_init(&sbr->dsp); + aacsbr_func_ptr_init(&sbr->c); } av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr) @@ -391,6 +399,8 @@ static int sbr_make_f_master(AACContext *ac, SpectralBandReplication *sbr, max_qmf_subbands = 35; } else if (sbr->sample_rate >= 48000) max_qmf_subbands = 32; + else + av_assert0(0); if (sbr->k[2] - sbr->k[0] > max_qmf_subbands) { av_log(ac->avctx, AV_LOG_ERROR, @@ -1172,7 +1182,8 @@ static void sbr_dequant(SpectralBandReplication *sbr, int id_aac) * @param x pointer to the beginning of the first sample window * @param W array of complex-valued samples split into subbands */ -static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, +#ifndef sbr_qmf_analysis +static void sbr_qmf_analysis(AVFloatDSPContext *dsp, FFTContext *mdct, SBRDSPContext *sbrdsp, const float *in, float *x, float z[320], float W[2][32][32][2], int buf_idx) { @@ -1189,13 +1200,15 @@ static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, x += 32; } } +#endif /** * Synthesis QMF Bank (14496-3 sp04 p206) and Downsampled Synthesis QMF Bank * (14496-3 sp04 p206) */ -static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, - SBRDSPContext *sbrdsp, AVFloatDSPContext *fdsp, +#ifndef sbr_qmf_synthesis +static void sbr_qmf_synthesis(FFTContext *mdct, + SBRDSPContext *sbrdsp, AVFloatDSPContext *dsp, float *out, float X[2][38][64], float mdct_buf[2][64], float *v0, int *v_off, const unsigned int div) @@ -1226,7 +1239,7 @@ static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, mdct->imdct_half(mdct, mdct_buf[1], X[1][i]); sbrdsp->qmf_deint_bfly(v, mdct_buf[1], mdct_buf[0]); } - fdsp->vector_fmul (out, v , sbr_qmf_window , 64 >> div); + dsp->vector_fmul (out, v , sbr_qmf_window , 64 >> div); dsp->vector_fmul_add(out, v + ( 192 >> div), sbr_qmf_window + ( 64 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 256 >> div), sbr_qmf_window + (128 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 448 >> div), sbr_qmf_window + (192 >> div), out , 64 >> div); @@ -1239,6 +1252,7 @@ static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, out += 64 >> div; } } +#endif /** High Frequency Generation (14496-3 sp04 p214+) and Inverse Filtering * (14496-3 sp04 p214) @@ -1684,13 +1698,13 @@ void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, } for (ch = 0; ch < nch; ch++) { /* decode channel */ - sbr_qmf_analysis(&ac->dsp, &sbr->mdct_ana, &sbr->dsp, ch ? R : L, sbr->data[ch].analysis_filterbank_samples, + sbr_qmf_analysis(&ac->fdsp, &sbr->mdct_ana, &sbr->dsp, ch ? R : L, sbr->data[ch].analysis_filterbank_samples, (float*)sbr->qmf_filter_scratch, sbr->data[ch].W, sbr->data[ch].Ypos); - sbr_lf_gen(ac, sbr, sbr->X_low, sbr->data[ch].W, sbr->data[ch].Ypos); + sbr->c.sbr_lf_gen(ac, sbr, sbr->X_low, sbr->data[ch].W, sbr->data[ch].Ypos); sbr->data[ch].Ypos ^= 1; if (sbr->start) { - sbr_hf_inverse_filter(&sbr->dsp, sbr->alpha0, sbr->alpha1, sbr->X_low, sbr->k[0]); + sbr->c.sbr_hf_inverse_filter(&sbr->dsp, sbr->alpha0, sbr->alpha1, sbr->X_low, sbr->k[0]); sbr_chirp(sbr, &sbr->data[ch]); sbr_hf_gen(ac, sbr, sbr->X_high, sbr->X_low, sbr->alpha0, sbr->alpha1, sbr->data[ch].bw_array, sbr->data[ch].t_env, @@ -1701,14 +1715,14 @@ void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, if (!err) { sbr_env_estimate(sbr->e_curr, sbr->X_high, sbr, &sbr->data[ch]); sbr_gain_calc(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a); - sbr_hf_assemble(sbr->data[ch].Y[sbr->data[ch].Ypos], + sbr->c.sbr_hf_assemble(sbr->data[ch].Y[sbr->data[ch].Ypos], sbr->X_high, sbr, &sbr->data[ch], sbr->data[ch].e_a); } } /* synthesis */ - sbr_x_gen(sbr, sbr->X[ch], + sbr->c.sbr_x_gen(sbr, sbr->X[ch], sbr->data[ch].Y[1-sbr->data[ch].Ypos], sbr->data[ch].Y[ sbr->data[ch].Ypos], sbr->X_low, ch); @@ -1723,15 +1737,26 @@ void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, nch = 2; } - sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, &sbr->dsp, &ac->fdsp, + sbr_qmf_synthesis(&sbr->mdct, &sbr->dsp, &ac->fdsp, L, sbr->X[0], sbr->qmf_filter_scratch, sbr->data[0].synthesis_filterbank_samples, &sbr->data[0].synthesis_filterbank_samples_offset, downsampled); if (nch == 2) - sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, &sbr->dsp, &ac->fdsp, + sbr_qmf_synthesis(&sbr->mdct, &sbr->dsp, &ac->fdsp, R, sbr->X[1], sbr->qmf_filter_scratch, sbr->data[1].synthesis_filterbank_samples, &sbr->data[1].synthesis_filterbank_samples_offset, downsampled); } + +static void aacsbr_func_ptr_init(AACSBRContext *c) +{ + c->sbr_lf_gen = sbr_lf_gen; + c->sbr_hf_assemble = sbr_hf_assemble; + c->sbr_x_gen = sbr_x_gen; + c->sbr_hf_inverse_filter = sbr_hf_inverse_filter; + + if(ARCH_MIPS) + ff_aacsbr_func_ptr_init_mips(c); +} diff --git a/mythtv/external/FFmpeg/libavcodec/aacsbr.h b/mythtv/external/FFmpeg/libavcodec/aacsbr.h index d0284981c3e..f5e33ab6882 100644 --- a/mythtv/external/FFmpeg/libavcodec/aacsbr.h +++ b/mythtv/external/FFmpeg/libavcodec/aacsbr.h @@ -34,11 +34,11 @@ #include "sbr.h" /** Initialize SBR. */ -av_cold void ff_aac_sbr_init(void); +void ff_aac_sbr_init(void); /** Initialize one SBR context. */ -av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr); +void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr); /** Close one SBR context. */ -av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr); +void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr); /** Decode one SBR element. */ int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, int crc, int cnt, int id_aac); @@ -46,4 +46,6 @@ int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, float* L, float *R); +void ff_aacsbr_func_ptr_init_mips(AACSBRContext *c); + #endif /* AVCODEC_AACSBR_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/aasc.c b/mythtv/external/FFmpeg/libavcodec/aasc.c index 245951ab16c..308edd06477 100644 --- a/mythtv/external/FFmpeg/libavcodec/aasc.c +++ b/mythtv/external/FFmpeg/libavcodec/aasc.c @@ -29,7 +29,6 @@ #include #include "avcodec.h" -#include "dsputil.h" #include "msrledec.h" typedef struct AascContext { @@ -81,7 +80,7 @@ static int aasc_decode_frame(AVCodecContext *avctx, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AascContext *s = avctx->priv_data; - int compr, i, stride, psize; + int compr, i, stride, psize, ret; if (buf_size < 4) { av_log(avctx, AV_LOG_ERROR, "frame too short\n"); @@ -90,9 +89,9 @@ static int aasc_decode_frame(AVCodecContext *avctx, s->frame.reference = 3; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; - if (avctx->reget_buffer(avctx, &s->frame)) { + if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } compr = AV_RL32(buf); @@ -124,7 +123,7 @@ static int aasc_decode_frame(AVCodecContext *avctx, break; default: av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr); - return -1; + return AVERROR_INVALIDDATA; } break; default: diff --git a/mythtv/external/FFmpeg/libavcodec/ac3dec.c b/mythtv/external/FFmpeg/libavcodec/ac3dec.c index b98ffa98899..51ef187cdb4 100644 --- a/mythtv/external/FFmpeg/libavcodec/ac3dec.c +++ b/mythtv/external/FFmpeg/libavcodec/ac3dec.c @@ -170,6 +170,7 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) ff_mdct_init(&s->imdct_512, 9, 1, 1.0); ff_kbd_window_init(s->window, 5.0, 256); ff_dsputil_init(&s->dsp, avctx); + avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT); ff_fmt_convert_init(&s->fmt_conv, avctx); av_lfg_init(&s->dith_state, 0); @@ -184,9 +185,6 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) } s->downmixed = 1; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - for (i = 0; i < AC3_MAX_CHANNELS; i++) { s->xcfptr[i] = s->transform_coeffs[i]; s->dlyptr[i] = s->delay[i]; @@ -441,8 +439,9 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma int mantissa; switch (bap) { case 0: + /* random noise with approximate range of -0.707 to 0.707 */ if (dither) - mantissa = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; + mantissa = (((av_lfg_get(&s->dith_state)>>8)*181)>>8) - 5931008; else mantissa = 0; break; @@ -606,15 +605,15 @@ static inline void do_imdct(AC3DecodeContext *s, int channels) for (i = 0; i < 128; i++) x[i] = s->transform_coeffs[ch][2 * i]; s->imdct_256.imdct_half(&s->imdct_256, s->tmp_output, x); - s->dsp.vector_fmul_window(s->outptr[ch - 1], s->delay[ch - 1], - s->tmp_output, s->window, 128); + s->fdsp.vector_fmul_window(s->outptr[ch - 1], s->delay[ch - 1], + s->tmp_output, s->window, 128); for (i = 0; i < 128; i++) x[i] = s->transform_coeffs[ch][2 * i + 1]; s->imdct_256.imdct_half(&s->imdct_256, s->delay[ch - 1], x); } else { s->imdct_512.imdct_half(&s->imdct_512, s->tmp_output, s->transform_coeffs[ch]); - s->dsp.vector_fmul_window(s->outptr[ch - 1], s->delay[ch - 1], - s->tmp_output, s->window, 128); + s->fdsp.vector_fmul_window(s->outptr[ch - 1], s->delay[ch - 1], + s->tmp_output, s->window, 128); memcpy(s->delay[ch - 1], s->tmp_output + 128, 128 * sizeof(float)); } } @@ -1265,6 +1264,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AC3DecodeContext *s = avctx->priv_data; @@ -1374,8 +1374,8 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, avctx->audio_service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE; /* get output buffer */ - s->frame.nb_samples = s->num_blocks * 256; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = s->num_blocks * 256; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -1388,7 +1388,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, } for (ch = 0; ch < s->channels; ch++) { if (ch < s->out_channels) - s->outptr[channel_map[ch]] = (float *)s->frame.data[ch]; + s->outptr[channel_map[ch]] = (float *)frame->data[ch]; } for (blk = 0; blk < s->num_blocks; blk++) { if (!err && decode_audio_block(s, blk)) { @@ -1397,7 +1397,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, } if (err) for (ch = 0; ch < s->out_channels; ch++) - memcpy(((float*)s->frame.data[ch]) + AC3_BLOCK_SIZE*blk, output[ch], 1024); + memcpy(((float*)frame->data[ch]) + AC3_BLOCK_SIZE*blk, output[ch], 1024); for (ch = 0; ch < s->out_channels; ch++) output[ch] = s->outptr[channel_map[ch]]; for (ch = 0; ch < s->out_channels; ch++) { @@ -1406,14 +1406,13 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, } } - s->frame.decode_error_flags = err ? FF_DECODE_ERROR_INVALID_BITSTREAM : 0; + av_frame_set_decode_error_flags(frame, err ? FF_DECODE_ERROR_INVALID_BITSTREAM : 0); /* keep last block for error concealment in next frame */ for (ch = 0; ch < s->out_channels; ch++) memcpy(s->output[ch], output[ch], 1024); - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return FFMIN(buf_size, s->frame_size); } diff --git a/mythtv/external/FFmpeg/libavcodec/ac3dec.h b/mythtv/external/FFmpeg/libavcodec/ac3dec.h index 18640dd6d91..6c99ef6e6aa 100644 --- a/mythtv/external/FFmpeg/libavcodec/ac3dec.h +++ b/mythtv/external/FFmpeg/libavcodec/ac3dec.h @@ -50,6 +50,7 @@ #ifndef AVCODEC_AC3DEC_H #define AVCODEC_AC3DEC_H +#include "libavutil/float_dsp.h" #include "libavutil/lfg.h" #include "ac3.h" #include "ac3dsp.h" @@ -68,7 +69,6 @@ typedef struct AC3DecodeContext { AVClass *class; ///< class for AVOptions AVCodecContext *avctx; ///< parent context - AVFrame frame; ///< AVFrame for decoded output GetBitContext gbc; ///< bitstream reader ///@name Bit stream information @@ -199,6 +199,7 @@ typedef struct AC3DecodeContext { ///@name Optimization DSPContext dsp; ///< for optimization + AVFloatDSPContext fdsp; AC3DSPContext ac3dsp; FmtConvertContext fmt_conv; ///< optimized conversion functions ///@} diff --git a/mythtv/external/FFmpeg/libavcodec/ac3enc.c b/mythtv/external/FFmpeg/libavcodec/ac3enc.c index de8defceb83..16f0cdc4de8 100644 --- a/mythtv/external/FFmpeg/libavcodec/ac3enc.c +++ b/mythtv/external/FFmpeg/libavcodec/ac3enc.c @@ -34,10 +34,10 @@ #include "libavutil/avstring.h" #include "libavutil/channel_layout.h" #include "libavutil/crc.h" +#include "libavutil/internal.h" #include "libavutil/opt.h" #include "avcodec.h" #include "put_bits.h" -#include "dsputil.h" #include "ac3dsp.h" #include "ac3.h" #include "fft.h" diff --git a/mythtv/external/FFmpeg/libavcodec/ac3enc_template.c b/mythtv/external/FFmpeg/libavcodec/ac3enc_template.c index 904e0bb9ef8..0389c2ef4a7 100644 --- a/mythtv/external/FFmpeg/libavcodec/ac3enc_template.c +++ b/mythtv/external/FFmpeg/libavcodec/ac3enc_template.c @@ -28,6 +28,7 @@ #include +#include "libavutil/internal.h" /* prototypes for static functions in ac3enc_fixed.c and ac3enc_float.c */ @@ -132,7 +133,7 @@ static void apply_channel_coupling(AC3EncodeContext *s) #else int32_t (*fixed_cpl_coords)[AC3_MAX_CHANNELS][16] = cpl_coords; #endif - int blk, ch, bnd, i, j; + int av_uninit(blk), ch, bnd, i, j; CoefSumType energy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}}; int cpl_start, num_cpl_coefs; @@ -336,7 +337,7 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s) { int nb_coefs; int blk, bnd; - AC3Block *block, *block0; + AC3Block *block, *block0 = NULL; if (s->channel_mode != AC3_CHMODE_STEREO) return; @@ -434,7 +435,7 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, AVPacket *avpkt, ff_ac3_quantize_mantissas(s); - if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size))) + if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size)) < 0) return ret; ff_ac3_output_frame(s, avpkt->data); diff --git a/mythtv/external/FFmpeg/libavcodec/acelp_pitch_delay.c b/mythtv/external/FFmpeg/libavcodec/acelp_pitch_delay.c index 95bcce7a4ac..c005c4b4e88 100644 --- a/mythtv/external/FFmpeg/libavcodec/acelp_pitch_delay.c +++ b/mythtv/external/FFmpeg/libavcodec/acelp_pitch_delay.c @@ -21,10 +21,10 @@ */ #include "libavutil/common.h" +#include "libavutil/float_dsp.h" #include "libavutil/libm.h" #include "libavutil/mathematics.h" #include "avcodec.h" -#include "dsputil.h" #include "acelp_pitch_delay.h" #include "celp_math.h" @@ -132,7 +132,7 @@ float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy, // Note 10^(0.05 * -10log(average x2)) = 1/sqrt((average x2)). float val = fixed_gain_factor * exp2f(M_LOG2_10 * 0.05 * - (ff_scalarproduct_float_c(pred_table, prediction_error, 4) + + (avpriv_scalarproduct_float_c(pred_table, prediction_error, 4) + energy_mean)) / sqrtf(fixed_mean_energy); diff --git a/mythtv/external/FFmpeg/libavcodec/acelp_vectors.c b/mythtv/external/FFmpeg/libavcodec/acelp_vectors.c index aadacb42836..c9d6f877f6d 100644 --- a/mythtv/external/FFmpeg/libavcodec/acelp_vectors.c +++ b/mythtv/external/FFmpeg/libavcodec/acelp_vectors.c @@ -23,8 +23,8 @@ #include #include "libavutil/common.h" +#include "libavutil/float_dsp.h" #include "avcodec.h" -#include "dsputil.h" #include "acelp_vectors.h" const uint8_t ff_fc_2pulses_9bits_track1[16] = @@ -203,7 +203,7 @@ void ff_adaptive_gain_control(float *out, const float *in, float speech_energ, int size, float alpha, float *gain_mem) { int i; - float postfilter_energ = ff_scalarproduct_float_c(in, in, size); + float postfilter_energ = avpriv_scalarproduct_float_c(in, in, size); float gain_scale_factor = 1.0; float mem = *gain_mem; @@ -224,7 +224,7 @@ void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in, float sum_of_squares, const int n) { int i; - float scalefactor = ff_scalarproduct_float_c(in, in, n); + float scalefactor = avpriv_scalarproduct_float_c(in, in, n); if (scalefactor) scalefactor = sqrt(sum_of_squares / scalefactor); for (i = 0; i < n; i++) diff --git a/mythtv/external/FFmpeg/libavcodec/adpcm.c b/mythtv/external/FFmpeg/libavcodec/adpcm.c index cd682572569..02de22cee73 100644 --- a/mythtv/external/FFmpeg/libavcodec/adpcm.c +++ b/mythtv/external/FFmpeg/libavcodec/adpcm.c @@ -85,7 +85,6 @@ static const int swf_index_tables[4][16] = { /* end of tables */ typedef struct ADPCMDecodeContext { - AVFrame frame; ADPCMChannelStatus status[6]; int vqa_version; /**< VQA version. Used for ADPCM_IMA_WS */ } ADPCMDecodeContext; @@ -159,9 +158,6 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) avctx->sample_fmt = AV_SAMPLE_FMT_S16; } - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - return 0; } @@ -619,6 +615,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, static int adpcm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; ADPCMDecodeContext *c = avctx->priv_data; @@ -639,20 +636,20 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - c->frame.nb_samples = nb_samples; - if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = nb_samples; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (short *)c->frame.data[0]; - samples_p = (int16_t **)c->frame.extended_data; + samples = (short *)frame->data[0]; + samples_p = (int16_t **)frame->extended_data; /* use coded_samples when applicable */ /* it is always <= nb_samples, so the output buffer will be large enough */ if (coded_samples) { if (coded_samples != nb_samples) av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n"); - c->frame.nb_samples = nb_samples = coded_samples; + frame->nb_samples = nb_samples = coded_samples; } st = avctx->channels == 2 ? 1 : 0; @@ -738,7 +735,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } for (i = 0; i < avctx->channels; i++) { - samples = (int16_t *)c->frame.data[i]; + samples = (int16_t *)frame->data[i]; cs = &c->status[i]; for (n = nb_samples >> 1; n > 0; n--) { int v = bytestream2_get_byteu(&gb); @@ -1135,7 +1132,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } } - c->frame.nb_samples = count * 28; + frame->nb_samples = count * 28; bytestream2_seek(&gb, 0, SEEK_END); break; } @@ -1378,8 +1375,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, return AVERROR_INVALIDDATA; } - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return bytestream2_tell(&gb); } diff --git a/mythtv/external/FFmpeg/libavcodec/adpcmenc.c b/mythtv/external/FFmpeg/libavcodec/adpcmenc.c index 217d165f30c..59f016bdb14 100644 --- a/mythtv/external/FFmpeg/libavcodec/adpcmenc.c +++ b/mythtv/external/FFmpeg/libavcodec/adpcmenc.c @@ -19,7 +19,6 @@ */ #include "avcodec.h" -#include "get_bits.h" #include "put_bits.h" #include "bytestream.h" #include "adpcm.h" @@ -495,7 +494,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, pkt_size = (2 + avctx->channels * (22 + 4 * (frame->nb_samples - 1)) + 7) / 8; else pkt_size = avctx->block_align; - if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size))) + if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size)) < 0) return ret; dst = avpkt->data; diff --git a/mythtv/external/FFmpeg/libavcodec/adx.h b/mythtv/external/FFmpeg/libavcodec/adx.h index 85b35d15be1..b28d09a32ea 100644 --- a/mythtv/external/FFmpeg/libavcodec/adx.h +++ b/mythtv/external/FFmpeg/libavcodec/adx.h @@ -40,7 +40,6 @@ typedef struct ADXChannelState { } ADXChannelState; typedef struct ADXContext { - AVFrame frame; int channels; ADXChannelState prev[2]; int header_parsed; diff --git a/mythtv/external/FFmpeg/libavcodec/adxdec.c b/mythtv/external/FFmpeg/libavcodec/adxdec.c index 0130628af7a..aebf6910c9e 100644 --- a/mythtv/external/FFmpeg/libavcodec/adxdec.c +++ b/mythtv/external/FFmpeg/libavcodec/adxdec.c @@ -52,9 +52,6 @@ static av_cold int adx_decode_init(AVCodecContext *avctx) avctx->sample_fmt = AV_SAMPLE_FMT_S16P; - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - return 0; } @@ -98,6 +95,7 @@ static int adx_decode(ADXContext *c, int16_t *out, int offset, static int adx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; int buf_size = avpkt->size; ADXContext *c = avctx->priv_data; int16_t **samples; @@ -143,12 +141,12 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - c->frame.nb_samples = num_blocks * BLOCK_SAMPLES; - if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = num_blocks * BLOCK_SAMPLES; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (int16_t **)c->frame.extended_data; + samples = (int16_t **)frame->extended_data; samples_offset = 0; while (num_blocks--) { @@ -164,8 +162,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data, samples_offset += BLOCK_SAMPLES; } - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return buf - avpkt->data; } diff --git a/mythtv/external/FFmpeg/libavcodec/adxenc.c b/mythtv/external/FFmpeg/libavcodec/adxenc.c index 8514a0c9b15..fb8e06deb3d 100644 --- a/mythtv/external/FFmpeg/libavcodec/adxenc.c +++ b/mythtv/external/FFmpeg/libavcodec/adxenc.c @@ -107,6 +107,14 @@ static int adx_encode_header(AVCodecContext *avctx, uint8_t *buf, int bufsize) return HEADER_SIZE; } +#if FF_API_OLD_ENCODE_AUDIO +static av_cold int adx_encode_close(AVCodecContext *avctx) +{ + av_freep(&avctx->coded_frame); + return 0; +} +#endif + static av_cold int adx_encode_init(AVCodecContext *avctx) { ADXContext *c = avctx->priv_data; @@ -118,8 +126,8 @@ static av_cold int adx_encode_init(AVCodecContext *avctx) avctx->frame_size = BLOCK_SAMPLES; #if FF_API_OLD_ENCODE_AUDIO - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; + if (!(avctx->coded_frame = avcodec_alloc_frame())) + return AVERROR(ENOMEM); #endif /* the cutoff can be adjusted, but this seems to work pretty well */ @@ -167,6 +175,9 @@ AVCodec ff_adpcm_adx_encoder = { .id = AV_CODEC_ID_ADPCM_ADX, .priv_data_size = sizeof(ADXContext), .init = adx_encode_init, +#if FF_API_OLD_ENCODE_AUDIO + .close = adx_encode_close, +#endif .encode2 = adx_encode_frame, .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, diff --git a/mythtv/external/FFmpeg/libavcodec/alac.c b/mythtv/external/FFmpeg/libavcodec/alac.c index 180ef53105d..f8ac560cb8d 100644 --- a/mythtv/external/FFmpeg/libavcodec/alac.c +++ b/mythtv/external/FFmpeg/libavcodec/alac.c @@ -58,7 +58,6 @@ typedef struct { AVCodecContext *avctx; - AVFrame frame; GetBitContext gb; int channels; @@ -254,7 +253,7 @@ static void append_extra_bits(int32_t *buffer[2], int32_t *extra_bits_buffer[2], buffer[ch][i] = (buffer[ch][i] << extra_bits) | extra_bits_buffer[ch][i]; } -static int decode_element(AVCodecContext *avctx, void *data, int ch_index, +static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index, int channels) { ALACContext *alac = avctx->priv_data; @@ -289,8 +288,8 @@ static int decode_element(AVCodecContext *avctx, void *data, int ch_index, } if (!alac->nb_samples) { /* get output buffer */ - alac->frame.nb_samples = output_samples; - if ((ret = ff_get_buffer(avctx, &alac->frame)) < 0) { + frame->nb_samples = output_samples; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -302,7 +301,7 @@ static int decode_element(AVCodecContext *avctx, void *data, int ch_index, alac->nb_samples = output_samples; if (alac->direct_output) { for (ch = 0; ch < channels; ch++) - alac->output_samples_buffer[ch] = (int32_t *)alac->frame.extended_data[ch_index + ch]; + alac->output_samples_buffer[ch] = (int32_t *)frame->extended_data[ch_index + ch]; } if (is_compressed) { @@ -390,7 +389,7 @@ static int decode_element(AVCodecContext *avctx, void *data, int ch_index, switch(alac->sample_size) { case 16: { for (ch = 0; ch < channels; ch++) { - int16_t *outbuffer = (int16_t *)alac->frame.extended_data[ch_index + ch]; + int16_t *outbuffer = (int16_t *)frame->extended_data[ch_index + ch]; for (i = 0; i < alac->nb_samples; i++) *outbuffer++ = alac->output_samples_buffer[ch][i]; }} @@ -405,7 +404,7 @@ static int decode_element(AVCodecContext *avctx, void *data, int ch_index, }else{ switch(alac->sample_size) { case 16: { - int16_t *outbuffer = ((int16_t *)alac->frame.extended_data[0]) + ch_index; + int16_t *outbuffer = ((int16_t *)frame->extended_data[0]) + ch_index; for (i = 0; i < alac->nb_samples; i++) { for (ch = 0; ch < channels; ch++) *outbuffer++ = alac->output_samples_buffer[ch][i]; @@ -414,7 +413,7 @@ static int decode_element(AVCodecContext *avctx, void *data, int ch_index, } break; case 24: { - int32_t *outbuffer = ((int32_t *)alac->frame.extended_data[0]) + ch_index; + int32_t *outbuffer = ((int32_t *)frame->extended_data[0]) + ch_index; for (i = 0; i < alac->nb_samples; i++) { for (ch = 0; ch < channels; ch++) *outbuffer++ = alac->output_samples_buffer[ch][i] << 8; @@ -423,7 +422,7 @@ static int decode_element(AVCodecContext *avctx, void *data, int ch_index, } break; case 32: { - int32_t *outbuffer = ((int32_t *)alac->frame.extended_data[0]) + ch_index; + int32_t *outbuffer = ((int32_t *)frame->extended_data[0]) + ch_index; for (i = 0; i < alac->nb_samples; i++) { for (ch = 0; ch < channels; ch++) *outbuffer++ = alac->output_samples_buffer[ch][i]; @@ -441,6 +440,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { ALACContext *alac = avctx->priv_data; + AVFrame *frame = data; enum AlacRawDataBlockType element; int channels; int ch, ret, got_end; @@ -469,7 +469,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data, return AVERROR_INVALIDDATA; } - ret = decode_element(avctx, data, + ret = decode_element(avctx, frame, ff_alac_channel_layout_offsets[alac->channels - 1][ch], channels); if (ret < 0 && get_bits_left(&alac->gb)) @@ -487,8 +487,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data, avpkt->size * 8 - get_bits_count(&alac->gb)); } - *got_frame_ptr = 1; - *(AVFrame *)data = alac->frame; + *got_frame_ptr = 1; return avpkt->size; } @@ -616,9 +615,6 @@ static av_cold int alac_decode_init(AVCodecContext * avctx) return ret; } - avcodec_get_frame_defaults(&alac->frame); - avctx->coded_frame = &alac->frame; - return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/alacenc.c b/mythtv/external/FFmpeg/libavcodec/alacenc.c index 71e2a748224..4ee558c6732 100644 --- a/mythtv/external/FFmpeg/libavcodec/alacenc.c +++ b/mythtv/external/FFmpeg/libavcodec/alacenc.c @@ -21,7 +21,6 @@ #include "avcodec.h" #include "put_bits.h" -#include "dsputil.h" #include "internal.h" #include "lpc.h" #include "mathops.h" @@ -614,7 +613,7 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, else max_frame_size = s->max_coded_frame_size; - if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * max_frame_size))) + if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * max_frame_size)) < 0) return ret; /* use verbatim mode for compression_level 0 */ diff --git a/mythtv/external/FFmpeg/libavcodec/allcodecs.c b/mythtv/external/FFmpeg/libavcodec/allcodecs.c index 619c8e68505..584446f1363 100644 --- a/mythtv/external/FFmpeg/libavcodec/allcodecs.c +++ b/mythtv/external/FFmpeg/libavcodec/allcodecs.c @@ -74,18 +74,23 @@ void avcodec_register_all(void) /* hardware accelerators */ REGISTER_HWACCEL(H263_VAAPI, h263_vaapi); + REGISTER_HWACCEL(H263_VDPAU, h263_vdpau); REGISTER_HWACCEL(H264_DXVA2, h264_dxva2); REGISTER_HWACCEL(H264_VAAPI, h264_vaapi); REGISTER_HWACCEL(H264_VDA, h264_vda); + REGISTER_HWACCEL(H264_VDPAU, h264_vdpau); REGISTER_HWACCEL(MPEG1_VDPAU, mpeg1_vdpau); REGISTER_HWACCEL(MPEG2_DXVA2, mpeg2_dxva2); REGISTER_HWACCEL(MPEG2_VAAPI, mpeg2_vaapi); REGISTER_HWACCEL(MPEG2_VDPAU, mpeg2_vdpau); REGISTER_HWACCEL(MPEG4_VAAPI, mpeg4_vaapi); + REGISTER_HWACCEL(MPEG4_VDPAU, mpeg4_vdpau); REGISTER_HWACCEL(VC1_DXVA2, vc1_dxva2); REGISTER_HWACCEL(VC1_VAAPI, vc1_vaapi); + REGISTER_HWACCEL(VC1_VDPAU, vc1_vdpau); REGISTER_HWACCEL(WMV3_DXVA2, wmv3_dxva2); REGISTER_HWACCEL(WMV3_VAAPI, wmv3_vaapi); + REGISTER_HWACCEL(WMV3_VDPAU, wmv3_vdpau); /* video codecs */ REGISTER_ENCODER(A64MULTI, a64multi); @@ -318,6 +323,7 @@ void avcodec_register_all(void) REGISTER_ENCDEC (DCA, dca); REGISTER_DECODER(DSICINAUDIO, dsicinaudio); REGISTER_ENCDEC (EAC3, eac3); + REGISTER_DECODER(EVRC, evrc); REGISTER_DECODER(FFWAVESYNTH, ffwavesynth); REGISTER_ENCDEC (FLAC, flac); REGISTER_ENCDEC (G723_1, g723_1); @@ -483,7 +489,8 @@ void avcodec_register_all(void) REGISTER_ENCODER(LIBVO_AACENC, libvo_aacenc); REGISTER_ENCODER(LIBVO_AMRWBENC, libvo_amrwbenc); REGISTER_ENCDEC (LIBVORBIS, libvorbis); - REGISTER_ENCDEC (LIBVPX, libvpx); + REGISTER_ENCDEC (LIBVPX_VP8, libvpx_vp8); + REGISTER_ENCDEC (LIBVPX_VP9, libvpx_vp9); REGISTER_ENCODER(LIBX264, libx264); REGISTER_ENCODER(LIBX264RGB, libx264rgb); REGISTER_ENCODER(LIBXAVS, libxavs); diff --git a/mythtv/external/FFmpeg/libavcodec/alpha/dsputil_alpha.c b/mythtv/external/FFmpeg/libavcodec/alpha/dsputil_alpha.c index 38ac0209a88..cb62665a554 100644 --- a/mythtv/external/FFmpeg/libavcodec/alpha/dsputil_alpha.c +++ b/mythtv/external/FFmpeg/libavcodec/alpha/dsputil_alpha.c @@ -19,20 +19,21 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/attributes.h" #include "libavcodec/dsputil.h" #include "dsputil_alpha.h" #include "asm.h" -void (*put_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels, +void (*put_pixels_clamped_axp_p)(const int16_t *block, uint8_t *pixels, int line_size); -void (*add_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels, +void (*add_pixels_clamped_axp_p)(const int16_t *block, uint8_t *pixels, int line_size); #if 0 /* These functions were the base for the optimized assembler routines, and remain here for documentation purposes. */ -static void put_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels, - int line_size) +static void put_pixels_clamped_mvi(const int16_t *block, uint8_t *pixels, + ptrdiff_t line_size) { int i = 8; uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */ @@ -55,8 +56,8 @@ static void put_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels, } while (--i); } -void add_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels, - int line_size) +void add_pixels_clamped_mvi(const int16_t *block, uint8_t *pixels, + ptrdiff_t line_size) { int h = 8; /* Keep this function a leaf function by generating the constants @@ -100,9 +101,9 @@ void add_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels, } #endif -static void clear_blocks_axp(DCTELEM *blocks) { +static void clear_blocks_axp(int16_t *blocks) { uint64_t *p = (uint64_t *) blocks; - int n = sizeof(DCTELEM) * 6 * 64; + int n = sizeof(int16_t) * 6 * 64; do { p[0] = 0; @@ -211,8 +212,8 @@ static inline uint64_t avg4(uint64_t l1, uint64_t l2, uint64_t l3, uint64_t l4) #define MAKE_OP(OPNAME, SUFF, OPKIND, STORE) \ static void OPNAME ## _pixels ## SUFF ## _axp \ - (uint8_t *av_restrict block, const uint8_t *av_restrict pixels, \ - int line_size, int h) \ + (uint8_t *restrict block, const uint8_t *restrict pixels, \ + ptrdiff_t line_size, int h) \ { \ if ((size_t) pixels & 0x7) { \ OPKIND(uldq, STORE); \ @@ -222,8 +223,8 @@ static void OPNAME ## _pixels ## SUFF ## _axp \ } \ \ static void OPNAME ## _pixels16 ## SUFF ## _axp \ - (uint8_t *av_restrict block, const uint8_t *av_restrict pixels, \ - int line_size, int h) \ + (uint8_t *restrict block, const uint8_t *restrict pixels, \ + ptrdiff_t line_size, int h) \ { \ OPNAME ## _pixels ## SUFF ## _axp(block, pixels, line_size, h); \ OPNAME ## _pixels ## SUFF ## _axp(block + 8, pixels + 8, line_size, h); \ @@ -262,13 +263,13 @@ PIXOP(put_no_rnd, STORE); PIXOP(avg_no_rnd, STORE); static void put_pixels16_axp_asm(uint8_t *block, const uint8_t *pixels, - int line_size, int h) + ptrdiff_t line_size, int h) { put_pixels_axp_asm(block, pixels, line_size, h); put_pixels_axp_asm(block + 8, pixels + 8, line_size, h); } -void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx) +av_cold void ff_dsputil_init_alpha(DSPContext *c, AVCodecContext *avctx) { const int high_bit_depth = avctx->bits_per_raw_sample > 8; @@ -288,10 +289,10 @@ void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx) c->avg_pixels_tab[0][2] = avg_pixels16_y2_axp; c->avg_pixels_tab[0][3] = avg_pixels16_xy2_axp; - c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_axp; - c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_axp; - c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_axp; - c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_axp; + c->avg_no_rnd_pixels_tab[0] = avg_no_rnd_pixels16_axp; + c->avg_no_rnd_pixels_tab[1] = avg_no_rnd_pixels16_x2_axp; + c->avg_no_rnd_pixels_tab[2] = avg_no_rnd_pixels16_y2_axp; + c->avg_no_rnd_pixels_tab[3] = avg_no_rnd_pixels16_xy2_axp; c->put_pixels_tab[1][0] = put_pixels_axp_asm; c->put_pixels_tab[1][1] = put_pixels_x2_axp; @@ -308,11 +309,6 @@ void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx) c->avg_pixels_tab[1][2] = avg_pixels_y2_axp; c->avg_pixels_tab[1][3] = avg_pixels_xy2_axp; - c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels_axp; - c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels_x2_axp; - c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels_y2_axp; - c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels_xy2_axp; - c->clear_blocks = clear_blocks_axp; } diff --git a/mythtv/external/FFmpeg/libavcodec/alpha/dsputil_alpha.h b/mythtv/external/FFmpeg/libavcodec/alpha/dsputil_alpha.h index 4bc09a497dd..cf5ca3b6bf0 100644 --- a/mythtv/external/FFmpeg/libavcodec/alpha/dsputil_alpha.h +++ b/mythtv/external/FFmpeg/libavcodec/alpha/dsputil_alpha.h @@ -19,26 +19,27 @@ #ifndef AVCODEC_ALPHA_DSPUTIL_ALPHA_H #define AVCODEC_ALPHA_DSPUTIL_ALPHA_H -#include "libavcodec/dsputil.h" +#include +#include -void ff_simple_idct_axp(DCTELEM *block); -void ff_simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block); -void ff_simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block); +void ff_simple_idct_axp(int16_t *block); +void ff_simple_idct_put_axp(uint8_t *dest, int line_size, int16_t *block); +void ff_simple_idct_add_axp(uint8_t *dest, int line_size, int16_t *block); void put_pixels_axp_asm(uint8_t *block, const uint8_t *pixels, - int line_size, int h); -void put_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels, + ptrdiff_t line_size, int h); +void put_pixels_clamped_mvi_asm(const int16_t *block, uint8_t *pixels, int line_size); -void add_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels, +void add_pixels_clamped_mvi_asm(const int16_t *block, uint8_t *pixels, int line_size); -extern void (*put_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels, +extern void (*put_pixels_clamped_axp_p)(const int16_t *block, uint8_t *pixels, int line_size); -extern void (*add_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels, +extern void (*add_pixels_clamped_axp_p)(const int16_t *block, uint8_t *pixels, int line_size); -void get_pixels_mvi(DCTELEM *av_restrict block, - const uint8_t *av_restrict pixels, int line_size); -void diff_pixels_mvi(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, +void get_pixels_mvi(int16_t *restrict block, + const uint8_t *restrict pixels, int line_size); +void diff_pixels_mvi(int16_t *block, const uint8_t *s1, const uint8_t *s2, int stride); int pix_abs8x8_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h); int pix_abs16x16_mvi_asm(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h); diff --git a/mythtv/external/FFmpeg/libavcodec/alpha/dsputil_alpha_asm.S b/mythtv/external/FFmpeg/libavcodec/alpha/dsputil_alpha_asm.S index 32a8bc9562d..557ba57a955 100644 --- a/mythtv/external/FFmpeg/libavcodec/alpha/dsputil_alpha_asm.S +++ b/mythtv/external/FFmpeg/libavcodec/alpha/dsputil_alpha_asm.S @@ -135,7 +135,7 @@ $aligned: .end put_pixels_axp_asm /************************************************************************ - * void put_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels, + * void put_pixels_clamped_mvi_asm(const int16_t *block, uint8_t *pixels, * int line_size) */ .align 6 @@ -185,7 +185,7 @@ put_pixels_clamped_mvi_asm: .end put_pixels_clamped_mvi_asm /************************************************************************ - * void add_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels, + * void add_pixels_clamped_mvi_asm(const int16_t *block, uint8_t *pixels, * int line_size) */ .align 6 diff --git a/mythtv/external/FFmpeg/libavcodec/alpha/motion_est_alpha.c b/mythtv/external/FFmpeg/libavcodec/alpha/motion_est_alpha.c index 927b25d992f..a7c33e49007 100644 --- a/mythtv/external/FFmpeg/libavcodec/alpha/motion_est_alpha.c +++ b/mythtv/external/FFmpeg/libavcodec/alpha/motion_est_alpha.c @@ -19,12 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavcodec/dsputil.h" #include "dsputil_alpha.h" #include "asm.h" -void get_pixels_mvi(DCTELEM *av_restrict block, - const uint8_t *av_restrict pixels, int line_size) +void get_pixels_mvi(int16_t *restrict block, + const uint8_t *restrict pixels, int line_size) { int h = 8; @@ -40,7 +39,7 @@ void get_pixels_mvi(DCTELEM *av_restrict block, } while (--h); } -void diff_pixels_mvi(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, +void diff_pixels_mvi(int16_t *block, const uint8_t *s1, const uint8_t *s2, int stride) { int h = 8; uint64_t mask = 0x4040; diff --git a/mythtv/external/FFmpeg/libavcodec/alpha/mpegvideo_alpha.c b/mythtv/external/FFmpeg/libavcodec/alpha/mpegvideo_alpha.c index 28eca072c08..7ba0f2e68f1 100644 --- a/mythtv/external/FFmpeg/libavcodec/alpha/mpegvideo_alpha.c +++ b/mythtv/external/FFmpeg/libavcodec/alpha/mpegvideo_alpha.c @@ -19,11 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavcodec/dsputil.h" +#include "libavutil/attributes.h" #include "libavcodec/mpegvideo.h" #include "asm.h" -static void dct_unquantize_h263_axp(DCTELEM *block, int n_coeffs, +static void dct_unquantize_h263_axp(int16_t *block, int n_coeffs, uint64_t qscale, uint64_t qadd) { uint64_t qmul = qscale << 1; @@ -69,12 +69,12 @@ static void dct_unquantize_h263_axp(DCTELEM *block, int n_coeffs, } } -static void dct_unquantize_h263_intra_axp(MpegEncContext *s, DCTELEM *block, +static void dct_unquantize_h263_intra_axp(MpegEncContext *s, int16_t *block, int n, int qscale) { int n_coeffs; uint64_t qadd; - DCTELEM block0 = block[0]; + int16_t block0 = block[0]; if (!s->h263_aic) { if (n < 4) @@ -96,14 +96,14 @@ static void dct_unquantize_h263_intra_axp(MpegEncContext *s, DCTELEM *block, block[0] = block0; } -static void dct_unquantize_h263_inter_axp(MpegEncContext *s, DCTELEM *block, +static void dct_unquantize_h263_inter_axp(MpegEncContext *s, int16_t *block, int n, int qscale) { int n_coeffs = s->inter_scantable.raster_end[s->block_last_index[n]]; dct_unquantize_h263_axp(block, n_coeffs, qscale, (qscale - 1) | 1); } -void ff_MPV_common_init_axp(MpegEncContext *s) +av_cold void ff_MPV_common_init_axp(MpegEncContext *s) { s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_axp; s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_axp; diff --git a/mythtv/external/FFmpeg/libavcodec/alpha/simple_idct_alpha.c b/mythtv/external/FFmpeg/libavcodec/alpha/simple_idct_alpha.c index 522efd2b4dd..3bd1b336fe7 100644 --- a/mythtv/external/FFmpeg/libavcodec/alpha/simple_idct_alpha.c +++ b/mythtv/external/FFmpeg/libavcodec/alpha/simple_idct_alpha.c @@ -26,7 +26,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavcodec/dsputil.h" #include "dsputil_alpha.h" #include "asm.h" @@ -44,7 +43,7 @@ #define COL_SHIFT 20 /* 0: all entries 0, 1: only first entry nonzero, 2: otherwise */ -static inline int idct_row(DCTELEM *row) +static inline int idct_row(int16_t *row) { int a0, a1, a2, a3, b0, b1, b2, b3, t; uint64_t l, r, t2; @@ -152,7 +151,7 @@ static inline int idct_row(DCTELEM *row) return 2; } -static inline void idct_col(DCTELEM *col) +static inline void idct_col(int16_t *col) { int a0, a1, a2, a3, b0, b1, b2, b3; @@ -229,7 +228,7 @@ static inline void idct_col(DCTELEM *col) /* If all rows but the first one are zero after row transformation, all rows will be identical after column transformation. */ -static inline void idct_col2(DCTELEM *col) +static inline void idct_col2(int16_t *col) { int i; uint64_t l, r; @@ -251,7 +250,7 @@ static inline void idct_col2(DCTELEM *col) stq(l, col + 14 * 4); stq(r, col + 15 * 4); } -void ff_simple_idct_axp(DCTELEM *block) +void ff_simple_idct_axp(int16_t *block) { int i; @@ -291,13 +290,13 @@ void ff_simple_idct_axp(DCTELEM *block) } } -void ff_simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block) +void ff_simple_idct_put_axp(uint8_t *dest, int line_size, int16_t *block) { ff_simple_idct_axp(block); put_pixels_clamped_axp_p(block, dest, line_size); } -void ff_simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block) +void ff_simple_idct_add_axp(uint8_t *dest, int line_size, int16_t *block) { ff_simple_idct_axp(block); add_pixels_clamped_axp_p(block, dest, line_size); diff --git a/mythtv/external/FFmpeg/libavcodec/alsdec.c b/mythtv/external/FFmpeg/libavcodec/alsdec.c index d7baa6eccb8..a6d70d44e2e 100644 --- a/mythtv/external/FFmpeg/libavcodec/alsdec.c +++ b/mythtv/external/FFmpeg/libavcodec/alsdec.c @@ -192,7 +192,6 @@ typedef struct { typedef struct { AVCodecContext *avctx; - AVFrame frame; ALSSpecificConfig sconf; GetBitContext gb; DSPContext dsp; @@ -289,8 +288,10 @@ static av_cold int read_specific_config(ALSDecContext *ctx) ALSSpecificConfig *sconf = &ctx->sconf; AVCodecContext *avctx = ctx->avctx; uint32_t als_id, header_size, trailer_size; + int ret; - init_get_bits(&gb, avctx->extradata, avctx->extradata_size * 8); + if ((ret = init_get_bits8(&gb, avctx->extradata, avctx->extradata_size)) < 0) + return ret; config_offset = avpriv_mpeg4audio_get_config(&m4ac, avctx->extradata, avctx->extradata_size * 8, 1); @@ -1448,6 +1449,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { ALSDecContext *ctx = avctx->priv_data; + AVFrame *frame = data; ALSSpecificConfig *sconf = &ctx->sconf; const uint8_t *buffer = avpkt->data; int buffer_size = avpkt->size; @@ -1477,8 +1479,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, ctx->frame_id++; /* get output buffer */ - ctx->frame.nb_samples = ctx->cur_frame_length; - if ((ret = ff_get_buffer(avctx, &ctx->frame)) < 0) { + frame->nb_samples = ctx->cur_frame_length; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed.\n"); return ret; } @@ -1486,7 +1488,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, // transform decoded frame into output format #define INTERLEAVE_OUTPUT(bps) \ { \ - int##bps##_t *dest = (int##bps##_t*)ctx->frame.data[0]; \ + int##bps##_t *dest = (int##bps##_t*)frame->data[0]; \ shift = bps - ctx->avctx->bits_per_raw_sample; \ if (!ctx->cs_switch) { \ for (sample = 0; sample < ctx->cur_frame_length; sample++) \ @@ -1510,7 +1512,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, int swap = HAVE_BIGENDIAN != sconf->msb_first; if (ctx->avctx->bits_per_raw_sample == 24) { - int32_t *src = (int32_t *)ctx->frame.data[0]; + int32_t *src = (int32_t *)frame->data[0]; for (sample = 0; sample < ctx->cur_frame_length * avctx->channels; @@ -1531,7 +1533,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, if (swap) { if (ctx->avctx->bits_per_raw_sample <= 16) { - int16_t *src = (int16_t*) ctx->frame.data[0]; + int16_t *src = (int16_t*) frame->data[0]; int16_t *dest = (int16_t*) ctx->crc_buffer; for (sample = 0; sample < ctx->cur_frame_length * avctx->channels; @@ -1539,12 +1541,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, *dest++ = av_bswap16(src[sample]); } else { ctx->dsp.bswap_buf((uint32_t*)ctx->crc_buffer, - (uint32_t *)ctx->frame.data[0], + (uint32_t *)frame->data[0], ctx->cur_frame_length * avctx->channels); } crc_source = ctx->crc_buffer; } else { - crc_source = ctx->frame.data[0]; + crc_source = frame->data[0]; } ctx->crc = av_crc(ctx->crc_table, ctx->crc, crc_source, @@ -1560,9 +1562,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, } } - *got_frame_ptr = 1; - *(AVFrame *)data = ctx->frame; - + *got_frame_ptr = 1; bytes_read = invalid_frame ? buffer_size : (get_bits_count(&ctx->gb) + 7) >> 3; @@ -1759,9 +1759,6 @@ static av_cold int decode_init(AVCodecContext *avctx) ff_dsputil_init(&ctx->dsp, avctx); - avcodec_get_frame_defaults(&ctx->frame); - avctx->coded_frame = &ctx->frame; - return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/amrnbdec.c b/mythtv/external/FFmpeg/libavcodec/amrnbdec.c index 40bc2530e6f..6e14a608432 100644 --- a/mythtv/external/FFmpeg/libavcodec/amrnbdec.c +++ b/mythtv/external/FFmpeg/libavcodec/amrnbdec.c @@ -44,8 +44,8 @@ #include #include "libavutil/channel_layout.h" +#include "libavutil/float_dsp.h" #include "avcodec.h" -#include "dsputil.h" #include "libavutil/common.h" #include "libavutil/avassert.h" #include "celp_math.h" @@ -98,7 +98,6 @@ #define AMR_AGC_ALPHA 0.9 typedef struct AMRContext { - AVFrame avframe; ///< AVFrame for decoded samples AMRNBFrame frame; ///< decoded AMR parameters (lsf coefficients, codebook indexes, etc) uint8_t bad_frame_indicator; ///< bad frame ? 1 : 0 enum Mode cur_frame_mode; @@ -185,9 +184,6 @@ static av_cold int amrnb_decode_init(AVCodecContext *avctx) for (i = 0; i < 4; i++) p->prediction_error[i] = MIN_ENERGY; - avcodec_get_frame_defaults(&p->avframe); - avctx->coded_frame = &p->avframe; - ff_acelp_filter_init(&p->acelpf_ctx); ff_acelp_vectors_init(&p->acelpv_ctx); ff_celp_filter_init(&p->celpf_ctx); @@ -810,7 +806,7 @@ static int synthesis(AMRContext *p, float *lpc, // emphasize pitch vector contribution if (p->pitch_gain[4] > 0.5 && !overflow) { float energy = p->celpm_ctx.dot_productf(excitation, excitation, - AMR_SUBFRAME_SIZE); + AMR_SUBFRAME_SIZE); float pitch_factor = p->pitch_gain[4] * (p->cur_frame_mode == MODE_12k2 ? @@ -911,7 +907,7 @@ static void postfilter(AMRContext *p, float *lpc, float *buf_out) float *samples = p->samples_in + LP_FILTER_ORDER; // Start of input float speech_gain = p->celpm_ctx.dot_productf(samples, samples, - AMR_SUBFRAME_SIZE); + AMR_SUBFRAME_SIZE); float pole_out[AMR_SUBFRAME_SIZE + LP_FILTER_ORDER]; // Output of pole filter const float *gamma_n, *gamma_d; // Formant filter factor table @@ -954,6 +950,7 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data, { AMRContext *p = avctx->priv_data; // pointer to private data + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; float *buf_out; // pointer to the output data buffer @@ -965,12 +962,12 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data, const float *synth_fixed_vector; // pointer to the fixed vector that synthesis should use /* get output buffer */ - p->avframe.nb_samples = AMR_BLOCK_SIZE; - if ((ret = ff_get_buffer(avctx, &p->avframe)) < 0) { + frame->nb_samples = AMR_BLOCK_SIZE; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - buf_out = (float *)p->avframe.data[0]; + buf_out = (float *)frame->data[0]; p->cur_frame_mode = unpack_bitstream(p, buf, buf_size); if (p->cur_frame_mode == NO_DATA) { @@ -1018,8 +1015,8 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data, p->fixed_gain[4] = ff_amr_set_fixed_gain(fixed_gain_factor, p->celpm_ctx.dot_productf(p->fixed_vector, - p->fixed_vector, - AMR_SUBFRAME_SIZE) / + p->fixed_vector, + AMR_SUBFRAME_SIZE) / AMR_SUBFRAME_SIZE, p->prediction_error, energy_mean[p->cur_frame_mode], energy_pred_fac); @@ -1078,8 +1075,7 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data, p->acelpv_ctx.weighted_vector_sumf(p->lsf_avg, p->lsf_avg, p->lsf_q[3], 0.84, 0.16, LP_FILTER_ORDER); - *got_frame_ptr = 1; - *(AVFrame *)data = p->avframe; + *got_frame_ptr = 1; /* return the amount of bytes consumed if everything was OK */ return frame_sizes_nb[p->cur_frame_mode] + 1; // +7 for rounding and +8 for TOC diff --git a/mythtv/external/FFmpeg/libavcodec/amrwbdec.c b/mythtv/external/FFmpeg/libavcodec/amrwbdec.c index fa910466d4c..c0481325e73 100644 --- a/mythtv/external/FFmpeg/libavcodec/amrwbdec.c +++ b/mythtv/external/FFmpeg/libavcodec/amrwbdec.c @@ -26,10 +26,10 @@ #include "libavutil/channel_layout.h" #include "libavutil/common.h" +#include "libavutil/float_dsp.h" #include "libavutil/lfg.h" #include "avcodec.h" -#include "dsputil.h" #include "lsp.h" #include "celp_filters.h" #include "celp_math.h" @@ -45,7 +45,6 @@ #include "mips/amrwbdec_mips.h" typedef struct { - AVFrame avframe; ///< AVFrame for decoded samples AMRWBFrame frame; ///< AMRWB parameters decoded from bitstream enum Mode fr_cur_mode; ///< mode index of current frame uint8_t fr_quality; ///< frame quality index (FQI) @@ -121,9 +120,6 @@ static av_cold int amrwb_decode_init(AVCodecContext *avctx) for (i = 0; i < 4; i++) ctx->prediction_error[i] = MIN_ENERGY; - avcodec_get_frame_defaults(&ctx->avframe); - avctx->coded_frame = &ctx->avframe; - ff_acelp_filter_init(&ctx->acelpf_ctx); ff_acelp_vectors_init(&ctx->acelpv_ctx); ff_celp_filter_init(&ctx->celpf_ctx); @@ -612,11 +608,11 @@ static float voice_factor(float *p_vector, float p_gain, CELPMContext *ctx) { double p_ener = (double) ctx->dot_productf(p_vector, p_vector, - AMRWB_SFR_SIZE) * - p_gain * p_gain; + AMRWB_SFR_SIZE) * + p_gain * p_gain; double f_ener = (double) ctx->dot_productf(f_vector, f_vector, - AMRWB_SFR_SIZE) * - f_gain * f_gain; + AMRWB_SFR_SIZE) * + f_gain * f_gain; return (p_ener - f_ener) / (p_ener + f_ener); } @@ -785,7 +781,7 @@ static void synthesis(AMRWBContext *ctx, float *lpc, float *excitation, if (ctx->pitch_gain[0] > 0.5 && ctx->fr_cur_mode <= MODE_8k85) { int i; float energy = ctx->celpm_ctx.dot_productf(excitation, excitation, - AMRWB_SFR_SIZE); + AMRWB_SFR_SIZE); // XXX: Weird part in both ref code and spec. A unknown parameter // {beta} seems to be identical to the current pitch gain @@ -846,8 +842,8 @@ static void upsample_5_4(float *out, const float *in, int o_size, CELPMContext * for (k = 1; k < 5; k++) { out[i] = ctx->dot_productf(in0 + int_part, - upsample_fir[4 - frac_part], - UPS_MEM_SIZE); + upsample_fir[4 - frac_part], + UPS_MEM_SIZE); int_part++; frac_part--; i++; @@ -893,7 +889,8 @@ static void scaled_hb_excitation(AMRWBContext *ctx, float *hb_exc, const float *synth_exc, float hb_gain) { int i; - float energy = ctx->celpm_ctx.dot_productf(synth_exc, synth_exc, AMRWB_SFR_SIZE); + float energy = ctx->celpm_ctx.dot_productf(synth_exc, synth_exc, + AMRWB_SFR_SIZE); /* Generate a white-noise excitation */ for (i = 0; i < AMRWB_SFR_SIZE_16k; i++) @@ -1096,6 +1093,7 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { AMRWBContext *ctx = avctx->priv_data; + AVFrame *frame = data; AMRWBFrame *cf = &ctx->frame; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; @@ -1113,12 +1111,12 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int sub, i, ret; /* get output buffer */ - ctx->avframe.nb_samples = 4 * AMRWB_SFR_SIZE_16k; - if ((ret = ff_get_buffer(avctx, &ctx->avframe)) < 0) { + frame->nb_samples = 4 * AMRWB_SFR_SIZE_16k; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - buf_out = (float *)ctx->avframe.data[0]; + buf_out = (float *)frame->data[0]; header_size = decode_mime_header(ctx, buf); if (ctx->fr_cur_mode > MODE_SID) { @@ -1189,8 +1187,8 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, ctx->fixed_gain[0] = ff_amr_set_fixed_gain(fixed_gain_factor, ctx->celpm_ctx.dot_productf(ctx->fixed_vector, - ctx->fixed_vector, - AMRWB_SFR_SIZE) / + ctx->fixed_vector, + AMRWB_SFR_SIZE) / AMRWB_SFR_SIZE, ctx->prediction_error, ENERGY_MEAN, energy_pred_fac); @@ -1264,8 +1262,7 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, memcpy(ctx->isp_sub4_past, ctx->isp[3], LP_ORDER * sizeof(ctx->isp[3][0])); memcpy(ctx->isf_past_final, ctx->isf_cur, LP_ORDER * sizeof(float)); - *got_frame_ptr = 1; - *(AVFrame *)data = ctx->avframe; + *got_frame_ptr = 1; return expected_fr_size; } diff --git a/mythtv/external/FFmpeg/libavcodec/anm.c b/mythtv/external/FFmpeg/libavcodec/anm.c index d405213c827..08f5170e9bb 100644 --- a/mythtv/external/FFmpeg/libavcodec/anm.c +++ b/mythtv/external/FFmpeg/libavcodec/anm.c @@ -114,7 +114,7 @@ static int decode_frame(AVCodecContext *avctx, uint8_t *dst, *dst_end; int count, ret; - if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0) { + if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0){ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } diff --git a/mythtv/external/FFmpeg/libavcodec/ansi.c b/mythtv/external/FFmpeg/libavcodec/ansi.c index e705da62811..51339d24f9e 100644 --- a/mythtv/external/FFmpeg/libavcodec/ansi.c +++ b/mythtv/external/FFmpeg/libavcodec/ansi.c @@ -434,8 +434,8 @@ static int decode_frame(AVCodecContext *avctx, av_log(avctx, AV_LOG_WARNING, "args overflow (%i)\n", s->nb_args); if (s->nb_args < MAX_NB_ARGS && s->args[s->nb_args] >= 0) s->nb_args++; - if (execute_code(avctx, buf[0]) < 0) - return -1; + if ((ret = execute_code(avctx, buf[0])) < 0) + return ret; s->state = STATE_NORMAL; } break; diff --git a/mythtv/external/FFmpeg/libavcodec/apedec.c b/mythtv/external/FFmpeg/libavcodec/apedec.c index 214679634cf..e0af6aad5f0 100644 --- a/mythtv/external/FFmpeg/libavcodec/apedec.c +++ b/mythtv/external/FFmpeg/libavcodec/apedec.c @@ -129,7 +129,6 @@ typedef struct APEPredictor { typedef struct APEContext { AVClass *class; ///< class for AVOptions AVCodecContext *avctx; - AVFrame frame; DSPContext dsp; int channels; int samples; ///< samples left to decode in current frame @@ -235,9 +234,6 @@ static av_cold int ape_decode_init(AVCodecContext *avctx) ff_dsputil_init(&s->dsp, avctx); avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; filter_alloc_fail: ape_decode_close(avctx); @@ -826,6 +822,7 @@ static void ape_unpack_stereo(APEContext *ctx, int count) static int ape_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; APEContext *s = avctx->priv_data; uint8_t *sample8; @@ -906,8 +903,8 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data, s->decoded[1] = s->decoded_buffer + FFALIGN(blockstodecode, 8); /* get output buffer */ - s->frame.nb_samples = blockstodecode; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = blockstodecode; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -929,21 +926,21 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data, switch (s->bps) { case 8: for (ch = 0; ch < s->channels; ch++) { - sample8 = (uint8_t *)s->frame.data[ch]; + sample8 = (uint8_t *)frame->data[ch]; for (i = 0; i < blockstodecode; i++) *sample8++ = (s->decoded[ch][i] + 0x80) & 0xff; } break; case 16: for (ch = 0; ch < s->channels; ch++) { - sample16 = (int16_t *)s->frame.data[ch]; + sample16 = (int16_t *)frame->data[ch]; for (i = 0; i < blockstodecode; i++) *sample16++ = s->decoded[ch][i]; } break; case 24: for (ch = 0; ch < s->channels; ch++) { - sample24 = (int32_t *)s->frame.data[ch]; + sample24 = (int32_t *)frame->data[ch]; for (i = 0; i < blockstodecode; i++) *sample24++ = s->decoded[ch][i] << 8; } @@ -952,8 +949,7 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data, s->samples -= blockstodecode; - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return !s->samples ? avpkt->size : 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/arm/Makefile b/mythtv/external/FFmpeg/libavcodec/arm/Makefile index ac486f47dc0..1c91d62ca8f 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/Makefile +++ b/mythtv/external/FFmpeg/libavcodec/arm/Makefile @@ -1,3 +1,5 @@ +ARCH_HEADERS = mathops.h + OBJS-$(CONFIG_AC3DSP) += arm/ac3dsp_init_arm.o \ arm/ac3dsp_arm.o @@ -15,6 +17,7 @@ OBJS-$(CONFIG_MPEGAUDIODSP) += arm/mpegaudiodsp_init_arm.o ARMV6-OBJS-$(CONFIG_MPEGAUDIODSP) += arm/mpegaudiodsp_fixed_armv6.o OBJS-$(CONFIG_MPEGVIDEO) += arm/mpegvideo_arm.o +OBJS-$(CONFIG_VORBIS_DECODER) += arm/vorbisdsp_init_arm.o OBJS-$(CONFIG_VP3DSP) += arm/vp3dsp_init_arm.o OBJS-$(CONFIG_VP5_DECODER) += arm/vp56dsp_init_arm.o OBJS-$(CONFIG_VP6_DECODER) += arm/vp56dsp_init_arm.o @@ -23,8 +26,10 @@ ARMV6-OBJS-$(CONFIG_VP8_DECODER) += arm/vp8_armv6.o \ arm/vp8dsp_init_armv6.o \ arm/vp8dsp_armv6.o +OBJS-$(CONFIG_H264CHROMA) += arm/h264chroma_init_arm.o OBJS-$(CONFIG_H264DSP) += arm/h264dsp_init_arm.o OBJS-$(CONFIG_H264PRED) += arm/h264pred_init_arm.o +OBJS-$(CONFIG_H264QPEL) += arm/h264qpel_init_arm.o OBJS-$(CONFIG_RV30_DECODER) += arm/rv34dsp_init_arm.o OBJS-$(CONFIG_RV40_DECODER) += arm/rv34dsp_init_arm.o \ @@ -55,9 +60,6 @@ ARMV6-OBJS += arm/dsputil_init_armv6.o \ VFP-OBJS-$(HAVE_ARMV6) += arm/fmtconvert_vfp.o -VFP-OBJS += arm/dsputil_vfp.o \ - arm/dsputil_init_vfp.o \ - NEON-OBJS-$(CONFIG_FFT) += arm/fft_neon.o \ arm/fft_fixed_neon.o \ @@ -66,12 +68,14 @@ NEON-OBJS-$(CONFIG_MDCT) += arm/mdct_neon.o \ NEON-OBJS-$(CONFIG_RDFT) += arm/rdft_neon.o \ +NEON-OBJS-$(CONFIG_H264CHROMA) += arm/h264cmc_neon.o NEON-OBJS-$(CONFIG_H264DSP) += arm/h264dsp_neon.o \ arm/h264idct_neon.o \ - arm/h264cmc_neon.o \ NEON-OBJS-$(CONFIG_H264PRED) += arm/h264pred_neon.o \ +NEON-OBJS-$(CONFIG_H264QPEL) += arm/h264qpel_neon.o \ + NEON-OBJS-$(CONFIG_AC3DSP) += arm/ac3dsp_neon.o NEON-OBJS-$(CONFIG_AAC_DECODER) += arm/sbrdsp_neon.o \ @@ -84,7 +88,8 @@ NEON-OBJS-$(CONFIG_MPEGVIDEO) += arm/mpegvideo_neon.o NEON-OBJS-$(CONFIG_RV30_DECODER) += arm/rv34dsp_neon.o NEON-OBJS-$(CONFIG_RV40_DECODER) += arm/rv34dsp_neon.o \ arm/rv40dsp_neon.o \ - arm/h264cmc_neon.o \ + +NEON-OBJS-$(CONFIG_VORBIS_DECODER) += arm/vorbisdsp_neon.o NEON-OBJS-$(CONFIG_VP3DSP) += arm/vp3dsp_neon.o diff --git a/mythtv/external/FFmpeg/libavcodec/arm/dca.h b/mythtv/external/FFmpeg/libavcodec/arm/dca.h index 3b341cf3da5..2cfd18a8377 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/dca.h +++ b/mythtv/external/FFmpeg/libavcodec/arm/dca.h @@ -22,8 +22,9 @@ #define AVCODEC_ARM_DCA_H #include + #include "config.h" -#include "libavutil/intmath.h" +#include "libavcodec/mathops.h" #if HAVE_ARMV6_INLINE && AV_GCC_VERSION_AT_LEAST(4,4) && !CONFIG_THUMB diff --git a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_arm.c index 03df6b29d0f..a6725f370ca 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_arm.c @@ -19,27 +19,27 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/attributes.h" #include "libavutil/arm/cpu.h" -#include "libavcodec/dsputil.h" #include "dsputil_arm.h" -void ff_j_rev_dct_arm(DCTELEM *data); -void ff_simple_idct_arm(DCTELEM *data); +void ff_j_rev_dct_arm(int16_t *data); +void ff_simple_idct_arm(int16_t *data); /* XXX: local hack */ -static void (*ff_put_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size); -static void (*ff_add_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size); +static void (*ff_put_pixels_clamped)(const int16_t *block, uint8_t *pixels, int line_size); +static void (*ff_add_pixels_clamped)(const int16_t *block, uint8_t *pixels, int line_size); -void ff_put_pixels8_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h); -void ff_put_pixels8_x2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h); -void ff_put_pixels8_y2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h); -void ff_put_pixels8_xy2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h); +void ff_put_pixels8_arm(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h); +void ff_put_pixels8_x2_arm(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h); +void ff_put_pixels8_y2_arm(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h); +void ff_put_pixels8_xy2_arm(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h); -void ff_put_no_rnd_pixels8_x2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h); -void ff_put_no_rnd_pixels8_y2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h); -void ff_put_no_rnd_pixels8_xy2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h); +void ff_put_no_rnd_pixels8_x2_arm(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h); +void ff_put_no_rnd_pixels8_y2_arm(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h); +void ff_put_no_rnd_pixels8_xy2_arm(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h); -void ff_put_pixels16_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h); +void ff_put_pixels16_arm(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h); CALL_2X_PIXELS(ff_put_pixels16_x2_arm, ff_put_pixels8_x2_arm, 8) CALL_2X_PIXELS(ff_put_pixels16_y2_arm, ff_put_pixels8_y2_arm, 8) @@ -48,33 +48,33 @@ CALL_2X_PIXELS(ff_put_no_rnd_pixels16_x2_arm, ff_put_no_rnd_pixels8_x2_arm, 8) CALL_2X_PIXELS(ff_put_no_rnd_pixels16_y2_arm, ff_put_no_rnd_pixels8_y2_arm, 8) CALL_2X_PIXELS(ff_put_no_rnd_pixels16_xy2_arm, ff_put_no_rnd_pixels8_xy2_arm,8) -void ff_add_pixels_clamped_arm(const DCTELEM *block, uint8_t *dest, +void ff_add_pixels_clamped_arm(const int16_t *block, uint8_t *dest, int line_size); /* XXX: those functions should be suppressed ASAP when all IDCTs are converted */ -static void j_rev_dct_arm_put(uint8_t *dest, int line_size, DCTELEM *block) +static void j_rev_dct_arm_put(uint8_t *dest, int line_size, int16_t *block) { ff_j_rev_dct_arm (block); ff_put_pixels_clamped(block, dest, line_size); } -static void j_rev_dct_arm_add(uint8_t *dest, int line_size, DCTELEM *block) +static void j_rev_dct_arm_add(uint8_t *dest, int line_size, int16_t *block) { ff_j_rev_dct_arm (block); ff_add_pixels_clamped(block, dest, line_size); } -static void simple_idct_arm_put(uint8_t *dest, int line_size, DCTELEM *block) +static void simple_idct_arm_put(uint8_t *dest, int line_size, int16_t *block) { ff_simple_idct_arm (block); ff_put_pixels_clamped(block, dest, line_size); } -static void simple_idct_arm_add(uint8_t *dest, int line_size, DCTELEM *block) +static void simple_idct_arm_add(uint8_t *dest, int line_size, int16_t *block) { ff_simple_idct_arm (block); ff_add_pixels_clamped(block, dest, line_size); } -void ff_dsputil_init_arm(DSPContext* c, AVCodecContext *avctx) +av_cold void ff_dsputil_init_arm(DSPContext *c, AVCodecContext *avctx) { const int high_bit_depth = avctx->bits_per_raw_sample > 8; int cpu_flags = av_get_cpu_flags(); @@ -121,6 +121,5 @@ void ff_dsputil_init_arm(DSPContext* c, AVCodecContext *avctx) if (have_armv5te(cpu_flags)) ff_dsputil_init_armv5te(c, avctx); if (have_armv6(cpu_flags)) ff_dsputil_init_armv6(c, avctx); - if (have_vfp(cpu_flags)) ff_dsputil_init_vfp(c, avctx); if (have_neon(cpu_flags)) ff_dsputil_init_neon(c, avctx); } diff --git a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_armv5te.c b/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_armv5te.c index b4f3f0616e0..841fbfadcdf 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_armv5te.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_armv5te.c @@ -18,12 +18,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavcodec/dsputil.h" #include "dsputil_arm.h" -void ff_simple_idct_armv5te(DCTELEM *data); -void ff_simple_idct_put_armv5te(uint8_t *dest, int line_size, DCTELEM *data); -void ff_simple_idct_add_armv5te(uint8_t *dest, int line_size, DCTELEM *data); +void ff_simple_idct_armv5te(int16_t *data); +void ff_simple_idct_put_armv5te(uint8_t *dest, int line_size, int16_t *data); +void ff_simple_idct_add_armv5te(uint8_t *dest, int line_size, int16_t *data); av_cold void ff_dsputil_init_armv5te(DSPContext *c, AVCodecContext *avctx) { diff --git a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_armv6.c b/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_armv6.c index 1081135874b..3e7aa37b9d0 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_armv6.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_armv6.c @@ -21,37 +21,36 @@ #include #include "libavcodec/avcodec.h" -#include "libavcodec/dsputil.h" #include "dsputil_arm.h" -void ff_simple_idct_armv6(DCTELEM *data); -void ff_simple_idct_put_armv6(uint8_t *dest, int line_size, DCTELEM *data); -void ff_simple_idct_add_armv6(uint8_t *dest, int line_size, DCTELEM *data); +void ff_simple_idct_armv6(int16_t *data); +void ff_simple_idct_put_armv6(uint8_t *dest, int line_size, int16_t *data); +void ff_simple_idct_add_armv6(uint8_t *dest, int line_size, int16_t *data); -void ff_put_pixels16_armv6(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels16_x2_armv6(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels16_y2_armv6(uint8_t *, const uint8_t *, int, int); +void ff_put_pixels16_armv6(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels16_x2_armv6(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels16_y2_armv6(uint8_t *, const uint8_t *, ptrdiff_t, int); -void ff_put_pixels16_x2_no_rnd_armv6(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels16_y2_no_rnd_armv6(uint8_t *, const uint8_t *, int, int); +void ff_put_pixels16_x2_no_rnd_armv6(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels16_y2_no_rnd_armv6(uint8_t *, const uint8_t *, ptrdiff_t, int); -void ff_avg_pixels16_armv6(uint8_t *, const uint8_t *, int, int); +void ff_avg_pixels16_armv6(uint8_t *, const uint8_t *, ptrdiff_t, int); -void ff_put_pixels8_armv6(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels8_x2_armv6(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels8_y2_armv6(uint8_t *, const uint8_t *, int, int); +void ff_put_pixels8_armv6(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels8_x2_armv6(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels8_y2_armv6(uint8_t *, const uint8_t *, ptrdiff_t, int); -void ff_put_pixels8_x2_no_rnd_armv6(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels8_y2_no_rnd_armv6(uint8_t *, const uint8_t *, int, int); +void ff_put_pixels8_x2_no_rnd_armv6(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels8_y2_no_rnd_armv6(uint8_t *, const uint8_t *, ptrdiff_t, int); -void ff_avg_pixels8_armv6(uint8_t *, const uint8_t *, int, int); +void ff_avg_pixels8_armv6(uint8_t *, const uint8_t *, ptrdiff_t, int); -void ff_add_pixels_clamped_armv6(const DCTELEM *block, - uint8_t *av_restrict pixels, +void ff_add_pixels_clamped_armv6(const int16_t *block, + uint8_t *restrict pixels, int line_size); -void ff_get_pixels_armv6(DCTELEM *block, const uint8_t *pixels, int stride); -void ff_diff_pixels_armv6(DCTELEM *block, const uint8_t *s1, +void ff_get_pixels_armv6(int16_t *block, const uint8_t *pixels, int stride); +void ff_diff_pixels_armv6(int16_t *block, const uint8_t *s1, const uint8_t *s2, int stride); int ff_pix_abs16_armv6(void *s, uint8_t *blk1, uint8_t *blk2, diff --git a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_neon.c b/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_neon.c index ff1178d6be6..5555bc8e746 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_neon.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_neon.c @@ -21,143 +21,53 @@ #include +#include "libavutil/attributes.h" #include "libavcodec/avcodec.h" -#include "libavcodec/dsputil.h" #include "dsputil_arm.h" -void ff_simple_idct_neon(DCTELEM *data); -void ff_simple_idct_put_neon(uint8_t *dest, int line_size, DCTELEM *data); -void ff_simple_idct_add_neon(uint8_t *dest, int line_size, DCTELEM *data); - -void ff_clear_block_neon(DCTELEM *block); -void ff_clear_blocks_neon(DCTELEM *blocks); - -void ff_put_pixels16_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels16_x2_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels16_y2_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels16_xy2_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels8_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels8_x2_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels8_y2_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels8_xy2_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels16_x2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels16_y2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels16_xy2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels8_x2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels8_y2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); -void ff_put_pixels8_xy2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); - -void ff_avg_pixels16_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels16_x2_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels16_y2_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels16_xy2_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels8_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels8_x2_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels8_y2_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels8_xy2_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels16_x2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels16_y2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels16_xy2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels8_x2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels8_y2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); -void ff_avg_pixels8_xy2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); - -void ff_add_pixels_clamped_neon(const DCTELEM *, uint8_t *, int); -void ff_put_pixels_clamped_neon(const DCTELEM *, uint8_t *, int); -void ff_put_signed_pixels_clamped_neon(const DCTELEM *, uint8_t *, int); - -void ff_put_h264_qpel16_mc00_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc10_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc20_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc30_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc01_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc11_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc21_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc31_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc02_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc12_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc22_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc32_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc03_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc13_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc23_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel16_mc33_neon(uint8_t *, uint8_t *, int); - -void ff_put_h264_qpel8_mc00_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc10_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc20_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc30_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc01_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc11_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc21_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc31_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc02_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc12_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc22_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc32_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc03_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc13_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc23_neon(uint8_t *, uint8_t *, int); -void ff_put_h264_qpel8_mc33_neon(uint8_t *, uint8_t *, int); - -void ff_avg_h264_qpel16_mc00_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc10_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc20_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc30_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc01_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc11_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc21_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc31_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc02_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc12_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc22_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc32_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc03_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc13_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc23_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel16_mc33_neon(uint8_t *, uint8_t *, int); - -void ff_avg_h264_qpel8_mc00_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc10_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc20_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc30_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc01_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc11_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc21_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc31_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc02_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc12_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc22_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc32_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc03_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc13_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc23_neon(uint8_t *, uint8_t *, int); -void ff_avg_h264_qpel8_mc33_neon(uint8_t *, uint8_t *, int); - -void ff_put_h264_chroma_mc8_neon(uint8_t *, uint8_t *, int, int, int, int); -void ff_put_h264_chroma_mc4_neon(uint8_t *, uint8_t *, int, int, int, int); -void ff_put_h264_chroma_mc2_neon(uint8_t *, uint8_t *, int, int, int, int); - -void ff_avg_h264_chroma_mc8_neon(uint8_t *, uint8_t *, int, int, int, int); -void ff_avg_h264_chroma_mc4_neon(uint8_t *, uint8_t *, int, int, int, int); -void ff_avg_h264_chroma_mc2_neon(uint8_t *, uint8_t *, int, int, int, int); - -void ff_vector_fmul_window_neon(float *dst, const float *src0, - const float *src1, const float *win, int len); -void ff_butterflies_float_neon(float *v1, float *v2, int len); -float ff_scalarproduct_float_neon(const float *v1, const float *v2, int len); -void ff_vector_fmul_reverse_neon(float *dst, const float *src0, - const float *src1, int len); -void ff_vector_fmul_add_neon(float *dst, const float *src0, const float *src1, - const float *src2, int len); +void ff_simple_idct_neon(int16_t *data); +void ff_simple_idct_put_neon(uint8_t *dest, int line_size, int16_t *data); +void ff_simple_idct_add_neon(uint8_t *dest, int line_size, int16_t *data); + +void ff_clear_block_neon(int16_t *block); +void ff_clear_blocks_neon(int16_t *blocks); + +void ff_put_pixels16_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels16_x2_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels16_y2_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels16_xy2_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels8_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels8_x2_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels8_y2_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels8_xy2_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels16_x2_no_rnd_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels16_y2_no_rnd_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels16_xy2_no_rnd_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels8_x2_no_rnd_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels8_y2_no_rnd_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_put_pixels8_xy2_no_rnd_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); + +void ff_avg_pixels16_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_avg_pixels16_x2_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_avg_pixels16_y2_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_avg_pixels16_xy2_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_avg_pixels8_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_avg_pixels8_x2_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_avg_pixels8_y2_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_avg_pixels8_xy2_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_avg_pixels16_x2_no_rnd_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_avg_pixels16_y2_no_rnd_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); +void ff_avg_pixels16_xy2_no_rnd_neon(uint8_t *, const uint8_t *, ptrdiff_t, int); + +void ff_add_pixels_clamped_neon(const int16_t *, uint8_t *, int); +void ff_put_pixels_clamped_neon(const int16_t *, uint8_t *, int); +void ff_put_signed_pixels_clamped_neon(const int16_t *, uint8_t *, int); void ff_vector_clipf_neon(float *dst, const float *src, float min, float max, int len); void ff_vector_clip_int32_neon(int32_t *dst, const int32_t *src, int32_t min, int32_t max, unsigned int len); -void ff_vorbis_inverse_coupling_neon(float *mag, float *ang, int blocksize); - int32_t ff_scalarproduct_int16_neon(const int16_t *v1, const int16_t *v2, int len); int32_t ff_scalarproduct_and_madd_int16_neon(int16_t *v1, const int16_t *v2, const int16_t *v3, int len, int mul); @@ -165,7 +75,7 @@ int32_t ff_scalarproduct_and_madd_int16_neon(int16_t *v1, const int16_t *v2, void ff_apply_window_int16_neon(int16_t *dst, const int16_t *src, const int16_t *window, unsigned n); -void ff_dsputil_init_neon(DSPContext *c, AVCodecContext *avctx) +av_cold void ff_dsputil_init_neon(DSPContext *c, AVCodecContext *avctx) { const int high_bit_depth = avctx->bits_per_raw_sample > 8; @@ -210,109 +120,19 @@ void ff_dsputil_init_neon(DSPContext *c, AVCodecContext *avctx) c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_neon; c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_neon; - c->avg_no_rnd_pixels_tab[0][0] = ff_avg_pixels16_neon; - c->avg_no_rnd_pixels_tab[0][1] = ff_avg_pixels16_x2_no_rnd_neon; - c->avg_no_rnd_pixels_tab[0][2] = ff_avg_pixels16_y2_no_rnd_neon; - c->avg_no_rnd_pixels_tab[0][3] = ff_avg_pixels16_xy2_no_rnd_neon; - c->avg_no_rnd_pixels_tab[1][0] = ff_avg_pixels8_neon; - c->avg_no_rnd_pixels_tab[1][1] = ff_avg_pixels8_x2_no_rnd_neon; - c->avg_no_rnd_pixels_tab[1][2] = ff_avg_pixels8_y2_no_rnd_neon; - c->avg_no_rnd_pixels_tab[1][3] = ff_avg_pixels8_xy2_no_rnd_neon; + c->avg_no_rnd_pixels_tab[0] = ff_avg_pixels16_neon; + c->avg_no_rnd_pixels_tab[1] = ff_avg_pixels16_x2_no_rnd_neon; + c->avg_no_rnd_pixels_tab[2] = ff_avg_pixels16_y2_no_rnd_neon; + c->avg_no_rnd_pixels_tab[3] = ff_avg_pixels16_xy2_no_rnd_neon; } c->add_pixels_clamped = ff_add_pixels_clamped_neon; c->put_pixels_clamped = ff_put_pixels_clamped_neon; c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_neon; - if (CONFIG_H264_DECODER && !high_bit_depth) { - c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_neon; - c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_neon; - c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_neon; - - c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_neon; - c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_neon; - c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_neon; - - c->put_h264_qpel_pixels_tab[0][ 0] = ff_put_h264_qpel16_mc00_neon; - c->put_h264_qpel_pixels_tab[0][ 1] = ff_put_h264_qpel16_mc10_neon; - c->put_h264_qpel_pixels_tab[0][ 2] = ff_put_h264_qpel16_mc20_neon; - c->put_h264_qpel_pixels_tab[0][ 3] = ff_put_h264_qpel16_mc30_neon; - c->put_h264_qpel_pixels_tab[0][ 4] = ff_put_h264_qpel16_mc01_neon; - c->put_h264_qpel_pixels_tab[0][ 5] = ff_put_h264_qpel16_mc11_neon; - c->put_h264_qpel_pixels_tab[0][ 6] = ff_put_h264_qpel16_mc21_neon; - c->put_h264_qpel_pixels_tab[0][ 7] = ff_put_h264_qpel16_mc31_neon; - c->put_h264_qpel_pixels_tab[0][ 8] = ff_put_h264_qpel16_mc02_neon; - c->put_h264_qpel_pixels_tab[0][ 9] = ff_put_h264_qpel16_mc12_neon; - c->put_h264_qpel_pixels_tab[0][10] = ff_put_h264_qpel16_mc22_neon; - c->put_h264_qpel_pixels_tab[0][11] = ff_put_h264_qpel16_mc32_neon; - c->put_h264_qpel_pixels_tab[0][12] = ff_put_h264_qpel16_mc03_neon; - c->put_h264_qpel_pixels_tab[0][13] = ff_put_h264_qpel16_mc13_neon; - c->put_h264_qpel_pixels_tab[0][14] = ff_put_h264_qpel16_mc23_neon; - c->put_h264_qpel_pixels_tab[0][15] = ff_put_h264_qpel16_mc33_neon; - - c->put_h264_qpel_pixels_tab[1][ 0] = ff_put_h264_qpel8_mc00_neon; - c->put_h264_qpel_pixels_tab[1][ 1] = ff_put_h264_qpel8_mc10_neon; - c->put_h264_qpel_pixels_tab[1][ 2] = ff_put_h264_qpel8_mc20_neon; - c->put_h264_qpel_pixels_tab[1][ 3] = ff_put_h264_qpel8_mc30_neon; - c->put_h264_qpel_pixels_tab[1][ 4] = ff_put_h264_qpel8_mc01_neon; - c->put_h264_qpel_pixels_tab[1][ 5] = ff_put_h264_qpel8_mc11_neon; - c->put_h264_qpel_pixels_tab[1][ 6] = ff_put_h264_qpel8_mc21_neon; - c->put_h264_qpel_pixels_tab[1][ 7] = ff_put_h264_qpel8_mc31_neon; - c->put_h264_qpel_pixels_tab[1][ 8] = ff_put_h264_qpel8_mc02_neon; - c->put_h264_qpel_pixels_tab[1][ 9] = ff_put_h264_qpel8_mc12_neon; - c->put_h264_qpel_pixels_tab[1][10] = ff_put_h264_qpel8_mc22_neon; - c->put_h264_qpel_pixels_tab[1][11] = ff_put_h264_qpel8_mc32_neon; - c->put_h264_qpel_pixels_tab[1][12] = ff_put_h264_qpel8_mc03_neon; - c->put_h264_qpel_pixels_tab[1][13] = ff_put_h264_qpel8_mc13_neon; - c->put_h264_qpel_pixels_tab[1][14] = ff_put_h264_qpel8_mc23_neon; - c->put_h264_qpel_pixels_tab[1][15] = ff_put_h264_qpel8_mc33_neon; - - c->avg_h264_qpel_pixels_tab[0][ 0] = ff_avg_h264_qpel16_mc00_neon; - c->avg_h264_qpel_pixels_tab[0][ 1] = ff_avg_h264_qpel16_mc10_neon; - c->avg_h264_qpel_pixels_tab[0][ 2] = ff_avg_h264_qpel16_mc20_neon; - c->avg_h264_qpel_pixels_tab[0][ 3] = ff_avg_h264_qpel16_mc30_neon; - c->avg_h264_qpel_pixels_tab[0][ 4] = ff_avg_h264_qpel16_mc01_neon; - c->avg_h264_qpel_pixels_tab[0][ 5] = ff_avg_h264_qpel16_mc11_neon; - c->avg_h264_qpel_pixels_tab[0][ 6] = ff_avg_h264_qpel16_mc21_neon; - c->avg_h264_qpel_pixels_tab[0][ 7] = ff_avg_h264_qpel16_mc31_neon; - c->avg_h264_qpel_pixels_tab[0][ 8] = ff_avg_h264_qpel16_mc02_neon; - c->avg_h264_qpel_pixels_tab[0][ 9] = ff_avg_h264_qpel16_mc12_neon; - c->avg_h264_qpel_pixels_tab[0][10] = ff_avg_h264_qpel16_mc22_neon; - c->avg_h264_qpel_pixels_tab[0][11] = ff_avg_h264_qpel16_mc32_neon; - c->avg_h264_qpel_pixels_tab[0][12] = ff_avg_h264_qpel16_mc03_neon; - c->avg_h264_qpel_pixels_tab[0][13] = ff_avg_h264_qpel16_mc13_neon; - c->avg_h264_qpel_pixels_tab[0][14] = ff_avg_h264_qpel16_mc23_neon; - c->avg_h264_qpel_pixels_tab[0][15] = ff_avg_h264_qpel16_mc33_neon; - - c->avg_h264_qpel_pixels_tab[1][ 0] = ff_avg_h264_qpel8_mc00_neon; - c->avg_h264_qpel_pixels_tab[1][ 1] = ff_avg_h264_qpel8_mc10_neon; - c->avg_h264_qpel_pixels_tab[1][ 2] = ff_avg_h264_qpel8_mc20_neon; - c->avg_h264_qpel_pixels_tab[1][ 3] = ff_avg_h264_qpel8_mc30_neon; - c->avg_h264_qpel_pixels_tab[1][ 4] = ff_avg_h264_qpel8_mc01_neon; - c->avg_h264_qpel_pixels_tab[1][ 5] = ff_avg_h264_qpel8_mc11_neon; - c->avg_h264_qpel_pixels_tab[1][ 6] = ff_avg_h264_qpel8_mc21_neon; - c->avg_h264_qpel_pixels_tab[1][ 7] = ff_avg_h264_qpel8_mc31_neon; - c->avg_h264_qpel_pixels_tab[1][ 8] = ff_avg_h264_qpel8_mc02_neon; - c->avg_h264_qpel_pixels_tab[1][ 9] = ff_avg_h264_qpel8_mc12_neon; - c->avg_h264_qpel_pixels_tab[1][10] = ff_avg_h264_qpel8_mc22_neon; - c->avg_h264_qpel_pixels_tab[1][11] = ff_avg_h264_qpel8_mc32_neon; - c->avg_h264_qpel_pixels_tab[1][12] = ff_avg_h264_qpel8_mc03_neon; - c->avg_h264_qpel_pixels_tab[1][13] = ff_avg_h264_qpel8_mc13_neon; - c->avg_h264_qpel_pixels_tab[1][14] = ff_avg_h264_qpel8_mc23_neon; - c->avg_h264_qpel_pixels_tab[1][15] = ff_avg_h264_qpel8_mc33_neon; - } - - c->vector_fmul_window = ff_vector_fmul_window_neon; - c->butterflies_float = ff_butterflies_float_neon; - c->scalarproduct_float = ff_scalarproduct_float_neon; - c->vector_fmul_reverse = ff_vector_fmul_reverse_neon; - c->vector_fmul_add = ff_vector_fmul_add_neon; c->vector_clipf = ff_vector_clipf_neon; c->vector_clip_int32 = ff_vector_clip_int32_neon; - if (CONFIG_VORBIS_DECODER) - c->vorbis_inverse_coupling = ff_vorbis_inverse_coupling_neon; - c->scalarproduct_int16 = ff_scalarproduct_int16_neon; c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_neon; diff --git a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_neon.S b/mythtv/external/FFmpeg/libavcodec/arm/dsputil_neon.S index 610a2bb57fd..89d364328d8 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_neon.S +++ b/mythtv/external/FFmpeg/libavcodec/arm/dsputil_neon.S @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "config.h" #include "libavutil/arm/asm.S" function ff_clear_block_neon, export=1 @@ -422,9 +421,9 @@ function ff_avg_h264_qpel8_mc00_neon, export=1 endfunc pixfunc avg_, pixels8, avg=1 - pixfunc2 avg_, pixels8_x2, avg=1 - pixfunc2 avg_, pixels8_y2, avg=1 - pixfunc2 avg_, pixels8_xy2, avg=1 + pixfunc avg_, pixels8_x2, avg=1 + pixfunc avg_, pixels8_y2, avg=1 + pixfunc avg_, pixels8_xy2, avg=1 function ff_put_pixels_clamped_neon, export=1 vld1.16 {d16-d19}, [r0,:128]! @@ -532,192 +531,6 @@ function ff_add_pixels_clamped_neon, export=1 bx lr endfunc -function ff_vector_fmul_window_neon, export=1 - push {r4,r5,lr} - ldr lr, [sp, #12] - sub r2, r2, #8 - sub r5, lr, #2 - add r2, r2, r5, lsl #2 - add r4, r3, r5, lsl #3 - add ip, r0, r5, lsl #3 - mov r5, #-16 - vld1.32 {d0,d1}, [r1,:128]! - vld1.32 {d2,d3}, [r2,:128], r5 - vld1.32 {d4,d5}, [r3,:128]! - vld1.32 {d6,d7}, [r4,:128], r5 -1: subs lr, lr, #4 - vmul.f32 d22, d0, d4 - vrev64.32 q3, q3 - vmul.f32 d23, d1, d5 - vrev64.32 q1, q1 - vmul.f32 d20, d0, d7 - vmul.f32 d21, d1, d6 - beq 2f - vmla.f32 d22, d3, d7 - vld1.32 {d0,d1}, [r1,:128]! - vmla.f32 d23, d2, d6 - vld1.32 {d18,d19},[r2,:128], r5 - vmls.f32 d20, d3, d4 - vld1.32 {d24,d25},[r3,:128]! - vmls.f32 d21, d2, d5 - vld1.32 {d6,d7}, [r4,:128], r5 - vmov q1, q9 - vrev64.32 q11, q11 - vmov q2, q12 - vswp d22, d23 - vst1.32 {d20,d21},[r0,:128]! - vst1.32 {d22,d23},[ip,:128], r5 - b 1b -2: vmla.f32 d22, d3, d7 - vmla.f32 d23, d2, d6 - vmls.f32 d20, d3, d4 - vmls.f32 d21, d2, d5 - vrev64.32 q11, q11 - vswp d22, d23 - vst1.32 {d20,d21},[r0,:128]! - vst1.32 {d22,d23},[ip,:128], r5 - pop {r4,r5,pc} -endfunc - -#if CONFIG_VORBIS_DECODER -function ff_vorbis_inverse_coupling_neon, export=1 - vmov.i32 q10, #1<<31 - subs r2, r2, #4 - mov r3, r0 - mov r12, r1 - beq 3f - - vld1.32 {d24-d25},[r1,:128]! - vld1.32 {d22-d23},[r0,:128]! - vcle.s32 q8, q12, #0 - vand q9, q11, q10 - veor q12, q12, q9 - vand q2, q12, q8 - vbic q3, q12, q8 - vadd.f32 q12, q11, q2 - vsub.f32 q11, q11, q3 -1: vld1.32 {d2-d3}, [r1,:128]! - vld1.32 {d0-d1}, [r0,:128]! - vcle.s32 q8, q1, #0 - vand q9, q0, q10 - veor q1, q1, q9 - vst1.32 {d24-d25},[r3, :128]! - vst1.32 {d22-d23},[r12,:128]! - vand q2, q1, q8 - vbic q3, q1, q8 - vadd.f32 q1, q0, q2 - vsub.f32 q0, q0, q3 - subs r2, r2, #8 - ble 2f - vld1.32 {d24-d25},[r1,:128]! - vld1.32 {d22-d23},[r0,:128]! - vcle.s32 q8, q12, #0 - vand q9, q11, q10 - veor q12, q12, q9 - vst1.32 {d2-d3}, [r3, :128]! - vst1.32 {d0-d1}, [r12,:128]! - vand q2, q12, q8 - vbic q3, q12, q8 - vadd.f32 q12, q11, q2 - vsub.f32 q11, q11, q3 - b 1b - -2: vst1.32 {d2-d3}, [r3, :128]! - vst1.32 {d0-d1}, [r12,:128]! - it lt - bxlt lr - -3: vld1.32 {d2-d3}, [r1,:128] - vld1.32 {d0-d1}, [r0,:128] - vcle.s32 q8, q1, #0 - vand q9, q0, q10 - veor q1, q1, q9 - vand q2, q1, q8 - vbic q3, q1, q8 - vadd.f32 q1, q0, q2 - vsub.f32 q0, q0, q3 - vst1.32 {d2-d3}, [r0,:128]! - vst1.32 {d0-d1}, [r1,:128]! - bx lr -endfunc -#endif - -function ff_butterflies_float_neon, export=1 -1: vld1.32 {q0},[r0,:128] - vld1.32 {q1},[r1,:128] - vsub.f32 q2, q0, q1 - vadd.f32 q1, q0, q1 - vst1.32 {q2},[r1,:128]! - vst1.32 {q1},[r0,:128]! - subs r2, r2, #4 - bgt 1b - bx lr -endfunc - -function ff_scalarproduct_float_neon, export=1 - vmov.f32 q2, #0.0 -1: vld1.32 {q0},[r0,:128]! - vld1.32 {q1},[r1,:128]! - vmla.f32 q2, q0, q1 - subs r2, r2, #4 - bgt 1b - vadd.f32 d0, d4, d5 - vpadd.f32 d0, d0, d0 -NOVFP vmov.32 r0, d0[0] - bx lr -endfunc - -function ff_vector_fmul_reverse_neon, export=1 - add r2, r2, r3, lsl #2 - sub r2, r2, #32 - mov r12, #-32 - vld1.32 {q0-q1}, [r1,:128]! - vld1.32 {q2-q3}, [r2,:128], r12 -1: pld [r1, #32] - vrev64.32 q3, q3 - vmul.f32 d16, d0, d7 - vmul.f32 d17, d1, d6 - pld [r2, #-32] - vrev64.32 q2, q2 - vmul.f32 d18, d2, d5 - vmul.f32 d19, d3, d4 - subs r3, r3, #8 - beq 2f - vld1.32 {q0-q1}, [r1,:128]! - vld1.32 {q2-q3}, [r2,:128], r12 - vst1.32 {q8-q9}, [r0,:128]! - b 1b -2: vst1.32 {q8-q9}, [r0,:128]! - bx lr -endfunc - -function ff_vector_fmul_add_neon, export=1 - ldr r12, [sp] - vld1.32 {q0-q1}, [r1,:128]! - vld1.32 {q8-q9}, [r2,:128]! - vld1.32 {q2-q3}, [r3,:128]! - vmul.f32 q10, q0, q8 - vmul.f32 q11, q1, q9 -1: vadd.f32 q12, q2, q10 - vadd.f32 q13, q3, q11 - pld [r1, #16] - pld [r2, #16] - pld [r3, #16] - subs r12, r12, #8 - beq 2f - vld1.32 {q0}, [r1,:128]! - vld1.32 {q8}, [r2,:128]! - vmul.f32 q10, q0, q8 - vld1.32 {q1}, [r1,:128]! - vld1.32 {q9}, [r2,:128]! - vmul.f32 q11, q1, q9 - vld1.32 {q2-q3}, [r3,:128]! - vst1.32 {q12-q13},[r0,:128]! - b 1b -2: vst1.32 {q12-q13},[r0,:128]! - bx lr -endfunc - function ff_vector_clipf_neon, export=1 VFP vdup.32 q1, d0[1] VFP vdup.32 q0, d0[0] diff --git a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_vfp.S b/mythtv/external/FFmpeg/libavcodec/arm/dsputil_vfp.S deleted file mode 100644 index 63ba7668593..00000000000 --- a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_vfp.S +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2008 Siarhei Siamashka - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config.h" -#include "libavutil/arm/asm.S" - -/* - * VFP is a floating point coprocessor used in some ARM cores. VFP11 has 1 cycle - * throughput for almost all the instructions (except for double precision - * arithmetics), but rather high latency. Latency is 4 cycles for loads and 8 cycles - * for arithmetic operations. Scheduling code to avoid pipeline stalls is very - * important for performance. One more interesting feature is that VFP has - * independent load/store and arithmetics pipelines, so it is possible to make - * them work simultaneously and get more than 1 operation per cycle. Load/store - * pipeline can process 2 single precision floating point values per cycle and - * supports bulk loads and stores for large sets of registers. Arithmetic operations - * can be done on vectors, which allows to keep the arithmetics pipeline busy, - * while the processor may issue and execute other instructions. Detailed - * optimization manuals can be found at http://www.arm.com - */ - -/** - * ARM VFP optimized implementation of 'vector_fmul_reverse_c' function. - * Assume that len is a positive number and is multiple of 8 - */ -@ void ff_vector_fmul_reverse_vfp(float *dst, const float *src0, -@ const float *src1, int len) -function ff_vector_fmul_reverse_vfp, export=1 - vpush {d8-d15} - add r2, r2, r3, lsl #2 - vldmdb r2!, {s0-s3} - vldmia r1!, {s8-s11} - vldmdb r2!, {s4-s7} - vldmia r1!, {s12-s15} - vmul.f32 s8, s3, s8 - vmul.f32 s9, s2, s9 - vmul.f32 s10, s1, s10 - vmul.f32 s11, s0, s11 -1: - subs r3, r3, #16 - it ge - vldmdbge r2!, {s16-s19} - vmul.f32 s12, s7, s12 - it ge - vldmiage r1!, {s24-s27} - vmul.f32 s13, s6, s13 - it ge - vldmdbge r2!, {s20-s23} - vmul.f32 s14, s5, s14 - it ge - vldmiage r1!, {s28-s31} - vmul.f32 s15, s4, s15 - it ge - vmulge.f32 s24, s19, s24 - it gt - vldmdbgt r2!, {s0-s3} - it ge - vmulge.f32 s25, s18, s25 - vstmia r0!, {s8-s13} - it ge - vmulge.f32 s26, s17, s26 - it gt - vldmiagt r1!, {s8-s11} - itt ge - vmulge.f32 s27, s16, s27 - vmulge.f32 s28, s23, s28 - it gt - vldmdbgt r2!, {s4-s7} - it ge - vmulge.f32 s29, s22, s29 - vstmia r0!, {s14-s15} - ittt ge - vmulge.f32 s30, s21, s30 - vmulge.f32 s31, s20, s31 - vmulge.f32 s8, s3, s8 - it gt - vldmiagt r1!, {s12-s15} - itttt ge - vmulge.f32 s9, s2, s9 - vmulge.f32 s10, s1, s10 - vstmiage r0!, {s24-s27} - vmulge.f32 s11, s0, s11 - it ge - vstmiage r0!, {s28-s31} - bgt 1b - - vpop {d8-d15} - bx lr -endfunc diff --git a/mythtv/external/FFmpeg/libavcodec/arm/fft_fixed_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/fft_fixed_init_arm.c index 59b933e5a0c..ef098f4bf1c 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/fft_fixed_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/fft_fixed_init_arm.c @@ -33,7 +33,9 @@ av_cold void ff_fft_fixed_init_arm(FFTContext *s) if (have_neon(cpu_flags)) { s->fft_permutation = FF_FFT_PERM_SWAP_LSBS; +#if CONFIG_FFT s->fft_calc = ff_fft_fixed_calc_neon; +#endif #if CONFIG_MDCT if (!s->inverse && s->nbits >= 3) { diff --git a/mythtv/external/FFmpeg/libavcodec/arm/fft_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/fft_init_arm.c index 12d28a3efd2..8c98abcdf05 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/fft_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/fft_init_arm.c @@ -43,8 +43,10 @@ av_cold void ff_fft_init_arm(FFTContext *s) int cpu_flags = av_get_cpu_flags(); if (have_neon(cpu_flags)) { +#if CONFIG_FFT s->fft_permute = ff_fft_permute_neon; s->fft_calc = ff_fft_calc_neon; +#endif #if CONFIG_MDCT s->imdct_calc = ff_imdct_calc_neon; s->imdct_half = ff_imdct_half_neon; diff --git a/mythtv/external/FFmpeg/libavcodec/arm/fmtconvert_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/fmtconvert_init_arm.c index 5b3e3c1e98c..1d99c9720a8 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/fmtconvert_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/fmtconvert_init_arm.c @@ -20,6 +20,7 @@ #include +#include "libavutil/attributes.h" #include "libavutil/arm/cpu.h" #include "libavcodec/avcodec.h" #include "libavcodec/fmtconvert.h" @@ -32,7 +33,7 @@ void ff_float_to_int16_interleave_neon(int16_t *, const float **, long, int); void ff_float_to_int16_vfp(int16_t *dst, const float *src, long len); -void ff_fmt_convert_init_arm(FmtConvertContext *c, AVCodecContext *avctx) +av_cold void ff_fmt_convert_init_arm(FmtConvertContext *c, AVCodecContext *avctx) { int cpu_flags = av_get_cpu_flags(); diff --git a/mythtv/external/FFmpeg/libavcodec/arm/h264chroma_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/h264chroma_init_arm.c new file mode 100644 index 00000000000..13f7e0d7026 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/arm/h264chroma_init_arm.c @@ -0,0 +1,51 @@ +/* + * ARM NEON optimised H.264 chroma functions + * Copyright (c) 2008 Mans Rullgard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/attributes.h" +#include "libavutil/cpu.h" +#include "libavutil/arm/cpu.h" +#include "libavcodec/h264chroma.h" + +void ff_put_h264_chroma_mc8_neon(uint8_t *, uint8_t *, int, int, int, int); +void ff_put_h264_chroma_mc4_neon(uint8_t *, uint8_t *, int, int, int, int); +void ff_put_h264_chroma_mc2_neon(uint8_t *, uint8_t *, int, int, int, int); + +void ff_avg_h264_chroma_mc8_neon(uint8_t *, uint8_t *, int, int, int, int); +void ff_avg_h264_chroma_mc4_neon(uint8_t *, uint8_t *, int, int, int, int); +void ff_avg_h264_chroma_mc2_neon(uint8_t *, uint8_t *, int, int, int, int); + +av_cold void ff_h264chroma_init_arm(H264ChromaContext *c, int bit_depth) +{ + const int high_bit_depth = bit_depth > 8; + int cpu_flags = av_get_cpu_flags(); + + if (have_neon(cpu_flags) && !high_bit_depth) { + c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_neon; + c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_neon; + c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_neon; + + c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_neon; + c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_neon; + c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_neon; + } +} diff --git a/mythtv/external/FFmpeg/libavcodec/arm/h264dsp_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/h264dsp_init_arm.c index f150a4508d1..785b6047495 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/h264dsp_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/h264dsp_init_arm.c @@ -20,8 +20,8 @@ #include +#include "libavutil/attributes.h" #include "libavutil/arm/cpu.h" -#include "libavcodec/dsputil.h" #include "libavcodec/h264dsp.h" void ff_h264_v_loop_filter_luma_neon(uint8_t *pix, int stride, int alpha, @@ -50,25 +50,26 @@ void ff_biweight_h264_pixels_4_neon(uint8_t *dst, uint8_t *src, int stride, int height, int log2_den, int weightd, int weights, int offset); -void ff_h264_idct_add_neon(uint8_t *dst, DCTELEM *block, int stride); -void ff_h264_idct_dc_add_neon(uint8_t *dst, DCTELEM *block, int stride); +void ff_h264_idct_add_neon(uint8_t *dst, int16_t *block, int stride); +void ff_h264_idct_dc_add_neon(uint8_t *dst, int16_t *block, int stride); void ff_h264_idct_add16_neon(uint8_t *dst, const int *block_offset, - DCTELEM *block, int stride, + int16_t *block, int stride, const uint8_t nnzc[6*8]); void ff_h264_idct_add16intra_neon(uint8_t *dst, const int *block_offset, - DCTELEM *block, int stride, + int16_t *block, int stride, const uint8_t nnzc[6*8]); void ff_h264_idct_add8_neon(uint8_t **dest, const int *block_offset, - DCTELEM *block, int stride, + int16_t *block, int stride, const uint8_t nnzc[6*8]); -void ff_h264_idct8_add_neon(uint8_t *dst, DCTELEM *block, int stride); -void ff_h264_idct8_dc_add_neon(uint8_t *dst, DCTELEM *block, int stride); +void ff_h264_idct8_add_neon(uint8_t *dst, int16_t *block, int stride); +void ff_h264_idct8_dc_add_neon(uint8_t *dst, int16_t *block, int stride); void ff_h264_idct8_add4_neon(uint8_t *dst, const int *block_offset, - DCTELEM *block, int stride, + int16_t *block, int stride, const uint8_t nnzc[6*8]); -static void ff_h264dsp_init_neon(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) +static av_cold void ff_h264dsp_init_neon(H264DSPContext *c, const int bit_depth, + const int chroma_format_idc) { #if HAVE_NEON if (bit_depth == 8) { @@ -100,7 +101,8 @@ static void ff_h264dsp_init_neon(H264DSPContext *c, const int bit_depth, const i #endif // HAVE_NEON } -void ff_h264dsp_init_arm(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) +av_cold void ff_h264dsp_init_arm(H264DSPContext *c, const int bit_depth, + const int chroma_format_idc) { int cpu_flags = av_get_cpu_flags(); diff --git a/mythtv/external/FFmpeg/libavcodec/arm/h264dsp_neon.S b/mythtv/external/FFmpeg/libavcodec/arm/h264dsp_neon.S index be0d2ec0bb8..274a547f268 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/h264dsp_neon.S +++ b/mythtv/external/FFmpeg/libavcodec/arm/h264dsp_neon.S @@ -271,939 +271,6 @@ function ff_h264_h_loop_filter_chroma_neon, export=1 bx lr endfunc - /* H.264 qpel MC */ - -.macro lowpass_const r - movw \r, #5 - movt \r, #20 - vmov.32 d6[0], \r -.endm - -.macro lowpass_8 r0, r1, r2, r3, d0, d1, narrow=1 - .if \narrow - t0 .req q0 - t1 .req q8 - .else - t0 .req \d0 - t1 .req \d1 - .endif - vext.8 d2, \r0, \r1, #2 - vext.8 d3, \r0, \r1, #3 - vaddl.u8 q1, d2, d3 - vext.8 d4, \r0, \r1, #1 - vext.8 d5, \r0, \r1, #4 - vaddl.u8 q2, d4, d5 - vext.8 d30, \r0, \r1, #5 - vaddl.u8 t0, \r0, d30 - vext.8 d18, \r2, \r3, #2 - vmla.i16 t0, q1, d6[1] - vext.8 d19, \r2, \r3, #3 - vaddl.u8 q9, d18, d19 - vext.8 d20, \r2, \r3, #1 - vmls.i16 t0, q2, d6[0] - vext.8 d21, \r2, \r3, #4 - vaddl.u8 q10, d20, d21 - vext.8 d31, \r2, \r3, #5 - vaddl.u8 t1, \r2, d31 - vmla.i16 t1, q9, d6[1] - vmls.i16 t1, q10, d6[0] - .if \narrow - vqrshrun.s16 \d0, t0, #5 - vqrshrun.s16 \d1, t1, #5 - .endif - .unreq t0 - .unreq t1 -.endm - -.macro lowpass_8_1 r0, r1, d0, narrow=1 - .if \narrow - t0 .req q0 - .else - t0 .req \d0 - .endif - vext.8 d2, \r0, \r1, #2 - vext.8 d3, \r0, \r1, #3 - vaddl.u8 q1, d2, d3 - vext.8 d4, \r0, \r1, #1 - vext.8 d5, \r0, \r1, #4 - vaddl.u8 q2, d4, d5 - vext.8 d30, \r0, \r1, #5 - vaddl.u8 t0, \r0, d30 - vmla.i16 t0, q1, d6[1] - vmls.i16 t0, q2, d6[0] - .if \narrow - vqrshrun.s16 \d0, t0, #5 - .endif - .unreq t0 -.endm - -.macro lowpass_8.16 r0, r1, l0, h0, l1, h1, d - vext.16 q1, \r0, \r1, #2 - vext.16 q0, \r0, \r1, #3 - vaddl.s16 q9, d2, d0 - vext.16 q2, \r0, \r1, #1 - vaddl.s16 q1, d3, d1 - vext.16 q3, \r0, \r1, #4 - vaddl.s16 q10, d4, d6 - vext.16 \r1, \r0, \r1, #5 - vaddl.s16 q2, d5, d7 - vaddl.s16 q0, \h0, \h1 - vaddl.s16 q8, \l0, \l1 - - vshl.i32 q3, q9, #4 - vshl.i32 q9, q9, #2 - vshl.i32 q15, q10, #2 - vadd.i32 q9, q9, q3 - vadd.i32 q10, q10, q15 - - vshl.i32 q3, q1, #4 - vshl.i32 q1, q1, #2 - vshl.i32 q15, q2, #2 - vadd.i32 q1, q1, q3 - vadd.i32 q2, q2, q15 - - vadd.i32 q9, q9, q8 - vsub.i32 q9, q9, q10 - - vadd.i32 q1, q1, q0 - vsub.i32 q1, q1, q2 - - vrshrn.s32 d18, q9, #10 - vrshrn.s32 d19, q1, #10 - - vqmovun.s16 \d, q9 -.endm - -function put_h264_qpel16_h_lowpass_neon_packed - mov r4, lr - mov r12, #16 - mov r3, #8 - bl put_h264_qpel8_h_lowpass_neon - sub r1, r1, r2, lsl #4 - add r1, r1, #8 - mov r12, #16 - mov lr, r4 - b put_h264_qpel8_h_lowpass_neon -endfunc - -.macro h264_qpel_h_lowpass type -function \type\()_h264_qpel16_h_lowpass_neon - push {lr} - mov r12, #16 - bl \type\()_h264_qpel8_h_lowpass_neon - sub r0, r0, r3, lsl #4 - sub r1, r1, r2, lsl #4 - add r0, r0, #8 - add r1, r1, #8 - mov r12, #16 - pop {lr} -endfunc - -function \type\()_h264_qpel8_h_lowpass_neon -1: vld1.8 {d0, d1}, [r1], r2 - vld1.8 {d16,d17}, [r1], r2 - subs r12, r12, #2 - lowpass_8 d0, d1, d16, d17, d0, d16 - .ifc \type,avg - vld1.8 {d2}, [r0,:64], r3 - vrhadd.u8 d0, d0, d2 - vld1.8 {d3}, [r0,:64] - vrhadd.u8 d16, d16, d3 - sub r0, r0, r3 - .endif - vst1.8 {d0}, [r0,:64], r3 - vst1.8 {d16}, [r0,:64], r3 - bne 1b - bx lr -endfunc -.endm - - h264_qpel_h_lowpass put - h264_qpel_h_lowpass avg - -.macro h264_qpel_h_lowpass_l2 type -function \type\()_h264_qpel16_h_lowpass_l2_neon - push {lr} - mov r12, #16 - bl \type\()_h264_qpel8_h_lowpass_l2_neon - sub r0, r0, r2, lsl #4 - sub r1, r1, r2, lsl #4 - sub r3, r3, r2, lsl #4 - add r0, r0, #8 - add r1, r1, #8 - add r3, r3, #8 - mov r12, #16 - pop {lr} -endfunc - -function \type\()_h264_qpel8_h_lowpass_l2_neon -1: vld1.8 {d0, d1}, [r1], r2 - vld1.8 {d16,d17}, [r1], r2 - vld1.8 {d28}, [r3], r2 - vld1.8 {d29}, [r3], r2 - subs r12, r12, #2 - lowpass_8 d0, d1, d16, d17, d0, d1 - vrhadd.u8 q0, q0, q14 - .ifc \type,avg - vld1.8 {d2}, [r0,:64], r2 - vrhadd.u8 d0, d0, d2 - vld1.8 {d3}, [r0,:64] - vrhadd.u8 d1, d1, d3 - sub r0, r0, r2 - .endif - vst1.8 {d0}, [r0,:64], r2 - vst1.8 {d1}, [r0,:64], r2 - bne 1b - bx lr -endfunc -.endm - - h264_qpel_h_lowpass_l2 put - h264_qpel_h_lowpass_l2 avg - -function put_h264_qpel16_v_lowpass_neon_packed - mov r4, lr - mov r2, #8 - bl put_h264_qpel8_v_lowpass_neon - sub r1, r1, r3, lsl #2 - bl put_h264_qpel8_v_lowpass_neon - sub r1, r1, r3, lsl #4 - sub r1, r1, r3, lsl #2 - add r1, r1, #8 - bl put_h264_qpel8_v_lowpass_neon - sub r1, r1, r3, lsl #2 - mov lr, r4 - b put_h264_qpel8_v_lowpass_neon -endfunc - -.macro h264_qpel_v_lowpass type -function \type\()_h264_qpel16_v_lowpass_neon - mov r4, lr - bl \type\()_h264_qpel8_v_lowpass_neon - sub r1, r1, r3, lsl #2 - bl \type\()_h264_qpel8_v_lowpass_neon - sub r0, r0, r2, lsl #4 - add r0, r0, #8 - sub r1, r1, r3, lsl #4 - sub r1, r1, r3, lsl #2 - add r1, r1, #8 - bl \type\()_h264_qpel8_v_lowpass_neon - sub r1, r1, r3, lsl #2 - mov lr, r4 -endfunc - -function \type\()_h264_qpel8_v_lowpass_neon - vld1.8 {d8}, [r1], r3 - vld1.8 {d10}, [r1], r3 - vld1.8 {d12}, [r1], r3 - vld1.8 {d14}, [r1], r3 - vld1.8 {d22}, [r1], r3 - vld1.8 {d24}, [r1], r3 - vld1.8 {d26}, [r1], r3 - vld1.8 {d28}, [r1], r3 - vld1.8 {d9}, [r1], r3 - vld1.8 {d11}, [r1], r3 - vld1.8 {d13}, [r1], r3 - vld1.8 {d15}, [r1], r3 - vld1.8 {d23}, [r1] - - transpose_8x8 q4, q5, q6, q7, q11, q12, q13, q14 - lowpass_8 d8, d9, d10, d11, d8, d10 - lowpass_8 d12, d13, d14, d15, d12, d14 - lowpass_8 d22, d23, d24, d25, d22, d24 - lowpass_8 d26, d27, d28, d29, d26, d28 - transpose_8x8 d8, d10, d12, d14, d22, d24, d26, d28 - - .ifc \type,avg - vld1.8 {d9}, [r0,:64], r2 - vrhadd.u8 d8, d8, d9 - vld1.8 {d11}, [r0,:64], r2 - vrhadd.u8 d10, d10, d11 - vld1.8 {d13}, [r0,:64], r2 - vrhadd.u8 d12, d12, d13 - vld1.8 {d15}, [r0,:64], r2 - vrhadd.u8 d14, d14, d15 - vld1.8 {d23}, [r0,:64], r2 - vrhadd.u8 d22, d22, d23 - vld1.8 {d25}, [r0,:64], r2 - vrhadd.u8 d24, d24, d25 - vld1.8 {d27}, [r0,:64], r2 - vrhadd.u8 d26, d26, d27 - vld1.8 {d29}, [r0,:64], r2 - vrhadd.u8 d28, d28, d29 - sub r0, r0, r2, lsl #3 - .endif - - vst1.8 {d8}, [r0,:64], r2 - vst1.8 {d10}, [r0,:64], r2 - vst1.8 {d12}, [r0,:64], r2 - vst1.8 {d14}, [r0,:64], r2 - vst1.8 {d22}, [r0,:64], r2 - vst1.8 {d24}, [r0,:64], r2 - vst1.8 {d26}, [r0,:64], r2 - vst1.8 {d28}, [r0,:64], r2 - - bx lr -endfunc -.endm - - h264_qpel_v_lowpass put - h264_qpel_v_lowpass avg - -.macro h264_qpel_v_lowpass_l2 type -function \type\()_h264_qpel16_v_lowpass_l2_neon - mov r4, lr - bl \type\()_h264_qpel8_v_lowpass_l2_neon - sub r1, r1, r3, lsl #2 - bl \type\()_h264_qpel8_v_lowpass_l2_neon - sub r0, r0, r3, lsl #4 - sub r12, r12, r2, lsl #4 - add r0, r0, #8 - add r12, r12, #8 - sub r1, r1, r3, lsl #4 - sub r1, r1, r3, lsl #2 - add r1, r1, #8 - bl \type\()_h264_qpel8_v_lowpass_l2_neon - sub r1, r1, r3, lsl #2 - mov lr, r4 -endfunc - -function \type\()_h264_qpel8_v_lowpass_l2_neon - vld1.8 {d8}, [r1], r3 - vld1.8 {d10}, [r1], r3 - vld1.8 {d12}, [r1], r3 - vld1.8 {d14}, [r1], r3 - vld1.8 {d22}, [r1], r3 - vld1.8 {d24}, [r1], r3 - vld1.8 {d26}, [r1], r3 - vld1.8 {d28}, [r1], r3 - vld1.8 {d9}, [r1], r3 - vld1.8 {d11}, [r1], r3 - vld1.8 {d13}, [r1], r3 - vld1.8 {d15}, [r1], r3 - vld1.8 {d23}, [r1] - - transpose_8x8 q4, q5, q6, q7, q11, q12, q13, q14 - lowpass_8 d8, d9, d10, d11, d8, d9 - lowpass_8 d12, d13, d14, d15, d12, d13 - lowpass_8 d22, d23, d24, d25, d22, d23 - lowpass_8 d26, d27, d28, d29, d26, d27 - transpose_8x8 d8, d9, d12, d13, d22, d23, d26, d27 - - vld1.8 {d0}, [r12], r2 - vld1.8 {d1}, [r12], r2 - vld1.8 {d2}, [r12], r2 - vld1.8 {d3}, [r12], r2 - vld1.8 {d4}, [r12], r2 - vrhadd.u8 q0, q0, q4 - vld1.8 {d5}, [r12], r2 - vrhadd.u8 q1, q1, q6 - vld1.8 {d10}, [r12], r2 - vrhadd.u8 q2, q2, q11 - vld1.8 {d11}, [r12], r2 - vrhadd.u8 q5, q5, q13 - - .ifc \type,avg - vld1.8 {d16}, [r0,:64], r3 - vrhadd.u8 d0, d0, d16 - vld1.8 {d17}, [r0,:64], r3 - vrhadd.u8 d1, d1, d17 - vld1.8 {d16}, [r0,:64], r3 - vrhadd.u8 d2, d2, d16 - vld1.8 {d17}, [r0,:64], r3 - vrhadd.u8 d3, d3, d17 - vld1.8 {d16}, [r0,:64], r3 - vrhadd.u8 d4, d4, d16 - vld1.8 {d17}, [r0,:64], r3 - vrhadd.u8 d5, d5, d17 - vld1.8 {d16}, [r0,:64], r3 - vrhadd.u8 d10, d10, d16 - vld1.8 {d17}, [r0,:64], r3 - vrhadd.u8 d11, d11, d17 - sub r0, r0, r3, lsl #3 - .endif - - vst1.8 {d0}, [r0,:64], r3 - vst1.8 {d1}, [r0,:64], r3 - vst1.8 {d2}, [r0,:64], r3 - vst1.8 {d3}, [r0,:64], r3 - vst1.8 {d4}, [r0,:64], r3 - vst1.8 {d5}, [r0,:64], r3 - vst1.8 {d10}, [r0,:64], r3 - vst1.8 {d11}, [r0,:64], r3 - - bx lr -endfunc -.endm - - h264_qpel_v_lowpass_l2 put - h264_qpel_v_lowpass_l2 avg - -function put_h264_qpel8_hv_lowpass_neon_top - lowpass_const r12 - mov r12, #12 -1: vld1.8 {d0, d1}, [r1], r3 - vld1.8 {d16,d17}, [r1], r3 - subs r12, r12, #2 - lowpass_8 d0, d1, d16, d17, q11, q12, narrow=0 - vst1.8 {d22-d25}, [r4,:128]! - bne 1b - - vld1.8 {d0, d1}, [r1] - lowpass_8_1 d0, d1, q12, narrow=0 - - mov r12, #-16 - add r4, r4, r12 - vld1.8 {d30,d31}, [r4,:128], r12 - vld1.8 {d20,d21}, [r4,:128], r12 - vld1.8 {d18,d19}, [r4,:128], r12 - vld1.8 {d16,d17}, [r4,:128], r12 - vld1.8 {d14,d15}, [r4,:128], r12 - vld1.8 {d12,d13}, [r4,:128], r12 - vld1.8 {d10,d11}, [r4,:128], r12 - vld1.8 {d8, d9}, [r4,:128], r12 - vld1.8 {d6, d7}, [r4,:128], r12 - vld1.8 {d4, d5}, [r4,:128], r12 - vld1.8 {d2, d3}, [r4,:128], r12 - vld1.8 {d0, d1}, [r4,:128] - - swap4 d1, d3, d5, d7, d8, d10, d12, d14 - transpose16_4x4 q0, q1, q2, q3, q4, q5, q6, q7 - - swap4 d17, d19, d21, d31, d24, d26, d28, d22 - transpose16_4x4 q8, q9, q10, q15, q12, q13, q14, q11 - - vst1.8 {d30,d31}, [r4,:128]! - vst1.8 {d6, d7}, [r4,:128]! - vst1.8 {d20,d21}, [r4,:128]! - vst1.8 {d4, d5}, [r4,:128]! - vst1.8 {d18,d19}, [r4,:128]! - vst1.8 {d2, d3}, [r4,:128]! - vst1.8 {d16,d17}, [r4,:128]! - vst1.8 {d0, d1}, [r4,:128] - - lowpass_8.16 q4, q12, d8, d9, d24, d25, d8 - lowpass_8.16 q5, q13, d10, d11, d26, d27, d9 - lowpass_8.16 q6, q14, d12, d13, d28, d29, d10 - lowpass_8.16 q7, q11, d14, d15, d22, d23, d11 - - vld1.8 {d16,d17}, [r4,:128], r12 - vld1.8 {d30,d31}, [r4,:128], r12 - lowpass_8.16 q8, q15, d16, d17, d30, d31, d12 - vld1.8 {d16,d17}, [r4,:128], r12 - vld1.8 {d30,d31}, [r4,:128], r12 - lowpass_8.16 q8, q15, d16, d17, d30, d31, d13 - vld1.8 {d16,d17}, [r4,:128], r12 - vld1.8 {d30,d31}, [r4,:128], r12 - lowpass_8.16 q8, q15, d16, d17, d30, d31, d14 - vld1.8 {d16,d17}, [r4,:128], r12 - vld1.8 {d30,d31}, [r4,:128] - lowpass_8.16 q8, q15, d16, d17, d30, d31, d15 - - transpose_8x8 d12, d13, d14, d15, d8, d9, d10, d11 - - bx lr -endfunc - -.macro h264_qpel8_hv_lowpass type -function \type\()_h264_qpel8_hv_lowpass_neon - mov r10, lr - bl put_h264_qpel8_hv_lowpass_neon_top - .ifc \type,avg - vld1.8 {d0}, [r0,:64], r2 - vrhadd.u8 d12, d12, d0 - vld1.8 {d1}, [r0,:64], r2 - vrhadd.u8 d13, d13, d1 - vld1.8 {d2}, [r0,:64], r2 - vrhadd.u8 d14, d14, d2 - vld1.8 {d3}, [r0,:64], r2 - vrhadd.u8 d15, d15, d3 - vld1.8 {d4}, [r0,:64], r2 - vrhadd.u8 d8, d8, d4 - vld1.8 {d5}, [r0,:64], r2 - vrhadd.u8 d9, d9, d5 - vld1.8 {d6}, [r0,:64], r2 - vrhadd.u8 d10, d10, d6 - vld1.8 {d7}, [r0,:64], r2 - vrhadd.u8 d11, d11, d7 - sub r0, r0, r2, lsl #3 - .endif - - vst1.8 {d12}, [r0,:64], r2 - vst1.8 {d13}, [r0,:64], r2 - vst1.8 {d14}, [r0,:64], r2 - vst1.8 {d15}, [r0,:64], r2 - vst1.8 {d8}, [r0,:64], r2 - vst1.8 {d9}, [r0,:64], r2 - vst1.8 {d10}, [r0,:64], r2 - vst1.8 {d11}, [r0,:64], r2 - - mov lr, r10 - bx lr -endfunc -.endm - - h264_qpel8_hv_lowpass put - h264_qpel8_hv_lowpass avg - -.macro h264_qpel8_hv_lowpass_l2 type -function \type\()_h264_qpel8_hv_lowpass_l2_neon - mov r10, lr - bl put_h264_qpel8_hv_lowpass_neon_top - - vld1.8 {d0, d1}, [r2,:128]! - vld1.8 {d2, d3}, [r2,:128]! - vrhadd.u8 q0, q0, q6 - vld1.8 {d4, d5}, [r2,:128]! - vrhadd.u8 q1, q1, q7 - vld1.8 {d6, d7}, [r2,:128]! - vrhadd.u8 q2, q2, q4 - vrhadd.u8 q3, q3, q5 - .ifc \type,avg - vld1.8 {d16}, [r0,:64], r3 - vrhadd.u8 d0, d0, d16 - vld1.8 {d17}, [r0,:64], r3 - vrhadd.u8 d1, d1, d17 - vld1.8 {d18}, [r0,:64], r3 - vrhadd.u8 d2, d2, d18 - vld1.8 {d19}, [r0,:64], r3 - vrhadd.u8 d3, d3, d19 - vld1.8 {d20}, [r0,:64], r3 - vrhadd.u8 d4, d4, d20 - vld1.8 {d21}, [r0,:64], r3 - vrhadd.u8 d5, d5, d21 - vld1.8 {d22}, [r0,:64], r3 - vrhadd.u8 d6, d6, d22 - vld1.8 {d23}, [r0,:64], r3 - vrhadd.u8 d7, d7, d23 - sub r0, r0, r3, lsl #3 - .endif - vst1.8 {d0}, [r0,:64], r3 - vst1.8 {d1}, [r0,:64], r3 - vst1.8 {d2}, [r0,:64], r3 - vst1.8 {d3}, [r0,:64], r3 - vst1.8 {d4}, [r0,:64], r3 - vst1.8 {d5}, [r0,:64], r3 - vst1.8 {d6}, [r0,:64], r3 - vst1.8 {d7}, [r0,:64], r3 - - mov lr, r10 - bx lr -endfunc -.endm - - h264_qpel8_hv_lowpass_l2 put - h264_qpel8_hv_lowpass_l2 avg - -.macro h264_qpel16_hv type -function \type\()_h264_qpel16_hv_lowpass_neon - mov r9, lr - bl \type\()_h264_qpel8_hv_lowpass_neon - sub r1, r1, r3, lsl #2 - bl \type\()_h264_qpel8_hv_lowpass_neon - sub r1, r1, r3, lsl #4 - sub r1, r1, r3, lsl #2 - add r1, r1, #8 - sub r0, r0, r2, lsl #4 - add r0, r0, #8 - bl \type\()_h264_qpel8_hv_lowpass_neon - sub r1, r1, r3, lsl #2 - mov lr, r9 - b \type\()_h264_qpel8_hv_lowpass_neon -endfunc - -function \type\()_h264_qpel16_hv_lowpass_l2_neon - mov r9, lr - sub r2, r4, #256 - bl \type\()_h264_qpel8_hv_lowpass_l2_neon - sub r1, r1, r3, lsl #2 - bl \type\()_h264_qpel8_hv_lowpass_l2_neon - sub r1, r1, r3, lsl #4 - sub r1, r1, r3, lsl #2 - add r1, r1, #8 - sub r0, r0, r3, lsl #4 - add r0, r0, #8 - bl \type\()_h264_qpel8_hv_lowpass_l2_neon - sub r1, r1, r3, lsl #2 - mov lr, r9 - b \type\()_h264_qpel8_hv_lowpass_l2_neon -endfunc -.endm - - h264_qpel16_hv put - h264_qpel16_hv avg - -.macro h264_qpel8 type -function ff_\type\()_h264_qpel8_mc10_neon, export=1 - lowpass_const r3 - mov r3, r1 - sub r1, r1, #2 - mov r12, #8 - b \type\()_h264_qpel8_h_lowpass_l2_neon -endfunc - -function ff_\type\()_h264_qpel8_mc20_neon, export=1 - lowpass_const r3 - sub r1, r1, #2 - mov r3, r2 - mov r12, #8 - b \type\()_h264_qpel8_h_lowpass_neon -endfunc - -function ff_\type\()_h264_qpel8_mc30_neon, export=1 - lowpass_const r3 - add r3, r1, #1 - sub r1, r1, #2 - mov r12, #8 - b \type\()_h264_qpel8_h_lowpass_l2_neon -endfunc - -function ff_\type\()_h264_qpel8_mc01_neon, export=1 - push {lr} - mov r12, r1 -\type\()_h264_qpel8_mc01: - lowpass_const r3 - mov r3, r2 - sub r1, r1, r2, lsl #1 - vpush {d8-d15} - bl \type\()_h264_qpel8_v_lowpass_l2_neon - vpop {d8-d15} - pop {pc} -endfunc - -function ff_\type\()_h264_qpel8_mc11_neon, export=1 - push {r0, r1, r11, lr} -\type\()_h264_qpel8_mc11: - lowpass_const r3 - mov r11, sp -A bic sp, sp, #15 -T bic r0, r11, #15 -T mov sp, r0 - sub sp, sp, #64 - mov r0, sp - sub r1, r1, #2 - mov r3, #8 - mov r12, #8 - vpush {d8-d15} - bl put_h264_qpel8_h_lowpass_neon - ldrd r0, r1, [r11], #8 - mov r3, r2 - add r12, sp, #64 - sub r1, r1, r2, lsl #1 - mov r2, #8 - bl \type\()_h264_qpel8_v_lowpass_l2_neon - vpop {d8-d15} - mov sp, r11 - pop {r11, pc} -endfunc - -function ff_\type\()_h264_qpel8_mc21_neon, export=1 - push {r0, r1, r4, r10, r11, lr} -\type\()_h264_qpel8_mc21: - lowpass_const r3 - mov r11, sp -A bic sp, sp, #15 -T bic r0, r11, #15 -T mov sp, r0 - sub sp, sp, #(8*8+16*12) - sub r1, r1, #2 - mov r3, #8 - mov r0, sp - mov r12, #8 - vpush {d8-d15} - bl put_h264_qpel8_h_lowpass_neon - mov r4, r0 - ldrd r0, r1, [r11], #8 - sub r1, r1, r2, lsl #1 - sub r1, r1, #2 - mov r3, r2 - sub r2, r4, #64 - bl \type\()_h264_qpel8_hv_lowpass_l2_neon - vpop {d8-d15} - mov sp, r11 - pop {r4, r10, r11, pc} -endfunc - -function ff_\type\()_h264_qpel8_mc31_neon, export=1 - add r1, r1, #1 - push {r0, r1, r11, lr} - sub r1, r1, #1 - b \type\()_h264_qpel8_mc11 -endfunc - -function ff_\type\()_h264_qpel8_mc02_neon, export=1 - push {lr} - lowpass_const r3 - sub r1, r1, r2, lsl #1 - mov r3, r2 - vpush {d8-d15} - bl \type\()_h264_qpel8_v_lowpass_neon - vpop {d8-d15} - pop {pc} -endfunc - -function ff_\type\()_h264_qpel8_mc12_neon, export=1 - push {r0, r1, r4, r10, r11, lr} -\type\()_h264_qpel8_mc12: - lowpass_const r3 - mov r11, sp -A bic sp, sp, #15 -T bic r0, r11, #15 -T mov sp, r0 - sub sp, sp, #(8*8+16*12) - sub r1, r1, r2, lsl #1 - mov r3, r2 - mov r2, #8 - mov r0, sp - vpush {d8-d15} - bl put_h264_qpel8_v_lowpass_neon - mov r4, r0 - ldrd r0, r1, [r11], #8 - sub r1, r1, r3, lsl #1 - sub r1, r1, #2 - sub r2, r4, #64 - bl \type\()_h264_qpel8_hv_lowpass_l2_neon - vpop {d8-d15} - mov sp, r11 - pop {r4, r10, r11, pc} -endfunc - -function ff_\type\()_h264_qpel8_mc22_neon, export=1 - push {r4, r10, r11, lr} - mov r11, sp -A bic sp, sp, #15 -T bic r4, r11, #15 -T mov sp, r4 - sub r1, r1, r2, lsl #1 - sub r1, r1, #2 - mov r3, r2 - sub sp, sp, #(16*12) - mov r4, sp - vpush {d8-d15} - bl \type\()_h264_qpel8_hv_lowpass_neon - vpop {d8-d15} - mov sp, r11 - pop {r4, r10, r11, pc} -endfunc - -function ff_\type\()_h264_qpel8_mc32_neon, export=1 - push {r0, r1, r4, r10, r11, lr} - add r1, r1, #1 - b \type\()_h264_qpel8_mc12 -endfunc - -function ff_\type\()_h264_qpel8_mc03_neon, export=1 - push {lr} - add r12, r1, r2 - b \type\()_h264_qpel8_mc01 -endfunc - -function ff_\type\()_h264_qpel8_mc13_neon, export=1 - push {r0, r1, r11, lr} - add r1, r1, r2 - b \type\()_h264_qpel8_mc11 -endfunc - -function ff_\type\()_h264_qpel8_mc23_neon, export=1 - push {r0, r1, r4, r10, r11, lr} - add r1, r1, r2 - b \type\()_h264_qpel8_mc21 -endfunc - -function ff_\type\()_h264_qpel8_mc33_neon, export=1 - add r1, r1, #1 - push {r0, r1, r11, lr} - add r1, r1, r2 - sub r1, r1, #1 - b \type\()_h264_qpel8_mc11 -endfunc -.endm - - h264_qpel8 put - h264_qpel8 avg - -.macro h264_qpel16 type -function ff_\type\()_h264_qpel16_mc10_neon, export=1 - lowpass_const r3 - mov r3, r1 - sub r1, r1, #2 - b \type\()_h264_qpel16_h_lowpass_l2_neon -endfunc - -function ff_\type\()_h264_qpel16_mc20_neon, export=1 - lowpass_const r3 - sub r1, r1, #2 - mov r3, r2 - b \type\()_h264_qpel16_h_lowpass_neon -endfunc - -function ff_\type\()_h264_qpel16_mc30_neon, export=1 - lowpass_const r3 - add r3, r1, #1 - sub r1, r1, #2 - b \type\()_h264_qpel16_h_lowpass_l2_neon -endfunc - -function ff_\type\()_h264_qpel16_mc01_neon, export=1 - push {r4, lr} - mov r12, r1 -\type\()_h264_qpel16_mc01: - lowpass_const r3 - mov r3, r2 - sub r1, r1, r2, lsl #1 - vpush {d8-d15} - bl \type\()_h264_qpel16_v_lowpass_l2_neon - vpop {d8-d15} - pop {r4, pc} -endfunc - -function ff_\type\()_h264_qpel16_mc11_neon, export=1 - push {r0, r1, r4, r11, lr} -\type\()_h264_qpel16_mc11: - lowpass_const r3 - mov r11, sp -A bic sp, sp, #15 -T bic r0, r11, #15 -T mov sp, r0 - sub sp, sp, #256 - mov r0, sp - sub r1, r1, #2 - mov r3, #16 - vpush {d8-d15} - bl put_h264_qpel16_h_lowpass_neon - ldrd r0, r1, [r11], #8 - mov r3, r2 - add r12, sp, #64 - sub r1, r1, r2, lsl #1 - mov r2, #16 - bl \type\()_h264_qpel16_v_lowpass_l2_neon - vpop {d8-d15} - mov sp, r11 - pop {r4, r11, pc} -endfunc - -function ff_\type\()_h264_qpel16_mc21_neon, export=1 - push {r0, r1, r4-r5, r9-r11, lr} -\type\()_h264_qpel16_mc21: - lowpass_const r3 - mov r11, sp -A bic sp, sp, #15 -T bic r0, r11, #15 -T mov sp, r0 - sub sp, sp, #(16*16+16*12) - sub r1, r1, #2 - mov r0, sp - vpush {d8-d15} - bl put_h264_qpel16_h_lowpass_neon_packed - mov r4, r0 - ldrd r0, r1, [r11], #8 - sub r1, r1, r2, lsl #1 - sub r1, r1, #2 - mov r3, r2 - bl \type\()_h264_qpel16_hv_lowpass_l2_neon - vpop {d8-d15} - mov sp, r11 - pop {r4-r5, r9-r11, pc} -endfunc - -function ff_\type\()_h264_qpel16_mc31_neon, export=1 - add r1, r1, #1 - push {r0, r1, r4, r11, lr} - sub r1, r1, #1 - b \type\()_h264_qpel16_mc11 -endfunc - -function ff_\type\()_h264_qpel16_mc02_neon, export=1 - push {r4, lr} - lowpass_const r3 - sub r1, r1, r2, lsl #1 - mov r3, r2 - vpush {d8-d15} - bl \type\()_h264_qpel16_v_lowpass_neon - vpop {d8-d15} - pop {r4, pc} -endfunc - -function ff_\type\()_h264_qpel16_mc12_neon, export=1 - push {r0, r1, r4-r5, r9-r11, lr} -\type\()_h264_qpel16_mc12: - lowpass_const r3 - mov r11, sp -A bic sp, sp, #15 -T bic r0, r11, #15 -T mov sp, r0 - sub sp, sp, #(16*16+16*12) - sub r1, r1, r2, lsl #1 - mov r0, sp - mov r3, r2 - vpush {d8-d15} - bl put_h264_qpel16_v_lowpass_neon_packed - mov r4, r0 - ldrd r0, r1, [r11], #8 - sub r1, r1, r3, lsl #1 - sub r1, r1, #2 - mov r2, r3 - bl \type\()_h264_qpel16_hv_lowpass_l2_neon - vpop {d8-d15} - mov sp, r11 - pop {r4-r5, r9-r11, pc} -endfunc - -function ff_\type\()_h264_qpel16_mc22_neon, export=1 - push {r4, r9-r11, lr} - lowpass_const r3 - mov r11, sp -A bic sp, sp, #15 -T bic r4, r11, #15 -T mov sp, r4 - sub r1, r1, r2, lsl #1 - sub r1, r1, #2 - mov r3, r2 - sub sp, sp, #(16*12) - mov r4, sp - vpush {d8-d15} - bl \type\()_h264_qpel16_hv_lowpass_neon - vpop {d8-d15} - mov sp, r11 - pop {r4, r9-r11, pc} -endfunc - -function ff_\type\()_h264_qpel16_mc32_neon, export=1 - push {r0, r1, r4-r5, r9-r11, lr} - add r1, r1, #1 - b \type\()_h264_qpel16_mc12 -endfunc - -function ff_\type\()_h264_qpel16_mc03_neon, export=1 - push {r4, lr} - add r12, r1, r2 - b \type\()_h264_qpel16_mc01 -endfunc - -function ff_\type\()_h264_qpel16_mc13_neon, export=1 - push {r0, r1, r4, r11, lr} - add r1, r1, r2 - b \type\()_h264_qpel16_mc11 -endfunc - -function ff_\type\()_h264_qpel16_mc23_neon, export=1 - push {r0, r1, r4-r5, r9-r11, lr} - add r1, r1, r2 - b \type\()_h264_qpel16_mc21 -endfunc - -function ff_\type\()_h264_qpel16_mc33_neon, export=1 - add r1, r1, #1 - push {r0, r1, r4, r11, lr} - add r1, r1, r2 - sub r1, r1, #1 - b \type\()_h264_qpel16_mc11 -endfunc -.endm - - h264_qpel16 put - h264_qpel16 avg - @ Biweighted prediction .macro biweight_16 macs, macd diff --git a/mythtv/external/FFmpeg/libavcodec/arm/h264idct_neon.S b/mythtv/external/FFmpeg/libavcodec/arm/h264idct_neon.S index 1b349ced58f..fa5b90c23aa 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/h264idct_neon.S +++ b/mythtv/external/FFmpeg/libavcodec/arm/h264idct_neon.S @@ -22,9 +22,12 @@ function ff_h264_idct_add_neon, export=1 vld1.64 {d0-d3}, [r1,:128] + vmov.i16 q15, #0 vswp d1, d2 + vst1.16 {q15}, [r1,:128]! vadd.i16 d4, d0, d1 + vst1.16 {q15}, [r1,:128]! vshr.s16 q8, q1, #1 vsub.i16 d5, d0, d1 vadd.i16 d6, d2, d17 @@ -65,11 +68,14 @@ function ff_h264_idct_add_neon, export=1 vst1.32 {d0[1]}, [r0,:32], r2 vst1.32 {d1[0]}, [r0,:32], r2 + sub r1, r1, #32 bx lr endfunc function ff_h264_idct_dc_add_neon, export=1 + mov r3, #0 vld1.16 {d2[],d3[]}, [r1,:16] + strh r3, [r1] vrshr.s16 q1, q1, #6 vld1.32 {d0[0]}, [r0,:32], r2 vld1.32 {d0[1]}, [r0,:32], r2 @@ -148,7 +154,7 @@ function ff_h264_idct_add8_neon, export=1 add r5, r1, #16*4 add r1, r2, #16*32 mov r2, r3 - mov r3, r1 + mov r10, r1 ldr r6, [sp, #32] movrel r7, scan8+16 mov r12, #0 @@ -156,7 +162,7 @@ function ff_h264_idct_add8_neon, export=1 ldr r0, [r5, r12, lsl #2] ldrb r8, [r6, r8] add r0, r0, r4 - add r1, r3, r12, lsl #5 + add r1, r10, r12, lsl #5 cmp r8, #0 ldrsh r8, [r1] iteet ne @@ -180,7 +186,9 @@ endfunc qb .req q14 vshr.s16 q2, q10, #1 vadd.i16 q0, q8, q12 - vld1.16 {q14-q15},[r1,:128]! + vld1.16 {q14-q15},[r1,:128] + vst1.16 {q7}, [r1,:128]! + vst1.16 {q7}, [r1,:128]! vsub.i16 q1, q8, q12 vshr.s16 q3, q14, #1 vsub.i16 q2, q2, q14 @@ -259,9 +267,16 @@ endfunc .endm function ff_h264_idct8_add_neon, export=1 - vld1.16 {q8-q9}, [r1,:128]! - vld1.16 {q10-q11},[r1,:128]! - vld1.16 {q12-q13},[r1,:128]! + vmov.i16 q7, #0 + vld1.16 {q8-q9}, [r1,:128] + vst1.16 {q7}, [r1,:128]! + vst1.16 {q7}, [r1,:128]! + vld1.16 {q10-q11},[r1,:128] + vst1.16 {q7}, [r1,:128]! + vst1.16 {q7}, [r1,:128]! + vld1.16 {q12-q13},[r1,:128] + vst1.16 {q7}, [r1,:128]! + vst1.16 {q7}, [r1,:128]! idct8x8_cols 0 idct8x8_cols 1 @@ -313,7 +328,9 @@ function ff_h264_idct8_add_neon, export=1 endfunc function ff_h264_idct8_dc_add_neon, export=1 + mov r3, #0 vld1.16 {d30[],d31[]},[r1,:16] + strh r3, [r1] vld1.32 {d0}, [r0,:64], r2 vrshr.s16 q15, q15, #6 vld1.32 {d1}, [r0,:64], r2 diff --git a/mythtv/external/FFmpeg/libavcodec/arm/h264pred_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/h264pred_init_arm.c index 31714d73d59..5ec39ce6bb6 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/h264pred_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/h264pred_init_arm.c @@ -20,7 +20,9 @@ #include +#include "libavutil/attributes.h" #include "libavutil/arm/cpu.h" +#include "libavcodec/avcodec.h" #include "libavcodec/h264pred.h" void ff_pred16x16_vert_neon(uint8_t *src, ptrdiff_t stride); @@ -43,7 +45,9 @@ void ff_pred8x8_0lt_dc_neon(uint8_t *src, ptrdiff_t stride); void ff_pred8x8_l00_dc_neon(uint8_t *src, ptrdiff_t stride); void ff_pred8x8_0l0_dc_neon(uint8_t *src, ptrdiff_t stride); -static void ff_h264_pred_init_neon(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc) +static av_cold void ff_h264_pred_init_neon(H264PredContext *h, int codec_id, + const int bit_depth, + const int chroma_format_idc) { #if HAVE_NEON const int high_depth = bit_depth > 8; @@ -78,7 +82,8 @@ static void ff_h264_pred_init_neon(H264PredContext *h, int codec_id, const int b #endif // HAVE_NEON } -void ff_h264_pred_init_arm(H264PredContext *h, int codec_id, int bit_depth, const int chroma_format_idc) +av_cold void ff_h264_pred_init_arm(H264PredContext *h, int codec_id, + int bit_depth, const int chroma_format_idc) { int cpu_flags = av_get_cpu_flags(); diff --git a/mythtv/external/FFmpeg/libavcodec/arm/h264qpel_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/h264qpel_init_arm.c new file mode 100644 index 00000000000..fd014fd9ed6 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/arm/h264qpel_init_arm.c @@ -0,0 +1,171 @@ +/* + * ARM NEON optimised DSP functions + * Copyright (c) 2008 Mans Rullgard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "config.h" +#include "libavutil/attributes.h" +#include "libavutil/arm/cpu.h" +#include "libavcodec/h264qpel.h" + +void ff_put_h264_qpel16_mc00_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc10_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc20_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc30_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc01_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc11_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc21_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc31_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc02_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc12_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc22_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc32_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc03_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc13_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc23_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel16_mc33_neon(uint8_t *, uint8_t *, int); + +void ff_put_h264_qpel8_mc00_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc10_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc20_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc30_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc01_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc11_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc21_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc31_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc02_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc12_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc22_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc32_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc03_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc13_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc23_neon(uint8_t *, uint8_t *, int); +void ff_put_h264_qpel8_mc33_neon(uint8_t *, uint8_t *, int); + +void ff_avg_h264_qpel16_mc00_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc10_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc20_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc30_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc01_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc11_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc21_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc31_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc02_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc12_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc22_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc32_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc03_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc13_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc23_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel16_mc33_neon(uint8_t *, uint8_t *, int); + +void ff_avg_h264_qpel8_mc00_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc10_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc20_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc30_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc01_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc11_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc21_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc31_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc02_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc12_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc22_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc32_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc03_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc13_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc23_neon(uint8_t *, uint8_t *, int); +void ff_avg_h264_qpel8_mc33_neon(uint8_t *, uint8_t *, int); + +av_cold void ff_h264qpel_init_arm(H264QpelContext *c, int bit_depth) +{ + const int high_bit_depth = bit_depth > 8; + int cpu_flags = av_get_cpu_flags(); + + if (have_neon(cpu_flags) && !high_bit_depth) { + c->put_h264_qpel_pixels_tab[0][ 0] = ff_put_h264_qpel16_mc00_neon; + c->put_h264_qpel_pixels_tab[0][ 1] = ff_put_h264_qpel16_mc10_neon; + c->put_h264_qpel_pixels_tab[0][ 2] = ff_put_h264_qpel16_mc20_neon; + c->put_h264_qpel_pixels_tab[0][ 3] = ff_put_h264_qpel16_mc30_neon; + c->put_h264_qpel_pixels_tab[0][ 4] = ff_put_h264_qpel16_mc01_neon; + c->put_h264_qpel_pixels_tab[0][ 5] = ff_put_h264_qpel16_mc11_neon; + c->put_h264_qpel_pixels_tab[0][ 6] = ff_put_h264_qpel16_mc21_neon; + c->put_h264_qpel_pixels_tab[0][ 7] = ff_put_h264_qpel16_mc31_neon; + c->put_h264_qpel_pixels_tab[0][ 8] = ff_put_h264_qpel16_mc02_neon; + c->put_h264_qpel_pixels_tab[0][ 9] = ff_put_h264_qpel16_mc12_neon; + c->put_h264_qpel_pixels_tab[0][10] = ff_put_h264_qpel16_mc22_neon; + c->put_h264_qpel_pixels_tab[0][11] = ff_put_h264_qpel16_mc32_neon; + c->put_h264_qpel_pixels_tab[0][12] = ff_put_h264_qpel16_mc03_neon; + c->put_h264_qpel_pixels_tab[0][13] = ff_put_h264_qpel16_mc13_neon; + c->put_h264_qpel_pixels_tab[0][14] = ff_put_h264_qpel16_mc23_neon; + c->put_h264_qpel_pixels_tab[0][15] = ff_put_h264_qpel16_mc33_neon; + + c->put_h264_qpel_pixels_tab[1][ 0] = ff_put_h264_qpel8_mc00_neon; + c->put_h264_qpel_pixels_tab[1][ 1] = ff_put_h264_qpel8_mc10_neon; + c->put_h264_qpel_pixels_tab[1][ 2] = ff_put_h264_qpel8_mc20_neon; + c->put_h264_qpel_pixels_tab[1][ 3] = ff_put_h264_qpel8_mc30_neon; + c->put_h264_qpel_pixels_tab[1][ 4] = ff_put_h264_qpel8_mc01_neon; + c->put_h264_qpel_pixels_tab[1][ 5] = ff_put_h264_qpel8_mc11_neon; + c->put_h264_qpel_pixels_tab[1][ 6] = ff_put_h264_qpel8_mc21_neon; + c->put_h264_qpel_pixels_tab[1][ 7] = ff_put_h264_qpel8_mc31_neon; + c->put_h264_qpel_pixels_tab[1][ 8] = ff_put_h264_qpel8_mc02_neon; + c->put_h264_qpel_pixels_tab[1][ 9] = ff_put_h264_qpel8_mc12_neon; + c->put_h264_qpel_pixels_tab[1][10] = ff_put_h264_qpel8_mc22_neon; + c->put_h264_qpel_pixels_tab[1][11] = ff_put_h264_qpel8_mc32_neon; + c->put_h264_qpel_pixels_tab[1][12] = ff_put_h264_qpel8_mc03_neon; + c->put_h264_qpel_pixels_tab[1][13] = ff_put_h264_qpel8_mc13_neon; + c->put_h264_qpel_pixels_tab[1][14] = ff_put_h264_qpel8_mc23_neon; + c->put_h264_qpel_pixels_tab[1][15] = ff_put_h264_qpel8_mc33_neon; + + c->avg_h264_qpel_pixels_tab[0][ 0] = ff_avg_h264_qpel16_mc00_neon; + c->avg_h264_qpel_pixels_tab[0][ 1] = ff_avg_h264_qpel16_mc10_neon; + c->avg_h264_qpel_pixels_tab[0][ 2] = ff_avg_h264_qpel16_mc20_neon; + c->avg_h264_qpel_pixels_tab[0][ 3] = ff_avg_h264_qpel16_mc30_neon; + c->avg_h264_qpel_pixels_tab[0][ 4] = ff_avg_h264_qpel16_mc01_neon; + c->avg_h264_qpel_pixels_tab[0][ 5] = ff_avg_h264_qpel16_mc11_neon; + c->avg_h264_qpel_pixels_tab[0][ 6] = ff_avg_h264_qpel16_mc21_neon; + c->avg_h264_qpel_pixels_tab[0][ 7] = ff_avg_h264_qpel16_mc31_neon; + c->avg_h264_qpel_pixels_tab[0][ 8] = ff_avg_h264_qpel16_mc02_neon; + c->avg_h264_qpel_pixels_tab[0][ 9] = ff_avg_h264_qpel16_mc12_neon; + c->avg_h264_qpel_pixels_tab[0][10] = ff_avg_h264_qpel16_mc22_neon; + c->avg_h264_qpel_pixels_tab[0][11] = ff_avg_h264_qpel16_mc32_neon; + c->avg_h264_qpel_pixels_tab[0][12] = ff_avg_h264_qpel16_mc03_neon; + c->avg_h264_qpel_pixels_tab[0][13] = ff_avg_h264_qpel16_mc13_neon; + c->avg_h264_qpel_pixels_tab[0][14] = ff_avg_h264_qpel16_mc23_neon; + c->avg_h264_qpel_pixels_tab[0][15] = ff_avg_h264_qpel16_mc33_neon; + + c->avg_h264_qpel_pixels_tab[1][ 0] = ff_avg_h264_qpel8_mc00_neon; + c->avg_h264_qpel_pixels_tab[1][ 1] = ff_avg_h264_qpel8_mc10_neon; + c->avg_h264_qpel_pixels_tab[1][ 2] = ff_avg_h264_qpel8_mc20_neon; + c->avg_h264_qpel_pixels_tab[1][ 3] = ff_avg_h264_qpel8_mc30_neon; + c->avg_h264_qpel_pixels_tab[1][ 4] = ff_avg_h264_qpel8_mc01_neon; + c->avg_h264_qpel_pixels_tab[1][ 5] = ff_avg_h264_qpel8_mc11_neon; + c->avg_h264_qpel_pixels_tab[1][ 6] = ff_avg_h264_qpel8_mc21_neon; + c->avg_h264_qpel_pixels_tab[1][ 7] = ff_avg_h264_qpel8_mc31_neon; + c->avg_h264_qpel_pixels_tab[1][ 8] = ff_avg_h264_qpel8_mc02_neon; + c->avg_h264_qpel_pixels_tab[1][ 9] = ff_avg_h264_qpel8_mc12_neon; + c->avg_h264_qpel_pixels_tab[1][10] = ff_avg_h264_qpel8_mc22_neon; + c->avg_h264_qpel_pixels_tab[1][11] = ff_avg_h264_qpel8_mc32_neon; + c->avg_h264_qpel_pixels_tab[1][12] = ff_avg_h264_qpel8_mc03_neon; + c->avg_h264_qpel_pixels_tab[1][13] = ff_avg_h264_qpel8_mc13_neon; + c->avg_h264_qpel_pixels_tab[1][14] = ff_avg_h264_qpel8_mc23_neon; + c->avg_h264_qpel_pixels_tab[1][15] = ff_avg_h264_qpel8_mc33_neon; + } +} diff --git a/mythtv/external/FFmpeg/libavcodec/arm/h264qpel_neon.S b/mythtv/external/FFmpeg/libavcodec/arm/h264qpel_neon.S new file mode 100644 index 00000000000..21336c6c32e --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/arm/h264qpel_neon.S @@ -0,0 +1,955 @@ +/* + * Copyright (c) 2008 Mans Rullgard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/arm/asm.S" +#include "neon.S" + + /* H.264 qpel MC */ + +.macro lowpass_const r + movw \r, #5 + movt \r, #20 + vmov.32 d6[0], \r +.endm + +.macro lowpass_8 r0, r1, r2, r3, d0, d1, narrow=1 + .if \narrow + t0 .req q0 + t1 .req q8 + .else + t0 .req \d0 + t1 .req \d1 + .endif + vext.8 d2, \r0, \r1, #2 + vext.8 d3, \r0, \r1, #3 + vaddl.u8 q1, d2, d3 + vext.8 d4, \r0, \r1, #1 + vext.8 d5, \r0, \r1, #4 + vaddl.u8 q2, d4, d5 + vext.8 d30, \r0, \r1, #5 + vaddl.u8 t0, \r0, d30 + vext.8 d18, \r2, \r3, #2 + vmla.i16 t0, q1, d6[1] + vext.8 d19, \r2, \r3, #3 + vaddl.u8 q9, d18, d19 + vext.8 d20, \r2, \r3, #1 + vmls.i16 t0, q2, d6[0] + vext.8 d21, \r2, \r3, #4 + vaddl.u8 q10, d20, d21 + vext.8 d31, \r2, \r3, #5 + vaddl.u8 t1, \r2, d31 + vmla.i16 t1, q9, d6[1] + vmls.i16 t1, q10, d6[0] + .if \narrow + vqrshrun.s16 \d0, t0, #5 + vqrshrun.s16 \d1, t1, #5 + .endif + .unreq t0 + .unreq t1 +.endm + +.macro lowpass_8_1 r0, r1, d0, narrow=1 + .if \narrow + t0 .req q0 + .else + t0 .req \d0 + .endif + vext.8 d2, \r0, \r1, #2 + vext.8 d3, \r0, \r1, #3 + vaddl.u8 q1, d2, d3 + vext.8 d4, \r0, \r1, #1 + vext.8 d5, \r0, \r1, #4 + vaddl.u8 q2, d4, d5 + vext.8 d30, \r0, \r1, #5 + vaddl.u8 t0, \r0, d30 + vmla.i16 t0, q1, d6[1] + vmls.i16 t0, q2, d6[0] + .if \narrow + vqrshrun.s16 \d0, t0, #5 + .endif + .unreq t0 +.endm + +.macro lowpass_8.16 r0, r1, l0, h0, l1, h1, d + vext.16 q1, \r0, \r1, #2 + vext.16 q0, \r0, \r1, #3 + vaddl.s16 q9, d2, d0 + vext.16 q2, \r0, \r1, #1 + vaddl.s16 q1, d3, d1 + vext.16 q3, \r0, \r1, #4 + vaddl.s16 q10, d4, d6 + vext.16 \r1, \r0, \r1, #5 + vaddl.s16 q2, d5, d7 + vaddl.s16 q0, \h0, \h1 + vaddl.s16 q8, \l0, \l1 + + vshl.i32 q3, q9, #4 + vshl.i32 q9, q9, #2 + vshl.i32 q15, q10, #2 + vadd.i32 q9, q9, q3 + vadd.i32 q10, q10, q15 + + vshl.i32 q3, q1, #4 + vshl.i32 q1, q1, #2 + vshl.i32 q15, q2, #2 + vadd.i32 q1, q1, q3 + vadd.i32 q2, q2, q15 + + vadd.i32 q9, q9, q8 + vsub.i32 q9, q9, q10 + + vadd.i32 q1, q1, q0 + vsub.i32 q1, q1, q2 + + vrshrn.s32 d18, q9, #10 + vrshrn.s32 d19, q1, #10 + + vqmovun.s16 \d, q9 +.endm + +function put_h264_qpel16_h_lowpass_neon_packed + mov r4, lr + mov r12, #16 + mov r3, #8 + bl put_h264_qpel8_h_lowpass_neon + sub r1, r1, r2, lsl #4 + add r1, r1, #8 + mov r12, #16 + mov lr, r4 + b put_h264_qpel8_h_lowpass_neon +endfunc + +.macro h264_qpel_h_lowpass type +function \type\()_h264_qpel16_h_lowpass_neon + push {lr} + mov r12, #16 + bl \type\()_h264_qpel8_h_lowpass_neon + sub r0, r0, r3, lsl #4 + sub r1, r1, r2, lsl #4 + add r0, r0, #8 + add r1, r1, #8 + mov r12, #16 + pop {lr} +endfunc + +function \type\()_h264_qpel8_h_lowpass_neon +1: vld1.8 {d0, d1}, [r1], r2 + vld1.8 {d16,d17}, [r1], r2 + subs r12, r12, #2 + lowpass_8 d0, d1, d16, d17, d0, d16 + .ifc \type,avg + vld1.8 {d2}, [r0,:64], r3 + vrhadd.u8 d0, d0, d2 + vld1.8 {d3}, [r0,:64] + vrhadd.u8 d16, d16, d3 + sub r0, r0, r3 + .endif + vst1.8 {d0}, [r0,:64], r3 + vst1.8 {d16}, [r0,:64], r3 + bne 1b + bx lr +endfunc +.endm + + h264_qpel_h_lowpass put + h264_qpel_h_lowpass avg + +.macro h264_qpel_h_lowpass_l2 type +function \type\()_h264_qpel16_h_lowpass_l2_neon + push {lr} + mov r12, #16 + bl \type\()_h264_qpel8_h_lowpass_l2_neon + sub r0, r0, r2, lsl #4 + sub r1, r1, r2, lsl #4 + sub r3, r3, r2, lsl #4 + add r0, r0, #8 + add r1, r1, #8 + add r3, r3, #8 + mov r12, #16 + pop {lr} +endfunc + +function \type\()_h264_qpel8_h_lowpass_l2_neon +1: vld1.8 {d0, d1}, [r1], r2 + vld1.8 {d16,d17}, [r1], r2 + vld1.8 {d28}, [r3], r2 + vld1.8 {d29}, [r3], r2 + subs r12, r12, #2 + lowpass_8 d0, d1, d16, d17, d0, d1 + vrhadd.u8 q0, q0, q14 + .ifc \type,avg + vld1.8 {d2}, [r0,:64], r2 + vrhadd.u8 d0, d0, d2 + vld1.8 {d3}, [r0,:64] + vrhadd.u8 d1, d1, d3 + sub r0, r0, r2 + .endif + vst1.8 {d0}, [r0,:64], r2 + vst1.8 {d1}, [r0,:64], r2 + bne 1b + bx lr +endfunc +.endm + + h264_qpel_h_lowpass_l2 put + h264_qpel_h_lowpass_l2 avg + +function put_h264_qpel16_v_lowpass_neon_packed + mov r4, lr + mov r2, #8 + bl put_h264_qpel8_v_lowpass_neon + sub r1, r1, r3, lsl #2 + bl put_h264_qpel8_v_lowpass_neon + sub r1, r1, r3, lsl #4 + sub r1, r1, r3, lsl #2 + add r1, r1, #8 + bl put_h264_qpel8_v_lowpass_neon + sub r1, r1, r3, lsl #2 + mov lr, r4 + b put_h264_qpel8_v_lowpass_neon +endfunc + +.macro h264_qpel_v_lowpass type +function \type\()_h264_qpel16_v_lowpass_neon + mov r4, lr + bl \type\()_h264_qpel8_v_lowpass_neon + sub r1, r1, r3, lsl #2 + bl \type\()_h264_qpel8_v_lowpass_neon + sub r0, r0, r2, lsl #4 + add r0, r0, #8 + sub r1, r1, r3, lsl #4 + sub r1, r1, r3, lsl #2 + add r1, r1, #8 + bl \type\()_h264_qpel8_v_lowpass_neon + sub r1, r1, r3, lsl #2 + mov lr, r4 +endfunc + +function \type\()_h264_qpel8_v_lowpass_neon + vld1.8 {d8}, [r1], r3 + vld1.8 {d10}, [r1], r3 + vld1.8 {d12}, [r1], r3 + vld1.8 {d14}, [r1], r3 + vld1.8 {d22}, [r1], r3 + vld1.8 {d24}, [r1], r3 + vld1.8 {d26}, [r1], r3 + vld1.8 {d28}, [r1], r3 + vld1.8 {d9}, [r1], r3 + vld1.8 {d11}, [r1], r3 + vld1.8 {d13}, [r1], r3 + vld1.8 {d15}, [r1], r3 + vld1.8 {d23}, [r1] + + transpose_8x8 q4, q5, q6, q7, q11, q12, q13, q14 + lowpass_8 d8, d9, d10, d11, d8, d10 + lowpass_8 d12, d13, d14, d15, d12, d14 + lowpass_8 d22, d23, d24, d25, d22, d24 + lowpass_8 d26, d27, d28, d29, d26, d28 + transpose_8x8 d8, d10, d12, d14, d22, d24, d26, d28 + + .ifc \type,avg + vld1.8 {d9}, [r0,:64], r2 + vrhadd.u8 d8, d8, d9 + vld1.8 {d11}, [r0,:64], r2 + vrhadd.u8 d10, d10, d11 + vld1.8 {d13}, [r0,:64], r2 + vrhadd.u8 d12, d12, d13 + vld1.8 {d15}, [r0,:64], r2 + vrhadd.u8 d14, d14, d15 + vld1.8 {d23}, [r0,:64], r2 + vrhadd.u8 d22, d22, d23 + vld1.8 {d25}, [r0,:64], r2 + vrhadd.u8 d24, d24, d25 + vld1.8 {d27}, [r0,:64], r2 + vrhadd.u8 d26, d26, d27 + vld1.8 {d29}, [r0,:64], r2 + vrhadd.u8 d28, d28, d29 + sub r0, r0, r2, lsl #3 + .endif + + vst1.8 {d8}, [r0,:64], r2 + vst1.8 {d10}, [r0,:64], r2 + vst1.8 {d12}, [r0,:64], r2 + vst1.8 {d14}, [r0,:64], r2 + vst1.8 {d22}, [r0,:64], r2 + vst1.8 {d24}, [r0,:64], r2 + vst1.8 {d26}, [r0,:64], r2 + vst1.8 {d28}, [r0,:64], r2 + + bx lr +endfunc +.endm + + h264_qpel_v_lowpass put + h264_qpel_v_lowpass avg + +.macro h264_qpel_v_lowpass_l2 type +function \type\()_h264_qpel16_v_lowpass_l2_neon + mov r4, lr + bl \type\()_h264_qpel8_v_lowpass_l2_neon + sub r1, r1, r3, lsl #2 + bl \type\()_h264_qpel8_v_lowpass_l2_neon + sub r0, r0, r3, lsl #4 + sub r12, r12, r2, lsl #4 + add r0, r0, #8 + add r12, r12, #8 + sub r1, r1, r3, lsl #4 + sub r1, r1, r3, lsl #2 + add r1, r1, #8 + bl \type\()_h264_qpel8_v_lowpass_l2_neon + sub r1, r1, r3, lsl #2 + mov lr, r4 +endfunc + +function \type\()_h264_qpel8_v_lowpass_l2_neon + vld1.8 {d8}, [r1], r3 + vld1.8 {d10}, [r1], r3 + vld1.8 {d12}, [r1], r3 + vld1.8 {d14}, [r1], r3 + vld1.8 {d22}, [r1], r3 + vld1.8 {d24}, [r1], r3 + vld1.8 {d26}, [r1], r3 + vld1.8 {d28}, [r1], r3 + vld1.8 {d9}, [r1], r3 + vld1.8 {d11}, [r1], r3 + vld1.8 {d13}, [r1], r3 + vld1.8 {d15}, [r1], r3 + vld1.8 {d23}, [r1] + + transpose_8x8 q4, q5, q6, q7, q11, q12, q13, q14 + lowpass_8 d8, d9, d10, d11, d8, d9 + lowpass_8 d12, d13, d14, d15, d12, d13 + lowpass_8 d22, d23, d24, d25, d22, d23 + lowpass_8 d26, d27, d28, d29, d26, d27 + transpose_8x8 d8, d9, d12, d13, d22, d23, d26, d27 + + vld1.8 {d0}, [r12], r2 + vld1.8 {d1}, [r12], r2 + vld1.8 {d2}, [r12], r2 + vld1.8 {d3}, [r12], r2 + vld1.8 {d4}, [r12], r2 + vrhadd.u8 q0, q0, q4 + vld1.8 {d5}, [r12], r2 + vrhadd.u8 q1, q1, q6 + vld1.8 {d10}, [r12], r2 + vrhadd.u8 q2, q2, q11 + vld1.8 {d11}, [r12], r2 + vrhadd.u8 q5, q5, q13 + + .ifc \type,avg + vld1.8 {d16}, [r0,:64], r3 + vrhadd.u8 d0, d0, d16 + vld1.8 {d17}, [r0,:64], r3 + vrhadd.u8 d1, d1, d17 + vld1.8 {d16}, [r0,:64], r3 + vrhadd.u8 d2, d2, d16 + vld1.8 {d17}, [r0,:64], r3 + vrhadd.u8 d3, d3, d17 + vld1.8 {d16}, [r0,:64], r3 + vrhadd.u8 d4, d4, d16 + vld1.8 {d17}, [r0,:64], r3 + vrhadd.u8 d5, d5, d17 + vld1.8 {d16}, [r0,:64], r3 + vrhadd.u8 d10, d10, d16 + vld1.8 {d17}, [r0,:64], r3 + vrhadd.u8 d11, d11, d17 + sub r0, r0, r3, lsl #3 + .endif + + vst1.8 {d0}, [r0,:64], r3 + vst1.8 {d1}, [r0,:64], r3 + vst1.8 {d2}, [r0,:64], r3 + vst1.8 {d3}, [r0,:64], r3 + vst1.8 {d4}, [r0,:64], r3 + vst1.8 {d5}, [r0,:64], r3 + vst1.8 {d10}, [r0,:64], r3 + vst1.8 {d11}, [r0,:64], r3 + + bx lr +endfunc +.endm + + h264_qpel_v_lowpass_l2 put + h264_qpel_v_lowpass_l2 avg + +function put_h264_qpel8_hv_lowpass_neon_top + lowpass_const r12 + mov r12, #12 +1: vld1.8 {d0, d1}, [r1], r3 + vld1.8 {d16,d17}, [r1], r3 + subs r12, r12, #2 + lowpass_8 d0, d1, d16, d17, q11, q12, narrow=0 + vst1.8 {d22-d25}, [r4,:128]! + bne 1b + + vld1.8 {d0, d1}, [r1] + lowpass_8_1 d0, d1, q12, narrow=0 + + mov r12, #-16 + add r4, r4, r12 + vld1.8 {d30,d31}, [r4,:128], r12 + vld1.8 {d20,d21}, [r4,:128], r12 + vld1.8 {d18,d19}, [r4,:128], r12 + vld1.8 {d16,d17}, [r4,:128], r12 + vld1.8 {d14,d15}, [r4,:128], r12 + vld1.8 {d12,d13}, [r4,:128], r12 + vld1.8 {d10,d11}, [r4,:128], r12 + vld1.8 {d8, d9}, [r4,:128], r12 + vld1.8 {d6, d7}, [r4,:128], r12 + vld1.8 {d4, d5}, [r4,:128], r12 + vld1.8 {d2, d3}, [r4,:128], r12 + vld1.8 {d0, d1}, [r4,:128] + + swap4 d1, d3, d5, d7, d8, d10, d12, d14 + transpose16_4x4 q0, q1, q2, q3, q4, q5, q6, q7 + + swap4 d17, d19, d21, d31, d24, d26, d28, d22 + transpose16_4x4 q8, q9, q10, q15, q12, q13, q14, q11 + + vst1.8 {d30,d31}, [r4,:128]! + vst1.8 {d6, d7}, [r4,:128]! + vst1.8 {d20,d21}, [r4,:128]! + vst1.8 {d4, d5}, [r4,:128]! + vst1.8 {d18,d19}, [r4,:128]! + vst1.8 {d2, d3}, [r4,:128]! + vst1.8 {d16,d17}, [r4,:128]! + vst1.8 {d0, d1}, [r4,:128] + + lowpass_8.16 q4, q12, d8, d9, d24, d25, d8 + lowpass_8.16 q5, q13, d10, d11, d26, d27, d9 + lowpass_8.16 q6, q14, d12, d13, d28, d29, d10 + lowpass_8.16 q7, q11, d14, d15, d22, d23, d11 + + vld1.8 {d16,d17}, [r4,:128], r12 + vld1.8 {d30,d31}, [r4,:128], r12 + lowpass_8.16 q8, q15, d16, d17, d30, d31, d12 + vld1.8 {d16,d17}, [r4,:128], r12 + vld1.8 {d30,d31}, [r4,:128], r12 + lowpass_8.16 q8, q15, d16, d17, d30, d31, d13 + vld1.8 {d16,d17}, [r4,:128], r12 + vld1.8 {d30,d31}, [r4,:128], r12 + lowpass_8.16 q8, q15, d16, d17, d30, d31, d14 + vld1.8 {d16,d17}, [r4,:128], r12 + vld1.8 {d30,d31}, [r4,:128] + lowpass_8.16 q8, q15, d16, d17, d30, d31, d15 + + transpose_8x8 d12, d13, d14, d15, d8, d9, d10, d11 + + bx lr +endfunc + +.macro h264_qpel8_hv_lowpass type +function \type\()_h264_qpel8_hv_lowpass_neon + mov r10, lr + bl put_h264_qpel8_hv_lowpass_neon_top + .ifc \type,avg + vld1.8 {d0}, [r0,:64], r2 + vrhadd.u8 d12, d12, d0 + vld1.8 {d1}, [r0,:64], r2 + vrhadd.u8 d13, d13, d1 + vld1.8 {d2}, [r0,:64], r2 + vrhadd.u8 d14, d14, d2 + vld1.8 {d3}, [r0,:64], r2 + vrhadd.u8 d15, d15, d3 + vld1.8 {d4}, [r0,:64], r2 + vrhadd.u8 d8, d8, d4 + vld1.8 {d5}, [r0,:64], r2 + vrhadd.u8 d9, d9, d5 + vld1.8 {d6}, [r0,:64], r2 + vrhadd.u8 d10, d10, d6 + vld1.8 {d7}, [r0,:64], r2 + vrhadd.u8 d11, d11, d7 + sub r0, r0, r2, lsl #3 + .endif + + vst1.8 {d12}, [r0,:64], r2 + vst1.8 {d13}, [r0,:64], r2 + vst1.8 {d14}, [r0,:64], r2 + vst1.8 {d15}, [r0,:64], r2 + vst1.8 {d8}, [r0,:64], r2 + vst1.8 {d9}, [r0,:64], r2 + vst1.8 {d10}, [r0,:64], r2 + vst1.8 {d11}, [r0,:64], r2 + + mov lr, r10 + bx lr +endfunc +.endm + + h264_qpel8_hv_lowpass put + h264_qpel8_hv_lowpass avg + +.macro h264_qpel8_hv_lowpass_l2 type +function \type\()_h264_qpel8_hv_lowpass_l2_neon + mov r10, lr + bl put_h264_qpel8_hv_lowpass_neon_top + + vld1.8 {d0, d1}, [r2,:128]! + vld1.8 {d2, d3}, [r2,:128]! + vrhadd.u8 q0, q0, q6 + vld1.8 {d4, d5}, [r2,:128]! + vrhadd.u8 q1, q1, q7 + vld1.8 {d6, d7}, [r2,:128]! + vrhadd.u8 q2, q2, q4 + vrhadd.u8 q3, q3, q5 + .ifc \type,avg + vld1.8 {d16}, [r0,:64], r3 + vrhadd.u8 d0, d0, d16 + vld1.8 {d17}, [r0,:64], r3 + vrhadd.u8 d1, d1, d17 + vld1.8 {d18}, [r0,:64], r3 + vrhadd.u8 d2, d2, d18 + vld1.8 {d19}, [r0,:64], r3 + vrhadd.u8 d3, d3, d19 + vld1.8 {d20}, [r0,:64], r3 + vrhadd.u8 d4, d4, d20 + vld1.8 {d21}, [r0,:64], r3 + vrhadd.u8 d5, d5, d21 + vld1.8 {d22}, [r0,:64], r3 + vrhadd.u8 d6, d6, d22 + vld1.8 {d23}, [r0,:64], r3 + vrhadd.u8 d7, d7, d23 + sub r0, r0, r3, lsl #3 + .endif + vst1.8 {d0}, [r0,:64], r3 + vst1.8 {d1}, [r0,:64], r3 + vst1.8 {d2}, [r0,:64], r3 + vst1.8 {d3}, [r0,:64], r3 + vst1.8 {d4}, [r0,:64], r3 + vst1.8 {d5}, [r0,:64], r3 + vst1.8 {d6}, [r0,:64], r3 + vst1.8 {d7}, [r0,:64], r3 + + mov lr, r10 + bx lr +endfunc +.endm + + h264_qpel8_hv_lowpass_l2 put + h264_qpel8_hv_lowpass_l2 avg + +.macro h264_qpel16_hv type +function \type\()_h264_qpel16_hv_lowpass_neon + mov r9, lr + bl \type\()_h264_qpel8_hv_lowpass_neon + sub r1, r1, r3, lsl #2 + bl \type\()_h264_qpel8_hv_lowpass_neon + sub r1, r1, r3, lsl #4 + sub r1, r1, r3, lsl #2 + add r1, r1, #8 + sub r0, r0, r2, lsl #4 + add r0, r0, #8 + bl \type\()_h264_qpel8_hv_lowpass_neon + sub r1, r1, r3, lsl #2 + mov lr, r9 + b \type\()_h264_qpel8_hv_lowpass_neon +endfunc + +function \type\()_h264_qpel16_hv_lowpass_l2_neon + mov r9, lr + sub r2, r4, #256 + bl \type\()_h264_qpel8_hv_lowpass_l2_neon + sub r1, r1, r3, lsl #2 + bl \type\()_h264_qpel8_hv_lowpass_l2_neon + sub r1, r1, r3, lsl #4 + sub r1, r1, r3, lsl #2 + add r1, r1, #8 + sub r0, r0, r3, lsl #4 + add r0, r0, #8 + bl \type\()_h264_qpel8_hv_lowpass_l2_neon + sub r1, r1, r3, lsl #2 + mov lr, r9 + b \type\()_h264_qpel8_hv_lowpass_l2_neon +endfunc +.endm + + h264_qpel16_hv put + h264_qpel16_hv avg + +.macro h264_qpel8 type +function ff_\type\()_h264_qpel8_mc10_neon, export=1 + lowpass_const r3 + mov r3, r1 + sub r1, r1, #2 + mov r12, #8 + b \type\()_h264_qpel8_h_lowpass_l2_neon +endfunc + +function ff_\type\()_h264_qpel8_mc20_neon, export=1 + lowpass_const r3 + sub r1, r1, #2 + mov r3, r2 + mov r12, #8 + b \type\()_h264_qpel8_h_lowpass_neon +endfunc + +function ff_\type\()_h264_qpel8_mc30_neon, export=1 + lowpass_const r3 + add r3, r1, #1 + sub r1, r1, #2 + mov r12, #8 + b \type\()_h264_qpel8_h_lowpass_l2_neon +endfunc + +function ff_\type\()_h264_qpel8_mc01_neon, export=1 + push {lr} + mov r12, r1 +\type\()_h264_qpel8_mc01: + lowpass_const r3 + mov r3, r2 + sub r1, r1, r2, lsl #1 + vpush {d8-d15} + bl \type\()_h264_qpel8_v_lowpass_l2_neon + vpop {d8-d15} + pop {pc} +endfunc + +function ff_\type\()_h264_qpel8_mc11_neon, export=1 + push {r0, r1, r11, lr} +\type\()_h264_qpel8_mc11: + lowpass_const r3 + mov r11, sp +A bic sp, sp, #15 +T bic r0, r11, #15 +T mov sp, r0 + sub sp, sp, #64 + mov r0, sp + sub r1, r1, #2 + mov r3, #8 + mov r12, #8 + vpush {d8-d15} + bl put_h264_qpel8_h_lowpass_neon + ldrd r0, r1, [r11], #8 + mov r3, r2 + add r12, sp, #64 + sub r1, r1, r2, lsl #1 + mov r2, #8 + bl \type\()_h264_qpel8_v_lowpass_l2_neon + vpop {d8-d15} + mov sp, r11 + pop {r11, pc} +endfunc + +function ff_\type\()_h264_qpel8_mc21_neon, export=1 + push {r0, r1, r4, r10, r11, lr} +\type\()_h264_qpel8_mc21: + lowpass_const r3 + mov r11, sp +A bic sp, sp, #15 +T bic r0, r11, #15 +T mov sp, r0 + sub sp, sp, #(8*8+16*12) + sub r1, r1, #2 + mov r3, #8 + mov r0, sp + mov r12, #8 + vpush {d8-d15} + bl put_h264_qpel8_h_lowpass_neon + mov r4, r0 + ldrd r0, r1, [r11], #8 + sub r1, r1, r2, lsl #1 + sub r1, r1, #2 + mov r3, r2 + sub r2, r4, #64 + bl \type\()_h264_qpel8_hv_lowpass_l2_neon + vpop {d8-d15} + mov sp, r11 + pop {r4, r10, r11, pc} +endfunc + +function ff_\type\()_h264_qpel8_mc31_neon, export=1 + add r1, r1, #1 + push {r0, r1, r11, lr} + sub r1, r1, #1 + b \type\()_h264_qpel8_mc11 +endfunc + +function ff_\type\()_h264_qpel8_mc02_neon, export=1 + push {lr} + lowpass_const r3 + sub r1, r1, r2, lsl #1 + mov r3, r2 + vpush {d8-d15} + bl \type\()_h264_qpel8_v_lowpass_neon + vpop {d8-d15} + pop {pc} +endfunc + +function ff_\type\()_h264_qpel8_mc12_neon, export=1 + push {r0, r1, r4, r10, r11, lr} +\type\()_h264_qpel8_mc12: + lowpass_const r3 + mov r11, sp +A bic sp, sp, #15 +T bic r0, r11, #15 +T mov sp, r0 + sub sp, sp, #(8*8+16*12) + sub r1, r1, r2, lsl #1 + mov r3, r2 + mov r2, #8 + mov r0, sp + vpush {d8-d15} + bl put_h264_qpel8_v_lowpass_neon + mov r4, r0 + ldrd r0, r1, [r11], #8 + sub r1, r1, r3, lsl #1 + sub r1, r1, #2 + sub r2, r4, #64 + bl \type\()_h264_qpel8_hv_lowpass_l2_neon + vpop {d8-d15} + mov sp, r11 + pop {r4, r10, r11, pc} +endfunc + +function ff_\type\()_h264_qpel8_mc22_neon, export=1 + push {r4, r10, r11, lr} + mov r11, sp +A bic sp, sp, #15 +T bic r4, r11, #15 +T mov sp, r4 + sub r1, r1, r2, lsl #1 + sub r1, r1, #2 + mov r3, r2 + sub sp, sp, #(16*12) + mov r4, sp + vpush {d8-d15} + bl \type\()_h264_qpel8_hv_lowpass_neon + vpop {d8-d15} + mov sp, r11 + pop {r4, r10, r11, pc} +endfunc + +function ff_\type\()_h264_qpel8_mc32_neon, export=1 + push {r0, r1, r4, r10, r11, lr} + add r1, r1, #1 + b \type\()_h264_qpel8_mc12 +endfunc + +function ff_\type\()_h264_qpel8_mc03_neon, export=1 + push {lr} + add r12, r1, r2 + b \type\()_h264_qpel8_mc01 +endfunc + +function ff_\type\()_h264_qpel8_mc13_neon, export=1 + push {r0, r1, r11, lr} + add r1, r1, r2 + b \type\()_h264_qpel8_mc11 +endfunc + +function ff_\type\()_h264_qpel8_mc23_neon, export=1 + push {r0, r1, r4, r10, r11, lr} + add r1, r1, r2 + b \type\()_h264_qpel8_mc21 +endfunc + +function ff_\type\()_h264_qpel8_mc33_neon, export=1 + add r1, r1, #1 + push {r0, r1, r11, lr} + add r1, r1, r2 + sub r1, r1, #1 + b \type\()_h264_qpel8_mc11 +endfunc +.endm + + h264_qpel8 put + h264_qpel8 avg + +.macro h264_qpel16 type +function ff_\type\()_h264_qpel16_mc10_neon, export=1 + lowpass_const r3 + mov r3, r1 + sub r1, r1, #2 + b \type\()_h264_qpel16_h_lowpass_l2_neon +endfunc + +function ff_\type\()_h264_qpel16_mc20_neon, export=1 + lowpass_const r3 + sub r1, r1, #2 + mov r3, r2 + b \type\()_h264_qpel16_h_lowpass_neon +endfunc + +function ff_\type\()_h264_qpel16_mc30_neon, export=1 + lowpass_const r3 + add r3, r1, #1 + sub r1, r1, #2 + b \type\()_h264_qpel16_h_lowpass_l2_neon +endfunc + +function ff_\type\()_h264_qpel16_mc01_neon, export=1 + push {r4, lr} + mov r12, r1 +\type\()_h264_qpel16_mc01: + lowpass_const r3 + mov r3, r2 + sub r1, r1, r2, lsl #1 + vpush {d8-d15} + bl \type\()_h264_qpel16_v_lowpass_l2_neon + vpop {d8-d15} + pop {r4, pc} +endfunc + +function ff_\type\()_h264_qpel16_mc11_neon, export=1 + push {r0, r1, r4, r11, lr} +\type\()_h264_qpel16_mc11: + lowpass_const r3 + mov r11, sp +A bic sp, sp, #15 +T bic r0, r11, #15 +T mov sp, r0 + sub sp, sp, #256 + mov r0, sp + sub r1, r1, #2 + mov r3, #16 + vpush {d8-d15} + bl put_h264_qpel16_h_lowpass_neon + ldrd r0, r1, [r11], #8 + mov r3, r2 + add r12, sp, #64 + sub r1, r1, r2, lsl #1 + mov r2, #16 + bl \type\()_h264_qpel16_v_lowpass_l2_neon + vpop {d8-d15} + mov sp, r11 + pop {r4, r11, pc} +endfunc + +function ff_\type\()_h264_qpel16_mc21_neon, export=1 + push {r0, r1, r4-r5, r9-r11, lr} +\type\()_h264_qpel16_mc21: + lowpass_const r3 + mov r11, sp +A bic sp, sp, #15 +T bic r0, r11, #15 +T mov sp, r0 + sub sp, sp, #(16*16+16*12) + sub r1, r1, #2 + mov r0, sp + vpush {d8-d15} + bl put_h264_qpel16_h_lowpass_neon_packed + mov r4, r0 + ldrd r0, r1, [r11], #8 + sub r1, r1, r2, lsl #1 + sub r1, r1, #2 + mov r3, r2 + bl \type\()_h264_qpel16_hv_lowpass_l2_neon + vpop {d8-d15} + mov sp, r11 + pop {r4-r5, r9-r11, pc} +endfunc + +function ff_\type\()_h264_qpel16_mc31_neon, export=1 + add r1, r1, #1 + push {r0, r1, r4, r11, lr} + sub r1, r1, #1 + b \type\()_h264_qpel16_mc11 +endfunc + +function ff_\type\()_h264_qpel16_mc02_neon, export=1 + push {r4, lr} + lowpass_const r3 + sub r1, r1, r2, lsl #1 + mov r3, r2 + vpush {d8-d15} + bl \type\()_h264_qpel16_v_lowpass_neon + vpop {d8-d15} + pop {r4, pc} +endfunc + +function ff_\type\()_h264_qpel16_mc12_neon, export=1 + push {r0, r1, r4-r5, r9-r11, lr} +\type\()_h264_qpel16_mc12: + lowpass_const r3 + mov r11, sp +A bic sp, sp, #15 +T bic r0, r11, #15 +T mov sp, r0 + sub sp, sp, #(16*16+16*12) + sub r1, r1, r2, lsl #1 + mov r0, sp + mov r3, r2 + vpush {d8-d15} + bl put_h264_qpel16_v_lowpass_neon_packed + mov r4, r0 + ldrd r0, r1, [r11], #8 + sub r1, r1, r3, lsl #1 + sub r1, r1, #2 + mov r2, r3 + bl \type\()_h264_qpel16_hv_lowpass_l2_neon + vpop {d8-d15} + mov sp, r11 + pop {r4-r5, r9-r11, pc} +endfunc + +function ff_\type\()_h264_qpel16_mc22_neon, export=1 + push {r4, r9-r11, lr} + lowpass_const r3 + mov r11, sp +A bic sp, sp, #15 +T bic r4, r11, #15 +T mov sp, r4 + sub r1, r1, r2, lsl #1 + sub r1, r1, #2 + mov r3, r2 + sub sp, sp, #(16*12) + mov r4, sp + vpush {d8-d15} + bl \type\()_h264_qpel16_hv_lowpass_neon + vpop {d8-d15} + mov sp, r11 + pop {r4, r9-r11, pc} +endfunc + +function ff_\type\()_h264_qpel16_mc32_neon, export=1 + push {r0, r1, r4-r5, r9-r11, lr} + add r1, r1, #1 + b \type\()_h264_qpel16_mc12 +endfunc + +function ff_\type\()_h264_qpel16_mc03_neon, export=1 + push {r4, lr} + add r12, r1, r2 + b \type\()_h264_qpel16_mc01 +endfunc + +function ff_\type\()_h264_qpel16_mc13_neon, export=1 + push {r0, r1, r4, r11, lr} + add r1, r1, r2 + b \type\()_h264_qpel16_mc11 +endfunc + +function ff_\type\()_h264_qpel16_mc23_neon, export=1 + push {r0, r1, r4-r5, r9-r11, lr} + add r1, r1, r2 + b \type\()_h264_qpel16_mc21 +endfunc + +function ff_\type\()_h264_qpel16_mc33_neon, export=1 + add r1, r1, #1 + push {r0, r1, r4, r11, lr} + add r1, r1, r2 + sub r1, r1, #1 + b \type\()_h264_qpel16_mc11 +endfunc +.endm + + h264_qpel16 put + h264_qpel16 avg diff --git a/mythtv/external/FFmpeg/libavcodec/arm/jrevdct_arm.S b/mythtv/external/FFmpeg/libavcodec/arm/jrevdct_arm.S index 331ad85328b..f951e2af34e 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/jrevdct_arm.S +++ b/mythtv/external/FFmpeg/libavcodec/arm/jrevdct_arm.S @@ -66,7 +66,7 @@ row_loop: ldrsh r2, [lr, # 2] @ r2 = 'd2' @ Optimization for row that have all items except the first set to 0 - @ (this works as the DCTELEMS are always 4-byte aligned) + @ (this works as the int16_t are always 4-byte aligned) ldr r5, [lr, # 0] ldr r6, [lr, # 4] ldr r3, [lr, # 8] diff --git a/mythtv/external/FFmpeg/libavcodec/arm/mpegaudiodsp_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/mpegaudiodsp_init_arm.c index a9804e976c5..e73aee6a2bb 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/mpegaudiodsp_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/mpegaudiodsp_init_arm.c @@ -20,6 +20,7 @@ #include +#include "libavutil/attributes.h" #include "libavutil/arm/cpu.h" #include "libavcodec/mpegaudiodsp.h" #include "config.h" @@ -27,7 +28,7 @@ void ff_mpadsp_apply_window_fixed_armv6(int32_t *synth_buf, int32_t *window, int *dither, int16_t *out, int incr); -void ff_mpadsp_init_arm(MPADSPContext *s) +av_cold void ff_mpadsp_init_arm(MPADSPContext *s) { int cpu_flags = av_get_cpu_flags(); diff --git a/mythtv/external/FFmpeg/libavcodec/arm/mpegvideo_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/mpegvideo_arm.c index 28838bb0398..656679809b0 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/mpegvideo_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/mpegvideo_arm.c @@ -20,7 +20,6 @@ #include "libavutil/arm/cpu.h" #include "libavcodec/avcodec.h" -#include "libavcodec/dsputil.h" #include "libavcodec/mpegvideo.h" #include "mpegvideo_arm.h" #include "asm-offsets.h" @@ -34,12 +33,12 @@ CHK_OFFS(MpegEncContext, inter_scantable.raster_end, INTER_SCANTAB_RASTER_END); CHK_OFFS(MpegEncContext, h263_aic, H263_AIC); #endif -void ff_dct_unquantize_h263_inter_neon(MpegEncContext *s, DCTELEM *block, +void ff_dct_unquantize_h263_inter_neon(MpegEncContext *s, int16_t *block, int n, int qscale); -void ff_dct_unquantize_h263_intra_neon(MpegEncContext *s, DCTELEM *block, +void ff_dct_unquantize_h263_intra_neon(MpegEncContext *s, int16_t *block, int n, int qscale); -void ff_MPV_common_init_arm(MpegEncContext *s) +av_cold void ff_MPV_common_init_arm(MpegEncContext *s) { int cpu_flags = av_get_cpu_flags(); diff --git a/mythtv/external/FFmpeg/libavcodec/arm/mpegvideo_armv5te.c b/mythtv/external/FFmpeg/libavcodec/arm/mpegvideo_armv5te.c index 842620bad72..a5722900a82 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/mpegvideo_armv5te.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/mpegvideo_armv5te.c @@ -19,13 +19,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/attributes.h" #include "libavutil/avassert.h" #include "libavcodec/avcodec.h" -#include "libavcodec/dsputil.h" #include "libavcodec/mpegvideo.h" #include "mpegvideo_arm.h" -void ff_dct_unquantize_h263_armv5te(DCTELEM *block, int qmul, int qadd, int count); +void ff_dct_unquantize_h263_armv5te(int16_t *block, int qmul, int qadd, int count); #ifdef ENABLE_ARM_TESTS /** @@ -33,7 +33,7 @@ void ff_dct_unquantize_h263_armv5te(DCTELEM *block, int qmul, int qadd, int coun * have optimized implementations for each architecture. Is also used as a reference * implementation in regression tests */ -static inline void dct_unquantize_h263_helper_c(DCTELEM *block, int qmul, int qadd, int count) +static inline void dct_unquantize_h263_helper_c(int16_t *block, int qmul, int qadd, int count) { int i, level; for (i = 0; i < count; i++) { @@ -51,7 +51,7 @@ static inline void dct_unquantize_h263_helper_c(DCTELEM *block, int qmul, int qa #endif static void dct_unquantize_h263_intra_armv5te(MpegEncContext *s, - DCTELEM *block, int n, int qscale) + int16_t *block, int n, int qscale) { int level, qmul, qadd; int nCoeffs; @@ -80,7 +80,7 @@ static void dct_unquantize_h263_intra_armv5te(MpegEncContext *s, } static void dct_unquantize_h263_inter_armv5te(MpegEncContext *s, - DCTELEM *block, int n, int qscale) + int16_t *block, int n, int qscale) { int qmul, qadd; int nCoeffs; @@ -95,7 +95,7 @@ static void dct_unquantize_h263_inter_armv5te(MpegEncContext *s, ff_dct_unquantize_h263_armv5te(block, qmul, qadd, nCoeffs + 1); } -void ff_MPV_common_init_armv5te(MpegEncContext *s) +av_cold void ff_MPV_common_init_armv5te(MpegEncContext *s) { s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_armv5te; s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_armv5te; diff --git a/mythtv/external/FFmpeg/libavcodec/arm/rv34dsp_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/rv34dsp_init_arm.c index 60ab82eed47..8bfe90b3d33 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/rv34dsp_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/rv34dsp_init_arm.c @@ -20,18 +20,19 @@ #include +#include "libavutil/attributes.h" #include "libavcodec/avcodec.h" #include "libavcodec/rv34dsp.h" #include "libavutil/arm/cpu.h" -void ff_rv34_inv_transform_noround_neon(DCTELEM *block); +void ff_rv34_inv_transform_noround_neon(int16_t *block); -void ff_rv34_inv_transform_noround_dc_neon(DCTELEM *block); +void ff_rv34_inv_transform_noround_dc_neon(int16_t *block); -void ff_rv34_idct_add_neon(uint8_t *dst, ptrdiff_t stride, DCTELEM *block); +void ff_rv34_idct_add_neon(uint8_t *dst, ptrdiff_t stride, int16_t *block); void ff_rv34_idct_dc_add_neon(uint8_t *dst, ptrdiff_t stride, int dc); -void ff_rv34dsp_init_arm(RV34DSPContext *c, DSPContext* dsp) +av_cold void ff_rv34dsp_init_arm(RV34DSPContext *c) { int cpu_flags = av_get_cpu_flags(); diff --git a/mythtv/external/FFmpeg/libavcodec/arm/rv34dsp_neon.S b/mythtv/external/FFmpeg/libavcodec/arm/rv34dsp_neon.S index 522e387582b..a29123f7722 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/rv34dsp_neon.S +++ b/mythtv/external/FFmpeg/libavcodec/arm/rv34dsp_neon.S @@ -67,7 +67,7 @@ vsub.s32 q15, q14, q9 @ z0 - z3 .endm -/* void rv34_idct_add_c(uint8_t *dst, int stride, DCTELEM *block) */ +/* void rv34_idct_add_c(uint8_t *dst, int stride, int16_t *block) */ function ff_rv34_idct_add_neon, export=1 mov r3, r0 rv34_inv_transform r2 @@ -97,7 +97,7 @@ function ff_rv34_idct_add_neon, export=1 bx lr endfunc -/* void rv34_inv_transform_noround_neon(DCTELEM *block); */ +/* void rv34_inv_transform_noround_neon(int16_t *block); */ function ff_rv34_inv_transform_noround_neon, export=1 rv34_inv_transform r0 vshl.s32 q11, q2, #1 @@ -142,7 +142,7 @@ function ff_rv34_idct_dc_add_neon, export=1 bx lr endfunc -/* void rv34_inv_transform_dc_noround_c(DCTELEM *block) */ +/* void rv34_inv_transform_dc_noround_c(int16_t *block) */ function ff_rv34_inv_transform_noround_dc_neon, export=1 vld1.16 {d28[]}, [r0,:16] @ block[0] vmov.i16 d4, #251 diff --git a/mythtv/external/FFmpeg/libavcodec/arm/rv40dsp_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/rv40dsp_init_arm.c index 1f9364ad618..59ef10b24b5 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/rv40dsp_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/rv40dsp_init_arm.c @@ -20,6 +20,7 @@ #include +#include "libavutil/attributes.h" #include "libavcodec/avcodec.h" #include "libavcodec/rv34dsp.h" #include "libavutil/arm/cpu.h" @@ -69,7 +70,7 @@ void ff_rv40_v_weak_loop_filter_neon(uint8_t *src, ptrdiff_t stride, int filter_ int filter_q1, int alpha, int beta, int lim_p0q0, int lim_q1, int lim_p1); -static void ff_rv40dsp_init_neon(RV34DSPContext *c) +static av_cold void ff_rv40dsp_init_neon(RV34DSPContext *c) { c->put_pixels_tab[0][ 1] = ff_put_rv40_qpel16_mc10_neon; c->put_pixels_tab[0][ 3] = ff_put_rv40_qpel16_mc30_neon; @@ -138,7 +139,7 @@ static void ff_rv40dsp_init_neon(RV34DSPContext *c) c->rv40_weak_loop_filter[1] = ff_rv40_v_weak_loop_filter_neon; } -void ff_rv40dsp_init_arm(RV34DSPContext *c, DSPContext* dsp) +av_cold void ff_rv40dsp_init_arm(RV34DSPContext *c) { int cpu_flags = av_get_cpu_flags(); diff --git a/mythtv/external/FFmpeg/libavcodec/arm/simple_idct_armv6.S b/mythtv/external/FFmpeg/libavcodec/arm/simple_idct_armv6.S index 0c19d267a81..79cf5d41fb6 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/simple_idct_armv6.S +++ b/mythtv/external/FFmpeg/libavcodec/arm/simple_idct_armv6.S @@ -375,7 +375,7 @@ endfunc sub r0, r0, #(16*7) .endm -/* void ff_simple_idct_armv6(DCTELEM *data); */ +/* void ff_simple_idct_armv6(int16_t *data); */ function ff_simple_idct_armv6, export=1 push {r4-r11, lr} sub sp, sp, #128 @@ -390,7 +390,7 @@ function ff_simple_idct_armv6, export=1 pop {r4-r11, pc} endfunc -/* ff_simple_idct_add_armv6(uint8_t *dest, int line_size, DCTELEM *data); */ +/* ff_simple_idct_add_armv6(uint8_t *dest, int line_size, int16_t *data); */ function ff_simple_idct_add_armv6, export=1 push {r0, r1, r4-r11, lr} sub sp, sp, #128 @@ -407,7 +407,7 @@ function ff_simple_idct_add_armv6, export=1 pop {r4-r11, pc} endfunc -/* ff_simple_idct_put_armv6(uint8_t *dest, int line_size, DCTELEM *data); */ +/* ff_simple_idct_put_armv6(uint8_t *dest, int line_size, int16_t *data); */ function ff_simple_idct_put_armv6, export=1 push {r0, r1, r4-r11, lr} sub sp, sp, #128 diff --git a/mythtv/external/FFmpeg/libavcodec/arm/simple_idct_neon.S b/mythtv/external/FFmpeg/libavcodec/arm/simple_idct_neon.S index a8fc13768ea..c3e573c00a8 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/simple_idct_neon.S +++ b/mythtv/external/FFmpeg/libavcodec/arm/simple_idct_neon.S @@ -261,7 +261,7 @@ endconst pop {r4-r7, pc} .endm -/* void ff_simple_idct_put_neon(uint8_t *dst, int line_size, DCTELEM *data); */ +/* void ff_simple_idct_put_neon(uint8_t *dst, int line_size, int16_t *data); */ function ff_simple_idct_put_neon, export=1 idct_start r2 @@ -316,7 +316,7 @@ function idct_col4_add8_neon bx lr endfunc -/* void ff_simple_idct_add_neon(uint8_t *dst, int line_size, DCTELEM *data); */ +/* void ff_simple_idct_add_neon(uint8_t *dst, int line_size, int16_t *data); */ function ff_simple_idct_add_neon, export=1 idct_start r2 @@ -355,7 +355,7 @@ function idct_col4_st16_neon bx lr endfunc -/* void ff_simple_idct_neon(DCTELEM *data); */ +/* void ff_simple_idct_neon(int16_t *data); */ function ff_simple_idct_neon, export=1 idct_start r0 diff --git a/mythtv/external/FFmpeg/libavcodec/arm/videodsp_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/videodsp_init_arm.c index 6ce8788b0d2..a89abb25d58 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/videodsp_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/videodsp_init_arm.c @@ -18,11 +18,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/attributes.h" #include "libavutil/arm/cpu.h" #include "libavcodec/videodsp.h" #include "videodsp_arm.h" -void ff_videodsp_init_arm(VideoDSPContext *ctx, int bpc) +av_cold void ff_videodsp_init_arm(VideoDSPContext *ctx, int bpc) { int cpu_flags = av_get_cpu_flags(); if (have_armv5te(cpu_flags)) ff_videodsp_init_armv5te(ctx, bpc); diff --git a/mythtv/external/FFmpeg/libavcodec/arm/videodsp_init_armv5te.c b/mythtv/external/FFmpeg/libavcodec/arm/videodsp_init_armv5te.c index d11a07061be..1ea1f3438d3 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/videodsp_init_armv5te.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/videodsp_init_armv5te.c @@ -18,13 +18,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/attributes.h" #include "libavutil/arm/cpu.h" #include "libavcodec/videodsp.h" #include "videodsp_arm.h" void ff_prefetch_arm(uint8_t *mem, ptrdiff_t stride, int h); -void ff_videodsp_init_armv5te(VideoDSPContext *ctx, int bpc) +av_cold void ff_videodsp_init_armv5te(VideoDSPContext *ctx, int bpc) { #if HAVE_ARMV5TE_EXTERNAL ctx->prefetch = ff_prefetch_arm; diff --git a/mythtv/external/FFmpeg/libavcodec/arm/vorbisdsp_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/vorbisdsp_init_arm.c new file mode 100644 index 00000000000..f4b3d80ef60 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/arm/vorbisdsp_init_arm.c @@ -0,0 +1,37 @@ +/* + * ARM NEON optimised DSP functions + * Copyright (c) 2008 Mans Rullgard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/attributes.h" +#include "libavutil/cpu.h" +#include "libavutil/arm/cpu.h" +#include "libavcodec/vorbisdsp.h" + +void ff_vorbis_inverse_coupling_neon(float *mag, float *ang, + intptr_t blocksize); + +av_cold void ff_vorbisdsp_init_arm(VorbisDSPContext *c) +{ + int cpu_flags = av_get_cpu_flags(); + + if (have_neon(cpu_flags)) { + c->vorbis_inverse_coupling = ff_vorbis_inverse_coupling_neon; + } +} diff --git a/mythtv/external/FFmpeg/libavcodec/arm/vorbisdsp_neon.S b/mythtv/external/FFmpeg/libavcodec/arm/vorbisdsp_neon.S new file mode 100644 index 00000000000..79ce54f938b --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/arm/vorbisdsp_neon.S @@ -0,0 +1,83 @@ +/* + * ARM NEON optimised DSP functions + * Copyright (c) 2008 Mans Rullgard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/arm/asm.S" + +function ff_vorbis_inverse_coupling_neon, export=1 + vmov.i32 q10, #1<<31 + subs r2, r2, #4 + mov r3, r0 + mov r12, r1 + beq 3f + + vld1.32 {d24-d25},[r1,:128]! + vld1.32 {d22-d23},[r0,:128]! + vcle.s32 q8, q12, #0 + vand q9, q11, q10 + veor q12, q12, q9 + vand q2, q12, q8 + vbic q3, q12, q8 + vadd.f32 q12, q11, q2 + vsub.f32 q11, q11, q3 +1: vld1.32 {d2-d3}, [r1,:128]! + vld1.32 {d0-d1}, [r0,:128]! + vcle.s32 q8, q1, #0 + vand q9, q0, q10 + veor q1, q1, q9 + vst1.32 {d24-d25},[r3, :128]! + vst1.32 {d22-d23},[r12,:128]! + vand q2, q1, q8 + vbic q3, q1, q8 + vadd.f32 q1, q0, q2 + vsub.f32 q0, q0, q3 + subs r2, r2, #8 + ble 2f + vld1.32 {d24-d25},[r1,:128]! + vld1.32 {d22-d23},[r0,:128]! + vcle.s32 q8, q12, #0 + vand q9, q11, q10 + veor q12, q12, q9 + vst1.32 {d2-d3}, [r3, :128]! + vst1.32 {d0-d1}, [r12,:128]! + vand q2, q12, q8 + vbic q3, q12, q8 + vadd.f32 q12, q11, q2 + vsub.f32 q11, q11, q3 + b 1b + +2: vst1.32 {d2-d3}, [r3, :128]! + vst1.32 {d0-d1}, [r12,:128]! + it lt + bxlt lr + +3: vld1.32 {d2-d3}, [r1,:128] + vld1.32 {d0-d1}, [r0,:128] + vcle.s32 q8, q1, #0 + vand q9, q0, q10 + veor q1, q1, q9 + vand q2, q1, q8 + vbic q3, q1, q8 + vadd.f32 q1, q0, q2 + vsub.f32 q0, q0, q3 + vst1.32 {d2-d3}, [r0,:128]! + vst1.32 {d0-d1}, [r1,:128]! + bx lr +endfunc diff --git a/mythtv/external/FFmpeg/libavcodec/arm/vp3dsp_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/vp3dsp_init_arm.c index 90fc34b2186..5ffc8fd440f 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/vp3dsp_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/vp3dsp_init_arm.c @@ -21,11 +21,12 @@ #include "libavutil/attributes.h" #include "libavutil/cpu.h" #include "libavutil/arm/cpu.h" +#include "libavcodec/dsputil.h" #include "libavcodec/vp3dsp.h" -void ff_vp3_idct_put_neon(uint8_t *dest, int line_size, DCTELEM *data); -void ff_vp3_idct_add_neon(uint8_t *dest, int line_size, DCTELEM *data); -void ff_vp3_idct_dc_add_neon(uint8_t *dest, int line_size, const DCTELEM *data); +void ff_vp3_idct_put_neon(uint8_t *dest, int line_size, int16_t *data); +void ff_vp3_idct_add_neon(uint8_t *dest, int line_size, int16_t *data); +void ff_vp3_idct_dc_add_neon(uint8_t *dest, int line_size, const int16_t *data); void ff_vp3_v_loop_filter_neon(uint8_t *, int, int *); void ff_vp3_h_loop_filter_neon(uint8_t *, int, int *); diff --git a/mythtv/external/FFmpeg/libavcodec/arm/vp3dsp_neon.S b/mythtv/external/FFmpeg/libavcodec/arm/vp3dsp_neon.S index 0c88562b458..f133905efec 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/vp3dsp_neon.S +++ b/mythtv/external/FFmpeg/libavcodec/arm/vp3dsp_neon.S @@ -108,14 +108,20 @@ endfunc function vp3_idct_start_neon vpush {d8-d15} + vmov.i16 q4, #0 + vmov.i16 q5, #0 movrel r3, vp3_idct_constants vld1.64 {d0-d1}, [r3,:128] - vld1.64 {d16-d19}, [r2,:128]! - vld1.64 {d20-d23}, [r2,:128]! - vld1.64 {d24-d27}, [r2,:128]! + vld1.64 {d16-d19}, [r2,:128] + vst1.64 {q4-q5}, [r2,:128]! + vld1.64 {d20-d23}, [r2,:128] + vst1.64 {q4-q5}, [r2,:128]! + vld1.64 {d24-d27}, [r2,:128] + vst1.64 {q4-q5}, [r2,:128]! vadd.s16 q1, q8, q12 vsub.s16 q8, q8, q12 - vld1.64 {d28-d31}, [r2,:128]! + vld1.64 {d28-d31}, [r2,:128] + vst1.64 {q4-q5}, [r2,:128]! vp3_idct_core_neon: vmull.s16 q2, d18, xC1S7 // (ip[1] * C1) << 16 @@ -345,10 +351,12 @@ function ff_vp3_idct_add_neon, export=1 endfunc function ff_vp3_idct_dc_add_neon, export=1 - ldrsh r2, [r2] + ldrsh r12, [r2] mov r3, r0 - add r2, r2, #15 - vdup.16 q15, r2 + add r12, r12, #15 + vdup.16 q15, r12 + mov r12, 0 + strh r12, [r2] vshr.s16 q15, q15, #5 vld1.8 {d0}, [r0,:64], r1 diff --git a/mythtv/external/FFmpeg/libavcodec/arm/vp56dsp_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/vp56dsp_init_arm.c index 13046535d9b..f53cbae1edf 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/vp56dsp_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/vp56dsp_init_arm.c @@ -20,6 +20,7 @@ #include +#include "libavutil/attributes.h" #include "libavutil/arm/cpu.h" #include "libavcodec/avcodec.h" #include "libavcodec/vp56dsp.h" @@ -27,7 +28,7 @@ void ff_vp6_edge_filter_hor_neon(uint8_t *yuv, int stride, int t); void ff_vp6_edge_filter_ver_neon(uint8_t *yuv, int stride, int t); -void ff_vp56dsp_init_arm(VP56DSPContext *s, enum AVCodecID codec) +av_cold void ff_vp56dsp_init_arm(VP56DSPContext *s, enum AVCodecID codec) { int cpu_flags = av_get_cpu_flags(); diff --git a/mythtv/external/FFmpeg/libavcodec/arm/vp8.h b/mythtv/external/FFmpeg/libavcodec/arm/vp8.h index 7574a51f50e..ddaa1203fd4 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/vp8.h +++ b/mythtv/external/FFmpeg/libavcodec/arm/vp8.h @@ -19,11 +19,15 @@ #ifndef AVCODEC_ARM_VP8_H #define AVCODEC_ARM_VP8_H +#include + #include "config.h" +#include "libavcodec/vp56.h" +#include "libavcodec/vp8.h" #if HAVE_ARMV6_EXTERNAL #define decode_block_coeffs_internal ff_decode_block_coeffs_armv6 -int ff_decode_block_coeffs_armv6(VP56RangeCoder *rc, DCTELEM block[16], +int ff_decode_block_coeffs_armv6(VP56RangeCoder *rc, int16_t block[16], uint8_t probs[8][3][NUM_DCT_TOKENS-1], int i, uint8_t *token_prob, int16_t qmul[2]); #endif diff --git a/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_armv6.S b/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_armv6.S index 4047aabc135..52077582cde 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_armv6.S +++ b/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_armv6.S @@ -56,7 +56,7 @@ @ idct -@ void vp8_luma_dc_wht(DCTELEM block[4][4][16], DCTELEM dc[16]) +@ void vp8_luma_dc_wht(int16_t block[4][4][16], int16_t dc[16]) function ff_vp8_luma_dc_wht_armv6, export=1 push {r4-r10, lr} @@ -179,7 +179,7 @@ function ff_vp8_luma_dc_wht_armv6, export=1 pop {r4-r10, pc} endfunc -@ void vp8_luma_dc_wht_dc(DCTELEM block[4][4][16], DCTELEM dc[16]) +@ void vp8_luma_dc_wht_dc(int16_t block[4][4][16], int16_t dc[16]) function ff_vp8_luma_dc_wht_dc_armv6, export=1 ldrsh r2, [r1] mov r3, #0 @@ -192,7 +192,7 @@ function ff_vp8_luma_dc_wht_dc_armv6, export=1 bx lr endfunc -@ void vp8_idct_add(uint8_t *dst, DCTELEM block[16], int stride) +@ void vp8_idct_add(uint8_t *dst, int16_t block[16], int stride) function ff_vp8_idct_add_armv6, export=1 push {r4-r12, lr} sub sp, sp, #32 @@ -314,7 +314,7 @@ function ff_vp8_idct_add_armv6, export=1 pop {r4-r12, pc} endfunc -@ void vp8_idct_dc_add(uint8_t *dst, DCTELEM block[16], int stride) +@ void vp8_idct_dc_add(uint8_t *dst, int16_t block[16], int stride) function ff_vp8_idct_dc_add_armv6, export=1 push {r4-r6, lr} add r6, r0, r2, lsl #1 @@ -355,7 +355,7 @@ function ff_vp8_idct_dc_add_armv6, export=1 pop {r4-r6, pc} endfunc -@ void vp8_idct_dc_add4uv(uint8_t *dst, DCTELEM block[4][16], int stride) +@ void vp8_idct_dc_add4uv(uint8_t *dst, int16_t block[4][16], int stride) function ff_vp8_idct_dc_add4uv_armv6, export=1 push {r4, lr} @@ -371,7 +371,7 @@ function ff_vp8_idct_dc_add4uv_armv6, export=1 pop {r4, pc} endfunc -@ void vp8_idct_dc_add4y(uint8_t *dst, DCTELEM block[4][16], int stride) +@ void vp8_idct_dc_add4y(uint8_t *dst, int16_t block[4][16], int stride) function ff_vp8_idct_dc_add4y_armv6, export=1 push {r4, lr} diff --git a/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_init_arm.c b/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_init_arm.c index 5c84ed32311..d360ae3e6dc 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_init_arm.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_init_arm.c @@ -18,6 +18,7 @@ #include +#include "libavutil/attributes.h" #include "libavutil/arm/cpu.h" #include "libavcodec/vp8dsp.h" #include "vp8dsp.h" diff --git a/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_init_armv6.c b/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_init_armv6.c index 85a803af839..e15e191e300 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_init_armv6.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_init_armv6.c @@ -17,16 +17,18 @@ */ #include + +#include "libavutil/attributes.h" #include "libavcodec/vp8dsp.h" #include "vp8dsp.h" -void ff_vp8_luma_dc_wht_armv6(DCTELEM block[4][4][16], DCTELEM dc[16]); -void ff_vp8_luma_dc_wht_dc_armv6(DCTELEM block[4][4][16], DCTELEM dc[16]); +void ff_vp8_luma_dc_wht_armv6(int16_t block[4][4][16], int16_t dc[16]); +void ff_vp8_luma_dc_wht_dc_armv6(int16_t block[4][4][16], int16_t dc[16]); -void ff_vp8_idct_add_armv6(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride); -void ff_vp8_idct_dc_add_armv6(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride); -void ff_vp8_idct_dc_add4y_armv6(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride); -void ff_vp8_idct_dc_add4uv_armv6(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride); +void ff_vp8_idct_add_armv6(uint8_t *dst, int16_t block[16], ptrdiff_t stride); +void ff_vp8_idct_dc_add_armv6(uint8_t *dst, int16_t block[16], ptrdiff_t stride); +void ff_vp8_idct_dc_add4y_armv6(uint8_t *dst, int16_t block[4][16], ptrdiff_t stride); +void ff_vp8_idct_dc_add4uv_armv6(uint8_t *dst, int16_t block[4][16], ptrdiff_t stride); VP8_LF(armv6); diff --git a/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_init_neon.c b/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_init_neon.c index dbe5b9f961d..0468181f70e 100644 --- a/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_init_neon.c +++ b/mythtv/external/FFmpeg/libavcodec/arm/vp8dsp_init_neon.c @@ -17,15 +17,17 @@ */ #include + +#include "libavutil/attributes.h" #include "libavcodec/vp8dsp.h" #include "vp8dsp.h" -void ff_vp8_luma_dc_wht_neon(DCTELEM block[4][4][16], DCTELEM dc[16]); +void ff_vp8_luma_dc_wht_neon(int16_t block[4][4][16], int16_t dc[16]); -void ff_vp8_idct_add_neon(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride); -void ff_vp8_idct_dc_add_neon(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride); -void ff_vp8_idct_dc_add4y_neon(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride); -void ff_vp8_idct_dc_add4uv_neon(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride); +void ff_vp8_idct_add_neon(uint8_t *dst, int16_t block[16], ptrdiff_t stride); +void ff_vp8_idct_dc_add_neon(uint8_t *dst, int16_t block[16], ptrdiff_t stride); +void ff_vp8_idct_dc_add4y_neon(uint8_t *dst, int16_t block[4][16], ptrdiff_t stride); +void ff_vp8_idct_dc_add4uv_neon(uint8_t *dst, int16_t block[4][16], ptrdiff_t stride); VP8_LF(neon); diff --git a/mythtv/external/FFmpeg/libavcodec/ass_split.c b/mythtv/external/FFmpeg/libavcodec/ass_split.c index ddf4675acd6..413e9c8d06e 100644 --- a/mythtv/external/FFmpeg/libavcodec/ass_split.c +++ b/mythtv/external/FFmpeg/libavcodec/ass_split.c @@ -250,7 +250,9 @@ static const char *ass_split_section(ASSSplitContext *ctx, const char *buf) ptr = struct_ptr + section->fields[order[i]].offset; convert_func[type](ptr, buf, len); } - buf = skip_space(buf + len + !last); + buf += len; + if (!last && *buf) buf++; + buf = skip_space(buf); } } } else { @@ -283,14 +285,17 @@ static int ass_split(ASSSplitContext *ctx, const char *buf) while (buf && *buf) { if (sscanf(buf, "[%15[0-9A-Za-z+ ]]%c", section, &c) == 2) { - buf += strcspn(buf, "\n") + 1; + buf += strcspn(buf, "\n"); + buf += !!*buf; for (i=0; icurrent_section = i; buf = ass_split_section(ctx, buf); } - } else - buf += strcspn(buf, "\n") + 1; + } else { + buf += strcspn(buf, "\n"); + buf += !!*buf; + } } return buf ? 0 : AVERROR_INVALIDDATA; } diff --git a/mythtv/external/FFmpeg/libavcodec/asv.c b/mythtv/external/FFmpeg/libavcodec/asv.c index 34622b4e720..21f179bb778 100644 --- a/mythtv/external/FFmpeg/libavcodec/asv.c +++ b/mythtv/external/FFmpeg/libavcodec/asv.c @@ -27,7 +27,6 @@ #include "asv.h" #include "avcodec.h" -#include "dsputil.h" const uint8_t ff_asv_scantab[64] = { 0x00,0x08,0x01,0x09,0x10,0x18,0x11,0x19, diff --git a/mythtv/external/FFmpeg/libavcodec/asv.h b/mythtv/external/FFmpeg/libavcodec/asv.h index 4a6c7997383..ca67c67daa1 100644 --- a/mythtv/external/FFmpeg/libavcodec/asv.h +++ b/mythtv/external/FFmpeg/libavcodec/asv.h @@ -28,7 +28,6 @@ #include -#include "libavutil/attributes.h" #include "libavutil/mem.h" #include "avcodec.h" @@ -48,7 +47,7 @@ typedef struct ASV1Context{ int mb_height; int mb_width2; int mb_height2; - DECLARE_ALIGNED(16, DCTELEM, block)[6][64]; + DECLARE_ALIGNED(16, int16_t, block)[6][64]; uint16_t intra_matrix[64]; int q_intra_matrix[64]; uint8_t *bitstream_buffer; @@ -62,6 +61,6 @@ extern const uint8_t ff_asv_dc_ccp_tab[8][2]; extern const uint8_t ff_asv_ac_ccp_tab[16][2]; extern const uint8_t ff_asv2_level_tab[63][2]; -av_cold void ff_asv_common_init(AVCodecContext *avctx); +void ff_asv_common_init(AVCodecContext *avctx); #endif /* AVCODEC_ASV_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/asvdec.c b/mythtv/external/FFmpeg/libavcodec/asvdec.c index 7c3b30c8db6..e7a04cdd937 100644 --- a/mythtv/external/FFmpeg/libavcodec/asvdec.c +++ b/mythtv/external/FFmpeg/libavcodec/asvdec.c @@ -29,7 +29,6 @@ #include "asv.h" #include "avcodec.h" #include "put_bits.h" -#include "dsputil.h" #include "internal.h" #include "mathops.h" #include "mpeg12data.h" @@ -94,7 +93,7 @@ static inline int asv2_get_level(GetBitContext *gb) return code - 31; } -static inline int asv1_decode_block(ASV1Context *a, DCTELEM block[64]) +static inline int asv1_decode_block(ASV1Context *a, int16_t block[64]) { int i; @@ -108,7 +107,7 @@ static inline int asv1_decode_block(ASV1Context *a, DCTELEM block[64]) break; if (ccp < 0 || i >= 10) { av_log(a->avctx, AV_LOG_ERROR, "coded coeff pattern damaged\n"); - return -1; + return AVERROR_INVALIDDATA; } if (ccp & 8) @@ -125,7 +124,7 @@ static inline int asv1_decode_block(ASV1Context *a, DCTELEM block[64]) return 0; } -static inline int asv2_decode_block(ASV1Context *a, DCTELEM block[64]) +static inline int asv2_decode_block(ASV1Context *a, int16_t block[64]) { int i, count, ccp; @@ -161,7 +160,7 @@ static inline int asv2_decode_block(ASV1Context *a, DCTELEM block[64]) return 0; } -static inline int decode_mb(ASV1Context *a, DCTELEM block[6][64]) +static inline int decode_mb(ASV1Context *a, int16_t block[6][64]) { int i; @@ -183,7 +182,7 @@ static inline int decode_mb(ASV1Context *a, DCTELEM block[6][64]) static inline void idct_put(ASV1Context *a, int mb_x, int mb_y) { - DCTELEM (*block)[64] = a->block; + int16_t (*block)[64] = a->block; int linesize = a->picture.linesize[0]; uint8_t *dest_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16; @@ -210,15 +209,15 @@ static int decode_frame(AVCodecContext *avctx, int buf_size = avpkt->size; AVFrame *picture = data; AVFrame * const p = &a->picture; - int mb_x, mb_y; + int mb_x, mb_y, ret; if (p->data[0]) avctx->release_buffer(avctx, p); p->reference = 0; - if (ff_get_buffer(avctx, p) < 0) { + if ((ret = ff_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; @@ -240,8 +239,8 @@ static int decode_frame(AVCodecContext *avctx, for (mb_y = 0; mb_y < a->mb_height2; mb_y++) { for (mb_x = 0; mb_x < a->mb_width2; mb_x++) { - if (decode_mb(a, a->block) < 0) - return -1; + if ((ret = decode_mb(a, a->block)) < 0) + return ret; idct_put(a, mb_x, mb_y); } @@ -250,8 +249,8 @@ static int decode_frame(AVCodecContext *avctx, if (a->mb_width2 != a->mb_width) { mb_x = a->mb_width2; for (mb_y = 0; mb_y < a->mb_height2; mb_y++) { - if (decode_mb(a, a->block) < 0) - return -1; + if ((ret = decode_mb(a, a->block)) < 0) + return ret; idct_put(a, mb_x, mb_y); } @@ -260,8 +259,8 @@ static int decode_frame(AVCodecContext *avctx, if (a->mb_height2 != a->mb_height) { mb_y = a->mb_height2; for (mb_x = 0; mb_x < a->mb_width; mb_x++) { - if (decode_mb(a, a->block) < 0) - return -1; + if ((ret = decode_mb(a, a->block)) < 0) + return ret; idct_put(a, mb_x, mb_y); } diff --git a/mythtv/external/FFmpeg/libavcodec/asvenc.c b/mythtv/external/FFmpeg/libavcodec/asvenc.c index e5f3b48ea4d..a09aa73ce05 100644 --- a/mythtv/external/FFmpeg/libavcodec/asvenc.c +++ b/mythtv/external/FFmpeg/libavcodec/asvenc.c @@ -56,7 +56,7 @@ static inline void asv2_put_level(PutBitContext *pb, int level){ } } -static inline void asv1_encode_block(ASV1Context *a, DCTELEM block[64]){ +static inline void asv1_encode_block(ASV1Context *a, int16_t block[64]){ int i; int nc_count=0; @@ -89,7 +89,7 @@ static inline void asv1_encode_block(ASV1Context *a, DCTELEM block[64]){ put_bits(&a->pb, ff_asv_ccp_tab[16][1], ff_asv_ccp_tab[16][0]); } -static inline void asv2_encode_block(ASV1Context *a, DCTELEM block[64]){ +static inline void asv2_encode_block(ASV1Context *a, int16_t block[64]){ int i; int count=0; @@ -130,7 +130,7 @@ static inline void asv2_encode_block(ASV1Context *a, DCTELEM block[64]){ #define MAX_MB_SIZE (30*16*16*3/2/8) -static inline int encode_mb(ASV1Context *a, DCTELEM block[6][64]){ +static inline int encode_mb(ASV1Context *a, int16_t block[6][64]){ int i; if (a->pb.buf_end - a->pb.buf - (put_bits_count(&a->pb)>>3) < MAX_MB_SIZE) { @@ -149,7 +149,7 @@ static inline int encode_mb(ASV1Context *a, DCTELEM block[6][64]){ } static inline void dct_get(ASV1Context *a, int mb_x, int mb_y){ - DCTELEM (*block)[64]= a->block; + int16_t (*block)[64]= a->block; int linesize= a->picture.linesize[0]; int i; diff --git a/mythtv/external/FFmpeg/libavcodec/atrac.c b/mythtv/external/FFmpeg/libavcodec/atrac.c index cb2f7ba736b..ea342a04387 100644 --- a/mythtv/external/FFmpeg/libavcodec/atrac.c +++ b/mythtv/external/FFmpeg/libavcodec/atrac.c @@ -30,7 +30,6 @@ #include #include "avcodec.h" -#include "dsputil.h" #include "atrac.h" float ff_atrac_sf_table[64]; diff --git a/mythtv/external/FFmpeg/libavcodec/atrac1.c b/mythtv/external/FFmpeg/libavcodec/atrac1.c index e5b5b107712..72c1b508e78 100644 --- a/mythtv/external/FFmpeg/libavcodec/atrac1.c +++ b/mythtv/external/FFmpeg/libavcodec/atrac1.c @@ -32,9 +32,9 @@ #include #include +#include "libavutil/float_dsp.h" #include "avcodec.h" #include "get_bits.h" -#include "dsputil.h" #include "fft.h" #include "internal.h" #include "sinewin.h" @@ -72,7 +72,6 @@ typedef struct { * The atrac1 context, holds all needed parameters for decoding */ typedef struct { - AVFrame frame; AT1SUCtx SUs[AT1_MAX_CHANNELS]; ///< channel sound unit DECLARE_ALIGNED(32, float, spec)[AT1_SU_SAMPLES]; ///< the mdct spectrum buffer @@ -81,7 +80,7 @@ typedef struct { DECLARE_ALIGNED(32, float, high)[512]; float* bands[3]; FFTContext mdct_ctx[3]; - DSPContext dsp; + AVFloatDSPContext fdsp; } AT1Ctx; /** size of the transform in samples in the long mode for each QMF band */ @@ -141,8 +140,8 @@ static int at1_imdct_block(AT1SUCtx* su, AT1Ctx *q) at1_imdct(q, &q->spec[pos], &su->spectrum[0][ref_pos + start_pos], nbits, band_num); /* overlap and window */ - q->dsp.vector_fmul_window(&q->bands[band_num][start_pos], prev_buf, - &su->spectrum[0][ref_pos + start_pos], ff_sine_32, 16); + q->fdsp.vector_fmul_window(&q->bands[band_num][start_pos], prev_buf, + &su->spectrum[0][ref_pos + start_pos], ff_sine_32, 16); prev_buf = &su->spectrum[0][ref_pos+start_pos + 16]; start_pos += block_size; @@ -273,6 +272,7 @@ static void at1_subband_synthesis(AT1Ctx *q, AT1SUCtx* su, float *pOut) static int atrac1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AT1Ctx *q = avctx->priv_data; @@ -286,8 +286,8 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - q->frame.nb_samples = AT1_SU_SAMPLES; - if ((ret = ff_get_buffer(avctx, &q->frame)) < 0) { + frame->nb_samples = AT1_SU_SAMPLES; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -309,11 +309,10 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data, ret = at1_imdct_block(su, q); if (ret < 0) return ret; - at1_subband_synthesis(q, su, (float *)q->frame.extended_data[ch]); + at1_subband_synthesis(q, su, (float *)frame->extended_data[ch]); } - *got_frame_ptr = 1; - *(AVFrame *)data = q->frame; + *got_frame_ptr = 1; return avctx->block_align; } @@ -362,7 +361,7 @@ static av_cold int atrac1_decode_init(AVCodecContext *avctx) ff_atrac_generate_tables(); - ff_dsputil_init(&q->dsp, avctx); + avpriv_float_dsp_init(&q->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); q->bands[0] = q->low; q->bands[1] = q->mid; @@ -374,9 +373,6 @@ static av_cold int atrac1_decode_init(AVCodecContext *avctx) q->SUs[1].spectrum[0] = q->SUs[1].spec1; q->SUs[1].spectrum[1] = q->SUs[1].spec2; - avcodec_get_frame_defaults(&q->frame); - avctx->coded_frame = &q->frame; - return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/atrac3.c b/mythtv/external/FFmpeg/libavcodec/atrac3.c index c1518a733f0..62165363639 100644 --- a/mythtv/external/FFmpeg/libavcodec/atrac3.c +++ b/mythtv/external/FFmpeg/libavcodec/atrac3.c @@ -87,7 +87,6 @@ typedef struct ChannelUnit { } ChannelUnit; typedef struct ATRAC3Context { - AVFrame frame; GetBitContext gb; //@{ /** stream data */ @@ -165,10 +164,7 @@ static int decode_bytes(const uint8_t *input, uint8_t *out, int bytes) off = (intptr_t)input & 3; buf = (const uint32_t *)(input - off); - if (off) - c = av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8)))); - else - c = av_be2ne32(0x537F6103U); + c = av_be2ne32((0x537F6103 >> (off * 8)) | (0x537F6103 << (32 - (off * 8)))); bytes += 3 + off; for (i = 0; i < bytes / 4; i++) output[i] = c ^ buf[i]; @@ -743,7 +739,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, /* set the bitstream reader at the start of the second Sound Unit*/ - init_get_bits(&q->gb, ptr1, avctx->block_align * 8); + init_get_bits8(&q->gb, ptr1, q->decoded_bytes_buffer + avctx->block_align - ptr1); /* Fill the Weighting coeffs delay buffer */ memmove(q->weighting_delay, &q->weighting_delay[2], @@ -802,6 +798,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, static int atrac3_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; ATRAC3Context *q = avctx->priv_data; @@ -815,8 +812,8 @@ static int atrac3_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - q->frame.nb_samples = SAMPLES_PER_FRAME; - if ((ret = ff_get_buffer(avctx, &q->frame)) < 0) { + frame->nb_samples = SAMPLES_PER_FRAME; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -829,14 +826,13 @@ static int atrac3_decode_frame(AVCodecContext *avctx, void *data, databuf = buf; } - ret = decode_frame(avctx, databuf, (float **)q->frame.extended_data); + ret = decode_frame(avctx, databuf, (float **)frame->extended_data); if (ret) { av_log(NULL, AV_LOG_ERROR, "Frame decoding error!\n"); return ret; } - *got_frame_ptr = 1; - *(AVFrame *)data = q->frame; + *got_frame_ptr = 1; return avctx->block_align; } @@ -911,7 +907,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) avctx->channels, frame_factor); return AVERROR_INVALIDDATA; } - } else if (avctx->extradata_size == 10) { + } else if (avctx->extradata_size == 12 || avctx->extradata_size == 10) { /* Parse the extradata, RM format. */ version = bytestream_get_be32(&edata_ptr); samples_per_frame = bytestream_get_be16(&edata_ptr); @@ -1000,9 +996,6 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) return AVERROR(ENOMEM); } - avcodec_get_frame_defaults(&q->frame); - avctx->coded_frame = &q->frame; - return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/audio_frame_queue.c b/mythtv/external/FFmpeg/libavcodec/audio_frame_queue.c index e21629695c8..ba6e22516cb 100644 --- a/mythtv/external/FFmpeg/libavcodec/audio_frame_queue.c +++ b/mythtv/external/FFmpeg/libavcodec/audio_frame_queue.c @@ -57,7 +57,7 @@ int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f) (AVRational){ 1, afq->avctx->sample_rate }); new->pts -= afq->remaining_delay; if(afq->frame_count && new[-1].pts >= new->pts) - av_log(afq->avctx, AV_LOG_WARNING, "Que input is backward in time\n"); + av_log(afq->avctx, AV_LOG_WARNING, "Queue input is backward in time\n"); } else { new->pts = AV_NOPTS_VALUE; } diff --git a/mythtv/external/FFmpeg/libavcodec/aura.c b/mythtv/external/FFmpeg/libavcodec/aura.c index cd4e42b6094..c591f2f6db5 100644 --- a/mythtv/external/FFmpeg/libavcodec/aura.c +++ b/mythtv/external/FFmpeg/libavcodec/aura.c @@ -39,7 +39,7 @@ static av_cold int aura_decode_init(AVCodecContext *avctx) s->avctx = avctx; /* width needs to be divisible by 4 for this codec to work */ if (avctx->width & 0x3) - return -1; + return AVERROR(EINVAL); avctx->pix_fmt = AV_PIX_FMT_YUV422P; avcodec_get_frame_defaults(&s->frame); @@ -53,7 +53,7 @@ static int aura_decode_frame(AVCodecContext *avctx, AuraDecodeContext *s = avctx->priv_data; uint8_t *Y, *U, *V; uint8_t val; - int x, y; + int x, y, ret; const uint8_t *buf = pkt->data; /* prediction error tables (make it clear that they are signed values) */ @@ -62,7 +62,7 @@ static int aura_decode_frame(AVCodecContext *avctx, if (pkt->size != 48 + avctx->height * avctx->width) { av_log(avctx, AV_LOG_ERROR, "got a buffer with %d bytes when %d were expected\n", pkt->size, 48 + avctx->height * avctx->width); - return -1; + return AVERROR_INVALIDDATA; } /* pixel data starts 48 bytes in, after 3x16-byte tables */ @@ -73,9 +73,9 @@ static int aura_decode_frame(AVCodecContext *avctx, s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; s->frame.reference = 0; - if (ff_get_buffer(avctx, &s->frame) < 0) { + if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } Y = s->frame.data[0]; diff --git a/mythtv/external/FFmpeg/libavcodec/avcodec.h b/mythtv/external/FFmpeg/libavcodec/avcodec.h index 2b62be598ef..f828f88fbbc 100644 --- a/mythtv/external/FFmpeg/libavcodec/avcodec.h +++ b/mythtv/external/FFmpeg/libavcodec/avcodec.h @@ -267,6 +267,7 @@ enum AVCodecID { AV_CODEC_ID_MTS2, AV_CODEC_ID_CLLC, AV_CODEC_ID_MSS2, + AV_CODEC_ID_VP9, AV_CODEC_ID_BRENDER_PIX= MKBETAG('B','P','I','X'), AV_CODEC_ID_Y41P = MKBETAG('Y','4','1','P'), AV_CODEC_ID_ESCAPE130 = MKBETAG('E','1','3','0'), @@ -447,6 +448,8 @@ enum AVCodecID { AV_CODEC_ID_PAF_AUDIO = MKBETAG('P','A','F','A'), AV_CODEC_ID_OPUS = MKBETAG('O','P','U','S'), AV_CODEC_ID_TAK = MKBETAG('t','B','a','K'), + AV_CODEC_ID_EVRC = MKBETAG('s','e','v','c'), + AV_CODEC_ID_SMV = MKBETAG('s','s','m','v'), /* subtitle codecs */ AV_CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs. @@ -544,6 +547,10 @@ typedef struct AVCodecDescriptor { * Codec supports lossless compression. Audio and video codecs only. */ #define AV_CODEC_PROP_LOSSLESS (1 << 2) +/** + * Subtitle codec is bitmap based + */ +#define AV_CODEC_PROP_BITMAP_SUB (1 << 16) #if FF_API_OLD_DECODE_AUDIO /* in bytes */ @@ -717,6 +724,8 @@ typedef struct RcOverride{ #define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding. #define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata. #define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. DEPRECATED!!!! +#define CODEC_FLAG2_IGNORE_CROP 0x00010000 ///< Discard cropping information from SPS. + #if FF_API_MPV_GLOBAL_OPTS #define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp. #define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon. @@ -985,6 +994,14 @@ enum AVPacketSideDataType { * @endcode */ AV_PKT_DATA_SUBTITLE_POSITION, + + /** + * Data found in BlockAdditional element of matroska container. There is + * no end marker for the data, so it is required to rely on the side data + * size to recognize the end. 8 byte id (as found in BlockAddId) followed + * by data. + */ + AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, }; /** @@ -1491,7 +1508,7 @@ typedef struct AVFrame { * - encoding: unused * - decoding: Read by user. */ - int64_t channels; + int channels; /** ATSC CC data CEA-608/708 * - encoding: unused @@ -2919,20 +2936,22 @@ typedef struct AVCodecContext { #define FF_IDCT_ALTIVEC 8 #define FF_IDCT_SH4 9 #define FF_IDCT_SIMPLEARM 10 -#define FF_IDCT_H264 11 -#define FF_IDCT_VP3 12 #define FF_IDCT_IPP 13 #define FF_IDCT_XVIDMMX 14 -#define FF_IDCT_CAVS 15 #define FF_IDCT_SIMPLEARMV5TE 16 #define FF_IDCT_SIMPLEARMV6 17 #define FF_IDCT_SIMPLEVIS 18 -#define FF_IDCT_WMV2 19 #define FF_IDCT_FAAN 20 -#define FF_IDCT_EA 21 #define FF_IDCT_SIMPLENEON 22 #define FF_IDCT_SIMPLEALPHA 23 +#if FF_API_IDCT +#define FF_IDCT_H264 11 +#define FF_IDCT_VP3 12 +#define FF_IDCT_CAVS 15 +#define FF_IDCT_WMV2 19 +#define FF_IDCT_EA 21 #define FF_IDCT_BINK 24 +#endif #if FF_API_DSP_MASK /** @@ -3190,7 +3209,7 @@ typedef struct AVCodecContext { /** * Timebase in which pkt_dts/pts and AVPacket.dts/pts are. * Code outside libavcodec should access this field using: - * avcodec_set_pkt_timebase(avctx) + * av_codec_{get,set}_pkt_timebase(avctx) * - encoding unused. * - decodimg set by user */ @@ -3199,7 +3218,7 @@ typedef struct AVCodecContext { /** * AVCodecDescriptor * Code outside libavcodec should access this field using: - * avcodec_get_codec_descriptior(avctx) + * av_codec_{get,set}_codec_descriptor(avctx) * - encoding: unused. * - decoding: set by libavcodec. */ @@ -3221,6 +3240,24 @@ typedef struct AVCodecContext { * - encoding: unused */ AVDictionary *metadata; + + /** + * Character encoding of the input subtitles file. + * - decoding: set by user + * - encoding: unused + */ + char *sub_charenc; + + /** + * Subtitles character encoding mode. Formats or codecs might be adjusting + * this setting (if they are doing the conversion themselves for instance). + * - decoding: set by libavcodec + * - encoding: unused + */ + int sub_charenc_mode; +#define FF_SUB_CHARENC_MODE_DO_NOTHING -1 ///< do nothing (demuxer outputs a stream supposed to be already in UTF-8, or the codec is bitmap for instance) +#define FF_SUB_CHARENC_MODE_AUTOMATIC 0 ///< libavcodec will select the mode itself +#define FF_SUB_CHARENC_MODE_PRE_DECODER 1 ///< the AVPacket data needs to be recoded to UTF-8 before being fed to the decoder, requires iconv } AVCodecContext; AVRational av_codec_get_pkt_timebase (const AVCodecContext *avctx); @@ -4616,11 +4653,16 @@ int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt, */ int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height); +#if FF_API_DEINTERLACE /** * deinterlace - if not supported return -1 + * + * @deprecated - use yadif (in libavfilter) instead */ +attribute_deprecated int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, enum AVPixelFormat pix_fmt, int width, int height); +#endif /** * Copy image src to dst. Wraps av_image_copy(). */ diff --git a/mythtv/external/FFmpeg/libavcodec/avpacket.c b/mythtv/external/FFmpeg/libavcodec/avpacket.c index 516f1c972b9..dea72e5d731 100644 --- a/mythtv/external/FFmpeg/libavcodec/avpacket.c +++ b/mythtv/external/FFmpeg/libavcodec/avpacket.c @@ -41,8 +41,6 @@ void av_destruct_packet(AVPacket *pkt) av_free(pkt->data); pkt->data = NULL; pkt->size = 0; - - ff_packet_free_side_data(pkt); } void av_init_packet(AVPacket *pkt) @@ -174,11 +172,16 @@ int av_copy_packet(AVPacket *dst, AVPacket *src) void av_free_packet(AVPacket *pkt) { if (pkt) { + int i; + if (pkt->destruct) pkt->destruct(pkt); pkt->data = NULL; pkt->size = 0; - pkt->side_data = NULL; + + for (i = 0; i < pkt->side_data_elems; i++) + av_free(pkt->side_data[i].data); + av_freep(&pkt->side_data); pkt->side_data_elems = 0; } } diff --git a/mythtv/external/FFmpeg/libavcodec/avs.c b/mythtv/external/FFmpeg/libavcodec/avs.c index 39ce7da561d..e3d2070bb79 100644 --- a/mythtv/external/FFmpeg/libavcodec/avs.c +++ b/mythtv/external/FFmpeg/libavcodec/avs.c @@ -54,14 +54,14 @@ avs_decode_frame(AVCodecContext * avctx, AVFrame *const p = &avs->picture; const uint8_t *table, *vect; uint8_t *out; - int i, j, x, y, stride, vect_w = 3, vect_h = 3; + int i, j, x, y, stride, ret, vect_w = 3, vect_h = 3; AvsVideoSubType sub_type; AvsBlockType type; GetBitContext change_map = {0}; //init to silence warning - if (avctx->reget_buffer(avctx, p)) { + if ((ret = avctx->reget_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } p->reference = 3; p->pict_type = AV_PICTURE_TYPE_P; @@ -96,7 +96,7 @@ avs_decode_frame(AVCodecContext * avctx, } if (type != AVS_VIDEO) - return -1; + return AVERROR_INVALIDDATA; switch (sub_type) { case AVS_I_FRAME: @@ -118,7 +118,7 @@ avs_decode_frame(AVCodecContext * avctx, break; default: - return -1; + return AVERROR_INVALIDDATA; } if (buf_end - buf < 256 * vect_w * vect_h) diff --git a/mythtv/external/FFmpeg/libavcodec/bethsoftvideo.c b/mythtv/external/FFmpeg/libavcodec/bethsoftvideo.c index 04243ed33ae..2a03f1adbe0 100644 --- a/mythtv/external/FFmpeg/libavcodec/bethsoftvideo.c +++ b/mythtv/external/FFmpeg/libavcodec/bethsoftvideo.c @@ -28,7 +28,7 @@ */ #include "libavutil/common.h" -#include "dsputil.h" +#include "avcodec.h" #include "bethsoftvideo.h" #include "bytestream.h" diff --git a/mythtv/external/FFmpeg/libavcodec/bfi.c b/mythtv/external/FFmpeg/libavcodec/bfi.c index 70291b563b9..231ee622046 100644 --- a/mythtv/external/FFmpeg/libavcodec/bfi.c +++ b/mythtv/external/FFmpeg/libavcodec/bfi.c @@ -57,16 +57,16 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, uint8_t *src, *dst_offset, colour1, colour2; uint8_t *frame_end = bfi->dst + avctx->width * avctx->height; uint32_t *pal; - int i, j, height = avctx->height; + int i, j, ret, height = avctx->height; if (bfi->frame.data[0]) avctx->release_buffer(avctx, &bfi->frame); bfi->frame.reference = 3; - if (ff_get_buffer(avctx, &bfi->frame) < 0) { + if ((ret = ff_get_buffer(avctx, &bfi->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } bytestream2_init(&g, avpkt->data, buf_size); @@ -78,7 +78,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, /* Setting the palette */ if (avctx->extradata_size > 768) { av_log(NULL, AV_LOG_ERROR, "Palette is too large.\n"); - return -1; + return AVERROR_INVALIDDATA; } pal = (uint32_t *)bfi->frame.data[1]; for (i = 0; i < avctx->extradata_size / 3; i++) { @@ -109,7 +109,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, if (!bytestream2_get_bytes_left(&g)) { av_log(avctx, AV_LOG_ERROR, "Input resolution larger than actual frame.\n"); - return -1; + return AVERROR_INVALIDDATA; } /* Get length and offset (if required) */ @@ -135,7 +135,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, case 0: // normal chain if (length >= bytestream2_get_bytes_left(&g)) { av_log(avctx, AV_LOG_ERROR, "Frame larger than buffer.\n"); - return -1; + return AVERROR_INVALIDDATA; } bytestream2_get_buffer(&g, dst, length); dst += length; diff --git a/mythtv/external/FFmpeg/libavcodec/bfin/Makefile b/mythtv/external/FFmpeg/libavcodec/bfin/Makefile index be81e6c39a3..d1b41bc7f4d 100644 --- a/mythtv/external/FFmpeg/libavcodec/bfin/Makefile +++ b/mythtv/external/FFmpeg/libavcodec/bfin/Makefile @@ -2,7 +2,7 @@ OBJS += bfin/dsputil_bfin.o \ bfin/fdct_bfin.o \ bfin/idct_bfin.o \ bfin/pixels_bfin.o \ - bfin/vp3_bfin.o \ - bfin/vp3_idct_bfin.o \ OBJS-$(CONFIG_MPEGVIDEOENC) += bfin/mpegvideo_bfin.o +OBJS-$(CONFIG_VP3DSP) += bfin/vp3_bfin.o \ + bfin/vp3_idct_bfin.o diff --git a/mythtv/external/FFmpeg/libavcodec/bfin/config_bfin.h b/mythtv/external/FFmpeg/libavcodec/bfin/config_bfin.h index f3a2c6ebc6e..36439530e9f 100644 --- a/mythtv/external/FFmpeg/libavcodec/bfin/config_bfin.h +++ b/mythtv/external/FFmpeg/libavcodec/bfin/config_bfin.h @@ -21,7 +21,7 @@ low level assembler interface wrapper DEFUN(put_pixels_clamped,mL1, - (DCTELEM *block, uint8_t *dest, int line_size)): + (int16_t *block, uint8_t *dest, int line_size)): body diff --git a/mythtv/external/FFmpeg/libavcodec/bfin/dsputil_bfin.c b/mythtv/external/FFmpeg/libavcodec/bfin/dsputil_bfin.c index 434d2a71900..ce04753bc26 100644 --- a/mythtv/external/FFmpeg/libavcodec/bfin/dsputil_bfin.c +++ b/mythtv/external/FFmpeg/libavcodec/bfin/dsputil_bfin.c @@ -21,26 +21,27 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/attributes.h" #include "libavcodec/avcodec.h" #include "libavcodec/dsputil.h" #include "dsputil_bfin.h" int off; -static void bfin_idct_add (uint8_t *dest, int line_size, DCTELEM *block) +static void bfin_idct_add (uint8_t *dest, int line_size, int16_t *block) { ff_bfin_idct (block); ff_bfin_add_pixels_clamped (block, dest, line_size); } -static void bfin_idct_put (uint8_t *dest, int line_size, DCTELEM *block) +static void bfin_idct_put (uint8_t *dest, int line_size, int16_t *block) { ff_bfin_idct (block); ff_bfin_put_pixels_clamped (block, dest, line_size); } -static void bfin_clear_blocks (DCTELEM *blocks) +static void bfin_clear_blocks (int16_t *blocks) { // This is just a simple memset. // @@ -55,73 +56,73 @@ static void bfin_clear_blocks (DCTELEM *blocks) -static void bfin_put_pixels8 (uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void bfin_put_pixels8 (uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { ff_bfin_put_pixels8uc (block, pixels, pixels, line_size, line_size, h); } -static void bfin_put_pixels8_x2(uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void bfin_put_pixels8_x2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { ff_bfin_put_pixels8uc (block, pixels, pixels+1, line_size, line_size, h); } -static void bfin_put_pixels8_y2 (uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void bfin_put_pixels8_y2 (uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { ff_bfin_put_pixels8uc (block, pixels, pixels+line_size, line_size, line_size, h); } -static void bfin_put_pixels8_xy2 (uint8_t *block, const uint8_t *s0, int line_size, int h) +static void bfin_put_pixels8_xy2 (uint8_t *block, const uint8_t *s0, ptrdiff_t line_size, int h) { ff_bfin_z_put_pixels8_xy2 (block,s0,line_size, line_size, h); } -static void bfin_put_pixels16 (uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void bfin_put_pixels16 (uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { ff_bfin_put_pixels16uc (block, pixels, pixels, line_size, line_size, h); } -static void bfin_put_pixels16_x2 (uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void bfin_put_pixels16_x2 (uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { ff_bfin_put_pixels16uc (block, pixels, pixels+1, line_size, line_size, h); } -static void bfin_put_pixels16_y2 (uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void bfin_put_pixels16_y2 (uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { ff_bfin_put_pixels16uc (block, pixels, pixels+line_size, line_size, line_size, h); } -static void bfin_put_pixels16_xy2 (uint8_t *block, const uint8_t *s0, int line_size, int h) +static void bfin_put_pixels16_xy2 (uint8_t *block, const uint8_t *s0, ptrdiff_t line_size, int h) { ff_bfin_z_put_pixels16_xy2 (block,s0,line_size, line_size, h); } -static void bfin_put_pixels8_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void bfin_put_pixels8_nornd (uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { ff_bfin_put_pixels8uc_nornd (block, pixels, pixels, line_size, h); } -static void bfin_put_pixels8_x2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void bfin_put_pixels8_x2_nornd (uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { ff_bfin_put_pixels8uc_nornd (block, pixels, pixels+1, line_size, h); } -static void bfin_put_pixels8_y2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void bfin_put_pixels8_y2_nornd (uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { ff_bfin_put_pixels8uc_nornd (block, pixels, pixels+line_size, line_size, h); } -static void bfin_put_pixels16_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void bfin_put_pixels16_nornd (uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { ff_bfin_put_pixels16uc_nornd (block, pixels, pixels, line_size, h); } -static void bfin_put_pixels16_x2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void bfin_put_pixels16_x2_nornd (uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { ff_bfin_put_pixels16uc_nornd (block, pixels, pixels+1, line_size, h); } -static void bfin_put_pixels16_y2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void bfin_put_pixels16_y2_nornd (uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { ff_bfin_put_pixels16uc_nornd (block, pixels, pixels+line_size, line_size, h); } @@ -195,7 +196,7 @@ static int bfin_pix_abs8_xy2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_si */ -void ff_dsputil_init_bfin( DSPContext* c, AVCodecContext *avctx ) +av_cold void ff_dsputil_init_bfin(DSPContext *c, AVCodecContext *avctx) { const int high_bit_depth = avctx->bits_per_raw_sample > 8; @@ -257,12 +258,7 @@ void ff_dsputil_init_bfin( DSPContext* c, AVCodecContext *avctx ) if (avctx->dct_algo == FF_DCT_AUTO) c->fdct = ff_bfin_fdct; - if (avctx->idct_algo == FF_IDCT_VP3) { - c->idct_permutation_type = FF_NO_IDCT_PERM; - c->idct = ff_bfin_vp3_idct; - c->idct_add = ff_bfin_vp3_idct_add; - c->idct_put = ff_bfin_vp3_idct_put; - } else if (avctx->idct_algo == FF_IDCT_AUTO) { + if (avctx->idct_algo == FF_IDCT_AUTO) { c->idct_permutation_type = FF_NO_IDCT_PERM; c->idct = ff_bfin_idct; c->idct_add = bfin_idct_add; diff --git a/mythtv/external/FFmpeg/libavcodec/bfin/dsputil_bfin.h b/mythtv/external/FFmpeg/libavcodec/bfin/dsputil_bfin.h index 43ac39c9e0d..293092363b2 100644 --- a/mythtv/external/FFmpeg/libavcodec/bfin/dsputil_bfin.h +++ b/mythtv/external/FFmpeg/libavcodec/bfin/dsputil_bfin.h @@ -24,8 +24,9 @@ #ifndef AVCODEC_BFIN_DSPUTIL_BFIN_H #define AVCODEC_BFIN_DSPUTIL_BFIN_H +#include + #include "config.h" -#include "libavcodec/dsputil.h" #if defined(__FDPIC__) && CONFIG_SRAM #define attribute_l1_text __attribute__ ((l1_text)) @@ -35,15 +36,12 @@ #define attribute_l1_data_b #endif -void ff_bfin_idct (DCTELEM *block) attribute_l1_text; -void ff_bfin_fdct (DCTELEM *block) attribute_l1_text; -void ff_bfin_vp3_idct (DCTELEM *block); -void ff_bfin_vp3_idct_put (uint8_t *dest, int line_size, DCTELEM *block); -void ff_bfin_vp3_idct_add (uint8_t *dest, int line_size, DCTELEM *block); -void ff_bfin_add_pixels_clamped (const DCTELEM *block, uint8_t *dest, int line_size) attribute_l1_text; -void ff_bfin_put_pixels_clamped (const DCTELEM *block, uint8_t *dest, int line_size) attribute_l1_text; -void ff_bfin_diff_pixels (DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride) attribute_l1_text; -void ff_bfin_get_pixels (DCTELEM *av_restrict block, const uint8_t *pixels, int line_size) attribute_l1_text; +void ff_bfin_idct (int16_t *block) attribute_l1_text; +void ff_bfin_fdct (int16_t *block) attribute_l1_text; +void ff_bfin_add_pixels_clamped (const int16_t *block, uint8_t *dest, int line_size) attribute_l1_text; +void ff_bfin_put_pixels_clamped (const int16_t *block, uint8_t *dest, int line_size) attribute_l1_text; +void ff_bfin_diff_pixels (int16_t *block, const uint8_t *s1, const uint8_t *s2, int stride) attribute_l1_text; +void ff_bfin_get_pixels (int16_t *restrict block, const uint8_t *pixels, int line_size) attribute_l1_text; int ff_bfin_pix_norm1 (uint8_t * pix, int line_size) attribute_l1_text; int ff_bfin_z_sad8x8 (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) attribute_l1_text; int ff_bfin_z_sad16x16 (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) attribute_l1_text; diff --git a/mythtv/external/FFmpeg/libavcodec/bfin/fdct_bfin.S b/mythtv/external/FFmpeg/libavcodec/bfin/fdct_bfin.S index e15acb654f5..916957467c6 100644 --- a/mythtv/external/FFmpeg/libavcodec/bfin/fdct_bfin.S +++ b/mythtv/external/FFmpeg/libavcodec/bfin/fdct_bfin.S @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* - void ff_bfin_fdct (DCTELEM *buf); + void ff_bfin_fdct (int16_t *buf); This implementation works only for 8x8 input. The range of input must be -256 to 255 i.e. 8bit input represented in a 16bit data @@ -61,9 +61,9 @@ Notation Other registers used: I0, I1, I2, I3, B0, B2, B3, M0, M1, L3 registers and LC0. - Input - r0 - pointer to start of DCTELEM *block + Input - r0 - pointer to start of int16_t *block - Output - The DCT output coefficients in the DCTELEM *block + Output - The DCT output coefficients in the int16_t *block Register constraint: This code is called from jpeg_encode. @@ -147,7 +147,7 @@ vtmp: .space 128 .text DEFUN(fdct,mL1, - (DCTELEM *block)): + (int16_t *block)): [--SP] = (R7:4, P5:3); // Push the registers onto the stack. b0 = r0; diff --git a/mythtv/external/FFmpeg/libavcodec/bfin/idct_bfin.S b/mythtv/external/FFmpeg/libavcodec/bfin/idct_bfin.S index 66430096f0b..bd80447bde8 100644 --- a/mythtv/external/FFmpeg/libavcodec/bfin/idct_bfin.S +++ b/mythtv/external/FFmpeg/libavcodec/bfin/idct_bfin.S @@ -22,7 +22,7 @@ /* This blackfin DSP code implements an 8x8 inverse type II DCT. -Prototype : void ff_bfin_idct(DCTELEM *in) +Prototype : void ff_bfin_idct(int16_t *in) Registers Used : A0, A1, R0-R7, I0-I3, B0, B2, B3, M0-M2, L0-L3, P0-P5, LC0. @@ -90,7 +90,7 @@ vtmp: .space 256 .text DEFUN(idct,mL1, - (DCTELEM *block)): + (int16_t *block)): /********************** Function Prologue *********************************/ link 16; diff --git a/mythtv/external/FFmpeg/libavcodec/bfin/mpegvideo_bfin.c b/mythtv/external/FFmpeg/libavcodec/bfin/mpegvideo_bfin.c index f7f3d729de9..458e7dcdbae 100644 --- a/mythtv/external/FFmpeg/libavcodec/bfin/mpegvideo_bfin.c +++ b/mythtv/external/FFmpeg/libavcodec/bfin/mpegvideo_bfin.c @@ -20,13 +20,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/attributes.h" #include "libavcodec/avcodec.h" -#include "libavcodec/dsputil.h" #include "libavcodec/mpegvideo.h" #include "dsputil_bfin.h" static int dct_quantize_bfin (MpegEncContext *s, - DCTELEM *block, int n, + int16_t *block, int n, int qscale, int *overflow) { int last_non_zero, q, start_i; @@ -146,7 +146,7 @@ static int dct_quantize_bfin (MpegEncContext *s, return last_non_zero; } -void ff_MPV_common_init_bfin (MpegEncContext *s) +av_cold void ff_MPV_common_init_bfin (MpegEncContext *s) { /* s->dct_quantize= dct_quantize_bfin; */ } diff --git a/mythtv/external/FFmpeg/libavcodec/bfin/pixels_bfin.S b/mythtv/external/FFmpeg/libavcodec/bfin/pixels_bfin.S index 995d7b8cc81..2e3cd0f9bc1 100644 --- a/mythtv/external/FFmpeg/libavcodec/bfin/pixels_bfin.S +++ b/mythtv/external/FFmpeg/libavcodec/bfin/pixels_bfin.S @@ -21,7 +21,7 @@ #include "config_bfin.h" DEFUN(put_pixels_clamped,mL1, - (DCTELEM *block, uint8_t *dest, int line_size)): + (int16_t *block, uint8_t *dest, int line_size)): [--SP] = (R7:4); R4 = 0; R5.l = 0x00ff; @@ -51,7 +51,7 @@ ppc$1: R2 = Max(R0, R4) (V) || [I1++M1] = R6; DEFUN_END(put_pixels_clamped) DEFUN(add_pixels_clamped,mL1, - (DCTELEM *block, uint8_t *dest, int line_size)): + (int16_t *block, uint8_t *dest, int line_size)): [-- SP] = (R7:4); R4 = 0; I0 = 0; @@ -442,7 +442,7 @@ LE$8OT: DISALGNEXCPT || R2 =[I1++] || [I3++M2] = R5; rts; DEFUN(diff_pixels,mL1, - (DCTELEM *block, uint8_t *s1, uint8_t *s2, int stride)): + (int16_t *block, uint8_t *s1, uint8_t *s2, int stride)): link 0; [--sp] = (r7:4); p0=8; @@ -518,7 +518,7 @@ DEFUN_END(pix_sum) DEFUN(get_pixels,mL1, - (DCTELEM *av_restrict block, const uint8_t *pixels, int line_size)): + (int16_t *av_restrict block, const uint8_t *pixels, int line_size)): [--sp] = (r7:4); i3=r0; // dest i0=r1; // src0 diff --git a/mythtv/external/FFmpeg/libavcodec/bfin/vp3_bfin.c b/mythtv/external/FFmpeg/libavcodec/bfin/vp3_bfin.c index 6d6ac826365..e823a045b1a 100644 --- a/mythtv/external/FFmpeg/libavcodec/bfin/vp3_bfin.c +++ b/mythtv/external/FFmpeg/libavcodec/bfin/vp3_bfin.c @@ -18,12 +18,17 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + +#include "libavutil/attributes.h" #include "libavcodec/avcodec.h" +#include "libavcodec/vp3dsp.h" #include "libavcodec/dsputil.h" #include "dsputil_bfin.h" +#include "vp3_bfin.h" /* Intra iDCT offset 128 */ -void ff_bfin_vp3_idct_put (uint8_t *dest, int line_size, DCTELEM *block) +void ff_bfin_vp3_idct_put (uint8_t *dest, int line_size, int16_t *block) { uint8_t *cm = ff_cropTbl + MAX_NEG_CROP + 128; int i,j; @@ -33,11 +38,21 @@ void ff_bfin_vp3_idct_put (uint8_t *dest, int line_size, DCTELEM *block) for (i=0;i<8;i++) for (j=0;j<8;j++) dest[line_size*i+j]=cm[block[i*8+j]]; + + memset(block, 0, 128); } /* Inter iDCT */ -void ff_bfin_vp3_idct_add (uint8_t *dest, int line_size, DCTELEM *block) +void ff_bfin_vp3_idct_add (uint8_t *dest, int line_size, int16_t *block) { ff_bfin_vp3_idct (block); ff_bfin_add_pixels_clamped (block, dest, line_size); + + memset(block, 0, 128); +} + +av_cold void ff_vp3dsp_init_bfin(VP3DSPContext *c, int flags) +{ + c->idct_add = ff_bfin_vp3_idct_add; + c->idct_put = ff_bfin_vp3_idct_put; } diff --git a/mythtv/external/FFmpeg/libavcodec/bfin/vp3_bfin.h b/mythtv/external/FFmpeg/libavcodec/bfin/vp3_bfin.h new file mode 100644 index 00000000000..f0bf824951e --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/bfin/vp3_bfin.h @@ -0,0 +1,29 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#ifndef AVCODEC_BFIN_VP3_BFIN_H +#define AVCODEC_BFIN_VP3_BFIN_H + +#include + +void ff_bfin_vp3_idct(int16_t *block); +void ff_bfin_vp3_idct_put(uint8_t *dest, int line_size, int16_t *block); +void ff_bfin_vp3_idct_add(uint8_t *dest, int line_size, int16_t *block); + +#endif /* AVCODEC_BFIN_VP3_BFIN_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/bfin/vp3_idct_bfin.S b/mythtv/external/FFmpeg/libavcodec/bfin/vp3_idct_bfin.S index 83747f9fcdd..4e200459f42 100644 --- a/mythtv/external/FFmpeg/libavcodec/bfin/vp3_idct_bfin.S +++ b/mythtv/external/FFmpeg/libavcodec/bfin/vp3_idct_bfin.S @@ -22,7 +22,7 @@ /* This blackfin DSP code implements an 8x8 inverse type II DCT. -Prototype : void ff_bfin_vp3_idct(DCTELEM *in) +Prototype : void ff_bfin_vp3_idct(int16_t *in) Registers Used : A0, A1, R0-R7, I0-I3, B0, B2, B3, M0-M2, L0-L3, P0-P5, LC0. @@ -63,7 +63,7 @@ vtmp: .space 256 .text DEFUN(vp3_idct,mL1, - (DCTELEM *block)): + (int16_t *block)): /********************** Function Prologue *********************************/ link 16; diff --git a/mythtv/external/FFmpeg/libavcodec/bink.c b/mythtv/external/FFmpeg/libavcodec/bink.c index 9c04d05e206..5d000a86b4d 100644 --- a/mythtv/external/FFmpeg/libavcodec/bink.c +++ b/mythtv/external/FFmpeg/libavcodec/bink.c @@ -21,6 +21,7 @@ */ #include "libavutil/imgutils.h" +#include "libavutil/internal.h" #include "avcodec.h" #include "dsputil.h" #include "binkdata.h" @@ -112,7 +113,7 @@ typedef struct BinkContext { AVCodecContext *avctx; DSPContext dsp; BinkDSPContext bdsp; - AVFrame pic, last; + AVFrame *pic, *last; int version; ///< internal Bink file version int has_alpha; int swap_planes; @@ -317,7 +318,7 @@ static int read_runs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) dec_end = b->cur_dec + t; if (dec_end > b->data_end) { av_log(avctx, AV_LOG_ERROR, "Run value went out of bounds\n"); - return -1; + return AVERROR_INVALIDDATA; } if (get_bits1(gb)) { v = get_bits(gb, 4); @@ -339,7 +340,7 @@ static int read_motion_values(AVCodecContext *avctx, GetBitContext *gb, Bundle * dec_end = b->cur_dec + t; if (dec_end > b->data_end) { av_log(avctx, AV_LOG_ERROR, "Too many motion values\n"); - return -1; + return AVERROR_INVALIDDATA; } if (get_bits1(gb)) { v = get_bits(gb, 4); @@ -374,7 +375,7 @@ static int read_block_types(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) dec_end = b->cur_dec + t; if (dec_end > b->data_end) { av_log(avctx, AV_LOG_ERROR, "Too many block type values\n"); - return -1; + return AVERROR_INVALIDDATA; } if (get_bits1(gb)) { v = get_bits(gb, 4); @@ -390,7 +391,7 @@ static int read_block_types(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) int run = bink_rlelens[v - 12]; if (dec_end - b->cur_dec < run) - return -1; + return AVERROR_INVALIDDATA; memset(b->cur_dec, last, run); b->cur_dec += run; } @@ -408,7 +409,7 @@ static int read_patterns(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) dec_end = b->cur_dec + t; if (dec_end > b->data_end) { av_log(avctx, AV_LOG_ERROR, "Too many pattern values\n"); - return -1; + return AVERROR_INVALIDDATA; } while (b->cur_dec < dec_end) { v = GET_HUFF(gb, b->tree); @@ -428,7 +429,7 @@ static int read_colors(GetBitContext *gb, Bundle *b, BinkContext *c) dec_end = b->cur_dec + t; if (dec_end > b->data_end) { av_log(c->avctx, AV_LOG_ERROR, "Too many color values\n"); - return -1; + return AVERROR_INVALIDDATA; } if (get_bits1(gb)) { c->col_lastval = GET_HUFF(gb, c->col_high[c->col_lastval]); @@ -474,13 +475,13 @@ static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b, v = (v ^ sign) - sign; } if (dst_end - dst < 1) - return -1; + return AVERROR_INVALIDDATA; *dst++ = v; len--; for (i = 0; i < len; i += 8) { len2 = FFMIN(len - i, 8); if (dst_end - dst < len2) - return -1; + return AVERROR_INVALIDDATA; bsize = get_bits(gb, 4); if (bsize) { for (j = 0; j < len2; j++) { @@ -493,7 +494,7 @@ static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b, *dst++ = v; if (v < -32768 || v > 32767) { av_log(avctx, AV_LOG_ERROR, "DC value went out of bounds: %d\n", v); - return -1; + return AVERROR_INVALIDDATA; } } } else { @@ -549,7 +550,7 @@ static int binkb_read_bundle(BinkContext *c, GetBitContext *gb, int bundle_num) CHECK_READ_VAL(gb, b, len); if (b->data_end - b->cur_dec < len * (1 + (bits > 8))) - return -1; + return AVERROR_INVALIDDATA; if (bits <= 8) { if (!issigned) { for (i = 0; i < len; i++) @@ -704,7 +705,7 @@ static int read_dct_coeffs(GetBitContext *gb, int32_t block[64], const uint8_t * * @param masks_count number of masks to decode * @return 0 on success, negative value in other cases */ -static int read_residue(GetBitContext *gb, DCTELEM block[64], int masks_count) +static int read_residue(GetBitContext *gb, int16_t block[64], int masks_count) { int coef_list[128]; int mode_list[128]; @@ -802,36 +803,36 @@ static inline void put_pixels8x8_overlapped(uint8_t *dst, uint8_t *src, int stri static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, int is_key, int is_chroma) { - int blk; + int blk, ret; int i, j, bx, by; uint8_t *dst, *ref, *ref_start, *ref_end; int v, col[2]; const uint8_t *scan; int xoff, yoff; - LOCAL_ALIGNED_16(DCTELEM, block, [64]); + LOCAL_ALIGNED_16(int16_t, block, [64]); LOCAL_ALIGNED_16(int32_t, dctblock, [64]); int coordmap[64]; int ybias = is_key ? -15 : 0; int qp; - const int stride = c->pic.linesize[plane_idx]; + const int stride = c->pic->linesize[plane_idx]; int bw = is_chroma ? (c->avctx->width + 15) >> 4 : (c->avctx->width + 7) >> 3; int bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3; binkb_init_bundles(c); - ref_start = c->pic.data[plane_idx]; - ref_end = c->pic.data[plane_idx] + (bh * c->pic.linesize[plane_idx] + bw) * 8; + ref_start = c->pic->data[plane_idx]; + ref_end = c->pic->data[plane_idx] + (bh * c->pic->linesize[plane_idx] + bw) * 8; for (i = 0; i < 64; i++) coordmap[i] = (i & 7) + (i >> 3) * stride; for (by = 0; by < bh; by++) { for (i = 0; i < BINKB_NB_SRC; i++) { - if (binkb_read_bundle(c, gb, i) < 0) - return -1; + if ((ret = binkb_read_bundle(c, gb, i)) < 0) + return ret; } - dst = c->pic.data[plane_idx] + 8*by*stride; + dst = c->pic->data[plane_idx] + 8*by*stride; for (bx = 0; bx < bw; bx++, dst += 8) { blk = binkb_get_value(c, BINKB_SRC_BLOCK_TYPES); switch (blk) { @@ -849,7 +850,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, i += run; if (i > 64) { av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); - return -1; + return AVERROR_INVALIDDATA; } if (mode) { v = binkb_get_value(c, BINKB_SRC_COLORS); @@ -935,7 +936,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, break; default: av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk); - return -1; + return AVERROR_INVALIDDATA; } } } @@ -948,18 +949,18 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, int is_chroma) { - int blk; + int blk, ret; int i, j, bx, by; uint8_t *dst, *prev, *ref, *ref_start, *ref_end; int v, col[2]; const uint8_t *scan; int xoff, yoff; - LOCAL_ALIGNED_16(DCTELEM, block, [64]); + LOCAL_ALIGNED_16(int16_t, block, [64]); LOCAL_ALIGNED_16(uint8_t, ublock, [64]); LOCAL_ALIGNED_16(int32_t, dctblock, [64]); int coordmap[64]; - const int stride = c->pic.linesize[plane_idx]; + const int stride = c->pic->linesize[plane_idx]; int bw = is_chroma ? (c->avctx->width + 15) >> 4 : (c->avctx->width + 7) >> 3; int bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3; int width = c->avctx->width >> is_chroma; @@ -968,39 +969,39 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, for (i = 0; i < BINK_NB_SRC; i++) read_bundle(gb, c, i); - ref_start = c->last.data[plane_idx] ? c->last.data[plane_idx] - : c->pic.data[plane_idx]; + ref_start = c->last->data[plane_idx] ? c->last->data[plane_idx] + : c->pic->data[plane_idx]; ref_end = ref_start - + (bw - 1 + c->last.linesize[plane_idx] * (bh - 1)) * 8; + + (bw - 1 + c->last->linesize[plane_idx] * (bh - 1)) * 8; for (i = 0; i < 64; i++) coordmap[i] = (i & 7) + (i >> 3) * stride; for (by = 0; by < bh; by++) { - if (read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_BLOCK_TYPES]) < 0) - return -1; - if (read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_SUB_BLOCK_TYPES]) < 0) - return -1; - if (read_colors(gb, &c->bundle[BINK_SRC_COLORS], c) < 0) - return -1; - if (read_patterns(c->avctx, gb, &c->bundle[BINK_SRC_PATTERN]) < 0) - return -1; - if (read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_X_OFF]) < 0) - return -1; - if (read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_Y_OFF]) < 0) - return -1; - if (read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTRA_DC], DC_START_BITS, 0) < 0) - return -1; - if (read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTER_DC], DC_START_BITS, 1) < 0) - return -1; - if (read_runs(c->avctx, gb, &c->bundle[BINK_SRC_RUN]) < 0) - return -1; + if ((ret = read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_BLOCK_TYPES])) < 0) + return ret; + if ((ret = read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_SUB_BLOCK_TYPES])) < 0) + return ret; + if ((ret = read_colors(gb, &c->bundle[BINK_SRC_COLORS], c)) < 0) + return ret; + if ((ret = read_patterns(c->avctx, gb, &c->bundle[BINK_SRC_PATTERN])) < 0) + return ret; + if ((ret = read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_X_OFF])) < 0) + return ret; + if ((ret = read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_Y_OFF])) < 0) + return ret; + if ((ret = read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTRA_DC], DC_START_BITS, 0)) < 0) + return ret; + if ((ret = read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTER_DC], DC_START_BITS, 1)) < 0) + return ret; + if ((ret = read_runs(c->avctx, gb, &c->bundle[BINK_SRC_RUN])) < 0) + return ret; if (by == bh) break; - dst = c->pic.data[plane_idx] + 8*by*stride; - prev = (c->last.data[plane_idx] ? c->last.data[plane_idx] - : c->pic.data[plane_idx]) + 8*by*stride; + dst = c->pic->data[plane_idx] + 8*by*stride; + prev = (c->last->data[plane_idx] ? c->last->data[plane_idx] + : c->pic->data[plane_idx]) + 8*by*stride; for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) { blk = get_value(c, BINK_SRC_BLOCK_TYPES); // 16x16 block type on odd line means part of the already decoded block, so skip it @@ -1026,7 +1027,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, i += run; if (i > 64) { av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); - return -1; + return AVERROR_INVALIDDATA; } if (get_bits1(gb)) { v = get_value(c, BINK_SRC_COLORS); @@ -1066,7 +1067,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, break; default: av_log(c->avctx, AV_LOG_ERROR, "Incorrect 16x16 block type %d\n", blk); - return -1; + return AVERROR_INVALIDDATA; } if (blk != FILL_BLOCK) c->bdsp.scale_block(ublock, dst, stride); @@ -1081,7 +1082,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, if (ref < ref_start || ref > ref_end) { av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n", bx*8 + xoff, by*8 + yoff); - return -1; + return AVERROR_INVALIDDATA; } c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); break; @@ -1094,7 +1095,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, i += run; if (i > 64) { av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); - return -1; + return AVERROR_INVALIDDATA; } if (get_bits1(gb)) { v = get_value(c, BINK_SRC_COLORS); @@ -1115,7 +1116,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, if (ref < ref_start || ref > ref_end) { av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n", bx*8 + xoff, by*8 + yoff); - return -1; + return AVERROR_INVALIDDATA; } c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); c->dsp.clear_block(block); @@ -1164,7 +1165,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, break; default: av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk); - return -1; + return AVERROR_INVALIDDATA; } } } @@ -1178,21 +1179,21 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac { BinkContext * const c = avctx->priv_data; GetBitContext gb; - int plane, plane_idx; + int plane, plane_idx, ret; int bits_count = pkt->size << 3; if (c->version > 'b') { - if(c->pic.data[0]) - avctx->release_buffer(avctx, &c->pic); + if(c->pic->data[0]) + avctx->release_buffer(avctx, c->pic); - if(ff_get_buffer(avctx, &c->pic) < 0){ + if ((ret = ff_get_buffer(avctx, c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } } else { - if(avctx->reget_buffer(avctx, &c->pic) < 0){ + if ((ret = avctx->reget_buffer(avctx, c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } } @@ -1200,8 +1201,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac if (c->has_alpha) { if (c->version >= 'i') skip_bits_long(&gb, 32); - if (bink_decode_plane(c, &gb, 3, 0) < 0) - return -1; + if ((ret = bink_decode_plane(c, &gb, 3, 0)) < 0) + return ret; } if (c->version >= 'i') skip_bits_long(&gb, 32); @@ -1210,11 +1211,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac plane_idx = (!plane || !c->swap_planes) ? plane : (plane ^ 3); if (c->version > 'b') { - if (bink_decode_plane(c, &gb, plane_idx, !!plane) < 0) - return -1; + if ((ret = bink_decode_plane(c, &gb, plane_idx, !!plane)) < 0) + return ret; } else { - if (binkb_decode_plane(c, &gb, plane_idx, !pkt->pts, !!plane) < 0) - return -1; + if ((ret = binkb_decode_plane(c, &gb, plane_idx, + !avctx->frame_number, !!plane)) < 0) + return ret; } if (get_bits_count(&gb) >= bits_count) break; @@ -1222,10 +1224,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac emms_c(); *got_frame = 1; - *(AVFrame*)data = c->pic; + *(AVFrame*)data = *c->pic; if (c->version > 'b') - FFSWAP(AVFrame, c->pic, c->last); + FFSWAP(AVFrame*, c->pic, c->last); /* always report that the buffer was completely consumed */ return pkt->size; @@ -1274,7 +1276,7 @@ static av_cold int decode_init(AVCodecContext *avctx) c->version = avctx->codec_tag >> 24; if (avctx->extradata_size < 4) { av_log(avctx, AV_LOG_ERROR, "Extradata missing or too short\n"); - return -1; + return AVERROR_INVALIDDATA; } flags = AV_RL32(avctx->extradata); c->has_alpha = flags & BINK_FLAG_ALPHA; @@ -1291,15 +1293,19 @@ static av_cold int decode_init(AVCodecContext *avctx) } c->avctx = avctx; - c->pic.data[0] = NULL; - - if (av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) { - return 1; + c->pic = avcodec_alloc_frame(); + c->last = avcodec_alloc_frame(); + if (!c->pic || !c->last) { + avcodec_free_frame(&c->pic); + avcodec_free_frame(&c->last); + return AVERROR(ENOMEM); } + if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0) + return ret; + avctx->pix_fmt = c->has_alpha ? AV_PIX_FMT_YUVA420P : AV_PIX_FMT_YUV420P; - avctx->idct_algo = FF_IDCT_BINK; ff_dsputil_init(&c->dsp, avctx); ff_binkdsp_init(&c->bdsp); @@ -1322,10 +1328,12 @@ static av_cold int decode_end(AVCodecContext *avctx) { BinkContext * const c = avctx->priv_data; - if (c->pic.data[0]) - avctx->release_buffer(avctx, &c->pic); - if (c->last.data[0]) - avctx->release_buffer(avctx, &c->last); + if (c->pic->data[0]) + avctx->release_buffer(avctx, c->pic); + if (c->last->data[0]) + avctx->release_buffer(avctx, c->last); + avcodec_free_frame(&c->pic); + avcodec_free_frame(&c->last); free_bundles(c); return 0; diff --git a/mythtv/external/FFmpeg/libavcodec/binkaudio.c b/mythtv/external/FFmpeg/libavcodec/binkaudio.c index 6fe14df52fc..5ba77a68f09 100644 --- a/mythtv/external/FFmpeg/libavcodec/binkaudio.c +++ b/mythtv/external/FFmpeg/libavcodec/binkaudio.c @@ -32,7 +32,6 @@ #include "avcodec.h" #define BITSTREAM_READER_LE #include "get_bits.h" -#include "dsputil.h" #include "dct.h" #include "rdft.h" #include "fmtconvert.h" @@ -47,7 +46,6 @@ static float quant_table[96]; #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11) typedef struct { - AVFrame frame; GetBitContext gb; int version_b; ///< Bink version 'b' int first; @@ -143,9 +141,6 @@ static av_cold int decode_init(AVCodecContext *avctx) else return -1; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -294,6 +289,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { BinkAudioContext *s = avctx->priv_data; + AVFrame *frame = data; GetBitContext *gb = &s->gb; int ret, consumed = 0; @@ -321,22 +317,21 @@ static int decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - s->frame.nb_samples = s->frame_len; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = s->frame_len; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - if (decode_block(s, (float **)s->frame.extended_data, + if (decode_block(s, (float **)frame->extended_data, avctx->codec->id == AV_CODEC_ID_BINKAUDIO_DCT)) { av_log(avctx, AV_LOG_ERROR, "Incomplete packet\n"); return AVERROR_INVALIDDATA; } get_bits_align32(gb); - s->frame.nb_samples = s->block_size / avctx->channels; - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + frame->nb_samples = s->block_size / avctx->channels; + *got_frame_ptr = 1; return consumed; } diff --git a/mythtv/external/FFmpeg/libavcodec/binkdsp.h b/mythtv/external/FFmpeg/libavcodec/binkdsp.h index d105f717e90..4968413bee9 100644 --- a/mythtv/external/FFmpeg/libavcodec/binkdsp.h +++ b/mythtv/external/FFmpeg/libavcodec/binkdsp.h @@ -27,7 +27,7 @@ #ifndef AVCODEC_BINKDSP_H #define AVCODEC_BINKDSP_H -#include "dsputil.h" +#include typedef struct BinkDSPContext { void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, int32_t *block/*align 16*/); diff --git a/mythtv/external/FFmpeg/libavcodec/bit_depth_template.c b/mythtv/external/FFmpeg/libavcodec/bit_depth_template.c index 6b757fc0416..1a6d0078459 100644 --- a/mythtv/external/FFmpeg/libavcodec/bit_depth_template.c +++ b/mythtv/external/FFmpeg/libavcodec/bit_depth_template.c @@ -16,7 +16,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "dsputil.h" +#include "rnd_avg.h" +#include "libavutil/intreadwrite.h" #ifndef BIT_DEPTH #define BIT_DEPTH 8 diff --git a/mythtv/external/FFmpeg/libavcodec/bmp.c b/mythtv/external/FFmpeg/libavcodec/bmp.c index 13f3c7e1b24..fb69396ab49 100644 --- a/mythtv/external/FFmpeg/libavcodec/bmp.c +++ b/mythtv/external/FFmpeg/libavcodec/bmp.c @@ -49,8 +49,8 @@ static int bmp_decode_frame(AVCodecContext *avctx, unsigned int depth; BiCompression comp; unsigned int ihsize; - int i, j, n, linesize; - uint32_t rgb[3]; + int i, j, n, linesize, ret; + uint32_t rgb[3] = {0}; uint32_t alpha = 0; uint8_t *ptr; int dsize; @@ -59,13 +59,13 @@ static int bmp_decode_frame(AVCodecContext *avctx, if (buf_size < 14) { av_log(avctx, AV_LOG_ERROR, "buf size too small (%d)\n", buf_size); - return -1; + return AVERROR_INVALIDDATA; } if (bytestream_get_byte(&buf) != 'B' || bytestream_get_byte(&buf) != 'M') { av_log(avctx, AV_LOG_ERROR, "bad magic number\n"); - return -1; + return AVERROR_INVALIDDATA; } fsize = bytestream_get_le32(&buf); @@ -82,7 +82,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, ihsize = bytestream_get_le32(&buf); /* more header size */ if (ihsize + 14 > hsize) { av_log(avctx, AV_LOG_ERROR, "invalid header size %d\n", hsize); - return -1; + return AVERROR_INVALIDDATA; } /* sometimes file size is set to some headers size, set a real size in that case */ @@ -92,7 +92,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, if (fsize <= hsize) { av_log(avctx, AV_LOG_ERROR, "declared file size is less than header size (%d < %d)\n", fsize, hsize); - return -1; + return AVERROR_INVALIDDATA; } switch (ihsize) { @@ -110,13 +110,13 @@ static int bmp_decode_frame(AVCodecContext *avctx, break; default: av_log(avctx, AV_LOG_ERROR, "unsupported BMP file, patch welcome\n"); - return -1; + return AVERROR_PATCHWELCOME; } /* planes */ if (bytestream_get_le16(&buf) != 1) { av_log(avctx, AV_LOG_ERROR, "invalid BMP header\n"); - return -1; + return AVERROR_INVALIDDATA; } depth = bytestream_get_le16(&buf); @@ -129,7 +129,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, if (comp != BMP_RGB && comp != BMP_BITFIELDS && comp != BMP_RLE4 && comp != BMP_RLE8) { av_log(avctx, AV_LOG_ERROR, "BMP coding %d not supported\n", comp); - return -1; + return AVERROR_INVALIDDATA; } if (comp == BMP_BITFIELDS) { @@ -195,26 +195,26 @@ static int bmp_decode_frame(AVCodecContext *avctx, avctx->pix_fmt = AV_PIX_FMT_PAL8; } else { av_log(avctx, AV_LOG_ERROR, "Unknown palette for %d-colour BMP\n", 1<pix_fmt == AV_PIX_FMT_NONE) { av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n"); - return -1; + return AVERROR_INVALIDDATA; } if (p->data[0]) avctx->release_buffer(avctx, p); p->reference = 0; - if (ff_get_buffer(avctx, p) < 0) { + if ((ret = ff_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; @@ -228,7 +228,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, if (n * avctx->height > dsize && comp != BMP_RLE4 && comp != BMP_RLE8) { av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n", dsize, n * avctx->height); - return -1; + return AVERROR_INVALIDDATA; } // RLE may skip decoding some picture areas, so blank picture before decoding @@ -261,6 +261,10 @@ static int bmp_decode_frame(AVCodecContext *avctx, buf = buf0 + 14 + ihsize; //palette location // OS/2 bitmap, 3 bytes per palette entry if ((hsize-ihsize-14) < (colors << 2)) { + if ((hsize-ihsize-14) < colors * 3) { + av_log(avctx, AV_LOG_ERROR, "palette doesnt fit in packet\n"); + return AVERROR_INVALIDDATA; + } for (i = 0; i < colors; i++) ((uint32_t*)p->data[1])[i] = (0xFFU<<24) | bytestream_get_le24(&buf); } else { @@ -333,7 +337,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, break; default: av_log(avctx, AV_LOG_ERROR, "BMP decoder is broken\n"); - return -1; + return AVERROR_INVALIDDATA; } } diff --git a/mythtv/external/FFmpeg/libavcodec/bmv.c b/mythtv/external/FFmpeg/libavcodec/bmv.c index defa1ab88bb..c480815333b 100644 --- a/mythtv/external/FFmpeg/libavcodec/bmv.c +++ b/mythtv/external/FFmpeg/libavcodec/bmv.c @@ -68,7 +68,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, int i; if (src_len <= 0) - return -1; + return AVERROR_INVALIDDATA; if (forward) { src = source; @@ -92,7 +92,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, */ if (!mode || (tmplen == 4)) { if (src < source || src >= source_end) - return -1; + return AVERROR_INVALIDDATA; val = *src; read_two_nibbles = 1; } else { @@ -105,7 +105,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, return -1; if (!read_two_nibbles) { if (src < source || src >= source_end) - return -1; + return AVERROR_INVALIDDATA; shift += 2; val |= *src << shift; if (*src & 0xC) @@ -141,7 +141,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, if (mode >= 4) mode -= 3; if (FFABS(dst_end - dst) < len) - return -1; + return AVERROR_INVALIDDATA; switch (mode) { case 1: if (forward) { @@ -149,7 +149,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, dst - frame + SCREEN_WIDE + frame_off < 0 || frame_end - dst < frame_off + len || frame_end - dst < len) - return -1; + return AVERROR_INVALIDDATA; for (i = 0; i < len; i++) dst[i] = dst[frame_off + i]; dst += len; @@ -159,7 +159,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, dst - frame + SCREEN_WIDE + frame_off < 0 || frame_end - dst < frame_off + len || frame_end - dst < len) - return -1; + return AVERROR_INVALIDDATA; for (i = len - 1; i >= 0; i--) dst[i] = dst[frame_off + i]; } @@ -167,13 +167,13 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, case 2: if (forward) { if (source + src_len - src < len) - return -1; + return AVERROR_INVALIDDATA; memcpy(dst, src, len); dst += len; src += len; } else { if (src - source < len) - return -1; + return AVERROR_INVALIDDATA; dst -= len; src -= len; memcpy(dst, src, len); @@ -302,32 +302,23 @@ static av_cold int decode_end(AVCodecContext *avctx) return 0; } -typedef struct BMVAudioDecContext { - AVFrame frame; -} BMVAudioDecContext; - static const int bmv_aud_mults[16] = { 16512, 8256, 4128, 2064, 1032, 516, 258, 192, 129, 88, 64, 56, 48, 40, 36, 32 }; static av_cold int bmv_aud_decode_init(AVCodecContext *avctx) { - BMVAudioDecContext *c = avctx->priv_data; - avctx->channels = 2; avctx->channel_layout = AV_CH_LAYOUT_STEREO; avctx->sample_fmt = AV_SAMPLE_FMT_S16; - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - return 0; } static int bmv_aud_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { - BMVAudioDecContext *c = avctx->priv_data; + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int blocks = 0, total_blocks, i; @@ -343,12 +334,12 @@ static int bmv_aud_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - c->frame.nb_samples = total_blocks * 32; - if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = total_blocks * 32; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - output_samples = (int16_t *)c->frame.data[0]; + output_samples = (int16_t *)frame->data[0]; for (blocks = 0; blocks < total_blocks; blocks++) { uint8_t code = *buf++; @@ -361,8 +352,7 @@ static int bmv_aud_decode_frame(AVCodecContext *avctx, void *data, } } - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return buf_size; } @@ -383,7 +373,6 @@ AVCodec ff_bmv_audio_decoder = { .name = "bmv_audio", .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_BMV_AUDIO, - .priv_data_size = sizeof(BMVAudioDecContext), .init = bmv_aud_decode_init, .decode = bmv_aud_decode_frame, .capabilities = CODEC_CAP_DR1, diff --git a/mythtv/external/FFmpeg/libavcodec/brender_pix.c b/mythtv/external/FFmpeg/libavcodec/brender_pix.c index 5245fa0d71c..6c63244ac9a 100644 --- a/mythtv/external/FFmpeg/libavcodec/brender_pix.c +++ b/mythtv/external/FFmpeg/libavcodec/brender_pix.c @@ -193,6 +193,14 @@ static int brpix_decode_frame(AVCodecContext *avctx, s->frame.palette_has_changed = 1; chunk_type = bytestream2_get_be32(&gb); + } else if (avctx->pix_fmt == AV_PIX_FMT_PAL8) { + uint32_t *pal_out = (uint32_t *)s->frame.data[1]; + int i; + + for (i = 0; i < 256; ++i) { + *pal_out++ = (0xFFU << 24) | (i * 0x010101); + } + s->frame.palette_has_changed = 1; } data_len = bytestream2_get_be32(&gb); diff --git a/mythtv/external/FFmpeg/libavcodec/c93.c b/mythtv/external/FFmpeg/libavcodec/c93.c index 9f3bf8b6ccc..e5f371b0814 100644 --- a/mythtv/external/FFmpeg/libavcodec/c93.c +++ b/mythtv/external/FFmpeg/libavcodec/c93.c @@ -134,7 +134,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, newpic->reference = 3; newpic->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; - if ((ret = avctx->reget_buffer(avctx, newpic))) { + if ((ret = avctx->reget_buffer(avctx, newpic)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return ret; } @@ -166,8 +166,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, switch (block_type) { case C93_8X8_FROM_PREV: offset = bytestream2_get_le16(&gb); - if (copy_block(avctx, out, copy_from, offset, 8, stride)) - return AVERROR_INVALIDDATA; + if ((ret = copy_block(avctx, out, copy_from, offset, 8, stride)) < 0) + return ret; break; case C93_4X4_FROM_CURR: @@ -176,9 +176,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, for (j = 0; j < 8; j += 4) { for (i = 0; i < 8; i += 4) { offset = bytestream2_get_le16(&gb); - if (copy_block(avctx, &out[j*stride+i], - copy_from, offset, 4, stride)) - return AVERROR_INVALIDDATA; + if ((ret = copy_block(avctx, &out[j*stride+i], + copy_from, offset, 4, stride)) < 0) + return ret; } } break; diff --git a/mythtv/external/FFmpeg/libavcodec/cavs.c b/mythtv/external/FFmpeg/libavcodec/cavs.c index e1ac0befa36..adf0ecaa563 100644 --- a/mythtv/external/FFmpeg/libavcodec/cavs.c +++ b/mythtv/external/FFmpeg/libavcodec/cavs.c @@ -28,6 +28,7 @@ #include "avcodec.h" #include "get_bits.h" #include "golomb.h" +#include "h264chroma.h" #include "mathops.h" #include "cavs.h" @@ -464,30 +465,35 @@ void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type) { if(ff_cavs_partition_flags[mb_type] == 0){ // 16x16 mc_part_std(h, 8, 0, h->cy, h->cu, h->cv, 0, 0, h->cdsp.put_cavs_qpel_pixels_tab[0], - h->dsp.put_h264_chroma_pixels_tab[0], + h->h264chroma.put_h264_chroma_pixels_tab[0], h->cdsp.avg_cavs_qpel_pixels_tab[0], - h->dsp.avg_h264_chroma_pixels_tab[0],&h->mv[MV_FWD_X0]); + h->h264chroma.avg_h264_chroma_pixels_tab[0], + &h->mv[MV_FWD_X0]); }else{ mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 0, 0, h->cdsp.put_cavs_qpel_pixels_tab[1], - h->dsp.put_h264_chroma_pixels_tab[1], + h->h264chroma.put_h264_chroma_pixels_tab[1], h->cdsp.avg_cavs_qpel_pixels_tab[1], - h->dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X0]); + h->h264chroma.avg_h264_chroma_pixels_tab[1], + &h->mv[MV_FWD_X0]); mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 4, 0, h->cdsp.put_cavs_qpel_pixels_tab[1], - h->dsp.put_h264_chroma_pixels_tab[1], + h->h264chroma.put_h264_chroma_pixels_tab[1], h->cdsp.avg_cavs_qpel_pixels_tab[1], - h->dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X1]); + h->h264chroma.avg_h264_chroma_pixels_tab[1], + &h->mv[MV_FWD_X1]); mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 0, 4, h->cdsp.put_cavs_qpel_pixels_tab[1], - h->dsp.put_h264_chroma_pixels_tab[1], + h->h264chroma.put_h264_chroma_pixels_tab[1], h->cdsp.avg_cavs_qpel_pixels_tab[1], - h->dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X2]); + h->h264chroma.avg_h264_chroma_pixels_tab[1], + &h->mv[MV_FWD_X2]); mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 4, 4, h->cdsp.put_cavs_qpel_pixels_tab[1], - h->dsp.put_h264_chroma_pixels_tab[1], + h->h264chroma.put_h264_chroma_pixels_tab[1], h->cdsp.avg_cavs_qpel_pixels_tab[1], - h->dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X3]); + h->h264chroma.avg_h264_chroma_pixels_tab[1], + &h->mv[MV_FWD_X3]); } } @@ -715,13 +721,14 @@ void ff_cavs_init_top_lines(AVSContext *h) { /* alloc space for co-located MVs and types */ h->col_mv = av_mallocz( h->mb_width*h->mb_height*4*sizeof(cavs_vector)); h->col_type_base = av_mallocz(h->mb_width*h->mb_height); - h->block = av_mallocz(64*sizeof(DCTELEM)); + h->block = av_mallocz(64*sizeof(int16_t)); } av_cold int ff_cavs_init(AVCodecContext *avctx) { AVSContext *h = avctx->priv_data; ff_dsputil_init(&h->dsp, avctx); + ff_h264chroma_init(&h->h264chroma, 8); ff_videodsp_init(&h->vdsp, 8); ff_cavsdsp_init(&h->cdsp, avctx); ff_init_scantable_permutation(h->dsp.idct_permutation, diff --git a/mythtv/external/FFmpeg/libavcodec/cavs.h b/mythtv/external/FFmpeg/libavcodec/cavs.h index 649a567b414..b0cdb8f2007 100644 --- a/mythtv/external/FFmpeg/libavcodec/cavs.h +++ b/mythtv/external/FFmpeg/libavcodec/cavs.h @@ -24,6 +24,7 @@ #include "cavsdsp.h" #include "dsputil.h" +#include "h264chroma.h" #include "get_bits.h" #include "videodsp.h" @@ -161,6 +162,7 @@ typedef struct AVSFrame { typedef struct AVSContext { AVCodecContext *avctx; DSPContext dsp; + H264ChromaContext h264chroma; VideoDSPContext vdsp; CAVSDSPContext cdsp; GetBitContext gb; @@ -234,7 +236,7 @@ typedef struct AVSContext { uint8_t *edge_emu_buffer; int got_keyframe; - DCTELEM *block; + int16_t *block; } AVSContext; extern const uint8_t ff_cavs_partition_flags[30]; diff --git a/mythtv/external/FFmpeg/libavcodec/cavsdec.c b/mythtv/external/FFmpeg/libavcodec/cavsdec.c index 0074c4cf6d9..fa60d6c0eb8 100644 --- a/mythtv/external/FFmpeg/libavcodec/cavsdec.c +++ b/mythtv/external/FFmpeg/libavcodec/cavsdec.c @@ -510,15 +510,19 @@ static inline void mv_pred_sym(AVSContext *h, cavs_vector *src, /** kth-order exponential golomb code */ static inline int get_ue_code(GetBitContext *gb, int order) { + unsigned ret = get_ue_golomb(gb); + if (ret >= ((1U<<31)>>order)) { + av_log(NULL, AV_LOG_ERROR, "get_ue_code: value too larger\n"); + return AVERROR_INVALIDDATA; + } if (order) { - int ret = get_ue_golomb(gb) << order; - return ret + get_bits(gb, order); + return (ret<block; + int16_t *block = h->block; for (i = 0; i < 65; i++) { level_code = get_ue_code(gb, r->golomb_order); diff --git a/mythtv/external/FFmpeg/libavcodec/cavsdsp.c b/mythtv/external/FFmpeg/libavcodec/cavsdsp.c index a9b136e2a3c..f66cabca285 100644 --- a/mythtv/external/FFmpeg/libavcodec/cavsdsp.c +++ b/mythtv/external/FFmpeg/libavcodec/cavsdsp.c @@ -183,9 +183,9 @@ static void cavs_filter_ch_c(uint8_t *d, int stride, int alpha, int beta, int tc * ****************************************************************************/ -static void cavs_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride) { +static void cavs_idct8_add_c(uint8_t *dst, int16_t *block, int stride) { int i; - DCTELEM (*src)[8] = (DCTELEM(*)[8])block; + int16_t (*src)[8] = (int16_t(*)[8])block; uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; src[0][0] += 8; diff --git a/mythtv/external/FFmpeg/libavcodec/cavsdsp.h b/mythtv/external/FFmpeg/libavcodec/cavsdsp.h index f6e3e18e83b..4598c7d745e 100644 --- a/mythtv/external/FFmpeg/libavcodec/cavsdsp.h +++ b/mythtv/external/FFmpeg/libavcodec/cavsdsp.h @@ -32,7 +32,7 @@ typedef struct CAVSDSPContext { void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); - void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride); + void (*cavs_idct8_add)(uint8_t *dst, int16_t *block, int stride); int idct_perm; } CAVSDSPContext; diff --git a/mythtv/external/FFmpeg/libavcodec/cdgraphics.c b/mythtv/external/FFmpeg/libavcodec/cdgraphics.c index 71d9da7ee23..94ce6ae946b 100644 --- a/mythtv/external/FFmpeg/libavcodec/cdgraphics.c +++ b/mythtv/external/FFmpeg/libavcodec/cdgraphics.c @@ -291,12 +291,18 @@ static int cdg_decode_frame(AVCodecContext *avctx, av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return ret; } + if (!avctx->frame_number) { + memset(cc->frame.data[0], 0, cc->frame.linesize[0] * avctx->height); + memset(cc->frame.data[1], 0, AVPALETTE_SIZE); + } command = bytestream_get_byte(&buf); inst = bytestream_get_byte(&buf); inst &= CDG_MASK; buf += 2; /// skipping 2 unneeded bytes - bytestream_get_buffer(&buf, cdg_data, buf_size - CDG_HEADER_SIZE); + + if (buf_size > CDG_HEADER_SIZE) + bytestream_get_buffer(&buf, cdg_data, buf_size - CDG_HEADER_SIZE); if ((command & CDG_MASK) == CDG_COMMAND) { switch (inst) { diff --git a/mythtv/external/FFmpeg/libavcodec/cdxl.c b/mythtv/external/FFmpeg/libavcodec/cdxl.c index 3c2afd02326..1af69b75b46 100644 --- a/mythtv/external/FFmpeg/libavcodec/cdxl.c +++ b/mythtv/external/FFmpeg/libavcodec/cdxl.c @@ -119,6 +119,7 @@ static void cdxl_decode_rgb(CDXLVideoContext *c) { uint32_t *new_palette = (uint32_t *)c->frame.data[1]; + memset(c->frame.data[1], 0, AVPALETTE_SIZE); import_palette(c, new_palette); import_format(c, c->frame.linesize[0], c->frame.data[0]); } diff --git a/mythtv/external/FFmpeg/libavcodec/cinepak.c b/mythtv/external/FFmpeg/libavcodec/cinepak.c index b323da47411..5bd3f1349b9 100644 --- a/mythtv/external/FFmpeg/libavcodec/cinepak.c +++ b/mythtv/external/FFmpeg/libavcodec/cinepak.c @@ -28,6 +28,9 @@ * http://www.csse.monash.edu.au/~timf/ * @see For more information on the quirky data inside Sega FILM/CPK files, visit: * http://wiki.multimedia.cx/index.php?title=Sega_FILM + * + * Cinepak colorspace support (c) 2013 Rl, Aetey Global Technologies AB + * @author Cinepak colorspace, Rl, Aetey Global Technologies AB */ #include @@ -39,10 +42,7 @@ #include "avcodec.h" -typedef struct { - uint8_t y0, y1, y2, y3; - uint8_t u, v; -} cvid_codebook; +typedef uint8_t cvid_codebook[12]; #define MAX_STRIPS 32 @@ -78,12 +78,14 @@ static void cinepak_decode_codebook (cvid_codebook *codebook, const uint8_t *eod = (data + size); uint32_t flag, mask; int i, n; + uint8_t *p; /* check if this chunk contains 4- or 6-element vectors */ n = (chunk_id & 0x04) ? 4 : 6; flag = 0; mask = 0; + p = codebook[0]; for (i=0; i < 256; i++) { if ((chunk_id & 0x01) && !(mask >>= 1)) { if ((data + 4) > eod) @@ -95,28 +97,33 @@ static void cinepak_decode_codebook (cvid_codebook *codebook, } if (!(chunk_id & 0x01) || (flag & mask)) { + int k, kk; + if ((data + n) > eod) break; + for (k = 0; k < 4; ++k) { + int r = *data++; + for (kk = 0; kk < 3; ++kk) + *p++ = r; + } if (n == 6) { - codebook[i].y0 = *data++; - codebook[i].y1 = *data++; - codebook[i].y2 = *data++; - codebook[i].y3 = *data++; - codebook[i].u = 128 + *data++; - codebook[i].v = 128 + *data++; - } else { - /* this codebook type indicates either greyscale or - * palettized video; if palettized, U & V components will - * not be used so it is safe to set them to 128 for the - * benefit of greyscale rendering in YUV420P */ - codebook[i].y0 = *data++; - codebook[i].y1 = *data++; - codebook[i].y2 = *data++; - codebook[i].y3 = *data++; - codebook[i].u = 128; - codebook[i].v = 128; + int r, g, b, u, v; + u = *(int8_t *)data++; + v = *(int8_t *)data++; + p -= 12; + for(k=0; k<4; ++k) { + r = *p++ + v*2; + g = *p++ - (u/2) - v; + b = *p + u*2; + p -= 2; + *p++ = av_clip_uint8(r); + *p++ = av_clip_uint8(g); + *p++ = av_clip_uint8(b); + } } + } else { + p += 12; } } } @@ -126,25 +133,31 @@ static int cinepak_decode_vectors (CinepakContext *s, cvid_strip *strip, { const uint8_t *eod = (data + size); uint32_t flag, mask; - cvid_codebook *codebook; + uint8_t *cb0, *cb1, *cb2, *cb3; unsigned int x, y; - uint32_t iy[4]; - uint32_t iu[2]; - uint32_t iv[2]; + char *ip0, *ip1, *ip2, *ip3; flag = 0; mask = 0; for (y=strip->y1; y < strip->y2; y+=4) { - iy[0] = strip->x1 + (y * s->frame.linesize[0]); - iy[1] = iy[0] + s->frame.linesize[0]; - iy[2] = iy[1] + s->frame.linesize[0]; - iy[3] = iy[2] + s->frame.linesize[0]; - iu[0] = (strip->x1/2) + ((y/2) * s->frame.linesize[1]); - iu[1] = iu[0] + s->frame.linesize[1]; - iv[0] = (strip->x1/2) + ((y/2) * s->frame.linesize[2]); - iv[1] = iv[0] + s->frame.linesize[2]; +/* take care of y dimension not being multiple of 4, such streams exist */ + ip0 = ip1 = ip2 = ip3 = s->frame.data[0] + + (s->palette_video?strip->x1:strip->x1*3) + (y * s->frame.linesize[0]); + if(s->avctx->height - y > 1) { + ip1 = ip0 + s->frame.linesize[0]; + if(s->avctx->height - y > 2) { + ip2 = ip1 + s->frame.linesize[0]; + if(s->avctx->height - y > 3) { + ip3 = ip2 + s->frame.linesize[0]; + } + } + } +/* to get the correct picture for not-multiple-of-4 cases let us fill + * each block from the bottom up, thus possibly overwriting the top line + * more than once but ending with the correct data in place + * (instead of in-loop checking) */ for (x=strip->x1; x < strip->x2; x+=4) { if ((chunk_id & 0x01) && !(mask >>= 1)) { @@ -167,97 +180,82 @@ static int cinepak_decode_vectors (CinepakContext *s, cvid_strip *strip, } if ((chunk_id & 0x02) || (~flag & mask)) { + uint8_t *p; if (data >= eod) return AVERROR_INVALIDDATA; - codebook = &strip->v1_codebook[*data++]; - s->frame.data[0][iy[0] + 0] = codebook->y0; - s->frame.data[0][iy[0] + 1] = codebook->y0; - s->frame.data[0][iy[1] + 0] = codebook->y0; - s->frame.data[0][iy[1] + 1] = codebook->y0; - if (!s->palette_video) { - s->frame.data[1][iu[0]] = codebook->u; - s->frame.data[2][iv[0]] = codebook->v; - } - - s->frame.data[0][iy[0] + 2] = codebook->y1; - s->frame.data[0][iy[0] + 3] = codebook->y1; - s->frame.data[0][iy[1] + 2] = codebook->y1; - s->frame.data[0][iy[1] + 3] = codebook->y1; - if (!s->palette_video) { - s->frame.data[1][iu[0] + 1] = codebook->u; - s->frame.data[2][iv[0] + 1] = codebook->v; - } - - s->frame.data[0][iy[2] + 0] = codebook->y2; - s->frame.data[0][iy[2] + 1] = codebook->y2; - s->frame.data[0][iy[3] + 0] = codebook->y2; - s->frame.data[0][iy[3] + 1] = codebook->y2; - if (!s->palette_video) { - s->frame.data[1][iu[1]] = codebook->u; - s->frame.data[2][iv[1]] = codebook->v; - } - - s->frame.data[0][iy[2] + 2] = codebook->y3; - s->frame.data[0][iy[2] + 3] = codebook->y3; - s->frame.data[0][iy[3] + 2] = codebook->y3; - s->frame.data[0][iy[3] + 3] = codebook->y3; - if (!s->palette_video) { - s->frame.data[1][iu[1] + 1] = codebook->u; - s->frame.data[2][iv[1] + 1] = codebook->v; + p = strip->v1_codebook[*data++]; + if (s->palette_video) { + ip3[0] = ip3[1] = ip2[0] = ip2[1] = p[6]; + ip3[2] = ip3[3] = ip2[2] = ip2[3] = p[9]; + ip1[0] = ip1[1] = ip0[0] = ip0[1] = p[0]; + ip1[2] = ip1[3] = ip0[2] = ip0[3] = p[3]; + } else { + p += 6; + memcpy(ip3 + 0, p, 3); memcpy(ip3 + 3, p, 3); + memcpy(ip2 + 0, p, 3); memcpy(ip2 + 3, p, 3); + p += 3; /* ... + 9 */ + memcpy(ip3 + 6, p, 3); memcpy(ip3 + 9, p, 3); + memcpy(ip2 + 6, p, 3); memcpy(ip2 + 9, p, 3); + p -= 9; /* ... + 0 */ + memcpy(ip1 + 0, p, 3); memcpy(ip1 + 3, p, 3); + memcpy(ip0 + 0, p, 3); memcpy(ip0 + 3, p, 3); + p += 3; /* ... + 3 */ + memcpy(ip1 + 6, p, 3); memcpy(ip1 + 9, p, 3); + memcpy(ip0 + 6, p, 3); memcpy(ip0 + 9, p, 3); } } else if (flag & mask) { if ((data + 4) > eod) return AVERROR_INVALIDDATA; - codebook = &strip->v4_codebook[*data++]; - s->frame.data[0][iy[0] + 0] = codebook->y0; - s->frame.data[0][iy[0] + 1] = codebook->y1; - s->frame.data[0][iy[1] + 0] = codebook->y2; - s->frame.data[0][iy[1] + 1] = codebook->y3; - if (!s->palette_video) { - s->frame.data[1][iu[0]] = codebook->u; - s->frame.data[2][iv[0]] = codebook->v; - } - - codebook = &strip->v4_codebook[*data++]; - s->frame.data[0][iy[0] + 2] = codebook->y0; - s->frame.data[0][iy[0] + 3] = codebook->y1; - s->frame.data[0][iy[1] + 2] = codebook->y2; - s->frame.data[0][iy[1] + 3] = codebook->y3; - if (!s->palette_video) { - s->frame.data[1][iu[0] + 1] = codebook->u; - s->frame.data[2][iv[0] + 1] = codebook->v; - } - - codebook = &strip->v4_codebook[*data++]; - s->frame.data[0][iy[2] + 0] = codebook->y0; - s->frame.data[0][iy[2] + 1] = codebook->y1; - s->frame.data[0][iy[3] + 0] = codebook->y2; - s->frame.data[0][iy[3] + 1] = codebook->y3; - if (!s->palette_video) { - s->frame.data[1][iu[1]] = codebook->u; - s->frame.data[2][iv[1]] = codebook->v; - } - - codebook = &strip->v4_codebook[*data++]; - s->frame.data[0][iy[2] + 2] = codebook->y0; - s->frame.data[0][iy[2] + 3] = codebook->y1; - s->frame.data[0][iy[3] + 2] = codebook->y2; - s->frame.data[0][iy[3] + 3] = codebook->y3; - if (!s->palette_video) { - s->frame.data[1][iu[1] + 1] = codebook->u; - s->frame.data[2][iv[1] + 1] = codebook->v; + cb0 = strip->v4_codebook[*data++]; + cb1 = strip->v4_codebook[*data++]; + cb2 = strip->v4_codebook[*data++]; + cb3 = strip->v4_codebook[*data++]; + if (s->palette_video) { + uint8_t *p; + p = ip3; + *p++ = cb2[6]; + *p++ = cb2[9]; + *p++ = cb3[6]; + *p = cb3[9]; + p = ip2; + *p++ = cb2[0]; + *p++ = cb2[3]; + *p++ = cb3[0]; + *p = cb3[3]; + p = ip1; + *p++ = cb0[6]; + *p++ = cb0[9]; + *p++ = cb1[6]; + *p = cb1[9]; + p = ip0; + *p++ = cb0[0]; + *p++ = cb0[3]; + *p++ = cb1[0]; + *p = cb1[3]; + } else { + memcpy(ip3 + 0, cb2 + 6, 6); + memcpy(ip3 + 6, cb3 + 6, 6); + memcpy(ip2 + 0, cb2 + 0, 6); + memcpy(ip2 + 6, cb3 + 0, 6); + memcpy(ip1 + 0, cb0 + 6, 6); + memcpy(ip1 + 6, cb1 + 6, 6); + memcpy(ip0 + 0, cb0 + 0, 6); + memcpy(ip0 + 6, cb1 + 0, 6); } } } - iy[0] += 4; iy[1] += 4; - iy[2] += 4; iy[3] += 4; - iu[0] += 2; iu[1] += 2; - iv[0] += 2; iv[1] += 2; + if (s->palette_video) { + ip0 += 4; ip1 += 4; + ip2 += 4; ip3 += 4; + } else { + ip0 += 12; ip1 += 12; + ip2 += 12; ip3 += 12; + } } } @@ -368,10 +366,13 @@ static int cinepak_decode (CinepakContext *s) return AVERROR_INVALIDDATA; s->strips[i].id = s->data[0]; - s->strips[i].y1 = y0; - s->strips[i].x1 = 0; - s->strips[i].y2 = y0 + AV_RB16 (&s->data[8]); - s->strips[i].x2 = s->avctx->width; +/* zero y1 means "relative to the previous stripe" */ + if (!(s->strips[i].y1 = AV_RB16 (&s->data[4]))) + s->strips[i].y2 = (s->strips[i].y1 = y0) + AV_RB16 (&s->data[8]); + else + s->strips[i].y2 = AV_RB16 (&s->data[8]); + s->strips[i].x1 = AV_RB16 (&s->data[6]); + s->strips[i].x2 = AV_RB16 (&s->data[10]); if (s->strips[i].id == 0x10) s->frame.key_frame = 1; @@ -407,12 +408,13 @@ static av_cold int cinepak_decode_init(AVCodecContext *avctx) s->avctx = avctx; s->width = (avctx->width + 3) & ~3; s->height = (avctx->height + 3) & ~3; + s->sega_film_skip_bytes = -1; /* uninitialized state */ // check for paletted data if (avctx->bits_per_coded_sample != 8) { s->palette_video = 0; - avctx->pix_fmt = AV_PIX_FMT_YUV420P; + avctx->pix_fmt = AV_PIX_FMT_RGB24; } else { s->palette_video = 1; avctx->pix_fmt = AV_PIX_FMT_PAL8; @@ -451,7 +453,9 @@ static int cinepak_decode_frame(AVCodecContext *avctx, } } - cinepak_decode(s); + if ((ret = cinepak_decode(s)) < 0) { + av_log(avctx, AV_LOG_ERROR, "cinepak_decode failed\n"); + } if (s->palette_video) memcpy (s->frame.data[1], s->pal, AVPALETTE_SIZE); diff --git a/mythtv/external/FFmpeg/libavcodec/cngdec.c b/mythtv/external/FFmpeg/libavcodec/cngdec.c index d2b1257af9b..edfdd3e44ce 100644 --- a/mythtv/external/FFmpeg/libavcodec/cngdec.c +++ b/mythtv/external/FFmpeg/libavcodec/cngdec.c @@ -28,7 +28,6 @@ #include "libavutil/lfg.h" typedef struct CNGContext { - AVFrame avframe; float *refl_coef, *target_refl_coef; float *lpc_coef; int order; @@ -58,8 +57,6 @@ static av_cold int cng_decode_init(AVCodecContext *avctx) avctx->channels = 1; avctx->sample_rate = 8000; - avcodec_get_frame_defaults(&p->avframe); - avctx->coded_frame = &p->avframe; p->order = 12; avctx->frame_size = 640; p->refl_coef = av_mallocz(p->order * sizeof(*p->refl_coef)); @@ -105,7 +102,7 @@ static void cng_decode_flush(AVCodecContext *avctx) static int cng_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { - + AVFrame *frame = data; CNGContext *p = avctx->priv_data; int buf_size = avpkt->size; int ret, i; @@ -144,19 +141,18 @@ static int cng_decode_frame(AVCodecContext *avctx, void *data, ff_celp_lp_synthesis_filterf(p->filter_out + p->order, p->lpc_coef, p->excitation, avctx->frame_size, p->order); - p->avframe.nb_samples = avctx->frame_size; - if ((ret = ff_get_buffer(avctx, &p->avframe)) < 0) { + frame->nb_samples = avctx->frame_size; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - buf_out = (int16_t *)p->avframe.data[0]; + buf_out = (int16_t *)frame->data[0]; for (i = 0; i < avctx->frame_size; i++) buf_out[i] = p->filter_out[i + p->order]; memcpy(p->filter_out, p->filter_out + avctx->frame_size, p->order * sizeof(*p->filter_out)); - *got_frame_ptr = 1; - *(AVFrame *)data = p->avframe; + *got_frame_ptr = 1; return buf_size; } diff --git a/mythtv/external/FFmpeg/libavcodec/codec_desc.c b/mythtv/external/FFmpeg/libavcodec/codec_desc.c index 7508ac3f357..673f9710b5d 100644 --- a/mythtv/external/FFmpeg/libavcodec/codec_desc.c +++ b/mythtv/external/FFmpeg/libavcodec/codec_desc.c @@ -749,7 +749,7 @@ static const AVCodecDescriptor codec_descriptors[] = { .type = AVMEDIA_TYPE_VIDEO, .name = "sgi", .long_name = NULL_IF_CONFIG_SMALL("SGI image"), - .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY, + .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS, }, { .id = AV_CODEC_ID_SGIRLE, @@ -944,7 +944,7 @@ static const AVCodecDescriptor codec_descriptors[] = { .type = AVMEDIA_TYPE_VIDEO, .name = "dpx", .long_name = NULL_IF_CONFIG_SMALL("DPX image"), - .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY, + .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS, }, { .id = AV_CODEC_ID_MAD, @@ -1030,6 +1030,13 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("On2 VP8"), .props = AV_CODEC_PROP_LOSSY, }, + { + .id = AV_CODEC_ID_VP9, + .type = AVMEDIA_TYPE_VIDEO, + .name = "vp9", + .long_name = NULL_IF_CONFIG_SMALL("Google VP9"), + .props = AV_CODEC_PROP_LOSSY, + }, { .id = AV_CODEC_ID_PICTOR, .type = AVMEDIA_TYPE_VIDEO, @@ -1348,12 +1355,14 @@ static const AVCodecDescriptor codec_descriptors[] = { .type = AVMEDIA_TYPE_VIDEO, .name = "xface", .long_name = NULL_IF_CONFIG_SMALL("X-face image"), + .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY, }, { .id = AV_CODEC_ID_BRENDER_PIX, .type = AVMEDIA_TYPE_VIDEO, .name = "brender_pix", .long_name = NULL_IF_CONFIG_SMALL("BRender PIX image"), + .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS, }, /* various PCM "codecs" */ @@ -2343,6 +2352,20 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("TAK (Tom's lossless Audio Kompressor)"), .props = AV_CODEC_PROP_LOSSLESS, }, + { + .id = AV_CODEC_ID_EVRC, + .type = AVMEDIA_TYPE_AUDIO, + .name = "evrc", + .long_name = NULL_IF_CONFIG_SMALL("EVRC (Enhanced Variable Rate Codec)"), + .props = AV_CODEC_PROP_LOSSY, + }, + { + .id = AV_CODEC_ID_SMV, + .type = AVMEDIA_TYPE_AUDIO, + .name = "smv", + .long_name = NULL_IF_CONFIG_SMALL("SMV (Selectable Mode Vocoder)"), + .props = AV_CODEC_PROP_LOSSY, + }, /* subtitle codecs */ { @@ -2350,12 +2373,14 @@ static const AVCodecDescriptor codec_descriptors[] = { .type = AVMEDIA_TYPE_SUBTITLE, .name = "dvd_subtitle", .long_name = NULL_IF_CONFIG_SMALL("DVD subtitles"), + .props = AV_CODEC_PROP_BITMAP_SUB, }, { .id = AV_CODEC_ID_DVB_SUBTITLE, .type = AVMEDIA_TYPE_SUBTITLE, .name = "dvb_subtitle", .long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"), + .props = AV_CODEC_PROP_BITMAP_SUB, }, { .id = AV_CODEC_ID_TEXT, @@ -2368,6 +2393,7 @@ static const AVCodecDescriptor codec_descriptors[] = { .type = AVMEDIA_TYPE_SUBTITLE, .name = "xsub", .long_name = NULL_IF_CONFIG_SMALL("XSUB"), + .props = AV_CODEC_PROP_BITMAP_SUB, }, { .id = AV_CODEC_ID_SSA, @@ -2386,6 +2412,7 @@ static const AVCodecDescriptor codec_descriptors[] = { .type = AVMEDIA_TYPE_SUBTITLE, .name = "hdmv_pgs_subtitle", .long_name = NULL_IF_CONFIG_SMALL("HDMV Presentation Graphic Stream subtitles"), + .props = AV_CODEC_PROP_BITMAP_SUB, }, { .id = AV_CODEC_ID_DVB_TELETEXT, diff --git a/mythtv/external/FFmpeg/libavcodec/cook.c b/mythtv/external/FFmpeg/libavcodec/cook.c index 4117cee1f92..7dcf6558ec5 100644 --- a/mythtv/external/FFmpeg/libavcodec/cook.c +++ b/mythtv/external/FFmpeg/libavcodec/cook.c @@ -123,7 +123,6 @@ typedef struct cook { AVCodecContext* avctx; DSPContext dsp; - AVFrame frame; GetBitContext gb; /* stream data */ int num_vectors; @@ -956,6 +955,7 @@ static int decode_subpacket(COOKContext *q, COOKSubpacket *p, static int cook_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; COOKContext *q = avctx->priv_data; @@ -969,12 +969,12 @@ static int cook_decode_frame(AVCodecContext *avctx, void *data, /* get output buffer */ if (q->discarded_packets >= 2) { - q->frame.nb_samples = q->samples_per_channel; - if ((ret = ff_get_buffer(avctx, &q->frame)) < 0) { + frame->nb_samples = q->samples_per_channel; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (float **)q->frame.extended_data; + samples = (float **)frame->extended_data; } /* estimate subpacket sizes */ @@ -1015,8 +1015,7 @@ static int cook_decode_frame(AVCodecContext *avctx, void *data, return avctx->block_align; } - *got_frame_ptr = 1; - *(AVFrame *) data = q->frame; + *got_frame_ptr = 1; return avctx->block_align; } @@ -1092,6 +1091,11 @@ static av_cold int cook_decode_init(AVCodecContext *avctx) if (extradata_size >= 8) { bytestream_get_be32(&edata_ptr); // Unknown unused q->subpacket[s].js_subband_start = bytestream_get_be16(&edata_ptr); + if (q->subpacket[s].js_subband_start >= 51) { + av_log(avctx, AV_LOG_ERROR, "js_subband_start %d is too large\n", q->subpacket[s].js_subband_start); + return AVERROR_INVALIDDATA; + } + q->subpacket[s].js_vlc_bits = bytestream_get_be16(&edata_ptr); extradata_size -= 8; } @@ -1269,9 +1273,6 @@ static av_cold int cook_decode_init(AVCodecContext *avctx) else avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; - avcodec_get_frame_defaults(&q->frame); - avctx->coded_frame = &q->frame; - #ifdef DEBUG dump_cook_context(q); #endif diff --git a/mythtv/external/FFmpeg/libavcodec/copy_block.h b/mythtv/external/FFmpeg/libavcodec/copy_block.h new file mode 100644 index 00000000000..a73910d80f4 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/copy_block.h @@ -0,0 +1,94 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_COPY_BLOCK_H +#define AVCODEC_COPY_BLOCK_H + +#include + +#include "libavutil/intreadwrite.h" + +static inline void copy_block2(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h) +{ + int i; + for(i=0; idecode_error_flags = FF_DECODE_ERROR_INVALID_BITSTREAM; + av_frame_set_decode_error_flags(frame, FF_DECODE_ERROR_INVALID_BITSTREAM); av_log(avctx, AV_LOG_WARNING, "Frame ended enexpectedly!\n"); break; } if (src[linelength - 1] != EOL) { - frame->decode_error_flags = FF_DECODE_ERROR_INVALID_BITSTREAM; + av_frame_set_decode_error_flags(frame, FF_DECODE_ERROR_INVALID_BITSTREAM); av_log(avctx, AV_LOG_WARNING, "Wrong line length %d or line not terminated properly (found 0x%02x)!\n", linelength, src[linelength - 1]); break; } @@ -140,7 +140,7 @@ static int cpia_decode_frame(AVCodecContext *avctx, */ for (j = 0; j < linelength - 1; j++) { if (y > y_end) { - frame->decode_error_flags = FF_DECODE_ERROR_INVALID_BITSTREAM; + av_frame_set_decode_error_flags(frame, FF_DECODE_ERROR_INVALID_BITSTREAM); av_log(avctx, AV_LOG_WARNING, "Decoded data exceeded linesize!\n"); break; } @@ -160,7 +160,7 @@ static int cpia_decode_frame(AVCodecContext *avctx, */ for (j = 0; j < linelength - 4; ) { if (y + 1 > y_end || u > u_end || v > v_end) { - frame->decode_error_flags = FF_DECODE_ERROR_INVALID_BITSTREAM; + av_frame_set_decode_error_flags(frame, FF_DECODE_ERROR_INVALID_BITSTREAM); av_log(avctx, AV_LOG_WARNING, "Decoded data exceeded linesize!\n"); break; } diff --git a/mythtv/external/FFmpeg/libavcodec/crystalhd.c b/mythtv/external/FFmpeg/libavcodec/crystalhd.c index 95f1fb6e8dc..e2596a29e1e 100644 --- a/mythtv/external/FFmpeg/libavcodec/crystalhd.c +++ b/mythtv/external/FFmpeg/libavcodec/crystalhd.c @@ -932,8 +932,8 @@ static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *a } else { av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: parser picture type %d\n", - h->s.picture_structure); - pic_type = h->s.picture_structure; + h->picture_structure); + pic_type = h->picture_structure; } } else { av_log(avctx, AV_LOG_WARNING, diff --git a/mythtv/external/FFmpeg/libavcodec/cscd.c b/mythtv/external/FFmpeg/libavcodec/cscd.c index e7ebb37f58a..110b06fa2ba 100644 --- a/mythtv/external/FFmpeg/libavcodec/cscd.c +++ b/mythtv/external/FFmpeg/libavcodec/cscd.c @@ -68,18 +68,19 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, int buf_size = avpkt->size; CamStudioContext *c = avctx->priv_data; AVFrame *picture = data; + int ret; if (buf_size < 2) { av_log(avctx, AV_LOG_ERROR, "coded frame too small\n"); - return -1; + return AVERROR_INVALIDDATA; } c->pic.reference = 3; c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; - if (avctx->reget_buffer(avctx, &c->pic) < 0) { + if ((ret = avctx->reget_buffer(avctx, &c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } // decompress data @@ -98,12 +99,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, break; #else av_log(avctx, AV_LOG_ERROR, "compiled without zlib support\n"); - return -1; + return AVERROR(ENOSYS); #endif } default: av_log(avctx, AV_LOG_ERROR, "unknown compression\n"); - return -1; + return AVERROR_INVALIDDATA; } // flip upside down, add difference frame diff --git a/mythtv/external/FFmpeg/libavcodec/cyuv.c b/mythtv/external/FFmpeg/libavcodec/cyuv.c index 3bc6ba4981e..b3bf4f2b09a 100644 --- a/mythtv/external/FFmpeg/libavcodec/cyuv.c +++ b/mythtv/external/FFmpeg/libavcodec/cyuv.c @@ -33,7 +33,6 @@ #include #include "avcodec.h" -#include "dsputil.h" #include "internal.h" #include "libavutil/internal.h" @@ -52,7 +51,7 @@ static av_cold int cyuv_decode_init(AVCodecContext *avctx) s->width = avctx->width; /* width needs to be divisible by 4 for this codec to work */ if (s->width & 0x3) - return -1; + return AVERROR_INVALIDDATA; s->height = avctx->height; avcodec_get_frame_defaults(&s->frame); @@ -84,6 +83,7 @@ static int cyuv_decode_frame(AVCodecContext *avctx, unsigned char cur_byte; int pixel_groups; int rawsize = s->height * FFALIGN(s->width,2) * 2; + int ret; if (avctx->codec_id == AV_CODEC_ID_AURA) { y_table = u_table; @@ -100,7 +100,7 @@ static int cyuv_decode_frame(AVCodecContext *avctx, } else { av_log(avctx, AV_LOG_ERROR, "got a buffer with %d bytes when %d were expected\n", buf_size, 48 + s->height * (s->width * 3 / 4)); - return -1; + return AVERROR_INVALIDDATA; } /* pixel data starts 48 bytes in, after 3x16-byte tables */ @@ -111,9 +111,9 @@ static int cyuv_decode_frame(AVCodecContext *avctx, s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; s->frame.reference = 0; - if (ff_get_buffer(avctx, &s->frame) < 0) { + if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } y_plane = s->frame.data[0]; diff --git a/mythtv/external/FFmpeg/libavcodec/dcadec.c b/mythtv/external/FFmpeg/libavcodec/dcadec.c index e7ae6e2d20e..1b955e4e7be 100644 --- a/mythtv/external/FFmpeg/libavcodec/dcadec.c +++ b/mythtv/external/FFmpeg/libavcodec/dcadec.c @@ -29,12 +29,11 @@ #include "libavutil/channel_layout.h" #include "libavutil/common.h" #include "libavutil/float_dsp.h" -#include "libavutil/intmath.h" +#include "libavutil/internal.h" #include "libavutil/intreadwrite.h" #include "libavutil/mathematics.h" #include "libavutil/samplefmt.h" #include "avcodec.h" -#include "dsputil.h" #include "fft.h" #include "get_bits.h" #include "put_bits.h" @@ -42,6 +41,7 @@ #include "dcahuff.h" #include "dca.h" #include "dca_parser.h" +#include "mathops.h" #include "synth_filter.h" #include "dcadsp.h" #include "fmtconvert.h" @@ -349,7 +349,6 @@ static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, typedef struct { AVCodecContext *avctx; - AVFrame frame; /* Frame header */ int frame_type; ///< type of the current frame int samples_deficit; ///< deficit sample count @@ -2067,6 +2066,7 @@ static void dca_exss_parse_header(DCAContext *s) static int dca_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int channel_mask; @@ -2354,17 +2354,17 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - s->frame.nb_samples = 256 * (s->sample_blocks / 8); - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = 256 * (s->sample_blocks / 8); + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples_flt = (float **) s->frame.extended_data; + samples_flt = (float **)frame->extended_data; /* allocate buffer for extra channels if downmixing */ if (avctx->channels < full_channels) { ret = av_samples_get_buffer_size(NULL, full_channels - channels, - s->frame.nb_samples, + frame->nb_samples, avctx->sample_fmt, 0); if (ret < 0) return ret; @@ -2377,7 +2377,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data, ret = av_samples_fill_arrays((uint8_t **)s->extra_channels, NULL, s->extra_channels_buffer, full_channels - channels, - s->frame.nb_samples, avctx->sample_fmt, 0); + frame->nb_samples, avctx->sample_fmt, 0); if (ret < 0) return ret; } @@ -2456,8 +2456,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data, for (i = 0; i < 2 * s->lfe * 4; i++) s->lfe_data[i] = s->lfe_data[i + lfe_samples]; - *got_frame_ptr = 1; - *(AVFrame *) data = s->frame; + *got_frame_ptr = 1; return buf_size; } @@ -2491,9 +2490,6 @@ static av_cold int dca_decode_init(AVCodecContext *avctx) avctx->channels = avctx->request_channels; } - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/dcaenc.c b/mythtv/external/FFmpeg/libavcodec/dcaenc.c index 7d55bb5ce91..4799ef40bd3 100644 --- a/mythtv/external/FFmpeg/libavcodec/dcaenc.c +++ b/mythtv/external/FFmpeg/libavcodec/dcaenc.c @@ -25,7 +25,6 @@ #include "libavutil/common.h" #include "libavutil/avassert.h" #include "avcodec.h" -#include "get_bits.h" #include "internal.h" #include "put_bits.h" #include "dcaenc.h" @@ -498,7 +497,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const int16_t *samples; int ret, real_channel = 0; - if ((ret = ff_alloc_packet2(avctx, avpkt, DCA_MAX_FRAME_SIZE + DCA_HEADER_SIZE))) + if ((ret = ff_alloc_packet2(avctx, avpkt, DCA_MAX_FRAME_SIZE + DCA_HEADER_SIZE)) < 0) return ret; samples = (const int16_t *)frame->data[0]; diff --git a/mythtv/external/FFmpeg/libavcodec/dct-test.c b/mythtv/external/FFmpeg/libavcodec/dct-test.c index 2c43b36aa42..29f47e8b76c 100644 --- a/mythtv/external/FFmpeg/libavcodec/dct-test.c +++ b/mythtv/external/FFmpeg/libavcodec/dct-test.c @@ -39,6 +39,7 @@ #include "libavutil/lfg.h" #include "libavutil/time.h" +#include "dct.h" #include "simple_idct.h" #include "aandcttab.h" #include "faandct.h" @@ -48,28 +49,28 @@ #undef printf -void ff_mmx_idct(DCTELEM *data); -void ff_mmxext_idct(DCTELEM *data); +void ff_mmx_idct(int16_t *data); +void ff_mmxext_idct(int16_t *data); // BFIN -void ff_bfin_idct(DCTELEM *block); -void ff_bfin_fdct(DCTELEM *block); +void ff_bfin_idct(int16_t *block); +void ff_bfin_fdct(int16_t *block); // ALTIVEC -void ff_fdct_altivec(DCTELEM *block); +void ff_fdct_altivec(int16_t *block); // ARM -void ff_j_rev_dct_arm(DCTELEM *data); -void ff_simple_idct_arm(DCTELEM *data); -void ff_simple_idct_armv5te(DCTELEM *data); -void ff_simple_idct_armv6(DCTELEM *data); -void ff_simple_idct_neon(DCTELEM *data); +void ff_j_rev_dct_arm(int16_t *data); +void ff_simple_idct_arm(int16_t *data); +void ff_simple_idct_armv5te(int16_t *data); +void ff_simple_idct_armv6(int16_t *data); +void ff_simple_idct_neon(int16_t *data); -void ff_simple_idct_axp(DCTELEM *data); +void ff_simple_idct_axp(int16_t *data); struct algo { const char *name; - void (*func)(DCTELEM *block); + void (*func)(int16_t *block); enum formattag { NO_PERM, MMX_PERM, MMX_SIMPLE_PERM, SCALE_PERM, SSE2_PERM, PARTTRANS_PERM, TRANSPOSE_PERM } format; int mm_support; @@ -103,9 +104,9 @@ static const struct algo fdct_tab[] = { #if ARCH_X86_64 && HAVE_MMX && HAVE_YASM void ff_prores_idct_put_10_sse2(uint16_t *dst, int linesize, - DCTELEM *block, int16_t *qmat); + int16_t *block, int16_t *qmat); -static void ff_prores_idct_put_10_sse2_wrap(DCTELEM *dst){ +static void ff_prores_idct_put_10_sse2_wrap(int16_t *dst){ DECLARE_ALIGNED(16, static int16_t, qmat)[64]; DECLARE_ALIGNED(16, static int16_t, tmp)[64]; int i; @@ -193,10 +194,10 @@ static void idct_mmx_init(void) } } -DECLARE_ALIGNED(16, static DCTELEM, block)[64]; -DECLARE_ALIGNED(8, static DCTELEM, block1)[64]; +DECLARE_ALIGNED(16, static int16_t, block)[64]; +DECLARE_ALIGNED(8, static int16_t, block1)[64]; -static void init_block(DCTELEM block[64], int test, int is_idct, AVLFG *prng, int vals) +static void init_block(int16_t block[64], int test, int is_idct, AVLFG *prng, int vals) { int i, j; @@ -226,7 +227,7 @@ static void init_block(DCTELEM block[64], int test, int is_idct, AVLFG *prng, in } } -static void permute(DCTELEM dst[64], const DCTELEM src[64], int perm) +static void permute(int16_t dst[64], const int16_t src[64], int perm) { int i; @@ -253,7 +254,7 @@ static void permute(DCTELEM dst[64], const DCTELEM src[64], int perm) static int dct_error(const struct algo *dct, int test, int is_idct, int speed, const int bits) { - void (*ref)(DCTELEM *block) = is_idct ? ff_ref_idct : ff_ref_fdct; + void (*ref)(int16_t *block) = is_idct ? ff_ref_idct : ff_ref_fdct; int it, i, scale; int err_inf, v; int64_t err2, ti, ti1, it1, err_sum = 0; diff --git a/mythtv/external/FFmpeg/libavcodec/dct.h b/mythtv/external/FFmpeg/libavcodec/dct.h index 8995f10a802..a500521dce9 100644 --- a/mythtv/external/FFmpeg/libavcodec/dct.h +++ b/mythtv/external/FFmpeg/libavcodec/dct.h @@ -24,6 +24,8 @@ #ifndef AVCODEC_DCT_H #define AVCODEC_DCT_H +#include + #include "rdft.h" struct DCTContext { @@ -49,4 +51,20 @@ void ff_dct_end (DCTContext *s); void ff_dct_init_x86(DCTContext *s); +void ff_fdct_ifast(int16_t *data); +void ff_fdct_ifast248(int16_t *data); +void ff_jpeg_fdct_islow_8(int16_t *data); +void ff_jpeg_fdct_islow_10(int16_t *data); +void ff_fdct248_islow_8(int16_t *data); +void ff_fdct248_islow_10(int16_t *data); + +void ff_j_rev_dct(int16_t *data); +void ff_j_rev_dct4(int16_t *data); +void ff_j_rev_dct2(int16_t *data); +void ff_j_rev_dct1(int16_t *data); + +void ff_fdct_mmx(int16_t *block); +void ff_fdct_mmxext(int16_t *block); +void ff_fdct_sse2(int16_t *block); + #endif /* AVCODEC_DCT_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/dirac_dwt.c b/mythtv/external/FFmpeg/libavcodec/dirac_dwt.c new file mode 100644 index 00000000000..a2848f01acf --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/dirac_dwt.c @@ -0,0 +1,585 @@ +/* + * Copyright (C) 2004-2010 Michael Niedermayer + * Copyright (C) 2008 David Conrad + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/attributes.h" +#include "libavutil/avassert.h" +#include "libavutil/common.h" +#include "dsputil.h" +#include "dirac_dwt.h" +#include "libavcodec/x86/dirac_dwt.h" + + +static inline int mirror(int v, int m) +{ + while ((unsigned)v > (unsigned)m) { + v = -v; + if (v < 0) + v += 2 * m; + } + return v; +} + +static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, + int width) +{ + int i; + + for (i = 0; i < width; i++) + b1[i] -= (b0[i] + b2[i] + 2) >> 2; +} + + +static av_always_inline +void interleave(IDWTELEM *dst, IDWTELEM *src0, IDWTELEM *src1, int w2, int add, int shift) +{ + int i; + for (i = 0; i < w2; i++) { + dst[2*i ] = (src0[i] + add) >> shift; + dst[2*i+1] = (src1[i] + add) >> shift; + } +} + +static void horizontal_compose_dirac53i(IDWTELEM *b, IDWTELEM *temp, int w) +{ + const int w2 = w >> 1; + int x; + + temp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]); + for (x = 1; x < w2; x++) { + temp[x ] = COMPOSE_53iL0 (b[x+w2-1], b[x ], b[x+w2]); + temp[x+w2-1] = COMPOSE_DIRAC53iH0(temp[x-1], b[x+w2-1], temp[x]); + } + temp[w-1] = COMPOSE_DIRAC53iH0(temp[w2-1], b[w-1], temp[w2-1]); + + interleave(b, temp, temp+w2, w2, 1, 1); +} + +static void horizontal_compose_dd97i(IDWTELEM *b, IDWTELEM *tmp, int w) +{ + const int w2 = w >> 1; + int x; + + tmp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]); + for (x = 1; x < w2; x++) + tmp[x] = COMPOSE_53iL0(b[x+w2-1], b[x], b[x+w2]); + + // extend the edges + tmp[-1] = tmp[0]; + tmp[w2+1] = tmp[w2] = tmp[w2-1]; + + for (x = 0; x < w2; x++) { + b[2*x ] = (tmp[x] + 1)>>1; + b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1; + } +} + +static void horizontal_compose_dd137i(IDWTELEM *b, IDWTELEM *tmp, int w) +{ + const int w2 = w >> 1; + int x; + + tmp[0] = COMPOSE_DD137iL0(b[w2], b[w2], b[0], b[w2 ], b[w2+1]); + tmp[1] = COMPOSE_DD137iL0(b[w2], b[w2], b[1], b[w2+1], b[w2+2]); + for (x = 2; x < w2-1; x++) + tmp[x] = COMPOSE_DD137iL0(b[x+w2-2], b[x+w2-1], b[x], b[x+w2], b[x+w2+1]); + tmp[w2-1] = COMPOSE_DD137iL0(b[w-3], b[w-2], b[w2-1], b[w-1], b[w-1]); + + // extend the edges + tmp[-1] = tmp[0]; + tmp[w2+1] = tmp[w2] = tmp[w2-1]; + + for (x = 0; x < w2; x++) { + b[2*x ] = (tmp[x] + 1)>>1; + b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1; + } +} + +static av_always_inline +void horizontal_compose_haari(IDWTELEM *b, IDWTELEM *temp, int w, int shift) +{ + const int w2 = w >> 1; + int x; + + for (x = 0; x < w2; x++) { + temp[x ] = COMPOSE_HAARiL0(b[x ], b[x+w2]); + temp[x+w2] = COMPOSE_HAARiH0(b[x+w2], temp[x]); + } + + interleave(b, temp, temp+w2, w2, shift, shift); +} + +static void horizontal_compose_haar0i(IDWTELEM *b, IDWTELEM *temp, int w) +{ + horizontal_compose_haari(b, temp, w, 0); +} + +static void horizontal_compose_haar1i(IDWTELEM *b, IDWTELEM *temp, int w) +{ + horizontal_compose_haari(b, temp, w, 1); +} + +static void horizontal_compose_fidelityi(IDWTELEM *b, IDWTELEM *tmp, int w) +{ + const int w2 = w >> 1; + int i, x; + IDWTELEM v[8]; + + for (x = 0; x < w2; x++) { + for (i = 0; i < 8; i++) + v[i] = b[av_clip(x-3+i, 0, w2-1)]; + tmp[x] = COMPOSE_FIDELITYiH0(v[0], v[1], v[2], v[3], b[x+w2], v[4], v[5], v[6], v[7]); + } + + for (x = 0; x < w2; x++) { + for (i = 0; i < 8; i++) + v[i] = tmp[av_clip(x-4+i, 0, w2-1)]; + tmp[x+w2] = COMPOSE_FIDELITYiL0(v[0], v[1], v[2], v[3], b[x], v[4], v[5], v[6], v[7]); + } + + interleave(b, tmp+w2, tmp, w2, 0, 0); +} + +static void horizontal_compose_daub97i(IDWTELEM *b, IDWTELEM *temp, int w) +{ + const int w2 = w >> 1; + int x, b0, b1, b2; + + temp[0] = COMPOSE_DAUB97iL1(b[w2], b[0], b[w2]); + for (x = 1; x < w2; x++) { + temp[x ] = COMPOSE_DAUB97iL1(b[x+w2-1], b[x ], b[x+w2]); + temp[x+w2-1] = COMPOSE_DAUB97iH1(temp[x-1], b[x+w2-1], temp[x]); + } + temp[w-1] = COMPOSE_DAUB97iH1(temp[w2-1], b[w-1], temp[w2-1]); + + // second stage combined with interleave and shift + b0 = b2 = COMPOSE_DAUB97iL0(temp[w2], temp[0], temp[w2]); + b[0] = (b0 + 1) >> 1; + for (x = 1; x < w2; x++) { + b2 = COMPOSE_DAUB97iL0(temp[x+w2-1], temp[x ], temp[x+w2]); + b1 = COMPOSE_DAUB97iH0( b0, temp[x+w2-1], b2 ); + b[2*x-1] = (b1 + 1) >> 1; + b[2*x ] = (b2 + 1) >> 1; + b0 = b2; + } + b[w-1] = (COMPOSE_DAUB97iH0(b2, temp[w-1], b2) + 1) >> 1; +} + +static void vertical_compose_dirac53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width) +{ + int i; + + for(i=0; ivertical_compose_l0; + vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0; + DWTCompose *cs = d->cs + level; + + int i, y = cs->y; + IDWTELEM *b[8]; + for (i = 0; i < 6; i++) + b[i] = cs->b[i]; + b[6] = d->buffer + av_clip(y+5, 0, height-2)*stride; + b[7] = d->buffer + av_clip(y+6, 1, height-1)*stride; + + if(y+5<(unsigned)height) vertical_compose_l0( b[5], b[6], b[7], width); + if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width); + + if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width); + if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width); + + for (i = 0; i < 6; i++) + cs->b[i] = b[i+2]; + cs->y += 2; +} + +static void spatial_compose_dirac53i_dy(DWTContext *d, int level, int width, int height, int stride) +{ + vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0; + vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0; + DWTCompose *cs = d->cs + level; + + int y= cs->y; + IDWTELEM *b[4] = { cs->b[0], cs->b[1] }; + b[2] = d->buffer + mirror(y+1, height-1)*stride; + b[3] = d->buffer + mirror(y+2, height-1)*stride; + + if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width); + if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width); + + if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width); + if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width); + + cs->b[0] = b[2]; + cs->b[1] = b[3]; + cs->y += 2; +} + + +static void spatial_compose_dd137i_dy(DWTContext *d, int level, int width, int height, int stride) +{ + vertical_compose_5tap vertical_compose_l0 = (void*)d->vertical_compose_l0; + vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0; + DWTCompose *cs = d->cs + level; + + int i, y = cs->y; + IDWTELEM *b[10]; + for (i = 0; i < 8; i++) + b[i] = cs->b[i]; + b[8] = d->buffer + av_clip(y+7, 0, height-2)*stride; + b[9] = d->buffer + av_clip(y+8, 1, height-1)*stride; + + if(y+5<(unsigned)height) vertical_compose_l0(b[3], b[5], b[6], b[7], b[9], width); + if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width); + + if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width); + if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width); + + for (i = 0; i < 8; i++) + cs->b[i] = b[i+2]; + cs->y += 2; +} + +// haar makes the assumption that height is even (always true for dirac) +static void spatial_compose_haari_dy(DWTContext *d, int level, int width, int height, int stride) +{ + vertical_compose_2tap vertical_compose = (void*)d->vertical_compose; + int y = d->cs[level].y; + IDWTELEM *b0 = d->buffer + (y-1)*stride; + IDWTELEM *b1 = d->buffer + (y )*stride; + + vertical_compose(b0, b1, width); + d->horizontal_compose(b0, d->temp, width); + d->horizontal_compose(b1, d->temp, width); + + d->cs[level].y += 2; +} + +// Don't do sliced idwt for fidelity; the 9 tap filter makes it a bit annoying +// Fortunately, this filter isn't used in practice. +static void spatial_compose_fidelity(DWTContext *d, int level, int width, int height, int stride) +{ + vertical_compose_9tap vertical_compose_l0 = (void*)d->vertical_compose_l0; + vertical_compose_9tap vertical_compose_h0 = (void*)d->vertical_compose_h0; + int i, y; + IDWTELEM *b[8]; + + for (y = 1; y < height; y += 2) { + for (i = 0; i < 8; i++) + b[i] = d->buffer + av_clip((y-7 + 2*i), 0, height-2)*stride; + vertical_compose_h0(d->buffer + y*stride, b, width); + } + + for (y = 0; y < height; y += 2) { + for (i = 0; i < 8; i++) + b[i] = d->buffer + av_clip((y-7 + 2*i), 1, height-1)*stride; + vertical_compose_l0(d->buffer + y*stride, b, width); + } + + for (y = 0; y < height; y++) + d->horizontal_compose(d->buffer + y*stride, d->temp, width); + + d->cs[level].y = height+1; +} + +static void spatial_compose_daub97i_dy(DWTContext *d, int level, int width, int height, int stride) +{ + vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0; + vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0; + vertical_compose_3tap vertical_compose_l1 = (void*)d->vertical_compose_l1; + vertical_compose_3tap vertical_compose_h1 = (void*)d->vertical_compose_h1; + DWTCompose *cs = d->cs + level; + + int i, y = cs->y; + IDWTELEM *b[6]; + for (i = 0; i < 4; i++) + b[i] = cs->b[i]; + b[4] = d->buffer + mirror(y+3, height-1)*stride; + b[5] = d->buffer + mirror(y+4, height-1)*stride; + + if(y+3<(unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width); + if(y+2<(unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width); + if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width); + if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width); + + if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width); + if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width); + + for (i = 0; i < 4; i++) + cs->b[i] = b[i+2]; + cs->y += 2; +} + + +static void spatial_compose97i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride) +{ + cs->b[0] = buffer + mirror(-3-1, height-1)*stride; + cs->b[1] = buffer + mirror(-3 , height-1)*stride; + cs->b[2] = buffer + mirror(-3+1, height-1)*stride; + cs->b[3] = buffer + mirror(-3+2, height-1)*stride; + cs->y = -3; +} + +static void spatial_compose53i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride) +{ + cs->b[0] = buffer + mirror(-1-1, height-1)*stride; + cs->b[1] = buffer + mirror(-1 , height-1)*stride; + cs->y = -1; +} + +static void spatial_compose_dd97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride) +{ + cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride; + cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride; + cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride; + cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride; + cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride; + cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride; + cs->y = -5; +} + +static void spatial_compose_dd137i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride) +{ + cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride; + cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride; + cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride; + cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride; + cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride; + cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride; + cs->b[6] = buffer + av_clip(-5+5, 0, height-2)*stride; + cs->b[7] = buffer + av_clip(-5+6, 1, height-1)*stride; + cs->y = -5; +} + +int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height, + int stride, enum dwt_type type, int decomposition_count, + IDWTELEM *temp) +{ + int level; + + d->buffer = buffer; + d->width = width; + d->height = height; + d->stride = stride; + d->decomposition_count = decomposition_count; + d->temp = temp + 8; + + for(level=decomposition_count-1; level>=0; level--){ + int hl = height >> level; + int stride_l = stride << level; + + switch(type){ + case DWT_DIRAC_DD9_7: + spatial_compose_dd97i_init(d->cs+level, buffer, hl, stride_l); + break; + case DWT_DIRAC_LEGALL5_3: + spatial_compose53i_init2(d->cs+level, buffer, hl, stride_l); + break; + case DWT_DIRAC_DD13_7: + spatial_compose_dd137i_init(d->cs+level, buffer, hl, stride_l); + break; + case DWT_DIRAC_HAAR0: + case DWT_DIRAC_HAAR1: + d->cs[level].y = 1; + break; + case DWT_DIRAC_DAUB9_7: + spatial_compose97i_init2(d->cs+level, buffer, hl, stride_l); + break; + default: + d->cs[level].y = 0; + break; + } + } + + switch (type) { + case DWT_DIRAC_DD9_7: + d->spatial_compose = spatial_compose_dd97i_dy; + d->vertical_compose_l0 = (void*)vertical_compose53iL0; + d->vertical_compose_h0 = (void*)vertical_compose_dd97iH0; + d->horizontal_compose = horizontal_compose_dd97i; + d->support = 7; + break; + case DWT_DIRAC_LEGALL5_3: + d->spatial_compose = spatial_compose_dirac53i_dy; + d->vertical_compose_l0 = (void*)vertical_compose53iL0; + d->vertical_compose_h0 = (void*)vertical_compose_dirac53iH0; + d->horizontal_compose = horizontal_compose_dirac53i; + d->support = 3; + break; + case DWT_DIRAC_DD13_7: + d->spatial_compose = spatial_compose_dd137i_dy; + d->vertical_compose_l0 = (void*)vertical_compose_dd137iL0; + d->vertical_compose_h0 = (void*)vertical_compose_dd97iH0; + d->horizontal_compose = horizontal_compose_dd137i; + d->support = 7; + break; + case DWT_DIRAC_HAAR0: + case DWT_DIRAC_HAAR1: + d->spatial_compose = spatial_compose_haari_dy; + d->vertical_compose = (void*)vertical_compose_haar; + if (type == DWT_DIRAC_HAAR0) + d->horizontal_compose = horizontal_compose_haar0i; + else + d->horizontal_compose = horizontal_compose_haar1i; + d->support = 1; + break; + case DWT_DIRAC_FIDELITY: + d->spatial_compose = spatial_compose_fidelity; + d->vertical_compose_l0 = (void*)vertical_compose_fidelityiL0; + d->vertical_compose_h0 = (void*)vertical_compose_fidelityiH0; + d->horizontal_compose = horizontal_compose_fidelityi; + break; + case DWT_DIRAC_DAUB9_7: + d->spatial_compose = spatial_compose_daub97i_dy; + d->vertical_compose_l0 = (void*)vertical_compose_daub97iL0; + d->vertical_compose_h0 = (void*)vertical_compose_daub97iH0; + d->vertical_compose_l1 = (void*)vertical_compose_daub97iL1; + d->vertical_compose_h1 = (void*)vertical_compose_daub97iH1; + d->horizontal_compose = horizontal_compose_daub97i; + d->support = 5; + break; + default: + av_log(NULL, AV_LOG_ERROR, "Unknown wavelet type %d\n", type); + return -1; + } + + if (HAVE_MMX) ff_spatial_idwt_init_mmx(d, type); + + return 0; +} + +void ff_spatial_idwt_slice2(DWTContext *d, int y) +{ + int level, support = d->support; + + for (level = d->decomposition_count-1; level >= 0; level--) { + int wl = d->width >> level; + int hl = d->height >> level; + int stride_l = d->stride << level; + + while (d->cs[level].y <= FFMIN((y>>level)+support, hl)) + d->spatial_compose(d, level, wl, hl, stride_l); + } +} + +int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride, + enum dwt_type type, int decomposition_count, IDWTELEM *temp) +{ + DWTContext d; + int y; + + if (ff_spatial_idwt_init2(&d, buffer, width, height, stride, type, decomposition_count, temp)) + return -1; + + for (y = 0; y < d.height; y += 4) + ff_spatial_idwt_slice2(&d, y); + + return 0; +} diff --git a/mythtv/external/FFmpeg/libavcodec/dirac_dwt.h b/mythtv/external/FFmpeg/libavcodec/dirac_dwt.h new file mode 100644 index 00000000000..9514e9575bd --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/dirac_dwt.h @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2004-2010 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_DIRAC_DWT_H +#define AVCODEC_DIRAC_DWT_H + +#include + +typedef int DWTELEM; +typedef short IDWTELEM; + +#define MAX_DWT_SUPPORT 8 +#define MAX_DECOMPOSITIONS 8 + +typedef struct DWTCompose { + IDWTELEM *b[MAX_DWT_SUPPORT]; + int y; +} DWTCompose; + +struct DWTContext; + +// Possible prototypes for vertical_compose functions +typedef void (*vertical_compose_2tap)(IDWTELEM *b0, IDWTELEM *b1, int width); +typedef void (*vertical_compose_3tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width); +typedef void (*vertical_compose_5tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, int width); +typedef void (*vertical_compose_9tap)(IDWTELEM *dst, IDWTELEM *b[8], int width); + +typedef struct DWTContext { + IDWTELEM *buffer; + IDWTELEM *temp; + int width; + int height; + int stride; + int decomposition_count; + int support; + + void (*spatial_compose)(struct DWTContext *cs, int level, int width, int height, int stride); + void (*vertical_compose_l0)(void); + void (*vertical_compose_h0)(void); + void (*vertical_compose_l1)(void); + void (*vertical_compose_h1)(void); + void (*vertical_compose)(void); ///< one set of lowpass and highpass combined + void (*horizontal_compose)(IDWTELEM *b, IDWTELEM *tmp, int width); + + DWTCompose cs[MAX_DECOMPOSITIONS]; +} DWTContext; + +enum dwt_type { + DWT_SNOW_DAUB9_7, + DWT_SNOW_LEGALL5_3, + DWT_DIRAC_DD9_7, + DWT_DIRAC_LEGALL5_3, + DWT_DIRAC_DD13_7, + DWT_DIRAC_HAAR0, + DWT_DIRAC_HAAR1, + DWT_DIRAC_FIDELITY, + DWT_DIRAC_DAUB9_7, + DWT_NUM_TYPES +}; + +// -1 if an error occurred, e.g. the dwt_type isn't recognized +int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height, + int stride, enum dwt_type type, int decomposition_count, + IDWTELEM *temp); + +int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride, + enum dwt_type type, int decomposition_count, IDWTELEM *temp); + +void ff_spatial_idwt_slice2(DWTContext *d, int y); + +// shared stuff for simd optimiztions +#define COMPOSE_53iL0(b0, b1, b2)\ + (b1 - ((b0 + b2 + 2) >> 2)) + +#define COMPOSE_DIRAC53iH0(b0, b1, b2)\ + (b1 + ((b0 + b2 + 1) >> 1)) + +#define COMPOSE_DD97iH0(b0, b1, b2, b3, b4)\ + (b2 + ((-b0 + 9*b1 + 9*b3 - b4 + 8) >> 4)) + +#define COMPOSE_DD137iL0(b0, b1, b2, b3, b4)\ + (b2 - ((-b0 + 9*b1 + 9*b3 - b4 + 16) >> 5)) + +#define COMPOSE_HAARiL0(b0, b1)\ + (b0 - ((b1 + 1) >> 1)) + +#define COMPOSE_HAARiH0(b0, b1)\ + (b0 + b1) + +#define COMPOSE_FIDELITYiL0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\ + (b4 - ((-8*(b0+b8) + 21*(b1+b7) - 46*(b2+b6) + 161*(b3+b5) + 128) >> 8)) + +#define COMPOSE_FIDELITYiH0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\ + (b4 + ((-2*(b0+b8) + 10*(b1+b7) - 25*(b2+b6) + 81*(b3+b5) + 128) >> 8)) + +#define COMPOSE_DAUB97iL1(b0, b1, b2)\ + (b1 - ((1817*(b0 + b2) + 2048) >> 12)) + +#define COMPOSE_DAUB97iH1(b0, b1, b2)\ + (b1 - (( 113*(b0 + b2) + 64) >> 7)) + +#define COMPOSE_DAUB97iL0(b0, b1, b2)\ + (b1 + (( 217*(b0 + b2) + 2048) >> 12)) + +#define COMPOSE_DAUB97iH0(b0, b1, b2)\ + (b1 + ((6497*(b0 + b2) + 2048) >> 12)) + + +#endif /* AVCODEC_DWT_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/diracdec.c b/mythtv/external/FFmpeg/libavcodec/diracdec.c index c431b97019f..a791e8835a7 100644 --- a/mythtv/external/FFmpeg/libavcodec/diracdec.c +++ b/mythtv/external/FFmpeg/libavcodec/diracdec.c @@ -34,9 +34,10 @@ #include "golomb.h" #include "dirac_arith.h" #include "mpeg12data.h" -#include "dwt.h" +#include "dirac_dwt.h" #include "dirac.h" #include "diracdsp.h" +#include "videodsp.h" // for ff_emulated_edge_mc_8 /** * The spec limits the number of wavelet decompositions to 4 for both diff --git a/mythtv/external/FFmpeg/libavcodec/dnxhddata.c b/mythtv/external/FFmpeg/libavcodec/dnxhddata.c index c433d9d13e2..669b8067e99 100644 --- a/mythtv/external/FFmpeg/libavcodec/dnxhddata.c +++ b/mythtv/external/FFmpeg/libavcodec/dnxhddata.c @@ -952,70 +952,80 @@ const CIDEntry ff_dnxhd_cid_table[] = { dnxhd_1235_1241_ac_codes, dnxhd_1235_1241_ac_bits, dnxhd_1235_1241_ac_level, dnxhd_1235_1241_ac_flags, dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1235_1241_run, - { 175, 185, 365, 440 } }, + { 175, 185, 365, 440 }, + { { 24000, 1001 }, { 25, 1 }, { 50, 1 }, { 60000, 1001 } } }, { 1237, 1920, 1080, 0, 606208, 606208, 4, 8, 3, dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight, dnxhd_1237_dc_codes, dnxhd_1237_dc_bits, dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_level, dnxhd_1237_ac_flags, dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run, - { 115, 120, 145, 240, 290 } }, + { 115, 120, 145, 240, 290 }, + { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } }, { 1238, 1920, 1080, 0, 917504, 917504, 4, 8, 4, dnxhd_1238_luma_weight, dnxhd_1238_chroma_weight, dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, dnxhd_1238_ac_flags, dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1238_run, - { 175, 185, 220, 365, 440 } }, + { 175, 185, 220, 365, 440 }, + { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } }, { 1241, 1920, 1080, 1, 917504, 458752, 6, 10, 4, dnxhd_1241_luma_weight, dnxhd_1241_chroma_weight, dnxhd_1235_1241_dc_codes, dnxhd_1235_1241_dc_bits, dnxhd_1235_1241_ac_codes, dnxhd_1235_1241_ac_bits, dnxhd_1235_1241_ac_level, dnxhd_1235_1241_ac_flags, dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1235_1241_run, - { 185, 220 } }, + { 185, 220 }, + { { 25, 1 }, { 30000, 1001 } } }, { 1242, 1920, 1080, 1, 606208, 303104, 4, 8, 3, dnxhd_1242_luma_weight, dnxhd_1242_chroma_weight, dnxhd_1237_dc_codes, dnxhd_1237_dc_bits, dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_level, dnxhd_1237_ac_flags, dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run, - { 120, 145 } }, + { 120, 145 }, + { { 25, 1 }, { 30000, 1001 } } }, { 1243, 1920, 1080, 1, 917504, 458752, 4, 8, 4, dnxhd_1243_luma_weight, dnxhd_1243_chroma_weight, dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, dnxhd_1238_ac_flags, dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1238_run, - { 185, 220 } }, + { 185, 220 }, + { { 25, 1 }, { 30000, 1001 } } }, { 1250, 1280, 720, 0, 458752, 458752, 6, 10, 4, dnxhd_1250_luma_weight, dnxhd_1250_chroma_weight, dnxhd_1250_dc_codes, dnxhd_1250_dc_bits, dnxhd_1250_ac_codes, dnxhd_1250_ac_bits, dnxhd_1250_ac_level, dnxhd_1250_ac_flags, dnxhd_1250_run_codes, dnxhd_1250_run_bits, dnxhd_1250_run, - { 90, 180, 220 } }, + { 90, 90, 180, 220 }, + { { 24000, 1001 }, { 25, 1 }, { 50, 1 }, { 60000, 1001 } } }, { 1251, 1280, 720, 0, 458752, 458752, 4, 8, 4, dnxhd_1251_luma_weight, dnxhd_1251_chroma_weight, dnxhd_1251_dc_codes, dnxhd_1251_dc_bits, dnxhd_1251_ac_codes, dnxhd_1251_ac_bits, dnxhd_1251_ac_level, dnxhd_1251_ac_flags, dnxhd_1251_run_codes, dnxhd_1251_run_bits, dnxhd_1251_run, - { 90, 110, 175, 220 } }, + { 90, 90, 110, 180, 220 }, + { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } }, { 1252, 1280, 720, 0, 303104, 303104, 4, 8, 5, dnxhd_1252_luma_weight, dnxhd_1252_chroma_weight, dnxhd_1252_dc_codes, dnxhd_1252_dc_bits, dnxhd_1252_ac_codes, dnxhd_1252_ac_bits, dnxhd_1252_ac_level, dnxhd_1252_ac_flags, dnxhd_1251_run_codes, dnxhd_1251_run_bits, dnxhd_1251_run, - { 60, 75, 115, 145 } }, + { 60, 60, 75, 120, 145 }, + { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } }, { 1253, 1920, 1080, 0, 188416, 188416, 4, 8, 3, dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight, dnxhd_1237_dc_codes, dnxhd_1237_dc_bits, dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_level, dnxhd_1237_ac_flags, dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run, - { 36, 45, 75, 90 } }, + { 36, 36, 45, 75, 90 }, + { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } }, }; int ff_dnxhd_get_cid_table(int cid) @@ -1054,3 +1064,19 @@ int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth) } return 0; } + +void ff_dnxhd_print_profiles(AVCodecContext *avctx, int loglevel) +{ + int i, j; + for (i = 0; i < FF_ARRAY_ELEMS(ff_dnxhd_cid_table); i++) { + const CIDEntry *cid = &ff_dnxhd_cid_table[i]; + for (j = 0; j < FF_ARRAY_ELEMS(cid->bit_rates); j++) { + if (!cid->bit_rates[j]) + break; + + av_log(avctx, loglevel, "Frame size: %dx%d%c; bitrate: %dMbps; pixel format: %s; framerate: %d/%d\n", + cid->width, cid->height, cid->interlaced ? 'i' : 'p', cid->bit_rates[j], + cid->bit_depth == 10 ? "yuv422p10" : "yuv422p", cid->frame_rates[j].num, cid->frame_rates[j].den); + } + } +} diff --git a/mythtv/external/FFmpeg/libavcodec/dnxhddata.h b/mythtv/external/FFmpeg/libavcodec/dnxhddata.h index f1a6ec7a8ff..b8bcb21d8ea 100644 --- a/mythtv/external/FFmpeg/libavcodec/dnxhddata.h +++ b/mythtv/external/FFmpeg/libavcodec/dnxhddata.h @@ -43,12 +43,14 @@ typedef struct CIDEntry { const uint16_t *run_codes; const uint8_t *run_bits, *run; int bit_rates[5]; ///< Helpher to choose variants, rounded to nearest 5Mb/s + AVRational frame_rates[5]; } CIDEntry; extern av_export const CIDEntry ff_dnxhd_cid_table[]; int ff_dnxhd_get_cid_table(int cid); int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth); +void ff_dnxhd_print_profiles(AVCodecContext *avctx, int loglevel); int avpriv_dnxhd_get_frame_size(int cid); diff --git a/mythtv/external/FFmpeg/libavcodec/dnxhddec.c b/mythtv/external/FFmpeg/libavcodec/dnxhddec.c index 104b94354c8..429d9a518a8 100644 --- a/mythtv/external/FFmpeg/libavcodec/dnxhddec.c +++ b/mythtv/external/FFmpeg/libavcodec/dnxhddec.c @@ -45,11 +45,11 @@ typedef struct DNXHDContext { VLC ac_vlc, dc_vlc, run_vlc; int last_dc[3]; DSPContext dsp; - DECLARE_ALIGNED(16, DCTELEM, blocks)[8][64]; + DECLARE_ALIGNED(16, int16_t, blocks)[8][64]; ScanTable scantable; const CIDEntry *cid_table; int bit_depth; // 8, 10 or 0 if not initialized at all. - void (*decode_dct_block)(struct DNXHDContext *ctx, DCTELEM *block, + void (*decode_dct_block)(struct DNXHDContext *ctx, int16_t *block, int n, int qscale); int last_qscale; int luma_scale[64]; @@ -59,8 +59,8 @@ typedef struct DNXHDContext { #define DNXHD_VLC_BITS 9 #define DNXHD_DC_VLC_BITS 7 -static void dnxhd_decode_dct_block_8(DNXHDContext *ctx, DCTELEM *block, int n, int qscale); -static void dnxhd_decode_dct_block_10(DNXHDContext *ctx, DCTELEM *block, int n, int qscale); +static void dnxhd_decode_dct_block_8(DNXHDContext *ctx, int16_t *block, int n, int qscale); +static void dnxhd_decode_dct_block_10(DNXHDContext *ctx, int16_t *block, int n, int qscale); static av_cold int dnxhd_decode_init(AVCodecContext *avctx) { @@ -180,7 +180,7 @@ static int dnxhd_decode_header(DNXHDContext *ctx, const uint8_t *buf, int buf_si for (i = 0; i < ctx->mb_height; i++) { ctx->mb_scan_index[i] = AV_RB32(buf + 0x170 + (i<<2)); av_dlog(ctx->avctx, "mb scan index %d\n", ctx->mb_scan_index[i]); - if (buf_size < ctx->mb_scan_index[i] + 0x280) { + if (buf_size < ctx->mb_scan_index[i] + 0x280LL) { av_log(ctx->avctx, AV_LOG_ERROR, "invalid mb scan index\n"); return -1; } @@ -190,7 +190,7 @@ static int dnxhd_decode_header(DNXHDContext *ctx, const uint8_t *buf, int buf_si } static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx, - DCTELEM *block, int n, + int16_t *block, int n, int qscale, int index_bits, int level_bias, @@ -272,13 +272,13 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx, CLOSE_READER(bs, &ctx->gb); } -static void dnxhd_decode_dct_block_8(DNXHDContext *ctx, DCTELEM *block, +static void dnxhd_decode_dct_block_8(DNXHDContext *ctx, int16_t *block, int n, int qscale) { dnxhd_decode_dct_block(ctx, block, n, qscale, 4, 32, 6); } -static void dnxhd_decode_dct_block_10(DNXHDContext *ctx, DCTELEM *block, +static void dnxhd_decode_dct_block_10(DNXHDContext *ctx, int16_t *block, int n, int qscale) { dnxhd_decode_dct_block(ctx, block, n, qscale, 6, 8, 4); diff --git a/mythtv/external/FFmpeg/libavcodec/dnxhdenc.c b/mythtv/external/FFmpeg/libavcodec/dnxhdenc.c index 0d1a396d18e..4b6ce2f60b9 100644 --- a/mythtv/external/FFmpeg/libavcodec/dnxhdenc.c +++ b/mythtv/external/FFmpeg/libavcodec/dnxhdenc.c @@ -26,6 +26,7 @@ //#define DEBUG #define RC_VARIANCE 1 // use variance or ssd for fast rc +#include "libavutil/internal.h" #include "libavutil/opt.h" #include "avcodec.h" #include "dsputil.h" @@ -51,7 +52,7 @@ static const AVClass class = { #define LAMBDA_FRAC_BITS 10 -static void dnxhd_8bit_get_pixels_8x4_sym(DCTELEM *av_restrict block, const uint8_t *pixels, int line_size) +static void dnxhd_8bit_get_pixels_8x4_sym(int16_t *av_restrict block, const uint8_t *pixels, int line_size) { int i; for (i = 0; i < 4; i++) { @@ -68,7 +69,7 @@ static void dnxhd_8bit_get_pixels_8x4_sym(DCTELEM *av_restrict block, const uint memcpy(block + 24, block - 32, sizeof(*block) * 8); } -static av_always_inline void dnxhd_10bit_get_pixels_8x4_sym(DCTELEM *av_restrict block, const uint8_t *pixels, int line_size) +static av_always_inline void dnxhd_10bit_get_pixels_8x4_sym(int16_t *av_restrict block, const uint8_t *pixels, int line_size) { int i; const uint16_t* pixels16 = (const uint16_t*)pixels; @@ -88,7 +89,7 @@ static av_always_inline void dnxhd_10bit_get_pixels_8x4_sym(DCTELEM *av_restrict memcpy(block + 24, block - 32, sizeof(*block) * 8); } -static int dnxhd_10bit_dct_quantize(MpegEncContext *ctx, DCTELEM *block, +static int dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int16_t *block, int n, int qscale, int *overflow) { const uint8_t *scantable= ctx->intra_scantable.scantable; @@ -266,7 +267,8 @@ static int dnxhd_encode_init(AVCodecContext *avctx) ctx->cid = ff_dnxhd_find_cid(avctx, bit_depth); if (!ctx->cid) { - av_log(avctx, AV_LOG_ERROR, "video parameters incompatible with DNxHD\n"); + av_log(avctx, AV_LOG_ERROR, "video parameters incompatible with DNxHD. Valid DNxHD profiles:\n"); + ff_dnxhd_print_profiles(avctx, AV_LOG_ERROR); return -1; } av_log(avctx, AV_LOG_DEBUG, "cid %d\n", ctx->cid); @@ -392,7 +394,7 @@ static av_always_inline void dnxhd_encode_dc(DNXHDEncContext *ctx, int diff) (ctx->cid_table->dc_codes[nbits]<m.pb, ctx->vlc_bits[0], ctx->vlc_codes[0]); // EOB } -static av_always_inline void dnxhd_unquantize_c(DNXHDEncContext *ctx, DCTELEM *block, int n, int qscale, int last_index) +static av_always_inline void dnxhd_unquantize_c(DNXHDEncContext *ctx, int16_t *block, int n, int qscale, int last_index) { const uint8_t *weight_matrix; int level; @@ -456,7 +458,7 @@ static av_always_inline void dnxhd_unquantize_c(DNXHDEncContext *ctx, DCTELEM *b } } -static av_always_inline int dnxhd_ssd_block(DCTELEM *qblock, DCTELEM *block) +static av_always_inline int dnxhd_ssd_block(int16_t *qblock, int16_t *block) { int score = 0; int i; @@ -465,7 +467,7 @@ static av_always_inline int dnxhd_ssd_block(DCTELEM *qblock, DCTELEM *block) return score; } -static av_always_inline int dnxhd_calc_ac_bits(DNXHDEncContext *ctx, DCTELEM *block, int last_index) +static av_always_inline int dnxhd_calc_ac_bits(DNXHDEncContext *ctx, int16_t *block, int last_index) { int last_non_zero = 0; int bits = 0; @@ -527,7 +529,7 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, int jobnr, i DNXHDEncContext *ctx = avctx->priv_data; int mb_y = jobnr, mb_x; int qscale = ctx->qscale; - LOCAL_ALIGNED_16(DCTELEM, block, [64]); + LOCAL_ALIGNED_16(int16_t, block, [64]); ctx = ctx->thread[threadnr]; ctx->m.last_dc[0] = @@ -544,7 +546,7 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, int jobnr, i dnxhd_get_blocks(ctx, mb_x, mb_y); for (i = 0; i < 8; i++) { - DCTELEM *src_block = ctx->blocks[i]; + int16_t *src_block = ctx->blocks[i]; int overflow, nbits, diff, last_index; int n = dnxhd_switch_matrix(ctx, i); @@ -593,7 +595,7 @@ static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg, int jobnr, int dnxhd_get_blocks(ctx, mb_x, mb_y); for (i = 0; i < 8; i++) { - DCTELEM *block = ctx->blocks[i]; + int16_t *block = ctx->blocks[i]; int overflow, n = dnxhd_switch_matrix(ctx, i); int last_index = ctx->m.dct_quantize(&ctx->m, block, 4&(2*i), qscale, &overflow); //START_TIMER; diff --git a/mythtv/external/FFmpeg/libavcodec/dnxhdenc.h b/mythtv/external/FFmpeg/libavcodec/dnxhdenc.h index 36a42fb1001..9b59b96d3e4 100644 --- a/mythtv/external/FFmpeg/libavcodec/dnxhdenc.h +++ b/mythtv/external/FFmpeg/libavcodec/dnxhdenc.h @@ -64,7 +64,7 @@ typedef struct DNXHDEncContext { int nitris_compat; unsigned min_padding; - DECLARE_ALIGNED(16, DCTELEM, blocks)[8][64]; + DECLARE_ALIGNED(16, int16_t, blocks)[8][64]; int (*qmatrix_c) [64]; int (*qmatrix_l) [64]; @@ -90,7 +90,7 @@ typedef struct DNXHDEncContext { RCCMPEntry *mb_cmp; RCEntry (*mb_rc)[8160]; - void (*get_pixels_8x4_sym)(DCTELEM * /*align 16*/, const uint8_t *, int); + void (*get_pixels_8x4_sym)(int16_t * /*align 16*/, const uint8_t *, int); } DNXHDEncContext; void ff_dnxhdenc_init_x86(DNXHDEncContext *ctx); diff --git a/mythtv/external/FFmpeg/libavcodec/dpcm.c b/mythtv/external/FFmpeg/libavcodec/dpcm.c index 5fa9778ff69..1ec837066d3 100644 --- a/mythtv/external/FFmpeg/libavcodec/dpcm.c +++ b/mythtv/external/FFmpeg/libavcodec/dpcm.c @@ -44,7 +44,6 @@ #include "mathops.h" typedef struct DPCMContext { - AVFrame frame; int16_t roq_square_array[256]; int sample[2]; ///< previous sample (for SOL_DPCM) const int8_t *sol_table; ///< delta table for SOL_DPCM @@ -163,9 +162,6 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx) else avctx->sample_fmt = AV_SAMPLE_FMT_S16; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -175,6 +171,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, { int buf_size = avpkt->size; DPCMContext *s = avctx->priv_data; + AVFrame *frame = data; int out = 0, ret; int predictor[2]; int ch = 0; @@ -213,12 +210,12 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - s->frame.nb_samples = (out + avctx->channels - 1) / avctx->channels; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = (out + avctx->channels - 1) / avctx->channels; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - output_samples = (int16_t *)s->frame.data[0]; + output_samples = (int16_t *)frame->data[0]; samples_end = output_samples + out; switch(avctx->codec->id) { @@ -298,7 +295,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, } case AV_CODEC_ID_SOL_DPCM: if (avctx->codec_tag != 3) { - uint8_t *output_samples_u8 = s->frame.data[0], + uint8_t *output_samples_u8 = frame->data[0], *samples_end_u8 = output_samples_u8 + out; while (output_samples_u8 < samples_end_u8) { int n = bytestream2_get_byteu(&gb); @@ -325,8 +322,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, break; } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return avpkt->size; } diff --git a/mythtv/external/FFmpeg/libavcodec/dpx.c b/mythtv/external/FFmpeg/libavcodec/dpx.c index a9a8c16d6c3..310036b0cd0 100644 --- a/mythtv/external/FFmpeg/libavcodec/dpx.c +++ b/mythtv/external/FFmpeg/libavcodec/dpx.c @@ -71,7 +71,7 @@ static int decode_frame(AVCodecContext *avctx, unsigned int offset; int magic_num, endian; - int x, y, i; + int x, y, i, ret; int w, h, bits_per_color, descriptor, elements, packing, total_size; unsigned int rgbBuffer = 0; @@ -93,7 +93,7 @@ static int decode_frame(AVCodecContext *avctx, endian = 1; } else { av_log(avctx, AV_LOG_ERROR, "DPX marker not found\n"); - return -1; + return AVERROR_INVALIDDATA; } offset = read32(&buf, endian); @@ -105,8 +105,8 @@ static int decode_frame(AVCodecContext *avctx, buf = avpkt->data + 0x304; w = read32(&buf, endian); h = read32(&buf, endian); - if (av_image_check_size(w, h, 0, avctx)) - return AVERROR(EINVAL); + if ((ret = av_image_check_size(w, h, 0, avctx)) < 0) + return ret; if (w != avctx->width || h != avctx->height) avcodec_set_dimensions(avctx, w, h); @@ -141,7 +141,7 @@ static int decode_frame(AVCodecContext *avctx, break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported descriptor %d\n", descriptor); - return -1; + return AVERROR_INVALIDDATA; } switch (bits_per_color) { @@ -159,7 +159,7 @@ static int decode_frame(AVCodecContext *avctx, return -1; } avctx->pix_fmt = AV_PIX_FMT_GBRP10; - total_size = (4 * avctx->width * avctx->height * elements) / 3; + total_size = (avctx->width * avctx->height * elements + 2) / 3 * 4; break; case 12: if (!packing) { @@ -183,14 +183,14 @@ static int decode_frame(AVCodecContext *avctx, break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported color depth : %d\n", bits_per_color); - return -1; + return AVERROR_INVALIDDATA; } if (s->picture.data[0]) avctx->release_buffer(avctx, &s->picture); - if (ff_get_buffer(avctx, p) < 0) { + if ((ret = ff_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } // Move pointer to offset from start of file @@ -199,9 +199,9 @@ static int decode_frame(AVCodecContext *avctx, for (i=0; idata[i]; - if (total_size > avpkt->size) { + if (total_size + (int64_t)offset > avpkt->size) { av_log(avctx, AV_LOG_ERROR, "Overread buffer. Invalid header?\n"); - return -1; + return AVERROR_INVALIDDATA; } switch (bits_per_color) { case 10: diff --git a/mythtv/external/FFmpeg/libavcodec/dsicinav.c b/mythtv/external/FFmpeg/libavcodec/dsicinav.c index 76d4d1fc4d4..85eafcfcca4 100644 --- a/mythtv/external/FFmpeg/libavcodec/dsicinav.c +++ b/mythtv/external/FFmpeg/libavcodec/dsicinav.c @@ -46,7 +46,6 @@ typedef struct CinVideoContext { } CinVideoContext; typedef struct CinAudioContext { - AVFrame frame; int initial_decode_frame; int delta; } CinAudioContext; @@ -349,15 +348,13 @@ static av_cold int cinaudio_decode_init(AVCodecContext *avctx) avctx->channels = 1; avctx->channel_layout = AV_CH_LAYOUT_MONO; - avcodec_get_frame_defaults(&cin->frame); - avctx->coded_frame = &cin->frame; - return 0; } static int cinaudio_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; CinAudioContext *cin = avctx->priv_data; const uint8_t *buf_end = buf + avpkt->size; @@ -365,12 +362,12 @@ static int cinaudio_decode_frame(AVCodecContext *avctx, void *data, int delta, ret; /* get output buffer */ - cin->frame.nb_samples = avpkt->size - cin->initial_decode_frame; - if ((ret = ff_get_buffer(avctx, &cin->frame)) < 0) { + frame->nb_samples = avpkt->size - cin->initial_decode_frame; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (int16_t *)cin->frame.data[0]; + samples = (int16_t *)frame->data[0]; delta = cin->delta; if (cin->initial_decode_frame) { @@ -386,8 +383,7 @@ static int cinaudio_decode_frame(AVCodecContext *avctx, void *data, } cin->delta = delta; - *got_frame_ptr = 1; - *(AVFrame *)data = cin->frame; + *got_frame_ptr = 1; return avpkt->size; } diff --git a/mythtv/external/FFmpeg/libavcodec/dsputil.c b/mythtv/external/FFmpeg/libavcodec/dsputil.c index 7314215387d..12cfb1b2162 100644 --- a/mythtv/external/FFmpeg/libavcodec/dsputil.c +++ b/mythtv/external/FFmpeg/libavcodec/dsputil.c @@ -28,21 +28,22 @@ */ #include "libavutil/imgutils.h" +#include "libavutil/internal.h" #include "avcodec.h" +#include "copy_block.h" +#include "dct.h" #include "dsputil.h" #include "simple_idct.h" #include "faandct.h" #include "faanidct.h" +#include "imgconvert.h" #include "mathops.h" #include "mpegvideo.h" #include "config.h" -#include "vorbis.h" #include "diracdsp.h" -uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, }; uint32_t ff_squareTbl[512] = {0, }; -#define pixeltmp int16_t #define BIT_DEPTH 9 #include "dsputil_template.c" #undef BIT_DEPTH @@ -51,8 +52,6 @@ uint32_t ff_squareTbl[512] = {0, }; #include "dsputil_template.c" #undef BIT_DEPTH -#undef pixeltmp -#define pixeltmp int32_t #define BIT_DEPTH 12 #include "dsputil_template.c" #undef BIT_DEPTH @@ -61,27 +60,13 @@ uint32_t ff_squareTbl[512] = {0, }; #include "dsputil_template.c" #undef BIT_DEPTH -#undef pixeltmp -#define pixeltmp int16_t #define BIT_DEPTH 8 #include "dsputil_template.c" -#undef pixeltmp // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size #define pb_7f (~0UL/255 * 0x7f) #define pb_80 (~0UL/255 * 0x80) -const uint8_t ff_zigzag_direct[64] = { - 0, 1, 8, 16, 9, 2, 3, 10, - 17, 24, 32, 25, 18, 11, 4, 5, - 12, 19, 26, 33, 40, 48, 41, 34, - 27, 20, 13, 6, 7, 14, 21, 28, - 35, 42, 49, 56, 57, 50, 43, 36, - 29, 22, 15, 23, 30, 37, 44, 51, - 58, 59, 52, 45, 38, 31, 39, 46, - 53, 60, 61, 54, 47, 55, 62, 63 -}; - /* Specific zigzag scan for 248 idct. NOTE that unlike the specification, we interleave the fields */ const uint8_t ff_zigzag248_direct[64] = { @@ -352,7 +337,7 @@ static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) return s; } -static void diff_pixels_c(DCTELEM *av_restrict block, const uint8_t *s1, +static void diff_pixels_c(int16_t *av_restrict block, const uint8_t *s1, const uint8_t *s2, int stride){ int i; @@ -372,8 +357,7 @@ static void diff_pixels_c(DCTELEM *av_restrict block, const uint8_t *s1, } } - -static void put_pixels_clamped_c(const DCTELEM *block, uint8_t *av_restrict pixels, +static void put_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels, int line_size) { int i; @@ -394,7 +378,7 @@ static void put_pixels_clamped_c(const DCTELEM *block, uint8_t *av_restrict pixe } } -static void put_pixels_clamped4_c(const DCTELEM *block, uint8_t *av_restrict pixels, +static void put_pixels_clamped4_c(const int16_t *block, uint8_t *av_restrict pixels, int line_size) { int i; @@ -411,7 +395,7 @@ static void put_pixels_clamped4_c(const DCTELEM *block, uint8_t *av_restrict pix } } -static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *av_restrict pixels, +static void put_pixels_clamped2_c(const int16_t *block, uint8_t *av_restrict pixels, int line_size) { int i; @@ -426,7 +410,7 @@ static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *av_restrict pix } } -static void put_signed_pixels_clamped_c(const DCTELEM *block, +static void put_signed_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels, int line_size) { @@ -447,7 +431,27 @@ static void put_signed_pixels_clamped_c(const DCTELEM *block, } } -static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *av_restrict pixels, +static void add_pixels8_c(uint8_t *av_restrict pixels, + int16_t *block, + int line_size) +{ + int i; + + for(i=0;i<8;i++) { + pixels[0] += block[0]; + pixels[1] += block[1]; + pixels[2] += block[2]; + pixels[3] += block[3]; + pixels[4] += block[4]; + pixels[5] += block[5]; + pixels[6] += block[6]; + pixels[7] += block[7]; + pixels += line_size; + block += 8; + } +} + +static void add_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels, int line_size) { int i; @@ -467,7 +471,7 @@ static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *av_restrict pixe } } -static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *av_restrict pixels, +static void add_pixels_clamped4_c(const int16_t *block, uint8_t *av_restrict pixels, int line_size) { int i; @@ -483,7 +487,7 @@ static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *av_restrict pix } } -static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *av_restrict pixels, +static void add_pixels_clamped2_c(const int16_t *block, uint8_t *av_restrict pixels, int line_size) { int i; @@ -497,7 +501,7 @@ static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *av_restrict pix } } -static int sum_abs_dctelem_c(DCTELEM *block) +static int sum_abs_dctelem_c(int16_t *block) { int sum=0, i; for(i=0; i<64; i++) @@ -1827,35 +1831,6 @@ static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){ } } -/** - * Permute an 8x8 block. - * @param block the block which will be permuted according to the given permutation vector - * @param permutation the permutation vector - * @param last the last non zero coefficient in scantable order, used to speed the permutation up - * @param scantable the used scantable, this is only used to speed the permutation up, the block is not - * (inverse) permutated to scantable order! - */ -void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last) -{ - int i; - DCTELEM temp[64]; - - if(last<=0) return; - //if(permutation[1]==1) return; //FIXME it is ok but not clean and might fail for some permutations - - for(i=0; i<=last; i++){ - const int j= scantable[i]; - temp[j]= block[j]; - block[j]=0; - } - - for(i=0; i<=last; i++){ - const int j= scantable[i]; - const int perm_j= permutation[j]; - block[perm_j]= temp[j]; - } -} - static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){ return 0; } @@ -2161,7 +2136,7 @@ static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_ static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ MpegEncContext * const s= (MpegEncContext *)c; - LOCAL_ALIGNED_16(DCTELEM, temp, [64]); + LOCAL_ALIGNED_16(int16_t, temp, [64]); av_assert2(h==8); @@ -2200,7 +2175,7 @@ static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2 static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ MpegEncContext * const s= (MpegEncContext *)c; - DCTELEM dct[8][8]; + int16_t dct[8][8]; int i; int sum=0; @@ -2225,7 +2200,7 @@ static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *s static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ MpegEncContext * const s= (MpegEncContext *)c; - LOCAL_ALIGNED_16(DCTELEM, temp, [64]); + LOCAL_ALIGNED_16(int16_t, temp, [64]); int sum=0, i; av_assert2(h==8); @@ -2241,8 +2216,8 @@ static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2 static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ MpegEncContext * const s= (MpegEncContext *)c; - LOCAL_ALIGNED_16(DCTELEM, temp, [64*2]); - DCTELEM * const bak = temp+64; + LOCAL_ALIGNED_16(int16_t, temp, [64*2]); + int16_t * const bak = temp+64; int sum=0, i; av_assert2(h==8); @@ -2250,7 +2225,7 @@ static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *s s->dsp.diff_pixels(temp, src1, src2, stride); - memcpy(bak, temp, 64*sizeof(DCTELEM)); + memcpy(bak, temp, 64*sizeof(int16_t)); s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i); s->dct_unquantize_inter(s, temp, 0, s->qscale); @@ -2265,7 +2240,7 @@ static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *s static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ MpegEncContext * const s= (MpegEncContext *)c; const uint8_t *scantable= s->intra_scantable.permutated; - LOCAL_ALIGNED_16(DCTELEM, temp, [64]); + LOCAL_ALIGNED_16(int16_t, temp, [64]); LOCAL_ALIGNED_16(uint8_t, lsrc1, [64]); LOCAL_ALIGNED_16(uint8_t, lsrc2, [64]); int i, last, run, bits, level, distortion, start_i; @@ -2341,7 +2316,7 @@ static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ MpegEncContext * const s= (MpegEncContext *)c; const uint8_t *scantable= s->intra_scantable.permutated; - LOCAL_ALIGNED_16(DCTELEM, temp, [64]); + LOCAL_ALIGNED_16(int16_t, temp, [64]); int i, last, run, bits, level, start_i; const int esc_length= s->ac_esc_length; uint8_t * length; @@ -2473,6 +2448,20 @@ static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2, return score; } +#define WRAPPER8_16_SQ(name8, name16)\ +static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\ + int score=0;\ + score +=name8(s, dst , src , stride, 8);\ + score +=name8(s, dst+8 , src+8 , stride, 8);\ + if(h==16){\ + dst += 8*stride;\ + src += 8*stride;\ + score +=name8(s, dst , src , stride, 8);\ + score +=name8(s, dst+8 , src+8 , stride, 8);\ + }\ + return score;\ +} + WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c) WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c) WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c) @@ -2484,70 +2473,6 @@ WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c) WRAPPER8_16_SQ(rd8x8_c, rd16_c) WRAPPER8_16_SQ(bit8x8_c, bit16_c) -static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){ - int i; - src1 += len-1; - for(i=0; i 0); } -#define W0 2048 -#define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */ -#define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */ -#define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */ -#define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */ -#define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */ -#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */ -#define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */ - -static void wmv2_idct_row(short * b) -{ - int s1,s2; - int a0,a1,a2,a3,a4,a5,a6,a7; - /*step 1*/ - a1 = W1*b[1]+W7*b[7]; - a7 = W7*b[1]-W1*b[7]; - a5 = W5*b[5]+W3*b[3]; - a3 = W3*b[5]-W5*b[3]; - a2 = W2*b[2]+W6*b[6]; - a6 = W6*b[2]-W2*b[6]; - a0 = W0*b[0]+W0*b[4]; - a4 = W0*b[0]-W0*b[4]; - /*step 2*/ - s1 = (181*(a1-a5+a7-a3)+128)>>8;//1,3,5,7, - s2 = (181*(a1-a5-a7+a3)+128)>>8; - /*step 3*/ - b[0] = (a0+a2+a1+a5 + (1<<7))>>8; - b[1] = (a4+a6 +s1 + (1<<7))>>8; - b[2] = (a4-a6 +s2 + (1<<7))>>8; - b[3] = (a0-a2+a7+a3 + (1<<7))>>8; - b[4] = (a0-a2-a7-a3 + (1<<7))>>8; - b[5] = (a4-a6 -s2 + (1<<7))>>8; - b[6] = (a4+a6 -s1 + (1<<7))>>8; - b[7] = (a0+a2-a1-a5 + (1<<7))>>8; -} -static void wmv2_idct_col(short * b) -{ - int s1,s2; - int a0,a1,a2,a3,a4,a5,a6,a7; - /*step 1, with extended precision*/ - a1 = (W1*b[8*1]+W7*b[8*7] + 4)>>3; - a7 = (W7*b[8*1]-W1*b[8*7] + 4)>>3; - a5 = (W5*b[8*5]+W3*b[8*3] + 4)>>3; - a3 = (W3*b[8*5]-W5*b[8*3] + 4)>>3; - a2 = (W2*b[8*2]+W6*b[8*6] + 4)>>3; - a6 = (W6*b[8*2]-W2*b[8*6] + 4)>>3; - a0 = (W0*b[8*0]+W0*b[8*4] )>>3; - a4 = (W0*b[8*0]-W0*b[8*4] )>>3; - /*step 2*/ - s1 = (181*(a1-a5+a7-a3)+128)>>8; - s2 = (181*(a1-a5-a7+a3)+128)>>8; - /*step 3*/ - b[8*0] = (a0+a2+a1+a5 + (1<<13))>>14; - b[8*1] = (a4+a6 +s1 + (1<<13))>>14; - b[8*2] = (a4-a6 +s2 + (1<<13))>>14; - b[8*3] = (a0-a2+a7+a3 + (1<<13))>>14; - - b[8*4] = (a0-a2-a7-a3 + (1<<13))>>14; - b[8*5] = (a4-a6 -s2 + (1<<13))>>14; - b[8*6] = (a4+a6 -s1 + (1<<13))>>14; - b[8*7] = (a0+a2-a1-a5 + (1<<13))>>14; -} -void ff_wmv2_idct_c(short * block){ - int i; - - for(i=0;i<64;i+=8){ - wmv2_idct_row(block+i); - } - for(i=0;i<8;i++){ - wmv2_idct_col(block+i); - } -} -/* XXX: those functions should be suppressed ASAP when all IDCTs are - converted */ -static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block) -{ - ff_wmv2_idct_c(block); - put_pixels_clamped_c(block, dest, line_size); -} -static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block) -{ - ff_wmv2_idct_c(block); - add_pixels_clamped_c(block, dest, line_size); -} -static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block) +static void ff_jref_idct_put(uint8_t *dest, int line_size, int16_t *block) { ff_j_rev_dct (block); put_pixels_clamped_c(block, dest, line_size); } -static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block) +static void ff_jref_idct_add(uint8_t *dest, int line_size, int16_t *block) { ff_j_rev_dct (block); add_pixels_clamped_c(block, dest, line_size); } -static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block) +static void ff_jref_idct4_put(uint8_t *dest, int line_size, int16_t *block) { ff_j_rev_dct4 (block); put_pixels_clamped4_c(block, dest, line_size); } -static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block) +static void ff_jref_idct4_add(uint8_t *dest, int line_size, int16_t *block) { ff_j_rev_dct4 (block); add_pixels_clamped4_c(block, dest, line_size); } -static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block) +static void ff_jref_idct2_put(uint8_t *dest, int line_size, int16_t *block) { ff_j_rev_dct2 (block); put_pixels_clamped2_c(block, dest, line_size); } -static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block) +static void ff_jref_idct2_add(uint8_t *dest, int line_size, int16_t *block) { ff_j_rev_dct2 (block); add_pixels_clamped2_c(block, dest, line_size); } -static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block) +static void ff_jref_idct1_put(uint8_t *dest, int line_size, int16_t *block) { dest[0] = av_clip_uint8((block[0] + 4)>>3); } -static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block) +static void ff_jref_idct1_add(uint8_t *dest, int line_size, int16_t *block) { dest[0] = av_clip_uint8(dest[0] + ((block[0] + 4)>>3)); } @@ -2773,12 +2614,6 @@ av_cold void ff_dsputil_static_init(void) { int i; - for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i; - for(i=0;iidct_add= ff_jref_idct_add; c->idct = ff_j_rev_dct; c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM; - }else if(avctx->idct_algo==FF_IDCT_WMV2){ - c->idct_put= ff_wmv2_idct_put_c; - c->idct_add= ff_wmv2_idct_add_c; - c->idct = ff_wmv2_idct_c; - c->idct_permutation_type= FF_NO_IDCT_PERM; }else if(avctx->idct_algo==FF_IDCT_FAAN){ c->idct_put= ff_faanidct_put; c->idct_add= ff_faanidct_add; @@ -2990,7 +2818,7 @@ av_cold void ff_dsputil_init(DSPContext* c, AVCodecContext *avctx) c->vsse[5]= vsse_intra8_c; c->nsse[0]= nsse16_c; c->nsse[1]= nsse8_c; -#if CONFIG_DWT +#if CONFIG_SNOW_DECODER || CONFIG_SNOW_ENCODER ff_dsputil_init_dwt(c); #endif @@ -3015,96 +2843,47 @@ av_cold void ff_dsputil_init(DSPContext* c, AVCodecContext *avctx) c->try_8x8basis= try_8x8basis_c; c->add_8x8basis= add_8x8basis_c; -#if CONFIG_VORBIS_DECODER - c->vorbis_inverse_coupling = ff_vorbis_inverse_coupling; -#endif - c->vector_fmul_reverse = vector_fmul_reverse_c; - c->vector_fmul_add = vector_fmul_add_c; - c->vector_fmul_window = vector_fmul_window_c; c->vector_clipf = vector_clipf_c; c->scalarproduct_int16 = scalarproduct_int16_c; c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c; c->apply_window_int16 = apply_window_int16_c; c->vector_clip_int32 = vector_clip_int32_c; - c->scalarproduct_float = ff_scalarproduct_float_c; - c->butterflies_float = butterflies_float_c; - c->butterflies_float_interleave = butterflies_float_interleave_c; c->shrink[0]= av_image_copy_plane; c->shrink[1]= ff_shrink22; c->shrink[2]= ff_shrink44; c->shrink[3]= ff_shrink88; - memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab)); - memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab)); + c->add_pixels8 = add_pixels8_c; + +#define hpel_funcs(prefix, idx, num) \ + c->prefix ## _pixels_tab idx [0] = prefix ## _pixels ## num ## _8_c; \ + c->prefix ## _pixels_tab idx [1] = prefix ## _pixels ## num ## _x2_8_c; \ + c->prefix ## _pixels_tab idx [2] = prefix ## _pixels ## num ## _y2_8_c; \ + c->prefix ## _pixels_tab idx [3] = prefix ## _pixels ## num ## _xy2_8_c + + hpel_funcs(put, [0], 16); + hpel_funcs(put, [1], 8); + hpel_funcs(put, [2], 4); + hpel_funcs(put, [3], 2); + hpel_funcs(put_no_rnd, [0], 16); + hpel_funcs(put_no_rnd, [1], 8); + hpel_funcs(avg, [0], 16); + hpel_funcs(avg, [1], 8); + hpel_funcs(avg, [2], 4); + hpel_funcs(avg, [3], 2); + hpel_funcs(avg_no_rnd,, 16); #undef FUNC #undef FUNCC #define FUNC(f, depth) f ## _ ## depth #define FUNCC(f, depth) f ## _ ## depth ## _c -#define dspfunc1(PFX, IDX, NUM, depth)\ - c->PFX ## _pixels_tab[IDX][0] = FUNCC(PFX ## _pixels ## NUM , depth);\ - c->PFX ## _pixels_tab[IDX][1] = FUNCC(PFX ## _pixels ## NUM ## _x2 , depth);\ - c->PFX ## _pixels_tab[IDX][2] = FUNCC(PFX ## _pixels ## NUM ## _y2 , depth);\ - c->PFX ## _pixels_tab[IDX][3] = FUNCC(PFX ## _pixels ## NUM ## _xy2, depth) - -#define dspfunc2(PFX, IDX, NUM, depth)\ - c->PFX ## _pixels_tab[IDX][ 0] = FUNCC(PFX ## NUM ## _mc00, depth);\ - c->PFX ## _pixels_tab[IDX][ 1] = FUNCC(PFX ## NUM ## _mc10, depth);\ - c->PFX ## _pixels_tab[IDX][ 2] = FUNCC(PFX ## NUM ## _mc20, depth);\ - c->PFX ## _pixels_tab[IDX][ 3] = FUNCC(PFX ## NUM ## _mc30, depth);\ - c->PFX ## _pixels_tab[IDX][ 4] = FUNCC(PFX ## NUM ## _mc01, depth);\ - c->PFX ## _pixels_tab[IDX][ 5] = FUNCC(PFX ## NUM ## _mc11, depth);\ - c->PFX ## _pixels_tab[IDX][ 6] = FUNCC(PFX ## NUM ## _mc21, depth);\ - c->PFX ## _pixels_tab[IDX][ 7] = FUNCC(PFX ## NUM ## _mc31, depth);\ - c->PFX ## _pixels_tab[IDX][ 8] = FUNCC(PFX ## NUM ## _mc02, depth);\ - c->PFX ## _pixels_tab[IDX][ 9] = FUNCC(PFX ## NUM ## _mc12, depth);\ - c->PFX ## _pixels_tab[IDX][10] = FUNCC(PFX ## NUM ## _mc22, depth);\ - c->PFX ## _pixels_tab[IDX][11] = FUNCC(PFX ## NUM ## _mc32, depth);\ - c->PFX ## _pixels_tab[IDX][12] = FUNCC(PFX ## NUM ## _mc03, depth);\ - c->PFX ## _pixels_tab[IDX][13] = FUNCC(PFX ## NUM ## _mc13, depth);\ - c->PFX ## _pixels_tab[IDX][14] = FUNCC(PFX ## NUM ## _mc23, depth);\ - c->PFX ## _pixels_tab[IDX][15] = FUNCC(PFX ## NUM ## _mc33, depth) - - #define BIT_DEPTH_FUNCS(depth, dct)\ c->get_pixels = FUNCC(get_pixels ## dct , depth);\ c->draw_edges = FUNCC(draw_edges , depth);\ c->clear_block = FUNCC(clear_block ## dct , depth);\ c->clear_blocks = FUNCC(clear_blocks ## dct , depth);\ - c->add_pixels8 = FUNCC(add_pixels8 ## dct , depth);\ - c->add_pixels4 = FUNCC(add_pixels4 ## dct , depth);\ - c->put_no_rnd_pixels_l2[0] = FUNCC(put_no_rnd_pixels16_l2, depth);\ - c->put_no_rnd_pixels_l2[1] = FUNCC(put_no_rnd_pixels8_l2 , depth);\ -\ - c->put_h264_chroma_pixels_tab[0] = FUNCC(put_h264_chroma_mc8 , depth);\ - c->put_h264_chroma_pixels_tab[1] = FUNCC(put_h264_chroma_mc4 , depth);\ - c->put_h264_chroma_pixels_tab[2] = FUNCC(put_h264_chroma_mc2 , depth);\ - c->avg_h264_chroma_pixels_tab[0] = FUNCC(avg_h264_chroma_mc8 , depth);\ - c->avg_h264_chroma_pixels_tab[1] = FUNCC(avg_h264_chroma_mc4 , depth);\ - c->avg_h264_chroma_pixels_tab[2] = FUNCC(avg_h264_chroma_mc2 , depth);\ -\ - dspfunc1(put , 0, 16, depth);\ - dspfunc1(put , 1, 8, depth);\ - dspfunc1(put , 2, 4, depth);\ - dspfunc1(put , 3, 2, depth);\ - dspfunc1(put_no_rnd, 0, 16, depth);\ - dspfunc1(put_no_rnd, 1, 8, depth);\ - dspfunc1(avg , 0, 16, depth);\ - dspfunc1(avg , 1, 8, depth);\ - dspfunc1(avg , 2, 4, depth);\ - dspfunc1(avg , 3, 2, depth);\ - dspfunc1(avg_no_rnd, 0, 16, depth);\ - dspfunc1(avg_no_rnd, 1, 8, depth);\ -\ - dspfunc2(put_h264_qpel, 0, 16, depth);\ - dspfunc2(put_h264_qpel, 1, 8, depth);\ - dspfunc2(put_h264_qpel, 2, 4, depth);\ - dspfunc2(put_h264_qpel, 3, 2, depth);\ - dspfunc2(avg_h264_qpel, 0, 16, depth);\ - dspfunc2(avg_h264_qpel, 1, 8, depth);\ - dspfunc2(avg_h264_qpel, 2, 4, depth); switch (avctx->bits_per_raw_sample) { case 9: @@ -3150,18 +2929,6 @@ av_cold void ff_dsputil_init(DSPContext* c, AVCodecContext *avctx) if (ARCH_PPC) ff_dsputil_init_ppc (c, avctx); if (ARCH_SH4) ff_dsputil_init_sh4 (c, avctx); if (ARCH_BFIN) ff_dsputil_init_bfin (c, avctx); - if (HAVE_MIPSFPU) ff_dsputil_init_mips (c, avctx); - - for (i = 0; i < 4; i++) { - for (j = 0; j < 16; j++) { - if(!c->put_2tap_qpel_pixels_tab[i][j]) - c->put_2tap_qpel_pixels_tab[i][j] = - c->put_h264_qpel_pixels_tab[i][j]; - if(!c->avg_2tap_qpel_pixels_tab[i][j]) - c->avg_2tap_qpel_pixels_tab[i][j] = - c->avg_h264_qpel_pixels_tab[i][j]; - } - } ff_init_scantable_permutation(c->idct_permutation, c->idct_permutation_type); diff --git a/mythtv/external/FFmpeg/libavcodec/dsputil.h b/mythtv/external/FFmpeg/libavcodec/dsputil.h index c6726d3ff73..454be389587 100644 --- a/mythtv/external/FFmpeg/libavcodec/dsputil.h +++ b/mythtv/external/FFmpeg/libavcodec/dsputil.h @@ -35,48 +35,6 @@ //#define DEBUG -/* dct code */ -typedef short DCTELEM; - -void ff_fdct_ifast (DCTELEM *data); -void ff_fdct_ifast248 (DCTELEM *data); -void ff_jpeg_fdct_islow_8(DCTELEM *data); -void ff_jpeg_fdct_islow_10(DCTELEM *data); -void ff_fdct248_islow_8(DCTELEM *data); -void ff_fdct248_islow_10(DCTELEM *data); - -void ff_j_rev_dct (DCTELEM *data); -void ff_j_rev_dct4 (DCTELEM *data); -void ff_j_rev_dct2 (DCTELEM *data); -void ff_j_rev_dct1 (DCTELEM *data); -void ff_wmv2_idct_c(DCTELEM *data); - -void ff_fdct_mmx(DCTELEM *block); -void ff_fdct_mmxext(DCTELEM *block); -void ff_fdct_sse2(DCTELEM *block); - -#define H264_IDCT(depth) \ -void ff_h264_idct8_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\ -void ff_h264_idct_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\ -void ff_h264_idct8_dc_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\ -void ff_h264_idct_dc_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\ -void ff_h264_idct_add16_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ -void ff_h264_idct_add16intra_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ -void ff_h264_idct8_add4_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ -void ff_h264_idct_add8_422_ ## depth ## _c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ -void ff_h264_idct_add8_ ## depth ## _c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ -void ff_h264_luma_dc_dequant_idct_ ## depth ## _c(DCTELEM *output, DCTELEM *input, int qmul);\ -void ff_h264_chroma422_dc_dequant_idct_ ## depth ## _c(DCTELEM *block, int qmul);\ -void ff_h264_chroma_dc_dequant_idct_ ## depth ## _c(DCTELEM *block, int qmul); - -H264_IDCT( 8) -H264_IDCT( 9) -H264_IDCT(10) -H264_IDCT(12) -H264_IDCT(14) - -void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qp); -void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc); /* encoding scans */ extern const uint8_t ff_alternate_horizontal_scan[64]; @@ -89,7 +47,7 @@ extern const uint8_t ff_zigzag248_direct[64]; /* temporary */ extern uint32_t ff_squareTbl[512]; -extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP]; +extern const uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP]; #define PUTAVG_PIXELS(depth)\ void ff_put_pixels8x8_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\ @@ -114,11 +72,6 @@ void ff_avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride); void ff_put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride); void ff_avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride); -/* 1/2^n downscaling functions from imgconvert.c */ -void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); -void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); -void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); - void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy, int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height); @@ -135,21 +88,12 @@ could be reached easily ... !future video codecs might need functions with less strict alignment */ -/* -void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size); -void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride); -void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size); -void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size); -void clear_blocks_c(DCTELEM *blocks); -*/ - /* add and put pixel (decoding) */ // blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16 //h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller than 4 -typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h); +typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, ptrdiff_t line_size, int h); typedef void (*tpel_mc_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int w, int h); typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride); -typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y); typedef void (*op_fill_func)(uint8_t *block/*align width (8 or 16)*/, uint8_t value, int line_size, int h); @@ -172,7 +116,7 @@ DEF_OLD_QPEL(qpel8_mc13_old_c) DEF_OLD_QPEL(qpel8_mc33_old_c) #define CALL_2X_PIXELS(a, b, n)\ -static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ +static void a(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){\ b(block , pixels , line_size, h);\ b(block+n, pixels+n, line_size, h);\ } @@ -195,14 +139,6 @@ void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable); void ff_init_scantable_permutation(uint8_t *idct_permutation, int idct_permutation_type); -#define EMULATED_EDGE(depth) \ -void ff_emulated_edge_mc_ ## depth (uint8_t *buf, const uint8_t *src, ptrdiff_t linesize,\ - int block_w, int block_h,\ - int src_x, int src_y, int w, int h); - -EMULATED_EDGE(8) -EMULATED_EDGE(16) - /** * DSPContext. */ @@ -213,14 +149,13 @@ typedef struct DSPContext { int dct_bits; /* pixel ops : interface with DCT */ - void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size); - void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride); - void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); - void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); - void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); - void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size); - void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size); - int (*sum_abs_dctelem)(DCTELEM *block/*align 16*/); + void (*get_pixels)(int16_t *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size); + void (*diff_pixels)(int16_t *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride); + void (*put_pixels_clamped)(const int16_t *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); + void (*put_signed_pixels_clamped)(const int16_t *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); + void (*add_pixels_clamped)(const int16_t *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); + void (*add_pixels8)(uint8_t *pixels, int16_t *block, int line_size); + int (*sum_abs_dctelem)(int16_t *block/*align 16*/); /** * translational global motion compensation. */ @@ -230,8 +165,8 @@ typedef struct DSPContext { */ void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy, int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height); - void (*clear_block)(DCTELEM *block/*align 16*/); - void (*clear_blocks)(DCTELEM *blocks/*align 16*/); + void (*clear_block)(int16_t *block/*align 16*/); + void (*clear_blocks)(int16_t *blocks/*align 16*/); int (*pix_sum)(uint8_t * pix, int line_size); int (*pix_norm1)(uint8_t * pix, int line_size); // 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4 @@ -299,17 +234,15 @@ typedef struct DSPContext { /** * Halfpel motion compensation with no rounding (a+b)>>1. - * this is an array[2][4] of motion compensation functions for 2 - * horizontal blocksizes (8,16) and the 4 halfpel positions
- * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] + * this is an array[4] of motion compensation functions for 1 + * horizontal blocksize (16) and the 4 halfpel positions
+ * *pixels_tab[0][ xhalfpel + 2*yhalfpel ] * @param block destination into which the result is averaged (a+b)>>1 * @param pixels source * @param line_size number of bytes in a horizontal line of block * @param h height */ - op_pixels_func avg_no_rnd_pixels_tab[4][4]; - - void (*put_no_rnd_pixels_l2[2])(uint8_t *block/*align width (8 or 16)*/, const uint8_t *a/*align 1*/, const uint8_t *b/*align 1*/, int line_size, int h); + op_pixels_func avg_no_rnd_pixels_tab[4]; /** * Thirdpel motion compensation with rounding (a+b+1)>>1. @@ -327,21 +260,8 @@ typedef struct DSPContext { qpel_mc_func put_qpel_pixels_tab[2][16]; qpel_mc_func avg_qpel_pixels_tab[2][16]; qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16]; - qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16]; qpel_mc_func put_mspel_pixels_tab[8]; - /** - * h264 Chroma MC - */ - h264_chroma_mc_func put_h264_chroma_pixels_tab[3]; - h264_chroma_mc_func avg_h264_chroma_pixels_tab[3]; - - qpel_mc_func put_h264_qpel_pixels_tab[4][16]; - qpel_mc_func avg_h264_qpel_pixels_tab[4][16]; - - qpel_mc_func put_2tap_qpel_pixels_tab[4][16]; - qpel_mc_func avg_2tap_qpel_pixels_tab[4][16]; - me_cmp_func pix_abs[2][4]; /* huffyuv specific */ @@ -364,67 +284,28 @@ typedef struct DSPContext { void (*h261_loop_filter)(uint8_t *src, int stride); - /* assume len is a multiple of 4, and arrays are 16-byte aligned */ - void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize); - /* assume len is a multiple of 16, and arrays are 32-byte aligned */ - void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len); - /* assume len is a multiple of 8, and src arrays are 16-byte aligned */ - void (*vector_fmul_add)(float *dst, const float *src0, const float *src1, const float *src2, int len); - /* assume len is a multiple of 4, and arrays are 16-byte aligned */ - void (*vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len); /* assume len is a multiple of 8, and arrays are 16-byte aligned */ void (*vector_clipf)(float *dst /* align 16 */, const float *src /* align 16 */, float min, float max, int len /* align 16 */); - /** - * Calculate the scalar product of two vectors of floats. - * @param v1 first vector, 16-byte aligned - * @param v2 second vector, 16-byte aligned - * @param len length of vectors, multiple of 4 - */ - float (*scalarproduct_float)(const float *v1, const float *v2, int len); - /** - * Calculate the sum and difference of two vectors of floats. - * @param v1 first input vector, sum output, 16-byte aligned - * @param v2 second input vector, difference output, 16-byte aligned - * @param len length of vectors, multiple of 4 - */ - void (*butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len); - - /** - * Calculate the sum and difference of two vectors of floats and interleave - * results into a separate output vector of floats, with each sum - * positioned before the corresponding difference. - * - * @param dst output vector - * constraints: 16-byte aligned - * @param src0 first input vector - * constraints: 32-byte aligned - * @param src1 second input vector - * constraints: 32-byte aligned - * @param len number of elements in the input - * constraints: multiple of 8 - */ - void (*butterflies_float_interleave)(float *dst, const float *src0, - const float *src1, int len); /* (I)DCT */ - void (*fdct)(DCTELEM *block/* align 16*/); - void (*fdct248)(DCTELEM *block/* align 16*/); + void (*fdct)(int16_t *block/* align 16*/); + void (*fdct248)(int16_t *block/* align 16*/); /* IDCT really*/ - void (*idct)(DCTELEM *block/* align 16*/); + void (*idct)(int16_t *block/* align 16*/); /** * block -> idct -> clip to unsigned 8 bit -> dest. * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...) * @param line_size size in bytes of a horizontal line of dest */ - void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); + void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, int16_t *block/*align 16*/); /** * block -> idct -> add dest -> clip to unsigned 8 bit -> dest. * @param line_size size in bytes of a horizontal line of dest */ - void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); + void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, int16_t *block/*align 16*/); /** * idct input permutation. @@ -511,72 +392,8 @@ attribute_deprecated void dsputil_init(DSPContext* c, AVCodecContext *avctx); int ff_check_alignment(void); -/** - * Return the scalar product of two vectors. - * - * @param v1 first input vector - * @param v2 first input vector - * @param len number of elements - * - * @return sum of elementwise products - */ -float ff_scalarproduct_float_c(const float *v1, const float *v2, int len); - -/** - * permute block according to permuatation. - * @param last last non zero element in scantable order - */ -void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last); - void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type); -#define BYTE_VEC32(c) ((c)*0x01010101UL) -#define BYTE_VEC64(c) ((c)*UINT64_C(0x0001000100010001)) - -static inline uint32_t rnd_avg32(uint32_t a, uint32_t b) -{ - return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1); -} - -static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b) -{ - return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1); -} - -static inline uint64_t rnd_avg64(uint64_t a, uint64_t b) -{ - return (a | b) - (((a ^ b) & ~BYTE_VEC64(0x01)) >> 1); -} - -static inline uint64_t no_rnd_avg64(uint64_t a, uint64_t b) -{ - return (a & b) + (((a ^ b) & ~BYTE_VEC64(0x01)) >> 1); -} - -static inline int get_penalty_factor(int lambda, int lambda2, int type){ - switch(type&0xFF){ - default: - case FF_CMP_SAD: - return lambda>>FF_LAMBDA_SHIFT; - case FF_CMP_DCT: - return (3*lambda)>>(FF_LAMBDA_SHIFT+1); - case FF_CMP_W53: - return (4*lambda)>>(FF_LAMBDA_SHIFT); - case FF_CMP_W97: - return (2*lambda)>>(FF_LAMBDA_SHIFT); - case FF_CMP_SATD: - case FF_CMP_DCT264: - return (2*lambda)>>FF_LAMBDA_SHIFT; - case FF_CMP_RD: - case FF_CMP_PSNR: - case FF_CMP_SSE: - case FF_CMP_NSSE: - return lambda2>>FF_LAMBDA_SHIFT; - case FF_CMP_BIT: - return 1; - } -} - void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx); void ff_dsputil_init_arm(DSPContext* c, AVCodecContext *avctx); void ff_dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx); @@ -584,123 +401,7 @@ void ff_dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx); void ff_dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx); void ff_dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx); void ff_dsputil_init_vis(DSPContext* c, AVCodecContext *avctx); -void ff_dsputil_init_mips(DSPContext* c, AVCodecContext *avctx); void ff_dsputil_init_dwt(DSPContext *c); -#if (ARCH_ARM && HAVE_NEON) || ARCH_PPC || HAVE_MMX -# define STRIDE_ALIGN 16 -#else -# define STRIDE_ALIGN 8 -#endif - -// Some broken preprocessors need a second expansion -// to be forced to tokenize __VA_ARGS__ -#define E(x) x - -#define LOCAL_ALIGNED_A(a, t, v, s, o, ...) \ - uint8_t la_##v[sizeof(t s o) + (a)]; \ - t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a) - -#define LOCAL_ALIGNED_D(a, t, v, s, o, ...) \ - DECLARE_ALIGNED(a, t, la_##v) s o; \ - t (*v) o = la_##v - -#define LOCAL_ALIGNED(a, t, v, ...) E(LOCAL_ALIGNED_A(a, t, v, __VA_ARGS__,,)) - -#if HAVE_LOCAL_ALIGNED_8 -# define LOCAL_ALIGNED_8(t, v, ...) E(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,)) -#else -# define LOCAL_ALIGNED_8(t, v, ...) LOCAL_ALIGNED(8, t, v, __VA_ARGS__) -#endif - -#if HAVE_LOCAL_ALIGNED_16 -# define LOCAL_ALIGNED_16(t, v, ...) E(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,)) -#else -# define LOCAL_ALIGNED_16(t, v, ...) LOCAL_ALIGNED(16, t, v, __VA_ARGS__) -#endif - -#define WRAPPER8_16_SQ(name8, name16)\ -static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\ - int score=0;\ - score +=name8(s, dst , src , stride, 8);\ - score +=name8(s, dst+8 , src+8 , stride, 8);\ - if(h==16){\ - dst += 8*stride;\ - src += 8*stride;\ - score +=name8(s, dst , src , stride, 8);\ - score +=name8(s, dst+8 , src+8 , stride, 8);\ - }\ - return score;\ -} - - -static inline void copy_block2(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h) -{ - int i; - for(i=0; i 8 DCTELEM_FUNCS(dctcoef, _32) #endif +#include "hpel_template.c" + #define PIXOP2(OPNAME, OP) \ -static void FUNCC(OPNAME ## _pixels2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ - int i;\ - for(i=0; i>= sizeof(pixel)-1;\ a0= pixels[0];\ b0= pixels[1] + 2;\ @@ -441,7 +282,7 @@ static inline void FUNCC(OPNAME ## _pixels2_xy2)(uint8_t *p_block, const uint8_t }\ }\ \ -static inline void FUNCC(OPNAME ## _pixels4_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +static inline void FUNCC(OPNAME ## _pixels4_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)\ {\ /* FIXME HIGH BIT DEPTH */\ int i;\ @@ -478,7 +319,7 @@ static inline void FUNCC(OPNAME ## _pixels4_xy2)(uint8_t *block, const uint8_t * }\ }\ \ -static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)\ {\ /* FIXME HIGH BIT DEPTH */\ int j;\ @@ -520,7 +361,7 @@ static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, const uint8_t * }\ }\ \ -static inline void FUNCC(OPNAME ## _no_rnd_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +static inline void FUNCC(OPNAME ## _no_rnd_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)\ {\ /* FIXME HIGH BIT DEPTH */\ int j;\ @@ -562,7 +403,6 @@ static inline void FUNCC(OPNAME ## _no_rnd_pixels8_xy2)(uint8_t *block, const ui }\ }\ \ -CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16) , FUNCC(OPNAME ## _pixels8) , 8*sizeof(pixel))\ CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_x2) , FUNCC(OPNAME ## _pixels8_x2) , 8*sizeof(pixel))\ CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_y2) , FUNCC(OPNAME ## _pixels8_y2) , 8*sizeof(pixel))\ CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), FUNCC(OPNAME ## _pixels8_xy2), 8*sizeof(pixel))\ @@ -573,629 +413,14 @@ CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_xy2), FUNCC(OPNAME ## _no_rnd_pi #define op_avg(a, b) a = rnd_avg_pixel4(a, b) #define op_put(a, b) a = b - +#if BIT_DEPTH == 8 +#define put_no_rnd_pixels8_8_c put_pixels8_8_c PIXOP2(avg, op_avg) PIXOP2(put, op_put) +#endif #undef op_avg #undef op_put -#define put_no_rnd_pixels8_c put_pixels8_c -#define put_no_rnd_pixels16_c put_pixels16_c - -static void FUNCC(put_no_rnd_pixels16_l2)(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){ - FUNC(put_no_rnd_pixels16_l2)(dst, a, b, stride, stride, stride, h); -} - -static void FUNCC(put_no_rnd_pixels8_l2)(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){ - FUNC(put_no_rnd_pixels8_l2)(dst, a, b, stride, stride, stride, h); -} - -#define H264_CHROMA_MC(OPNAME, OP)\ -static void FUNCC(OPNAME ## h264_chroma_mc2)(uint8_t *p_dst/*align 8*/, uint8_t *p_src/*align 1*/, int stride, int h, int x, int y){\ - pixel *dst = (pixel*)p_dst;\ - pixel *src = (pixel*)p_src;\ - const int A=(8-x)*(8-y);\ - const int B=( x)*(8-y);\ - const int C=(8-x)*( y);\ - const int D=( x)*( y);\ - int i;\ - stride >>= sizeof(pixel)-1;\ - \ - av_assert2(x<8 && y<8 && x>=0 && y>=0);\ -\ - if(D){\ - for(i=0; i>= sizeof(pixel)-1;\ - \ - av_assert2(x<8 && y<8 && x>=0 && y>=0);\ -\ - if(D){\ - for(i=0; i>= sizeof(pixel)-1;\ - \ - av_assert2(x<8 && y<8 && x>=0 && y>=0);\ -\ - if(D){\ - for(i=0; i>6)+1)>>1) -#define op_put(a, b) a = (((b) + 32)>>6) - -H264_CHROMA_MC(put_ , op_put) -H264_CHROMA_MC(avg_ , op_avg) -#undef op_avg -#undef op_put - -#define H264_LOWPASS(OPNAME, OP, OP2) \ -static av_unused void FUNC(OPNAME ## h264_qpel2_h_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\ - const int h=2;\ - INIT_CLIP\ - int i;\ - pixel *dst = (pixel*)p_dst;\ - pixel *src = (pixel*)p_src;\ - dstStride >>= sizeof(pixel)-1;\ - srcStride >>= sizeof(pixel)-1;\ - for(i=0; i>= sizeof(pixel)-1;\ - srcStride >>= sizeof(pixel)-1;\ - for(i=0; i>= sizeof(pixel)-1;\ - srcStride >>= sizeof(pixel)-1;\ - src -= 2*srcStride;\ - for(i=0; i>= sizeof(pixel)-1;\ - srcStride >>= sizeof(pixel)-1;\ - for(i=0; i>= sizeof(pixel)-1;\ - srcStride >>= sizeof(pixel)-1;\ - for(i=0; i>= sizeof(pixel)-1;\ - srcStride >>= sizeof(pixel)-1;\ - src -= 2*srcStride;\ - for(i=0; i>= sizeof(pixel)-1;\ - srcStride >>= sizeof(pixel)-1;\ - for(i=0; i>= sizeof(pixel)-1;\ - srcStride >>= sizeof(pixel)-1;\ - for(i=0; i>= sizeof(pixel)-1;\ - srcStride >>= sizeof(pixel)-1;\ - src -= 2*srcStride;\ - for(i=0; i>5)+1)>>1) -//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7) -#define op_put(a, b) a = CLIP(((b) + 16)>>5) -#define op2_avg(a, b) a = (((a)+CLIP(((b) + 512)>>10)+1)>>1) -#define op2_put(a, b) a = CLIP(((b) + 512)>>10) - -H264_LOWPASS(put_ , op_put, op2_put) -H264_LOWPASS(avg_ , op_avg, op2_avg) -H264_MC(put_, 2) -H264_MC(put_, 4) -H264_MC(put_, 8) -H264_MC(put_, 16) -H264_MC(avg_, 4) -H264_MC(avg_, 8) -H264_MC(avg_, 16) - -#undef op_avg -#undef op_put -#undef op2_avg -#undef op2_put - -#if BIT_DEPTH == 8 -# define put_h264_qpel8_mc00_8_c ff_put_pixels8x8_8_c -# define avg_h264_qpel8_mc00_8_c ff_avg_pixels8x8_8_c -# define put_h264_qpel16_mc00_8_c ff_put_pixels16x16_8_c -# define avg_h264_qpel16_mc00_8_c ff_avg_pixels16x16_8_c -#elif BIT_DEPTH == 9 -# define put_h264_qpel8_mc00_9_c ff_put_pixels8x8_9_c -# define avg_h264_qpel8_mc00_9_c ff_avg_pixels8x8_9_c -# define put_h264_qpel16_mc00_9_c ff_put_pixels16x16_9_c -# define avg_h264_qpel16_mc00_9_c ff_avg_pixels16x16_9_c -#elif BIT_DEPTH == 10 -# define put_h264_qpel8_mc00_10_c ff_put_pixels8x8_10_c -# define avg_h264_qpel8_mc00_10_c ff_avg_pixels8x8_10_c -# define put_h264_qpel16_mc00_10_c ff_put_pixels16x16_10_c -# define avg_h264_qpel16_mc00_10_c ff_avg_pixels16x16_10_c -#elif BIT_DEPTH == 12 -# define put_h264_qpel8_mc00_12_c ff_put_pixels8x8_12_c -# define avg_h264_qpel8_mc00_12_c ff_avg_pixels8x8_12_c -# define put_h264_qpel16_mc00_12_c ff_put_pixels16x16_12_c -# define avg_h264_qpel16_mc00_12_c ff_avg_pixels16x16_12_c -#elif BIT_DEPTH == 14 -# define put_h264_qpel8_mc00_14_c ff_put_pixels8x8_14_c -# define avg_h264_qpel8_mc00_14_c ff_avg_pixels8x8_14_c -# define put_h264_qpel16_mc00_14_c ff_put_pixels16x16_14_c -# define avg_h264_qpel16_mc00_14_c ff_avg_pixels16x16_14_c -#endif - void FUNCC(ff_put_pixels8x8)(uint8_t *dst, uint8_t *src, int stride) { FUNCC(put_pixels8)(dst, src, stride, 8); } diff --git a/mythtv/external/FFmpeg/libavcodec/dv.c b/mythtv/external/FFmpeg/libavcodec/dv.c index 18c90c2b6cb..0812dbbacfb 100644 --- a/mythtv/external/FFmpeg/libavcodec/dv.c +++ b/mythtv/external/FFmpeg/libavcodec/dv.c @@ -38,9 +38,9 @@ * DV codec. */ +#include "libavutil/internal.h" #include "libavutil/pixdesc.h" #include "avcodec.h" -#include "dsputil.h" #include "get_bits.h" #include "internal.h" #include "put_bits.h" @@ -417,7 +417,7 @@ typedef struct EncBlockInfo { int cur_ac; int cno; int dct_mode; - DCTELEM mb[64]; + int16_t mb[64]; uint8_t next[64]; uint8_t sign[64]; uint8_t partial_bit_count; @@ -506,7 +506,7 @@ static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, i { const int *weight; const uint8_t* zigzag_scan; - LOCAL_ALIGNED_16(DCTELEM, blk, [64]); + LOCAL_ALIGNED_16(int16_t, blk, [64]); int i, area; /* We offer two different methods for class number assignment: the method suggested in SMPTE 314M Table 22, and an improved diff --git a/mythtv/external/FFmpeg/libavcodec/dv_profile.c b/mythtv/external/FFmpeg/libavcodec/dv_profile.c index 05d4abae169..a1d98818c42 100644 --- a/mythtv/external/FFmpeg/libavcodec/dv_profile.c +++ b/mythtv/external/FFmpeg/libavcodec/dv_profile.c @@ -298,7 +298,11 @@ const DVprofile* avpriv_dv_frame_profile2(AVCodecContext* codec, const DVprofile return &dv_profiles[2]; } - if(stype == 0 && codec && codec->codec_tag==AV_RL32("dvsd") && codec->coded_width==720 && codec->coded_height==576) + if( stype == 0 + && codec + && (codec->codec_tag==AV_RL32("dvsd") || codec->codec_tag==AV_RL32("CDVC")) + && codec->coded_width ==720 + && codec->coded_height==576) return &dv_profiles[1]; for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++) diff --git a/mythtv/external/FFmpeg/libavcodec/dvbsub_parser.c b/mythtv/external/FFmpeg/libavcodec/dvbsub_parser.c index ff685398d2f..a2f5ea3f086 100644 --- a/mythtv/external/FFmpeg/libavcodec/dvbsub_parser.c +++ b/mythtv/external/FFmpeg/libavcodec/dvbsub_parser.c @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avcodec.h" -#include "dsputil.h" #include "get_bits.h" /* Parser (mostly) copied from dvdsub.c */ diff --git a/mythtv/external/FFmpeg/libavcodec/dvdata.h b/mythtv/external/FFmpeg/libavcodec/dvdata.h index b1fa44ae39d..97c20e3a1a1 100644 --- a/mythtv/external/FFmpeg/libavcodec/dvdata.h +++ b/mythtv/external/FFmpeg/libavcodec/dvdata.h @@ -40,9 +40,9 @@ typedef struct DVVideoContext { uint8_t dv_zigzag[2][64]; - void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size); - void (*fdct[2])(DCTELEM *block); - void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block); + void (*get_pixels)(int16_t *block, const uint8_t *pixels, int line_size); + void (*fdct[2])(int16_t *block); + void (*idct_put[2])(uint8_t *dest, int line_size, int16_t *block); me_cmp_func ildct_cmp; } DVVideoContext; diff --git a/mythtv/external/FFmpeg/libavcodec/dvdec.c b/mythtv/external/FFmpeg/libavcodec/dvdec.c index fd00cc18d60..64d2259a7b6 100644 --- a/mythtv/external/FFmpeg/libavcodec/dvdec.c +++ b/mythtv/external/FFmpeg/libavcodec/dvdec.c @@ -36,9 +36,9 @@ */ #include "libavutil/avassert.h" +#include "libavutil/internal.h" #include "libavutil/pixdesc.h" #include "avcodec.h" -#include "dsputil.h" #include "internal.h" #include "get_bits.h" #include "put_bits.h" @@ -49,7 +49,7 @@ typedef struct BlockInfo { const uint32_t *factor_table; const uint8_t *scan_table; uint8_t pos; /* position in block */ - void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block); + void (*idct_put)(uint8_t *dest, int line_size, int16_t *block); uint8_t partial_bit_count; uint32_t partial_bit_buffer; int shift_offset; @@ -58,7 +58,7 @@ typedef struct BlockInfo { static const int dv_iweight_bits = 14; /* decode AC coefficients */ -static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, DCTELEM *block) +static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, int16_t *block) { int last_index = gb->size_in_bits; const uint8_t *scan_table = mb->scan_table; @@ -136,14 +136,14 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg) int quant, dc, dct_mode, class1, j; int mb_index, mb_x, mb_y, last_index; int y_stride, linesize; - DCTELEM *block, *block1; + int16_t *block, *block1; int c_offset; uint8_t *y_ptr; const uint8_t *buf_ptr; PutBitContext pb, vs_pb; GetBitContext gb; BlockInfo mb_data[5 * DV_MAX_BPM], *mb, *mb1; - LOCAL_ALIGNED_16(DCTELEM, sblock, [5*DV_MAX_BPM], [64]); + LOCAL_ALIGNED_16(int16_t, sblock, [5*DV_MAX_BPM], [64]); LOCAL_ALIGNED_16(uint8_t, mb_bit_buffer, [ 80 + FF_INPUT_BUFFER_PADDING_SIZE]); /* allow some slack */ LOCAL_ALIGNED_16(uint8_t, vs_bit_buffer, [5*80 + FF_INPUT_BUFFER_PADDING_SIZE]); /* allow some slack */ const int log2_blocksize = 3-s->avctx->lowres; diff --git a/mythtv/external/FFmpeg/libavcodec/dvdsubdec.c b/mythtv/external/FFmpeg/libavcodec/dvdsubdec.c index b6b9614b535..4bfc0e4e80f 100644 --- a/mythtv/external/FFmpeg/libavcodec/dvdsubdec.c +++ b/mythtv/external/FFmpeg/libavcodec/dvdsubdec.c @@ -24,6 +24,7 @@ #include "libavutil/colorspace.h" #include "libavutil/opt.h" #include "libavutil/imgutils.h" +#include "libavutil/avstring.h" //#define DEBUG @@ -127,8 +128,8 @@ static int decode_rle(uint8_t *bitmap, int linesize, int w, int h, return 0; } -static void guess_palette(uint32_t *rgba_palette, - DVDSubContext* ctx, +static void guess_palette(DVDSubContext* ctx, + uint32_t *rgba_palette, uint32_t subtitle_color) { static const uint8_t level_map[4][4] = { @@ -146,7 +147,7 @@ static void guess_palette(uint32_t *rgba_palette, if(ctx->has_palette) { for(i = 0; i < 4; i++) rgba_palette[i] = (ctx->palette[colormap[i]] & 0x00ffffff) - | ((alpha[i] * 17) << 24); + | ((alpha[i] * 17U) << 24); return; } @@ -351,7 +352,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header, yuv_a_to_rgba(yuv_palette, alpha, (uint32_t*)sub_header->rects[0]->pict.data[1], 256); } else { sub_header->rects[0]->nb_colors = 4; - guess_palette((uint32_t*)sub_header->rects[0]->pict.data[1], ctx, + guess_palette(ctx, (uint32_t*)sub_header->rects[0]->pict.data[1], 0xffffff); } sub_header->rects[0]->x = x1; @@ -490,7 +491,7 @@ static int dvdsub_decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { - DVDSubContext *ctx = (DVDSubContext*) avctx->priv_data; + DVDSubContext *ctx = avctx->priv_data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AVSubtitle *sub = data; @@ -526,7 +527,7 @@ static void parse_palette(DVDSubContext *ctx, char *p) ctx->has_palette = 1; for(i=0;i<16;i++) { ctx->palette[i] = strtoul(p, &p, 16); - while(*p == ',' || isspace(*p)) + while(*p == ',' || av_isspace(*p)) p++; } } @@ -569,7 +570,7 @@ static int dvdsub_parse_extradata(AVCodecContext *avctx) static int dvdsub_init(AVCodecContext *avctx) { - DVDSubContext *ctx = (DVDSubContext*) avctx->priv_data; + DVDSubContext *ctx = avctx->priv_data; int ret; if ((ret = dvdsub_parse_extradata(avctx)) < 0) diff --git a/mythtv/external/FFmpeg/libavcodec/dvdsubenc.c b/mythtv/external/FFmpeg/libavcodec/dvdsubenc.c index cd041c3f240..6e196235cba 100644 --- a/mythtv/external/FFmpeg/libavcodec/dvdsubenc.c +++ b/mythtv/external/FFmpeg/libavcodec/dvdsubenc.c @@ -207,7 +207,7 @@ static void select_palette(AVCodecContext *avctx, int out_palette[4], static void build_color_map(AVCodecContext *avctx, int cmap[], const uint32_t palette[], - const int out_palette[], int const out_alpha[]) + const int out_palette[], unsigned int const out_alpha[]) { DVDSubtitleContext *dvdc = avctx->priv_data; int i, j, d, best_d; diff --git a/mythtv/external/FFmpeg/libavcodec/dxa.c b/mythtv/external/FFmpeg/libavcodec/dxa.c index 3f489aeab9f..a2fe5578df0 100644 --- a/mythtv/external/FFmpeg/libavcodec/dxa.c +++ b/mythtv/external/FFmpeg/libavcodec/dxa.c @@ -211,7 +211,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac pc = 1; } - if ((ret = ff_get_buffer(avctx, &c->pic)) < 0){ + if ((ret = ff_get_buffer(avctx, &c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -234,7 +234,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac if (uncompress(c->decomp_buf, &dsize, avpkt->data + bytestream2_tell(&gb), bytestream2_get_bytes_left(&gb)) != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Uncompress failed!\n"); - return AVERROR_INVALIDDATA; + return AVERROR_UNKNOWN; } } switch(compr){ diff --git a/mythtv/external/FFmpeg/libavcodec/dxva2.c b/mythtv/external/FFmpeg/libavcodec/dxva2.c index d8660710d69..0997c736778 100644 --- a/mythtv/external/FFmpeg/libavcodec/dxva2.c +++ b/mythtv/external/FFmpeg/libavcodec/dxva2.c @@ -76,7 +76,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, return result; } -int ff_dxva2_common_end_frame(AVCodecContext *avctx, MpegEncContext *s, +int ff_dxva2_common_end_frame(AVCodecContext *avctx, Picture *pic, const void *pp, unsigned pp_size, const void *qm, unsigned qm_size, int (*commit_bs_si)(AVCodecContext *, @@ -90,7 +90,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, MpegEncContext *s, int result; if (FAILED(IDirectXVideoDecoder_BeginFrame(ctx->decoder, - ff_dxva2_get_surface(s->current_picture_ptr), + ff_dxva2_get_surface(pic), NULL))) { av_log(avctx, AV_LOG_ERROR, "Failed to begin frame\n"); return -1; @@ -146,7 +146,5 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, MpegEncContext *s, result = -1; } - if (!result) - ff_draw_horiz_band(s, 0, s->avctx->height); return result; } diff --git a/mythtv/external/FFmpeg/libavcodec/dxva2.h b/mythtv/external/FFmpeg/libavcodec/dxva2.h index 7d27ca5af79..ac39e06917b 100644 --- a/mythtv/external/FFmpeg/libavcodec/dxva2.h +++ b/mythtv/external/FFmpeg/libavcodec/dxva2.h @@ -29,8 +29,15 @@ * Public libavcodec DXVA2 header. */ -#include +#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600 +#undef _WIN32_WINNT +#endif + +#if !defined(_WIN32_WINNT) +#define _WIN32_WINNT 0x0600 +#endif +#include #include #include diff --git a/mythtv/external/FFmpeg/libavcodec/dxva2_h264.c b/mythtv/external/FFmpeg/libavcodec/dxva2_h264.c index f7d4e5d4ec3..f57ee544a85 100644 --- a/mythtv/external/FFmpeg/libavcodec/dxva2_h264.c +++ b/mythtv/external/FFmpeg/libavcodec/dxva2_h264.c @@ -44,15 +44,14 @@ static void fill_picture_entry(DXVA_PicEntry_H264 *pic, static void fill_picture_parameters(struct dxva_context *ctx, const H264Context *h, DXVA_PicParams_H264 *pp) { - const MpegEncContext *s = &h->s; - const Picture *current_picture = s->current_picture_ptr; + const Picture *current_picture = h->cur_pic_ptr; int i, j; memset(pp, 0, sizeof(*pp)); /* Configure current picture */ fill_picture_entry(&pp->CurrPic, ff_dxva2_get_surface_index(ctx, current_picture), - s->picture_structure == PICT_BOTTOM_FIELD); + h->picture_structure == PICT_BOTTOM_FIELD); /* Configure the set of references */ pp->UsedForReferenceFlags = 0; pp->NonExistingFrameFlags = 0; @@ -88,13 +87,13 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context } } - pp->wFrameWidthInMbsMinus1 = s->mb_width - 1; - pp->wFrameHeightInMbsMinus1 = s->mb_height - 1; + pp->wFrameWidthInMbsMinus1 = h->mb_width - 1; + pp->wFrameHeightInMbsMinus1 = h->mb_height - 1; pp->num_ref_frames = h->sps.ref_frame_count; - pp->wBitFields = ((s->picture_structure != PICT_FRAME) << 0) | + pp->wBitFields = ((h->picture_structure != PICT_FRAME) << 0) | ((h->sps.mb_aff && - (s->picture_structure == PICT_FRAME)) << 1) | + (h->picture_structure == PICT_FRAME)) << 1) | (h->sps.residual_color_transform_flag << 2) | /* sp_for_switch_flag (not implemented by FFmpeg) */ (0 << 3) | @@ -109,7 +108,7 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context (h->pps.transform_8x8_mode << 13) | ((h->sps.level_idc >= 31) << 14) | /* IntraPicFlag (Modified if we detect a non - * intra slice in decode_slice) */ + * intra slice in dxva2_h264_decode_slice) */ (1 << 15); pp->bit_depth_luma_minus8 = h->sps.bit_depth_luma - 8; @@ -120,11 +119,11 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context pp->Reserved16Bits = 3; /* FIXME is there a way to detect the right mode ? */ pp->StatusReportFeedbackNumber = 1 + ctx->report_id++; pp->CurrFieldOrderCnt[0] = 0; - if ((s->picture_structure & PICT_TOP_FIELD) && + if ((h->picture_structure & PICT_TOP_FIELD) && current_picture->field_poc[0] != INT_MAX) pp->CurrFieldOrderCnt[0] = current_picture->field_poc[0]; pp->CurrFieldOrderCnt[1] = 0; - if ((s->picture_structure & PICT_BOTTOM_FIELD) && + if ((h->picture_structure & PICT_BOTTOM_FIELD) && current_picture->field_poc[1] != INT_MAX) pp->CurrFieldOrderCnt[1] = current_picture->field_poc[1]; pp->pic_init_qs_minus26 = h->pps.init_qs - 26; @@ -200,7 +199,6 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, { const H264Context *h = avctx->priv_data; struct dxva_context *ctx = avctx->hwaccel_context; - const MpegEncContext *s = &h->s; unsigned list; memset(slice, 0, sizeof(*slice)); @@ -208,9 +206,9 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, slice->SliceBytesInBuffer = size; slice->wBadSliceChopping = 0; - slice->first_mb_in_slice = (s->mb_y >> FIELD_OR_MBAFF_PICTURE) * s->mb_width + s->mb_x; + slice->first_mb_in_slice = (h->mb_y >> FIELD_OR_MBAFF_PICTURE) * h->mb_width + h->mb_x; slice->NumMbsForSlice = 0; /* XXX it is set once we have all slices */ - slice->BitOffsetToSliceData = get_bits_count(&s->gb); + slice->BitOffsetToSliceData = get_bits_count(&h->gb); slice->slice_type = ff_h264_get_slice_type(h); if (h->slice_type_fixed) slice->slice_type += 5; @@ -260,7 +258,7 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, } } slice->slice_qs_delta = 0; /* XXX not implemented by FFmpeg */ - slice->slice_qp_delta = s->qscale - h->pps.init_qp; + slice->slice_qp_delta = h->qscale - h->pps.init_qp; slice->redundant_pic_cnt = h->redundant_pic_count; if (h->slice_type == AV_PICTURE_TYPE_B) slice->direct_spatial_mv_pred_flag = h->direct_spatial_mv_pred; @@ -277,10 +275,9 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, DXVA2_DecodeBufferDesc *sc) { const H264Context *h = avctx->priv_data; - const MpegEncContext *s = &h->s; - const unsigned mb_count = s->mb_width * s->mb_height; + const unsigned mb_count = h->mb_width * h->mb_height; struct dxva_context *ctx = avctx->hwaccel_context; - const Picture *current_picture = h->s.current_picture_ptr; + const Picture *current_picture = h->cur_pic_ptr; struct dxva2_picture_context *ctx_pic = current_picture->f.hwaccel_picture_private; DXVA_Slice_H264_Short *slice = NULL; uint8_t *dxva_data, *current, *end; @@ -370,13 +367,13 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, } -static int start_frame(AVCodecContext *avctx, - av_unused const uint8_t *buffer, - av_unused uint32_t size) +static int dxva2_h264_start_frame(AVCodecContext *avctx, + av_unused const uint8_t *buffer, + av_unused uint32_t size) { const H264Context *h = avctx->priv_data; struct dxva_context *ctx = avctx->hwaccel_context; - struct dxva2_picture_context *ctx_pic = h->s.current_picture_ptr->f.hwaccel_picture_private; + struct dxva2_picture_context *ctx_pic = h->cur_pic_ptr->f.hwaccel_picture_private; if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0) return -1; @@ -394,12 +391,13 @@ static int start_frame(AVCodecContext *avctx, return 0; } -static int decode_slice(AVCodecContext *avctx, - const uint8_t *buffer, uint32_t size) +static int dxva2_h264_decode_slice(AVCodecContext *avctx, + const uint8_t *buffer, + uint32_t size) { const H264Context *h = avctx->priv_data; struct dxva_context *ctx = avctx->hwaccel_context; - const Picture *current_picture = h->s.current_picture_ptr; + const Picture *current_picture = h->cur_pic_ptr; struct dxva2_picture_context *ctx_pic = current_picture->f.hwaccel_picture_private; unsigned position; @@ -424,19 +422,22 @@ static int decode_slice(AVCodecContext *avctx, return 0; } -static int end_frame(AVCodecContext *avctx) +static int dxva2_h264_end_frame(AVCodecContext *avctx) { H264Context *h = avctx->priv_data; - MpegEncContext *s = &h->s; struct dxva2_picture_context *ctx_pic = - h->s.current_picture_ptr->f.hwaccel_picture_private; + h->cur_pic_ptr->f.hwaccel_picture_private; + int ret; if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0) return -1; - return ff_dxva2_common_end_frame(avctx, s, - &ctx_pic->pp, sizeof(ctx_pic->pp), - &ctx_pic->qm, sizeof(ctx_pic->qm), - commit_bitstream_and_slice_buffer); + ret = ff_dxva2_common_end_frame(avctx, h->cur_pic_ptr, + &ctx_pic->pp, sizeof(ctx_pic->pp), + &ctx_pic->qm, sizeof(ctx_pic->qm), + commit_bitstream_and_slice_buffer); + if (!ret) + ff_h264_draw_horiz_band(h, 0, h->avctx->height); + return ret; } AVHWAccel ff_h264_dxva2_hwaccel = { @@ -444,8 +445,8 @@ AVHWAccel ff_h264_dxva2_hwaccel = { .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_H264, .pix_fmt = AV_PIX_FMT_DXVA2_VLD, - .start_frame = start_frame, - .decode_slice = decode_slice, - .end_frame = end_frame, + .start_frame = dxva2_h264_start_frame, + .decode_slice = dxva2_h264_decode_slice, + .end_frame = dxva2_h264_end_frame, .priv_data_size = sizeof(struct dxva2_picture_context), }; diff --git a/mythtv/external/FFmpeg/libavcodec/dxva2_internal.h b/mythtv/external/FFmpeg/libavcodec/dxva2_internal.h index fcf45bc664c..8a454c12997 100644 --- a/mythtv/external/FFmpeg/libavcodec/dxva2_internal.h +++ b/mythtv/external/FFmpeg/libavcodec/dxva2_internal.h @@ -23,7 +23,6 @@ #ifndef AVCODEC_DXVA_INTERNAL_H #define AVCODEC_DXVA_INTERNAL_H -#define _WIN32_WINNT 0x0600 #define COBJMACROS #include "config.h" @@ -47,7 +46,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *, struct dxva_context *, unsigned mb_count); -int ff_dxva2_common_end_frame(AVCodecContext *, MpegEncContext *, +int ff_dxva2_common_end_frame(AVCodecContext *, Picture *, const void *pp, unsigned pp_size, const void *qm, unsigned qm_size, int (*commit_bs_si)(AVCodecContext *, diff --git a/mythtv/external/FFmpeg/libavcodec/dxva2_mpeg2.c b/mythtv/external/FFmpeg/libavcodec/dxva2_mpeg2.c index f050ed9d50e..7c292bf1bef 100644 --- a/mythtv/external/FFmpeg/libavcodec/dxva2_mpeg2.c +++ b/mythtv/external/FFmpeg/libavcodec/dxva2_mpeg2.c @@ -203,9 +203,9 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, mb_count); } -static int start_frame(AVCodecContext *avctx, - av_unused const uint8_t *buffer, - av_unused uint32_t size) +static int dxva2_mpeg2_start_frame(AVCodecContext *avctx, + av_unused const uint8_t *buffer, + av_unused uint32_t size) { const struct MpegEncContext *s = avctx->priv_data; struct dxva_context *ctx = avctx->hwaccel_context; @@ -225,8 +225,8 @@ static int start_frame(AVCodecContext *avctx, return 0; } -static int decode_slice(AVCodecContext *avctx, - const uint8_t *buffer, uint32_t size) +static int dxva2_mpeg2_decode_slice(AVCodecContext *avctx, + const uint8_t *buffer, uint32_t size) { const struct MpegEncContext *s = avctx->priv_data; struct dxva2_picture_context *ctx_pic = @@ -246,18 +246,22 @@ static int decode_slice(AVCodecContext *avctx, return 0; } -static int end_frame(AVCodecContext *avctx) +static int dxva2_mpeg2_end_frame(AVCodecContext *avctx) { struct MpegEncContext *s = avctx->priv_data; struct dxva2_picture_context *ctx_pic = s->current_picture_ptr->f.hwaccel_picture_private; + int ret; if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0) return -1; - return ff_dxva2_common_end_frame(avctx, s, - &ctx_pic->pp, sizeof(ctx_pic->pp), - &ctx_pic->qm, sizeof(ctx_pic->qm), - commit_bitstream_and_slice_buffer); + ret = ff_dxva2_common_end_frame(avctx, s->current_picture_ptr, + &ctx_pic->pp, sizeof(ctx_pic->pp), + &ctx_pic->qm, sizeof(ctx_pic->qm), + commit_bitstream_and_slice_buffer); + if (!ret) + ff_mpeg_draw_horiz_band(s, 0, avctx->height); + return ret; } AVHWAccel ff_mpeg2_dxva2_hwaccel = { @@ -265,8 +269,8 @@ AVHWAccel ff_mpeg2_dxva2_hwaccel = { .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_MPEG2VIDEO, .pix_fmt = AV_PIX_FMT_DXVA2_VLD, - .start_frame = start_frame, - .decode_slice = decode_slice, - .end_frame = end_frame, + .start_frame = dxva2_mpeg2_start_frame, + .decode_slice = dxva2_mpeg2_decode_slice, + .end_frame = dxva2_mpeg2_end_frame, .priv_data_size = sizeof(struct dxva2_picture_context), }; diff --git a/mythtv/external/FFmpeg/libavcodec/dxva2_vc1.c b/mythtv/external/FFmpeg/libavcodec/dxva2_vc1.c index ed4836dc8b1..a0810c9c777 100644 --- a/mythtv/external/FFmpeg/libavcodec/dxva2_vc1.c +++ b/mythtv/external/FFmpeg/libavcodec/dxva2_vc1.c @@ -211,9 +211,9 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, slice, sizeof(*slice), bs->NumMBsInBuffer); } -static int start_frame(AVCodecContext *avctx, - av_unused const uint8_t *buffer, - av_unused uint32_t size) +static int dxva2_vc1_start_frame(AVCodecContext *avctx, + av_unused const uint8_t *buffer, + av_unused uint32_t size) { const VC1Context *v = avctx->priv_data; struct dxva_context *ctx = avctx->hwaccel_context; @@ -230,8 +230,9 @@ static int start_frame(AVCodecContext *avctx, return 0; } -static int decode_slice(AVCodecContext *avctx, - const uint8_t *buffer, uint32_t size) +static int dxva2_vc1_decode_slice(AVCodecContext *avctx, + const uint8_t *buffer, + uint32_t size) { const VC1Context *v = avctx->priv_data; const Picture *current_picture = v->s.current_picture_ptr; @@ -253,18 +254,22 @@ static int decode_slice(AVCodecContext *avctx, return 0; } -static int end_frame(AVCodecContext *avctx) +static int dxva2_vc1_end_frame(AVCodecContext *avctx) { VC1Context *v = avctx->priv_data; struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->f.hwaccel_picture_private; + int ret; if (ctx_pic->bitstream_size <= 0) return -1; - return ff_dxva2_common_end_frame(avctx, &v->s, - &ctx_pic->pp, sizeof(ctx_pic->pp), - NULL, 0, - commit_bitstream_and_slice_buffer); + ret = ff_dxva2_common_end_frame(avctx, v->s.current_picture_ptr, + &ctx_pic->pp, sizeof(ctx_pic->pp), + NULL, 0, + commit_bitstream_and_slice_buffer); + if (!ret) + ff_mpeg_draw_horiz_band(&v->s, 0, avctx->height); + return ret; } #if CONFIG_WMV3_DXVA2_HWACCEL @@ -273,9 +278,9 @@ AVHWAccel ff_wmv3_dxva2_hwaccel = { .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_WMV3, .pix_fmt = AV_PIX_FMT_DXVA2_VLD, - .start_frame = start_frame, - .decode_slice = decode_slice, - .end_frame = end_frame, + .start_frame = dxva2_vc1_start_frame, + .decode_slice = dxva2_vc1_decode_slice, + .end_frame = dxva2_vc1_end_frame, .priv_data_size = sizeof(struct dxva2_picture_context), }; #endif @@ -285,8 +290,8 @@ AVHWAccel ff_vc1_dxva2_hwaccel = { .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_VC1, .pix_fmt = AV_PIX_FMT_DXVA2_VLD, - .start_frame = start_frame, - .decode_slice = decode_slice, - .end_frame = end_frame, + .start_frame = dxva2_vc1_start_frame, + .decode_slice = dxva2_vc1_decode_slice, + .end_frame = dxva2_vc1_end_frame, .priv_data_size = sizeof(struct dxva2_picture_context), }; diff --git a/mythtv/external/FFmpeg/libavcodec/eacmv.c b/mythtv/external/FFmpeg/libavcodec/eacmv.c index a129161386b..33c614588d4 100644 --- a/mythtv/external/FFmpeg/libavcodec/eacmv.c +++ b/mythtv/external/FFmpeg/libavcodec/eacmv.c @@ -132,8 +132,13 @@ static void cmv_process_header(CmvContext *s, const uint8_t *buf, const uint8_t s->width = AV_RL16(&buf[4]); s->height = AV_RL16(&buf[6]); - if (s->avctx->width!=s->width || s->avctx->height!=s->height) + if (s->avctx->width!=s->width || s->avctx->height!=s->height) { avcodec_set_dimensions(s->avctx, s->width, s->height); + if (s->frame.data[0]) + s->avctx->release_buffer(s->avctx, &s->frame); + if (s->last_frame.data[0]) + s->avctx->release_buffer(s->avctx, &s->last_frame); + } s->avctx->time_base.num = 1; s->avctx->time_base.den = AV_RL16(&buf[10]); diff --git a/mythtv/external/FFmpeg/libavcodec/eaidct.c b/mythtv/external/FFmpeg/libavcodec/eaidct.c index 175c1c47c0a..e4840f26535 100644 --- a/mythtv/external/FFmpeg/libavcodec/eaidct.c +++ b/mythtv/external/FFmpeg/libavcodec/eaidct.c @@ -25,7 +25,6 @@ * @author Peter Ross */ -#include "dsputil.h" #include "eaidct.h" #include "libavutil/common.h" @@ -64,7 +63,7 @@ #define MUNGE_8BIT(x) av_clip_uint8((x)>>4) #define IDCT_ROW(dest,src) IDCT_TRANSFORM(dest,0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,MUNGE_8BIT,src) -static inline void ea_idct_col(DCTELEM *dest, const DCTELEM *src) { +static inline void ea_idct_col(int16_t *dest, const int16_t *src) { if ((src[8]|src[16]|src[24]|src[32]|src[40]|src[48]|src[56])==0) { dest[0] = dest[8] = @@ -78,9 +77,9 @@ static inline void ea_idct_col(DCTELEM *dest, const DCTELEM *src) { IDCT_COL(dest, src); } -void ff_ea_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block) { +void ff_ea_idct_put_c(uint8_t *dest, int linesize, int16_t *block) { int i; - DCTELEM temp[64]; + int16_t temp[64]; block[0] += 4; for (i=0; i<8; i++) ea_idct_col(&temp[i], &block[i]); diff --git a/mythtv/external/FFmpeg/libavcodec/eaidct.h b/mythtv/external/FFmpeg/libavcodec/eaidct.h index a436673e885..6b9ec1c91c8 100644 --- a/mythtv/external/FFmpeg/libavcodec/eaidct.h +++ b/mythtv/external/FFmpeg/libavcodec/eaidct.h @@ -20,8 +20,7 @@ #define AVCODEC_EAIDCT_H #include -#include "dsputil.h" -void ff_ea_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block); +void ff_ea_idct_put_c(uint8_t *dest, int linesize, int16_t *block); #endif /* AVCODEC_EAIDCT_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/eamad.c b/mythtv/external/FFmpeg/libavcodec/eamad.c index e71bf9adb3c..b9679bca861 100644 --- a/mythtv/external/FFmpeg/libavcodec/eamad.c +++ b/mythtv/external/FFmpeg/libavcodec/eamad.c @@ -30,7 +30,6 @@ #include "avcodec.h" #include "get_bits.h" -#include "dsputil.h" #include "aandcttab.h" #include "eaidct.h" #include "internal.h" @@ -51,7 +50,7 @@ typedef struct MadContext { GetBitContext gb; void *bitstream_buf; unsigned int bitstream_buf_size; - DECLARE_ALIGNED(16, DCTELEM, block)[64]; + DECLARE_ALIGNED(16, int16_t, block)[64]; ScanTable scantable; uint16_t quant_matrix[64]; int mb_x; @@ -102,7 +101,7 @@ static inline void comp_block(MadContext *t, int mb_x, int mb_y, } } -static inline void idct_put(MadContext *t, DCTELEM *block, int mb_x, int mb_y, int j) +static inline void idct_put(MadContext *t, int16_t *block, int mb_x, int mb_y, int j) { if (j < 4) { ff_ea_idct_put_c( @@ -116,7 +115,7 @@ static inline void idct_put(MadContext *t, DCTELEM *block, int mb_x, int mb_y, i } } -static inline int decode_block_intra(MadContext *s, DCTELEM * block) +static inline int decode_block_intra(MadContext *s, int16_t * block) { int level, i, j, run; RLTable *rl = &ff_rl_mpeg1; @@ -276,21 +275,6 @@ static int decode_frame(AVCodecContext *avctx, } } - if (inter && !s->last_frame.data[0]) { - int ret; - av_log(avctx, AV_LOG_WARNING, "Missing reference frame.\n"); - s->last_frame.reference = 1; - ret = ff_get_buffer(avctx, &s->last_frame); - if (ret < 0) - return ret; - memset(s->last_frame.data[0], 0, s->last_frame.height * - s->last_frame.linesize[0]); - memset(s->last_frame.data[1], 0x80, s->last_frame.height / 2 * - s->last_frame.linesize[1]); - memset(s->last_frame.data[2], 0x80, s->last_frame.height / 2 * - s->last_frame.linesize[2]); - } - av_fast_padded_malloc(&s->bitstream_buf, &s->bitstream_buf_size, buf_end - buf); if (!s->bitstream_buf) diff --git a/mythtv/external/FFmpeg/libavcodec/eatgq.c b/mythtv/external/FFmpeg/libavcodec/eatgq.c index c38b3cdf9ca..524798b1b99 100644 --- a/mythtv/external/FFmpeg/libavcodec/eatgq.c +++ b/mythtv/external/FFmpeg/libavcodec/eatgq.c @@ -40,137 +40,141 @@ typedef struct TgqContext { AVCodecContext *avctx; AVFrame frame; - int width,height; + int width, height; ScanTable scantable; int qtable[64]; - DECLARE_ALIGNED(16, DCTELEM, block)[6][64]; + DECLARE_ALIGNED(16, int16_t, block)[6][64]; GetByteContext gb; } TgqContext; -static av_cold int tgq_decode_init(AVCodecContext *avctx){ +static av_cold int tgq_decode_init(AVCodecContext *avctx) +{ TgqContext *s = avctx->priv_data; uint8_t idct_permutation[64]; s->avctx = avctx; ff_init_scantable_permutation(idct_permutation, FF_NO_IDCT_PERM); ff_init_scantable(idct_permutation, &s->scantable, ff_zigzag_direct); avctx->time_base = (AVRational){1, 15}; - avctx->pix_fmt = AV_PIX_FMT_YUV420P; + avctx->pix_fmt = AV_PIX_FMT_YUV420P; return 0; } -static void tgq_decode_block(TgqContext *s, DCTELEM block[64], GetBitContext *gb){ +static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb) +{ uint8_t *perm = s->scantable.permutated; - int i,j,value; - block[0] = get_sbits(gb,8) * s->qtable[0]; - for(i=1; i<64; ) { - switch(show_bits(gb,3)) { + int i, j, value; + block[0] = get_sbits(gb, 8) * s->qtable[0]; + for (i = 1; i < 64;) { + switch (show_bits(gb, 3)) { case 4: block[perm[i++]] = 0; case 0: block[perm[i++]] = 0; - skip_bits(gb,3); + skip_bits(gb, 3); break; case 5: case 1: - skip_bits(gb,2); - value = get_bits(gb,6); - for(j=0; jqtable[perm[i]]; i++; break; case 2: - skip_bits(gb,3); + skip_bits(gb, 3); block[perm[i]] = s->qtable[perm[i]]; i++; break; case 7: // 111b case 3: // 011b - skip_bits(gb,2); - if (show_bits(gb,6)==0x3F) { + skip_bits(gb, 2); + if (show_bits(gb, 6) == 0x3F) { skip_bits(gb, 6); - block[perm[i]] = get_sbits(gb,8)*s->qtable[perm[i]]; - }else{ - block[perm[i]] = get_sbits(gb,6)*s->qtable[perm[i]]; + block[perm[i]] = get_sbits(gb, 8) * s->qtable[perm[i]]; + } else { + block[perm[i]] = get_sbits(gb, 6) * s->qtable[perm[i]]; } i++; break; } } - block[0] += 128<<4; + block[0] += 128 << 4; } -static void tgq_idct_put_mb(TgqContext *s, DCTELEM (*block)[64], int mb_x, int mb_y){ - int linesize= s->frame.linesize[0]; - uint8_t *dest_y = s->frame.data[0] + (mb_y * 16* linesize ) + mb_x * 16; - uint8_t *dest_cb = s->frame.data[1] + (mb_y * 8 * s->frame.linesize[1]) + mb_x * 8; - uint8_t *dest_cr = s->frame.data[2] + (mb_y * 8 * s->frame.linesize[2]) + mb_x * 8; +static void tgq_idct_put_mb(TgqContext *s, int16_t (*block)[64], + int mb_x, int mb_y) +{ + int linesize = s->frame.linesize[0]; + uint8_t *dest_y = s->frame.data[0] + (mb_y * 16 * linesize) + mb_x * 16; + uint8_t *dest_cb = s->frame.data[1] + (mb_y * 8 * s->frame.linesize[1]) + mb_x * 8; + uint8_t *dest_cr = s->frame.data[2] + (mb_y * 8 * s->frame.linesize[2]) + mb_x * 8; - ff_ea_idct_put_c(dest_y , linesize, block[0]); - ff_ea_idct_put_c(dest_y + 8, linesize, block[1]); - ff_ea_idct_put_c(dest_y + 8*linesize , linesize, block[2]); - ff_ea_idct_put_c(dest_y + 8*linesize + 8, linesize, block[3]); - if(!(s->avctx->flags&CODEC_FLAG_GRAY)){ + ff_ea_idct_put_c(dest_y , linesize, block[0]); + ff_ea_idct_put_c(dest_y + 8, linesize, block[1]); + ff_ea_idct_put_c(dest_y + 8 * linesize , linesize, block[2]); + ff_ea_idct_put_c(dest_y + 8 * linesize + 8, linesize, block[3]); + if (!(s->avctx->flags & CODEC_FLAG_GRAY)) { ff_ea_idct_put_c(dest_cb, s->frame.linesize[1], block[4]); ff_ea_idct_put_c(dest_cr, s->frame.linesize[2], block[5]); } } -static inline void tgq_dconly(TgqContext *s, unsigned char *dst, int dst_stride, int dc){ - int level = av_clip_uint8((dc*s->qtable[0] + 2056)>>4); +static inline void tgq_dconly(TgqContext *s, unsigned char *dst, + int dst_stride, int dc) +{ + int level = av_clip_uint8((dc*s->qtable[0] + 2056) >> 4); int j; - for(j=0;j<8;j++) - memset(dst+j*dst_stride, level, 8); + for (j = 0; j < 8; j++) + memset(dst + j * dst_stride, level, 8); } static void tgq_idct_put_mb_dconly(TgqContext *s, int mb_x, int mb_y, const int8_t *dc) { - int linesize= s->frame.linesize[0]; - uint8_t *dest_y = s->frame.data[0] + (mb_y * 16* linesize ) + mb_x * 16; - uint8_t *dest_cb = s->frame.data[1] + (mb_y * 8 * s->frame.linesize[1]) + mb_x * 8; - uint8_t *dest_cr = s->frame.data[2] + (mb_y * 8 * s->frame.linesize[2]) + mb_x * 8; - tgq_dconly(s,dest_y , linesize, dc[0]); - tgq_dconly(s,dest_y + 8, linesize, dc[1]); - tgq_dconly(s,dest_y + 8*linesize , linesize, dc[2]); - tgq_dconly(s,dest_y + 8*linesize + 8, linesize, dc[3]); - if(!(s->avctx->flags&CODEC_FLAG_GRAY)) { - tgq_dconly(s,dest_cb, s->frame.linesize[1], dc[4]); - tgq_dconly(s,dest_cr, s->frame.linesize[2], dc[5]); + int linesize = s->frame.linesize[0]; + uint8_t *dest_y = s->frame.data[0] + (mb_y * 16 * linesize) + mb_x * 16; + uint8_t *dest_cb = s->frame.data[1] + (mb_y * 8 * s->frame.linesize[1]) + mb_x * 8; + uint8_t *dest_cr = s->frame.data[2] + (mb_y * 8 * s->frame.linesize[2]) + mb_x * 8; + tgq_dconly(s, dest_y, linesize, dc[0]); + tgq_dconly(s, dest_y + 8, linesize, dc[1]); + tgq_dconly(s, dest_y + 8 * linesize, linesize, dc[2]); + tgq_dconly(s, dest_y + 8 * linesize + 8, linesize, dc[3]); + if (!(s->avctx->flags & CODEC_FLAG_GRAY)) { + tgq_dconly(s, dest_cb, s->frame.linesize[1], dc[4]); + tgq_dconly(s, dest_cr, s->frame.linesize[2], dc[5]); } } -/** - * @return <0 on error - */ -static int tgq_decode_mb(TgqContext *s, int mb_y, int mb_x){ +static int tgq_decode_mb(TgqContext *s, int mb_y, int mb_x) +{ int mode; int i; int8_t dc[6]; mode = bytestream2_get_byte(&s->gb); - if (mode>12) { + if (mode > 12) { GetBitContext gb; init_get_bits(&gb, s->gb.buffer, FFMIN(bytestream2_get_bytes_left(&s->gb), mode) * 8); - for(i=0; i<6; i++) + for (i = 0; i < 6; i++) tgq_decode_block(s, s->block[i], &gb); tgq_idct_put_mb(s, s->block, mb_x, mb_y); bytestream2_skip(&s->gb, mode); - }else{ - if (mode==3) { + } else { + if (mode == 3) { memset(dc, bytestream2_get_byte(&s->gb), 4); dc[4] = bytestream2_get_byte(&s->gb); dc[5] = bytestream2_get_byte(&s->gb); - }else if (mode==6) { + } else if (mode == 6) { bytestream2_get_buffer(&s->gb, dc, 6); - }else if (mode==12) { + } else if (mode == 12) { for (i = 0; i < 6; i++) { dc[i] = bytestream2_get_byte(&s->gb); bytestream2_skip(&s->gb, 1); } - }else{ + } else { av_log(s->avctx, AV_LOG_ERROR, "unsupported mb mode %i\n", mode); return -1; } @@ -179,27 +183,30 @@ static int tgq_decode_mb(TgqContext *s, int mb_y, int mb_x){ return 0; } -static void tgq_calculate_qtable(TgqContext *s, int quant){ - int i,j; - const int a = (14*(100-quant))/100 + 1; - const int b = (11*(100-quant))/100 + 4; - for(j=0;j<8;j++) - for(i=0;i<8;i++) - s->qtable[j*8+i] = ((a*(j+i)/(7+7) + b)*ff_inv_aanscales[j*8+i])>>(14-4); +static void tgq_calculate_qtable(TgqContext *s, int quant) +{ + int i, j; + const int a = (14 * (100 - quant)) / 100 + 1; + const int b = (11 * (100 - quant)) / 100 + 4; + for (j = 0; j < 8; j++) + for (i = 0; i < 8; i++) + s->qtable[j * 8 + i] = ((a * (j + i) / (7 + 7) + b) * + ff_inv_aanscales[j * 8 + i]) >> (14 - 4); } static int tgq_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, - AVPacket *avpkt){ + AVPacket *avpkt) +{ const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; - TgqContext *s = avctx->priv_data; - int x,y; + int buf_size = avpkt->size; + TgqContext *s = avctx->priv_data; + int x, y, ret; int big_endian; if (buf_size < 16) { av_log(avctx, AV_LOG_WARNING, "truncated header\n"); - return -1; + return AVERROR_INVALIDDATA; } big_endian = AV_RL32(&buf[4]) > 0x000FFFFF; bytestream2_init(&s->gb, buf + 8, buf_size - 8); @@ -223,9 +230,9 @@ static int tgq_decode_frame(AVCodecContext *avctx, s->frame.key_frame = 1; s->frame.pict_type = AV_PICTURE_TYPE_I; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; - if (ff_get_buffer(avctx, &s->frame)) { + if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } } @@ -240,7 +247,8 @@ static int tgq_decode_frame(AVCodecContext *avctx, return avpkt->size; } -static av_cold int tgq_decode_end(AVCodecContext *avctx){ +static av_cold int tgq_decode_end(AVCodecContext *avctx) +{ TgqContext *s = avctx->priv_data; if (s->frame.data[0]) s->avctx->release_buffer(avctx, &s->frame); diff --git a/mythtv/external/FFmpeg/libavcodec/eatgv.c b/mythtv/external/FFmpeg/libavcodec/eatgv.c index b105ea539c5..7092ba679b2 100644 --- a/mythtv/external/FFmpeg/libavcodec/eatgv.c +++ b/mythtv/external/FFmpeg/libavcodec/eatgv.c @@ -42,19 +42,20 @@ typedef struct TgvContext { AVFrame frame; AVFrame last_frame; int width,height; - unsigned int palette[AVPALETTE_COUNT]; + uint32_t palette[AVPALETTE_COUNT]; int (*mv_codebook)[2]; - unsigned char (*block_codebook)[16]; + uint8_t (*block_codebook)[16]; int num_mvs; ///< current length of mv_codebook int num_blocks_packed; ///< current length of block_codebook } TgvContext; -static av_cold int tgv_decode_init(AVCodecContext *avctx){ +static av_cold int tgv_decode_init(AVCodecContext *avctx) +{ TgvContext *s = avctx->priv_data; - s->avctx = avctx; + s->avctx = avctx; avctx->time_base = (AVRational){1, 15}; - avctx->pix_fmt = AV_PIX_FMT_PAL8; + avctx->pix_fmt = AV_PIX_FMT_PAL8; avcodec_get_frame_defaults(&s->frame); avcodec_get_frame_defaults(&s->last_frame); return 0; @@ -64,10 +65,12 @@ static av_cold int tgv_decode_init(AVCodecContext *avctx){ * Unpack buffer * @return 0 on success, -1 on critical buffer underflow */ -static int unpack(const uint8_t *src, const uint8_t *src_end, unsigned char *dst, int width, int height) { - unsigned char *dst_end = dst + width*height; +static int unpack(const uint8_t *src, const uint8_t *src_end, + uint8_t *dst, int width, int height) +{ + uint8_t *dst_end = dst + width*height; int size, size1, size2, offset, run; - unsigned char *dst_start = dst; + uint8_t *dst_start = dst; if (src[0] & 0x01) src += 5; @@ -75,56 +78,56 @@ static int unpack(const uint8_t *src, const uint8_t *src_end, unsigned char *dst src += 2; if (src_end - src < 3) - return -1; + return AVERROR_INVALIDDATA; size = AV_RB24(src); src += 3; - while(size>0 && src 0 && src < src_end) { /* determine size1 and size2 */ size1 = (src[0] & 3); - if ( src[0] & 0x80 ) { // 1 + if (src[0] & 0x80) { // 1 if (src[0] & 0x40 ) { // 11 - if ( src[0] & 0x20 ) { // 111 - if ( src[0] < 0xFC ) // !(111111) + if (src[0] & 0x20) { // 111 + if (src[0] < 0xFC) // !(111111) size1 = (((src[0] & 31) + 1) << 2); src++; size2 = 0; } else { // 110 offset = ((src[0] & 0x10) << 12) + AV_RB16(&src[1]) + 1; - size2 = ((src[0] & 0xC) << 6) + src[3] + 5; - src += 4; + size2 = ((src[0] & 0xC) << 6) + src[3] + 5; + src += 4; } } else { // 10 - size1 = ( ( src[1] & 0xC0) >> 6 ); + size1 = ((src[1] & 0xC0) >> 6); offset = (AV_RB16(&src[1]) & 0x3FFF) + 1; - size2 = (src[0] & 0x3F) + 4; - src += 3; + size2 = (src[0] & 0x3F) + 4; + src += 3; } } else { // 0 offset = ((src[0] & 0x60) << 3) + src[1] + 1; - size2 = ((src[0] & 0x1C) >> 2) + 3; - src += 2; + size2 = ((src[0] & 0x1C) >> 2) + 3; + src += 2; } /* fetch strip from src */ - if (size1>src_end-src) + if (size1 > src_end - src) break; - if (size1>0) { + if (size1 > 0) { size -= size1; - run = FFMIN(size1, dst_end-dst); + run = FFMIN(size1, dst_end - dst); memcpy(dst, src, run); dst += run; src += run; } - if (size2>0) { - if (dst-dst_start 0) { + if (dst - dst_start < offset) return 0; size -= size2; - run = FFMIN(size2, dst_end-dst); + run = FFMIN(size2, dst_end - dst); av_memcpy_backptr(dst, offset, run); dst += run; } @@ -137,7 +140,9 @@ static int unpack(const uint8_t *src, const uint8_t *src_end, unsigned char *dst * Decode inter-frame * @return 0 on success, -1 on critical buffer underflow */ -static int tgv_decode_inter(TgvContext * s, const uint8_t *buf, const uint8_t *buf_end){ +static int tgv_decode_inter(TgvContext *s, const uint8_t *buf, + const uint8_t *buf_end) +{ int num_mvs; int num_blocks_raw; int num_blocks_packed; @@ -145,10 +150,10 @@ static int tgv_decode_inter(TgvContext * s, const uint8_t *buf, const uint8_t *b int i,j,x,y; GetBitContext gb; int mvbits; - const unsigned char *blocks_raw; + const uint8_t *blocks_raw; if(buf_end - buf < 12) - return -1; + return AVERROR_INVALIDDATA; num_mvs = AV_RL16(&buf[0]); num_blocks_raw = AV_RL16(&buf[2]); @@ -169,75 +174,75 @@ static int tgv_decode_inter(TgvContext * s, const uint8_t *buf, const uint8_t *b } if (num_blocks_packed > s->num_blocks_packed) { - s->block_codebook = av_realloc(s->block_codebook, num_blocks_packed*16*sizeof(unsigned char)); + s->block_codebook = av_realloc(s->block_codebook, num_blocks_packed*16); s->num_blocks_packed = num_blocks_packed; } /* read motion vectors */ - mvbits = (num_mvs*2*10+31) & ~31; + mvbits = (num_mvs * 2 * 10 + 31) & ~31; - if (buf_end - buf < (mvbits>>3)+16*num_blocks_raw+8*num_blocks_packed) - return -1; + if (buf_end - buf < (mvbits>>3) + 16*num_blocks_raw + 8*num_blocks_packed) + return AVERROR_INVALIDDATA; init_get_bits(&gb, buf, mvbits); - for (i=0; imv_codebook[i][0] = get_sbits(&gb, 10); s->mv_codebook[i][1] = get_sbits(&gb, 10); } - buf += mvbits>>3; + buf += mvbits >> 3; /* note ptr to uncompressed blocks */ blocks_raw = buf; - buf += num_blocks_raw*16; + buf += num_blocks_raw * 16; /* read compressed blocks */ - init_get_bits(&gb, buf, (buf_end-buf)<<3); - for (i=0; iblock_codebook[i][15-j] = tmp[get_bits(&gb, 2)]; } if (get_bits_left(&gb) < vector_bits * - (s->avctx->height/4) * (s->avctx->width/4)) - return -1; + (s->avctx->height / 4) * (s->avctx->width / 4)) + return AVERROR_INVALIDDATA; /* read vectors and build frame */ - for(y=0; yavctx->height/4; y++) - for(x=0; xavctx->width/4; x++) { - unsigned int vector = get_bits(&gb, vector_bits); - const unsigned char *src; - int src_stride; - - if (vector < num_mvs) { - int mx = x * 4 + s->mv_codebook[vector][0]; - int my = y * 4 + s->mv_codebook[vector][1]; - - if ( mx < 0 || mx + 4 > s->avctx->width - || my < 0 || my + 4 > s->avctx->height) { - av_log(s->avctx, AV_LOG_ERROR, "MV %d %d out of picture\n", mx, my); - continue; - } + for (y = 0; y < s->avctx->height / 4; y++) + for (x = 0; x < s->avctx->width / 4; x++) { + unsigned int vector = get_bits(&gb, vector_bits); + const uint8_t *src; + int src_stride; + + if (vector < num_mvs) { + int mx = x * 4 + s->mv_codebook[vector][0]; + int my = y * 4 + s->mv_codebook[vector][1]; + + if (mx < 0 || mx + 4 > s->avctx->width || + my < 0 || my + 4 > s->avctx->height) { + av_log(s->avctx, AV_LOG_ERROR, "MV %d %d out of picture\n", mx, my); + continue; + } - src = s->last_frame.data[0] + mx + my * s->last_frame.linesize[0]; - src_stride = s->last_frame.linesize[0]; - }else{ - int offset = vector - num_mvs; - if (offsetblock_codebook[offset-num_blocks_raw]; - else - continue; - src_stride = 4; - } + src = s->last_frame.data[0] + mx + my * s->last_frame.linesize[0]; + src_stride = s->last_frame.linesize[0]; + } else { + int offset = vector - num_mvs; + if (offset < num_blocks_raw) + src = blocks_raw + 16*offset; + else if (offset - num_blocks_raw < num_blocks_packed) + src = s->block_codebook[offset - num_blocks_raw]; + else + continue; + src_stride = 4; + } - for(j=0; j<4; j++) - for(i=0; i<4; i++) - s->frame.data[0][ (y*4+j)*s->frame.linesize[0] + (x*4+i) ] = - src[j*src_stride + i]; + for (j = 0; j < 4; j++) + for (i = 0; i < 4; i++) + s->frame.data[0][(y * 4 + j) * s->frame.linesize[0] + (x * 4 + i)] = + src[j * src_stride + i]; } return 0; @@ -256,28 +261,28 @@ static int tgv_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; - TgvContext *s = avctx->priv_data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + TgvContext *s = avctx->priv_data; const uint8_t *buf_end = buf + buf_size; - int chunk_type; + int chunk_type, ret; if (buf_end - buf < EA_PREAMBLE_SIZE) return AVERROR_INVALIDDATA; chunk_type = AV_RL32(&buf[0]); - buf += EA_PREAMBLE_SIZE; + buf += EA_PREAMBLE_SIZE; - if (chunk_type==kVGT_TAG) { + if (chunk_type == kVGT_TAG) { int pal_count, i; if(buf_end - buf < 12) { av_log(avctx, AV_LOG_WARNING, "truncated header\n"); - return -1; + return AVERROR_INVALIDDATA; } s->width = AV_RL16(&buf[0]); s->height = AV_RL16(&buf[2]); - if (s->avctx->width!=s->width || s->avctx->height!=s->height) { + if (s->avctx->width != s->width || s->avctx->height != s->height) { avcodec_set_dimensions(s->avctx, s->width, s->height); cond_release_buffer(&s->frame); cond_release_buffer(&s->last_frame); @@ -285,14 +290,14 @@ static int tgv_decode_frame(AVCodecContext *avctx, pal_count = AV_RL16(&buf[6]); buf += 12; - for(i=0; i= 3; i++) { + for(i = 0; i < pal_count && i < AVPALETTE_COUNT && buf_end - buf >= 3; i++) { s->palette[i] = 0xFFU << 24 | AV_RB24(buf); buf += 3; } } - if (av_image_check_size(s->width, s->height, 0, avctx)) - return -1; + if ((ret = av_image_check_size(s->width, s->height, 0, avctx)) < 0) + return ret; /* shuffle */ FFSWAP(AVFrame, s->frame, s->last_frame); @@ -312,23 +317,23 @@ static int tgv_decode_frame(AVCodecContext *avctx, } memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE); - if(chunk_type==kVGT_TAG) { + if (chunk_type == kVGT_TAG) { s->frame.key_frame = 1; s->frame.pict_type = AV_PICTURE_TYPE_I; - if (unpack(buf, buf_end, s->frame.data[0], s->avctx->width, s->avctx->height)<0) { + if (unpack(buf, buf_end, s->frame.data[0], s->avctx->width, s->avctx->height) < 0) { av_log(avctx, AV_LOG_WARNING, "truncated intra frame\n"); - return -1; + return AVERROR_INVALIDDATA; } - }else{ + } else { if (!s->last_frame.data[0]) { av_log(avctx, AV_LOG_WARNING, "inter frame without corresponding intra frame\n"); return buf_size; } s->frame.key_frame = 0; s->frame.pict_type = AV_PICTURE_TYPE_P; - if (tgv_decode_inter(s, buf, buf_end)<0) { + if (tgv_decode_inter(s, buf, buf_end) < 0) { av_log(avctx, AV_LOG_WARNING, "truncated inter frame\n"); - return -1; + return AVERROR_INVALIDDATA; } } diff --git a/mythtv/external/FFmpeg/libavcodec/eatqi.c b/mythtv/external/FFmpeg/libavcodec/eatqi.c index 306331f3591..5513848a8e4 100644 --- a/mythtv/external/FFmpeg/libavcodec/eatqi.c +++ b/mythtv/external/FFmpeg/libavcodec/eatqi.c @@ -28,7 +28,6 @@ #include "avcodec.h" #include "get_bits.h" -#include "dsputil.h" #include "aandcttab.h" #include "eaidct.h" #include "internal.h" @@ -40,7 +39,7 @@ typedef struct TqiContext { AVFrame frame; void *bitstream_buf; unsigned int bitstream_buf_size; - DECLARE_ALIGNED(16, DCTELEM, block)[6][64]; + DECLARE_ALIGNED(16, int16_t, block)[6][64]; } TqiContext; static av_cold int tqi_decode_init(AVCodecContext *avctx) @@ -58,7 +57,7 @@ static av_cold int tqi_decode_init(AVCodecContext *avctx) return 0; } -static int tqi_decode_mb(MpegEncContext *s, DCTELEM (*block)[64]) +static int tqi_decode_mb(MpegEncContext *s, int16_t (*block)[64]) { int n; s->dsp.clear_blocks(block[0]); @@ -69,7 +68,7 @@ static int tqi_decode_mb(MpegEncContext *s, DCTELEM (*block)[64]) return 0; } -static inline void tqi_idct_put(TqiContext *t, DCTELEM (*block)[64]) +static inline void tqi_idct_put(TqiContext *t, int16_t (*block)[64]) { MpegEncContext *s = &t->s; int linesize= t->frame.linesize[0]; diff --git a/mythtv/external/FFmpeg/libavcodec/error_resilience.c b/mythtv/external/FFmpeg/libavcodec/error_resilience.c index 2b6bc42adef..70a800a7465 100644 --- a/mythtv/external/FFmpeg/libavcodec/error_resilience.c +++ b/mythtv/external/FFmpeg/libavcodec/error_resilience.c @@ -28,73 +28,21 @@ #include #include "avcodec.h" -#include "dsputil.h" +#include "error_resilience.h" #include "mpegvideo.h" -#include "h264.h" #include "rectangle.h" #include "thread.h" -/* - * H264 redefines mb_intra so it is not mistakely used (its uninitialized in h264) - * but error concealment must support both h264 and h263 thus we must undo this - */ -#undef mb_intra - -static void decode_mb(MpegEncContext *s, int ref) -{ - s->dest[0] = s->current_picture.f.data[0] + (s->mb_y * 16 * s->linesize) + s->mb_x * 16; - 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); - - ff_init_block_index(s); - ff_update_block_index(s); - s->dest[1] += (16 >> s->chroma_x_shift) - 8; - s->dest[2] += (16 >> s->chroma_x_shift) - 8; - - if (CONFIG_H264_DECODER && s->codec_id == AV_CODEC_ID_H264) { - H264Context *h = (void*)s; - h->mb_xy = s->mb_x + s->mb_y * s->mb_stride; - memset(h->non_zero_count_cache, 0, sizeof(h->non_zero_count_cache)); - av_assert1(ref >= 0); - /* FIXME: It is possible albeit uncommon that slice references - * differ between slices. We take the easy approach and ignore - * it for now. If this turns out to have any relevance in - * practice then correct remapping should be added. */ - if (ref >= h->ref_count[0]) - ref = 0; - if (!h->ref_list[0][ref].f.data[0]) { - av_log(s->avctx, AV_LOG_DEBUG, "Reference not available for error concealing\n"); - ref = 0; - } - if ((h->ref_list[0][ref].f.reference&3) != 3) { - av_log(s->avctx, AV_LOG_DEBUG, "Reference invalid\n"); - return; - } - fill_rectangle(&s->current_picture.f.ref_index[0][4 * h->mb_xy], - 2, 2, 2, ref, 1); - fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1); - fill_rectangle(h->mv_cache[0][scan8[0]], 4, 4, 8, - pack16to32(s->mv[0][0][0], s->mv[0][0][1]), 4); - h->mb_mbaff = - h->mb_field_decoding_flag = 0; - ff_h264_hl_decode_mb(h); - } else { - assert(ref == 0); - ff_MPV_decode_mb(s, s->block); - } -} - /** * @param stride the number of MVs to get to the next row * @param mv_step the number of MVs per row or column in a macroblock */ -static void set_mv_strides(MpegEncContext *s, int *mv_step, int *stride) +static void set_mv_strides(ERContext *s, int *mv_step, int *stride) { - if (s->codec_id == AV_CODEC_ID_H264) { - H264Context *h = (void*)s; + if (s->avctx->codec_id == AV_CODEC_ID_H264) { av_assert0(s->quarter_sample); *mv_step = 4; - *stride = h->b_stride; + *stride = s->mb_width * 4; } else { *mv_step = 2; *stride = s->b8_stride; @@ -104,9 +52,10 @@ static void set_mv_strides(MpegEncContext *s, int *mv_step, int *stride) /** * Replace the current MB with a flat dc-only version. */ -static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, +static void put_dc(ERContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y) { + int *linesize = s->cur_pic->f.linesize; int dc, dcu, dcv, y, i; for (i = 0; i < 4; i++) { dc = s->dc_val[0][mb_x * 2 + (i & 1) + (mb_y * 2 + (i >> 1)) * s->b8_stride]; @@ -117,7 +66,7 @@ static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, for (y = 0; y < 8; y++) { int x; for (x = 0; x < 8; x++) - dest_y[x + (i & 1) * 8 + (y + (i >> 1) * 8) * s->linesize] = dc / 8; + dest_y[x + (i & 1) * 8 + (y + (i >> 1) * 8) * linesize[0]] = dc / 8; } } dcu = s->dc_val[1][mb_x + mb_y * s->mb_stride]; @@ -133,8 +82,8 @@ static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, for (y = 0; y < 8; y++) { int x; for (x = 0; x < 8; x++) { - dest_cb[x + y * s->uvlinesize] = dcu / 8; - dest_cr[x + y * s->uvlinesize] = dcv / 8; + dest_cb[x + y * linesize[1]] = dcu / 8; + dest_cr[x + y * linesize[2]] = dcv / 8; } } } @@ -180,7 +129,7 @@ static void filter181(int16_t *data, int width, int height, int stride) * @param w width in 8 pixel blocks * @param h height in 8 pixel blocks */ -static void guess_dc(MpegEncContext *s, int16_t *dc, int w, +static void guess_dc(ERContext *s, int16_t *dc, int w, int h, int stride, int is_luma) { int b_x, b_y; @@ -198,7 +147,7 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, for(b_x=0; b_x>is_luma) + (b_y>>is_luma)*s->mb_stride; int error_j= s->error_status_table[mb_index_j]; - int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); + int intra_j = IS_INTRA(s->cur_pic->f.mb_type[mb_index_j]); if(intra_j==0 || !(error_j&ER_DC_ERROR)){ color= dc[b_x + b_y*stride]; distance= b_x; @@ -211,7 +160,7 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, for(b_x=w-1; b_x>=0; b_x--){ int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride; int error_j= s->error_status_table[mb_index_j]; - int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); + int intra_j = IS_INTRA(s->cur_pic->f.mb_type[mb_index_j]); if(intra_j==0 || !(error_j&ER_DC_ERROR)){ color= dc[b_x + b_y*stride]; distance= b_x; @@ -226,7 +175,7 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, for(b_y=0; b_y>is_luma) + (b_y>>is_luma)*s->mb_stride; int error_j= s->error_status_table[mb_index_j]; - int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); + int intra_j = IS_INTRA(s->cur_pic->f.mb_type[mb_index_j]); if(intra_j==0 || !(error_j&ER_DC_ERROR)){ color= dc[b_x + b_y*stride]; distance= b_y; @@ -239,7 +188,7 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, for(b_y=h-1; b_y>=0; b_y--){ int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride; int error_j= s->error_status_table[mb_index_j]; - int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); + int intra_j = IS_INTRA(s->cur_pic->f.mb_type[mb_index_j]); if(intra_j==0 || !(error_j&ER_DC_ERROR)){ color= dc[b_x + b_y*stride]; distance= b_y; @@ -256,7 +205,7 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, mb_index = (b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride; error = s->error_status_table[mb_index]; - if (IS_INTER(s->current_picture.f.mb_type[mb_index])) + if (IS_INTER(s->cur_pic->f.mb_type[mb_index])) continue; // inter if (!(error & ER_DC_ERROR)) continue; // dc-ok @@ -283,7 +232,7 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, * @param w width in 8 pixel blocks * @param h height in 8 pixel blocks */ -static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, +static void h_block_filter(ERContext *s, uint8_t *dst, int w, int h, int stride, int is_luma) { int b_x, b_y, mvx_stride, mvy_stride; @@ -297,13 +246,13 @@ static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int y; int left_status = s->error_status_table[( b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride]; int right_status = s->error_status_table[((b_x + 1) >> is_luma) + (b_y >> is_luma) * s->mb_stride]; - int left_intra = IS_INTRA(s->current_picture.f.mb_type[( b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride]); - int right_intra = IS_INTRA(s->current_picture.f.mb_type[((b_x + 1) >> is_luma) + (b_y >> is_luma) * s->mb_stride]); + int left_intra = IS_INTRA(s->cur_pic->f.mb_type[( b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride]); + int right_intra = IS_INTRA(s->cur_pic->f.mb_type[((b_x + 1) >> is_luma) + (b_y >> is_luma) * s->mb_stride]); int left_damage = left_status & ER_MB_ERROR; int right_damage = right_status & ER_MB_ERROR; int offset = b_x * 8 + b_y * stride * 8; - int16_t *left_mv = s->current_picture.f.motion_val[0][mvy_stride * b_y + mvx_stride * b_x]; - int16_t *right_mv = s->current_picture.f.motion_val[0][mvy_stride * b_y + mvx_stride * (b_x + 1)]; + int16_t *left_mv = s->cur_pic->f.motion_val[0][mvy_stride * b_y + mvx_stride * b_x]; + int16_t *right_mv = s->cur_pic->f.motion_val[0][mvy_stride * b_y + mvx_stride * (b_x + 1)]; if (!(left_damage || right_damage)) continue; // both undamaged if ((!left_intra) && (!right_intra) && @@ -351,7 +300,7 @@ static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, * @param w width in 8 pixel blocks * @param h height in 8 pixel blocks */ -static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, +static void v_block_filter(ERContext *s, uint8_t *dst, int w, int h, int stride, int is_luma) { int b_x, b_y, mvx_stride, mvy_stride; @@ -365,14 +314,14 @@ static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int x; int top_status = s->error_status_table[(b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride]; int bottom_status = s->error_status_table[(b_x >> is_luma) + ((b_y + 1) >> is_luma) * s->mb_stride]; - int top_intra = IS_INTRA(s->current_picture.f.mb_type[(b_x >> is_luma) + ( b_y >> is_luma) * s->mb_stride]); - int bottom_intra = IS_INTRA(s->current_picture.f.mb_type[(b_x >> is_luma) + ((b_y + 1) >> is_luma) * s->mb_stride]); + int top_intra = IS_INTRA(s->cur_pic->f.mb_type[(b_x >> is_luma) + ( b_y >> is_luma) * s->mb_stride]); + int bottom_intra = IS_INTRA(s->cur_pic->f.mb_type[(b_x >> is_luma) + ((b_y + 1) >> is_luma) * s->mb_stride]); int top_damage = top_status & ER_MB_ERROR; int bottom_damage = bottom_status & ER_MB_ERROR; int offset = b_x * 8 + b_y * stride * 8; - int16_t *top_mv = s->current_picture.f.motion_val[0][mvy_stride * b_y + mvx_stride * b_x]; - int16_t *bottom_mv = s->current_picture.f.motion_val[0][mvy_stride * (b_y + 1) + mvx_stride * b_x]; + int16_t *top_mv = s->cur_pic->f.motion_val[0][mvy_stride * b_y + mvx_stride * b_x]; + int16_t *bottom_mv = s->cur_pic->f.motion_val[0][mvy_stride * (b_y + 1) + mvx_stride * b_x]; if (!(top_damage || bottom_damage)) continue; // both undamaged @@ -417,7 +366,7 @@ static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, } } -static void guess_mv(MpegEncContext *s) +static void guess_mv(ERContext *s) { uint8_t *fixed = s->er_temp_buffer; #define MV_FROZEN 3 @@ -437,7 +386,7 @@ static void guess_mv(MpegEncContext *s) int f = 0; int error = s->error_status_table[mb_xy]; - if (IS_INTRA(s->current_picture.f.mb_type[mb_xy])) + if (IS_INTRA(s->cur_pic->f.mb_type[mb_xy])) f = MV_FROZEN; // intra // FIXME check if (!(error & ER_MV_ERROR)) f = MV_FROZEN; // inter with undamaged MV @@ -445,13 +394,13 @@ static void guess_mv(MpegEncContext *s) fixed[mb_xy] = f; if (f == MV_FROZEN) num_avail++; - else if(s->last_picture.f.data[0] && s->last_picture.f.motion_val[0]){ + else if(s->last_pic->f.data[0] && s->last_pic->f.motion_val[0]){ const int mb_y= mb_xy / s->mb_stride; const int mb_x= mb_xy % s->mb_stride; const int mot_index= (mb_x + mb_y*mot_stride) * mot_step; - s->current_picture.f.motion_val[0][mot_index][0]= s->last_picture.f.motion_val[0][mot_index][0]; - s->current_picture.f.motion_val[0][mot_index][1]= s->last_picture.f.motion_val[0][mot_index][1]; - s->current_picture.f.ref_index[0][4*mb_xy] = s->last_picture.f.ref_index[0][4*mb_xy]; + s->cur_pic->f.motion_val[0][mot_index][0]= s->last_pic->f.motion_val[0][mot_index][0]; + s->cur_pic->f.motion_val[0][mot_index][1]= s->last_pic->f.motion_val[0][mot_index][1]; + s->cur_pic->f.ref_index[0][4*mb_xy] = s->last_pic->f.ref_index[0][4*mb_xy]; } } @@ -460,25 +409,17 @@ static void guess_mv(MpegEncContext *s) for (mb_y = 0; mb_y < s->mb_height; mb_y++) { for (mb_x = 0; mb_x < s->mb_width; mb_x++) { const int mb_xy = mb_x + mb_y * s->mb_stride; + int mv_dir = (s->last_pic && s->last_pic->f.data[0]) ? MV_DIR_FORWARD : MV_DIR_BACKWARD; - if (IS_INTRA(s->current_picture.f.mb_type[mb_xy])) + if (IS_INTRA(s->cur_pic->f.mb_type[mb_xy])) continue; if (!(s->error_status_table[mb_xy] & ER_MV_ERROR)) continue; - s->mv_dir = s->last_picture.f.data[0] ? MV_DIR_FORWARD - : MV_DIR_BACKWARD; - s->mb_intra = 0; - s->mv_type = MV_TYPE_16X16; - s->mb_skipped = 0; - - s->dsp.clear_blocks(s->block[0]); - - s->mb_x = mb_x; - s->mb_y = mb_y; s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; - decode_mb(s, 0); + s->decode_mb(s->opaque, 0, mv_dir, MV_TYPE_16X16, &s->mv, + mb_x, mb_y, 0, 0); } } return; @@ -511,8 +452,8 @@ static void guess_mv(MpegEncContext *s) if (fixed[mb_xy] == MV_FROZEN) continue; - av_assert1(!IS_INTRA(s->current_picture.f.mb_type[mb_xy])); - av_assert1(s->last_picture_ptr && s->last_picture_ptr->f.data[0]); + av_assert1(!IS_INTRA(s->cur_pic->f.mb_type[mb_xy])); + av_assert1(s->last_pic && s->last_pic->f.data[0]); j = 0; if (mb_x > 0 && fixed[mb_xy - 1] == MV_FROZEN) @@ -542,38 +483,38 @@ static void guess_mv(MpegEncContext *s) if (mb_x > 0 && fixed[mb_xy - 1]) { mv_predictor[pred_count][0] = - s->current_picture.f.motion_val[0][mot_index - mot_step][0]; + s->cur_pic->f.motion_val[0][mot_index - mot_step][0]; mv_predictor[pred_count][1] = - s->current_picture.f.motion_val[0][mot_index - mot_step][1]; + s->cur_pic->f.motion_val[0][mot_index - mot_step][1]; ref[pred_count] = - s->current_picture.f.ref_index[0][4 * (mb_xy - 1)]; + s->cur_pic->f.ref_index[0][4 * (mb_xy - 1)]; pred_count++; } if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) { mv_predictor[pred_count][0] = - s->current_picture.f.motion_val[0][mot_index + mot_step][0]; + s->cur_pic->f.motion_val[0][mot_index + mot_step][0]; mv_predictor[pred_count][1] = - s->current_picture.f.motion_val[0][mot_index + mot_step][1]; + s->cur_pic->f.motion_val[0][mot_index + mot_step][1]; ref[pred_count] = - s->current_picture.f.ref_index[0][4 * (mb_xy + 1)]; + s->cur_pic->f.ref_index[0][4 * (mb_xy + 1)]; pred_count++; } if (mb_y > 0 && fixed[mb_xy - mb_stride]) { mv_predictor[pred_count][0] = - s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][0]; + s->cur_pic->f.motion_val[0][mot_index - mot_stride * mot_step][0]; mv_predictor[pred_count][1] = - s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][1]; + s->cur_pic->f.motion_val[0][mot_index - mot_stride * mot_step][1]; ref[pred_count] = - s->current_picture.f.ref_index[0][4 * (mb_xy - s->mb_stride)]; + s->cur_pic->f.ref_index[0][4 * (mb_xy - s->mb_stride)]; pred_count++; } if (mb_y + 1current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][0]; + s->cur_pic->f.motion_val[0][mot_index + mot_stride * mot_step][0]; mv_predictor[pred_count][1] = - s->current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][1]; + s->cur_pic->f.motion_val[0][mot_index + mot_stride * mot_step][1]; ref[pred_count] = - s->current_picture.f.ref_index[0][4 * (mb_xy + s->mb_stride)]; + s->cur_pic->f.ref_index[0][4 * (mb_xy + s->mb_stride)]; pred_count++; } if (pred_count == 0) @@ -631,19 +572,19 @@ static void guess_mv(MpegEncContext *s) if (s->avctx->codec_id == AV_CODEC_ID_H264) { // FIXME } else { - ff_thread_await_progress(&s->last_picture_ptr->f, + ff_thread_await_progress(&s->last_pic->f, mb_y, 0); } - if (!s->last_picture.f.motion_val[0] || - !s->last_picture.f.ref_index[0]) + if (!s->last_pic->f.motion_val[0] || + !s->last_pic->f.ref_index[0]) goto skip_last_mv; - prev_x = s->last_picture.f.motion_val[0][mot_index][0]; - prev_y = s->last_picture.f.motion_val[0][mot_index][1]; - prev_ref = s->last_picture.f.ref_index[0][4 * mb_xy]; + prev_x = s->last_pic->f.motion_val[0][mot_index][0]; + prev_y = s->last_pic->f.motion_val[0][mot_index][1]; + prev_ref = s->last_pic->f.ref_index[0][4 * mb_xy]; } else { - prev_x = s->current_picture.f.motion_val[0][mot_index][0]; - prev_y = s->current_picture.f.motion_val[0][mot_index][1]; - prev_ref = s->current_picture.f.ref_index[0][4 * mb_xy]; + prev_x = s->cur_pic->f.motion_val[0][mot_index][0]; + prev_y = s->cur_pic->f.motion_val[0][mot_index][1]; + prev_ref = s->cur_pic->f.ref_index[0][4 * mb_xy]; } /* last MV */ @@ -653,54 +594,47 @@ static void guess_mv(MpegEncContext *s) pred_count++; skip_last_mv: - s->mv_dir = MV_DIR_FORWARD; - s->mb_intra = 0; - s->mv_type = MV_TYPE_16X16; - s->mb_skipped = 0; - - s->dsp.clear_blocks(s->block[0]); - - s->mb_x = mb_x; - s->mb_y = mb_y; for (j = 0; j < pred_count; j++) { + int *linesize = s->cur_pic->f.linesize; int score = 0; - uint8_t *src = s->current_picture.f.data[0] + - mb_x * 16 + mb_y * 16 * s->linesize; + uint8_t *src = s->cur_pic->f.data[0] + + mb_x * 16 + mb_y * 16 * linesize[0]; - s->current_picture.f.motion_val[0][mot_index][0] = + s->cur_pic->f.motion_val[0][mot_index][0] = s->mv[0][0][0] = mv_predictor[j][0]; - s->current_picture.f.motion_val[0][mot_index][1] = + s->cur_pic->f.motion_val[0][mot_index][1] = s->mv[0][0][1] = mv_predictor[j][1]; // predictor intra or otherwise not available if (ref[j] < 0) continue; - decode_mb(s, ref[j]); + s->decode_mb(s->opaque, ref[j], MV_DIR_FORWARD, + MV_TYPE_16X16, &s->mv, mb_x, mb_y, 0, 0); if (mb_x > 0 && fixed[mb_xy - 1]) { int k; for (k = 0; k < 16; k++) - score += FFABS(src[k * s->linesize - 1] - - src[k * s->linesize]); + score += FFABS(src[k * linesize[0] - 1] - + src[k * linesize[0]]); } if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) { int k; for (k = 0; k < 16; k++) - score += FFABS(src[k * s->linesize + 15] - - src[k * s->linesize + 16]); + score += FFABS(src[k * linesize[0] + 15] - + src[k * linesize[0] + 16]); } if (mb_y > 0 && fixed[mb_xy - mb_stride]) { int k; for (k = 0; k < 16; k++) - score += FFABS(src[k - s->linesize] - src[k]); + score += FFABS(src[k - linesize[0]] - src[k]); } if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride]) { int k; for (k = 0; k < 16; k++) - score += FFABS(src[k + s->linesize * 15] - - src[k + s->linesize * 16]); + score += FFABS(src[k + linesize[0] * 15] - + src[k + linesize[0] * 16]); } if (score <= best_score) { // <= will favor the last MV @@ -714,11 +648,12 @@ static void guess_mv(MpegEncContext *s) for (i = 0; i < mot_step; i++) for (j = 0; j < mot_step; j++) { - s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0]; - s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1]; + s->cur_pic->f.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0]; + s->cur_pic->f.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1]; } - decode_mb(s, ref[best_pred]); + s->decode_mb(s->opaque, ref[best_pred], MV_DIR_FORWARD, + MV_TYPE_16X16, &s->mv, mb_x, mb_y, 0, 0); if (s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y) { @@ -741,11 +676,11 @@ static void guess_mv(MpegEncContext *s) } } -static int is_intra_more_likely(MpegEncContext *s) +static int is_intra_more_likely(ERContext *s) { int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y; - if (!s->last_picture_ptr || !s->last_picture_ptr->f.data[0]) + if (!s->last_pic || !s->last_pic->f.data[0]) return 1; // no previous frame available -> use spatial prediction undamaged_count = 0; @@ -756,12 +691,8 @@ static int is_intra_more_likely(MpegEncContext *s) undamaged_count++; } - if (s->codec_id == AV_CODEC_ID_H264) { - H264Context *h = (void*) s; - if (h->list_count <= 0 || h->ref_count[0] <= 0 || - !h->ref_list[0][0].f.data[0]) - return 1; - } + if (s->avctx->codec_id == AV_CODEC_ID_H264 && s->ref_count <= 0) + return 1; if (undamaged_count < 5) return 0; // almost all MBs damaged -> use temporal prediction @@ -769,7 +700,7 @@ static int is_intra_more_likely(MpegEncContext *s) // prevent dsp.sad() check, that requires access to the image if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration && - s->pict_type == AV_PICTURE_TYPE_I) + s->cur_pic->f.pict_type == AV_PICTURE_TYPE_I) return 1; skip_amount = FFMAX(undamaged_count / 50, 1); // check only up to 50 MBs @@ -790,23 +721,26 @@ static int is_intra_more_likely(MpegEncContext *s) if ((j % skip_amount) != 0) continue; - if (s->pict_type == AV_PICTURE_TYPE_I) { - uint8_t *mb_ptr = s->current_picture.f.data[0] + - mb_x * 16 + mb_y * 16 * s->linesize; - uint8_t *last_mb_ptr = s->last_picture.f.data[0] + - mb_x * 16 + mb_y * 16 * s->linesize; + if (s->cur_pic->f.pict_type == AV_PICTURE_TYPE_I) { + int *linesize = s->cur_pic->f.linesize; + uint8_t *mb_ptr = s->cur_pic->f.data[0] + + mb_x * 16 + mb_y * 16 * linesize[0]; + uint8_t *last_mb_ptr = s->last_pic->f.data[0] + + mb_x * 16 + mb_y * 16 * linesize[0]; if (s->avctx->codec_id == AV_CODEC_ID_H264) { // FIXME } else { - ff_thread_await_progress(&s->last_picture_ptr->f, - mb_y, 0); + ff_thread_await_progress(&s->last_pic->f, mb_y, 0); } - is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr , s->linesize, 16); + is_intra_likely += s->dsp->sad[0](NULL, last_mb_ptr, mb_ptr, + linesize[0], 16); // FIXME need await_progress() here - is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize, 16); + is_intra_likely -= s->dsp->sad[0](NULL, last_mb_ptr, + last_mb_ptr + linesize[0] * 16, + linesize[0], 16); } else { - if (IS_INTRA(s->current_picture.f.mb_type[mb_xy])) + if (IS_INTRA(s->cur_pic->f.mb_type[mb_xy])) is_intra_likely++; else is_intra_likely--; @@ -817,9 +751,9 @@ static int is_intra_more_likely(MpegEncContext *s) return is_intra_likely > 0; } -void ff_er_frame_start(MpegEncContext *s) +void ff_er_frame_start(ERContext *s) { - if (!s->err_recognition) + if (!s->avctx->err_recognition) return; memset(s->error_status_table, ER_MB_ERROR | VP_START | ER_MB_END, @@ -835,7 +769,7 @@ void ff_er_frame_start(MpegEncContext *s) * @param status the status at the end (ER_MV_END, ER_AC_ERROR, ...), it is * assumed that no earlier end or error of the same type occurred */ -void ff_er_add_slice(MpegEncContext *s, int startx, int starty, +void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status) { const int start_i = av_clip(startx + starty * s->mb_width, 0, s->mb_num - 1); @@ -853,7 +787,7 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, return; } - if (!s->err_recognition) + if (!s->avctx->err_recognition) return; mask &= ~VP_START; @@ -893,7 +827,7 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, s->error_status_table[start_xy] |= VP_START; - if (start_xy > 0 && s->avctx->thread_count <= 1 && + if (start_xy > 0 && !(s->avctx->active_thread_type & FF_THREAD_SLICE) && s->avctx->skip_top * s->mb_width < start_i) { int prev_status = s->error_status_table[s->mb_index2xy[start_i - 1]]; @@ -903,43 +837,53 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, } } -void ff_er_frame_end(MpegEncContext *s) +void ff_er_frame_end(ERContext *s) { + int *linesize = s->cur_pic->f.linesize; int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error; int distance; int threshold_part[4] = { 100, 100, 100 }; int threshold = 50; int is_intra_likely; int size = s->b8_stride * 2 * s->mb_height; - Picture *pic = s->current_picture_ptr; /* We do not support ER of field pictures yet, * though it should not crash if enabled. */ - if (!s->err_recognition || s->error_count == 0 || s->avctx->lowres || + if (!s->avctx->err_recognition || s->error_count == 0 || + s->avctx->lowres || s->avctx->hwaccel || s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU || - s->picture_structure != PICT_FRAME || + !s->cur_pic || s->cur_pic->field_picture || s->error_count == 3 * s->mb_width * (s->avctx->skip_top + s->avctx->skip_bottom)) { return; - }; - - if ( s->picture_structure == PICT_FRAME - && s->current_picture.f.linesize[0] != s->current_picture_ptr->f.linesize[0]) { - av_log(s->avctx, AV_LOG_ERROR, "Error concealment not possible, frame not fully initialized\n"); - return; + } + if (s->last_pic) { + if (s->last_pic->f.width != s->cur_pic->f.width || + s->last_pic->f.height != s->cur_pic->f.height || + s->last_pic->f.format != s->cur_pic->f.format) { + av_log(s->avctx, AV_LOG_WARNING, "Cannot use previous picture in error concealment\n"); + s->last_pic = NULL; + } + } + if (s->next_pic) { + if (s->next_pic->f.width != s->cur_pic->f.width || + s->next_pic->f.height != s->cur_pic->f.height || + s->next_pic->f.format != s->cur_pic->f.format) { + av_log(s->avctx, AV_LOG_WARNING, "Cannot use next picture in error concealment\n"); + s->next_pic = NULL; + } } - if (s->current_picture.f.motion_val[0] == NULL) { + if (s->cur_pic->f.motion_val[0] == NULL) { av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n"); for (i = 0; i < 2; i++) { - pic->f.ref_index[i] = av_mallocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t)); - pic->motion_val_base[i] = av_mallocz((size + 4) * 2 * sizeof(uint16_t)); - pic->f.motion_val[i] = pic->motion_val_base[i] + 4; + s->cur_pic->f.ref_index[i] = av_mallocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t)); + s->cur_pic->motion_val_base[i] = av_mallocz((size + 4) * 2 * sizeof(uint16_t)); + s->cur_pic->f.motion_val[i] = s->cur_pic->motion_val_base[i] + 4; } - pic->f.motion_subsample_log2 = 3; - s->current_picture = *s->current_picture_ptr; + s->cur_pic->f.motion_subsample_log2 = 3; } if (s->avctx->debug & FF_DEBUG_ER) { @@ -1000,7 +944,7 @@ void ff_er_frame_end(MpegEncContext *s) } #endif /* handle missing slices */ - if (s->err_recognition & AV_EF_EXPLODE) { + if (s->avctx->err_recognition & AV_EF_EXPLODE) { int end_ok = 1; // FIXME + 100 hack @@ -1090,7 +1034,7 @@ void ff_er_frame_end(MpegEncContext *s) mv_error++; } av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors in %c frame\n", - dc_error, ac_error, mv_error, av_get_picture_type_char(s->pict_type)); + dc_error, ac_error, mv_error, av_get_picture_type_char(s->cur_pic->f.pict_type)); is_intra_likely = is_intra_more_likely(s); @@ -1102,25 +1046,28 @@ void ff_er_frame_end(MpegEncContext *s) continue; if (is_intra_likely) - s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4; + s->cur_pic->f.mb_type[mb_xy] = MB_TYPE_INTRA4x4; else - s->current_picture.f.mb_type[mb_xy] = MB_TYPE_16x16 | MB_TYPE_L0; + s->cur_pic->f.mb_type[mb_xy] = MB_TYPE_16x16 | MB_TYPE_L0; } // change inter to intra blocks if no reference frames are available - if (!s->last_picture.f.data[0] && !s->next_picture.f.data[0]) + if (!(s->last_pic && s->last_pic->f.data[0]) && + !(s->next_pic && s->next_pic->f.data[0])) for (i = 0; i < s->mb_num; i++) { const int mb_xy = s->mb_index2xy[i]; - if (!IS_INTRA(s->current_picture.f.mb_type[mb_xy])) - s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4; + if (!IS_INTRA(s->cur_pic->f.mb_type[mb_xy])) + s->cur_pic->f.mb_type[mb_xy] = MB_TYPE_INTRA4x4; } /* handle inter blocks with damaged AC */ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { for (mb_x = 0; mb_x < s->mb_width; mb_x++) { const int mb_xy = mb_x + mb_y * s->mb_stride; - const int mb_type = s->current_picture.f.mb_type[mb_xy]; - int dir = !s->last_picture.f.data[0]; + const int mb_type = s->cur_pic->f.mb_type[mb_xy]; + const int dir = !(s->last_pic && s->last_pic->f.data[0]); + const int mv_dir = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD; + int mv_type; error = s->error_status_table[mb_xy]; @@ -1131,38 +1078,33 @@ void ff_er_frame_end(MpegEncContext *s) if (!(error & ER_AC_ERROR)) continue; // undamaged inter - s->mv_dir = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD; - s->mb_intra = 0; - s->mb_skipped = 0; if (IS_8X8(mb_type)) { int mb_index = mb_x * 2 + mb_y * 2 * s->b8_stride; int j; - s->mv_type = MV_TYPE_8X8; + mv_type = MV_TYPE_8X8; for (j = 0; j < 4; j++) { - s->mv[0][j][0] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][0]; - s->mv[0][j][1] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][1]; + s->mv[0][j][0] = s->cur_pic->f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][0]; + s->mv[0][j][1] = s->cur_pic->f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][1]; } } else { - s->mv_type = MV_TYPE_16X16; - s->mv[0][0][0] = s->current_picture.f.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][0]; - s->mv[0][0][1] = s->current_picture.f.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][1]; + mv_type = MV_TYPE_16X16; + s->mv[0][0][0] = s->cur_pic->f.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][0]; + s->mv[0][0][1] = s->cur_pic->f.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][1]; } - s->dsp.clear_blocks(s->block[0]); - - s->mb_x = mb_x; - s->mb_y = mb_y; - decode_mb(s, 0 /* FIXME h264 partitioned slices need this set */); + s->decode_mb(s->opaque, 0 /* FIXME h264 partitioned slices need this set */, + mv_dir, mv_type, &s->mv, mb_x, mb_y, 0, 0); } } /* guess MVs */ - if (s->pict_type == AV_PICTURE_TYPE_B) { + if (s->cur_pic->f.pict_type == AV_PICTURE_TYPE_B) { for (mb_y = 0; mb_y < s->mb_height; mb_y++) { for (mb_x = 0; mb_x < s->mb_width; mb_x++) { int xy = mb_x * 2 + mb_y * 2 * s->b8_stride; const int mb_xy = mb_x + mb_y * s->mb_stride; - const int mb_type = s->current_picture.f.mb_type[mb_xy]; + const int mb_type = s->cur_pic->f.mb_type[mb_xy]; + int mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; error = s->error_status_table[mb_xy]; @@ -1173,28 +1115,22 @@ void ff_er_frame_end(MpegEncContext *s) if (!(error & ER_AC_ERROR)) continue; // undamaged inter - s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; - if (!s->last_picture.f.data[0]) - s->mv_dir &= ~MV_DIR_FORWARD; - if (!s->next_picture.f.data[0]) - s->mv_dir &= ~MV_DIR_BACKWARD; - s->mb_intra = 0; - s->mv_type = MV_TYPE_16X16; - s->mb_skipped = 0; + if (!(s->last_pic && s->last_pic->f.data[0])) + mv_dir &= ~MV_DIR_FORWARD; + if (!(s->next_pic && s->next_pic->f.data[0])) + mv_dir &= ~MV_DIR_BACKWARD; if (s->pp_time) { int time_pp = s->pp_time; int time_pb = s->pb_time; - if (s->avctx->codec_id == AV_CODEC_ID_H264) { - // FIXME - } else { - ff_thread_await_progress(&s->next_picture_ptr->f, mb_y, 0); - } - s->mv[0][0][0] = s->next_picture.f.motion_val[0][xy][0] * time_pb / time_pp; - s->mv[0][0][1] = s->next_picture.f.motion_val[0][xy][1] * time_pb / time_pp; - s->mv[1][0][0] = s->next_picture.f.motion_val[0][xy][0] * (time_pb - time_pp) / time_pp; - s->mv[1][0][1] = s->next_picture.f.motion_val[0][xy][1] * (time_pb - time_pp) / time_pp; + av_assert0(s->avctx->codec_id != AV_CODEC_ID_H264); + ff_thread_await_progress(&s->next_pic->f, mb_y, 0); + + s->mv[0][0][0] = s->next_pic->f.motion_val[0][xy][0] * time_pb / time_pp; + s->mv[0][0][1] = s->next_pic->f.motion_val[0][xy][1] * time_pb / time_pp; + s->mv[1][0][0] = s->next_pic->f.motion_val[0][xy][0] * (time_pb - time_pp) / time_pp; + s->mv[1][0][1] = s->next_pic->f.motion_val[0][xy][1] * (time_pb - time_pp) / time_pp; } else { s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; @@ -1202,10 +1138,8 @@ void ff_er_frame_end(MpegEncContext *s) s->mv[1][0][1] = 0; } - s->dsp.clear_blocks(s->block[0]); - s->mb_x = mb_x; - s->mb_y = mb_y; - decode_mb(s, 0); + s->decode_mb(s->opaque, 0, mv_dir, MV_TYPE_16X16, &s->mv, + mb_x, mb_y, 0, 0); } } } else @@ -1221,7 +1155,7 @@ void ff_er_frame_end(MpegEncContext *s) int16_t *dc_ptr; uint8_t *dest_y, *dest_cb, *dest_cr; const int mb_xy = mb_x + mb_y * s->mb_stride; - const int mb_type = s->current_picture.f.mb_type[mb_xy]; + const int mb_type = s->cur_pic->f.mb_type[mb_xy]; error = s->error_status_table[mb_xy]; @@ -1230,9 +1164,9 @@ void ff_er_frame_end(MpegEncContext *s) // if (error & ER_MV_ERROR) // continue; // inter data damaged FIXME is this good? - dest_y = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize; - dest_cb = s->current_picture.f.data[1] + mb_x * 8 + mb_y * 8 * s->uvlinesize; - dest_cr = s->current_picture.f.data[2] + mb_x * 8 + mb_y * 8 * s->uvlinesize; + dest_y = s->cur_pic->f.data[0] + mb_x * 16 + mb_y * 16 * linesize[0]; + dest_cb = s->cur_pic->f.data[1] + mb_x * 8 + mb_y * 8 * linesize[1]; + dest_cr = s->cur_pic->f.data[2] + mb_x * 8 + mb_y * 8 * linesize[2]; dc_ptr = &s->dc_val[0][mb_x * 2 + mb_y * 2 * s->b8_stride]; for (n = 0; n < 4; n++) { @@ -1241,7 +1175,7 @@ void ff_er_frame_end(MpegEncContext *s) int x; for (x = 0; x < 8; x++) dc += dest_y[x + (n & 1) * 8 + - (y + (n >> 1) * 8) * s->linesize]; + (y + (n >> 1) * 8) * linesize[0]]; } dc_ptr[(n & 1) + (n >> 1) * s->b8_stride] = (dc + 4) >> 3; } @@ -1250,8 +1184,8 @@ void ff_er_frame_end(MpegEncContext *s) for (y = 0; y < 8; y++) { int x; for (x = 0; x < 8; x++) { - dcu += dest_cb[x + y * s->uvlinesize]; - dcv += dest_cr[x + y * s->uvlinesize]; + dcu += dest_cb[x + y * linesize[1]]; + dcv += dest_cr[x + y * linesize[2]]; } } s->dc_val[1][mb_x + mb_y * s->mb_stride] = (dcu + 4) >> 3; @@ -1274,7 +1208,7 @@ void ff_er_frame_end(MpegEncContext *s) for (mb_x = 0; mb_x < s->mb_width; mb_x++) { uint8_t *dest_y, *dest_cb, *dest_cr; const int mb_xy = mb_x + mb_y * s->mb_stride; - const int mb_type = s->current_picture.f.mb_type[mb_xy]; + const int mb_type = s->cur_pic->f.mb_type[mb_xy]; error = s->error_status_table[mb_xy]; @@ -1283,9 +1217,9 @@ void ff_er_frame_end(MpegEncContext *s) if (!(error & ER_AC_ERROR)) continue; // undamaged - dest_y = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize; - dest_cb = s->current_picture.f.data[1] + mb_x * 8 + mb_y * 8 * s->uvlinesize; - dest_cr = s->current_picture.f.data[2] + mb_x * 8 + mb_y * 8 * s->uvlinesize; + dest_y = s->cur_pic->f.data[0] + mb_x * 16 + mb_y * 16 * linesize[0]; + dest_cb = s->cur_pic->f.data[1] + mb_x * 8 + mb_y * 8 * linesize[1]; + dest_cr = s->cur_pic->f.data[2] + mb_x * 8 + mb_y * 8 * linesize[2]; put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y); } @@ -1294,20 +1228,20 @@ void ff_er_frame_end(MpegEncContext *s) if (s->avctx->error_concealment & FF_EC_DEBLOCK) { /* filter horizontal block boundaries */ - h_block_filter(s, s->current_picture.f.data[0], s->mb_width * 2, - s->mb_height * 2, s->linesize, 1); - h_block_filter(s, s->current_picture.f.data[1], s->mb_width, - s->mb_height , s->uvlinesize, 0); - h_block_filter(s, s->current_picture.f.data[2], s->mb_width, - s->mb_height , s->uvlinesize, 0); + h_block_filter(s, s->cur_pic->f.data[0], s->mb_width * 2, + s->mb_height * 2, linesize[0], 1); + h_block_filter(s, s->cur_pic->f.data[1], s->mb_width, + s->mb_height, linesize[1], 0); + h_block_filter(s, s->cur_pic->f.data[2], s->mb_width, + s->mb_height, linesize[2], 0); /* filter vertical block boundaries */ - v_block_filter(s, s->current_picture.f.data[0], s->mb_width * 2, - s->mb_height * 2, s->linesize, 1); - v_block_filter(s, s->current_picture.f.data[1], s->mb_width, - s->mb_height , s->uvlinesize, 0); - v_block_filter(s, s->current_picture.f.data[2], s->mb_width, - s->mb_height , s->uvlinesize, 0); + v_block_filter(s, s->cur_pic->f.data[0], s->mb_width * 2, + s->mb_height * 2, linesize[0], 1); + v_block_filter(s, s->cur_pic->f.data[1], s->mb_width, + s->mb_height, linesize[1], 0); + v_block_filter(s, s->cur_pic->f.data[2], s->mb_width, + s->mb_height, linesize[2], 0); } ec_clean: @@ -1316,10 +1250,13 @@ void ff_er_frame_end(MpegEncContext *s) const int mb_xy = s->mb_index2xy[i]; int error = s->error_status_table[mb_xy]; - if (s->pict_type != AV_PICTURE_TYPE_B && + if (s->cur_pic->f.pict_type != AV_PICTURE_TYPE_B && (error & (ER_DC_ERROR | ER_MV_ERROR | ER_AC_ERROR))) { s->mbskip_table[mb_xy] = 0; } s->mbintra_table[mb_xy] = 1; } + s->cur_pic = NULL; + s->next_pic = NULL; + s->last_pic = NULL; } diff --git a/mythtv/external/FFmpeg/libavcodec/error_resilience.h b/mythtv/external/FFmpeg/libavcodec/error_resilience.h new file mode 100644 index 00000000000..970fdc20665 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/error_resilience.h @@ -0,0 +1,79 @@ +/* + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_ERROR_RESILIENCE_H +#define AVCODEC_ERROR_RESILIENCE_H + +#include + +#include "avcodec.h" +#include "dsputil.h" + +///< current MB is the first after a resync marker +#define VP_START 1 +#define ER_AC_ERROR 2 +#define ER_DC_ERROR 4 +#define ER_MV_ERROR 8 +#define ER_AC_END 16 +#define ER_DC_END 32 +#define ER_MV_END 64 + +#define ER_MB_ERROR (ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR) +#define ER_MB_END (ER_AC_END|ER_DC_END|ER_MV_END) + +typedef struct ERContext { + AVCodecContext *avctx; + DSPContext *dsp; + + int *mb_index2xy; + int mb_num; + int mb_width, mb_height; + int mb_stride; + int b8_stride; + + int error_count, error_occurred; + uint8_t *error_status_table; + uint8_t *er_temp_buffer; + int16_t *dc_val[3]; + uint8_t *mbskip_table; + uint8_t *mbintra_table; + int mv[2][4][2]; + + struct Picture *cur_pic; + struct Picture *last_pic; + struct Picture *next_pic; + + uint16_t pp_time; + uint16_t pb_time; + int quarter_sample; + int partitioned_frame; + int ref_count; + + void (*decode_mb)(void *opaque, int ref, int mv_dir, int mv_type, + int (*mv)[2][4][2], + int mb_x, int mb_y, int mb_intra, int mb_skipped); + void *opaque; +} ERContext; + +void ff_er_frame_start(ERContext *s); +void ff_er_frame_end(ERContext *s); +void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, + int status); + +#endif /* AVCODEC_ERROR_RESILIENCE_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/evrcdata.h b/mythtv/external/FFmpeg/libavcodec/evrcdata.h new file mode 100644 index 00000000000..cde1f571d8a --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/evrcdata.h @@ -0,0 +1,1499 @@ +/* + * Enhanced Variable Rate Codec, Service Option 3 decoder + * Copyright (c) 2013 Paul B Mahol + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_EVRCDATA_H +#define AVCODEC_EVRCDATA_H + +/** + * @file + * Data tables for the EVRC decoder + * @author Paul B Mahol + */ + +#include "libavutil/common.h" + +/** + * Rate 1/8 frame energy quantization + * + * TIA/IS-127 table 8-18 + */ +static const float evrc_energy_quant[][3] = { +{-0.2464E-01,-0.4005E-02,-0.1107E+00 }, { 0.8734E+00, 0.1004E+01, 0.9930E+00 }, +{ 0.4222E+00, 0.3894E+00, 0.5020E+00 }, { 0.1450E+01, 0.1328E+01, 0.1278E+01 }, +{ 0.1957E+00, 0.2169E+00, 0.2735E+00 }, { 0.1142E+01, 0.1240E+01, 0.1157E+01 }, +{ 0.7881E+00, 0.6778E+00, 0.4185E+00 }, { 0.1504E+01, 0.1468E+01, 0.1534E+01 }, +{ 0.3173E+00, 0.2693E+00,-0.9526E-01 }, { 0.1141E+01, 0.1154E+01, 0.1044E+01 }, +{ 0.5147E+00, 0.5784E+00, 0.8802E+00 }, { 0.1502E+01, 0.1407E+01, 0.1409E+01 }, +{ 0.3163E+00, 0.3592E+00, 0.2830E+00 }, { 0.1217E+01, 0.1213E+01, 0.1216E+01 }, +{ 0.1023E+01, 0.1139E+01,-0.9526E-01 }, { 0.1619E+01, 0.1655E+01, 0.1642E+01 }, +{ 0.1437E+00, 0.1505E+00, 0.6838E-01 }, { 0.9794E+00, 0.1021E+01, 0.1117E+01 }, +{ 0.4701E+00, 0.6426E+00, 0.5519E+00 }, { 0.1366E+01, 0.1397E+01, 0.1406E+01 }, +{ 0.2918E+00, 0.3022E+00, 0.2420E+00 }, { 0.1309E+01, 0.1241E+01, 0.1220E+01 }, +{ 0.7989E+00, 0.7654E+00, 0.7391E+00 }, { 0.1612E+01, 0.1502E+01, 0.1447E+01 }, +{ 0.2594E+00, 0.1948E+00, 0.2555E+00 }, { 0.1091E+01, 0.1150E+01, 0.1272E+01 }, +{ 0.3423E+00, 0.4150E+00, 0.1294E+01 }, { 0.1729E+01, 0.1377E+01, 0.1065E+01 }, +{ 0.4103E+00, 0.3287E+00, 0.3228E+00 }, { 0.1144E+01, 0.1281E+01, 0.1416E+01 }, +{ 0.1047E+01, 0.1117E+01, 0.6188E+00 }, { 0.1914E+01, 0.1777E+01, 0.1516E+01 }, +{-0.2117E-01, 0.2159E+00, 0.2351E+00 }, { 0.1093E+01, 0.1088E+01, 0.1026E+01 }, +{ 0.5567E+00, 0.5092E+00, 0.4654E+00 }, { 0.1510E+01, 0.1449E+01, 0.1201E+01 }, +{ 0.2362E+00, 0.3426E+00, 0.2549E+00 }, { 0.1340E+01, 0.1225E+01, 0.1117E+01 }, +{ 0.1203E+01, 0.3819E+00, 0.2269E+00 }, { 0.1373E+01, 0.1404E+01, 0.1830E+01 }, +{ 0.2570E+00, 0.2668E+00, 0.1636E+00 }, { 0.1219E+01, 0.1098E+01, 0.1122E+01 }, +{ 0.6985E+00, 0.8456E+00, 0.1069E+01 }, { 0.1550E+01, 0.1501E+01, 0.1388E+01 }, +{ 0.2870E+00, 0.3060E+00, 0.3599E+00 }, { 0.1178E+01, 0.1345E+01, 0.1302E+01 }, +{ 0.1270E+01, 0.1215E+01, 0.1812E+00 }, { 0.1725E+01, 0.1777E+01, 0.1693E+01 }, +{ 0.2074E+00, 0.2104E+00, 0.1539E+00 }, { 0.1105E+01, 0.1034E+01, 0.1104E+01 }, +{ 0.6683E+00, 0.6646E+00, 0.6639E+00 }, { 0.1403E+01, 0.1462E+01, 0.1435E+01 }, +{ 0.3389E+00, 0.3754E+00, 0.2150E+00 }, { 0.1288E+01, 0.1325E+01, 0.1257E+01 }, +{ 0.8933E+00, 0.8253E+00, 0.8133E+00 }, { 0.1555E+01, 0.1579E+01, 0.1565E+01 }, +{ 0.3264E+00, 0.2434E+00, 0.2852E+00 }, { 0.1242E+01, 0.1180E+01, 0.1202E+01 }, +{ 0.1314E+00, 0.1698E+00, 0.1646E+01 }, { 0.1797E+01, 0.1597E+01, 0.1241E+01 }, +{ 0.4721E+00, 0.5346E+00, 0.3066E+00 }, { 0.1274E+01, 0.1401E+01, 0.1351E+01 }, +{ 0.1455E+01, 0.1386E+01, 0.6430E+00 }, { 0.1828E+01, 0.1867E+01, 0.1825E+01 }, +{-0.3265E+00,-0.2956E+00,-0.2462E+00 }, { 0.1035E+01, 0.1020E+01, 0.1003E+01 }, +{ 0.3702E+00, 0.4307E+00, 0.7072E+00 }, { 0.1424E+01, 0.1345E+01, 0.1352E+01 }, +{ 0.2267E+00, 0.2680E+00, 0.3037E+00 }, { 0.1235E+01, 0.1249E+01, 0.1146E+01 }, +{ 0.9944E+00, 0.6485E+00, 0.5248E+00 }, { 0.1539E+01, 0.1492E+01, 0.1612E+01 }, +{ 0.3815E+00, 0.3360E+00,-0.9526E-01 }, { 0.1163E+01, 0.1144E+01, 0.1117E+01 }, +{ 0.6734E+00, 0.7656E+00, 0.1014E+01 }, { 0.1568E+01, 0.1438E+01, 0.1455E+01 }, +{ 0.3409E+00, 0.3317E+00, 0.3856E+00 }, { 0.1180E+01, 0.1284E+01, 0.1284E+01 }, +{ 0.1244E+01, 0.1214E+01,-0.9526E-01 }, { 0.1753E+01, 0.1598E+01, 0.1744E+01 }, +{ 0.1548E+00, 0.1388E+00, 0.2020E+00 }, { 0.1027E+01, 0.1133E+01, 0.1093E+01 }, +{ 0.3906E+00, 0.7505E+00, 0.5705E+00 }, { 0.1420E+01, 0.1357E+01, 0.1543E+01 }, +{ 0.3252E+00, 0.3136E+00, 0.2804E+00 }, { 0.1351E+01, 0.1309E+01, 0.1224E+01 }, +{ 0.8781E+00, 0.8095E+00, 0.7109E+00 }, { 0.1614E+01, 0.1580E+01, 0.1433E+01 }, +{ 0.3222E+00, 0.2298E+00, 0.2157E+00 }, { 0.1216E+01, 0.1077E+01, 0.1247E+01 }, +{ 0.1363E+01, 0.1280E+01, 0.1317E+01 }, { 0.1751E+01, 0.1457E+01, 0.1182E+01 }, +{ 0.4428E+00, 0.4082E+00, 0.3181E+00 }, { 0.1157E+01, 0.1227E+01, 0.1604E+01 }, +{ 0.1286E+01, 0.1268E+01, 0.8167E+00 }, { 0.1994E+01, 0.2018E+01, 0.1307E+01 }, +{ 0.2671E-01, 0.2594E+00, 0.3397E+00 }, { 0.1164E+01, 0.1080E+01, 0.9321E+00 }, +{ 0.5998E+00, 0.6076E+00, 0.5081E+00 }, { 0.1442E+01, 0.1442E+01, 0.1375E+01 }, +{ 0.2390E+00, 0.3554E+00, 0.3426E+00 }, { 0.1287E+01, 0.1307E+01, 0.1144E+01 }, +{ 0.1200E+01, 0.7495E+00, 0.3967E+00 }, { 0.1561E+01, 0.1517E+01, 0.1898E+01 }, +{ 0.3598E+00, 0.3463E+00, 0.1200E+00 }, { 0.1298E+01, 0.1125E+01, 0.1062E+01 }, +{ 0.7577E+00, 0.1013E+01, 0.1194E+01 }, { 0.1537E+01, 0.1513E+01, 0.1464E+01 }, +{ 0.4041E+00, 0.4038E+00, 0.3897E+00 }, { 0.1293E+01, 0.1219E+01, 0.1378E+01 }, +{ 0.1250E+01, 0.1391E+01, 0.2451E+00 }, { 0.1558E+01, 0.1764E+01, 0.1728E+01 }, +{ 0.2700E+00, 0.1894E+00, 0.1924E+00 }, { 0.1111E+01, 0.1112E+01, 0.1173E+01 }, +{ 0.7579E+00, 0.8342E+00, 0.4781E+00 }, { 0.1464E+01, 0.1477E+01, 0.1469E+01 }, +{ 0.4001E+00, 0.3104E+00, 0.2217E+00 }, { 0.1346E+01, 0.1421E+01, 0.1312E+01 }, +{ 0.1071E+01, 0.8967E+00, 0.7511E+00 }, { 0.1616E+01, 0.1551E+01, 0.1574E+01 }, +{ 0.3329E+00, 0.2785E+00, 0.3140E+00 }, { 0.1281E+01, 0.1209E+01, 0.1239E+01 }, +{ 0.2805E+00, 0.2687E+00, 0.1646E+01 }, { 0.1814E+01, 0.1514E+01, 0.1510E+01 }, +{ 0.6231E+00, 0.4200E+00, 0.3701E+00 }, { 0.1255E+01, 0.1429E+01, 0.1454E+01 }, +{ 0.1642E+01, 0.1581E+01, 0.7112E+00 }, { 0.1844E+01, 0.1963E+01, 0.1895E+01 }, +{-0.4208E-01,-0.1491E+00,-0.7639E-01 }, { 0.1046E+01, 0.9598E+00, 0.9176E+00 }, +{ 0.4478E+00, 0.4605E+00, 0.5111E+00 }, { 0.1521E+01, 0.1292E+01, 0.1342E+01 }, +{ 0.2220E+00, 0.2549E+00, 0.2510E+00 }, { 0.1186E+01, 0.1254E+01, 0.1171E+01 }, +{ 0.8999E+00, 0.4960E+00, 0.4943E+00 }, { 0.1423E+01, 0.1484E+01, 0.1620E+01 }, +{ 0.2796E+00, 0.2778E+00,-0.2820E+00 }, { 0.1170E+01, 0.1181E+01, 0.1076E+01 }, +{ 0.4068E+00, 0.8541E+00, 0.9352E+00 }, { 0.1584E+01, 0.1416E+01, 0.1387E+01 }, +{ 0.3325E+00, 0.3655E+00, 0.3340E+00 }, { 0.1224E+01, 0.1257E+01, 0.1245E+01 }, +{ 0.1061E+01, 0.1138E+01,-0.9526E-01 }, { 0.1681E+01, 0.1704E+01, 0.1673E+01 }, +{ 0.1932E+00, 0.1489E+00, 0.1258E+00 }, { 0.1023E+01, 0.1088E+01, 0.1145E+01 }, +{ 0.5190E+00, 0.6873E+00, 0.5172E+00 }, { 0.1380E+01, 0.1405E+01, 0.1474E+01 }, +{ 0.3393E+00, 0.3100E+00, 0.2231E+00 }, { 0.1354E+01, 0.1249E+01, 0.1270E+01 }, +{ 0.7363E+00, 0.8508E+00, 0.8247E+00 }, { 0.1612E+01, 0.1537E+01, 0.1509E+01 }, +{ 0.2952E+00, 0.2053E+00, 0.2590E+00 }, { 0.1138E+01, 0.1219E+01, 0.1262E+01 }, +{ 0.1345E+01, 0.1289E+01, 0.1338E+01 }, { 0.1437E+01, 0.1360E+01, 0.1442E+01 }, +{ 0.4826E+00, 0.3298E+00, 0.3842E+00 }, { 0.1219E+01, 0.1311E+01, 0.1413E+01 }, +{ 0.1212E+01, 0.1186E+01, 0.6357E+00 }, { 0.1873E+01, 0.1939E+01, 0.1674E+01 }, +{ 0.1260E+01, 0.1306E+01, 0.1368E+01 }, { 0.1146E+01, 0.1077E+01, 0.1025E+01 }, +{ 0.6029E+00, 0.5039E+00, 0.5781E+00 }, { 0.1514E+01, 0.1420E+01, 0.1324E+01 }, +{ 0.2652E+00, 0.3192E+00, 0.3042E+00 }, { 0.1368E+01, 0.1198E+01, 0.1200E+01 }, +{ 0.1234E+01, 0.4910E+00, 0.3464E-01 }, { 0.1347E+01, 0.1560E+01, 0.1861E+01 }, +{ 0.2766E+00, 0.2887E+00, 0.2029E+00 }, { 0.1257E+01, 0.1105E+01, 0.1145E+01 }, +{ 0.1351E+01, 0.1353E+01, 0.1406E+01 }, { 0.1506E+01, 0.1580E+01, 0.1362E+01 }, +{ 0.2794E+00, 0.3868E+00, 0.4277E+00 }, { 0.1234E+01, 0.1334E+01, 0.1336E+01 }, +{ 0.1280E+01, 0.1252E+01, 0.1805E+00 }, { 0.1387E+01, 0.1396E+01, 0.1434E+01 }, +{ 0.2902E+00, 0.1170E+00, 0.1698E+00 }, { 0.1134E+01, 0.1077E+01, 0.1117E+01 }, +{ 0.6986E+00, 0.7177E+00, 0.7366E+00 }, { 0.1370E+01, 0.1491E+01, 0.1495E+01 }, +{ 0.4031E+00, 0.5144E+00, 0.1751E+00 }, { 0.1333E+01, 0.1377E+01, 0.1257E+01 }, +{ 0.9212E+00, 0.8934E+00, 0.8897E+00 }, { 0.1589E+01, 0.1614E+01, 0.1523E+01 }, +{ 0.3152E+00, 0.2164E+00, 0.3230E+00 }, { 0.1300E+01, 0.1145E+01, 0.1212E+01 }, +{ 0.1269E+01, 0.1245E+01, 0.1497E+01 }, { 0.1763E+01, 0.1716E+01, 0.1311E+01 }, +{ 0.4702E+00, 0.5422E+00, 0.4306E+00 }, { 0.1342E+01, 0.1433E+01, 0.1423E+01 }, +{ 0.1472E+01, 0.1404E+01, 0.8371E+00 }, { 0.1936E+01, 0.1883E+01, 0.1838E+01 }, +{ 0.1266E+01, 0.1295E+01, 0.1302E+01 }, { 0.1074E+01, 0.1002E+01, 0.1023E+01 }, +{ 0.5206E+00, 0.4045E+00, 0.6549E+00 }, { 0.1457E+01, 0.1378E+01, 0.1363E+01 }, +{ 0.2715E+00, 0.2629E+00, 0.2841E+00 }, { 0.1264E+01, 0.1271E+01, 0.1175E+01 }, +{ 0.1337E+01, 0.1305E+01, 0.1306E+01 }, { 0.1555E+01, 0.1571E+01, 0.1657E+01 }, +{ 0.3341E+00, 0.4147E+00,-0.3648E+00 }, { 0.1188E+01, 0.1185E+01, 0.1161E+01 }, +{ 0.6198E+00, 0.7208E+00, 0.1157E+01 }, { 0.1582E+01, 0.1465E+01, 0.1513E+01 }, +{ 0.3839E+00, 0.3651E+00, 0.3814E+00 }, { 0.1214E+01, 0.1256E+01, 0.1292E+01 }, +{ 0.1361E+01, 0.1363E+01, 0.1312E+01 }, { 0.1793E+01, 0.1693E+01, 0.1669E+01 }, +{ 0.1889E+00, 0.1275E+00, 0.2534E+00 }, { 0.1066E+01, 0.1174E+01, 0.1133E+01 }, +{ 0.4999E+00, 0.8207E+00, 0.5813E+00 }, { 0.1478E+01, 0.1416E+01, 0.1497E+01 }, +{ 0.3814E+00, 0.3138E+00, 0.2889E+00 }, { 0.1396E+01, 0.1265E+01, 0.1233E+01 }, +{ 0.9458E+00, 0.9161E+00, 0.5875E+00 }, { 0.1672E+01, 0.1632E+01, 0.1553E+01 }, +{ 0.3505E+00, 0.2525E+00, 0.2364E+00 }, { 0.1211E+01, 0.1138E+01, 0.1235E+01 }, +{ 0.1391E+01, 0.1231E+01, 0.1355E+01 }, { 0.1783E+01, 0.1510E+01, 0.1199E+01 }, +{ 0.4227E+00, 0.4548E+00, 0.3671E+00 }, { 0.1281E+01, 0.1254E+01, 0.1661E+01 }, +{ 0.1338E+01, 0.1379E+01, 0.9531E+00 }, { 0.2148E+01, 0.1965E+01, 0.1584E+01 }, +{ 0.9324E-01, 0.3575E+00, 0.3522E+00 }, { 0.1212E+01, 0.1086E+01, 0.1044E+01 }, +{ 0.6128E+00, 0.6136E+00, 0.6060E+00 }, { 0.1484E+01, 0.1507E+01, 0.1396E+01 }, +{ 0.2820E+00, 0.3848E+00, 0.3156E+00 }, { 0.1368E+01, 0.1287E+01, 0.1128E+01 }, +{ 0.1369E+01, 0.1352E+01, 0.1358E+01 }, { 0.1381E+01, 0.1765E+01, 0.2113E+01 }, +{ 0.1314E+01, 0.1345E+01, 0.1334E+01 }, { 0.1290E+01, 0.1172E+01, 0.1119E+01 }, +{ 0.1304E+01, 0.1377E+01, 0.1427E+01 }, { 0.1490E+01, 0.1540E+01, 0.1536E+01 }, +{ 0.3994E+00, 0.4402E+00, 0.4173E+00 }, { 0.1323E+01, 0.1307E+01, 0.1392E+01 }, +{ 0.1400E+01, 0.1388E+01, 0.1369E+01 }, { 0.1669E+01, 0.1818E+01, 0.1834E+01 }, +{ 0.2742E+00, 0.2235E+00, 0.1986E+00 }, { 0.1137E+01, 0.1139E+01, 0.1201E+01 }, +{ 0.1324E+01, 0.1385E+01, 0.1349E+01 }, { 0.1455E+01, 0.1574E+01, 0.1454E+01 }, +{ 0.5019E+00, 0.3255E+00, 0.2555E+00 }, { 0.1388E+01, 0.1438E+01, 0.1300E+01 }, +{ 0.1394E+01, 0.1349E+01, 0.1411E+01 }, { 0.1639E+01, 0.1580E+01, 0.1681E+01 }, +{ 0.3920E+00, 0.2498E+00, 0.3523E+00 }, { 0.1301E+01, 0.1221E+01, 0.1285E+01 }, +{ 0.1318E+01, 0.1342E+01, 0.1494E+01 }, { 0.1910E+01, 0.1680E+01, 0.1470E+01 }, +{ 0.6082E+00, 0.5270E+00, 0.4173E+00 }, { 0.1255E+01, 0.1477E+01, 0.1503E+01 }, +{ 0.1807E+01, 0.1742E+01, 0.6553E+00 }, { 0.2000E+01, 0.2072E+01, 0.2051E+01 }}; + +/** + * LSP vector quantization tables + * + * TIA/IS-127 tables 8-1 through 8-9 + */ + +static const float evrc_lspq_full_codebook1[64][2] = { +{1.42016308E-2, 1.93881616E-2}, {2.91667543E-2, 6.51749149E-2}, +{2.06693150E-2, 4.97564934E-2}, {3.94719802E-2, 9.55850929E-2}, +{2.27012448E-2, 3.96625809E-2}, {5.38789518E-2, 6.28347769E-2}, +{2.90525518E-2, 5.73435798E-2}, {4.48280610E-2, 1.15364626E-1}, +{1.94110647E-2, 3.46889682E-2}, {4.37502973E-2, 6.75228462E-2}, +{3.55497338E-2, 4.94086780E-2}, {6.99219853E-2, 8.67279768E-2}, +{2.77880151E-2, 4.65748496E-2}, {5.79111017E-2, 6.74542487E-2}, +{4.74664383E-2, 5.50271496E-2}, {7.88898915E-2, 1.22443043E-1}, +{2.21715886E-2, 3.02628800E-2}, {3.39134485E-2, 7.17703998E-2}, +{3.17989141E-2, 4.98996116E-2}, {6.11555986E-2, 8.73361230E-2}, +{2.67506503E-2, 3.96735854E-2}, {4.44100983E-2, 8.26731324E-2}, +{3.89172547E-2, 5.65788932E-2}, {6.04800619E-2, 1.04536951E-1}, +{2.69156620E-2, 3.57168876E-2}, {4.11117189E-2, 7.33322948E-2}, +{4.12660725E-2, 4.85165231E-2}, {7.18049556E-2, 1.06202349E-1}, +{3.38037871E-2, 4.24300395E-2}, {5.91818243E-2, 7.97467977E-2}, +{4.70107906E-2, 6.28563762E-2}, {9.42011923E-2, 1.30053163E-1}, +{1.94244273E-2, 2.72732340E-2}, {3.70831676E-2, 6.64898157E-2}, +{2.80136354E-2, 5.15984930E-2}, {5.34461029E-2, 9.25904214E-2}, +{2.54959203E-2, 4.32844795E-2}, {5.51860742E-2, 7.36182332E-2}, +{3.39851119E-2, 6.05329126E-2}, {6.18182123E-2, 1.34581268E-1}, +{2.35669166E-2, 3.55242006E-2}, {5.10804243E-2, 6.79562539E-2}, +{3.83464955E-2, 5.23469411E-2}, {7.44275749E-2, 9.66108292E-2}, +{3.18591148E-2, 4.62123118E-2}, {6.18909821E-2, 7.33231753E-2}, +{4.41718437E-2, 5.79240918E-2}, {7.93596208E-2, 1.41177371E-1}, +{2.47412287E-2, 3.23629379E-2}, {3.36563922E-2, 8.04650635E-2}, +{3.37943695E-2, 5.44977151E-2}, {6.53648973E-2, 9.52775925E-2}, +{2.93364152E-2, 4.28411029E-2}, {5.27870469E-2, 8.16159397E-2}, +{4.00724895E-2, 6.18144684E-2}, {6.75848573E-2, 1.17196076E-1}, +{3.03064957E-2, 3.86914052E-2}, {4.83106263E-2, 7.42383003E-2}, +{4.37548272E-2, 5.22842295E-2}, {8.32310021E-2, 1.09881967E-1}, +{3.75600643E-2, 4.53217216E-2}, {6.60113171E-2, 7.97580183E-2}, +{5.03225066E-2, 5.90176322E-2}, {8.77133310E-2, 1.63187444E-1}}; + +static const float evrc_lspq_full_codebook2[64][2] = { +{5.21959551E-2, 8.38445649E-2}, {1.05874076E-1, 1.28694162E-1}, +{5.48323877E-2, 1.33842856E-1}, {1.17768474E-1, 1.94037274E-1}, +{5.36086522E-2, 1.11398734E-1}, {1.19989693E-1, 1.47474691E-1}, +{8.00373554E-2, 1.42999724E-1}, {1.64086595E-1, 2.09821835E-1}, +{5.21059223E-2, 9.95229408E-2}, {8.67567956E-2, 1.85966507E-1}, +{7.77341127E-2, 1.31506845E-1}, {1.60545513E-1, 1.81930289E-1}, +{7.42243677E-2, 1.10437103E-1}, {1.18635088E-1, 1.75306752E-1}, +{6.61557764E-2, 1.64441928E-1}, {1.96810856E-1, 2.16682002E-1}, +{6.05317838E-2, 9.45408568E-2}, {1.06271386E-1, 1.48013934E-1}, +{5.87486550E-2, 1.47724584E-1}, {1.34816468E-1, 2.01517954E-1}, +{6.59698322E-2, 1.16447397E-1}, {1.32297173E-1, 1.53267249E-1}, +{9.26660746E-2, 1.46725491E-1}, {1.79285541E-1, 2.19705954E-1}, +{7.06458464E-2, 9.99924466E-2}, {1.06500491E-1, 1.79443434E-1}, +{8.79249722E-2, 1.25287697E-1}, {1.53640196E-1, 1.97852716E-1}, +{8.88430104E-2, 1.12465657E-1}, {1.48286715E-1, 1.67517021E-1}, +{8.16568136E-2, 1.69274017E-1}, {2.07810536E-1, 2.31033549E-1}, +{6.14927970E-2, 8.36263224E-2}, {1.14473253E-1, 1.36779979E-1}, +{6.87129870E-2, 1.38099059E-1}, {1.10511415E-1, 2.15352878E-1}, +{5.55652268E-2, 1.22242786E-1}, {1.20557591E-1, 1.61072448E-1}, +{8.32249671E-2, 1.55475482E-1}, {1.61638483E-1, 2.28268847E-1}, +{6.29152283E-2, 1.06229566E-1}, {8.29186887E-2, 2.06774518E-1}, +{8.84756893E-2, 1.35799959E-1}, {1.69772223E-1, 1.93773940E-1}, +{7.77297840E-2, 1.20287232E-1}, {1.30648017E-1, 1.84331819E-1}, +{6.91939592E-2, 1.84218004E-1}, {2.03904077E-1, 2.49715164E-1}, +{7.07671717E-2, 9.03186128E-2}, {1.08471557E-1, 1.61966518E-1}, +{7.16886371E-2, 1.51093170E-1}, {1.38779536E-1, 2.18801782E-1}, +{6.75907061E-2, 1.26740307E-1}, {1.33412346E-1, 1.68838874E-1}, +{9.61822569E-2, 1.58728704E-1}, {1.86485633E-1, 2.36560926E-1}, +{8.23447108E-2, 1.02126025E-1}, {1.00336641E-1, 1.94918498E-1}, +{9.95981991E-2, 1.36425093E-1}, {1.82448462E-1, 2.03655198E-1}, +{9.78890732E-2, 1.21145472E-1}, {1.45453140E-1, 1.83604524E-1}, +{9.58395451E-2, 1.72194853E-1}, {2.23295853E-1, 2.46418610E-1}}; + +static const float evrc_lspq_full_codebook3[512][3] = { +{1.36425778E-1, 1.68651849E-1, 2.04688221E-1}, +{1.85717627E-1, 2.28756160E-1, 2.51958042E-1}, +{1.22760192E-1, 1.85950696E-1, 2.79446691E-1}, +{1.96468458E-1, 2.64484435E-1, 2.89318889E-1}, +{1.25653744E-1, 1.50529265E-1, 2.76144296E-1}, +{1.96301565E-1, 2.41699994E-1, 2.88230687E-1}, +{1.40099391E-1, 2.22365588E-1, 2.74666578E-1}, +{2.59952307E-1, 2.75394946E-1, 3.10975939E-1}, +{1.58452198E-1, 1.88591003E-1, 2.07339197E-1}, +{1.95616230E-1, 2.21379519E-1, 2.87022918E-1}, +{1.69424579E-1, 2.01614648E-1, 2.75669187E-1}, +{2.12393746E-1, 2.64250666E-1, 3.17967504E-1}, +{1.82965085E-1, 1.99547559E-1, 2.29538843E-1}, +{2.15200707E-1, 2.62409419E-1, 2.82432705E-1}, +{1.46404549E-1, 2.36966729E-1, 2.90067106E-1}, +{2.45338634E-1, 3.03358108E-1, 3.42260152E-1}, +{1.37478963E-1, 1.58276558E-1, 2.39217222E-1}, +{2.01999024E-1, 2.20102608E-1, 2.69546896E-1}, +{1.18350029E-1, 2.30206400E-1, 2.83554822E-1}, +{2.25519255E-1, 2.72272140E-1, 3.06072980E-1}, +{1.35661438E-1, 1.91633970E-1, 2.65912026E-1}, +{1.95733085E-1, 2.31926173E-1, 3.14376086E-1}, +{1.67998984E-1, 2.27706313E-1, 2.76947826E-1}, +{2.50170559E-1, 3.01627070E-1, 3.21084231E-1}, +{1.33492306E-1, 2.01223105E-1, 2.33893991E-1}, +{2.06442133E-1, 2.38704175E-1, 2.77560145E-1}, +{1.79048792E-1, 1.95776582E-1, 2.80656606E-1}, +{2.06193641E-1, 2.64055401E-1, 3.33098441E-1}, +{1.75185278E-1, 1.91166341E-1, 2.57540315E-1}, +{2.28398636E-1, 2.45296657E-1, 3.08980793E-1}, +{1.80859819E-1, 2.43579060E-1, 2.96631068E-1}, +{2.76152968E-1, 3.08256060E-1, 3.46822590E-1}, +{1.37115732E-1, 1.80057764E-1, 2.20953465E-1}, +{1.81370094E-1, 2.26770103E-1, 2.70392686E-1}, +{1.25246510E-1, 1.79606944E-1, 3.10376436E-1}, +{1.90708354E-1, 2.87734240E-1, 3.13476235E-1}, +{1.30486086E-1, 1.60435289E-1, 3.00243706E-1}, +{1.97318628E-1, 2.56378502E-1, 2.78474301E-1}, +{1.58597067E-1, 2.37381399E-1, 2.62910336E-1}, +{2.61825919E-1, 2.77717203E-1, 3.31382245E-1}, +{1.64160743E-1, 1.85841531E-1, 2.35615849E-1}, +{2.09486142E-1, 2.21452802E-1, 2.92153865E-1}, +{1.66807845E-1, 2.13641763E-1, 2.70675927E-1}, +{2.29834273E-1, 2.88374633E-1, 3.06238323E-1}, +{1.82154253E-1, 2.00822473E-1, 2.40169376E-1}, +{2.24944726E-1, 2.69813925E-1, 2.91401237E-1}, +{1.63940564E-1, 2.50341147E-1, 2.78307766E-1}, +{2.56727993E-1, 2.95103759E-1, 3.53297085E-1}, +{1.40218839E-1, 1.76687688E-1, 2.46773273E-1}, +{2.15291306E-1, 2.29216009E-1, 2.64283627E-1}, +{1.21002659E-1, 2.18333840E-1, 3.22341293E-1}, +{2.54243195E-1, 2.73986191E-1, 2.96262473E-1}, +{1.60385415E-1, 1.83762908E-1, 2.81598717E-1}, +{1.87832162E-1, 2.37420350E-1, 3.29777509E-1}, +{1.77788362E-1, 2.26703495E-1, 3.02322537E-1}, +{2.75108218E-1, 2.93730587E-1, 3.12373787E-1}, +{1.70116410E-1, 1.85232103E-1, 2.46125028E-1}, +{2.21754774E-1, 2.39912242E-1, 2.86891907E-1}, +{1.95083722E-1, 2.08337873E-1, 2.88349718E-1}, +{2.37536535E-1, 2.75004476E-1, 3.39786023E-1}, +{1.88369319E-1, 2.04371840E-1, 2.57375032E-1}, +{2.47250155E-1, 2.60551840E-1, 3.02137524E-1}, +{1.66944191E-1, 2.46912360E-1, 3.18894416E-1}, +{2.78118610E-1, 3.13011140E-1, 3.65329295E-1}, +{1.45213529E-1, 1.63051456E-1, 2.24912614E-1}, +{2.05692515E-1, 2.20831484E-1, 2.52817810E-1}, +{1.21125661E-1, 1.96374118E-1, 3.00122708E-1}, +{2.15566799E-1, 2.65657336E-1, 2.99202889E-1}, +{1.09134212E-1, 1.78472102E-1, 2.88323194E-1}, +{2.03508541E-1, 2.40347922E-1, 2.96309739E-1}, +{1.53101787E-1, 2.25415319E-1, 2.84843713E-1}, +{2.50233442E-1, 2.77736932E-1, 3.24840695E-1}, +{1.66308925E-1, 1.94173396E-1, 2.11635381E-1}, +{2.01289460E-1, 2.26062179E-1, 2.93246478E-1}, +{1.49518773E-1, 2.14201719E-1, 2.83894747E-1}, +{2.21836135E-1, 2.85231501E-1, 3.20082635E-1}, +{1.89573213E-1, 2.06577629E-1, 2.30332345E-1}, +{2.31247649E-1, 2.46864259E-1, 2.89846569E-1}, +{1.39116928E-1, 2.59189934E-1, 2.98019558E-1}, +{2.44512573E-1, 2.82671362E-1, 3.61258298E-1}, +{1.22530967E-1, 1.68514788E-1, 2.70879298E-1}, +{2.04372838E-1, 2.30398357E-1, 2.71792918E-1}, +{1.42643943E-1, 2.22405583E-1, 2.92057186E-1}, +{2.42643669E-1, 2.77429372E-1, 2.97135502E-1}, +{1.52048603E-1, 1.96921080E-1, 2.61013240E-1}, +{2.17875019E-1, 2.45840371E-1, 3.08138579E-1}, +{1.90109268E-1, 2.31099129E-1, 2.80178159E-1}, +{2.54314184E-1, 2.94079810E-1, 3.39649171E-1}, +{1.56698599E-1, 2.08597451E-1, 2.28010774E-1}, +{2.25088730E-1, 2.50014484E-1, 2.76250154E-1}, +{1.78219035E-1, 1.98228240E-1, 3.04198891E-1}, +{2.08567217E-1, 2.92395383E-1, 3.46786886E-1}, +{1.71052113E-1, 2.03438759E-1, 2.62644321E-1}, +{2.30275467E-1, 2.58817524E-1, 3.11986536E-1}, +{1.85333565E-1, 2.45760202E-1, 3.10553998E-1}, +{2.89413869E-1, 3.11095625E-1, 3.46476167E-1}, +{1.50332406E-1, 1.67538226E-1, 2.40182847E-1}, +{1.79971650E-1, 2.37168610E-1, 2.60899693E-1}, +{1.49866179E-1, 1.97890073E-1, 3.07916552E-1}, +{2.10799649E-1, 2.88180083E-1, 3.29747230E-1}, +{1.31711140E-1, 1.65906459E-1, 3.22898000E-1}, +{2.14832023E-1, 2.52822131E-1, 2.97547072E-1}, +{1.83760419E-1, 2.37523615E-1, 2.74610013E-1}, +{2.55575180E-1, 2.75439233E-1, 3.46021861E-1}, +{1.82662204E-1, 1.99470907E-1, 2.16051653E-1}, +{2.09240332E-1, 2.22406715E-1, 3.02382857E-1}, +{1.84088245E-1, 2.11327791E-1, 2.82538086E-1}, +{2.41171077E-1, 2.97036022E-1, 3.15979272E-1}, +{1.96804658E-1, 2.11815894E-1, 2.41647676E-1}, +{2.42761984E-1, 2.58586556E-1, 2.93204397E-1}, +{1.58905461E-1, 2.65077025E-1, 2.89881319E-1}, +{2.58060575E-1, 3.18903178E-1, 3.47846836E-1}, +{1.48766384E-1, 1.66853935E-1, 2.66827434E-1}, +{2.15942249E-1, 2.29938298E-1, 2.76041597E-1}, +{1.38410494E-1, 2.39283442E-1, 3.27972382E-1}, +{2.43765280E-1, 2.88408488E-1, 3.06048721E-1}, +{1.70157120E-1, 1.89986289E-1, 2.81219155E-1}, +{2.19117031E-1, 2.58005291E-1, 3.26571971E-1}, +{1.92163572E-1, 2.23614186E-1, 2.98683077E-1}, +{2.73545444E-1, 3.12078089E-1, 3.30766588E-1}, +{1.62452087E-1, 2.04930902E-1, 2.53337711E-1}, +{2.23855302E-1, 2.37671077E-1, 3.03202003E-1}, +{1.93955287E-1, 2.12335557E-1, 3.07566851E-1}, +{2.29912683E-1, 2.97581047E-1, 3.37499231E-1}, +{1.89335391E-1, 2.04148144E-1, 2.78609782E-1}, +{2.42303565E-1, 2.73163110E-1, 3.15361649E-1}, +{1.55009672E-1, 2.88095146E-1, 3.35996419E-1}, +{2.73716152E-1, 3.31215471E-1, 3.62539083E-1}, +{1.52389362E-1, 1.72619134E-1, 1.90585673E-1}, +{1.96988270E-1, 2.26309747E-1, 2.46197492E-1}, +{1.20555148E-1, 2.06369758E-1, 2.81199783E-1}, +{1.93709418E-1, 2.71900505E-1, 3.01332921E-1}, +{1.36701152E-1, 1.54093146E-1, 2.82258362E-1}, +{1.97299168E-1, 2.53656298E-1, 2.90315062E-1}, +{1.43463776E-1, 2.43872911E-1, 2.75533706E-1}, +{2.58477271E-1, 2.73279876E-1, 3.21119100E-1}, +{1.54406175E-1, 1.93793535E-1, 2.15884149E-1}, +{2.05979452E-1, 2.24277020E-1, 2.85732359E-1}, +{1.74535319E-1, 2.08482355E-1, 2.79668540E-1}, +{2.18844578E-1, 2.72486299E-1, 3.27095598E-1}, +{1.77609727E-1, 2.12990195E-1, 2.39119649E-1}, +{2.29163751E-1, 2.59165913E-1, 2.83514649E-1}, +{1.57353148E-1, 2.39961296E-1, 3.04263145E-1}, +{2.45613828E-1, 3.16824526E-1, 3.42909366E-1}, +{1.42953232E-1, 1.61905348E-1, 2.53710240E-1}, +{2.10192814E-1, 2.22847700E-1, 2.71103770E-1}, +{1.26843944E-1, 2.16709048E-1, 2.97734648E-1}, +{2.31000140E-1, 2.80109137E-1, 2.99707443E-1}, +{1.52980462E-1, 1.93996876E-1, 2.72895664E-1}, +{2.12860718E-1, 2.41545349E-1, 3.16518754E-1}, +{1.71154693E-1, 2.22469687E-1, 2.93786496E-1}, +{2.51988232E-1, 3.04254979E-1, 3.31269950E-1}, +{1.33188918E-1, 2.07924992E-1, 2.55362093E-1}, +{2.12044910E-1, 2.42189646E-1, 2.88903743E-1}, +{1.84612468E-1, 2.01143622E-1, 2.86360770E-1}, +{2.18286708E-1, 2.76752442E-1, 3.44581515E-1}, +{1.83562174E-1, 1.99478507E-1, 2.62156576E-1}, +{2.33130530E-1, 2.49596909E-1, 3.15842837E-1}, +{1.89898983E-1, 2.46874869E-1, 2.97132462E-1}, +{2.75022447E-1, 3.22490305E-1, 3.46977681E-1}, +{1.42305329E-1, 1.92689180E-1, 2.16155857E-1}, +{1.95676163E-1, 2.22268641E-1, 2.76587397E-1}, +{1.33241490E-1, 1.97791785E-1, 3.22897941E-1}, +{1.84865132E-1, 2.97106177E-1, 3.26105148E-1}, +{1.50203660E-1, 1.76781267E-1, 2.91536182E-1}, +{2.03144446E-1, 2.59616166E-1, 2.99156040E-1}, +{1.65488973E-1, 2.38342047E-1, 2.87493914E-1}, +{2.71071255E-1, 2.89544493E-1, 3.19521040E-1}, +{1.68598369E-1, 1.98825568E-1, 2.30347604E-1}, +{2.13811651E-1, 2.34471768E-1, 2.90959626E-1}, +{1.74605444E-1, 2.17256010E-1, 2.85688072E-1}, +{2.28503481E-1, 2.96190292E-1, 3.16534668E-1}, +{1.87172607E-1, 2.20547438E-1, 2.39688724E-1}, +{2.28884771E-1, 2.63583153E-1, 3.01329464E-1}, +{1.77897051E-1, 2.58131474E-1, 2.81487674E-1}, +{2.59513617E-1, 3.07204396E-1, 3.48793596E-1}, +{1.45224437E-1, 1.78715974E-1, 2.59186983E-1}, +{2.19062313E-1, 2.38223523E-1, 2.60461539E-1}, +{1.43650874E-1, 2.09760785E-1, 3.15830201E-1}, +{2.50127465E-1, 2.79182345E-1, 3.05153579E-1}, +{1.48986444E-1, 2.01226771E-1, 2.82543689E-1}, +{2.08387777E-1, 2.35603899E-1, 3.45363885E-1}, +{1.85830340E-1, 2.21607298E-1, 3.10773641E-1}, +{2.80904710E-1, 2.95469791E-1, 3.25499445E-1}, +{1.72967300E-1, 1.97078109E-1, 2.45801106E-1}, +{2.19495699E-1, 2.44767100E-1, 2.93587774E-1}, +{1.83909580E-1, 2.15004295E-1, 3.00334543E-1}, +{2.45338634E-1, 2.68595248E-1, 3.48330349E-1}, +{1.92957386E-1, 2.06625074E-1, 2.67336398E-1}, +{2.54845560E-1, 2.68642277E-1, 3.03547889E-1}, +{1.76853105E-1, 2.59330958E-1, 3.16200763E-1}, +{2.90929139E-1, 3.15634757E-1, 3.68723541E-1}, +{1.57116994E-1, 1.73552901E-1, 2.28736520E-1}, +{2.12509260E-1, 2.30501205E-1, 2.52217978E-1}, +{1.42521843E-1, 2.01979935E-1, 2.93012232E-1}, +{2.14919671E-1, 2.78065056E-1, 3.14176053E-1}, +{1.35947272E-1, 1.81055903E-1, 2.75475413E-1}, +{1.98416695E-1, 2.41673797E-1, 3.05173427E-1}, +{1.59517333E-1, 2.31580108E-1, 2.95412451E-1}, +{2.58203626E-1, 2.87348121E-1, 3.20351988E-1}, +{1.74840674E-1, 1.92883253E-1, 2.11250007E-1}, +{2.02168509E-1, 2.27025688E-1, 3.04884046E-1}, +{1.69532105E-1, 2.11826235E-1, 2.97355384E-1}, +{2.30033740E-1, 2.91504353E-1, 3.26589435E-1}, +{1.95046112E-1, 2.11709172E-1, 2.27705747E-1}, +{2.37926885E-1, 2.52411634E-1, 2.97752172E-1}, +{1.53762922E-1, 2.46541560E-1, 3.14768940E-1}, +{2.36075714E-1, 3.03568929E-1, 3.70624453E-1}, +{1.38660327E-1, 1.67949975E-1, 2.73515254E-1}, +{2.13806167E-1, 2.27267206E-1, 2.86276251E-1}, +{1.25080630E-1, 2.44098395E-1, 3.02548796E-1}, +{2.35714868E-1, 2.81208843E-1, 3.08903724E-1}, +{1.51691392E-1, 2.10877746E-1, 2.63812989E-1}, +{2.20730439E-1, 2.52777904E-1, 3.16413730E-1}, +{1.84924737E-1, 2.39424765E-1, 2.85120815E-1}, +{2.59548545E-1, 3.09809893E-1, 3.26423734E-1}, +{1.62930742E-1, 2.19900876E-1, 2.36148626E-1}, +{2.34194234E-1, 2.49944329E-1, 2.77549058E-1}, +{1.70870200E-1, 1.98291600E-1, 3.21412593E-1}, +{2.31566861E-1, 2.75015086E-1, 3.69710356E-1}, +{1.80002406E-1, 2.06701040E-1, 2.71204919E-1}, +{2.38075271E-1, 2.54006237E-1, 3.23827595E-1}, +{1.99148253E-1, 2.54273921E-1, 3.07479709E-1}, +{2.87428617E-1, 3.25045079E-1, 3.48634571E-1}, +{1.45285025E-1, 1.91359162E-1, 2.49691397E-1}, +{1.94659308E-1, 2.40821242E-1, 2.77302653E-1}, +{1.53150991E-1, 1.94375664E-1, 3.27550441E-1}, +{2.04085842E-1, 2.98595697E-1, 3.21480066E-1}, +{1.56009689E-1, 1.81012720E-1, 3.00931662E-1}, +{2.10962430E-1, 2.55770296E-1, 3.08086127E-1}, +{1.85444072E-1, 2.49021322E-1, 2.74029821E-1}, +{2.74493456E-1, 2.89441973E-1, 3.38794917E-1}, +{1.76941887E-1, 1.94476932E-1, 2.22077265E-1}, +{2.16377512E-1, 2.30735779E-1, 3.03689271E-1}, +{1.89683452E-1, 2.14660764E-1, 2.88445383E-1}, +{2.40827337E-1, 2.98141748E-1, 3.27378422E-1}, +{2.01787844E-1, 2.19441772E-1, 2.39327446E-1}, +{2.48812512E-1, 2.65865892E-1, 2.93382376E-1}, +{1.82027832E-1, 2.68279046E-1, 2.93991417E-1}, +{2.56498635E-1, 3.19984466E-1, 3.62663239E-1}, +{1.58799276E-1, 1.75433666E-1, 2.67389864E-1}, +{2.24259302E-1, 2.36668259E-1, 2.77639121E-1}, +{1.49203405E-1, 2.26585329E-1, 3.45255584E-1}, +{2.50655770E-1, 2.92264849E-1, 3.13574284E-1}, +{1.58096299E-1, 2.02193201E-1, 2.98711687E-1}, +{2.28820905E-1, 2.48557344E-1, 3.44726473E-1}, +{1.87972054E-1, 2.34109432E-1, 3.04235607E-1}, +{2.85657108E-1, 3.14878136E-1, 3.36931497E-1}, +{1.62680015E-1, 2.17820048E-1, 2.57436782E-1}, +{2.24049792E-1, 2.46739820E-1, 3.00795883E-1}, +{2.01354548E-1, 2.18286663E-1, 3.13036293E-1}, +{2.38028511E-1, 2.98103482E-1, 3.53503793E-1}, +{1.98829994E-1, 2.12877125E-1, 2.72980839E-1}, +{2.50616491E-1, 2.67659992E-1, 3.20611864E-1}, +{1.70901820E-1, 2.69330353E-1, 3.34428221E-1}, +{3.04988861E-1, 3.36196691E-1, 3.65235358E-1}, +{1.47624031E-1, 1.81272805E-1, 2.04707921E-1}, +{1.93751350E-1, 2.20973969E-1, 2.61775166E-1}, +{1.32089809E-1, 1.94851607E-1, 2.83547610E-1}, +{2.07739428E-1, 2.70596832E-1, 2.92264789E-1}, +{1.27733424E-1, 1.66896015E-1, 2.83891350E-1}, +{2.05309406E-1, 2.47807533E-1, 2.83632785E-1}, +{1.54211894E-1, 2.25014091E-1, 2.70082027E-1}, +{2.67574131E-1, 2.84426898E-1, 3.09334785E-1}, +{1.68846920E-1, 1.87004536E-1, 2.02433169E-1}, +{2.02441111E-1, 2.16733068E-1, 2.93079227E-1}, +{1.63621262E-1, 2.15616465E-1, 2.82792896E-1}, +{2.25509301E-1, 2.66283005E-1, 3.17886561E-1}, +{1.89110294E-1, 2.05609441E-1, 2.22113580E-1}, +{2.21240178E-1, 2.60288864E-1, 2.92541057E-1}, +{1.55563369E-1, 2.46850818E-1, 2.89648801E-1}, +{2.48406157E-1, 3.05291861E-1, 3.55316669E-1}, +{1.27122149E-1, 1.58053726E-1, 2.54164368E-1}, +{2.04998836E-1, 2.19476849E-1, 2.78342038E-1}, +{1.33302316E-1, 2.29614019E-1, 2.86947161E-1}, +{2.36777052E-1, 2.67918199E-1, 3.08230907E-1}, +{1.40853569E-1, 2.03414679E-1, 2.73257107E-1}, +{2.07684264E-1, 2.34520018E-1, 3.24583262E-1}, +{1.77181646E-1, 2.29595393E-1, 2.83539146E-1}, +{2.61378348E-1, 3.01160187E-1, 3.21707100E-1}, +{1.48595735E-1, 2.07772017E-1, 2.46946126E-1}, +{2.14334831E-1, 2.48061299E-1, 2.72259146E-1}, +{1.76380262E-1, 1.96897894E-1, 2.92286903E-1}, +{1.98193476E-1, 2.75483340E-1, 3.49037558E-1}, +{1.76153168E-1, 1.93248957E-1, 2.69548506E-1}, +{2.36968622E-1, 2.50065804E-1, 3.06820840E-1}, +{1.76060721E-1, 2.54037619E-1, 3.03566784E-1}, +{2.82952905E-1, 3.01765054E-1, 3.53956312E-1}, +{1.45353720E-1, 1.83678836E-1, 2.34750062E-1}, +{1.93842635E-1, 2.30635554E-1, 2.67817765E-1}, +{1.38958976E-1, 1.86760783E-1, 3.13113242E-1}, +{1.99944481E-1, 2.77624756E-1, 3.25046331E-1}, +{1.42966077E-1, 1.71310842E-1, 3.03013414E-1}, +{2.07741663E-1, 2.58691758E-1, 2.88766950E-1}, +{1.71776935E-1, 2.40246087E-1, 2.73284525E-1}, +{2.71046638E-1, 2.85170943E-1, 3.27401131E-1}, +{1.69854626E-1, 1.87545776E-1, 2.24484712E-1}, +{2.15221986E-1, 2.27339745E-1, 2.95008808E-1}, +{1.75596640E-1, 2.17936546E-1, 2.74879605E-1}, +{2.34665439E-1, 2.89530903E-1, 3.16494375E-1}, +{1.89946994E-1, 2.04953820E-1, 2.46955171E-1}, +{2.37297818E-1, 2.68316716E-1, 2.90684313E-1}, +{1.69963166E-1, 2.53367484E-1, 2.92533010E-1}, +{2.70659864E-1, 2.97146112E-1, 3.56183976E-1}, +{1.52539685E-1, 1.70138955E-1, 2.52703935E-1}, +{2.19119206E-1, 2.35900700E-1, 2.69739121E-1}, +{1.42245665E-1, 2.18184620E-1, 3.28218073E-1}, +{2.61472821E-1, 2.78025657E-1, 3.02375883E-1}, +{1.53526023E-1, 1.90727741E-1, 2.92820841E-1}, +{2.09240988E-1, 2.49808684E-1, 3.24709088E-1}, +{1.75176397E-1, 2.38646746E-1, 3.06392699E-1}, +{2.73218870E-1, 3.03954989E-1, 3.20513874E-1}, +{1.63911596E-1, 1.89611584E-1, 2.56272525E-1}, +{2.26953760E-1, 2.40120232E-1, 2.92728513E-1}, +{1.95565715E-1, 2.11956203E-1, 2.97374696E-1}, +{2.41045550E-1, 2.88497001E-1, 3.36352319E-1}, +{1.94948331E-1, 2.09475279E-1, 2.56309658E-1}, +{2.47884631E-1, 2.63356417E-1, 3.11270863E-1}, +{1.69189706E-1, 2.35864580E-1, 3.36249381E-1}, +{2.86001563E-1, 3.25423747E-1, 3.59607369E-1}, +{1.56258598E-1, 1.76704943E-1, 2.14393437E-1}, +{2.08996847E-1, 2.23968685E-1, 2.60886759E-1}, +{1.35765389E-1, 2.03580052E-1, 3.05503219E-1}, +{2.18961373E-1, 2.79463500E-1, 2.99450845E-1}, +{1.34064749E-1, 1.78332120E-1, 2.90169626E-1}, +{2.13298395E-1, 2.40031511E-1, 3.00345927E-1}, +{1.64373413E-1, 2.26438701E-1, 2.87171155E-1}, +{2.50739604E-1, 2.80812472E-1, 3.35349351E-1}, +{1.63649514E-1, 1.97108001E-1, 2.21165180E-1}, +{2.08139613E-1, 2.30869800E-1, 2.96137065E-1}, +{1.59113124E-1, 2.18189180E-1, 2.95531958E-1}, +{2.39883497E-1, 2.81831235E-1, 3.26045603E-1}, +{1.89394727E-1, 2.08127141E-1, 2.38446414E-1}, +{2.32995704E-1, 2.59603471E-1, 2.93427974E-1}, +{1.60558835E-1, 2.55164832E-1, 3.02872926E-1}, +{2.53509283E-1, 2.96028465E-1, 3.67721587E-1}, +{1.30124375E-1, 1.74838990E-1, 2.60486037E-1}, +{2.10203990E-1, 2.33570784E-1, 2.83061892E-1}, +{1.52365491E-1, 2.25338757E-1, 3.03720981E-1}, +{2.40558609E-1, 2.77192205E-1, 3.05891901E-1}, +{1.63728818E-1, 1.94779396E-1, 2.69253582E-1}, +{2.25709423E-1, 2.40902692E-1, 3.18060607E-1}, +{1.92055091E-1, 2.29857832E-1, 2.89826721E-1}, +{2.62759686E-1, 3.04292172E-1, 3.35680574E-1}, +{1.66071162E-1, 2.06819177E-1, 2.39712462E-1}, +{2.23915562E-1, 2.50106871E-1, 2.85296232E-1}, +{1.88402340E-1, 2.03793734E-1, 3.03041130E-1}, +{2.30698988E-1, 2.87044138E-1, 3.49802762E-1}, +{1.82025358E-1, 2.14073509E-1, 2.63470024E-1}, +{2.37297758E-1, 2.65025407E-1, 3.17815512E-1}, +{1.89278707E-1, 2.58802205E-1, 3.04866165E-1}, +{2.97243059E-1, 3.17153066E-1, 3.56583923E-1}, +{1.58607468E-1, 1.78659767E-1, 2.41919369E-1}, +{1.94887385E-1, 2.41695851E-1, 2.62176663E-1}, +{1.58124432E-1, 2.11753070E-1, 3.11352164E-1}, +{2.16902718E-1, 2.98796803E-1, 3.20994049E-1}, +{1.49272785E-1, 1.74964130E-1, 3.15334409E-1}, +{2.21622273E-1, 2.56179065E-1, 3.03902954E-1}, +{1.75979599E-1, 2.43505448E-1, 2.85801739E-1}, +{2.64590383E-1, 2.85541564E-1, 3.45107764E-1}, +{1.80137083E-1, 2.05279350E-1, 2.22255990E-1}, +{2.10796222E-1, 2.26315439E-1, 3.14426929E-1}, +{1.79151163E-1, 2.09439725E-1, 2.93280870E-1}, +{2.49719024E-1, 2.91257650E-1, 3.27162296E-1}, +{1.98700234E-1, 2.15896755E-1, 2.49960214E-1}, +{2.40726396E-1, 2.64857739E-1, 2.99639553E-1}, +{1.71249732E-1, 2.68166155E-1, 3.03572744E-1}, +{2.69555569E-1, 3.16100627E-1, 3.56570691E-1}, +{1.50564745E-1, 1.84190869E-1, 2.68674821E-1}, +{2.16941193E-1, 2.40813971E-1, 2.78942198E-1}, +{1.35399476E-1, 2.60586530E-1, 3.32604855E-1}, +{2.56150961E-1, 2.87822872E-1, 3.06156367E-1}, +{1.66398838E-1, 1.88721806E-1, 2.93023735E-1}, +{2.29214087E-1, 2.61565417E-1, 3.27494055E-1}, +{1.98266640E-1, 2.32970506E-1, 2.99134284E-1}, +{2.87046254E-1, 3.07103783E-1, 3.27298075E-1}, +{1.75898686E-1, 2.11898595E-1, 2.51332909E-1}, +{2.32067421E-1, 2.44622201E-1, 2.99443692E-1}, +{1.90780059E-1, 2.12090015E-1, 3.25059265E-1}, +{2.31531218E-1, 3.14166099E-1, 3.42735857E-1}, +{1.95099846E-1, 2.09554315E-1, 2.79483467E-1}, +{2.40416065E-1, 2.69604772E-1, 3.28015476E-1}, +{1.71800867E-1, 2.82233089E-1, 3.14749271E-1}, +{2.69243777E-1, 3.38462502E-1, 3.79935652E-1}, +{1.59934625E-1, 1.77966774E-1, 2.00818628E-1}, +{2.01979712E-1, 2.30668545E-1, 2.56773323E-1}, +{1.34024277E-1, 2.10961610E-1, 2.84687728E-1}, +{2.03712896E-1, 2.83053070E-1, 3.03309411E-1}, +{1.44528881E-1, 1.64728075E-1, 2.85079390E-1}, +{2.06285611E-1, 2.48649031E-1, 2.96383053E-1}, +{1.58138171E-1, 2.34317720E-1, 2.79650003E-1}, +{2.64995635E-1, 2.79900700E-1, 3.18619400E-1}, +{1.66537479E-1, 1.84279412E-1, 2.14547485E-1}, +{2.03051880E-1, 2.35110492E-1, 2.88755983E-1}, +{1.68422714E-1, 2.03946173E-1, 2.87478894E-1}, +{2.31727019E-1, 2.74086386E-1, 3.24755162E-1}, +{1.85356215E-1, 2.14113116E-1, 2.29030401E-1}, +{2.42482558E-1, 2.60655493E-1, 2.83030301E-1}, +{1.67562261E-1, 2.42027491E-1, 2.99461991E-1}, +{2.38809898E-1, 3.19003850E-1, 3.58415872E-1}, +{1.37908265E-1, 1.54787809E-1, 2.65611202E-1}, +{2.11019263E-1, 2.24607319E-1, 2.79954702E-1}, +{1.37569889E-1, 2.25128531E-1, 3.09312850E-1}, +{2.29239866E-1, 2.76150972E-1, 3.15241843E-1}, +{1.60487458E-1, 1.95461214E-1, 2.83169478E-1}, +{2.18505666E-1, 2.38197207E-1, 3.30340117E-1}, +{1.81991324E-1, 2.33026952E-1, 2.93276042E-1}, +{2.54552305E-1, 3.14394146E-1, 3.36392254E-1}, +{1.44095764E-1, 2.26640165E-1, 2.50595063E-1}, +{2.15188012E-1, 2.51417249E-1, 2.85043985E-1}, +{1.87674388E-1, 2.04458863E-1, 2.94168979E-1}, +{2.30494842E-1, 2.68452436E-1, 3.52370054E-1}, +{1.85022101E-1, 1.99075252E-1, 2.71930546E-1}, +{2.42569372E-1, 2.55389154E-1, 3.11399311E-1}, +{1.95166096E-1, 2.49102056E-1, 2.98998445E-1}, +{2.83654153E-1, 3.14600259E-1, 3.55619401E-1}, +{1.51490018E-1, 1.97729796E-1, 2.32467473E-1}, +{2.00029895E-1, 2.30101258E-1, 2.81933933E-1}, +{1.38711318E-1, 1.91816628E-1, 3.45780402E-1}, +{1.96580395E-1, 3.04714769E-1, 3.40553433E-1}, +{1.38154253E-1, 1.88543141E-1, 2.99461216E-1}, +{2.05666468E-1, 2.68904895E-1, 3.05537194E-1}, +{1.72447845E-1, 2.33558387E-1, 2.93625206E-1}, +{2.70145416E-1, 2.98654765E-1, 3.28556389E-1}, +{1.75489411E-1, 1.91361547E-1, 2.35585332E-1}, +{2.20548794E-1, 2.34773993E-1, 2.95397669E-1}, +{1.85652360E-1, 2.22349137E-1, 2.79883891E-1}, +{2.29456946E-1, 3.04546326E-1, 3.24684292E-1}, +{1.86900780E-1, 2.15469390E-1, 2.51856804E-1}, +{2.34910533E-1, 2.71217376E-1, 2.99894661E-1}, +{1.85142443E-1, 2.56071001E-1, 2.93291301E-1}, +{2.63883710E-1, 3.07127446E-1, 3.62546653E-1}, +{1.60997644E-1, 1.78937852E-1, 2.55808324E-1}, +{2.25671068E-1, 2.43735075E-1, 2.68624991E-1}, +{1.55076161E-1, 2.30396181E-1, 3.21005553E-1}, +{2.51760483E-1, 2.79653400E-1, 3.14202160E-1}, +{1.56988814E-1, 2.07466930E-1, 2.89933950E-1}, +{2.17479482E-1, 2.59626418E-1, 3.40659052E-1}, +{1.76811531E-1, 2.31087089E-1, 3.17562491E-1}, +{2.82952607E-1, 2.99844354E-1, 3.36822897E-1}, +{1.82060316E-1, 1.98734730E-1, 2.51980305E-1}, +{2.25874200E-1, 2.52469152E-1, 2.93356389E-1}, +{2.00799957E-1, 2.17786849E-1, 3.02210063E-1}, +{2.47423753E-1, 2.86882848E-1, 3.47820610E-1}, +{2.01128140E-1, 2.14746892E-1, 2.62269646E-1}, +{2.53963351E-1, 2.69477993E-1, 3.12133819E-1}, +{1.91034868E-1, 2.55738169E-1, 3.32559615E-1}, +{2.91053712E-1, 3.31458420E-1, 3.68588477E-1}, +{1.57229915E-1, 1.85374141E-1, 2.25361317E-1}, +{2.08051339E-1, 2.38350868E-1, 2.64212936E-1}, +{1.46848336E-1, 2.13000089E-1, 3.00192565E-1}, +{2.18630567E-1, 2.90263802E-1, 3.09045762E-1}, +{1.43699184E-1, 1.87815160E-1, 2.83769876E-1}, +{2.07328036E-1, 2.45088696E-1, 3.08956414E-1}, +{1.64228097E-1, 2.27826655E-1, 3.08907896E-1}, +{2.61919737E-1, 2.91333705E-1, 3.31527978E-1}, +{1.70648888E-1, 2.02157527E-1, 2.17827827E-1}, +{2.07796112E-1, 2.34704822E-1, 3.06783766E-1}, +{1.72118798E-1, 2.14057386E-1, 3.10151786E-1}, +{2.29116157E-1, 2.80949861E-1, 3.33774298E-1}, +{1.96622208E-1, 2.16653049E-1, 2.33279720E-1}, +{2.37789229E-1, 2.58971304E-1, 3.04609209E-1}, +{1.55182019E-1, 2.63032585E-1, 3.18943053E-1}, +{2.49388829E-1, 3.16970855E-1, 3.77762467E-1}, +{1.51363596E-1, 1.75010651E-1, 2.78245836E-1}, +{2.19810233E-1, 2.32360214E-1, 2.85034925E-1}, +{1.42630622E-1, 2.40602851E-1, 3.04125100E-1}, +{2.42764875E-1, 2.83762127E-1, 3.15481216E-1}, +{1.57467470E-1, 2.07524061E-1, 2.75674909E-1}, +{2.28758618E-1, 2.49092206E-1, 3.28139395E-1}, +{1.90872714E-1, 2.38125205E-1, 2.94894546E-1}, +{2.66389251E-1, 3.14321429E-1, 3.38669509E-1}, +{1.70644209E-1, 2.25980043E-1, 2.47372389E-1}, +{2.36442789E-1, 2.53003448E-1, 2.88220435E-1}, +{1.85423777E-1, 2.04888850E-1, 3.14608842E-1}, +{2.17379019E-1, 2.94553548E-1, 3.67831022E-1}, +{1.88563988E-1, 2.15174288E-1, 2.72999734E-1}, +{2.45102122E-1, 2.59770364E-1, 3.21885556E-1}, +{1.98444173E-1, 2.61160702E-1, 3.17097872E-1}, +{2.99013853E-1, 3.28965336E-1, 3.56681198E-1}, +{1.58248767E-1, 1.92205697E-1, 2.46059090E-1}, +{2.02385351E-1, 2.47965842E-1, 2.71749645E-1}, +{1.61710784E-1, 2.13708103E-1, 3.27384740E-1}, +{2.14419708E-1, 3.05552453E-1, 3.33721548E-1}, +{1.61819980E-1, 1.89897299E-1, 3.10501546E-1}, +{2.19436333E-1, 2.65029579E-1, 3.09288830E-1}, +{1.88303933E-1, 2.49633163E-1, 2.85499543E-1}, +{2.69325376E-1, 2.99807042E-1, 3.41722459E-1}, +{1.72406003E-1, 2.10977256E-1, 2.27773219E-1}, +{2.20281526E-1, 2.34015763E-1, 3.12846094E-1}, +{1.83257267E-1, 2.22061962E-1, 2.91052371E-1}, +{2.42531225E-1, 3.09527606E-1, 3.30389649E-1}, +{2.07546696E-1, 2.24662632E-1, 2.44420141E-1}, +{2.45858207E-1, 2.70285994E-1, 3.05132121E-1}, +{1.84840545E-1, 2.72096783E-1, 3.12531084E-1}, +{2.74252594E-1, 3.21252435E-1, 3.74658197E-1}, +{1.66425839E-1, 1.84491634E-1, 2.68278092E-1}, +{2.28423670E-1, 2.43025422E-1, 2.81184882E-1}, +{1.60091296E-1, 2.52953321E-1, 3.35822314E-1}, +{2.62109995E-1, 2.95581907E-1, 3.13354105E-1}, +{1.67702749E-1, 2.01536924E-1, 3.01801592E-1}, +{2.37822965E-1, 2.59894758E-1, 3.38231117E-1}, +{1.97206214E-1, 2.45490909E-1, 3.17895442E-1}, +{2.98455298E-1, 3.19209784E-1, 3.40971738E-1}, +{1.71195343E-1, 2.24327832E-1, 2.62736112E-1}, +{2.30626896E-1, 2.53310233E-1, 3.01206797E-1}, +{2.04814211E-1, 2.21881568E-1, 3.25966567E-1}, +{2.22987518E-1, 3.06339115E-1, 3.50717157E-1}, +{2.00855389E-1, 2.15359926E-1, 2.84143478E-1}, +{2.50951648E-1, 2.66189247E-1, 3.33360583E-1}, +{1.75610259E-1, 2.93791324E-1, 3.40326935E-1}, +{2.91745067E-1, 3.40602487E-1, 3.81397158E-1}}; + +static const float evrc_lspq_full_codebook4[128][3] = { +{2.77461529E-1, 3.16972077E-1, 3.95498335E-1}, +{3.36560428E-1, 3.60156953E-1, 3.81473005E-1}, +{3.10509324E-1, 3.31732392E-1, 3.66864383E-1}, +{3.37470949E-1, 3.96795273E-1, 4.12356317E-1}, +{2.79660404E-1, 3.66520107E-1, 3.85313451E-1}, +{3.16038966E-1, 3.85609329E-1, 4.01304781E-1}, +{3.09960425E-1, 3.43410730E-1, 4.24745500E-1}, +{3.54243636E-1, 4.08699274E-1, 4.22167957E-1}, +{2.95587242E-1, 3.33741128E-1, 3.87421668E-1}, +{3.33446383E-1, 3.86974752E-1, 4.01353061E-1}, +{3.23412836E-1, 3.65269661E-1, 3.85193288E-1}, +{3.42731953E-1, 4.03192520E-1, 4.19920385E-1}, +{2.77681828E-1, 3.82494986E-1, 4.04274166E-1}, +{3.18247974E-1, 3.95985305E-1, 4.31353152E-1}, +{3.03711414E-1, 3.80319715E-1, 4.37173545E-1}, +{3.78288805E-1, 4.07077312E-1, 4.22679126E-1}, +{2.38116503E-1, 3.42454314E-1, 4.24624741E-1}, +{3.45615685E-1, 3.68681073E-1, 4.00817335E-1}, +{3.17688107E-1, 3.41902673E-1, 4.05601799E-1}, +{3.66368949E-1, 3.89039934E-1, 4.06154454E-1}, +{2.99398005E-1, 3.52021694E-1, 3.99955690E-1}, +{3.24991941E-1, 3.90028834E-1, 4.19478714E-1}, +{3.23025763E-1, 3.68114293E-1, 4.02087748E-1}, +{3.62326264E-1, 4.16927993E-1, 4.32773650E-1}, +{2.72696435E-1, 3.59205008E-1, 4.26880658E-1}, +{3.46539855E-1, 3.69616628E-1, 4.15621221E-1}, +{3.34109128E-1, 3.55736315E-1, 3.96749556E-1}, +{3.37468982E-1, 4.10392702E-1, 4.25986826E-1}, +{2.99468994E-1, 3.80648255E-1, 4.18284118E-1}, +{3.21378171E-1, 4.11198020E-1, 4.28792536E-1}, +{3.27841163E-1, 3.69345129E-1, 4.34395611E-1}, +{3.80669057E-1, 4.26086366E-1, 4.42754567E-1}, +{2.68943667E-1, 3.42942953E-1, 3.98681462E-1}, +{3.38102877E-1, 3.76338840E-1, 3.92043173E-1}, +{3.23593497E-1, 3.48742068E-1, 3.72551978E-1}, +{3.47550809E-1, 3.92885387E-1, 4.21169937E-1}, +{3.04182827E-1, 3.59816670E-1, 3.81633341E-1}, +{3.14221382E-1, 4.02108550E-1, 4.20085251E-1}, +{3.01306546E-1, 3.62662733E-1, 4.29262817E-1}, +{3.71770263E-1, 3.98696363E-1, 4.31438982E-1}, +{2.74591267E-1, 3.35595489E-1, 4.20079648E-1}, +{3.44540834E-1, 3.90451789E-1, 4.06412065E-1}, +{3.25239837E-1, 3.78344476E-1, 3.94673288E-1}, +{3.56683493E-1, 3.90574157E-1, 4.33851063E-1}, +{2.63501287E-1, 3.95260096E-1, 4.23116386E-1}, +{3.37520659E-1, 3.92563462E-1, 4.43415821E-1}, +{3.14522266E-1, 3.80968630E-1, 4.22676384E-1}, +{3.76235068E-1, 4.17298734E-1, 4.31451261E-1}, +{2.61855006E-1, 3.68646085E-1, 4.04260576E-1}, +{3.55580151E-1, 3.77994478E-1, 3.95868242E-1}, +{3.27742815E-1, 3.53872776E-1, 4.11040604E-1}, +{3.62960637E-1, 3.99466991E-1, 4.14690197E-1}, +{3.09410870E-1, 3.73796046E-1, 3.92672479E-1}, +{3.31016302E-1, 4.00801599E-1, 4.31759298E-1}, +{3.23573053E-1, 3.68619561E-1, 4.17455137E-1}, +{3.49115849E-1, 4.26840067E-1, 4.43913996E-1}, +{2.89738595E-1, 3.63759339E-1, 4.10511792E-1}, +{3.55286479E-1, 3.89331281E-1, 4.13432419E-1}, +{3.36565912E-1, 3.60222459E-1, 4.24179018E-1}, +{3.39932680E-1, 4.09228802E-1, 4.40184891E-1}, +{3.00889730E-1, 4.00081098E-1, 4.17955697E-1}, +{3.17052066E-1, 4.22288120E-1, 4.42229569E-1}, +{3.27336788E-1, 3.84311676E-1, 4.30288613E-1}, +{3.98990929E-1, 4.29498434E-1, 4.43475187E-1}, +{2.49110118E-1, 3.25696886E-1, 4.11728263E-1}, +{3.45929205E-1, 3.68577540E-1, 3.88473272E-1}, +{3.13219666E-1, 3.39229465E-1, 3.87597919E-1}, +{3.51453960E-1, 3.98730278E-1, 4.12656188E-1}, +{2.93487132E-1, 3.75763118E-1, 3.94488096E-1}, +{3.24470758E-1, 3.94202888E-1, 4.08882737E-1}, +{3.12710822E-1, 3.57720256E-1, 4.14061189E-1}, +{3.66507173E-1, 4.08171296E-1, 4.23891425E-1}, +{2.99965680E-1, 3.31993401E-1, 4.07860160E-1}, +{3.34925175E-1, 3.86143029E-1, 4.11538124E-1}, +{3.34788024E-1, 3.66196156E-1, 3.93347144E-1}, +{3.47847939E-1, 4.05926466E-1, 4.30507302E-1}, +{2.85952926E-1, 3.95283282E-1, 4.16119337E-1}, +{3.23867381E-1, 4.06476676E-1, 4.42482829E-1}, +{3.16716671E-1, 3.84451628E-1, 4.39411044E-1}, +{3.86772931E-1, 4.11824584E-1, 4.27831531E-1}, +{2.38072395E-1, 3.62342358E-1, 4.30931687E-1}, +{3.46450031E-1, 3.79082918E-1, 4.06567812E-1}, +{3.16576600E-1, 3.56468618E-1, 3.96218300E-1}, +{3.66539180E-1, 3.89590919E-1, 4.21055555E-1}, +{3.08291376E-1, 3.71324301E-1, 4.07867432E-1}, +{3.36435199E-1, 3.91514421E-1, 4.22977090E-1}, +{3.23035538E-1, 3.80447328E-1, 4.09550190E-1}, +{3.65228057E-1, 4.27910388E-1, 4.43691254E-1}, +{2.72038043E-1, 3.76596808E-1, 4.33685899E-1}, +{3.57665777E-1, 3.77761602E-1, 4.09178972E-1}, +{3.36498559E-1, 3.64215910E-1, 4.09255505E-1}, +{3.48082423E-1, 4.17631805E-1, 4.33284521E-1}, +{3.02754521E-1, 3.95974755E-1, 4.33717251E-1}, +{3.31676304E-1, 4.17587161E-1, 4.36239839E-1}, +{3.33287597E-1, 3.80799115E-1, 4.39620733E-1}, +{3.88112009E-1, 4.36933577E-1, 4.50829268E-1}, +{2.56026626E-1, 3.48015189E-1, 4.22922611E-1}, +{3.45773995E-1, 3.81725788E-1, 3.96794081E-1}, +{3.25623751E-1, 3.50391924E-1, 3.87330651E-1}, +{3.56868088E-1, 3.98574769E-1, 4.23177242E-1}, +{3.01226199E-1, 3.86906981E-1, 4.03335571E-1}, +{3.28178406E-1, 4.02090192E-1, 4.19389248E-1}, +{3.14385355E-1, 3.69043887E-1, 4.34375286E-1}, +{3.72321129E-1, 4.11672413E-1, 4.40518737E-1}, +{2.90479720E-1, 3.48121881E-1, 4.26216483E-1}, +{3.44438791E-1, 3.82666349E-1, 4.17321086E-1}, +{3.34866822E-1, 3.76235664E-1, 4.04475212E-1}, +{3.59025359E-1, 4.04721916E-1, 4.34838414E-1}, +{2.79127955E-1, 4.11106586E-1, 4.35360551E-1}, +{3.48125517E-1, 3.98732066E-1, 4.46927428E-1}, +{3.27018857E-1, 3.90107334E-1, 4.41707492E-1}, +{3.90858352E-1, 4.19813931E-1, 4.35153484E-1}, +{2.55319297E-1, 3.70405972E-1, 4.32188630E-1}, +{3.54651988E-1, 3.88332665E-1, 4.02956128E-1}, +{3.21608186E-1, 3.54489803E-1, 4.28299785E-1}, +{3.75163496E-1, 3.98833990E-1, 4.14177418E-1}, +{3.11953604E-1, 3.91430676E-1, 4.12552476E-1}, +{3.42528820E-1, 3.96365345E-1, 4.32497382E-1}, +{3.33744347E-1, 3.76422405E-1, 4.20536995E-1}, +{3.53529096E-1, 4.29231048E-1, 4.59699273E-1}, +{2.88017929E-1, 3.77999961E-1, 4.34011698E-1}, +{3.55683446E-1, 3.80780041E-1, 4.23145533E-1}, +{3.44358265E-1, 3.72184873E-1, 4.31265354E-1}, +{3.53966117E-1, 4.14166689E-1, 4.42941308E-1}, +{3.04770231E-1, 4.12517488E-1, 4.34183121E-1}, +{3.35913360E-1, 4.24590766E-1, 4.46378469E-1}, +{3.43738198E-1, 3.84766221E-1, 4.35271382E-1}, +{4.10941303E-1, 4.40662980E-1, 4.52113390E-1}}; + +static const float evrc_lspq_half_codebook1[128][3] = { +{1.35226343E-2, 1.82081293E-2, 3.93940695E-2}, +{2.29392890E-2, 3.57831158E-2, 1.05352886E-1}, +{2.09106486E-2, 3.04159056E-2, 8.93941075E-2}, +{1.88909005E-2, 3.82722206E-2, 1.37820408E-1}, +{2.05143820E-2, 2.85481159E-2, 7.39762187E-2}, +{4.69510332E-2, 6.84031919E-2, 1.09123811E-1}, +{3.15557197E-2, 5.69139980E-2, 8.57057571E-2}, +{3.81181911E-2, 7.77784660E-2, 1.92532852E-1}, +{2.16297153E-2, 2.92908940E-2, 6.25042021E-2}, +{3.11414022E-2, 5.99079318E-2, 1.02860682E-1}, +{3.02799307E-2, 5.35012372E-2, 7.80925751E-2}, +{6.50846213E-2, 9.06624720E-2, 1.42850950E-1}, +{3.27340364E-2, 5.04027791E-2, 6.26492277E-2}, +{5.27439862E-2, 6.22574277E-2, 1.22198336E-1}, +{3.48840356E-2, 6.42222390E-2, 9.16024595E-2}, +{4.88984436E-2, 1.05058022E-1, 1.68813452E-1}, +{2.35791076E-2, 3.21034677E-2, 5.60899563E-2}, +{2.77252812E-2, 4.87281792E-2, 1.01224191E-1}, +{2.74348017E-2, 4.04965915E-2, 9.34926122E-2}, +{4.38360050E-2, 6.03261292E-2, 1.52400866E-1}, +{2.68994924E-2, 4.52906378E-2, 6.49800375E-2}, +{5.16058952E-2, 6.08312152E-2, 1.08799636E-1}, +{4.20064926E-2, 6.11845106E-2, 8.54474008E-2}, +{7.13502690E-2, 1.01972111E-1, 1.74640998E-1}, +{2.88906675E-2, 4.13964354E-2, 5.25928028E-2}, +{3.16364467E-2, 6.63532093E-2, 1.24950245E-1}, +{4.30289507E-2, 5.14023267E-2, 7.96877742E-2}, +{5.70970774E-2, 1.08444504E-1, 1.44075617E-1}, +{3.38840261E-2, 5.04746847E-2, 7.29765445E-2}, +{6.54265657E-2, 7.90987685E-2, 1.15570590E-1}, +{3.85423526E-2, 7.33125433E-2, 1.02307513E-1}, +{6.57824501E-2, 1.02909811E-1, 2.11874440E-1}, +{1.54727865E-2, 2.04559695E-2, 5.46121262E-2}, +{2.27950197E-2, 3.90954204E-2, 1.19443826E-1}, +{3.06889173E-2, 4.54540215E-2, 8.20418894E-2}, +{2.25957241E-2, 4.79101725E-2, 1.71844408E-1}, +{2.71088015E-2, 4.01739590E-2, 7.01922849E-2}, +{4.95789349E-2, 7.92963281E-2, 1.04862511E-1}, +{3.06095853E-2, 5.64059429E-2, 9.49584097E-2}, +{6.34224564E-2, 9.11655501E-2, 1.84724405E-1}, +{2.43342388E-2, 3.91998328E-2, 6.31406233E-2}, +{3.38011980E-2, 6.60846457E-2, 1.11031540E-1}, +{3.51784080E-2, 5.79397269E-2, 7.20702857E-2}, +{6.49054050E-2, 8.65831897E-2, 1.54648736E-1}, +{2.91934665E-2, 5.16204573E-2, 6.94437325E-2}, +{5.94522804E-2, 7.19829276E-2, 1.27434507E-1}, +{5.31888530E-2, 6.38182089E-2, 9.88218486E-2}, +{8.68290961E-2, 1.41135350E-1, 1.91728458E-1}, +{2.49991138E-2, 3.62556018E-2, 5.03724031E-2}, +{2.82246377E-2, 5.44572286E-2, 1.12663500E-1}, +{3.62618119E-2, 4.59073223E-2, 9.43343639E-2}, +{5.70455343E-2, 7.46300444E-2, 1.59157172E-1}, +{2.72987466E-2, 4.56625856E-2, 7.52529651E-2}, +{5.12860194E-2, 8.51126984E-2, 1.23587973E-1}, +{4.91451994E-2, 5.93483113E-2, 9.22686011E-2}, +{7.06961900E-2, 1.05451979E-1, 1.92602143E-1}, +{2.80733760E-2, 4.18509208E-2, 5.87159805E-2}, +{4.64449003E-2, 7.06698820E-2, 1.26038432E-1}, +{4.18453738E-2, 6.30445331E-2, 7.66169876E-2}, +{8.42416435E-2, 1.13282882E-1, 1.43687114E-1}, +{4.17615622E-2, 5.59472926E-2, 7.09872842E-2}, +{5.55161387E-2, 9.50126722E-2, 1.27727196E-1}, +{5.90935498E-2, 7.36730024E-2, 9.65935886E-2}, +{7.84136653E-2, 1.41432360E-1, 2.17428640E-1}, +{2.10490543E-2, 2.91891042E-2, 4.60035764E-2}, +{3.64863276E-2, 4.62387018E-2, 1.07044168E-1}, +{2.68652122E-2, 3.92937548E-2, 8.41179937E-2}, +{2.72903945E-2, 5.53805046E-2, 1.41586170E-1}, +{2.48476695E-2, 3.63277681E-2, 7.62430876E-2}, +{5.25430813E-2, 7.75778666E-2, 1.14567965E-1}, +{4.07741442E-2, 5.39923795E-2, 9.07640457E-2}, +{5.73043302E-2, 7.65803084E-2, 1.79578975E-1}, +{2.46032421E-2, 3.41408364E-2, 6.78990781E-2}, +{4.08220068E-2, 6.29783794E-2, 9.95191261E-2}, +{3.83025035E-2, 5.52857481E-2, 7.90019333E-2}, +{7.24111274E-2, 1.01903863E-1, 1.46979645E-1}, +{3.73902172E-2, 4.70463894E-2, 6.54684529E-2}, +{5.27397543E-2, 6.72770366E-2, 1.39680430E-1}, +{4.05365378E-2, 7.05081299E-2, 9.25668627E-2}, +{4.43425253E-2, 1.10367171E-1, 1.99636266E-1}, +{2.54920740E-2, 3.47603969E-2, 6.05902039E-2}, +{4.35465500E-2, 5.32369502E-2, 1.08325966E-1}, +{2.79599819E-2, 4.91324775E-2, 8.84284526E-2}, +{4.98051867E-2, 8.81728902E-2, 1.52597323E-1}, +{3.19346264E-2, 4.62169312E-2, 6.85206428E-2}, +{5.80246300E-2, 6.84268698E-2, 1.15085281E-1}, +{4.33904678E-2, 6.90575615E-2, 8.44984353E-2}, +{7.39691556E-2, 1.19240515E-1, 1.77340195E-1}, +{3.18767503E-2, 4.59697433E-2, 5.72372638E-2}, +{4.50873822E-2, 5.66509366E-2, 1.32005826E-1}, +{4.59097028E-2, 5.45580424E-2, 8.61423314E-2}, +{7.44685754E-2, 1.13815404E-1, 1.61570594E-1}, +{3.97509560E-2, 4.95359488E-2, 7.22542256E-2}, +{6.76257759E-2, 8.31029043E-2, 1.27990112E-1}, +{5.76258078E-2, 6.95326403E-2, 1.05012968E-1}, +{6.85313493E-2, 1.21758826E-1, 2.20626548E-1}, +{2.18480472E-2, 2.99130920E-2, 5.16208000E-2}, +{3.64343151E-2, 4.91795056E-2, 1.23277210E-1}, +{3.89611274E-2, 4.76634987E-2, 8.61716568E-2}, +{4.14635167E-2, 6.88006952E-2, 1.69356152E-1}, +{3.35514620E-2, 4.17815186E-2, 7.37159401E-2}, +{5.80224693E-2, 8.70314166E-2, 1.12917498E-1}, +{4.80243117E-2, 5.69486506E-2, 1.00755706E-1}, +{5.98873124E-2, 8.57942328E-2, 2.01388851E-1}, +{2.99309995E-2, 3.94828431E-2, 6.46376088E-2}, +{3.88626605E-2, 8.07443634E-2, 1.15519784E-1}, +{3.49444002E-2, 6.28911033E-2, 8.04982036E-2}, +{6.88817874E-2, 9.92431119E-2, 1.60393253E-1}, +{3.64237651E-2, 5.34016453E-2, 6.70152009E-2}, +{5.83492741E-2, 7.85285756E-2, 1.41746715E-1}, +{4.86469641E-2, 7.26736858E-2, 9.48315859E-2}, +{5.85533604E-2, 1.36289746E-1, 1.98639736E-1}, +{2.60888506E-2, 3.73406820E-2, 5.57853170E-2}, +{4.58504409E-2, 5.60512505E-2, 1.17927872E-1}, +{4.28801328E-2, 5.14739119E-2, 9.75309014E-2}, +{6.37611598E-2, 8.73552933E-2, 1.68334916E-1}, +{3.76709923E-2, 4.58216034E-2, 7.86528140E-2}, +{6.75194561E-2, 8.98697898E-2, 1.19418114E-1}, +{5.46374246E-2, 6.66805878E-2, 8.93813819E-2}, +{7.73086548E-2, 1.21754415E-1, 1.99579224E-1}, +{3.15621309E-2, 4.51702215E-2, 6.25768527E-2}, +{3.78782675E-2, 8.03486481E-2, 1.38961688E-1}, +{5.08303270E-2, 6.18740581E-2, 8.31153840E-2}, +{8.96311402E-2, 1.28753766E-1, 1.64891586E-1}, +{4.73503470E-2, 5.75724356E-2, 7.65264630E-2}, +{7.16898590E-2, 9.89895687E-2, 1.30078360E-1}, +{6.29082546E-2, 7.90778771E-2, 1.05111063E-1}, +{8.80649835E-2, 1.65206164E-1, 2.13214174E-1}}; + +static const float evrc_lspq_half_codebook2[128][3] = { +{9.75915268E-2, 1.23701490E-1, 1.69437975E-1}, +{9.49536338E-2, 2.01081768E-1, 2.26855248E-1}, +{9.00496617E-2, 1.49164870E-1, 2.26532787E-1}, +{1.70302704E-1, 1.97222874E-1, 2.49974832E-1}, +{1.08773641E-1, 1.51972428E-1, 1.75123364E-1}, +{1.30278930E-1, 2.13229164E-1, 2.29646355E-1}, +{1.24917991E-1, 1.87347755E-1, 2.04712003E-1}, +{2.00670198E-1, 2.28963569E-1, 2.69420803E-1}, +{8.98375586E-2, 1.25332758E-1, 2.10539430E-1}, +{9.62376669E-2, 2.07185850E-1, 2.54174471E-1}, +{1.05694629E-1, 1.78856418E-1, 2.00121015E-1}, +{1.56048968E-1, 2.19573721E-1, 2.91079402E-1}, +{1.37392268E-1, 1.59993336E-1, 1.94698542E-1}, +{1.07262500E-1, 2.37790957E-1, 2.70740807E-1}, +{1.42976448E-1, 2.01550499E-1, 2.18468934E-1}, +{2.14270487E-1, 2.71881402E-1, 3.01200211E-1}, +{1.10729210E-1, 1.33688226E-1, 1.54877156E-1}, +{1.06667660E-1, 1.76678821E-1, 2.62798905E-1}, +{9.16352943E-2, 1.74592838E-1, 2.19329327E-1}, +{1.84038624E-1, 2.27964059E-1, 2.47762203E-1}, +{1.10572360E-1, 1.58207163E-1, 1.96013063E-1}, +{1.33543387E-1, 2.32269660E-1, 2.51828164E-1}, +{1.55922309E-1, 1.77941337E-1, 2.18096644E-1}, +{1.92260072E-1, 2.49512479E-1, 2.89911509E-1}, +{1.13708906E-1, 1.37872443E-1, 2.02929884E-1}, +{1.02557532E-1, 1.84820071E-1, 2.92164624E-1}, +{1.36595622E-1, 1.58687428E-1, 2.41399556E-1}, +{1.72813818E-1, 2.49303415E-1, 3.00458610E-1}, +{1.36871174E-1, 1.57249823E-1, 2.10913152E-1}, +{1.28974810E-1, 2.45167866E-1, 2.67653584E-1}, +{1.66812256E-1, 1.88998029E-1, 2.31345922E-1}, +{2.32248470E-1, 2.63196051E-1, 3.16754937E-1}, +{9.24560949E-2, 1.19977452E-1, 1.91262275E-1}, +{1.13085262E-1, 2.08461538E-1, 2.29368120E-1}, +{1.00716405E-1, 1.40670076E-1, 2.58062959E-1}, +{1.67010382E-1, 2.18105540E-1, 2.62592494E-1}, +{1.25487238E-1, 1.62686959E-1, 1.84409231E-1}, +{1.52406558E-1, 2.07131729E-1, 2.47582436E-1}, +{1.37441203E-1, 1.80262372E-1, 2.17698842E-1}, +{2.07853511E-1, 2.49209508E-1, 2.69830108E-1}, +{9.35257301E-2, 1.49197355E-1, 2.04652041E-1}, +{1.11997180E-1, 2.25233063E-1, 2.47003049E-1}, +{1.09315015E-1, 1.93811879E-1, 2.13802189E-1}, +{1.75118580E-1, 2.52520263E-1, 2.75082767E-1}, +{1.36918738E-1, 1.77440569E-1, 1.97931141E-1}, +{1.36811242E-1, 2.37426177E-1, 2.84737825E-1}, +{1.60759792E-1, 2.00833157E-1, 2.18084484E-1}, +{2.33710244E-1, 2.66372561E-1, 2.91802049E-1}, +{1.19171090E-1, 1.39703169E-1, 1.87723249E-1}, +{1.31049946E-1, 1.93696663E-1, 2.60426998E-1}, +{1.08267047E-1, 1.65194795E-1, 2.39523023E-1}, +{2.03195021E-1, 2.25942209E-1, 2.49403238E-1}, +{1.23842932E-1, 1.45794615E-1, 2.15635628E-1}, +{1.71226338E-1, 2.38054529E-1, 2.57975638E-1}, +{1.66923836E-1, 1.88604668E-1, 2.11124212E-1}, +{2.10620746E-1, 2.62442708E-1, 2.83127964E-1}, +{1.05748810E-1, 1.36286482E-1, 2.20050186E-1}, +{9.72945765E-2, 2.33471528E-1, 2.96113968E-1}, +{1.34298369E-1, 1.93955436E-1, 2.39148825E-1}, +{1.64229318E-1, 2.70067751E-1, 2.94142485E-1}, +{1.42760262E-1, 1.65033355E-1, 2.24100381E-1}, +{1.46414533E-1, 2.47942328E-1, 3.00708115E-1}, +{1.74778774E-1, 2.19349250E-1, 2.38162965E-1}, +{2.36311123E-1, 2.90669680E-1, 3.28010976E-1}, +{1.14076428E-1, 1.33071408E-1, 1.73181504E-1}, +{1.13575839E-1, 1.90307274E-1, 2.41681188E-1}, +{8.59165266E-2, 1.63920239E-1, 2.37934500E-1}, +{1.92916945E-1, 2.15082392E-1, 2.39128128E-1}, +{1.37291834E-1, 1.59423307E-1, 1.79722220E-1}, +{1.40435383E-1, 2.22092256E-1, 2.40960747E-1}, +{1.40387163E-1, 1.89601168E-1, 2.05635697E-1}, +{2.11695507E-1, 2.36578360E-1, 2.81248927E-1}, +{9.03010592E-2, 1.27157405E-1, 2.33567923E-1}, +{1.10118054E-1, 2.09328398E-1, 2.72836268E-1}, +{1.16710417E-1, 1.77853987E-1, 2.22808748E-1}, +{1.81691542E-1, 2.32265159E-1, 2.74991214E-1}, +{1.46553472E-1, 1.69474706E-1, 1.90245956E-1}, +{1.09213792E-1, 2.63291955E-1, 2.88490772E-1}, +{1.49815127E-1, 2.11342707E-1, 2.28899449E-1}, +{1.97645500E-1, 2.83229947E-1, 3.14882278E-1}, +{1.24495603E-1, 1.46097973E-1, 1.66125208E-1}, +{1.34878591E-1, 1.83030054E-1, 2.89288282E-1}, +{9.33032110E-2, 1.83962211E-1, 2.38543004E-1}, +{1.92844257E-1, 2.39588335E-1, 2.58421540E-1}, +{1.23796798E-1, 1.65556595E-1, 2.08408386E-1}, +{1.51144341E-1, 2.35801116E-1, 2.59280622E-1}, +{1.50657728E-1, 1.90052524E-1, 2.28362590E-1}, +{1.98180959E-1, 2.56794214E-1, 3.08975637E-1}, +{1.28490031E-1, 1.49084017E-1, 1.98376507E-1}, +{9.20595750E-2, 2.12231293E-1, 2.92948842E-1}, +{1.41698137E-1, 1.72356680E-1, 2.58454144E-1}, +{1.96733460E-1, 2.29709730E-1, 2.95780182E-1}, +{1.47062227E-1, 1.68918088E-1, 2.07363635E-1}, +{1.36309877E-1, 2.60373056E-1, 2.82607377E-1}, +{1.81041077E-1, 2.01826140E-1, 2.38867551E-1}, +{2.45326266E-1, 2.80183077E-1, 3.11954319E-1}, +{1.04131766E-1, 1.33040652E-1, 1.89834684E-1}, +{1.23298146E-1, 2.09621087E-1, 2.47813210E-1}, +{1.24040775E-1, 1.59827366E-1, 2.58856058E-1}, +{1.87048867E-1, 2.12488100E-1, 2.59629130E-1}, +{1.24255307E-1, 1.73768952E-1, 1.92850024E-1}, +{1.58917829E-1, 2.25389823E-1, 2.43284762E-1}, +{1.53421149E-1, 1.91807315E-1, 2.09249526E-1}, +{2.27154449E-1, 2.51181155E-1, 2.72600353E-1}, +{1.09922059E-1, 1.57100275E-1, 2.20024973E-1}, +{1.32782355E-1, 2.19485506E-1, 2.67028928E-1}, +{1.26857504E-1, 1.98836312E-1, 2.17928499E-1}, +{1.91415027E-1, 2.52424240E-1, 2.72652745E-1}, +{1.55277625E-1, 1.79573521E-1, 2.00773627E-1}, +{1.17547743E-1, 2.47869864E-1, 3.08279335E-1}, +{1.65706977E-1, 2.10339502E-1, 2.29199320E-1}, +{2.25694910E-1, 2.84438193E-1, 3.12106073E-1}, +{1.29503176E-1, 1.48420051E-1, 1.80180401E-1}, +{1.54752508E-1, 1.97748467E-1, 2.67275035E-1}, +{1.28590241E-1, 1.76178381E-1, 2.39905864E-1}, +{2.14926764E-1, 2.37634435E-1, 2.58794010E-1}, +{1.28322318E-1, 1.59338519E-1, 2.26626605E-1}, +{1.55747548E-1, 2.47740522E-1, 2.73726821E-1}, +{1.75741687E-1, 1.97952345E-1, 2.19115943E-1}, +{2.18626365E-1, 2.45809183E-1, 3.00479650E-1}, +{1.17709018E-1, 1.45512864E-1, 2.38044471E-1}, +{1.18006893E-1, 2.23775521E-1, 2.94175088E-1}, +{1.51349202E-1, 1.88157812E-1, 2.48743281E-1}, +{1.89312205E-1, 2.69580543E-1, 2.93785989E-1}, +{1.49895594E-1, 1.74537256E-1, 2.37430006E-1}, +{1.39775530E-1, 2.71709383E-1, 3.07839513E-1}, +{1.83945730E-1, 2.07717165E-1, 2.26722151E-1}, +{2.54552156E-1, 2.96640933E-1, 3.24801445E-1}}; + +static const float evrc_lspq_half_codebook3[256][4] = { +{2.36904725E-1, 2.56104350E-1, 3.16955745E-1, 4.07520533E-1}, +{2.97596931E-1, 3.23482454E-1, 3.47667515E-1, 3.74551237E-1}, +{2.73721159E-1, 2.98297524E-1, 3.29923928E-1, 3.83599102E-1}, +{3.07849586E-1, 3.32836270E-1, 3.89340341E-1, 4.05575991E-1}, +{2.33803615E-1, 2.60296524E-1, 3.67351949E-1, 4.04388249E-1}, +{2.97513664E-1, 3.15356553E-1, 3.85135233E-1, 4.02197123E-1}, +{2.85618782E-1, 3.10872793E-1, 3.65022361E-1, 3.84816766E-1}, +{3.35271597E-1, 3.55222225E-1, 3.81921113E-1, 3.98685753E-1}, +{2.00265601E-1, 2.50502288E-1, 3.70398223E-1, 4.32012677E-1}, +{3.07982087E-1, 3.33767712E-1, 3.58199060E-1, 3.78386796E-1}, +{2.60086119E-1, 3.25520277E-1, 3.56873333E-1, 3.84737790E-1}, +{3.01356375E-1, 3.41369390E-1, 4.00296748E-1, 4.17337179E-1}, +{2.67080963E-1, 2.97674358E-1, 3.69702041E-1, 3.89139235E-1}, +{2.72669852E-1, 3.49704087E-1, 3.91925275E-1, 4.06383276E-1}, +{2.52825916E-1, 3.49636555E-1, 3.84550989E-1, 4.05930996E-1}, +{3.42927098E-1, 3.74274015E-1, 4.05468166E-1, 4.20351923E-1}, +{2.52408743E-1, 2.80375838E-1, 3.21436584E-1, 3.88436913E-1}, +{2.96970189E-1, 3.17173600E-1, 3.65342557E-1, 4.02736843E-1}, +{2.81905174E-1, 3.01479161E-1, 3.34335625E-1, 4.07633483E-1}, +{3.26872945E-1, 3.47177684E-1, 3.75017703E-1, 4.05372381E-1}, +{2.36371145E-1, 3.16441059E-1, 3.48707020E-1, 3.82030427E-1}, +{2.87817597E-1, 3.13627005E-1, 4.05129731E-1, 4.23379660E-1}, +{2.77502477E-1, 3.01843822E-1, 3.72250855E-1, 4.19212818E-1}, +{3.28988850E-1, 3.61901104E-1, 4.02015507E-1, 4.19229805E-1}, +{2.24960461E-1, 2.74636388E-1, 3.77016127E-1, 3.94726515E-1}, +{3.01045477E-1, 3.40486169E-1, 3.74888122E-1, 4.02532160E-1}, +{2.59897947E-1, 3.30334961E-1, 3.57493818E-1, 4.08657968E-1}, +{3.00961852E-1, 3.56449068E-1, 4.04779494E-1, 4.22508955E-1}, +{2.20979586E-1, 3.16477656E-1, 4.01744068E-1, 4.20735776E-1}, +{2.79754996E-1, 3.30776095E-1, 4.11152899E-1, 4.32687044E-1}, +{2.64246881E-1, 3.16610634E-1, 3.83876741E-1, 4.36683774E-1}, +{3.44381154E-1, 3.85365665E-1, 4.24949467E-1, 4.41560209E-1}, +{2.19488308E-1, 2.36459881E-1, 3.42465997E-1, 4.24989998E-1}, +{2.91465104E-1, 3.22282016E-1, 3.72852802E-1, 3.91635895E-1}, +{2.74792433E-1, 3.16536307E-1, 3.45392585E-1, 3.74555230E-1}, +{3.10583472E-1, 3.35264921E-1, 3.87527227E-1, 4.23076212E-1}, +{2.23211512E-1, 2.98497617E-1, 3.68426204E-1, 3.90213728E-1}, +{2.89078832E-1, 3.26512754E-1, 3.76308680E-1, 4.09553707E-1}, +{2.63830125E-1, 3.08977246E-1, 3.81453037E-1, 4.04660761E-1}, +{3.47073615E-1, 3.64797831E-1, 3.86763453E-1, 4.04511690E-1}, +{2.18452707E-1, 2.75614083E-1, 3.62711072E-1, 4.18278992E-1}, +{3.15042794E-1, 3.40813220E-1, 3.78627181E-1, 3.96316767E-1}, +{2.79727697E-1, 3.31259727E-1, 3.60061288E-1, 3.81175518E-1}, +{3.18602443E-1, 3.38044286E-1, 4.09010768E-1, 4.30300415E-1}, +{2.64196932E-1, 2.90672481E-1, 3.68595004E-1, 4.31856751E-1}, +{2.72645593E-1, 3.63514841E-1, 3.96518826E-1, 4.20091212E-1}, +{2.26540968E-1, 3.50055099E-1, 3.93851519E-1, 4.12597001E-1}, +{3.53053868E-1, 3.69929552E-1, 4.09656048E-1, 4.26387310E-1}, +{2.60788381E-1, 2.85172462E-1, 3.45943332E-1, 3.97500694E-1}, +{3.01113129E-1, 3.28201890E-1, 3.56068015E-1, 4.10803795E-1}, +{2.88101614E-1, 3.09559643E-1, 3.43756795E-1, 4.24872875E-1}, +{3.10489357E-1, 3.51421893E-1, 3.93717408E-1, 4.15550530E-1}, +{2.22308263E-1, 3.26798201E-1, 3.77981663E-1, 3.98635030E-1}, +{3.02915514E-1, 3.22781920E-1, 3.98558855E-1, 4.25489604E-1}, +{2.77136803E-1, 3.19992602E-1, 3.77490878E-1, 4.29177463E-1}, +{3.38731766E-1, 3.58164370E-1, 4.08386350E-1, 4.25495386E-1}, +{2.18726233E-1, 2.84384966E-1, 3.94053698E-1, 4.16346967E-1}, +{3.01005960E-1, 3.44093680E-1, 3.69013667E-1, 4.15091276E-1}, +{2.80783713E-1, 3.33053648E-1, 3.76726151E-1, 3.97526860E-1}, +{3.14394057E-1, 3.62678826E-1, 4.23668981E-1, 4.41899240E-1}, +{2.66453624E-1, 3.08513761E-1, 3.97407174E-1, 4.17450190E-1}, +{2.94222653E-1, 3.41904402E-1, 4.12726879E-1, 4.34888899E-1}, +{2.87300706E-1, 3.32434595E-1, 3.78856659E-1, 4.38234031E-1}, +{3.57146621E-1, 3.98147047E-1, 4.29875731E-1, 4.44243908E-1}, +{2.29671344E-1, 2.51018614E-1, 3.41046572E-1, 4.04376328E-1}, +{2.94472575E-1, 3.34944606E-1, 3.60409737E-1, 3.83682847E-1}, +{2.88250983E-1, 3.11722696E-1, 3.31680059E-1, 3.65104675E-1}, +{3.24881613E-1, 3.45656693E-1, 3.88306379E-1, 4.05954897E-1}, +{2.50829220E-1, 2.77623534E-1, 3.70799541E-1, 3.90479207E-1}, +{2.93523371E-1, 3.28319192E-1, 3.92112255E-1, 4.09464061E-1}, +{2.83608794E-1, 3.03885639E-1, 3.78504395E-1, 3.97310555E-1}, +{3.34039807E-1, 3.52837384E-1, 3.97272944E-1, 4.14322019E-1}, +{2.21891895E-1, 2.51877457E-1, 3.71723533E-1, 4.31791008E-1}, +{3.13201427E-1, 3.41175437E-1, 3.65503550E-1, 3.88567209E-1}, +{2.71330535E-1, 3.39163721E-1, 3.62616420E-1, 3.95735979E-1}, +{3.07550132E-1, 3.47777665E-1, 4.01049614E-1, 4.32767451E-1}, +{2.59387434E-1, 2.87243843E-1, 3.86817336E-1, 4.06042695E-1}, +{2.85485208E-1, 3.44094992E-1, 4.02050495E-1, 4.19413745E-1}, +{2.65781403E-1, 3.40084374E-1, 3.69407654E-1, 4.27031696E-1}, +{3.53740931E-1, 3.84463251E-1, 4.11747813E-1, 4.26181793E-1}, +{2.43866488E-1, 2.68350184E-1, 3.42201948E-1, 3.98457229E-1}, +{2.93145239E-1, 3.34754169E-1, 3.61702800E-1, 3.98416638E-1}, +{2.91342974E-1, 3.13155174E-1, 3.36525917E-1, 3.87748599E-1}, +{3.05656791E-1, 3.62904549E-1, 3.88153434E-1, 4.05543149E-1}, +{2.17492327E-1, 3.11723530E-1, 3.75984788E-1, 4.28997755E-1}, +{2.91149259E-1, 3.29380929E-1, 4.03900385E-1, 4.22333181E-1}, +{2.90362060E-1, 3.09530973E-1, 3.78994226E-1, 4.13688362E-1}, +{3.29564869E-1, 3.77404690E-1, 4.06584859E-1, 4.24739718E-1}, +{2.46461585E-1, 2.71593273E-1, 3.66338253E-1, 4.30753767E-1}, +{3.14107716E-1, 3.37011874E-1, 3.80409718E-1, 4.11099434E-1}, +{2.76568413E-1, 3.27320695E-1, 3.58844280E-1, 4.28949475E-1}, +{3.17179084E-1, 3.58972430E-1, 4.04765844E-1, 4.40376341E-1}, +{2.42777750E-1, 3.34954798E-1, 3.96943450E-1, 4.13318396E-1}, +{2.88895488E-1, 3.25691164E-1, 4.22859550E-1, 4.43758667E-1}, +{2.77583301E-1, 3.25479031E-1, 3.89144659E-1, 4.41075861E-1}, +{3.59125674E-1, 3.90694141E-1, 4.21009541E-1, 4.35708523E-1}, +{2.20172390E-1, 2.47719273E-1, 3.54381859E-1, 4.25398111E-1}, +{3.06046784E-1, 3.27924728E-1, 3.66992772E-1, 3.93192589E-1}, +{2.70805597E-1, 3.16826642E-1, 3.45648706E-1, 4.11717594E-1}, +{3.23188901E-1, 3.45463097E-1, 3.89778793E-1, 4.21570778E-1}, +{2.46136114E-1, 3.12391996E-1, 3.72188628E-1, 3.95842731E-1}, +{3.03856730E-1, 3.24354768E-1, 3.85747254E-1, 4.14155006E-1}, +{2.81075418E-1, 3.18608463E-1, 3.85646880E-1, 4.02703643E-1}, +{3.53517115E-1, 3.72702539E-1, 3.96264613E-1, 4.13074911E-1}, +{2.09221140E-1, 2.95262218E-1, 3.80314291E-1, 4.31278229E-1}, +{3.25313628E-1, 3.46735477E-1, 3.70724022E-1, 3.91045630E-1}, +{2.86396503E-1, 3.43560040E-1, 3.69713604E-1, 3.89867842E-1}, +{3.27794671E-1, 3.47367823E-1, 4.05465066E-1, 4.24566150E-1}, +{2.53054976E-1, 3.02656293E-1, 3.82165134E-1, 4.29898322E-1}, +{2.94418454E-1, 3.70745420E-1, 3.95443261E-1, 4.19514775E-1}, +{2.62873113E-1, 3.45069230E-1, 4.04140890E-1, 4.21902061E-1}, +{3.65063488E-1, 3.82435143E-1, 4.13424790E-1, 4.31241691E-1}, +{2.48788506E-1, 2.82372773E-1, 3.65772307E-1, 4.10981059E-1}, +{3.07288766E-1, 3.27828944E-1, 3.77664983E-1, 4.36220944E-1}, +{2.98542321E-1, 3.20627332E-1, 3.50569665E-1, 4.27620232E-1}, +{3.16258013E-1, 3.62903833E-1, 3.88225138E-1, 4.25608873E-1}, +{2.39077866E-1, 3.31310451E-1, 3.70317876E-1, 4.15995896E-1}, +{3.03735793E-1, 3.32806051E-1, 4.10232842E-1, 4.27751064E-1}, +{2.96002507E-1, 3.19014788E-1, 3.81062448E-1, 4.26954985E-1}, +{3.32508922E-1, 3.62516999E-1, 4.23315108E-1, 4.40995157E-1}, +{2.35128701E-1, 2.74731100E-1, 4.12070572E-1, 4.35478806E-1}, +{2.98073769E-1, 3.55338752E-1, 3.79087746E-1, 4.15318787E-1}, +{2.83429801E-1, 3.45264912E-1, 3.70376289E-1, 4.09900844E-1}, +{3.23593080E-1, 3.65412831E-1, 4.12813127E-1, 4.31023479E-1}, +{2.76626348E-1, 3.00508440E-1, 4.02236879E-1, 4.26638782E-1}, +{2.94512928E-1, 3.61443222E-1, 4.19635236E-1, 4.36999202E-1}, +{2.90807247E-1, 3.41689348E-1, 3.92779291E-1, 4.43490267E-1}, +{3.59391451E-1, 4.03985143E-1, 4.40843761E-1, 4.53028619E-1}, +{2.23295465E-1, 2.39192486E-1, 3.23768020E-1, 4.21689451E-1}, +{2.94778049E-1, 3.18798721E-1, 3.53217840E-1, 3.91906381E-1}, +{2.59032130E-1, 3.10240507E-1, 3.43569040E-1, 3.95064235E-1}, +{3.16474676E-1, 3.38544369E-1, 3.93329024E-1, 4.12235558E-1}, +{2.40108207E-1, 2.84631193E-1, 3.60280991E-1, 3.79973769E-1}, +{2.96909094E-1, 3.15798342E-1, 3.94964337E-1, 4.15127575E-1}, +{2.85434067E-1, 3.04921508E-1, 3.61974716E-1, 4.05767262E-1}, +{3.37407053E-1, 3.56672168E-1, 3.85155082E-1, 4.11186695E-1}, +{2.24014923E-1, 2.60116160E-1, 3.94772530E-1, 4.19585884E-1}, +{3.00647914E-1, 3.41640651E-1, 3.70223522E-1, 3.89520049E-1}, +{2.65946031E-1, 3.25039148E-1, 3.74339938E-1, 3.92346144E-1}, +{3.16029310E-1, 3.40491295E-1, 4.02355313E-1, 4.20484245E-1}, +{2.69841492E-1, 2.94562399E-1, 3.62341762E-1, 4.06415462E-1}, +{2.78897285E-1, 3.59831035E-1, 3.82025838E-1, 4.10577476E-1}, +{2.60760844E-1, 3.31088543E-1, 3.88826251E-1, 4.05486643E-1}, +{3.43372285E-1, 3.82647038E-1, 4.14716601E-1, 4.31592941E-1}, +{2.47998103E-1, 2.73393154E-1, 3.31160426E-1, 4.18943226E-1}, +{3.03579569E-1, 3.25202465E-1, 3.70984435E-1, 4.14420485E-1}, +{2.76896894E-1, 3.00499499E-1, 3.54178190E-1, 4.28807020E-1}, +{3.23655546E-1, 3.59816968E-1, 3.89525414E-1, 4.09288704E-1}, +{2.38927796E-1, 3.09919238E-1, 3.53915572E-1, 4.16634321E-1}, +{2.81171739E-1, 3.07520270E-1, 4.16264892E-1, 4.38523829E-1}, +{2.88858652E-1, 3.09810817E-1, 3.67845178E-1, 4.36035573E-1}, +{3.38423491E-1, 3.70634377E-1, 4.15449977E-1, 4.31534529E-1}, +{2.41260394E-1, 2.73617864E-1, 3.89554620E-1, 4.12539542E-1}, +{2.98046708E-1, 3.40122104E-1, 3.86183739E-1, 4.13826346E-1}, +{2.82436430E-1, 3.31597507E-1, 3.57941389E-1, 4.12115216E-1}, +{3.03820193E-1, 3.70588601E-1, 4.05774951E-1, 4.31517065E-1}, +{2.39077732E-1, 3.11638474E-1, 4.13935781E-1, 4.35304046E-1}, +{2.67116845E-1, 3.41937900E-1, 4.17409420E-1, 4.39184844E-1}, +{2.67946839E-1, 3.33343923E-1, 3.86481404E-1, 4.37462509E-1}, +{3.40510964E-1, 3.90878022E-1, 4.35485125E-1, 4.49101925E-1}, +{2.10069850E-1, 2.32524484E-1, 3.61781418E-1, 4.31357861E-1}, +{2.94509888E-1, 3.33709776E-1, 3.82278621E-1, 3.98638904E-1}, +{2.80525148E-1, 3.25905204E-1, 3.50647032E-1, 3.92873943E-1}, +{3.19999635E-1, 3.43674660E-1, 3.91070545E-1, 4.37501073E-1}, +{2.20581010E-1, 3.03151906E-1, 3.81765544E-1, 4.04488146E-1}, +{2.86122739E-1, 3.29746544E-1, 3.88102829E-1, 4.24247742E-1}, +{2.69807100E-1, 3.25332284E-1, 3.79154503E-1, 4.15138245E-1}, +{3.34858894E-1, 3.69258404E-1, 3.94743145E-1, 4.11922157E-1}, +{2.07109794E-1, 2.72779524E-1, 3.78566444E-1, 4.34579968E-1}, +{3.06466222E-1, 3.46695721E-1, 3.87138307E-1, 4.03558314E-1}, +{2.70148575E-1, 3.46654534E-1, 3.77696693E-1, 3.96434486E-1}, +{3.18745911E-1, 3.40225697E-1, 4.14991558E-1, 4.41578746E-1}, +{2.58592844E-1, 3.14370096E-1, 3.65083754E-1, 4.21615183E-1}, +{2.82712996E-1, 3.54137123E-1, 4.06745970E-1, 4.29267883E-1}, +{2.52021760E-1, 3.59105110E-1, 3.95102918E-1, 4.18148398E-1}, +{3.54906201E-1, 3.74952912E-1, 4.18965995E-1, 4.36144412E-1}, +{2.64841139E-1, 2.92941809E-1, 3.27751458E-1, 4.08790469E-1}, +{3.07774246E-1, 3.35586190E-1, 3.62209618E-1, 4.25394237E-1}, +{2.88466334E-1, 3.16075742E-1, 3.60989630E-1, 4.19551432E-1}, +{3.17128420E-1, 3.55772197E-1, 4.05808747E-1, 4.23972964E-1}, +{2.47089684E-1, 3.38184595E-1, 3.71859610E-1, 3.95971477E-1}, +{3.07981730E-1, 3.32691789E-1, 4.00534213E-1, 4.38273668E-1}, +{2.79484808E-1, 3.16183507E-1, 3.97237718E-1, 4.34746623E-1}, +{3.44490469E-1, 3.66153181E-1, 4.10959423E-1, 4.41727102E-1}, +{2.35741779E-1, 2.94587255E-1, 3.98072541E-1, 4.16833401E-1}, +{3.14038455E-1, 3.52272034E-1, 3.79138887E-1, 4.10969079E-1}, +{2.83002496E-1, 3.38136256E-1, 3.88641894E-1, 4.06193316E-1}, +{3.23625326E-1, 3.50243390E-1, 4.28089559E-1, 4.46630359E-1}, +{2.61252105E-1, 3.24970961E-1, 4.00214493E-1, 4.25321758E-1}, +{3.05284500E-1, 3.42164159E-1, 4.24475133E-1, 4.43830967E-1}, +{2.87374794E-1, 3.32500637E-1, 3.94308269E-1, 4.42538500E-1}, +{3.74075353E-1, 4.02026355E-1, 4.30933535E-1, 4.44160044E-1}, +{2.34503999E-1, 2.56218612E-1, 3.41238797E-1, 4.23045278E-1}, +{3.05492580E-1, 3.29156995E-1, 3.52709830E-1, 3.92439067E-1}, +{2.81323552E-1, 3.03292334E-1, 3.48925412E-1, 3.93163860E-1}, +{3.21893454E-1, 3.50419939E-1, 3.97317469E-1, 4.14560318E-1}, +{2.39684582E-1, 2.92451501E-1, 3.78937423E-1, 3.96535456E-1}, +{3.07307243E-1, 3.29127908E-1, 3.98455560E-1, 4.16143298E-1}, +{2.85274565E-1, 3.08774531E-1, 3.92916501E-1, 4.14437652E-1}, +{3.44446361E-1, 3.62201869E-1, 3.97619784E-1, 4.17743623E-1}, +{2.32083067E-1, 2.67807961E-1, 3.78075659E-1, 4.34560895E-1}, +{3.04738700E-1, 3.51865292E-1, 3.75973165E-1, 3.95293653E-1}, +{2.61990905E-1, 3.46207321E-1, 3.71296942E-1, 4.12438929E-1}, +{3.11080933E-1, 3.51040900E-1, 4.16082799E-1, 4.34340119E-1}, +{2.74980426E-1, 2.96631455E-1, 3.87520492E-1, 4.09243762E-1}, +{2.90939093E-1, 3.54455590E-1, 3.93426955E-1, 4.08220291E-1}, +{2.71871865E-1, 3.45510781E-1, 3.87125313E-1, 4.22590613E-1}, +{3.63245904E-1, 3.81932199E-1, 4.04114902E-1, 4.18370664E-1}, +{2.45770738E-1, 2.72909343E-1, 3.48317921E-1, 4.25161839E-1}, +{3.14139009E-1, 3.37872326E-1, 3.65195215E-1, 4.04423416E-1}, +{2.94075787E-1, 3.16935539E-1, 3.43047202E-1, 4.06130373E-1}, +{3.14627469E-1, 3.72413397E-1, 4.00660694E-1, 4.17930841E-1}, +{2.34014243E-1, 3.14007223E-1, 3.83003533E-1, 4.34829175E-1}, +{2.93635666E-1, 3.20529997E-1, 4.10837352E-1, 4.36393142E-1}, +{2.89505839E-1, 3.11828852E-1, 3.86311471E-1, 4.38771248E-1}, +{3.26317430E-1, 3.80858183E-1, 4.19721425E-1, 4.38795507E-1}, +{2.50809520E-1, 2.83018053E-1, 3.82247388E-1, 4.34244394E-1}, +{3.18994045E-1, 3.44855130E-1, 3.72690141E-1, 4.23067033E-1}, +{2.88380086E-1, 3.36622238E-1, 3.69742334E-1, 4.25057590E-1}, +{3.06107700E-1, 3.81856918E-1, 4.18206155E-1, 4.32868361E-1}, +{2.33898312E-1, 3.44861805E-1, 4.12176549E-1, 4.29216206E-1}, +{2.85980880E-1, 3.42903793E-1, 4.25112903E-1, 4.44299698E-1}, +{2.79858828E-1, 3.38789344E-1, 3.92085373E-1, 4.40541029E-1}, +{3.64509344E-1, 3.82202744E-1, 4.29830611E-1, 4.45818365E-1}, +{2.34392300E-1, 2.57377386E-1, 3.59567046E-1, 4.30088580E-1}, +{3.05031896E-1, 3.27589393E-1, 3.78305554E-1, 4.01026130E-1}, +{2.77522624E-1, 3.18130314E-1, 3.67794275E-1, 4.01543021E-1}, +{3.33035767E-1, 3.55820954E-1, 3.87548923E-1, 4.24628675E-1}, +{2.45021001E-1, 3.12560678E-1, 3.91147614E-1, 4.08762813E-1}, +{2.97059119E-1, 3.40246916E-1, 3.92919302E-1, 4.28899705E-1}, +{2.77839303E-1, 3.25019777E-1, 3.97436380E-1, 4.15920913E-1}, +{3.49465251E-1, 3.70362461E-1, 3.95482540E-1, 4.31923389E-1}, +{2.31485590E-1, 2.91023374E-1, 3.77909541E-1, 4.32259738E-1}, +{3.19283485E-1, 3.53671074E-1, 3.80982876E-1, 3.97843361E-1}, +{2.89689243E-1, 3.50265682E-1, 3.80729675E-1, 3.97969365E-1}, +{3.28987300E-1, 3.52005422E-1, 4.12557244E-1, 4.37597930E-1}, +{2.76273251E-1, 3.02267194E-1, 3.81723404E-1, 4.34989095E-1}, +{2.79627264E-1, 3.73727322E-1, 4.12374616E-1, 4.30626333E-1}, +{2.53442764E-1, 3.65940034E-1, 4.14937019E-1, 4.32743609E-1}, +{3.76107216E-1, 3.95142019E-1, 4.16787744E-1, 4.33023572E-1}, +{2.62815833E-1, 2.88270533E-1, 3.47397208E-1, 4.24182594E-1}, +{3.01931322E-1, 3.43652546E-1, 3.77031326E-1, 4.34204459E-1}, +{2.97834277E-1, 3.23495388E-1, 3.64492416E-1, 4.33550835E-1}, +{3.31774473E-1, 3.64324927E-1, 3.98243546E-1, 4.35078323E-1}, +{2.49049723E-1, 3.27870786E-1, 3.83587003E-1, 4.35558081E-1}, +{3.04653406E-1, 3.27671230E-1, 4.18484688E-1, 4.41378772E-1}, +{2.96960890E-1, 3.23898911E-1, 3.90463710E-1, 4.39915955E-1}, +{3.43923748E-1, 3.67100477E-1, 4.29523230E-1, 4.45214987E-1}, +{2.59399652E-1, 2.91602671E-1, 4.04372454E-1, 4.31413233E-1}, +{2.97537506E-1, 3.57573807E-1, 3.88991833E-1, 4.30006981E-1}, +{2.84068942E-1, 3.49574566E-1, 3.81042838E-1, 4.29712772E-1}, +{3.25716257E-1, 3.74875903E-1, 4.31959271E-1, 4.47290838E-1}, +{2.65302956E-1, 3.14745963E-1, 4.16703463E-1, 4.37294722E-1}, +{3.00398588E-1, 3.54147255E-1, 4.28538084E-1, 4.60336387E-1}, +{2.98077166E-1, 3.49304914E-1, 4.00429249E-1, 4.48213518E-1}, +{3.75576198E-1, 4.16657329E-1, 4.42136765E-1, 4.52728629E-1}}; + +static const float evrc_lspq_quant_codebook1[16][5] = { +{0.42091064E-1, 0.69474973E-1, 0.11168948E+0, 0.14571965E+0, 0.20893581E+0}, +{0.54944664E-1, 0.98242261E-1, 0.11007882E+0, 0.15890779E+0, 0.20548241E+0}, +{0.45188572E-1, 0.75199433E-1, 0.11423391E+0, 0.15469728E+0, 0.19746706E+0}, +{0.49474996E-1, 0.79667501E-1, 0.12571351E+0, 0.16944779E+0, 0.20775315E+0}, +{0.41789379E-1, 0.63459560E-1, 0.12068028E+0, 0.15850765E+0, 0.20406815E+0}, +{0.47159236E-1, 0.79129547E-1, 0.12183110E+0, 0.15650047E+0, 0.22309226E+0}, +{0.54539919E-1, 0.80343045E-1, 0.12947764E+0, 0.15186153E+0, 0.20171718E+0}, +{0.55852082E-1, 0.94114847E-1, 0.14016025E+0, 0.17807084E+0, 0.22955489E+0}, +{0.45443531E-1, 0.73541410E-1, 0.11937657E+0, 0.15442030E+0, 0.21010752E+0}, +{0.63178010E-1, 0.95231488E-1, 0.12364983E+0, 0.17672543E+0, 0.21743731E+0}, +{0.52765369E-1, 0.84351443E-1, 0.11589085E+0, 0.15790924E+0, 0.20732352E+0}, +{0.51865745E-1, 0.81328541E-1, 0.13756232E+0, 0.18322878E+0, 0.21640070E+0}, +{0.44419531E-1, 0.68874463E-1, 0.13115251E+0, 0.16263582E+0, 0.21659100E+0}, +{0.49378436E-1, 0.81882551E-1, 0.13067168E+0, 0.16821896E+0, 0.23136081E+0}, +{0.55909779E-1, 0.90783298E-1, 0.13348848E+0, 0.16298474E+0, 0.20961523E+0}, +{0.61378211E-1, 0.98602772E-1, 0.14793332E+0, 0.19283190E+0, 0.23156509E+0}}; + +static const float evrc_lspq_quant_codebook2[16][5] = { +{0.26822963, 0.30585295, 0.31110349, 0.36823335, 0.40774474}, +{0.24418014, 0.28970167, 0.32573757, 0.39021483, 0.41345838}, +{0.23341830, 0.30078292, 0.32893899, 0.38557330, 0.41068462}, +{0.25905868, 0.29756859, 0.34196618, 0.38531172, 0.41295227}, +{0.24290450, 0.29223618, 0.32718554, 0.37788135, 0.40332928}, +{0.24674191, 0.29749370, 0.33631226, 0.39426059, 0.42258954}, +{0.21377595, 0.33140418, 0.34067687, 0.38222077, 0.40939021}, +{0.26673481, 0.30791649, 0.34419721, 0.39611506, 0.42387524}, +{0.26121426, 0.30492544, 0.32997236, 0.38486803, 0.42023736}, +{0.24954870, 0.29372856, 0.33382735, 0.37850669, 0.41714057}, +{0.24158891, 0.30173415, 0.34128246, 0.38428575, 0.41619650}, +{0.25818908, 0.31736413, 0.34904337, 0.38769925, 0.41551358}, +{0.24450587, 0.30673453, 0.33579323, 0.37844428, 0.40557048}, +{0.25164026, 0.31225079, 0.33847794, 0.39554194, 0.42396802}, +{0.22787990, 0.31779197, 0.33831909, 0.40044111, 0.41185561}, +{0.27896860, 0.32261974, 0.35658112, 0.40206763, 0.42370448}}; + +static const float const *evrc_lspq_full_codebooks[] = { + evrc_lspq_full_codebook1[0], evrc_lspq_full_codebook2[0], + evrc_lspq_full_codebook3[0], evrc_lspq_full_codebook4[0], +}; + +static const float const *evrc_lspq_half_codebooks[] = { + evrc_lspq_half_codebook1[0], evrc_lspq_half_codebook2[0], + evrc_lspq_half_codebook3[0], +}; + +static const float const *evrc_lspq_quant_codebooks[] = { + evrc_lspq_quant_codebook1[0], evrc_lspq_quant_codebook2[0], +}; + +static const float const **evrc_lspq_codebooks[] = { + 0, + evrc_lspq_quant_codebooks, + 0, + evrc_lspq_half_codebooks, + evrc_lspq_full_codebooks, +}; + +static const uint8_t evrc_lspq_nb_codebooks[] = { + 0, + FF_ARRAY_ELEMS(evrc_lspq_quant_codebooks), + 0, + FF_ARRAY_ELEMS(evrc_lspq_half_codebooks), + FF_ARRAY_ELEMS(evrc_lspq_full_codebooks), +}; + +static const uint8_t evrc_lspq_full_codebooks_row_sizes[] = { + FF_ARRAY_ELEMS(evrc_lspq_full_codebook1[0]), + FF_ARRAY_ELEMS(evrc_lspq_full_codebook2[0]), + FF_ARRAY_ELEMS(evrc_lspq_full_codebook3[0]), + FF_ARRAY_ELEMS(evrc_lspq_full_codebook4[0]), +}; + +static const uint8_t evrc_lspq_half_codebooks_row_sizes[] = { + FF_ARRAY_ELEMS(evrc_lspq_half_codebook1[0]), + FF_ARRAY_ELEMS(evrc_lspq_half_codebook2[0]), + FF_ARRAY_ELEMS(evrc_lspq_half_codebook3[0]), +}; + +static const uint8_t evrc_lspq_quant_codebooks_row_sizes[] = { + FF_ARRAY_ELEMS(evrc_lspq_quant_codebook1[0]), + FF_ARRAY_ELEMS(evrc_lspq_quant_codebook2[0]), +}; + +static const uint8_t* const evrc_lspq_codebooks_row_sizes[] = { + NULL, + evrc_lspq_quant_codebooks_row_sizes, + NULL, + evrc_lspq_half_codebooks_row_sizes, + evrc_lspq_full_codebooks_row_sizes, +}; + +static const float pitch_gain_vq[] = { 0, 0.3, 0.55, 0.7, 0.8, 0.9, 1, 1.2 }; +static const float estimation_delay[] = { 55.0, 80.0, 39.0, 71.0, 33.0 }; // 5.2.3.4 +static const uint8_t subframe_sizes[] = { 53, 53, 54 }; +#endif /* AVCODEC_EVRCDATA_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/evrcdec.c b/mythtv/external/FFmpeg/libavcodec/evrcdec.c new file mode 100644 index 00000000000..5569ca25117 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/evrcdec.c @@ -0,0 +1,917 @@ +/* + * Enhanced Variable Rate Codec, Service Option 3 decoder + * Copyright (c) 2013 Paul B Mahol + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Enhanced Variable Rate Codec, Service Option 3 decoder + * @author Paul B Mahol + */ + +#include "libavutil/mathematics.h" +#include "avcodec.h" +#include "internal.h" +#include "get_bits.h" +#include "evrcdata.h" +#include "acelp_vectors.h" +#include "lsp.h" + +#define MIN_LSP_SEP (0.05 / (2.0 * M_PI)) +#define MIN_DELAY 20 +#define MAX_DELAY 120 +#define NB_SUBFRAMES 3 +#define SUBFRAME_SIZE 54 +#define FILTER_ORDER 10 +#define ACB_SIZE 128 + +typedef enum { + RATE_ERRS = -1, + SILENCE, + RATE_QUANT, + RATE_QUARTER, + RATE_HALF, + RATE_FULL, +} evrc_packet_rate; + +/** + * EVRC-A unpacked data frame + */ +typedef struct EVRCAFrame { + uint8_t lpc_flag; ///< spectral change indicator + uint16_t lsp[4]; ///< index into LSP codebook + uint8_t pitch_delay; ///< pitch delay for entire frame + uint8_t delay_diff; ///< delay difference for entire frame + uint8_t acb_gain[3]; ///< adaptive codebook gain + uint16_t fcb_shape[3][4]; ///< fixed codebook shape + uint8_t fcb_gain[3]; ///< fixed codebook gain index + uint8_t energy_gain; ///< frame energy gain index + uint8_t tty; ///< tty baud rate bit +} EVRCAFrame; + +typedef struct EVRCContext { + GetBitContext gb; + evrc_packet_rate bitrate; + evrc_packet_rate last_valid_bitrate; + EVRCAFrame frame; + + float lspf[FILTER_ORDER]; + float prev_lspf[FILTER_ORDER]; + float synthesis[FILTER_ORDER]; + float postfilter_fir[FILTER_ORDER]; + float postfilter_iir[FILTER_ORDER]; + float postfilter_residual[ACB_SIZE + SUBFRAME_SIZE]; + float pitch_delay; + float prev_pitch_delay; + float avg_acb_gain; ///< average adaptive codebook gain + float avg_fcb_gain; ///< average fixed codebook gain + float pitch[ACB_SIZE + FILTER_ORDER + SUBFRAME_SIZE]; + float pitch_back[ACB_SIZE]; + float interpolation_coeffs[136]; + float energy_vector[NB_SUBFRAMES]; + float fade_scale; + float last; + + uint8_t prev_energy_gain; + uint8_t prev_error_flag; + uint8_t warned_buf_mismatch_bitrate; +} EVRCContext; + +/** + * Frame unpacking for RATE_FULL, RATE_HALF and RATE_QUANT + * + * @param e the context + * + * TIA/IS-127 Table 4.21-1 + */ +static void unpack_frame(EVRCContext *e) +{ + EVRCAFrame *frame = &e->frame; + GetBitContext *gb = &e->gb; + + switch (e->bitrate) { + case RATE_FULL: + frame->lpc_flag = get_bits1(gb); + frame->lsp[0] = get_bits(gb, 6); + frame->lsp[1] = get_bits(gb, 6); + frame->lsp[2] = get_bits(gb, 9); + frame->lsp[3] = get_bits(gb, 7); + frame->pitch_delay = get_bits(gb, 7); + frame->delay_diff = get_bits(gb, 5); + frame->acb_gain[0] = get_bits(gb, 3); + frame->fcb_shape[0][0] = get_bits(gb, 8); + frame->fcb_shape[0][1] = get_bits(gb, 8); + frame->fcb_shape[0][2] = get_bits(gb, 8); + frame->fcb_shape[0][3] = get_bits(gb, 11); + frame->fcb_gain[0] = get_bits(gb, 5); + frame->acb_gain[1] = get_bits(gb, 3); + frame->fcb_shape[1][0] = get_bits(gb, 8); + frame->fcb_shape[1][1] = get_bits(gb, 8); + frame->fcb_shape[1][2] = get_bits(gb, 8); + frame->fcb_shape[1][3] = get_bits(gb, 11); + frame->fcb_gain [1] = get_bits(gb, 5); + frame->acb_gain [2] = get_bits(gb, 3); + frame->fcb_shape[2][0] = get_bits(gb, 8); + frame->fcb_shape[2][1] = get_bits(gb, 8); + frame->fcb_shape[2][2] = get_bits(gb, 8); + frame->fcb_shape[2][3] = get_bits(gb, 11); + frame->fcb_gain [2] = get_bits(gb, 5); + frame->tty = get_bits1(gb); + break; + case RATE_HALF: + frame->lsp [0] = get_bits(gb, 7); + frame->lsp [1] = get_bits(gb, 7); + frame->lsp [2] = get_bits(gb, 8); + frame->pitch_delay = get_bits(gb, 7); + frame->acb_gain [0] = get_bits(gb, 3); + frame->fcb_shape[0][0] = get_bits(gb, 10); + frame->fcb_gain [0] = get_bits(gb, 4); + frame->acb_gain [1] = get_bits(gb, 3); + frame->fcb_shape[1][0] = get_bits(gb, 10); + frame->fcb_gain [1] = get_bits(gb, 4); + frame->acb_gain [2] = get_bits(gb, 3); + frame->fcb_shape[2][0] = get_bits(gb, 10); + frame->fcb_gain [2] = get_bits(gb, 4); + break; + case RATE_QUANT: + frame->lsp [0] = get_bits(gb, 4); + frame->lsp [1] = get_bits(gb, 4); + frame->energy_gain = get_bits(gb, 8); + break; + } +} + +static evrc_packet_rate buf_size2bitrate(const int buf_size) +{ + switch (buf_size) { + case 23: return RATE_FULL; + case 11: return RATE_HALF; + case 6: return RATE_QUARTER; + case 3: return RATE_QUANT; + case 1: return SILENCE; + } + + return RATE_ERRS; +} + +/** + * Determine the bitrate from the frame size and/or the first byte of the frame. + * + * @param avctx the AV codec context + * @param buf_size length of the buffer + * @param buf the bufffer + * + * @return the bitrate on success, + * RATE_ERRS if the bitrate cannot be satisfactorily determined + */ +static evrc_packet_rate determine_bitrate(AVCodecContext *avctx, + int *buf_size, + const uint8_t **buf) +{ + evrc_packet_rate bitrate; + + if ((bitrate = buf_size2bitrate(*buf_size)) >= 0) { + if (bitrate > **buf) { + EVRCContext *e = avctx->priv_data; + if (!e->warned_buf_mismatch_bitrate) { + av_log(avctx, AV_LOG_WARNING, + "Claimed bitrate and buffer size mismatch.\n"); + e->warned_buf_mismatch_bitrate = 1; + } + bitrate = **buf; + } else if (bitrate < **buf) { + av_log(avctx, AV_LOG_ERROR, + "Buffer is too small for the claimed bitrate.\n"); + return RATE_ERRS; + } + (*buf)++; + *buf_size -= 1; + } else if ((bitrate = buf_size2bitrate(*buf_size + 1)) >= 0) { + av_log(avctx, AV_LOG_DEBUG, + "Bitrate byte is missing, guessing the bitrate from packet size.\n"); + } else + return RATE_ERRS; + + return bitrate; +} + +static void warn_insufficient_frame_quality(AVCodecContext *avctx, + const char *message) +{ + av_log(avctx, AV_LOG_WARNING, "Frame #%d, %s\n", + avctx->frame_number, message); +} + +/** + * Initialize the speech codec according to the specification. + * + * TIA/IS-127 5.2 + */ +static av_cold int evrc_decode_init(AVCodecContext *avctx) +{ + EVRCContext *e = avctx->priv_data; + int i, n, idx = 0; + float denom = 2.0 / (2.0 * 8.0 + 1.0); + + avctx->channels = 1; + avctx->channel_layout = AV_CH_LAYOUT_MONO; + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; + + for (i = 0; i < FILTER_ORDER; i++) { + e->prev_lspf[i] = (i + 1) * 0.048; + e->synthesis[i] = 0.0; + } + + for (i = 0; i < ACB_SIZE; i++) + e->pitch[i] = e->pitch_back[i] = 0.0; + + e->last_valid_bitrate = RATE_QUANT; + e->prev_pitch_delay = 40.0; + e->fade_scale = 1.0; + e->prev_error_flag = 0; + e->avg_acb_gain = e->avg_fcb_gain = 0.0; + + for (i = 0; i < 8; i++) { + float tt = ((float)i - 8.0 / 2.0) / 8.0; + + for (n = -8; n <= 8; n++, idx++) { + float arg1 = M_PI * 0.9 * (tt - n); + float arg2 = M_PI * (tt - n); + + e->interpolation_coeffs[idx] = 0.9; + if (arg1) + e->interpolation_coeffs[idx] *= (0.54 + 0.46 * cos(arg2 * denom)) * + sin(arg1) / arg1; + } + } + + return 0; +} + +/** + * Decode the 10 vector quantized line spectral pair frequencies from the LSP + * transmission codes of any bitrate and check for badly received packets. + * + * @param e the context + * + * @return 0 on success, -1 if the packet is badly received + * + * TIA/IS-127 5.2.1, 5.7.1 + */ +static int decode_lspf(EVRCContext *e) +{ + const float **codebooks = evrc_lspq_codebooks[e->bitrate]; + int i, j, k = 0; + + for (i = 0; i < evrc_lspq_nb_codebooks[e->bitrate]; i++) { + int row_size = evrc_lspq_codebooks_row_sizes[e->bitrate][i]; + const float *codebook = codebooks[i]; + + for (j = 0; j < row_size; j++) + e->lspf[k++] = codebook[e->frame.lsp[i] * row_size + j]; + } + + // check for monotonic LSPs + for (i = 1; i < FILTER_ORDER; i++) + if (e->lspf[i] <= e->lspf[i - 1]) + return -1; + + // check for minimum separation of LSPs at the splits + for (i = 0, k = 0; i < evrc_lspq_nb_codebooks[e->bitrate] - 1; i++) { + k += evrc_lspq_codebooks_row_sizes[e->bitrate][i]; + if (e->lspf[k] - e->lspf[k - 1] <= MIN_LSP_SEP) + return -1; + } + + return 0; +} + +/* + * Interpolation of LSP parameters. + * + * TIA/IS-127 5.2.3.1, 5.7.3.2 + */ +static void interpolate_lsp(float *ilsp, const float *lsp, + const float *prev, int index) +{ + static const float lsp_interpolation_factors[] = { 0.1667, 0.5, 0.8333 }; + ff_weighted_vector_sumf(ilsp, prev, lsp, + 1.0 - lsp_interpolation_factors[index], + lsp_interpolation_factors[index], FILTER_ORDER); +} + +/* + * Reconstruction of the delay contour. + * + * TIA/IS-127 5.2.2.3.2 + */ +static void interpolate_delay(float *dst, float current, float prev, int index) +{ + static const float d_interpolation_factors[] = { 0, 0.3313, 0.6625, 1, 1 }; + dst[0] = (1.0 - d_interpolation_factors[index ]) * prev + + d_interpolation_factors[index ] * current; + dst[1] = (1.0 - d_interpolation_factors[index + 1]) * prev + + d_interpolation_factors[index + 1] * current; + dst[2] = (1.0 - d_interpolation_factors[index + 2]) * prev + + d_interpolation_factors[index + 2] * current; +} + +/* + * Convert the quantized, interpolated line spectral frequencies, + * to prediction coefficients. + * + * TIA/IS-127 5.2.3.2, 4.7.2.2 + */ +static void decode_predictor_coeffs(const float *ilspf, float *ilpc) +{ + double lsp[FILTER_ORDER]; + float a[FILTER_ORDER / 2 + 1], b[FILTER_ORDER / 2 + 1]; + float a1[FILTER_ORDER / 2] = { 0 }; + float a2[FILTER_ORDER / 2] = { 0 }; + float b1[FILTER_ORDER / 2] = { 0 }; + float b2[FILTER_ORDER / 2] = { 0 }; + int i, k; + + ff_acelp_lsf2lspd(lsp, ilspf, FILTER_ORDER); + + for (k = 0; k <= FILTER_ORDER; k++) { + a[0] = k < 2 ? 0.25 : 0; + b[0] = k < 2 ? k < 1 ? 0.25 : -0.25 : 0; + + for (i = 0; i < FILTER_ORDER / 2; i++) { + a[i + 1] = a[i] - 2 * lsp[i * 2 ] * a1[i] + a2[i]; + b[i + 1] = b[i] - 2 * lsp[i * 2 + 1] * b1[i] + b2[i]; + a2[i] = a1[i]; + a1[i] = a[i]; + b2[i] = b1[i]; + b1[i] = b[i]; + } + + if (k) + ilpc[k - 1] = 2.0 * (a[FILTER_ORDER / 2] + b[FILTER_ORDER / 2]); + } +} + +static void bl_intrp(EVRCContext *e, float *ex, float delay) +{ + float *f; + int offset, i, coef_idx; + int16_t t; + + offset = lrintf(fabs(delay)); + + t = (offset - delay + 0.5) * 8.0 + 0.5; + if (t == 8) { + t = 0; + offset--; + } + + f = ex - offset - 8; + + coef_idx = t * (2 * 8 + 1); + + ex[0] = 0.0; + for (i = 0; i < 2 * 8 + 1; i++) + ex[0] += e->interpolation_coeffs[coef_idx + i] * f[i]; +} + +/* + * Adaptive codebook excitation. + * + * TIA/IS-127 5.2.2.3.3, 4.12.5.2 + */ +static void acb_excitation(EVRCContext *e, float *excitation, float gain, + const float delay[3], int length) +{ + float denom, locdelay, dpr, invl; + int i; + + invl = 1.0 / ((float) length); + dpr = length; + + /* first at-most extra samples */ + denom = (delay[1] - delay[0]) * invl; + for (i = 0; i < dpr; i++) { + locdelay = delay[0] + i * denom; + bl_intrp(e, excitation + i, locdelay); + } + + denom = (delay[2] - delay[1]) * invl; + /* interpolation */ + for (i = dpr; i < dpr + 10; i++) { + locdelay = delay[1] + (i - dpr) * denom; + bl_intrp(e, excitation + i, locdelay); + } + + for (i = 0; i < length; i++) + excitation[i] *= gain; +} + +static void decode_8_pulses_35bits(const uint16_t *fixed_index, float *cod) +{ + int i, pos1, pos2, offset; + + offset = (fixed_index[3] >> 9) & 3; + + for (i = 0; i < 3; i++) { + pos1 = ((fixed_index[i] & 0x7f) / 11) * 5 + ((i + offset) % 5); + pos2 = ((fixed_index[i] & 0x7f) % 11) * 5 + ((i + offset) % 5); + + cod[pos1] = (fixed_index[i] & 0x80) ? -1.0 : 1.0; + + if (pos2 < pos1) + cod[pos2] = -cod[pos1]; + else + cod[pos2] += cod[pos1]; + } + + pos1 = ((fixed_index[3] & 0x7f) / 11) * 5 + ((3 + offset) % 5); + pos2 = ((fixed_index[3] & 0x7f) % 11) * 5 + ((4 + offset) % 5); + + cod[pos1] = (fixed_index[3] & 0x100) ? -1.0 : 1.0; + cod[pos2] = (fixed_index[3] & 0x80 ) ? -1.0 : 1.0; +} + +static void decode_3_pulses_10bits(uint16_t fixed_index, float *cod) +{ + float sign; + int pos; + + sign = (fixed_index & 0x200) ? -1.0 : 1.0; + + pos = ((fixed_index & 0x7) * 7) + 4; + cod[pos] += sign; + pos = (((fixed_index >> 3) & 0x7) * 7) + 2; + cod[pos] -= sign; + pos = (((fixed_index >> 6) & 0x7) * 7); + cod[pos] += sign; +} + +/* + * Reconstruction of ACELP fixed codebook excitation for full and half rate. + * + * TIA/IS-127 5.2.3.7 + */ +static void fcb_excitation(EVRCContext *e, const uint16_t *codebook, + float *excitation, float pitch_gain, + int pitch_lag, int subframe_size) +{ + int i; + + if (e->bitrate == RATE_FULL) + decode_8_pulses_35bits(codebook, excitation); + else + decode_3_pulses_10bits(*codebook, excitation); + + pitch_gain = av_clipf(pitch_gain, 0.2, 0.9); + + for (i = pitch_lag; i < subframe_size; i++) + excitation[i] += pitch_gain * excitation[i - pitch_lag]; +} + +/** + * Synthesis of the decoder output signal. + * + * param[in] in input signal + * param[in] filter_coeffs LPC coefficients + * param[in/out] memory synthesis filter memory + * param buffer_length amount of data to process + * param[out] samples output samples + * + * TIA/IS-127 5.2.3.15, 5.7.3.4 + */ +static void synthesis_filter(const float *in, const float *filter_coeffs, + float *memory, int buffer_length, float *samples) +{ + int i, j; + + for (i = 0; i < buffer_length; i++) { + samples[i] = in[i]; + for (j = FILTER_ORDER - 1; j > 0; j--) { + samples[i] -= filter_coeffs[j] * memory[j]; + memory[j] = memory[j - 1]; + } + samples[i] -= filter_coeffs[0] * memory[0]; + memory[0] = samples[i]; + } +} + +static void bandwidth_expansion(float *coeff, const float *inbuf, float gamma) +{ + double fac = gamma; + int i; + + for (i = 0; i < FILTER_ORDER; i++) { + coeff[i] = inbuf[i] * fac; + fac *= gamma; + } +} + +static void residual_filter(float *output, const float *input, + const float *coef, float *memory, int length) +{ + float sum; + int i, j; + + for (i = 0; i < length; i++) { + sum = input[i]; + + for (j = FILTER_ORDER - 1; j > 0; j--) { + sum += coef[j] * memory[j]; + memory[j] = memory[j - 1]; + } + sum += coef[0] * memory[0]; + memory[0] = input[i]; + output[i] = sum; + } +} + +/* + * TIA/IS-127 Table 5.9.1-1. + */ +static const struct PfCoeff { + float tilt; + float ltgain; + float p1; + float p2; +} postfilter_coeffs[5] = { + { 0.0 , 0.0 , 0.0 , 0.0 }, + { 0.0 , 0.0 , 0.57, 0.57 }, + { 0.0 , 0.0 , 0.0 , 0.0 }, + { 0.35, 0.50, 0.50, 0.75 }, + { 0.20, 0.50, 0.57, 0.75 }, +}; + +/* + * Adaptive postfilter. + * + * TIA/IS-127 5.9 + */ +static void postfilter(EVRCContext *e, float *in, const float *coeff, + float *out, int idx, const struct PfCoeff *pfc, + int length) +{ + float wcoef1[FILTER_ORDER], wcoef2[FILTER_ORDER], + scratch[SUBFRAME_SIZE], temp[SUBFRAME_SIZE], + mem[SUBFRAME_SIZE]; + float sum1 = 0.0, sum2 = 0.0, gamma, gain; + float tilt = pfc->tilt; + int i, n, best; + + bandwidth_expansion(wcoef1, coeff, pfc->p1); + bandwidth_expansion(wcoef2, coeff, pfc->p2); + + /* Tilt compensation filter, TIA/IS-127 5.9.1 */ + for (i = 0; i < length - 1; i++) + sum2 += in[i] * in[i + 1]; + if (sum2 < 0.0) + tilt = 0.0; + + for (i = 0; i < length; i++) { + scratch[i] = in[i] - tilt * e->last; + e->last = in[i]; + } + + /* Short term residual filter, TIA/IS-127 5.9.2 */ + residual_filter(&e->postfilter_residual[ACB_SIZE], scratch, wcoef1, e->postfilter_fir, length); + + /* Long term postfilter */ + best = idx; + for (i = FFMIN(MIN_DELAY, idx - 3); i <= FFMAX(MAX_DELAY, idx + 3); i++) { + for (n = ACB_SIZE, sum2 = 0; n < ACB_SIZE + length; n++) + sum2 += e->postfilter_residual[n] * e->postfilter_residual[n - i]; + if (sum2 > sum1) { + sum1 = sum2; + best = i; + } + } + + for (i = ACB_SIZE, sum1 = 0; i < ACB_SIZE + length; i++) + sum1 += e->postfilter_residual[i - best] * e->postfilter_residual[i - best]; + for (i = ACB_SIZE, sum2 = 0; i < ACB_SIZE + length; i++) + sum2 += e->postfilter_residual[i] * e->postfilter_residual[i - best]; + + if (sum2 * sum1 == 0 || e->bitrate == RATE_QUANT) { + memcpy(temp, e->postfilter_residual + ACB_SIZE, length * sizeof(float)); + } else { + gamma = sum2 / sum1; + if (gamma < 0.5) + memcpy(temp, e->postfilter_residual + ACB_SIZE, length * sizeof(float)); + else { + gamma = FFMIN(gamma, 1.0); + + for (i = 0; i < length; i++) { + temp[i] = e->postfilter_residual[ACB_SIZE + i] + gamma * + pfc->ltgain * e->postfilter_residual[ACB_SIZE + i - best]; + } + } + } + + memcpy(scratch, temp, length * sizeof(float)); + memcpy(mem, e->postfilter_iir, FILTER_ORDER * sizeof(float)); + synthesis_filter(scratch, wcoef2, mem, length, scratch); + + /* Gain computation, TIA/IS-127 5.9.4-2 */ + for (i = 0, sum1 = 0, sum2 = 0; i < length; i++) { + sum1 += in[i] * in[i]; + sum2 += scratch[i] * scratch[i]; + } + gain = sum2 ? sqrt(sum1 / sum2) : 1.0; + + for (i = 0; i < length; i++) + temp[i] *= gain; + + /* Short term postfilter */ + synthesis_filter(temp, wcoef2, e->postfilter_iir, length, out); + + memcpy(e->postfilter_residual, + e->postfilter_residual + length, ACB_SIZE * sizeof(float)); +} + +static void frame_erasure(EVRCContext *e, float *samples) +{ + float ilspf[FILTER_ORDER], ilpc[FILTER_ORDER], idelay[NB_SUBFRAMES], + tmp[SUBFRAME_SIZE + 6], f; + int i, j; + + for (i = 0; i < FILTER_ORDER; i++) { + if (e->bitrate != RATE_QUANT) + e->lspf[i] = e->prev_lspf[i] * 0.875 + 0.125 * (i + 1) * 0.048; + else + e->lspf[i] = e->prev_lspf[i]; + } + + if (e->prev_error_flag) + e->avg_acb_gain *= 0.75; + if (e->bitrate == RATE_FULL) + memcpy(e->pitch_back, e->pitch, ACB_SIZE * sizeof(float)); + if (e->last_valid_bitrate == RATE_QUANT) + e->bitrate = RATE_QUANT; + else + e->bitrate = RATE_FULL; + + if (e->bitrate == RATE_FULL || e->bitrate == RATE_HALF) { + e->pitch_delay = e->prev_pitch_delay; + } else { + float sum = 0; + + idelay[0] = idelay[1] = idelay[2] = MIN_DELAY; + + for (i = 0; i < NB_SUBFRAMES; i++) + sum += evrc_energy_quant[e->prev_energy_gain][i]; + sum /= (float) NB_SUBFRAMES; + sum = pow(10, sum); + for (i = 0; i < NB_SUBFRAMES; i++) + e->energy_vector[i] = sum; + } + + if (fabs(e->pitch_delay - e->prev_pitch_delay) > 15) + e->prev_pitch_delay = e->pitch_delay; + + for (i = 0; i < NB_SUBFRAMES; i++) { + int subframe_size = subframe_sizes[i]; + int pitch_lag; + + interpolate_lsp(ilspf, e->lspf, e->prev_lspf, i); + + if (e->bitrate != RATE_QUANT) { + if (e->avg_acb_gain < 0.3) { + idelay[0] = estimation_delay[i]; + idelay[1] = estimation_delay[i + 1]; + idelay[2] = estimation_delay[i + 2]; + } else { + interpolate_delay(idelay, e->pitch_delay, e->prev_pitch_delay, i); + } + } + + pitch_lag = lrintf((idelay[1] + idelay[0]) / 2.0); + decode_predictor_coeffs(ilspf, ilpc); + + if (e->bitrate != RATE_QUANT) { + acb_excitation(e, e->pitch + ACB_SIZE, + e->avg_acb_gain, idelay, subframe_size); + for (j = 0; j < subframe_size; j++) + e->pitch[ACB_SIZE + j] *= e->fade_scale; + e->fade_scale = FFMAX(e->fade_scale - 0.05, 0.0); + } else { + for (j = 0; j < subframe_size; j++) + e->pitch[ACB_SIZE + j] = e->energy_vector[i]; + } + + memcpy(e->pitch, e->pitch + subframe_size, ACB_SIZE * sizeof(float)); + + if (e->bitrate != RATE_QUANT && e->avg_acb_gain < 0.4) { + f = 0.1 * e->avg_fcb_gain; + for (j = 0; j < subframe_size; j++) + e->pitch[ACB_SIZE + j] += f; + } else if (e->bitrate == RATE_QUANT) { + for (j = 0; j < subframe_size; j++) + e->pitch[ACB_SIZE + j] = e->energy_vector[i]; + } + + synthesis_filter(e->pitch + ACB_SIZE, ilpc, + e->synthesis, subframe_size, tmp); + postfilter(e, tmp, ilpc, samples, pitch_lag, + &postfilter_coeffs[e->bitrate], subframe_size); + + samples += subframe_size; + } +} + +static int evrc_decode_frame(AVCodecContext *avctx, void *data, + int *got_frame_ptr, AVPacket *avpkt) +{ + const uint8_t *buf = avpkt->data; + AVFrame *frame = data; + EVRCContext *e = avctx->priv_data; + int buf_size = avpkt->size; + float ilspf[FILTER_ORDER], ilpc[FILTER_ORDER], idelay[NB_SUBFRAMES]; + float *samples; + int i, j, ret, error_flag = 0; + + frame->nb_samples = 160; + if ((ret = ff_get_buffer(avctx, frame)) < 0) + return ret; + samples = (float *)frame->data[0]; + + if ((e->bitrate = determine_bitrate(avctx, &buf_size, &buf)) == RATE_ERRS) { + warn_insufficient_frame_quality(avctx, "bitrate cannot be determined."); + goto erasure; + } + if (e->bitrate <= SILENCE || e->bitrate == RATE_QUARTER) + goto erasure; + if (e->bitrate == RATE_QUANT && e->last_valid_bitrate == RATE_FULL + && !e->prev_error_flag) + goto erasure; + + init_get_bits(&e->gb, buf, 8 * buf_size); + memset(&e->frame, 0, sizeof(EVRCAFrame)); + + unpack_frame(e); + + if (e->bitrate != RATE_QUANT) { + uint8_t *p = (uint8_t *) &e->frame; + for (i = 0; i < sizeof(EVRCAFrame); i++) { + if (p[i]) + break; + } + if (i == sizeof(EVRCAFrame)) + goto erasure; + } else if (e->frame.lsp[0] == 0xf && + e->frame.lsp[1] == 0xf && + e->frame.energy_gain == 0xff) { + goto erasure; + } + + if (decode_lspf(e) < 0) + goto erasure; + + if (e->bitrate == RATE_FULL || e->bitrate == RATE_HALF) { + /* Pitch delay parameter checking as per TIA/IS-127 5.1.5.1 */ + if (e->frame.pitch_delay > MAX_DELAY - MIN_DELAY) + goto erasure; + + e->pitch_delay = e->frame.pitch_delay + MIN_DELAY; + + /* Delay diff parameter checking as per TIA/IS-127 5.1.5.2 */ + if (e->frame.delay_diff) { + int p = e->pitch_delay - e->frame.delay_diff + 16; + if (p < MIN_DELAY || p > MAX_DELAY) + goto erasure; + } + + /* Delay contour reconstruction as per TIA/IS-127 5.2.2.2 */ + if (e->frame.delay_diff && + e->bitrate == RATE_FULL && e->prev_error_flag) { + float delay; + + memcpy(e->pitch, e->pitch_back, ACB_SIZE * sizeof(float)); + + delay = e->prev_pitch_delay; + e->prev_pitch_delay = delay - e->frame.delay_diff + 16.0; + + if (fabs(e->pitch_delay - delay) > 15) + delay = e->pitch_delay; + + for (i = 0; i < NB_SUBFRAMES; i++) { + int subframe_size = subframe_sizes[i]; + + interpolate_delay(idelay, delay, e->prev_pitch_delay, i); + acb_excitation(e, e->pitch + ACB_SIZE, e->avg_acb_gain, idelay, subframe_size); + memcpy(e->pitch, e->pitch + subframe_size, ACB_SIZE * sizeof(float)); + } + } + + /* Smoothing of the decoded delay as per TIA/IS-127 5.2.2.5 */ + if (fabs(e->pitch_delay - e->prev_pitch_delay) > 15) + e->prev_pitch_delay = e->pitch_delay; + + e->avg_acb_gain = e->avg_fcb_gain = 0.0; + } else { + idelay[0] = idelay[1] = idelay[2] = MIN_DELAY; + + /* Decode frame energy vectors as per TIA/IS-127 5.7.2 */ + for (i = 0; i < NB_SUBFRAMES; i++) + e->energy_vector[i] = pow(10, evrc_energy_quant[e->frame.energy_gain][i]); + e->prev_energy_gain = e->frame.energy_gain; + } + + for (i = 0; i < NB_SUBFRAMES; i++) { + float tmp[SUBFRAME_SIZE + 6] = { 0 }; + int subframe_size = subframe_sizes[i]; + int pitch_lag; + + interpolate_lsp(ilspf, e->lspf, e->prev_lspf, i); + + if (e->bitrate != RATE_QUANT) + interpolate_delay(idelay, e->pitch_delay, e->prev_pitch_delay, i); + + pitch_lag = lrintf((idelay[1] + idelay[0]) / 2.0); + decode_predictor_coeffs(ilspf, ilpc); + + /* Bandwidth expansion as per TIA/IS-127 5.2.3.3 */ + if (e->frame.lpc_flag && e->prev_error_flag) + bandwidth_expansion(ilpc, ilpc, 0.75); + + if (e->bitrate != RATE_QUANT) { + float acb_sum, f; + + f = exp((e->bitrate == RATE_HALF ? 0.5 : 0.25) + * (e->frame.fcb_gain[i] + 1)); + acb_sum = pitch_gain_vq[e->frame.acb_gain[i]]; + e->avg_acb_gain += acb_sum / NB_SUBFRAMES; + e->avg_fcb_gain += f / NB_SUBFRAMES; + + acb_excitation(e, e->pitch + ACB_SIZE, + acb_sum, idelay, subframe_size); + fcb_excitation(e, e->frame.fcb_shape[i], tmp, + acb_sum, pitch_lag, subframe_size); + + /* Total excitation generation as per TIA/IS-127 5.2.3.9 */ + for (j = 0; j < subframe_size; j++) + e->pitch[ACB_SIZE + j] += f * tmp[j]; + e->fade_scale = FFMIN(e->fade_scale + 0.2, 1.0); + } else { + for (j = 0; j < subframe_size; j++) + e->pitch[ACB_SIZE + j] = e->energy_vector[i]; + } + + memcpy(e->pitch, e->pitch + subframe_size, ACB_SIZE * sizeof(float)); + + synthesis_filter(e->pitch + ACB_SIZE, ilpc, + e->synthesis, subframe_size, tmp); + postfilter(e, tmp, ilpc, samples, pitch_lag, + &postfilter_coeffs[e->bitrate], subframe_size); + + samples += subframe_size; + } + + if (error_flag) { +erasure: + error_flag = 1; + av_log(avctx, AV_LOG_WARNING, "frame erasure\n"); + frame_erasure(e, samples); + } + + memcpy(e->prev_lspf, e->lspf, sizeof(e->prev_lspf)); + e->prev_error_flag = error_flag; + e->last_valid_bitrate = e->bitrate; + + if (e->bitrate != RATE_QUANT) + e->prev_pitch_delay = e->pitch_delay; + + samples = (float *)frame->data[0]; + for (i = 0; i < 160; i++) + samples[i] /= 32768; + + *got_frame_ptr = 1; + + return avpkt->size; +} + +AVCodec ff_evrc_decoder = { + .name = "evrc", + .type = AVMEDIA_TYPE_AUDIO, + .id = AV_CODEC_ID_EVRC, + .init = evrc_decode_init, + .decode = evrc_decode_frame, + .capabilities = CODEC_CAP_DR1, + .priv_data_size = sizeof(EVRCContext), + .long_name = NULL_IF_CONFIG_SMALL("EVRC (Enhanced Variable Rate Codec)"), +}; diff --git a/mythtv/external/FFmpeg/libavcodec/exr.c b/mythtv/external/FFmpeg/libavcodec/exr.c index fef0d105e00..d7277915611 100644 --- a/mythtv/external/FFmpeg/libavcodec/exr.c +++ b/mythtv/external/FFmpeg/libavcodec/exr.c @@ -37,6 +37,7 @@ #include "mathops.h" #include "thread.h" #include "libavutil/imgutils.h" +#include "libavutil/avassert.h" enum ExrCompr { EXR_RAW = 0, @@ -44,21 +45,54 @@ enum ExrCompr { EXR_ZIP1 = 2, EXR_ZIP16 = 3, EXR_PIZ = 4, + EXR_PXR24 = 5, EXR_B44 = 6, EXR_B44A = 7, }; -typedef struct EXRContext { - AVFrame picture; - int compr; - int bits_per_color_id; - int channel_offsets[4]; // 0 = red, 1 = green, 2 = blue and 3 = alpha +enum ExrPixelType { + EXR_UINT, + EXR_HALF, + EXR_FLOAT +}; + +typedef struct EXRChannel { + int xsub, ysub; + enum ExrPixelType pixel_type; +} EXRChannel; +typedef struct EXRThreadData { uint8_t *uncompressed_data; int uncompressed_size; uint8_t *tmp; int tmp_size; +} EXRThreadData; + +typedef struct EXRContext { + AVFrame picture; + int compr; + enum ExrPixelType pixel_type; + int channel_offsets[4]; // 0 = red, 1 = green, 2 = blue and 3 = alpha + const AVPixFmtDescriptor *desc; + + uint32_t xmax, xmin; + uint32_t ymax, ymin; + uint32_t xdelta, ydelta; + + int ysize; + + uint64_t scan_line_size; + int scan_lines_per_block; + + const uint8_t *buf, *table; + int buf_size; + + EXRChannel *channels; + int nb_channels; + + EXRThreadData *thread_data; + int thread_data_size; } EXRContext; /** @@ -143,8 +177,6 @@ static int check_header_variable(AVCodecContext *avctx, *variable_buffer_data_size = get_header_variable_length(buf, buf_end); if (!*variable_buffer_data_size) av_log(avctx, AV_LOG_ERROR, "Incomplete header\n"); - if (*variable_buffer_data_size > buf_end - *buf) - return -1; return 1; } *buf -= strlen(value_name)+1; @@ -185,10 +217,28 @@ static void reorder_pixels(uint8_t *src, uint8_t *dst, int size) } } -static int rle_uncompress(const uint8_t *src, int ssize, uint8_t *dst, int dsize) +static int zip_uncompress(const uint8_t *src, int compressed_size, + int uncompressed_size, EXRThreadData *td) +{ + unsigned long dest_len = uncompressed_size; + + if (uncompress(td->tmp, &dest_len, src, compressed_size) != Z_OK || + dest_len != uncompressed_size) + return AVERROR(EINVAL); + + predictor(td->tmp, uncompressed_size); + reorder_pixels(td->tmp, td->uncompressed_data, uncompressed_size); + + return 0; +} + +static int rle_uncompress(const uint8_t *src, int compressed_size, + int uncompressed_size, EXRThreadData *td) { - int8_t *d = (int8_t *)dst; - int8_t *s = (int8_t *)src; + int8_t *d = (int8_t *)td->tmp; + const int8_t *s = (const int8_t *)src; + int ssize = compressed_size; + int dsize = uncompressed_size; int8_t *dend = d + dsize; int count; @@ -218,7 +268,185 @@ static int rle_uncompress(const uint8_t *src, int ssize, uint8_t *dst, int dsize } } - return dend != d; + if (dend != d) + return AVERROR_INVALIDDATA; + + predictor(td->tmp, uncompressed_size); + reorder_pixels(td->tmp, td->uncompressed_data, uncompressed_size); + + return 0; +} + +static int pxr24_uncompress(EXRContext *s, const uint8_t *src, + int compressed_size, int uncompressed_size, + EXRThreadData *td) +{ + unsigned long dest_len = uncompressed_size; + const uint8_t *in = td->tmp; + uint8_t *out; + int c, i, j; + + if (uncompress(td->tmp, &dest_len, src, compressed_size) != Z_OK || + dest_len != uncompressed_size) + return AVERROR(EINVAL); + + out = td->uncompressed_data; + for (i = 0; i < s->ysize; i++) { + for (c = 0; c < s->nb_channels; c++) { + EXRChannel *channel = &s->channels[c]; + const uint8_t *ptr[4]; + uint32_t pixel = 0; + + switch (channel->pixel_type) { + case EXR_FLOAT: + ptr[0] = in; + ptr[1] = ptr[0] + s->xdelta; + ptr[2] = ptr[1] + s->xdelta; + in = ptr[2] + s->xdelta; + + for (j = 0; j < s->xdelta; ++j) { + uint32_t diff = (*(ptr[0]++) << 24) | + (*(ptr[1]++) << 16) | + (*(ptr[2]++) << 8); + pixel += diff; + bytestream_put_le32(&out, pixel); + } + break; + case EXR_HALF: + ptr[0] = in; + ptr[1] = ptr[0] + s->xdelta; + in = ptr[1] + s->xdelta; + for (j = 0; j < s->xdelta; j++) { + uint32_t diff = (*(ptr[0]++) << 8) | *(ptr[1]++); + + pixel += diff; + bytestream_put_le16(&out, pixel); + } + break; + default: + av_assert1(0); + } + } + } + + return 0; +} + +static int decode_block(AVCodecContext *avctx, void *tdata, + int jobnr, int threadnr) +{ + EXRContext *s = avctx->priv_data; + AVFrame *const p = &s->picture; + EXRThreadData *td = &s->thread_data[threadnr]; + const uint8_t *channel_buffer[4] = { 0 }; + const uint8_t *buf = s->buf; + uint64_t line_offset, uncompressed_size; + uint32_t xdelta = s->xdelta; + uint16_t *ptr_x; + uint8_t *ptr; + int32_t data_size, line; + const uint8_t *src; + int axmax = (avctx->width - (s->xmax + 1)) * 2 * s->desc->nb_components; + int bxmin = s->xmin * 2 * s->desc->nb_components; + int i, x, buf_size = s->buf_size; + int av_unused ret; + + line_offset = AV_RL64(s->table + jobnr * 8); + // Check if the buffer has the required bytes needed from the offset + if (line_offset > buf_size - 8) + return AVERROR_INVALIDDATA; + + src = buf + line_offset + 8; + line = AV_RL32(src - 8); + if (line < s->ymin || line > s->ymax) + return AVERROR_INVALIDDATA; + + data_size = AV_RL32(src - 4); + if (data_size <= 0 || data_size > buf_size) + return AVERROR_INVALIDDATA; + + s->ysize = FFMIN(s->scan_lines_per_block, s->ymax - line + 1); + uncompressed_size = s->scan_line_size * s->ysize; + if ((s->compr == EXR_RAW && (data_size != uncompressed_size || + line_offset > buf_size - uncompressed_size)) || + (s->compr != EXR_RAW && (data_size > uncompressed_size || + line_offset > buf_size - data_size))) { + return AVERROR_INVALIDDATA; + } + + if (data_size < uncompressed_size) { + av_fast_padded_malloc(&td->uncompressed_data, &td->uncompressed_size, uncompressed_size); + av_fast_padded_malloc(&td->tmp, &td->tmp_size, uncompressed_size); + if (!td->uncompressed_data || !td->tmp) + return AVERROR(ENOMEM); + + switch (s->compr) { + case EXR_ZIP1: + case EXR_ZIP16: + ret = zip_uncompress(src, data_size, uncompressed_size, td); + break; + case EXR_PXR24: + ret = pxr24_uncompress(s, src, data_size, uncompressed_size, td); + break; + case EXR_RLE: + ret = rle_uncompress(src, data_size, uncompressed_size, td); + } + + src = td->uncompressed_data; + } + + channel_buffer[0] = src + xdelta * s->channel_offsets[0]; + channel_buffer[1] = src + xdelta * s->channel_offsets[1]; + channel_buffer[2] = src + xdelta * s->channel_offsets[2]; + if (s->channel_offsets[3] >= 0) + channel_buffer[3] = src + xdelta * s->channel_offsets[3]; + + ptr = p->data[0] + line * p->linesize[0]; + for (i = 0; i < s->scan_lines_per_block && line + i <= s->ymax; i++, ptr += p->linesize[0]) { + const uint8_t *r, *g, *b, *a; + + r = channel_buffer[0]; + g = channel_buffer[1]; + b = channel_buffer[2]; + if (channel_buffer[3]) + a = channel_buffer[3]; + + ptr_x = (uint16_t *)ptr; + + // Zero out the start if xmin is not 0 + memset(ptr_x, 0, bxmin); + ptr_x += s->xmin * s->desc->nb_components; + if (s->pixel_type == EXR_FLOAT) { + // 32-bit + for (x = 0; x < xdelta; x++) { + *ptr_x++ = exr_flt2uint(bytestream_get_le32(&r)); + *ptr_x++ = exr_flt2uint(bytestream_get_le32(&g)); + *ptr_x++ = exr_flt2uint(bytestream_get_le32(&b)); + if (channel_buffer[3]) + *ptr_x++ = exr_flt2uint(bytestream_get_le32(&a)); + } + } else { + // 16-bit + for (x = 0; x < xdelta; x++) { + *ptr_x++ = exr_halflt2uint(bytestream_get_le16(&r)); + *ptr_x++ = exr_halflt2uint(bytestream_get_le16(&g)); + *ptr_x++ = exr_halflt2uint(bytestream_get_le16(&b)); + if (channel_buffer[3]) + *ptr_x++ = exr_halflt2uint(bytestream_get_le16(&a)); + } + } + + // Zero out the end if xmax+1 is not w + memset(ptr_x, 0, axmax); + + channel_buffer[0] += s->scan_line_size; + channel_buffer[1] += s->scan_line_size; + channel_buffer[2] += s->scan_line_size; + if (channel_buffer[3]) + channel_buffer[3] += s->scan_line_size; + } + + return 0; } static int decode_frame(AVCodecContext *avctx, @@ -230,34 +458,35 @@ static int decode_frame(AVCodecContext *avctx, unsigned int buf_size = avpkt->size; const uint8_t *buf_end = buf + buf_size; - const AVPixFmtDescriptor *desc; EXRContext *const s = avctx->priv_data; AVFrame *picture = data; AVFrame *const p = &s->picture; uint8_t *ptr; - int i, x, y, stride, magic_number, version_flag, ret; + int i, y, magic_number, version, flags, ret; int w = 0; int h = 0; - unsigned int xmin = ~0; - unsigned int xmax = ~0; - unsigned int ymin = ~0; - unsigned int ymax = ~0; - unsigned int xdelta = ~0; int out_line_size; - int bxmin, axmax; - int scan_lines_per_block; - unsigned long scan_line_size; - unsigned long uncompressed_size; + int scan_line_blocks; unsigned int current_channel_offset = 0; + s->xmin = ~0; + s->xmax = ~0; + s->ymin = ~0; + s->ymax = ~0; + s->xdelta = ~0; + s->ydelta = ~0; s->channel_offsets[0] = -1; s->channel_offsets[1] = -1; s->channel_offsets[2] = -1; s->channel_offsets[3] = -1; - s->bits_per_color_id = -1; + s->pixel_type = -1; + s->nb_channels = 0; + s->compr = -1; + s->buf = buf; + s->buf_size = buf_size; if (buf_size < 10) { av_log(avctx, AV_LOG_ERROR, "Too short header to parse\n"); @@ -270,8 +499,14 @@ static int decode_frame(AVCodecContext *avctx, return AVERROR_INVALIDDATA; } - version_flag = bytestream_get_le32(&buf); - if ((version_flag & 0x200) == 0x200) { + version = bytestream_get_byte(&buf); + if (version != 2) { + av_log(avctx, AV_LOG_ERROR, "Unsupported version %d\n", version); + return AVERROR_PATCHWELCOME; + } + + flags = bytestream_get_le24(&buf); + if (flags & 0x2) { av_log(avctx, AV_LOG_ERROR, "Tile based images are not supported\n"); return AVERROR_PATCHWELCOME; } @@ -287,8 +522,10 @@ static int decode_frame(AVCodecContext *avctx, channel_list_end = buf + variable_buffer_data_size; while (channel_list_end - buf >= 19) { - int current_bits_per_color_id = -1; + EXRChannel *channel; + int current_pixel_type = -1; int channel_index = -1; + int xsub, ysub; if (!strcmp(buf, "R")) channel_index = 0; @@ -309,23 +546,38 @@ static int decode_frame(AVCodecContext *avctx, return AVERROR_INVALIDDATA; } - current_bits_per_color_id = bytestream_get_le32(&buf); - if (current_bits_per_color_id > 2) { - av_log(avctx, AV_LOG_ERROR, "Unknown color format\n"); + current_pixel_type = bytestream_get_le32(&buf); + if (current_pixel_type > 2) { + av_log(avctx, AV_LOG_ERROR, "Unknown pixel type\n"); return AVERROR_INVALIDDATA; } + buf += 4; + xsub = bytestream_get_le32(&buf); + ysub = bytestream_get_le32(&buf); + if (xsub != 1 || ysub != 1) { + av_log(avctx, AV_LOG_ERROR, "Unsupported subsampling %dx%d\n", xsub, ysub); + return AVERROR_PATCHWELCOME; + } + if (channel_index >= 0) { - if (s->bits_per_color_id != -1 && s->bits_per_color_id != current_bits_per_color_id) { + if (s->pixel_type != -1 && s->pixel_type != current_pixel_type) { av_log(avctx, AV_LOG_ERROR, "RGB channels not of the same depth\n"); return AVERROR_INVALIDDATA; } - s->bits_per_color_id = current_bits_per_color_id; + s->pixel_type = current_pixel_type; s->channel_offsets[channel_index] = current_channel_offset; } - current_channel_offset += 1 << current_bits_per_color_id; - buf += 12; + s->channels = av_realloc_f(s->channels, ++s->nb_channels, sizeof(EXRChannel)); + if (!s->channels) + return AVERROR(ENOMEM); + channel = &s->channels[s->nb_channels - 1]; + channel->pixel_type = current_pixel_type; + channel->xsub = xsub; + channel->ysub = ysub; + + current_channel_offset += 1 << current_pixel_type; } /* Check if all channels are set with an offset or if the channels @@ -345,25 +597,20 @@ static int decode_frame(AVCodecContext *avctx, buf = channel_list_end; continue; - } - - // Process the dataWindow variable - if (check_header_variable(avctx, &buf, buf_end, "dataWindow", "box2i", 31, &variable_buffer_data_size) >= 0) { + } else if (check_header_variable(avctx, &buf, buf_end, "dataWindow", "box2i", 31, &variable_buffer_data_size) >= 0) { if (!variable_buffer_data_size) return AVERROR_INVALIDDATA; - xmin = AV_RL32(buf); - ymin = AV_RL32(buf + 4); - xmax = AV_RL32(buf + 8); - ymax = AV_RL32(buf + 12); - xdelta = (xmax-xmin) + 1; + s->xmin = AV_RL32(buf); + s->ymin = AV_RL32(buf + 4); + s->xmax = AV_RL32(buf + 8); + s->ymax = AV_RL32(buf + 12); + s->xdelta = (s->xmax - s->xmin) + 1; + s->ydelta = (s->ymax - s->ymin) + 1; buf += variable_buffer_data_size; continue; - } - - // Process the displayWindow variable - if (check_header_variable(avctx, &buf, buf_end, "displayWindow", "box2i", 34, &variable_buffer_data_size) >= 0) { + } else if (check_header_variable(avctx, &buf, buf_end, "displayWindow", "box2i", 34, &variable_buffer_data_size) >= 0) { if (!variable_buffer_data_size) return AVERROR_INVALIDDATA; @@ -372,24 +619,19 @@ static int decode_frame(AVCodecContext *avctx, buf += variable_buffer_data_size; continue; - } - - // Process the lineOrder variable - if (check_header_variable(avctx, &buf, buf_end, "lineOrder", "lineOrder", 25, &variable_buffer_data_size) >= 0) { + } else if (check_header_variable(avctx, &buf, buf_end, "lineOrder", "lineOrder", 25, &variable_buffer_data_size) >= 0) { if (!variable_buffer_data_size) return AVERROR_INVALIDDATA; - if (*buf) { - av_log(avctx, AV_LOG_ERROR, "Doesn't support this line order : %d\n", *buf); - return AVERROR_PATCHWELCOME; + av_log(avctx, AV_LOG_DEBUG, "line order : %d\n", *buf); + if (*buf > 2) { + av_log(avctx, AV_LOG_ERROR, "Unknown line order\n"); + return AVERROR_INVALIDDATA; } buf += variable_buffer_data_size; continue; - } - - // Process the pixelAspectRatio variable - if (check_header_variable(avctx, &buf, buf_end, "pixelAspectRatio", "float", 31, &variable_buffer_data_size) >= 0) { + } else if (check_header_variable(avctx, &buf, buf_end, "pixelAspectRatio", "float", 31, &variable_buffer_data_size) >= 0) { if (!variable_buffer_data_size) return AVERROR_INVALIDDATA; @@ -397,10 +639,7 @@ static int decode_frame(AVCodecContext *avctx, buf += variable_buffer_data_size; continue; - } - - // Process the compression variable - if (check_header_variable(avctx, &buf, buf_end, "compression", "compression", 29, &variable_buffer_data_size) >= 0) { + } else if (check_header_variable(avctx, &buf, buf_end, "compression", "compression", 29, &variable_buffer_data_size) >= 0) { if (!variable_buffer_data_size) return AVERROR_INVALIDDATA; @@ -449,20 +688,19 @@ static int decode_frame(AVCodecContext *avctx, } buf++; - switch (s->bits_per_color_id) { - case 2: // 32-bit - case 1: // 16-bit + switch (s->pixel_type) { + case EXR_FLOAT: + case EXR_HALF: if (s->channel_offsets[3] >= 0) avctx->pix_fmt = AV_PIX_FMT_RGBA64; else avctx->pix_fmt = AV_PIX_FMT_RGB48; break; - // 8-bit - case 0: - av_log_missing_feature(avctx, "8-bit OpenEXR", 1); + case EXR_UINT: + av_log_missing_feature(avctx, "32-bit unsigned int", 1); return AVERROR_PATCHWELCOME; default: - av_log(avctx, AV_LOG_ERROR, "Unknown color format : %d\n", s->bits_per_color_id); + av_log(avctx, AV_LOG_ERROR, "Missing channel list\n"); return AVERROR_INVALIDDATA; } @@ -470,10 +708,11 @@ static int decode_frame(AVCodecContext *avctx, case EXR_RAW: case EXR_RLE: case EXR_ZIP1: - scan_lines_per_block = 1; + s->scan_lines_per_block = 1; break; + case EXR_PXR24: case EXR_ZIP16: - scan_lines_per_block = 16; + s->scan_lines_per_block = 16; break; default: av_log(avctx, AV_LOG_ERROR, "Compression type %d is not supported\n", s->compr); @@ -486,7 +725,10 @@ static int decode_frame(AVCodecContext *avctx, return AVERROR_INVALIDDATA; // Verify the xmin, xmax, ymin, ymax and xdelta before setting the actual image size - if (xmin > xmax || ymin > ymax || xdelta != xmax - xmin + 1 || xmax >= w || ymax >= h) { + if (s->xmin > s->xmax || + s->ymin > s->ymax || + s->xdelta != s->xmax - s->xmin + 1 || + s->xmax >= w || s->ymax >= h) { av_log(avctx, AV_LOG_ERROR, "Wrong sizing or missing size information\n"); return AVERROR_INVALIDDATA; } @@ -495,18 +737,24 @@ static int decode_frame(AVCodecContext *avctx, avcodec_set_dimensions(avctx, w, h); } - desc = av_pix_fmt_desc_get(avctx->pix_fmt); - bxmin = xmin * 2 * desc->nb_components; - axmax = (avctx->width - (xmax + 1)) * 2 * desc->nb_components; - out_line_size = avctx->width * 2 * desc->nb_components; - scan_line_size = xdelta * current_channel_offset; - uncompressed_size = scan_line_size * scan_lines_per_block; + s->desc = av_pix_fmt_desc_get(avctx->pix_fmt); + out_line_size = avctx->width * 2 * s->desc->nb_components; + s->scan_line_size = s->xdelta * current_channel_offset; + scan_line_blocks = (s->ydelta + s->scan_lines_per_block - 1) / s->scan_lines_per_block; if (s->compr != EXR_RAW) { - av_fast_padded_malloc(&s->uncompressed_data, &s->uncompressed_size, uncompressed_size); - av_fast_padded_malloc(&s->tmp, &s->tmp_size, uncompressed_size); - if (!s->uncompressed_data || !s->tmp) + size_t thread_data_size, prev_size; + EXRThreadData *m; + + prev_size = s->thread_data_size; + if (av_size_mult(avctx->thread_count, sizeof(EXRThreadData), &thread_data_size)) + return AVERROR(EINVAL); + + m = av_fast_realloc(s->thread_data, &s->thread_data_size, thread_data_size); + if (!m) return AVERROR(ENOMEM); + s->thread_data = m; + memset(s->thread_data + prev_size, 0, s->thread_data_size - prev_size); } if ((ret = ff_thread_get_buffer(avctx, p)) < 0) { @@ -514,122 +762,23 @@ static int decode_frame(AVCodecContext *avctx, return ret; } - ptr = p->data[0]; - stride = p->linesize[0]; + if (buf_end - buf < scan_line_blocks * 8) + return AVERROR_INVALIDDATA; + s->table = buf; + ptr = p->data[0]; // Zero out the start if ymin is not 0 - for (y = 0; y < ymin; y++) { + for (y = 0; y < s->ymin; y++) { memset(ptr, 0, out_line_size); - ptr += stride; + ptr += p->linesize[0]; } - // Process the actual scan line blocks - for (y = ymin; y <= ymax; y += scan_lines_per_block) { - uint16_t *ptr_x = (uint16_t *)ptr; - if (buf_end - buf > 8) { - /* Read the lineoffset from the line offset table and add 8 bytes - to skip the coordinates and data size fields */ - const uint64_t line_offset = bytestream_get_le64(&buf) + 8; - int32_t data_size; - - // Check if the buffer has the required bytes needed from the offset - if ((line_offset > buf_size) || - (s->compr == EXR_RAW && line_offset > avpkt->size - xdelta * current_channel_offset) || - (s->compr != EXR_RAW && line_offset > buf_size - (data_size = AV_RL32(avpkt->data + line_offset - 4)))) { - // Line offset is probably wrong and not inside the buffer - av_log(avctx, AV_LOG_WARNING, "Line offset for line %d is out of reach setting it to black\n", y); - for (i = 0; i < scan_lines_per_block && y + i <= ymax; i++, ptr += stride) { - ptr_x = (uint16_t *)ptr; - memset(ptr_x, 0, out_line_size); - } - } else { - const uint8_t *red_channel_buffer, *green_channel_buffer, *blue_channel_buffer, *alpha_channel_buffer = 0; - - if (scan_lines_per_block > 1) - uncompressed_size = scan_line_size * FFMIN(scan_lines_per_block, ymax - y + 1); - if ((s->compr == EXR_ZIP1 || s->compr == EXR_ZIP16) && data_size < uncompressed_size) { - unsigned long dest_len = uncompressed_size; - - if (uncompress(s->tmp, &dest_len, avpkt->data + line_offset, data_size) != Z_OK || - dest_len != uncompressed_size) { - av_log(avctx, AV_LOG_ERROR, "error during zlib decompression\n"); - return AVERROR(EINVAL); - } - } else if (s->compr == EXR_RLE && data_size < uncompressed_size) { - if (rle_uncompress(avpkt->data + line_offset, data_size, s->tmp, uncompressed_size)) { - av_log(avctx, AV_LOG_ERROR, "error during rle decompression\n"); - return AVERROR(EINVAL); - } - } - - if (s->compr != EXR_RAW && data_size < uncompressed_size) { - predictor(s->tmp, uncompressed_size); - reorder_pixels(s->tmp, s->uncompressed_data, uncompressed_size); - - red_channel_buffer = s->uncompressed_data + xdelta * s->channel_offsets[0]; - green_channel_buffer = s->uncompressed_data + xdelta * s->channel_offsets[1]; - blue_channel_buffer = s->uncompressed_data + xdelta * s->channel_offsets[2]; - if (s->channel_offsets[3] >= 0) - alpha_channel_buffer = s->uncompressed_data + xdelta * s->channel_offsets[3]; - } else { - red_channel_buffer = avpkt->data + line_offset + xdelta * s->channel_offsets[0]; - green_channel_buffer = avpkt->data + line_offset + xdelta * s->channel_offsets[1]; - blue_channel_buffer = avpkt->data + line_offset + xdelta * s->channel_offsets[2]; - if (s->channel_offsets[3] >= 0) - alpha_channel_buffer = avpkt->data + line_offset + xdelta * s->channel_offsets[3]; - } - - for (i = 0; i < scan_lines_per_block && y + i <= ymax; i++, ptr += stride) { - const uint8_t *r, *g, *b, *a; - - r = red_channel_buffer; - g = green_channel_buffer; - b = blue_channel_buffer; - if (alpha_channel_buffer) - a = alpha_channel_buffer; - - ptr_x = (uint16_t *)ptr; - - // Zero out the start if xmin is not 0 - memset(ptr_x, 0, bxmin); - ptr_x += xmin * desc->nb_components; - if (s->bits_per_color_id == 2) { - // 32-bit - for (x = 0; x < xdelta; x++) { - *ptr_x++ = exr_flt2uint(bytestream_get_le32(&r)); - *ptr_x++ = exr_flt2uint(bytestream_get_le32(&g)); - *ptr_x++ = exr_flt2uint(bytestream_get_le32(&b)); - if (alpha_channel_buffer) - *ptr_x++ = exr_flt2uint(bytestream_get_le32(&a)); - } - } else { - // 16-bit - for (x = 0; x < xdelta; x++) { - *ptr_x++ = exr_halflt2uint(bytestream_get_le16(&r)); - *ptr_x++ = exr_halflt2uint(bytestream_get_le16(&g)); - *ptr_x++ = exr_halflt2uint(bytestream_get_le16(&b)); - if (alpha_channel_buffer) - *ptr_x++ = exr_halflt2uint(bytestream_get_le16(&a)); - } - } - - // Zero out the end if xmax+1 is not w - memset(ptr_x, 0, axmax); - - red_channel_buffer += scan_line_size; - green_channel_buffer += scan_line_size; - blue_channel_buffer += scan_line_size; - if (alpha_channel_buffer) - alpha_channel_buffer += scan_line_size; - } - } - } - } + avctx->execute2(avctx, decode_block, s->thread_data, NULL, scan_line_blocks); // Zero out the end if ymax+1 is not h - for (y = ymax + 1; y < avctx->height; y++) { + for (y = s->ymax + 1; y < avctx->height; y++) { memset(ptr, 0, out_line_size); - ptr += stride; + ptr += p->linesize[0]; } *picture = s->picture; @@ -645,20 +794,26 @@ static av_cold int decode_init(AVCodecContext *avctx) avcodec_get_frame_defaults(&s->picture); avctx->coded_frame = &s->picture; - s->compr = -1; - return 0; } static av_cold int decode_end(AVCodecContext *avctx) { EXRContext *s = avctx->priv_data; + int i; if (s->picture.data[0]) avctx->release_buffer(avctx, &s->picture); - av_freep(&s->uncompressed_data); - av_freep(&s->tmp); + for (i = 0; i < s->thread_data_size / sizeof(EXRThreadData); i++) { + EXRThreadData *td = &s->thread_data[i]; + av_free(td->uncompressed_data); + av_free(td->tmp); + } + + av_freep(&s->thread_data); + s->thread_data_size = 0; + av_freep(&s->channels); return 0; } @@ -671,6 +826,6 @@ AVCodec ff_exr_decoder = { .init = decode_init, .close = decode_end, .decode = decode_frame, - .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS, + .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS | CODEC_CAP_SLICE_THREADS, .long_name = NULL_IF_CONFIG_SMALL("OpenEXR image"), }; diff --git a/mythtv/external/FFmpeg/libavcodec/faandct.c b/mythtv/external/FFmpeg/libavcodec/faandct.c index 1379394aa9e..b1d7a145f4f 100644 --- a/mythtv/external/FFmpeg/libavcodec/faandct.c +++ b/mythtv/external/FFmpeg/libavcodec/faandct.c @@ -25,7 +25,6 @@ * @author Michael Niedermayer */ -#include "dsputil.h" #include "faandct.h" #include "libavutil/internal.h" #include "libavutil/libm.h" @@ -64,7 +63,7 @@ B6*B0, B6*B1, B6*B2, B6*B3, B6*B4, B6*B5, B6*B6, B6*B7, B7*B0, B7*B1, B7*B2, B7*B3, B7*B4, B7*B5, B7*B6, B7*B7, }; -static av_always_inline void row_fdct(FLOAT temp[64], DCTELEM * data) +static av_always_inline void row_fdct(FLOAT temp[64], int16_t *data) { FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; FLOAT tmp10, tmp11, tmp12, tmp13; @@ -119,7 +118,7 @@ static av_always_inline void row_fdct(FLOAT temp[64], DCTELEM * data) } } -void ff_faandct(DCTELEM * data) +void ff_faandct(int16_t *data) { FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; FLOAT tmp10, tmp11, tmp12, tmp13; @@ -179,7 +178,7 @@ void ff_faandct(DCTELEM * data) } } -void ff_faandct248(DCTELEM * data) +void ff_faandct248(int16_t *data) { FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; FLOAT tmp10, tmp11, tmp12, tmp13; diff --git a/mythtv/external/FFmpeg/libavcodec/faandct.h b/mythtv/external/FFmpeg/libavcodec/faandct.h index a12dcaf92fb..c5ef96dcf19 100644 --- a/mythtv/external/FFmpeg/libavcodec/faandct.h +++ b/mythtv/external/FFmpeg/libavcodec/faandct.h @@ -29,9 +29,9 @@ #ifndef AVCODEC_FAANDCT_H #define AVCODEC_FAANDCT_H -#include "dsputil.h" +#include -void ff_faandct(DCTELEM * data); -void ff_faandct248(DCTELEM * data); +void ff_faandct(int16_t *data); +void ff_faandct248(int16_t *data); #endif /* AVCODEC_FAANDCT_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/faanidct.c b/mythtv/external/FFmpeg/libavcodec/faanidct.c index 1e9bfaf48a3..5f34fa508f1 100644 --- a/mythtv/external/FFmpeg/libavcodec/faanidct.c +++ b/mythtv/external/FFmpeg/libavcodec/faanidct.c @@ -47,7 +47,7 @@ B6*B0/8, B6*B1/8, B6*B2/8, B6*B3/8, B6*B4/8, B6*B5/8, B6*B6/8, B6*B7/8, B7*B0/8, B7*B1/8, B7*B2/8, B7*B3/8, B7*B4/8, B7*B5/8, B7*B6/8, B7*B7/8, }; -static inline void p8idct(DCTELEM data[64], FLOAT temp[64], uint8_t *dest, int stride, int x, int y, int type){ +static inline void p8idct(int16_t data[64], FLOAT temp[64], uint8_t *dest, int stride, int x, int y, int type){ int i; FLOAT av_unused tmp0; FLOAT s04, d04, s17, d17, s26, d26, s53, d53; @@ -129,7 +129,7 @@ static inline void p8idct(DCTELEM data[64], FLOAT temp[64], uint8_t *dest, int s } } -void ff_faanidct(DCTELEM block[64]){ +void ff_faanidct(int16_t block[64]){ FLOAT temp[64]; int i; @@ -142,7 +142,7 @@ void ff_faanidct(DCTELEM block[64]){ p8idct(block, temp, NULL, 0, 8, 1, 1); } -void ff_faanidct_add(uint8_t *dest, int line_size, DCTELEM block[64]){ +void ff_faanidct_add(uint8_t *dest, int line_size, int16_t block[64]){ FLOAT temp[64]; int i; @@ -155,7 +155,7 @@ void ff_faanidct_add(uint8_t *dest, int line_size, DCTELEM block[64]){ p8idct(NULL , temp, dest, line_size, 8, 1, 2); } -void ff_faanidct_put(uint8_t *dest, int line_size, DCTELEM block[64]){ +void ff_faanidct_put(uint8_t *dest, int line_size, int16_t block[64]){ FLOAT temp[64]; int i; diff --git a/mythtv/external/FFmpeg/libavcodec/faanidct.h b/mythtv/external/FFmpeg/libavcodec/faanidct.h index 4cf11892863..4cd2c7858f8 100644 --- a/mythtv/external/FFmpeg/libavcodec/faanidct.h +++ b/mythtv/external/FFmpeg/libavcodec/faanidct.h @@ -23,10 +23,9 @@ #define AVCODEC_FAANIDCT_H #include -#include "dsputil.h" -void ff_faanidct(DCTELEM block[64]); -void ff_faanidct_add(uint8_t *dest, int line_size, DCTELEM block[64]); -void ff_faanidct_put(uint8_t *dest, int line_size, DCTELEM block[64]); +void ff_faanidct(int16_t block[64]); +void ff_faanidct_add(uint8_t *dest, int line_size, int16_t block[64]); +void ff_faanidct_put(uint8_t *dest, int line_size, int16_t block[64]); #endif /* AVCODEC_FAANIDCT_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/faxcompr.c b/mythtv/external/FFmpeg/libavcodec/faxcompr.c index 3e51a3e7933..86be97792e3 100644 --- a/mythtv/external/FFmpeg/libavcodec/faxcompr.c +++ b/mythtv/external/FFmpeg/libavcodec/faxcompr.c @@ -170,10 +170,12 @@ static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb, return -1; } if(!cmode){//pass mode - run_off += *ref++; + if(run_off < width) + run_off += *ref++; run = run_off - offs; offs= run_off; - run_off += *ref++; + if(run_off < width) + run_off += *ref++; if(offs > width){ av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n"); return -1; diff --git a/mythtv/external/FFmpeg/libavcodec/fft-internal.h b/mythtv/external/FFmpeg/libavcodec/fft-internal.h index 61066bb18b7..d66731fb48e 100644 --- a/mythtv/external/FFmpeg/libavcodec/fft-internal.h +++ b/mythtv/external/FFmpeg/libavcodec/fft-internal.h @@ -36,7 +36,7 @@ #else -#include "libavutil/intmath.h" +#include "fft.h" #include "mathops.h" void ff_mdct_calcw_c(FFTContext *s, FFTDouble *output, const FFTSample *input); diff --git a/mythtv/external/FFmpeg/libavcodec/ffv1.c b/mythtv/external/FFmpeg/libavcodec/ffv1.c index 074be4cfbb0..c75f2aa619a 100644 --- a/mythtv/external/FFmpeg/libavcodec/ffv1.c +++ b/mythtv/external/FFmpeg/libavcodec/ffv1.c @@ -33,7 +33,6 @@ #include "libavutil/timer.h" #include "avcodec.h" #include "internal.h" -#include "dsputil.h" #include "rangecoder.h" #include "golomb.h" #include "mathops.h" @@ -123,6 +122,10 @@ av_cold int ffv1_init_slice_contexts(FFV1Context *f) int sxe = f->avctx->width * (sx + 1) / f->num_h_slices; int sys = f->avctx->height * sy / f->num_v_slices; int sye = f->avctx->height * (sy + 1) / f->num_v_slices; + + if (!fs) + return AVERROR(ENOMEM); + f->slice_context[i] = fs; memcpy(fs, f, sizeof(*fs)); memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2)); diff --git a/mythtv/external/FFmpeg/libavcodec/ffv1dec.c b/mythtv/external/FFmpeg/libavcodec/ffv1dec.c index a1da544697b..cb722034685 100644 --- a/mythtv/external/FFmpeg/libavcodec/ffv1dec.c +++ b/mythtv/external/FFmpeg/libavcodec/ffv1dec.c @@ -35,7 +35,6 @@ #include "internal.h" #include "get_bits.h" #include "put_bits.h" -#include "dsputil.h" #include "rangecoder.h" #include "golomb.h" #include "mathops.h" diff --git a/mythtv/external/FFmpeg/libavcodec/ffv1enc.c b/mythtv/external/FFmpeg/libavcodec/ffv1enc.c index 031db061fee..70fcd65852a 100644 --- a/mythtv/external/FFmpeg/libavcodec/ffv1enc.c +++ b/mythtv/external/FFmpeg/libavcodec/ffv1enc.c @@ -33,8 +33,7 @@ #include "libavutil/timer.h" #include "avcodec.h" #include "internal.h" -#include "get_bits.h" -#include "dsputil.h" +#include "put_bits.h" #include "rangecoder.h" #include "golomb.h" #include "mathops.h" @@ -395,8 +394,8 @@ static void encode_rgb_frame(FFV1Context *s, uint8_t *src[3], int w, int h, int int x, y, p, i; const int ring_size = s->avctx->context_model ? 3 : 2; int16_t *sample[4][3]; - int lbd = s->avctx->bits_per_raw_sample <= 8; - int bits = s->avctx->bits_per_raw_sample > 0 ? s->avctx->bits_per_raw_sample : 8; + int lbd = s->bits_per_raw_sample <= 8; + int bits = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8; int offset = 1 << bits; s->run_index = 0; @@ -856,18 +855,29 @@ static av_cold int encode_init(AVCodecContext *avctx) find_best_state(best_state, s->state_transition); for (i = 0; i < s->quant_table_count; i++) { - for (j = 0; j < s->context_count[i]; j++) - for (k = 0; k < 32; k++) { + for (k = 0; k < 32; k++) { + double a=0, b=0; + int jp = 0; + for (j = 0; j < s->context_count[i]; j++) { double p = 128; - if (s->rc_stat2[i][j][k][0] + s->rc_stat2[i][j][k][1]) { - p = 256.0 * s->rc_stat2[i][j][k][1] / - (s->rc_stat2[i][j][k][0] + s->rc_stat2[i][j][k][1]); + if (s->rc_stat2[i][j][k][0] + s->rc_stat2[i][j][k][1] > 200 && j || a+b > 200) { + if (a+b) + p = 256.0 * b / (a + b); + s->initial_states[i][jp][k] = + best_state[av_clip(round(p), 1, 255)][av_clip((a + b) / gob_count, 0, 255)]; + for(jp++; jpinitial_states[i][jp][k] = s->initial_states[i][jp-1][k]; + a=b=0; + } + a += s->rc_stat2[i][j][k][0]; + b += s->rc_stat2[i][j][k][1]; + if (a+b) { + p = 256.0 * b / (a + b); } s->initial_states[i][j][k] = - best_state[av_clip(round(p), 1, 255)][av_clip((s->rc_stat2[i][j][k][0] + - s->rc_stat2[i][j][k][1]) / - gob_count, 0, 255)]; + best_state[av_clip(round(p), 1, 255)][av_clip((a + b) / gob_count, 0, 255)]; } + } } } @@ -896,6 +906,8 @@ static av_cold int encode_init(AVCodecContext *avctx) #define STATS_OUT_SIZE 1024 * 1024 * 6 if (avctx->flags & CODEC_FLAG_PASS1) { avctx->stats_out = av_mallocz(STATS_OUT_SIZE); + if (!avctx->stats_out) + return AVERROR(ENOMEM); for (i = 0; i < s->quant_table_count; i++) for (j = 0; j < s->slice_count; j++) { FFV1Context *sf = s->slice_context[j]; diff --git a/mythtv/external/FFmpeg/libavcodec/flac.c b/mythtv/external/FFmpeg/libavcodec/flac.c index f767f6b367c..a79a80964df 100644 --- a/mythtv/external/FFmpeg/libavcodec/flac.c +++ b/mythtv/external/FFmpeg/libavcodec/flac.c @@ -29,13 +29,15 @@ static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 }; -static const int64_t flac_channel_layouts[6] = { +static const uint64_t flac_channel_layouts[8] = { AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_SURROUND, AV_CH_LAYOUT_QUAD, AV_CH_LAYOUT_5POINT0, - AV_CH_LAYOUT_5POINT1 + AV_CH_LAYOUT_5POINT1, + AV_CH_LAYOUT_6POINT1, + AV_CH_LAYOUT_7POINT1 }; static int64_t get_utf8(GetBitContext *gb) diff --git a/mythtv/external/FFmpeg/libavcodec/flac_parser.c b/mythtv/external/FFmpeg/libavcodec/flac_parser.c index 52ec1ee6838..e2c6744d783 100644 --- a/mythtv/external/FFmpeg/libavcodec/flac_parser.c +++ b/mythtv/external/FFmpeg/libavcodec/flac_parser.c @@ -458,7 +458,7 @@ static int get_best_header(FLACParseContext* fpc, const uint8_t **poutbuf, } if (header->fi.channels != fpc->avctx->channels || - (!fpc->avctx->channel_layout && header->fi.channels <= 6)) { + !fpc->avctx->channel_layout) { fpc->avctx->channels = header->fi.channels; ff_flac_set_channel_layout(fpc->avctx); } diff --git a/mythtv/external/FFmpeg/libavcodec/flacdec.c b/mythtv/external/FFmpeg/libavcodec/flacdec.c index 9d5ecd04cfe..91a25f02c48 100644 --- a/mythtv/external/FFmpeg/libavcodec/flacdec.c +++ b/mythtv/external/FFmpeg/libavcodec/flacdec.c @@ -49,7 +49,6 @@ typedef struct FLACContext { FLACSTREAMINFO AVCodecContext *avctx; ///< parent AVCodecContext - AVFrame frame; GetBitContext gb; ///< GetBitContext initialized to start at the current frame int blocksize; ///< number of samples in the current frame @@ -113,9 +112,6 @@ static av_cold int flac_decode_init(AVCodecContext *avctx) ff_flacdsp_init(&s->dsp, avctx->sample_fmt, s->bps); s->got_streaminfo = 1; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -254,7 +250,7 @@ static int decode_subframe_fixed(FLACContext *s, int32_t *decoded, int pred_order, int bps) { const int blocksize = s->blocksize; - int a, b, c, d, i; + int av_uninit(a), av_uninit(b), av_uninit(c), av_uninit(d), i; /* warm up samples */ for (i = 0; i < pred_order; i++) { @@ -424,7 +420,7 @@ static int decode_frame(FLACContext *s) return ret; } s->channels = s->avctx->channels = fi.channels; - if (!s->avctx->channel_layout && s->channels <= 6) + if (!s->avctx->channel_layout) ff_flac_set_channel_layout(s->avctx); s->ch_mode = fi.ch_mode; @@ -491,6 +487,7 @@ static int decode_frame(FLACContext *s) static int flac_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; FLACContext *s = avctx->priv_data; @@ -505,6 +502,16 @@ static int flac_decode_frame(AVCodecContext *avctx, void *data, FLAC_MAX_CHANNELS, 32); } + if (buf_size > 5 && !memcmp(buf, "\177FLAC", 5)) { + av_log(s->avctx, AV_LOG_DEBUG, "skiping flac header packet 1\n"); + return buf_size; + } + + if (buf_size > 0 && (*buf & 0x7F) == FLAC_METADATA_TYPE_VORBIS_COMMENT) { + av_log(s->avctx, AV_LOG_DEBUG, "skiping vorbis comment\n"); + return buf_size; + } + /* check that there is at least the smallest decodable amount of data. this amount corresponds to the smallest valid FLAC frame possible. FF F8 69 02 00 00 9A 00 00 34 46 */ @@ -526,16 +533,24 @@ static int flac_decode_frame(AVCodecContext *avctx, void *data, av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n"); return -1; } - bytes_read = (get_bits_count(&s->gb)+7)/8; + bytes_read = get_bits_count(&s->gb)/8; + + if ((s->avctx->err_recognition & AV_EF_CRCCHECK) && + av_crc(av_crc_get_table(AV_CRC_16_ANSI), + 0, buf, bytes_read)) { + av_log(s->avctx, AV_LOG_ERROR, "CRC error at PTS %"PRId64"\n", avpkt->pts); + if (s->avctx->err_recognition & AV_EF_EXPLODE) + return AVERROR_INVALIDDATA; + } /* get output buffer */ - s->frame.nb_samples = s->blocksize; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = s->blocksize; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - s->dsp.decorrelate[s->ch_mode](s->frame.data, s->decoded, s->channels, + s->dsp.decorrelate[s->ch_mode](frame->data, s->decoded, s->channels, s->blocksize, s->sample_shift); if (bytes_read > buf_size) { @@ -547,8 +562,7 @@ static int flac_decode_frame(AVCodecContext *avctx, void *data, buf_size - bytes_read, buf_size); } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return bytes_read; } diff --git a/mythtv/external/FFmpeg/libavcodec/flacenc.c b/mythtv/external/FFmpeg/libavcodec/flacenc.c index b6364e1afca..354a0f76862 100644 --- a/mythtv/external/FFmpeg/libavcodec/flacenc.c +++ b/mythtv/external/FFmpeg/libavcodec/flacenc.c @@ -26,7 +26,7 @@ #include "libavutil/opt.h" #include "avcodec.h" #include "dsputil.h" -#include "get_bits.h" +#include "put_bits.h" #include "golomb.h" #include "internal.h" #include "lpc.h" @@ -1276,7 +1276,7 @@ static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } } - if ((ret = ff_alloc_packet2(avctx, avpkt, frame_bytes))) + if ((ret = ff_alloc_packet2(avctx, avpkt, frame_bytes)) < 0) return ret; out_bytes = write_frame(s, avpkt); diff --git a/mythtv/external/FFmpeg/libavcodec/flashsv.c b/mythtv/external/FFmpeg/libavcodec/flashsv.c index 78554165677..21464ed6b4a 100644 --- a/mythtv/external/FFmpeg/libavcodec/flashsv.c +++ b/mythtv/external/FFmpeg/libavcodec/flashsv.c @@ -245,6 +245,8 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data, FlashSVContext *s = avctx->priv_data; int h_blocks, v_blocks, h_part, v_part, i, j; GetBitContext gb; + int last_blockwidth = s->block_width; + int last_blockheight= s->block_height; /* no supplementary picture */ if (buf_size == 0) @@ -260,6 +262,10 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data, s->block_height = 16 * (get_bits(&gb, 4) + 1); s->image_height = get_bits(&gb, 12); + if ( last_blockwidth != s->block_width + || last_blockheight!= s->block_height) + av_freep(&s->blocks); + if (s->ver == 2) { skip_bits(&gb, 6); if (get_bits1(&gb)) { @@ -323,9 +329,8 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data, s->keyframedata = av_realloc(s->keyframedata, avpkt->size); memcpy(s->keyframedata, avpkt->data, avpkt->size); } - if(s->ver == 2) - s->blocks = av_realloc(s->blocks, - (v_blocks + !!v_part) * (h_blocks + !!h_part) + if(s->ver == 2 && !s->blocks) + s->blocks = av_mallocz((v_blocks + !!v_part) * (h_blocks + !!h_part) * sizeof(s->blocks[0])); av_dlog(avctx, "image: %dx%d block: %dx%d num: %dx%d part: %dx%d\n", diff --git a/mythtv/external/FFmpeg/libavcodec/flicvideo.c b/mythtv/external/FFmpeg/libavcodec/flicvideo.c index e1bb2dd7d38..2f8cd338027 100644 --- a/mythtv/external/FFmpeg/libavcodec/flicvideo.c +++ b/mythtv/external/FFmpeg/libavcodec/flicvideo.c @@ -792,7 +792,7 @@ static int flic_decode_frame(AVCodecContext *avctx, /* the finite set of possibilites allowable by here. */ /* But in case we do, just error out. */ av_log(avctx, AV_LOG_ERROR, "Unknown FLC format, my science cannot explain how this happened.\n"); - return AVERROR_INVALIDDATA; + return AVERROR_BUG; } diff --git a/mythtv/external/FFmpeg/libavcodec/fmtconvert.h b/mythtv/external/FFmpeg/libavcodec/fmtconvert.h index ab2caa2089b..3fb9f4e46bc 100644 --- a/mythtv/external/FFmpeg/libavcodec/fmtconvert.h +++ b/mythtv/external/FFmpeg/libavcodec/fmtconvert.h @@ -87,7 +87,7 @@ typedef struct FmtConvertContext { void ff_float_interleave_c(float *dst, const float **src, unsigned int len, int channels); -av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx); +void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx); void ff_fmt_convert_init_arm(FmtConvertContext *c, AVCodecContext *avctx); void ff_fmt_convert_init_altivec(FmtConvertContext *c, AVCodecContext *avctx); diff --git a/mythtv/external/FFmpeg/libavcodec/fraps.c b/mythtv/external/FFmpeg/libavcodec/fraps.c index e0fa916481e..5e2ba90d3f9 100644 --- a/mythtv/external/FFmpeg/libavcodec/fraps.c +++ b/mythtv/external/FFmpeg/libavcodec/fraps.c @@ -43,7 +43,7 @@ /** * local variable storage */ -typedef struct FrapsContext{ +typedef struct FrapsContext { AVCodecContext *avctx; AVFrame frame; uint8_t *tmpbuf; @@ -64,7 +64,7 @@ static av_cold int decode_init(AVCodecContext *avctx) avcodec_get_frame_defaults(&s->frame); avctx->coded_frame = &s->frame; - s->avctx = avctx; + s->avctx = avctx; s->tmpbuf = NULL; ff_dsputil_init(&s->dsp, avctx); @@ -76,7 +76,8 @@ static av_cold int decode_init(AVCodecContext *avctx) * Comparator - our nodes should ascend by count * but with preserved symbol order */ -static int huff_cmp(const void *va, const void *vb){ +static int huff_cmp(const void *va, const void *vb) +{ const Node *a = va, *b = vb; return (a->count - b->count)*256 + a->sym - b->sym; } @@ -88,31 +89,33 @@ static int fraps2_decode_plane(FrapsContext *s, uint8_t *dst, int stride, int w, int h, const uint8_t *src, int size, int Uoff, const int step) { - int i, j; + int i, j, ret; GetBitContext gb; VLC vlc; Node nodes[512]; - for(i = 0; i < 256; i++) + for (i = 0; i < 256; i++) nodes[i].count = bytestream_get_le32(&src); size -= 1024; - if (ff_huff_build_tree(s->avctx, &vlc, 256, nodes, huff_cmp, - FF_HUFFMAN_FLAG_ZERO_COUNT) < 0) - return -1; + if ((ret = ff_huff_build_tree(s->avctx, &vlc, 256, nodes, huff_cmp, + FF_HUFFMAN_FLAG_ZERO_COUNT)) < 0) + return ret; /* we have built Huffman table and are ready to decode plane */ /* convert bits so they may be used by standard bitreader */ s->dsp.bswap_buf((uint32_t *)s->tmpbuf, (const uint32_t *)src, size >> 2); init_get_bits(&gb, s->tmpbuf, size * 8); - for(j = 0; j < h; j++){ - for(i = 0; i < w*step; i += step){ + for (j = 0; j < h; j++) { + for (i = 0; i < w*step; i += step) { dst[i] = get_vlc2(&gb, vlc.table, 9, 3); /* lines are stored as deltas between previous lines * and we need to add 0x80 to the first lines of chroma planes */ - if(j) dst[i] += dst[i - stride]; - else if(Uoff) dst[i] += 0x80; + if (j) + dst[i] += dst[i - stride]; + else if (Uoff) + dst[i] += 0x80; if (get_bits_left(&gb) < 0) { ff_free_vlc(&vlc); return AVERROR_INVALIDDATA; @@ -128,25 +131,24 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; FrapsContext * const s = avctx->priv_data; - AVFrame *frame = data; - AVFrame * const f = &s->frame; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + AVFrame *frame = data; + AVFrame * const f = &s->frame; uint32_t header; unsigned int version,header_size; unsigned int x, y; const uint32_t *buf32; uint32_t *luma1,*luma2,*cb,*cr; uint32_t offs[4]; - int i, j, is_chroma; + int i, j, ret, is_chroma; const int planes = 3; uint8_t *out; enum AVPixelFormat pix_fmt; - int ret; - header = AV_RL32(buf); - version = header & 0xff; + header = AV_RL32(buf); + version = header & 0xff; header_size = (header & (1<<30))? 8 : 4; /* bit 30 means pad to 8 bytes */ if (version > 5) { @@ -159,7 +161,7 @@ static int decode_frame(AVCodecContext *avctx, buf += header_size; if (version < 2) { - unsigned needed_size = avctx->width*avctx->height*3; + unsigned needed_size = avctx->width * avctx->height * 3; if (version == 0) needed_size /= 2; needed_size += header_size; /* bit 31 means same as previous pic */ @@ -183,15 +185,15 @@ static int decode_frame(AVCodecContext *avctx, av_log(avctx, AV_LOG_ERROR, "Fraps: error in data stream\n"); return AVERROR_INVALIDDATA; } - for(i = 0; i < planes; i++) { + for (i = 0; i < planes; i++) { offs[i] = AV_RL32(buf + 4 + i * 4); - if(offs[i] >= buf_size - header_size || (i && offs[i] <= offs[i - 1] + 1024)) { + if (offs[i] >= buf_size - header_size || (i && offs[i] <= offs[i - 1] + 1024)) { av_log(avctx, AV_LOG_ERROR, "Fraps: plane %i offset is out of bounds\n", i); return AVERROR_INVALIDDATA; } } offs[planes] = buf_size - header_size; - for(i = 0; i < planes; i++) { + for (i = 0; i < planes; i++) { av_fast_padded_malloc(&s->tmpbuf, &s->tmpbuf_size, offs[i + 1] - offs[i] - 1024); if (!s->tmpbuf) return AVERROR(ENOMEM); @@ -216,23 +218,23 @@ static int decode_frame(AVCodecContext *avctx, return ret; } - switch(version) { + switch (version) { case 0: default: /* Fraps v0 is a reordered YUV420 */ - if ( (avctx->width % 8) != 0 || (avctx->height % 2) != 0 ) { + if (((avctx->width % 8) != 0) || ((avctx->height % 2) != 0)) { av_log(avctx, AV_LOG_ERROR, "Invalid frame size %dx%d\n", avctx->width, avctx->height); return AVERROR_INVALIDDATA; } - buf32=(const uint32_t*)buf; - for(y=0; yheight/2; y++){ - luma1=(uint32_t*)&f->data[0][ y*2*f->linesize[0] ]; - luma2=(uint32_t*)&f->data[0][ (y*2+1)*f->linesize[0] ]; - cr=(uint32_t*)&f->data[1][ y*f->linesize[1] ]; - cb=(uint32_t*)&f->data[2][ y*f->linesize[2] ]; - for(x=0; xwidth; x+=8){ + buf32 = (const uint32_t*)buf; + for (y = 0; y < avctx->height / 2; y++) { + luma1 = (uint32_t*)&f->data[0][ y * 2 * f->linesize[0] ]; + luma2 = (uint32_t*)&f->data[0][ (y * 2 + 1) * f->linesize[0] ]; + cr = (uint32_t*)&f->data[1][ y * f->linesize[1] ]; + cb = (uint32_t*)&f->data[2][ y * f->linesize[2] ]; + for (x = 0; x < avctx->width; x += 8) { *luma1++ = *buf32++; *luma1++ = *buf32++; *luma2++ = *buf32++; @@ -245,10 +247,10 @@ static int decode_frame(AVCodecContext *avctx, case 1: /* Fraps v1 is an upside-down BGR24 */ - for(y=0; yheight; y++) - memcpy(&f->data[0][ (avctx->height - y -1) * f->linesize[0]], - &buf[y*avctx->width*3], - 3*avctx->width); + for (y = 0; yheight; y++) + memcpy(&f->data[0][(avctx->height - y - 1) * f->linesize[0]], + &buf[y * avctx->width * 3], + 3 * avctx->width); break; case 2: @@ -257,28 +259,32 @@ static int decode_frame(AVCodecContext *avctx, * Fraps v2 is Huffman-coded YUV420 planes * Fraps v4 is virtually the same */ - for(i = 0; i < planes; i++){ + for (i = 0; i < planes; i++) { is_chroma = !!i; - if(fraps2_decode_plane(s, f->data[i], f->linesize[i], avctx->width >> is_chroma, - avctx->height >> is_chroma, buf + offs[i], offs[i + 1] - offs[i], is_chroma, 1) < 0) { + if ((ret = fraps2_decode_plane(s, f->data[i], f->linesize[i], + avctx->width >> is_chroma, + avctx->height >> is_chroma, + buf + offs[i], offs[i + 1] - offs[i], + is_chroma, 1)) < 0) { av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i); - return AVERROR_INVALIDDATA; + return ret; } } break; case 3: case 5: /* Virtually the same as version 4, but is for RGB24 */ - for(i = 0; i < planes; i++){ - if(fraps2_decode_plane(s, f->data[0] + i + (f->linesize[0] * (avctx->height - 1)), -f->linesize[0], - avctx->width, avctx->height, buf + offs[i], offs[i + 1] - offs[i], 0, 3) < 0) { + for (i = 0; i < planes; i++) { + if ((ret = fraps2_decode_plane(s, f->data[0] + i + (f->linesize[0] * (avctx->height - 1)), + -f->linesize[0], avctx->width, avctx->height, + buf + offs[i], offs[i + 1] - offs[i], 0, 3)) < 0) { av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i); - return AVERROR_INVALIDDATA; + return ret; } } out = f->data[0]; // convert pseudo-YUV into real RGB - for(j = 0; j < avctx->height; j++){ + for (j = 0; j < avctx->height; j++) { uint8_t *line_end = out + 3*avctx->width; while (out < line_end) { out[0] += out[1]; diff --git a/mythtv/external/FFmpeg/libavcodec/g722.h b/mythtv/external/FFmpeg/libavcodec/g722.h index bab1da48cc3..71d03fc5fa8 100644 --- a/mythtv/external/FFmpeg/libavcodec/g722.h +++ b/mythtv/external/FFmpeg/libavcodec/g722.h @@ -32,7 +32,6 @@ typedef struct G722Context { const AVClass *class; - AVFrame frame; int bits_per_codeword; int16_t prev_samples[PREV_SAMPLES_BUF_SIZE]; ///< memory of past decoded samples int prev_samples_pos; ///< the number of values in prev_samples diff --git a/mythtv/external/FFmpeg/libavcodec/g722dec.c b/mythtv/external/FFmpeg/libavcodec/g722dec.c index 965c7907447..b9c634b5804 100644 --- a/mythtv/external/FFmpeg/libavcodec/g722dec.c +++ b/mythtv/external/FFmpeg/libavcodec/g722dec.c @@ -67,9 +67,6 @@ static av_cold int g722_decode_init(AVCodecContext * avctx) c->band[1].scale_factor = 2; c->prev_samples_pos = 22; - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - return 0; } @@ -88,6 +85,7 @@ static int g722_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { G722Context *c = avctx->priv_data; + AVFrame *frame = data; int16_t *out_buf; int j, ret; const int skip = 8 - c->bits_per_codeword; @@ -95,12 +93,12 @@ static int g722_decode_frame(AVCodecContext *avctx, void *data, GetBitContext gb; /* get output buffer */ - c->frame.nb_samples = avpkt->size * 2; - if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = avpkt->size * 2; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - out_buf = (int16_t *)c->frame.data[0]; + out_buf = (int16_t *)frame->data[0]; init_get_bits(&gb, avpkt->data, avpkt->size * 8); @@ -135,8 +133,7 @@ static int g722_decode_frame(AVCodecContext *avctx, void *data, } } - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return avpkt->size; } diff --git a/mythtv/external/FFmpeg/libavcodec/g722enc.c b/mythtv/external/FFmpeg/libavcodec/g722enc.c index 39f83dcba4a..3c470540f8c 100644 --- a/mythtv/external/FFmpeg/libavcodec/g722enc.c +++ b/mythtv/external/FFmpeg/libavcodec/g722enc.c @@ -368,7 +368,7 @@ static int g722_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int nb_samples, out_size, ret; out_size = (frame->nb_samples + 1) / 2; - if ((ret = ff_alloc_packet2(avctx, avpkt, out_size))) + if ((ret = ff_alloc_packet2(avctx, avpkt, out_size)) < 0) return ret; nb_samples = frame->nb_samples - (frame->nb_samples & 1); diff --git a/mythtv/external/FFmpeg/libavcodec/g723_1.c b/mythtv/external/FFmpeg/libavcodec/g723_1.c index c2e86d96d36..d2cde8a864d 100644 --- a/mythtv/external/FFmpeg/libavcodec/g723_1.c +++ b/mythtv/external/FFmpeg/libavcodec/g723_1.c @@ -42,7 +42,6 @@ typedef struct g723_1_context { AVClass *class; - AVFrame frame; G723_1_Subframe subframe[4]; enum FrameType cur_frame_type; @@ -93,9 +92,6 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx) avctx->channels = 1; p->pf_gain = 1 << 12; - avcodec_get_frame_defaults(&p->frame); - avctx->coded_frame = &p->frame; - memcpy(p->prev_lsp, dc_lsp, LPC_ORDER * sizeof(*p->prev_lsp)); memcpy(p->sid_lsp, dc_lsp, LPC_ORDER * sizeof(*p->sid_lsp)); @@ -1158,6 +1154,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { G723_1_Context *p = avctx->priv_data; + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int dec_mode = buf[0] & 3; @@ -1187,13 +1184,13 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data, p->cur_frame_type = UNTRANSMITTED_FRAME; } - p->frame.nb_samples = FRAME_LEN; - if ((ret = ff_get_buffer(avctx, &p->frame)) < 0) { + frame->nb_samples = FRAME_LEN; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - out = (int16_t *)p->frame.data[0]; + out = (int16_t *)frame->data[0]; if (p->cur_frame_type == ACTIVE_FRAME) { if (!bad_frame) @@ -1264,7 +1261,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data, (FRAME_LEN + PITCH_MAX) * sizeof(*p->excitation)); memset(p->prev_excitation, 0, PITCH_MAX * sizeof(*p->excitation)); - memset(p->frame.data[0], 0, + memset(frame->data[0], 0, (FRAME_LEN + LPC_ORDER) * sizeof(int16_t)); } else { int16_t *buf = p->audio + LPC_ORDER; @@ -1313,8 +1310,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data, out[i] = av_clip_int16(p->audio[LPC_ORDER + i] << 1); } - *got_frame_ptr = 1; - *(AVFrame *)data = p->frame; + *got_frame_ptr = 1; return frame_size[dec_mode]; } @@ -2462,7 +2458,7 @@ static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, offset += LPC_ORDER; } - if ((ret = ff_alloc_packet2(avctx, avpkt, 24))) + if ((ret = ff_alloc_packet2(avctx, avpkt, 24)) < 0) return ret; *got_packet_ptr = 1; diff --git a/mythtv/external/FFmpeg/libavcodec/g726.c b/mythtv/external/FFmpeg/libavcodec/g726.c index ba4f01ba93d..995d40a6c71 100644 --- a/mythtv/external/FFmpeg/libavcodec/g726.c +++ b/mythtv/external/FFmpeg/libavcodec/g726.c @@ -77,7 +77,6 @@ typedef struct G726Tables { typedef struct G726Context { AVClass *class; - AVFrame frame; G726Tables tbls; /**< static tables needed for computation */ Float11 sr[2]; /**< prev. reconstructed samples */ @@ -363,7 +362,7 @@ static int g726_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int i, ret, out_size; out_size = (frame->nb_samples * c->code_size + 7) / 8; - if ((ret = ff_alloc_packet2(avctx, avpkt, out_size))) + if ((ret = ff_alloc_packet2(avctx, avpkt, out_size)) < 0) return ret; init_put_bits(&pb, avpkt->data, avpkt->size); @@ -432,15 +431,13 @@ static av_cold int g726_decode_init(AVCodecContext *avctx) avctx->sample_fmt = AV_SAMPLE_FMT_S16; - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - return 0; } static int g726_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; G726Context *c = avctx->priv_data; @@ -451,12 +448,12 @@ static int g726_decode_frame(AVCodecContext *avctx, void *data, out_samples = buf_size * 8 / c->code_size; /* get output buffer */ - c->frame.nb_samples = out_samples; - if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = out_samples; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (int16_t *)c->frame.data[0]; + samples = (int16_t *)frame->data[0]; init_get_bits(&gb, buf, buf_size * 8); @@ -466,8 +463,7 @@ static int g726_decode_frame(AVCodecContext *avctx, void *data, if (get_bits_left(&gb) > 0) av_log(avctx, AV_LOG_ERROR, "Frame invalidly split, missing parser?\n"); - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return buf_size; } diff --git a/mythtv/external/FFmpeg/libavcodec/get_bits.h b/mythtv/external/FFmpeg/libavcodec/get_bits.h index 1d24bdf3d7c..a4d899c4bec 100644 --- a/mythtv/external/FFmpeg/libavcodec/get_bits.h +++ b/mythtv/external/FFmpeg/libavcodec/get_bits.h @@ -27,6 +27,7 @@ #define AVCODEC_GET_BITS_H #include + #include "libavutil/common.h" #include "libavutil/intreadwrite.h" #include "libavutil/log.h" @@ -72,46 +73,48 @@ typedef struct RL_VLC_ELEM { } RL_VLC_ELEM; /* Bitstream reader API docs: -name - arbitrary name which is used as prefix for the internal variables - -gb - getbitcontext - -OPEN_READER(name, gb) - load gb into local variables - -CLOSE_READER(name, gb) - store local vars in gb - -UPDATE_CACHE(name, gb) - refill the internal cache from the bitstream - after this call at least MIN_CACHE_BITS will be available, - -GET_CACHE(name, gb) - will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit) - -SHOW_UBITS(name, gb, num) - will return the next num bits - -SHOW_SBITS(name, gb, num) - will return the next num bits and do sign extension - -SKIP_BITS(name, gb, num) - will skip over the next num bits - note, this is equivalent to SKIP_CACHE; SKIP_COUNTER - -SKIP_CACHE(name, gb, num) - will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER) - -SKIP_COUNTER(name, gb, num) - will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS) - -LAST_SKIP_BITS(name, gb, num) - like SKIP_BITS, to be used if next call is UPDATE_CACHE or CLOSE_READER - -for examples see get_bits, show_bits, skip_bits, get_vlc -*/ + * name + * arbitrary name which is used as prefix for the internal variables + * + * gb + * getbitcontext + * + * OPEN_READER(name, gb) + * load gb into local variables + * + * CLOSE_READER(name, gb) + * store local vars in gb + * + * UPDATE_CACHE(name, gb) + * Refill the internal cache from the bitstream. + * After this call at least MIN_CACHE_BITS will be available. + * + * GET_CACHE(name, gb) + * Will output the contents of the internal cache, + * next bit is MSB of 32 or 64 bit (FIXME 64bit). + * + * SHOW_UBITS(name, gb, num) + * Will return the next num bits. + * + * SHOW_SBITS(name, gb, num) + * Will return the next num bits and do sign extension. + * + * SKIP_BITS(name, gb, num) + * Will skip over the next num bits. + * Note, this is equivalent to SKIP_CACHE; SKIP_COUNTER. + * + * SKIP_CACHE(name, gb, num) + * Will remove the next num bits from the cache (note SKIP_COUNTER + * MUST be called before UPDATE_CACHE / CLOSE_READER). + * + * SKIP_COUNTER(name, gb, num) + * Will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS). + * + * LAST_SKIP_BITS(name, gb, num) + * Like SKIP_BITS, to be used if next call is UPDATE_CACHE or CLOSE_READER. + * + * For examples see get_bits, show_bits, skip_bits, get_vlc. + */ #ifdef LONG_BITSTREAM_READER # define MIN_CACHE_BITS 32 @@ -121,19 +124,17 @@ for examples see get_bits, show_bits, skip_bits, get_vlc #if UNCHECKED_BITSTREAM_READER #define OPEN_READER(name, gb) \ - unsigned int name##_index = (gb)->index; \ - av_unused unsigned int name##_cache + unsigned int name ## _index = (gb)->index; \ + unsigned int av_unused name ## _cache #define HAVE_BITS_REMAINING(name, gb) 1 #else #define OPEN_READER(name, gb) \ - unsigned int name##_index = (gb)->index; \ - unsigned int av_unused name##_cache = 0; \ - unsigned int av_unused name##_size_plus8 = \ - (gb)->size_in_bits_plus8 + unsigned int name ## _index = (gb)->index; \ + unsigned int av_unused name ## _cache = 0; \ + unsigned int av_unused name ## _size_plus8 = (gb)->size_in_bits_plus8 -#define HAVE_BITS_REMAINING(name, gb) \ - name##_index < name##_size_plus8 +#define HAVE_BITS_REMAINING(name, gb) name ## _index < name ## _size_plus8 #endif // Added the void use of the cache to defeat compiler warnings with newer gcc @@ -145,37 +146,38 @@ for examples see get_bits, show_bits, skip_bits, get_vlc #ifdef BITSTREAM_READER_LE # ifdef LONG_BITSTREAM_READER -# define UPDATE_CACHE(name, gb) name##_cache = \ - AV_RL64((gb)->buffer + (name##_index >> 3)) >> (name##_index & 7) +# define UPDATE_CACHE(name, gb) name ## _cache = \ + AV_RL64((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7) # else -# define UPDATE_CACHE(name, gb) name##_cache = \ - AV_RL32((gb)->buffer + (name##_index >> 3)) >> (name##_index & 7) +# define UPDATE_CACHE(name, gb) name ## _cache = \ + AV_RL32((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7) # endif -# define SKIP_CACHE(name, gb, num) name##_cache >>= (num) +# define SKIP_CACHE(name, gb, num) name ## _cache >>= (num) #else # ifdef LONG_BITSTREAM_READER -# define UPDATE_CACHE(name, gb) name##_cache = \ - AV_RB64((gb)->buffer + (name##_index >> 3)) >> (32 - (name##_index & 7)) +# define UPDATE_CACHE(name, gb) name ## _cache = \ + AV_RB64((gb)->buffer + (name ## _index >> 3)) >> (32 - (name ## _index & 7)) # else -# define UPDATE_CACHE(name, gb) name##_cache = \ - AV_RB32((gb)->buffer + (name##_index >> 3)) << (name##_index & 7) +# define UPDATE_CACHE(name, gb) name ## _cache = \ + AV_RB32((gb)->buffer + (name ## _index >> 3)) << (name ## _index & 7) # endif -# define SKIP_CACHE(name, gb, num) name##_cache <<= (num) +# define SKIP_CACHE(name, gb, num) name ## _cache <<= (num) #endif #if UNCHECKED_BITSTREAM_READER -# define SKIP_COUNTER(name, gb, num) name##_index += (num) +# define SKIP_COUNTER(name, gb, num) name ## _index += (num) #else # define SKIP_COUNTER(name, gb, num) \ - name##_index = FFMIN(name##_size_plus8, name##_index + (num)) + name ## _index = FFMIN(name ## _size_plus8, name ## _index + (num)) #endif -#define SKIP_BITS(name, gb, num) do { \ +#define SKIP_BITS(name, gb, num) \ + do { \ SKIP_CACHE(name, gb, num); \ SKIP_COUNTER(name, gb, num); \ } while (0) @@ -183,21 +185,22 @@ for examples see get_bits, show_bits, skip_bits, get_vlc #define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) #ifdef BITSTREAM_READER_LE -# define SHOW_UBITS(name, gb, num) zero_extend(name##_cache, num) -# define SHOW_SBITS(name, gb, num) sign_extend(name##_cache, num) +# define SHOW_UBITS(name, gb, num) zero_extend(name ## _cache, num) +# define SHOW_SBITS(name, gb, num) sign_extend(name ## _cache, num) #else -# define SHOW_UBITS(name, gb, num) NEG_USR32(name##_cache, num) -# define SHOW_SBITS(name, gb, num) NEG_SSR32(name##_cache, num) +# define SHOW_UBITS(name, gb, num) NEG_USR32(name ## _cache, num) +# define SHOW_SBITS(name, gb, num) NEG_SSR32(name ## _cache, num) #endif -#define GET_CACHE(name, gb) ((uint32_t)name##_cache) +#define GET_CACHE(name, gb) ((uint32_t) name ## _cache) static inline int get_bits_count(const GetBitContext *s) { return s->index; } -static inline void skip_bits_long(GetBitContext *s, int n){ +static inline void skip_bits_long(GetBitContext *s, int n) +{ #if UNCHECKED_BITSTREAM_READER s->index += n; #else @@ -217,7 +220,7 @@ static inline int get_xbits(GetBitContext *s, int n) OPEN_READER(re, s); UPDATE_CACHE(re, s); cache = GET_CACHE(re, s); - sign = ~cache >> 31; + sign = ~cache >> 31; LAST_SKIP_BITS(re, s, n); CLOSE_READER(re, s); return (NEG_USR32(sign ^ cache, n) ^ sign) - sign; @@ -274,10 +277,10 @@ static inline void skip_bits(GetBitContext *s, int n) static inline unsigned int get_bits1(GetBitContext *s) { unsigned int index = s->index; - uint8_t result = s->buffer[index>>3]; + uint8_t result = s->buffer[index >> 3]; #ifdef BITSTREAM_READER_LE result >>= index & 7; - result &= 1; + result &= 1; #else result <<= index & 7; result >>= 8 - 1; @@ -308,15 +311,15 @@ static inline unsigned int get_bits_long(GetBitContext *s, int n) { if (!n) { return 0; - } else if (n <= MIN_CACHE_BITS) + } else if (n <= MIN_CACHE_BITS) { return get_bits(s, n); - else { + } else { #ifdef BITSTREAM_READER_LE unsigned ret = get_bits(s, 16); - return ret | (get_bits(s, n-16) << 16); + return ret | (get_bits(s, n - 16) << 16); #else - unsigned ret = get_bits(s, 16) << (n-16); - return ret | get_bits(s, n-16); + unsigned ret = get_bits(s, 16) << (n - 16); + return ret | get_bits(s, n - 16); #endif } } @@ -331,9 +334,9 @@ static inline uint64_t get_bits64(GetBitContext *s, int n) } else { #ifdef BITSTREAM_READER_LE uint64_t ret = get_bits_long(s, 32); - return ret | (uint64_t)get_bits_long(s, n - 32) << 32; + return ret | (uint64_t) get_bits_long(s, n - 32) << 32; #else - uint64_t ret = (uint64_t)get_bits_long(s, n - 32) << 32; + uint64_t ret = (uint64_t) get_bits_long(s, n - 32) << 32; return ret | get_bits_long(s, 32); #endif } @@ -352,9 +355,9 @@ static inline int get_sbits_long(GetBitContext *s, int n) */ static inline unsigned int show_bits_long(GetBitContext *s, int n) { - if (n <= MIN_CACHE_BITS) + if (n <= MIN_CACHE_BITS) { return show_bits(s, n); - else { + } else { GetBitContext gb = *s; return get_bits_long(&gb, n); } @@ -385,17 +388,18 @@ static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer, if (bit_size >= INT_MAX - 7 || bit_size < 0 || !buffer) { buffer_size = bit_size = 0; - buffer = NULL; - ret = AVERROR_INVALIDDATA; + buffer = NULL; + ret = AVERROR_INVALIDDATA; } buffer_size = (bit_size + 7) >> 3; - s->buffer = buffer; - s->size_in_bits = bit_size; + s->buffer = buffer; + s->size_in_bits = bit_size; s->size_in_bits_plus8 = bit_size + 8; - s->buffer_end = buffer + buffer_size; - s->index = 0; + s->buffer_end = buffer + buffer_size; + s->index = 0; + return ret; } @@ -415,37 +419,40 @@ static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer, return init_get_bits(s, buffer, byte_size * 8); } -static inline void align_get_bits(GetBitContext *s) +static inline const uint8_t *align_get_bits(GetBitContext *s) { int n = -get_bits_count(s) & 7; - if (n) skip_bits(s, n); + if (n) + skip_bits(s, n); + return s->buffer + (s->index >> 3); } #define init_vlc(vlc, nb_bits, nb_codes, \ bits, bits_wrap, bits_size, \ codes, codes_wrap, codes_size, \ flags) \ - ff_init_vlc_sparse(vlc, nb_bits, nb_codes, \ - bits, bits_wrap, bits_size, \ - codes, codes_wrap, codes_size, \ - NULL, 0, 0, flags) + ff_init_vlc_sparse(vlc, nb_bits, nb_codes, \ + bits, bits_wrap, bits_size, \ + codes, codes_wrap, codes_size, \ + NULL, 0, 0, flags) int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, - const void *bits, int bits_wrap, int bits_size, - const void *codes, int codes_wrap, int codes_size, - const void *symbols, int symbols_wrap, int symbols_size, - int flags); -#define INIT_VLC_LE 2 -#define INIT_VLC_USE_NEW_STATIC 4 + const void *bits, int bits_wrap, int bits_size, + const void *codes, int codes_wrap, int codes_size, + const void *symbols, int symbols_wrap, int symbols_size, + int flags); void ff_free_vlc(VLC *vlc); -#define INIT_VLC_STATIC(vlc, bits, a,b,c,d,e,f,g, static_size) do { \ - static VLC_TYPE table[static_size][2]; \ - (vlc)->table = table; \ - (vlc)->table_allocated = static_size; \ - init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC); \ - } while (0) +#define INIT_VLC_LE 2 +#define INIT_VLC_USE_NEW_STATIC 4 +#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size) \ + do { \ + static VLC_TYPE table[static_size][2]; \ + (vlc)->table = table; \ + (vlc)->table_allocated = static_size; \ + init_vlc(vlc, bits, a, b, c, d, e, f, g, INIT_VLC_USE_NEW_STATIC); \ + } while (0) /** * If the vlc code is invalid and max_depth=1, then no bits will be removed. @@ -484,32 +491,32 @@ void ff_free_vlc(VLC *vlc); SKIP_BITS(name, gb, n); \ } while (0) -#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update) \ - do { \ - int n, nb_bits; \ - unsigned int index; \ - \ - index = SHOW_UBITS(name, gb, bits); \ - level = table[index].level; \ - n = table[index].len; \ - \ - if (max_depth > 1 && n < 0) { \ - SKIP_BITS(name, gb, bits); \ - if (need_update) { \ - UPDATE_CACHE(name, gb); \ - } \ - \ - nb_bits = -n; \ - \ - index = SHOW_UBITS(name, gb, nb_bits) + level; \ - level = table[index].level; \ - n = table[index].len; \ - } \ - run = table[index].run; \ - SKIP_BITS(name, gb, n); \ +#define GET_RL_VLC(level, run, name, gb, table, bits, \ + max_depth, need_update) \ + do { \ + int n, nb_bits; \ + unsigned int index; \ + \ + index = SHOW_UBITS(name, gb, bits); \ + level = table[index].level; \ + n = table[index].len; \ + \ + if (max_depth > 1 && n < 0) { \ + SKIP_BITS(name, gb, bits); \ + if (need_update) { \ + UPDATE_CACHE(name, gb); \ + } \ + \ + nb_bits = -n; \ + \ + index = SHOW_UBITS(name, gb, nb_bits) + level; \ + level = table[index].level; \ + n = table[index].len; \ + } \ + run = table[index].run; \ + SKIP_BITS(name, gb, n); \ } while (0) - /** * Parse a vlc code. * @param bits is the number of bits which will be read at once, must be @@ -529,6 +536,7 @@ static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], GET_VLC(code, re, s, table, bits, max_depth); CLOSE_READER(re, s); + return code; } @@ -562,9 +570,8 @@ static inline void print_bin(int bits, int n) { int i; - for (i = n-1; i >= 0; i--) { - av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1); - } + for (i = n - 1; i >= 0; i--) + av_log(NULL, AV_LOG_DEBUG, "%d", (bits >> i) & 1); for (i = n; i < 24; i++) av_log(NULL, AV_LOG_DEBUG, " "); } @@ -576,9 +583,11 @@ static inline int get_bits_trace(GetBitContext *s, int n, const char *file, print_bin(r, n); av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n", - r, n, r, get_bits_count(s)-n, file, func, line); + r, n, r, get_bits_count(s) - n, file, func, line); + return r; } + static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, const char *file, const char *func, int line) @@ -587,14 +596,16 @@ static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int pos = get_bits_count(s); int r = get_vlc2(s, table, bits, max_depth); int len = get_bits_count(s) - pos; - int bits2 = show >> (24-len); + int bits2 = show >> (24 - len); print_bin(bits2, len); av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); + return r; } + static inline int get_xbits_trace(GetBitContext *s, int n, const char *file, const char *func, int line) { @@ -603,20 +614,22 @@ static inline int get_xbits_trace(GetBitContext *s, int n, const char *file, print_bin(show, n); av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n", - show, n, r, get_bits_count(s)-n, file, func, line); + show, n, r, get_bits_count(s) - n, file, func, line); + return r; } -#define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) -#define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__) +#define get_bits(s, n) get_bits_trace(s , n, __FILE__, __PRETTY_FUNCTION__, __LINE__) +#define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) -#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) -#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) + +#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) +#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define tprintf(p, ...) av_log(p, AV_LOG_DEBUG, __VA_ARGS__) #else //TRACE -#define tprintf(p, ...) {} +#define tprintf(p, ...) { } #endif #endif /* AVCODEC_GET_BITS_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/gif.c b/mythtv/external/FFmpeg/libavcodec/gif.c index 1ae46618a5a..de3e576b3d6 100644 --- a/mythtv/external/FFmpeg/libavcodec/gif.c +++ b/mythtv/external/FFmpeg/libavcodec/gif.c @@ -25,8 +25,6 @@ * First version by Francois Revol revol@free.fr * * Features and limitations: - * - currently no compression is performed, - * in fact the size of the data is 9/8 the size of the image in 8bpp * - uses only a global standard palette * - tested with IE 5.0, Opera for BeOS, NetPositive (BeOS), and Mozilla (BeOS). * @@ -34,11 +32,6 @@ * http://www.goice.co.jp/member/mo/formats/gif.html * http://astronomy.swin.edu.au/pbourke/dataformats/gif/ * http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/GIF89a.txt - * - * this url claims to have an LZW algorithm not covered by Unisys patent: - * http://www.msg.net/utility/whirlgif/gifencod.html - * could help reduce the size of the files _a lot_... - * some sites mentions an RLE type compression also. */ #include "avcodec.h" diff --git a/mythtv/external/FFmpeg/libavcodec/gifdec.c b/mythtv/external/FFmpeg/libavcodec/gifdec.c index a916dfe8e71..727887ab44c 100644 --- a/mythtv/external/FFmpeg/libavcodec/gifdec.c +++ b/mythtv/external/FFmpeg/libavcodec/gifdec.c @@ -75,6 +75,7 @@ typedef struct GifState { AVCodecContext *avctx; int keyframe; + int keyframe_ok; int trans_color; /**< color value that is used instead of transparent color */ } GifState; @@ -115,7 +116,7 @@ static void gif_copy_img_rect(const uint32_t *src, uint32_t *dst, int linesize, int l, int t, int w, int h) { const int y_start = t * linesize; - const uint32_t *src_px, *src_pr, + const uint32_t *src_px, *src_py = src + y_start, *dst_py = dst + y_start; const uint32_t *src_pb = src_py + h * linesize; @@ -124,10 +125,8 @@ static void gif_copy_img_rect(const uint32_t *src, uint32_t *dst, for (; src_py < src_pb; src_py += linesize, dst_py += linesize) { src_px = src_py + l; dst_px = (uint32_t *)dst_py + l; - src_pr = src_px + w; - for (; src_px < src_pr; src_px++, dst_px++) - *dst_px = *src_px; + memcpy(dst_px, src_px, w * sizeof(uint32_t)); } } @@ -186,6 +185,8 @@ static int gif_read_image(GifState *s) if (left + width > s->screen_width || top + height > s->screen_height) return AVERROR_INVALIDDATA; + if (width <= 0 || height <= 0) + return AVERROR_INVALIDDATA; /* process disposal method */ if (s->gce_prev_disposal == GCE_DISPOSAL_BACKGROUND) { @@ -337,7 +338,7 @@ static int gif_read_extension(GifState *s) /* NOTE: many extension blocks can come after */ discard_ext: - while (ext_len != 0) { + while (ext_len) { /* There must be at least ext_len bytes and 1 for next block size byte. */ if (bytestream2_get_bytes_left(&s->gb) < ext_len + 1) return AVERROR_INVALIDDATA; @@ -361,23 +362,14 @@ static int gif_read_header1(GifState *s) /* read gif signature */ bytestream2_get_bufferu(&s->gb, sig, 6); - if (memcmp(sig, gif87a_sig, 6) != 0 && - memcmp(sig, gif89a_sig, 6) != 0) + if (memcmp(sig, gif87a_sig, 6) && + memcmp(sig, gif89a_sig, 6)) return AVERROR_INVALIDDATA; /* read screen header */ s->transparent_color_index = -1; s->screen_width = bytestream2_get_le16u(&s->gb); s->screen_height = bytestream2_get_le16u(&s->gb); - if( (unsigned)s->screen_width > 32767 - || (unsigned)s->screen_height > 32767){ - av_log(s->avctx, AV_LOG_ERROR, "picture size too large\n"); - return AVERROR_INVALIDDATA; - } - - av_fast_malloc(&s->idx_line, &s->idx_line_size, s->screen_width); - if (!s->idx_line) - return AVERROR(ENOMEM); v = bytestream2_get_byteu(&s->gb); s->color_resolution = ((v & 0x70) >> 4) + 1; @@ -408,12 +400,11 @@ static int gif_read_header1(GifState *s) return 0; } -static int gif_parse_next_image(GifState *s, int *got_picture) +static int gif_parse_next_image(GifState *s) { - int ret; - *got_picture = 1; while (bytestream2_get_bytes_left(&s->gb)) { int code = bytestream2_get_byte(&s->gb); + int ret; av_dlog(s->avctx, "code=%02x '%c'\n", code, code); @@ -426,8 +417,7 @@ static int gif_parse_next_image(GifState *s, int *got_picture) break; case GIF_TRAILER: /* end of image */ - *got_picture = 0; - return 0; + return AVERROR_EOF; default: /* erroneous block label */ return AVERROR_INVALIDDATA; @@ -461,7 +451,7 @@ static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, A s->picture.pts = avpkt->pts; s->picture.pkt_pts = avpkt->pts; s->picture.pkt_dts = avpkt->dts; - s->picture.pkt_duration = avpkt->duration; + av_frame_set_pkt_duration(&s->picture, avpkt->duration); if (avpkt->size >= 6) { s->keyframe = memcmp(avpkt->data, gif87a_sig, 6) == 0 || @@ -471,6 +461,8 @@ static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, A } if (s->keyframe) { + s->keyframe_ok = 0; + s->gce_prev_disposal = GCE_DISPOSAL_NONE; if ((ret = gif_read_header1(s)) < 0) return ret; @@ -486,9 +478,19 @@ static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, A return ret; } + av_fast_malloc(&s->idx_line, &s->idx_line_size, s->screen_width); + if (!s->idx_line) + return AVERROR(ENOMEM); + s->picture.pict_type = AV_PICTURE_TYPE_I; s->picture.key_frame = 1; + s->keyframe_ok = 1; } else { + if (!s->keyframe_ok) { + av_log(avctx, AV_LOG_ERROR, "cannot decode frame without keyframe\n"); + return AVERROR_INVALIDDATA; + } + if ((ret = avctx->reget_buffer(avctx, &s->picture)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return ret; @@ -498,11 +500,12 @@ static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, A s->picture.key_frame = 0; } - ret = gif_parse_next_image(s, got_frame); + ret = gif_parse_next_image(s); if (ret < 0) return ret; - else if (*got_frame) - *picture = s->picture; + + *picture = s->picture; + *got_frame = 1; return avpkt->size; } diff --git a/mythtv/external/FFmpeg/libavcodec/golomb.h b/mythtv/external/FFmpeg/libavcodec/golomb.h index 4eb182c83b2..7a8bcb1e809 100644 --- a/mythtv/external/FFmpeg/libavcodec/golomb.h +++ b/mythtv/external/FFmpeg/libavcodec/golomb.h @@ -66,10 +66,14 @@ static inline int get_ue_golomb(GetBitContext *gb){ return ff_ue_golomb_vlc_code[buf]; }else{ log= 2*av_log2(buf) - 31; - buf>>= log; - buf--; LAST_SKIP_BITS(re, gb, 32 - log); CLOSE_READER(re, gb); + if (CONFIG_FTRAPV && log < 0) { + av_log(0, AV_LOG_ERROR, "Invalid UE golomb code\n"); + return AVERROR_INVALIDDATA; + } + buf>>= log; + buf--; return buf; } @@ -183,7 +187,11 @@ static inline int get_se_golomb(GetBitContext *gb){ return ff_se_golomb_vlc_code[buf]; }else{ - log= 2*av_log2(buf) - 31; + log = av_log2(buf); + LAST_SKIP_BITS(re, gb, 31 - log); + UPDATE_CACHE(re, gb); + buf = GET_CACHE(re, gb); + buf>>= log; LAST_SKIP_BITS(re, gb, 32 - log); diff --git a/mythtv/external/FFmpeg/libavcodec/gsmdec.c b/mythtv/external/FFmpeg/libavcodec/gsmdec.c index 71127c71a12..f20ef9a20ea 100644 --- a/mythtv/external/FFmpeg/libavcodec/gsmdec.c +++ b/mythtv/external/FFmpeg/libavcodec/gsmdec.c @@ -34,8 +34,6 @@ static av_cold int gsm_init(AVCodecContext *avctx) { - GSMContext *s = avctx->priv_data; - avctx->channels = 1; avctx->channel_layout = AV_CH_LAYOUT_MONO; if (!avctx->sample_rate) @@ -52,16 +50,13 @@ static av_cold int gsm_init(AVCodecContext *avctx) avctx->block_align = GSM_MS_BLOCK_SIZE; } - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } static int gsm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { - GSMContext *s = avctx->priv_data; + AVFrame *frame = data; int res; GetBitContext gb; const uint8_t *buf = avpkt->data; @@ -74,12 +69,12 @@ static int gsm_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - s->frame.nb_samples = avctx->frame_size; - if ((res = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = avctx->frame_size; + if ((res = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return res; } - samples = (int16_t *)s->frame.data[0]; + samples = (int16_t *)frame->data[0]; switch (avctx->codec_id) { case AV_CODEC_ID_GSM: @@ -96,8 +91,7 @@ static int gsm_decode_frame(AVCodecContext *avctx, void *data, return res; } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return avctx->block_align; } diff --git a/mythtv/external/FFmpeg/libavcodec/gsmdec_data.h b/mythtv/external/FFmpeg/libavcodec/gsmdec_data.h index 082c65d4b17..fd89ed63eef 100644 --- a/mythtv/external/FFmpeg/libavcodec/gsmdec_data.h +++ b/mythtv/external/FFmpeg/libavcodec/gsmdec_data.h @@ -26,7 +26,6 @@ #include "avcodec.h" typedef struct GSMContext { - AVFrame frame; // Contains first 120 elements from the previous frame // (used by long_term_synth according to the "lag"), // then in the following 160 elements the current diff --git a/mythtv/external/FFmpeg/libavcodec/h261.c b/mythtv/external/FFmpeg/libavcodec/h261.c index 951997d65e7..f89d5c7741b 100644 --- a/mythtv/external/FFmpeg/libavcodec/h261.c +++ b/mythtv/external/FFmpeg/libavcodec/h261.c @@ -25,7 +25,6 @@ * h261codec. */ -#include "dsputil.h" #include "avcodec.h" #include "h261.h" diff --git a/mythtv/external/FFmpeg/libavcodec/h261dec.c b/mythtv/external/FFmpeg/libavcodec/h261dec.c index 7cca7bb82ec..eebfd027371 100644 --- a/mythtv/external/FFmpeg/libavcodec/h261dec.c +++ b/mythtv/external/FFmpeg/libavcodec/h261dec.c @@ -26,7 +26,6 @@ */ #include "libavutil/avassert.h" -#include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" #include "h263.h" @@ -48,7 +47,7 @@ static VLC h261_mtype_vlc; static VLC h261_mv_vlc; static VLC h261_cbp_vlc; -static int h261_decode_block(H261Context * h, DCTELEM * block, int n, int coded); +static int h261_decode_block(H261Context * h, int16_t * block, int n, int coded); static av_cold void h261_decode_init_vlc(H261Context *h){ static int done = 0; @@ -366,7 +365,7 @@ static int h261_decode_mb(H261Context *h){ * Decode a macroblock. * @return <0 if an error occurred */ -static int h261_decode_block(H261Context * h, DCTELEM * block, +static int h261_decode_block(H261Context * h, int16_t * block, int n, int coded) { MpegEncContext * const s = &h->s; @@ -617,7 +616,7 @@ static int h261_decode_frame(AVCodecContext *avctx, if(ff_MPV_frame_start(s, avctx) < 0) return -1; - ff_er_frame_start(s); + ff_mpeg_er_frame_start(s); /* decode each macroblock */ s->mb_x=0; diff --git a/mythtv/external/FFmpeg/libavcodec/h261enc.c b/mythtv/external/FFmpeg/libavcodec/h261enc.c index 29bee5d46eb..c22100cf8c6 100644 --- a/mythtv/external/FFmpeg/libavcodec/h261enc.c +++ b/mythtv/external/FFmpeg/libavcodec/h261enc.c @@ -26,7 +26,6 @@ */ #include "libavutil/avassert.h" -#include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" #include "h263.h" @@ -35,7 +34,7 @@ extern uint8_t ff_h261_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3]; -static void h261_encode_block(H261Context * h, DCTELEM * block, +static void h261_encode_block(H261Context * h, int16_t * block, int n); int ff_h261_get_picture_format(int width, int height){ @@ -144,7 +143,7 @@ static void h261_encode_motion(H261Context * h, int val){ } static inline int get_cbp(MpegEncContext * s, - DCTELEM block[6][64]) + int16_t block[6][64]) { int i, cbp; cbp= 0; @@ -155,7 +154,7 @@ static inline int get_cbp(MpegEncContext * s, return cbp; } void ff_h261_encode_mb(MpegEncContext * s, - DCTELEM block[6][64], + int16_t block[6][64], int motion_x, int motion_y) { H261Context * h = (H261Context *)s; @@ -256,7 +255,7 @@ void ff_h261_encode_init(MpegEncContext *s){ * @param block the 8x8 block * @param n block index (0-3 are luma, 4-5 are chroma) */ -static void h261_encode_block(H261Context * h, DCTELEM * block, int n){ +static void h261_encode_block(H261Context * h, int16_t * block, int n){ MpegEncContext * const s = &h->s; int level, run, i, j, last_index, last_non_zero, sign, slevel, code; RLTable *rl; diff --git a/mythtv/external/FFmpeg/libavcodec/h263.c b/mythtv/external/FFmpeg/libavcodec/h263.c index 5b77106d7db..a7e60eac2c9 100644 --- a/mythtv/external/FFmpeg/libavcodec/h263.c +++ b/mythtv/external/FFmpeg/libavcodec/h263.c @@ -30,7 +30,6 @@ //#define DEBUG #include -#include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" #include "h263.h" @@ -226,7 +225,7 @@ void ff_h263_loop_filter(MpegEncContext * s){ } } -void ff_h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n) +void ff_h263_pred_acdc(MpegEncContext * s, int16_t *block, int n) { int x, y, wrap, a, c, pred_dc, scale, i; int16_t *dc_val, *ac_val, *ac_val1; diff --git a/mythtv/external/FFmpeg/libavcodec/h263.h b/mythtv/external/FFmpeg/libavcodec/h263.h index 34d79a088d4..a95cfb0079a 100644 --- a/mythtv/external/FFmpeg/libavcodec/h263.h +++ b/mythtv/external/FFmpeg/libavcodec/h263.h @@ -64,6 +64,8 @@ extern const uint8_t ff_mba_length[7]; extern uint8_t ff_h263_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; +extern const enum AVPixelFormat ff_h263_hwaccel_pixfmt_list_420[]; + int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code); av_const int ff_h263_aspect_to_info(AVRational aspect); @@ -73,14 +75,14 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVPacket *avpkt); int ff_h263_decode_end(AVCodecContext *avctx); void ff_h263_encode_mb(MpegEncContext *s, - DCTELEM block[6][64], + int16_t block[6][64], int motion_x, int motion_y); void ff_h263_encode_picture_header(MpegEncContext *s, int picture_number); void ff_h263_encode_gob_header(MpegEncContext * s, int mb_line); int16_t *ff_h263_pred_motion(MpegEncContext * s, int block, int dir, int *px, int *py); void ff_h263_encode_init(MpegEncContext *s); -void ff_h263_decode_init_vlc(MpegEncContext *s); +void ff_h263_decode_init_vlc(void); int ff_h263_decode_picture_header(MpegEncContext *s); int ff_h263_decode_gob_header(MpegEncContext *s); void ff_h263_update_motion_val(MpegEncContext * s); @@ -89,7 +91,7 @@ int ff_h263_decode_mba(MpegEncContext *s); void ff_h263_encode_mba(MpegEncContext *s); void ff_init_qscale_tab(MpegEncContext *s); int ff_h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr); -void ff_h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n); +void ff_h263_pred_acdc(MpegEncContext * s, int16_t *block, int n); /** @@ -99,7 +101,7 @@ void ff_h263_show_pict_info(MpegEncContext *s); int ff_intel_h263_decode_picture_header(MpegEncContext *s); int ff_h263_decode_mb(MpegEncContext *s, - DCTELEM block[6][64]); + int16_t block[6][64]); /** * Return the value of the 3bit "source format" syntax element. @@ -144,7 +146,7 @@ static inline void ff_h263_encode_motion_vector(MpegEncContext * s, int x, int y } static inline int get_p_cbp(MpegEncContext * s, - DCTELEM block[6][64], + int16_t block[6][64], int motion_x, int motion_y){ int cbp, i; diff --git a/mythtv/external/FFmpeg/libavcodec/h263dec.c b/mythtv/external/FFmpeg/libavcodec/h263dec.c index 0232aa4c9d7..e231b085484 100644 --- a/mythtv/external/FFmpeg/libavcodec/h263dec.c +++ b/mythtv/external/FFmpeg/libavcodec/h263dec.c @@ -30,7 +30,6 @@ #include "libavutil/cpu.h" #include "internal.h" #include "avcodec.h" -#include "dsputil.h" #include "mpegvideo.h" #include "h263.h" #include "h263_parser.h" @@ -121,7 +120,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) if ((ret = ff_MPV_common_init(s)) < 0) return ret; - ff_h263_decode_init_vlc(s); + ff_h263_decode_init_vlc(); return 0; } @@ -194,7 +193,7 @@ static int decode_slice(MpegEncContext *s){ /* per-row end of slice checks */ if(s->msmpeg4_version){ if(s->resync_mb_y + s->slice_height == s->mb_y){ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); return 0; } @@ -235,24 +234,24 @@ static int decode_slice(MpegEncContext *s){ if(s->loop_filter) ff_h263_loop_filter(s); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask); s->padding_bug_score--; if(++s->mb_x >= s->mb_width){ s->mb_x=0; - ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size); + ff_mpeg_draw_horiz_band(s, s->mb_y*mb_size, mb_size); ff_MPV_report_decode_progress(s); s->mb_y++; } return 0; }else if(ret==SLICE_NOEND){ av_log(s->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x+1, s->mb_y, ER_MB_END&part_mask); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x+1, s->mb_y, ER_MB_END&part_mask); return AVERROR_INVALIDDATA; } av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask); return AVERROR_INVALIDDATA; } @@ -262,7 +261,7 @@ static int decode_slice(MpegEncContext *s){ ff_h263_loop_filter(s); } - ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size); + ff_mpeg_draw_horiz_band(s, s->mb_y*mb_size, mb_size); ff_MPV_report_decode_progress(s); s->mb_x= 0; @@ -331,7 +330,7 @@ static int decode_slice(MpegEncContext *s){ else if(left<0){ av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left); }else - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); return 0; } @@ -340,7 +339,7 @@ static int decode_slice(MpegEncContext *s){ get_bits_left(&s->gb), show_bits(&s->gb, 24), s->padding_bug_score); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask); return AVERROR_INVALIDDATA; } @@ -469,7 +468,7 @@ uint64_t time= rdtsc(); if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){ if(s->stream_codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVIX") || - s->codec_tag == AV_RL32("RMP4") || + s->codec_tag == AV_RL32("RMP4") || s->codec_tag == AV_RL32("ZMP4") || s->codec_tag == AV_RL32("SIPP") ) s->xvid_build= 0; @@ -643,10 +642,7 @@ uint64_t time= rdtsc(); s->next_p_frame_damaged=0; } - if((s->avctx->flags2 & CODEC_FLAG2_FAST) && s->pict_type==AV_PICTURE_TYPE_B){ - s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab; - s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab; - }else if((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){ + if((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){ s->me.qpel_put= s->dsp.put_qpel_pixels_tab; s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab; }else{ @@ -669,7 +665,7 @@ uint64_t time= rdtsc(); return ret; } - ff_er_frame_start(s); + ff_mpeg_er_frame_start(s); //the second part of the wmv2 header contains the MB skip bits which are stored in current_picture->mb_type //which is not available before ff_MPV_frame_start() @@ -693,7 +689,7 @@ uint64_t time= rdtsc(); if(ff_h263_resync(s)<0) break; if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x) - s->error_occurred = 1; + s->er.error_occurred = 1; } if(s->msmpeg4_version<4 && s->h263_pred) @@ -704,7 +700,7 @@ uint64_t time= rdtsc(); if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I) if(!CONFIG_MSMPEG4_DECODER || ff_msmpeg4_decode_ext_header(s, buf_size) < 0){ - s->error_status_table[s->mb_num-1]= ER_MB_ERROR; + s->er.error_status_table[s->mb_num - 1] = ER_MB_ERROR; } av_assert1(s->bitstream_buffer_size==0); @@ -737,7 +733,7 @@ uint64_t time= rdtsc(); } intrax8_decoded: - ff_er_frame_end(s); + ff_er_frame_end(&s->er); if (avctx->hwaccel) { if ((ret = avctx->hwaccel->end_frame(avctx)) < 0) @@ -766,6 +762,17 @@ av_log(avctx, AV_LOG_DEBUG, "%"PRId64"\n", rdtsc()-time); return (ret && (avctx->err_recognition & AV_EF_EXPLODE))?ret:get_consumed_bytes(s, buf_size); } +const enum AVPixelFormat ff_h263_hwaccel_pixfmt_list_420[] = { +#if CONFIG_VAAPI + AV_PIX_FMT_VAAPI_VLD, +#endif +#if CONFIG_VDPAU + AV_PIX_FMT_VDPAU, +#endif + AV_PIX_FMT_YUV420P, + AV_PIX_FMT_NONE +}; + AVCodec ff_h263_decoder = { .name = "h263", .type = AVMEDIA_TYPE_VIDEO, @@ -779,7 +786,7 @@ AVCodec ff_h263_decoder = { .flush = ff_mpeg_flush, .max_lowres = 3, .long_name = NULL_IF_CONFIG_SMALL("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"), - .pix_fmts = ff_hwaccel_pixfmt_list_420, + .pix_fmts = ff_h263_hwaccel_pixfmt_list_420, }; AVCodec ff_h263p_decoder = { @@ -795,5 +802,5 @@ AVCodec ff_h263p_decoder = { .flush = ff_mpeg_flush, .max_lowres = 3, .long_name = NULL_IF_CONFIG_SMALL("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"), - .pix_fmts = ff_hwaccel_pixfmt_list_420, + .pix_fmts = ff_h263_hwaccel_pixfmt_list_420, }; diff --git a/mythtv/external/FFmpeg/libavcodec/h264.c b/mythtv/external/FFmpeg/libavcodec/h264.c index d992bf2da9e..3a83b4b0316 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264.c +++ b/mythtv/external/FFmpeg/libavcodec/h264.c @@ -37,10 +37,12 @@ #include "mpegvideo.h" #include "h264.h" #include "h264data.h" +#include "h264chroma.h" #include "h264_mvpred.h" #include "golomb.h" #include "mathops.h" #include "rectangle.h" +#include "svq3.h" #include "thread.h" #include "vdpau_internal.h" #include "libavutil/avassert.h" @@ -66,10 +68,36 @@ static const uint8_t div6[QP_MAX_NUM + 1] = { 14,14,14,14, }; -static const enum AVPixelFormat hwaccel_pixfmt_list_h264_jpeg_420[] = { +static const enum AVPixelFormat h264_hwaccel_pixfmt_list_420[] = { +#if CONFIG_H264_DXVA2_HWACCEL AV_PIX_FMT_DXVA2_VLD, +#endif +#if CONFIG_H264_VAAPI_HWACCEL AV_PIX_FMT_VAAPI_VLD, +#endif +#if CONFIG_H264_VDA_HWACCEL AV_PIX_FMT_VDA_VLD, +#endif +#if CONFIG_H264_VDPAU_HWACCEL + AV_PIX_FMT_VDPAU, +#endif + AV_PIX_FMT_YUV420P, + AV_PIX_FMT_NONE +}; + +static const enum AVPixelFormat h264_hwaccel_pixfmt_list_jpeg_420[] = { +#if CONFIG_H264_DXVA2_HWACCEL + AV_PIX_FMT_DXVA2_VLD, +#endif +#if CONFIG_H264_VAAPI_HWACCEL + AV_PIX_FMT_VAAPI_VLD, +#endif +#if CONFIG_H264_VDA_HWACCEL + AV_PIX_FMT_VDA_VLD, +#endif +#if CONFIG_H264_VDPAU_HWACCEL + AV_PIX_FMT_VDPAU, +#endif AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_NONE }; @@ -80,13 +108,246 @@ int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx) return h ? h->sps.num_reorder_frames : 0; } +static void h264_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, + int (*mv)[2][4][2], + int mb_x, int mb_y, int mb_intra, int mb_skipped) +{ + H264Context *h = opaque; + + h->mb_x = mb_x; + h->mb_y = mb_y; + h->mb_xy = mb_x + mb_y * h->mb_stride; + memset(h->non_zero_count_cache, 0, sizeof(h->non_zero_count_cache)); + av_assert1(ref >= 0); + /* FIXME: It is possible albeit uncommon that slice references + * differ between slices. We take the easy approach and ignore + * it for now. If this turns out to have any relevance in + * practice then correct remapping should be added. */ + if (ref >= h->ref_count[0]) + ref = 0; + if (!h->ref_list[0][ref].f.data[0]) { + av_log(h->avctx, AV_LOG_DEBUG, "Reference not available for error concealing\n"); + ref = 0; + } + if ((h->ref_list[0][ref].f.reference&3) != 3) { + av_log(h->avctx, AV_LOG_DEBUG, "Reference invalid\n"); + return; + } + fill_rectangle(&h->cur_pic.f.ref_index[0][4 * h->mb_xy], + 2, 2, 2, ref, 1); + fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1); + fill_rectangle(h->mv_cache[0][scan8[0]], 4, 4, 8, + pack16to32((*mv)[0][0][0], (*mv)[0][0][1]), 4); + h->mb_mbaff = + h->mb_field_decoding_flag = 0; + ff_h264_hl_decode_mb(h); +} + +void ff_h264_draw_horiz_band(H264Context *h, int y, int height) +{ + AVCodecContext *avctx = h->avctx; + Picture *cur = &h->cur_pic; + Picture *last = h->ref_list[0][0].f.data[0] ? &h->ref_list[0][0] : NULL; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); + int vshift = desc->log2_chroma_h; + const int field_pic = h->picture_structure != PICT_FRAME; + if (field_pic) { + height <<= 1; + y <<= 1; + } + + height = FFMIN(height, avctx->height - y); + + if (field_pic && h->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->f.pict_type == AV_PICTURE_TYPE_B || h->low_delay || + (avctx->slice_flags & SLICE_FLAG_CODED_ORDER)) + src = &cur->f; + else if (last) + src = &last->f; + else + return; + + 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, h->picture_structure, height); + } +} + +static void free_frame_buffer(H264Context *h, Picture *pic) +{ + pic->period_since_free = 0; + ff_thread_release_buffer(h->avctx, &pic->f); + av_freep(&pic->f.hwaccel_picture_private); +} + +static void free_picture(H264Context *h, Picture *pic) +{ + int i; + + if (pic->f.data[0]) + free_frame_buffer(h, pic); + + av_freep(&pic->qscale_table_base); + pic->f.qscale_table = NULL; + av_freep(&pic->mb_type_base); + pic->f.mb_type = NULL; + for (i = 0; i < 2; i++) { + av_freep(&pic->motion_val_base[i]); + av_freep(&pic->f.ref_index[i]); + pic->f.motion_val[i] = NULL; + } +} + +static void release_unused_pictures(H264Context *h, int remove_current) +{ + int i; + + /* release non reference frames */ + for (i = 0; i < h->picture_count; i++) { + if (h->DPB[i].f.data[0] && !h->DPB[i].f.reference && + (!h->DPB[i].owner2 || h->DPB[i].owner2 == h) && + (remove_current || &h->DPB[i] != h->cur_pic_ptr)) { + free_frame_buffer(h, &h->DPB[i]); + } + } +} + +static int alloc_scratch_buffers(H264Context *h, int linesize) +{ + int alloc_size = FFALIGN(FFABS(linesize) + 32, 32); + + if (h->bipred_scratchpad) + return 0; + + h->bipred_scratchpad = av_malloc(16 * 6 * alloc_size); + // edge emu needs blocksize + filter length - 1 + // (= 21x21 for h264) + h->edge_emu_buffer = av_mallocz(alloc_size * 2 * 21); + h->me.scratchpad = av_mallocz(alloc_size * 2 * 16 * 2); + + if (!h->bipred_scratchpad || !h->edge_emu_buffer || !h->me.scratchpad) { + av_freep(&h->bipred_scratchpad); + av_freep(&h->edge_emu_buffer); + av_freep(&h->me.scratchpad); + return AVERROR(ENOMEM); + } + + h->me.temp = h->me.scratchpad; + + return 0; +} + +static int alloc_picture(H264Context *h, Picture *pic) +{ + const int big_mb_num = h->mb_stride * (h->mb_height + 1) + 1; + const int mb_array_size = h->mb_stride * h->mb_height; + const int b4_stride = h->mb_width * 4 + 1; + const int b4_array_size = b4_stride * h->mb_height * 4; + int i, ret = 0; + + av_assert0(!pic->f.data[0]); + + if (h->avctx->hwaccel) { + const AVHWAccel *hwaccel = h->avctx->hwaccel; + av_assert0(!pic->f.hwaccel_picture_private); + if (hwaccel->priv_data_size) { + pic->f.hwaccel_picture_private = av_mallocz(hwaccel->priv_data_size); + if (!pic->f.hwaccel_picture_private) + return AVERROR(ENOMEM); + } + } + ret = ff_thread_get_buffer(h->avctx, &pic->f); + if (ret < 0) + goto fail; + + h->linesize = pic->f.linesize[0]; + h->uvlinesize = pic->f.linesize[1]; + + if (pic->f.qscale_table == NULL) { + FF_ALLOCZ_OR_GOTO(h->avctx, pic->qscale_table_base, + (big_mb_num + h->mb_stride) * sizeof(uint8_t), + fail) + FF_ALLOCZ_OR_GOTO(h->avctx, pic->mb_type_base, + (big_mb_num + h->mb_stride) * sizeof(uint32_t), + fail) + pic->f.mb_type = pic->mb_type_base + 2 * h->mb_stride + 1; + pic->f.qscale_table = pic->qscale_table_base + 2 * h->mb_stride + 1; + + for (i = 0; i < 2; i++) { + FF_ALLOCZ_OR_GOTO(h->avctx, pic->motion_val_base[i], + 2 * (b4_array_size + 4) * sizeof(int16_t), + fail) + pic->f.motion_val[i] = pic->motion_val_base[i] + 4; + FF_ALLOCZ_OR_GOTO(h->avctx, pic->f.ref_index[i], + 4 * mb_array_size * sizeof(uint8_t), fail) + } + pic->f.motion_subsample_log2 = 2; + + pic->f.qstride = h->mb_stride; + } + + pic->owner2 = h; + + return 0; +fail: + free_frame_buffer(h, pic); + return (ret < 0) ? ret : AVERROR(ENOMEM); +} + +static inline int pic_is_unused(H264Context *h, Picture *pic) +{ + if ( (h->avctx->active_thread_type & FF_THREAD_FRAME) + && pic->f.qscale_table //check if the frame has anything allocated + && pic->period_since_free < h->avctx->thread_count) + return 0; + if (pic->f.data[0] == NULL) + return 1; + if (pic->needs_realloc && !(pic->f.reference & DELAYED_PIC_REF)) + if (!pic->owner2 || pic->owner2 == h) + return 1; + return 0; +} + +static int find_unused_picture(H264Context *h) +{ + int i; + + for (i = h->picture_range_start; i < h->picture_range_end; i++) { + if (pic_is_unused(h, &h->DPB[i])) + break; + } + if (i == h->picture_range_end) + return AVERROR_INVALIDDATA; + + if (h->DPB[i].needs_realloc) { + h->DPB[i].needs_realloc = 0; + free_picture(h, &h->DPB[i]); + avcodec_get_frame_defaults(&h->DPB[i].f); + } + + return i; +} + /** * Check if the top & left blocks are available if needed and * change the dc mode so it only uses the available blocks. */ int ff_h264_check_intra4x4_pred_mode(H264Context *h) { - MpegEncContext *const s = &h->s; static const int8_t top[12] = { -1, 0, LEFT_DC_PRED, -1, -1, -1, -1, -1, 0 }; @@ -99,9 +360,9 @@ int ff_h264_check_intra4x4_pred_mode(H264Context *h) for (i = 0; i < 4; i++) { int status = top[h->intra4x4_pred_mode_cache[scan8[0] + i]]; if (status < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "top block unavailable for requested intra4x4 mode %d at %d %d\n", - status, s->mb_x, s->mb_y); + status, h->mb_x, h->mb_y); return -1; } else if (status) { h->intra4x4_pred_mode_cache[scan8[0] + i] = status; @@ -115,9 +376,9 @@ int ff_h264_check_intra4x4_pred_mode(H264Context *h) if (!(h->left_samples_available & mask[i])) { int status = left[h->intra4x4_pred_mode_cache[scan8[0] + 8 * i]]; if (status < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "left block unavailable for requested intra4x4 mode %d at %d %d\n", - status, s->mb_x, s->mb_y); + status, h->mb_x, h->mb_y); return -1; } else if (status) { h->intra4x4_pred_mode_cache[scan8[0] + 8 * i] = status; @@ -134,23 +395,22 @@ int ff_h264_check_intra4x4_pred_mode(H264Context *h) */ int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma) { - MpegEncContext *const s = &h->s; static const int8_t top[7] = { LEFT_DC_PRED8x8, 1, -1, -1 }; static const int8_t left[7] = { TOP_DC_PRED8x8, -1, 2, -1, DC_128_PRED8x8 }; if (mode > 6U) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "out of range intra chroma pred mode at %d %d\n", - s->mb_x, s->mb_y); + h->mb_x, h->mb_y); return -1; } if (!(h->top_samples_available & 0x8000)) { mode = top[mode]; if (mode < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "top block unavailable for requested intra mode at %d %d\n", - s->mb_x, s->mb_y); + h->mb_x, h->mb_y); return -1; } } @@ -164,9 +424,9 @@ int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma) 2 * (mode == DC_128_PRED8x8); } if (mode < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "left block unavailable for requested intra mode at %d %d\n", - s->mb_x, s->mb_y); + h->mb_x, h->mb_y); return -1; } } @@ -246,7 +506,7 @@ const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, if(i>=length-1){ //no escaped 0 *dst_length= length; *consumed= length+1; //+1 for the header - if(h->s.avctx->flags2 & CODEC_FLAG2_FAST){ + if(h->avctx->flags2 & CODEC_FLAG2_FAST){ return src; }else{ memcpy(dst, src, length); @@ -295,7 +555,7 @@ static int decode_rbsp_trailing(H264Context *h, const uint8_t *src) int v = *src; int r; - tprintf(h->s.avctx, "rbsp trailing %X\n", v); + tprintf(h->avctx, "rbsp trailing %X\n", v); for (r = 1; r < 9; r++) { if (v & 1) @@ -309,23 +569,22 @@ static inline int get_lowest_part_list_y(H264Context *h, Picture *pic, int n, int height, int y_offset, int list) { int raw_my = h->mv_cache[list][scan8[n]][1]; - int filter_height_up = (raw_my & 3) ? 2 : 0; int filter_height_down = (raw_my & 3) ? 3 : 0; int full_my = (raw_my >> 2) + y_offset; - int top = full_my - filter_height_up; int bottom = full_my + filter_height_down + height; - return FFMAX(abs(top), bottom); + av_assert2(height >= 0); + + return FFMAX(0, bottom); } static inline void get_lowest_part_y(H264Context *h, int refs[2][48], int n, int height, int y_offset, int list0, int list1, int *nrefs) { - MpegEncContext *const s = &h->s; int my; - y_offset += 16 * (s->mb_y >> MB_FIELD); + y_offset += 16 * (h->mb_y >> MB_FIELD); if (list0) { int ref_n = h->ref_cache[0][scan8[n]]; @@ -334,8 +593,8 @@ static inline void get_lowest_part_y(H264Context *h, int refs[2][48], int n, // Error resilience puts the current picture in the ref list. // Don't try to wait on these as it will cause a deadlock. // Fields can wait on each other, though. - if (ref->f.thread_opaque != s->current_picture.f.thread_opaque || - (ref->f.reference & 3) != s->picture_structure) { + if (ref->f.thread_opaque != h->cur_pic.f.thread_opaque || + (ref->f.reference & 3) != h->picture_structure) { my = get_lowest_part_list_y(h, ref, n, height, y_offset, 0); if (refs[0][ref_n] < 0) nrefs[0] += 1; @@ -347,8 +606,8 @@ static inline void get_lowest_part_y(H264Context *h, int refs[2][48], int n, int ref_n = h->ref_cache[1][scan8[n]]; Picture *ref = &h->ref_list[1][ref_n]; - if (ref->f.thread_opaque != s->current_picture.f.thread_opaque || - (ref->f.reference & 3) != s->picture_structure) { + if (ref->f.thread_opaque != h->cur_pic.f.thread_opaque || + (ref->f.reference & 3) != h->picture_structure) { my = get_lowest_part_list_y(h, ref, n, height, y_offset, 1); if (refs[1][ref_n] < 0) nrefs[1] += 1; @@ -364,9 +623,8 @@ static inline void get_lowest_part_y(H264Context *h, int refs[2][48], int n, */ static void await_references(H264Context *h) { - MpegEncContext *const s = &h->s; const int mb_xy = h->mb_xy; - const int mb_type = s->current_picture.f.mb_type[mb_xy]; + const int mb_type = h->cur_pic.f.mb_type[mb_xy]; int refs[2][48]; int nrefs[2] = { 0 }; int ref, list; @@ -440,7 +698,7 @@ static void await_references(H264Context *h) Picture *ref_pic = &h->ref_list[list][ref]; int ref_field = ref_pic->f.reference - 1; int ref_field_picture = ref_pic->field_picture; - int pic_height = 16 * s->mb_height >> ref_field_picture; + int pic_height = 16 * h->mb_height >> ref_field_picture; row <<= MB_MBAFF; nrefs[list]--; @@ -481,20 +739,19 @@ static av_always_inline void mc_dir_part(H264Context *h, Picture *pic, h264_chroma_mc_func chroma_op, int pixel_shift, int chroma_idc) { - MpegEncContext *const s = &h->s; const int mx = h->mv_cache[list][scan8[n]][0] + src_x_offset * 8; int my = h->mv_cache[list][scan8[n]][1] + src_y_offset * 8; const int luma_xy = (mx & 3) + ((my & 3) << 2); int offset = ((mx >> 2) << pixel_shift) + (my >> 2) * h->mb_linesize; uint8_t *src_y = pic->f.data[0] + offset; uint8_t *src_cb, *src_cr; - int extra_width = h->emu_edge_width; - int extra_height = h->emu_edge_height; + int extra_width = 0; + int extra_height = 0; int emu = 0; const int full_mx = mx >> 2; const int full_my = my >> 2; - const int pic_width = 16 * s->mb_width; - const int pic_height = 16 * s->mb_height >> MB_FIELD; + const int pic_width = 16 * h->mb_width; + const int pic_height = 16 * h->mb_height >> MB_FIELD; int ysh; if (mx & 7) @@ -506,12 +763,12 @@ static av_always_inline void mc_dir_part(H264Context *h, Picture *pic, full_my < 0 - extra_height || full_mx + 16 /*FIXME*/ > pic_width + extra_width || full_my + 16 /*FIXME*/ > pic_height + extra_height) { - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, + h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_y - (2 << pixel_shift) - 2 * h->mb_linesize, h->mb_linesize, 16 + 5, 16 + 5 /*FIXME*/, full_mx - 2, full_my - 2, pic_width, pic_height); - src_y = s->edge_emu_buffer + (2 << pixel_shift) + 2 * h->mb_linesize; + src_y = h->edge_emu_buffer + (2 << pixel_shift) + 2 * h->mb_linesize; emu = 1; } @@ -519,19 +776,19 @@ static av_always_inline void mc_dir_part(H264Context *h, Picture *pic, if (!square) qpix_op[luma_xy](dest_y + delta, src_y + delta, h->mb_linesize); - if (CONFIG_GRAY && s->flags & CODEC_FLAG_GRAY) + if (CONFIG_GRAY && h->flags & CODEC_FLAG_GRAY) return; if (chroma_idc == 3 /* yuv444 */) { src_cb = pic->f.data[1] + offset; if (emu) { - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, + h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cb - (2 << pixel_shift) - 2 * h->mb_linesize, h->mb_linesize, 16 + 5, 16 + 5 /*FIXME*/, full_mx - 2, full_my - 2, pic_width, pic_height); - src_cb = s->edge_emu_buffer + (2 << pixel_shift) + 2 * h->mb_linesize; + src_cb = h->edge_emu_buffer + (2 << pixel_shift) + 2 * h->mb_linesize; } qpix_op[luma_xy](dest_cb, src_cb, h->mb_linesize); // FIXME try variable height perhaps? if (!square) @@ -539,13 +796,13 @@ static av_always_inline void mc_dir_part(H264Context *h, Picture *pic, src_cr = pic->f.data[2] + offset; if (emu) { - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, + h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cr - (2 << pixel_shift) - 2 * h->mb_linesize, h->mb_linesize, 16 + 5, 16 + 5 /*FIXME*/, full_mx - 2, full_my - 2, pic_width, pic_height); - src_cr = s->edge_emu_buffer + (2 << pixel_shift) + 2 * h->mb_linesize; + src_cr = h->edge_emu_buffer + (2 << pixel_shift) + 2 * h->mb_linesize; } qpix_op[luma_xy](dest_cr, src_cr, h->mb_linesize); // FIXME try variable height perhaps? if (!square) @@ -556,7 +813,7 @@ static av_always_inline void mc_dir_part(H264Context *h, Picture *pic, ysh = 3 - (chroma_idc == 2 /* yuv422 */); if (chroma_idc == 1 /* yuv420 */ && MB_FIELD) { // chroma offset when predicting from a field of opposite parity - my += 2 * ((s->mb_y & 1) - (pic->f.reference - 1)); + my += 2 * ((h->mb_y & 1) - (pic->f.reference - 1)); emu |= (my >> 3) < 0 || (my >> 3) + 8 >= (pic_height >> 1); } @@ -566,20 +823,20 @@ static av_always_inline void mc_dir_part(H264Context *h, Picture *pic, (my >> ysh) * h->mb_uvlinesize; if (emu) { - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src_cb, h->mb_uvlinesize, + h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cb, h->mb_uvlinesize, 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh), pic_width >> 1, pic_height >> (chroma_idc == 1 /* yuv420 */)); - src_cb = s->edge_emu_buffer; + src_cb = h->edge_emu_buffer; } chroma_op(dest_cb, src_cb, h->mb_uvlinesize, height >> (chroma_idc == 1 /* yuv420 */), mx & 7, (my << (chroma_idc == 2 /* yuv422 */)) & 7); if (emu) { - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src_cr, h->mb_uvlinesize, + h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cr, h->mb_uvlinesize, 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh), pic_width >> 1, pic_height >> (chroma_idc == 1 /* yuv420 */)); - src_cr = s->edge_emu_buffer; + src_cr = h->edge_emu_buffer; } chroma_op(dest_cr, src_cr, h->mb_uvlinesize, height >> (chroma_idc == 1 /* yuv420 */), mx & 7, (my << (chroma_idc == 2 /* yuv422 */)) & 7); @@ -597,7 +854,6 @@ static av_always_inline void mc_part_std(H264Context *h, int n, int square, int list0, int list1, int pixel_shift, int chroma_idc) { - MpegEncContext *const s = &h->s; qpel_mc_func *qpix_op = qpix_put; h264_chroma_mc_func chroma_op = chroma_put; @@ -612,8 +868,8 @@ static av_always_inline void mc_part_std(H264Context *h, int n, int square, dest_cb += (x_offset << pixel_shift) + y_offset * h->mb_uvlinesize; dest_cr += (x_offset << pixel_shift) + y_offset * h->mb_uvlinesize; } - x_offset += 8 * s->mb_x; - y_offset += 8 * (s->mb_y >> MB_FIELD); + x_offset += 8 * h->mb_x; + y_offset += 8 * (h->mb_y >> MB_FIELD); if (list0) { Picture *ref = &h->ref_list[0][h->ref_cache[0][scan8[n]]]; @@ -647,7 +903,6 @@ static av_always_inline void mc_part_weighted(H264Context *h, int n, int square, int list0, int list1, int pixel_shift, int chroma_idc) { - MpegEncContext *const s = &h->s; int chroma_height; dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->mb_linesize; @@ -666,8 +921,8 @@ static av_always_inline void mc_part_weighted(H264Context *h, int n, int square, dest_cb += (x_offset << pixel_shift) + y_offset * h->mb_uvlinesize; dest_cr += (x_offset << pixel_shift) + y_offset * h->mb_uvlinesize; } - x_offset += 8 * s->mb_x; - y_offset += 8 * (s->mb_y >> MB_FIELD); + x_offset += 8 * h->mb_x; + y_offset += 8 * (h->mb_y >> MB_FIELD); if (list0 && list1) { /* don't optimize for luma-only case, since B-frames usually @@ -688,7 +943,7 @@ static av_always_inline void mc_part_weighted(H264Context *h, int n, int square, pixel_shift, chroma_idc); if (h->use_weight == 2) { - int weight0 = h->implicit_weight[refn0][refn1][s->mb_y & 1]; + int weight0 = h->implicit_weight[refn0][refn1][h->mb_y & 1]; int weight1 = 64 - weight0; luma_weight_avg(dest_y, tmp_y, h->mb_linesize, height, 5, weight0, weight1, 0); @@ -746,22 +1001,21 @@ static av_always_inline void prefetch_motion(H264Context *h, int list, { /* fetch pixels for estimated mv 4 macroblocks ahead * optimized for 64byte cache lines */ - MpegEncContext *const s = &h->s; const int refn = h->ref_cache[list][scan8[0]]; if (refn >= 0) { - const int mx = (h->mv_cache[list][scan8[0]][0] >> 2) + 16 * s->mb_x + 8; - const int my = (h->mv_cache[list][scan8[0]][1] >> 2) + 16 * s->mb_y; + const int mx = (h->mv_cache[list][scan8[0]][0] >> 2) + 16 * h->mb_x + 8; + const int my = (h->mv_cache[list][scan8[0]][1] >> 2) + 16 * h->mb_y; uint8_t **src = h->ref_list[list][refn].f.data; int off = (mx << pixel_shift) + - (my + (s->mb_x & 3) * 4) * h->mb_linesize + + (my + (h->mb_x & 3) * 4) * h->mb_linesize + (64 << pixel_shift); - s->vdsp.prefetch(src[0] + off, s->linesize, 4); + h->vdsp.prefetch(src[0] + off, h->linesize, 4); if (chroma_idc == 3 /* yuv444 */) { - s->vdsp.prefetch(src[1] + off, s->linesize, 4); - s->vdsp.prefetch(src[2] + off, s->linesize, 4); + h->vdsp.prefetch(src[1] + off, h->linesize, 4); + h->vdsp.prefetch(src[2] + off, h->linesize, 4); } else { - off= (((mx>>1)+64)<>1) + (s->mb_x&7))*s->uvlinesize; - s->vdsp.prefetch(src[1] + off, src[2] - src[1], 2); + off= (((mx>>1)+64)<>1) + (h->mb_x&7))*h->uvlinesize; + h->vdsp.prefetch(src[1] + off, src[2] - src[1], 2); } } } @@ -785,6 +1039,21 @@ static void free_tables(H264Context *h, int free_rbsp) av_freep(&h->mb2b_xy); av_freep(&h->mb2br_xy); + for (i = 0; i < 3; i++) + av_freep(&h->visualization_buffer[i]); + + if (free_rbsp) { + for (i = 0; i < h->picture_count && !h->avctx->internal->is_copy; i++) + free_picture(h, &h->DPB[i]); + av_freep(&h->DPB); + h->picture_count = 0; + } else if (h->DPB) { + for (i = 0; i < h->picture_count; i++) + h->DPB[i].needs_realloc = 1; + } + + h->cur_pic_ptr = NULL; + for (i = 0; i < MAX_THREADS; i++) { hx = h->thread_context[i]; if (!hx) @@ -792,6 +1061,15 @@ static void free_tables(H264Context *h, int free_rbsp) av_freep(&hx->top_borders[1]); av_freep(&hx->top_borders[0]); av_freep(&hx->bipred_scratchpad); + av_freep(&hx->edge_emu_buffer); + av_freep(&hx->dc_val_base); + av_freep(&hx->me.scratchpad); + av_freep(&hx->er.mb_index2xy); + av_freep(&hx->er.error_status_table); + av_freep(&hx->er.er_temp_buffer); + av_freep(&hx->er.mbintra_table); + av_freep(&hx->er.mbskip_table); + if (free_rbsp) { av_freep(&hx->rbsp_buffer[1]); av_freep(&hx->rbsp_buffer[0]); @@ -875,50 +1153,59 @@ static void init_dequant_tables(H264Context *h) int ff_h264_alloc_tables(H264Context *h) { - MpegEncContext *const s = &h->s; - const int big_mb_num = s->mb_stride * (s->mb_height + 1); - const int row_mb_num = 2*s->mb_stride*FFMAX(s->avctx->thread_count, 1); - int x, y; + const int big_mb_num = h->mb_stride * (h->mb_height + 1); + const int row_mb_num = 2*h->mb_stride*FFMAX(h->avctx->thread_count, 1); + int x, y, i; - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->intra4x4_pred_mode, + FF_ALLOCZ_OR_GOTO(h->avctx, h->intra4x4_pred_mode, row_mb_num * 8 * sizeof(uint8_t), fail) - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->non_zero_count, + FF_ALLOCZ_OR_GOTO(h->avctx, h->non_zero_count, big_mb_num * 48 * sizeof(uint8_t), fail) - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->slice_table_base, - (big_mb_num + s->mb_stride) * sizeof(*h->slice_table_base), fail) - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->cbp_table, + FF_ALLOCZ_OR_GOTO(h->avctx, h->slice_table_base, + (big_mb_num + h->mb_stride) * sizeof(*h->slice_table_base), fail) + FF_ALLOCZ_OR_GOTO(h->avctx, h->cbp_table, big_mb_num * sizeof(uint16_t), fail) - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->chroma_pred_mode_table, + FF_ALLOCZ_OR_GOTO(h->avctx, h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t), fail) - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[0], + FF_ALLOCZ_OR_GOTO(h->avctx, h->mvd_table[0], 16 * row_mb_num * sizeof(uint8_t), fail); - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[1], + FF_ALLOCZ_OR_GOTO(h->avctx, h->mvd_table[1], 16 * row_mb_num * sizeof(uint8_t), fail); - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->direct_table, + FF_ALLOCZ_OR_GOTO(h->avctx, h->direct_table, 4 * big_mb_num * sizeof(uint8_t), fail); - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->list_counts, + FF_ALLOCZ_OR_GOTO(h->avctx, h->list_counts, big_mb_num * sizeof(uint8_t), fail) memset(h->slice_table_base, -1, - (big_mb_num + s->mb_stride) * sizeof(*h->slice_table_base)); - h->slice_table = h->slice_table_base + s->mb_stride * 2 + 1; + (big_mb_num + h->mb_stride) * sizeof(*h->slice_table_base)); + h->slice_table = h->slice_table_base + h->mb_stride * 2 + 1; - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mb2b_xy, + FF_ALLOCZ_OR_GOTO(h->avctx, h->mb2b_xy, big_mb_num * sizeof(uint32_t), fail); - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mb2br_xy, + FF_ALLOCZ_OR_GOTO(h->avctx, h->mb2br_xy, big_mb_num * sizeof(uint32_t), fail); - for (y = 0; y < s->mb_height; y++) - for (x = 0; x < s->mb_width; x++) { - const int mb_xy = x + y * s->mb_stride; + for (y = 0; y < h->mb_height; y++) + for (x = 0; x < h->mb_width; x++) { + const int mb_xy = x + y * h->mb_stride; const int b_xy = 4 * x + 4 * y * h->b_stride; h->mb2b_xy[mb_xy] = b_xy; - h->mb2br_xy[mb_xy] = 8 * (FMO ? mb_xy : (mb_xy % (2 * s->mb_stride))); + h->mb2br_xy[mb_xy] = 8 * (FMO ? mb_xy : (mb_xy % (2 * h->mb_stride))); } if (!h->dequant4_coeff[0]) init_dequant_tables(h); + if (!h->DPB) { + h->picture_count = MAX_PICTURE_COUNT * FFMAX(1, h->avctx->thread_count); + h->DPB = av_mallocz_array(h->picture_count, sizeof(*h->DPB)); + if (!h->DPB) + return AVERROR(ENOMEM); + for (i = 0; i < h->picture_count; i++) + avcodec_get_frame_defaults(&h->DPB[i].f); + avcodec_get_frame_defaults(&h->cur_pic.f); + } + return 0; fail: @@ -931,20 +1218,24 @@ int ff_h264_alloc_tables(H264Context *h) */ static void clone_tables(H264Context *dst, H264Context *src, int i) { - MpegEncContext *const s = &src->s; - dst->intra4x4_pred_mode = src->intra4x4_pred_mode + i * 8 * 2 * s->mb_stride; + dst->intra4x4_pred_mode = src->intra4x4_pred_mode + i * 8 * 2 * src->mb_stride; dst->non_zero_count = src->non_zero_count; dst->slice_table = src->slice_table; dst->cbp_table = src->cbp_table; dst->mb2b_xy = src->mb2b_xy; dst->mb2br_xy = src->mb2br_xy; dst->chroma_pred_mode_table = src->chroma_pred_mode_table; - dst->mvd_table[0] = src->mvd_table[0] + i * 8 * 2 * s->mb_stride; - dst->mvd_table[1] = src->mvd_table[1] + i * 8 * 2 * s->mb_stride; + dst->mvd_table[0] = src->mvd_table[0] + i * 8 * 2 * src->mb_stride; + dst->mvd_table[1] = src->mvd_table[1] + i * 8 * 2 * src->mb_stride; dst->direct_table = src->direct_table; dst->list_counts = src->list_counts; + dst->DPB = src->DPB; + dst->cur_pic_ptr = src->cur_pic_ptr; + dst->cur_pic = src->cur_pic; dst->bipred_scratchpad = NULL; - ff_h264_pred_init(&dst->hpc, src->s.codec_id, src->sps.bit_depth_luma, + dst->edge_emu_buffer = NULL; + dst->me.scratchpad = NULL; + ff_h264_pred_init(&dst->hpc, src->avctx->codec_id, src->sps.bit_depth_luma, src->sps.chroma_format_idc); } @@ -954,10 +1245,17 @@ static void clone_tables(H264Context *dst, H264Context *src, int i) */ static int context_init(H264Context *h) { - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[0], - h->s.mb_width * 16 * 3 * sizeof(uint8_t) * 2, fail) - FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[1], - h->s.mb_width * 16 * 3 * sizeof(uint8_t) * 2, fail) + ERContext *er = &h->er; + int mb_array_size = h->mb_height * h->mb_stride; + int y_size = (2 * h->mb_width + 1) * (2 * h->mb_height + 1); + int c_size = h->mb_stride * (h->mb_height + 1); + int yc_size = y_size + 2 * c_size; + int x, y, i; + + FF_ALLOCZ_OR_GOTO(h->avctx, h->top_borders[0], + h->mb_width * 16 * 3 * sizeof(uint8_t) * 2, fail) + FF_ALLOCZ_OR_GOTO(h->avctx, h->top_borders[1], + h->mb_width * 16 * 3 * sizeof(uint8_t) * 2, fail) h->ref_cache[0][scan8[5] + 1] = h->ref_cache[0][scan8[7] + 1] = @@ -966,6 +1264,48 @@ static int context_init(H264Context *h) h->ref_cache[1][scan8[7] + 1] = h->ref_cache[1][scan8[13] + 1] = PART_NOT_AVAILABLE; + if (CONFIG_ERROR_RESILIENCE) { + /* init ER */ + er->avctx = h->avctx; + er->dsp = &h->dsp; + er->decode_mb = h264_er_decode_mb; + er->opaque = h; + er->quarter_sample = 1; + + er->mb_num = h->mb_num; + er->mb_width = h->mb_width; + er->mb_height = h->mb_height; + er->mb_stride = h->mb_stride; + er->b8_stride = h->mb_width * 2 + 1; + + FF_ALLOCZ_OR_GOTO(h->avctx, er->mb_index2xy, (h->mb_num + 1) * sizeof(int), + fail); // error ressilience code looks cleaner with this + for (y = 0; y < h->mb_height; y++) + for (x = 0; x < h->mb_width; x++) + er->mb_index2xy[x + y * h->mb_width] = x + y * h->mb_stride; + + er->mb_index2xy[h->mb_height * h->mb_width] = (h->mb_height - 1) * + h->mb_stride + h->mb_width; + + FF_ALLOCZ_OR_GOTO(h->avctx, er->error_status_table, + mb_array_size * sizeof(uint8_t), fail); + + FF_ALLOC_OR_GOTO(h->avctx, er->mbintra_table, mb_array_size, fail); + memset(er->mbintra_table, 1, mb_array_size); + + FF_ALLOCZ_OR_GOTO(h->avctx, er->mbskip_table, mb_array_size + 2, fail); + + FF_ALLOC_OR_GOTO(h->avctx, er->er_temp_buffer, h->mb_height * h->mb_stride, + fail); + + FF_ALLOCZ_OR_GOTO(h->avctx, h->dc_val_base, yc_size * sizeof(int16_t), fail); + er->dc_val[0] = h->dc_val_base + h->mb_width * 2 + 2; + er->dc_val[1] = h->dc_val_base + y_size + h->mb_stride + 1; + er->dc_val[2] = er->dc_val[1] + c_size; + for (i = 0; i < yc_size; i++) + h->dc_val_base[i] = 1024; + } + return 0; fail: @@ -977,27 +1317,30 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, static av_cold void common_init(H264Context *h) { - MpegEncContext *const s = &h->s; - s->width = s->avctx->width; - s->height = s->avctx->height; - s->codec_id = s->avctx->codec->id; + h->width = h->avctx->width; + h->height = h->avctx->height; - s->avctx->bits_per_raw_sample = 8; + h->bit_depth_luma = 8; + h->chroma_format_idc = 1; + + h->avctx->bits_per_raw_sample = 8; h->cur_chroma_format_idc = 1; - ff_h264dsp_init(&h->h264dsp, - s->avctx->bits_per_raw_sample, h->cur_chroma_format_idc); - ff_h264_pred_init(&h->hpc, s->codec_id, - s->avctx->bits_per_raw_sample, h->cur_chroma_format_idc); + ff_h264dsp_init(&h->h264dsp, 8, 1); + av_assert0(h->sps.bit_depth_chroma == 0); + ff_h264chroma_init(&h->h264chroma, h->sps.bit_depth_chroma); + ff_h264qpel_init(&h->h264qpel, 8); + ff_h264_pred_init(&h->hpc, h->avctx->codec_id, 8, 1); h->dequant_coeff_pps = -1; - s->unrestricted_mv = 1; - s->dsp.dct_bits = 16; - /* needed so that IDCT permutation is known early */ - ff_dsputil_init(&s->dsp, s->avctx); - ff_videodsp_init(&s->vdsp, 8); + if (CONFIG_ERROR_RESILIENCE) { + h->dsp.dct_bits = 16; + /* needed so that IDCT permutation is known early */ + ff_dsputil_init(&h->dsp, h->avctx); + } + ff_videodsp_init(&h->vdsp, 8); memset(h->pps.scaling_matrix4, 16, 6 * 16 * sizeof(uint8_t)); memset(h->pps.scaling_matrix8, 16, 2 * 64 * sizeof(uint8_t)); @@ -1005,7 +1348,7 @@ static av_cold void common_init(H264Context *h) int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size) { - AVCodecContext *avctx = h->s.avctx; + AVCodecContext *avctx = h->avctx; if (!buf || size <= 0) return -1; @@ -1063,22 +1406,22 @@ int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size) av_cold int ff_h264_decode_init(AVCodecContext *avctx) { H264Context *h = avctx->priv_data; - MpegEncContext *const s = &h->s; int i; - ff_MPV_decode_defaults(s); - - s->avctx = avctx; + h->avctx = avctx; common_init(h); - s->out_format = FMT_H264; - s->workaround_bugs = avctx->workaround_bugs; + h->picture_structure = PICT_FRAME; + h->picture_range_start = 0; + h->picture_range_end = MAX_PICTURE_COUNT; + h->slice_context_count = 1; + h->workaround_bugs = avctx->workaround_bugs; + h->flags = avctx->flags; /* set defaults */ // s->decode_mb = ff_h263_decode_mb; - s->quarter_sample = 1; if (!avctx->has_b_frames) - s->low_delay = 1; + h->low_delay = 1; avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; @@ -1097,10 +1440,10 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx) ff_h264_reset_sei(h); if (avctx->codec_id == AV_CODEC_ID_H264) { if (avctx->ticks_per_frame == 1) { - if(s->avctx->time_base.den < INT_MAX/2) { - s->avctx->time_base.den *= 2; + if(h->avctx->time_base.den < INT_MAX/2) { + h->avctx->time_base.den *= 2; } else - s->avctx->time_base.num /= 2; + h->avctx->time_base.num /= 2; } avctx->ticks_per_frame = 2; } @@ -1112,9 +1455,9 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx) } if (h->sps.bitstream_restriction_flag && - s->avctx->has_b_frames < h->sps.num_reorder_frames) { - s->avctx->has_b_frames = h->sps.num_reorder_frames; - s->low_delay = 0; + h->avctx->has_b_frames < h->sps.num_reorder_frames) { + h->avctx->has_b_frames = h->sps.num_reorder_frames; + h->low_delay = 0; } ff_init_cabac_states(); @@ -1123,16 +1466,21 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx) } #define IN_RANGE(a, b, size) (((a) >= (b)) && ((a) < ((b) + (size)))) +#undef REBASE_PICTURE +#define REBASE_PICTURE(pic, new_ctx, old_ctx) \ + ((pic && pic >= old_ctx->DPB && \ + pic < old_ctx->DPB + old_ctx->picture_count) ? \ + &new_ctx->DPB[pic - old_ctx->DPB] : NULL) static void copy_picture_range(Picture **to, Picture **from, int count, - MpegEncContext *new_base, - MpegEncContext *old_base) + H264Context *new_base, + H264Context *old_base) { int i; for (i = 0; i < count; i++) { assert((IN_RANGE(from[i], old_base, sizeof(*old_base)) || - IN_RANGE(from[i], old_base->picture, + IN_RANGE(from[i], old_base->DPB, sizeof(Picture) * old_base->picture_count) || !from[i])); to[i] = REBASE_PICTURE(from[i], new_base, old_base); @@ -1163,7 +1511,7 @@ static int decode_init_thread_copy(AVCodecContext *avctx) memset(h->sps_buffers, 0, sizeof(h->sps_buffers)); memset(h->pps_buffers, 0, sizeof(h->pps_buffers)); - h->s.context_initialized = 0; + h->context_initialized = 0; return 0; } @@ -1180,27 +1528,30 @@ static int decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { H264Context *h = dst->priv_data, *h1 = src->priv_data; - MpegEncContext *const s = &h->s, *const s1 = &h1->s; - int inited = s->context_initialized, err; + int inited = h->context_initialized, err = 0; + int context_reinitialized = 0; int i; if (dst == src) return 0; if (inited && - (s->width != s1->width || - s->height != s1->height || - s->mb_width != s1->mb_width || - s->mb_height != s1->mb_height || + (h->width != h1->width || + h->height != h1->height || + h->mb_width != h1->mb_width || + h->mb_height != h1->mb_height || h->sps.bit_depth_luma != h1->sps.bit_depth_luma || h->sps.chroma_format_idc != h1->sps.chroma_format_idc || h->sps.colorspace != h1->sps.colorspace)) { av_freep(&h->bipred_scratchpad); - s->width = s1->width; - s->height = s1->height; - s->mb_height = s1->mb_height; + h->width = h1->width; + h->height = h1->height; + h->mb_height = h1->mb_height; + h->mb_width = h1->mb_width; + h->mb_num = h1->mb_num; + h->mb_stride = h1->mb_stride; h->b_stride = h1->b_stride; // SPS/PPS copy_parameter_set((void **)h->sps_buffers, (void **)h1->sps_buffers, @@ -1211,24 +1562,24 @@ static int decode_update_thread_context(AVCodecContext *dst, h->pps = h1->pps; if ((err = h264_slice_header_init(h, 1)) < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, "h264_slice_header_init() failed"); + av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed"); return err; } - h->context_reinitialized = 1; - - /* update linesize on resize for h264. The h264 decoder doesn't - * necessarily call ff_MPV_frame_start in the new thread */ - s->linesize = s1->linesize; - s->uvlinesize = s1->uvlinesize; + context_reinitialized = 1; - /* copy block_offset since frame_start may not be called */ - memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset)); +#if 0 h264_set_parameter_from_sps(h); + //Note we set context_reinitialized which will cause h264_set_parameter_from_sps to be reexecuted + h->cur_chroma_format_idc = h1->cur_chroma_format_idc; +#endif } + /* update linesize on resize for h264. The h264 decoder doesn't + * necessarily call ff_MPV_frame_start in the new thread */ + h->linesize = h1->linesize; + h->uvlinesize = h1->uvlinesize; - err = ff_mpeg_update_thread_context(dst, src); - if (err) - return err; + /* copy block_offset since frame_start may not be called */ + memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset)); if (!inited) { for (i = 0; i < MAX_SPS_COUNT; i++) @@ -1237,19 +1588,32 @@ static int decode_update_thread_context(AVCodecContext *dst, for (i = 0; i < MAX_PPS_COUNT; i++) av_freep(h->pps_buffers + i); - // copy all fields after MpegEnc - memcpy(&h->s + 1, &h1->s + 1, - sizeof(H264Context) - sizeof(MpegEncContext)); + memcpy(h, h1, offsetof(H264Context, intra_pcm_ptr)); + memcpy(&h->cabac, &h1->cabac, + sizeof(H264Context) - offsetof(H264Context, cabac)); + av_assert0((void*)&h->cabac == &h->mb_padding + 1); + memset(h->sps_buffers, 0, sizeof(h->sps_buffers)); memset(h->pps_buffers, 0, sizeof(h->pps_buffers)); - if (s1->context_initialized) { + memset(&h->er, 0, sizeof(h->er)); + memset(&h->me, 0, sizeof(h->me)); + h->avctx = dst; + h->DPB = NULL; + + if (h1->context_initialized) { + h->context_initialized = 0; + + h->picture_range_start += MAX_PICTURE_COUNT; + h->picture_range_end += MAX_PICTURE_COUNT; + + h->cur_pic.f.extended_data = h->cur_pic.f.data; + if (ff_h264_alloc_tables(h) < 0) { av_log(dst, AV_LOG_ERROR, "Could not allocate memory for h264\n"); return AVERROR(ENOMEM); } context_init(h); - } for (i = 0; i < 2; i++) { @@ -1257,17 +1621,39 @@ static int decode_update_thread_context(AVCodecContext *dst, h->rbsp_buffer_size[i] = 0; } h->bipred_scratchpad = NULL; + h->edge_emu_buffer = NULL; h->thread_context[0] = h; + h->context_initialized = h1->context_initialized; + } - s->dsp.clear_blocks(h->mb); - s->dsp.clear_blocks(h->mb + (24 * 16 << h->pixel_shift)); + h->avctx->coded_height = h1->avctx->coded_height; + h->avctx->coded_width = h1->avctx->coded_width; + h->avctx->width = h1->avctx->width; + h->avctx->height = h1->avctx->height; + h->coded_picture_number = h1->coded_picture_number; + h->first_field = h1->first_field; + h->picture_structure = h1->picture_structure; + h->qscale = h1->qscale; + h->droppable = h1->droppable; + h->data_partitioning = h1->data_partitioning; + h->low_delay = h1->low_delay; + + memcpy(h->DPB, h1->DPB, h1->picture_count * sizeof(*h1->DPB)); + + // reset s->picture[].f.extended_data to s->picture[].f.data + for (i = 0; i < h->picture_count; i++) { + h->DPB[i].f.extended_data = h->DPB[i].f.data; + h->DPB[i].period_since_free ++; } - /* frame_start may not be called for the next thread (if it's decoding - * a bottom field) so this has to be allocated here */ - if (!h->bipred_scratchpad && s->linesize) - h->bipred_scratchpad = av_malloc(16 * 6 * s->linesize); + h->cur_pic_ptr = REBASE_PICTURE(h1->cur_pic_ptr, h, h1); + h->cur_pic = h1->cur_pic; + h->cur_pic.f.extended_data = h->cur_pic.f.data; + + h->workaround_bugs = h1->workaround_bugs; + h->low_delay = h1->low_delay; + h->droppable = h1->droppable; // extradata/NAL handling h->is_avc = h1->is_avc; @@ -1298,22 +1684,24 @@ static int decode_update_thread_context(AVCodecContext *dst, copy_fields(h, h1, poc_lsb, redundant_pic_count); // reference lists - copy_fields(h, h1, ref_count, list_count); - copy_fields(h, h1, ref_list, intra_gb); copy_fields(h, h1, short_ref, cabac_init_idc); - copy_picture_range(h->short_ref, h1->short_ref, 32, s, s1); - copy_picture_range(h->long_ref, h1->long_ref, 32, s, s1); + copy_picture_range(h->short_ref, h1->short_ref, 32, h, h1); + copy_picture_range(h->long_ref, h1->long_ref, 32, h, h1); copy_picture_range(h->delayed_pic, h1->delayed_pic, - MAX_DELAYED_PIC_COUNT + 2, s, s1); + MAX_DELAYED_PIC_COUNT + 2, h, h1); h->last_slice_type = h1->last_slice_type; h->sync = h1->sync; + memcpy(h->last_ref_count, h1->last_ref_count, sizeof(h->last_ref_count)); - if (!s->current_picture_ptr) + if (context_reinitialized) + h264_set_parameter_from_sps(h); + + if (!h->cur_pic_ptr) return 0; - if (!s->droppable) { + if (!h->droppable) { err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index); h->prev_poc_msb = h->poc_msb; h->prev_poc_lsb = h->poc_lsb; @@ -1327,49 +1715,80 @@ static int decode_update_thread_context(AVCodecContext *dst, int ff_h264_frame_start(H264Context *h) { - MpegEncContext *const s = &h->s; - int i; + Picture *pic; + int i, ret; const int pixel_shift = h->pixel_shift; + int c[4] = { + 1<<(h->sps.bit_depth_luma-1), + 1<<(h->sps.bit_depth_chroma-1), + 1<<(h->sps.bit_depth_chroma-1), + -1 + }; - if (ff_MPV_frame_start(s, s->avctx) < 0) + if (!ff_thread_can_start_frame(h->avctx)) { + av_log(h->avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n"); return -1; - ff_er_frame_start(s); + } + + release_unused_pictures(h, 1); + h->cur_pic_ptr = NULL; + + i = find_unused_picture(h); + if (i < 0) { + av_log(h->avctx, AV_LOG_ERROR, "no frame buffer available\n"); + return i; + } + pic = &h->DPB[i]; + + pic->f.reference = h->droppable ? 0 : h->picture_structure; + pic->f.coded_picture_number = h->coded_picture_number++; + pic->field_picture = h->picture_structure != PICT_FRAME; + /* - * ff_MPV_frame_start uses pict_type to derive key_frame. - * This is incorrect for H.264; IDR markings must be used. - * Zero here; IDR markings per slice in frame or fields are ORed in later. + * Zero key_frame here; IDR markings per slice in frame or fields are ORed + * in later. * See decode_nal_units(). */ - s->current_picture_ptr->f.key_frame = 0; - s->current_picture_ptr->sync = 0; - s->current_picture_ptr->mmco_reset = 0; + pic->f.key_frame = 0; + pic->sync = 0; + pic->mmco_reset = 0; - assert(s->linesize && s->uvlinesize); + if ((ret = alloc_picture(h, pic)) < 0) + return ret; + if(!h->sync && !h->avctx->hwaccel && + !(h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)) + avpriv_color_frame(&pic->f, c); + + h->cur_pic_ptr = pic; + h->cur_pic = *h->cur_pic_ptr; + h->cur_pic.f.extended_data = h->cur_pic.f.data; + + if (CONFIG_ERROR_RESILIENCE) { + ff_er_frame_start(&h->er); + h->er.last_pic = + h->er.next_pic = NULL; + } + + assert(h->linesize && h->uvlinesize); for (i = 0; i < 16; i++) { - h->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * s->linesize * ((scan8[i] - scan8[0]) >> 3); - h->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * s->linesize * ((scan8[i] - scan8[0]) >> 3); + h->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * h->linesize * ((scan8[i] - scan8[0]) >> 3); + h->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * h->linesize * ((scan8[i] - scan8[0]) >> 3); } for (i = 0; i < 16; i++) { h->block_offset[16 + i] = - h->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * s->uvlinesize * ((scan8[i] - scan8[0]) >> 3); + h->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * h->uvlinesize * ((scan8[i] - scan8[0]) >> 3); h->block_offset[48 + 16 + i] = - h->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * s->uvlinesize * ((scan8[i] - scan8[0]) >> 3); + h->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * h->uvlinesize * ((scan8[i] - scan8[0]) >> 3); } - /* can't be in alloc_tables because linesize isn't known there. - * FIXME: redo bipred weight to not require extra buffer? */ - for (i = 0; i < s->slice_context_count; i++) - if (h->thread_context[i] && !h->thread_context[i]->bipred_scratchpad) - h->thread_context[i]->bipred_scratchpad = av_malloc(16 * 6 * s->linesize); - /* Some macroblocks can be accessed before they're available in case * of lost slices, MBAFF or threading. */ memset(h->slice_table, -1, - (s->mb_height * s->mb_stride - 1) * sizeof(*h->slice_table)); + (h->mb_height * h->mb_stride - 1) * sizeof(*h->slice_table)); - // s->decode = (s->flags & CODEC_FLAG_PSNR) || !s->encoding || - // s->current_picture.f.reference /* || h->contains_intra */ || 1; + // s->decode = (h->flags & CODEC_FLAG_PSNR) || !s->encoding || + // h->cur_pic.f.reference /* || h->contains_intra */ || 1; /* We mark the current picture as non-reference after allocating it, so * that if we break out due to an error it can be released automatically @@ -1377,15 +1796,14 @@ int ff_h264_frame_start(H264Context *h) * SVQ3 as well as most other codecs have only last/next/current and thus * get released even with set reference, besides SVQ3 and others do not * mark frames as reference later "naturally". */ - if (s->codec_id != AV_CODEC_ID_SVQ3) - s->current_picture_ptr->f.reference = 0; + if (h->avctx->codec_id != AV_CODEC_ID_SVQ3) + h->cur_pic_ptr->f.reference = 0; - s->current_picture_ptr->field_poc[0] = - s->current_picture_ptr->field_poc[1] = INT_MAX; + h->cur_pic_ptr->field_poc[0] = h->cur_pic_ptr->field_poc[1] = INT_MAX; h->next_output_pic = NULL; - assert(s->current_picture_ptr->long_ref == 0); + assert(h->cur_pic_ptr->long_ref == 0); return 0; } @@ -1400,13 +1818,12 @@ int ff_h264_frame_start(H264Context *h) */ static void decode_postinit(H264Context *h, int setup_finished) { - MpegEncContext *const s = &h->s; - Picture *out = s->current_picture_ptr; - Picture *cur = s->current_picture_ptr; + Picture *out = h->cur_pic_ptr; + Picture *cur = h->cur_pic_ptr; int i, pics, out_of_order, out_idx; - s->current_picture_ptr->f.qscale_type = FF_QSCALE_TYPE_H264; - s->current_picture_ptr->f.pict_type = s->pict_type; + h->cur_pic_ptr->f.qscale_type = FF_QSCALE_TYPE_H264; + h->cur_pic_ptr->f.pict_type = h->pict_type; if (h->next_output_pic) return; @@ -1417,7 +1834,7 @@ static void decode_postinit(H264Context *h, int setup_finished) * The check in decode_nal_units() is not good enough to find this * yet, so we assume the worst for now. */ // if (setup_finished) - // ff_thread_finish_setup(s->avctx); + // ff_thread_finish_setup(h->avctx); return; } @@ -1452,7 +1869,6 @@ static void decode_postinit(H264Context *h, int setup_finished) cur->f.repeat_pict = 1; break; case SEI_PIC_STRUCT_FRAME_DOUBLING: - // Force progressive here, doubling interlaced frame is a bad idea. cur->f.repeat_pict = 2; break; case SEI_PIC_STRUCT_FRAME_TRIPLING: @@ -1494,15 +1910,15 @@ static void decode_postinit(H264Context *h, int setup_finished) /* Sort B-frames into display order */ if (h->sps.bitstream_restriction_flag && - s->avctx->has_b_frames < h->sps.num_reorder_frames) { - s->avctx->has_b_frames = h->sps.num_reorder_frames; - s->low_delay = 0; + h->avctx->has_b_frames < h->sps.num_reorder_frames) { + h->avctx->has_b_frames = h->sps.num_reorder_frames; + h->low_delay = 0; } - if (s->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT && + if (h->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT && !h->sps.bitstream_restriction_flag) { - s->avctx->has_b_frames = MAX_DELAYED_PIC_COUNT - 1; - s->low_delay = 0; + h->avctx->has_b_frames = MAX_DELAYED_PIC_COUNT - 1; + h->low_delay = 0; } for (i = 0; 1; i++) { @@ -1519,15 +1935,15 @@ static void decode_postinit(H264Context *h, int setup_finished) || (h->last_pocs[MAX_DELAYED_PIC_COUNT-2] > INT_MIN && h->last_pocs[MAX_DELAYED_PIC_COUNT-1] - h->last_pocs[MAX_DELAYED_PIC_COUNT-2] > 2)) out_of_order = FFMAX(out_of_order, 1); if (out_of_order == MAX_DELAYED_PIC_COUNT) { - av_log(s->avctx, AV_LOG_VERBOSE, "Invalid POC %d<%d\n", cur->poc, h->last_pocs[0]); + av_log(h->avctx, AV_LOG_VERBOSE, "Invalid POC %d<%d\n", cur->poc, h->last_pocs[0]); for (i = 1; i < MAX_DELAYED_PIC_COUNT; i++) h->last_pocs[i] = INT_MIN; h->last_pocs[0] = cur->poc; cur->mmco_reset = 1; - } else if(s->avctx->has_b_frames < out_of_order && !h->sps.bitstream_restriction_flag){ - av_log(s->avctx, AV_LOG_VERBOSE, "Increasing reorder buffer to %d\n", out_of_order); - s->avctx->has_b_frames = out_of_order; - s->low_delay = 0; + } else if(h->avctx->has_b_frames < out_of_order && !h->sps.bitstream_restriction_flag){ + av_log(h->avctx, AV_LOG_VERBOSE, "Increasing reorder buffer to %d\n", out_of_order); + h->avctx->has_b_frames = out_of_order; + h->low_delay = 0; } pics = 0; @@ -1550,27 +1966,27 @@ static void decode_postinit(H264Context *h, int setup_finished) out = h->delayed_pic[i]; out_idx = i; } - if (s->avctx->has_b_frames == 0 && + if (h->avctx->has_b_frames == 0 && (h->delayed_pic[0]->f.key_frame || h->delayed_pic[0]->mmco_reset)) h->next_outputed_poc = INT_MIN; out_of_order = out->poc < h->next_outputed_poc; - if (out_of_order || pics > s->avctx->has_b_frames) { + if (out_of_order || pics > h->avctx->has_b_frames) { out->f.reference &= ~DELAYED_PIC_REF; // for frame threading, the owner must be the second field's thread or // else the first thread can release the picture and reuse it unsafely - out->owner2 = s; + out->owner2 = h; for (i = out_idx; h->delayed_pic[i]; i++) h->delayed_pic[i] = h->delayed_pic[i + 1]; } - if (!out_of_order && pics > s->avctx->has_b_frames) { + if (!out_of_order && pics > h->avctx->has_b_frames) { h->next_output_pic = out; if (out_idx == 0 && h->delayed_pic[0] && (h->delayed_pic[0]->f.key_frame || h->delayed_pic[0]->mmco_reset)) { h->next_outputed_poc = INT_MIN; } else h->next_outputed_poc = out->poc; } else { - av_log(s->avctx, AV_LOG_DEBUG, "no picture %s\n", out_of_order ? "ooo" : ""); + av_log(h->avctx, AV_LOG_DEBUG, "no picture %s\n", out_of_order ? "ooo" : ""); } if (h->next_output_pic && h->next_output_pic->sync) { @@ -1578,7 +1994,7 @@ static void decode_postinit(H264Context *h, int setup_finished) } if (setup_finished) - ff_thread_finish_setup(s->avctx); + ff_thread_finish_setup(h->avctx); } static av_always_inline void backup_mb_border(H264Context *h, uint8_t *src_y, @@ -1586,7 +2002,6 @@ static av_always_inline void backup_mb_border(H264Context *h, uint8_t *src_y, int linesize, int uvlinesize, int simple) { - MpegEncContext *const s = &h->s; uint8_t *top_border; int top_idx = 1; const int pixel_shift = h->pixel_shift; @@ -1598,13 +2013,13 @@ static av_always_inline void backup_mb_border(H264Context *h, uint8_t *src_y, src_cr -= uvlinesize; if (!simple && FRAME_MBAFF) { - if (s->mb_y & 1) { + if (h->mb_y & 1) { if (!MB_MBAFF) { - top_border = h->top_borders[0][s->mb_x]; + top_border = h->top_borders[0][h->mb_x]; AV_COPY128(top_border, src_y + 15 * linesize); if (pixel_shift) AV_COPY128(top_border + 16, src_y + 15 * linesize + 16); - if (simple || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { + if (simple || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) { if (chroma444) { if (pixel_shift) { AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize); @@ -1640,14 +2055,14 @@ static av_always_inline void backup_mb_border(H264Context *h, uint8_t *src_y, return; } - top_border = h->top_borders[top_idx][s->mb_x]; + top_border = h->top_borders[top_idx][h->mb_x]; /* There are two lines saved, the line above the top macroblock * of a pair, and the line above the bottom macroblock. */ AV_COPY128(top_border, src_y + 16 * linesize); if (pixel_shift) AV_COPY128(top_border + 16, src_y + 16 * linesize + 16); - if (simple || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { + if (simple || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) { if (chroma444) { if (pixel_shift) { AV_COPY128(top_border + 32, src_cb + 16 * linesize); @@ -1684,7 +2099,6 @@ static av_always_inline void xchg_mb_border(H264Context *h, uint8_t *src_y, int xchg, int chroma444, int simple, int pixel_shift) { - MpegEncContext *const s = &h->s; int deblock_topleft; int deblock_top; int top_idx = 1; @@ -1692,7 +2106,7 @@ static av_always_inline void xchg_mb_border(H264Context *h, uint8_t *src_y, uint8_t *top_border; if (!simple && FRAME_MBAFF) { - if (s->mb_y & 1) { + if (h->mb_y & 1) { if (!MB_MBAFF) return; } else { @@ -1701,19 +2115,19 @@ static av_always_inline void xchg_mb_border(H264Context *h, uint8_t *src_y, } if (h->deblocking_filter == 2) { - deblock_topleft = h->slice_table[h->mb_xy - 1 - s->mb_stride] == h->slice_num; + deblock_topleft = h->slice_table[h->mb_xy - 1 - h->mb_stride] == h->slice_num; deblock_top = h->top_type; } else { - deblock_topleft = (s->mb_x > 0); - deblock_top = (s->mb_y > !!MB_FIELD); + deblock_topleft = (h->mb_x > 0); + deblock_top = (h->mb_y > !!MB_FIELD); } src_y -= linesize + 1 + pixel_shift; src_cb -= uvlinesize + 1 + pixel_shift; src_cr -= uvlinesize + 1 + pixel_shift; - top_border_m1 = h->top_borders[top_idx][s->mb_x - 1]; - top_border = h->top_borders[top_idx][s->mb_x]; + top_border_m1 = h->top_borders[top_idx][h->mb_x - 1]; + top_border = h->top_borders[top_idx][h->mb_x]; #define XCHG(a, b, xchg) \ if (pixel_shift) { \ @@ -1735,12 +2149,12 @@ static av_always_inline void xchg_mb_border(H264Context *h, uint8_t *src_y, } XCHG(top_border + (0 << pixel_shift), src_y + (1 << pixel_shift), xchg); XCHG(top_border + (8 << pixel_shift), src_y + (9 << pixel_shift), 1); - if (s->mb_x + 1 < s->mb_width) { - XCHG(h->top_borders[top_idx][s->mb_x + 1], + if (h->mb_x + 1 < h->mb_width) { + XCHG(h->top_borders[top_idx][h->mb_x + 1], src_y + (17 << pixel_shift), 1); } } - if (simple || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { + if (simple || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) { if (chroma444) { if (deblock_topleft) { XCHG(top_border_m1 + (24 << pixel_shift), src_cb - (7 << pixel_shift), 1); @@ -1750,9 +2164,9 @@ static av_always_inline void xchg_mb_border(H264Context *h, uint8_t *src_y, XCHG(top_border + (24 << pixel_shift), src_cb + (9 << pixel_shift), 1); XCHG(top_border + (32 << pixel_shift), src_cr + (1 << pixel_shift), xchg); XCHG(top_border + (40 << pixel_shift), src_cr + (9 << pixel_shift), 1); - if (s->mb_x + 1 < s->mb_width) { - XCHG(h->top_borders[top_idx][s->mb_x + 1] + (16 << pixel_shift), src_cb + (17 << pixel_shift), 1); - XCHG(h->top_borders[top_idx][s->mb_x + 1] + (32 << pixel_shift), src_cr + (17 << pixel_shift), 1); + if (h->mb_x + 1 < h->mb_width) { + XCHG(h->top_borders[top_idx][h->mb_x + 1] + (16 << pixel_shift), src_cb + (17 << pixel_shift), 1); + XCHG(h->top_borders[top_idx][h->mb_x + 1] + (32 << pixel_shift), src_cr + (17 << pixel_shift), 1); } } else { if (deblock_top) { @@ -1767,7 +2181,7 @@ static av_always_inline void xchg_mb_border(H264Context *h, uint8_t *src_y, } } -static av_always_inline int dctcoef_get(DCTELEM *mb, int high_bit_depth, +static av_always_inline int dctcoef_get(int16_t *mb, int high_bit_depth, int index) { if (high_bit_depth) { @@ -1776,7 +2190,7 @@ static av_always_inline int dctcoef_get(DCTELEM *mb, int high_bit_depth, return AV_RN16A(mb + index); } -static av_always_inline void dctcoef_set(DCTELEM *mb, int high_bit_depth, +static av_always_inline void dctcoef_set(int16_t *mb, int high_bit_depth, int index, int value) { if (high_bit_depth) { @@ -1794,84 +2208,81 @@ static av_always_inline void hl_decode_mb_predict_luma(H264Context *h, int linesize, uint8_t *dest_y, int p) { - MpegEncContext *const s = &h->s; - void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride); - void (*idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride); + void (*idct_add)(uint8_t *dst, int16_t *block, int stride); + void (*idct_dc_add)(uint8_t *dst, int16_t *block, int stride); int i; - int qscale = p == 0 ? s->qscale : h->chroma_qp[p - 1]; + int qscale = p == 0 ? h->qscale : h->chroma_qp[p - 1]; block_offset += 16 * p; if (IS_INTRA4x4(mb_type)) { - if (simple || !s->encoding) { - if (IS_8x8DCT(mb_type)) { - if (transform_bypass) { - idct_dc_add = - idct_add = s->dsp.add_pixels8; + if (IS_8x8DCT(mb_type)) { + if (transform_bypass) { + idct_dc_add = + idct_add = h->h264dsp.h264_add_pixels8_clear; + } else { + idct_dc_add = h->h264dsp.h264_idct8_dc_add; + idct_add = h->h264dsp.h264_idct8_add; + } + for (i = 0; i < 16; i += 4) { + uint8_t *const ptr = dest_y + block_offset[i]; + const int dir = h->intra4x4_pred_mode_cache[scan8[i]]; + if (transform_bypass && h->sps.profile_idc == 244 && dir <= 1) { + h->hpc.pred8x8l_add[dir](ptr, h->mb + (i * 16 + p * 256 << pixel_shift), linesize); } else { - idct_dc_add = h->h264dsp.h264_idct8_dc_add; - idct_add = h->h264dsp.h264_idct8_add; - } - for (i = 0; i < 16; i += 4) { - uint8_t *const ptr = dest_y + block_offset[i]; - const int dir = h->intra4x4_pred_mode_cache[scan8[i]]; - if (transform_bypass && h->sps.profile_idc == 244 && dir <= 1) { - h->hpc.pred8x8l_add[dir](ptr, h->mb + (i * 16 + p * 256 << pixel_shift), linesize); - } else { - const int nnz = h->non_zero_count_cache[scan8[i + p * 16]]; - h->hpc.pred8x8l[dir](ptr, (h->topleft_samples_available << i) & 0x8000, - (h->topright_samples_available << i) & 0x4000, linesize); - if (nnz) { - if (nnz == 1 && dctcoef_get(h->mb, pixel_shift, i * 16 + p * 256)) - idct_dc_add(ptr, h->mb + (i * 16 + p * 256 << pixel_shift), linesize); - else - idct_add(ptr, h->mb + (i * 16 + p * 256 << pixel_shift), linesize); - } + const int nnz = h->non_zero_count_cache[scan8[i + p * 16]]; + h->hpc.pred8x8l[dir](ptr, (h->topleft_samples_available << i) & 0x8000, + (h->topright_samples_available << i) & 0x4000, linesize); + if (nnz) { + if (nnz == 1 && dctcoef_get(h->mb, pixel_shift, i * 16 + p * 256)) + idct_dc_add(ptr, h->mb + (i * 16 + p * 256 << pixel_shift), linesize); + else + idct_add(ptr, h->mb + (i * 16 + p * 256 << pixel_shift), linesize); } } + } + } else { + if (transform_bypass) { + idct_dc_add = + idct_add = h->h264dsp.h264_add_pixels4_clear; } else { - if (transform_bypass) { - idct_dc_add = - idct_add = s->dsp.add_pixels4; - } else { - idct_dc_add = h->h264dsp.h264_idct_dc_add; - idct_add = h->h264dsp.h264_idct_add; - } - for (i = 0; i < 16; i++) { - uint8_t *const ptr = dest_y + block_offset[i]; - const int dir = h->intra4x4_pred_mode_cache[scan8[i]]; + idct_dc_add = h->h264dsp.h264_idct_dc_add; + idct_add = h->h264dsp.h264_idct_add; + } + for (i = 0; i < 16; i++) { + uint8_t *const ptr = dest_y + block_offset[i]; + const int dir = h->intra4x4_pred_mode_cache[scan8[i]]; - if (transform_bypass && h->sps.profile_idc == 244 && dir <= 1) { - h->hpc.pred4x4_add[dir](ptr, h->mb + (i * 16 + p * 256 << pixel_shift), linesize); - } else { - uint8_t *topright; - int nnz, tr; - uint64_t tr_high; - if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) { - const int topright_avail = (h->topright_samples_available << i) & 0x8000; - av_assert2(s->mb_y || linesize <= block_offset[i]); - if (!topright_avail) { - if (pixel_shift) { - tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL; - topright = (uint8_t *)&tr_high; - } else { - tr = ptr[3 - linesize] * 0x01010101u; - topright = (uint8_t *)&tr; - } - } else - topright = ptr + (4 << pixel_shift) - linesize; + if (transform_bypass && h->sps.profile_idc == 244 && dir <= 1) { + h->hpc.pred4x4_add[dir](ptr, h->mb + (i * 16 + p * 256 << pixel_shift), linesize); + } else { + uint8_t *topright; + int nnz, tr; + uint64_t tr_high; + if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) { + const int topright_avail = (h->topright_samples_available << i) & 0x8000; + av_assert2(h->mb_y || linesize <= block_offset[i]); + if (!topright_avail) { + if (pixel_shift) { + tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL; + topright = (uint8_t *)&tr_high; + } else { + tr = ptr[3 - linesize] * 0x01010101u; + topright = (uint8_t *)&tr; + } } else - topright = NULL; - - h->hpc.pred4x4[dir](ptr, topright, linesize); - nnz = h->non_zero_count_cache[scan8[i + p * 16]]; - if (nnz) { - if (is_h264) { - if (nnz == 1 && dctcoef_get(h->mb, pixel_shift, i * 16 + p * 256)) - idct_dc_add(ptr, h->mb + (i * 16 + p * 256 << pixel_shift), linesize); - else - idct_add(ptr, h->mb + (i * 16 + p * 256 << pixel_shift), linesize); - } else if (CONFIG_SVQ3_DECODER) - ff_svq3_add_idct_c(ptr, h->mb + i * 16 + p * 256, linesize, qscale, 0); - } + topright = ptr + (4 << pixel_shift) - linesize; + } else + topright = NULL; + + h->hpc.pred4x4[dir](ptr, topright, linesize); + nnz = h->non_zero_count_cache[scan8[i + p * 16]]; + if (nnz) { + if (is_h264) { + if (nnz == 1 && dctcoef_get(h->mb, pixel_shift, i * 16 + p * 256)) + idct_dc_add(ptr, h->mb + (i * 16 + p * 256 << pixel_shift), linesize); + else + idct_add(ptr, h->mb + (i * 16 + p * 256 << pixel_shift), linesize); + } else if (CONFIG_SVQ3_DECODER) + ff_svq3_add_idct_c(ptr, h->mb + i * 16 + p * 256, linesize, qscale, 0); } } } @@ -1911,8 +2322,7 @@ static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, int mb_type, int linesize, uint8_t *dest_y, int p) { - MpegEncContext *const s = &h->s; - void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride); + void (*idct_add)(uint8_t *dst, int16_t *block, int stride); int i; block_offset += 16 * p; if (!IS_INTRA4x4(mb_type)) { @@ -1929,9 +2339,9 @@ static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, int mb_type, for (i = 0; i < 16; i++) if (h->non_zero_count_cache[scan8[i + p * 16]] || dctcoef_get(h->mb, pixel_shift, i * 16 + p * 256)) - s->dsp.add_pixels4(dest_y + block_offset[i], - h->mb + (i * 16 + p * 256 << pixel_shift), - linesize); + h->h264dsp.h264_add_pixels4_clear(dest_y + block_offset[i], + h->mb + (i * 16 + p * 256 << pixel_shift), + linesize); } } else { h->h264dsp.h264_idct_add16intra(dest_y, block_offset, @@ -1942,8 +2352,8 @@ static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, int mb_type, } else if (h->cbp & 15) { if (transform_bypass) { const int di = IS_8x8DCT(mb_type) ? 4 : 1; - idct_add = IS_8x8DCT(mb_type) ? s->dsp.add_pixels8 - : s->dsp.add_pixels4; + idct_add = IS_8x8DCT(mb_type) ? h->h264dsp.h264_add_pixels8_clear + : h->h264dsp.h264_add_pixels4_clear; for (i = 0; i < 16; i += di) if (h->non_zero_count_cache[scan8[i + p * 16]]) idct_add(dest_y + block_offset[i], @@ -1968,7 +2378,7 @@ static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, int mb_type, // FIXME benchmark weird rule, & below uint8_t *const ptr = dest_y + block_offset[i]; ff_svq3_add_idct_c(ptr, h->mb + i * 16 + p * 256, linesize, - s->qscale, IS_INTRA(mb_type) ? 1 : 0); + h->qscale, IS_INTRA(mb_type) ? 1 : 0); } } } @@ -1988,10 +2398,9 @@ static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, int mb_type, void ff_h264_hl_decode_mb(H264Context *h) { - MpegEncContext *const s = &h->s; const int mb_xy = h->mb_xy; - const int mb_type = s->current_picture.f.mb_type[mb_xy]; - int is_complex = CONFIG_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0; + const int mb_type = h->cur_pic.f.mb_type[mb_xy]; + int is_complex = CONFIG_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || h->qscale == 0; if (CHROMA444) { if (is_complex || h->pixel_shift) @@ -2008,15 +2417,14 @@ void ff_h264_hl_decode_mb(H264Context *h) static int pred_weight_table(H264Context *h) { - MpegEncContext *const s = &h->s; int list, i; int luma_def, chroma_def; h->use_weight = 0; h->use_weight_chroma = 0; - h->luma_log2_weight_denom = get_ue_golomb(&s->gb); + h->luma_log2_weight_denom = get_ue_golomb(&h->gb); if (h->sps.chroma_format_idc) - h->chroma_log2_weight_denom = get_ue_golomb(&s->gb); + h->chroma_log2_weight_denom = get_ue_golomb(&h->gb); luma_def = 1 << h->luma_log2_weight_denom; chroma_def = 1 << h->chroma_log2_weight_denom; @@ -2026,10 +2434,10 @@ static int pred_weight_table(H264Context *h) for (i = 0; i < h->ref_count[list]; i++) { int luma_weight_flag, chroma_weight_flag; - luma_weight_flag = get_bits1(&s->gb); + luma_weight_flag = get_bits1(&h->gb); if (luma_weight_flag) { - h->luma_weight[i][list][0] = get_se_golomb(&s->gb); - h->luma_weight[i][list][1] = get_se_golomb(&s->gb); + h->luma_weight[i][list][0] = get_se_golomb(&h->gb); + h->luma_weight[i][list][1] = get_se_golomb(&h->gb); if (h->luma_weight[i][list][0] != luma_def || h->luma_weight[i][list][1] != 0) { h->use_weight = 1; @@ -2041,12 +2449,12 @@ static int pred_weight_table(H264Context *h) } if (h->sps.chroma_format_idc) { - chroma_weight_flag = get_bits1(&s->gb); + chroma_weight_flag = get_bits1(&h->gb); if (chroma_weight_flag) { int j; for (j = 0; j < 2; j++) { - h->chroma_weight[i][list][j][0] = get_se_golomb(&s->gb); - h->chroma_weight[i][list][j][1] = get_se_golomb(&s->gb); + h->chroma_weight[i][list][j][0] = get_se_golomb(&h->gb); + h->chroma_weight[i][list][j][1] = get_se_golomb(&h->gb); if (h->chroma_weight[i][list][j][0] != chroma_def || h->chroma_weight[i][list][j][1] != 0) { h->use_weight_chroma = 1; @@ -2076,7 +2484,6 @@ static int pred_weight_table(H264Context *h) */ static void implicit_weight_table(H264Context *h, int field) { - MpegEncContext *const s = &h->s; int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1; for (i = 0; i < 2; i++) { @@ -2085,10 +2492,10 @@ static void implicit_weight_table(H264Context *h, int field) } if (field < 0) { - if (s->picture_structure == PICT_FRAME) { - cur_poc = s->current_picture_ptr->poc; + if (h->picture_structure == PICT_FRAME) { + cur_poc = h->cur_pic_ptr->poc; } else { - cur_poc = s->current_picture_ptr->field_poc[s->picture_structure - 1]; + cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure - 1]; } if (h->ref_count[0] == 1 && h->ref_count[1] == 1 && !FRAME_MBAFF && h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2 * cur_poc) { @@ -2100,7 +2507,7 @@ static void implicit_weight_table(H264Context *h, int field) ref_count0 = h->ref_count[0]; ref_count1 = h->ref_count[1]; } else { - cur_poc = s->current_picture_ptr->field_poc[field]; + cur_poc = h->cur_pic_ptr->field_poc[field]; ref_start = 16; ref_count0 = 16 + 2 * h->ref_count[0]; ref_count1 = 16 + 2 * h->ref_count[1]; @@ -2154,13 +2561,20 @@ static void idr(H264Context *h) /* forget old pics after a seek */ static void flush_change(H264Context *h) { + int i, j; + h->outputed_poc = h->next_outputed_poc = INT_MIN; h->prev_interlaced_frame = 1; idr(h); h->prev_frame_num = -1; - if (h->s.current_picture_ptr) - h->s.current_picture_ptr->f.reference = 0; - h->s.first_field = 0; + if (h->cur_pic_ptr) { + h->cur_pic_ptr->f.reference = 0; + for (j=i=0; h->delayed_pic[i]; i++) + if (h->delayed_pic[i] != h->cur_pic_ptr) + h->delayed_pic[j++] = h->delayed_pic[i]; + h->delayed_pic[j] = NULL; + } + h->first_field = 0; memset(h->ref_list[0], 0, sizeof(h->ref_list[0])); memset(h->ref_list[1], 0, sizeof(h->ref_list[1])); memset(h->default_ref_list[0], 0, sizeof(h->default_ref_list[0])); @@ -2185,15 +2599,28 @@ static void flush_dpb(AVCodecContext *avctx) } flush_change(h); - ff_mpeg_flush(avctx); + + for (i = 0; i < h->picture_count; i++) { + if (h->DPB[i].f.data[0]) + free_frame_buffer(h, &h->DPB[i]); + } + h->cur_pic_ptr = NULL; + + h->mb_x = h->mb_y = 0; + + h->parse_context.state = -1; + h->parse_context.frame_start_found = 0; + h->parse_context.overread = 0; + h->parse_context.overread_index = 0; + h->parse_context.index = 0; + h->parse_context.last_index = 0; } static int init_poc(H264Context *h) { - MpegEncContext *const s = &h->s; const int max_frame_num = 1 << h->sps.log2_max_frame_num; int field_poc[2]; - Picture *cur = s->current_picture_ptr; + Picture *cur = h->cur_pic_ptr; h->frame_num_offset = h->prev_frame_num_offset; if (h->frame_num < h->prev_frame_num) @@ -2210,7 +2637,7 @@ static int init_poc(H264Context *h) h->poc_msb = h->prev_poc_msb; field_poc[0] = field_poc[1] = h->poc_msb + h->poc_lsb; - if (s->picture_structure == PICT_FRAME) + if (h->picture_structure == PICT_FRAME) field_poc[1] += h->delta_poc_bottom; } else if (h->sps.poc_type == 1) { int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc; @@ -2245,7 +2672,7 @@ static int init_poc(H264Context *h) field_poc[0] = expectedpoc + h->delta_poc[0]; field_poc[1] = field_poc[0] + h->sps.offset_for_top_to_bottom_field; - if (s->picture_structure == PICT_FRAME) + if (h->picture_structure == PICT_FRAME) field_poc[1] += h->delta_poc[1]; } else { int poc = 2 * (h->frame_num_offset + h->frame_num); @@ -2257,10 +2684,10 @@ static int init_poc(H264Context *h) field_poc[1] = poc; } - if (s->picture_structure != PICT_BOTTOM_FIELD) - s->current_picture_ptr->field_poc[0] = field_poc[0]; - if (s->picture_structure != PICT_TOP_FIELD) - s->current_picture_ptr->field_poc[1] = field_poc[1]; + if (h->picture_structure != PICT_BOTTOM_FIELD) + h->cur_pic_ptr->field_poc[0] = field_poc[0]; + if (h->picture_structure != PICT_TOP_FIELD) + h->cur_pic_ptr->field_poc[1] = field_poc[1]; cur->poc = FFMIN(cur->field_poc[0], cur->field_poc[1]); return 0; @@ -2305,21 +2732,20 @@ static void init_scan_tables(H264Context *h) static int field_end(H264Context *h, int in_setup) { - MpegEncContext *const s = &h->s; - AVCodecContext *const avctx = s->avctx; + AVCodecContext *const avctx = h->avctx; int err = 0; - s->mb_y = 0; + h->mb_y = 0; - if (!in_setup && !s->droppable) - ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, - s->picture_structure == PICT_BOTTOM_FIELD); + if (!in_setup && !h->droppable) + ff_thread_report_progress(&h->cur_pic_ptr->f, INT_MAX, + h->picture_structure == PICT_BOTTOM_FIELD); if (CONFIG_H264_VDPAU_DECODER && - s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) - ff_vdpau_h264_set_reference_frames(s); + h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) + ff_vdpau_h264_set_reference_frames(h); if (in_setup || !(avctx->active_thread_type & FF_THREAD_FRAME)) { - if (!s->droppable) { + if (!h->droppable) { err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index); h->prev_poc_msb = h->poc_msb; h->prev_poc_lsb = h->poc_lsb; @@ -2336,8 +2762,8 @@ static int field_end(H264Context *h, int in_setup) } if (CONFIG_H264_VDPAU_DECODER && - s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) - ff_vdpau_h264_picture_complete(s); + h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) + ff_vdpau_h264_picture_complete(h); /* * FIXME: Error handling code does not seem to support interlaced @@ -2351,10 +2777,12 @@ static int field_end(H264Context *h, int in_setup) * past end by one (callers fault) and resync_mb_y != 0 * causes problems for the first MB line, too. */ - if (!FIELD_PICTURE && h->current_slice && !h->sps.new) - ff_er_frame_end(s); - - ff_MPV_frame_end(s); + if (CONFIG_ERROR_RESILIENCE && + !FIELD_PICTURE && h->current_slice && !h->sps.new) { + h->er.cur_pic = h->cur_pic_ptr; + ff_er_frame_end(&h->er); + } + emms_c(); h->current_slice = 0; @@ -2366,21 +2794,12 @@ static int field_end(H264Context *h, int in_setup) */ static int clone_slice(H264Context *dst, H264Context *src) { - int ret; - memcpy(dst->block_offset, src->block_offset, sizeof(dst->block_offset)); - dst->s.current_picture_ptr = src->s.current_picture_ptr; - dst->s.current_picture = src->s.current_picture; - dst->s.linesize = src->s.linesize; - dst->s.uvlinesize = src->s.uvlinesize; - dst->s.first_field = src->s.first_field; - - if (!dst->s.edge_emu_buffer && - (ret = ff_mpv_frame_size_alloc(&dst->s, dst->s.linesize))) { - av_log(dst->s.avctx, AV_LOG_ERROR, - "Failed to allocate scratch buffers\n"); - return ret; - } + dst->cur_pic_ptr = src->cur_pic_ptr; + dst->cur_pic = src->cur_pic; + dst->linesize = src->linesize; + dst->uvlinesize = src->uvlinesize; + dst->first_field = src->first_field; dst->prev_poc_msb = src->prev_poc_msb; dst->prev_poc_lsb = src->prev_poc_lsb; @@ -2391,7 +2810,6 @@ static int clone_slice(H264Context *dst, H264Context *src) memcpy(dst->short_ref, src->short_ref, sizeof(dst->short_ref)); memcpy(dst->long_ref, src->long_ref, sizeof(dst->long_ref)); memcpy(dst->default_ref_list, src->default_ref_list, sizeof(dst->default_ref_list)); - memcpy(dst->ref_list, src->ref_list, sizeof(dst->ref_list)); memcpy(dst->dequant4_coeff, src->dequant4_coeff, sizeof(src->dequant4_coeff)); memcpy(dst->dequant8_coeff, src->dequant8_coeff, sizeof(src->dequant8_coeff)); @@ -2428,52 +2846,54 @@ int ff_h264_get_profile(SPS *sps) static int h264_set_parameter_from_sps(H264Context *h) { - MpegEncContext *s = &h->s; - - if (s->flags & CODEC_FLAG_LOW_DELAY || + if (h->flags & CODEC_FLAG_LOW_DELAY || (h->sps.bitstream_restriction_flag && !h->sps.num_reorder_frames)) { - if (s->avctx->has_b_frames > 1 || h->delayed_pic[0]) - av_log(h->s.avctx, AV_LOG_WARNING, "Delayed frames seen. " + if (h->avctx->has_b_frames > 1 || h->delayed_pic[0]) + av_log(h->avctx, AV_LOG_WARNING, "Delayed frames seen. " "Reenabling low delay requires a codec flush.\n"); else - s->low_delay = 1; + h->low_delay = 1; } - if (s->avctx->has_b_frames < 2) - s->avctx->has_b_frames = !s->low_delay; + if (h->avctx->has_b_frames < 2) + h->avctx->has_b_frames = !h->low_delay; if (h->sps.bit_depth_luma != h->sps.bit_depth_chroma) { - av_log_missing_feature(s->avctx, + av_log_missing_feature(h->avctx, "Different bit depth between chroma and luma", 1); return AVERROR_PATCHWELCOME; } - if (s->avctx->bits_per_raw_sample != h->sps.bit_depth_luma || + if (h->avctx->bits_per_raw_sample != h->sps.bit_depth_luma || h->cur_chroma_format_idc != h->sps.chroma_format_idc) { - if (s->avctx->codec && - s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU && + if (h->avctx->codec && + h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU && (h->sps.bit_depth_luma != 8 || h->sps.chroma_format_idc > 1)) { - av_log(s->avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "VDPAU decoding does not support video colorspace.\n"); return AVERROR_INVALIDDATA; } if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 14 && h->sps.bit_depth_luma != 11 && h->sps.bit_depth_luma != 13 && (h->sps.bit_depth_luma != 9 || !CHROMA422)) { - s->avctx->bits_per_raw_sample = h->sps.bit_depth_luma; + h->avctx->bits_per_raw_sample = h->sps.bit_depth_luma; h->cur_chroma_format_idc = h->sps.chroma_format_idc; h->pixel_shift = h->sps.bit_depth_luma > 8; ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma, h->sps.chroma_format_idc); - ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma, + ff_h264chroma_init(&h->h264chroma, h->sps.bit_depth_chroma); + ff_h264qpel_init(&h->h264qpel, h->sps.bit_depth_luma); + ff_h264_pred_init(&h->hpc, h->avctx->codec_id, h->sps.bit_depth_luma, h->sps.chroma_format_idc); - s->dsp.dct_bits = h->sps.bit_depth_luma > 8 ? 32 : 16; - ff_dsputil_init(&s->dsp, s->avctx); - ff_videodsp_init(&s->vdsp, h->sps.bit_depth_luma); + if (CONFIG_ERROR_RESILIENCE) { + h->dsp.dct_bits = h->sps.bit_depth_luma > 8 ? 32 : 16; + ff_dsputil_init(&h->dsp, h->avctx); + } + ff_videodsp_init(&h->vdsp, h->sps.bit_depth_luma); } else { - av_log(s->avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", + av_log(h->avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", h->sps.bit_depth_luma); return AVERROR_INVALIDDATA; } @@ -2483,11 +2903,10 @@ static int h264_set_parameter_from_sps(H264Context *h) static enum PixelFormat get_pixel_format(H264Context *h, int force_callback) { - MpegEncContext *const s = &h->s; switch (h->sps.bit_depth_luma) { case 9: if (CHROMA444) { - if (s->avctx->colorspace == AVCOL_SPC_RGB) { + if (h->avctx->colorspace == AVCOL_SPC_RGB) { return AV_PIX_FMT_GBRP9; } else return AV_PIX_FMT_YUV444P9; @@ -2498,7 +2917,7 @@ static enum PixelFormat get_pixel_format(H264Context *h, int force_callback) break; case 10: if (CHROMA444) { - if (s->avctx->colorspace == AVCOL_SPC_RGB) { + if (h->avctx->colorspace == AVCOL_SPC_RGB) { return AV_PIX_FMT_GBRP10; } else return AV_PIX_FMT_YUV444P10; @@ -2509,7 +2928,7 @@ static enum PixelFormat get_pixel_format(H264Context *h, int force_callback) break; case 12: if (CHROMA444) { - if (s->avctx->colorspace == AVCOL_SPC_RGB) { + if (h->avctx->colorspace == AVCOL_SPC_RGB) { return AV_PIX_FMT_GBRP12; } else return AV_PIX_FMT_YUV444P12; @@ -2520,7 +2939,7 @@ static enum PixelFormat get_pixel_format(H264Context *h, int force_callback) break; case 14: if (CHROMA444) { - if (s->avctx->colorspace == AVCOL_SPC_RGB) { + if (h->avctx->colorspace == AVCOL_SPC_RGB) { return AV_PIX_FMT_GBRP14; } else return AV_PIX_FMT_YUV444P14; @@ -2531,33 +2950,33 @@ static enum PixelFormat get_pixel_format(H264Context *h, int force_callback) break; case 8: if (CHROMA444) { - if (s->avctx->colorspace == AVCOL_SPC_RGB) { - av_log(h->s.avctx, AV_LOG_DEBUG, "Detected GBR colorspace.\n"); + if (h->avctx->colorspace == AVCOL_SPC_RGB) { + av_log(h->avctx, AV_LOG_DEBUG, "Detected GBR colorspace.\n"); return AV_PIX_FMT_GBR24P; - } else if (s->avctx->colorspace == AVCOL_SPC_YCGCO) { - av_log(h->s.avctx, AV_LOG_WARNING, "Detected unsupported YCgCo colorspace.\n"); + } else if (h->avctx->colorspace == AVCOL_SPC_YCGCO) { + av_log(h->avctx, AV_LOG_WARNING, "Detected unsupported YCgCo colorspace.\n"); } - return s->avctx->color_range == AVCOL_RANGE_JPEG ? AV_PIX_FMT_YUVJ444P + return h->avctx->color_range == AVCOL_RANGE_JPEG ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P; } else if (CHROMA422) { - return s->avctx->color_range == AVCOL_RANGE_JPEG ? AV_PIX_FMT_YUVJ422P + return h->avctx->color_range == AVCOL_RANGE_JPEG ? AV_PIX_FMT_YUVJ422P : AV_PIX_FMT_YUV422P; } else { int i; - const enum AVPixelFormat * fmt = s->avctx->codec->pix_fmts ? - s->avctx->codec->pix_fmts : - s->avctx->color_range == AVCOL_RANGE_JPEG ? - hwaccel_pixfmt_list_h264_jpeg_420 : - ff_hwaccel_pixfmt_list_420; + const enum AVPixelFormat * fmt = h->avctx->codec->pix_fmts ? + h->avctx->codec->pix_fmts : + h->avctx->color_range == AVCOL_RANGE_JPEG ? + h264_hwaccel_pixfmt_list_jpeg_420 : + h264_hwaccel_pixfmt_list_420; for (i=0; fmt[i] != AV_PIX_FMT_NONE; i++) - if (fmt[i] == s->avctx->pix_fmt && !force_callback) + if (fmt[i] == h->avctx->pix_fmt && !force_callback) return fmt[i]; - return s->avctx->get_format(s->avctx, fmt); + return h->avctx->get_format(h->avctx, fmt); } break; default: - av_log(s->avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", h->sps.bit_depth_luma); return AVERROR_INVALIDDATA; } @@ -2565,85 +2984,117 @@ static enum PixelFormat get_pixel_format(H264Context *h, int force_callback) static int h264_slice_header_init(H264Context *h, int reinit) { - MpegEncContext *const s = &h->s; - int i, ret; + int nb_slices = (HAVE_THREADS && + h->avctx->active_thread_type & FF_THREAD_SLICE) ? + h->avctx->thread_count : 1; + int i; - if( FFALIGN(s->avctx->width , 16 ) == s->width - && FFALIGN(s->avctx->height, 16*(2 - h->sps.frame_mbs_only_flag)) == s->height + if( FFALIGN(h->avctx->width , 16 ) == h->width + && FFALIGN(h->avctx->height, 16*(2 - h->sps.frame_mbs_only_flag)) == h->height && !h->sps.crop_right && !h->sps.crop_bottom - && (s->avctx->width != s->width || s->avctx->height && s->height) + && (h->avctx->width != h->width || h->avctx->height && h->height) ) { - av_log(h->s.avctx, AV_LOG_DEBUG, "Using externally provided dimensions\n"); - s->avctx->coded_width = s->width; - s->avctx->coded_height = s->height; + av_log(h->avctx, AV_LOG_DEBUG, "Using externally provided dimensions\n"); + h->avctx->coded_width = h->width; + h->avctx->coded_height = h->height; } else{ - avcodec_set_dimensions(s->avctx, s->width, s->height); - s->avctx->width -= (2>>CHROMA444)*FFMIN(h->sps.crop_right, (8<avctx->height -= (1<chroma_y_shift)*FFMIN(h->sps.crop_bottom, (16>>s->chroma_y_shift)-1) * (2 - h->sps.frame_mbs_only_flag); + avcodec_set_dimensions(h->avctx, h->width, h->height); + h->avctx->width -= (2>>CHROMA444)*FFMIN(h->sps.crop_right, (8<avctx->height -= (1<chroma_y_shift)*FFMIN(h->sps.crop_bottom, (16>>h->chroma_y_shift)-1) * (2 - h->sps.frame_mbs_only_flag); } - s->avctx->sample_aspect_ratio = h->sps.sar; - av_assert0(s->avctx->sample_aspect_ratio.den); + h->avctx->sample_aspect_ratio = h->sps.sar; + av_assert0(h->avctx->sample_aspect_ratio.den); + av_pix_fmt_get_chroma_sub_sample(h->avctx->pix_fmt, + &h->chroma_x_shift, &h->chroma_y_shift); if (h->sps.timing_info_present_flag) { int64_t den = h->sps.time_scale; if (h->x264_build < 44U) den *= 2; - av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den, + av_reduce(&h->avctx->time_base.num, &h->avctx->time_base.den, h->sps.num_units_in_tick, den, 1 << 30); } - s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id, s->avctx->pix_fmt); + h->avctx->hwaccel = ff_find_hwaccel(h->avctx->codec->id, h->avctx->pix_fmt); - if (reinit) { + if (reinit) free_tables(h, 0); - if ((ret = ff_MPV_common_frame_size_change(s)) < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, "ff_MPV_common_frame_size_change() failed.\n"); - return ret; - } - } else { - if ((ret = ff_MPV_common_init(s)) < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, "ff_MPV_common_init() failed.\n"); - return ret; - } - } - s->first_field = 0; + h->first_field = 0; h->prev_interlaced_frame = 1; init_scan_tables(h); if (ff_h264_alloc_tables(h) < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "Could not allocate memory for h264\n"); return AVERROR(ENOMEM); } - if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_SLICE)) { + if (nb_slices > MAX_THREADS || (nb_slices > h->mb_height && h->mb_height)) { + int max_slices; + if (h->mb_height) + max_slices = FFMIN(MAX_THREADS, h->mb_height); + else + max_slices = MAX_THREADS; + av_log(h->avctx, AV_LOG_WARNING, "too many threads/slices (%d)," + " reducing to %d\n", nb_slices, max_slices); + nb_slices = max_slices; + } + h->slice_context_count = nb_slices; + + if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_SLICE)) { if (context_init(h) < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\n"); + av_log(h->avctx, AV_LOG_ERROR, "context_init() failed.\n"); return -1; } } else { - for (i = 1; i < s->slice_context_count; i++) { + for (i = 1; i < h->slice_context_count; i++) { H264Context *c; - c = h->thread_context[i] = av_malloc(sizeof(H264Context)); - memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext)); - memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext)); + c = h->thread_context[i] = av_mallocz(sizeof(H264Context)); + c->avctx = h->avctx; + if (CONFIG_ERROR_RESILIENCE) { + c->dsp = h->dsp; + } + c->vdsp = h->vdsp; c->h264dsp = h->h264dsp; + c->h264qpel = h->h264qpel; + c->h264chroma = h->h264chroma; c->sps = h->sps; c->pps = h->pps; c->pixel_shift = h->pixel_shift; c->cur_chroma_format_idc = h->cur_chroma_format_idc; + c->width = h->width; + c->height = h->height; + c->linesize = h->linesize; + c->uvlinesize = h->uvlinesize; + c->chroma_x_shift = h->chroma_x_shift; + c->chroma_y_shift = h->chroma_y_shift; + c->qscale = h->qscale; + c->droppable = h->droppable; + c->data_partitioning = h->data_partitioning; + c->low_delay = h->low_delay; + c->mb_width = h->mb_width; + c->mb_height = h->mb_height; + c->mb_stride = h->mb_stride; + c->mb_num = h->mb_num; + c->flags = h->flags; + c->workaround_bugs = h->workaround_bugs; + c->pict_type = h->pict_type; + init_scan_tables(c); clone_tables(c, h, i); + c->context_initialized = 1; } - for (i = 0; i < s->slice_context_count; i++) + for (i = 0; i < h->slice_context_count; i++) if (context_init(h->thread_context[i]) < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\n"); + av_log(h->avctx, AV_LOG_ERROR, "context_init() failed.\n"); return -1; } } + h->context_initialized = 1; + return 0; } @@ -2659,8 +3110,6 @@ static int h264_slice_header_init(H264Context *h, int reinit) */ static int decode_slice_header(H264Context *h, H264Context *h0) { - MpegEncContext *const s = &h->s; - MpegEncContext *const s0 = &h0->s; unsigned int first_mb_in_slice; unsigned int pps_id; int num_ref_idx_active_override_flag, ret; @@ -2670,17 +3119,10 @@ static int decode_slice_header(H264Context *h, H264Context *h0) int must_reinit; int needs_reinit = 0; - /* FIXME: 2tap qpel isn't implemented for high bit depth. */ - if ((s->avctx->flags2 & CODEC_FLAG2_FAST) && - !h->nal_ref_idc && !h->pixel_shift) { - s->me.qpel_put = s->dsp.put_2tap_qpel_pixels_tab; - s->me.qpel_avg = s->dsp.avg_2tap_qpel_pixels_tab; - } else { - s->me.qpel_put = s->dsp.put_h264_qpel_pixels_tab; - s->me.qpel_avg = s->dsp.avg_h264_qpel_pixels_tab; - } + h->me.qpel_put = h->h264qpel.put_h264_qpel_pixels_tab; + h->me.qpel_avg = h->h264qpel.avg_h264_qpel_pixels_tab; - first_mb_in_slice = get_ue_golomb_long(&s->gb); + first_mb_in_slice = get_ue_golomb_long(&h->gb); if (first_mb_in_slice == 0) { // FIXME better field boundary detection if (h0->current_slice && FIELD_PICTURE) { @@ -2688,21 +3130,21 @@ static int decode_slice_header(H264Context *h, H264Context *h0) } h0->current_slice = 0; - if (!s0->first_field) { - if (s->current_picture_ptr && !s->droppable && - s->current_picture_ptr->owner2 == s) { - ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, - s->picture_structure == PICT_BOTTOM_FIELD); + if (!h0->first_field) { + if (h->cur_pic_ptr && !h->droppable && + h->cur_pic_ptr->owner2 == h) { + ff_thread_report_progress(&h->cur_pic_ptr->f, INT_MAX, + h->picture_structure == PICT_BOTTOM_FIELD); } - s->current_picture_ptr = NULL; + h->cur_pic_ptr = NULL; } } - slice_type = get_ue_golomb_31(&s->gb); + slice_type = get_ue_golomb_31(&h->gb); if (slice_type > 9) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", - slice_type, s->mb_x, s->mb_y); + slice_type, h->mb_x, h->mb_y); return -1; } if (slice_type > 4) { @@ -2713,22 +3155,24 @@ static int decode_slice_header(H264Context *h, H264Context *h0) slice_type = golomb_to_pict_type[slice_type]; if (slice_type == AV_PICTURE_TYPE_I || - (h0->current_slice != 0 && slice_type == h0->last_slice_type)) { + (h0->current_slice != 0 && + slice_type == h0->last_slice_type && + !memcmp(h0->last_ref_count, h0->ref_count, sizeof(h0->ref_count)))) { default_ref_list_done = 1; } h->slice_type = slice_type; h->slice_type_nos = slice_type & 3; // to make a few old functions happy, it's wrong though - s->pict_type = h->slice_type; + h->pict_type = h->slice_type; - pps_id = get_ue_golomb(&s->gb); + pps_id = get_ue_golomb(&h->gb); if (pps_id >= MAX_PPS_COUNT) { - av_log(h->s.avctx, AV_LOG_ERROR, "pps_id %d out of range\n", pps_id); + av_log(h->avctx, AV_LOG_ERROR, "pps_id %d out of range\n", pps_id); return -1; } if (!h0->pps_buffers[pps_id]) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "non-existing PPS %u referenced\n", pps_id); return -1; @@ -2736,79 +3180,80 @@ static int decode_slice_header(H264Context *h, H264Context *h0) h->pps = *h0->pps_buffers[pps_id]; if (!h0->sps_buffers[h->pps.sps_id]) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\n", h->pps.sps_id); return -1; } if (h->pps.sps_id != h->current_sps_id || - h->context_reinitialized || h0->sps_buffers[h->pps.sps_id]->new) { - SPS *new_sps = h0->sps_buffers[h->pps.sps_id]; - h0->sps_buffers[h->pps.sps_id]->new = 0; - if (h->sps.chroma_format_idc != new_sps->chroma_format_idc || - h->sps.bit_depth_luma != new_sps->bit_depth_luma) - needs_reinit = 1; - h->current_sps_id = h->pps.sps_id; h->sps = *h0->sps_buffers[h->pps.sps_id]; - if (s->mb_width != h->sps.mb_width || - s->mb_height != h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag) || - s->avctx->bits_per_raw_sample != h->sps.bit_depth_luma || + if (h->mb_width != h->sps.mb_width || + h->mb_height != h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag) || + h->avctx->bits_per_raw_sample != h->sps.bit_depth_luma || h->cur_chroma_format_idc != h->sps.chroma_format_idc ) needs_reinit = 1; + if (h->bit_depth_luma != h->sps.bit_depth_luma || + h->chroma_format_idc != h->sps.chroma_format_idc) { + h->bit_depth_luma = h->sps.bit_depth_luma; + h->chroma_format_idc = h->sps.chroma_format_idc; + needs_reinit = 1; + } if ((ret = h264_set_parameter_from_sps(h)) < 0) return ret; } - s->avctx->profile = ff_h264_get_profile(&h->sps); - s->avctx->level = h->sps.level_idc; - s->avctx->refs = h->sps.ref_frame_count; + h->avctx->profile = ff_h264_get_profile(&h->sps); + h->avctx->level = h->sps.level_idc; + h->avctx->refs = h->sps.ref_frame_count; - must_reinit = (s->context_initialized && - ( 16*h->sps.mb_width != s->avctx->coded_width - || 16*h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag) != s->avctx->coded_height - || s->avctx->bits_per_raw_sample != h->sps.bit_depth_luma + must_reinit = (h->context_initialized && + ( 16*h->sps.mb_width != h->avctx->coded_width + || 16*h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag) != h->avctx->coded_height + || h->avctx->bits_per_raw_sample != h->sps.bit_depth_luma || h->cur_chroma_format_idc != h->sps.chroma_format_idc - || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))); - if (h0->s.avctx->pix_fmt != get_pixel_format(h0, 0)) + || av_cmp_q(h->sps.sar, h->avctx->sample_aspect_ratio))); + if (h0->avctx->pix_fmt != get_pixel_format(h0, 0)) must_reinit = 1; - s->mb_width = h->sps.mb_width; - s->mb_height = h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag); + h->mb_width = h->sps.mb_width; + h->mb_height = h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag); + h->mb_num = h->mb_width * h->mb_height; + h->mb_stride = h->mb_width + 1; - h->b_stride = s->mb_width * 4; + h->b_stride = h->mb_width * 4; - s->chroma_y_shift = h->sps.chroma_format_idc <= 1; // 400 uses yuv420p + h->chroma_y_shift = h->sps.chroma_format_idc <= 1; // 400 uses yuv420p - s->width = 16 * s->mb_width; - s->height = 16 * s->mb_height; + h->width = 16 * h->mb_width; + h->height = 16 * h->mb_height; if (h->sps.video_signal_type_present_flag) { - s->avctx->color_range = h->sps.full_range>0 ? AVCOL_RANGE_JPEG + h->avctx->color_range = h->sps.full_range>0 ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; if (h->sps.colour_description_present_flag) { - if (s->avctx->colorspace != h->sps.colorspace) + if (h->avctx->colorspace != h->sps.colorspace) needs_reinit = 1; - s->avctx->color_primaries = h->sps.color_primaries; - s->avctx->color_trc = h->sps.color_trc; - s->avctx->colorspace = h->sps.colorspace; + h->avctx->color_primaries = h->sps.color_primaries; + h->avctx->color_trc = h->sps.color_trc; + h->avctx->colorspace = h->sps.colorspace; } } - if (s->context_initialized && + if (h->context_initialized && ( needs_reinit || must_reinit)) { if (h != h0) { - av_log(s->avctx, AV_LOG_ERROR, "changing width/height on " + av_log(h->avctx, AV_LOG_ERROR, "changing width/height on " "slice %d\n", h0->current_slice + 1); return AVERROR_INVALIDDATA; } @@ -2817,31 +3262,30 @@ static int decode_slice_header(H264Context *h, H264Context *h0) if ((ret = get_pixel_format(h, 1)) < 0) return ret; - s->avctx->pix_fmt = ret; + h->avctx->pix_fmt = ret; - av_log(h->s.avctx, AV_LOG_INFO, "Reinit context to %dx%d, " - "pix_fmt: %d\n", s->width, s->height, s->avctx->pix_fmt); + av_log(h->avctx, AV_LOG_INFO, "Reinit context to %dx%d, " + "pix_fmt: %d\n", h->width, h->height, h->avctx->pix_fmt); if ((ret = h264_slice_header_init(h, 1)) < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed\n"); return ret; } - h->context_reinitialized = 1; } - if (!s->context_initialized) { + if (!h->context_initialized) { if (h != h0) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "Cannot (re-)initialize context during parallel decoding.\n"); return -1; } if ((ret = get_pixel_format(h, 1)) < 0) return ret; - s->avctx->pix_fmt = ret; + h->avctx->pix_fmt = ret; if ((ret = h264_slice_header_init(h, 0)) < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed\n"); return ret; } @@ -2852,41 +3296,41 @@ static int decode_slice_header(H264Context *h, H264Context *h0) init_dequant_tables(h); } - h->frame_num = get_bits(&s->gb, h->sps.log2_max_frame_num); + h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num); h->mb_mbaff = 0; h->mb_aff_frame = 0; - last_pic_structure = s0->picture_structure; - last_pic_droppable = s0->droppable; - s->droppable = h->nal_ref_idc == 0; + last_pic_structure = h0->picture_structure; + last_pic_droppable = h0->droppable; + h->droppable = h->nal_ref_idc == 0; if (h->sps.frame_mbs_only_flag) { - s->picture_structure = PICT_FRAME; + h->picture_structure = PICT_FRAME; } else { if (!h->sps.direct_8x8_inference_flag && slice_type == AV_PICTURE_TYPE_B) { - av_log(h->s.avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n"); + av_log(h->avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n"); return -1; } - if (get_bits1(&s->gb)) { // field_pic_flag - s->picture_structure = PICT_TOP_FIELD + get_bits1(&s->gb); // bottom_field_flag + if (get_bits1(&h->gb)) { // field_pic_flag + h->picture_structure = PICT_TOP_FIELD + get_bits1(&h->gb); // bottom_field_flag } else { - s->picture_structure = PICT_FRAME; + h->picture_structure = PICT_FRAME; h->mb_aff_frame = h->sps.mb_aff; } } - h->mb_field_decoding_flag = s->picture_structure != PICT_FRAME; + h->mb_field_decoding_flag = h->picture_structure != PICT_FRAME; if (h0->current_slice != 0) { - if (last_pic_structure != s->picture_structure || - last_pic_droppable != s->droppable) { - av_log(h->s.avctx, AV_LOG_ERROR, + if (last_pic_structure != h->picture_structure || + last_pic_droppable != h->droppable) { + av_log(h->avctx, AV_LOG_ERROR, "Changing field mode (%d -> %d) between slices is not allowed\n", - last_pic_structure, s->picture_structure); - s->picture_structure = last_pic_structure; - s->droppable = last_pic_droppable; + last_pic_structure, h->picture_structure); + h->picture_structure = last_pic_structure; + h->droppable = last_pic_droppable; return AVERROR_INVALIDDATA; - } else if (!s0->current_picture_ptr) { - av_log(s->avctx, AV_LOG_ERROR, - "unset current_picture_ptr on %d. slice\n", + } else if (!h0->cur_pic_ptr) { + av_log(h->avctx, AV_LOG_ERROR, + "unset cur_pic_ptr on %d. slice\n", h0->current_slice + 1); return AVERROR_INVALIDDATA; } @@ -2913,54 +3357,54 @@ static int decode_slice_header(H264Context *h, H264Context *h0) * Here, we're using that to see if we should mark previously * decode frames as "finished". * We have to do that before the "dummy" in-between frame allocation, - * since that can modify s->current_picture_ptr. */ - if (s0->first_field) { - assert(s0->current_picture_ptr); - assert(s0->current_picture_ptr->f.data[0]); - assert(s0->current_picture_ptr->f.reference != DELAYED_PIC_REF); + * since that can modify h->cur_pic_ptr. */ + if (h0->first_field) { + assert(h0->cur_pic_ptr); + assert(h0->cur_pic_ptr->f.data[0]); + assert(h0->cur_pic_ptr->f.reference != DELAYED_PIC_REF); /* Mark old field/frame as completed */ - if (!last_pic_droppable && s0->current_picture_ptr->owner2 == s0) { - ff_thread_report_progress(&s0->current_picture_ptr->f, INT_MAX, + if (!last_pic_droppable && h0->cur_pic_ptr->owner2 == h0) { + ff_thread_report_progress(&h0->cur_pic_ptr->f, INT_MAX, last_pic_structure == PICT_BOTTOM_FIELD); } /* figure out if we have a complementary field pair */ - if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) { + if (!FIELD_PICTURE || h->picture_structure == last_pic_structure) { /* Previous field is unmatched. Don't display it, but let it * remain for reference if marked as such. */ if (!last_pic_droppable && last_pic_structure != PICT_FRAME) { - ff_thread_report_progress(&s0->current_picture_ptr->f, INT_MAX, + ff_thread_report_progress(&h0->cur_pic_ptr->f, INT_MAX, last_pic_structure == PICT_TOP_FIELD); } } else { - if (s0->current_picture_ptr->frame_num != h->frame_num) { + if (h0->cur_pic_ptr->frame_num != h->frame_num) { /* This and previous field were reference, but had * different frame_nums. Consider this field first in * pair. Throw away previous field except for reference * purposes. */ if (!last_pic_droppable && last_pic_structure != PICT_FRAME) { - ff_thread_report_progress(&s0->current_picture_ptr->f, INT_MAX, + ff_thread_report_progress(&h0->cur_pic_ptr->f, INT_MAX, last_pic_structure == PICT_TOP_FIELD); } } else { /* Second field in complementary pair */ if (!((last_pic_structure == PICT_TOP_FIELD && - s->picture_structure == PICT_BOTTOM_FIELD) || + h->picture_structure == PICT_BOTTOM_FIELD) || (last_pic_structure == PICT_BOTTOM_FIELD && - s->picture_structure == PICT_TOP_FIELD))) { - av_log(s->avctx, AV_LOG_ERROR, + h->picture_structure == PICT_TOP_FIELD))) { + av_log(h->avctx, AV_LOG_ERROR, "Invalid field mode combination %d/%d\n", - last_pic_structure, s->picture_structure); - s->picture_structure = last_pic_structure; - s->droppable = last_pic_droppable; + last_pic_structure, h->picture_structure); + h->picture_structure = last_pic_structure; + h->droppable = last_pic_droppable; return AVERROR_INVALIDDATA; - } else if (last_pic_droppable != s->droppable) { - av_log(s->avctx, AV_LOG_ERROR, + } else if (last_pic_droppable != h->droppable) { + av_log(h->avctx, AV_LOG_ERROR, "Cannot combine reference and non-reference fields in the same frame\n"); - av_log_ask_for_sample(s->avctx, NULL); - s->picture_structure = last_pic_structure; - s->droppable = last_pic_droppable; + av_log_ask_for_sample(h->avctx, NULL); + h->picture_structure = last_pic_structure; + h->droppable = last_pic_droppable; return AVERROR_PATCHWELCOME; } @@ -2970,15 +3414,15 @@ static int decode_slice_header(H264Context *h, H264Context *h0) * on that first field (or if that was us, we just did that above). * By taking ownership, we assign responsibility to ourselves to * report progress on the second field. */ - s0->current_picture_ptr->owner2 = s0; + h0->cur_pic_ptr->owner2 = h0; } } } - while (h->frame_num != h->prev_frame_num && h->prev_frame_num >= 0 && !s0->first_field && + while (h->frame_num != h->prev_frame_num && h->prev_frame_num >= 0 && !h0->first_field && h->frame_num != (h->prev_frame_num + 1) % (1 << h->sps.log2_max_frame_num)) { Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL; - av_log(h->s.avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n", + av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n", h->frame_num, h->prev_frame_num); if (!h->sps.gaps_in_frame_num_allowed_flag) for(i=0; ilast_pocs); i++) @@ -2987,14 +3431,14 @@ static int decode_slice_header(H264Context *h, H264Context *h0) return -1; h->prev_frame_num++; h->prev_frame_num %= 1 << h->sps.log2_max_frame_num; - s->current_picture_ptr->frame_num = h->prev_frame_num; - ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 0); - ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 1); + h->cur_pic_ptr->frame_num = h->prev_frame_num; + ff_thread_report_progress(&h->cur_pic_ptr->f, INT_MAX, 0); + ff_thread_report_progress(&h->cur_pic_ptr->f, INT_MAX, 1); if ((ret = ff_generate_sliding_window_mmcos(h, 1)) < 0 && - s->avctx->err_recognition & AV_EF_EXPLODE) + h->avctx->err_recognition & AV_EF_EXPLODE) return ret; if (ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index) < 0 && - (s->avctx->err_recognition & AV_EF_EXPLODE)) + (h->avctx->err_recognition & AV_EF_EXPLODE)) return AVERROR_INVALIDDATA; /* Error concealment: if a ref is missing, copy the previous ref in its place. * FIXME: avoiding a memcpy would be nice, but ref handling makes many assumptions @@ -3006,7 +3450,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0) if (prev) { av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize, (const uint8_t **)prev->f.data, prev->f.linesize, - s->avctx->pix_fmt, s->mb_width * 16, s->mb_height * 16); + h->avctx->pix_fmt, h->mb_width * 16, h->mb_height * 16); h->short_ref[0]->poc = prev->poc + 2; } h->short_ref[0]->frame_num = h->prev_frame_num; @@ -3016,63 +3460,72 @@ static int decode_slice_header(H264Context *h, H264Context *h0) /* See if we have a decoded first field looking for a pair... * We're using that to see whether to continue decoding in that * frame, or to allocate a new one. */ - if (s0->first_field) { - assert(s0->current_picture_ptr); - assert(s0->current_picture_ptr->f.data[0]); - assert(s0->current_picture_ptr->f.reference != DELAYED_PIC_REF); + if (h0->first_field) { + assert(h0->cur_pic_ptr); + assert(h0->cur_pic_ptr->f.data[0]); + assert(h0->cur_pic_ptr->f.reference != DELAYED_PIC_REF); /* figure out if we have a complementary field pair */ - if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) { + if (!FIELD_PICTURE || h->picture_structure == last_pic_structure) { /* Previous field is unmatched. Don't display it, but let it * remain for reference if marked as such. */ - s0->current_picture_ptr = NULL; - s0->first_field = FIELD_PICTURE; + h0->cur_pic_ptr = NULL; + h0->first_field = FIELD_PICTURE; } else { - if (s0->current_picture_ptr->frame_num != h->frame_num) { - ff_thread_report_progress((AVFrame*)s0->current_picture_ptr, INT_MAX, - s0->picture_structure==PICT_BOTTOM_FIELD); + if (h0->cur_pic_ptr->frame_num != h->frame_num) { + ff_thread_report_progress((AVFrame*)h0->cur_pic_ptr, INT_MAX, + h0->picture_structure==PICT_BOTTOM_FIELD); /* This and the previous field had different frame_nums. * Consider this field first in pair. Throw away previous * one except for reference purposes. */ - s0->first_field = 1; - s0->current_picture_ptr = NULL; + h0->first_field = 1; + h0->cur_pic_ptr = NULL; } else { /* Second field in complementary pair */ - s0->first_field = 0; + h0->first_field = 0; } } } else { /* Frame or first field in a potentially complementary pair */ - s0->first_field = FIELD_PICTURE; + h0->first_field = FIELD_PICTURE; } - if (!FIELD_PICTURE || s0->first_field) { + if (!FIELD_PICTURE || h0->first_field) { if (ff_h264_frame_start(h) < 0) { - s0->first_field = 0; + h0->first_field = 0; return -1; } } else { - ff_release_unused_pictures(s, 0); + release_unused_pictures(h, 0); } } if (h != h0 && (ret = clone_slice(h, h0)) < 0) return ret; - s->current_picture_ptr->frame_num = h->frame_num; // FIXME frame_num cleanup + /* can't be in alloc_tables because linesize isn't known there. + * FIXME: redo bipred weight to not require extra buffer? */ + for (i = 0; i < h->slice_context_count; i++) + if (h->thread_context[i]) { + ret = alloc_scratch_buffers(h->thread_context[i], h->linesize); + if (ret < 0) + return ret; + } - av_assert1(s->mb_num == s->mb_width * s->mb_height); - if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num || - first_mb_in_slice >= s->mb_num) { - av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); + h->cur_pic_ptr->frame_num = h->frame_num; // FIXME frame_num cleanup + + av_assert1(h->mb_num == h->mb_width * h->mb_height); + if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= h->mb_num || + first_mb_in_slice >= h->mb_num) { + av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); return -1; } - s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width; - s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE; - if (s->picture_structure == PICT_BOTTOM_FIELD) - s->resync_mb_y = s->mb_y = s->mb_y + 1; - av_assert1(s->mb_y < s->mb_height); + h->resync_mb_x = h->mb_x = first_mb_in_slice % h->mb_width; + h->resync_mb_y = h->mb_y = (first_mb_in_slice / h->mb_width) << FIELD_OR_MBAFF_PICTURE; + if (h->picture_structure == PICT_BOTTOM_FIELD) + h->resync_mb_y = h->mb_y = h->mb_y + 1; + av_assert1(h->mb_y < h->mb_height); - if (s->picture_structure == PICT_FRAME) { + if (h->picture_structure == PICT_FRAME) { h->curr_pic_num = h->frame_num; h->max_pic_num = 1 << h->sps.log2_max_frame_num; } else { @@ -3081,26 +3534,26 @@ static int decode_slice_header(H264Context *h, H264Context *h0) } if (h->nal_unit_type == NAL_IDR_SLICE) - get_ue_golomb(&s->gb); /* idr_pic_id */ + get_ue_golomb(&h->gb); /* idr_pic_id */ if (h->sps.poc_type == 0) { - h->poc_lsb = get_bits(&s->gb, h->sps.log2_max_poc_lsb); + h->poc_lsb = get_bits(&h->gb, h->sps.log2_max_poc_lsb); - if (h->pps.pic_order_present == 1 && s->picture_structure == PICT_FRAME) - h->delta_poc_bottom = get_se_golomb(&s->gb); + if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME) + h->delta_poc_bottom = get_se_golomb(&h->gb); } if (h->sps.poc_type == 1 && !h->sps.delta_pic_order_always_zero_flag) { - h->delta_poc[0] = get_se_golomb(&s->gb); + h->delta_poc[0] = get_se_golomb(&h->gb); - if (h->pps.pic_order_present == 1 && s->picture_structure == PICT_FRAME) - h->delta_poc[1] = get_se_golomb(&s->gb); + if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME) + h->delta_poc[1] = get_se_golomb(&h->gb); } init_poc(h); if (h->pps.redundant_pic_cnt_present) - h->redundant_pic_count = get_ue_golomb(&s->gb); + h->redundant_pic_count = get_ue_golomb(&h->gb); // set defaults, might be overridden a few lines later h->ref_count[0] = h->pps.ref_count[0]; @@ -3108,23 +3561,23 @@ static int decode_slice_header(H264Context *h, H264Context *h0) if (h->slice_type_nos != AV_PICTURE_TYPE_I) { unsigned max[2]; - max[0] = max[1] = s->picture_structure == PICT_FRAME ? 15 : 31; + max[0] = max[1] = h->picture_structure == PICT_FRAME ? 15 : 31; if (h->slice_type_nos == AV_PICTURE_TYPE_B) - h->direct_spatial_mv_pred = get_bits1(&s->gb); - num_ref_idx_active_override_flag = get_bits1(&s->gb); + h->direct_spatial_mv_pred = get_bits1(&h->gb); + num_ref_idx_active_override_flag = get_bits1(&h->gb); if (num_ref_idx_active_override_flag) { - h->ref_count[0] = get_ue_golomb(&s->gb) + 1; + h->ref_count[0] = get_ue_golomb(&h->gb) + 1; if (h->slice_type_nos == AV_PICTURE_TYPE_B) { - h->ref_count[1] = get_ue_golomb(&s->gb) + 1; + h->ref_count[1] = get_ue_golomb(&h->gb) + 1; } else // full range is spec-ok in this case, even for frames h->ref_count[1] = 1; } if (h->ref_count[0]-1 > max[0] || h->ref_count[1]-1 > max[1]){ - av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow %u > %u or %u > %u\n", h->ref_count[0]-1, max[0], h->ref_count[1]-1, max[1]); + av_log(h->avctx, AV_LOG_ERROR, "reference overflow %u > %u or %u > %u\n", h->ref_count[0]-1, max[0], h->ref_count[1]-1, max[1]); h->ref_count[0] = h->ref_count[1] = 0; return AVERROR_INVALIDDATA; } @@ -3147,17 +3600,6 @@ static int decode_slice_header(H264Context *h, H264Context *h0) return -1; } - if (h->slice_type_nos != AV_PICTURE_TYPE_I) { - s->last_picture_ptr = &h->ref_list[0][0]; - s->last_picture_ptr->owner2 = s; - ff_copy_picture(&s->last_picture, s->last_picture_ptr); - } - if (h->slice_type_nos == AV_PICTURE_TYPE_B) { - s->next_picture_ptr = &h->ref_list[1][0]; - s->next_picture_ptr->owner2 = s; - ff_copy_picture(&s->next_picture, s->next_picture_ptr); - } - if ((h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P) || (h->pps.weighted_bipred_idc == 1 && h->slice_type_nos == AV_PICTURE_TYPE_B)) @@ -3179,10 +3621,10 @@ static int decode_slice_header(H264Context *h, H264Context *h0) // further down the line. This may break decoding if the first slice is // corrupt, thus we only do this if frame-mt is enabled. if (h->nal_ref_idc && - ff_h264_decode_ref_pic_marking(h0, &s->gb, - !(s->avctx->active_thread_type & FF_THREAD_FRAME) || + ff_h264_decode_ref_pic_marking(h0, &h->gb, + !(h->avctx->active_thread_type & FF_THREAD_FRAME) || h0->current_slice == 0) < 0 && - (s->avctx->err_recognition & AV_EF_EXPLODE)) + (h->avctx->err_recognition & AV_EF_EXPLODE)) return AVERROR_INVALIDDATA; if (FRAME_MBAFF) { @@ -3199,37 +3641,37 @@ static int decode_slice_header(H264Context *h, H264Context *h0) ff_h264_direct_ref_list_init(h); if (h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac) { - tmp = get_ue_golomb_31(&s->gb); + tmp = get_ue_golomb_31(&h->gb); if (tmp > 2) { - av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n"); + av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n"); return -1; } h->cabac_init_idc = tmp; } h->last_qscale_diff = 0; - tmp = h->pps.init_qp + get_se_golomb(&s->gb); + tmp = h->pps.init_qp + get_se_golomb(&h->gb); if (tmp > 51 + 6 * (h->sps.bit_depth_luma - 8)) { - av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp); + av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp); return -1; } - s->qscale = tmp; - h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); - h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); + h->qscale = tmp; + h->chroma_qp[0] = get_chroma_qp(h, 0, h->qscale); + h->chroma_qp[1] = get_chroma_qp(h, 1, h->qscale); // FIXME qscale / qp ... stuff if (h->slice_type == AV_PICTURE_TYPE_SP) - get_bits1(&s->gb); /* sp_for_switch_flag */ + get_bits1(&h->gb); /* sp_for_switch_flag */ if (h->slice_type == AV_PICTURE_TYPE_SP || h->slice_type == AV_PICTURE_TYPE_SI) - get_se_golomb(&s->gb); /* slice_qs_delta */ + get_se_golomb(&h->gb); /* slice_qs_delta */ h->deblocking_filter = 1; h->slice_alpha_c0_offset = 52; h->slice_beta_offset = 52; if (h->pps.deblocking_filter_parameters_present) { - tmp = get_ue_golomb_31(&s->gb); + tmp = get_ue_golomb_31(&h->gb); if (tmp > 2) { - av_log(s->avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\n", tmp); return -1; } @@ -3238,11 +3680,11 @@ static int decode_slice_header(H264Context *h, H264Context *h0) h->deblocking_filter ^= 1; // 1<->0 if (h->deblocking_filter) { - h->slice_alpha_c0_offset += get_se_golomb(&s->gb) << 1; - h->slice_beta_offset += get_se_golomb(&s->gb) << 1; + h->slice_alpha_c0_offset += get_se_golomb(&h->gb) << 1; + h->slice_beta_offset += get_se_golomb(&h->gb) << 1; if (h->slice_alpha_c0_offset > 104U || h->slice_beta_offset > 104U) { - av_log(s->avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "deblocking filter parameters %d %d out of range\n", h->slice_alpha_c0_offset, h->slice_beta_offset); return -1; @@ -3250,29 +3692,29 @@ static int decode_slice_header(H264Context *h, H264Context *h0) } } - if (s->avctx->skip_loop_filter >= AVDISCARD_ALL || - (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && + if (h->avctx->skip_loop_filter >= AVDISCARD_ALL || + (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type_nos != AV_PICTURE_TYPE_I) || - (s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && + (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type_nos == AV_PICTURE_TYPE_B) || - (s->avctx->skip_loop_filter >= AVDISCARD_NONREF && + (h->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) h->deblocking_filter = 0; if (h->deblocking_filter == 1 && h0->max_contexts > 1) { - if (s->avctx->flags2 & CODEC_FLAG2_FAST) { + if (h->avctx->flags2 & CODEC_FLAG2_FAST) { /* Cheat slightly for speed: * Do not bother to deblock across slices. */ h->deblocking_filter = 2; } else { h0->max_contexts = 1; if (!h0->single_decode_warning) { - av_log(s->avctx, AV_LOG_INFO, + av_log(h->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n"); h0->single_decode_warning = 1; } if (h != h0) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "Deblocking switched inside frame.\n"); return 1; } @@ -3286,15 +3728,16 @@ static int decode_slice_header(H264Context *h, H264Context *h0) 6 * (h->sps.bit_depth_luma - 8); h0->last_slice_type = slice_type; + memcpy(h0->last_ref_count, h0->ref_count, sizeof(h0->last_ref_count)); h->slice_num = ++h0->current_slice; if (h->slice_num) - h0->slice_row[(h->slice_num-1)&(MAX_SLICES-1)]= s->resync_mb_y; - if ( h0->slice_row[h->slice_num&(MAX_SLICES-1)] + 3 >= s->resync_mb_y - && h0->slice_row[h->slice_num&(MAX_SLICES-1)] <= s->resync_mb_y + h0->slice_row[(h->slice_num-1)&(MAX_SLICES-1)]= h->resync_mb_y; + if ( h0->slice_row[h->slice_num&(MAX_SLICES-1)] + 3 >= h->resync_mb_y + && h0->slice_row[h->slice_num&(MAX_SLICES-1)] <= h->resync_mb_y && h->slice_num >= MAX_SLICES) { //in case of ASO this check needs to be updated depending on how we decide to assign slice numbers in this case - av_log(s->avctx, AV_LOG_WARNING, "Possibly too many slices (%d >= %d), increase MAX_SLICES and recompile if there are artifacts\n", h->slice_num, MAX_SLICES); + av_log(h->avctx, AV_LOG_WARNING, "Possibly too many slices (%d >= %d), increase MAX_SLICES and recompile if there are artifacts\n", h->slice_num, MAX_SLICES); } for (j = 0; j < 2; j++) { @@ -3330,27 +3773,23 @@ static int decode_slice_header(H264Context *h, H264Context *h0) (h->ref_list[j][i].f.reference & 3); } - // FIXME: fix draw_edges + PAFF + frame threads - h->emu_edge_width = (s->flags & CODEC_FLAG_EMU_EDGE || - (!h->sps.frame_mbs_only_flag && - s->avctx->active_thread_type)) - ? 0 : 16; - h->emu_edge_height = (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width; + if (h->ref_count[0]) h->er.last_pic = &h->ref_list[0][0]; + if (h->ref_count[1]) h->er.next_pic = &h->ref_list[1][0]; - if (s->avctx->debug & FF_DEBUG_PICT_INFO) { - av_log(h->s.avctx, AV_LOG_DEBUG, + if (h->avctx->debug & FF_DEBUG_PICT_INFO) { + av_log(h->avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n", h->slice_num, - (s->picture_structure == PICT_FRAME ? "F" : s->picture_structure == PICT_TOP_FIELD ? "T" : "B"), + (h->picture_structure == PICT_FRAME ? "F" : h->picture_structure == PICT_TOP_FIELD ? "T" : "B"), first_mb_in_slice, av_get_picture_type_char(h->slice_type), h->slice_type_fixed ? " fix" : "", h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "", pps_id, h->frame_num, - s->current_picture_ptr->field_poc[0], - s->current_picture_ptr->field_poc[1], + h->cur_pic_ptr->field_poc[0], + h->cur_pic_ptr->field_poc[1], h->ref_count[0], h->ref_count[1], - s->qscale, + h->qscale, h->deblocking_filter, h->slice_alpha_c0_offset / 2 - 26, h->slice_beta_offset / 2 - 26, h->use_weight, @@ -3380,7 +3819,6 @@ int ff_h264_get_slice_type(const H264Context *h) } static av_always_inline void fill_filter_caches_inter(H264Context *h, - MpegEncContext *const s, int mb_type, int top_xy, int left_xy[LEFT_MBS], int top_type, @@ -3395,11 +3833,11 @@ static av_always_inline void fill_filter_caches_inter(H264Context *h, const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride; const int b8_xy = 4 * top_xy + 2; int (*ref2frm)[64] = (void*)(h->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][0] + (MB_MBAFF ? 20 : 2)); - AV_COPY128(mv_dst - 1 * 8, s->current_picture.f.motion_val[list][b_xy + 0]); + AV_COPY128(mv_dst - 1 * 8, h->cur_pic.f.motion_val[list][b_xy + 0]); ref_cache[0 - 1 * 8] = - ref_cache[1 - 1 * 8] = ref2frm[list][s->current_picture.f.ref_index[list][b8_xy + 0]]; + ref_cache[1 - 1 * 8] = ref2frm[list][h->cur_pic.f.ref_index[list][b8_xy + 0]]; ref_cache[2 - 1 * 8] = - ref_cache[3 - 1 * 8] = ref2frm[list][s->current_picture.f.ref_index[list][b8_xy + 1]]; + ref_cache[3 - 1 * 8] = ref2frm[list][h->cur_pic.f.ref_index[list][b8_xy + 1]]; } else { AV_ZERO128(mv_dst - 1 * 8); AV_WN32A(&ref_cache[0 - 1 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); @@ -3410,14 +3848,14 @@ static av_always_inline void fill_filter_caches_inter(H264Context *h, const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3; const int b8_xy = 4 * left_xy[LTOP] + 1; int (*ref2frm)[64] =(void*)( h->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][0] + (MB_MBAFF ? 20 : 2)); - AV_COPY32(mv_dst - 1 + 0, s->current_picture.f.motion_val[list][b_xy + b_stride * 0]); - AV_COPY32(mv_dst - 1 + 8, s->current_picture.f.motion_val[list][b_xy + b_stride * 1]); - AV_COPY32(mv_dst - 1 + 16, s->current_picture.f.motion_val[list][b_xy + b_stride * 2]); - AV_COPY32(mv_dst - 1 + 24, s->current_picture.f.motion_val[list][b_xy + b_stride * 3]); + AV_COPY32(mv_dst - 1 + 0, h->cur_pic.f.motion_val[list][b_xy + b_stride * 0]); + AV_COPY32(mv_dst - 1 + 8, h->cur_pic.f.motion_val[list][b_xy + b_stride * 1]); + AV_COPY32(mv_dst - 1 + 16, h->cur_pic.f.motion_val[list][b_xy + b_stride * 2]); + AV_COPY32(mv_dst - 1 + 24, h->cur_pic.f.motion_val[list][b_xy + b_stride * 3]); ref_cache[-1 + 0] = - ref_cache[-1 + 8] = ref2frm[list][s->current_picture.f.ref_index[list][b8_xy + 2 * 0]]; + ref_cache[-1 + 8] = ref2frm[list][h->cur_pic.f.ref_index[list][b8_xy + 2 * 0]]; ref_cache[-1 + 16] = - ref_cache[-1 + 24] = ref2frm[list][s->current_picture.f.ref_index[list][b8_xy + 2 * 1]]; + ref_cache[-1 + 24] = ref2frm[list][h->cur_pic.f.ref_index[list][b8_xy + 2 * 1]]; } else { AV_ZERO32(mv_dst - 1 + 0); AV_ZERO32(mv_dst - 1 + 8); @@ -3441,7 +3879,7 @@ static av_always_inline void fill_filter_caches_inter(H264Context *h, } { - int8_t *ref = &s->current_picture.f.ref_index[list][4 * mb_xy]; + int8_t *ref = &h->cur_pic.f.ref_index[list][4 * mb_xy]; int (*ref2frm)[64] = (void*)(h->ref2frm[h->slice_num & (MAX_SLICES - 1)][0] + (MB_MBAFF ? 20 : 2)); uint32_t ref01 = (pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101; uint32_t ref23 = (pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101; @@ -3452,7 +3890,7 @@ static av_always_inline void fill_filter_caches_inter(H264Context *h, } { - int16_t(*mv_src)[2] = &s->current_picture.f.motion_val[list][4 * s->mb_x + 4 * s->mb_y * b_stride]; + int16_t(*mv_src)[2] = &h->cur_pic.f.motion_val[list][4 * h->mb_x + 4 * h->mb_y * b_stride]; AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride); AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride); AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride); @@ -3466,31 +3904,30 @@ static av_always_inline void fill_filter_caches_inter(H264Context *h, */ static int fill_filter_caches(H264Context *h, int mb_type) { - MpegEncContext *const s = &h->s; const int mb_xy = h->mb_xy; int top_xy, left_xy[LEFT_MBS]; int top_type, left_type[LEFT_MBS]; uint8_t *nnz; uint8_t *nnz_cache; - top_xy = mb_xy - (s->mb_stride << MB_FIELD); + top_xy = mb_xy - (h->mb_stride << MB_FIELD); /* Wow, what a mess, why didn't they simplify the interlacing & intra * stuff, I can't imagine that these complex rules are worth it. */ left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1; if (FRAME_MBAFF) { - const int left_mb_field_flag = IS_INTERLACED(s->current_picture.f.mb_type[mb_xy - 1]); + const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.f.mb_type[mb_xy - 1]); const int curr_mb_field_flag = IS_INTERLACED(mb_type); - if (s->mb_y & 1) { + if (h->mb_y & 1) { if (left_mb_field_flag != curr_mb_field_flag) - left_xy[LTOP] -= s->mb_stride; + left_xy[LTOP] -= h->mb_stride; } else { if (curr_mb_field_flag) - top_xy += s->mb_stride & - (((s->current_picture.f.mb_type[top_xy] >> 7) & 1) - 1); + top_xy += h->mb_stride & + (((h->cur_pic.f.mb_type[top_xy] >> 7) & 1) - 1); if (left_mb_field_flag != curr_mb_field_flag) - left_xy[LBOT] += s->mb_stride; + left_xy[LBOT] += h->mb_stride; } } @@ -3502,25 +3939,25 @@ static int fill_filter_caches(H264Context *h, int mb_type) * This is a conservative estimate: could also check beta_offset * and more accurate chroma_qp. */ int qp_thresh = h->qp_thresh; // FIXME strictly we should store qp_thresh for each mb of a slice - int qp = s->current_picture.f.qscale_table[mb_xy]; + int qp = h->cur_pic.f.qscale_table[mb_xy]; if (qp <= qp_thresh && (left_xy[LTOP] < 0 || - ((qp + s->current_picture.f.qscale_table[left_xy[LTOP]] + 1) >> 1) <= qp_thresh) && + ((qp + h->cur_pic.f.qscale_table[left_xy[LTOP]] + 1) >> 1) <= qp_thresh) && (top_xy < 0 || - ((qp + s->current_picture.f.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) { + ((qp + h->cur_pic.f.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) { if (!FRAME_MBAFF) return 1; if ((left_xy[LTOP] < 0 || - ((qp + s->current_picture.f.qscale_table[left_xy[LBOT]] + 1) >> 1) <= qp_thresh) && - (top_xy < s->mb_stride || - ((qp + s->current_picture.f.qscale_table[top_xy - s->mb_stride] + 1) >> 1) <= qp_thresh)) + ((qp + h->cur_pic.f.qscale_table[left_xy[LBOT]] + 1) >> 1) <= qp_thresh) && + (top_xy < h->mb_stride || + ((qp + h->cur_pic.f.qscale_table[top_xy - h->mb_stride] + 1) >> 1) <= qp_thresh)) return 1; } } - top_type = s->current_picture.f.mb_type[top_xy]; - left_type[LTOP] = s->current_picture.f.mb_type[left_xy[LTOP]]; - left_type[LBOT] = s->current_picture.f.mb_type[left_xy[LBOT]]; + top_type = h->cur_pic.f.mb_type[top_xy]; + left_type[LTOP] = h->cur_pic.f.mb_type[left_xy[LTOP]]; + left_type[LBOT] = h->cur_pic.f.mb_type[left_xy[LBOT]]; if (h->deblocking_filter == 2) { if (h->slice_table[top_xy] != h->slice_num) top_type = 0; @@ -3539,10 +3976,10 @@ static int fill_filter_caches(H264Context *h, int mb_type) if (IS_INTRA(mb_type)) return 0; - fill_filter_caches_inter(h, s, mb_type, top_xy, left_xy, + fill_filter_caches_inter(h, mb_type, top_xy, left_xy, top_type, left_type, mb_xy, 0); if (h->list_count == 2) - fill_filter_caches_inter(h, s, mb_type, top_xy, left_xy, + fill_filter_caches_inter(h, mb_type, top_xy, left_xy, top_type, left_type, mb_xy, 1); nnz = h->non_zero_count[mb_xy]; @@ -3612,57 +4049,56 @@ static int fill_filter_caches(H264Context *h, int mb_type) static void loop_filter(H264Context *h, int start_x, int end_x) { - MpegEncContext *const s = &h->s; uint8_t *dest_y, *dest_cb, *dest_cr; int linesize, uvlinesize, mb_x, mb_y; - const int end_mb_y = s->mb_y + FRAME_MBAFF; + const int end_mb_y = h->mb_y + FRAME_MBAFF; const int old_slice_type = h->slice_type; const int pixel_shift = h->pixel_shift; - const int block_h = 16 >> s->chroma_y_shift; + const int block_h = 16 >> h->chroma_y_shift; if (h->deblocking_filter) { for (mb_x = start_x; mb_x < end_x; mb_x++) for (mb_y = end_mb_y - FRAME_MBAFF; mb_y <= end_mb_y; mb_y++) { int mb_xy, mb_type; - mb_xy = h->mb_xy = mb_x + mb_y * s->mb_stride; + mb_xy = h->mb_xy = mb_x + mb_y * h->mb_stride; h->slice_num = h->slice_table[mb_xy]; - mb_type = s->current_picture.f.mb_type[mb_xy]; + mb_type = h->cur_pic.f.mb_type[mb_xy]; h->list_count = h->list_counts[mb_xy]; if (FRAME_MBAFF) h->mb_mbaff = h->mb_field_decoding_flag = !!IS_INTERLACED(mb_type); - s->mb_x = mb_x; - s->mb_y = mb_y; - dest_y = s->current_picture.f.data[0] + - ((mb_x << pixel_shift) + mb_y * s->linesize) * 16; - dest_cb = s->current_picture.f.data[1] + + h->mb_x = mb_x; + h->mb_y = mb_y; + dest_y = h->cur_pic.f.data[0] + + ((mb_x << pixel_shift) + mb_y * h->linesize) * 16; + dest_cb = h->cur_pic.f.data[1] + (mb_x << pixel_shift) * (8 << CHROMA444) + - mb_y * s->uvlinesize * block_h; - dest_cr = s->current_picture.f.data[2] + + mb_y * h->uvlinesize * block_h; + dest_cr = h->cur_pic.f.data[2] + (mb_x << pixel_shift) * (8 << CHROMA444) + - mb_y * s->uvlinesize * block_h; + mb_y * h->uvlinesize * block_h; // FIXME simplify above if (MB_FIELD) { - linesize = h->mb_linesize = s->linesize * 2; - uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2; + linesize = h->mb_linesize = h->linesize * 2; + uvlinesize = h->mb_uvlinesize = h->uvlinesize * 2; if (mb_y & 1) { // FIXME move out of this function? - dest_y -= s->linesize * 15; - dest_cb -= s->uvlinesize * (block_h - 1); - dest_cr -= s->uvlinesize * (block_h - 1); + dest_y -= h->linesize * 15; + dest_cb -= h->uvlinesize * (block_h - 1); + dest_cr -= h->uvlinesize * (block_h - 1); } } else { - linesize = h->mb_linesize = s->linesize; - uvlinesize = h->mb_uvlinesize = s->uvlinesize; + linesize = h->mb_linesize = h->linesize; + uvlinesize = h->mb_uvlinesize = h->uvlinesize; } backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0); if (fill_filter_caches(h, mb_type)) continue; - h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mb_xy]); - h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mb_xy]); + h->chroma_qp[0] = get_chroma_qp(h, 0, h->cur_pic.f.qscale_table[mb_xy]); + h->chroma_qp[1] = get_chroma_qp(h, 1, h->cur_pic.f.qscale_table[mb_xy]); if (FRAME_MBAFF) { ff_h264_filter_mb(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, @@ -3674,20 +4110,19 @@ static void loop_filter(H264Context *h, int start_x, int end_x) } } h->slice_type = old_slice_type; - s->mb_x = end_x; - s->mb_y = end_mb_y - FRAME_MBAFF; - h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); - h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); + h->mb_x = end_x; + h->mb_y = end_mb_y - FRAME_MBAFF; + h->chroma_qp[0] = get_chroma_qp(h, 0, h->qscale); + h->chroma_qp[1] = get_chroma_qp(h, 1, h->qscale); } static void predict_field_decoding_flag(H264Context *h) { - MpegEncContext *const s = &h->s; - const int mb_xy = s->mb_x + s->mb_y * s->mb_stride; + const int mb_xy = h->mb_x + h->mb_y * h->mb_stride; int mb_type = (h->slice_table[mb_xy - 1] == h->slice_num) ? - s->current_picture.f.mb_type[mb_xy - 1] : - (h->slice_table[mb_xy - s->mb_stride] == h->slice_num) ? - s->current_picture.f.mb_type[mb_xy - s->mb_stride] : 0; + h->cur_pic.f.mb_type[mb_xy - 1] : + (h->slice_table[mb_xy - h->mb_stride] == h->slice_num) ? + h->cur_pic.f.mb_type[mb_xy - h->mb_stride] : 0; h->mb_mbaff = h->mb_field_decoding_flag = IS_INTERLACED(mb_type) ? 1 : 0; } @@ -3696,9 +4131,8 @@ static void predict_field_decoding_flag(H264Context *h) */ static void decode_finish_row(H264Context *h) { - MpegEncContext *const s = &h->s; - int top = 16 * (s->mb_y >> FIELD_PICTURE); - int pic_height = 16 * s->mb_height >> FIELD_PICTURE; + int top = 16 * (h->mb_y >> FIELD_PICTURE); + int pic_height = 16 * h->mb_height >> FIELD_PICTURE; int height = 16 << FRAME_MBAFF; int deblock_border = (16 + 4) << FRAME_MBAFF; @@ -3708,46 +4142,56 @@ static void decode_finish_row(H264Context *h) top -= deblock_border; } - if (top >= pic_height || (top + height) < h->emu_edge_height) + if (top >= pic_height || (top + height) < 0) return; height = FFMIN(height, pic_height - top); - if (top < h->emu_edge_height) { + if (top < 0) { height = top + height; top = 0; } - ff_draw_horiz_band(s, top, height); + ff_h264_draw_horiz_band(h, top, height); - if (s->droppable) + if (h->droppable) return; - ff_thread_report_progress(&s->current_picture_ptr->f, top + height - 1, - s->picture_structure == PICT_BOTTOM_FIELD); + ff_thread_report_progress(&h->cur_pic_ptr->f, top + height - 1, + h->picture_structure == PICT_BOTTOM_FIELD); +} + +static void er_add_slice(H264Context *h, int startx, int starty, + int endx, int endy, int status) +{ + if (CONFIG_ERROR_RESILIENCE) { + ERContext *er = &h->er; + + er->ref_count = h->ref_count[0]; + ff_er_add_slice(er, startx, starty, endx, endy, status); + } } static int decode_slice(struct AVCodecContext *avctx, void *arg) { H264Context *h = *(void **)arg; - MpegEncContext *const s = &h->s; - const int part_mask = s->partitioned_frame ? (ER_AC_END | ER_AC_ERROR) - : 0x7F; - int lf_x_start = s->mb_x; + int lf_x_start = h->mb_x; + + h->mb_skip_run = -1; - s->mb_skip_run = -1; + av_assert0(h->block_offset[15] == (4 * ((scan8[15] - scan8[0]) & 7) << h->pixel_shift) + 4 * h->linesize * ((scan8[15] - scan8[0]) >> 3)); - h->is_complex = FRAME_MBAFF || s->picture_structure != PICT_FRAME || - s->codec_id != AV_CODEC_ID_H264 || - (CONFIG_GRAY && (s->flags & CODEC_FLAG_GRAY)); + h->is_complex = FRAME_MBAFF || h->picture_structure != PICT_FRAME || + avctx->codec_id != AV_CODEC_ID_H264 || + (CONFIG_GRAY && (h->flags & CODEC_FLAG_GRAY)); if (h->pps.cabac) { /* realign */ - align_get_bits(&s->gb); + align_get_bits(&h->gb); /* init cabac */ ff_init_cabac_decoder(&h->cabac, - s->gb.buffer + get_bits_count(&s->gb) / 8, - (get_bits_left(&s->gb) + 7) / 8); + h->gb.buffer + get_bits_count(&h->gb) / 8, + (get_bits_left(&h->gb) + 7) / 8); ff_h264_init_cabac_states(h); @@ -3762,55 +4206,55 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) // FIXME optimal? or let mb_decode decode 16x32 ? if (ret >= 0 && FRAME_MBAFF) { - s->mb_y++; + h->mb_y++; ret = ff_h264_decode_mb_cabac(h); if (ret >= 0) ff_h264_hl_decode_mb(h); - s->mb_y--; + h->mb_y--; } eos = get_cabac_terminate(&h->cabac); - if ((s->workaround_bugs & FF_BUG_TRUNCATED) && + if ((h->workaround_bugs & FF_BUG_TRUNCATED) && h->cabac.bytestream > h->cabac.bytestream_end + 2) { - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x - 1, - s->mb_y, ER_MB_END & part_mask); - if (s->mb_x >= lf_x_start) - loop_filter(h, lf_x_start, s->mb_x + 1); + er_add_slice(h, h->resync_mb_x, h->resync_mb_y, h->mb_x - 1, + h->mb_y, ER_MB_END); + if (h->mb_x >= lf_x_start) + loop_filter(h, lf_x_start, h->mb_x + 1); return 0; } if (h->cabac.bytestream > h->cabac.bytestream_end + 2 ) - av_log(h->s.avctx, AV_LOG_DEBUG, "bytestream overread %td\n", h->cabac.bytestream_end - h->cabac.bytestream); + av_log(h->avctx, AV_LOG_DEBUG, "bytestream overread %td\n", h->cabac.bytestream_end - h->cabac.bytestream); if (ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 4) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\n", - s->mb_x, s->mb_y, + h->mb_x, h->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, - s->mb_y, ER_MB_ERROR & part_mask); + er_add_slice(h, h->resync_mb_x, h->resync_mb_y, h->mb_x, + h->mb_y, ER_MB_ERROR); return -1; } - if (++s->mb_x >= s->mb_width) { - loop_filter(h, lf_x_start, s->mb_x); - s->mb_x = lf_x_start = 0; + if (++h->mb_x >= h->mb_width) { + loop_filter(h, lf_x_start, h->mb_x); + h->mb_x = lf_x_start = 0; decode_finish_row(h); - ++s->mb_y; + ++h->mb_y; if (FIELD_OR_MBAFF_PICTURE) { - ++s->mb_y; - if (FRAME_MBAFF && s->mb_y < s->mb_height) + ++h->mb_y; + if (FRAME_MBAFF && h->mb_y < h->mb_height) predict_field_decoding_flag(h); } } - if (eos || s->mb_y >= s->mb_height) { - tprintf(s->avctx, "slice end %d %d\n", - get_bits_count(&s->gb), s->gb.size_in_bits); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x - 1, - s->mb_y, ER_MB_END & part_mask); - if (s->mb_x > lf_x_start) - loop_filter(h, lf_x_start, s->mb_x); + if (eos || h->mb_y >= h->mb_height) { + tprintf(h->avctx, "slice end %d %d\n", + get_bits_count(&h->gb), h->gb.size_in_bits); + er_add_slice(h, h->resync_mb_x, h->resync_mb_y, h->mb_x - 1, + h->mb_y, ER_MB_END); + if (h->mb_x > lf_x_start) + loop_filter(h, lf_x_start, h->mb_x); return 0; } } @@ -3823,67 +4267,67 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) // FIXME optimal? or let mb_decode decode 16x32 ? if (ret >= 0 && FRAME_MBAFF) { - s->mb_y++; + h->mb_y++; ret = ff_h264_decode_mb_cavlc(h); if (ret >= 0) ff_h264_hl_decode_mb(h); - s->mb_y--; + h->mb_y--; } if (ret < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, - "error while decoding MB %d %d\n", s->mb_x, s->mb_y); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, - s->mb_y, ER_MB_ERROR & part_mask); + av_log(h->avctx, AV_LOG_ERROR, + "error while decoding MB %d %d\n", h->mb_x, h->mb_y); + er_add_slice(h, h->resync_mb_x, h->resync_mb_y, h->mb_x, + h->mb_y, ER_MB_ERROR); return -1; } - if (++s->mb_x >= s->mb_width) { - loop_filter(h, lf_x_start, s->mb_x); - s->mb_x = lf_x_start = 0; + if (++h->mb_x >= h->mb_width) { + loop_filter(h, lf_x_start, h->mb_x); + h->mb_x = lf_x_start = 0; decode_finish_row(h); - ++s->mb_y; + ++h->mb_y; if (FIELD_OR_MBAFF_PICTURE) { - ++s->mb_y; - if (FRAME_MBAFF && s->mb_y < s->mb_height) + ++h->mb_y; + if (FRAME_MBAFF && h->mb_y < h->mb_height) predict_field_decoding_flag(h); } - if (s->mb_y >= s->mb_height) { - tprintf(s->avctx, "slice end %d %d\n", - get_bits_count(&s->gb), s->gb.size_in_bits); + if (h->mb_y >= h->mb_height) { + tprintf(h->avctx, "slice end %d %d\n", + get_bits_count(&h->gb), h->gb.size_in_bits); - if ( get_bits_left(&s->gb) == 0 - || get_bits_left(&s->gb) > 0 && !(s->avctx->err_recognition & AV_EF_AGGRESSIVE)) { - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, - s->mb_x - 1, s->mb_y, - ER_MB_END & part_mask); + if ( get_bits_left(&h->gb) == 0 + || get_bits_left(&h->gb) > 0 && !(h->avctx->err_recognition & AV_EF_AGGRESSIVE)) { + er_add_slice(h, h->resync_mb_x, h->resync_mb_y, + h->mb_x - 1, h->mb_y, + ER_MB_END); return 0; } else { - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, - s->mb_x, s->mb_y, - ER_MB_END & part_mask); + er_add_slice(h, h->resync_mb_x, h->resync_mb_y, + h->mb_x, h->mb_y, + ER_MB_END); return -1; } } } - if (get_bits_left(&s->gb) <= 0 && s->mb_skip_run <= 0) { - tprintf(s->avctx, "slice end %d %d\n", - get_bits_count(&s->gb), s->gb.size_in_bits); - if (get_bits_left(&s->gb) == 0) { - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, - s->mb_x - 1, s->mb_y, - ER_MB_END & part_mask); - if (s->mb_x > lf_x_start) - loop_filter(h, lf_x_start, s->mb_x); + if (get_bits_left(&h->gb) <= 0 && h->mb_skip_run <= 0) { + tprintf(h->avctx, "slice end %d %d\n", + get_bits_count(&h->gb), h->gb.size_in_bits); + if (get_bits_left(&h->gb) == 0) { + er_add_slice(h, h->resync_mb_x, h->resync_mb_y, + h->mb_x - 1, h->mb_y, + ER_MB_END); + if (h->mb_x > lf_x_start) + loop_filter(h, lf_x_start, h->mb_x); return 0; } else { - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, - s->mb_y, ER_MB_ERROR & part_mask); + er_add_slice(h, h->resync_mb_x, h->resync_mb_y, h->mb_x, + h->mb_y, ER_MB_ERROR); return -1; } @@ -3900,21 +4344,22 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) */ static int execute_decode_slices(H264Context *h, int context_count) { - MpegEncContext *const s = &h->s; - AVCodecContext *const avctx = s->avctx; + AVCodecContext *const avctx = h->avctx; H264Context *hx; int i; - if (s->avctx->hwaccel || - s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) + if (h->avctx->hwaccel || + h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) return 0; if (context_count == 1) { return decode_slice(avctx, &h); } else { + av_assert0(context_count > 0); for (i = 1; i < context_count; i++) { hx = h->thread_context[i]; - hx->s.err_recognition = avctx->err_recognition; - hx->s.error_count = 0; + if (CONFIG_ERROR_RESILIENCE) { + hx->er.error_count = 0; + } hx->x264_build = h->x264_build; } @@ -3923,12 +4368,14 @@ static int execute_decode_slices(H264Context *h, int context_count) /* pull back stuff from slices to master context */ hx = h->thread_context[context_count - 1]; - s->mb_x = hx->s.mb_x; - s->mb_y = hx->s.mb_y; - s->droppable = hx->s.droppable; - s->picture_structure = hx->s.picture_structure; - for (i = 1; i < context_count; i++) - h->s.error_count += h->thread_context[i]->s.error_count; + h->mb_x = hx->mb_x; + h->mb_y = hx->mb_y; + h->droppable = hx->droppable; + h->picture_structure = hx->picture_structure; + if (CONFIG_ERROR_RESILIENCE) { + for (i = 1; i < context_count; i++) + h->er.error_count += h->thread_context[i]->er.error_count; + } } return 0; @@ -3937,8 +4384,7 @@ static int execute_decode_slices(H264Context *h, int context_count) static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, int parse_extradata) { - MpegEncContext *const s = &h->s; - AVCodecContext *const avctx = s->avctx; + AVCodecContext *const avctx = h->avctx; H264Context *hx; ///< thread context int buf_index; int context_count; @@ -3951,13 +4397,13 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, h->nal_unit_type= 0; - if(!s->slice_context_count) - s->slice_context_count= 1; - h->max_contexts = s->slice_context_count; - if (!(s->flags2 & CODEC_FLAG2_CHUNKS)) { + if(!h->slice_context_count) + h->slice_context_count= 1; + h->max_contexts = h->slice_context_count; + if (!(avctx->flags2 & CODEC_FLAG2_CHUNKS)) { h->current_slice = 0; - if (!s->first_field) - s->current_picture_ptr = NULL; + if (!h->first_field) + h->cur_pic_ptr = NULL; ff_h264_reset_sei(h); } @@ -3988,7 +4434,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, for (i = 0; i < h->nal_length_size; i++) nalsize = (nalsize << 8) | buf[buf_index++]; if (nalsize <= 0 || nalsize > buf_size - buf_index) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "AVC: nal size %d\n", nalsize); break; } @@ -4021,23 +4467,23 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, goto end; } i = buf_index + consumed; - if ((s->workaround_bugs & FF_BUG_AUTODETECT) && i + 3 < next_avc && + if ((h->workaround_bugs & FF_BUG_AUTODETECT) && i + 3 < next_avc && buf[i] == 0x00 && buf[i + 1] == 0x00 && buf[i + 2] == 0x01 && buf[i + 3] == 0xE0) - s->workaround_bugs |= FF_BUG_TRUNCATED; + h->workaround_bugs |= FF_BUG_TRUNCATED; - if (!(s->workaround_bugs & FF_BUG_TRUNCATED)) + if (!(h->workaround_bugs & FF_BUG_TRUNCATED)) while(dst_length > 0 && ptr[dst_length - 1] == 0) dst_length--; bit_length = !dst_length ? 0 : (8 * dst_length - decode_rbsp_trailing(h, ptr + dst_length - 1)); - if (s->avctx->debug & FF_DEBUG_STARTCODE) - av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d/%d at %d/%d length %d pass %d\n", hx->nal_unit_type, hx->nal_ref_idc, buf_index, buf_size, dst_length, pass); + if (h->avctx->debug & FF_DEBUG_STARTCODE) + av_log(h->avctx, AV_LOG_DEBUG, "NAL %d/%d at %d/%d length %d pass %d\n", hx->nal_unit_type, hx->nal_ref_idc, buf_index, buf_size, dst_length, pass); if (h->is_avc && (nalsize != consumed) && nalsize) - av_log(h->s.avctx, AV_LOG_DEBUG, + av_log(h->avctx, AV_LOG_DEBUG, "AVC: Consumed only %d bytes instead of %d\n", consumed, nalsize); @@ -4057,8 +4503,8 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, case NAL_DPA: case NAL_IDR_SLICE: case NAL_SLICE: - init_get_bits(&hx->s.gb, ptr, bit_length); - if (!get_ue_golomb(&hx->s.gb) || !first_slice) + init_get_bits(&hx->gb, ptr, bit_length); + if (!get_ue_golomb(&hx->gb) || !first_slice) nals_needed = nal_index; if (!first_slice) first_slice = hx->nal_unit_type; @@ -4090,7 +4536,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, case NAL_DPB: case NAL_DPC: case NAL_AUXILIARY_SLICE: - av_log(h->s.avctx, AV_LOG_WARNING, "Ignoring NAL %d in global header/extradata\n", hx->nal_unit_type); + av_log(h->avctx, AV_LOG_WARNING, "Ignoring NAL %d in global header/extradata\n", hx->nal_unit_type); hx->nal_unit_type = NAL_FF_IGNORE; } } @@ -4100,7 +4546,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, switch (hx->nal_unit_type) { case NAL_IDR_SLICE: if (first_slice != NAL_IDR_SLICE) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "Invalid mix of idr and non-idr slices\n"); buf_index = -1; goto end; @@ -4109,10 +4555,10 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, idr(h); // FIXME ensure we don't lose some frames if there is reordering idr_cleared = 1; case NAL_SLICE: - init_get_bits(&hx->s.gb, ptr, bit_length); + init_get_bits(&hx->gb, ptr, bit_length); hx->intra_gb_ptr = - hx->inter_gb_ptr = &hx->s.gb; - hx->s.data_partitioning = 0; + hx->inter_gb_ptr = &hx->gb; + hx->data_partitioning = 0; if ((err = decode_slice_header(hx, h))) break; @@ -4130,28 +4576,28 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, h->recovery_frame = h->frame_num; } - s->current_picture_ptr->f.key_frame |= + h->cur_pic_ptr->f.key_frame |= (hx->nal_unit_type == NAL_IDR_SLICE); if (h->recovery_frame == h->frame_num) { - s->current_picture_ptr->sync |= 1; + h->cur_pic_ptr->sync |= 1; h->recovery_frame = -1; } - h->sync |= !!s->current_picture_ptr->f.key_frame; - h->sync |= 3*!!(s->flags2 & CODEC_FLAG2_SHOW_ALL); - s->current_picture_ptr->sync |= h->sync; + h->sync |= !!h->cur_pic_ptr->f.key_frame; + h->sync |= 3*!!(avctx->flags2 & CODEC_FLAG2_SHOW_ALL); + h->cur_pic_ptr->sync |= h->sync; if (h->current_slice == 1) { - if (!(s->flags2 & CODEC_FLAG2_CHUNKS)) + if (!(avctx->flags2 & CODEC_FLAG2_CHUNKS)) decode_postinit(h, nal_index >= nals_needed); - if (s->avctx->hwaccel && - s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0) + if (h->avctx->hwaccel && + h->avctx->hwaccel->start_frame(h->avctx, NULL, 0) < 0) return -1; if (CONFIG_H264_VDPAU_DECODER && - s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) - ff_vdpau_h264_picture_start(s); + h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) + ff_vdpau_h264_picture_start(h); } if (hx->redundant_pic_count == 0 && @@ -4168,26 +4614,26 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, consumed) < 0) return -1; } else if (CONFIG_H264_VDPAU_DECODER && - s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) { + h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) { static const uint8_t start_code[] = { 0x00, 0x00, 0x01 }; - ff_vdpau_add_data_chunk(s, start_code, + ff_vdpau_add_data_chunk(h->cur_pic_ptr->f.data[0], start_code, sizeof(start_code)); - ff_vdpau_add_data_chunk(s, &buf[buf_index - consumed], + ff_vdpau_add_data_chunk(h->cur_pic_ptr->f.data[0], &buf[buf_index - consumed], consumed); } else context_count++; } break; case NAL_DPA: - init_get_bits(&hx->s.gb, ptr, bit_length); + init_get_bits(&hx->gb, ptr, bit_length); hx->intra_gb_ptr = hx->inter_gb_ptr = NULL; if ((err = decode_slice_header(hx, h)) < 0) break; - hx->s.data_partitioning = 1; + hx->data_partitioning = 1; break; case NAL_DPB: init_get_bits(&hx->intra_gb, ptr, bit_length); @@ -4197,14 +4643,13 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, init_get_bits(&hx->inter_gb, ptr, bit_length); hx->inter_gb_ptr = &hx->inter_gb; - av_log(h->s.avctx, AV_LOG_ERROR, "Partitioned H.264 support is incomplete\n"); + av_log(h->avctx, AV_LOG_ERROR, "Partitioned H.264 support is incomplete\n"); break; if (hx->redundant_pic_count == 0 && hx->intra_gb_ptr && - hx->s.data_partitioning && - s->current_picture_ptr && - s->context_initialized && + hx->data_partitioning && + h->cur_pic_ptr && h->context_initialized && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos != AV_PICTURE_TYPE_B) && @@ -4214,26 +4659,26 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, context_count++; break; case NAL_SEI: - init_get_bits(&s->gb, ptr, bit_length); + init_get_bits(&h->gb, ptr, bit_length); ff_h264_decode_sei(h); break; case NAL_SPS: - init_get_bits(&s->gb, ptr, bit_length); + init_get_bits(&h->gb, ptr, bit_length); if (ff_h264_decode_seq_parameter_set(h) < 0 && (h->is_avc ? (nalsize != consumed) && nalsize : 1)) { - av_log(h->s.avctx, AV_LOG_DEBUG, + av_log(h->avctx, AV_LOG_DEBUG, "SPS decoding failure, trying again with the complete NAL\n"); if (h->is_avc) av_assert0(next_avc - buf_index + consumed == nalsize); if ((next_avc - buf_index + consumed - 1) >= INT_MAX/8) break; - init_get_bits(&s->gb, &buf[buf_index + 1 - consumed], + init_get_bits(&h->gb, &buf[buf_index + 1 - consumed], 8*(next_avc - buf_index + consumed - 1)); ff_h264_decode_seq_parameter_set(h); } break; case NAL_PPS: - init_get_bits(&s->gb, ptr, bit_length); + init_get_bits(&h->gb, ptr, bit_length); ff_h264_decode_picture_parameter_set(h, bit_length); break; case NAL_AUD: @@ -4256,7 +4701,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, } if (err < 0) - av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n"); + av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\n"); else if (err == 1) { /* Slice could not be decoded in parallel mode, copy down * NAL unit stuff to context 0 and restart. Note that @@ -4274,10 +4719,10 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, end: /* clean up */ - if (s->current_picture_ptr && s->current_picture_ptr->owner2 == s && - !s->droppable) { - ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, - s->picture_structure == PICT_BOTTOM_FIELD); + if (h->cur_pic_ptr && h->cur_pic_ptr->owner2 == h && + !h->droppable) { + ff_thread_report_progress(&h->cur_pic_ptr->f, INT_MAX, + h->picture_structure == PICT_BOTTOM_FIELD); } return buf_index; @@ -4286,7 +4731,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, /** * Return the number of bytes consumed for building the current frame. */ -static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size) +static int get_consumed_bytes(int pos, int buf_size) { if (pos == 0) pos = 1; // avoid infinite loops (i doubt that is needed but ...) @@ -4302,20 +4747,19 @@ static int decode_frame(AVCodecContext *avctx, void *data, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; H264Context *h = avctx->priv_data; - MpegEncContext *s = &h->s; AVFrame *pict = data; int buf_index = 0; Picture *out; int i, out_idx; - s->flags = avctx->flags; - s->flags2 = avctx->flags2; + h->flags = avctx->flags; /* end of stream, output what is still in the buffers */ if (buf_size == 0) { out: - s->current_picture_ptr = NULL; + h->cur_pic_ptr = NULL; + h->first_field = 0; // FIXME factorize this with the output code below out = h->delayed_pic[0]; @@ -4334,6 +4778,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, h->delayed_pic[i] = h->delayed_pic[i + 1]; if (out) { + out->f.reference &= ~DELAYED_PIC_REF; *got_frame = 1; *pict = out->f; } @@ -4367,12 +4812,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, if (buf_index < 0) return -1; - if (!s->current_picture_ptr && h->nal_unit_type == NAL_END_SEQUENCE) { + if (!h->cur_pic_ptr && h->nal_unit_type == NAL_END_SEQUENCE) { av_assert0(buf_index <= buf_size); goto out; } - if (!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr) { + if (!(avctx->flags2 & CODEC_FLAG2_CHUNKS) && !h->cur_pic_ptr) { if (avctx->skip_frame >= AVDISCARD_NONREF || buf_size >= 4 && !memcmp("Q264", buf, 4)) return buf_size; @@ -4380,13 +4825,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, return -1; } - if (!(s->flags2 & CODEC_FLAG2_CHUNKS) || - (s->mb_y >= s->mb_height && s->mb_height)) { - if (s->flags2 & CODEC_FLAG2_CHUNKS) + if (!(avctx->flags2 & CODEC_FLAG2_CHUNKS) || + (h->mb_y >= h->mb_height && h->mb_height)) { + if (avctx->flags2 & CODEC_FLAG2_CHUNKS) decode_postinit(h, 1); field_end(h, 0); - h->context_reinitialized = 0; /* Wait for second field. */ *got_frame = 0; @@ -4397,9 +4841,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, } assert(pict->data[0] || !*got_frame); - ff_print_debug_info(s, pict); - return get_consumed_bytes(s, buf_index, buf_size); + if (CONFIG_MPEGVIDEO) { + ff_print_debug_info2(h->avctx, pict, h->er.mbskip_table, h->visualization_buffer, &h->low_delay, + h->mb_width, h->mb_height, h->mb_stride, 1); + } + + return get_consumed_bytes(buf_index, buf_size); } av_cold void ff_h264_free_context(H264Context *h) @@ -4418,14 +4866,17 @@ av_cold void ff_h264_free_context(H264Context *h) static av_cold int h264_decode_end(AVCodecContext *avctx) { H264Context *h = avctx->priv_data; - MpegEncContext *s = &h->s; + int i; ff_h264_remove_all_refs(h); ff_h264_free_context(h); - ff_MPV_common_end(s); - - // memset(h, 0, sizeof(H264Context)); + if (h->DPB && !h->avctx->internal->is_copy) { + for (i = 0; i < h->picture_count; i++) { + free_picture(h, &h->DPB[i]); + } + } + av_freep(&h->DPB); return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/h264.h b/mythtv/external/FFmpeg/libavcodec/h264.h index 4b6a19ed4a4..03be472c513 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264.h +++ b/mythtv/external/FFmpeg/libavcodec/h264.h @@ -29,16 +29,15 @@ #define AVCODEC_H264_H #include "libavutil/intreadwrite.h" -#include "dsputil.h" #include "cabac.h" +#include "get_bits.h" #include "mpegvideo.h" +#include "h264chroma.h" #include "h264dsp.h" #include "h264pred.h" +#include "h264qpel.h" #include "rectangle.h" -#define interlaced_dct interlaced_dct_is_a_bad_name -#define mb_intra mb_intra_is_not_initialized_see_mb_type - #define MAX_SPS_COUNT 32 #define MAX_PPS_COUNT 256 @@ -64,7 +63,7 @@ #define MB_MBAFF h->mb_mbaff #define MB_FIELD h->mb_field_decoding_flag #define FRAME_MBAFF h->mb_aff_frame -#define FIELD_PICTURE (s->picture_structure != PICT_FRAME) +#define FIELD_PICTURE (h->picture_structure != PICT_FRAME) #define LEFT_MBS 2 #define LTOP 0 #define LBOT 1 @@ -256,13 +255,42 @@ typedef struct MMCO { * H264Context */ typedef struct H264Context { - MpegEncContext s; + AVCodecContext *avctx; + VideoDSPContext vdsp; H264DSPContext h264dsp; + H264ChromaContext h264chroma; + H264QpelContext h264qpel; + MotionEstContext me; + ParseContext parse_context; + GetBitContext gb; + DSPContext dsp; + ERContext er; + + Picture *DPB; + Picture *cur_pic_ptr; + Picture cur_pic; + int picture_count; + int picture_range_start, picture_range_end; + int pixel_shift; ///< 0 for 8-bit H264, 1 for high-bit-depth H264 int chroma_qp[2]; // QPc int qp_thresh; ///< QP threshold to skip loopfilter + int width, height; + int linesize, uvlinesize; + int chroma_x_shift, chroma_y_shift; + + int qscale; + int droppable; + int data_partitioning; + int coded_picture_number; + int low_delay; + + int context_initialized; + int flags; + int workaround_bugs; + int prev_mb_skipped; int next_mb_skipped; @@ -326,9 +354,6 @@ typedef struct H264Context { int mb_linesize; ///< may be equal to s->linesize or s->linesize * 2, for mbaff int mb_uvlinesize; - int emu_edge_width; - int emu_edge_height; - unsigned current_sps_id; ///< id of the current SPS SPS sps; ///< current sps @@ -352,6 +377,8 @@ typedef struct H264Context { int mb_aff_frame; int mb_field_decoding_flag; int mb_mbaff; ///< mb_aff_frame && mb_field_decoding_flag + int picture_structure; + int first_field; DECLARE_ALIGNED(8, uint16_t, sub_mb_type)[4]; @@ -390,9 +417,10 @@ typedef struct H264Context { GetBitContext *intra_gb_ptr; GetBitContext *inter_gb_ptr; - DECLARE_ALIGNED(16, DCTELEM, mb)[16 * 48 * 2]; ///< as a dct coeffecient is int32_t in high depth, we need to reserve twice the space. - DECLARE_ALIGNED(16, DCTELEM, mb_luma_dc)[3][16 * 2]; - DCTELEM mb_padding[256 * 2]; ///< as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not too large or ensure that there is some unused stuff after mb + const uint8_t *intra_pcm_ptr; + DECLARE_ALIGNED(16, int16_t, mb)[16 * 48 * 2]; ///< as a dct coeffecient is int32_t in high depth, we need to reserve twice the space. + DECLARE_ALIGNED(16, int16_t, mb_luma_dc)[3][16 * 2]; + int16_t mb_padding[256 * 2]; ///< as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not too large or ensure that there is some unused stuff after mb /** * Cabac @@ -428,6 +456,13 @@ typedef struct H264Context { int x264_build; + int mb_x, mb_y; + int resync_mb_x; + int resync_mb_y; + int mb_skip_run; + int mb_height, mb_width; + int mb_stride; + int mb_num; int mb_xy; int is_complex; @@ -452,7 +487,8 @@ typedef struct H264Context { int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4) int got_first; ///< this flag is != 0 if we've parsed a frame - int context_reinitialized; + int bit_depth_luma; ///< luma bit depth from sps to detect changes + int chroma_format_idc; ///< chroma format from sps to detect changes SPS *sps_buffers[MAX_SPS_COUNT]; PPS *pps_buffers[MAX_PPS_COUNT]; @@ -485,9 +521,9 @@ typedef struct H264Context { int redundant_pic_count; + Picture default_ref_list[2][32]; ///< base reference list for all slices of a coded picture Picture *short_ref[32]; Picture *long_ref[32]; - Picture default_ref_list[2][32]; ///< base reference list for all slices of a coded picture Picture *delayed_pic[MAX_DELAYED_PIC_COUNT + 2]; // FIXME size? int last_pocs[MAX_DELAYED_PIC_COUNT]; Picture *next_output_pic; @@ -525,13 +561,18 @@ typedef struct H264Context { */ int max_contexts; + int slice_context_count; + /** * 1 if the single thread fallback warning has already been * displayed, 0 otherwise. */ int single_decode_warning; + enum AVPictureType pict_type; + int last_slice_type; + unsigned int last_ref_count[2]; /** @} */ /** @@ -602,6 +643,10 @@ typedef struct H264Context { uint8_t parse_history[4]; int parse_history_count; int parse_last_mb; + uint8_t *edge_emu_buffer; + int16_t *dc_val_base; + + uint8_t *visualization_buffer[3]; ///< temporary buffer vor MV visualization } H264Context; extern const uint8_t ff_h264_chroma_qp[7][QP_MAX_NUM + 1]; ///< One chroma qp table for each possible bit depth (8-14). @@ -642,7 +687,7 @@ const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, * Free any data that may have been allocated in the H264 context * like SPS, PPS etc. */ -av_cold void ff_h264_free_context(H264Context *h); +void ff_h264_free_context(H264Context *h); /** * Reconstruct bitstream slice_type. @@ -689,8 +734,8 @@ int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma); void ff_h264_hl_decode_mb(H264Context *h); int ff_h264_frame_start(H264Context *h); int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size); -av_cold int ff_h264_decode_init(AVCodecContext *avctx); -av_cold void ff_h264_decode_init_vlc(void); +int ff_h264_decode_init(AVCodecContext *avctx); +void ff_h264_decode_init_vlc(void); /** * Decode a macroblock @@ -810,7 +855,7 @@ static av_always_inline int pred_intra_mode(H264Context *h, int n) const int top = h->intra4x4_pred_mode_cache[index8 - 8]; const int min = FFMIN(left, top); - tprintf(h->s.avctx, "mode:%d %d min:%d\n", left, top, min); + tprintf(h->avctx, "mode:%d %d min:%d\n", left, top, min); if (min < 0) return DC_PRED; @@ -844,7 +889,7 @@ static av_always_inline void write_back_non_zero_count(H264Context *h) AV_COPY32(&nnz[32], &nnz_cache[4 + 8 * 11]); AV_COPY32(&nnz[36], &nnz_cache[4 + 8 * 12]); - if (!h->s.chroma_y_shift) { + if (!h->chroma_y_shift) { AV_COPY32(&nnz[24], &nnz_cache[4 + 8 * 8]); AV_COPY32(&nnz[28], &nnz_cache[4 + 8 * 9]); AV_COPY32(&nnz[40], &nnz_cache[4 + 8 * 13]); @@ -853,12 +898,11 @@ static av_always_inline void write_back_non_zero_count(H264Context *h) } static av_always_inline void write_back_motion_list(H264Context *h, - MpegEncContext *const s, int b_stride, int b_xy, int b8_xy, int mb_type, int list) { - int16_t(*mv_dst)[2] = &s->current_picture.f.motion_val[list][b_xy]; + int16_t(*mv_dst)[2] = &h->cur_pic.f.motion_val[list][b_xy]; int16_t(*mv_src)[2] = &h->mv_cache[list][scan8[0]]; AV_COPY128(mv_dst + 0 * b_stride, mv_src + 8 * 0); AV_COPY128(mv_dst + 1 * b_stride, mv_src + 8 * 1); @@ -879,7 +923,7 @@ static av_always_inline void write_back_motion_list(H264Context *h, } { - int8_t *ref_index = &s->current_picture.f.ref_index[list][b8_xy]; + int8_t *ref_index = &h->cur_pic.f.ref_index[list][b8_xy]; int8_t *ref_cache = h->ref_cache[list]; ref_index[0 + 0 * 2] = ref_cache[scan8[0]]; ref_index[1 + 0 * 2] = ref_cache[scan8[4]]; @@ -890,19 +934,18 @@ static av_always_inline void write_back_motion_list(H264Context *h, static av_always_inline void write_back_motion(H264Context *h, int mb_type) { - MpegEncContext *const s = &h->s; const int b_stride = h->b_stride; - const int b_xy = 4 * s->mb_x + 4 * s->mb_y * h->b_stride; // try mb2b(8)_xy + const int b_xy = 4 * h->mb_x + 4 * h->mb_y * h->b_stride; // try mb2b(8)_xy const int b8_xy = 4 * h->mb_xy; if (USES_LIST(mb_type, 0)) { - write_back_motion_list(h, s, b_stride, b_xy, b8_xy, mb_type, 0); + write_back_motion_list(h, b_stride, b_xy, b8_xy, mb_type, 0); } else { - fill_rectangle(&s->current_picture.f.ref_index[0][b8_xy], + fill_rectangle(&h->cur_pic.f.ref_index[0][b8_xy], 2, 2, 2, (uint8_t)LIST_NOT_USED, 1); } if (USES_LIST(mb_type, 1)) - write_back_motion_list(h, s, b_stride, b_xy, b8_xy, mb_type, 1); + write_back_motion_list(h, b_stride, b_xy, b8_xy, mb_type, 1); if (h->slice_type_nos == AV_PICTURE_TYPE_B && CABAC) { if (IS_8X8(mb_type)) { @@ -926,4 +969,6 @@ static av_always_inline int get_dct8x8_allowed(H264Context *h) 0x0001000100010001ULL)); } +void ff_h264_draw_horiz_band(H264Context *h, int y, int height); + #endif /* AVCODEC_H264_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/h264_cabac.c b/mythtv/external/FFmpeg/libavcodec/h264_cabac.c index 76a648143de..435343c9891 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264_cabac.c +++ b/mythtv/external/FFmpeg/libavcodec/h264_cabac.c @@ -32,7 +32,6 @@ #include "cabac.h" #include "cabac_functions.h" #include "internal.h" -#include "dsputil.h" #include "avcodec.h" #include "h264.h" #include "h264data.h" @@ -1259,10 +1258,9 @@ static const int8_t cabac_context_init_PB[3][1024][2] = }; void ff_h264_init_cabac_states(H264Context *h) { - MpegEncContext * const s = &h->s; int i; const int8_t (*tab)[2]; - const int slice_qp = av_clip(s->qscale - 6*(h->sps.bit_depth_luma-8), 0, 51); + const int slice_qp = av_clip(h->qscale - 6*(h->sps.bit_depth_luma-8), 0, 51); if( h->slice_type_nos == AV_PICTURE_TYPE_I ) tab = cabac_context_init_I; else tab = cabac_context_init_PB[h->cabac_init_idc]; @@ -1280,13 +1278,12 @@ void ff_h264_init_cabac_states(H264Context *h) { } static int decode_cabac_field_decoding_flag(H264Context *h) { - MpegEncContext * const s = &h->s; - const long mbb_xy = h->mb_xy - 2L*s->mb_stride; + const long mbb_xy = h->mb_xy - 2L*h->mb_stride; unsigned long ctx = 0; - ctx += h->mb_field_decoding_flag & !!s->mb_x; //for FMO:(s->current_picture.f.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num); - ctx += (s->current_picture.f.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == h->slice_num); + ctx += h->mb_field_decoding_flag & !!h->mb_x; //for FMO:(s->current_picture.f.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num); + ctx += (h->cur_pic.f.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == h->slice_num); return get_cabac_noinline( &h->cabac, &(h->cabac_state+70)[ctx] ); } @@ -1322,34 +1319,33 @@ static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_sl } static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) { - MpegEncContext * const s = &h->s; int mba_xy, mbb_xy; int ctx = 0; if(FRAME_MBAFF){ //FIXME merge with the stuff in fill_caches? - int mb_xy = mb_x + (mb_y&~1)*s->mb_stride; + int mb_xy = mb_x + (mb_y&~1)*h->mb_stride; mba_xy = mb_xy - 1; if( (mb_y&1) && h->slice_table[mba_xy] == h->slice_num - && MB_FIELD == !!IS_INTERLACED( s->current_picture.f.mb_type[mba_xy] ) ) - mba_xy += s->mb_stride; + && MB_FIELD == !!IS_INTERLACED( h->cur_pic.f.mb_type[mba_xy] ) ) + mba_xy += h->mb_stride; if( MB_FIELD ){ - mbb_xy = mb_xy - s->mb_stride; + mbb_xy = mb_xy - h->mb_stride; if( !(mb_y&1) && h->slice_table[mbb_xy] == h->slice_num - && IS_INTERLACED( s->current_picture.f.mb_type[mbb_xy] ) ) - mbb_xy -= s->mb_stride; + && IS_INTERLACED( h->cur_pic.f.mb_type[mbb_xy] ) ) + mbb_xy -= h->mb_stride; }else - mbb_xy = mb_x + (mb_y-1)*s->mb_stride; + mbb_xy = mb_x + (mb_y-1)*h->mb_stride; }else{ int mb_xy = h->mb_xy; mba_xy = mb_xy - 1; - mbb_xy = mb_xy - (s->mb_stride << FIELD_PICTURE); + mbb_xy = mb_xy - (h->mb_stride << FIELD_PICTURE); } - if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mba_xy] )) + if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP(h->cur_pic.f.mb_type[mba_xy] )) ctx++; - if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mbb_xy] )) + if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP(h->cur_pic.f.mb_type[mbb_xy] )) ctx++; if( h->slice_type_nos == AV_PICTURE_TYPE_B ) @@ -1506,7 +1502,7 @@ static int decode_cabac_mb_mvd( H264Context *h, int ctxbase, int amvd, int *mvda mvd += 1 << k; k++; if(k>24){ - av_log(h->s.avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_mvd\n"); + av_log(h->avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_mvd\n"); return INT_MIN; } } @@ -1560,7 +1556,7 @@ static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, } static av_always_inline void -decode_cabac_residual_internal(H264Context *h, DCTELEM *block, +decode_cabac_residual_internal(H264Context *h, int16_t *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff, int is_dc, int chroma422) @@ -1712,7 +1708,7 @@ decode_cabac_residual_internal(H264Context *h, DCTELEM *block, \ if( coeff_abs >= 15 ) { \ int j = 0; \ - while( get_cabac_bypass( CC ) ) { \ + while(get_cabac_bypass( CC ) && j<30) { \ j++; \ } \ \ @@ -1744,18 +1740,27 @@ decode_cabac_residual_internal(H264Context *h, DCTELEM *block, } -static void decode_cabac_residual_dc_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, int max_coeff ) { +static void decode_cabac_residual_dc_internal(H264Context *h, int16_t *block, + int cat, int n, + const uint8_t *scantable, + int max_coeff) +{ decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 0); } -static void decode_cabac_residual_dc_internal_422(H264Context *h, DCTELEM *block, +static void decode_cabac_residual_dc_internal_422(H264Context *h, int16_t *block, int cat, int n, const uint8_t *scantable, int max_coeff) { decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 1); } -static void decode_cabac_residual_nondc_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) { +static void decode_cabac_residual_nondc_internal(H264Context *h, int16_t *block, + int cat, int n, + const uint8_t *scantable, + const uint32_t *qmul, + int max_coeff) +{ decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 0, 0); } @@ -1771,7 +1776,12 @@ static void decode_cabac_residual_nondc_internal( H264Context *h, DCTELEM *block * because it allows improved constant propagation into get_cabac_cbf_ctx, * as well as because most blocks have zero CBFs. */ -static av_always_inline void decode_cabac_residual_dc( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, int max_coeff ) { +static av_always_inline void decode_cabac_residual_dc(H264Context *h, + int16_t *block, + int cat, int n, + const uint8_t *scantable, + int max_coeff) +{ /* read coded block flag */ if( get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 1 ) ] ) == 0 ) { h->non_zero_count_cache[scan8[n]] = 0; @@ -1781,7 +1791,7 @@ static av_always_inline void decode_cabac_residual_dc( H264Context *h, DCTELEM * } static av_always_inline void -decode_cabac_residual_dc_422(H264Context *h, DCTELEM *block, +decode_cabac_residual_dc_422(H264Context *h, int16_t *block, int cat, int n, const uint8_t *scantable, int max_coeff) { @@ -1793,7 +1803,13 @@ decode_cabac_residual_dc_422(H264Context *h, DCTELEM *block, decode_cabac_residual_dc_internal_422(h, block, cat, n, scantable, max_coeff); } -static av_always_inline void decode_cabac_residual_nondc( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) { +static av_always_inline void decode_cabac_residual_nondc(H264Context *h, + int16_t *block, + int cat, int n, + const uint8_t *scantable, + const uint32_t *qmul, + int max_coeff) +{ /* read coded block flag */ if( (cat != 5 || CHROMA444) && get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 0 ) ] ) == 0 ) { if( max_coeff == 64 ) { @@ -1811,8 +1827,7 @@ static av_always_inline void decode_cabac_luma_residual( H264Context *h, const u static const uint8_t ctx_cat[4][3] = {{0,6,10},{1,7,11},{2,8,12},{5,9,13}}; const uint32_t *qmul; int i8x8, i4x4; - MpegEncContext * const s = &h->s; - int qscale = p == 0 ? s->qscale : h->chroma_qp[p-1]; + int qscale = p == 0 ? h->qscale : h->chroma_qp[p-1]; if( IS_INTRA16x16( mb_type ) ) { AV_ZERO128(h->mb_luma_dc[p]+0); AV_ZERO128(h->mb_luma_dc[p]+8); @@ -1858,7 +1873,6 @@ static av_always_inline void decode_cabac_luma_residual( H264Context *h, const u * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed */ int ff_h264_decode_mb_cabac(H264Context *h) { - MpegEncContext * const s = &h->s; int mb_xy; int mb_type, partition_count, cbp = 0; int dct8x8_allowed= h->pps.transform_8x8_mode; @@ -1866,21 +1880,21 @@ int ff_h264_decode_mb_cabac(H264Context *h) { const int pixel_shift = h->pixel_shift; unsigned local_ref_count[2]; - mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride; + mb_xy = h->mb_xy = h->mb_x + h->mb_y*h->mb_stride; - tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); + tprintf(h->avctx, "pic:%d mb:%d/%d\n", h->frame_num, h->mb_x, h->mb_y); if( h->slice_type_nos != AV_PICTURE_TYPE_I ) { int skip; /* a skipped mb needs the aff flag from the following mb */ - if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped ) + if( FRAME_MBAFF && (h->mb_y&1)==1 && h->prev_mb_skipped ) skip = h->next_mb_skipped; else - skip = decode_cabac_mb_skip( h, s->mb_x, s->mb_y ); + skip = decode_cabac_mb_skip( h, h->mb_x, h->mb_y ); /* read skip flags */ if( skip ) { - if( FRAME_MBAFF && (s->mb_y&1)==0 ){ - s->current_picture.f.mb_type[mb_xy] = MB_TYPE_SKIP; - h->next_mb_skipped = decode_cabac_mb_skip( h, s->mb_x, s->mb_y+1 ); + if( FRAME_MBAFF && (h->mb_y&1)==0 ){ + h->cur_pic.f.mb_type[mb_xy] = MB_TYPE_SKIP; + h->next_mb_skipped = decode_cabac_mb_skip( h, h->mb_x, h->mb_y+1 ); if(!h->next_mb_skipped) h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h); } @@ -1896,7 +1910,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { } } if(FRAME_MBAFF){ - if( (s->mb_y&1) == 0 ) + if( (h->mb_y&1) == 0 ) h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h); } @@ -1989,7 +2003,8 @@ int ff_h264_decode_mb_cabac(H264Context *h) { // The pixels are stored in the same order as levels in h->mb array. if ((int) (h->cabac.bytestream_end - ptr) < mb_size) return -1; - memcpy(h->mb, ptr, mb_size); ptr+=mb_size; + h->intra_pcm_ptr = ptr; + ptr += mb_size; ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr); @@ -1997,10 +2012,10 @@ int ff_h264_decode_mb_cabac(H264Context *h) { h->cbp_table[mb_xy] = 0xf7ef; h->chroma_pred_mode_table[mb_xy] = 0; // In deblocking, the quantizer is 0 - s->current_picture.f.qscale_table[mb_xy] = 0; + h->cur_pic.f.qscale_table[mb_xy] = 0; // All coeffs are present memset(h->non_zero_count[mb_xy], 16, 48); - s->current_picture.f.mb_type[mb_xy] = mb_type; + h->cur_pic.f.mb_type[mb_xy] = mb_type; h->last_qscale_diff = 0; return 0; } @@ -2025,7 +2040,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { int pred = pred_intra_mode( h, i ); h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred ); - av_dlog(s->avctx, "i4x4 pred=%d mode=%d\n", pred, + av_dlog(h->avctx, "i4x4 pred=%d mode=%d\n", pred, h->intra4x4_pred_mode_cache[scan8[i]]); } } @@ -2079,7 +2094,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { if (local_ref_count[list] > 1) { ref[list][i] = decode_cabac_mb_ref( h, list, 4*i ); if (ref[list][i] >= (unsigned)local_ref_count[list]) { - av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref[list][i], local_ref_count[list]); + av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref[list][i], local_ref_count[list]); return -1; } }else @@ -2114,7 +2129,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ]; pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); DECODE_CABAC_MB_MVD( h, list, index) - tprintf(s->avctx, "final mv:%d %d\n", mx, my); + tprintf(h->avctx, "final mv:%d %d\n", mx, my); if(IS_SUB_8X8(sub_mb_type)){ mv_cache[ 1 ][0]= @@ -2165,7 +2180,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { if (local_ref_count[list] > 1) { ref= decode_cabac_mb_ref(h, list, 0); if (ref >= (unsigned)local_ref_count[list]) { - av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]); + av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]); return -1; } }else @@ -2178,7 +2193,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { int mx,my,mpx,mpy; pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); DECODE_CABAC_MB_MVD( h, list, 0) - tprintf(s->avctx, "final mv:%d %d\n", mx, my); + tprintf(h->avctx, "final mv:%d %d\n", mx, my); fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2); fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); @@ -2193,7 +2208,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { if (local_ref_count[list] > 1) { ref= decode_cabac_mb_ref( h, list, 8*i ); if (ref >= (unsigned)local_ref_count[list]) { - av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]); + av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]); return -1; } }else @@ -2209,7 +2224,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { int mx,my,mpx,mpy; pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); DECODE_CABAC_MB_MVD( h, list, 8*i) - tprintf(s->avctx, "final mv:%d %d\n", mx, my); + tprintf(h->avctx, "final mv:%d %d\n", mx, my); fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack8to16(mpx,mpy), 2); fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); @@ -2228,7 +2243,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { if (local_ref_count[list] > 1) { ref= decode_cabac_mb_ref( h, list, 4*i ); if (ref >= (unsigned)local_ref_count[list]) { - av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]); + av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]); return -1; } }else @@ -2245,7 +2260,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); DECODE_CABAC_MB_MVD( h, list, 4*i) - tprintf(s->avctx, "final mv:%d %d\n", mx, my); + tprintf(h->avctx, "final mv:%d %d\n", mx, my); fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack8to16(mpx,mpy), 2); fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); }else{ @@ -2268,7 +2283,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { cbp |= decode_cabac_mb_cbp_chroma( h ) << 4; } else { if (!decode_chroma && cbp>15) { - av_log(s->avctx, AV_LOG_ERROR, "gray chroma\n"); + av_log(h->avctx, AV_LOG_ERROR, "gray chroma\n"); return AVERROR_INVALIDDATA; } } @@ -2301,18 +2316,18 @@ int ff_h264_decode_mb_cabac(H264Context *h) { AV_WN32A(&nnz_cache[4+8*10], top_empty); } } - s->current_picture.f.mb_type[mb_xy] = mb_type; + h->cur_pic.f.mb_type[mb_xy] = mb_type; if( cbp || IS_INTRA16x16( mb_type ) ) { const uint8_t *scan, *scan8x8; const uint32_t *qmul; if(IS_INTERLACED(mb_type)){ - scan8x8= s->qscale ? h->field_scan8x8 : h->field_scan8x8_q0; - scan= s->qscale ? h->field_scan : h->field_scan_q0; + scan8x8= h->qscale ? h->field_scan8x8 : h->field_scan8x8_q0; + scan= h->qscale ? h->field_scan : h->field_scan_q0; }else{ - scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0; - scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0; + scan8x8= h->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0; + scan= h->qscale ? h->zigzag_scan : h->zigzag_scan_q0; } // decode_cabac_mb_dqp @@ -2325,7 +2340,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { ctx= 3; val++; if(val > 2*max_qp){ //prevent infinite loop - av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\n", s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\n", h->mb_x, h->mb_y); return -1; } } @@ -2335,13 +2350,13 @@ int ff_h264_decode_mb_cabac(H264Context *h) { else val= -((val + 1)>>1); h->last_qscale_diff = val; - s->qscale += val; - if(((unsigned)s->qscale) > max_qp){ - if(s->qscale<0) s->qscale+= max_qp+1; - else s->qscale-= max_qp+1; + h->qscale += val; + if(((unsigned)h->qscale) > max_qp){ + if(h->qscale<0) h->qscale+= max_qp+1; + else h->qscale-= max_qp+1; } - h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); - h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); + h->chroma_qp[0] = get_chroma_qp(h, 0, h->qscale); + h->chroma_qp[1] = get_chroma_qp(h, 1, h->qscale); }else h->last_qscale_diff=0; @@ -2361,7 +2376,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { if( cbp&0x20 ) { int c, i, i8x8; for( c = 0; c < 2; c++ ) { - DCTELEM *mb = h->mb + (16*(16 + 16*c) << pixel_shift); + int16_t *mb = h->mb + (16*(16 + 16*c) << pixel_shift); qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]]; for (i8x8 = 0; i8x8 < 2; i8x8++) { for (i = 0; i < 4; i++) { @@ -2403,7 +2418,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { h->last_qscale_diff = 0; } - s->current_picture.f.qscale_table[mb_xy] = s->qscale; + h->cur_pic.f.qscale_table[mb_xy] = h->qscale; write_back_non_zero_count(h); return 0; diff --git a/mythtv/external/FFmpeg/libavcodec/h264_cavlc.c b/mythtv/external/FFmpeg/libavcodec/h264_cavlc.c index cd1130a4bc0..b75e653268b 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264_cavlc.c +++ b/mythtv/external/FFmpeg/libavcodec/h264_cavlc.c @@ -292,7 +292,7 @@ static inline int pred_non_zero_count(H264Context *h, int n){ if(i<64) i= (i+1)>>1; - tprintf(h->s.avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); + tprintf(h->avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); return i&31; } @@ -442,8 +442,7 @@ static inline int get_level_prefix(GetBitContext *gb){ * @param max_coeff number of coefficients in the block * @return <0 if an error occurred */ -static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff){ - MpegEncContext * const s = &h->s; +static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff){ static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3}; int level[16]; int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before; @@ -474,12 +473,12 @@ static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, in if(total_coeff==0) return 0; if(total_coeff > (unsigned)max_coeff) { - av_log(h->s.avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", s->mb_x, s->mb_y, total_coeff); + av_log(h->avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", h->mb_x, h->mb_y, total_coeff); return -1; } trailing_ones= coeff_token&3; - tprintf(h->s.avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff); + tprintf(h->avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff); av_assert2(total_coeff<=16); i = show_bits(gb, 3); @@ -515,7 +514,7 @@ static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, in level_code= 30; if(prefix>=16){ if(prefix > 25+3){ - av_log(h->s.avctx, AV_LOG_ERROR, "Invalid level prefix\n"); + av_log(h->avctx, AV_LOG_ERROR, "Invalid level prefix\n"); return -1; } level_code += (1<<(prefix-3))-4096; @@ -618,7 +617,7 @@ static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, in } if(zeros_left<0){ - av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", h->mb_x, h->mb_y); return -1; } @@ -627,8 +626,7 @@ static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, in static av_always_inline int decode_luma_residual(H264Context *h, GetBitContext *gb, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p){ int i4x4, i8x8; - MpegEncContext * const s = &h->s; - int qscale = p == 0 ? s->qscale : h->chroma_qp[p-1]; + int qscale = p == 0 ? h->qscale : h->chroma_qp[p-1]; if(IS_INTRA16x16(mb_type)){ AV_ZERO128(h->mb_luma_dc[p]+0); AV_ZERO128(h->mb_luma_dc[p]+8); @@ -662,7 +660,7 @@ static av_always_inline int decode_luma_residual(H264Context *h, GetBitContext * for(i8x8=0; i8x8<4; i8x8++){ if(cbp & (1<mb[64*i8x8+256*p << pixel_shift]; + int16_t *buf = &h->mb[64*i8x8+256*p << pixel_shift]; uint8_t *nnz; for(i4x4=0; i4x4<4; i4x4++){ const int index= i4x4 + 4*i8x8 + p*16; @@ -693,7 +691,6 @@ static av_always_inline int decode_luma_residual(H264Context *h, GetBitContext * } int ff_h264_decode_mb_cavlc(H264Context *h){ - MpegEncContext * const s = &h->s; int mb_xy; int partition_count; unsigned int mb_type, cbp; @@ -702,32 +699,32 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ const int pixel_shift = h->pixel_shift; unsigned local_ref_count[2]; - mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride; + mb_xy = h->mb_xy = h->mb_x + h->mb_y*h->mb_stride; - tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); + tprintf(h->avctx, "pic:%d mb:%d/%d\n", h->frame_num, h->mb_x, h->mb_y); cbp = 0; /* avoid warning. FIXME: find a solution without slowing down the code */ if(h->slice_type_nos != AV_PICTURE_TYPE_I){ - if(s->mb_skip_run==-1) - s->mb_skip_run= get_ue_golomb(&s->gb); + if(h->mb_skip_run==-1) + h->mb_skip_run= get_ue_golomb(&h->gb); - if (s->mb_skip_run--) { - if(FRAME_MBAFF && (s->mb_y&1) == 0){ - if(s->mb_skip_run==0) - h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb); + if (h->mb_skip_run--) { + if(FRAME_MBAFF && (h->mb_y&1) == 0){ + if(h->mb_skip_run==0) + h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&h->gb); } decode_mb_skip(h); return 0; } } if(FRAME_MBAFF){ - if( (s->mb_y&1) == 0 ) - h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb); + if( (h->mb_y&1) == 0 ) + h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&h->gb); } h->prev_mb_skipped= 0; - mb_type= get_ue_golomb(&s->gb); + mb_type= get_ue_golomb(&h->gb); if(h->slice_type_nos == AV_PICTURE_TYPE_B){ if(mb_type < 23){ partition_count= b_mb_type_info[mb_type].partition_count; @@ -750,7 +747,7 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ mb_type--; decode_intra_mb: if(mb_type > 25){ - av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_picture_type_char(h->slice_type), s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_picture_type_char(h->slice_type), h->mb_x, h->mb_y); return -1; } partition_count=0; @@ -765,24 +762,19 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ h->slice_table[ mb_xy ]= h->slice_num; if(IS_INTRA_PCM(mb_type)){ - unsigned int x; const int mb_size = ff_h264_mb_sizes[h->sps.chroma_format_idc] * - h->sps.bit_depth_luma >> 3; + h->sps.bit_depth_luma; // We assume these blocks are very rare so we do not optimize it. - align_get_bits(&s->gb); - - // The pixels are stored in the same order as levels in h->mb array. - for(x=0; x < mb_size; x++){ - ((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8); - } + h->intra_pcm_ptr = align_get_bits(&h->gb); + skip_bits_long(&h->gb, mb_size); // In deblocking, the quantizer is 0 - s->current_picture.f.qscale_table[mb_xy] = 0; + h->cur_pic.f.qscale_table[mb_xy] = 0; // All coeffs are present memset(h->non_zero_count[mb_xy], 16, 48); - s->current_picture.f.mb_type[mb_xy] = mb_type; + h->cur_pic.f.mb_type[mb_xy] = mb_type; return 0; } @@ -799,7 +791,7 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ if(IS_INTRA4x4(mb_type)){ int i; int di = 1; - if(dct8x8_allowed && get_bits1(&s->gb)){ + if(dct8x8_allowed && get_bits1(&h->gb)){ mb_type |= MB_TYPE_8x8DCT; di = 4; } @@ -808,8 +800,8 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ for(i=0; i<16; i+=di){ int mode= pred_intra_mode(h, i); - if(!get_bits1(&s->gb)){ - const int rem_mode= get_bits(&s->gb, 3); + if(!get_bits1(&h->gb)){ + const int rem_mode= get_bits(&h->gb, 3); mode = rem_mode + (rem_mode >= mode); } @@ -827,7 +819,7 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ return -1; } if(decode_chroma){ - pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb), 1); + pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&h->gb), 1); if(pred_mode < 0) return -1; h->chroma_pred_mode= pred_mode; @@ -839,9 +831,9 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ if(h->slice_type_nos == AV_PICTURE_TYPE_B){ for(i=0; i<4; i++){ - h->sub_mb_type[i]= get_ue_golomb_31(&s->gb); + h->sub_mb_type[i]= get_ue_golomb_31(&h->gb); if(h->sub_mb_type[i] >=13){ - av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], h->mb_x, h->mb_y); return -1; } sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; @@ -857,9 +849,9 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ }else{ av_assert2(h->slice_type_nos == AV_PICTURE_TYPE_P); //FIXME SP correct ? for(i=0; i<4; i++){ - h->sub_mb_type[i]= get_ue_golomb_31(&s->gb); + h->sub_mb_type[i]= get_ue_golomb_31(&h->gb); if(h->sub_mb_type[i] >=4){ - av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], h->mb_x, h->mb_y); return -1; } sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; @@ -876,11 +868,11 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ if(ref_count == 1){ tmp= 0; }else if(ref_count == 2){ - tmp= get_bits1(&s->gb)^1; + tmp= get_bits1(&h->gb)^1; }else{ - tmp= get_ue_golomb_31(&s->gb); + tmp= get_ue_golomb_31(&h->gb); if(tmp>=ref_count){ - av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp); + av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp); return -1; } } @@ -912,9 +904,9 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ const int index= 4*i + block_width*j; int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); - mx += get_se_golomb(&s->gb); - my += get_se_golomb(&s->gb); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); + mx += get_se_golomb(&h->gb); + my += get_se_golomb(&h->gb); + tprintf(h->avctx, "final mv:%d %d\n", mx, my); if(IS_SUB_8X8(sub_mb_type)){ mv_cache[ 1 ][0]= @@ -951,11 +943,11 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ if(local_ref_count[list]==1){ val= 0; }else if(local_ref_count[list]==2){ - val= get_bits1(&s->gb)^1; + val= get_bits1(&h->gb)^1; }else{ - val= get_ue_golomb_31(&s->gb); + val= get_ue_golomb_31(&h->gb); if(val >= local_ref_count[list]){ - av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); + av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; } } @@ -965,9 +957,9 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ for(list=0; listlist_count; list++){ if(IS_DIR(mb_type, 0, list)){ pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); - mx += get_se_golomb(&s->gb); - my += get_se_golomb(&s->gb); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); + mx += get_se_golomb(&h->gb); + my += get_se_golomb(&h->gb); + tprintf(h->avctx, "final mv:%d %d\n", mx, my); fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); } @@ -981,11 +973,11 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ if(local_ref_count[list] == 1){ val= 0; }else if(local_ref_count[list] == 2){ - val= get_bits1(&s->gb)^1; + val= get_bits1(&h->gb)^1; }else{ - val= get_ue_golomb_31(&s->gb); + val= get_ue_golomb_31(&h->gb); if(val >= local_ref_count[list]){ - av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); + av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; } } @@ -999,9 +991,9 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ unsigned int val; if(IS_DIR(mb_type, i, list)){ pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); - mx += get_se_golomb(&s->gb); - my += get_se_golomb(&s->gb); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); + mx += get_se_golomb(&h->gb); + my += get_se_golomb(&h->gb); + tprintf(h->avctx, "final mv:%d %d\n", mx, my); val= pack16to32(mx,my); }else @@ -1018,11 +1010,11 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ if(local_ref_count[list]==1){ val= 0; }else if(local_ref_count[list]==2){ - val= get_bits1(&s->gb)^1; + val= get_bits1(&h->gb)^1; }else{ - val= get_ue_golomb_31(&s->gb); + val= get_ue_golomb_31(&h->gb); if(val >= local_ref_count[list]){ - av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); + av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; } } @@ -1036,9 +1028,9 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ unsigned int val; if(IS_DIR(mb_type, i, list)){ pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); - mx += get_se_golomb(&s->gb); - my += get_se_golomb(&s->gb); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); + mx += get_se_golomb(&h->gb); + my += get_se_golomb(&h->gb); + tprintf(h->avctx, "final mv:%d %d\n", mx, my); val= pack16to32(mx,my); }else @@ -1053,18 +1045,18 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ write_back_motion(h, mb_type); if(!IS_INTRA16x16(mb_type)){ - cbp= get_ue_golomb(&s->gb); + cbp= get_ue_golomb(&h->gb); if(decode_chroma){ if(cbp > 47){ - av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, h->mb_x, h->mb_y); return -1; } if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp[cbp]; else cbp= golomb_to_inter_cbp [cbp]; }else{ if(cbp > 15){ - av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, h->mb_x, h->mb_y); return -1; } if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp]; @@ -1072,17 +1064,17 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ } } else { if (!decode_chroma && cbp>15) { - av_log(s->avctx, AV_LOG_ERROR, "gray chroma\n"); + av_log(h->avctx, AV_LOG_ERROR, "gray chroma\n"); return AVERROR_INVALIDDATA; } } if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){ - mb_type |= MB_TYPE_8x8DCT*get_bits1(&s->gb); + mb_type |= MB_TYPE_8x8DCT*get_bits1(&h->gb); } h->cbp= h->cbp_table[mb_xy]= cbp; - s->current_picture.f.mb_type[mb_xy] = mb_type; + h->cur_pic.f.mb_type[mb_xy] = mb_type; if(cbp || IS_INTRA16x16(mb_type)){ int i4x4, i8x8, chroma_idx; @@ -1093,28 +1085,28 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8); if(IS_INTERLACED(mb_type)){ - scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0; - scan= s->qscale ? h->field_scan : h->field_scan_q0; + scan8x8= h->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0; + scan= h->qscale ? h->field_scan : h->field_scan_q0; }else{ - scan8x8= s->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0; - scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0; + scan8x8= h->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0; + scan= h->qscale ? h->zigzag_scan : h->zigzag_scan_q0; } - dquant= get_se_golomb(&s->gb); + dquant= get_se_golomb(&h->gb); - s->qscale += dquant; + h->qscale += dquant; - if(((unsigned)s->qscale) > max_qp){ - if(s->qscale<0) s->qscale+= max_qp+1; - else s->qscale-= max_qp+1; - if(((unsigned)s->qscale) > max_qp){ - av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y); + if(((unsigned)h->qscale) > max_qp){ + if(h->qscale<0) h->qscale+= max_qp+1; + else h->qscale-= max_qp+1; + if(((unsigned)h->qscale) > max_qp){ + av_log(h->avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, h->mb_x, h->mb_y); return -1; } } - h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale); - h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale); + h->chroma_qp[0]= get_chroma_qp(h, 0, h->qscale); + h->chroma_qp[1]= get_chroma_qp(h, 1, h->qscale); if( (ret = decode_luma_residual(h, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 0)) < 0 ){ return -1; @@ -1143,7 +1135,7 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ if(cbp&0x20){ for(chroma_idx=0; chroma_idx<2; chroma_idx++){ const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]]; - DCTELEM *mb = h->mb + (16*(16 + 16*chroma_idx) << pixel_shift); + int16_t *mb = h->mb + (16*(16 + 16*chroma_idx) << pixel_shift); for (i8x8=0; i8x8non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); } - s->current_picture.f.qscale_table[mb_xy] = s->qscale; + h->cur_pic.f.qscale_table[mb_xy] = h->qscale; write_back_non_zero_count(h); return 0; diff --git a/mythtv/external/FFmpeg/libavcodec/h264_direct.c b/mythtv/external/FFmpeg/libavcodec/h264_direct.c index 54af4742e49..c6be4557667 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264_direct.c +++ b/mythtv/external/FFmpeg/libavcodec/h264_direct.c @@ -26,7 +26,6 @@ */ #include "internal.h" -#include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" #include "h264.h" @@ -50,14 +49,13 @@ static int get_scale_factor(H264Context * const h, int poc, int poc1, int i){ } void ff_h264_direct_dist_scale_factor(H264Context * const h){ - MpegEncContext * const s = &h->s; - const int poc = h->s.current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ]; + const int poc = h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD]; const int poc1 = h->ref_list[1][0].poc; int i, field; if (FRAME_MBAFF) for (field = 0; field < 2; field++){ - const int poc = h->s.current_picture_ptr->field_poc[field]; + const int poc = h->cur_pic_ptr->field_poc[field]; const int poc1 = h->ref_list[1][0].field_poc[field]; for (i = 0; i < 2 * h->ref_count[0]; i++) h->dist_scale_factor_field[field][i^field] = @@ -70,12 +68,11 @@ void ff_h264_direct_dist_scale_factor(H264Context * const h){ } static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){ - MpegEncContext * const s = &h->s; Picture * const ref1 = &h->ref_list[1][0]; int j, old_ref, rfield; int start= mbafi ? 16 : 0; int end = mbafi ? 16+2*h->ref_count[0] : h->ref_count[0]; - int interl= mbafi || s->picture_structure != PICT_FRAME; + int interl= mbafi || h->picture_structure != PICT_FRAME; /* bogus; fills in for missing frames */ memset(map[list], 0, sizeof(map[list])); @@ -104,11 +101,10 @@ static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, } void ff_h264_direct_ref_list_init(H264Context * const h){ - MpegEncContext * const s = &h->s; Picture * const ref1 = &h->ref_list[1][0]; - Picture * const cur = s->current_picture_ptr; + Picture * const cur = h->cur_pic_ptr; int list, j, field; - int sidx= (s->picture_structure&1)^1; + int sidx= (h->picture_structure&1)^1; int ref1sidx = (ref1->f.reference&1)^1; for(list=0; list<2; list++){ @@ -117,7 +113,7 @@ void ff_h264_direct_ref_list_init(H264Context * const h){ cur->ref_poc[sidx][list][j] = 4 * h->ref_list[list][j].frame_num + (h->ref_list[list][j].f.reference & 3); } - if(s->picture_structure == PICT_FRAME){ + if(h->picture_structure == PICT_FRAME){ memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0])); memcpy(cur->ref_poc [1], cur->ref_poc [0], sizeof(cur->ref_poc [0])); } @@ -125,12 +121,12 @@ void ff_h264_direct_ref_list_init(H264Context * const h){ cur->mbaff= FRAME_MBAFF; h->col_fieldoff= 0; - if(s->picture_structure == PICT_FRAME){ - int cur_poc = s->current_picture_ptr->poc; + if(h->picture_structure == PICT_FRAME){ + int cur_poc = h->cur_pic_ptr->poc; int *col_poc = h->ref_list[1]->field_poc; h->col_parity= (FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc)); ref1sidx=sidx= h->col_parity; - } else if (!(s->picture_structure & h->ref_list[1][0].f.reference) && !h->ref_list[1][0].mbaff) { // FL -> FL & differ parity + } else if (!(h->picture_structure & h->ref_list[1][0].f.reference) && !h->ref_list[1][0].mbaff) { // FL -> FL & differ parity h->col_fieldoff = 2 * h->ref_list[1][0].f.reference - 3; } @@ -149,9 +145,9 @@ static void await_reference_mb_row(H264Context * const h, Picture *ref, int mb_y { int ref_field = ref->f.reference - 1; int ref_field_picture = ref->field_picture; - int ref_height = 16*h->s.mb_height >> ref_field_picture; + int ref_height = 16*h->mb_height >> ref_field_picture; - if(!HAVE_THREADS || !(h->s.avctx->active_thread_type&FF_THREAD_FRAME)) + if(!HAVE_THREADS || !(h->avctx->active_thread_type&FF_THREAD_FRAME)) return; //FIXME it can be safe to access mb stuff @@ -163,10 +159,9 @@ static void await_reference_mb_row(H264Context * const h, Picture *ref, int mb_y } static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ - MpegEncContext * const s = &h->s; int b8_stride = 2; int b4_stride = h->b_stride; - int mb_xy = h->mb_xy, mb_y = s->mb_y; + int mb_xy = h->mb_xy, mb_y = h->mb_y; int mb_type_col[2]; const int16_t (*l1mv0)[2], (*l1mv1)[2]; const int8_t *l1ref0, *l1ref1; @@ -179,7 +174,7 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ assert(h->ref_list[1][0].f.reference & 3); - await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type)); + await_reference_mb_row(h, &h->ref_list[1][0], h->mb_y + !!IS_INTERLACED(*mb_type)); #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM) @@ -241,21 +236,21 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ if (IS_INTERLACED(h->ref_list[1][0].f.mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL - mb_y = (s->mb_y&~1) + h->col_parity; - mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride; + mb_y = (h->mb_y&~1) + h->col_parity; + mb_xy= h->mb_x + ((h->mb_y&~1) + h->col_parity)*h->mb_stride; b8_stride = 0; }else{ mb_y += h->col_fieldoff; - mb_xy += s->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity + mb_xy += h->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity } goto single_col; }else{ // AFL/AFR/FR/FL -> AFR/FR if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR - mb_y = s->mb_y&~1; - mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride; + mb_y = h->mb_y&~1; + mb_xy= h->mb_x + (h->mb_y&~1)*h->mb_stride; mb_type_col[0] = h->ref_list[1][0].f.mb_type[mb_xy]; - mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + s->mb_stride]; - b8_stride = 2+4*s->mb_stride; + mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + h->mb_stride]; + b8_stride = 2+4*h->mb_stride; b4_stride *= 6; if (IS_INTERLACED(mb_type_col[0]) != IS_INTERLACED(mb_type_col[1])) { mb_type_col[0] &= ~MB_TYPE_INTERLACED; @@ -298,7 +293,7 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ l1ref0 = &h->ref_list[1][0].f.ref_index [0][4 * mb_xy]; l1ref1 = &h->ref_list[1][0].f.ref_index [1][4 * mb_xy]; if(!b8_stride){ - if(s->mb_y&1){ + if(h->mb_y&1){ l1ref0 += 2; l1ref1 += 2; l1mv0 += 2*b4_stride; @@ -414,10 +409,9 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ } static void pred_temp_direct_motion(H264Context * const h, int *mb_type){ - MpegEncContext * const s = &h->s; int b8_stride = 2; int b4_stride = h->b_stride; - int mb_xy = h->mb_xy, mb_y = s->mb_y; + int mb_xy = h->mb_xy, mb_y = h->mb_y; int mb_type_col[2]; const int16_t (*l1mv0)[2], (*l1mv1)[2]; const int8_t *l1ref0, *l1ref1; @@ -427,25 +421,25 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){ assert(h->ref_list[1][0].f.reference & 3); - await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type)); + await_reference_mb_row(h, &h->ref_list[1][0], h->mb_y + !!IS_INTERLACED(*mb_type)); if (IS_INTERLACED(h->ref_list[1][0].f.mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL - mb_y = (s->mb_y&~1) + h->col_parity; - mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride; + mb_y = (h->mb_y&~1) + h->col_parity; + mb_xy= h->mb_x + ((h->mb_y&~1) + h->col_parity)*h->mb_stride; b8_stride = 0; }else{ mb_y += h->col_fieldoff; - mb_xy += s->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity + mb_xy += h->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity } goto single_col; }else{ // AFL/AFR/FR/FL -> AFR/FR if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR - mb_y = s->mb_y&~1; - mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride; + mb_y = h->mb_y&~1; + mb_xy= h->mb_x + (h->mb_y&~1)*h->mb_stride; mb_type_col[0] = h->ref_list[1][0].f.mb_type[mb_xy]; - mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + s->mb_stride]; - b8_stride = 2+4*s->mb_stride; + mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + h->mb_stride]; + b8_stride = 2+4*h->mb_stride; b4_stride *= 6; if (IS_INTERLACED(mb_type_col[0]) != IS_INTERLACED(mb_type_col[1])) { mb_type_col[0] &= ~MB_TYPE_INTERLACED; @@ -489,7 +483,7 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){ l1ref0 = &h->ref_list[1][0].f.ref_index [0][4 * mb_xy]; l1ref1 = &h->ref_list[1][0].f.ref_index [1][4 * mb_xy]; if(!b8_stride){ - if(s->mb_y&1){ + if(h->mb_y&1){ l1ref0 += 2; l1ref1 += 2; l1mv0 += 2*b4_stride; @@ -503,9 +497,9 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){ int ref_offset; if(FRAME_MBAFF && IS_INTERLACED(*mb_type)){ - map_col_to_list0[0] = h->map_col_to_list0_field[s->mb_y&1][0]; - map_col_to_list0[1] = h->map_col_to_list0_field[s->mb_y&1][1]; - dist_scale_factor =h->dist_scale_factor_field[s->mb_y&1]; + map_col_to_list0[0] = h->map_col_to_list0_field[h->mb_y&1][0]; + map_col_to_list0[1] = h->map_col_to_list0_field[h->mb_y&1][1]; + dist_scale_factor =h->dist_scale_factor_field[h->mb_y&1]; } ref_offset = (h->ref_list[1][0].mbaff<<4) & (mb_type_col[0]>>3); //if(h->ref_list[1][0].mbaff && IS_INTERLACED(mb_type_col[0])) ref_offset=16 else 0 diff --git a/mythtv/external/FFmpeg/libavcodec/h264_loopfilter.c b/mythtv/external/FFmpeg/libavcodec/h264_loopfilter.c index 7cd9f691890..13d99f2306e 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264_loopfilter.c +++ b/mythtv/external/FFmpeg/libavcodec/h264_loopfilter.c @@ -25,9 +25,9 @@ * @author Michael Niedermayer */ +#include "libavutil/internal.h" #include "libavutil/intreadwrite.h" #include "internal.h" -#include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" #include "h264.h" @@ -241,8 +241,7 @@ static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, unsigned int uvlinesize, int pixel_shift) { - MpegEncContext * const s = &h->s; - int chroma = CHROMA && !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY)); + int chroma = CHROMA && !(CONFIG_GRAY && (h->flags&CODEC_FLAG_GRAY)); int chroma444 = CHROMA444; int chroma422 = CHROMA422; @@ -254,10 +253,10 @@ static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, int a = h->slice_alpha_c0_offset - qp_bd_offset; int b = h->slice_beta_offset - qp_bd_offset; - int mb_type = s->current_picture.f.mb_type[mb_xy]; - int qp = s->current_picture.f.qscale_table[mb_xy]; - int qp0 = s->current_picture.f.qscale_table[mb_xy - 1]; - int qp1 = s->current_picture.f.qscale_table[h->top_mb_xy]; + int mb_type = h->cur_pic.f.mb_type[mb_xy]; + int qp = h->cur_pic.f.qscale_table[mb_xy]; + int qp0 = h->cur_pic.f.qscale_table[mb_xy - 1]; + int qp1 = h->cur_pic.f.qscale_table[h->top_mb_xy]; int qpc = get_chroma_qp( h, 0, qp ); int qpc0 = get_chroma_qp( h, 0, qp0 ); int qpc1 = get_chroma_qp( h, 0, qp1 ); @@ -462,7 +461,6 @@ static int check_mv(H264Context *h, long b_idx, long bn_idx, int mvy_limit){ } static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize, int mb_xy, int mb_type, int mvy_limit, int first_vertical_edge_done, int a, int b, int chroma, int dir) { - MpegEncContext * const s = &h->s; int edge; int chroma_qp_avg[2]; int chroma444 = CHROMA444; @@ -490,16 +488,16 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u // unsigned int tmp_linesize = 2 * linesize; unsigned int tmp_uvlinesize = 2 * uvlinesize; - int mbn_xy = mb_xy - 2 * s->mb_stride; + int mbn_xy = mb_xy - 2 * h->mb_stride; int j; - for(j=0; j<2; j++, mbn_xy += s->mb_stride){ + for(j=0; j<2; j++, mbn_xy += h->mb_stride){ DECLARE_ALIGNED(8, int16_t, bS)[4]; int qp; - if (IS_INTRA(mb_type | s->current_picture.f.mb_type[mbn_xy])) { + if (IS_INTRA(mb_type | h->cur_pic.f.mb_type[mbn_xy])) { AV_WN64A(bS, 0x0003000300030003ULL); } else { - if (!CABAC && IS_8x8DCT(s->current_picture.f.mb_type[mbn_xy])) { + if (!CABAC && IS_8x8DCT(h->cur_pic.f.mb_type[mbn_xy])) { bS[0]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+0]); bS[1]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+1]); bS[2]= 1+((h->cbp_table[mbn_xy] & 0x8000)||h->non_zero_count_cache[scan8[0]+2]); @@ -514,12 +512,12 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u } // Do not use s->qscale as luma quantizer because it has not the same // value in IPCM macroblocks. - qp = (s->current_picture.f.qscale_table[mb_xy] + s->current_picture.f.qscale_table[mbn_xy] + 1) >> 1; - tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize); - { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } + qp = (h->cur_pic.f.qscale_table[mb_xy] + h->cur_pic.f.qscale_table[mbn_xy] + 1) >> 1; + tprintf(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize); + { int i; for (i = 0; i < 4; i++) tprintf(h->avctx, " bS[%d]:%d", i, bS[i]); tprintf(h->avctx, "\n"); } filter_mb_edgeh( &img_y[j*linesize], tmp_linesize, bS, qp, a, b, h, 0 ); - chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mbn_xy]) + 1) >> 1; - chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mbn_xy]) + 1) >> 1; + chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, h->cur_pic.f.qscale_table[mbn_xy]) + 1) >> 1; + chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, h->cur_pic.f.qscale_table[mbn_xy]) + 1) >> 1; if (chroma) { if (chroma444) { filter_mb_edgeh (&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], a, b, h, 0); @@ -537,7 +535,7 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u if( IS_INTRA(mb_type|mbm_type)) { AV_WN64A(bS, 0x0003000300030003ULL); if ( (!IS_INTERLACED(mb_type|mbm_type)) - || ((FRAME_MBAFF || (s->picture_structure != PICT_FRAME)) && (dir == 0)) + || ((FRAME_MBAFF || (h->picture_structure != PICT_FRAME)) && (dir == 0)) ) AV_WN64A(bS, 0x0004000400040004ULL); } else { @@ -579,12 +577,12 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u // Do not use s->qscale as luma quantizer because it has not the same // value in IPCM macroblocks. if(bS[0]+bS[1]+bS[2]+bS[3]){ - qp = (s->current_picture.f.qscale_table[mb_xy] + s->current_picture.f.qscale_table[mbm_xy] + 1) >> 1; - //tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]); - tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); - //{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } - chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mbm_xy]) + 1) >> 1; - chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mbm_xy]) + 1) >> 1; + qp = (h->cur_pic.f.qscale_table[mb_xy] + h->cur_pic.f.qscale_table[mbm_xy] + 1) >> 1; + //tprintf(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], h->cur_pic.qscale_table[mbn_xy]); + tprintf(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); + //{ int i; for (i = 0; i < 4; i++) tprintf(h->avctx, " bS[%d]:%d", i, bS[i]); tprintf(h->avctx, "\n"); } + chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, h->cur_pic.f.qscale_table[mbm_xy]) + 1) >> 1; + chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, h->cur_pic.f.qscale_table[mbm_xy]) + 1) >> 1; if( dir == 0 ) { filter_mb_edgev( &img_y[0], linesize, bS, qp, a, b, h, 1 ); if (chroma) { @@ -664,10 +662,10 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u /* Filter edge */ // Do not use s->qscale as luma quantizer because it has not the same // value in IPCM macroblocks. - qp = s->current_picture.f.qscale_table[mb_xy]; - //tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]); - tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); - //{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } + qp = h->cur_pic.f.qscale_table[mb_xy]; + //tprintf(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], h->cur_pic.qscale_table[mbn_xy]); + tprintf(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); + //{ int i; for (i = 0; i < 4; i++) tprintf(h->avctx, " bS[%d]:%d", i, bS[i]); tprintf(h->avctx, "\n"); } if( dir == 0 ) { filter_mb_edgev( &img_y[4*edge << h->pixel_shift], linesize, bS, qp, a, b, h, 0 ); if (chroma) { @@ -704,13 +702,12 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u } void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) { - MpegEncContext * const s = &h->s; - const int mb_xy= mb_x + mb_y*s->mb_stride; - const int mb_type = s->current_picture.f.mb_type[mb_xy]; + const int mb_xy= mb_x + mb_y*h->mb_stride; + const int mb_type = h->cur_pic.f.mb_type[mb_xy]; const int mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4; int first_vertical_edge_done = 0; av_unused int dir; - int chroma = CHROMA && !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY)); + int chroma = CHROMA && !(CONFIG_GRAY && (h->flags&CODEC_FLAG_GRAY)); int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); int a = h->slice_alpha_c0_offset - qp_bd_offset; int b = h->slice_beta_offset - qp_bd_offset; @@ -762,9 +759,9 @@ void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint } } - mb_qp = s->current_picture.f.qscale_table[mb_xy]; - mbn0_qp = s->current_picture.f.qscale_table[h->left_mb_xy[0]]; - mbn1_qp = s->current_picture.f.qscale_table[h->left_mb_xy[1]]; + mb_qp = h->cur_pic.f.qscale_table[mb_xy]; + mbn0_qp = h->cur_pic.f.qscale_table[h->left_mb_xy[0]]; + mbn1_qp = h->cur_pic.f.qscale_table[h->left_mb_xy[1]]; qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1; bqp[0] = ( get_chroma_qp( h, 0, mb_qp ) + get_chroma_qp( h, 0, mbn0_qp ) + 1 ) >> 1; @@ -777,8 +774,8 @@ void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint get_chroma_qp( h, 1, mbn1_qp ) + 1 ) >> 1; /* Filter edge */ - tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize); - { int i; for (i = 0; i < 8; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } + tprintf(h->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize); + { int i; for (i = 0; i < 8; i++) tprintf(h->avctx, " bS[%d]:%d", i, bS[i]); tprintf(h->avctx, "\n"); } if(MB_FIELD){ filter_mb_mbaff_edgev ( h, img_y , linesize, bS , 1, qp [0], a, b, 1 ); filter_mb_mbaff_edgev ( h, img_y + 8* linesize, linesize, bS+4, 1, qp [1], a, b, 1 ); diff --git a/mythtv/external/FFmpeg/libavcodec/h264_mb_template.c b/mythtv/external/FFmpeg/libavcodec/h264_mb_template.c index a11009412c9..8830d3444bb 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264_mb_template.c +++ b/mythtv/external/FFmpeg/libavcodec/h264_mb_template.c @@ -40,39 +40,38 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) { - MpegEncContext *const s = &h->s; - const int mb_x = s->mb_x; - const int mb_y = s->mb_y; + const int mb_x = h->mb_x; + const int mb_y = h->mb_y; const int mb_xy = h->mb_xy; - const int mb_type = s->current_picture.f.mb_type[mb_xy]; + const int mb_type = h->cur_pic.f.mb_type[mb_xy]; uint8_t *dest_y, *dest_cb, *dest_cr; int linesize, uvlinesize /*dct_offset*/; int i, j; int *block_offset = &h->block_offset[0]; - const int transform_bypass = !SIMPLE && (s->qscale == 0 && h->sps.transform_bypass); + const int transform_bypass = !SIMPLE && (h->qscale == 0 && h->sps.transform_bypass); /* is_h264 should always be true if SVQ3 is disabled. */ - const int is_h264 = !CONFIG_SVQ3_DECODER || SIMPLE || s->codec_id == AV_CODEC_ID_H264; - void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride); - const int block_h = 16 >> s->chroma_y_shift; + const int is_h264 = !CONFIG_SVQ3_DECODER || SIMPLE || h->avctx->codec_id == AV_CODEC_ID_H264; + void (*idct_add)(uint8_t *dst, int16_t *block, int stride); + const int block_h = 16 >> h->chroma_y_shift; const int chroma422 = CHROMA422; - dest_y = s->current_picture.f.data[0] + ((mb_x << PIXEL_SHIFT) + mb_y * s->linesize) * 16; - dest_cb = s->current_picture.f.data[1] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * s->uvlinesize * block_h; - dest_cr = s->current_picture.f.data[2] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * s->uvlinesize * block_h; + dest_y = h->cur_pic.f.data[0] + ((mb_x << PIXEL_SHIFT) + mb_y * h->linesize) * 16; + dest_cb = h->cur_pic.f.data[1] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * h->uvlinesize * block_h; + dest_cr = h->cur_pic.f.data[2] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * h->uvlinesize * block_h; - s->vdsp.prefetch(dest_y + (s->mb_x & 3) * 4 * s->linesize + (64 << PIXEL_SHIFT), s->linesize, 4); - s->vdsp.prefetch(dest_cb + (s->mb_x & 7) * s->uvlinesize + (64 << PIXEL_SHIFT), dest_cr - dest_cb, 2); + h->vdsp.prefetch(dest_y + (h->mb_x & 3) * 4 * h->linesize + (64 << PIXEL_SHIFT), h->linesize, 4); + h->vdsp.prefetch(dest_cb + (h->mb_x & 7) * h->uvlinesize + (64 << PIXEL_SHIFT), dest_cr - dest_cb, 2); h->list_counts[mb_xy] = h->list_count; if (!SIMPLE && MB_FIELD) { - linesize = h->mb_linesize = s->linesize * 2; - uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2; + linesize = h->mb_linesize = h->linesize * 2; + uvlinesize = h->mb_uvlinesize = h->uvlinesize * 2; block_offset = &h->block_offset[48]; if (mb_y & 1) { // FIXME move out of this function? - dest_y -= s->linesize * 15; - dest_cb -= s->uvlinesize * (block_h - 1); - dest_cr -= s->uvlinesize * (block_h - 1); + dest_y -= h->linesize * 15; + dest_cb -= h->uvlinesize * (block_h - 1); + dest_cr -= h->uvlinesize * (block_h - 1); } if (FRAME_MBAFF) { int list; @@ -81,20 +80,20 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) continue; if (IS_16X16(mb_type)) { int8_t *ref = &h->ref_cache[list][scan8[0]]; - fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (s->mb_y & 1), 1); + fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (h->mb_y & 1), 1); } else { for (i = 0; i < 16; i += 4) { int ref = h->ref_cache[list][scan8[i]]; if (ref >= 0) fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, - 8, (16 + ref) ^ (s->mb_y & 1), 1); + 8, (16 + ref) ^ (h->mb_y & 1), 1); } } } } } else { - linesize = h->mb_linesize = s->linesize; - uvlinesize = h->mb_uvlinesize = s->uvlinesize; + linesize = h->mb_linesize = h->linesize; + uvlinesize = h->mb_uvlinesize = h->uvlinesize; // dct_offset = s->linesize * 16; } @@ -103,7 +102,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) if (PIXEL_SHIFT) { int j; GetBitContext gb; - init_get_bits(&gb, (uint8_t *)h->mb, + init_get_bits(&gb, h->intra_pcm_ptr, ff_h264_mb_sizes[h->sps.chroma_format_idc] * bit_depth); for (i = 0; i < 16; i++) { @@ -111,7 +110,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) for (j = 0; j < 16; j++) tmp_y[j] = get_bits(&gb, bit_depth); } - if (SIMPLE || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { + if (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) { if (!h->sps.chroma_format_idc) { for (i = 0; i < block_h; i++) { uint16_t *tmp_cb = (uint16_t *)(dest_cb + i * uvlinesize); @@ -135,16 +134,16 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) } } else { for (i = 0; i < 16; i++) - memcpy(dest_y + i * linesize, (uint8_t *)h->mb + i * 16, 16); - if (SIMPLE || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { + memcpy(dest_y + i * linesize, h->intra_pcm_ptr + i * 16, 16); + if (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) { if (!h->sps.chroma_format_idc) { for (i = 0; i < 8; i++) { memset(dest_cb + i*uvlinesize, 1 << (bit_depth - 1), 8); memset(dest_cr + i*uvlinesize, 1 << (bit_depth - 1), 8); } } else { - uint8_t *src_cb = (uint8_t *)h->mb + 256; - uint8_t *src_cr = (uint8_t *)h->mb + 256 + block_h * 8; + const uint8_t *src_cb = h->intra_pcm_ptr + 256; + const uint8_t *src_cr = h->intra_pcm_ptr + 256 + block_h * 8; for (i = 0; i < block_h; i++) { memcpy(dest_cb + i * uvlinesize, src_cb + i * 8, 8); memcpy(dest_cr + i * uvlinesize, src_cr + i * 8, 8); @@ -158,7 +157,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1, 0, SIMPLE, PIXEL_SHIFT); - if (SIMPLE || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { + if (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) { h->hpc.pred8x8[h->chroma_pred_mode](dest_cb, uvlinesize); h->hpc.pred8x8[h->chroma_pred_mode](dest_cr, uvlinesize); } @@ -173,14 +172,14 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) } else if (is_h264) { if (chroma422) { FUNC(hl_motion_422)(h, dest_y, dest_cb, dest_cr, - s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab, - s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab, + h->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab, + h->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab, h->h264dsp.weight_h264_pixels_tab, h->h264dsp.biweight_h264_pixels_tab); } else { FUNC(hl_motion_420)(h, dest_y, dest_cb, dest_cr, - s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab, - s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab, + h->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab, + h->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab, h->h264dsp.weight_h264_pixels_tab, h->h264dsp.biweight_h264_pixels_tab); } @@ -189,7 +188,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) hl_decode_mb_idct_luma(h, mb_type, is_h264, SIMPLE, transform_bypass, PIXEL_SHIFT, block_offset, linesize, dest_y, 0); - if ((SIMPLE || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) && + if ((SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) && (h->cbp & 0x30)) { uint8_t *dest[2] = { dest_cb, dest_cr }; if (transform_bypass) { @@ -205,7 +204,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) h->mb + (16 * 16 * 2 << PIXEL_SHIFT), uvlinesize); } else { - idct_add = s->dsp.add_pixels4; + idct_add = h->h264dsp.h264_add_pixels4_clear; for (j = 1; j < 3; j++) { for (i = j * 16; i < j * 16 + 4; i++) if (h->non_zero_count_cache[scan8[i]] || @@ -253,17 +252,13 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) uint8_t *const ptr = dest[j - 1] + block_offset[i]; ff_svq3_add_idct_c(ptr, h->mb + i * 16, uvlinesize, - ff_h264_chroma_qp[0][s->qscale + 12] - 12, 2); + ff_h264_chroma_qp[0][h->qscale + 12] - 12, 2); } } } } } } - if (h->cbp || IS_INTRA(mb_type)) { - s->dsp.clear_blocks(h->mb); - s->dsp.clear_blocks(h->mb + (24 * 16 << PIXEL_SHIFT)); - } } #if !SIMPLE || BITS == 8 @@ -274,33 +269,32 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h) { - MpegEncContext *const s = &h->s; - const int mb_x = s->mb_x; - const int mb_y = s->mb_y; + const int mb_x = h->mb_x; + const int mb_y = h->mb_y; const int mb_xy = h->mb_xy; - const int mb_type = s->current_picture.f.mb_type[mb_xy]; + const int mb_type = h->cur_pic.f.mb_type[mb_xy]; uint8_t *dest[3]; int linesize; int i, j, p; int *block_offset = &h->block_offset[0]; - const int transform_bypass = !SIMPLE && (s->qscale == 0 && h->sps.transform_bypass); - const int plane_count = (SIMPLE || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) ? 3 : 1; + const int transform_bypass = !SIMPLE && (h->qscale == 0 && h->sps.transform_bypass); + const int plane_count = (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) ? 3 : 1; for (p = 0; p < plane_count; p++) { - dest[p] = s->current_picture.f.data[p] + - ((mb_x << PIXEL_SHIFT) + mb_y * s->linesize) * 16; - s->vdsp.prefetch(dest[p] + (s->mb_x & 3) * 4 * s->linesize + (64 << PIXEL_SHIFT), - s->linesize, 4); + dest[p] = h->cur_pic.f.data[p] + + ((mb_x << PIXEL_SHIFT) + mb_y * h->linesize) * 16; + h->vdsp.prefetch(dest[p] + (h->mb_x & 3) * 4 * h->linesize + (64 << PIXEL_SHIFT), + h->linesize, 4); } h->list_counts[mb_xy] = h->list_count; if (!SIMPLE && MB_FIELD) { - linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize * 2; + linesize = h->mb_linesize = h->mb_uvlinesize = h->linesize * 2; block_offset = &h->block_offset[48]; if (mb_y & 1) // FIXME move out of this function? for (p = 0; p < 3; p++) - dest[p] -= s->linesize * 15; + dest[p] -= h->linesize * 15; if (FRAME_MBAFF) { int list; for (list = 0; list < h->list_count; list++) { @@ -308,26 +302,26 @@ static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h) continue; if (IS_16X16(mb_type)) { int8_t *ref = &h->ref_cache[list][scan8[0]]; - fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (s->mb_y & 1), 1); + fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (h->mb_y & 1), 1); } else { for (i = 0; i < 16; i += 4) { int ref = h->ref_cache[list][scan8[i]]; if (ref >= 0) fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, - 8, (16 + ref) ^ (s->mb_y & 1), 1); + 8, (16 + ref) ^ (h->mb_y & 1), 1); } } } } } else { - linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize; + linesize = h->mb_linesize = h->mb_uvlinesize = h->linesize; } if (!SIMPLE && IS_INTRA_PCM(mb_type)) { if (PIXEL_SHIFT) { const int bit_depth = h->sps.bit_depth_luma; GetBitContext gb; - init_get_bits(&gb, (uint8_t *)h->mb, 768 * bit_depth); + init_get_bits(&gb, h->intra_pcm_ptr, 768 * bit_depth); for (p = 0; p < plane_count; p++) for (i = 0; i < 16; i++) { @@ -339,7 +333,7 @@ static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h) for (p = 0; p < plane_count; p++) for (i = 0; i < 16; i++) memcpy(dest[p] + i * linesize, - (uint8_t *)h->mb + p * 256 + i * 16, 16); + h->intra_pcm_ptr + p * 256 + i * 16, 16); } } else { if (IS_INTRA(mb_type)) { @@ -357,8 +351,8 @@ static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h) linesize, 0, 1, SIMPLE, PIXEL_SHIFT); } else { FUNC(hl_motion_444)(h, dest[0], dest[1], dest[2], - s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab, - s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab, + h->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab, + h->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab, h->h264dsp.weight_h264_pixels_tab, h->h264dsp.biweight_h264_pixels_tab); } @@ -368,10 +362,6 @@ static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h) PIXEL_SHIFT, block_offset, linesize, dest[p], p); } - if (h->cbp || IS_INTRA(mb_type)) { - s->dsp.clear_blocks(h->mb); - s->dsp.clear_blocks(h->mb + (24 * 16 << PIXEL_SHIFT)); - } } #endif diff --git a/mythtv/external/FFmpeg/libavcodec/h264_mc_template.c b/mythtv/external/FFmpeg/libavcodec/h264_mc_template.c index a59d6a269c7..2a035af27e6 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264_mc_template.c +++ b/mythtv/external/FFmpeg/libavcodec/h264_mc_template.c @@ -46,7 +46,7 @@ static void mc_part(H264Context *h, int n, int square, int list0, int list1) { if ((h->use_weight == 2 && list0 && list1 && - (h->implicit_weight[h->ref_cache[0][scan8[n]]][h->ref_cache[1][scan8[n]]][h->s.mb_y & 1] != 32)) || + (h->implicit_weight[h->ref_cache[0][scan8[n]]][h->ref_cache[1][scan8[n]]][h->mb_y & 1] != 32)) || h->use_weight == 1) mc_part_weighted(h, n, square, height, delta, dest_y, dest_cb, dest_cr, x_offset, y_offset, qpix_put, chroma_put, @@ -67,13 +67,12 @@ static void MCFUNC(hl_motion)(H264Context *h, uint8_t *dest_y, h264_weight_func *weight_op, h264_biweight_func *weight_avg) { - MpegEncContext *const s = &h->s; const int mb_xy = h->mb_xy; - const int mb_type = s->current_picture.f.mb_type[mb_xy]; + const int mb_type = h->cur_pic.f.mb_type[mb_xy]; av_assert2(IS_INTER(mb_type)); - if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) + if (HAVE_THREADS && (h->avctx->active_thread_type & FF_THREAD_FRAME)) await_references(h); prefetch_motion(h, 0, PIXEL_SHIFT, CHROMA_IDC); diff --git a/mythtv/external/FFmpeg/libavcodec/h264_mvpred.h b/mythtv/external/FFmpeg/libavcodec/h264_mvpred.h index 0a405f77049..41670fcbdcf 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264_mvpred.h +++ b/mythtv/external/FFmpeg/libavcodec/h264_mvpred.h @@ -38,32 +38,31 @@ static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width) { const int topright_ref = h->ref_cache[list][i - 8 + part_width]; - MpegEncContext *s = &h->s; /* there is no consistent mapping of mvs to neighboring locations that will * make mbaff happy, so we can't move all this logic to fill_caches */ if (FRAME_MBAFF) { #define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4) \ const int xy = XY, y4 = Y4; \ - const int mb_type = mb_types[xy + (y4 >> 2) * s->mb_stride]; \ + const int mb_type = mb_types[xy + (y4 >> 2) * h->mb_stride]; \ if (!USES_LIST(mb_type, list)) \ return LIST_NOT_USED; \ - mv = s->current_picture_ptr->f.motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \ + mv = h->cur_pic_ptr->f.motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \ h->mv_cache[list][scan8[0] - 2][0] = mv[0]; \ h->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP; \ - return s->current_picture_ptr->f.ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP; + return h->cur_pic_ptr->f.ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP; if (topright_ref == PART_NOT_AVAILABLE && i >= scan8[0] + 8 && (i & 7) == 4 && h->ref_cache[list][scan8[0] - 1] != PART_NOT_AVAILABLE) { - const uint32_t *mb_types = s->current_picture_ptr->f.mb_type; + const uint32_t *mb_types = h->cur_pic_ptr->f.mb_type; const int16_t *mv; AV_ZERO32(h->mv_cache[list][scan8[0] - 2]); *C = h->mv_cache[list][scan8[0] - 2]; if (!MB_FIELD && IS_INTERLACED(h->left_type[0])) { - SET_DIAG_MV(* 2, >> 1, h->left_mb_xy[0] + s->mb_stride, - (s->mb_y & 1) * 2 + (i >> 5)); + SET_DIAG_MV(* 2, >> 1, h->left_mb_xy[0] + h->mb_stride, + (h->mb_y & 1) * 2 + (i >> 5)); } if (MB_FIELD && !IS_INTERLACED(h->left_type[0])) { // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK. @@ -77,7 +76,7 @@ static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, *C = h->mv_cache[list][i - 8 + part_width]; return topright_ref; } else { - tprintf(s->avctx, "topright MV not available\n"); + tprintf(h->avctx, "topright MV not available\n"); *C = h->mv_cache[list][i - 8 - 1]; return h->ref_cache[list][i - 8 - 1]; @@ -115,7 +114,7 @@ static av_always_inline void pred_motion(H264Context *const h, int n, diagonal_ref = fetch_diagonal_mv(h, &C, index8, list, part_width); match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref); - tprintf(h->s.avctx, "pred_motion match_count=%d\n", match_count); + tprintf(h->avctx, "pred_motion match_count=%d\n", match_count); if (match_count > 1) { //most common *mx = mid_pred(A[0], B[0], C[0]); *my = mid_pred(A[1], B[1], C[1]); @@ -142,10 +141,10 @@ static av_always_inline void pred_motion(H264Context *const h, int n, } } - tprintf(h->s.avctx, + tprintf(h->avctx, "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, - A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list); + A[0], A[1], ref, *mx, *my, h->mb_x, h->mb_y, n, list); } /** @@ -162,8 +161,8 @@ static av_always_inline void pred_16x8_motion(H264Context *const h, const int top_ref = h->ref_cache[list][scan8[0] - 8]; const int16_t *const B = h->mv_cache[list][scan8[0] - 8]; - tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", - top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list); + tprintf(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", + top_ref, B[0], B[1], h->mb_x, h->mb_y, n, list); if (top_ref == ref) { *mx = B[0]; @@ -174,8 +173,8 @@ static av_always_inline void pred_16x8_motion(H264Context *const h, const int left_ref = h->ref_cache[list][scan8[8] - 1]; const int16_t *const A = h->mv_cache[list][scan8[8] - 1]; - tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", - left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); + tprintf(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", + left_ref, A[0], A[1], h->mb_x, h->mb_y, n, list); if (left_ref == ref) { *mx = A[0]; @@ -202,8 +201,8 @@ static av_always_inline void pred_8x16_motion(H264Context *const h, const int left_ref = h->ref_cache[list][scan8[0] - 1]; const int16_t *const A = h->mv_cache[list][scan8[0] - 1]; - tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", - left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); + tprintf(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", + left_ref, A[0], A[1], h->mb_x, h->mb_y, n, list); if (left_ref == ref) { *mx = A[0]; @@ -216,8 +215,8 @@ static av_always_inline void pred_8x16_motion(H264Context *const h, diagonal_ref = fetch_diagonal_mv(h, &C, scan8[4], list, 2); - tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", - diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list); + tprintf(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", + diagonal_ref, C[0], C[1], h->mb_x, h->mb_y, n, list); if (diagonal_ref == ref) { *mx = C[0]; @@ -253,9 +252,8 @@ static av_always_inline void pred_pskip_motion(H264Context *const h) { DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = { 0 }; DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2]; - MpegEncContext *const s = &h->s; - int8_t *ref = s->current_picture.f.ref_index[0]; - int16_t(*mv)[2] = s->current_picture.f.motion_val[0]; + int8_t *ref = h->cur_pic.f.ref_index[0]; + int16_t(*mv)[2] = h->cur_pic.f.motion_val[0]; int top_ref, left_ref, diagonal_ref, match_count, mx, my; const int16_t *A, *B, *C; int b_stride = h->b_stride; @@ -293,8 +291,8 @@ static av_always_inline void pred_pskip_motion(H264Context *const h) goto zeromv; } - tprintf(h->s.avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", - top_ref, left_ref, h->s.mb_x, h->s.mb_y); + tprintf(h->avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", + top_ref, left_ref, h->mb_x, h->mb_y); if (USES_LIST(h->topright_type, 0)) { diagonal_ref = ref[4 * h->topright_mb_xy + 2]; @@ -320,7 +318,7 @@ static av_always_inline void pred_pskip_motion(H264Context *const h) } match_count = !diagonal_ref + !top_ref + !left_ref; - tprintf(h->s.avctx, "pred_pskip_motion match_count=%d\n", match_count); + tprintf(h->avctx, "pred_pskip_motion match_count=%d\n", match_count); if (match_count > 1) { mx = mid_pred(A[0], B[0], C[0]); my = mid_pred(A[1], B[1], C[1]); @@ -350,7 +348,6 @@ static av_always_inline void pred_pskip_motion(H264Context *const h) static void fill_decode_neighbors(H264Context *h, int mb_type) { - MpegEncContext *const s = &h->s; const int mb_xy = h->mb_xy; int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; static const uint8_t left_block_options[4][32] = { @@ -362,7 +359,7 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) h->topleft_partition = -1; - top_xy = mb_xy - (s->mb_stride << MB_FIELD); + top_xy = mb_xy - (h->mb_stride << MB_FIELD); /* Wow, what a mess, why didn't they simplify the interlacing & intra * stuff, I can't imagine that these complex rules are worth it. */ @@ -372,16 +369,16 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1; h->left_block = left_block_options[0]; if (FRAME_MBAFF) { - const int left_mb_field_flag = IS_INTERLACED(s->current_picture.f.mb_type[mb_xy - 1]); + const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.f.mb_type[mb_xy - 1]); const int curr_mb_field_flag = IS_INTERLACED(mb_type); - if (s->mb_y & 1) { + if (h->mb_y & 1) { if (left_mb_field_flag != curr_mb_field_flag) { - left_xy[LBOT] = left_xy[LTOP] = mb_xy - s->mb_stride - 1; + left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1; if (curr_mb_field_flag) { - left_xy[LBOT] += s->mb_stride; + left_xy[LBOT] += h->mb_stride; h->left_block = left_block_options[3]; } else { - topleft_xy += s->mb_stride; + topleft_xy += h->mb_stride; /* take top left mv from the middle of the mb, as opposed * to all other modes which use the bottom right partition */ h->topleft_partition = 0; @@ -390,13 +387,13 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) } } else { if (curr_mb_field_flag) { - topleft_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy - 1] >> 7) & 1) - 1); - topright_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy + 1] >> 7) & 1) - 1); - top_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy] >> 7) & 1) - 1); + topleft_xy += h->mb_stride & (((h->cur_pic.f.mb_type[top_xy - 1] >> 7) & 1) - 1); + topright_xy += h->mb_stride & (((h->cur_pic.f.mb_type[top_xy + 1] >> 7) & 1) - 1); + top_xy += h->mb_stride & (((h->cur_pic.f.mb_type[top_xy] >> 7) & 1) - 1); } if (left_mb_field_flag != curr_mb_field_flag) { if (curr_mb_field_flag) { - left_xy[LBOT] += s->mb_stride; + left_xy[LBOT] += h->mb_stride; h->left_block = left_block_options[3]; } else { h->left_block = left_block_options[2]; @@ -412,11 +409,11 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) h->left_mb_xy[LBOT] = left_xy[LBOT]; //FIXME do we need all in the context? - h->topleft_type = s->current_picture.f.mb_type[topleft_xy]; - h->top_type = s->current_picture.f.mb_type[top_xy]; - h->topright_type = s->current_picture.f.mb_type[topright_xy]; - h->left_type[LTOP] = s->current_picture.f.mb_type[left_xy[LTOP]]; - h->left_type[LBOT] = s->current_picture.f.mb_type[left_xy[LBOT]]; + h->topleft_type = h->cur_pic.f.mb_type[topleft_xy]; + h->top_type = h->cur_pic.f.mb_type[top_xy]; + h->topright_type = h->cur_pic.f.mb_type[topright_xy]; + h->left_type[LTOP] = h->cur_pic.f.mb_type[left_xy[LTOP]]; + h->left_type[LBOT] = h->cur_pic.f.mb_type[left_xy[LBOT]]; if (FMO) { if (h->slice_table[topleft_xy] != h->slice_num) @@ -440,7 +437,6 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) static void fill_decode_caches(H264Context *h, int mb_type) { - MpegEncContext *const s = &h->s; int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; int topleft_type, top_type, topright_type, left_type[LEFT_MBS]; const uint8_t *left_block = h->left_block; @@ -483,7 +479,7 @@ static void fill_decode_caches(H264Context *h, int mb_type) h->left_samples_available &= 0xFF5F; } } else { - int left_typei = s->current_picture.f.mb_type[left_xy[LTOP] + s->mb_stride]; + int left_typei = h->cur_pic.f.mb_type[left_xy[LTOP] + h->mb_stride]; av_assert2(left_xy[LTOP] == left_xy[LBOT]); if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) { @@ -540,7 +536,7 @@ static void fill_decode_caches(H264Context *h, int mb_type) if (top_type) { nnz = h->non_zero_count[top_xy]; AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]); - if (!s->chroma_y_shift) { + if (!h->chroma_y_shift) { AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]); AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]); } else { @@ -605,9 +601,9 @@ static void fill_decode_caches(H264Context *h, int mb_type) int b_stride = h->b_stride; for (list = 0; list < h->list_count; list++) { int8_t *ref_cache = &h->ref_cache[list][scan8[0]]; - int8_t *ref = s->current_picture.f.ref_index[list]; + int8_t *ref = h->cur_pic.f.ref_index[list]; int16_t(*mv_cache)[2] = &h->mv_cache[list][scan8[0]]; - int16_t(*mv)[2] = s->current_picture.f.motion_val[list]; + int16_t(*mv)[2] = h->cur_pic.f.motion_val[list]; if (!USES_LIST(mb_type, list)) continue; av_assert2(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)); @@ -799,7 +795,6 @@ static void fill_decode_caches(H264Context *h, int mb_type) */ static void av_unused decode_mb_skip(H264Context *h) { - MpegEncContext *const s = &h->s; const int mb_xy = h->mb_xy; int mb_type = 0; @@ -825,10 +820,10 @@ static void av_unused decode_mb_skip(H264Context *h) } write_back_motion(h, mb_type); - s->current_picture.f.mb_type[mb_xy] = mb_type; - s->current_picture.f.qscale_table[mb_xy] = s->qscale; - h->slice_table[mb_xy] = h->slice_num; - h->prev_mb_skipped = 1; + h->cur_pic.f.mb_type[mb_xy] = mb_type; + h->cur_pic.f.qscale_table[mb_xy] = h->qscale; + h->slice_table[mb_xy] = h->slice_num; + h->prev_mb_skipped = 1; } #endif /* AVCODEC_H264_MVPRED_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/h264_parser.c b/mythtv/external/FFmpeg/libavcodec/h264_parser.c index 26281958445..44b92b79e33 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264_parser.c +++ b/mythtv/external/FFmpeg/libavcodec/h264_parser.c @@ -36,7 +36,7 @@ static int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_si { int i, j; uint32_t state; - ParseContext *pc = &(h->s.parse_context); + ParseContext *pc = &h->parse_context; int next_avc= h->is_avc ? 0 : buf_size; // mb_addr= pc->mb_addr - 1; @@ -45,7 +45,7 @@ static int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_si state= 7; if(h->is_avc && !h->nal_length_size) - av_log(h->s.avctx, AV_LOG_ERROR, "AVC-parser: nal length size invalid\n"); + av_log(h->avctx, AV_LOG_ERROR, "AVC-parser: nal length size invalid\n"); for(i=0; i= next_avc) { @@ -54,7 +54,7 @@ static int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_si for(j = 0; j < h->nal_length_size; j++) nalsize = (nalsize << 8) | buf[i++]; if(nalsize <= 0 || nalsize > buf_size - i){ - av_log(h->s.avctx, AV_LOG_ERROR, "AVC-parser: nal size %d remaining %d\n", nalsize, buf_size - i); + av_log(h->avctx, AV_LOG_ERROR, "AVC-parser: nal size %d remaining %d\n", nalsize, buf_size - i); return buf_size; } next_avc= i + nalsize; @@ -153,7 +153,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, s->pict_type = AV_PICTURE_TYPE_I; s->key_frame = 0; - h->s.avctx= avctx; + h->avctx= avctx; h->sei_recovery_frame_cnt = -1; h->sei_dpb_output_delay = 0; h->sei_cpb_removal_delay = -1; @@ -171,7 +171,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, for (i = 0; i < h->nal_length_size; i++) nalsize = (nalsize << 8) | *buf++; if (nalsize <= 0 || nalsize > buf_end - buf) { - av_log(h->s.avctx, AV_LOG_ERROR, "AVC: nal size %d\n", nalsize); + av_log(h->avctx, AV_LOG_ERROR, "AVC: nal size %d\n", nalsize); break; } src_length = nalsize; @@ -194,13 +194,13 @@ static inline int parse_nal_units(AVCodecParserContext *s, if (ptr==NULL || dst_length < 0) break; - init_get_bits(&h->s.gb, ptr, 8*dst_length); + init_get_bits(&h->gb, ptr, 8*dst_length); switch(h->nal_unit_type) { case NAL_SPS: ff_h264_decode_seq_parameter_set(h); break; case NAL_PPS: - ff_h264_decode_picture_parameter_set(h, h->s.gb.size_in_bits); + ff_h264_decode_picture_parameter_set(h, h->gb.size_in_bits); break; case NAL_SEI: ff_h264_decode_sei(h); @@ -209,40 +209,40 @@ static inline int parse_nal_units(AVCodecParserContext *s, s->key_frame = 1; /* fall through */ case NAL_SLICE: - get_ue_golomb_long(&h->s.gb); // skip first_mb_in_slice - slice_type = get_ue_golomb_31(&h->s.gb); + get_ue_golomb_long(&h->gb); // skip first_mb_in_slice + slice_type = get_ue_golomb_31(&h->gb); s->pict_type = golomb_to_pict_type[slice_type % 5]; if (h->sei_recovery_frame_cnt >= 0) { /* key frame, since recovery_frame_cnt is set */ s->key_frame = 1; } - pps_id= get_ue_golomb(&h->s.gb); + pps_id= get_ue_golomb(&h->gb); if(pps_id>=MAX_PPS_COUNT) { - av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); + av_log(h->avctx, AV_LOG_ERROR, "pps_id out of range\n"); return -1; } if(!h->pps_buffers[pps_id]) { - av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS referenced\n"); + av_log(h->avctx, AV_LOG_ERROR, "non-existing PPS referenced\n"); return -1; } h->pps= *h->pps_buffers[pps_id]; if(!h->sps_buffers[h->pps.sps_id]) { - av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS referenced\n"); + av_log(h->avctx, AV_LOG_ERROR, "non-existing SPS referenced\n"); return -1; } h->sps = *h->sps_buffers[h->pps.sps_id]; - h->frame_num = get_bits(&h->s.gb, h->sps.log2_max_frame_num); + h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num); avctx->profile = ff_h264_get_profile(&h->sps); avctx->level = h->sps.level_idc; if(h->sps.frame_mbs_only_flag){ - h->s.picture_structure= PICT_FRAME; + h->picture_structure= PICT_FRAME; }else{ - if(get_bits1(&h->s.gb)) { //field_pic_flag - h->s.picture_structure= PICT_TOP_FIELD + get_bits1(&h->s.gb); //bottom_field_flag + if(get_bits1(&h->gb)) { //field_pic_flag + h->picture_structure= PICT_TOP_FIELD + get_bits1(&h->gb); //bottom_field_flag } else { - h->s.picture_structure= PICT_FRAME; + h->picture_structure= PICT_FRAME; } } @@ -268,11 +268,11 @@ static inline int parse_nal_units(AVCodecParserContext *s, s->repeat_pict = 5; break; default: - s->repeat_pict = h->s.picture_structure == PICT_FRAME ? 1 : 0; + s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0; break; } } else { - s->repeat_pict = h->s.picture_structure == PICT_FRAME ? 1 : 0; + s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0; } return 0; /* no need to evaluate the rest */ @@ -282,7 +282,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, if (q264) return 0; /* didn't find a picture! */ - av_log(h->s.avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size); + av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size); return -1; } @@ -292,19 +292,19 @@ static int h264_parse(AVCodecParserContext *s, const uint8_t *buf, int buf_size) { H264Context *h = s->priv_data; - ParseContext *pc = &h->s.parse_context; + ParseContext *pc = &h->parse_context; int next; if (!h->got_first) { h->got_first = 1; if (avctx->extradata_size) { - h->s.avctx = avctx; + h->avctx = avctx; // must be done like in decoder, otherwise opening the parser, // letting it create extradata and then closing and opening again // will cause has_b_frames to be always set. // Note that estimate_timings_from_pts does exactly this. if (!avctx->has_b_frames) - h->s.low_delay = 1; + h->low_delay = 1; ff_h264_decode_extradata(h, avctx->extradata, avctx->extradata_size); } } @@ -374,7 +374,7 @@ static int h264_split(AVCodecContext *avctx, static void close(AVCodecParserContext *s) { H264Context *h = s->priv_data; - ParseContext *pc = &h->s.parse_context; + ParseContext *pc = &h->parse_context; av_free(pc->buffer); ff_h264_free_context(h); @@ -384,7 +384,7 @@ static int init(AVCodecParserContext *s) { H264Context *h = s->priv_data; h->thread_context[0] = h; - h->s.slice_context_count = 1; + h->slice_context_count = 1; return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/h264_ps.c b/mythtv/external/FFmpeg/libavcodec/h264_ps.c index f8439b110cd..8638ce267d6 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264_ps.c +++ b/mythtv/external/FFmpeg/libavcodec/h264_ps.c @@ -27,7 +27,6 @@ #include "libavutil/imgutils.h" #include "internal.h" -#include "dsputil.h" #include "avcodec.h" #include "h264.h" #include "h264data.h" //FIXME FIXME FIXME (just for zigzag_scan) @@ -151,46 +150,44 @@ static const uint8_t default_scaling8[2][64]={ }}; static inline int decode_hrd_parameters(H264Context *h, SPS *sps){ - MpegEncContext * const s = &h->s; int cpb_count, i; - cpb_count = get_ue_golomb_31(&s->gb) + 1; + cpb_count = get_ue_golomb_31(&h->gb) + 1; if(cpb_count > 32U){ - av_log(h->s.avctx, AV_LOG_ERROR, "cpb_count %d invalid\n", cpb_count); + av_log(h->avctx, AV_LOG_ERROR, "cpb_count %d invalid\n", cpb_count); return -1; } - get_bits(&s->gb, 4); /* bit_rate_scale */ - get_bits(&s->gb, 4); /* cpb_size_scale */ + get_bits(&h->gb, 4); /* bit_rate_scale */ + get_bits(&h->gb, 4); /* cpb_size_scale */ for(i=0; igb); /* bit_rate_value_minus1 */ - get_ue_golomb_long(&s->gb); /* cpb_size_value_minus1 */ - get_bits1(&s->gb); /* cbr_flag */ + get_ue_golomb_long(&h->gb); /* bit_rate_value_minus1 */ + get_ue_golomb_long(&h->gb); /* cpb_size_value_minus1 */ + get_bits1(&h->gb); /* cbr_flag */ } - sps->initial_cpb_removal_delay_length = get_bits(&s->gb, 5) + 1; - sps->cpb_removal_delay_length = get_bits(&s->gb, 5) + 1; - sps->dpb_output_delay_length = get_bits(&s->gb, 5) + 1; - sps->time_offset_length = get_bits(&s->gb, 5); + sps->initial_cpb_removal_delay_length = get_bits(&h->gb, 5) + 1; + sps->cpb_removal_delay_length = get_bits(&h->gb, 5) + 1; + sps->dpb_output_delay_length = get_bits(&h->gb, 5) + 1; + sps->time_offset_length = get_bits(&h->gb, 5); sps->cpb_cnt = cpb_count; return 0; } static inline int decode_vui_parameters(H264Context *h, SPS *sps){ - MpegEncContext * const s = &h->s; int aspect_ratio_info_present_flag; unsigned int aspect_ratio_idc; - aspect_ratio_info_present_flag= get_bits1(&s->gb); + aspect_ratio_info_present_flag= get_bits1(&h->gb); if( aspect_ratio_info_present_flag ) { - aspect_ratio_idc= get_bits(&s->gb, 8); + aspect_ratio_idc= get_bits(&h->gb, 8); if( aspect_ratio_idc == EXTENDED_SAR ) { - sps->sar.num= get_bits(&s->gb, 16); - sps->sar.den= get_bits(&s->gb, 16); + sps->sar.num= get_bits(&h->gb, 16); + sps->sar.den= get_bits(&h->gb, 16); }else if(aspect_ratio_idc < FF_ARRAY_ELEMS(pixel_aspect)){ sps->sar= pixel_aspect[aspect_ratio_idc]; }else{ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal aspect ratio\n"); + av_log(h->avctx, AV_LOG_ERROR, "illegal aspect ratio\n"); return -1; } }else{ @@ -199,20 +196,20 @@ static inline int decode_vui_parameters(H264Context *h, SPS *sps){ } // s->avctx->aspect_ratio= sar_width*s->width / (float)(s->height*sar_height); - if(get_bits1(&s->gb)){ /* overscan_info_present_flag */ - get_bits1(&s->gb); /* overscan_appropriate_flag */ + if(get_bits1(&h->gb)){ /* overscan_info_present_flag */ + get_bits1(&h->gb); /* overscan_appropriate_flag */ } - sps->video_signal_type_present_flag = get_bits1(&s->gb); + sps->video_signal_type_present_flag = get_bits1(&h->gb); if(sps->video_signal_type_present_flag){ - get_bits(&s->gb, 3); /* video_format */ - sps->full_range = get_bits1(&s->gb); /* video_full_range_flag */ + get_bits(&h->gb, 3); /* video_format */ + sps->full_range = get_bits1(&h->gb); /* video_full_range_flag */ - sps->colour_description_present_flag = get_bits1(&s->gb); + sps->colour_description_present_flag = get_bits1(&h->gb); if(sps->colour_description_present_flag){ - sps->color_primaries = get_bits(&s->gb, 8); /* colour_primaries */ - sps->color_trc = get_bits(&s->gb, 8); /* transfer_characteristics */ - sps->colorspace = get_bits(&s->gb, 8); /* matrix_coefficients */ + sps->color_primaries = get_bits(&h->gb, 8); /* colour_primaries */ + sps->color_trc = get_bits(&h->gb, 8); /* transfer_characteristics */ + sps->colorspace = get_bits(&h->gb, 8); /* matrix_coefficients */ if (sps->color_primaries >= AVCOL_PRI_NB) sps->color_primaries = AVCOL_PRI_UNSPECIFIED; if (sps->color_trc >= AVCOL_TRC_NB) @@ -222,58 +219,58 @@ static inline int decode_vui_parameters(H264Context *h, SPS *sps){ } } - if(get_bits1(&s->gb)){ /* chroma_location_info_present_flag */ - s->avctx->chroma_sample_location = get_ue_golomb(&s->gb)+1; /* chroma_sample_location_type_top_field */ - get_ue_golomb(&s->gb); /* chroma_sample_location_type_bottom_field */ + if(get_bits1(&h->gb)){ /* chroma_location_info_present_flag */ + h->avctx->chroma_sample_location = get_ue_golomb(&h->gb)+1; /* chroma_sample_location_type_top_field */ + get_ue_golomb(&h->gb); /* chroma_sample_location_type_bottom_field */ } - sps->timing_info_present_flag = get_bits1(&s->gb); + sps->timing_info_present_flag = get_bits1(&h->gb); if(sps->timing_info_present_flag){ - sps->num_units_in_tick = get_bits_long(&s->gb, 32); - sps->time_scale = get_bits_long(&s->gb, 32); + sps->num_units_in_tick = get_bits_long(&h->gb, 32); + sps->time_scale = get_bits_long(&h->gb, 32); if(!sps->num_units_in_tick || !sps->time_scale){ - av_log(h->s.avctx, AV_LOG_ERROR, "time_scale/num_units_in_tick invalid or unsupported (%d/%d)\n", sps->time_scale, sps->num_units_in_tick); + av_log(h->avctx, AV_LOG_ERROR, "time_scale/num_units_in_tick invalid or unsupported (%d/%d)\n", sps->time_scale, sps->num_units_in_tick); return -1; } - sps->fixed_frame_rate_flag = get_bits1(&s->gb); + sps->fixed_frame_rate_flag = get_bits1(&h->gb); } - sps->nal_hrd_parameters_present_flag = get_bits1(&s->gb); + sps->nal_hrd_parameters_present_flag = get_bits1(&h->gb); if(sps->nal_hrd_parameters_present_flag) if(decode_hrd_parameters(h, sps) < 0) return -1; - sps->vcl_hrd_parameters_present_flag = get_bits1(&s->gb); + sps->vcl_hrd_parameters_present_flag = get_bits1(&h->gb); if(sps->vcl_hrd_parameters_present_flag) if(decode_hrd_parameters(h, sps) < 0) return -1; if(sps->nal_hrd_parameters_present_flag || sps->vcl_hrd_parameters_present_flag) - get_bits1(&s->gb); /* low_delay_hrd_flag */ - sps->pic_struct_present_flag = get_bits1(&s->gb); - if(!get_bits_left(&s->gb)) + get_bits1(&h->gb); /* low_delay_hrd_flag */ + sps->pic_struct_present_flag = get_bits1(&h->gb); + if(!get_bits_left(&h->gb)) return 0; - sps->bitstream_restriction_flag = get_bits1(&s->gb); + sps->bitstream_restriction_flag = get_bits1(&h->gb); if(sps->bitstream_restriction_flag){ - get_bits1(&s->gb); /* motion_vectors_over_pic_boundaries_flag */ - get_ue_golomb(&s->gb); /* max_bytes_per_pic_denom */ - get_ue_golomb(&s->gb); /* max_bits_per_mb_denom */ - get_ue_golomb(&s->gb); /* log2_max_mv_length_horizontal */ - get_ue_golomb(&s->gb); /* log2_max_mv_length_vertical */ - sps->num_reorder_frames= get_ue_golomb(&s->gb); - get_ue_golomb(&s->gb); /*max_dec_frame_buffering*/ - - if (get_bits_left(&s->gb) < 0) { + get_bits1(&h->gb); /* motion_vectors_over_pic_boundaries_flag */ + get_ue_golomb(&h->gb); /* max_bytes_per_pic_denom */ + get_ue_golomb(&h->gb); /* max_bits_per_mb_denom */ + get_ue_golomb(&h->gb); /* log2_max_mv_length_horizontal */ + get_ue_golomb(&h->gb); /* log2_max_mv_length_vertical */ + sps->num_reorder_frames= get_ue_golomb(&h->gb); + get_ue_golomb(&h->gb); /*max_dec_frame_buffering*/ + + if (get_bits_left(&h->gb) < 0) { sps->num_reorder_frames=0; sps->bitstream_restriction_flag= 0; } if(sps->num_reorder_frames > 16U /*max_dec_frame_buffering || max_dec_frame_buffering > 16*/){ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal num_reorder_frames %d\n", sps->num_reorder_frames); + av_log(h->avctx, AV_LOG_ERROR, "illegal num_reorder_frames %d\n", sps->num_reorder_frames); return -1; } } - if (get_bits_left(&s->gb) < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, "Overread VUI by %d bits\n", -get_bits_left(&s->gb)); + if (get_bits_left(&h->gb) < 0) { + av_log(h->avctx, AV_LOG_ERROR, "Overread VUI by %d bits\n", -get_bits_left(&h->gb)); return AVERROR_INVALIDDATA; } @@ -282,15 +279,14 @@ static inline int decode_vui_parameters(H264Context *h, SPS *sps){ static void decode_scaling_list(H264Context *h, uint8_t *factors, int size, const uint8_t *jvt_list, const uint8_t *fallback_list){ - MpegEncContext * const s = &h->s; int i, last = 8, next = 8; const uint8_t *scan = size == 16 ? zigzag_scan : ff_zigzag_direct; - if(!get_bits1(&s->gb)) /* matrix not written, we use the predicted one */ + if(!get_bits1(&h->gb)) /* matrix not written, we use the predicted one */ memcpy(factors, fallback_list, size*sizeof(uint8_t)); else for(i=0;igb)) & 0xff; + next = (last + get_se_golomb(&h->gb)) & 0xff; if(!i && !next){ /* matrix not written, we use the preset one */ memcpy(factors, jvt_list, size*sizeof(uint8_t)); break; @@ -301,7 +297,6 @@ static void decode_scaling_list(H264Context *h, uint8_t *factors, int size, static void decode_scaling_matrices(H264Context *h, SPS *sps, PPS *pps, int is_sps, uint8_t (*scaling_matrix4)[16], uint8_t (*scaling_matrix8)[64]){ - MpegEncContext * const s = &h->s; int fallback_sps = !is_sps && sps->scaling_matrix_present; const uint8_t *fallback[4] = { fallback_sps ? sps->scaling_matrix4[0] : default_scaling4[0], @@ -309,7 +304,7 @@ static void decode_scaling_matrices(H264Context *h, SPS *sps, PPS *pps, int is_s fallback_sps ? sps->scaling_matrix8[0] : default_scaling8[0], fallback_sps ? sps->scaling_matrix8[3] : default_scaling8[1] }; - if(get_bits1(&s->gb)){ + if(get_bits1(&h->gb)){ sps->scaling_matrix_present |= is_sps; decode_scaling_list(h,scaling_matrix4[0],16,default_scaling4[0],fallback[0]); // Intra, Y decode_scaling_list(h,scaling_matrix4[1],16,default_scaling4[0],scaling_matrix4[0]); // Intra, Cr @@ -331,25 +326,24 @@ static void decode_scaling_matrices(H264Context *h, SPS *sps, PPS *pps, int is_s } int ff_h264_decode_seq_parameter_set(H264Context *h){ - MpegEncContext * const s = &h->s; int profile_idc, level_idc, constraint_set_flags = 0; unsigned int sps_id; int i, log2_max_frame_num_minus4; SPS *sps; - profile_idc= get_bits(&s->gb, 8); - constraint_set_flags |= get_bits1(&s->gb) << 0; //constraint_set0_flag - constraint_set_flags |= get_bits1(&s->gb) << 1; //constraint_set1_flag - constraint_set_flags |= get_bits1(&s->gb) << 2; //constraint_set2_flag - constraint_set_flags |= get_bits1(&s->gb) << 3; //constraint_set3_flag - constraint_set_flags |= get_bits1(&s->gb) << 4; //constraint_set4_flag - constraint_set_flags |= get_bits1(&s->gb) << 5; //constraint_set5_flag - get_bits(&s->gb, 2); // reserved - level_idc= get_bits(&s->gb, 8); - sps_id= get_ue_golomb_31(&s->gb); + profile_idc= get_bits(&h->gb, 8); + constraint_set_flags |= get_bits1(&h->gb) << 0; //constraint_set0_flag + constraint_set_flags |= get_bits1(&h->gb) << 1; //constraint_set1_flag + constraint_set_flags |= get_bits1(&h->gb) << 2; //constraint_set2_flag + constraint_set_flags |= get_bits1(&h->gb) << 3; //constraint_set3_flag + constraint_set_flags |= get_bits1(&h->gb) << 4; //constraint_set4_flag + constraint_set_flags |= get_bits1(&h->gb) << 5; //constraint_set5_flag + get_bits(&h->gb, 2); // reserved + level_idc= get_bits(&h->gb, 8); + sps_id= get_ue_golomb_31(&h->gb); if(sps_id >= MAX_SPS_COUNT) { - av_log(h->s.avctx, AV_LOG_ERROR, "sps_id (%d) out of range\n", sps_id); + av_log(h->avctx, AV_LOG_ERROR, "sps_id (%d) out of range\n", sps_id); return -1; } sps= av_mallocz(sizeof(SPS)); @@ -372,25 +366,25 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){ sps->profile_idc == 44 || sps->profile_idc == 83 || sps->profile_idc == 86 || sps->profile_idc == 118 || sps->profile_idc == 128 || sps->profile_idc == 144) { - sps->chroma_format_idc= get_ue_golomb_31(&s->gb); + sps->chroma_format_idc= get_ue_golomb_31(&h->gb); if (sps->chroma_format_idc > 3U) { - av_log(h->s.avctx, AV_LOG_ERROR, "chroma_format_idc %d is illegal\n", sps->chroma_format_idc); + av_log(h->avctx, AV_LOG_ERROR, "chroma_format_idc %d is illegal\n", sps->chroma_format_idc); goto fail; } else if(sps->chroma_format_idc == 3) { - sps->residual_color_transform_flag = get_bits1(&s->gb); + sps->residual_color_transform_flag = get_bits1(&h->gb); if(sps->residual_color_transform_flag) { - av_log(h->s.avctx, AV_LOG_ERROR, "separate color planes are not supported\n"); + av_log(h->avctx, AV_LOG_ERROR, "separate color planes are not supported\n"); goto fail; } } - sps->bit_depth_luma = get_ue_golomb(&s->gb) + 8; - sps->bit_depth_chroma = get_ue_golomb(&s->gb) + 8; + sps->bit_depth_luma = get_ue_golomb(&h->gb) + 8; + sps->bit_depth_chroma = get_ue_golomb(&h->gb) + 8; if (sps->bit_depth_luma > 14U || sps->bit_depth_chroma > 14U || sps->bit_depth_luma != sps->bit_depth_chroma) { - av_log(h->s.avctx, AV_LOG_ERROR, "illegal bit depth value (%d, %d)\n", + av_log(h->avctx, AV_LOG_ERROR, "illegal bit depth value (%d, %d)\n", sps->bit_depth_luma, sps->bit_depth_chroma); goto fail; } - sps->transform_bypass = get_bits1(&s->gb); + sps->transform_bypass = get_bits1(&h->gb); decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8); }else{ sps->chroma_format_idc= 1; @@ -398,84 +392,98 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){ sps->bit_depth_chroma = 8; } - log2_max_frame_num_minus4 = get_ue_golomb(&s->gb); + log2_max_frame_num_minus4 = get_ue_golomb(&h->gb); if (log2_max_frame_num_minus4 < MIN_LOG2_MAX_FRAME_NUM - 4 || log2_max_frame_num_minus4 > MAX_LOG2_MAX_FRAME_NUM - 4) { - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "log2_max_frame_num_minus4 out of range (0-12): %d\n", log2_max_frame_num_minus4); goto fail; } sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4; - sps->poc_type= get_ue_golomb_31(&s->gb); + sps->poc_type= get_ue_golomb_31(&h->gb); if(sps->poc_type == 0){ //FIXME #define - unsigned t = get_ue_golomb(&s->gb); + unsigned t = get_ue_golomb(&h->gb); if(t>12){ - av_log(h->s.avctx, AV_LOG_ERROR, "log2_max_poc_lsb (%d) is out of range\n", t); + av_log(h->avctx, AV_LOG_ERROR, "log2_max_poc_lsb (%d) is out of range\n", t); goto fail; } sps->log2_max_poc_lsb= t + 4; } else if(sps->poc_type == 1){//FIXME #define - sps->delta_pic_order_always_zero_flag= get_bits1(&s->gb); - sps->offset_for_non_ref_pic= get_se_golomb(&s->gb); - sps->offset_for_top_to_bottom_field= get_se_golomb(&s->gb); - sps->poc_cycle_length = get_ue_golomb(&s->gb); + sps->delta_pic_order_always_zero_flag= get_bits1(&h->gb); + sps->offset_for_non_ref_pic= get_se_golomb(&h->gb); + sps->offset_for_top_to_bottom_field= get_se_golomb(&h->gb); + sps->poc_cycle_length = get_ue_golomb(&h->gb); if((unsigned)sps->poc_cycle_length >= FF_ARRAY_ELEMS(sps->offset_for_ref_frame)){ - av_log(h->s.avctx, AV_LOG_ERROR, "poc_cycle_length overflow %u\n", sps->poc_cycle_length); + av_log(h->avctx, AV_LOG_ERROR, "poc_cycle_length overflow %u\n", sps->poc_cycle_length); goto fail; } for(i=0; ipoc_cycle_length; i++) - sps->offset_for_ref_frame[i]= get_se_golomb(&s->gb); + sps->offset_for_ref_frame[i]= get_se_golomb(&h->gb); }else if(sps->poc_type != 2){ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); + av_log(h->avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); goto fail; } - sps->ref_frame_count= get_ue_golomb_31(&s->gb); - if (h->s.avctx->codec_tag == MKTAG('S', 'M', 'V', '2')) + sps->ref_frame_count= get_ue_golomb_31(&h->gb); + if (h->avctx->codec_tag == MKTAG('S', 'M', 'V', '2')) sps->ref_frame_count= FFMAX(2, sps->ref_frame_count); if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count > 16U){ - av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n"); + av_log(h->avctx, AV_LOG_ERROR, "too many reference frames\n"); goto fail; } - sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb); - sps->mb_width = get_ue_golomb(&s->gb) + 1; - sps->mb_height= get_ue_golomb(&s->gb) + 1; + sps->gaps_in_frame_num_allowed_flag= get_bits1(&h->gb); + sps->mb_width = get_ue_golomb(&h->gb) + 1; + sps->mb_height= get_ue_golomb(&h->gb) + 1; if((unsigned)sps->mb_width >= INT_MAX/16 || (unsigned)sps->mb_height >= INT_MAX/16 || - av_image_check_size(16*sps->mb_width, 16*sps->mb_height, 0, h->s.avctx)){ - av_log(h->s.avctx, AV_LOG_ERROR, "mb_width/height overflow\n"); + av_image_check_size(16*sps->mb_width, 16*sps->mb_height, 0, h->avctx)){ + av_log(h->avctx, AV_LOG_ERROR, "mb_width/height overflow\n"); goto fail; } - sps->frame_mbs_only_flag= get_bits1(&s->gb); + sps->frame_mbs_only_flag= get_bits1(&h->gb); if(!sps->frame_mbs_only_flag) - sps->mb_aff= get_bits1(&s->gb); + sps->mb_aff= get_bits1(&h->gb); else sps->mb_aff= 0; - sps->direct_8x8_inference_flag= get_bits1(&s->gb); + sps->direct_8x8_inference_flag= get_bits1(&h->gb); #ifndef ALLOW_INTERLACE if(sps->mb_aff) - av_log(h->s.avctx, AV_LOG_ERROR, "MBAFF support not included; enable it at compile-time.\n"); + av_log(h->avctx, AV_LOG_ERROR, "MBAFF support not included; enable it at compile-time.\n"); #endif - sps->crop= get_bits1(&s->gb); + sps->crop= get_bits1(&h->gb); if(sps->crop){ int crop_vertical_limit = sps->chroma_format_idc & 2 ? 16 : 8; int crop_horizontal_limit = sps->chroma_format_idc == 3 ? 16 : 8; - sps->crop_left = get_ue_golomb(&s->gb); - sps->crop_right = get_ue_golomb(&s->gb); - sps->crop_top = get_ue_golomb(&s->gb); - sps->crop_bottom= get_ue_golomb(&s->gb); + sps->crop_left = get_ue_golomb(&h->gb); + sps->crop_right = get_ue_golomb(&h->gb); + sps->crop_top = get_ue_golomb(&h->gb); + sps->crop_bottom= get_ue_golomb(&h->gb); + if (h->avctx->flags2 & CODEC_FLAG2_IGNORE_CROP) { + av_log(h->avctx, AV_LOG_DEBUG, + "discarding sps cropping, " + "original values are l:%u r:%u t:%u b:%u\n", + sps->crop_left, + sps->crop_right, + sps->crop_top, + sps->crop_bottom); + + sps->crop_left = + sps->crop_right = + sps->crop_top = + sps->crop_bottom = 0; + } if(sps->crop_left || sps->crop_top){ - av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completely supported, this could look slightly wrong ... (left: %d, top: %d)\n", sps->crop_left, sps->crop_top); + av_log(h->avctx, AV_LOG_ERROR, "insane cropping not completely supported, this could look slightly wrong ... (left: %d, top: %d)\n", sps->crop_left, sps->crop_top); } if(sps->crop_right >= crop_horizontal_limit || sps->crop_bottom >= crop_vertical_limit){ - av_log(h->s.avctx, AV_LOG_ERROR, "brainfart cropping not supported, cropping disabled (right: %d, bottom: %d)\n", sps->crop_right, sps->crop_bottom); + av_log(h->avctx, AV_LOG_ERROR, "brainfart cropping not supported, cropping disabled (right: %d, bottom: %d)\n", sps->crop_right, sps->crop_bottom); /* It is very unlikely that partial cropping will make anybody happy. * Not cropping at all fixes for example playback of Sisvel 3D streams * in applications supporting Sisvel 3D. */ @@ -491,7 +499,7 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){ sps->crop_bottom= 0; } - sps->vui_parameters_present_flag= get_bits1(&s->gb); + sps->vui_parameters_present_flag= get_bits1(&h->gb); if( sps->vui_parameters_present_flag ) if (decode_vui_parameters(h, sps) < 0) goto fail; @@ -499,9 +507,9 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){ if(!sps->sar.den) sps->sar.den= 1; - if(s->avctx->debug&FF_DEBUG_PICT_INFO){ + if(h->avctx->debug&FF_DEBUG_PICT_INFO){ static const char csp[4][5] = { "Gray", "420", "422", "444" }; - av_log(h->s.avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s %d/%d b%d reo:%d\n", + av_log(h->avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s %d/%d b%d reo:%d\n", sps_id, sps->profile_idc, sps->level_idc, sps->poc_type, sps->ref_frame_count, @@ -547,7 +555,7 @@ static int more_rbsp_data_in_pps(H264Context *h, PPS *pps) if ((profile_idc == 66 || profile_idc == 77 || profile_idc == 88) && (sps->constraint_set_flags & 7)) { - av_log(h->s.avctx, AV_LOG_VERBOSE, + av_log(h->avctx, AV_LOG_VERBOSE, "Current profile doesn't provide more RBSP data in PPS, skipping\n"); return 0; } @@ -556,38 +564,37 @@ static int more_rbsp_data_in_pps(H264Context *h, PPS *pps) } int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){ - MpegEncContext * const s = &h->s; - unsigned int pps_id= get_ue_golomb(&s->gb); + unsigned int pps_id= get_ue_golomb(&h->gb); PPS *pps; const int qp_bd_offset = 6*(h->sps.bit_depth_luma-8); int bits_left; if(pps_id >= MAX_PPS_COUNT) { - av_log(h->s.avctx, AV_LOG_ERROR, "pps_id (%d) out of range\n", pps_id); + av_log(h->avctx, AV_LOG_ERROR, "pps_id (%d) out of range\n", pps_id); return -1; } else if (h->sps.bit_depth_luma > 14) { - av_log(h->s.avctx, AV_LOG_ERROR, "Invalid luma bit depth=%d\n", h->sps.bit_depth_luma); + av_log(h->avctx, AV_LOG_ERROR, "Invalid luma bit depth=%d\n", h->sps.bit_depth_luma); return AVERROR_INVALIDDATA; } else if (h->sps.bit_depth_luma == 11 || h->sps.bit_depth_luma == 13) { - av_log(h->s.avctx, AV_LOG_ERROR, "Unimplemented luma bit depth=%d\n", h->sps.bit_depth_luma); + av_log(h->avctx, AV_LOG_ERROR, "Unimplemented luma bit depth=%d\n", h->sps.bit_depth_luma); return AVERROR_PATCHWELCOME; } pps= av_mallocz(sizeof(PPS)); if(pps == NULL) return -1; - pps->sps_id= get_ue_golomb_31(&s->gb); + pps->sps_id= get_ue_golomb_31(&h->gb); if((unsigned)pps->sps_id>=MAX_SPS_COUNT || h->sps_buffers[pps->sps_id] == NULL){ - av_log(h->s.avctx, AV_LOG_ERROR, "sps_id out of range\n"); + av_log(h->avctx, AV_LOG_ERROR, "sps_id out of range\n"); goto fail; } - pps->cabac= get_bits1(&s->gb); - pps->pic_order_present= get_bits1(&s->gb); - pps->slice_group_count= get_ue_golomb(&s->gb) + 1; + pps->cabac= get_bits1(&h->gb); + pps->pic_order_present= get_bits1(&h->gb); + pps->slice_group_count= get_ue_golomb(&h->gb) + 1; if(pps->slice_group_count > 1 ){ - pps->mb_slice_group_map_type= get_ue_golomb(&s->gb); - av_log(h->s.avctx, AV_LOG_ERROR, "FMO not supported\n"); + pps->mb_slice_group_map_type= get_ue_golomb(&h->gb); + av_log(h->avctx, AV_LOG_ERROR, "FMO not supported\n"); switch(pps->mb_slice_group_map_type){ case 0: #if 0 @@ -622,32 +629,32 @@ int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){ break; } } - pps->ref_count[0]= get_ue_golomb(&s->gb) + 1; - pps->ref_count[1]= get_ue_golomb(&s->gb) + 1; + pps->ref_count[0]= get_ue_golomb(&h->gb) + 1; + pps->ref_count[1]= get_ue_golomb(&h->gb) + 1; if(pps->ref_count[0]-1 > 32-1 || pps->ref_count[1]-1 > 32-1){ - av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); + av_log(h->avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); goto fail; } - pps->weighted_pred= get_bits1(&s->gb); - pps->weighted_bipred_idc= get_bits(&s->gb, 2); - pps->init_qp= get_se_golomb(&s->gb) + 26 + qp_bd_offset; - pps->init_qs= get_se_golomb(&s->gb) + 26 + qp_bd_offset; - pps->chroma_qp_index_offset[0]= get_se_golomb(&s->gb); - pps->deblocking_filter_parameters_present= get_bits1(&s->gb); - pps->constrained_intra_pred= get_bits1(&s->gb); - pps->redundant_pic_cnt_present = get_bits1(&s->gb); + pps->weighted_pred= get_bits1(&h->gb); + pps->weighted_bipred_idc= get_bits(&h->gb, 2); + pps->init_qp= get_se_golomb(&h->gb) + 26 + qp_bd_offset; + pps->init_qs= get_se_golomb(&h->gb) + 26 + qp_bd_offset; + pps->chroma_qp_index_offset[0]= get_se_golomb(&h->gb); + pps->deblocking_filter_parameters_present= get_bits1(&h->gb); + pps->constrained_intra_pred= get_bits1(&h->gb); + pps->redundant_pic_cnt_present = get_bits1(&h->gb); pps->transform_8x8_mode= 0; h->dequant_coeff_pps= -1; //contents of sps/pps can change even if id doesn't, so reinit memcpy(pps->scaling_matrix4, h->sps_buffers[pps->sps_id]->scaling_matrix4, sizeof(pps->scaling_matrix4)); memcpy(pps->scaling_matrix8, h->sps_buffers[pps->sps_id]->scaling_matrix8, sizeof(pps->scaling_matrix8)); - bits_left = bit_length - get_bits_count(&s->gb); + bits_left = bit_length - get_bits_count(&h->gb); if(bits_left > 0 && more_rbsp_data_in_pps(h, pps)){ - pps->transform_8x8_mode= get_bits1(&s->gb); + pps->transform_8x8_mode= get_bits1(&h->gb); decode_scaling_matrices(h, h->sps_buffers[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8); - pps->chroma_qp_index_offset[1]= get_se_golomb(&s->gb); //second_chroma_qp_index_offset + pps->chroma_qp_index_offset[1]= get_se_golomb(&h->gb); //second_chroma_qp_index_offset } else { pps->chroma_qp_index_offset[1]= pps->chroma_qp_index_offset[0]; } @@ -657,8 +664,8 @@ int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){ if(pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1]) pps->chroma_qp_diff= 1; - if(s->avctx->debug&FF_DEBUG_PICT_INFO){ - av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d/%d %s %s %s %s\n", + if(h->avctx->debug&FF_DEBUG_PICT_INFO){ + av_log(h->avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d/%d %s %s %s %s\n", pps_id, pps->sps_id, pps->cabac ? "CABAC" : "CAVLC", pps->slice_group_count, diff --git a/mythtv/external/FFmpeg/libavcodec/h264_refs.c b/mythtv/external/FFmpeg/libavcodec/h264_refs.c index 1f058ee6e39..5d45d3425b6 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264_refs.c +++ b/mythtv/external/FFmpeg/libavcodec/h264_refs.c @@ -27,7 +27,6 @@ #include "libavutil/avassert.h" #include "internal.h" -#include "dsputil.h" #include "avcodec.h" #include "h264.h" #include "golomb.h" @@ -107,7 +106,6 @@ static int add_sorted(Picture **sorted, Picture **src, int len, int limit, int d } int ff_h264_fill_default_ref_list(H264Context *h){ - MpegEncContext * const s = &h->s; int i, len; if(h->slice_type_nos==AV_PICTURE_TYPE_B){ @@ -116,16 +114,16 @@ int ff_h264_fill_default_ref_list(H264Context *h){ int lens[2]; if(FIELD_PICTURE) - cur_poc= s->current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ]; + cur_poc= h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD]; else - cur_poc= s->current_picture_ptr->poc; + cur_poc= h->cur_pic_ptr->poc; for(list= 0; list<2; list++){ len= add_sorted(sorted , h->short_ref, h->short_ref_count, cur_poc, 1^list); len+=add_sorted(sorted+len, h->short_ref, h->short_ref_count, cur_poc, 0^list); av_assert0(len<=32); - len= build_def_list(h->default_ref_list[list] , sorted , len, 0, s->picture_structure); - len+=build_def_list(h->default_ref_list[list]+len, h->long_ref, 16 , 1, s->picture_structure); + len= build_def_list(h->default_ref_list[list] , sorted , len, 0, h->picture_structure); + len+=build_def_list(h->default_ref_list[list]+len, h->long_ref, 16 , 1, h->picture_structure); av_assert0(len<=32); if(len < h->ref_count[list]) @@ -139,19 +137,19 @@ int ff_h264_fill_default_ref_list(H264Context *h){ FFSWAP(Picture, h->default_ref_list[1][0], h->default_ref_list[1][1]); } }else{ - len = build_def_list(h->default_ref_list[0] , h->short_ref, h->short_ref_count, 0, s->picture_structure); - len+= build_def_list(h->default_ref_list[0]+len, h-> long_ref, 16 , 1, s->picture_structure); + len = build_def_list(h->default_ref_list[0] , h->short_ref, h->short_ref_count, 0, h->picture_structure); + len+= build_def_list(h->default_ref_list[0]+len, h-> long_ref, 16 , 1, h->picture_structure); av_assert0(len<=32); if(len < h->ref_count[0]) memset(&h->default_ref_list[0][len], 0, sizeof(Picture)*(h->ref_count[0] - len)); } #ifdef TRACE for (i=0; iref_count[0]; i++) { - tprintf(h->s.avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].f.data[0]); + tprintf(h->avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].f.data[0]); } if(h->slice_type_nos==AV_PICTURE_TYPE_B){ for (i=0; iref_count[1]; i++) { - tprintf(h->s.avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[1][i].f.data[0]); + tprintf(h->avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[1][i].f.data[0]); } } #endif @@ -172,9 +170,7 @@ static void print_long_term(H264Context *h); * described by pic_num */ static int pic_num_extract(H264Context *h, int pic_num, int *structure){ - MpegEncContext * const s = &h->s; - - *structure = s->picture_structure; + *structure = h->picture_structure; if(FIELD_PICTURE){ if (!(pic_num & 1)) /* opposite field */ @@ -186,7 +182,6 @@ static int pic_num_extract(H264Context *h, int pic_num, int *structure){ } int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ - MpegEncContext * const s = &h->s; int list, index, pic_structure; print_short_term(h); @@ -195,11 +190,11 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ for(list=0; listlist_count; list++){ memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); - if(get_bits1(&s->gb)){ + if(get_bits1(&h->gb)){ int pred= h->curr_pic_num; for(index=0; ; index++){ - unsigned int reordering_of_pic_nums_idc= get_ue_golomb_31(&s->gb); + unsigned int reordering_of_pic_nums_idc= get_ue_golomb_31(&h->gb); unsigned int pic_id; int i; Picture *ref = NULL; @@ -208,17 +203,17 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ break; if(index >= h->ref_count[list]){ - av_log(h->s.avctx, AV_LOG_ERROR, "reference count overflow\n"); + av_log(h->avctx, AV_LOG_ERROR, "reference count overflow\n"); return -1; } if(reordering_of_pic_nums_idc<3){ if(reordering_of_pic_nums_idc<2){ - const unsigned int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1; + const unsigned int abs_diff_pic_num= get_ue_golomb(&h->gb) + 1; int frame_num; if(abs_diff_pic_num > h->max_pic_num){ - av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); + av_log(h->avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); return -1; } @@ -242,12 +237,12 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ ref->pic_id= pred; }else{ int long_idx; - pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx + pic_id= get_ue_golomb(&h->gb); //long_term_pic_idx long_idx= pic_num_extract(h, pic_id, &pic_structure); if(long_idx>31){ - av_log(h->s.avctx, AV_LOG_ERROR, "long_term_pic_idx overflow\n"); + av_log(h->avctx, AV_LOG_ERROR, "long_term_pic_idx overflow\n"); return -1; } ref = h->long_ref[long_idx]; @@ -262,7 +257,7 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ } if (i < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, "reference picture missing during reorder\n"); + av_log(h->avctx, AV_LOG_ERROR, "reference picture missing during reorder\n"); memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME } else { for(i=index; i+1ref_count[list]; i++){ @@ -278,7 +273,7 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ } } }else{ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); + av_log(h->avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); return -1; } } @@ -288,7 +283,7 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ for(index= 0; index < h->ref_count[list]; index++){ if (!h->ref_list[list][index].f.data[0]) { int i; - av_log(h->s.avctx, AV_LOG_ERROR, "Missing reference picture, default is %d\n", h->default_ref_list[list][0].poc); + av_log(h->avctx, AV_LOG_ERROR, "Missing reference picture, default is %d\n", h->default_ref_list[list][0].poc); for (i=0; ilast_pocs); i++) h->last_pocs[i] = INT_MIN; if (h->default_ref_list[list][0].f.data[0]) @@ -363,13 +358,12 @@ static inline int unreference_pic(H264Context *h, Picture *pic, int refmask){ * frame number is found */ static Picture * find_short(H264Context *h, int frame_num, int *idx){ - MpegEncContext * const s = &h->s; int i; for(i=0; ishort_ref_count; i++){ Picture *pic= h->short_ref[i]; - if(s->avctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); + if(h->avctx->debug&FF_DEBUG_MMCO) + av_log(h->avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); if(pic->frame_num == frame_num) { *idx = i; return pic; @@ -396,12 +390,11 @@ static void remove_short_at_index(H264Context *h, int i){ * @return the removed picture or NULL if an error occurs */ static Picture * remove_short(H264Context *h, int frame_num, int ref_mask){ - MpegEncContext * const s = &h->s; Picture *pic; int i; - if(s->avctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); + if(h->avctx->debug&FF_DEBUG_MMCO) + av_log(h->avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); pic = find_short(h, frame_num, &i); if (pic){ @@ -456,11 +449,11 @@ void ff_h264_remove_all_refs(H264Context *h){ */ static void print_short_term(H264Context *h) { uint32_t i; - if(h->s.avctx->debug&FF_DEBUG_MMCO) { - av_log(h->s.avctx, AV_LOG_DEBUG, "short term list:\n"); + if(h->avctx->debug&FF_DEBUG_MMCO) { + av_log(h->avctx, AV_LOG_DEBUG, "short term list:\n"); for(i=0; ishort_ref_count; i++){ Picture *pic= h->short_ref[i]; - av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", + av_log(h->avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->f.data[0]); } } @@ -471,12 +464,12 @@ static void print_short_term(H264Context *h) { */ static void print_long_term(H264Context *h) { uint32_t i; - if(h->s.avctx->debug&FF_DEBUG_MMCO) { - av_log(h->s.avctx, AV_LOG_DEBUG, "long term list:\n"); + if(h->avctx->debug&FF_DEBUG_MMCO) { + av_log(h->avctx, AV_LOG_DEBUG, "long term list:\n"); for(i = 0; i < 16; i++){ Picture *pic= h->long_ref[i]; if (pic) { - av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", + av_log(h->avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->f.data[0]); } } @@ -488,8 +481,11 @@ static int check_opcodes(MMCO *mmco1, MMCO *mmco2, int n_mmcos) int i; for (i = 0; i < n_mmcos; i++) { - if (mmco1[i].opcode != mmco2[i].opcode) + if (mmco1[i].opcode != mmco2[i].opcode) { + av_log(NULL, AV_LOG_ERROR, "MMCO opcode [%d, %d] at %d mismatches between slices\n", + mmco1[i].opcode, mmco2[i].opcode, i); return -1; + } } return 0; @@ -497,14 +493,12 @@ static int check_opcodes(MMCO *mmco1, MMCO *mmco2, int n_mmcos) int ff_generate_sliding_window_mmcos(H264Context *h, int first_slice) { - MpegEncContext * const s = &h->s; MMCO mmco_temp[MAX_MMCO_COUNT], *mmco = first_slice ? h->mmco : mmco_temp; int mmco_index = 0, i; if (h->short_ref_count && h->long_ref_count + h->short_ref_count >= h->sps.ref_frame_count && - !(FIELD_PICTURE && !s->first_field && - s->current_picture_ptr->f.reference)) { + !(FIELD_PICTURE && !h->first_field && h->cur_pic_ptr->f.reference)) { mmco[0].opcode = MMCO_SHORT2UNUSED; mmco[0].short_pic_num = h->short_ref[h->short_ref_count - 1]->frame_num; mmco_index = 1; @@ -521,27 +515,26 @@ int ff_generate_sliding_window_mmcos(H264Context *h, int first_slice) } else if (!first_slice && mmco_index >= 0 && (mmco_index != h->mmco_index || (i = check_opcodes(h->mmco, mmco_temp, mmco_index)))) { - av_log(h->s.avctx, AV_LOG_ERROR, - "Inconsistent MMCO state between slices [%d, %d, %d]\n", - mmco_index, h->mmco_index, i); + av_log(h->avctx, AV_LOG_ERROR, + "Inconsistent MMCO state between slices [%d, %d]\n", + mmco_index, h->mmco_index); return AVERROR_INVALIDDATA; } return 0; } int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ - MpegEncContext * const s = &h->s; int i, av_uninit(j); int current_ref_assigned=0, err=0; Picture *av_uninit(pic); - if((s->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0) - av_log(h->s.avctx, AV_LOG_DEBUG, "no mmco here\n"); + if((h->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0) + av_log(h->avctx, AV_LOG_DEBUG, "no mmco here\n"); for(i=0; iavctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_pic_num, h->mmco[i].long_arg); + if(h->avctx->debug&FF_DEBUG_MMCO) + av_log(h->avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_pic_num, h->mmco[i].long_arg); if( mmco[i].opcode == MMCO_SHORT2UNUSED || mmco[i].opcode == MMCO_SHORT2LONG){ @@ -550,7 +543,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ if(!pic){ if(mmco[i].opcode != MMCO_SHORT2LONG || !h->long_ref[mmco[i].long_arg] || h->long_ref[mmco[i].long_arg]->frame_num != frame_num) { - av_log(h->s.avctx, AV_LOG_ERROR, "mmco: unref short failure\n"); + av_log(h->avctx, AV_LOG_ERROR, "mmco: unref short failure\n"); err = AVERROR_INVALIDDATA; } continue; @@ -559,8 +552,8 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ switch(mmco[i].opcode){ case MMCO_SHORT2UNUSED: - if(s->avctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n", h->mmco[i].short_pic_num, h->short_ref_count); + if(h->avctx->debug&FF_DEBUG_MMCO) + av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n", h->mmco[i].short_pic_num, h->short_ref_count); remove_short(h, frame_num, structure ^ PICT_FRAME); break; case MMCO_SHORT2LONG: @@ -579,8 +572,8 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ pic = h->long_ref[j]; if (pic) { remove_long(h, j, structure ^ PICT_FRAME); - } else if(s->avctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref long failure\n"); + } else if(h->avctx->debug&FF_DEBUG_MMCO) + av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref long failure\n"); break; case MMCO_LONG: // Comment below left from previous code as it is an interresting note. @@ -591,15 +584,15 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ * and mark this field valid. */ - if (h->long_ref[mmco[i].long_arg] != s->current_picture_ptr) { + if (h->long_ref[mmco[i].long_arg] != h->cur_pic_ptr) { remove_long(h, mmco[i].long_arg, 0); - h->long_ref[ mmco[i].long_arg ]= s->current_picture_ptr; + h->long_ref[ mmco[i].long_arg ]= h->cur_pic_ptr; h->long_ref[ mmco[i].long_arg ]->long_ref=1; h->long_ref_count++; } - s->current_picture_ptr->f.reference |= s->picture_structure; + h->cur_pic_ptr->f.reference |= h->picture_structure; current_ref_assigned=1; break; case MMCO_SET_MAX_LONG: @@ -617,9 +610,9 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ remove_long(h, j, 0); } h->frame_num= - s->current_picture_ptr->frame_num= 0; + h->cur_pic_ptr->frame_num= 0; h->mmco_reset = 1; - s->current_picture_ptr->mmco_reset=1; + h->cur_pic_ptr->mmco_reset=1; for (j = 0; j < MAX_DELAYED_PIC_COUNT; j++) h->last_pocs[j] = INT_MIN; break; @@ -634,28 +627,28 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ * in long_ref; trying to put it on the short list here is an * error in the encoded bit stream (ref: 7.4.3.3, NOTE 2 and 3). */ - if (h->short_ref_count && h->short_ref[0] == s->current_picture_ptr) { + if (h->short_ref_count && h->short_ref[0] == h->cur_pic_ptr) { /* Just mark the second field valid */ - s->current_picture_ptr->f.reference = PICT_FRAME; - } else if (s->current_picture_ptr->long_ref) { - av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term reference " - "assignment for second field " - "in complementary field pair " - "(first field is long term)\n"); + h->cur_pic_ptr->f.reference = PICT_FRAME; + } else if (h->cur_pic_ptr->long_ref) { + av_log(h->avctx, AV_LOG_ERROR, "illegal short term reference " + "assignment for second field " + "in complementary field pair " + "(first field is long term)\n"); err = AVERROR_INVALIDDATA; } else { - pic= remove_short(h, s->current_picture_ptr->frame_num, 0); + pic= remove_short(h, h->cur_pic_ptr->frame_num, 0); if(pic){ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); + av_log(h->avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); err = AVERROR_INVALIDDATA; } if(h->short_ref_count) memmove(&h->short_ref[1], &h->short_ref[0], h->short_ref_count*sizeof(Picture*)); - h->short_ref[0]= s->current_picture_ptr; + h->short_ref[0]= h->cur_pic_ptr; h->short_ref_count++; - s->current_picture_ptr->f.reference |= s->picture_structure; + h->cur_pic_ptr->f.reference |= h->picture_structure; // do not add more reference frames than allowed after seeing frame num gap if (!mmco_count && h->short_ref_count > h->sps.ref_frame_count) { @@ -671,7 +664,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ * stream. Need to discard one frame. Prevents overrun of the * short_ref and long_ref buffers. */ - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "number of reference frames (%d+%d) exceeds max (%d; probably " "corrupt input), discarding one\n", h->long_ref_count, h->short_ref_count, h->sps.ref_frame_count); @@ -693,25 +686,24 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ print_short_term(h); print_long_term(h); - if(err >= 0 && h->long_ref_count==0 && h->short_ref_count<=2 && h->pps.ref_count[0]<=1 + (s->picture_structure != PICT_FRAME) && s->current_picture_ptr->f.pict_type == AV_PICTURE_TYPE_I){ - s->current_picture_ptr->sync |= 1; - if(!h->s.avctx->has_b_frames) + if(err >= 0 && h->long_ref_count==0 && h->short_ref_count<=2 && h->pps.ref_count[0]<=1 + (h->picture_structure != PICT_FRAME) && h->cur_pic_ptr->f.pict_type == AV_PICTURE_TYPE_I){ + h->cur_pic_ptr->sync |= 1; + if(!h->avctx->has_b_frames) h->sync = 2; } - return (h->s.avctx->err_recognition & AV_EF_EXPLODE) ? err : 0; + return (h->avctx->err_recognition & AV_EF_EXPLODE) ? err : 0; } int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, int first_slice) { - MpegEncContext * const s = &h->s; int i, ret; MMCO mmco_temp[MAX_MMCO_COUNT], *mmco = first_slice ? h->mmco : mmco_temp; int mmco_index = 0; if (h->nal_unit_type == NAL_IDR_SLICE){ // FIXME fields - s->broken_link = get_bits1(gb) - 1; + skip_bits1(gb); // broken_link if (get_bits1(gb)){ mmco[0].opcode = MMCO_LONG; mmco[0].long_arg = 0; @@ -744,7 +736,7 @@ int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, (long_arg >= 16 && !(opcode == MMCO_SET_MAX_LONG && long_arg == 16) && !(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){ - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "illegal long ref in memory management control " "operation %d\n", opcode); return -1; @@ -753,7 +745,7 @@ int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, } if (opcode > (unsigned) MMCO_LONG){ - av_log(h->s.avctx, AV_LOG_ERROR, + av_log(h->avctx, AV_LOG_ERROR, "illegal memory management control operation %d\n", opcode); return -1; @@ -765,7 +757,7 @@ int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, } else { if (first_slice) { ret = ff_generate_sliding_window_mmcos(h, first_slice); - if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE) + if (ret < 0 && h->avctx->err_recognition & AV_EF_EXPLODE) return ret; } mmco_index = -1; @@ -777,9 +769,9 @@ int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, } else if (!first_slice && mmco_index >= 0 && (mmco_index != h->mmco_index || (i = check_opcodes(h->mmco, mmco_temp, mmco_index)))) { - av_log(h->s.avctx, AV_LOG_ERROR, - "Inconsistent MMCO state between slices [%d, %d, %d]\n", - mmco_index, h->mmco_index, i); + av_log(h->avctx, AV_LOG_ERROR, + "Inconsistent MMCO state between slices [%d, %d]\n", + mmco_index, h->mmco_index); return AVERROR_INVALIDDATA; } diff --git a/mythtv/external/FFmpeg/libavcodec/h264_sei.c b/mythtv/external/FFmpeg/libavcodec/h264_sei.c index 62320e2d6ab..ece54f10076 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264_sei.c +++ b/mythtv/external/FFmpeg/libavcodec/h264_sei.c @@ -45,14 +45,13 @@ void ff_h264_reset_sei(H264Context *h) { } static int decode_picture_timing(H264Context *h){ - MpegEncContext * const s = &h->s; if(h->sps.nal_hrd_parameters_present_flag || h->sps.vcl_hrd_parameters_present_flag){ - h->sei_cpb_removal_delay = get_bits_long(&s->gb, h->sps.cpb_removal_delay_length); - h->sei_dpb_output_delay = get_bits_long(&s->gb, h->sps.dpb_output_delay_length); + h->sei_cpb_removal_delay = get_bits_long(&h->gb, h->sps.cpb_removal_delay_length); + h->sei_dpb_output_delay = get_bits_long(&h->gb, h->sps.dpb_output_delay_length); } if(h->sps.pic_struct_present_flag){ unsigned int i, num_clock_ts; - h->sei_pic_struct = get_bits(&s->gb, 4); + h->sei_pic_struct = get_bits(&h->gb, 4); h->sei_ct_type = 0; if (h->sei_pic_struct > SEI_PIC_STRUCT_FRAME_TRIPLING) @@ -61,42 +60,41 @@ static int decode_picture_timing(H264Context *h){ num_clock_ts = sei_num_clock_ts_table[h->sei_pic_struct]; for (i = 0 ; i < num_clock_ts ; i++){ - if(get_bits(&s->gb, 1)){ /* clock_timestamp_flag */ + if(get_bits(&h->gb, 1)){ /* clock_timestamp_flag */ unsigned int full_timestamp_flag; - h->sei_ct_type |= 1<gb, 2); - skip_bits(&s->gb, 1); /* nuit_field_based_flag */ - skip_bits(&s->gb, 5); /* counting_type */ - full_timestamp_flag = get_bits(&s->gb, 1); - skip_bits(&s->gb, 1); /* discontinuity_flag */ - skip_bits(&s->gb, 1); /* cnt_dropped_flag */ - skip_bits(&s->gb, 8); /* n_frames */ + h->sei_ct_type |= 1<gb, 2); + skip_bits(&h->gb, 1); /* nuit_field_based_flag */ + skip_bits(&h->gb, 5); /* counting_type */ + full_timestamp_flag = get_bits(&h->gb, 1); + skip_bits(&h->gb, 1); /* discontinuity_flag */ + skip_bits(&h->gb, 1); /* cnt_dropped_flag */ + skip_bits(&h->gb, 8); /* n_frames */ if(full_timestamp_flag){ - skip_bits(&s->gb, 6); /* seconds_value 0..59 */ - skip_bits(&s->gb, 6); /* minutes_value 0..59 */ - skip_bits(&s->gb, 5); /* hours_value 0..23 */ + skip_bits(&h->gb, 6); /* seconds_value 0..59 */ + skip_bits(&h->gb, 6); /* minutes_value 0..59 */ + skip_bits(&h->gb, 5); /* hours_value 0..23 */ }else{ - if(get_bits(&s->gb, 1)){ /* seconds_flag */ - skip_bits(&s->gb, 6); /* seconds_value range 0..59 */ - if(get_bits(&s->gb, 1)){ /* minutes_flag */ - skip_bits(&s->gb, 6); /* minutes_value 0..59 */ - if(get_bits(&s->gb, 1)) /* hours_flag */ - skip_bits(&s->gb, 5); /* hours_value 0..23 */ + if(get_bits(&h->gb, 1)){ /* seconds_flag */ + skip_bits(&h->gb, 6); /* seconds_value range 0..59 */ + if(get_bits(&h->gb, 1)){ /* minutes_flag */ + skip_bits(&h->gb, 6); /* minutes_value 0..59 */ + if(get_bits(&h->gb, 1)) /* hours_flag */ + skip_bits(&h->gb, 5); /* hours_value 0..23 */ } } } if(h->sps.time_offset_length > 0) - skip_bits(&s->gb, h->sps.time_offset_length); /* time_offset */ + skip_bits(&h->gb, h->sps.time_offset_length); /* time_offset */ } } - if(s->avctx->debug & FF_DEBUG_PICT_INFO) - av_log(s->avctx, AV_LOG_DEBUG, "ct_type:%X pic_struct:%d\n", h->sei_ct_type, h->sei_pic_struct); + if(h->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(h->avctx, AV_LOG_DEBUG, "ct_type:%X pic_struct:%d\n", h->sei_ct_type, h->sei_pic_struct); } return 0; } static int decode_user_data_itu_t_t35(H264Context *h, int size) { - MpegEncContext * const s = &h->s; uint32_t user_identifier; int dtg_active_format; @@ -104,28 +102,28 @@ static int decode_user_data_itu_t_t35(H264Context *h, int size) { return -1; size -= 7; - skip_bits(&s->gb, 8); // country_code - skip_bits(&s->gb, 16); // provider_code - user_identifier = get_bits_long(&s->gb, 32); + skip_bits(&h->gb, 8); // country_code + skip_bits(&h->gb, 16); // provider_code + user_identifier = get_bits_long(&h->gb, 32); switch (user_identifier) { case 0x44544731: // "DTG1" - AFD_data if (size < 1) return -1; - skip_bits(&s->gb, 1); - if (get_bits(&s->gb, 1)) { - skip_bits(&s->gb, 6); + skip_bits(&h->gb, 1); + if (get_bits(&h->gb, 1)) { + skip_bits(&h->gb, 6); if (size < 2) return -1; - skip_bits(&s->gb, 4); - dtg_active_format = get_bits(&s->gb, 4); - s->avctx->dtg_active_format = dtg_active_format; + skip_bits(&h->gb, 4); + dtg_active_format = get_bits(&h->gb, 4); + h->avctx->dtg_active_format = dtg_active_format; } else { - skip_bits(&s->gb, 6); + skip_bits(&h->gb, 6); } break; default: - skip_bits(&s->gb, size * 8); + skip_bits(&h->gb, size * 8); break; } @@ -133,7 +131,6 @@ static int decode_user_data_itu_t_t35(H264Context *h, int size) { } static int decode_unregistered_user_data(H264Context *h, int size){ - MpegEncContext * const s = &h->s; uint8_t user_data[16+256]; int e, build, i; @@ -141,7 +138,7 @@ static int decode_unregistered_user_data(H264Context *h, int size){ return -1; for(i=0; igb, 8); + user_data[i]= get_bits(&h->gb, 8); } user_data[i]= 0; @@ -151,33 +148,30 @@ static int decode_unregistered_user_data(H264Context *h, int size){ if(e==1 && build==1 && !strncmp(user_data+16, "x264 - core 0000", 16)) h->x264_build = 67; - if(s->avctx->debug & FF_DEBUG_BUGS) - av_log(s->avctx, AV_LOG_DEBUG, "user data:\"%s\"\n", user_data+16); + if(h->avctx->debug & FF_DEBUG_BUGS) + av_log(h->avctx, AV_LOG_DEBUG, "user data:\"%s\"\n", user_data+16); for(; igb, 8); + skip_bits(&h->gb, 8); return 0; } static int decode_recovery_point(H264Context *h){ - MpegEncContext * const s = &h->s; - - h->sei_recovery_frame_cnt = get_ue_golomb(&s->gb); - skip_bits(&s->gb, 4); /* 1b exact_match_flag, 1b broken_link_flag, 2b changing_slice_group_idc */ + h->sei_recovery_frame_cnt = get_ue_golomb(&h->gb); + skip_bits(&h->gb, 4); /* 1b exact_match_flag, 1b broken_link_flag, 2b changing_slice_group_idc */ return 0; } static int decode_buffering_period(H264Context *h){ - MpegEncContext * const s = &h->s; unsigned int sps_id; int sched_sel_idx; SPS *sps; - sps_id = get_ue_golomb_31(&s->gb); + sps_id = get_ue_golomb_31(&h->gb); if(sps_id > 31 || !h->sps_buffers[sps_id]) { - av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS %d referenced in buffering period\n", sps_id); + av_log(h->avctx, AV_LOG_ERROR, "non-existing SPS %d referenced in buffering period\n", sps_id); return -1; } sps = h->sps_buffers[sps_id]; @@ -185,14 +179,14 @@ static int decode_buffering_period(H264Context *h){ // NOTE: This is really so duplicated in the standard... See H.264, D.1.1 if (sps->nal_hrd_parameters_present_flag) { for (sched_sel_idx = 0; sched_sel_idx < sps->cpb_cnt; sched_sel_idx++) { - h->initial_cpb_removal_delay[sched_sel_idx] = get_bits_long(&s->gb, sps->initial_cpb_removal_delay_length); - skip_bits(&s->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset + h->initial_cpb_removal_delay[sched_sel_idx] = get_bits_long(&h->gb, sps->initial_cpb_removal_delay_length); + skip_bits(&h->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset } } if (sps->vcl_hrd_parameters_present_flag) { for (sched_sel_idx = 0; sched_sel_idx < sps->cpb_cnt; sched_sel_idx++) { - h->initial_cpb_removal_delay[sched_sel_idx] = get_bits_long(&s->gb, sps->initial_cpb_removal_delay_length); - skip_bits(&s->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset + h->initial_cpb_removal_delay[sched_sel_idx] = get_bits_long(&h->gb, sps->initial_cpb_removal_delay_length); + skip_bits(&h->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset } } @@ -201,27 +195,25 @@ static int decode_buffering_period(H264Context *h){ } int ff_h264_decode_sei(H264Context *h){ - MpegEncContext * const s = &h->s; - - while (get_bits_left(&s->gb) > 16) { + while (get_bits_left(&h->gb) > 16) { int size, type; type=0; do{ - if (get_bits_left(&s->gb) < 8) + if (get_bits_left(&h->gb) < 8) return -1; - type+= show_bits(&s->gb, 8); - }while(get_bits(&s->gb, 8) == 255); + type+= show_bits(&h->gb, 8); + }while(get_bits(&h->gb, 8) == 255); size=0; do{ - if (get_bits_left(&s->gb) < 8) + if (get_bits_left(&h->gb) < 8) return -1; - size+= show_bits(&s->gb, 8); - }while(get_bits(&s->gb, 8) == 255); + size+= show_bits(&h->gb, 8); + }while(get_bits(&h->gb, 8) == 255); - if(s->avctx->debug&FF_DEBUG_STARTCODE) - av_log(h->s.avctx, AV_LOG_DEBUG, "SEI %d len:%d\n", type, size); + if(h->avctx->debug&FF_DEBUG_STARTCODE) + av_log(h->avctx, AV_LOG_DEBUG, "SEI %d len:%d\n", type, size); switch(type){ case SEI_TYPE_PIC_TIMING: // Picture timing SEI @@ -245,11 +237,11 @@ int ff_h264_decode_sei(H264Context *h){ return -1; break; default: - skip_bits(&s->gb, 8*size); + skip_bits(&h->gb, 8*size); } //FIXME check bits here - align_get_bits(&s->gb); + align_get_bits(&h->gb); } return 0; diff --git a/mythtv/external/FFmpeg/libavcodec/h264addpx_template.c b/mythtv/external/FFmpeg/libavcodec/h264addpx_template.c new file mode 100644 index 00000000000..046b6c2e19e --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/h264addpx_template.c @@ -0,0 +1,72 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder + * Copyright (c) 2003-2011 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * H.264 / AVC / MPEG4 part10 DSP functions. + * @author Michael Niedermayer + */ + +#include "bit_depth_template.c" + +static void FUNCC(ff_h264_add_pixels4)(uint8_t *_dst, int16_t *_src, int stride) +{ + int i; + pixel *dst = (pixel *) _dst; + dctcoef *src = (dctcoef *) _src; + stride /= sizeof(pixel); + + for (i = 0; i < 4; i++) { + dst[0] += src[0]; + dst[1] += src[1]; + dst[2] += src[2]; + dst[3] += src[3]; + + dst += stride; + src += 4; + } + + memset(_src, 0, sizeof(dctcoef) * 16); +} + +static void FUNCC(ff_h264_add_pixels8)(uint8_t *_dst, int16_t *_src, int stride) +{ + int i; + pixel *dst = (pixel *) _dst; + dctcoef *src = (dctcoef *) _src; + stride /= sizeof(pixel); + + for (i = 0; i < 8; i++) { + dst[0] += src[0]; + dst[1] += src[1]; + dst[2] += src[2]; + dst[3] += src[3]; + dst[4] += src[4]; + dst[5] += src[5]; + dst[6] += src[6]; + dst[7] += src[7]; + + dst += stride; + src += 8; + } + + memset(_src, 0, sizeof(dctcoef) * 64); +} diff --git a/mythtv/external/FFmpeg/libavcodec/h264chroma.c b/mythtv/external/FFmpeg/libavcodec/h264chroma.c new file mode 100644 index 00000000000..3b780a04e23 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/h264chroma.c @@ -0,0 +1,54 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "h264chroma.h" + +#define BIT_DEPTH 8 +#include "h264chroma_template.c" +#undef BIT_DEPTH + +#define BIT_DEPTH 16 +#include "h264chroma_template.c" +#undef BIT_DEPTH + +#define SET_CHROMA(depth) \ + c->put_h264_chroma_pixels_tab[0] = put_h264_chroma_mc8_ ## depth ## _c; \ + c->put_h264_chroma_pixels_tab[1] = put_h264_chroma_mc4_ ## depth ## _c; \ + c->put_h264_chroma_pixels_tab[2] = put_h264_chroma_mc2_ ## depth ## _c; \ + c->avg_h264_chroma_pixels_tab[0] = avg_h264_chroma_mc8_ ## depth ## _c; \ + c->avg_h264_chroma_pixels_tab[1] = avg_h264_chroma_mc4_ ## depth ## _c; \ + c->avg_h264_chroma_pixels_tab[2] = avg_h264_chroma_mc2_ ## depth ## _c; \ + +void ff_h264chroma_init(H264ChromaContext *c, int bit_depth) +{ + if (bit_depth > 8 && bit_depth <= 16) { + SET_CHROMA(16); + } else { + SET_CHROMA(8); + } + + if (ARCH_ARM) + ff_h264chroma_init_arm(c, bit_depth); + if (ARCH_PPC) + ff_h264chroma_init_ppc(c, bit_depth); + if (ARCH_SH4) + ff_h264chroma_init_sh4(c, bit_depth); + if (ARCH_X86) + ff_h264chroma_init_x86(c, bit_depth); +} diff --git a/mythtv/external/FFmpeg/libavcodec/h264chroma.h b/mythtv/external/FFmpeg/libavcodec/h264chroma.h new file mode 100644 index 00000000000..4e035b0c389 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/h264chroma.h @@ -0,0 +1,38 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_H264CHROMA_H +#define AVCODEC_H264CHROMA_H + +#include + +typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y); + +typedef struct H264ChromaContext { + h264_chroma_mc_func put_h264_chroma_pixels_tab[3]; + h264_chroma_mc_func avg_h264_chroma_pixels_tab[3]; +} H264ChromaContext; + +void ff_h264chroma_init(H264ChromaContext *c, int bit_depth); + +void ff_h264chroma_init_arm(H264ChromaContext *c, int bit_depth); +void ff_h264chroma_init_ppc(H264ChromaContext *c, int bit_depth); +void ff_h264chroma_init_sh4(H264ChromaContext *c, int bit_depth); +void ff_h264chroma_init_x86(H264ChromaContext *c, int bit_depth); + +#endif /* AVCODEC_H264CHROMA_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/h264chroma_template.c b/mythtv/external/FFmpeg/libavcodec/h264chroma_template.c new file mode 100644 index 00000000000..93559d7c685 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/h264chroma_template.c @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2000, 2001 Fabrice Bellard + * Copyright (c) 2002-2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/avassert.h" + +#include "bit_depth_template.c" + +#define H264_CHROMA_MC(OPNAME, OP)\ +static void FUNCC(OPNAME ## h264_chroma_mc2)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\ + pixel *dst = (pixel*)_dst;\ + pixel *src = (pixel*)_src;\ + const int A=(8-x)*(8-y);\ + const int B=( x)*(8-y);\ + const int C=(8-x)*( y);\ + const int D=( x)*( y);\ + int i;\ + stride >>= sizeof(pixel)-1;\ + \ + av_assert2(x<8 && y<8 && x>=0 && y>=0);\ +\ + if(D){\ + for(i=0; i>= sizeof(pixel)-1;\ + \ + av_assert2(x<8 && y<8 && x>=0 && y>=0);\ +\ + if(D){\ + for(i=0; i>= sizeof(pixel)-1;\ + \ + av_assert2(x<8 && y<8 && x>=0 && y>=0);\ +\ + if(D){\ + for(i=0; i>6)+1)>>1) +#define op_put(a, b) a = (((b) + 32)>>6) + +H264_CHROMA_MC(put_ , op_put) +H264_CHROMA_MC(avg_ , op_avg) +#undef op_avg +#undef op_put diff --git a/mythtv/external/FFmpeg/libavcodec/h264dsp.c b/mythtv/external/FFmpeg/libavcodec/h264dsp.c index 69d0536981b..da9e417e8e4 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264dsp.c +++ b/mythtv/external/FFmpeg/libavcodec/h264dsp.c @@ -29,6 +29,7 @@ #include "libavutil/avassert.h" #include "avcodec.h" #include "h264dsp.h" +#include "h264idct.h" #include "libavutil/common.h" #define BIT_DEPTH 8 @@ -51,11 +52,29 @@ #include "h264dsp_template.c" #undef BIT_DEPTH +#define BIT_DEPTH 8 +#include "h264addpx_template.c" +#undef BIT_DEPTH + +#define BIT_DEPTH 16 +#include "h264addpx_template.c" +#undef BIT_DEPTH + void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) { #undef FUNC #define FUNC(a, depth) a ## _ ## depth ## _c +#define ADDPX_DSP(depth) \ + c->h264_add_pixels4_clear = FUNC(ff_h264_add_pixels4, depth);\ + c->h264_add_pixels8_clear = FUNC(ff_h264_add_pixels8, depth) + + if (bit_depth > 8 && bit_depth <= 16) { + ADDPX_DSP(16); + } else { + ADDPX_DSP(8); + } + #define H264_DSP(depth) \ c->h264_idct_add= FUNC(ff_h264_idct_add, depth);\ c->h264_idct8_add= FUNC(ff_h264_idct8_add, depth);\ diff --git a/mythtv/external/FFmpeg/libavcodec/h264dsp.h b/mythtv/external/FFmpeg/libavcodec/h264dsp.h index 45f81a09c8b..98ea15c330a 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264dsp.h +++ b/mythtv/external/FFmpeg/libavcodec/h264dsp.h @@ -29,8 +29,6 @@ #include -#include "dsputil.h" - typedef void (*h264_weight_func)(uint8_t *block, int stride, int height, int log2_denom, int weight, int offset); typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, @@ -80,29 +78,33 @@ typedef struct H264DSPContext { /* IDCT */ void (*h264_idct_add)(uint8_t *dst /*align 4*/, - DCTELEM *block /*align 16*/, int stride); + int16_t *block /*align 16*/, int stride); void (*h264_idct8_add)(uint8_t *dst /*align 8*/, - DCTELEM *block /*align 16*/, int stride); + int16_t *block /*align 16*/, int stride); void (*h264_idct_dc_add)(uint8_t *dst /*align 4*/, - DCTELEM *block /*align 16*/, int stride); + int16_t *block /*align 16*/, int stride); void (*h264_idct8_dc_add)(uint8_t *dst /*align 8*/, - DCTELEM *block /*align 16*/, int stride); + int16_t *block /*align 16*/, int stride); void (*h264_idct_add16)(uint8_t *dst /*align 16*/, const int *blockoffset, - DCTELEM *block /*align 16*/, int stride, + int16_t *block /*align 16*/, int stride, const uint8_t nnzc[15 * 8]); void (*h264_idct8_add4)(uint8_t *dst /*align 16*/, const int *blockoffset, - DCTELEM *block /*align 16*/, int stride, + int16_t *block /*align 16*/, int stride, const uint8_t nnzc[15 * 8]); void (*h264_idct_add8)(uint8_t **dst /*align 16*/, const int *blockoffset, - DCTELEM *block /*align 16*/, int stride, + int16_t *block /*align 16*/, int stride, const uint8_t nnzc[15 * 8]); void (*h264_idct_add16intra)(uint8_t *dst /*align 16*/, const int *blockoffset, - DCTELEM *block /*align 16*/, + int16_t *block /*align 16*/, int stride, const uint8_t nnzc[15 * 8]); - void (*h264_luma_dc_dequant_idct)(DCTELEM *output, - DCTELEM *input /*align 16*/, int qmul); - void (*h264_chroma_dc_dequant_idct)(DCTELEM *block, int qmul); + void (*h264_luma_dc_dequant_idct)(int16_t *output, + int16_t *input /*align 16*/, int qmul); + void (*h264_chroma_dc_dequant_idct)(int16_t *block, int qmul); + + /* bypass-transform */ + void (*h264_add_pixels8_clear)(uint8_t *dst, int16_t *block, int stride); + void (*h264_add_pixels4_clear)(uint8_t *dst, int16_t *block, int stride); } H264DSPContext; void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, diff --git a/mythtv/external/FFmpeg/libavcodec/h264idct.c b/mythtv/external/FFmpeg/libavcodec/h264idct.c index d92025ce01e..6a771affe1c 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264idct.c +++ b/mythtv/external/FFmpeg/libavcodec/h264idct.c @@ -25,6 +25,8 @@ * @author Michael Niedermayer */ +#include "h264idct.h" + #define BIT_DEPTH 8 #include "h264idct_template.c" #undef BIT_DEPTH diff --git a/mythtv/external/FFmpeg/libavcodec/h264idct.h b/mythtv/external/FFmpeg/libavcodec/h264idct.h new file mode 100644 index 00000000000..17e0051497b --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/h264idct.h @@ -0,0 +1,44 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_H264IDCT_H +#define AVCODEC_H264IDCT_H + +#include + +#define H264_IDCT(depth) \ +void ff_h264_idct8_add_ ## depth ## _c(uint8_t *dst, int16_t *block, int stride);\ +void ff_h264_idct_add_ ## depth ## _c(uint8_t *dst, int16_t *block, int stride);\ +void ff_h264_idct8_dc_add_ ## depth ## _c(uint8_t *dst, int16_t *block, int stride);\ +void ff_h264_idct_dc_add_ ## depth ## _c(uint8_t *dst, int16_t *block, int stride);\ +void ff_h264_idct_add16_ ## depth ## _c(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[6*8]);\ +void ff_h264_idct_add16intra_ ## depth ## _c(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[6*8]);\ +void ff_h264_idct8_add4_ ## depth ## _c(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[6*8]);\ +void ff_h264_idct_add8_422_ ## depth ## _c(uint8_t **dest, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[6*8]);\ +void ff_h264_idct_add8_ ## depth ## _c(uint8_t **dest, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[6*8]);\ +void ff_h264_luma_dc_dequant_idct_ ## depth ## _c(int16_t *output, int16_t *input, int qmul);\ +void ff_h264_chroma422_dc_dequant_idct_ ## depth ## _c(int16_t *block, int qmul);\ +void ff_h264_chroma_dc_dequant_idct_ ## depth ## _c(int16_t *block, int qmul); + +H264_IDCT( 8) +H264_IDCT( 9) +H264_IDCT(10) +H264_IDCT(12) +H264_IDCT(14) + +#endif /* AVCODEC_H264IDCT_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/h264idct_template.c b/mythtv/external/FFmpeg/libavcodec/h264idct_template.c index 313732b4665..9f16e1d2e0b 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264idct_template.c +++ b/mythtv/external/FFmpeg/libavcodec/h264idct_template.c @@ -27,27 +27,9 @@ #include "bit_depth_template.c" #include "libavutil/common.h" +#include "h264.h" -#ifndef AVCODEC_H264IDCT_INTERNAL_H -#define AVCODEC_H264IDCT_INTERNAL_H -//FIXME this table is a duplicate from h264data.h, and will be removed once the tables from, h264 have been split -static const uint8_t scan8[16*3]={ - 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8, - 6+ 1*8, 7+ 1*8, 6+ 2*8, 7+ 2*8, - 4+ 3*8, 5+ 3*8, 4+ 4*8, 5+ 4*8, - 6+ 3*8, 7+ 3*8, 6+ 4*8, 7+ 4*8, - 4+ 6*8, 5+ 6*8, 4+ 7*8, 5+ 7*8, - 6+ 6*8, 7+ 6*8, 6+ 7*8, 7+ 7*8, - 4+ 8*8, 5+ 8*8, 4+ 9*8, 5+ 9*8, - 6+ 8*8, 7+ 8*8, 6+ 9*8, 7+ 9*8, - 4+11*8, 5+11*8, 4+12*8, 5+12*8, - 6+11*8, 7+11*8, 6+12*8, 7+12*8, - 4+13*8, 5+13*8, 4+14*8, 5+14*8, - 6+13*8, 7+13*8, 6+14*8, 7+14*8 -}; -#endif - -void FUNCC(ff_h264_idct_add)(uint8_t *_dst, DCTELEM *_block, int stride) +void FUNCC(ff_h264_idct_add)(uint8_t *_dst, int16_t *_block, int stride) { int i; pixel *dst = (pixel*)_dst; @@ -79,9 +61,11 @@ void FUNCC(ff_h264_idct_add)(uint8_t *_dst, DCTELEM *_block, int stride) dst[i + 2*stride]= av_clip_pixel(dst[i + 2*stride] + ((z1 - z2) >> 6)); dst[i + 3*stride]= av_clip_pixel(dst[i + 3*stride] + ((z0 - z3) >> 6)); } + + memset(block, 0, 16 * sizeof(dctcoef)); } -void FUNCC(ff_h264_idct8_add)(uint8_t *_dst, DCTELEM *_block, int stride){ +void FUNCC(ff_h264_idct8_add)(uint8_t *_dst, int16_t *_block, int stride){ int i; pixel *dst = (pixel*)_dst; dctcoef *block = (dctcoef*)_block; @@ -151,14 +135,18 @@ void FUNCC(ff_h264_idct8_add)(uint8_t *_dst, DCTELEM *_block, int stride){ dst[i + 6*stride] = av_clip_pixel( dst[i + 6*stride] + ((b2 - b5) >> 6) ); dst[i + 7*stride] = av_clip_pixel( dst[i + 7*stride] + ((b0 - b7) >> 6) ); } + + memset(block, 0, 64 * sizeof(dctcoef)); } // assumes all AC coefs are 0 -void FUNCC(ff_h264_idct_dc_add)(uint8_t *p_dst, DCTELEM *block, int stride){ +void FUNCC(ff_h264_idct_dc_add)(uint8_t *_dst, int16_t *_block, int stride){ int i, j; - int dc = (((dctcoef*)block)[0] + 32) >> 6; - pixel *dst = (pixel*)p_dst; + pixel *dst = (pixel*)_dst; + dctcoef *block = (dctcoef*)_block; + int dc = (block[0] + 32) >> 6; stride >>= sizeof(pixel)-1; + block[0] = 0; for( j = 0; j < 4; j++ ) { for( i = 0; i < 4; i++ ) @@ -167,10 +155,12 @@ void FUNCC(ff_h264_idct_dc_add)(uint8_t *p_dst, DCTELEM *block, int stride){ } } -void FUNCC(ff_h264_idct8_dc_add)(uint8_t *p_dst, DCTELEM *block, int stride){ +void FUNCC(ff_h264_idct8_dc_add)(uint8_t *_dst, int16_t *_block, int stride){ int i, j; - int dc = (((dctcoef*)block)[0] + 32) >> 6; - pixel *dst = (pixel*)p_dst; + pixel *dst = (pixel*)_dst; + dctcoef *block = (dctcoef*)_block; + int dc = (block[0] + 32) >> 6; + block[0] = 0; stride >>= sizeof(pixel)-1; for( j = 0; j < 8; j++ ) { @@ -180,7 +170,7 @@ void FUNCC(ff_h264_idct8_dc_add)(uint8_t *p_dst, DCTELEM *block, int stride){ } } -void FUNCC(ff_h264_idct_add16)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ +void FUNCC(ff_h264_idct_add16)(uint8_t *dst, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){ int i; for(i=0; i<16; i++){ int nnz = nnzc[ scan8[i] ]; @@ -191,7 +181,7 @@ void FUNCC(ff_h264_idct_add16)(uint8_t *dst, const int *block_offset, DCTELEM *b } } -void FUNCC(ff_h264_idct_add16intra)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ +void FUNCC(ff_h264_idct_add16intra)(uint8_t *dst, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){ int i; for(i=0; i<16; i++){ if(nnzc[ scan8[i] ]) FUNCC(ff_h264_idct_add )(dst + block_offset[i], block + i*16*sizeof(pixel), stride); @@ -199,7 +189,7 @@ void FUNCC(ff_h264_idct_add16intra)(uint8_t *dst, const int *block_offset, DCTEL } } -void FUNCC(ff_h264_idct8_add4)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ +void FUNCC(ff_h264_idct8_add4)(uint8_t *dst, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){ int i; for(i=0; i<16; i+=4){ int nnz = nnzc[ scan8[i] ]; @@ -210,7 +200,7 @@ void FUNCC(ff_h264_idct8_add4)(uint8_t *dst, const int *block_offset, DCTELEM *b } } -void FUNCC(ff_h264_idct_add8)(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ +void FUNCC(ff_h264_idct_add8)(uint8_t **dest, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){ int i, j; for(j=1; j<3; j++){ for(i=j*16; is; - #undef FUNC #undef FUNCC #define FUNC(a, depth) a ## _ ## depth diff --git a/mythtv/external/FFmpeg/libavcodec/h264pred.h b/mythtv/external/FFmpeg/libavcodec/h264pred.h index 33f39447dfc..ed67d2ef43e 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264pred.h +++ b/mythtv/external/FFmpeg/libavcodec/h264pred.h @@ -28,8 +28,8 @@ #ifndef AVCODEC_H264PRED_H #define AVCODEC_H264PRED_H -#include "libavutil/common.h" -#include "dsputil.h" +#include +#include /** * Prediction types @@ -98,15 +98,15 @@ typedef struct H264PredContext { void(*pred16x16[4 + 3 + 2])(uint8_t *src, ptrdiff_t stride); void(*pred4x4_add[2])(uint8_t *pix /*align 4*/, - const DCTELEM *block /*align 16*/, ptrdiff_t stride); + int16_t *block /*align 16*/, ptrdiff_t stride); void(*pred8x8l_add[2])(uint8_t *pix /*align 8*/, - const DCTELEM *block /*align 16*/, ptrdiff_t stride); + int16_t *block /*align 16*/, ptrdiff_t stride); void(*pred8x8_add[3])(uint8_t *pix /*align 8*/, const int *block_offset, - const DCTELEM *block /*align 16*/, ptrdiff_t stride); + int16_t *block /*align 16*/, ptrdiff_t stride); void(*pred16x16_add[3])(uint8_t *pix /*align 16*/, const int *block_offset, - const DCTELEM *block /*align 16*/, ptrdiff_t stride); + int16_t *block /*align 16*/, ptrdiff_t stride); } H264PredContext; void ff_h264_pred_init(H264PredContext *h, int codec_id, diff --git a/mythtv/external/FFmpeg/libavcodec/h264pred_template.c b/mythtv/external/FFmpeg/libavcodec/h264pred_template.c index f08fdf4ba43..8d8d62e0b6f 100644 --- a/mythtv/external/FFmpeg/libavcodec/h264pred_template.c +++ b/mythtv/external/FFmpeg/libavcodec/h264pred_template.c @@ -1132,7 +1132,7 @@ static void FUNCC(pred8x8l_horizontal_up)(uint8_t *_src, int has_topleft, #undef PL #undef SRC -static void FUNCC(pred4x4_vertical_add)(uint8_t *_pix, const DCTELEM *_block, +static void FUNCC(pred4x4_vertical_add)(uint8_t *_pix, int16_t *_block, ptrdiff_t stride) { int i; @@ -1149,9 +1149,11 @@ static void FUNCC(pred4x4_vertical_add)(uint8_t *_pix, const DCTELEM *_block, pix++; block++; } + + memset(_block, 0, sizeof(dctcoef) * 16); } -static void FUNCC(pred4x4_horizontal_add)(uint8_t *_pix, const DCTELEM *_block, +static void FUNCC(pred4x4_horizontal_add)(uint8_t *_pix, int16_t *_block, ptrdiff_t stride) { int i; @@ -1167,9 +1169,11 @@ static void FUNCC(pred4x4_horizontal_add)(uint8_t *_pix, const DCTELEM *_block, pix+= stride; block+= 4; } + + memset(_block, 0, sizeof(dctcoef) * 16); } -static void FUNCC(pred8x8l_vertical_add)(uint8_t *_pix, const DCTELEM *_block, +static void FUNCC(pred8x8l_vertical_add)(uint8_t *_pix, int16_t *_block, ptrdiff_t stride) { int i; @@ -1190,9 +1194,11 @@ static void FUNCC(pred8x8l_vertical_add)(uint8_t *_pix, const DCTELEM *_block, pix++; block++; } + + memset(_block, 0, sizeof(dctcoef) * 64); } -static void FUNCC(pred8x8l_horizontal_add)(uint8_t *_pix, const DCTELEM *_block, +static void FUNCC(pred8x8l_horizontal_add)(uint8_t *_pix, int16_t *_block, ptrdiff_t stride) { int i; @@ -1212,10 +1218,12 @@ static void FUNCC(pred8x8l_horizontal_add)(uint8_t *_pix, const DCTELEM *_block, pix+= stride; block+= 8; } + + memset(_block, 0, sizeof(dctcoef) * 64); } static void FUNCC(pred16x16_vertical_add)(uint8_t *pix, const int *block_offset, - const DCTELEM *block, + int16_t *block, ptrdiff_t stride) { int i; @@ -1225,7 +1233,7 @@ static void FUNCC(pred16x16_vertical_add)(uint8_t *pix, const int *block_offset, static void FUNCC(pred16x16_horizontal_add)(uint8_t *pix, const int *block_offset, - const DCTELEM *block, + int16_t *block, ptrdiff_t stride) { int i; @@ -1234,7 +1242,7 @@ static void FUNCC(pred16x16_horizontal_add)(uint8_t *pix, } static void FUNCC(pred8x8_vertical_add)(uint8_t *pix, const int *block_offset, - const DCTELEM *block, ptrdiff_t stride) + int16_t *block, ptrdiff_t stride) { int i; for(i=0; i<4; i++) @@ -1242,7 +1250,7 @@ static void FUNCC(pred8x8_vertical_add)(uint8_t *pix, const int *block_offset, } static void FUNCC(pred8x16_vertical_add)(uint8_t *pix, const int *block_offset, - const DCTELEM *block, ptrdiff_t stride) + int16_t *block, ptrdiff_t stride) { int i; for(i=0; i<4; i++) @@ -1252,7 +1260,7 @@ static void FUNCC(pred8x16_vertical_add)(uint8_t *pix, const int *block_offset, } static void FUNCC(pred8x8_horizontal_add)(uint8_t *pix, const int *block_offset, - const DCTELEM *block, + int16_t *block, ptrdiff_t stride) { int i; @@ -1262,7 +1270,7 @@ static void FUNCC(pred8x8_horizontal_add)(uint8_t *pix, const int *block_offset, static void FUNCC(pred8x16_horizontal_add)(uint8_t *pix, const int *block_offset, - const DCTELEM *block, ptrdiff_t stride) + int16_t *block, ptrdiff_t stride) { int i; for(i=0; i<4; i++) diff --git a/mythtv/external/FFmpeg/libavcodec/h264qpel.c b/mythtv/external/FFmpeg/libavcodec/h264qpel.c new file mode 100644 index 00000000000..f46da8f6c87 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/h264qpel.c @@ -0,0 +1,104 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder + * Copyright (c) 2003-2010 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "h264qpel.h" + +#define pixeltmp int16_t +#define BIT_DEPTH 8 +#include "h264qpel_template.c" +#undef BIT_DEPTH + +#define BIT_DEPTH 9 +#include "h264qpel_template.c" +#undef BIT_DEPTH + +#define BIT_DEPTH 10 +#include "h264qpel_template.c" +#undef BIT_DEPTH +#undef pixeltmp + +#define pixeltmp int32_t +#define BIT_DEPTH 12 +#include "h264qpel_template.c" +#undef BIT_DEPTH + +#define BIT_DEPTH 14 +#include "h264qpel_template.c" +#undef BIT_DEPTH + + +void ff_h264qpel_init(H264QpelContext *c, int bit_depth) +{ +#undef FUNCC +#define FUNCC(f, depth) f ## _ ## depth ## _c + +#define dspfunc2(PFX, IDX, NUM, depth) \ + c->PFX ## _pixels_tab[IDX][ 0] = FUNCC(PFX ## NUM ## _mc00, depth); \ + c->PFX ## _pixels_tab[IDX][ 1] = FUNCC(PFX ## NUM ## _mc10, depth); \ + c->PFX ## _pixels_tab[IDX][ 2] = FUNCC(PFX ## NUM ## _mc20, depth); \ + c->PFX ## _pixels_tab[IDX][ 3] = FUNCC(PFX ## NUM ## _mc30, depth); \ + c->PFX ## _pixels_tab[IDX][ 4] = FUNCC(PFX ## NUM ## _mc01, depth); \ + c->PFX ## _pixels_tab[IDX][ 5] = FUNCC(PFX ## NUM ## _mc11, depth); \ + c->PFX ## _pixels_tab[IDX][ 6] = FUNCC(PFX ## NUM ## _mc21, depth); \ + c->PFX ## _pixels_tab[IDX][ 7] = FUNCC(PFX ## NUM ## _mc31, depth); \ + c->PFX ## _pixels_tab[IDX][ 8] = FUNCC(PFX ## NUM ## _mc02, depth); \ + c->PFX ## _pixels_tab[IDX][ 9] = FUNCC(PFX ## NUM ## _mc12, depth); \ + c->PFX ## _pixels_tab[IDX][10] = FUNCC(PFX ## NUM ## _mc22, depth); \ + c->PFX ## _pixels_tab[IDX][11] = FUNCC(PFX ## NUM ## _mc32, depth); \ + c->PFX ## _pixels_tab[IDX][12] = FUNCC(PFX ## NUM ## _mc03, depth); \ + c->PFX ## _pixels_tab[IDX][13] = FUNCC(PFX ## NUM ## _mc13, depth); \ + c->PFX ## _pixels_tab[IDX][14] = FUNCC(PFX ## NUM ## _mc23, depth); \ + c->PFX ## _pixels_tab[IDX][15] = FUNCC(PFX ## NUM ## _mc33, depth) + +#define SET_QPEL(depth) \ + dspfunc2(put_h264_qpel, 0, 16, depth); \ + dspfunc2(put_h264_qpel, 1, 8, depth); \ + dspfunc2(put_h264_qpel, 2, 4, depth); \ + dspfunc2(put_h264_qpel, 3, 2, depth); \ + dspfunc2(avg_h264_qpel, 0, 16, depth); \ + dspfunc2(avg_h264_qpel, 1, 8, depth); \ + dspfunc2(avg_h264_qpel, 2, 4, depth) + + switch (bit_depth) { + default: + SET_QPEL(8); + break; + case 9: + SET_QPEL(9); + break; + case 10: + SET_QPEL(10); + break; + case 12: + SET_QPEL(12); + break; + case 14: + SET_QPEL(14); + break; + } + + if (ARCH_ARM) + ff_h264qpel_init_arm(c, bit_depth); + if (ARCH_PPC) + ff_h264qpel_init_ppc(c, bit_depth); + if (ARCH_X86) + ff_h264qpel_init_x86(c, bit_depth); +} diff --git a/mythtv/external/FFmpeg/libavcodec/h264qpel.h b/mythtv/external/FFmpeg/libavcodec/h264qpel.h new file mode 100644 index 00000000000..6abfac042c5 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/h264qpel.h @@ -0,0 +1,38 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder + * Copyright (c) 2003-2010 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_H264QPEL_H +#define AVCODEC_H264QPEL_H + +#include "dsputil.h" + +typedef struct H264QpelContext { + qpel_mc_func put_h264_qpel_pixels_tab[4][16]; + qpel_mc_func avg_h264_qpel_pixels_tab[4][16]; +} H264QpelContext; + +void ff_h264qpel_init(H264QpelContext *c, int bit_depth); + +void ff_h264qpel_init_arm(H264QpelContext *c, int bit_depth); +void ff_h264qpel_init_ppc(H264QpelContext *c, int bit_depth); +void ff_h264qpel_init_x86(H264QpelContext *c, int bit_depth); + +#endif /* AVCODEC_H264QPEL_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/h264qpel_template.c b/mythtv/external/FFmpeg/libavcodec/h264qpel_template.c new file mode 100644 index 00000000000..95950f44dc4 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/h264qpel_template.c @@ -0,0 +1,560 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder + * Copyright (c) 2003-2010 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" +#include "bit_depth_template.c" +#include "hpel_template.c" + +static inline void FUNC(copy_block2)(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h) +{ + int i; + for(i=0; i>= sizeof(pixel)-1;\ + srcStride >>= sizeof(pixel)-1;\ + for(i=0; i>= sizeof(pixel)-1;\ + srcStride >>= sizeof(pixel)-1;\ + for(i=0; i>= sizeof(pixel)-1;\ + srcStride >>= sizeof(pixel)-1;\ + src -= 2*srcStride;\ + for(i=0; i>= sizeof(pixel)-1;\ + srcStride >>= sizeof(pixel)-1;\ + for(i=0; i>= sizeof(pixel)-1;\ + srcStride >>= sizeof(pixel)-1;\ + for(i=0; i>= sizeof(pixel)-1;\ + srcStride >>= sizeof(pixel)-1;\ + src -= 2*srcStride;\ + for(i=0; i>= sizeof(pixel)-1;\ + srcStride >>= sizeof(pixel)-1;\ + for(i=0; i>= sizeof(pixel)-1;\ + srcStride >>= sizeof(pixel)-1;\ + for(i=0; i>= sizeof(pixel)-1;\ + srcStride >>= sizeof(pixel)-1;\ + src -= 2*srcStride;\ + for(i=0; i>5)+1)>>1) +//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7) +#define op_put(a, b) a = CLIP(((b) + 16)>>5) +#define op2_avg(a, b) a = (((a)+CLIP(((b) + 512)>>10)+1)>>1) +#define op2_put(a, b) a = CLIP(((b) + 512)>>10) + +H264_LOWPASS(put_ , op_put, op2_put) +H264_LOWPASS(avg_ , op_avg, op2_avg) +H264_MC(put_, 2) +H264_MC(put_, 4) +H264_MC(put_, 8) +H264_MC(put_, 16) +H264_MC(avg_, 4) +H264_MC(avg_, 8) +H264_MC(avg_, 16) + +#undef op_avg +#undef op_put +#undef op2_avg +#undef op2_put + +#if BIT_DEPTH == 8 +# define put_h264_qpel8_mc00_8_c ff_put_pixels8x8_8_c +# define avg_h264_qpel8_mc00_8_c ff_avg_pixels8x8_8_c +# define put_h264_qpel16_mc00_8_c ff_put_pixels16x16_8_c +# define avg_h264_qpel16_mc00_8_c ff_avg_pixels16x16_8_c +#elif BIT_DEPTH == 9 +# define put_h264_qpel8_mc00_9_c ff_put_pixels8x8_9_c +# define avg_h264_qpel8_mc00_9_c ff_avg_pixels8x8_9_c +# define put_h264_qpel16_mc00_9_c ff_put_pixels16x16_9_c +# define avg_h264_qpel16_mc00_9_c ff_avg_pixels16x16_9_c +#elif BIT_DEPTH == 10 +# define put_h264_qpel8_mc00_10_c ff_put_pixels8x8_10_c +# define avg_h264_qpel8_mc00_10_c ff_avg_pixels8x8_10_c +# define put_h264_qpel16_mc00_10_c ff_put_pixels16x16_10_c +# define avg_h264_qpel16_mc00_10_c ff_avg_pixels16x16_10_c +#elif BIT_DEPTH == 12 +# define put_h264_qpel8_mc00_12_c ff_put_pixels8x8_12_c +# define avg_h264_qpel8_mc00_12_c ff_avg_pixels8x8_12_c +# define put_h264_qpel16_mc00_12_c ff_put_pixels16x16_12_c +# define avg_h264_qpel16_mc00_12_c ff_avg_pixels16x16_12_c +#elif BIT_DEPTH == 14 +# define put_h264_qpel8_mc00_14_c ff_put_pixels8x8_14_c +# define avg_h264_qpel8_mc00_14_c ff_avg_pixels8x8_14_c +# define put_h264_qpel16_mc00_14_c ff_put_pixels16x16_14_c +# define avg_h264_qpel16_mc00_14_c ff_avg_pixels16x16_14_c +#endif diff --git a/mythtv/external/FFmpeg/libavcodec/hpel_template.c b/mythtv/external/FFmpeg/libavcodec/hpel_template.c new file mode 100644 index 00000000000..3b4699927f0 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/hpel_template.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2000, 2001 Fabrice Bellard + * Copyright (c) 2002-2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define DEF_HPEL(OPNAME, OP) \ +static inline void FUNCC(OPNAME ## _pixels2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){\ + int i;\ + for(i=0; ibitstream_bpp < 24) { int p, i, y, u; for (p = 0; p < 3; p++) { @@ -133,8 +134,9 @@ static void generate_joint_tables(HYuvContext *s) } } ff_free_vlc(&s->vlc[3 + p]); - ff_init_vlc_sparse(&s->vlc[3 + p], VLC_BITS, i, len, 1, 1, - bits, 2, 2, symbols, 2, 2, 0); + if ((ret = ff_init_vlc_sparse(&s->vlc[3 + p], VLC_BITS, i, len, 1, 1, + bits, 2, 2, symbols, 2, 2, 0)) < 0) + return ret; } } else { uint8_t (*map)[4] = (uint8_t(*)[4])s->pix_bgr_map; @@ -176,8 +178,10 @@ static void generate_joint_tables(HYuvContext *s) } } ff_free_vlc(&s->vlc[3]); - init_vlc(&s->vlc[3], VLC_BITS, i, len, 1, 1, bits, 2, 2, 0); + if ((ret = init_vlc(&s->vlc[3], VLC_BITS, i, len, 1, 1, bits, 2, 2, 0)) < 0) + return ret; } + return 0; } static int read_huffman_tables(HYuvContext *s, const uint8_t *src, int length) @@ -200,7 +204,8 @@ static int read_huffman_tables(HYuvContext *s, const uint8_t *src, int length) return ret; } - generate_joint_tables(s); + if ((ret = generate_joint_tables(s)) < 0) + return ret; return (get_bits_count(&gb) + 7) / 8; } @@ -238,7 +243,8 @@ static int read_old_huffman_tables(HYuvContext *s) return ret; } - generate_joint_tables(s); + if ((ret = generate_joint_tables(s)) < 0) + return ret; return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/idcinvideo.c b/mythtv/external/FFmpeg/libavcodec/idcinvideo.c index 064e55f8672..2070419d7e5 100644 --- a/mythtv/external/FFmpeg/libavcodec/idcinvideo.c +++ b/mythtv/external/FFmpeg/libavcodec/idcinvideo.c @@ -169,7 +169,6 @@ static av_cold int idcin_decode_init(AVCodecContext *avctx) } avcodec_get_frame_defaults(&s->frame); - s->frame.data[0] = NULL; return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/iff.c b/mythtv/external/FFmpeg/libavcodec/iff.c index bebf6a52729..8e7f8cae468 100644 --- a/mythtv/external/FFmpeg/libavcodec/iff.c +++ b/mythtv/external/FFmpeg/libavcodec/iff.c @@ -139,7 +139,7 @@ static av_always_inline uint32_t gray2rgb(const uint32_t x) { /** * Convert CMAP buffer (stored in extradata) to lavc palette format */ -static int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal) +static int cmap_read_palette(AVCodecContext *avctx, uint32_t *pal) { IffContext *s = avctx->priv_data; int count, i; @@ -488,7 +488,7 @@ static int decode_byterun(uint8_t *dst, int dst_size, return buf - buf_start; } -#define DECODE_RGBX_COMMON(pixel_size) \ +#define DECODE_RGBX_COMMON(type) \ if (!length) { \ length = bytestream2_get_byte(gb); \ if (!length) { \ @@ -498,7 +498,7 @@ static int decode_byterun(uint8_t *dst, int dst_size, } \ } \ for (i = 0; i < length; i++) { \ - *(uint32_t *)(dst + y*linesize + x * pixel_size) = pixel; \ + *(type *)(dst + y*linesize + x * sizeof(type)) = pixel; \ x += 1; \ if (x >= width) { \ y += 1; \ @@ -521,7 +521,7 @@ static void decode_rgb8(GetByteContext *gb, uint8_t *dst, int width, int height, while (bytestream2_get_bytes_left(gb) >= 4) { uint32_t pixel = 0xFF000000 | bytestream2_get_be24(gb); length = bytestream2_get_byte(gb) & 0x7F; - DECODE_RGBX_COMMON(4) + DECODE_RGBX_COMMON(uint32_t) } } @@ -539,7 +539,7 @@ static void decode_rgbn(GetByteContext *gb, uint8_t *dst, int width, int height, uint32_t pixel = bytestream2_get_be16u(gb); length = pixel & 0x7; pixel >>= 4; - DECODE_RGBX_COMMON(2) + DECODE_RGBX_COMMON(uint16_t) } } @@ -576,7 +576,7 @@ static void decode_deep_rle32(uint8_t *dst, const uint8_t *src, int src_size, in } } else { int size = -opcode + 1; - uint32_t pixel = AV_RL32(src); + uint32_t pixel = AV_RN32(src); for (i = 0; i < size; i++) { *(uint32_t *)(dst + y*linesize + x * 4) = pixel; x += 1; @@ -671,10 +671,10 @@ static int decode_frame(AVCodecContext *avctx, av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return res; } else if (avctx->bits_per_coded_sample <= 8 && avctx->pix_fmt == AV_PIX_FMT_PAL8) { - if ((res = ff_cmap_read_palette(avctx, (uint32_t*)s->frame.data[1])) < 0) + if ((res = cmap_read_palette(avctx, (uint32_t*)s->frame.data[1])) < 0) return res; } else if (avctx->pix_fmt == AV_PIX_FMT_RGB32 && avctx->bits_per_coded_sample <= 8) { - if ((res = ff_cmap_read_palette(avctx, s->mask_palbuf)) < 0) + if ((res = cmap_read_palette(avctx, s->mask_palbuf)) < 0) return res; } s->init = 1; diff --git a/mythtv/external/FFmpeg/libavcodec/imc.c b/mythtv/external/FFmpeg/libavcodec/imc.c index 1295c8ec6c5..0f434614c6d 100644 --- a/mythtv/external/FFmpeg/libavcodec/imc.c +++ b/mythtv/external/FFmpeg/libavcodec/imc.c @@ -36,6 +36,8 @@ #include #include "libavutil/channel_layout.h" +#include "libavutil/float_dsp.h" +#include "libavutil/internal.h" #include "libavutil/libm.h" #include "avcodec.h" #include "get_bits.h" @@ -79,8 +81,6 @@ typedef struct IMCChannel { } IMCChannel; typedef struct { - AVFrame frame; - IMCChannel chctx[2]; /** MDCT tables */ @@ -96,6 +96,7 @@ typedef struct { GetBitContext gb; DSPContext dsp; + AVFloatDSPContext fdsp; FFTContext fft; DECLARE_ALIGNED(32, FFTComplex, samples)[COEFFS / 2]; float *out_samples; @@ -245,13 +246,11 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) return ret; } ff_dsputil_init(&q->dsp, avctx); + avpriv_float_dsp_init(&q->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; - avcodec_get_frame_defaults(&q->frame); - avctx->coded_frame = &q->frame; - return 0; } @@ -933,6 +932,7 @@ static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch) static int imc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int ret, i; @@ -947,14 +947,14 @@ static int imc_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - q->frame.nb_samples = COEFFS; - if ((ret = ff_get_buffer(avctx, &q->frame)) < 0) { + frame->nb_samples = COEFFS; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } for (i = 0; i < avctx->channels; i++) { - q->out_samples = (float *)q->frame.extended_data[i]; + q->out_samples = (float *)frame->extended_data[i]; q->dsp.bswap16_buf(buf16, (const uint16_t*)buf, IMC_BLOCK_SIZE / 2); @@ -967,12 +967,11 @@ static int imc_decode_frame(AVCodecContext *avctx, void *data, } if (avctx->channels == 2) { - q->dsp.butterflies_float((float *)q->frame.extended_data[0], - (float *)q->frame.extended_data[1], COEFFS); + q->fdsp.butterflies_float((float *)frame->extended_data[0], + (float *)frame->extended_data[1], COEFFS); } - *got_frame_ptr = 1; - *(AVFrame *)data = q->frame; + *got_frame_ptr = 1; return IMC_BLOCK_SIZE * avctx->channels; } diff --git a/mythtv/external/FFmpeg/libavcodec/imgconvert.c b/mythtv/external/FFmpeg/libavcodec/imgconvert.c index 09d24899f13..6c3bb368ec0 100644 --- a/mythtv/external/FFmpeg/libavcodec/imgconvert.c +++ b/mythtv/external/FFmpeg/libavcodec/imgconvert.c @@ -32,6 +32,7 @@ #include "avcodec.h" #include "dsputil.h" +#include "imgconvert.h" #include "internal.h" #include "libavutil/avassert.h" #include "libavutil/colorspace.h" @@ -103,24 +104,25 @@ static int get_pix_fmt_depth(int *min, int *max, enum AVPixelFormat pix_fmt) return 0; } -int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, - enum AVPixelFormat src_pix_fmt, - int has_alpha) +static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt, + enum AVPixelFormat src_pix_fmt, + unsigned *lossp, unsigned consider) { const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt); const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt); int src_color, dst_color; int src_min_depth, src_max_depth, dst_min_depth, dst_max_depth; int ret, loss, i, nb_components; + int score = INT_MAX; if (dst_pix_fmt >= AV_PIX_FMT_NB || dst_pix_fmt <= AV_PIX_FMT_NONE) return ~0; /* compute loss */ - loss = 0; + *lossp = loss = 0; if (dst_pix_fmt == src_pix_fmt) - return 0; + return INT_MAX; if ((ret = get_pix_fmt_depth(&src_min_depth, &src_max_depth, src_pix_fmt)) < 0) return ret; @@ -132,13 +134,28 @@ int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, nb_components = FFMIN(src_desc->nb_components, dst_desc->nb_components); for (i = 0; i < nb_components; i++) - if (src_desc->comp[i].depth_minus1 > dst_desc->comp[i].depth_minus1) + if (src_desc->comp[i].depth_minus1 > dst_desc->comp[i].depth_minus1 && (consider & FF_LOSS_DEPTH)) { loss |= FF_LOSS_DEPTH; + score -= 65536 >> dst_desc->comp[i].depth_minus1; + } - if (dst_desc->log2_chroma_w > src_desc->log2_chroma_w || - dst_desc->log2_chroma_h > src_desc->log2_chroma_h) - loss |= FF_LOSS_RESOLUTION; + if (consider & FF_LOSS_RESOLUTION) { + if (dst_desc->log2_chroma_w > src_desc->log2_chroma_w) { + loss |= FF_LOSS_RESOLUTION; + score -= 256 << dst_desc->log2_chroma_w; + } + if (dst_desc->log2_chroma_h > src_desc->log2_chroma_h) { + loss |= FF_LOSS_RESOLUTION; + score -= 256 << dst_desc->log2_chroma_h; + } + // dont favor 422 over 420 if downsampling is needed, because 420 has much better support on the decoder side + if (dst_desc->log2_chroma_w == 1 && src_desc->log2_chroma_w == 0 && + dst_desc->log2_chroma_h == 1 && src_desc->log2_chroma_h == 0 ) { + score += 512; + } + } + if(consider & FF_LOSS_COLORSPACE) switch(dst_color) { case FF_COLOR_RGB: if (src_color != FF_COLOR_RGB && @@ -165,15 +182,36 @@ int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, loss |= FF_LOSS_COLORSPACE; break; } + if(loss & FF_LOSS_COLORSPACE) + score -= (nb_components * 65536) >> FFMIN(dst_desc->comp[0].depth_minus1, src_desc->comp[0].depth_minus1); + if (dst_color == FF_COLOR_GRAY && - src_color != FF_COLOR_GRAY) + src_color != FF_COLOR_GRAY && (consider & FF_LOSS_CHROMA)) { loss |= FF_LOSS_CHROMA; - if (!pixdesc_has_alpha(dst_desc) && (pixdesc_has_alpha(src_desc) && has_alpha)) + score -= 2 * 65536; + } + if (!pixdesc_has_alpha(dst_desc) && (pixdesc_has_alpha(src_desc) && (consider & FF_LOSS_ALPHA))) { loss |= FF_LOSS_ALPHA; - if (dst_pix_fmt == AV_PIX_FMT_PAL8 && - (src_pix_fmt != AV_PIX_FMT_PAL8 && (src_color != FF_COLOR_GRAY || (pixdesc_has_alpha(src_desc) && has_alpha)))) + score -= 65536; + } + if (dst_pix_fmt == AV_PIX_FMT_PAL8 && (consider & FF_LOSS_COLORQUANT) && + (src_pix_fmt != AV_PIX_FMT_PAL8 && (src_color != FF_COLOR_GRAY || (pixdesc_has_alpha(src_desc) && (consider & FF_LOSS_ALPHA))))) { loss |= FF_LOSS_COLORQUANT; + score -= 65536; + } + *lossp = loss; + return score; +} + +int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, + enum AVPixelFormat src_pix_fmt, + int has_alpha) +{ + int loss; + int ret = get_pix_fmt_score(dst_pix_fmt, src_pix_fmt, &loss, has_alpha ? ~0 : ~FF_LOSS_ALPHA); + if (ret < 0) + return ret; return loss; } @@ -200,43 +238,27 @@ enum AVPixelFormat avcodec_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr) { enum AVPixelFormat dst_pix_fmt; - int loss1, loss2, loss_order1, loss_order2, i, loss_mask; + int loss1, loss2, loss_mask; const AVPixFmtDescriptor *desc1 = av_pix_fmt_desc_get(dst_pix_fmt1); const AVPixFmtDescriptor *desc2 = av_pix_fmt_desc_get(dst_pix_fmt2); - static const int loss_mask_order[] = { - ~0, /* no loss first */ - ~FF_LOSS_ALPHA, - ~FF_LOSS_RESOLUTION, - ~FF_LOSS_COLORSPACE, - ~(FF_LOSS_COLORSPACE | FF_LOSS_RESOLUTION), - ~FF_LOSS_COLORQUANT, - ~FF_LOSS_DEPTH, - ~(FF_LOSS_DEPTH|FF_LOSS_COLORSPACE), - ~(FF_LOSS_RESOLUTION | FF_LOSS_DEPTH | FF_LOSS_COLORSPACE | FF_LOSS_ALPHA | - FF_LOSS_COLORQUANT | FF_LOSS_CHROMA), - 0x80000, //non zero entry that combines all loss variants including future additions - 0, - }; + int score1, score2; loss_mask= loss_ptr?~*loss_ptr:~0; /* use loss mask if provided */ + if(!has_alpha) + loss_mask &= ~FF_LOSS_ALPHA; + dst_pix_fmt = AV_PIX_FMT_NONE; - loss1 = avcodec_get_pix_fmt_loss(dst_pix_fmt1, src_pix_fmt, has_alpha) & loss_mask; - loss2 = avcodec_get_pix_fmt_loss(dst_pix_fmt2, src_pix_fmt, has_alpha) & loss_mask; - - /* try with successive loss */ - for(i = 0;loss_mask_order[i] != 0 && dst_pix_fmt == AV_PIX_FMT_NONE;i++) { - loss_order1 = loss1 & loss_mask_order[i]; - loss_order2 = loss2 & loss_mask_order[i]; - - if (loss_order1 == 0 && loss_order2 == 0 && dst_pix_fmt2 != AV_PIX_FMT_NONE && dst_pix_fmt1 != AV_PIX_FMT_NONE){ /* use format with smallest depth */ - if(av_get_padded_bits_per_pixel(desc2) != av_get_padded_bits_per_pixel(desc1)) { - dst_pix_fmt = av_get_padded_bits_per_pixel(desc2) < av_get_padded_bits_per_pixel(desc1) ? dst_pix_fmt2 : dst_pix_fmt1; - } else { - dst_pix_fmt = desc2->nb_components < desc1->nb_components ? dst_pix_fmt2 : dst_pix_fmt1; - } - } else if (loss_order1 == 0 || loss_order2 == 0) { /* use format with no loss */ - dst_pix_fmt = loss_order2 ? dst_pix_fmt1 : dst_pix_fmt2; + score1 = get_pix_fmt_score(dst_pix_fmt1, src_pix_fmt, &loss1, loss_mask); + score2 = get_pix_fmt_score(dst_pix_fmt2, src_pix_fmt, &loss2, loss_mask); + + if (score1 == score2) { + if(av_get_padded_bits_per_pixel(desc2) != av_get_padded_bits_per_pixel(desc1)) { + dst_pix_fmt = av_get_padded_bits_per_pixel(desc2) < av_get_padded_bits_per_pixel(desc1) ? dst_pix_fmt2 : dst_pix_fmt1; + } else { + dst_pix_fmt = desc2->nb_components < desc1->nb_components ? dst_pix_fmt2 : dst_pix_fmt1; } + } else { + dst_pix_fmt = score1 < score2 ? dst_pix_fmt2 : dst_pix_fmt1; } if (loss_ptr) @@ -470,6 +492,8 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, return 0; } +#if FF_API_DEINTERLACE + #if !HAVE_MMX_EXTERNAL /* filter parameters: [-1 4 2 4 -1] // 8 */ static void deinterlace_line_c(uint8_t *dst, @@ -629,6 +653,8 @@ int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, return 0; } +#endif /* FF_API_DEINTERLACE */ + #ifdef TEST int main(void){ diff --git a/mythtv/external/FFmpeg/libavcodec/imgconvert.h b/mythtv/external/FFmpeg/libavcodec/imgconvert.h new file mode 100644 index 00000000000..df8cee794fc --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/imgconvert.h @@ -0,0 +1,29 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_IMGCONVERT_H +#define AVCODEC_IMGCONVERT_H + +#include + +/* 1/2^n downscaling functions */ +void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); +void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); +void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); + +#endif /* AVCODEC_IMGCONVERT_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/indeo2.c b/mythtv/external/FFmpeg/libavcodec/indeo2.c index fcd0ae46d4b..ec6ff3c18fc 100644 --- a/mythtv/external/FFmpeg/libavcodec/indeo2.c +++ b/mythtv/external/FFmpeg/libavcodec/indeo2.c @@ -47,8 +47,8 @@ static inline int ir2_get_code(GetBitContext *gb) return get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1) + 1; } -static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride, - const uint8_t *table) +static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, + int stride, const uint8_t *table) { int i; int j; @@ -56,16 +56,16 @@ static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst int c; int t; - if(width&1) - return -1; + if (width & 1) + return AVERROR_INVALIDDATA; /* first line contain absolute values, other lines contain deltas */ - while (out < width){ + while (out < width) { c = ir2_get_code(&ctx->gb); - if(c >= 0x80) { /* we have a run */ + if (c >= 0x80) { /* we have a run */ c -= 0x7F; - if(out + c*2 > width) - return -1; + if (out + c*2 > width) + return AVERROR_INVALIDDATA; for (i = 0; i < c * 2; i++) dst[out++] = 0x80; } else { /* copy two values from table */ @@ -75,25 +75,25 @@ static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst } dst += stride; - for (j = 1; j < height; j++){ + for (j = 1; j < height; j++) { out = 0; - while (out < width){ + while (out < width) { c = ir2_get_code(&ctx->gb); - if(c >= 0x80) { /* we have a skip */ + if (c >= 0x80) { /* we have a skip */ c -= 0x7F; - if(out + c*2 > width) - return -1; + if (out + c*2 > width) + return AVERROR_INVALIDDATA; for (i = 0; i < c * 2; i++) { dst[out] = dst[out - stride]; out++; } } else { /* add two deltas from table */ - t = dst[out - stride] + (table[c * 2] - 128); - t= av_clip_uint8(t); + t = dst[out - stride] + (table[c * 2] - 128); + t = av_clip_uint8(t); dst[out] = t; out++; - t = dst[out - stride] + (table[(c * 2) + 1] - 128); - t= av_clip_uint8(t); + t = dst[out - stride] + (table[(c * 2) + 1] - 128); + t = av_clip_uint8(t); dst[out] = t; out++; } @@ -103,31 +103,31 @@ static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst return 0; } -static int ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride, - const uint8_t *table) +static int ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_t *dst, + int stride, const uint8_t *table) { int j; int out = 0; int c; int t; - if(width&1) - return -1; + if (width & 1) + return AVERROR_INVALIDDATA; - for (j = 0; j < height; j++){ + for (j = 0; j < height; j++) { out = 0; - while (out < width){ + while (out < width) { c = ir2_get_code(&ctx->gb); - if(c >= 0x80) { /* we have a skip */ - c -= 0x7F; + if (c >= 0x80) { /* we have a skip */ + c -= 0x7F; out += c * 2; } else { /* add two deltas from table */ - t = dst[out] + (((table[c * 2] - 128)*3) >> 2); - t= av_clip_uint8(t); + t = dst[out] + (((table[c * 2] - 128)*3) >> 2); + t = av_clip_uint8(t); dst[out] = t; out++; - t = dst[out] + (((table[(c * 2) + 1] - 128)*3) >> 2); - t= av_clip_uint8(t); + t = dst[out] + (((table[(c * 2) + 1] - 128)*3) >> 2); + t = av_clip_uint8(t); dst[out] = t; out++; } @@ -141,18 +141,18 @@ static int ir2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; Ir2Context * const s = avctx->priv_data; - AVFrame *picture = data; - AVFrame * const p = &s->picture; - int start; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + AVFrame *picture = data; + AVFrame * const p = &s->picture; + int start, ret; p->reference = 3; p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; - if (avctx->reget_buffer(avctx, p)) { + if ((ret = avctx->reget_buffer(avctx, p)) < 0) { av_log(s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } start = 48; /* hardcoded for now */ @@ -173,21 +173,34 @@ static int ir2_decode_frame(AVCodecContext *avctx, init_get_bits(&s->gb, buf + start, (buf_size - start) * 8); if (s->decode_delta) { /* intraframe */ - ir2_decode_plane(s, avctx->width, avctx->height, - s->picture.data[0], s->picture.linesize[0], ir2_luma_table); + if ((ret = ir2_decode_plane(s, avctx->width, avctx->height, + s->picture.data[0], s->picture.linesize[0], + ir2_luma_table)) < 0) + return ret; + /* swapped U and V */ - ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2, - s->picture.data[2], s->picture.linesize[2], ir2_luma_table); - ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2, - s->picture.data[1], s->picture.linesize[1], ir2_luma_table); + if ((ret = ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2, + s->picture.data[2], s->picture.linesize[2], + ir2_luma_table)) < 0) + return ret; + if ((ret = ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2, + s->picture.data[1], s->picture.linesize[1], + ir2_luma_table)) < 0) + return ret; } else { /* interframe */ - ir2_decode_plane_inter(s, avctx->width, avctx->height, - s->picture.data[0], s->picture.linesize[0], ir2_luma_table); + if ((ret = ir2_decode_plane_inter(s, avctx->width, avctx->height, + s->picture.data[0], s->picture.linesize[0], + ir2_luma_table)) < 0) + return ret; /* swapped U and V */ - ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2, - s->picture.data[2], s->picture.linesize[2], ir2_luma_table); - ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2, - s->picture.data[1], s->picture.linesize[1], ir2_luma_table); + if ((ret = ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2, + s->picture.data[2], s->picture.linesize[2], + ir2_luma_table)) < 0) + return ret; + if ((ret = ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2, + s->picture.data[1], s->picture.linesize[1], + ir2_luma_table)) < 0) + return ret; } *picture = s->picture; @@ -196,7 +209,8 @@ static int ir2_decode_frame(AVCodecContext *avctx, return buf_size; } -static av_cold int ir2_decode_init(AVCodecContext *avctx){ +static av_cold int ir2_decode_init(AVCodecContext *avctx) +{ Ir2Context * const ic = avctx->priv_data; static VLC_TYPE vlc_tables[1 << CODE_VLC_BITS][2]; @@ -220,7 +234,8 @@ static av_cold int ir2_decode_init(AVCodecContext *avctx){ return 0; } -static av_cold int ir2_decode_end(AVCodecContext *avctx){ +static av_cold int ir2_decode_end(AVCodecContext *avctx) +{ Ir2Context * const ic = avctx->priv_data; AVFrame *pic = &ic->picture; diff --git a/mythtv/external/FFmpeg/libavcodec/indeo3.c b/mythtv/external/FFmpeg/libavcodec/indeo3.c index a8206dbb00b..a94b087bedb 100644 --- a/mythtv/external/FFmpeg/libavcodec/indeo3.c +++ b/mythtv/external/FFmpeg/libavcodec/indeo3.c @@ -32,6 +32,7 @@ #include "libavutil/imgutils.h" #include "libavutil/intreadwrite.h" #include "avcodec.h" +#include "copy_block.h" #include "dsputil.h" #include "bytestream.h" #include "get_bits.h" @@ -410,7 +411,8 @@ if (*data_ptr >= last_ptr) \ } -static int decode_cell_data(Cell *cell, uint8_t *block, uint8_t *ref_block, +static int decode_cell_data(Indeo3DecodeContext *ctx, Cell *cell, + uint8_t *block, uint8_t *ref_block, int pitch, int h_zoom, int v_zoom, int mode, const vqEntry *delta[2], int swap_quads[2], const uint8_t **data_ptr, const uint8_t *last_ptr) @@ -656,14 +658,16 @@ static int decode_cell(Indeo3DecodeContext *ctx, AVCodecContext *avctx, } zoom_fac = mode >= 3; - error = decode_cell_data(cell, block, ref_block, plane->pitch, 0, zoom_fac, - mode, delta, swap_quads, &data_ptr, last_ptr); + error = decode_cell_data(ctx, cell, block, ref_block, plane->pitch, + 0, zoom_fac, mode, delta, swap_quads, + &data_ptr, last_ptr); break; case 10: /*-------------------- MODE 10 (8x8 block processing) ---------------------*/ case 11: /*----------------- MODE 11 (4x8 INTER block processing) ------------------*/ if (mode == 10 && !cell->mv_ptr) { /* MODE 10 INTRA processing */ - error = decode_cell_data(cell, block, ref_block, plane->pitch, 1, 1, - mode, delta, swap_quads, &data_ptr, last_ptr); + error = decode_cell_data(ctx, cell, block, ref_block, plane->pitch, + 1, 1, mode, delta, swap_quads, + &data_ptr, last_ptr); } else { /* mode 10 and 11 INTER processing */ if (mode == 11 && !cell->mv_ptr) { av_log(avctx, AV_LOG_ERROR, "Attempt to use Mode 11 for an INTRA cell!\n"); @@ -671,7 +675,7 @@ static int decode_cell(Indeo3DecodeContext *ctx, AVCodecContext *avctx, } zoom_fac = mode == 10; - error = decode_cell_data(cell, block, ref_block, plane->pitch, + error = decode_cell_data(ctx, cell, block, ref_block, plane->pitch, zoom_fac, 1, mode, delta, swap_quads, &data_ptr, last_ptr); } diff --git a/mythtv/external/FFmpeg/libavcodec/indeo4.c b/mythtv/external/FFmpeg/libavcodec/indeo4.c index 0766ed489a8..e810003ace6 100644 --- a/mythtv/external/FFmpeg/libavcodec/indeo4.c +++ b/mythtv/external/FFmpeg/libavcodec/indeo4.c @@ -30,7 +30,6 @@ #define BITSTREAM_READER_LE #include "avcodec.h" #include "get_bits.h" -#include "dsputil.h" #include "ivi_dsp.h" #include "ivi_common.h" #include "indeo4data.h" @@ -387,6 +386,10 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band, av_log(avctx, AV_LOG_ERROR, "mismatching scan table!\n"); return AVERROR_INVALIDDATA; } + if (band->transform_size == 8 && band->blk_size < 8) { + av_log(avctx, AV_LOG_ERROR, "mismatching transform_size!\n"); + return AVERROR_INVALIDDATA; + } /* decode block huffman codebook */ if (ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_BLK_HUFF, diff --git a/mythtv/external/FFmpeg/libavcodec/internal.h b/mythtv/external/FFmpeg/libavcodec/internal.h index cf8bbe5e32e..af9e58eead3 100644 --- a/mythtv/external/FFmpeg/libavcodec/internal.h +++ b/mythtv/external/FFmpeg/libavcodec/internal.h @@ -62,7 +62,7 @@ typedef struct AVCodecInternal { */ int is_copy; -#if FF_API_OLD_DECODE_AUDIO +#if FF_API_OLD_ENCODE_AUDIO /** * Internal sample count used by avcodec_encode_audio() to fabricate pts. * Can be removed along with avcodec_encode_audio(). @@ -124,6 +124,9 @@ unsigned int avpriv_toupper4(unsigned int x); */ void ff_init_buffer_info(AVCodecContext *s, AVFrame *frame); + +void avpriv_color_frame(AVFrame *frame, const int color[4]); + /** * Remove and free all side data from packet. */ @@ -189,6 +192,10 @@ int ff_get_logical_cpus(AVCodecContext *avctx); int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx); +void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_table, + uint8_t *visualization_buffer[3], int *low_delay, + int mb_width, int mb_height, int mb_stride, int quarter_sample); + /** * Call avcodec_open2 recursively by decrementing counter, unlocking mutex, * calling the function and then restoring again. Assumes the mutex is @@ -206,4 +213,6 @@ int ff_codec_close_recursive(AVCodecContext *avctx); */ int avpriv_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf); +AVDictionary **ff_frame_get_metadatap(AVFrame *frame); + #endif /* AVCODEC_INTERNAL_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/interplayvideo.c b/mythtv/external/FFmpeg/libavcodec/interplayvideo.c index f1a2a3856a0..e0550a702b3 100644 --- a/mythtv/external/FFmpeg/libavcodec/interplayvideo.c +++ b/mythtv/external/FFmpeg/libavcodec/interplayvideo.c @@ -74,11 +74,11 @@ static int copy_from(IpvideoContext *s, AVFrame *src, int delta_x, int delta_y) + delta_x * (1 + s->is_16bpp); if (motion_offset < 0) { av_log(s->avctx, AV_LOG_ERROR, "motion offset < 0 (%d)\n", motion_offset); - return -1; + return AVERROR_INVALIDDATA; } else if (motion_offset > s->upper_motion_limit_offset) { av_log(s->avctx, AV_LOG_ERROR, "motion offset above limit (%d >= %d)\n", motion_offset, s->upper_motion_limit_offset); - return -1; + return AVERROR_INVALIDDATA; } if (src->data[0] == NULL) { av_log(s->avctx, AV_LOG_ERROR, "Invalid decode type, corrupted header?\n"); @@ -882,12 +882,8 @@ static void ipvideo_decode_opcodes(IpvideoContext *s) int x, y; unsigned char opcode; int ret; - static int frame = 0; GetBitContext gb; - av_dlog(s->avctx, "frame %d\n", frame); - frame++; - bytestream2_skip(&s->stream_ptr, 14); /* data starts 14 bytes in */ if (!s->is_16bpp) { /* this is PAL8, so make the palette available */ @@ -923,7 +919,7 @@ static void ipvideo_decode_opcodes(IpvideoContext *s) } if (ret != 0) { av_log(s->avctx, AV_LOG_ERROR, "decode problem on frame %d, @ block (%d, %d)\n", - frame, x, y); + s->avctx->frame_number, x, y); return; } } @@ -963,6 +959,7 @@ static int ipvideo_decode_frame(AVCodecContext *avctx, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; IpvideoContext *s = avctx->priv_data; + int ret; /* decoding map contains 4 bits of information per 8x8 block */ s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2); @@ -972,14 +969,21 @@ static int ipvideo_decode_frame(AVCodecContext *avctx, if (buf_size < s->decoding_map_size) return buf_size; + if (s->last_frame.data[0] && av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, NULL)) { + if (s->last_frame.data[0]) + avctx->release_buffer(avctx, &s->last_frame); + if (s->second_last_frame.data[0]) + avctx->release_buffer(avctx, &s->second_last_frame); + } + s->decoding_map = buf; bytestream2_init(&s->stream_ptr, buf + s->decoding_map_size, buf_size - s->decoding_map_size); s->current_frame.reference = 3; - if (ff_get_buffer(avctx, &s->current_frame)) { + if ((ret = ff_get_buffer(avctx, &s->current_frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } if (!s->is_16bpp) { diff --git a/mythtv/external/FFmpeg/libavcodec/intrax8.c b/mythtv/external/FFmpeg/libavcodec/intrax8.c index fe1e770a186..5b76942addf 100644 --- a/mythtv/external/FFmpeg/libavcodec/intrax8.c +++ b/mythtv/external/FFmpeg/libavcodec/intrax8.c @@ -776,12 +776,12 @@ int ff_intrax8_decode_picture(IntraX8Context * const w, int dquant, int quant_of s->dest[0]+= 8; } if(s->mb_y&1){ - ff_draw_horiz_band(s, (s->mb_y-1)*8, 16); + ff_mpeg_draw_horiz_band(s, (s->mb_y-1)*8, 16); } } error: - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, (s->mb_x>>1)-1, (s->mb_y>>1)-1, ER_MB_END ); return 0; diff --git a/mythtv/external/FFmpeg/libavcodec/intrax8dsp.c b/mythtv/external/FFmpeg/libavcodec/intrax8dsp.c index 447ad21846c..1b34f899d60 100644 --- a/mythtv/external/FFmpeg/libavcodec/intrax8dsp.c +++ b/mythtv/external/FFmpeg/libavcodec/intrax8dsp.c @@ -21,7 +21,6 @@ *@brief IntraX8 frame subdecoder image manipulation routines */ -#include "dsputil.h" #include "intrax8dsp.h" #include "libavutil/common.h" diff --git a/mythtv/external/FFmpeg/libavcodec/ituh263dec.c b/mythtv/external/FFmpeg/libavcodec/ituh263dec.c index 44b13aa5edd..d43ed399727 100644 --- a/mythtv/external/FFmpeg/libavcodec/ituh263dec.c +++ b/mythtv/external/FFmpeg/libavcodec/ituh263dec.c @@ -32,8 +32,8 @@ //#define DEBUG #include +#include "libavutil/internal.h" #include "libavutil/mathematics.h" -#include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" #include "h263.h" @@ -100,7 +100,7 @@ static VLC cbpc_b_vlc; /* init vlcs */ /* XXX: find a better solution to handle static init */ -void ff_h263_decode_init_vlc(MpegEncContext *s) +void ff_h263_decode_init_vlc(void) { static volatile int done = 0; @@ -439,7 +439,7 @@ static void h263_decode_dquant(MpegEncContext *s){ ff_set_qscale(s, s->qscale); } -static int h263_decode_block(MpegEncContext * s, DCTELEM * block, +static int h263_decode_block(MpegEncContext * s, int16_t * block, int n, int coded) { int code, level, i, j, last, run; @@ -564,7 +564,7 @@ static int h263_decode_block(MpegEncContext * s, DCTELEM * block, static int h263_skip_b_part(MpegEncContext *s, int cbp) { - LOCAL_ALIGNED_16(DCTELEM, dblock, [64]); + LOCAL_ALIGNED_16(int16_t, dblock, [64]); int i, mbi; int bli[6]; @@ -603,7 +603,7 @@ static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb) } int ff_h263_decode_mb(MpegEncContext *s, - DCTELEM block[6][64]) + int16_t block[6][64]) { int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; int16_t *mot_val; diff --git a/mythtv/external/FFmpeg/libavcodec/ituh263enc.c b/mythtv/external/FFmpeg/libavcodec/ituh263enc.c index 3eb198f2ce8..bdcc4159104 100644 --- a/mythtv/external/FFmpeg/libavcodec/ituh263enc.c +++ b/mythtv/external/FFmpeg/libavcodec/ituh263enc.c @@ -30,7 +30,6 @@ //#define DEBUG #include -#include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" #include "h263.h" @@ -303,7 +302,7 @@ static const int dquant_code[5]= {1,0,9,2,3}; * @param block the 8x8 block * @param n block index (0-3 are luma, 4-5 are chroma) */ -static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n) +static void h263_encode_block(MpegEncContext * s, int16_t * block, int n) { int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code; RLTable *rl; @@ -452,7 +451,7 @@ static void h263p_encode_umotion(MpegEncContext * s, int val) } void ff_h263_encode_mb(MpegEncContext * s, - DCTELEM block[6][64], + int16_t block[6][64], int motion_x, int motion_y) { int cbpc, cbpy, i, cbp, pred_x, pred_y; diff --git a/mythtv/external/FFmpeg/libavcodec/ivi_common.h b/mythtv/external/FFmpeg/libavcodec/ivi_common.h index fcea5f6b4f3..86acbe67fcc 100644 --- a/mythtv/external/FFmpeg/libavcodec/ivi_common.h +++ b/mythtv/external/FFmpeg/libavcodec/ivi_common.h @@ -317,6 +317,6 @@ int ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height); int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt); -av_cold int ff_ivi_decode_close(AVCodecContext *avctx); +int ff_ivi_decode_close(AVCodecContext *avctx); #endif /* AVCODEC_IVI_COMMON_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/ivi_dsp.c b/mythtv/external/FFmpeg/libavcodec/ivi_dsp.c index 52cd402cb1e..84e2436446f 100644 --- a/mythtv/external/FFmpeg/libavcodec/ivi_dsp.c +++ b/mythtv/external/FFmpeg/libavcodec/ivi_dsp.c @@ -27,8 +27,6 @@ */ #include "avcodec.h" -#include "dsputil.h" -#include "dwt.h" #include "ivi_common.h" #include "ivi_dsp.h" @@ -40,7 +38,7 @@ void ff_ivi_recompose53(const IVIPlaneDesc *plane, uint8_t *dst, int32_t b0_1, b0_2, b1_1, b1_2, b1_3, b2_1, b2_2, b2_3, b2_4, b2_5, b2_6; int32_t b3_1, b3_2, b3_3, b3_4, b3_5, b3_6, b3_7, b3_8, b3_9; int32_t pitch, back_pitch; - const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr; + const short *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr; const int num_bands = 4; /* all bands should have the same pitch */ @@ -193,7 +191,7 @@ void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8_t *dst, const int dst_pitch) { int x, y, indx, b0, b1, b2, b3, p0, p1, p2, p3; - const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr; + const short *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr; int32_t pitch; /* all bands should have the same pitch */ diff --git a/mythtv/external/FFmpeg/libavcodec/jfdctfst.c b/mythtv/external/FFmpeg/libavcodec/jfdctfst.c index 3e30e5d535f..bbcf5984901 100644 --- a/mythtv/external/FFmpeg/libavcodec/jfdctfst.c +++ b/mythtv/external/FFmpeg/libavcodec/jfdctfst.c @@ -69,7 +69,7 @@ #include #include #include "libavutil/common.h" -#include "dsputil.h" +#include "dct.h" #define DCTSIZE 8 #define GLOBAL(x) x @@ -136,17 +136,17 @@ #endif -/* Multiply a DCTELEM variable by an int32_t constant, and immediately - * descale to yield a DCTELEM result. +/* Multiply a int16_t variable by an int32_t constant, and immediately + * descale to yield a int16_t result. */ -#define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) +#define MULTIPLY(var,const) ((int16_t) DESCALE((var) * (const), CONST_BITS)) -static av_always_inline void row_fdct(DCTELEM * data){ +static av_always_inline void row_fdct(int16_t * data){ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int tmp10, tmp11, tmp12, tmp13; int z1, z2, z3, z4, z5, z11, z13; - DCTELEM *dataptr; + int16_t *dataptr; int ctr; /* Pass 1: process rows. */ @@ -205,12 +205,12 @@ static av_always_inline void row_fdct(DCTELEM * data){ */ GLOBAL(void) -ff_fdct_ifast (DCTELEM * data) +ff_fdct_ifast (int16_t * data) { int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int tmp10, tmp11, tmp12, tmp13; int z1, z2, z3, z4, z5, z11, z13; - DCTELEM *dataptr; + int16_t *dataptr; int ctr; row_fdct(data); @@ -271,12 +271,12 @@ ff_fdct_ifast (DCTELEM * data) */ GLOBAL(void) -ff_fdct_ifast248 (DCTELEM * data) +ff_fdct_ifast248 (int16_t * data) { int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int tmp10, tmp11, tmp12, tmp13; int z1; - DCTELEM *dataptr; + int16_t *dataptr; int ctr; row_fdct(data); diff --git a/mythtv/external/FFmpeg/libavcodec/jfdctint_template.c b/mythtv/external/FFmpeg/libavcodec/jfdctint_template.c index 51753907102..c6a16381070 100644 --- a/mythtv/external/FFmpeg/libavcodec/jfdctint_template.c +++ b/mythtv/external/FFmpeg/libavcodec/jfdctint_template.c @@ -60,7 +60,7 @@ */ #include "libavutil/common.h" -#include "dsputil.h" +#include "dct.h" #include "bit_depth_template.c" @@ -184,12 +184,12 @@ #endif -static av_always_inline void FUNC(row_fdct)(DCTELEM *data) +static av_always_inline void FUNC(row_fdct)(int16_t *data) { int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int tmp10, tmp11, tmp12, tmp13; int z1, z2, z3, z4, z5; - DCTELEM *dataptr; + int16_t *dataptr; int ctr; /* Pass 1: process rows. */ @@ -216,13 +216,13 @@ static av_always_inline void FUNC(row_fdct)(DCTELEM *data) tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; - dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS); - dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS); + dataptr[0] = (int16_t) ((tmp10 + tmp11) << PASS1_BITS); + dataptr[4] = (int16_t) ((tmp10 - tmp11) << PASS1_BITS); z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); - dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), + dataptr[2] = (int16_t) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), CONST_BITS-PASS1_BITS); - dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), + dataptr[6] = (int16_t) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), CONST_BITS-PASS1_BITS); /* Odd part per figure 8 --- note paper omits factor of sqrt(2). @@ -248,10 +248,10 @@ static av_always_inline void FUNC(row_fdct)(DCTELEM *data) z3 += z5; z4 += z5; - dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS); - dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS); - dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS); - dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS); + dataptr[7] = (int16_t) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS); + dataptr[5] = (int16_t) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS); + dataptr[3] = (int16_t) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS); + dataptr[1] = (int16_t) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS); dataptr += DCTSIZE; /* advance pointer to next row */ } @@ -262,12 +262,12 @@ static av_always_inline void FUNC(row_fdct)(DCTELEM *data) */ GLOBAL(void) -FUNC(ff_jpeg_fdct_islow)(DCTELEM *data) +FUNC(ff_jpeg_fdct_islow)(int16_t *data) { int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int tmp10, tmp11, tmp12, tmp13; int z1, z2, z3, z4, z5; - DCTELEM *dataptr; + int16_t *dataptr; int ctr; FUNC(row_fdct)(data); @@ -344,12 +344,12 @@ FUNC(ff_jpeg_fdct_islow)(DCTELEM *data) * you do even part two times. */ GLOBAL(void) -FUNC(ff_fdct248_islow)(DCTELEM *data) +FUNC(ff_fdct248_islow)(int16_t *data) { int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int tmp10, tmp11, tmp12, tmp13; int z1; - DCTELEM *dataptr; + int16_t *dataptr; int ctr; FUNC(row_fdct)(data); diff --git a/mythtv/external/FFmpeg/libavcodec/jpeglsenc.c b/mythtv/external/FFmpeg/libavcodec/jpeglsenc.c index e51e47aafdb..be979aa3716 100644 --- a/mythtv/external/FFmpeg/libavcodec/jpeglsenc.c +++ b/mythtv/external/FFmpeg/libavcodec/jpeglsenc.c @@ -27,10 +27,10 @@ #include "avcodec.h" #include "get_bits.h" +#include "put_bits.h" #include "golomb.h" #include "internal.h" #include "mathops.h" -#include "dsputil.h" #include "mjpeg.h" #include "jpegls.h" diff --git a/mythtv/external/FFmpeg/libavcodec/jrevdct.c b/mythtv/external/FFmpeg/libavcodec/jrevdct.c index 395eb8c6388..91780b2e444 100644 --- a/mythtv/external/FFmpeg/libavcodec/jrevdct.c +++ b/mythtv/external/FFmpeg/libavcodec/jrevdct.c @@ -63,7 +63,7 @@ */ #include "libavutil/common.h" -#include "dsputil.h" +#include "dct.h" #define EIGHT_BIT_SAMPLES @@ -74,7 +74,7 @@ #define RIGHT_SHIFT(x, n) ((x) >> (n)) -typedef DCTELEM DCTBLOCK[DCTSIZE2]; +typedef int16_t DCTBLOCK[DCTSIZE2]; #define CONST_BITS 13 @@ -213,7 +213,7 @@ void ff_j_rev_dct(DCTBLOCK data) int32_t tmp10, tmp11, tmp12, tmp13; int32_t z1, z2, z3, z4, z5; int32_t d0, d1, d2, d3, d4, d5, d6, d7; - register DCTELEM *dataptr; + register int16_t *dataptr; int rowctr; /* Pass 1: process rows. */ @@ -249,7 +249,7 @@ void ff_j_rev_dct(DCTBLOCK data) /* AC terms all zero */ if (d0) { /* Compute a 32 bit value to assign. */ - DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS); + int16_t dcval = (int16_t) (d0 << PASS1_BITS); register int v = (dcval & 0xffff) | ((dcval << 16) & 0xffff0000); idataptr[0] = v; @@ -574,14 +574,14 @@ void ff_j_rev_dct(DCTBLOCK data) } /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - dataptr[0] = (DCTELEM) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS); - dataptr[7] = (DCTELEM) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS); - dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS); - dataptr[6] = (DCTELEM) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS); - dataptr[2] = (DCTELEM) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS); - dataptr[5] = (DCTELEM) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS); - dataptr[3] = (DCTELEM) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS); - dataptr[4] = (DCTELEM) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS); + dataptr[0] = (int16_t) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS); + dataptr[7] = (int16_t) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS); + dataptr[1] = (int16_t) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS); + dataptr[6] = (int16_t) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS); + dataptr[2] = (int16_t) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS); + dataptr[5] = (int16_t) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS); + dataptr[3] = (int16_t) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS); + dataptr[4] = (int16_t) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS); dataptr += DCTSIZE; /* advance pointer to next row */ } @@ -920,21 +920,21 @@ void ff_j_rev_dct(DCTBLOCK data) /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp3, + dataptr[DCTSIZE*0] = (int16_t) DESCALE(tmp10 + tmp3, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp10 - tmp3, + dataptr[DCTSIZE*7] = (int16_t) DESCALE(tmp10 - tmp3, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp11 + tmp2, + dataptr[DCTSIZE*1] = (int16_t) DESCALE(tmp11 + tmp2, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(tmp11 - tmp2, + dataptr[DCTSIZE*6] = (int16_t) DESCALE(tmp11 - tmp2, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp12 + tmp1, + dataptr[DCTSIZE*2] = (int16_t) DESCALE(tmp12 + tmp1, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12 - tmp1, + dataptr[DCTSIZE*5] = (int16_t) DESCALE(tmp12 - tmp1, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp13 + tmp0, + dataptr[DCTSIZE*3] = (int16_t) DESCALE(tmp13 + tmp0, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp13 - tmp0, + dataptr[DCTSIZE*4] = (int16_t) DESCALE(tmp13 - tmp0, CONST_BITS+PASS1_BITS+3); dataptr++; /* advance pointer to next column */ @@ -951,7 +951,7 @@ void ff_j_rev_dct4(DCTBLOCK data) int32_t tmp10, tmp11, tmp12, tmp13; int32_t z1; int32_t d0, d2, d4, d6; - register DCTELEM *dataptr; + register int16_t *dataptr; int rowctr; /* Pass 1: process rows. */ @@ -983,7 +983,7 @@ void ff_j_rev_dct4(DCTBLOCK data) /* AC terms all zero */ if (d0) { /* Compute a 32 bit value to assign. */ - DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS); + int16_t dcval = (int16_t) (d0 << PASS1_BITS); register int v = (dcval & 0xffff) | ((dcval << 16) & 0xffff0000); idataptr[0] = v; @@ -1045,10 +1045,10 @@ void ff_j_rev_dct4(DCTBLOCK data) /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - dataptr[0] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS); - dataptr[1] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS); - dataptr[2] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS); - dataptr[3] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS); + dataptr[0] = (int16_t) DESCALE(tmp10, CONST_BITS-PASS1_BITS); + dataptr[1] = (int16_t) DESCALE(tmp11, CONST_BITS-PASS1_BITS); + dataptr[2] = (int16_t) DESCALE(tmp12, CONST_BITS-PASS1_BITS); + dataptr[3] = (int16_t) DESCALE(tmp13, CONST_BITS-PASS1_BITS); dataptr += DCTSTRIDE; /* advance pointer to next row */ } diff --git a/mythtv/external/FFmpeg/libavcodec/kgv1dec.c b/mythtv/external/FFmpeg/libavcodec/kgv1dec.c index 01996368225..6b81095af9c 100644 --- a/mythtv/external/FFmpeg/libavcodec/kgv1dec.c +++ b/mythtv/external/FFmpeg/libavcodec/kgv1dec.c @@ -50,19 +50,19 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, const uint8_t *buf_end = buf + avpkt->size; KgvContext * const c = avctx->priv_data; int offsets[8]; - uint16_t *out, *prev; + uint8_t *out, *prev; int outcnt = 0, maxcnt; int w, h, i, res; if (avpkt->size < 2) - return -1; + return AVERROR_INVALIDDATA; w = (buf[0] + 1) * 8; h = (buf[1] + 1) * 8; buf += 2; - if (av_image_check_size(w, h, 0, avctx)) - return -1; + if ((res = av_image_check_size(w, h, 0, avctx)) < 0) + return res; if (w != avctx->width || h != avctx->height) { if (c->prev.data[0]) @@ -75,9 +75,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, c->cur.reference = 3; if ((res = ff_get_buffer(avctx, &c->cur)) < 0) return res; - out = (uint16_t *) c->cur.data[0]; + out = c->cur.data[0]; if (c->prev.data[0]) { - prev = (uint16_t *) c->prev.data[0]; + prev = c->prev.data[0]; } else { prev = NULL; } @@ -90,11 +90,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, buf += 2; if (!(code & 0x8000)) { - out[outcnt++] = code; // rgb555 pixel coded directly + AV_WN16A(&out[2 * outcnt], code); // rgb555 pixel coded directly + outcnt++; } else { int count; - int inp_off; - uint16_t *inp; if ((code & 0x6000) == 0x6000) { // copy from previous frame @@ -112,7 +111,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, start = (outcnt + offsets[oidx]) % maxcnt; - if (maxcnt - start < count) + if (maxcnt - start < count || maxcnt - outcnt < count) break; if (!prev) { @@ -121,8 +120,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, break; } - inp = prev; - inp_off = start; + memcpy(out + 2 * outcnt, prev + 2 * start, 2 * count); } else { // copy from earlier in this frame int offset = (code & 0x1FFF) + 1; @@ -137,19 +135,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, count = 4 + *buf++; } - if (outcnt < offset) + if (outcnt < offset || maxcnt - outcnt < count) break; - inp = out; - inp_off = outcnt - offset; - } - - if (maxcnt - outcnt < count) - break; - - for (i = inp_off; i < count + inp_off; i++) { - out[outcnt++] = inp[i]; + av_memcpy_backptr(out + 2 * outcnt, 2 * offset, 2 * count); } + outcnt += count; } } diff --git a/mythtv/external/FFmpeg/libavcodec/kmvc.c b/mythtv/external/FFmpeg/libavcodec/kmvc.c index edfafa04011..ffef77138bc 100644 --- a/mythtv/external/FFmpeg/libavcodec/kmvc.c +++ b/mythtv/external/FFmpeg/libavcodec/kmvc.c @@ -264,11 +264,10 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame, { KmvcContext *const ctx = avctx->priv_data; uint8_t *out, *src; - int i; + int i, ret; int header; int blocksize; const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); - int ret; bytestream2_init(&ctx->g, avpkt->data, avpkt->size); if (ctx->pic.data[0]) @@ -383,7 +382,7 @@ static av_cold int decode_init(AVCodecContext * avctx) if (avctx->width > 320 || avctx->height > 200) { av_log(avctx, AV_LOG_ERROR, "KMVC supports frames <= 320x200\n"); - return AVERROR_INVALIDDATA; + return AVERROR(EINVAL); } c->frm0 = av_mallocz(320 * 200); diff --git a/mythtv/external/FFmpeg/libavcodec/lagarith.c b/mythtv/external/FFmpeg/libavcodec/lagarith.c index 486e326a0f4..eb8a77e84cd 100644 --- a/mythtv/external/FFmpeg/libavcodec/lagarith.c +++ b/mythtv/external/FFmpeg/libavcodec/lagarith.c @@ -518,6 +518,7 @@ static int lag_decode_frame(AVCodecContext *avctx, uint32_t offs[4]; uint8_t *srcs[4], *dst; int i, j, planes = 3; + int ret; AVFrame *picture = data; @@ -535,18 +536,33 @@ static int lag_decode_frame(AVCodecContext *avctx, switch (frametype) { case FRAME_SOLID_RGBA: avctx->pix_fmt = AV_PIX_FMT_RGB32; + case FRAME_SOLID_GRAY: + if (frametype == FRAME_SOLID_GRAY) + if (avctx->bits_per_coded_sample == 24) { + avctx->pix_fmt = AV_PIX_FMT_RGB24; + } else { + avctx->pix_fmt = AV_PIX_FMT_0RGB32; + planes = 4; + } - if (ff_thread_get_buffer(avctx, p) < 0) { + if ((ret = ff_thread_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } dst = p->data[0]; + if (frametype == FRAME_SOLID_RGBA) { for (j = 0; j < avctx->height; j++) { for (i = 0; i < avctx->width; i++) AV_WN32(dst + i * 4, offset_gu); dst += p->linesize[0]; } + } else { + for (j = 0; j < avctx->height; j++) { + memset(dst, buf[1], avctx->width * planes); + dst += p->linesize[0]; + } + } break; case FRAME_ARITH_RGBA: avctx->pix_fmt = AV_PIX_FMT_RGB32; @@ -558,9 +574,9 @@ static int lag_decode_frame(AVCodecContext *avctx, if (frametype == FRAME_ARITH_RGB24 || frametype == FRAME_U_RGB24) avctx->pix_fmt = AV_PIX_FMT_RGB24; - if (ff_thread_get_buffer(avctx, p) < 0) { + if ((ret = ff_thread_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } offs[0] = offset_bv; @@ -617,9 +633,9 @@ static int lag_decode_frame(AVCodecContext *avctx, case FRAME_ARITH_YUY2: avctx->pix_fmt = AV_PIX_FMT_YUV422P; - if (ff_thread_get_buffer(avctx, p) < 0) { + if ((ret = ff_thread_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } if (offset_ry >= buf_size || @@ -643,9 +659,9 @@ static int lag_decode_frame(AVCodecContext *avctx, case FRAME_ARITH_YV12: avctx->pix_fmt = AV_PIX_FMT_YUV420P; - if (ff_thread_get_buffer(avctx, p) < 0) { + if ((ret = ff_thread_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } if (buf_size <= offset_ry || buf_size <= offset_gu || buf_size <= offset_bv) { return AVERROR_INVALIDDATA; @@ -672,7 +688,7 @@ static int lag_decode_frame(AVCodecContext *avctx, default: av_log(avctx, AV_LOG_ERROR, "Unsupported Lagarith frame type: %#x\n", frametype); - return -1; + return AVERROR_PATCHWELCOME; } *picture = *p; diff --git a/mythtv/external/FFmpeg/libavcodec/lcldec.c b/mythtv/external/FFmpeg/libavcodec/lcldec.c index 5708a12d3d9..f8d45da95aa 100644 --- a/mythtv/external/FFmpeg/libavcodec/lcldec.c +++ b/mythtv/external/FFmpeg/libavcodec/lcldec.c @@ -138,7 +138,7 @@ static int zlib_decomp(AVCodecContext *avctx, const uint8_t *src, int src_len, i int zret = inflateReset(&c->zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); - return -1; + return AVERROR_UNKNOWN; } c->zstream.next_in = (uint8_t *)src; c->zstream.avail_in = src_len; @@ -147,12 +147,12 @@ static int zlib_decomp(AVCodecContext *avctx, const uint8_t *src, int src_len, i zret = inflate(&c->zstream, Z_FINISH); if (zret != Z_OK && zret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); - return -1; + return AVERROR_UNKNOWN; } if (expected != (unsigned int)c->zstream.total_out) { av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", expected, c->zstream.total_out); - return -1; + return AVERROR_UNKNOWN; } return c->zstream.total_out; } @@ -178,7 +178,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac unsigned int height = avctx->height; // Real image height unsigned int mszh_dlen; unsigned char yq, y1q, uq, vq; - int uqvq; + int uqvq, ret; unsigned int mthread_inlen, mthread_outlen; unsigned int len = buf_size; @@ -187,9 +187,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac c->pic.reference = 0; c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; - if(ff_get_buffer(avctx, &c->pic) < 0){ + if ((ret = ff_get_buffer(avctx, &c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } outptr = c->pic.data[0]; // Output image pointer @@ -203,6 +203,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac ; } else if (c->flags & FLAG_MULTITHREAD) { mthread_inlen = AV_RL32(encoded); + if (len < 8) { + av_log(avctx, AV_LOG_ERROR, "len %d is too small\n", len); + return AVERROR_INVALIDDATA; + } mthread_inlen = FFMIN(mthread_inlen, len - 8); mthread_outlen = AV_RL32(encoded+4); mthread_outlen = FFMIN(mthread_outlen, c->decomp_size); @@ -210,14 +214,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac if (mthread_outlen != mszh_dlen) { av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n", mthread_outlen, mszh_dlen); - return -1; + return AVERROR_INVALIDDATA; } mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - 8 - mthread_inlen, c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen); if (mthread_outlen != mszh_dlen) { av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n", mthread_outlen, mszh_dlen); - return -1; + return AVERROR_INVALIDDATA; } encoded = c->decomp_buf; len = c->decomp_size; @@ -226,7 +230,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac if (c->decomp_size != mszh_dlen) { av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n", c->decomp_size, mszh_dlen); - return -1; + return AVERROR_INVALIDDATA; } encoded = c->decomp_buf; len = mszh_dlen; @@ -257,7 +261,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac } default: av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); - return -1; + return AVERROR_INVALIDDATA; } break; #if CONFIG_ZLIB_DECODER @@ -274,7 +278,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac break; } } else if (c->flags & FLAG_MULTITHREAD) { - int ret; mthread_inlen = AV_RL32(encoded); mthread_inlen = FFMIN(mthread_inlen, len - 8); mthread_outlen = AV_RL32(encoded+4); @@ -294,7 +297,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac #endif default: av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n"); - return -1; + return AVERROR_INVALIDDATA; } @@ -378,7 +381,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac break; default: av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n"); - return -1; + return AVERROR_INVALIDDATA; } } @@ -466,7 +469,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac break; default: av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n"); - return -1; + return AVERROR_INVALIDDATA; } *got_frame = 1; diff --git a/mythtv/external/FFmpeg/libavcodec/libaacplus.c b/mythtv/external/FFmpeg/libavcodec/libaacplus.c index e9e50f8fe9c..05c9e389d1e 100644 --- a/mythtv/external/FFmpeg/libavcodec/libaacplus.c +++ b/mythtv/external/FFmpeg/libavcodec/libaacplus.c @@ -104,7 +104,7 @@ static int aacPlus_encode_frame(AVCodecContext *avctx, AVPacket *pkt, int32_t *input_buffer = (int32_t *)frame->data[0]; int ret; - if ((ret = ff_alloc_packet2(avctx, pkt, s->max_output_bytes))) + if ((ret = ff_alloc_packet2(avctx, pkt, s->max_output_bytes)) < 0) return ret; pkt->size = aacplusEncEncode(s->aacplus_handle, input_buffer, diff --git a/mythtv/external/FFmpeg/libavcodec/libavcodec.v b/mythtv/external/FFmpeg/libavcodec/libavcodec.v index 5fc3f58a7f2..00c233f8123 100644 --- a/mythtv/external/FFmpeg/libavcodec/libavcodec.v +++ b/mythtv/external/FFmpeg/libavcodec/libavcodec.v @@ -1,9 +1,10 @@ LIBAVCODEC_$MAJOR { global: av*; + #deprecated, remove after next bump audio_resample; audio_resample_close; - #deprecated, remove after next bump dsputil_init; + ff_dsputil_init; ff_find_pix_fmt; ff_framenum_to_drop_timecode; ff_framenum_to_smtpe_timecode; diff --git a/mythtv/external/FFmpeg/libavcodec/libcelt_dec.c b/mythtv/external/FFmpeg/libavcodec/libcelt_dec.c index 7f0f9ad25d1..a66f9f56349 100644 --- a/mythtv/external/FFmpeg/libavcodec/libcelt_dec.c +++ b/mythtv/external/FFmpeg/libavcodec/libcelt_dec.c @@ -28,7 +28,6 @@ struct libcelt_context { CELTMode *mode; CELTDecoder *dec; - AVFrame frame; int discard; }; @@ -91,8 +90,6 @@ static av_cold int libcelt_dec_init(AVCodecContext *c) version, lib_version); } c->sample_fmt = AV_SAMPLE_FMT_S16; - avcodec_get_frame_defaults(&celt->frame); - c->coded_frame = &celt->frame; return 0; } @@ -105,31 +102,31 @@ static av_cold int libcelt_dec_close(AVCodecContext *c) return 0; } -static int libcelt_dec_decode(AVCodecContext *c, void *frame, +static int libcelt_dec_decode(AVCodecContext *c, void *data, int *got_frame_ptr, AVPacket *pkt) { struct libcelt_context *celt = c->priv_data; + AVFrame *frame = data; int err; int16_t *pcm; - celt->frame.nb_samples = c->frame_size; - err = ff_get_buffer(c, &celt->frame); + frame->nb_samples = c->frame_size; + err = ff_get_buffer(c, frame); if (err < 0) { av_log(c, AV_LOG_ERROR, "get_buffer() failed\n"); return err; } - pcm = (int16_t *)celt->frame.data[0]; + pcm = (int16_t *)frame->data[0]; err = celt_decode(celt->dec, pkt->data, pkt->size, pcm, c->frame_size); if (err < 0) return ff_celt_error_to_averror(err); if (celt->discard) { - celt->frame.nb_samples -= celt->discard; + frame->nb_samples -= celt->discard; memmove(pcm, pcm + celt->discard * c->channels, - celt->frame.nb_samples * c->channels * sizeof(int16_t)); + frame->nb_samples * c->channels * sizeof(int16_t)); celt->discard = 0; } *got_frame_ptr = 1; - *(AVFrame *)frame = celt->frame; return pkt->size; } diff --git a/mythtv/external/FFmpeg/libavcodec/libfaac.c b/mythtv/external/FFmpeg/libavcodec/libfaac.c index bf226af956e..43de22a80b3 100644 --- a/mythtv/external/FFmpeg/libavcodec/libfaac.c +++ b/mythtv/external/FFmpeg/libavcodec/libfaac.c @@ -184,10 +184,8 @@ static int Faac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int num_samples = frame ? frame->nb_samples : 0; void *samples = frame ? frame->data[0] : NULL; - if ((ret = ff_alloc_packet2(avctx, avpkt, (7 + 768) * avctx->channels))) { - av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); + if ((ret = ff_alloc_packet2(avctx, avpkt, (7 + 768) * avctx->channels)) < 0) return ret; - } bytes_written = faacEncEncode(s->faac_handle, samples, num_samples * avctx->channels, diff --git a/mythtv/external/FFmpeg/libavcodec/libfdk-aacenc.c b/mythtv/external/FFmpeg/libavcodec/libfdk-aacenc.c index 06576aabae7..e4710f6c56c 100644 --- a/mythtv/external/FFmpeg/libavcodec/libfdk-aacenc.c +++ b/mythtv/external/FFmpeg/libavcodec/libfdk-aacenc.c @@ -250,7 +250,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) } if (avctx->cutoff > 0) { - if (avctx->cutoff < (avctx->sample_rate + 255) >> 8) { + if (avctx->cutoff < (avctx->sample_rate + 255) >> 8 || avctx->cutoff > 20000) { av_log(avctx, AV_LOG_ERROR, "cutoff valid range is %d-20000\n", (avctx->sample_rate + 255) >> 8); goto error; @@ -339,7 +339,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } /* The maximum packet size is 6144 bits aka 768 bytes per channel. */ - if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels)))) + if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels))) < 0) return ret; out_ptr = avpkt->data; diff --git a/mythtv/external/FFmpeg/libavcodec/libgsm.c b/mythtv/external/FFmpeg/libavcodec/libgsm.c index f3cfb91f17f..328c7c7e418 100644 --- a/mythtv/external/FFmpeg/libavcodec/libgsm.c +++ b/mythtv/external/FFmpeg/libavcodec/libgsm.c @@ -27,7 +27,12 @@ // The idiosyncrasies of GSM-in-WAV are explained at http://kbs.cs.tu-berlin.de/~jutta/toast.html +#include "config.h" +#if HAVE_GSM_H +#include +#else #include +#endif #include "libavutil/channel_layout.h" #include "libavutil/common.h" @@ -102,7 +107,7 @@ static int libgsm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, gsm_signal *samples = (gsm_signal *)frame->data[0]; struct gsm_state *state = avctx->priv_data; - if ((ret = ff_alloc_packet2(avctx, avpkt, avctx->block_align))) + if ((ret = ff_alloc_packet2(avctx, avpkt, avctx->block_align)) < 0) return ret; switch(avctx->codec_id) { @@ -147,7 +152,6 @@ AVCodec ff_libgsm_ms_encoder = { #endif typedef struct LibGSMDecodeContext { - AVFrame frame; struct gsm_state *state; } LibGSMDecodeContext; @@ -175,9 +179,6 @@ static av_cold int libgsm_decode_init(AVCodecContext *avctx) { } } - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -194,6 +195,7 @@ static int libgsm_decode_frame(AVCodecContext *avctx, void *data, { int i, ret; LibGSMDecodeContext *s = avctx->priv_data; + AVFrame *frame = data; uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int16_t *samples; @@ -204,12 +206,12 @@ static int libgsm_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - s->frame.nb_samples = avctx->frame_size; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = avctx->frame_size; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (int16_t *)s->frame.data[0]; + samples = (int16_t *)frame->data[0]; for (i = 0; i < avctx->frame_size / GSM_FRAME_SIZE; i++) { if ((ret = gsm_decode(s->state, buf, samples)) < 0) @@ -218,8 +220,7 @@ static int libgsm_decode_frame(AVCodecContext *avctx, void *data, samples += GSM_FRAME_SIZE; } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return avctx->block_align; } diff --git a/mythtv/external/FFmpeg/libavcodec/libilbc.c b/mythtv/external/FFmpeg/libavcodec/libilbc.c index f9e286c7edf..98053484b11 100644 --- a/mythtv/external/FFmpeg/libavcodec/libilbc.c +++ b/mythtv/external/FFmpeg/libavcodec/libilbc.c @@ -41,7 +41,6 @@ static int get_mode(AVCodecContext *avctx) typedef struct ILBCDecContext { const AVClass *class; - AVFrame frame; iLBC_Dec_Inst_t decoder; int enhance; } ILBCDecContext; @@ -69,8 +68,6 @@ static av_cold int ilbc_decode_init(AVCodecContext *avctx) } WebRtcIlbcfix_InitDecode(&s->decoder, mode, s->enhance); - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; avctx->channels = 1; avctx->channel_layout = AV_CH_LAYOUT_MONO; @@ -86,6 +83,7 @@ static int ilbc_decode_frame(AVCodecContext *avctx, void *data, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; ILBCDecContext *s = avctx->priv_data; + AVFrame *frame = data; int ret; if (s->decoder.no_of_bytes > buf_size) { @@ -94,17 +92,16 @@ static int ilbc_decode_frame(AVCodecContext *avctx, void *data, return AVERROR_INVALIDDATA; } - s->frame.nb_samples = s->decoder.blockl; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = s->decoder.blockl; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - WebRtcIlbcfix_DecodeImpl((WebRtc_Word16*) s->frame.data[0], + WebRtcIlbcfix_DecodeImpl((WebRtc_Word16*) frame->data[0], (const WebRtc_UWord16*) buf, &s->decoder, 1); - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return s->decoder.no_of_bytes; } @@ -185,10 +182,8 @@ static int ilbc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ILBCEncContext *s = avctx->priv_data; int ret; - if ((ret = ff_alloc_packet(avpkt, 50))) { - av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); + if ((ret = ff_alloc_packet2(avctx, avpkt, 50)) < 0) return ret; - } WebRtcIlbcfix_EncodeImpl((WebRtc_UWord16*) avpkt->data, (const WebRtc_Word16*) frame->data[0], &s->encoder); diff --git a/mythtv/external/FFmpeg/libavcodec/libmp3lame.c b/mythtv/external/FFmpeg/libavcodec/libmp3lame.c index eea9d031b1b..e60856c10b1 100644 --- a/mythtv/external/FFmpeg/libavcodec/libmp3lame.c +++ b/mythtv/external/FFmpeg/libavcodec/libmp3lame.c @@ -218,7 +218,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } } else { lame_result = lame_encode_flush(s->gfp, s->buffer + s->buffer_index, - s->buffer_size - s->buffer_index); + BUFFER_SIZE - s->buffer_index); } if (lame_result < 0) { if (lame_result == -1) { @@ -254,7 +254,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_dlog(avctx, "in:%d packet-len:%d index:%d\n", avctx->frame_size, len, s->buffer_index); if (len <= s->buffer_index) { - if ((ret = ff_alloc_packet2(avctx, avpkt, len))) + if ((ret = ff_alloc_packet2(avctx, avpkt, len)) < 0) return ret; memcpy(avpkt->data, s->buffer, len); s->buffer_index -= len; diff --git a/mythtv/external/FFmpeg/libavcodec/libopencore-amr.c b/mythtv/external/FFmpeg/libavcodec/libopencore-amr.c index 0016cc6dc2e..f52d160502c 100644 --- a/mythtv/external/FFmpeg/libavcodec/libopencore-amr.c +++ b/mythtv/external/FFmpeg/libavcodec/libopencore-amr.c @@ -52,7 +52,6 @@ static int amr_decode_fix_avctx(AVCodecContext *avctx) typedef struct AMRContext { AVClass *av_class; - AVFrame frame; void *dec_state; void *enc_state; int enc_bitrate; @@ -77,9 +76,6 @@ static av_cold int amr_nb_decode_init(AVCodecContext *avctx) return -1; } - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -95,6 +91,7 @@ static av_cold int amr_nb_decode_close(AVCodecContext *avctx) static int amr_nb_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AMRContext *s = avctx->priv_data; @@ -106,8 +103,8 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void *data, buf, buf_size, avctx->frame_number); /* get output buffer */ - s->frame.nb_samples = 160; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = 160; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -124,10 +121,9 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void *data, av_dlog(avctx, "packet_size=%d buf= 0x%X %X %X %X\n", packet_size, buf[0], buf[1], buf[2], buf[3]); /* call decoder */ - Decoder_Interface_Decode(s->dec_state, buf, (short *)s->frame.data[0], 0); + Decoder_Interface_Decode(s->dec_state, buf, (short *)frame->data[0], 0); - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return packet_size; } @@ -251,7 +247,7 @@ static int amr_nb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, s->enc_bitrate = avctx->bit_rate; } - if ((ret = ff_alloc_packet2(avctx, avpkt, 32))) + if ((ret = ff_alloc_packet2(avctx, avpkt, 32)) < 0) return ret; if (frame) { @@ -318,7 +314,6 @@ AVCodec ff_libopencore_amrnb_encoder = { #include typedef struct AMRWBContext { - AVFrame frame; void *state; } AMRWBContext; @@ -332,15 +327,13 @@ static av_cold int amr_wb_decode_init(AVCodecContext *avctx) s->state = D_IF_init(); - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } static int amr_wb_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AMRWBContext *s = avctx->priv_data; @@ -349,8 +342,8 @@ static int amr_wb_decode_frame(AVCodecContext *avctx, void *data, static const uint8_t block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1}; /* get output buffer */ - s->frame.nb_samples = 320; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = 320; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -368,10 +361,9 @@ static int amr_wb_decode_frame(AVCodecContext *avctx, void *data, return AVERROR_INVALIDDATA; } - D_IF_decode(s->state, buf, (short *)s->frame.data[0], _good_frame); + D_IF_decode(s->state, buf, (short *)frame->data[0], _good_frame); - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return packet_size; } diff --git a/mythtv/external/FFmpeg/libavcodec/libopenjpegenc.c b/mythtv/external/FFmpeg/libavcodec/libopenjpegenc.c index 13e8ef914cd..c35508376b6 100644 --- a/mythtv/external/FFmpeg/libavcodec/libopenjpegenc.c +++ b/mythtv/external/FFmpeg/libavcodec/libopenjpegenc.c @@ -100,6 +100,12 @@ static opj_image_t *mj2_create_image(AVCodecContext *avctx, opj_cparameters_t *p case AV_PIX_FMT_RGBA: case AV_PIX_FMT_RGB48: case AV_PIX_FMT_RGBA64: + case AV_PIX_FMT_GBR24P: + case AV_PIX_FMT_GBRP9: + case AV_PIX_FMT_GBRP10: + case AV_PIX_FMT_GBRP12: + case AV_PIX_FMT_GBRP14: + case AV_PIX_FMT_GBRP16: color_space = CLRSPC_SRGB; break; case AV_PIX_FMT_YUV410P: @@ -182,6 +188,35 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx) ctx->enc_params.tcp_numlayers = ctx->numlayers; ctx->enc_params.tcp_rates[0] = FFMAX(avctx->compression_level, 0) * 2; + if (ctx->cinema_mode > 0) { + ctx->enc_params.irreversible = 1; + ctx->enc_params.tcp_mct = 1; + ctx->enc_params.tile_size_on = 0; + /* no subsampling */ + ctx->enc_params.cp_tdx=1; + ctx->enc_params.cp_tdy=1; + ctx->enc_params.subsampling_dx = 1; + ctx->enc_params.subsampling_dy = 1; + /* Tile and Image shall be at (0,0) */ + ctx->enc_params.cp_tx0 = 0; + ctx->enc_params.cp_ty0 = 0; + ctx->enc_params.image_offset_x0 = 0; + ctx->enc_params.image_offset_y0 = 0; + /* Codeblock size= 32*32 */ + ctx->enc_params.cblockw_init = 32; + ctx->enc_params.cblockh_init = 32; + ctx->enc_params.csty |= 0x01; + /* No ROI */ + ctx->enc_params.roi_compno = -1; + + if (ctx->enc_params.prog_order != CPRL) { + av_log(avctx, AV_LOG_ERROR, "prog_order forced to CPRL\n"); + ctx->enc_params.prog_order = CPRL; + } + ctx->enc_params.tp_flag = 'C'; + ctx->enc_params.tp_on = 1; + } + ctx->compress = opj_create_compress(ctx->format); if (!ctx->compress) { av_log(avctx, AV_LOG_ERROR, "Error creating the compressor\n"); @@ -351,6 +386,7 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, opj_cio_t *stream; int cpyresult = 0; int ret, len; + AVFrame gbrframe; // x0, y0 is the top left corner of the image // x1, y1 is the width, height of the reference grid @@ -369,6 +405,25 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, case AV_PIX_FMT_RGBA64: cpyresult = libopenjpeg_copy_packed16(avctx, frame, image); break; + case AV_PIX_FMT_GBR24P: + case AV_PIX_FMT_GBRP9: + case AV_PIX_FMT_GBRP10: + case AV_PIX_FMT_GBRP12: + case AV_PIX_FMT_GBRP14: + case AV_PIX_FMT_GBRP16: + gbrframe = *frame; + gbrframe.data[0] = frame->data[2]; // swap to be rgb + gbrframe.data[1] = frame->data[0]; + gbrframe.data[2] = frame->data[1]; + gbrframe.linesize[0] = frame->linesize[2]; + gbrframe.linesize[1] = frame->linesize[0]; + gbrframe.linesize[2] = frame->linesize[1]; + if (avctx->pix_fmt == AV_PIX_FMT_GBR24P) { + cpyresult = libopenjpeg_copy_unpacked8(avctx, &gbrframe, image); + } else { + cpyresult = libopenjpeg_copy_unpacked16(avctx, &gbrframe, image); + } + break; case AV_PIX_FMT_GRAY8: case AV_PIX_FMT_YUV410P: case AV_PIX_FMT_YUV411P: @@ -505,6 +560,8 @@ AVCodec ff_libopenjpeg_encoder = { .capabilities = 0, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA, AV_PIX_FMT_RGB48, AV_PIX_FMT_RGBA64, + AV_PIX_FMT_GBR24P, + AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16, AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A, AV_PIX_FMT_GRAY16, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVA422P, diff --git a/mythtv/external/FFmpeg/libavcodec/libopusdec.c b/mythtv/external/FFmpeg/libavcodec/libopusdec.c index f603bdf1860..686b8a6798a 100644 --- a/mythtv/external/FFmpeg/libavcodec/libopusdec.c +++ b/mythtv/external/FFmpeg/libavcodec/libopusdec.c @@ -32,7 +32,6 @@ struct libopus_context { OpusMSDecoder *dec; - AVFrame frame; int pre_skip; #ifndef OPUS_SET_GAIN union { int i; double d; } gain; @@ -111,8 +110,7 @@ static av_cold int libopus_decode_init(AVCodecContext *avc) avc->internal->skip_samples = opus->pre_skip; avc->delay = 3840; /* Decoder delay (in samples) at 48kHz */ - avcodec_get_frame_defaults(&opus->frame); - avc->coded_frame = &opus->frame; + return 0; } @@ -126,14 +124,15 @@ static av_cold int libopus_decode_close(AVCodecContext *avc) #define MAX_FRAME_SIZE (960 * 6) -static int libopus_decode(AVCodecContext *avc, void *frame, +static int libopus_decode(AVCodecContext *avc, void *data, int *got_frame_ptr, AVPacket *pkt) { struct libopus_context *opus = avc->priv_data; + AVFrame *frame = data; int ret, nb_samples; - opus->frame.nb_samples = MAX_FRAME_SIZE; - ret = ff_get_buffer(avc, &opus->frame); + frame->nb_samples = MAX_FRAME_SIZE; + ret = ff_get_buffer(avc, frame); if (ret < 0) { av_log(avc, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; @@ -141,12 +140,12 @@ static int libopus_decode(AVCodecContext *avc, void *frame, if (avc->sample_fmt == AV_SAMPLE_FMT_S16) nb_samples = opus_multistream_decode(opus->dec, pkt->data, pkt->size, - (opus_int16 *)opus->frame.data[0], - opus->frame.nb_samples, 0); + (opus_int16 *)frame->data[0], + frame->nb_samples, 0); else nb_samples = opus_multistream_decode_float(opus->dec, pkt->data, pkt->size, - (float *)opus->frame.data[0], - opus->frame.nb_samples, 0); + (float *)frame->data[0], + frame->nb_samples, 0); if (nb_samples < 0) { av_log(avc, AV_LOG_ERROR, "Decoding error: %s\n", @@ -158,20 +157,20 @@ static int libopus_decode(AVCodecContext *avc, void *frame, { int i = avc->channels * nb_samples; if (avc->sample_fmt == AV_SAMPLE_FMT_FLT) { - float *pcm = (float *)opus->frame.data[0]; + float *pcm = (float *)frame->data[0]; for (; i > 0; i--, pcm++) *pcm = av_clipf(*pcm * opus->gain.d, -1, 1); } else { - int16_t *pcm = (int16_t *)opus->frame.data[0]; + int16_t *pcm = (int16_t *)frame->data[0]; for (; i > 0; i--, pcm++) *pcm = av_clip_int16(((int64_t)opus->gain.i * *pcm) >> 16); } } #endif - opus->frame.nb_samples = nb_samples; - *(AVFrame *)frame = opus->frame; - *got_frame_ptr = 1; + frame->nb_samples = nb_samples; + *got_frame_ptr = 1; + return pkt->size; } diff --git a/mythtv/external/FFmpeg/libavcodec/libopusenc.c b/mythtv/external/FFmpeg/libavcodec/libopusenc.c index d1987989299..04c297deba0 100644 --- a/mythtv/external/FFmpeg/libavcodec/libopusenc.c +++ b/mythtv/external/FFmpeg/libavcodec/libopusenc.c @@ -107,6 +107,13 @@ static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc, { int ret; + if (avctx->global_quality) { + av_log(avctx, AV_LOG_ERROR, + "Quality-based encoding not supported, " + "please specify a bitrate and VBR setting.\n"); + return AVERROR(EINVAL); + } + ret = opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(avctx->bit_rate)); if (ret != OPUS_OK) { av_log(avctx, AV_LOG_ERROR, @@ -324,10 +331,8 @@ static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt, /* Maximum packet size taken from opusenc in opus-tools. 60ms packets * consist of 3 frames in one packet. The maximum frame size is 1275 * bytes along with the largest possible packet header of 7 bytes. */ - if (ret = ff_alloc_packet(avpkt, (1275 * 3 + 7) * opus->stream_count)) { - av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); + if ((ret = ff_alloc_packet2(avctx, avpkt, (1275 * 3 + 7) * opus->stream_count)) < 0) return ret; - } if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) ret = opus_multistream_encode_float(opus->enc, (float *)audio, diff --git a/mythtv/external/FFmpeg/libavcodec/libschroedinger.c b/mythtv/external/FFmpeg/libavcodec/libschroedinger.c index c4963e19b76..f452d70a688 100644 --- a/mythtv/external/FFmpeg/libavcodec/libschroedinger.c +++ b/mythtv/external/FFmpeg/libavcodec/libschroedinger.c @@ -46,7 +46,7 @@ static const SchroVideoFormatInfo ff_schro_video_format_info[] = { { 4096, 2160, 24, 1 }, }; -static unsigned int get_video_format_idx(AVCodecContext *avccontext) +static unsigned int get_video_format_idx(AVCodecContext *avctx) { unsigned int ret_idx = 0; unsigned int idx; @@ -55,11 +55,11 @@ static unsigned int get_video_format_idx(AVCodecContext *avccontext) for (idx = 1; idx < num_formats; ++idx) { const SchroVideoFormatInfo *vf = &ff_schro_video_format_info[idx]; - if (avccontext->width == vf->width && - avccontext->height == vf->height) { + if (avctx->width == vf->width && + avctx->height == vf->height) { ret_idx = idx; - if (avccontext->time_base.den == vf->frame_rate_num && - avccontext->time_base.num == vf->frame_rate_denom) + if (avctx->time_base.den == vf->frame_rate_num && + avctx->time_base.num == vf->frame_rate_denom) return idx; } } @@ -136,12 +136,12 @@ static const SchroVideoFormatEnum ff_schro_video_formats[]={ SCHRO_VIDEO_FORMAT_DC4K_24 , }; -SchroVideoFormatEnum ff_get_schro_video_format_preset(AVCodecContext *avccontext) +SchroVideoFormatEnum ff_get_schro_video_format_preset(AVCodecContext *avctx) { unsigned int num_formats = sizeof(ff_schro_video_formats) / sizeof(ff_schro_video_formats[0]); - unsigned int idx = get_video_format_idx(avccontext); + unsigned int idx = get_video_format_idx(avctx); return (idx < num_formats) ? ff_schro_video_formats[idx] : SCHRO_VIDEO_FORMAT_CUSTOM; @@ -175,7 +175,7 @@ static void free_schro_frame(SchroFrame *frame, void *priv) av_freep(&p_pic); } -SchroFrame *ff_create_schro_frame(AVCodecContext *avccontext, +SchroFrame *ff_create_schro_frame(AVCodecContext *avctx, SchroFrameFormat schro_frame_fmt) { AVPicture *p_pic; @@ -184,13 +184,13 @@ SchroFrame *ff_create_schro_frame(AVCodecContext *avccontext, int y_height, uv_height; int i; - y_width = avccontext->width; - y_height = avccontext->height; + y_width = avctx->width; + y_height = avctx->height; uv_width = y_width >> (SCHRO_FRAME_FORMAT_H_SHIFT(schro_frame_fmt)); uv_height = y_height >> (SCHRO_FRAME_FORMAT_V_SHIFT(schro_frame_fmt)); p_pic = av_mallocz(sizeof(AVPicture)); - if (!p_pic || avpicture_alloc(p_pic, avccontext->pix_fmt, y_width, y_height) < 0) { + if (!p_pic || avpicture_alloc(p_pic, avctx->pix_fmt, y_width, y_height) < 0) { av_free(p_pic); return NULL; } diff --git a/mythtv/external/FFmpeg/libavcodec/libschroedinger.h b/mythtv/external/FFmpeg/libavcodec/libschroedinger.h index f2e513b5517..12fe57c7f17 100644 --- a/mythtv/external/FFmpeg/libavcodec/libschroedinger.h +++ b/mythtv/external/FFmpeg/libavcodec/libschroedinger.h @@ -114,7 +114,7 @@ static const struct { * Returns the video format preset matching the input video dimensions and * time base. */ -SchroVideoFormatEnum ff_get_schro_video_format_preset (AVCodecContext *avccontext); +SchroVideoFormatEnum ff_get_schro_video_format_preset (AVCodecContext *avctx); /** * Sets the Schroedinger frame format corresponding to the Schro chroma format @@ -127,7 +127,7 @@ int ff_get_schro_frame_format(SchroChromaFormat schro_chroma_fmt, * Create a Schro frame based on the dimensions and frame format * passed. Returns a pointer to a frame on success, NULL on failure. */ -SchroFrame *ff_create_schro_frame(AVCodecContext *avccontext, +SchroFrame *ff_create_schro_frame(AVCodecContext *avctx, SchroFrameFormat schro_frame_fmt); #endif /* AVCODEC_LIBSCHROEDINGER_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/libschroedingerdec.c b/mythtv/external/FFmpeg/libavcodec/libschroedingerdec.c index bce0271850e..985ae60835c 100644 --- a/mythtv/external/FFmpeg/libavcodec/libschroedingerdec.c +++ b/mythtv/external/FFmpeg/libavcodec/libschroedingerdec.c @@ -147,14 +147,14 @@ static enum AVPixelFormat get_chroma_format(SchroChromaFormat schro_pix_fmt) return AV_PIX_FMT_NONE; } -static av_cold int libschroedinger_decode_init(AVCodecContext *avccontext) +static av_cold int libschroedinger_decode_init(AVCodecContext *avctx) { - SchroDecoderParams *p_schro_params = avccontext->priv_data; + SchroDecoderParams *p_schro_params = avctx->priv_data; /* First of all, initialize our supporting libraries. */ schro_init(); - schro_debug_set_level(avccontext->debug); + schro_debug_set_level(avctx->debug); p_schro_params->decoder = schro_decoder_new(); schro_decoder_set_skip_ratio(p_schro_params->decoder, 1); @@ -171,38 +171,38 @@ static void libschroedinger_decode_frame_free(void *frame) schro_frame_unref(frame); } -static void libschroedinger_handle_first_access_unit(AVCodecContext *avccontext) +static void libschroedinger_handle_first_access_unit(AVCodecContext *avctx) { - SchroDecoderParams *p_schro_params = avccontext->priv_data; + SchroDecoderParams *p_schro_params = avctx->priv_data; SchroDecoder *decoder = p_schro_params->decoder; p_schro_params->format = schro_decoder_get_video_format(decoder); /* Tell FFmpeg about sequence details. */ if (av_image_check_size(p_schro_params->format->width, - p_schro_params->format->height, 0, avccontext) < 0) { - av_log(avccontext, AV_LOG_ERROR, "invalid dimensions (%dx%d)\n", + p_schro_params->format->height, 0, avctx) < 0) { + av_log(avctx, AV_LOG_ERROR, "invalid dimensions (%dx%d)\n", p_schro_params->format->width, p_schro_params->format->height); - avccontext->height = avccontext->width = 0; + avctx->height = avctx->width = 0; return; } - avccontext->height = p_schro_params->format->height; - avccontext->width = p_schro_params->format->width; - avccontext->pix_fmt = get_chroma_format(p_schro_params->format->chroma_format); + avctx->height = p_schro_params->format->height; + avctx->width = p_schro_params->format->width; + avctx->pix_fmt = get_chroma_format(p_schro_params->format->chroma_format); if (ff_get_schro_frame_format(p_schro_params->format->chroma_format, &p_schro_params->frame_format) == -1) { - av_log(avccontext, AV_LOG_ERROR, + av_log(avctx, AV_LOG_ERROR, "This codec currently only supports planar YUV 4:2:0, 4:2:2 " "and 4:4:4 formats.\n"); return; } - avccontext->time_base.den = p_schro_params->format->frame_rate_numerator; - avccontext->time_base.num = p_schro_params->format->frame_rate_denominator; + avctx->time_base.den = p_schro_params->format->frame_rate_numerator; + avctx->time_base.num = p_schro_params->format->frame_rate_denominator; } -static int libschroedinger_decode_frame(AVCodecContext *avccontext, +static int libschroedinger_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { @@ -211,7 +211,7 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext, int64_t pts = avpkt->pts; SchroTag *tag; - SchroDecoderParams *p_schro_params = avccontext->priv_data; + SchroDecoderParams *p_schro_params = avctx->priv_data; SchroDecoder *decoder = p_schro_params->decoder; SchroBuffer *enc_buf; SchroFrame* frame; @@ -237,17 +237,17 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext, /* Set Schrotag with the pts to be recovered after decoding*/ enc_buf->tag = schro_tag_new(av_malloc(sizeof(int64_t)), av_free); if (!enc_buf->tag->value) { - av_log(avccontext, AV_LOG_ERROR, "Unable to allocate SchroTag\n"); + av_log(avctx, AV_LOG_ERROR, "Unable to allocate SchroTag\n"); return AVERROR(ENOMEM); } AV_WN(64, enc_buf->tag->value, pts); /* Push buffer into decoder. */ if (SCHRO_PARSE_CODE_IS_PICTURE(enc_buf->data[4]) && SCHRO_PARSE_CODE_NUM_REFS(enc_buf->data[4]) > 0) - avccontext->has_b_frames = 1; + avctx->has_b_frames = 1; state = schro_decoder_push(decoder, enc_buf); if (state == SCHRO_DECODER_FIRST_ACCESS_UNIT) - libschroedinger_handle_first_access_unit(avccontext); + libschroedinger_handle_first_access_unit(avctx); go = 1; } else outer = 0; @@ -257,7 +257,7 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext, state = schro_decoder_wait(decoder); switch (state) { case SCHRO_DECODER_FIRST_ACCESS_UNIT: - libschroedinger_handle_first_access_unit(avccontext); + libschroedinger_handle_first_access_unit(avctx); break; case SCHRO_DECODER_NEED_BITS: @@ -267,7 +267,7 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext, case SCHRO_DECODER_NEED_FRAME: /* Decoder needs a frame - create one and push it in. */ - frame = ff_create_schro_frame(avccontext, + frame = ff_create_schro_frame(avctx, p_schro_params->frame_format); schro_decoder_add_output_picture(decoder, frame); break; @@ -281,7 +281,7 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext, /* Add relation between schroframe and pts. */ framewithpts = av_malloc(sizeof(LibSchroFrameContext)); if (!framewithpts) { - av_log(avccontext, AV_LOG_ERROR, "Unable to allocate FrameWithPts\n"); + av_log(avctx, AV_LOG_ERROR, "Unable to allocate FrameWithPts\n"); return AVERROR(ENOMEM); } framewithpts->frame = frame; @@ -309,9 +309,9 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext, if (framewithpts && framewithpts->frame) { if (p_schro_params->dec_frame.data[0]) - avccontext->release_buffer(avccontext, &p_schro_params->dec_frame); - if (ff_get_buffer(avccontext, &p_schro_params->dec_frame) < 0) { - av_log(avccontext, AV_LOG_ERROR, "Unable to allocate buffer\n"); + avctx->release_buffer(avctx, &p_schro_params->dec_frame); + if (ff_get_buffer(avctx, &p_schro_params->dec_frame) < 0) { + av_log(avctx, AV_LOG_ERROR, "Unable to allocate buffer\n"); return AVERROR(ENOMEM); } @@ -350,15 +350,15 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext, } -static av_cold int libschroedinger_decode_close(AVCodecContext *avccontext) +static av_cold int libschroedinger_decode_close(AVCodecContext *avctx) { - SchroDecoderParams *p_schro_params = avccontext->priv_data; + SchroDecoderParams *p_schro_params = avctx->priv_data; /* Free the decoder. */ schro_decoder_free(p_schro_params->decoder); av_freep(&p_schro_params->format); if (p_schro_params->dec_frame.data[0]) - avccontext->release_buffer(avccontext, &p_schro_params->dec_frame); + avctx->release_buffer(avctx, &p_schro_params->dec_frame); /* Free data in the output frame queue. */ ff_schro_queue_free(&p_schro_params->dec_frame_queue, @@ -367,11 +367,11 @@ static av_cold int libschroedinger_decode_close(AVCodecContext *avccontext) return 0; } -static void libschroedinger_flush(AVCodecContext *avccontext) +static void libschroedinger_flush(AVCodecContext *avctx) { /* Got a seek request. Free the decoded frames queue and then reset * the decoder */ - SchroDecoderParams *p_schro_params = avccontext->priv_data; + SchroDecoderParams *p_schro_params = avctx->priv_data; /* Free data in the output frame queue. */ ff_schro_queue_free(&p_schro_params->dec_frame_queue, diff --git a/mythtv/external/FFmpeg/libavcodec/libschroedingerenc.c b/mythtv/external/FFmpeg/libavcodec/libschroedingerenc.c index aed78185672..297c6c50c8a 100644 --- a/mythtv/external/FFmpeg/libavcodec/libschroedingerenc.c +++ b/mythtv/external/FFmpeg/libavcodec/libschroedingerenc.c @@ -77,33 +77,32 @@ typedef struct SchroEncoderParams { /** * Works out Schro-compatible chroma format. */ -static int set_chroma_format(AVCodecContext *avccontext) +static int set_chroma_format(AVCodecContext *avctx) { int num_formats = sizeof(schro_pixel_format_map) / sizeof(schro_pixel_format_map[0]); int idx; - SchroEncoderParams *p_schro_params = avccontext->priv_data; + SchroEncoderParams *p_schro_params = avctx->priv_data; for (idx = 0; idx < num_formats; ++idx) { - if (schro_pixel_format_map[idx].ff_pix_fmt == - avccontext->pix_fmt) { + if (schro_pixel_format_map[idx].ff_pix_fmt == avctx->pix_fmt) { p_schro_params->format->chroma_format = schro_pixel_format_map[idx].schro_pix_fmt; return 0; } } - av_log(avccontext, AV_LOG_ERROR, + av_log(avctx, AV_LOG_ERROR, "This codec currently only supports planar YUV 4:2:0, 4:2:2" " and 4:4:4 formats.\n"); return -1; } -static int libschroedinger_encode_init(AVCodecContext *avccontext) +static int libschroedinger_encode_init(AVCodecContext *avctx) { - SchroEncoderParams *p_schro_params = avccontext->priv_data; + SchroEncoderParams *p_schro_params = avctx->priv_data; SchroVideoFormatEnum preset; /* Initialize the libraries that libschroedinger depends on. */ @@ -113,75 +112,75 @@ static int libschroedinger_encode_init(AVCodecContext *avccontext) p_schro_params->encoder = schro_encoder_new(); if (!p_schro_params->encoder) { - av_log(avccontext, AV_LOG_ERROR, + av_log(avctx, AV_LOG_ERROR, "Unrecoverable Error: schro_encoder_new failed. "); return -1; } /* Initialize the format. */ - preset = ff_get_schro_video_format_preset(avccontext); + preset = ff_get_schro_video_format_preset(avctx); p_schro_params->format = schro_encoder_get_video_format(p_schro_params->encoder); schro_video_format_set_std_video_format(p_schro_params->format, preset); - p_schro_params->format->width = avccontext->width; - p_schro_params->format->height = avccontext->height; + p_schro_params->format->width = avctx->width; + p_schro_params->format->height = avctx->height; - if (set_chroma_format(avccontext) == -1) + if (set_chroma_format(avctx) == -1) return -1; - if (avccontext->color_primaries == AVCOL_PRI_BT709) { + if (avctx->color_primaries == AVCOL_PRI_BT709) { p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_HDTV; - } else if (avccontext->color_primaries == AVCOL_PRI_BT470BG) { + } else if (avctx->color_primaries == AVCOL_PRI_BT470BG) { p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_625; - } else if (avccontext->color_primaries == AVCOL_PRI_SMPTE170M) { + } else if (avctx->color_primaries == AVCOL_PRI_SMPTE170M) { p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_525; } - if (avccontext->colorspace == AVCOL_SPC_BT709) { + if (avctx->colorspace == AVCOL_SPC_BT709) { p_schro_params->format->colour_matrix = SCHRO_COLOUR_MATRIX_HDTV; - } else if (avccontext->colorspace == AVCOL_SPC_BT470BG) { + } else if (avctx->colorspace == AVCOL_SPC_BT470BG) { p_schro_params->format->colour_matrix = SCHRO_COLOUR_MATRIX_SDTV; } - if (avccontext->color_trc == AVCOL_TRC_BT709) { + if (avctx->color_trc == AVCOL_TRC_BT709) { p_schro_params->format->transfer_function = SCHRO_TRANSFER_CHAR_TV_GAMMA; } if (ff_get_schro_frame_format(p_schro_params->format->chroma_format, &p_schro_params->frame_format) == -1) { - av_log(avccontext, AV_LOG_ERROR, + av_log(avctx, AV_LOG_ERROR, "This codec currently supports only planar YUV 4:2:0, 4:2:2" " and 4:4:4 formats.\n"); return -1; } - p_schro_params->format->frame_rate_numerator = avccontext->time_base.den; - p_schro_params->format->frame_rate_denominator = avccontext->time_base.num; + p_schro_params->format->frame_rate_numerator = avctx->time_base.den; + p_schro_params->format->frame_rate_denominator = avctx->time_base.num; - p_schro_params->frame_size = avpicture_get_size(avccontext->pix_fmt, - avccontext->width, - avccontext->height); + p_schro_params->frame_size = avpicture_get_size(avctx->pix_fmt, + avctx->width, + avctx->height); - avccontext->coded_frame = &p_schro_params->picture; + avctx->coded_frame = &p_schro_params->picture; - if (!avccontext->gop_size) { + if (!avctx->gop_size) { schro_encoder_setting_set_double(p_schro_params->encoder, "gop_structure", SCHRO_ENCODER_GOP_INTRA_ONLY); - if (avccontext->coder_type == FF_CODER_TYPE_VLC) + if (avctx->coder_type == FF_CODER_TYPE_VLC) schro_encoder_setting_set_double(p_schro_params->encoder, "enable_noarith", 1); } else { schro_encoder_setting_set_double(p_schro_params->encoder, - "au_distance", avccontext->gop_size); - avccontext->has_b_frames = 1; + "au_distance", avctx->gop_size); + avctx->has_b_frames = 1; p_schro_params->dts = -1; } /* FIXME - Need to handle SCHRO_ENCODER_RATE_CONTROL_LOW_DELAY. */ - if (avccontext->flags & CODEC_FLAG_QSCALE) { - if (!avccontext->global_quality) { + if (avctx->flags & CODEC_FLAG_QSCALE) { + if (!avctx->global_quality) { /* lossless coding */ schro_encoder_setting_set_double(p_schro_params->encoder, "rate_control", @@ -192,7 +191,7 @@ static int libschroedinger_encode_init(AVCodecContext *avccontext) "rate_control", SCHRO_ENCODER_RATE_CONTROL_CONSTANT_QUALITY); - quality = avccontext->global_quality / FF_QP2LAMBDA; + quality = avctx->global_quality / FF_QP2LAMBDA; if (quality > 10) quality = 10; schro_encoder_setting_set_double(p_schro_params->encoder, @@ -204,19 +203,17 @@ static int libschroedinger_encode_init(AVCodecContext *avccontext) SCHRO_ENCODER_RATE_CONTROL_CONSTANT_BITRATE); schro_encoder_setting_set_double(p_schro_params->encoder, - "bitrate", - avccontext->bit_rate); - + "bitrate", avctx->bit_rate); } - if (avccontext->flags & CODEC_FLAG_INTERLACED_ME) + if (avctx->flags & CODEC_FLAG_INTERLACED_ME) /* All material can be coded as interlaced or progressive irrespective of the type of source material. */ schro_encoder_setting_set_double(p_schro_params->encoder, "interlaced_coding", 1); schro_encoder_setting_set_double(p_schro_params->encoder, "open_gop", - !(avccontext->flags & CODEC_FLAG_CLOSED_GOP)); + !(avctx->flags & CODEC_FLAG_CLOSED_GOP)); /* FIXME: Signal range hardcoded to 8-bit data until both libschroedinger * and libdirac support other bit-depth data. */ @@ -228,7 +225,7 @@ static int libschroedinger_encode_init(AVCodecContext *avccontext) p_schro_params->format); /* Set the debug level. */ - schro_debug_set_level(avccontext->debug); + schro_debug_set_level(avctx->debug); schro_encoder_start(p_schro_params->encoder); @@ -237,19 +234,19 @@ static int libschroedinger_encode_init(AVCodecContext *avccontext) return 0; } -static SchroFrame *libschroedinger_frame_from_data(AVCodecContext *avccontext, +static SchroFrame *libschroedinger_frame_from_data(AVCodecContext *avctx, const AVFrame *frame) { - SchroEncoderParams *p_schro_params = avccontext->priv_data; + SchroEncoderParams *p_schro_params = avctx->priv_data; SchroFrame *in_frame; /* Input line size may differ from what the codec supports. Especially * when transcoding from one format to another. So use avpicture_layout * to copy the frame. */ - in_frame = ff_create_schro_frame(avccontext, p_schro_params->frame_format); + in_frame = ff_create_schro_frame(avctx, p_schro_params->frame_format); if (in_frame) - avpicture_layout((const AVPicture *)frame, avccontext->pix_fmt, - avccontext->width, avccontext->height, + avpicture_layout((const AVPicture *)frame, avctx->pix_fmt, + avctx->width, avctx->height, in_frame->components[0].data, p_schro_params->frame_size); @@ -264,11 +261,11 @@ static void libschroedinger_free_frame(void *data) av_free(enc_frame); } -static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pkt, +static int libschroedinger_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet) { int enc_size = 0; - SchroEncoderParams *p_schro_params = avccontext->priv_data; + SchroEncoderParams *p_schro_params = avctx->priv_data; SchroEncoder *encoder = p_schro_params->encoder; struct FFSchroEncodedFrame *p_frame_output = NULL; int go = 1; @@ -286,8 +283,7 @@ static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pk } } else { /* Allocate frame data to schro input buffer. */ - SchroFrame *in_frame = libschroedinger_frame_from_data(avccontext, - frame); + SchroFrame *in_frame = libschroedinger_frame_from_data(avctx, frame); /* Load next frame. */ schro_encoder_push_frame(encoder, in_frame); } @@ -358,7 +354,7 @@ static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pk break; default: - av_log(avccontext, AV_LOG_ERROR, "Unknown Schro Encoder state\n"); + av_log(avctx, AV_LOG_ERROR, "Unknown Schro Encoder state\n"); return -1; } } @@ -377,16 +373,16 @@ static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pk pkt_size = p_frame_output->size; if (last_frame_in_sequence && p_schro_params->enc_buf_size > 0) pkt_size += p_schro_params->enc_buf_size; - if ((ret = ff_alloc_packet2(avccontext, pkt, pkt_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size)) < 0) goto error; memcpy(pkt->data, p_frame_output->p_encbuf, p_frame_output->size); - avccontext->coded_frame->key_frame = p_frame_output->key_frame; + avctx->coded_frame->key_frame = p_frame_output->key_frame; /* Use the frame number of the encoded frame as the pts. It is OK to * do so since Dirac is a constant frame rate codec. It expects input * to be of constant frame rate. */ pkt->pts = - avccontext->coded_frame->pts = p_frame_output->frame_num; + avctx->coded_frame->pts = p_frame_output->frame_num; pkt->dts = p_schro_params->dts++; enc_size = p_frame_output->size; @@ -411,9 +407,9 @@ static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pk } -static int libschroedinger_encode_close(AVCodecContext *avccontext) +static int libschroedinger_encode_close(AVCodecContext *avctx) { - SchroEncoderParams *p_schro_params = avccontext->priv_data; + SchroEncoderParams *p_schro_params = avctx->priv_data; /* Close the encoder. */ schro_encoder_free(p_schro_params->encoder); diff --git a/mythtv/external/FFmpeg/libavcodec/libspeexdec.c b/mythtv/external/FFmpeg/libavcodec/libspeexdec.c index 2ab0a8d4eda..1b2db78015e 100644 --- a/mythtv/external/FFmpeg/libavcodec/libspeexdec.c +++ b/mythtv/external/FFmpeg/libavcodec/libspeexdec.c @@ -29,7 +29,6 @@ #include "internal.h" typedef struct { - AVFrame frame; SpeexBits bits; SpeexStereoState stereo; void *dec_state; @@ -104,9 +103,6 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx) speex_decoder_ctl(s->dec_state, SPEEX_SET_HANDLER, &callback); } - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -116,16 +112,17 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data, uint8_t *buf = avpkt->data; int buf_size = avpkt->size; LibSpeexContext *s = avctx->priv_data; + AVFrame *frame = data; int16_t *output; int ret, consumed = 0; /* get output buffer */ - s->frame.nb_samples = s->frame_size; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = s->frame_size; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - output = (int16_t *)s->frame.data[0]; + output = (int16_t *)frame->data[0]; /* if there is not enough data left for the smallest possible frame or the next 5 bits are a terminator code, reset the libspeex buffer using the @@ -152,8 +149,7 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data, if (avctx->channels == 2) speex_decode_stereo_int(output, s->frame_size, &s->stereo); - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return consumed; } diff --git a/mythtv/external/FFmpeg/libavcodec/libspeexenc.c b/mythtv/external/FFmpeg/libavcodec/libspeexenc.c index 23ebe72dadd..051dce6dd0b 100644 --- a/mythtv/external/FFmpeg/libavcodec/libspeexenc.c +++ b/mythtv/external/FFmpeg/libavcodec/libspeexenc.c @@ -304,7 +304,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, /* write output if all frames for the packet have been encoded */ if (s->pkt_frame_count == s->frames_per_packet) { s->pkt_frame_count = 0; - if ((ret = ff_alloc_packet2(avctx, avpkt, speex_bits_nbytes(&s->bits)))) + if ((ret = ff_alloc_packet2(avctx, avpkt, speex_bits_nbytes(&s->bits))) < 0) return ret; ret = speex_bits_write(&s->bits, avpkt->data, avpkt->size); speex_bits_reset(&s->bits); diff --git a/mythtv/external/FFmpeg/libavcodec/libtwolame.c b/mythtv/external/FFmpeg/libavcodec/libtwolame.c index b57fbc96e02..88587141904 100644 --- a/mythtv/external/FFmpeg/libavcodec/libtwolame.c +++ b/mythtv/external/FFmpeg/libavcodec/libtwolame.c @@ -94,7 +94,7 @@ static int twolame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, TWOLAMEContext *s = avctx->priv_data; int ret; - if ((ret = ff_alloc_packet2(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE))) + if ((ret = ff_alloc_packet2(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE)) < 0) return ret; if (frame) { diff --git a/mythtv/external/FFmpeg/libavcodec/libutvideo.h b/mythtv/external/FFmpeg/libavcodec/libutvideo.h index a9387e134eb..ac665b21906 100644 --- a/mythtv/external/FFmpeg/libavcodec/libutvideo.h +++ b/mythtv/external/FFmpeg/libavcodec/libutvideo.h @@ -31,6 +31,16 @@ #include #include +/* Ut Video version 12.0.0 removed the _WIN names, so if those are + * absent, redefine them to maintain compatibility with pre-v12 versions.*/ +#if !defined(UTVF_RGB24_WIN) +#define UTVF_RGB24_WIN UTVF_NFCC_BGR_BU +#endif + +#if !defined(UTVF_RGB32_WIN) +#define UTVF_RGB32_WIN UTVF_NFCC_BGRA_BU +#endif + typedef struct { uint32_t version; uint32_t original_format; diff --git a/mythtv/external/FFmpeg/libavcodec/libvo-aacenc.c b/mythtv/external/FFmpeg/libavcodec/libvo-aacenc.c index 1414aadb646..10f292b784b 100644 --- a/mythtv/external/FFmpeg/libavcodec/libvo-aacenc.c +++ b/mythtv/external/FFmpeg/libavcodec/libvo-aacenc.c @@ -161,7 +161,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, return ret; } - if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels)))) + if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels))) < 0) return ret; input.Buffer = samples; diff --git a/mythtv/external/FFmpeg/libavcodec/libvo-amrwbenc.c b/mythtv/external/FFmpeg/libavcodec/libvo-amrwbenc.c index eaf632d469a..42943744825 100644 --- a/mythtv/external/FFmpeg/libavcodec/libvo-amrwbenc.c +++ b/mythtv/external/FFmpeg/libavcodec/libvo-amrwbenc.c @@ -121,7 +121,7 @@ static int amr_wb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const int16_t *samples = (const int16_t *)frame->data[0]; int size, ret; - if ((ret = ff_alloc_packet2(avctx, avpkt, MAX_PACKET_SIZE))) + if ((ret = ff_alloc_packet2(avctx, avpkt, MAX_PACKET_SIZE)) < 0) return ret; if (s->last_bitrate != avctx->bit_rate) { diff --git a/mythtv/external/FFmpeg/libavcodec/libvorbisdec.c b/mythtv/external/FFmpeg/libavcodec/libvorbisdec.c index 8f5f9d85f91..99fb83aac0b 100644 --- a/mythtv/external/FFmpeg/libavcodec/libvorbisdec.c +++ b/mythtv/external/FFmpeg/libavcodec/libvorbisdec.c @@ -25,7 +25,6 @@ #include "internal.h" typedef struct OggVorbisDecContext { - AVFrame frame; vorbis_info vi; /**< vorbis_info used during init */ vorbis_dsp_state vd; /**< DSP state used for analysis */ vorbis_block vb; /**< vorbis_block used for analysis */ @@ -99,6 +98,7 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) { avccontext->channels = context->vi.channels; avccontext->sample_rate = context->vi.rate; + avccontext->sample_fmt = AV_SAMPLE_FMT_S16; avccontext->time_base= (AVRational){1, avccontext->sample_rate}; vorbis_synthesis_init(&context->vd, &context->vi); @@ -130,6 +130,7 @@ static int oggvorbis_decode_frame(AVCodecContext *avccontext, void *data, int *got_frame_ptr, AVPacket *avpkt) { OggVorbisDecContext *context = avccontext->priv_data ; + AVFrame *frame = data; float **pcm ; ogg_packet *op= &context->op; int samples, total_samples, total_bytes; @@ -141,12 +142,12 @@ static int oggvorbis_decode_frame(AVCodecContext *avccontext, void *data, return 0; } - context->frame.nb_samples = 8192*4; - if ((ret = ff_get_buffer(avccontext, &context->frame)) < 0) { + frame->nb_samples = 8192*4; + if ((ret = ff_get_buffer(avccontext, frame)) < 0) { av_log(avccontext, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - output = (int16_t *)context->frame.data[0]; + output = (int16_t *)frame->data[0]; op->packet = avpkt->data; @@ -171,9 +172,8 @@ static int oggvorbis_decode_frame(AVCodecContext *avccontext, void *data, vorbis_synthesis_read(&context->vd, samples) ; } - context->frame.nb_samples = total_samples; + frame->nb_samples = total_samples; *got_frame_ptr = 1; - *(AVFrame *)data = context->frame; return avpkt->size; } diff --git a/mythtv/external/FFmpeg/libavcodec/libvorbisenc.c b/mythtv/external/FFmpeg/libavcodec/libvorbisenc.c index 188c8cc9c53..1c0dab65e9c 100644 --- a/mythtv/external/FFmpeg/libavcodec/libvorbisenc.c +++ b/mythtv/external/FFmpeg/libavcodec/libvorbisenc.c @@ -348,7 +348,7 @@ static int oggvorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_fifo_generic_read(s->pkt_fifo, &op, sizeof(ogg_packet), NULL); - if ((ret = ff_alloc_packet2(avctx, avpkt, op.bytes))) + if ((ret = ff_alloc_packet2(avctx, avpkt, op.bytes)) < 0) return ret; av_fifo_generic_read(s->pkt_fifo, avpkt->data, op.bytes, NULL); diff --git a/mythtv/external/FFmpeg/libavcodec/libvpxdec.c b/mythtv/external/FFmpeg/libavcodec/libvpxdec.c index 809266a9829..7e41e80646b 100644 --- a/mythtv/external/FFmpeg/libavcodec/libvpxdec.c +++ b/mythtv/external/FFmpeg/libavcodec/libvpxdec.c @@ -35,10 +35,10 @@ typedef struct VP8DecoderContext { struct vpx_codec_ctx decoder; } VP8Context; -static av_cold int vp8_init(AVCodecContext *avctx) +static av_cold int vpx_init(AVCodecContext *avctx, + const struct vpx_codec_iface *iface) { VP8Context *ctx = avctx->priv_data; - const struct vpx_codec_iface *iface = &vpx_codec_vp8_dx_algo; struct vpx_codec_dec_cfg deccfg = { /* token partitions+1 would be a decent choice */ .threads = FFMIN(avctx->thread_count, 16) @@ -112,7 +112,13 @@ static av_cold int vp8_free(AVCodecContext *avctx) return 0; } -AVCodec ff_libvpx_decoder = { +#if CONFIG_LIBVPX_VP8_DECODER +static av_cold int vp8_init(AVCodecContext *avctx) +{ + return vpx_init(avctx, &vpx_codec_vp8_dx_algo); +} + +AVCodec ff_libvpx_vp8_decoder = { .name = "libvpx", .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_VP8, @@ -123,3 +129,23 @@ AVCodec ff_libvpx_decoder = { .capabilities = CODEC_CAP_AUTO_THREADS, .long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"), }; +#endif /* CONFIG_LIBVPX_VP8_DECODER */ + +#if CONFIG_LIBVPX_VP9_DECODER +static av_cold int vp9_init(AVCodecContext *avctx) +{ + return vpx_init(avctx, &vpx_codec_vp9_dx_algo); +} + +AVCodec ff_libvpx_vp9_decoder = { + .name = "libvpx-vp9", + .type = AVMEDIA_TYPE_VIDEO, + .id = AV_CODEC_ID_VP9, + .priv_data_size = sizeof(VP8Context), + .init = vp9_init, + .close = vp8_free, + .decode = vp8_decode, + .capabilities = CODEC_CAP_AUTO_THREADS | CODEC_CAP_EXPERIMENTAL, + .long_name = NULL_IF_CONFIG_SMALL("libvpx VP9"), +}; +#endif /* CONFIG_LIBVPX_VP9_DECODER */ diff --git a/mythtv/external/FFmpeg/libavcodec/libvpxenc.c b/mythtv/external/FFmpeg/libavcodec/libvpxenc.c index 0de11b5448c..4f1adb85c47 100644 --- a/mythtv/external/FFmpeg/libavcodec/libvpxenc.c +++ b/mythtv/external/FFmpeg/libavcodec/libvpxenc.c @@ -48,6 +48,9 @@ struct FrameListData { unsigned long duration; /**< duration to show frame (in timebase units) */ uint32_t flags; /**< flags for this frame */ + uint64_t sse[4]; + int have_sse; /**< true if we have pending sse[] */ + uint64_t frame_number; struct FrameListData *next; }; @@ -57,6 +60,9 @@ typedef struct VP8EncoderContext { struct vpx_image rawimg; struct vpx_fixed_buf twopass_stats; int deadline; //i.e., RT/GOOD/BEST + uint64_t sse[4]; + int have_sse; /**< true if we have pending sse[] */ + uint64_t frame_number; struct FrameListData *coded_frame_list; int cpu_used; @@ -227,11 +233,12 @@ static av_cold int vp8_free(AVCodecContext *avctx) return 0; } -static av_cold int vp8_init(AVCodecContext *avctx) +static av_cold int vpx_init(AVCodecContext *avctx, + const struct vpx_codec_iface *iface) { VP8Context *ctx = avctx->priv_data; - const struct vpx_codec_iface *iface = &vpx_codec_vp8_cx_algo; struct vpx_codec_enc_cfg enccfg; + vpx_codec_flags_t flags = (avctx->flags & CODEC_FLAG_PSNR) ? VPX_CODEC_USE_PSNR : 0; int res; av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str()); @@ -285,10 +292,20 @@ static av_cold int vp8_init(AVCodecContext *avctx) } } - if (avctx->qmin > 0) + if (avctx->qmin >= 0) enccfg.rc_min_quantizer = avctx->qmin; if (avctx->qmax > 0) enccfg.rc_max_quantizer = avctx->qmax; + + if (enccfg.rc_end_usage == VPX_CQ) { + if (ctx->crf < enccfg.rc_min_quantizer || ctx->crf > enccfg.rc_max_quantizer) { + av_log(avctx, AV_LOG_ERROR, + "CQ level must be between minimum and maximum quantizer value (%d-%d)\n", + enccfg.rc_min_quantizer, enccfg.rc_max_quantizer); + return AVERROR(EINVAL); + } + } + enccfg.rc_dropframe_thresh = avctx->frame_skip_threshold; //0-100 (0 => CBR, 100 => VBR) @@ -354,7 +371,7 @@ static av_cold int vp8_init(AVCodecContext *avctx) dump_enc_cfg(avctx, &enccfg); /* Construct Encoder Context */ - res = vpx_codec_enc_init(&ctx->encoder, iface, &enccfg, 0); + res = vpx_codec_enc_init(&ctx->encoder, iface, &enccfg, flags); if (res != VPX_CODEC_OK) { log_encoder_error(avctx, "Failed to initialize encoder"); return AVERROR(EINVAL); @@ -397,13 +414,30 @@ static av_cold int vp8_init(AVCodecContext *avctx) } static inline void cx_pktcpy(struct FrameListData *dst, - const struct vpx_codec_cx_pkt *src) + const struct vpx_codec_cx_pkt *src, + VP8Context *ctx) { dst->pts = src->data.frame.pts; dst->duration = src->data.frame.duration; dst->flags = src->data.frame.flags; dst->sz = src->data.frame.sz; dst->buf = src->data.frame.buf; + dst->have_sse = 0; + /* For alt-ref frame, don't store PSNR or increment frame_number */ + if (!(dst->flags & VPX_FRAME_IS_INVISIBLE)) { + dst->frame_number = ++ctx->frame_number; + dst->have_sse = ctx->have_sse; + if (ctx->have_sse) { + /* associate last-seen SSE to the frame. */ + /* Transfers ownership from ctx to dst. */ + /* WARNING! This makes the assumption that PSNR_PKT comes + just before the frame it refers to! */ + memcpy(dst->sse, ctx->sse, sizeof(dst->sse)); + ctx->have_sse = 0; + } + } else { + dst->frame_number = -1; /* sanity marker */ + } } /** @@ -428,6 +462,19 @@ static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame, pkt->flags |= AV_PKT_FLAG_KEY; } else coded_frame->pict_type = AV_PICTURE_TYPE_P; + + if (cx_frame->have_sse) { + int i; + /* Beware of the Y/U/V/all order! */ + coded_frame->error[0] = cx_frame->sse[1]; + coded_frame->error[1] = cx_frame->sse[2]; + coded_frame->error[2] = cx_frame->sse[3]; + coded_frame->error[3] = 0; // alpha + for (i = 0; i < 4; ++i) { + avctx->error[i] += coded_frame->error[i]; + } + cx_frame->have_sse = 0; + } } else { return ret; } @@ -471,7 +518,7 @@ static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out, /* avoid storing the frame when the list is empty and we haven't yet provided a frame for output */ av_assert0(!ctx->coded_frame_list); - cx_pktcpy(&cx_frame, pkt); + cx_pktcpy(&cx_frame, pkt, ctx); size = storeframe(avctx, &cx_frame, pkt_out, coded_frame); if (size < 0) return size; @@ -484,7 +531,7 @@ static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out, "Frame queue element alloc failed\n"); return AVERROR(ENOMEM); } - cx_pktcpy(cx_frame, pkt); + cx_pktcpy(cx_frame, pkt, ctx); cx_frame->buf = av_malloc(cx_frame->sz); if (!cx_frame->buf) { @@ -511,7 +558,14 @@ static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out, stats->sz += pkt->data.twopass_stats.sz; break; } - case VPX_CODEC_PSNR_PKT: //FIXME add support for CODEC_FLAG_PSNR + case VPX_CODEC_PSNR_PKT: + av_assert0(!ctx->have_sse); + ctx->sse[0] = pkt->data.psnr.sse[0]; + ctx->sse[1] = pkt->data.psnr.sse[1]; + ctx->sse[2] = pkt->data.psnr.sse[2]; + ctx->sse[3] = pkt->data.psnr.sse[3]; + ctx->have_sse = 1; + break; case VPX_CODEC_CUSTOM_PKT: //ignore unsupported/unrecognized packet types break; @@ -608,13 +662,6 @@ static const AVOption options[] = { { NULL } }; -static const AVClass class = { - .class_name = "libvpx encoder", - .item_name = av_default_item_name, - .option = options, - .version = LIBAVUTIL_VERSION_INT, -}; - static const AVCodecDefault defaults[] = { { "qmin", "-1" }, { "qmax", "-1" }, @@ -623,7 +670,20 @@ static const AVCodecDefault defaults[] = { { NULL }, }; -AVCodec ff_libvpx_encoder = { +#if CONFIG_LIBVPX_VP8_ENCODER +static av_cold int vp8_init(AVCodecContext *avctx) +{ + return vpx_init(avctx, &vpx_codec_vp8_cx_algo); +} + +static const AVClass class_vp8 = { + .class_name = "libvpx encoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVCodec ff_libvpx_vp8_encoder = { .name = "libvpx", .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_VP8, @@ -634,6 +694,36 @@ AVCodec ff_libvpx_encoder = { .capabilities = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE }, .long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"), - .priv_class = &class, + .priv_class = &class_vp8, + .defaults = defaults, +}; +#endif /* CONFIG_LIBVPX_VP8_ENCODER */ + +#if CONFIG_LIBVPX_VP9_ENCODER +static av_cold int vp9_init(AVCodecContext *avctx) +{ + return vpx_init(avctx, &vpx_codec_vp9_cx_algo); +} + +static const AVClass class_vp9 = { + .class_name = "libvpx encoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVCodec ff_libvpx_vp9_encoder = { + .name = "libvpx-vp9", + .type = AVMEDIA_TYPE_VIDEO, + .id = AV_CODEC_ID_VP9, + .priv_data_size = sizeof(VP8Context), + .init = vp9_init, + .encode2 = vp8_encode, + .close = vp8_free, + .capabilities = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS | CODEC_CAP_EXPERIMENTAL, + .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE }, + .long_name = NULL_IF_CONFIG_SMALL("libvpx VP9"), + .priv_class = &class_vp9, .defaults = defaults, }; +#endif /* CONFIG_LIBVPX_VP9_ENCODER */ diff --git a/mythtv/external/FFmpeg/libavcodec/libx264.c b/mythtv/external/FFmpeg/libavcodec/libx264.c index 3e7592edef6..7e8fa65818d 100644 --- a/mythtv/external/FFmpeg/libavcodec/libx264.c +++ b/mythtv/external/FFmpeg/libavcodec/libx264.c @@ -73,6 +73,7 @@ typedef struct X264Context { int slice_max_size; char *stats; int nal_hrd; + char *x264_params; } X264Context; static void X264_log(void *p, int level, const char *fmt, va_list args) @@ -285,7 +286,6 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER; - x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor); x4->params.rc.f_pb_factor = avctx->b_quant_factor; x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset; if (x4->preset || x4->tune) @@ -356,6 +356,9 @@ static av_cold int X264_init(AVCodecContext *avctx) } } + if (avctx->i_quant_factor > 0) + x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor); + if (avctx->me_method == ME_EPZS) x4->params.analyse.i_me_method = X264_ME_DIA; else if (avctx->me_method == ME_HEX) @@ -522,6 +525,22 @@ static av_cold int X264_init(AVCodecContext *avctx) if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) x4->params.b_repeat_headers = 0; + if (x4->x264_params) { + AVDictionary *dict = NULL; + AVDictionaryEntry *en = NULL; + + if (!av_dict_parse_string(&dict, x4->x264_params, "=", ":", 0)) { + while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) { + if (x264_param_parse(&x4->params, en->key, en->value) < 0) + av_log(avctx, AV_LOG_WARNING, + "Error parsing option '%s = %s'.\n", + en->key, en->value); + } + + av_dict_free(&dict); + } + } + // update AVCodecContext with x264 parameters avctx->has_b_frames = x4->params.i_bframe ? x4->params.i_bframe_pyramid ? 2 : 1 : 0; @@ -653,6 +672,7 @@ static const AVOption options[] = { { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_NONE}, INT_MIN, INT_MAX, VE, "nal-hrd" }, { "vbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_VBR}, INT_MIN, INT_MAX, VE, "nal-hrd" }, { "cbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_CBR}, INT_MIN, INT_MAX, VE, "nal-hrd" }, + { "x264-params", "Override the x264 configuration using a :-separated list of key=value parameters", OFFSET(x264_params), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { NULL }, }; @@ -675,6 +695,7 @@ static const AVCodecDefault x264_defaults[] = { { "bf", "-1" }, { "flags2", "0" }, { "g", "-1" }, + { "i_qfactor", "-1" }, { "qmin", "-1" }, { "qmax", "-1" }, { "qdiff", "-1" }, diff --git a/mythtv/external/FFmpeg/libavcodec/libxvid.c b/mythtv/external/FFmpeg/libavcodec/libxvid.c index dae8ac82442..05a12db58b1 100644 --- a/mythtv/external/FFmpeg/libavcodec/libxvid.c +++ b/mythtv/external/FFmpeg/libavcodec/libxvid.c @@ -60,6 +60,7 @@ struct xvid_context { char *twopassbuffer; /**< Character buffer for two-pass */ char *old_twopassbuffer; /**< Old character buffer (two-pass) */ char *twopassfile; /**< second pass temp file name */ + int twopassfd; unsigned char *intra_matrix; /**< P-Frame Quant Matrix */ unsigned char *inter_matrix; /**< I-Frame Quant Matrix */ }; @@ -72,6 +73,8 @@ struct xvid_ff_pass1 { struct xvid_context *context; /**< Pointer to private context */ }; +static int xvid_encode_close(AVCodecContext *avctx); + /* * Xvid 2-Pass Kludge Section * @@ -356,6 +359,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { xvid_enc_create_t xvid_enc_create = { 0 }; xvid_enc_plugin_t plugins[7]; + x->twopassfd = -1; + /* Bring in VOP flags from ffmpeg command-line */ x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */ if( xvid_flags & CODEC_FLAG_4MV ) @@ -474,7 +479,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { if( x->twopassbuffer == NULL || x->old_twopassbuffer == NULL ) { av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot allocate 2-pass log buffers\n"); - return -1; + goto fail; } x->twopassbuffer[0] = x->old_twopassbuffer[0] = 0; @@ -489,24 +494,23 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { if( fd == -1 ) { av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot write 2-pass pipe\n"); - return -1; + goto fail; } + x->twopassfd = fd; if( avctx->stats_in == NULL ) { av_log(avctx, AV_LOG_ERROR, "Xvid: No 2-pass information loaded for second pass\n"); - return -1; + goto fail; } if( strlen(avctx->stats_in) > write(fd, avctx->stats_in, strlen(avctx->stats_in)) ) { - close(fd); av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot write to 2-pass pipe\n"); - return -1; + goto fail; } - close(fd); rc2pass2.filename = x->twopassfile; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; plugins[xvid_enc_create.num_plugins].param = &rc2pass2; @@ -604,13 +608,16 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); if( xerr ) { av_log(avctx, AV_LOG_ERROR, "Xvid: Could not create encoder reference\n"); - return -1; + goto fail; } x->encoder_handle = xvid_enc_create.handle; avctx->coded_frame = &x->encoded_picture; return 0; +fail: + xvid_encode_close(avctx); + return -1; } static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt, @@ -733,17 +740,24 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt, static av_cold int xvid_encode_close(AVCodecContext *avctx) { struct xvid_context *x = avctx->priv_data; - xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL); + if(x->encoder_handle) + xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL); + x->encoder_handle = NULL; av_freep(&avctx->extradata); if( x->twopassbuffer != NULL ) { - av_free(x->twopassbuffer); - av_free(x->old_twopassbuffer); + av_freep(&x->twopassbuffer); + av_freep(&x->old_twopassbuffer); avctx->stats_out = NULL; } - av_free(x->twopassfile); - av_free(x->intra_matrix); - av_free(x->inter_matrix); + if (x->twopassfd>=0) { + unlink(x->twopassfile); + close(x->twopassfd); + x->twopassfd = -1; + } + av_freep(&x->twopassfile); + av_freep(&x->intra_matrix); + av_freep(&x->inter_matrix); return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/libxvid_rc.c b/mythtv/external/FFmpeg/libavcodec/libxvid_rc.c index 93aeb7199b8..4a5842f9730 100644 --- a/mythtv/external/FFmpeg/libavcodec/libxvid_rc.c +++ b/mythtv/external/FFmpeg/libavcodec/libxvid_rc.c @@ -26,7 +26,6 @@ #include "libavutil/file.h" #include "avcodec.h" #include "libxvid.h" -//#include "dsputil.h" #include "mpegvideo.h" #undef NDEBUG diff --git a/mythtv/external/FFmpeg/libavcodec/ljpegenc.c b/mythtv/external/FFmpeg/libavcodec/ljpegenc.c index 0ab4985c105..064b9114b9b 100644 --- a/mythtv/external/FFmpeg/libavcodec/ljpegenc.c +++ b/mythtv/external/FFmpeg/libavcodec/ljpegenc.c @@ -31,7 +31,6 @@ */ #include "avcodec.h" -#include "dsputil.h" #include "internal.h" #include "mpegvideo.h" #include "mjpeg.h" diff --git a/mythtv/external/FFmpeg/libavcodec/loco.c b/mythtv/external/FFmpeg/libavcodec/loco.c index f53e11cea37..2b7116685d5 100644 --- a/mythtv/external/FFmpeg/libavcodec/loco.c +++ b/mythtv/external/FFmpeg/libavcodec/loco.c @@ -30,29 +30,39 @@ #include "internal.h" #include "mathops.h" -enum LOCO_MODE {LOCO_UNKN=0, LOCO_CYUY2=-1, LOCO_CRGB=-2, LOCO_CRGBA=-3, LOCO_CYV12=-4, - LOCO_YUY2=1, LOCO_UYVY=2, LOCO_RGB=3, LOCO_RGBA=4, LOCO_YV12=5}; +enum LOCO_MODE { + LOCO_UNKN = 0, + LOCO_CYUY2 = -1, + LOCO_CRGB = -2, + LOCO_CRGBA = -3, + LOCO_CYV12 = -4, + LOCO_YUY2 = 1, + LOCO_UYVY = 2, + LOCO_RGB = 3, + LOCO_RGBA = 4, + LOCO_YV12 = 5, +}; -typedef struct LOCOContext{ +typedef struct LOCOContext { AVCodecContext *avctx; AVFrame pic; int lossy; int mode; } LOCOContext; -typedef struct RICEContext{ +typedef struct RICEContext { GetBitContext gb; int save, run, run2; /* internal rice decoder state */ int sum, count; /* sum and count for getting rice parameter */ int lossy; -}RICEContext; +} RICEContext; static int loco_get_rice_param(RICEContext *r) { int cnt = 0; int val = r->count; - while(r->sum > val && cnt < 9) { + while (r->sum > val && cnt < 9) { val <<= 1; cnt++; } @@ -65,8 +75,8 @@ static inline void loco_update_rice_param(RICEContext *r, int val) r->sum += val; r->count++; - if(r->count == 16) { - r->sum >>= 1; + if (r->count == 16) { + r->sum >>= 1; r->count >>= 1; } } @@ -80,19 +90,18 @@ static inline int loco_get_rice(RICEContext *r) return 0; } v = get_ur_golomb_jpegls(&r->gb, loco_get_rice_param(r), INT_MAX, 0); - loco_update_rice_param(r, (v+1)>>1); + loco_update_rice_param(r, (v + 1) >> 1); if (!v) { if (r->save >= 0) { r->run = get_ur_golomb_jpegls(&r->gb, 2, INT_MAX, 0); - if(r->run > 1) + if (r->run > 1) r->save += r->run + 1; else r->save -= 3; - } - else + } else r->run2++; } else { - v = ((v>>1) + r->lossy) ^ -(v&1); + v = ((v >> 1) + r->lossy) ^ -(v & 1); if (r->run2 > 0) { if (r->run2 > 2) r->save += r->run2; @@ -128,16 +137,16 @@ static int loco_decode_plane(LOCOContext *l, uint8_t *data, int width, int heigh return -1; init_get_bits(&rc.gb, buf, buf_size*8); - rc.save = 0; - rc.run = 0; - rc.run2 = 0; + rc.save = 0; + rc.run = 0; + rc.run2 = 0; rc.lossy = l->lossy; - rc.sum = 8; + rc.sum = 8; rc.count = 1; /* restore top left pixel */ - val = loco_get_rice(&rc); + val = loco_get_rice(&rc); data[0] = 128 + val; /* restore top line */ for (i = 1; i < width; i++) { @@ -164,19 +173,19 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; LOCOContext * const l = avctx->priv_data; - AVFrame * const p = &l->pic; - int decoded; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + AVFrame * const p = &l->pic; + int decoded, ret; - if(p->data[0]) + if (p->data[0]) avctx->release_buffer(avctx, p); p->reference = 0; - if(ff_get_buffer(avctx, p) < 0){ + if ((ret = ff_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } p->key_frame = 1; @@ -229,12 +238,18 @@ static int decode_frame(AVCodecContext *avctx, decoded = loco_decode_plane(l, p->data[0] + p->linesize[0]*(avctx->height-1) + 3, avctx->width, avctx->height, -p->linesize[0], buf, buf_size, 4); break; + default: + av_assert0(0); } + if (decoded < 0 || decoded > buf_size) + goto buf_too_small; + buf_size -= decoded; + *got_frame = 1; *(AVFrame*)data = l->pic; - return buf_size < 0 ? -1 : avpkt->size - buf_size; + return avpkt->size - buf_size; buf_too_small: av_log(avctx, AV_LOG_ERROR, "Input data too small.\n"); return AVERROR(EINVAL); @@ -249,10 +264,10 @@ static av_cold int decode_init(AVCodecContext *avctx) if (avctx->extradata_size < 12) { av_log(avctx, AV_LOG_ERROR, "Extradata size must be >= 12 instead of %i\n", avctx->extradata_size); - return -1; + return AVERROR_INVALIDDATA; } version = AV_RL32(avctx->extradata); - switch(version) { + switch (version) { case 1: l->lossy = 0; break; @@ -265,24 +280,29 @@ static av_cold int decode_init(AVCodecContext *avctx) } l->mode = AV_RL32(avctx->extradata + 4); - switch(l->mode) { - case LOCO_CYUY2: case LOCO_YUY2: case LOCO_UYVY: + switch (l->mode) { + case LOCO_CYUY2: + case LOCO_YUY2: + case LOCO_UYVY: avctx->pix_fmt = AV_PIX_FMT_YUV422P; break; - case LOCO_CRGB: case LOCO_RGB: + case LOCO_CRGB: + case LOCO_RGB: avctx->pix_fmt = AV_PIX_FMT_BGR24; break; - case LOCO_CYV12: case LOCO_YV12: + case LOCO_CYV12: + case LOCO_YV12: avctx->pix_fmt = AV_PIX_FMT_YUV420P; break; - case LOCO_CRGBA: case LOCO_RGBA: - avctx->pix_fmt = AV_PIX_FMT_RGB32; + case LOCO_CRGBA: + case LOCO_RGBA: + avctx->pix_fmt = AV_PIX_FMT_BGRA; break; default: av_log(avctx, AV_LOG_INFO, "Unknown colorspace, index = %i\n", l->mode); - return -1; + return AVERROR_INVALIDDATA; } - if(avctx->debug & FF_DEBUG_PICT_INFO) + if (avctx->debug & FF_DEBUG_PICT_INFO) av_log(avctx, AV_LOG_INFO, "lossy:%i, version:%i, mode: %i\n", l->lossy, version, l->mode); avcodec_get_frame_defaults(&l->pic); @@ -290,7 +310,8 @@ static av_cold int decode_init(AVCodecContext *avctx) return 0; } -static av_cold int decode_end(AVCodecContext *avctx){ +static av_cold int decode_end(AVCodecContext *avctx) +{ LOCOContext * const l = avctx->priv_data; AVFrame *pic = &l->pic; diff --git a/mythtv/external/FFmpeg/libavcodec/lpc.c b/mythtv/external/FFmpeg/libavcodec/lpc.c index 019689a2476..414913527b9 100644 --- a/mythtv/external/FFmpeg/libavcodec/lpc.c +++ b/mythtv/external/FFmpeg/libavcodec/lpc.c @@ -207,7 +207,7 @@ int ff_lpc_calc_coefs(LPCContext *s, lpc_passes = 2; for(pass=0; pass>pass) + fabs(eval - var[0]); inv = 1/eval; rinv = sqrt(inv); @@ -226,9 +226,9 @@ int ff_lpc_calc_coefs(LPCContext *s, }else weight++; - av_update_lls(&m[pass&1], var, 1.0); + avpriv_update_lls(&m[pass&1], var, 1.0); } - av_solve_lls(&m[pass&1], 0.001, 0); + avpriv_solve_lls(&m[pass&1], 0.001, 0); } for(i=0; i #include "libavutil/avassert.h" -#include "dsputil.h" #define ORDER_METHOD_EST 0 #define ORDER_METHOD_2LEVEL 1 diff --git a/mythtv/external/FFmpeg/libavcodec/mace.c b/mythtv/external/FFmpeg/libavcodec/mace.c index d2a04114f43..e78c49fbf50 100644 --- a/mythtv/external/FFmpeg/libavcodec/mace.c +++ b/mythtv/external/FFmpeg/libavcodec/mace.c @@ -155,7 +155,6 @@ typedef struct ChannelData { } ChannelData; typedef struct MACEContext { - AVFrame frame; ChannelData chd[2]; } MACEContext; @@ -227,21 +226,17 @@ static void chomp6(ChannelData *chd, int16_t *output, uint8_t val, int tab_idx) static av_cold int mace_decode_init(AVCodecContext * avctx) { - MACEContext *ctx = avctx->priv_data; - if (avctx->channels > 2 || avctx->channels <= 0) return -1; avctx->sample_fmt = AV_SAMPLE_FMT_S16P; - avcodec_get_frame_defaults(&ctx->frame); - avctx->coded_frame = &ctx->frame; - return 0; } static int mace_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int16_t **samples; @@ -250,12 +245,12 @@ static int mace_decode_frame(AVCodecContext *avctx, void *data, int is_mace3 = (avctx->codec_id == AV_CODEC_ID_MACE3); /* get output buffer */ - ctx->frame.nb_samples = 3 * (buf_size << (1 - is_mace3)) / avctx->channels; - if ((ret = ff_get_buffer(avctx, &ctx->frame)) < 0) { + frame->nb_samples = 3 * (buf_size << (1 - is_mace3)) / avctx->channels; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (int16_t **)ctx->frame.extended_data; + samples = (int16_t **)frame->extended_data; for(i = 0; i < avctx->channels; i++) { int16_t *output = samples[i]; @@ -279,8 +274,7 @@ static int mace_decode_frame(AVCodecContext *avctx, void *data, } } - *got_frame_ptr = 1; - *(AVFrame *)data = ctx->frame; + *got_frame_ptr = 1; return buf_size; } diff --git a/mythtv/external/FFmpeg/libavcodec/mathtables.c b/mythtv/external/FFmpeg/libavcodec/mathtables.c index 037b135a1b1..126b05f4c5d 100644 --- a/mythtv/external/FFmpeg/libavcodec/mathtables.c +++ b/mythtv/external/FFmpeg/libavcodec/mathtables.c @@ -87,3 +87,36 @@ const uint8_t ff_reverse[256] = { 0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7, 0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF, }; + +#define times4(x) x, x, x, x + +const uint8_t ff_cropTbl[256 + 2 * 1024] = { +times4(times4(times4(times4(times4(0x00))))), +0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F, +0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, +0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F, +0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F, +0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F, +0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F, +0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F, +0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F, +0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, +0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, +0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, +0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, +0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, +0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, +0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, +0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF, +times4(times4(times4(times4(times4(0xFF)))))}; + +const uint8_t ff_zigzag_direct[64] = { + 0, 1, 8, 16, 9, 2, 3, 10, + 17, 24, 32, 25, 18, 11, 4, 5, + 12, 19, 26, 33, 40, 48, 41, 34, + 27, 20, 13, 6, 7, 14, 21, 28, + 35, 42, 49, 56, 57, 50, 43, 36, + 29, 22, 15, 23, 30, 37, 44, 51, + 58, 59, 52, 45, 38, 31, 39, 46, + 53, 60, 61, 54, 47, 55, 62, 63 +}; diff --git a/mythtv/external/FFmpeg/libavcodec/mdec.c b/mythtv/external/FFmpeg/libavcodec/mdec.c index 364e9995138..7e59c3437c0 100644 --- a/mythtv/external/FFmpeg/libavcodec/mdec.c +++ b/mythtv/external/FFmpeg/libavcodec/mdec.c @@ -28,12 +28,11 @@ */ #include "avcodec.h" -#include "dsputil.h" #include "mpegvideo.h" #include "mpeg12.h" #include "thread.h" -typedef struct MDECContext{ +typedef struct MDECContext { AVCodecContext *avctx; DSPContext dsp; AVFrame picture; @@ -45,48 +44,48 @@ typedef struct MDECContext{ int mb_width; int mb_height; int mb_x, mb_y; - DECLARE_ALIGNED(16, DCTELEM, block)[6][64]; + DECLARE_ALIGNED(16, int16_t, block)[6][64]; uint8_t *bitstream_buffer; unsigned int bitstream_buffer_size; int block_last_index[6]; } MDECContext; //very similar to MPEG-1 -static inline int mdec_decode_block_intra(MDECContext *a, DCTELEM *block, int n) +static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n) { int level, diff, i, j, run; int component; RLTable *rl = &ff_rl_mpeg1; - uint8_t * const scantable= a->scantable.permutated; - const uint16_t *quant_matrix= ff_mpeg1_default_intra_matrix; - const int qscale= a->qscale; + uint8_t * const scantable = a->scantable.permutated; + const uint16_t *quant_matrix = ff_mpeg1_default_intra_matrix; + const int qscale = a->qscale; /* DC coefficient */ - if(a->version==2){ - block[0]= 2*get_sbits(&a->gb, 10) + 1024; - }else{ + if (a->version == 2) { + block[0] = 2 * get_sbits(&a->gb, 10) + 1024; + } else { component = (n <= 3 ? 0 : n - 4 + 1); diff = decode_dc(&a->gb, component); if (diff >= 0xffff) - return -1; - a->last_dc[component]+= diff; - block[0] = a->last_dc[component]<<3; + return AVERROR_INVALIDDATA; + a->last_dc[component] += diff; + block[0] = a->last_dc[component] << 3; } i = 0; { OPEN_READER(re, &a->gb); /* now quantify & encode AC coefficients */ - for(;;) { + for (;;) { UPDATE_CACHE(re, &a->gb); GET_RL_VLC(level, run, re, &a->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); - if(level == 127){ + if (level == 127) { break; - } else if(level != 0) { - i += run; - j = scantable[i]; - level= (level*qscale*quant_matrix[j])>>3; + } else if (level != 0) { + i += run; + j = scantable[i]; + level = (level * qscale * quant_matrix[j]) >> 3; level = (level ^ SHOW_SBITS(re, &a->gb, 1)) - SHOW_SBITS(re, &a->gb, 1); LAST_SKIP_BITS(re, &a->gb, 1); } else { @@ -94,21 +93,21 @@ static inline int mdec_decode_block_intra(MDECContext *a, DCTELEM *block, int n) run = SHOW_UBITS(re, &a->gb, 6)+1; LAST_SKIP_BITS(re, &a->gb, 6); UPDATE_CACHE(re, &a->gb); level = SHOW_SBITS(re, &a->gb, 10); SKIP_BITS(re, &a->gb, 10); - i += run; - j = scantable[i]; - if(level<0){ - level= -level; - level= (level*qscale*quant_matrix[j])>>3; - level= (level-1)|1; - level= -level; - }else{ - level= (level*qscale*quant_matrix[j])>>3; - level= (level-1)|1; + i += run; + j = scantable[i]; + if (level < 0) { + level = -level; + level = (level * qscale * quant_matrix[j]) >> 3; + level = (level - 1) | 1; + level = -level; + } else { + level = (level * qscale * quant_matrix[j]) >> 3; + level = (level - 1) | 1; } } - if (i > 63){ + if (i > 63) { av_log(a->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", a->mb_x, a->mb_y); - return -1; + return AVERROR_INVALIDDATA; } block[j] = level; @@ -119,34 +118,38 @@ static inline int mdec_decode_block_intra(MDECContext *a, DCTELEM *block, int n) return 0; } -static inline int decode_mb(MDECContext *a, DCTELEM block[6][64]){ - int i; - const int block_index[6]= {5,4,0,1,2,3}; +static inline int decode_mb(MDECContext *a, int16_t block[6][64]) +{ + int i, ret; + const int block_index[6] = { 5, 4, 0, 1, 2, 3 }; a->dsp.clear_blocks(block[0]); - for(i=0; i<6; i++){ - if( mdec_decode_block_intra(a, block[ block_index[i] ], block_index[i]) < 0 || - get_bits_left(&a->gb) < 0) - return -1; + for (i = 0; i < 6; i++) { + if ((ret = mdec_decode_block_intra(a, block[block_index[i]], + block_index[i])) < 0) + return ret; + if (get_bits_left(&a->gb) < 0) + return AVERROR_INVALIDDATA; } return 0; } -static inline void idct_put(MDECContext *a, int mb_x, int mb_y){ - DCTELEM (*block)[64]= a->block; - int linesize= a->picture.linesize[0]; +static inline void idct_put(MDECContext *a, int mb_x, int mb_y) +{ + int16_t (*block)[64] = a->block; + int linesize = a->picture.linesize[0]; - uint8_t *dest_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16; - uint8_t *dest_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8; - uint8_t *dest_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8; + uint8_t *dest_y = a->picture.data[0] + (mb_y * 16 * linesize ) + mb_x * 16; + uint8_t *dest_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8; + uint8_t *dest_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8; - a->dsp.idct_put(dest_y , linesize, block[0]); - a->dsp.idct_put(dest_y + 8, linesize, block[1]); - a->dsp.idct_put(dest_y + 8*linesize , linesize, block[2]); - a->dsp.idct_put(dest_y + 8*linesize + 8, linesize, block[3]); + a->dsp.idct_put(dest_y, linesize, block[0]); + a->dsp.idct_put(dest_y + 8, linesize, block[1]); + a->dsp.idct_put(dest_y + 8 * linesize, linesize, block[2]); + a->dsp.idct_put(dest_y + 8 * linesize + 8, linesize, block[3]); - if(!(a->avctx->flags&CODEC_FLAG_GRAY)){ + if (!(a->avctx->flags & CODEC_FLAG_GRAY)) { a->dsp.idct_put(dest_cb, a->picture.linesize[1], block[4]); a->dsp.idct_put(dest_cr, a->picture.linesize[2], block[5]); } @@ -156,112 +159,106 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; MDECContext * const a = avctx->priv_data; - AVFrame *picture = data; - AVFrame * const p= &a->picture; - int i; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + AVFrame *picture = data; + AVFrame * const p = &a->picture; + int i, ret; - if(p->data[0]) + if (p->data[0]) ff_thread_release_buffer(avctx, p); - p->reference= 0; - if(ff_thread_get_buffer(avctx, p) < 0){ + p->reference = 0; + if ((ret = ff_thread_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } - p->pict_type= AV_PICTURE_TYPE_I; - p->key_frame= 1; + p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; av_fast_malloc(&a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!a->bitstream_buffer) return AVERROR(ENOMEM); - for(i=0; ibitstream_buffer[i] = buf[i+1]; - a->bitstream_buffer[i+1]= buf[i ]; + for (i = 0; i < buf_size; i += 2) { + a->bitstream_buffer[i] = buf[i + 1]; + a->bitstream_buffer[i + 1] = buf[i]; } - init_get_bits(&a->gb, a->bitstream_buffer, buf_size*8); + init_get_bits(&a->gb, a->bitstream_buffer, buf_size * 8); /* skip over 4 preamble bytes in stream (typically 0xXX 0xXX 0x00 0x38) */ skip_bits(&a->gb, 32); - a->qscale= get_bits(&a->gb, 16); - a->version= get_bits(&a->gb, 16); + a->qscale = get_bits(&a->gb, 16); + a->version = get_bits(&a->gb, 16); - a->last_dc[0]= - a->last_dc[1]= - a->last_dc[2]= 128; + a->last_dc[0] = a->last_dc[1] = a->last_dc[2] = 128; - for(a->mb_x=0; a->mb_xmb_width; a->mb_x++){ - for(a->mb_y=0; a->mb_ymb_height; a->mb_y++){ - if( decode_mb(a, a->block) <0) - return -1; + for (a->mb_x = 0; a->mb_x < a->mb_width; a->mb_x++) { + for (a->mb_y = 0; a->mb_y < a->mb_height; a->mb_y++) { + if ((ret = decode_mb(a, a->block)) < 0) + return ret; idct_put(a, a->mb_x, a->mb_y); } } - p->quality= a->qscale * FF_QP2LAMBDA; + p->quality = a->qscale * FF_QP2LAMBDA; memset(p->qscale_table, a->qscale, a->mb_width); *picture = a->picture; *got_frame = 1; - return (get_bits_count(&a->gb)+31)/32*4; + return (get_bits_count(&a->gb) + 31) / 32 * 4; } -static av_cold void mdec_common_init(AVCodecContext *avctx){ +static av_cold int decode_init(AVCodecContext *avctx) +{ MDECContext * const a = avctx->priv_data; + AVFrame *p = &a->picture; - ff_dsputil_init(&a->dsp, avctx); - - a->mb_width = (avctx->coded_width + 15) / 16; - a->mb_height = (avctx->coded_height + 15) / 16; + a->mb_width = (avctx->coded_width + 15) / 16; + a->mb_height = (avctx->coded_height + 15) / 16; avcodec_get_frame_defaults(&a->picture); - avctx->coded_frame= &a->picture; - a->avctx= avctx; -} + avctx->coded_frame = &a->picture; + a->avctx = avctx; -static av_cold int decode_init(AVCodecContext *avctx){ - MDECContext * const a = avctx->priv_data; - AVFrame *p= &a->picture; - - mdec_common_init(avctx); + ff_dsputil_init(&a->dsp, avctx); ff_mpeg12_init_vlcs(); ff_init_scantable(a->dsp.idct_permutation, &a->scantable, ff_zigzag_direct); - if( avctx->idct_algo == FF_IDCT_AUTO ) + if (avctx->idct_algo == FF_IDCT_AUTO) avctx->idct_algo = FF_IDCT_SIMPLE; - p->qstride= 0; - p->qscale_table= av_mallocz(a->mb_width); - avctx->pix_fmt= AV_PIX_FMT_YUVJ420P; + p->qstride = 0; + p->qscale_table = av_mallocz(a->mb_width); + avctx->pix_fmt = AV_PIX_FMT_YUVJ420P; return 0; } -static av_cold int decode_init_thread_copy(AVCodecContext *avctx){ +static av_cold int decode_init_thread_copy(AVCodecContext *avctx) +{ MDECContext * const a = avctx->priv_data; - AVFrame *p = &a->picture; + AVFrame *p = &a->picture; - avctx->coded_frame= p; - a->avctx= avctx; + avctx->coded_frame = p; + a->avctx = avctx; p->qscale_table= av_mallocz(a->mb_width); return 0; } - -static av_cold int decode_end(AVCodecContext *avctx){ +static av_cold int decode_end(AVCodecContext *avctx) +{ MDECContext * const a = avctx->priv_data; - if(a->picture.data[0]) + if (a->picture.data[0]) avctx->release_buffer(avctx, &a->picture); av_freep(&a->bitstream_buffer); av_freep(&a->picture.qscale_table); - a->bitstream_buffer_size=0; + a->bitstream_buffer_size = 0; return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/mimic.c b/mythtv/external/FFmpeg/libavcodec/mimic.c index 880bbc0ddd2..54d27e8af38 100644 --- a/mythtv/external/FFmpeg/libavcodec/mimic.c +++ b/mythtv/external/FFmpeg/libavcodec/mimic.c @@ -47,7 +47,7 @@ typedef struct { AVFrame buf_ptrs [16]; AVPicture flipped_ptrs[16]; - DECLARE_ALIGNED(16, DCTELEM, dct_block)[64]; + DECLARE_ALIGNED(16, int16_t, dct_block)[64]; GetBitContext gb; ScanTable scantable; @@ -112,14 +112,15 @@ static const uint8_t col_zag[64] = { static av_cold int mimic_decode_init(AVCodecContext *avctx) { MimicContext *ctx = avctx->priv_data; + int ret; ctx->prev_index = 0; - ctx->cur_index = 15; + ctx->cur_index = 15; - if(init_vlc(&ctx->vlc, 11, FF_ARRAY_ELEMS(huffbits), - huffbits, 1, 1, huffcodes, 4, 4, 0)) { + if ((ret = init_vlc(&ctx->vlc, 11, FF_ARRAY_ELEMS(huffbits), + huffbits, 1, 1, huffcodes, 4, 4, 0)) < 0) { av_log(avctx, AV_LOG_ERROR, "error initializing vlc table\n"); - return -1; + return ret; } ff_dsputil_init(&ctx->dsp, avctx); ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable, col_zag); @@ -131,7 +132,8 @@ static int mimic_decode_update_thread_context(AVCodecContext *avctx, const AVCod { MimicContext *dst = avctx->priv_data, *src = avctx_from->priv_data; - if (avctx == avctx_from) return 0; + if (avctx == avctx_from) + return 0; dst->cur_index = src->next_cur_index; dst->prev_index = src->next_prev_index; @@ -183,30 +185,30 @@ static const int8_t vlcdec_lookup[9][64] = { static int vlc_decode_block(MimicContext *ctx, int num_coeffs, int qscale) { - DCTELEM *block = ctx->dct_block; + int16_t *block = ctx->dct_block; unsigned int pos; ctx->dsp.clear_block(block); block[0] = get_bits(&ctx->gb, 8) << 3; - for(pos = 1; pos < num_coeffs; pos++) { + for (pos = 1; pos < num_coeffs; pos++) { uint32_t vlc, num_bits; int value; int coeff; vlc = get_vlc2(&ctx->gb, ctx->vlc.table, ctx->vlc.bits, 3); - if(!vlc) /* end-of-block code */ - return 1; - if(vlc == -1) + if (!vlc) /* end-of-block code */ return 0; + if (vlc == -1) + return AVERROR_INVALIDDATA; /* pos_add and num_bits are coded in the vlc code */ - pos += vlc&15; // pos_add - num_bits = vlc>>4; // num_bits + pos += vlc & 15; // pos_add + num_bits = vlc >> 4; // num_bits - if(pos >= 64) - return 0; + if (pos >= 64) + return AVERROR_INVALIDDATA; value = get_bits(&ctx->gb, num_bits); @@ -214,7 +216,7 @@ static int vlc_decode_block(MimicContext *ctx, int num_coeffs, int qscale) * a factor of 4 was added to the input */ coeff = vlcdec_lookup[num_bits][value]; - if(pos<3) + if (pos < 3) coeff <<= 4; else /* TODO Use >> 10 instead of / 1001 */ coeff = (coeff * qscale) / 1001; @@ -222,47 +224,50 @@ static int vlc_decode_block(MimicContext *ctx, int num_coeffs, int qscale) block[ctx->scantable.permutated[pos]] = coeff; } - return 1; + return 0; } static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe) { - int y, x, plane, cur_row = 0; + int ret, y, x, plane, cur_row = 0; - for(plane = 0; plane < 3; plane++) { + for (plane = 0; plane < 3; plane++) { const int is_chroma = !!plane; - const int qscale = av_clip(10000-quality,is_chroma?1000:2000,10000)<<2; - const int stride = ctx->flipped_ptrs[ctx->cur_index].linesize[plane]; - const uint8_t *src = ctx->flipped_ptrs[ctx->prev_index].data[plane]; - uint8_t *dst = ctx->flipped_ptrs[ctx->cur_index ].data[plane]; - - for(y = 0; y < ctx->num_vblocks[plane]; y++) { - for(x = 0; x < ctx->num_hblocks[plane]; x++) { - + const int qscale = av_clip(10000 - quality, is_chroma ? 1000 : 2000, + 10000) << 2; + const int stride = ctx->flipped_ptrs[ctx->cur_index ].linesize[plane]; + const uint8_t *src = ctx->flipped_ptrs[ctx->prev_index].data[plane]; + uint8_t *dst = ctx->flipped_ptrs[ctx->cur_index ].data[plane]; + + for (y = 0; y < ctx->num_vblocks[plane]; y++) { + for (x = 0; x < ctx->num_hblocks[plane]; x++) { /* Check for a change condition in the current block. * - iframes always change. * - Luma plane changes on get_bits1 == 0 * - Chroma planes change on get_bits1 == 1 */ - if(is_iframe || get_bits1(&ctx->gb) == is_chroma) { - + if (is_iframe || get_bits1(&ctx->gb) == is_chroma) { /* Luma planes may use a backreference from the 15 last * frames preceding the previous. (get_bits1 == 1) * Chroma planes don't use backreferences. */ - if(is_chroma || is_iframe || !get_bits1(&ctx->gb)) { - - if(!vlc_decode_block(ctx, num_coeffs, qscale)) - return 0; + if (is_chroma || is_iframe || !get_bits1(&ctx->gb)) { + if ((ret = vlc_decode_block(ctx, num_coeffs, + qscale)) < 0) { + av_log(ctx->avctx, AV_LOG_ERROR, "Error decoding " + "block.\n"); + return ret; + } ctx->dsp.idct_put(dst, stride, ctx->dct_block); } else { unsigned int backref = get_bits(&ctx->gb, 4); - int index = (ctx->cur_index+backref)&15; - uint8_t *p = ctx->flipped_ptrs[index].data[0]; + int index = (ctx->cur_index + backref) & 15; + uint8_t *p = ctx->flipped_ptrs[index].data[0]; if (index != ctx->cur_index && p) { - ff_thread_await_progress(&ctx->buf_ptrs[index], cur_row, 0); + ff_thread_await_progress(&ctx->buf_ptrs[index], + cur_row, 0); p += src - - ctx->flipped_ptrs[ctx->prev_index].data[plane]; + ctx->flipped_ptrs[ctx->prev_index].data[plane]; ctx->dsp.put_pixels_tab[1][0](dst, p, stride, 8); } else { av_log(ctx->avctx, AV_LOG_ERROR, @@ -270,33 +275,35 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs, } } } else { - ff_thread_await_progress(&ctx->buf_ptrs[ctx->prev_index], cur_row, 0); + ff_thread_await_progress(&ctx->buf_ptrs[ctx->prev_index], + cur_row, 0); ctx->dsp.put_pixels_tab[1][0](dst, src, stride, 8); } src += 8; dst += 8; } - src += (stride - ctx->num_hblocks[plane])<<3; - dst += (stride - ctx->num_hblocks[plane])<<3; + src += (stride - ctx->num_hblocks[plane]) << 3; + dst += (stride - ctx->num_hblocks[plane]) << 3; - ff_thread_report_progress(&ctx->buf_ptrs[ctx->cur_index], cur_row++, 0); + ff_thread_report_progress(&ctx->buf_ptrs[ctx->cur_index], + cur_row++, 0); } } - return 1; + return 0; } /** * Flip the buffer upside-down and put it in the YVU order to match the * way Mimic encodes frames. */ -static void prepare_avpic(MimicContext *ctx, AVPicture *dst, AVPicture *src) +static void prepare_avpic(MimicContext *ctx, AVPicture *dst, AVFrame *src) { int i; - dst->data[0] = src->data[0]+( ctx->avctx->height -1)*src->linesize[0]; - dst->data[1] = src->data[2]+((ctx->avctx->height>>1)-1)*src->linesize[2]; - dst->data[2] = src->data[1]+((ctx->avctx->height>>1)-1)*src->linesize[1]; - for(i = 0; i < 3; i++) + dst->data[0] = src->data[0] + ( ctx->avctx->height - 1) * src->linesize[0]; + dst->data[1] = src->data[2] + ((ctx->avctx->height >> 1) - 1) * src->linesize[2]; + dst->data[2] = src->data[1] + ((ctx->avctx->height >> 1) - 1) * src->linesize[1]; + for (i = 0; i < 3; i++) dst->linesize[i] = -src->linesize[i]; } @@ -304,18 +311,18 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; - MimicContext *ctx = avctx->priv_data; + int buf_size = avpkt->size; + int swap_buf_size = buf_size - MIMIC_HEADER_SIZE; + MimicContext *ctx = avctx->priv_data; GetByteContext gb; int is_pframe; int width, height; int quality, num_coeffs; - int swap_buf_size = buf_size - MIMIC_HEADER_SIZE; int res; if (buf_size <= MIMIC_HEADER_SIZE) { av_log(avctx, AV_LOG_ERROR, "insufficient data\n"); - return -1; + return AVERROR_INVALIDDATA; } bytestream2_init(&gb, buf, MIMIC_HEADER_SIZE); @@ -328,63 +335,64 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data, num_coeffs = bytestream2_get_byteu(&gb); bytestream2_skip(&gb, 3); /* some constant */ - if(!ctx->avctx) { + if (!ctx->avctx) { int i; - if(!(width == 160 && height == 120) && - !(width == 320 && height == 240)) { + if (!(width == 160 && height == 120) && + !(width == 320 && height == 240)) { av_log(avctx, AV_LOG_ERROR, "invalid width/height!\n"); - return -1; + return AVERROR_INVALIDDATA; } ctx->avctx = avctx; avctx->width = width; avctx->height = height; avctx->pix_fmt = AV_PIX_FMT_YUV420P; - for(i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) { ctx->num_vblocks[i] = -((-height) >> (3 + !!i)); - ctx->num_hblocks[i] = width >> (3 + !!i) ; + ctx->num_hblocks[i] = width >> (3 + !!i); } - } else if(width != ctx->avctx->width || height != ctx->avctx->height) { - av_log(avctx, AV_LOG_ERROR, "resolution changing is not supported\n"); - return -1; + } else if (width != ctx->avctx->width || height != ctx->avctx->height) { + av_log_missing_feature(avctx, "resolution changing", 1); + return AVERROR_PATCHWELCOME; } - if(is_pframe && !ctx->buf_ptrs[ctx->prev_index].data[0]) { + if (is_pframe && !ctx->buf_ptrs[ctx->prev_index].data[0]) { av_log(avctx, AV_LOG_ERROR, "decoding must start with keyframe\n"); - return -1; + return AVERROR_INVALIDDATA; } ctx->buf_ptrs[ctx->cur_index].reference = 3; - ctx->buf_ptrs[ctx->cur_index].pict_type = is_pframe ? AV_PICTURE_TYPE_P:AV_PICTURE_TYPE_I; - if(ff_thread_get_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index])) { + ctx->buf_ptrs[ctx->cur_index].pict_type = is_pframe ? AV_PICTURE_TYPE_P : + AV_PICTURE_TYPE_I; + if ((res = ff_thread_get_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index])) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return res; } ctx->next_prev_index = ctx->cur_index; ctx->next_cur_index = (ctx->cur_index - 1) & 15; prepare_avpic(ctx, &ctx->flipped_ptrs[ctx->cur_index], - (AVPicture*) &ctx->buf_ptrs[ctx->cur_index]); + &ctx->buf_ptrs[ctx->cur_index]); ff_thread_finish_setup(avctx); av_fast_padded_malloc(&ctx->swap_buf, &ctx->swap_buf_size, swap_buf_size); - if(!ctx->swap_buf) + if (!ctx->swap_buf) return AVERROR(ENOMEM); ctx->dsp.bswap_buf(ctx->swap_buf, - (const uint32_t*) (buf + MIMIC_HEADER_SIZE), - swap_buf_size>>2); + (const uint32_t*) (buf + MIMIC_HEADER_SIZE), + swap_buf_size >> 2); init_get_bits(&ctx->gb, ctx->swap_buf, swap_buf_size << 3); res = decode(ctx, quality, num_coeffs, !is_pframe); ff_thread_report_progress(&ctx->buf_ptrs[ctx->cur_index], INT_MAX, 0); - if (!res) { + if (res < 0) { if (!(avctx->active_thread_type & FF_THREAD_FRAME)) { ff_thread_release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]); - return -1; + return res; } } @@ -395,7 +403,7 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data, ctx->cur_index = ctx->next_cur_index; /* Only release frames that aren't used for backreferences anymore */ - if(ctx->buf_ptrs[ctx->cur_index].data[0]) + if (ctx->buf_ptrs[ctx->cur_index].data[0]) ff_thread_release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]); return buf_size; @@ -411,8 +419,8 @@ static av_cold int mimic_decode_end(AVCodecContext *avctx) if (avctx->internal->is_copy) return 0; - for(i = 0; i < 16; i++) - if(ctx->buf_ptrs[i].data[0]) + for (i = 0; i < 16; i++) + if (ctx->buf_ptrs[i].data[0]) ff_thread_release_buffer(avctx, &ctx->buf_ptrs[i]); ff_free_vlc(&ctx->vlc); diff --git a/mythtv/external/FFmpeg/libavcodec/mips/Makefile b/mythtv/external/FFmpeg/libavcodec/mips/Makefile index feeec99a4bd..8223f11418e 100644 --- a/mythtv/external/FFmpeg/libavcodec/mips/Makefile +++ b/mythtv/external/FFmpeg/libavcodec/mips/Makefile @@ -11,6 +11,9 @@ MIPSFPU-OBJS-$(CONFIG_MPEGAUDIODSP) += mips/mpegaudiodsp_mips_float.o MIPSDSPR1-OBJS-$(CONFIG_MPEGAUDIODSP) += mips/mpegaudiodsp_mips_fixed.o OBJS-$(CONFIG_FFT) += mips/fft_init_table.o MIPSFPU-OBJS-$(CONFIG_FFT) += mips/fft_mips.o -MIPSFPU-OBJS += mips/dsputil_mips.o \ - mips/fmtconvert_mips.o +MIPSFPU-OBJS += mips/fmtconvert_mips.o OBJS-$(CONFIG_AC3DSP) += mips/ac3dsp_mips.o +OBJS-$(CONFIG_AAC_DECODER) += mips/aacdec_mips.o \ + mips/aacsbr_mips.o \ + mips/sbrdsp_mips.o \ + mips/aacpsdsp_mips.o diff --git a/mythtv/external/FFmpeg/libavcodec/mips/aacdec_mips.c b/mythtv/external/FFmpeg/libavcodec/mips/aacdec_mips.c new file mode 100644 index 00000000000..e4033668da4 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/mips/aacdec_mips.c @@ -0,0 +1,831 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Authors: Darko Laus (darko@mips.com) + * Djordje Pesut (djordje@mips.com) + * Mirjana Vulin (mvulin@mips.com) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Reference: libavcodec/aacdec.c + */ + +#include "libavcodec/aac.h" +#include "aacdec_mips.h" +#include "libavcodec/aactab.h" +#include "libavcodec/sinewin.h" + +#if HAVE_INLINE_ASM +static av_always_inline int lcg_random(unsigned previous_val) +{ + union { unsigned u; int s; } v = { previous_val * 1664525u + 1013904223 }; + return v.s; +} + +static void imdct_and_windowing_mips(AACContext *ac, SingleChannelElement *sce) +{ + IndividualChannelStream *ics = &sce->ics; + float *in = sce->coeffs; + float *out = sce->ret; + float *saved = sce->saved; + const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; + const float *lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024; + const float *swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; + float *buf = ac->buf_mdct; + int i; + + if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { + for (i = 0; i < 1024; i += 128) + ac->mdct_small.imdct_half(&ac->mdct_small, buf + i, in + i); + } else + ac->mdct.imdct_half(&ac->mdct, buf, in); + + /* window overlapping + * NOTE: To simplify the overlapping code, all 'meaningless' short to long + * and long to short transitions are considered to be short to short + * transitions. This leaves just two cases (long to long and short to short) + * with a little special sauce for EIGHT_SHORT_SEQUENCE. + */ + if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) && + (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) { + ac->fdsp.vector_fmul_window( out, saved, buf, lwindow_prev, 512); + } else { + { + float *buf1 = saved; + float *buf2 = out; + int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7; + int loop_end; + + /* loop unrolled 8 times */ + __asm__ volatile ( + ".set push \n\t" + ".set noreorder \n\t" + "addiu %[loop_end], %[src], 1792 \n\t" + "1: \n\t" + "lw %[temp0], 0(%[src]) \n\t" + "lw %[temp1], 4(%[src]) \n\t" + "lw %[temp2], 8(%[src]) \n\t" + "lw %[temp3], 12(%[src]) \n\t" + "lw %[temp4], 16(%[src]) \n\t" + "lw %[temp5], 20(%[src]) \n\t" + "lw %[temp6], 24(%[src]) \n\t" + "lw %[temp7], 28(%[src]) \n\t" + "addiu %[src], %[src], 32 \n\t" + "sw %[temp0], 0(%[dst]) \n\t" + "sw %[temp1], 4(%[dst]) \n\t" + "sw %[temp2], 8(%[dst]) \n\t" + "sw %[temp3], 12(%[dst]) \n\t" + "sw %[temp4], 16(%[dst]) \n\t" + "sw %[temp5], 20(%[dst]) \n\t" + "sw %[temp6], 24(%[dst]) \n\t" + "sw %[temp7], 28(%[dst]) \n\t" + "bne %[src], %[loop_end], 1b \n\t" + " addiu %[dst], %[dst], 32 \n\t" + ".set pop \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [loop_end]"=&r"(loop_end), [src]"+r"(buf1), + [dst]"+r"(buf2) + : + : "memory" + ); + } + + if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { + { + float wi; + float wj; + int i; + float temp0, temp1, temp2, temp3; + float *dst0 = out + 448 + 0*128; + float *dst1 = dst0 + 64 + 63; + float *dst2 = saved + 63; + float *win0 = (float*)swindow; + float *win1 = win0 + 64 + 63; + float *win0_prev = (float*)swindow_prev; + float *win1_prev = win0_prev + 64 + 63; + float *src0_prev = saved + 448; + float *src1_prev = buf + 0*128 + 63; + float *src0 = buf + 0*128 + 64; + float *src1 = buf + 1*128 + 63; + + for(i = 0; i < 64; i++) + { + temp0 = src0_prev[0]; + temp1 = src1_prev[0]; + wi = *win0_prev; + wj = *win1_prev; + temp2 = src0[0]; + temp3 = src1[0]; + dst0[0] = temp0 * wj - temp1 * wi; + dst1[0] = temp0 * wi + temp1 * wj; + + wi = *win0; + wj = *win1; + + temp0 = src0[128]; + temp1 = src1[128]; + dst0[128] = temp2 * wj - temp3 * wi; + dst1[128] = temp2 * wi + temp3 * wj; + + temp2 = src0[256]; + temp3 = src1[256]; + dst0[256] = temp0 * wj - temp1 * wi; + dst1[256] = temp0 * wi + temp1 * wj; + dst0[384] = temp2 * wj - temp3 * wi; + dst1[384] = temp2 * wi + temp3 * wj; + + temp0 = src0[384]; + temp1 = src1[384]; + dst0[512] = temp0 * wj - temp1 * wi; + dst2[0] = temp0 * wi + temp1 * wj; + + src0++; + src1--; + src0_prev++; + src1_prev--; + win0++; + win1--; + win0_prev++; + win1_prev--; + dst0++; + dst1--; + dst2--; + } + } + } else { + ac->fdsp.vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64); + { + float *buf1 = buf + 64; + float *buf2 = out + 576; + int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7; + int loop_end; + + /* loop unrolled 8 times */ + __asm__ volatile ( + ".set push \n\t" + ".set noreorder \n\t" + "addiu %[loop_end], %[src], 1792 \n\t" + "1: \n\t" + "lw %[temp0], 0(%[src]) \n\t" + "lw %[temp1], 4(%[src]) \n\t" + "lw %[temp2], 8(%[src]) \n\t" + "lw %[temp3], 12(%[src]) \n\t" + "lw %[temp4], 16(%[src]) \n\t" + "lw %[temp5], 20(%[src]) \n\t" + "lw %[temp6], 24(%[src]) \n\t" + "lw %[temp7], 28(%[src]) \n\t" + "addiu %[src], %[src], 32 \n\t" + "sw %[temp0], 0(%[dst]) \n\t" + "sw %[temp1], 4(%[dst]) \n\t" + "sw %[temp2], 8(%[dst]) \n\t" + "sw %[temp3], 12(%[dst]) \n\t" + "sw %[temp4], 16(%[dst]) \n\t" + "sw %[temp5], 20(%[dst]) \n\t" + "sw %[temp6], 24(%[dst]) \n\t" + "sw %[temp7], 28(%[dst]) \n\t" + "bne %[src], %[loop_end], 1b \n\t" + " addiu %[dst], %[dst], 32 \n\t" + ".set pop \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [loop_end]"=&r"(loop_end), [src]"+r"(buf1), + [dst]"+r"(buf2) + : + : "memory" + ); + } + } + } + + // buffer update + if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { + ac->fdsp.vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64); + ac->fdsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64); + ac->fdsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64); + { + float *buf1 = buf + 7*128 + 64; + float *buf2 = saved + 448; + int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7; + int loop_end; + + /* loop unrolled 8 times */ + __asm__ volatile ( + ".set push \n\t" + ".set noreorder \n\t" + "addiu %[loop_end], %[src], 256 \n\t" + "1: \n\t" + "lw %[temp0], 0(%[src]) \n\t" + "lw %[temp1], 4(%[src]) \n\t" + "lw %[temp2], 8(%[src]) \n\t" + "lw %[temp3], 12(%[src]) \n\t" + "lw %[temp4], 16(%[src]) \n\t" + "lw %[temp5], 20(%[src]) \n\t" + "lw %[temp6], 24(%[src]) \n\t" + "lw %[temp7], 28(%[src]) \n\t" + "addiu %[src], %[src], 32 \n\t" + "sw %[temp0], 0(%[dst]) \n\t" + "sw %[temp1], 4(%[dst]) \n\t" + "sw %[temp2], 8(%[dst]) \n\t" + "sw %[temp3], 12(%[dst]) \n\t" + "sw %[temp4], 16(%[dst]) \n\t" + "sw %[temp5], 20(%[dst]) \n\t" + "sw %[temp6], 24(%[dst]) \n\t" + "sw %[temp7], 28(%[dst]) \n\t" + "bne %[src], %[loop_end], 1b \n\t" + " addiu %[dst], %[dst], 32 \n\t" + ".set pop \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [loop_end]"=&r"(loop_end), [src]"+r"(buf1), + [dst]"+r"(buf2) + : + : "memory" + ); + } + } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { + float *buf1 = buf + 512; + float *buf2 = saved; + int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7; + int loop_end; + + /* loop unrolled 8 times */ + __asm__ volatile ( + ".set push \n\t" + ".set noreorder \n\t" + "addiu %[loop_end], %[src], 1792 \n\t" + "1: \n\t" + "lw %[temp0], 0(%[src]) \n\t" + "lw %[temp1], 4(%[src]) \n\t" + "lw %[temp2], 8(%[src]) \n\t" + "lw %[temp3], 12(%[src]) \n\t" + "lw %[temp4], 16(%[src]) \n\t" + "lw %[temp5], 20(%[src]) \n\t" + "lw %[temp6], 24(%[src]) \n\t" + "lw %[temp7], 28(%[src]) \n\t" + "addiu %[src], %[src], 32 \n\t" + "sw %[temp0], 0(%[dst]) \n\t" + "sw %[temp1], 4(%[dst]) \n\t" + "sw %[temp2], 8(%[dst]) \n\t" + "sw %[temp3], 12(%[dst]) \n\t" + "sw %[temp4], 16(%[dst]) \n\t" + "sw %[temp5], 20(%[dst]) \n\t" + "sw %[temp6], 24(%[dst]) \n\t" + "sw %[temp7], 28(%[dst]) \n\t" + "bne %[src], %[loop_end], 1b \n\t" + " addiu %[dst], %[dst], 32 \n\t" + ".set pop \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [loop_end]"=&r"(loop_end), [src]"+r"(buf1), + [dst]"+r"(buf2) + : + : "memory" + ); + { + float *buf1 = buf + 7*128 + 64; + float *buf2 = saved + 448; + int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7; + int loop_end; + + /* loop unrolled 8 times */ + __asm__ volatile ( + ".set push \n\t" + ".set noreorder \n\t" + "addiu %[loop_end], %[src], 256 \n\t" + "1: \n\t" + "lw %[temp0], 0(%[src]) \n\t" + "lw %[temp1], 4(%[src]) \n\t" + "lw %[temp2], 8(%[src]) \n\t" + "lw %[temp3], 12(%[src]) \n\t" + "lw %[temp4], 16(%[src]) \n\t" + "lw %[temp5], 20(%[src]) \n\t" + "lw %[temp6], 24(%[src]) \n\t" + "lw %[temp7], 28(%[src]) \n\t" + "addiu %[src], %[src], 32 \n\t" + "sw %[temp0], 0(%[dst]) \n\t" + "sw %[temp1], 4(%[dst]) \n\t" + "sw %[temp2], 8(%[dst]) \n\t" + "sw %[temp3], 12(%[dst]) \n\t" + "sw %[temp4], 16(%[dst]) \n\t" + "sw %[temp5], 20(%[dst]) \n\t" + "sw %[temp6], 24(%[dst]) \n\t" + "sw %[temp7], 28(%[dst]) \n\t" + "bne %[src], %[loop_end], 1b \n\t" + " addiu %[dst], %[dst], 32 \n\t" + ".set pop \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [loop_end]"=&r"(loop_end), [src]"+r"(buf1), + [dst]"+r"(buf2) + : + : "memory" + ); + } + } else { // LONG_STOP or ONLY_LONG + float *buf1 = buf + 512; + float *buf2 = saved; + int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7; + int loop_end; + + /* loop unrolled 8 times */ + __asm__ volatile ( + ".set push \n\t" + ".set noreorder \n\t" + "addiu %[loop_end], %[src], 2048 \n\t" + "1: \n\t" + "lw %[temp0], 0(%[src]) \n\t" + "lw %[temp1], 4(%[src]) \n\t" + "lw %[temp2], 8(%[src]) \n\t" + "lw %[temp3], 12(%[src]) \n\t" + "lw %[temp4], 16(%[src]) \n\t" + "lw %[temp5], 20(%[src]) \n\t" + "lw %[temp6], 24(%[src]) \n\t" + "lw %[temp7], 28(%[src]) \n\t" + "addiu %[src], %[src], 32 \n\t" + "sw %[temp0], 0(%[dst]) \n\t" + "sw %[temp1], 4(%[dst]) \n\t" + "sw %[temp2], 8(%[dst]) \n\t" + "sw %[temp3], 12(%[dst]) \n\t" + "sw %[temp4], 16(%[dst]) \n\t" + "sw %[temp5], 20(%[dst]) \n\t" + "sw %[temp6], 24(%[dst]) \n\t" + "sw %[temp7], 28(%[dst]) \n\t" + "bne %[src], %[loop_end], 1b \n\t" + " addiu %[dst], %[dst], 32 \n\t" + ".set pop \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [loop_end]"=&r"(loop_end), [src]"+r"(buf1), + [dst]"+r"(buf2) + : + : "memory" + ); + } +} + +static void apply_ltp_mips(AACContext *ac, SingleChannelElement *sce) +{ + const LongTermPrediction *ltp = &sce->ics.ltp; + const uint16_t *offsets = sce->ics.swb_offset; + int i, sfb; + int j, k; + + if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) { + float *predTime = sce->ret; + float *predFreq = ac->buf_mdct; + float *p_predTime; + int16_t num_samples = 2048; + + if (ltp->lag < 1024) + num_samples = ltp->lag + 1024; + j = (2048 - num_samples) >> 2; + k = (2048 - num_samples) & 3; + p_predTime = &predTime[num_samples]; + + for (i = 0; i < num_samples; i++) + predTime[i] = sce->ltp_state[i + 2048 - ltp->lag] * ltp->coef; + for (i = 0; i < j; i++) { + + /* loop unrolled 4 times */ + __asm__ volatile ( + "sw $0, 0(%[p_predTime]) \n\t" + "sw $0, 4(%[p_predTime]) \n\t" + "sw $0, 8(%[p_predTime]) \n\t" + "sw $0, 12(%[p_predTime]) \n\t" + "addiu %[p_predTime], %[p_predTime], 16 \n\t" + + : [p_predTime]"+r"(p_predTime) + : + : "memory" + ); + } + for (i = 0; i < k; i++) { + + __asm__ volatile ( + "sw $0, 0(%[p_predTime]) \n\t" + "addiu %[p_predTime], %[p_predTime], 4 \n\t" + + : [p_predTime]"+r"(p_predTime) + : + : "memory" + ); + } + + ac->windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics); + + if (sce->tns.present) + ac->apply_tns(predFreq, &sce->tns, &sce->ics, 0); + + for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++) + if (ltp->used[sfb]) + for (i = offsets[sfb]; i < offsets[sfb + 1]; i++) + sce->coeffs[i] += predFreq[i]; + } +} + +#if HAVE_MIPSFPU +static void update_ltp_mips(AACContext *ac, SingleChannelElement *sce) +{ + IndividualChannelStream *ics = &sce->ics; + float *saved = sce->saved; + float *saved_ltp = sce->coeffs; + const float *lwindow = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; + const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; + int i; + int loop_end, loop_end1, loop_end2; + float temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10, temp11; + + if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { + float *buf = saved; + float *buf0 = saved_ltp; + float *p_saved_ltp = saved_ltp + 576; + float *ptr1 = &saved_ltp[512]; + float *ptr2 = &ac->buf_mdct[1023]; + float *ptr3 = (float*)&swindow[63]; + loop_end1 = (int)(p_saved_ltp + 448); + + /* loop unrolled 8 times */ + __asm__ volatile ( + ".set push \n\t" + ".set noreorder \n\t" + "addiu %[loop_end], %[src], 2048 \n\t" + "1: \n\t" + "lw %[temp0], 0(%[src]) \n\t" + "lw %[temp1], 4(%[src]) \n\t" + "lw %[temp2], 8(%[src]) \n\t" + "lw %[temp3], 12(%[src]) \n\t" + "lw %[temp4], 16(%[src]) \n\t" + "lw %[temp5], 20(%[src]) \n\t" + "lw %[temp6], 24(%[src]) \n\t" + "lw %[temp7], 28(%[src]) \n\t" + "addiu %[src], %[src], 32 \n\t" + "sw %[temp0], 0(%[dst]) \n\t" + "sw %[temp1], 4(%[dst]) \n\t" + "sw %[temp2], 8(%[dst]) \n\t" + "sw %[temp3], 12(%[dst]) \n\t" + "sw %[temp4], 16(%[dst]) \n\t" + "sw %[temp5], 20(%[dst]) \n\t" + "sw %[temp6], 24(%[dst]) \n\t" + "sw %[temp7], 28(%[dst]) \n\t" + "bne %[src], %[loop_end], 1b \n\t" + " addiu %[dst], %[dst], 32 \n\t" + ".set pop \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [loop_end]"=&r"(loop_end), [src]"+r"(buf), + [dst]"+r"(buf0) + : + : "memory" + ); + + /* loop unrolled 8 times */ + __asm__ volatile ( + "1: \n\t" + "sw $0, 0(%[p_saved_ltp]) \n\t" + "sw $0, 4(%[p_saved_ltp]) \n\t" + "sw $0, 8(%[p_saved_ltp]) \n\t" + "sw $0, 12(%[p_saved_ltp]) \n\t" + "sw $0, 16(%[p_saved_ltp]) \n\t" + "sw $0, 20(%[p_saved_ltp]) \n\t" + "sw $0, 24(%[p_saved_ltp]) \n\t" + "sw $0, 28(%[p_saved_ltp]) \n\t" + "addiu %[p_saved_ltp], %[p_saved_ltp], 32 \n\t" + "bne %[p_saved_ltp], %[loop_end1], 1b \n\t" + + : [p_saved_ltp]"+r"(p_saved_ltp) + : [loop_end1]"r"(loop_end1) + : "memory" + ); + + ac->fdsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); + for (i = 0; i < 16; i++){ + /* loop unrolled 4 times */ + __asm__ volatile ( + "lwc1 %[temp0], 0(%[ptr2]) \n\t" + "lwc1 %[temp1], -4(%[ptr2]) \n\t" + "lwc1 %[temp2], -8(%[ptr2]) \n\t" + "lwc1 %[temp3], -12(%[ptr2]) \n\t" + "lwc1 %[temp4], 0(%[ptr3]) \n\t" + "lwc1 %[temp5], -4(%[ptr3]) \n\t" + "lwc1 %[temp6], -8(%[ptr3]) \n\t" + "lwc1 %[temp7], -12(%[ptr3]) \n\t" + "mul.s %[temp8], %[temp0], %[temp4] \n\t" + "mul.s %[temp9], %[temp1], %[temp5] \n\t" + "mul.s %[temp10], %[temp2], %[temp6] \n\t" + "mul.s %[temp11], %[temp3], %[temp7] \n\t" + "swc1 %[temp8], 0(%[ptr1]) \n\t" + "swc1 %[temp9], 4(%[ptr1]) \n\t" + "swc1 %[temp10], 8(%[ptr1]) \n\t" + "swc1 %[temp11], 12(%[ptr1]) \n\t" + "addiu %[ptr1], %[ptr1], 16 \n\t" + "addiu %[ptr2], %[ptr2], -16 \n\t" + "addiu %[ptr3], %[ptr3], -16 \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), + [temp2]"=&f"(temp2), [temp3]"=&f"(temp3), + [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [temp6]"=&f"(temp6), [temp7]"=&f"(temp7), + [temp8]"=&f"(temp8), [temp9]"=&f"(temp9), + [temp10]"=&f"(temp10), [temp11]"=&f"(temp11), + [ptr1]"+r"(ptr1), [ptr2]"+r"(ptr2), [ptr3]"+r"(ptr3) + : + : "memory" + ); + } + } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { + float *buff0 = saved; + float *buff1 = saved_ltp; + float *ptr1 = &saved_ltp[512]; + float *ptr2 = &ac->buf_mdct[1023]; + float *ptr3 = (float*)&swindow[63]; + loop_end = (int)(saved + 448); + + /* loop unrolled 8 times */ + __asm__ volatile ( + ".set push \n\t" + ".set noreorder \n\t" + "1: \n\t" + "lw %[temp0], 0(%[src]) \n\t" + "lw %[temp1], 4(%[src]) \n\t" + "lw %[temp2], 8(%[src]) \n\t" + "lw %[temp3], 12(%[src]) \n\t" + "lw %[temp4], 16(%[src]) \n\t" + "lw %[temp5], 20(%[src]) \n\t" + "lw %[temp6], 24(%[src]) \n\t" + "lw %[temp7], 28(%[src]) \n\t" + "addiu %[src], %[src], 32 \n\t" + "sw %[temp0], 0(%[dst]) \n\t" + "sw %[temp1], 4(%[dst]) \n\t" + "sw %[temp2], 8(%[dst]) \n\t" + "sw %[temp3], 12(%[dst]) \n\t" + "sw %[temp4], 16(%[dst]) \n\t" + "sw %[temp5], 20(%[dst]) \n\t" + "sw %[temp6], 24(%[dst]) \n\t" + "sw %[temp7], 28(%[dst]) \n\t" + "sw $0, 2304(%[dst]) \n\t" + "sw $0, 2308(%[dst]) \n\t" + "sw $0, 2312(%[dst]) \n\t" + "sw $0, 2316(%[dst]) \n\t" + "sw $0, 2320(%[dst]) \n\t" + "sw $0, 2324(%[dst]) \n\t" + "sw $0, 2328(%[dst]) \n\t" + "sw $0, 2332(%[dst]) \n\t" + "bne %[src], %[loop_end], 1b \n\t" + " addiu %[dst], %[dst], 32 \n\t" + ".set pop \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [src]"+r"(buff0), [dst]"+r"(buff1) + : [loop_end]"r"(loop_end) + : "memory" + ); + ac->fdsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); + for (i = 0; i < 16; i++){ + /* loop unrolled 8 times */ + __asm__ volatile ( + "lwc1 %[temp0], 0(%[ptr2]) \n\t" + "lwc1 %[temp1], -4(%[ptr2]) \n\t" + "lwc1 %[temp2], -8(%[ptr2]) \n\t" + "lwc1 %[temp3], -12(%[ptr2]) \n\t" + "lwc1 %[temp4], 0(%[ptr3]) \n\t" + "lwc1 %[temp5], -4(%[ptr3]) \n\t" + "lwc1 %[temp6], -8(%[ptr3]) \n\t" + "lwc1 %[temp7], -12(%[ptr3]) \n\t" + "mul.s %[temp8], %[temp0], %[temp4] \n\t" + "mul.s %[temp9], %[temp1], %[temp5] \n\t" + "mul.s %[temp10], %[temp2], %[temp6] \n\t" + "mul.s %[temp11], %[temp3], %[temp7] \n\t" + "swc1 %[temp8], 0(%[ptr1]) \n\t" + "swc1 %[temp9], 4(%[ptr1]) \n\t" + "swc1 %[temp10], 8(%[ptr1]) \n\t" + "swc1 %[temp11], 12(%[ptr1]) \n\t" + "addiu %[ptr1], %[ptr1], 16 \n\t" + "addiu %[ptr2], %[ptr2], -16 \n\t" + "addiu %[ptr3], %[ptr3], -16 \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), + [temp2]"=&f"(temp2), [temp3]"=&f"(temp3), + [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [temp6]"=&f"(temp6), [temp7]"=&f"(temp7), + [temp8]"=&f"(temp8), [temp9]"=&f"(temp9), + [temp10]"=&f"(temp10), [temp11]"=&f"(temp11), + [ptr1]"+r"(ptr1), [ptr2]"+r"(ptr2), [ptr3]"+r"(ptr3) + : + : "memory" + ); + } + } else { // LONG_STOP or ONLY_LONG + float *ptr1, *ptr2, *ptr3; + ac->fdsp.vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, &lwindow[512], 512); + + ptr1 = &saved_ltp[512]; + ptr2 = &ac->buf_mdct[1023]; + ptr3 = (float*)&lwindow[511]; + + for (i = 0; i < 512; i+=4){ + /* loop unrolled 4 times */ + __asm__ volatile ( + "lwc1 %[temp0], 0(%[ptr2]) \n\t" + "lwc1 %[temp1], -4(%[ptr2]) \n\t" + "lwc1 %[temp2], -8(%[ptr2]) \n\t" + "lwc1 %[temp3], -12(%[ptr2]) \n\t" + "lwc1 %[temp4], 0(%[ptr3]) \n\t" + "lwc1 %[temp5], -4(%[ptr3]) \n\t" + "lwc1 %[temp6], -8(%[ptr3]) \n\t" + "lwc1 %[temp7], -12(%[ptr3]) \n\t" + "mul.s %[temp8], %[temp0], %[temp4] \n\t" + "mul.s %[temp9], %[temp1], %[temp5] \n\t" + "mul.s %[temp10], %[temp2], %[temp6] \n\t" + "mul.s %[temp11], %[temp3], %[temp7] \n\t" + "swc1 %[temp8], 0(%[ptr1]) \n\t" + "swc1 %[temp9], 4(%[ptr1]) \n\t" + "swc1 %[temp10], 8(%[ptr1]) \n\t" + "swc1 %[temp11], 12(%[ptr1]) \n\t" + "addiu %[ptr1], %[ptr1], 16 \n\t" + "addiu %[ptr2], %[ptr2], -16 \n\t" + "addiu %[ptr3], %[ptr3], -16 \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), + [temp2]"=&f"(temp2), [temp3]"=&f"(temp3), + [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [temp6]"=&f"(temp6), [temp7]"=&f"(temp7), + [temp8]"=&f"(temp8), [temp9]"=&f"(temp9), + [temp10]"=&f"(temp10), [temp11]"=&f"(temp11), + [ptr1]"+r"(ptr1), [ptr2]"+r"(ptr2), + [ptr3]"+r"(ptr3) + : + : "memory" + ); + } + } + + { + float *buf1 = sce->ltp_state+1024; + float *buf2 = sce->ltp_state; + float *buf3 = sce->ret; + float *buf4 = sce->ltp_state+1024; + float *buf5 = saved_ltp; + float *buf6 = sce->ltp_state+2048; + + /* loops unrolled 8 times */ + __asm__ volatile ( + ".set push \n\t" + ".set noreorder \n\t" + "addiu %[loop_end], %[src], 4096 \n\t" + "addiu %[loop_end1], %[src1], 4096 \n\t" + "addiu %[loop_end2], %[src2], 4096 \n\t" + "1: \n\t" + "lw %[temp0], 0(%[src]) \n\t" + "lw %[temp1], 4(%[src]) \n\t" + "lw %[temp2], 8(%[src]) \n\t" + "lw %[temp3], 12(%[src]) \n\t" + "lw %[temp4], 16(%[src]) \n\t" + "lw %[temp5], 20(%[src]) \n\t" + "lw %[temp6], 24(%[src]) \n\t" + "lw %[temp7], 28(%[src]) \n\t" + "addiu %[src], %[src], 32 \n\t" + "sw %[temp0], 0(%[dst]) \n\t" + "sw %[temp1], 4(%[dst]) \n\t" + "sw %[temp2], 8(%[dst]) \n\t" + "sw %[temp3], 12(%[dst]) \n\t" + "sw %[temp4], 16(%[dst]) \n\t" + "sw %[temp5], 20(%[dst]) \n\t" + "sw %[temp6], 24(%[dst]) \n\t" + "sw %[temp7], 28(%[dst]) \n\t" + "bne %[src], %[loop_end], 1b \n\t" + " addiu %[dst], %[dst], 32 \n\t" + "2: \n\t" + "lw %[temp0], 0(%[src1]) \n\t" + "lw %[temp1], 4(%[src1]) \n\t" + "lw %[temp2], 8(%[src1]) \n\t" + "lw %[temp3], 12(%[src1]) \n\t" + "lw %[temp4], 16(%[src1]) \n\t" + "lw %[temp5], 20(%[src1]) \n\t" + "lw %[temp6], 24(%[src1]) \n\t" + "lw %[temp7], 28(%[src1]) \n\t" + "addiu %[src1], %[src1], 32 \n\t" + "sw %[temp0], 0(%[dst1]) \n\t" + "sw %[temp1], 4(%[dst1]) \n\t" + "sw %[temp2], 8(%[dst1]) \n\t" + "sw %[temp3], 12(%[dst1]) \n\t" + "sw %[temp4], 16(%[dst1]) \n\t" + "sw %[temp5], 20(%[dst1]) \n\t" + "sw %[temp6], 24(%[dst1]) \n\t" + "sw %[temp7], 28(%[dst1]) \n\t" + "bne %[src1], %[loop_end1], 2b \n\t" + " addiu %[dst1], %[dst1], 32 \n\t" + "3: \n\t" + "lw %[temp0], 0(%[src2]) \n\t" + "lw %[temp1], 4(%[src2]) \n\t" + "lw %[temp2], 8(%[src2]) \n\t" + "lw %[temp3], 12(%[src2]) \n\t" + "lw %[temp4], 16(%[src2]) \n\t" + "lw %[temp5], 20(%[src2]) \n\t" + "lw %[temp6], 24(%[src2]) \n\t" + "lw %[temp7], 28(%[src2]) \n\t" + "addiu %[src2], %[src2], 32 \n\t" + "sw %[temp0], 0(%[dst2]) \n\t" + "sw %[temp1], 4(%[dst2]) \n\t" + "sw %[temp2], 8(%[dst2]) \n\t" + "sw %[temp3], 12(%[dst2]) \n\t" + "sw %[temp4], 16(%[dst2]) \n\t" + "sw %[temp5], 20(%[dst2]) \n\t" + "sw %[temp6], 24(%[dst2]) \n\t" + "sw %[temp7], 28(%[dst2]) \n\t" + "bne %[src2], %[loop_end2], 3b \n\t" + " addiu %[dst2], %[dst2], 32 \n\t" + ".set pop \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [loop_end]"=&r"(loop_end), [loop_end1]"=&r"(loop_end1), + [loop_end2]"=&r"(loop_end2), [src]"+r"(buf1), + [dst]"+r"(buf2), [src1]"+r"(buf3), [dst1]"+r"(buf4), + [src2]"+r"(buf5), [dst2]"+r"(buf6) + : + : "memory" + ); + } +} +#endif /* HAVE_MIPSFPU */ +#endif /* HAVE_INLINE_ASM */ + +void ff_aacdec_init_mips(AACContext *c) +{ +#if HAVE_INLINE_ASM + c->imdct_and_windowing = imdct_and_windowing_mips; + c->apply_ltp = apply_ltp_mips; +#if HAVE_MIPSFPU + c->update_ltp = update_ltp_mips; +#endif /* HAVE_MIPSFPU */ +#endif /* HAVE_INLINE_ASM */ +} diff --git a/mythtv/external/FFmpeg/libavcodec/mips/aacdec_mips.h b/mythtv/external/FFmpeg/libavcodec/mips/aacdec_mips.h new file mode 100644 index 00000000000..9ba307962ff --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/mips/aacdec_mips.h @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Authors: Darko Laus (darko@mips.com) + * Djordje Pesut (djordje@mips.com) + * Mirjana Vulin (mvulin@mips.com) + * + * AAC Spectral Band Replication decoding functions optimized for MIPS + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Reference: libavcodec/aacdec.c + */ + +#ifndef AVCODEC_MIPS_AACDEC_FLOAT_H +#define AVCODEC_MIPS_AACDEC_FLOAT_H + +#include "libavcodec/aac.h" + +#if HAVE_INLINE_ASM && HAVE_MIPSFPU +static inline float *VMUL2_mips(float *dst, const float *v, unsigned idx, + const float *scale) +{ + float temp0, temp1, temp2; + int temp3, temp4; + float *ret; + + __asm__ volatile( + "andi %[temp3], %[idx], 15 \n\t" + "ext %[temp4], %[idx], 4, 4 \n\t" + "sll %[temp3], %[temp3], 2 \n\t" + "sll %[temp4], %[temp4], 2 \n\t" + "lwc1 %[temp2], 0(%[scale]) \n\t" + "lwxc1 %[temp0], %[temp3](%[v]) \n\t" + "lwxc1 %[temp1], %[temp4](%[v]) \n\t" + "mul.s %[temp0], %[temp0], %[temp2] \n\t" + "mul.s %[temp1], %[temp1], %[temp2] \n\t" + "addiu %[ret], %[dst], 8 \n\t" + "swc1 %[temp0], 0(%[dst]) \n\t" + "swc1 %[temp1], 4(%[dst]) \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), + [temp2]"=&f"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [ret]"=&r"(ret) + : [idx]"r"(idx), [scale]"r"(scale), [v]"r"(v), + [dst]"r"(dst) + : "memory" + ); + return ret; +} + +static inline float *VMUL4_mips(float *dst, const float *v, unsigned idx, + const float *scale) +{ + int temp0, temp1, temp2, temp3; + float temp4, temp5, temp6, temp7, temp8; + float *ret; + + __asm__ volatile( + "andi %[temp0], %[idx], 3 \n\t" + "ext %[temp1], %[idx], 2, 2 \n\t" + "ext %[temp2], %[idx], 4, 2 \n\t" + "ext %[temp3], %[idx], 6, 2 \n\t" + "sll %[temp0], %[temp0], 2 \n\t" + "sll %[temp1], %[temp1], 2 \n\t" + "sll %[temp2], %[temp2], 2 \n\t" + "sll %[temp3], %[temp3], 2 \n\t" + "lwc1 %[temp4], 0(%[scale]) \n\t" + "lwxc1 %[temp5], %[temp0](%[v]) \n\t" + "lwxc1 %[temp6], %[temp1](%[v]) \n\t" + "lwxc1 %[temp7], %[temp2](%[v]) \n\t" + "lwxc1 %[temp8], %[temp3](%[v]) \n\t" + "mul.s %[temp5], %[temp5], %[temp4] \n\t" + "mul.s %[temp6], %[temp6], %[temp4] \n\t" + "mul.s %[temp7], %[temp7], %[temp4] \n\t" + "mul.s %[temp8], %[temp8], %[temp4] \n\t" + "addiu %[ret], %[dst], 16 \n\t" + "swc1 %[temp5], 0(%[dst]) \n\t" + "swc1 %[temp6], 4(%[dst]) \n\t" + "swc1 %[temp7], 8(%[dst]) \n\t" + "swc1 %[temp8], 12(%[dst]) \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [temp6]"=&f"(temp6), [temp7]"=&f"(temp7), + [temp8]"=&f"(temp8), [ret]"=&r"(ret) + : [idx]"r"(idx), [scale]"r"(scale), [v]"r"(v), + [dst]"r"(dst) + : "memory" + ); + return ret; +} + +static inline float *VMUL2S_mips(float *dst, const float *v, unsigned idx, + unsigned sign, const float *scale) +{ + int temp0, temp1, temp2, temp3, temp4, temp5; + float temp6, temp7, temp8, temp9; + float *ret; + + __asm__ volatile( + "andi %[temp0], %[idx], 15 \n\t" + "ext %[temp1], %[idx], 4, 4 \n\t" + "lw %[temp4], 0(%[scale]) \n\t" + "srl %[temp2], %[sign], 1 \n\t" + "sll %[temp3], %[sign], 31 \n\t" + "sll %[temp2], %[temp2], 31 \n\t" + "sll %[temp0], %[temp0], 2 \n\t" + "sll %[temp1], %[temp1], 2 \n\t" + "lwxc1 %[temp8], %[temp0](%[v]) \n\t" + "lwxc1 %[temp9], %[temp1](%[v]) \n\t" + "xor %[temp5], %[temp4], %[temp2] \n\t" + "xor %[temp4], %[temp4], %[temp3] \n\t" + "mtc1 %[temp5], %[temp6] \n\t" + "mtc1 %[temp4], %[temp7] \n\t" + "mul.s %[temp8], %[temp8], %[temp6] \n\t" + "mul.s %[temp9], %[temp9], %[temp7] \n\t" + "addiu %[ret], %[dst], 8 \n\t" + "swc1 %[temp8], 0(%[dst]) \n\t" + "swc1 %[temp9], 4(%[dst]) \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&f"(temp6), [temp7]"=&f"(temp7), + [temp8]"=&f"(temp8), [temp9]"=&f"(temp9), + [ret]"=&r"(ret) + : [idx]"r"(idx), [scale]"r"(scale), [v]"r"(v), + [dst]"r"(dst), [sign]"r"(sign) + : "memory" + ); + return ret; +} + +static inline float *VMUL4S_mips(float *dst, const float *v, unsigned idx, + unsigned sign, const float *scale) +{ + int temp0, temp1, temp2, temp3, temp4; + float temp10, temp11, temp12, temp13, temp14, temp15, temp16, temp17; + float *ret; + unsigned int mask = 1U << 31; + + __asm__ volatile( + "lw %[temp0], 0(%[scale]) \n\t" + "and %[temp1], %[idx], 3 \n\t" + "ext %[temp2], %[idx], 2, 2 \n\t" + "ext %[temp3], %[idx], 4, 2 \n\t" + "ext %[temp4], %[idx], 6, 2 \n\t" + "sll %[temp1], %[temp1], 2 \n\t" + "sll %[temp2], %[temp2], 2 \n\t" + "sll %[temp3], %[temp3], 2 \n\t" + "sll %[temp4], %[temp4], 2 \n\t" + "lwxc1 %[temp10], %[temp1](%[v]) \n\t" + "lwxc1 %[temp11], %[temp2](%[v]) \n\t" + "lwxc1 %[temp12], %[temp3](%[v]) \n\t" + "lwxc1 %[temp13], %[temp4](%[v]) \n\t" + "and %[temp1], %[sign], %[mask] \n\t" + "ext %[temp2], %[idx], 12, 1 \n\t" + "ext %[temp3], %[idx], 13, 1 \n\t" + "ext %[temp4], %[idx], 14, 1 \n\t" + "sllv %[sign], %[sign], %[temp2] \n\t" + "xor %[temp1], %[temp0], %[temp1] \n\t" + "and %[temp2], %[sign], %[mask] \n\t" + "mtc1 %[temp1], %[temp14] \n\t" + "xor %[temp2], %[temp0], %[temp2] \n\t" + "sllv %[sign], %[sign], %[temp3] \n\t" + "mtc1 %[temp2], %[temp15] \n\t" + "and %[temp3], %[sign], %[mask] \n\t" + "sllv %[sign], %[sign], %[temp4] \n\t" + "xor %[temp3], %[temp0], %[temp3] \n\t" + "and %[temp4], %[sign], %[mask] \n\t" + "mtc1 %[temp3], %[temp16] \n\t" + "xor %[temp4], %[temp0], %[temp4] \n\t" + "mtc1 %[temp4], %[temp17] \n\t" + "mul.s %[temp10], %[temp10], %[temp14] \n\t" + "mul.s %[temp11], %[temp11], %[temp15] \n\t" + "mul.s %[temp12], %[temp12], %[temp16] \n\t" + "mul.s %[temp13], %[temp13], %[temp17] \n\t" + "addiu %[ret], %[dst], 16 \n\t" + "swc1 %[temp10], 0(%[dst]) \n\t" + "swc1 %[temp11], 4(%[dst]) \n\t" + "swc1 %[temp12], 8(%[dst]) \n\t" + "swc1 %[temp13], 12(%[dst]) \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp10]"=&f"(temp10), + [temp11]"=&f"(temp11), [temp12]"=&f"(temp12), + [temp13]"=&f"(temp13), [temp14]"=&f"(temp14), + [temp15]"=&f"(temp15), [temp16]"=&f"(temp16), + [temp17]"=&f"(temp17), [ret]"=&r"(ret), + [sign]"+r"(sign) + : [idx]"r"(idx), [scale]"r"(scale), [v]"r"(v), + [dst]"r"(dst), [mask]"r"(mask) + : "memory" + ); + return ret; +} + +#define VMUL2 VMUL2_mips +#define VMUL4 VMUL4_mips +#define VMUL2S VMUL2S_mips +#define VMUL4S VMUL4S_mips +#endif /* HAVE_INLINE_ASM && HAVE_MIPSFPU */ + +#endif /* AVCODEC_MIPS_AACDEC_FLOAT_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/mips/aacpsdsp_mips.c b/mythtv/external/FFmpeg/libavcodec/mips/aacpsdsp_mips.c new file mode 100644 index 00000000000..4730a7f7143 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/mips/aacpsdsp_mips.c @@ -0,0 +1,459 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Authors: Darko Laus (darko@mips.com) + * Djordje Pesut (djordje@mips.com) + * Mirjana Vulin (mvulin@mips.com) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Reference: libavcodec/aacpsdsp.c + */ + +#include "config.h" +#include "libavcodec/aacpsdsp.h" + +#if HAVE_INLINE_ASM +static void ps_hybrid_analysis_ileave_mips(float (*out)[32][2], float L[2][38][64], + int i, int len) +{ + int temp0, temp1, temp2, temp3; + int temp4, temp5, temp6, temp7; + float *out1=&out[i][0][0]; + float *L1=&L[0][0][i]; + float *j=out1+ len*2; + + for (; i < 64; i++) { + + /* loop unrolled 8 times */ + __asm__ volatile ( + "1: \n\t" + "lw %[temp0], 0(%[L1]) \n\t" + "lw %[temp1], 9728(%[L1]) \n\t" + "lw %[temp2], 256(%[L1]) \n\t" + "lw %[temp3], 9984(%[L1]) \n\t" + "lw %[temp4], 512(%[L1]) \n\t" + "lw %[temp5], 10240(%[L1]) \n\t" + "lw %[temp6], 768(%[L1]) \n\t" + "lw %[temp7], 10496(%[L1]) \n\t" + "sw %[temp0], 0(%[out1]) \n\t" + "sw %[temp1], 4(%[out1]) \n\t" + "sw %[temp2], 8(%[out1]) \n\t" + "sw %[temp3], 12(%[out1]) \n\t" + "sw %[temp4], 16(%[out1]) \n\t" + "sw %[temp5], 20(%[out1]) \n\t" + "sw %[temp6], 24(%[out1]) \n\t" + "sw %[temp7], 28(%[out1]) \n\t" + "addiu %[out1], %[out1], 32 \n\t" + "addiu %[L1], %[L1], 1024 \n\t" + "bne %[out1], %[j], 1b \n\t" + + : [out1]"+r"(out1), [L1]"+r"(L1), [j]"+r"(j), + [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7) + : [len]"r"(len) + : "memory" + ); + out1-=(len<<1)-64; + L1-=(len<<6)-1; + j+=len*2; + } +} + +static void ps_hybrid_synthesis_deint_mips(float out[2][38][64], + float (*in)[32][2], + int i, int len) +{ + int n; + int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7; + float *out1 = (float*)out + i; + float *out2 = (float*)out + 2432 + i; + float *in1 = (float*)in + 64 * i; + float *in2 = (float*)in + 64 * i + 1; + + for (; i < 64; i++) { + for (n = 0; n < 7; n++) { + + /* loop unrolled 8 times */ + __asm__ volatile ( + "lw %[temp0], 0(%[in1]) \n\t" + "lw %[temp1], 0(%[in2]) \n\t" + "lw %[temp2], 8(%[in1]) \n\t" + "lw %[temp3], 8(%[in2]) \n\t" + "lw %[temp4], 16(%[in1]) \n\t" + "lw %[temp5], 16(%[in2]) \n\t" + "lw %[temp6], 24(%[in1]) \n\t" + "lw %[temp7], 24(%[in2]) \n\t" + "addiu %[out1], %[out1], 1024 \n\t" + "addiu %[out2], %[out2], 1024 \n\t" + "addiu %[in1], %[in1], 32 \n\t" + "addiu %[in2], %[in2], 32 \n\t" + "sw %[temp0], -1024(%[out1]) \n\t" + "sw %[temp1], -1024(%[out2]) \n\t" + "sw %[temp2], -768(%[out1]) \n\t" + "sw %[temp3], -768(%[out2]) \n\t" + "sw %[temp4], -512(%[out1]) \n\t" + "sw %[temp5], -512(%[out2]) \n\t" + "sw %[temp6], -256(%[out1]) \n\t" + "sw %[temp7], -256(%[out2]) \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [out1]"+r"(out1), [out2]"+r"(out2), + [in1]"+r"(in1), [in2]"+r"(in2) + : + : "memory" + ); + } + /* loop unrolled 8 times */ + __asm__ volatile ( + "lw %[temp0], 0(%[in1]) \n\t" + "lw %[temp1], 0(%[in2]) \n\t" + "lw %[temp2], 8(%[in1]) \n\t" + "lw %[temp3], 8(%[in2]) \n\t" + "lw %[temp4], 16(%[in1]) \n\t" + "lw %[temp5], 16(%[in2]) \n\t" + "lw %[temp6], 24(%[in1]) \n\t" + "lw %[temp7], 24(%[in2]) \n\t" + "addiu %[out1], %[out1], -7164 \n\t" + "addiu %[out2], %[out2], -7164 \n\t" + "addiu %[in1], %[in1], 32 \n\t" + "addiu %[in2], %[in2], 32 \n\t" + "sw %[temp0], 7164(%[out1]) \n\t" + "sw %[temp1], 7164(%[out2]) \n\t" + "sw %[temp2], 7420(%[out1]) \n\t" + "sw %[temp3], 7420(%[out2]) \n\t" + "sw %[temp4], 7676(%[out1]) \n\t" + "sw %[temp5], 7676(%[out2]) \n\t" + "sw %[temp6], 7932(%[out1]) \n\t" + "sw %[temp7], 7932(%[out2]) \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [out1]"+r"(out1), [out2]"+r"(out2), + [in1]"+r"(in1), [in2]"+r"(in2) + : + : "memory" + ); + } +} + +#if HAVE_MIPSFPU +static void ps_add_squares_mips(float *dst, const float (*src)[2], int n) +{ + int i; + float temp0, temp1, temp2, temp3, temp4, temp5; + float temp6, temp7, temp8, temp9, temp10, temp11; + float *src0 = (float*)&src[0][0]; + float *dst0 = &dst[0]; + + for (i = 0; i < 8; i++) { + /* loop unrolled 4 times */ + __asm__ volatile ( + "lwc1 %[temp0], 0(%[src0]) \n\t" + "lwc1 %[temp1], 4(%[src0]) \n\t" + "lwc1 %[temp2], 8(%[src0]) \n\t" + "lwc1 %[temp3], 12(%[src0]) \n\t" + "lwc1 %[temp4], 16(%[src0]) \n\t" + "lwc1 %[temp5], 20(%[src0]) \n\t" + "lwc1 %[temp6], 24(%[src0]) \n\t" + "lwc1 %[temp7], 28(%[src0]) \n\t" + "lwc1 %[temp8], 0(%[dst0]) \n\t" + "lwc1 %[temp9], 4(%[dst0]) \n\t" + "lwc1 %[temp10], 8(%[dst0]) \n\t" + "lwc1 %[temp11], 12(%[dst0]) \n\t" + "mul.s %[temp1], %[temp1], %[temp1] \n\t" + "mul.s %[temp3], %[temp3], %[temp3] \n\t" + "mul.s %[temp5], %[temp5], %[temp5] \n\t" + "mul.s %[temp7], %[temp7], %[temp7] \n\t" + "madd.s %[temp0], %[temp1], %[temp0], %[temp0] \n\t" + "madd.s %[temp2], %[temp3], %[temp2], %[temp2] \n\t" + "madd.s %[temp4], %[temp5], %[temp4], %[temp4] \n\t" + "madd.s %[temp6], %[temp7], %[temp6], %[temp6] \n\t" + "add.s %[temp0], %[temp8], %[temp0] \n\t" + "add.s %[temp2], %[temp9], %[temp2] \n\t" + "add.s %[temp4], %[temp10], %[temp4] \n\t" + "add.s %[temp6], %[temp11], %[temp6] \n\t" + "swc1 %[temp0], 0(%[dst0]) \n\t" + "swc1 %[temp2], 4(%[dst0]) \n\t" + "swc1 %[temp4], 8(%[dst0]) \n\t" + "swc1 %[temp6], 12(%[dst0]) \n\t" + "addiu %[dst0], %[dst0], 16 \n\t" + "addiu %[src0], %[src0], 32 \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&f"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [temp6]"=&f"(temp6), [temp7]"=&f"(temp7), [temp8]"=&f"(temp8), + [temp9]"=&f"(temp9), [dst0]"+r"(dst0), [src0]"+r"(src0), + [temp10]"=&f"(temp10), [temp11]"=&f"(temp11) + : + : "memory" + ); + } +} + +static void ps_mul_pair_single_mips(float (*dst)[2], float (*src0)[2], float *src1, + int n) +{ + float temp0, temp1, temp2; + float *p_d, *p_s0, *p_s1, *end; + p_d = &dst[0][0]; + p_s0 = &src0[0][0]; + p_s1 = &src1[0]; + end = p_s1 + n; + + __asm__ volatile( + ".set push \n\t" + ".set noreorder \n\t" + "1: \n\t" + "lwc1 %[temp2], 0(%[p_s1]) \n\t" + "lwc1 %[temp0], 0(%[p_s0]) \n\t" + "lwc1 %[temp1], 4(%[p_s0]) \n\t" + "addiu %[p_d], %[p_d], 8 \n\t" + "mul.s %[temp0], %[temp0], %[temp2] \n\t" + "mul.s %[temp1], %[temp1], %[temp2] \n\t" + "addiu %[p_s0], %[p_s0], 8 \n\t" + "swc1 %[temp0], -8(%[p_d]) \n\t" + "swc1 %[temp1], -4(%[p_d]) \n\t" + "bne %[p_s1], %[end], 1b \n\t" + " addiu %[p_s1], %[p_s1], 4 \n\t" + ".set pop \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), + [temp2]"=&f"(temp2), [p_d]"+r"(p_d), + [p_s0]"+r"(p_s0), [p_s1]"+r"(p_s1) + : [end]"r"(end) + : "memory" + ); +} + +static void ps_decorrelate_mips(float (*out)[2], float (*delay)[2], + float (*ap_delay)[PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2], + const float phi_fract[2], float (*Q_fract)[2], + const float *transient_gain, + float g_decay_slope, + int len) +{ + float *p_delay = &delay[0][0]; + float *p_out = &out[0][0]; + float *p_ap_delay = &ap_delay[0][0][0]; + float *p_t_gain = (float*)transient_gain; + float *p_Q_fract = &Q_fract[0][0]; + float ag0, ag1, ag2; + float phi_fract0 = phi_fract[0]; + float phi_fract1 = phi_fract[1]; + float temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9; + + len = (int)((int*)p_delay + (len << 1)); + + /* merged 2 loops */ + __asm__ volatile( + ".set push \n\t" + ".set noreorder \n\t" + "li.s %[ag0], 0.65143905753106 \n\t" + "li.s %[ag1], 0.56471812200776 \n\t" + "li.s %[ag2], 0.48954165955695 \n\t" + "mul.s %[ag0], %[ag0], %[g_decay_slope] \n\t" + "mul.s %[ag1], %[ag1], %[g_decay_slope] \n\t" + "mul.s %[ag2], %[ag2], %[g_decay_slope] \n\t" + "1: \n\t" + "lwc1 %[temp0], 0(%[p_delay]) \n\t" + "lwc1 %[temp1], 4(%[p_delay]) \n\t" + "lwc1 %[temp4], 16(%[p_ap_delay]) \n\t" + "lwc1 %[temp5], 20(%[p_ap_delay]) \n\t" + "mul.s %[temp3], %[temp0], %[phi_fract1] \n\t" + "lwc1 %[temp6], 0(%[p_Q_fract]) \n\t" + "mul.s %[temp2], %[temp1], %[phi_fract1] \n\t" + "lwc1 %[temp7], 4(%[p_Q_fract]) \n\t" + "madd.s %[temp3], %[temp3], %[temp1], %[phi_fract0] \n\t" + "msub.s %[temp2], %[temp2], %[temp0], %[phi_fract0] \n\t" + "mul.s %[temp8], %[temp5], %[temp7] \n\t" + "mul.s %[temp9], %[temp4], %[temp7] \n\t" + "lwc1 %[temp7], 12(%[p_Q_fract]) \n\t" + "mul.s %[temp0], %[ag0], %[temp2] \n\t" + "mul.s %[temp1], %[ag0], %[temp3] \n\t" + "msub.s %[temp8], %[temp8], %[temp4], %[temp6] \n\t" + "lwc1 %[temp4], 304(%[p_ap_delay]) \n\t" + "madd.s %[temp9], %[temp9], %[temp5], %[temp6] \n\t" + "lwc1 %[temp5], 308(%[p_ap_delay]) \n\t" + "sub.s %[temp0], %[temp8], %[temp0] \n\t" + "sub.s %[temp1], %[temp9], %[temp1] \n\t" + "madd.s %[temp2], %[temp2], %[ag0], %[temp0] \n\t" + "lwc1 %[temp6], 8(%[p_Q_fract]) \n\t" + "madd.s %[temp3], %[temp3], %[ag0], %[temp1] \n\t" + "mul.s %[temp8], %[temp5], %[temp7] \n\t" + "mul.s %[temp9], %[temp4], %[temp7] \n\t" + "lwc1 %[temp7], 20(%[p_Q_fract]) \n\t" + "msub.s %[temp8], %[temp8], %[temp4], %[temp6] \n\t" + "swc1 %[temp2], 40(%[p_ap_delay]) \n\t" + "mul.s %[temp2], %[ag1], %[temp0] \n\t" + "swc1 %[temp3], 44(%[p_ap_delay]) \n\t" + "mul.s %[temp3], %[ag1], %[temp1] \n\t" + "lwc1 %[temp4], 592(%[p_ap_delay]) \n\t" + "madd.s %[temp9], %[temp9], %[temp5], %[temp6] \n\t" + "lwc1 %[temp5], 596(%[p_ap_delay]) \n\t" + "sub.s %[temp2], %[temp8], %[temp2] \n\t" + "sub.s %[temp3], %[temp9], %[temp3] \n\t" + "lwc1 %[temp6], 16(%[p_Q_fract]) \n\t" + "madd.s %[temp0], %[temp0], %[ag1], %[temp2] \n\t" + "madd.s %[temp1], %[temp1], %[ag1], %[temp3] \n\t" + "mul.s %[temp8], %[temp5], %[temp7] \n\t" + "mul.s %[temp9], %[temp4], %[temp7] \n\t" + "msub.s %[temp8], %[temp8], %[temp4], %[temp6] \n\t" + "madd.s %[temp9], %[temp9], %[temp5], %[temp6] \n\t" + "swc1 %[temp0], 336(%[p_ap_delay]) \n\t" + "mul.s %[temp0], %[ag2], %[temp2] \n\t" + "swc1 %[temp1], 340(%[p_ap_delay]) \n\t" + "mul.s %[temp1], %[ag2], %[temp3] \n\t" + "lwc1 %[temp4], 0(%[p_t_gain]) \n\t" + "sub.s %[temp0], %[temp8], %[temp0] \n\t" + "addiu %[p_ap_delay], %[p_ap_delay], 8 \n\t" + "sub.s %[temp1], %[temp9], %[temp1] \n\t" + "addiu %[p_t_gain], %[p_t_gain], 4 \n\t" + "madd.s %[temp2], %[temp2], %[ag2], %[temp0] \n\t" + "addiu %[p_delay], %[p_delay], 8 \n\t" + "madd.s %[temp3], %[temp3], %[ag2], %[temp1] \n\t" + "addiu %[p_out], %[p_out], 8 \n\t" + "mul.s %[temp5], %[temp4], %[temp0] \n\t" + "mul.s %[temp6], %[temp4], %[temp1] \n\t" + "swc1 %[temp2], 624(%[p_ap_delay]) \n\t" + "swc1 %[temp3], 628(%[p_ap_delay]) \n\t" + "swc1 %[temp5], -8(%[p_out]) \n\t" + "swc1 %[temp6], -4(%[p_out]) \n\t" + "bne %[p_delay], %[len], 1b \n\t" + " swc1 %[temp6], -4(%[p_out]) \n\t" + ".set pop \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&f"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [temp6]"=&f"(temp6), [temp7]"=&f"(temp7), [temp8]"=&f"(temp8), + [temp9]"=&f"(temp9), [p_delay]"+r"(p_delay), [p_ap_delay]"+r"(p_ap_delay), + [p_Q_fract]"+r"(p_Q_fract), [p_t_gain]"+r"(p_t_gain), [p_out]"+r"(p_out), + [ag0]"=&f"(ag0), [ag1]"=&f"(ag1), [ag2]"=&f"(ag2) + : [phi_fract0]"f"(phi_fract0), [phi_fract1]"f"(phi_fract1), + [len]"r"(len), [g_decay_slope]"f"(g_decay_slope) + : "memory" + ); +} + +static void ps_stereo_interpolate_mips(float (*l)[2], float (*r)[2], + float h[2][4], float h_step[2][4], + int len) +{ + float h0 = h[0][0]; + float h1 = h[0][1]; + float h2 = h[0][2]; + float h3 = h[0][3]; + float hs0 = h_step[0][0]; + float hs1 = h_step[0][1]; + float hs2 = h_step[0][2]; + float hs3 = h_step[0][3]; + float temp0, temp1, temp2, temp3; + float l_re, l_im, r_re, r_im; + + len = (int)((int*)l + (len << 1)); + + __asm__ volatile( + ".set push \n\t" + ".set noreorder \n\t" + "1: \n\t" + "add.s %[h0], %[h0], %[hs0] \n\t" + "lwc1 %[l_re], 0(%[l]) \n\t" + "add.s %[h1], %[h1], %[hs1] \n\t" + "lwc1 %[r_re], 0(%[r]) \n\t" + "add.s %[h2], %[h2], %[hs2] \n\t" + "lwc1 %[l_im], 4(%[l]) \n\t" + "add.s %[h3], %[h3], %[hs3] \n\t" + "lwc1 %[r_im], 4(%[r]) \n\t" + "mul.s %[temp0], %[h0], %[l_re] \n\t" + "addiu %[l], %[l], 8 \n\t" + "mul.s %[temp2], %[h1], %[l_re] \n\t" + "addiu %[r], %[r], 8 \n\t" + "madd.s %[temp0], %[temp0], %[h2], %[r_re] \n\t" + "madd.s %[temp2], %[temp2], %[h3], %[r_re] \n\t" + "mul.s %[temp1], %[h0], %[l_im] \n\t" + "mul.s %[temp3], %[h1], %[l_im] \n\t" + "madd.s %[temp1], %[temp1], %[h2], %[r_im] \n\t" + "madd.s %[temp3], %[temp3], %[h3], %[r_im] \n\t" + "swc1 %[temp0], -8(%[l]) \n\t" + "swc1 %[temp2], -8(%[r]) \n\t" + "swc1 %[temp1], -4(%[l]) \n\t" + "bne %[l], %[len], 1b \n\t" + " swc1 %[temp3], -4(%[r]) \n\t" + ".set pop \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), + [temp2]"=&f"(temp2), [temp3]"=&f"(temp3), + [h0]"+f"(h0), [h1]"+f"(h1), [h2]"+f"(h2), + [h3]"+f"(h3), [l]"+r"(l), [r]"+r"(r), + [l_re]"=&f"(l_re), [l_im]"=&f"(l_im), + [r_re]"=&f"(r_re), [r_im]"=&f"(r_im) + : [hs0]"f"(hs0), [hs1]"f"(hs1), [hs2]"f"(hs2), + [hs3]"f"(hs3), [len]"r"(len) + : "memory" + ); +} +#endif /* HAVE_MIPSFPU */ +#endif /* HAVE_INLINE_ASM */ + +void ff_psdsp_init_mips(PSDSPContext *s) +{ +#if HAVE_INLINE_ASM + s->hybrid_analysis_ileave = ps_hybrid_analysis_ileave_mips; + s->hybrid_synthesis_deint = ps_hybrid_synthesis_deint_mips; +#if HAVE_MIPSFPU + s->add_squares = ps_add_squares_mips; + s->mul_pair_single = ps_mul_pair_single_mips; + s->decorrelate = ps_decorrelate_mips; + s->stereo_interpolate[0] = ps_stereo_interpolate_mips; +#endif /* HAVE_MIPSFPU */ +#endif /* HAVE_INLINE_ASM */ +} diff --git a/mythtv/external/FFmpeg/libavcodec/mips/aacsbr_mips.c b/mythtv/external/FFmpeg/libavcodec/mips/aacsbr_mips.c new file mode 100644 index 00000000000..53a5fd06b71 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/mips/aacsbr_mips.c @@ -0,0 +1,618 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Authors: Djordje Pesut (djordje@mips.com) + * Mirjana Vulin (mvulin@mips.com) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Reference: libavcodec/aacsbr.c + */ + +#include "libavcodec/aac.h" +#include "libavcodec/aacsbr.h" + +#define ENVELOPE_ADJUSTMENT_OFFSET 2 + +#if HAVE_INLINE_ASM +static int sbr_lf_gen_mips(AACContext *ac, SpectralBandReplication *sbr, + float X_low[32][40][2], const float W[2][32][32][2], + int buf_idx) +{ + int i, k; + int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7; + float *p_x_low = &X_low[0][8][0]; + float *p_w = (float*)&W[buf_idx][0][0][0]; + float *p_x1_low = &X_low[0][0][0]; + float *p_w1 = (float*)&W[1-buf_idx][24][0][0]; + + float *loop_end=p_x1_low + 2560; + + /* loop unrolled 8 times */ + __asm__ volatile ( + "1: \n\t" + "sw $0, 0(%[p_x1_low]) \n\t" + "sw $0, 4(%[p_x1_low]) \n\t" + "sw $0, 8(%[p_x1_low]) \n\t" + "sw $0, 12(%[p_x1_low]) \n\t" + "sw $0, 16(%[p_x1_low]) \n\t" + "sw $0, 20(%[p_x1_low]) \n\t" + "sw $0, 24(%[p_x1_low]) \n\t" + "sw $0, 28(%[p_x1_low]) \n\t" + "addiu %[p_x1_low], %[p_x1_low], 32 \n\t" + "bne %[p_x1_low], %[loop_end], 1b \n\t" + "addiu %[p_x1_low], %[p_x1_low], -10240 \n\t" + + : [p_x1_low]"+r"(p_x1_low) + : [loop_end]"r"(loop_end) + : "memory" + ); + + for (k = 0; k < sbr->kx[1]; k++) { + for (i = 0; i < 32; i+=4) { + /* loop unrolled 4 times */ + __asm__ volatile ( + "lw %[temp0], 0(%[p_w]) \n\t" + "lw %[temp1], 4(%[p_w]) \n\t" + "lw %[temp2], 256(%[p_w]) \n\t" + "lw %[temp3], 260(%[p_w]) \n\t" + "lw %[temp4], 512(%[p_w]) \n\t" + "lw %[temp5], 516(%[p_w]) \n\t" + "lw %[temp6], 768(%[p_w]) \n\t" + "lw %[temp7], 772(%[p_w]) \n\t" + "sw %[temp0], 0(%[p_x_low]) \n\t" + "sw %[temp1], 4(%[p_x_low]) \n\t" + "sw %[temp2], 8(%[p_x_low]) \n\t" + "sw %[temp3], 12(%[p_x_low]) \n\t" + "sw %[temp4], 16(%[p_x_low]) \n\t" + "sw %[temp5], 20(%[p_x_low]) \n\t" + "sw %[temp6], 24(%[p_x_low]) \n\t" + "sw %[temp7], 28(%[p_x_low]) \n\t" + "addiu %[p_x_low], %[p_x_low], 32 \n\t" + "addiu %[p_w], %[p_w], 1024 \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [p_w]"+r"(p_w), [p_x_low]"+r"(p_x_low) + : + : "memory" + ); + } + p_x_low += 16; + p_w -= 2046; + } + + for (k = 0; k < sbr->kx[0]; k++) { + for (i = 0; i < 2; i++) { + + /* loop unrolled 4 times */ + __asm__ volatile ( + "lw %[temp0], 0(%[p_w1]) \n\t" + "lw %[temp1], 4(%[p_w1]) \n\t" + "lw %[temp2], 256(%[p_w1]) \n\t" + "lw %[temp3], 260(%[p_w1]) \n\t" + "lw %[temp4], 512(%[p_w1]) \n\t" + "lw %[temp5], 516(%[p_w1]) \n\t" + "lw %[temp6], 768(%[p_w1]) \n\t" + "lw %[temp7], 772(%[p_w1]) \n\t" + "sw %[temp0], 0(%[p_x1_low]) \n\t" + "sw %[temp1], 4(%[p_x1_low]) \n\t" + "sw %[temp2], 8(%[p_x1_low]) \n\t" + "sw %[temp3], 12(%[p_x1_low]) \n\t" + "sw %[temp4], 16(%[p_x1_low]) \n\t" + "sw %[temp5], 20(%[p_x1_low]) \n\t" + "sw %[temp6], 24(%[p_x1_low]) \n\t" + "sw %[temp7], 28(%[p_x1_low]) \n\t" + "addiu %[p_x1_low], %[p_x1_low], 32 \n\t" + "addiu %[p_w1], %[p_w1], 1024 \n\t" + + : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), + [p_w1]"+r"(p_w1), [p_x1_low]"+r"(p_x1_low) + : + : "memory" + ); + } + p_x1_low += 64; + p_w1 -= 510; + } + return 0; +} + +static int sbr_x_gen_mips(SpectralBandReplication *sbr, float X[2][38][64], + const float Y0[38][64][2], const float Y1[38][64][2], + const float X_low[32][40][2], int ch) +{ + int k, i; + const int i_f = 32; + int temp0, temp1, temp2, temp3; + const float *X_low1, *Y01, *Y11; + float *x1=&X[0][0][0]; + float *j=x1+4864; + const int i_Temp = FFMAX(2*sbr->data[ch].t_env_num_env_old - i_f, 0); + + /* loop unrolled 8 times */ + __asm__ volatile ( + "1: \n\t" + "sw $0, 0(%[x1]) \n\t" + "sw $0, 4(%[x1]) \n\t" + "sw $0, 8(%[x1]) \n\t" + "sw $0, 12(%[x1]) \n\t" + "sw $0, 16(%[x1]) \n\t" + "sw $0, 20(%[x1]) \n\t" + "sw $0, 24(%[x1]) \n\t" + "sw $0, 28(%[x1]) \n\t" + "addiu %[x1], %[x1], 32 \n\t" + "bne %[x1], %[j], 1b \n\t" + "addiu %[x1], %[x1], -19456 \n\t" + + : [x1]"+r"(x1) + : [j]"r"(j) + : "memory" + ); + + if (i_Temp != 0) { + + X_low1=&X_low[0][2][0]; + + for (k = 0; k < sbr->kx[0]; k++) { + + __asm__ volatile ( + "move %[i], $zero \n\t" + "2: \n\t" + "lw %[temp0], 0(%[X_low1]) \n\t" + "lw %[temp1], 4(%[X_low1]) \n\t" + "sw %[temp0], 0(%[x1]) \n\t" + "sw %[temp1], 9728(%[x1]) \n\t" + "addiu %[x1], %[x1], 256 \n\t" + "addiu %[X_low1], %[X_low1], 8 \n\t" + "addiu %[i], %[i], 1 \n\t" + "bne %[i], %[i_Temp], 2b \n\t" + + : [x1]"+r"(x1), [X_low1]"+r"(X_low1), [i]"=&r"(i), + [temp0]"=&r"(temp0), [temp1]"=&r"(temp1) + : [i_Temp]"r"(i_Temp) + : "memory" + ); + x1-=(i_Temp<<6)-1; + X_low1-=(i_Temp<<1)-80; + } + + x1=&X[0][0][k]; + Y01=(float*)&Y0[32][k][0]; + + for (; k < sbr->kx[0] + sbr->m[0]; k++) { + __asm__ volatile ( + "move %[i], $zero \n\t" + "3: \n\t" + "lw %[temp0], 0(%[Y01]) \n\t" + "lw %[temp1], 4(%[Y01]) \n\t" + "sw %[temp0], 0(%[x1]) \n\t" + "sw %[temp1], 9728(%[x1]) \n\t" + "addiu %[x1], %[x1], 256 \n\t" + "addiu %[Y01], %[Y01], 512 \n\t" + "addiu %[i], %[i], 1 \n\t" + "bne %[i], %[i_Temp], 3b \n\t" + + : [x1]"+r"(x1), [Y01]"+r"(Y01), [i]"=&r"(i), + [temp0]"=&r"(temp0), [temp1]"=&r"(temp1) + : [i_Temp]"r"(i_Temp) + : "memory" + ); + x1 -=(i_Temp<<6)-1; + Y01 -=(i_Temp<<7)-2; + } + } + + x1=&X[0][i_Temp][0]; + X_low1=&X_low[0][i_Temp+2][0]; + temp3=38; + + for (k = 0; k < sbr->kx[1]; k++) { + + __asm__ volatile ( + "move %[i], %[i_Temp] \n\t" + "4: \n\t" + "lw %[temp0], 0(%[X_low1]) \n\t" + "lw %[temp1], 4(%[X_low1]) \n\t" + "sw %[temp0], 0(%[x1]) \n\t" + "sw %[temp1], 9728(%[x1]) \n\t" + "addiu %[x1], %[x1], 256 \n\t" + "addiu %[X_low1], %[X_low1], 8 \n\t" + "addiu %[i], %[i], 1 \n\t" + "bne %[i], %[temp3], 4b \n\t" + + : [x1]"+r"(x1), [X_low1]"+r"(X_low1), [i]"=&r"(i), + [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2) + : [i_Temp]"r"(i_Temp), [temp3]"r"(temp3) + : "memory" + ); + x1 -= ((38-i_Temp)<<6)-1; + X_low1 -= ((38-i_Temp)<<1)- 80; + } + + x1=&X[0][i_Temp][k]; + Y11=&Y1[i_Temp][k][0]; + temp2=32; + + for (; k < sbr->kx[1] + sbr->m[1]; k++) { + + __asm__ volatile ( + "move %[i], %[i_Temp] \n\t" + "5: \n\t" + "lw %[temp0], 0(%[Y11]) \n\t" + "lw %[temp1], 4(%[Y11]) \n\t" + "sw %[temp0], 0(%[x1]) \n\t" + "sw %[temp1], 9728(%[x1]) \n\t" + "addiu %[x1], %[x1], 256 \n\t" + "addiu %[Y11], %[Y11], 512 \n\t" + "addiu %[i], %[i], 1 \n\t" + "bne %[i], %[temp2], 5b \n\t" + + : [x1]"+r"(x1), [Y11]"+r"(Y11), [i]"=&r"(i), + [temp0]"=&r"(temp0), [temp1]"=&r"(temp1) + : [i_Temp]"r"(i_Temp), [temp3]"r"(temp3), + [temp2]"r"(temp2) + : "memory" + ); + + x1 -= ((32-i_Temp)<<6)-1; + Y11 -= ((32-i_Temp)<<7)-2; + } + return 0; +} + +#if HAVE_MIPSFPU +static void sbr_hf_assemble_mips(float Y1[38][64][2], + const float X_high[64][40][2], + SpectralBandReplication *sbr, SBRData *ch_data, + const int e_a[2]) +{ + int e, i, j, m; + const int h_SL = 4 * !sbr->bs_smoothing_mode; + const int kx = sbr->kx[1]; + const int m_max = sbr->m[1]; + static const float h_smooth[5] = { + 0.33333333333333, + 0.30150283239582, + 0.21816949906249, + 0.11516383427084, + 0.03183050093751, + }; + + float (*g_temp)[48] = ch_data->g_temp, (*q_temp)[48] = ch_data->q_temp; + int indexnoise = ch_data->f_indexnoise; + int indexsine = ch_data->f_indexsine; + float *g_temp1, *q_temp1, *pok, *pok1; + float temp1, temp2, temp3, temp4; + int size = m_max; + + if (sbr->reset) { + for (i = 0; i < h_SL; i++) { + memcpy(g_temp[i + 2*ch_data->t_env[0]], sbr->gain[0], m_max * sizeof(sbr->gain[0][0])); + memcpy(q_temp[i + 2*ch_data->t_env[0]], sbr->q_m[0], m_max * sizeof(sbr->q_m[0][0])); + } + } else if (h_SL) { + memcpy(g_temp[2*ch_data->t_env[0]], g_temp[2*ch_data->t_env_num_env_old], 4*sizeof(g_temp[0])); + memcpy(q_temp[2*ch_data->t_env[0]], q_temp[2*ch_data->t_env_num_env_old], 4*sizeof(q_temp[0])); + } + + for (e = 0; e < ch_data->bs_num_env; e++) { + for (i = 2 * ch_data->t_env[e]; i < 2 * ch_data->t_env[e + 1]; i++) { + g_temp1 = g_temp[h_SL + i]; + pok = sbr->gain[e]; + q_temp1 = q_temp[h_SL + i]; + pok1 = sbr->q_m[e]; + + /* loop unrolled 4 times */ + for (j=0; j<(size>>2); j++) { + __asm__ volatile ( + "lw %[temp1], 0(%[pok]) \n\t" + "lw %[temp2], 4(%[pok]) \n\t" + "lw %[temp3], 8(%[pok]) \n\t" + "lw %[temp4], 12(%[pok]) \n\t" + "sw %[temp1], 0(%[g_temp1]) \n\t" + "sw %[temp2], 4(%[g_temp1]) \n\t" + "sw %[temp3], 8(%[g_temp1]) \n\t" + "sw %[temp4], 12(%[g_temp1]) \n\t" + "lw %[temp1], 0(%[pok1]) \n\t" + "lw %[temp2], 4(%[pok1]) \n\t" + "lw %[temp3], 8(%[pok1]) \n\t" + "lw %[temp4], 12(%[pok1]) \n\t" + "sw %[temp1], 0(%[q_temp1]) \n\t" + "sw %[temp2], 4(%[q_temp1]) \n\t" + "sw %[temp3], 8(%[q_temp1]) \n\t" + "sw %[temp4], 12(%[q_temp1]) \n\t" + "addiu %[pok], %[pok], 16 \n\t" + "addiu %[g_temp1], %[g_temp1], 16 \n\t" + "addiu %[pok1], %[pok1], 16 \n\t" + "addiu %[q_temp1], %[q_temp1], 16 \n\t" + + : [temp1]"=&r"(temp1), [temp2]"=&r"(temp2), + [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), + [pok]"+r"(pok), [g_temp1]"+r"(g_temp1), + [pok1]"+r"(pok1), [q_temp1]"+r"(q_temp1) + : + : "memory" + ); + } + + for (j=0; j<(size&3); j++) { + __asm__ volatile ( + "lw %[temp1], 0(%[pok]) \n\t" + "lw %[temp2], 0(%[pok1]) \n\t" + "sw %[temp1], 0(%[g_temp1]) \n\t" + "sw %[temp2], 0(%[q_temp1]) \n\t" + "addiu %[pok], %[pok], 4 \n\t" + "addiu %[g_temp1], %[g_temp1], 4 \n\t" + "addiu %[pok1], %[pok1], 4 \n\t" + "addiu %[q_temp1], %[q_temp1], 4 \n\t" + + : [temp1]"=&r"(temp1), [temp2]"=&r"(temp2), + [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), + [pok]"+r"(pok), [g_temp1]"+r"(g_temp1), + [pok1]"+r"(pok1), [q_temp1]"+r"(q_temp1) + : + : "memory" + ); + } + } + } + + for (e = 0; e < ch_data->bs_num_env; e++) { + for (i = 2 * ch_data->t_env[e]; i < 2 * ch_data->t_env[e + 1]; i++) { + LOCAL_ALIGNED_16(float, g_filt_tab, [48]); + LOCAL_ALIGNED_16(float, q_filt_tab, [48]); + float *g_filt, *q_filt; + + if (h_SL && e != e_a[0] && e != e_a[1]) { + g_filt = g_filt_tab; + q_filt = q_filt_tab; + + for (m = 0; m < m_max; m++) { + const int idx1 = i + h_SL; + g_filt[m] = 0.0f; + q_filt[m] = 0.0f; + + for (j = 0; j <= h_SL; j++) { + g_filt[m] += g_temp[idx1 - j][m] * h_smooth[j]; + q_filt[m] += q_temp[idx1 - j][m] * h_smooth[j]; + } + } + } else { + g_filt = g_temp[i + h_SL]; + q_filt = q_temp[i]; + } + + sbr->dsp.hf_g_filt(Y1[i] + kx, X_high + kx, g_filt, m_max, + i + ENVELOPE_ADJUSTMENT_OFFSET); + + if (e != e_a[0] && e != e_a[1]) { + sbr->dsp.hf_apply_noise[indexsine](Y1[i] + kx, sbr->s_m[e], + q_filt, indexnoise, + kx, m_max); + } else { + int idx = indexsine&1; + int A = (1-((indexsine+(kx & 1))&2)); + int B = (A^(-idx)) + idx; + float *out = &Y1[i][kx][idx]; + float *in = sbr->s_m[e]; + float temp0, temp1, temp2, temp3, temp4, temp5; + float A_f = (float)A; + float B_f = (float)B; + + for (m = 0; m+1 < m_max; m+=2) { + + temp2 = out[0]; + temp3 = out[2]; + + __asm__ volatile( + "lwc1 %[temp0], 0(%[in]) \n\t" + "lwc1 %[temp1], 4(%[in]) \n\t" + "madd.s %[temp4], %[temp2], %[temp0], %[A_f] \n\t" + "madd.s %[temp5], %[temp3], %[temp1], %[B_f] \n\t" + "swc1 %[temp4], 0(%[out]) \n\t" + "swc1 %[temp5], 8(%[out]) \n\t" + "addiu %[in], %[in], 8 \n\t" + "addiu %[out], %[out], 16 \n\t" + + : [temp0]"=&f" (temp0), [temp1]"=&f"(temp1), + [temp4]"=&f" (temp4), [temp5]"=&f"(temp5), + [in]"+r"(in), [out]"+r"(out) + : [A_f]"f"(A_f), [B_f]"f"(B_f), [temp2]"f"(temp2), + [temp3]"f"(temp3) + : "memory" + ); + } + if(m_max&1) + out[2*m ] += in[m ] * A; + } + indexnoise = (indexnoise + m_max) & 0x1ff; + indexsine = (indexsine + 1) & 3; + } + } + ch_data->f_indexnoise = indexnoise; + ch_data->f_indexsine = indexsine; +} + +static void sbr_hf_inverse_filter_mips(SBRDSPContext *dsp, + float (*alpha0)[2], float (*alpha1)[2], + const float X_low[32][40][2], int k0) +{ + int k; + float temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, c; + float *phi1, *alpha_1, *alpha_0, res1, res2, temp_real, temp_im; + + c = 1.000001f; + + for (k = 0; k < k0; k++) { + LOCAL_ALIGNED_16(float, phi, [3], [2][2]); + float dk; + phi1 = &phi[0][0][0]; + alpha_1 = &alpha1[k][0]; + alpha_0 = &alpha0[k][0]; + dsp->autocorrelate(X_low[k], phi); + + __asm__ volatile ( + "lwc1 %[temp0], 40(%[phi1]) \n\t" + "lwc1 %[temp1], 16(%[phi1]) \n\t" + "lwc1 %[temp2], 24(%[phi1]) \n\t" + "lwc1 %[temp3], 28(%[phi1]) \n\t" + "mul.s %[dk], %[temp0], %[temp1] \n\t" + "lwc1 %[temp4], 0(%[phi1]) \n\t" + "mul.s %[res2], %[temp2], %[temp2] \n\t" + "lwc1 %[temp5], 4(%[phi1]) \n\t" + "madd.s %[res2], %[res2], %[temp3], %[temp3] \n\t" + "lwc1 %[temp6], 8(%[phi1]) \n\t" + "div.s %[res2], %[res2], %[c] \n\t" + "lwc1 %[temp0], 12(%[phi1]) \n\t" + "sub.s %[dk], %[dk], %[res2] \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&f"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [temp6]"=&f"(temp6), [res2]"=&f"(res2), [dk]"=&f"(dk) + : [phi1]"r"(phi1), [c]"f"(c) + : "memory" + ); + + if (!dk) { + alpha_1[0] = 0; + alpha_1[1] = 0; + } else { + __asm__ volatile ( + "mul.s %[temp_real], %[temp4], %[temp2] \n\t" + "nmsub.s %[temp_real], %[temp_real], %[temp5], %[temp3] \n\t" + "nmsub.s %[temp_real], %[temp_real], %[temp6], %[temp1] \n\t" + "mul.s %[temp_im], %[temp4], %[temp3] \n\t" + "madd.s %[temp_im], %[temp_im], %[temp5], %[temp2] \n\t" + "nmsub.s %[temp_im], %[temp_im], %[temp0], %[temp1] \n\t" + "div.s %[temp_real], %[temp_real], %[dk] \n\t" + "div.s %[temp_im], %[temp_im], %[dk] \n\t" + "swc1 %[temp_real], 0(%[alpha_1]) \n\t" + "swc1 %[temp_im], 4(%[alpha_1]) \n\t" + + : [temp_real]"=&f" (temp_real), [temp_im]"=&f"(temp_im) + : [phi1]"r"(phi1), [temp0]"f"(temp0), [temp1]"f"(temp1), + [temp2]"f"(temp2), [temp3]"f"(temp3), [temp4]"f"(temp4), + [temp5]"f"(temp5), [temp6]"f"(temp6), + [alpha_1]"r"(alpha_1), [dk]"f"(dk) + : "memory" + ); + } + + if (!phi1[4]) { + alpha_0[0] = 0; + alpha_0[1] = 0; + } else { + __asm__ volatile ( + "lwc1 %[temp6], 0(%[alpha_1]) \n\t" + "lwc1 %[temp7], 4(%[alpha_1]) \n\t" + "mul.s %[temp_real], %[temp6], %[temp2] \n\t" + "add.s %[temp_real], %[temp_real], %[temp4] \n\t" + "madd.s %[temp_real], %[temp_real], %[temp7], %[temp3] \n\t" + "mul.s %[temp_im], %[temp7], %[temp2] \n\t" + "add.s %[temp_im], %[temp_im], %[temp5] \n\t" + "nmsub.s %[temp_im], %[temp_im], %[temp6], %[temp3] \n\t" + "div.s %[temp_real], %[temp_real], %[temp1] \n\t" + "div.s %[temp_im], %[temp_im], %[temp1] \n\t" + "neg.s %[temp_real], %[temp_real] \n\t" + "neg.s %[temp_im], %[temp_im] \n\t" + "swc1 %[temp_real], 0(%[alpha_0]) \n\t" + "swc1 %[temp_im], 4(%[alpha_0]) \n\t" + + : [temp_real]"=&f"(temp_real), [temp_im]"=&f"(temp_im), + [temp6]"=&f"(temp6), [temp7]"=&f"(temp7), + [res1]"=&f"(res1), [res2]"=&f"(res2) + : [alpha_1]"r"(alpha_1), [alpha_0]"r"(alpha_0), + [temp0]"f"(temp0), [temp1]"f"(temp1), [temp2]"f"(temp2), + [temp3]"f"(temp3), [temp4]"f"(temp4), [temp5]"f"(temp5) + : "memory" + ); + } + + __asm__ volatile ( + "lwc1 %[temp1], 0(%[alpha_1]) \n\t" + "lwc1 %[temp2], 4(%[alpha_1]) \n\t" + "lwc1 %[temp_real], 0(%[alpha_0]) \n\t" + "lwc1 %[temp_im], 4(%[alpha_0]) \n\t" + "mul.s %[res1], %[temp1], %[temp1] \n\t" + "madd.s %[res1], %[res1], %[temp2], %[temp2] \n\t" + "mul.s %[res2], %[temp_real], %[temp_real] \n\t" + "madd.s %[res2], %[res2], %[temp_im], %[temp_im] \n\t" + + : [temp_real]"=&f"(temp_real), [temp_im]"=&f"(temp_im), + [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [res1]"=&f"(res1), [res2]"=&f"(res2) + : [alpha_1]"r"(alpha_1), [alpha_0]"r"(alpha_0) + : "memory" + ); + + if (res1 >= 16.0f || res2 >= 16.0f) { + alpha_1[0] = 0; + alpha_1[1] = 0; + alpha_0[0] = 0; + alpha_0[1] = 0; + } + } +} +#endif /* HAVE_MIPSFPU */ +#endif /* HAVE_INLINE_ASM */ + +void ff_aacsbr_func_ptr_init_mips(AACSBRContext *c) +{ +#if HAVE_INLINE_ASM + c->sbr_lf_gen = sbr_lf_gen_mips; + c->sbr_x_gen = sbr_x_gen_mips; +#if HAVE_MIPSFPU + c->sbr_hf_inverse_filter = sbr_hf_inverse_filter_mips; + c->sbr_hf_assemble = sbr_hf_assemble_mips; +#endif /* HAVE_MIPSFPU */ +#endif /* HAVE_INLINE_ASM */ +} diff --git a/mythtv/external/FFmpeg/libavcodec/mips/aacsbr_mips.h b/mythtv/external/FFmpeg/libavcodec/mips/aacsbr_mips.h new file mode 100644 index 00000000000..8e6ad7d839f --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/mips/aacsbr_mips.h @@ -0,0 +1,493 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Authors: Djordje Pesut (djordje@mips.com) + * Mirjana Vulin (mvulin@mips.com) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Reference: libavcodec/aacsbr.c + */ + +#ifndef AVCODEC_MIPS_AACSBR_FLOAT_H +#define AVCODEC_MIPS_AACSBR_FLOAT_H + +#include "libavcodec/aac.h" +#include "libavcodec/sbr.h" + +#if HAVE_INLINE_ASM +static void sbr_qmf_analysis_mips(AVFloatDSPContext *fdsp, FFTContext *mdct, + SBRDSPContext *sbrdsp, const float *in, float *x, + float z[320], float W[2][32][32][2], int buf_idx) +{ + int i; + float *w0; + float *w1; + int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7; + + w0 = x; + w1 = x + 1024; + for(i = 0; i < 36; i++) + { + /* loop unrolled 8 times */ + __asm__ volatile( + "lw %[temp0], 0(%[w1]) \n\t" + "lw %[temp1], 4(%[w1]) \n\t" + "lw %[temp2], 8(%[w1]) \n\t" + "lw %[temp3], 12(%[w1]) \n\t" + "lw %[temp4], 16(%[w1]) \n\t" + "lw %[temp5], 20(%[w1]) \n\t" + "lw %[temp6], 24(%[w1]) \n\t" + "lw %[temp7], 28(%[w1]) \n\t" + "sw %[temp0], 0(%[w0]) \n\t" + "sw %[temp1], 4(%[w0]) \n\t" + "sw %[temp2], 8(%[w0]) \n\t" + "sw %[temp3], 12(%[w0]) \n\t" + "sw %[temp4], 16(%[w0]) \n\t" + "sw %[temp5], 20(%[w0]) \n\t" + "sw %[temp6], 24(%[w0]) \n\t" + "sw %[temp7], 28(%[w0]) \n\t" + "addiu %[w0], %[w0], 32 \n\t" + "addiu %[w1], %[w1], 32 \n\t" + + : [w0]"+r"(w0), [w1]"+r"(w1), + [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7) + : + : "memory" + ); + } + + w0 = x + 288; + w1 = (float*)in; + for(i = 0; i < 128; i++) + { + /* loop unrolled 8 times */ + __asm__ volatile( + "lw %[temp0], 0(%[w1]) \n\t" + "lw %[temp1], 4(%[w1]) \n\t" + "lw %[temp2], 8(%[w1]) \n\t" + "lw %[temp3], 12(%[w1]) \n\t" + "lw %[temp4], 16(%[w1]) \n\t" + "lw %[temp5], 20(%[w1]) \n\t" + "lw %[temp6], 24(%[w1]) \n\t" + "lw %[temp7], 28(%[w1]) \n\t" + "sw %[temp0], 0(%[w0]) \n\t" + "sw %[temp1], 4(%[w0]) \n\t" + "sw %[temp2], 8(%[w0]) \n\t" + "sw %[temp3], 12(%[w0]) \n\t" + "sw %[temp4], 16(%[w0]) \n\t" + "sw %[temp5], 20(%[w0]) \n\t" + "sw %[temp6], 24(%[w0]) \n\t" + "sw %[temp7], 28(%[w0]) \n\t" + "addiu %[w0], %[w0], 32 \n\t" + "addiu %[w1], %[w1], 32 \n\t" + + : [w0]"+r"(w0), [w1]"+r"(w1), + [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), + [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), + [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), + [temp6]"=&r"(temp6), [temp7]"=&r"(temp7) + : + : "memory" + ); + } + + for (i = 0; i < 32; i++) { // numTimeSlots*RATE = 16*2 as 960 sample frames + // are not supported + fdsp->vector_fmul_reverse(z, sbr_qmf_window_ds, x, 320); + sbrdsp->sum64x5(z); + sbrdsp->qmf_pre_shuffle(z); + mdct->imdct_half(mdct, z, z+64); + sbrdsp->qmf_post_shuffle(W[buf_idx][i], z); + x += 32; + } +} + +#if HAVE_MIPSFPU +static void sbr_qmf_synthesis_mips(FFTContext *mdct, + SBRDSPContext *sbrdsp, AVFloatDSPContext *fdsp, + float *out, float X[2][38][64], + float mdct_buf[2][64], + float *v0, int *v_off, const unsigned int div) +{ + int i, n; + const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us; + const int step = 128 >> div; + float *v; + float temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10, temp11, temp12, temp13; + float temp14, temp15, temp16, temp17, temp18, temp19; + float *vv0, *s0, *dst; + dst = out; + + for (i = 0; i < 32; i++) { + if (*v_off < step) { + int saved_samples = (1280 - 128) >> div; + memcpy(&v0[SBR_SYNTHESIS_BUF_SIZE - saved_samples], v0, saved_samples * sizeof(float)); + *v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - step; + } else { + *v_off -= step; + } + v = v0 + *v_off; + if (div) { + for (n = 0; n < 32; n++) { + X[0][i][ n] = -X[0][i][n]; + X[0][i][32+n] = X[1][i][31-n]; + } + mdct->imdct_half(mdct, mdct_buf[0], X[0][i]); + sbrdsp->qmf_deint_neg(v, mdct_buf[0]); + } else { + sbrdsp->neg_odd_64(X[1][i]); + mdct->imdct_half(mdct, mdct_buf[0], X[0][i]); + mdct->imdct_half(mdct, mdct_buf[1], X[1][i]); + sbrdsp->qmf_deint_bfly(v, mdct_buf[1], mdct_buf[0]); + } + + if(div == 0) + { + float *v0_end; + vv0 = v; + v0_end = v + 60; + s0 = (float*)sbr_qmf_window; + + /* 10 calls of function vector_fmul_add merged into one loop + and loop unrolled 4 times */ + __asm__ volatile( + ".set push \n\t" + ".set noreorder \n\t" + "lwc1 %[temp4], 0(%[v0]) \n\t" + "lwc1 %[temp5], 0(%[s0]) \n\t" + "lwc1 %[temp6], 4(%[v0]) \n\t" + "lwc1 %[temp7], 4(%[s0]) \n\t" + "lwc1 %[temp8], 8(%[v0]) \n\t" + "lwc1 %[temp9], 8(%[s0]) \n\t" + "lwc1 %[temp10], 12(%[v0]) \n\t" + "lwc1 %[temp11], 12(%[s0]) \n\t" + "lwc1 %[temp12], 768(%[v0]) \n\t" + "lwc1 %[temp13], 256(%[s0]) \n\t" + "lwc1 %[temp14], 772(%[v0]) \n\t" + "lwc1 %[temp15], 260(%[s0]) \n\t" + "lwc1 %[temp16], 776(%[v0]) \n\t" + "lwc1 %[temp17], 264(%[s0]) \n\t" + "lwc1 %[temp18], 780(%[v0]) \n\t" + "lwc1 %[temp19], 268(%[s0]) \n\t" + "1: \n\t" + "mul.s %[temp0], %[temp4], %[temp5] \n\t" + "lwc1 %[temp4], 1024(%[v0]) \n\t" + "mul.s %[temp1], %[temp6], %[temp7] \n\t" + "lwc1 %[temp5], 512(%[s0]) \n\t" + "mul.s %[temp2], %[temp8], %[temp9] \n\t" + "lwc1 %[temp6], 1028(%[v0]) \n\t" + "mul.s %[temp3], %[temp10], %[temp11] \n\t" + "lwc1 %[temp7], 516(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp12], %[temp13] \n\t" + "lwc1 %[temp8], 1032(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp14], %[temp15] \n\t" + "lwc1 %[temp9], 520(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp16], %[temp17] \n\t" + "lwc1 %[temp10], 1036(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp18], %[temp19] \n\t" + "lwc1 %[temp11], 524(%[s0]) \n\t" + "lwc1 %[temp12], 1792(%[v0]) \n\t" + "lwc1 %[temp13], 768(%[s0]) \n\t" + "lwc1 %[temp14], 1796(%[v0]) \n\t" + "lwc1 %[temp15], 772(%[s0]) \n\t" + "lwc1 %[temp16], 1800(%[v0]) \n\t" + "lwc1 %[temp17], 776(%[s0]) \n\t" + "lwc1 %[temp18], 1804(%[v0]) \n\t" + "lwc1 %[temp19], 780(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp4], %[temp5] \n\t" + "lwc1 %[temp4], 2048(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp6], %[temp7] \n\t" + "lwc1 %[temp5], 1024(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp8], %[temp9] \n\t" + "lwc1 %[temp6], 2052(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp10], %[temp11] \n\t" + "lwc1 %[temp7], 1028(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp12], %[temp13] \n\t" + "lwc1 %[temp8], 2056(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp14], %[temp15] \n\t" + "lwc1 %[temp9], 1032(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp16], %[temp17] \n\t" + "lwc1 %[temp10], 2060(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp18], %[temp19] \n\t" + "lwc1 %[temp11], 1036(%[s0]) \n\t" + "lwc1 %[temp12], 2816(%[v0]) \n\t" + "lwc1 %[temp13], 1280(%[s0]) \n\t" + "lwc1 %[temp14], 2820(%[v0]) \n\t" + "lwc1 %[temp15], 1284(%[s0]) \n\t" + "lwc1 %[temp16], 2824(%[v0]) \n\t" + "lwc1 %[temp17], 1288(%[s0]) \n\t" + "lwc1 %[temp18], 2828(%[v0]) \n\t" + "lwc1 %[temp19], 1292(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp4], %[temp5] \n\t" + "lwc1 %[temp4], 3072(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp6], %[temp7] \n\t" + "lwc1 %[temp5], 1536(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp8], %[temp9] \n\t" + "lwc1 %[temp6], 3076(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp10], %[temp11] \n\t" + "lwc1 %[temp7], 1540(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp12], %[temp13] \n\t" + "lwc1 %[temp8], 3080(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp14], %[temp15] \n\t" + "lwc1 %[temp9], 1544(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp16], %[temp17] \n\t" + "lwc1 %[temp10], 3084(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp18], %[temp19] \n\t" + "lwc1 %[temp11], 1548(%[s0]) \n\t" + "lwc1 %[temp12], 3840(%[v0]) \n\t" + "lwc1 %[temp13], 1792(%[s0]) \n\t" + "lwc1 %[temp14], 3844(%[v0]) \n\t" + "lwc1 %[temp15], 1796(%[s0]) \n\t" + "lwc1 %[temp16], 3848(%[v0]) \n\t" + "lwc1 %[temp17], 1800(%[s0]) \n\t" + "lwc1 %[temp18], 3852(%[v0]) \n\t" + "lwc1 %[temp19], 1804(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp4], %[temp5] \n\t" + "lwc1 %[temp4], 4096(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp6], %[temp7] \n\t" + "lwc1 %[temp5], 2048(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp8], %[temp9] \n\t" + "lwc1 %[temp6], 4100(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp10], %[temp11] \n\t" + "lwc1 %[temp7], 2052(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp12], %[temp13] \n\t" + "lwc1 %[temp8], 4104(%[v0]) \n\t" + "addiu %[dst], %[dst], 16 \n\t" + "madd.s %[temp1], %[temp1], %[temp14], %[temp15] \n\t" + "lwc1 %[temp9], 2056(%[s0]) \n\t" + "addiu %[s0], %[s0], 16 \n\t" + "madd.s %[temp2], %[temp2], %[temp16], %[temp17] \n\t" + "lwc1 %[temp10], 4108(%[v0]) \n\t" + "addiu %[v0], %[v0], 16 \n\t" + "madd.s %[temp3], %[temp3], %[temp18], %[temp19] \n\t" + "lwc1 %[temp11], 2044(%[s0]) \n\t" + "lwc1 %[temp12], 4848(%[v0]) \n\t" + "lwc1 %[temp13], 2288(%[s0]) \n\t" + "lwc1 %[temp14], 4852(%[v0]) \n\t" + "lwc1 %[temp15], 2292(%[s0]) \n\t" + "lwc1 %[temp16], 4856(%[v0]) \n\t" + "lwc1 %[temp17], 2296(%[s0]) \n\t" + "lwc1 %[temp18], 4860(%[v0]) \n\t" + "lwc1 %[temp19], 2300(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp4], %[temp5] \n\t" + "lwc1 %[temp4], 0(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp6], %[temp7] \n\t" + "lwc1 %[temp5], 0(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp8], %[temp9] \n\t" + "lwc1 %[temp6], 4(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp10], %[temp11] \n\t" + "lwc1 %[temp7], 4(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp12], %[temp13] \n\t" + "lwc1 %[temp8], 8(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp14], %[temp15] \n\t" + "lwc1 %[temp9], 8(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp16], %[temp17] \n\t" + "lwc1 %[temp10], 12(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp18], %[temp19] \n\t" + "lwc1 %[temp11], 12(%[s0]) \n\t" + "lwc1 %[temp12], 768(%[v0]) \n\t" + "lwc1 %[temp13], 256(%[s0]) \n\t" + "lwc1 %[temp14], 772(%[v0]) \n\t" + "lwc1 %[temp15], 260(%[s0]) \n\t" + "lwc1 %[temp16], 776(%[v0]) \n\t" + "lwc1 %[temp17], 264(%[s0]) \n\t" + "lwc1 %[temp18], 780(%[v0]) \n\t" + "lwc1 %[temp19], 268(%[s0]) \n\t" + "swc1 %[temp0], -16(%[dst]) \n\t" + "swc1 %[temp1], -12(%[dst]) \n\t" + "swc1 %[temp2], -8(%[dst]) \n\t" + "bne %[v0], %[v0_end], 1b \n\t" + " swc1 %[temp3], -4(%[dst]) \n\t" + "mul.s %[temp0], %[temp4], %[temp5] \n\t" + "lwc1 %[temp4], 1024(%[v0]) \n\t" + "mul.s %[temp1], %[temp6], %[temp7] \n\t" + "lwc1 %[temp5], 512(%[s0]) \n\t" + "mul.s %[temp2], %[temp8], %[temp9] \n\t" + "lwc1 %[temp6], 1028(%[v0]) \n\t" + "mul.s %[temp3], %[temp10], %[temp11] \n\t" + "lwc1 %[temp7], 516(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp12], %[temp13] \n\t" + "lwc1 %[temp8], 1032(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp14], %[temp15] \n\t" + "lwc1 %[temp9], 520(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp16], %[temp17] \n\t" + "lwc1 %[temp10], 1036(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp18], %[temp19] \n\t" + "lwc1 %[temp11], 524(%[s0]) \n\t" + "lwc1 %[temp12], 1792(%[v0]) \n\t" + "lwc1 %[temp13], 768(%[s0]) \n\t" + "lwc1 %[temp14], 1796(%[v0]) \n\t" + "lwc1 %[temp15], 772(%[s0]) \n\t" + "lwc1 %[temp16], 1800(%[v0]) \n\t" + "lwc1 %[temp17], 776(%[s0]) \n\t" + "lwc1 %[temp18], 1804(%[v0]) \n\t" + "lwc1 %[temp19], 780(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp4], %[temp5] \n\t" + "lwc1 %[temp4], 2048(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp6], %[temp7] \n\t" + "lwc1 %[temp5], 1024(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp8], %[temp9] \n\t" + "lwc1 %[temp6], 2052(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp10], %[temp11] \n\t" + "lwc1 %[temp7], 1028(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp12], %[temp13] \n\t" + "lwc1 %[temp8], 2056(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp14], %[temp15] \n\t" + "lwc1 %[temp9], 1032(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp16], %[temp17] \n\t" + "lwc1 %[temp10], 2060(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp18], %[temp19] \n\t" + "lwc1 %[temp11], 1036(%[s0]) \n\t" + "lwc1 %[temp12], 2816(%[v0]) \n\t" + "lwc1 %[temp13], 1280(%[s0]) \n\t" + "lwc1 %[temp14], 2820(%[v0]) \n\t" + "lwc1 %[temp15], 1284(%[s0]) \n\t" + "lwc1 %[temp16], 2824(%[v0]) \n\t" + "lwc1 %[temp17], 1288(%[s0]) \n\t" + "lwc1 %[temp18], 2828(%[v0]) \n\t" + "lwc1 %[temp19], 1292(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp4], %[temp5] \n\t" + "lwc1 %[temp4], 3072(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp6], %[temp7] \n\t" + "lwc1 %[temp5], 1536(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp8], %[temp9] \n\t" + "lwc1 %[temp6], 3076(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp10], %[temp11] \n\t" + "lwc1 %[temp7], 1540(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp12], %[temp13] \n\t" + "lwc1 %[temp8], 3080(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp14], %[temp15] \n\t" + "lwc1 %[temp9], 1544(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp16], %[temp17] \n\t" + "lwc1 %[temp10], 3084(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp18], %[temp19] \n\t" + "lwc1 %[temp11], 1548(%[s0]) \n\t" + "lwc1 %[temp12], 3840(%[v0]) \n\t" + "lwc1 %[temp13], 1792(%[s0]) \n\t" + "lwc1 %[temp14], 3844(%[v0]) \n\t" + "lwc1 %[temp15], 1796(%[s0]) \n\t" + "lwc1 %[temp16], 3848(%[v0]) \n\t" + "lwc1 %[temp17], 1800(%[s0]) \n\t" + "lwc1 %[temp18], 3852(%[v0]) \n\t" + "lwc1 %[temp19], 1804(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp4], %[temp5] \n\t" + "lwc1 %[temp4], 4096(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp6], %[temp7] \n\t" + "lwc1 %[temp5], 2048(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp8], %[temp9] \n\t" + "lwc1 %[temp6], 4100(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp10], %[temp11] \n\t" + "lwc1 %[temp7], 2052(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp12], %[temp13] \n\t" + "lwc1 %[temp8], 4104(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp14], %[temp15] \n\t" + "lwc1 %[temp9], 2056(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp16], %[temp17] \n\t" + "lwc1 %[temp10], 4108(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp18], %[temp19] \n\t" + "lwc1 %[temp11], 2060(%[s0]) \n\t" + "lwc1 %[temp12], 4864(%[v0]) \n\t" + "lwc1 %[temp13], 2304(%[s0]) \n\t" + "lwc1 %[temp14], 4868(%[v0]) \n\t" + "lwc1 %[temp15], 2308(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp4], %[temp5] \n\t" + "lwc1 %[temp16], 4872(%[v0]) \n\t" + "madd.s %[temp1], %[temp1], %[temp6], %[temp7] \n\t" + "lwc1 %[temp17], 2312(%[s0]) \n\t" + "madd.s %[temp2], %[temp2], %[temp8], %[temp9] \n\t" + "lwc1 %[temp18], 4876(%[v0]) \n\t" + "madd.s %[temp3], %[temp3], %[temp10], %[temp11] \n\t" + "lwc1 %[temp19], 2316(%[s0]) \n\t" + "madd.s %[temp0], %[temp0], %[temp12], %[temp13] \n\t" + "addiu %[dst], %[dst], 16 \n\t" + "madd.s %[temp1], %[temp1], %[temp14], %[temp15] \n\t" + "madd.s %[temp2], %[temp2], %[temp16], %[temp17] \n\t" + "madd.s %[temp3], %[temp3], %[temp18], %[temp19] \n\t" + "swc1 %[temp0], -16(%[dst]) \n\t" + "swc1 %[temp1], -12(%[dst]) \n\t" + "swc1 %[temp2], -8(%[dst]) \n\t" + "swc1 %[temp3], -4(%[dst]) \n\t" + ".set pop \n\t" + + : [dst]"+r"(dst), [v0]"+r"(vv0), [s0]"+r"(s0), + [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&f"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [temp6]"=&f"(temp6), [temp7]"=&f"(temp7), [temp8]"=&f"(temp8), + [temp9]"=&f"(temp9), [temp10]"=&f"(temp10), [temp11]"=&f"(temp11), + [temp12]"=&f"(temp12), [temp13]"=&f"(temp13), [temp14]"=&f"(temp14), + [temp15]"=&f"(temp15), [temp16]"=&f"(temp16), [temp17]"=&f"(temp17), + [temp18]"=&f"(temp18), [temp19]"=&f"(temp19) + : [v0_end]"r"(v0_end) + : "memory" + ); + } + else + { + fdsp->vector_fmul (out, v , sbr_qmf_window , 64 >> div); + fdsp->vector_fmul_add(out, v + ( 192 >> div), sbr_qmf_window + ( 64 >> div), out , 64 >> div); + fdsp->vector_fmul_add(out, v + ( 256 >> div), sbr_qmf_window + (128 >> div), out , 64 >> div); + fdsp->vector_fmul_add(out, v + ( 448 >> div), sbr_qmf_window + (192 >> div), out , 64 >> div); + fdsp->vector_fmul_add(out, v + ( 512 >> div), sbr_qmf_window + (256 >> div), out , 64 >> div); + fdsp->vector_fmul_add(out, v + ( 704 >> div), sbr_qmf_window + (320 >> div), out , 64 >> div); + fdsp->vector_fmul_add(out, v + ( 768 >> div), sbr_qmf_window + (384 >> div), out , 64 >> div); + fdsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div); + fdsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div); + fdsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div); + out += 64 >> div; + } + } +} + +#define sbr_qmf_analysis sbr_qmf_analysis_mips +#define sbr_qmf_synthesis sbr_qmf_synthesis_mips + +#endif /* HAVE_MIPSFPU */ +#endif /* HAVE_INLINE_ASM */ + +#endif /* AVCODEC_MIPS_AACSBR_FLOAT_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/mips/dsputil_mips.c b/mythtv/external/FFmpeg/libavcodec/mips/dsputil_mips.c deleted file mode 100644 index 76dc664e608..00000000000 --- a/mythtv/external/FFmpeg/libavcodec/mips/dsputil_mips.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2012 - * MIPS Technologies, Inc., California. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the MIPS Technologies, Inc., nor the names of is - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Author: Zoran Lukic (zoranl@mips.com) - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "config.h" -#include "libavcodec/dsputil.h" - -#if HAVE_INLINE_ASM -static void vector_fmul_window_mips(float *dst, const float *src0, - const float *src1, const float *win, int len) -{ - int i, j; - /* - * variables used in inline assembler - */ - float * dst_i, * dst_j, * dst_i2, * dst_j2; - float temp, temp1, temp2, temp3, temp4, temp5, temp6, temp7; - - dst += len; - win += len; - src0 += len; - - for (i = -len, j = len - 1; i < 0; i += 8, j -= 8) { - - dst_i = dst + i; - dst_j = dst + j; - - dst_i2 = dst + i + 4; - dst_j2 = dst + j - 4; - - __asm__ volatile ( - "mul.s %[temp], %[s1], %[wi] \n\t" - "mul.s %[temp1], %[s1], %[wj] \n\t" - "mul.s %[temp2], %[s11], %[wi1] \n\t" - "mul.s %[temp3], %[s11], %[wj1] \n\t" - - "msub.s %[temp], %[temp], %[s0], %[wj] \n\t" - "madd.s %[temp1], %[temp1], %[s0], %[wi] \n\t" - "msub.s %[temp2], %[temp2], %[s01], %[wj1] \n\t" - "madd.s %[temp3], %[temp3], %[s01], %[wi1] \n\t" - - "swc1 %[temp], 0(%[dst_i]) \n\t" /* dst[i] = s0*wj - s1*wi; */ - "swc1 %[temp1], 0(%[dst_j]) \n\t" /* dst[j] = s0*wi + s1*wj; */ - "swc1 %[temp2], 4(%[dst_i]) \n\t" /* dst[i+1] = s01*wj1 - s11*wi1; */ - "swc1 %[temp3], -4(%[dst_j]) \n\t" /* dst[j-1] = s01*wi1 + s11*wj1; */ - - "mul.s %[temp4], %[s12], %[wi2] \n\t" - "mul.s %[temp5], %[s12], %[wj2] \n\t" - "mul.s %[temp6], %[s13], %[wi3] \n\t" - "mul.s %[temp7], %[s13], %[wj3] \n\t" - - "msub.s %[temp4], %[temp4], %[s02], %[wj2] \n\t" - "madd.s %[temp5], %[temp5], %[s02], %[wi2] \n\t" - "msub.s %[temp6], %[temp6], %[s03], %[wj3] \n\t" - "madd.s %[temp7], %[temp7], %[s03], %[wi3] \n\t" - - "swc1 %[temp4], 8(%[dst_i]) \n\t" /* dst[i+2] = s02*wj2 - s12*wi2; */ - "swc1 %[temp5], -8(%[dst_j]) \n\t" /* dst[j-2] = s02*wi2 + s12*wj2; */ - "swc1 %[temp6], 12(%[dst_i]) \n\t" /* dst[i+2] = s03*wj3 - s13*wi3; */ - "swc1 %[temp7], -12(%[dst_j]) \n\t" /* dst[j-3] = s03*wi3 + s13*wj3; */ - : [temp]"=&f"(temp), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), - [temp3]"=&f"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), - [temp6]"=&f"(temp6), [temp7]"=&f"(temp7) - : [dst_j]"r"(dst_j), [dst_i]"r" (dst_i), - [s0] "f"(src0[i]), [wj] "f"(win[j]), [s1] "f"(src1[j]), - [wi] "f"(win[i]), [s01]"f"(src0[i + 1]),[wj1]"f"(win[j - 1]), - [s11]"f"(src1[j - 1]), [wi1]"f"(win[i + 1]), [s02]"f"(src0[i + 2]), - [wj2]"f"(win[j - 2]), [s12]"f"(src1[j - 2]),[wi2]"f"(win[i + 2]), - [s03]"f"(src0[i + 3]), [wj3]"f"(win[j - 3]), [s13]"f"(src1[j - 3]), - [wi3]"f"(win[i + 3]) - : "memory" - ); - - __asm__ volatile ( - "mul.s %[temp], %[s1], %[wi] \n\t" - "mul.s %[temp1], %[s1], %[wj] \n\t" - "mul.s %[temp2], %[s11], %[wi1] \n\t" - "mul.s %[temp3], %[s11], %[wj1] \n\t" - - "msub.s %[temp], %[temp], %[s0], %[wj] \n\t" - "madd.s %[temp1], %[temp1], %[s0], %[wi] \n\t" - "msub.s %[temp2], %[temp2], %[s01], %[wj1] \n\t" - "madd.s %[temp3], %[temp3], %[s01], %[wi1] \n\t" - - "swc1 %[temp], 0(%[dst_i2]) \n\t" /* dst[i] = s0*wj - s1*wi; */ - "swc1 %[temp1], 0(%[dst_j2]) \n\t" /* dst[j] = s0*wi + s1*wj; */ - "swc1 %[temp2], 4(%[dst_i2]) \n\t" /* dst[i+1] = s01*wj1 - s11*wi1; */ - "swc1 %[temp3], -4(%[dst_j2]) \n\t" /* dst[j-1] = s01*wi1 + s11*wj1; */ - - "mul.s %[temp4], %[s12], %[wi2] \n\t" - "mul.s %[temp5], %[s12], %[wj2] \n\t" - "mul.s %[temp6], %[s13], %[wi3] \n\t" - "mul.s %[temp7], %[s13], %[wj3] \n\t" - - "msub.s %[temp4], %[temp4], %[s02], %[wj2] \n\t" - "madd.s %[temp5], %[temp5], %[s02], %[wi2] \n\t" - "msub.s %[temp6], %[temp6], %[s03], %[wj3] \n\t" - "madd.s %[temp7], %[temp7], %[s03], %[wi3] \n\t" - - "swc1 %[temp4], 8(%[dst_i2]) \n\t" /* dst[i+2] = s02*wj2 - s12*wi2; */ - "swc1 %[temp5], -8(%[dst_j2]) \n\t" /* dst[j-2] = s02*wi2 + s12*wj2; */ - "swc1 %[temp6], 12(%[dst_i2]) \n\t" /* dst[i+2] = s03*wj3 - s13*wi3; */ - "swc1 %[temp7], -12(%[dst_j2]) \n\t" /* dst[j-3] = s03*wi3 + s13*wj3; */ - : [temp]"=&f"(temp), - [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), [temp3]"=&f"(temp3), - [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), [temp6]"=&f"(temp6), - [temp7] "=&f" (temp7) - : [dst_j2]"r"(dst_j2), [dst_i2]"r"(dst_i2), - [s0] "f"(src0[i + 4]), [wj] "f"(win[j - 4]), [s1] "f"(src1[j - 4]), - [wi] "f"(win[i + 4]), [s01]"f"(src0[i + 5]),[wj1]"f"(win[j - 5]), - [s11]"f"(src1[j - 5]), [wi1]"f"(win[i + 5]), [s02]"f"(src0[i + 6]), - [wj2]"f"(win[j - 6]), [s12]"f"(src1[j - 6]),[wi2]"f"(win[i + 6]), - [s03]"f"(src0[i + 7]), [wj3]"f"(win[j - 7]), [s13]"f"(src1[j - 7]), - [wi3]"f"(win[i + 7]) - : "memory" - ); - } -} -#endif /* HAVE_INLINE_ASM */ - -av_cold void ff_dsputil_init_mips( DSPContext* c, AVCodecContext *avctx ) -{ -#if HAVE_INLINE_ASM - c->vector_fmul_window = vector_fmul_window_mips; -#endif -} diff --git a/mythtv/external/FFmpeg/libavcodec/mips/sbrdsp_mips.c b/mythtv/external/FFmpeg/libavcodec/mips/sbrdsp_mips.c new file mode 100644 index 00000000000..d4460bad6ed --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/mips/sbrdsp_mips.c @@ -0,0 +1,940 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Authors: Darko Laus (darko@mips.com) + * Djordje Pesut (djordje@mips.com) + * Mirjana Vulin (mvulin@mips.com) + * + * AAC Spectral Band Replication decoding functions optimized for MIPS + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Reference: libavcodec/sbrdsp.c + */ + +#include "config.h" +#include "libavcodec/sbrdsp.h" + +#if HAVE_INLINE_ASM +static void sbr_neg_odd_64_mips(float *x) +{ + int Temp1, Temp2, Temp3, Temp4, Temp5; + float *x1 = &x[1]; + float *x_end = x1 + 64; + + /* loop unrolled 4 times */ + __asm__ volatile ( + "lui %[Temp5], 0x8000 \n\t" + "1: \n\t" + "lw %[Temp1], 0(%[x1]) \n\t" + "lw %[Temp2], 8(%[x1]) \n\t" + "lw %[Temp3], 16(%[x1]) \n\t" + "lw %[Temp4], 24(%[x1]) \n\t" + "xor %[Temp1], %[Temp1], %[Temp5] \n\t" + "xor %[Temp2], %[Temp2], %[Temp5] \n\t" + "xor %[Temp3], %[Temp3], %[Temp5] \n\t" + "xor %[Temp4], %[Temp4], %[Temp5] \n\t" + "sw %[Temp1], 0(%[x1]) \n\t" + "sw %[Temp2], 8(%[x1]) \n\t" + "sw %[Temp3], 16(%[x1]) \n\t" + "sw %[Temp4], 24(%[x1]) \n\t" + "addiu %[x1], %[x1], 32 \n\t" + "bne %[x1], %[x_end], 1b \n\t" + + : [Temp1]"=&r"(Temp1), [Temp2]"=&r"(Temp2), + [Temp3]"=&r"(Temp3), [Temp4]"=&r"(Temp4), + [Temp5]"=&r"(Temp5), [x1]"+r"(x1) + : [x_end]"r"(x_end) + : "memory" + ); +} + +static void sbr_qmf_pre_shuffle_mips(float *z) +{ + int Temp1, Temp2, Temp3, Temp4, Temp5, Temp6; + float *z1 = &z[66]; + float *z2 = &z[59]; + float *z3 = &z[2]; + float *z4 = z1 + 60; + + /* loop unrolled 5 times */ + __asm__ volatile ( + "lui %[Temp6], 0x8000 \n\t" + "1: \n\t" + "lw %[Temp1], 0(%[z2]) \n\t" + "lw %[Temp2], 4(%[z2]) \n\t" + "lw %[Temp3], 8(%[z2]) \n\t" + "lw %[Temp4], 12(%[z2]) \n\t" + "lw %[Temp5], 16(%[z2]) \n\t" + "xor %[Temp1], %[Temp1], %[Temp6] \n\t" + "xor %[Temp2], %[Temp2], %[Temp6] \n\t" + "xor %[Temp3], %[Temp3], %[Temp6] \n\t" + "xor %[Temp4], %[Temp4], %[Temp6] \n\t" + "xor %[Temp5], %[Temp5], %[Temp6] \n\t" + "addiu %[z2], %[z2], -20 \n\t" + "sw %[Temp1], 32(%[z1]) \n\t" + "sw %[Temp2], 24(%[z1]) \n\t" + "sw %[Temp3], 16(%[z1]) \n\t" + "sw %[Temp4], 8(%[z1]) \n\t" + "sw %[Temp5], 0(%[z1]) \n\t" + "lw %[Temp1], 0(%[z3]) \n\t" + "lw %[Temp2], 4(%[z3]) \n\t" + "lw %[Temp3], 8(%[z3]) \n\t" + "lw %[Temp4], 12(%[z3]) \n\t" + "lw %[Temp5], 16(%[z3]) \n\t" + "sw %[Temp1], 4(%[z1]) \n\t" + "sw %[Temp2], 12(%[z1]) \n\t" + "sw %[Temp3], 20(%[z1]) \n\t" + "sw %[Temp4], 28(%[z1]) \n\t" + "sw %[Temp5], 36(%[z1]) \n\t" + "addiu %[z3], %[z3], 20 \n\t" + "addiu %[z1], %[z1], 40 \n\t" + "bne %[z1], %[z4], 1b \n\t" + "lw %[Temp1], 132(%[z]) \n\t" + "lw %[Temp2], 128(%[z]) \n\t" + "lw %[Temp3], 0(%[z]) \n\t" + "lw %[Temp4], 4(%[z]) \n\t" + "xor %[Temp1], %[Temp1], %[Temp6] \n\t" + "sw %[Temp1], 504(%[z]) \n\t" + "sw %[Temp2], 508(%[z]) \n\t" + "sw %[Temp3], 256(%[z]) \n\t" + "sw %[Temp4], 260(%[z]) \n\t" + + : [Temp1]"=&r"(Temp1), [Temp2]"=&r"(Temp2), + [Temp3]"=&r"(Temp3), [Temp4]"=&r"(Temp4), + [Temp5]"=&r"(Temp5), [Temp6]"=&r"(Temp6), + [z1]"+r"(z1), [z2]"+r"(z2), [z3]"+r"(z3) + : [z4]"r"(z4), [z]"r"(z) + : "memory" + ); +} + +static void sbr_qmf_post_shuffle_mips(float W[32][2], const float *z) +{ + int Temp1, Temp2, Temp3, Temp4, Temp5; + float *W_ptr = (float *)W; + float *z1 = (float *)z; + float *z2 = (float *)&z[60]; + float *z_end = z1 + 32; + + /* loop unrolled 4 times */ + __asm__ volatile ( + "lui %[Temp5], 0x8000 \n\t" + "1: \n\t" + "lw %[Temp1], 0(%[z2]) \n\t" + "lw %[Temp2], 4(%[z2]) \n\t" + "lw %[Temp3], 8(%[z2]) \n\t" + "lw %[Temp4], 12(%[z2]) \n\t" + "xor %[Temp1], %[Temp1], %[Temp5] \n\t" + "xor %[Temp2], %[Temp2], %[Temp5] \n\t" + "xor %[Temp3], %[Temp3], %[Temp5] \n\t" + "xor %[Temp4], %[Temp4], %[Temp5] \n\t" + "addiu %[z2], %[z2], -16 \n\t" + "sw %[Temp1], 24(%[W_ptr]) \n\t" + "sw %[Temp2], 16(%[W_ptr]) \n\t" + "sw %[Temp3], 8(%[W_ptr]) \n\t" + "sw %[Temp4], 0(%[W_ptr]) \n\t" + "lw %[Temp1], 0(%[z1]) \n\t" + "lw %[Temp2], 4(%[z1]) \n\t" + "lw %[Temp3], 8(%[z1]) \n\t" + "lw %[Temp4], 12(%[z1]) \n\t" + "sw %[Temp1], 4(%[W_ptr]) \n\t" + "sw %[Temp2], 12(%[W_ptr]) \n\t" + "sw %[Temp3], 20(%[W_ptr]) \n\t" + "sw %[Temp4], 28(%[W_ptr]) \n\t" + "addiu %[z1], %[z1], 16 \n\t" + "addiu %[W_ptr], %[W_ptr], 32 \n\t" + "bne %[z1], %[z_end], 1b \n\t" + + : [Temp1]"=&r"(Temp1), [Temp2]"=&r"(Temp2), + [Temp3]"=&r"(Temp3), [Temp4]"=&r"(Temp4), + [Temp5]"=&r"(Temp5), [z1]"+r"(z1), + [z2]"+r"(z2), [W_ptr]"+r"(W_ptr) + : [z_end]"r"(z_end) + : "memory" + ); +} + +#if HAVE_MIPSFPU +static void sbr_sum64x5_mips(float *z) +{ + int k; + float *z1; + float f1, f2, f3, f4, f5, f6, f7, f8; + for (k = 0; k < 64; k += 8) { + + z1 = &z[k]; + + /* loop unrolled 8 times */ + __asm__ volatile ( + "lwc1 $f0, 0(%[z1]) \n\t" + "lwc1 $f1, 256(%[z1]) \n\t" + "lwc1 $f2, 4(%[z1]) \n\t" + "lwc1 $f3, 260(%[z1]) \n\t" + "lwc1 $f4, 8(%[z1]) \n\t" + "add.s %[f1], $f0, $f1 \n\t" + "lwc1 $f5, 264(%[z1]) \n\t" + "add.s %[f2], $f2, $f3 \n\t" + "lwc1 $f6, 12(%[z1]) \n\t" + "lwc1 $f7, 268(%[z1]) \n\t" + "add.s %[f3], $f4, $f5 \n\t" + "lwc1 $f8, 16(%[z1]) \n\t" + "lwc1 $f9, 272(%[z1]) \n\t" + "add.s %[f4], $f6, $f7 \n\t" + "lwc1 $f10, 20(%[z1]) \n\t" + "lwc1 $f11, 276(%[z1]) \n\t" + "add.s %[f5], $f8, $f9 \n\t" + "lwc1 $f12, 24(%[z1]) \n\t" + "lwc1 $f13, 280(%[z1]) \n\t" + "add.s %[f6], $f10, $f11 \n\t" + "lwc1 $f14, 28(%[z1]) \n\t" + "lwc1 $f15, 284(%[z1]) \n\t" + "add.s %[f7], $f12, $f13 \n\t" + "lwc1 $f0, 512(%[z1]) \n\t" + "lwc1 $f1, 516(%[z1]) \n\t" + "add.s %[f8], $f14, $f15 \n\t" + "lwc1 $f2, 520(%[z1]) \n\t" + "add.s %[f1], %[f1], $f0 \n\t" + "add.s %[f2], %[f2], $f1 \n\t" + "lwc1 $f3, 524(%[z1]) \n\t" + "add.s %[f3], %[f3], $f2 \n\t" + "lwc1 $f4, 528(%[z1]) \n\t" + "lwc1 $f5, 532(%[z1]) \n\t" + "add.s %[f4], %[f4], $f3 \n\t" + "lwc1 $f6, 536(%[z1]) \n\t" + "add.s %[f5], %[f5], $f4 \n\t" + "add.s %[f6], %[f6], $f5 \n\t" + "lwc1 $f7, 540(%[z1]) \n\t" + "add.s %[f7], %[f7], $f6 \n\t" + "lwc1 $f0, 768(%[z1]) \n\t" + "lwc1 $f1, 772(%[z1]) \n\t" + "add.s %[f8], %[f8], $f7 \n\t" + "lwc1 $f2, 776(%[z1]) \n\t" + "add.s %[f1], %[f1], $f0 \n\t" + "add.s %[f2], %[f2], $f1 \n\t" + "lwc1 $f3, 780(%[z1]) \n\t" + "add.s %[f3], %[f3], $f2 \n\t" + "lwc1 $f4, 784(%[z1]) \n\t" + "lwc1 $f5, 788(%[z1]) \n\t" + "add.s %[f4], %[f4], $f3 \n\t" + "lwc1 $f6, 792(%[z1]) \n\t" + "add.s %[f5], %[f5], $f4 \n\t" + "add.s %[f6], %[f6], $f5 \n\t" + "lwc1 $f7, 796(%[z1]) \n\t" + "add.s %[f7], %[f7], $f6 \n\t" + "lwc1 $f0, 1024(%[z1]) \n\t" + "lwc1 $f1, 1028(%[z1]) \n\t" + "add.s %[f8], %[f8], $f7 \n\t" + "lwc1 $f2, 1032(%[z1]) \n\t" + "add.s %[f1], %[f1], $f0 \n\t" + "add.s %[f2], %[f2], $f1 \n\t" + "lwc1 $f3, 1036(%[z1]) \n\t" + "add.s %[f3], %[f3], $f2 \n\t" + "lwc1 $f4, 1040(%[z1]) \n\t" + "lwc1 $f5, 1044(%[z1]) \n\t" + "add.s %[f4], %[f4], $f3 \n\t" + "lwc1 $f6, 1048(%[z1]) \n\t" + "add.s %[f5], %[f5], $f4 \n\t" + "add.s %[f6], %[f6], $f5 \n\t" + "lwc1 $f7, 1052(%[z1]) \n\t" + "add.s %[f7], %[f7], $f6 \n\t" + "swc1 %[f1], 0(%[z1]) \n\t" + "swc1 %[f2], 4(%[z1]) \n\t" + "add.s %[f8], %[f8], $f7 \n\t" + "swc1 %[f3], 8(%[z1]) \n\t" + "swc1 %[f4], 12(%[z1]) \n\t" + "swc1 %[f5], 16(%[z1]) \n\t" + "swc1 %[f6], 20(%[z1]) \n\t" + "swc1 %[f7], 24(%[z1]) \n\t" + "swc1 %[f8], 28(%[z1]) \n\t" + + : [f1]"=&f"(f1), [f2]"=&f"(f2), [f3]"=&f"(f3), + [f4]"=&f"(f4), [f5]"=&f"(f5), [f6]"=&f"(f6), + [f7]"=&f"(f7), [f8]"=&f"(f8) + : [z1]"r"(z1) + : "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", + "$f6", "$f7", "$f8", "$f9", "$f10", "$f11", + "$f12", "$f13", "$f14", "$f15", + "memory" + ); + } +} + +static float sbr_sum_square_mips(float (*x)[2], int n) +{ + float sum0 = 0.0f, sum1 = 0.0f; + float *p_x; + float temp0, temp1, temp2, temp3; + float *loop_end; + p_x = &x[0][0]; + loop_end = p_x + (n >> 1)*4 - 4; + + __asm__ volatile ( + ".set push \n\t" + ".set noreorder \n\t" + "lwc1 %[temp0], 0(%[p_x]) \n\t" + "lwc1 %[temp1], 4(%[p_x]) \n\t" + "lwc1 %[temp2], 8(%[p_x]) \n\t" + "lwc1 %[temp3], 12(%[p_x]) \n\t" + "1: \n\t" + "addiu %[p_x], %[p_x], 16 \n\t" + "madd.s %[sum0], %[sum0], %[temp0], %[temp0] \n\t" + "lwc1 %[temp0], 0(%[p_x]) \n\t" + "madd.s %[sum1], %[sum1], %[temp1], %[temp1] \n\t" + "lwc1 %[temp1], 4(%[p_x]) \n\t" + "madd.s %[sum0], %[sum0], %[temp2], %[temp2] \n\t" + "lwc1 %[temp2], 8(%[p_x]) \n\t" + "madd.s %[sum1], %[sum1], %[temp3], %[temp3] \n\t" + "bne %[p_x], %[loop_end], 1b \n\t" + " lwc1 %[temp3], 12(%[p_x]) \n\t" + "madd.s %[sum0], %[sum0], %[temp0], %[temp0] \n\t" + "madd.s %[sum1], %[sum1], %[temp1], %[temp1] \n\t" + "madd.s %[sum0], %[sum0], %[temp2], %[temp2] \n\t" + "madd.s %[sum1], %[sum1], %[temp3], %[temp3] \n\t" + ".set pop \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&f"(temp3), [sum0]"+f"(sum0), [sum1]"+f"(sum1), + [p_x]"+r"(p_x) + : [loop_end]"r"(loop_end) + : "memory" + ); + return sum0 + sum1; +} + +static void sbr_qmf_deint_bfly_mips(float *v, const float *src0, const float *src1) +{ + int i; + float temp0, temp1, temp2, temp3, temp4, temp5; + float temp6, temp7, temp8, temp9, temp10, temp11; + float *v0 = v; + float *v1 = &v[127]; + float *psrc0 = (float*)src0; + float *psrc1 = (float*)&src1[63]; + + for (i = 0; i < 4; i++) { + + /* loop unrolled 16 times */ + __asm__ volatile( + "lwc1 %[temp0], 0(%[src0]) \n\t" + "lwc1 %[temp1], 0(%[src1]) \n\t" + "lwc1 %[temp3], 4(%[src0]) \n\t" + "lwc1 %[temp4], -4(%[src1]) \n\t" + "lwc1 %[temp6], 8(%[src0]) \n\t" + "lwc1 %[temp7], -8(%[src1]) \n\t" + "lwc1 %[temp9], 12(%[src0]) \n\t" + "lwc1 %[temp10], -12(%[src1]) \n\t" + "add.s %[temp2], %[temp0], %[temp1] \n\t" + "add.s %[temp5], %[temp3], %[temp4] \n\t" + "add.s %[temp8], %[temp6], %[temp7] \n\t" + "add.s %[temp11], %[temp9], %[temp10] \n\t" + "sub.s %[temp0], %[temp0], %[temp1] \n\t" + "sub.s %[temp3], %[temp3], %[temp4] \n\t" + "sub.s %[temp6], %[temp6], %[temp7] \n\t" + "sub.s %[temp9], %[temp9], %[temp10] \n\t" + "swc1 %[temp2], 0(%[v1]) \n\t" + "swc1 %[temp0], 0(%[v0]) \n\t" + "swc1 %[temp5], -4(%[v1]) \n\t" + "swc1 %[temp3], 4(%[v0]) \n\t" + "swc1 %[temp8], -8(%[v1]) \n\t" + "swc1 %[temp6], 8(%[v0]) \n\t" + "swc1 %[temp11], -12(%[v1]) \n\t" + "swc1 %[temp9], 12(%[v0]) \n\t" + "lwc1 %[temp0], 16(%[src0]) \n\t" + "lwc1 %[temp1], -16(%[src1]) \n\t" + "lwc1 %[temp3], 20(%[src0]) \n\t" + "lwc1 %[temp4], -20(%[src1]) \n\t" + "lwc1 %[temp6], 24(%[src0]) \n\t" + "lwc1 %[temp7], -24(%[src1]) \n\t" + "lwc1 %[temp9], 28(%[src0]) \n\t" + "lwc1 %[temp10], -28(%[src1]) \n\t" + "add.s %[temp2], %[temp0], %[temp1] \n\t" + "add.s %[temp5], %[temp3], %[temp4] \n\t" + "add.s %[temp8], %[temp6], %[temp7] \n\t" + "add.s %[temp11], %[temp9], %[temp10] \n\t" + "sub.s %[temp0], %[temp0], %[temp1] \n\t" + "sub.s %[temp3], %[temp3], %[temp4] \n\t" + "sub.s %[temp6], %[temp6], %[temp7] \n\t" + "sub.s %[temp9], %[temp9], %[temp10] \n\t" + "swc1 %[temp2], -16(%[v1]) \n\t" + "swc1 %[temp0], 16(%[v0]) \n\t" + "swc1 %[temp5], -20(%[v1]) \n\t" + "swc1 %[temp3], 20(%[v0]) \n\t" + "swc1 %[temp8], -24(%[v1]) \n\t" + "swc1 %[temp6], 24(%[v0]) \n\t" + "swc1 %[temp11], -28(%[v1]) \n\t" + "swc1 %[temp9], 28(%[v0]) \n\t" + "lwc1 %[temp0], 32(%[src0]) \n\t" + "lwc1 %[temp1], -32(%[src1]) \n\t" + "lwc1 %[temp3], 36(%[src0]) \n\t" + "lwc1 %[temp4], -36(%[src1]) \n\t" + "lwc1 %[temp6], 40(%[src0]) \n\t" + "lwc1 %[temp7], -40(%[src1]) \n\t" + "lwc1 %[temp9], 44(%[src0]) \n\t" + "lwc1 %[temp10], -44(%[src1]) \n\t" + "add.s %[temp2], %[temp0], %[temp1] \n\t" + "add.s %[temp5], %[temp3], %[temp4] \n\t" + "add.s %[temp8], %[temp6], %[temp7] \n\t" + "add.s %[temp11], %[temp9], %[temp10] \n\t" + "sub.s %[temp0], %[temp0], %[temp1] \n\t" + "sub.s %[temp3], %[temp3], %[temp4] \n\t" + "sub.s %[temp6], %[temp6], %[temp7] \n\t" + "sub.s %[temp9], %[temp9], %[temp10] \n\t" + "swc1 %[temp2], -32(%[v1]) \n\t" + "swc1 %[temp0], 32(%[v0]) \n\t" + "swc1 %[temp5], -36(%[v1]) \n\t" + "swc1 %[temp3], 36(%[v0]) \n\t" + "swc1 %[temp8], -40(%[v1]) \n\t" + "swc1 %[temp6], 40(%[v0]) \n\t" + "swc1 %[temp11], -44(%[v1]) \n\t" + "swc1 %[temp9], 44(%[v0]) \n\t" + "lwc1 %[temp0], 48(%[src0]) \n\t" + "lwc1 %[temp1], -48(%[src1]) \n\t" + "lwc1 %[temp3], 52(%[src0]) \n\t" + "lwc1 %[temp4], -52(%[src1]) \n\t" + "lwc1 %[temp6], 56(%[src0]) \n\t" + "lwc1 %[temp7], -56(%[src1]) \n\t" + "lwc1 %[temp9], 60(%[src0]) \n\t" + "lwc1 %[temp10], -60(%[src1]) \n\t" + "add.s %[temp2], %[temp0], %[temp1] \n\t" + "add.s %[temp5], %[temp3], %[temp4] \n\t" + "add.s %[temp8], %[temp6], %[temp7] \n\t" + "add.s %[temp11], %[temp9], %[temp10] \n\t" + "sub.s %[temp0], %[temp0], %[temp1] \n\t" + "sub.s %[temp3], %[temp3], %[temp4] \n\t" + "sub.s %[temp6], %[temp6], %[temp7] \n\t" + "sub.s %[temp9], %[temp9], %[temp10] \n\t" + "swc1 %[temp2], -48(%[v1]) \n\t" + "swc1 %[temp0], 48(%[v0]) \n\t" + "swc1 %[temp5], -52(%[v1]) \n\t" + "swc1 %[temp3], 52(%[v0]) \n\t" + "swc1 %[temp8], -56(%[v1]) \n\t" + "swc1 %[temp6], 56(%[v0]) \n\t" + "swc1 %[temp11], -60(%[v1]) \n\t" + "swc1 %[temp9], 60(%[v0]) \n\t" + "addiu %[src0], %[src0], 64 \n\t" + "addiu %[src1], %[src1], -64 \n\t" + "addiu %[v0], %[v0], 64 \n\t" + "addiu %[v1], %[v1], -64 \n\t" + + : [v0]"+r"(v0), [v1]"+r"(v1), [src0]"+r"(psrc0), [src1]"+r"(psrc1), + [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&f"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [temp6]"=&f"(temp6), [temp7]"=&f"(temp7), [temp8]"=&f"(temp8), + [temp9]"=&f"(temp9), [temp10]"=&f"(temp10), [temp11]"=&f"(temp11) + : + :"memory" + ); + } +} + +static void sbr_autocorrelate_mips(const float x[40][2], float phi[3][2][2]) +{ + int i; + float real_sum_0 = 0.0f; + float real_sum_1 = 0.0f; + float real_sum_2 = 0.0f; + float imag_sum_1 = 0.0f; + float imag_sum_2 = 0.0f; + float *p_x, *p_phi; + float temp0, temp1, temp2, temp3, temp4, temp5, temp6; + float temp7, temp_r, temp_r1, temp_r2, temp_r3, temp_r4; + p_x = (float*)&x[0][0]; + p_phi = &phi[0][0][0]; + + __asm__ volatile ( + "lwc1 %[temp0], 8(%[p_x]) \n\t" + "lwc1 %[temp1], 12(%[p_x]) \n\t" + "lwc1 %[temp2], 16(%[p_x]) \n\t" + "lwc1 %[temp3], 20(%[p_x]) \n\t" + "lwc1 %[temp4], 24(%[p_x]) \n\t" + "lwc1 %[temp5], 28(%[p_x]) \n\t" + "mul.s %[temp_r], %[temp1], %[temp1] \n\t" + "mul.s %[temp_r1], %[temp1], %[temp3] \n\t" + "mul.s %[temp_r2], %[temp1], %[temp2] \n\t" + "mul.s %[temp_r3], %[temp1], %[temp5] \n\t" + "mul.s %[temp_r4], %[temp1], %[temp4] \n\t" + "madd.s %[temp_r], %[temp_r], %[temp0], %[temp0] \n\t" + "madd.s %[temp_r1], %[temp_r1], %[temp0], %[temp2] \n\t" + "msub.s %[temp_r2], %[temp_r2], %[temp0], %[temp3] \n\t" + "madd.s %[temp_r3], %[temp_r3], %[temp0], %[temp4] \n\t" + "msub.s %[temp_r4], %[temp_r4], %[temp0], %[temp5] \n\t" + "add.s %[real_sum_0], %[real_sum_0], %[temp_r] \n\t" + "add.s %[real_sum_1], %[real_sum_1], %[temp_r1] \n\t" + "add.s %[imag_sum_1], %[imag_sum_1], %[temp_r2] \n\t" + "add.s %[real_sum_2], %[real_sum_2], %[temp_r3] \n\t" + "add.s %[imag_sum_2], %[imag_sum_2], %[temp_r4] \n\t" + "addiu %[p_x], %[p_x], 8 \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&f"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [real_sum_0]"+f"(real_sum_0), [real_sum_1]"+f"(real_sum_1), + [imag_sum_1]"+f"(imag_sum_1), [real_sum_2]"+f"(real_sum_2), + [temp_r]"=&f"(temp_r), [temp_r1]"=&f"(temp_r1), [temp_r2]"=&f"(temp_r2), + [temp_r3]"=&f"(temp_r3), [temp_r4]"=&f"(temp_r4), + [p_x]"+r"(p_x), [imag_sum_2]"+f"(imag_sum_2) + : + : "memory" + ); + + for (i = 0; i < 12; i++) { + __asm__ volatile ( + "lwc1 %[temp0], 8(%[p_x]) \n\t" + "lwc1 %[temp1], 12(%[p_x]) \n\t" + "lwc1 %[temp2], 16(%[p_x]) \n\t" + "lwc1 %[temp3], 20(%[p_x]) \n\t" + "lwc1 %[temp4], 24(%[p_x]) \n\t" + "lwc1 %[temp5], 28(%[p_x]) \n\t" + "mul.s %[temp_r], %[temp1], %[temp1] \n\t" + "mul.s %[temp_r1], %[temp1], %[temp3] \n\t" + "mul.s %[temp_r2], %[temp1], %[temp2] \n\t" + "mul.s %[temp_r3], %[temp1], %[temp5] \n\t" + "mul.s %[temp_r4], %[temp1], %[temp4] \n\t" + "madd.s %[temp_r], %[temp_r], %[temp0], %[temp0] \n\t" + "madd.s %[temp_r1], %[temp_r1], %[temp0], %[temp2] \n\t" + "msub.s %[temp_r2], %[temp_r2], %[temp0], %[temp3] \n\t" + "madd.s %[temp_r3], %[temp_r3], %[temp0], %[temp4] \n\t" + "msub.s %[temp_r4], %[temp_r4], %[temp0], %[temp5] \n\t" + "add.s %[real_sum_0], %[real_sum_0], %[temp_r] \n\t" + "add.s %[real_sum_1], %[real_sum_1], %[temp_r1] \n\t" + "add.s %[imag_sum_1], %[imag_sum_1], %[temp_r2] \n\t" + "add.s %[real_sum_2], %[real_sum_2], %[temp_r3] \n\t" + "add.s %[imag_sum_2], %[imag_sum_2], %[temp_r4] \n\t" + "lwc1 %[temp0], 32(%[p_x]) \n\t" + "lwc1 %[temp1], 36(%[p_x]) \n\t" + "mul.s %[temp_r], %[temp3], %[temp3] \n\t" + "mul.s %[temp_r1], %[temp3], %[temp5] \n\t" + "mul.s %[temp_r2], %[temp3], %[temp4] \n\t" + "mul.s %[temp_r3], %[temp3], %[temp1] \n\t" + "mul.s %[temp_r4], %[temp3], %[temp0] \n\t" + "madd.s %[temp_r], %[temp_r], %[temp2], %[temp2] \n\t" + "madd.s %[temp_r1], %[temp_r1], %[temp2], %[temp4] \n\t" + "msub.s %[temp_r2], %[temp_r2], %[temp2], %[temp5] \n\t" + "madd.s %[temp_r3], %[temp_r3], %[temp2], %[temp0] \n\t" + "msub.s %[temp_r4], %[temp_r4], %[temp2], %[temp1] \n\t" + "add.s %[real_sum_0], %[real_sum_0], %[temp_r] \n\t" + "add.s %[real_sum_1], %[real_sum_1], %[temp_r1] \n\t" + "add.s %[imag_sum_1], %[imag_sum_1], %[temp_r2] \n\t" + "add.s %[real_sum_2], %[real_sum_2], %[temp_r3] \n\t" + "add.s %[imag_sum_2], %[imag_sum_2], %[temp_r4] \n\t" + "lwc1 %[temp2], 40(%[p_x]) \n\t" + "lwc1 %[temp3], 44(%[p_x]) \n\t" + "mul.s %[temp_r], %[temp5], %[temp5] \n\t" + "mul.s %[temp_r1], %[temp5], %[temp1] \n\t" + "mul.s %[temp_r2], %[temp5], %[temp0] \n\t" + "mul.s %[temp_r3], %[temp5], %[temp3] \n\t" + "mul.s %[temp_r4], %[temp5], %[temp2] \n\t" + "madd.s %[temp_r], %[temp_r], %[temp4], %[temp4] \n\t" + "madd.s %[temp_r1], %[temp_r1], %[temp4], %[temp0] \n\t" + "msub.s %[temp_r2], %[temp_r2], %[temp4], %[temp1] \n\t" + "madd.s %[temp_r3], %[temp_r3], %[temp4], %[temp2] \n\t" + "msub.s %[temp_r4], %[temp_r4], %[temp4], %[temp3] \n\t" + "add.s %[real_sum_0], %[real_sum_0], %[temp_r] \n\t" + "add.s %[real_sum_1], %[real_sum_1], %[temp_r1] \n\t" + "add.s %[imag_sum_1], %[imag_sum_1], %[temp_r2] \n\t" + "add.s %[real_sum_2], %[real_sum_2], %[temp_r3] \n\t" + "add.s %[imag_sum_2], %[imag_sum_2], %[temp_r4] \n\t" + "addiu %[p_x], %[p_x], 24 \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&f"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [real_sum_0]"+f"(real_sum_0), [real_sum_1]"+f"(real_sum_1), + [imag_sum_1]"+f"(imag_sum_1), [real_sum_2]"+f"(real_sum_2), + [temp_r]"=&f"(temp_r), [temp_r1]"=&f"(temp_r1), + [temp_r2]"=&f"(temp_r2), [temp_r3]"=&f"(temp_r3), + [temp_r4]"=&f"(temp_r4), [p_x]"+r"(p_x), + [imag_sum_2]"+f"(imag_sum_2) + : + : "memory" + ); + } + __asm__ volatile ( + "lwc1 %[temp0], -296(%[p_x]) \n\t" + "lwc1 %[temp1], -292(%[p_x]) \n\t" + "lwc1 %[temp2], 8(%[p_x]) \n\t" + "lwc1 %[temp3], 12(%[p_x]) \n\t" + "lwc1 %[temp4], -288(%[p_x]) \n\t" + "lwc1 %[temp5], -284(%[p_x]) \n\t" + "lwc1 %[temp6], -280(%[p_x]) \n\t" + "lwc1 %[temp7], -276(%[p_x]) \n\t" + "madd.s %[temp_r], %[real_sum_0], %[temp0], %[temp0] \n\t" + "madd.s %[temp_r1], %[real_sum_0], %[temp2], %[temp2] \n\t" + "madd.s %[temp_r2], %[real_sum_1], %[temp0], %[temp4] \n\t" + "madd.s %[temp_r3], %[imag_sum_1], %[temp0], %[temp5] \n\t" + "madd.s %[temp_r], %[temp_r], %[temp1], %[temp1] \n\t" + "madd.s %[temp_r1], %[temp_r1], %[temp3], %[temp3] \n\t" + "madd.s %[temp_r2], %[temp_r2], %[temp1], %[temp5] \n\t" + "nmsub.s %[temp_r3], %[temp_r3], %[temp1], %[temp4] \n\t" + "lwc1 %[temp4], 16(%[p_x]) \n\t" + "lwc1 %[temp5], 20(%[p_x]) \n\t" + "swc1 %[temp_r], 40(%[p_phi]) \n\t" + "swc1 %[temp_r1], 16(%[p_phi]) \n\t" + "swc1 %[temp_r2], 24(%[p_phi]) \n\t" + "swc1 %[temp_r3], 28(%[p_phi]) \n\t" + "madd.s %[temp_r], %[real_sum_1], %[temp2], %[temp4] \n\t" + "madd.s %[temp_r1], %[imag_sum_1], %[temp2], %[temp5] \n\t" + "madd.s %[temp_r2], %[real_sum_2], %[temp0], %[temp6] \n\t" + "madd.s %[temp_r3], %[imag_sum_2], %[temp0], %[temp7] \n\t" + "madd.s %[temp_r], %[temp_r], %[temp3], %[temp5] \n\t" + "nmsub.s %[temp_r1], %[temp_r1], %[temp3], %[temp4] \n\t" + "madd.s %[temp_r2], %[temp_r2], %[temp1], %[temp7] \n\t" + "nmsub.s %[temp_r3], %[temp_r3], %[temp1], %[temp6] \n\t" + "swc1 %[temp_r], 0(%[p_phi]) \n\t" + "swc1 %[temp_r1], 4(%[p_phi]) \n\t" + "swc1 %[temp_r2], 8(%[p_phi]) \n\t" + "swc1 %[temp_r3], 12(%[p_phi]) \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&f"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [temp6]"=&f"(temp6), [temp7]"=&f"(temp7), [temp_r]"=&f"(temp_r), + [real_sum_0]"+f"(real_sum_0), [real_sum_1]"+f"(real_sum_1), + [real_sum_2]"+f"(real_sum_2), [imag_sum_1]"+f"(imag_sum_1), + [temp_r2]"=&f"(temp_r2), [temp_r3]"=&f"(temp_r3), + [temp_r1]"=&f"(temp_r1), [p_phi]"+r"(p_phi), + [imag_sum_2]"+f"(imag_sum_2) + : [p_x]"r"(p_x) + : "memory" + ); +} + +static void sbr_hf_gen_mips(float (*X_high)[2], const float (*X_low)[2], + const float alpha0[2], const float alpha1[2], + float bw, int start, int end) +{ + float alpha[4]; + int i; + float *p_x_low = (float*)&X_low[0][0] + 2*start; + float *p_x_high = &X_high[0][0] + 2*start; + float temp0, temp1, temp2, temp3, temp4, temp5, temp6; + float temp7, temp8, temp9, temp10, temp11, temp12; + + alpha[0] = alpha1[0] * bw * bw; + alpha[1] = alpha1[1] * bw * bw; + alpha[2] = alpha0[0] * bw; + alpha[3] = alpha0[1] * bw; + + for (i = start; i < end; i++) { + __asm__ volatile ( + "lwc1 %[temp0], -16(%[p_x_low]) \n\t" + "lwc1 %[temp1], -12(%[p_x_low]) \n\t" + "lwc1 %[temp2], -8(%[p_x_low]) \n\t" + "lwc1 %[temp3], -4(%[p_x_low]) \n\t" + "lwc1 %[temp5], 0(%[p_x_low]) \n\t" + "lwc1 %[temp6], 4(%[p_x_low]) \n\t" + "lwc1 %[temp7], 0(%[alpha]) \n\t" + "lwc1 %[temp8], 4(%[alpha]) \n\t" + "lwc1 %[temp9], 8(%[alpha]) \n\t" + "lwc1 %[temp10], 12(%[alpha]) \n\t" + "addiu %[p_x_high], %[p_x_high], 8 \n\t" + "addiu %[p_x_low], %[p_x_low], 8 \n\t" + "mul.s %[temp11], %[temp1], %[temp8] \n\t" + "msub.s %[temp11], %[temp11], %[temp0], %[temp7] \n\t" + "madd.s %[temp11], %[temp11], %[temp2], %[temp9] \n\t" + "nmsub.s %[temp11], %[temp11], %[temp3], %[temp10] \n\t" + "add.s %[temp11], %[temp11], %[temp5] \n\t" + "swc1 %[temp11], -8(%[p_x_high]) \n\t" + "mul.s %[temp12], %[temp1], %[temp7] \n\t" + "madd.s %[temp12], %[temp12], %[temp0], %[temp8] \n\t" + "madd.s %[temp12], %[temp12], %[temp3], %[temp9] \n\t" + "madd.s %[temp12], %[temp12], %[temp2], %[temp10] \n\t" + "add.s %[temp12], %[temp12], %[temp6] \n\t" + "swc1 %[temp12], -4(%[p_x_high]) \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&f"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), + [temp6]"=&f"(temp6), [temp7]"=&f"(temp7), [temp8]"=&f"(temp8), + [temp9]"=&f"(temp9), [temp10]"=&f"(temp10), [temp11]"=&f"(temp11), + [temp12]"=&f"(temp12), [p_x_high]"+r"(p_x_high), + [p_x_low]"+r"(p_x_low) + : [alpha]"r"(alpha) + : "memory" + ); + } +} + +static void sbr_hf_g_filt_mips(float (*Y)[2], const float (*X_high)[40][2], + const float *g_filt, int m_max, intptr_t ixh) +{ + float *p_y, *p_x, *p_g; + float temp0, temp1, temp2; + int loop_end; + + p_g = (float*)&g_filt[0]; + p_y = &Y[0][0]; + p_x = (float*)&X_high[0][ixh][0]; + loop_end = (int)((int*)p_g + m_max); + + __asm__ volatile( + ".set push \n\t" + ".set noreorder \n\t" + "1: \n\t" + "lwc1 %[temp0], 0(%[p_g]) \n\t" + "lwc1 %[temp1], 0(%[p_x]) \n\t" + "lwc1 %[temp2], 4(%[p_x]) \n\t" + "mul.s %[temp1], %[temp1], %[temp0] \n\t" + "mul.s %[temp2], %[temp2], %[temp0] \n\t" + "addiu %[p_g], %[p_g], 4 \n\t" + "addiu %[p_x], %[p_x], 320 \n\t" + "swc1 %[temp1], 0(%[p_y]) \n\t" + "swc1 %[temp2], 4(%[p_y]) \n\t" + "bne %[p_g], %[loop_end], 1b \n\t" + " addiu %[p_y], %[p_y], 8 \n\t" + ".set pop \n\t" + + : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1), + [temp2]"=&f"(temp2), [p_x]"+r"(p_x), + [p_y]"+r"(p_y), [p_g]"+r"(p_g) + : [loop_end]"r"(loop_end) + : "memory" + ); +} + +static void sbr_hf_apply_noise_0_mips(float (*Y)[2], const float *s_m, + const float *q_filt, int noise, + int kx, int m_max) +{ + int m; + + for (m = 0; m < m_max; m++){ + + float *Y1=&Y[m][0]; + float *ff_table; + float y0,y1, temp1, temp2, temp4, temp5; + int temp0, temp3; + const float *s_m1=&s_m[m]; + const float *q_filt1= &q_filt[m]; + + __asm__ volatile( + "lwc1 %[y0], 0(%[Y1]) \n\t" + "lwc1 %[temp1], 0(%[s_m1]) \n\t" + "addiu %[noise], %[noise], 1 \n\t" + "andi %[noise], %[noise], 0x1ff \n\t" + "sll %[temp0], %[noise], 3 \n\t" + "addu %[ff_table], %[ff_sbr_noise_table], %[temp0] \n\t" + "add.s %[y0], %[y0], %[temp1] \n\t" + "mfc1 %[temp3], %[temp1] \n\t" + "bne %[temp3], $0, 1f \n\t" + "lwc1 %[y1], 4(%[Y1]) \n\t" + "lwc1 %[temp2], 0(%[q_filt1]) \n\t" + "lwc1 %[temp4], 0(%[ff_table]) \n\t" + "lwc1 %[temp5], 4(%[ff_table]) \n\t" + "madd.s %[y0], %[y0], %[temp2], %[temp4] \n\t" + "madd.s %[y1], %[y1], %[temp2], %[temp5] \n\t" + "swc1 %[y1], 4(%[Y1]) \n\t" + "1: \n\t" + "swc1 %[y0], 0(%[Y1]) \n\t" + + : [ff_table]"=&r"(ff_table), [y0]"=&f"(y0), [y1]"=&f"(y1), + [temp0]"=&r"(temp0), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&r"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5) + : [ff_sbr_noise_table]"r"(ff_sbr_noise_table), [noise]"r"(noise), + [Y1]"r"(Y1), [s_m1]"r"(s_m1), [q_filt1]"r"(q_filt1) + : "memory" + ); + } +} + +static void sbr_hf_apply_noise_1_mips(float (*Y)[2], const float *s_m, + const float *q_filt, int noise, + int kx, int m_max) +{ + float y0,y1,temp1, temp2, temp4, temp5; + int temp0, temp3, m; + float phi_sign = 1 - 2 * (kx & 1); + + for (m = 0; m < m_max; m++) { + + float *ff_table; + float *Y1=&Y[m][0]; + const float *s_m1=&s_m[m]; + const float *q_filt1= &q_filt[m]; + + __asm__ volatile( + "lwc1 %[y1], 4(%[Y1]) \n\t" + "lwc1 %[temp1], 0(%[s_m1]) \n\t" + "lw %[temp3], 0(%[s_m1]) \n\t" + "addiu %[noise], %[noise], 1 \n\t" + "andi %[noise], %[noise], 0x1ff \n\t" + "sll %[temp0], %[noise], 3 \n\t" + "addu %[ff_table], %[ff_sbr_noise_table], %[temp0] \n\t" + "madd.s %[y1], %[y1], %[temp1], %[phi_sign] \n\t" + "bne %[temp3], $0, 1f \n\t" + "lwc1 %[y0], 0(%[Y1]) \n\t" + "lwc1 %[temp2], 0(%[q_filt1]) \n\t" + "lwc1 %[temp4], 0(%[ff_table]) \n\t" + "lwc1 %[temp5], 4(%[ff_table]) \n\t" + "madd.s %[y0], %[y0], %[temp2], %[temp4] \n\t" + "madd.s %[y1], %[y1], %[temp2], %[temp5] \n\t" + "swc1 %[y0], 0(%[Y1]) \n\t" + "1: \n\t" + "swc1 %[y1], 4(%[Y1]) \n\t" + + : [ff_table] "=&r" (ff_table), [y0] "=&f" (y0), [y1] "=&f" (y1), + [temp0] "=&r" (temp0), [temp1] "=&f" (temp1), [temp2] "=&f" (temp2), + [temp3] "=&r" (temp3), [temp4] "=&f" (temp4), [temp5] "=&f" (temp5) + : [ff_sbr_noise_table] "r" (ff_sbr_noise_table), [noise] "r" (noise), + [Y1] "r" (Y1), [s_m1] "r" (s_m1), [q_filt1] "r" (q_filt1), + [phi_sign] "f" (phi_sign) + : "memory" + ); + phi_sign = -phi_sign; + } +} + +static void sbr_hf_apply_noise_2_mips(float (*Y)[2], const float *s_m, + const float *q_filt, int noise, + int kx, int m_max) +{ + int m; + float *ff_table; + float y0,y1, temp0, temp1, temp2, temp3, temp4, temp5; + + for (m = 0; m < m_max; m++) { + + float *Y1=&Y[m][0]; + const float *s_m1=&s_m[m]; + const float *q_filt1= &q_filt[m]; + + __asm__ volatile( + "lwc1 %[y0], 0(%[Y1]) \n\t" + "lwc1 %[temp1], 0(%[s_m1]) \n\t" + "addiu %[noise], %[noise], 1 \n\t" + "andi %[noise], %[noise], 0x1ff \n\t" + "sll %[temp0], %[noise], 3 \n\t" + "addu %[ff_table], %[ff_sbr_noise_table], %[temp0] \n\t" + "sub.s %[y0], %[y0], %[temp1] \n\t" + "mfc1 %[temp3], %[temp1] \n\t" + "bne %[temp3], $0, 1f \n\t" + "lwc1 %[y1], 4(%[Y1]) \n\t" + "lwc1 %[temp2], 0(%[q_filt1]) \n\t" + "lwc1 %[temp4], 0(%[ff_table]) \n\t" + "lwc1 %[temp5], 4(%[ff_table]) \n\t" + "madd.s %[y0], %[y0], %[temp2], %[temp4] \n\t" + "madd.s %[y1], %[y1], %[temp2], %[temp5] \n\t" + "swc1 %[y1], 4(%[Y1]) \n\t" + "1: \n\t" + "swc1 %[y0], 0(%[Y1]) \n\t" + + : [temp0]"=&r"(temp0), [ff_table]"=&r"(ff_table), [y0]"=&f"(y0), + [y1]"=&f"(y1), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&r"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5) + : [ff_sbr_noise_table]"r"(ff_sbr_noise_table), [noise]"r"(noise), + [Y1]"r"(Y1), [s_m1]"r"(s_m1), [q_filt1]"r"(q_filt1) + : "memory" + ); + } +} + +static void sbr_hf_apply_noise_3_mips(float (*Y)[2], const float *s_m, + const float *q_filt, int noise, + int kx, int m_max) +{ + float phi_sign = 1 - 2 * (kx & 1); + int m; + + for (m = 0; m < m_max; m++) { + + float *Y1=&Y[m][0]; + float *ff_table; + float y0,y1, temp1, temp2, temp4, temp5; + int temp0, temp3; + const float *s_m1=&s_m[m]; + const float *q_filt1= &q_filt[m]; + + __asm__ volatile( + "lwc1 %[y1], 4(%[Y1]) \n\t" + "lwc1 %[temp1], 0(%[s_m1]) \n\t" + "addiu %[noise], %[noise], 1 \n\t" + "andi %[noise], %[noise], 0x1ff \n\t" + "sll %[temp0], %[noise], 3 \n\t" + "addu %[ff_table], %[ff_sbr_noise_table], %[temp0] \n\t" + "nmsub.s %[y1], %[y1], %[temp1], %[phi_sign] \n\t" + "mfc1 %[temp3], %[temp1] \n\t" + "bne %[temp3], $0, 1f \n\t" + "lwc1 %[y0], 0(%[Y1]) \n\t" + "lwc1 %[temp2], 0(%[q_filt1]) \n\t" + "lwc1 %[temp4], 0(%[ff_table]) \n\t" + "lwc1 %[temp5], 4(%[ff_table]) \n\t" + "madd.s %[y0], %[y0], %[temp2], %[temp4] \n\t" + "madd.s %[y1], %[y1], %[temp2], %[temp5] \n\t" + "swc1 %[y0], 0(%[Y1]) \n\t" + "1: \n\t" + "swc1 %[y1], 4(%[Y1]) \n\t" + + : [ff_table]"=&r"(ff_table), [y0]"=&f"(y0), [y1]"=&f"(y1), + [temp0]"=&r"(temp0), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), + [temp3]"=&r"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5) + : [ff_sbr_noise_table]"r"(ff_sbr_noise_table), [noise]"r"(noise), + [Y1]"r"(Y1), [s_m1]"r"(s_m1), [q_filt1]"r"(q_filt1), + [phi_sign]"f"(phi_sign) + : "memory" + ); + phi_sign = -phi_sign; + } +} +#endif /* HAVE_MIPSFPU */ +#endif /* HAVE_INLINE_ASM */ + +void ff_sbrdsp_init_mips(SBRDSPContext *s) +{ +#if HAVE_INLINE_ASM + s->neg_odd_64 = sbr_neg_odd_64_mips; + s->qmf_pre_shuffle = sbr_qmf_pre_shuffle_mips; + s->qmf_post_shuffle = sbr_qmf_post_shuffle_mips; +#if HAVE_MIPSFPU + s->sum64x5 = sbr_sum64x5_mips; + s->sum_square = sbr_sum_square_mips; + s->qmf_deint_bfly = sbr_qmf_deint_bfly_mips; + s->autocorrelate = sbr_autocorrelate_mips; + s->hf_gen = sbr_hf_gen_mips; + s->hf_g_filt = sbr_hf_g_filt_mips; + + s->hf_apply_noise[0] = sbr_hf_apply_noise_0_mips; + s->hf_apply_noise[1] = sbr_hf_apply_noise_1_mips; + s->hf_apply_noise[2] = sbr_hf_apply_noise_2_mips; + s->hf_apply_noise[3] = sbr_hf_apply_noise_3_mips; +#endif /* HAVE_MIPSFPU */ +#endif /* HAVE_INLINE_ASM */ +} diff --git a/mythtv/external/FFmpeg/libavcodec/mjpegdec.c b/mythtv/external/FFmpeg/libavcodec/mjpegdec.c index fd5136466b8..f1e9b6809b5 100644 --- a/mythtv/external/FFmpeg/libavcodec/mjpegdec.c +++ b/mythtv/external/FFmpeg/libavcodec/mjpegdec.c @@ -34,7 +34,7 @@ #include "libavutil/avassert.h" #include "libavutil/opt.h" #include "avcodec.h" -#include "dsputil.h" +#include "copy_block.h" #include "internal.h" #include "mjpeg.h" #include "mjpegdec.h" @@ -298,13 +298,11 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) return AVERROR_PATCHWELCOME; } - if (s->v_max == 1 && s->h_max == 1 && s->lossless==1 && nb_components==3) - s->rgb = 1; /* if different size, realloc/alloc picture */ if ( width != s->width || height != s->height - || memcmp(s->h_count, h_count, sizeof(h_count[0])*nb_components) - || memcmp(s->v_count, v_count, sizeof(v_count[0])*nb_components)) { + || memcmp(s->h_count, h_count, sizeof(h_count)) + || memcmp(s->v_count, v_count, sizeof(v_count))) { av_freep(&s->qscale_table); s->width = width; @@ -337,6 +335,10 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) return AVERROR_INVALIDDATA; } } else{ + if (s->v_max == 1 && s->h_max == 1 && s->lossless==1 && nb_components==3) + s->rgb = 1; + else if (!s->lossless) + s->rgb = 0; /* XXX: not complete test ! */ pix_fmt_id = (s->h_count[0] << 28) | (s->v_count[0] << 24) | (s->h_count[1] << 20) | (s->v_count[1] << 16) | @@ -463,6 +465,11 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) av_log(s->avctx, AV_LOG_DEBUG, "decode_sof0: error, len(%d) mismatch\n", len); } + if (s->rgb && !s->lossless && !s->ls) { + av_log(s->avctx, AV_LOG_ERROR, "Unsupported coding and pixel format combination\n"); + return AVERROR_PATCHWELCOME; + } + /* totally blank picture as progressive JPEG will only add details to it */ if (s->progressive) { int bw = (width + s->h_max * 8 - 1) / (s->h_max * 8); @@ -498,7 +505,7 @@ static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index) } /* decode block and dequantize */ -static int decode_block(MJpegDecodeContext *s, DCTELEM *block, int component, +static int decode_block(MJpegDecodeContext *s, int16_t *block, int component, int dc_index, int ac_index, int16_t *quant_matrix) { int code, i, j, level, val; @@ -546,7 +553,7 @@ static int decode_block(MJpegDecodeContext *s, DCTELEM *block, int component, return 0; } -static int decode_dc_progressive(MJpegDecodeContext *s, DCTELEM *block, +static int decode_dc_progressive(MJpegDecodeContext *s, int16_t *block, int component, int dc_index, int16_t *quant_matrix, int Al) { @@ -564,7 +571,7 @@ static int decode_dc_progressive(MJpegDecodeContext *s, DCTELEM *block, } /* decode block and dequantize - progressive JPEG version */ -static int decode_block_progressive(MJpegDecodeContext *s, DCTELEM *block, +static int decode_block_progressive(MJpegDecodeContext *s, int16_t *block, uint8_t *last_nnz, int ac_index, int16_t *quant_matrix, int ss, int se, int Al, int *EOBRUN) @@ -662,7 +669,7 @@ for (; ; i++) { \ } /* decode block and dequantize - progressive JPEG refinement pass */ -static int decode_block_refinement(MJpegDecodeContext *s, DCTELEM *block, +static int decode_block_refinement(MJpegDecodeContext *s, int16_t *block, uint8_t *last_nnz, int ac_index, int16_t *quant_matrix, int ss, int se, int Al, int *EOBRUN) @@ -844,18 +851,17 @@ static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int p return 0; } -static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, +static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int nb_components, int predictor, int point_transform) { int i, mb_x, mb_y; - const int nb_components=s->nb_components; int bits= (s->bits+7)&~7; int resync_mb_y = 0; int resync_mb_x = 0; point_transform += bits - s->bits; - av_assert0(nb_components==1 || nb_components==3); + av_assert0(nb_components>=1 && nb_components<=3); for (mb_y = 0; mb_y < s->mb_height; mb_y++) { for (mb_x = 0; mb_x < s->mb_width; mb_x++) { @@ -988,11 +994,12 @@ static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, return 0; } -static av_always_inline void mjpeg_copy_block(uint8_t *dst, const uint8_t *src, +static av_always_inline void mjpeg_copy_block(MJpegDecodeContext *s, + uint8_t *dst, const uint8_t *src, int linesize, int lowres) { switch (lowres) { - case 0: copy_block8(dst, src, linesize, linesize, 8); + case 0: s->dsp.put_pixels_tab[1][0](dst, src, linesize, 8); break; case 1: copy_block4(dst, src, linesize, linesize, 4); break; @@ -1068,8 +1075,9 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, ptr = data[c] + block_offset; if (!s->progressive) { if (copy_mb) - mjpeg_copy_block(ptr, reference_data[c] + block_offset, + mjpeg_copy_block(s, ptr, reference_data[c] + block_offset, linesize[c], s->avctx->lowres); + else { s->dsp.clear_block(s->block); if (decode_block(s, s->block, i, @@ -1084,7 +1092,7 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, } else { int block_idx = s->block_stride[c] * (v * mb_y + y) + (h * mb_x + x); - DCTELEM *block = s->blocks[c][block_idx]; + int16_t *block = s->blocks[c][block_idx]; if (Ah) block[0] += get_bits1(&s->gb) * s->quant_matrixes[s->quant_index[c]][0] << Al; @@ -1142,7 +1150,7 @@ static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, for (mb_y = 0; mb_y < s->mb_height; mb_y++) { uint8_t *ptr = data + (mb_y * linesize * 8 >> s->avctx->lowres); int block_idx = mb_y * s->block_stride[c]; - DCTELEM (*block)[64] = &s->blocks[c][block_idx]; + int16_t (*block)[64] = &s->blocks[c][block_idx]; uint8_t *last_nnz = &s->last_nnz[c][block_idx]; for (mb_x = 0; mb_x < s->mb_width; mb_x++, block++, last_nnz++) { int ret; @@ -1287,7 +1295,7 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask, if ((ret = ljpeg_decode_rgb_scan(s, nb_components, predictor, point_transform)) < 0) return ret; } else { - if ((ret = ljpeg_decode_yuv_scan(s, predictor, point_transform)) < 0) + if ((ret = ljpeg_decode_yuv_scan(s, nb_components, predictor, point_transform)) < 0) return ret; } } @@ -1351,7 +1359,6 @@ static int mjpeg_decode_app(MJpegDecodeContext *s) return AVERROR_INVALIDDATA; id = get_bits_long(&s->gb, 32); - id = av_be2ne32(id); len -= 6; if (s->avctx->debug & FF_DEBUG_STARTCODE) @@ -1360,7 +1367,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s) /* Buggy AVID, it puts EOI only at every 10th frame. */ /* Also, this fourcc is used by non-avid files too, it holds some information, but it's always present in AVID-created files. */ - if (id == AV_RL32("AVI1")) { + if (id == AV_RB32("AVI1")) { /* structure: 4bytes AVI1 1bytes polarity @@ -1382,7 +1389,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s) // len -= 2; - if (id == AV_RL32("JFIF")) { + if (id == AV_RB32("JFIF")) { int t_w, t_h, v1, v2; skip_bits(&s->gb, 8); /* the trailing zero-byte */ v1 = get_bits(&s->gb, 8); @@ -1410,7 +1417,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s) goto out; } - if (id == AV_RL32("Adob") && (get_bits(&s->gb, 8) == 'e')) { + if (id == AV_RB32("Adob") && (get_bits(&s->gb, 8) == 'e')) { if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found\n"); skip_bits(&s->gb, 16); /* version */ @@ -1421,7 +1428,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s) goto out; } - if (id == AV_RL32("LJIF")) { + if (id == AV_RB32("LJIF")) { if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, "Pegasus lossless jpeg header found\n"); @@ -1448,10 +1455,9 @@ static int mjpeg_decode_app(MJpegDecodeContext *s) /* Apple MJPEG-A */ if ((s->start_code == APP1) && (len > (0x28 - 8))) { id = get_bits_long(&s->gb, 32); - id = av_be2ne32(id); len -= 4; /* Apple MJPEG-A */ - if (id == AV_RL32("mjpg")) { + if (id == AV_RB32("mjpg")) { #if 0 skip_bits(&s->gb, 32); /* field size */ skip_bits(&s->gb, 32); /* pad field size */ @@ -1593,7 +1599,7 @@ int ff_mjpeg_find_marker(MJpegDecodeContext *s, while ((src + t < buf_end) && x == 0xff) x = src[t++]; if (x & 0x80) { - t -= 2; + t -= FFMIN(2, t); break; } } @@ -1633,6 +1639,7 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, MJpegDecodeContext *s = avctx->priv_data; const uint8_t *buf_end, *buf_ptr; const uint8_t *unescaped_buf_ptr; + int hshift, vshift; int unescaped_buf_size; int start_code; int i, index; @@ -1738,23 +1745,23 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (s->bottom_field == !s->interlace_polarity) break; } - *picture = *s->picture_ptr; - *got_frame = 1; - s->got_picture = 0; - - if (!s->lossless) { - picture->quality = FFMAX3(s->qscale[0], - s->qscale[1], - s->qscale[2]); - picture->qstride = 0; - picture->qscale_table = s->qscale_table; - memset(picture->qscale_table, picture->quality, - (s->width + 15) / 16); - if (avctx->debug & FF_DEBUG_QP) - av_log(avctx, AV_LOG_DEBUG, - "QP: %d\n", picture->quality); - picture->quality *= FF_QP2LAMBDA; - } + *picture = *s->picture_ptr; + *got_frame = 1; + s->got_picture = 0; + + if (!s->lossless) { + picture->quality = FFMAX3(s->qscale[0], + s->qscale[1], + s->qscale[2]); + picture->qstride = 0; + picture->qscale_table = s->qscale_table; + memset(picture->qscale_table, picture->quality, + (s->width + 15) / 16); + if (avctx->debug & FF_DEBUG_QP) + av_log(avctx, AV_LOG_DEBUG, + "QP: %d\n", picture->quality); + picture->quality *= FF_QP2LAMBDA; + } goto the_end; case SOS: @@ -1811,6 +1818,9 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, } if (s->upscale_v) { uint8_t *dst = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[(s->height - 1) * s->linesize[s->upscale_v]]; + int w; + avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &hshift, &vshift); + w = s->width >> hshift; av_assert0(avctx->pix_fmt == AV_PIX_FMT_YUVJ444P || avctx->pix_fmt == AV_PIX_FMT_YUV444P || avctx->pix_fmt == AV_PIX_FMT_YUVJ422P || @@ -1819,16 +1829,16 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, uint8_t *src1 = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[i / 2 * s->linesize[s->upscale_v]]; uint8_t *src2 = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[(i + 1) / 2 * s->linesize[s->upscale_v]]; if (src1 == src2) { - memcpy(dst, src1, s->width); + memcpy(dst, src1, w); } else { - for (index = 0; index < s->width; index++) + for (index = 0; index < w; index++) dst[index] = (src1[index] + src2[index]) >> 1; } dst -= s->linesize[s->upscale_v]; } } if (s->flipped && (s->avctx->flags & CODEC_FLAG_EMU_EDGE)) { - int hshift, vshift, j; + int j; avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &hshift, &vshift); for (index=0; index<4; index++) { uint8_t *dst = s->picture_ptr->data[index]; diff --git a/mythtv/external/FFmpeg/libavcodec/mjpegdec.h b/mythtv/external/FFmpeg/libavcodec/mjpegdec.h index 6c6195b3d38..01f4323bc7f 100644 --- a/mythtv/external/FFmpeg/libavcodec/mjpegdec.h +++ b/mythtv/external/FFmpeg/libavcodec/mjpegdec.h @@ -91,8 +91,8 @@ typedef struct MJpegDecodeContext { int got_picture; ///< we found a SOF and picture is valid, too. int linesize[MAX_COMPONENTS]; ///< linesize << interlaced int8_t *qscale_table; - DECLARE_ALIGNED(16, DCTELEM, block)[64]; - DCTELEM (*blocks[MAX_COMPONENTS])[64]; ///< intermediate sums (progressive mode) + DECLARE_ALIGNED(16, int16_t, block)[64]; + int16_t (*blocks[MAX_COMPONENTS])[64]; ///< intermediate sums (progressive mode) uint8_t *last_nnz[MAX_COMPONENTS]; uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have been completely decoded (progressive mode) ScanTable scantable; diff --git a/mythtv/external/FFmpeg/libavcodec/mjpegenc.c b/mythtv/external/FFmpeg/libavcodec/mjpegenc.c index 7ac304295cb..80a4022c7e8 100644 --- a/mythtv/external/FFmpeg/libavcodec/mjpegenc.c +++ b/mythtv/external/FFmpeg/libavcodec/mjpegenc.c @@ -31,7 +31,6 @@ */ #include "avcodec.h" -#include "dsputil.h" #include "mpegvideo.h" #include "mjpeg.h" #include "mjpegenc.h" @@ -397,7 +396,7 @@ void ff_mjpeg_encode_dc(MpegEncContext *s, int val, } } -static void encode_block(MpegEncContext *s, DCTELEM *block, int n) +static void encode_block(MpegEncContext *s, int16_t *block, int n) { int mant, nbits, code, i, j; int component, dc, run, last_index, val; @@ -455,7 +454,7 @@ static void encode_block(MpegEncContext *s, DCTELEM *block, int n) put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]); } -void ff_mjpeg_encode_mb(MpegEncContext *s, DCTELEM block[6][64]) +void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[6][64]) { int i; if (s->chroma_format == CHROMA_444) { diff --git a/mythtv/external/FFmpeg/libavcodec/mjpegenc.h b/mythtv/external/FFmpeg/libavcodec/mjpegenc.h index 06f77c6a15e..ce0c1cce153 100644 --- a/mythtv/external/FFmpeg/libavcodec/mjpegenc.h +++ b/mythtv/external/FFmpeg/libavcodec/mjpegenc.h @@ -33,7 +33,8 @@ #ifndef AVCODEC_MJPEGENC_H #define AVCODEC_MJPEGENC_H -#include "dsputil.h" +#include + #include "mpegvideo.h" typedef struct MJpegContext { @@ -55,6 +56,6 @@ void ff_mjpeg_encode_picture_trailer(MpegEncContext *s); void ff_mjpeg_encode_stuffing(MpegEncContext *s); void ff_mjpeg_encode_dc(MpegEncContext *s, int val, uint8_t *huff_size, uint16_t *huff_code); -void ff_mjpeg_encode_mb(MpegEncContext *s, DCTELEM block[6][64]); +void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[6][64]); #endif /* AVCODEC_MJPEGENC_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/mlp_parser.c b/mythtv/external/FFmpeg/libavcodec/mlp_parser.c index b2fd6007d60..2cc4b9153a2 100644 --- a/mythtv/external/FFmpeg/libavcodec/mlp_parser.c +++ b/mythtv/external/FFmpeg/libavcodec/mlp_parser.c @@ -330,16 +330,45 @@ static int mlp_parse(AVCodecParserContext *s, if(!avctx->channels || !avctx->channel_layout) { if (mh.stream_type == 0xbb) { /* MLP stream */ - avctx->channels = mh.channels_mlp; - avctx->channel_layout = mh.channel_layout_mlp; +#if FF_API_REQUEST_CHANNELS + if (avctx->request_channels > 0 && avctx->request_channels <= 2 && + mh.num_substreams > 1) { + avctx->channels = 2; + avctx->channel_layout = AV_CH_LAYOUT_STEREO; + } else +#endif + if (avctx->request_channel_layout == AV_CH_LAYOUT_STEREO && + mh.num_substreams > 1) { + avctx->channels = 2; + avctx->channel_layout = AV_CH_LAYOUT_STEREO; + } else { + avctx->channels = mh.channels_mlp; + avctx->channel_layout = mh.channel_layout_mlp; + } } else { /* mh.stream_type == 0xba */ /* TrueHD stream */ - if (mh.channels_thd_stream2) { - avctx->channels = mh.channels_thd_stream2; - avctx->channel_layout = mh.channel_layout_thd_stream2; - } else { +#if FF_API_REQUEST_CHANNELS + if (avctx->request_channels > 0 && avctx->request_channels <= 2 && + mh.num_substreams > 1) { + avctx->channels = 2; + avctx->channel_layout = AV_CH_LAYOUT_STEREO; + } else if (avctx->request_channels > 0 && + avctx->request_channels <= mh.channels_thd_stream1) { avctx->channels = mh.channels_thd_stream1; avctx->channel_layout = mh.channel_layout_thd_stream1; + } else +#endif + if (avctx->request_channel_layout == AV_CH_LAYOUT_STEREO && + mh.num_substreams > 1) { + avctx->channels = 2; + avctx->channel_layout = AV_CH_LAYOUT_STEREO; + } else if (avctx->request_channel_layout == mh.channel_layout_thd_stream1 || + !mh.channels_thd_stream2) { + avctx->channels = mh.channels_thd_stream1; + avctx->channel_layout = mh.channel_layout_thd_stream1; + } else { + avctx->channels = mh.channels_thd_stream2; + avctx->channel_layout = mh.channel_layout_thd_stream2; } } } diff --git a/mythtv/external/FFmpeg/libavcodec/mlp_parser.h b/mythtv/external/FFmpeg/libavcodec/mlp_parser.h index 4175e6c8cd1..9967abbad20 100644 --- a/mythtv/external/FFmpeg/libavcodec/mlp_parser.h +++ b/mythtv/external/FFmpeg/libavcodec/mlp_parser.h @@ -31,13 +31,13 @@ typedef struct MLPHeaderInfo { - int stream_type; ///< 0xBB for MLP, 0xBA for TrueHD + int stream_type; ///< 0xBB for MLP, 0xBA for TrueHD - int group1_bits; ///< The bit depth of the first substream - int group2_bits; ///< Bit depth of the second substream (MLP only) + int group1_bits; ///< The bit depth of the first substream + int group2_bits; ///< Bit depth of the second substream (MLP only) - int group1_samplerate; ///< Sample rate of first substream - int group2_samplerate; ///< Sample rate of second substream (MLP only) + int group1_samplerate; ///< Sample rate of first substream + int group2_samplerate; ///< Sample rate of second substream (MLP only) int channel_arrangement; int channels_mlp; ///< Channel count for MLP streams @@ -47,13 +47,13 @@ typedef struct MLPHeaderInfo uint64_t channel_layout_thd_stream1; ///< Channel layout for substream 1 of TrueHD streams ("6-channel presentation") uint64_t channel_layout_thd_stream2; ///< Channel layout for substream 2 of TrueHD streams ("8-channel presentation") - int access_unit_size; ///< Number of samples per coded frame - int access_unit_size_pow2; ///< Next power of two above number of samples per frame + int access_unit_size; ///< Number of samples per coded frame + int access_unit_size_pow2; ///< Next power of two above number of samples per frame - int is_vbr; ///< Stream is VBR instead of CBR - int peak_bitrate; ///< Peak bitrate for VBR, actual bitrate (==peak) for CBR + int is_vbr; ///< Stream is VBR instead of CBR + int peak_bitrate; ///< Peak bitrate for VBR, actual bitrate (==peak) for CBR - int num_substreams; ///< Number of substreams within stream + int num_substreams; ///< Number of substreams within stream } MLPHeaderInfo; diff --git a/mythtv/external/FFmpeg/libavcodec/mlpdec.c b/mythtv/external/FFmpeg/libavcodec/mlpdec.c index 28b5502ad0a..c763624f1c3 100644 --- a/mythtv/external/FFmpeg/libavcodec/mlpdec.c +++ b/mythtv/external/FFmpeg/libavcodec/mlpdec.c @@ -118,7 +118,6 @@ typedef struct SubStream { typedef struct MLPDecodeContext { AVCodecContext *avctx; - AVFrame frame; /// Current access unit being read has a major sync. int is_major_sync_unit; @@ -271,9 +270,6 @@ static av_cold int mlp_decode_init(AVCodecContext *avctx) m->substream[substr].lossless_check_data = 0xffffffff; ff_mlpdsp_init(&m->dsp); - avcodec_get_frame_defaults(&m->frame); - avctx->coded_frame = &m->frame; - return 0; } @@ -462,14 +458,24 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp, s->max_channel = max_channel; s->max_matrix_channel = matrix_channel; - if (m->avctx->request_channels > 0 - && s->max_channel + 1 >= m->avctx->request_channels - && substr < m->max_decoded_substream) { +#if FF_API_REQUEST_CHANNELS + if (m->avctx->request_channels > 0 && + m->avctx->request_channels <= s->max_channel + 1 && + m->max_decoded_substream > substr) { av_log(m->avctx, AV_LOG_DEBUG, - "Extracting %d channel downmix from substream %d. " + "Extracting %d-channel downmix from substream %d. " "Further substreams will be skipped.\n", s->max_channel + 1, substr); m->max_decoded_substream = substr; + } else +#endif + if (m->avctx->request_channel_layout == s->ch_layout && + m->max_decoded_substream > substr) { + av_log(m->avctx, AV_LOG_DEBUG, + "Extracting %d-channel downmix (0x%"PRIx64") from substream %d. " + "Further substreams will be skipped.\n", + s->max_channel + 1, s->ch_layout, substr); + m->max_decoded_substream = substr; } s->noise_shift = get_bits(gbp, 4); @@ -500,7 +506,7 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp, ch_assign = av_get_channel_layout_channel_index(s->ch_layout, channel); } - if (ch_assign > s->max_matrix_channel) { + if ((unsigned)ch_assign > s->max_matrix_channel) { av_log_ask_for_sample(m->avctx, "Assignment of matrix channel %d to invalid output channel %d.\n", ch, ch_assign); @@ -509,19 +515,6 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp, s->ch_assign[ch_assign] = ch; } - if (m->avctx->codec_id == AV_CODEC_ID_MLP && m->needs_reordering) { - if (m->avctx->channel_layout == (AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY) || - m->avctx->channel_layout == AV_CH_LAYOUT_5POINT0_BACK) { - int i = s->ch_assign[4]; - s->ch_assign[4] = s->ch_assign[3]; - s->ch_assign[3] = s->ch_assign[2]; - s->ch_assign[2] = i; - } else if (m->avctx->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) { - FFSWAP(int, s->ch_assign[2], s->ch_assign[4]); - FFSWAP(int, s->ch_assign[3], s->ch_assign[5]); - } - } - checksum = ff_mlp_restart_checksum(buf, get_bits_count(gbp) - start_count); if (checksum != get_bits(gbp, 8)) @@ -553,6 +546,20 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp, if (substr == m->max_decoded_substream) { m->avctx->channels = s->max_matrix_channel + 1; m->avctx->channel_layout = s->ch_layout; + + if (m->avctx->codec_id == AV_CODEC_ID_MLP && m->needs_reordering) { + if (m->avctx->channel_layout == (AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY) || + m->avctx->channel_layout == AV_CH_LAYOUT_5POINT0_BACK) { + int i = s->ch_assign[4]; + s->ch_assign[4] = s->ch_assign[3]; + s->ch_assign[3] = s->ch_assign[2]; + s->ch_assign[2] = i; + } else if (m->avctx->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) { + FFSWAP(int, s->ch_assign[2], s->ch_assign[4]); + FFSWAP(int, s->ch_assign[3], s->ch_assign[5]); + } + } + } return 0; @@ -994,7 +1001,7 @@ static void rematrix_channels(MLPDecodeContext *m, unsigned int substr) /** Write the audio data into the output buffer. */ static int output_data(MLPDecodeContext *m, unsigned int substr, - void *data, int *got_frame_ptr) + AVFrame *frame, int *got_frame_ptr) { AVCodecContext *avctx = m->avctx; SubStream *s = &m->substream[substr]; @@ -1015,13 +1022,13 @@ static int output_data(MLPDecodeContext *m, unsigned int substr, } /* get output buffer */ - m->frame.nb_samples = s->blockpos; - if ((ret = ff_get_buffer(avctx, &m->frame)) < 0) { + frame->nb_samples = s->blockpos; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - data_32 = (int32_t *)m->frame.data[0]; - data_16 = (int16_t *)m->frame.data[0]; + data_32 = (int32_t *)frame->data[0]; + data_16 = (int16_t *)frame->data[0]; for (i = 0; i < s->blockpos; i++) { for (out_ch = 0; out_ch <= s->max_matrix_channel; out_ch++) { @@ -1034,8 +1041,7 @@ static int output_data(MLPDecodeContext *m, unsigned int substr, } } - *got_frame_ptr = 1; - *(AVFrame *)data = m->frame; + *got_frame_ptr = 1; return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/mmvideo.c b/mythtv/external/FFmpeg/libavcodec/mmvideo.c index c61cd576e49..b74424cc138 100644 --- a/mythtv/external/FFmpeg/libavcodec/mmvideo.c +++ b/mythtv/external/FFmpeg/libavcodec/mmvideo.c @@ -104,6 +104,9 @@ static int mm_decode_intra(MmContext * s, int half_horiz, int half_vert) if (half_horiz) run_length *=2; + if (run_length > s->avctx->width - x) + return AVERROR_INVALIDDATA; + if (color) { memset(s->frame.data[0] + y*s->frame.linesize[0] + x, color, run_length); if (half_vert) @@ -151,6 +154,8 @@ static int mm_decode_inter(MmContext * s, int half_horiz, int half_vert) int replace_array = bytestream2_get_byte(&s->gb); for(j=0; j<8; j++) { int replace = (replace_array >> (7-j)) & 1; + if (x + half_horiz >= s->avctx->width) + return AVERROR_INVALIDDATA; if (replace) { int color = bytestream2_get_byte(&data_ptr); s->frame.data[0][y*s->frame.linesize[0] + x] = color; diff --git a/mythtv/external/FFmpeg/libavcodec/motion-test.c b/mythtv/external/FFmpeg/libavcodec/motion-test.c index 2cdb1c07553..53cfedbe76e 100644 --- a/mythtv/external/FFmpeg/libavcodec/motion-test.c +++ b/mythtv/external/FFmpeg/libavcodec/motion-test.c @@ -127,12 +127,12 @@ int main(int argc, char **argv) printf("ffmpeg motion test\n"); ctx = avcodec_alloc_context3(NULL); - ctx->dsp_mask = AV_CPU_FLAG_FORCE; + ctx->flags |= CODEC_FLAG_BITEXACT; memset(&cctx, 0, sizeof(cctx)); ff_dsputil_init(&cctx, ctx); for (c = 0; c < flags_size; c++) { int x; - ctx->dsp_mask = AV_CPU_FLAG_FORCE | flags[c]; + av_force_cpu_flags(flags[c]); memset(&mmxctx, 0, sizeof(mmxctx)); ff_dsputil_init(&mmxctx, ctx); diff --git a/mythtv/external/FFmpeg/libavcodec/motion_est.c b/mythtv/external/FFmpeg/libavcodec/motion_est.c index a303d379b1c..d9d6a1fd9d0 100644 --- a/mythtv/external/FFmpeg/libavcodec/motion_est.c +++ b/mythtv/external/FFmpeg/libavcodec/motion_est.c @@ -32,7 +32,6 @@ #include #include "avcodec.h" -#include "dsputil.h" #include "mathops.h" #include "mpegvideo.h" @@ -290,7 +289,7 @@ static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){ return 0; } -static void zero_hpel(uint8_t *a, const uint8_t *b, int stride, int h){ +static void zero_hpel(uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h){ } int ff_init_me(MpegEncContext *s){ @@ -516,6 +515,7 @@ static inline void get_limits(MpegEncContext *s, int x, int y) { MotionEstContext * const c= &s->me; int range= c->avctx->me_range >> (1 + !!(c->flags&FLAG_QPEL)); + int max_range = MAX_MV >> (1 + !!(c->flags&FLAG_QPEL)); /* if(c->avctx->me_range) c->range= c->avctx->me_range >> 1; else c->range= 16; @@ -537,6 +537,8 @@ static inline void get_limits(MpegEncContext *s, int x, int y) c->xmax = - x + s->mb_width *16 - 16; c->ymax = - y + s->mb_height*16 - 16; } + if(!range || range > max_range) + range = max_range; if(range){ c->xmin = FFMAX(c->xmin,-range); c->xmax = FFMIN(c->xmax, range); @@ -984,6 +986,30 @@ static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int return d; } +static inline int get_penalty_factor(int lambda, int lambda2, int type){ + switch(type&0xFF){ + default: + case FF_CMP_SAD: + return lambda>>FF_LAMBDA_SHIFT; + case FF_CMP_DCT: + return (3*lambda)>>(FF_LAMBDA_SHIFT+1); + case FF_CMP_W53: + return (4*lambda)>>(FF_LAMBDA_SHIFT); + case FF_CMP_W97: + return (2*lambda)>>(FF_LAMBDA_SHIFT); + case FF_CMP_SATD: + case FF_CMP_DCT264: + return (2*lambda)>>FF_LAMBDA_SHIFT; + case FF_CMP_RD: + case FF_CMP_PSNR: + case FF_CMP_SSE: + case FF_CMP_NSSE: + return lambda2>>FF_LAMBDA_SHIFT; + case FF_CMP_BIT: + return 1; + } +} + void ff_estimate_p_frame_motion(MpegEncContext * s, int mb_x, int mb_y) { @@ -1089,7 +1115,6 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, vard = s->dsp.sse[0](NULL, pix, ppix, s->linesize, 16); pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8; -// pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin; c->mc_mb_var_sum_temp += (vard+128)>>8; if(mb_type){ @@ -1168,7 +1193,6 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, } } -// pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin; set_p_mv_tables(s, mx, my, mb_type!=CANDIDATE_MB_TYPE_INTER4V); /* get intra luma score */ diff --git a/mythtv/external/FFmpeg/libavcodec/motionpixels.c b/mythtv/external/FFmpeg/libavcodec/motionpixels.c index 61a718c5a93..4fa45e9c5db 100644 --- a/mythtv/external/FFmpeg/libavcodec/motionpixels.c +++ b/mythtv/external/FFmpeg/libavcodec/motionpixels.c @@ -101,38 +101,48 @@ static void mp_read_changes_map(MotionPixelsContext *mp, GetBitContext *gb, int } } -static void mp_get_code(MotionPixelsContext *mp, GetBitContext *gb, int size, int code) +static int mp_get_code(MotionPixelsContext *mp, GetBitContext *gb, int size, int code) { while (get_bits1(gb)) { ++size; if (size > mp->max_codes_bits) { av_log(mp->avctx, AV_LOG_ERROR, "invalid code size %d/%d\n", size, mp->max_codes_bits); - return; + return AVERROR_INVALIDDATA; } code <<= 1; - mp_get_code(mp, gb, size, code + 1); + if (mp_get_code(mp, gb, size, code + 1) < 0) + return AVERROR_INVALIDDATA; } if (mp->current_codes_count >= MAX_HUFF_CODES) { av_log(mp->avctx, AV_LOG_ERROR, "too many codes\n"); - return; + return AVERROR_INVALIDDATA; } + mp->codes[mp->current_codes_count ].code = code; mp->codes[mp->current_codes_count++].size = size; + return 0; } -static void mp_read_codes_table(MotionPixelsContext *mp, GetBitContext *gb) +static int mp_read_codes_table(MotionPixelsContext *mp, GetBitContext *gb) { if (mp->codes_count == 1) { mp->codes[0].delta = get_bits(gb, 4); } else { int i; + int ret; mp->max_codes_bits = get_bits(gb, 4); for (i = 0; i < mp->codes_count; ++i) mp->codes[i].delta = get_bits(gb, 4); mp->current_codes_count = 0; - mp_get_code(mp, gb, 0, 0); + if ((ret = mp_get_code(mp, gb, 0, 0)) < 0) + return ret; + if (mp->current_codes_count < mp->codes_count) { + av_log(mp->avctx, AV_LOG_ERROR, "too few codes\n"); + return AVERROR_INVALIDDATA; + } } + return 0; } static int mp_gradient(MotionPixelsContext *mp, int component, int v) @@ -287,7 +297,8 @@ static int mp_decode_frame(AVCodecContext *avctx, *(uint16_t *)mp->frame.data[0] = get_bits(&gb, 15); mp->changes_map[0] = 1; } - mp_read_codes_table(mp, &gb); + if (mp_read_codes_table(mp, &gb) < 0) + goto end; sz = get_bits(&gb, 18); if (avctx->extradata[0] != 5) diff --git a/mythtv/external/FFmpeg/libavcodec/mpc.c b/mythtv/external/FFmpeg/libavcodec/mpc.c index d064924b910..3bd2d357880 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpc.c +++ b/mythtv/external/FFmpeg/libavcodec/mpc.c @@ -28,7 +28,6 @@ #include "avcodec.h" #include "get_bits.h" -#include "dsputil.h" #include "mpegaudiodsp.h" #include "mpegaudio.h" diff --git a/mythtv/external/FFmpeg/libavcodec/mpc.h b/mythtv/external/FFmpeg/libavcodec/mpc.h index 7ee402b3560..295b4c7aef8 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpc.h +++ b/mythtv/external/FFmpeg/libavcodec/mpc.h @@ -50,7 +50,6 @@ typedef struct Band { }Band; typedef struct MPCContext { - AVFrame frame; DSPContext dsp; MPADSPContext mpadsp; GetBitContext gb; diff --git a/mythtv/external/FFmpeg/libavcodec/mpc7.c b/mythtv/external/FFmpeg/libavcodec/mpc7.c index 2326a9bd8bc..d4f5e2d4163 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpc7.c +++ b/mythtv/external/FFmpeg/libavcodec/mpc7.c @@ -26,6 +26,7 @@ */ #include "libavutil/channel_layout.h" +#include "libavutil/internal.h" #include "libavutil/lfg.h" #include "avcodec.h" #include "get_bits.h" @@ -94,9 +95,6 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx) avctx->sample_fmt = AV_SAMPLE_FMT_S16P; avctx->channel_layout = AV_CH_LAYOUT_STEREO; - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - if(vlc_initialized) return 0; av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); scfi_vlc.table = scfi_table; @@ -196,6 +194,7 @@ static int get_scale_idx(GetBitContext *gb, int ref) static int mpc7_decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size; MPCContext *c = avctx->priv_data; @@ -225,8 +224,8 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data, buf_size -= 4; /* get output buffer */ - c->frame.nb_samples = MPC_FRAME_SIZE; - if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = MPC_FRAME_SIZE; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -294,9 +293,9 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data, for(ch = 0; ch < 2; ch++) idx_to_quant(c, &gb, bands[i].res[ch], c->Q[ch] + off); - ff_mpc_dequantize_and_synth(c, mb, (int16_t **)c->frame.extended_data, 2); + ff_mpc_dequantize_and_synth(c, mb, (int16_t **)frame->extended_data, 2); if(last_frame) - c->frame.nb_samples = c->lastframelen; + frame->nb_samples = c->lastframelen; bits_used = get_bits_count(&gb); bits_avail = buf_size * 8; @@ -310,8 +309,7 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data, return avpkt->size; } - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return avpkt->size; } diff --git a/mythtv/external/FFmpeg/libavcodec/mpc8.c b/mythtv/external/FFmpeg/libavcodec/mpc8.c index a6bb5801c57..489737a8c99 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpc8.c +++ b/mythtv/external/FFmpeg/libavcodec/mpc8.c @@ -144,9 +144,6 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx) avctx->channel_layout = (channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; avctx->channels = channels; - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - if(vlc_initialized) return 0; av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); @@ -244,6 +241,7 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx) static int mpc8_decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MPCContext *c = avctx->priv_data; @@ -255,8 +253,8 @@ static int mpc8_decode_frame(AVCodecContext * avctx, void *data, int last[2]; /* get output buffer */ - c->frame.nb_samples = MPC_FRAME_SIZE; - if ((res = ff_get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = MPC_FRAME_SIZE; + if ((res = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return res; } @@ -415,7 +413,7 @@ static int mpc8_decode_frame(AVCodecContext * avctx, void *data, } ff_mpc_dequantize_and_synth(c, maxband - 1, - (int16_t **)c->frame.extended_data, + (int16_t **)frame->extended_data, avctx->channels); c->cur_frame++; @@ -426,8 +424,7 @@ static int mpc8_decode_frame(AVCodecContext * avctx, void *data, if(c->cur_frame >= c->frames) c->cur_frame = 0; - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return c->cur_frame ? c->last_bits_used >> 3 : buf_size; } diff --git a/mythtv/external/FFmpeg/libavcodec/mpeg12.c b/mythtv/external/FFmpeg/libavcodec/mpeg12.c index 4808c7c3795..ccc1ddbb422 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpeg12.c +++ b/mythtv/external/FFmpeg/libavcodec/mpeg12.c @@ -81,7 +81,7 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) return sign_extend(val, 5 + shift); } -static inline int mpeg1_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n) +static inline int mpeg1_decode_block_intra(MpegEncContext *s, int16_t *block, int n) { int level, dc, diff, i, j, run; int component; @@ -152,12 +152,12 @@ static inline int mpeg1_decode_block_intra(MpegEncContext *s, DCTELEM *block, in return 0; } -int ff_mpeg1_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n) +int ff_mpeg1_decode_block_intra(MpegEncContext *s, int16_t *block, int n) { return mpeg1_decode_block_intra(s, block, n); } -static inline int mpeg1_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n) +static inline int mpeg1_decode_block_inter(MpegEncContext *s, int16_t *block, int n) { int level, i, j, run; RLTable *rl = &ff_rl_mpeg1; @@ -237,7 +237,7 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s, DCTELEM *block, in * Changing this would eat up any speed benefits it has. * Do not use "fast" flag if you need the code to be robust. */ -static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n) +static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, int16_t *block, int n) { int level, i, j, run; RLTable *rl = &ff_rl_mpeg1; @@ -309,7 +309,7 @@ static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *bloc } -static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n) +static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, int16_t *block, int n) { int level, i, j, run; RLTable *rl = &ff_rl_mpeg1; @@ -394,7 +394,7 @@ static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, DCTELEM *block * Do not use "fast" flag if you need the code to be robust. */ static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, - DCTELEM *block, int n) + int16_t *block, int n) { int level, i, j, run; RLTable *rl = &ff_rl_mpeg1; @@ -455,7 +455,7 @@ static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, } -static inline int mpeg2_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n) +static inline int mpeg2_decode_block_intra(MpegEncContext *s, int16_t *block, int n) { int level, dc, diff, i, j, run; int component; @@ -538,7 +538,7 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s, DCTELEM *block, in * Changing this would eat up any speed benefits it has. * Do not use "fast" flag if you need the code to be robust. */ -static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n) +static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, int16_t *block, int n) { int level, dc, diff, j, run; int component; @@ -737,7 +737,7 @@ static inline int get_qscale(MpegEncContext *s) static void exchange_uv(MpegEncContext *s) { - DCTELEM (*tmp)[64]; + int16_t (*tmp)[64]; tmp = s->pblocks[4]; s->pblocks[4] = s->pblocks[5]; @@ -750,7 +750,7 @@ static void exchange_uv(MpegEncContext *s) #define MT_16X8 2 #define MT_DMV 3 -static int mpeg_decode_mb(MpegEncContext *s, DCTELEM block[12][64]) +static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64]) { int i, j, k, cbp, val, mb_type, motion_type; const int mb_block_count = 4 + (1 << s->chroma_format); @@ -1349,7 +1349,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx) avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt); // until then pix_fmt may be changed right after codec init if (avctx->pix_fmt == AV_PIX_FMT_XVMC_MPEG2_IDCT || - avctx->hwaccel ) + avctx->hwaccel || uses_vdpau(avctx)) if (avctx->idct_algo == FF_IDCT_AUTO) avctx->idct_algo = FF_IDCT_SIMPLE; @@ -1609,7 +1609,7 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size) if (ff_MPV_frame_start(s, avctx) < 0) return -1; - ff_er_frame_start(s); + ff_mpeg_er_frame_start(s); /* first check if we must repeat the frame */ s->current_picture_ptr->f.repeat_pict = 0; @@ -1809,7 +1809,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y, if (++s->mb_x >= s->mb_width) { const int mb_size = 16 >> s->avctx->lowres; - ff_draw_horiz_band(s, mb_size*(s->mb_y >> field_pic), mb_size); + ff_mpeg_draw_horiz_band(s, mb_size*(s->mb_y >> field_pic), mb_size); ff_MPV_report_decode_progress(s); s->mb_x = 0; @@ -1821,6 +1821,15 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y, && s->intra_dc_precision == 2 && s->q_scale_type == 1 && s->alternate_scan == 0 && s->progressive_frame == 0 /* vbv_delay == 0xBBB || 0xE10*/; + if (left >= 32 && !is_d10) { + GetBitContext gb = s->gb; + align_get_bits(&gb); + if (show_bits(&gb, 24) == 0x060E2B) { + av_log(avctx, AV_LOG_DEBUG, "Invalid MXF data found in video stream\n"); + is_d10 = 1; + } + } + if (left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10) || ((avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_AGGRESSIVE)) && left > 8)) { av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X\n", left, show_bits(&s->gb, FFMIN(left, 23))); @@ -1903,7 +1912,7 @@ static int slice_decode_thread(AVCodecContext *c, void *arg) int mb_y = s->start_mb_y; const int field_pic = s->picture_structure != PICT_FRAME; - s->error_count = (3 * (s->end_mb_y - s->start_mb_y) * s->mb_width) >> field_pic; + s->er.error_count = (3 * (s->end_mb_y - s->start_mb_y) * s->mb_width) >> field_pic; for (;;) { uint32_t start_code; @@ -1913,14 +1922,14 @@ static int slice_decode_thread(AVCodecContext *c, void *arg) emms_c(); av_dlog(c, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n", ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, - s->start_mb_y, s->end_mb_y, s->error_count); + s->start_mb_y, s->end_mb_y, s->er.error_count); if (ret < 0) { if (c->err_recognition & AV_EF_EXPLODE) return ret; if (s->resync_mb_x >= 0 && s->resync_mb_y >= 0) - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR); } else { - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_AC_END | ER_DC_END | ER_MV_END); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_AC_END | ER_DC_END | ER_MV_END); } if (s->mb_y == s->end_mb_y) @@ -1965,7 +1974,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict) s->current_picture_ptr->f.qscale_type = FF_QSCALE_TYPE_MPEG2; - ff_er_frame_end(s); + ff_er_frame_end(&s->er); ff_MPV_frame_end(s); @@ -2085,7 +2094,7 @@ static int vcr2_init_sequence(AVCodecContext *avctx) avctx->pix_fmt = mpeg_get_pixelformat(avctx); avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt); - if( avctx->pix_fmt == AV_PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel ) + if (avctx->pix_fmt == AV_PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel || uses_vdpau(avctx)) if (avctx->idct_algo == FF_IDCT_AUTO) avctx->idct_algo = FF_IDCT_SIMPLE; @@ -2446,6 +2455,7 @@ static int decode_chunks(AVCodecContext *avctx, const uint8_t *buf_end = buf + buf_size; int ret, input_size; int last_code = 0; + int picture_start_code_seen = 0; for (;;) { /* find next start code */ @@ -2459,7 +2469,7 @@ static int decode_chunks(AVCodecContext *avctx, avctx->execute(avctx, slice_decode_thread, &s2->thread_context[0], NULL, s->slice_count, sizeof(void*)); for (i = 0; i < s->slice_count; i++) - s2->error_count += s2->thread_context[i]->error_count; + s2->er.error_count += s2->thread_context[i]->er.error_count; } if (CONFIG_VDPAU && uses_vdpau(avctx)) @@ -2496,6 +2506,14 @@ static int decode_chunks(AVCodecContext *avctx, break; case PICTURE_START_CODE: + if (picture_start_code_seen && s2->picture_structure == PICT_FRAME) { + /* If it's a frame picture, there can't be more than one picture header. + Yet, it does happen and we need to handle it. */ + av_log(avctx, AV_LOG_WARNING, "ignoring extra picture following a frame-picture\n"); + break; + } + picture_start_code_seen = 1; + if (s2->width <= 0 || s2->height <= 0) { av_log(avctx, AV_LOG_ERROR, "%dx%d is invalid\n", s2->width, s2->height); return AVERROR_INVALIDDATA; @@ -2512,7 +2530,7 @@ static int decode_chunks(AVCodecContext *avctx, s2->thread_context, NULL, s->slice_count, sizeof(void*)); for (i = 0; i < s->slice_count; i++) - s2->error_count += s2->thread_context[i]->error_count; + s2->er.error_count += s2->thread_context[i]->er.error_count; s->slice_count = 0; } if (last_code == 0 || last_code == SLICE_MIN_START_CODE) { @@ -2701,9 +2719,9 @@ static int decode_chunks(AVCodecContext *avctx, if (avctx->err_recognition & AV_EF_EXPLODE) return ret; if (s2->resync_mb_x >= 0 && s2->resync_mb_y >= 0) - ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR); + ff_er_add_slice(&s2->er, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR); } else { - ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, ER_AC_END | ER_DC_END | ER_MV_END); + ff_er_add_slice(&s2->er, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, ER_AC_END | ER_DC_END | ER_MV_END); } } } diff --git a/mythtv/external/FFmpeg/libavcodec/mpeg12.h b/mythtv/external/FFmpeg/libavcodec/mpeg12.h index 6e60c8695f7..1f369176a57 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpeg12.h +++ b/mythtv/external/FFmpeg/libavcodec/mpeg12.h @@ -71,6 +71,6 @@ static inline int decode_dc(GetBitContext *gb, int component) return diff; } -extern int ff_mpeg1_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n); +extern int ff_mpeg1_decode_block_intra(MpegEncContext *s, int16_t *block, int n); #endif /* AVCODEC_MPEG12_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/mpeg12enc.c b/mythtv/external/FFmpeg/libavcodec/mpeg12enc.c index f2b5c05f0dd..c8e7b45287d 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpeg12enc.c +++ b/mythtv/external/FFmpeg/libavcodec/mpeg12enc.c @@ -26,7 +26,6 @@ */ #include "avcodec.h" -#include "dsputil.h" #include "mathops.h" #include "mpegvideo.h" @@ -52,7 +51,7 @@ static const uint8_t svcd_scan_offset_placeholder[14] = { }; static void mpeg1_encode_block(MpegEncContext *s, - DCTELEM *block, + int16_t *block, int component); static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code); // RAL: f_code parameter added @@ -471,7 +470,7 @@ static inline void put_mb_modes(MpegEncContext *s, int n, int bits, } static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s, - DCTELEM block[6][64], + int16_t block[6][64], int motion_x, int motion_y, int mb_block_count) { @@ -695,7 +694,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s, } } -void ff_mpeg1_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y) +void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y) { if (s->chroma_format == CHROMA_420) mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6); else mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8); @@ -878,7 +877,7 @@ static inline void encode_dc(MpegEncContext *s, int diff, int component) } static void mpeg1_encode_block(MpegEncContext *s, - DCTELEM *block, + int16_t *block, int n) { int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign; diff --git a/mythtv/external/FFmpeg/libavcodec/mpeg4audio.c b/mythtv/external/FFmpeg/libavcodec/mpeg4audio.c index 8aa32192071..68448e6fa2a 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpeg4audio.c +++ b/mythtv/external/FFmpeg/libavcodec/mpeg4audio.c @@ -84,10 +84,8 @@ int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, GetBitContext gb; int specific_config_bitindex; - if(bit_size<=0) + if (bit_size <= 0 || init_get_bits(&gb, buf, bit_size) < 0) return AVERROR_INVALIDDATA; - - init_get_bits(&gb, buf, bit_size); c->object_type = get_object_type(&gb); c->sample_rate = get_sample_rate(&gb, &c->sampling_index); c->chan_config = get_bits(&gb, 4); diff --git a/mythtv/external/FFmpeg/libavcodec/mpeg4video.h b/mythtv/external/FFmpeg/libavcodec/mpeg4video.h index 97c39b6ed6e..400ce4d1848 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpeg4video.h +++ b/mythtv/external/FFmpeg/libavcodec/mpeg4video.h @@ -83,9 +83,9 @@ extern const uint16_t ff_mpeg4_resync_prefix[8]; extern const uint8_t ff_mpeg4_dc_threshold[8]; void ff_mpeg4_encode_mb(MpegEncContext *s, - DCTELEM block[6][64], + int16_t block[6][64], int motion_x, int motion_y); -void ff_mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n, +void ff_mpeg4_pred_ac(MpegEncContext * s, int16_t *block, int n, int dir); void ff_set_mpeg4_time(MpegEncContext * s); void ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); diff --git a/mythtv/external/FFmpeg/libavcodec/mpeg4videodec.c b/mythtv/external/FFmpeg/libavcodec/mpeg4videodec.c index 58920649656..56b6a97299e 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpeg4videodec.c +++ b/mythtv/external/FFmpeg/libavcodec/mpeg4videodec.c @@ -53,7 +53,7 @@ static const int mb_type_b_map[4]= { * @param n block index (0-3 are luma, 4-5 are chroma) * @param dir the ac prediction direction */ -void ff_mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n, +void ff_mpeg4_pred_ac(MpegEncContext * s, int16_t *block, int n, int dir) { int i; @@ -801,13 +801,13 @@ int ff_mpeg4_decode_partitions(MpegEncContext *s) mb_num= mpeg4_decode_partition_a(s); if(mb_num<0){ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error); return -1; } if(s->resync_mb_x + s->resync_mb_y*s->mb_width + mb_num > s->mb_num){ av_log(s->avctx, AV_LOG_ERROR, "slice below monitor ...\n"); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error); return -1; } @@ -828,15 +828,15 @@ int ff_mpeg4_decode_partitions(MpegEncContext *s) return -1; } } - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, part_a_end); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, part_a_end); if( mpeg4_decode_partition_b(s, mb_num) < 0){ if(s->pict_type==AV_PICTURE_TYPE_P) - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_DC_ERROR); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_DC_ERROR); return -1; }else{ if(s->pict_type==AV_PICTURE_TYPE_P) - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_DC_END); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_DC_END); } return 0; @@ -846,7 +846,7 @@ int ff_mpeg4_decode_partitions(MpegEncContext *s) * Decode a block. * @return <0 if an error occurred */ -static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, +static inline int mpeg4_decode_block(MpegEncContext * s, int16_t * block, int n, int coded, int intra, int rvlc) { int level, i, last, run; @@ -1092,7 +1092,7 @@ static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, * decode partition C of one MB. * @return <0 if an error occurred */ -static int mpeg4_decode_partitioned_mb(MpegEncContext *s, DCTELEM block[6][64]) +static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64]) { int cbp, mb_type; const int xy= s->mb_x + s->mb_y*s->mb_stride; @@ -1175,7 +1175,7 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, DCTELEM block[6][64]) } static int mpeg4_decode_mb(MpegEncContext *s, - DCTELEM block[6][64]) + int16_t block[6][64]) { int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; int16_t *mot_val; @@ -2364,7 +2364,7 @@ AVCodec ff_mpeg4_decoder = { .flush = ff_mpeg_flush, .max_lowres = 3, .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2"), - .pix_fmts = ff_hwaccel_pixfmt_list_420, + .pix_fmts = ff_h263_hwaccel_pixfmt_list_420, .profiles = NULL_IF_CONFIG_SMALL(mpeg4_video_profiles), .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_mpeg_update_thread_context), .priv_class = &mpeg4_class, diff --git a/mythtv/external/FFmpeg/libavcodec/mpeg4videoenc.c b/mythtv/external/FFmpeg/libavcodec/mpeg4videoenc.c index f6555037baa..a575a09dbac 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpeg4videoenc.c +++ b/mythtv/external/FFmpeg/libavcodec/mpeg4videoenc.c @@ -59,7 +59,7 @@ max run: 29/41 * Return the number of bits that encoding the 8x8 block in block would need. * @param[in] block_last_index last index in scantable order that refers to a non zero element in block. */ -static inline int get_block_rate(MpegEncContext * s, DCTELEM block[64], int block_last_index, uint8_t scantable[64]){ +static inline int get_block_rate(MpegEncContext * s, int16_t block[64], int block_last_index, uint8_t scantable[64]){ int last=0; int j; int rate=0; @@ -91,7 +91,7 @@ static inline int get_block_rate(MpegEncContext * s, DCTELEM block[64], int bloc * @param[out] st scantable for each 8x8 block * @param[in] zigzag_last_index index referring to the last non zero coefficient in zigzag order */ -static inline void restore_ac_coeffs(MpegEncContext * s, DCTELEM block[6][64], const int dir[6], uint8_t *st[6], const int zigzag_last_index[6]) +static inline void restore_ac_coeffs(MpegEncContext * s, int16_t block[6][64], const int dir[6], uint8_t *st[6], const int zigzag_last_index[6]) { int i, n; memcpy(s->block_last_index, zigzag_last_index, sizeof(int)*6); @@ -122,7 +122,7 @@ static inline void restore_ac_coeffs(MpegEncContext * s, DCTELEM block[6][64], c * @param[out] st scantable for each 8x8 block * @param[out] zigzag_last_index index referring to the last non zero coefficient in zigzag order */ -static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], const int dir[6], uint8_t *st[6], int zigzag_last_index[6]) +static inline int decide_ac_pred(MpegEncContext * s, int16_t block[6][64], const int dir[6], uint8_t *st[6], int zigzag_last_index[6]) { int score= 0; int i, n; @@ -294,7 +294,7 @@ static inline int mpeg4_get_dc_length(int level, int n){ * Encode an 8x8 block. * @param n block index (0-3 are luma, 4-5 are chroma) */ -static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, +static inline void mpeg4_encode_block(MpegEncContext * s, int16_t * block, int n, int intra_dc, uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb) { int i, last_non_zero; @@ -345,7 +345,7 @@ static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n } } -static int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, +static int mpeg4_get_block_length(MpegEncContext * s, int16_t * block, int n, int intra_dc, uint8_t *scan_table) { int i, last_non_zero; @@ -396,7 +396,7 @@ static int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, in return len; } -static inline void mpeg4_encode_blocks(MpegEncContext * s, DCTELEM block[6][64], int intra_dc[6], +static inline void mpeg4_encode_blocks(MpegEncContext * s, int16_t block[6][64], int intra_dc[6], uint8_t **scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb){ int i; @@ -425,7 +425,7 @@ static inline void mpeg4_encode_blocks(MpegEncContext * s, DCTELEM block[6][64], } } -static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64], +static inline int get_b_cbp(MpegEncContext * s, int16_t block[6][64], int motion_x, int motion_y, int mb_type) { int cbp = 0, i; @@ -469,7 +469,7 @@ static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64], static const int dquant_code[5]= {1,0,9,2,3}; void ff_mpeg4_encode_mb(MpegEncContext * s, - DCTELEM block[6][64], + int16_t block[6][64], int motion_x, int motion_y) { int cbpc, cbpy, pred_x, pred_y; @@ -1241,6 +1241,11 @@ static av_cold int encode_init(AVCodecContext *avctx) int ret; static int done = 0; + if (avctx->width >= (1<<13) || avctx->height >= (1<<13)) { + av_log(avctx, AV_LOG_ERROR, "dimensions too large for MPEG-4\n"); + return AVERROR(EINVAL); + } + if((ret=ff_MPV_encode_init(avctx)) < 0) return ret; diff --git a/mythtv/external/FFmpeg/libavcodec/mpegaudiodec.c b/mythtv/external/FFmpeg/libavcodec/mpegaudiodec.c index 1834e1a16e3..393b4ba4573 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpegaudiodec.c +++ b/mythtv/external/FFmpeg/libavcodec/mpegaudiodec.c @@ -26,13 +26,13 @@ #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" +#include "libavutil/float_dsp.h" #include "libavutil/libm.h" #include "avcodec.h" #include "get_bits.h" #include "internal.h" #include "mathops.h" #include "mpegaudiodsp.h" -#include "dsputil.h" /* * TODO: @@ -84,8 +84,8 @@ typedef struct MPADecodeContext { int err_recognition; AVCodecContext* avctx; MPADSPContext mpadsp; - DSPContext dsp; - AVFrame frame; + AVFloatDSPContext fdsp; + AVFrame *frame; } MPADecodeContext; #if CONFIG_FLOAT @@ -441,8 +441,8 @@ static av_cold int decode_init(AVCodecContext * avctx) s->avctx = avctx; + avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); ff_mpadsp_init(&s->mpadsp); - ff_dsputil_init(&s->dsp, avctx); if (avctx->request_sample_fmt == OUT_FMT && avctx->codec_id != AV_CODEC_ID_MP3ON4) @@ -454,9 +454,6 @@ static av_cold int decode_init(AVCodecContext * avctx) if (avctx->codec_id == AV_CODEC_ID_MP3ADU) s->adu_mode = 1; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -1164,7 +1161,7 @@ static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1) /* NOTE: the 1/sqrt(2) normalization factor is included in the global gain */ #if CONFIG_FLOAT - s-> dsp.butterflies_float(g0->sb_hybrid, g1->sb_hybrid, 576); + s->fdsp.butterflies_float(g0->sb_hybrid, g1->sb_hybrid, 576); #else tab0 = g0->sb_hybrid; tab1 = g1->sb_hybrid; @@ -1629,12 +1626,13 @@ static int mp_decode_frame(MPADecodeContext *s, OUT_INT **samples, /* get output buffer */ if (!samples) { - s->frame.nb_samples = s->avctx->frame_size; - if ((ret = ff_get_buffer(s->avctx, &s->frame)) < 0) { + av_assert0(s->frame != NULL); + s->frame->nb_samples = s->avctx->frame_size; + if ((ret = ff_get_buffer(s->avctx, s->frame)) < 0) { av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (OUT_INT **)s->frame.extended_data; + samples = (OUT_INT **)s->frame->extended_data; } /* apply the synthesis filter */ @@ -1710,11 +1708,13 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, buf_size= s->frame_size; } + s->frame = data; + ret = mp_decode_frame(s, NULL, buf, buf_size); if (ret >= 0) { - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; - avctx->sample_rate = s->sample_rate; + s->frame->nb_samples = avctx->frame_size; + *got_frame_ptr = 1; + avctx->sample_rate = s->sample_rate; //FIXME maybe move the other codec info stuff from above here too } else { av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n"); @@ -1782,14 +1782,15 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data, s->frame_size = len; + s->frame = data; + ret = mp_decode_frame(s, NULL, buf, buf_size); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n"); return ret; } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return buf_size; } @@ -1801,7 +1802,6 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data, * Context for MP3On4 decoder */ typedef struct MP3On4DecodeContext { - AVFrame *frame; int frames; ///< number of mp3 frames per block (number of mp3 decoder instances) int syncword; ///< syncword patch const uint8_t *coff; ///< channel offsets in output buffer @@ -1890,7 +1890,6 @@ static int decode_init_mp3on4(AVCodecContext * avctx) // Put decoder context in place to make init_decode() happy avctx->priv_data = s->mp3decctx[0]; decode_init(avctx); - s->frame = avctx->coded_frame; // Restore mp3on4 context pointer avctx->priv_data = s; s->mp3decctx[0]->adu_mode = 1; // Set adu mode @@ -1927,6 +1926,7 @@ static void flush_mp3on4(AVCodecContext *avctx) static int decode_frame_mp3on4(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MP3On4DecodeContext *s = avctx->priv_data; @@ -1938,12 +1938,12 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data, int fr, ch, ret; /* get output buffer */ - s->frame->nb_samples = MPA_FRAME_SIZE; - if ((ret = ff_get_buffer(avctx, s->frame)) < 0) { + frame->nb_samples = MPA_FRAME_SIZE; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - out_samples = (OUT_INT **)s->frame->extended_data; + out_samples = (OUT_INT **)frame->extended_data; // Discard too short frames if (buf_size < HEADER_SIZE) @@ -1993,9 +1993,8 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data, /* update codec info */ avctx->sample_rate = s->mp3decctx[0]->sample_rate; - s->frame->nb_samples = out_size / (avctx->channels * sizeof(OUT_INT)); - *got_frame_ptr = 1; - *(AVFrame *)data = *s->frame; + frame->nb_samples = out_size / (avctx->channels * sizeof(OUT_INT)); + *got_frame_ptr = 1; return buf_size; } diff --git a/mythtv/external/FFmpeg/libavcodec/mpegaudioenc.c b/mythtv/external/FFmpeg/libavcodec/mpegaudioenc.c index 75436f8522f..36345137f24 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpegaudioenc.c +++ b/mythtv/external/FFmpeg/libavcodec/mpegaudioenc.c @@ -754,7 +754,7 @@ static int MPA_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } compute_bit_allocation(s, smr, bit_alloc, &padding); - if ((ret = ff_alloc_packet2(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE))) + if ((ret = ff_alloc_packet2(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE)) < 0) return ret; init_put_bits(&s->pb, avpkt->data, avpkt->size); diff --git a/mythtv/external/FFmpeg/libavcodec/mpegvideo.c b/mythtv/external/FFmpeg/libavcodec/mpegvideo.c index 61a3efaa8b1..298332886ca 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpegvideo.c +++ b/mythtv/external/FFmpeg/libavcodec/mpegvideo.c @@ -30,6 +30,7 @@ #include "libavutil/imgutils.h" #include "avcodec.h" #include "dsputil.h" +#include "h264chroma.h" #include "internal.h" #include "mathops.h" #include "mpegvideo.h" @@ -43,19 +44,19 @@ //#include static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale); + int16_t *block, int n, int qscale); static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale); + int16_t *block, int n, int qscale); static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale); + int16_t *block, int n, int qscale); static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s, - DCTELEM *block, int n, int qscale); + int16_t *block, int n, int qscale); static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale); + int16_t *block, int n, int qscale); static void dct_unquantize_h263_intra_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale); + int16_t *block, int n, int qscale); static void dct_unquantize_h263_inter_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale); + int16_t *block, int n, int qscale); //#define DEBUG @@ -127,13 +128,32 @@ const enum AVPixelFormat ff_pixfmt_list_420[] = { AV_PIX_FMT_NONE }; -const enum AVPixelFormat ff_hwaccel_pixfmt_list_420[] = { - AV_PIX_FMT_DXVA2_VLD, - AV_PIX_FMT_VAAPI_VLD, - AV_PIX_FMT_VDA_VLD, - AV_PIX_FMT_YUV420P, - AV_PIX_FMT_NONE -}; +static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, + int (*mv)[2][4][2], + int mb_x, int mb_y, int mb_intra, int mb_skipped) +{ + MpegEncContext *s = opaque; + + s->mv_dir = mv_dir; + s->mv_type = mv_type; + s->mb_intra = mb_intra; + s->mb_skipped = mb_skipped; + s->mb_x = mb_x; + s->mb_y = mb_y; + memcpy(s->mv, mv, sizeof(*mv)); + + ff_init_block_index(s); + ff_update_block_index(s); + + s->dsp.clear_blocks(s->block[0]); + + s->dest[0] = s->current_picture.f.data[0] + (s->mb_y * 16 * s->linesize) + s->mb_x * 16; + 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); + ff_MPV_decode_mb(s, s->block); +} const uint8_t *avpriv_mpv_find_start_code(const uint8_t *av_restrict p, const uint8_t *end, @@ -172,6 +192,7 @@ const uint8_t *avpriv_mpv_find_start_code(const uint8_t *av_restrict p, 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_videodsp_init(&s->vdsp, s->avctx->bits_per_raw_sample); s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c; @@ -222,6 +243,7 @@ void ff_copy_picture(Picture *dst, Picture *src) */ static void free_frame_buffer(MpegEncContext *s, Picture *pic) { + pic->period_since_free = 0; /* WM Image / Screen codecs allocate internal buffers with different * dimensions / colorspaces; ignore user-defined callbacks for these. */ if (s->codec_id != AV_CODEC_ID_WMV3IMAGE && @@ -390,7 +412,7 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared) } if (s->avctx->debug&FF_DEBUG_DCT_COEFF) { FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.dct_coeff, - 64 * mb_array_size * sizeof(DCTELEM) * 6, fail) + 64 * mb_array_size * sizeof(int16_t) * 6, fail) } pic->f.qstride = s->mb_stride; FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.pan_scan, @@ -443,7 +465,7 @@ static void free_picture(MpegEncContext *s, Picture *pic) } } -static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base) +static int init_duplicate_context(MpegEncContext *s) { int y_size = s->b8_stride * (2 * s->mb_height + 1); int c_size = s->mb_stride * (s->mb_height + 1); @@ -467,7 +489,7 @@ static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base) 2 * 64 * sizeof(int), fail) } } - FF_ALLOCZ_OR_GOTO(s->avctx, s->blocks, 64 * 12 * 2 * sizeof(DCTELEM), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->blocks, 64 * 12 * 2 * sizeof(int16_t), fail) s->block = s->blocks[0]; for (i = 0; i < 12; i++) { @@ -582,8 +604,11 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, if (s1->context_initialized){ s->picture_range_start += MAX_PICTURE_COUNT; s->picture_range_end += MAX_PICTURE_COUNT; - if((err = ff_MPV_common_init(s)) < 0) + if((err = ff_MPV_common_init(s)) < 0){ + memset(s, 0, sizeof(MpegEncContext)); + s->avctx = dst; return err; + } } } @@ -610,8 +635,10 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, (char *) &s1->last_picture_ptr - (char *) &s1->last_picture); // reset s->picture[].f.extended_data to s->picture[].f.data - for (i = 0; i < s->picture_count; i++) + for (i = 0; i < s->picture_count; i++) { s->picture[i].f.extended_data = s->picture[i].f.data; + s->picture[i].period_since_free ++; + } s->last_picture_ptr = REBASE_PICTURE(s1->last_picture_ptr, s, s1); s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, s, s1); @@ -717,6 +744,43 @@ void ff_MPV_decode_defaults(MpegEncContext *s) ff_MPV_common_defaults(s); } +static int init_er(MpegEncContext *s) +{ + ERContext *er = &s->er; + int mb_array_size = s->mb_height * s->mb_stride; + int i; + + er->avctx = s->avctx; + er->dsp = &s->dsp; + + er->mb_index2xy = s->mb_index2xy; + er->mb_num = s->mb_num; + er->mb_width = s->mb_width; + er->mb_height = s->mb_height; + er->mb_stride = s->mb_stride; + er->b8_stride = s->b8_stride; + + er->er_temp_buffer = av_malloc(s->mb_height * s->mb_stride); + er->error_status_table = av_mallocz(mb_array_size); + if (!er->er_temp_buffer || !er->error_status_table) + goto fail; + + er->mbskip_table = s->mbskip_table; + er->mbintra_table = s->mbintra_table; + + for (i = 0; i < FF_ARRAY_ELEMS(s->dc_val); i++) + er->dc_val[i] = s->dc_val[i]; + + er->decode_mb = mpeg_er_decode_mb; + er->opaque = s; + + return 0; +fail: + av_freep(&er->er_temp_buffer); + av_freep(&er->error_status_table); + return AVERROR(ENOMEM); +} + /** * Initialize and allocates MpegEncContext fields dependent on the resolution. */ @@ -783,12 +847,8 @@ static int init_context_frame(MpegEncContext *s) } - FF_ALLOC_OR_GOTO(s->avctx, s->er_temp_buffer, - mb_array_size * sizeof(uint8_t), fail); - FF_ALLOCZ_OR_GOTO(s->avctx, s->error_status_table, - mb_array_size * sizeof(uint8_t), fail); - - if (s->codec_id == AV_CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)) { + if (s->codec_id == AV_CODEC_ID_MPEG4 || + (s->flags & CODEC_FLAG_INTERLACED_ME)) { /* interlaced direct mode decoding tables */ for (i = 0; i < 2; i++) { int j, k; @@ -837,7 +897,7 @@ static int init_context_frame(MpegEncContext *s) FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size + 2, fail); // Note the + 1 is for a quicker mpeg4 slice_end detection - return 0; + return init_er(s); fail: return AVERROR(ENOMEM); } @@ -941,7 +1001,7 @@ av_cold int ff_MPV_common_init(MpegEncContext *s) } for (i = 0; i < nb_slices; i++) { - if (init_duplicate_context(s->thread_context[i], s) < 0) + if (init_duplicate_context(s->thread_context[i]) < 0) goto fail; s->thread_context[i]->start_mb_y = (s->mb_height * (i) + nb_slices / 2) / nb_slices; @@ -949,7 +1009,7 @@ av_cold int ff_MPV_common_init(MpegEncContext *s) (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices; } } else { - if (init_duplicate_context(s, s) < 0) + if (init_duplicate_context(s) < 0) goto fail; s->start_mb_y = 0; s->end_mb_y = s->mb_height; @@ -1006,8 +1066,8 @@ static int free_context_frame(MpegEncContext *s) av_freep(&s->mbskip_table); - av_freep(&s->error_status_table); - av_freep(&s->er_temp_buffer); + av_freep(&s->er.error_status_table); + av_freep(&s->er.er_temp_buffer); av_freep(&s->mb_index2xy); av_freep(&s->lambda_table); @@ -1071,7 +1131,7 @@ int ff_MPV_common_frame_size_change(MpegEncContext *s) } for (i = 0; i < nb_slices; i++) { - if (init_duplicate_context(s->thread_context[i], s) < 0) + if (init_duplicate_context(s->thread_context[i]) < 0) goto fail; s->thread_context[i]->start_mb_y = (s->mb_height * (i) + nb_slices / 2) / nb_slices; @@ -1079,7 +1139,7 @@ int ff_MPV_common_frame_size_change(MpegEncContext *s) (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices; } } else { - if (init_duplicate_context(s, s) < 0) + if (init_duplicate_context(s) < 0) goto fail; s->start_mb_y = 0; s->end_mb_y = s->mb_height; @@ -1257,6 +1317,10 @@ void ff_release_unused_pictures(MpegEncContext*s, int remove_current) static inline int pic_is_unused(MpegEncContext *s, Picture *pic) { + if ( (s->avctx->active_thread_type & FF_THREAD_FRAME) + && pic->f.qscale_table //check if the frame has anything allocated + && pic->period_since_free < s->avctx->thread_count) + return 0; if (pic->f.data[0] == NULL) return 1; if (pic->needs_realloc && !(pic->f.reference & DELAYED_PIC_REF)) @@ -1454,6 +1518,9 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) s->last_picture_ptr->f.data[0] == NULL) && (s->pict_type != AV_PICTURE_TYPE_I || s->picture_structure != PICT_FRAME)) { + 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) av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n"); @@ -1474,6 +1541,15 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) return -1; } + memset(s->last_picture_ptr->f.data[0], 0x80, + 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(s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263){ for(i=0; iheight; i++) memset(s->last_picture_ptr->f.data[0] + s->last_picture_ptr->f.linesize[0]*i, 16, avctx->width); @@ -1504,6 +1580,8 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) } } + 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)); if (s->last_picture_ptr) ff_copy_picture(&s->last_picture, s->last_picture_ptr); if (s->next_picture_ptr) @@ -1568,7 +1646,7 @@ void ff_MPV_frame_end(MpegEncContext *s) // just to make sure that all data is rendered. if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) { ff_xvmc_field_end(s); - } else if((s->error_count || s->encoding || !(s->avctx->codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND)) && + } else if ((s->er.error_count || s->encoding || !(s->avctx->codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND)) && !s->avctx->hwaccel && !(s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) && s->unrestricted_mv && @@ -1725,134 +1803,136 @@ static void draw_arrow(uint8_t *buf, int sx, int sy, int ex, /** * Print debugging info for the given picture. */ -void ff_print_debug_info(MpegEncContext *s, AVFrame *pict) +void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_table, + uint8_t *visualization_buffer[3], int *low_delay, + int mb_width, int mb_height, int mb_stride, int quarter_sample) { - if ( s->avctx->hwaccel || !pict || !pict->mb_type - || (s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)) + if ( avctx->hwaccel || !pict || !pict->mb_type + || (avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)) return; - 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: %c\n", + av_log(avctx, AV_LOG_DEBUG, "New frame, type: %c\n", av_get_picture_type_char(pict->pict_type)); - 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]; + 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", - pict->qscale_table[x + y * s->mb_stride]); + if (avctx->debug & FF_DEBUG_QP) { + av_log(avctx, AV_LOG_DEBUG, "%2d", + pict->qscale_table[x + y * mb_stride]); } - if (s->avctx->debug & FF_DEBUG_MB_TYPE) { - int mb_type = pict->mb_type[x + y * s->mb_stride]; + if (avctx->debug & FF_DEBUG_MB_TYPE) { + int mb_type = pict->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 { av_assert2(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1)); - av_log(s->avctx, AV_LOG_DEBUG, "X"); + 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(s->avctx, AV_LOG_DEBUG, "\n"); + av_log(avctx, AV_LOG_DEBUG, "\n"); } } - if ((s->avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) || - (s->avctx->debug_mv)) { - const int shift = 1 + s->quarter_sample; + 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 = s->avctx->width; - const int height = s->avctx->height; + const int width = avctx->width; + const int height = avctx->height; const int mv_sample_log2 = 4 - pict->motion_subsample_log2; - const int mv_stride = (s->mb_width << mv_sample_log2) + - (s->codec_id == AV_CODEC_ID_H264 ? 0 : 1); - s->low_delay = 0; // needed to see the vectors without trashing the buffers + 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(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); + avcodec_get_chroma_sub_sample(avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); for (i = 0; i < 3; i++) { size_t size= (i == 0) ? pict->linesize[i] * FFALIGN(height, 16): pict->linesize[i] * FFALIGN(height, 16) >> v_chroma_shift; - s->visualization_buffer[i]= av_realloc(s->visualization_buffer[i], size); - memcpy(s->visualization_buffer[i], pict->data[i], size); - pict->data[i] = s->visualization_buffer[i]; + visualization_buffer[i]= av_realloc(visualization_buffer[i], size); + memcpy(visualization_buffer[i], pict->data[i], size); + pict->data[i] = visualization_buffer[i]; } pict->type = FF_BUFFER_TYPE_COPY; pict->opaque= NULL; ptr = pict->data[0]; block_height = 16 >> v_chroma_shift; - for (mb_y = 0; mb_y < s->mb_height; mb_y++) { + for (mb_y = 0; mb_y < mb_height; mb_y++) { int mb_x; - for (mb_x = 0; mb_x < s->mb_width; mb_x++) { - const int mb_index = mb_x + mb_y * s->mb_stride; - if ((s->avctx->debug_mv) && pict->motion_val[0]) { + for (mb_x = 0; mb_x < mb_width; mb_x++) { + const int mb_index = mb_x + mb_y * mb_stride; + if ((avctx->debug_mv) && pict->motion_val[0]) { int type; for (type = 0; type < 3; type++) { int direction = 0; switch (type) { case 0: - if ((!(s->avctx->debug_mv & FF_DEBUG_VIS_MV_P_FOR)) || + if ((!(avctx->debug_mv & FF_DEBUG_VIS_MV_P_FOR)) || (pict->pict_type!= AV_PICTURE_TYPE_P)) continue; direction = 0; break; case 1: - if ((!(s->avctx->debug_mv & FF_DEBUG_VIS_MV_B_FOR)) || + if ((!(avctx->debug_mv & FF_DEBUG_VIS_MV_B_FOR)) || (pict->pict_type!= AV_PICTURE_TYPE_B)) continue; direction = 0; break; case 2: - if ((!(s->avctx->debug_mv & FF_DEBUG_VIS_MV_B_BACK)) || + if ((!(avctx->debug_mv & FF_DEBUG_VIS_MV_B_BACK)) || (pict->pict_type!= AV_PICTURE_TYPE_B)) continue; direction = 1; @@ -1871,7 +1951,7 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict) int mx = (pict->motion_val[direction][xy][0] >> shift) + sx; int my = (pict->motion_val[direction][xy][1] >> shift) + sy; draw_arrow(ptr, sx, sy, mx, my, width, - height, s->linesize, 100); + height, pict->linesize[0], 100); } } else if (IS_16X8(pict->mb_type[mb_index])) { int i; @@ -1886,7 +1966,7 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict) my *= 2; draw_arrow(ptr, sx, sy, mx + sx, my + sy, width, - height, s->linesize, 100); + height, pict->linesize[0], 100); } } else if (IS_8X16(pict->mb_type[mb_index])) { int i; @@ -1901,7 +1981,7 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict) my *= 2; draw_arrow(ptr, sx, sy, mx + sx, my + sy, width, - height, s->linesize, 100); + height, pict->linesize[0], 100); } } else { int sx= mb_x * 16 + 8; @@ -1909,11 +1989,11 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict) int xy= (mb_x + mb_y * mv_stride) << mv_sample_log2; int mx= (pict->motion_val[direction][xy][0]>>shift) + sx; int my= (pict->motion_val[direction][xy][1]>>shift) + sy; - draw_arrow(ptr, sx, sy, mx, my, width, height, s->linesize, 100); + draw_arrow(ptr, sx, sy, mx, my, width, height, pict->linesize[0], 100); } } } - if ((s->avctx->debug & FF_DEBUG_VIS_QP)) { + if ((avctx->debug & FF_DEBUG_VIS_QP)) { uint64_t c = (pict->qscale_table[mb_index] * 128 / 31) * 0x0101010101010101ULL; int y; @@ -1926,7 +2006,7 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict) pict->linesize[2]) = c; } } - if ((s->avctx->debug & FF_DEBUG_VIS_MB_TYPE) && + if ((avctx->debug & FF_DEBUG_VIS_MB_TYPE) && pict->motion_val[0]) { int mb_type = pict->mb_type[mb_index]; uint64_t u,v; @@ -2004,16 +2084,22 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict) } if (IS_INTERLACED(mb_type) && - s->codec_id == AV_CODEC_ID_H264) { + avctx->codec->id == AV_CODEC_ID_H264) { // hmm } } - s->mbskip_table[mb_index] = 0; + mbskip_table[mb_index] = 0; } } } } +void ff_print_debug_info(MpegEncContext *s, AVFrame *pict) +{ + ff_print_debug_info2(s->avctx, pict, s->mbskip_table, s->visualization_buffer, &s->low_delay, + s->mb_width, s->mb_height, s->mb_stride, s->quarter_sample); +} + static inline int hpel_motion_lowres(MpegEncContext *s, uint8_t *dest, uint8_t *src, int field_based, int field_select, @@ -2143,7 +2229,7 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, 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) || + 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, 17, 17 + field_based, @@ -2183,11 +2269,12 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, 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 (h >> s->chroma_y_shift) { - pix_op[op_index](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); - pix_op[op_index](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); + 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 @@ -2363,7 +2450,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s, s->mv[dir][2 * i + j][1], block_s, mb_y); } - pix_op = s->dsp.avg_h264_chroma_pixels_tab; + pix_op = s->h264chroma.avg_h264_chroma_pixels_tab; } } else { for (i = 0; i < 2; i++) { @@ -2374,7 +2461,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s, 2 * block_s, mb_y >> 1); // after put we make avg of the same block - pix_op = s->dsp.avg_h264_chroma_pixels_tab; + pix_op = s->h264chroma.avg_h264_chroma_pixels_tab; // opposite parity is always in the same // frame if this is second field @@ -2429,7 +2516,7 @@ int ff_MPV_lowest_referenced_row(MpegEncContext *s, int dir) /* put block[] to dest[] */ static inline void put_dct(MpegEncContext *s, - DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale) + int16_t *block, int i, uint8_t *dest, int line_size, int qscale) { s->dct_unquantize_intra(s, block, i, qscale); s->dsp.idct_put (dest, line_size, block); @@ -2437,7 +2524,7 @@ static inline void put_dct(MpegEncContext *s, /* add block[] to dest[] */ static inline void add_dct(MpegEncContext *s, - DCTELEM *block, int i, uint8_t *dest, int line_size) + int16_t *block, int i, uint8_t *dest, int line_size) { if (s->block_last_index[i] >= 0) { s->dsp.idct_add (dest, line_size, block); @@ -2445,7 +2532,7 @@ static inline void add_dct(MpegEncContext *s, } static inline void add_dequant_dct(MpegEncContext *s, - DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale) + int16_t *block, int i, uint8_t *dest, int line_size, int qscale) { if (s->block_last_index[i] >= 0) { s->dct_unquantize_inter(s, block, i, qscale); @@ -2498,7 +2585,7 @@ void ff_clean_intra_table_entries(MpegEncContext *s) s->interlaced_dct : true if interlaced dct used (mpeg2) */ static av_always_inline -void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], +void MPV_decode_mb_internal(MpegEncContext *s, int16_t block[12][64], int lowres_flag, int is_mpeg12) { const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; @@ -2510,7 +2597,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], if(s->avctx->debug&FF_DEBUG_DCT_COEFF) { /* save DCT coefficients */ int i,j; - DCTELEM *dct = &s->current_picture.f.dct_coeff[mb_xy * 64 * 6]; + int16_t *dct = &s->current_picture.f.dct_coeff[mb_xy * 64 * 6]; av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y); for(i=0; i<6; i++){ for(j=0; j<64; j++){ @@ -2595,11 +2682,11 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], } if(lowres_flag){ - h264_chroma_mc_func *op_pix = s->dsp.put_h264_chroma_pixels_tab; + 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->dsp.avg_h264_chroma_pixels_tab; + 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); @@ -2741,7 +2828,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], } } -void ff_MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]){ +void ff_MPV_decode_mb(MpegEncContext *s, int16_t block[12][64]){ #if !CONFIG_SMALL if(s->out_format == FMT_MPEG1) { if(s->avctx->lowres) MPV_decode_mb_internal(s, block, 1, 1); @@ -2755,73 +2842,91 @@ void ff_MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]){ /** * @param h is the normal height, this will be reduced automatically if needed for the last row */ -void ff_draw_horiz_band(MpegEncContext *s, int y, int h){ - const int field_pic= s->picture_structure != PICT_FRAME; +void ff_draw_horiz_band(AVCodecContext *avctx, DSPContext *dsp, Picture *cur, + Picture *last, int y, int h, int picture_structure, + int first_field, int draw_edges, int low_delay, + int v_edge_pos, int h_edge_pos) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); + int hshift = desc->log2_chroma_w; + int vshift = desc->log2_chroma_h; + const int field_pic = picture_structure != PICT_FRAME; if(field_pic){ h <<= 1; y <<= 1; } - if (!s->avctx->hwaccel - && !(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) - && s->unrestricted_mv - && s->current_picture.f.reference - && !s->intra_only - && !(s->flags&CODEC_FLAG_EMU_EDGE)) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt); + if (!avctx->hwaccel && + !(avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) && + draw_edges && + cur->f.reference && + !(avctx->flags & CODEC_FLAG_EMU_EDGE)) { + int *linesize = cur->f.linesize; int sides = 0, edge_h; - int hshift = desc->log2_chroma_w; - int vshift = desc->log2_chroma_h; if (y==0) sides |= EDGE_TOP; - if (y + h >= s->v_edge_pos) sides |= EDGE_BOTTOM; + if (y + h >= v_edge_pos) + sides |= EDGE_BOTTOM; - edge_h= FFMIN(h, s->v_edge_pos - y); + edge_h= FFMIN(h, v_edge_pos - y); - s->dsp.draw_edges(s->current_picture_ptr->f.data[0] + y *s->linesize, - s->linesize, s->h_edge_pos, edge_h, - EDGE_WIDTH, EDGE_WIDTH, sides); - s->dsp.draw_edges(s->current_picture_ptr->f.data[1] + (y>>vshift)*s->uvlinesize, - s->uvlinesize, s->h_edge_pos>>hshift, edge_h>>vshift, - EDGE_WIDTH>>hshift, EDGE_WIDTH>>vshift, sides); - s->dsp.draw_edges(s->current_picture_ptr->f.data[2] + (y>>vshift)*s->uvlinesize, - s->uvlinesize, s->h_edge_pos>>hshift, edge_h>>vshift, - EDGE_WIDTH>>hshift, EDGE_WIDTH>>vshift, sides); + dsp->draw_edges(cur->f.data[0] + y * linesize[0], + linesize[0], h_edge_pos, edge_h, + EDGE_WIDTH, EDGE_WIDTH, sides); + dsp->draw_edges(cur->f.data[1] + (y >> vshift) * linesize[1], + linesize[1], h_edge_pos >> hshift, edge_h >> vshift, + EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, sides); + dsp->draw_edges(cur->f.data[2] + (y >> vshift) * linesize[2], + linesize[2], h_edge_pos >> hshift, edge_h >> vshift, + EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, sides); } - h= FFMIN(h, s->avctx->height - y); + h = FFMIN(h, avctx->height - y); - if(field_pic && s->first_field && !(s->avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return; + if(field_pic && first_field && !(avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return; - if (s->avctx->draw_horiz_band) { + if (avctx->draw_horiz_band) { AVFrame *src; int offset[AV_NUM_DATA_POINTERS]; int i; - if(s->pict_type==AV_PICTURE_TYPE_B || s->low_delay || (s->avctx->slice_flags&SLICE_FLAG_CODED_ORDER)) - src = &s->current_picture_ptr->f; - else if(s->last_picture_ptr) - src = &s->last_picture_ptr->f; + if(cur->f.pict_type == AV_PICTURE_TYPE_B || low_delay || + (avctx->slice_flags & SLICE_FLAG_CODED_ORDER)) + src = &cur->f; + else if (last) + src = &last->f; else return; - if(s->pict_type==AV_PICTURE_TYPE_B && s->picture_structure == PICT_FRAME && s->out_format != FMT_H264){ + if (cur->f.pict_type == AV_PICTURE_TYPE_B && + picture_structure == PICT_FRAME && + avctx->codec_id != AV_CODEC_ID_H264 && + avctx->codec_id != AV_CODEC_ID_SVQ3) { for (i = 0; i < AV_NUM_DATA_POINTERS; i++) offset[i] = 0; }else{ - offset[0]= y * s->linesize; + offset[0]= y * src->linesize[0]; offset[1]= - offset[2]= (y >> s->chroma_y_shift) * s->uvlinesize; + offset[2]= (y >> vshift) * src->linesize[1]; for (i = 3; i < AV_NUM_DATA_POINTERS; i++) offset[i] = 0; } emms_c(); - s->avctx->draw_horiz_band(s->avctx, src, offset, - y, s->picture_structure, h); + avctx->draw_horiz_band(avctx, src, offset, + y, picture_structure, h); } } +void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h) +{ + int draw_edges = s->unrestricted_mv && !s->intra_only; + ff_draw_horiz_band(s->avctx, &s->dsp, &s->current_picture, + &s->last_picture, y, h, s->picture_structure, + s->first_field, draw_edges, s->low_delay, + s->v_edge_pos, s->h_edge_pos); +} + 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]; @@ -2854,6 +2959,35 @@ void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename } } +/** + * Permute an 8x8 block. + * @param block the block which will be permuted according to the given permutation vector + * @param permutation the permutation vector + * @param last the last non zero coefficient in scantable order, used to speed the permutation up + * @param scantable the used scantable, this is only used to speed the permutation up, the block is not + * (inverse) permutated to scantable order! + */ +void ff_block_permute(int16_t *block, uint8_t *permutation, const uint8_t *scantable, int last) +{ + int i; + int16_t temp[64]; + + if(last<=0) return; + //if(permutation[1]==1) return; //FIXME it is ok but not clean and might fail for some permutations + + for(i=0; i<=last; i++){ + const int j= scantable[i]; + temp[j]= block[j]; + block[j]=0; + } + + for(i=0; i<=last; i++){ + const int j= scantable[i]; + const int perm_j= permutation[j]; + block[perm_j]= temp[j]; + } +} + void ff_mpeg_flush(AVCodecContext *avctx){ int i; MpegEncContext *s = avctx->priv_data; @@ -2883,7 +3017,7 @@ void ff_mpeg_flush(AVCodecContext *avctx){ } static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale) + int16_t *block, int n, int qscale) { int i, level, nCoeffs; const uint16_t *quant_matrix; @@ -2912,7 +3046,7 @@ static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, } static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale) + int16_t *block, int n, int qscale) { int i, level, nCoeffs; const uint16_t *quant_matrix; @@ -2941,7 +3075,7 @@ static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s, } static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale) + int16_t *block, int n, int qscale) { int i, level, nCoeffs; const uint16_t *quant_matrix; @@ -2968,7 +3102,7 @@ static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s, } static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s, - DCTELEM *block, int n, int qscale) + int16_t *block, int n, int qscale) { int i, level, nCoeffs; const uint16_t *quant_matrix; @@ -2999,7 +3133,7 @@ static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s, } static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale) + int16_t *block, int n, int qscale) { int i, level, nCoeffs; const uint16_t *quant_matrix; @@ -3030,7 +3164,7 @@ static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s, } static void dct_unquantize_h263_intra_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale) + int16_t *block, int n, int qscale) { int i, level, qmul, qadd; int nCoeffs; @@ -3064,7 +3198,7 @@ static void dct_unquantize_h263_intra_c(MpegEncContext *s, } static void dct_unquantize_h263_inter_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale) + int16_t *block, int n, int qscale) { int i, level, qmul, qadd; int nCoeffs; @@ -3108,6 +3242,22 @@ void ff_set_qscale(MpegEncContext * s, int qscale) void ff_MPV_report_decode_progress(MpegEncContext *s) { - if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->error_occurred) + if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->er.error_occurred) ff_thread_report_progress(&s->current_picture_ptr->f, s->mb_y, 0); } + +void ff_mpeg_er_frame_start(MpegEncContext *s) +{ + ERContext *er = &s->er; + + er->cur_pic = s->current_picture_ptr; + er->last_pic = s->last_picture_ptr; + er->next_pic = s->next_picture_ptr; + + er->pp_time = s->pp_time; + er->pb_time = s->pb_time; + er->quarter_sample = s->quarter_sample; + er->partitioned_frame = s->partitioned_frame; + + ff_er_frame_start(er); +} diff --git a/mythtv/external/FFmpeg/libavcodec/mpegvideo.h b/mythtv/external/FFmpeg/libavcodec/mpegvideo.h index f4cd4beb125..937082a2723 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpegvideo.h +++ b/mythtv/external/FFmpeg/libavcodec/mpegvideo.h @@ -30,7 +30,9 @@ #include "avcodec.h" #include "dsputil.h" +#include "error_resilience.h" #include "get_bits.h" +#include "h264chroma.h" #include "put_bits.h" #include "ratecontrol.h" #include "parser.h" @@ -57,11 +59,10 @@ enum OutputFormat { #define QMAT_SHIFT 21 #define MAX_FCODE 7 -#define MAX_MV 2048 +#define MAX_MV 4096 #define MAX_THREADS 32 - -#define MAX_PICTURE_COUNT 34 +#define MAX_PICTURE_COUNT 36 #define ME_MAP_SIZE 64 #define ME_MAP_SHIFT 3 @@ -95,10 +96,6 @@ struct MpegEncContext; typedef struct Picture{ struct AVFrame f; - /** - * halfpel luma planes. - */ - uint8_t *interpolated[3]; int8_t *qscale_table_base; int16_t (*motion_val_base[2])[2]; uint32_t *mb_type_base; @@ -145,10 +142,10 @@ typedef struct Picture{ uint16_t *mb_var; ///< Table for MB variances uint16_t *mc_mb_var; ///< Table for motion compensated MB variances uint8_t *mb_mean; ///< Table for MB luminance - int32_t *mb_cmp_score; ///< Table for MB cmp scores, for mb decision FIXME remove int b_frame_score; /* */ - struct MpegEncContext *owner2; ///< pointer to the MpegEncContext that allocated this picture + void *owner2; ///< pointer to the context that allocated this picture int needs_realloc; ///< Picture needs to be reallocated (eg due to a frame size change) + int period_since_free; ///< "cycles" since this Picture has been freed } Picture; /** @@ -364,6 +361,7 @@ typedef struct MpegEncContext { int h263_long_vectors; ///< use horrible h263v1 long vector mode DSPContext dsp; ///< pointers for accelerated dsp functions + H264ChromaContext h264chroma; VideoDSPContext vdsp; int f_code; ///< forward MV resolution int b_code; ///< backward MV resolution for B Frames (mpeg4) @@ -497,19 +495,6 @@ typedef struct MpegEncContext { int last_bits; ///< temp var used for calculating the above vars /* error concealment / resync */ - int error_count, error_occurred; - uint8_t *error_status_table; ///< table of the error status of each MB -#define VP_START 1 ///< current MB is the first after a resync marker -#define ER_AC_ERROR 2 -#define ER_DC_ERROR 4 -#define ER_MV_ERROR 8 -#define ER_AC_END 16 -#define ER_DC_END 32 -#define ER_MV_END 64 - -#define ER_MB_ERROR (ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR) -#define ER_MB_END (ER_AC_END|ER_DC_END|ER_MV_END) - int resync_mb_x; ///< x position of last resync marker int resync_mb_y; ///< y position of last resync marker GetBitContext last_resync_gb; ///< used to search for the next resync marker @@ -690,58 +675,57 @@ typedef struct MpegEncContext { uint8_t *ptr_lastgob; int swap_uv; //vcr2 codec is an MPEG-2 variant with U and V swapped - DCTELEM (*pblocks[12])[64]; + int16_t (*pblocks[12])[64]; - DCTELEM (*block)[64]; ///< points to one of the following blocks - DCTELEM (*blocks)[12][64]; // for HQ mode we need to keep the best block - int (*decode_mb)(struct MpegEncContext *s, DCTELEM block[6][64]); // used by some codecs to avoid a switch() + int16_t (*block)[64]; ///< points to one of the following blocks + 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 #define SLICE_END -2 ///= old_ctx->picture && pic < old_ctx->picture+old_ctx->picture_count ?\ - &new_ctx->picture[pic - old_ctx->picture] : (Picture*) ((uint8_t*)pic - (uint8_t*)old_ctx + (uint8_t*)new_ctx))\ - : NULL) +#define REBASE_PICTURE(pic, new_ctx, old_ctx) \ + ((pic && pic >= old_ctx->picture && \ + pic < old_ctx->picture + old_ctx->picture_count) ? \ + &new_ctx->picture[pic - old_ctx->picture] : NULL) /* mpegvideo_enc common options */ #define FF_MPV_FLAG_SKIP_RD 0x0001 @@ -785,7 +769,7 @@ int ff_MPV_common_init(MpegEncContext *s); int ff_mpv_frame_size_alloc(MpegEncContext *s, int linesize); int ff_MPV_common_frame_size_change(MpegEncContext *s); void ff_MPV_common_end(MpegEncContext *s); -void ff_MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]); +void ff_MPV_decode_mb(MpegEncContext *s, int16_t block[12][64]); int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx); void ff_MPV_frame_end(MpegEncContext *s); int ff_MPV_encode_init(AVCodecContext *avctx); @@ -799,13 +783,17 @@ void ff_MPV_common_init_arm(MpegEncContext *s); void ff_MPV_common_init_altivec(MpegEncContext *s); void ff_MPV_common_init_bfin(MpegEncContext *s); void ff_clean_intra_table_entries(MpegEncContext *s); -void ff_draw_horiz_band(MpegEncContext *s, int y, int h); +void ff_draw_horiz_band(AVCodecContext *avctx, DSPContext *dsp, Picture *cur, + Picture *last, int y, int h, int picture_structure, + int first_field, int draw_edges, int low_delay, + int v_edge_pos, int h_edge_pos); +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, AVFrame *pict); void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix); void ff_release_unused_pictures(MpegEncContext *s, int remove_current); int ff_find_unused_picture(MpegEncContext *s, int shared); -void ff_denoise_dct(MpegEncContext *s, DCTELEM *block); +void ff_denoise_dct(MpegEncContext *s, int16_t *block); int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src); int ff_MPV_lowest_referenced_row(MpegEncContext *s, int dir); void ff_MPV_report_decode_progress(MpegEncContext *s); @@ -813,15 +801,13 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src const uint8_t *avpriv_mpv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state); void ff_set_qscale(MpegEncContext * s, int qscale); -void ff_er_frame_start(MpegEncContext *s); -void ff_er_frame_end(MpegEncContext *s); -void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status); +void ff_mpeg_er_frame_start(MpegEncContext *s); 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, DCTELEM *block, int n, int qscale, int *overflow); +int ff_dct_quantize_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow); void ff_init_block_index(MpegEncContext *s); void ff_copy_picture(Picture *dst, Picture *src); @@ -840,7 +826,12 @@ void ff_MPV_motion(MpegEncContext *s, int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared); extern const enum AVPixelFormat ff_pixfmt_list_420[]; -extern const enum AVPixelFormat ff_hwaccel_pixfmt_list_420[]; + +/** + * permute block according to permuatation. + * @param last last non zero element in scantable order + */ +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 >> s->avctx->lowres; @@ -896,7 +887,7 @@ extern const uint8_t * const ff_mpeg2_dc_scale_table[4]; void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number); void ff_mpeg1_encode_mb(MpegEncContext *s, - DCTELEM block[6][64], + int16_t block[6][64], int motion_x, int motion_y); void ff_mpeg1_encode_init(MpegEncContext *s); void ff_mpeg1_encode_slice_header(MpegEncContext *s); @@ -911,7 +902,7 @@ extern const uint8_t ff_h263_loop_filter_strength[32]; void ff_h261_loop_filter(MpegEncContext *s); void ff_h261_reorder_mb_index(MpegEncContext* s); void ff_h261_encode_mb(MpegEncContext *s, - DCTELEM block[6][64], + int16_t block[6][64], int motion_x, int motion_y); void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number); void ff_h261_encode_init(MpegEncContext *s); @@ -928,7 +919,7 @@ void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number); void ff_msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number); void ff_msmpeg4_encode_ext_header(MpegEncContext * s); void ff_msmpeg4_encode_mb(MpegEncContext * s, - DCTELEM block[6][64], + int16_t block[6][64], int motion_x, int motion_y); int ff_msmpeg4_decode_picture_header(MpegEncContext * s); int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size); @@ -936,14 +927,14 @@ int ff_msmpeg4_decode_init(AVCodecContext *avctx); void ff_msmpeg4_encode_init(MpegEncContext *s); int ff_wmv2_decode_picture_header(MpegEncContext * s); int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s); -void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr); +void ff_wmv2_add_mb(MpegEncContext *s, int16_t block[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr); void ff_mspel_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t **ref_picture, op_pixels_func (*pix_op)[4], int motion_x, int motion_y, int h); int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number); void ff_wmv2_encode_mb(MpegEncContext * s, - DCTELEM block[6][64], + int16_t block[6][64], int motion_x, int motion_y); #endif /* AVCODEC_MPEGVIDEO_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/mpegvideo_enc.c b/mythtv/external/FFmpeg/libavcodec/mpegvideo_enc.c index 1e4c58d9ceb..a0e7a54fb13 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpegvideo_enc.c +++ b/mythtv/external/FFmpeg/libavcodec/mpegvideo_enc.c @@ -27,11 +27,13 @@ * The simplest mpeg encoder (well, it was the simplest!). */ +#include "libavutil/internal.h" #include "libavutil/intmath.h" #include "libavutil/mathematics.h" #include "libavutil/pixdesc.h" #include "libavutil/opt.h" #include "avcodec.h" +#include "dct.h" #include "dsputil.h" #include "mpegvideo.h" #include "h263.h" @@ -52,10 +54,10 @@ //#include static int encode_picture(MpegEncContext *s, int picture_number); -static int dct_quantize_refine(MpegEncContext *s, DCTELEM *block, int16_t *weight, DCTELEM *orig, int n, int qscale); +static int dct_quantize_refine(MpegEncContext *s, int16_t *block, int16_t *weight, int16_t *orig, int n, int qscale); static int sse_mb(MpegEncContext *s); -static void denoise_dct_c(MpegEncContext *s, DCTELEM *block); -static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); +static void denoise_dct_c(MpegEncContext *s, int16_t *block); +static int dct_quantize_trellis_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow); //#define DEBUG @@ -183,9 +185,8 @@ void ff_init_qscale_tab(MpegEncContext *s) } } -static void copy_picture_attributes(MpegEncContext *s, - AVFrame *dst, - AVFrame *src) +static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, + const AVFrame *src) { int i; @@ -1006,18 +1007,18 @@ static int get_intra_count(MpegEncContext *s, uint8_t *src, } -static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg) +static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) { AVFrame *pic = NULL; int64_t pts; - int i; + int i, display_picture_number = 0; const int encoding_delay = s->max_b_frames ? s->max_b_frames : (s->low_delay ? 0 : 1); int direct = 1; if (pic_arg) { pts = pic_arg->pts; - pic_arg->display_picture_number = s->input_picture_number++; + display_picture_number = s->input_picture_number++; if (pts != AV_NOPTS_VALUE) { if (s->user_specified_pts != AV_NOPTS_VALUE) { @@ -1031,7 +1032,7 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg) return -1; } - if (!s->low_delay && pic_arg->display_picture_number == 1) + if (!s->low_delay && display_picture_number == 1) s->dts_delta = time - last; } s->user_specified_pts = pts; @@ -1043,91 +1044,103 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg) "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts); } else { - pts = pic_arg->display_picture_number; + pts = display_picture_number; } } } - if (pic_arg) { - if (encoding_delay && !(s->flags & CODEC_FLAG_INPUT_PRESERVED)) - direct = 0; - if (pic_arg->linesize[0] != s->linesize) - direct = 0; - if (pic_arg->linesize[1] != s->uvlinesize) - direct = 0; - if (pic_arg->linesize[2] != s->uvlinesize) - direct = 0; - - av_dlog(s->avctx, "%d %d %d %d\n", pic_arg->linesize[0], - pic_arg->linesize[1], s->linesize, s->uvlinesize); - - if (direct) { - i = ff_find_unused_picture(s, 1); - if (i < 0) - return i; - - pic = &s->picture[i].f; - pic->reference = 3; + if (pic_arg) { + if (encoding_delay && !(s->flags & CODEC_FLAG_INPUT_PRESERVED)) + direct = 0; + if (pic_arg->linesize[0] != s->linesize) + direct = 0; + if (pic_arg->linesize[1] != s->uvlinesize) + direct = 0; + if (pic_arg->linesize[2] != s->uvlinesize) + direct = 0; + + av_dlog(s->avctx, "%d %d %d %d\n", pic_arg->linesize[0], + pic_arg->linesize[1], s->linesize, s->uvlinesize); + + if (direct) { + i = ff_find_unused_picture(s, 1); + if (i < 0) + return i; - for (i = 0; i < 4; i++) { - pic->data[i] = pic_arg->data[i]; - pic->linesize[i] = pic_arg->linesize[i]; - } - if (ff_alloc_picture(s, (Picture *) pic, 1) < 0) { - return -1; - } - } else { - i = ff_find_unused_picture(s, 0); - if (i < 0) - return i; + pic = &s->picture[i].f; + pic->reference = 3; - pic = &s->picture[i].f; - pic->reference = 3; + for (i = 0; i < 4; i++) { + pic->data[i] = pic_arg->data[i]; + pic->linesize[i] = pic_arg->linesize[i]; + } + if (ff_alloc_picture(s, (Picture *) pic, 1) < 0) { + return -1; + } + } else { + i = ff_find_unused_picture(s, 0); + if (i < 0) + return i; - if (ff_alloc_picture(s, (Picture *) pic, 0) < 0) { - return -1; - } + pic = &s->picture[i].f; + pic->reference = 3; - if (pic->data[0] + INPLACE_OFFSET == pic_arg->data[0] && - pic->data[1] + INPLACE_OFFSET == pic_arg->data[1] && - pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]) { - // empty - } else { - int h_chroma_shift, v_chroma_shift; - avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); - - for (i = 0; i < 3; i++) { - int src_stride = pic_arg->linesize[i]; - int dst_stride = i ? s->uvlinesize : s->linesize; - int h_shift = i ? h_chroma_shift : 0; - int v_shift = i ? v_chroma_shift : 0; - int w = s->width >> h_shift; - int h = s->height >> v_shift; - uint8_t *src = pic_arg->data[i]; - uint8_t *dst = pic->data[i]; - - if(s->codec_id == AV_CODEC_ID_AMV && !(s->avctx->flags & CODEC_FLAG_EMU_EDGE)){ - h= ((s->height+15)/16*16)>>v_shift; - } + if (ff_alloc_picture(s, (Picture *) pic, 0) < 0) { + return -1; + } - if (!s->avctx->rc_buffer_size) - dst += INPLACE_OFFSET; + if (pic->data[0] + INPLACE_OFFSET == pic_arg->data[0] && + pic->data[1] + INPLACE_OFFSET == pic_arg->data[1] && + pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]) { + // empty + } else { + int h_chroma_shift, v_chroma_shift; + av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, + &h_chroma_shift, + &v_chroma_shift); + + for (i = 0; i < 3; i++) { + int src_stride = pic_arg->linesize[i]; + int dst_stride = i ? s->uvlinesize : s->linesize; + int h_shift = i ? h_chroma_shift : 0; + int v_shift = i ? v_chroma_shift : 0; + int w = s->width >> h_shift; + int h = s->height >> v_shift; + uint8_t *src = pic_arg->data[i]; + uint8_t *dst = pic->data[i]; + + if (s->codec_id == AV_CODEC_ID_AMV && !(s->avctx->flags & CODEC_FLAG_EMU_EDGE)) { + h = ((s->height + 15)/16*16) >> v_shift; + } - if (src_stride == dst_stride) - memcpy(dst, src, src_stride * h); - else { - while (h--) { - memcpy(dst, src, w); - dst += dst_stride; - src += src_stride; + if (!s->avctx->rc_buffer_size) + dst += INPLACE_OFFSET; + + if (src_stride == dst_stride) + memcpy(dst, src, src_stride * h); + else { + int h2 = h; + uint8_t *dst2 = dst; + while (h2--) { + memcpy(dst2, src, w); + dst2 += dst_stride; + src += src_stride; + } + } + if ((s->width & 15) || (s->height & 15)) { + s->dsp.draw_edges(dst, dst_stride, + w, h, + 16>>h_shift, + 16>>v_shift, + EDGE_BOTTOM); } } } } + copy_picture_attributes(s, pic, pic_arg); + pic->display_picture_number = display_picture_number; + pic->pts = pts; // we set this here to avoid modifiying pic_arg } - copy_picture_attributes(s, pic, pic_arg); - pic->pts = pts; // we set this here to avoid modifiying pic_arg - } /* shift buffer entries */ for (i = 1; i < MAX_PICTURE_COUNT /*s->encoding_delay + 1*/; i++) @@ -1727,7 +1740,7 @@ static inline void dct_single_coeff_elimination(MpegEncContext *s, int score = 0; int run = 0; int i; - DCTELEM *block = s->block[n]; + int16_t *block = s->block[n]; const int last_index = s->block_last_index[n]; int skip_dc; @@ -1767,7 +1780,7 @@ static inline void dct_single_coeff_elimination(MpegEncContext *s, s->block_last_index[n] = -1; } -static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, +static inline void clip_coeffs(MpegEncContext *s, int16_t *block, int last_index) { int i; @@ -1832,7 +1845,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, int mb_block_count) { int16_t weight[12][64]; - DCTELEM orig[12][64]; + int16_t orig[12][64]; const int mb_x = s->mb_x; const int mb_y = s->mb_y; int i; @@ -2093,7 +2106,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, get_visual_weight(weight[7], ptr_cr + uv_dct_offset, wrap_c); } - memcpy(orig[0], s->block[0], sizeof(DCTELEM) * 64 * mb_block_count); + memcpy(orig[0], s->block[0], sizeof(int16_t) * 64 * mb_block_count); } /* DCT & quantize */ @@ -2143,6 +2156,12 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, s->block_last_index[5] = 0; s->block[4][0] = s->block[5][0] = (1024 + s->c_dc_scale / 2) / s->c_dc_scale; + if (!s->chroma_y_shift) { /* 422 / 444 */ + for (i=6; i<12; i++) { + s->block_last_index[i] = 0; + s->block[i][0] = s->block[4][0]; + } + } } // non c quantize code returns incorrect block_last_index FIXME @@ -2839,9 +2858,10 @@ static int encode_thread(AVCodecContext *c, void *arg){ if(best_s.mv_type==MV_TYPE_16X16){ //FIXME move 4mv after QPRD const int last_qp= backup_s.qscale; int qpi, qp, dc[6]; - DCTELEM ac[6][16]; + int16_t ac[6][16]; const int mvdir= (best_s.mv_dir&MV_DIR_BACKWARD) ? 1 : 0; static const int dquant_tab[4]={-1,1,-2,2}; + int storecoefs = s->mb_intra && s->dc_val[0]; av_assert2(backup_s.dquant == 0); @@ -2861,20 +2881,20 @@ static int encode_thread(AVCodecContext *c, void *arg){ if(qp < s->avctx->qmin || qp > s->avctx->qmax) continue; backup_s.dquant= dquant; - if(s->mb_intra && s->dc_val[0]){ + if(storecoefs){ for(i=0; i<6; i++){ dc[i]= s->dc_val[0][ s->block_index[i] ]; - memcpy(ac[i], s->ac_val[0][s->block_index[i]], sizeof(DCTELEM)*16); + memcpy(ac[i], s->ac_val[0][s->block_index[i]], sizeof(int16_t)*16); } } encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_pb, &dmin, &next_block, s->mv[mvdir][0][0], s->mv[mvdir][0][1]); if(best_s.qscale != qp){ - if(s->mb_intra && s->dc_val[0]){ + if(storecoefs){ for(i=0; i<6; i++){ s->dc_val[0][ s->block_index[i] ]= dc[i]; - memcpy(s->ac_val[0][s->block_index[i]], ac[i], sizeof(DCTELEM)*16); + memcpy(s->ac_val[0][s->block_index[i]], ac[i], sizeof(int16_t)*16); } } } @@ -3158,7 +3178,7 @@ static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src) MERGE(b_count); MERGE(skip_count); MERGE(misc_bits); - MERGE(error_count); + MERGE(er.error_count); MERGE(padding_bug_score); MERGE(current_picture.f.error[0]); MERGE(current_picture.f.error[1]); @@ -3479,7 +3499,7 @@ static int encode_picture(MpegEncContext *s, int picture_number) return 0; } -static void denoise_dct_c(MpegEncContext *s, DCTELEM *block){ +static void denoise_dct_c(MpegEncContext *s, int16_t *block){ const int intra= s->mb_intra; int i; @@ -3504,7 +3524,7 @@ static void denoise_dct_c(MpegEncContext *s, DCTELEM *block){ } static int dct_quantize_trellis_c(MpegEncContext *s, - DCTELEM *block, int n, + int16_t *block, int n, int qscale, int *overflow){ const int *qmat; const uint8_t *scantable= s->intra_scantable.scantable; @@ -3611,7 +3631,7 @@ static int dct_quantize_trellis_c(MpegEncContext *s, *overflow= s->max_qcoeff < max; //overflow might have happened if(last_non_zero < start_i){ - memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); + memset(block + start_i, 0, (64-start_i)*sizeof(int16_t)); return last_non_zero; } @@ -3743,7 +3763,7 @@ static int dct_quantize_trellis_c(MpegEncContext *s, dc= FFABS(block[0]); last_non_zero= last_i - 1; - memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); + memset(block + start_i, 0, (64-start_i)*sizeof(int16_t)); if(last_non_zero < start_i) return last_non_zero; @@ -3818,10 +3838,10 @@ static void build_basis(uint8_t *perm){ } static int dct_quantize_refine(MpegEncContext *s, //FIXME breaks denoise? - DCTELEM *block, int16_t *weight, DCTELEM *orig, + int16_t *block, int16_t *weight, int16_t *orig, int n, int qscale){ int16_t rem[64]; - LOCAL_ALIGNED_16(DCTELEM, d1, [64]); + LOCAL_ALIGNED_16(int16_t, d1, [64]); const uint8_t *scantable= s->intra_scantable.scantable; const uint8_t *perm_scantable= s->intra_scantable.permutated; // unsigned int threshold1, threshold2; @@ -4191,7 +4211,7 @@ STOP_TIMER("iterative search") } int ff_dct_quantize_c(MpegEncContext *s, - DCTELEM *block, int n, + int16_t *block, int n, int qscale, int *overflow) { int i, j, level, last_non_zero, q, start_i; diff --git a/mythtv/external/FFmpeg/libavcodec/mpegvideo_motion.c b/mythtv/external/FFmpeg/libavcodec/mpegvideo_motion.c index 22381dea273..565f6cb2866 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpegvideo_motion.c +++ b/mythtv/external/FFmpeg/libavcodec/mpegvideo_motion.c @@ -22,7 +22,9 @@ */ #include + #include "libavutil/avassert.h" +#include "libavutil/internal.h" #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" diff --git a/mythtv/external/FFmpeg/libavcodec/mpegvideo_xvmc.c b/mythtv/external/FFmpeg/libavcodec/mpegvideo_xvmc.c index 6247e6240c1..f30124cf44b 100644 --- a/mythtv/external/FFmpeg/libavcodec/mpegvideo_xvmc.c +++ b/mythtv/external/FFmpeg/libavcodec/mpegvideo_xvmc.c @@ -23,7 +23,6 @@ #include #include "avcodec.h" -#include "dsputil.h" #include "mpegvideo.h" #undef NDEBUG @@ -44,7 +43,7 @@ void ff_xvmc_init_block(MpegEncContext *s) struct xvmc_pix_fmt *render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2]; assert(render && render->xvmc_id == AV_XVMC_ID); - s->block = (DCTELEM (*)[64])(render->data_blocks + render->next_free_data_block_num * 64); + s->block = (int16_t (*)[64])(render->data_blocks + render->next_free_data_block_num * 64); } /** @@ -145,7 +144,7 @@ void ff_xvmc_field_end(MpegEncContext *s) assert(render); if (render->filled_mv_blocks_num > 0) - ff_draw_horiz_band(s, 0, 0); + ff_mpeg_draw_horiz_band(s, 0, 0); } /** @@ -328,5 +327,5 @@ void ff_xvmc_decode_mb(MpegEncContext *s) if (render->filled_mv_blocks_num == render->allocated_mv_blocks) - ff_draw_horiz_band(s, 0, 0); + ff_mpeg_draw_horiz_band(s, 0, 0); } diff --git a/mythtv/external/FFmpeg/libavcodec/msmpeg4.c b/mythtv/external/FFmpeg/libavcodec/msmpeg4.c index 00fac8c4b22..278c5fcfdc1 100644 --- a/mythtv/external/FFmpeg/libavcodec/msmpeg4.c +++ b/mythtv/external/FFmpeg/libavcodec/msmpeg4.c @@ -404,7 +404,7 @@ static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code) return val; } -static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) +static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64]) { int cbp, code, i; uint32_t * const mb_type_ptr = &s->current_picture.f.mb_type[s->mb_x + s->mb_y*s->mb_stride]; @@ -494,7 +494,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) return 0; } -static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) +static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64]) { int cbp, code, i; uint8_t *coded_val; @@ -938,7 +938,7 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) } //#define ERROR_DETAILS -int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, +int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block, int n, int coded, const uint8_t *scan_table) { int level, i, last, run, run_diff; diff --git a/mythtv/external/FFmpeg/libavcodec/msmpeg4.h b/mythtv/external/FFmpeg/libavcodec/msmpeg4.h index abc414cfdd8..a723888192f 100644 --- a/mythtv/external/FFmpeg/libavcodec/msmpeg4.h +++ b/mythtv/external/FFmpeg/libavcodec/msmpeg4.h @@ -26,7 +26,6 @@ #include "config.h" #include "avcodec.h" -#include "dsputil.h" #include "mpegvideo.h" #include "msmpeg4data.h" #include "put_bits.h" @@ -45,17 +44,17 @@ extern VLC ff_inter_intra_vlc; void ff_msmpeg4_code012(PutBitContext *pb, int n); void ff_msmpeg4_common_init(MpegEncContext *s); -void ff_msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n); +void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n); void ff_msmpeg4_handle_slices(MpegEncContext *s); void ff_msmpeg4_encode_motion(MpegEncContext * s, int mx, int my); int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr); int ff_msmpeg4_decode_motion(MpegEncContext * s, int *mx_ptr, int *my_ptr); -int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, +int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block, int n, int coded, const uint8_t *scan_table); int ff_msmpeg4_pred_dc(MpegEncContext *s, int n, int16_t **dc_val_ptr, int *dir_ptr); -int ff_wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); +int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]); #define CONFIG_MSMPEG4_DECODER (CONFIG_MSMPEG4V1_DECODER || \ CONFIG_MSMPEG4V2_DECODER || \ diff --git a/mythtv/external/FFmpeg/libavcodec/msmpeg4enc.c b/mythtv/external/FFmpeg/libavcodec/msmpeg4enc.c index 71b84df7396..82e6646fbac 100644 --- a/mythtv/external/FFmpeg/libavcodec/msmpeg4enc.c +++ b/mythtv/external/FFmpeg/libavcodec/msmpeg4enc.c @@ -369,7 +369,7 @@ static void msmpeg4v2_encode_motion(MpegEncContext * s, int val) } void ff_msmpeg4_encode_mb(MpegEncContext * s, - DCTELEM block[6][64], + int16_t block[6][64], int motion_x, int motion_y) { int cbp, coded_cbp, i; @@ -570,7 +570,7 @@ static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr /* Encoding of a block. Very similar to MPEG4 except for a different escape coding (same as H263) and more vlc tables. */ -void ff_msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n) +void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n) { int level, run, last, i, j, last_index; int last_non_zero, sign, slevel; diff --git a/mythtv/external/FFmpeg/libavcodec/msrle.c b/mythtv/external/FFmpeg/libavcodec/msrle.c index 5b7ba7fdad4..7187d1a5e19 100644 --- a/mythtv/external/FFmpeg/libavcodec/msrle.c +++ b/mythtv/external/FFmpeg/libavcodec/msrle.c @@ -33,7 +33,6 @@ #include #include "avcodec.h" -#include "dsputil.h" #include "msrledec.h" typedef struct MsrleContext { @@ -67,7 +66,7 @@ static av_cold int msrle_decode_init(AVCodecContext *avctx) break; default: av_log(avctx, AV_LOG_ERROR, "unsupported bits per sample\n"); - return -1; + return AVERROR_INVALIDDATA; } avcodec_get_frame_defaults(&s->frame); @@ -88,15 +87,16 @@ static int msrle_decode_frame(AVCodecContext *avctx, int buf_size = avpkt->size; MsrleContext *s = avctx->priv_data; int istride = FFALIGN(avctx->width*avctx->bits_per_coded_sample, 32) / 8; + int ret; s->buf = buf; s->size = buf_size; s->frame.reference = 3; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; - if (avctx->reget_buffer(avctx, &s->frame)) { + if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } if (avctx->bits_per_coded_sample > 1 && avctx->bits_per_coded_sample <= 8) { diff --git a/mythtv/external/FFmpeg/libavcodec/mss12.c b/mythtv/external/FFmpeg/libavcodec/mss12.c index 59294b8b14c..b522e4a4080 100644 --- a/mythtv/external/FFmpeg/libavcodec/mss12.c +++ b/mythtv/external/FFmpeg/libavcodec/mss12.c @@ -586,6 +586,11 @@ av_cold int ff_mss12_decode_init(MSS12Context *c, int version, avctx->coded_width, avctx->coded_height); return AVERROR_INVALIDDATA; } + if (avctx->coded_width < 1 || avctx->coded_height < 1) { + av_log(avctx, AV_LOG_ERROR, "Frame dimensions %dx%d too small", + avctx->coded_width, avctx->coded_height); + return AVERROR_INVALIDDATA; + } av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d\n", AV_RB32(avctx->extradata + 4), AV_RB32(avctx->extradata + 8)); diff --git a/mythtv/external/FFmpeg/libavcodec/mss12.h b/mythtv/external/FFmpeg/libavcodec/mss12.h index 42ceab568f7..a3f9a7ca70d 100644 --- a/mythtv/external/FFmpeg/libavcodec/mss12.h +++ b/mythtv/external/FFmpeg/libavcodec/mss12.h @@ -95,9 +95,9 @@ int ff_mss12_decode_rect(SliceContext *ctx, ArithCoder *acoder, int x, int y, int width, int height); void ff_mss12_model_update(Model *m, int val); void ff_mss12_slicecontext_reset(SliceContext *sc); -av_cold int ff_mss12_decode_init(MSS12Context *c, int version, - SliceContext* sc1, SliceContext *sc2); -av_cold int ff_mss12_decode_end(MSS12Context *ctx); +int ff_mss12_decode_init(MSS12Context *c, int version, + SliceContext *sc1, SliceContext *sc2); +int ff_mss12_decode_end(MSS12Context *ctx); #define ARITH_GET_BIT(VERSION) \ static int arith ## VERSION ## _get_bit(ArithCoder *c) \ diff --git a/mythtv/external/FFmpeg/libavcodec/mss2.c b/mythtv/external/FFmpeg/libavcodec/mss2.c index 32a50323726..afdf33c244a 100644 --- a/mythtv/external/FFmpeg/libavcodec/mss2.c +++ b/mythtv/external/FFmpeg/libavcodec/mss2.c @@ -163,7 +163,7 @@ static int decode_pal_v2(MSS12Context *ctx, const uint8_t *buf, int buf_size) ncol = *buf++; if (ncol > ctx->free_colours || buf_size < 2 + ncol * 3) - return -1; + return AVERROR_INVALIDDATA; for (i = 0; i < ncol; i++) *pal++ = AV_RB24(buf + 3 * i); @@ -189,7 +189,7 @@ static int decode_555(GetByteContext *gB, uint16_t *dst, int stride, READ_PAIR(y, endy) if (endx >= w || endy >= h || x > endx || y > endy) - return -1; + return AVERROR_INVALIDDATA; dst += x + stride * y; w = endx - x + 1; h = endy - y + 1; @@ -373,13 +373,14 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size, VC1Context *v = avctx->priv_data; MpegEncContext *s = &v->s; AVFrame *f; + int ret; ff_mpeg_flush(avctx); if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) { int i = ff_find_unused_picture(s, 0); if (i < 0) - return -1; + return i; s->current_picture_ptr = &s->picture[i]; } @@ -399,13 +400,13 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size, avctx->pix_fmt = AV_PIX_FMT_YUV420P; - if (ff_MPV_frame_start(s, avctx) < 0) { + if ((ret = ff_MPV_frame_start(s, avctx)) < 0) { av_log(v->s.avctx, AV_LOG_ERROR, "ff_MPV_frame_start error\n"); avctx->pix_fmt = AV_PIX_FMT_RGB24; - return -1; + return ret; } - ff_er_frame_start(s); + ff_mpeg_er_frame_start(s); v->bits = buf_size * 8; @@ -418,7 +419,7 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size, ff_vc1_decode_blocks(v); - ff_er_frame_end(s); + ff_er_frame_end(&s->er); ff_MPV_frame_end(s); @@ -617,7 +618,7 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, ctx->last_pic.linesize[0] * (avctx->height - 1); } else { av_log(avctx, AV_LOG_ERROR, "Missing keyframe\n"); - return -1; + return AVERROR_INVALIDDATA; } } else { if (ctx->last_pic.data[0]) @@ -753,16 +754,14 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, static av_cold int wmv9_init(AVCodecContext *avctx) { VC1Context *v = avctx->priv_data; + int ret; v->s.avctx = avctx; avctx->flags |= CODEC_FLAG_EMU_EDGE; v->s.flags |= CODEC_FLAG_EMU_EDGE; - if (avctx->idct_algo == FF_IDCT_AUTO) - avctx->idct_algo = FF_IDCT_WMV2; - - if (ff_vc1_init_common(v) < 0) - return -1; + if ((ret = ff_vc1_init_common(v)) < 0) + return ret; ff_vc1dsp_init(&v->vc1dsp); v->profile = PROFILE_MAIN; @@ -802,9 +801,9 @@ static av_cold int wmv9_init(AVCodecContext *avctx) ff_vc1_init_transposed_scantables(v); - if (ff_msmpeg4_decode_init(avctx) < 0 || - ff_vc1_decode_init_alloc_tables(v) < 0) - return -1; + if ((ret = ff_msmpeg4_decode_init(avctx)) < 0 || + (ret = ff_vc1_decode_init_alloc_tables(v)) < 0) + return ret; /* error concealment */ v->s.me.qpel_put = v->s.dsp.put_qpel_pixels_tab; diff --git a/mythtv/external/FFmpeg/libavcodec/mss2dsp.c b/mythtv/external/FFmpeg/libavcodec/mss2dsp.c index b18bf1f0a96..c5fc1f8dcf3 100644 --- a/mythtv/external/FFmpeg/libavcodec/mss2dsp.c +++ b/mythtv/external/FFmpeg/libavcodec/mss2dsp.c @@ -106,6 +106,9 @@ static void upsample_plane_c(uint8_t *plane, int plane_stride, int w, int h) uint8_t *src1, *src2, *dst1, *dst2, *p, a, b; int i, j; + if(!w || !h) + return; + w += (w & 1); h += (h & 1); diff --git a/mythtv/external/FFmpeg/libavcodec/mss2dsp.h b/mythtv/external/FFmpeg/libavcodec/mss2dsp.h index e04aab04d59..7368abb581a 100644 --- a/mythtv/external/FFmpeg/libavcodec/mss2dsp.h +++ b/mythtv/external/FFmpeg/libavcodec/mss2dsp.h @@ -26,7 +26,7 @@ #ifndef AVCODEC_MSS2DSP_H #define AVCODEC_MSS2DSP_H -#include "dsputil.h" +#include typedef struct MSS2DSPContext { void (*mss2_blit_wmv9)(uint8_t *dst, int dst_stride, @@ -45,6 +45,6 @@ typedef struct MSS2DSPContext { void (*upsample_plane)(uint8_t *plane, int plane_stride, int w, int h); } MSS2DSPContext; -av_cold void ff_mss2dsp_init(MSS2DSPContext* dsp); +void ff_mss2dsp_init(MSS2DSPContext *dsp); #endif /* AVCODEC_MSS2DSP_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/mss3.c b/mythtv/external/FFmpeg/libavcodec/mss3.c index 545fefc47ae..d5bb2d4e356 100644 --- a/mythtv/external/FFmpeg/libavcodec/mss3.c +++ b/mythtv/external/FFmpeg/libavcodec/mss3.c @@ -295,7 +295,7 @@ static void rac_normalise(RangeCoder *c) c->low |= *c->src++; } else if (!c->low) { c->got_error = 1; - return; + c->low = 1; } if (c->range >= RAC_BOTTOM) return; diff --git a/mythtv/external/FFmpeg/libavcodec/mss4.c b/mythtv/external/FFmpeg/libavcodec/mss4.c index f575387e6ea..977e1e55525 100644 --- a/mythtv/external/FFmpeg/libavcodec/mss4.c +++ b/mythtv/external/FFmpeg/libavcodec/mss4.c @@ -126,7 +126,6 @@ static const uint8_t mss4_vec_entry_vlc_syms[2][9] = { typedef struct MSS4Context { AVFrame pic; - DSPContext dsp; VLC dc_vlc[2], ac_vlc[2]; VLC vec_entry_vlc[2]; diff --git a/mythtv/external/FFmpeg/libavcodec/nellymoser.c b/mythtv/external/FFmpeg/libavcodec/nellymoser.c index 195e2e80ae9..0740c75a0f0 100644 --- a/mythtv/external/FFmpeg/libavcodec/nellymoser.c +++ b/mythtv/external/FFmpeg/libavcodec/nellymoser.c @@ -33,7 +33,6 @@ #include "nellymoser.h" #include "avcodec.h" -#include "dsputil.h" #define BITSTREAM_READER_LE #include "get_bits.h" diff --git a/mythtv/external/FFmpeg/libavcodec/nellymoserdec.c b/mythtv/external/FFmpeg/libavcodec/nellymoserdec.c index 8fa52de9d53..4b4b61c4721 100644 --- a/mythtv/external/FFmpeg/libavcodec/nellymoserdec.c +++ b/mythtv/external/FFmpeg/libavcodec/nellymoserdec.c @@ -32,10 +32,10 @@ */ #include "libavutil/channel_layout.h" +#include "libavutil/float_dsp.h" #include "libavutil/lfg.h" #include "libavutil/random_seed.h" #include "avcodec.h" -#include "dsputil.h" #include "fft.h" #include "fmtconvert.h" #include "internal.h" @@ -48,11 +48,10 @@ typedef struct NellyMoserDecodeContext { AVCodecContext* avctx; - AVFrame frame; AVLFG random_state; GetBitContext gb; float scale_bias; - DSPContext dsp; + AVFloatDSPContext fdsp; FFTContext imdct_ctx; DECLARE_ALIGNED(32, float, imdct_buf)[2][NELLY_BUF_LEN]; float *imdct_out; @@ -107,7 +106,9 @@ static void nelly_decode_block(NellyMoserDecodeContext *s, (NELLY_BUF_LEN - NELLY_FILL_LEN) * sizeof(float)); s->imdct_ctx.imdct_half(&s->imdct_ctx, s->imdct_out, aptr); - s->dsp.vector_fmul_window(aptr, s->imdct_prev + NELLY_BUF_LEN/2, s->imdct_out, ff_sine_128, NELLY_BUF_LEN/2); + s->fdsp.vector_fmul_window(aptr, s->imdct_prev + NELLY_BUF_LEN / 2, + s->imdct_out, ff_sine_128, + NELLY_BUF_LEN / 2); FFSWAP(float *, s->imdct_out, s->imdct_prev); } } @@ -121,7 +122,7 @@ static av_cold int decode_init(AVCodecContext * avctx) { av_lfg_init(&s->random_state, 0); ff_mdct_init(&s->imdct_ctx, 8, 1, 1.0); - ff_dsputil_init(&s->dsp, avctx); + avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); s->scale_bias = 1.0/(32768*8); avctx->sample_fmt = AV_SAMPLE_FMT_FLT; @@ -133,15 +134,13 @@ static av_cold int decode_init(AVCodecContext * avctx) { avctx->channels = 1; avctx->channel_layout = AV_CH_LAYOUT_MONO; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } static int decode_tag(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; const uint8_t *side=av_packet_get_side_data(avpkt, 'F', NULL); int buf_size = avpkt->size; @@ -171,12 +170,12 @@ static int decode_tag(AVCodecContext *avctx, void *data, avctx->sample_rate= 11025*(blocks/2); /* get output buffer */ - s->frame.nb_samples = NELLY_SAMPLES * blocks; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = NELLY_SAMPLES * blocks; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples_flt = (float *)s->frame.data[0]; + samples_flt = (float *)frame->data[0]; for (i=0 ; iframe; + *got_frame_ptr = 1; return buf_size; } diff --git a/mythtv/external/FFmpeg/libavcodec/nellymoserenc.c b/mythtv/external/FFmpeg/libavcodec/nellymoserenc.c index 0fdec2c3b59..a8c96faea77 100644 --- a/mythtv/external/FFmpeg/libavcodec/nellymoserenc.c +++ b/mythtv/external/FFmpeg/libavcodec/nellymoserenc.c @@ -40,7 +40,6 @@ #include "nellymoser.h" #include "avcodec.h" #include "audio_frame_queue.h" -#include "dsputil.h" #include "fft.h" #include "internal.h" #include "sinewin.h" @@ -55,7 +54,6 @@ typedef struct NellyMoserEncodeContext { AVCodecContext *avctx; int last_frame; - DSPContext dsp; AVFloatDSPContext fdsp; FFTContext mdct_ctx; AudioFrameQueue afq; @@ -122,12 +120,12 @@ static void apply_mdct(NellyMoserEncodeContext *s) float *in1 = s->buf + NELLY_BUF_LEN; float *in2 = s->buf + 2 * NELLY_BUF_LEN; - s->fdsp.vector_fmul (s->in_buff, in0, ff_sine_128, NELLY_BUF_LEN); - s->dsp.vector_fmul_reverse(s->in_buff + NELLY_BUF_LEN, in1, ff_sine_128, NELLY_BUF_LEN); + s->fdsp.vector_fmul (s->in_buff, in0, ff_sine_128, NELLY_BUF_LEN); + s->fdsp.vector_fmul_reverse(s->in_buff + NELLY_BUF_LEN, in1, ff_sine_128, NELLY_BUF_LEN); s->mdct_ctx.mdct_calc(&s->mdct_ctx, s->mdct_out, s->in_buff); - s->fdsp.vector_fmul (s->in_buff, in1, ff_sine_128, NELLY_BUF_LEN); - s->dsp.vector_fmul_reverse(s->in_buff + NELLY_BUF_LEN, in2, ff_sine_128, NELLY_BUF_LEN); + s->fdsp.vector_fmul (s->in_buff, in1, ff_sine_128, NELLY_BUF_LEN); + s->fdsp.vector_fmul_reverse(s->in_buff + NELLY_BUF_LEN, in2, ff_sine_128, NELLY_BUF_LEN); s->mdct_ctx.mdct_calc(&s->mdct_ctx, s->mdct_out + NELLY_BUF_LEN, s->in_buff); } @@ -173,7 +171,6 @@ static av_cold int encode_init(AVCodecContext *avctx) s->avctx = avctx; if ((ret = ff_mdct_init(&s->mdct_ctx, 8, 0, 32768.0)) < 0) goto error; - ff_dsputil_init(&s->dsp, avctx); avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); /* Generate overlap window */ @@ -404,7 +401,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, s->last_frame = 1; } - if ((ret = ff_alloc_packet2(avctx, avpkt, NELLY_BLOCK_LEN))) + if ((ret = ff_alloc_packet2(avctx, avpkt, NELLY_BLOCK_LEN)) < 0) return ret; encode_block(s, avpkt->data, avpkt->size); diff --git a/mythtv/external/FFmpeg/libavcodec/nuv.c b/mythtv/external/FFmpeg/libavcodec/nuv.c index ff11d007c49..dffe339ca3d 100644 --- a/mythtv/external/FFmpeg/libavcodec/nuv.c +++ b/mythtv/external/FFmpeg/libavcodec/nuv.c @@ -28,7 +28,6 @@ #include "libavutil/lzo.h" #include "libavutil/imgutils.h" #include "avcodec.h" -#include "dsputil.h" #include "rtjpeg.h" typedef struct { @@ -88,7 +87,7 @@ static int get_quant(AVCodecContext *avctx, NuvContext *c, const uint8_t *buf, int i; if (size < 2 * 64 * 4) { av_log(avctx, AV_LOG_ERROR, "insufficient rtjpeg quant data\n"); - return -1; + return AVERROR_INVALIDDATA; } for (i = 0; i < 64; i++, buf += 4) c->lq[i] = AV_RL32(buf); @@ -114,6 +113,8 @@ static int codec_reinit(AVCodecContext *avctx, int width, int height, int quality) { NuvContext *c = avctx->priv_data; + int ret; + width = FFALIGN(width, 2); height = FFALIGN(height, 2); if (quality >= 0) @@ -121,9 +122,10 @@ static int codec_reinit(AVCodecContext *avctx, int width, int height, if (width != c->width || height != c->height) { // also reserve space for a possible additional header int buf_size = 24 + height * width * 3 / 2 + AV_LZO_OUTPUT_PADDING; - if (av_image_check_size(height, width, 0, avctx) < 0 || - buf_size > INT_MAX/8) + if (buf_size > INT_MAX/8) return -1; + if ((ret = av_image_check_size(height, width, 0, avctx)) < 0) + return ret; avctx->width = c->width = width; avctx->height = c->height = height; av_fast_malloc(&c->decomp_buf, &c->decomp_size, @@ -153,7 +155,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, int orig_size = buf_size; int keyframe; int size_change = 0; - int result; + int result, init_frame = !avctx->frame_number; enum { NUV_UNCOMPRESSED = '0', NUV_RTJPEG = '1', @@ -165,7 +167,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (buf_size < 12) { av_log(avctx, AV_LOG_ERROR, "coded frame too small\n"); - return -1; + return AVERROR_INVALIDDATA; } // codec data (rtjpeg quant tables) @@ -184,7 +186,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (buf_size < 12 || buf[0] != 'V') { av_log(avctx, AV_LOG_ERROR, "not a nuv video frame\n"); - return -1; + return AVERROR_INVALIDDATA; } comptype = buf[1]; switch (comptype) { @@ -212,7 +214,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, } if (c->codec_frameheader) { int w, h, q; - int res; if (buf_size < RTJPEG_HEADER_SIZE) { av_log(avctx, AV_LOG_ERROR, "Too small NUV video frame\n"); return AVERROR_INVALIDDATA; @@ -227,28 +228,34 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, w = AV_RL16(&buf[6]); h = AV_RL16(&buf[8]); q = buf[10]; - res = codec_reinit(avctx, w, h, q); - if (res < 0) - return res; - if (res) { + if ((result = codec_reinit(avctx, w, h, q)) < 0) + return result; + if (result) { buf = avpkt->data; buf_size = avpkt->size; size_change = 1; goto retry; } - buf = &buf[RTJPEG_HEADER_SIZE]; + buf = &buf[RTJPEG_HEADER_SIZE]; buf_size -= RTJPEG_HEADER_SIZE; } - if ((size_change || keyframe) && c->pic.data[0]) + if ((size_change || keyframe) && c->pic.data[0]) { avctx->release_buffer(avctx, &c->pic); + init_frame = 1; + } c->pic.reference = 3; c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; result = avctx->reget_buffer(avctx, &c->pic); if (result < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return result; + } + if (init_frame) { + memset(c->pic.data[0], 0, avctx->height * c->pic.linesize[0]); + memset(c->pic.data[1], 0x80, avctx->height * c->pic.linesize[1] / 2); + memset(c->pic.data[2], 0x80, avctx->height * c->pic.linesize[2] / 2); } c->pic.pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; @@ -280,7 +287,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, break; default: av_log(avctx, AV_LOG_ERROR, "unknown compression\n"); - return -1; + return AVERROR_INVALIDDATA; } *picture = c->pic; @@ -291,6 +298,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, static av_cold int decode_init(AVCodecContext *avctx) { NuvContext *c = avctx->priv_data; + int ret; + avctx->pix_fmt = AV_PIX_FMT_YUV420P; c->pic.data[0] = NULL; c->decomp_buf = NULL; @@ -305,8 +314,8 @@ static av_cold int decode_init(AVCodecContext *avctx) ff_dsputil_init(&c->dsp, avctx); - if (codec_reinit(avctx, avctx->width, avctx->height, -1) < 0) - return 1; + if ((ret = codec_reinit(avctx, avctx->width, avctx->height, -1)) < 0) + return ret; return 0; } diff --git a/mythtv/external/FFmpeg/libavcodec/options_table.h b/mythtv/external/FFmpeg/libavcodec/options_table.h index 2a31fa64cc7..d0c55a2a440 100644 --- a/mythtv/external/FFmpeg/libavcodec/options_table.h +++ b/mythtv/external/FFmpeg/libavcodec/options_table.h @@ -79,6 +79,7 @@ static const AVOption options[]={ {"sgop", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.i64 = CODEC_FLAG2_STRICT_GOP }, INT_MIN, INT_MAX, V|E, "flags2"}, #endif {"noout", "skip bitstream encoding", 0, AV_OPT_TYPE_CONST, {.i64 = CODEC_FLAG2_NO_OUTPUT }, INT_MIN, INT_MAX, V|E, "flags2"}, +{"ignorecrop", "ignore cropping information from sps", 1, AV_OPT_TYPE_CONST, {.i64 = CODEC_FLAG2_IGNORE_CROP }, INT_MIN, INT_MAX, V|D, "flags2"}, {"local_header", "place global headers at every keyframe instead of in extradata", 0, AV_OPT_TYPE_CONST, {.i64 = CODEC_FLAG2_LOCAL_HEADER }, INT_MIN, INT_MAX, V|E, "flags2"}, {"chunks", "Frame data might be split into multiple chunks", 0, AV_OPT_TYPE_CONST, {.i64 = CODEC_FLAG2_CHUNKS }, INT_MIN, INT_MAX, V|D, "flags2"}, {"showall", "Show all frames before the first keyframe", 0, AV_OPT_TYPE_CONST, {.i64 = CODEC_FLAG2_SHOW_ALL }, INT_MIN, INT_MAX, V|D, "flags2"}, @@ -214,8 +215,10 @@ static const AVOption options[]={ {"simplearmv6", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARMV6 }, INT_MIN, INT_MAX, V|E|D, "idct"}, {"simpleneon", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLENEON }, INT_MIN, INT_MAX, V|E|D, "idct"}, {"simplealpha", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEALPHA }, INT_MIN, INT_MAX, V|E|D, "idct"}, +#if FF_API_IDCT {"h264", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_H264 }, INT_MIN, INT_MAX, V|E|D, "idct"}, {"vp3", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_VP3 }, INT_MIN, INT_MAX, V|E|D, "idct"}, +#endif {"ipp", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_IPP }, INT_MIN, INT_MAX, V|E|D, "idct"}, {"xvidmmx", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_XVIDMMX }, INT_MIN, INT_MAX, V|E|D, "idct"}, {"faani", "floating point AAN IDCT", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_FAAN }, INT_MIN, INT_MAX, V|D|E, "idct"}, @@ -295,7 +298,7 @@ static const AVOption options[]={ {"context", "context model", OFFSET(context_model), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"slice_flags", NULL, OFFSET(slice_flags), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX}, {"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX}, -{"mbd", "macroblock decision algorithm (high quality mode)", OFFSET(mb_decision), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E, "mbd"}, +{"mbd", "macroblock decision algorithm (high quality mode)", OFFSET(mb_decision), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, 2, V|E, "mbd"}, {"simple", "use mbcmp (default)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MB_DECISION_SIMPLE }, INT_MIN, INT_MAX, V|E, "mbd"}, {"bits", "use fewest bits", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MB_DECISION_BITS }, INT_MIN, INT_MAX, V|E, "mbd"}, {"rd", "use best rate distortion", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MB_DECISION_RD }, INT_MIN, INT_MAX, V|E, "mbd"}, @@ -403,6 +406,11 @@ static const AVOption options[]={ {"ka", "Karaoke", 0, AV_OPT_TYPE_CONST, {.i64 = AV_AUDIO_SERVICE_TYPE_KARAOKE }, INT_MIN, INT_MAX, A|E, "audio_service_type"}, {"request_sample_fmt", "sample format audio decoders should prefer", OFFSET(request_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, {.i64=AV_SAMPLE_FMT_NONE}, -1, AV_SAMPLE_FMT_NB-1, A|D, "request_sample_fmt"}, {"pkt_timebase", NULL, OFFSET(pkt_timebase), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, 0, INT_MAX, 0}, +{"sub_charenc", "set input text subtitles character encoding", OFFSET(sub_charenc), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, S|D}, +{"sub_charenc_mode", "set input text subtitles character encoding mode", OFFSET(sub_charenc_mode), AV_OPT_TYPE_FLAGS, {.i64 = FF_SUB_CHARENC_MODE_AUTOMATIC}, -1, INT_MAX, S|D, "sub_charenc_mode"}, +{"do_nothing", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_SUB_CHARENC_MODE_DO_NOTHING}, INT_MIN, INT_MAX, S|D, "sub_charenc_mode"}, +{"auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_SUB_CHARENC_MODE_AUTOMATIC}, INT_MIN, INT_MAX, S|D, "sub_charenc_mode"}, +{"pre_decoder", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_SUB_CHARENC_MODE_PRE_DECODER}, INT_MIN, INT_MAX, S|D, "sub_charenc_mode"}, {NULL}, }; diff --git a/mythtv/external/FFmpeg/libavcodec/paf.c b/mythtv/external/FFmpeg/libavcodec/paf.c index adb37ee7b64..78a5d97b202 100644 --- a/mythtv/external/FFmpeg/libavcodec/paf.c +++ b/mythtv/external/FFmpeg/libavcodec/paf.c @@ -20,10 +20,10 @@ */ #include "libavutil/intreadwrite.h" -#include "libavcodec/dsputil.h" #include "libavcodec/paf.h" #include "bytestream.h" #include "avcodec.h" +#include "copy_block.h" #include "internal.h" @@ -377,22 +377,14 @@ static av_cold int paf_vid_close(AVCodecContext *avctx) return 0; } -typedef struct PAFAudioDecContext { - AVFrame frame; -} PAFAudioDecContext; - static av_cold int paf_aud_init(AVCodecContext *avctx) { - PAFAudioDecContext *c = avctx->priv_data; - if (avctx->channels != 2) { av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n"); return AVERROR_INVALIDDATA; } - avcodec_get_frame_defaults(&c->frame); avctx->channel_layout = AV_CH_LAYOUT_STEREO; - avctx->coded_frame = &c->frame; avctx->sample_fmt = AV_SAMPLE_FMT_S16; return 0; @@ -401,7 +393,7 @@ static av_cold int paf_aud_init(AVCodecContext *avctx) static int paf_aud_decode(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *pkt) { - PAFAudioDecContext *c = avctx->priv_data; + AVFrame *frame = data; uint8_t *buf = pkt->data; int16_t *output_samples; const uint8_t *t; @@ -411,11 +403,11 @@ static int paf_aud_decode(AVCodecContext *avctx, void *data, if (frames < 1) return AVERROR_INVALIDDATA; - c->frame.nb_samples = PAF_SOUND_SAMPLES * frames; - if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) + frame->nb_samples = PAF_SOUND_SAMPLES * frames; + if ((ret = ff_get_buffer(avctx, frame)) < 0) return ret; - output_samples = (int16_t *)c->frame.data[0]; + output_samples = (int16_t *)frame->data[0]; for (i = 0; i < frames; i++) { t = buf + 256 * sizeof(uint16_t); for (j = 0; j < PAF_SOUND_SAMPLES; j++) { @@ -428,7 +420,6 @@ static int paf_aud_decode(AVCodecContext *avctx, void *data, } *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; return pkt->size; } @@ -449,7 +440,6 @@ AVCodec ff_paf_audio_decoder = { .name = "paf_audio", .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_PAF_AUDIO, - .priv_data_size = sizeof(PAFAudioDecContext), .init = paf_aud_init, .decode = paf_aud_decode, .capabilities = CODEC_CAP_DR1, diff --git a/mythtv/external/FFmpeg/libavcodec/pcm-mpeg.c b/mythtv/external/FFmpeg/libavcodec/pcm-mpeg.c index fe7c4a71d27..08aad95fba6 100644 --- a/mythtv/external/FFmpeg/libavcodec/pcm-mpeg.c +++ b/mythtv/external/FFmpeg/libavcodec/pcm-mpeg.c @@ -122,26 +122,12 @@ static int pcm_bluray_parse_header(AVCodecContext *avctx, return 0; } -typedef struct PCMBRDecode { - AVFrame frame; -} PCMBRDecode; - -static av_cold int pcm_bluray_decode_init(AVCodecContext * avctx) -{ - PCMBRDecode *s = avctx->priv_data; - - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - - return 0; -} - static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *src = avpkt->data; int buf_size = avpkt->size; - PCMBRDecode *s = avctx->priv_data; GetByteContext gb; int num_source_channels, channel, retval; int sample_size, samples; @@ -166,13 +152,13 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data, samples = buf_size / sample_size; /* get output buffer */ - s->frame.nb_samples = samples; - if ((retval = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = samples; + if ((retval = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return retval; } - dst16 = (int16_t *)s->frame.data[0]; - dst32 = (int32_t *)s->frame.data[0]; + dst16 = (int16_t *)frame->data[0]; + dst32 = (int32_t *)frame->data[0]; if (samples) { switch (avctx->channel_layout) { @@ -306,8 +292,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data, } } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; retval = bytestream2_tell(&gb); if (avctx->debug & FF_DEBUG_BITSTREAM) @@ -320,8 +305,6 @@ AVCodec ff_pcm_bluray_decoder = { .name = "pcm_bluray", .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_PCM_BLURAY, - .priv_data_size = sizeof(PCMBRDecode), - .init = pcm_bluray_decode_init, .decode = pcm_bluray_decode_frame, .capabilities = CODEC_CAP_DR1, .sample_fmts = (const enum AVSampleFormat[]){ diff --git a/mythtv/external/FFmpeg/libavcodec/pcm.c b/mythtv/external/FFmpeg/libavcodec/pcm.c index c0951a9e74f..7f971d9e365 100644 --- a/mythtv/external/FFmpeg/libavcodec/pcm.c +++ b/mythtv/external/FFmpeg/libavcodec/pcm.c @@ -107,7 +107,7 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, n = frame->nb_samples * avctx->channels; samples = (const short *)frame->data[0]; - if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size))) + if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size)) < 0) return ret; dst = avpkt->data; @@ -230,7 +230,6 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } typedef struct PCMDecode { - AVFrame frame; short table[256]; } PCMDecode; @@ -247,7 +246,7 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - switch (avctx->codec->id) { + switch (avctx->codec_id) { case AV_CODEC_ID_PCM_ALAW: for (i = 0; i < 256; i++) s->table[i] = alaw2linear(i); @@ -265,9 +264,6 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx) if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) avctx->bits_per_raw_sample = av_get_bits_per_sample(avctx->codec_id); - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -292,7 +288,7 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx) n /= avctx->channels; \ for (c = 0; c < avctx->channels; c++) { \ int i; \ - dst = s->frame.extended_data[c]; \ + dst = frame->extended_data[c]; \ for (i = n; i > 0; i--) { \ uint ## size ## _t v = bytestream_get_ ## endian(&src); \ AV_WN ## size ## A(dst, (v - offset) << shift); \ @@ -306,6 +302,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, const uint8_t *src = avpkt->data; int buf_size = avpkt->size; PCMDecode *s = avctx->priv_data; + AVFrame *frame = data; int sample_size, c, n, ret, samples_per_block; uint8_t *samples; int32_t *dst_int32_t; @@ -361,12 +358,12 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, n = buf_size / sample_size; /* get output buffer */ - s->frame.nb_samples = n * samples_per_block / avctx->channels; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = n * samples_per_block / avctx->channels; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = s->frame.data[0]; + samples = frame->data[0]; switch (avctx->codec_id) { case AV_CODEC_ID_PCM_U32LE: @@ -413,7 +410,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, n /= avctx->channels; for (c = 0; c < avctx->channels; c++) { int i; - samples = s->frame.extended_data[c]; + samples = frame->extended_data[c]; for (i = n; i > 0; i--) *samples++ = *src++ + 128; } @@ -469,7 +466,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, #endif /* HAVE_BIGENDIAN */ n /= avctx->channels; for (c = 0; c < avctx->channels; c++) { - samples = s->frame.extended_data[c]; + samples = frame->extended_data[c]; bytestream_get_buffer(&src, samples, n * sample_size); } break; @@ -491,16 +488,9 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, case AV_CODEC_ID_PCM_DVD: { const uint8_t *src8; - dst_int32_t = (int32_t *)s->frame.data[0]; + dst_int32_t = (int32_t *)frame->data[0]; n /= avctx->channels; switch (avctx->bits_per_coded_sample) { - case 16: - while (n--) { - c = avctx->channels; - while (c--) - *dst_int32_t++ = bytestream_get_be16(&src) << 16; - } - break; case 20: while (n--) { c = avctx->channels; @@ -531,7 +521,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, int i; n /= avctx->channels; for (c = 0; c < avctx->channels; c++) { - dst_int32_t = (int32_t *)s->frame.extended_data[c]; + dst_int32_t = (int32_t *)frame->extended_data[c]; for (i = 0; i < n; i++) { // extract low 20 bits and expand to 32 bits *dst_int32_t++ = (src[2] << 28) | @@ -554,8 +544,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, return -1; } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return buf_size; } diff --git a/mythtv/external/FFmpeg/libavcodec/pcx.c b/mythtv/external/FFmpeg/libavcodec/pcx.c index bac818c5862..e7f9c240f6a 100644 --- a/mythtv/external/FFmpeg/libavcodec/pcx.c +++ b/mythtv/external/FFmpeg/libavcodec/pcx.c @@ -119,7 +119,7 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, bytes_per_line = bytestream2_get_le16u(&gb); bytes_per_scanline = nplanes * bytes_per_line; - if (bytes_per_scanline < w * bits_per_pixel * nplanes / 8) { + if (bytes_per_scanline < (w * bits_per_pixel * nplanes + 7) / 8) { av_log(avctx, AV_LOG_ERROR, "PCX data is corrupted\n"); return AVERROR_INVALIDDATA; } @@ -147,8 +147,8 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (p->data[0]) avctx->release_buffer(avctx, p); - if (av_image_check_size(w, h, 0, avctx)) - return AVERROR_INVALIDDATA; + if ((ret = av_image_check_size(w, h, 0, avctx)) < 0) + return ret; if (w != avctx->width || h != avctx->height) avcodec_set_dimensions(avctx, w, h); if ((ret = ff_get_buffer(avctx, p)) < 0) { @@ -161,7 +161,7 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, ptr = p->data[0]; stride = p->linesize[0]; - scanline = av_malloc(bytes_per_scanline); + scanline = av_malloc(bytes_per_scanline + FF_INPUT_BUFFER_PADDING_SIZE); if (!scanline) return AVERROR(ENOMEM); @@ -200,7 +200,7 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, GetBitContext s; for (y=0; yg); - palette[i] = ff_cga_palette[FFMIN(pal_idx, 16)]; + palette[i] = ff_cga_palette[FFMIN(pal_idx, 15)]; } } else if (etype == 3) { npal = FFMIN(esize, 16); diff --git a/mythtv/external/FFmpeg/libavcodec/png.c b/mythtv/external/FFmpeg/libavcodec/png.c index b398d910003..a4287bd7e2e 100644 --- a/mythtv/external/FFmpeg/libavcodec/png.c +++ b/mythtv/external/FFmpeg/libavcodec/png.c @@ -38,7 +38,9 @@ static const uint8_t ff_png_pass_xshift[NB_PASSES] = { void *ff_png_zalloc(void *opaque, unsigned int items, unsigned int size) { - return av_mallocz_array(items, size); + if(items >= UINT_MAX / size) + return NULL; + return av_malloc(items * size); } void ff_png_zfree(void *opaque, void *ptr) diff --git a/mythtv/external/FFmpeg/libavcodec/pngdec.c b/mythtv/external/FFmpeg/libavcodec/pngdec.c index c0a1737054c..36db29e53e7 100644 --- a/mythtv/external/FFmpeg/libavcodec/pngdec.c +++ b/mythtv/external/FFmpeg/libavcodec/pngdec.c @@ -96,12 +96,13 @@ static void png_put_interlaced_row(uint8_t *dst, int width, uint8_t *d; const uint8_t *s; - mask = png_pass_mask[pass]; + mask = png_pass_mask[pass]; dsp_mask = png_pass_dsp_mask[pass]; - switch(bits_per_pixel) { + + switch (bits_per_pixel) { case 1: src_x = 0; - for(x = 0; x < width; x++) { + for (x = 0; x < width; x++) { j = (x & 7); if ((dsp_mask << j) & 0x80) { b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1; @@ -114,8 +115,8 @@ static void png_put_interlaced_row(uint8_t *dst, int width, break; case 2: src_x = 0; - for(x = 0; x < width; x++) { - int j2 = 2*(x&3); + for (x = 0; x < width; x++) { + int j2 = 2 * (x & 3); j = (x & 7); if ((dsp_mask << j) & 0x80) { b = (src[src_x >> 2] >> (6 - 2*(src_x & 3))) & 3; @@ -128,7 +129,7 @@ static void png_put_interlaced_row(uint8_t *dst, int width, break; case 4: src_x = 0; - for(x = 0; x < width; x++) { + for (x = 0; x < width; x++) { int j2 = 4*(x&1); j = (x & 7); if ((dsp_mask << j) & 0x80) { @@ -142,9 +143,9 @@ static void png_put_interlaced_row(uint8_t *dst, int width, break; default: bpp = bits_per_pixel >> 3; - d = dst; - s = src; - for(x = 0; x < width; x++) { + d = dst; + s = src; + for (x = 0; x < width; x++) { j = x & 7; if ((dsp_mask << j) & 0x80) { memcpy(d, s, bpp); @@ -160,14 +161,14 @@ static void png_put_interlaced_row(uint8_t *dst, int width, void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp) { int i; - for(i = 0; i < w; i++) { + for (i = 0; i < w; i++) { int a, b, c, p, pa, pb, pc; a = dst[i - bpp]; b = top[i]; c = top[i - bpp]; - p = b - c; + p = b - c; pc = a - c; pa = abs(p); @@ -215,20 +216,20 @@ static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, { int i, p, r, g, b, a; - switch(filter_type) { + switch (filter_type) { case PNG_FILTER_VALUE_NONE: memcpy(dst, src, size); break; case PNG_FILTER_VALUE_SUB: - for(i = 0; i < bpp; i++) { + for (i = 0; i < bpp; i++) { dst[i] = src[i]; } - if(bpp == 4) { + if (bpp == 4) { p = *(int*)dst; - for(; i < size; i+=bpp) { - int s = *(int*)(src+i); - p = ((s&0x7f7f7f7f) + (p&0x7f7f7f7f)) ^ ((s^p)&0x80808080); - *(int*)(dst+i) = p; + for (; i < size; i += bpp) { + int s = *(int*)(src + i); + p = ((s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((s ^ p) & 0x80808080); + *(int*)(dst + i) = p; } } else { #define OP_SUB(x,s,l) x+s @@ -239,7 +240,7 @@ static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, dsp->add_bytes_l2(dst, src, last, size); break; case PNG_FILTER_VALUE_AVG: - for(i = 0; i < bpp; i++) { + for (i = 0; i < bpp; i++) { p = (last[i] >> 1); dst[i] = p + src[i]; } @@ -247,17 +248,17 @@ static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, UNROLL_FILTER(OP_AVG); break; case PNG_FILTER_VALUE_PAETH: - for(i = 0; i < bpp; i++) { + for (i = 0; i < bpp; i++) { p = last[i]; dst[i] = p + src[i]; } - if(bpp > 2 && size > 4) { + if (bpp > 2 && size > 4) { // would write off the end of the array if we let it process the last pixel with bpp=3 - int w = bpp==4 ? size : size-3; - dsp->add_paeth_prediction(dst+i, src+i, last+i, w-i, bpp); + int w = bpp == 4 ? size : size - 3; + dsp->add_paeth_prediction(dst + i, src + i, last + i, w - i, bpp); i = w; } - ff_add_png_paeth_prediction(dst+i, src+i, last+i, size-i, bpp); + ff_add_png_paeth_prediction(dst + i, src + i, last + i, size - i, bpp); break; } } @@ -318,7 +319,7 @@ static void png_handle_row(PNGDecContext *s) } } else { got_line = 0; - for(;;) { + for (;;) { ptr = s->image_buf + s->image_linesize * s->y; if ((ff_png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) { /* if we already read one row, it is time to stop to @@ -337,7 +338,7 @@ static void png_handle_row(PNGDecContext *s) s->y++; if (s->y == s->height) { memset(s->last_row, 0, s->row_size); - for(;;) { + for (;;) { if (s->pass == NB_PASSES - 1) { s->state |= PNG_ALLIMAGE; goto the_end; @@ -363,7 +364,7 @@ static int png_decode_idat(PNGDecContext *s, int length) { int ret; s->zstream.avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb)); - s->zstream.next_in = (unsigned char *)s->gb.buffer; + s->zstream.next_in = (unsigned char *)s->gb.buffer; bytestream2_skip(&s->gb, length); /* decode one line if possible */ @@ -378,7 +379,7 @@ static int png_decode_idat(PNGDecContext *s, int length) png_handle_row(s); } s->zstream.avail_out = s->crow_size; - s->zstream.next_out = s->crow_buf; + s->zstream.next_out = s->crow_buf; } } return 0; @@ -504,19 +505,19 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; PNGDecContext * const s = avctx->priv_data; - AVFrame *picture = data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + AVFrame *picture = data; + AVDictionary *metadata = NULL; + uint8_t *crow_buf_base = NULL; AVFrame *p; - AVDictionary *metadata = NULL; - uint8_t *crow_buf_base = NULL; uint32_t tag, length; int64_t sig; int ret; FFSWAP(AVFrame *, s->current_picture, s->last_picture); - avctx->coded_frame= s->current_picture; + avctx->coded_frame = s->current_picture; p = s->current_picture; bytestream2_init(&s->gb, buf, buf_size); @@ -529,19 +530,18 @@ static int decode_frame(AVCodecContext *avctx, return -1; } - s->y= - s->state=0; -// memset(s, 0, sizeof(PNGDecContext)); + s->y = s->state = 0; + /* init the zlib */ s->zstream.zalloc = ff_png_zalloc; - s->zstream.zfree = ff_png_zfree; + s->zstream.zfree = ff_png_zfree; s->zstream.opaque = NULL; ret = inflateInit(&s->zstream); if (ret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "inflateInit returned %d\n", ret); return -1; } - for(;;) { + for (;;) { if (bytestream2_get_bytes_left(&s->gb) <= 0) { av_log(avctx, AV_LOG_ERROR, "No bytes left\n"); goto fail; @@ -559,14 +559,14 @@ static int decode_frame(AVCodecContext *avctx, ((tag >> 8) & 0xff), ((tag >> 16) & 0xff), ((tag >> 24) & 0xff), length); - switch(tag) { + switch (tag) { case MKTAG('I', 'H', 'D', 'R'): if (length != 13) goto fail; s->width = bytestream2_get_be32(&s->gb); s->height = bytestream2_get_be32(&s->gb); - if(av_image_check_size(s->width, s->height, 0, avctx)){ - s->width= s->height= 0; + if (av_image_check_size(s->width, s->height, 0, avctx)) { + s->width = s->height = 0; av_log(avctx, AV_LOG_ERROR, "Invalid image size\n"); goto fail; } @@ -578,7 +578,8 @@ static int decode_frame(AVCodecContext *avctx, bytestream2_skip(&s->gb, 4); /* crc */ s->state |= PNG_IHDR; if (avctx->debug & FF_DEBUG_PICT_INFO) - av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n", + av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d " + "compression_type=%d filter_type=%d interlace_type=%d\n", s->width, s->height, s->bit_depth, s->color_type, s->compression_type, s->filter_type, s->interlace_type); break; @@ -601,13 +602,13 @@ static int decode_frame(AVCodecContext *avctx, } if (!(s->state & PNG_IDAT)) { /* init image info */ - avctx->width = s->width; + avctx->width = s->width; avctx->height = s->height; - s->channels = ff_png_get_nb_channels(s->color_type); + s->channels = ff_png_get_nb_channels(s->color_type); s->bits_per_pixel = s->bit_depth * s->channels; - s->bpp = (s->bits_per_pixel + 7) >> 3; - s->row_size = (avctx->width * s->bits_per_pixel + 7) >> 3; + s->bpp = (s->bits_per_pixel + 7) >> 3; + s->row_size = (avctx->width * s->bits_per_pixel + 7) >> 3; if ((s->bit_depth == 2 || s->bit_depth == 4 || s->bit_depth == 8) && s->color_type == PNG_COLOR_TYPE_RGB) { @@ -641,16 +642,16 @@ static int decode_frame(AVCodecContext *avctx, s->bit_depth, s->color_type); goto fail; } - if(p->data[0]) + if (p->data[0]) avctx->release_buffer(avctx, p); - p->reference= 3; - if(ff_get_buffer(avctx, p) < 0){ + p->reference = 3; + if (ff_get_buffer(avctx, p) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); goto fail; } - p->pict_type= AV_PICTURE_TYPE_I; - p->key_frame= 1; + p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; p->interlaced_frame = !!s->interlace_type; /* compute the compressed row size */ @@ -665,7 +666,7 @@ static int decode_frame(AVCodecContext *avctx, } av_dlog(avctx, "row_size=%d crow_size =%d\n", s->row_size, s->crow_size); - s->image_buf = p->data[0]; + s->image_buf = p->data[0]; s->image_linesize = p->linesize[0]; /* copy the palette if needed */ if (avctx->pix_fmt == AV_PIX_FMT_PAL8) @@ -686,9 +687,9 @@ static int decode_frame(AVCodecContext *avctx, goto fail; /* we want crow_buf+1 to be 16-byte aligned */ - s->crow_buf = crow_buf_base + 15; + s->crow_buf = crow_buf_base + 15; s->zstream.avail_out = s->crow_size; - s->zstream.next_out = s->crow_buf; + s->zstream.next_out = s->crow_buf; } s->state |= PNG_IDAT; if (png_decode_idat(s, length) < 0) @@ -703,13 +704,13 @@ static int decode_frame(AVCodecContext *avctx, goto skip_tag; /* read the palette */ n = length / 3; - for(i=0;igb); g = bytestream2_get_byte(&s->gb); b = bytestream2_get_byte(&s->gb); s->palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | b; } - for(;i<256;i++) { + for (; i < 256; i++) { s->palette[i] = (0xFFU << 24); } s->state |= PNG_PLTE; @@ -725,7 +726,7 @@ static int decode_frame(AVCodecContext *avctx, length > 256 || !(s->state & PNG_PLTE)) goto skip_tag; - for(i=0;igb); s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24); } @@ -759,68 +760,72 @@ static int decode_frame(AVCodecContext *avctx, } exit_loop: - if(s->bits_per_pixel == 1 && s->color_type == PNG_COLOR_TYPE_PALETTE){ - int i, j; + if (s->bits_per_pixel == 1 && s->color_type == PNG_COLOR_TYPE_PALETTE){ + int i, j, k; uint8_t *pd = s->current_picture->data[0]; - for(j=0; j < s->height; j++) { - for(i=s->width/8-1; i>=0; i--) { - pd[8*i+7]= pd[i] &1; - pd[8*i+6]= (pd[i]>>1)&1; - pd[8*i+5]= (pd[i]>>2)&1; - pd[8*i+4]= (pd[i]>>3)&1; - pd[8*i+3]= (pd[i]>>4)&1; - pd[8*i+2]= (pd[i]>>5)&1; - pd[8*i+1]= (pd[i]>>6)&1; - pd[8*i+0]= pd[i]>>7; + for (j = 0; j < s->height; j++) { + i = s->width / 8; + for (k = 7; k >= 1; k--) + if ((s->width&7) >= k) + pd[8*i + k - 1] = (pd[i]>>8-k) & 1; + for (i--; i >= 0; i--) { + pd[8*i + 7]= pd[i] & 1; + pd[8*i + 6]= (pd[i]>>1) & 1; + pd[8*i + 5]= (pd[i]>>2) & 1; + pd[8*i + 4]= (pd[i]>>3) & 1; + pd[8*i + 3]= (pd[i]>>4) & 1; + pd[8*i + 2]= (pd[i]>>5) & 1; + pd[8*i + 1]= (pd[i]>>6) & 1; + pd[8*i + 0]= pd[i]>>7; } pd += s->image_linesize; } } - if(s->bits_per_pixel == 2){ + if (s->bits_per_pixel == 2){ int i, j; uint8_t *pd = s->current_picture->data[0]; - for(j=0; j < s->height; j++) { - i = s->width/4; + for (j = 0; j < s->height; j++) { + i = s->width / 4; if (s->color_type == PNG_COLOR_TYPE_PALETTE){ - if ((s->width&3) >= 3) pd[4*i+2]= (pd[i]>>2)&3; - if ((s->width&3) >= 2) pd[4*i+1]= (pd[i]>>4)&3; - if ((s->width&3) >= 1) pd[4*i+0]= pd[i]>>6; - for(i--; i>=0; i--) { - pd[4*i+3]= pd[i] &3; - pd[4*i+2]= (pd[i]>>2)&3; - pd[4*i+1]= (pd[i]>>4)&3; - pd[4*i+0]= pd[i]>>6; - } + if ((s->width&3) >= 3) pd[4*i + 2]= (pd[i] >> 2) & 3; + if ((s->width&3) >= 2) pd[4*i + 1]= (pd[i] >> 4) & 3; + if ((s->width&3) >= 1) pd[4*i + 0]= pd[i] >> 6; + for (i--; i >= 0; i--) { + pd[4*i + 3]= pd[i] & 3; + pd[4*i + 2]= (pd[i]>>2) & 3; + pd[4*i + 1]= (pd[i]>>4) & 3; + pd[4*i + 0]= pd[i]>>6; + } } else { - if ((s->width&3) >= 3) pd[4*i+2]= ((pd[i]>>2)&3)*0x55; - if ((s->width&3) >= 2) pd[4*i+1]= ((pd[i]>>4)&3)*0x55; - if ((s->width&3) >= 1) pd[4*i+0]= ( pd[i]>>6 )*0x55; - for(i--; i>=0; i--) { - pd[4*i+3]= ( pd[i] &3)*0x55; - pd[4*i+2]= ((pd[i]>>2)&3)*0x55; - pd[4*i+1]= ((pd[i]>>4)&3)*0x55; - pd[4*i+0]= ( pd[i]>>6 )*0x55; + if ((s->width&3) >= 3) pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55; + if ((s->width&3) >= 2) pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55; + if ((s->width&3) >= 1) pd[4*i + 0]= ( pd[i]>>6 )*0x55; + for (i--; i >= 0; i--) { + pd[4*i + 3]= ( pd[i] & 3)*0x55; + pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55; + pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55; + pd[4*i + 0]= ( pd[i]>>6 )*0x55; } } pd += s->image_linesize; } } - if(s->bits_per_pixel == 4){ + if (s->bits_per_pixel == 4){ int i, j; uint8_t *pd = s->current_picture->data[0]; - for(j=0; j < s->height; j++) { - i=s->width/2; + for (j = 0; j < s->height; j++) { + i = s->width/2; if (s->color_type == PNG_COLOR_TYPE_PALETTE){ if (s->width&1) pd[2*i+0]= pd[i]>>4; - for(i--; i>=0; i--) { - pd[2*i+1]= pd[i]&15; - pd[2*i+0]= pd[i]>>4; + for (i--; i >= 0; i--) { + pd[2*i + 1] = pd[i] & 15; + pd[2*i + 0] = pd[i] >> 4; } } else { - if (s->width&1) pd[2*i+0]= (pd[i]>>4)*0x11; - for(i--; i>=0; i--) { - pd[2*i+1]= (pd[i]&15)*0x11; - pd[2*i+0]= (pd[i]>>4)*0x11; + if (s->width & 1) pd[2*i + 0]= (pd[i] >> 4) * 0x11; + for (i--; i >= 0; i--) { + pd[2*i + 1] = (pd[i] & 15) * 0x11; + pd[2*i + 0] = (pd[i] >> 4) * 0x11; } } pd += s->image_linesize; @@ -828,29 +833,29 @@ static int decode_frame(AVCodecContext *avctx, } /* handle p-frames only if a predecessor frame is available */ - if(s->last_picture->data[0] != NULL) { - if( !(avpkt->flags & AV_PKT_FLAG_KEY) + if (s->last_picture->data[0] != NULL) { + if ( !(avpkt->flags & AV_PKT_FLAG_KEY) && s->last_picture->width == s->current_picture->width && s->last_picture->height== s->current_picture->height && s->last_picture->format== s->current_picture->format ) { int i, j; - uint8_t *pd = s->current_picture->data[0]; + uint8_t *pd = s->current_picture->data[0]; uint8_t *pd_last = s->last_picture->data[0]; - for(j=0; j < s->height; j++) { - for(i=0; i < s->width * s->bpp; i++) { + for (j = 0; j < s->height; j++) { + for (i = 0; i < s->width * s->bpp; i++) { pd[i] += pd_last[i]; } - pd += s->image_linesize; + pd += s->image_linesize; pd_last += s->image_linesize; } } } - s->current_picture->metadata = metadata; - metadata = NULL; - *picture= *s->current_picture; + av_frame_set_metadata(&s->current_picture, metadata); + metadata = NULL; + *picture = *s->current_picture; *got_frame = 1; ret = bytestream2_tell(&s->gb); @@ -872,7 +877,7 @@ static av_cold int png_dec_init(AVCodecContext *avctx) PNGDecContext *s = avctx->priv_data; s->current_picture = &s->picture1; - s->last_picture = &s->picture2; + s->last_picture = &s->picture2; avcodec_get_frame_defaults(&s->picture1); avcodec_get_frame_defaults(&s->picture2); diff --git a/mythtv/external/FFmpeg/libavcodec/pnm.c b/mythtv/external/FFmpeg/libavcodec/pnm.c index 13ecbb057fa..6d1eb6d0edc 100644 --- a/mythtv/external/FFmpeg/libavcodec/pnm.c +++ b/mythtv/external/FFmpeg/libavcodec/pnm.c @@ -65,7 +65,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) pnm_get(s, buf1, sizeof(buf1)); s->type= buf1[1]-'0'; if(buf1[0] != 'P') - return -1; + return AVERROR_INVALIDDATA; if (s->type==1 || s->type==4) { avctx->pix_fmt = AV_PIX_FMT_MONOWHITE; @@ -103,12 +103,12 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) } else if (!strcmp(buf1, "ENDHDR")) { break; } else { - return -1; + return AVERROR_INVALIDDATA; } } /* check that all tags are present */ if (w <= 0 || h <= 0 || maxval <= 0 || depth <= 0 || tuple_type[0] == '\0' || av_image_check_size(w, h, 0, avctx) || s->bytestream >= s->bytestream_end) - return -1; + return AVERROR_INVALIDDATA; avctx->width = w; avctx->height = h; @@ -137,18 +137,18 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) avctx->pix_fmt = AV_PIX_FMT_RGBA64BE; } } else { - return -1; + return AVERROR_INVALIDDATA; } return 0; } else { - return -1; + return AVERROR_INVALIDDATA; } pnm_get(s, buf1, sizeof(buf1)); w = atoi(buf1); pnm_get(s, buf1, sizeof(buf1)); h = atoi(buf1); if(w <= 0 || h <= 0 || av_image_check_size(w, h, 0, avctx) || s->bytestream >= s->bytestream_end) - return -1; + return AVERROR_INVALIDDATA; avctx->width = w; avctx->height = h; @@ -165,21 +165,28 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) avctx->pix_fmt = AV_PIX_FMT_GRAY16BE; } else if (avctx->pix_fmt == AV_PIX_FMT_RGB24) { avctx->pix_fmt = AV_PIX_FMT_RGB48BE; + } else if (avctx->pix_fmt == AV_PIX_FMT_YUV420P && s->maxval < 65536) { + if (s->maxval < 512) + avctx->pix_fmt = AV_PIX_FMT_YUV420P9BE; + else if (s->maxval < 1024) + avctx->pix_fmt = AV_PIX_FMT_YUV420P10BE; + else + avctx->pix_fmt = AV_PIX_FMT_YUV420P16; } else { av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format\n"); avctx->pix_fmt = AV_PIX_FMT_NONE; - return -1; + return AVERROR_INVALIDDATA; } } }else s->maxval=1; /* more check if YUV420 */ - if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) { + if (av_pix_fmt_desc_get(avctx->pix_fmt)->flags & PIX_FMT_PLANAR) { if ((avctx->width & 1) != 0) - return -1; + return AVERROR_INVALIDDATA; h = (avctx->height * 2); if ((h % 3) != 0) - return -1; + return AVERROR_INVALIDDATA; h /= 3; avctx->height = h; } diff --git a/mythtv/external/FFmpeg/libavcodec/pnm.h b/mythtv/external/FFmpeg/libavcodec/pnm.h index ac4b1084fb8..bb2cc77b873 100644 --- a/mythtv/external/FFmpeg/libavcodec/pnm.h +++ b/mythtv/external/FFmpeg/libavcodec/pnm.h @@ -34,7 +34,7 @@ typedef struct PNMContext { } PNMContext; int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s); -av_cold int ff_pnm_end(AVCodecContext *avctx); -av_cold int ff_pnm_init(AVCodecContext *avctx); +int ff_pnm_end(AVCodecContext *avctx); +int ff_pnm_init(AVCodecContext *avctx); #endif /* AVCODEC_PNM_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/pnmdec.c b/mythtv/external/FFmpeg/libavcodec/pnmdec.c index fd17fe34998..3280eef6720 100644 --- a/mythtv/external/FFmpeg/libavcodec/pnmdec.c +++ b/mythtv/external/FFmpeg/libavcodec/pnmdec.c @@ -41,8 +41,8 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, s->bytestream = (uint8_t *)buf; s->bytestream_end = (uint8_t *)buf + buf_size; - if (ff_pnm_decode_header(avctx, s) < 0) - return AVERROR_INVALIDDATA; + if ((ret = ff_pnm_decode_header(avctx, s)) < 0) + return ret; if (p->data[0]) avctx->release_buffer(avctx, p); @@ -57,7 +57,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, switch (avctx->pix_fmt) { default: - return AVERROR_INVALIDDATA; + return AVERROR(EINVAL); case AV_PIX_FMT_RGBA64BE: n = avctx->width * 8; components=4; @@ -157,12 +157,16 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, } break; case AV_PIX_FMT_YUV420P: + case AV_PIX_FMT_YUV420P9BE: + case AV_PIX_FMT_YUV420P10BE: { unsigned char *ptr1, *ptr2; n = avctx->width; ptr = p->data[0]; linesize = p->linesize[0]; + if (s->maxval >= 256) + n *= 2; if (s->bytestream + n * avctx->height * 3 / 2 > s->bytestream_end) return AVERROR_INVALIDDATA; for (i = 0; i < avctx->height; i++) { @@ -184,6 +188,47 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, } } break; + case AV_PIX_FMT_YUV420P16: + { + uint16_t *ptr1, *ptr2; + const int f = (65535 * 32768 + s->maxval / 2) / s->maxval; + unsigned int j, v; + + n = avctx->width * 2; + ptr = p->data[0]; + linesize = p->linesize[0]; + if (s->bytestream + n * avctx->height * 3 / 2 > s->bytestream_end) + return AVERROR_INVALIDDATA; + for (i = 0; i < avctx->height; i++) { + for (j = 0; j < n / 2; j++) { + v = av_be2ne16(((uint16_t *)s->bytestream)[j]); + ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15; + } + s->bytestream += n; + ptr += linesize; + } + ptr1 = (uint16_t*)p->data[1]; + ptr2 = (uint16_t*)p->data[2]; + n >>= 1; + h = avctx->height >> 1; + for (i = 0; i < h; i++) { + for (j = 0; j < n / 2; j++) { + v = av_be2ne16(((uint16_t *)s->bytestream)[j]); + ptr1[j] = (v * f + 16384) >> 15; + } + s->bytestream += n; + + for (j = 0; j < n / 2; j++) { + v = av_be2ne16(((uint16_t *)s->bytestream)[j]); + ptr2[j] = (v * f + 16384) >> 15; + } + s->bytestream += n; + + ptr1 += p->linesize[1] / 2; + ptr2 += p->linesize[2] / 2; + } + } + break; } *picture = s->picture; *got_frame = 1; diff --git a/mythtv/external/FFmpeg/libavcodec/pnmenc.c b/mythtv/external/FFmpeg/libavcodec/pnmenc.c index ab20cf558f7..8cd96bed5dd 100644 --- a/mythtv/external/FFmpeg/libavcodec/pnmenc.c +++ b/mythtv/external/FFmpeg/libavcodec/pnmenc.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/pixdesc.h" #include "avcodec.h" #include "internal.h" #include "pnm.h" @@ -77,6 +78,11 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, n = avctx->width; h1 = (h * 3) / 2; break; + case AV_PIX_FMT_YUV420P16BE: + c = '5'; + n = avctx->width * 2; + h1 = (h * 3) / 2; + break; default: return -1; } @@ -84,8 +90,9 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, "P%c\n%d %d\n", c, avctx->width, h1); s->bytestream += strlen(s->bytestream); if (avctx->pix_fmt != AV_PIX_FMT_MONOWHITE) { + int maxdepth = (1 << (av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth_minus1 + 1)) - 1; snprintf(s->bytestream, s->bytestream_end - s->bytestream, - "%d\n", (avctx->pix_fmt != AV_PIX_FMT_GRAY16BE && avctx->pix_fmt != AV_PIX_FMT_RGB48BE) ? 255 : 65535); + "%d\n", maxdepth); s->bytestream += strlen(s->bytestream); } @@ -97,7 +104,7 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, ptr += linesize; } - if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) { + if (avctx->pix_fmt == AV_PIX_FMT_YUV420P || avctx->pix_fmt == AV_PIX_FMT_YUV420P16BE) { h >>= 1; n >>= 1; ptr1 = p->data[1]; @@ -142,7 +149,9 @@ AVCodec ff_pgmyuv_encoder = { .priv_data_size = sizeof(PNMContext), .init = ff_pnm_init, .encode2 = pnm_encode_frame, - .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE }, + .pix_fmts = (const enum AVPixelFormat[]){ + AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P16BE, AV_PIX_FMT_NONE + }, .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), }; #endif diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/Makefile b/mythtv/external/FFmpeg/libavcodec/ppc/Makefile index c8c3025bf08..a2ce9ebafb7 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/Makefile +++ b/mythtv/external/FFmpeg/libavcodec/ppc/Makefile @@ -1,6 +1,9 @@ OBJS += ppc/dsputil_ppc.o \ ppc/videodsp_ppc.o \ +OBJS-$(CONFIG_H264CHROMA) += ppc/h264chroma_init.o +OBJS-$(CONFIG_H264QPEL) += ppc/h264_qpel.o +OBJS-$(CONFIG_VORBIS_DECODER) += ppc/vorbisdsp_altivec.o OBJS-$(CONFIG_VP3DSP) += ppc/vp3dsp_altivec.o FFT-OBJS-$(HAVE_GNU_AS) += ppc/fft_altivec_s.o @@ -14,7 +17,6 @@ ALTIVEC-OBJS-$(CONFIG_VP8_DECODER) += ppc/vp8dsp_altivec.o ALTIVEC-OBJS += ppc/dsputil_altivec.o \ ppc/fdct_altivec.o \ - ppc/float_altivec.o \ ppc/fmtconvert_altivec.o \ ppc/gmc_altivec.o \ ppc/idct_altivec.o \ diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/dsputil_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/dsputil_altivec.c index 5619c3fc030..75a6a6ab915 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/dsputil_altivec.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/dsputil_altivec.c @@ -24,6 +24,7 @@ #if HAVE_ALTIVEC_H #include #endif +#include "libavutil/attributes.h" #include "libavutil/ppc/types_altivec.h" #include "libavutil/ppc/util_altivec.h" #include "libavcodec/dsputil.h" @@ -476,7 +477,7 @@ static int pix_sum_altivec(uint8_t * pix, int line_size) return s; } -static void get_pixels_altivec(DCTELEM *av_restrict block, const uint8_t *pixels, int line_size) +static void get_pixels_altivec(int16_t *restrict block, const uint8_t *pixels, int line_size) { int i; vector unsigned char perm = vec_lvsl(0, pixels); @@ -502,7 +503,7 @@ static void get_pixels_altivec(DCTELEM *av_restrict block, const uint8_t *pixels } } -static void diff_pixels_altivec(DCTELEM *av_restrict block, const uint8_t *s1, +static void diff_pixels_altivec(int16_t *restrict block, const uint8_t *s1, const uint8_t *s2, int stride) { int i; @@ -576,7 +577,7 @@ static void diff_pixels_altivec(DCTELEM *av_restrict block, const uint8_t *s1, } -static void clear_block_altivec(DCTELEM *block) { +static void clear_block_altivec(int16_t *block) { LOAD_ZERO; vec_st(zero_s16v, 0, block); vec_st(zero_s16v, 16, block); @@ -607,7 +608,7 @@ static void add_bytes_altivec(uint8_t *dst, uint8_t *src, int w) { } /* next one assumes that ((line_size % 16) == 0) */ -void ff_put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h) +void ff_put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { register vector unsigned char pixelsv1, pixelsv2; register vector unsigned char pixelsv1B, pixelsv2B; @@ -616,9 +617,9 @@ void ff_put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_siz register vector unsigned char perm = vec_lvsl(0, pixels); int i; - register int line_size_2 = line_size << 1; - register int line_size_3 = line_size + line_size_2; - register int line_size_4 = line_size << 2; + register ptrdiff_t line_size_2 = line_size << 1; + register ptrdiff_t line_size_3 = line_size + line_size_2; + register ptrdiff_t line_size_4 = line_size << 2; // hand-unrolling the loop by 4 gains about 15% // mininum execution time goes from 74 to 60 cycles @@ -649,7 +650,7 @@ void ff_put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_siz /* next one assumes that ((line_size % 16) == 0) */ #define op_avg(a,b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEUL)>>1) ) -void ff_avg_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h) +void ff_avg_pixels16_altivec(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { register vector unsigned char pixelsv1, pixelsv2, pixelsv, blockv; register vector unsigned char perm = vec_lvsl(0, pixels); @@ -668,7 +669,7 @@ void ff_avg_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_siz } /* next one assumes that ((line_size % 8) == 0) */ -static void avg_pixels8_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h) +static void avg_pixels8_altivec(uint8_t * block, const uint8_t * pixels, ptrdiff_t line_size, int h) { register vector unsigned char pixelsv1, pixelsv2, pixelsv, blockv; int i; @@ -699,7 +700,7 @@ static void avg_pixels8_altivec(uint8_t * block, const uint8_t * pixels, int lin } /* next one assumes that ((line_size % 8) == 0) */ -static void put_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void put_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { register int i; register vector unsigned char pixelsv1, pixelsv2, pixelsavg; @@ -758,7 +759,7 @@ static void put_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int l } /* next one assumes that ((line_size % 8) == 0) */ -static void put_no_rnd_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void put_no_rnd_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { register int i; register vector unsigned char pixelsv1, pixelsv2, pixelsavg; @@ -818,7 +819,7 @@ static void put_no_rnd_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels } /* next one assumes that ((line_size % 16) == 0) */ -static void put_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h) +static void put_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, ptrdiff_t line_size, int h) { register int i; register vector unsigned char pixelsv1, pixelsv2, pixelsv3, pixelsv4; @@ -886,7 +887,7 @@ static void put_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, in } /* next one assumes that ((line_size % 16) == 0) */ -static void put_no_rnd_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h) +static void put_no_rnd_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, ptrdiff_t line_size, int h) { register int i; register vector unsigned char pixelsv1, pixelsv2, pixelsv3, pixelsv4; @@ -1283,31 +1284,8 @@ static int hadamard8_diff16_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, ui return score; } -static void vorbis_inverse_coupling_altivec(float *mag, float *ang, - int blocksize) -{ - int i; - vector float m, a; - vector bool int t0, t1; - const vector unsigned int v_31 = //XXX - vec_add(vec_add(vec_splat_u32(15),vec_splat_u32(15)),vec_splat_u32(1)); - for (i = 0; i < blocksize; i += 4) { - m = vec_ld(0, mag+i); - a = vec_ld(0, ang+i); - t0 = vec_cmple(m, (vector float)vec_splat_u32(0)); - t1 = vec_cmple(a, (vector float)vec_splat_u32(0)); - a = vec_xor(a, (vector float) vec_sl((vector unsigned int)t0, v_31)); - t0 = (vector bool int)vec_and(a, t1); - t1 = (vector bool int)vec_andc(a, t1); - a = vec_sub(m, (vector float)t1); - m = vec_add(m, (vector float)t0); - vec_stl(a, 0, ang+i); - vec_stl(m, 0, mag+i); - } -} - /* next one assumes that ((line_size % 8) == 0) */ -static void avg_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void avg_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) { register int i; register vector unsigned char pixelsv1, pixelsv2, pixelsavg; @@ -1369,7 +1347,7 @@ static void avg_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int l } } -void ff_dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx) +av_cold void ff_dsputil_init_altivec(DSPContext *c, AVCodecContext *avctx) { const int high_bit_depth = avctx->bits_per_raw_sample > 8; @@ -1403,6 +1381,4 @@ void ff_dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx) c->hadamard8_diff[0] = hadamard8_diff16_altivec; c->hadamard8_diff[1] = hadamard8_diff8x8_altivec; - if (CONFIG_VORBIS_DECODER) - c->vorbis_inverse_coupling = vorbis_inverse_coupling_altivec; } diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/dsputil_altivec.h b/mythtv/external/FFmpeg/libavcodec/ppc/dsputil_altivec.h index 0b5e404225d..0e769ab0606 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/dsputil_altivec.h +++ b/mythtv/external/FFmpeg/libavcodec/ppc/dsputil_altivec.h @@ -26,9 +26,9 @@ #include #include "libavcodec/dsputil.h" -void ff_put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h); +void ff_put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h); -void ff_avg_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h); +void ff_avg_pixels16_altivec(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h); void ff_fdct_altivec(int16_t *block); void ff_gmc1_altivec(uint8_t *dst, uint8_t *src, int stride, int h, @@ -36,8 +36,6 @@ void ff_gmc1_altivec(uint8_t *dst, uint8_t *src, int stride, int h, void ff_idct_put_altivec(uint8_t *dest, int line_size, int16_t *block); void ff_idct_add_altivec(uint8_t *dest, int line_size, int16_t *block); -void ff_dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx); - void ff_dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx); void ff_float_init_altivec(DSPContext* c, AVCodecContext *avctx); void ff_int_init_altivec(DSPContext* c, AVCodecContext *avctx); diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/dsputil_ppc.c b/mythtv/external/FFmpeg/libavcodec/ppc/dsputil_ppc.c index 32141e4952b..4b2bd60858e 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/dsputil_ppc.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/dsputil_ppc.c @@ -22,9 +22,9 @@ #include +#include "libavutil/attributes.h" #include "libavutil/cpu.h" #include "libavutil/mem.h" -#include "libavcodec/dsputil.h" #include "dsputil_altivec.h" /* ***** WARNING ***** WARNING ***** WARNING ***** */ @@ -47,7 +47,7 @@ distinguish, and use dcbz (32 bytes) or dcbzl (one cache line) as required. see and */ -static void clear_blocks_dcbz32_ppc(DCTELEM *blocks) +static void clear_blocks_dcbz32_ppc(int16_t *blocks) { register int misal = ((unsigned long)blocks & 0x00000010); register int i = 0; @@ -58,7 +58,7 @@ static void clear_blocks_dcbz32_ppc(DCTELEM *blocks) ((unsigned long*)blocks)[3] = 0L; i += 16; } - for ( ; i < sizeof(DCTELEM)*6*64-31 ; i += 32) { + for ( ; i < sizeof(int16_t)*6*64-31 ; i += 32) { __asm__ volatile("dcbz %0,%1" : : "b" (blocks), "r" (i) : "memory"); } if (misal) { @@ -73,7 +73,7 @@ static void clear_blocks_dcbz32_ppc(DCTELEM *blocks) /* same as above, when dcbzl clear a whole 128B cache line i.e. the PPC970 aka G5 */ #if HAVE_DCBZL -static void clear_blocks_dcbz128_ppc(DCTELEM *blocks) +static void clear_blocks_dcbz128_ppc(int16_t *blocks) { register int misal = ((unsigned long)blocks & 0x0000007f); register int i = 0; @@ -81,17 +81,17 @@ static void clear_blocks_dcbz128_ppc(DCTELEM *blocks) // we could probably also optimize this case, // but there's not much point as the machines // aren't available yet (2003-06-26) - memset(blocks, 0, sizeof(DCTELEM)*6*64); + memset(blocks, 0, sizeof(int16_t)*6*64); } else - for ( ; i < sizeof(DCTELEM)*6*64 ; i += 128) { + for ( ; i < sizeof(int16_t)*6*64 ; i += 128) { __asm__ volatile("dcbzl %0,%1" : : "b" (blocks), "r" (i) : "memory"); } } #else -static void clear_blocks_dcbz128_ppc(DCTELEM *blocks) +static void clear_blocks_dcbz128_ppc(int16_t *blocks) { - memset(blocks, 0, sizeof(DCTELEM)*6*64); + memset(blocks, 0, sizeof(int16_t)*6*64); } #endif @@ -137,7 +137,7 @@ static long check_dcbzl_effect(void) } #endif -void ff_dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx) +av_cold void ff_dsputil_init_ppc(DSPContext *c, AVCodecContext *avctx) { const int high_bit_depth = avctx->bits_per_raw_sample > 8; int mm_flags = av_get_cpu_flags(); @@ -164,11 +164,8 @@ void ff_dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx) } #if HAVE_ALTIVEC - if(CONFIG_H264_DECODER) ff_dsputil_h264_init_ppc(c, avctx); - if (mm_flags & AV_CPU_FLAG_ALTIVEC) { ff_dsputil_init_altivec(c, avctx); - ff_float_init_altivec(c, avctx); ff_int_init_altivec(c, avctx); c->gmc1 = ff_gmc1_altivec; diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/fdct_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/fdct_altivec.c index 608dac42956..acab127314d 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/fdct_altivec.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/fdct_altivec.c @@ -23,7 +23,6 @@ #include #endif #include "libavutil/common.h" -#include "libavcodec/dsputil.h" #include "dsputil_altivec.h" #define vs16(v) ((vector signed short)(v)) diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/float_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/float_altivec.c deleted file mode 100644 index e7b04ece6a4..00000000000 --- a/mythtv/external/FFmpeg/libavcodec/ppc/float_altivec.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2006 Luca Barbato - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "libavutil/ppc/util_altivec.h" -#include "libavcodec/dsputil.h" - -#include "dsputil_altivec.h" - -static void vector_fmul_reverse_altivec(float *dst, const float *src0, - const float *src1, int len) -{ - int i; - vector float d, s0, s1, h0, l0, - s2, s3, zero = (vector float)vec_splat_u32(0); - src1 += len-4; - for(i=0; ivector_fmul_reverse = vector_fmul_reverse_altivec; - c->vector_fmul_add = vector_fmul_add_altivec; - if(!(avctx->flags & CODEC_FLAG_BITEXACT)) { - c->vector_fmul_window = vector_fmul_window_altivec; - } -} diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/fmtconvert_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/fmtconvert_altivec.c index d40ce075839..b29c7d4d39b 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/fmtconvert_altivec.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/fmtconvert_altivec.c @@ -21,6 +21,7 @@ #include "libavcodec/fmtconvert.h" #include "libavutil/ppc/util_altivec.h" +#include "libavutil/attributes.h" #include "libavutil/mem.h" #include "dsputil_altivec.h" @@ -93,7 +94,7 @@ static void float_to_int16_stride_altivec(int16_t *dst, const float *src, long len, int stride) { int i; - vector signed short d, s; + vector signed short d; for (i = 0; i < len - 7; i += 8) { d = float_to_int16_one_altivec(src + i); @@ -155,7 +156,7 @@ static void float_to_int16_interleave_altivec(int16_t *dst, const float **src, } } -void ff_fmt_convert_init_altivec(FmtConvertContext *c, AVCodecContext *avctx) +av_cold void ff_fmt_convert_init_altivec(FmtConvertContext *c, AVCodecContext *avctx) { c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_altivec; if (!(avctx->flags & CODEC_FLAG_BITEXACT)) { diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/gmc_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/gmc_altivec.c index 4e361214d02..4db761de448 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/gmc_altivec.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/gmc_altivec.c @@ -23,7 +23,6 @@ #include "libavutil/mem.h" #include "libavutil/ppc/types_altivec.h" #include "libavutil/ppc/util_altivec.h" -#include "libavcodec/dsputil.h" #include "dsputil_altivec.h" /* diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/h264_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/h264_altivec.c index be54b48303f..3c2bb4d630d 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/h264_altivec.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/h264_altivec.c @@ -18,262 +18,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/attributes.h" #include "libavutil/cpu.h" #include "libavutil/intreadwrite.h" #include "libavutil/ppc/types_altivec.h" #include "libavutil/ppc/util_altivec.h" -#include "libavcodec/dsputil.h" #include "libavcodec/h264data.h" #include "libavcodec/h264dsp.h" -#include "dsputil_altivec.h" - -#define PUT_OP_U8_ALTIVEC(d, s, dst) d = s -#define AVG_OP_U8_ALTIVEC(d, s, dst) d = vec_avg(dst, s) - -#define OP_U8_ALTIVEC PUT_OP_U8_ALTIVEC -#define PREFIX_h264_chroma_mc8_altivec put_h264_chroma_mc8_altivec -#define PREFIX_h264_chroma_mc8_num altivec_put_h264_chroma_mc8_num -#define PREFIX_h264_qpel16_h_lowpass_altivec put_h264_qpel16_h_lowpass_altivec -#define PREFIX_h264_qpel16_h_lowpass_num altivec_put_h264_qpel16_h_lowpass_num -#define PREFIX_h264_qpel16_v_lowpass_altivec put_h264_qpel16_v_lowpass_altivec -#define PREFIX_h264_qpel16_v_lowpass_num altivec_put_h264_qpel16_v_lowpass_num -#define PREFIX_h264_qpel16_hv_lowpass_altivec put_h264_qpel16_hv_lowpass_altivec -#define PREFIX_h264_qpel16_hv_lowpass_num altivec_put_h264_qpel16_hv_lowpass_num -#include "h264_altivec_template.c" -#undef OP_U8_ALTIVEC -#undef PREFIX_h264_chroma_mc8_altivec -#undef PREFIX_h264_chroma_mc8_num -#undef PREFIX_h264_qpel16_h_lowpass_altivec -#undef PREFIX_h264_qpel16_h_lowpass_num -#undef PREFIX_h264_qpel16_v_lowpass_altivec -#undef PREFIX_h264_qpel16_v_lowpass_num -#undef PREFIX_h264_qpel16_hv_lowpass_altivec -#undef PREFIX_h264_qpel16_hv_lowpass_num - -#define OP_U8_ALTIVEC AVG_OP_U8_ALTIVEC -#define PREFIX_h264_chroma_mc8_altivec avg_h264_chroma_mc8_altivec -#define PREFIX_h264_chroma_mc8_num altivec_avg_h264_chroma_mc8_num -#define PREFIX_h264_qpel16_h_lowpass_altivec avg_h264_qpel16_h_lowpass_altivec -#define PREFIX_h264_qpel16_h_lowpass_num altivec_avg_h264_qpel16_h_lowpass_num -#define PREFIX_h264_qpel16_v_lowpass_altivec avg_h264_qpel16_v_lowpass_altivec -#define PREFIX_h264_qpel16_v_lowpass_num altivec_avg_h264_qpel16_v_lowpass_num -#define PREFIX_h264_qpel16_hv_lowpass_altivec avg_h264_qpel16_hv_lowpass_altivec -#define PREFIX_h264_qpel16_hv_lowpass_num altivec_avg_h264_qpel16_hv_lowpass_num -#include "h264_altivec_template.c" -#undef OP_U8_ALTIVEC -#undef PREFIX_h264_chroma_mc8_altivec -#undef PREFIX_h264_chroma_mc8_num -#undef PREFIX_h264_qpel16_h_lowpass_altivec -#undef PREFIX_h264_qpel16_h_lowpass_num -#undef PREFIX_h264_qpel16_v_lowpass_altivec -#undef PREFIX_h264_qpel16_v_lowpass_num -#undef PREFIX_h264_qpel16_hv_lowpass_altivec -#undef PREFIX_h264_qpel16_hv_lowpass_num - -#define H264_MC(OPNAME, SIZE, CODETYPE) \ -static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## CODETYPE (uint8_t *dst, uint8_t *src, int stride){\ - ff_ ## OPNAME ## pixels ## SIZE ## _ ## CODETYPE(dst, src, stride, SIZE);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){ \ - DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ - put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(dst, src, stride, stride);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ - put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+1, half, stride, stride, SIZE);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(dst, src, stride, stride);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+stride, half, stride, stride, SIZE);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ - DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ - put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ - DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ - put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ - DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ - put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ - DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ - put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ - OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(dst, tmp, src, stride, SIZE, stride);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ - DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ - DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ - put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\ - put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ - DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ - DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ - put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\ - put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ - DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ - DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\ - put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\ -}\ -\ -static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ - DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ - DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\ - put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\ -}\ - -static inline void put_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1, - const uint8_t * src2, int dst_stride, - int src_stride1, int h) -{ - int i; - vec_u8 a, b, d, tmp1, tmp2, mask, mask_, edges, align; - - mask_ = vec_lvsl(0, src2); - - for (i = 0; i < h; i++) { - - tmp1 = vec_ld(i * src_stride1, src1); - mask = vec_lvsl(i * src_stride1, src1); - tmp2 = vec_ld(i * src_stride1 + 15, src1); - - a = vec_perm(tmp1, tmp2, mask); - - tmp1 = vec_ld(i * 16, src2); - tmp2 = vec_ld(i * 16 + 15, src2); - - b = vec_perm(tmp1, tmp2, mask_); - - tmp1 = vec_ld(0, dst); - mask = vec_lvsl(0, dst); - tmp2 = vec_ld(15, dst); - - d = vec_avg(a, b); - - edges = vec_perm(tmp2, tmp1, mask); - - align = vec_lvsr(0, dst); - - tmp2 = vec_perm(d, edges, align); - tmp1 = vec_perm(edges, d, align); - - vec_st(tmp2, 15, dst); - vec_st(tmp1, 0 , dst); - - dst += dst_stride; - } -} - -static inline void avg_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1, - const uint8_t * src2, int dst_stride, - int src_stride1, int h) -{ - int i; - vec_u8 a, b, d, tmp1, tmp2, mask, mask_, edges, align; - - mask_ = vec_lvsl(0, src2); - - for (i = 0; i < h; i++) { - - tmp1 = vec_ld(i * src_stride1, src1); - mask = vec_lvsl(i * src_stride1, src1); - tmp2 = vec_ld(i * src_stride1 + 15, src1); - - a = vec_perm(tmp1, tmp2, mask); - - tmp1 = vec_ld(i * 16, src2); - tmp2 = vec_ld(i * 16 + 15, src2); - - b = vec_perm(tmp1, tmp2, mask_); - - tmp1 = vec_ld(0, dst); - mask = vec_lvsl(0, dst); - tmp2 = vec_ld(15, dst); - - d = vec_avg(vec_perm(tmp1, tmp2, mask), vec_avg(a, b)); - - edges = vec_perm(tmp2, tmp1, mask); - - align = vec_lvsr(0, dst); - - tmp2 = vec_perm(d, edges, align); - tmp1 = vec_perm(edges, d, align); - - vec_st(tmp2, 15, dst); - vec_st(tmp1, 0 , dst); - - dst += dst_stride; - } -} - -/* Implemented but could be faster -#define put_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) put_pixels16_l2(d,s1,s2,ds,s1s,16,h) -#define avg_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) avg_pixels16_l2(d,s1,s2,ds,s1s,16,h) - */ - -H264_MC(put_, 16, altivec) -H264_MC(avg_, 16, altivec) - - /**************************************************************************** * IDCT transform: ****************************************************************************/ @@ -315,7 +67,7 @@ H264_MC(avg_, 16, altivec) va_u32 = vec_splat((vec_u32)va_u8, 0); \ vec_ste(va_u32, element, (uint32_t*)dst); -static void ff_h264_idct_add_altivec(uint8_t *dst, DCTELEM *block, int stride) +static void ff_h264_idct_add_altivec(uint8_t *dst, int16_t *block, int stride) { vec_s16 va0, va1, va2, va3; vec_s16 vz0, vz1, vz2, vz3; @@ -335,6 +87,7 @@ static void ff_h264_idct_add_altivec(uint8_t *dst, DCTELEM *block, int stride) vtmp1 = vec_sld(vtmp0, vtmp0, 8); vtmp2 = vec_ld(16,block); vtmp3 = vec_sld(vtmp2, vtmp2, 8); + memset(block, 0, 16 * sizeof(int16_t)); VEC_1D_DCT(vtmp0,vtmp1,vtmp2,vtmp3,va0,va1,va2,va3); VEC_TRANSPOSE_4(va0,va1,va2,va3,vtmp0,vtmp1,vtmp2,vtmp3); @@ -429,7 +182,7 @@ static void ff_h264_idct_add_altivec(uint8_t *dst, DCTELEM *block, int stride) vec_st( hv, 0, dest ); \ } -static void ff_h264_idct8_add_altivec( uint8_t *dst, DCTELEM *dct, int stride ) { +static void ff_h264_idct8_add_altivec( uint8_t *dst, int16_t *dct, int stride ) { vec_s16 s0, s1, s2, s3, s4, s5, s6, s7; vec_s16 d0, d1, d2, d3, d4, d5, d6, d7; vec_s16 idct0, idct1, idct2, idct3, idct4, idct5, idct6, idct7; @@ -454,6 +207,7 @@ static void ff_h264_idct8_add_altivec( uint8_t *dst, DCTELEM *dct, int stride ) s5 = vec_ld(0x50, (int16_t*)dct); s6 = vec_ld(0x60, (int16_t*)dct); s7 = vec_ld(0x70, (int16_t*)dct); + memset(dct, 0, 64 * sizeof(int16_t)); IDCT8_1D_ALTIVEC(s0, s1, s2, s3, s4, s5, s6, s7, d0, d1, d2, d3, d4, d5, d6, d7); @@ -473,7 +227,7 @@ static void ff_h264_idct8_add_altivec( uint8_t *dst, DCTELEM *dct, int stride ) ALTIVEC_STORE_SUM_CLIP(&dst[7*stride], idct7, perm_ldv, perm_stv, sel); } -static av_always_inline void h264_idct_dc_add_internal(uint8_t *dst, DCTELEM *block, int stride, int size) +static av_always_inline void h264_idct_dc_add_internal(uint8_t *dst, int16_t *block, int stride, int size) { vec_s16 dc16; vec_u8 dcplus, dcminus, v0, v1, v2, v3, aligner; @@ -482,6 +236,7 @@ static av_always_inline void h264_idct_dc_add_internal(uint8_t *dst, DCTELEM *bl int i; dc = (block[0] + 32) >> 6; + block[0] = 0; dc16 = vec_splat((vec_s16) vec_lde(0, &dc), 1); if (size == 4) @@ -518,17 +273,17 @@ static av_always_inline void h264_idct_dc_add_internal(uint8_t *dst, DCTELEM *bl } } -static void h264_idct_dc_add_altivec(uint8_t *dst, DCTELEM *block, int stride) +static void h264_idct_dc_add_altivec(uint8_t *dst, int16_t *block, int stride) { h264_idct_dc_add_internal(dst, block, stride, 4); } -static void ff_h264_idct8_dc_add_altivec(uint8_t *dst, DCTELEM *block, int stride) +static void ff_h264_idct8_dc_add_altivec(uint8_t *dst, int16_t *block, int stride) { h264_idct_dc_add_internal(dst, block, stride, 8); } -static void ff_h264_idct_add16_altivec(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ +static void ff_h264_idct_add16_altivec(uint8_t *dst, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){ int i; for(i=0; i<16; i++){ int nnz = nnzc[ scan8[i] ]; @@ -539,7 +294,7 @@ static void ff_h264_idct_add16_altivec(uint8_t *dst, const int *block_offset, DC } } -static void ff_h264_idct_add16intra_altivec(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ +static void ff_h264_idct_add16intra_altivec(uint8_t *dst, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){ int i; for(i=0; i<16; i++){ if(nnzc[ scan8[i] ]) ff_h264_idct_add_altivec(dst + block_offset[i], block + i*16, stride); @@ -547,7 +302,7 @@ static void ff_h264_idct_add16intra_altivec(uint8_t *dst, const int *block_offse } } -static void ff_h264_idct8_add4_altivec(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ +static void ff_h264_idct8_add4_altivec(uint8_t *dst, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){ int i; for(i=0; i<16; i+=4){ int nnz = nnzc[ scan8[i] ]; @@ -558,7 +313,7 @@ static void ff_h264_idct8_add4_altivec(uint8_t *dst, const int *block_offset, DC } } -static void ff_h264_idct_add8_altivec(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ +static void ff_h264_idct_add8_altivec(uint8_t **dest, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){ int i, j; for (j = 1; j < 3; j++) { for(i = j * 16; i < j * 16 + 4; i++){ @@ -967,40 +722,8 @@ static void ff_biweight_h264_pixels ## W ## _altivec(uint8_t *dst, uint8_t *src, H264_WEIGHT(16) H264_WEIGHT( 8) -void ff_dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx) { - const int high_bit_depth = avctx->bits_per_raw_sample > 8; - - if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) { - if (!high_bit_depth) { - c->put_h264_chroma_pixels_tab[0] = put_h264_chroma_mc8_altivec; - c->avg_h264_chroma_pixels_tab[0] = avg_h264_chroma_mc8_altivec; - -#define dspfunc(PFX, IDX, NUM) \ - c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_altivec; \ - c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_altivec; \ - c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_altivec; \ - c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_altivec; \ - c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_altivec; \ - c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_altivec; \ - c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_altivec; \ - c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_altivec; \ - c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_altivec; \ - c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_altivec; \ - c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_altivec; \ - c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_altivec; \ - c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_altivec; \ - c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_altivec; \ - c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_altivec; \ - c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_altivec - - dspfunc(put_h264_qpel, 0, 16); - dspfunc(avg_h264_qpel, 0, 16); -#undef dspfunc - } - } -} - -void ff_h264dsp_init_ppc(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) +av_cold void ff_h264dsp_init_ppc(H264DSPContext *c, const int bit_depth, + const int chroma_format_idc) { if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) { if (bit_depth == 8) { diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/h264_qpel.c b/mythtv/external/FFmpeg/libavcodec/ppc/h264_qpel.c new file mode 100644 index 00000000000..8938783a472 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/ppc/h264_qpel.c @@ -0,0 +1,301 @@ +/* + * Copyright (c) 2004 Romain Dolbeau + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "libavutil/attributes.h" +#include "libavcodec/h264qpel.h" + +#if HAVE_ALTIVEC +#include "libavutil/cpu.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/ppc/types_altivec.h" +#include "libavutil/ppc/util_altivec.h" +#include "dsputil_altivec.h" + +#define PUT_OP_U8_ALTIVEC(d, s, dst) d = s +#define AVG_OP_U8_ALTIVEC(d, s, dst) d = vec_avg(dst, s) + +#define OP_U8_ALTIVEC PUT_OP_U8_ALTIVEC +#define PREFIX_h264_qpel16_h_lowpass_altivec put_h264_qpel16_h_lowpass_altivec +#define PREFIX_h264_qpel16_h_lowpass_num altivec_put_h264_qpel16_h_lowpass_num +#define PREFIX_h264_qpel16_v_lowpass_altivec put_h264_qpel16_v_lowpass_altivec +#define PREFIX_h264_qpel16_v_lowpass_num altivec_put_h264_qpel16_v_lowpass_num +#define PREFIX_h264_qpel16_hv_lowpass_altivec put_h264_qpel16_hv_lowpass_altivec +#define PREFIX_h264_qpel16_hv_lowpass_num altivec_put_h264_qpel16_hv_lowpass_num +#include "h264_qpel_template.c" +#undef OP_U8_ALTIVEC +#undef PREFIX_h264_qpel16_h_lowpass_altivec +#undef PREFIX_h264_qpel16_h_lowpass_num +#undef PREFIX_h264_qpel16_v_lowpass_altivec +#undef PREFIX_h264_qpel16_v_lowpass_num +#undef PREFIX_h264_qpel16_hv_lowpass_altivec +#undef PREFIX_h264_qpel16_hv_lowpass_num + +#define OP_U8_ALTIVEC AVG_OP_U8_ALTIVEC +#define PREFIX_h264_qpel16_h_lowpass_altivec avg_h264_qpel16_h_lowpass_altivec +#define PREFIX_h264_qpel16_h_lowpass_num altivec_avg_h264_qpel16_h_lowpass_num +#define PREFIX_h264_qpel16_v_lowpass_altivec avg_h264_qpel16_v_lowpass_altivec +#define PREFIX_h264_qpel16_v_lowpass_num altivec_avg_h264_qpel16_v_lowpass_num +#define PREFIX_h264_qpel16_hv_lowpass_altivec avg_h264_qpel16_hv_lowpass_altivec +#define PREFIX_h264_qpel16_hv_lowpass_num altivec_avg_h264_qpel16_hv_lowpass_num +#include "h264_qpel_template.c" +#undef OP_U8_ALTIVEC +#undef PREFIX_h264_qpel16_h_lowpass_altivec +#undef PREFIX_h264_qpel16_h_lowpass_num +#undef PREFIX_h264_qpel16_v_lowpass_altivec +#undef PREFIX_h264_qpel16_v_lowpass_num +#undef PREFIX_h264_qpel16_hv_lowpass_altivec +#undef PREFIX_h264_qpel16_hv_lowpass_num + +#define H264_MC(OPNAME, SIZE, CODETYPE) \ +static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## CODETYPE (uint8_t *dst, uint8_t *src, int stride){\ + ff_ ## OPNAME ## pixels ## SIZE ## _ ## CODETYPE(dst, src, stride, SIZE);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){ \ + DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ + put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(dst, src, stride, stride);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ + put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+1, half, stride, stride, SIZE);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(dst, src, stride, stride);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+stride, half, stride, stride, SIZE);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ + put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ + put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ + put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ + put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ + OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(dst, tmp, src, stride, SIZE, stride);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ + put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\ + put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ + put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\ + put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\ + put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\ +}\ +\ +static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ + DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\ + put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\ +}\ + +static inline void put_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1, + const uint8_t * src2, int dst_stride, + int src_stride1, int h) +{ + int i; + vec_u8 a, b, d, tmp1, tmp2, mask, mask_, edges, align; + + mask_ = vec_lvsl(0, src2); + + for (i = 0; i < h; i++) { + + tmp1 = vec_ld(i * src_stride1, src1); + mask = vec_lvsl(i * src_stride1, src1); + tmp2 = vec_ld(i * src_stride1 + 15, src1); + + a = vec_perm(tmp1, tmp2, mask); + + tmp1 = vec_ld(i * 16, src2); + tmp2 = vec_ld(i * 16 + 15, src2); + + b = vec_perm(tmp1, tmp2, mask_); + + tmp1 = vec_ld(0, dst); + mask = vec_lvsl(0, dst); + tmp2 = vec_ld(15, dst); + + d = vec_avg(a, b); + + edges = vec_perm(tmp2, tmp1, mask); + + align = vec_lvsr(0, dst); + + tmp2 = vec_perm(d, edges, align); + tmp1 = vec_perm(edges, d, align); + + vec_st(tmp2, 15, dst); + vec_st(tmp1, 0 , dst); + + dst += dst_stride; + } +} + +static inline void avg_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1, + const uint8_t * src2, int dst_stride, + int src_stride1, int h) +{ + int i; + vec_u8 a, b, d, tmp1, tmp2, mask, mask_, edges, align; + + mask_ = vec_lvsl(0, src2); + + for (i = 0; i < h; i++) { + + tmp1 = vec_ld(i * src_stride1, src1); + mask = vec_lvsl(i * src_stride1, src1); + tmp2 = vec_ld(i * src_stride1 + 15, src1); + + a = vec_perm(tmp1, tmp2, mask); + + tmp1 = vec_ld(i * 16, src2); + tmp2 = vec_ld(i * 16 + 15, src2); + + b = vec_perm(tmp1, tmp2, mask_); + + tmp1 = vec_ld(0, dst); + mask = vec_lvsl(0, dst); + tmp2 = vec_ld(15, dst); + + d = vec_avg(vec_perm(tmp1, tmp2, mask), vec_avg(a, b)); + + edges = vec_perm(tmp2, tmp1, mask); + + align = vec_lvsr(0, dst); + + tmp2 = vec_perm(d, edges, align); + tmp1 = vec_perm(edges, d, align); + + vec_st(tmp2, 15, dst); + vec_st(tmp1, 0 , dst); + + dst += dst_stride; + } +} + +/* Implemented but could be faster +#define put_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) put_pixels16_l2(d,s1,s2,ds,s1s,16,h) +#define avg_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) avg_pixels16_l2(d,s1,s2,ds,s1s,16,h) + */ + +H264_MC(put_, 16, altivec) +H264_MC(avg_, 16, altivec) +#endif /* HAVE_ALTIVEC */ + +av_cold void ff_h264qpel_init_ppc(H264QpelContext *c, int bit_depth) +{ +#if HAVE_ALTIVEC + const int high_bit_depth = bit_depth > 8; + + if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) { + if (!high_bit_depth) { +#define dspfunc(PFX, IDX, NUM) \ + c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_altivec; \ + c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_altivec; \ + c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_altivec; \ + c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_altivec; \ + c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_altivec; \ + c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_altivec; \ + c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_altivec; \ + c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_altivec; \ + c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_altivec; \ + c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_altivec; \ + c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_altivec; \ + c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_altivec; \ + c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_altivec; \ + c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_altivec; \ + c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_altivec; \ + c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_altivec + + dspfunc(put_h264_qpel, 0, 16); + dspfunc(avg_h264_qpel, 0, 16); +#undef dspfunc + } + } +#endif /* HAVE_ALTIVEC */ +} diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/h264_altivec_template.c b/mythtv/external/FFmpeg/libavcodec/ppc/h264_qpel_template.c similarity index 66% rename from mythtv/external/FFmpeg/libavcodec/ppc/h264_altivec_template.c rename to mythtv/external/FFmpeg/libavcodec/ppc/h264_qpel_template.c index 5a08e0e27fe..cfc45602675 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/h264_altivec_template.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/h264_qpel_template.c @@ -26,274 +26,6 @@ #define ASSERT_ALIGNED(ptr) ; #endif -/* this code assume that stride % 16 == 0 */ - -#define CHROMA_MC8_ALTIVEC_CORE(BIAS1, BIAS2) \ - vsrc2ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc2uc);\ - vsrc3ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc3uc);\ -\ - psum = vec_mladd(vA, vsrc0ssH, BIAS1);\ - psum = vec_mladd(vB, vsrc1ssH, psum);\ - psum = vec_mladd(vC, vsrc2ssH, psum);\ - psum = vec_mladd(vD, vsrc3ssH, psum);\ - psum = BIAS2(psum);\ - psum = vec_sr(psum, v6us);\ -\ - vdst = vec_ld(0, dst);\ - ppsum = (vec_u8)vec_pack(psum, psum);\ - vfdst = vec_perm(vdst, ppsum, fperm);\ -\ - OP_U8_ALTIVEC(fsum, vfdst, vdst);\ -\ - vec_st(fsum, 0, dst);\ -\ - vsrc0ssH = vsrc2ssH;\ - vsrc1ssH = vsrc3ssH;\ -\ - dst += stride;\ - src += stride; - -#define CHROMA_MC8_ALTIVEC_CORE_SIMPLE \ -\ - vsrc0ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc0uc);\ - vsrc1ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc1uc);\ -\ - psum = vec_mladd(vA, vsrc0ssH, v32ss);\ - psum = vec_mladd(vE, vsrc1ssH, psum);\ - psum = vec_sr(psum, v6us);\ -\ - vdst = vec_ld(0, dst);\ - ppsum = (vec_u8)vec_pack(psum, psum);\ - vfdst = vec_perm(vdst, ppsum, fperm);\ -\ - OP_U8_ALTIVEC(fsum, vfdst, vdst);\ -\ - vec_st(fsum, 0, dst);\ -\ - dst += stride;\ - src += stride; - -#define noop(a) a -#define add28(a) vec_add(v28ss, a) - -#ifdef PREFIX_h264_chroma_mc8_altivec -static void PREFIX_h264_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, - int stride, int h, int x, int y) { - DECLARE_ALIGNED(16, signed int, ABCD)[4] = - {((8 - x) * (8 - y)), - (( x) * (8 - y)), - ((8 - x) * ( y)), - (( x) * ( y))}; - register int i; - vec_u8 fperm; - const vec_s32 vABCD = vec_ld(0, ABCD); - const vec_s16 vA = vec_splat((vec_s16)vABCD, 1); - const vec_s16 vB = vec_splat((vec_s16)vABCD, 3); - const vec_s16 vC = vec_splat((vec_s16)vABCD, 5); - const vec_s16 vD = vec_splat((vec_s16)vABCD, 7); - LOAD_ZERO; - const vec_s16 v32ss = vec_sl(vec_splat_s16(1),vec_splat_u16(5)); - const vec_u16 v6us = vec_splat_u16(6); - register int loadSecond = (((unsigned long)src) % 16) <= 7 ? 0 : 1; - register int reallyBadAlign = (((unsigned long)src) % 16) == 15 ? 1 : 0; - - vec_u8 vsrcAuc, av_uninit(vsrcBuc), vsrcperm0, vsrcperm1; - vec_u8 vsrc0uc, vsrc1uc; - vec_s16 vsrc0ssH, vsrc1ssH; - vec_u8 vsrcCuc, vsrc2uc, vsrc3uc; - vec_s16 vsrc2ssH, vsrc3ssH, psum; - vec_u8 vdst, ppsum, vfdst, fsum; - - if (((unsigned long)dst) % 16 == 0) { - fperm = (vec_u8){0x10, 0x11, 0x12, 0x13, - 0x14, 0x15, 0x16, 0x17, - 0x08, 0x09, 0x0A, 0x0B, - 0x0C, 0x0D, 0x0E, 0x0F}; - } else { - fperm = (vec_u8){0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, - 0x18, 0x19, 0x1A, 0x1B, - 0x1C, 0x1D, 0x1E, 0x1F}; - } - - vsrcAuc = vec_ld(0, src); - - if (loadSecond) - vsrcBuc = vec_ld(16, src); - vsrcperm0 = vec_lvsl(0, src); - vsrcperm1 = vec_lvsl(1, src); - - vsrc0uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm0); - if (reallyBadAlign) - vsrc1uc = vsrcBuc; - else - vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1); - - vsrc0ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc0uc); - vsrc1ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc1uc); - - if (ABCD[3]) { - if (!loadSecond) {// -> !reallyBadAlign - for (i = 0 ; i < h ; i++) { - vsrcCuc = vec_ld(stride + 0, src); - vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); - vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1); - - CHROMA_MC8_ALTIVEC_CORE(v32ss, noop) - } - } else { - vec_u8 vsrcDuc; - for (i = 0 ; i < h ; i++) { - vsrcCuc = vec_ld(stride + 0, src); - vsrcDuc = vec_ld(stride + 16, src); - vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); - if (reallyBadAlign) - vsrc3uc = vsrcDuc; - else - vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1); - - CHROMA_MC8_ALTIVEC_CORE(v32ss, noop) - } - } - } else { - const vec_s16 vE = vec_add(vB, vC); - if (ABCD[2]) { // x == 0 B == 0 - if (!loadSecond) {// -> !reallyBadAlign - for (i = 0 ; i < h ; i++) { - vsrcCuc = vec_ld(stride + 0, src); - vsrc1uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); - CHROMA_MC8_ALTIVEC_CORE_SIMPLE - - vsrc0uc = vsrc1uc; - } - } else { - vec_u8 vsrcDuc; - for (i = 0 ; i < h ; i++) { - vsrcCuc = vec_ld(stride + 0, src); - vsrcDuc = vec_ld(stride + 15, src); - vsrc1uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); - CHROMA_MC8_ALTIVEC_CORE_SIMPLE - - vsrc0uc = vsrc1uc; - } - } - } else { // y == 0 C == 0 - if (!loadSecond) {// -> !reallyBadAlign - for (i = 0 ; i < h ; i++) { - vsrcCuc = vec_ld(0, src); - vsrc0uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); - vsrc1uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1); - - CHROMA_MC8_ALTIVEC_CORE_SIMPLE - } - } else { - vec_u8 vsrcDuc; - for (i = 0 ; i < h ; i++) { - vsrcCuc = vec_ld(0, src); - vsrcDuc = vec_ld(15, src); - vsrc0uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); - if (reallyBadAlign) - vsrc1uc = vsrcDuc; - else - vsrc1uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1); - - CHROMA_MC8_ALTIVEC_CORE_SIMPLE - } - } - } - } -} -#endif - -/* this code assume that stride % 16 == 0 */ -#ifdef PREFIX_no_rnd_vc1_chroma_mc8_altivec -static void PREFIX_no_rnd_vc1_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, int stride, int h, int x, int y) { - DECLARE_ALIGNED(16, signed int, ABCD)[4] = - {((8 - x) * (8 - y)), - (( x) * (8 - y)), - ((8 - x) * ( y)), - (( x) * ( y))}; - register int i; - vec_u8 fperm; - const vec_s32 vABCD = vec_ld(0, ABCD); - const vec_s16 vA = vec_splat((vec_s16)vABCD, 1); - const vec_s16 vB = vec_splat((vec_s16)vABCD, 3); - const vec_s16 vC = vec_splat((vec_s16)vABCD, 5); - const vec_s16 vD = vec_splat((vec_s16)vABCD, 7); - LOAD_ZERO; - const vec_s16 v28ss = vec_sub(vec_sl(vec_splat_s16(1),vec_splat_u16(5)),vec_splat_s16(4)); - const vec_u16 v6us = vec_splat_u16(6); - register int loadSecond = (((unsigned long)src) % 16) <= 7 ? 0 : 1; - register int reallyBadAlign = (((unsigned long)src) % 16) == 15 ? 1 : 0; - - vec_u8 vsrcAuc, av_uninit(vsrcBuc), vsrcperm0, vsrcperm1; - vec_u8 vsrc0uc, vsrc1uc; - vec_s16 vsrc0ssH, vsrc1ssH; - vec_u8 vsrcCuc, vsrc2uc, vsrc3uc; - vec_s16 vsrc2ssH, vsrc3ssH, psum; - vec_u8 vdst, ppsum, vfdst, fsum; - - if (((unsigned long)dst) % 16 == 0) { - fperm = (vec_u8){0x10, 0x11, 0x12, 0x13, - 0x14, 0x15, 0x16, 0x17, - 0x08, 0x09, 0x0A, 0x0B, - 0x0C, 0x0D, 0x0E, 0x0F}; - } else { - fperm = (vec_u8){0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, - 0x18, 0x19, 0x1A, 0x1B, - 0x1C, 0x1D, 0x1E, 0x1F}; - } - - vsrcAuc = vec_ld(0, src); - - if (loadSecond) - vsrcBuc = vec_ld(16, src); - vsrcperm0 = vec_lvsl(0, src); - vsrcperm1 = vec_lvsl(1, src); - - vsrc0uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm0); - if (reallyBadAlign) - vsrc1uc = vsrcBuc; - else - vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1); - - vsrc0ssH = (vec_s16)vec_mergeh(zero_u8v, (vec_u8)vsrc0uc); - vsrc1ssH = (vec_s16)vec_mergeh(zero_u8v, (vec_u8)vsrc1uc); - - if (!loadSecond) {// -> !reallyBadAlign - for (i = 0 ; i < h ; i++) { - - - vsrcCuc = vec_ld(stride + 0, src); - - vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); - vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1); - - CHROMA_MC8_ALTIVEC_CORE(vec_splat_s16(0), add28) - } - } else { - vec_u8 vsrcDuc; - for (i = 0 ; i < h ; i++) { - vsrcCuc = vec_ld(stride + 0, src); - vsrcDuc = vec_ld(stride + 16, src); - - vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); - if (reallyBadAlign) - vsrc3uc = vsrcDuc; - else - vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1); - - CHROMA_MC8_ALTIVEC_CORE(vec_splat_s16(0), add28) - } - } -} -#endif - -#undef noop -#undef add28 -#undef CHROMA_MC8_ALTIVEC_CORE - /* this code assume stride % 16 == 0 */ #ifdef PREFIX_h264_qpel16_h_lowpass_altivec static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, int dstStride, int srcStride) { diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/h264chroma_init.c b/mythtv/external/FFmpeg/libavcodec/ppc/h264chroma_init.c new file mode 100644 index 00000000000..f9e2a76ccad --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/ppc/h264chroma_init.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2004 Romain Dolbeau + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "libavutil/attributes.h" +#include "libavcodec/h264chroma.h" + +#if HAVE_ALTIVEC +#include "libavutil/cpu.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/ppc/types_altivec.h" +#include "libavutil/ppc/util_altivec.h" +#include "dsputil_altivec.h" + +#define PUT_OP_U8_ALTIVEC(d, s, dst) d = s +#define AVG_OP_U8_ALTIVEC(d, s, dst) d = vec_avg(dst, s) + +#define OP_U8_ALTIVEC PUT_OP_U8_ALTIVEC +#define PREFIX_h264_chroma_mc8_altivec put_h264_chroma_mc8_altivec +#define PREFIX_h264_chroma_mc8_num altivec_put_h264_chroma_mc8_num +#include "h264chroma_template.c" +#undef OP_U8_ALTIVEC +#undef PREFIX_h264_chroma_mc8_altivec +#undef PREFIX_h264_chroma_mc8_num + +#define OP_U8_ALTIVEC AVG_OP_U8_ALTIVEC +#define PREFIX_h264_chroma_mc8_altivec avg_h264_chroma_mc8_altivec +#define PREFIX_h264_chroma_mc8_num altivec_avg_h264_chroma_mc8_num +#include "h264chroma_template.c" +#undef OP_U8_ALTIVEC +#undef PREFIX_h264_chroma_mc8_altivec +#undef PREFIX_h264_chroma_mc8_num +#endif /* HAVE_ALTIVEC */ + +av_cold void ff_h264chroma_init_ppc(H264ChromaContext *c, int bit_depth) +{ +#if HAVE_ALTIVEC + const int high_bit_depth = bit_depth > 8; + + if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) { + if (!high_bit_depth) { + c->put_h264_chroma_pixels_tab[0] = put_h264_chroma_mc8_altivec; + c->avg_h264_chroma_pixels_tab[0] = avg_h264_chroma_mc8_altivec; + } + } +#endif /* HAVE_ALTIVEC */ +} diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/h264chroma_template.c b/mythtv/external/FFmpeg/libavcodec/ppc/h264chroma_template.c new file mode 100644 index 00000000000..7436e118c54 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/ppc/h264chroma_template.c @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2004 Romain Dolbeau + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/mem.h" + +/* this code assume that stride % 16 == 0 */ + +#define CHROMA_MC8_ALTIVEC_CORE(BIAS1, BIAS2) \ + vsrc2ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc2uc);\ + vsrc3ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc3uc);\ +\ + psum = vec_mladd(vA, vsrc0ssH, BIAS1);\ + psum = vec_mladd(vB, vsrc1ssH, psum);\ + psum = vec_mladd(vC, vsrc2ssH, psum);\ + psum = vec_mladd(vD, vsrc3ssH, psum);\ + psum = BIAS2(psum);\ + psum = vec_sr(psum, v6us);\ +\ + vdst = vec_ld(0, dst);\ + ppsum = (vec_u8)vec_pack(psum, psum);\ + vfdst = vec_perm(vdst, ppsum, fperm);\ +\ + OP_U8_ALTIVEC(fsum, vfdst, vdst);\ +\ + vec_st(fsum, 0, dst);\ +\ + vsrc0ssH = vsrc2ssH;\ + vsrc1ssH = vsrc3ssH;\ +\ + dst += stride;\ + src += stride; + +#define CHROMA_MC8_ALTIVEC_CORE_SIMPLE \ +\ + vsrc0ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc0uc);\ + vsrc1ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc1uc);\ +\ + psum = vec_mladd(vA, vsrc0ssH, v32ss);\ + psum = vec_mladd(vE, vsrc1ssH, psum);\ + psum = vec_sr(psum, v6us);\ +\ + vdst = vec_ld(0, dst);\ + ppsum = (vec_u8)vec_pack(psum, psum);\ + vfdst = vec_perm(vdst, ppsum, fperm);\ +\ + OP_U8_ALTIVEC(fsum, vfdst, vdst);\ +\ + vec_st(fsum, 0, dst);\ +\ + dst += stride;\ + src += stride; + +#define noop(a) a +#define add28(a) vec_add(v28ss, a) + +#ifdef PREFIX_h264_chroma_mc8_altivec +static void PREFIX_h264_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, + int stride, int h, int x, int y) { + DECLARE_ALIGNED(16, signed int, ABCD)[4] = + {((8 - x) * (8 - y)), + (( x) * (8 - y)), + ((8 - x) * ( y)), + (( x) * ( y))}; + register int i; + vec_u8 fperm; + const vec_s32 vABCD = vec_ld(0, ABCD); + const vec_s16 vA = vec_splat((vec_s16)vABCD, 1); + const vec_s16 vB = vec_splat((vec_s16)vABCD, 3); + const vec_s16 vC = vec_splat((vec_s16)vABCD, 5); + const vec_s16 vD = vec_splat((vec_s16)vABCD, 7); + LOAD_ZERO; + const vec_s16 v32ss = vec_sl(vec_splat_s16(1),vec_splat_u16(5)); + const vec_u16 v6us = vec_splat_u16(6); + register int loadSecond = (((unsigned long)src) % 16) <= 7 ? 0 : 1; + register int reallyBadAlign = (((unsigned long)src) % 16) == 15 ? 1 : 0; + + vec_u8 vsrcAuc, av_uninit(vsrcBuc), vsrcperm0, vsrcperm1; + vec_u8 vsrc0uc, vsrc1uc; + vec_s16 vsrc0ssH, vsrc1ssH; + vec_u8 vsrcCuc, vsrc2uc, vsrc3uc; + vec_s16 vsrc2ssH, vsrc3ssH, psum; + vec_u8 vdst, ppsum, vfdst, fsum; + + if (((unsigned long)dst) % 16 == 0) { + fperm = (vec_u8){0x10, 0x11, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, + 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F}; + } else { + fperm = (vec_u8){0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, + 0x18, 0x19, 0x1A, 0x1B, + 0x1C, 0x1D, 0x1E, 0x1F}; + } + + vsrcAuc = vec_ld(0, src); + + if (loadSecond) + vsrcBuc = vec_ld(16, src); + vsrcperm0 = vec_lvsl(0, src); + vsrcperm1 = vec_lvsl(1, src); + + vsrc0uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm0); + if (reallyBadAlign) + vsrc1uc = vsrcBuc; + else + vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1); + + vsrc0ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc0uc); + vsrc1ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc1uc); + + if (ABCD[3]) { + if (!loadSecond) {// -> !reallyBadAlign + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(stride + 0, src); + vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); + vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1); + + CHROMA_MC8_ALTIVEC_CORE(v32ss, noop) + } + } else { + vec_u8 vsrcDuc; + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(stride + 0, src); + vsrcDuc = vec_ld(stride + 16, src); + vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); + if (reallyBadAlign) + vsrc3uc = vsrcDuc; + else + vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1); + + CHROMA_MC8_ALTIVEC_CORE(v32ss, noop) + } + } + } else { + const vec_s16 vE = vec_add(vB, vC); + if (ABCD[2]) { // x == 0 B == 0 + if (!loadSecond) {// -> !reallyBadAlign + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(stride + 0, src); + vsrc1uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); + CHROMA_MC8_ALTIVEC_CORE_SIMPLE + + vsrc0uc = vsrc1uc; + } + } else { + vec_u8 vsrcDuc; + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(stride + 0, src); + vsrcDuc = vec_ld(stride + 15, src); + vsrc1uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); + CHROMA_MC8_ALTIVEC_CORE_SIMPLE + + vsrc0uc = vsrc1uc; + } + } + } else { // y == 0 C == 0 + if (!loadSecond) {// -> !reallyBadAlign + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(0, src); + vsrc0uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); + vsrc1uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1); + + CHROMA_MC8_ALTIVEC_CORE_SIMPLE + } + } else { + vec_u8 vsrcDuc; + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(0, src); + vsrcDuc = vec_ld(15, src); + vsrc0uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); + if (reallyBadAlign) + vsrc1uc = vsrcDuc; + else + vsrc1uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1); + + CHROMA_MC8_ALTIVEC_CORE_SIMPLE + } + } + } + } +} +#endif + +/* this code assume that stride % 16 == 0 */ +#ifdef PREFIX_no_rnd_vc1_chroma_mc8_altivec +static void PREFIX_no_rnd_vc1_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, int stride, int h, int x, int y) { + DECLARE_ALIGNED(16, signed int, ABCD)[4] = + {((8 - x) * (8 - y)), + (( x) * (8 - y)), + ((8 - x) * ( y)), + (( x) * ( y))}; + register int i; + vec_u8 fperm; + const vec_s32 vABCD = vec_ld(0, ABCD); + const vec_s16 vA = vec_splat((vec_s16)vABCD, 1); + const vec_s16 vB = vec_splat((vec_s16)vABCD, 3); + const vec_s16 vC = vec_splat((vec_s16)vABCD, 5); + const vec_s16 vD = vec_splat((vec_s16)vABCD, 7); + LOAD_ZERO; + const vec_s16 v28ss = vec_sub(vec_sl(vec_splat_s16(1),vec_splat_u16(5)),vec_splat_s16(4)); + const vec_u16 v6us = vec_splat_u16(6); + register int loadSecond = (((unsigned long)src) % 16) <= 7 ? 0 : 1; + register int reallyBadAlign = (((unsigned long)src) % 16) == 15 ? 1 : 0; + + vec_u8 vsrcAuc, av_uninit(vsrcBuc), vsrcperm0, vsrcperm1; + vec_u8 vsrc0uc, vsrc1uc; + vec_s16 vsrc0ssH, vsrc1ssH; + vec_u8 vsrcCuc, vsrc2uc, vsrc3uc; + vec_s16 vsrc2ssH, vsrc3ssH, psum; + vec_u8 vdst, ppsum, vfdst, fsum; + + if (((unsigned long)dst) % 16 == 0) { + fperm = (vec_u8){0x10, 0x11, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, + 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F}; + } else { + fperm = (vec_u8){0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, + 0x18, 0x19, 0x1A, 0x1B, + 0x1C, 0x1D, 0x1E, 0x1F}; + } + + vsrcAuc = vec_ld(0, src); + + if (loadSecond) + vsrcBuc = vec_ld(16, src); + vsrcperm0 = vec_lvsl(0, src); + vsrcperm1 = vec_lvsl(1, src); + + vsrc0uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm0); + if (reallyBadAlign) + vsrc1uc = vsrcBuc; + else + vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1); + + vsrc0ssH = (vec_s16)vec_mergeh(zero_u8v, (vec_u8)vsrc0uc); + vsrc1ssH = (vec_s16)vec_mergeh(zero_u8v, (vec_u8)vsrc1uc); + + if (!loadSecond) {// -> !reallyBadAlign + for (i = 0 ; i < h ; i++) { + + + vsrcCuc = vec_ld(stride + 0, src); + + vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); + vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1); + + CHROMA_MC8_ALTIVEC_CORE(vec_splat_s16(0), add28) + } + } else { + vec_u8 vsrcDuc; + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(stride + 0, src); + vsrcDuc = vec_ld(stride + 16, src); + + vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); + if (reallyBadAlign) + vsrc3uc = vsrcDuc; + else + vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1); + + CHROMA_MC8_ALTIVEC_CORE(vec_splat_s16(0), add28) + } + } +} +#endif + +#undef noop +#undef add28 +#undef CHROMA_MC8_ALTIVEC_CORE diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/idct_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/idct_altivec.c index 9a8b91740e4..c6f2cd8b8aa 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/idct_altivec.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/idct_altivec.c @@ -42,7 +42,6 @@ #include #endif #include "libavutil/ppc/types_altivec.h" -#include "libavcodec/dsputil.h" #include "dsputil_altivec.h" #define IDCT_HALF \ diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/int_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/int_altivec.c index 5a73876ad31..4386b13b237 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/int_altivec.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/int_altivec.c @@ -28,6 +28,7 @@ #include #endif +#include "libavutil/attributes.h" #include "libavutil/ppc/types_altivec.h" #include "libavcodec/dsputil.h" @@ -136,7 +137,7 @@ static int32_t scalarproduct_and_madd_int16_altivec(int16_t *v1, const int16_t * return ires; } -void ff_int_init_altivec(DSPContext* c, AVCodecContext *avctx) +av_cold void ff_int_init_altivec(DSPContext *c, AVCodecContext *avctx) { c->ssd_int8_vs_int16 = ssd_int8_vs_int16_altivec; c->scalarproduct_int16 = scalarproduct_int16_altivec; diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/mpegaudiodec_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/mpegaudiodec_altivec.c index 7d829b86f4e..1152fd77aca 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/mpegaudiodec_altivec.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/mpegaudiodec_altivec.c @@ -20,8 +20,9 @@ */ #include "dsputil_altivec.h" +#include "libavutil/attributes.h" +#include "libavutil/internal.h" #include "libavutil/ppc/util_altivec.h" -#include "libavcodec/dsputil.h" #include "libavcodec/mpegaudiodsp.h" #define MACS(rt, ra, rb) rt+=(ra)*(rb) @@ -123,7 +124,7 @@ static void apply_window_mp3(float *in, float *win, int *unused, float *out, *out = sum; } -void ff_mpadsp_init_altivec(MPADSPContext *s) +av_cold void ff_mpadsp_init_altivec(MPADSPContext *s) { s->apply_window_float = apply_window_mp3; } diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/mpegvideo_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/mpegvideo_altivec.c index bbc102bc21f..bf490b04ea7 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/mpegvideo_altivec.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/mpegvideo_altivec.c @@ -24,10 +24,10 @@ #include #include +#include "libavutil/attributes.h" #include "libavutil/cpu.h" #include "libavutil/ppc/types_altivec.h" #include "libavutil/ppc/util_altivec.h" -#include "libavcodec/dsputil.h" #include "libavcodec/mpegvideo.h" #include "dsputil_altivec.h" @@ -35,7 +35,7 @@ /* AltiVec version of dct_unquantize_h263 this code assumes `block' is 16 bytes-aligned */ static void dct_unquantize_h263_altivec(MpegEncContext *s, - DCTELEM *block, int n, int qscale) + int16_t *block, int n, int qscale) { int i, level, qmul, qadd; int nCoeffs; @@ -112,7 +112,7 @@ static void dct_unquantize_h263_altivec(MpegEncContext *s, } -void ff_MPV_common_init_altivec(MpegEncContext *s) +av_cold void ff_MPV_common_init_altivec(MpegEncContext *s) { if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return; diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/vc1dsp_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/vc1dsp_altivec.c index 33e87afc3a8..9c2ad70b62a 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/vc1dsp_altivec.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/vc1dsp_altivec.c @@ -19,9 +19,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/attributes.h" #include "libavutil/ppc/types_altivec.h" #include "libavutil/ppc/util_altivec.h" -#include "libavcodec/dsputil.h" #include "libavcodec/vc1dsp.h" // main steps of 8x8 transform @@ -129,7 +129,7 @@ do { \ /** Do inverse transform on 8x8 block */ -static void vc1_inv_trans_8x8_altivec(DCTELEM block[64]) +static void vc1_inv_trans_8x8_altivec(int16_t block[64]) { vector signed short src0, src1, src2, src3, src4, src5, src6, src7; vector signed int s0, s1, s2, s3, s4, s5, s6, s7; @@ -224,7 +224,7 @@ static void vc1_inv_trans_8x8_altivec(DCTELEM block[64]) /** Do inverse transform on 8x4 part of block */ -static void vc1_inv_trans_8x4_altivec(uint8_t *dest, int stride, DCTELEM *block) +static void vc1_inv_trans_8x4_altivec(uint8_t *dest, int stride, int16_t *block) { vector signed short src0, src1, src2, src3, src4, src5, src6, src7; vector signed int s0, s1, s2, s3, s4, s5, s6, s7; @@ -325,17 +325,17 @@ static void vc1_inv_trans_8x4_altivec(uint8_t *dest, int stride, DCTELEM *block) #define OP_U8_ALTIVEC PUT_OP_U8_ALTIVEC #define PREFIX_no_rnd_vc1_chroma_mc8_altivec put_no_rnd_vc1_chroma_mc8_altivec -#include "h264_altivec_template.c" +#include "h264chroma_template.c" #undef OP_U8_ALTIVEC #undef PREFIX_no_rnd_vc1_chroma_mc8_altivec #define OP_U8_ALTIVEC AVG_OP_U8_ALTIVEC #define PREFIX_no_rnd_vc1_chroma_mc8_altivec avg_no_rnd_vc1_chroma_mc8_altivec -#include "h264_altivec_template.c" +#include "h264chroma_template.c" #undef OP_U8_ALTIVEC #undef PREFIX_no_rnd_vc1_chroma_mc8_altivec -void ff_vc1dsp_init_altivec(VC1DSPContext* dsp) +av_cold void ff_vc1dsp_init_altivec(VC1DSPContext *dsp) { if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return; diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/videodsp_ppc.c b/mythtv/external/FFmpeg/libavcodec/ppc/videodsp_ppc.c index 0fe515fbb8d..915702252e6 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/videodsp_ppc.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/videodsp_ppc.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/attributes.h" #include "libavcodec/videodsp.h" static void prefetch_ppc(uint8_t *mem, ptrdiff_t stride, int h) @@ -29,7 +30,7 @@ static void prefetch_ppc(uint8_t *mem, ptrdiff_t stride, int h) } while(--h); } -void ff_videodsp_init_ppc(VideoDSPContext *ctx, int bpc) +av_cold void ff_videodsp_init_ppc(VideoDSPContext *ctx, int bpc) { ctx->prefetch = prefetch_ppc; } diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/vorbisdsp_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/vorbisdsp_altivec.c new file mode 100644 index 00000000000..08a2b26f8ae --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/ppc/vorbisdsp_altivec.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2006 Luca Barbato + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#if HAVE_ALTIVEC_H +#include +#endif +#include "libavutil/attributes.h" +#include "libavutil/cpu.h" +#include "libavcodec/vorbisdsp.h" + +#if HAVE_ALTIVEC +static void vorbis_inverse_coupling_altivec(float *mag, float *ang, + intptr_t blocksize) +{ + int i; + vector float m, a; + vector bool int t0, t1; + const vector unsigned int v_31 = //XXX + vec_add(vec_add(vec_splat_u32(15),vec_splat_u32(15)),vec_splat_u32(1)); + for (i = 0; i < blocksize; i += 4) { + m = vec_ld(0, mag+i); + a = vec_ld(0, ang+i); + t0 = vec_cmple(m, (vector float)vec_splat_u32(0)); + t1 = vec_cmple(a, (vector float)vec_splat_u32(0)); + a = vec_xor(a, (vector float) vec_sl((vector unsigned int)t0, v_31)); + t0 = (vector bool int)vec_and(a, t1); + t1 = (vector bool int)vec_andc(a, t1); + a = vec_sub(m, (vector float)t1); + m = vec_add(m, (vector float)t0); + vec_stl(a, 0, ang+i); + vec_stl(m, 0, mag+i); + } +} +#endif /* HAVE_ALTIVEC */ + +av_cold void ff_vorbisdsp_init_ppc(VorbisDSPContext *c) +{ +#if HAVE_ALTIVEC + if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) { + c->vorbis_inverse_coupling = vorbis_inverse_coupling_altivec; + } +#endif /* HAVE_ALTIVEC */ +} diff --git a/mythtv/external/FFmpeg/libavcodec/ppc/vp3dsp_altivec.c b/mythtv/external/FFmpeg/libavcodec/ppc/vp3dsp_altivec.c index ac00c933bb0..42ae00b8bad 100644 --- a/mythtv/external/FFmpeg/libavcodec/ppc/vp3dsp_altivec.c +++ b/mythtv/external/FFmpeg/libavcodec/ppc/vp3dsp_altivec.c @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "config.h" #include "libavutil/attributes.h" #include "libavutil/cpu.h" @@ -27,7 +29,6 @@ #include "libavutil/ppc/types_altivec.h" #include "libavutil/ppc/util_altivec.h" -#include "libavcodec/dsputil.h" #include "dsputil_altivec.h" static const vec_s16 constants = @@ -114,7 +115,7 @@ static inline vec_s16 M16(vec_s16 a, vec_s16 C) #define ADD8(a) vec_add(a, eight) #define SHIFT4(a) vec_sra(a, four) -static void vp3_idct_put_altivec(uint8_t *dst, int stride, DCTELEM block[64]) +static void vp3_idct_put_altivec(uint8_t *dst, int stride, int16_t block[64]) { vec_u8 t; IDCT_START @@ -140,9 +141,10 @@ static void vp3_idct_put_altivec(uint8_t *dst, int stride, DCTELEM block[64]) PUT(b5) dst += stride; PUT(b6) dst += stride; PUT(b7) + memset(block, 0, sizeof(*block) * 64); } -static void vp3_idct_add_altivec(uint8_t *dst, int stride, DCTELEM block[64]) +static void vp3_idct_add_altivec(uint8_t *dst, int stride, int16_t block[64]) { LOAD_ZERO; vec_u8 t, vdst; @@ -171,6 +173,7 @@ static void vp3_idct_add_altivec(uint8_t *dst, int stride, DCTELEM block[64]) ADD(b5) dst += stride; ADD(b6) dst += stride; ADD(b7) + memset(block, 0, sizeof(*block) * 64); } #endif /* HAVE_ALTIVEC */ diff --git a/mythtv/external/FFmpeg/libavcodec/proresdec2.c b/mythtv/external/FFmpeg/libavcodec/proresdec2.c index 3b3175a41a5..4634e704e2d 100644 --- a/mythtv/external/FFmpeg/libavcodec/proresdec2.c +++ b/mythtv/external/FFmpeg/libavcodec/proresdec2.c @@ -294,10 +294,10 @@ static int decode_picture_header(AVCodecContext *avctx, const uint8_t *buf, cons static const uint8_t dc_codebook[7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70}; -static av_always_inline void decode_dc_coeffs(GetBitContext *gb, DCTELEM *out, +static av_always_inline void decode_dc_coeffs(GetBitContext *gb, int16_t *out, int blocks_per_slice) { - DCTELEM prev_dc; + int16_t prev_dc; int code, i, sign; OPEN_READER(re, gb); @@ -325,7 +325,7 @@ static const uint8_t run_to_cb[16] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, static const uint8_t lev_to_cb[10] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C }; static av_always_inline void decode_ac_coeffs(AVCodecContext *avctx, GetBitContext *gb, - DCTELEM *out, int blocks_per_slice) + int16_t *out, int blocks_per_slice) { ProresContext *ctx = avctx->priv_data; int block_mask, sign; @@ -372,8 +372,8 @@ static void decode_slice_luma(AVCodecContext *avctx, SliceContext *slice, const int16_t *qmat) { ProresContext *ctx = avctx->priv_data; - LOCAL_ALIGNED_16(DCTELEM, blocks, [8*4*64]); - DCTELEM *block; + LOCAL_ALIGNED_16(int16_t, blocks, [8*4*64]); + int16_t *block; GetBitContext gb; int i, blocks_per_slice = slice->mb_count<<2; @@ -402,8 +402,8 @@ static void decode_slice_chroma(AVCodecContext *avctx, SliceContext *slice, const int16_t *qmat, int log2_blocks_per_mb) { ProresContext *ctx = avctx->priv_data; - LOCAL_ALIGNED_16(DCTELEM, blocks, [8*4*64]); - DCTELEM *block; + LOCAL_ALIGNED_16(int16_t, blocks, [8*4*64]); + int16_t *block; GetBitContext gb; int i, j, blocks_per_slice = slice->mb_count << log2_blocks_per_mb; diff --git a/mythtv/external/FFmpeg/libavcodec/proresdec_lgpl.c b/mythtv/external/FFmpeg/libavcodec/proresdec_lgpl.c index 4fa2817e863..5c53882ce39 100644 --- a/mythtv/external/FFmpeg/libavcodec/proresdec_lgpl.c +++ b/mythtv/external/FFmpeg/libavcodec/proresdec_lgpl.c @@ -34,6 +34,7 @@ #include "libavutil/intmath.h" #include "avcodec.h" +#include "dsputil.h" #include "internal.h" #include "proresdata.h" #include "proresdsp.h" @@ -45,7 +46,7 @@ typedef struct { int x_pos, y_pos; int slice_width; int prev_slice_sf; ///< scalefactor of the previous decoded slice - DECLARE_ALIGNED(16, DCTELEM, blocks)[8 * 4 * 64]; + DECLARE_ALIGNED(16, int16_t, blocks)[8 * 4 * 64]; DECLARE_ALIGNED(16, int16_t, qmat_luma_scaled)[64]; DECLARE_ALIGNED(16, int16_t, qmat_chroma_scaled)[64]; } ProresThreadData; @@ -164,6 +165,8 @@ static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, if (ctx->frame_type) { /* if interlaced */ ctx->picture.interlaced_frame = 1; ctx->picture.top_field_first = ctx->frame_type & 1; + } else { + ctx->picture.interlaced_frame = 0; } avctx->color_primaries = buf[14]; @@ -338,10 +341,10 @@ static inline int decode_vlc_codeword(GetBitContext *gb, unsigned codebook) /** * Decode DC coefficients for all blocks in a slice. */ -static inline void decode_dc_coeffs(GetBitContext *gb, DCTELEM *out, +static inline void decode_dc_coeffs(GetBitContext *gb, int16_t *out, int nblocks) { - DCTELEM prev_dc; + int16_t prev_dc; int i, sign; int16_t delta; unsigned int code; @@ -366,7 +369,7 @@ static inline void decode_dc_coeffs(GetBitContext *gb, DCTELEM *out, /** * Decode AC coefficients for all blocks in a slice. */ -static inline void decode_ac_coeffs(GetBitContext *gb, DCTELEM *out, +static inline void decode_ac_coeffs(GetBitContext *gb, int16_t *out, int blocks_per_slice, int plane_size_factor, const uint8_t *scan) @@ -419,7 +422,7 @@ static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td, const int16_t *qmat, int is_chroma) { GetBitContext gb; - DCTELEM *block_ptr; + int16_t *block_ptr; int mb_num, blocks_per_slice; blocks_per_slice = mbs_per_slice * blocks_per_mb; diff --git a/mythtv/external/FFmpeg/libavcodec/proresdsp.c b/mythtv/external/FFmpeg/libavcodec/proresdsp.c index 9e063b09744..d73de465197 100644 --- a/mythtv/external/FFmpeg/libavcodec/proresdsp.c +++ b/mythtv/external/FFmpeg/libavcodec/proresdsp.c @@ -20,6 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "dct.h" +#include "dsputil.h" #include "proresdsp.h" #include "simple_idct.h" #include "libavutil/common.h" @@ -34,7 +36,7 @@ /** * Add bias value, clamp and output pixels of a slice */ -static void put_pixels(uint16_t *dst, int stride, const DCTELEM *in) +static void put_pixels(uint16_t *dst, int stride, const int16_t *in) { int x, y, src_offset, dst_offset; @@ -47,7 +49,7 @@ static void put_pixels(uint16_t *dst, int stride, const DCTELEM *in) } } -static void prores_idct_put_c(uint16_t *out, int linesize, DCTELEM *block, const int16_t *qmat) +static void prores_idct_put_c(uint16_t *out, int linesize, int16_t *block, const int16_t *qmat) { ff_prores_idct(block, qmat); put_pixels(out, linesize >> 1, block); @@ -55,7 +57,7 @@ static void prores_idct_put_c(uint16_t *out, int linesize, DCTELEM *block, const #endif #if CONFIG_PRORES_KOSTYA_ENCODER -static void prores_fdct_c(const uint16_t *src, int linesize, DCTELEM *block) +static void prores_fdct_c(const uint16_t *src, int linesize, int16_t *block) { int x, y; const uint16_t *tsrc = src; diff --git a/mythtv/external/FFmpeg/libavcodec/proresdsp.h b/mythtv/external/FFmpeg/libavcodec/proresdsp.h index 09541d96420..706162af529 100644 --- a/mythtv/external/FFmpeg/libavcodec/proresdsp.h +++ b/mythtv/external/FFmpeg/libavcodec/proresdsp.h @@ -23,6 +23,7 @@ #ifndef AVCODEC_PRORESDSP_H #define AVCODEC_PRORESDSP_H +#include #include "dsputil.h" #define PRORES_BITS_PER_SAMPLE 10 ///< output precision of prores decoder @@ -32,8 +33,8 @@ typedef struct ProresDSPContext { uint8_t idct_permutation[64]; int dct_permutation_type; uint8_t dct_permutation[64]; - void (* idct_put) (uint16_t *out, int linesize, DCTELEM *block, const int16_t *qmat); - void (* fdct) (const uint16_t *src, int linesize, DCTELEM *block); + void (* idct_put) (uint16_t *out, int linesize, int16_t *block, const int16_t *qmat); + void (* fdct) (const uint16_t *src, int linesize, int16_t *block); } ProresDSPContext; void ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx); diff --git a/mythtv/external/FFmpeg/libavcodec/proresenc_anatoliy.c b/mythtv/external/FFmpeg/libavcodec/proresenc_anatoliy.c index 8c71ca5aea4..7bf71a3e896 100644 --- a/mythtv/external/FFmpeg/libavcodec/proresenc_anatoliy.c +++ b/mythtv/external/FFmpeg/libavcodec/proresenc_anatoliy.c @@ -27,6 +27,7 @@ */ #include "avcodec.h" +#include "dct.h" #include "internal.h" #include "put_bits.h" #include "bytestream.h" @@ -198,7 +199,7 @@ static av_always_inline int get_level(int val) static const uint8_t dc_codebook[7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70}; -static void encode_dc_coeffs(PutBitContext *pb, DCTELEM *in, +static void encode_dc_coeffs(PutBitContext *pb, int16_t *in, int blocks_per_slice, int *qmat) { int prev_dc, code; @@ -230,7 +231,7 @@ static const uint8_t lev_to_cb[10] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C }; static void encode_ac_coeffs(AVCodecContext *avctx, PutBitContext *pb, - DCTELEM *in, int blocks_per_slice, int *qmat) + int16_t *in, int blocks_per_slice, int *qmat) { int prev_run = 4; int prev_level = 2; @@ -260,7 +261,7 @@ static void encode_ac_coeffs(AVCodecContext *avctx, PutBitContext *pb, } } -static void get(uint8_t *pixels, int stride, DCTELEM* block) +static void get(uint8_t *pixels, int stride, int16_t* block) { int16_t *p = (int16_t*)pixels; int i, j; @@ -275,7 +276,7 @@ static void get(uint8_t *pixels, int stride, DCTELEM* block) } } -static void fdct_get(uint8_t *pixels, int stride, DCTELEM* block) +static void fdct_get(uint8_t *pixels, int stride, int16_t* block) { get(pixels, stride, block); ff_jpeg_fdct_islow_10(block); @@ -285,7 +286,7 @@ static int encode_slice_plane(AVCodecContext *avctx, int mb_count, uint8_t *src, int src_stride, uint8_t *buf, unsigned buf_size, int *qmat, int chroma) { - DECLARE_ALIGNED(16, DCTELEM, blocks)[DEFAULT_SLICE_MB_WIDTH << 8], *block; + DECLARE_ALIGNED(16, int16_t, blocks)[DEFAULT_SLICE_MB_WIDTH << 8], *block; int i, blocks_per_slice; PutBitContext pb; diff --git a/mythtv/external/FFmpeg/libavcodec/proresenc_kostya.c b/mythtv/external/FFmpeg/libavcodec/proresenc_kostya.c index 0462c74b13c..8da13ac8224 100644 --- a/mythtv/external/FFmpeg/libavcodec/proresenc_kostya.c +++ b/mythtv/external/FFmpeg/libavcodec/proresenc_kostya.c @@ -25,6 +25,7 @@ #include "libavutil/opt.h" #include "avcodec.h" +#include "dsputil.h" #include "put_bits.h" #include "bytestream.h" #include "internal.h" @@ -170,7 +171,7 @@ struct TrellisNode { #define MAX_STORED_Q 16 typedef struct ProresThreadData { - DECLARE_ALIGNED(16, DCTELEM, blocks)[MAX_PLANES][64 * 4 * MAX_MBS_PER_SLICE]; + DECLARE_ALIGNED(16, int16_t, blocks)[MAX_PLANES][64 * 4 * MAX_MBS_PER_SLICE]; DECLARE_ALIGNED(16, uint16_t, emu_buf)[16 * 16]; int16_t custom_q[64]; struct TrellisNode *nodes; @@ -178,7 +179,7 @@ typedef struct ProresThreadData { typedef struct ProresContext { AVClass *class; - DECLARE_ALIGNED(16, DCTELEM, blocks)[MAX_PLANES][64 * 4 * MAX_MBS_PER_SLICE]; + DECLARE_ALIGNED(16, int16_t, blocks)[MAX_PLANES][64 * 4 * MAX_MBS_PER_SLICE]; DECLARE_ALIGNED(16, uint16_t, emu_buf)[16*16]; int16_t quants[MAX_STORED_Q][64]; int16_t custom_q[64]; @@ -213,7 +214,7 @@ typedef struct ProresContext { static void get_slice_data(ProresContext *ctx, const uint16_t *src, int linesize, int x, int y, int w, int h, - DCTELEM *blocks, uint16_t *emu_buf, + int16_t *blocks, uint16_t *emu_buf, int mbs_per_slice, int blocks_per_mb, int is_chroma) { const uint16_t *esrc; @@ -317,7 +318,7 @@ static inline void encode_vlc_codeword(PutBitContext *pb, unsigned codebook, int #define GET_SIGN(x) ((x) >> 31) #define MAKE_CODE(x) (((x) << 1) ^ GET_SIGN(x)) -static void encode_dcs(PutBitContext *pb, DCTELEM *blocks, +static void encode_dcs(PutBitContext *pb, int16_t *blocks, int blocks_per_slice, int scale) { int i; @@ -343,7 +344,7 @@ static void encode_dcs(PutBitContext *pb, DCTELEM *blocks, } } -static void encode_acs(PutBitContext *pb, DCTELEM *blocks, +static void encode_acs(PutBitContext *pb, int16_t *blocks, int blocks_per_slice, int plane_size_factor, const uint8_t *scan, const int16_t *qmat) @@ -379,7 +380,7 @@ static void encode_acs(PutBitContext *pb, DCTELEM *blocks, static int encode_slice_plane(ProresContext *ctx, PutBitContext *pb, const uint16_t *src, int linesize, - int mbs_per_slice, DCTELEM *blocks, + int mbs_per_slice, int16_t *blocks, int blocks_per_mb, int plane_size_factor, const int16_t *qmat) { @@ -481,7 +482,7 @@ static inline int estimate_vlc(unsigned codebook, int val) } } -static int estimate_dcs(int *error, DCTELEM *blocks, int blocks_per_slice, +static int estimate_dcs(int *error, int16_t *blocks, int blocks_per_slice, int scale) { int i; @@ -512,7 +513,7 @@ static int estimate_dcs(int *error, DCTELEM *blocks, int blocks_per_slice, return bits; } -static int estimate_acs(int *error, DCTELEM *blocks, int blocks_per_slice, +static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice, int plane_size_factor, const uint8_t *scan, const int16_t *qmat) { diff --git a/mythtv/external/FFmpeg/libavcodec/psymodel.h b/mythtv/external/FFmpeg/libavcodec/psymodel.h index 37c81917246..d1a126a88f3 100644 --- a/mythtv/external/FFmpeg/libavcodec/psymodel.h +++ b/mythtv/external/FFmpeg/libavcodec/psymodel.h @@ -139,9 +139,9 @@ typedef struct FFPsyModel { * * @return zero if successful, a negative value if not */ -av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens, - const uint8_t **bands, const int* num_bands, - int num_groups, const uint8_t *group_map); +int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens, + const uint8_t **bands, const int *num_bands, + int num_groups, const uint8_t *group_map); /** * Determine what group a channel belongs to. @@ -158,7 +158,7 @@ FFPsyChannelGroup *ff_psy_find_group(FFPsyContext *ctx, int channel); * * @param ctx model context */ -av_cold void ff_psy_end(FFPsyContext *ctx); +void ff_psy_end(FFPsyContext *ctx); /************************************************************************** @@ -170,7 +170,7 @@ struct FFPsyPreprocessContext; /** * psychoacoustic model audio preprocessing initialization */ -av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *avctx); +struct FFPsyPreprocessContext *ff_psy_preprocess_init(AVCodecContext *avctx); /** * Preprocess several channel in audio frame in order to compress it better. @@ -184,6 +184,6 @@ void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int ch /** * Cleanup audio preprocessing module. */ -av_cold void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx); +void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx); #endif /* AVCODEC_PSYMODEL_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/pthread.c b/mythtv/external/FFmpeg/libavcodec/pthread.c index b55cccf2000..1ca72b44f23 100644 --- a/mythtv/external/FFmpeg/libavcodec/pthread.c +++ b/mythtv/external/FFmpeg/libavcodec/pthread.c @@ -754,7 +754,11 @@ static void frame_thread_free(AVCodecContext *avctx, int thread_count) park_frame_worker_threads(fctx, thread_count); if (fctx->prev_thread && fctx->prev_thread != fctx->threads) - update_context_from_thread(fctx->threads->avctx, fctx->prev_thread->avctx, 0); + if (update_context_from_thread(fctx->threads->avctx, fctx->prev_thread->avctx, 0) < 0) { + av_log(avctx, AV_LOG_ERROR, "Final thread update failed\n"); + fctx->prev_thread->avctx->internal->is_copy = fctx->threads->avctx->internal->is_copy; + fctx->threads->avctx->internal->is_copy = 1; + } fctx->die = 1; @@ -1019,6 +1023,9 @@ void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f) PerThreadContext *p = avctx->thread_opaque; FrameThreadContext *fctx; + if (!f->data[0]) + return; + if (!(avctx->active_thread_type&FF_THREAD_FRAME)) { avctx->release_buffer(avctx, f); return; diff --git a/mythtv/external/FFmpeg/libavcodec/ptx.c b/mythtv/external/FFmpeg/libavcodec/ptx.c index 720dad1b943..1a76c55c894 100644 --- a/mythtv/external/FFmpeg/libavcodec/ptx.c +++ b/mythtv/external/FFmpeg/libavcodec/ptx.c @@ -46,6 +46,7 @@ static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVFrame *picture = data; AVFrame * const p = &s->picture; unsigned int offset, w, h, y, stride, bytes_per_pixel; + int ret; uint8_t *ptr; if (buf_end - buf < 14) @@ -72,13 +73,13 @@ static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (p->data[0]) avctx->release_buffer(avctx, p); - if (av_image_check_size(w, h, 0, avctx)) - return -1; + if ((ret = av_image_check_size(w, h, 0, avctx)) < 0) + return ret; if (w != avctx->width || h != avctx->height) avcodec_set_dimensions(avctx, w, h); - if (ff_get_buffer(avctx, p) < 0) { + if ((ret = ff_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } p->pict_type = AV_PICTURE_TYPE_I; diff --git a/mythtv/external/FFmpeg/libavcodec/put_bits.h b/mythtv/external/FFmpeg/libavcodec/put_bits.h index f02965e3002..7320443895e 100644 --- a/mythtv/external/FFmpeg/libavcodec/put_bits.h +++ b/mythtv/external/FFmpeg/libavcodec/put_bits.h @@ -29,6 +29,7 @@ #include #include #include + #include "libavutil/bswap.h" #include "libavutil/common.h" #include "libavutil/intreadwrite.h" @@ -50,19 +51,20 @@ typedef struct PutBitContext { * @param buffer the buffer where to put bits * @param buffer_size the size in bytes of buffer */ -static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size) +static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, + int buffer_size) { - if(buffer_size < 0) { + if (buffer_size < 0) { buffer_size = 0; - buffer = NULL; + buffer = NULL; } - s->size_in_bits= 8*buffer_size; - s->buf = buffer; - s->buf_end = s->buf + buffer_size; - s->buf_ptr = s->buf; - s->bit_left=32; - s->bit_buf=0; + s->size_in_bits = 8 * buffer_size; + s->buf = buffer; + s->buf_end = s->buf + buffer_size; + s->buf_ptr = s->buf; + s->bit_left = 32; + s->bit_buf = 0; } /** @@ -80,21 +82,21 @@ static inline void flush_put_bits(PutBitContext *s) { #ifndef BITSTREAM_WRITER_LE if (s->bit_left < 32) - s->bit_buf<<= s->bit_left; + s->bit_buf <<= s->bit_left; #endif while (s->bit_left < 32) { /* XXX: should test end of buffer */ #ifdef BITSTREAM_WRITER_LE - *s->buf_ptr++=s->bit_buf; - s->bit_buf>>=8; + *s->buf_ptr++ = s->bit_buf; + s->bit_buf >>= 8; #else - *s->buf_ptr++=s->bit_buf >> 24; - s->bit_buf<<=8; + *s->buf_ptr++ = s->bit_buf >> 24; + s->bit_buf <<= 8; #endif - s->bit_left+=8; + s->bit_left += 8; } - s->bit_left=32; - s->bit_buf=0; + s->bit_left = 32; + s->bit_buf = 0; } #ifdef BITSTREAM_WRITER_LE @@ -112,7 +114,8 @@ void avpriv_align_put_bits(PutBitContext *s); * * @param terminate_string 0-terminates the written string if value is 1 */ -void avpriv_put_string(PutBitContext *pb, const char *string, int terminate_string); +void avpriv_put_string(PutBitContext *pb, const char *string, + int terminate_string); /** * Copy the content of src to the bitstream. @@ -133,7 +136,7 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value) av_assert2(n <= 31 && value < (1U << n)); - bit_buf = s->bit_buf; + bit_buf = s->bit_buf; bit_left = s->bit_left; /* XXX: optimize */ @@ -142,27 +145,27 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value) if (n >= bit_left) { av_assert2(s->buf_ptr+3buf_end); AV_WL32(s->buf_ptr, bit_buf); - s->buf_ptr+=4; - bit_buf = (bit_left==32)?0:value >> bit_left; - bit_left+=32; + s->buf_ptr += 4; + bit_buf = (bit_left == 32) ? 0 : value >> bit_left; + bit_left += 32; } - bit_left-=n; + bit_left -= n; #else if (n < bit_left) { - bit_buf = (bit_buf<> (n - bit_left); + bit_buf <<= bit_left; + bit_buf |= value >> (n - bit_left); av_assert2(s->buf_ptr+3buf_end); AV_WB32(s->buf_ptr, bit_buf); - s->buf_ptr+=4; - bit_left+=32 - n; - bit_buf = value; + s->buf_ptr += 4; + bit_left += 32 - n; + bit_buf = value; } #endif - s->bit_buf = bit_buf; + s->bit_buf = bit_buf; s->bit_left = bit_left; } @@ -170,7 +173,7 @@ static inline void put_sbits(PutBitContext *pb, int n, int32_t value) { av_assert2(n >= 0 && n <= 31); - put_bits(pb, n, value & ((1<buf_ptr; + return s->buf_ptr; } /** @@ -204,9 +207,9 @@ static inline uint8_t* put_bits_ptr(PutBitContext *s) */ static inline void skip_put_bytes(PutBitContext *s, int n) { - av_assert2((put_bits_count(s)&7)==0); - av_assert2(s->bit_left==32); - s->buf_ptr += n; + av_assert2((put_bits_count(s) & 7) == 0); + av_assert2(s->bit_left == 32); + s->buf_ptr += n; } /** @@ -217,7 +220,7 @@ static inline void skip_put_bytes(PutBitContext *s, int n) static inline void skip_put_bits(PutBitContext *s, int n) { s->bit_left -= n; - s->buf_ptr-= 4*(s->bit_left>>5); + s->buf_ptr -= 4 * (s->bit_left >> 5); s->bit_left &= 31; } @@ -228,7 +231,7 @@ static inline void skip_put_bits(PutBitContext *s, int n) */ static inline void set_put_bits_buffer_size(PutBitContext *s, int size) { - s->buf_end= s->buf + size; + s->buf_end = s->buf + size; } #endif /* AVCODEC_PUT_BITS_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/qcelpdec.c b/mythtv/external/FFmpeg/libavcodec/qcelpdec.c index aff872563c0..76b51f841cd 100644 --- a/mythtv/external/FFmpeg/libavcodec/qcelpdec.c +++ b/mythtv/external/FFmpeg/libavcodec/qcelpdec.c @@ -30,10 +30,10 @@ #include #include "libavutil/channel_layout.h" +#include "libavutil/float_dsp.h" #include "avcodec.h" #include "internal.h" #include "get_bits.h" -#include "dsputil.h" #include "qcelpdata.h" #include "celp_filters.h" #include "acelp_filters.h" @@ -53,7 +53,6 @@ typedef enum { } qcelp_packet_rate; typedef struct { - AVFrame avframe; GetBitContext gb; qcelp_packet_rate bitrate; QCELPFrame frame; /**< unpacked data frame */ @@ -97,9 +96,6 @@ static av_cold int qcelp_decode_init(AVCodecContext *avctx) for (i = 0; i < 10; i++) q->prev_lspf[i] = (i + 1) / 11.; - avcodec_get_frame_defaults(&q->avframe); - avctx->coded_frame = &q->avframe; - return 0; } @@ -400,12 +396,10 @@ static void apply_gain_ctrl(float *v_out, const float *v_ref, const float *v_in) { int i; - for (i = 0; i < 160; i += 40) - ff_scale_vector_to_given_sum_of_squares(v_out + i, v_in + i, - ff_scalarproduct_float_c(v_ref + i, - v_ref + i, - 40), - 40); + for (i = 0; i < 160; i += 40) { + float res = avpriv_scalarproduct_float_c(v_ref + i, v_ref + i, 40); + ff_scale_vector_to_given_sum_of_squares(v_out + i, v_in + i, res, 40); + } } /** @@ -680,8 +674,9 @@ static void postfilter(QCELPContext *q, float *samples, float *lpc) ff_tilt_compensation(&q->postfilter_tilt_mem, 0.3, pole_out + 10, 160); ff_adaptive_gain_control(samples, pole_out + 10, - ff_scalarproduct_float_c(q->formant_mem + 10, - q->formant_mem + 10, 160), + avpriv_scalarproduct_float_c(q->formant_mem + 10, + q->formant_mem + 10, + 160), 160, 0.9375, &q->postfilter_agc_mem); } @@ -691,6 +686,7 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; QCELPContext *q = avctx->priv_data; + AVFrame *frame = data; float *outbuffer; int i, ret; float quantized_lspf[10], lpc[10]; @@ -698,12 +694,12 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, float *formant_mem; /* get output buffer */ - q->avframe.nb_samples = 160; - if ((ret = ff_get_buffer(avctx, &q->avframe)) < 0) { + frame->nb_samples = 160; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - outbuffer = (float *)q->avframe.data[0]; + outbuffer = (float *)frame->data[0]; if ((q->bitrate = determine_bitrate(avctx, buf_size, &buf)) == I_F_Q) { warn_insufficient_frame_quality(avctx, "bitrate cannot be determined."); @@ -786,8 +782,7 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, memcpy(q->prev_lspf, quantized_lspf, sizeof(q->prev_lspf)); q->prev_bitrate = q->bitrate; - *got_frame_ptr = 1; - *(AVFrame *)data = q->avframe; + *got_frame_ptr = 1; return buf_size; } diff --git a/mythtv/external/FFmpeg/libavcodec/qdm2.c b/mythtv/external/FFmpeg/libavcodec/qdm2.c index f5ed7074021..7136cf1c233 100644 --- a/mythtv/external/FFmpeg/libavcodec/qdm2.c +++ b/mythtv/external/FFmpeg/libavcodec/qdm2.c @@ -39,7 +39,6 @@ #include "libavutil/channel_layout.h" #include "avcodec.h" #include "get_bits.h" -#include "dsputil.h" #include "internal.h" #include "rdft.h" #include "mpegaudiodsp.h" @@ -130,8 +129,6 @@ typedef struct { * QDM2 decoder context */ typedef struct { - AVFrame frame; - /// Parameters from codec header, do not change during playback int nb_channels; ///< number of channels int channels; ///< number of channels @@ -649,7 +646,8 @@ static void fill_coding_method_array (sb_int8_array tone_level_idx, sb_int8_arra if (!superblocktype_2_3) { /* This case is untested, no samples available */ - SAMPLES_NEEDED + av_log_ask_for_sample(NULL, "!superblocktype_2_3"); + return; for (ch = 0; ch < nb_channels; ch++) for (sb = 0; sb < 30; sb++) { for (j = 1; j < 63; j++) { // The loop only iterates to 63 so the code doesn't overflow the buffer @@ -685,7 +683,7 @@ static void fill_coding_method_array (sb_int8_array tone_level_idx, sb_int8_arra for (j = 0; j < 64; j++) acc += tone_level_idx_temp[ch][sb][j]; - multres = 0x66666667 * (acc * 10); + multres = 0x66666667LL * (acc * 10); esp_40 = (multres >> 32) / 8 + ((multres & 0xffffffff) >> 31); for (ch = 0; ch < nb_channels; ch++) for (sb = 0; sb < 30; sb++) @@ -826,6 +824,11 @@ static int synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int le } } else { n = get_bits(gb, 8); + if (n >= 243) { + av_log(NULL, AV_LOG_ERROR, "Invalid 8bit codeword\n"); + return AVERROR_INVALIDDATA; + } + for (k = 0; k < 5; k++) samples[2 * k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]]; } @@ -862,6 +865,11 @@ static int synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int le } } else { n = get_bits (gb, 8); + if (n >= 243) { + av_log(NULL, AV_LOG_ERROR, "Invalid 8bit codeword\n"); + return AVERROR_INVALIDDATA; + } + for (k = 0; k < 5; k++) samples[k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]]; } @@ -875,6 +883,11 @@ static int synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int le case 24: if (get_bits_left(gb) >= 7) { n = get_bits(gb, 7); + if (n >= 125) { + av_log(NULL, AV_LOG_ERROR, "Invalid 7bit codeword\n"); + return AVERROR_INVALIDDATA; + } + for (k = 0; k < 3; k++) samples[k] = (random_dequant_type24[n][k] - 2.0) * 0.5; } else { @@ -928,10 +941,10 @@ static int synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int le if (joined_stereo) { float tmp[10][MPA_MAX_CHANNELS]; - for (k = 0; k < run; k++) { tmp[k][0] = samples[k]; - tmp[k][1] = (sign_bits[(j + k) / 8]) ? -samples[k] : samples[k]; + if ((j + k) < 128) + tmp[k][1] = (sign_bits[(j + k) / 8]) ? -samples[k] : samples[k]; } for (chs = 0; chs < q->nb_channels; chs++) for (k = 0; k < run; k++) @@ -1878,9 +1891,6 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx) avctx->sample_fmt = AV_SAMPLE_FMT_S16; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -1961,6 +1971,7 @@ static int qdm2_decode (QDM2Context *q, const uint8_t *in, int16_t *out) static int qdm2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; QDM2Context *s = avctx->priv_data; @@ -1973,12 +1984,12 @@ static int qdm2_decode_frame(AVCodecContext *avctx, void *data, return -1; /* get output buffer */ - s->frame.nb_samples = 16 * s->frame_size; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = 16 * s->frame_size; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - out = (int16_t *)s->frame.data[0]; + out = (int16_t *)frame->data[0]; for (i = 0; i < 16; i++) { if (qdm2_decode(s, buf, out) < 0) @@ -1986,8 +1997,7 @@ static int qdm2_decode_frame(AVCodecContext *avctx, void *data, out += s->channels * s->frame_size; } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return s->checksum_size; } diff --git a/mythtv/external/FFmpeg/libavcodec/qdm2_tablegen.h b/mythtv/external/FFmpeg/libavcodec/qdm2_tablegen.h index 585edfdd653..13ec9beb628 100644 --- a/mythtv/external/FFmpeg/libavcodec/qdm2_tablegen.h +++ b/mythtv/external/FFmpeg/libavcodec/qdm2_tablegen.h @@ -37,7 +37,7 @@ #include "libavcodec/qdm2_tables.h" #else static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1]; -static float noise_table[4096]; +static float noise_table[4096 + 20]; static uint8_t random_dequant_index[256][5]; static uint8_t random_dequant_type24[128][3]; static float noise_samples[128]; @@ -54,8 +54,7 @@ static av_cold void softclip_table_init(void) { // random generated table static av_cold void rnd_table_init(void) { int i,j; - uint32_t ldw,hdw; - uint64_t tmp64_1; + uint32_t ldw; uint64_t random_seed = 0; float delta = 1.0 / 16384.0; for(i = 0; i < 4096 ;i++) { @@ -67,22 +66,18 @@ static av_cold void rnd_table_init(void) { random_seed = 81; ldw = i; for (j = 0; j < 5 ;j++) { - random_dequant_index[i][j] = (uint8_t)((ldw / random_seed) & 0xFF); - ldw = (uint32_t)ldw % (uint32_t)random_seed; - tmp64_1 = (random_seed * 0x55555556); - hdw = (uint32_t)(tmp64_1 >> 32); - random_seed = (uint64_t)(hdw + (ldw >> 31)); + random_dequant_index[i][j] = ldw / random_seed; + ldw %= random_seed; + random_seed /= 3; } } for (i = 0; i < 128 ;i++) { random_seed = 25; ldw = i; for (j = 0; j < 3 ;j++) { - random_dequant_type24[i][j] = (uint8_t)((ldw / random_seed) & 0xFF); - ldw = (uint32_t)ldw % (uint32_t)random_seed; - tmp64_1 = (random_seed * 0x66666667); - hdw = (uint32_t)(tmp64_1 >> 33); - random_seed = hdw + (ldw >> 31); + random_dequant_type24[i][j] = ldw / random_seed; + ldw %= random_seed; + random_seed /= 5; } } } diff --git a/mythtv/external/FFmpeg/libavcodec/qdrw.c b/mythtv/external/FFmpeg/libavcodec/qdrw.c index 2be6e04b645..4ad64aadae8 100644 --- a/mythtv/external/FFmpeg/libavcodec/qdrw.c +++ b/mythtv/external/FFmpeg/libavcodec/qdrw.c @@ -29,7 +29,7 @@ #include "avcodec.h" #include "internal.h" -typedef struct QdrawContext{ +typedef struct QdrawContext { AVCodecContext *avctx; AVFrame pic; } QdrawContext; @@ -38,39 +38,39 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { - const uint8_t *buf = avpkt->data; + const uint8_t *buf = avpkt->data; const uint8_t *buf_end = avpkt->data + avpkt->size; - int buf_size = avpkt->size; + int buf_size = avpkt->size; QdrawContext * const a = avctx->priv_data; - AVFrame * const p = &a->pic; + AVFrame * const p = &a->pic; uint8_t* outdata; int colors; - int i; + int i, ret; uint32_t *pal; int r, g, b; - if(p->data[0]) + if (p->data[0]) avctx->release_buffer(avctx, p); - p->reference= 0; - if(ff_get_buffer(avctx, p) < 0){ + p->reference = 0; + if ((ret = ff_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } - p->pict_type= AV_PICTURE_TYPE_I; - p->key_frame= 1; + p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; outdata = a->pic.data[0]; if (buf_end - buf < 0x68 + 4) return AVERROR_INVALIDDATA; - buf += 0x68; /* jump to palette */ + buf += 0x68; /* jump to palette */ colors = AV_RB32(buf); - buf += 4; + buf += 4; - if(colors < 0 || colors > 256) { + if (colors < 0 || colors > 256) { av_log(avctx, AV_LOG_ERROR, "Error color count - %i(0x%X)\n", colors, colors); - return -1; + return AVERROR_INVALIDDATA; } if (buf_end - buf < (colors + 1) * 8) return AVERROR_INVALIDDATA; @@ -106,7 +106,7 @@ static int decode_frame(AVCodecContext *avctx, int tsize = 0; /* decode line */ - out = outdata; + out = outdata; size = AV_RB16(buf); /* size of packed line */ buf += 2; if (buf_end - buf < size) @@ -121,18 +121,18 @@ static int decode_frame(AVCodecContext *avctx, if ((out + (257 - code)) > (outdata + a->pic.linesize[0])) break; memset(out, pix, 257 - code); - out += 257 - code; + out += 257 - code; tsize += 257 - code; - left -= 2; + left -= 2; } else { /* copy */ if ((out + code) > (outdata + a->pic.linesize[0])) break; if (buf_end - buf < code + 1) return AVERROR_INVALIDDATA; memcpy(out, buf, code + 1); - out += code + 1; - buf += code + 1; - left -= 2 + code; + out += code + 1; + buf += code + 1; + left -= 2 + code; tsize += code + 1; } } @@ -146,7 +146,8 @@ static int decode_frame(AVCodecContext *avctx, return buf_size; } -static av_cold int decode_init(AVCodecContext *avctx){ +static av_cold int decode_init(AVCodecContext *avctx) +{ QdrawContext * const a = avctx->priv_data; avcodec_get_frame_defaults(&a->pic); @@ -155,7 +156,8 @@ static av_cold int decode_init(AVCodecContext *avctx){ return 0; } -static av_cold int decode_end(AVCodecContext *avctx){ +static av_cold int decode_end(AVCodecContext *avctx) +{ QdrawContext * const a = avctx->priv_data; AVFrame *pic = &a->pic; diff --git a/mythtv/external/FFmpeg/libavcodec/qpeg.c b/mythtv/external/FFmpeg/libavcodec/qpeg.c index 105ac696005..73d652e5d8b 100644 --- a/mythtv/external/FFmpeg/libavcodec/qpeg.c +++ b/mythtv/external/FFmpeg/libavcodec/qpeg.c @@ -258,7 +258,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame * p = &a->pic; AVFrame * ref= &a->ref; uint8_t* outdata; - int delta; + int delta, ret; const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); if (avpkt->size < 0x86) { @@ -273,9 +273,9 @@ static int decode_frame(AVCodecContext *avctx, FFSWAP(AVFrame, *ref, *p); p->reference= 3; - if(ff_get_buffer(avctx, p) < 0){ + if ((ret = ff_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } outdata = a->pic.data[0]; bytestream2_skip(&a->buffer, 4); diff --git a/mythtv/external/FFmpeg/libavcodec/qtrle.c b/mythtv/external/FFmpeg/libavcodec/qtrle.c index c778ee3e37d..1b92885b321 100644 --- a/mythtv/external/FFmpeg/libavcodec/qtrle.c +++ b/mythtv/external/FFmpeg/libavcodec/qtrle.c @@ -46,12 +46,12 @@ typedef struct QtrleContext { uint32_t pal[256]; } QtrleContext; -#define CHECK_PIXEL_PTR(n) \ - if ((pixel_ptr + n > pixel_limit) || (pixel_ptr + n < 0)) { \ - av_log (s->avctx, AV_LOG_INFO, "Problem: pixel_ptr = %d, pixel_limit = %d\n", \ - pixel_ptr + n, pixel_limit); \ - return; \ - } \ +#define CHECK_PIXEL_PTR(n) \ + if ((pixel_ptr + n > pixel_limit) || (pixel_ptr + n < 0)) { \ + av_log (s->avctx, AV_LOG_ERROR, "Problem: pixel_ptr = %d, pixel_limit = %d\n",\ + pixel_ptr + n, pixel_limit); \ + return; \ + } \ static void qtrle_decode_1bpp(QtrleContext *s, int row_ptr, int lines_to_change) { @@ -62,6 +62,14 @@ static void qtrle_decode_1bpp(QtrleContext *s, int row_ptr, int lines_to_change) unsigned char *rgb = s->frame.data[0]; int pixel_limit = s->frame.linesize[0] * s->avctx->height; int skip; + /* skip & 0x80 appears to mean 'start a new line', which can be interpreted + * as 'go to next line' during the decoding of a frame but is 'go to first + * line' at the beginning. Since we always interpret it as 'go to next line' + * in the decoding loop (which makes code simpler/faster), the first line + * would not be counted, so we count one more. + * See: https://ffmpeg.org/trac/ffmpeg/ticket/226 + * In the following decoding loop, row_ptr will be the position of the + * current row. */ row_ptr -= row_inc; pixel_ptr = row_ptr; @@ -401,14 +409,15 @@ static int qtrle_decode_frame(AVCodecContext *avctx, int header, start_line; int height, row_ptr; int has_palette = 0; + int ret; bytestream2_init(&s->g, avpkt->data, avpkt->size); s->frame.reference = 3; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; - if (avctx->reget_buffer(avctx, &s->frame)) { + if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0) { av_log (s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } /* check if this frame is even supposed to change */ diff --git a/mythtv/external/FFmpeg/libavcodec/qtrleenc.c b/mythtv/external/FFmpeg/libavcodec/qtrleenc.c index e151c9e1faa..a25c45d6dbc 100644 --- a/mythtv/external/FFmpeg/libavcodec/qtrleenc.c +++ b/mythtv/external/FFmpeg/libavcodec/qtrleenc.c @@ -121,8 +121,6 @@ static void qtrle_encode_line(QtrleEncContext *s, const AVFrame *p, int line, ui int i; signed char rlecode; - /* We will use it to compute the best bulk copy sequence */ - unsigned int av_uninit(bulkcount); /* This will be the number of pixels equal to the preivous frame one's * starting from the ith pixel */ unsigned int skipcount; @@ -131,12 +129,14 @@ static void qtrle_encode_line(QtrleEncContext *s, const AVFrame *p, int line, ui unsigned int av_uninit(repeatcount); /* The cost of the three different possibilities */ - int total_bulk_cost; int total_skip_cost; int total_repeat_cost; - int temp_cost; - int j; + int base_bulk_cost; + int lowest_bulk_cost; + int lowest_bulk_cost_index; + int sec_lowest_bulk_cost; + int sec_lowest_bulk_cost_index; uint8_t *this_line = p-> data[0] + line*p-> linesize[0] + (width - 1)*s->pixel_size; @@ -146,8 +146,57 @@ static void qtrle_encode_line(QtrleEncContext *s, const AVFrame *p, int line, ui s->length_table[width] = 0; skipcount = 0; + /* Initial values */ + lowest_bulk_cost = INT_MAX / 2; + lowest_bulk_cost_index = width; + sec_lowest_bulk_cost = INT_MAX / 2; + sec_lowest_bulk_cost_index = width; + + base_bulk_cost = 1 + s->pixel_size; + for (i = width - 1; i >= 0; i--) { + int prev_bulk_cost; + + /* If our lowest bulk cost index is too far away, replace it + * with the next lowest bulk cost */ + if (FFMIN(width, i + MAX_RLE_BULK) < lowest_bulk_cost_index) { + lowest_bulk_cost = sec_lowest_bulk_cost; + lowest_bulk_cost_index = sec_lowest_bulk_cost_index; + + sec_lowest_bulk_cost = INT_MAX / 2; + sec_lowest_bulk_cost_index = width; + } + + /* Deal with the first pixel's bulk cost */ + if (!i) { + base_bulk_cost++; + lowest_bulk_cost++; + sec_lowest_bulk_cost++; + } + + /* Look at the bulk cost of the previous loop and see if it is + * a new lower bulk cost */ + prev_bulk_cost = s->length_table[i + 1] + base_bulk_cost; + if (prev_bulk_cost <= sec_lowest_bulk_cost) { + /* If it's lower than the 2nd lowest, then it may be lower + * than the lowest */ + if (prev_bulk_cost <= lowest_bulk_cost) { + + /* If we have found a new lowest bulk cost, + * then the 2nd lowest bulk cost is now farther than the + * lowest bulk cost, and will never be used */ + sec_lowest_bulk_cost = INT_MAX / 2; + + lowest_bulk_cost = prev_bulk_cost; + lowest_bulk_cost_index = i + 1; + } else { + /* Then it must be the 2nd lowest bulk cost */ + sec_lowest_bulk_cost = prev_bulk_cost; + sec_lowest_bulk_cost_index = i + 1; + } + } + if (!s->frame.key_frame && !memcmp(this_line, prev_line, s->pixel_size)) skipcount = FFMIN(skipcount + 1, MAX_RLE_SKIP); else @@ -183,26 +232,17 @@ static void qtrle_encode_line(QtrleEncContext *s, const AVFrame *p, int line, ui } else { /* We cannot do neither skip nor repeat - * thus we search for the best bulk copy to do */ + * thus we use the best bulk copy */ - int limit = FFMIN(width - i, MAX_RLE_BULK); + s->length_table[i] = lowest_bulk_cost; + s->rlecode_table[i] = lowest_bulk_cost_index - i; - temp_cost = 1 + s->pixel_size + !i; - total_bulk_cost = INT_MAX; - - for (j = 1; j <= limit; j++) { - if (s->length_table[i + j] + temp_cost < total_bulk_cost) { - /* We have found a better bulk copy ... */ - total_bulk_cost = s->length_table[i + j] + temp_cost; - bulkcount = j; - } - temp_cost += s->pixel_size; - } - - s->length_table[i] = total_bulk_cost; - s->rlecode_table[i] = bulkcount; } + /* These bulk costs increase every iteration */ + lowest_bulk_cost += s->pixel_size; + sec_lowest_bulk_cost += s->pixel_size; + this_line -= s->pixel_size; prev_line -= s->pixel_size; } diff --git a/mythtv/external/FFmpeg/libavcodec/r210dec.c b/mythtv/external/FFmpeg/libavcodec/r210dec.c index d51a55719b7..b58f11f9be4 100644 --- a/mythtv/external/FFmpeg/libavcodec/r210dec.c +++ b/mythtv/external/FFmpeg/libavcodec/r210dec.c @@ -40,7 +40,7 @@ static av_cold int decode_init(AVCodecContext *avctx) static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { - int h, w; + int h, w, ret; AVFrame *pic = avctx->coded_frame; const uint32_t *src = (const uint32_t *)avpkt->data; int aligned_width = FFALIGN(avctx->width, @@ -52,12 +52,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (avpkt->size < 4 * aligned_width * avctx->height) { av_log(avctx, AV_LOG_ERROR, "packet too small\n"); - return -1; + return AVERROR_INVALIDDATA; } pic->reference = 0; - if (ff_get_buffer(avctx, pic) < 0) - return -1; + if ((ret = ff_get_buffer(avctx, pic)) < 0) + return ret; pic->pict_type = AV_PICTURE_TYPE_I; pic->key_frame = 1; diff --git a/mythtv/external/FFmpeg/libavcodec/ra144.h b/mythtv/external/FFmpeg/libavcodec/ra144.h index 331dc35f3c1..eb893988fbb 100644 --- a/mythtv/external/FFmpeg/libavcodec/ra144.h +++ b/mythtv/external/FFmpeg/libavcodec/ra144.h @@ -35,7 +35,6 @@ typedef struct RA144Context { AVCodecContext *avctx; - AVFrame frame; LPCContext lpc_ctx; AudioFrameQueue afq; int last_frame; diff --git a/mythtv/external/FFmpeg/libavcodec/ra144dec.c b/mythtv/external/FFmpeg/libavcodec/ra144dec.c index b0e2498f40e..f12954b2f77 100644 --- a/mythtv/external/FFmpeg/libavcodec/ra144dec.c +++ b/mythtv/external/FFmpeg/libavcodec/ra144dec.c @@ -23,7 +23,6 @@ */ #include "libavutil/channel_layout.h" -#include "libavutil/intmath.h" #include "avcodec.h" #include "get_bits.h" #include "internal.h" @@ -43,9 +42,6 @@ static av_cold int ra144_decode_init(AVCodecContext * avctx) avctx->channel_layout = AV_CH_LAYOUT_MONO; avctx->sample_fmt = AV_SAMPLE_FMT_S16; - avcodec_get_frame_defaults(&ractx->frame); - avctx->coded_frame = &ractx->frame; - return 0; } @@ -65,6 +61,7 @@ static void do_output_subblock(RA144Context *ractx, const uint16_t *lpc_coefs, static int ra144_decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; static const uint8_t sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2}; @@ -80,12 +77,12 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *data, GetBitContext gb; /* get output buffer */ - ractx->frame.nb_samples = NBLOCKS * BLOCKSIZE; - if ((ret = ff_get_buffer(avctx, &ractx->frame)) < 0) { + frame->nb_samples = NBLOCKS * BLOCKSIZE; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (int16_t *)ractx->frame.data[0]; + samples = (int16_t *)frame->data[0]; if(buf_size < FRAMESIZE) { av_log(avctx, AV_LOG_ERROR, @@ -124,8 +121,7 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *data, FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]); - *got_frame_ptr = 1; - *(AVFrame *)data = ractx->frame; + *got_frame_ptr = 1; return FRAMESIZE; } diff --git a/mythtv/external/FFmpeg/libavcodec/ra144enc.c b/mythtv/external/FFmpeg/libavcodec/ra144enc.c index b89e4b7fb01..21d38dcea0a 100644 --- a/mythtv/external/FFmpeg/libavcodec/ra144enc.c +++ b/mythtv/external/FFmpeg/libavcodec/ra144enc.c @@ -208,8 +208,8 @@ static void create_adapt_vect(float *vect, const int16_t *cb, int lag) static int adaptive_cb_search(const int16_t *adapt_cb, float *work, const float *coefs, float *data) { - int i, best_vect; - float score, gain, best_score, best_gain; + int i, av_uninit(best_vect); + float score, gain, best_score, av_uninit(best_gain); float exc[BLOCKSIZE]; gain = best_score = 0; @@ -458,7 +458,7 @@ static int ra144_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (ractx->last_frame) return 0; - if ((ret = ff_alloc_packet2(avctx, avpkt, FRAMESIZE))) + if ((ret = ff_alloc_packet2(avctx, avpkt, FRAMESIZE)) < 0) return ret; /** diff --git a/mythtv/external/FFmpeg/libavcodec/ra288.c b/mythtv/external/FFmpeg/libavcodec/ra288.c index 7f0e2f71a84..dac8aa60325 100644 --- a/mythtv/external/FFmpeg/libavcodec/ra288.c +++ b/mythtv/external/FFmpeg/libavcodec/ra288.c @@ -21,6 +21,7 @@ #include "libavutil/channel_layout.h" #include "libavutil/float_dsp.h" +#include "libavutil/internal.h" #include "avcodec.h" #include "internal.h" #define BITSTREAM_READER_LE @@ -37,8 +38,6 @@ #define RA288_BLOCKS_PER_FRAME 32 typedef struct { - AVFrame frame; - DSPContext dsp; AVFloatDSPContext fdsp; DECLARE_ALIGNED(32, float, sp_lpc)[FFALIGN(36, 16)]; ///< LPC coefficients for speech data (spec: A) DECLARE_ALIGNED(32, float, gain_lpc)[FFALIGN(10, 16)]; ///< LPC coefficients for gain (spec: GB) @@ -75,16 +74,13 @@ static av_cold int ra288_decode_init(AVCodecContext *avctx) avpriv_float_dsp_init(&ractx->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); - avcodec_get_frame_defaults(&ractx->frame); - avctx->coded_frame = &ractx->frame; - return 0; } static void convolve(float *tgt, const float *src, int len, int n) { for (; n >= 0; n--) - tgt[n] = ff_scalarproduct_float_c(src, src - n, len); + tgt[n] = avpriv_scalarproduct_float_c(src, src - n, len); } @@ -113,7 +109,7 @@ static void decode(RA288Context *ractx, float gain, int cb_coef) for (i=0; i < 5; i++) buffer[i] = codetable[cb_coef][i] * sumsum; - sum = ff_scalarproduct_float_c(buffer, buffer, 5); + sum = avpriv_scalarproduct_float_c(buffer, buffer, 5); sum = FFMAX(sum, 5. / (1<<24)); @@ -185,6 +181,7 @@ static void backward_filter(RA288Context *ractx, static int ra288_decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; float *out; @@ -200,12 +197,12 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data, } /* get output buffer */ - ractx->frame.nb_samples = RA288_BLOCK_SIZE * RA288_BLOCKS_PER_FRAME; - if ((ret = ff_get_buffer(avctx, &ractx->frame)) < 0) { + frame->nb_samples = RA288_BLOCK_SIZE * RA288_BLOCKS_PER_FRAME; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - out = (float *)ractx->frame.data[0]; + out = (float *)frame->data[0]; init_get_bits(&gb, buf, avctx->block_align * 8); @@ -227,8 +224,7 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data, } } - *got_frame_ptr = 1; - *(AVFrame *)data = ractx->frame; + *got_frame_ptr = 1; return avctx->block_align; } diff --git a/mythtv/external/FFmpeg/libavcodec/ra288.h b/mythtv/external/FFmpeg/libavcodec/ra288.h index 0432bed4858..7323eea8b28 100644 --- a/mythtv/external/FFmpeg/libavcodec/ra288.h +++ b/mythtv/external/FFmpeg/libavcodec/ra288.h @@ -23,7 +23,6 @@ #define AVCODEC_RA288_H #include -#include "dsputil.h" #include "libavutil/common.h" static const float amptable[8]={ diff --git a/mythtv/external/FFmpeg/libavcodec/ralf.c b/mythtv/external/FFmpeg/libavcodec/ralf.c index 580def31834..b163a895abc 100644 --- a/mythtv/external/FFmpeg/libavcodec/ralf.c +++ b/mythtv/external/FFmpeg/libavcodec/ralf.c @@ -49,8 +49,6 @@ typedef struct VLCSet { #define RALF_MAX_PKT_SIZE 8192 typedef struct RALFContext { - AVFrame frame; - int version; int max_frame_size; VLCSet sets[3]; @@ -154,9 +152,6 @@ static av_cold int decode_init(AVCodecContext *avctx) avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; - avcodec_get_frame_defaults(&ctx->frame); - avctx->coded_frame = &ctx->frame; - ctx->max_frame_size = AV_RB32(avctx->extradata + 16); if (ctx->max_frame_size > (1 << 20) || !ctx->max_frame_size) { av_log(avctx, AV_LOG_ERROR, "invalid frame size %d\n", @@ -426,6 +421,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { RALFContext *ctx = avctx->priv_data; + AVFrame *frame = data; int16_t *samples0; int16_t *samples1; int ret; @@ -463,13 +459,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, src_size = avpkt->size; } - ctx->frame.nb_samples = ctx->max_frame_size; - if ((ret = ff_get_buffer(avctx, &ctx->frame)) < 0) { + frame->nb_samples = ctx->max_frame_size; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "Me fail get_buffer()? That's unpossible!\n"); return ret; } - samples0 = (int16_t *)ctx->frame.data[0]; - samples1 = (int16_t *)ctx->frame.data[1]; + samples0 = (int16_t *)frame->data[0]; + samples1 = (int16_t *)frame->data[1]; if (src_size < 5) { av_log(avctx, AV_LOG_ERROR, "too short packets are too short!\n"); @@ -511,9 +507,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, bytes_left -= ctx->block_size[i]; } - ctx->frame.nb_samples = ctx->sample_offset; - *got_frame_ptr = ctx->sample_offset > 0; - *(AVFrame*)data = ctx->frame; + frame->nb_samples = ctx->sample_offset; + *got_frame_ptr = ctx->sample_offset > 0; return avpkt->size; } diff --git a/mythtv/external/FFmpeg/libavcodec/ratecontrol.c b/mythtv/external/FFmpeg/libavcodec/ratecontrol.c index ea6aafd0986..58604237710 100644 --- a/mythtv/external/FFmpeg/libavcodec/ratecontrol.c +++ b/mythtv/external/FFmpeg/libavcodec/ratecontrol.c @@ -25,9 +25,7 @@ * Rate control for video encoders. */ -#include "libavutil/intmath.h" #include "avcodec.h" -#include "dsputil.h" #include "ratecontrol.h" #include "mpegvideo.h" #include "libavutil/eval.h" @@ -40,38 +38,56 @@ #endif static int init_pass2(MpegEncContext *s); -static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num); +static double get_qscale(MpegEncContext *s, RateControlEntry *rce, + double rate_factor, int frame_num); -void ff_write_pass1_stats(MpegEncContext *s){ - snprintf(s->avctx->stats_out, 256, "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d;\n", - s->current_picture_ptr->f.display_picture_number, s->current_picture_ptr->f.coded_picture_number, s->pict_type, - s->current_picture.f.quality, s->i_tex_bits, s->p_tex_bits, s->mv_bits, s->misc_bits, - s->f_code, s->b_code, s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count, s->skip_count, s->header_bits); +void ff_write_pass1_stats(MpegEncContext *s) +{ + snprintf(s->avctx->stats_out, 256, + "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d " + "fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d;\n", + s->current_picture_ptr->f.display_picture_number, + s->current_picture_ptr->f.coded_picture_number, + s->pict_type, + s->current_picture.f.quality, + s->i_tex_bits, + s->p_tex_bits, + s->mv_bits, + s->misc_bits, + s->f_code, + s->b_code, + s->current_picture.mc_mb_var_sum, + s->current_picture.mb_var_sum, + s->i_count, s->skip_count, + s->header_bits); } -static double get_fps(AVCodecContext *avctx){ +static double get_fps(AVCodecContext *avctx) +{ return 1.0 / av_q2d(avctx->time_base) / FFMAX(avctx->ticks_per_frame, 1); } -static inline double qp2bits(RateControlEntry *rce, double qp){ - if(qp<=0.0){ +static inline double qp2bits(RateControlEntry *rce, double qp) +{ + if (qp <= 0.0) { av_log(NULL, AV_LOG_ERROR, "qp<=0.0\n"); } - return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits+1)/ qp; + return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits + 1) / qp; } -static inline double bits2qp(RateControlEntry *rce, double bits){ - if(bits<0.9){ +static inline double bits2qp(RateControlEntry *rce, double bits) +{ + if (bits < 0.9) { av_log(NULL, AV_LOG_ERROR, "bits<0.9\n"); } - return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits+1)/ bits; + return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits + 1) / bits; } int ff_rate_control_init(MpegEncContext *s) { - RateControlContext *rcc= &s->rc_context; + RateControlContext *rcc = &s->rc_context; int i, res; - static const char * const const_names[]={ + static const char * const const_names[] = { "PI", "E", "iTex", @@ -87,10 +103,12 @@ int ff_rate_control_init(MpegEncContext *s) "isB", "avgQP", "qComp", -/* "lastIQP", +#if 0 + "lastIQP", "lastPQP", "lastBQP", - "nextNonBQP",*/ + "nextNonBQP", +#endif "avgIITex", "avgPITex", "avgPPTex", @@ -98,12 +116,12 @@ int ff_rate_control_init(MpegEncContext *s) "avgTex", NULL }; - static double (* const func1[])(void *, double)={ + static double (* const func1[])(void *, double) = { (void *)bits2qp, (void *)qp2bits, NULL }; - static const char * const func1_names[]={ + static const char * const func1_names[] = { "bits2qp", "qp2bits", NULL @@ -117,146 +135,162 @@ int ff_rate_control_init(MpegEncContext *s) s->avctx->rc_max_available_vbv_use = 1.0; } - res = av_expr_parse(&rcc->rc_eq_eval, s->avctx->rc_eq ? s->avctx->rc_eq : "tex^qComp", const_names, func1_names, func1, NULL, NULL, 0, s->avctx); + res = av_expr_parse(&rcc->rc_eq_eval, + s->avctx->rc_eq ? s->avctx->rc_eq : "tex^qComp", + const_names, func1_names, func1, + NULL, NULL, 0, s->avctx); if (res < 0) { av_log(s->avctx, AV_LOG_ERROR, "Error parsing rc_eq \"%s\"\n", s->avctx->rc_eq); return res; } - for(i=0; i<5; i++){ - rcc->pred[i].coeff= FF_QP2LAMBDA * 7.0; - rcc->pred[i].count= 1.0; - - rcc->pred[i].decay= 0.4; - rcc->i_cplx_sum [i]= - rcc->p_cplx_sum [i]= - rcc->mv_bits_sum[i]= - rcc->qscale_sum [i]= - rcc->frame_count[i]= 1; // 1 is better because of 1/0 and such - rcc->last_qscale_for[i]=FF_QP2LAMBDA * 5; + for (i = 0; i < 5; i++) { + rcc->pred[i].coeff = FF_QP2LAMBDA * 7.0; + rcc->pred[i].count = 1.0; + rcc->pred[i].decay = 0.4; + + rcc->i_cplx_sum [i] = + rcc->p_cplx_sum [i] = + rcc->mv_bits_sum[i] = + rcc->qscale_sum [i] = + rcc->frame_count[i] = 1; // 1 is better because of 1/0 and such + + rcc->last_qscale_for[i] = FF_QP2LAMBDA * 5; } - rcc->buffer_index= s->avctx->rc_initial_buffer_occupancy; + rcc->buffer_index = s->avctx->rc_initial_buffer_occupancy; if (!rcc->buffer_index) rcc->buffer_index = s->avctx->rc_buffer_size * 3 / 4; - if(s->flags&CODEC_FLAG_PASS2){ + if (s->flags & CODEC_FLAG_PASS2) { int i; char *p; /* find number of pics */ - p= s->avctx->stats_in; - for(i=-1; p; i++){ - p= strchr(p+1, ';'); - } - i+= s->max_b_frames; - if(i<=0 || i>=INT_MAX / sizeof(RateControlEntry)) + p = s->avctx->stats_in; + for (i = -1; p; i++) + p = strchr(p + 1, ';'); + i += s->max_b_frames; + if (i <= 0 || i >= INT_MAX / sizeof(RateControlEntry)) return -1; - rcc->entry = av_mallocz(i*sizeof(RateControlEntry)); - rcc->num_entries= i; - - /* init all to skipped p frames (with b frames we might have a not encoded frame at the end FIXME) */ - for(i=0; inum_entries; i++){ - RateControlEntry *rce= &rcc->entry[i]; - rce->pict_type= rce->new_pict_type=AV_PICTURE_TYPE_P; - rce->qscale= rce->new_qscale=FF_QP2LAMBDA * 2; - rce->misc_bits= s->mb_num + 10; - rce->mb_var_sum= s->mb_num*100; + rcc->entry = av_mallocz(i * sizeof(RateControlEntry)); + rcc->num_entries = i; + + /* init all to skipped p frames + * (with b frames we might have a not encoded frame at the end FIXME) */ + for (i = 0; i < rcc->num_entries; i++) { + RateControlEntry *rce = &rcc->entry[i]; + + rce->pict_type = rce->new_pict_type = AV_PICTURE_TYPE_P; + rce->qscale = rce->new_qscale = FF_QP2LAMBDA * 2; + rce->misc_bits = s->mb_num + 10; + rce->mb_var_sum = s->mb_num * 100; } /* read stats */ - p= s->avctx->stats_in; - for(i=0; inum_entries - s->max_b_frames; i++){ + p = s->avctx->stats_in; + for (i = 0; i < rcc->num_entries - s->max_b_frames; i++) { RateControlEntry *rce; int picture_number; int e; char *next; - next= strchr(p, ';'); - if(next){ - (*next)=0; //sscanf in unbelievably slow on looong strings //FIXME copy / do not write + next = strchr(p, ';'); + if (next) { + (*next) = 0; // sscanf in unbelievably slow on looong strings // FIXME copy / do not write next++; } - e= sscanf(p, " in:%d ", &picture_number); + e = sscanf(p, " in:%d ", &picture_number); assert(picture_number >= 0); assert(picture_number < rcc->num_entries); - rce= &rcc->entry[picture_number]; - - e+=sscanf(p, " in:%*d out:%*d type:%d q:%f itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d", - &rce->pict_type, &rce->qscale, &rce->i_tex_bits, &rce->p_tex_bits, &rce->mv_bits, &rce->misc_bits, - &rce->f_code, &rce->b_code, &rce->mc_mb_var_sum, &rce->mb_var_sum, &rce->i_count, &rce->skip_count, &rce->header_bits); - if(e!=14){ - av_log(s->avctx, AV_LOG_ERROR, "statistics are damaged at line %d, parser out=%d\n", i, e); + rce = &rcc->entry[picture_number]; + + e += sscanf(p, " in:%*d out:%*d type:%d q:%f itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d", + &rce->pict_type, &rce->qscale, &rce->i_tex_bits, &rce->p_tex_bits, + &rce->mv_bits, &rce->misc_bits, + &rce->f_code, &rce->b_code, + &rce->mc_mb_var_sum, &rce->mb_var_sum, + &rce->i_count, &rce->skip_count, &rce->header_bits); + if (e != 14) { + av_log(s->avctx, AV_LOG_ERROR, + "statistics are damaged at line %d, parser out=%d\n", + i, e); return -1; } - p= next; + p = next; } - if(init_pass2(s) < 0) return -1; + if (init_pass2(s) < 0) + return -1; - //FIXME maybe move to end - if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) { + // FIXME maybe move to end + if ((s->flags & CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) { #if CONFIG_LIBXVID return ff_xvid_rate_control_init(s); #else - av_log(s->avctx, AV_LOG_ERROR, "Xvid ratecontrol requires libavcodec compiled with Xvid support.\n"); + av_log(s->avctx, AV_LOG_ERROR, + "Xvid ratecontrol requires libavcodec compiled with Xvid support.\n"); return -1; #endif } } - if(!(s->flags&CODEC_FLAG_PASS2)){ - - rcc->short_term_qsum=0.001; - rcc->short_term_qcount=0.001; + if (!(s->flags & CODEC_FLAG_PASS2)) { + rcc->short_term_qsum = 0.001; + rcc->short_term_qcount = 0.001; - rcc->pass1_rc_eq_output_sum= 0.001; - rcc->pass1_wanted_bits=0.001; + rcc->pass1_rc_eq_output_sum = 0.001; + rcc->pass1_wanted_bits = 0.001; - if(s->avctx->qblur > 1.0){ + if (s->avctx->qblur > 1.0) { av_log(s->avctx, AV_LOG_ERROR, "qblur too large\n"); return -1; } /* init stuff with the user specified complexity */ - if(s->avctx->rc_initial_cplx){ - for(i=0; i<60*30; i++){ - double bits= s->avctx->rc_initial_cplx * (i/10000.0 + 1.0)*s->mb_num; + if (s->avctx->rc_initial_cplx) { + for (i = 0; i < 60 * 30; i++) { + double bits = s->avctx->rc_initial_cplx * (i / 10000.0 + 1.0) * s->mb_num; RateControlEntry rce; - if (i%((s->gop_size+3)/4)==0) rce.pict_type= AV_PICTURE_TYPE_I; - else if(i%(s->max_b_frames+1)) rce.pict_type= AV_PICTURE_TYPE_B; - else rce.pict_type= AV_PICTURE_TYPE_P; - - rce.new_pict_type= rce.pict_type; - rce.mc_mb_var_sum= bits*s->mb_num/100000; - rce.mb_var_sum = s->mb_num; - rce.qscale = FF_QP2LAMBDA * 2; - rce.f_code = 2; - rce.b_code = 1; - rce.misc_bits= 1; - - if(s->pict_type== AV_PICTURE_TYPE_I){ - rce.i_count = s->mb_num; - rce.i_tex_bits= bits; - rce.p_tex_bits= 0; - rce.mv_bits= 0; - }else{ - rce.i_count = 0; //FIXME we do know this approx - rce.i_tex_bits= 0; - rce.p_tex_bits= bits*0.9; - rce.mv_bits= bits*0.1; + if (i % ((s->gop_size + 3) / 4) == 0) + rce.pict_type = AV_PICTURE_TYPE_I; + else if (i % (s->max_b_frames + 1)) + rce.pict_type = AV_PICTURE_TYPE_B; + else + rce.pict_type = AV_PICTURE_TYPE_P; + + rce.new_pict_type = rce.pict_type; + rce.mc_mb_var_sum = bits * s->mb_num / 100000; + rce.mb_var_sum = s->mb_num; + + rce.qscale = FF_QP2LAMBDA * 2; + rce.f_code = 2; + rce.b_code = 1; + rce.misc_bits = 1; + + if (s->pict_type == AV_PICTURE_TYPE_I) { + rce.i_count = s->mb_num; + rce.i_tex_bits = bits; + rce.p_tex_bits = 0; + rce.mv_bits = 0; + } else { + rce.i_count = 0; // FIXME we do know this approx + rce.i_tex_bits = 0; + rce.p_tex_bits = bits * 0.9; + rce.mv_bits = bits * 0.1; } - rcc->i_cplx_sum [rce.pict_type] += rce.i_tex_bits*rce.qscale; - rcc->p_cplx_sum [rce.pict_type] += rce.p_tex_bits*rce.qscale; + rcc->i_cplx_sum[rce.pict_type] += rce.i_tex_bits * rce.qscale; + rcc->p_cplx_sum[rce.pict_type] += rce.p_tex_bits * rce.qscale; rcc->mv_bits_sum[rce.pict_type] += rce.mv_bits; - rcc->frame_count[rce.pict_type] ++; + rcc->frame_count[rce.pict_type]++; + + get_qscale(s, &rce, rcc->pass1_wanted_bits / rcc->pass1_rc_eq_output_sum, i); - get_qscale(s, &rce, rcc->pass1_wanted_bits/rcc->pass1_rc_eq_output_sum, i); - rcc->pass1_wanted_bits+= s->bit_rate/get_fps(s->avctx); //FIXME misbehaves a little for variable fps + // FIXME misbehaves a little for variable fps + rcc->pass1_wanted_bits += s->bit_rate / get_fps(s->avctx); } } - } return 0; @@ -264,47 +298,49 @@ int ff_rate_control_init(MpegEncContext *s) void ff_rate_control_uninit(MpegEncContext *s) { - RateControlContext *rcc= &s->rc_context; + RateControlContext *rcc = &s->rc_context; emms_c(); av_expr_free(rcc->rc_eq_eval); av_freep(&rcc->entry); #if CONFIG_LIBXVID - if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) + if ((s->flags & CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) ff_xvid_rate_control_uninit(s); #endif } -int ff_vbv_update(MpegEncContext *s, int frame_size){ - RateControlContext *rcc= &s->rc_context; - const double fps= get_fps(s->avctx); - const int buffer_size= s->avctx->rc_buffer_size; - const double min_rate= s->avctx->rc_min_rate/fps; - const double max_rate= s->avctx->rc_max_rate/fps; +int ff_vbv_update(MpegEncContext *s, int frame_size) +{ + RateControlContext *rcc = &s->rc_context; + const double fps = get_fps(s->avctx); + const int buffer_size = s->avctx->rc_buffer_size; + const double min_rate = s->avctx->rc_min_rate / fps; + const double max_rate = s->avctx->rc_max_rate / fps; av_dlog(s, "%d %f %d %f %f\n", buffer_size, rcc->buffer_index, frame_size, min_rate, max_rate); - if(buffer_size){ + + if (buffer_size) { int left; - rcc->buffer_index-= frame_size; - if(rcc->buffer_index < 0){ + rcc->buffer_index -= frame_size; + if (rcc->buffer_index < 0) { av_log(s->avctx, AV_LOG_ERROR, "rc buffer underflow\n"); - rcc->buffer_index= 0; + rcc->buffer_index = 0; } - left= buffer_size - rcc->buffer_index - 1; + left = buffer_size - rcc->buffer_index - 1; rcc->buffer_index += av_clip(left, min_rate, max_rate); - if(rcc->buffer_index > buffer_size){ - int stuffing= ceil((rcc->buffer_index - buffer_size)/8); + if (rcc->buffer_index > buffer_size) { + int stuffing = ceil((rcc->buffer_index - buffer_size) / 8); - if(stuffing < 4 && s->codec_id == AV_CODEC_ID_MPEG4) - stuffing=4; - rcc->buffer_index -= 8*stuffing; + if (stuffing < 4 && s->codec_id == AV_CODEC_ID_MPEG4) + stuffing = 4; + rcc->buffer_index -= 8 * stuffing; - if(s->avctx->debug & FF_DEBUG_RC) + if (s->avctx->debug & FF_DEBUG_RC) av_log(s->avctx, AV_LOG_DEBUG, "stuffing %d bytes\n", stuffing); return stuffing; @@ -316,34 +352,38 @@ int ff_vbv_update(MpegEncContext *s, int frame_size){ /** * Modify the bitrate curve from pass1 for one frame. */ -static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num){ - RateControlContext *rcc= &s->rc_context; - AVCodecContext *a= s->avctx; +static double get_qscale(MpegEncContext *s, RateControlEntry *rce, + double rate_factor, int frame_num) +{ + RateControlContext *rcc = &s->rc_context; + AVCodecContext *a = s->avctx; + const int pict_type = rce->new_pict_type; + const double mb_num = s->mb_num; double q, bits; - const int pict_type= rce->new_pict_type; - const double mb_num= s->mb_num; int i; - double const_values[]={ + double const_values[] = { M_PI, M_E, - rce->i_tex_bits*rce->qscale, - rce->p_tex_bits*rce->qscale, - (rce->i_tex_bits + rce->p_tex_bits)*(double)rce->qscale, - rce->mv_bits/mb_num, - rce->pict_type == AV_PICTURE_TYPE_B ? (rce->f_code + rce->b_code)*0.5 : rce->f_code, - rce->i_count/mb_num, - rce->mc_mb_var_sum/mb_num, - rce->mb_var_sum/mb_num, + rce->i_tex_bits * rce->qscale, + rce->p_tex_bits * rce->qscale, + (rce->i_tex_bits + rce->p_tex_bits) * (double)rce->qscale, + rce->mv_bits / mb_num, + rce->pict_type == AV_PICTURE_TYPE_B ? (rce->f_code + rce->b_code) * 0.5 : rce->f_code, + rce->i_count / mb_num, + rce->mc_mb_var_sum / mb_num, + rce->mb_var_sum / mb_num, rce->pict_type == AV_PICTURE_TYPE_I, rce->pict_type == AV_PICTURE_TYPE_P, rce->pict_type == AV_PICTURE_TYPE_B, rcc->qscale_sum[pict_type] / (double)rcc->frame_count[pict_type], a->qcompress, -/* rcc->last_qscale_for[AV_PICTURE_TYPE_I], +#if 0 + rcc->last_qscale_for[AV_PICTURE_TYPE_I], rcc->last_qscale_for[AV_PICTURE_TYPE_P], rcc->last_qscale_for[AV_PICTURE_TYPE_B], - rcc->next_non_b_qscale,*/ + rcc->next_non_b_qscale, +#endif rcc->i_cplx_sum[AV_PICTURE_TYPE_I] / (double)rcc->frame_count[AV_PICTURE_TYPE_I], rcc->i_cplx_sum[AV_PICTURE_TYPE_P] / (double)rcc->frame_count[AV_PICTURE_TYPE_P], rcc->p_cplx_sum[AV_PICTURE_TYPE_P] / (double)rcc->frame_count[AV_PICTURE_TYPE_P], @@ -358,61 +398,71 @@ static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_f return -1; } - rcc->pass1_rc_eq_output_sum+= bits; - bits*=rate_factor; - if(bits<0.0) bits=0.0; - bits+= 1.0; //avoid 1/0 issues + rcc->pass1_rc_eq_output_sum += bits; + bits *= rate_factor; + if (bits < 0.0) + bits = 0.0; + bits += 1.0; // avoid 1/0 issues /* user override */ - for(i=0; iavctx->rc_override_count; i++){ - RcOverride *rco= s->avctx->rc_override; - if(rco[i].start_frame > frame_num) continue; - if(rco[i].end_frame < frame_num) continue; - - if(rco[i].qscale) - bits= qp2bits(rce, rco[i].qscale); //FIXME move at end to really force it? + for (i = 0; i < s->avctx->rc_override_count; i++) { + RcOverride *rco = s->avctx->rc_override; + if (rco[i].start_frame > frame_num) + continue; + if (rco[i].end_frame < frame_num) + continue; + + if (rco[i].qscale) + bits = qp2bits(rce, rco[i].qscale); // FIXME move at end to really force it? else - bits*= rco[i].quality_factor; + bits *= rco[i].quality_factor; } - q= bits2qp(rce, bits); + q = bits2qp(rce, bits); /* I/B difference */ - if (pict_type==AV_PICTURE_TYPE_I && s->avctx->i_quant_factor<0.0) - q= -q*s->avctx->i_quant_factor + s->avctx->i_quant_offset; - else if(pict_type==AV_PICTURE_TYPE_B && s->avctx->b_quant_factor<0.0) - q= -q*s->avctx->b_quant_factor + s->avctx->b_quant_offset; - if(q<1) q=1; + if (pict_type == AV_PICTURE_TYPE_I && s->avctx->i_quant_factor < 0.0) + q = -q * s->avctx->i_quant_factor + s->avctx->i_quant_offset; + else if (pict_type == AV_PICTURE_TYPE_B && s->avctx->b_quant_factor < 0.0) + q = -q * s->avctx->b_quant_factor + s->avctx->b_quant_offset; + if (q < 1) + q = 1; return q; } -static double get_diff_limited_q(MpegEncContext *s, RateControlEntry *rce, double q){ - RateControlContext *rcc= &s->rc_context; - AVCodecContext *a= s->avctx; - const int pict_type= rce->new_pict_type; - const double last_p_q = rcc->last_qscale_for[AV_PICTURE_TYPE_P]; - const double last_non_b_q= rcc->last_qscale_for[rcc->last_non_b_pict_type]; - - if (pict_type==AV_PICTURE_TYPE_I && (a->i_quant_factor>0.0 || rcc->last_non_b_pict_type==AV_PICTURE_TYPE_P)) - q= last_p_q *FFABS(a->i_quant_factor) + a->i_quant_offset; - else if(pict_type==AV_PICTURE_TYPE_B && a->b_quant_factor>0.0) - q= last_non_b_q* a->b_quant_factor + a->b_quant_offset; - if(q<1) q=1; +static double get_diff_limited_q(MpegEncContext *s, RateControlEntry *rce, double q) +{ + RateControlContext *rcc = &s->rc_context; + AVCodecContext *a = s->avctx; + const int pict_type = rce->new_pict_type; + const double last_p_q = rcc->last_qscale_for[AV_PICTURE_TYPE_P]; + const double last_non_b_q = rcc->last_qscale_for[rcc->last_non_b_pict_type]; + + if (pict_type == AV_PICTURE_TYPE_I && + (a->i_quant_factor > 0.0 || rcc->last_non_b_pict_type == AV_PICTURE_TYPE_P)) + q = last_p_q * FFABS(a->i_quant_factor) + a->i_quant_offset; + else if (pict_type == AV_PICTURE_TYPE_B && + a->b_quant_factor > 0.0) + q = last_non_b_q * a->b_quant_factor + a->b_quant_offset; + if (q < 1) + q = 1; /* last qscale / qdiff stuff */ - if(rcc->last_non_b_pict_type==pict_type || pict_type!=AV_PICTURE_TYPE_I){ - double last_q= rcc->last_qscale_for[pict_type]; - const int maxdiff= FF_QP2LAMBDA * a->max_qdiff; - - if (q > last_q + maxdiff) q= last_q + maxdiff; - else if(q < last_q - maxdiff) q= last_q - maxdiff; + if (rcc->last_non_b_pict_type == pict_type || pict_type != AV_PICTURE_TYPE_I) { + double last_q = rcc->last_qscale_for[pict_type]; + const int maxdiff = FF_QP2LAMBDA * a->max_qdiff; + + if (q > last_q + maxdiff) + q = last_q + maxdiff; + else if (q < last_q - maxdiff) + q = last_q - maxdiff; } - rcc->last_qscale_for[pict_type]= q; //Note we cannot do that after blurring + rcc->last_qscale_for[pict_type] = q; // Note we cannot do that after blurring - if(pict_type!=AV_PICTURE_TYPE_B) - rcc->last_non_b_pict_type= pict_type; + if (pict_type != AV_PICTURE_TYPE_B) + rcc->last_non_b_pict_type = pict_type; return q; } @@ -420,239 +470,269 @@ static double get_diff_limited_q(MpegEncContext *s, RateControlEntry *rce, doubl /** * Get the qmin & qmax for pict_type. */ -static void get_qminmax(int *qmin_ret, int *qmax_ret, MpegEncContext *s, int pict_type){ - int qmin= s->avctx->lmin; - int qmax= s->avctx->lmax; +static void get_qminmax(int *qmin_ret, int *qmax_ret, MpegEncContext *s, int pict_type) +{ + int qmin = s->avctx->lmin; + int qmax = s->avctx->lmax; assert(qmin <= qmax); - if(pict_type==AV_PICTURE_TYPE_B){ - qmin= (int)(qmin*FFABS(s->avctx->b_quant_factor)+s->avctx->b_quant_offset + 0.5); - qmax= (int)(qmax*FFABS(s->avctx->b_quant_factor)+s->avctx->b_quant_offset + 0.5); - }else if(pict_type==AV_PICTURE_TYPE_I){ - qmin= (int)(qmin*FFABS(s->avctx->i_quant_factor)+s->avctx->i_quant_offset + 0.5); - qmax= (int)(qmax*FFABS(s->avctx->i_quant_factor)+s->avctx->i_quant_offset + 0.5); + switch (pict_type) { + case AV_PICTURE_TYPE_B: + qmin = (int)(qmin * FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset + 0.5); + qmax = (int)(qmax * FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset + 0.5); + break; + case AV_PICTURE_TYPE_I: + qmin = (int)(qmin * FFABS(s->avctx->i_quant_factor) + s->avctx->i_quant_offset + 0.5); + qmax = (int)(qmax * FFABS(s->avctx->i_quant_factor) + s->avctx->i_quant_offset + 0.5); + break; } - qmin= av_clip(qmin, 1, FF_LAMBDA_MAX); - qmax= av_clip(qmax, 1, FF_LAMBDA_MAX); + qmin = av_clip(qmin, 1, FF_LAMBDA_MAX); + qmax = av_clip(qmax, 1, FF_LAMBDA_MAX); - if(qmaxrc_context; +static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, + double q, int frame_num) +{ + RateControlContext *rcc = &s->rc_context; + const double buffer_size = s->avctx->rc_buffer_size; + const double fps = get_fps(s->avctx); + const double min_rate = s->avctx->rc_min_rate / fps; + const double max_rate = s->avctx->rc_max_rate / fps; + const int pict_type = rce->new_pict_type; int qmin, qmax; - const int pict_type= rce->new_pict_type; - const double buffer_size= s->avctx->rc_buffer_size; - const double fps= get_fps(s->avctx); - const double min_rate= s->avctx->rc_min_rate / fps; - const double max_rate= s->avctx->rc_max_rate / fps; get_qminmax(&qmin, &qmax, s, pict_type); /* modulation */ - if(s->avctx->rc_qmod_freq && frame_num%s->avctx->rc_qmod_freq==0 && pict_type==AV_PICTURE_TYPE_P) - q*= s->avctx->rc_qmod_amp; + if (s->avctx->rc_qmod_freq && + frame_num % s->avctx->rc_qmod_freq == 0 && + pict_type == AV_PICTURE_TYPE_P) + q *= s->avctx->rc_qmod_amp; /* buffer overflow/underflow protection */ - if(buffer_size){ - double expected_size= rcc->buffer_index; + if (buffer_size) { + double expected_size = rcc->buffer_index; double q_limit; - if(min_rate){ - double d= 2*(buffer_size - expected_size)/buffer_size; - if(d>1.0) d=1.0; - else if(d<0.0001) d=0.0001; - q*= pow(d, 1.0/s->avctx->rc_buffer_aggressivity); - - q_limit= bits2qp(rce, FFMAX((min_rate - buffer_size + rcc->buffer_index) * s->avctx->rc_min_vbv_overflow_use, 1)); - if(q > q_limit){ - if(s->avctx->debug&FF_DEBUG_RC){ - av_log(s->avctx, AV_LOG_DEBUG, "limiting QP %f -> %f\n", q, q_limit); - } - q= q_limit; + if (min_rate) { + double d = 2 * (buffer_size - expected_size) / buffer_size; + if (d > 1.0) + d = 1.0; + else if (d < 0.0001) + d = 0.0001; + q *= pow(d, 1.0 / s->avctx->rc_buffer_aggressivity); + + q_limit = bits2qp(rce, + FFMAX((min_rate - buffer_size + rcc->buffer_index) * + s->avctx->rc_min_vbv_overflow_use, 1)); + + if (q > q_limit) { + if (s->avctx->debug & FF_DEBUG_RC) + av_log(s->avctx, AV_LOG_DEBUG, + "limiting QP %f -> %f\n", q, q_limit); + q = q_limit; } } - if(max_rate){ - double d= 2*expected_size/buffer_size; - if(d>1.0) d=1.0; - else if(d<0.0001) d=0.0001; - q/= pow(d, 1.0/s->avctx->rc_buffer_aggressivity); - - q_limit= bits2qp(rce, FFMAX(rcc->buffer_index * s->avctx->rc_max_available_vbv_use, 1)); - if(q < q_limit){ - if(s->avctx->debug&FF_DEBUG_RC){ - av_log(s->avctx, AV_LOG_DEBUG, "limiting QP %f -> %f\n", q, q_limit); - } - q= q_limit; + if (max_rate) { + double d = 2 * expected_size / buffer_size; + if (d > 1.0) + d = 1.0; + else if (d < 0.0001) + d = 0.0001; + q /= pow(d, 1.0 / s->avctx->rc_buffer_aggressivity); + + q_limit = bits2qp(rce, + FFMAX(rcc->buffer_index * + s->avctx->rc_max_available_vbv_use, + 1)); + if (q < q_limit) { + if (s->avctx->debug & FF_DEBUG_RC) + av_log(s->avctx, AV_LOG_DEBUG, + "limiting QP %f -> %f\n", q, q_limit); + q = q_limit; } } } av_dlog(s, "q:%f max:%f min:%f size:%f index:%f agr:%f\n", q, max_rate, min_rate, buffer_size, rcc->buffer_index, s->avctx->rc_buffer_aggressivity); - if(s->avctx->rc_qsquish==0.0 || qmin==qmax){ - if (qqmax) q=qmax; - }else{ - double min2= log(qmin); - double max2= log(qmax); - - q= log(q); - q= (q - min2)/(max2-min2) - 0.5; - q*= -4.0; - q= 1.0/(1.0 + exp(q)); - q= q*(max2-min2) + min2; - - q= exp(q); + if (s->avctx->rc_qsquish == 0.0 || qmin == qmax) { + if (q < qmin) + q = qmin; + else if (q > qmax) + q = qmax; + } else { + double min2 = log(qmin); + double max2 = log(qmax); + + q = log(q); + q = (q - min2) / (max2 - min2) - 0.5; + q *= -4.0; + q = 1.0 / (1.0 + exp(q)); + q = q * (max2 - min2) + min2; + + q = exp(q); } return q; } -//---------------------------------- +// ---------------------------------- // 1 Pass Code static double predict_size(Predictor *p, double q, double var) { - return p->coeff*var / (q*p->count); + return p->coeff * var / (q * p->count); } static void update_predictor(Predictor *p, double q, double var, double size) { - double new_coeff= size*q / (var + 1); - if(var<10) return; + double new_coeff = size * q / (var + 1); + if (var < 10) + return; - p->count*= p->decay; - p->coeff*= p->decay; + p->count *= p->decay; + p->coeff *= p->decay; p->count++; - p->coeff+= new_coeff; + p->coeff += new_coeff; } -static void adaptive_quantization(MpegEncContext *s, double q){ +static void adaptive_quantization(MpegEncContext *s, double q) +{ int i; - const float lumi_masking= s->avctx->lumi_masking / (128.0*128.0); - const float dark_masking= s->avctx->dark_masking / (128.0*128.0); - const float temp_cplx_masking= s->avctx->temporal_cplx_masking; + const float lumi_masking = s->avctx->lumi_masking / (128.0 * 128.0); + const float dark_masking = s->avctx->dark_masking / (128.0 * 128.0); + const float temp_cplx_masking = s->avctx->temporal_cplx_masking; const float spatial_cplx_masking = s->avctx->spatial_cplx_masking; - const float p_masking = s->avctx->p_masking; - const float border_masking = s->avctx->border_masking; - float bits_sum= 0.0; - float cplx_sum= 0.0; - float *cplx_tab = s->cplx_tab; - float *bits_tab = s->bits_tab; - const int qmin= s->avctx->mb_lmin; - const int qmax= s->avctx->mb_lmax; - Picture * const pic= &s->current_picture; - const int mb_width = s->mb_width; - const int mb_height = s->mb_height; - - for(i=0; imb_num; i++){ - const int mb_xy= s->mb_index2xy[i]; - float temp_cplx= sqrt(pic->mc_mb_var[mb_xy]); //FIXME merge in pow() - float spat_cplx= sqrt(pic->mb_var[mb_xy]); - const int lumi= pic->mb_mean[mb_xy]; + const float p_masking = s->avctx->p_masking; + const float border_masking = s->avctx->border_masking; + float bits_sum = 0.0; + float cplx_sum = 0.0; + float *cplx_tab = s->cplx_tab; + float *bits_tab = s->bits_tab; + const int qmin = s->avctx->mb_lmin; + const int qmax = s->avctx->mb_lmax; + Picture *const pic = &s->current_picture; + const int mb_width = s->mb_width; + const int mb_height = s->mb_height; + + for (i = 0; i < s->mb_num; i++) { + const int mb_xy = s->mb_index2xy[i]; + float temp_cplx = sqrt(pic->mc_mb_var[mb_xy]); // FIXME merge in pow() + float spat_cplx = sqrt(pic->mb_var[mb_xy]); + const int lumi = pic->mb_mean[mb_xy]; float bits, cplx, factor; int mb_x = mb_xy % s->mb_stride; int mb_y = mb_xy / s->mb_stride; int mb_distance; float mb_factor = 0.0; - if(spat_cplx < 4) spat_cplx= 4; //FIXME finetune - if(temp_cplx < 4) temp_cplx= 4; //FIXME finetune - - if((s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_INTRA)){//FIXME hq mode - cplx= spat_cplx; - factor= 1.0 + p_masking; - }else{ - cplx= temp_cplx; - factor= pow(temp_cplx, - temp_cplx_masking); + if (spat_cplx < 4) + spat_cplx = 4; // FIXME finetune + if (temp_cplx < 4) + temp_cplx = 4; // FIXME finetune + + if ((s->mb_type[mb_xy] & CANDIDATE_MB_TYPE_INTRA)) { // FIXME hq mode + cplx = spat_cplx; + factor = 1.0 + p_masking; + } else { + cplx = temp_cplx; + factor = pow(temp_cplx, -temp_cplx_masking); } - factor*=pow(spat_cplx, - spatial_cplx_masking); + factor *= pow(spat_cplx, -spatial_cplx_masking); - if(lumi>127) - factor*= (1.0 - (lumi-128)*(lumi-128)*lumi_masking); + if (lumi > 127) + factor *= (1.0 - (lumi - 128) * (lumi - 128) * lumi_masking); else - factor*= (1.0 - (lumi-128)*(lumi-128)*dark_masking); - - if(mb_x < mb_width/5){ - mb_distance = mb_width/5 - mb_x; - mb_factor = (float)mb_distance / (float)(mb_width/5); - }else if(mb_x > 4*mb_width/5){ - mb_distance = mb_x - 4*mb_width/5; - mb_factor = (float)mb_distance / (float)(mb_width/5); + factor *= (1.0 - (lumi - 128) * (lumi - 128) * dark_masking); + + if (mb_x < mb_width / 5) { + mb_distance = mb_width / 5 - mb_x; + mb_factor = (float)mb_distance / (float)(mb_width / 5); + } else if (mb_x > 4 * mb_width / 5) { + mb_distance = mb_x - 4 * mb_width / 5; + mb_factor = (float)mb_distance / (float)(mb_width / 5); } - if(mb_y < mb_height/5){ - mb_distance = mb_height/5 - mb_y; - mb_factor = FFMAX(mb_factor, (float)mb_distance / (float)(mb_height/5)); - }else if(mb_y > 4*mb_height/5){ - mb_distance = mb_y - 4*mb_height/5; - mb_factor = FFMAX(mb_factor, (float)mb_distance / (float)(mb_height/5)); + if (mb_y < mb_height / 5) { + mb_distance = mb_height / 5 - mb_y; + mb_factor = FFMAX(mb_factor, + (float)mb_distance / (float)(mb_height / 5)); + } else if (mb_y > 4 * mb_height / 5) { + mb_distance = mb_y - 4 * mb_height / 5; + mb_factor = FFMAX(mb_factor, + (float)mb_distance / (float)(mb_height / 5)); } - factor*= 1.0 - border_masking*mb_factor; + factor *= 1.0 - border_masking * mb_factor; - if(factor<0.00001) factor= 0.00001; + if (factor < 0.00001) + factor = 0.00001; - bits= cplx*factor; - cplx_sum+= cplx; - bits_sum+= bits; - cplx_tab[i]= cplx; - bits_tab[i]= bits; + bits = cplx * factor; + cplx_sum += cplx; + bits_sum += bits; + cplx_tab[i] = cplx; + bits_tab[i] = bits; } /* handle qmin/qmax clipping */ - if(s->flags&CODEC_FLAG_NORMALIZE_AQP){ - float factor= bits_sum/cplx_sum; - for(i=0; imb_num; i++){ - float newq= q*cplx_tab[i]/bits_tab[i]; - newq*= factor; + if (s->flags & CODEC_FLAG_NORMALIZE_AQP) { + float factor = bits_sum / cplx_sum; + for (i = 0; i < s->mb_num; i++) { + float newq = q * cplx_tab[i] / bits_tab[i]; + newq *= factor; - if (newq > qmax){ + if (newq > qmax) { bits_sum -= bits_tab[i]; - cplx_sum -= cplx_tab[i]*q/qmax; - } - else if(newq < qmin){ + cplx_sum -= cplx_tab[i] * q / qmax; + } else if (newq < qmin) { bits_sum -= bits_tab[i]; - cplx_sum -= cplx_tab[i]*q/qmin; + cplx_sum -= cplx_tab[i] * q / qmin; } } - if(bits_sum < 0.001) bits_sum= 0.001; - if(cplx_sum < 0.001) cplx_sum= 0.001; + if (bits_sum < 0.001) + bits_sum = 0.001; + if (cplx_sum < 0.001) + cplx_sum = 0.001; } - for(i=0; imb_num; i++){ - const int mb_xy= s->mb_index2xy[i]; - float newq= q*cplx_tab[i]/bits_tab[i]; + for (i = 0; i < s->mb_num; i++) { + const int mb_xy = s->mb_index2xy[i]; + float newq = q * cplx_tab[i] / bits_tab[i]; int intq; - if(s->flags&CODEC_FLAG_NORMALIZE_AQP){ - newq*= bits_sum/cplx_sum; + if (s->flags & CODEC_FLAG_NORMALIZE_AQP) { + newq *= bits_sum / cplx_sum; } - intq= (int)(newq + 0.5); + intq = (int)(newq + 0.5); - if (intq > qmax) intq= qmax; - else if(intq < qmin) intq= qmin; - s->lambda_table[mb_xy]= intq; + if (intq > qmax) + intq = qmax; + else if (intq < qmin) + intq = qmin; + s->lambda_table[mb_xy] = intq; } } -void ff_get_2pass_fcode(MpegEncContext *s){ - RateControlContext *rcc= &s->rc_context; - int picture_number= s->picture_number; - RateControlEntry *rce; +void ff_get_2pass_fcode(MpegEncContext *s) +{ + RateControlContext *rcc = &s->rc_context; + RateControlEntry *rce = &rcc->entry[s->picture_number]; - rce= &rcc->entry[picture_number]; - s->f_code= rce->f_code; - s->b_code= rce->b_code; + s->f_code = rce->f_code; + s->b_code = rce->b_code; } -//FIXME rd or at least approx for dquant +// FIXME rd or at least approx for dquant float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run) { @@ -662,259 +742,283 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run) double diff; double short_term_q; double fps; - int picture_number= s->picture_number; + int picture_number = s->picture_number; int64_t wanted_bits; - RateControlContext *rcc= &s->rc_context; - AVCodecContext *a= s->avctx; + RateControlContext *rcc = &s->rc_context; + AVCodecContext *a = s->avctx; RateControlEntry local_rce, *rce; double bits; double rate_factor; int var; - const int pict_type= s->pict_type; - Picture * const pic= &s->current_picture; + const int pict_type = s->pict_type; + Picture * const pic = &s->current_picture; emms_c(); #if CONFIG_LIBXVID - if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) + if ((s->flags & CODEC_FLAG_PASS2) && + s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) return ff_xvid_rate_estimate_qscale(s, dry_run); #endif get_qminmax(&qmin, &qmax, s, pict_type); - fps= get_fps(s->avctx); - /* update predictors */ - if(picture_number>2 && !dry_run){ - const int last_var= s->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum : rcc->last_mc_mb_var_sum; + fps = get_fps(s->avctx); + /* update predictors */ + if (picture_number > 2 && !dry_run) { + const int last_var = s->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum + : rcc->last_mc_mb_var_sum; av_assert1(s->frame_bits >= s->stuffing_bits); - update_predictor(&rcc->pred[s->last_pict_type], rcc->last_qscale, sqrt(last_var), s->frame_bits - s->stuffing_bits); + update_predictor(&rcc->pred[s->last_pict_type], + rcc->last_qscale, + sqrt(last_var), + s->frame_bits - s->stuffing_bits); } - if(s->flags&CODEC_FLAG_PASS2){ - assert(picture_number>=0); - if(picture_number >= rcc->num_entries) { + if (s->flags & CODEC_FLAG_PASS2) { + assert(picture_number >= 0); + if (picture_number >= rcc->num_entries) { av_log(s, AV_LOG_ERROR, "Input is longer than 2-pass log file\n"); return -1; } - rce= &rcc->entry[picture_number]; - wanted_bits= rce->expected_bits; - }else{ + rce = &rcc->entry[picture_number]; + wanted_bits = rce->expected_bits; + } else { Picture *dts_pic; - rce= &local_rce; + rce = &local_rce; - //FIXME add a dts field to AVFrame and ensure its set and use it here instead of reordering - //but the reordering is simpler for now until h.264 b pyramid must be handeld - if(s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) - dts_pic= s->current_picture_ptr; + /* FIXME add a dts field to AVFrame and ensure it is set and use it + * here instead of reordering but the reordering is simpler for now + * until H.264 B-pyramid must be handled. */ + if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) + dts_pic = s->current_picture_ptr; else - dts_pic= s->last_picture_ptr; + dts_pic = s->last_picture_ptr; if (!dts_pic || dts_pic->f.pts == AV_NOPTS_VALUE) - wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps); + wanted_bits = (uint64_t)(s->bit_rate * (double)picture_number / fps); else - wanted_bits = (uint64_t)(s->bit_rate*(double)dts_pic->f.pts / fps); + wanted_bits = (uint64_t)(s->bit_rate * (double)dts_pic->f.pts / fps); } - diff= s->total_bits - wanted_bits; - br_compensation= (a->bit_rate_tolerance - diff)/a->bit_rate_tolerance; - if(br_compensation<=0.0) br_compensation=0.001; + diff = s->total_bits - wanted_bits; + br_compensation = (a->bit_rate_tolerance - diff) / a->bit_rate_tolerance; + if (br_compensation <= 0.0) + br_compensation = 0.001; - var= pict_type == AV_PICTURE_TYPE_I ? pic->mb_var_sum : pic->mc_mb_var_sum; + var = pict_type == AV_PICTURE_TYPE_I ? pic->mb_var_sum : pic->mc_mb_var_sum; short_term_q = 0; /* avoid warning */ - if(s->flags&CODEC_FLAG_PASS2){ - if(pict_type!=AV_PICTURE_TYPE_I) + if (s->flags & CODEC_FLAG_PASS2) { + if (pict_type != AV_PICTURE_TYPE_I) assert(pict_type == rce->new_pict_type); - q= rce->new_qscale / br_compensation; + q = rce->new_qscale / br_compensation; av_dlog(s, "%f %f %f last:%d var:%d type:%d//\n", q, rce->new_qscale, br_compensation, s->frame_bits, var, pict_type); - }else{ - rce->pict_type= - rce->new_pict_type= pict_type; - rce->mc_mb_var_sum= pic->mc_mb_var_sum; - rce->mb_var_sum = pic-> mb_var_sum; - rce->qscale = FF_QP2LAMBDA * 2; - rce->f_code = s->f_code; - rce->b_code = s->b_code; - rce->misc_bits= 1; - - bits= predict_size(&rcc->pred[pict_type], rce->qscale, sqrt(var)); - if(pict_type== AV_PICTURE_TYPE_I){ - rce->i_count = s->mb_num; - rce->i_tex_bits= bits; - rce->p_tex_bits= 0; - rce->mv_bits= 0; - }else{ - rce->i_count = 0; //FIXME we do know this approx - rce->i_tex_bits= 0; - rce->p_tex_bits= bits*0.9; - - rce->mv_bits= bits*0.1; + } else { + rce->pict_type = + rce->new_pict_type = pict_type; + rce->mc_mb_var_sum = pic->mc_mb_var_sum; + rce->mb_var_sum = pic->mb_var_sum; + rce->qscale = FF_QP2LAMBDA * 2; + rce->f_code = s->f_code; + rce->b_code = s->b_code; + rce->misc_bits = 1; + + bits = predict_size(&rcc->pred[pict_type], rce->qscale, sqrt(var)); + if (pict_type == AV_PICTURE_TYPE_I) { + rce->i_count = s->mb_num; + rce->i_tex_bits = bits; + rce->p_tex_bits = 0; + rce->mv_bits = 0; + } else { + rce->i_count = 0; // FIXME we do know this approx + rce->i_tex_bits = 0; + rce->p_tex_bits = bits * 0.9; + rce->mv_bits = bits * 0.1; } - rcc->i_cplx_sum [pict_type] += rce->i_tex_bits*rce->qscale; - rcc->p_cplx_sum [pict_type] += rce->p_tex_bits*rce->qscale; + rcc->i_cplx_sum[pict_type] += rce->i_tex_bits * rce->qscale; + rcc->p_cplx_sum[pict_type] += rce->p_tex_bits * rce->qscale; rcc->mv_bits_sum[pict_type] += rce->mv_bits; - rcc->frame_count[pict_type] ++; + rcc->frame_count[pict_type]++; - bits= rce->i_tex_bits + rce->p_tex_bits; - rate_factor= rcc->pass1_wanted_bits/rcc->pass1_rc_eq_output_sum * br_compensation; + bits = rce->i_tex_bits + rce->p_tex_bits; + rate_factor = rcc->pass1_wanted_bits / + rcc->pass1_rc_eq_output_sum * br_compensation; - q= get_qscale(s, rce, rate_factor, picture_number); + q = get_qscale(s, rce, rate_factor, picture_number); if (q < 0) return -1; - assert(q>0.0); - q= get_diff_limited_q(s, rce, q); - assert(q>0.0); + assert(q > 0.0); + q = get_diff_limited_q(s, rce, q); + assert(q > 0.0); - if(pict_type==AV_PICTURE_TYPE_P || s->intra_only){ //FIXME type dependent blur like in 2-pass - rcc->short_term_qsum*=a->qblur; - rcc->short_term_qcount*=a->qblur; + // FIXME type dependent blur like in 2-pass + if (pict_type == AV_PICTURE_TYPE_P || s->intra_only) { + rcc->short_term_qsum *= a->qblur; + rcc->short_term_qcount *= a->qblur; - rcc->short_term_qsum+= q; + rcc->short_term_qsum += q; rcc->short_term_qcount++; - q= short_term_q= rcc->short_term_qsum/rcc->short_term_qcount; + q = short_term_q = rcc->short_term_qsum / rcc->short_term_qcount; } - assert(q>0.0); + assert(q > 0.0); - q= modify_qscale(s, rce, q, picture_number); + q = modify_qscale(s, rce, q, picture_number); - rcc->pass1_wanted_bits+= s->bit_rate/fps; + rcc->pass1_wanted_bits += s->bit_rate / fps; - assert(q>0.0); + assert(q > 0.0); } - if(s->avctx->debug&FF_DEBUG_RC){ - av_log(s->avctx, AV_LOG_DEBUG, "%c qp:%d<%2.1f<%d %d want:%d total:%d comp:%f st_q:%2.2f size:%d var:%d/%d br:%d fps:%d\n", - av_get_picture_type_char(pict_type), qmin, q, qmax, picture_number, (int)wanted_bits/1000, (int)s->total_bits/1000, - br_compensation, short_term_q, s->frame_bits, pic->mb_var_sum, pic->mc_mb_var_sum, s->bit_rate/1000, (int)fps - ); + if (s->avctx->debug & FF_DEBUG_RC) { + av_log(s->avctx, AV_LOG_DEBUG, + "%c qp:%d<%2.1f<%d %d want:%d total:%d comp:%f st_q:%2.2f " + "size:%d var:%d/%d br:%d fps:%d\n", + av_get_picture_type_char(pict_type), + qmin, q, qmax, picture_number, + (int)wanted_bits / 1000, (int)s->total_bits / 1000, + br_compensation, short_term_q, s->frame_bits, + pic->mb_var_sum, pic->mc_mb_var_sum, + s->bit_rate / 1000, (int)fps); } - if (qqmax) q=qmax; + if (q < qmin) + q = qmin; + else if (q > qmax) + q = qmax; - if(s->adaptive_quant) + if (s->adaptive_quant) adaptive_quantization(s, q); else - q= (int)(q + 0.5); + q = (int)(q + 0.5); - if(!dry_run){ - rcc->last_qscale= q; - rcc->last_mc_mb_var_sum= pic->mc_mb_var_sum; - rcc->last_mb_var_sum= pic->mb_var_sum; + if (!dry_run) { + rcc->last_qscale = q; + rcc->last_mc_mb_var_sum = pic->mc_mb_var_sum; + rcc->last_mb_var_sum = pic->mb_var_sum; } return q; } -//---------------------------------------------- +// ---------------------------------------------- // 2-Pass code static int init_pass2(MpegEncContext *s) { - RateControlContext *rcc= &s->rc_context; - AVCodecContext *a= s->avctx; + RateControlContext *rcc = &s->rc_context; + AVCodecContext *a = s->avctx; int i, toobig; - double fps= get_fps(s->avctx); - double complexity[5]={0,0,0,0,0}; // approximate bits at quant=1 - uint64_t const_bits[5]={0,0,0,0,0}; // quantizer independent bits + double fps = get_fps(s->avctx); + double complexity[5] = { 0 }; // approximate bits at quant=1 + uint64_t const_bits[5] = { 0 }; // quantizer independent bits uint64_t all_const_bits; - uint64_t all_available_bits= (uint64_t)(s->bit_rate*(double)rcc->num_entries/fps); - double rate_factor=0; + uint64_t all_available_bits = (uint64_t)(s->bit_rate * + (double)rcc->num_entries / fps); + double rate_factor = 0; double step; - //int last_i_frame=-10000000; - const int filter_size= (int)(a->qblur*4) | 1; + const int filter_size = (int)(a->qblur * 4) | 1; double expected_bits; double *qscale, *blurred_qscale, qscale_sum; /* find complexity & const_bits & decide the pict_types */ - for(i=0; inum_entries; i++){ - RateControlEntry *rce= &rcc->entry[i]; + for (i = 0; i < rcc->num_entries; i++) { + RateControlEntry *rce = &rcc->entry[i]; - rce->new_pict_type= rce->pict_type; - rcc->i_cplx_sum [rce->pict_type] += rce->i_tex_bits*rce->qscale; - rcc->p_cplx_sum [rce->pict_type] += rce->p_tex_bits*rce->qscale; + rce->new_pict_type = rce->pict_type; + rcc->i_cplx_sum[rce->pict_type] += rce->i_tex_bits * rce->qscale; + rcc->p_cplx_sum[rce->pict_type] += rce->p_tex_bits * rce->qscale; rcc->mv_bits_sum[rce->pict_type] += rce->mv_bits; - rcc->frame_count[rce->pict_type] ++; + rcc->frame_count[rce->pict_type]++; - complexity[rce->new_pict_type]+= (rce->i_tex_bits+ rce->p_tex_bits)*(double)rce->qscale; - const_bits[rce->new_pict_type]+= rce->mv_bits + rce->misc_bits; + complexity[rce->new_pict_type] += (rce->i_tex_bits + rce->p_tex_bits) * + (double)rce->qscale; + const_bits[rce->new_pict_type] += rce->mv_bits + rce->misc_bits; } - all_const_bits= const_bits[AV_PICTURE_TYPE_I] + const_bits[AV_PICTURE_TYPE_P] + const_bits[AV_PICTURE_TYPE_B]; - if(all_available_bits < all_const_bits){ + all_const_bits = const_bits[AV_PICTURE_TYPE_I] + + const_bits[AV_PICTURE_TYPE_P] + + const_bits[AV_PICTURE_TYPE_B]; + + if (all_available_bits < all_const_bits) { av_log(s->avctx, AV_LOG_ERROR, "requested bitrate is too low\n"); return -1; } - qscale= av_malloc(sizeof(double)*rcc->num_entries); - blurred_qscale= av_malloc(sizeof(double)*rcc->num_entries); + qscale = av_malloc(sizeof(double) * rcc->num_entries); + blurred_qscale = av_malloc(sizeof(double) * rcc->num_entries); toobig = 0; - for(step=256*256; step>0.0000001; step*=0.5){ - expected_bits=0; - rate_factor+= step; + for (step = 256 * 256; step > 0.0000001; step *= 0.5) { + expected_bits = 0; + rate_factor += step; - rcc->buffer_index= s->avctx->rc_buffer_size/2; + rcc->buffer_index = s->avctx->rc_buffer_size / 2; /* find qscale */ - for(i=0; inum_entries; i++){ - RateControlEntry *rce= &rcc->entry[i]; - qscale[i]= get_qscale(s, &rcc->entry[i], rate_factor, i); + for (i = 0; i < rcc->num_entries; i++) { + RateControlEntry *rce = &rcc->entry[i]; + + qscale[i] = get_qscale(s, &rcc->entry[i], rate_factor, i); rcc->last_qscale_for[rce->pict_type] = qscale[i]; } - assert(filter_size%2==1); + assert(filter_size % 2 == 1); /* fixed I/B QP relative to P mode */ - for(i=FFMAX(0, rcc->num_entries-300); inum_entries; i++){ - RateControlEntry *rce= &rcc->entry[i]; + for (i = FFMAX(0, rcc->num_entries - 300); i < rcc->num_entries; i++) { + RateControlEntry *rce = &rcc->entry[i]; - qscale[i]= get_diff_limited_q(s, rce, qscale[i]); + qscale[i] = get_diff_limited_q(s, rce, qscale[i]); } - for(i=rcc->num_entries-1; i>=0; i--){ - RateControlEntry *rce= &rcc->entry[i]; + for (i = rcc->num_entries - 1; i >= 0; i--) { + RateControlEntry *rce = &rcc->entry[i]; - qscale[i]= get_diff_limited_q(s, rce, qscale[i]); + qscale[i] = get_diff_limited_q(s, rce, qscale[i]); } /* smooth curve */ - for(i=0; inum_entries; i++){ - RateControlEntry *rce= &rcc->entry[i]; - const int pict_type= rce->new_pict_type; + for (i = 0; i < rcc->num_entries; i++) { + RateControlEntry *rce = &rcc->entry[i]; + const int pict_type = rce->new_pict_type; int j; - double q=0.0, sum=0.0; - - for(j=0; jqblur==0 ? 1.0 : exp(-d*d/(a->qblur * a->qblur)); - - if(index < 0 || index >= rcc->num_entries) continue; - if(pict_type != rcc->entry[index].new_pict_type) continue; - q+= qscale[index] * coeff; - sum+= coeff; + double q = 0.0, sum = 0.0; + + for (j = 0; j < filter_size; j++) { + int index = i + j - filter_size / 2; + double d = index - i; + double coeff = a->qblur == 0 ? 1.0 : exp(-d * d / (a->qblur * a->qblur)); + + if (index < 0 || index >= rcc->num_entries) + continue; + if (pict_type != rcc->entry[index].new_pict_type) + continue; + q += qscale[index] * coeff; + sum += coeff; } - blurred_qscale[i]= q/sum; + blurred_qscale[i] = q / sum; } /* find expected bits */ - for(i=0; inum_entries; i++){ - RateControlEntry *rce= &rcc->entry[i]; + for (i = 0; i < rcc->num_entries; i++) { + RateControlEntry *rce = &rcc->entry[i]; double bits; - rce->new_qscale= modify_qscale(s, rce, blurred_qscale[i], i); - bits= qp2bits(rce, rce->new_qscale) + rce->mv_bits + rce->misc_bits; - bits += 8*ff_vbv_update(s, bits); - rce->expected_bits= expected_bits; - expected_bits += bits; + rce->new_qscale = modify_qscale(s, rce, blurred_qscale[i], i); + + bits = qp2bits(rce, rce->new_qscale) + rce->mv_bits + rce->misc_bits; + bits += 8 * ff_vbv_update(s, bits); + + rce->expected_bits = expected_bits; + expected_bits += bits; } av_dlog(s->avctx, "expected_bits: %f all_available_bits: %d rate_factor: %f\n", expected_bits, (int)all_available_bits, rate_factor); - if(expected_bits > all_available_bits) { - rate_factor-= step; + if (expected_bits > all_available_bits) { + rate_factor -= step; ++toobig; } } @@ -923,33 +1027,34 @@ static int init_pass2(MpegEncContext *s) /* check bitrate calculations and print info */ qscale_sum = 0.0; - for(i=0; inum_entries; i++){ + for (i = 0; i < rcc->num_entries; i++) { av_dlog(s, "[lavc rc] entry[%d].new_qscale = %.3f qp = %.3f\n", i, rcc->entry[i].new_qscale, rcc->entry[i].new_qscale / FF_QP2LAMBDA); - qscale_sum += av_clip(rcc->entry[i].new_qscale / FF_QP2LAMBDA, s->avctx->qmin, s->avctx->qmax); + qscale_sum += av_clip(rcc->entry[i].new_qscale / FF_QP2LAMBDA, + s->avctx->qmin, s->avctx->qmax); } assert(toobig <= 40); av_log(s->avctx, AV_LOG_DEBUG, - "[lavc rc] requested bitrate: %d bps expected bitrate: %d bps\n", - s->bit_rate, - (int)(expected_bits / ((double)all_available_bits/s->bit_rate))); + "[lavc rc] requested bitrate: %d bps expected bitrate: %d bps\n", + s->bit_rate, + (int)(expected_bits / ((double)all_available_bits / s->bit_rate))); av_log(s->avctx, AV_LOG_DEBUG, - "[lavc rc] estimated target average qp: %.3f\n", - (float)qscale_sum / rcc->num_entries); + "[lavc rc] estimated target average qp: %.3f\n", + (float)qscale_sum / rcc->num_entries); if (toobig == 0) { av_log(s->avctx, AV_LOG_INFO, - "[lavc rc] Using all of requested bitrate is not " - "necessary for this video with these parameters.\n"); + "[lavc rc] Using all of requested bitrate is not " + "necessary for this video with these parameters.\n"); } else if (toobig == 40) { av_log(s->avctx, AV_LOG_ERROR, - "[lavc rc] Error: bitrate too low for this video " - "with these parameters.\n"); + "[lavc rc] Error: bitrate too low for this video " + "with these parameters.\n"); return -1; - } else if (fabs(expected_bits/all_available_bits - 1.0) > 0.01) { + } else if (fabs(expected_bits / all_available_bits - 1.0) > 0.01) { av_log(s->avctx, AV_LOG_ERROR, - "[lavc rc] Error: 2pass curve failed to converge\n"); + "[lavc rc] Error: 2pass curve failed to converge\n"); return -1; } diff --git a/mythtv/external/FFmpeg/libavcodec/raw.h b/mythtv/external/FFmpeg/libavcodec/raw.h index 87b6c901cab..3e59f28e33d 100644 --- a/mythtv/external/FFmpeg/libavcodec/raw.h +++ b/mythtv/external/FFmpeg/libavcodec/raw.h @@ -36,6 +36,9 @@ typedef struct PixelFormatTag { } PixelFormatTag; extern av_export const PixelFormatTag ff_raw_pix_fmt_tags[]; +#if LIBAVCODEC_VERSION_MAJOR < 55 enum AVPixelFormat ff_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc); +#endif +enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc); #endif /* AVCODEC_RAW_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/rawdec.c b/mythtv/external/FFmpeg/libavcodec/rawdec.c index a4cb151197d..f7143d7eb0f 100644 --- a/mythtv/external/FFmpeg/libavcodec/rawdec.c +++ b/mythtv/external/FFmpeg/libavcodec/rawdec.c @@ -35,8 +35,8 @@ typedef struct RawVideoContext { AVClass *av_class; uint32_t palette[AVPALETTE_COUNT]; - unsigned char * buffer; /* block of memory for holding one frame */ - int length; /* number of bytes in buffer */ + unsigned char *buffer; /* block of memory for holding one frame */ + int length; /* number of bytes in buffer */ int flip; AVFrame pic; ///< AVCodecContext.coded_frame int tff; @@ -58,12 +58,12 @@ static const PixelFormatTag pix_fmt_bps_avi[] = { { AV_PIX_FMT_PAL8, 2 }, { AV_PIX_FMT_PAL8, 4 }, { AV_PIX_FMT_PAL8, 8 }, - { AV_PIX_FMT_RGB444, 12 }, - { AV_PIX_FMT_RGB555, 15 }, - { AV_PIX_FMT_RGB555, 16 }, + { AV_PIX_FMT_RGB444LE, 12 }, + { AV_PIX_FMT_RGB555LE, 15 }, + { AV_PIX_FMT_RGB555LE, 16 }, { AV_PIX_FMT_BGR24, 24 }, { AV_PIX_FMT_BGRA, 32 }, - { AV_PIX_FMT_NONE, 0 }, + { AV_PIX_FMT_NONE, 0 }, }; static const PixelFormatTag pix_fmt_bps_mov[] = { @@ -77,31 +77,43 @@ static const PixelFormatTag pix_fmt_bps_mov[] = { { AV_PIX_FMT_RGB24, 24 }, { AV_PIX_FMT_ARGB, 32 }, { AV_PIX_FMT_MONOWHITE,33 }, - { AV_PIX_FMT_NONE, 0 }, + { AV_PIX_FMT_NONE, 0 }, }; -enum AVPixelFormat ff_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc) +enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags, + unsigned int fourcc) { while (tags->pix_fmt >= 0) { if (tags->fourcc == fourcc) return tags->pix_fmt; tags++; } - return AV_PIX_FMT_YUV420P; + return AV_PIX_FMT_NONE; +} + +#if LIBAVCODEC_VERSION_MAJOR < 55 +enum AVPixelFormat ff_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc) +{ + return avpriv_find_pix_fmt(tags, fourcc); } +#endif static av_cold int raw_init_decoder(AVCodecContext *avctx) { RawVideoContext *context = avctx->priv_data; - if (avctx->codec_tag == MKTAG('r','a','w',' ') || avctx->codec_tag == MKTAG('N','O','1','6')) - avctx->pix_fmt = ff_find_pix_fmt(pix_fmt_bps_mov, avctx->bits_per_coded_sample); - else if (avctx->codec_tag == MKTAG('W','R','A','W')) - avctx->pix_fmt = ff_find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample); + if ( avctx->codec_tag == MKTAG('r','a','w',' ') + || avctx->codec_tag == MKTAG('N','O','1','6')) + avctx->pix_fmt = avpriv_find_pix_fmt(pix_fmt_bps_mov, + avctx->bits_per_coded_sample); + else if (avctx->codec_tag == MKTAG('W', 'R', 'A', 'W')) + avctx->pix_fmt = avpriv_find_pix_fmt(pix_fmt_bps_avi, + avctx->bits_per_coded_sample); else if (avctx->codec_tag) - avctx->pix_fmt = ff_find_pix_fmt(ff_raw_pix_fmt_tags, avctx->codec_tag); + avctx->pix_fmt = avpriv_find_pix_fmt(ff_raw_pix_fmt_tags, avctx->codec_tag); else if (avctx->pix_fmt == AV_PIX_FMT_NONE && avctx->bits_per_coded_sample) - avctx->pix_fmt = ff_find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample); + avctx->pix_fmt = avpriv_find_pix_fmt(pix_fmt_bps_avi, + avctx->bits_per_coded_sample); if (avctx->pix_fmt == AV_PIX_FMT_NONE) { av_log(avctx, AV_LOG_ERROR, "Pixel format was not specified and cannot be detected\n"); @@ -109,10 +121,12 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx) } avpriv_set_systematic_pal2(context->palette, avctx->pix_fmt); - if((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) && - avctx->pix_fmt==AV_PIX_FMT_PAL8 && - (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))){ - context->length = avpicture_get_size(avctx->pix_fmt, FFALIGN(avctx->width, 16), avctx->height); + if ((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) && + avctx->pix_fmt == AV_PIX_FMT_PAL8 && + (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))) { + context->length = avpicture_get_size(avctx->pix_fmt, + FFALIGN(avctx->width, 16), + avctx->height); if (context->length < 0) return context->length; context->buffer = av_malloc(context->length); @@ -126,12 +140,14 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx) context->pic.pict_type = AV_PICTURE_TYPE_I; context->pic.key_frame = 1; - avctx->coded_frame= &context->pic; + avctx->coded_frame = &context->pic; - if((avctx->extradata_size >= 9 && !memcmp(avctx->extradata + avctx->extradata_size - 9, "BottomUp", 9)) || + if ((avctx->extradata_size >= 9 && + !memcmp(avctx->extradata + avctx->extradata_size - 9, "BottomUp", 9)) || avctx->codec_tag == MKTAG('c','y','u','v') || - avctx->codec_tag == MKTAG(3, 0, 0, 0) || avctx->codec_tag == MKTAG('W','R','A','W')) - context->flip=1; + avctx->codec_tag == MKTAG(3, 0, 0, 0) || + avctx->codec_tag == MKTAG('W','R','A','W')) + context->flip = 1; if (avctx->field_order > AV_FIELD_PROGRESSIVE) { /*we have interlaced material flagged in container */ avctx->coded_frame->interlaced_frame = 1; @@ -143,20 +159,20 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx) return 0; } -static void flip(AVCodecContext *avctx, AVPicture * picture){ - picture->data[0] += picture->linesize[0] * (avctx->height-1); +static void flip(AVCodecContext *avctx, AVPicture *picture) +{ + picture->data[0] += picture->linesize[0] * (avctx->height - 1); picture->linesize[0] *= -1; } -static int raw_decode(AVCodecContext *avctx, - void *data, int *got_frame, - AVPacket *avpkt) +static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame, + AVPacket *avpkt) { - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; - int linesize_align = 4; - RawVideoContext *context = avctx->priv_data; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); + RawVideoContext *context = avctx->priv_data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + int linesize_align = 4; int res, len; AVFrame *frame = data; @@ -164,13 +180,13 @@ static int raw_decode(AVCodecContext *avctx, frame->pict_type = avctx->coded_frame->pict_type; frame->interlaced_frame = avctx->coded_frame->interlaced_frame; - frame->top_field_first = avctx->coded_frame->top_field_first; + frame->top_field_first = avctx->coded_frame->top_field_first; frame->reordered_opaque = avctx->reordered_opaque; frame->pkt_pts = avctx->pkt->pts; - frame->pkt_pos = avctx->pkt->pos; - frame->pkt_duration = avctx->pkt->duration; + av_frame_set_pkt_pos (frame, avctx->pkt->pos); + av_frame_set_pkt_duration(frame, avctx->pkt->duration); - if(context->tff>=0){ + if (context->tff >= 0) { frame->interlaced_frame = 1; frame->top_field_first = context->tff; } @@ -183,27 +199,27 @@ static int raw_decode(AVCodecContext *avctx, int i; uint8_t *dst = context->buffer; buf_size = context->length - AVPALETTE_SIZE; - if (avctx->bits_per_coded_sample == 4){ - for(i=0; 2*i+1 < buf_size && isize; i++){ - dst[2*i+0]= buf[i]>>4; - dst[2*i+1]= buf[i]&15; + if (avctx->bits_per_coded_sample == 4) { + for (i = 0; 2 * i + 1 < buf_size && isize; i++) { + dst[2 * i + 0] = buf[i] >> 4; + dst[2 * i + 1] = buf[i] & 15; } linesize_align = 8; } else { av_assert0(avctx->bits_per_coded_sample == 2); - for(i=0; 4*i+3 < buf_size && isize; i++){ - dst[4*i+0]= buf[i]>>6; - dst[4*i+1]= buf[i]>>4&3; - dst[4*i+2]= buf[i]>>2&3; - dst[4*i+3]= buf[i] &3; + for (i = 0; 4 * i + 3 < buf_size && isize; i++) { + dst[4 * i + 0] = buf[i] >> 6; + dst[4 * i + 1] = buf[i] >> 4 & 3; + dst[4 * i + 2] = buf[i] >> 2 & 3; + dst[4 * i + 3] = buf[i] & 3; } linesize_align = 16; } - buf= dst; + buf = dst; } - if(avctx->codec_tag == MKTAG('A', 'V', '1', 'x') || - avctx->codec_tag == MKTAG('A', 'V', 'u', 'p')) + if (avctx->codec_tag == MKTAG('A', 'V', '1', 'x') || + avctx->codec_tag == MKTAG('A', 'V', 'u', 'p')) buf += buf_size - context->length; len = context->length - (avctx->pix_fmt==AV_PIX_FMT_PAL8 ? AVPALETTE_SIZE : 0); @@ -215,63 +231,64 @@ static int raw_decode(AVCodecContext *avctx, if ((res = avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height)) < 0) return res; - if((avctx->pix_fmt==AV_PIX_FMT_PAL8 && buf_size < context->length) || - (desc->flags & PIX_FMT_PSEUDOPAL)) { - frame->data[1]= (uint8_t*)context->palette; + if ((avctx->pix_fmt == AV_PIX_FMT_PAL8 && buf_size < context->length) || + (desc->flags & PIX_FMT_PSEUDOPAL)) { + frame->data[1] = (uint8_t*)context->palette; } if (avctx->pix_fmt == AV_PIX_FMT_PAL8) { - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); + const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, + NULL); if (pal) { memcpy(frame->data[1], pal, AVPALETTE_SIZE); frame->palette_has_changed = 1; } } - if((avctx->pix_fmt==AV_PIX_FMT_BGR24 || + if ((avctx->pix_fmt==AV_PIX_FMT_BGR24 || avctx->pix_fmt==AV_PIX_FMT_GRAY8 || avctx->pix_fmt==AV_PIX_FMT_RGB555LE || avctx->pix_fmt==AV_PIX_FMT_RGB555BE || avctx->pix_fmt==AV_PIX_FMT_RGB565LE || avctx->pix_fmt==AV_PIX_FMT_MONOWHITE || avctx->pix_fmt==AV_PIX_FMT_PAL8) && - FFALIGN(frame->linesize[0], linesize_align)*avctx->height <= buf_size) + FFALIGN(frame->linesize[0], linesize_align) * avctx->height <= buf_size) frame->linesize[0] = FFALIGN(frame->linesize[0], linesize_align); - if(avctx->pix_fmt == AV_PIX_FMT_NV12 && avctx->codec_tag == MKTAG('N', 'V', '1', '2') && - FFALIGN(frame->linesize[0], linesize_align)*avctx->height + - FFALIGN(frame->linesize[1], linesize_align)*((avctx->height+1)/2) <= buf_size) { + if (avctx->pix_fmt == AV_PIX_FMT_NV12 && avctx->codec_tag == MKTAG('N', 'V', '1', '2') && + FFALIGN(frame->linesize[0], linesize_align) * avctx->height + + FFALIGN(frame->linesize[1], linesize_align) * ((avctx->height + 1) / 2) <= buf_size) { int la0 = FFALIGN(frame->linesize[0], linesize_align); - frame->data[1] += (la0 - frame->linesize[0])*avctx->height; + frame->data[1] += (la0 - frame->linesize[0]) * avctx->height; frame->linesize[0] = la0; frame->linesize[1] = FFALIGN(frame->linesize[1], linesize_align); } - if(context->flip) + if (context->flip) flip(avctx, picture); - if ( avctx->codec_tag == MKTAG('Y', 'V', '1', '2') - || avctx->codec_tag == MKTAG('Y', 'V', '1', '6') - || avctx->codec_tag == MKTAG('Y', 'V', '2', '4') - || avctx->codec_tag == MKTAG('Y', 'V', 'U', '9')) + if (avctx->codec_tag == MKTAG('Y', 'V', '1', '2') || + avctx->codec_tag == MKTAG('Y', 'V', '1', '6') || + avctx->codec_tag == MKTAG('Y', 'V', '2', '4') || + avctx->codec_tag == MKTAG('Y', 'V', 'U', '9')) FFSWAP(uint8_t *, picture->data[1], picture->data[2]); if (avctx->codec_tag == AV_RL32("I420") && (avctx->width+1)*(avctx->height+1) * 3/2 == buf_size) { - picture->data[1] = picture->data[1] + (avctx->width+1)*(avctx->height+1) -avctx->width*avctx->height; + picture->data[1] = picture->data[1] + (avctx->width+1)*(avctx->height+1) -avctx->width*avctx->height; picture->data[2] = picture->data[2] + ((avctx->width+1)*(avctx->height+1) -avctx->width*avctx->height)*5/4; } - if(avctx->codec_tag == AV_RL32("yuv2") && - avctx->pix_fmt == AV_PIX_FMT_YUYV422) { + if (avctx->codec_tag == AV_RL32("yuv2") && + avctx->pix_fmt == AV_PIX_FMT_YUYV422) { int x, y; uint8_t *line = picture->data[0]; - for(y = 0; y < avctx->height; y++) { - for(x = 0; x < avctx->width; x++) - line[2*x + 1] ^= 0x80; + for (y = 0; y < avctx->height; y++) { + for (x = 0; x < avctx->width; x++) + line[2 * x + 1] ^= 0x80; line += picture->linesize[0]; } } - if(avctx->codec_tag == AV_RL32("YVYU") && - avctx->pix_fmt == AV_PIX_FMT_YUYV422) { + if (avctx->codec_tag == AV_RL32("YVYU") && + avctx->pix_fmt == AV_PIX_FMT_YUYV422) { int x, y; uint8_t *line = picture->data[0]; for(y = 0; y < avctx->height; y++) { diff --git a/mythtv/external/FFmpeg/libavcodec/realtextdec.c b/mythtv/external/FFmpeg/libavcodec/realtextdec.c index 102e0d924f3..45788977b59 100644 --- a/mythtv/external/FFmpeg/libavcodec/realtextdec.c +++ b/mythtv/external/FFmpeg/libavcodec/realtextdec.c @@ -35,11 +35,11 @@ static int rt_event_to_ass(AVBPrint *buf, const char *p) while (*p) { if (*p != '<') { - if (!isspace(*p)) + if (!av_isspace(*p)) av_bprint_chars(buf, *p, 1); else if (!prev_chr_is_space) av_bprint_chars(buf, ' ', 1); - prev_chr_is_space = isspace(*p); + prev_chr_is_space = av_isspace(*p); } else { const char *end = strchr(p, '>'); if (!end) diff --git a/mythtv/external/FFmpeg/libavcodec/rectangle.h b/mythtv/external/FFmpeg/libavcodec/rectangle.h index 43f89c9e0fb..594a7608012 100644 --- a/mythtv/external/FFmpeg/libavcodec/rectangle.h +++ b/mythtv/external/FFmpeg/libavcodec/rectangle.h @@ -31,7 +31,6 @@ #include "config.h" #include "libavutil/common.h" #include "libavutil/avassert.h" -#include "dsputil.h" /** * fill a rectangle. @@ -47,7 +46,7 @@ static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, w *= size; stride *= size; - av_assert2((((long)vp)&(FFMIN(w, STRIDE_ALIGN)-1)) == 0); + av_assert2((((long)vp)&(FFMIN(w, 8<<(HAVE_NEON|ARCH_PPC|HAVE_MMX))-1)) == 0); av_assert2((stride&(w-1))==0); if(w==2){ const uint16_t v= size==4 ? val : val*0x0101; diff --git a/mythtv/external/FFmpeg/libavcodec/resample2.c b/mythtv/external/FFmpeg/libavcodec/resample2.c index 4cdb0e50953..9b63b53c868 100644 --- a/mythtv/external/FFmpeg/libavcodec/resample2.c +++ b/mythtv/external/FFmpeg/libavcodec/resample2.c @@ -27,7 +27,6 @@ #include "libavutil/avassert.h" #include "avcodec.h" -#include "dsputil.h" #include "libavutil/common.h" #if FF_API_AVCODEC_RESAMPLE diff --git a/mythtv/external/FFmpeg/libavcodec/rl2.c b/mythtv/external/FFmpeg/libavcodec/rl2.c index 642d31af322..b908a83f488 100644 --- a/mythtv/external/FFmpeg/libavcodec/rl2.c +++ b/mythtv/external/FFmpeg/libavcodec/rl2.c @@ -43,10 +43,10 @@ typedef struct Rl2Context { AVCodecContext *avctx; AVFrame frame; - unsigned short video_base; ///< initial drawing offset - unsigned int clr_count; ///< number of used colors (currently unused) - unsigned char* back_frame; ///< background frame - unsigned int palette[AVPALETTE_COUNT]; + uint16_t video_base; ///< initial drawing offset + uint32_t clr_count; ///< number of used colors (currently unused) + uint8_t *back_frame; ///< background frame + uint32_t palette[AVPALETTE_COUNT]; } Rl2Context; /** @@ -58,67 +58,68 @@ typedef struct Rl2Context { * @param stride stride of the output buffer * @param video_base offset of the rle data inside the frame */ -static void rl2_rle_decode(Rl2Context *s,const unsigned char* in,int size, - unsigned char* out,int stride,int video_base){ +static void rl2_rle_decode(Rl2Context *s, const uint8_t *in, int size, + uint8_t *out, int stride, int video_base) +{ int base_x = video_base % s->avctx->width; int base_y = video_base / s->avctx->width; int stride_adj = stride - s->avctx->width; int i; - const unsigned char* back_frame = s->back_frame; - const unsigned char* in_end = in + size; - const unsigned char* out_end = out + stride * s->avctx->height; - unsigned char* line_end; + const uint8_t *back_frame = s->back_frame; + const uint8_t *in_end = in + size; + const uint8_t *out_end = out + stride * s->avctx->height; + uint8_t *line_end; /** copy start of the background frame */ - for(i=0;i<=base_y;i++){ - if(s->back_frame) - memcpy(out,back_frame,s->avctx->width); - out += stride; + for (i = 0; i <= base_y; i++) { + if (s->back_frame) + memcpy(out, back_frame, s->avctx->width); + out += stride; back_frame += s->avctx->width; } back_frame += base_x - s->avctx->width; - line_end = out - stride_adj; - out += base_x - stride; + line_end = out - stride_adj; + out += base_x - stride; /** decode the variable part of the frame */ - while(in < in_end){ - unsigned char val = *in++; - int len = 1; - if(val >= 0x80){ - if(in >= in_end) + while (in < in_end) { + uint8_t val = *in++; + int len = 1; + if (val >= 0x80) { + if (in >= in_end) break; len = *in++; - if(!len) + if (!len) break; } - if(len >= out_end - out) + if (len >= out_end - out) break; - if(s->back_frame) + if (s->back_frame) val |= 0x80; else val &= ~0x80; - while(len--){ - *out++ = (val == 0x80)? *back_frame:val; + while (len--) { + *out++ = (val == 0x80) ? *back_frame : val; back_frame++; - if(out == line_end){ - out += stride_adj; + if (out == line_end) { + out += stride_adj; line_end += stride; - if(len >= out_end - out) + if (len >= out_end - out) break; } } } /** copy the rest from the background frame */ - if(s->back_frame){ - while(out < out_end){ + if (s->back_frame) { + while (out < out_end) { memcpy(out, back_frame, line_end - out); back_frame += line_end - out; - out = line_end + stride_adj; - line_end += stride; + out = line_end + stride_adj; + line_end += stride; } } } @@ -134,38 +135,39 @@ static av_cold int rl2_decode_init(AVCodecContext *avctx) Rl2Context *s = avctx->priv_data; int back_size; int i; - s->avctx = avctx; + + s->avctx = avctx; avctx->pix_fmt = AV_PIX_FMT_PAL8; avcodec_get_frame_defaults(&s->frame); /** parse extra data */ - if(!avctx->extradata || avctx->extradata_size < EXTRADATA1_SIZE){ + if (!avctx->extradata || avctx->extradata_size < EXTRADATA1_SIZE) { av_log(avctx, AV_LOG_ERROR, "invalid extradata size\n"); - return AVERROR_INVALIDDATA; + return AVERROR(EINVAL); } /** get frame_offset */ s->video_base = AV_RL16(&avctx->extradata[0]); - s->clr_count = AV_RL32(&avctx->extradata[2]); + s->clr_count = AV_RL32(&avctx->extradata[2]); - if(s->video_base >= avctx->width * avctx->height){ + if (s->video_base >= avctx->width * avctx->height) { av_log(avctx, AV_LOG_ERROR, "invalid video_base\n"); return AVERROR_INVALIDDATA; } /** initialize palette */ - for(i=0;ipalette[i] = 0xFFU << 24 | AV_RB24(&avctx->extradata[6 + i * 3]); /** decode background frame if present */ back_size = avctx->extradata_size - EXTRADATA1_SIZE; - if(back_size > 0){ - unsigned char* back_frame = av_mallocz(avctx->width*avctx->height); - if(!back_frame) + if (back_size > 0) { + uint8_t *back_frame = av_mallocz(avctx->width*avctx->height); + if (!back_frame) return AVERROR(ENOMEM); - rl2_rle_decode(s,avctx->extradata + EXTRADATA1_SIZE,back_size, - back_frame,avctx->width,0); + rl2_rle_decode(s, avctx->extradata + EXTRADATA1_SIZE, back_size, + back_frame, avctx->width, 0); s->back_frame = back_frame; } return 0; @@ -173,26 +175,26 @@ static av_cold int rl2_decode_init(AVCodecContext *avctx) static int rl2_decode_frame(AVCodecContext *avctx, - void *data, int *got_frame, - AVPacket *avpkt) + void *data, int *got_frame, + AVPacket *avpkt) { const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; + int ret, buf_size = avpkt->size; Rl2Context *s = avctx->priv_data; - int ret; - if(s->frame.data[0]) + if (s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); /** get buffer */ - s->frame.reference= 0; + s->frame.reference = 0; if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } /** run length decode */ - rl2_rle_decode(s,buf,buf_size,s->frame.data[0],s->frame.linesize[0],s->video_base); + rl2_rle_decode(s, buf, buf_size, s->frame.data[0], s->frame.linesize[0], + s->video_base); /** make the palette available on the way out */ memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE); @@ -214,7 +216,7 @@ static av_cold int rl2_decode_end(AVCodecContext *avctx) { Rl2Context *s = avctx->priv_data; - if(s->frame.data[0]) + if (s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); av_free(s->back_frame); diff --git a/mythtv/external/FFmpeg/libavcodec/rnd_avg.h b/mythtv/external/FFmpeg/libavcodec/rnd_avg.h new file mode 100644 index 00000000000..bc663ef8646 --- /dev/null +++ b/mythtv/external/FFmpeg/libavcodec/rnd_avg.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2001-2003 BERO + * Copyright (c) 2011 Oskar Arvidsson + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_RND_AVG_H +#define AVCODEC_RND_AVG_H + +#include + +#define BYTE_VEC32(c) ((c)*0x01010101UL) +#define BYTE_VEC64(c) ((c)*0x0001000100010001UL) + +static inline uint32_t rnd_avg32(uint32_t a, uint32_t b) +{ + return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1); +} + +static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b) +{ + return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1); +} + +static inline uint64_t rnd_avg64(uint64_t a, uint64_t b) +{ + return (a | b) - (((a ^ b) & ~BYTE_VEC64(0x01)) >> 1); +} + +static inline uint64_t no_rnd_avg64(uint64_t a, uint64_t b) +{ + return (a & b) + (((a ^ b) & ~BYTE_VEC64(0x01)) >> 1); +} + +#endif /* AVCODEC_RND_AVG_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/roqaudioenc.c b/mythtv/external/FFmpeg/libavcodec/roqaudioenc.c index ed5481f3952..ba020d03e5f 100644 --- a/mythtv/external/FFmpeg/libavcodec/roqaudioenc.c +++ b/mythtv/external/FFmpeg/libavcodec/roqaudioenc.c @@ -173,7 +173,7 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, else data_size = avctx->channels * avctx->frame_size; - if ((ret = ff_alloc_packet2(avctx, avpkt, ROQ_HEADER_SIZE + data_size))) + if ((ret = ff_alloc_packet2(avctx, avpkt, ROQ_HEADER_SIZE + data_size)) < 0) return ret; out = avpkt->data; diff --git a/mythtv/external/FFmpeg/libavcodec/roqvideo.h b/mythtv/external/FFmpeg/libavcodec/roqvideo.h index 2f9493d3b6c..3834897252c 100644 --- a/mythtv/external/FFmpeg/libavcodec/roqvideo.h +++ b/mythtv/external/FFmpeg/libavcodec/roqvideo.h @@ -25,7 +25,6 @@ #include "libavutil/lfg.h" #include "avcodec.h" #include "bytestream.h" -#include "dsputil.h" typedef struct roq_cell { unsigned char y[4]; diff --git a/mythtv/external/FFmpeg/libavcodec/rpza.c b/mythtv/external/FFmpeg/libavcodec/rpza.c index a4247599530..a5da96720fa 100644 --- a/mythtv/external/FFmpeg/libavcodec/rpza.c +++ b/mythtv/external/FFmpeg/libavcodec/rpza.c @@ -251,15 +251,16 @@ static int rpza_decode_frame(AVCodecContext *avctx, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; RpzaContext *s = avctx->priv_data; + int ret; s->buf = buf; s->size = buf_size; s->frame.reference = 3; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; - if (avctx->reget_buffer(avctx, &s->frame)) { + if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } rpza_decode_stream(s); diff --git a/mythtv/external/FFmpeg/libavcodec/rtjpeg.c b/mythtv/external/FFmpeg/libavcodec/rtjpeg.c index 7797a655c1d..fe781ce25ee 100644 --- a/mythtv/external/FFmpeg/libavcodec/rtjpeg.c +++ b/mythtv/external/FFmpeg/libavcodec/rtjpeg.c @@ -20,7 +20,6 @@ */ #include "libavutil/common.h" #include "get_bits.h" -#include "dsputil.h" #include "rtjpeg.h" #define PUT_COEFF(c) \ @@ -44,7 +43,7 @@ * aligned this could be done faster in a different way, e.g. as it is done * in MPlayer libmpcodecs/native/rtjpegn.c. */ -static inline int get_block(GetBitContext *gb, DCTELEM *block, const uint8_t *scan, +static inline int get_block(GetBitContext *gb, int16_t *block, const uint8_t *scan, const uint32_t *quant) { int coeff, i, n; int8_t ac; @@ -61,7 +60,7 @@ static inline int get_block(GetBitContext *gb, DCTELEM *block, const uint8_t *sc // normally we would only need to clear the (63 - coeff) last values, // but since we do not know where they are we just clear the whole block - memset(block, 0, 64 * sizeof(DCTELEM)); + memset(block, 0, 64 * sizeof(int16_t)); // 2 bits per coefficient while (coeff) { @@ -121,7 +120,7 @@ int ff_rtjpeg_decode_frame_yuv420(RTJpegContext *c, AVFrame *f, if (res > 0) \ c->dsp->idct_put(dst, stride, block); \ } while (0) - DCTELEM *block = c->block; + int16_t *block = c->block; BLOCK(c->lquant, y1, f->linesize[0]); y1 += 8; BLOCK(c->lquant, y1, f->linesize[0]); diff --git a/mythtv/external/FFmpeg/libavcodec/rtjpeg.h b/mythtv/external/FFmpeg/libavcodec/rtjpeg.h index 0fd24a356cb..294b06c6978 100644 --- a/mythtv/external/FFmpeg/libavcodec/rtjpeg.h +++ b/mythtv/external/FFmpeg/libavcodec/rtjpeg.h @@ -35,7 +35,7 @@ typedef struct RTJpegContext { uint8_t scan[64]; uint32_t lquant[64]; uint32_t cquant[64]; - DECLARE_ALIGNED(16, DCTELEM, block)[64]; + DECLARE_ALIGNED(16, int16_t, block)[64]; } RTJpegContext; void ff_rtjpeg_decode_init(RTJpegContext *c, DSPContext *dsp, diff --git a/mythtv/external/FFmpeg/libavcodec/rv10.c b/mythtv/external/FFmpeg/libavcodec/rv10.c index e10cbbf7736..3f338f3ff34 100644 --- a/mythtv/external/FFmpeg/libavcodec/rv10.c +++ b/mythtv/external/FFmpeg/libavcodec/rv10.c @@ -27,7 +27,6 @@ #include "libavutil/imgutils.h" #include "avcodec.h" -#include "dsputil.h" #include "mpegvideo.h" #include "mpeg4video.h" #include "h263.h" @@ -415,13 +414,16 @@ static int rv20_decode_picture_header(RVDecContext *rv) }else{ s->time= seq; s->pb_time= s->pp_time - (s->last_non_b_time - s->time); - if(s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0){ - av_log(s->avctx, AV_LOG_DEBUG, "messed up order, possible from seeking? skipping current b frame\n"); - return FRAME_SKIPPED; - } - ff_mpeg4_init_direct_mv(s); } } + if (s->pict_type==AV_PICTURE_TYPE_B) { + if(s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0){ + av_log(s->avctx, AV_LOG_DEBUG, "messed up order, possible from seeking? skipping current b frame\n"); +#define ERROR_SKIP_FRAME -123 + return ERROR_SKIP_FRAME; + } + ff_mpeg4_init_direct_mv(s); + } s->no_rounding= get_bits1(&s->gb); @@ -495,7 +497,7 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx) } if(avctx->debug & FF_DEBUG_PICT_INFO){ - av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%X\n", rv->sub_id, avctx->extradata_size >= 4 ? ((uint32_t*)avctx->extradata)[0] : -1); + av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%X\n", rv->sub_id, ((uint32_t*)avctx->extradata)[0]); } avctx->pix_fmt = AV_PIX_FMT_YUV420P; @@ -503,7 +505,7 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx) if (ff_MPV_common_init(s) < 0) return -1; - ff_h263_decode_init_vlc(s); + ff_h263_decode_init_vlc(); /* init rv vlc */ if (!done) { @@ -541,7 +543,8 @@ static int rv10_decode_packet(AVCodecContext *avctx, else mb_count = rv20_decode_picture_header(rv); if (mb_count < 0) { - av_log(s->avctx, AV_LOG_ERROR, "HEADER ERROR\n"); + if (mb_count != ERROR_SKIP_FRAME) + av_log(s->avctx, AV_LOG_ERROR, "HEADER ERROR\n"); return -1; } @@ -559,13 +562,13 @@ static int rv10_decode_packet(AVCodecContext *avctx, if ((s->mb_x == 0 && s->mb_y == 0) || s->current_picture_ptr==NULL) { if(s->current_picture_ptr){ //FIXME write parser so we always have complete frames? - ff_er_frame_end(s); + ff_er_frame_end(&s->er); ff_MPV_frame_end(s); s->mb_x= s->mb_y = s->resync_mb_x = s->resync_mb_y= 0; } if(ff_MPV_frame_start(s, avctx) < 0) return -1; - ff_er_frame_start(s); + ff_mpeg_er_frame_start(s); } else { if (s->current_picture_ptr->f.pict_type != s->pict_type) { av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n"); @@ -658,7 +661,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, if(ret == SLICE_END) break; } - ff_er_add_slice(s, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); + ff_er_add_slice(&s->er, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); return active_bits_size; } @@ -693,11 +696,15 @@ static int rv10_decode_frame(AVCodecContext *avctx, if(!avctx->slice_count){ slice_count = (*buf++) + 1; buf_size--; + + if (!slice_count || buf_size <= 8 * slice_count) { + av_log(avctx, AV_LOG_ERROR, "Invalid slice count: %d.\n", slice_count); + return AVERROR_INVALIDDATA; + } + slices_hdr = buf + 4; buf += 8 * slice_count; buf_size -= 8 * slice_count; - if (buf_size <= 0) - return AVERROR_INVALIDDATA; }else slice_count = avctx->slice_count; @@ -727,7 +734,7 @@ static int rv10_decode_frame(AVCodecContext *avctx, } if(s->current_picture_ptr != NULL && s->mb_y>=s->mb_height){ - ff_er_frame_end(s); + ff_er_frame_end(&s->er); ff_MPV_frame_end(s); if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { diff --git a/mythtv/external/FFmpeg/libavcodec/rv30.c b/mythtv/external/FFmpeg/libavcodec/rv30.c index 17f1e997268..7f8f8cbc7f4 100644 --- a/mythtv/external/FFmpeg/libavcodec/rv30.c +++ b/mythtv/external/FFmpeg/libavcodec/rv30.c @@ -25,7 +25,6 @@ */ #include "avcodec.h" -#include "dsputil.h" #include "mpegvideo.h" #include "golomb.h" diff --git a/mythtv/external/FFmpeg/libavcodec/rv30dsp.c b/mythtv/external/FFmpeg/libavcodec/rv30dsp.c index 83439600cea..d13a2d8d307 100644 --- a/mythtv/external/FFmpeg/libavcodec/rv30dsp.c +++ b/mythtv/external/FFmpeg/libavcodec/rv30dsp.c @@ -25,7 +25,8 @@ */ #include "avcodec.h" -#include "dsputil.h" +#include "h264chroma.h" +#include "h264qpel.h" #include "rv34dsp.h" #define RV30_LOWPASS(OPNAME, OP) \ @@ -252,11 +253,16 @@ RV30_MC(put_, 16) RV30_MC(avg_, 8) RV30_MC(avg_, 16) -av_cold void ff_rv30dsp_init(RV34DSPContext *c, DSPContext* dsp) { +av_cold void ff_rv30dsp_init(RV34DSPContext *c) +{ + H264ChromaContext h264chroma; + H264QpelContext qpel; - ff_rv34dsp_init(c, dsp); + ff_rv34dsp_init(c); + ff_h264chroma_init(&h264chroma, 8); + ff_h264qpel_init(&qpel, 8); - c->put_pixels_tab[0][ 0] = dsp->put_h264_qpel_pixels_tab[0][0]; + c->put_pixels_tab[0][ 0] = qpel.put_h264_qpel_pixels_tab[0][0]; c->put_pixels_tab[0][ 1] = put_rv30_tpel16_mc10_c; c->put_pixels_tab[0][ 2] = put_rv30_tpel16_mc20_c; c->put_pixels_tab[0][ 4] = put_rv30_tpel16_mc01_c; @@ -265,7 +271,7 @@ av_cold void ff_rv30dsp_init(RV34DSPContext *c, DSPContext* dsp) { c->put_pixels_tab[0][ 8] = put_rv30_tpel16_mc02_c; c->put_pixels_tab[0][ 9] = put_rv30_tpel16_mc12_c; c->put_pixels_tab[0][10] = put_rv30_tpel16_mc22_c; - c->avg_pixels_tab[0][ 0] = dsp->avg_h264_qpel_pixels_tab[0][0]; + c->avg_pixels_tab[0][ 0] = qpel.avg_h264_qpel_pixels_tab[0][0]; c->avg_pixels_tab[0][ 1] = avg_rv30_tpel16_mc10_c; c->avg_pixels_tab[0][ 2] = avg_rv30_tpel16_mc20_c; c->avg_pixels_tab[0][ 4] = avg_rv30_tpel16_mc01_c; @@ -274,7 +280,7 @@ av_cold void ff_rv30dsp_init(RV34DSPContext *c, DSPContext* dsp) { c->avg_pixels_tab[0][ 8] = avg_rv30_tpel16_mc02_c; c->avg_pixels_tab[0][ 9] = avg_rv30_tpel16_mc12_c; c->avg_pixels_tab[0][10] = avg_rv30_tpel16_mc22_c; - c->put_pixels_tab[1][ 0] = dsp->put_h264_qpel_pixels_tab[1][0]; + c->put_pixels_tab[1][ 0] = qpel.put_h264_qpel_pixels_tab[1][0]; c->put_pixels_tab[1][ 1] = put_rv30_tpel8_mc10_c; c->put_pixels_tab[1][ 2] = put_rv30_tpel8_mc20_c; c->put_pixels_tab[1][ 4] = put_rv30_tpel8_mc01_c; @@ -283,7 +289,7 @@ av_cold void ff_rv30dsp_init(RV34DSPContext *c, DSPContext* dsp) { c->put_pixels_tab[1][ 8] = put_rv30_tpel8_mc02_c; c->put_pixels_tab[1][ 9] = put_rv30_tpel8_mc12_c; c->put_pixels_tab[1][10] = put_rv30_tpel8_mc22_c; - c->avg_pixels_tab[1][ 0] = dsp->avg_h264_qpel_pixels_tab[1][0]; + c->avg_pixels_tab[1][ 0] = qpel.avg_h264_qpel_pixels_tab[1][0]; c->avg_pixels_tab[1][ 1] = avg_rv30_tpel8_mc10_c; c->avg_pixels_tab[1][ 2] = avg_rv30_tpel8_mc20_c; c->avg_pixels_tab[1][ 4] = avg_rv30_tpel8_mc01_c; @@ -293,8 +299,8 @@ av_cold void ff_rv30dsp_init(RV34DSPContext *c, DSPContext* dsp) { c->avg_pixels_tab[1][ 9] = avg_rv30_tpel8_mc12_c; c->avg_pixels_tab[1][10] = avg_rv30_tpel8_mc22_c; - c->put_chroma_pixels_tab[0] = dsp->put_h264_chroma_pixels_tab[0]; - c->put_chroma_pixels_tab[1] = dsp->put_h264_chroma_pixels_tab[1]; - c->avg_chroma_pixels_tab[0] = dsp->avg_h264_chroma_pixels_tab[0]; - c->avg_chroma_pixels_tab[1] = dsp->avg_h264_chroma_pixels_tab[1]; + c->put_chroma_pixels_tab[0] = h264chroma.put_h264_chroma_pixels_tab[0]; + c->put_chroma_pixels_tab[1] = h264chroma.put_h264_chroma_pixels_tab[1]; + c->avg_chroma_pixels_tab[0] = h264chroma.avg_h264_chroma_pixels_tab[0]; + c->avg_chroma_pixels_tab[1] = h264chroma.avg_h264_chroma_pixels_tab[1]; } diff --git a/mythtv/external/FFmpeg/libavcodec/rv34.c b/mythtv/external/FFmpeg/libavcodec/rv34.c index 73b6cb78d9d..462cef91ad4 100644 --- a/mythtv/external/FFmpeg/libavcodec/rv34.c +++ b/mythtv/external/FFmpeg/libavcodec/rv34.c @@ -28,7 +28,6 @@ #include "libavutil/internal.h" #include "avcodec.h" -#include "dsputil.h" #include "mpegvideo.h" #include "golomb.h" #include "internal.h" @@ -217,7 +216,7 @@ static int rv34_decode_cbp(GetBitContext *gb, RV34VLC *vlc, int table) /** * Get one coefficient value from the bitstream and store it. */ -static inline void decode_coeff(DCTELEM *dst, int coef, int esc, GetBitContext *gb, VLC* vlc, int q) +static inline void decode_coeff(int16_t *dst, int coef, int esc, GetBitContext *gb, VLC* vlc, int q) { if(coef){ if(coef == esc){ @@ -237,7 +236,7 @@ static inline void decode_coeff(DCTELEM *dst, int coef, int esc, GetBitContext * /** * Decode 2x2 subblock of coefficients. */ -static inline void decode_subblock(DCTELEM *dst, int code, const int is_block2, GetBitContext *gb, VLC *vlc, int q) +static inline void decode_subblock(int16_t *dst, int code, const int is_block2, GetBitContext *gb, VLC *vlc, int q) { int flags = modulo_three_table[code]; @@ -255,13 +254,13 @@ static inline void decode_subblock(DCTELEM *dst, int code, const int is_block2, /** * Decode a single coefficient. */ -static inline void decode_subblock1(DCTELEM *dst, int code, GetBitContext *gb, VLC *vlc, int q) +static inline void decode_subblock1(int16_t *dst, int code, GetBitContext *gb, VLC *vlc, int q) { int coeff = modulo_three_table[code] >> 6; decode_coeff(dst, coeff, 3, gb, vlc, q); } -static inline void decode_subblock3(DCTELEM *dst, int code, GetBitContext *gb, VLC *vlc, +static inline void decode_subblock3(int16_t *dst, int code, GetBitContext *gb, VLC *vlc, int q_dc, int q_ac1, int q_ac2) { int flags = modulo_three_table[code]; @@ -283,7 +282,7 @@ static inline void decode_subblock3(DCTELEM *dst, int code, GetBitContext *gb, V * o--o */ -static int rv34_decode_block(DCTELEM *dst, GetBitContext *gb, RV34VLC *rvlc, int fc, int sc, int q_dc, int q_ac1, int q_ac2) +static int rv34_decode_block(int16_t *dst, GetBitContext *gb, RV34VLC *rvlc, int fc, int sc, int q_dc, int q_ac1, int q_ac2) { int code, pattern, has_ac = 1; @@ -995,7 +994,7 @@ static inline void rv34_process_block(RV34DecContext *r, int fc, int sc, int q_dc, int q_ac) { MpegEncContext *s = &r->s; - DCTELEM *ptr = s->block[0]; + int16_t *ptr = s->block[0]; int has_ac = rv34_decode_block(ptr, &s->gb, r->cur_vlcs, fc, sc, q_dc, q_ac, q_ac); if(has_ac){ @@ -1008,13 +1007,13 @@ static inline void rv34_process_block(RV34DecContext *r, static void rv34_output_i16x16(RV34DecContext *r, int8_t *intra_types, int cbp) { - LOCAL_ALIGNED_16(DCTELEM, block16, [16]); + LOCAL_ALIGNED_16(int16_t, block16, [16]); MpegEncContext *s = &r->s; GetBitContext *gb = &s->gb; int q_dc = rv34_qscale_tab[ r->luma_dc_quant_i[s->qscale] ], q_ac = rv34_qscale_tab[s->qscale]; uint8_t *dst = s->dest[0]; - DCTELEM *ptr = s->block[0]; + int16_t *ptr = s->block[0]; int i, j, itype, has_ac; memset(block16, 0, 16 * sizeof(*block16)); @@ -1180,7 +1179,7 @@ static int rv34_decode_inter_macroblock(RV34DecContext *r, int8_t *intra_types) MpegEncContext *s = &r->s; GetBitContext *gb = &s->gb; uint8_t *dst = s->dest[0]; - DCTELEM *ptr = s->block[0]; + int16_t *ptr = s->block[0]; int mb_pos = s->mb_x + s->mb_y * s->mb_stride; int cbp, cbp2; int q_dc, q_ac, has_ac; @@ -1220,7 +1219,7 @@ static int rv34_decode_inter_macroblock(RV34DecContext *r, int8_t *intra_types) if(r->is16){ // Only for RV34_MB_P_MIX16x16 - LOCAL_ALIGNED_16(DCTELEM, block16, [16]); + LOCAL_ALIGNED_16(int16_t, block16, [16]); memset(block16, 0, 16 * sizeof(*block16)); q_dc = rv34_qscale_tab[ r->luma_dc_quant_p[s->qscale] ]; q_ac = rv34_qscale_tab[s->qscale]; @@ -1434,7 +1433,7 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int else res = rv34_decode_intra_macroblock(r, r->intra_types + s->mb_x * 4 + 4); if(res < 0){ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_ERROR); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_ERROR); return -1; } if (++s->mb_x == s->mb_width) { @@ -1457,7 +1456,7 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int s->first_slice_line=0; s->mb_num_left--; } - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); + ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); return s->mb_y == s->mb_height; } @@ -1495,11 +1494,11 @@ av_cold int ff_rv34_decode_init(AVCodecContext *avctx) #if CONFIG_RV30_DECODER if (avctx->codec_id == AV_CODEC_ID_RV30) - ff_rv30dsp_init(&r->rdsp, &r->s.dsp); + ff_rv30dsp_init(&r->rdsp); #endif #if CONFIG_RV40_DECODER if (avctx->codec_id == AV_CODEC_ID_RV40) - ff_rv40dsp_init(&r->rdsp, &r->s.dsp); + ff_rv40dsp_init(&r->rdsp); #endif if ((ret = rv34_decoder_alloc(r)) < 0) @@ -1570,7 +1569,7 @@ static int finish_frame(AVCodecContext *avctx, AVFrame *pict) MpegEncContext *s = &r->s; int got_picture = 0; - ff_er_frame_end(s); + ff_er_frame_end(&s->er); ff_MPV_frame_end(s); s->mb_num_left = 0; @@ -1590,6 +1589,16 @@ static int finish_frame(AVCodecContext *avctx, AVFrame *pict) return got_picture; } +static AVRational update_sar(int old_w, int old_h, AVRational sar, int new_w, int new_h) +{ + // attempt to keep aspect during typical resolution switches + if (!sar.num) + sar = (AVRational){1, 1}; + + sar = av_mul_q(sar, (AVRational){new_h * old_w, new_w * old_h}); + return sar; +} + int ff_rv34_decode_frame(AVCodecContext *avctx, void *data, int *got_picture_ptr, AVPacket *avpkt) @@ -1652,7 +1661,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, if (s->mb_num_left > 0) { av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n", s->mb_num_left); - ff_er_frame_end(s); + ff_er_frame_end(&s->er); ff_MPV_frame_end(s); } @@ -1665,6 +1674,9 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, if (av_image_check_size(si.width, si.height, 0, s->avctx)) return AVERROR_INVALIDDATA; + s->avctx->sample_aspect_ratio = update_sar( + s->width, s->height, s->avctx->sample_aspect_ratio, + si.width, si.height); s->width = si.width; s->height = si.height; avcodec_set_dimensions(s->avctx, s->width, s->height); @@ -1676,7 +1688,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, s->pict_type = si.type ? si.type : AV_PICTURE_TYPE_I; if (ff_MPV_frame_start(s, s->avctx) < 0) return -1; - ff_er_frame_start(s); + ff_mpeg_er_frame_start(s); if (!r->tmp_b_block_base) { int i; @@ -1775,7 +1787,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, av_log(avctx, AV_LOG_INFO, "marking unfished frame as finished\n"); /* always mark the current frame as finished, frame-mt supports * only complete frames */ - ff_er_frame_end(s); + ff_er_frame_end(&s->er); ff_MPV_frame_end(s); s->mb_num_left = 0; ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 0); diff --git a/mythtv/external/FFmpeg/libavcodec/rv34.h b/mythtv/external/FFmpeg/libavcodec/rv34.h index bb18b45d221..475f17a496e 100644 --- a/mythtv/external/FFmpeg/libavcodec/rv34.h +++ b/mythtv/external/FFmpeg/libavcodec/rv34.h @@ -28,7 +28,6 @@ #define AVCODEC_RV34_H #include "avcodec.h" -#include "dsputil.h" #include "mpegvideo.h" #include "h264pred.h" diff --git a/mythtv/external/FFmpeg/libavcodec/rv34dsp.c b/mythtv/external/FFmpeg/libavcodec/rv34dsp.c index 86a2ffd58e2..7234ee808b8 100644 --- a/mythtv/external/FFmpeg/libavcodec/rv34dsp.c +++ b/mythtv/external/FFmpeg/libavcodec/rv34dsp.c @@ -24,7 +24,7 @@ * @file * RV30/40 decoder common dsp functions */ -#include "dsputil.h" + #include "rv34dsp.h" #include "libavutil/common.h" @@ -33,7 +33,7 @@ * @{ */ -static av_always_inline void rv34_row_transform(int temp[16], DCTELEM *block) +static av_always_inline void rv34_row_transform(int temp[16], int16_t *block) { int i; @@ -54,12 +54,12 @@ static av_always_inline void rv34_row_transform(int temp[16], DCTELEM *block) * Real Video 3.0/4.0 inverse transform + sample reconstruction * Code is almost the same as in SVQ3, only scaling is different. */ -static void rv34_idct_add_c(uint8_t *dst, ptrdiff_t stride, DCTELEM *block){ +static void rv34_idct_add_c(uint8_t *dst, ptrdiff_t stride, int16_t *block){ int temp[16]; int i; rv34_row_transform(temp, block); - memset(block, 0, 16*sizeof(DCTELEM)); + memset(block, 0, 16*sizeof(int16_t)); for(i = 0; i < 4; i++){ const int z0 = 13*(temp[4*0+i] + temp[4*2+i]) + 0x200; @@ -82,7 +82,7 @@ static void rv34_idct_add_c(uint8_t *dst, ptrdiff_t stride, DCTELEM *block){ * Code is almost the same as rv34_inv_transform() * but final coefficients are multiplied by 1.5 and have no rounding. */ -static void rv34_inv_transform_noround_c(DCTELEM *block){ +static void rv34_inv_transform_noround_c(int16_t *block){ int temp[16]; int i; @@ -115,9 +115,9 @@ static void rv34_idct_dc_add_c(uint8_t *dst, ptrdiff_t stride, int dc) } } -static void rv34_inv_transform_dc_noround_c(DCTELEM *block) +static void rv34_inv_transform_dc_noround_c(int16_t *block) { - DCTELEM dc = (13 * 13 * 3 * block[0]) >> 11; + int16_t dc = (13 * 13 * 3 * block[0]) >> 11; int i, j; for (i = 0; i < 4; i++, block += 4) @@ -128,7 +128,8 @@ static void rv34_inv_transform_dc_noround_c(DCTELEM *block) /** @} */ // transform -av_cold void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp) { +av_cold void ff_rv34dsp_init(RV34DSPContext *c) +{ c->rv34_inv_transform = rv34_inv_transform_noround_c; c->rv34_inv_transform_dc = rv34_inv_transform_dc_noround_c; @@ -136,7 +137,7 @@ av_cold void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp) { c->rv34_idct_dc_add = rv34_idct_dc_add_c; if (ARCH_ARM) - ff_rv34dsp_init_arm(c, dsp); + ff_rv34dsp_init_arm(c); if (ARCH_X86) - ff_rv34dsp_init_x86(c, dsp); + ff_rv34dsp_init_x86(c); } diff --git a/mythtv/external/FFmpeg/libavcodec/rv34dsp.h b/mythtv/external/FFmpeg/libavcodec/rv34dsp.h index f0263b12fe7..c5d4e39f4f7 100644 --- a/mythtv/external/FFmpeg/libavcodec/rv34dsp.h +++ b/mythtv/external/FFmpeg/libavcodec/rv34dsp.h @@ -28,15 +28,16 @@ #define AVCODEC_RV34DSP_H #include "dsputil.h" +#include "h264chroma.h" typedef void (*rv40_weight_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src1/*align width (8 or 16)*/, uint8_t *src2/*align width (8 or 16)*/, int w1, int w2, ptrdiff_t stride); -typedef void (*rv34_inv_transform_func)(DCTELEM *block); +typedef void (*rv34_inv_transform_func)(int16_t *block); -typedef void (*rv34_idct_add_func)(uint8_t *dst, ptrdiff_t stride, DCTELEM *block); +typedef void (*rv34_idct_add_func)(uint8_t *dst, ptrdiff_t stride, int16_t *block); typedef void (*rv34_idct_dc_add_func)(uint8_t *dst, ptrdiff_t stride, int dc); @@ -73,14 +74,14 @@ typedef struct RV34DSPContext { rv40_loop_filter_strength_func rv40_loop_filter_strength[2]; } RV34DSPContext; -void ff_rv30dsp_init(RV34DSPContext *c, DSPContext* dsp); -void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp); -void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp); +void ff_rv30dsp_init(RV34DSPContext *c); +void ff_rv34dsp_init(RV34DSPContext *c); +void ff_rv40dsp_init(RV34DSPContext *c); -void ff_rv34dsp_init_arm(RV34DSPContext *c, DSPContext *dsp); -void ff_rv34dsp_init_x86(RV34DSPContext *c, DSPContext *dsp); +void ff_rv34dsp_init_arm(RV34DSPContext *c); +void ff_rv34dsp_init_x86(RV34DSPContext *c); -void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp); -void ff_rv40dsp_init_arm(RV34DSPContext *c, DSPContext *dsp); +void ff_rv40dsp_init_x86(RV34DSPContext *c); +void ff_rv40dsp_init_arm(RV34DSPContext *c); #endif /* AVCODEC_RV34DSP_H */ diff --git a/mythtv/external/FFmpeg/libavcodec/rv40.c b/mythtv/external/FFmpeg/libavcodec/rv40.c index ff0ef91a5c4..fe3608e3a27 100644 --- a/mythtv/external/FFmpeg/libavcodec/rv40.c +++ b/mythtv/external/FFmpeg/libavcodec/rv40.c @@ -27,7 +27,6 @@ #include "libavutil/imgutils.h" #include "avcodec.h" -#include "dsputil.h" #include "mpegvideo.h" #include "golomb.h" diff --git a/mythtv/external/FFmpeg/libavcodec/rv40dsp.c b/mythtv/external/FFmpeg/libavcodec/rv40dsp.c index 944a628e201..cea4552a513 100644 --- a/mythtv/external/FFmpeg/libavcodec/rv40dsp.c +++ b/mythtv/external/FFmpeg/libavcodec/rv40dsp.c @@ -25,7 +25,7 @@ */ #include "avcodec.h" -#include "dsputil.h" +#include "h264qpel.h" #include "rv34dsp.h" #include "libavutil/avassert.h" #include "libavutil/common.h" @@ -518,19 +518,22 @@ static int rv40_v_loop_filter_strength(uint8_t *src, ptrdiff_t stride, return rv40_loop_filter_strength(src, 1, stride, beta, beta2, edge, p1, q1); } -av_cold void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp) { +av_cold void ff_rv40dsp_init(RV34DSPContext *c) +{ + H264QpelContext qpel; - ff_rv34dsp_init(c, dsp); + ff_rv34dsp_init(c); + ff_h264qpel_init(&qpel, 8); - c->put_pixels_tab[0][ 0] = dsp->put_h264_qpel_pixels_tab[0][0]; + c->put_pixels_tab[0][ 0] = qpel.put_h264_qpel_pixels_tab[0][0]; c->put_pixels_tab[0][ 1] = put_rv40_qpel16_mc10_c; - c->put_pixels_tab[0][ 2] = dsp->put_h264_qpel_pixels_tab[0][2]; + c->put_pixels_tab[0][ 2] = qpel.put_h264_qpel_pixels_tab[0][2]; c->put_pixels_tab[0][ 3] = put_rv40_qpel16_mc30_c; c->put_pixels_tab[0][ 4] = put_rv40_qpel16_mc01_c; c->put_pixels_tab[0][ 5] = put_rv40_qpel16_mc11_c; c->put_pixels_tab[0][ 6] = put_rv40_qpel16_mc21_c; c->put_pixels_tab[0][ 7] = put_rv40_qpel16_mc31_c; - c->put_pixels_tab[0][ 8] = dsp->put_h264_qpel_pixels_tab[0][8]; + c->put_pixels_tab[0][ 8] = qpel.put_h264_qpel_pixels_tab[0][8]; c->put_pixels_tab[0][ 9] = put_rv40_qpel16_mc12_c; c->put_pixels_tab[0][10] = put_rv40_qpel16_mc22_c; c->put_pixels_tab[0][11] = put_rv40_qpel16_mc32_c; @@ -538,15 +541,15 @@ av_cold void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp) { c->put_pixels_tab[0][13] = put_rv40_qpel16_mc13_c; c->put_pixels_tab[0][14] = put_rv40_qpel16_mc23_c; c->put_pixels_tab[0][15] = ff_put_rv40_qpel16_mc33_c; - c->avg_pixels_tab[0][ 0] = dsp->avg_h264_qpel_pixels_tab[0][0]; + c->avg_pixels_tab[0][ 0] = qpel.avg_h264_qpel_pixels_tab[0][0]; c->avg_pixels_tab[0][ 1] = avg_rv40_qpel16_mc10_c; - c->avg_pixels_tab[0][ 2] = dsp->avg_h264_qpel_pixels_tab[0][2]; + c->avg_pixels_tab[0][ 2] = qpel.avg_h264_qpel_pixels_tab[0][2]; c->avg_pixels_tab[0][ 3] = avg_rv40_qpel16_mc30_c; c->avg_pixels_tab[0][ 4] = avg_rv40_qpel16_mc01_c; c->avg_pixels_tab[0][ 5] = avg_rv40_qpel16_mc11_c; c->avg_pixels_tab[0][ 6] = avg_rv40_qpel16_mc21_c; c->avg_pixels_tab[0][ 7] = avg_rv40_qpel16_mc31_c; - c->avg_pixels_tab[0][ 8] = dsp->avg_h264_qpel_pixels_tab[0][8]; + c->avg_pixels_tab[0][ 8] = qpel.avg_h264_qpel_pixels_tab[0][8]; c->avg_pixels_tab[0][ 9] = avg_rv40_qpel16_mc12_c; c->avg_pixels_tab[0][10] = avg_rv40_qpel16_mc22_c; c->avg_pixels_tab[0][11] = avg_rv40_qpel16_mc32_c; @@ -554,15 +557,15 @@ av_cold void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp) { c->avg_pixels_tab[0][13] = avg_rv40_qpel16_mc13_c; c->avg_pixels_tab[0][14] = avg_rv40_qpel16_mc23_c; c->avg_pixels_tab[0][15] = ff_avg_rv40_qpel16_mc33_c; - c->put_pixels_tab[1][ 0] = dsp->put_h264_qpel_pixels_tab[1][0]; + c->put_pixels_tab[1][ 0] = qpel.put_h264_qpel_pixels_tab[1][0]; c->put_pixels_tab[1][ 1] = put_rv40_qpel8_mc10_c; - c->put_pixels_tab[1][ 2] = dsp->put_h264_qpel_pixels_tab[1][2]; + c->put_pixels_tab[1][ 2] = qpel.put_h264_qpel_pixels_tab[1][2]; c->put_pixels_tab[1][ 3] = put_rv40_qpel8_mc30_c; c->put_pixels_tab[1][ 4] = put_rv40_qpel8_mc01_c; c->put_pixels_tab[1][ 5] = put_rv40_qpel8_mc11_c; c->put_pixels_tab[1][ 6] = put_rv40_qpel8_mc21_c; c->put_pixels_tab[1][ 7] = put_rv40_qpel8_mc31_c; - c->put_pixels_tab[1][ 8] = dsp->put_h264_qpel_pixels_tab[1][8]; + c->put_pixels_tab[1][ 8] = qpel.put_h264_qpel_pixels_tab[1][8]; c->put_pixels_tab[1][ 9] = put_rv40_qpel8_mc12_c; c->put_pixels_tab[1][10] = put_rv40_qpel8_mc22_c; c->put_pixels_tab[1][11] = put_rv40_qpel8_mc32_c; @@ -570,15 +573,15 @@ av_cold void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp) { c->put_pixels_tab[1][13] = put_rv40_qpel8_mc13_c; c->put_pixels_tab[1][14] = put_rv40_qpel8_mc23_c; c->put_pixels_tab[1][15] = ff_put_rv40_qpel8_mc33_c; - c->avg_pixels_tab[1][ 0] = dsp->avg_h264_qpel_pixels_tab[1][0]; + c->avg_pixels_tab[1][ 0] = qpel.avg_h264_qpel_pixels_tab[1][0]; c->avg_pixels_tab[1][ 1] = avg_rv40_qpel8_mc10_c; - c->avg_pixels_tab[1][ 2] = dsp->avg_h264_qpel_pixels_tab[1][2]; + c->avg_pixels_tab[1][ 2] = qpel.avg_h264_qpel_pixels_tab[1][2]; c->avg_pixels_tab[1][ 3] = avg_rv40_qpel8_mc30_c; c->avg_pixels_tab[1][ 4] = avg_rv40_qpel8_mc01_c; c->avg_pixels_tab[1][ 5] = avg_rv40_qpel8_mc11_c; c->avg_pixels_tab[1][ 6] = avg_rv40_qpel8_mc21_c; c->avg_pixels_tab[1][ 7] = avg_rv40_qpel8_mc31_c; - c->avg_pixels_tab[1][ 8] = dsp->avg_h264_qpel_pixels_tab[1][8]; + c->avg_pixels_tab[1][ 8] = qpel.avg_h264_qpel_pixels_tab[1][8]; c->avg_pixels_tab[1][ 9] = avg_rv40_qpel8_mc12_c; c->avg_pixels_tab[1][10] = avg_rv40_qpel8_mc22_c; c->avg_pixels_tab[1][11] = avg_rv40_qpel8_mc32_c; @@ -605,7 +608,7 @@ av_cold void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp) { c->rv40_loop_filter_strength[1] = rv40_v_loop_filter_strength; if (ARCH_X86) - ff_rv40dsp_init_x86(c, dsp); + ff_rv40dsp_init_x86(c); if (ARCH_ARM) - ff_rv40dsp_init_arm(c, dsp); + ff_rv40dsp_init_arm(c); } diff --git a/mythtv/external/FFmpeg/libavcodec/s302m.c b/mythtv/external/FFmpeg/libavcodec/s302m.c index a06192c488b..d641c2ec6af 100644 --- a/mythtv/external/FFmpeg/libavcodec/s302m.c +++ b/mythtv/external/FFmpeg/libavcodec/s302m.c @@ -28,10 +28,6 @@ #define AES3_HEADER_LEN 4 -typedef struct S302MDecodeContext { - AVFrame frame; -} S302MDecodeContext; - static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t *buf, int buf_size) { @@ -95,7 +91,7 @@ static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t *buf, static int s302m_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { - S302MDecodeContext *s = avctx->priv_data; + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int block_size, ret; @@ -109,16 +105,16 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data, /* get output buffer */ block_size = (avctx->bits_per_coded_sample + 4) / 4; - s->frame.nb_samples = 2 * (buf_size / block_size) / avctx->channels; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = 2 * (buf_size / block_size) / avctx->channels; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - buf_size = (s->frame.nb_samples * avctx->channels / 2) * block_size; + buf_size = (frame->nb_samples * avctx->channels / 2) * block_size; if (avctx->bits_per_coded_sample == 24) { - uint32_t *o = (uint32_t *)s->frame.data[0]; + uint32_t *o = (uint32_t *)frame->data[0]; for (; buf_size > 6; buf_size -= 7) { *o++ = (ff_reverse[buf[2]] << 24) | (ff_reverse[buf[1]] << 16) | @@ -130,7 +126,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data, buf += 7; } } else if (avctx->bits_per_coded_sample == 20) { - uint32_t *o = (uint32_t *)s->frame.data[0]; + uint32_t *o = (uint32_t *)frame->data[0]; for (; buf_size > 5; buf_size -= 6) { *o++ = (ff_reverse[buf[2] & 0xf0] << 28) | (ff_reverse[buf[1]] << 20) | @@ -141,7 +137,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data, buf += 6; } } else { - uint16_t *o = (uint16_t *)s->frame.data[0]; + uint16_t *o = (uint16_t *)frame->data[0]; for (; buf_size > 4; buf_size -= 5) { *o++ = (ff_reverse[buf[1]] << 8) | ff_reverse[buf[0]]; @@ -152,29 +148,15 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data, } } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return avpkt->size; } -static int s302m_decode_init(AVCodecContext *avctx) -{ - S302MDecodeContext *s = avctx->priv_data; - - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - - return 0; -} - - AVCodec ff_s302m_decoder = { .name = "s302m", .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_S302M, - .priv_data_size = sizeof(S302MDecodeContext), - .init = s302m_decode_init, .decode = s302m_decode_frame, .capabilities = CODEC_CAP_DR1, .long_name = NULL_IF_CONFIG_SMALL("SMPTE 302M"), diff --git a/mythtv/external/FFmpeg/libavcodec/samidec.c b/mythtv/external/FFmpeg/libavcodec/samidec.c index c04b8a336e3..39ac6082bc6 100644 --- a/mythtv/external/FFmpeg/libavcodec/samidec.c +++ b/mythtv/external/FFmpeg/libavcodec/samidec.c @@ -52,7 +52,7 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src) p = av_stristr(p, " + if (p[2] != '>' && !av_isspace(p[2])) { // avoid confusion with tags such as
             p++;
             continue;
         }
@@ -70,7 +70,7 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
         }
 
         /* if empty event -> skip subtitle */
-        while (isspace(*p))
+        while (av_isspace(*p))
             p++;
         if (!strncmp(p, " ", 6)) {
             ret = -1;
@@ -80,7 +80,7 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
         /* extract the text, stripping most of the tags */
         while (*p) {
             if (*p == '<') {
-                if (!av_strncasecmp(p, "' || isspace(p[2])))
+                if (!av_strncasecmp(p, "' || av_isspace(p[2])))
                     break;
                 if (!av_strncasecmp(p, "')
                     p++;
             }
-            if (!isspace(*p))
+            if (!av_isspace(*p))
                 av_bprint_chars(dst, *p, 1);
             else if (!prev_chr_is_space)
                 av_bprint_chars(dst, ' ', 1);
-            prev_chr_is_space = isspace(*p);
+            prev_chr_is_space = av_isspace(*p);
             p++;
         }
     }
diff --git a/mythtv/external/FFmpeg/libavcodec/sanm.c b/mythtv/external/FFmpeg/libavcodec/sanm.c
index e317b33b1f8..61c30060687 100644
--- a/mythtv/external/FFmpeg/libavcodec/sanm.c
+++ b/mythtv/external/FFmpeg/libavcodec/sanm.c
@@ -23,12 +23,13 @@
 // #define DEBUG 1
 
 #include "avcodec.h"
+#include "copy_block.h"
 #include "bytestream.h"
 #include "internal.h"
 #include "libavutil/bswap.h"
 #include "libavutil/imgutils.h"
-#include "libavcodec/dsputil.h"
 #include "sanm_data.h"
+#include "libavutil/avassert.h"
 
 #define NGLYPHS 256
 
@@ -230,6 +231,9 @@ static void destroy_buffers(SANMVideoContext *ctx)
     av_freep(&ctx->frm2);
     av_freep(&ctx->stored_frame);
     av_freep(&ctx->rle_buf);
+    ctx->frm0_size =
+    ctx->frm1_size =
+    ctx->frm2_size = 0;
 }
 
 static av_cold int init_buffers(SANMVideoContext *ctx)
@@ -618,6 +622,16 @@ static int process_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *prev1,
     } else {
         int mx = motion_vectors[code][0];
         int my = motion_vectors[code][1];
+        int index = prev2 - (const uint8_t*)ctx->frm2;
+
+        av_assert2(index >= 0 && index < (ctx->buf_size>>1));
+
+        if (index < - mx - my*stride ||
+            (ctx->buf_size>>1) - index < mx + size + (my + size - 1)*stride) {
+            av_log(ctx->avctx, AV_LOG_ERROR, "MV is invalid \n");
+            return AVERROR_INVALIDDATA;
+        }
+
         for (k = 0; k < size; k++)
             memcpy(dst + k * stride, prev2 + mx + (my + k) * stride, size);
     }
@@ -662,8 +676,7 @@ static int old_codec47(SANMVideoContext *ctx, int top,
         if (bytestream2_get_bytes_left(&ctx->gb) < width * height)
             return AVERROR_INVALIDDATA;
         for (j = 0; j < height; j++) {
-            for (i = 0; i < width; i++)
-                bytestream2_get_bufferu(&ctx->gb, dst, width);
+            bytestream2_get_bufferu(&ctx->gb, dst, width);
             dst += stride;
         }
         break;
@@ -726,13 +739,19 @@ static int process_frame_obj(SANMVideoContext *ctx)
     w     = bytestream2_get_le16u(&ctx->gb);
     h     = bytestream2_get_le16u(&ctx->gb);
 
+    if (!w || !h) {
+        av_log(ctx->avctx, AV_LOG_ERROR, "dimensions are invalid\n");
+        return AVERROR_INVALIDDATA;
+    }
+
     if (ctx->width < left + w || ctx->height < top + h) {
         if (av_image_check_size(FFMAX(left + w, ctx->width),
                                 FFMAX(top  + h, ctx->height), 0, ctx->avctx) < 0)
             return AVERROR_INVALIDDATA;
         avcodec_set_dimensions(ctx->avctx, FFMAX(left + w, ctx->width),
                                            FFMAX(top  + h, ctx->height));
-        init_sizes(ctx, left + w, top + h);
+        init_sizes(ctx, FFMAX(left + w, ctx->width),
+                        FFMAX(top  + h, ctx->height));
         if (init_buffers(ctx)) {
             av_log(ctx->avctx, AV_LOG_ERROR, "error resizing buffers\n");
             return AVERROR(ENOMEM);
diff --git a/mythtv/external/FFmpeg/libavcodec/sbr.h b/mythtv/external/FFmpeg/libavcodec/sbr.h
index 1e413967a9e..e28fccda092 100644
--- a/mythtv/external/FFmpeg/libavcodec/sbr.h
+++ b/mythtv/external/FFmpeg/libavcodec/sbr.h
@@ -34,6 +34,8 @@
 #include "aacps.h"
 #include "sbrdsp.h"
 
+typedef struct AACContext AACContext;
+
 /**
  * Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header.
  */
@@ -108,10 +110,31 @@ typedef struct SBRData {
     /** @} */
 } SBRData;
 
+typedef struct SpectralBandReplication SpectralBandReplication;
+
+/**
+ * aacsbr functions pointers
+ */
+typedef struct AACSBRContext {
+    int (*sbr_lf_gen)(AACContext *ac, SpectralBandReplication *sbr,
+                      float X_low[32][40][2], const float W[2][32][32][2],
+                      int buf_idx);
+    void (*sbr_hf_assemble)(float Y1[38][64][2],
+                            const float X_high[64][40][2],
+                            SpectralBandReplication *sbr, SBRData *ch_data,
+                            const int e_a[2]);
+    int (*sbr_x_gen)(SpectralBandReplication *sbr, float X[2][38][64],
+                     const float Y0[38][64][2], const float Y1[38][64][2],
+                     const float X_low[32][40][2], int ch);
+    void (*sbr_hf_inverse_filter)(SBRDSPContext *dsp,
+                                  float (*alpha0)[2], float (*alpha1)[2],
+                                  const float X_low[32][40][2], int k0);
+} AACSBRContext;
+
 /**
  * Spectral Band Replication
  */
-typedef struct SpectralBandReplication {
+struct SpectralBandReplication {
     int                sample_rate;
     int                start;
     int                reset;
@@ -184,6 +207,7 @@ typedef struct SpectralBandReplication {
     FFTContext         mdct_ana;
     FFTContext         mdct;
     SBRDSPContext      dsp;
-} SpectralBandReplication;
+    AACSBRContext      c;
+};
 
 #endif /* AVCODEC_SBR_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/sbrdsp.c b/mythtv/external/FFmpeg/libavcodec/sbrdsp.c
index 781ec83fe84..6fede7981f2 100644
--- a/mythtv/external/FFmpeg/libavcodec/sbrdsp.c
+++ b/mythtv/external/FFmpeg/libavcodec/sbrdsp.c
@@ -245,4 +245,6 @@ av_cold void ff_sbrdsp_init(SBRDSPContext *s)
         ff_sbrdsp_init_arm(s);
     if (ARCH_X86)
         ff_sbrdsp_init_x86(s);
+    if (ARCH_MIPS)
+        ff_sbrdsp_init_mips(s);
 }
diff --git a/mythtv/external/FFmpeg/libavcodec/sbrdsp.h b/mythtv/external/FFmpeg/libavcodec/sbrdsp.h
index 07235c68e67..38311357c63 100644
--- a/mythtv/external/FFmpeg/libavcodec/sbrdsp.h
+++ b/mythtv/external/FFmpeg/libavcodec/sbrdsp.h
@@ -47,5 +47,6 @@ extern const float ff_sbr_noise_table[][2];
 void ff_sbrdsp_init(SBRDSPContext *s);
 void ff_sbrdsp_init_arm(SBRDSPContext *s);
 void ff_sbrdsp_init_x86(SBRDSPContext *s);
+void ff_sbrdsp_init_mips(SBRDSPContext *s);
 
 #endif /* AVCODEC_SBRDSP_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/sgidec.c b/mythtv/external/FFmpeg/libavcodec/sgidec.c
index 555b5044afb..51bd5d6f8d0 100644
--- a/mythtv/external/FFmpeg/libavcodec/sgidec.c
+++ b/mythtv/external/FFmpeg/libavcodec/sgidec.c
@@ -169,17 +169,17 @@ static int decode_frame(AVCodecContext *avctx,
     }
 
     /* Test for SGI magic. */
-    if (bytestream2_get_be16(&s->g) != SGI_MAGIC) {
+    if (bytestream2_get_be16u(&s->g) != SGI_MAGIC) {
         av_log(avctx, AV_LOG_ERROR, "bad magic number\n");
         return AVERROR_INVALIDDATA;
     }
 
-    rle                  = bytestream2_get_byte(&s->g);
-    s->bytes_per_channel = bytestream2_get_byte(&s->g);
-    dimension            = bytestream2_get_be16(&s->g);
-    s->width             = bytestream2_get_be16(&s->g);
-    s->height            = bytestream2_get_be16(&s->g);
-    s->depth             = bytestream2_get_be16(&s->g);
+    rle                  = bytestream2_get_byteu(&s->g);
+    s->bytes_per_channel = bytestream2_get_byteu(&s->g);
+    dimension            = bytestream2_get_be16u(&s->g);
+    s->width             = bytestream2_get_be16u(&s->g);
+    s->height            = bytestream2_get_be16u(&s->g);
+    s->depth             = bytestream2_get_be16u(&s->g);
 
     if (s->bytes_per_channel != 1 && (s->bytes_per_channel != 2 || rle)) {
         av_log(avctx, AV_LOG_ERROR, "wrong channel number\n");
diff --git a/mythtv/external/FFmpeg/libavcodec/sh4/Makefile b/mythtv/external/FFmpeg/libavcodec/sh4/Makefile
index aa17eabd6e8..f907408d9fb 100644
--- a/mythtv/external/FFmpeg/libavcodec/sh4/Makefile
+++ b/mythtv/external/FFmpeg/libavcodec/sh4/Makefile
@@ -1,3 +1,5 @@
 OBJS += sh4/dsputil_align.o                                             \
         sh4/dsputil_sh4.o                                               \
         sh4/idct_sh4.o                                                  \
+
+OBJS-$(CONFIG_H264CHROMA)               += sh4/h264chroma_init.o        \
diff --git a/mythtv/external/FFmpeg/libavcodec/sh4/dsputil_align.c b/mythtv/external/FFmpeg/libavcodec/sh4/dsputil_align.c
index 88a86ac875c..46981f6c87e 100644
--- a/mythtv/external/FFmpeg/libavcodec/sh4/dsputil_align.c
+++ b/mythtv/external/FFmpeg/libavcodec/sh4/dsputil_align.c
@@ -20,9 +20,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-
+#include "libavutil/attributes.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/dsputil.h"
+#include "libavcodec/rnd_avg.h"
 #include "dsputil_sh4.h"
 
 
@@ -65,34 +66,6 @@
                 dest+=stride; \
         } while(--height)
 
-
-#define         OP      put
-
-static void put_pixels4_c(uint8_t *dest,const uint8_t *ref, const int stride,int height)
-{
-        switch((int)ref&3){
-        case 0: OP_C40(); return;
-        case 1: OP_C4(1); return;
-        case 2: OP_C4(2); return;
-        case 3: OP_C4(3); return;
-        }
-}
-
-#undef          OP
-#define         OP      avg
-
-static void avg_pixels4_c(uint8_t *dest,const uint8_t *ref, const int stride,int height)
-{
-        switch((int)ref&3){
-        case 0: OP_C40(); return;
-        case 1: OP_C4(1); return;
-        case 2: OP_C4(2); return;
-        case 3: OP_C4(3); return;
-        }
-}
-
-#undef          OP
-
 #define         OP_C(ofs,sz,avg2) \
 { \
         ref-=ofs; \
@@ -262,7 +235,7 @@ if (sz==16) { \
 
 #define         DEFFUNC(op,rnd,xy,sz,OP_N,avgfunc) \
 static void op##_##rnd##_pixels##sz##_##xy (uint8_t * dest, const uint8_t * ref, \
-                                const int stride, int height) \
+                                const ptrdiff_t stride, int height) \
 { \
         switch((int)ref&3) { \
         case 0:OP_N##0(sz,rnd##_##avgfunc); return; \
@@ -294,11 +267,8 @@ DEFFUNC(put,no_rnd,xy,16,OP_XY,PACK)
 
 DEFFUNC(avg,   rnd,o,8,OP_C,avg32)
 DEFFUNC(avg,   rnd,x,8,OP_X,avg32)
-DEFFUNC(avg,no_rnd,x,8,OP_X,avg32)
 DEFFUNC(avg,   rnd,y,8,OP_Y,avg32)
-DEFFUNC(avg,no_rnd,y,8,OP_Y,avg32)
 DEFFUNC(avg,   rnd,xy,8,OP_XY,PACK)
-DEFFUNC(avg,no_rnd,xy,8,OP_XY,PACK)
 DEFFUNC(avg,   rnd,o,16,OP_C,avg32)
 DEFFUNC(avg,   rnd,x,16,OP_X,avg32)
 DEFFUNC(avg,no_rnd,x,16,OP_X,avg32)
@@ -311,7 +281,6 @@ DEFFUNC(avg,no_rnd,xy,16,OP_XY,PACK)
 
 #define         put_no_rnd_pixels8_o     put_rnd_pixels8_o
 #define         put_no_rnd_pixels16_o    put_rnd_pixels16_o
-#define         avg_no_rnd_pixels8_o     avg_rnd_pixels8_o
 #define         avg_no_rnd_pixels16_o    avg_rnd_pixels16_o
 
 #define         put_pixels8_c            put_rnd_pixels8_o
@@ -320,7 +289,6 @@ DEFFUNC(avg,no_rnd,xy,16,OP_XY,PACK)
 #define         avg_pixels16_c           avg_rnd_pixels16_o
 #define         put_no_rnd_pixels8_c     put_rnd_pixels8_o
 #define         put_no_rnd_pixels16_c    put_rnd_pixels16_o
-#define         avg_no_rnd_pixels8_c     avg_rnd_pixels8_o
 #define         avg_no_rnd_pixels16_c    avg_rnd_pixels16_o
 
 #define         QPEL
@@ -331,7 +299,7 @@ DEFFUNC(avg,no_rnd,xy,16,OP_XY,PACK)
 
 #endif
 
-void ff_dsputil_init_align(DSPContext* c, AVCodecContext *avctx)
+av_cold void ff_dsputil_init_align(DSPContext *c, AVCodecContext *avctx)
 {
         const int high_bit_depth = avctx->bits_per_raw_sample > 8;
 
@@ -363,14 +331,10 @@ void ff_dsputil_init_align(DSPContext* c, AVCodecContext *avctx)
         c->avg_pixels_tab[1][2] = avg_rnd_pixels8_y;
         c->avg_pixels_tab[1][3] = avg_rnd_pixels8_xy;
 
-        c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_o;
-        c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x;
-        c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y;
-        c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy;
-        c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_o;
-        c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x;
-        c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y;
-        c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy;
+        c->avg_no_rnd_pixels_tab[0] = avg_no_rnd_pixels16_o;
+        c->avg_no_rnd_pixels_tab[1] = avg_no_rnd_pixels16_x;
+        c->avg_no_rnd_pixels_tab[2] = avg_no_rnd_pixels16_y;
+        c->avg_no_rnd_pixels_tab[3] = avg_no_rnd_pixels16_xy;
         }
 
 #ifdef QPEL
@@ -405,24 +369,7 @@ void ff_dsputil_init_align(DSPContext* c, AVCodecContext *avctx)
     dspfunc(avg_qpel, 1, 8);
     /* dspfunc(avg_no_rnd_qpel, 1, 8); */
 
-    if (!high_bit_depth) {
-    dspfunc(put_h264_qpel, 0, 16);
-    dspfunc(put_h264_qpel, 1, 8);
-    dspfunc(put_h264_qpel, 2, 4);
-    dspfunc(avg_h264_qpel, 0, 16);
-    dspfunc(avg_h264_qpel, 1, 8);
-    dspfunc(avg_h264_qpel, 2, 4);
-    }
-
 #undef dspfunc
-    if (!high_bit_depth) {
-    c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_sh4;
-    c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_sh4;
-    c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_sh4;
-    c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_sh4;
-    c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_sh4;
-    c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_sh4;
-    }
 
     c->put_mspel_pixels_tab[0]= put_mspel8_mc00_sh4;
     c->put_mspel_pixels_tab[1]= put_mspel8_mc10_sh4;
diff --git a/mythtv/external/FFmpeg/libavcodec/sh4/dsputil_sh4.c b/mythtv/external/FFmpeg/libavcodec/sh4/dsputil_sh4.c
index 7deab41d623..6e19fa09586 100644
--- a/mythtv/external/FFmpeg/libavcodec/sh4/dsputil_sh4.c
+++ b/mythtv/external/FFmpeg/libavcodec/sh4/dsputil_sh4.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/attributes.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/dsputil.h"
 #include "dsputil_sh4.h"
@@ -47,12 +48,12 @@ static void memzero_align8(void *dst,size_t size)
         fp_single_leave(fpscr);
 }
 
-static void clear_blocks_sh4(DCTELEM *blocks)
+static void clear_blocks_sh4(int16_t *blocks)
 {
-        memzero_align8(blocks,sizeof(DCTELEM)*6*64);
+        memzero_align8(blocks,sizeof(int16_t)*6*64);
 }
 
-static void idct_put(uint8_t *dest, int line_size, DCTELEM *block)
+static void idct_put(uint8_t *dest, int line_size, int16_t *block)
 {
         int i;
         uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
@@ -70,7 +71,7 @@ static void idct_put(uint8_t *dest, int line_size, DCTELEM *block)
                 block+=8;
         }
 }
-static void idct_add(uint8_t *dest, int line_size, DCTELEM *block)
+static void idct_add(uint8_t *dest, int line_size, int16_t *block)
 {
         int i;
         uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
@@ -89,7 +90,7 @@ static void idct_add(uint8_t *dest, int line_size, DCTELEM *block)
         }
 }
 
-void ff_dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx)
+av_cold void ff_dsputil_init_sh4(DSPContext *c, AVCodecContext *avctx)
 {
         const int idct_algo= avctx->idct_algo;
         const int high_bit_depth = avctx->bits_per_raw_sample > 8;
diff --git a/mythtv/external/FFmpeg/libavcodec/sh4/dsputil_sh4.h b/mythtv/external/FFmpeg/libavcodec/sh4/dsputil_sh4.h
index f2cb11e3789..1c041ae27dc 100644
--- a/mythtv/external/FFmpeg/libavcodec/sh4/dsputil_sh4.h
+++ b/mythtv/external/FFmpeg/libavcodec/sh4/dsputil_sh4.h
@@ -22,7 +22,7 @@
 #include "libavcodec/avcodec.h"
 #include "libavcodec/dsputil.h"
 
-void ff_idct_sh4(DCTELEM *block);
+void ff_idct_sh4(int16_t *block);
 void ff_dsputil_init_align(DSPContext* c, AVCodecContext *avctx);
 
 #endif /* AVCODEC_SH4_DSPUTIL_SH4_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/sh4/h264chroma_init.c b/mythtv/external/FFmpeg/libavcodec/sh4/h264chroma_init.c
new file mode 100644
index 00000000000..d15f0ae34e1
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/sh4/h264chroma_init.c
@@ -0,0 +1,132 @@
+/*
+ * aligned/packed access motion
+ *
+ * Copyright (c) 2001-2003 BERO 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+
+#include "libavutil/attributes.h"
+#include "libavcodec/h264chroma.h"
+
+#define H264_CHROMA_MC(OPNAME, OP)\
+static void OPNAME ## h264_chroma_mc2_sh4(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
+    const int A=(8-x)*(8-y);\
+    const int B=(  x)*(8-y);\
+    const int C=(8-x)*(  y);\
+    const int D=(  x)*(  y);\
+    \
+    assert(x<8 && y<8 && x>=0 && y>=0);\
+\
+    do {\
+        int t0,t1,t2,t3; \
+        uint8_t *s0 = src; \
+        uint8_t *s1 = src+stride; \
+        t0 = *s0++; t2 = *s1++; \
+        t1 = *s0++; t3 = *s1++; \
+        OP(dst[0], (A*t0 + B*t1 + C*t2 + D*t3));\
+        t0 = *s0++; t2 = *s1++; \
+        OP(dst[1], (A*t1 + B*t0 + C*t3 + D*t2));\
+        dst+= stride;\
+        src+= stride;\
+    }while(--h);\
+}\
+\
+static void OPNAME ## h264_chroma_mc4_sh4(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
+    const int A=(8-x)*(8-y);\
+    const int B=(  x)*(8-y);\
+    const int C=(8-x)*(  y);\
+    const int D=(  x)*(  y);\
+    \
+    assert(x<8 && y<8 && x>=0 && y>=0);\
+\
+    do {\
+        int t0,t1,t2,t3; \
+        uint8_t *s0 = src; \
+        uint8_t *s1 = src+stride; \
+        t0 = *s0++; t2 = *s1++; \
+        t1 = *s0++; t3 = *s1++; \
+        OP(dst[0], (A*t0 + B*t1 + C*t2 + D*t3));\
+        t0 = *s0++; t2 = *s1++; \
+        OP(dst[1], (A*t1 + B*t0 + C*t3 + D*t2));\
+        t1 = *s0++; t3 = *s1++; \
+        OP(dst[2], (A*t0 + B*t1 + C*t2 + D*t3));\
+        t0 = *s0++; t2 = *s1++; \
+        OP(dst[3], (A*t1 + B*t0 + C*t3 + D*t2));\
+        dst+= stride;\
+        src+= stride;\
+    }while(--h);\
+}\
+\
+static void OPNAME ## h264_chroma_mc8_sh4(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
+    const int A=(8-x)*(8-y);\
+    const int B=(  x)*(8-y);\
+    const int C=(8-x)*(  y);\
+    const int D=(  x)*(  y);\
+    \
+    assert(x<8 && y<8 && x>=0 && y>=0);\
+\
+    do {\
+        int t0,t1,t2,t3; \
+        uint8_t *s0 = src; \
+        uint8_t *s1 = src+stride; \
+        t0 = *s0++; t2 = *s1++; \
+        t1 = *s0++; t3 = *s1++; \
+        OP(dst[0], (A*t0 + B*t1 + C*t2 + D*t3));\
+        t0 = *s0++; t2 = *s1++; \
+        OP(dst[1], (A*t1 + B*t0 + C*t3 + D*t2));\
+        t1 = *s0++; t3 = *s1++; \
+        OP(dst[2], (A*t0 + B*t1 + C*t2 + D*t3));\
+        t0 = *s0++; t2 = *s1++; \
+        OP(dst[3], (A*t1 + B*t0 + C*t3 + D*t2));\
+        t1 = *s0++; t3 = *s1++; \
+        OP(dst[4], (A*t0 + B*t1 + C*t2 + D*t3));\
+        t0 = *s0++; t2 = *s1++; \
+        OP(dst[5], (A*t1 + B*t0 + C*t3 + D*t2));\
+        t1 = *s0++; t3 = *s1++; \
+        OP(dst[6], (A*t0 + B*t1 + C*t2 + D*t3));\
+        t0 = *s0++; t2 = *s1++; \
+        OP(dst[7], (A*t1 + B*t0 + C*t3 + D*t2));\
+        dst+= stride;\
+        src+= stride;\
+    }while(--h);\
+}
+
+#define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
+#define op_put(a, b) a = (((b) + 32)>>6)
+
+H264_CHROMA_MC(put_       , op_put)
+H264_CHROMA_MC(avg_       , op_avg)
+#undef op_avg
+#undef op_put
+
+av_cold void ff_h264chroma_init_sh4(H264ChromaContext *c, int bit_depth)
+{
+    const int high_bit_depth = bit_depth > 8;
+
+    if (!high_bit_depth) {
+    c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_sh4;
+    c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_sh4;
+    c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_sh4;
+    c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_sh4;
+    c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_sh4;
+    c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_sh4;
+    }
+}
diff --git a/mythtv/external/FFmpeg/libavcodec/sh4/idct_sh4.c b/mythtv/external/FFmpeg/libavcodec/sh4/idct_sh4.c
index e54c3308578..d4e87110971 100644
--- a/mythtv/external/FFmpeg/libavcodec/sh4/idct_sh4.c
+++ b/mythtv/external/FFmpeg/libavcodec/sh4/idct_sh4.c
@@ -20,7 +20,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavcodec/dsputil.h"
 #include "dsputil_sh4.h"
 #include "sh4.h"
 
@@ -89,7 +88,7 @@ static const float odd_table[] __attribute__ ((aligned(8))) = {
 
 //optimized
 
-void ff_idct_sh4(DCTELEM *block)
+void ff_idct_sh4(int16_t *block)
 {
         DEFREG;
 
diff --git a/mythtv/external/FFmpeg/libavcodec/sh4/qpel.c b/mythtv/external/FFmpeg/libavcodec/sh4/qpel.c
index dab834f4ab5..1a5a4cd88d3 100644
--- a/mythtv/external/FFmpeg/libavcodec/sh4/qpel.c
+++ b/mythtv/external/FFmpeg/libavcodec/sh4/qpel.c
@@ -22,6 +22,8 @@
  */
 
 #include "libavutil/common.h"
+#include "libavcodec/copy_block.h"
+#include "libavcodec/rnd_avg.h"
 
 #define PIXOP2(OPNAME, OP) \
 \
@@ -359,97 +361,6 @@ static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y
     }while(--h);
 }
 
-#define H264_CHROMA_MC(OPNAME, OP)\
-static void OPNAME ## h264_chroma_mc2_sh4(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
-    const int A=(8-x)*(8-y);\
-    const int B=(  x)*(8-y);\
-    const int C=(8-x)*(  y);\
-    const int D=(  x)*(  y);\
-    \
-    assert(x<8 && y<8 && x>=0 && y>=0);\
-\
-    do {\
-        int t0,t1,t2,t3; \
-        uint8_t *s0 = src; \
-        uint8_t *s1 = src+stride; \
-        t0 = *s0++; t2 = *s1++; \
-        t1 = *s0++; t3 = *s1++; \
-        OP(dst[0], (A*t0 + B*t1 + C*t2 + D*t3));\
-        t0 = *s0++; t2 = *s1++; \
-        OP(dst[1], (A*t1 + B*t0 + C*t3 + D*t2));\
-        dst+= stride;\
-        src+= stride;\
-    }while(--h);\
-}\
-\
-static void OPNAME ## h264_chroma_mc4_sh4(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
-    const int A=(8-x)*(8-y);\
-    const int B=(  x)*(8-y);\
-    const int C=(8-x)*(  y);\
-    const int D=(  x)*(  y);\
-    \
-    assert(x<8 && y<8 && x>=0 && y>=0);\
-\
-    do {\
-        int t0,t1,t2,t3; \
-        uint8_t *s0 = src; \
-        uint8_t *s1 = src+stride; \
-        t0 = *s0++; t2 = *s1++; \
-        t1 = *s0++; t3 = *s1++; \
-        OP(dst[0], (A*t0 + B*t1 + C*t2 + D*t3));\
-        t0 = *s0++; t2 = *s1++; \
-        OP(dst[1], (A*t1 + B*t0 + C*t3 + D*t2));\
-        t1 = *s0++; t3 = *s1++; \
-        OP(dst[2], (A*t0 + B*t1 + C*t2 + D*t3));\
-        t0 = *s0++; t2 = *s1++; \
-        OP(dst[3], (A*t1 + B*t0 + C*t3 + D*t2));\
-        dst+= stride;\
-        src+= stride;\
-    }while(--h);\
-}\
-\
-static void OPNAME ## h264_chroma_mc8_sh4(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
-    const int A=(8-x)*(8-y);\
-    const int B=(  x)*(8-y);\
-    const int C=(8-x)*(  y);\
-    const int D=(  x)*(  y);\
-    \
-    assert(x<8 && y<8 && x>=0 && y>=0);\
-\
-    do {\
-        int t0,t1,t2,t3; \
-        uint8_t *s0 = src; \
-        uint8_t *s1 = src+stride; \
-        t0 = *s0++; t2 = *s1++; \
-        t1 = *s0++; t3 = *s1++; \
-        OP(dst[0], (A*t0 + B*t1 + C*t2 + D*t3));\
-        t0 = *s0++; t2 = *s1++; \
-        OP(dst[1], (A*t1 + B*t0 + C*t3 + D*t2));\
-        t1 = *s0++; t3 = *s1++; \
-        OP(dst[2], (A*t0 + B*t1 + C*t2 + D*t3));\
-        t0 = *s0++; t2 = *s1++; \
-        OP(dst[3], (A*t1 + B*t0 + C*t3 + D*t2));\
-        t1 = *s0++; t3 = *s1++; \
-        OP(dst[4], (A*t0 + B*t1 + C*t2 + D*t3));\
-        t0 = *s0++; t2 = *s1++; \
-        OP(dst[5], (A*t1 + B*t0 + C*t3 + D*t2));\
-        t1 = *s0++; t3 = *s1++; \
-        OP(dst[6], (A*t0 + B*t1 + C*t2 + D*t3));\
-        t0 = *s0++; t2 = *s1++; \
-        OP(dst[7], (A*t1 + B*t0 + C*t3 + D*t2));\
-        dst+= stride;\
-        src+= stride;\
-    }while(--h);\
-}
-
-#define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
-#define op_put(a, b) a = (((b) + 32)>>6)
-
-H264_CHROMA_MC(put_       , op_put)
-H264_CHROMA_MC(avg_       , op_avg)
-#undef op_avg
-#undef op_put
-
 #define QPEL_MC(r, OPNAME, RND, OP) \
 static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
     uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
@@ -842,407 +753,6 @@ QPEL_MC(0, avg_       , _       , op_avg)
 #undef op_put
 #undef op_put_no_rnd
 
-#define H264_LOWPASS(OPNAME, OP, OP2) \
-static inline void OPNAME ## h264_qpel_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride,int w,int h){\
-    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
-    do {\
-        int srcB,srcA,src0,src1,src2,src3,src4,src5,src6;\
-        uint8_t *s = src-2;\
-        srcB = *s++;\
-        srcA = *s++;\
-        src0 = *s++;\
-        src1 = *s++;\
-        src2 = *s++;\
-        src3 = *s++;\
-        OP(dst[0], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
-        src4 = *s++;\
-        OP(dst[1], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
-        src5 = *s++;\
-        OP(dst[2], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
-        src6 = *s++;\
-        OP(dst[3], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
-      if (w>4) { /* it optimized */ \
-        int src7,src8,src9,src10; \
-        src7 = *s++;\
-        OP(dst[4], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
-        src8 = *s++;\
-        OP(dst[5], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
-        src9 = *s++;\
-        OP(dst[6], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
-        src10 = *s++;\
-        OP(dst[7], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
-       if (w>8) { \
-        int src11,src12,src13,src14,src15,src16,src17,src18; \
-        src11 = *s++;\
-        OP(dst[8] , (src8 +src9 )*20 - (src7 +src10)*5 + (src6 +src11));\
-        src12 = *s++;\
-        OP(dst[9] , (src9 +src10)*20 - (src8 +src11)*5 + (src7 +src12));\
-        src13 = *s++;\
-        OP(dst[10], (src10+src11)*20 - (src9 +src12)*5 + (src8 +src13));\
-        src14 = *s++;\
-        OP(dst[11], (src11+src12)*20 - (src10+src13)*5 + (src9 +src14));\
-        src15 = *s++;\
-        OP(dst[12], (src12+src13)*20 - (src11+src14)*5 + (src10+src15));\
-        src16 = *s++;\
-        OP(dst[13], (src13+src14)*20 - (src12+src15)*5 + (src11+src16));\
-        src17 = *s++;\
-        OP(dst[14], (src14+src15)*20 - (src13+src16)*5 + (src12+src17));\
-        src18 = *s++;\
-        OP(dst[15], (src15+src16)*20 - (src14+src17)*5 + (src13+src18));\
-       } \
-      } \
-        dst+=dstStride;\
-        src+=srcStride;\
-    }while(--h);\
-}\
-\
-static inline void OPNAME ## h264_qpel_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride,int w,int h){\
-    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
-    do{\
-        int srcB,srcA,src0,src1,src2,src3,src4,src5,src6;\
-        uint8_t *s = src-2*srcStride,*d=dst;\
-        srcB = *s; s+=srcStride;\
-        srcA = *s; s+=srcStride;\
-        src0 = *s; s+=srcStride;\
-        src1 = *s; s+=srcStride;\
-        src2 = *s; s+=srcStride;\
-        src3 = *s; s+=srcStride;\
-        OP(*d, (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));d+=dstStride;\
-        src4 = *s; s+=srcStride;\
-        OP(*d, (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));d+=dstStride;\
-        src5 = *s; s+=srcStride;\
-        OP(*d, (src2+src3)*20 - (src1+src4)*5 + (src0+src5));d+=dstStride;\
-        src6 = *s; s+=srcStride;\
-        OP(*d, (src3+src4)*20 - (src2+src5)*5 + (src1+src6));d+=dstStride;\
-      if (h>4) { \
-        int src7,src8,src9,src10; \
-        src7 = *s; s+=srcStride;\
-        OP(*d, (src4+src5)*20 - (src3+src6)*5 + (src2+src7));d+=dstStride;\
-        src8 = *s; s+=srcStride;\
-        OP(*d, (src5+src6)*20 - (src4+src7)*5 + (src3+src8));d+=dstStride;\
-        src9 = *s; s+=srcStride;\
-        OP(*d, (src6+src7)*20 - (src5+src8)*5 + (src4+src9));d+=dstStride;\
-        src10 = *s; s+=srcStride;\
-        OP(*d, (src7+src8)*20 - (src6+src9)*5 + (src5+src10));d+=dstStride;\
-       if (h>8) { \
-        int src11,src12,src13,src14,src15,src16,src17,src18; \
-        src11 = *s; s+=srcStride;\
-        OP(*d , (src8 +src9 )*20 - (src7 +src10)*5 + (src6 +src11));d+=dstStride;\
-        src12 = *s; s+=srcStride;\
-        OP(*d , (src9 +src10)*20 - (src8 +src11)*5 + (src7 +src12));d+=dstStride;\
-        src13 = *s; s+=srcStride;\
-        OP(*d, (src10+src11)*20 - (src9 +src12)*5 + (src8 +src13));d+=dstStride;\
-        src14 = *s; s+=srcStride;\
-        OP(*d, (src11+src12)*20 - (src10+src13)*5 + (src9 +src14));d+=dstStride;\
-        src15 = *s; s+=srcStride;\
-        OP(*d, (src12+src13)*20 - (src11+src14)*5 + (src10+src15));d+=dstStride;\
-        src16 = *s; s+=srcStride;\
-        OP(*d, (src13+src14)*20 - (src12+src15)*5 + (src11+src16));d+=dstStride;\
-        src17 = *s; s+=srcStride;\
-        OP(*d, (src14+src15)*20 - (src13+src16)*5 + (src12+src17));d+=dstStride;\
-        src18 = *s; s+=srcStride;\
-        OP(*d, (src15+src16)*20 - (src14+src17)*5 + (src13+src18));d+=dstStride;\
-       } \
-      } \
-        dst++;\
-        src++;\
-    }while(--w);\
-}\
-\
-static inline void OPNAME ## h264_qpel_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride,int w,int h){\
-    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
-    int i;\
-    src -= 2*srcStride;\
-    i= h+5; \
-    do {\
-        int srcB,srcA,src0,src1,src2,src3,src4,src5,src6;\
-        uint8_t *s = src-2;\
-        srcB = *s++;\
-        srcA = *s++;\
-        src0 = *s++;\
-        src1 = *s++;\
-        src2 = *s++;\
-        src3 = *s++;\
-        tmp[0] = ((src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
-        src4 = *s++;\
-        tmp[1] = ((src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
-        src5 = *s++;\
-        tmp[2] = ((src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
-        src6 = *s++;\
-        tmp[3] = ((src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
-      if (w>4) { /* it optimized */ \
-        int src7,src8,src9,src10; \
-        src7 = *s++;\
-        tmp[4] = ((src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
-        src8 = *s++;\
-        tmp[5] = ((src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
-        src9 = *s++;\
-        tmp[6] = ((src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
-        src10 = *s++;\
-        tmp[7] = ((src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
-       if (w>8) { \
-        int src11,src12,src13,src14,src15,src16,src17,src18; \
-        src11 = *s++;\
-        tmp[8] = ((src8 +src9 )*20 - (src7 +src10)*5 + (src6 +src11));\
-        src12 = *s++;\
-        tmp[9] = ((src9 +src10)*20 - (src8 +src11)*5 + (src7 +src12));\
-        src13 = *s++;\
-        tmp[10] = ((src10+src11)*20 - (src9 +src12)*5 + (src8 +src13));\
-        src14 = *s++;\
-        tmp[11] = ((src11+src12)*20 - (src10+src13)*5 + (src9 +src14));\
-        src15 = *s++;\
-        tmp[12] = ((src12+src13)*20 - (src11+src14)*5 + (src10+src15));\
-        src16 = *s++;\
-        tmp[13] = ((src13+src14)*20 - (src12+src15)*5 + (src11+src16));\
-        src17 = *s++;\
-        tmp[14] = ((src14+src15)*20 - (src13+src16)*5 + (src12+src17));\
-        src18 = *s++;\
-        tmp[15] = ((src15+src16)*20 - (src14+src17)*5 + (src13+src18));\
-       } \
-      } \
-        tmp+=tmpStride;\
-        src+=srcStride;\
-    }while(--i);\
-    tmp -= tmpStride*(h+5-2);\
-    i = w; \
-    do {\
-        int tmpB,tmpA,tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6;\
-        int16_t *s = tmp-2*tmpStride; \
-        uint8_t *d=dst;\
-        tmpB = *s; s+=tmpStride;\
-        tmpA = *s; s+=tmpStride;\
-        tmp0 = *s; s+=tmpStride;\
-        tmp1 = *s; s+=tmpStride;\
-        tmp2 = *s; s+=tmpStride;\
-        tmp3 = *s; s+=tmpStride;\
-        OP2(*d, (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));d+=dstStride;\
-        tmp4 = *s; s+=tmpStride;\
-        OP2(*d, (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));d+=dstStride;\
-        tmp5 = *s; s+=tmpStride;\
-        OP2(*d, (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));d+=dstStride;\
-        tmp6 = *s; s+=tmpStride;\
-        OP2(*d, (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));d+=dstStride;\
-      if (h>4) { \
-        int tmp7,tmp8,tmp9,tmp10; \
-        tmp7 = *s; s+=tmpStride;\
-        OP2(*d, (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));d+=dstStride;\
-        tmp8 = *s; s+=tmpStride;\
-        OP2(*d, (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));d+=dstStride;\
-        tmp9 = *s; s+=tmpStride;\
-        OP2(*d, (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));d+=dstStride;\
-        tmp10 = *s; s+=tmpStride;\
-        OP2(*d, (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));d+=dstStride;\
-       if (h>8) { \
-        int tmp11,tmp12,tmp13,tmp14,tmp15,tmp16,tmp17,tmp18; \
-        tmp11 = *s; s+=tmpStride;\
-        OP2(*d , (tmp8 +tmp9 )*20 - (tmp7 +tmp10)*5 + (tmp6 +tmp11));d+=dstStride;\
-        tmp12 = *s; s+=tmpStride;\
-        OP2(*d , (tmp9 +tmp10)*20 - (tmp8 +tmp11)*5 + (tmp7 +tmp12));d+=dstStride;\
-        tmp13 = *s; s+=tmpStride;\
-        OP2(*d, (tmp10+tmp11)*20 - (tmp9 +tmp12)*5 + (tmp8 +tmp13));d+=dstStride;\
-        tmp14 = *s; s+=tmpStride;\
-        OP2(*d, (tmp11+tmp12)*20 - (tmp10+tmp13)*5 + (tmp9 +tmp14));d+=dstStride;\
-        tmp15 = *s; s+=tmpStride;\
-        OP2(*d, (tmp12+tmp13)*20 - (tmp11+tmp14)*5 + (tmp10+tmp15));d+=dstStride;\
-        tmp16 = *s; s+=tmpStride;\
-        OP2(*d, (tmp13+tmp14)*20 - (tmp12+tmp15)*5 + (tmp11+tmp16));d+=dstStride;\
-        tmp17 = *s; s+=tmpStride;\
-        OP2(*d, (tmp14+tmp15)*20 - (tmp13+tmp16)*5 + (tmp12+tmp17));d+=dstStride;\
-        tmp18 = *s; s+=tmpStride;\
-        OP2(*d, (tmp15+tmp16)*20 - (tmp14+tmp17)*5 + (tmp13+tmp18));d+=dstStride;\
-       } \
-      } \
-        dst++;\
-        tmp++;\
-    }while(--i);\
-}\
-\
-static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
-    OPNAME ## h264_qpel_h_lowpass(dst,src,dstStride,srcStride,4,4); \
-}\
-static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
-   OPNAME ## h264_qpel_h_lowpass(dst,src,dstStride,srcStride,8,8); \
-}\
-static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
-   OPNAME ## h264_qpel_h_lowpass(dst,src,dstStride,srcStride,16,16); \
-}\
-\
-static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
-   OPNAME ## h264_qpel_v_lowpass(dst,src,dstStride,srcStride,4,4); \
-}\
-static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
-   OPNAME ## h264_qpel_v_lowpass(dst,src,dstStride,srcStride,8,8); \
-}\
-static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
-   OPNAME ## h264_qpel_v_lowpass(dst,src,dstStride,srcStride,16,16); \
-}\
-static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
-   OPNAME ## h264_qpel_hv_lowpass(dst,tmp,src,dstStride,tmpStride,srcStride,4,4); \
-}\
-static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
-   OPNAME ## h264_qpel_hv_lowpass(dst,tmp,src,dstStride,tmpStride,srcStride,8,8); \
-}\
-static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
-   OPNAME ## h264_qpel_hv_lowpass(dst,tmp,src,dstStride,tmpStride,srcStride,16,16); \
-}\
-
-#define H264_MC(OPNAME, SIZE) \
-static void OPNAME ## h264_qpel ## SIZE ## _mc00_sh4 (uint8_t *dst, uint8_t *src, int stride){\
-    OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc10_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    uint8_t half[SIZE*SIZE];\
-    put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
-    OPNAME ## pixels ## SIZE ## _l2_aligned2(dst, src, half, stride, stride, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc20_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc30_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    uint8_t half[SIZE*SIZE];\
-    put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
-    OPNAME ## pixels ## SIZE ## _l2_aligned2(dst, src+1, half, stride, stride, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc01_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    uint8_t full[SIZE*(SIZE+5)];\
-    uint8_t * const full_mid= full + SIZE*2;\
-    uint8_t half[SIZE*SIZE];\
-    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
-    put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
-    OPNAME ## pixels ## SIZE ## _l2_aligned(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc02_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    uint8_t full[SIZE*(SIZE+5)];\
-    uint8_t * const full_mid= full + SIZE*2;\
-    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
-    OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc03_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    uint8_t full[SIZE*(SIZE+5)];\
-    uint8_t * const full_mid= full + SIZE*2;\
-    uint8_t half[SIZE*SIZE];\
-    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
-    put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
-    OPNAME ## pixels ## SIZE ## _l2_aligned(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc11_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    uint8_t full[SIZE*(SIZE+5)];\
-    uint8_t * const full_mid= full + SIZE*2;\
-    uint8_t halfH[SIZE*SIZE];\
-    uint8_t halfV[SIZE*SIZE];\
-    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
-    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
-    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
-    OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc31_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    uint8_t full[SIZE*(SIZE+5)];\
-    uint8_t * const full_mid= full + SIZE*2;\
-    uint8_t halfH[SIZE*SIZE];\
-    uint8_t halfV[SIZE*SIZE];\
-    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
-    copy_block ## SIZE (full, src - stride*2 + 1, SIZE,  stride, SIZE + 5);\
-    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
-    OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc13_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    uint8_t full[SIZE*(SIZE+5)];\
-    uint8_t * const full_mid= full + SIZE*2;\
-    uint8_t halfH[SIZE*SIZE];\
-    uint8_t halfV[SIZE*SIZE];\
-    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
-    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
-    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
-    OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc33_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    uint8_t full[SIZE*(SIZE+5)];\
-    uint8_t * const full_mid= full + SIZE*2;\
-    uint8_t halfH[SIZE*SIZE];\
-    uint8_t halfV[SIZE*SIZE];\
-    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
-    copy_block ## SIZE (full, src - stride*2 + 1, SIZE,  stride, SIZE + 5);\
-    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
-    OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc22_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    int16_t tmp[SIZE*(SIZE+5)];\
-    OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc21_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    int16_t tmp[SIZE*(SIZE+5)];\
-    uint8_t halfH[SIZE*SIZE];\
-    uint8_t halfHV[SIZE*SIZE];\
-    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
-    put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
-    OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc23_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    int16_t tmp[SIZE*(SIZE+5)];\
-    uint8_t halfH[SIZE*SIZE];\
-    uint8_t halfHV[SIZE*SIZE];\
-    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
-    put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
-    OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc12_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    uint8_t full[SIZE*(SIZE+5)];\
-    uint8_t * const full_mid= full + SIZE*2;\
-    int16_t tmp[SIZE*(SIZE+5)];\
-    uint8_t halfV[SIZE*SIZE];\
-    uint8_t halfHV[SIZE*SIZE];\
-    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
-    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
-    put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
-    OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc32_sh4(uint8_t *dst, uint8_t *src, int stride){\
-    uint8_t full[SIZE*(SIZE+5)];\
-    uint8_t * const full_mid= full + SIZE*2;\
-    int16_t tmp[SIZE*(SIZE+5)];\
-    uint8_t halfV[SIZE*SIZE];\
-    uint8_t halfHV[SIZE*SIZE];\
-    copy_block ## SIZE (full, src - stride*2 + 1, SIZE,  stride, SIZE + 5);\
-    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
-    put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
-    OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
-}\
-
-#define op_avg(a, b)  a = (((a)+cm[((b) + 16)>>5]+1)>>1)
-//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
-#define op_put(a, b)  a = cm[((b) + 16)>>5]
-#define op2_avg(a, b)  a = (((a)+cm[((b) + 512)>>10]+1)>>1)
-#define op2_put(a, b)  a = cm[((b) + 512)>>10]
-
-H264_LOWPASS(put_       , op_put, op2_put)
-H264_LOWPASS(avg_       , op_avg, op2_avg)
-H264_MC(put_, 4)
-H264_MC(put_, 8)
-H264_MC(put_, 16)
-H264_MC(avg_, 4)
-H264_MC(avg_, 8)
-H264_MC(avg_, 16)
-
-#undef op_avg
-#undef op_put
-#undef op2_avg
-#undef op2_put
-
 static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
     uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
 
diff --git a/mythtv/external/FFmpeg/libavcodec/shorten.c b/mythtv/external/FFmpeg/libavcodec/shorten.c
index 991141533ac..3a6d6340122 100644
--- a/mythtv/external/FFmpeg/libavcodec/shorten.c
+++ b/mythtv/external/FFmpeg/libavcodec/shorten.c
@@ -84,7 +84,6 @@ static const uint8_t is_audio_command[10] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 };
 
 typedef struct ShortenContext {
     AVCodecContext *avctx;
-    AVFrame frame;
     GetBitContext gb;
 
     int min_framesize, max_framesize;
@@ -118,9 +117,6 @@ static av_cold int shorten_decode_init(AVCodecContext *avctx)
     ShortenContext *s = avctx->priv_data;
     s->avctx          = avctx;
 
-    avcodec_get_frame_defaults(&s->frame);
-    avctx->coded_frame = &s->frame;
-
     return 0;
 }
 
@@ -416,6 +412,7 @@ static int read_header(ShortenContext *s)
 static int shorten_decode_frame(AVCodecContext *avctx, void *data,
                                 int *got_frame_ptr, AVPacket *avpkt)
 {
+    AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
     int buf_size       = avpkt->size;
     ShortenContext *s  = avctx->priv_data;
@@ -480,7 +477,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
 
     s->cur_chan = 0;
     while (s->cur_chan < s->channels) {
-        unsigned int cmd;
+        unsigned cmd;
         int len;
 
         if (get_bits_left(&s->gb) < 3 + FNSIZE) {
@@ -598,15 +595,15 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
                 int chan;
 
                 /* get output buffer */
-                s->frame.nb_samples = s->blocksize;
-                if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
+                frame->nb_samples = s->blocksize;
+                if ((ret = ff_get_buffer(avctx, frame)) < 0) {
                     av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
                     return ret;
                 }
 
                 for (chan = 0; chan < s->channels; chan++) {
-                    samples_u8  = ((uint8_t **)s->frame.extended_data)[chan];
-                    samples_s16 = ((int16_t **)s->frame.extended_data)[chan];
+                    samples_u8  = ((uint8_t **)frame->extended_data)[chan];
+                    samples_s16 = ((int16_t **)frame->extended_data)[chan];
                     for (i = 0; i < s->blocksize; i++) {
                         switch (s->internal_ftype) {
                         case TYPE_U8:
@@ -620,9 +617,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
                     }
                 }
 
-
-                *got_frame_ptr   = 1;
-                *(AVFrame *)data = s->frame;
+                *got_frame_ptr = 1;
             }
         }
     }
diff --git a/mythtv/external/FFmpeg/libavcodec/simple_idct.c b/mythtv/external/FFmpeg/libavcodec/simple_idct.c
index 293185074b8..d204565ea42 100644
--- a/mythtv/external/FFmpeg/libavcodec/simple_idct.c
+++ b/mythtv/external/FFmpeg/libavcodec/simple_idct.c
@@ -27,7 +27,6 @@
 
 #include "libavutil/intreadwrite.h"
 #include "avcodec.h"
-#include "dsputil.h"
 #include "mathops.h"
 #include "simple_idct.h"
 
@@ -50,7 +49,7 @@
    and the butterfly must be multiplied by 0.5 * sqrt(2.0) */
 #define C_SHIFT (4+1+12)
 
-static inline void idct4col_put(uint8_t *dest, int line_size, const DCTELEM *col)
+static inline void idct4col_put(uint8_t *dest, int line_size, const int16_t *col)
 {
     int c0, c1, c2, c3, a0, a1, a2, a3;
 
@@ -86,10 +85,10 @@ static inline void idct4col_put(uint8_t *dest, int line_size, const DCTELEM *col
 /* XXX: I think a 1.0/sqrt(2) normalization should be needed to
    compensate the extra butterfly stage - I don't have the full DV
    specification */
-void ff_simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block)
+void ff_simple_idct248_put(uint8_t *dest, int line_size, int16_t *block)
 {
     int i;
-    DCTELEM *ptr;
+    int16_t *ptr;
 
     /* butterfly */
     ptr = block;
@@ -129,7 +128,7 @@ void ff_simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block)
 #define C2 C_FIX(0.2705980501)
 #define C3 C_FIX(0.5)
 #define C_SHIFT (4+1+12)
-static inline void idct4col_add(uint8_t *dest, int line_size, const DCTELEM *col)
+static inline void idct4col_add(uint8_t *dest, int line_size, const int16_t *col)
 {
     int c0, c1, c2, c3, a0, a1, a2, a3;
 
@@ -156,7 +155,7 @@ static inline void idct4col_add(uint8_t *dest, int line_size, const DCTELEM *col
 #define R2 R_FIX(0.2705980501)
 #define R3 R_FIX(0.5)
 #define R_SHIFT 11
-static inline void idct4row(DCTELEM *row)
+static inline void idct4row(int16_t *row)
 {
     int c0, c1, c2, c3, a0, a1, a2, a3;
 
@@ -174,7 +173,7 @@ static inline void idct4row(DCTELEM *row)
     row[3]= (c0 - c1) >> R_SHIFT;
 }
 
-void ff_simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block)
+void ff_simple_idct84_add(uint8_t *dest, int line_size, int16_t *block)
 {
     int i;
 
@@ -189,7 +188,7 @@ void ff_simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block)
     }
 }
 
-void ff_simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block)
+void ff_simple_idct48_add(uint8_t *dest, int line_size, int16_t *block)
 {
     int i;
 
@@ -204,7 +203,7 @@ void ff_simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block)
     }
 }
 
-void ff_simple_idct44_add(uint8_t *dest, int line_size, DCTELEM *block)
+void ff_simple_idct44_add(uint8_t *dest, int line_size, int16_t *block)
 {
     int i;
 
@@ -219,7 +218,7 @@ void ff_simple_idct44_add(uint8_t *dest, int line_size, DCTELEM *block)
     }
 }
 
-void ff_prores_idct(DCTELEM *block, const int16_t *qmat)
+void ff_prores_idct(int16_t *block, const int16_t *qmat)
 {
     int i;
 
diff --git a/mythtv/external/FFmpeg/libavcodec/simple_idct.h b/mythtv/external/FFmpeg/libavcodec/simple_idct.h
index 64d3c2ac316..3fec5e00879 100644
--- a/mythtv/external/FFmpeg/libavcodec/simple_idct.h
+++ b/mythtv/external/FFmpeg/libavcodec/simple_idct.h
@@ -29,30 +29,29 @@
 #define AVCODEC_SIMPLE_IDCT_H
 
 #include 
-#include "dsputil.h"
 
-void ff_simple_idct_put_8(uint8_t *dest, int line_size, DCTELEM *block);
-void ff_simple_idct_add_8(uint8_t *dest, int line_size, DCTELEM *block);
-void ff_simple_idct_8(DCTELEM *block);
+void ff_simple_idct_put_8(uint8_t *dest, int line_size, int16_t *block);
+void ff_simple_idct_add_8(uint8_t *dest, int line_size, int16_t *block);
+void ff_simple_idct_8(int16_t *block);
 
-void ff_simple_idct_put_10(uint8_t *dest, int line_size, DCTELEM *block);
-void ff_simple_idct_add_10(uint8_t *dest, int line_size, DCTELEM *block);
-void ff_simple_idct_10(DCTELEM *block);
+void ff_simple_idct_put_10(uint8_t *dest, int line_size, int16_t *block);
+void ff_simple_idct_add_10(uint8_t *dest, int line_size, int16_t *block);
+void ff_simple_idct_10(int16_t *block);
 /**
  * Special version of ff_simple_idct_10() which does dequantization
  * and scales by a factor of 2 more between the two IDCTs to account
  * for larger scale of input coefficients.
  */
-void ff_prores_idct(DCTELEM *block, const int16_t *qmat);
+void ff_prores_idct(int16_t *block, const int16_t *qmat);
 
 void ff_simple_idct_mmx(int16_t *block);
 void ff_simple_idct_add_mmx(uint8_t *dest, int line_size, int16_t *block);
 void ff_simple_idct_put_mmx(uint8_t *dest, int line_size, int16_t *block);
 
-void ff_simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_simple_idct248_put(uint8_t *dest, int line_size, int16_t *block);
 
-void ff_simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block);
-void ff_simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block);
-void ff_simple_idct44_add(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_simple_idct84_add(uint8_t *dest, int line_size, int16_t *block);
+void ff_simple_idct48_add(uint8_t *dest, int line_size, int16_t *block);
+void ff_simple_idct44_add(uint8_t *dest, int line_size, int16_t *block);
 
 #endif /* AVCODEC_SIMPLE_IDCT_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/simple_idct_template.c b/mythtv/external/FFmpeg/libavcodec/simple_idct_template.c
index b67893c2b2d..dabfbda8a0f 100644
--- a/mythtv/external/FFmpeg/libavcodec/simple_idct_template.c
+++ b/mythtv/external/FFmpeg/libavcodec/simple_idct_template.c
@@ -85,7 +85,7 @@
 
 #endif
 
-static inline void FUNC(idctRowCondDC)(DCTELEM *row, int extra_shift)
+static inline void FUNC(idctRowCondDC)(int16_t *row, int extra_shift)
 {
     int a0, a1, a2, a3, b0, b1, b2, b3;
 
@@ -221,7 +221,7 @@ static inline void FUNC(idctRowCondDC)(DCTELEM *row, int extra_shift)
     } while (0)
 
 static inline void FUNC(idctSparseColPut)(pixel *dest, int line_size,
-                                          DCTELEM *col)
+                                          int16_t *col)
 {
     int a0, a1, a2, a3, b0, b1, b2, b3;
 
@@ -245,7 +245,7 @@ static inline void FUNC(idctSparseColPut)(pixel *dest, int line_size,
 }
 
 static inline void FUNC(idctSparseColAdd)(pixel *dest, int line_size,
-                                          DCTELEM *col)
+                                          int16_t *col)
 {
     int a0, a1, a2, a3, b0, b1, b2, b3;
 
@@ -268,7 +268,7 @@ static inline void FUNC(idctSparseColAdd)(pixel *dest, int line_size,
     dest[0] = av_clip_pixel(dest[0] + ((a0 - b0) >> COL_SHIFT));
 }
 
-static inline void FUNC(idctSparseCol)(DCTELEM *col)
+static inline void FUNC(idctSparseCol)(int16_t *col)
 {
     int a0, a1, a2, a3, b0, b1, b2, b3;
 
@@ -284,7 +284,7 @@ static inline void FUNC(idctSparseCol)(DCTELEM *col)
     col[56] = ((a0 - b0) >> COL_SHIFT);
 }
 
-void FUNC(ff_simple_idct_put)(uint8_t *dest_, int line_size, DCTELEM *block)
+void FUNC(ff_simple_idct_put)(uint8_t *dest_, int line_size, int16_t *block)
 {
     pixel *dest = (pixel *)dest_;
     int i;
@@ -298,7 +298,7 @@ void FUNC(ff_simple_idct_put)(uint8_t *dest_, int line_size, DCTELEM *block)
         FUNC(idctSparseColPut)(dest + i, line_size, block + i);
 }
 
-void FUNC(ff_simple_idct_add)(uint8_t *dest_, int line_size, DCTELEM *block)
+void FUNC(ff_simple_idct_add)(uint8_t *dest_, int line_size, int16_t *block)
 {
     pixel *dest = (pixel *)dest_;
     int i;
@@ -312,7 +312,7 @@ void FUNC(ff_simple_idct_add)(uint8_t *dest_, int line_size, DCTELEM *block)
         FUNC(idctSparseColAdd)(dest + i, line_size, block + i);
 }
 
-void FUNC(ff_simple_idct)(DCTELEM *block)
+void FUNC(ff_simple_idct)(int16_t *block)
 {
     int i;
 
diff --git a/mythtv/external/FFmpeg/libavcodec/sipr.c b/mythtv/external/FFmpeg/libavcodec/sipr.c
index 06b22c0c31d..dc169361934 100644
--- a/mythtv/external/FFmpeg/libavcodec/sipr.c
+++ b/mythtv/external/FFmpeg/libavcodec/sipr.c
@@ -26,11 +26,11 @@
 #include 
 
 #include "libavutil/channel_layout.h"
+#include "libavutil/float_dsp.h"
 #include "libavutil/mathematics.h"
 #include "avcodec.h"
 #define BITSTREAM_READER_LE
 #include "get_bits.h"
-#include "dsputil.h"
 #include "internal.h"
 
 #include "lsp.h"
@@ -411,9 +411,10 @@ static void decode_frame(SiprContext *ctx, SiprParameters *params,
         convolute_with_sparse(fixed_vector, &fixed_cb, impulse_response,
                               SUBFR_SIZE);
 
-        avg_energy =
-            (0.01 + ff_scalarproduct_float_c(fixed_vector, fixed_vector, SUBFR_SIZE)) /
-                SUBFR_SIZE;
+        avg_energy = (0.01 + avpriv_scalarproduct_float_c(fixed_vector,
+                                                          fixed_vector,
+                                                          SUBFR_SIZE)) /
+                     SUBFR_SIZE;
 
         ctx->past_pitch_gain = pitch_gain = gain_cb[params->gc_index[i]][0];
 
@@ -454,9 +455,9 @@ static void decode_frame(SiprContext *ctx, SiprParameters *params,
 
     if (ctx->mode == MODE_5k0) {
         for (i = 0; i < subframe_count; i++) {
-            float energy = ff_scalarproduct_float_c(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,
-                                                    ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,
-                                                    SUBFR_SIZE);
+            float energy = avpriv_scalarproduct_float_c(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,
+                                                        ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,
+                                                        SUBFR_SIZE);
             ff_adaptive_gain_control(&synth[i * SUBFR_SIZE],
                                      &synth[i * SUBFR_SIZE], energy,
                                      SUBFR_SIZE, 0.9, &ctx->postfilter_agc);
@@ -515,9 +516,6 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx)
     avctx->channel_layout = AV_CH_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_FLT;
 
-    avcodec_get_frame_defaults(&ctx->frame);
-    avctx->coded_frame = &ctx->frame;
-
     return 0;
 }
 
@@ -525,6 +523,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *data,
                              int *got_frame_ptr, AVPacket *avpkt)
 {
     SiprContext *ctx = avctx->priv_data;
+    AVFrame *frame   = data;
     const uint8_t *buf=avpkt->data;
     SiprParameters parm;
     const SiprModeParam *mode_par = &modes[ctx->mode];
@@ -542,13 +541,13 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     /* get output buffer */
-    ctx->frame.nb_samples = mode_par->frames_per_packet * subframe_size *
-                            mode_par->subframe_count;
-    if ((ret = ff_get_buffer(avctx, &ctx->frame)) < 0) {
+    frame->nb_samples = mode_par->frames_per_packet * subframe_size *
+                        mode_par->subframe_count;
+    if ((ret = ff_get_buffer(avctx, frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
-    samples = (float *)ctx->frame.data[0];
+    samples = (float *)frame->data[0];
 
     init_get_bits(&gb, buf, mode_par->bits_per_frame);
 
@@ -560,8 +559,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *data,
         samples += subframe_size * mode_par->subframe_count;
     }
 
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = ctx->frame;
+    *got_frame_ptr = 1;
 
     return mode_par->bits_per_frame >> 3;
 }
diff --git a/mythtv/external/FFmpeg/libavcodec/sipr.h b/mythtv/external/FFmpeg/libavcodec/sipr.h
index 8872fa326eb..34f7f994cde 100644
--- a/mythtv/external/FFmpeg/libavcodec/sipr.h
+++ b/mythtv/external/FFmpeg/libavcodec/sipr.h
@@ -25,7 +25,6 @@
 #define AVCODEC_SIPR_H
 
 #include "avcodec.h"
-#include "dsputil.h"
 #include "acelp_pitch_delay.h"
 #include "libavutil/mem.h"
 
@@ -65,7 +64,6 @@ typedef struct SiprParameters {
 
 typedef struct SiprContext {
     AVCodecContext *avctx;
-    AVFrame frame;
 
     SiprMode mode;
 
diff --git a/mythtv/external/FFmpeg/libavcodec/sipr16k.c b/mythtv/external/FFmpeg/libavcodec/sipr16k.c
index c2e090bb0af..fbf749759c7 100644
--- a/mythtv/external/FFmpeg/libavcodec/sipr16k.c
+++ b/mythtv/external/FFmpeg/libavcodec/sipr16k.c
@@ -25,8 +25,8 @@
 
 #include "sipr.h"
 #include "libavutil/common.h"
+#include "libavutil/float_dsp.h"
 #include "libavutil/mathematics.h"
-#include "dsputil.h"
 #include "lsp.h"
 #include "celp_filters.h"
 #include "acelp_vectors.h"
@@ -163,11 +163,11 @@ static float acelp_decode_gain_codef(float gain_corr_factor, const float *fc_v,
                                      const float *ma_prediction_coeff,
                                      int subframe_size, int ma_pred_order)
 {
-    mr_energy +=
-        ff_scalarproduct_float_c(quant_energy, ma_prediction_coeff, ma_pred_order);
+    mr_energy += avpriv_scalarproduct_float_c(quant_energy, ma_prediction_coeff,
+                                              ma_pred_order);
 
     mr_energy = gain_corr_factor * exp(M_LN10 / 20. * mr_energy) /
-        sqrt((0.01 + ff_scalarproduct_float_c(fc_v, fc_v, subframe_size)));
+        sqrt((0.01 + avpriv_scalarproduct_float_c(fc_v, fc_v, subframe_size)));
     return mr_energy;
 }
 
diff --git a/mythtv/external/FFmpeg/libavcodec/smacker.c b/mythtv/external/FFmpeg/libavcodec/smacker.c
index 1a73dcce0df..ad1d4c31716 100644
--- a/mythtv/external/FFmpeg/libavcodec/smacker.c
+++ b/mythtv/external/FFmpeg/libavcodec/smacker.c
@@ -572,14 +572,8 @@ static av_cold int decode_end(AVCodecContext *avctx)
 }
 
 
-typedef struct SmackerAudioContext {
-    AVFrame frame;
-} SmackerAudioContext;
-
 static av_cold int smka_decode_init(AVCodecContext *avctx)
 {
-    SmackerAudioContext *s = avctx->priv_data;
-
     if (avctx->channels < 1 || avctx->channels > 2) {
         av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
         return AVERROR(EINVAL);
@@ -587,9 +581,6 @@ static av_cold int smka_decode_init(AVCodecContext *avctx)
     avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
     avctx->sample_fmt = avctx->bits_per_coded_sample == 8 ? AV_SAMPLE_FMT_U8 : AV_SAMPLE_FMT_S16;
 
-    avcodec_get_frame_defaults(&s->frame);
-    avctx->coded_frame = &s->frame;
-
     return 0;
 }
 
@@ -599,7 +590,7 @@ static av_cold int smka_decode_init(AVCodecContext *avctx)
 static int smka_decode_frame(AVCodecContext *avctx, void *data,
                              int *got_frame_ptr, AVPacket *avpkt)
 {
-    SmackerAudioContext *s = avctx->priv_data;
+    AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     GetBitContext gb;
@@ -644,13 +635,13 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     /* get output buffer */
-    s->frame.nb_samples = unp_size / (avctx->channels * (bits + 1));
-    if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
+    frame->nb_samples = unp_size / (avctx->channels * (bits + 1));
+    if ((ret = ff_get_buffer(avctx, frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
-    samples  = (int16_t *)s->frame.data[0];
-    samples8 =            s->frame.data[0];
+    samples  = (int16_t *)frame->data[0];
+    samples8 =            frame->data[0];
 
     // Initialize
     for(i = 0; i < (1 << (bits + stereo)); i++) {
@@ -769,8 +760,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data,
         av_free(h[i].values);
     }
 
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = s->frame;
+    *got_frame_ptr = 1;
 
     return buf_size;
 }
@@ -791,7 +781,6 @@ AVCodec ff_smackaud_decoder = {
     .name           = "smackaud",
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_SMACKAUDIO,
-    .priv_data_size = sizeof(SmackerAudioContext),
     .init           = smka_decode_init,
     .decode         = smka_decode_frame,
     .capabilities   = CODEC_CAP_DR1,
diff --git a/mythtv/external/FFmpeg/libavcodec/snow.c b/mythtv/external/FFmpeg/libavcodec/snow.c
index 3adf723f709..b2c6714a40e 100644
--- a/mythtv/external/FFmpeg/libavcodec/snow.c
+++ b/mythtv/external/FFmpeg/libavcodec/snow.c
@@ -23,7 +23,7 @@
 #include "libavutil/opt.h"
 #include "avcodec.h"
 #include "dsputil.h"
-#include "dwt.h"
+#include "snow_dwt.h"
 #include "internal.h"
 #include "snow.h"
 #include "snowdata.h"
@@ -361,24 +361,24 @@ void ff_snow_pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, int stride,
         else if(b_w==32){
             int y;
             for(y=0; ydsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + y*stride, src + 3 + (y+3)*stride,stride);
-                s->dsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + 16 + y*stride, src + 19 + (y+3)*stride,stride);
+                s->h264qpel.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + y*stride, src + 3 + (y+3)*stride,stride);
+                s->h264qpel.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + 16 + y*stride, src + 19 + (y+3)*stride,stride);
             }
         }else if(b_w==b_h)
-            s->dsp.put_h264_qpel_pixels_tab[tab_index  ][dy+(dx>>2)](dst,src + 3 + 3*stride,stride);
+            s->h264qpel.put_h264_qpel_pixels_tab[tab_index  ][dy+(dx>>2)](dst,src + 3 + 3*stride,stride);
         else if(b_w==2*b_h){
-            s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst    ,src + 3       + 3*stride,stride);
-            s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst+b_h,src + 3 + b_h + 3*stride,stride);
+            s->h264qpel.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst    ,src + 3       + 3*stride,stride);
+            s->h264qpel.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst+b_h,src + 3 + b_h + 3*stride,stride);
         }else{
             av_assert2(2*b_w==b_h);
-            s->dsp.put_h264_qpel_pixels_tab[tab_index  ][dy+(dx>>2)](dst           ,src + 3 + 3*stride           ,stride);
-            s->dsp.put_h264_qpel_pixels_tab[tab_index  ][dy+(dx>>2)](dst+b_w*stride,src + 3 + 3*stride+b_w*stride,stride);
+            s->h264qpel.put_h264_qpel_pixels_tab[tab_index  ][dy+(dx>>2)](dst           ,src + 3 + 3*stride           ,stride);
+            s->h264qpel.put_h264_qpel_pixels_tab[tab_index  ][dy+(dx>>2)](dst+b_w*stride,src + 3 + 3*stride+b_w*stride,stride);
         }
     }
 }
 
 #define mca(dx,dy,b_w)\
-static void mc_block_hpel ## dx ## dy ## b_w(uint8_t *dst, const uint8_t *src, int stride, int h){\
+static void mc_block_hpel ## dx ## dy ## b_w(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h){\
     av_assert2(h==b_w);\
     mc_block(NULL, dst, src-(HTAPS_MAX/2-1)-(HTAPS_MAX/2-1)*stride, stride, b_w, b_w, dx, dy);\
 }
@@ -398,19 +398,20 @@ av_cold int ff_snow_common_init(AVCodecContext *avctx){
     int i, j;
 
     s->avctx= avctx;
-    s->max_ref_frames=1; //just make sure its not an invalid value in case of no initial keyframe
+    s->max_ref_frames=1; //just make sure it's not an invalid value in case of no initial keyframe
 
     ff_dsputil_init(&s->dsp, avctx);
     ff_videodsp_init(&s->vdsp, 8);
     ff_dwt_init(&s->dwt);
+    ff_h264qpel_init(&s->h264qpel, 8);
 
 #define mcf(dx,dy)\
     s->dsp.put_qpel_pixels_tab       [0][dy+dx/4]=\
     s->dsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\
-        s->dsp.put_h264_qpel_pixels_tab[0][dy+dx/4];\
+        s->h264qpel.put_h264_qpel_pixels_tab[0][dy+dx/4];\
     s->dsp.put_qpel_pixels_tab       [1][dy+dx/4]=\
     s->dsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\
-        s->dsp.put_h264_qpel_pixels_tab[1][dy+dx/4];
+        s->h264qpel.put_h264_qpel_pixels_tab[1][dy+dx/4];
 
     mcf( 0, 0)
     mcf( 4, 0)
diff --git a/mythtv/external/FFmpeg/libavcodec/snow.h b/mythtv/external/FFmpeg/libavcodec/snow.h
index 2565988a577..a3b0512490a 100644
--- a/mythtv/external/FFmpeg/libavcodec/snow.h
+++ b/mythtv/external/FFmpeg/libavcodec/snow.h
@@ -23,11 +23,12 @@
 #define AVCODEC_SNOW_H
 
 #include "dsputil.h"
-#include "dwt.h"
+#include "snow_dwt.h"
 
 #include "rangecoder.h"
 #include "mathops.h"
 #include "mpegvideo.h"
+#include "h264qpel.h"
 
 #define MID_STATE 128
 
@@ -109,7 +110,8 @@ typedef struct SnowContext{
     RangeCoder c;
     DSPContext dsp;
     VideoDSPContext vdsp;
-    DWTContext dwt;
+    H264QpelContext h264qpel;
+    SnowDWTContext dwt;
     AVFrame new_picture;
     AVFrame input_picture;              ///< new_picture with the internal linesizes
     AVFrame current_picture;
diff --git a/mythtv/external/FFmpeg/libavcodec/dwt.c b/mythtv/external/FFmpeg/libavcodec/snow_dwt.c
similarity index 61%
rename from mythtv/external/FFmpeg/libavcodec/dwt.c
rename to mythtv/external/FFmpeg/libavcodec/snow_dwt.c
index d36d25d1a60..28edf6aafb8 100644
--- a/mythtv/external/FFmpeg/libavcodec/dwt.c
+++ b/mythtv/external/FFmpeg/libavcodec/snow_dwt.c
@@ -23,8 +23,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/common.h"
 #include "dsputil.h"
-#include "dwt.h"
-#include "libavcodec/x86/dwt.h"
+#include "snow_dwt.h"
 
 int ff_slice_buffer_init(slice_buffer *buf, int line_count,
                          int max_allocated_lines, int line_width,
@@ -566,7 +565,7 @@ static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height
     cs->y  = -3;
 }
 
-static void spatial_compose97i_dy_buffered(DWTContext *dsp, DWTCompose *cs,
+static void spatial_compose97i_dy_buffered(SnowDWTContext *dsp, DWTCompose *cs,
                                            slice_buffer * sb, IDWTELEM *temp,
                                            int width, int height,
                                            int stride_line)
@@ -661,7 +660,7 @@ void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width,
     }
 }
 
-void ff_spatial_idwt_buffered_slice(DWTContext *dsp, DWTCompose *cs,
+void ff_spatial_idwt_buffered_slice(SnowDWTContext *dsp, DWTCompose *cs,
                                     slice_buffer *slice_buf, IDWTELEM *temp,
                                     int width, int height, int stride_line,
                                     int type, int decomposition_count, int y)
@@ -853,7 +852,7 @@ void ff_dsputil_init_dwt(DSPContext *c)
     c->w97[1] = w97_8_c;
 }
 
-void ff_dwt_init(DWTContext *c)
+void ff_dwt_init(SnowDWTContext *c)
 {
     c->vertical_compose97i   = ff_snow_vertical_compose97i;
     c->horizontal_compose97i = ff_snow_horizontal_compose97i;
@@ -864,539 +863,3 @@ void ff_dwt_init(DWTContext *c)
 }
 
 
-static av_always_inline
-void interleave(IDWTELEM *dst, IDWTELEM *src0, IDWTELEM *src1, int w2, int add, int shift)
-{
-    int i;
-    for (i = 0; i < w2; i++) {
-        dst[2*i  ] = (src0[i] + add) >> shift;
-        dst[2*i+1] = (src1[i] + add) >> shift;
-    }
-}
-
-static void horizontal_compose_dirac53i(IDWTELEM *b, IDWTELEM *temp, int w)
-{
-    const int w2 = w >> 1;
-    int x;
-
-    temp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
-    for (x = 1; x < w2; x++) {
-        temp[x     ] = COMPOSE_53iL0     (b[x+w2-1], b[x     ], b[x+w2]);
-        temp[x+w2-1] = COMPOSE_DIRAC53iH0(temp[x-1], b[x+w2-1], temp[x]);
-    }
-    temp[w-1] = COMPOSE_DIRAC53iH0(temp[w2-1], b[w-1], temp[w2-1]);
-
-    interleave(b, temp, temp+w2, w2, 1, 1);
-}
-
-static void horizontal_compose_dd97i(IDWTELEM *b, IDWTELEM *tmp, int w)
-{
-    const int w2 = w >> 1;
-    int x;
-
-    tmp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
-    for (x = 1; x < w2; x++)
-        tmp[x] = COMPOSE_53iL0(b[x+w2-1], b[x], b[x+w2]);
-
-    // extend the edges
-    tmp[-1]   = tmp[0];
-    tmp[w2+1] = tmp[w2] = tmp[w2-1];
-
-    for (x = 0; x < w2; x++) {
-        b[2*x  ] = (tmp[x] + 1)>>1;
-        b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
-    }
-}
-
-static void horizontal_compose_dd137i(IDWTELEM *b, IDWTELEM *tmp, int w)
-{
-    const int w2 = w >> 1;
-    int x;
-
-    tmp[0] = COMPOSE_DD137iL0(b[w2], b[w2], b[0], b[w2  ], b[w2+1]);
-    tmp[1] = COMPOSE_DD137iL0(b[w2], b[w2], b[1], b[w2+1], b[w2+2]);
-    for (x = 2; x < w2-1; x++)
-        tmp[x] = COMPOSE_DD137iL0(b[x+w2-2], b[x+w2-1], b[x], b[x+w2], b[x+w2+1]);
-    tmp[w2-1] = COMPOSE_DD137iL0(b[w-3], b[w-2], b[w2-1], b[w-1], b[w-1]);
-
-    // extend the edges
-    tmp[-1]   = tmp[0];
-    tmp[w2+1] = tmp[w2] = tmp[w2-1];
-
-    for (x = 0; x < w2; x++) {
-        b[2*x  ] = (tmp[x] + 1)>>1;
-        b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
-    }
-}
-
-static av_always_inline
-void horizontal_compose_haari(IDWTELEM *b, IDWTELEM *temp, int w, int shift)
-{
-    const int w2 = w >> 1;
-    int x;
-
-    for (x = 0; x < w2; x++) {
-        temp[x   ] = COMPOSE_HAARiL0(b[x   ], b[x+w2]);
-        temp[x+w2] = COMPOSE_HAARiH0(b[x+w2], temp[x]);
-    }
-
-    interleave(b, temp, temp+w2, w2, shift, shift);
-}
-
-static void horizontal_compose_haar0i(IDWTELEM *b, IDWTELEM *temp, int w)
-{
-    horizontal_compose_haari(b, temp, w, 0);
-}
-
-static void horizontal_compose_haar1i(IDWTELEM *b, IDWTELEM *temp, int w)
-{
-    horizontal_compose_haari(b, temp, w, 1);
-}
-
-static void horizontal_compose_fidelityi(IDWTELEM *b, IDWTELEM *tmp, int w)
-{
-    const int w2 = w >> 1;
-    int i, x;
-    IDWTELEM v[8];
-
-    for (x = 0; x < w2; x++) {
-        for (i = 0; i < 8; i++)
-            v[i] = b[av_clip(x-3+i, 0, w2-1)];
-        tmp[x] = COMPOSE_FIDELITYiH0(v[0], v[1], v[2], v[3], b[x+w2], v[4], v[5], v[6], v[7]);
-    }
-
-    for (x = 0; x < w2; x++) {
-        for (i = 0; i < 8; i++)
-            v[i] = tmp[av_clip(x-4+i, 0, w2-1)];
-        tmp[x+w2] = COMPOSE_FIDELITYiL0(v[0], v[1], v[2], v[3], b[x], v[4], v[5], v[6], v[7]);
-    }
-
-    interleave(b, tmp+w2, tmp, w2, 0, 0);
-}
-
-static void horizontal_compose_daub97i(IDWTELEM *b, IDWTELEM *temp, int w)
-{
-    const int w2 = w >> 1;
-    int x, b0, b1, b2;
-
-    temp[0] = COMPOSE_DAUB97iL1(b[w2], b[0], b[w2]);
-    for (x = 1; x < w2; x++) {
-        temp[x     ] = COMPOSE_DAUB97iL1(b[x+w2-1], b[x     ], b[x+w2]);
-        temp[x+w2-1] = COMPOSE_DAUB97iH1(temp[x-1], b[x+w2-1], temp[x]);
-    }
-    temp[w-1] = COMPOSE_DAUB97iH1(temp[w2-1], b[w-1], temp[w2-1]);
-
-    // second stage combined with interleave and shift
-    b0 = b2 = COMPOSE_DAUB97iL0(temp[w2], temp[0], temp[w2]);
-    b[0] = (b0 + 1) >> 1;
-    for (x = 1; x < w2; x++) {
-        b2 = COMPOSE_DAUB97iL0(temp[x+w2-1], temp[x     ], temp[x+w2]);
-        b1 = COMPOSE_DAUB97iH0(          b0, temp[x+w2-1], b2        );
-        b[2*x-1] = (b1 + 1) >> 1;
-        b[2*x  ] = (b2 + 1) >> 1;
-        b0 = b2;
-    }
-    b[w-1] = (COMPOSE_DAUB97iH0(b2, temp[w-1], b2) + 1) >> 1;
-}
-
-static void vertical_compose_dirac53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
-{
-    int i;
-
-    for(i=0; ivertical_compose_l0;
-    vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
-    DWTCompose *cs = d->cs + level;
-
-    int i, y = cs->y;
-    IDWTELEM *b[8];
-    for (i = 0; i < 6; i++)
-        b[i] = cs->b[i];
-    b[6] = d->buffer + av_clip(y+5, 0, height-2)*stride;
-    b[7] = d->buffer + av_clip(y+6, 1, height-1)*stride;
-
-        if(y+5<(unsigned)height) vertical_compose_l0(      b[5], b[6], b[7],       width);
-        if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
-
-        if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
-        if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
-
-    for (i = 0; i < 6; i++)
-        cs->b[i] = b[i+2];
-    cs->y += 2;
-}
-
-static void spatial_compose_dirac53i_dy(DWTContext *d, int level, int width, int height, int stride)
-{
-    vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
-    vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
-    DWTCompose *cs = d->cs + level;
-
-    int y= cs->y;
-    IDWTELEM *b[4] = { cs->b[0], cs->b[1] };
-    b[2] = d->buffer + mirror(y+1, height-1)*stride;
-    b[3] = d->buffer + mirror(y+2, height-1)*stride;
-
-        if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
-        if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
-
-        if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
-        if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
-
-    cs->b[0] = b[2];
-    cs->b[1] = b[3];
-    cs->y += 2;
-}
-
-
-static void spatial_compose_dd137i_dy(DWTContext *d, int level, int width, int height, int stride)
-{
-    vertical_compose_5tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
-    vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
-    DWTCompose *cs = d->cs + level;
-
-    int i, y = cs->y;
-    IDWTELEM *b[10];
-    for (i = 0; i < 8; i++)
-        b[i] = cs->b[i];
-    b[8] = d->buffer + av_clip(y+7, 0, height-2)*stride;
-    b[9] = d->buffer + av_clip(y+8, 1, height-1)*stride;
-
-        if(y+5<(unsigned)height) vertical_compose_l0(b[3], b[5], b[6], b[7], b[9], width);
-        if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
-
-        if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
-        if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
-
-    for (i = 0; i < 8; i++)
-        cs->b[i] = b[i+2];
-    cs->y += 2;
-}
-
-// haar makes the assumption that height is even (always true for dirac)
-static void spatial_compose_haari_dy(DWTContext *d, int level, int width, int height, int stride)
-{
-    vertical_compose_2tap vertical_compose = (void*)d->vertical_compose;
-    int y = d->cs[level].y;
-    IDWTELEM *b0 = d->buffer + (y-1)*stride;
-    IDWTELEM *b1 = d->buffer + (y  )*stride;
-
-    vertical_compose(b0, b1, width);
-    d->horizontal_compose(b0, d->temp, width);
-    d->horizontal_compose(b1, d->temp, width);
-
-    d->cs[level].y += 2;
-}
-
-// Don't do sliced idwt for fidelity; the 9 tap filter makes it a bit annoying
-// Fortunately, this filter isn't used in practice.
-static void spatial_compose_fidelity(DWTContext *d, int level, int width, int height, int stride)
-{
-    vertical_compose_9tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
-    vertical_compose_9tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
-    int i, y;
-    IDWTELEM *b[8];
-
-    for (y = 1; y < height; y += 2) {
-        for (i = 0; i < 8; i++)
-            b[i] = d->buffer + av_clip((y-7 + 2*i), 0, height-2)*stride;
-        vertical_compose_h0(d->buffer + y*stride, b, width);
-    }
-
-    for (y = 0; y < height; y += 2) {
-        for (i = 0; i < 8; i++)
-            b[i] = d->buffer + av_clip((y-7 + 2*i), 1, height-1)*stride;
-        vertical_compose_l0(d->buffer + y*stride, b, width);
-    }
-
-    for (y = 0; y < height; y++)
-        d->horizontal_compose(d->buffer + y*stride, d->temp, width);
-
-    d->cs[level].y = height+1;
-}
-
-static void spatial_compose_daub97i_dy(DWTContext *d, int level, int width, int height, int stride)
-{
-    vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
-    vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
-    vertical_compose_3tap vertical_compose_l1 = (void*)d->vertical_compose_l1;
-    vertical_compose_3tap vertical_compose_h1 = (void*)d->vertical_compose_h1;
-    DWTCompose *cs = d->cs + level;
-
-    int i, y = cs->y;
-    IDWTELEM *b[6];
-    for (i = 0; i < 4; i++)
-        b[i] = cs->b[i];
-    b[4] = d->buffer + mirror(y+3, height-1)*stride;
-    b[5] = d->buffer + mirror(y+4, height-1)*stride;
-
-        if(y+3<(unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width);
-        if(y+2<(unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width);
-        if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
-        if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
-
-        if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
-        if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
-
-    for (i = 0; i < 4; i++)
-        cs->b[i] = b[i+2];
-    cs->y += 2;
-}
-
-
-static void spatial_compose97i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
-{
-    cs->b[0] = buffer + mirror(-3-1, height-1)*stride;
-    cs->b[1] = buffer + mirror(-3  , height-1)*stride;
-    cs->b[2] = buffer + mirror(-3+1, height-1)*stride;
-    cs->b[3] = buffer + mirror(-3+2, height-1)*stride;
-    cs->y = -3;
-}
-
-static void spatial_compose53i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
-{
-    cs->b[0] = buffer + mirror(-1-1, height-1)*stride;
-    cs->b[1] = buffer + mirror(-1  , height-1)*stride;
-    cs->y = -1;
-}
-
-static void spatial_compose_dd97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
-{
-    cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
-    cs->b[1] = buffer + av_clip(-5  , 1, height-1)*stride;
-    cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
-    cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
-    cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
-    cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
-    cs->y = -5;
-}
-
-static void spatial_compose_dd137i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
-{
-    cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
-    cs->b[1] = buffer + av_clip(-5  , 1, height-1)*stride;
-    cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
-    cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
-    cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
-    cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
-    cs->b[6] = buffer + av_clip(-5+5, 0, height-2)*stride;
-    cs->b[7] = buffer + av_clip(-5+6, 1, height-1)*stride;
-    cs->y = -5;
-}
-
-int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height,
-                          int stride, enum dwt_type type, int decomposition_count,
-                          IDWTELEM *temp)
-{
-    int level;
-
-    d->buffer = buffer;
-    d->width = width;
-    d->height = height;
-    d->stride = stride;
-    d->decomposition_count = decomposition_count;
-    d->temp = temp + 8;
-
-    for(level=decomposition_count-1; level>=0; level--){
-        int hl = height >> level;
-        int stride_l = stride << level;
-
-        switch(type){
-        case DWT_DIRAC_DD9_7:
-            spatial_compose_dd97i_init(d->cs+level, buffer, hl, stride_l);
-            break;
-        case DWT_DIRAC_LEGALL5_3:
-            spatial_compose53i_init2(d->cs+level, buffer, hl, stride_l);
-            break;
-        case DWT_DIRAC_DD13_7:
-            spatial_compose_dd137i_init(d->cs+level, buffer, hl, stride_l);
-            break;
-        case DWT_DIRAC_HAAR0:
-        case DWT_DIRAC_HAAR1:
-            d->cs[level].y = 1;
-            break;
-        case DWT_DIRAC_DAUB9_7:
-            spatial_compose97i_init2(d->cs+level, buffer, hl, stride_l);
-            break;
-        default:
-            d->cs[level].y = 0;
-            break;
-        }
-    }
-
-    switch (type) {
-    case DWT_DIRAC_DD9_7:
-        d->spatial_compose = spatial_compose_dd97i_dy;
-        d->vertical_compose_l0 = (void*)vertical_compose53iL0;
-        d->vertical_compose_h0 = (void*)vertical_compose_dd97iH0;
-        d->horizontal_compose = horizontal_compose_dd97i;
-        d->support = 7;
-        break;
-    case DWT_DIRAC_LEGALL5_3:
-        d->spatial_compose = spatial_compose_dirac53i_dy;
-        d->vertical_compose_l0 = (void*)vertical_compose53iL0;
-        d->vertical_compose_h0 = (void*)vertical_compose_dirac53iH0;
-        d->horizontal_compose = horizontal_compose_dirac53i;
-        d->support = 3;
-        break;
-    case DWT_DIRAC_DD13_7:
-        d->spatial_compose = spatial_compose_dd137i_dy;
-        d->vertical_compose_l0 = (void*)vertical_compose_dd137iL0;
-        d->vertical_compose_h0 = (void*)vertical_compose_dd97iH0;
-        d->horizontal_compose = horizontal_compose_dd137i;
-        d->support = 7;
-        break;
-    case DWT_DIRAC_HAAR0:
-    case DWT_DIRAC_HAAR1:
-        d->spatial_compose = spatial_compose_haari_dy;
-        d->vertical_compose = (void*)vertical_compose_haar;
-        if (type == DWT_DIRAC_HAAR0)
-            d->horizontal_compose = horizontal_compose_haar0i;
-        else
-            d->horizontal_compose = horizontal_compose_haar1i;
-        d->support = 1;
-        break;
-    case DWT_DIRAC_FIDELITY:
-        d->spatial_compose = spatial_compose_fidelity;
-        d->vertical_compose_l0 = (void*)vertical_compose_fidelityiL0;
-        d->vertical_compose_h0 = (void*)vertical_compose_fidelityiH0;
-        d->horizontal_compose = horizontal_compose_fidelityi;
-        break;
-    case DWT_DIRAC_DAUB9_7:
-        d->spatial_compose = spatial_compose_daub97i_dy;
-        d->vertical_compose_l0 = (void*)vertical_compose_daub97iL0;
-        d->vertical_compose_h0 = (void*)vertical_compose_daub97iH0;
-        d->vertical_compose_l1 = (void*)vertical_compose_daub97iL1;
-        d->vertical_compose_h1 = (void*)vertical_compose_daub97iH1;
-        d->horizontal_compose = horizontal_compose_daub97i;
-        d->support = 5;
-        break;
-    default:
-        av_log(NULL, AV_LOG_ERROR, "Unknown wavelet type %d\n", type);
-        return -1;
-    }
-
-    if (HAVE_MMX) ff_spatial_idwt_init_mmx(d, type);
-
-    return 0;
-}
-
-void ff_spatial_idwt_slice2(DWTContext *d, int y)
-{
-    int level, support = d->support;
-
-    for (level = d->decomposition_count-1; level >= 0; level--) {
-        int wl = d->width  >> level;
-        int hl = d->height >> level;
-        int stride_l = d->stride << level;
-
-        while (d->cs[level].y <= FFMIN((y>>level)+support, hl))
-            d->spatial_compose(d, level, wl, hl, stride_l);
-    }
-}
-
-int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride,
-                     enum dwt_type type, int decomposition_count, IDWTELEM *temp)
-{
-    DWTContext d;
-    int y;
-
-    if (ff_spatial_idwt_init2(&d, buffer, width, height, stride, type, decomposition_count, temp))
-        return -1;
-
-    for (y = 0; y < d.height; y += 4)
-        ff_spatial_idwt_slice2(&d, y);
-
-    return 0;
-}
diff --git a/mythtv/external/FFmpeg/libavcodec/dwt.h b/mythtv/external/FFmpeg/libavcodec/snow_dwt.h
similarity index 58%
rename from mythtv/external/FFmpeg/libavcodec/dwt.h
rename to mythtv/external/FFmpeg/libavcodec/snow_dwt.h
index d82e5100066..0806b389e26 100644
--- a/mythtv/external/FFmpeg/libavcodec/dwt.h
+++ b/mythtv/external/FFmpeg/libavcodec/snow_dwt.h
@@ -18,20 +18,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef AVCODEC_DWT_H
-#define AVCODEC_DWT_H
+#ifndef AVCODEC_SNOW_DWT_H
+#define AVCODEC_SNOW_DWT_H
 
 #include 
 
 typedef int DWTELEM;
 typedef short IDWTELEM;
 
-#define MAX_DWT_SUPPORT 8
 #define MAX_DECOMPOSITIONS 8
 
 typedef struct DWTCompose {
-    IDWTELEM *b[MAX_DWT_SUPPORT];
-
     IDWTELEM *b0;
     IDWTELEM *b1;
     IDWTELEM *b2;
@@ -51,31 +48,9 @@ typedef struct slice_buffer_s {
     IDWTELEM *base_buffer;  ///< Buffer that this structure is caching.
 } slice_buffer;
 
-struct DWTContext;
-
-// Possible prototypes for vertical_compose functions
-typedef void (*vertical_compose_2tap)(IDWTELEM *b0, IDWTELEM *b1, int width);
-typedef void (*vertical_compose_3tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width);
-typedef void (*vertical_compose_5tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, int width);
-typedef void (*vertical_compose_9tap)(IDWTELEM *dst, IDWTELEM *b[8], int width);
-
-typedef struct DWTContext {
-    IDWTELEM *buffer;
-    IDWTELEM *temp;
-    int width;
-    int height;
-    int stride;
-    int decomposition_count;
-    int support;
-
-    void (*spatial_compose)(struct DWTContext *cs, int level, int width, int height, int stride);
-    void (*vertical_compose_l0)(void);
-    void (*vertical_compose_h0)(void);
-    void (*vertical_compose_l1)(void);
-    void (*vertical_compose_h1)(void);
-    void (*vertical_compose)(void);     ///< one set of lowpass and highpass combined
-    void (*horizontal_compose)(IDWTELEM *b, IDWTELEM *tmp, int width);
+struct SnowDWTContext;
 
+typedef struct SnowDWTContext {
     void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
                                 IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5,
                                 int width);
@@ -84,70 +59,7 @@ typedef struct DWTContext {
                              uint8_t **block, int b_w, int b_h, int src_x,
                              int src_y, int src_stride, slice_buffer *sb,
                              int add, uint8_t *dst8);
-
-    DWTCompose cs[MAX_DECOMPOSITIONS];
-} DWTContext;
-
-enum dwt_type {
-    DWT_SNOW_DAUB9_7,
-    DWT_SNOW_LEGALL5_3,
-    DWT_DIRAC_DD9_7,
-    DWT_DIRAC_LEGALL5_3,
-    DWT_DIRAC_DD13_7,
-    DWT_DIRAC_HAAR0,
-    DWT_DIRAC_HAAR1,
-    DWT_DIRAC_FIDELITY,
-    DWT_DIRAC_DAUB9_7,
-    DWT_NUM_TYPES
-};
-
-// -1 if an error occurred, e.g. the dwt_type isn't recognized
-int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height,
-                          int stride, enum dwt_type type, int decomposition_count,
-                          IDWTELEM *temp);
-
-int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride,
-                     enum dwt_type type, int decomposition_count, IDWTELEM *temp);
-
-void ff_spatial_idwt_slice2(DWTContext *d, int y);
-
-// shared stuff for simd optimiztions
-#define COMPOSE_53iL0(b0, b1, b2)\
-    (b1 - ((b0 + b2 + 2) >> 2))
-
-#define COMPOSE_DIRAC53iH0(b0, b1, b2)\
-    (b1 + ((b0 + b2 + 1) >> 1))
-
-#define COMPOSE_DD97iH0(b0, b1, b2, b3, b4)\
-    (b2 + ((-b0 + 9*b1 + 9*b3 - b4 + 8) >> 4))
-
-#define COMPOSE_DD137iL0(b0, b1, b2, b3, b4)\
-    (b2 - ((-b0 + 9*b1 + 9*b3 - b4 + 16) >> 5))
-
-#define COMPOSE_HAARiL0(b0, b1)\
-    (b0 - ((b1 + 1) >> 1))
-
-#define COMPOSE_HAARiH0(b0, b1)\
-    (b0 + b1)
-
-#define COMPOSE_FIDELITYiL0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\
-    (b4 - ((-8*(b0+b8) + 21*(b1+b7) - 46*(b2+b6) + 161*(b3+b5) + 128) >> 8))
-
-#define COMPOSE_FIDELITYiH0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\
-    (b4 + ((-2*(b0+b8) + 10*(b1+b7) - 25*(b2+b6) + 81*(b3+b5) + 128) >> 8))
-
-#define COMPOSE_DAUB97iL1(b0, b1, b2)\
-    (b1 - ((1817*(b0 + b2) + 2048) >> 12))
-
-#define COMPOSE_DAUB97iH1(b0, b1, b2)\
-    (b1 - (( 113*(b0 + b2) + 64) >> 7))
-
-#define COMPOSE_DAUB97iL0(b0, b1, b2)\
-    (b1 + (( 217*(b0 + b2) + 2048) >> 12))
-
-#define COMPOSE_DAUB97iH0(b0, b1, b2)\
-    (b1 + ((6497*(b0 + b2) + 2048) >> 12))
-
+} SnowDWTContext;
 
 
 #define DWT_97 0
@@ -202,14 +114,14 @@ void ff_spatial_dwt(int *buffer, int *temp, int width, int height, int stride,
 void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width,
                                    int height, int stride_line, int type,
                                    int decomposition_count);
-void ff_spatial_idwt_buffered_slice(DWTContext *dsp, DWTCompose *cs,
+void ff_spatial_idwt_buffered_slice(SnowDWTContext *dsp, DWTCompose *cs,
                                     slice_buffer *slice_buf, IDWTELEM *temp,
                                     int width, int height, int stride_line,
                                     int type, int decomposition_count, int y);
 void ff_spatial_idwt(IDWTELEM *buffer, IDWTELEM *temp, int width, int height,
                      int stride, int type, int decomposition_count);
 
-void ff_dwt_init(DWTContext *c);
-void ff_dwt_init_x86(DWTContext *c);
+void ff_dwt_init(SnowDWTContext *c);
+void ff_dwt_init_x86(SnowDWTContext *c);
 
 #endif /* AVCODEC_DWT_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/snowdec.c b/mythtv/external/FFmpeg/libavcodec/snowdec.c
index c4baf0a7d12..e2115068c81 100644
--- a/mythtv/external/FFmpeg/libavcodec/snowdec.c
+++ b/mythtv/external/FFmpeg/libavcodec/snowdec.c
@@ -23,7 +23,7 @@
 #include "libavutil/opt.h"
 #include "avcodec.h"
 #include "dsputil.h"
-#include "dwt.h"
+#include "snow_dwt.h"
 #include "internal.h"
 #include "snow.h"
 
diff --git a/mythtv/external/FFmpeg/libavcodec/snowenc.c b/mythtv/external/FFmpeg/libavcodec/snowenc.c
index de2c859302a..c0c847a9fb1 100644
--- a/mythtv/external/FFmpeg/libavcodec/snowenc.c
+++ b/mythtv/external/FFmpeg/libavcodec/snowenc.c
@@ -25,7 +25,7 @@
 #include "internal.h"
 #include "dsputil.h"
 #include "internal.h"
-#include "dwt.h"
+#include "snow_dwt.h"
 #include "snow.h"
 
 #include "rangecoder.h"
@@ -287,6 +287,30 @@ static int pix_norm1(uint8_t * pix, int line_size, int w)
     return s;
 }
 
+static inline int get_penalty_factor(int lambda, int lambda2, int type){
+    switch(type&0xFF){
+    default:
+    case FF_CMP_SAD:
+        return lambda>>FF_LAMBDA_SHIFT;
+    case FF_CMP_DCT:
+        return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
+    case FF_CMP_W53:
+        return (4*lambda)>>(FF_LAMBDA_SHIFT);
+    case FF_CMP_W97:
+        return (2*lambda)>>(FF_LAMBDA_SHIFT);
+    case FF_CMP_SATD:
+    case FF_CMP_DCT264:
+        return (2*lambda)>>FF_LAMBDA_SHIFT;
+    case FF_CMP_RD:
+    case FF_CMP_PSNR:
+    case FF_CMP_SSE:
+    case FF_CMP_NSSE:
+        return lambda2>>FF_LAMBDA_SHIFT;
+    case FF_CMP_BIT:
+        return 1;
+    }
+}
+
 //FIXME copy&paste
 #define P_LEFT P[1]
 #define P_TOP P[2]
@@ -1647,7 +1671,13 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
             memcpy(&s->input_picture.data[i][y * s->input_picture.linesize[i]],
                    &pict->data[i][y * pict->linesize[i]],
                    width>>hshift);
+        s->dsp.draw_edges(s->input_picture.data[i], s->input_picture.linesize[i],
+                            width >> hshift, height >> vshift,
+                            EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift,
+                            EDGE_TOP | EDGE_BOTTOM);
+
     }
+    emms_c();
     s->new_picture = *pict;
 
     s->m.picture_number= avctx->frame_number;
diff --git a/mythtv/external/FFmpeg/libavcodec/sonic.c b/mythtv/external/FFmpeg/libavcodec/sonic.c
index 0bc8428a1e9..ae54388ff61 100644
--- a/mythtv/external/FFmpeg/libavcodec/sonic.c
+++ b/mythtv/external/FFmpeg/libavcodec/sonic.c
@@ -632,7 +632,7 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     int ret;
     const short *samples = (const int16_t*)frame->data[0];
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size * 5 + 1000)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size * 5 + 1000)) < 0)
         return ret;
 
     init_put_bits(&pb, avpkt->data, avpkt->size);
diff --git a/mythtv/external/FFmpeg/libavcodec/sparc/dsputil_vis.c b/mythtv/external/FFmpeg/libavcodec/sparc/dsputil_vis.c
index 5b5b96e60f5..0ade237c828 100644
--- a/mythtv/external/FFmpeg/libavcodec/sparc/dsputil_vis.c
+++ b/mythtv/external/FFmpeg/libavcodec/sparc/dsputil_vis.c
@@ -26,6 +26,7 @@
 
 #include 
 
+#include "libavutil/attributes.h"
 #include "libavcodec/dsputil.h"
 #include "libavutil/mem.h"
 #include "dsputil_vis.h"
@@ -120,7 +121,7 @@ DECLARE_ALIGNED(8, static const int16_t, constants256_1024)[] =
 #define TMP32           58
 
 static void MC_put_o_16_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                             const ptrdiff_t stride, int height)
 {
         ref = vis_alignaddr(ref);
         do {    /* 5 cycles */
@@ -141,7 +142,7 @@ static void MC_put_o_16_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_put_o_8_vis (uint8_t * dest, const uint8_t * ref,
-                            const int stride, int height)
+                            const ptrdiff_t stride, int height)
 {
         ref = vis_alignaddr(ref);
         do {    /* 4 cycles */
@@ -160,7 +161,7 @@ static void MC_put_o_8_vis (uint8_t * dest, const uint8_t * ref,
 
 
 static void MC_avg_o_16_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                             const ptrdiff_t stride, int height)
 {
         int stride_8 = stride + 8;
 
@@ -320,7 +321,7 @@ static void MC_avg_o_16_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_avg_o_8_vis (uint8_t * dest, const uint8_t * ref,
-                            const int stride, int height)
+                            const ptrdiff_t stride, int height)
 {
         ref = vis_alignaddr(ref);
 
@@ -412,7 +413,7 @@ static void MC_avg_o_8_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_put_x_16_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                             const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -604,7 +605,7 @@ static void MC_put_x_16_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_put_x_8_vis (uint8_t * dest, const uint8_t * ref,
-                            const int stride, int height)
+                            const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -727,7 +728,7 @@ static void MC_put_x_8_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_avg_x_16_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                             const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -817,7 +818,7 @@ static void MC_avg_x_16_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_avg_x_8_vis (uint8_t * dest, const uint8_t * ref,
-                            const int stride, int height)
+                            const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -982,7 +983,7 @@ static void MC_avg_x_8_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_put_y_16_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                             const ptrdiff_t stride, int height)
 {
         ref = vis_alignaddr(ref);
         vis_ld64(ref[0], TMP0);
@@ -1136,7 +1137,7 @@ static void MC_put_y_16_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_put_y_8_vis (uint8_t * dest, const uint8_t * ref,
-                            const int stride, int height)
+                            const ptrdiff_t stride, int height)
 {
         ref = vis_alignaddr(ref);
         vis_ld64(ref[0], TMP0);
@@ -1226,7 +1227,7 @@ static void MC_put_y_8_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_avg_y_16_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                             const ptrdiff_t stride, int height)
 {
         int stride_8 = stride + 8;
         int stride_16 = stride + 16;
@@ -1354,7 +1355,7 @@ static void MC_avg_y_16_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_avg_y_8_vis (uint8_t * dest, const uint8_t * ref,
-                            const int stride, int height)
+                            const ptrdiff_t stride, int height)
 {
         int stride_8 = stride + 8;
 
@@ -1433,7 +1434,7 @@ static void MC_avg_y_8_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_put_xy_16_vis (uint8_t * dest, const uint8_t * ref,
-                              const int stride, int height)
+                              const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -1597,7 +1598,7 @@ static void MC_put_xy_16_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_put_xy_8_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                             const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -1701,7 +1702,7 @@ static void MC_put_xy_8_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_avg_xy_16_vis (uint8_t * dest, const uint8_t * ref,
-                              const int stride, int height)
+                              const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -1897,7 +1898,7 @@ static void MC_avg_xy_16_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_avg_xy_8_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                             const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -2040,7 +2041,7 @@ static void MC_avg_xy_8_vis (uint8_t * dest, const uint8_t * ref,
  */
 
 static void MC_put_no_round_o_16_vis (uint8_t * dest, const uint8_t * ref,
-                                      const int stride, int height)
+                                      const ptrdiff_t stride, int height)
 {
         ref = vis_alignaddr(ref);
         do {    /* 5 cycles */
@@ -2061,7 +2062,7 @@ static void MC_put_no_round_o_16_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_put_no_round_o_8_vis (uint8_t * dest, const uint8_t * ref,
-                            const int stride, int height)
+                                     const ptrdiff_t stride, int height)
 {
         ref = vis_alignaddr(ref);
         do {    /* 4 cycles */
@@ -2080,7 +2081,7 @@ static void MC_put_no_round_o_8_vis (uint8_t * dest, const uint8_t * ref,
 
 
 static void MC_avg_no_round_o_16_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                                      const ptrdiff_t stride, int height)
 {
         int stride_8 = stride + 8;
 
@@ -2239,100 +2240,8 @@ static void MC_avg_no_round_o_16_vis (uint8_t * dest, const uint8_t * ref,
         vis_st64_2(TMP22, dest, 8);
 }
 
-static void MC_avg_no_round_o_8_vis (uint8_t * dest, const uint8_t * ref,
-                            const int stride, int height)
-{
-        ref = vis_alignaddr(ref);
-
-        vis_ld64(ref[0], TMP0);
-
-        vis_ld64(ref[8], TMP2);
-
-        vis_ld64(dest[0], DST_0);
-
-        vis_ld64(constants_fe[0], MASK_fe);
-
-        vis_ld64(constants_7f[0], MASK_7f);
-        vis_faligndata(TMP0, TMP2, REF_0);
-
-        vis_ld64(constants128[0], CONST_128);
-
-        ref += stride;
-        height = (height >> 1) - 1;
-
-        do {    /* 12 cycles */
-                vis_ld64(ref[0], TMP0);
-                vis_xor(DST_0, REF_0, TMP4);
-
-                vis_ld64(ref[8], TMP2);
-                vis_and(TMP4, MASK_fe, TMP4);
-
-                vis_and(DST_0, REF_0, TMP6);
-                vis_ld64_2(dest, stride, DST_0);
-                ref += stride;
-                vis_mul8x16(CONST_128, TMP4, TMP4);
-
-                vis_ld64(ref[0], TMP12);
-                vis_faligndata(TMP0, TMP2, REF_0);
-
-                vis_ld64(ref[8], TMP2);
-                vis_xor(DST_0, REF_0, TMP0);
-                ref += stride;
-
-                vis_and(TMP0, MASK_fe, TMP0);
-
-                vis_and(TMP4, MASK_7f, TMP4);
-
-                vis_padd16(TMP6, TMP4, TMP4);
-                vis_st64(TMP4, dest[0]);
-                dest += stride;
-                vis_mul8x16(CONST_128, TMP0, TMP0);
-
-                vis_and(DST_0, REF_0, TMP6);
-                vis_ld64_2(dest, stride, DST_0);
-
-                vis_faligndata(TMP12, TMP2, REF_0);
-
-                vis_and(TMP0, MASK_7f, TMP0);
-
-                vis_padd16(TMP6, TMP0, TMP4);
-                vis_st64(TMP4, dest[0]);
-                dest += stride;
-        } while (--height);
-
-        vis_ld64(ref[0], TMP0);
-        vis_xor(DST_0, REF_0, TMP4);
-
-        vis_ld64(ref[8], TMP2);
-        vis_and(TMP4, MASK_fe, TMP4);
-
-        vis_and(DST_0, REF_0, TMP6);
-        vis_ld64_2(dest, stride, DST_0);
-        vis_mul8x16(CONST_128, TMP4, TMP4);
-
-        vis_faligndata(TMP0, TMP2, REF_0);
-
-        vis_xor(DST_0, REF_0, TMP0);
-
-        vis_and(TMP0, MASK_fe, TMP0);
-
-        vis_and(TMP4, MASK_7f, TMP4);
-
-        vis_padd16(TMP6, TMP4, TMP4);
-        vis_st64(TMP4, dest[0]);
-        dest += stride;
-        vis_mul8x16(CONST_128, TMP0, TMP0);
-
-        vis_and(DST_0, REF_0, TMP6);
-
-        vis_and(TMP0, MASK_7f, TMP0);
-
-        vis_padd16(TMP6, TMP0, TMP4);
-        vis_st64(TMP4, dest[0]);
-}
-
 static void MC_put_no_round_x_16_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                                      const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -2524,7 +2433,7 @@ static void MC_put_no_round_x_16_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_put_no_round_x_8_vis (uint8_t * dest, const uint8_t * ref,
-                            const int stride, int height)
+                                     const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -2647,7 +2556,7 @@ static void MC_put_no_round_x_8_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_avg_no_round_x_16_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                                      const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -2736,173 +2645,8 @@ static void MC_avg_no_round_x_16_vis (uint8_t * dest, const uint8_t * ref,
         } while (--height);
 }
 
-static void MC_avg_no_round_x_8_vis (uint8_t * dest, const uint8_t * ref,
-                            const int stride, int height)
-{
-        unsigned long off = (unsigned long) ref & 0x7;
-        unsigned long off_plus_1 = off + 1;
-        int stride_times_2 = stride << 1;
-
-        vis_set_gsr(5 << VIS_GSR_SCALEFACT_SHIFT);
-
-        vis_ld64(constants3[0], CONST_3);
-        vis_fzero(ZERO);
-        vis_ld64(constants256_512[0], CONST_256);
-
-        ref = vis_alignaddr(ref);
-        height >>= 2;
-        do {    /* 47 cycles */
-                vis_ld64(ref[0],   TMP0);
-
-                vis_ld64_2(ref, 8, TMP2);
-                ref += stride;
-
-                vis_alignaddr_g0((void *)off);
-
-                vis_ld64(ref[0],   TMP4);
-                vis_faligndata(TMP0, TMP2, REF_0);
-
-                vis_ld64_2(ref, 8, TMP6);
-                ref += stride;
-
-                vis_ld64(ref[0],   TMP8);
-
-                vis_ld64_2(ref, 8, TMP10);
-                ref += stride;
-                vis_faligndata(TMP4, TMP6, REF_4);
-
-                vis_ld64(ref[0],   TMP12);
-
-                vis_ld64_2(ref, 8, TMP14);
-                ref += stride;
-                vis_faligndata(TMP8, TMP10, REF_S0);
-
-                vis_faligndata(TMP12, TMP14, REF_S4);
-
-                if (off != 0x7) {
-                        vis_alignaddr_g0((void *)off_plus_1);
-
-                        vis_ld64(dest[0], DST_0);
-                        vis_faligndata(TMP0, TMP2, REF_2);
-
-                        vis_ld64_2(dest, stride, DST_2);
-                        vis_faligndata(TMP4, TMP6, REF_6);
-
-                        vis_faligndata(TMP8, TMP10, REF_S2);
-
-                        vis_faligndata(TMP12, TMP14, REF_S6);
-                } else {
-                        vis_ld64(dest[0], DST_0);
-                        vis_src1(TMP2, REF_2);
-
-                        vis_ld64_2(dest, stride, DST_2);
-                        vis_src1(TMP6, REF_6);
-
-                        vis_src1(TMP10, REF_S2);
-
-                        vis_src1(TMP14, REF_S6);
-                }
-
-                vis_pmerge(ZERO,     REF_0,     TMP0);
-                vis_mul8x16au(REF_0_1, CONST_256, TMP2);
-
-                vis_pmerge(ZERO,     REF_2,     TMP4);
-                vis_mul8x16au(REF_2_1, CONST_256, TMP6);
-
-                vis_padd16(TMP0, CONST_3, TMP0);
-                vis_mul8x16al(DST_0,   CONST_512, TMP16);
-
-                vis_padd16(TMP2, CONST_3, TMP2);
-                vis_mul8x16al(DST_1,   CONST_512, TMP18);
-
-                vis_padd16(TMP0, TMP4, TMP0);
-                vis_mul8x16au(REF_4, CONST_256, TMP8);
-
-                vis_padd16(TMP2, TMP6, TMP2);
-                vis_mul8x16au(REF_4_1, CONST_256, TMP10);
-
-                vis_padd16(TMP0, TMP16, TMP0);
-                vis_mul8x16au(REF_6, CONST_256, TMP12);
-
-                vis_padd16(TMP2, TMP18, TMP2);
-                vis_mul8x16au(REF_6_1, CONST_256, TMP14);
-
-                vis_padd16(TMP8, CONST_3, TMP8);
-                vis_mul8x16al(DST_2, CONST_512, TMP16);
-
-                vis_padd16(TMP8, TMP12, TMP8);
-                vis_mul8x16al(DST_3, CONST_512, TMP18);
-
-                vis_padd16(TMP10, TMP14, TMP10);
-                vis_pack16(TMP0, DST_0);
-
-                vis_pack16(TMP2, DST_1);
-                vis_st64(DST_0, dest[0]);
-                dest += stride;
-                vis_padd16(TMP10, CONST_3, TMP10);
-
-                vis_ld64_2(dest, stride, DST_0);
-                vis_padd16(TMP8, TMP16, TMP8);
-
-                vis_ld64_2(dest, stride_times_2, TMP4/*DST_2*/);
-                vis_padd16(TMP10, TMP18, TMP10);
-                vis_pack16(TMP8, DST_2);
-
-                vis_pack16(TMP10, DST_3);
-                vis_st64(DST_2, dest[0]);
-                dest += stride;
-
-                vis_mul8x16au(REF_S0_1, CONST_256, TMP2);
-                vis_pmerge(ZERO,     REF_S0,     TMP0);
-
-                vis_pmerge(ZERO,     REF_S2,     TMP24);
-                vis_mul8x16au(REF_S2_1, CONST_256, TMP6);
-
-                vis_padd16(TMP0, CONST_3, TMP0);
-                vis_mul8x16au(REF_S4, CONST_256, TMP8);
-
-                vis_padd16(TMP2, CONST_3, TMP2);
-                vis_mul8x16au(REF_S4_1, CONST_256, TMP10);
-
-                vis_padd16(TMP0, TMP24, TMP0);
-                vis_mul8x16au(REF_S6, CONST_256, TMP12);
-
-                vis_padd16(TMP2, TMP6, TMP2);
-                vis_mul8x16au(REF_S6_1, CONST_256, TMP14);
-
-                vis_padd16(TMP8, CONST_3, TMP8);
-                vis_mul8x16al(DST_0,   CONST_512, TMP16);
-
-                vis_padd16(TMP10, CONST_3, TMP10);
-                vis_mul8x16al(DST_1,   CONST_512, TMP18);
-
-                vis_padd16(TMP8, TMP12, TMP8);
-                vis_mul8x16al(TMP4/*DST_2*/, CONST_512, TMP20);
-
-                vis_mul8x16al(TMP5/*DST_3*/, CONST_512, TMP22);
-                vis_padd16(TMP0, TMP16, TMP0);
-
-                vis_padd16(TMP2, TMP18, TMP2);
-                vis_pack16(TMP0, DST_0);
-
-                vis_padd16(TMP10, TMP14, TMP10);
-                vis_pack16(TMP2, DST_1);
-                vis_st64(DST_0, dest[0]);
-                dest += stride;
-
-                vis_padd16(TMP8, TMP20, TMP8);
-
-                vis_padd16(TMP10, TMP22, TMP10);
-                vis_pack16(TMP8, DST_2);
-
-                vis_pack16(TMP10, DST_3);
-                vis_st64(DST_2, dest[0]);
-                dest += stride;
-        } while (--height);
-}
-
 static void MC_put_no_round_y_16_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                                      const ptrdiff_t stride, int height)
 {
         ref = vis_alignaddr(ref);
         vis_ld64(ref[0], TMP0);
@@ -3056,7 +2800,7 @@ static void MC_put_no_round_y_16_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_put_no_round_y_8_vis (uint8_t * dest, const uint8_t * ref,
-                            const int stride, int height)
+                                     const ptrdiff_t stride, int height)
 {
         ref = vis_alignaddr(ref);
         vis_ld64(ref[0], TMP0);
@@ -3146,7 +2890,7 @@ static void MC_put_no_round_y_8_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_avg_no_round_y_16_vis (uint8_t * dest, const uint8_t * ref,
-                             const int stride, int height)
+                                      const ptrdiff_t stride, int height)
 {
         int stride_8 = stride + 8;
         int stride_16 = stride + 16;
@@ -3273,87 +3017,8 @@ static void MC_avg_no_round_y_16_vis (uint8_t * dest, const uint8_t * ref,
         } while (--height);
 }
 
-static void MC_avg_no_round_y_8_vis (uint8_t * dest, const uint8_t * ref,
-                            const int stride, int height)
-{
-        int stride_8 = stride + 8;
-
-        vis_set_gsr(5 << VIS_GSR_SCALEFACT_SHIFT);
-
-        ref = vis_alignaddr(ref);
-
-        vis_ld64(ref[ 0], TMP0);
-        vis_fzero(ZERO);
-
-        vis_ld64(ref[ 8], TMP2);
-
-        vis_ld64(constants3[0], CONST_3);
-        vis_faligndata(TMP0, TMP2, REF_2);
-
-        vis_ld64(constants256_512[0], CONST_256);
-
-        height >>= 1;
-        do {    /* 20 cycles */
-                vis_ld64_2(ref, stride, TMP0);
-                vis_pmerge(ZERO,       REF_2,     TMP8);
-                vis_mul8x16au(REF_2_1, CONST_256, TMP10);
-
-                vis_ld64_2(ref, stride_8, TMP2);
-                ref += stride;
-
-                vis_ld64(dest[0], DST_0);
-
-                vis_ld64_2(dest, stride, DST_2);
-                vis_faligndata(TMP0, TMP2, REF_0);
-
-                vis_ld64_2(ref, stride, TMP4);
-                vis_mul8x16al(DST_0,   CONST_512, TMP16);
-                vis_pmerge(ZERO,       REF_0,     TMP12);
-
-                vis_ld64_2(ref, stride_8, TMP6);
-                ref += stride;
-                vis_mul8x16al(DST_1,   CONST_512, TMP18);
-                vis_pmerge(ZERO,       REF_0_1,   TMP14);
-
-                vis_padd16(TMP12, CONST_3, TMP12);
-                vis_mul8x16al(DST_2,   CONST_512, TMP24);
-
-                vis_padd16(TMP14, CONST_3, TMP14);
-                vis_mul8x16al(DST_3,   CONST_512, TMP26);
-
-                vis_faligndata(TMP4, TMP6, REF_2);
-
-                vis_padd16(TMP8, TMP12, TMP8);
-
-                vis_padd16(TMP10, TMP14, TMP10);
-                vis_mul8x16au(REF_2,   CONST_256, TMP20);
-
-                vis_padd16(TMP8, TMP16, TMP0);
-                vis_mul8x16au(REF_2_1, CONST_256, TMP22);
-
-                vis_padd16(TMP10, TMP18, TMP2);
-                vis_pack16(TMP0, DST_0);
-
-                vis_pack16(TMP2, DST_1);
-                vis_st64(DST_0, dest[0]);
-                dest += stride;
-                vis_padd16(TMP12, TMP20, TMP12);
-
-                vis_padd16(TMP14, TMP22, TMP14);
-
-                vis_padd16(TMP12, TMP24, TMP0);
-
-                vis_padd16(TMP14, TMP26, TMP2);
-                vis_pack16(TMP0, DST_2);
-
-                vis_pack16(TMP2, DST_3);
-                vis_st64(DST_2, dest[0]);
-                dest += stride;
-        } while (--height);
-}
-
 static void MC_put_no_round_xy_16_vis (uint8_t * dest, const uint8_t * ref,
-                                       const int stride, int height)
+                                       const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -3517,7 +3182,7 @@ static void MC_put_no_round_xy_16_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_put_no_round_xy_8_vis (uint8_t * dest, const uint8_t * ref,
-                                      const int stride, int height)
+                                      const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -3621,7 +3286,7 @@ static void MC_put_no_round_xy_8_vis (uint8_t * dest, const uint8_t * ref,
 }
 
 static void MC_avg_no_round_xy_16_vis (uint8_t * dest, const uint8_t * ref,
-                                       const int stride, int height)
+                                       const ptrdiff_t stride, int height)
 {
         unsigned long off = (unsigned long) ref & 0x7;
         unsigned long off_plus_1 = off + 1;
@@ -3816,126 +3481,6 @@ static void MC_avg_no_round_xy_16_vis (uint8_t * dest, const uint8_t * ref,
         } while (--height);
 }
 
-static void MC_avg_no_round_xy_8_vis (uint8_t * dest, const uint8_t * ref,
-                                      const int stride, int height)
-{
-        unsigned long off = (unsigned long) ref & 0x7;
-        unsigned long off_plus_1 = off + 1;
-        int stride_8 = stride + 8;
-
-        vis_set_gsr(4 << VIS_GSR_SCALEFACT_SHIFT);
-
-        ref = vis_alignaddr(ref);
-
-        vis_ld64(ref[0], TMP0);
-        vis_fzero(ZERO);
-
-        vis_ld64_2(ref, 8, TMP2);
-
-        vis_ld64(constants6[0], CONST_6);
-
-        vis_ld64(constants256_1024[0], CONST_256);
-        vis_faligndata(TMP0, TMP2, REF_S0);
-
-        if (off != 0x7) {
-                vis_alignaddr_g0((void *)off_plus_1);
-                vis_faligndata(TMP0, TMP2, REF_S2);
-        } else {
-                vis_src1(TMP2, REF_S2);
-        }
-
-        height >>= 1;
-        do {    /* 31 cycles */
-                vis_ld64_2(ref, stride, TMP0);
-                vis_mul8x16au(REF_S0, CONST_256, TMP8);
-                vis_pmerge(ZERO,      REF_S0_1,  TMP10);
-
-                vis_ld64_2(ref, stride_8, TMP2);
-                ref += stride;
-                vis_mul8x16au(REF_S2, CONST_256, TMP12);
-                vis_pmerge(ZERO,      REF_S2_1,  TMP14);
-
-                vis_alignaddr_g0((void *)off);
-
-                vis_ld64_2(ref, stride, TMP4);
-                vis_faligndata(TMP0, TMP2, REF_S4);
-
-                vis_ld64_2(ref, stride_8, TMP6);
-                ref += stride;
-
-                vis_ld64(dest[0], DST_0);
-                vis_faligndata(TMP4, TMP6, REF_S0);
-
-                vis_ld64_2(dest, stride, DST_2);
-
-                if (off != 0x7) {
-                        vis_alignaddr_g0((void *)off_plus_1);
-                        vis_faligndata(TMP0, TMP2, REF_S6);
-                        vis_faligndata(TMP4, TMP6, REF_S2);
-                } else {
-                        vis_src1(TMP2, REF_S6);
-                        vis_src1(TMP6, REF_S2);
-                }
-
-                vis_mul8x16al(DST_0,   CONST_1024, TMP30);
-                vis_pmerge(ZERO, REF_S4, TMP22);
-
-                vis_mul8x16al(DST_1,   CONST_1024, TMP32);
-                vis_pmerge(ZERO,      REF_S4_1,  TMP24);
-
-                vis_mul8x16au(REF_S6, CONST_256, TMP26);
-                vis_pmerge(ZERO,      REF_S6_1,  TMP28);
-
-                vis_mul8x16au(REF_S0, CONST_256, REF_S4);
-                vis_padd16(TMP22, CONST_6, TMP22);
-
-                vis_mul8x16au(REF_S0_1, CONST_256, REF_S6);
-                vis_padd16(TMP24, CONST_6, TMP24);
-
-                vis_mul8x16al(DST_2,   CONST_1024, REF_0);
-                vis_padd16(TMP22, TMP26, TMP22);
-
-                vis_mul8x16al(DST_3,   CONST_1024, REF_2);
-                vis_padd16(TMP24, TMP28, TMP24);
-
-                vis_mul8x16au(REF_S2, CONST_256, TMP26);
-                vis_padd16(TMP8, TMP22, TMP8);
-
-                vis_mul8x16au(REF_S2_1, CONST_256, TMP28);
-                vis_padd16(TMP10, TMP24, TMP10);
-
-                vis_padd16(TMP8, TMP12, TMP8);
-
-                vis_padd16(TMP10, TMP14, TMP10);
-
-                vis_padd16(TMP8, TMP30, TMP8);
-
-                vis_padd16(TMP10, TMP32, TMP10);
-                vis_pack16(TMP8, DST_0);
-
-                vis_pack16(TMP10, DST_1);
-                vis_st64(DST_0, dest[0]);
-                dest += stride;
-
-                vis_padd16(REF_S4, TMP22, TMP12);
-
-                vis_padd16(REF_S6, TMP24, TMP14);
-
-                vis_padd16(TMP12, TMP26, TMP12);
-
-                vis_padd16(TMP14, TMP28, TMP14);
-
-                vis_padd16(TMP12, REF_0, TMP12);
-
-                vis_padd16(TMP14, REF_2, TMP14);
-                vis_pack16(TMP12, DST_2);
-
-                vis_pack16(TMP14, DST_3);
-                vis_st64(DST_2, dest[0]);
-                dest += stride;
-        } while (--height);
-}
-
 /* End of no rounding code */
 
 #define ACCEL_SPARC_VIS 1
@@ -3950,22 +3495,20 @@ static int vis_level(void)
 }
 
 /* libavcodec initialization code */
-void ff_dsputil_init_vis(DSPContext* c, AVCodecContext *avctx)
+av_cold void ff_dsputil_init_vis(DSPContext *c, AVCodecContext *avctx)
 {
   /* VIS-specific optimizations */
   int accel = vis_level ();
   const int high_bit_depth = avctx->bits_per_raw_sample > 8;
 
-  if (accel & ACCEL_SPARC_VIS) {
-      if (avctx->bits_per_raw_sample <= 8 &&
-          avctx->idct_algo == FF_IDCT_SIMPLEVIS) {
+  if (accel & ACCEL_SPARC_VIS && !high_bit_depth) {
+      if (avctx->idct_algo == FF_IDCT_SIMPLEVIS) {
           c->idct_put = ff_simple_idct_put_vis;
           c->idct_add = ff_simple_idct_add_vis;
           c->idct     = ff_simple_idct_vis;
           c->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
       }
 
-      if (!high_bit_depth) {
       c->put_pixels_tab[0][0] = MC_put_o_16_vis;
       c->put_pixels_tab[0][1] = MC_put_x_16_vis;
       c->put_pixels_tab[0][2] = MC_put_y_16_vis;
@@ -3996,15 +3539,9 @@ void ff_dsputil_init_vis(DSPContext* c, AVCodecContext *avctx)
       c->put_no_rnd_pixels_tab[1][2] = MC_put_no_round_y_8_vis;
       c->put_no_rnd_pixels_tab[1][3] = MC_put_no_round_xy_8_vis;
 
-      c->avg_no_rnd_pixels_tab[0][0] = MC_avg_no_round_o_16_vis;
-      c->avg_no_rnd_pixels_tab[0][1] = MC_avg_no_round_x_16_vis;
-      c->avg_no_rnd_pixels_tab[0][2] = MC_avg_no_round_y_16_vis;
-      c->avg_no_rnd_pixels_tab[0][3] = MC_avg_no_round_xy_16_vis;
-
-      c->avg_no_rnd_pixels_tab[1][0] = MC_avg_no_round_o_8_vis;
-      c->avg_no_rnd_pixels_tab[1][1] = MC_avg_no_round_x_8_vis;
-      c->avg_no_rnd_pixels_tab[1][2] = MC_avg_no_round_y_8_vis;
-      c->avg_no_rnd_pixels_tab[1][3] = MC_avg_no_round_xy_8_vis;
-      }
+      c->avg_no_rnd_pixels_tab[0] = MC_avg_no_round_o_16_vis;
+      c->avg_no_rnd_pixels_tab[1] = MC_avg_no_round_x_16_vis;
+      c->avg_no_rnd_pixels_tab[2] = MC_avg_no_round_y_16_vis;
+      c->avg_no_rnd_pixels_tab[3] = MC_avg_no_round_xy_16_vis;
   }
 }
diff --git a/mythtv/external/FFmpeg/libavcodec/sparc/dsputil_vis.h b/mythtv/external/FFmpeg/libavcodec/sparc/dsputil_vis.h
index e1cbcb49e3e..d7e2e63ab98 100644
--- a/mythtv/external/FFmpeg/libavcodec/sparc/dsputil_vis.h
+++ b/mythtv/external/FFmpeg/libavcodec/sparc/dsputil_vis.h
@@ -20,10 +20,9 @@
 #define AVCODEC_SPARC_DSPUTIL_VIS_H
 
 #include 
-#include "libavcodec/dsputil.h"
 
-void ff_simple_idct_put_vis(uint8_t *dest, int line_size, DCTELEM *data);
-void ff_simple_idct_add_vis(uint8_t *dest, int line_size, DCTELEM *data);
-void ff_simple_idct_vis(DCTELEM *data);
+void ff_simple_idct_put_vis(uint8_t *dest, int line_size, int16_t *data);
+void ff_simple_idct_add_vis(uint8_t *dest, int line_size, int16_t *data);
+void ff_simple_idct_vis(int16_t *data);
 
 #endif /* AVCODEC_SPARC_DSPUTIL_VIS_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/sparc/simple_idct_vis.c b/mythtv/external/FFmpeg/libavcodec/sparc/simple_idct_vis.c
index 45ca0105881..c9923e09251 100644
--- a/mythtv/external/FFmpeg/libavcodec/sparc/simple_idct_vis.c
+++ b/mythtv/external/FFmpeg/libavcodec/sparc/simple_idct_vis.c
@@ -24,7 +24,6 @@
 
 #include 
 
-#include "libavcodec/dsputil.h"
 #include "dsputil_vis.h"
 #include "libavutil/mem.h"
 
@@ -388,7 +387,7 @@ static const DECLARE_ALIGNED(8, uint16_t, expand)[4] = {
         "st %%f14, [%12+" dest "] \n\t"\
 
 
-void ff_simple_idct_vis(DCTELEM *data) {
+void ff_simple_idct_vis(int16_t *data) {
     int out1, out2, out3, out4;
     DECLARE_ALIGNED(8, int16_t, temp)[8*8];
 
@@ -428,7 +427,7 @@ void ff_simple_idct_vis(DCTELEM *data) {
     );
 }
 
-void ff_simple_idct_put_vis(uint8_t *dest, int line_size, DCTELEM *data) {
+void ff_simple_idct_put_vis(uint8_t *dest, int line_size, int16_t *data) {
     int out1, out2, out3, out4, out5;
     int r1, r2, r3, r4, r5, r6, r7;
 
@@ -478,7 +477,7 @@ void ff_simple_idct_put_vis(uint8_t *dest, int line_size, DCTELEM *data) {
     );
 }
 
-void ff_simple_idct_add_vis(uint8_t *dest, int line_size, DCTELEM *data) {
+void ff_simple_idct_add_vis(uint8_t *dest, int line_size, int16_t *data) {
     int out1, out2, out3, out4, out5, out6;
     int r1, r2, r3, r4, r5, r6, r7;
 
diff --git a/mythtv/external/FFmpeg/libavcodec/svq1.c b/mythtv/external/FFmpeg/libavcodec/svq1.c
index 0c19a6d53ba..c219f2221a9 100644
--- a/mythtv/external/FFmpeg/libavcodec/svq1.c
+++ b/mythtv/external/FFmpeg/libavcodec/svq1.c
@@ -37,7 +37,7 @@
 #include "svq1_vlc.h"
 
 /* standard video sizes */
-const struct svq1_frame_size ff_svq1_frame_size_table[7] = {
+const uint16_t ff_svq1_frame_size_table[7][2] = {
     { 160, 120 }, { 128,  96 }, { 176, 144 }, { 352, 288 },
     { 704, 576 }, { 240, 180 }, { 320, 240 }
 };
diff --git a/mythtv/external/FFmpeg/libavcodec/svq1.h b/mythtv/external/FFmpeg/libavcodec/svq1.h
index 9b132e23207..8380f2256b0 100644
--- a/mythtv/external/FFmpeg/libavcodec/svq1.h
+++ b/mythtv/external/FFmpeg/libavcodec/svq1.h
@@ -42,11 +42,6 @@
 #define SVQ1_BLOCK_INTER_4V     2
 #define SVQ1_BLOCK_INTRA        3
 
-struct svq1_frame_size {
-    uint16_t width;
-    uint16_t height;
-};
-
 uint16_t ff_svq1_packet_checksum(const uint8_t *data,
                                  const int length, int value);
 
@@ -59,6 +54,6 @@ extern const uint8_t ff_svq1_inter_multistage_vlc[6][8][2];
 extern const uint16_t ff_svq1_intra_mean_vlc[256][2];
 extern const uint16_t ff_svq1_inter_mean_vlc[512][2];
 
-extern const struct svq1_frame_size ff_svq1_frame_size_table[7];
+extern const uint16_t ff_svq1_frame_size_table[7][2];
 
 #endif /* AVCODEC_SVQ1_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/svq1dec.c b/mythtv/external/FFmpeg/libavcodec/svq1dec.c
index 187522c3bfa..5b9a620591a 100644
--- a/mythtv/external/FFmpeg/libavcodec/svq1dec.c
+++ b/mythtv/external/FFmpeg/libavcodec/svq1dec.c
@@ -575,8 +575,8 @@ static int svq1_decode_frame_header(AVCodecContext *avctx, AVFrame *frame)
                 return AVERROR_INVALIDDATA;
         } else {
             /* get width, height from table */
-            width  = ff_svq1_frame_size_table[frame_size_code].width;
-            height = ff_svq1_frame_size_table[frame_size_code].height;
+            width  = ff_svq1_frame_size_table[frame_size_code][0];
+            height = ff_svq1_frame_size_table[frame_size_code][1];
         }
     }
 
@@ -692,7 +692,7 @@ static int svq1_decode_frame(AVCodecContext *avctx, void *data,
         } else {
             /* delta frame */
             uint8_t *previous = s->prev->data[i];
-            if (!previous) {
+            if (!previous || s->prev->width != s->cur->width || s->prev->height != s->cur->height) {
                 av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
                 result = AVERROR_INVALIDDATA;
                 goto err;
diff --git a/mythtv/external/FFmpeg/libavcodec/svq1enc.c b/mythtv/external/FFmpeg/libavcodec/svq1enc.c
index 1b32bbc533b..d12dfcdb01f 100644
--- a/mythtv/external/FFmpeg/libavcodec/svq1enc.c
+++ b/mythtv/external/FFmpeg/libavcodec/svq1enc.c
@@ -27,7 +27,6 @@
  */
 
 #include "avcodec.h"
-#include "dsputil.h"
 #include "mpegvideo.h"
 #include "h263.h"
 #include "internal.h"
diff --git a/mythtv/external/FFmpeg/libavcodec/svq3.c b/mythtv/external/FFmpeg/libavcodec/svq3.c
index c12c75f51b8..0481c807aba 100644
--- a/mythtv/external/FFmpeg/libavcodec/svq3.c
+++ b/mythtv/external/FFmpeg/libavcodec/svq3.c
@@ -40,7 +40,6 @@
  *  http://samples.mplayerhq.hu/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov
  */
 #include "internal.h"
-#include "dsputil.h"
 #include "avcodec.h"
 #include "mpegvideo.h"
 #include "h264.h"
@@ -57,6 +56,7 @@
 #endif
 
 #include "svq1.h"
+#include "svq3.h"
 
 /**
  * @file
@@ -65,6 +65,9 @@
 
 typedef struct {
     H264Context h;
+    Picture *cur_pic;
+    Picture *next_pic;
+    Picture *last_pic;
     int halfpel_flag;
     int thirdpel_flag;
     int unknown_flag;
@@ -72,6 +75,11 @@ typedef struct {
     uint32_t watermark_key;
     uint8_t *buf;
     int buf_size;
+    int adaptive_quant;
+    int next_p_frame_damaged;
+    int h_edge_pos;
+    int v_edge_pos;
+    int last_frame_output;
 } SVQ3Context;
 
 #define FULLPEL_MODE  1
@@ -139,7 +147,7 @@ static const uint32_t svq3_dequant_coeff[32] = {
     61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533
 };
 
-void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qp)
+void ff_svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)
 {
     const int qmul = svq3_dequant_coeff[qp];
 #define stride 16
@@ -174,7 +182,7 @@ void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qp)
 }
 #undef stride
 
-void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block,
+void ff_svq3_add_idct_c(uint8_t *dst, int16_t *block,
                         int stride, int qp, int dc)
 {
     const int qmul = svq3_dequant_coeff[qp];
@@ -210,9 +218,11 @@ void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block,
         dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((z1 - z2) * qmul + rr >> 20));
         dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((z0 - z3) * qmul + rr >> 20));
     }
+
+    memset(block, 0, 16 * sizeof(int16_t));
 }
 
-static inline int svq3_decode_block(GetBitContext *gb, DCTELEM *block,
+static inline int svq3_decode_block(GetBitContext *gb, int16_t *block,
                                     int index, const int type)
 {
     static const uint8_t *const scan_patterns[4] =
@@ -270,12 +280,13 @@ static inline int svq3_decode_block(GetBitContext *gb, DCTELEM *block,
     return 0;
 }
 
-static inline void svq3_mc_dir_part(MpegEncContext *s,
+static inline void svq3_mc_dir_part(SVQ3Context *s,
                                     int x, int y, int width, int height,
                                     int mx, int my, int dxy,
                                     int thirdpel, int dir, int avg)
 {
-    const Picture *pic = (dir == 0) ? &s->last_picture : &s->next_picture;
+    H264Context *h     = &s->h;
+    const Picture *pic = (dir == 0) ? s->last_pic : s->next_pic;
     uint8_t *src, *dest;
     int i, emu = 0;
     int blocksize = 2 - (width >> 3); // 16->0, 8->1, 4->2
@@ -285,33 +296,31 @@ static inline void svq3_mc_dir_part(MpegEncContext *s,
 
     if (mx < 0 || mx >= s->h_edge_pos - width  - 1 ||
         my < 0 || my >= s->v_edge_pos - height - 1) {
-        if ((s->flags & CODEC_FLAG_EMU_EDGE))
-            emu = 1;
-
+        emu = 1;
         mx = av_clip(mx, -16, s->h_edge_pos - width  + 15);
         my = av_clip(my, -16, s->v_edge_pos - height + 15);
     }
 
     /* form component predictions */
-    dest = s->current_picture.f.data[0] + x + y * s->linesize;
-    src  = pic->f.data[0] + mx + my * s->linesize;
+    dest = h->cur_pic.f.data[0] + x + y * h->linesize;
+    src  = pic->f.data[0] + mx + my * h->linesize;
 
     if (emu) {
-        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize,
+        h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src, h->linesize,
                                  width + 1, height + 1,
                                  mx, my, s->h_edge_pos, s->v_edge_pos);
-        src = s->edge_emu_buffer;
+        src = h->edge_emu_buffer;
     }
     if (thirdpel)
-        (avg ? s->dsp.avg_tpel_pixels_tab
-             : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->linesize,
+        (avg ? h->dsp.avg_tpel_pixels_tab
+             : h->dsp.put_tpel_pixels_tab)[dxy](dest, src, h->linesize,
                                                 width, height);
     else
-        (avg ? s->dsp.avg_pixels_tab
-             : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->linesize,
+        (avg ? h->dsp.avg_pixels_tab
+             : h->dsp.put_pixels_tab)[blocksize][dxy](dest, src, h->linesize,
                                                       height);
 
-    if (!(s->flags & CODEC_FLAG_GRAY)) {
+    if (!(h->flags & CODEC_FLAG_GRAY)) {
         mx     = mx + (mx < (int) x) >> 1;
         my     = my + (my < (int) y) >> 1;
         width  = width  >> 1;
@@ -319,35 +328,35 @@ static inline void svq3_mc_dir_part(MpegEncContext *s,
         blocksize++;
 
         for (i = 1; i < 3; i++) {
-            dest = s->current_picture.f.data[i] + (x >> 1) + (y >> 1) * s->uvlinesize;
-            src  = pic->f.data[i] + mx + my * s->uvlinesize;
+            dest = h->cur_pic.f.data[i] + (x >> 1) + (y >> 1) * h->uvlinesize;
+            src  = pic->f.data[i] + mx + my * h->uvlinesize;
 
             if (emu) {
-                s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src, s->uvlinesize,
+                h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src, h->uvlinesize,
                                          width + 1, height + 1,
                                          mx, my, (s->h_edge_pos >> 1),
                                          s->v_edge_pos >> 1);
-                src = s->edge_emu_buffer;
+                src = h->edge_emu_buffer;
             }
             if (thirdpel)
-                (avg ? s->dsp.avg_tpel_pixels_tab
-                     : s->dsp.put_tpel_pixels_tab)[dxy](dest, src,
-                                                        s->uvlinesize,
+                (avg ? h->dsp.avg_tpel_pixels_tab
+                     : h->dsp.put_tpel_pixels_tab)[dxy](dest, src,
+                                                        h->uvlinesize,
                                                         width, height);
             else
-                (avg ? s->dsp.avg_pixels_tab
-                     : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src,
-                                                              s->uvlinesize,
+                (avg ? h->dsp.avg_pixels_tab
+                     : h->dsp.put_pixels_tab)[blocksize][dxy](dest, src,
+                                                              h->uvlinesize,
                                                               height);
         }
     }
 }
 
-static inline int svq3_mc_dir(H264Context *h, int size, int mode,
+static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,
                               int dir, int avg)
 {
     int i, j, k, mx, my, dx, dy, x, y;
-    MpegEncContext *const s = (MpegEncContext *)h;
+    H264Context *h          = &s->h;
     const int part_width    = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
     const int part_height   = 16 >> ((unsigned)(size + 1) / 3);
     const int extra_width   = (mode == PREDICT_MODE) ? -16 * 6 : 0;
@@ -356,19 +365,19 @@ static inline int svq3_mc_dir(H264Context *h, int size, int mode,
 
     for (i = 0; i < 16; i += part_height)
         for (j = 0; j < 16; j += part_width) {
-            const int b_xy = (4 * s->mb_x + (j >> 2)) +
-                             (4 * s->mb_y + (i >> 2)) * h->b_stride;
+            const int b_xy = (4 * h->mb_x + (j >> 2)) +
+                             (4 * h->mb_y + (i >> 2)) * h->b_stride;
             int dxy;
-            x = 16 * s->mb_x + j;
-            y = 16 * s->mb_y + i;
+            x = 16 * h->mb_x + j;
+            y = 16 * h->mb_y + i;
             k = (j >> 2 & 1) + (i >> 1 & 2) +
                 (j >> 1 & 4) + (i      & 8);
 
             if (mode != PREDICT_MODE) {
                 pred_motion(h, k, part_width >> 2, dir, 1, &mx, &my);
             } else {
-                mx = s->next_picture.f.motion_val[0][b_xy][0] << 1;
-                my = s->next_picture.f.motion_val[0][b_xy][1] << 1;
+                mx = s->next_pic->f.motion_val[0][b_xy][0] << 1;
+                my = s->next_pic->f.motion_val[0][b_xy][1] << 1;
 
                 if (dir == 0) {
                     mx = mx * h->frame_num_offset /
@@ -391,11 +400,11 @@ static inline int svq3_mc_dir(H264Context *h, int size, int mode,
             if (mode == PREDICT_MODE) {
                 dx = dy = 0;
             } else {
-                dy = svq3_get_se_golomb(&s->gb);
-                dx = svq3_get_se_golomb(&s->gb);
+                dy = svq3_get_se_golomb(&h->gb);
+                dx = svq3_get_se_golomb(&h->gb);
 
                 if (dx == INVALID_VLC || dy == INVALID_VLC) {
-                    av_log(h->s.avctx, AV_LOG_ERROR, "invalid MV vlc\n");
+                    av_log(h->avctx, AV_LOG_ERROR, "invalid MV vlc\n");
                     return -1;
                 }
             }
@@ -449,7 +458,7 @@ static inline int svq3_mc_dir(H264Context *h, int size, int mode,
             }
 
             /* write back motion vectors */
-            fill_rectangle(s->current_picture.f.motion_val[dir][b_xy],
+            fill_rectangle(h->cur_pic.f.motion_val[dir][b_xy],
                            part_width >> 2, part_height >> 2, h->b_stride,
                            pack16to32(mx, my), 4);
         }
@@ -457,46 +466,45 @@ static inline int svq3_mc_dir(H264Context *h, int size, int mode,
     return 0;
 }
 
-static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
+static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
 {
-    H264Context *h = &svq3->h;
+    H264Context *h = &s->h;
     int i, j, k, m, dir, mode;
     int cbp = 0;
     uint32_t vlc;
     int8_t *top, *left;
-    MpegEncContext *const s = (MpegEncContext *)h;
     const int mb_xy         = h->mb_xy;
-    const int b_xy          = 4 * s->mb_x + 4 * s->mb_y * h->b_stride;
+    const int b_xy          = 4 * h->mb_x + 4 * h->mb_y * h->b_stride;
 
-    h->top_samples_available      = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
-    h->left_samples_available     = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
+    h->top_samples_available      = (h->mb_y == 0) ? 0x33FF : 0xFFFF;
+    h->left_samples_available     = (h->mb_x == 0) ? 0x5F5F : 0xFFFF;
     h->topright_samples_available = 0xFFFF;
 
     if (mb_type == 0) {           /* SKIP */
-        if (s->pict_type == AV_PICTURE_TYPE_P ||
-            s->next_picture.f.mb_type[mb_xy] == -1) {
-            svq3_mc_dir_part(s, 16 * s->mb_x, 16 * s->mb_y, 16, 16,
+        if (h->pict_type == AV_PICTURE_TYPE_P ||
+            s->next_pic->f.mb_type[mb_xy] == -1) {
+            svq3_mc_dir_part(s, 16 * h->mb_x, 16 * h->mb_y, 16, 16,
                              0, 0, 0, 0, 0, 0);
 
-            if (s->pict_type == AV_PICTURE_TYPE_B)
-                svq3_mc_dir_part(s, 16 * s->mb_x, 16 * s->mb_y, 16, 16,
+            if (h->pict_type == AV_PICTURE_TYPE_B)
+                svq3_mc_dir_part(s, 16 * h->mb_x, 16 * h->mb_y, 16, 16,
                                  0, 0, 0, 0, 1, 1);
 
             mb_type = MB_TYPE_SKIP;
         } else {
-            mb_type = FFMIN(s->next_picture.f.mb_type[mb_xy], 6);
-            if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 0, 0) < 0)
+            mb_type = FFMIN(s->next_pic->f.mb_type[mb_xy], 6);
+            if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 0, 0) < 0)
                 return -1;
-            if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 1, 1) < 0)
+            if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 1, 1) < 0)
                 return -1;
 
             mb_type = MB_TYPE_16x16;
         }
     } else if (mb_type < 8) {     /* INTER */
-        if (svq3->thirdpel_flag && svq3->halfpel_flag == !get_bits1(&s->gb))
+        if (s->thirdpel_flag && s->halfpel_flag == !get_bits1(&h->gb))
             mode = THIRDPEL_MODE;
-        else if (svq3->halfpel_flag &&
-                 svq3->thirdpel_flag == !get_bits1(&s->gb))
+        else if (s->halfpel_flag &&
+                 s->thirdpel_flag == !get_bits1(&h->gb))
             mode = HALFPEL_MODE;
         else
             mode = FULLPEL_MODE;
@@ -511,63 +519,63 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
          */
 
         for (m = 0; m < 2; m++) {
-            if (s->mb_x > 0 && h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1] + 6] != -1) {
+            if (h->mb_x > 0 && h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1] + 6] != -1) {
                 for (i = 0; i < 4; i++)
                     AV_COPY32(h->mv_cache[m][scan8[0] - 1 + i * 8],
-                              s->current_picture.f.motion_val[m][b_xy - 1 + i * h->b_stride]);
+                              h->cur_pic.f.motion_val[m][b_xy - 1 + i * h->b_stride]);
             } else {
                 for (i = 0; i < 4; i++)
                     AV_ZERO32(h->mv_cache[m][scan8[0] - 1 + i * 8]);
             }
-            if (s->mb_y > 0) {
+            if (h->mb_y > 0) {
                 memcpy(h->mv_cache[m][scan8[0] - 1 * 8],
-                       s->current_picture.f.motion_val[m][b_xy - h->b_stride],
+                       h->cur_pic.f.motion_val[m][b_xy - h->b_stride],
                        4 * 2 * sizeof(int16_t));
                 memset(&h->ref_cache[m][scan8[0] - 1 * 8],
-                       (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4);
+                       (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4);
 
-                if (s->mb_x < s->mb_width - 1) {
+                if (h->mb_x < h->mb_width - 1) {
                     AV_COPY32(h->mv_cache[m][scan8[0] + 4 - 1 * 8],
-                              s->current_picture.f.motion_val[m][b_xy - h->b_stride + 4]);
+                              h->cur_pic.f.motion_val[m][b_xy - h->b_stride + 4]);
                     h->ref_cache[m][scan8[0] + 4 - 1 * 8] =
-                        (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride + 1] + 6] == -1 ||
-                         h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1;
+                        (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride + 1] + 6] == -1 ||
+                         h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1;
                 } else
                     h->ref_cache[m][scan8[0] + 4 - 1 * 8] = PART_NOT_AVAILABLE;
-                if (s->mb_x > 0) {
+                if (h->mb_x > 0) {
                     AV_COPY32(h->mv_cache[m][scan8[0] - 1 - 1 * 8],
-                              s->current_picture.f.motion_val[m][b_xy - h->b_stride - 1]);
+                              h->cur_pic.f.motion_val[m][b_xy - h->b_stride - 1]);
                     h->ref_cache[m][scan8[0] - 1 - 1 * 8] =
-                        (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] == -1) ? PART_NOT_AVAILABLE : 1;
+                        (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride - 1] + 3] == -1) ? PART_NOT_AVAILABLE : 1;
                 } else
                     h->ref_cache[m][scan8[0] - 1 - 1 * 8] = PART_NOT_AVAILABLE;
             } else
                 memset(&h->ref_cache[m][scan8[0] - 1 * 8 - 1],
                        PART_NOT_AVAILABLE, 8);
 
-            if (s->pict_type != AV_PICTURE_TYPE_B)
+            if (h->pict_type != AV_PICTURE_TYPE_B)
                 break;
         }
 
         /* decode motion vector(s) and form prediction(s) */
-        if (s->pict_type == AV_PICTURE_TYPE_P) {
-            if (svq3_mc_dir(h, mb_type - 1, mode, 0, 0) < 0)
+        if (h->pict_type == AV_PICTURE_TYPE_P) {
+            if (svq3_mc_dir(s, mb_type - 1, mode, 0, 0) < 0)
                 return -1;
         } else {        /* AV_PICTURE_TYPE_B */
             if (mb_type != 2) {
-                if (svq3_mc_dir(h, 0, mode, 0, 0) < 0)
+                if (svq3_mc_dir(s, 0, mode, 0, 0) < 0)
                     return -1;
             } else {
                 for (i = 0; i < 4; i++)
-                    memset(s->current_picture.f.motion_val[0][b_xy + i * h->b_stride],
+                    memset(h->cur_pic.f.motion_val[0][b_xy + i * h->b_stride],
                            0, 4 * 2 * sizeof(int16_t));
             }
             if (mb_type != 1) {
-                if (svq3_mc_dir(h, 0, mode, 1, mb_type == 3) < 0)
+                if (svq3_mc_dir(s, 0, mode, 1, mb_type == 3) < 0)
                     return -1;
             } else {
                 for (i = 0; i < 4; i++)
-                    memset(s->current_picture.f.motion_val[1][b_xy + i * h->b_stride],
+                    memset(h->cur_pic.f.motion_val[1][b_xy + i * h->b_stride],
                            0, 4 * 2 * sizeof(int16_t));
             }
         }
@@ -577,17 +585,17 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
         memset(h->intra4x4_pred_mode_cache, -1, 8 * 5 * sizeof(int8_t));
 
         if (mb_type == 8) {
-            if (s->mb_x > 0) {
+            if (h->mb_x > 0) {
                 for (i = 0; i < 4; i++)
                     h->intra4x4_pred_mode_cache[scan8[0] - 1 + i * 8] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1] + 6 - i];
                 if (h->intra4x4_pred_mode_cache[scan8[0] - 1] == -1)
                     h->left_samples_available = 0x5F5F;
             }
-            if (s->mb_y > 0) {
-                h->intra4x4_pred_mode_cache[4 + 8 * 0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride] + 0];
-                h->intra4x4_pred_mode_cache[5 + 8 * 0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride] + 1];
-                h->intra4x4_pred_mode_cache[6 + 8 * 0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride] + 2];
-                h->intra4x4_pred_mode_cache[7 + 8 * 0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride] + 3];
+            if (h->mb_y > 0) {
+                h->intra4x4_pred_mode_cache[4 + 8 * 0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride] + 0];
+                h->intra4x4_pred_mode_cache[5 + 8 * 0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride] + 1];
+                h->intra4x4_pred_mode_cache[6 + 8 * 0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride] + 2];
+                h->intra4x4_pred_mode_cache[7 + 8 * 0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride] + 3];
 
                 if (h->intra4x4_pred_mode_cache[4 + 8 * 0] == -1)
                     h->top_samples_available = 0x33FF;
@@ -595,10 +603,10 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
 
             /* decode prediction codes for luma blocks */
             for (i = 0; i < 16; i += 2) {
-                vlc = svq3_get_ue_golomb(&s->gb);
+                vlc = svq3_get_ue_golomb(&h->gb);
 
                 if (vlc >= 25U) {
-                    av_log(h->s.avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc);
+                    av_log(h->avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc);
                     return -1;
                 }
 
@@ -609,7 +617,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
                 left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
 
                 if (left[1] == -1 || left[2] == -1) {
-                    av_log(h->s.avctx, AV_LOG_ERROR, "weird prediction\n");
+                    av_log(h->avctx, AV_LOG_ERROR, "weird prediction\n");
                     return -1;
                 }
             }
@@ -623,8 +631,8 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
         if (mb_type == 8) {
             ff_h264_check_intra4x4_pred_mode(h);
 
-            h->top_samples_available  = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
-            h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
+            h->top_samples_available  = (h->mb_y == 0) ? 0x33FF : 0xFFFF;
+            h->left_samples_available = (h->mb_x == 0) ? 0x5F5F : 0xFFFF;
         } else {
             for (i = 0; i < 4; i++)
                 memset(&h->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_128_PRED, 4);
@@ -639,7 +647,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
         dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
 
         if ((h->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h, dir, 0)) == -1) {
-            av_log(h->s.avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n");
+            av_log(h->avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n");
             return -1;
         }
 
@@ -647,29 +655,27 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
         mb_type = MB_TYPE_INTRA16x16;
     }
 
-    if (!IS_INTER(mb_type) && s->pict_type != AV_PICTURE_TYPE_I) {
+    if (!IS_INTER(mb_type) && h->pict_type != AV_PICTURE_TYPE_I) {
         for (i = 0; i < 4; i++)
-            memset(s->current_picture.f.motion_val[0][b_xy + i * h->b_stride],
+            memset(h->cur_pic.f.motion_val[0][b_xy + i * h->b_stride],
                    0, 4 * 2 * sizeof(int16_t));
-        if (s->pict_type == AV_PICTURE_TYPE_B) {
+        if (h->pict_type == AV_PICTURE_TYPE_B) {
             for (i = 0; i < 4; i++)
-                memset(s->current_picture.f.motion_val[1][b_xy + i * h->b_stride],
+                memset(h->cur_pic.f.motion_val[1][b_xy + i * h->b_stride],
                        0, 4 * 2 * sizeof(int16_t));
         }
     }
     if (!IS_INTRA4x4(mb_type)) {
         memset(h->intra4x4_pred_mode + h->mb2br_xy[mb_xy], DC_PRED, 8);
     }
-    if (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B) {
+    if (!IS_SKIP(mb_type) || h->pict_type == AV_PICTURE_TYPE_B) {
         memset(h->non_zero_count_cache + 8, 0, 14 * 8 * sizeof(uint8_t));
-        s->dsp.clear_blocks(h->mb +   0);
-        s->dsp.clear_blocks(h->mb + 384);
     }
 
     if (!IS_INTRA16x16(mb_type) &&
-        (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) {
-        if ((vlc = svq3_get_ue_golomb(&s->gb)) >= 48U){
-            av_log(h->s.avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc);
+        (!IS_SKIP(mb_type) || h->pict_type == AV_PICTURE_TYPE_B)) {
+        if ((vlc = svq3_get_ue_golomb(&h->gb)) >= 48U){
+            av_log(h->avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc);
             return -1;
         }
 
@@ -677,19 +683,19 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
                                 : golomb_to_inter_cbp[vlc];
     }
     if (IS_INTRA16x16(mb_type) ||
-        (s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
-        s->qscale += svq3_get_se_golomb(&s->gb);
+        (h->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
+        h->qscale += svq3_get_se_golomb(&h->gb);
 
-        if (s->qscale > 31u) {
-            av_log(h->s.avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
+        if (h->qscale > 31u) {
+            av_log(h->avctx, AV_LOG_ERROR, "qscale:%d\n", h->qscale);
             return -1;
         }
     }
     if (IS_INTRA16x16(mb_type)) {
         AV_ZERO128(h->mb_luma_dc[0] + 0);
         AV_ZERO128(h->mb_luma_dc[0] + 8);
-        if (svq3_decode_block(&s->gb, h->mb_luma_dc[0], 0, 1)) {
-            av_log(h->s.avctx, AV_LOG_ERROR,
+        if (svq3_decode_block(&h->gb, h->mb_luma_dc[0], 0, 1)) {
+            av_log(h->avctx, AV_LOG_ERROR,
                    "error while decoding intra luma dc\n");
             return -1;
         }
@@ -697,7 +703,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
 
     if (cbp) {
         const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
-        const int type  = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
+        const int type  = ((h->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
 
         for (i = 0; i < 4; i++)
             if ((cbp & (1 << i))) {
@@ -707,8 +713,8 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
                               : (4 * i + j);
                     h->non_zero_count_cache[scan8[k]] = 1;
 
-                    if (svq3_decode_block(&s->gb, &h->mb[16 * k], index, type)) {
-                        av_log(h->s.avctx, AV_LOG_ERROR,
+                    if (svq3_decode_block(&h->gb, &h->mb[16 * k], index, type)) {
+                        av_log(h->avctx, AV_LOG_ERROR,
                                "error while decoding block\n");
                         return -1;
                     }
@@ -717,8 +723,8 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
 
         if ((cbp & 0x30)) {
             for (i = 1; i < 3; ++i)
-                if (svq3_decode_block(&s->gb, &h->mb[16 * 16 * i], 0, 3)) {
-                    av_log(h->s.avctx, AV_LOG_ERROR,
+                if (svq3_decode_block(&h->gb, &h->mb[16 * 16 * i], 0, 3)) {
+                    av_log(h->avctx, AV_LOG_ERROR,
                            "error while decoding chroma dc block\n");
                     return -1;
                 }
@@ -729,8 +735,8 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
                         k                                 = 16 * i + j;
                         h->non_zero_count_cache[scan8[k]] = 1;
 
-                        if (svq3_decode_block(&s->gb, &h->mb[16 * k], 1, 1)) {
-                            av_log(h->s.avctx, AV_LOG_ERROR,
+                        if (svq3_decode_block(&h->gb, &h->mb[16 * k], 1, 1)) {
+                            av_log(h->avctx, AV_LOG_ERROR,
                                    "error while decoding chroma ac block\n");
                             return -1;
                         }
@@ -741,7 +747,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
     }
 
     h->cbp                              = cbp;
-    s->current_picture.f.mb_type[mb_xy] = mb_type;
+    h->cur_pic.f.mb_type[mb_xy] = mb_type;
 
     if (IS_INTRA(mb_type))
         h->chroma_pred_mode = ff_h264_check_intra_pred_mode(h, DC_PRED8x8, 1);
@@ -751,14 +757,13 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
 
 static int svq3_decode_slice_header(AVCodecContext *avctx)
 {
-    SVQ3Context *svq3 = avctx->priv_data;
-    H264Context *h    = &svq3->h;
-    MpegEncContext *s = &h->s;
+    SVQ3Context *s = avctx->priv_data;
+    H264Context *h    = &s->h;
     const int mb_xy   = h->mb_xy;
     int i, header;
     unsigned slice_id;
 
-    header = get_bits(&s->gb, 8);
+    header = get_bits(&h->gb, 8);
 
     if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
         /* TODO: what? */
@@ -767,75 +772,75 @@ static int svq3_decode_slice_header(AVCodecContext *avctx)
     } else {
         int length = header >> 5 & 3;
 
-        svq3->next_slice_index = get_bits_count(&s->gb) +
-                                 8 * show_bits(&s->gb, 8 * length) +
-                                 8 * length;
+        s->next_slice_index = get_bits_count(&h->gb) +
+                              8 * show_bits(&h->gb, 8 * length) +
+                              8 * length;
 
-        if (svq3->next_slice_index > s->gb.size_in_bits) {
+        if (s->next_slice_index > h->gb.size_in_bits) {
             av_log(avctx, AV_LOG_ERROR, "slice after bitstream end\n");
             return -1;
         }
 
-        s->gb.size_in_bits = svq3->next_slice_index - 8 * (length - 1);
-        skip_bits(&s->gb, 8);
+        h->gb.size_in_bits = s->next_slice_index - 8 * (length - 1);
+        skip_bits(&h->gb, 8);
 
-        if (svq3->watermark_key) {
-            uint32_t header = AV_RL32(&s->gb.buffer[(get_bits_count(&s->gb) >> 3) + 1]);
-            AV_WL32(&s->gb.buffer[(get_bits_count(&s->gb) >> 3) + 1],
-                    header ^ svq3->watermark_key);
+        if (s->watermark_key) {
+            uint32_t header = AV_RL32(&h->gb.buffer[(get_bits_count(&h->gb) >> 3) + 1]);
+            AV_WL32(&h->gb.buffer[(get_bits_count(&h->gb) >> 3) + 1],
+                    header ^ s->watermark_key);
         }
         if (length > 0) {
-            memcpy((uint8_t *) &s->gb.buffer[get_bits_count(&s->gb) >> 3],
-                   &s->gb.buffer[s->gb.size_in_bits >> 3], length - 1);
+            memcpy((uint8_t *) &h->gb.buffer[get_bits_count(&h->gb) >> 3],
+                   &h->gb.buffer[h->gb.size_in_bits >> 3], length - 1);
         }
-        skip_bits_long(&s->gb, 0);
+        skip_bits_long(&h->gb, 0);
     }
 
-    if ((slice_id = svq3_get_ue_golomb(&s->gb)) >= 3) {
-        av_log(h->s.avctx, AV_LOG_ERROR, "illegal slice type %d \n", slice_id);
+    if ((slice_id = svq3_get_ue_golomb(&h->gb)) >= 3) {
+        av_log(h->avctx, AV_LOG_ERROR, "illegal slice type %d \n", slice_id);
         return -1;
     }
 
     h->slice_type = golomb_to_pict_type[slice_id];
 
     if ((header & 0x9F) == 2) {
-        i              = (s->mb_num < 64) ? 6 : (1 + av_log2(s->mb_num - 1));
-        s->mb_skip_run = get_bits(&s->gb, i) -
-                         (s->mb_y * s->mb_width + s->mb_x);
+        i              = (h->mb_num < 64) ? 6 : (1 + av_log2(h->mb_num - 1));
+        h->mb_skip_run = get_bits(&h->gb, i) -
+                         (h->mb_y * h->mb_width + h->mb_x);
     } else {
-        skip_bits1(&s->gb);
-        s->mb_skip_run = 0;
+        skip_bits1(&h->gb);
+        h->mb_skip_run = 0;
     }
 
-    h->slice_num      = get_bits(&s->gb, 8);
-    s->qscale         = get_bits(&s->gb, 5);
-    s->adaptive_quant = get_bits1(&s->gb);
+    h->slice_num      = get_bits(&h->gb, 8);
+    h->qscale         = get_bits(&h->gb, 5);
+    s->adaptive_quant = get_bits1(&h->gb);
 
     /* unknown fields */
-    skip_bits1(&s->gb);
+    skip_bits1(&h->gb);
 
-    if (svq3->unknown_flag)
-        skip_bits1(&s->gb);
+    if (s->unknown_flag)
+        skip_bits1(&h->gb);
 
-    skip_bits1(&s->gb);
-    skip_bits(&s->gb, 2);
+    skip_bits1(&h->gb);
+    skip_bits(&h->gb, 2);
 
-    while (get_bits1(&s->gb))
-        skip_bits(&s->gb, 8);
+    while (get_bits1(&h->gb))
+        skip_bits(&h->gb, 8);
 
     /* reset intra predictors and invalidate motion vector references */
-    if (s->mb_x > 0) {
+    if (h->mb_x > 0) {
         memset(h->intra4x4_pred_mode + h->mb2br_xy[mb_xy - 1] + 3,
                -1, 4 * sizeof(int8_t));
-        memset(h->intra4x4_pred_mode + h->mb2br_xy[mb_xy - s->mb_x],
-               -1, 8 * sizeof(int8_t) * s->mb_x);
+        memset(h->intra4x4_pred_mode + h->mb2br_xy[mb_xy - h->mb_x],
+               -1, 8 * sizeof(int8_t) * h->mb_x);
     }
-    if (s->mb_y > 0) {
-        memset(h->intra4x4_pred_mode + h->mb2br_xy[mb_xy - s->mb_stride],
-               -1, 8 * sizeof(int8_t) * (s->mb_width - s->mb_x));
+    if (h->mb_y > 0) {
+        memset(h->intra4x4_pred_mode + h->mb2br_xy[mb_xy - h->mb_stride],
+               -1, 8 * sizeof(int8_t) * (h->mb_width - h->mb_x));
 
-        if (s->mb_x > 0)
-            h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] = -1;
+        if (h->mb_x > 0)
+            h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride - 1] + 3] = -1;
     }
 
     return 0;
@@ -843,250 +848,343 @@ static int svq3_decode_slice_header(AVCodecContext *avctx)
 
 static av_cold int svq3_decode_init(AVCodecContext *avctx)
 {
-    SVQ3Context *svq3 = avctx->priv_data;
-    H264Context *h    = &svq3->h;
-    MpegEncContext *s = &h->s;
+    SVQ3Context *s = avctx->priv_data;
+    H264Context *h = &s->h;
     int m;
     unsigned char *extradata;
     unsigned char *extradata_end;
     unsigned int size;
     int marker_found = 0;
 
+    s->cur_pic  = av_mallocz(sizeof(*s->cur_pic));
+    s->last_pic = av_mallocz(sizeof(*s->last_pic));
+    s->next_pic = av_mallocz(sizeof(*s->next_pic));
+    if (!s->next_pic || !s->last_pic || !s->cur_pic) {
+        av_freep(&s->cur_pic);
+        av_freep(&s->last_pic);
+        av_freep(&s->next_pic);
+        return AVERROR(ENOMEM);
+    }
+
     if (ff_h264_decode_init(avctx) < 0)
         return -1;
 
-    s->flags           = avctx->flags;
-    s->flags2          = avctx->flags2;
-    s->unrestricted_mv = 1;
+    h->flags           = avctx->flags;
     h->is_complex      = 1;
     h->sps.chroma_format_idc = 1;
+    h->picture_structure = PICT_FRAME;
     avctx->pix_fmt     = avctx->codec->pix_fmts[0];
 
-    if (!s->context_initialized) {
-        h->chroma_qp[0] = h->chroma_qp[1] = 4;
-
-        svq3->halfpel_flag  = 1;
-        svq3->thirdpel_flag = 1;
-        svq3->unknown_flag  = 0;
+    h->chroma_qp[0] = h->chroma_qp[1] = 4;
+    h->chroma_x_shift = h->chroma_y_shift = 1;
 
+    s->halfpel_flag  = 1;
+    s->thirdpel_flag = 1;
+    s->unknown_flag  = 0;
 
-        /* prowl for the "SEQH" marker in the extradata */
-        extradata     = (unsigned char *)avctx->extradata;
-        extradata_end = avctx->extradata + avctx->extradata_size;
-        if (extradata) {
-            for (m = 0; m + 8 < avctx->extradata_size; m++) {
-                if (!memcmp(extradata, "SEQH", 4)) {
-                    marker_found = 1;
-                    break;
-                }
-                extradata++;
+    /* prowl for the "SEQH" marker in the extradata */
+    extradata     = (unsigned char *)avctx->extradata;
+    extradata_end = avctx->extradata + avctx->extradata_size;
+    if (extradata) {
+        for (m = 0; m + 8 < avctx->extradata_size; m++) {
+            if (!memcmp(extradata, "SEQH", 4)) {
+                marker_found = 1;
+                break;
             }
+            extradata++;
         }
+    }
 
-        /* if a match was found, parse the extra data */
-        if (marker_found) {
-            GetBitContext gb;
-            int frame_size_code;
-
-            size = AV_RB32(&extradata[4]);
-            if (size > extradata_end - extradata - 8)
-                return AVERROR_INVALIDDATA;
-            init_get_bits(&gb, extradata + 8, size * 8);
-
-            /* 'frame size code' and optional 'width, height' */
-            frame_size_code = get_bits(&gb, 3);
-            switch (frame_size_code) {
-            case 0:
-                avctx->width  = 160;
-                avctx->height = 120;
-                break;
-            case 1:
-                avctx->width  = 128;
-                avctx->height =  96;
-                break;
-            case 2:
-                avctx->width  = 176;
-                avctx->height = 144;
-                break;
-            case 3:
-                avctx->width  = 352;
-                avctx->height = 288;
-                break;
-            case 4:
-                avctx->width  = 704;
-                avctx->height = 576;
-                break;
-            case 5:
-                avctx->width  = 240;
-                avctx->height = 180;
-                break;
-            case 6:
-                avctx->width  = 320;
-                avctx->height = 240;
-                break;
-            case 7:
-                avctx->width  = get_bits(&gb, 12);
-                avctx->height = get_bits(&gb, 12);
-                break;
-            }
+    /* if a match was found, parse the extra data */
+    if (marker_found) {
+        GetBitContext gb;
+        int frame_size_code;
+
+        size = AV_RB32(&extradata[4]);
+        if (size > extradata_end - extradata - 8)
+            return AVERROR_INVALIDDATA;
+        init_get_bits(&gb, extradata + 8, size * 8);
+
+        /* 'frame size code' and optional 'width, height' */
+        frame_size_code = get_bits(&gb, 3);
+        switch (frame_size_code) {
+        case 0:
+            avctx->width  = 160;
+            avctx->height = 120;
+            break;
+        case 1:
+            avctx->width  = 128;
+            avctx->height =  96;
+            break;
+        case 2:
+            avctx->width  = 176;
+            avctx->height = 144;
+            break;
+        case 3:
+            avctx->width  = 352;
+            avctx->height = 288;
+            break;
+        case 4:
+            avctx->width  = 704;
+            avctx->height = 576;
+            break;
+        case 5:
+            avctx->width  = 240;
+            avctx->height = 180;
+            break;
+        case 6:
+            avctx->width  = 320;
+            avctx->height = 240;
+            break;
+        case 7:
+            avctx->width  = get_bits(&gb, 12);
+            avctx->height = get_bits(&gb, 12);
+            break;
+        }
 
-            svq3->halfpel_flag  = get_bits1(&gb);
-            svq3->thirdpel_flag = get_bits1(&gb);
+        s->halfpel_flag  = get_bits1(&gb);
+        s->thirdpel_flag = get_bits1(&gb);
 
-            /* unknown fields */
-            skip_bits1(&gb);
-            skip_bits1(&gb);
-            skip_bits1(&gb);
-            skip_bits1(&gb);
+        /* unknown fields */
+        skip_bits1(&gb);
+        skip_bits1(&gb);
+        skip_bits1(&gb);
+        skip_bits1(&gb);
 
-            s->low_delay = get_bits1(&gb);
+        h->low_delay = get_bits1(&gb);
 
-            /* unknown field */
-            skip_bits1(&gb);
+        /* unknown field */
+        skip_bits1(&gb);
 
-            while (get_bits1(&gb))
-                skip_bits(&gb, 8);
+        while (get_bits1(&gb))
+            skip_bits(&gb, 8);
 
-            svq3->unknown_flag  = get_bits1(&gb);
-            avctx->has_b_frames = !s->low_delay;
-            if (svq3->unknown_flag) {
+        s->unknown_flag  = get_bits1(&gb);
+        avctx->has_b_frames = !h->low_delay;
+        if (s->unknown_flag) {
 #if CONFIG_ZLIB
-                unsigned watermark_width  = svq3_get_ue_golomb(&gb);
-                unsigned watermark_height = svq3_get_ue_golomb(&gb);
-                int u1                    = svq3_get_ue_golomb(&gb);
-                int u2                    = get_bits(&gb, 8);
-                int u3                    = get_bits(&gb, 2);
-                int u4                    = svq3_get_ue_golomb(&gb);
-                unsigned long buf_len     = watermark_width *
-                                            watermark_height * 4;
-                int offset                = get_bits_count(&gb) + 7 >> 3;
-                uint8_t *buf;
-
-                if (watermark_height <= 0 || (uint64_t)watermark_width*4 > UINT_MAX/watermark_height)
-                    return -1;
+            unsigned watermark_width  = svq3_get_ue_golomb(&gb);
+            unsigned watermark_height = svq3_get_ue_golomb(&gb);
+            int u1                    = svq3_get_ue_golomb(&gb);
+            int u2                    = get_bits(&gb, 8);
+            int u3                    = get_bits(&gb, 2);
+            int u4                    = svq3_get_ue_golomb(&gb);
+            unsigned long buf_len     = watermark_width *
+                                        watermark_height * 4;
+            int offset                = get_bits_count(&gb) + 7 >> 3;
+            uint8_t *buf;
+
+            if (watermark_height <= 0 || (uint64_t)watermark_width*4 > UINT_MAX/watermark_height)
+                return -1;
 
-                buf = av_malloc(buf_len);
-                av_log(avctx, AV_LOG_DEBUG, "watermark size: %dx%d\n",
-                       watermark_width, watermark_height);
-                av_log(avctx, AV_LOG_DEBUG,
-                       "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
-                       u1, u2, u3, u4, offset);
-                if (uncompress(buf, &buf_len, extradata + 8 + offset,
-                               size - offset) != Z_OK) {
-                    av_log(avctx, AV_LOG_ERROR,
-                           "could not uncompress watermark logo\n");
-                    av_free(buf);
-                    return -1;
-                }
-                svq3->watermark_key = ff_svq1_packet_checksum(buf, buf_len, 0);
-                svq3->watermark_key = svq3->watermark_key << 16 |
-                                      svq3->watermark_key;
-                av_log(avctx, AV_LOG_DEBUG,
-                       "watermark key %#x\n", svq3->watermark_key);
-                av_free(buf);
-#else
+            buf = av_malloc(buf_len);
+            av_log(avctx, AV_LOG_DEBUG, "watermark size: %dx%d\n",
+                   watermark_width, watermark_height);
+            av_log(avctx, AV_LOG_DEBUG,
+                   "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
+                   u1, u2, u3, u4, offset);
+            if (uncompress(buf, &buf_len, extradata + 8 + offset,
+                           size - offset) != Z_OK) {
                 av_log(avctx, AV_LOG_ERROR,
-                       "this svq3 file contains watermark which need zlib support compiled in\n");
+                       "could not uncompress watermark logo\n");
+                av_free(buf);
                 return -1;
-#endif
             }
+            s->watermark_key = ff_svq1_packet_checksum(buf, buf_len, 0);
+            s->watermark_key = s->watermark_key << 16 | s->watermark_key;
+            av_log(avctx, AV_LOG_DEBUG,
+                   "watermark key %#x\n", s->watermark_key);
+            av_free(buf);
+#else
+            av_log(avctx, AV_LOG_ERROR,
+                   "this svq3 file contains watermark which need zlib support compiled in\n");
+            return -1;
+#endif
         }
+    }
 
-        s->width  = avctx->width;
-        s->height = avctx->height;
+    h->width  = avctx->width;
+    h->height = avctx->height;
+    h->mb_width  = (h->width + 15) / 16;
+    h->mb_height = (h->height + 15) / 16;
+    h->mb_stride = h->mb_width + 1;
+    h->mb_num    = h->mb_width * h->mb_height;
+    h->b_stride = 4 * h->mb_width;
+    s->h_edge_pos = h->mb_width * 16;
+    s->v_edge_pos = h->mb_height * 16;
+
+    if (ff_h264_alloc_tables(h) < 0) {
+        av_log(avctx, AV_LOG_ERROR, "svq3 memory allocation failed\n");
+        return AVERROR(ENOMEM);
+    }
 
-        if (ff_MPV_common_init(s) < 0)
-            return -1;
+    return 0;
+}
 
-        h->b_stride = 4 * s->mb_width;
+static int get_buffer(AVCodecContext *avctx, Picture *pic)
+{
+    SVQ3Context *s = avctx->priv_data;
+    H264Context *h = &s->h;
+    const int big_mb_num    = h->mb_stride * (h->mb_height + 1) + 1;
+    const int mb_array_size = h->mb_stride * h->mb_height;
+    const int b4_stride     = h->mb_width * 4 + 1;
+    const int b4_array_size = b4_stride * h->mb_height * 4;
+    int ret;
+
+    if (!pic->motion_val_base[0]) {
+        int i;
 
-        if (ff_h264_alloc_tables(h) < 0) {
-            av_log(avctx, AV_LOG_ERROR, "svq3 memory allocation failed\n");
+        pic->mb_type_base = av_mallocz((big_mb_num + h->mb_stride) * sizeof(uint32_t));
+        if (!pic->mb_type_base)
             return AVERROR(ENOMEM);
+        pic->f.mb_type = pic->mb_type_base + 2 * h->mb_stride + 1;
+
+        for (i = 0; i < 2; i++) {
+            pic->motion_val_base[i] = av_mallocz(2 * (b4_array_size + 4) * sizeof(int16_t));
+            pic->f.ref_index[i]     = av_mallocz(4 * mb_array_size);
+            if (!pic->motion_val_base[i] || !pic->f.ref_index[i])
+                return AVERROR(ENOMEM);
+
+            pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
         }
     }
+    pic->f.motion_subsample_log2 = 2;
+    pic->f.reference = !(h->pict_type == AV_PICTURE_TYPE_B);
 
-    return 0;
+    ret = ff_get_buffer(avctx, &pic->f);
+    if (!h->edge_emu_buffer) {
+        h->edge_emu_buffer = av_mallocz(pic->f.linesize[0] * 17);
+        if (!h->edge_emu_buffer)
+            return AVERROR(ENOMEM);
+    }
+
+    h->linesize   = pic->f.linesize[0];
+    h->uvlinesize = pic->f.linesize[1];
+
+    return ret;
 }
 
 static int svq3_decode_frame(AVCodecContext *avctx, void *data,
                              int *got_frame, AVPacket *avpkt)
 {
-    SVQ3Context *svq3  = avctx->priv_data;
-    H264Context *h     = &svq3->h;
-    MpegEncContext *s  = &h->s;
+    SVQ3Context *s     = avctx->priv_data;
+    H264Context *h     = &s->h;
     int buf_size       = avpkt->size;
-    int m, left;
+    int left;
     uint8_t *buf;
+    int ret, m, i;
 
     /* special case for last picture */
     if (buf_size == 0) {
-        if (s->next_picture_ptr && !s->low_delay) {
-            *(AVFrame *) data   = s->next_picture.f;
-            s->next_picture_ptr = NULL;
+        if (s->next_pic->f.data[0] && !h->low_delay && !s->last_frame_output) {
+            *(AVFrame *) data   = s->next_pic->f;
+            s->last_frame_output = 1;
             *got_frame          = 1;
         }
         return 0;
     }
 
-    s->mb_x = s->mb_y = h->mb_xy = 0;
+    h->mb_x = h->mb_y = h->mb_xy = 0;
 
-    if (svq3->watermark_key) {
-        av_fast_malloc(&svq3->buf, &svq3->buf_size,
+    if (s->watermark_key) {
+        av_fast_malloc(&s->buf, &s->buf_size,
                        buf_size+FF_INPUT_BUFFER_PADDING_SIZE);
-        if (!svq3->buf)
+        if (!s->buf)
             return AVERROR(ENOMEM);
-        memcpy(svq3->buf, avpkt->data, buf_size);
-        buf = svq3->buf;
+        memcpy(s->buf, avpkt->data, buf_size);
+        buf = s->buf;
     } else {
         buf = avpkt->data;
     }
 
-    init_get_bits(&s->gb, buf, 8 * buf_size);
+    init_get_bits(&h->gb, buf, 8 * buf_size);
 
     if (svq3_decode_slice_header(avctx))
         return -1;
 
-    s->pict_type      = h->slice_type;
-    s->picture_number = h->slice_num;
+    h->pict_type = h->slice_type;
 
-    if (avctx->debug & FF_DEBUG_PICT_INFO)
-        av_log(h->s.avctx, AV_LOG_DEBUG,
-               "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
-               av_get_picture_type_char(s->pict_type),
-               svq3->halfpel_flag, svq3->thirdpel_flag,
-               s->adaptive_quant, s->qscale, h->slice_num);
+    if (h->pict_type != AV_PICTURE_TYPE_B)
+        FFSWAP(Picture*, s->next_pic, s->last_pic);
+
+    if (s->cur_pic->f.data[0])
+        avctx->release_buffer(avctx, &s->cur_pic->f);
 
     /* for skipping the frame */
-    s->current_picture.f.pict_type = s->pict_type;
-    s->current_picture.f.key_frame = (s->pict_type == AV_PICTURE_TYPE_I);
+    s->cur_pic->f.pict_type = h->pict_type;
+    s->cur_pic->f.key_frame = (h->pict_type == AV_PICTURE_TYPE_I);
 
-    /* Skip B-frames if we do not have reference frames. */
-    if (s->last_picture_ptr == NULL && s->pict_type == AV_PICTURE_TYPE_B)
-        return 0;
-    if (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B ||
-        avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I ||
+    ret = get_buffer(avctx, s->cur_pic);
+    if (ret < 0)
+        return ret;
+
+    h->cur_pic_ptr = s->cur_pic;
+    h->cur_pic     = *s->cur_pic;
+
+    for (i = 0; i < 16; i++) {
+        h->block_offset[i]           = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * h->linesize * ((scan8[i] - scan8[0]) >> 3);
+        h->block_offset[48 + i]      = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * h->linesize * ((scan8[i] - scan8[0]) >> 3);
+    }
+    for (i = 0; i < 16; i++) {
+        h->block_offset[16 + i]      =
+        h->block_offset[32 + i]      = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * h->uvlinesize * ((scan8[i] - scan8[0]) >> 3);
+        h->block_offset[48 + 16 + i] =
+        h->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * h->uvlinesize * ((scan8[i] - scan8[0]) >> 3);
+    }
+
+    if (h->pict_type != AV_PICTURE_TYPE_I) {
+        if (!s->last_pic->f.data[0]) {
+            av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
+            ret = get_buffer(avctx, s->last_pic);
+            if (ret < 0)
+                return ret;
+            memset(s->last_pic->f.data[0], 0, avctx->height * s->last_pic->f.linesize[0]);
+            memset(s->last_pic->f.data[1], 0x80, (avctx->height / 2) *
+                   s->last_pic->f.linesize[1]);
+            memset(s->last_pic->f.data[2], 0x80, (avctx->height / 2) *
+                   s->last_pic->f.linesize[2]);
+        }
+
+        if (h->pict_type == AV_PICTURE_TYPE_B && !s->next_pic->f.data[0]) {
+            av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
+            ret = get_buffer(avctx, s->next_pic);
+            if (ret < 0)
+                return ret;
+            memset(s->next_pic->f.data[0], 0, avctx->height * s->next_pic->f.linesize[0]);
+            memset(s->next_pic->f.data[1], 0x80, (avctx->height / 2) *
+                   s->next_pic->f.linesize[1]);
+            memset(s->next_pic->f.data[2], 0x80, (avctx->height / 2) *
+                   s->next_pic->f.linesize[2]);
+        }
+    }
+
+    if (avctx->debug & FF_DEBUG_PICT_INFO)
+        av_log(h->avctx, AV_LOG_DEBUG,
+               "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
+               av_get_picture_type_char(h->pict_type),
+               s->halfpel_flag, s->thirdpel_flag,
+               s->adaptive_quant, h->qscale, h->slice_num);
+
+    if (avctx->skip_frame >= AVDISCARD_NONREF && h->pict_type == AV_PICTURE_TYPE_B ||
+        avctx->skip_frame >= AVDISCARD_NONKEY && h->pict_type != AV_PICTURE_TYPE_I ||
         avctx->skip_frame >= AVDISCARD_ALL)
         return 0;
 
     if (s->next_p_frame_damaged) {
-        if (s->pict_type == AV_PICTURE_TYPE_B)
+        if (h->pict_type == AV_PICTURE_TYPE_B)
             return 0;
         else
             s->next_p_frame_damaged = 0;
     }
 
-    if (ff_h264_frame_start(h) < 0)
-        return -1;
-
-    if (s->pict_type == AV_PICTURE_TYPE_B) {
+    if (h->pict_type == AV_PICTURE_TYPE_B) {
         h->frame_num_offset = h->slice_num - h->prev_frame_num;
 
         if (h->frame_num_offset < 0)
             h->frame_num_offset += 256;
         if (h->frame_num_offset == 0 ||
             h->frame_num_offset >= h->prev_frame_num_offset) {
-            av_log(h->s.avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
+            av_log(h->avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
             return -1;
         }
     } else {
@@ -1109,16 +1207,16 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data,
         }
     }
 
-    for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
-        for (s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
+    for (h->mb_y = 0; h->mb_y < h->mb_height; h->mb_y++) {
+        for (h->mb_x = 0; h->mb_x < h->mb_width; h->mb_x++) {
             unsigned mb_type;
-            h->mb_xy = s->mb_x + s->mb_y * s->mb_stride;
+            h->mb_xy = h->mb_x + h->mb_y * h->mb_stride;
 
-            if ((get_bits_count(&s->gb) + 7) >= s->gb.size_in_bits &&
-                ((get_bits_count(&s->gb) & 7) == 0 ||
-                 show_bits(&s->gb, -get_bits_count(&s->gb) & 7) == 0)) {
-                skip_bits(&s->gb, svq3->next_slice_index - get_bits_count(&s->gb));
-                s->gb.size_in_bits = 8 * buf_size;
+            if ((get_bits_count(&h->gb) + 7) >= h->gb.size_in_bits &&
+                ((get_bits_count(&h->gb) & 7) == 0 ||
+                 show_bits(&h->gb, -get_bits_count(&h->gb) & 7) == 0)) {
+                skip_bits(&h->gb, s->next_slice_index - get_bits_count(&h->gb));
+                h->gb.size_in_bits = 8 * buf_size;
 
                 if (svq3_decode_slice_header(avctx))
                     return -1;
@@ -1126,33 +1224,35 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data,
                 /* TODO: support s->mb_skip_run */
             }
 
-            mb_type = svq3_get_ue_golomb(&s->gb);
+            mb_type = svq3_get_ue_golomb(&h->gb);
 
-            if (s->pict_type == AV_PICTURE_TYPE_I)
+            if (h->pict_type == AV_PICTURE_TYPE_I)
                 mb_type += 8;
-            else if (s->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4)
+            else if (h->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4)
                 mb_type += 4;
-            if (mb_type > 33 || svq3_decode_mb(svq3, mb_type)) {
-                av_log(h->s.avctx, AV_LOG_ERROR,
-                       "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
+            if (mb_type > 33 || svq3_decode_mb(s, mb_type)) {
+                av_log(h->avctx, AV_LOG_ERROR,
+                       "error while decoding MB %d %d\n", h->mb_x, h->mb_y);
                 return -1;
             }
 
-            if (mb_type != 0)
+            if (mb_type != 0 || h->cbp)
                 ff_h264_hl_decode_mb(h);
 
-            if (s->pict_type != AV_PICTURE_TYPE_B && !s->low_delay)
-                s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride] =
-                    (s->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
+            if (h->pict_type != AV_PICTURE_TYPE_B && !h->low_delay)
+                h->cur_pic.f.mb_type[h->mb_x + h->mb_y * h->mb_stride] =
+                    (h->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
         }
 
-        ff_draw_horiz_band(s, 16 * s->mb_y, 16);
+        ff_draw_horiz_band(avctx, NULL, s->cur_pic, s->last_pic->f.data[0] ? s->last_pic : NULL,
+                           16 * h->mb_y, 16, h->picture_structure, 0, 0,
+                           h->low_delay, h->mb_height * 16, h->mb_width * 16);
     }
 
-    left = buf_size*8 - get_bits_count(&s->gb);
+    left = buf_size*8 - get_bits_count(&h->gb);
 
-    if (s->mb_y != s->mb_height || s->mb_x != s->mb_width) {
-        av_log(avctx, AV_LOG_INFO, "frame num %d incomplete pic x %d y %d left %d\n", avctx->frame_number, s->mb_y, s->mb_x, left);
+    if (h->mb_y != h->mb_height || h->mb_x != h->mb_width) {
+        av_log(avctx, AV_LOG_INFO, "frame num %d incomplete pic x %d y %d left %d\n", avctx->frame_number, h->mb_y, h->mb_x, left);
         //av_hex_dump(stderr, buf+buf_size-8, 8);
     }
 
@@ -1161,32 +1261,50 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data,
         return -1;
     }
 
-    ff_MPV_frame_end(s);
-
-    if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay)
-        *(AVFrame *)data = s->current_picture.f;
+    if (h->pict_type == AV_PICTURE_TYPE_B || h->low_delay)
+        *(AVFrame *)data = s->cur_pic->f;
     else
-        *(AVFrame *)data = s->last_picture.f;
+        *(AVFrame *)data = s->last_pic->f;
 
     /* Do not output the last pic after seeking. */
-    if (s->last_picture_ptr || s->low_delay)
+    if (s->last_pic->f.data[0] || h->low_delay)
         *got_frame = 1;
 
+    if (h->pict_type != AV_PICTURE_TYPE_B) {
+        FFSWAP(Picture*, s->cur_pic, s->next_pic);
+    }
+
     return buf_size;
 }
 
+static void free_picture(AVCodecContext *avctx, Picture *pic)
+{
+    int i;
+    for (i = 0; i < 2; i++) {
+        av_freep(&pic->motion_val_base[i]);
+        av_freep(&pic->f.ref_index[i]);
+    }
+    av_freep(&pic->mb_type_base);
+
+    if (pic->f.data[0])
+        avctx->release_buffer(avctx, &pic->f);
+    av_freep(&pic);
+}
+
 static int svq3_decode_end(AVCodecContext *avctx)
 {
-    SVQ3Context *svq3 = avctx->priv_data;
-    H264Context *h    = &svq3->h;
-    MpegEncContext *s = &h->s;
+    SVQ3Context *s = avctx->priv_data;
+    H264Context *h = &s->h;
 
-    ff_h264_free_context(h);
+    free_picture(avctx, s->cur_pic);
+    free_picture(avctx, s->next_pic);
+    free_picture(avctx, s->last_pic);
 
-    ff_MPV_common_end(s);
+    ff_h264_free_context(h);
 
-    av_freep(&svq3->buf);
-    svq3->buf_size = 0;
+    av_freep(&s->buf);
+    s->buf_size = 0;
+    av_freep(&h->edge_emu_buffer);
 
     return 0;
 }
diff --git a/mythtv/external/FFmpeg/libavcodec/svq3.h b/mythtv/external/FFmpeg/libavcodec/svq3.h
new file mode 100644
index 00000000000..7a57d8ad017
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/svq3.h
@@ -0,0 +1,27 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_SVQ3_H
+#define AVCODEC_SVQ3_H
+
+#include 
+
+void ff_svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp);
+void ff_svq3_add_idct_c(uint8_t *dst, int16_t *block, int stride, int qp, int dc);
+
+#endif /* AVCODEC_DSPUTIL_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/takdec.c b/mythtv/external/FFmpeg/libavcodec/takdec.c
index 86c1a7dda52..ae751fed167 100644
--- a/mythtv/external/FFmpeg/libavcodec/takdec.c
+++ b/mythtv/external/FFmpeg/libavcodec/takdec.c
@@ -25,6 +25,7 @@
  * @author Paul B Mahol
  */
 
+#include "libavutil/internal.h"
 #include "libavutil/samplefmt.h"
 #include "tak.h"
 #include "avcodec.h"
@@ -44,7 +45,6 @@ typedef struct MCDParam {
 
 typedef struct TAKDecContext {
     AVCodecContext *avctx;                          ///< parent AVCodecContext
-    AVFrame         frame;                          ///< AVFrame for decoded output
     DSPContext      dsp;
     TAKStreamInfo   ti;
     GetBitContext   gb;                             ///< bitstream reader initialized to start at the current frame
@@ -174,8 +174,6 @@ static av_cold int tak_decode_init(AVCodecContext *avctx)
     ff_dsputil_init(&s->dsp, avctx);
 
     s->avctx = avctx;
-    avcodec_get_frame_defaults(&s->frame);
-    avctx->coded_frame = &s->frame;
     avctx->bits_per_raw_sample = avctx->bits_per_coded_sample;
 
     set_sample_rate_params(avctx);
@@ -687,13 +685,15 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
                             int *got_frame_ptr, AVPacket *pkt)
 {
     TAKDecContext *s  = avctx->priv_data;
+    AVFrame *frame    = data;
     GetBitContext *gb = &s->gb;
     int chan, i, ret, hsize;
 
     if (pkt->size < TAK_MIN_FRAME_HEADER_BYTES)
         return AVERROR_INVALIDDATA;
 
-    init_get_bits(gb, pkt->data, pkt->size * 8);
+    if ((ret = init_get_bits8(gb, pkt->data, pkt->size)) < 0)
+        return ret;
 
     if ((ret = ff_tak_decode_frame_header(avctx, gb, &s->ti, 0)) < 0)
         return ret;
@@ -748,8 +748,8 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
     s->nb_samples = s->ti.last_frame_samples ? s->ti.last_frame_samples
                                              : s->ti.frame_samples;
 
-    s->frame.nb_samples = s->nb_samples;
-    if ((ret = ff_get_buffer(avctx, &s->frame)) < 0)
+    frame->nb_samples = s->nb_samples;
+    if ((ret = ff_get_buffer(avctx, frame)) < 0)
         return ret;
 
     if (avctx->bits_per_raw_sample <= 16) {
@@ -766,7 +766,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
             return ret;
     } else {
         for (chan = 0; chan < avctx->channels; chan++)
-            s->decoded[chan] = (int32_t *)s->frame.extended_data[chan];
+            s->decoded[chan] = (int32_t *)frame->extended_data[chan];
     }
 
     if (s->nb_samples < 16) {
@@ -884,7 +884,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
     switch (avctx->sample_fmt) {
     case AV_SAMPLE_FMT_U8P:
         for (chan = 0; chan < avctx->channels; chan++) {
-            uint8_t *samples = (uint8_t *)s->frame.extended_data[chan];
+            uint8_t *samples = (uint8_t *)frame->extended_data[chan];
             int32_t *decoded = s->decoded[chan];
             for (i = 0; i < s->nb_samples; i++)
                 samples[i] = decoded[i] + 0x80;
@@ -892,7 +892,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
         break;
     case AV_SAMPLE_FMT_S16P:
         for (chan = 0; chan < avctx->channels; chan++) {
-            int16_t *samples = (int16_t *)s->frame.extended_data[chan];
+            int16_t *samples = (int16_t *)frame->extended_data[chan];
             int32_t *decoded = s->decoded[chan];
             for (i = 0; i < s->nb_samples; i++)
                 samples[i] = decoded[i];
@@ -900,15 +900,14 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
         break;
     case AV_SAMPLE_FMT_S32P:
         for (chan = 0; chan < avctx->channels; chan++) {
-            int32_t *samples = (int32_t *)s->frame.extended_data[chan];
+            int32_t *samples = (int32_t *)frame->extended_data[chan];
             for (i = 0; i < s->nb_samples; i++)
                 samples[i] <<= 8;
         }
         break;
     }
 
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = s->frame;
+    *got_frame_ptr = 1;
 
     return pkt->size;
 }
diff --git a/mythtv/external/FFmpeg/libavcodec/targa.c b/mythtv/external/FFmpeg/libavcodec/targa.c
index 321441cb08c..2d1d3dfb13c 100644
--- a/mythtv/external/FFmpeg/libavcodec/targa.c
+++ b/mythtv/external/FFmpeg/libavcodec/targa.c
@@ -178,7 +178,7 @@ static int decode_frame(AVCodecContext *avctx,
         return AVERROR_INVALIDDATA;
     }
 
-    if ((ret = av_image_check_size(w, h, 0, avctx)))
+    if ((ret = av_image_check_size(w, h, 0, avctx)) < 0)
         return ret;
     if (w != avctx->width || h != avctx->height)
         avcodec_set_dimensions(avctx, w, h);
@@ -200,6 +200,7 @@ static int decode_frame(AVCodecContext *avctx,
 
     if (colors) {
         int pal_size, pal_sample_size;
+
         switch (csize) {
         case 32: pal_sample_size = 4; break;
         case 24: pal_sample_size = 3; break;
@@ -267,7 +268,7 @@ static int decode_frame(AVCodecContext *avctx,
             line = dst;
             y = 0;
             do {
-                bytestream2_get_bufferu(&s->gb, line, img_size);
+                bytestream2_get_buffer(&s->gb, line, img_size);
                 line = advance_line(dst, line, stride, &y, h, interleave);
             } while (line);
         }
diff --git a/mythtv/external/FFmpeg/libavcodec/tiff.c b/mythtv/external/FFmpeg/libavcodec/tiff.c
index 1011116f41d..b43fda8c638 100644
--- a/mythtv/external/FFmpeg/libavcodec/tiff.c
+++ b/mythtv/external/FFmpeg/libavcodec/tiff.c
@@ -139,7 +139,11 @@ static int cmp_id_key(const void *id, const void *k)
 
 static const char *search_keyval(const TiffGeoTagKeyName *keys, int n, int id)
 {
-    return ((TiffGeoTagKeyName*)bsearch(&id, keys, n, sizeof(keys[0]), cmp_id_key))->name;
+    TiffGeoTagKeyName *r = bsearch(&id, keys, n, sizeof(keys[0]), cmp_id_key);
+    if(r)
+        return r->name;
+
+    return NULL;
 }
 
 static char *get_geokey_val(int key, int val)
@@ -187,10 +191,12 @@ static char *get_geokey_val(int key, int val)
         RET_GEOKEY_VAL(PRIME_MERIDIAN, prime_meridian);
         break;
     case TIFF_PROJECTED_CS_TYPE_GEOKEY:
-        return av_strdup(search_keyval(ff_tiff_proj_cs_type_codes, FF_ARRAY_ELEMS(ff_tiff_proj_cs_type_codes), val));
+        ap = av_strdup(search_keyval(ff_tiff_proj_cs_type_codes, FF_ARRAY_ELEMS(ff_tiff_proj_cs_type_codes), val));
+        if(ap) return ap;
         break;
     case TIFF_PROJECTION_GEOKEY:
-        return av_strdup(search_keyval(ff_tiff_projection_codes, FF_ARRAY_ELEMS(ff_tiff_projection_codes), val));
+        ap = av_strdup(search_keyval(ff_tiff_projection_codes, FF_ARRAY_ELEMS(ff_tiff_projection_codes), val));
+        if(ap) return ap;
         break;
     case TIFF_PROJ_COORD_TRANS_GEOKEY:
         RET_GEOKEY_VAL(COORD_TRANS, coord_trans);
@@ -283,7 +289,7 @@ static int add_doubles_metadata(int count,
     av_freep(&dp);
     if (!ap)
         return AVERROR(ENOMEM);
-    av_dict_set(&s->picture.metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
+    av_dict_set(ff_frame_get_metadatap(&s->picture), name, ap, AV_DICT_DONT_STRDUP_VAL);
     return 0;
 }
 
@@ -309,7 +315,7 @@ static int add_shorts_metadata(int count, const char *name,
     av_freep(&sp);
     if (!ap)
         return AVERROR(ENOMEM);
-    av_dict_set(&s->picture.metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
+    av_dict_set(ff_frame_get_metadatap(&s->picture), name, ap, AV_DICT_DONT_STRDUP_VAL);
     return 0;
 }
 
@@ -318,7 +324,7 @@ static int add_string_metadata(int count, const char *name,
 {
     char *value;
 
-    if (bytestream2_get_bytes_left(&s->gb) < count)
+    if (bytestream2_get_bytes_left(&s->gb) < count || count < 0)
         return AVERROR_INVALIDDATA;
 
     value = av_malloc(count + 1);
@@ -328,7 +334,7 @@ static int add_string_metadata(int count, const char *name,
     bytestream2_get_bufferu(&s->gb, value, count);
     value[count] = 0;
 
-    av_dict_set(&s->picture.metadata, name, value, AV_DICT_DONT_STRDUP_VAL);
+    av_dict_set(ff_frame_get_metadatap(&s->picture), name, value, AV_DICT_DONT_STRDUP_VAL);
     return 0;
 }
 
@@ -409,7 +415,7 @@ static void av_always_inline horizontal_fill(unsigned int bpp, uint8_t* dst,
 static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
                              const uint8_t *src, int size, int lines)
 {
-    int c, line, pixels, code;
+    int c, line, pixels, code, ret;
     const uint8_t *ssrc = src;
     int width = ((s->width * s->bpp) + 7) >> 3;
 
@@ -444,7 +450,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
                    (unsigned long)width * lines, ret);
             av_free(src2);
             av_free(zbuf);
-            return -1;
+            return AVERROR_UNKNOWN;
         }
         src = zbuf;
         for (line = 0; line < lines; line++) {
@@ -475,9 +481,9 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
         if (size > 1 && !src[0] && (src[1]&1)) {
             av_log(s->avctx, AV_LOG_ERROR, "Old style LZW is unsupported\n");
         }
-        if (ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0) {
+        if ((ret = ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF)) < 0) {
             av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
-            return -1;
+            return ret;
         }
     }
     if (s->compr == TIFF_CCITT_RLE || s->compr == TIFF_G3
@@ -495,7 +501,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
             av_log(s->avctx, AV_LOG_ERROR,
                    "Uncompressed fax mode is not supported (yet)\n");
             av_free(src2);
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         if (!s->fill_order) {
             memcpy(src2, src, size);
@@ -523,7 +529,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
     for (line = 0; line < lines; line++) {
         if (src - ssrc > size) {
             av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         switch (s->compr) {
         case TIFF_RAW:
@@ -551,7 +557,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
                     if (pixels + code > width) {
                         av_log(s->avctx, AV_LOG_ERROR,
                                "Copy went out of bounds\n");
-                        return -1;
+                        return AVERROR_INVALIDDATA;
                     }
                     if (ssrc + size - src < code) {
                         av_log(s->avctx, AV_LOG_ERROR, "Read went out of bounds\n");
@@ -566,7 +572,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
                     if (pixels + code > width) {
                         av_log(s->avctx, AV_LOG_ERROR,
                                "Run went out of bounds\n");
-                        return -1;
+                        return AVERROR_INVALIDDATA;
                     }
                     c = *src++;
                     horizontal_fill(s->bpp * (s->avctx->pix_fmt == AV_PIX_FMT_PAL8),
@@ -580,7 +586,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
             if (pixels < width) {
                 av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",
                        pixels, width);
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
             if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
                 horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0);
@@ -715,7 +721,7 @@ static int tiff_decode_tag(TiffContext *s)
             av_log(s->avctx, AV_LOG_ERROR,
                    "This format is not supported (bpp=%d, %d components)\n",
                    s->bpp, count);
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         if (count == 1)
             s->bpp = value;
@@ -729,7 +735,7 @@ static int tiff_decode_tag(TiffContext *s)
             case TIFF_LONG:
                 s->bpp = 0;
                 if (bytestream2_get_bytes_left(&s->gb) < type_sizes[type] * count)
-                    return -1;
+                    return AVERROR_INVALIDDATA;
                 for (i = 0; i < count; i++)
                     s->bpp += tget(&s->gb, type, s->le);
                 break;
@@ -744,6 +750,11 @@ static int tiff_decode_tag(TiffContext *s)
                    "Samples per pixel requires a single value, many provided\n");
             return AVERROR_INVALIDDATA;
         }
+        if (value > 4U) {
+            av_log(s->avctx, AV_LOG_ERROR,
+                   "Samples per pixel %d is too large\n", value);
+            return AVERROR_INVALIDDATA;
+        }
         if (s->bppcount == 1)
             s->bpp *= value;
         s->bppcount = value;
@@ -767,17 +778,17 @@ static int tiff_decode_tag(TiffContext *s)
             break;
 #else
             av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
-            return -1;
+            return AVERROR(ENOSYS);
 #endif
         case TIFF_JPEG:
         case TIFF_NEWJPEG:
             av_log(s->avctx, AV_LOG_ERROR,
                    "JPEG compression is not supported\n");
-            return -1;
+            return AVERROR_PATCHWELCOME;
         default:
             av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
                    s->compr);
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         break;
     case TIFF_ROWSPERSTRIP:
@@ -786,7 +797,7 @@ static int tiff_decode_tag(TiffContext *s)
         if (value < 1) {
             av_log(s->avctx, AV_LOG_ERROR,
                    "Incorrect value of rows per strip\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         s->rps = value;
         break;
@@ -803,7 +814,7 @@ static int tiff_decode_tag(TiffContext *s)
         if (s->strippos > bytestream2_size(&s->gb)) {
             av_log(s->avctx, AV_LOG_ERROR,
                    "Tag referencing position outside the image\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         break;
     case TIFF_STRIP_SIZE:
@@ -819,7 +830,7 @@ static int tiff_decode_tag(TiffContext *s)
         if (s->stripsizesoff > bytestream2_size(&s->gb)) {
             av_log(s->avctx, AV_LOG_ERROR,
                    "Tag referencing position outside the image\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         break;
     case TIFF_TILE_BYTE_COUNTS:
@@ -846,7 +857,7 @@ static int tiff_decode_tag(TiffContext *s)
         default:
             av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n",
                    value);
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         break;
     case TIFF_FILL_ORDER:
@@ -861,7 +872,7 @@ static int tiff_decode_tag(TiffContext *s)
         pal = (uint32_t *) s->palette;
         off = type_sizes[type];
         if (count / 3 > 256 || bytestream2_get_bytes_left(&s->gb) < count / 3 * off * 3)
-            return -1;
+            return AVERROR_INVALIDDATA;
         off = (type_sizes[type] - 1) << 3;
         for (k = 2; k >= 0; k--) {
             for (i = 0; i < count / 3; i++) {
@@ -876,7 +887,7 @@ static int tiff_decode_tag(TiffContext *s)
     case TIFF_PLANAR:
         if (value == 2) {
             av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n");
-            return -1;
+            return AVERROR_PATCHWELCOME;
         }
         break;
     case TIFF_T4OPTIONS:
@@ -909,11 +920,14 @@ static int tiff_decode_tag(TiffContext *s)
             s->geotag_count = count / 4 - 1;
             av_log(s->avctx, AV_LOG_WARNING, "GeoTIFF key directory buffer shorter than specified\n");
         }
-        if (bytestream2_get_bytes_left(&s->gb) < s->geotag_count * sizeof(int16_t) * 4)
+        if (bytestream2_get_bytes_left(&s->gb) < s->geotag_count * sizeof(int16_t) * 4) {
+            s->geotag_count = 0;
             return -1;
+        }
         s->geotags = av_mallocz(sizeof(TiffGeoTag) * s->geotag_count);
         if (!s->geotags) {
             av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
+            s->geotag_count = 0;
             return AVERROR(ENOMEM);
         }
         for (i = 0; i < s->geotag_count; i++) {
@@ -969,7 +983,7 @@ static int tiff_decode_tag(TiffContext *s)
 
                     bytestream2_seek(&s->gb, pos + s->geotags[i].offset, SEEK_SET);
                     if (bytestream2_get_bytes_left(&s->gb) < s->geotags[i].count)
-                        return -1;
+                        return AVERROR_INVALIDDATA;
                     ap = av_malloc(s->geotags[i].count);
                     if (!ap) {
                         av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
@@ -1050,7 +1064,7 @@ static int decode_frame(AVCodecContext *avctx,
         le = 0;
     else {
         av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
     s->le = le;
     // TIFF_BPP is not a required tag and defaults to 1
@@ -1061,14 +1075,14 @@ static int decode_frame(AVCodecContext *avctx,
     free_geotags(s);
     /* metadata has been destroyed from lavc internals, that pointer is not
      * valid anymore */
-    s->picture.metadata = NULL;
+    av_frame_set_metadata(&s->picture, NULL);
 
     // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number
     // that further identifies the file as a TIFF file"
     if (tget_short(&s->gb, le) != 42) {
         av_log(avctx, AV_LOG_ERROR,
                "The answer to life, universe and everything is not correct!\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
     // Reset these offsets so we can tell if they were set this frame
     s->stripsizesoff = s->strippos = 0;
@@ -1083,8 +1097,8 @@ static int decode_frame(AVCodecContext *avctx,
     if (bytestream2_get_bytes_left(&s->gb) < entries * 12)
         return AVERROR_INVALIDDATA;
     for (i = 0; i < entries; i++) {
-        if (tiff_decode_tag(s) < 0)
-            return -1;
+        if ((ret = tiff_decode_tag(s)) < 0)
+            return ret;
     }
 
     for (i = 0; igeotag_count; i++) {
@@ -1097,7 +1111,7 @@ static int decode_frame(AVCodecContext *avctx,
             av_log(avctx, AV_LOG_WARNING, "Type of GeoTIFF key %d is wrong\n", s->geotags[i].key);
             continue;
         }
-        ret = av_dict_set(&s->picture.metadata, keyname, s->geotags[i].val, 0);
+        ret = av_dict_set(ff_frame_get_metadatap(&s->picture), keyname, s->geotags[i].val, 0);
         if (ret<0) {
             av_log(avctx, AV_LOG_ERROR, "Writing metadata with key '%s' failed\n", keyname);
             return ret;
@@ -1106,7 +1120,7 @@ static int decode_frame(AVCodecContext *avctx,
 
     if (!s->strippos && !s->stripoff) {
         av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
     /* now we have the data and may start decoding */
     if ((ret = init_image(s)) < 0)
@@ -1148,7 +1162,7 @@ static int decode_frame(AVCodecContext *avctx,
 
         if (soff > avpkt->size || ssize > avpkt->size - soff) {
             av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         if (tiff_unpack_strip(s, dst, stride, avpkt->data + soff, ssize,
                               FFMIN(s->rps, s->height - i)) < 0)
diff --git a/mythtv/external/FFmpeg/libavcodec/tmv.c b/mythtv/external/FFmpeg/libavcodec/tmv.c
index 2179dfbd6fe..f8d7969d40d 100644
--- a/mythtv/external/FFmpeg/libavcodec/tmv.c
+++ b/mythtv/external/FFmpeg/libavcodec/tmv.c
@@ -48,20 +48,21 @@ static int tmv_decode_frame(AVCodecContext *avctx, void *data,
     unsigned char_cols = avctx->width >> 3;
     unsigned char_rows = avctx->height >> 3;
     unsigned x, y, fg, bg, c;
+    int ret;
 
     if (tmv->pic.data[0])
         avctx->release_buffer(avctx, &tmv->pic);
 
-    if (ff_get_buffer(avctx, &tmv->pic) < 0) {
+    if ((ret = ff_get_buffer(avctx, &tmv->pic)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
-        return -1;
+        return ret;
     }
 
     if (avpkt->size < 2*char_rows*char_cols) {
         av_log(avctx, AV_LOG_ERROR,
                "Input buffer too small, truncated sample?\n");
         *got_frame = 0;
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     tmv->pic.pict_type = AV_PICTURE_TYPE_I;
@@ -70,6 +71,7 @@ static int tmv_decode_frame(AVCodecContext *avctx, void *data,
 
     tmv->pic.palette_has_changed = 1;
     memcpy(tmv->pic.data[1], ff_cga_palette, 16 * 4);
+    memset(tmv->pic.data[1] + 16 * 4, 0, AVPALETTE_SIZE - 16 * 4);
 
     for (y = 0; y < char_rows; y++) {
         for (x = 0; x < char_cols; x++) {
diff --git a/mythtv/external/FFmpeg/libavcodec/truemotion1.c b/mythtv/external/FFmpeg/libavcodec/truemotion1.c
index e2c1d2804ac..ed6b5d95cf5 100644
--- a/mythtv/external/FFmpeg/libavcodec/truemotion1.c
+++ b/mythtv/external/FFmpeg/libavcodec/truemotion1.c
@@ -34,9 +34,9 @@
 #include 
 
 #include "avcodec.h"
-#include "dsputil.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
+#include "libavutil/intreadwrite.h"
 #include "libavutil/mem.h"
 
 #include "truemotion1data.h"
@@ -308,7 +308,7 @@ static void gen_vector_table24(TrueMotion1Context *s, const uint8_t *sel_vector_
  * there was an error while decoding the header */
 static int truemotion1_decode_header(TrueMotion1Context *s)
 {
-    int i;
+    int i, ret;
     int width_shift = 0;
     int new_pix_fmt;
     struct frame_header header;
@@ -319,7 +319,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s)
     if (s->buf[0] < 0x10 || header.header_size >= s->size)
     {
         av_log(s->avctx, AV_LOG_ERROR, "invalid header size (%d)\n", s->buf[0]);
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     /* unscramble the header bytes with a XOR operation */
@@ -343,7 +343,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s)
         if (header.header_type > 3)
         {
             av_log(s->avctx, AV_LOG_ERROR, "invalid header type (%d)\n", header.header_type);
-            return -1;
+            return AVERROR_INVALIDDATA;
         } else if ((header.header_type == 2) || (header.header_type == 3)) {
             s->flags = header.flags;
             if (!(s->flags & FLAG_INTERFRAME))
@@ -371,7 +371,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s)
 
     if (header.compression >= 17) {
         av_log(s->avctx, AV_LOG_ERROR, "invalid compression type (%d)\n", header.compression);
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if ((header.deltaset != s->last_deltaset) ||
@@ -385,7 +385,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s)
             sel_vector_table = tables[header.vectable - 1];
         else {
             av_log(s->avctx, AV_LOG_ERROR, "invalid vector table id (%d)\n", header.vectable);
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
     }
 
@@ -396,8 +396,8 @@ static int truemotion1_decode_header(TrueMotion1Context *s)
         new_pix_fmt = AV_PIX_FMT_RGB555; // RGB565 is supported as well
 
     s->w >>= width_shift;
-    if (av_image_check_size(s->w, s->h, 0, s->avctx) < 0)
-        return -1;
+    if ((ret = av_image_check_size(s->w, s->h, 0, s->avctx)) < 0)
+        return ret;
 
     if (s->w != s->avctx->width || s->h != s->avctx->height ||
         new_pix_fmt != s->avctx->pix_fmt) {
@@ -860,21 +860,21 @@ static int truemotion1_decode_frame(AVCodecContext *avctx,
                                     AVPacket *avpkt)
 {
     const uint8_t *buf = avpkt->data;
-    int buf_size = avpkt->size;
+    int ret, buf_size = avpkt->size;
     TrueMotion1Context *s = avctx->priv_data;
 
     s->buf = buf;
     s->size = buf_size;
 
-    if (truemotion1_decode_header(s) == -1)
-        return -1;
+    if ((ret = truemotion1_decode_header(s)) < 0)
+        return ret;
 
     s->frame.reference = 3;
     s->frame.buffer_hints = FF_BUFFER_HINTS_VALID |
         FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
-    if (avctx->reget_buffer(avctx, &s->frame) < 0) {
+    if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0) {
         av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
-        return -1;
+        return ret;
     }
 
     if (compression_types[s->compression].algorithm == ALGO_RGB24H) {
diff --git a/mythtv/external/FFmpeg/libavcodec/truemotion2.c b/mythtv/external/FFmpeg/libavcodec/truemotion2.c
index 5ba2cf10e7d..eacd728ca41 100644
--- a/mythtv/external/FFmpeg/libavcodec/truemotion2.c
+++ b/mythtv/external/FFmpeg/libavcodec/truemotion2.c
@@ -31,14 +31,31 @@
 
 #define TM2_ESCAPE 0x80000000
 #define TM2_DELTAS 64
+
 /* Huffman-coded streams of different types of blocks */
-enum TM2_STREAMS{ TM2_C_HI = 0, TM2_C_LO, TM2_L_HI, TM2_L_LO,
-     TM2_UPD, TM2_MOT, TM2_TYPE, TM2_NUM_STREAMS};
+enum TM2_STREAMS {
+    TM2_C_HI = 0,
+    TM2_C_LO,
+    TM2_L_HI,
+    TM2_L_LO,
+    TM2_UPD,
+    TM2_MOT,
+    TM2_TYPE,
+    TM2_NUM_STREAMS
+};
+
 /* Block types */
-enum TM2_BLOCKS{ TM2_HI_RES = 0, TM2_MED_RES, TM2_LOW_RES, TM2_NULL_RES,
-                 TM2_UPDATE, TM2_STILL, TM2_MOTION};
+enum TM2_BLOCKS {
+    TM2_HI_RES = 0,
+    TM2_MED_RES,
+    TM2_LOW_RES,
+    TM2_NULL_RES,
+    TM2_UPDATE,
+    TM2_STILL,
+    TM2_MOTION
+};
 
-typedef struct TM2Context{
+typedef struct TM2Context {
     AVCodecContext *avctx;
     AVFrame pic;
 
@@ -69,7 +86,7 @@ typedef struct TM2Context{
 /**
 * Huffman codes for each of streams
 */
-typedef struct TM2Codes{
+typedef struct TM2Codes {
     VLC vlc; ///< table for FFmpeg bitstream reader
     int bits;
     int *recode; ///< table for converting from code indexes to values
@@ -79,7 +96,7 @@ typedef struct TM2Codes{
 /**
 * structure for gathering Huffman codes information
 */
-typedef struct TM2Huff{
+typedef struct TM2Huff {
     int val_bits; ///< length of literal
     int max_bits; ///< maximum length of code
     int min_bits; ///< minimum length of code
@@ -93,18 +110,20 @@ typedef struct TM2Huff{
 
 static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *huff)
 {
-    if(length > huff->max_bits) {
-        av_log(ctx->avctx, AV_LOG_ERROR, "Tree exceeded its given depth (%i)\n", huff->max_bits);
-        return -1;
+    int ret;
+    if (length > huff->max_bits) {
+        av_log(ctx->avctx, AV_LOG_ERROR, "Tree exceeded its given depth (%i)\n",
+               huff->max_bits);
+        return AVERROR_INVALIDDATA;
     }
 
-    if(!get_bits1(&ctx->gb)) { /* literal */
+    if (!get_bits1(&ctx->gb)) { /* literal */
         if (length == 0) {
             length = 1;
         }
-        if(huff->num >= huff->max_num) {
+        if (huff->num >= huff->max_num) {
             av_log(ctx->avctx, AV_LOG_DEBUG, "Too many literals\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         huff->nums[huff->num] = get_bits_long(&ctx->gb, huff->val_bits);
         huff->bits[huff->num] = prefix;
@@ -112,10 +131,10 @@ static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *
         huff->num++;
         return 0;
     } else { /* non-terminal node */
-        if(tm2_read_tree(ctx, prefix << 1, length + 1, huff) == -1)
-            return -1;
-        if(tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff) == -1)
-            return -1;
+        if ((ret = tm2_read_tree(ctx, prefix << 1, length + 1, huff)) < 0)
+            return ret;
+        if ((ret = tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff)) < 0)
+            return ret;
     }
     return 0;
 }
@@ -128,56 +147,53 @@ static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
     huff.val_bits = get_bits(&ctx->gb, 5);
     huff.max_bits = get_bits(&ctx->gb, 5);
     huff.min_bits = get_bits(&ctx->gb, 5);
-    huff.nodes = get_bits_long(&ctx->gb, 17);
-    huff.num = 0;
+    huff.nodes    = get_bits_long(&ctx->gb, 17);
+    huff.num      = 0;
 
     /* check for correct codes parameters */
-    if((huff.val_bits < 1) || (huff.val_bits > 32) ||
-       (huff.max_bits < 0) || (huff.max_bits > 25)) {
-        av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect tree parameters - literal length: %i, max code length: %i\n",
-               huff.val_bits, huff.max_bits);
-        return -1;
+    if ((huff.val_bits < 1) || (huff.val_bits > 32) ||
+        (huff.max_bits < 0) || (huff.max_bits > 25)) {
+        av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect tree parameters - literal "
+               "length: %i, max code length: %i\n", huff.val_bits, huff.max_bits);
+        return AVERROR_INVALIDDATA;
     }
-    if((huff.nodes <= 0) || (huff.nodes > 0x10000)) {
-        av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of Huffman tree nodes: %i\n", huff.nodes);
-        return -1;
+    if ((huff.nodes <= 0) || (huff.nodes > 0x10000)) {
+        av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of Huffman tree "
+               "nodes: %i\n", huff.nodes);
+        return AVERROR_INVALIDDATA;
     }
     /* one-node tree */
-    if(huff.max_bits == 0)
+    if (huff.max_bits == 0)
         huff.max_bits = 1;
 
     /* allocate space for codes - it is exactly ceil(nodes / 2) entries */
     huff.max_num = (huff.nodes + 1) >> 1;
-    huff.nums = av_mallocz(huff.max_num * sizeof(int));
-    huff.bits = av_mallocz(huff.max_num * sizeof(uint32_t));
-    huff.lens = av_mallocz(huff.max_num * sizeof(int));
+    huff.nums    = av_mallocz(huff.max_num * sizeof(int));
+    huff.bits    = av_mallocz(huff.max_num * sizeof(uint32_t));
+    huff.lens    = av_mallocz(huff.max_num * sizeof(int));
 
-    if(tm2_read_tree(ctx, 0, 0, &huff) == -1)
-        res = -1;
+    res = tm2_read_tree(ctx, 0, 0, &huff);
 
-    if(huff.num != huff.max_num) {
+    if (huff.num != huff.max_num) {
         av_log(ctx->avctx, AV_LOG_ERROR, "Got less codes than expected: %i of %i\n",
                huff.num, huff.max_num);
-        res = -1;
+        res = AVERROR_INVALIDDATA;
     }
 
     /* convert codes to vlc_table */
-    if(res != -1) {
+    if (res >= 0) {
         int i;
 
         res = init_vlc(&code->vlc, huff.max_bits, huff.max_num,
-                    huff.lens, sizeof(int), sizeof(int),
-                    huff.bits, sizeof(uint32_t), sizeof(uint32_t), 0);
-        if(res < 0) {
+                       huff.lens, sizeof(int), sizeof(int),
+                       huff.bits, sizeof(uint32_t), sizeof(uint32_t), 0);
+        if (res < 0)
             av_log(ctx->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
-            res = -1;
-        } else
-            res = 0;
-        if(res != -1) {
+        else {
             code->bits = huff.max_bits;
             code->length = huff.max_num;
             code->recode = av_malloc(code->length * sizeof(int));
-            for(i = 0; i < code->length; i++)
+            for (i = 0; i < code->length; i++)
                 code->recode[i] = huff.nums[i];
         }
     }
@@ -192,7 +208,7 @@ static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
 static void tm2_free_codes(TM2Codes *code)
 {
     av_free(code->recode);
-    if(code->vlc.table)
+    if (code->vlc.table)
         ff_free_vlc(&code->vlc);
 }
 
@@ -224,26 +240,27 @@ static inline int tm2_read_header(TM2Context *ctx, const uint8_t *buf)
     }
 }
 
-static int tm2_read_deltas(TM2Context *ctx, int stream_id) {
+static int tm2_read_deltas(TM2Context *ctx, int stream_id)
+{
     int d, mb;
     int i, v;
 
-    d = get_bits(&ctx->gb, 9);
+    d  = get_bits(&ctx->gb, 9);
     mb = get_bits(&ctx->gb, 5);
 
-    if((d < 1) || (d > TM2_DELTAS) || (mb < 1) || (mb > 32)) {
+    if ((d < 1) || (d > TM2_DELTAS) || (mb < 1) || (mb > 32)) {
         av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect delta table: %i deltas x %i bits\n", d, mb);
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
-    for(i = 0; i < d; i++) {
+    for (i = 0; i < d; i++) {
         v = get_bits_long(&ctx->gb, mb);
-        if(v & (1 << (mb - 1)))
+        if (v & (1 << (mb - 1)))
             ctx->deltas[stream_id][i] = v - (1 << mb);
         else
             ctx->deltas[stream_id][i] = v;
     }
-    for(; i < TM2_DELTAS; i++)
+    for (; i < TM2_DELTAS; i++)
         ctx->deltas[stream_id][i] = 0;
 
     return 0;
@@ -251,7 +268,7 @@ static int tm2_read_deltas(TM2Context *ctx, int stream_id) {
 
 static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, int buf_size)
 {
-    int i;
+    int i, ret;
     int skip = 0;
     int len, toks, pos;
     TM2Codes codes;
@@ -267,7 +284,7 @@ static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, i
     len  = bytestream2_get_be32(&gb);
     skip = len * 4 + 4;
 
-    if(len == 0)
+    if (len == 0)
         return 4;
 
     if (len >= INT_MAX/4-1 || len < 0 || skip > buf_size) {
@@ -276,24 +293,24 @@ static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, i
     }
 
     toks = bytestream2_get_be32(&gb);
-    if(toks & 1) {
+    if (toks & 1) {
         len = bytestream2_get_be32(&gb);
-        if(len == TM2_ESCAPE) {
+        if (len == TM2_ESCAPE) {
             len = bytestream2_get_be32(&gb);
         }
-        if(len > 0) {
+        if (len > 0) {
             pos = bytestream2_tell(&gb);
             if (skip <= pos)
                 return AVERROR_INVALIDDATA;
             init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8);
-            if(tm2_read_deltas(ctx, stream_id) == -1)
-                return AVERROR_INVALIDDATA;
+            if ((ret = tm2_read_deltas(ctx, stream_id)) < 0)
+                return ret;
             bytestream2_skip(&gb, ((get_bits_count(&ctx->gb) + 31) >> 5) << 2);
         }
     }
     /* skip unused fields */
     len = bytestream2_get_be32(&gb);
-    if(len == TM2_ESCAPE) { /* some unknown length - could be escaped too */
+    if (len == TM2_ESCAPE) { /* some unknown length - could be escaped too */
         bytestream2_skip(&gb, 8); /* unused by decoder */
     } else {
         bytestream2_skip(&gb, 4); /* unused by decoder */
@@ -303,26 +320,26 @@ static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, i
     if (skip <= pos)
         return AVERROR_INVALIDDATA;
     init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8);
-    if(tm2_build_huff_table(ctx, &codes) == -1)
-        return AVERROR_INVALIDDATA;
+    if ((ret = tm2_build_huff_table(ctx, &codes)) < 0)
+        return ret;
     bytestream2_skip(&gb, ((get_bits_count(&ctx->gb) + 31) >> 5) << 2);
 
     toks >>= 1;
     /* check if we have sane number of tokens */
-    if((toks < 0) || (toks > 0xFFFFFF)){
+    if ((toks < 0) || (toks > 0xFFFFFF)) {
         av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of tokens: %i\n", toks);
         tm2_free_codes(&codes);
         return AVERROR_INVALIDDATA;
     }
-    ctx->tokens[stream_id] = av_realloc(ctx->tokens[stream_id], toks * sizeof(int));
+    ctx->tokens[stream_id]   = av_realloc(ctx->tokens[stream_id], toks * sizeof(int));
     ctx->tok_lens[stream_id] = toks;
     len = bytestream2_get_be32(&gb);
-    if(len > 0) {
+    if (len > 0) {
         pos = bytestream2_tell(&gb);
         if (skip <= pos)
             return AVERROR_INVALIDDATA;
         init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8);
-        for(i = 0; i < toks; i++) {
+        for (i = 0; i < toks; i++) {
             if (get_bits_left(&ctx->gb) <= 0) {
                 av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of tokens: %i\n", toks);
                 return AVERROR_INVALIDDATA;
@@ -335,7 +352,7 @@ static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, i
             }
         }
     } else {
-        for(i = 0; i < toks; i++) {
+        for (i = 0; i < toks; i++) {
             ctx->tokens[stream_id][i] = codes.recode[0];
             if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >= TM2_DELTAS) {
                 av_log(ctx->avctx, AV_LOG_ERROR, "Invalid delta token index %d for type %d, n=%d\n",
@@ -349,12 +366,13 @@ static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, i
     return skip;
 }
 
-static inline int GET_TOK(TM2Context *ctx,int type) {
-    if(ctx->tok_ptrs[type] >= ctx->tok_lens[type]) {
+static inline int GET_TOK(TM2Context *ctx,int type)
+{
+    if (ctx->tok_ptrs[type] >= ctx->tok_lens[type]) {
         av_log(ctx->avctx, AV_LOG_ERROR, "Read token from stream %i out of bounds (%i>=%i)\n", type, ctx->tok_ptrs[type], ctx->tok_lens[type]);
         return 0;
     }
-    if(type <= TM2_MOT) {
+    if (type <= TM2_MOT) {
         if (ctx->tokens[type][ctx->tok_ptrs[type]] >= TM2_DELTAS) {
             av_log(ctx->avctx, AV_LOG_ERROR, "token %d is too large\n", ctx->tokens[type][ctx->tok_ptrs[type]]);
             return 0;
@@ -406,15 +424,15 @@ static inline void tm2_apply_deltas(TM2Context *ctx, int* Y, int stride, int *de
     int ct, d;
     int i, j;
 
-    for(j = 0; j < 4; j++){
+    for (j = 0; j < 4; j++){
         ct = ctx->D[j];
-        for(i = 0; i < 4; i++){
-            d = deltas[i + j * 4];
-            ct += d;
+        for (i = 0; i < 4; i++){
+            d        = deltas[i + j * 4];
+            ct      += d;
             last[i] += ct;
-            Y[i] = av_clip_uint8(last[i]);
+            Y[i]     = av_clip_uint8(last[i]);
         }
-        Y += stride;
+        Y        += stride;
         ctx->D[j] = ct;
     }
 }
@@ -422,11 +440,11 @@ static inline void tm2_apply_deltas(TM2Context *ctx, int* Y, int stride, int *de
 static inline void tm2_high_chroma(int *data, int stride, int *last, int *CD, int *deltas)
 {
     int i, j;
-    for(j = 0; j < 2; j++){
-        for(i = 0; i < 2; i++){
-            CD[j] += deltas[i + j * 2];
+    for (j = 0; j < 2; j++) {
+        for (i = 0; i < 2; i++)  {
+            CD[j]   += deltas[i + j * 2];
             last[i] += CD[j];
-            data[i] = last[i];
+            data[i]  = last[i];
         }
         data += stride;
     }
@@ -438,14 +456,14 @@ static inline void tm2_low_chroma(int *data, int stride, int *clast, int *CD, in
     int l;
     int prev;
 
-    if(bx > 0)
+    if (bx > 0)
         prev = clast[-3];
     else
         prev = 0;
-    t = (CD[0] + CD[1]) >> 1;
-    l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
-    CD[1] = CD[0] + CD[1] - t;
-    CD[0] = t;
+    t        = (CD[0] + CD[1]) >> 1;
+    l        = (prev - CD[0] - CD[1] + clast[1]) >> 1;
+    CD[1]    = CD[0] + CD[1] - t;
+    CD[0]    = t;
     clast[0] = l;
 
     tm2_high_chroma(data, stride, clast, CD, deltas);
@@ -458,15 +476,15 @@ static inline void tm2_hi_res_block(TM2Context *ctx, AVFrame *pic, int bx, int b
     TM2_INIT_POINTERS();
 
     /* hi-res chroma */
-    for(i = 0; i < 4; i++) {
-        deltas[i] = GET_TOK(ctx, TM2_C_HI);
+    for (i = 0; i < 4; i++) {
+        deltas[i]     = GET_TOK(ctx, TM2_C_HI);
         deltas[i + 4] = GET_TOK(ctx, TM2_C_HI);
     }
-    tm2_high_chroma(U, Ustride, clast, ctx->CD, deltas);
+    tm2_high_chroma(U, Ustride, clast,     ctx->CD,     deltas);
     tm2_high_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas + 4);
 
     /* hi-res luma */
-    for(i = 0; i < 16; i++)
+    for (i = 0; i < 16; i++)
         deltas[i] = GET_TOK(ctx, TM2_L_HI);
 
     tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
@@ -488,7 +506,7 @@ static inline void tm2_med_res_block(TM2Context *ctx, AVFrame *pic, int bx, int
     tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
 
     /* hi-res luma */
-    for(i = 0; i < 16; i++)
+    for (i = 0; i < 16; i++)
         deltas[i] = GET_TOK(ctx, TM2_L_HI);
 
     tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
@@ -511,7 +529,7 @@ static inline void tm2_low_res_block(TM2Context *ctx, AVFrame *pic, int bx, int
     tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
 
     /* low-res luma */
-    for(i = 0; i < 16; i++)
+    for (i = 0; i < 16; i++)
         deltas[i] = 0;
 
     deltas[ 0] = GET_TOK(ctx, TM2_L_LO);
@@ -519,7 +537,7 @@ static inline void tm2_low_res_block(TM2Context *ctx, AVFrame *pic, int bx, int
     deltas[ 8] = GET_TOK(ctx, TM2_L_LO);
     deltas[10] = GET_TOK(ctx, TM2_L_LO);
 
-    if(bx > 0)
+    if (bx > 0)
         last[0] = (last[-1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3] + last[1]) >> 1;
     else
         last[0] = (last[1]  - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3])>> 1;
@@ -551,18 +569,18 @@ static inline void tm2_null_res_block(TM2Context *ctx, AVFrame *pic, int bx, int
     tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
 
     /* null luma */
-    for(i = 0; i < 16; i++)
+    for (i = 0; i < 16; i++)
         deltas[i] = 0;
 
     ct = ctx->D[0] + ctx->D[1] + ctx->D[2] + ctx->D[3];
 
-    if(bx > 0)
+    if (bx > 0)
         left = last[-1] - ct;
     else
         left = 0;
 
-    right = last[3];
-    diff = right - left;
+    right   = last[3];
+    diff    = right - left;
     last[0] = left + (diff >> 2);
     last[1] = left + (diff >> 1);
     last[2] = right - (diff >> 2);
@@ -571,11 +589,11 @@ static inline void tm2_null_res_block(TM2Context *ctx, AVFrame *pic, int bx, int
         int tp = left;
 
         ctx->D[0] = (tp + (ct >> 2)) - left;
-        left += ctx->D[0];
+        left     += ctx->D[0];
         ctx->D[1] = (tp + (ct >> 1)) - left;
-        left += ctx->D[1];
+        left     += ctx->D[1];
         ctx->D[2] = ((tp + ct) - (ct >> 2)) - left;
-        left += ctx->D[2];
+        left     += ctx->D[2];
         ctx->D[3] = (tp + ct) - left;
     }
     tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
@@ -587,12 +605,12 @@ static inline void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by
     TM2_INIT_POINTERS_2();
 
     /* update chroma */
-    for(j = 0; j < 2; j++){
-        for(i = 0; i < 2; i++){
+    for (j = 0; j < 2; j++) {
+        for (i = 0; i < 2; i++){
             U[i] = Uo[i];
             V[i] = Vo[i];
         }
-        U += Ustride; V += Vstride;
+        U  += Ustride; V += Vstride;
         Uo += oUstride; Vo += oVstride;
     }
     U -= Ustride * 2;
@@ -606,12 +624,12 @@ static inline void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by
     ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
     ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
 
-    for(j = 0; j < 4; j++){
-        for(i = 0; i < 4; i++){
-            Y[i] = Yo[i];
+    for (j = 0; j < 4; j++) {
+        for (i = 0; i < 4; i++) {
+            Y[i]    = Yo[i];
             last[i] = Yo[i];
         }
-        Y += Ystride;
+        Y  += Ystride;
         Yo += oYstride;
     }
 }
@@ -623,13 +641,15 @@ static inline void tm2_update_block(TM2Context *ctx, AVFrame *pic, int bx, int b
     TM2_INIT_POINTERS_2();
 
     /* update chroma */
-    for(j = 0; j < 2; j++){
-        for(i = 0; i < 2; i++){
+    for (j = 0; j < 2; j++) {
+        for (i = 0; i < 2; i++) {
             U[i] = Uo[i] + GET_TOK(ctx, TM2_UPD);
             V[i] = Vo[i] + GET_TOK(ctx, TM2_UPD);
         }
-        U += Ustride; V += Vstride;
-        Uo += oUstride; Vo += oVstride;
+        U  += Ustride;
+        V  += Vstride;
+        Uo += oUstride;
+        Vo += oVstride;
     }
     U -= Ustride * 2;
     V -= Vstride * 2;
@@ -642,14 +662,14 @@ static inline void tm2_update_block(TM2Context *ctx, AVFrame *pic, int bx, int b
     ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
     ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
 
-    for(j = 0; j < 4; j++){
+    for (j = 0; j < 4; j++) {
         d = last[3];
-        for(i = 0; i < 4; i++){
-            Y[i] = Yo[i] + GET_TOK(ctx, TM2_UPD);
+        for (i = 0; i < 4; i++) {
+            Y[i]    = Yo[i] + GET_TOK(ctx, TM2_UPD);
             last[i] = Y[i];
         }
         ctx->D[j] = last[3] - d;
-        Y += Ystride;
+        Y  += Ystride;
         Yo += oYstride;
     }
 }
@@ -675,13 +695,15 @@ static inline void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int b
     Vo += (my >> 1) * oVstride + (mx >> 1);
 
     /* copy chroma */
-    for(j = 0; j < 2; j++){
-        for(i = 0; i < 2; i++){
+    for (j = 0; j < 2; j++) {
+        for (i = 0; i < 2; i++) {
             U[i] = Uo[i];
             V[i] = Vo[i];
         }
-        U += Ustride; V += Vstride;
-        Uo += oUstride; Vo += oVstride;
+        U  += Ustride;
+        V  += Vstride;
+        Uo += oUstride;
+        Vo += oVstride;
     }
     U -= Ustride * 2;
     V -= Vstride * 2;
@@ -689,11 +711,11 @@ static inline void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int b
     TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
 
     /* copy luma */
-    for(j = 0; j < 4; j++){
-        for(i = 0; i < 4; i++){
+    for (j = 0; j < 4; j++) {
+        for (i = 0; i < 4; i++) {
             Y[i] = Yo[i];
         }
-        Y += Ystride;
+        Y  += Ystride;
         Yo += oYstride;
     }
     /* calculate deltas */
@@ -702,7 +724,7 @@ static inline void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int b
     ctx->D[1] = Y[3 + Ystride] - Y[3];
     ctx->D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
     ctx->D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
-    for(i = 0; i < 4; i++)
+    for (i = 0; i < 4; i++)
         last[i] = Y[i + Ystride * 3];
 }
 
@@ -715,21 +737,21 @@ static int tm2_decode_blocks(TM2Context *ctx, AVFrame *p)
     int *Y, *U, *V;
     uint8_t *dst;
 
-    for(i = 0; i < TM2_NUM_STREAMS; i++)
+    for (i = 0; i < TM2_NUM_STREAMS; i++)
         ctx->tok_ptrs[i] = 0;
 
-    if (ctx->tok_lens[TM2_TYPE]tok_lens[TM2_TYPE]avctx,AV_LOG_ERROR,"Got %i tokens for %i blocks\n",ctx->tok_lens[TM2_TYPE],bw*bh);
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     memset(ctx->last, 0, 4 * bw * sizeof(int));
     memset(ctx->clast, 0, 4 * bw * sizeof(int));
 
-    for(j = 0; j < bh; j++) {
+    for (j = 0; j < bh; j++) {
         memset(ctx->D, 0, 4 * sizeof(int));
         memset(ctx->CD, 0, 4 * sizeof(int));
-        for(i = 0; i < bw; i++) {
+        for (i = 0; i < bw; i++) {
             type = GET_TOK(ctx, TM2_TYPE);
             switch(type) {
             case TM2_HI_RES:
@@ -767,8 +789,8 @@ static int tm2_decode_blocks(TM2Context *ctx, AVFrame *p)
     U = (ctx->cur?ctx->U2:ctx->U1);
     V = (ctx->cur?ctx->V2:ctx->V1);
     dst = p->data[0];
-    for(j = 0; j < h; j++){
-        for(i = 0; i < w; i++){
+    for (j = 0; j < h; j++) {
+        for (i = 0; i < w; i++) {
             int y = Y[i], u = U[i >> 1], v = V[i >> 1];
             dst[3*i+0] = av_clip_uint8(y + v);
             dst[3*i+1] = av_clip_uint8(y);
@@ -832,20 +854,21 @@ static int decode_frame(AVCodecContext *avctx,
                         void *data, int *got_frame,
                         AVPacket *avpkt)
 {
-    const uint8_t *buf = avpkt->data;
-    int buf_size = avpkt->size & ~3;
     TM2Context * const l = avctx->priv_data;
-    AVFrame * const p = &l->pic;
-    int i, offset = TM2_HEADER_SIZE, t, ret;
+    const uint8_t *buf   = avpkt->data;
+    int buf_size         = avpkt->size & ~3;
+    AVFrame * const p    = &l->pic;
+    int offset           = TM2_HEADER_SIZE;
+    int i, t, ret;
 
     av_fast_padded_malloc(&l->buffer, &l->buffer_size, buf_size);
-    if(!l->buffer){
+    if (!l->buffer) {
         av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
         return AVERROR(ENOMEM);
     }
     p->reference = 3;
     p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
-    if((ret = avctx->reget_buffer(avctx, p)) < 0){
+    if ((ret = avctx->reget_buffer(avctx, p)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
@@ -856,7 +879,7 @@ static int decode_frame(AVCodecContext *avctx,
         return ret;
     }
 
-    for(i = 0; i < TM2_NUM_STREAMS; i++){
+    for (i = 0; i < TM2_NUM_STREAMS; i++) {
         if (offset >= buf_size) {
             av_log(avctx, AV_LOG_ERROR, "no space for tm2_read_stream\n");
             return AVERROR_INVALIDDATA;
@@ -864,13 +887,15 @@ static int decode_frame(AVCodecContext *avctx,
 
         t = tm2_read_stream(l, l->buffer + offset, tm2_stream_order[i],
                             buf_size - offset);
-        if(t < 0){
+        if (t < 0) {
+            int j = tm2_stream_order[i];
+            memset(l->tokens[j], 0, sizeof(**l->tokens) * l->tok_lens[j]);
             return t;
         }
         offset += t;
     }
     p->key_frame = tm2_decode_blocks(l, p);
-    if(p->key_frame)
+    if (p->key_frame)
         p->pict_type = AV_PICTURE_TYPE_I;
     else
         p->pict_type = AV_PICTURE_TYPE_P;
@@ -882,17 +907,18 @@ static int decode_frame(AVCodecContext *avctx,
     return buf_size;
 }
 
-static av_cold int decode_init(AVCodecContext *avctx){
+static av_cold int decode_init(AVCodecContext *avctx)
+{
     TM2Context * const l = avctx->priv_data;
     int i, w = avctx->width, h = avctx->height;
 
-    if((avctx->width & 3) || (avctx->height & 3)){
+    if ((avctx->width & 3) || (avctx->height & 3)) {
         av_log(avctx, AV_LOG_ERROR, "Width and height must be multiple of 4\n");
-        return AVERROR_INVALIDDATA;
+        return AVERROR(EINVAL);
     }
 
-    l->avctx = avctx;
-    l->pic.data[0]=NULL;
+    l->avctx       = avctx;
+    l->pic.data[0] = NULL;
     avctx->pix_fmt = AV_PIX_FMT_BGR24;
     avcodec_get_frame_defaults(&l->pic);
 
@@ -901,22 +927,22 @@ static av_cold int decode_init(AVCodecContext *avctx){
     l->last  = av_malloc(4 * sizeof(*l->last)  * (w >> 2));
     l->clast = av_malloc(4 * sizeof(*l->clast) * (w >> 2));
 
-    for(i = 0; i < TM2_NUM_STREAMS; i++) {
+    for (i = 0; i < TM2_NUM_STREAMS; i++) {
         l->tokens[i] = NULL;
         l->tok_lens[i] = 0;
     }
 
     w += 8;
     h += 8;
-    l->Y1_base = av_malloc(sizeof(*l->Y1_base) * w * h);
-    l->Y2_base = av_malloc(sizeof(*l->Y2_base) * w * h);
+    l->Y1_base = av_mallocz(sizeof(*l->Y1_base) * w * h);
+    l->Y2_base = av_mallocz(sizeof(*l->Y2_base) * w * h);
     l->y_stride = w;
     w = (w + 1) >> 1;
     h = (h + 1) >> 1;
-    l->U1_base = av_malloc(sizeof(*l->U1_base) * w * h);
-    l->V1_base = av_malloc(sizeof(*l->V1_base) * w * h);
-    l->U2_base = av_malloc(sizeof(*l->U2_base) * w * h);
-    l->V2_base = av_malloc(sizeof(*l->V1_base) * w * h);
+    l->U1_base = av_mallocz(sizeof(*l->U1_base) * w * h);
+    l->V1_base = av_mallocz(sizeof(*l->V1_base) * w * h);
+    l->U2_base = av_mallocz(sizeof(*l->U2_base) * w * h);
+    l->V2_base = av_mallocz(sizeof(*l->V1_base) * w * h);
     l->uv_stride = w;
     l->cur = 0;
     if (!l->Y1_base || !l->Y2_base || !l->U1_base ||
@@ -942,16 +968,17 @@ static av_cold int decode_init(AVCodecContext *avctx){
     return 0;
 }
 
-static av_cold int decode_end(AVCodecContext *avctx){
+static av_cold int decode_end(AVCodecContext *avctx)
+{
     TM2Context * const l = avctx->priv_data;
     AVFrame *pic = &l->pic;
     int i;
 
     av_free(l->last);
     av_free(l->clast);
-    for(i = 0; i < TM2_NUM_STREAMS; i++)
+    for (i = 0; i < TM2_NUM_STREAMS; i++)
         av_free(l->tokens[i]);
-    if(l->Y1){
+    if (l->Y1) {
         av_free(l->Y1_base);
         av_free(l->U1_base);
         av_free(l->V1_base);
diff --git a/mythtv/external/FFmpeg/libavcodec/truespeech.c b/mythtv/external/FFmpeg/libavcodec/truespeech.c
index edaaea686af..fea9ae41950 100644
--- a/mythtv/external/FFmpeg/libavcodec/truespeech.c
+++ b/mythtv/external/FFmpeg/libavcodec/truespeech.c
@@ -36,7 +36,6 @@
  * TrueSpeech decoder context
  */
 typedef struct {
-    AVFrame frame;
     DSPContext dsp;
     /* input data */
     DECLARE_ALIGNED(16, uint8_t, buffer)[32];
@@ -73,9 +72,6 @@ static av_cold int truespeech_decode_init(AVCodecContext * avctx)
 
     ff_dsputil_init(&c->dsp, avctx);
 
-    avcodec_get_frame_defaults(&c->frame);
-    avctx->coded_frame = &c->frame;
-
     return 0;
 }
 
@@ -310,6 +306,7 @@ static void truespeech_save_prevvec(TSContext *c)
 static int truespeech_decode_frame(AVCodecContext *avctx, void *data,
                                    int *got_frame_ptr, AVPacket *avpkt)
 {
+    AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     TSContext *c = avctx->priv_data;
@@ -327,12 +324,12 @@ static int truespeech_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     /* get output buffer */
-    c->frame.nb_samples = iterations * 240;
-    if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) {
+    frame->nb_samples = iterations * 240;
+    if ((ret = ff_get_buffer(avctx, frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
-    samples = (int16_t *)c->frame.data[0];
+    samples = (int16_t *)frame->data[0];
 
     memset(samples, 0, iterations * 240 * sizeof(*samples));
 
@@ -354,8 +351,7 @@ static int truespeech_decode_frame(AVCodecContext *avctx, void *data,
         truespeech_save_prevvec(c);
     }
 
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = c->frame;
+    *got_frame_ptr = 1;
 
     return buf_size;
 }
diff --git a/mythtv/external/FFmpeg/libavcodec/tscc.c b/mythtv/external/FFmpeg/libavcodec/tscc.c
index 2aca0ba3b00..7c2d2319bb1 100644
--- a/mythtv/external/FFmpeg/libavcodec/tscc.c
+++ b/mythtv/external/FFmpeg/libavcodec/tscc.c
@@ -44,10 +44,6 @@
 
 #include 
 
-
-/*
- * Decoder context
- */
 typedef struct TsccContext {
 
     AVCodecContext *avctx;
@@ -66,11 +62,6 @@ typedef struct TsccContext {
     uint32_t pal[256];
 } CamtasiaContext;
 
-/*
- *
- * Decode a frame
- *
- */
 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
                         AVPacket *avpkt)
 {
@@ -83,7 +74,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 
     c->pic.reference = 3;
     c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
-    if((ret = avctx->reget_buffer(avctx, &c->pic)) < 0){
+    if ((ret = avctx->reget_buffer(avctx, &c->pic)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
@@ -91,7 +82,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     zret = inflateReset(&c->zstream);
     if (zret != Z_OK) {
         av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
-        return AVERROR(EINVAL);
+        return AVERROR_UNKNOWN;
     }
     c->zstream.next_in = (uint8_t*)encoded;
     c->zstream.avail_in = len;
@@ -101,7 +92,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     // Z_DATA_ERROR means empty picture
     if ((zret != Z_OK) && (zret != Z_STREAM_END) && (zret != Z_DATA_ERROR)) {
         av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret);
-        return AVERROR(EINVAL);
+        return AVERROR_UNKNOWN;
     }
 
 
@@ -129,13 +120,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     return buf_size;
 }
 
-
-
-/*
- *
- * Init tscc decoder
- *
- */
 static av_cold int decode_init(AVCodecContext *avctx)
 {
     CamtasiaContext * const c = avctx->priv_data;
@@ -176,19 +160,12 @@ static av_cold int decode_init(AVCodecContext *avctx)
     zret = inflateInit(&c->zstream);
     if (zret != Z_OK) {
         av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
-        return AVERROR(ENOMEM);
+        return AVERROR_UNKNOWN;
     }
 
     return 0;
 }
 
-
-
-/*
- *
- * Uninit tscc decoder
- *
- */
 static av_cold int decode_end(AVCodecContext *avctx)
 {
     CamtasiaContext * const c = avctx->priv_data;
diff --git a/mythtv/external/FFmpeg/libavcodec/tta.c b/mythtv/external/FFmpeg/libavcodec/tta.c
index 09dc0468092..4240946aa26 100644
--- a/mythtv/external/FFmpeg/libavcodec/tta.c
+++ b/mythtv/external/FFmpeg/libavcodec/tta.c
@@ -34,6 +34,8 @@
 #include "get_bits.h"
 #include "internal.h"
 #include "libavutil/crc.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
 
 #define FORMAT_SIMPLE    1
 #define FORMAT_ENCRYPTED 2
@@ -57,8 +59,8 @@ typedef struct TTAChannel {
 } TTAChannel;
 
 typedef struct TTAContext {
+    AVClass *class;
     AVCodecContext *avctx;
-    AVFrame frame;
     GetBitContext gb;
     const AVCRC *crc_table;
 
@@ -68,6 +70,8 @@ typedef struct TTAContext {
 
     int32_t *decode_buffer;
 
+    uint8_t crc_pass[8];
+    uint8_t *pass;
     TTAChannel *ch_ctx;
 } TTAContext;
 
@@ -93,8 +97,13 @@ static const int32_t ttafilter_configs[4] = {
     12
 };
 
-static void ttafilter_init(TTAFilter *c, int32_t shift) {
+static void ttafilter_init(TTAContext *s, TTAFilter *c, int32_t shift) {
     memset(c, 0, sizeof(TTAFilter));
+    if (s->format == FORMAT_ENCRYPTED) {
+        int i;
+        for (i = 0; i < 8; i++)
+            c->qm[i] = sign_extend(s->crc_pass[i], 8);
+    }
     c->shift = shift;
    c->round = shift_1[shift-1];
 //    c->round = 1 << (shift - 1);
@@ -173,6 +182,21 @@ static int tta_check_crc(TTAContext *s, const uint8_t *buf, int buf_size)
     return 0;
 }
 
+static uint64_t tta_check_crc64(uint8_t *pass)
+{
+    uint64_t crc = UINT64_MAX, poly = 0x42F0E1EBA9EA3693U;
+    uint8_t *end = pass + strlen(pass);
+    int i;
+
+    while (pass < end) {
+        crc ^= (uint64_t)*pass++ << 56;
+        for (i = 0; i < 8; i++)
+            crc = (crc << 1) ^ (poly & (((int64_t) crc) >> 63));
+    }
+
+    return crc ^ UINT64_MAX;
+}
+
 static av_cold int tta_decode_init(AVCodecContext * avctx)
 {
     TTAContext *s = avctx->priv_data;
@@ -197,12 +221,15 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
 
         s->format = get_bits(&s->gb, 16);
         if (s->format > 2) {
-            av_log(s->avctx, AV_LOG_ERROR, "Invalid format\n");
+            av_log(avctx, AV_LOG_ERROR, "Invalid format\n");
             return AVERROR_INVALIDDATA;
         }
         if (s->format == FORMAT_ENCRYPTED) {
-            av_log_missing_feature(s->avctx, "Encrypted TTA", 0);
-            return AVERROR_PATCHWELCOME;
+            if (!s->pass) {
+                av_log(avctx, AV_LOG_ERROR, "Missing password for encrypted stream. Please use the -password option\n");
+                return AVERROR(EINVAL);
+            }
+            AV_WL64(s->crc_pass, tta_check_crc64(s->pass));
         }
         avctx->channels = s->channels = get_bits(&s->gb, 16);
         if (s->channels > 1 && s->channels < 9)
@@ -214,10 +241,10 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
         skip_bits_long(&s->gb, 32); // CRC32 of header
 
         if (s->channels == 0) {
-            av_log(s->avctx, AV_LOG_ERROR, "Invalid number of channels\n");
+            av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
             return AVERROR_INVALIDDATA;
         } else if (avctx->sample_rate == 0) {
-            av_log(s->avctx, AV_LOG_ERROR, "Invalid samplerate\n");
+            av_log(avctx, AV_LOG_ERROR, "Invalid samplerate\n");
             return AVERROR_INVALIDDATA;
         }
 
@@ -246,10 +273,10 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
         total_frames = s->data_length / s->frame_length +
                        (s->last_frame_length ? 1 : 0);
 
-        av_log(s->avctx, AV_LOG_DEBUG, "format: %d chans: %d bps: %d rate: %d block: %d\n",
+        av_log(avctx, AV_LOG_DEBUG, "format: %d chans: %d bps: %d rate: %d block: %d\n",
             s->format, avctx->channels, avctx->bits_per_coded_sample, avctx->sample_rate,
             avctx->block_align);
-        av_log(s->avctx, AV_LOG_DEBUG, "data_length: %d frame_length: %d last: %d total: %d\n",
+        av_log(avctx, AV_LOG_DEBUG, "data_length: %d frame_length: %d last: %d total: %d\n",
             s->data_length, s->frame_length, s->last_frame_length, total_frames);
 
         // FIXME: seek table
@@ -284,15 +311,13 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
         return AVERROR_INVALIDDATA;
     }
 
-    avcodec_get_frame_defaults(&s->frame);
-    avctx->coded_frame = &s->frame;
-
     return 0;
 }
 
 static int tta_decode_frame(AVCodecContext *avctx, void *data,
                             int *got_frame_ptr, AVPacket *avpkt)
 {
+    AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     TTAContext *s = avctx->priv_data;
@@ -308,20 +333,20 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
     init_get_bits(&s->gb, buf, buf_size*8);
 
     /* get output buffer */
-    s->frame.nb_samples = framelen;
-    if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
+    frame->nb_samples = framelen;
+    if ((ret = ff_get_buffer(avctx, frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
 
     // decode directly to output buffer for 24-bit sample format
     if (s->bps == 3)
-        s->decode_buffer = (int32_t *)s->frame.data[0];
+        s->decode_buffer = (int32_t *)frame->data[0];
 
     // init per channel states
     for (i = 0; i < s->channels; i++) {
         s->ch_ctx[i].predictor = 0;
-        ttafilter_init(&s->ch_ctx[i].filter, ttafilter_configs[s->bps-1]);
+        ttafilter_init(s, &s->ch_ctx[i].filter, ttafilter_configs[s->bps-1]);
         rice_init(&s->ch_ctx[i].rice, 10, 10);
     }
 
@@ -405,7 +430,7 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
             i++;
             // check for last frame
             if (i == s->last_frame_length && get_bits_left(&s->gb) / 8 == 4) {
-                s->frame.nb_samples = framelen = s->last_frame_length;
+                frame->nb_samples = framelen = s->last_frame_length;
                 break;
             }
         }
@@ -421,20 +446,20 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
     // convert to output buffer
     switch (s->bps) {
     case 1: {
-        uint8_t *samples = (uint8_t *)s->frame.data[0];
+        uint8_t *samples = (uint8_t *)frame->data[0];
         for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++)
             *samples++ = *p + 0x80;
         break;
         }
     case 2: {
-        int16_t *samples = (int16_t *)s->frame.data[0];
+        int16_t *samples = (int16_t *)frame->data[0];
         for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++)
             *samples++ = *p;
         break;
         }
     case 3: {
         // shift samples for 24-bit sample format
-        int32_t *samples = (int32_t *)s->frame.data[0];
+        int32_t *samples = (int32_t *)frame->data[0];
         for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++)
             *samples++ <<= 8;
         // reset decode buffer
@@ -443,8 +468,7 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
         }
     }
 
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = s->frame;
+    *got_frame_ptr = 1;
 
     return buf_size;
 error:
@@ -465,6 +489,20 @@ static av_cold int tta_decode_close(AVCodecContext *avctx) {
     return 0;
 }
 
+#define OFFSET(x) offsetof(TTAContext, x)
+#define DEC (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
+static const AVOption options[] = {
+    { "password", "Set decoding password", OFFSET(pass), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, DEC },
+    { NULL },
+};
+
+static const AVClass tta_decoder_class = {
+    .class_name = "TTA Decoder",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 AVCodec ff_tta_decoder = {
     .name           = "tta",
     .type           = AVMEDIA_TYPE_AUDIO,
@@ -475,4 +513,5 @@ AVCodec ff_tta_decoder = {
     .decode         = tta_decode_frame,
     .capabilities   = CODEC_CAP_DR1,
     .long_name      = NULL_IF_CONFIG_SMALL("TTA (True Audio)"),
+    .priv_class     = &tta_decoder_class,
 };
diff --git a/mythtv/external/FFmpeg/libavcodec/twinvq.c b/mythtv/external/FFmpeg/libavcodec/twinvq.c
index b34f159485e..e9d206e2902 100644
--- a/mythtv/external/FFmpeg/libavcodec/twinvq.c
+++ b/mythtv/external/FFmpeg/libavcodec/twinvq.c
@@ -23,7 +23,6 @@
 #include "libavutil/float_dsp.h"
 #include "avcodec.h"
 #include "get_bits.h"
-#include "dsputil.h"
 #include "fft.h"
 #include "internal.h"
 #include "lsp.h"
@@ -177,8 +176,6 @@ static const ModeTab mode_44_48 = {
 
 typedef struct TwinContext {
     AVCodecContext *avctx;
-    AVFrame frame;
-    DSPContext      dsp;
     AVFloatDSPContext fdsp;
     FFTContext mdct_ctx[3];
 
@@ -650,11 +647,10 @@ static void imdct_and_window(TwinContext *tctx, enum FrameType ftype, int wtype,
 
         mdct->imdct_half(mdct, buf1 + bsize*j, in + bsize*j);
 
-        tctx->dsp.vector_fmul_window(out2,
-                                     prev_buf + (bsize-wsize)/2,
-                                     buf1 + bsize*j,
-                                     ff_sine_windows[av_log2(wsize)],
-                                     wsize/2);
+        tctx->fdsp.vector_fmul_window(out2, prev_buf + (bsize-wsize) / 2,
+                                      buf1 + bsize * j,
+                                      ff_sine_windows[av_log2(wsize)],
+                                      wsize / 2);
         out2 += wsize;
 
         memcpy(out2, buf1 + bsize*j + wsize/2, (bsize - wsize/2)*sizeof(float));
@@ -694,7 +690,7 @@ static void imdct_output(TwinContext *tctx, enum FrameType ftype, int wtype,
     if (tctx->avctx->channels == 2) {
         memcpy(&out[1][0],     &prev_buf[2*mtab->size],         size1 * sizeof(out[1][0]));
         memcpy(&out[1][size1], &tctx->curr_frame[2*mtab->size], size2 * sizeof(out[1][0]));
-        tctx->dsp.butterflies_float(out[0], out[1], mtab->size);
+        tctx->fdsp.butterflies_float(out[0], out[1], mtab->size);
     }
 }
 
@@ -813,6 +809,7 @@ static void read_and_decode_spectrum(TwinContext *tctx, GetBitContext *gb,
 static int twin_decode_frame(AVCodecContext * avctx, void *data,
                              int *got_frame_ptr, AVPacket *avpkt)
 {
+    AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     TwinContext *tctx = avctx->priv_data;
@@ -834,12 +831,12 @@ static int twin_decode_frame(AVCodecContext * avctx, void *data,
 
     /* get output buffer */
     if (tctx->discarded_packets >= 2) {
-        tctx->frame.nb_samples = mtab->size;
-        if ((ret = ff_get_buffer(avctx, &tctx->frame)) < 0) {
+        frame->nb_samples = mtab->size;
+        if ((ret = ff_get_buffer(avctx, frame)) < 0) {
             av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
             return ret;
         }
-        out = (float **)tctx->frame.extended_data;
+        out = (float **)frame->extended_data;
     }
 
     init_get_bits(&gb, buf, buf_size * 8);
@@ -865,8 +862,7 @@ static int twin_decode_frame(AVCodecContext * avctx, void *data,
         return buf_size;
     }
 
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = tctx->frame;
+    *got_frame_ptr = 1;
 
     return buf_size;
 }
@@ -1163,7 +1159,6 @@ static av_cold int twin_decode_init(AVCodecContext *avctx)
         return -1;
     }
 
-    ff_dsputil_init(&tctx->dsp, avctx);
     avpriv_float_dsp_init(&tctx->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
     if ((ret = init_mdct_win(tctx))) {
         av_log(avctx, AV_LOG_ERROR, "Error initializing MDCT\n");
@@ -1174,9 +1169,6 @@ static av_cold int twin_decode_init(AVCodecContext *avctx)
 
     memset_float(tctx->bark_hist[0][0], 0.1, FF_ARRAY_ELEMS(tctx->bark_hist));
 
-    avcodec_get_frame_defaults(&tctx->frame);
-    avctx->coded_frame = &tctx->frame;
-
     return 0;
 }
 
diff --git a/mythtv/external/FFmpeg/libavcodec/txd.c b/mythtv/external/FFmpeg/libavcodec/txd.c
index 2dd82598a4a..b5b34acf3c1 100644
--- a/mythtv/external/FFmpeg/libavcodec/txd.c
+++ b/mythtv/external/FFmpeg/libavcodec/txd.c
@@ -51,6 +51,7 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     unsigned int y, v;
     uint8_t *ptr;
     uint32_t *pal;
+    int ret;
 
     bytestream2_init(&gb, avpkt->data, avpkt->size);
     version         = bytestream2_get_le32(&gb);
@@ -65,7 +66,7 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     if (version < 8 || version > 9) {
         av_log(avctx, AV_LOG_ERROR, "texture data version %i is unsupported\n",
                                                                     version);
-        return -1;
+        return AVERROR_PATCHWELCOME;
     }
 
     if (depth == 8) {
@@ -74,19 +75,19 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         avctx->pix_fmt = AV_PIX_FMT_RGB32;
     } else {
         av_log(avctx, AV_LOG_ERROR, "depth of %i is unsupported\n", depth);
-        return -1;
+        return AVERROR_PATCHWELCOME;
     }
 
     if (p->data[0])
         avctx->release_buffer(avctx, p);
 
-    if (av_image_check_size(w, h, 0, avctx))
-        return -1;
+    if ((ret = av_image_check_size(w, h, 0, avctx)) < 0)
+        return ret;
     if (w != avctx->width || h != avctx->height)
         avcodec_set_dimensions(avctx, w, h);
-    if (ff_get_buffer(avctx, p) < 0) {
+    if ((ret = ff_get_buffer(avctx, p)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
-        return -1;
+        return ret;
     }
 
     p->pict_type = AV_PICTURE_TYPE_I;
@@ -149,7 +150,7 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 
 unsupported:
     av_log(avctx, AV_LOG_ERROR, "unsupported d3d format (%08x)\n", d3d_format);
-    return -1;
+    return AVERROR_PATCHWELCOME;
 }
 
 static av_cold int txd_end(AVCodecContext *avctx) {
diff --git a/mythtv/external/FFmpeg/libavcodec/utils.c b/mythtv/external/FFmpeg/libavcodec/utils.c
index 6552b9ee8d4..8a4aaf486f0 100644
--- a/mythtv/external/FFmpeg/libavcodec/utils.c
+++ b/mythtv/external/FFmpeg/libavcodec/utils.c
@@ -25,6 +25,7 @@
  * utils.
  */
 
+#include "config.h"
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
@@ -47,6 +48,9 @@
 #include 
 #include 
 #include 
+#if CONFIG_ICONV
+# include 
+#endif
 
 volatile int ff_avcodec_locked;
 static int volatile entangled_thread_counter = 0;
@@ -177,6 +181,12 @@ void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
 
 #define INTERNAL_BUFFER_SIZE (32 + 1)
 
+#if (ARCH_ARM && HAVE_NEON) || ARCH_PPC || HAVE_MMX
+#   define STRIDE_ALIGN 16
+#else
+#   define STRIDE_ALIGN 8
+#endif
+
 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
                                int linesize_align[AV_NUM_DATA_POINTERS])
 {
@@ -257,7 +267,8 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
     case AV_PIX_FMT_PAL8:
     case AV_PIX_FMT_BGR8:
     case AV_PIX_FMT_RGB8:
-        if (s->codec_id == AV_CODEC_ID_SMC) {
+        if (s->codec_id == AV_CODEC_ID_SMC ||
+            s->codec_id == AV_CODEC_ID_CINEPAK) {
             w_align = 4;
             h_align = 4;
         }
@@ -269,6 +280,12 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
             h_align = 4;
         }
         break;
+    case AV_PIX_FMT_RGB24:
+        if (s->codec_id == AV_CODEC_ID_CINEPAK) {
+            w_align = 4;
+            h_align = 4;
+        }
+        break;
     default:
         w_align = 1;
         h_align = 1;
@@ -460,7 +477,6 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
             buf->base[i] = av_malloc(size[i] + 16); //FIXME 16
             if (buf->base[i] == NULL)
                 return AVERROR(ENOMEM);
-            memset(buf->base[i], 128, size[i]);
 
             // no edge if EDGE EMU or not planar YUV
             if ((s->flags & CODEC_FLAG_EMU_EDGE) || !size[2])
@@ -494,6 +510,28 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
     return 0;
 }
 
+void avpriv_color_frame(AVFrame *frame, const int c[4])
+{
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
+    int p, y, x;
+
+    av_assert0(desc->flags & PIX_FMT_PLANAR);
+
+    for (p = 0; pnb_components; p++) {
+        uint8_t *dst = frame->data[p];
+        int is_chroma = p == 1 || p == 2;
+        int bytes = -((-frame->width) >> (is_chroma ? desc->log2_chroma_w : 0));
+        for (y = 0; y<-((-frame->height) >> (is_chroma ? desc->log2_chroma_h : 0)); y++){
+            if (desc->comp[0].depth_minus1 >= 8) {
+                for (x = 0; xlinesize[p];
+        }
+    }
+}
+
 int avcodec_default_get_buffer(AVCodecContext *avctx, AVFrame *frame)
 {
     frame->type = FF_BUFFER_TYPE_INTERNAL;
@@ -511,14 +549,14 @@ void ff_init_buffer_info(AVCodecContext *s, AVFrame *frame)
 {
     if (s->pkt) {
         frame->pkt_pts = s->pkt->pts;
-        frame->pkt_pos = s->pkt->pos;
-        frame->pkt_duration = s->pkt->duration;
-        frame->pkt_size = s->pkt->size;
+        av_frame_set_pkt_pos     (frame, s->pkt->pos);
+        av_frame_set_pkt_duration(frame, s->pkt->duration);
+        av_frame_set_pkt_size    (frame, s->pkt->size);
     } else {
         frame->pkt_pts = AV_NOPTS_VALUE;
-        frame->pkt_pos = -1;
-        frame->pkt_duration = 0;
-        frame->pkt_size = -1;
+        av_frame_set_pkt_pos     (frame, -1);
+        av_frame_set_pkt_duration(frame, 0);
+        av_frame_set_pkt_size    (frame, -1);
     }
     frame->reordered_opaque = s->reordered_opaque;
 
@@ -533,7 +571,7 @@ void ff_init_buffer_info(AVCodecContext *s, AVFrame *frame)
         frame->sample_rate    = s->sample_rate;
         frame->format         = s->sample_fmt;
         frame->channel_layout = s->channel_layout;
-        frame->channels       = s->channels;
+        av_frame_set_channels(frame, s->channels);
         break;
     }
 }
@@ -676,11 +714,11 @@ void avcodec_get_frame_defaults(AVFrame *frame)
 
     frame->pts                   =
     frame->pkt_dts               =
-    frame->pkt_pts               =
-    frame->best_effort_timestamp = AV_NOPTS_VALUE;
-    frame->pkt_duration        = 0;
-    frame->pkt_pos             = -1;
-    frame->pkt_size            = -1;
+    frame->pkt_pts               = AV_NOPTS_VALUE;
+    av_frame_set_best_effort_timestamp(frame, AV_NOPTS_VALUE);
+    av_frame_set_pkt_duration         (frame, 0);
+    av_frame_set_pkt_pos              (frame, -1);
+    av_frame_set_pkt_size             (frame, -1);
     frame->key_frame           = 1;
     frame->sample_aspect_ratio = (AVRational) {0, 1 };
     frame->format              = -1; /* unknown */
@@ -729,6 +767,8 @@ MAKE_ACCESSORS(AVFrame, frame, AVDictionary *, metadata)
 MAKE_ACCESSORS(AVFrame, frame, int,     decode_error_flags)
 MAKE_ACCESSORS(AVFrame, frame, int,     pkt_size)
 
+AVDictionary **ff_frame_get_metadatap(AVFrame *frame) {return &frame->metadata;};
+
 MAKE_ACCESSORS(AVCodecContext, codec, AVRational, pkt_timebase)
 MAKE_ACCESSORS(AVCodecContext, codec, const AVCodecDescriptor *, codec_descriptor)
 
@@ -1061,6 +1101,32 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
             ret = AVERROR(EINVAL);
             goto free_and_end;
         }
+        if (avctx->sub_charenc) {
+            if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
+                av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
+                       "supported with subtitles codecs\n");
+                ret = AVERROR(EINVAL);
+                goto free_and_end;
+            } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
+                av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
+                       "subtitles character encoding will be ignored\n",
+                       avctx->codec_descriptor->name);
+                avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_DO_NOTHING;
+            } else {
+                /* input character encoding is set for a text based subtitle
+                 * codec at this point */
+                if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_AUTOMATIC)
+                    avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_PRE_DECODER;
+
+                if (!CONFIG_ICONV && avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_PRE_DECODER) {
+                    av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
+                           "conversion needs a libavcodec built with iconv support "
+                           "for this codec\n");
+                    ret = AVERROR(ENOSYS);
+                    goto free_and_end;
+                }
+            }
+        }
     }
 end:
     ff_unlock_avcodec();
@@ -1584,13 +1650,13 @@ static int add_metadata_from_side_data(AVCodecContext *avctx, AVFrame *frame)
     while (side_metadata < end) {
         const uint8_t *key = side_metadata;
         const uint8_t *val = side_metadata + strlen(key) + 1;
-        int ret = av_dict_set(&frame->metadata, key, val, 0);
+        int ret = av_dict_set(ff_frame_get_metadatap(frame), key, val, 0);
         if (ret < 0)
             break;
         side_metadata = val + strlen(val) + 1;
     }
 end:
-    avctx->metadata = frame->metadata;
+    avctx->metadata = av_frame_get_metadata(frame);
     return ret;
 }
 
@@ -1626,7 +1692,7 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
             picture->pkt_dts = avpkt->dts;
 
             if(!avctx->has_b_frames){
-                picture->pkt_pos         = avpkt->pos;
+                av_frame_set_pkt_pos(picture, avpkt->pos);
             }
             //FIXME these should be under if(!avctx->has_b_frames)
             /* get_buffer is supposed to set frame parameters */
@@ -1650,9 +1716,10 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
 
         if (*got_picture_ptr){
             avctx->frame_number++;
-            picture->best_effort_timestamp = guess_correct_pts(avctx,
-                                                            picture->pkt_pts,
-                                                            picture->pkt_dts);
+            av_frame_set_best_effort_timestamp(picture,
+                                               guess_correct_pts(avctx,
+                                                                 picture->pkt_pts,
+                                                                 picture->pkt_dts));
         }
     } else
         ret = 0;
@@ -1747,15 +1814,16 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
         if (ret >= 0 && *got_frame_ptr) {
             avctx->frame_number++;
             frame->pkt_dts = avpkt->dts;
-            frame->best_effort_timestamp = guess_correct_pts(avctx,
-                                                             frame->pkt_pts,
-                                                             frame->pkt_dts);
+            av_frame_set_best_effort_timestamp(frame,
+                                               guess_correct_pts(avctx,
+                                                                 frame->pkt_pts,
+                                                                 frame->pkt_dts));
             if (frame->format == AV_SAMPLE_FMT_NONE)
                 frame->format = avctx->sample_fmt;
             if (!frame->channel_layout)
                 frame->channel_layout = avctx->channel_layout;
-            if (!frame->channels)
-                frame->channels = avctx->channels;
+            if (!av_frame_get_channels(frame))
+                av_frame_set_channels(frame, avctx->channels);
             if (!frame->sample_rate)
                 frame->sample_rate = avctx->sample_rate;
         }
@@ -1784,8 +1852,8 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
                         frame->pkt_pts += diff_ts;
                     if(frame->pkt_dts!=AV_NOPTS_VALUE)
                         frame->pkt_dts += diff_ts;
-                    if (frame->pkt_duration >= diff_ts)
-                        frame->pkt_duration -= diff_ts;
+                    if (av_frame_get_pkt_duration(frame) >= diff_ts)
+                        av_frame_set_pkt_duration(frame, av_frame_get_pkt_duration(frame) - diff_ts);
                 } else {
                     av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
                 }
@@ -1809,7 +1877,7 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
      * extended_data are doing it correctly */
     if (*got_frame_ptr) {
         planar   = av_sample_fmt_is_planar(frame->format);
-        channels = frame->channels;
+        channels = av_frame_get_channels(frame);
         if (!(planar && channels > AV_NUM_DATA_POINTERS))
             frame->extended_data = frame->data;
     } else {
@@ -1819,6 +1887,68 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
     return ret;
 }
 
+#define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
+static int recode_subtitle(AVCodecContext *avctx,
+                           AVPacket *outpkt, const AVPacket *inpkt)
+{
+#if CONFIG_ICONV
+    iconv_t cd = (iconv_t)-1;
+    int ret = 0;
+    char *inb, *outb;
+    size_t inl, outl;
+    AVPacket tmp;
+#endif
+
+    if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER)
+        return 0;
+
+#if CONFIG_ICONV
+    cd = iconv_open("UTF-8", avctx->sub_charenc);
+    if (cd == (iconv_t)-1) {
+        av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
+               "with input character encoding \"%s\"\n", avctx->sub_charenc);
+        ret = AVERROR(errno);
+        goto end;
+    }
+
+    inb = inpkt->data;
+    inl = inpkt->size;
+
+    if (inl >= INT_MAX / UTF8_MAX_BYTES - FF_INPUT_BUFFER_PADDING_SIZE) {
+        av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
+        ret = AVERROR(ENOMEM);
+        goto end;
+    }
+
+    ret = av_new_packet(&tmp, inl * UTF8_MAX_BYTES);
+    if (ret < 0)
+        goto end;
+    outpkt->data = tmp.data;
+    outpkt->size = tmp.size;
+    outb = outpkt->data;
+    outl = outpkt->size;
+
+    if (iconv(cd, &inb, &inl, &outb, &outl) == (size_t)-1 ||
+        iconv(cd, NULL, NULL, &outb, &outl) == (size_t)-1 ||
+        outl >= outpkt->size || inl != 0) {
+        av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" "
+               "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc);
+        av_free_packet(&tmp);
+        ret = AVERROR(errno);
+        goto end;
+    }
+    outpkt->size -= outl;
+    memset(outpkt->data + outpkt->size, 0, outl);
+
+end:
+    if (cd != (iconv_t)-1)
+        iconv_close(cd);
+    return ret;
+#else
+    av_assert0(!"requesting subtitles recoding without iconv");
+#endif
+}
+
 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
                              int *got_sub_ptr,
                              AVPacket *avpkt)
@@ -1834,19 +1964,30 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
     avcodec_get_subtitle_defaults(sub);
 
     if (avpkt->size) {
+        AVPacket pkt_recoded;
         AVPacket tmp = *avpkt;
         int did_split = av_packet_split_side_data(&tmp);
         //apply_param_change(avctx, &tmp);
 
-        avctx->pkt = &tmp;
-
-        if (avctx->pkt_timebase.den && avpkt->pts != AV_NOPTS_VALUE)
-            sub->pts = av_rescale_q(avpkt->pts,
-                                    avctx->pkt_timebase, AV_TIME_BASE_Q);
-        ret = avctx->codec->decode(avctx, sub, got_sub_ptr, &tmp);
-        sub->format = sub->num_rects && sub->rects[0]->ass;
+        pkt_recoded = tmp;
+        ret = recode_subtitle(avctx, &pkt_recoded, &tmp);
+        if (ret < 0) {
+            *got_sub_ptr = 0;
+        } else {
+            avctx->pkt = &pkt_recoded;
+
+            if (avctx->pkt_timebase.den && avpkt->pts != AV_NOPTS_VALUE)
+                sub->pts = av_rescale_q(avpkt->pts,
+                                        avctx->pkt_timebase, AV_TIME_BASE_Q);
+            ret = avctx->codec->decode(avctx, sub, got_sub_ptr, &pkt_recoded);
+            av_assert1((ret >= 0) >= !!*got_sub_ptr &&
+                       !!*got_sub_ptr >= !!sub->num_rects);
+            if (tmp.data != pkt_recoded.data)
+                av_free(pkt_recoded.data);
+            sub->format = !(avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB);
+            avctx->pkt = NULL;
+        }
 
-        avctx->pkt = NULL;
         if (did_split) {
             ff_packet_free_side_data(&tmp);
             if(ret == tmp.size)
@@ -2020,14 +2161,14 @@ size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_ta
 {
     int i, len, ret = 0;
 
-#define IS_PRINT(x)                                               \
+#define TAG_PRINT(x)                                              \
     (((x) >= '0' && (x) <= '9') ||                                \
      ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') ||  \
      ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
 
     for (i = 0; i < 4; i++) {
         len = snprintf(buf, buf_size,
-                       IS_PRINT(codec_tag&0xFF) ? "%c" : "[%d]", codec_tag&0xFF);
+                       TAG_PRINT(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF);
         buf        += len;
         buf_size    = buf_size > len ? buf_size - len : 0;
         ret        += len;
@@ -2120,6 +2261,15 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
                      ", %s", av_get_sample_fmt_name(enc->sample_fmt));
         }
         break;
+    case AVMEDIA_TYPE_DATA:
+        if (av_log_get_level() >= AV_LOG_DEBUG) {
+            int g = av_gcd(enc->time_base.num, enc->time_base.den);
+            if (g)
+                snprintf(buf + strlen(buf), buf_size - strlen(buf),
+                         ", %d/%d",
+                         enc->time_base.num / g, enc->time_base.den / g);
+        }
+        break;
     default:
         return;
     }
@@ -2339,6 +2489,7 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
     case AV_CODEC_ID_ADPCM_IMA_QT: return   64;
     case AV_CODEC_ID_ADPCM_EA_XAS: return  128;
     case AV_CODEC_ID_AMR_NB:
+    case AV_CODEC_ID_EVRC:
     case AV_CODEC_ID_GSM:
     case AV_CODEC_ID_QCELP:
     case AV_CODEC_ID_RA_288:       return  160;
@@ -2626,10 +2777,10 @@ int avpriv_unlock_avformat(void)
 
 unsigned int avpriv_toupper4(unsigned int x)
 {
-    return toupper(x & 0xFF)
-           + (toupper((x >> 8) & 0xFF) << 8)
-           + (toupper((x >> 16) & 0xFF) << 16)
-           + (toupper((x >> 24) & 0xFF) << 24);
+    return av_toupper(x & 0xFF)
+           + (av_toupper((x >> 8) & 0xFF) << 8)
+           + (av_toupper((x >> 16) & 0xFF) << 16)
+           + (av_toupper((x >> 24) & 0xFF) << 24);
 }
 
 #if !HAVE_THREADS
diff --git a/mythtv/external/FFmpeg/libavcodec/utvideoenc.c b/mythtv/external/FFmpeg/libavcodec/utvideoenc.c
index 71672783511..acb25c3899e 100644
--- a/mythtv/external/FFmpeg/libavcodec/utvideoenc.c
+++ b/mythtv/external/FFmpeg/libavcodec/utvideoenc.c
@@ -594,7 +594,6 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
      * At least currently Ut Video is IDR only.
      * Set flags accordingly.
      */
-    avctx->coded_frame->reference = 0;
     avctx->coded_frame->key_frame = 1;
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
 
diff --git a/mythtv/external/FFmpeg/libavcodec/v210dec.c b/mythtv/external/FFmpeg/libavcodec/v210dec.c
index 63037adb8dc..132b42ad979 100644
--- a/mythtv/external/FFmpeg/libavcodec/v210dec.c
+++ b/mythtv/external/FFmpeg/libavcodec/v210dec.c
@@ -55,7 +55,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     if (avctx->width & 1) {
         av_log(avctx, AV_LOG_ERROR, "v210 needs even width\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
     avctx->pix_fmt             = AV_PIX_FMT_YUV422P10;
     avctx->bits_per_raw_sample = 10;
@@ -77,7 +77,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 {
     V210DecContext *s = avctx->priv_data;
 
-    int h, w, stride, aligned_input;
+    int h, w, ret, stride, aligned_input;
     AVFrame *pic = avctx->coded_frame;
     const uint8_t *psrc = avpkt->data;
     uint16_t *y, *u, *v;
@@ -97,7 +97,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             s->stride_warning_shown = 1;
         } else {
             av_log(avctx, AV_LOG_ERROR, "packet too small\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
     }
 
@@ -112,8 +112,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         avctx->release_buffer(avctx, pic);
 
     pic->reference = 0;
-    if (ff_get_buffer(avctx, pic) < 0)
-        return -1;
+    if ((ret = ff_get_buffer(avctx, pic)) < 0)
+        return ret;
 
     y = (uint16_t*)pic->data[0];
     u = (uint16_t*)pic->data[1];
diff --git a/mythtv/external/FFmpeg/libavcodec/v210x.c b/mythtv/external/FFmpeg/libavcodec/v210x.c
index f973124122f..cb9fc6f27a8 100644
--- a/mythtv/external/FFmpeg/libavcodec/v210x.c
+++ b/mythtv/external/FFmpeg/libavcodec/v210x.c
@@ -26,12 +26,12 @@
 
 static av_cold int decode_init(AVCodecContext *avctx)
 {
-    if(avctx->width & 1){
+    if (avctx->width & 1) {
         av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n");
-        return -1;
+        return AVERROR(EINVAL);
     }
-    avctx->pix_fmt = AV_PIX_FMT_YUV422P16;
-    avctx->bits_per_raw_sample= 10;
+    avctx->pix_fmt             = AV_PIX_FMT_YUV422P16;
+    avctx->bits_per_raw_sample = 10;
 
     avctx->coded_frame= avcodec_alloc_frame();
     if (!avctx->coded_frame)
@@ -43,81 +43,82 @@ static av_cold int decode_init(AVCodecContext *avctx)
 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
                         AVPacket *avpkt)
 {
-    int y=0;
-    int width= avctx->width;
-    AVFrame *pic= avctx->coded_frame;
-    const uint32_t *src= (const uint32_t *)avpkt->data;
+    const uint32_t *src = (const uint32_t *)avpkt->data;
+    AVFrame *pic        = avctx->coded_frame;
+    int width           = avctx->width;
+    int y               = 0;
     uint16_t *ydst, *udst, *vdst, *yend;
+    int ret;
 
-    if(pic->data[0])
+    if (pic->data[0])
         avctx->release_buffer(avctx, pic);
 
-    if(avpkt->size < avctx->width * avctx->height * 8 / 3){
+    if (avpkt->size < avctx->width * avctx->height * 8 / 3) {
         av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
-    if(avpkt->size > avctx->width * avctx->height * 8 / 3){
+    if (avpkt->size > avctx->width * avctx->height * 8 / 3) {
         av_log_ask_for_sample(avctx, "Probably padded data\n");
     }
 
-    pic->reference= 0;
-    if(ff_get_buffer(avctx, pic) < 0)
-        return -1;
-
-    ydst= (uint16_t *)pic->data[0];
-    udst= (uint16_t *)pic->data[1];
-    vdst= (uint16_t *)pic->data[2];
-    yend= ydst + width;
-    pic->pict_type= AV_PICTURE_TYPE_I;
-    pic->key_frame= 1;
-
-    for(;;){
-        uint32_t v= av_be2ne32(*src++);
-        *udst++= (v>>16) & 0xFFC0;
-        *ydst++= (v>>6 ) & 0xFFC0;
-        *vdst++= (v<<4 ) & 0xFFC0;
-
-        v= av_be2ne32(*src++);
-        *ydst++= (v>>16) & 0xFFC0;
-
-        if(ydst >= yend){
-            ydst+= pic->linesize[0]/2 - width;
-            udst+= pic->linesize[1]/2 - width/2;
-            vdst+= pic->linesize[2]/2 - width/2;
-            yend= ydst + width;
-            if(++y >= avctx->height)
+    pic->reference = 0;
+    if ((ret = ff_get_buffer(avctx, pic)) < 0)
+        return ret;
+
+    ydst = (uint16_t *)pic->data[0];
+    udst = (uint16_t *)pic->data[1];
+    vdst = (uint16_t *)pic->data[2];
+    yend = ydst + width;
+    pic->pict_type = AV_PICTURE_TYPE_I;
+    pic->key_frame = 1;
+
+    for (;;) {
+        uint32_t v = av_be2ne32(*src++);
+        *udst++ = (v >> 16) & 0xFFC0;
+        *ydst++ = (v >> 6 ) & 0xFFC0;
+        *vdst++ = (v << 4 ) & 0xFFC0;
+
+        v       = av_be2ne32(*src++);
+        *ydst++ = (v >> 16) & 0xFFC0;
+
+        if (ydst >= yend) {
+            ydst += pic->linesize[0] / 2 - width;
+            udst += pic->linesize[1] / 2 - width / 2;
+            vdst += pic->linesize[2] / 2 - width / 2;
+            yend = ydst + width;
+            if (++y >= avctx->height)
                 break;
         }
 
-        *udst++= (v>>6 ) & 0xFFC0;
-        *ydst++= (v<<4 ) & 0xFFC0;
+        *udst++ = (v >> 6 ) & 0xFFC0;
+        *ydst++ = (v << 4 ) & 0xFFC0;
 
-        v= av_be2ne32(*src++);
-        *vdst++= (v>>16) & 0xFFC0;
-        *ydst++= (v>>6 ) & 0xFFC0;
+        v = av_be2ne32(*src++);
+        *vdst++ = (v >> 16) & 0xFFC0;
+        *ydst++ = (v >> 6 ) & 0xFFC0;
 
-        if(ydst >= yend){
-            ydst+= pic->linesize[0]/2 - width;
-            udst+= pic->linesize[1]/2 - width/2;
-            vdst+= pic->linesize[2]/2 - width/2;
-            yend= ydst + width;
-            if(++y >= avctx->height)
+        if (ydst >= yend) {
+            ydst += pic->linesize[0] / 2 - width;
+            udst += pic->linesize[1] / 2 - width / 2;
+            vdst += pic->linesize[2] / 2 - width / 2;
+            yend  = ydst + width;
+            if (++y >= avctx->height)
                 break;
         }
 
-        *udst++= (v<<4 ) & 0xFFC0;
-
-        v= av_be2ne32(*src++);
-        *ydst++= (v>>16) & 0xFFC0;
-        *vdst++= (v>>6 ) & 0xFFC0;
-        *ydst++= (v<<4 ) & 0xFFC0;
-        if(ydst >= yend){
-            ydst+= pic->linesize[0]/2 - width;
-            udst+= pic->linesize[1]/2 - width/2;
-            vdst+= pic->linesize[2]/2 - width/2;
-            yend= ydst + width;
-            if(++y >= avctx->height)
+        *udst++ = (v << 4 ) & 0xFFC0;
+
+        v = av_be2ne32(*src++);
+        *ydst++ = (v >> 16) & 0xFFC0;
+        *vdst++ = (v >> 6 ) & 0xFFC0;
+        *ydst++ = (v << 4 ) & 0xFFC0;
+        if (ydst >= yend) {
+            ydst += pic->linesize[0] / 2 - width;
+            udst += pic->linesize[1] / 2 - width / 2;
+            vdst += pic->linesize[2] / 2 - width / 2;
+            yend  = ydst + width;
+            if (++y >= avctx->height)
                 break;
         }
     }
diff --git a/mythtv/external/FFmpeg/libavcodec/v410enc.c b/mythtv/external/FFmpeg/libavcodec/v410enc.c
index 67d8fc9d77d..9661c7c8ea4 100644
--- a/mythtv/external/FFmpeg/libavcodec/v410enc.c
+++ b/mythtv/external/FFmpeg/libavcodec/v410enc.c
@@ -54,7 +54,6 @@ static int v410_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         return ret;
     dst = pkt->data;
 
-    avctx->coded_frame->reference = 0;
     avctx->coded_frame->key_frame = 1;
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
 
diff --git a/mythtv/external/FFmpeg/libavcodec/vaapi.c b/mythtv/external/FFmpeg/libavcodec/vaapi.c
index 774fde840f3..a220a9d3c21 100644
--- a/mythtv/external/FFmpeg/libavcodec/vaapi.c
+++ b/mythtv/external/FFmpeg/libavcodec/vaapi.c
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "h264.h"
 #include "vaapi_internal.h"
 
 /**
@@ -40,7 +41,7 @@ static void destroy_buffers(VADisplay display, VABufferID *buffers, unsigned int
     }
 }
 
-static int render_picture(struct vaapi_context *vactx, VASurfaceID surface)
+int ff_vaapi_render_picture(struct vaapi_context *vactx, VASurfaceID surface)
 {
     VABufferID va_buffers[3];
     unsigned int n_va_buffers = 0;
@@ -77,7 +78,7 @@ static int render_picture(struct vaapi_context *vactx, VASurfaceID surface)
     return 0;
 }
 
-static int commit_slices(struct vaapi_context *vactx)
+int ff_vaapi_commit_slices(struct vaapi_context *vactx)
 {
     VABufferID *slice_buf_ids;
     VABufferID slice_param_buf_id, slice_data_buf_id;
@@ -152,7 +153,7 @@ VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, co
     if (!vactx->slice_data)
         vactx->slice_data = buffer;
     if (vactx->slice_data + vactx->slice_data_size != buffer) {
-        if (commit_slices(vactx) < 0)
+        if (ff_vaapi_commit_slices(vactx) < 0)
             return NULL;
         vactx->slice_data = buffer;
     }
@@ -175,23 +176,12 @@ VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, co
     return slice_param;
 }
 
-int ff_vaapi_common_end_frame(MpegEncContext *s)
+void ff_vaapi_common_end_frame(AVCodecContext *avctx)
 {
-    struct vaapi_context * const vactx = s->avctx->hwaccel_context;
-    int ret = -1;
+    struct vaapi_context * const vactx = avctx->hwaccel_context;
 
-    av_dlog(s->avctx, "ff_vaapi_common_end_frame()\n");
+    av_dlog(avctx, "ff_vaapi_common_end_frame()\n");
 
-    if (commit_slices(vactx) < 0)
-        goto done;
-    if (vactx->n_slice_buf_ids > 0) {
-        if (render_picture(vactx, ff_vaapi_get_surface_id(s->current_picture_ptr)) < 0)
-            goto done;
-        ff_draw_horiz_band(s, 0, s->avctx->height);
-    }
-    ret = 0;
-
-done:
     destroy_buffers(vactx->display, &vactx->pic_param_buf_id, 1);
     destroy_buffers(vactx->display, &vactx->iq_matrix_buf_id, 1);
     destroy_buffers(vactx->display, &vactx->bitplane_buf_id, 1);
@@ -202,6 +192,27 @@ int ff_vaapi_common_end_frame(MpegEncContext *s)
     vactx->slice_buf_ids_alloc = 0;
     vactx->slice_count         = 0;
     vactx->slice_params_alloc  = 0;
+}
+
+int ff_vaapi_mpeg_end_frame(AVCodecContext *avctx)
+{
+    struct vaapi_context * const vactx = avctx->hwaccel_context;
+    MpegEncContext *s = avctx->priv_data;
+    int ret;
+
+    ret = ff_vaapi_commit_slices(vactx);
+    if (ret < 0)
+        goto finish;
+
+    ret = ff_vaapi_render_picture(vactx,
+                                  ff_vaapi_get_surface_id(s->current_picture_ptr));
+    if (ret < 0)
+        goto finish;
+
+    ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
+
+finish:
+    ff_vaapi_common_end_frame(avctx);
     return ret;
 }
 
diff --git a/mythtv/external/FFmpeg/libavcodec/vaapi_h264.c b/mythtv/external/FFmpeg/libavcodec/vaapi_h264.c
index 9be51bf24c9..349dc1bb017 100644
--- a/mythtv/external/FFmpeg/libavcodec/vaapi_h264.c
+++ b/mythtv/external/FFmpeg/libavcodec/vaapi_h264.c
@@ -219,17 +219,16 @@ static void fill_vaapi_plain_pred_weight_table(H264Context   *h,
 }
 
 /** Initialize and start decoding a frame with VA API. */
-static int start_frame(AVCodecContext          *avctx,
-                       av_unused const uint8_t *buffer,
-                       av_unused uint32_t       size)
+static int vaapi_h264_start_frame(AVCodecContext          *avctx,
+                                  av_unused const uint8_t *buffer,
+                                  av_unused uint32_t       size)
 {
     H264Context * const h = avctx->priv_data;
-    MpegEncContext * const s = &h->s;
     struct vaapi_context * const vactx = avctx->hwaccel_context;
     VAPictureParameterBufferH264 *pic_param;
     VAIQMatrixBufferH264 *iq_matrix;
 
-    av_dlog(avctx, "start_frame()\n");
+    av_dlog(avctx, "vaapi_h264_start_frame()\n");
 
     vactx->slice_param_size = sizeof(VASliceParameterBufferH264);
 
@@ -237,11 +236,11 @@ static int start_frame(AVCodecContext          *avctx,
     pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferH264));
     if (!pic_param)
         return -1;
-    fill_vaapi_pic(&pic_param->CurrPic, s->current_picture_ptr, s->picture_structure);
+    fill_vaapi_pic(&pic_param->CurrPic, h->cur_pic_ptr, h->picture_structure);
     if (fill_vaapi_ReferenceFrames(pic_param, h) < 0)
         return -1;
-    pic_param->picture_width_in_mbs_minus1                      = s->mb_width - 1;
-    pic_param->picture_height_in_mbs_minus1                     = s->mb_height - 1;
+    pic_param->picture_width_in_mbs_minus1                      = h->mb_width - 1;
+    pic_param->picture_height_in_mbs_minus1                     = h->mb_height - 1;
     pic_param->bit_depth_luma_minus8                            = h->sps.bit_depth_luma - 8;
     pic_param->bit_depth_chroma_minus8                          = h->sps.bit_depth_chroma - 8;
     pic_param->num_ref_frames                                   = h->sps.ref_frame_count;
@@ -269,7 +268,7 @@ static int start_frame(AVCodecContext          *avctx,
     pic_param->pic_fields.bits.weighted_pred_flag               = h->pps.weighted_pred;
     pic_param->pic_fields.bits.weighted_bipred_idc              = h->pps.weighted_bipred_idc;
     pic_param->pic_fields.bits.transform_8x8_mode_flag          = h->pps.transform_8x8_mode;
-    pic_param->pic_fields.bits.field_pic_flag                   = s->picture_structure != PICT_FRAME;
+    pic_param->pic_fields.bits.field_pic_flag                   = h->picture_structure != PICT_FRAME;
     pic_param->pic_fields.bits.constrained_intra_pred_flag      = h->pps.constrained_intra_pred;
     pic_param->pic_fields.bits.pic_order_present_flag           = h->pps.pic_order_present;
     pic_param->pic_fields.bits.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present;
@@ -288,37 +287,51 @@ static int start_frame(AVCodecContext          *avctx,
 }
 
 /** End a hardware decoding based frame. */
-static int end_frame(AVCodecContext *avctx)
+static int vaapi_h264_end_frame(AVCodecContext *avctx)
 {
+    struct vaapi_context * const vactx = avctx->hwaccel_context;
     H264Context * const h = avctx->priv_data;
+    int ret;
+
+    av_dlog(avctx, "vaapi_h264_end_frame()\n");
+    ret = ff_vaapi_commit_slices(vactx);
+    if (ret < 0)
+        goto finish;
+
+    ret = ff_vaapi_render_picture(vactx, ff_vaapi_get_surface_id(h->cur_pic_ptr));
+    if (ret < 0)
+        goto finish;
+
+    ff_h264_draw_horiz_band(h, 0, h->avctx->height);
 
-    av_dlog(avctx, "end_frame()\n");
-    return ff_vaapi_common_end_frame(&h->s);
+finish:
+    ff_vaapi_common_end_frame(avctx);
+    return ret;
 }
 
 /** Decode the given H.264 slice with VA API. */
-static int decode_slice(AVCodecContext *avctx,
-                        const uint8_t  *buffer,
-                        uint32_t        size)
+static int vaapi_h264_decode_slice(AVCodecContext *avctx,
+                                   const uint8_t  *buffer,
+                                   uint32_t        size)
 {
     H264Context * const h = avctx->priv_data;
-    MpegEncContext * const s = &h->s;
     VASliceParameterBufferH264 *slice_param;
 
-    av_dlog(avctx, "decode_slice(): buffer %p, size %d\n", buffer, size);
+    av_dlog(avctx, "vaapi_h264_decode_slice(): buffer %p, size %d\n",
+            buffer, size);
 
     /* Fill in VASliceParameterBufferH264. */
     slice_param = (VASliceParameterBufferH264 *)ff_vaapi_alloc_slice(avctx->hwaccel_context, buffer, size);
     if (!slice_param)
         return -1;
-    slice_param->slice_data_bit_offset          = get_bits_count(&h->s.gb) + 8; /* bit buffer started beyond nal_unit_type */
-    slice_param->first_mb_in_slice              = (s->mb_y >> FIELD_OR_MBAFF_PICTURE) * s->mb_width + s->mb_x;
+    slice_param->slice_data_bit_offset          = get_bits_count(&h->gb) + 8; /* bit buffer started beyond nal_unit_type */
+    slice_param->first_mb_in_slice              = (h->mb_y >> FIELD_OR_MBAFF_PICTURE) * h->mb_width + h->mb_x;
     slice_param->slice_type                     = ff_h264_get_slice_type(h);
     slice_param->direct_spatial_mv_pred_flag    = h->slice_type == AV_PICTURE_TYPE_B ? h->direct_spatial_mv_pred : 0;
     slice_param->num_ref_idx_l0_active_minus1   = h->list_count > 0 ? h->ref_count[0] - 1 : 0;
     slice_param->num_ref_idx_l1_active_minus1   = h->list_count > 1 ? h->ref_count[1] - 1 : 0;
     slice_param->cabac_init_idc                 = h->cabac_init_idc;
-    slice_param->slice_qp_delta                 = s->qscale - h->pps.init_qp;
+    slice_param->slice_qp_delta                 = h->qscale - h->pps.init_qp;
     slice_param->disable_deblocking_filter_idc  = h->deblocking_filter < 2 ? !h->deblocking_filter : h->deblocking_filter;
     slice_param->slice_alpha_c0_offset_div2     = h->slice_alpha_c0_offset / 2 - 26;
     slice_param->slice_beta_offset_div2         = h->slice_beta_offset     / 2 - 26;
@@ -342,7 +355,7 @@ AVHWAccel ff_h264_vaapi_hwaccel = {
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_H264,
     .pix_fmt        = AV_PIX_FMT_VAAPI_VLD,
-    .start_frame    = start_frame,
-    .end_frame      = end_frame,
-    .decode_slice   = decode_slice,
+    .start_frame    = vaapi_h264_start_frame,
+    .end_frame      = vaapi_h264_end_frame,
+    .decode_slice   = vaapi_h264_decode_slice,
 };
diff --git a/mythtv/external/FFmpeg/libavcodec/vaapi_internal.h b/mythtv/external/FFmpeg/libavcodec/vaapi_internal.h
index e514dd6f445..1ac0e9fe35d 100644
--- a/mythtv/external/FFmpeg/libavcodec/vaapi_internal.h
+++ b/mythtv/external/FFmpeg/libavcodec/vaapi_internal.h
@@ -42,7 +42,7 @@ static inline VASurfaceID ff_vaapi_get_surface_id(Picture *pic)
 }
 
 /** Common AVHWAccel.end_frame() implementation */
-int ff_vaapi_common_end_frame(MpegEncContext *s);
+void ff_vaapi_common_end_frame(AVCodecContext *avctx);
 
 /** Allocate a new picture parameter buffer */
 void *ff_vaapi_alloc_pic_param(struct vaapi_context *vactx, unsigned int size);
@@ -63,6 +63,10 @@ uint8_t *ff_vaapi_alloc_bitplane(struct vaapi_context *vactx, uint32_t size);
  */
 VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, const uint8_t *buffer, uint32_t size);
 
+int ff_vaapi_mpeg_end_frame(AVCodecContext *avctx);
+int ff_vaapi_commit_slices(struct vaapi_context *vactx);
+int ff_vaapi_render_picture(struct vaapi_context *vactx, VASurfaceID surface);
+
 /* @} */
 
 #endif /* AVCODEC_VAAPI_INTERNAL_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/vaapi_mpeg2.c b/mythtv/external/FFmpeg/libavcodec/vaapi_mpeg2.c
index 50ba06d3e25..d626f242e5d 100644
--- a/mythtv/external/FFmpeg/libavcodec/vaapi_mpeg2.c
+++ b/mythtv/external/FFmpeg/libavcodec/vaapi_mpeg2.c
@@ -21,7 +21,6 @@
  */
 
 #include "vaapi_internal.h"
-#include "dsputil.h"
 
 /** Reconstruct bitstream f_code */
 static inline int mpeg2_get_f_code(MpegEncContext *s)
@@ -99,11 +98,6 @@ static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint8_
     return 0;
 }
 
-static int vaapi_mpeg2_end_frame(AVCodecContext *avctx)
-{
-    return ff_vaapi_common_end_frame(avctx->priv_data);
-}
-
 static int vaapi_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
 {
     MpegEncContext * const s = avctx->priv_data;
@@ -144,6 +138,6 @@ AVHWAccel ff_mpeg2_vaapi_hwaccel = {
     .id             = AV_CODEC_ID_MPEG2VIDEO,
     .pix_fmt        = AV_PIX_FMT_VAAPI_VLD,
     .start_frame    = vaapi_mpeg2_start_frame,
-    .end_frame      = vaapi_mpeg2_end_frame,
+    .end_frame      = ff_vaapi_mpeg_end_frame,
     .decode_slice   = vaapi_mpeg2_decode_slice,
 };
diff --git a/mythtv/external/FFmpeg/libavcodec/vaapi_mpeg4.c b/mythtv/external/FFmpeg/libavcodec/vaapi_mpeg4.c
index 31787402e41..bcc0ebabab7 100644
--- a/mythtv/external/FFmpeg/libavcodec/vaapi_mpeg4.c
+++ b/mythtv/external/FFmpeg/libavcodec/vaapi_mpeg4.c
@@ -115,11 +115,6 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_
     return 0;
 }
 
-static int vaapi_mpeg4_end_frame(AVCodecContext *avctx)
-{
-    return ff_vaapi_common_end_frame(avctx->priv_data);
-}
-
 static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
 {
     MpegEncContext * const s = avctx->priv_data;
@@ -156,7 +151,7 @@ AVHWAccel ff_mpeg4_vaapi_hwaccel = {
     .id             = AV_CODEC_ID_MPEG4,
     .pix_fmt        = AV_PIX_FMT_VAAPI_VLD,
     .start_frame    = vaapi_mpeg4_start_frame,
-    .end_frame      = vaapi_mpeg4_end_frame,
+    .end_frame      = ff_vaapi_mpeg_end_frame,
     .decode_slice   = vaapi_mpeg4_decode_slice,
 };
 #endif
@@ -168,7 +163,7 @@ AVHWAccel ff_h263_vaapi_hwaccel = {
     .id             = AV_CODEC_ID_H263,
     .pix_fmt        = AV_PIX_FMT_VAAPI_VLD,
     .start_frame    = vaapi_mpeg4_start_frame,
-    .end_frame      = vaapi_mpeg4_end_frame,
+    .end_frame      = ff_vaapi_mpeg_end_frame,
     .decode_slice   = vaapi_mpeg4_decode_slice,
 };
 #endif
diff --git a/mythtv/external/FFmpeg/libavcodec/vaapi_vc1.c b/mythtv/external/FFmpeg/libavcodec/vaapi_vc1.c
index af01e51df21..b8f0530f266 100644
--- a/mythtv/external/FFmpeg/libavcodec/vaapi_vc1.c
+++ b/mythtv/external/FFmpeg/libavcodec/vaapi_vc1.c
@@ -310,13 +310,6 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t
     return 0;
 }
 
-static int vaapi_vc1_end_frame(AVCodecContext *avctx)
-{
-    VC1Context * const v = avctx->priv_data;
-
-    return ff_vaapi_common_end_frame(&v->s);
-}
-
 static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
 {
     VC1Context * const v = avctx->priv_data;
@@ -347,7 +340,7 @@ AVHWAccel ff_wmv3_vaapi_hwaccel = {
     .id             = AV_CODEC_ID_WMV3,
     .pix_fmt        = AV_PIX_FMT_VAAPI_VLD,
     .start_frame    = vaapi_vc1_start_frame,
-    .end_frame      = vaapi_vc1_end_frame,
+    .end_frame      = ff_vaapi_mpeg_end_frame,
     .decode_slice   = vaapi_vc1_decode_slice,
 };
 #endif
@@ -358,6 +351,6 @@ AVHWAccel ff_vc1_vaapi_hwaccel = {
     .id             = AV_CODEC_ID_VC1,
     .pix_fmt        = AV_PIX_FMT_VAAPI_VLD,
     .start_frame    = vaapi_vc1_start_frame,
-    .end_frame      = vaapi_vc1_end_frame,
+    .end_frame      = ff_vaapi_mpeg_end_frame,
     .decode_slice   = vaapi_vc1_decode_slice,
 };
diff --git a/mythtv/external/FFmpeg/libavcodec/vb.c b/mythtv/external/FFmpeg/libavcodec/vb.c
index 11225869f15..3b5a83be17a 100644
--- a/mythtv/external/FFmpeg/libavcodec/vb.c
+++ b/mythtv/external/FFmpeg/libavcodec/vb.c
@@ -31,7 +31,7 @@
 #include "bytestream.h"
 #include "internal.h"
 
-enum VBFlags{
+enum VBFlags {
     VB_HAS_GMC     = 0x01,
     VB_HAS_AUDIO   = 0x04,
     VB_HAS_VIDEO   = 0x08,
@@ -64,16 +64,16 @@ static void vb_decode_palette(VBDecContext *c, int data_size)
     int start, size, i;
 
     start = bytestream2_get_byte(&c->stream);
-    size = (bytestream2_get_byte(&c->stream) - 1) & 0xFF;
-    if(start + size > 255){
+    size  = (bytestream2_get_byte(&c->stream) - 1) & 0xFF;
+    if (start + size > 255) {
         av_log(c->avctx, AV_LOG_ERROR, "Palette change runs beyond entry 256\n");
         return;
     }
-    if(size*3+2 > data_size){
+    if (size*3+2 > data_size) {
         av_log(c->avctx, AV_LOG_ERROR, "Palette data runs beyond chunk size\n");
         return;
     }
-    for(i = start; i <= start + size; i++)
+    for (i = start; i <= start + size; i++)
         c->pal[i] = 0xFFU << 24 | bytestream2_get_be24(&c->stream);
 }
 
@@ -97,42 +97,42 @@ static int vb_decode_framedata(VBDecContext *c, int offset)
     int pattype, pattern;
     const int width = c->avctx->width;
     uint8_t *pstart = c->prev_frame;
-    uint8_t *pend = c->prev_frame + width*c->avctx->height;
+    uint8_t *pend   = c->prev_frame + width*c->avctx->height;
 
     g = c->stream;
 
     prev = c->prev_frame + offset;
-    cur = c->frame;
+    cur  = c->frame;
 
     blocks = (c->avctx->width >> 2) * (c->avctx->height >> 2);
-    blk2 = 0;
-    for(blk = 0; blk < blocks; blk++){
-        if(!(blk & 3)) {
+    blk2   = 0;
+    for (blk = 0; blk < blocks; blk++) {
+        if (!(blk & 3)) {
             blocktypes = bytestream2_get_byte(&g);
         }
-        switch(blocktypes & 0xC0){
+        switch (blocktypes & 0xC0) {
         case 0x00: //skip
-            for(y = 0; y < 4; y++)
-                if(check_line(prev + y*width, pstart, pend))
+            for (y = 0; y < 4; y++)
+                if (check_line(prev + y*width, pstart, pend))
                     memcpy(cur + y*width, prev + y*width, 4);
                 else
                     memset(cur + y*width, 0, 4);
             break;
         case 0x40:
             t = bytestream2_get_byte(&g);
-            if(!t){ //raw block
+            if (!t) { //raw block
                 if (bytestream2_get_bytes_left(&g) < 16) {
                     av_log(c->avctx, AV_LOG_ERROR, "Insufficient data\n");
-                    return -1;
+                    return AVERROR_INVALIDDATA;
                 }
-                for(y = 0; y < 4; y++)
+                for (y = 0; y < 4; y++)
                     bytestream2_get_buffer(&g, cur + y * width, 4);
-            }else{ // motion compensation
+            } else { // motion compensation
                 x = ((t & 0xF)^8) - 8;
                 y = ((t >> 4) ^8) - 8;
                 t = x + y*width;
-                for(y = 0; y < 4; y++)
-                    if(check_line(prev + t + y*width, pstart, pend))
+                for (y = 0; y < 4; y++)
+                    if (check_line(prev + t + y*width, pstart, pend))
                         memcpy(cur + y*width, prev + t + y*width, 4);
                     else
                         memset(cur + y*width, 0, 4);
@@ -140,35 +140,35 @@ static int vb_decode_framedata(VBDecContext *c, int offset)
             break;
         case 0x80: // fill
             t = bytestream2_get_byte(&g);
-            for(y = 0; y < 4; y++)
+            for (y = 0; y < 4; y++)
                 memset(cur + y*width, t, 4);
             break;
         case 0xC0: // pattern fill
-            t = bytestream2_get_byte(&g);
+            t       = bytestream2_get_byte(&g);
             pattype = t >> 6;
             pattern = vb_patterns[t & 0x3F];
-            switch(pattype){
+            switch (pattype) {
             case 0:
                 a = bytestream2_get_byte(&g);
                 b = bytestream2_get_byte(&g);
-                for(y = 0; y < 4; y++)
-                    for(x = 0; x < 4; x++, pattern >>= 1)
+                for (y = 0; y < 4; y++)
+                    for (x = 0; x < 4; x++, pattern >>= 1)
                         cur[x + y*width] = (pattern & 1) ? b : a;
                 break;
             case 1:
                 pattern = ~pattern;
             case 2:
                 a = bytestream2_get_byte(&g);
-                for(y = 0; y < 4; y++)
-                    for(x = 0; x < 4; x++, pattern >>= 1)
-                        if(pattern & 1 && check_pixel(prev + x + y*width, pstart, pend))
+                for (y = 0; y < 4; y++)
+                    for (x = 0; x < 4; x++, pattern >>= 1)
+                        if (pattern & 1 && check_pixel(prev + x + y*width, pstart, pend))
                             cur[x + y*width] = prev[x + y*width];
                         else
                             cur[x + y*width] = a;
                 break;
             case 3:
-                av_log(c->avctx, AV_LOG_ERROR, "Invalid opcode seen @%d\n",blk);
-                return -1;
+                av_log(c->avctx, AV_LOG_ERROR, "Invalid opcode seen @%d\n", blk);
+                return AVERROR_INVALIDDATA;
             }
             break;
         }
@@ -176,8 +176,8 @@ static int vb_decode_framedata(VBDecContext *c, int offset)
         cur  += 4;
         prev += 4;
         blk2++;
-        if(blk2 == (width >> 2)){
-            blk2 = 0;
+        if (blk2 == (width >> 2)) {
+            blk2  = 0;
             cur  += width * 3;
             prev += width * 3;
         }
@@ -190,29 +190,29 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 {
     VBDecContext * const c = avctx->priv_data;
     uint8_t *outptr, *srcptr;
-    int i, j;
+    int i, j, ret;
     int flags;
     uint32_t size;
     int offset = 0;
 
     bytestream2_init(&c->stream, avpkt->data, avpkt->size);
 
-    if(c->pic.data[0])
+    if (c->pic.data[0])
         avctx->release_buffer(avctx, &c->pic);
     c->pic.reference = 3;
-    if(ff_get_buffer(avctx, &c->pic) < 0){
+    if ((ret = ff_get_buffer(avctx, &c->pic)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
-        return -1;
+        return ret;
     }
 
     flags = bytestream2_get_le16(&c->stream);
 
-    if(flags & VB_HAS_GMC){
+    if (flags & VB_HAS_GMC) {
         i = (int16_t)bytestream2_get_le16(&c->stream);
         j = (int16_t)bytestream2_get_le16(&c->stream);
         offset = i + j * avctx->width;
     }
-    if(flags & VB_HAS_VIDEO){
+    if (flags & VB_HAS_VIDEO) {
         size = bytestream2_get_le32(&c->stream);
         if(size > bytestream2_get_bytes_left(&c->stream)+4 || size<4){
             av_log(avctx, AV_LOG_ERROR, "Frame size invalid\n");
@@ -221,7 +221,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         vb_decode_framedata(c, offset);
         bytestream2_skip(&c->stream, size - 4);
     }
-    if(flags & VB_HAS_PALETTE){
+    if (flags & VB_HAS_PALETTE) {
         size = bytestream2_get_le32(&c->stream);
         vb_decode_palette(c, size);
     }
@@ -232,7 +232,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     outptr = c->pic.data[0];
     srcptr = c->frame;
 
-    for(i = 0; i < avctx->height; i++){
+    for (i = 0; i < avctx->height; i++) {
         memcpy(outptr, srcptr, avctx->width);
         srcptr += avctx->width;
         outptr += c->pic.linesize[0];
@@ -251,7 +251,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 {
     VBDecContext * const c = avctx->priv_data;
 
-    c->avctx = avctx;
+    c->avctx       = avctx;
     avctx->pix_fmt = AV_PIX_FMT_PAL8;
     avcodec_get_frame_defaults(&c->pic);
 
diff --git a/mythtv/external/FFmpeg/libavcodec/vc1.c b/mythtv/external/FFmpeg/libavcodec/vc1.c
index fa0b916898a..a6a7bac2396 100644
--- a/mythtv/external/FFmpeg/libavcodec/vc1.c
+++ b/mythtv/external/FFmpeg/libavcodec/vc1.c
@@ -28,7 +28,6 @@
  */
 
 #include "internal.h"
-#include "dsputil.h"
 #include "avcodec.h"
 #include "mpegvideo.h"
 #include "vc1.h"
diff --git a/mythtv/external/FFmpeg/libavcodec/vc1.h b/mythtv/external/FFmpeg/libavcodec/vc1.h
index 4ed89234696..596d4d35e53 100644
--- a/mythtv/external/FFmpeg/libavcodec/vc1.h
+++ b/mythtv/external/FFmpeg/libavcodec/vc1.h
@@ -24,6 +24,7 @@
 #define AVCODEC_VC1_H
 
 #include "avcodec.h"
+#include "h264chroma.h"
 #include "mpegvideo.h"
 #include "intrax8.h"
 #include "vc1dsp.h"
@@ -181,6 +182,7 @@ enum FrameCodingMode {
 typedef struct VC1Context{
     MpegEncContext s;
     IntraX8Context x8;
+    H264ChromaContext h264chroma;
     VC1DSPContext vc1dsp;
 
     int bits;
@@ -384,7 +386,7 @@ typedef struct VC1Context{
     int bi_type;
     int x8_type;
 
-    DCTELEM (*block)[6][64];
+    int16_t (*block)[6][64];
     int n_allocated_blks, cur_blk_idx, left_blk_idx, topleft_blk_idx, top_blk_idx;
     uint32_t *cbp_base, *cbp;
     uint8_t *is_intra_base, *is_intra;
@@ -452,9 +454,9 @@ int ff_vc1_parse_frame_header    (VC1Context *v, GetBitContext *gb);
 int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext *gb);
 int ff_vc1_init_common(VC1Context *v);
 
-av_cold int  ff_vc1_decode_init_alloc_tables(VC1Context *v);
-av_cold void ff_vc1_init_transposed_scantables(VC1Context *v);
-av_cold int  ff_vc1_decode_end(AVCodecContext *avctx);
+int  ff_vc1_decode_init_alloc_tables(VC1Context *v);
+void ff_vc1_init_transposed_scantables(VC1Context *v);
+int  ff_vc1_decode_end(AVCodecContext *avctx);
 void ff_vc1_decode_blocks(VC1Context *v);
 
 #endif /* AVCODEC_VC1_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/vc1dec.c b/mythtv/external/FFmpeg/libavcodec/vc1dec.c
index fa25161d75f..2130c741096 100644
--- a/mythtv/external/FFmpeg/libavcodec/vc1dec.c
+++ b/mythtv/external/FFmpeg/libavcodec/vc1dec.c
@@ -27,10 +27,10 @@
  */
 
 #include "internal.h"
-#include "dsputil.h"
 #include "avcodec.h"
 #include "mpegvideo.h"
 #include "h263.h"
+#include "h264chroma.h"
 #include "vc1.h"
 #include "vc1data.h"
 #include "vc1acdata.h"
@@ -73,6 +73,17 @@ enum Imode {
 };
 /** @} */ //imode defines
 
+static void init_block_index(VC1Context *v)
+{
+    MpegEncContext *s = &v->s;
+    ff_init_block_index(s);
+    if (v->field_mode && v->second_field) {
+        s->dest[0] += s->current_picture_ptr->f.linesize[0];
+        s->dest[1] += s->current_picture_ptr->f.linesize[1];
+        s->dest[2] += s->current_picture_ptr->f.linesize[2];
+    }
+}
+
 
 /** @} */ //Bitplane group
 
@@ -80,7 +91,7 @@ static void vc1_put_signed_blocks_clamped(VC1Context *v)
 {
     MpegEncContext *s = &v->s;
     int topleft_mb_pos, top_mb_pos;
-    int stride_y, fieldtx;
+    int stride_y, fieldtx = 0;
     int v_dist;
 
     /* The put pixels loop is always one MB row behind the decoding loop,
@@ -93,7 +104,8 @@ static void vc1_put_signed_blocks_clamped(VC1Context *v)
     if (!s->first_slice_line) {
         if (s->mb_x) {
             topleft_mb_pos = (s->mb_y - 1) * s->mb_stride + s->mb_x - 1;
-            fieldtx        = v->fieldtx_plane[topleft_mb_pos];
+            if (v->fcm == ILACE_FRAME)
+                fieldtx = v->fieldtx_plane[topleft_mb_pos];
             stride_y       = s->linesize << fieldtx;
             v_dist         = (16 - fieldtx) >> (fieldtx == 0);
             s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][0],
@@ -117,7 +129,8 @@ static void vc1_put_signed_blocks_clamped(VC1Context *v)
         }
         if (s->mb_x == s->mb_width - 1) {
             top_mb_pos = (s->mb_y - 1) * s->mb_stride + s->mb_x;
-            fieldtx    = v->fieldtx_plane[top_mb_pos];
+            if (v->fcm == ILACE_FRAME)
+                fieldtx = v->fieldtx_plane[top_mb_pos];
             stride_y   = s->linesize << fieldtx;
             v_dist     = fieldtx ? 15 : 8;
             s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][0],
@@ -332,6 +345,7 @@ static void vc1_mc_1mv(VC1Context *v, int dir)
 {
     MpegEncContext *s = &v->s;
     DSPContext *dsp   = &v->s.dsp;
+    H264ChromaContext *h264chroma = &v->h264chroma;
     uint8_t *srcY, *srcU, *srcV;
     int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
     int off, off_uv;
@@ -496,13 +510,8 @@ static void vc1_mc_1mv(VC1Context *v, int dir)
         srcY += s->mspel * (1 + s->linesize);
     }
 
-    if (v->field_mode && v->second_field) {
-        off    = s->current_picture_ptr->f.linesize[0];
-        off_uv = s->current_picture_ptr->f.linesize[1];
-    } else {
         off    = 0;
         off_uv = 0;
-    }
     if (s->mspel) {
         dxy = ((my & 3) << 2) | (mx & 3);
         v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off    , srcY    , s->linesize, v->rnd);
@@ -523,8 +532,8 @@ static void vc1_mc_1mv(VC1Context *v, int dir)
     uvmx = (uvmx & 3) << 1;
     uvmy = (uvmy & 3) << 1;
     if (!v->rnd) {
-        dsp->put_h264_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
-        dsp->put_h264_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
+        h264chroma->put_h264_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
+        h264chroma->put_h264_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
     } else {
         v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
         v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
@@ -638,8 +647,6 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir)
         off = ((n > 1) ? s->linesize : 0) + (n & 1) * 8;
     else
         off = s->linesize * 4 * (n & 2) + (n & 1) * 8;
-    if (v->field_mode && v->second_field)
-        off += s->current_picture_ptr->f.linesize[0];
 
     src_x = s->mb_x * 16 + (n & 1) * 8 + (mx >> 2);
     if (!fieldmv)
@@ -778,7 +785,7 @@ static av_always_inline int get_chroma_mv(int *mvx, int *mvy, int *a, int flag,
 static void vc1_mc_4mv_chroma(VC1Context *v, int dir)
 {
     MpegEncContext *s = &v->s;
-    DSPContext *dsp   = &v->s.dsp;
+    H264ChromaContext *h264chroma = &v->h264chroma;
     uint8_t *srcU, *srcV;
     int uvmx, uvmy, uvsrc_x, uvsrc_y;
     int k, tx = 0, ty = 0;
@@ -876,7 +883,7 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir)
             srcU += s->current_picture_ptr->f.linesize[1];
             srcV += s->current_picture_ptr->f.linesize[2];
         }
-        off = v->second_field ? s->current_picture_ptr->f.linesize[1] : 0;
+        off = 0;
     }
 
     if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
@@ -930,8 +937,8 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir)
     uvmx = (uvmx & 3) << 1;
     uvmy = (uvmy & 3) << 1;
     if (!v->rnd) {
-        dsp->put_h264_chroma_pixels_tab[0](s->dest[1] + off, srcU, s->uvlinesize, 8, uvmx, uvmy);
-        dsp->put_h264_chroma_pixels_tab[0](s->dest[2] + off, srcV, s->uvlinesize, 8, uvmx, uvmy);
+        h264chroma->put_h264_chroma_pixels_tab[0](s->dest[1] + off, srcU, s->uvlinesize, 8, uvmx, uvmy);
+        h264chroma->put_h264_chroma_pixels_tab[0](s->dest[2] + off, srcV, s->uvlinesize, 8, uvmx, uvmy);
     } else {
         v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off, srcU, s->uvlinesize, 8, uvmx, uvmy);
         v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off, srcV, s->uvlinesize, 8, uvmx, uvmy);
@@ -943,7 +950,7 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir)
 static void vc1_mc_4mv_chroma4(VC1Context *v)
 {
     MpegEncContext *s = &v->s;
-    DSPContext *dsp = &v->s.dsp;
+    H264ChromaContext *h264chroma = &v->h264chroma;
     uint8_t *srcU, *srcV;
     int uvsrc_x, uvsrc_y;
     int uvmx_field[4], uvmy_field[4];
@@ -1016,8 +1023,8 @@ static void vc1_mc_4mv_chroma4(VC1Context *v)
             }
         }
         if (!v->rnd) {
-            dsp->put_h264_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
-            dsp->put_h264_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
+            h264chroma->put_h264_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
+            h264chroma->put_h264_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
         } else {
             v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
             v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
@@ -1755,9 +1762,10 @@ static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y,
                 px = mid_pred(A[0], B[0], C[0]);
                 py = mid_pred(A[1], B[1], C[1]);
             } else if (total_valid) {
-                if (a_valid) { px = A[0]; py = A[1]; }
-                if (b_valid) { px = B[0]; py = B[1]; }
-                if (c_valid) { px = C[0]; py = C[1]; }
+                if      (a_valid) { px = A[0]; py = A[1]; }
+                else if (b_valid) { px = B[0]; py = B[1]; }
+                else if (c_valid) { px = C[0]; py = C[1]; }
+                else av_assert2(0);
             } else
                 px = py = 0;
         }
@@ -1845,6 +1853,7 @@ static void vc1_interp_mc(VC1Context *v)
 {
     MpegEncContext *s = &v->s;
     DSPContext *dsp = &v->s.dsp;
+    H264ChromaContext *h264chroma = &v->h264chroma;
     uint8_t *srcY, *srcU, *srcV;
     int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
     int off, off_uv;
@@ -1945,13 +1954,8 @@ static void vc1_interp_mc(VC1Context *v)
         srcY += s->mspel * (1 + s->linesize);
     }
 
-    if (v->field_mode && v->second_field) {
-        off    = s->current_picture_ptr->f.linesize[0];
-        off_uv = s->current_picture_ptr->f.linesize[1];
-    } else {
         off    = 0;
         off_uv = 0;
-    }
 
     if (s->mspel) {
         dxy = ((my & 3) << 2) | (mx & 3);
@@ -1966,7 +1970,7 @@ static void vc1_interp_mc(VC1Context *v)
         if (!v->rnd)
             dsp->avg_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16);
         else
-            dsp->avg_no_rnd_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16);
+            dsp->avg_no_rnd_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize, 16);
     }
 
     if (s->flags & CODEC_FLAG_GRAY) return;
@@ -1974,8 +1978,8 @@ static void vc1_interp_mc(VC1Context *v)
     uvmx = (uvmx & 3) << 1;
     uvmy = (uvmy & 3) << 1;
     if (!v->rnd) {
-        dsp->avg_h264_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
-        dsp->avg_h264_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
+        h264chroma->avg_h264_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
+        h264chroma->avg_h264_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
     } else {
         v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
         v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
@@ -2555,7 +2559,7 @@ static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip,
  * @param coded are AC coeffs present or not
  * @param codingset set of VLC to decode data
  */
-static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n,
+static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
                               int coded, int codingset)
 {
     GetBitContext *gb = &v->s.gb;
@@ -2718,14 +2722,14 @@ static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n,
  * @param codingset set of VLC to decode data
  * @param mquant quantizer value for this macroblock
  */
-static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n,
+static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
                                   int coded, int codingset, int mquant)
 {
     GetBitContext *gb = &v->s.gb;
     MpegEncContext *s = &v->s;
     int dc_pred_dir = 0; /* Direction of the DC prediction used */
     int i;
-    int16_t *dc_val;
+    int16_t *dc_val = NULL;
     int16_t *ac_val, *ac_val2;
     int dcdiff;
     int a_avail = v->a_avail, c_avail = v->c_avail;
@@ -2930,14 +2934,14 @@ static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n,
  * @param mquant block quantizer
  * @param codingset set of VLC to decode data
  */
-static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n,
+static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
                                   int coded, int mquant, int codingset)
 {
     GetBitContext *gb = &v->s.gb;
     MpegEncContext *s = &v->s;
     int dc_pred_dir = 0; /* Direction of the DC prediction used */
     int i;
-    int16_t *dc_val;
+    int16_t *dc_val = NULL;
     int16_t *ac_val, *ac_val2;
     int dcdiff;
     int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
@@ -3140,7 +3144,7 @@ static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n,
 
 /** Decode P block
  */
-static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n,
+static int vc1_decode_p_block(VC1Context *v, int16_t block[64], int n,
                               int mquant, int ttmb, int first_block,
                               uint8_t *dst, int linesize, int skip_block,
                               int *ttmb_out)
@@ -3955,7 +3959,6 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
                 continue;
             v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
             off  = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
-            off += v->second_field ? ((i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]) : 0;
             s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize);
             // TODO: loop filter
         }
@@ -4002,8 +4005,6 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
             dst_idx += i >> 2;
             val = ((cbp >> (5 - i)) & 1);
             off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
-            if (v->second_field)
-                off += (i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0];
             if (val) {
                 pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
                                          first_block, s->dest[dst_idx] + off,
@@ -4232,7 +4233,6 @@ static void vc1_decode_b_mb_intfi(VC1Context *v)
                 for (j = 0; j < 64; j++)
                     s->block[i][j] <<= 1;
             off  = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
-            off += v->second_field ? ((i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]) : 0;
             s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize);
             // TODO: yet to perform loop filter
         }
@@ -4314,8 +4314,6 @@ static void vc1_decode_b_mb_intfi(VC1Context *v)
             dst_idx += i >> 2;
             val = ((cbp >> (5 - i)) & 1);
             off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
-            if (v->second_field)
-                off += (i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0];
             if (val) {
                 vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
                                    first_block, s->dest[dst_idx] + off,
@@ -4374,7 +4372,7 @@ static void vc1_decode_i_blocks(VC1Context *v)
     s->first_slice_line = 1;
     for (s->mb_y = 0; s->mb_y < s->end_mb_y; s->mb_y++) {
         s->mb_x = 0;
-        ff_init_block_index(s);
+        init_block_index(v);
         for (; s->mb_x < v->end_mb_x; s->mb_x++) {
             uint8_t *dst[6];
             ff_update_block_index(s);
@@ -4448,25 +4446,25 @@ static void vc1_decode_i_blocks(VC1Context *v)
             if (v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq);
 
             if (get_bits_count(&s->gb) > v->bits) {
-                ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, ER_MB_ERROR);
+                ff_er_add_slice(&s->er, 0, 0, s->mb_x, s->mb_y, ER_MB_ERROR);
                 av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n",
                        get_bits_count(&s->gb), v->bits);
                 return;
             }
         }
         if (!v->s.loop_filter)
-            ff_draw_horiz_band(s, s->mb_y * 16, 16);
+            ff_mpeg_draw_horiz_band(s, s->mb_y * 16, 16);
         else if (s->mb_y)
-            ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
+            ff_mpeg_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
 
         s->first_slice_line = 0;
     }
     if (v->s.loop_filter)
-        ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
+        ff_mpeg_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
 
     /* This is intentionally mb_height and not end_mb_y - unlike in advanced
      * profile, these only differ are when decoding MSS2 rectangles. */
-    ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, ER_MB_END);
+    ff_er_add_slice(&s->er, 0, 0, s->mb_width - 1, s->mb_height - 1, ER_MB_END);
 }
 
 /** Decode blocks of I-frame for advanced profile
@@ -4514,15 +4512,15 @@ static void vc1_decode_i_blocks_adv(VC1Context *v)
     s->mb_y             = s->start_mb_y;
     if (s->start_mb_y) {
         s->mb_x = 0;
-        ff_init_block_index(s);
+        init_block_index(v);
         memset(&s->coded_block[s->block_index[0] - s->b8_stride], 0,
                (1 + s->b8_stride) * sizeof(*s->coded_block));
     }
     for (; s->mb_y < s->end_mb_y; s->mb_y++) {
         s->mb_x = 0;
-        ff_init_block_index(s);
+        init_block_index(v);
         for (;s->mb_x < s->mb_width; s->mb_x++) {
-            DCTELEM (*block)[64] = v->block[v->cur_blk_idx];
+            int16_t (*block)[64] = v->block[v->cur_blk_idx];
             ff_update_block_index(s);
             s->dsp.clear_blocks(block[0]);
             mb_pos = s->mb_x + s->mb_y * s->mb_stride;
@@ -4576,22 +4574,23 @@ static void vc1_decode_i_blocks_adv(VC1Context *v)
 
             if (get_bits_count(&s->gb) > v->bits) {
                 // TODO: may need modification to handle slice coding
-                ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
+                ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
                 av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n",
                        get_bits_count(&s->gb), v->bits);
                 return;
             }
         }
         if (!v->s.loop_filter)
-            ff_draw_horiz_band(s, s->mb_y * 16, 16);
+            ff_mpeg_draw_horiz_band(s, s->mb_y * 16, 16);
         else if (s->mb_y)
-            ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
+            ff_mpeg_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
         s->first_slice_line = 0;
     }
 
     /* raw bottom MB row */
     s->mb_x = 0;
-    ff_init_block_index(s);
+    init_block_index(v);
+
     for (;s->mb_x < s->mb_width; s->mb_x++) {
         ff_update_block_index(s);
         vc1_put_signed_blocks_clamped(v);
@@ -4599,8 +4598,8 @@ static void vc1_decode_i_blocks_adv(VC1Context *v)
             vc1_loop_filter_iblk_delayed(v, v->pq);
     }
     if (v->s.loop_filter)
-        ff_draw_horiz_band(s, (s->end_mb_y-1)*16, 16);
-    ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
+        ff_mpeg_draw_horiz_band(s, (s->end_mb_y-1)*16, 16);
+    ff_er_add_slice(&s->er, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
                     (s->end_mb_y << v->field_mode) - 1, ER_MB_END);
 }
 
@@ -4639,7 +4638,7 @@ static void vc1_decode_p_blocks(VC1Context *v)
     memset(v->cbp_base, 0, sizeof(v->cbp_base[0])*2*s->mb_stride);
     for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
         s->mb_x = 0;
-        ff_init_block_index(s);
+        init_block_index(v);
         for (; s->mb_x < s->mb_width; s->mb_x++) {
             ff_update_block_index(s);
 
@@ -4652,7 +4651,7 @@ static void vc1_decode_p_blocks(VC1Context *v)
                 vc1_apply_p_loop_filter(v);
             if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
                 // TODO: may need modification to handle slice coding
-                ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
+                ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
                 av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n",
                        get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y);
                 return;
@@ -4662,20 +4661,20 @@ static void vc1_decode_p_blocks(VC1Context *v)
         memmove(v->ttblk_base,    v->ttblk,    sizeof(v->ttblk_base[0])    * s->mb_stride);
         memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0]) * s->mb_stride);
         memmove(v->luma_mv_base,  v->luma_mv,  sizeof(v->luma_mv_base[0])  * s->mb_stride);
-        if (s->mb_y != s->start_mb_y) ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
+        if (s->mb_y != s->start_mb_y) ff_mpeg_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
         s->first_slice_line = 0;
     }
     if (apply_loop_filter && v->fcm == PROGRESSIVE) {
         s->mb_x = 0;
-        ff_init_block_index(s);
+        init_block_index(v);
         for (; s->mb_x < s->mb_width; s->mb_x++) {
             ff_update_block_index(s);
             vc1_apply_p_loop_filter(v);
         }
     }
     if (s->end_mb_y >= s->start_mb_y)
-        ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
-    ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
+        ff_mpeg_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
+    ff_er_add_slice(&s->er, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
                     (s->end_mb_y << v->field_mode) - 1, ER_MB_END);
 }
 
@@ -4711,7 +4710,7 @@ static void vc1_decode_b_blocks(VC1Context *v)
     s->first_slice_line = 1;
     for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
         s->mb_x = 0;
-        ff_init_block_index(s);
+        init_block_index(v);
         for (; s->mb_x < s->mb_width; s->mb_x++) {
             ff_update_block_index(s);
 
@@ -4721,7 +4720,7 @@ static void vc1_decode_b_blocks(VC1Context *v)
                 vc1_decode_b_mb(v);
             if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
                 // TODO: may need modification to handle slice coding
-                ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
+                ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
                 av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n",
                        get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y);
                 return;
@@ -4729,14 +4728,14 @@ static void vc1_decode_b_blocks(VC1Context *v)
             if (v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq);
         }
         if (!v->s.loop_filter)
-            ff_draw_horiz_band(s, s->mb_y * 16, 16);
+            ff_mpeg_draw_horiz_band(s, s->mb_y * 16, 16);
         else if (s->mb_y)
-            ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
+            ff_mpeg_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
         s->first_slice_line = 0;
     }
     if (v->s.loop_filter)
-        ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
-    ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
+        ff_mpeg_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
+    ff_er_add_slice(&s->er, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
                     (s->end_mb_y << v->field_mode) - 1, ER_MB_END);
 }
 
@@ -4744,18 +4743,18 @@ static void vc1_decode_skip_blocks(VC1Context *v)
 {
     MpegEncContext *s = &v->s;
 
-    ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, ER_MB_END);
+    ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, ER_MB_END);
     s->first_slice_line = 1;
     for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
         s->mb_x = 0;
-        ff_init_block_index(s);
+        init_block_index(v);
         ff_update_block_index(s);
         if (s->last_picture.f.data[0]) {
             memcpy(s->dest[0], s->last_picture.f.data[0] + s->mb_y * 16 * s->linesize,   s->linesize   * 16);
             memcpy(s->dest[1], s->last_picture.f.data[1] + s->mb_y *  8 * s->uvlinesize, s->uvlinesize *  8);
             memcpy(s->dest[2], s->last_picture.f.data[2] + s->mb_y *  8 * s->uvlinesize, s->uvlinesize *  8);
         }
-        ff_draw_horiz_band(s, s->mb_y * 16, 16);
+        ff_mpeg_draw_horiz_band(s, s->mb_y * 16, 16);
         s->first_slice_line = 0;
     }
     s->pict_type = AV_PICTURE_TYPE_P;
@@ -5181,10 +5180,6 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
     avctx->flags |= CODEC_FLAG_EMU_EDGE;
     v->s.flags   |= CODEC_FLAG_EMU_EDGE;
 
-    if (avctx->idct_algo == FF_IDCT_AUTO) {
-        avctx->idct_algo = FF_IDCT_WMV2;
-    }
-
     if (ff_vc1_init_common(v) < 0)
         return -1;
     // ensure static VLC tables are initialized
@@ -5196,6 +5191,8 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
     // again once we know all necessary settings.
     // That this is necessary might indicate a bug.
     ff_vc1_decode_end(avctx);
+
+    ff_h264chroma_init(&v->h264chroma, 8);
     ff_vc1dsp_init(&v->vc1dsp);
 
     if (avctx->codec_id == AV_CODEC_ID_WMV3 || avctx->codec_id == AV_CODEC_ID_WMV3IMAGE) {
@@ -5263,7 +5260,7 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
             av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n");
             return -1;
         }
-        v->res_sprite = (avctx->codec_tag == MKTAG('W','V','P','2'));
+        v->res_sprite = (avctx->codec_id == AV_CODEC_ID_VC1IMAGE);
     }
 
     avctx->profile = v->profile;
@@ -5295,6 +5292,11 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
             v->sprite_height > 1 << 14 ||
             v->output_width  > 1 << 14 ||
             v->output_height > 1 << 14) return -1;
+
+        if ((v->sprite_width&1) || (v->sprite_height&1)) {
+            av_log_ask_for_sample(avctx, "odd sprites are not supported\n");
+            return AVERROR_PATCHWELCOME;
+        }
     }
     return 0;
 }
@@ -5642,10 +5644,12 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data,
                 goto err;
         }
     } else {
+        int header_ret = 0;
+
         if (v->fcm == ILACE_FRAME && s->pict_type == AV_PICTURE_TYPE_B)
             goto err; // This codepath is still incomplete thus it is disabled
 
-        ff_er_frame_start(s);
+        ff_mpeg_er_frame_start(s);
 
         v->bits = buf_size * 8;
         v->end_mb_x = s->mb_width;
@@ -5675,7 +5679,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data,
                     continue;
                 }
                 v->second_field = 1;
-                v->blocks_off   = s->mb_width  * s->mb_height << 1;
+                v->blocks_off   = s->b8_stride * (s->mb_height&~1);
                 v->mb_off       = s->mb_stride * s->mb_height >> 1;
             } else {
                 v->second_field = 0;
@@ -5685,18 +5689,20 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data,
             if (i) {
                 v->pic_header_flag = 0;
                 if (v->field_mode && i == n_slices1 + 2) {
-                    if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
+                    if ((header_ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
                         av_log(v->s.avctx, AV_LOG_ERROR, "Field header damaged\n");
                         continue;
                     }
                 } else if (get_bits1(&s->gb)) {
                     v->pic_header_flag = 1;
-                    if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
+                    if ((header_ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
                         av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
                         continue;
                     }
                 }
             }
+            if (header_ret < 0)
+                continue;
             s->start_mb_y = (i == 0) ? 0 : FFMAX(0, slices[i-1].mby_start % mb_height);
             if (!v->field_mode || v->second_field)
                 s->end_mb_y = (i == n_slices     ) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height);
@@ -5711,6 +5717,10 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data,
                 av_log(v->s.avctx, AV_LOG_ERROR, "end mb y %d %d invalid\n", s->end_mb_y, s->start_mb_y);
                 continue;
             }
+            if (!v->p_frame_skipped && s->pict_type != AV_PICTURE_TYPE_I && !v->cbpcy_vlc) {
+                av_log(v->s.avctx, AV_LOG_ERROR, "missing cbpcy_vlc\n");
+                continue;
+            }
             ff_vc1_decode_blocks(v);
             if (i != n_slices)
                 s->gb = slices[i].gb;
@@ -5731,10 +5741,10 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data,
                 get_bits_count(&s->gb), s->gb.size_in_bits);
 //  if (get_bits_count(&s->gb) > buf_size * 8)
 //      return -1;
-        if(s->error_occurred && s->pict_type == AV_PICTURE_TYPE_B)
+        if(s->er.error_occurred && s->pict_type == AV_PICTURE_TYPE_B)
             goto err;
         if(!v->field_mode)
-            ff_er_frame_end(s);
+            ff_er_frame_end(&s->er);
     }
 
     ff_MPV_frame_end(s);
@@ -5787,6 +5797,20 @@ static const AVProfile profiles[] = {
     { FF_PROFILE_UNKNOWN },
 };
 
+static const enum AVPixelFormat vc1_hwaccel_pixfmt_list_420[] = {
+#if CONFIG_DXVA2
+    AV_PIX_FMT_DXVA2_VLD,
+#endif
+#if CONFIG_VAAPI
+    AV_PIX_FMT_VAAPI_VLD,
+#endif
+#if CONFIG_VDPAU
+    AV_PIX_FMT_VDPAU,
+#endif
+    AV_PIX_FMT_YUV420P,
+    AV_PIX_FMT_NONE
+};
+
 AVCodec ff_vc1_decoder = {
     .name           = "vc1",
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -5798,7 +5822,7 @@ AVCodec ff_vc1_decoder = {
     .flush          = ff_mpeg_flush,
     .capabilities   = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
     .long_name      = NULL_IF_CONFIG_SMALL("SMPTE VC-1"),
-    .pix_fmts       = ff_hwaccel_pixfmt_list_420,
+    .pix_fmts       = vc1_hwaccel_pixfmt_list_420,
     .profiles       = NULL_IF_CONFIG_SMALL(profiles)
 };
 
@@ -5814,7 +5838,7 @@ AVCodec ff_wmv3_decoder = {
     .flush          = ff_mpeg_flush,
     .capabilities   = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
     .long_name      = NULL_IF_CONFIG_SMALL("Windows Media Video 9"),
-    .pix_fmts       = ff_hwaccel_pixfmt_list_420,
+    .pix_fmts       = vc1_hwaccel_pixfmt_list_420,
     .profiles       = NULL_IF_CONFIG_SMALL(profiles)
 };
 #endif
diff --git a/mythtv/external/FFmpeg/libavcodec/vc1dsp.c b/mythtv/external/FFmpeg/libavcodec/vc1dsp.c
index 69637365789..260eda401bf 100644
--- a/mythtv/external/FFmpeg/libavcodec/vc1dsp.c
+++ b/mythtv/external/FFmpeg/libavcodec/vc1dsp.c
@@ -25,9 +25,11 @@
  *
  */
 
-#include "vc1dsp.h"
 #include "libavutil/avassert.h"
 #include "libavutil/common.h"
+#include "h264chroma.h"
+#include "rnd_avg.h"
+#include "vc1dsp.h"
 
 
 /** Apply overlap transform to horizontal edge
@@ -80,7 +82,7 @@ static void vc1_h_overlap_c(uint8_t* src, int stride)
     }
 }
 
-static void vc1_v_s_overlap_c(DCTELEM *top,  DCTELEM *bottom)
+static void vc1_v_s_overlap_c(int16_t *top,  int16_t *bottom)
 {
     int i;
     int a, b, c, d;
@@ -106,7 +108,7 @@ static void vc1_v_s_overlap_c(DCTELEM *top,  DCTELEM *bottom)
     }
 }
 
-static void vc1_h_s_overlap_c(DCTELEM *left, DCTELEM *right)
+static void vc1_h_s_overlap_c(int16_t *left, int16_t *right)
 {
     int i;
     int a, b, c, d;
@@ -230,7 +232,7 @@ static void vc1_h_loop_filter16_c(uint8_t *src, int stride, int pq)
 
 /** Do inverse transform on 8x8 block
 */
-static void vc1_inv_trans_8x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
+static void vc1_inv_trans_8x8_dc_c(uint8_t *dest, int linesize, int16_t *block)
 {
     int i;
     int dc = block[0];
@@ -249,11 +251,11 @@ static void vc1_inv_trans_8x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
     }
 }
 
-static void vc1_inv_trans_8x8_c(DCTELEM block[64])
+static void vc1_inv_trans_8x8_c(int16_t block[64])
 {
     int i;
     register int t1,t2,t3,t4,t5,t6,t7,t8;
-    DCTELEM *src, *dst, temp[64];
+    int16_t *src, *dst, temp[64];
 
     src = block;
     dst = temp;
@@ -320,7 +322,7 @@ static void vc1_inv_trans_8x8_c(DCTELEM block[64])
 
 /** Do inverse transform on 8x4 part of block
 */
-static void vc1_inv_trans_8x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
+static void vc1_inv_trans_8x4_dc_c(uint8_t *dest, int linesize, int16_t *block)
 {
     int i;
     int dc = block[0];
@@ -339,11 +341,11 @@ static void vc1_inv_trans_8x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
     }
 }
 
-static void vc1_inv_trans_8x4_c(uint8_t *dest, int linesize, DCTELEM *block)
+static void vc1_inv_trans_8x4_c(uint8_t *dest, int linesize, int16_t *block)
 {
     int i;
     register int t1,t2,t3,t4,t5,t6,t7,t8;
-    DCTELEM *src, *dst;
+    int16_t *src, *dst;
 
     src = block;
     dst = block;
@@ -395,7 +397,7 @@ static void vc1_inv_trans_8x4_c(uint8_t *dest, int linesize, DCTELEM *block)
 
 /** Do inverse transform on 4x8 parts of block
 */
-static void vc1_inv_trans_4x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
+static void vc1_inv_trans_4x8_dc_c(uint8_t *dest, int linesize, int16_t *block)
 {
     int i;
     int dc = block[0];
@@ -410,11 +412,11 @@ static void vc1_inv_trans_4x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
     }
 }
 
-static void vc1_inv_trans_4x8_c(uint8_t *dest, int linesize, DCTELEM *block)
+static void vc1_inv_trans_4x8_c(uint8_t *dest, int linesize, int16_t *block)
 {
     int i;
     register int t1,t2,t3,t4,t5,t6,t7,t8;
-    DCTELEM *src, *dst;
+    int16_t *src, *dst;
 
     src = block;
     dst = block;
@@ -466,7 +468,7 @@ static void vc1_inv_trans_4x8_c(uint8_t *dest, int linesize, DCTELEM *block)
 
 /** Do inverse transform on 4x4 part of block
 */
-static void vc1_inv_trans_4x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
+static void vc1_inv_trans_4x4_dc_c(uint8_t *dest, int linesize, int16_t *block)
 {
     int i;
     int dc = block[0];
@@ -481,11 +483,11 @@ static void vc1_inv_trans_4x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
     }
 }
 
-static void vc1_inv_trans_4x4_c(uint8_t *dest, int linesize, DCTELEM *block)
+static void vc1_inv_trans_4x4_c(uint8_t *dest, int linesize, int16_t *block)
 {
     int i;
     register int t1,t2,t3,t4;
-    DCTELEM *src, *dst;
+    int16_t *src, *dst;
 
     src = block;
     dst = block;
diff --git a/mythtv/external/FFmpeg/libavcodec/vc1dsp.h b/mythtv/external/FFmpeg/libavcodec/vc1dsp.h
index 877581861f4..6540eff0b83 100644
--- a/mythtv/external/FFmpeg/libavcodec/vc1dsp.h
+++ b/mythtv/external/FFmpeg/libavcodec/vc1dsp.h
@@ -29,21 +29,24 @@
 #define AVCODEC_VC1DSP_H
 
 #include "dsputil.h"
+#include "h264chroma.h"
+
+typedef void (*vc1op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
 
 typedef struct VC1DSPContext {
     /* vc1 functions */
-    void (*vc1_inv_trans_8x8)(DCTELEM *b);
-    void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block);
-    void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block);
-    void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block);
-    void (*vc1_inv_trans_8x8_dc)(uint8_t *dest, int line_size, DCTELEM *block);
-    void (*vc1_inv_trans_8x4_dc)(uint8_t *dest, int line_size, DCTELEM *block);
-    void (*vc1_inv_trans_4x8_dc)(uint8_t *dest, int line_size, DCTELEM *block);
-    void (*vc1_inv_trans_4x4_dc)(uint8_t *dest, int line_size, DCTELEM *block);
+    void (*vc1_inv_trans_8x8)(int16_t *b);
+    void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, int16_t *block);
+    void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, int16_t *block);
+    void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, int16_t *block);
+    void (*vc1_inv_trans_8x8_dc)(uint8_t *dest, int line_size, int16_t *block);
+    void (*vc1_inv_trans_8x4_dc)(uint8_t *dest, int line_size, int16_t *block);
+    void (*vc1_inv_trans_4x8_dc)(uint8_t *dest, int line_size, int16_t *block);
+    void (*vc1_inv_trans_4x4_dc)(uint8_t *dest, int line_size, int16_t *block);
     void (*vc1_v_overlap)(uint8_t *src, int stride);
     void (*vc1_h_overlap)(uint8_t *src, int stride);
-    void (*vc1_v_s_overlap)(DCTELEM *top,  DCTELEM *bottom);
-    void (*vc1_h_s_overlap)(DCTELEM *left, DCTELEM *right);
+    void (*vc1_v_s_overlap)(int16_t *top,  int16_t *bottom);
+    void (*vc1_h_s_overlap)(int16_t *left, int16_t *right);
     void (*vc1_v_loop_filter4)(uint8_t *src, int stride, int pq);
     void (*vc1_h_loop_filter4)(uint8_t *src, int stride, int pq);
     void (*vc1_v_loop_filter8)(uint8_t *src, int stride, int pq);
@@ -54,8 +57,8 @@ typedef struct VC1DSPContext {
     /* put 8x8 block with bicubic interpolation and quarterpel precision
      * last argument is actually round value instead of height
      */
-    op_pixels_func put_vc1_mspel_pixels_tab[16];
-    op_pixels_func avg_vc1_mspel_pixels_tab[16];
+    vc1op_pixels_func put_vc1_mspel_pixels_tab[16];
+    vc1op_pixels_func avg_vc1_mspel_pixels_tab[16];
 
     /* This is really one func used in VC-1 decoding */
     h264_chroma_mc_func put_no_rnd_vc1_chroma_pixels_tab[3];
diff --git a/mythtv/external/FFmpeg/libavcodec/vcr1.c b/mythtv/external/FFmpeg/libavcodec/vcr1.c
index 778ad0d8c29..e9b1a7b7951 100644
--- a/mythtv/external/FFmpeg/libavcodec/vcr1.c
+++ b/mythtv/external/FFmpeg/libavcodec/vcr1.c
@@ -25,7 +25,6 @@
  */
 
 #include "avcodec.h"
-#include "dsputil.h"
 #include "internal.h"
 #include "libavutil/internal.h"
 
@@ -77,7 +76,7 @@ static int vcr1_decode_frame(AVCodecContext *avctx, void *data,
     AVFrame *picture          = data;
     AVFrame *const p          = &a->picture;
     const uint8_t *bytestream = buf;
-    int i, x, y;
+    int i, x, y, ret;
 
     if (p->data[0])
         avctx->release_buffer(avctx, p);
@@ -88,9 +87,9 @@ static int vcr1_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     p->reference = 0;
-    if (ff_get_buffer(avctx, p) < 0) {
+    if ((ret = ff_get_buffer(avctx, p)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
-        return -1;
+        return ret;
     }
     p->pict_type = AV_PICTURE_TYPE_I;
     p->key_frame = 1;
@@ -159,42 +158,3 @@ AVCodec ff_vcr1_decoder = {
     .capabilities   = CODEC_CAP_DR1,
     .long_name      = NULL_IF_CONFIG_SMALL("ATI VCR1"),
 };
-
-/* Disable the encoder. */
-#undef CONFIG_VCR1_ENCODER
-#define CONFIG_VCR1_ENCODER 0
-
-#if CONFIG_VCR1_ENCODER
-
-#include "put_bits.h"
-
-static int vcr1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
-                             int buf_size, void *data)
-{
-    VCR1Context *const a = avctx->priv_data;
-    AVFrame *pict        = data;
-    AVFrame *const p     = &a->picture;
-    int size;
-
-    *p           = *pict;
-    p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
-
-    avpriv_align_put_bits(&a->pb);
-    flush_put_bits(&a->pb);
-
-    size = put_bits_count(&a->pb) / 32;
-
-    return size * 4;
-}
-
-AVCodec ff_vcr1_encoder = {
-    .name           = "vcr1",
-    .type           = AVMEDIA_TYPE_VIDEO,
-    .id             = AV_CODEC_ID_VCR1,
-    .priv_data_size = sizeof(VCR1Context),
-    .init           = vcr1_common_init,
-    .encode         = vcr1_encode_frame,
-    .long_name      = NULL_IF_CONFIG_SMALL("ATI VCR1"),
-};
-#endif /* CONFIG_VCR1_ENCODER */
diff --git a/mythtv/external/FFmpeg/libavcodec/vda_h264.c b/mythtv/external/FFmpeg/libavcodec/vda_h264.c
index 0d8335d5c75..23e2b518562 100644
--- a/mythtv/external/FFmpeg/libavcodec/vda_h264.c
+++ b/mythtv/external/FFmpeg/libavcodec/vda_h264.c
@@ -199,9 +199,10 @@ static int vda_sync_decode(struct vda_context *vda_ctx)
     return status;
 }
 
-static int start_frame(AVCodecContext *avctx,
-                       av_unused const uint8_t *buffer,
-                       av_unused uint32_t size)
+
+static int vda_h264_start_frame(AVCodecContext *avctx,
+                                av_unused const uint8_t *buffer,
+                                av_unused uint32_t size)
 {
     struct vda_context *vda_ctx = avctx->hwaccel_context;
 
@@ -213,9 +214,9 @@ static int start_frame(AVCodecContext *avctx,
     return 0;
 }
 
-static int decode_slice(AVCodecContext *avctx,
-                        const uint8_t *buffer,
-                        uint32_t size)
+static int vda_h264_decode_slice(AVCodecContext *avctx,
+                                 const uint8_t *buffer,
+                                 uint32_t size)
 {
     struct vda_context *vda_ctx = avctx->hwaccel_context;
     void *tmp;
@@ -239,11 +240,11 @@ static int decode_slice(AVCodecContext *avctx,
     return 0;
 }
 
-static int end_frame(AVCodecContext *avctx)
+static int vda_h264_end_frame(AVCodecContext *avctx)
 {
     H264Context *h                      = avctx->priv_data;
     struct vda_context *vda_ctx         = avctx->hwaccel_context;
-    AVFrame *frame                      = &h->s.current_picture_ptr->f;
+    AVFrame *frame                      = &h->cur_pic_ptr->f;
     int status;
 
     if (!vda_ctx->decoder || !vda_ctx->priv_bitstream)
@@ -376,7 +377,7 @@ AVHWAccel ff_h264_vda_hwaccel = {
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_H264,
     .pix_fmt        = AV_PIX_FMT_VDA_VLD,
-    .start_frame    = start_frame,
-    .decode_slice   = decode_slice,
-    .end_frame      = end_frame,
+    .start_frame    = vda_h264_start_frame,
+    .decode_slice   = vda_h264_decode_slice,
+    .end_frame      = vda_h264_end_frame,
 };
diff --git a/mythtv/external/FFmpeg/libavcodec/vdpau.c b/mythtv/external/FFmpeg/libavcodec/vdpau.c
index 6ac195ec00c..6df7f4af959 100644
--- a/mythtv/external/FFmpeg/libavcodec/vdpau.c
+++ b/mythtv/external/FFmpeg/libavcodec/vdpau.c
@@ -38,15 +38,61 @@
  * @{
  */
 
-void ff_vdpau_h264_set_reference_frames(MpegEncContext *s)
+int ff_vdpau_common_start_frame(AVCodecContext *avctx,
+                                av_unused const uint8_t *buffer,
+                                av_unused uint32_t size)
+{
+    AVVDPAUContext *hwctx = avctx->hwaccel_context;
+
+    hwctx->bitstream_buffers_used = 0;
+    return 0;
+}
+
+int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
+{
+    AVVDPAUContext *hwctx = avctx->hwaccel_context;
+    MpegEncContext *s = avctx->priv_data;
+    VdpVideoSurface surf = ff_vdpau_get_surface_id(s->current_picture_ptr);
+
+    hwctx->render(hwctx->decoder, surf, (void *)&hwctx->info,
+                  hwctx->bitstream_buffers_used, hwctx->bitstream_buffers);
+
+    ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
+    hwctx->bitstream_buffers_used = 0;
+
+    return 0;
+}
+
+int ff_vdpau_add_buffer(AVCodecContext *avctx,
+                        const uint8_t *buf, uint32_t size)
+{
+    AVVDPAUContext *hwctx = avctx->hwaccel_context;
+    VdpBitstreamBuffer *buffers = hwctx->bitstream_buffers;
+
+    buffers = av_fast_realloc(buffers, &hwctx->bitstream_buffers_allocated,
+                              (hwctx->bitstream_buffers_used + 1) * sizeof(*buffers));
+    if (!buffers)
+        return AVERROR(ENOMEM);
+
+    hwctx->bitstream_buffers = buffers;
+    buffers += hwctx->bitstream_buffers_used++;
+
+    buffers->struct_version  = VDP_BITSTREAM_BUFFER_VERSION;
+    buffers->bitstream       = buf;
+    buffers->bitstream_bytes = size;
+    return 0;
+}
+
+/* Obsolete non-hwaccel VDPAU support below... */
+
+void ff_vdpau_h264_set_reference_frames(H264Context *h)
 {
-    H264Context *h = s->avctx->priv_data;
     struct vdpau_render_state *render, *render_ref;
     VdpReferenceFrameH264 *rf, *rf2;
     Picture *pic;
     int i, list, pic_frame_idx;
 
-    render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0];
+    render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0];
     assert(render);
 
     rf = &render->info.h264.referenceFrames[0];
@@ -107,12 +153,9 @@ void ff_vdpau_h264_set_reference_frames(MpegEncContext *s)
     }
 }
 
-void ff_vdpau_add_data_chunk(MpegEncContext *s,
-                             const uint8_t *buf, int buf_size)
+void ff_vdpau_add_data_chunk(uint8_t *data, const uint8_t *buf, int buf_size)
 {
-    struct vdpau_render_state *render;
-
-    render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0];
+    struct vdpau_render_state *render = (struct vdpau_render_state*)data;
     assert(render);
 
     render->bitstream_buffers= av_fast_realloc(
@@ -127,17 +170,16 @@ void ff_vdpau_add_data_chunk(MpegEncContext *s,
     render->bitstream_buffers_used++;
 }
 
-void ff_vdpau_h264_picture_start(MpegEncContext *s)
+void ff_vdpau_h264_picture_start(H264Context *h)
 {
-    H264Context *h = s->avctx->priv_data;
     struct vdpau_render_state *render;
     int i;
 
-    render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0];
+    render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0];
     assert(render);
 
     for (i = 0; i < 2; ++i) {
-        int foc = s->current_picture_ptr->field_poc[i];
+        int foc = h->cur_pic_ptr->field_poc[i];
         if (foc == INT_MAX)
             foc = 0;
         render->info.h264.field_order_cnt[i] = foc;
@@ -146,21 +188,20 @@ void ff_vdpau_h264_picture_start(MpegEncContext *s)
     render->info.h264.frame_num = h->frame_num;
 }
 
-void ff_vdpau_h264_picture_complete(MpegEncContext *s)
+void ff_vdpau_h264_picture_complete(H264Context *h)
 {
-    H264Context *h = s->avctx->priv_data;
     struct vdpau_render_state *render;
 
-    render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0];
+    render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0];
     assert(render);
 
     render->info.h264.slice_count = h->slice_num;
     if (render->info.h264.slice_count < 1)
         return;
 
-    render->info.h264.is_reference                           = (s->current_picture_ptr->f.reference & 3) ? VDP_TRUE : VDP_FALSE;
-    render->info.h264.field_pic_flag                         = s->picture_structure != PICT_FRAME;
-    render->info.h264.bottom_field_flag                      = s->picture_structure == PICT_BOTTOM_FIELD;
+    render->info.h264.is_reference                           = (h->cur_pic_ptr->f.reference & 3) ? VDP_TRUE : VDP_FALSE;
+    render->info.h264.field_pic_flag                         = h->picture_structure != PICT_FRAME;
+    render->info.h264.bottom_field_flag                      = h->picture_structure == PICT_BOTTOM_FIELD;
     render->info.h264.num_ref_frames                         = h->sps.ref_frame_count;
     render->info.h264.mb_adaptive_frame_field_flag           = h->sps.mb_aff && !render->info.h264.field_pic_flag;
     render->info.h264.constrained_intra_pred_flag            = h->pps.constrained_intra_pred;
@@ -186,7 +227,7 @@ void ff_vdpau_h264_picture_complete(MpegEncContext *s)
     memcpy(render->info.h264.scaling_lists_8x8[0], h->pps.scaling_matrix8[0], sizeof(render->info.h264.scaling_lists_8x8[0]));
     memcpy(render->info.h264.scaling_lists_8x8[1], h->pps.scaling_matrix8[3], sizeof(render->info.h264.scaling_lists_8x8[0]));
 
-    ff_draw_horiz_band(s, 0, s->avctx->height);
+    ff_h264_draw_horiz_band(h, 0, h->avctx->height);
     render->bitstream_buffers_used = 0;
 }
 
@@ -238,12 +279,12 @@ void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf,
         render->info.mpeg.forward_reference      = last->surface;
     }
 
-    ff_vdpau_add_data_chunk(s, buf, buf_size);
+    ff_vdpau_add_data_chunk(s->current_picture_ptr->f.data[0], buf, buf_size);
 
     render->info.mpeg.slice_count                = slice_count;
 
     if (slice_count)
-        ff_draw_horiz_band(s, 0, s->avctx->height);
+        ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
     render->bitstream_buffers_used               = 0;
 }
 
@@ -308,11 +349,11 @@ void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf,
         render->info.vc1.forward_reference = last->surface;
     }
 
-    ff_vdpau_add_data_chunk(s, buf, buf_size);
+    ff_vdpau_add_data_chunk(s->current_picture_ptr->f.data[0], buf, buf_size);
 
     render->info.vc1.slice_count          = 1;
 
-    ff_draw_horiz_band(s, 0, s->avctx->height);
+    ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
     render->bitstream_buffers_used        = 0;
 }
 
@@ -364,46 +405,10 @@ void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf,
         render->info.mpeg4.forward_reference      = last->surface;
     }
 
-    ff_vdpau_add_data_chunk(s, buf, buf_size);
+    ff_vdpau_add_data_chunk(s->current_picture_ptr->f.data[0], buf, buf_size);
 
-    ff_draw_horiz_band(s, 0, s->avctx->height);
+    ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
     render->bitstream_buffers_used = 0;
 }
 
-// Only dummy functions for now
-static int vdpau_mpeg2_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
-{
-    return 0;
-}
-
-static int vdpau_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
-{
-    return 0;
-}
-
-static int vdpau_mpeg2_end_frame(AVCodecContext *avctx)
-{
-    return 0;
-}
-
-AVHWAccel ff_mpeg1_vdpau_hwaccel = {
-    .name           = "mpeg1_vdpau",
-    .type           = AVMEDIA_TYPE_VIDEO,
-    .id             = AV_CODEC_ID_MPEG1VIDEO,
-    .pix_fmt        = AV_PIX_FMT_VDPAU_MPEG1,
-    .start_frame    = vdpau_mpeg2_start_frame,
-    .end_frame      = vdpau_mpeg2_end_frame,
-    .decode_slice   = vdpau_mpeg2_decode_slice,
-};
-
-AVHWAccel ff_mpeg2_vdpau_hwaccel = {
-    .name           = "mpeg2_vdpau",
-    .type           = AVMEDIA_TYPE_VIDEO,
-    .id             = AV_CODEC_ID_MPEG2VIDEO,
-    .pix_fmt        = AV_PIX_FMT_VDPAU_MPEG2,
-    .start_frame    = vdpau_mpeg2_start_frame,
-    .end_frame      = vdpau_mpeg2_end_frame,
-    .decode_slice   = vdpau_mpeg2_decode_slice,
-};
-
 /* @}*/
diff --git a/mythtv/external/FFmpeg/libavcodec/vdpau.h b/mythtv/external/FFmpeg/libavcodec/vdpau.h
index 23394b57a39..df2aaced266 100644
--- a/mythtv/external/FFmpeg/libavcodec/vdpau.h
+++ b/mythtv/external/FFmpeg/libavcodec/vdpau.h
@@ -52,6 +52,68 @@
 #include 
 #include 
 
+union FFVdpPictureInfo {
+    VdpPictureInfoH264        h264;
+    VdpPictureInfoMPEG1Or2    mpeg;
+    VdpPictureInfoVC1          vc1;
+    VdpPictureInfoMPEG4Part2 mpeg4;
+};
+
+/**
+ * This structure is used to share data between the libavcodec library and
+ * the client video application.
+ * The user shall zero-allocate the structure and make it available as
+ * AVCodecContext.hwaccel_context. Members can be set by the user once
+ * during initialization or through each AVCodecContext.get_buffer()
+ * function call. In any case, they must be valid prior to calling
+ * decoding functions.
+ */
+typedef struct AVVDPAUContext {
+    /**
+     * VDPAU decoder handle
+     *
+     * Set by user.
+     */
+    VdpDecoder decoder;
+
+    /**
+     * VDPAU decoder render callback
+     *
+     * Set by the user.
+     */
+    VdpDecoderRender *render;
+
+    /**
+     * VDPAU picture information
+     *
+     * Set by libavcodec.
+     */
+    union FFVdpPictureInfo info;
+
+    /**
+     * Allocated size of the bitstream_buffers table.
+     *
+     * Set by libavcodec.
+     */
+    int bitstream_buffers_allocated;
+
+    /**
+     * Useful bitstream buffers in the bitstream buffers table.
+     *
+     * Set by libavcodec.
+     */
+    int bitstream_buffers_used;
+
+   /**
+     * Table of bitstream buffers.
+     * The user is responsible for freeing this buffer using av_freep().
+     *
+     * Set by libavcodec.
+     */
+    VdpBitstreamBuffer *bitstream_buffers;
+} AVVDPAUContext;
+
+
 /** @brief The videoSurface is used for rendering. */
 #define FF_VDPAU_STATE_USED_FOR_RENDER 1
 
@@ -81,12 +143,7 @@ struct vdpau_render_state {
     VdpBitstreamBuffer *bitstream_buffers;
 
     /** picture parameter information for all supported codecs */
-    union VdpPictureInfo {
-        VdpPictureInfoH264        h264;
-        VdpPictureInfoMPEG1Or2    mpeg;
-        VdpPictureInfoVC1          vc1;
-        VdpPictureInfoMPEG4Part2 mpeg4;
-    } info;
+    union FFVdpPictureInfo info;
 };
 
 /* @}*/
diff --git a/mythtv/external/FFmpeg/libavcodec/vdpau_h264.c b/mythtv/external/FFmpeg/libavcodec/vdpau_h264.c
new file mode 100644
index 00000000000..0f79c5868fc
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/vdpau_h264.c
@@ -0,0 +1,210 @@
+/*
+ * MPEG-4 Part 10 / AVC / H.264 HW decode acceleration through VDPAU
+ *
+ * Copyright (c) 2008 NVIDIA
+ * Copyright (c) 2013 Rémi Denis-Courmont
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "avcodec.h"
+#include "h264.h"
+#include "vdpau.h"
+#include "vdpau_internal.h"
+
+static int32_t h264_foc(int foc)
+{
+    if (foc == INT_MAX)
+        foc = 0;
+    return foc;
+}
+
+static void vdpau_h264_clear_rf(VdpReferenceFrameH264 *rf)
+{
+    rf->surface             = VDP_INVALID_HANDLE;
+    rf->is_long_term        = VDP_FALSE;
+    rf->top_is_reference    = VDP_FALSE;
+    rf->bottom_is_reference = VDP_FALSE;
+    rf->field_order_cnt[0]  = 0;
+    rf->field_order_cnt[1]  = 0;
+    rf->frame_idx           = 0;
+}
+
+static void vdpau_h264_set_rf(VdpReferenceFrameH264 *rf, Picture *pic,
+                              int pic_structure)
+{
+    VdpVideoSurface surface = ff_vdpau_get_surface_id(pic);
+
+    if (pic_structure == 0)
+        pic_structure = pic->f.reference;
+
+    rf->surface             = surface;
+    rf->is_long_term        = pic->f.reference && pic->long_ref;
+    rf->top_is_reference    = (pic_structure & PICT_TOP_FIELD)    != 0;
+    rf->bottom_is_reference = (pic_structure & PICT_BOTTOM_FIELD) != 0;
+    rf->field_order_cnt[0]  = h264_foc(pic->field_poc[0]);
+    rf->field_order_cnt[1]  = h264_foc(pic->field_poc[1]);
+    rf->frame_idx           = pic->long_ref ? pic->pic_id : pic->frame_num;
+}
+
+static void vdpau_h264_set_reference_frames(AVCodecContext *avctx)
+{
+    H264Context * const h = avctx->priv_data;
+    AVVDPAUContext *hwctx = avctx->hwaccel_context;
+    VdpPictureInfoH264 *info = &hwctx->info.h264;
+    int list;
+
+    VdpReferenceFrameH264 *rf = &info->referenceFrames[0];
+#define H264_RF_COUNT FF_ARRAY_ELEMS(info->referenceFrames)
+
+    for (list = 0; list < 2; ++list) {
+        Picture **lp = list ? h->long_ref : h->short_ref;
+        int i, ls    = list ? 16          : h->short_ref_count;
+
+        for (i = 0; i < ls; ++i) {
+            Picture *pic = lp[i];
+            VdpReferenceFrameH264 *rf2;
+            VdpVideoSurface surface_ref;
+            int pic_frame_idx;
+
+            if (!pic || !pic->f.reference)
+                continue;
+            pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num;
+            surface_ref = ff_vdpau_get_surface_id(pic);
+
+            rf2 = &info->referenceFrames[0];
+            while (rf2 != rf) {
+                if ((rf2->surface      == surface_ref)   &&
+                    (rf2->is_long_term == pic->long_ref) &&
+                    (rf2->frame_idx    == pic_frame_idx))
+                    break;
+                ++rf2;
+            }
+            if (rf2 != rf) {
+                rf2->top_is_reference    |= (pic->f.reference & PICT_TOP_FIELD)    ? VDP_TRUE : VDP_FALSE;
+                rf2->bottom_is_reference |= (pic->f.reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
+                continue;
+            }
+
+            if (rf >= &info->referenceFrames[H264_RF_COUNT])
+                continue;
+
+            vdpau_h264_set_rf(rf, pic, pic->f.reference);
+            ++rf;
+        }
+    }
+
+    for (; rf < &info->referenceFrames[H264_RF_COUNT]; ++rf)
+        vdpau_h264_clear_rf(rf);
+}
+
+static int vdpau_h264_start_frame(AVCodecContext *avctx,
+                                  const uint8_t *buffer, uint32_t size)
+{
+    H264Context * const h = avctx->priv_data;
+    AVVDPAUContext *hwctx = avctx->hwaccel_context;
+    VdpPictureInfoH264 *info = &hwctx->info.h264;
+    Picture *pic = h->cur_pic_ptr;
+
+    /* init VdpPictureInfoH264 */
+    info->slice_count                            = 0;
+    info->field_order_cnt[0]                     = h264_foc(pic->field_poc[0]);
+    info->field_order_cnt[1]                     = h264_foc(pic->field_poc[1]);
+    info->is_reference                           = h->nal_ref_idc != 0;
+    info->frame_num                              = h->frame_num;
+    info->field_pic_flag                         = h->picture_structure != PICT_FRAME;
+    info->bottom_field_flag                      = h->picture_structure == PICT_BOTTOM_FIELD;
+    info->num_ref_frames                         = h->sps.ref_frame_count;
+    info->mb_adaptive_frame_field_flag           = h->sps.mb_aff && !info->field_pic_flag;
+    info->constrained_intra_pred_flag            = h->pps.constrained_intra_pred;
+    info->weighted_pred_flag                     = h->pps.weighted_pred;
+    info->weighted_bipred_idc                    = h->pps.weighted_bipred_idc;
+    info->frame_mbs_only_flag                    = h->sps.frame_mbs_only_flag;
+    info->transform_8x8_mode_flag                = h->pps.transform_8x8_mode;
+    info->chroma_qp_index_offset                 = h->pps.chroma_qp_index_offset[0];
+    info->second_chroma_qp_index_offset          = h->pps.chroma_qp_index_offset[1];
+    info->pic_init_qp_minus26                    = h->pps.init_qp - 26;
+    info->num_ref_idx_l0_active_minus1           = h->pps.ref_count[0] - 1;
+    info->num_ref_idx_l1_active_minus1           = h->pps.ref_count[1] - 1;
+    info->log2_max_frame_num_minus4              = h->sps.log2_max_frame_num - 4;
+    info->pic_order_cnt_type                     = h->sps.poc_type;
+    info->log2_max_pic_order_cnt_lsb_minus4      = h->sps.poc_type ? 0 : h->sps.log2_max_poc_lsb - 4;
+    info->delta_pic_order_always_zero_flag       = h->sps.delta_pic_order_always_zero_flag;
+    info->direct_8x8_inference_flag              = h->sps.direct_8x8_inference_flag;
+    info->entropy_coding_mode_flag               = h->pps.cabac;
+    info->pic_order_present_flag                 = h->pps.pic_order_present;
+    info->deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present;
+    info->redundant_pic_cnt_present_flag         = h->pps.redundant_pic_cnt_present;
+
+    memcpy(info->scaling_lists_4x4, h->pps.scaling_matrix4,
+           sizeof(info->scaling_lists_4x4));
+    memcpy(info->scaling_lists_8x8[0], h->pps.scaling_matrix8[0],
+           sizeof(info->scaling_lists_8x8[0]));
+    memcpy(info->scaling_lists_8x8[1], h->pps.scaling_matrix8[3],
+           sizeof(info->scaling_lists_8x8[1]));
+
+    vdpau_h264_set_reference_frames(avctx);
+
+    return ff_vdpau_common_start_frame(avctx, buffer, size);
+}
+
+static const uint8_t start_code_prefix[3] = { 0x00, 0x00, 0x01 };
+
+static int vdpau_h264_decode_slice(AVCodecContext *avctx,
+                                   const uint8_t *buffer, uint32_t size)
+{
+    AVVDPAUContext *hwctx = avctx->hwaccel_context;
+    int val;
+
+    val = ff_vdpau_add_buffer(avctx, start_code_prefix, 3);
+    if (val)
+        return val;
+
+    val = ff_vdpau_add_buffer(avctx, buffer, size);
+    if (val)
+        return val;
+
+    hwctx->info.h264.slice_count++;
+    return 0;
+}
+
+static int vdpau_h264_end_frame(AVCodecContext *avctx)
+{
+    AVVDPAUContext *hwctx = avctx->hwaccel_context;
+    H264Context *h = avctx->priv_data;
+    VdpVideoSurface surf = ff_vdpau_get_surface_id(h->cur_pic_ptr);
+
+    hwctx->render(hwctx->decoder, surf, (void *)&hwctx->info,
+                  hwctx->bitstream_buffers_used, hwctx->bitstream_buffers);
+
+    ff_h264_draw_horiz_band(h, 0, h->avctx->height);
+    hwctx->bitstream_buffers_used = 0;
+
+    return 0;
+}
+
+AVHWAccel ff_h264_vdpau_hwaccel = {
+    .name           = "h264_vdpau",
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_H264,
+    .pix_fmt        = AV_PIX_FMT_VDPAU,
+    .start_frame    = vdpau_h264_start_frame,
+    .end_frame      = vdpau_h264_end_frame,
+    .decode_slice   = vdpau_h264_decode_slice,
+};
diff --git a/mythtv/external/FFmpeg/libavcodec/vdpau_internal.h b/mythtv/external/FFmpeg/libavcodec/vdpau_internal.h
index 0a8d0b6b556..790b3efe6d3 100644
--- a/mythtv/external/FFmpeg/libavcodec/vdpau_internal.h
+++ b/mythtv/external/FFmpeg/libavcodec/vdpau_internal.h
@@ -25,17 +25,31 @@
 #define AVCODEC_VDPAU_INTERNAL_H
 
 #include 
+#include "h264.h"
 #include "mpegvideo.h"
 
-void ff_vdpau_add_data_chunk(MpegEncContext *s, const uint8_t *buf,
+/** Extract VdpVideoSurface from a Picture */
+static inline uintptr_t ff_vdpau_get_surface_id(Picture *pic)
+{
+    return (uintptr_t)pic->f.data[3];
+}
+
+int ff_vdpau_common_start_frame(AVCodecContext *avctx,
+                                const uint8_t *buffer, uint32_t size);
+int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx);
+int ff_vdpau_add_buffer(AVCodecContext *avctx,
+                        const uint8_t *buf, uint32_t buf_size);
+
+
+void ff_vdpau_add_data_chunk(uint8_t *data, const uint8_t *buf,
                              int buf_size);
 
 void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf,
                                     int buf_size, int slice_count);
 
-void ff_vdpau_h264_picture_start(MpegEncContext *s);
-void ff_vdpau_h264_set_reference_frames(MpegEncContext *s);
-void ff_vdpau_h264_picture_complete(MpegEncContext *s);
+void ff_vdpau_h264_picture_start(H264Context *h);
+void ff_vdpau_h264_set_reference_frames(H264Context *h);
+void ff_vdpau_h264_picture_complete(H264Context *h);
 
 void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf,
                                  int buf_size);
diff --git a/mythtv/external/FFmpeg/libavcodec/vdpau_mpeg12.c b/mythtv/external/FFmpeg/libavcodec/vdpau_mpeg12.c
new file mode 100644
index 00000000000..74e3f16f5b0
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/vdpau_mpeg12.c
@@ -0,0 +1,116 @@
+/*
+ * MPEG-1/2 HW decode acceleration through VDPAU
+ *
+ * Copyright (c) 2008 NVIDIA
+ * Copyright (c) 2013 Rémi Denis-Courmont
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "avcodec.h"
+#include "vdpau.h"
+#include "vdpau_internal.h"
+
+static int vdpau_mpeg_start_frame(AVCodecContext *avctx,
+                                  const uint8_t *buffer, uint32_t size)
+{
+    MpegEncContext * const s = avctx->priv_data;
+    AVVDPAUContext *hwctx    = avctx->hwaccel_context;
+    VdpPictureInfoMPEG1Or2 *info = &hwctx->info.mpeg;
+    VdpVideoSurface ref;
+    int i;
+
+    /* fill VdpPictureInfoMPEG1Or2 struct */
+    info->forward_reference  = VDP_INVALID_HANDLE;
+    info->backward_reference = VDP_INVALID_HANDLE;
+
+    switch (s->pict_type) {
+    case AV_PICTURE_TYPE_B:
+        ref = ff_vdpau_get_surface_id(&s->next_picture);
+        assert(ref != VDP_INVALID_HANDLE);
+        hwctx->info.mpeg.backward_reference = ref;
+        /* fall through to forward prediction */
+    case AV_PICTURE_TYPE_P:
+        ref = ff_vdpau_get_surface_id(&s->last_picture);
+        hwctx->info.mpeg.forward_reference  = ref;
+    }
+
+    info->slice_count                = 0;
+    info->picture_structure          = s->picture_structure;
+    info->picture_coding_type        = s->pict_type;
+    info->intra_dc_precision         = s->intra_dc_precision;
+    info->frame_pred_frame_dct       = s->frame_pred_frame_dct;
+    info->concealment_motion_vectors = s->concealment_motion_vectors;
+    info->intra_vlc_format           = s->intra_vlc_format;
+    info->alternate_scan             = s->alternate_scan;
+    info->q_scale_type               = s->q_scale_type;
+    info->top_field_first            = s->top_field_first;
+    // Both for MPEG-1 only, zero for MPEG-2:
+    info->full_pel_forward_vector    = s->full_pel[0];
+    info->full_pel_backward_vector   = s->full_pel[1];
+    // For MPEG-1 fill both horizontal & vertical:
+    info->f_code[0][0]               = s->mpeg_f_code[0][0];
+    info->f_code[0][1]               = s->mpeg_f_code[0][1];
+    info->f_code[1][0]               = s->mpeg_f_code[1][0];
+    info->f_code[1][1]               = s->mpeg_f_code[1][1];
+    for (i = 0; i < 64; ++i) {
+        info->intra_quantizer_matrix[i]     = s->intra_matrix[i];
+        info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
+    }
+
+    return ff_vdpau_common_start_frame(avctx, buffer, size);
+}
+
+static int vdpau_mpeg_decode_slice(AVCodecContext *avctx,
+                                   const uint8_t *buffer, uint32_t size)
+{
+    AVVDPAUContext *hwctx = avctx->hwaccel_context;
+    int val;
+
+    val = ff_vdpau_add_buffer(avctx, buffer, size);
+    if (val < 0)
+        return val;
+
+    hwctx->info.mpeg.slice_count++;
+    return 0;
+}
+
+#if CONFIG_MPEG1_VDPAU_HWACCEL
+AVHWAccel ff_mpeg1_vdpau_hwaccel = {
+    .name           = "mpeg1_vdpau",
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_MPEG1VIDEO,
+    .pix_fmt        = AV_PIX_FMT_VDPAU,
+    .start_frame    = vdpau_mpeg_start_frame,
+    .end_frame      = ff_vdpau_mpeg_end_frame,
+    .decode_slice   = vdpau_mpeg_decode_slice,
+};
+#endif
+
+#if CONFIG_MPEG2_VDPAU_HWACCEL
+AVHWAccel ff_mpeg2_vdpau_hwaccel = {
+    .name           = "mpeg2_vdpau",
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_MPEG2VIDEO,
+    .pix_fmt        = AV_PIX_FMT_VDPAU,
+    .start_frame    = vdpau_mpeg_start_frame,
+    .end_frame      = ff_vdpau_mpeg_end_frame,
+    .decode_slice   = vdpau_mpeg_decode_slice,
+};
+#endif
diff --git a/mythtv/external/FFmpeg/libavcodec/vdpau_mpeg4.c b/mythtv/external/FFmpeg/libavcodec/vdpau_mpeg4.c
new file mode 100644
index 00000000000..cb8ee0a40ca
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/vdpau_mpeg4.c
@@ -0,0 +1,110 @@
+/*
+ * MPEG-4 Part 2 / H.263 decode acceleration through VDPAU
+ *
+ * Copyright (c) 2008 NVIDIA
+ * Copyright (c) 2013 Rémi Denis-Courmont
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "avcodec.h"
+#include "vdpau.h"
+#include "vdpau_internal.h"
+
+static int vdpau_mpeg4_start_frame(AVCodecContext *avctx,
+                                   const uint8_t *buffer, uint32_t size)
+{
+    MpegEncContext * const s = avctx->priv_data;
+    AVVDPAUContext *hwctx    = avctx->hwaccel_context;
+    VdpPictureInfoMPEG4Part2 *info = &hwctx->info.mpeg4;
+    VdpVideoSurface ref;
+    int i;
+
+    /* fill VdpPictureInfoMPEG4Part2 struct */
+    info->forward_reference  = VDP_INVALID_HANDLE;
+    info->backward_reference = VDP_INVALID_HANDLE;
+    info->vop_coding_type    = 0;
+
+    switch (s->pict_type) {
+    case AV_PICTURE_TYPE_B:
+        ref = ff_vdpau_get_surface_id(&s->next_picture);
+        assert(ref != VDP_INVALID_HANDLE);
+        info->backward_reference = ref;
+        info->vop_coding_type    = 2;
+        /* fall-through */
+    case AV_PICTURE_TYPE_P:
+        ref = ff_vdpau_get_surface_id(&s->last_picture);
+        assert(ref != VDP_INVALID_HANDLE);
+        info->forward_reference  = ref;
+    }
+
+    info->trd[0]                            = s->pp_time;
+    info->trb[0]                            = s->pb_time;
+    info->trd[1]                            = s->pp_field_time >> 1;
+    info->trb[1]                            = s->pb_field_time >> 1;
+    info->vop_time_increment_resolution     = s->avctx->time_base.den;
+    info->vop_fcode_forward                 = s->f_code;
+    info->vop_fcode_backward                = s->b_code;
+    info->resync_marker_disable             = !s->resync_marker;
+    info->interlaced                        = !s->progressive_sequence;
+    info->quant_type                        = s->mpeg_quant;
+    info->quarter_sample                    = s->quarter_sample;
+    info->short_video_header                = avctx->codec->id == AV_CODEC_ID_H263;
+    info->rounding_control                  = s->no_rounding;
+    info->alternate_vertical_scan_flag      = s->alternate_scan;
+    info->top_field_first                   = s->top_field_first;
+    for (i = 0; i < 64; ++i) {
+        info->intra_quantizer_matrix[i]     = s->intra_matrix[i];
+        info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
+    }
+
+    ff_vdpau_common_start_frame(avctx, buffer, size);
+    return ff_vdpau_add_buffer(avctx, buffer, size);
+}
+
+static int vdpau_mpeg4_decode_slice(av_unused AVCodecContext *avctx,
+                                    av_unused const uint8_t *buffer,
+                                    av_unused uint32_t size)
+{
+     return 0;
+}
+
+#if CONFIG_H263_VDPAU_HWACCEL
+AVHWAccel ff_h263_vdpau_hwaccel = {
+    .name           = "h263_vdpau",
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_H263,
+    .pix_fmt        = AV_PIX_FMT_VDPAU,
+    .start_frame    = vdpau_mpeg4_start_frame,
+    .end_frame      = ff_vdpau_mpeg_end_frame,
+    .decode_slice   = vdpau_mpeg4_decode_slice,
+};
+#endif
+
+#if CONFIG_MPEG4_VDPAU_HWACCEL
+AVHWAccel ff_mpeg4_vdpau_hwaccel = {
+    .name           = "mpeg4_vdpau",
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_MPEG4,
+    .pix_fmt        = AV_PIX_FMT_VDPAU,
+    .start_frame    = vdpau_mpeg4_start_frame,
+    .end_frame      = ff_vdpau_mpeg_end_frame,
+    .decode_slice   = vdpau_mpeg4_decode_slice,
+};
+#endif
diff --git a/mythtv/external/FFmpeg/libavcodec/vdpau_vc1.c b/mythtv/external/FFmpeg/libavcodec/vdpau_vc1.c
new file mode 100644
index 00000000000..f5da9bbe1f5
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/vdpau_vc1.c
@@ -0,0 +1,128 @@
+/*
+ * VC-1 decode acceleration through VDPAU
+ *
+ * Copyright (c) 2008 NVIDIA
+ * Copyright (c) 2013 Rémi Denis-Courmont
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "avcodec.h"
+#include "vc1.h"
+#include "vdpau.h"
+#include "vdpau_internal.h"
+
+static int vdpau_vc1_start_frame(AVCodecContext *avctx,
+                                 const uint8_t *buffer, uint32_t size)
+{
+    VC1Context * const v  = avctx->priv_data;
+    AVVDPAUContext *hwctx = avctx->hwaccel_context;
+    MpegEncContext * const s = &v->s;
+    VdpPictureInfoVC1 *info = &hwctx->info.vc1;
+    VdpVideoSurface ref;
+
+    /*  fill LvPictureInfoVC1 struct */
+    info->forward_reference  = VDP_INVALID_HANDLE;
+    info->backward_reference = VDP_INVALID_HANDLE;
+
+    switch (s->pict_type) {
+    case AV_PICTURE_TYPE_B:
+        ref = ff_vdpau_get_surface_id(&s->next_picture);
+        assert(ref != VDP_INVALID_HANDLE);
+        info->backward_reference = ref;
+        /* fall-through */
+    case AV_PICTURE_TYPE_P:
+        ref = ff_vdpau_get_surface_id(&s->last_picture);
+        assert(ref != VDP_INVALID_HANDLE);
+        info->forward_reference  = ref;
+    }
+
+    info->slice_count       = 0;
+    if (v->bi_type)
+        info->picture_type  = 4;
+    else
+        info->picture_type  = s->pict_type - 1 + s->pict_type / 3;
+
+    info->frame_coding_mode = v->fcm;
+    info->postprocflag      = v->postprocflag;
+    info->pulldown          = v->broadcast;
+    info->interlace         = v->interlace;
+    info->tfcntrflag        = v->tfcntrflag;
+    info->finterpflag       = v->finterpflag;
+    info->psf               = v->psf;
+    info->dquant            = v->dquant;
+    info->panscan_flag      = v->panscanflag;
+    info->refdist_flag      = v->refdist_flag;
+    info->quantizer         = v->quantizer_mode;
+    info->extended_mv       = v->extended_mv;
+    info->extended_dmv      = v->extended_dmv;
+    info->overlap           = v->overlap;
+    info->vstransform       = v->vstransform;
+    info->loopfilter        = v->s.loop_filter;
+    info->fastuvmc          = v->fastuvmc;
+    info->range_mapy_flag   = v->range_mapy_flag;
+    info->range_mapy        = v->range_mapy;
+    info->range_mapuv_flag  = v->range_mapuv_flag;
+    info->range_mapuv       = v->range_mapuv;
+    /* Specific to simple/main profile only */
+    info->multires          = v->multires;
+    info->syncmarker        = v->s.resync_marker;
+    info->rangered          = v->rangered | (v->rangeredfrm << 1);
+    info->maxbframes        = v->s.max_b_frames;
+    info->deblockEnable     = v->postprocflag & 1;
+    info->pquant            = v->pq;
+
+    return ff_vdpau_common_start_frame(avctx, buffer, size);
+}
+
+static int vdpau_vc1_decode_slice(AVCodecContext *avctx,
+                                  const uint8_t *buffer, uint32_t size)
+{
+    AVVDPAUContext *hwctx = avctx->hwaccel_context;
+    int val;
+
+    val = ff_vdpau_add_buffer(avctx, buffer, size);
+    if (val < 0)
+        return val;
+
+    hwctx->info.vc1.slice_count++;
+    return 0;
+}
+
+#if CONFIG_WMV3_VDPAU_HWACCEL
+AVHWAccel ff_wmv3_vdpau_hwaccel = {
+    .name           = "wm3_vdpau",
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_WMV3,
+    .pix_fmt        = AV_PIX_FMT_VDPAU,
+    .start_frame    = vdpau_vc1_start_frame,
+    .end_frame      = ff_vdpau_mpeg_end_frame,
+    .decode_slice   = vdpau_vc1_decode_slice,
+};
+#endif
+
+AVHWAccel ff_vc1_vdpau_hwaccel = {
+    .name           = "vc1_vdpau",
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_VC1,
+    .pix_fmt        = AV_PIX_FMT_VDPAU,
+    .start_frame    = vdpau_vc1_start_frame,
+    .end_frame      = ff_vdpau_mpeg_end_frame,
+    .decode_slice   = vdpau_vc1_decode_slice,
+};
diff --git a/mythtv/external/FFmpeg/libavcodec/version.h b/mythtv/external/FFmpeg/libavcodec/version.h
index f9d87f40b12..67fdc252159 100644
--- a/mythtv/external/FFmpeg/libavcodec/version.h
+++ b/mythtv/external/FFmpeg/libavcodec/version.h
@@ -29,7 +29,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 54
-#define LIBAVCODEC_VERSION_MINOR 86
+#define LIBAVCODEC_VERSION_MINOR 92
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
@@ -103,5 +103,11 @@
 #ifndef FF_API_MMI
 #define FF_API_MMI               (LIBAVCODEC_VERSION_MAJOR < 55)
 #endif
+#ifndef FF_API_IDCT
+#define FF_API_IDCT              (LIBAVCODEC_VERSION_MAJOR < 55)
+#endif
+#ifndef FF_API_DEINTERLACE
+#define FF_API_DEINTERLACE       (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
 
 #endif /* AVCODEC_VERSION_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/videodsp.h b/mythtv/external/FFmpeg/libavcodec/videodsp.h
index dc893847b38..e3977207738 100644
--- a/mythtv/external/FFmpeg/libavcodec/videodsp.h
+++ b/mythtv/external/FFmpeg/libavcodec/videodsp.h
@@ -29,6 +29,14 @@
 #include 
 #include 
 
+#define EMULATED_EDGE(depth) \
+void ff_emulated_edge_mc_ ## depth (uint8_t *buf, const uint8_t *src, ptrdiff_t linesize,\
+                         int block_w, int block_h,\
+                         int src_x, int src_y, int w, int h);
+
+EMULATED_EDGE(8)
+EMULATED_EDGE(16)
+
 typedef struct VideoDSPContext {
     /**
      * Copy a rectangular area of samples to a temporary buffer and replicate
diff --git a/mythtv/external/FFmpeg/libavcodec/vima.c b/mythtv/external/FFmpeg/libavcodec/vima.c
index f823cb37e7a..604e0ce1102 100644
--- a/mythtv/external/FFmpeg/libavcodec/vima.c
+++ b/mythtv/external/FFmpeg/libavcodec/vima.c
@@ -26,7 +26,6 @@
 #include "adpcm_data.h"
 
 typedef struct {
-    AVFrame     frame;
     uint16_t    predict_table[5786 * 2];
 } VimaContext;
 
@@ -125,8 +124,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
         }
     }
 
-    avcodec_get_frame_defaults(&vima->frame);
-    avctx->coded_frame = &vima->frame;
     avctx->sample_fmt  = AV_SAMPLE_FMT_S16;
 
     return 0;
@@ -137,6 +134,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 {
     GetBitContext  gb;
     VimaContext    *vima = avctx->priv_data;
+    AVFrame        *frame = data;
     int16_t        pcm_data[2];
     uint32_t       samples;
     int8_t         channel_hint[2];
@@ -145,7 +143,8 @@ static int decode_frame(AVCodecContext *avctx, void *data,
     if (pkt->size < 13)
         return AVERROR_INVALIDDATA;
 
-    init_get_bits(&gb, pkt->data, pkt->size * 8);
+    if ((ret = init_get_bits8(&gb, pkt->data, pkt->size)) < 0)
+        return ret;
 
     samples = get_bits_long(&gb, 32);
     if (samples == 0xffffffff) {
@@ -170,14 +169,14 @@ static int decode_frame(AVCodecContext *avctx, void *data,
         pcm_data[1] = get_sbits(&gb, 16);
     }
 
-    vima->frame.nb_samples = samples;
-    if ((ret = ff_get_buffer(avctx, &vima->frame)) < 0) {
+    frame->nb_samples = samples;
+    if ((ret = ff_get_buffer(avctx, frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
 
     for (chan = 0; chan < channels; chan++) {
-        uint16_t *dest = (uint16_t*)vima->frame.data[0] + chan;
+        uint16_t *dest = (uint16_t*)frame->data[0] + chan;
         int step_index = channel_hint[chan];
         int output = pcm_data[chan];
         int sample;
@@ -220,7 +219,6 @@ static int decode_frame(AVCodecContext *avctx, void *data,
     }
 
     *got_frame_ptr   = 1;
-    *(AVFrame *)data = vima->frame;
 
     return pkt->size;
 }
diff --git a/mythtv/external/FFmpeg/libavcodec/vmdav.c b/mythtv/external/FFmpeg/libavcodec/vmdav.c
index 9c96055b621..79a33b867fa 100644
--- a/mythtv/external/FFmpeg/libavcodec/vmdav.c
+++ b/mythtv/external/FFmpeg/libavcodec/vmdav.c
@@ -162,7 +162,7 @@ static int rle_unpack(const unsigned char *src, int src_len, int src_count,
     const unsigned char *ps;
     const unsigned char *ps_end;
     unsigned char *pd;
-    int i, l;
+    int i, j, l;
     unsigned char *dest_end = dest + dest_len;
 
     ps = src;
@@ -188,9 +188,9 @@ static int rle_unpack(const unsigned char *src, int src_len, int src_count,
             ps += l;
             pd += l;
         } else {
-            if (dest_end - pd < i || ps_end - ps < 2)
+            if (dest_end - pd < 2*l || ps_end - ps < 2)
                 return ps - src;
-            for (i = 0; i < l; i++) {
+            for (j = 0; j < l; j++) {
                 *pd++ = ps[0];
                 *pd++ = ps[1];
             }
@@ -469,7 +469,6 @@ static av_cold int vmdvideo_decode_end(AVCodecContext *avctx)
 #define BLOCK_TYPE_SILENCE  3
 
 typedef struct VmdAudioContext {
-    AVFrame frame;
     int out_bps;
     int chunk_size;
 } VmdAudioContext;
@@ -514,9 +513,6 @@ static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
 
     s->chunk_size = avctx->block_align + avctx->channels * (s->out_bps == 2);
 
-    avcodec_get_frame_defaults(&s->frame);
-    avctx->coded_frame = &s->frame;
-
     av_log(avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, "
            "block align = %d, sample rate = %d\n",
            avctx->channels, avctx->bits_per_coded_sample, avctx->block_align,
@@ -557,6 +553,7 @@ static void decode_audio_s16(int16_t *out, const uint8_t *buf, int buf_size,
 static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
                                  int *got_frame_ptr, AVPacket *avpkt)
 {
+    AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
     const uint8_t *buf_end;
     int buf_size = avpkt->size;
@@ -601,13 +598,14 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
     audio_chunks = buf_size / s->chunk_size;
 
     /* get output buffer */
-    s->frame.nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) / avctx->channels;
-    if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
+    frame->nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) /
+                        avctx->channels;
+    if ((ret = ff_get_buffer(avctx, frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
-    output_samples_u8  = s->frame.data[0];
-    output_samples_s16 = (int16_t *)s->frame.data[0];
+    output_samples_u8  =            frame->data[0];
+    output_samples_s16 = (int16_t *)frame->data[0];
 
     /* decode silent chunks */
     if (silent_chunks > 0) {
@@ -624,7 +622,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
     /* decode audio chunks */
     if (audio_chunks > 0) {
         buf_end = buf + buf_size;
-        while (buf_end - buf >= s->chunk_size) {
+        while ( buf_end - buf >= s->chunk_size) {
             if (s->out_bps == 2) {
                 decode_audio_s16(output_samples_s16, buf, s->chunk_size,
                                  avctx->channels);
@@ -637,8 +635,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
         }
     }
 
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = s->frame;
+    *got_frame_ptr = 1;
 
     return avpkt->size;
 }
diff --git a/mythtv/external/FFmpeg/libavcodec/vorbis.c b/mythtv/external/FFmpeg/libavcodec/vorbis.c
index adf08b5fb91..6eb765d7d0f 100644
--- a/mythtv/external/FFmpeg/libavcodec/vorbis.c
+++ b/mythtv/external/FFmpeg/libavcodec/vorbis.c
@@ -121,7 +121,7 @@ int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, unsigned num)
     return 0;
 }
 
-int ff_vorbis_ready_floor1_list(AVCodecContext *avccontext,
+int ff_vorbis_ready_floor1_list(AVCodecContext *avctx,
                                 vorbis_floor1_entry *list, int values)
 {
     int i;
@@ -147,7 +147,7 @@ int ff_vorbis_ready_floor1_list(AVCodecContext *avccontext,
         int j;
         for (j = i + 1; j < values; j++) {
             if (list[i].x == list[j].x) {
-                av_log(avccontext, AV_LOG_ERROR,
+                av_log(avctx, AV_LOG_ERROR,
                        "Duplicate value found in floor 1 X coordinates\n");
                 return AVERROR_INVALIDDATA;
             }
diff --git a/mythtv/external/FFmpeg/libavcodec/vorbis.h b/mythtv/external/FFmpeg/libavcodec/vorbis.h
index 0bab0b9c0fd..98dd14f9d45 100644
--- a/mythtv/external/FFmpeg/libavcodec/vorbis.h
+++ b/mythtv/external/FFmpeg/libavcodec/vorbis.h
@@ -36,14 +36,14 @@ typedef struct vorbis_floor1_entry {
     uint16_t high;
 } vorbis_floor1_entry;
 
-int ff_vorbis_ready_floor1_list(AVCodecContext *avccontext,
+int ff_vorbis_ready_floor1_list(AVCodecContext *avctx,
                                 vorbis_floor1_entry *list, int values);
 unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n); // x^(1/n)
 int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, unsigned num);
 void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values,
                                   uint16_t *y_list, int *flag,
                                   int multiplier, float * out, int samples);
-void ff_vorbis_inverse_coupling(float *mag, float *ang, int blocksize);
+void ff_vorbis_inverse_coupling(float *mag, float *ang, intptr_t blocksize);
 
 #define ilog(i) av_log2(2*(i))
 
diff --git a/mythtv/external/FFmpeg/libavcodec/vorbis_data.c b/mythtv/external/FFmpeg/libavcodec/vorbis_data.c
index 8aa8015df5e..063a075ce05 100644
--- a/mythtv/external/FFmpeg/libavcodec/vorbis_data.c
+++ b/mythtv/external/FFmpeg/libavcodec/vorbis_data.c
@@ -20,7 +20,6 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/mem.h"
-#include "dsputil.h"
 #include "vorbis.h"
 
 const uint8_t ff_vorbis_channel_layout_offsets[8][8] = {
diff --git a/mythtv/external/FFmpeg/libavcodec/vorbisdec.c b/mythtv/external/FFmpeg/libavcodec/vorbisdec.c
index dd4a8bc810d..bd5b2e43c3e 100644
--- a/mythtv/external/FFmpeg/libavcodec/vorbisdec.c
+++ b/mythtv/external/FFmpeg/libavcodec/vorbisdec.c
@@ -34,12 +34,12 @@
 #include "libavutil/avassert.h"
 #include "avcodec.h"
 #include "get_bits.h"
-#include "dsputil.h"
 #include "fft.h"
 #include "fmtconvert.h"
 #include "internal.h"
 
 #include "vorbis.h"
+#include "vorbisdsp.h"
 #include "xiph.h"
 
 #define V_NB_BITS 8
@@ -124,10 +124,9 @@ typedef struct {
 } vorbis_mode;
 
 typedef struct vorbis_context_s {
-    AVCodecContext *avccontext;
-    AVFrame frame;
+    AVCodecContext *avctx;
     GetBitContext gb;
-    DSPContext dsp;
+    VorbisDSPContext dsp;
     AVFloatDSPContext fdsp;
     FmtConvertContext fmt_conv;
 
@@ -165,7 +164,7 @@ typedef struct vorbis_context_s {
 static const char idx_err_str[] = "Index value %d out of range (0 - %d) for %s at %s:%i\n";
 #define VALIDATE_INDEX(idx, limit) \
     if (idx >= limit) {\
-        av_log(vc->avccontext, AV_LOG_ERROR,\
+        av_log(vc->avctx, AV_LOG_ERROR,\
                idx_err_str,\
                (int)(idx), (int)(limit - 1), #idx, __FILE__, __LINE__);\
         return AVERROR_INVALIDDATA;\
@@ -240,10 +239,10 @@ static void vorbis_free(vorbis_context *vc)
 static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
 {
     unsigned cb;
-    uint8_t  *tmp_vlc_bits;
-    uint32_t *tmp_vlc_codes;
+    uint8_t  *tmp_vlc_bits  = NULL;
+    uint32_t *tmp_vlc_codes = NULL;
     GetBitContext *gb = &vc->gb;
-    uint16_t *codebook_multiplicands;
+    uint16_t *codebook_multiplicands = NULL;
     int ret = 0;
 
     vc->codebook_count = get_bits(gb, 8) + 1;
@@ -254,6 +253,11 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
     tmp_vlc_bits  = av_mallocz(V_MAX_VLCS * sizeof(*tmp_vlc_bits));
     tmp_vlc_codes = av_mallocz(V_MAX_VLCS * sizeof(*tmp_vlc_codes));
     codebook_multiplicands = av_malloc(V_MAX_VLCS * sizeof(*codebook_multiplicands));
+    if (!vc->codebooks ||
+        !tmp_vlc_bits || !tmp_vlc_codes || !codebook_multiplicands) {
+        ret = AVERROR(ENOMEM);
+        goto error;
+    }
 
     for (cb = 0; cb < vc->codebook_count; ++cb) {
         vorbis_codebook *codebook_setup = &vc->codebooks[cb];
@@ -262,7 +266,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
         av_dlog(NULL, " %u. Codebook\n", cb);
 
         if (get_bits(gb, 24) != 0x564342) {
-            av_log(vc->avccontext, AV_LOG_ERROR,
+            av_log(vc->avctx, AV_LOG_ERROR,
                    " %u. Codebook setup data corrupt.\n", cb);
             ret = AVERROR_INVALIDDATA;
             goto error;
@@ -270,7 +274,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
 
         codebook_setup->dimensions=get_bits(gb, 16);
         if (codebook_setup->dimensions > 16 || codebook_setup->dimensions == 0) {
-            av_log(vc->avccontext, AV_LOG_ERROR,
+            av_log(vc->avctx, AV_LOG_ERROR,
                    " %u. Codebook's dimension is invalid (%d).\n",
                    cb, codebook_setup->dimensions);
             ret = AVERROR_INVALIDDATA;
@@ -278,7 +282,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
         }
         entries = get_bits(gb, 24);
         if (entries > V_MAX_VLCS) {
-            av_log(vc->avccontext, AV_LOG_ERROR,
+            av_log(vc->avctx, AV_LOG_ERROR,
                    " %u. Codebook has too many entries (%u).\n",
                    cb, entries);
             ret = AVERROR_INVALIDDATA;
@@ -338,7 +342,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
                 current_entry+=number;
             }
             if (current_entry>used_entries) {
-                av_log(vc->avccontext, AV_LOG_ERROR, " More codelengths than codes in codebook. \n");
+                av_log(vc->avctx, AV_LOG_ERROR, " More codelengths than codes in codebook. \n");
                 ret = AVERROR_INVALIDDATA;
                 goto error;
             }
@@ -385,7 +389,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
                     float last = 0.0;
                     unsigned lookup_offset = i;
 
-                    av_dlog(vc->avccontext, "Lookup offset %u ,", i);
+                    av_dlog(vc->avctx, "Lookup offset %u ,", i);
 
                     for (k = 0; k < dim; ++k) {
                         unsigned multiplicand_offset = lookup_offset % codebook_lookup_values;
@@ -396,30 +400,30 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
                     }
                     tmp_vlc_bits[j] = tmp_vlc_bits[i];
 
-                    av_dlog(vc->avccontext, "real lookup offset %u, vector: ", j);
+                    av_dlog(vc->avctx, "real lookup offset %u, vector: ", j);
                     for (k = 0; k < dim; ++k)
-                        av_dlog(vc->avccontext, " %f ",
+                        av_dlog(vc->avctx, " %f ",
                                 codebook_setup->codevectors[j * dim + k]);
-                    av_dlog(vc->avccontext, "\n");
+                    av_dlog(vc->avctx, "\n");
 
                     ++j;
                 }
             }
             if (j != used_entries) {
-                av_log(vc->avccontext, AV_LOG_ERROR, "Bug in codevector vector building code. \n");
+                av_log(vc->avctx, AV_LOG_ERROR, "Bug in codevector vector building code. \n");
                 ret = AVERROR_INVALIDDATA;
                 goto error;
             }
             entries = used_entries;
         } else if (codebook_setup->lookup_type >= 2) {
-            av_log(vc->avccontext, AV_LOG_ERROR, "Codebook lookup type not supported. \n");
+            av_log(vc->avctx, AV_LOG_ERROR, "Codebook lookup type not supported. \n");
             ret = AVERROR_INVALIDDATA;
             goto error;
         }
 
 // Initialize VLC table
         if (ff_vorbis_len2vlc(tmp_vlc_bits, tmp_vlc_codes, entries)) {
-            av_log(vc->avccontext, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n");
+            av_log(vc->avctx, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n");
             ret = AVERROR_INVALIDDATA;
             goto error;
         }
@@ -440,7 +444,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
                             sizeof(*tmp_vlc_bits), tmp_vlc_codes,
                             sizeof(*tmp_vlc_codes), sizeof(*tmp_vlc_codes),
                             INIT_VLC_LE))) {
-            av_log(vc->avccontext, AV_LOG_ERROR, " Error generating vlc tables. \n");
+            av_log(vc->avctx, AV_LOG_ERROR, " Error generating vlc tables. \n");
             goto error;
         }
     }
@@ -472,7 +476,7 @@ static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc)
                 vorbis_time_count, vorbis_tdtransform);
 
         if (vorbis_tdtransform) {
-            av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis time domain transform data nonzero. \n");
+            av_log(vc->avctx, AV_LOG_ERROR, "Vorbis time domain transform data nonzero. \n");
             return AVERROR_INVALIDDATA;
         }
     }
@@ -483,17 +487,19 @@ static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc)
 
 static int vorbis_floor0_decode(vorbis_context *vc,
                                 vorbis_floor_data *vfu, float *vec);
-static void create_map(vorbis_context *vc, unsigned floor_number);
+static int create_map(vorbis_context *vc, unsigned floor_number);
 static int vorbis_floor1_decode(vorbis_context *vc,
                                 vorbis_floor_data *vfu, float *vec);
 static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
 {
     GetBitContext *gb = &vc->gb;
-    int i,j,k;
+    int i, j, k, ret;
 
     vc->floor_count = get_bits(gb, 6) + 1;
 
     vc->floors = av_mallocz(vc->floor_count * sizeof(*vc->floors));
+    if (!vc->floors)
+        return AVERROR(ENOMEM);
 
     for (i = 0; i < vc->floor_count; ++i) {
         vorbis_floor *floor_setup = &vc->floors[i];
@@ -557,12 +563,13 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
 
             floor_setup->data.t1.list = av_mallocz(floor_setup->data.t1.x_list_dim *
                                                    sizeof(*floor_setup->data.t1.list));
-
+            if (!floor_setup->data.t1.list)
+                return AVERROR(ENOMEM);
 
             rangebits = get_bits(gb, 4);
             rangemax = (1 << rangebits);
             if (rangemax > vc->blocksize[1] / 2) {
-                av_log(vc->avccontext, AV_LOG_ERROR,
+                av_log(vc->avctx, AV_LOG_ERROR,
                        "Floor value is too large for blocksize: %u (%"PRIu32")\n",
                        rangemax, vc->blocksize[1] / 2);
                 return AVERROR_INVALIDDATA;
@@ -580,7 +587,7 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
             }
 
 // Precalculate order of x coordinates - needed for decode
-            if (ff_vorbis_ready_floor1_list(vc->avccontext,
+            if (ff_vorbis_ready_floor1_list(vc->avctx,
                                             floor_setup->data.t1.list,
                                             floor_setup->data.t1.x_list_dim)) {
                 return AVERROR_INVALIDDATA;
@@ -592,19 +599,17 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
 
             floor_setup->data.t0.order          = get_bits(gb,  8);
             if (!floor_setup->data.t0.order) {
-                av_log(vc->avccontext, AV_LOG_ERROR,
-                       "Floor 0 order is 0.\n");
+                av_log(vc->avctx, AV_LOG_ERROR, "Floor 0 order is 0.\n");
                 return AVERROR_INVALIDDATA;
             }
             floor_setup->data.t0.rate           = get_bits(gb, 16);
             if (!floor_setup->data.t0.rate) {
-                av_log(vc->avccontext, AV_LOG_ERROR,
-                       "Floor 0 rate is 0.\n");
+                av_log(vc->avctx, AV_LOG_ERROR, "Floor 0 rate is 0.\n");
                 return AVERROR_INVALIDDATA;
             }
             floor_setup->data.t0.bark_map_size  = get_bits(gb, 16);
-            if (floor_setup->data.t0.bark_map_size == 0) {
-                av_log(vc->avccontext, AV_LOG_ERROR,
+            if (!floor_setup->data.t0.bark_map_size) {
+                av_log(vc->avctx, AV_LOG_ERROR,
                        "Floor 0 bark map size is 0.\n");
                 return AVERROR_INVALIDDATA;
             }
@@ -629,7 +634,8 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
                 }
             }
 
-            create_map(vc, i);
+            if ((ret = create_map(vc, i)) < 0)
+                return ret;
 
             /* codebook dim is for padding if codebook dim doesn't *
              * divide order+1 then we need to read more data       */
@@ -660,7 +666,7 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
                 }
             }
         } else {
-            av_log(vc->avccontext, AV_LOG_ERROR, "Invalid floor type!\n");
+            av_log(vc->avctx, AV_LOG_ERROR, "Invalid floor type!\n");
             return AVERROR_INVALIDDATA;
         }
     }
@@ -676,6 +682,8 @@ static int vorbis_parse_setup_hdr_residues(vorbis_context *vc)
 
     vc->residue_count = get_bits(gb, 6)+1;
     vc->residues      = av_mallocz(vc->residue_count * sizeof(*vc->residues));
+    if (!vc->residues)
+        return AVERROR(ENOMEM);
 
     av_dlog(NULL, " There are %d residues. \n", vc->residue_count);
 
@@ -695,7 +703,7 @@ static int vorbis_parse_setup_hdr_residues(vorbis_context *vc)
         if (res_setup->begin>res_setup->end ||
             res_setup->end > (res_setup->type == 2 ? vc->audio_channels : 1) * vc->blocksize[1] / 2 ||
             (res_setup->end-res_setup->begin) / res_setup->partition_size > V_MAX_PARTITIONS) {
-            av_log(vc->avccontext, AV_LOG_ERROR,
+            av_log(vc->avctx, AV_LOG_ERROR,
                    "partition out of bounds: type, begin, end, size, blocksize: %"PRIu16", %"PRIu32", %"PRIu32", %u, %"PRIu32"\n",
                    res_setup->type, res_setup->begin, res_setup->end,
                    res_setup->partition_size, vc->blocksize[1] / 2);
@@ -756,6 +764,8 @@ static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc)
 
     vc->mapping_count = get_bits(gb, 6)+1;
     vc->mappings      = av_mallocz(vc->mapping_count * sizeof(*vc->mappings));
+    if (!vc->mappings)
+        return AVERROR(ENOMEM);
 
     av_dlog(NULL, " There are %d mappings. \n", vc->mapping_count);
 
@@ -763,7 +773,7 @@ static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc)
         vorbis_mapping *mapping_setup = &vc->mappings[i];
 
         if (get_bits(gb, 16)) {
-            av_log(vc->avccontext, AV_LOG_ERROR, "Other mappings than type 0 are not compliant with the Vorbis I specification. \n");
+            av_log(vc->avctx, AV_LOG_ERROR, "Other mappings than type 0 are not compliant with the Vorbis I specification. \n");
             return AVERROR_INVALIDDATA;
         }
         if (get_bits1(gb)) {
@@ -778,6 +788,9 @@ static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc)
                                                        sizeof(*mapping_setup->magnitude));
             mapping_setup->angle          = av_mallocz(mapping_setup->coupling_steps *
                                                        sizeof(*mapping_setup->angle));
+            if (!mapping_setup->angle || !mapping_setup->magnitude)
+                return AVERROR(ENOMEM);
+
             for (j = 0; j < mapping_setup->coupling_steps; ++j) {
                 GET_VALIDATED_INDEX(mapping_setup->magnitude[j], ilog(vc->audio_channels - 1), vc->audio_channels)
                 GET_VALIDATED_INDEX(mapping_setup->angle[j],     ilog(vc->audio_channels - 1), vc->audio_channels)
@@ -790,13 +803,16 @@ static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc)
                 i, mapping_setup->coupling_steps);
 
         if (get_bits(gb, 2)) {
-            av_log(vc->avccontext, AV_LOG_ERROR, "%u. mapping setup data invalid.\n", i);
+            av_log(vc->avctx, AV_LOG_ERROR, "%u. mapping setup data invalid.\n", i);
             return AVERROR_INVALIDDATA; // following spec.
         }
 
         if (mapping_setup->submaps>1) {
             mapping_setup->mux = av_mallocz(vc->audio_channels *
                                             sizeof(*mapping_setup->mux));
+            if (!mapping_setup->mux)
+                return AVERROR(ENOMEM);
+
             for (j = 0; j < vc->audio_channels; ++j)
                 mapping_setup->mux[j] = get_bits(gb, 4);
         }
@@ -816,7 +832,7 @@ static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc)
 
 // Process modes part
 
-static void create_map(vorbis_context *vc, unsigned floor_number)
+static int create_map(vorbis_context *vc, unsigned floor_number)
 {
     vorbis_floor *floors = vc->floors;
     vorbis_floor0 *vf;
@@ -828,6 +844,8 @@ static void create_map(vorbis_context *vc, unsigned floor_number)
         n = vc->blocksize[blockflag] / 2;
         floors[floor_number].data.t0.map[blockflag] =
             av_malloc((n + 1) * sizeof(int32_t)); // n + sentinel
+        if (!floors[floor_number].data.t0.map[blockflag])
+            return AVERROR(ENOMEM);
 
         map =  floors[floor_number].data.t0.map[blockflag];
         vf  = &floors[floor_number].data.t0;
@@ -845,6 +863,8 @@ static void create_map(vorbis_context *vc, unsigned floor_number)
     for (idx = 0; idx <= n; ++idx) {
         av_dlog(NULL, "floor0 map: map at pos %d is %d\n", idx, map[idx]);
     }
+
+    return 0;
 }
 
 static int vorbis_parse_setup_hdr_modes(vorbis_context *vc)
@@ -854,6 +874,8 @@ static int vorbis_parse_setup_hdr_modes(vorbis_context *vc)
 
     vc->mode_count = get_bits(gb, 6) + 1;
     vc->modes      = av_mallocz(vc->mode_count * sizeof(*vc->modes));
+    if (!vc->modes)
+        return AVERROR(ENOMEM);
 
     av_dlog(NULL, " There are %d modes.\n", vc->mode_count);
 
@@ -882,36 +904,36 @@ static int vorbis_parse_setup_hdr(vorbis_context *vc)
     if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') ||
         (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') ||
         (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) {
-        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n");
+        av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n");
         return AVERROR_INVALIDDATA;
     }
 
     if ((ret = vorbis_parse_setup_hdr_codebooks(vc))) {
-        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (codebooks). \n");
+        av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (codebooks). \n");
         return ret;
     }
     if ((ret = vorbis_parse_setup_hdr_tdtransforms(vc))) {
-        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (time domain transforms). \n");
+        av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (time domain transforms). \n");
         return ret;
     }
     if ((ret = vorbis_parse_setup_hdr_floors(vc))) {
-        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (floors). \n");
+        av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (floors). \n");
         return ret;
     }
     if ((ret = vorbis_parse_setup_hdr_residues(vc))) {
-        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (residues). \n");
+        av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (residues). \n");
         return ret;
     }
     if ((ret = vorbis_parse_setup_hdr_mappings(vc))) {
-        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (mappings). \n");
+        av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (mappings). \n");
         return ret;
     }
     if ((ret = vorbis_parse_setup_hdr_modes(vc))) {
-        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (modes). \n");
+        av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (modes). \n");
         return ret;
     }
     if (!get_bits1(gb)) {
-        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (framing flag). \n");
+        av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (framing flag). \n");
         return AVERROR_INVALIDDATA; // framing flag bit unset error
     }
 
@@ -928,19 +950,19 @@ static int vorbis_parse_id_hdr(vorbis_context *vc)
     if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') ||
         (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') ||
         (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) {
-        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n");
+        av_log(vc->avctx, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n");
         return AVERROR_INVALIDDATA;
     }
 
     vc->version        = get_bits_long(gb, 32);    //FIXME check 0
     vc->audio_channels = get_bits(gb, 8);
     if (vc->audio_channels <= 0) {
-        av_log(vc->avccontext, AV_LOG_ERROR, "Invalid number of channels\n");
+        av_log(vc->avctx, AV_LOG_ERROR, "Invalid number of channels\n");
         return AVERROR_INVALIDDATA;
     }
     vc->audio_samplerate = get_bits_long(gb, 32);
     if (vc->audio_samplerate <= 0) {
-        av_log(vc->avccontext, AV_LOG_ERROR, "Invalid samplerate\n");
+        av_log(vc->avctx, AV_LOG_ERROR, "Invalid samplerate\n");
         return AVERROR_INVALIDDATA;
     }
     vc->bitrate_maximum = get_bits_long(gb, 32);
@@ -949,7 +971,7 @@ static int vorbis_parse_id_hdr(vorbis_context *vc)
     bl0 = get_bits(gb, 4);
     bl1 = get_bits(gb, 4);
     if (bl0 > 13 || bl0 < 6 || bl1 > 13 || bl1 < 6 || bl1 < bl0) {
-        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n");
+        av_log(vc->avctx, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n");
         return AVERROR_INVALIDDATA;
     }
     vc->blocksize[0] = (1 << bl0);
@@ -958,12 +980,15 @@ static int vorbis_parse_id_hdr(vorbis_context *vc)
     vc->win[1] = ff_vorbis_vwin[bl1 - 6];
 
     if ((get_bits1(gb)) == 0) {
-        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n");
+        av_log(vc->avctx, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n");
         return AVERROR_INVALIDDATA;
     }
 
     vc->channel_residues =  av_malloc((vc->blocksize[1]  / 2) * vc->audio_channels * sizeof(*vc->channel_residues));
     vc->saved            =  av_mallocz((vc->blocksize[1] / 4) * vc->audio_channels * sizeof(*vc->saved));
+    if (!vc->channel_residues || !vc->saved)
+        return AVERROR(ENOMEM);
+
     vc->previous_window  = 0;
 
     ff_mdct_init(&vc->mdct[0], bl0, 1, -1.0);
@@ -984,41 +1009,41 @@ static int vorbis_parse_id_hdr(vorbis_context *vc)
 
 // Process the extradata using the functions above (identification header, setup header)
 
-static av_cold int vorbis_decode_init(AVCodecContext *avccontext)
+static av_cold int vorbis_decode_init(AVCodecContext *avctx)
 {
-    vorbis_context *vc = avccontext->priv_data;
-    uint8_t *headers   = avccontext->extradata;
-    int headers_len    = avccontext->extradata_size;
+    vorbis_context *vc = avctx->priv_data;
+    uint8_t *headers   = avctx->extradata;
+    int headers_len    = avctx->extradata_size;
     uint8_t *header_start[3];
     int header_len[3];
     GetBitContext *gb = &vc->gb;
     int hdr_type, ret;
 
-    vc->avccontext = avccontext;
-    ff_dsputil_init(&vc->dsp, avccontext);
-    avpriv_float_dsp_init(&vc->fdsp, avccontext->flags & CODEC_FLAG_BITEXACT);
-    ff_fmt_convert_init(&vc->fmt_conv, avccontext);
+    vc->avctx = avctx;
+    ff_vorbisdsp_init(&vc->dsp);
+    avpriv_float_dsp_init(&vc->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
+    ff_fmt_convert_init(&vc->fmt_conv, avctx);
 
-    avccontext->sample_fmt = AV_SAMPLE_FMT_FLTP;
+    avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
 
     if (!headers_len) {
-        av_log(avccontext, AV_LOG_ERROR, "Extradata missing.\n");
+        av_log(avctx, AV_LOG_ERROR, "Extradata missing.\n");
         return AVERROR_INVALIDDATA;
     }
 
     if ((ret = avpriv_split_xiph_headers(headers, headers_len, 30, header_start, header_len)) < 0) {
-        av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n");
+        av_log(avctx, AV_LOG_ERROR, "Extradata corrupt.\n");
         return ret;
     }
 
     init_get_bits(gb, header_start[0], header_len[0]*8);
     hdr_type = get_bits(gb, 8);
     if (hdr_type != 1) {
-        av_log(avccontext, AV_LOG_ERROR, "First header is not the id header.\n");
+        av_log(avctx, AV_LOG_ERROR, "First header is not the id header.\n");
         return AVERROR_INVALIDDATA;
     }
     if ((ret = vorbis_parse_id_hdr(vc))) {
-        av_log(avccontext, AV_LOG_ERROR, "Id header corrupt.\n");
+        av_log(avctx, AV_LOG_ERROR, "Id header corrupt.\n");
         vorbis_free(vc);
         return ret;
     }
@@ -1026,26 +1051,23 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext)
     init_get_bits(gb, header_start[2], header_len[2]*8);
     hdr_type = get_bits(gb, 8);
     if (hdr_type != 5) {
-        av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n");
+        av_log(avctx, AV_LOG_ERROR, "Third header is not the setup header.\n");
         vorbis_free(vc);
         return AVERROR_INVALIDDATA;
     }
     if ((ret = vorbis_parse_setup_hdr(vc))) {
-        av_log(avccontext, AV_LOG_ERROR, "Setup header corrupt.\n");
+        av_log(avctx, AV_LOG_ERROR, "Setup header corrupt.\n");
         vorbis_free(vc);
         return ret;
     }
 
     if (vc->audio_channels > 8)
-        avccontext->channel_layout = 0;
+        avctx->channel_layout = 0;
     else
-        avccontext->channel_layout = ff_vorbis_channel_layouts[vc->audio_channels - 1];
-
-    avccontext->channels    = vc->audio_channels;
-    avccontext->sample_rate = vc->audio_samplerate;
+        avctx->channel_layout = ff_vorbis_channel_layouts[vc->audio_channels - 1];
 
-    avcodec_get_frame_defaults(&vc->frame);
-    avccontext->coded_frame = &vc->frame;
+    avctx->channels    = vc->audio_channels;
+    avctx->sample_rate = vc->audio_samplerate;
 
     return 0;
 }
@@ -1073,8 +1095,7 @@ static int vorbis_floor0_decode(vorbis_context *vc,
 
         book_idx = get_bits(&vc->gb, ilog(vf->num_books));
         if (book_idx >= vf->num_books) {
-            av_log(vc->avccontext, AV_LOG_ERROR,
-                    "floor0 dec: booknumber too high!\n");
+            av_log(vc->avctx, AV_LOG_ERROR, "floor0 dec: booknumber too high!\n");
             book_idx =  0;
         }
         av_dlog(NULL, "floor0 dec: booknumber: %u\n", book_idx);
@@ -1318,7 +1339,7 @@ static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc,
     }
 
     if (max_output > ch_left * vlen) {
-        av_log(vc->avccontext, AV_LOG_ERROR, "Insufficient output buffer\n");
+        av_log(vc->avctx, AV_LOG_ERROR, "Insufficient output buffer\n");
         return -1;
     }
 
@@ -1462,12 +1483,12 @@ static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr,
     else if (vr->type == 0)
         return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, ch_left, 0);
     else {
-        av_log(vc->avccontext, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n");
+        av_log(vc->avctx, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n");
         return AVERROR_INVALIDDATA;
     }
 }
 
-void ff_vorbis_inverse_coupling(float *mag, float *ang, int blocksize)
+void ff_vorbis_inverse_coupling(float *mag, float *ang, intptr_t blocksize)
 {
     int i;
     for (i = 0;  i < blocksize;  i++) {
@@ -1511,7 +1532,7 @@ static int vorbis_parse_audio_packet(vorbis_context *vc, float **floor_ptr)
     unsigned vlen;
 
     if (get_bits1(gb)) {
-        av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n");
+        av_log(vc->avctx, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n");
         return AVERROR_INVALIDDATA; // packet type not audio
     }
 
@@ -1552,7 +1573,7 @@ static int vorbis_parse_audio_packet(vorbis_context *vc, float **floor_ptr)
         ret = floor->decode(vc, &floor->data, floor_ptr[i]);
 
         if (ret < 0) {
-            av_log(vc->avccontext, AV_LOG_ERROR, "Invalid codebook in vorbis_floor_decode.\n");
+            av_log(vc->avctx, AV_LOG_ERROR, "Invalid codebook in vorbis_floor_decode.\n");
             return AVERROR_INVALIDDATA;
         }
         no_residue[i] = ret;
@@ -1588,7 +1609,7 @@ static int vorbis_parse_audio_packet(vorbis_context *vc, float **floor_ptr)
         }
         residue = &vc->residues[mapping->submap_residue[i]];
         if (ch_left < ch) {
-            av_log(vc->avccontext, AV_LOG_ERROR, "Too many channels in vorbis_floor_decode.\n");
+            av_log(vc->avctx, AV_LOG_ERROR, "Too many channels in vorbis_floor_decode.\n");
             return -1;
         }
         if (ch) {
@@ -1637,13 +1658,13 @@ static int vorbis_parse_audio_packet(vorbis_context *vc, float **floor_ptr)
         const float *win  = vc->win[blockflag & previous_window];
 
         if (blockflag == previous_window) {
-            vc->dsp.vector_fmul_window(ret, saved, buf, win, blocksize / 4);
+            vc->fdsp.vector_fmul_window(ret, saved, buf, win, blocksize / 4);
         } else if (blockflag > previous_window) {
-            vc->dsp.vector_fmul_window(ret, saved, buf, win, bs0 / 4);
+            vc->fdsp.vector_fmul_window(ret, saved, buf, win, bs0 / 4);
             memcpy(ret+bs0/2, buf+bs0/4, ((bs1-bs0)/4) * sizeof(float));
         } else {
             memcpy(ret, saved, ((bs1 - bs0) / 4) * sizeof(float));
-            vc->dsp.vector_fmul_window(ret + (bs1 - bs0) / 4, saved + (bs1 - bs0) / 4, buf, win, bs0 / 4);
+            vc->fdsp.vector_fmul_window(ret + (bs1 - bs0) / 4, saved + (bs1 - bs0) / 4, buf, win, bs0 / 4);
         }
         memcpy(saved, buf + blocksize / 4, blocksize / 4 * sizeof(float));
     }
@@ -1654,12 +1675,13 @@ static int vorbis_parse_audio_packet(vorbis_context *vc, float **floor_ptr)
 
 // Return the decoded audio packet through the standard api
 
-static int vorbis_decode_frame(AVCodecContext *avccontext, void *data,
+static int vorbis_decode_frame(AVCodecContext *avctx, void *data,
                                int *got_frame_ptr, AVPacket *avpkt)
 {
     const uint8_t *buf = avpkt->data;
     int buf_size       = avpkt->size;
-    vorbis_context *vc = avccontext->priv_data;
+    vorbis_context *vc = avctx->priv_data;
+    AVFrame *frame     = data;
     GetBitContext *gb = &vc->gb;
     float *channel_ptrs[255];
     int i, len, ret;
@@ -1670,30 +1692,30 @@ static int vorbis_decode_frame(AVCodecContext *avccontext, void *data,
         init_get_bits(gb, buf+1, buf_size*8 - 8);
         vorbis_free(vc);
         if ((ret = vorbis_parse_id_hdr(vc))) {
-            av_log(avccontext, AV_LOG_ERROR, "Id header corrupt.\n");
+            av_log(avctx, AV_LOG_ERROR, "Id header corrupt.\n");
             vorbis_free(vc);
             return ret;
         }
 
         if (vc->audio_channels > 8)
-            avccontext->channel_layout = 0;
+            avctx->channel_layout = 0;
         else
-            avccontext->channel_layout = ff_vorbis_channel_layouts[vc->audio_channels - 1];
+            avctx->channel_layout = ff_vorbis_channel_layouts[vc->audio_channels - 1];
 
-        avccontext->channels    = vc->audio_channels;
-        avccontext->sample_rate = vc->audio_samplerate;
+        avctx->channels    = vc->audio_channels;
+        avctx->sample_rate = vc->audio_samplerate;
         return buf_size;
     }
 
     if (*buf == 3 && buf_size > 7) {
-        av_log(avccontext, AV_LOG_DEBUG, "Ignoring comment header\n");
+        av_log(avctx, AV_LOG_DEBUG, "Ignoring comment header\n");
         return buf_size;
     }
 
     if (*buf == 5 && buf_size > 7 && vc->channel_residues && !vc->modes) {
         init_get_bits(gb, buf+1, buf_size*8 - 8);
         if ((ret = vorbis_parse_setup_hdr(vc))) {
-            av_log(avccontext, AV_LOG_ERROR, "Setup header corrupt.\n");
+            av_log(avctx, AV_LOG_ERROR, "Setup header corrupt.\n");
             vorbis_free(vc);
             return ret;
         }
@@ -1701,24 +1723,24 @@ static int vorbis_decode_frame(AVCodecContext *avccontext, void *data,
     }
 
     if (!vc->channel_residues || !vc->modes) {
-        av_log(avccontext, AV_LOG_ERROR, "Data packet before valid headers\n");
+        av_log(avctx, AV_LOG_ERROR, "Data packet before valid headers\n");
         return AVERROR_INVALIDDATA;
     }
 
     /* get output buffer */
-    vc->frame.nb_samples = vc->blocksize[1] / 2;
-    if ((ret = ff_get_buffer(avccontext, &vc->frame)) < 0) {
-        av_log(avccontext, AV_LOG_ERROR, "get_buffer() failed\n");
+    frame->nb_samples = vc->blocksize[1] / 2;
+    if ((ret = ff_get_buffer(avctx, frame)) < 0) {
+        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
 
     if (vc->audio_channels > 8) {
         for (i = 0; i < vc->audio_channels; i++)
-            channel_ptrs[i] = (float *)vc->frame.extended_data[i];
+            channel_ptrs[i] = (float *)frame->extended_data[i];
     } else {
         for (i = 0; i < vc->audio_channels; i++) {
             int ch = ff_vorbis_channel_layout_offsets[vc->audio_channels - 1][i];
-            channel_ptrs[ch] = (float *)vc->frame.extended_data[i];
+            channel_ptrs[ch] = (float *)frame->extended_data[i];
         }
     }
 
@@ -1736,27 +1758,26 @@ static int vorbis_decode_frame(AVCodecContext *avccontext, void *data,
     av_dlog(NULL, "parsed %d bytes %d bits, returned %d samples (*ch*bits) \n",
             get_bits_count(gb) / 8, get_bits_count(gb) % 8, len);
 
-    vc->frame.nb_samples = len;
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = vc->frame;
+    frame->nb_samples = len;
+    *got_frame_ptr    = 1;
 
     return buf_size;
 }
 
 // Close decoder
 
-static av_cold int vorbis_decode_close(AVCodecContext *avccontext)
+static av_cold int vorbis_decode_close(AVCodecContext *avctx)
 {
-    vorbis_context *vc = avccontext->priv_data;
+    vorbis_context *vc = avctx->priv_data;
 
     vorbis_free(vc);
 
     return 0;
 }
 
-static av_cold void vorbis_decode_flush(AVCodecContext *avccontext)
+static av_cold void vorbis_decode_flush(AVCodecContext *avctx)
 {
-    vorbis_context *vc = avccontext->priv_data;
+    vorbis_context *vc = avctx->priv_data;
 
     if (vc->saved) {
         memset(vc->saved, 0, (vc->blocksize[1] / 4) * vc->audio_channels *
diff --git a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_vfp.c b/mythtv/external/FFmpeg/libavcodec/vorbisdsp.c
similarity index 67%
rename from mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_vfp.c
rename to mythtv/external/FFmpeg/libavcodec/vorbisdsp.c
index 5713c71f802..fd8dcd7da80 100644
--- a/mythtv/external/FFmpeg/libavcodec/arm/dsputil_init_vfp.c
+++ b/mythtv/external/FFmpeg/libavcodec/vorbisdsp.c
@@ -1,6 +1,4 @@
 /*
- * Copyright (c) 2008 Siarhei Siamashka 
- *
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -18,13 +16,18 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavcodec/dsputil.h"
-#include "dsputil_arm.h"
-
-void ff_vector_fmul_reverse_vfp(float *dst, const float *src0,
-                                const float *src1, int len);
+#include "config.h"
+#include "vorbisdsp.h"
+#include "vorbis.h"
 
-void ff_dsputil_init_vfp(DSPContext* c, AVCodecContext *avctx)
+void ff_vorbisdsp_init(VorbisDSPContext *dsp)
 {
-    c->vector_fmul_reverse = ff_vector_fmul_reverse_vfp;
+    dsp->vorbis_inverse_coupling = ff_vorbis_inverse_coupling;
+
+    if (ARCH_X86)
+        ff_vorbisdsp_init_x86(dsp);
+    if (ARCH_PPC)
+        ff_vorbisdsp_init_ppc(dsp);
+    if (ARCH_ARM)
+        ff_vorbisdsp_init_arm(dsp);
 }
diff --git a/mythtv/external/FFmpeg/libavcodec/vorbisdsp.h b/mythtv/external/FFmpeg/libavcodec/vorbisdsp.h
new file mode 100644
index 00000000000..ed14049c8ce
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/vorbisdsp.h
@@ -0,0 +1,37 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_VORBISDSP_H
+#define AVCODEC_VORBISDSP_H
+
+#include 
+
+typedef struct VorbisDSPContext {
+    /* assume len is a multiple of 4, and arrays are 16-byte aligned */
+    void (*vorbis_inverse_coupling)(float *mag, float *ang,
+                                    intptr_t blocksize);
+} VorbisDSPContext;
+
+void ff_vorbisdsp_init(VorbisDSPContext *dsp);
+
+/* for internal use only */
+void ff_vorbisdsp_init_x86(VorbisDSPContext *dsp);
+void ff_vorbisdsp_init_arm(VorbisDSPContext *dsp);
+void ff_vorbisdsp_init_ppc(VorbisDSPContext *dsp);
+
+#endif /* AVCODEC_VORBISDSP_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/vorbisenc.c b/mythtv/external/FFmpeg/libavcodec/vorbisenc.c
index 33b2577d96b..b8752d6bea4 100644
--- a/mythtv/external/FFmpeg/libavcodec/vorbisenc.c
+++ b/mythtv/external/FFmpeg/libavcodec/vorbisenc.c
@@ -26,7 +26,6 @@
 
 #include 
 #include "avcodec.h"
-#include "dsputil.h"
 #include "internal.h"
 #include "fft.h"
 #include "vorbis.h"
@@ -236,15 +235,15 @@ static int ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc)
 }
 
 static int create_vorbis_context(vorbis_enc_context *venc,
-                                 AVCodecContext *avccontext)
+                                 AVCodecContext *avctx)
 {
     vorbis_enc_floor   *fc;
     vorbis_enc_residue *rc;
     vorbis_enc_mapping *mc;
     int i, book, ret;
 
-    venc->channels    = avccontext->channels;
-    venc->sample_rate = avccontext->sample_rate;
+    venc->channels    = avctx->channels;
+    venc->sample_rate = avctx->sample_rate;
     venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
 
     venc->ncodebooks = FF_ARRAY_ELEMS(cvectors);
@@ -340,7 +339,7 @@ static int create_vorbis_context(vorbis_enc_context *venc,
         };
         fc->list[i].x = a[i - 2];
     }
-    if (ff_vorbis_ready_floor1_list(avccontext, fc->list, fc->values))
+    if (ff_vorbis_ready_floor1_list(avctx, fc->list, fc->values))
         return AVERROR_BUG;
 
     venc->nresidues = 1;
@@ -1014,10 +1013,10 @@ static int apply_window_and_mdct(vorbis_enc_context *venc,
     return 1;
 }
 
-static int vorbis_encode_frame(AVCodecContext *avccontext, AVPacket *avpkt,
+static int vorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
                                const AVFrame *frame, int *got_packet_ptr)
 {
-    vorbis_enc_context *venc = avccontext->priv_data;
+    vorbis_enc_context *venc = avctx->priv_data;
     float **audio = frame ? (float **)frame->extended_data : NULL;
     int samples = frame ? frame->nb_samples : 0;
     vorbis_enc_mode *mode;
@@ -1029,13 +1028,13 @@ static int vorbis_encode_frame(AVCodecContext *avccontext, AVPacket *avpkt,
         return 0;
     samples = 1 << (venc->log2_blocksize[0] - 1);
 
-    if ((ret = ff_alloc_packet2(avccontext, avpkt, 8192)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, 8192)) < 0)
         return ret;
 
     init_put_bits(&pb, avpkt->data, avpkt->size);
 
     if (pb.size_in_bits - put_bits_count(&pb) < 1 + ilog(venc->nmodes - 1)) {
-        av_log(avccontext, AV_LOG_ERROR, "output buffer is too small\n");
+        av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
         return AVERROR(EINVAL);
     }
 
@@ -1055,7 +1054,7 @@ static int vorbis_encode_frame(AVCodecContext *avccontext, AVPacket *avpkt,
         uint16_t posts[MAX_FLOOR_VALUES];
         floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples);
         if (floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples)) {
-            av_log(avccontext, AV_LOG_ERROR, "output buffer is too small\n");
+            av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
             return AVERROR(EINVAL);
         }
     }
@@ -1079,17 +1078,17 @@ static int vorbis_encode_frame(AVCodecContext *avccontext, AVPacket *avpkt,
 
     if (residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]],
                        &pb, venc->coeffs, samples, venc->channels)) {
-        av_log(avccontext, AV_LOG_ERROR, "output buffer is too small\n");
+        av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
         return AVERROR(EINVAL);
     }
 
     flush_put_bits(&pb);
     avpkt->size = put_bits_count(&pb) >> 3;
 
-    avpkt->duration = ff_samples_to_time_base(avccontext, avccontext->frame_size);
+    avpkt->duration = ff_samples_to_time_base(avctx, avctx->frame_size);
     if (frame) {
         if (frame->pts != AV_NOPTS_VALUE)
-            avpkt->pts = ff_samples_to_time_base(avccontext, frame->pts);
+            avpkt->pts = ff_samples_to_time_base(avctx, frame->pts);
     } else
         avpkt->pts = venc->next_pts;
     if (avpkt->pts != AV_NOPTS_VALUE)
@@ -1100,9 +1099,9 @@ static int vorbis_encode_frame(AVCodecContext *avccontext, AVPacket *avpkt,
 }
 
 
-static av_cold int vorbis_encode_close(AVCodecContext *avccontext)
+static av_cold int vorbis_encode_close(AVCodecContext *avctx)
 {
-    vorbis_enc_context *venc = avccontext->priv_data;
+    vorbis_enc_context *venc = avctx->priv_data;
     int i;
 
     if (venc->codebooks)
@@ -1155,42 +1154,42 @@ static av_cold int vorbis_encode_close(AVCodecContext *avccontext)
     ff_mdct_end(&venc->mdct[1]);
 
 #if FF_API_OLD_ENCODE_AUDIO
-    av_freep(&avccontext->coded_frame);
+    av_freep(&avctx->coded_frame);
 #endif
-    av_freep(&avccontext->extradata);
+    av_freep(&avctx->extradata);
 
     return 0 ;
 }
 
-static av_cold int vorbis_encode_init(AVCodecContext *avccontext)
+static av_cold int vorbis_encode_init(AVCodecContext *avctx)
 {
-    vorbis_enc_context *venc = avccontext->priv_data;
+    vorbis_enc_context *venc = avctx->priv_data;
     int ret;
 
-    if (avccontext->channels != 2) {
-        av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n");
+    if (avctx->channels != 2) {
+        av_log(avctx, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n");
         return -1;
     }
 
-    if ((ret = create_vorbis_context(venc, avccontext)) < 0)
+    if ((ret = create_vorbis_context(venc, avctx)) < 0)
         goto error;
 
-    avccontext->bit_rate = 0;
-    if (avccontext->flags & CODEC_FLAG_QSCALE)
-        venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA;
+    avctx->bit_rate = 0;
+    if (avctx->flags & CODEC_FLAG_QSCALE)
+        venc->quality = avctx->global_quality / (float)FF_QP2LAMBDA;
     else
         venc->quality = 8;
     venc->quality *= venc->quality;
 
-    if ((ret = put_main_header(venc, (uint8_t**)&avccontext->extradata)) < 0)
+    if ((ret = put_main_header(venc, (uint8_t**)&avctx->extradata)) < 0)
         goto error;
-    avccontext->extradata_size = ret;
+    avctx->extradata_size = ret;
 
-    avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1);
+    avctx->frame_size = 1 << (venc->log2_blocksize[0] - 1);
 
 #if FF_API_OLD_ENCODE_AUDIO
-    avccontext->coded_frame = avcodec_alloc_frame();
-    if (!avccontext->coded_frame) {
+    avctx->coded_frame = avcodec_alloc_frame();
+    if (!avctx->coded_frame) {
         ret = AVERROR(ENOMEM);
         goto error;
     }
@@ -1198,7 +1197,7 @@ static av_cold int vorbis_encode_init(AVCodecContext *avccontext)
 
     return 0;
 error:
-    vorbis_encode_close(avccontext);
+    vorbis_encode_close(avctx);
     return ret;
 }
 
diff --git a/mythtv/external/FFmpeg/libavcodec/vp3.c b/mythtv/external/FFmpeg/libavcodec/vp3.c
index ce3ffe832a2..00a77e9e782 100644
--- a/mythtv/external/FFmpeg/libavcodec/vp3.c
+++ b/mythtv/external/FFmpeg/libavcodec/vp3.c
@@ -75,6 +75,10 @@ typedef struct Vp3Fragment {
 /* special internal mode */
 #define MODE_COPY             8
 
+static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb);
+static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb);
+
+
 /* There are 6 preset schemes, plus a free-form scheme */
 static const int ModeAlphabet[6][CODING_MODE_COUNT] =
 {
@@ -138,6 +142,7 @@ typedef struct Vp3DecodeContext {
     DSPContext dsp;
     VideoDSPContext vdsp;
     VP3DSPContext vp3dsp;
+    DECLARE_ALIGNED(16, int16_t, block)[64];
     int flipped_image;
     int last_slice_end;
     int skip_loop_filter;
@@ -291,6 +296,8 @@ static av_cold int vp3_decode_end(AVCodecContext *avctx)
     av_freep(&s->motion_val[1]);
     av_freep(&s->edge_emu_buffer);
 
+    s->theora_tables = 0;
+
     if (avctx->internal->is_copy)
         return 0;
 
@@ -919,7 +926,7 @@ static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb,
     int i, j = 0;
     int token;
     int zero_run = 0;
-    DCTELEM coeff = 0;
+    int16_t coeff = 0;
     int bits_to_get;
     int blocks_ended;
     int coeff_i = 0;
@@ -1349,7 +1356,7 @@ static void apply_loop_filter(Vp3DecodeContext *s, int plane, int ystart, int ye
  * for the next block in coding order
  */
 static inline int vp3_dequant(Vp3DecodeContext *s, Vp3Fragment *frag,
-                              int plane, int inter, DCTELEM block[64])
+                              int plane, int inter, int16_t block[64])
 {
     int16_t *dequantizer = s->qmat[frag->qpi][inter][plane];
     uint8_t *perm = s->scantable.permutated;
@@ -1458,7 +1465,7 @@ static void await_reference_row(Vp3DecodeContext *s, Vp3Fragment *fragment, int
 static void render_slice(Vp3DecodeContext *s, int slice)
 {
     int x, y, i, j, fragment;
-    LOCAL_ALIGNED_16(DCTELEM, block, [64]);
+    int16_t *block = s->block;
     int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef;
     int motion_halfpel_index;
     uint8_t *motion_source;
@@ -1563,7 +1570,7 @@ static void render_slice(Vp3DecodeContext *s, int slice)
                                 motion_source, stride, 8);
                         }else{
                             int d= (motion_x ^ motion_y)>>31; // d is 0 if motion_x and _y have the same sign, else -1
-                            s->dsp.put_no_rnd_pixels_l2[1](
+                            s->vp3dsp.put_no_rnd_pixels_l2(
                                 output_plane + first_pixel,
                                 motion_source - d,
                                 motion_source + stride + 1 + d,
@@ -1571,8 +1578,6 @@ static void render_slice(Vp3DecodeContext *s, int slice)
                         }
                     }
 
-                        s->dsp.clear_block(block);
-
                     /* invert DCT and place (or add) in final output */
 
                     if (s->all_fragments[i].coding_method == MODE_INTRA) {
@@ -1913,16 +1918,48 @@ static int vp3_decode_frame(AVCodecContext *avctx,
     Vp3DecodeContext *s = avctx->priv_data;
     GetBitContext gb;
     int i;
+    int ret;
 
     init_get_bits(&gb, buf, buf_size * 8);
 
+#if CONFIG_THEORA_DECODER
     if (s->theora && get_bits1(&gb))
     {
+        int type = get_bits(&gb, 7);
+        skip_bits_long(&gb, 6*8); /* "theora" */
+
+        if (s->avctx->active_thread_type&FF_THREAD_FRAME) {
+            av_log(avctx, AV_LOG_ERROR, "midstream reconfiguration with multithreading is unsupported, try -threads 1\n");
+            return AVERROR_PATCHWELCOME;
+        }
+        if (type == 0) {
+            vp3_decode_end(avctx);
+            ret = theora_decode_header(avctx, &gb);
+
+            if (ret < 0) {
+                vp3_decode_end(avctx);
+            } else
+                ret = vp3_decode_init(avctx);
+            return ret;
+        } else if (type == 2) {
+            ret = theora_decode_tables(avctx, &gb);
+            if (ret < 0) {
+                vp3_decode_end(avctx);
+            } else
+                ret = vp3_decode_init(avctx);
+            return ret;
+        }
+
         av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n");
         return -1;
     }
+#endif
 
     s->keyframe = !get_bits1(&gb);
+    if (!s->all_fragments) {
+        av_log(avctx, AV_LOG_ERROR, "Data packet without prior valid headers\n");
+        return -1;
+    }
     if (!s->theora)
         skip_bits(&gb, 1);
     for (i = 0; i < 3; i++)
diff --git a/mythtv/external/FFmpeg/libavcodec/vp3dsp.c b/mythtv/external/FFmpeg/libavcodec/vp3dsp.c
index 0e0c0f58ae5..051812e72d4 100644
--- a/mythtv/external/FFmpeg/libavcodec/vp3dsp.c
+++ b/mythtv/external/FFmpeg/libavcodec/vp3dsp.c
@@ -28,6 +28,7 @@
 #include "libavutil/common.h"
 #include "avcodec.h"
 #include "dsputil.h"
+#include "rnd_avg.h"
 #include "vp3dsp.h"
 
 #define IdctAdjustBeforeShift 8
@@ -213,16 +214,23 @@ static av_always_inline void idct(uint8_t *dst, int stride, int16_t *input, int
     }
 }
 
-static void vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/){
+static void vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size,
+                           int16_t *block/*align 16*/)
+{
     idct(dest, line_size, block, 1);
+    memset(block, 0, sizeof(*block) * 64);
 }
 
-static void vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/){
+static void vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size,
+                           int16_t *block/*align 16*/)
+{
     idct(dest, line_size, block, 2);
+    memset(block, 0, sizeof(*block) * 64);
 }
 
 static void vp3_idct_dc_add_c(uint8_t *dest/*align 8*/, int line_size,
-                              const DCTELEM *block/*align 16*/){
+                              int16_t *block/*align 16*/)
+{
     int i, dc = (block[0] + 15) >> 5;
 
     for(i = 0; i < 8; i++){
@@ -236,6 +244,7 @@ static void vp3_idct_dc_add_c(uint8_t *dest/*align 8*/, int line_size,
         dest[7] = av_clip_uint8(dest[7] + dc);
         dest += line_size;
     }
+    block[0] = 0;
 }
 
 static void vp3_v_loop_filter_c(uint8_t *first_pixel, int stride,
@@ -271,8 +280,27 @@ static void vp3_h_loop_filter_c(uint8_t *first_pixel, int stride,
     }
 }
 
+static void put_no_rnd_pixels_l2(uint8_t *dst, const uint8_t *src1,
+                                 const uint8_t *src2, ptrdiff_t stride, int h)
+{
+    int i;
+
+    for (i = 0; i < h; i++) {
+        uint32_t a, b;
+
+        a = AV_RN32(&src1[i * stride]);
+        b = AV_RN32(&src2[i * stride]);
+        AV_WN32A(&dst[i * stride], no_rnd_avg32(a, b));
+        a = AV_RN32(&src1[i * stride + 4]);
+        b = AV_RN32(&src2[i * stride + 4]);
+        AV_WN32A(&dst[i * stride + 4], no_rnd_avg32(a, b));
+    }
+}
+
 av_cold void ff_vp3dsp_init(VP3DSPContext *c, int flags)
 {
+    c->put_no_rnd_pixels_l2 = put_no_rnd_pixels_l2;
+
     c->idct_put      = vp3_idct_put_c;
     c->idct_add      = vp3_idct_add_c;
     c->idct_dc_add   = vp3_idct_dc_add_c;
@@ -283,6 +311,8 @@ av_cold void ff_vp3dsp_init(VP3DSPContext *c, int flags)
 
     if (ARCH_ARM)
         ff_vp3dsp_init_arm(c, flags);
+    if (ARCH_BFIN)
+        ff_vp3dsp_init_bfin(c, flags);
     if (ARCH_PPC)
         ff_vp3dsp_init_ppc(c, flags);
     if (ARCH_X86)
diff --git a/mythtv/external/FFmpeg/libavcodec/vp3dsp.h b/mythtv/external/FFmpeg/libavcodec/vp3dsp.h
index a14dec1eb48..558077f9086 100644
--- a/mythtv/external/FFmpeg/libavcodec/vp3dsp.h
+++ b/mythtv/external/FFmpeg/libavcodec/vp3dsp.h
@@ -19,13 +19,28 @@
 #ifndef AVCODEC_VP3DSP_H
 #define AVCODEC_VP3DSP_H
 
+#include 
 #include 
-#include "dsputil.h"
 
 typedef struct VP3DSPContext {
-    void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block);
-    void (*idct_add)(uint8_t *dest, int line_size, DCTELEM *block);
-    void (*idct_dc_add)(uint8_t *dest, int line_size, const DCTELEM *block);
+    /**
+     * Copy 8xH pixels from source to destination buffer using a bilinear
+     * filter with no rounding (i.e. *dst = (*a + *b) >> 1).
+     *
+     * @param dst destination buffer, aligned by 8
+     * @param a first source buffer, no alignment
+     * @param b second source buffer, no alignment
+     * @param stride distance between two lines in source/dest buffers
+     * @param h height
+     */
+    void (*put_no_rnd_pixels_l2)(uint8_t *dst,
+                                 const uint8_t *a,
+                                 const uint8_t *b,
+                                 ptrdiff_t stride, int h);
+
+    void (*idct_put)(uint8_t *dest, int line_size, int16_t *block);
+    void (*idct_add)(uint8_t *dest, int line_size, int16_t *block);
+    void (*idct_dc_add)(uint8_t *dest, int line_size, int16_t *block);
     void (*v_loop_filter)(uint8_t *src, int stride, int *bounding_values);
     void (*h_loop_filter)(uint8_t *src, int stride, int *bounding_values);
 
@@ -34,6 +49,7 @@ typedef struct VP3DSPContext {
 
 void ff_vp3dsp_init(VP3DSPContext *c, int flags);
 void ff_vp3dsp_init_arm(VP3DSPContext *c, int flags);
+void ff_vp3dsp_init_bfin(VP3DSPContext *c, int flags);
 void ff_vp3dsp_init_ppc(VP3DSPContext *c, int flags);
 void ff_vp3dsp_init_x86(VP3DSPContext *c, int flags);
 
diff --git a/mythtv/external/FFmpeg/libavcodec/vp5.c b/mythtv/external/FFmpeg/libavcodec/vp5.c
index 46c7fd85f23..10dab39e4c9 100644
--- a/mythtv/external/FFmpeg/libavcodec/vp5.c
+++ b/mythtv/external/FFmpeg/libavcodec/vp5.c
@@ -27,7 +27,6 @@
 #include 
 
 #include "avcodec.h"
-#include "dsputil.h"
 #include "get_bits.h"
 
 #include "vp56.h"
diff --git a/mythtv/external/FFmpeg/libavcodec/vp56.c b/mythtv/external/FFmpeg/libavcodec/vp56.c
index 581ba517bc3..b4af2cac71f 100644
--- a/mythtv/external/FFmpeg/libavcodec/vp56.c
+++ b/mythtv/external/FFmpeg/libavcodec/vp56.c
@@ -26,7 +26,7 @@
 #include "avcodec.h"
 #include "bytestream.h"
 #include "internal.h"
-
+#include "h264chroma.h"
 #include "vp56.h"
 #include "vp56data.h"
 
@@ -373,7 +373,7 @@ static void vp56_mc(VP56Context *s, int b, int plane, uint8_t *src,
             s->filter(s, dst, src_block, src_offset, src_offset+overlap_offset,
                       stride, s->mv[b], mask, s->filter_selection, b<4);
         else
-            s->dsp.put_no_rnd_pixels_l2[1](dst, src_block+src_offset,
+            s->vp3dsp.put_no_rnd_pixels_l2(dst, src_block+src_offset,
                                            src_block+src_offset+overlap_offset,
                                            stride, 8);
     } else {
@@ -394,8 +394,6 @@ static void vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
         mb_type = vp56_decode_mv(s, row, col);
     ref_frame = vp56_reference_frame[mb_type];
 
-    s->dsp.clear_blocks(*s->block_coeff);
-
     s->parse_coeff(s);
 
     vp56_add_predictors_dc(s, ref_frame);
@@ -448,6 +446,11 @@ static void vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
             }
             break;
     }
+
+    if (is_alpha) {
+        s->block_coeff[4][0] = 0;
+        s->block_coeff[5][0] = 0;
+    }
 }
 
 static int vp56_size_changed(VP56Context *s)
@@ -703,6 +706,7 @@ av_cold void ff_vp56_init_context(AVCodecContext *avctx, VP56Context *s,
     avctx->pix_fmt = has_alpha ? AV_PIX_FMT_YUVA420P : AV_PIX_FMT_YUV420P;
 
     ff_dsputil_init(&s->dsp, avctx);
+    ff_h264chroma_init(&s->h264chroma, 8);
     ff_videodsp_init(&s->vdsp, 8);
     ff_vp3dsp_init(&s->vp3dsp, avctx->flags);
     ff_vp56dsp_init(&s->vp56dsp, avctx->codec->id);
diff --git a/mythtv/external/FFmpeg/libavcodec/vp56.h b/mythtv/external/FFmpeg/libavcodec/vp56.h
index 3f0c6474327..14c130f4305 100644
--- a/mythtv/external/FFmpeg/libavcodec/vp56.h
+++ b/mythtv/external/FFmpeg/libavcodec/vp56.h
@@ -30,6 +30,7 @@
 #include "dsputil.h"
 #include "get_bits.h"
 #include "bytestream.h"
+#include "h264chroma.h"
 #include "videodsp.h"
 #include "vp3dsp.h"
 #include "vp56dsp.h"
@@ -67,7 +68,7 @@ typedef struct VP56RangeCoder {
 typedef struct VP56RefDc {
     uint8_t not_null_dc;
     VP56Frame ref_frame;
-    DCTELEM dc_coeff;
+    int16_t dc_coeff;
 } VP56RefDc;
 
 typedef struct VP56Macroblock {
@@ -95,6 +96,7 @@ typedef struct VP56Model {
 struct vp56_context {
     AVCodecContext *avctx;
     DSPContext dsp;
+    H264ChromaContext h264chroma;
     VideoDSPContext vdsp;
     VP3DSPContext vp3dsp;
     VP56DSPContext vp56dsp;
@@ -125,12 +127,12 @@ struct vp56_context {
     VP56RefDc *above_blocks;
     VP56RefDc left_block[4];
     int above_block_idx[6];
-    DCTELEM prev_dc[3][3];    /* [plan][ref_frame] */
+    int16_t prev_dc[3][3];    /* [plan][ref_frame] */
 
     /* blocks / macroblock */
     VP56mb mb_type;
     VP56Macroblock *macroblocks;
-    DECLARE_ALIGNED(16, DCTELEM, block_coeff)[6][64];
+    DECLARE_ALIGNED(16, int16_t, block_coeff)[6][64];
 
     /* motion vectors */
     VP56mv mv[6];  /* vectors for each block in MB */
diff --git a/mythtv/external/FFmpeg/libavcodec/vp6.c b/mythtv/external/FFmpeg/libavcodec/vp6.c
index c6ca13c5c03..f761aa7f29f 100644
--- a/mythtv/external/FFmpeg/libavcodec/vp6.c
+++ b/mythtv/external/FFmpeg/libavcodec/vp6.c
@@ -30,7 +30,6 @@
 #include 
 
 #include "avcodec.h"
-#include "dsputil.h"
 #include "get_bits.h"
 #include "huffman.h"
 
@@ -536,8 +535,8 @@ static void vp6_filter_diag2(VP56Context *s, uint8_t *dst, uint8_t *src,
                              int stride, int h_weight, int v_weight)
 {
     uint8_t *tmp = s->edge_emu_buffer+16;
-    s->dsp.put_h264_chroma_pixels_tab[0](tmp, src, stride, 9, h_weight, 0);
-    s->dsp.put_h264_chroma_pixels_tab[0](dst, tmp, stride, 8, 0, v_weight);
+    s->h264chroma.put_h264_chroma_pixels_tab[0](tmp, src, stride, 9, h_weight, 0);
+    s->h264chroma.put_h264_chroma_pixels_tab[0](dst, tmp, stride, 8, 0, v_weight);
 }
 
 static void vp6_filter(VP56Context *s, uint8_t *dst, uint8_t *src,
@@ -583,7 +582,7 @@ static void vp6_filter(VP56Context *s, uint8_t *dst, uint8_t *src,
         }
     } else {
         if (!x8 || !y8) {
-            s->dsp.put_h264_chroma_pixels_tab[0](dst, src+offset1, stride, 8, x8, y8);
+            s->h264chroma.put_h264_chroma_pixels_tab[0](dst, src + offset1, stride, 8, x8, y8);
         } else {
             vp6_filter_diag2(s, dst, src+offset1 + ((mv.x^mv.y)>>31), stride, x8, y8);
         }
diff --git a/mythtv/external/FFmpeg/libavcodec/vp8.c b/mythtv/external/FFmpeg/libavcodec/vp8.c
index a851fbcf07d..fc6fd3728f3 100644
--- a/mythtv/external/FFmpeg/libavcodec/vp8.c
+++ b/mythtv/external/FFmpeg/libavcodec/vp8.c
@@ -761,7 +761,7 @@ void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y,
  * @return 0 if no coeffs were decoded
  *         otherwise, the index of the last coeff decoded plus one
  */
-static int decode_block_coeffs_internal(VP56RangeCoder *r, DCTELEM block[16],
+static int decode_block_coeffs_internal(VP56RangeCoder *r, int16_t block[16],
                                         uint8_t probs[16][3][NUM_DCT_TOKENS-1],
                                         int i, uint8_t *token_prob, int16_t qmul[2])
 {
@@ -829,7 +829,7 @@ static int decode_block_coeffs_internal(VP56RangeCoder *r, DCTELEM block[16],
  *         otherwise, the index of the last coeff decoded plus one
  */
 static av_always_inline
-int decode_block_coeffs(VP56RangeCoder *c, DCTELEM block[16],
+int decode_block_coeffs(VP56RangeCoder *c, int16_t block[16],
                         uint8_t probs[16][3][NUM_DCT_TOKENS-1],
                         int i, int zero_nhood, int16_t qmul[2])
 {
diff --git a/mythtv/external/FFmpeg/libavcodec/vp8.h b/mythtv/external/FFmpeg/libavcodec/vp8.h
index dbbc751e178..19763907d7f 100644
--- a/mythtv/external/FFmpeg/libavcodec/vp8.h
+++ b/mythtv/external/FFmpeg/libavcodec/vp8.h
@@ -96,8 +96,8 @@ typedef struct VP8Macroblock {
 } VP8Macroblock;
 
 typedef struct VP8ThreadData {
-    DECLARE_ALIGNED(16, DCTELEM, block)[6][4][16];
-    DECLARE_ALIGNED(16, DCTELEM, block_dc)[16];
+    DECLARE_ALIGNED(16, int16_t, block)[6][4][16];
+    DECLARE_ALIGNED(16, int16_t, block_dc)[16];
     /**
      * This is the index plus one of the last non-zero coeff
      * for each of the blocks in the current macroblock.
diff --git a/mythtv/external/FFmpeg/libavcodec/vp8dsp.c b/mythtv/external/FFmpeg/libavcodec/vp8dsp.c
index a53643cd26c..017278ebea6 100644
--- a/mythtv/external/FFmpeg/libavcodec/vp8dsp.c
+++ b/mythtv/external/FFmpeg/libavcodec/vp8dsp.c
@@ -29,7 +29,7 @@
 #include "libavutil/common.h"
 
 // TODO: Maybe add dequant
-static void vp8_luma_dc_wht_c(DCTELEM block[4][4][16], DCTELEM dc[16])
+static void vp8_luma_dc_wht_c(int16_t block[4][4][16], int16_t dc[16])
 {
     int i, t0, t1, t2, t3;
 
@@ -62,7 +62,7 @@ static void vp8_luma_dc_wht_c(DCTELEM block[4][4][16], DCTELEM dc[16])
     }
 }
 
-static void vp8_luma_dc_wht_dc_c(DCTELEM block[4][4][16], DCTELEM dc[16])
+static void vp8_luma_dc_wht_dc_c(int16_t block[4][4][16], int16_t dc[16])
 {
     int i, val = (dc[0] + 3) >> 3;
     dc[0] = 0;
@@ -78,10 +78,10 @@ static void vp8_luma_dc_wht_dc_c(DCTELEM block[4][4][16], DCTELEM dc[16])
 #define MUL_20091(a) ((((a)*20091) >> 16) + (a))
 #define MUL_35468(a)  (((a)*35468) >> 16)
 
-static void vp8_idct_add_c(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride)
+static void vp8_idct_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride)
 {
     int i, t0, t1, t2, t3;
-    DCTELEM tmp[16];
+    int16_t tmp[16];
 
     for (i = 0; i < 4; i++) {
         t0 = block[0*4+i] + block[2*4+i];
@@ -113,7 +113,7 @@ static void vp8_idct_add_c(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride)
     }
 }
 
-static void vp8_idct_dc_add_c(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride)
+static void vp8_idct_dc_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride)
 {
     int i, dc = (block[0] + 4) >> 3;
     block[0] = 0;
@@ -127,7 +127,7 @@ static void vp8_idct_dc_add_c(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride)
     }
 }
 
-static void vp8_idct_dc_add4uv_c(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride)
+static void vp8_idct_dc_add4uv_c(uint8_t *dst, int16_t block[4][16], ptrdiff_t stride)
 {
     vp8_idct_dc_add_c(dst+stride*0+0, block[0], stride);
     vp8_idct_dc_add_c(dst+stride*0+4, block[1], stride);
@@ -135,7 +135,7 @@ static void vp8_idct_dc_add4uv_c(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t s
     vp8_idct_dc_add_c(dst+stride*4+4, block[3], stride);
 }
 
-static void vp8_idct_dc_add4y_c(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride)
+static void vp8_idct_dc_add4y_c(uint8_t *dst, int16_t block[4][16], ptrdiff_t stride)
 {
     vp8_idct_dc_add_c(dst+ 0, block[0], stride);
     vp8_idct_dc_add_c(dst+ 4, block[1], stride);
diff --git a/mythtv/external/FFmpeg/libavcodec/vp8dsp.h b/mythtv/external/FFmpeg/libavcodec/vp8dsp.h
index c4b9aa1a228..6308ff46cf8 100644
--- a/mythtv/external/FFmpeg/libavcodec/vp8dsp.h
+++ b/mythtv/external/FFmpeg/libavcodec/vp8dsp.h
@@ -27,20 +27,21 @@
 #ifndef AVCODEC_VP8DSP_H
 #define AVCODEC_VP8DSP_H
 
-#include "dsputil.h"
+#include 
+#include 
 
 typedef void (*vp8_mc_func)(uint8_t *dst/*align 8*/, ptrdiff_t dstStride,
                             uint8_t *src/*align 1*/, ptrdiff_t srcStride,
                             int h, int x, int y);
 
 typedef struct VP8DSPContext {
-    void (*vp8_luma_dc_wht)(DCTELEM block[4][4][16], DCTELEM dc[16]);
-    void (*vp8_luma_dc_wht_dc)(DCTELEM block[4][4][16], DCTELEM dc[16]);
-    void (*vp8_idct_add)(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride);
-    void (*vp8_idct_dc_add)(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride);
-    void (*vp8_idct_dc_add4y)(uint8_t *dst, DCTELEM block[4][16],
+    void (*vp8_luma_dc_wht)(int16_t block[4][4][16], int16_t dc[16]);
+    void (*vp8_luma_dc_wht_dc)(int16_t block[4][4][16], int16_t dc[16]);
+    void (*vp8_idct_add)(uint8_t *dst, int16_t block[16], ptrdiff_t stride);
+    void (*vp8_idct_dc_add)(uint8_t *dst, int16_t block[16], ptrdiff_t stride);
+    void (*vp8_idct_dc_add4y)(uint8_t *dst, int16_t block[4][16],
                               ptrdiff_t stride);
-    void (*vp8_idct_dc_add4uv)(uint8_t *dst, DCTELEM block[4][16],
+    void (*vp8_idct_dc_add4uv)(uint8_t *dst, int16_t block[4][16],
                                ptrdiff_t stride);
 
     // loop filter applied to edges between macroblocks
diff --git a/mythtv/external/FFmpeg/libavcodec/vqavideo.c b/mythtv/external/FFmpeg/libavcodec/vqavideo.c
index f78055f566c..43b3aaf57cc 100644
--- a/mythtv/external/FFmpeg/libavcodec/vqavideo.c
+++ b/mythtv/external/FFmpeg/libavcodec/vqavideo.c
@@ -122,7 +122,7 @@ typedef struct VqaContext {
 static av_cold int vqa_decode_init(AVCodecContext *avctx)
 {
     VqaContext *s = avctx->priv_data;
-    int i, j, codebook_index;
+    int i, j, codebook_index, ret;
 
     s->avctx = avctx;
     avctx->pix_fmt = AV_PIX_FMT_PAL8;
@@ -130,7 +130,7 @@ static av_cold int vqa_decode_init(AVCodecContext *avctx)
     /* make sure the extradata made it */
     if (s->avctx->extradata_size != VQA_HEADER_SIZE) {
         av_log(s->avctx, AV_LOG_ERROR, "expected extradata size of %d\n", VQA_HEADER_SIZE);
-        return AVERROR_INVALIDDATA;
+        return AVERROR(EINVAL);
     }
 
     /* load up the VQA parameters from the header */
@@ -141,9 +141,9 @@ static av_cold int vqa_decode_init(AVCodecContext *avctx)
     }
     s->width = AV_RL16(&s->avctx->extradata[6]);
     s->height = AV_RL16(&s->avctx->extradata[8]);
-    if(av_image_check_size(s->width, s->height, 0, avctx)){
+    if ((ret = av_image_check_size(s->width, s->height, 0, avctx)) < 0) {
         s->width= s->height= 0;
-        return AVERROR_INVALIDDATA;
+        return ret;
     }
     s->vector_width = s->avctx->extradata[10];
     s->vector_height = s->avctx->extradata[11];
@@ -604,7 +604,7 @@ static int vqa_decode_frame(AVCodecContext *avctx,
     if (s->frame.data[0])
         avctx->release_buffer(avctx, &s->frame);
 
-    if ((res = ff_get_buffer(avctx, &s->frame))) {
+    if ((res = ff_get_buffer(avctx, &s->frame)) < 0) {
         av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return res;
     }
diff --git a/mythtv/external/FFmpeg/libavcodec/wavpack.c b/mythtv/external/FFmpeg/libavcodec/wavpack.c
index 6b67f30b215..b5663b45dfc 100644
--- a/mythtv/external/FFmpeg/libavcodec/wavpack.c
+++ b/mythtv/external/FFmpeg/libavcodec/wavpack.c
@@ -129,7 +129,6 @@ typedef struct WavpackFrameContext {
 
 typedef struct WavpackContext {
     AVCodecContext *avctx;
-    AVFrame frame;
 
     WavpackFrameContext *fdec[WV_MAX_FRAME_DECODERS];
     int fdec_num;
@@ -741,9 +740,6 @@ static av_cold int wavpack_decode_init(AVCodecContext *avctx)
 
     s->fdec_num = 0;
 
-    avcodec_get_frame_defaults(&s->frame);
-    avctx->coded_frame = &s->frame;
-
     return 0;
 }
 
@@ -906,7 +902,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
                 continue;
             }
             t = 0;
-            for (i = s->terms - 1; (i >= 0) && (t < size); i--) {
+            for (i = s->terms - 1; (i >= 0) && (t < size) && buf <= buf_end; i--) {
                 if (s->decorr[i].value > 8) {
                     s->decorr[i].samplesA[0] = wp_exp2(AV_RL16(buf)); buf += 2;
                     s->decorr[i].samplesA[1] = wp_exp2(AV_RL16(buf)); buf += 2;
@@ -921,7 +917,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
                     s->decorr[i].samplesB[0] = wp_exp2(AV_RL16(buf)); buf += 2;
                     t += 4;
                 } else {
-                    for (j = 0; j < s->decorr[i].value; j++) {
+                    for (j = 0; j < s->decorr[i].value && buf+1decorr[i].samplesA[j] = wp_exp2(AV_RL16(buf)); buf += 2;
                         if (s->stereo_in) {
                             s->decorr[i].samplesB[j] = wp_exp2(AV_RL16(buf)); buf += 2;
@@ -1183,6 +1179,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
     WavpackContext *s  = avctx->priv_data;
     const uint8_t *buf = avpkt->data;
     int buf_size       = avpkt->size;
+    AVFrame *frame     = data;
     int frame_size, ret, frame_flags;
     int samplecount = 0;
 
@@ -1218,12 +1215,12 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     /* get output buffer */
-    s->frame.nb_samples = s->samples + 1;
-    if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
+    frame->nb_samples = s->samples + 1;
+    if ((ret = ff_get_buffer(avctx, frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
-    s->frame.nb_samples = s->samples;
+    frame->nb_samples = s->samples;
 
     while (buf_size > 0) {
         if (!s->multichannel) {
@@ -1244,7 +1241,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
             return AVERROR_INVALIDDATA;
         }
         if ((samplecount = wavpack_decode_block(avctx, s->block,
-                                                s->frame.data[0], got_frame_ptr,
+                                                frame->data[0], got_frame_ptr,
                                                 buf, frame_size)) < 0) {
             wavpack_decode_flush(avctx);
             return AVERROR_INVALIDDATA;
@@ -1253,9 +1250,6 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
         buf += frame_size; buf_size -= frame_size;
     }
 
-    if (*got_frame_ptr)
-        *(AVFrame *)data = s->frame;
-
     return avpkt->size;
 }
 
diff --git a/mythtv/external/FFmpeg/libavcodec/wma.c b/mythtv/external/FFmpeg/libavcodec/wma.c
index d0c0b348688..e704223f1ef 100644
--- a/mythtv/external/FFmpeg/libavcodec/wma.c
+++ b/mythtv/external/FFmpeg/libavcodec/wma.c
@@ -82,7 +82,6 @@ int ff_wma_init(AVCodecContext *avctx, int flags2)
         || avctx->bit_rate    <= 0)
         return -1;
 
-    ff_dsputil_init(&s->dsp, avctx);
     ff_fmt_convert_init(&s->fmt_conv, avctx);
     avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
 
@@ -135,6 +134,10 @@ int ff_wma_init(AVCodecContext *avctx, int flags2)
 
     bps = (float)avctx->bit_rate / (float)(avctx->channels * avctx->sample_rate);
     s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0 + 0.5)) + 2;
+    if (s->byte_offset_bits + 3 > MIN_CACHE_BITS) {
+        av_log(avctx, AV_LOG_ERROR, "byte_offset_bits %d is too large\n", s->byte_offset_bits);
+        return AVERROR_PATCHWELCOME;
+    }
 
     /* compute high frequency value and choose if noise coding should
        be activated */
@@ -387,6 +390,11 @@ int ff_wma_end(AVCodecContext *avctx)
         av_free(s->int_table[i]);
     }
 
+#if FF_API_OLD_ENCODE_AUDIO
+    if (av_codec_is_encoder(avctx->codec))
+        av_freep(&avctx->coded_frame);
+#endif
+
     return 0;
 }
 
diff --git a/mythtv/external/FFmpeg/libavcodec/wma.h b/mythtv/external/FFmpeg/libavcodec/wma.h
index 4db4faa54aa..c4056ecef1e 100644
--- a/mythtv/external/FFmpeg/libavcodec/wma.h
+++ b/mythtv/external/FFmpeg/libavcodec/wma.h
@@ -25,7 +25,6 @@
 #include "libavutil/float_dsp.h"
 #include "get_bits.h"
 #include "put_bits.h"
-#include "dsputil.h"
 #include "fft.h"
 #include "fmtconvert.h"
 
@@ -66,7 +65,6 @@ typedef struct CoefVLCTable {
 
 typedef struct WMACodecContext {
     AVCodecContext* avctx;
-    AVFrame frame;
     GetBitContext gb;
     PutBitContext pb;
     int version;                            ///< 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
@@ -132,7 +130,6 @@ typedef struct WMACodecContext {
     float lsp_pow_e_table[256];
     float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
     float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
-    DSPContext dsp;
     FmtConvertContext fmt_conv;
     AVFloatDSPContext fdsp;
 
diff --git a/mythtv/external/FFmpeg/libavcodec/wma_common.h b/mythtv/external/FFmpeg/libavcodec/wma_common.h
index 84d2cda1189..55404afc45a 100644
--- a/mythtv/external/FFmpeg/libavcodec/wma_common.h
+++ b/mythtv/external/FFmpeg/libavcodec/wma_common.h
@@ -21,9 +21,7 @@
 #ifndef AVCODEC_WMA_COMMON_H
 #define AVCODEC_WMA_COMMON_H
 
-#include "libavutil/attributes.h"
-
-av_cold int ff_wma_get_frame_len_bits(int sample_rate, int version,
-                                      unsigned int decode_flags);
+int ff_wma_get_frame_len_bits(int sample_rate, int version,
+                              unsigned int decode_flags);
 
 #endif /* AVCODEC_WMA_COMMON_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/wmadec.c b/mythtv/external/FFmpeg/libavcodec/wmadec.c
index 613a434ab1b..cdd285002df 100644
--- a/mythtv/external/FFmpeg/libavcodec/wmadec.c
+++ b/mythtv/external/FFmpeg/libavcodec/wmadec.c
@@ -72,11 +72,6 @@ static int wma_decode_init(AVCodecContext * avctx)
     int i, flags2;
     uint8_t *extradata;
 
-    if (!avctx->block_align) {
-        av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
-        return AVERROR(EINVAL);
-    }
-
     s->avctx = avctx;
 
     /* extract flag infos */
@@ -122,9 +117,6 @@ static int wma_decode_init(AVCodecContext * avctx)
 
     avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
 
-    avcodec_get_frame_defaults(&s->frame);
-    avctx->coded_frame = &s->frame;
-
     return 0;
 }
 
@@ -391,16 +383,16 @@ static void wma_window(WMACodecContext *s, float *out)
         block_len = s->block_len;
         bsize = s->frame_len_bits - s->block_len_bits;
 
-        s->dsp.vector_fmul_add(out, in, s->windows[bsize],
-                               out, block_len);
+        s->fdsp.vector_fmul_add(out, in, s->windows[bsize],
+                                out, block_len);
 
     } else {
         block_len = 1 << s->prev_block_len_bits;
         n = (s->block_len - block_len) / 2;
         bsize = s->frame_len_bits - s->prev_block_len_bits;
 
-        s->dsp.vector_fmul_add(out+n, in+n, s->windows[bsize],
-                               out+n, block_len);
+        s->fdsp.vector_fmul_add(out+n, in+n, s->windows[bsize],
+                                out+n, block_len);
 
         memcpy(out+n+block_len, in+n+block_len, n*sizeof(float));
     }
@@ -413,7 +405,7 @@ static void wma_window(WMACodecContext *s, float *out)
         block_len = s->block_len;
         bsize = s->frame_len_bits - s->block_len_bits;
 
-        s->dsp.vector_fmul_reverse(out, in, s->windows[bsize], block_len);
+        s->fdsp.vector_fmul_reverse(out, in, s->windows[bsize], block_len);
 
     } else {
         block_len = 1 << s->next_block_len_bits;
@@ -422,7 +414,7 @@ static void wma_window(WMACodecContext *s, float *out)
 
         memcpy(out, in, n*sizeof(float));
 
-        s->dsp.vector_fmul_reverse(out+n, in+n, s->windows[bsize], block_len);
+        s->fdsp.vector_fmul_reverse(out+n, in+n, s->windows[bsize], block_len);
 
         memset(out+n+block_len, 0, n*sizeof(float));
     }
@@ -736,7 +728,7 @@ static int wma_decode_block(WMACodecContext *s)
             s->channel_coded[0] = 1;
         }
 
-        s->dsp.butterflies_float(s->coefs[0], s->coefs[1], s->block_len);
+        s->fdsp.butterflies_float(s->coefs[0], s->coefs[1], s->block_len);
     }
 
 next:
@@ -805,6 +797,7 @@ static int wma_decode_frame(WMACodecContext *s, float **samples,
 static int wma_decode_superframe(AVCodecContext *avctx, void *data,
                                  int *got_frame_ptr, AVPacket *avpkt)
 {
+    AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     WMACodecContext *s = avctx->priv_data;
@@ -834,17 +827,21 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
         /* read super frame header */
         skip_bits(&s->gb, 4); /* super frame index */
         nb_frames = get_bits(&s->gb, 4) - (s->last_superframe_len <= 0);
+        if (nb_frames <= 0) {
+            av_log(avctx, AV_LOG_ERROR, "nb_frames is %d\n", nb_frames);
+            return AVERROR_INVALIDDATA;
+        }
     } else {
         nb_frames = 1;
     }
 
     /* get output buffer */
-    s->frame.nb_samples = nb_frames * s->frame_len;
-    if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
+    frame->nb_samples = nb_frames * s->frame_len;
+    if ((ret = ff_get_buffer(avctx, frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
-    samples = (float **)s->frame.extended_data;
+    samples = (float **)frame->extended_data;
     samples_offset = 0;
 
     if (s->use_bit_reservoir) {
@@ -923,8 +920,7 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
             s->frame_len_bits, s->block_len_bits, s->frame_len, s->block_len,
             (int8_t *)samples - (int8_t *)data, avctx->block_align);
 
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = s->frame;
+    *got_frame_ptr = 1;
 
     return buf_size;
  fail:
diff --git a/mythtv/external/FFmpeg/libavcodec/wmaenc.c b/mythtv/external/FFmpeg/libavcodec/wmaenc.c
index 5aebe81bc0c..e15109519ba 100644
--- a/mythtv/external/FFmpeg/libavcodec/wmaenc.c
+++ b/mythtv/external/FFmpeg/libavcodec/wmaenc.c
@@ -50,6 +50,11 @@ static int encode_init(AVCodecContext * avctx){
         return AVERROR(EINVAL);
     }
 
+#if FF_API_OLD_ENCODE_AUDIO
+    if (!(avctx->coded_frame = avcodec_alloc_frame()))
+        return AVERROR(ENOMEM);
+#endif
+
     /* extract flag infos */
     flags1 = 0;
     flags2 = 1;
@@ -85,11 +90,6 @@ static int encode_init(AVCodecContext * avctx){
 
     avctx->frame_size = avctx->delay = s->frame_len;
 
-#if FF_API_OLD_ENCODE_AUDIO
-    avctx->coded_frame = &s->frame;
-    avcodec_get_frame_defaults(avctx->coded_frame);
-#endif
-
     return 0;
 }
 
@@ -109,7 +109,7 @@ static void apply_window_and_mdct(AVCodecContext * avctx, const AVFrame *frame)
     for (ch = 0; ch < avctx->channels; ch++) {
         memcpy(s->output, s->frame_out[ch], window_len * sizeof(*s->output));
         s->fdsp.vector_fmul_scalar(s->frame_out[ch], audio[ch], n, len);
-        s->dsp.vector_fmul_reverse(&s->output[window_len], s->frame_out[ch], win, len);
+        s->fdsp.vector_fmul_reverse(&s->output[window_len], s->frame_out[ch], win, len);
         s->fdsp.vector_fmul(s->frame_out[ch], s->frame_out[ch], win, len);
         mdct->mdct_calc(mdct, s->coefs[ch], s->output);
     }
@@ -366,7 +366,7 @@ static int encode_superframe(AVCodecContext *avctx, AVPacket *avpkt,
         }
     }
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * MAX_CODED_SUPERFRAME_SIZE)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * MAX_CODED_SUPERFRAME_SIZE)) < 0)
         return ret;
 
     total_gain= 128;
diff --git a/mythtv/external/FFmpeg/libavcodec/wmalosslessdec.c b/mythtv/external/FFmpeg/libavcodec/wmalosslessdec.c
index 4f372619ee8..331a027133e 100644
--- a/mythtv/external/FFmpeg/libavcodec/wmalosslessdec.c
+++ b/mythtv/external/FFmpeg/libavcodec/wmalosslessdec.c
@@ -123,7 +123,7 @@ typedef struct WmallDecodeCtx {
     int8_t  acfilter_order;
     int8_t  acfilter_scaling;
     int64_t acfilter_coeffs[16];
-    int     acfilter_prevvalues[2][16];
+    int     acfilter_prevvalues[WMALL_MAX_CHANNELS][16];
 
     int8_t  mclms_order;
     int8_t  mclms_scaling;
@@ -145,29 +145,29 @@ typedef struct WmallDecodeCtx {
         int16_t lms_prevvalues[MAX_ORDER * 2];
         int16_t lms_updates[MAX_ORDER * 2];
         int recent;
-    } cdlms[2][9];
+    } cdlms[WMALL_MAX_CHANNELS][9];
 
-    int cdlms_ttl[2];
+    int cdlms_ttl[WMALL_MAX_CHANNELS];
 
     int bV3RTM;
 
-    int is_channel_coded[2];
-    int update_speed[2];
+    int is_channel_coded[WMALL_MAX_CHANNELS];
+    int update_speed[WMALL_MAX_CHANNELS];
 
-    int transient[2];
-    int transient_pos[2];
+    int transient[WMALL_MAX_CHANNELS];
+    int transient_pos[WMALL_MAX_CHANNELS];
     int seekable_tile;
 
-    int ave_sum[2];
+    int ave_sum[WMALL_MAX_CHANNELS];
 
-    int channel_residues[2][WMALL_BLOCK_MAX_SIZE];
+    int channel_residues[WMALL_MAX_CHANNELS][WMALL_BLOCK_MAX_SIZE];
 
-    int lpc_coefs[2][40];
+    int lpc_coefs[WMALL_MAX_CHANNELS][40];
     int lpc_order;
     int lpc_scaling;
     int lpc_intbits;
 
-    int channel_coeffs[2][WMALL_BLOCK_MAX_SIZE];
+    int channel_coeffs[WMALL_MAX_CHANNELS][WMALL_BLOCK_MAX_SIZE];
 } WmallDecodeCtx;
 
 
diff --git a/mythtv/external/FFmpeg/libavcodec/wmaprodec.c b/mythtv/external/FFmpeg/libavcodec/wmaprodec.c
index f6a11e3e142..a772e7371a8 100644
--- a/mythtv/external/FFmpeg/libavcodec/wmaprodec.c
+++ b/mythtv/external/FFmpeg/libavcodec/wmaprodec.c
@@ -94,7 +94,6 @@
 #include "get_bits.h"
 #include "put_bits.h"
 #include "wmaprodata.h"
-#include "dsputil.h"
 #include "sinewin.h"
 #include "wma.h"
 #include "wma_common.h"
@@ -169,8 +168,6 @@ typedef struct {
 typedef struct WMAProDecodeCtx {
     /* generic decoder variables */
     AVCodecContext*  avctx;                         ///< codec context for av_log
-    AVFrame          frame;                         ///< AVFrame for decoded output
-    DSPContext       dsp;                           ///< accelerated DSP functions
     AVFloatDSPContext fdsp;
     uint8_t          frame_data[MAX_FRAMESIZE +
                       FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data
@@ -280,13 +277,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     int log2_max_num_subframes;
     int num_possible_block_sizes;
 
-    if (!avctx->block_align) {
-        av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
-        return AVERROR(EINVAL);
-    }
-
     s->avctx = avctx;
-    ff_dsputil_init(&s->dsp, avctx);
     avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
 
     init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
@@ -478,9 +469,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     avctx->channel_layout = channel_mask;
 
-    avcodec_get_frame_defaults(&s->frame);
-    avctx->coded_frame = &s->frame;
-
     return 0;
 }
 
@@ -1061,8 +1049,8 @@ static void wmapro_window(WMAProDecodeCtx *s)
 
         winlen >>= 1;
 
-        s->dsp.vector_fmul_window(start, start, start + winlen,
-                                  window, winlen);
+        s->fdsp.vector_fmul_window(start, start, start + winlen,
+                                   window, winlen);
 
         s->channel[c].prev_block_len = s->subframe_len;
     }
@@ -1311,7 +1299,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
  *@return 0 if the trailer bit indicates that this is the last frame,
  *        1 if there are additional frames
  */
-static int decode_frame(WMAProDecodeCtx *s, int *got_frame_ptr)
+static int decode_frame(WMAProDecodeCtx *s, AVFrame *frame, int *got_frame_ptr)
 {
     AVCodecContext *avctx = s->avctx;
     GetBitContext* gb = &s->gb;
@@ -1384,8 +1372,8 @@ static int decode_frame(WMAProDecodeCtx *s, int *got_frame_ptr)
     }
 
     /* get output buffer */
-    s->frame.nb_samples = s->samples_per_frame;
-    if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
+    frame->nb_samples = s->samples_per_frame;
+    if ((ret = ff_get_buffer(avctx, frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         s->packet_loss = 1;
         return 0;
@@ -1393,7 +1381,7 @@ static int decode_frame(WMAProDecodeCtx *s, int *got_frame_ptr)
 
     /** copy samples to the output buffer */
     for (i = 0; i < avctx->channels; i++)
-        memcpy(s->frame.extended_data[i], s->channel[i].out,
+        memcpy(frame->extended_data[i], s->channel[i].out,
                s->samples_per_frame * sizeof(*s->channel[i].out));
 
     for (i = 0; i < avctx->channels; i++) {
@@ -1520,11 +1508,8 @@ static int decode_packet(AVCodecContext *avctx, void *data,
         s->packet_done = 0;
 
         /** sanity check for the buffer length */
-        if (buf_size < avctx->block_align) {
-            av_log(avctx, AV_LOG_ERROR, "Input packet too small (%d < %d)\n",
-                   buf_size, avctx->block_align);
-            return AVERROR_INVALIDDATA;
-        }
+        if (buf_size < avctx->block_align)
+            return 0;
 
         s->next_packet_start = buf_size - avctx->block_align;
         buf_size = avctx->block_align;
@@ -1564,7 +1549,7 @@ static int decode_packet(AVCodecContext *avctx, void *data,
 
             /** decode the cross packet frame if it is valid */
             if (!s->packet_loss)
-                decode_frame(s, got_frame_ptr);
+                decode_frame(s, data, got_frame_ptr);
         } else if (s->num_saved_bits - s->frame_offset) {
             av_dlog(avctx, "ignoring %x previously saved bits\n",
                     s->num_saved_bits - s->frame_offset);
@@ -1587,7 +1572,7 @@ static int decode_packet(AVCodecContext *avctx, void *data,
             (frame_size = show_bits(gb, s->log2_frame_size)) &&
             frame_size <= remaining_bits(s, gb)) {
             save_bits(s, gb, frame_size, 0);
-            s->packet_done = !decode_frame(s, got_frame_ptr);
+            s->packet_done = !decode_frame(s, data, got_frame_ptr);
         } else if (!s->len_prefix
                    && s->num_saved_bits > get_bits_count(&s->gb)) {
             /** when the frames do not have a length prefix, we don't know
@@ -1597,7 +1582,7 @@ static int decode_packet(AVCodecContext *avctx, void *data,
                 therefore we save the incoming packet first, then we append
                 the "previous frame" data from the next packet so that
                 we get a buffer that only contains full frames */
-            s->packet_done = !decode_frame(s, got_frame_ptr);
+            s->packet_done = !decode_frame(s, data, got_frame_ptr);
         } else
             s->packet_done = 1;
     }
@@ -1613,9 +1598,6 @@ static int decode_packet(AVCodecContext *avctx, void *data,
     if (s->packet_loss)
         return AVERROR_INVALIDDATA;
 
-    if (*got_frame_ptr)
-        *(AVFrame *)data = s->frame;
-
     return get_bits_count(gb) >> 3;
 }
 
diff --git a/mythtv/external/FFmpeg/libavcodec/wmavoice.c b/mythtv/external/FFmpeg/libavcodec/wmavoice.c
index 0ae3748911f..a82ee946a5c 100644
--- a/mythtv/external/FFmpeg/libavcodec/wmavoice.c
+++ b/mythtv/external/FFmpeg/libavcodec/wmavoice.c
@@ -25,13 +25,11 @@
  * @author Ronald S. Bultje 
  */
 
-#define UNCHECKED_BITSTREAM_READER 1
-
 #include 
 
 #include "libavutil/channel_layout.h"
+#include "libavutil/float_dsp.h"
 #include "libavutil/mem.h"
-#include "dsputil.h"
 #include "avcodec.h"
 #include "internal.h"
 #include "get_bits.h"
@@ -136,7 +134,6 @@ typedef struct {
      * @name Global values specified in the stream header / extradata or used all over.
      * @{
      */
-    AVFrame frame;
     GetBitContext gb;             ///< packet bitreader. During decoder init,
                                   ///< it contains the extradata from the
                                   ///< demuxer. During decoding, it contains
@@ -445,9 +442,6 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
     ctx->channel_layout         = AV_CH_LAYOUT_MONO;
     ctx->sample_fmt             = AV_SAMPLE_FMT_FLT;
 
-    avcodec_get_frame_defaults(&s->frame);
-    ctx->coded_frame = &s->frame;
-
     return 0;
 }
 
@@ -523,7 +517,7 @@ static int kalman_smoothen(WMAVoiceContext *s, int pitch,
 
     /* find best fitting point in history */
     do {
-        dot = ff_scalarproduct_float_c(in, ptr, size);
+        dot = avpriv_scalarproduct_float_c(in, ptr, size);
         if (dot > optimal_gain) {
             optimal_gain  = dot;
             best_hist_ptr = ptr;
@@ -532,7 +526,7 @@ static int kalman_smoothen(WMAVoiceContext *s, int pitch,
 
     if (optimal_gain <= 0)
         return -1;
-    dot = ff_scalarproduct_float_c(best_hist_ptr, best_hist_ptr, size);
+    dot = avpriv_scalarproduct_float_c(best_hist_ptr, best_hist_ptr, size);
     if (dot <= 0) // would be 1.0
         return -1;
 
@@ -562,8 +556,8 @@ static float tilt_factor(const float *lpcs, int n_lpcs)
 {
     float rh0, rh1;
 
-    rh0 = 1.0     + ff_scalarproduct_float_c(lpcs,  lpcs,    n_lpcs);
-    rh1 = lpcs[0] + ff_scalarproduct_float_c(lpcs, &lpcs[1], n_lpcs - 1);
+    rh0 = 1.0     + avpriv_scalarproduct_float_c(lpcs,  lpcs,    n_lpcs);
+    rh1 = lpcs[0] + avpriv_scalarproduct_float_c(lpcs, &lpcs[1], n_lpcs - 1);
 
     return rh1 / rh0;
 }
@@ -656,7 +650,8 @@ static void calc_input_response(WMAVoiceContext *s, float *lpcs,
                              -1.8 * tilt_factor(coeffs, remainder - 1),
                              coeffs, remainder);
     }
-    sq = (1.0 / 64.0) * sqrtf(1 / ff_scalarproduct_float_c(coeffs, coeffs, remainder));
+    sq = (1.0 / 64.0) * sqrtf(1 / avpriv_scalarproduct_float_c(coeffs, coeffs,
+                                                               remainder));
     for (n = 0; n < remainder; n++)
         coeffs[n] *= sq;
 }
@@ -1320,7 +1315,8 @@ static void synth_block_fcb_acb(WMAVoiceContext *s, GetBitContext *gb,
     /* Calculate gain for adaptive & fixed codebook signal.
      * see ff_amr_set_fixed_gain(). */
     idx = get_bits(gb, 7);
-    fcb_gain = expf(ff_scalarproduct_float_c(s->gain_pred_err, gain_coeff, 6) -
+    fcb_gain = expf(avpriv_scalarproduct_float_c(s->gain_pred_err,
+                                                 gain_coeff, 6) -
                     5.2409161640 + wmavoice_gain_codebook_fcb[idx]);
     acb_gain = wmavoice_gain_codebook_acb[idx];
     pred_err = av_clipf(wmavoice_gain_codebook_fcb[idx],
@@ -1440,8 +1436,8 @@ static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx,
                        float *excitation, float *synth)
 {
     WMAVoiceContext *s = ctx->priv_data;
-    int n, n_blocks_x2, log_n_blocks_x2, cur_pitch_val;
-    int pitch[MAX_BLOCKS], last_block_pitch;
+    int n, n_blocks_x2, log_n_blocks_x2, av_uninit(cur_pitch_val);
+    int pitch[MAX_BLOCKS], av_uninit(last_block_pitch);
 
     /* Parse frame type ("frame header"), see frame_descs */
     int bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)], block_nsamples;
@@ -1733,7 +1729,8 @@ static int check_bits_for_superframe(GetBitContext *orig_gb,
  * @return 0 on success, <0 on error or 1 if there was not enough data to
  *         fully parse the superframe
  */
-static int synth_superframe(AVCodecContext *ctx, int *got_frame_ptr)
+static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,
+                            int *got_frame_ptr)
 {
     WMAVoiceContext *s = ctx->priv_data;
     GetBitContext *gb = &s->gb, s_gb;
@@ -1801,13 +1798,13 @@ static int synth_superframe(AVCodecContext *ctx, int *got_frame_ptr)
     }
 
     /* get output buffer */
-    s->frame.nb_samples = 480;
-    if ((res = ff_get_buffer(ctx, &s->frame)) < 0) {
+    frame->nb_samples = 480;
+    if ((res = ff_get_buffer(ctx, frame)) < 0) {
         av_log(ctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return res;
     }
-    s->frame.nb_samples = n_samples;
-    samples = (float *)s->frame.data[0];
+    frame->nb_samples = n_samples;
+    samples = (float *)frame->data[0];
 
     /* Parse frames, optionally preceded by per-frame (independent) LSPs. */
     for (n = 0; n < 3; n++) {
@@ -1964,11 +1961,10 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, void *data,
                 copy_bits(&s->pb, avpkt->data, size, gb, s->spillover_nbits);
                 flush_put_bits(&s->pb);
                 s->sframe_cache_size += s->spillover_nbits;
-                if ((res = synth_superframe(ctx, got_frame_ptr)) == 0 &&
+                if ((res = synth_superframe(ctx, data, got_frame_ptr)) == 0 &&
                     *got_frame_ptr) {
                     cnt += s->spillover_nbits;
                     s->skip_bits_next = cnt & 7;
-                    *(AVFrame *)data = s->frame;
                     return cnt >> 3;
                 } else
                     skip_bits_long (gb, s->spillover_nbits - cnt +
@@ -1983,12 +1979,11 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, void *data,
     s->sframe_cache_size = 0;
     s->skip_bits_next = 0;
     pos = get_bits_left(gb);
-    if ((res = synth_superframe(ctx, got_frame_ptr)) < 0) {
+    if ((res = synth_superframe(ctx, data, got_frame_ptr)) < 0) {
         return res;
     } else if (*got_frame_ptr) {
         int cnt = get_bits_count(gb);
         s->skip_bits_next = cnt & 7;
-        *(AVFrame *)data = s->frame;
         return cnt >> 3;
     } else if ((s->sframe_cache_size = pos) > 0) {
         /* rewind bit reader to start of last (incomplete) superframe... */
diff --git a/mythtv/external/FFmpeg/libavcodec/wmv2.c b/mythtv/external/FFmpeg/libavcodec/wmv2.c
index c338bb10df2..6676652350f 100644
--- a/mythtv/external/FFmpeg/libavcodec/wmv2.c
+++ b/mythtv/external/FFmpeg/libavcodec/wmv2.c
@@ -28,17 +28,34 @@
 av_cold void ff_wmv2_common_init(Wmv2Context * w){
     MpegEncContext * const s= &w->s;
 
-    ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[0], ff_wmv2_scantableA);
-    ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[1], ff_wmv2_scantableB);
+    ff_wmv2dsp_init(&w->wdsp);
+    s->dsp.idct_permutation_type = w->wdsp.idct_perm;
+    ff_init_scantable_permutation(s->dsp.idct_permutation,
+                                  w->wdsp.idct_perm);
+    ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[0],
+                      ff_wmv2_scantableA);
+    ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[1],
+                      ff_wmv2_scantableB);
+    ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable,
+                      ff_wmv1_scantable[1]);
+    ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable,
+                      ff_wmv1_scantable[2]);
+    ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable,
+                      ff_wmv1_scantable[3]);
+    ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable,
+                      ff_wmv1_scantable[0]);
+    s->dsp.idct_put = w->wdsp.idct_put;
+    s->dsp.idct_add = w->wdsp.idct_add;
+    s->dsp.idct     = NULL;
 }
 
-static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int stride, int n){
+static void wmv2_add_block(Wmv2Context *w, int16_t *block1, uint8_t *dst, int stride, int n){
     MpegEncContext * const s= &w->s;
 
   if (s->block_last_index[n] >= 0) {
     switch(w->abt_type_table[n]){
     case 0:
-        s->dsp.idct_add (dst, stride, block1);
+        w->wdsp.idct_add(dst, stride, block1);
         break;
     case 1:
         ff_simple_idct84_add(dst           , stride, block1);
@@ -56,7 +73,7 @@ static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int st
   }
 }
 
-void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr){
+void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr){
     Wmv2Context * const w= (Wmv2Context*)s;
 
     wmv2_add_block(w, block1[0], dest_y                    , s->linesize, 0);
diff --git a/mythtv/external/FFmpeg/libavcodec/wmv2.h b/mythtv/external/FFmpeg/libavcodec/wmv2.h
index c69c9f48ee0..52739c1f9c2 100644
--- a/mythtv/external/FFmpeg/libavcodec/wmv2.h
+++ b/mythtv/external/FFmpeg/libavcodec/wmv2.h
@@ -22,9 +22,9 @@
 #define AVCODEC_WMV2_H
 
 #include "avcodec.h"
-#include "dsputil.h"
 #include "mpegvideo.h"
 #include "intrax8.h"
+#include "wmv2dsp.h"
 
 #define SKIP_TYPE_NONE 0
 #define SKIP_TYPE_MPEG 1
@@ -35,6 +35,7 @@
 typedef struct Wmv2Context{
     MpegEncContext s;
     IntraX8Context x8;
+    WMV2DSPContext wdsp;
     int j_type_bit;
     int j_type;
     int abt_flag;
@@ -50,7 +51,7 @@ typedef struct Wmv2Context{
     int hshift;
 
     ScanTable abt_scantable[2];
-    DECLARE_ALIGNED(16, DCTELEM, abt_block2)[6][64];
+    DECLARE_ALIGNED(16, int16_t, abt_block2)[6][64];
 }Wmv2Context;
 
 void ff_wmv2_common_init(Wmv2Context * w);
diff --git a/mythtv/external/FFmpeg/libavcodec/wmv2dec.c b/mythtv/external/FFmpeg/libavcodec/wmv2dec.c
index df11c219dae..fc7a1b3ede6 100644
--- a/mythtv/external/FFmpeg/libavcodec/wmv2dec.c
+++ b/mythtv/external/FFmpeg/libavcodec/wmv2dec.c
@@ -19,7 +19,6 @@
  */
 
 #include "avcodec.h"
-#include "dsputil.h"
 #include "mpegvideo.h"
 #include "h263.h"
 #include "mathops.h"
@@ -291,7 +290,7 @@ static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py){
     return mot_val;
 }
 
-static inline int wmv2_decode_inter_block(Wmv2Context *w, DCTELEM *block, int n, int cbp){
+static inline int wmv2_decode_inter_block(Wmv2Context *w, int16_t *block, int n, int cbp){
     MpegEncContext * const s= &w->s;
     static const int sub_cbp_table[3]= {2,3,1};
     int sub_cbp;
@@ -331,7 +330,7 @@ static inline int wmv2_decode_inter_block(Wmv2Context *w, DCTELEM *block, int n,
 }
 
 
-int ff_wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
+int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
 {
     Wmv2Context * const w= (Wmv2Context*)s;
     int cbp, code, i;
@@ -447,10 +446,6 @@ int ff_wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
 static av_cold int wmv2_decode_init(AVCodecContext *avctx){
     Wmv2Context * const w= avctx->priv_data;
 
-    if(avctx->idct_algo==FF_IDCT_AUTO){
-        avctx->idct_algo=FF_IDCT_WMV2;
-    }
-
     if(ff_msmpeg4_decode_init(avctx) < 0)
         return -1;
 
diff --git a/mythtv/external/FFmpeg/libavcodec/wmv2dsp.c b/mythtv/external/FFmpeg/libavcodec/wmv2dsp.c
new file mode 100644
index 00000000000..9627442b370
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/wmv2dsp.c
@@ -0,0 +1,146 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/attributes.h"
+#include "libavutil/common.h"
+#include "avcodec.h"
+#include "dsputil.h"
+#include "wmv2dsp.h"
+
+#define W0 2048
+#define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
+#define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
+#define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
+#define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
+#define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
+#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
+#define W7 565  /* 2048*sqrt (2)*cos (7*pi/16) */
+
+static void wmv2_idct_row(short * b)
+{
+    int s1, s2;
+    int a0, a1, a2, a3, a4, a5, a6, a7;
+
+    /* step 1 */
+    a1 = W1 * b[1] + W7 * b[7];
+    a7 = W7 * b[1] - W1 * b[7];
+    a5 = W5 * b[5] + W3 * b[3];
+    a3 = W3 * b[5] - W5 * b[3];
+    a2 = W2 * b[2] + W6 * b[6];
+    a6 = W6 * b[2] - W2 * b[6];
+    a0 = W0 * b[0] + W0 * b[4];
+    a4 = W0 * b[0] - W0 * b[4];
+
+    /* step 2 */
+    s1 = (181 * (a1 - a5 + a7 - a3) + 128) >> 8; // 1, 3, 5, 7
+    s2 = (181 * (a1 - a5 - a7 + a3) + 128) >> 8;
+
+    /* step 3 */
+    b[0] = (a0 + a2 + a1 + a5 + (1 << 7)) >> 8;
+    b[1] = (a4 + a6 + s1      + (1 << 7)) >> 8;
+    b[2] = (a4 - a6 + s2      + (1 << 7)) >> 8;
+    b[3] = (a0 - a2 + a7 + a3 + (1 << 7)) >> 8;
+    b[4] = (a0 - a2 - a7 - a3 + (1 << 7)) >> 8;
+    b[5] = (a4 - a6 - s2      + (1 << 7)) >> 8;
+    b[6] = (a4 + a6 - s1      + (1 << 7)) >> 8;
+    b[7] = (a0 + a2 - a1 - a5 + (1 << 7)) >> 8;
+}
+
+static void wmv2_idct_col(short * b)
+{
+    int s1, s2;
+    int a0, a1, a2, a3, a4, a5, a6, a7;
+
+    /* step 1, with extended precision */
+    a1 = (W1 * b[8 * 1] + W7 * b[8 * 7] + 4) >> 3;
+    a7 = (W7 * b[8 * 1] - W1 * b[8 * 7] + 4) >> 3;
+    a5 = (W5 * b[8 * 5] + W3 * b[8 * 3] + 4) >> 3;
+    a3 = (W3 * b[8 * 5] - W5 * b[8 * 3] + 4) >> 3;
+    a2 = (W2 * b[8 * 2] + W6 * b[8 * 6] + 4) >> 3;
+    a6 = (W6 * b[8 * 2] - W2 * b[8 * 6] + 4) >> 3;
+    a0 = (W0 * b[8 * 0] + W0 * b[8 * 4]    ) >> 3;
+    a4 = (W0 * b[8 * 0] - W0 * b[8 * 4]    ) >> 3;
+
+    /* step 2 */
+    s1 = (181 * (a1 - a5 + a7 - a3) + 128) >> 8;
+    s2 = (181 * (a1 - a5 - a7 + a3) + 128) >> 8;
+
+    /* step 3 */
+    b[8 * 0] = (a0 + a2 + a1 + a5 + (1 << 13)) >> 14;
+    b[8 * 1] = (a4 + a6 + s1      + (1 << 13)) >> 14;
+    b[8 * 2] = (a4 - a6 + s2      + (1 << 13)) >> 14;
+    b[8 * 3] = (a0 - a2 + a7 + a3 + (1 << 13)) >> 14;
+
+    b[8 * 4] = (a0 - a2 - a7 - a3 + (1 << 13)) >> 14;
+    b[8 * 5] = (a4 - a6 - s2      + (1 << 13)) >> 14;
+    b[8 * 6] = (a4 + a6 - s1      + (1 << 13)) >> 14;
+    b[8 * 7] = (a0 + a2 - a1 - a5 + (1 << 13)) >> 14;
+}
+
+static void wmv2_idct_add_c(uint8_t *dest, int line_size, int16_t *block)
+{
+    int i;
+
+    for (i = 0; i < 64; i += 8)
+        wmv2_idct_row(block + i);
+    for (i = 0; i < 8; i++)
+        wmv2_idct_col(block + i);
+
+    for (i = 0; i < 8; i++) {
+        dest[0] = av_clip_uint8(dest[0] + block[0]);
+        dest[1] = av_clip_uint8(dest[1] + block[1]);
+        dest[2] = av_clip_uint8(dest[2] + block[2]);
+        dest[3] = av_clip_uint8(dest[3] + block[3]);
+        dest[4] = av_clip_uint8(dest[4] + block[4]);
+        dest[5] = av_clip_uint8(dest[5] + block[5]);
+        dest[6] = av_clip_uint8(dest[6] + block[6]);
+        dest[7] = av_clip_uint8(dest[7] + block[7]);
+        dest += line_size;
+        block += 8;
+    }
+}
+
+static void wmv2_idct_put_c(uint8_t *dest, int line_size, int16_t *block)
+{
+    int i;
+
+    for (i = 0; i < 64; i += 8)
+        wmv2_idct_row(block + i);
+    for (i = 0; i < 8; i++)
+        wmv2_idct_col(block + i);
+
+    for (i = 0; i < 8; i++) {
+        dest[0] = av_clip_uint8(block[0]);
+        dest[1] = av_clip_uint8(block[1]);
+        dest[2] = av_clip_uint8(block[2]);
+        dest[3] = av_clip_uint8(block[3]);
+        dest[4] = av_clip_uint8(block[4]);
+        dest[5] = av_clip_uint8(block[5]);
+        dest[6] = av_clip_uint8(block[6]);
+        dest[7] = av_clip_uint8(block[7]);
+        dest += line_size;
+        block += 8;
+    }
+}
+
+av_cold void ff_wmv2dsp_init(WMV2DSPContext *c)
+{
+    c->idct_add  = wmv2_idct_add_c;
+    c->idct_put  = wmv2_idct_put_c;
+    c->idct_perm = FF_NO_IDCT_PERM;
+}
diff --git a/mythtv/external/FFmpeg/libavcodec/wmv2dsp.h b/mythtv/external/FFmpeg/libavcodec/wmv2dsp.h
new file mode 100644
index 00000000000..37bee205aa5
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/wmv2dsp.h
@@ -0,0 +1,33 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_WMV2DSP_H
+#define AVCODEC_WMV2DSP_H
+
+#include 
+
+typedef struct WMV2DSPContext {
+    void (*idct_add)(uint8_t *dest, int line_size, int16_t *block);
+    void (*idct_put)(uint8_t *dest, int line_size, int16_t *block);
+
+    int idct_perm;
+} WMV2DSPContext;
+
+void ff_wmv2dsp_init(WMV2DSPContext *c);
+
+#endif /* AVCODEC_WMV2DSP_H */
diff --git a/mythtv/external/FFmpeg/libavcodec/wmv2enc.c b/mythtv/external/FFmpeg/libavcodec/wmv2enc.c
index e6e1e678c1f..23b64a76a22 100644
--- a/mythtv/external/FFmpeg/libavcodec/wmv2enc.c
+++ b/mythtv/external/FFmpeg/libavcodec/wmv2enc.c
@@ -19,7 +19,6 @@
  */
 
 #include "avcodec.h"
-#include "dsputil.h"
 #include "mpegvideo.h"
 #include "msmpeg4.h"
 #include "msmpeg4data.h"
@@ -148,7 +147,7 @@ int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number)
  * useless M$ crap features. It is duplicated here in case someone wants
  * to add support for these crap features. */
 void ff_wmv2_encode_mb(MpegEncContext * s,
-                       DCTELEM block[6][64],
+                       int16_t block[6][64],
                        int motion_x, int motion_y)
 {
     Wmv2Context * const w= (Wmv2Context*)s;
diff --git a/mythtv/external/FFmpeg/libavcodec/ws-snd1.c b/mythtv/external/FFmpeg/libavcodec/ws-snd1.c
index 1c347e85a2a..24ebcebfe0e 100644
--- a/mythtv/external/FFmpeg/libavcodec/ws-snd1.c
+++ b/mythtv/external/FFmpeg/libavcodec/ws-snd1.c
@@ -41,28 +41,19 @@ static const int8_t ws_adpcm_4bit[] = {
      0,  1,  2,  3,  4,  5,  6,  8
 };
 
-typedef struct WSSndContext {
-    AVFrame frame;
-} WSSndContext;
-
 static av_cold int ws_snd_decode_init(AVCodecContext *avctx)
 {
-    WSSndContext *s = avctx->priv_data;
-
     avctx->channels       = 1;
     avctx->channel_layout = AV_CH_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_U8;
 
-    avcodec_get_frame_defaults(&s->frame);
-    avctx->coded_frame = &s->frame;
-
     return 0;
 }
 
 static int ws_snd_decode_frame(AVCodecContext *avctx, void *data,
                                int *got_frame_ptr, AVPacket *avpkt)
 {
-    WSSndContext *s = avctx->priv_data;
+    AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
     int buf_size       = avpkt->size;
 
@@ -89,18 +80,17 @@ static int ws_snd_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     /* get output buffer */
-    s->frame.nb_samples = out_size;
-    if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
+    frame->nb_samples = out_size;
+    if ((ret = ff_get_buffer(avctx, frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
-    samples     = s->frame.data[0];
+    samples     = frame->data[0];
     samples_end = samples + out_size;
 
     if (in_size == out_size) {
         memcpy(samples, buf, out_size);
-        *got_frame_ptr   = 1;
-        *(AVFrame *)data = s->frame;
+        *got_frame_ptr = 1;
         return buf_size;
     }
 
@@ -176,9 +166,8 @@ static int ws_snd_decode_frame(AVCodecContext *avctx, void *data,
         }
     }
 
-    s->frame.nb_samples = samples - s->frame.data[0];
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = s->frame;
+    frame->nb_samples = samples - frame->data[0];
+    *got_frame_ptr    = 1;
 
     return buf_size;
 }
@@ -187,7 +176,6 @@ AVCodec ff_ws_snd1_decoder = {
     .name           = "ws_snd1",
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_WESTWOOD_SND1,
-    .priv_data_size = sizeof(WSSndContext),
     .init           = ws_snd_decode_init,
     .decode         = ws_snd_decode_frame,
     .capabilities   = CODEC_CAP_DR1,
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/Makefile b/mythtv/external/FFmpeg/libavcodec/x86/Makefile
index 34254e4fde6..ff7ea776eff 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/Makefile
+++ b/mythtv/external/FFmpeg/libavcodec/x86/Makefile
@@ -6,8 +6,10 @@ OBJS-$(CONFIG_CAVS_DECODER)            += x86/cavsdsp.o
 OBJS-$(CONFIG_DNXHD_ENCODER)           += x86/dnxhdenc.o
 OBJS-$(CONFIG_FFT)                     += x86/fft_init.o
 OBJS-$(CONFIG_GPL)                     += x86/idct_mmx.o
+OBJS-$(CONFIG_H264CHROMA)              += x86/h264chroma_init.o
 OBJS-$(CONFIG_H264DSP)                 += x86/h264dsp_init.o
 OBJS-$(CONFIG_H264PRED)                += x86/h264_intrapred_init.o
+OBJS-$(CONFIG_H264QPEL)                += x86/h264_qpel.o
 OBJS-$(CONFIG_LPC)                     += x86/lpc.o
 OBJS-$(CONFIG_MLP_DECODER)             += x86/mlpdsp.o
 OBJS-$(CONFIG_MPEGAUDIODSP)            += x86/mpegaudiodec.o
@@ -23,6 +25,7 @@ OBJS-$(CONFIG_V210_DECODER)            += x86/v210-init.o
 OBJS-$(CONFIG_TRUEHD_DECODER)          += x86/mlpdsp.o
 OBJS-$(CONFIG_VC1_DECODER)             += x86/vc1dsp_init.o
 OBJS-$(CONFIG_VIDEODSP)                += x86/videodsp_init.o
+OBJS-$(CONFIG_VORBIS_DECODER)          += x86/vorbisdsp_init.o
 OBJS-$(CONFIG_VP3DSP)                  += x86/vp3dsp_init.o
 OBJS-$(CONFIG_VP5_DECODER)             += x86/vp56dsp_init.o
 OBJS-$(CONFIG_VP6_DECODER)             += x86/vp56dsp_init.o
@@ -35,19 +38,22 @@ MMX-OBJS                               += x86/dsputil_mmx.o             \
                                           x86/idct_sse2_xvid.o          \
                                           x86/simple_idct.o             \
 
-MMX-OBJS-$(CONFIG_DWT)                 += x86/snowdsp.o \
-                                          x86/dwt.o
 MMX-OBJS-$(CONFIG_ENCODERS)            += x86/dsputilenc_mmx.o          \
                                           x86/motion_est.o
+MMX-OBJS-$(CONFIG_DIRAC_DECODER)       += x86/dirac_dwt.o
+MMX-OBJS-$(CONFIG_SNOW_DECODER)        += x86/snowdsp.o
+MMX-OBJS-$(CONFIG_SNOW_ENCODER)        += x86/snowdsp.o
 MMX-OBJS-$(CONFIG_VC1_DECODER)         += x86/vc1dsp_mmx.o
 
 YASM-OBJS-$(CONFIG_AAC_DECODER)        += x86/sbrdsp.o
 YASM-OBJS-$(CONFIG_AC3DSP)             += x86/ac3dsp.o
 YASM-OBJS-$(CONFIG_DCT)                += x86/dct32.o
-YASM-OBJS-$(CONFIG_DIRAC_DECODER)      += x86/diracdsp_mmx.o x86/diracdsp_yasm.o
-YASM-OBJS-$(CONFIG_DWT)                += x86/dwt_yasm.o
+YASM-OBJS-$(CONFIG_DIRAC_DECODER)      += x86/diracdsp_mmx.o x86/diracdsp_yasm.o\
+                                          x86/dwt_yasm.o
 YASM-OBJS-$(CONFIG_ENCODERS)           += x86/dsputilenc.o
 YASM-OBJS-$(CONFIG_FFT)                += x86/fft.o
+YASM-OBJS-$(CONFIG_H263_DECODER)       += x86/h263_loopfilter.o
+YASM-OBJS-$(CONFIG_H263_ENCODER)       += x86/h263_loopfilter.o
 YASM-OBJS-$(CONFIG_H264CHROMA)         += x86/h264_chromamc.o           \
                                           x86/h264_chromamc_10bit.o
 YASM-OBJS-$(CONFIG_H264DSP)            += x86/h264_deblock.o            \
@@ -70,6 +76,7 @@ YASM-OBJS-$(CONFIG_RV40_DECODER)       += x86/rv34dsp.o                 \
 YASM-OBJS-$(CONFIG_V210_DECODER)       += x86/v210.o
 YASM-OBJS-$(CONFIG_VC1_DECODER)        += x86/vc1dsp.o
 YASM-OBJS-$(CONFIG_VIDEODSP)           += x86/videodsp.o
+YASM-OBJS-$(CONFIG_VORBIS_DECODER)     += x86/vorbisdsp.o
 YASM-OBJS-$(CONFIG_VP3DSP)             += x86/vp3dsp.o
 YASM-OBJS-$(CONFIG_VP6_DECODER)        += x86/vp56dsp.o
 YASM-OBJS-$(CONFIG_VP8_DECODER)        += x86/vp8dsp.o
@@ -77,3 +84,5 @@ YASM-OBJS-$(CONFIG_VP8_DECODER)        += x86/vp8dsp.o
 YASM-OBJS                              += x86/dsputil.o                 \
                                           x86/deinterlace.o             \
                                           x86/fmtconvert.o              \
+                                          x86/hpeldsp.o                 \
+                                          x86/mpeg4qpel.o               \
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/ac3dsp.asm b/mythtv/external/FFmpeg/libavcodec/x86/ac3dsp.asm
index 4958a7b67e8..98fb4462bc4 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/ac3dsp.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/ac3dsp.asm
@@ -151,15 +151,12 @@ cglobal ac3_max_msb_abs_int16, 2,2,5, src, len
 %endmacro
 
 INIT_MMX mmx
-%define ABS2 ABS2_MMX
 AC3_MAX_MSB_ABS_INT16 or_abs
 INIT_MMX mmxext
-%define ABS2 ABS2_MMXEXT
 AC3_MAX_MSB_ABS_INT16 min_max
 INIT_XMM sse2
 AC3_MAX_MSB_ABS_INT16 min_max
 INIT_XMM ssse3
-%define ABS2 ABS2_SSSE3
 AC3_MAX_MSB_ABS_INT16 or_abs
 
 ;-----------------------------------------------------------------------------
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/cabac.h b/mythtv/external/FFmpeg/libavcodec/x86/cabac.h
index 35f4ca7fdd6..2c9f77e3ff8 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/cabac.h
+++ b/mythtv/external/FFmpeg/libavcodec/x86/cabac.h
@@ -151,7 +151,7 @@
 
 
 #if HAVE_7REGS && !(defined(__i386) && defined(__clang__) && (__clang_major__<2 || (__clang_major__==2 && __clang_minor__<10)))\
-               && !(defined(__i386) && !defined(__clang__) && defined(__llvm__) && __GNUC__==4 && __GNUC_MINOR__==2 && __GNUC_PATCHLEVEL__<=1)
+               && !(                  !defined(__clang__) && defined(__llvm__) && __GNUC__==4 && __GNUC_MINOR__==2 && __GNUC_PATCHLEVEL__<=1)
 #define get_cabac_inline get_cabac_inline_x86
 static av_always_inline int get_cabac_inline_x86(CABACContext *c,
                                                  uint8_t *const state)
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/cavsdsp.c b/mythtv/external/FFmpeg/libavcodec/x86/cavsdsp.c
index 6a252e0fb77..dd7558439e5 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/cavsdsp.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/cavsdsp.c
@@ -22,11 +22,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/common.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
-#include "libavcodec/dsputil.h"
 #include "libavcodec/cavsdsp.h"
 #include "dsputil_mmx.h"
 #include "config.h"
@@ -446,7 +446,8 @@ CAVS_MC(put_, 16, mmxext)
 CAVS_MC(avg_,  8, mmxext)
 CAVS_MC(avg_, 16, mmxext)
 
-static void ff_cavsdsp_init_mmxext(CAVSDSPContext *c, AVCodecContext *avctx)
+static av_cold void ff_cavsdsp_init_mmxext(CAVSDSPContext *c,
+                                           AVCodecContext *avctx)
 {
 #define dspfunc(PFX, IDX, NUM) \
     c->PFX ## _pixels_tab[IDX][ 0] = ff_ ## PFX ## NUM ## _mc00_mmxext; \
@@ -474,7 +475,9 @@ CAVS_MC(put_, 16,3dnow)
 CAVS_MC(avg_, 8, 3dnow)
 CAVS_MC(avg_, 16,3dnow)
 
-static void ff_cavsdsp_init_3dnow(CAVSDSPContext* c, AVCodecContext *avctx) {
+static av_cold void ff_cavsdsp_init_3dnow(CAVSDSPContext *c,
+                                          AVCodecContext *avctx)
+{
 #define dspfunc(PFX, IDX, NUM) \
     c->PFX ## _pixels_tab[IDX][ 0] = ff_ ## PFX ## NUM ## _mc00_mmxext; \
     c->PFX ## _pixels_tab[IDX][ 2] = ff_ ## PFX ## NUM ## _mc20_3dnow; \
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/dwt.c b/mythtv/external/FFmpeg/libavcodec/x86/dirac_dwt.c
similarity index 99%
rename from mythtv/external/FFmpeg/libavcodec/x86/dwt.c
rename to mythtv/external/FFmpeg/libavcodec/x86/dirac_dwt.c
index e718c80fef7..fbb25a417c2 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/dwt.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/dirac_dwt.c
@@ -22,7 +22,7 @@
 
 #include "libavutil/x86/asm.h"
 #include "dsputil_mmx.h"
-#include "dwt.h"
+#include "dirac_dwt.h"
 
 #define COMPOSE_VERTICAL(ext, align) \
 void ff_vertical_compose53iL0##ext(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width); \
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/dwt.h b/mythtv/external/FFmpeg/libavcodec/x86/dirac_dwt.h
similarity index 91%
rename from mythtv/external/FFmpeg/libavcodec/x86/dwt.h
rename to mythtv/external/FFmpeg/libavcodec/x86/dirac_dwt.h
index 199f61175b3..126b29029fc 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/dwt.h
+++ b/mythtv/external/FFmpeg/libavcodec/x86/dirac_dwt.h
@@ -16,10 +16,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef AVCODEC_X86_DWT_H
-#define AVCODEC_X86_DWT_H
+#ifndef AVCODEC_X86_DIRAC_DWT_H
+#define AVCODEC_X86_DIRAC_DWT_H
 
-#include "libavcodec/dwt.h"
+#include "libavcodec/dirac_dwt.h"
 
 void ff_horizontal_compose_dd97i_end_c(IDWTELEM *b, IDWTELEM *tmp, int w2, int x);
 void ff_horizontal_compose_haar1i_end_c(IDWTELEM *b, IDWTELEM *tmp, int w2, int x);
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/diracdsp_mmx.c b/mythtv/external/FFmpeg/libavcodec/x86/diracdsp_mmx.c
index ee89295c945..cb6465f950e 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/diracdsp_mmx.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/diracdsp_mmx.c
@@ -60,6 +60,9 @@ void ff_diracdsp_init_mmx(DiracDSPContext* c)
 {
     int mm_flags = av_get_cpu_flags();
 
+    if (!(mm_flags & AV_CPU_FLAG_MMX))
+        return;
+
 #if HAVE_YASM
     c->add_dirac_obmc[0] = ff_add_dirac_obmc8_mmx;
 #if !ARCH_X86_64
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/diracdsp_yasm.asm b/mythtv/external/FFmpeg/libavcodec/x86/diracdsp_yasm.asm
index d12fc64dd5d..3e9765b42dd 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/diracdsp_yasm.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/diracdsp_yasm.asm
@@ -136,6 +136,8 @@ cglobal put_signed_rect_clamped_%1, 5,9,3, dst, dst_stride, src, src_stride, w,
     and     wd, ~(mmsize-1)
 
 %if ARCH_X86_64
+    movsxd   dst_strideq, dst_strided
+    movsxd   src_strideq, src_strided
     mov   r7d, r5m
     mov   r8d, wd
     %define wspill r8d
@@ -177,6 +179,8 @@ cglobal add_rect_clamped_%1, 7,9,3, dst, src, stride, idwt, idwt_stride, w, h
     and     wd, ~(mmsize-1)
 
 %if ARCH_X86_64
+    movsxd   strideq, strided
+    movsxd   idwt_strideq, idwt_strided
     mov   r8d, wd
     %define wspill r8d
 %else
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/dnxhdenc.c b/mythtv/external/FFmpeg/libavcodec/x86/dnxhdenc.c
index b2ba894bf3a..349fbb08257 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/dnxhdenc.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/dnxhdenc.c
@@ -21,12 +21,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/x86/asm.h"
 #include "libavcodec/dnxhdenc.h"
 
 #if HAVE_SSE2_INLINE
 
-static void get_pixels_8x4_sym_sse2(DCTELEM *block, const uint8_t *pixels, int line_size)
+static void get_pixels_8x4_sym_sse2(int16_t *block, const uint8_t *pixels, int line_size)
 {
     __asm__ volatile(
         "pxor %%xmm5,      %%xmm5       \n\t"
@@ -54,7 +55,7 @@ static void get_pixels_8x4_sym_sse2(DCTELEM *block, const uint8_t *pixels, int l
 
 #endif /* HAVE_SSE2_INLINE */
 
-void ff_dnxhdenc_init_x86(DNXHDEncContext *ctx)
+av_cold void ff_dnxhdenc_init_x86(DNXHDEncContext *ctx)
 {
 #if HAVE_SSE2_INLINE
     if (av_get_cpu_flags() & AV_CPU_FLAG_SSE2) {
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/dsputil.asm b/mythtv/external/FFmpeg/libavcodec/x86/dsputil.asm
index 89f36392d70..aa18bddd67a 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/dsputil.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/dsputil.asm
@@ -1,6 +1,8 @@
 ;******************************************************************************
 ;* MMX optimized DSP utils
 ;* Copyright (c) 2008 Loren Merritt
+;* Copyright (c) 2003-2013 Michael Niedermayer
+;* Copyright (c) 2013 Daniel Kang
 ;*
 ;* This file is part of FFmpeg.
 ;*
@@ -463,32 +465,6 @@ cglobal add_hfyu_left_prediction, 3,3,7, dst, src, w, left
 .src_unaligned:
     ADD_HFYU_LEFT_LOOP 0, 0
 
-
-; float scalarproduct_float_sse(const float *v1, const float *v2, int len)
-INIT_XMM sse
-cglobal scalarproduct_float, 3,3,2, v1, v2, offset
-    neg offsetq
-    shl offsetq, 2
-    sub v1q, offsetq
-    sub v2q, offsetq
-    xorps xmm0, xmm0
-    .loop:
-        movaps   xmm1, [v1q+offsetq]
-        mulps    xmm1, [v2q+offsetq]
-        addps    xmm0, xmm1
-        add      offsetq, 16
-        js       .loop
-    movhlps xmm1, xmm0
-    addps   xmm0, xmm1
-    movss   xmm1, xmm0
-    shufps  xmm0, xmm0, 1
-    addss   xmm0, xmm1
-%if ARCH_X86_64 == 0
-    movss   r0m,  xmm0
-    fld     dword r0m
-%endif
-    RET
-
 ;-----------------------------------------------------------------------------
 ; void ff_vector_clip_int32(int32_t *dst, const int32_t *src, int32_t min,
 ;                           int32_t max, unsigned int len)
@@ -567,121 +543,6 @@ VECTOR_CLIP_INT32 11, 1, 1, 0
 VECTOR_CLIP_INT32 6, 1, 0, 0
 %endif
 
-;-----------------------------------------------------------------------------
-; void vector_fmul_reverse(float *dst, const float *src0, const float *src1,
-;                          int len)
-;-----------------------------------------------------------------------------
-%macro VECTOR_FMUL_REVERSE 0
-cglobal vector_fmul_reverse, 4,4,2, dst, src0, src1, len
-    lea       lenq, [lend*4 - 2*mmsize]
-ALIGN 16
-.loop:
-%if cpuflag(avx)
-    vmovaps     xmm0, [src1q + 16]
-    vinsertf128 m0, m0, [src1q], 1
-    vshufps     m0, m0, m0, q0123
-    vmovaps     xmm1, [src1q + mmsize + 16]
-    vinsertf128 m1, m1, [src1q + mmsize], 1
-    vshufps     m1, m1, m1, q0123
-%else
-    mova    m0, [src1q]
-    mova    m1, [src1q + mmsize]
-    shufps  m0, m0, q0123
-    shufps  m1, m1, q0123
-%endif
-    mulps   m0, m0, [src0q + lenq + mmsize]
-    mulps   m1, m1, [src0q + lenq]
-    mova    [dstq + lenq + mmsize], m0
-    mova    [dstq + lenq], m1
-    add     src1q, 2*mmsize
-    sub     lenq,  2*mmsize
-    jge     .loop
-    REP_RET
-%endmacro
-
-INIT_XMM sse
-VECTOR_FMUL_REVERSE
-%if HAVE_AVX_EXTERNAL
-INIT_YMM avx
-VECTOR_FMUL_REVERSE
-%endif
-
-;-----------------------------------------------------------------------------
-; vector_fmul_add(float *dst, const float *src0, const float *src1,
-;                 const float *src2, int len)
-;-----------------------------------------------------------------------------
-%macro VECTOR_FMUL_ADD 0
-cglobal vector_fmul_add, 5,5,2, dst, src0, src1, src2, len
-    lea       lenq, [lend*4 - 2*mmsize]
-ALIGN 16
-.loop:
-    mova    m0,   [src0q + lenq]
-    mova    m1,   [src0q + lenq + mmsize]
-    mulps   m0, m0, [src1q + lenq]
-    mulps   m1, m1, [src1q + lenq + mmsize]
-    addps   m0, m0, [src2q + lenq]
-    addps   m1, m1, [src2q + lenq + mmsize]
-    mova    [dstq + lenq], m0
-    mova    [dstq + lenq + mmsize], m1
-
-    sub     lenq,   2*mmsize
-    jge     .loop
-    REP_RET
-%endmacro
-
-INIT_XMM sse
-VECTOR_FMUL_ADD
-%if HAVE_AVX_EXTERNAL
-INIT_YMM avx
-VECTOR_FMUL_ADD
-%endif
-
-;-----------------------------------------------------------------------------
-; void ff_butterflies_float_interleave(float *dst, const float *src0,
-;                                      const float *src1, int len);
-;-----------------------------------------------------------------------------
-
-%macro BUTTERFLIES_FLOAT_INTERLEAVE 0
-cglobal butterflies_float_interleave, 4,4,3, dst, src0, src1, len
-%if ARCH_X86_64
-    movsxd    lenq, lend
-%endif
-    test      lenq, lenq
-    jz .end
-    shl       lenq, 2
-    lea      src0q, [src0q +   lenq]
-    lea      src1q, [src1q +   lenq]
-    lea       dstq, [ dstq + 2*lenq]
-    neg       lenq
-.loop:
-    mova        m0, [src0q + lenq]
-    mova        m1, [src1q + lenq]
-    subps       m2, m0, m1
-    addps       m0, m0, m1
-    unpcklps    m1, m0, m2
-    unpckhps    m0, m0, m2
-%if cpuflag(avx)
-    vextractf128 [dstq + 2*lenq     ], m1, 0
-    vextractf128 [dstq + 2*lenq + 16], m0, 0
-    vextractf128 [dstq + 2*lenq + 32], m1, 1
-    vextractf128 [dstq + 2*lenq + 48], m0, 1
-%else
-    mova [dstq + 2*lenq         ], m1
-    mova [dstq + 2*lenq + mmsize], m0
-%endif
-    add       lenq, mmsize
-    jl .loop
-.end:
-    REP_RET
-%endmacro
-
-INIT_XMM sse
-BUTTERFLIES_FLOAT_INTERLEAVE
-%if HAVE_AVX_EXTERNAL
-INIT_YMM avx
-BUTTERFLIES_FLOAT_INTERLEAVE
-%endif
-
 ; %1 = aligned/unaligned
 %macro BSWAP_LOOPS  1
     mov      r3, r2
@@ -790,6 +651,10 @@ BSWAP32_BUF
 INIT_XMM ssse3
 BSWAP32_BUF
 
+
+; FIXME: All of the code below should be put back in h264_qpel_8bit.asm.
+; Unfortunately it is unconditionally used from dsputil_mmx.c since 71155d7 ..
+
 %macro op_avgh 3
     movh   %3, %2
     pavgb  %1, %3
@@ -977,46 +842,3 @@ PIXELS48 put, 4
 PIXELS48 avg, 4
 PIXELS48 put, 8
 PIXELS48 avg, 8
-
-INIT_XMM sse2
-; void put_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-cglobal put_pixels16, 4,5,4
-    movsxdifnidn r2, r2d
-    lea          r4, [r2*3]
-.loop:
-    movu         m0, [r1]
-    movu         m1, [r1+r2]
-    movu         m2, [r1+r2*2]
-    movu         m3, [r1+r4]
-    lea          r1, [r1+r2*4]
-    mova       [r0], m0
-    mova    [r0+r2], m1
-    mova  [r0+r2*2], m2
-    mova    [r0+r4], m3
-    sub         r3d, 4
-    lea          r0, [r0+r2*4]
-    jnz       .loop
-    REP_RET
-
-; void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-cglobal avg_pixels16, 4,5,4
-    movsxdifnidn r2, r2d
-    lea          r4, [r2*3]
-.loop:
-    movu         m0, [r1]
-    movu         m1, [r1+r2]
-    movu         m2, [r1+r2*2]
-    movu         m3, [r1+r4]
-    lea          r1, [r1+r2*4]
-    pavgb        m0, [r0]
-    pavgb        m1, [r0+r2]
-    pavgb        m2, [r0+r2*2]
-    pavgb        m3, [r0+r4]
-    mova       [r0], m0
-    mova    [r0+r2], m1
-    mova  [r0+r2*2], m2
-    mova    [r0+r4], m3
-    sub         r3d, 4
-    lea          r0, [r0+r2*4]
-    jnz       .loop
-    REP_RET
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/dsputil_avg_template.c b/mythtv/external/FFmpeg/libavcodec/x86/dsputil_avg_template.c
index 17f89556945..b9a8f834003 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/dsputil_avg_template.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/dsputil_avg_template.c
@@ -24,832 +24,54 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/* XXX: we use explicit registers to avoid a gcc 2.95.2 register asm
-   clobber bug - now it will work with 2.95.2 and also with -fPIC
- */
-static void DEF(put_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
-    __asm__ volatile(
-        "lea (%3, %3), %%"REG_a"        \n\t"
-        "1:                             \n\t"
-        "movq (%1), %%mm0               \n\t"
-        "movq (%1, %3), %%mm1           \n\t"
-        PAVGB" 1(%1), %%mm0             \n\t"
-        PAVGB" 1(%1, %3), %%mm1         \n\t"
-        "movq %%mm0, (%2)               \n\t"
-        "movq %%mm1, (%2, %3)           \n\t"
-        "add %%"REG_a", %1              \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "movq (%1), %%mm0               \n\t"
-        "movq (%1, %3), %%mm1           \n\t"
-        PAVGB" 1(%1), %%mm0             \n\t"
-        PAVGB" 1(%1, %3), %%mm1         \n\t"
-        "add %%"REG_a", %1              \n\t"
-        "movq %%mm0, (%2)               \n\t"
-        "movq %%mm1, (%2, %3)           \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "subl $4, %0                    \n\t"
-        "jnz 1b                         \n\t"
-        :"+g"(h), "+S"(pixels), "+D"(block)
-        :"r" ((x86_reg)line_size)
-        :"%"REG_a, "memory");
-}
-
-#ifndef SKIP_FOR_3DNOW
-static void DEF(put_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
-{
-    __asm__ volatile(
-        "testl $1, %0                   \n\t"
-            " jz 1f                     \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   (%2), %%mm1             \n\t"
-        "add    %4, %1                  \n\t"
-        "add    $8, %2                  \n\t"
-        PAVGB" %%mm1, %%mm0             \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "decl   %0                      \n\t"
-        "1:                             \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "add    %4, %1                  \n\t"
-        "movq   (%1), %%mm1             \n\t"
-        "add    %4, %1                  \n\t"
-        PAVGB" (%2), %%mm0              \n\t"
-        PAVGB" 8(%2), %%mm1             \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "movq   %%mm1, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "add    %4, %1                  \n\t"
-        "movq   (%1), %%mm1             \n\t"
-        "add    %4, %1                  \n\t"
-        PAVGB" 16(%2), %%mm0            \n\t"
-        PAVGB" 24(%2), %%mm1            \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "movq   %%mm1, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "add    $32, %2                 \n\t"
-        "subl   $4, %0                  \n\t"
-        "jnz    1b                      \n\t"
-#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
-        :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#else
-        :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#endif
-        :"S"((x86_reg)src1Stride), "D"((x86_reg)dstStride)
-        :"memory");
-//the following should be used, though better not with gcc ...
-/*        :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
-        :"r"(src1Stride), "r"(dstStride)
-        :"memory");*/
-}
-
-static void DEF(put_no_rnd_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
-{
-    __asm__ volatile(
-        "pcmpeqb %%mm6, %%mm6           \n\t"
-        "testl $1, %0                   \n\t"
-            " jz 1f                     \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   (%2), %%mm1             \n\t"
-        "add    %4, %1                  \n\t"
-        "add    $8, %2                  \n\t"
-        "pxor %%mm6, %%mm0              \n\t"
-        "pxor %%mm6, %%mm1              \n\t"
-        PAVGB" %%mm1, %%mm0             \n\t"
-        "pxor %%mm6, %%mm0              \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "decl   %0                      \n\t"
-        "1:                             \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "add    %4, %1                  \n\t"
-        "movq   (%1), %%mm1             \n\t"
-        "add    %4, %1                  \n\t"
-        "movq   (%2), %%mm2             \n\t"
-        "movq   8(%2), %%mm3            \n\t"
-        "pxor %%mm6, %%mm0              \n\t"
-        "pxor %%mm6, %%mm1              \n\t"
-        "pxor %%mm6, %%mm2              \n\t"
-        "pxor %%mm6, %%mm3              \n\t"
-        PAVGB" %%mm2, %%mm0             \n\t"
-        PAVGB" %%mm3, %%mm1             \n\t"
-        "pxor %%mm6, %%mm0              \n\t"
-        "pxor %%mm6, %%mm1              \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "movq   %%mm1, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "add    %4, %1                  \n\t"
-        "movq   (%1), %%mm1             \n\t"
-        "add    %4, %1                  \n\t"
-        "movq   16(%2), %%mm2           \n\t"
-        "movq   24(%2), %%mm3           \n\t"
-        "pxor %%mm6, %%mm0              \n\t"
-        "pxor %%mm6, %%mm1              \n\t"
-        "pxor %%mm6, %%mm2              \n\t"
-        "pxor %%mm6, %%mm3              \n\t"
-        PAVGB" %%mm2, %%mm0             \n\t"
-        PAVGB" %%mm3, %%mm1             \n\t"
-        "pxor %%mm6, %%mm0              \n\t"
-        "pxor %%mm6, %%mm1              \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "movq   %%mm1, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "add    $32, %2                 \n\t"
-        "subl   $4, %0                  \n\t"
-        "jnz    1b                      \n\t"
-#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
-        :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#else
-        :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#endif
-        :"S"((x86_reg)src1Stride), "D"((x86_reg)dstStride)
-        :"memory");
-//the following should be used, though better not with gcc ...
-/*        :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
-        :"r"(src1Stride), "r"(dstStride)
-        :"memory");*/
-}
-
-static void DEF(avg_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
-{
-    __asm__ volatile(
-        "testl $1, %0                   \n\t"
-            " jz 1f                     \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   (%2), %%mm1             \n\t"
-        "add    %4, %1                  \n\t"
-        "add    $8, %2                  \n\t"
-        PAVGB" %%mm1, %%mm0             \n\t"
-        PAVGB" (%3), %%mm0              \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "decl   %0                      \n\t"
-        "1:                             \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "add    %4, %1                  \n\t"
-        "movq   (%1), %%mm1             \n\t"
-        "add    %4, %1                  \n\t"
-        PAVGB" (%2), %%mm0              \n\t"
-        PAVGB" 8(%2), %%mm1             \n\t"
-        PAVGB" (%3), %%mm0              \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        PAVGB" (%3), %%mm1              \n\t"
-        "movq   %%mm1, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "add    %4, %1                  \n\t"
-        "movq   (%1), %%mm1             \n\t"
-        "add    %4, %1                  \n\t"
-        PAVGB" 16(%2), %%mm0            \n\t"
-        PAVGB" 24(%2), %%mm1            \n\t"
-        PAVGB" (%3), %%mm0              \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        PAVGB" (%3), %%mm1              \n\t"
-        "movq   %%mm1, (%3)             \n\t"
-        "add    %5, %3                  \n\t"
-        "add    $32, %2                 \n\t"
-        "subl   $4, %0                  \n\t"
-        "jnz    1b                      \n\t"
-#if !HAVE_EBX_AVAILABLE  //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
-        :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#else
-        :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#endif
-        :"S"((x86_reg)src1Stride), "D"((x86_reg)dstStride)
-        :"memory");
-//the following should be used, though better not with gcc ...
-/*        :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
-        :"r"(src1Stride), "r"(dstStride)
-        :"memory");*/
-}
-#endif /* SKIP_FOR_3DNOW */
-
-static void DEF(put_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
-    __asm__ volatile(
-        "lea (%3, %3), %%"REG_a"        \n\t"
-        "1:                             \n\t"
-        "movq (%1), %%mm0               \n\t"
-        "movq (%1, %3), %%mm1           \n\t"
-        "movq 8(%1), %%mm2              \n\t"
-        "movq 8(%1, %3), %%mm3          \n\t"
-        PAVGB" 1(%1), %%mm0             \n\t"
-        PAVGB" 1(%1, %3), %%mm1         \n\t"
-        PAVGB" 9(%1), %%mm2             \n\t"
-        PAVGB" 9(%1, %3), %%mm3         \n\t"
-        "movq %%mm0, (%2)               \n\t"
-        "movq %%mm1, (%2, %3)           \n\t"
-        "movq %%mm2, 8(%2)              \n\t"
-        "movq %%mm3, 8(%2, %3)          \n\t"
-        "add %%"REG_a", %1              \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "movq (%1), %%mm0               \n\t"
-        "movq (%1, %3), %%mm1           \n\t"
-        "movq 8(%1), %%mm2              \n\t"
-        "movq 8(%1, %3), %%mm3          \n\t"
-        PAVGB" 1(%1), %%mm0             \n\t"
-        PAVGB" 1(%1, %3), %%mm1         \n\t"
-        PAVGB" 9(%1), %%mm2             \n\t"
-        PAVGB" 9(%1, %3), %%mm3         \n\t"
-        "add %%"REG_a", %1              \n\t"
-        "movq %%mm0, (%2)               \n\t"
-        "movq %%mm1, (%2, %3)           \n\t"
-        "movq %%mm2, 8(%2)              \n\t"
-        "movq %%mm3, 8(%2, %3)          \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "subl $4, %0                    \n\t"
-        "jnz 1b                         \n\t"
-        :"+g"(h), "+S"(pixels), "+D"(block)
-        :"r" ((x86_reg)line_size)
-        :"%"REG_a, "memory");
-}
-
-#ifndef SKIP_FOR_3DNOW
-static void DEF(put_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
-{
-    __asm__ volatile(
-        "testl $1, %0                   \n\t"
-            " jz 1f                     \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   8(%1), %%mm1            \n\t"
-        PAVGB" (%2), %%mm0              \n\t"
-        PAVGB" 8(%2), %%mm1             \n\t"
-        "add    %4, %1                  \n\t"
-        "add    $16, %2                 \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "movq   %%mm1, 8(%3)            \n\t"
-        "add    %5, %3                  \n\t"
-        "decl   %0                      \n\t"
-        "1:                             \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   8(%1), %%mm1            \n\t"
-        "add    %4, %1                  \n\t"
-        PAVGB" (%2), %%mm0              \n\t"
-        PAVGB" 8(%2), %%mm1             \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "movq   %%mm1, 8(%3)            \n\t"
-        "add    %5, %3                  \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   8(%1), %%mm1            \n\t"
-        "add    %4, %1                  \n\t"
-        PAVGB" 16(%2), %%mm0            \n\t"
-        PAVGB" 24(%2), %%mm1            \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "movq   %%mm1, 8(%3)            \n\t"
-        "add    %5, %3                  \n\t"
-        "add    $32, %2                 \n\t"
-        "subl   $2, %0                  \n\t"
-        "jnz    1b                      \n\t"
-#if !HAVE_EBX_AVAILABLE  //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
-        :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#else
-        :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#endif
-        :"S"((x86_reg)src1Stride), "D"((x86_reg)dstStride)
-        :"memory");
-//the following should be used, though better not with gcc ...
-/*        :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
-        :"r"(src1Stride), "r"(dstStride)
-        :"memory");*/
-}
-
-static void DEF(avg_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
-{
-    __asm__ volatile(
-        "testl $1, %0                   \n\t"
-            " jz 1f                     \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   8(%1), %%mm1            \n\t"
-        PAVGB" (%2), %%mm0              \n\t"
-        PAVGB" 8(%2), %%mm1             \n\t"
-        "add    %4, %1                  \n\t"
-        "add    $16, %2                 \n\t"
-        PAVGB" (%3), %%mm0              \n\t"
-        PAVGB" 8(%3), %%mm1             \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "movq   %%mm1, 8(%3)            \n\t"
-        "add    %5, %3                  \n\t"
-        "decl   %0                      \n\t"
-        "1:                             \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   8(%1), %%mm1            \n\t"
-        "add    %4, %1                  \n\t"
-        PAVGB" (%2), %%mm0              \n\t"
-        PAVGB" 8(%2), %%mm1             \n\t"
-        PAVGB" (%3), %%mm0              \n\t"
-        PAVGB" 8(%3), %%mm1             \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "movq   %%mm1, 8(%3)            \n\t"
-        "add    %5, %3                  \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   8(%1), %%mm1            \n\t"
-        "add    %4, %1                  \n\t"
-        PAVGB" 16(%2), %%mm0            \n\t"
-        PAVGB" 24(%2), %%mm1            \n\t"
-        PAVGB" (%3), %%mm0              \n\t"
-        PAVGB" 8(%3), %%mm1             \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "movq   %%mm1, 8(%3)            \n\t"
-        "add    %5, %3                  \n\t"
-        "add    $32, %2                 \n\t"
-        "subl   $2, %0                  \n\t"
-        "jnz    1b                      \n\t"
-#if !HAVE_EBX_AVAILABLE  //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
-        :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#else
-        :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#endif
-        :"S"((x86_reg)src1Stride), "D"((x86_reg)dstStride)
-        :"memory");
-//the following should be used, though better not with gcc ...
-/*        :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
-        :"r"(src1Stride), "r"(dstStride)
-        :"memory");*/
-}
-
-static void DEF(put_no_rnd_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
-{
-    __asm__ volatile(
-        "pcmpeqb %%mm6, %%mm6           \n\t"
-        "testl $1, %0                   \n\t"
-            " jz 1f                     \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   8(%1), %%mm1            \n\t"
-        "movq   (%2), %%mm2             \n\t"
-        "movq   8(%2), %%mm3            \n\t"
-        "pxor %%mm6, %%mm0              \n\t"
-        "pxor %%mm6, %%mm1              \n\t"
-        "pxor %%mm6, %%mm2              \n\t"
-        "pxor %%mm6, %%mm3              \n\t"
-        PAVGB" %%mm2, %%mm0             \n\t"
-        PAVGB" %%mm3, %%mm1             \n\t"
-        "pxor %%mm6, %%mm0              \n\t"
-        "pxor %%mm6, %%mm1              \n\t"
-        "add    %4, %1                  \n\t"
-        "add    $16, %2                 \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "movq   %%mm1, 8(%3)            \n\t"
-        "add    %5, %3                  \n\t"
-        "decl   %0                      \n\t"
-        "1:                             \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   8(%1), %%mm1            \n\t"
-        "add    %4, %1                  \n\t"
-        "movq   (%2), %%mm2             \n\t"
-        "movq   8(%2), %%mm3            \n\t"
-        "pxor %%mm6, %%mm0              \n\t"
-        "pxor %%mm6, %%mm1              \n\t"
-        "pxor %%mm6, %%mm2              \n\t"
-        "pxor %%mm6, %%mm3              \n\t"
-        PAVGB" %%mm2, %%mm0             \n\t"
-        PAVGB" %%mm3, %%mm1             \n\t"
-        "pxor %%mm6, %%mm0              \n\t"
-        "pxor %%mm6, %%mm1              \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "movq   %%mm1, 8(%3)            \n\t"
-        "add    %5, %3                  \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   8(%1), %%mm1            \n\t"
-        "add    %4, %1                  \n\t"
-        "movq   16(%2), %%mm2           \n\t"
-        "movq   24(%2), %%mm3           \n\t"
-        "pxor %%mm6, %%mm0              \n\t"
-        "pxor %%mm6, %%mm1              \n\t"
-        "pxor %%mm6, %%mm2              \n\t"
-        "pxor %%mm6, %%mm3              \n\t"
-        PAVGB" %%mm2, %%mm0             \n\t"
-        PAVGB" %%mm3, %%mm1             \n\t"
-        "pxor %%mm6, %%mm0              \n\t"
-        "pxor %%mm6, %%mm1              \n\t"
-        "movq   %%mm0, (%3)             \n\t"
-        "movq   %%mm1, 8(%3)            \n\t"
-        "add    %5, %3                  \n\t"
-        "add    $32, %2                 \n\t"
-        "subl   $2, %0                  \n\t"
-        "jnz    1b                      \n\t"
-#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
-        :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#else
-        :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#endif
-        :"S"((x86_reg)src1Stride), "D"((x86_reg)dstStride)
-        :"memory");
-//the following should be used, though better not with gcc ...
-/*        :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
-        :"r"(src1Stride), "r"(dstStride)
-        :"memory");*/
-}
-#endif /* SKIP_FOR_3DNOW */
-
-/* GL: this function does incorrect rounding if overflow */
-static void DEF(put_no_rnd_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
-    MOVQ_BONE(mm6);
-    __asm__ volatile(
-        "lea (%3, %3), %%"REG_a"        \n\t"
-        "1:                             \n\t"
-        "movq (%1), %%mm0               \n\t"
-        "movq (%1, %3), %%mm2           \n\t"
-        "movq 1(%1), %%mm1              \n\t"
-        "movq 1(%1, %3), %%mm3          \n\t"
-        "add %%"REG_a", %1              \n\t"
-        "psubusb %%mm6, %%mm0           \n\t"
-        "psubusb %%mm6, %%mm2           \n\t"
-        PAVGB" %%mm1, %%mm0             \n\t"
-        PAVGB" %%mm3, %%mm2             \n\t"
-        "movq %%mm0, (%2)               \n\t"
-        "movq %%mm2, (%2, %3)           \n\t"
-        "movq (%1), %%mm0               \n\t"
-        "movq 1(%1), %%mm1              \n\t"
-        "movq (%1, %3), %%mm2           \n\t"
-        "movq 1(%1, %3), %%mm3          \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "add %%"REG_a", %1              \n\t"
-        "psubusb %%mm6, %%mm0           \n\t"
-        "psubusb %%mm6, %%mm2           \n\t"
-        PAVGB" %%mm1, %%mm0             \n\t"
-        PAVGB" %%mm3, %%mm2             \n\t"
-        "movq %%mm0, (%2)               \n\t"
-        "movq %%mm2, (%2, %3)           \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "subl $4, %0                    \n\t"
-        "jnz 1b                         \n\t"
-        :"+g"(h), "+S"(pixels), "+D"(block)
-        :"r" ((x86_reg)line_size)
-        :"%"REG_a, "memory");
-}
-
-static void DEF(put_no_rnd_pixels8_x2_exact)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
-    __asm__ volatile (
-        "pcmpeqb %%mm6, %%mm6           \n\t"
-        "1:                             \n\t"
-        "movq  (%1),     %%mm0          \n\t"
-        "movq  (%1, %3), %%mm2          \n\t"
-        "movq 1(%1),     %%mm1          \n\t"
-        "movq 1(%1, %3), %%mm3          \n\t"
-        "pxor  %%mm6, %%mm0             \n\t"
-        "pxor  %%mm6, %%mm2             \n\t"
-        "pxor  %%mm6, %%mm1             \n\t"
-        "pxor  %%mm6, %%mm3             \n\t"
-        PAVGB" %%mm1, %%mm0             \n\t"
-        PAVGB" %%mm3, %%mm2             \n\t"
-        "pxor  %%mm6, %%mm0             \n\t"
-        "pxor  %%mm6, %%mm2             \n\t"
-        "movq  %%mm0, (%2)              \n\t"
-        "movq  %%mm2, (%2, %3)          \n\t"
-        "movq  (%1, %3,2), %%mm0        \n\t"
-        "movq 1(%1, %3,2), %%mm1        \n\t"
-        "movq  (%1, %4),   %%mm2        \n\t"
-        "movq 1(%1, %4),   %%mm3        \n\t"
-        "pxor  %%mm6, %%mm0             \n\t"
-        "pxor  %%mm6, %%mm1             \n\t"
-        "pxor  %%mm6, %%mm2             \n\t"
-        "pxor  %%mm6, %%mm3             \n\t"
-        PAVGB" %%mm1, %%mm0             \n\t"
-        PAVGB" %%mm3, %%mm2             \n\t"
-        "pxor  %%mm6, %%mm0             \n\t"
-        "pxor  %%mm6, %%mm2             \n\t"
-        "movq  %%mm0, (%2, %3,2)        \n\t"
-        "movq  %%mm2, (%2, %4)          \n\t"
-        "lea   (%1, %3,4), %1           \n\t"
-        "lea   (%2, %3,4), %2           \n\t"
-        "subl  $4, %0                   \n\t"
-        "jg 1b                          \n\t"
-        : "+g"(h), "+r"(pixels), "+r"(block)
-        : "r" ((x86_reg)line_size), "r"((x86_reg)3*line_size)
-        : "memory"
-    );
-}
-
-static void DEF(put_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+//FIXME the following could be optimized too ...
+static void DEF(ff_put_no_rnd_pixels16_x2)(uint8_t *block,
+                                           const uint8_t *pixels,
+                                           ptrdiff_t line_size, int h)
 {
-    __asm__ volatile(
-        "lea (%3, %3), %%"REG_a"        \n\t"
-        "movq (%1), %%mm0               \n\t"
-        "sub %3, %2                     \n\t"
-        "1:                             \n\t"
-        "movq (%1, %3), %%mm1           \n\t"
-        "movq (%1, %%"REG_a"), %%mm2    \n\t"
-        "add %%"REG_a", %1              \n\t"
-        PAVGB" %%mm1, %%mm0             \n\t"
-        PAVGB" %%mm2, %%mm1             \n\t"
-        "movq %%mm0, (%2, %3)           \n\t"
-        "movq %%mm1, (%2, %%"REG_a")    \n\t"
-        "movq (%1, %3), %%mm1           \n\t"
-        "movq (%1, %%"REG_a"), %%mm0    \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "add %%"REG_a", %1              \n\t"
-        PAVGB" %%mm1, %%mm2             \n\t"
-        PAVGB" %%mm0, %%mm1             \n\t"
-        "movq %%mm2, (%2, %3)           \n\t"
-        "movq %%mm1, (%2, %%"REG_a")    \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "subl $4, %0                    \n\t"
-        "jnz 1b                         \n\t"
-        :"+g"(h), "+S"(pixels), "+D" (block)
-        :"r" ((x86_reg)line_size)
-        :"%"REG_a, "memory");
+    DEF(ff_put_no_rnd_pixels8_x2)(block,     pixels,     line_size, h);
+    DEF(ff_put_no_rnd_pixels8_x2)(block + 8, pixels + 8, line_size, h);
 }
 
-/* GL: this function does incorrect rounding if overflow */
-static void DEF(put_no_rnd_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(ff_put_pixels16_y2)(uint8_t *block, const uint8_t *pixels,
+                                    ptrdiff_t line_size, int h)
 {
-    MOVQ_BONE(mm6);
-    __asm__ volatile(
-        "lea (%3, %3), %%"REG_a"        \n\t"
-        "movq (%1), %%mm0               \n\t"
-        "sub %3, %2                     \n\t"
-        "1:                             \n\t"
-        "movq (%1, %3), %%mm1           \n\t"
-        "movq (%1, %%"REG_a"), %%mm2    \n\t"
-        "add %%"REG_a", %1              \n\t"
-        "psubusb %%mm6, %%mm1           \n\t"
-        PAVGB" %%mm1, %%mm0             \n\t"
-        PAVGB" %%mm2, %%mm1             \n\t"
-        "movq %%mm0, (%2, %3)           \n\t"
-        "movq %%mm1, (%2, %%"REG_a")    \n\t"
-        "movq (%1, %3), %%mm1           \n\t"
-        "movq (%1, %%"REG_a"), %%mm0    \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "add %%"REG_a", %1              \n\t"
-        "psubusb %%mm6, %%mm1           \n\t"
-        PAVGB" %%mm1, %%mm2             \n\t"
-        PAVGB" %%mm0, %%mm1             \n\t"
-        "movq %%mm2, (%2, %3)           \n\t"
-        "movq %%mm1, (%2, %%"REG_a")    \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "subl $4, %0                    \n\t"
-        "jnz 1b                         \n\t"
-        :"+g"(h), "+S"(pixels), "+D" (block)
-        :"r" ((x86_reg)line_size)
-        :"%"REG_a, "memory");
+    DEF(ff_put_pixels8_y2)(block,     pixels,     line_size, h);
+    DEF(ff_put_pixels8_y2)(block + 8, pixels + 8, line_size, h);
 }
 
-static void DEF(put_no_rnd_pixels8_y2_exact)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(ff_put_no_rnd_pixels16_y2)(uint8_t *block,
+                                           const uint8_t *pixels,
+                                           ptrdiff_t line_size, int h)
 {
-    __asm__ volatile (
-        "movq     (%1), %%mm0           \n\t"
-        "pcmpeqb %%mm6, %%mm6           \n\t"
-        "add        %3, %1              \n\t"
-        "pxor    %%mm6, %%mm0           \n\t"
-        "1:                             \n\t"
-        "movq  (%1),     %%mm1          \n\t"
-        "movq  (%1, %3), %%mm2          \n\t"
-        "pxor  %%mm6, %%mm1             \n\t"
-        "pxor  %%mm6, %%mm2             \n\t"
-        PAVGB" %%mm1, %%mm0             \n\t"
-        PAVGB" %%mm2, %%mm1             \n\t"
-        "pxor  %%mm6, %%mm0             \n\t"
-        "pxor  %%mm6, %%mm1             \n\t"
-        "movq  %%mm0, (%2)              \n\t"
-        "movq  %%mm1, (%2, %3)          \n\t"
-        "movq  (%1, %3,2), %%mm1        \n\t"
-        "movq  (%1, %4),   %%mm0        \n\t"
-        "pxor  %%mm6, %%mm1             \n\t"
-        "pxor  %%mm6, %%mm0             \n\t"
-        PAVGB" %%mm1, %%mm2             \n\t"
-        PAVGB" %%mm0, %%mm1             \n\t"
-        "pxor  %%mm6, %%mm2             \n\t"
-        "pxor  %%mm6, %%mm1             \n\t"
-        "movq %%mm2, (%2, %3,2)         \n\t"
-        "movq %%mm1, (%2, %4)           \n\t"
-        "lea   (%1, %3,4), %1           \n\t"
-        "lea   (%2, %3,4), %2           \n\t"
-        "subl $4, %0                    \n\t"
-        "jg 1b                          \n\t"
-        :"+g"(h), "+r"(pixels), "+r" (block)
-        :"r" ((x86_reg)line_size), "r"((x86_reg)3*line_size)
-        :"memory"
-    );
+    DEF(ff_put_no_rnd_pixels8_y2)(block,     pixels,     line_size, h);
+    DEF(ff_put_no_rnd_pixels8_y2)(block + 8, pixels + 8, line_size, h);
 }
 
-static void DEF(avg_pixels8)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(ff_avg_pixels16)(uint8_t *block, const uint8_t *pixels,
+                                 ptrdiff_t line_size, int h)
 {
-    __asm__ volatile(
-        "lea (%3, %3), %%"REG_a"        \n\t"
-        "1:                             \n\t"
-        "movq (%2), %%mm0               \n\t"
-        "movq (%2, %3), %%mm1           \n\t"
-        PAVGB" (%1), %%mm0              \n\t"
-        PAVGB" (%1, %3), %%mm1          \n\t"
-        "movq %%mm0, (%2)               \n\t"
-        "movq %%mm1, (%2, %3)           \n\t"
-        "add %%"REG_a", %1              \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "movq (%2), %%mm0               \n\t"
-        "movq (%2, %3), %%mm1           \n\t"
-        PAVGB" (%1), %%mm0              \n\t"
-        PAVGB" (%1, %3), %%mm1          \n\t"
-        "add %%"REG_a", %1              \n\t"
-        "movq %%mm0, (%2)               \n\t"
-        "movq %%mm1, (%2, %3)           \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "subl $4, %0                    \n\t"
-        "jnz 1b                         \n\t"
-        :"+g"(h), "+S"(pixels), "+D"(block)
-        :"r" ((x86_reg)line_size)
-        :"%"REG_a, "memory");
+    DEF(ff_avg_pixels8)(block,     pixels,     line_size, h);
+    DEF(ff_avg_pixels8)(block + 8, pixels + 8, line_size, h);
 }
 
-static void DEF(avg_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(ff_avg_pixels16_x2)(uint8_t *block, const uint8_t *pixels,
+                                    ptrdiff_t line_size, int h)
 {
-    __asm__ volatile(
-        "lea (%3, %3), %%"REG_a"        \n\t"
-        "1:                             \n\t"
-        "movq (%1), %%mm0               \n\t"
-        "movq (%1, %3), %%mm2           \n\t"
-        PAVGB" 1(%1), %%mm0             \n\t"
-        PAVGB" 1(%1, %3), %%mm2         \n\t"
-        PAVGB" (%2), %%mm0              \n\t"
-        PAVGB" (%2, %3), %%mm2          \n\t"
-        "add %%"REG_a", %1              \n\t"
-        "movq %%mm0, (%2)               \n\t"
-        "movq %%mm2, (%2, %3)           \n\t"
-        "movq (%1), %%mm0               \n\t"
-        "movq (%1, %3), %%mm2           \n\t"
-        PAVGB" 1(%1), %%mm0             \n\t"
-        PAVGB" 1(%1, %3), %%mm2         \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "add %%"REG_a", %1              \n\t"
-        PAVGB" (%2), %%mm0              \n\t"
-        PAVGB" (%2, %3), %%mm2          \n\t"
-        "movq %%mm0, (%2)               \n\t"
-        "movq %%mm2, (%2, %3)           \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "subl $4, %0                    \n\t"
-        "jnz 1b                         \n\t"
-        :"+g"(h), "+S"(pixels), "+D"(block)
-        :"r" ((x86_reg)line_size)
-        :"%"REG_a, "memory");
+    DEF(ff_avg_pixels8_x2)(block,     pixels,     line_size, h);
+    DEF(ff_avg_pixels8_x2)(block + 8, pixels + 8, line_size, h);
 }
 
-static void DEF(avg_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(ff_avg_pixels16_y2)(uint8_t *block, const uint8_t *pixels,
+                                    ptrdiff_t line_size, int h)
 {
-    __asm__ volatile(
-        "lea (%3, %3), %%"REG_a"        \n\t"
-        "movq (%1), %%mm0               \n\t"
-        "sub %3, %2                     \n\t"
-        "1:                             \n\t"
-        "movq (%1, %3), %%mm1           \n\t"
-        "movq (%1, %%"REG_a"), %%mm2    \n\t"
-        "add %%"REG_a", %1              \n\t"
-        PAVGB" %%mm1, %%mm0             \n\t"
-        PAVGB" %%mm2, %%mm1             \n\t"
-        "movq (%2, %3), %%mm3           \n\t"
-        "movq (%2, %%"REG_a"), %%mm4    \n\t"
-        PAVGB" %%mm3, %%mm0             \n\t"
-        PAVGB" %%mm4, %%mm1             \n\t"
-        "movq %%mm0, (%2, %3)           \n\t"
-        "movq %%mm1, (%2, %%"REG_a")    \n\t"
-        "movq (%1, %3), %%mm1           \n\t"
-        "movq (%1, %%"REG_a"), %%mm0    \n\t"
-        PAVGB" %%mm1, %%mm2             \n\t"
-        PAVGB" %%mm0, %%mm1             \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "add %%"REG_a", %1              \n\t"
-        "movq (%2, %3), %%mm3           \n\t"
-        "movq (%2, %%"REG_a"), %%mm4    \n\t"
-        PAVGB" %%mm3, %%mm2             \n\t"
-        PAVGB" %%mm4, %%mm1             \n\t"
-        "movq %%mm2, (%2, %3)           \n\t"
-        "movq %%mm1, (%2, %%"REG_a")    \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "subl $4, %0                    \n\t"
-        "jnz 1b                         \n\t"
-        :"+g"(h), "+S"(pixels), "+D"(block)
-        :"r" ((x86_reg)line_size)
-        :"%"REG_a, "memory");
+    DEF(ff_avg_pixels8_y2)(block,     pixels,     line_size, h);
+    DEF(ff_avg_pixels8_y2)(block + 8, pixels + 8, line_size, h);
 }
 
-/* Note this is not correctly rounded, but this function is only
- * used for B-frames so it does not matter. */
-static void DEF(avg_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(ff_avg_pixels16_xy2)(uint8_t *block, const uint8_t *pixels,
+                                     ptrdiff_t line_size, int h)
 {
-    MOVQ_BONE(mm6);
-    __asm__ volatile(
-        "lea (%3, %3), %%"REG_a"        \n\t"
-        "movq (%1), %%mm0               \n\t"
-        PAVGB" 1(%1), %%mm0             \n\t"
-         ".p2align 3                    \n\t"
-        "1:                             \n\t"
-        "movq (%1, %%"REG_a"), %%mm2    \n\t"
-        "movq (%1, %3), %%mm1           \n\t"
-        "psubusb %%mm6, %%mm2           \n\t"
-        PAVGB" 1(%1, %3), %%mm1         \n\t"
-        PAVGB" 1(%1, %%"REG_a"), %%mm2  \n\t"
-        "add %%"REG_a", %1              \n\t"
-        PAVGB" %%mm1, %%mm0             \n\t"
-        PAVGB" %%mm2, %%mm1             \n\t"
-        PAVGB" (%2), %%mm0              \n\t"
-        PAVGB" (%2, %3), %%mm1          \n\t"
-        "movq %%mm0, (%2)               \n\t"
-        "movq %%mm1, (%2, %3)           \n\t"
-        "movq (%1, %3), %%mm1           \n\t"
-        "movq (%1, %%"REG_a"), %%mm0    \n\t"
-        PAVGB" 1(%1, %3), %%mm1         \n\t"
-        PAVGB" 1(%1, %%"REG_a"), %%mm0  \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "add %%"REG_a", %1              \n\t"
-        PAVGB" %%mm1, %%mm2             \n\t"
-        PAVGB" %%mm0, %%mm1             \n\t"
-        PAVGB" (%2), %%mm2              \n\t"
-        PAVGB" (%2, %3), %%mm1          \n\t"
-        "movq %%mm2, (%2)               \n\t"
-        "movq %%mm1, (%2, %3)           \n\t"
-        "add %%"REG_a", %2              \n\t"
-        "subl $4, %0                    \n\t"
-        "jnz 1b                         \n\t"
-        :"+g"(h), "+S"(pixels), "+D"(block)
-        :"r" ((x86_reg)line_size)
-        :"%"REG_a,  "memory");
-}
-
-//FIXME the following could be optimized too ...
-static void DEF(put_no_rnd_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
-    DEF(put_no_rnd_pixels8_x2)(block  , pixels  , line_size, h);
-    DEF(put_no_rnd_pixels8_x2)(block+8, pixels+8, line_size, h);
-}
-static void DEF(put_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
-    DEF(put_pixels8_y2)(block  , pixels  , line_size, h);
-    DEF(put_pixels8_y2)(block+8, pixels+8, line_size, h);
-}
-static void DEF(put_no_rnd_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
-    DEF(put_no_rnd_pixels8_y2)(block  , pixels  , line_size, h);
-    DEF(put_no_rnd_pixels8_y2)(block+8, pixels+8, line_size, h);
-}
-static void DEF(avg_pixels16)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
-    DEF(avg_pixels8)(block  , pixels  , line_size, h);
-    DEF(avg_pixels8)(block+8, pixels+8, line_size, h);
-}
-static void DEF(avg_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
-    DEF(avg_pixels8_x2)(block  , pixels  , line_size, h);
-    DEF(avg_pixels8_x2)(block+8, pixels+8, line_size, h);
+    DEF(ff_avg_pixels8_xy2)(block,     pixels,     line_size, h);
+    DEF(ff_avg_pixels8_xy2)(block + 8, pixels + 8, line_size, h);
 }
-static void DEF(avg_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
-    DEF(avg_pixels8_y2)(block  , pixels  , line_size, h);
-    DEF(avg_pixels8_y2)(block+8, pixels+8, line_size, h);
-}
-static void DEF(avg_pixels16_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
-    DEF(avg_pixels8_xy2)(block  , pixels  , line_size, h);
-    DEF(avg_pixels8_xy2)(block+8, pixels+8, line_size, h);
-}
-
-#define QPEL_2TAP_L3(OPNAME) \
-static void DEF(OPNAME ## 2tap_qpel16_l3)(uint8_t *dst, uint8_t *src, int stride, int h, int off1, int off2){\
-    __asm__ volatile(\
-        "1:                    \n\t"\
-        "movq   (%1,%2), %%mm0 \n\t"\
-        "movq  8(%1,%2), %%mm1 \n\t"\
-        PAVGB"  (%1,%3), %%mm0 \n\t"\
-        PAVGB" 8(%1,%3), %%mm1 \n\t"\
-        PAVGB"  (%1),    %%mm0 \n\t"\
-        PAVGB" 8(%1),    %%mm1 \n\t"\
-        STORE_OP( (%1,%4),%%mm0)\
-        STORE_OP(8(%1,%4),%%mm1)\
-        "movq  %%mm0,  (%1,%4) \n\t"\
-        "movq  %%mm1, 8(%1,%4) \n\t"\
-        "add   %5, %1          \n\t"\
-        "decl  %0              \n\t"\
-        "jnz   1b              \n\t"\
-        :"+g"(h), "+r"(src)\
-        :"r"((x86_reg)off1), "r"((x86_reg)off2),\
-         "r"((x86_reg)(dst-src)), "r"((x86_reg)stride)\
-        :"memory"\
-    );\
-}\
-static void DEF(OPNAME ## 2tap_qpel8_l3)(uint8_t *dst, uint8_t *src, int stride, int h, int off1, int off2){\
-    __asm__ volatile(\
-        "1:                    \n\t"\
-        "movq   (%1,%2), %%mm0 \n\t"\
-        PAVGB"  (%1,%3), %%mm0 \n\t"\
-        PAVGB"  (%1),    %%mm0 \n\t"\
-        STORE_OP((%1,%4),%%mm0)\
-        "movq  %%mm0,  (%1,%4) \n\t"\
-        "add   %5, %1          \n\t"\
-        "decl  %0              \n\t"\
-        "jnz   1b              \n\t"\
-        :"+g"(h), "+r"(src)\
-        :"r"((x86_reg)off1), "r"((x86_reg)off2),\
-         "r"((x86_reg)(dst-src)), "r"((x86_reg)stride)\
-        :"memory"\
-    );\
-}
-
-#ifndef SKIP_FOR_3DNOW
-#define STORE_OP(a,b) PAVGB" "#a","#b" \n\t"
-QPEL_2TAP_L3(avg_)
-#undef STORE_OP
-#define STORE_OP(a,b)
-QPEL_2TAP_L3(put_)
-#undef STORE_OP
-#undef QPEL_2TAP_L3
-#endif /* SKIP_FOR_3DNOW */
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/dsputil_mmx.c b/mythtv/external/FFmpeg/libavcodec/x86/dsputil_mmx.c
index 738bbd152bb..15e46c7228e 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/dsputil_mmx.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/dsputil_mmx.c
@@ -22,12 +22,14 @@
  * MMX optimization by Nick Kurshev 
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/h264dsp.h"
 #include "libavcodec/mpegvideo.h"
 #include "libavcodec/simple_idct.h"
+#include "libavcodec/videodsp.h"
 #include "dsputil_mmx.h"
 #include "idct_xvid.h"
 #include "diracdsp_mmx.h"
@@ -39,9 +41,6 @@
 DECLARE_ALIGNED(8,  const uint64_t, ff_bone) = 0x0101010101010101ULL;
 DECLARE_ALIGNED(8,  const uint64_t, ff_wtwo) = 0x0002000200020002ULL;
 
-DECLARE_ALIGNED(16, const uint64_t, ff_pdw_80000000)[2] =
-    { 0x8000000080000000ULL, 0x8000000080000000ULL };
-
 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_1)    = { 0x0001000100010001ULL, 0x0001000100010001ULL };
 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_2)    = { 0x0002000200020002ULL, 0x0002000200020002ULL };
 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_3)    = { 0x0003000300030003ULL, 0x0003000300030003ULL };
@@ -84,6 +83,107 @@ DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_FE)   = { 0xFEFEFEFEFEFEFEFEULL, 0xFEF
 DECLARE_ALIGNED(16, const double, ff_pd_1)[2] = { 1.0, 1.0 };
 DECLARE_ALIGNED(16, const double, ff_pd_2)[2] = { 2.0, 2.0 };
 
+
+#if HAVE_YASM
+void ff_put_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
+                              ptrdiff_t line_size, int h);
+void ff_put_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
+                             ptrdiff_t line_size, int h);
+void ff_put_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
+                              int dstStride, int src1Stride, int h);
+void ff_put_no_rnd_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1,
+                                     uint8_t *src2, int dstStride,
+                                     int src1Stride, int h);
+void ff_avg_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
+                              int dstStride, int src1Stride, int h);
+void ff_put_pixels16_x2_mmxext(uint8_t *block, const uint8_t *pixels,
+                               ptrdiff_t line_size, int h);
+void ff_put_pixels16_x2_3dnow(uint8_t *block, const uint8_t *pixels,
+                              ptrdiff_t line_size, int h);
+void ff_put_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
+                               int dstStride, int src1Stride, int h);
+void ff_avg_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
+                               int dstStride, int src1Stride, int h);
+void ff_put_no_rnd_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
+                                      int dstStride, int src1Stride, int h);
+void ff_put_no_rnd_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
+                                     ptrdiff_t line_size, int h);
+void ff_put_no_rnd_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
+                                    ptrdiff_t line_size, int h);
+void ff_put_no_rnd_pixels8_x2_exact_mmxext(uint8_t *block,
+                                           const uint8_t *pixels,
+                                           ptrdiff_t line_size, int h);
+void ff_put_no_rnd_pixels8_x2_exact_3dnow(uint8_t *block,
+                                          const uint8_t *pixels,
+                                          ptrdiff_t line_size, int h);
+void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
+                              ptrdiff_t line_size, int h);
+void ff_put_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
+                             ptrdiff_t line_size, int h);
+void ff_put_no_rnd_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
+                                     ptrdiff_t line_size, int h);
+void ff_put_no_rnd_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
+                                    ptrdiff_t line_size, int h);
+void ff_put_no_rnd_pixels8_y2_exact_mmxext(uint8_t *block,
+                                           const uint8_t *pixels,
+                                           ptrdiff_t line_size, int h);
+void ff_put_no_rnd_pixels8_y2_exact_3dnow(uint8_t *block,
+                                          const uint8_t *pixels,
+                                          ptrdiff_t line_size, int h);
+void ff_avg_pixels8_3dnow(uint8_t *block, const uint8_t *pixels,
+                          ptrdiff_t line_size, int h);
+void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
+                              ptrdiff_t line_size, int h);
+void ff_avg_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
+                             ptrdiff_t line_size, int h);
+void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
+                              ptrdiff_t line_size, int h);
+void ff_avg_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
+                             ptrdiff_t line_size, int h);
+void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels,
+                               ptrdiff_t line_size, int h);
+void ff_avg_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels,
+                              ptrdiff_t line_size, int h);
+
+void ff_put_pixels8_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h);
+static void ff_put_pixels16_mmxext(uint8_t *block, const uint8_t *pixels,
+                                   ptrdiff_t line_size, int h)
+{
+    ff_put_pixels8_mmxext(block,     pixels,     line_size, h);
+    ff_put_pixels8_mmxext(block + 8, pixels + 8, line_size, h);
+}
+
+void ff_put_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
+                                         int dstStride, int srcStride, int h);
+void ff_avg_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
+                                         int dstStride, int srcStride, int h);
+void ff_put_no_rnd_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
+                                                 int dstStride, int srcStride,
+                                                 int h);
+void ff_put_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
+                                        int dstStride, int srcStride, int h);
+void ff_avg_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
+                                        int dstStride, int srcStride, int h);
+void ff_put_no_rnd_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
+                                                int dstStride, int srcStride,
+                                                int h);
+void ff_put_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
+                                         int dstStride, int srcStride);
+void ff_avg_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
+                                         int dstStride, int srcStride);
+void ff_put_no_rnd_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
+                                                 int dstStride, int srcStride);
+void ff_put_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
+                                        int dstStride, int srcStride);
+void ff_avg_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
+                                        int dstStride, int srcStride);
+void ff_put_no_rnd_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
+                                                int dstStride, int srcStride);
+#define ff_put_no_rnd_pixels16_mmxext ff_put_pixels16_mmxext
+#define ff_put_no_rnd_pixels8_mmxext ff_put_pixels8_mmxext
+#endif /* HAVE_YASM */
+
+
 #if HAVE_INLINE_ASM
 
 #define JUMPALIGN()     __asm__ volatile (".p2align 3"::)
@@ -164,6 +264,7 @@ DECLARE_ALIGNED(16, const double, ff_pd_2)[2] = { 2.0, 2.0 };
 
 /***********************************/
 /* MMX no rounding */
+#define NO_RND 1
 #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
 #define SET_RND  MOVQ_WONE
 #define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
@@ -176,6 +277,7 @@ DECLARE_ALIGNED(16, const double, ff_pd_2)[2] = { 2.0, 2.0 };
 #undef SET_RND
 #undef PAVGBP
 #undef PAVGB
+#undef NO_RND
 /***********************************/
 /* MMX rounding */
 
@@ -192,51 +294,43 @@ DECLARE_ALIGNED(16, const double, ff_pd_2)[2] = { 2.0, 2.0 };
 #undef PAVGB
 #undef OP_AVG
 
+#endif /* HAVE_INLINE_ASM */
+
+
+#if HAVE_YASM
+
 /***********************************/
 /* 3Dnow specific */
 
 #define DEF(x) x ## _3dnow
-#define PAVGB "pavgusb"
-#define OP_AVG PAVGB
-#define SKIP_FOR_3DNOW
 
 #include "dsputil_avg_template.c"
 
 #undef DEF
-#undef PAVGB
-#undef OP_AVG
-#undef SKIP_FOR_3DNOW
 
 /***********************************/
 /* MMXEXT specific */
 
 #define DEF(x) x ## _mmxext
 
-/* Introduced only in MMXEXT set */
-#define PAVGB "pavgb"
-#define OP_AVG PAVGB
-
 #include "dsputil_avg_template.c"
 
 #undef DEF
-#undef PAVGB
-#undef OP_AVG
 
+#endif /* HAVE_YASM */
+
+
+#if HAVE_INLINE_ASM
 #define put_no_rnd_pixels16_mmx put_pixels16_mmx
 #define put_no_rnd_pixels8_mmx put_pixels8_mmx
-#define put_pixels16_mmxext put_pixels16_mmx
-#define put_pixels8_mmxext put_pixels8_mmx
-#define put_pixels4_mmxext put_pixels4_mmx
-#define put_no_rnd_pixels16_mmxext put_no_rnd_pixels16_mmx
-#define put_no_rnd_pixels8_mmxext put_no_rnd_pixels8_mmx
 
 /***********************************/
 /* standard MMX */
 
-void ff_put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels,
+void ff_put_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels,
                                int line_size)
 {
-    const DCTELEM *p;
+    const int16_t *p;
     uint8_t *pix;
 
     /* read the pixels */
@@ -308,7 +402,7 @@ void ff_put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels,
     "movq               %%mm3, (%0, %3, 2)  \n\t"           \
     "movq               %%mm4, (%0, %1)     \n\t"
 
-void ff_put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels,
+void ff_put_signed_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels,
                                       int line_size)
 {
     x86_reg line_skip = line_size;
@@ -325,10 +419,10 @@ void ff_put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels,
         : "memory");
 }
 
-void ff_add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels,
+void ff_add_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels,
                                int line_size)
 {
-    const DCTELEM *p;
+    const int16_t *p;
     uint8_t *pix;
     int i;
 
@@ -368,7 +462,7 @@ void ff_add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels,
 }
 
 static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels,
-                            int line_size, int h)
+                            ptrdiff_t line_size, int h)
 {
     __asm__ volatile (
         "lea   (%3, %3), %%"REG_a"      \n\t"
@@ -395,7 +489,7 @@ static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels,
 }
 
 static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels,
-                             int line_size, int h)
+                             ptrdiff_t line_size, int h)
 {
     __asm__ volatile (
         "lea   (%3, %3), %%"REG_a"      \n\t"
@@ -430,7 +524,7 @@ static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels,
 }
 
 #define CLEAR_BLOCKS(name, n)                           \
-static void name(DCTELEM *blocks)                       \
+static void name(int16_t *blocks)                       \
 {                                                       \
     __asm__ volatile (                                  \
         "pxor %%mm7, %%mm7              \n\t"           \
@@ -450,7 +544,7 @@ static void name(DCTELEM *blocks)                       \
 CLEAR_BLOCKS(clear_blocks_mmx, 6)
 CLEAR_BLOCKS(clear_block_mmx, 1)
 
-static void clear_block_sse(DCTELEM *block)
+static void clear_block_sse(int16_t *block)
 {
     __asm__ volatile (
         "xorps  %%xmm0, %%xmm0          \n"
@@ -467,7 +561,7 @@ static void clear_block_sse(DCTELEM *block)
     );
 }
 
-static void clear_blocks_sse(DCTELEM *blocks)
+static void clear_blocks_sse(int16_t *blocks)
 {
     __asm__ volatile (
         "xorps  %%xmm0, %%xmm0              \n"
@@ -551,181 +645,12 @@ static void add_hfyu_median_prediction_cmov(uint8_t *dst, const uint8_t *top,
     *left_top = tl;
 }
 #endif
+#endif /* HAVE_INLINE_ASM */
 
-static inline void transpose4x4(uint8_t *dst, uint8_t *src, x86_reg dst_stride, x86_reg src_stride){
-    __asm__ volatile( //FIXME could save 1 instruction if done as 8x4 ...
-        "movd  (%1), %%mm0              \n\t"
-        "add   %3, %1                   \n\t"
-        "movd  (%1), %%mm1              \n\t"
-        "movd  (%1,%3,1), %%mm2         \n\t"
-        "movd  (%1,%3,2), %%mm3         \n\t"
-        "punpcklbw %%mm1, %%mm0         \n\t"
-        "punpcklbw %%mm3, %%mm2         \n\t"
-        "movq %%mm0, %%mm1              \n\t"
-        "punpcklwd %%mm2, %%mm0         \n\t"
-        "punpckhwd %%mm2, %%mm1         \n\t"
-        "movd  %%mm0, (%0)              \n\t"
-        "add   %2, %0                   \n\t"
-        "punpckhdq %%mm0, %%mm0         \n\t"
-        "movd  %%mm0, (%0)              \n\t"
-        "movd  %%mm1, (%0,%2,1)         \n\t"
-        "punpckhdq %%mm1, %%mm1         \n\t"
-        "movd  %%mm1, (%0,%2,2)         \n\t"
-
-        :  "+&r" (dst),
-           "+&r" (src)
-        :  "r" (dst_stride),
-           "r" (src_stride)
-        :  "memory"
-    );
-}
-
-#define H263_LOOP_FILTER                        \
-    "pxor      %%mm7, %%mm7             \n\t"   \
-    "movq         %0, %%mm0             \n\t"   \
-    "movq         %0, %%mm1             \n\t"   \
-    "movq         %3, %%mm2             \n\t"   \
-    "movq         %3, %%mm3             \n\t"   \
-    "punpcklbw %%mm7, %%mm0             \n\t"   \
-    "punpckhbw %%mm7, %%mm1             \n\t"   \
-    "punpcklbw %%mm7, %%mm2             \n\t"   \
-    "punpckhbw %%mm7, %%mm3             \n\t"   \
-    "psubw     %%mm2, %%mm0             \n\t"   \
-    "psubw     %%mm3, %%mm1             \n\t"   \
-    "movq         %1, %%mm2             \n\t"   \
-    "movq         %1, %%mm3             \n\t"   \
-    "movq         %2, %%mm4             \n\t"   \
-    "movq         %2, %%mm5             \n\t"   \
-    "punpcklbw %%mm7, %%mm2             \n\t"   \
-    "punpckhbw %%mm7, %%mm3             \n\t"   \
-    "punpcklbw %%mm7, %%mm4             \n\t"   \
-    "punpckhbw %%mm7, %%mm5             \n\t"   \
-    "psubw     %%mm2, %%mm4             \n\t"   \
-    "psubw     %%mm3, %%mm5             \n\t"   \
-    "psllw        $2, %%mm4             \n\t"   \
-    "psllw        $2, %%mm5             \n\t"   \
-    "paddw     %%mm0, %%mm4             \n\t"   \
-    "paddw     %%mm1, %%mm5             \n\t"   \
-    "pxor      %%mm6, %%mm6             \n\t"   \
-    "pcmpgtw   %%mm4, %%mm6             \n\t"   \
-    "pcmpgtw   %%mm5, %%mm7             \n\t"   \
-    "pxor      %%mm6, %%mm4             \n\t"   \
-    "pxor      %%mm7, %%mm5             \n\t"   \
-    "psubw     %%mm6, %%mm4             \n\t"   \
-    "psubw     %%mm7, %%mm5             \n\t"   \
-    "psrlw        $3, %%mm4             \n\t"   \
-    "psrlw        $3, %%mm5             \n\t"   \
-    "packuswb  %%mm5, %%mm4             \n\t"   \
-    "packsswb  %%mm7, %%mm6             \n\t"   \
-    "pxor      %%mm7, %%mm7             \n\t"   \
-    "movd         %4, %%mm2             \n\t"   \
-    "punpcklbw %%mm2, %%mm2             \n\t"   \
-    "punpcklbw %%mm2, %%mm2             \n\t"   \
-    "punpcklbw %%mm2, %%mm2             \n\t"   \
-    "psubusb   %%mm4, %%mm2             \n\t"   \
-    "movq      %%mm2, %%mm3             \n\t"   \
-    "psubusb   %%mm4, %%mm3             \n\t"   \
-    "psubb     %%mm3, %%mm2             \n\t"   \
-    "movq         %1, %%mm3             \n\t"   \
-    "movq         %2, %%mm4             \n\t"   \
-    "pxor      %%mm6, %%mm3             \n\t"   \
-    "pxor      %%mm6, %%mm4             \n\t"   \
-    "paddusb   %%mm2, %%mm3             \n\t"   \
-    "psubusb   %%mm2, %%mm4             \n\t"   \
-    "pxor      %%mm6, %%mm3             \n\t"   \
-    "pxor      %%mm6, %%mm4             \n\t"   \
-    "paddusb   %%mm2, %%mm2             \n\t"   \
-    "packsswb  %%mm1, %%mm0             \n\t"   \
-    "pcmpgtb   %%mm0, %%mm7             \n\t"   \
-    "pxor      %%mm7, %%mm0             \n\t"   \
-    "psubb     %%mm7, %%mm0             \n\t"   \
-    "movq      %%mm0, %%mm1             \n\t"   \
-    "psubusb   %%mm2, %%mm0             \n\t"   \
-    "psubb     %%mm0, %%mm1             \n\t"   \
-    "pand         %5, %%mm1             \n\t"   \
-    "psrlw        $2, %%mm1             \n\t"   \
-    "pxor      %%mm7, %%mm1             \n\t"   \
-    "psubb     %%mm7, %%mm1             \n\t"   \
-    "movq         %0, %%mm5             \n\t"   \
-    "movq         %3, %%mm6             \n\t"   \
-    "psubb     %%mm1, %%mm5             \n\t"   \
-    "paddb     %%mm1, %%mm6             \n\t"
-
-static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale)
-{
-    if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
-        const int strength = ff_h263_loop_filter_strength[qscale];
-
-        __asm__ volatile (
-            H263_LOOP_FILTER
-
-            "movq %%mm3, %1             \n\t"
-            "movq %%mm4, %2             \n\t"
-            "movq %%mm5, %0             \n\t"
-            "movq %%mm6, %3             \n\t"
-            : "+m"(*(uint64_t*)(src - 2 * stride)),
-              "+m"(*(uint64_t*)(src - 1 * stride)),
-              "+m"(*(uint64_t*)(src + 0 * stride)),
-              "+m"(*(uint64_t*)(src + 1 * stride))
-            : "g"(2 * strength), "m"(ff_pb_FC)
-            );
-    }
-}
-
-static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale)
-{
-    if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
-        const int strength = ff_h263_loop_filter_strength[qscale];
-        DECLARE_ALIGNED(8, uint64_t, temp)[4];
-        uint8_t *btemp = (uint8_t*)temp;
-
-        src -= 2;
-
-        transpose4x4(btemp,     src,              8, stride);
-        transpose4x4(btemp + 4, src + 4 * stride, 8, stride);
-        __asm__ volatile (
-            H263_LOOP_FILTER // 5 3 4 6
-
-            : "+m"(temp[0]),
-              "+m"(temp[1]),
-              "+m"(temp[2]),
-              "+m"(temp[3])
-            : "g"(2 * strength), "m"(ff_pb_FC)
-            );
-
-        __asm__ volatile (
-            "movq      %%mm5, %%mm1         \n\t"
-            "movq      %%mm4, %%mm0         \n\t"
-            "punpcklbw %%mm3, %%mm5         \n\t"
-            "punpcklbw %%mm6, %%mm4         \n\t"
-            "punpckhbw %%mm3, %%mm1         \n\t"
-            "punpckhbw %%mm6, %%mm0         \n\t"
-            "movq      %%mm5, %%mm3         \n\t"
-            "movq      %%mm1, %%mm6         \n\t"
-            "punpcklwd %%mm4, %%mm5         \n\t"
-            "punpcklwd %%mm0, %%mm1         \n\t"
-            "punpckhwd %%mm4, %%mm3         \n\t"
-            "punpckhwd %%mm0, %%mm6         \n\t"
-            "movd      %%mm5, (%0)          \n\t"
-            "punpckhdq %%mm5, %%mm5         \n\t"
-            "movd      %%mm5, (%0, %2)      \n\t"
-            "movd      %%mm3, (%0, %2, 2)   \n\t"
-            "punpckhdq %%mm3, %%mm3         \n\t"
-            "movd      %%mm3, (%0, %3)      \n\t"
-            "movd      %%mm1, (%1)          \n\t"
-            "punpckhdq %%mm1, %%mm1         \n\t"
-            "movd      %%mm1, (%1, %2)      \n\t"
-            "movd      %%mm6, (%1, %2, 2)   \n\t"
-            "punpckhdq %%mm6, %%mm6         \n\t"
-            "movd      %%mm6, (%1, %3)      \n\t"
-            :: "r"(src),
-               "r"(src + 4 * stride),
-               "r"((x86_reg)stride),
-               "r"((x86_reg)(3 * stride))
-            );
-    }
-}
+void ff_h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale);
+void ff_h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale);
 
+#if HAVE_INLINE_ASM
 /* Draw the edges of width 'w' of an image of size width, height
  * this MMX version can only handle w == 8 || w == 16. */
 static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
@@ -840,382 +765,15 @@ static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
         }
     }
 }
+#endif /* HAVE_INLINE_ASM */
 
-#define QPEL_V_LOW(m3, m4, m5, m6, pw_20, pw_3, rnd,                      \
-                   in0, in1, in2, in7, out, OP)                           \
-    "paddw               "#m4", "#m3"   \n\t" /* x1 */                    \
-    "movq   "MANGLE(ff_pw_20)", %%mm4   \n\t" /* 20 */                    \
-    "pmullw              "#m3", %%mm4   \n\t" /* 20x1 */                  \
-    "movq               "#in7", "#m3"   \n\t" /* d */                     \
-    "movq               "#in0", %%mm5   \n\t" /* D */                     \
-    "paddw               "#m3", %%mm5   \n\t" /* x4 */                    \
-    "psubw               %%mm5, %%mm4   \n\t" /* 20x1 - x4 */             \
-    "movq               "#in1", %%mm5   \n\t" /* C */                     \
-    "movq               "#in2", %%mm6   \n\t" /* B */                     \
-    "paddw               "#m6", %%mm5   \n\t" /* x3 */                    \
-    "paddw               "#m5", %%mm6   \n\t" /* x2 */                    \
-    "paddw               %%mm6, %%mm6   \n\t" /* 2x2 */                   \
-    "psubw               %%mm6, %%mm5   \n\t" /* -2x2 + x3 */             \
-    "pmullw  "MANGLE(ff_pw_3)", %%mm5   \n\t" /* -6x2 + 3x3 */            \
-    "paddw              "#rnd", %%mm4   \n\t" /* x2 */                    \
-    "paddw               %%mm4, %%mm5   \n\t" /* 20x1 - 6x2 + 3x3 - x4 */ \
-    "psraw                  $5, %%mm5   \n\t"                             \
-    "packuswb            %%mm5, %%mm5   \n\t"                             \
-    OP(%%mm5, out, %%mm7, d)
-
-#define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMXEXT)                        \
-static void OPNAME ## mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst,         \
-                                                    uint8_t *src,         \
-                                                    int dstStride,        \
-                                                    int srcStride,        \
-                                                    int h)                \
-{                                                                         \
-    uint64_t temp;                                                        \
-                                                                          \
-    __asm__ volatile (                                                    \
-        "pxor      %%mm7, %%mm7             \n\t"                         \
-        "1:                                 \n\t"                         \
-        "movq       (%0), %%mm0             \n\t" /* ABCDEFGH */          \
-        "movq      %%mm0, %%mm1             \n\t" /* ABCDEFGH */          \
-        "movq      %%mm0, %%mm2             \n\t" /* ABCDEFGH */          \
-        "punpcklbw %%mm7, %%mm0             \n\t" /* 0A0B0C0D */          \
-        "punpckhbw %%mm7, %%mm1             \n\t" /* 0E0F0G0H */          \
-        "pshufw    $0x90, %%mm0, %%mm5      \n\t" /* 0A0A0B0C */          \
-        "pshufw    $0x41, %%mm0, %%mm6      \n\t" /* 0B0A0A0B */          \
-        "movq      %%mm2, %%mm3             \n\t" /* ABCDEFGH */          \
-        "movq      %%mm2, %%mm4             \n\t" /* ABCDEFGH */          \
-        "psllq        $8, %%mm2             \n\t" /* 0ABCDEFG */          \
-        "psllq       $16, %%mm3             \n\t" /* 00ABCDEF */          \
-        "psllq       $24, %%mm4             \n\t" /* 000ABCDE */          \
-        "punpckhbw %%mm7, %%mm2             \n\t" /* 0D0E0F0G */          \
-        "punpckhbw %%mm7, %%mm3             \n\t" /* 0C0D0E0F */          \
-        "punpckhbw %%mm7, %%mm4             \n\t" /* 0B0C0D0E */          \
-        "paddw     %%mm3, %%mm5             \n\t" /* b */                 \
-        "paddw     %%mm2, %%mm6             \n\t" /* c */                 \
-        "paddw     %%mm5, %%mm5             \n\t" /* 2b */                \
-        "psubw     %%mm5, %%mm6             \n\t" /* c - 2b */            \
-        "pshufw    $0x06, %%mm0, %%mm5      \n\t" /* 0C0B0A0A */          \
-        "pmullw "MANGLE(ff_pw_3)", %%mm6    \n\t" /* 3c - 6b */           \
-        "paddw     %%mm4, %%mm0             \n\t" /* a */                 \
-        "paddw     %%mm1, %%mm5             \n\t" /* d */                 \
-        "pmullw "MANGLE(ff_pw_20)", %%mm0   \n\t" /* 20a */               \
-        "psubw     %%mm5, %%mm0             \n\t" /* 20a - d */           \
-        "paddw        %6, %%mm6             \n\t"                         \
-        "paddw     %%mm6, %%mm0             \n\t" /* 20a - 6b + 3c - d */ \
-        "psraw        $5, %%mm0             \n\t"                         \
-        "movq      %%mm0, %5                \n\t"                         \
-        /* mm1 = EFGH, mm2 = DEFG, mm3 = CDEF, mm4 = BCDE, mm7 = 0 */     \
-                                                                          \
-        "movq      5(%0), %%mm0             \n\t" /* FGHIJKLM */          \
-        "movq      %%mm0, %%mm5             \n\t" /* FGHIJKLM */          \
-        "movq      %%mm0, %%mm6             \n\t" /* FGHIJKLM */          \
-        "psrlq        $8, %%mm0             \n\t" /* GHIJKLM0 */          \
-        "psrlq       $16, %%mm5             \n\t" /* HIJKLM00 */          \
-        "punpcklbw %%mm7, %%mm0             \n\t" /* 0G0H0I0J */          \
-        "punpcklbw %%mm7, %%mm5             \n\t" /* 0H0I0J0K */          \
-        "paddw     %%mm0, %%mm2             \n\t" /* b */                 \
-        "paddw     %%mm5, %%mm3             \n\t" /* c */                 \
-        "paddw     %%mm2, %%mm2             \n\t" /* 2b */                \
-        "psubw     %%mm2, %%mm3             \n\t" /* c - 2b */            \
-        "movq      %%mm6, %%mm2             \n\t" /* FGHIJKLM */          \
-        "psrlq       $24, %%mm6             \n\t" /* IJKLM000 */          \
-        "punpcklbw %%mm7, %%mm2             \n\t" /* 0F0G0H0I */          \
-        "punpcklbw %%mm7, %%mm6             \n\t" /* 0I0J0K0L */          \
-        "pmullw "MANGLE(ff_pw_3)", %%mm3    \n\t" /* 3c - 6b */           \
-        "paddw     %%mm2, %%mm1             \n\t" /* a */                 \
-        "paddw     %%mm6, %%mm4             \n\t" /* d */                 \
-        "pmullw "MANGLE(ff_pw_20)", %%mm1   \n\t" /* 20a */               \
-        "psubw     %%mm4, %%mm3             \n\t" /* - 6b +3c - d */      \
-        "paddw        %6, %%mm1             \n\t"                         \
-        "paddw     %%mm1, %%mm3             \n\t" /* 20a - 6b +3c - d */  \
-        "psraw        $5, %%mm3             \n\t"                         \
-        "movq         %5, %%mm1             \n\t"                         \
-        "packuswb  %%mm3, %%mm1             \n\t"                         \
-        OP_MMXEXT(%%mm1, (%1), %%mm4, q)                                  \
-        /* mm0 = GHIJ, mm2 = FGHI, mm5 = HIJK, mm6 = IJKL, mm7 = 0 */     \
-                                                                          \
-        "movq      9(%0), %%mm1             \n\t" /* JKLMNOPQ */          \
-        "movq      %%mm1, %%mm4             \n\t" /* JKLMNOPQ */          \
-        "movq      %%mm1, %%mm3             \n\t" /* JKLMNOPQ */          \
-        "psrlq        $8, %%mm1             \n\t" /* KLMNOPQ0 */          \
-        "psrlq       $16, %%mm4             \n\t" /* LMNOPQ00 */          \
-        "punpcklbw %%mm7, %%mm1             \n\t" /* 0K0L0M0N */          \
-        "punpcklbw %%mm7, %%mm4             \n\t" /* 0L0M0N0O */          \
-        "paddw     %%mm1, %%mm5             \n\t" /* b */                 \
-        "paddw     %%mm4, %%mm0             \n\t" /* c */                 \
-        "paddw     %%mm5, %%mm5             \n\t" /* 2b */                \
-        "psubw     %%mm5, %%mm0             \n\t" /* c - 2b */            \
-        "movq      %%mm3, %%mm5             \n\t" /* JKLMNOPQ */          \
-        "psrlq       $24, %%mm3             \n\t" /* MNOPQ000 */          \
-        "pmullw "MANGLE(ff_pw_3)", %%mm0    \n\t" /* 3c - 6b */           \
-        "punpcklbw %%mm7, %%mm3             \n\t" /* 0M0N0O0P */          \
-        "paddw     %%mm3, %%mm2             \n\t" /* d */                 \
-        "psubw     %%mm2, %%mm0             \n\t" /* -6b + 3c - d */      \
-        "movq      %%mm5, %%mm2             \n\t" /* JKLMNOPQ */          \
-        "punpcklbw %%mm7, %%mm2             \n\t" /* 0J0K0L0M */          \
-        "punpckhbw %%mm7, %%mm5             \n\t" /* 0N0O0P0Q */          \
-        "paddw     %%mm2, %%mm6             \n\t" /* a */                 \
-        "pmullw "MANGLE(ff_pw_20)", %%mm6   \n\t" /* 20a */               \
-        "paddw        %6, %%mm0             \n\t"                         \
-        "paddw     %%mm6, %%mm0             \n\t" /* 20a - 6b + 3c - d */ \
-        "psraw        $5, %%mm0             \n\t"                         \
-        /* mm1 = KLMN, mm2 = JKLM, mm3 = MNOP, */                         \
-        /* mm4 = LMNO, mm5 = NOPQ mm7 = 0 */                              \
-                                                                          \
-        "paddw    %%mm5, %%mm3              \n\t" /* a */                 \
-        "pshufw   $0xF9, %%mm5, %%mm6       \n\t" /* 0O0P0Q0Q */          \
-        "paddw    %%mm4, %%mm6              \n\t" /* b */                 \
-        "pshufw   $0xBE, %%mm5, %%mm4       \n\t" /* 0P0Q0Q0P */          \
-        "pshufw   $0x6F, %%mm5, %%mm5       \n\t" /* 0Q0Q0P0O */          \
-        "paddw    %%mm1, %%mm4              \n\t" /* c */                 \
-        "paddw    %%mm2, %%mm5              \n\t" /* d */                 \
-        "paddw    %%mm6, %%mm6              \n\t" /* 2b */                \
-        "psubw    %%mm6, %%mm4              \n\t" /* c - 2b */            \
-        "pmullw "MANGLE(ff_pw_20)", %%mm3   \n\t" /* 20a */               \
-        "pmullw  "MANGLE(ff_pw_3)", %%mm4   \n\t" /* 3c - 6b */           \
-        "psubw    %%mm5, %%mm3              \n\t" /* -6b + 3c - d */      \
-        "paddw       %6, %%mm4              \n\t"                         \
-        "paddw    %%mm3, %%mm4              \n\t" /* 20a - 6b + 3c - d */ \
-        "psraw       $5, %%mm4              \n\t"                         \
-        "packuswb %%mm4, %%mm0              \n\t"                         \
-        OP_MMXEXT(%%mm0, 8(%1), %%mm4, q)                                 \
-                                                                          \
-        "add         %3, %0                 \n\t"                         \
-        "add         %4, %1                 \n\t"                         \
-        "decl        %2                     \n\t"                         \
-        "jnz         1b                     \n\t"                         \
-        : "+a"(src), "+c"(dst), "+D"(h)                                   \
-        : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride),               \
-          /* "m"(ff_pw_20), "m"(ff_pw_3), */ "m"(temp), "m"(ROUNDER)      \
-        : "memory"                                                        \
-        );                                                                \
-}                                                                         \
-                                                                          \
-static void OPNAME ## mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst,          \
-                                                   uint8_t *src,          \
-                                                   int dstStride,         \
-                                                   int srcStride,         \
-                                                   int h)                 \
-{                                                                         \
-    __asm__ volatile (                                                    \
-        "pxor      %%mm7, %%mm7             \n\t"                         \
-        "1:                                 \n\t"                         \
-        "movq       (%0), %%mm0             \n\t" /* ABCDEFGH */          \
-        "movq      %%mm0, %%mm1             \n\t" /* ABCDEFGH */          \
-        "movq      %%mm0, %%mm2             \n\t" /* ABCDEFGH */          \
-        "punpcklbw %%mm7, %%mm0             \n\t" /* 0A0B0C0D */          \
-        "punpckhbw %%mm7, %%mm1             \n\t" /* 0E0F0G0H */          \
-        "pshufw    $0x90, %%mm0, %%mm5      \n\t" /* 0A0A0B0C */          \
-        "pshufw    $0x41, %%mm0, %%mm6      \n\t" /* 0B0A0A0B */          \
-        "movq      %%mm2, %%mm3             \n\t" /* ABCDEFGH */          \
-        "movq      %%mm2, %%mm4             \n\t" /* ABCDEFGH */          \
-        "psllq        $8, %%mm2             \n\t" /* 0ABCDEFG */          \
-        "psllq       $16, %%mm3             \n\t" /* 00ABCDEF */          \
-        "psllq       $24, %%mm4             \n\t" /* 000ABCDE */          \
-        "punpckhbw %%mm7, %%mm2             \n\t" /* 0D0E0F0G */          \
-        "punpckhbw %%mm7, %%mm3             \n\t" /* 0C0D0E0F */          \
-        "punpckhbw %%mm7, %%mm4             \n\t" /* 0B0C0D0E */          \
-        "paddw     %%mm3, %%mm5             \n\t" /* b */                 \
-        "paddw     %%mm2, %%mm6             \n\t" /* c */                 \
-        "paddw     %%mm5, %%mm5             \n\t" /* 2b */                \
-        "psubw     %%mm5, %%mm6             \n\t" /* c - 2b */            \
-        "pshufw    $0x06, %%mm0, %%mm5      \n\t" /* 0C0B0A0A */          \
-        "pmullw "MANGLE(ff_pw_3)", %%mm6    \n\t" /* 3c - 6b */           \
-        "paddw     %%mm4, %%mm0             \n\t" /* a */                 \
-        "paddw     %%mm1, %%mm5             \n\t" /* d */                 \
-        "pmullw "MANGLE(ff_pw_20)", %%mm0   \n\t" /* 20a */               \
-        "psubw     %%mm5, %%mm0             \n\t" /* 20a - d */           \
-        "paddw        %5, %%mm6             \n\t"                         \
-        "paddw     %%mm6, %%mm0             \n\t" /* 20a - 6b + 3c - d */ \
-        "psraw        $5, %%mm0             \n\t"                         \
-        /* mm1 = EFGH, mm2 = DEFG, mm3 = CDEF, mm4 = BCDE, mm7 = 0 */     \
-                                                                          \
-        "movd      5(%0), %%mm5             \n\t" /* FGHI */              \
-        "punpcklbw %%mm7, %%mm5             \n\t" /* 0F0G0H0I */          \
-        "pshufw    $0xF9, %%mm5, %%mm6      \n\t" /* 0G0H0I0I */          \
-        "paddw     %%mm5, %%mm1             \n\t" /* a */                 \
-        "paddw     %%mm6, %%mm2             \n\t" /* b */                 \
-        "pshufw    $0xBE, %%mm5, %%mm6      \n\t" /* 0H0I0I0H */          \
-        "pshufw    $0x6F, %%mm5, %%mm5      \n\t" /* 0I0I0H0G */          \
-        "paddw     %%mm6, %%mm3             \n\t" /* c */                 \
-        "paddw     %%mm5, %%mm4             \n\t" /* d */                 \
-        "paddw     %%mm2, %%mm2             \n\t" /* 2b */                \
-        "psubw     %%mm2, %%mm3             \n\t" /* c - 2b */            \
-        "pmullw "MANGLE(ff_pw_20)", %%mm1   \n\t" /* 20a */               \
-        "pmullw  "MANGLE(ff_pw_3)", %%mm3   \n\t" /* 3c - 6b */           \
-        "psubw     %%mm4, %%mm3             \n\t" /* -6b + 3c - d */      \
-        "paddw        %5, %%mm1             \n\t"                         \
-        "paddw     %%mm1, %%mm3             \n\t" /* 20a - 6b + 3c - d */ \
-        "psraw        $5, %%mm3             \n\t"                         \
-        "packuswb  %%mm3, %%mm0             \n\t"                         \
-        OP_MMXEXT(%%mm0, (%1), %%mm4, q)                                  \
-                                                                          \
-        "add          %3, %0                \n\t"                         \
-        "add          %4, %1                \n\t"                         \
-        "decl         %2                    \n\t"                         \
-        "jnz          1b                    \n\t"                         \
-        : "+a"(src), "+c"(dst), "+d"(h)                                   \
-        : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride),               \
-          /* "m"(ff_pw_20), "m"(ff_pw_3), */ "m"(ROUNDER)                 \
-        : "memory"                                                        \
-        );                                                                \
-}
 
-#define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)                          \
-static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst,      \
-                                                     uint8_t *src,      \
-                                                     int dstStride,     \
-                                                     int srcStride)     \
-{                                                                       \
-    uint64_t temp[17 * 4];                                              \
-    uint64_t *temp_ptr = temp;                                          \
-    int count = 17;                                                     \
-                                                                        \
-    /* FIXME unroll */                                                  \
-    __asm__ volatile (                                                  \
-        "pxor      %%mm7, %%mm7             \n\t"                       \
-        "1:                                 \n\t"                       \
-        "movq       (%0), %%mm0             \n\t"                       \
-        "movq       (%0), %%mm1             \n\t"                       \
-        "movq      8(%0), %%mm2             \n\t"                       \
-        "movq      8(%0), %%mm3             \n\t"                       \
-        "punpcklbw %%mm7, %%mm0             \n\t"                       \
-        "punpckhbw %%mm7, %%mm1             \n\t"                       \
-        "punpcklbw %%mm7, %%mm2             \n\t"                       \
-        "punpckhbw %%mm7, %%mm3             \n\t"                       \
-        "movq      %%mm0, (%1)              \n\t"                       \
-        "movq      %%mm1, 17 * 8(%1)        \n\t"                       \
-        "movq      %%mm2, 2 * 17 * 8(%1)    \n\t"                       \
-        "movq      %%mm3, 3 * 17 * 8(%1)    \n\t"                       \
-        "add          $8, %1                \n\t"                       \
-        "add          %3, %0                \n\t"                       \
-        "decl         %2                    \n\t"                       \
-        "jnz          1b                    \n\t"                       \
-        : "+r"(src), "+r"(temp_ptr), "+r"(count)                        \
-        : "r"((x86_reg)srcStride)                                       \
-        : "memory"                                                      \
-        );                                                              \
-                                                                        \
-    temp_ptr = temp;                                                    \
-    count    = 4;                                                       \
-                                                                        \
-    /* FIXME reorder for speed */                                       \
-    __asm__ volatile (                                                  \
-        /* "pxor  %%mm7, %%mm7            \n\t" */                      \
-        "1:                             \n\t"                           \
-        "movq    (%0), %%mm0            \n\t"                           \
-        "movq   8(%0), %%mm1            \n\t"                           \
-        "movq  16(%0), %%mm2            \n\t"                           \
-        "movq  24(%0), %%mm3            \n\t"                           \
-        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0),   8(%0),    (%0),  32(%0), (%1),     OP) \
-        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5,  8(%0),    (%0),    (%0),  40(%0), (%1, %3), OP) \
-        "add       %4, %1               \n\t"                           \
-        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5,   (%0),    (%0),   8(%0),  48(%0), (%1),     OP) \
-                                                                        \
-        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5,   (%0),   8(%0),  16(%0),  56(%0), (%1, %3), OP) \
-        "add       %4, %1               \n\t"                           \
-        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5,  8(%0),  16(%0),  24(%0),  64(%0), (%1),     OP) \
-        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0),  24(%0),  32(%0),  72(%0), (%1, %3), OP) \
-        "add       %4, %1               \n\t"                           \
-        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0),  32(%0),  40(%0),  80(%0), (%1),     OP) \
-        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0),  40(%0),  48(%0),  88(%0), (%1, %3), OP) \
-        "add       %4, %1               \n\t"                           \
-        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0),  48(%0),  56(%0),  96(%0), (%1),     OP) \
-        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0),  56(%0),  64(%0), 104(%0), (%1, %3), OP) \
-        "add       %4, %1               \n\t"                           \
-        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0),  64(%0),  72(%0), 112(%0), (%1),     OP) \
-        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0),  72(%0),  80(%0), 120(%0), (%1, %3), OP) \
-        "add       %4, %1               \n\t"                           \
-        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0),  80(%0),  88(%0), 128(%0), (%1),     OP) \
-                                                                        \
-        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0),  88(%0),  96(%0), 128(%0), (%1, %3), OP) \
-        "add       %4, %1               \n\t"                           \
-        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0),  96(%0), 104(%0), 120(%0), (%1),     OP) \
-        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0), 104(%0), 112(%0), 112(%0), (%1, %3), OP) \
-                                                                        \
-        "add     $136, %0               \n\t"                           \
-        "add       %6, %1               \n\t"                           \
-        "decl      %2                   \n\t"                           \
-        "jnz       1b                   \n\t"                           \
-                                                                        \
-        : "+r"(temp_ptr), "+r"(dst), "+g"(count)                        \
-        : "r"((x86_reg)dstStride), "r"(2 * (x86_reg)dstStride),         \
-          /* "m"(ff_pw_20), "m"(ff_pw_3), */ "m"(ROUNDER),              \
-          "g"(4 - 14 * (x86_reg)dstStride)                              \
-        : "memory"                                                      \
-        );                                                              \
-}                                                                       \
-                                                                        \
-static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst,       \
-                                                    uint8_t *src,       \
-                                                    int dstStride,      \
-                                                    int srcStride)      \
-{                                                                       \
-    uint64_t temp[9 * 2];                                               \
-    uint64_t *temp_ptr = temp;                                          \
-    int count = 9;                                                      \
-                                                                        \
-    /* FIXME unroll */                                                  \
-    __asm__ volatile (                                                  \
-        "pxor      %%mm7, %%mm7         \n\t"                           \
-        "1:                             \n\t"                           \
-        "movq       (%0), %%mm0         \n\t"                           \
-        "movq       (%0), %%mm1         \n\t"                           \
-        "punpcklbw %%mm7, %%mm0         \n\t"                           \
-        "punpckhbw %%mm7, %%mm1         \n\t"                           \
-        "movq      %%mm0, (%1)          \n\t"                           \
-        "movq      %%mm1, 9*8(%1)       \n\t"                           \
-        "add          $8, %1            \n\t"                           \
-        "add          %3, %0            \n\t"                           \
-        "decl         %2                \n\t"                           \
-        "jnz          1b                \n\t"                           \
-        : "+r"(src), "+r"(temp_ptr), "+r"(count)                        \
-        : "r"((x86_reg)srcStride)                                       \
-        : "memory"                                                      \
-        );                                                              \
-                                                                        \
-    temp_ptr = temp;                                                    \
-    count    = 2;                                                       \
-                                                                        \
-    /* FIXME reorder for speed */                                       \
-    __asm__ volatile (                                                  \
-        /* "pxor  %%mm7, %%mm7            \n\t" */                      \
-        "1:                             \n\t"                           \
-        "movq    (%0), %%mm0            \n\t"                           \
-        "movq   8(%0), %%mm1            \n\t"                           \
-        "movq  16(%0), %%mm2            \n\t"                           \
-        "movq  24(%0), %%mm3            \n\t"                           \
-        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0),  8(%0),   (%0), 32(%0), (%1), OP)     \
-        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5,  8(%0),   (%0),   (%0), 40(%0), (%1, %3), OP) \
-        "add       %4, %1               \n\t"                           \
-        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5,   (%0),   (%0),  8(%0), 48(%0), (%1), OP)     \
-                                                                        \
-        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5,   (%0),  8(%0), 16(%0), 56(%0), (%1, %3), OP) \
-        "add       %4, %1               \n\t"                           \
-        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5,  8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)     \
-                                                                        \
-        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP) \
-        "add       %4, %1               \n\t"                           \
-        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)     \
-        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP) \
-                                                                        \
-        "add      $72, %0               \n\t"                           \
-        "add       %6, %1               \n\t"                           \
-        "decl      %2                   \n\t"                           \
-        "jnz       1b                   \n\t"                           \
-                                                                        \
-        : "+r"(temp_ptr), "+r"(dst), "+g"(count)                        \
-        : "r"((x86_reg)dstStride), "r"(2 * (x86_reg)dstStride),         \
-          /* "m"(ff_pw_20), "m"(ff_pw_3), */ "m"(ROUNDER),              \
-          "g"(4 - 6 * (x86_reg)dstStride)                               \
-        : "memory"                                                      \
-        );                                                              \
-}                                                                       \
-                                                                        \
+#if HAVE_YASM
+#define QPEL_OP(OPNAME, ROUNDER, RND, MMX)                              \
 static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src,   \
                                           int stride)                   \
 {                                                                       \
-    OPNAME ## pixels8_ ## MMX(dst, src, stride, 8);                     \
+    ff_ ## OPNAME ## pixels8_ ## MMX(dst, src, stride, 8);              \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1223,16 +781,17 @@ static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src,    \
 {                                                                       \
     uint64_t temp[8];                                                   \
     uint8_t * const half = (uint8_t*)temp;                              \
-    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8,           \
-                                                stride, 8);             \
-    OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);    \
+    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8,        \
+                                                   stride, 8);          \
+    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half,                 \
+                                        stride, stride, 8);             \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src,    \
                                          int stride)                    \
 {                                                                       \
-    OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride,           \
-                                            stride, 8);                 \
+    ff_ ## OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride,    \
+                                                   stride, 8);          \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1240,10 +799,10 @@ static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src,    \
 {                                                                       \
     uint64_t temp[8];                                                   \
     uint8_t * const half = (uint8_t*)temp;                              \
-    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8,           \
-                                                stride, 8);             \
-    OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride,            \
-                                 stride, 8);                            \
+    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8,        \
+                                                   stride, 8);          \
+    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride,     \
+                                        stride, 8);                     \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1251,14 +810,17 @@ static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src,    \
 {                                                                       \
     uint64_t temp[8];                                                   \
     uint8_t * const half = (uint8_t*)temp;                              \
-    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);  \
-    OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);    \
+    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src,           \
+                                                   8, stride);          \
+    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half,                 \
+                                        stride, stride, 8);             \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src,    \
                                          int stride)                    \
 {                                                                       \
-    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);  \
+    ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src,            \
+                                                   stride, stride);     \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1266,9 +828,10 @@ static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src,    \
 {                                                                       \
     uint64_t temp[8];                                                   \
     uint8_t * const half = (uint8_t*)temp;                              \
-    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);  \
-    OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride,       \
-                                 stride, 8);                            \
+    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src,           \
+                                                   8, stride);          \
+    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride,\
+                                        stride, 8);                     \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1277,11 +840,13 @@ static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src,    \
     uint64_t half[8 + 9];                                               \
     uint8_t * const halfH  = ((uint8_t*)half) + 64;                     \
     uint8_t * const halfHV = ((uint8_t*)half);                          \
-    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,          \
-                                                stride, 9);             \
-    put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);  \
-    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);   \
-    OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);     \
+    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
+                                                   stride, 9);          \
+    ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8,           \
+                                        stride, 9);                     \
+    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
+    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV,             \
+                                        stride, 8, 8);                  \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1290,12 +855,13 @@ static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src,    \
     uint64_t half[8 + 9];                                               \
     uint8_t * const halfH  = ((uint8_t*)half) + 64;                     \
     uint8_t * const halfHV = ((uint8_t*)half);                          \
-    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,          \
-                                                stride, 9);             \
-    put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8,          \
-                                     stride, 9);                        \
-    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);   \
-    OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);     \
+    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
+                                                   stride, 9);          \
+    ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8,       \
+                                        stride, 9);                     \
+    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
+    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV,             \
+                                        stride, 8, 8);                  \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1304,11 +870,13 @@ static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src,    \
     uint64_t half[8 + 9];                                               \
     uint8_t * const halfH  = ((uint8_t*)half) + 64;                     \
     uint8_t * const halfHV = ((uint8_t*)half);                          \
-    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,          \
-                                                stride, 9);             \
-    put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);  \
-    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);   \
-    OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, stride, 8, 8); \
+    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
+                                                   stride, 9);          \
+    ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8,           \
+                                        stride, 9);                     \
+    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
+    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV,         \
+                                        stride, 8, 8);                  \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1317,12 +885,13 @@ static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src,    \
     uint64_t half[8 + 9];                                               \
     uint8_t * const halfH  = ((uint8_t*)half) + 64;                     \
     uint8_t * const halfHV = ((uint8_t*)half);                          \
-    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,          \
-                                                stride, 9);             \
-    put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8,          \
-                                     stride, 9);                        \
-    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);   \
-    OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, stride, 8, 8); \
+    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
+                                                   stride, 9);          \
+    ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8,       \
+                                        stride, 9);                     \
+    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
+    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV,         \
+                                        stride, 8, 8);                  \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1331,10 +900,11 @@ static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src,    \
     uint64_t half[8 + 9];                                               \
     uint8_t * const halfH  = ((uint8_t*)half) + 64;                     \
     uint8_t * const halfHV = ((uint8_t*)half);                          \
-    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,          \
-                                                stride, 9);             \
-    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);   \
-    OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);     \
+    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
+                                                   stride, 9);          \
+    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
+    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV,             \
+                                        stride, 8, 8);                  \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1343,10 +913,11 @@ static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src,    \
     uint64_t half[8 + 9];                                               \
     uint8_t * const halfH  = ((uint8_t*)half) + 64;                     \
     uint8_t * const halfHV = ((uint8_t*)half);                          \
-    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,          \
-                                                stride, 9);             \
-    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);   \
-    OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, stride, 8, 8); \
+    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
+                                                   stride, 9);          \
+    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
+    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV,         \
+                                        stride, 8, 8);                  \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1354,10 +925,12 @@ static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src,    \
 {                                                                       \
     uint64_t half[8 + 9];                                               \
     uint8_t * const halfH = ((uint8_t*)half);                           \
-    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,          \
-                                                stride, 9);             \
-    put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);  \
-    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);     \
+    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
+                                                   stride, 9);          \
+    ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH,              \
+                                        8, stride, 9);                  \
+    ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH,          \
+                                                   stride, 8);          \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1365,11 +938,12 @@ static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src,    \
 {                                                                       \
     uint64_t half[8 + 9];                                               \
     uint8_t * const halfH = ((uint8_t*)half);                           \
-    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,          \
-                                                stride, 9);             \
-    put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8,          \
-                                     stride, 9);                        \
-    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);     \
+    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
+                                                   stride, 9);          \
+    ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8,       \
+                                        stride, 9);                     \
+    ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH,          \
+                                                   stride, 8);          \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src,    \
@@ -1377,15 +951,16 @@ static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src,    \
 {                                                                       \
     uint64_t half[9];                                                   \
     uint8_t * const halfH = ((uint8_t*)half);                           \
-    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,          \
-                                                stride, 9);             \
-    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);     \
+    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
+                                                   stride, 9);          \
+    ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH,          \
+                                                   stride, 8);          \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src,  \
                                            int stride)                  \
 {                                                                       \
-    OPNAME ## pixels16_ ## MMX(dst, src, stride, 16);                   \
+    ff_ ## OPNAME ## pixels16_ ## MMX(dst, src, stride, 16);            \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1393,16 +968,17 @@ static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src,   \
 {                                                                       \
     uint64_t temp[32];                                                  \
     uint8_t * const half = (uint8_t*)temp;                              \
-    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16,         \
-                                                 stride, 16);           \
-    OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);  \
+    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16,      \
+                                                    stride, 16);        \
+    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride,        \
+                                         stride, 16);                   \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src,   \
                                           int stride)                   \
 {                                                                       \
-    OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src,                  \
-                                             stride, stride, 16);       \
+    ff_ ## OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src,           \
+                                                    stride, stride, 16);\
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1410,10 +986,10 @@ static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src,   \
 {                                                                       \
     uint64_t temp[32];                                                  \
     uint8_t * const half = (uint8_t*)temp;                              \
-    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16,         \
-                                                 stride, 16);           \
-    OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half,                   \
-                                  stride, stride, 16);                  \
+    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16,      \
+                                                    stride, 16);        \
+    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half,            \
+                                         stride, stride, 16);           \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1421,15 +997,17 @@ static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src,   \
 {                                                                       \
     uint64_t temp[32];                                                  \
     uint8_t * const half = (uint8_t*)temp;                              \
-    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16,         \
-                                                 stride);               \
-    OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);  \
+    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16,      \
+                                                    stride);            \
+    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride,        \
+                                         stride, 16);                   \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src,   \
                                           int stride)                   \
 {                                                                       \
-    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride); \
+    ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src,           \
+                                                    stride, stride);    \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1437,10 +1015,10 @@ static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src,   \
 {                                                                       \
     uint64_t temp[32];                                                  \
     uint8_t * const half = (uint8_t*)temp;                              \
-    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16,         \
-                                                 stride);               \
-    OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half,                \
-                                  stride, stride, 16);                  \
+    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16,      \
+                                                    stride);            \
+    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half,         \
+                                         stride, stride, 16);           \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1449,13 +1027,14 @@ static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src,   \
     uint64_t half[16 * 2 + 17 * 2];                                     \
     uint8_t * const halfH  = ((uint8_t*)half) + 256;                    \
     uint8_t * const halfHV = ((uint8_t*)half);                          \
-    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,        \
-                                                 stride, 17);           \
-    put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16,            \
-                                      stride, 17);                      \
-    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,         \
-                                                 16, 16);               \
-    OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);  \
+    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
+                                                    stride, 17);        \
+    ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16,         \
+                                         stride, 17);                   \
+    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
+                                                    16, 16);            \
+    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV,            \
+                                         stride, 16, 16);               \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1464,13 +1043,14 @@ static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src,   \
     uint64_t half[16 * 2 + 17 * 2];                                     \
     uint8_t * const halfH  = ((uint8_t*)half) + 256;                    \
     uint8_t * const halfHV = ((uint8_t*)half);                          \
-    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,        \
-                                                 stride, 17);           \
-    put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16,        \
-                                      stride, 17);                      \
-    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,         \
-                                                 16, 16);               \
-    OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);  \
+    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
+                                                    stride, 17);        \
+    ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16,     \
+                                         stride, 17);                   \
+    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
+                                                    16, 16);            \
+    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV,            \
+                                         stride, 16, 16);               \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1479,14 +1059,14 @@ static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src,   \
     uint64_t half[16 * 2 + 17 * 2];                                     \
     uint8_t * const halfH  = ((uint8_t*)half) + 256;                    \
     uint8_t * const halfHV = ((uint8_t*)half);                          \
-    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,        \
-                                                 stride, 17);           \
-    put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16,            \
-                                      stride, 17);                      \
-    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,         \
-                                                 16, 16);               \
-    OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, stride,      \
-                                  16, 16);                              \
+    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
+                                                    stride, 17);        \
+    ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16,         \
+                                         stride, 17);                   \
+    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
+                                                    16, 16);            \
+    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV,       \
+                                         stride, 16, 16);               \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1495,14 +1075,14 @@ static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src,   \
     uint64_t half[16 * 2 + 17 * 2];                                     \
     uint8_t * const halfH  = ((uint8_t*)half) + 256;                    \
     uint8_t * const halfHV = ((uint8_t*)half);                          \
-    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,        \
-                                                 stride, 17);           \
-    put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16,        \
-                                      stride, 17);                      \
-    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,         \
-                                                 16, 16);               \
-    OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, stride,      \
-                                  16, 16);                              \
+    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
+                                                    stride, 17);        \
+    ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16,     \
+                                         stride, 17);                   \
+    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
+                                                    16, 16);            \
+    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV,       \
+                                         stride, 16, 16);               \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1511,11 +1091,12 @@ static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src,   \
     uint64_t half[16 * 2 + 17 * 2];                                     \
     uint8_t * const halfH  = ((uint8_t*)half) + 256;                    \
     uint8_t * const halfHV = ((uint8_t*)half);                          \
-    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,        \
-                                                 stride, 17);           \
-    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,         \
-                                                 16, 16);               \
-    OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);  \
+    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
+                                                    stride, 17);        \
+    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
+                                                    16, 16);            \
+    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV,            \
+                                         stride, 16, 16);               \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1524,12 +1105,12 @@ static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src,   \
     uint64_t half[16 * 2 + 17 * 2];                                     \
     uint8_t * const halfH  = ((uint8_t*)half) + 256;                    \
     uint8_t * const halfHV = ((uint8_t*)half);                          \
-    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,        \
-                                                 stride, 17);           \
-    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,         \
-                                                 16, 16);               \
-    OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, stride,      \
-                                  16, 16);                              \
+    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
+                                                    stride, 17);        \
+    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
+                                                    16, 16);            \
+    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV,       \
+                                         stride, 16, 16);               \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1537,11 +1118,12 @@ static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src,   \
 {                                                                       \
     uint64_t half[17 * 2];                                              \
     uint8_t * const halfH = ((uint8_t*)half);                           \
-    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,        \
-                                                 stride, 17);           \
-    put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16,            \
-                                      stride, 17);                      \
-    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);   \
+    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
+                                                    stride, 17);        \
+    ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16,         \
+                                         stride, 17);                   \
+    ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH,         \
+                                                    stride, 16);        \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1549,11 +1131,12 @@ static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src,   \
 {                                                                       \
     uint64_t half[17 * 2];                                              \
     uint8_t * const halfH = ((uint8_t*)half);                           \
-    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,        \
-                                                 stride, 17);           \
-    put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16,        \
-                                      stride, 17);                      \
-    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);   \
+    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
+                                                    stride, 17);        \
+    ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16,     \
+                                         stride, 17);                   \
+    ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH,         \
+                                                    stride, 16);        \
 }                                                                       \
                                                                         \
 static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src,   \
@@ -1561,83 +1144,19 @@ static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src,   \
 {                                                                       \
     uint64_t half[17 * 2];                                              \
     uint8_t * const halfH = ((uint8_t*)half);                           \
-    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,        \
-                                                 stride, 17);           \
-    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);   \
-}
-
-#define PUT_OP(a, b, temp, size)                \
-    "mov"#size"        "#a", "#b"       \n\t"
-
-#define AVG_MMXEXT_OP(a, b, temp, size)         \
-    "mov"#size"        "#b", "#temp"    \n\t"   \
-    "pavgb          "#temp", "#a"       \n\t"   \
-    "mov"#size"        "#a", "#b"       \n\t"
-
-QPEL_BASE(put_,        ff_pw_16, _,        PUT_OP)
-QPEL_BASE(avg_,        ff_pw_16, _,        AVG_MMXEXT_OP)
-QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP)
-QPEL_OP(put_,          ff_pw_16, _,        PUT_OP,        mmxext)
-QPEL_OP(avg_,          ff_pw_16, _,        AVG_MMXEXT_OP, mmxext)
-QPEL_OP(put_no_rnd_,   ff_pw_15, _no_rnd_, PUT_OP,        mmxext)
-
-/***********************************/
-/* bilinear qpel: not compliant to any spec, only for -lavdopts fast */
-
-#define QPEL_2TAP_XY(OPNAME, SIZE, MMX, XY, HPEL)                              \
-static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, \
-                                                                 uint8_t *src, \
-                                                                 int stride)   \
-{                                                                              \
-    OPNAME ## pixels ## SIZE ## HPEL(dst, src, stride, SIZE);                  \
+    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
+                                                    stride, 17);        \
+    ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH,         \
+                                                    stride, 16);        \
 }
 
-#define QPEL_2TAP_L3(OPNAME, SIZE, MMX, XY, S0, S1, S2)                        \
-static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, \
-                                                                 uint8_t *src, \
-                                                                 int stride)   \
-{                                                                              \
-    OPNAME ## 2tap_qpel ## SIZE ## _l3_ ## MMX(dst, src + S0, stride, SIZE,    \
-                                               S1, S2);                        \
-}
+QPEL_OP(put_,          ff_pw_16, _,        mmxext)
+QPEL_OP(avg_,          ff_pw_16, _,        mmxext)
+QPEL_OP(put_no_rnd_,   ff_pw_15, _no_rnd_, mmxext)
+#endif /* HAVE_YASM */
 
-#define QPEL_2TAP(OPNAME, SIZE, MMX)                                        \
-QPEL_2TAP_XY(OPNAME, SIZE, MMX, 20, _x2_ ## MMX)                            \
-QPEL_2TAP_XY(OPNAME, SIZE, MMX, 02, _y2_ ## MMX)                            \
-QPEL_2TAP_XY(OPNAME, SIZE, MMX, 22, _xy2_mmx)                               \
-static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc00_ ## MMX =    \
-    OPNAME ## qpel ## SIZE ## _mc00_ ## MMX;                                \
-static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc21_ ## MMX =    \
-    OPNAME ## 2tap_qpel ## SIZE ## _mc20_ ## MMX;                           \
-static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc12_ ## MMX =    \
-    OPNAME ## 2tap_qpel ## SIZE ## _mc02_ ## MMX;                           \
-static void OPNAME ## 2tap_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst,      \
-                                                         uint8_t *src,      \
-                                                         int stride)        \
-{                                                                           \
-    OPNAME ## pixels ## SIZE ## _y2_ ## MMX(dst, src + 1, stride, SIZE);    \
-}                                                                           \
-static void OPNAME ## 2tap_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst,      \
-                                                         uint8_t *src,      \
-                                                         int stride)        \
-{                                                                           \
-    OPNAME ## pixels ## SIZE ## _x2_ ## MMX(dst, src + stride,              \
-                                            stride, SIZE);                  \
-}                                                                           \
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 10, 0,           1,       0)                \
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 30, 1,          -1,       0)                \
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 01, 0,           stride,  0)                \
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 03, stride,     -stride,  0)                \
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 11, 0,           stride,  1)                \
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 31, 1,           stride, -1)                \
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 13, stride,     -stride,  1)                \
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 33, stride + 1, -stride, -1)                \
-
-QPEL_2TAP(put_, 16, mmxext)
-QPEL_2TAP(avg_, 16, mmxext)
-QPEL_2TAP(put_,  8, mmxext)
-QPEL_2TAP(avg_,  8, mmxext)
 
+#if HAVE_INLINE_ASM
 void ff_put_rv40_qpel8_mc33_mmx(uint8_t *dst, uint8_t *src, int stride)
 {
   put_pixels8_xy2_mmx(dst, src, stride, 8);
@@ -1819,50 +1338,10 @@ static void gmc_mmx(uint8_t *dst, uint8_t *src,
 
 #endif /* HAVE_INLINE_ASM */
 
-#include "h264_qpel.c"
-
-void ff_put_h264_chroma_mc8_rnd_mmx  (uint8_t *dst, uint8_t *src,
-                                      int stride, int h, int x, int y);
-void ff_avg_h264_chroma_mc8_rnd_mmxext(uint8_t *dst, uint8_t *src,
-                                       int stride, int h, int x, int y);
-void ff_avg_h264_chroma_mc8_rnd_3dnow(uint8_t *dst, uint8_t *src,
-                                      int stride, int h, int x, int y);
-
-void ff_put_h264_chroma_mc4_mmx      (uint8_t *dst, uint8_t *src,
-                                      int stride, int h, int x, int y);
-void ff_avg_h264_chroma_mc4_mmxext   (uint8_t *dst, uint8_t *src,
-                                      int stride, int h, int x, int y);
-void ff_avg_h264_chroma_mc4_3dnow    (uint8_t *dst, uint8_t *src,
-                                      int stride, int h, int x, int y);
-
-void ff_put_h264_chroma_mc2_mmxext   (uint8_t *dst, uint8_t *src,
-                                      int stride, int h, int x, int y);
-void ff_avg_h264_chroma_mc2_mmxext   (uint8_t *dst, uint8_t *src,
-                                      int stride, int h, int x, int y);
-
-void ff_put_h264_chroma_mc8_rnd_ssse3(uint8_t *dst, uint8_t *src,
-                                      int stride, int h, int x, int y);
-void ff_put_h264_chroma_mc4_ssse3    (uint8_t *dst, uint8_t *src,
-                                      int stride, int h, int x, int y);
-
-void ff_avg_h264_chroma_mc8_rnd_ssse3(uint8_t *dst, uint8_t *src,
-                                      int stride, int h, int x, int y);
-void ff_avg_h264_chroma_mc4_ssse3    (uint8_t *dst, uint8_t *src,
-                                      int stride, int h, int x, int y);
-
-#define CHROMA_MC(OP, NUM, DEPTH, OPT)                                  \
-void ff_ ## OP ## _h264_chroma_mc ## NUM ## _ ## DEPTH ## _ ## OPT      \
-                                      (uint8_t *dst, uint8_t *src,      \
-                                       int stride, int h, int x, int y);
-
-CHROMA_MC(put, 2, 10, mmxext)
-CHROMA_MC(avg, 2, 10, mmxext)
-CHROMA_MC(put, 4, 10, mmxext)
-CHROMA_MC(avg, 4, 10, mmxext)
-CHROMA_MC(put, 8, 10, sse2)
-CHROMA_MC(avg, 8, 10, sse2)
-CHROMA_MC(put, 8, 10, avx)
-CHROMA_MC(avg, 8, 10, avx)
+void ff_put_pixels16_sse2(uint8_t *block, const uint8_t *pixels,
+                          ptrdiff_t line_size, int h);
+void ff_avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels,
+                          ptrdiff_t line_size, int h);
 
 #if HAVE_INLINE_ASM
 
@@ -1894,88 +1373,71 @@ void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src,
     put_pixels8_mmx(dst, src, stride, 8);
 }
 
-void ff_avg_vc1_mspel_mc00_mmxext(uint8_t *dst, const uint8_t *src,
-                                  int stride, int rnd)
-{
-    avg_pixels8_mmxext(dst, src, stride, 8);
-}
-
-/* only used in VP3/5/6 */
-static void put_vp_no_rnd_pixels8_l2_mmx(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h)
-{
-//    START_TIMER
-    MOVQ_BFE(mm6);
-    __asm__ volatile(
-        "1:                             \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   (%2), %%mm1             \n\t"
-        "movq   (%1,%4), %%mm2          \n\t"
-        "movq   (%2,%4), %%mm3          \n\t"
-        PAVGBP_MMX_NO_RND(%%mm0, %%mm1, %%mm4,   %%mm2, %%mm3, %%mm5)
-        "movq   %%mm4, (%3)             \n\t"
-        "movq   %%mm5, (%3,%4)          \n\t"
-
-        "movq   (%1,%4,2), %%mm0        \n\t"
-        "movq   (%2,%4,2), %%mm1        \n\t"
-        "movq   (%1,%5), %%mm2          \n\t"
-        "movq   (%2,%5), %%mm3          \n\t"
-        "lea    (%1,%4,4), %1           \n\t"
-        "lea    (%2,%4,4), %2           \n\t"
-        PAVGBP_MMX_NO_RND(%%mm0, %%mm1, %%mm4,   %%mm2, %%mm3, %%mm5)
-        "movq   %%mm4, (%3,%4,2)        \n\t"
-        "movq   %%mm5, (%3,%5)          \n\t"
-        "lea    (%3,%4,4), %3           \n\t"
-        "subl   $4, %0                  \n\t"
-        "jnz    1b                      \n\t"
-        :"+r"(h), "+r"(a), "+r"(b), "+r"(dst)
-        :"r"((x86_reg)stride), "r"((x86_reg)3L*stride)
-        :"memory");
-//    STOP_TIMER("put_vp_no_rnd_pixels8_l2_mmx")
-}
-static void put_vp_no_rnd_pixels16_l2_mmx(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h)
-{
-    put_vp_no_rnd_pixels8_l2_mmx(dst, a, b, stride, h);
-    put_vp_no_rnd_pixels8_l2_mmx(dst+8, a+8, b+8, stride, h);
-}
-
 #if CONFIG_DIRAC_DECODER
-#define DIRAC_PIXOP(OPNAME, EXT)\
-void ff_ ## OPNAME ## _dirac_pixels8_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
+#define DIRAC_PIXOP(OPNAME2, OPNAME, EXT)\
+void ff_ ## OPNAME2 ## _dirac_pixels8_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
 {\
-    OPNAME ## _pixels8_ ## EXT(dst, src[0], stride, h);\
+    if (h&3)\
+        ff_ ## OPNAME2 ## _dirac_pixels8_c(dst, src, stride, h);\
+    else\
+        OPNAME ## _pixels8_ ## EXT(dst, src[0], stride, h);\
 }\
-void ff_ ## OPNAME ## _dirac_pixels16_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
+void ff_ ## OPNAME2 ## _dirac_pixels16_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
 {\
-    OPNAME ## _pixels16_ ## EXT(dst, src[0], stride, h);\
+    if (h&3)\
+        ff_ ## OPNAME2 ## _dirac_pixels16_c(dst, src, stride, h);\
+    else\
+        OPNAME ## _pixels16_ ## EXT(dst, src[0], stride, h);\
 }\
-void ff_ ## OPNAME ## _dirac_pixels32_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
+void ff_ ## OPNAME2 ## _dirac_pixels32_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
 {\
-    OPNAME ## _pixels16_ ## EXT(dst   , src[0]   , stride, h);\
-    OPNAME ## _pixels16_ ## EXT(dst+16, src[0]+16, stride, h);\
+    if (h&3) {\
+        ff_ ## OPNAME2 ## _dirac_pixels32_c(dst, src, stride, h);\
+    } else {\
+        OPNAME ## _pixels16_ ## EXT(dst   , src[0]   , stride, h);\
+        OPNAME ## _pixels16_ ## EXT(dst+16, src[0]+16, stride, h);\
+    }\
 }
 
-DIRAC_PIXOP(put, mmx)
-DIRAC_PIXOP(avg, mmx)
-DIRAC_PIXOP(avg, mmxext)
+#if HAVE_MMX_INLINE
+DIRAC_PIXOP(put, put, mmx)
+DIRAC_PIXOP(avg, avg, mmx)
+#endif
 
 #if HAVE_YASM
+DIRAC_PIXOP(avg, ff_avg, mmxext)
+
 void ff_put_dirac_pixels16_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h)
 {
+    if (h&3)
+        ff_put_dirac_pixels16_c(dst, src, stride, h);
+    else
     ff_put_pixels16_sse2(dst, src[0], stride, h);
 }
 void ff_avg_dirac_pixels16_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h)
 {
+    if (h&3)
+        ff_avg_dirac_pixels16_c(dst, src, stride, h);
+    else
     ff_avg_pixels16_sse2(dst, src[0], stride, h);
 }
 void ff_put_dirac_pixels32_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h)
 {
+    if (h&3) {
+        ff_put_dirac_pixels32_c(dst, src, stride, h);
+    } else {
     ff_put_pixels16_sse2(dst   , src[0]   , stride, h);
     ff_put_pixels16_sse2(dst+16, src[0]+16, stride, h);
+    }
 }
 void ff_avg_dirac_pixels32_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h)
 {
+    if (h&3) {
+        ff_avg_dirac_pixels32_c(dst, src, stride, h);
+    } else {
     ff_avg_pixels16_sse2(dst   , src[0]   , stride, h);
     ff_avg_pixels16_sse2(dst+16, src[0]+16, stride, h);
+    }
 }
 #endif
 #endif
@@ -1984,159 +1446,34 @@ void ff_avg_dirac_pixels32_sse2(uint8_t *dst, const uint8_t *src[5], int stride,
  * converted. */
 #if CONFIG_GPL
 static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size,
-                                    DCTELEM *block)
+                                    int16_t *block)
 {
     ff_mmx_idct(block);
     ff_put_pixels_clamped_mmx(block, dest, line_size);
 }
 
 static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size,
-                                    DCTELEM *block)
+                                    int16_t *block)
 {
     ff_mmx_idct(block);
     ff_add_pixels_clamped_mmx(block, dest, line_size);
 }
 
 static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size,
-                                     DCTELEM *block)
+                                     int16_t *block)
 {
     ff_mmxext_idct(block);
     ff_put_pixels_clamped_mmx(block, dest, line_size);
 }
 
 static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size,
-                                     DCTELEM *block)
+                                     int16_t *block)
 {
     ff_mmxext_idct(block);
     ff_add_pixels_clamped_mmx(block, dest, line_size);
 }
 #endif
 
-static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
-{
-    int i;
-    __asm__ volatile ("pxor %%mm7, %%mm7":);
-    for (i = 0; i < blocksize; i += 2) {
-        __asm__ volatile (
-            "movq       %0, %%mm0   \n\t"
-            "movq       %1, %%mm1   \n\t"
-            "movq    %%mm0, %%mm2   \n\t"
-            "movq    %%mm1, %%mm3   \n\t"
-            "pfcmpge %%mm7, %%mm2   \n\t" // m <= 0.0
-            "pfcmpge %%mm7, %%mm3   \n\t" // a <= 0.0
-            "pslld     $31, %%mm2   \n\t" // keep only the sign bit
-            "pxor    %%mm2, %%mm1   \n\t"
-            "movq    %%mm3, %%mm4   \n\t"
-            "pand    %%mm1, %%mm3   \n\t"
-            "pandn   %%mm1, %%mm4   \n\t"
-            "pfadd   %%mm0, %%mm3   \n\t" // a = m + ((a < 0) & (a ^ sign(m)))
-            "pfsub   %%mm4, %%mm0   \n\t" // m = m + ((a > 0) & (a ^ sign(m)))
-            "movq    %%mm3, %1      \n\t"
-            "movq    %%mm0, %0      \n\t"
-            : "+m"(mag[i]), "+m"(ang[i])
-            :: "memory"
-        );
-    }
-    __asm__ volatile ("femms");
-}
-
-static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
-{
-    int i;
-
-    __asm__ volatile (
-        "movaps  %0, %%xmm5 \n\t"
-        :: "m"(ff_pdw_80000000[0])
-    );
-    for (i = 0; i < blocksize; i += 4) {
-        __asm__ volatile (
-            "movaps      %0, %%xmm0 \n\t"
-            "movaps      %1, %%xmm1 \n\t"
-            "xorps   %%xmm2, %%xmm2 \n\t"
-            "xorps   %%xmm3, %%xmm3 \n\t"
-            "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
-            "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
-            "andps   %%xmm5, %%xmm2 \n\t" // keep only the sign bit
-            "xorps   %%xmm2, %%xmm1 \n\t"
-            "movaps  %%xmm3, %%xmm4 \n\t"
-            "andps   %%xmm1, %%xmm3 \n\t"
-            "andnps  %%xmm1, %%xmm4 \n\t"
-            "addps   %%xmm0, %%xmm3 \n\t" // a = m + ((a < 0) & (a ^ sign(m)))
-            "subps   %%xmm4, %%xmm0 \n\t" // m = m + ((a > 0) & (a ^ sign(m)))
-            "movaps  %%xmm3, %1     \n\t"
-            "movaps  %%xmm0, %0     \n\t"
-            : "+m"(mag[i]), "+m"(ang[i])
-            :: "memory"
-        );
-    }
-}
-
-#if HAVE_6REGS
-static void vector_fmul_window_3dnowext(float *dst, const float *src0,
-                                        const float *src1, const float *win,
-                                        int len)
-{
-    x86_reg i = -len * 4;
-    x86_reg j =  len * 4 - 8;
-    __asm__ volatile (
-        "1:                             \n"
-        "pswapd (%5, %1), %%mm1         \n"
-        "movq   (%5, %0), %%mm0         \n"
-        "pswapd (%4, %1), %%mm5         \n"
-        "movq   (%3, %0), %%mm4         \n"
-        "movq      %%mm0, %%mm2         \n"
-        "movq      %%mm1, %%mm3         \n"
-        "pfmul     %%mm4, %%mm2         \n" // src0[len + i] * win[len + i]
-        "pfmul     %%mm5, %%mm3         \n" // src1[j]       * win[len + j]
-        "pfmul     %%mm4, %%mm1         \n" // src0[len + i] * win[len + j]
-        "pfmul     %%mm5, %%mm0         \n" // src1[j]       * win[len + i]
-        "pfadd     %%mm3, %%mm2         \n"
-        "pfsub     %%mm0, %%mm1         \n"
-        "pswapd    %%mm2, %%mm2         \n"
-        "movq      %%mm1, (%2, %0)      \n"
-        "movq      %%mm2, (%2, %1)      \n"
-        "sub          $8, %1            \n"
-        "add          $8, %0            \n"
-        "jl           1b                \n"
-        "femms                          \n"
-        : "+r"(i), "+r"(j)
-        : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
-    );
-}
-
-static void vector_fmul_window_sse(float *dst, const float *src0,
-                                   const float *src1, const float *win, int len)
-{
-    x86_reg i = -len * 4;
-    x86_reg j =  len * 4 - 16;
-    __asm__ volatile (
-        "1:                             \n"
-        "movaps      (%5, %1), %%xmm1   \n"
-        "movaps      (%5, %0), %%xmm0   \n"
-        "movaps      (%4, %1), %%xmm5   \n"
-        "movaps      (%3, %0), %%xmm4   \n"
-        "shufps $0x1b, %%xmm1, %%xmm1   \n"
-        "shufps $0x1b, %%xmm5, %%xmm5   \n"
-        "movaps        %%xmm0, %%xmm2   \n"
-        "movaps        %%xmm1, %%xmm3   \n"
-        "mulps         %%xmm4, %%xmm2   \n" // src0[len + i] * win[len + i]
-        "mulps         %%xmm5, %%xmm3   \n" // src1[j]       * win[len + j]
-        "mulps         %%xmm4, %%xmm1   \n" // src0[len + i] * win[len + j]
-        "mulps         %%xmm5, %%xmm0   \n" // src1[j]       * win[len + i]
-        "addps         %%xmm3, %%xmm2   \n"
-        "subps         %%xmm0, %%xmm1   \n"
-        "shufps $0x1b, %%xmm2, %%xmm2   \n"
-        "movaps        %%xmm1, (%2, %0) \n"
-        "movaps        %%xmm2, (%2, %1) \n"
-        "sub              $16, %1       \n"
-        "add              $16, %0       \n"
-        "jl                1b           \n"
-        : "+r"(i), "+r"(j)
-        : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
-    );
-}
-#endif /* HAVE_6REGS */
-
 static void vector_clipf_sse(float *dst, const float *src,
                              float min, float max, int len)
 {
@@ -2211,18 +1548,6 @@ int  ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src,
 int  ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
                                       int w, int left);
 
-float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
-
-void ff_vector_fmul_reverse_sse(float *dst, const float *src0,
-                                const float *src1, int len);
-void ff_vector_fmul_reverse_avx(float *dst, const float *src0,
-                                const float *src1, int len);
-
-void ff_vector_fmul_add_sse(float *dst, const float *src0, const float *src1,
-                            const float *src2, int len);
-void ff_vector_fmul_add_avx(float *dst, const float *src0, const float *src1,
-                            const float *src2, int len);
-
 void ff_vector_clip_int32_mmx     (int32_t *dst, const int32_t *src,
                                    int32_t min, int32_t max, unsigned int len);
 void ff_vector_clip_int32_sse2    (int32_t *dst, const int32_t *src,
@@ -2232,11 +1557,6 @@ void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
 void ff_vector_clip_int32_sse4    (int32_t *dst, const int32_t *src,
                                    int32_t min, int32_t max, unsigned int len);
 
-extern void ff_butterflies_float_interleave_sse(float *dst, const float *src0,
-                                                const float *src1, int len);
-extern void ff_butterflies_float_interleave_avx(float *dst, const float *src0,
-                                                const float *src1, int len);
-
 #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX)                          \
     do {                                                                     \
     c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
@@ -2259,29 +1579,14 @@ extern void ff_butterflies_float_interleave_avx(float *dst, const float *src0,
 
 #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU)                                     \
     do {                                                                        \
-        c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _     ## CPU; \
-        c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## SIZE ## _x2_  ## CPU; \
-        c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## SIZE ## _y2_  ## CPU; \
-        c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
-    } while (0)
-
-#define H264_QPEL_FUNCS(x, y, CPU)                                                            \
-    do {                                                                                      \
-        c->put_h264_qpel_pixels_tab[0][x + y * 4] = put_h264_qpel16_mc ## x ## y ## _ ## CPU; \
-        c->put_h264_qpel_pixels_tab[1][x + y * 4] = put_h264_qpel8_mc  ## x ## y ## _ ## CPU; \
-        c->avg_h264_qpel_pixels_tab[0][x + y * 4] = avg_h264_qpel16_mc ## x ## y ## _ ## CPU; \
-        c->avg_h264_qpel_pixels_tab[1][x + y * 4] = avg_h264_qpel8_mc  ## x ## y ## _ ## CPU; \
-    } while (0)
-
-#define H264_QPEL_FUNCS_10(x, y, CPU)                                                               \
-    do {                                                                                            \
-        c->put_h264_qpel_pixels_tab[0][x + y * 4] = ff_put_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \
-        c->put_h264_qpel_pixels_tab[1][x + y * 4] = ff_put_h264_qpel8_mc  ## x ## y ## _10_ ## CPU; \
-        c->avg_h264_qpel_pixels_tab[0][x + y * 4] = ff_avg_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \
-        c->avg_h264_qpel_pixels_tab[1][x + y * 4] = ff_avg_h264_qpel8_mc  ## x ## y ## _10_ ## CPU; \
+        c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _     ## CPU; \
+        c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_  ## CPU; \
+        c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_  ## CPU; \
+        c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
     } while (0)
 
-static void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx, int mm_flags)
+static av_cold void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx,
+                                     int mm_flags)
 {
     const int high_bit_depth = avctx->bits_per_raw_sample > 8;
 
@@ -2295,35 +1600,26 @@ static void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx, int mm_flags)
         c->clear_blocks = clear_blocks_mmx;
         c->draw_edges   = draw_edges_mmx;
 
-        SET_HPEL_FUNCS(put,        0, 16, mmx);
-        SET_HPEL_FUNCS(put_no_rnd, 0, 16, mmx);
-        SET_HPEL_FUNCS(avg,        0, 16, mmx);
-        SET_HPEL_FUNCS(avg_no_rnd, 0, 16, mmx);
-        SET_HPEL_FUNCS(put,        1,  8, mmx);
-        SET_HPEL_FUNCS(put_no_rnd, 1,  8, mmx);
-        SET_HPEL_FUNCS(avg,        1,  8, mmx);
-        SET_HPEL_FUNCS(avg_no_rnd, 1,  8, mmx);
+        SET_HPEL_FUNCS(put,        [0], 16, mmx);
+        SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
+        SET_HPEL_FUNCS(avg,        [0], 16, mmx);
+        SET_HPEL_FUNCS(avg_no_rnd,    , 16, mmx);
+        SET_HPEL_FUNCS(put,        [1],  8, mmx);
+        SET_HPEL_FUNCS(put_no_rnd, [1],  8, mmx);
+        SET_HPEL_FUNCS(avg,        [1],  8, mmx);
     }
 
-#if ARCH_X86_32 || !HAVE_YASM
+#if CONFIG_VIDEODSP && (ARCH_X86_32 || !HAVE_YASM)
     c->gmc = gmc_mmx;
 #endif
 
     c->add_bytes = add_bytes_mmx;
-
-    c->put_no_rnd_pixels_l2[0]= put_vp_no_rnd_pixels16_l2_mmx;
-    c->put_no_rnd_pixels_l2[1]= put_vp_no_rnd_pixels8_l2_mmx;
-
-    if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
-        c->h263_v_loop_filter = h263_v_loop_filter_mmx;
-        c->h263_h_loop_filter = h263_h_loop_filter_mmx;
-    }
 #endif /* HAVE_INLINE_ASM */
 
 #if HAVE_YASM
-    if (!high_bit_depth && CONFIG_H264CHROMA) {
-        c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_rnd_mmx;
-        c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_mmx;
+    if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
+        c->h263_v_loop_filter = ff_h263_v_loop_filter_mmx;
+        c->h263_h_loop_filter = ff_h263_h_loop_filter_mmx;
     }
 
     c->vector_clip_int32 = ff_vector_clip_int32_mmx;
@@ -2331,92 +1627,55 @@ static void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx, int mm_flags)
 
 }
 
-static void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
-                                int mm_flags)
+static av_cold void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
+                                        int mm_flags)
 {
     const int bit_depth      = avctx->bits_per_raw_sample;
     const int high_bit_depth = bit_depth > 8;
 
-#if HAVE_INLINE_ASM
+#if HAVE_YASM
     SET_QPEL_FUNCS(avg_qpel,        0, 16, mmxext, );
     SET_QPEL_FUNCS(avg_qpel,        1,  8, mmxext, );
-    SET_QPEL_FUNCS(avg_2tap_qpel,   0, 16, mmxext, );
-    SET_QPEL_FUNCS(avg_2tap_qpel,   1,  8, mmxext, );
 
     SET_QPEL_FUNCS(put_qpel,        0, 16, mmxext, );
     SET_QPEL_FUNCS(put_qpel,        1,  8, mmxext, );
-    SET_QPEL_FUNCS(put_2tap_qpel,   0, 16, mmxext, );
-    SET_QPEL_FUNCS(put_2tap_qpel,   1,  8, mmxext, );
     SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmxext, );
     SET_QPEL_FUNCS(put_no_rnd_qpel, 1,  8, mmxext, );
 
     if (!high_bit_depth) {
-        c->put_pixels_tab[0][1] = put_pixels16_x2_mmxext;
-        c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
+        c->put_pixels_tab[0][1] = ff_put_pixels16_x2_mmxext;
+        c->put_pixels_tab[0][2] = ff_put_pixels16_y2_mmxext;
 
-        c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
-        c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
-        c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
+        c->avg_pixels_tab[0][0] = ff_avg_pixels16_mmxext;
+        c->avg_pixels_tab[0][1] = ff_avg_pixels16_x2_mmxext;
+        c->avg_pixels_tab[0][2] = ff_avg_pixels16_y2_mmxext;
 
-        c->put_pixels_tab[1][1] = put_pixels8_x2_mmxext;
-        c->put_pixels_tab[1][2] = put_pixels8_y2_mmxext;
+        c->put_pixels_tab[1][1] = ff_put_pixels8_x2_mmxext;
+        c->put_pixels_tab[1][2] = ff_put_pixels8_y2_mmxext;
 
-        c->avg_pixels_tab[1][0] = avg_pixels8_mmxext;
-        c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmxext;
-        c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmxext;
+        c->avg_pixels_tab[1][0] = ff_avg_pixels8_mmxext;
+        c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_mmxext;
+        c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_mmxext;
     }
 
     if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
         if (!high_bit_depth) {
-            c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
-            c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
-            c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmxext;
-            c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmxext;
+            c->put_no_rnd_pixels_tab[0][1] = ff_put_no_rnd_pixels16_x2_mmxext;
+            c->put_no_rnd_pixels_tab[0][2] = ff_put_no_rnd_pixels16_y2_mmxext;
+            c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_mmxext;
+            c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_mmxext;
 
-            c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
-            c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmxext;
+            c->avg_pixels_tab[0][3] = ff_avg_pixels16_xy2_mmxext;
+            c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_mmxext;
         }
     }
+#endif /* HAVE_YASM */
 
+#if HAVE_MMXEXT_EXTERNAL
     if (CONFIG_VP3_DECODER && (avctx->codec_id == AV_CODEC_ID_VP3 ||
                                avctx->codec_id == AV_CODEC_ID_THEORA)) {
-        c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_mmxext;
-        c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_mmxext;
-    }
-#endif /* HAVE_INLINE_ASM */
-
-#if HAVE_MMXEXT_EXTERNAL
-    if (CONFIG_H264QPEL) {
-        if (!high_bit_depth) {
-            SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmxext, );
-            SET_QPEL_FUNCS(put_h264_qpel, 1,  8, mmxext, );
-            SET_QPEL_FUNCS(put_h264_qpel, 2,  4, mmxext, );
-            SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmxext, );
-            SET_QPEL_FUNCS(avg_h264_qpel, 1,  8, mmxext, );
-            SET_QPEL_FUNCS(avg_h264_qpel, 2,  4, mmxext, );
-        } else if (bit_depth == 10) {
-#if !ARCH_X86_64
-            SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_mmxext, ff_);
-            SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_mmxext, ff_);
-            SET_QPEL_FUNCS(put_h264_qpel, 1,  8, 10_mmxext, ff_);
-            SET_QPEL_FUNCS(avg_h264_qpel, 1,  8, 10_mmxext, ff_);
-#endif
-            SET_QPEL_FUNCS(put_h264_qpel, 2, 4,  10_mmxext, ff_);
-            SET_QPEL_FUNCS(avg_h264_qpel, 2, 4,  10_mmxext, ff_);
-        }
-    }
-
-    if (!high_bit_depth && CONFIG_H264CHROMA) {
-        c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_mmxext;
-        c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_mmxext;
-        c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_mmxext;
-        c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_mmxext;
-    }
-    if (bit_depth == 10 && CONFIG_H264CHROMA) {
-        c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_10_mmxext;
-        c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_10_mmxext;
-        c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_10_mmxext;
-        c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_10_mmxext;
+        c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_mmxext;
+        c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_mmxext;
     }
 
     /* slower than cmov version on AMD */
@@ -2434,64 +1693,48 @@ static void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
 #endif /* HAVE_MMXEXT_EXTERNAL */
 }
 
-static void dsputil_init_3dnow(DSPContext *c, AVCodecContext *avctx,
-                               int mm_flags)
+static av_cold void dsputil_init_3dnow(DSPContext *c, AVCodecContext *avctx,
+                                       int mm_flags)
 {
     const int high_bit_depth = avctx->bits_per_raw_sample > 8;
 
-#if HAVE_INLINE_ASM
+#if HAVE_YASM
     if (!high_bit_depth) {
-        c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
-        c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
+        c->put_pixels_tab[0][1] = ff_put_pixels16_x2_3dnow;
+        c->put_pixels_tab[0][2] = ff_put_pixels16_y2_3dnow;
 
-        c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
-        c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
-        c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
+        c->avg_pixels_tab[0][0] = ff_avg_pixels16_3dnow;
+        c->avg_pixels_tab[0][1] = ff_avg_pixels16_x2_3dnow;
+        c->avg_pixels_tab[0][2] = ff_avg_pixels16_y2_3dnow;
 
-        c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
-        c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
+        c->put_pixels_tab[1][1] = ff_put_pixels8_x2_3dnow;
+        c->put_pixels_tab[1][2] = ff_put_pixels8_y2_3dnow;
 
-        c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
-        c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
-        c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
+        c->avg_pixels_tab[1][0] = ff_avg_pixels8_3dnow;
+        c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_3dnow;
+        c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_3dnow;
 
         if (!(avctx->flags & CODEC_FLAG_BITEXACT)){
-            c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
-            c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
-            c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
-            c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
+            c->put_no_rnd_pixels_tab[0][1] = ff_put_no_rnd_pixels16_x2_3dnow;
+            c->put_no_rnd_pixels_tab[0][2] = ff_put_no_rnd_pixels16_y2_3dnow;
+            c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_3dnow;
+            c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_3dnow;
 
-            c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
-            c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
+            c->avg_pixels_tab[0][3] = ff_avg_pixels16_xy2_3dnow;
+            c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_3dnow;
         }
     }
 
     if (CONFIG_VP3_DECODER && (avctx->codec_id == AV_CODEC_ID_VP3 ||
                                avctx->codec_id == AV_CODEC_ID_THEORA)) {
-        c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_3dnow;
-        c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_3dnow;
-    }
-
-    c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow;
-#endif /* HAVE_INLINE_ASM */
-
-#if HAVE_YASM
-    if (!high_bit_depth && CONFIG_H264CHROMA) {
-        c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_3dnow;
-        c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_3dnow;
+        c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_3dnow;
+        c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_3dnow;
     }
 #endif /* HAVE_YASM */
 }
 
-static void dsputil_init_3dnowext(DSPContext *c, AVCodecContext *avctx,
-                                  int mm_flags)
-{
-#if HAVE_AMD3DNOWEXT_INLINE && HAVE_6REGS
-    c->vector_fmul_window  = vector_fmul_window_3dnowext;
-#endif
-}
-
-static void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx, int mm_flags)
+static av_cold void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx,
+                                     int mm_flags)
 {
     const int high_bit_depth = avctx->bits_per_raw_sample > 8;
 
@@ -2504,30 +1747,18 @@ static void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx, int mm_flags)
         }
     }
 
-    c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse;
-
-#if HAVE_6REGS
-    c->vector_fmul_window = vector_fmul_window_sse;
-#endif
-
     c->vector_clipf = vector_clipf_sse;
 #endif /* HAVE_INLINE_ASM */
 
 #if HAVE_YASM
-    c->vector_fmul_reverse = ff_vector_fmul_reverse_sse;
-    c->vector_fmul_add     = ff_vector_fmul_add_sse;
-
-    c->scalarproduct_float          = ff_scalarproduct_float_sse;
-    c->butterflies_float_interleave = ff_butterflies_float_interleave_sse;
-
 #if HAVE_INLINE_ASM && CONFIG_VIDEODSP
     c->gmc = gmc_sse;
 #endif
 #endif /* HAVE_YASM */
 }
 
-static void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
-                              int mm_flags)
+static av_cold void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
+                                      int mm_flags)
 {
     const int bit_depth      = avctx->bits_per_raw_sample;
     const int high_bit_depth = bit_depth > 8;
@@ -2548,39 +1779,6 @@ static void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
             c->put_pixels_tab[0][0]        = ff_put_pixels16_sse2;
             c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_sse2;
             c->avg_pixels_tab[0][0]        = ff_avg_pixels16_sse2;
-            if (CONFIG_H264QPEL)
-                H264_QPEL_FUNCS(0, 0, sse2);
-        }
-    }
-
-    if (!high_bit_depth && CONFIG_H264QPEL) {
-        H264_QPEL_FUNCS(0, 1, sse2);
-        H264_QPEL_FUNCS(0, 2, sse2);
-        H264_QPEL_FUNCS(0, 3, sse2);
-        H264_QPEL_FUNCS(1, 1, sse2);
-        H264_QPEL_FUNCS(1, 2, sse2);
-        H264_QPEL_FUNCS(1, 3, sse2);
-        H264_QPEL_FUNCS(2, 1, sse2);
-        H264_QPEL_FUNCS(2, 2, sse2);
-        H264_QPEL_FUNCS(2, 3, sse2);
-        H264_QPEL_FUNCS(3, 1, sse2);
-        H264_QPEL_FUNCS(3, 2, sse2);
-        H264_QPEL_FUNCS(3, 3, sse2);
-    }
-
-    if (bit_depth == 10) {
-        if (CONFIG_H264QPEL) {
-            SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_sse2, ff_);
-            SET_QPEL_FUNCS(put_h264_qpel, 1,  8, 10_sse2, ff_);
-            SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_sse2, ff_);
-            SET_QPEL_FUNCS(avg_h264_qpel, 1,  8, 10_sse2, ff_);
-            H264_QPEL_FUNCS_10(1, 0, sse2_cache64);
-            H264_QPEL_FUNCS_10(2, 0, sse2_cache64);
-            H264_QPEL_FUNCS_10(3, 0, sse2_cache64);
-        }
-        if (CONFIG_H264CHROMA) {
-            c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_sse2;
-            c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_sse2;
         }
     }
 
@@ -2600,38 +1798,10 @@ static void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
 #endif /* HAVE_SSE2_EXTERNAL */
 }
 
-static void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
-                               int mm_flags)
+static av_cold void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
+                                       int mm_flags)
 {
 #if HAVE_SSSE3_EXTERNAL
-    const int high_bit_depth = avctx->bits_per_raw_sample > 8;
-    const int bit_depth      = avctx->bits_per_raw_sample;
-
-    if (!high_bit_depth && CONFIG_H264QPEL) {
-        H264_QPEL_FUNCS(1, 0, ssse3);
-        H264_QPEL_FUNCS(1, 1, ssse3);
-        H264_QPEL_FUNCS(1, 2, ssse3);
-        H264_QPEL_FUNCS(1, 3, ssse3);
-        H264_QPEL_FUNCS(2, 0, ssse3);
-        H264_QPEL_FUNCS(2, 1, ssse3);
-        H264_QPEL_FUNCS(2, 2, ssse3);
-        H264_QPEL_FUNCS(2, 3, ssse3);
-        H264_QPEL_FUNCS(3, 0, ssse3);
-        H264_QPEL_FUNCS(3, 1, ssse3);
-        H264_QPEL_FUNCS(3, 2, ssse3);
-        H264_QPEL_FUNCS(3, 3, ssse3);
-    }
-    if (bit_depth == 10 && CONFIG_H264QPEL) {
-        H264_QPEL_FUNCS_10(1, 0, ssse3_cache64);
-        H264_QPEL_FUNCS_10(2, 0, ssse3_cache64);
-        H264_QPEL_FUNCS_10(3, 0, ssse3_cache64);
-    }
-    if (!high_bit_depth && CONFIG_H264CHROMA) {
-        c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_rnd_ssse3;
-        c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_ssse3;
-        c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_ssse3;
-        c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_ssse3;
-    }
     c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
     if (mm_flags & AV_CPU_FLAG_SSE4) // not really sse4, just slow on Conroe
         c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
@@ -2646,40 +1816,15 @@ static void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
 #endif /* HAVE_SSSE3_EXTERNAL */
 }
 
-static void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
-                              int mm_flags)
+static av_cold void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
+                                      int mm_flags)
 {
 #if HAVE_SSE4_EXTERNAL
     c->vector_clip_int32 = ff_vector_clip_int32_sse4;
 #endif /* HAVE_SSE4_EXTERNAL */
 }
 
-static void dsputil_init_avx(DSPContext *c, AVCodecContext *avctx, int mm_flags)
-{
-#if HAVE_AVX_EXTERNAL
-    const int bit_depth = avctx->bits_per_raw_sample;
-
-    if (bit_depth == 10) {
-        // AVX implies !cache64.
-        // TODO: Port cache(32|64) detection from x264.
-        if (CONFIG_H264QPEL) {
-            H264_QPEL_FUNCS_10(1, 0, sse2);
-            H264_QPEL_FUNCS_10(2, 0, sse2);
-            H264_QPEL_FUNCS_10(3, 0, sse2);
-        }
-
-        if (CONFIG_H264CHROMA) {
-            c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_avx;
-            c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_avx;
-        }
-    }
-    c->butterflies_float_interleave = ff_butterflies_float_interleave_avx;
-    c->vector_fmul_reverse = ff_vector_fmul_reverse_avx;
-    c->vector_fmul_add = ff_vector_fmul_add_avx;
-#endif /* HAVE_AVX_EXTERNAL */
-}
-
-void ff_dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx)
+av_cold void ff_dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx)
 {
     int mm_flags = av_get_cpu_flags();
 
@@ -2739,9 +1884,6 @@ void ff_dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx)
     if (mm_flags & AV_CPU_FLAG_3DNOW)
         dsputil_init_3dnow(c, avctx, mm_flags);
 
-    if (mm_flags & AV_CPU_FLAG_3DNOWEXT)
-        dsputil_init_3dnowext(c, avctx, mm_flags);
-
     if (mm_flags & AV_CPU_FLAG_SSE)
         dsputil_init_sse(c, avctx, mm_flags);
 
@@ -2754,9 +1896,6 @@ void ff_dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx)
     if (mm_flags & AV_CPU_FLAG_SSE4)
         dsputil_init_sse4(c, avctx, mm_flags);
 
-    if (mm_flags & AV_CPU_FLAG_AVX)
-        dsputil_init_avx(c, avctx, mm_flags);
-
     if (CONFIG_ENCODERS)
         ff_dsputilenc_init_mmx(c, avctx);
 }
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/dsputil_mmx.h b/mythtv/external/FFmpeg/libavcodec/x86/dsputil_mmx.h
index d07ac9fc658..f3659703e60 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/dsputil_mmx.h
+++ b/mythtv/external/FFmpeg/libavcodec/x86/dsputil_mmx.h
@@ -22,7 +22,9 @@
 #ifndef AVCODEC_X86_DSPUTIL_MMX_H
 #define AVCODEC_X86_DSPUTIL_MMX_H
 
+#include 
 #include 
+
 #include "libavcodec/dsputil.h"
 #include "libavutil/x86/asm.h"
 
@@ -31,8 +33,6 @@ typedef struct xmm_reg { uint64_t a, b; } xmm_reg;
 extern const uint64_t ff_bone;
 extern const uint64_t ff_wtwo;
 
-extern const uint64_t ff_pdw_80000000[2];
-
 extern const xmm_reg  ff_pw_3;
 extern const xmm_reg  ff_pw_4;
 extern const xmm_reg  ff_pw_5;
@@ -85,9 +85,12 @@ extern const double ff_pd_2[2];
 void ff_dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx);
 void ff_dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
 
-void ff_add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
-void ff_put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
-void ff_put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
+void ff_add_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels, int line_size);
+void ff_put_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels, int line_size);
+void ff_put_signed_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels, int line_size);
+
+void ff_avg_pixels8_mmxext(uint8_t *block, const uint8_t *pixels,
+                           ptrdiff_t line_size, int h);
 
 void ff_put_cavs_qpel8_mc00_mmxext(uint8_t *dst, uint8_t *src, int stride);
 void ff_avg_cavs_qpel8_mc00_mmxext(uint8_t *dst, uint8_t *src, int stride);
@@ -95,15 +98,14 @@ void ff_put_cavs_qpel16_mc00_mmxext(uint8_t *dst, uint8_t *src, int stride);
 void ff_avg_cavs_qpel16_mc00_mmxext(uint8_t *dst, uint8_t *src, int stride);
 
 void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd);
-void ff_avg_vc1_mspel_mc00_mmxext(uint8_t *dst, const uint8_t *src, int stride, int rnd);
 
 void ff_put_rv40_qpel8_mc33_mmx(uint8_t *block, uint8_t *pixels, int line_size);
 void ff_put_rv40_qpel16_mc33_mmx(uint8_t *block, uint8_t *pixels, int line_size);
 void ff_avg_rv40_qpel8_mc33_mmx(uint8_t *block, uint8_t *pixels, int line_size);
 void ff_avg_rv40_qpel16_mc33_mmx(uint8_t *block, uint8_t *pixels, int line_size);
 
-void ff_mmx_idct(DCTELEM *block);
-void ff_mmxext_idct(DCTELEM *block);
+void ff_mmx_idct(int16_t *block);
+void ff_mmxext_idct(int16_t *block);
 
 
 void ff_deinterlace_line_mmx(uint8_t *dst,
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/dsputil_rnd_template.c b/mythtv/external/FFmpeg/libavcodec/x86/dsputil_rnd_template.c
index e4c91381fa5..4568207a2ed 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/dsputil_rnd_template.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/dsputil_rnd_template.c
@@ -25,7 +25,7 @@
  */
 
 // put_pixels
-static void DEF(put, pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(put, pixels8_x2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
 {
     MOVQ_BFE(mm6);
     __asm__ volatile(
@@ -107,7 +107,7 @@ static void av_unused DEF(put, pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t
         :"memory");
 }
 
-static void DEF(put, pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(put, pixels16_x2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
 {
     MOVQ_BFE(mm6);
     __asm__ volatile(
@@ -202,7 +202,7 @@ static void av_unused DEF(put, pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t
         :"memory");
 }
 
-static void DEF(put, pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(put, pixels8_y2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
 {
     MOVQ_BFE(mm6);
     __asm__ volatile(
@@ -231,7 +231,7 @@ static void DEF(put, pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line
         :REG_a, "memory");
 }
 
-static void DEF(put, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(put, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
 {
     MOVQ_ZERO(mm7);
     SET_RND(mm6); // =2 for rnd  and  =1 for no_rnd version
@@ -298,7 +298,7 @@ static void DEF(put, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int lin
 }
 
 // avg_pixels
-static void av_unused DEF(avg, pixels4)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void av_unused DEF(avg, pixels4)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
 {
     MOVQ_BFE(mm6);
     JUMPALIGN();
@@ -317,8 +317,9 @@ static void av_unused DEF(avg, pixels4)(uint8_t *block, const uint8_t *pixels, i
     while (--h);
 }
 
+#ifndef NO_RND
 // in case more speed is needed - unroling would certainly help
-static void DEF(avg, pixels8)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(avg, pixels8)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
 {
     MOVQ_BFE(mm6);
     JUMPALIGN();
@@ -336,8 +337,9 @@ static void DEF(avg, pixels8)(uint8_t *block, const uint8_t *pixels, int line_si
     }
     while (--h);
 }
+#endif // NO_RND
 
-static void DEF(avg, pixels16)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(avg, pixels16)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
 {
     MOVQ_BFE(mm6);
     JUMPALIGN();
@@ -360,7 +362,8 @@ static void DEF(avg, pixels16)(uint8_t *block, const uint8_t *pixels, int line_s
     while (--h);
 }
 
-static void DEF(avg, pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+#ifndef NO_RND
+static void DEF(avg, pixels8_x2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
 {
     MOVQ_BFE(mm6);
     JUMPALIGN();
@@ -379,6 +382,7 @@ static void DEF(avg, pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line
         block += line_size;
     } while (--h);
 }
+#endif // NO_RND
 
 static av_unused void DEF(avg, pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
 {
@@ -401,7 +405,7 @@ static av_unused void DEF(avg, pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t
     } while (--h);
 }
 
-static void DEF(avg, pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(avg, pixels16_x2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
 {
     MOVQ_BFE(mm6);
     JUMPALIGN();
@@ -454,7 +458,7 @@ static av_unused void DEF(avg, pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t
     } while (--h);
 }
 
-static void DEF(avg, pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(avg, pixels8_y2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
 {
     MOVQ_BFE(mm6);
     __asm__ volatile(
@@ -494,7 +498,7 @@ static void DEF(avg, pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line
 }
 
 // this routine is 'slightly' suboptimal but mostly unused
-static void DEF(avg, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+static void DEF(avg, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
 {
     MOVQ_ZERO(mm7);
     SET_RND(mm6); // =2 for rnd  and  =1 for no_rnd version
@@ -569,22 +573,22 @@ static void DEF(avg, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int lin
 }
 
 //FIXME optimize
-static void DEF(put, pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
+static void DEF(put, pixels16_y2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){
     DEF(put, pixels8_y2)(block  , pixels  , line_size, h);
     DEF(put, pixels8_y2)(block+8, pixels+8, line_size, h);
 }
 
-static void DEF(put, pixels16_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
+static void DEF(put, pixels16_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){
     DEF(put, pixels8_xy2)(block  , pixels  , line_size, h);
     DEF(put, pixels8_xy2)(block+8, pixels+8, line_size, h);
 }
 
-static void DEF(avg, pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
+static void DEF(avg, pixels16_y2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){
     DEF(avg, pixels8_y2)(block  , pixels  , line_size, h);
     DEF(avg, pixels8_y2)(block+8, pixels+8, line_size, h);
 }
 
-static void DEF(avg, pixels16_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
+static void DEF(avg, pixels16_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){
     DEF(avg, pixels8_xy2)(block  , pixels  , line_size, h);
     DEF(avg, pixels8_xy2)(block+8, pixels+8, line_size, h);
 }
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/dsputilenc.asm b/mythtv/external/FFmpeg/libavcodec/x86/dsputilenc.asm
index 3e7990d0a8a..1839bee24a3 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/dsputilenc.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/dsputilenc.asm
@@ -257,15 +257,12 @@ hadamard8_16_wrapper 0, 14
 %endmacro
 
 INIT_MMX mmx
-%define ABS1 ABS1_MMX
 HADAMARD8_DIFF
 
 INIT_MMX mmxext
-%define ABS1 ABS1_MMXEXT
 HADAMARD8_DIFF
 
 INIT_XMM sse2
-%define ABS2 ABS2_MMXEXT
 %if ARCH_X86_64
 %define ABS_SUM_8x8 ABS_SUM_8x8_64
 %else
@@ -274,7 +271,6 @@ INIT_XMM sse2
 HADAMARD8_DIFF 10
 
 INIT_XMM ssse3
-%define ABS2        ABS2_SSSE3
 %define ABS_SUM_8x8 ABS_SUM_8x8_64
 HADAMARD8_DIFF 9
 
@@ -337,3 +333,155 @@ cglobal sse16, 5, 5, 8
     paddd     m7, m1
     movd     eax, m7         ; return value
     RET
+
+INIT_MMX mmx
+; get_pixels_mmx(int16_t *block, const uint8_t *pixels, int line_size)
+cglobal get_pixels, 3,4
+    movsxdifnidn r2, r2d
+    add          r0, 128
+    mov          r3, -128
+    pxor         m7, m7
+.loop:
+    mova         m0, [r1]
+    mova         m2, [r1+r2]
+    mova         m1, m0
+    mova         m3, m2
+    punpcklbw    m0, m7
+    punpckhbw    m1, m7
+    punpcklbw    m2, m7
+    punpckhbw    m3, m7
+    mova [r0+r3+ 0], m0
+    mova [r0+r3+ 8], m1
+    mova [r0+r3+16], m2
+    mova [r0+r3+24], m3
+    lea          r1, [r1+r2*2]
+    add          r3, 32
+    js .loop
+    REP_RET
+
+INIT_XMM sse2
+cglobal get_pixels, 3, 4
+    movsxdifnidn r2, r2d
+    lea          r3, [r2*3]
+    pxor         m4, m4
+    movh         m0, [r1]
+    movh         m1, [r1+r2]
+    movh         m2, [r1+r2*2]
+    movh         m3, [r1+r3]
+    lea          r1, [r1+r2*4]
+    punpcklbw    m0, m4
+    punpcklbw    m1, m4
+    punpcklbw    m2, m4
+    punpcklbw    m3, m4
+    mova       [r0], m0
+    mova  [r0+0x10], m1
+    mova  [r0+0x20], m2
+    mova  [r0+0x30], m3
+    movh         m0, [r1]
+    movh         m1, [r1+r2*1]
+    movh         m2, [r1+r2*2]
+    movh         m3, [r1+r3]
+    punpcklbw    m0, m4
+    punpcklbw    m1, m4
+    punpcklbw    m2, m4
+    punpcklbw    m3, m4
+    mova  [r0+0x40], m0
+    mova  [r0+0x50], m1
+    mova  [r0+0x60], m2
+    mova  [r0+0x70], m3
+    RET
+
+INIT_MMX mmx
+; diff_pixels_mmx(int16_t *block, const uint8_t *s1, const unint8_t *s2, stride)
+cglobal diff_pixels, 4,5
+    movsxdifnidn r3, r3d
+    pxor         m7, m7
+    add          r0,  128
+    mov          r4, -128
+.loop:
+    mova         m0, [r1]
+    mova         m2, [r2]
+    mova         m1, m0
+    mova         m3, m2
+    punpcklbw    m0, m7
+    punpckhbw    m1, m7
+    punpcklbw    m2, m7
+    punpckhbw    m3, m7
+    psubw        m0, m2
+    psubw        m1, m3
+    mova  [r0+r4+0], m0
+    mova  [r0+r4+8], m1
+    add          r1, r3
+    add          r2, r3
+    add          r4, 16
+    jne .loop
+    REP_RET
+
+INIT_MMX mmx
+; pix_sum16_mmx(uint8_t * pix, int line_size)
+cglobal pix_sum16, 2, 3
+    movsxdifnidn r1, r1d
+    mov          r2, r1
+    neg          r2
+    shl          r2, 4
+    sub          r0, r2
+    pxor         m7, m7
+    pxor         m6, m6
+.loop:
+    mova         m0, [r0+r2+0]
+    mova         m1, [r0+r2+0]
+    mova         m2, [r0+r2+8]
+    mova         m3, [r0+r2+8]
+    punpcklbw    m0, m7
+    punpckhbw    m1, m7
+    punpcklbw    m2, m7
+    punpckhbw    m3, m7
+    paddw        m1, m0
+    paddw        m3, m2
+    paddw        m3, m1
+    paddw        m6, m3
+    add          r2, r1
+    js .loop
+    mova         m5, m6
+    psrlq        m6, 32
+    paddw        m6, m5
+    mova         m5, m6
+    psrlq        m6, 16
+    paddw        m6, m5
+    movd        eax, m6
+    and         eax, 0xffff
+    RET
+
+INIT_MMX mmx
+; pix_norm1_mmx(uint8_t *pix, int line_size)
+cglobal pix_norm1, 2, 4
+    movsxdifnidn r1, r1d
+    mov          r2, 16
+    pxor         m0, m0
+    pxor         m7, m7
+.loop:
+    mova         m2, [r0+0]
+    mova         m3, [r0+8]
+    mova         m1, m2
+    punpckhbw    m1, m0
+    punpcklbw    m2, m0
+    mova         m4, m3
+    punpckhbw    m3, m0
+    punpcklbw    m4, m0
+    pmaddwd      m1, m1
+    pmaddwd      m2, m2
+    pmaddwd      m3, m3
+    pmaddwd      m4, m4
+    paddd        m2, m1
+    paddd        m4, m3
+    paddd        m7, m2
+    add          r0, r1
+    paddd        m7, m4
+    dec r2
+    jne .loop
+    mova         m1, m7
+    psrlq        m7, 32
+    paddd        m1, m7
+    movd        eax, m1
+    RET
+
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/dsputilenc_mmx.c b/mythtv/external/FFmpeg/libavcodec/x86/dsputilenc_mmx.c
index 48fcce477d2..a3f268e7a88 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/dsputilenc_mmx.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/dsputilenc_mmx.c
@@ -22,189 +22,24 @@
  * MMX optimization by Nick Kurshev 
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
+#include "libavcodec/dct.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/mpegvideo.h"
 #include "libavcodec/mathops.h"
 #include "dsputil_mmx.h"
 
+void ff_get_pixels_mmx(int16_t *block, const uint8_t *pixels, int line_size);
+void ff_get_pixels_sse2(int16_t *block, const uint8_t *pixels, int line_size);
+void ff_diff_pixels_mmx(int16_t *block, const uint8_t *s1, const uint8_t *s2, int stride);
+int ff_pix_sum16_mmx(uint8_t * pix, int line_size);
+int ff_pix_norm1_mmx(uint8_t *pix, int line_size);
 
 #if HAVE_INLINE_ASM
 
-static void get_pixels_mmx(DCTELEM *block, const uint8_t *pixels, int line_size)
-{
-    __asm__ volatile(
-        "mov $-128, %%"REG_a"           \n\t"
-        "pxor %%mm7, %%mm7              \n\t"
-        ".p2align 4                     \n\t"
-        "1:                             \n\t"
-        "movq (%0), %%mm0               \n\t"
-        "movq (%0, %2), %%mm2           \n\t"
-        "movq %%mm0, %%mm1              \n\t"
-        "movq %%mm2, %%mm3              \n\t"
-        "punpcklbw %%mm7, %%mm0         \n\t"
-        "punpckhbw %%mm7, %%mm1         \n\t"
-        "punpcklbw %%mm7, %%mm2         \n\t"
-        "punpckhbw %%mm7, %%mm3         \n\t"
-        "movq %%mm0, (%1, %%"REG_a")    \n\t"
-        "movq %%mm1, 8(%1, %%"REG_a")   \n\t"
-        "movq %%mm2, 16(%1, %%"REG_a")  \n\t"
-        "movq %%mm3, 24(%1, %%"REG_a")  \n\t"
-        "add %3, %0                     \n\t"
-        "add $32, %%"REG_a"             \n\t"
-        "js 1b                          \n\t"
-        : "+r" (pixels)
-        : "r" (block+64), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*2)
-        : "%"REG_a
-    );
-}
-
-static void get_pixels_sse2(DCTELEM *block, const uint8_t *pixels, int line_size)
-{
-    __asm__ volatile(
-        "pxor %%xmm4,      %%xmm4         \n\t"
-        "movq (%0),        %%xmm0         \n\t"
-        "movq (%0, %2),    %%xmm1         \n\t"
-        "movq (%0, %2,2),  %%xmm2         \n\t"
-        "movq (%0, %3),    %%xmm3         \n\t"
-        "lea (%0,%2,4), %0                \n\t"
-        "punpcklbw %%xmm4, %%xmm0         \n\t"
-        "punpcklbw %%xmm4, %%xmm1         \n\t"
-        "punpcklbw %%xmm4, %%xmm2         \n\t"
-        "punpcklbw %%xmm4, %%xmm3         \n\t"
-        "movdqa %%xmm0,      (%1)         \n\t"
-        "movdqa %%xmm1,    16(%1)         \n\t"
-        "movdqa %%xmm2,    32(%1)         \n\t"
-        "movdqa %%xmm3,    48(%1)         \n\t"
-        "movq (%0),        %%xmm0         \n\t"
-        "movq (%0, %2),    %%xmm1         \n\t"
-        "movq (%0, %2,2),  %%xmm2         \n\t"
-        "movq (%0, %3),    %%xmm3         \n\t"
-        "punpcklbw %%xmm4, %%xmm0         \n\t"
-        "punpcklbw %%xmm4, %%xmm1         \n\t"
-        "punpcklbw %%xmm4, %%xmm2         \n\t"
-        "punpcklbw %%xmm4, %%xmm3         \n\t"
-        "movdqa %%xmm0,    64(%1)         \n\t"
-        "movdqa %%xmm1,    80(%1)         \n\t"
-        "movdqa %%xmm2,    96(%1)         \n\t"
-        "movdqa %%xmm3,   112(%1)         \n\t"
-        : "+r" (pixels)
-        : "r" (block), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3)
-    );
-}
-
-static inline void diff_pixels_mmx(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride)
-{
-    __asm__ volatile(
-        "pxor %%mm7, %%mm7              \n\t"
-        "mov $-128, %%"REG_a"           \n\t"
-        ".p2align 4                     \n\t"
-        "1:                             \n\t"
-        "movq (%0), %%mm0               \n\t"
-        "movq (%1), %%mm2               \n\t"
-        "movq %%mm0, %%mm1              \n\t"
-        "movq %%mm2, %%mm3              \n\t"
-        "punpcklbw %%mm7, %%mm0         \n\t"
-        "punpckhbw %%mm7, %%mm1         \n\t"
-        "punpcklbw %%mm7, %%mm2         \n\t"
-        "punpckhbw %%mm7, %%mm3         \n\t"
-        "psubw %%mm2, %%mm0             \n\t"
-        "psubw %%mm3, %%mm1             \n\t"
-        "movq %%mm0, (%2, %%"REG_a")    \n\t"
-        "movq %%mm1, 8(%2, %%"REG_a")   \n\t"
-        "add %3, %0                     \n\t"
-        "add %3, %1                     \n\t"
-        "add $16, %%"REG_a"             \n\t"
-        "jnz 1b                         \n\t"
-        : "+r" (s1), "+r" (s2)
-        : "r" (block+64), "r" ((x86_reg)stride)
-        : "%"REG_a
-    );
-}
-
-static int pix_sum16_mmx(uint8_t * pix, int line_size){
-    const int h=16;
-    int sum;
-    x86_reg index= -line_size*h;
-
-    __asm__ volatile(
-                "pxor %%mm7, %%mm7              \n\t"
-                "pxor %%mm6, %%mm6              \n\t"
-                "1:                             \n\t"
-                "movq (%2, %1), %%mm0           \n\t"
-                "movq (%2, %1), %%mm1           \n\t"
-                "movq 8(%2, %1), %%mm2          \n\t"
-                "movq 8(%2, %1), %%mm3          \n\t"
-                "punpcklbw %%mm7, %%mm0         \n\t"
-                "punpckhbw %%mm7, %%mm1         \n\t"
-                "punpcklbw %%mm7, %%mm2         \n\t"
-                "punpckhbw %%mm7, %%mm3         \n\t"
-                "paddw %%mm0, %%mm1             \n\t"
-                "paddw %%mm2, %%mm3             \n\t"
-                "paddw %%mm1, %%mm3             \n\t"
-                "paddw %%mm3, %%mm6             \n\t"
-                "add %3, %1                     \n\t"
-                " js 1b                         \n\t"
-                "movq %%mm6, %%mm5              \n\t"
-                "psrlq $32, %%mm6               \n\t"
-                "paddw %%mm5, %%mm6             \n\t"
-                "movq %%mm6, %%mm5              \n\t"
-                "psrlq $16, %%mm6               \n\t"
-                "paddw %%mm5, %%mm6             \n\t"
-                "movd %%mm6, %0                 \n\t"
-                "andl $0xFFFF, %0               \n\t"
-                : "=&r" (sum), "+r" (index)
-                : "r" (pix - index), "r" ((x86_reg)line_size)
-        );
-
-        return sum;
-}
-
-static int pix_norm1_mmx(uint8_t *pix, int line_size) {
-    int tmp;
-  __asm__ volatile (
-      "movl $16,%%ecx\n"
-      "pxor %%mm0,%%mm0\n"
-      "pxor %%mm7,%%mm7\n"
-      "1:\n"
-      "movq (%0),%%mm2\n"       /* mm2 = pix[0-7] */
-      "movq 8(%0),%%mm3\n"      /* mm3 = pix[8-15] */
-
-      "movq %%mm2,%%mm1\n"      /* mm1 = mm2 = pix[0-7] */
-
-      "punpckhbw %%mm0,%%mm1\n" /* mm1 = [pix4-7] */
-      "punpcklbw %%mm0,%%mm2\n" /* mm2 = [pix0-3] */
-
-      "movq %%mm3,%%mm4\n"      /* mm4 = mm3 = pix[8-15] */
-      "punpckhbw %%mm0,%%mm3\n" /* mm3 = [pix12-15] */
-      "punpcklbw %%mm0,%%mm4\n" /* mm4 = [pix8-11] */
-
-      "pmaddwd %%mm1,%%mm1\n"   /* mm1 = (pix0^2+pix1^2,pix2^2+pix3^2) */
-      "pmaddwd %%mm2,%%mm2\n"   /* mm2 = (pix4^2+pix5^2,pix6^2+pix7^2) */
-
-      "pmaddwd %%mm3,%%mm3\n"
-      "pmaddwd %%mm4,%%mm4\n"
-
-      "paddd %%mm1,%%mm2\n"     /* mm2 = (pix0^2+pix1^2+pix4^2+pix5^2,
-                                          pix2^2+pix3^2+pix6^2+pix7^2) */
-      "paddd %%mm3,%%mm4\n"
-      "paddd %%mm2,%%mm7\n"
-
-      "add %2, %0\n"
-      "paddd %%mm4,%%mm7\n"
-      "dec %%ecx\n"
-      "jnz 1b\n"
-
-      "movq %%mm7,%%mm1\n"
-      "psrlq $32, %%mm7\n"      /* shift hi dword to lo */
-      "paddd %%mm7,%%mm1\n"
-      "movd %%mm1,%1\n"
-      : "+r" (pix), "=r"(tmp) : "r" ((x86_reg)line_size) : "%ecx" );
-    return tmp;
-}
-
 static int sse8_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
     int tmp;
   __asm__ volatile (
@@ -965,7 +800,7 @@ static void sub_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *src1,
     HSUM(%%xmm0, %%xmm1, %0)
 
 #define DCT_SAD_FUNC(cpu) \
-static int sum_abs_dctelem_##cpu(DCTELEM *block){\
+static int sum_abs_dctelem_##cpu(int16_t *block){\
     int sum;\
     __asm__ volatile(\
         DCT_SAD\
@@ -1109,13 +944,26 @@ hadamard_func(mmxext)
 hadamard_func(sse2)
 hadamard_func(ssse3)
 
-void ff_dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx)
+av_cold void ff_dsputilenc_init_mmx(DSPContext *c, AVCodecContext *avctx)
 {
     int mm_flags = av_get_cpu_flags();
-
-#if HAVE_INLINE_ASM
     int bit_depth = avctx->bits_per_raw_sample;
 
+#if HAVE_YASM
+    if (EXTERNAL_MMX(mm_flags)) {
+        if (bit_depth <= 8)
+            c->get_pixels = ff_get_pixels_mmx;
+        c->diff_pixels = ff_diff_pixels_mmx;
+        c->pix_sum = ff_pix_sum16_mmx;
+
+        c->pix_norm1 = ff_pix_norm1_mmx;
+    }
+    if (EXTERNAL_SSE2(mm_flags))
+        if (bit_depth <= 8)
+            c->get_pixels = ff_get_pixels_sse2;
+#endif /* HAVE_YASM */
+
+#if HAVE_INLINE_ASM
     if (mm_flags & AV_CPU_FLAG_MMX) {
         const int dct_algo = avctx->dct_algo;
         if (avctx->bits_per_raw_sample <= 8 &&
@@ -1129,15 +977,10 @@ void ff_dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx)
             }
         }
 
-        if (bit_depth <= 8)
-            c->get_pixels = get_pixels_mmx;
-        c->diff_pixels = diff_pixels_mmx;
-        c->pix_sum = pix_sum16_mmx;
 
         c->diff_bytes= diff_bytes_mmx;
         c->sum_abs_dctelem= sum_abs_dctelem_mmx;
 
-        c->pix_norm1 = pix_norm1_mmx;
         c->sse[0] = sse16_mmx;
         c->sse[1] = sse8_mmx;
         c->vsad[4]= vsad_intra16_mmx;
@@ -1167,8 +1010,6 @@ void ff_dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx)
         }
 
         if(mm_flags & AV_CPU_FLAG_SSE2){
-            if (bit_depth <= 8)
-                c->get_pixels = get_pixels_sse2;
             c->sum_abs_dctelem= sum_abs_dctelem_sse2;
         }
 
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/dwt_yasm.asm b/mythtv/external/FFmpeg/libavcodec/x86/dwt_yasm.asm
index f6280d1a457..5253abc6c82 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/dwt_yasm.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/dwt_yasm.asm
@@ -64,6 +64,9 @@ section .text
 ;                                  int width)
 cglobal vertical_compose53iL0_%1, 4,4,1, b0, b1, b2, width
     mova    m2, [pw_2]
+%if ARCH_X86_64
+    mov     widthd, widthd
+%endif
 .loop:
     sub     widthq, mmsize/2
     mova    m1, [b0q+2*widthq]
@@ -77,6 +80,9 @@ cglobal vertical_compose53iL0_%1, 4,4,1, b0, b1, b2, width
 ;                                  int width)
 cglobal vertical_compose_dirac53iH0_%1, 4,4,1, b0, b1, b2, width
     mova    m1, [pw_1]
+%if ARCH_X86_64
+    mov     widthd, widthd
+%endif
 .loop:
     sub     widthq, mmsize/2
     mova    m0, [b0q+2*widthq]
@@ -93,6 +99,9 @@ cglobal vertical_compose_dirac53iH0_%1, 4,4,1, b0, b1, b2, width
 cglobal vertical_compose_dd97iH0_%1, 6,6,5, b0, b1, b2, b3, b4, width
     mova    m3, [pw_8]
     mova    m4, [pw_1991]
+%if ARCH_X86_64
+    mov     widthd, widthd
+%endif
 .loop:
     sub     widthq, mmsize/2
     mova    m0, [b0q+2*widthq]
@@ -107,6 +116,9 @@ cglobal vertical_compose_dd97iH0_%1, 6,6,5, b0, b1, b2, b3, b4, width
 cglobal vertical_compose_dd137iL0_%1, 6,6,6, b0, b1, b2, b3, b4, width
     mova    m3, [pw_16]
     mova    m4, [pw_1991]
+%if ARCH_X86_64
+    mov     widthd, widthd
+%endif
 .loop:
     sub     widthq, mmsize/2
     mova    m0, [b0q+2*widthq]
@@ -131,6 +143,9 @@ cglobal vertical_compose_dd137iL0_%1, 6,6,6, b0, b1, b2, b3, b4, width
 ; void vertical_compose_haar(IDWTELEM *b0, IDWTELEM *b1, int width)
 cglobal vertical_compose_haar_%1, 3,4,3, b0, b1, width
     mova    m3, [pw_1]
+%if ARCH_X86_64
+    mov     widthd, widthd
+%endif
 .loop:
     sub     widthq, mmsize/2
     mova    m1, [b1q+2*widthq]
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/fdct.c b/mythtv/external/FFmpeg/libavcodec/x86/fdct.c
index 44a3d7cbe86..d35245dbbea 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/fdct.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/fdct.c
@@ -32,7 +32,7 @@
 
 #include "libavutil/common.h"
 #include "libavutil/x86/asm.h"
-#include "libavcodec/dsputil.h"
+#include "libavcodec/dct.h"
 
 #if HAVE_INLINE_ASM
 
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/fft_init.c b/mythtv/external/FFmpeg/libavcodec/x86/fft_init.c
index a9d95799bab..bfa794743b9 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/fft_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/fft_init.c
@@ -18,7 +18,6 @@
 
 #include "libavutil/cpu.h"
 #include "libavutil/x86/cpu.h"
-#include "libavcodec/dsputil.h"
 #include "libavcodec/dct.h"
 #include "fft.h"
 
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/fmtconvert_init.c b/mythtv/external/FFmpeg/libavcodec/x86/fmtconvert_init.c
index 528b7b1221f..4a4c0170b72 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/fmtconvert_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/fmtconvert_init.c
@@ -22,11 +22,11 @@
  * MMX optimization by Nick Kurshev 
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/fmtconvert.h"
-#include "libavcodec/dsputil.h"
 
 #if HAVE_YASM
 
@@ -113,7 +113,7 @@ static void float_interleave_sse(float *dst, const float **src,
 }
 #endif /* HAVE_YASM */
 
-void ff_fmt_convert_init_x86(FmtConvertContext *c, AVCodecContext *avctx)
+av_cold void ff_fmt_convert_init_x86(FmtConvertContext *c, AVCodecContext *avctx)
 {
 #if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/h263_loopfilter.asm b/mythtv/external/FFmpeg/libavcodec/x86/h263_loopfilter.asm
new file mode 100644
index 00000000000..a21baf16294
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/x86/h263_loopfilter.asm
@@ -0,0 +1,189 @@
+;******************************************************************************
+;* MMX-optimized H.263 loop filter
+;* Copyright (c) 2003-2013 Michael Niedermayer
+;* Copyright (c) 2013 Daniel Kang
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg is free software; you can redistribute it and/or
+;* modify it under the terms of the GNU Lesser General Public
+;* License as published by the Free Software Foundation; either
+;* version 2.1 of the License, or (at your option) any later version.
+;*
+;* FFmpeg is distributed in the hope that it will be useful,
+;* but WITHOUT ANY WARRANTY; without even the implied warranty of
+;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;* Lesser General Public License for more details.
+;*
+;* You should have received a copy of the GNU Lesser General Public
+;* License along with FFmpeg; if not, write to the Free Software
+;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;******************************************************************************
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+cextern pb_FC
+cextern h263_loop_filter_strength
+
+SECTION_TEXT
+
+%macro H263_LOOP_FILTER 5
+    pxor         m7, m7
+    mova         m0, [%1]
+    mova         m1, [%1]
+    mova         m2, [%4]
+    mova         m3, [%4]
+    punpcklbw    m0, m7
+    punpckhbw    m1, m7
+    punpcklbw    m2, m7
+    punpckhbw    m3, m7
+    psubw        m0, m2
+    psubw        m1, m3
+    mova         m2, [%2]
+    mova         m3, [%2]
+    mova         m4, [%3]
+    mova         m5, [%3]
+    punpcklbw    m2, m7
+    punpckhbw    m3, m7
+    punpcklbw    m4, m7
+    punpckhbw    m5, m7
+    psubw        m4, m2
+    psubw        m5, m3
+    psllw        m4, 2
+    psllw        m5, 2
+    paddw        m4, m0
+    paddw        m5, m1
+    pxor         m6, m6
+    pcmpgtw      m6, m4
+    pcmpgtw      m7, m5
+    pxor         m4, m6
+    pxor         m5, m7
+    psubw        m4, m6
+    psubw        m5, m7
+    psrlw        m4, 3
+    psrlw        m5, 3
+    packuswb     m4, m5
+    packsswb     m6, m7
+    pxor         m7, m7
+    movd         m2, %5
+    punpcklbw    m2, m2
+    punpcklbw    m2, m2
+    punpcklbw    m2, m2
+    psubusb      m2, m4
+    mova         m3, m2
+    psubusb      m3, m4
+    psubb        m2, m3
+    mova         m3, [%2]
+    mova         m4, [%3]
+    pxor         m3, m6
+    pxor         m4, m6
+    paddusb      m3, m2
+    psubusb      m4, m2
+    pxor         m3, m6
+    pxor         m4, m6
+    paddusb      m2, m2
+    packsswb     m0, m1
+    pcmpgtb      m7, m0
+    pxor         m0, m7
+    psubb        m0, m7
+    mova         m1, m0
+    psubusb      m0, m2
+    psubb        m1, m0
+    pand         m1, [pb_FC]
+    psrlw        m1, 2
+    pxor         m1, m7
+    psubb        m1, m7
+    mova         m5, [%1]
+    mova         m6, [%4]
+    psubb        m5, m1
+    paddb        m6, m1
+%endmacro
+
+INIT_MMX mmx
+; void h263_v_loop_filter(uint8_t *src, int stride, int qscale)
+cglobal h263_v_loop_filter, 3,5
+    movsxdifnidn r1, r1d
+    movsxdifnidn r2, r2d
+
+    lea          r4, [h263_loop_filter_strength]
+    movzx       r3d, BYTE [r4+r2]
+    movsx        r2, r3b
+    shl          r2, 1
+
+    mov          r3, r0
+    sub          r3, r1
+    mov          r4, r3
+    sub          r4, r1
+    H263_LOOP_FILTER r4, r3, r0, r0+r1, r2d
+
+    mova       [r3], m3
+    mova       [r0], m4
+    mova       [r4], m5
+    mova    [r0+r1], m6
+    RET
+
+%macro TRANSPOSE4X4 2
+    movd      m0, [%1]
+    movd      m1, [%1+r1]
+    movd      m2, [%1+r1*2]
+    movd      m3, [%1+r3]
+    punpcklbw m0, m1
+    punpcklbw m2, m3
+    mova      m1, m0
+    punpcklwd m0, m2
+    punpckhwd m1, m2
+    movd [%2+ 0], m0
+    punpckhdq m0, m0
+    movd [%2+ 8], m0
+    movd [%2+16], m1
+    punpckhdq m1, m1
+    movd [%2+24], m1
+%endmacro
+
+
+; void h263_h_loop_filter(uint8_t *src, int stride, int qscale)
+INIT_MMX mmx
+cglobal h263_h_loop_filter, 3,5,0,32
+    movsxdifnidn r1, r1d
+    movsxdifnidn r2, r2d
+
+    lea          r4, [h263_loop_filter_strength]
+    movzx       r3d, BYTE [r4+r2]
+    movsx        r2, r3b
+    shl          r2, 1
+
+    sub          r0, 2
+    lea          r3, [r1*3]
+
+    TRANSPOSE4X4 r0, rsp
+    lea          r4, [r0+r1*4]
+    TRANSPOSE4X4 r4, rsp+4
+
+    H263_LOOP_FILTER rsp, rsp+8, rsp+16, rsp+24, r2d
+
+    mova         m1, m5
+    mova         m0, m4
+    punpcklbw    m5, m3
+    punpcklbw    m4, m6
+    punpckhbw    m1, m3
+    punpckhbw    m0, m6
+    mova         m3, m5
+    mova         m6, m1
+    punpcklwd    m5, m4
+    punpcklwd    m1, m0
+    punpckhwd    m3, m4
+    punpckhwd    m6, m0
+    movd       [r0], m5
+    punpckhdq    m5, m5
+    movd  [r0+r1*1], m5
+    movd  [r0+r1*2], m3
+    punpckhdq    m3, m3
+    movd    [r0+r3], m3
+    movd       [r4], m1
+    punpckhdq    m1, m1
+    movd  [r4+r1*1], m1
+    movd  [r4+r1*2], m6
+    punpckhdq    m6, m6
+    movd    [r4+r3], m6
+    RET
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/h264_chromamc.asm b/mythtv/external/FFmpeg/libavcodec/x86/h264_chromamc.asm
index 7f5be7521fb..867ba4927c2 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/h264_chromamc.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/h264_chromamc.asm
@@ -427,11 +427,11 @@ cglobal %1_%2_chroma_mc2, 6, 7, 0
 %macro NOTHING 2-3
 %endmacro
 %macro DIRECT_AVG 2
-    PAVG          %1, %2
+    PAVGB         %1, %2
 %endmacro
 %macro COPY_AVG 3
     movd          %2, %3
-    PAVG          %1, %2
+    PAVGB         %1, %2
 %endmacro
 
 INIT_MMX mmx
@@ -448,7 +448,6 @@ chroma_mc2_mmx_func put, h264
 
 %define CHROMAMC_AVG  DIRECT_AVG
 %define CHROMAMC_AVG4 COPY_AVG
-%define PAVG          pavgb
 chroma_mc8_mmx_func avg, h264, _rnd
 chroma_mc8_mmx_func avg, vc1,  _nornd
 chroma_mc8_mmx_func avg, rv40
@@ -456,7 +455,6 @@ chroma_mc4_mmx_func avg, h264
 chroma_mc4_mmx_func avg, rv40
 chroma_mc2_mmx_func avg, h264
 
-%define PAVG          pavgusb
 INIT_MMX 3dnow
 chroma_mc8_mmx_func avg, h264, _rnd
 chroma_mc8_mmx_func avg, vc1,  _nornd
@@ -673,7 +671,6 @@ INIT_MMX ssse3
 chroma_mc4_ssse3_func put, h264
 
 %define CHROMAMC_AVG DIRECT_AVG
-%define PAVG         pavgb
 INIT_XMM ssse3
 chroma_mc8_ssse3_func avg, h264, _rnd
 chroma_mc8_ssse3_func avg, vc1,  _nornd
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/h264_idct.asm b/mythtv/external/FFmpeg/libavcodec/x86/h264_idct.asm
index d0ac0fe16dd..7bb16534289 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/h264_idct.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/h264_idct.asm
@@ -70,6 +70,10 @@ SECTION .text
     paddw        m0, m6
     IDCT4_1D      w, 0, 1, 2, 3, 4, 5
     pxor         m7, m7
+    movq    [%2+ 0], m7
+    movq    [%2+ 8], m7
+    movq    [%2+16], m7
+    movq    [%2+24], m7
 
     STORE_DIFFx2 m0, m1, m4, m5, m7, 6, %1, %3
     lea          %1, [%1+%3*2]
@@ -161,13 +165,31 @@ cglobal h264_idct_add_8, 3, 3, 0
 %endmacro
 
 ; %1=uint8_t *dst, %2=int16_t *block, %3=int stride
-%macro IDCT8_ADD_MMX_END 3
+%macro IDCT8_ADD_MMX_END 3-4
     IDCT8_1D_FULL %2
     mova    [%2   ], m5
     mova    [%2+16], m6
     mova    [%2+32], m7
 
     pxor         m7, m7
+%if %0 == 4
+    movq   [%4+  0], m7
+    movq   [%4+  8], m7
+    movq   [%4+ 16], m7
+    movq   [%4+ 24], m7
+    movq   [%4+ 32], m7
+    movq   [%4+ 40], m7
+    movq   [%4+ 48], m7
+    movq   [%4+ 56], m7
+    movq   [%4+ 64], m7
+    movq   [%4+ 72], m7
+    movq   [%4+ 80], m7
+    movq   [%4+ 88], m7
+    movq   [%4+ 96], m7
+    movq   [%4+104], m7
+    movq   [%4+112], m7
+    movq   [%4+120], m7
+%endif
     STORE_DIFFx2 m0, m1, m5, m6, m7, 6, %1, %3
     lea          %1, [%1+%3*2]
     STORE_DIFFx2 m2, m3, m5, m6, m7, 6, %1, %3
@@ -190,7 +212,7 @@ cglobal h264_idct8_add_8, 3, 4, 0
     IDCT8_ADD_MMX_START r1  , rsp
     IDCT8_ADD_MMX_START r1+8, rsp+64
     lea          r3, [r0+4]
-    IDCT8_ADD_MMX_END   r0  , rsp,   r2
+    IDCT8_ADD_MMX_END   r0  , rsp,   r2, r1
     IDCT8_ADD_MMX_END   r3  , rsp+8, r2
 
     ADD         rsp, pad
@@ -233,6 +255,14 @@ cglobal h264_idct8_add_8, 3, 4, 0
     SWAP          0, 8
     SWAP          1, 9
 %endif
+    mova   [%2+  0], m7
+    mova   [%2+ 16], m7
+    mova   [%2+ 32], m7
+    mova   [%2+ 48], m7
+    mova   [%2+ 64], m7
+    mova   [%2+ 80], m7
+    mova   [%2+ 96], m7
+    mova   [%2+112], m7
     lea          %1, [%1+%3*4]
     STORE_DIFF   m4, m6, m7, [%1     ]
     STORE_DIFF   m5, m6, m7, [%1+%3  ]
@@ -246,19 +276,11 @@ cglobal h264_idct8_add_8, 3, 4, 10
     IDCT8_ADD_SSE r0, r1, r2, r3
     RET
 
-%macro DC_ADD_MMXEXT_INIT 2-3
-%if %0 == 2
-    movsx        %1, word [%1]
+%macro DC_ADD_MMXEXT_INIT 2
     add          %1, 32
     sar          %1, 6
     movd         m0, %1d
     lea          %1, [%2*3]
-%else
-    add          %3, 32
-    sar          %3, 6
-    movd         m0, %3d
-    lea          %3, [%2*3]
-%endif
     pshufw       m0, m0, 0
     pxor         m1, m1
     psubw        m1, m0
@@ -287,22 +309,47 @@ cglobal h264_idct8_add_8, 3, 4, 10
 
 INIT_MMX mmxext
 ; ff_h264_idct_dc_add_mmxext(uint8_t *dst, int16_t *block, int stride)
-cglobal h264_idct_dc_add_8, 3, 3, 0
-    DC_ADD_MMXEXT_INIT r1, r2
-    DC_ADD_MMXEXT_OP movh, r0, r2, r1
+%if ARCH_X86_64
+cglobal h264_idct_dc_add_8, 3, 4, 0
+    movsx        r3, word [r1]
+    mov   word [r1], 0
+    DC_ADD_MMXEXT_INIT r3, r2
+    DC_ADD_MMXEXT_OP movh, r0, r2, r3
     RET
 
 ; ff_h264_idct8_dc_add_mmxext(uint8_t *dst, int16_t *block, int stride)
-cglobal h264_idct8_dc_add_8, 3, 3, 0
-    DC_ADD_MMXEXT_INIT r1, r2
-    DC_ADD_MMXEXT_OP mova, r0, r2, r1
+cglobal h264_idct8_dc_add_8, 3, 4, 0
+    movsx        r3, word [r1]
+    mov   word [r1], 0
+    DC_ADD_MMXEXT_INIT r3, r2
+    DC_ADD_MMXEXT_OP mova, r0, r2, r3
     lea          r0, [r0+r2*4]
-    DC_ADD_MMXEXT_OP mova, r0, r2, r1
+    DC_ADD_MMXEXT_OP mova, r0, r2, r3
+    RET
+%else
+cglobal h264_idct_dc_add_8, 2, 3, 0
+    movsx        r2, word [r1]
+    mov   word [r1], 0
+    mov          r1, r2m
+    DC_ADD_MMXEXT_INIT r2, r1
+    DC_ADD_MMXEXT_OP movh, r0, r1, r2
     RET
 
+; ff_h264_idct8_dc_add_mmxext(uint8_t *dst, int16_t *block, int stride)
+cglobal h264_idct8_dc_add_8, 2, 3, 0
+    movsx        r2, word [r1]
+    mov   word [r1], 0
+    mov          r1, r2m
+    DC_ADD_MMXEXT_INIT r2, r1
+    DC_ADD_MMXEXT_OP mova, r0, r1, r2
+    lea          r0, [r0+r1*4]
+    DC_ADD_MMXEXT_OP mova, r0, r1, r2
+    RET
+%endif
+
 INIT_MMX mmx
 ; ff_h264_idct_add16_mmx(uint8_t *dst, const int *block_offset,
-;             DCTELEM *block, int stride, const uint8_t nnzc[6*8])
+;             int16_t *block, int stride, const uint8_t nnzc[6*8])
 cglobal h264_idct_add16_8, 5, 7 + npicregs, 0, dst, block_offset, block, stride, nnzc, cntr, coeff, picreg
     xor          r5, r5
 %ifdef PIC
@@ -324,7 +371,7 @@ cglobal h264_idct_add16_8, 5, 7 + npicregs, 0, dst, block_offset, block, stride,
     REP_RET
 
 ; ff_h264_idct8_add4_mmx(uint8_t *dst, const int *block_offset,
-;                        DCTELEM *block, int stride, const uint8_t nnzc[6*8])
+;                        int16_t *block, int stride, const uint8_t nnzc[6*8])
 cglobal h264_idct8_add4_8, 5, 7 + npicregs, 0, dst, block_offset, block, stride, nnzc, cntr, coeff, picreg
     %assign pad 128+4-(stack_offset&7)
     SUB         rsp, pad
@@ -343,7 +390,7 @@ cglobal h264_idct8_add4_8, 5, 7 + npicregs, 0, dst, block_offset, block, stride,
     add   word [r2], 32
     IDCT8_ADD_MMX_START r2  , rsp
     IDCT8_ADD_MMX_START r2+8, rsp+64
-    IDCT8_ADD_MMX_END   r6  , rsp,   r3
+    IDCT8_ADD_MMX_END   r6  , rsp,   r3, r2
     mov         r6d, dword [r1+r5*4]
     lea          r6, [r0+r6+4]
     IDCT8_ADD_MMX_END   r6  , rsp+8, r3
@@ -357,7 +404,7 @@ cglobal h264_idct8_add4_8, 5, 7 + npicregs, 0, dst, block_offset, block, stride,
 
 INIT_MMX mmxext
 ; ff_h264_idct_add16_mmxext(uint8_t *dst, const int *block_offset,
-;                           DCTELEM *block, int stride, const uint8_t nnzc[6*8])
+;                           int16_t *block, int stride, const uint8_t nnzc[6*8])
 cglobal h264_idct_add16_8, 5, 8 + npicregs, 0, dst1, block_offset, block, stride, nnzc, cntr, coeff, dst2, picreg
     xor          r5, r5
 %ifdef PIC
@@ -373,7 +420,8 @@ cglobal h264_idct_add16_8, 5, 8 + npicregs, 0, dst1, block_offset, block, stride
     movsx        r6, word [r2]
     test         r6, r6
     jz .no_dc
-    DC_ADD_MMXEXT_INIT r2, r3, r6
+    mov   word [r2], 0
+    DC_ADD_MMXEXT_INIT r6, r3
 %if ARCH_X86_64 == 0
 %define dst2q r1
 %define dst2d r1d
@@ -402,7 +450,7 @@ cglobal h264_idct_add16_8, 5, 8 + npicregs, 0, dst1, block_offset, block, stride
 
 INIT_MMX mmx
 ; ff_h264_idct_add16intra_mmx(uint8_t *dst, const int *block_offset,
-;                             DCTELEM *block, int stride, const uint8_t nnzc[6*8])
+;                             int16_t *block, int stride, const uint8_t nnzc[6*8])
 cglobal h264_idct_add16intra_8, 5, 7 + npicregs, 0, dst, block_offset, block, stride, nnzc, cntr, coeff, picreg
     xor          r5, r5
 %ifdef PIC
@@ -426,7 +474,7 @@ cglobal h264_idct_add16intra_8, 5, 7 + npicregs, 0, dst, block_offset, block, st
 
 INIT_MMX mmxext
 ; ff_h264_idct_add16intra_mmxext(uint8_t *dst, const int *block_offset,
-;                                DCTELEM *block, int stride,
+;                                int16_t *block, int stride,
 ;                                const uint8_t nnzc[6*8])
 cglobal h264_idct_add16intra_8, 5, 8 + npicregs, 0, dst1, block_offset, block, stride, nnzc, cntr, coeff, dst2, picreg
     xor          r5, r5
@@ -450,7 +498,8 @@ cglobal h264_idct_add16intra_8, 5, 8 + npicregs, 0, dst1, block_offset, block, s
     movsx        r6, word [r2]
     test         r6, r6
     jz .skipblock
-    DC_ADD_MMXEXT_INIT r2, r3, r6
+    mov   word [r2], 0
+    DC_ADD_MMXEXT_INIT r6, r3
 %if ARCH_X86_64 == 0
 %define dst2q r1
 %define dst2d r1d
@@ -469,7 +518,7 @@ cglobal h264_idct_add16intra_8, 5, 8 + npicregs, 0, dst1, block_offset, block, s
     REP_RET
 
 ; ff_h264_idct8_add4_mmxext(uint8_t *dst, const int *block_offset,
-;                           DCTELEM *block, int stride,
+;                           int16_t *block, int stride,
 ;                           const uint8_t nnzc[6*8])
 cglobal h264_idct8_add4_8, 5, 8 + npicregs, 0, dst1, block_offset, block, stride, nnzc, cntr, coeff, dst2, picreg
     %assign pad 128+4-(stack_offset&7)
@@ -489,7 +538,8 @@ cglobal h264_idct8_add4_8, 5, 8 + npicregs, 0, dst1, block_offset, block, stride
     movsx        r6, word [r2]
     test         r6, r6
     jz .no_dc
-    DC_ADD_MMXEXT_INIT r2, r3, r6
+    mov   word [r2], 0
+    DC_ADD_MMXEXT_INIT r6, r3
 %if ARCH_X86_64 == 0
 %define dst2q r1
 %define dst2d r1d
@@ -515,7 +565,7 @@ cglobal h264_idct8_add4_8, 5, 8 + npicregs, 0, dst1, block_offset, block, stride
     add   word [r2], 32
     IDCT8_ADD_MMX_START r2  , rsp
     IDCT8_ADD_MMX_START r2+8, rsp+64
-    IDCT8_ADD_MMX_END   r6  , rsp,   r3
+    IDCT8_ADD_MMX_END   r6  , rsp,   r3, r2
     mov         r6d, dword [r1+r5*4]
     lea          r6, [r0+r6+4]
     IDCT8_ADD_MMX_END   r6  , rsp+8, r3
@@ -530,7 +580,7 @@ cglobal h264_idct8_add4_8, 5, 8 + npicregs, 0, dst1, block_offset, block, stride
 
 INIT_XMM sse2
 ; ff_h264_idct8_add4_sse2(uint8_t *dst, const int *block_offset,
-;                         DCTELEM *block, int stride, const uint8_t nnzc[6*8])
+;                         int16_t *block, int stride, const uint8_t nnzc[6*8])
 cglobal h264_idct8_add4_8, 5, 8 + npicregs, 10, dst1, block_offset, block, stride, nnzc, cntr, coeff, dst2, picreg
     xor          r5, r5
 %ifdef PIC
@@ -547,7 +597,8 @@ cglobal h264_idct8_add4_8, 5, 8 + npicregs, 10, dst1, block_offset, block, strid
     test         r6, r6
     jz .no_dc
 INIT_MMX cpuname
-    DC_ADD_MMXEXT_INIT r2, r3, r6
+    mov   word [r2], 0
+    DC_ADD_MMXEXT_INIT r6, r3
 %if ARCH_X86_64 == 0
 %define dst2q r1
 %define dst2d r1d
@@ -605,7 +656,7 @@ h264_idct_add8_mmx_plane:
     rep ret
 
 ; ff_h264_idct_add8_mmx(uint8_t **dest, const int *block_offset,
-;                       DCTELEM *block, int stride, const uint8_t nnzc[6*8])
+;                       int16_t *block, int stride, const uint8_t nnzc[6*8])
 cglobal h264_idct_add8_8, 5, 8 + npicregs, 0, dst1, block_offset, block, stride, nnzc, cntr, coeff, dst2, picreg
     mov          r5, 16
     add          r2, 512
@@ -650,7 +701,8 @@ h264_idct_add8_mmxext_plane:
     movsx        r6, word [r2]
     test         r6, r6
     jz .skipblock
-    DC_ADD_MMXEXT_INIT r2, r3, r6
+    mov   word [r2], 0
+    DC_ADD_MMXEXT_INIT r6, r3
 %if ARCH_X86_64
     mov         r0d, dword [r1+r5*4]
     add          r0, [dst2q]
@@ -669,7 +721,7 @@ h264_idct_add8_mmxext_plane:
 
 INIT_MMX mmxext
 ; ff_h264_idct_add8_mmxext(uint8_t **dest, const int *block_offset,
-;                          DCTELEM *block, int stride, const uint8_t nnzc[6*8])
+;                          int16_t *block, int stride, const uint8_t nnzc[6*8])
 cglobal h264_idct_add8_8, 5, 8 + npicregs, 0, dst1, block_offset, block, stride, nnzc, cntr, coeff, dst2, picreg
     mov          r5, 16
     add          r2, 512
@@ -693,7 +745,9 @@ cglobal h264_idct_add8_8, 5, 8 + npicregs, 0, dst1, block_offset, block, stride,
 ; r0 = uint8_t *dst, r2 = int16_t *block, r3 = int stride, r6=clobbered
 h264_idct_dc_add8_mmxext:
     movd         m0, [r2   ]          ;  0 0 X D
+    mov word [r2+ 0], 0
     punpcklwd    m0, [r2+32]          ;  x X d D
+    mov word [r2+32], 0
     paddsw       m0, [pw_32]
     psraw        m0, 6
     punpcklwd    m0, m0               ;  d d D D
@@ -723,6 +777,10 @@ h264_add8x4_idct_sse2:
     paddw m0, [pw_32]
     IDCT4_1D w,0,1,2,3,4,5
     pxor  m7, m7
+    mova [r2+ 0], m7
+    mova [r2+16], m7
+    mova [r2+32], m7
+    mova [r2+48], m7
     STORE_DIFFx2 m0, m1, m4, m5, m7, 6, r0, r3
     lea   r0, [r0+r3*2]
     STORE_DIFFx2 m2, m3, m4, m5, m7, 6, r0, r3
@@ -746,7 +804,7 @@ h264_add8x4_idct_sse2:
 %endmacro
 
 ; ff_h264_idct_add16_sse2(uint8_t *dst, const int *block_offset,
-;                         DCTELEM *block, int stride, const uint8_t nnzc[6*8])
+;                         int16_t *block, int stride, const uint8_t nnzc[6*8])
 cglobal h264_idct_add16_8, 5, 5 + ARCH_X86_64, 8
 %if ARCH_X86_64
     mov         r5, r0
@@ -793,7 +851,7 @@ cglobal h264_idct_add16_8, 5, 5 + ARCH_X86_64, 8
 %endmacro
 
 ; ff_h264_idct_add16intra_sse2(uint8_t *dst, const int *block_offset,
-;                              DCTELEM *block, int stride, const uint8_t nnzc[6*8])
+;                              int16_t *block, int stride, const uint8_t nnzc[6*8])
 cglobal h264_idct_add16intra_8, 5, 7 + ARCH_X86_64, 8
 %if ARCH_X86_64
     mov         r7, r0
@@ -844,7 +902,7 @@ cglobal h264_idct_add16intra_8, 5, 7 + ARCH_X86_64, 8
 %endmacro
 
 ; ff_h264_idct_add8_sse2(uint8_t **dest, const int *block_offset,
-;                        DCTELEM *block, int stride, const uint8_t nnzc[6*8])
+;                        int16_t *block, int stride, const uint8_t nnzc[6*8])
 cglobal h264_idct_add8_8, 5, 7 + ARCH_X86_64, 8
     add          r2, 512
 %if ARCH_X86_64
@@ -861,7 +919,7 @@ cglobal h264_idct_add8_8, 5, 7 + ARCH_X86_64, 8
     add8_sse2_cycle 3, 0x64
     RET
 
-;void ff_h264_luma_dc_dequant_idct_mmx(DCTELEM *output, DCTELEM *input, int qmul)
+;void ff_h264_luma_dc_dequant_idct_mmx(int16_t *output, int16_t *input, int qmul)
 
 %macro WALSH4_1D 5
     SUMSUB_BADC w, %4, %3, %2, %1, %5
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/h264_idct_10bit.asm b/mythtv/external/FFmpeg/libavcodec/x86/h264_idct_10bit.asm
index eb375f94309..88fdb843a60 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/h264_idct_10bit.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/h264_idct_10bit.asm
@@ -66,6 +66,10 @@ SECTION .text
     paddd m0, [pd_32]
     IDCT4_1D d,0,1,2,3,4,5
     pxor  m5, m5
+    mova [%2+ 0], m5
+    mova [%2+16], m5
+    mova [%2+32], m5
+    mova [%2+48], m5
     STORE_DIFFx2 m0, m1, m4, m5, %1, %3
     lea   %1, [%1+%3*2]
     STORE_DIFFx2 m2, m3, m4, m5, %1, %3
@@ -100,6 +104,10 @@ add4x4_idct %+ SUFFIX:
     paddd m0, [pd_32]
     IDCT4_1D d,0,1,2,3,4,5
     pxor  m5, m5
+    mova  [r2+ 0], m5
+    mova  [r2+16], m5
+    mova  [r2+32], m5
+    mova  [r2+48], m5
     STORE_DIFFx2 m0, m1, m4, m5, r5, r3
     lea   r5, [r5+r3*2]
     STORE_DIFFx2 m2, m3, m4, m5, r5, r3
@@ -187,6 +195,7 @@ IDCT_ADD16_10
 INIT_MMX mmxext
 cglobal h264_idct_dc_add_10,3,3
     movd      m0, [r1]
+    mov dword [r1], 0
     paddd     m0, [pd_32]
     psrad     m0, 6
     lea       r1, [r2*3]
@@ -199,11 +208,11 @@ cglobal h264_idct_dc_add_10,3,3
 ; void h264_idct8_dc_add(pixel *dst, dctcoef *block, int stride)
 ;-----------------------------------------------------------------------------
 %macro IDCT8_DC_ADD 0
-cglobal h264_idct8_dc_add_10,3,3,7
-    mov      r1d, [r1]
-    add       r1, 32
-    sar       r1, 6
-    movd      m0, r1d
+cglobal h264_idct8_dc_add_10,3,4,7
+    movd      m0, [r1]
+    mov dword[r1], 0
+    paddd     m0, [pd_32]
+    psrad     m0, 6
     lea       r1, [r2*3]
     SPLATW    m0, m0, 0
     mova      m6, [pw_pixel_max]
@@ -255,6 +264,8 @@ idct_dc_add %+ SUFFIX:
     add       r5, r0
     movq      m0, [r2+ 0]
     movhps    m0, [r2+64]
+    mov dword [r2+ 0], 0
+    mov dword [r2+64], 0
     paddd     m0, [pd_32]
     psrad     m0, 6
     pshufhw   m0, m0, 0
@@ -473,6 +484,22 @@ h264_idct8_add1_10 %+ SUFFIX:
     packssdw      m8, m0
     paddsw        m8, [r0]
     pxor          m0, m0
+    mova    [r1+  0], m0
+    mova    [r1+ 16], m0
+    mova    [r1+ 32], m0
+    mova    [r1+ 48], m0
+    mova    [r1+ 64], m0
+    mova    [r1+ 80], m0
+    mova    [r1+ 96], m0
+    mova    [r1+112], m0
+    mova    [r1+128], m0
+    mova    [r1+144], m0
+    mova    [r1+160], m0
+    mova    [r1+176], m0
+    mova    [r1+192], m0
+    mova    [r1+208], m0
+    mova    [r1+224], m0
+    mova    [r1+240], m0
     CLIPW         m8, m0, [pw_pixel_max]
     mova        [r0], m8
     mova          m8, [pw_pixel_max]
@@ -492,6 +519,22 @@ h264_idct8_add1_10 %+ SUFFIX:
     lea           r3, [r0+8]
     IDCT8_ADD_SSE_END r0, rsp,    r2
     IDCT8_ADD_SSE_END r3, rsp+16, r2
+    mova    [r1+  0], m7
+    mova    [r1+ 16], m7
+    mova    [r1+ 32], m7
+    mova    [r1+ 48], m7
+    mova    [r1+ 64], m7
+    mova    [r1+ 80], m7
+    mova    [r1+ 96], m7
+    mova    [r1+112], m7
+    mova    [r1+128], m7
+    mova    [r1+144], m7
+    mova    [r1+160], m7
+    mova    [r1+176], m7
+    mova    [r1+192], m7
+    mova    [r1+208], m7
+    mova    [r1+224], m7
+    mova    [r1+240], m7
 %endif ; ARCH_X86_64
 
     add          rsp, pad
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/h264_intrapred_init.c b/mythtv/external/FFmpeg/libavcodec/x86/h264_intrapred_init.c
index deededaddbe..f5b5e3ef39b 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/h264_intrapred_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/h264_intrapred_init.c
@@ -18,8 +18,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/cpu.h"
+#include "libavcodec/avcodec.h"
 #include "libavcodec/h264pred.h"
 
 #define PRED4x4(TYPE, DEPTH, OPT) \
@@ -179,7 +181,9 @@ PRED4x4(tm_vp8, 8, mmxext)
 PRED4x4(tm_vp8, 8, ssse3)
 PRED4x4(vertical_vp8, 8, mmxext)
 
-void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc)
+av_cold void ff_h264_pred_init_x86(H264PredContext *h, int codec_id,
+                                   const int bit_depth,
+                                   const int chroma_format_idc)
 {
     int mm_flags = av_get_cpu_flags();
 
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/h264_qpel.c b/mythtv/external/FFmpeg/libavcodec/x86/h264_qpel.c
index 171ef2aa02d..c1e7fb72699 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/h264_qpel.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/h264_qpel.c
@@ -19,9 +19,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
-#include "libavcodec/dsputil.h"
+#include "libavutil/x86/cpu.h"
+#include "libavcodec/h264qpel.h"
 #include "libavcodec/mpegvideo.h"
 #include "dsputil_mmx.h"
 
@@ -29,7 +31,6 @@
 void ff_put_pixels4_mmxext(uint8_t *block, const uint8_t *pixels, int line_size, int h);
 void ff_avg_pixels4_mmxext(uint8_t *block, const uint8_t *pixels, int line_size, int h);
 void ff_put_pixels8_mmxext(uint8_t *block, const uint8_t *pixels, int line_size, int h);
-void ff_avg_pixels8_mmxext(uint8_t *block, const uint8_t *pixels, int line_size, int h);
 static void ff_put_pixels16_mmxext(uint8_t *block, const uint8_t *pixels,
                                    int line_size, int h)
 {
@@ -490,3 +491,134 @@ QPEL16(mmxext)
 #endif
 
 #endif /* HAVE_YASM */
+
+#define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX)                          \
+    do {                                                                     \
+    c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
+    c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
+    } while (0)
+
+#define H264_QPEL_FUNCS(x, y, CPU)                                                            \
+    do {                                                                                      \
+        c->put_h264_qpel_pixels_tab[0][x + y * 4] = put_h264_qpel16_mc ## x ## y ## _ ## CPU; \
+        c->put_h264_qpel_pixels_tab[1][x + y * 4] = put_h264_qpel8_mc  ## x ## y ## _ ## CPU; \
+        c->avg_h264_qpel_pixels_tab[0][x + y * 4] = avg_h264_qpel16_mc ## x ## y ## _ ## CPU; \
+        c->avg_h264_qpel_pixels_tab[1][x + y * 4] = avg_h264_qpel8_mc  ## x ## y ## _ ## CPU; \
+    } while (0)
+
+#define H264_QPEL_FUNCS_10(x, y, CPU)                                                               \
+    do {                                                                                            \
+        c->put_h264_qpel_pixels_tab[0][x + y * 4] = ff_put_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \
+        c->put_h264_qpel_pixels_tab[1][x + y * 4] = ff_put_h264_qpel8_mc  ## x ## y ## _10_ ## CPU; \
+        c->avg_h264_qpel_pixels_tab[0][x + y * 4] = ff_avg_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \
+        c->avg_h264_qpel_pixels_tab[1][x + y * 4] = ff_avg_h264_qpel8_mc  ## x ## y ## _10_ ## CPU; \
+    } while (0)
+
+av_cold void ff_h264qpel_init_x86(H264QpelContext *c, int bit_depth)
+{
+#if HAVE_YASM
+    int high_bit_depth = bit_depth > 8;
+    int mm_flags = av_get_cpu_flags();
+
+    if (EXTERNAL_MMXEXT(mm_flags)) {
+        if (!high_bit_depth) {
+            SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmxext, );
+            SET_QPEL_FUNCS(put_h264_qpel, 1,  8, mmxext, );
+            SET_QPEL_FUNCS(put_h264_qpel, 2,  4, mmxext, );
+            SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmxext, );
+            SET_QPEL_FUNCS(avg_h264_qpel, 1,  8, mmxext, );
+            SET_QPEL_FUNCS(avg_h264_qpel, 2,  4, mmxext, );
+        } else if (bit_depth == 10) {
+#if ARCH_X86_32
+            SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_mmxext, ff_);
+            SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_mmxext, ff_);
+            SET_QPEL_FUNCS(put_h264_qpel, 1,  8, 10_mmxext, ff_);
+            SET_QPEL_FUNCS(avg_h264_qpel, 1,  8, 10_mmxext, ff_);
+#endif
+            SET_QPEL_FUNCS(put_h264_qpel, 2, 4,  10_mmxext, ff_);
+            SET_QPEL_FUNCS(avg_h264_qpel, 2, 4,  10_mmxext, ff_);
+        }
+    }
+
+    if (EXTERNAL_SSE2(mm_flags)) {
+        if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW) && !high_bit_depth) {
+            // these functions are slower than mmx on AMD, but faster on Intel
+            H264_QPEL_FUNCS(0, 0, sse2);
+        }
+
+        if (!high_bit_depth) {
+            H264_QPEL_FUNCS(0, 1, sse2);
+            H264_QPEL_FUNCS(0, 2, sse2);
+            H264_QPEL_FUNCS(0, 3, sse2);
+            H264_QPEL_FUNCS(1, 1, sse2);
+            H264_QPEL_FUNCS(1, 2, sse2);
+            H264_QPEL_FUNCS(1, 3, sse2);
+            H264_QPEL_FUNCS(2, 1, sse2);
+            H264_QPEL_FUNCS(2, 2, sse2);
+            H264_QPEL_FUNCS(2, 3, sse2);
+            H264_QPEL_FUNCS(3, 1, sse2);
+            H264_QPEL_FUNCS(3, 2, sse2);
+            H264_QPEL_FUNCS(3, 3, sse2);
+        }
+
+        if (bit_depth == 10) {
+            SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_sse2, ff_);
+            SET_QPEL_FUNCS(put_h264_qpel, 1,  8, 10_sse2, ff_);
+            SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_sse2, ff_);
+            SET_QPEL_FUNCS(avg_h264_qpel, 1,  8, 10_sse2, ff_);
+            H264_QPEL_FUNCS_10(1, 0, sse2_cache64);
+            H264_QPEL_FUNCS_10(2, 0, sse2_cache64);
+            H264_QPEL_FUNCS_10(3, 0, sse2_cache64);
+        }
+    }
+
+    if (EXTERNAL_SSSE3(mm_flags)) {
+        if (!high_bit_depth) {
+            H264_QPEL_FUNCS(1, 0, ssse3);
+            H264_QPEL_FUNCS(1, 1, ssse3);
+            H264_QPEL_FUNCS(1, 2, ssse3);
+            H264_QPEL_FUNCS(1, 3, ssse3);
+            H264_QPEL_FUNCS(2, 0, ssse3);
+            H264_QPEL_FUNCS(2, 1, ssse3);
+            H264_QPEL_FUNCS(2, 2, ssse3);
+            H264_QPEL_FUNCS(2, 3, ssse3);
+            H264_QPEL_FUNCS(3, 0, ssse3);
+            H264_QPEL_FUNCS(3, 1, ssse3);
+            H264_QPEL_FUNCS(3, 2, ssse3);
+            H264_QPEL_FUNCS(3, 3, ssse3);
+        }
+
+        if (bit_depth == 10) {
+            H264_QPEL_FUNCS_10(1, 0, ssse3_cache64);
+            H264_QPEL_FUNCS_10(2, 0, ssse3_cache64);
+            H264_QPEL_FUNCS_10(3, 0, ssse3_cache64);
+        }
+    }
+
+    if (EXTERNAL_AVX(mm_flags)) {
+        /* AVX implies 64 byte cache lines without the need to avoid unaligned
+         * memory accesses that cross the boundary between two cache lines.
+         * TODO: Port X264_CPU_CACHELINE_32/64 detection from x264 to avoid
+         * having to treat SSE2 functions with such properties as AVX. */
+        if (bit_depth == 10) {
+            H264_QPEL_FUNCS_10(1, 0, sse2);
+            H264_QPEL_FUNCS_10(2, 0, sse2);
+            H264_QPEL_FUNCS_10(3, 0, sse2);
+        }
+    }
+#endif
+}
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/h264chroma_init.c b/mythtv/external/FFmpeg/libavcodec/x86/h264chroma_init.c
new file mode 100644
index 00000000000..b5c078f732d
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/x86/h264chroma_init.c
@@ -0,0 +1,118 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "config.h"
+#include "libavutil/cpu.h"
+#include "libavutil/x86/cpu.h"
+#include "libavcodec/h264chroma.h"
+
+void ff_put_h264_chroma_mc8_rnd_mmx  (uint8_t *dst, uint8_t *src,
+                                      int stride, int h, int x, int y);
+void ff_avg_h264_chroma_mc8_rnd_mmxext(uint8_t *dst, uint8_t *src,
+                                       int stride, int h, int x, int y);
+void ff_avg_h264_chroma_mc8_rnd_3dnow(uint8_t *dst, uint8_t *src,
+                                      int stride, int h, int x, int y);
+
+void ff_put_h264_chroma_mc4_mmx      (uint8_t *dst, uint8_t *src,
+                                      int stride, int h, int x, int y);
+void ff_avg_h264_chroma_mc4_mmxext   (uint8_t *dst, uint8_t *src,
+                                      int stride, int h, int x, int y);
+void ff_avg_h264_chroma_mc4_3dnow    (uint8_t *dst, uint8_t *src,
+                                      int stride, int h, int x, int y);
+
+void ff_put_h264_chroma_mc2_mmxext   (uint8_t *dst, uint8_t *src,
+                                      int stride, int h, int x, int y);
+void ff_avg_h264_chroma_mc2_mmxext   (uint8_t *dst, uint8_t *src,
+                                      int stride, int h, int x, int y);
+
+void ff_put_h264_chroma_mc8_rnd_ssse3(uint8_t *dst, uint8_t *src,
+                                      int stride, int h, int x, int y);
+void ff_put_h264_chroma_mc4_ssse3    (uint8_t *dst, uint8_t *src,
+                                      int stride, int h, int x, int y);
+
+void ff_avg_h264_chroma_mc8_rnd_ssse3(uint8_t *dst, uint8_t *src,
+                                      int stride, int h, int x, int y);
+void ff_avg_h264_chroma_mc4_ssse3    (uint8_t *dst, uint8_t *src,
+                                      int stride, int h, int x, int y);
+
+#define CHROMA_MC(OP, NUM, DEPTH, OPT)                                  \
+void ff_ ## OP ## _h264_chroma_mc ## NUM ## _ ## DEPTH ## _ ## OPT      \
+                                      (uint8_t *dst, uint8_t *src,      \
+                                       int stride, int h, int x, int y);
+
+CHROMA_MC(put, 2, 10, mmxext)
+CHROMA_MC(avg, 2, 10, mmxext)
+CHROMA_MC(put, 4, 10, mmxext)
+CHROMA_MC(avg, 4, 10, mmxext)
+CHROMA_MC(put, 8, 10, sse2)
+CHROMA_MC(avg, 8, 10, sse2)
+CHROMA_MC(put, 8, 10, avx)
+CHROMA_MC(avg, 8, 10, avx)
+
+void ff_h264chroma_init_x86(H264ChromaContext *c, int bit_depth)
+{
+#if HAVE_YASM
+    int high_bit_depth = bit_depth > 8;
+    int mm_flags       = av_get_cpu_flags();
+
+    if (EXTERNAL_MMX(mm_flags) && !high_bit_depth) {
+        c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_rnd_mmx;
+        c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_mmx;
+    }
+
+    if (EXTERNAL_AMD3DNOW(mm_flags) && !high_bit_depth) {
+        c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_3dnow;
+        c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_3dnow;
+    }
+
+    if (EXTERNAL_MMXEXT(mm_flags) && !high_bit_depth) {
+        c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_mmxext;
+        c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_mmxext;
+        c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_mmxext;
+        c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_mmxext;
+    }
+
+    if (EXTERNAL_MMXEXT(mm_flags) && bit_depth > 8 && bit_depth <= 10) {
+        c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_10_mmxext;
+        c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_10_mmxext;
+        c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_10_mmxext;
+        c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_10_mmxext;
+    }
+
+    if (EXTERNAL_SSE2(mm_flags) && bit_depth > 8 && bit_depth <= 10) {
+        c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_sse2;
+        c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_sse2;
+    }
+
+    if (EXTERNAL_SSSE3(mm_flags) && !high_bit_depth) {
+        c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_rnd_ssse3;
+        c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_ssse3;
+        c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_ssse3;
+        c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_ssse3;
+    }
+
+    if (EXTERNAL_AVX(mm_flags) && bit_depth > 8 && bit_depth <= 10) {
+        // AVX implies !cache64.
+        // TODO: Port cache(32|64) detection from x264.
+        c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_avx;
+        c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_avx;
+    }
+#endif
+}
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/h264dsp_init.c b/mythtv/external/FFmpeg/libavcodec/x86/h264dsp_init.c
index 65d300fe4d4..11aae77d233 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/h264dsp_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/h264dsp_init.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
@@ -48,7 +49,7 @@ IDCT_ADD_FUNC(8, 10, avx)
 #define IDCT_ADD_REP_FUNC(NUM, REP, DEPTH, OPT)                         \
 void ff_h264_idct ## NUM ## _add ## REP ## _ ## DEPTH ## _ ## OPT       \
     (uint8_t *dst, const int *block_offset,                             \
-     DCTELEM *block, int stride, const uint8_t nnzc[6 * 8]);
+     int16_t *block, int stride, const uint8_t nnzc[6 * 8]);
 
 IDCT_ADD_REP_FUNC(8, 4, 8, mmx)
 IDCT_ADD_REP_FUNC(8, 4, 8, mmxext)
@@ -70,7 +71,7 @@ IDCT_ADD_REP_FUNC(, 16intra, 10, avx)
 #define IDCT_ADD_REP_FUNC2(NUM, REP, DEPTH, OPT)                      \
 void ff_h264_idct ## NUM ## _add ## REP ## _ ## DEPTH ## _ ## OPT     \
     (uint8_t **dst, const int *block_offset,                          \
-     DCTELEM *block, int stride, const uint8_t nnzc[6 * 8]);
+     int16_t *block, int stride, const uint8_t nnzc[6 * 8]);
 
 IDCT_ADD_REP_FUNC2(, 8, 8, mmx)
 IDCT_ADD_REP_FUNC2(, 8, 8, mmxext)
@@ -78,8 +79,8 @@ IDCT_ADD_REP_FUNC2(, 8, 8, sse2)
 IDCT_ADD_REP_FUNC2(, 8, 10, sse2)
 IDCT_ADD_REP_FUNC2(, 8, 10, avx)
 
-void ff_h264_luma_dc_dequant_idct_mmx(DCTELEM *output, DCTELEM *input, int qmul);
-void ff_h264_luma_dc_dequant_idct_sse2(DCTELEM *output, DCTELEM *input, int qmul);
+void ff_h264_luma_dc_dequant_idct_mmx(int16_t *output, int16_t *input, int qmul);
+void ff_h264_luma_dc_dequant_idct_sse2(int16_t *output, int16_t *input, int qmul);
 
 /***********************************/
 /* deblocking */
@@ -207,8 +208,8 @@ H264_BIWEIGHT_10_SSE(16, 10)
 H264_BIWEIGHT_10_SSE(8,  10)
 H264_BIWEIGHT_10_SSE(4,  10)
 
-void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
-                         const int chroma_format_idc)
+av_cold void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
+                                 const int chroma_format_idc)
 {
 #if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/hpeldsp.asm b/mythtv/external/FFmpeg/libavcodec/x86/hpeldsp.asm
new file mode 100644
index 00000000000..c83c38870b5
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/x86/hpeldsp.asm
@@ -0,0 +1,502 @@
+;******************************************************************************
+;*
+;* Copyright (c) 2000-2001 Fabrice Bellard 
+;* Copyright (c)      Nick Kurshev 
+;* Copyright (c) 2002 Michael Niedermayer 
+;* Copyright (c) 2002 Zdenek Kabelac 
+;* Copyright (c) 2013 Daniel Kang
+;*
+;* MMX optimized hpel functions
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg is free software; you can redistribute it and/or
+;* modify it under the terms of the GNU Lesser General Public
+;* License as published by the Free Software Foundation; either
+;* version 2.1 of the License, or (at your option) any later version.
+;*
+;* FFmpeg is distributed in the hope that it will be useful,
+;* but WITHOUT ANY WARRANTY; without even the implied warranty of
+;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;* Lesser General Public License for more details.
+;*
+;* You should have received a copy of the GNU Lesser General Public
+;* License along with FFmpeg; if not, write to the Free Software
+;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;******************************************************************************
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+cextern pb_1
+
+SECTION_TEXT
+
+; put_pixels8_x2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+%macro PUT_PIXELS8_X2 0
+cglobal put_pixels8_x2, 4,5
+    lea          r4, [r2*2]
+.loop:
+    mova         m0, [r1]
+    mova         m1, [r1+r2]
+    PAVGB        m0, [r1+1]
+    PAVGB        m1, [r1+r2+1]
+    mova       [r0], m0
+    mova    [r0+r2], m1
+    add          r1, r4
+    add          r0, r4
+    mova         m0, [r1]
+    mova         m1, [r1+r2]
+    PAVGB        m0, [r1+1]
+    PAVGB        m1, [r1+r2+1]
+    add          r1, r4
+    mova       [r0], m0
+    mova    [r0+r2], m1
+    add          r0, r4
+    sub         r3d, 4
+    jne .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+PUT_PIXELS8_X2
+INIT_MMX 3dnow
+PUT_PIXELS8_X2
+
+
+; put_pixels16_x2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+%macro PUT_PIXELS_16 0
+cglobal put_pixels16_x2, 4,5
+    lea          r4, [r2*2]
+.loop:
+    mova         m0, [r1]
+    mova         m1, [r1+r2]
+    mova         m2, [r1+8]
+    mova         m3, [r1+r2+8]
+    PAVGB        m0, [r1+1]
+    PAVGB        m1, [r1+r2+1]
+    PAVGB        m2, [r1+9]
+    PAVGB        m3, [r1+r2+9]
+    mova       [r0], m0
+    mova    [r0+r2], m1
+    mova     [r0+8], m2
+    mova  [r0+r2+8], m3
+    add          r1, r4
+    add          r0, r4
+    mova         m0, [r1]
+    mova         m1, [r1+r2]
+    mova         m2, [r1+8]
+    mova         m3, [r1+r2+8]
+    PAVGB        m0, [r1+1]
+    PAVGB        m1, [r1+r2+1]
+    PAVGB        m2, [r1+9]
+    PAVGB        m3, [r1+r2+9]
+    add          r1, r4
+    mova       [r0], m0
+    mova    [r0+r2], m1
+    mova     [r0+8], m2
+    mova  [r0+r2+8], m3
+    add          r0, r4
+    sub         r3d, 4
+    jne .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+PUT_PIXELS_16
+INIT_MMX 3dnow
+PUT_PIXELS_16
+
+
+; put_no_rnd_pixels8_x2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+%macro PUT_NO_RND_PIXELS8_X2 0
+cglobal put_no_rnd_pixels8_x2, 4,5
+    mova         m6, [pb_1]
+    lea          r4, [r2*2]
+.loop:
+    mova         m0, [r1]
+    mova         m2, [r1+r2]
+    mova         m1, [r1+1]
+    mova         m3, [r1+r2+1]
+    add          r1, r4
+    psubusb      m0, m6
+    psubusb      m2, m6
+    PAVGB        m0, m1
+    PAVGB        m2, m3
+    mova       [r0], m0
+    mova    [r0+r2], m2
+    mova         m0, [r1]
+    mova         m1, [r1+1]
+    mova         m2, [r1+r2]
+    mova         m3, [r1+r2+1]
+    add          r0, r4
+    add          r1, r4
+    psubusb      m0, m6
+    psubusb      m2, m6
+    PAVGB        m0, m1
+    PAVGB        m2, m3
+    mova       [r0], m0
+    mova    [r0+r2], m2
+    add          r0, r4
+    sub         r3d, 4
+    jne .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+PUT_NO_RND_PIXELS8_X2
+INIT_MMX 3dnow
+PUT_NO_RND_PIXELS8_X2
+
+
+; put_no_rnd_pixels8_x2_exact(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+%macro PUT_NO_RND_PIXELS8_X2_EXACT 0
+cglobal put_no_rnd_pixels8_x2_exact, 4,5
+    lea          r4, [r2*3]
+    pcmpeqb      m6, m6
+.loop:
+    mova         m0, [r1]
+    mova         m2, [r1+r2]
+    mova         m1, [r1+1]
+    mova         m3, [r1+r2+1]
+    pxor         m0, m6
+    pxor         m2, m6
+    pxor         m1, m6
+    pxor         m3, m6
+    PAVGB        m0, m1
+    PAVGB        m2, m3
+    pxor         m0, m6
+    pxor         m2, m6
+    mova       [r0], m0
+    mova    [r0+r2], m2
+    mova         m0, [r1+r2*2]
+    mova         m1, [r1+r2*2+1]
+    mova         m2, [r1+r4]
+    mova         m3, [r1+r4+1]
+    pxor         m0, m6
+    pxor         m1, m6
+    pxor         m2, m6
+    pxor         m3, m6
+    PAVGB        m0, m1
+    PAVGB        m2, m3
+    pxor         m0, m6
+    pxor         m2, m6
+    mova  [r0+r2*2], m0
+    mova    [r0+r4], m2
+    lea          r1, [r1+r2*4]
+    lea          r0, [r0+r2*4]
+    sub         r3d, 4
+    jg .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+PUT_NO_RND_PIXELS8_X2_EXACT
+INIT_MMX 3dnow
+PUT_NO_RND_PIXELS8_X2_EXACT
+
+
+; put_pixels8_y2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+%macro PUT_PIXELS8_Y2 0
+cglobal put_pixels8_y2, 4,5
+    lea          r4, [r2*2]
+    mova         m0, [r1]
+    sub          r0, r2
+.loop:
+    mova         m1, [r1+r2]
+    mova         m2, [r1+r4]
+    add          r1, r4
+    PAVGB        m0, m1
+    PAVGB        m1, m2
+    mova    [r0+r2], m0
+    mova    [r0+r4], m1
+    mova         m1, [r1+r2]
+    mova         m0, [r1+r4]
+    add          r0, r4
+    add          r1, r4
+    PAVGB        m2, m1
+    PAVGB        m1, m0
+    mova    [r0+r2], m2
+    mova    [r0+r4], m1
+    add          r0, r4
+    sub         r3d, 4
+    jne .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+PUT_PIXELS8_Y2
+INIT_MMX 3dnow
+PUT_PIXELS8_Y2
+
+
+; put_no_rnd_pixels8_y2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+%macro PUT_NO_RND_PIXELS8_Y2 0
+cglobal put_no_rnd_pixels8_y2, 4,5
+    mova         m6, [pb_1]
+    lea          r4, [r2+r2]
+    mova         m0, [r1]
+    sub          r0, r2
+.loop:
+    mova         m1, [r1+r2]
+    mova         m2, [r1+r4]
+    add          r1, r4
+    psubusb      m1, m6
+    PAVGB        m0, m1
+    PAVGB        m1, m2
+    mova    [r0+r2], m0
+    mova    [r0+r4], m1
+    mova         m1, [r1+r2]
+    mova         m0, [r1+r4]
+    add          r0, r4
+    add          r1, r4
+    psubusb      m1, m6
+    PAVGB        m2, m1
+    PAVGB        m1, m0
+    mova    [r0+r2], m2
+    mova    [r0+r4], m1
+    add          r0, r4
+    sub         r3d, 4
+    jne .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+PUT_NO_RND_PIXELS8_Y2
+INIT_MMX 3dnow
+PUT_NO_RND_PIXELS8_Y2
+
+
+; put_no_rnd_pixels8_y2_exact(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+%macro PUT_NO_RND_PIXELS8_Y2_EXACT 0
+cglobal put_no_rnd_pixels8_y2_exact, 4,5
+    lea          r4, [r2*3]
+    mova         m0, [r1]
+    pcmpeqb      m6, m6
+    add          r1, r2
+    pxor         m0, m6
+.loop:
+    mova         m1, [r1]
+    mova         m2, [r1+r2]
+    pxor         m1, m6
+    pxor         m2, m6
+    PAVGB        m0, m1
+    PAVGB        m1, m2
+    pxor         m0, m6
+    pxor         m1, m6
+    mova       [r0], m0
+    mova    [r0+r2], m1
+    mova         m1, [r1+r2*2]
+    mova         m0, [r1+r4]
+    pxor         m1, m6
+    pxor         m0, m6
+    PAVGB        m2, m1
+    PAVGB        m1, m0
+    pxor         m2, m6
+    pxor         m1, m6
+    mova  [r0+r2*2], m2
+    mova    [r0+r4], m1
+    lea          r1, [r1+r2*4]
+    lea          r0, [r0+r2*4]
+    sub         r3d, 4
+    jg .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+PUT_NO_RND_PIXELS8_Y2_EXACT
+INIT_MMX 3dnow
+PUT_NO_RND_PIXELS8_Y2_EXACT
+
+
+; avg_pixels8(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+%macro AVG_PIXELS8 0
+cglobal avg_pixels8, 4,5
+    lea          r4, [r2*2]
+.loop:
+    mova         m0, [r0]
+    mova         m1, [r0+r2]
+    PAVGB        m0, [r1]
+    PAVGB        m1, [r1+r2]
+    mova       [r0], m0
+    mova    [r0+r2], m1
+    add          r1, r4
+    add          r0, r4
+    mova         m0, [r0]
+    mova         m1, [r0+r2]
+    PAVGB        m0, [r1]
+    PAVGB        m1, [r1+r2]
+    add          r1, r4
+    mova       [r0], m0
+    mova    [r0+r2], m1
+    add          r0, r4
+    sub         r3d, 4
+    jne .loop
+    REP_RET
+%endmacro
+
+INIT_MMX 3dnow
+AVG_PIXELS8
+
+
+; avg_pixels8_x2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+%macro AVG_PIXELS8_X2 0
+cglobal avg_pixels8_x2, 4,5
+    lea          r4, [r2*2]
+.loop:
+    mova         m0, [r1]
+    mova         m2, [r1+r2]
+    PAVGB        m0, [r1+1]
+    PAVGB        m2, [r1+r2+1]
+    PAVGB        m0, [r0]
+    PAVGB        m2, [r0+r2]
+    add          r1, r4
+    mova       [r0], m0
+    mova    [r0+r2], m2
+    mova         m0, [r1]
+    mova         m2, [r1+r2]
+    PAVGB        m0, [r1+1]
+    PAVGB        m2, [r1+r2+1]
+    add          r0, r4
+    add          r1, r4
+    PAVGB        m0, [r0]
+    PAVGB        m2, [r0+r2]
+    mova       [r0], m0
+    mova    [r0+r2], m2
+    add          r0, r4
+    sub         r3d, 4
+    jne .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+AVG_PIXELS8_X2
+INIT_MMX 3dnow
+AVG_PIXELS8_X2
+
+
+; avg_pixels8_y2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+%macro AVG_PIXELS8_Y2 0
+cglobal avg_pixels8_y2, 4,5
+    lea          r4, [r2*2]
+    mova         m0, [r1]
+    sub          r0, r2
+.loop:
+    mova         m1, [r1+r2]
+    mova         m2, [r1+r4]
+    add          r1, r4
+    PAVGB        m0, m1
+    PAVGB        m1, m2
+    mova         m3, [r0+r2]
+    mova         m4, [r0+r4]
+    PAVGB        m0, m3
+    PAVGB        m1, m4
+    mova    [r0+r2], m0
+    mova    [r0+r4], m1
+    mova         m1, [r1+r2]
+    mova         m0, [r1+r4]
+    PAVGB        m2, m1
+    PAVGB        m1, m0
+    add          r0, r4
+    add          r1, r4
+    mova         m3, [r0+r2]
+    mova         m4, [r0+r4]
+    PAVGB        m2, m3
+    PAVGB        m1, m4
+    mova    [r0+r2], m2
+    mova    [r0+r4], m1
+    add          r0, r4
+    sub         r3d, 4
+    jne .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+AVG_PIXELS8_Y2
+INIT_MMX 3dnow
+AVG_PIXELS8_Y2
+
+
+; avg_pixels8_xy2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+%macro AVG_PIXELS8_XY2 0
+cglobal avg_pixels8_xy2, 4,5
+    mova         m6, [pb_1]
+    lea          r4, [r2*2]
+    mova         m0, [r1]
+    pavgb        m0, [r1+1]
+.loop:
+    mova         m2, [r1+r4]
+    mova         m1, [r1+r2]
+    psubusb      m2, m6
+    pavgb        m1, [r1+r2+1]
+    pavgb        m2, [r1+r4+1]
+    add          r1, r4
+    pavgb        m0, m1
+    pavgb        m1, m2
+    pavgb        m0, [r0]
+    pavgb        m1, [r0+r2]
+    mova       [r0], m0
+    mova    [r0+r2], m1
+    mova         m1, [r1+r2]
+    mova         m0, [r1+r4]
+    pavgb        m1, [r1+r2+1]
+    pavgb        m0, [r1+r4+1]
+    add          r0, r4
+    add          r1, r4
+    pavgb        m2, m1
+    pavgb        m1, m0
+    pavgb        m2, [r0]
+    pavgb        m1, [r0+r2]
+    mova       [r0], m2
+    mova    [r0+r2], m1
+    add          r0, r4
+    sub         r3d, 4
+    jne .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+AVG_PIXELS8_XY2
+INIT_MMX 3dnow
+AVG_PIXELS8_XY2
+
+INIT_XMM sse2
+; void put_pixels16_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+cglobal put_pixels16, 4,5,4
+    lea          r4, [r2*3]
+.loop:
+    movu         m0, [r1]
+    movu         m1, [r1+r2]
+    movu         m2, [r1+r2*2]
+    movu         m3, [r1+r4]
+    lea          r1, [r1+r2*4]
+    mova       [r0], m0
+    mova    [r0+r2], m1
+    mova  [r0+r2*2], m2
+    mova    [r0+r4], m3
+    sub         r3d, 4
+    lea          r0, [r0+r2*4]
+    jnz       .loop
+    REP_RET
+
+; void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
+cglobal avg_pixels16, 4,5,4
+    lea          r4, [r2*3]
+.loop:
+    movu         m0, [r1]
+    movu         m1, [r1+r2]
+    movu         m2, [r1+r2*2]
+    movu         m3, [r1+r4]
+    lea          r1, [r1+r2*4]
+    pavgb        m0, [r0]
+    pavgb        m1, [r0+r2]
+    pavgb        m2, [r0+r2*2]
+    pavgb        m3, [r0+r4]
+    mova       [r0], m0
+    mova    [r0+r2], m1
+    mova  [r0+r2*2], m2
+    mova    [r0+r4], m3
+    sub         r3d, 4
+    lea          r0, [r0+r2*4]
+    jnz       .loop
+    REP_RET
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/idct_mmx_xvid.c b/mythtv/external/FFmpeg/libavcodec/x86/idct_mmx_xvid.c
index b62865e679c..5e9f4054523 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/idct_mmx_xvid.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/idct_mmx_xvid.c
@@ -531,25 +531,25 @@ __asm__ volatile(
     :: "r"(block), "r"(rounder_0), "r"(tab_i_04_xmm), "r"(tg_1_16));
 }
 
-void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
+void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, int16_t *block)
 {
     ff_idct_xvid_mmx(block);
     ff_put_pixels_clamped_mmx(block, dest, line_size);
 }
 
-void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
+void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, int16_t *block)
 {
     ff_idct_xvid_mmx(block);
     ff_add_pixels_clamped_mmx(block, dest, line_size);
 }
 
-void ff_idct_xvid_mmxext_put(uint8_t *dest, int line_size, DCTELEM *block)
+void ff_idct_xvid_mmxext_put(uint8_t *dest, int line_size, int16_t *block)
 {
     ff_idct_xvid_mmxext(block);
     ff_put_pixels_clamped_mmx(block, dest, line_size);
 }
 
-void ff_idct_xvid_mmxext_add(uint8_t *dest, int line_size, DCTELEM *block)
+void ff_idct_xvid_mmxext_add(uint8_t *dest, int line_size, int16_t *block)
 {
     ff_idct_xvid_mmxext(block);
     ff_add_pixels_clamped_mmx(block, dest, line_size);
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/idct_sse2_xvid.c b/mythtv/external/FFmpeg/libavcodec/x86/idct_sse2_xvid.c
index d121b250312..b51466cba09 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/idct_sse2_xvid.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/idct_sse2_xvid.c
@@ -38,7 +38,6 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavcodec/dsputil.h"
 #include "libavutil/mem.h"
 #include "libavutil/x86/asm.h"
 #include "idct_xvid.h"
@@ -376,7 +375,7 @@ inline void ff_idct_xvid_sse2(short *block)
     JZ("%%esi", "1f")
     "5:                                                          \n\t"
     iMTX_MULT("7*16(%0)", MANGLE(iTab2), ROUND(walkenIdctRounders+5*16), PUT_ODD(ROW7))
-#if !ARCH_X86_64
+#if ARCH_X86_32
     iLLM_HEAD
 #endif
     iLLM_PASS("%0")
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/idct_xvid.h b/mythtv/external/FFmpeg/libavcodec/x86/idct_xvid.h
index a584fba3776..7a2847b864f 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/idct_xvid.h
+++ b/mythtv/external/FFmpeg/libavcodec/x86/idct_xvid.h
@@ -28,15 +28,13 @@
 
 #include 
 
-#include "libavcodec/dsputil.h"
-
 void ff_idct_xvid_mmx(short *block);
-void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block);
-void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, int16_t *block);
+void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, int16_t *block);
 
 void ff_idct_xvid_mmxext(short *block);
-void ff_idct_xvid_mmxext_put(uint8_t *dest, int line_size, DCTELEM *block);
-void ff_idct_xvid_mmxext_add(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_idct_xvid_mmxext_put(uint8_t *dest, int line_size, int16_t *block);
+void ff_idct_xvid_mmxext_add(uint8_t *dest, int line_size, int16_t *block);
 
 void ff_idct_xvid_sse2(short *block);
 void ff_idct_xvid_sse2_put(uint8_t *dest, int line_size, short *block);
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/lpc.c b/mythtv/external/FFmpeg/libavcodec/x86/lpc.c
index a66f1e0da01..19622123e0e 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/lpc.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/lpc.c
@@ -20,6 +20,7 @@
  */
 
 #include "libavutil/x86/asm.h"
+#include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavcodec/lpc.h"
 
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/mlpdsp.c b/mythtv/external/FFmpeg/libavcodec/x86/mlpdsp.c
index de28e22b52b..81cab5a5e9d 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/mlpdsp.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/mlpdsp.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/x86/asm.h"
 #include "libavcodec/mlpdsp.h"
 #include "libavcodec/mlp.h"
@@ -173,7 +174,7 @@ static void mlp_filter_channel_x86(int32_t *state, const int32_t *coeff,
 
 #endif /* HAVE_7REGS && HAVE_INLINE_ASM */
 
-void ff_mlpdsp_init_x86(MLPDSPContext *c)
+av_cold void ff_mlpdsp_init_x86(MLPDSPContext *c)
 {
 #if HAVE_7REGS && HAVE_INLINE_ASM
     c->mlp_filter_channel = mlp_filter_channel_x86;
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/motion_est.c b/mythtv/external/FFmpeg/libavcodec/x86/motion_est.c
index e054a0d27a8..3ffb00296e6 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/motion_est.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/motion_est.c
@@ -22,10 +22,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/avassert.h"
 #include "libavutil/mem.h"
 #include "libavutil/x86/asm.h"
-#include "libavcodec/dsputil.h"
 #include "dsputil_mmx.h"
 
 #if HAVE_INLINE_ASM
@@ -432,7 +432,7 @@ PIX_SAD(mmxext)
 
 #endif /* HAVE_INLINE_ASM */
 
-void ff_dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx)
+av_cold void ff_dsputil_init_pix_mmx(DSPContext *c, AVCodecContext *avctx)
 {
 #if HAVE_INLINE_ASM
     int mm_flags = av_get_cpu_flags();
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/mpeg4qpel.asm b/mythtv/external/FFmpeg/libavcodec/x86/mpeg4qpel.asm
new file mode 100644
index 00000000000..ca52375a760
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/x86/mpeg4qpel.asm
@@ -0,0 +1,560 @@
+;******************************************************************************
+;* mpeg4 qpel
+;* Copyright (c) 2003 Michael Niedermayer 
+;* Copyright (c) 2008 Loren Merritt
+;* Copyright (c) 2013 Daniel Kang
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg is free software; you can redistribute it and/or
+;* modify it under the terms of the GNU Lesser General Public
+;* License as published by the Free Software Foundation; either
+;* version 2.1 of the License, or (at your option) any later version.
+;*
+;* FFmpeg is distributed in the hope that it will be useful,
+;* but WITHOUT ANY WARRANTY; without even the implied warranty of
+;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;* Lesser General Public License for more details.
+;*
+;* You should have received a copy of the GNU Lesser General Public
+;* License along with FFmpeg; if not, write to the Free Software
+;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;******************************************************************************
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+cextern pb_1
+cextern pw_3
+cextern pw_15
+cextern pw_16
+cextern pw_20
+
+
+SECTION_TEXT
+
+; put_no_rnd_pixels8_l2(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
+%macro PUT_NO_RND_PIXELS8_L2 0
+cglobal put_no_rnd_pixels8_l2, 6,6
+    movsxdifnidn r4, r4d
+    movsxdifnidn r3, r3d
+    pcmpeqb      m6, m6
+    test        r5d, 1
+    je .loop
+    mova         m0, [r1]
+    mova         m1, [r2]
+    add          r1, r4
+    add          r2, 8
+    pxor         m0, m6
+    pxor         m1, m6
+    PAVGB        m0, m1
+    pxor         m0, m6
+    mova       [r0], m0
+    add          r0, r3
+    dec r5d
+.loop:
+    mova         m0, [r1]
+    add          r1, r4
+    mova         m1, [r1]
+    add          r1, r4
+    mova         m2, [r2]
+    mova         m3, [r2+8]
+    pxor         m0, m6
+    pxor         m1, m6
+    pxor         m2, m6
+    pxor         m3, m6
+    PAVGB        m0, m2
+    PAVGB        m1, m3
+    pxor         m0, m6
+    pxor         m1, m6
+    mova       [r0], m0
+    add          r0, r3
+    mova       [r0], m1
+    add          r0, r3
+    mova         m0, [r1]
+    add          r1, r4
+    mova         m1, [r1]
+    add          r1, r4
+    mova         m2, [r2+16]
+    mova         m3, [r2+24]
+    pxor         m0, m6
+    pxor         m1, m6
+    pxor         m2, m6
+    pxor         m3, m6
+    PAVGB        m0, m2
+    PAVGB        m1, m3
+    pxor         m0, m6
+    pxor         m1, m6
+    mova       [r0], m0
+    add          r0, r3
+    mova       [r0], m1
+    add          r0, r3
+    add          r2, 32
+    sub         r5d, 4
+    jne .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+PUT_NO_RND_PIXELS8_L2
+
+
+; put_no_rnd_pixels16_l2(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
+%macro PUT_NO_RND_PIXELS16_l2 0
+cglobal put_no_rnd_pixels16_l2, 6,6
+    movsxdifnidn r3, r3d
+    movsxdifnidn r4, r4d
+    pcmpeqb      m6, m6
+    test        r5d, 1
+    je .loop
+    mova         m0, [r1]
+    mova         m1, [r1+8]
+    mova         m2, [r2]
+    mova         m3, [r2+8]
+    pxor         m0, m6
+    pxor         m1, m6
+    pxor         m2, m6
+    pxor         m3, m6
+    PAVGB        m0, m2
+    PAVGB        m1, m3
+    pxor         m0, m6
+    pxor         m1, m6
+    add          r1, r4
+    add          r2, 16
+    mova       [r0], m0
+    mova     [r0+8], m1
+    add          r0, r3
+    dec r5d
+.loop:
+    mova         m0, [r1]
+    mova         m1, [r1+8]
+    add          r1, r4
+    mova         m2, [r2]
+    mova         m3, [r2+8]
+    pxor         m0, m6
+    pxor         m1, m6
+    pxor         m2, m6
+    pxor         m3, m6
+    PAVGB        m0, m2
+    PAVGB        m1, m3
+    pxor         m0, m6
+    pxor         m1, m6
+    mova       [r0], m0
+    mova     [r0+8], m1
+    add          r0, r3
+    mova         m0, [r1]
+    mova         m1, [r1+8]
+    add          r1, r4
+    mova         m2, [r2+16]
+    mova         m3, [r2+24]
+    pxor         m0, m6
+    pxor         m1, m6
+    pxor         m2, m6
+    pxor         m3, m6
+    PAVGB        m0, m2
+    PAVGB        m1, m3
+    pxor         m0, m6
+    pxor         m1, m6
+    mova       [r0], m0
+    mova     [r0+8], m1
+    add          r0, r3
+    add          r2, 32
+    sub         r5d, 2
+    jne .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+PUT_NO_RND_PIXELS16_l2
+INIT_MMX 3dnow
+PUT_NO_RND_PIXELS16_l2
+
+%macro MPEG4_QPEL16_H_LOWPASS 1
+cglobal %1_mpeg4_qpel16_h_lowpass, 5, 5, 0, 16
+    movsxdifnidn r2, r2d
+    movsxdifnidn r3, r3d
+    pxor         m7, m7
+.loop:
+    mova         m0, [r1]
+    mova         m1, m0
+    mova         m2, m0
+    punpcklbw    m0, m7
+    punpckhbw    m1, m7
+    pshufw       m5, m0, 0x90
+    pshufw       m6, m0, 0x41
+    mova         m3, m2
+    mova         m4, m2
+    psllq        m2, 8
+    psllq        m3, 16
+    psllq        m4, 24
+    punpckhbw    m2, m7
+    punpckhbw    m3, m7
+    punpckhbw    m4, m7
+    paddw        m5, m3
+    paddw        m6, m2
+    paddw        m5, m5
+    psubw        m6, m5
+    pshufw       m5, m0, 6
+    pmullw       m6, [pw_3]
+    paddw        m0, m4
+    paddw        m5, m1
+    pmullw       m0, [pw_20]
+    psubw        m0, m5
+    paddw        m6, [PW_ROUND]
+    paddw        m0, m6
+    psraw        m0, 5
+    mova    [rsp+8], m0
+    mova         m0, [r1+5]
+    mova         m5, m0
+    mova         m6, m0
+    psrlq        m0, 8
+    psrlq        m5, 16
+    punpcklbw    m0, m7
+    punpcklbw    m5, m7
+    paddw        m2, m0
+    paddw        m3, m5
+    paddw        m2, m2
+    psubw        m3, m2
+    mova         m2, m6
+    psrlq        m6, 24
+    punpcklbw    m2, m7
+    punpcklbw    m6, m7
+    pmullw       m3, [pw_3]
+    paddw        m1, m2
+    paddw        m4, m6
+    pmullw       m1, [pw_20]
+    psubw        m3, m4
+    paddw        m1, [PW_ROUND]
+    paddw        m3, m1
+    psraw        m3, 5
+    mova         m1, [rsp+8]
+    packuswb     m1, m3
+    OP_MOV     [r0], m1, m4
+    mova         m1, [r1+9]
+    mova         m4, m1
+    mova         m3, m1
+    psrlq        m1, 8
+    psrlq        m4, 16
+    punpcklbw    m1, m7
+    punpcklbw    m4, m7
+    paddw        m5, m1
+    paddw        m0, m4
+    paddw        m5, m5
+    psubw        m0, m5
+    mova         m5, m3
+    psrlq        m3, 24
+    pmullw       m0, [pw_3]
+    punpcklbw    m3, m7
+    paddw        m2, m3
+    psubw        m0, m2
+    mova         m2, m5
+    punpcklbw    m2, m7
+    punpckhbw    m5, m7
+    paddw        m6, m2
+    pmullw       m6, [pw_20]
+    paddw        m0, [PW_ROUND]
+    paddw        m0, m6
+    psraw        m0, 5
+    paddw        m3, m5
+    pshufw       m6, m5, 0xf9
+    paddw        m6, m4
+    pshufw       m4, m5, 0xbe
+    pshufw       m5, m5, 0x6f
+    paddw        m4, m1
+    paddw        m5, m2
+    paddw        m6, m6
+    psubw        m4, m6
+    pmullw       m3, [pw_20]
+    pmullw       m4, [pw_3]
+    psubw        m3, m5
+    paddw        m4, [PW_ROUND]
+    paddw        m4, m3
+    psraw        m4, 5
+    packuswb     m0, m4
+    OP_MOV   [r0+8], m0, m4
+    add          r1, r3
+    add          r0, r2
+    dec r4d
+    jne .loop
+    REP_RET
+%endmacro
+
+%macro PUT_OP 2-3
+    mova %1, %2
+%endmacro
+
+%macro AVG_OP 2-3
+    mova  %3, %1
+    pavgb %2, %3
+    mova  %1, %2
+%endmacro
+
+INIT_MMX mmxext
+%define PW_ROUND pw_16
+%define OP_MOV PUT_OP
+MPEG4_QPEL16_H_LOWPASS put
+%define PW_ROUND pw_16
+%define OP_MOV AVG_OP
+MPEG4_QPEL16_H_LOWPASS avg
+%define PW_ROUND pw_15
+%define OP_MOV PUT_OP
+MPEG4_QPEL16_H_LOWPASS put_no_rnd
+
+
+
+%macro MPEG4_QPEL8_H_LOWPASS 1
+cglobal %1_mpeg4_qpel8_h_lowpass, 5, 5, 0, 8
+    movsxdifnidn r2, r2d
+    movsxdifnidn r3, r3d
+    pxor         m7, m7
+.loop:
+    mova         m0, [r1]
+    mova         m1, m0
+    mova         m2, m0
+    punpcklbw    m0, m7
+    punpckhbw    m1, m7
+    pshufw       m5, m0, 0x90
+    pshufw       m6, m0, 0x41
+    mova         m3, m2
+    mova         m4, m2
+    psllq        m2, 8
+    psllq        m3, 16
+    psllq        m4, 24
+    punpckhbw    m2, m7
+    punpckhbw    m3, m7
+    punpckhbw    m4, m7
+    paddw        m5, m3
+    paddw        m6, m2
+    paddw        m5, m5
+    psubw        m6, m5
+    pshufw       m5, m0, 0x6
+    pmullw       m6, [pw_3]
+    paddw        m0, m4
+    paddw        m5, m1
+    pmullw       m0, [pw_20]
+    psubw        m0, m5
+    paddw        m6, [PW_ROUND]
+    paddw        m0, m6
+    psraw        m0, 5
+    movh         m5, [r1+5]
+    punpcklbw    m5, m7
+    pshufw       m6, m5, 0xf9
+    paddw        m1, m5
+    paddw        m2, m6
+    pshufw       m6, m5, 0xbe
+    pshufw       m5, m5, 0x6f
+    paddw        m3, m6
+    paddw        m4, m5
+    paddw        m2, m2
+    psubw        m3, m2
+    pmullw       m1, [pw_20]
+    pmullw       m3, [pw_3]
+    psubw        m3, m4
+    paddw        m1, [PW_ROUND]
+    paddw        m3, m1
+    psraw        m3, 5
+    packuswb     m0, m3
+    OP_MOV     [r0], m0, m4
+    add          r1, r3
+    add          r0, r2
+    dec r4d
+    jne .loop
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+%define PW_ROUND pw_16
+%define OP_MOV PUT_OP
+MPEG4_QPEL8_H_LOWPASS put
+%define PW_ROUND pw_16
+%define OP_MOV AVG_OP
+MPEG4_QPEL8_H_LOWPASS avg
+%define PW_ROUND pw_15
+%define OP_MOV PUT_OP
+MPEG4_QPEL8_H_LOWPASS put_no_rnd
+
+
+
+%macro QPEL_V_LOW 5
+    paddw      m0, m1
+    mova       m4, [pw_20]
+    pmullw     m4, m0
+    mova       m0, %4
+    mova       m5, %1
+    paddw      m5, m0
+    psubw      m4, m5
+    mova       m5, %2
+    mova       m6, %3
+    paddw      m5, m3
+    paddw      m6, m2
+    paddw      m6, m6
+    psubw      m5, m6
+    pmullw     m5, [pw_3]
+    paddw      m4, [PW_ROUND]
+    paddw      m5, m4
+    psraw      m5, 5
+    packuswb   m5, m5
+    OP_MOV     %5, m5, m7
+    SWAP 0,1,2,3
+%endmacro
+
+%macro MPEG4_QPEL16_V_LOWPASS 1
+cglobal %1_mpeg4_qpel16_v_lowpass, 4, 6, 0, 544
+    movsxdifnidn r2, r2d
+    movsxdifnidn r3, r3d
+
+    mov         r4d, 17
+    mov          r5, rsp
+    pxor         m7, m7
+.looph:
+    mova         m0, [r1]
+    mova         m1, [r1]
+    mova         m2, [r1+8]
+    mova         m3, [r1+8]
+    punpcklbw    m0, m7
+    punpckhbw    m1, m7
+    punpcklbw    m2, m7
+    punpckhbw    m3, m7
+    mova       [r5], m0
+    mova  [r5+0x88], m1
+    mova [r5+0x110], m2
+    mova [r5+0x198], m3
+    add          r5, 8
+    add          r1, r3
+    dec r4d
+    jne .looph
+
+
+    ; NOTE: r1 CHANGES VALUES: r1 -> 4 - 14*dstStride
+    mov         r4d, 4
+    mov          r1, 4
+    neg          r2
+    lea          r1, [r1+r2*8]
+    lea          r1, [r1+r2*4]
+    lea          r1, [r1+r2*2]
+    neg          r2
+    mov          r5, rsp
+.loopv:
+    pxor         m7, m7
+    mova         m0, [r5+ 0x0]
+    mova         m1, [r5+ 0x8]
+    mova         m2, [r5+0x10]
+    mova         m3, [r5+0x18]
+    QPEL_V_LOW [r5+0x10], [r5+ 0x8], [r5+ 0x0], [r5+0x20], [r0]
+    QPEL_V_LOW [r5+ 0x8], [r5+ 0x0], [r5+ 0x0], [r5+0x28], [r0+r2]
+    lea    r0, [r0+r2*2]
+    QPEL_V_LOW [r5+ 0x0], [r5+ 0x0], [r5+ 0x8], [r5+0x30], [r0]
+    QPEL_V_LOW [r5+ 0x0], [r5+ 0x8], [r5+0x10], [r5+0x38], [r0+r2]
+    lea    r0, [r0+r2*2]
+    QPEL_V_LOW [r5+ 0x8], [r5+0x10], [r5+0x18], [r5+0x40], [r0]
+    QPEL_V_LOW [r5+0x10], [r5+0x18], [r5+0x20], [r5+0x48], [r0+r2]
+    lea    r0, [r0+r2*2]
+    QPEL_V_LOW [r5+0x18], [r5+0x20], [r5+0x28], [r5+0x50], [r0]
+    QPEL_V_LOW [r5+0x20], [r5+0x28], [r5+0x30], [r5+0x58], [r0+r2]
+    lea    r0, [r0+r2*2]
+    QPEL_V_LOW [r5+0x28], [r5+0x30], [r5+0x38], [r5+0x60], [r0]
+    QPEL_V_LOW [r5+0x30], [r5+0x38], [r5+0x40], [r5+0x68], [r0+r2]
+    lea    r0, [r0+r2*2]
+    QPEL_V_LOW [r5+0x38], [r5+0x40], [r5+0x48], [r5+0x70], [r0]
+    QPEL_V_LOW [r5+0x40], [r5+0x48], [r5+0x50], [r5+0x78], [r0+r2]
+    lea    r0, [r0+r2*2]
+    QPEL_V_LOW [r5+0x48], [r5+0x50], [r5+0x58], [r5+0x80], [r0]
+    QPEL_V_LOW [r5+0x50], [r5+0x58], [r5+0x60], [r5+0x80], [r0+r2]
+    lea    r0, [r0+r2*2]
+    QPEL_V_LOW [r5+0x58], [r5+0x60], [r5+0x68], [r5+0x78], [r0]
+    QPEL_V_LOW [r5+0x60], [r5+0x68], [r5+0x70], [r5+0x70], [r0+r2]
+
+    add    r5, 0x88
+    add    r0, r1
+    dec r4d
+    jne .loopv
+    REP_RET
+%endmacro
+
+%macro PUT_OPH 2-3
+    movh %1, %2
+%endmacro
+
+%macro AVG_OPH 2-3
+    movh  %3, %1
+    pavgb %2, %3
+    movh  %1, %2
+%endmacro
+
+INIT_MMX mmxext
+%define PW_ROUND pw_16
+%define OP_MOV PUT_OPH
+MPEG4_QPEL16_V_LOWPASS put
+%define PW_ROUND pw_16
+%define OP_MOV AVG_OPH
+MPEG4_QPEL16_V_LOWPASS avg
+%define PW_ROUND pw_15
+%define OP_MOV PUT_OPH
+MPEG4_QPEL16_V_LOWPASS put_no_rnd
+
+
+
+%macro MPEG4_QPEL8_V_LOWPASS 1
+cglobal %1_mpeg4_qpel8_v_lowpass, 4, 6, 0, 288
+    movsxdifnidn r2, r2d
+    movsxdifnidn r3, r3d
+
+    mov         r4d, 9
+    mov          r5, rsp
+    pxor         m7, m7
+.looph:
+    mova         m0, [r1]
+    mova         m1, [r1]
+    punpcklbw    m0, m7
+    punpckhbw    m1, m7
+    mova       [r5], m0
+    mova  [r5+0x48], m1
+    add          r5, 8
+    add          r1, r3
+    dec r4d
+    jne .looph
+
+
+    ; NOTE: r1 CHANGES VALUES: r1 -> 4 - 6*dstStride
+    mov         r4d, 2
+    mov          r1, 4
+    neg          r2
+    lea          r1, [r1+r2*4]
+    lea          r1, [r1+r2*2]
+    neg          r2
+    mov          r5, rsp
+.loopv:
+    pxor         m7, m7
+    mova         m0, [r5+ 0x0]
+    mova         m1, [r5+ 0x8]
+    mova         m2, [r5+0x10]
+    mova         m3, [r5+0x18]
+    QPEL_V_LOW [r5+0x10], [r5+ 0x8], [r5+ 0x0], [r5+0x20], [r0]
+    QPEL_V_LOW [r5+ 0x8], [r5+ 0x0], [r5+ 0x0], [r5+0x28], [r0+r2]
+    lea    r0, [r0+r2*2]
+    QPEL_V_LOW [r5+ 0x0], [r5+ 0x0], [r5+ 0x8], [r5+0x30], [r0]
+    QPEL_V_LOW [r5+ 0x0], [r5+ 0x8], [r5+0x10], [r5+0x38], [r0+r2]
+    lea    r0, [r0+r2*2]
+    QPEL_V_LOW [r5+ 0x8], [r5+0x10], [r5+0x18], [r5+0x40], [r0]
+    QPEL_V_LOW [r5+0x10], [r5+0x18], [r5+0x20], [r5+0x40], [r0+r2]
+    lea    r0, [r0+r2*2]
+    QPEL_V_LOW [r5+0x18], [r5+0x20], [r5+0x28], [r5+0x38], [r0]
+    QPEL_V_LOW [r5+0x20], [r5+0x28], [r5+0x30], [r5+0x30], [r0+r2]
+
+    add    r5, 0x48
+    add    r0, r1
+    dec r4d
+    jne .loopv
+    REP_RET
+%endmacro
+
+INIT_MMX mmxext
+%define PW_ROUND pw_16
+%define OP_MOV PUT_OPH
+MPEG4_QPEL8_V_LOWPASS put
+%define PW_ROUND pw_16
+%define OP_MOV AVG_OPH
+MPEG4_QPEL8_V_LOWPASS avg
+%define PW_ROUND pw_15
+%define OP_MOV PUT_OPH
+MPEG4_QPEL8_V_LOWPASS put_no_rnd
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/mpegaudiodec.c b/mythtv/external/FFmpeg/libavcodec/x86/mpegaudiodec.c
index 44cbf9a4282..287d8ff1268 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/mpegaudiodec.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/mpegaudiodec.c
@@ -19,10 +19,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
+#include "libavutil/internal.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
-#include "libavcodec/dsputil.h"
 #include "libavcodec/mpegaudiodsp.h"
 
 #define DECL(CPU)\
@@ -232,7 +233,7 @@ DECL_IMDCT_BLOCKS(avx,avx)
 #endif
 #endif /* HAVE_YASM */
 
-void ff_mpadsp_init_x86(MPADSPContext *s)
+av_cold void ff_mpadsp_init_x86(MPADSPContext *s)
 {
     int mm_flags = av_get_cpu_flags();
 
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/mpegvideo.c b/mythtv/external/FFmpeg/libavcodec/x86/mpegvideo.c
index 9870ed7d512..903ad62dd5a 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/mpegvideo.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/mpegvideo.c
@@ -19,17 +19,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
 #include "libavcodec/avcodec.h"
-#include "libavcodec/dsputil.h"
 #include "libavcodec/mpegvideo.h"
 #include "dsputil_mmx.h"
 
 #if HAVE_INLINE_ASM
 
 static void dct_unquantize_h263_intra_mmx(MpegEncContext *s,
-                                  DCTELEM *block, int n, int qscale)
+                                  int16_t *block, int n, int qscale)
 {
     x86_reg level, qmul, qadd, nCoeffs;
 
@@ -104,7 +104,7 @@ __asm__ volatile(
 
 
 static void dct_unquantize_h263_inter_mmx(MpegEncContext *s,
-                                  DCTELEM *block, int n, int qscale)
+                                  int16_t *block, int n, int qscale)
 {
     x86_reg qmul, qadd, nCoeffs;
 
@@ -187,7 +187,7 @@ __asm__ volatile(
  high3 += tlow1
 */
 static void dct_unquantize_mpeg1_intra_mmx(MpegEncContext *s,
-                                     DCTELEM *block, int n, int qscale)
+                                     int16_t *block, int n, int qscale)
 {
     x86_reg nCoeffs;
     const uint16_t *quant_matrix;
@@ -256,7 +256,7 @@ __asm__ volatile(
 }
 
 static void dct_unquantize_mpeg1_inter_mmx(MpegEncContext *s,
-                                     DCTELEM *block, int n, int qscale)
+                                     int16_t *block, int n, int qscale)
 {
     x86_reg nCoeffs;
     const uint16_t *quant_matrix;
@@ -322,7 +322,7 @@ __asm__ volatile(
 }
 
 static void dct_unquantize_mpeg2_intra_mmx(MpegEncContext *s,
-                                     DCTELEM *block, int n, int qscale)
+                                     int16_t *block, int n, int qscale)
 {
     x86_reg nCoeffs;
     const uint16_t *quant_matrix;
@@ -388,7 +388,7 @@ __asm__ volatile(
 }
 
 static void dct_unquantize_mpeg2_inter_mmx(MpegEncContext *s,
-                                     DCTELEM *block, int n, int qscale)
+                                     int16_t *block, int n, int qscale)
 {
     x86_reg nCoeffs;
     const uint16_t *quant_matrix;
@@ -464,7 +464,7 @@ __asm__ volatile(
         );
 }
 
-static void  denoise_dct_mmx(MpegEncContext *s, DCTELEM *block){
+static void  denoise_dct_mmx(MpegEncContext *s, int16_t *block){
     const int intra= s->mb_intra;
     int *sum= s->dct_error_sum[intra];
     uint16_t *offset= s->dct_offset[intra];
@@ -518,7 +518,7 @@ static void  denoise_dct_mmx(MpegEncContext *s, DCTELEM *block){
     );
 }
 
-static void  denoise_dct_sse2(MpegEncContext *s, DCTELEM *block){
+static void  denoise_dct_sse2(MpegEncContext *s, int16_t *block){
     const int intra= s->mb_intra;
     int *sum= s->dct_error_sum[intra];
     uint16_t *offset= s->dct_offset[intra];
@@ -576,7 +576,7 @@ static void  denoise_dct_sse2(MpegEncContext *s, DCTELEM *block){
 
 #endif /* HAVE_INLINE_ASM */
 
-void ff_MPV_common_init_x86(MpegEncContext *s)
+av_cold void ff_MPV_common_init_x86(MpegEncContext *s)
 {
 #if HAVE_INLINE_ASM
     int mm_flags = av_get_cpu_flags();
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/mpegvideoenc.c b/mythtv/external/FFmpeg/libavcodec/x86/mpegvideoenc.c
index 8e711f633b4..6219667af31 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/mpegvideoenc.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/mpegvideoenc.c
@@ -19,11 +19,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/avcodec.h"
-#include "libavcodec/dsputil.h"
+#include "libavcodec/dct.h"
 #include "libavcodec/mpegvideo.h"
 #include "dsputil_mmx.h"
 
@@ -80,7 +81,7 @@ extern uint16_t ff_inv_zigzag_direct16[64];
 #include "mpegvideoenc_template.c"
 #endif /* HAVE_SSSE3_INLINE */
 
-void ff_dct_encode_init_x86(MpegEncContext *s)
+av_cold void ff_dct_encode_init_x86(MpegEncContext *s)
 {
     int mm_flags = av_get_cpu_flags();
     const int dct_algo = s->avctx->dct_algo;
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/mpegvideoenc_template.c b/mythtv/external/FFmpeg/libavcodec/x86/mpegvideoenc_template.c
index 47c3b43f940..1e0505ea3c1 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/mpegvideoenc_template.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/mpegvideoenc_template.c
@@ -92,7 +92,7 @@
 #endif
 
 static int RENAME(dct_quantize)(MpegEncContext *s,
-                            DCTELEM *block, int n,
+                            int16_t *block, int n,
                             int qscale, int *overflow)
 {
     x86_reg last_non_zero_p1;
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/pngdsp_init.c b/mythtv/external/FFmpeg/libavcodec/x86/pngdsp_init.c
index 2355eeeb437..4c54ed30cf7 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/pngdsp_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/pngdsp_init.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/common.h"
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/pngdsp.h"
@@ -32,7 +33,7 @@ void ff_add_bytes_l2_mmx (uint8_t *dst, uint8_t *src1,
 void ff_add_bytes_l2_sse2(uint8_t *dst, uint8_t *src1,
                           uint8_t *src2, int w);
 
-void ff_pngdsp_init_x86(PNGDSPContext *dsp)
+av_cold void ff_pngdsp_init_x86(PNGDSPContext *dsp)
 {
     int flags = av_get_cpu_flags();
 
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/proresdsp.asm b/mythtv/external/FFmpeg/libavcodec/x86/proresdsp.asm
index 094f872bc87..aedacc2cdcc 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/proresdsp.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/proresdsp.asm
@@ -232,7 +232,7 @@ section .text align=16
 %endmacro
 
 ; void prores_idct_put_10_(uint8_t *pixels, int stride,
-;                               DCTELEM *block, const int16_t *qmat);
+;                               int16_t *block, const int16_t *qmat);
 %macro idct_put_fn 1
 cglobal prores_idct_put_10, 4, 4, %1
     movsxd      r1,  r1d
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/proresdsp_init.c b/mythtv/external/FFmpeg/libavcodec/x86/proresdsp_init.c
index 21ce0986d22..91ff2575648 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/proresdsp_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/proresdsp_init.c
@@ -21,14 +21,15 @@
  */
 
 #include "libavutil/x86/cpu.h"
+#include "libavcodec/dsputil.h"
 #include "libavcodec/proresdsp.h"
 
 void ff_prores_idct_put_10_sse2(uint16_t *dst, int linesize,
-                                DCTELEM *block, const int16_t *qmat);
+                                int16_t *block, const int16_t *qmat);
 void ff_prores_idct_put_10_sse4(uint16_t *dst, int linesize,
-                                DCTELEM *block, const int16_t *qmat);
+                                int16_t *block, const int16_t *qmat);
 void ff_prores_idct_put_10_avx (uint16_t *dst, int linesize,
-                                DCTELEM *block, const int16_t *qmat);
+                                int16_t *block, const int16_t *qmat);
 
 void ff_proresdsp_x86_init(ProresDSPContext *dsp, AVCodecContext *avctx)
 {
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/rv34dsp.asm b/mythtv/external/FFmpeg/libavcodec/x86/rv34dsp.asm
index c099ac5b1fe..4d9c35b6004 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/rv34dsp.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/rv34dsp.asm
@@ -133,7 +133,7 @@ cglobal rv34_idct_dc_add, 3, 3
     mova        mm5, [pd_512]           ; 0x200
 %endmacro
 
-; ff_rv34_idct_add_mmxext(uint8_t *dst, ptrdiff_t stride, DCTELEM *block);
+; ff_rv34_idct_add_mmxext(uint8_t *dst, ptrdiff_t stride, int16_t *block);
 %macro COL_TRANSFORM  4
     pshufw      mm3, %2, 0xDD        ; col. 1,3,1,3
     pshufw       %2, %2, 0x88        ; col. 0,2,0,2
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/rv34dsp_init.c b/mythtv/external/FFmpeg/libavcodec/x86/rv34dsp_init.c
index 6b6cf914ea5..a2dea74220d 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/rv34dsp_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/rv34dsp_init.c
@@ -22,16 +22,15 @@
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
-#include "libavcodec/dsputil.h"
 #include "libavcodec/rv34dsp.h"
 
-void ff_rv34_idct_dc_mmxext(DCTELEM *block);
-void ff_rv34_idct_dc_noround_mmxext(DCTELEM *block);
+void ff_rv34_idct_dc_mmxext(int16_t *block);
+void ff_rv34_idct_dc_noround_mmxext(int16_t *block);
 void ff_rv34_idct_dc_add_mmx(uint8_t *dst, ptrdiff_t stride, int dc);
 void ff_rv34_idct_dc_add_sse4(uint8_t *dst, ptrdiff_t stride, int dc);
-void ff_rv34_idct_add_mmxext(uint8_t *dst, ptrdiff_t stride, DCTELEM *block);
+void ff_rv34_idct_add_mmxext(uint8_t *dst, ptrdiff_t stride, int16_t *block);
 
-av_cold void ff_rv34dsp_init_x86(RV34DSPContext* c, DSPContext *dsp)
+av_cold void ff_rv34dsp_init_x86(RV34DSPContext* c)
 {
     int mm_flags = av_get_cpu_flags();
 
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/rv40dsp_init.c b/mythtv/external/FFmpeg/libavcodec/x86/rv40dsp_init.c
index 06ee86e57b0..51e98520cf3 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/rv40dsp_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/rv40dsp_init.c
@@ -27,6 +27,7 @@
  */
 
 #include "libavcodec/rv34dsp.h"
+#include "libavutil/attributes.h"
 #include "libavutil/mem.h"
 #include "libavutil/x86/cpu.h"
 #include "dsputil_mmx.h"
@@ -187,7 +188,7 @@ QPEL_FUNCS_SET (OP, 3, 2, OPT)
 
 #endif /* HAVE_YASM */
 
-void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp)
+av_cold void ff_rv40dsp_init_x86(RV34DSPContext *c)
 {
 #if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/sbrdsp.asm b/mythtv/external/FFmpeg/libavcodec/x86/sbrdsp.asm
index aaabf9f4aad..1b7f3a8646a 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/sbrdsp.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/sbrdsp.asm
@@ -24,6 +24,7 @@
 SECTION_RODATA
 ; mask equivalent for multiply by -1.0 1.0
 ps_mask         times 2 dd 1<<31, 0
+ps_neg          times 4 dd 1<<31
 
 SECTION_TEXT
 
@@ -178,3 +179,44 @@ cglobal sbr_hf_gen, 4,4,8, X_high, X_low, alpha0, alpha1, BW, S, E
     add     start, 16
     jnz         .loop2
     RET
+
+cglobal sbr_sum64x5, 1,2,4,z
+    lea    r1q, [zq+ 256]
+.loop:
+    mova    m0, [zq+   0]
+    mova    m2, [zq+  16]
+    mova    m1, [zq+ 256]
+    mova    m3, [zq+ 272]
+    addps   m0, [zq+ 512]
+    addps   m2, [zq+ 528]
+    addps   m1, [zq+ 768]
+    addps   m3, [zq+ 784]
+    addps   m0, [zq+1024]
+    addps   m2, [zq+1040]
+    addps   m0, m1
+    addps   m2, m3
+    mova  [zq], m0
+    mova  [zq+16], m2
+    add     zq, 32
+    cmp     zq, r1q
+    jne  .loop
+    REP_RET
+
+INIT_XMM sse
+cglobal sbr_qmf_post_shuffle, 2,3,4,W,z
+    lea              r2q, [zq + (64-4)*4]
+    mova              m3, [ps_neg]
+.loop:
+    mova              m1, [zq]
+    xorps             m0, m3, [r2q]
+    shufps            m0, m0, m0, q0123
+    unpcklps          m2, m0, m1
+    unpckhps          m0, m0, m1
+    mova       [Wq +  0], m2
+    mova       [Wq + 16], m0
+    add               Wq, 32
+    sub              r2q, 16
+    add               zq, 16
+    cmp               zq, r2q
+    jl             .loop
+    REP_RET
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/sbrdsp_init.c b/mythtv/external/FFmpeg/libavcodec/x86/sbrdsp_init.c
index 51c4bd4a16a..27fade133fd 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/sbrdsp_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/sbrdsp_init.c
@@ -20,24 +20,29 @@
  */
 
 #include "config.h"
+#include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/sbrdsp.h"
 
 float ff_sbr_sum_square_sse(float (*x)[2], int n);
+void ff_sbr_sum64x5_sse(float *z);
 void ff_sbr_hf_g_filt_sse(float (*Y)[2], const float (*X_high)[40][2],
                           const float *g_filt, int m_max, intptr_t ixh);
 void ff_sbr_hf_gen_sse(float (*X_high)[2], const float (*X_low)[2],
                        const float alpha0[2], const float alpha1[2],
                        float bw, int start, int end);
+void ff_sbr_qmf_post_shuffle_sse(float W[32][2], const float *z);
 
-void ff_sbrdsp_init_x86(SBRDSPContext *s)
+av_cold void ff_sbrdsp_init_x86(SBRDSPContext *s)
 {
     int mm_flags = av_get_cpu_flags();
 
     if (EXTERNAL_SSE(mm_flags)) {
         s->sum_square = ff_sbr_sum_square_sse;
+        s->sum64x5    = ff_sbr_sum64x5_sse;
         s->hf_g_filt  = ff_sbr_hf_g_filt_sse;
         s->hf_gen     = ff_sbr_hf_gen_sse;
+        s->qmf_post_shuffle = ff_sbr_qmf_post_shuffle_sse;
     }
 }
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/simple_idct.c b/mythtv/external/FFmpeg/libavcodec/x86/simple_idct.c
index c514d755ee3..f27d2b90ba0 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/simple_idct.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/simple_idct.c
@@ -19,7 +19,6 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#include "libavcodec/dsputil.h"
 #include "libavcodec/simple_idct.h"
 #include "libavutil/mem.h"
 #include "dsputil_mmx.h"
@@ -1154,12 +1153,12 @@ void ff_simple_idct_mmx(int16_t *block)
 
 //FIXME merge add/put into the idct
 
-void ff_simple_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block)
+void ff_simple_idct_put_mmx(uint8_t *dest, int line_size, int16_t *block)
 {
     idct(block);
     ff_put_pixels_clamped_mmx(block, dest, line_size);
 }
-void ff_simple_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block)
+void ff_simple_idct_add_mmx(uint8_t *dest, int line_size, int16_t *block)
 {
     idct(block);
     ff_add_pixels_clamped_mmx(block, dest, line_size);
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/snowdsp.c b/mythtv/external/FFmpeg/libavcodec/x86/snowdsp.c
index 631291aafe1..5505ee8bfd3 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/snowdsp.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/snowdsp.c
@@ -23,7 +23,7 @@
 #include "libavutil/x86/asm.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/snow.h"
-#include "libavcodec/dwt.h"
+#include "libavcodec/snow_dwt.h"
 #include "dsputil_mmx.h"
 
 #if HAVE_INLINE_ASM
@@ -875,7 +875,7 @@ static void ff_snow_inner_add_yblock_mmx(const uint8_t *obmc, const int obmc_str
 
 #endif /* HAVE_INLINE_ASM */
 
-void ff_dwt_init_x86(DWTContext *c)
+void ff_dwt_init_x86(SnowDWTContext *c)
 {
 #if HAVE_INLINE_ASM
     int mm_flags = av_get_cpu_flags();
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/vc1dsp_init.c b/mythtv/external/FFmpeg/libavcodec/x86/vc1dsp_init.c
index 230d06f0c0c..3f0b67ce675 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/vc1dsp_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/vc1dsp_init.c
@@ -27,6 +27,7 @@
 #include "libavutil/cpu.h"
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/vc1dsp.h"
+#include "dsputil_mmx.h"
 #include "vc1dsp.h"
 #include "config.h"
 
@@ -60,6 +61,12 @@ static void vc1_h_loop_filter16_sse4(uint8_t *src, int stride, int pq)
     ff_vc1_h_loop_filter8_sse4(src,          stride, pq);
     ff_vc1_h_loop_filter8_sse4(src+8*stride, stride, pq);
 }
+
+static void avg_vc1_mspel_mc00_mmxext(uint8_t *dst, const uint8_t *src,
+                                      int stride, int rnd)
+{
+    ff_avg_pixels8_mmxext(dst, src, stride, 8);
+}
 #endif /* HAVE_YASM */
 
 void ff_put_vc1_chroma_mc8_nornd_mmx  (uint8_t *dst, uint8_t *src,
@@ -100,6 +107,8 @@ av_cold void ff_vc1dsp_init_x86(VC1DSPContext *dsp)
     if (mm_flags & AV_CPU_FLAG_MMXEXT) {
         ASSIGN_LF(mmxext);
         dsp->avg_no_rnd_vc1_chroma_pixels_tab[0] = ff_avg_vc1_chroma_mc8_nornd_mmxext;
+
+        dsp->avg_vc1_mspel_pixels_tab[0]         = avg_vc1_mspel_mc00_mmxext;
     } else if (mm_flags & AV_CPU_FLAG_3DNOW) {
         dsp->avg_no_rnd_vc1_chroma_pixels_tab[0] = ff_avg_vc1_chroma_mc8_nornd_3dnow;
     }
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/vc1dsp_mmx.c b/mythtv/external/FFmpeg/libavcodec/x86/vc1dsp_mmx.c
index 6ce65e4e161..d1e4b9d9389 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/vc1dsp_mmx.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/vc1dsp_mmx.c
@@ -28,7 +28,6 @@
 #include "libavutil/mem.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
-#include "libavcodec/dsputil.h"
 #include "dsputil_mmx.h"
 #include "libavcodec/vc1dsp.h"
 #include "vc1dsp.h"
@@ -493,7 +492,7 @@ DECLARE_FUNCTION(3, 2)
 DECLARE_FUNCTION(3, 3)
 
 static void vc1_inv_trans_4x4_dc_mmxext(uint8_t *dest, int linesize,
-                                        DCTELEM *block)
+                                        int16_t *block)
 {
     int dc = block[0];
     dc = (17 * dc +  4) >> 3;
@@ -532,7 +531,7 @@ static void vc1_inv_trans_4x4_dc_mmxext(uint8_t *dest, int linesize,
 }
 
 static void vc1_inv_trans_4x8_dc_mmxext(uint8_t *dest, int linesize,
-                                        DCTELEM *block)
+                                        int16_t *block)
 {
     int dc = block[0];
     dc = (17 * dc +  4) >> 3;
@@ -594,7 +593,7 @@ static void vc1_inv_trans_4x8_dc_mmxext(uint8_t *dest, int linesize,
 }
 
 static void vc1_inv_trans_8x4_dc_mmxext(uint8_t *dest, int linesize,
-                                        DCTELEM *block)
+                                        int16_t *block)
 {
     int dc = block[0];
     dc = ( 3 * dc +  1) >> 1;
@@ -633,7 +632,7 @@ static void vc1_inv_trans_8x4_dc_mmxext(uint8_t *dest, int linesize,
 }
 
 static void vc1_inv_trans_8x8_dc_mmxext(uint8_t *dest, int linesize,
-                                        DCTELEM *block)
+                                        int16_t *block)
 {
     int dc = block[0];
     dc = (3 * dc +  1) >> 1;
@@ -719,7 +718,6 @@ av_cold void ff_vc1dsp_init_mmx(VC1DSPContext *dsp)
 
 av_cold void ff_vc1dsp_init_mmxext(VC1DSPContext *dsp)
 {
-        dsp->avg_vc1_mspel_pixels_tab[ 0] = ff_avg_vc1_mspel_mc00_mmxext;
         dsp->avg_vc1_mspel_pixels_tab[ 4] = avg_vc1_mspel_mc01_mmxext;
         dsp->avg_vc1_mspel_pixels_tab[ 8] = avg_vc1_mspel_mc02_mmxext;
         dsp->avg_vc1_mspel_pixels_tab[12] = avg_vc1_mspel_mc03_mmxext;
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/videodsp_init.c b/mythtv/external/FFmpeg/libavcodec/x86/videodsp_init.c
index 4a8b2442542..902450ea4d7 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/videodsp_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/videodsp_init.c
@@ -20,6 +20,7 @@
  */
 
 #include "config.h"
+#include "libavutil/attributes.h"
 #include "libavutil/avassert.h"
 #include "libavutil/common.h"
 #include "libavutil/cpu.h"
@@ -104,7 +105,7 @@ static av_noinline void emulated_edge_mc_sse(uint8_t *buf, const uint8_t *src,
 void ff_prefetch_mmxext(uint8_t *buf, ptrdiff_t stride, int h);
 void ff_prefetch_3dnow(uint8_t *buf, ptrdiff_t stride, int h);
 
-void ff_videodsp_init_x86(VideoDSPContext *ctx, int bpc)
+av_cold void ff_videodsp_init_x86(VideoDSPContext *ctx, int bpc)
 {
 #if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/vorbisdsp.asm b/mythtv/external/FFmpeg/libavcodec/x86/vorbisdsp.asm
new file mode 100644
index 00000000000..b25d8388684
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/x86/vorbisdsp.asm
@@ -0,0 +1,83 @@
+;******************************************************************************
+;* Vorbis x86 optimizations
+;* Copyright (C) 2006 Loren Merritt 
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg is free software; you can redistribute it and/or
+;* modify it under the terms of the GNU Lesser General Public
+;* License as published by the Free Software Foundation; either
+;* version 2.1 of the License, or (at your option) any later version.
+;*
+;* FFmpeg is distributed in the hope that it will be useful,
+;* but WITHOUT ANY WARRANTY; without even the implied warranty of
+;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;* Lesser General Public License for more details.
+;*
+;* You should have received a copy of the GNU Lesser General Public
+;* License along with FFmpeg; if not, write to the Free Software
+;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;******************************************************************************
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+
+pdw_80000000: times 4 dd 0x80000000
+
+SECTION .text
+
+%if ARCH_X86_32
+INIT_MMX 3dnow
+cglobal vorbis_inverse_coupling, 3, 3, 6, mag, ang, block_size
+    pxor                     m7, m7
+    lea                    magq, [magq+block_sizeq*4]
+    lea                    angq, [angq+block_sizeq*4]
+    neg             block_sizeq
+.loop:
+    mova                     m0, [magq+block_sizeq*4]
+    mova                     m1, [angq+block_sizeq*4]
+    mova                     m2, m0
+    mova                     m3, m1
+    pfcmpge                  m2, m7     ; m <= 0.0
+    pfcmpge                  m3, m7     ; a <= 0.0
+    pslld                    m2, 31     ; keep only the sign bit
+    pxor                     m1, m2
+    mova                     m4, m3
+    pand                     m3, m1
+    pandn                    m4, m1
+    pfadd                    m3, m0     ; a = m + ((a < 0) & (a ^ sign(m)))
+    pfsub                    m0, m4     ; m = m + ((a > 0) & (a ^ sign(m)))
+    mova   [angq+block_sizeq*4], m3
+    mova   [magq+block_sizeq*4], m0
+    add             block_sizeq, 2
+    jl .loop
+    femms
+    RET
+%endif
+
+INIT_XMM sse
+cglobal vorbis_inverse_coupling, 3, 4, 6, mag, ang, block_size, cntr
+    mova                     m5, [pdw_80000000]
+    xor                   cntrq, cntrq
+align 16
+.loop:
+    mova                     m0, [magq+cntrq*4]
+    mova                     m1, [angq+cntrq*4]
+    xorps                    m2, m2
+    xorps                    m3, m3
+    cmpleps                  m2, m0     ; m <= 0.0
+    cmpleps                  m3, m1     ; a <= 0.0
+    andps                    m2, m5     ; keep only the sign bit
+    xorps                    m1, m2
+    mova                     m4, m3
+    andps                    m3, m1
+    andnps                   m4, m1
+    addps                    m3, m0     ; a = m + ((a < 0) & (a ^ sign(m)))
+    subps                    m0, m4     ; m = m + ((a > 0) & (a ^ sign(m)))
+    mova         [angq+cntrq*4], m3
+    mova         [magq+cntrq*4], m0
+    add                   cntrq, 4
+    cmp                   cntrq, block_sizeq
+    jl .loop
+    RET
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/vorbisdsp_init.c b/mythtv/external/FFmpeg/libavcodec/x86/vorbisdsp_init.c
new file mode 100644
index 00000000000..08a2c096f00
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavcodec/x86/vorbisdsp_init.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2006 Loren Merritt 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libavcodec/vorbisdsp.h"
+
+void ff_vorbis_inverse_coupling_3dnow(float *mag, float *ang,
+                                      intptr_t blocksize);
+void ff_vorbis_inverse_coupling_sse(float *mag, float *ang,
+                                    intptr_t blocksize);
+
+av_cold void ff_vorbisdsp_init_x86(VorbisDSPContext *dsp)
+{
+#if HAVE_YASM
+    int mm_flags = av_get_cpu_flags();
+
+#if ARCH_X86_32
+    if (mm_flags & AV_CPU_FLAG_3DNOW)
+        dsp->vorbis_inverse_coupling = ff_vorbis_inverse_coupling_3dnow;
+#endif /* ARCH_X86_32 */
+    if (mm_flags & AV_CPU_FLAG_SSE)
+        dsp->vorbis_inverse_coupling = ff_vorbis_inverse_coupling_sse;
+#endif /* HAVE_YASM */
+}
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/vp3dsp.asm b/mythtv/external/FFmpeg/libavcodec/x86/vp3dsp.asm
index 3a5ed03c648..be5f21b2d87 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/vp3dsp.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/vp3dsp.asm
@@ -561,6 +561,13 @@ cglobal vp3_idct_put, 3, 4, 9
     movhps [r0+r3  ], m3
 %endif
 %assign %%i %%i+64
+%endrep
+
+    pxor          m0, m0
+%assign %%offset 0
+%rep 128/mmsize
+    mova [r2+%%offset], m0
+%assign %%offset %%offset+mmsize
 %endrep
     RET
 
@@ -600,6 +607,11 @@ cglobal vp3_idct_add, 3, 4, 9
     movhps   [r0+r1], m0
 %endif
     lea           r0, [r0+r1*2]
+%assign %%offset 0
+%rep 32/mmsize
+    mova [r2+%%offset], m4
+%assign %%offset %%offset+mmsize
+%endrep
     add           r2, 32
     dec           r3
     jg .loop
@@ -620,7 +632,7 @@ vp3_idct_funcs
     paddusb       m2, m0
     movq          m4, [r0+r1*2]
     paddusb       m3, m0
-    movq          m5, [r0+r3  ]
+    movq          m5, [r0+r2  ]
     paddusb       m4, m0
     paddusb       m5, m0
     psubusb       m2, m1
@@ -630,7 +642,7 @@ vp3_idct_funcs
     movq   [r0+r1  ], m3
     psubusb       m5, m1
     movq   [r0+r1*2], m4
-    movq   [r0+r3  ], m5
+    movq   [r0+r2  ], m5
 %endmacro
 
 INIT_MMX mmxext
@@ -638,11 +650,12 @@ cglobal vp3_idct_dc_add, 3, 4
 %if ARCH_X86_64
     movsxd        r1, r1d
 %endif
-    lea           r3, [r1*3]
-    movsx         r2, word [r2]
-    add           r2, 15
-    sar           r2, 5
-    movd          m0, r2d
+    movsx         r3, word [r2]
+    mov    word [r2], 0
+    lea           r2, [r1*3]
+    add           r3, 15
+    sar           r3, 5
+    movd          m0, r3d
     pshufw        m0, m0, 0x0
     pxor          m1, m1
     psubw         m1, m0
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/vp3dsp_init.c b/mythtv/external/FFmpeg/libavcodec/x86/vp3dsp_init.c
index eddfd072650..288dbcc6f3e 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/vp3dsp_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/vp3dsp_init.c
@@ -1,4 +1,6 @@
 /*
+ * Copyright (c) 2009 David Conrad 
+ *
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -21,28 +23,88 @@
 #include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/cpu.h"
+#include "libavutil/x86/asm.h"
 #include "libavcodec/avcodec.h"
+#include "libavcodec/dsputil.h"
 #include "libavcodec/vp3dsp.h"
 #include "config.h"
 
-void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block);
-void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, int16_t *block);
+void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, int16_t *block);
 
-void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block);
-void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, int16_t *block);
+void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, int16_t *block);
 
 void ff_vp3_idct_dc_add_mmxext(uint8_t *dest, int line_size,
-                               const DCTELEM *block);
+                               int16_t *block);
 
 void ff_vp3_v_loop_filter_mmxext(uint8_t *src, int stride,
                                  int *bounding_values);
 void ff_vp3_h_loop_filter_mmxext(uint8_t *src, int stride,
                                  int *bounding_values);
 
+#if HAVE_INLINE_ASM
+
+#define MOVQ_BFE(regd)                                  \
+    __asm__ volatile (                                  \
+        "pcmpeqd %%"#regd", %%"#regd"   \n\t"           \
+        "paddb   %%"#regd", %%"#regd"   \n\t" ::)
+
+#define PAVGBP_MMX_NO_RND(rega, regb, regr,  regc, regd, regp)   \
+    "movq  "#rega", "#regr"             \n\t"                    \
+    "movq  "#regc", "#regp"             \n\t"                    \
+    "pand  "#regb", "#regr"             \n\t"                    \
+    "pand  "#regd", "#regp"             \n\t"                    \
+    "pxor  "#rega", "#regb"             \n\t"                    \
+    "pxor  "#regc", "#regd"             \n\t"                    \
+    "pand    %%mm6, "#regb"             \n\t"                    \
+    "pand    %%mm6, "#regd"             \n\t"                    \
+    "psrlq      $1, "#regb"             \n\t"                    \
+    "psrlq      $1, "#regd"             \n\t"                    \
+    "paddb "#regb", "#regr"             \n\t"                    \
+    "paddb "#regd", "#regp"             \n\t"
+
+static void put_vp_no_rnd_pixels8_l2_mmx(uint8_t *dst, const uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h)
+{
+//    START_TIMER
+    MOVQ_BFE(mm6);
+    __asm__ volatile(
+        "1:                             \n\t"
+        "movq   (%1), %%mm0             \n\t"
+        "movq   (%2), %%mm1             \n\t"
+        "movq   (%1,%4), %%mm2          \n\t"
+        "movq   (%2,%4), %%mm3          \n\t"
+        PAVGBP_MMX_NO_RND(%%mm0, %%mm1, %%mm4,   %%mm2, %%mm3, %%mm5)
+        "movq   %%mm4, (%3)             \n\t"
+        "movq   %%mm5, (%3,%4)          \n\t"
+
+        "movq   (%1,%4,2), %%mm0        \n\t"
+        "movq   (%2,%4,2), %%mm1        \n\t"
+        "movq   (%1,%5), %%mm2          \n\t"
+        "movq   (%2,%5), %%mm3          \n\t"
+        "lea    (%1,%4,4), %1           \n\t"
+        "lea    (%2,%4,4), %2           \n\t"
+        PAVGBP_MMX_NO_RND(%%mm0, %%mm1, %%mm4,   %%mm2, %%mm3, %%mm5)
+        "movq   %%mm4, (%3,%4,2)        \n\t"
+        "movq   %%mm5, (%3,%5)          \n\t"
+        "lea    (%3,%4,4), %3           \n\t"
+        "subl   $4, %0                  \n\t"
+        "jnz    1b                      \n\t"
+        :"+r"(h), "+r"(a), "+r"(b), "+r"(dst)
+        :"r"((x86_reg)stride), "r"((x86_reg)3L*stride)
+        :"memory");
+//    STOP_TIMER("put_vp_no_rnd_pixels8_l2_mmx")
+}
+#endif /* HAVE_INLINE_ASM */
+
 av_cold void ff_vp3dsp_init_x86(VP3DSPContext *c, int flags)
 {
     int cpuflags = av_get_cpu_flags();
 
+#if HAVE_INLINE_ASM
+    c->put_no_rnd_pixels_l2 = put_vp_no_rnd_pixels8_l2_mmx;
+#endif /* HAVE_INLINE_ASM */
+
 #if ARCH_X86_32
     if (EXTERNAL_MMX(cpuflags)) {
         c->idct_put  = ff_vp3_idct_put_mmx;
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/vp56dsp_init.c b/mythtv/external/FFmpeg/libavcodec/x86/vp56dsp_init.c
index b699f793caf..defc63b0eac 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/vp56dsp_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/vp56dsp_init.c
@@ -23,7 +23,6 @@
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
-#include "libavcodec/dsputil.h"
 #include "libavcodec/vp56dsp.h"
 
 void ff_vp6_filter_diag4_mmx(uint8_t *dst, uint8_t *src, int stride,
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/vp8dsp.asm b/mythtv/external/FFmpeg/libavcodec/x86/vp8dsp.asm
index 84805fdc669..c5fb4555d39 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/vp8dsp.asm
+++ b/mythtv/external/FFmpeg/libavcodec/x86/vp8dsp.asm
@@ -899,7 +899,7 @@ cglobal put_vp8_pixels16, 5, 5, 2, dst, dststride, src, srcstride, height
     REP_RET
 
 ;-----------------------------------------------------------------------------
-; void vp8_idct_dc_add_(uint8_t *dst, DCTELEM block[16], int stride);
+; void vp8_idct_dc_add_(uint8_t *dst, int16_t block[16], int stride);
 ;-----------------------------------------------------------------------------
 
 %macro ADD_DC 4
@@ -977,7 +977,7 @@ cglobal vp8_idct_dc_add, 3, 3, 6, dst, block, stride
     RET
 
 ;-----------------------------------------------------------------------------
-; void vp8_idct_dc_add4y_(uint8_t *dst, DCTELEM block[4][16], int stride);
+; void vp8_idct_dc_add4y_(uint8_t *dst, int16_t block[4][16], int stride);
 ;-----------------------------------------------------------------------------
 
 %if ARCH_X86_32
@@ -1050,7 +1050,7 @@ cglobal vp8_idct_dc_add4y, 3, 3, 6, dst, block, stride
     RET
 
 ;-----------------------------------------------------------------------------
-; void vp8_idct_dc_add4uv_(uint8_t *dst, DCTELEM block[4][16], int stride);
+; void vp8_idct_dc_add4uv_(uint8_t *dst, int16_t block[4][16], int stride);
 ;-----------------------------------------------------------------------------
 
 INIT_MMX mmx
@@ -1092,7 +1092,7 @@ cglobal vp8_idct_dc_add4uv, 3, 3, 0, dst, block, stride
     RET
 
 ;-----------------------------------------------------------------------------
-; void vp8_idct_add_(uint8_t *dst, DCTELEM block[16], int stride);
+; void vp8_idct_add_(uint8_t *dst, int16_t block[16], int stride);
 ;-----------------------------------------------------------------------------
 
 ; calculate %1=mul_35468(%1)-mul_20091(%2); %2=mul_20091(%1)+mul_35468(%2)
@@ -1172,7 +1172,7 @@ INIT_MMX sse
 VP8_IDCT_ADD
 
 ;-----------------------------------------------------------------------------
-; void vp8_luma_dc_wht_mmxext(DCTELEM block[4][4][16], DCTELEM dc[16])
+; void vp8_luma_dc_wht_mmxext(int16_t block[4][4][16], int16_t dc[16])
 ;-----------------------------------------------------------------------------
 
 %macro SCATTER_WHT 3
diff --git a/mythtv/external/FFmpeg/libavcodec/x86/vp8dsp_init.c b/mythtv/external/FFmpeg/libavcodec/x86/vp8dsp_init.c
index 735619c32bf..09e2d9109ec 100644
--- a/mythtv/external/FFmpeg/libavcodec/x86/vp8dsp_init.c
+++ b/mythtv/external/FFmpeg/libavcodec/x86/vp8dsp_init.c
@@ -230,21 +230,21 @@ HVBILIN(ssse3, 8,  4,  8)
 HVBILIN(ssse3, 8,  8, 16)
 HVBILIN(ssse3, 8, 16, 16)
 
-extern void ff_vp8_idct_dc_add_mmx(uint8_t *dst, DCTELEM block[16],
+extern void ff_vp8_idct_dc_add_mmx(uint8_t *dst, int16_t block[16],
                                    ptrdiff_t stride);
-extern void ff_vp8_idct_dc_add_sse4(uint8_t *dst, DCTELEM block[16],
+extern void ff_vp8_idct_dc_add_sse4(uint8_t *dst, int16_t block[16],
                                     ptrdiff_t stride);
-extern void ff_vp8_idct_dc_add4y_mmx(uint8_t *dst, DCTELEM block[4][16],
+extern void ff_vp8_idct_dc_add4y_mmx(uint8_t *dst, int16_t block[4][16],
                                       ptrdiff_t stride);
-extern void ff_vp8_idct_dc_add4y_sse2(uint8_t *dst, DCTELEM block[4][16],
+extern void ff_vp8_idct_dc_add4y_sse2(uint8_t *dst, int16_t block[4][16],
                                       ptrdiff_t stride);
-extern void ff_vp8_idct_dc_add4uv_mmx(uint8_t *dst, DCTELEM block[2][16],
+extern void ff_vp8_idct_dc_add4uv_mmx(uint8_t *dst, int16_t block[2][16],
                                       ptrdiff_t stride);
-extern void ff_vp8_luma_dc_wht_mmx(DCTELEM block[4][4][16], DCTELEM dc[16]);
-extern void ff_vp8_luma_dc_wht_sse(DCTELEM block[4][4][16], DCTELEM dc[16]);
-extern void ff_vp8_idct_add_mmx(uint8_t *dst, DCTELEM block[16],
+extern void ff_vp8_luma_dc_wht_mmx(int16_t block[4][4][16], int16_t dc[16]);
+extern void ff_vp8_luma_dc_wht_sse(int16_t block[4][4][16], int16_t dc[16]);
+extern void ff_vp8_idct_add_mmx(uint8_t *dst, int16_t block[16],
                                 ptrdiff_t stride);
-extern void ff_vp8_idct_add_sse(uint8_t *dst, DCTELEM block[16],
+extern void ff_vp8_idct_add_sse(uint8_t *dst, int16_t block[16],
                                 ptrdiff_t stride);
 
 #define DECLARE_LOOP_FILTER(NAME)\
diff --git a/mythtv/external/FFmpeg/libavcodec/xan.c b/mythtv/external/FFmpeg/libavcodec/xan.c
index 899c1f1d221..219eedd92dc 100644
--- a/mythtv/external/FFmpeg/libavcodec/xan.c
+++ b/mythtv/external/FFmpeg/libavcodec/xan.c
@@ -116,7 +116,7 @@ static int xan_huffman_decode(unsigned char *dest, int dest_len,
     while (val != 0x16) {
         unsigned idx = val - 0x17 + get_bits1(&gb) * byte;
         if (idx >= 2 * byte)
-            return -1;
+            return AVERROR_INVALIDDATA;
         val = src[idx];
 
         if (val < 0x16) {
@@ -142,44 +142,47 @@ static void xan_unpack(unsigned char *dest, int dest_len,
     int size;
     unsigned char *dest_org = dest;
     unsigned char *dest_end = dest + dest_len;
-    const unsigned char *src_end = src + src_len;
+    GetByteContext ctx;
 
-    while (dest < dest_end && src < src_end) {
-        opcode = *src++;
+    bytestream2_init(&ctx, src, src_len);
+    while (dest < dest_end && bytestream2_get_bytes_left(&ctx)) {
+        opcode = bytestream2_get_byte(&ctx);
 
         if (opcode < 0xe0) {
             int size2, back;
             if ((opcode & 0x80) == 0) {
                 size = opcode & 3;
 
-                back  = ((opcode & 0x60) << 3) + *src++ + 1;
+                back  = ((opcode & 0x60) << 3) + bytestream2_get_byte(&ctx) + 1;
                 size2 = ((opcode & 0x1c) >> 2) + 3;
             } else if ((opcode & 0x40) == 0) {
-                size = *src >> 6;
+                size = bytestream2_peek_byte(&ctx) >> 6;
 
-                back  = (bytestream_get_be16(&src) & 0x3fff) + 1;
+                back  = (bytestream2_get_be16(&ctx) & 0x3fff) + 1;
                 size2 = (opcode & 0x3f) + 4;
             } else {
                 size = opcode & 3;
 
-                back  = ((opcode & 0x10) << 12) + bytestream_get_be16(&src) + 1;
-                size2 = ((opcode & 0x0c) <<  6) + *src++ + 5;
+                back  = ((opcode & 0x10) << 12) + bytestream2_get_be16(&ctx) + 1;
+                size2 = ((opcode & 0x0c) <<  6) + bytestream2_get_byte(&ctx) + 5;
             }
 
             if (dest_end - dest < size + size2 ||
                 dest + size - dest_org < back ||
-                src_end - src < size)
+                bytestream2_get_bytes_left(&ctx) < size)
                 return;
-            memcpy(dest, src, size);  dest += size;  src += size;
+            bytestream2_get_buffer(&ctx, dest, size);
+            dest += size;
             av_memcpy_backptr(dest, back, size2);
             dest += size2;
         } else {
             int finish = opcode >= 0xfc;
             size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4;
 
-            if (dest_end - dest < size || src_end - src < size)
+            if (dest_end - dest < size || bytestream2_get_bytes_left(&ctx) < size)
                 return;
-            memcpy(dest, src, size);  dest += size;  src += size;
+            bytestream2_get_buffer(&ctx, dest, size);
+            dest += size;
             if (finish)
                 return;
         }
@@ -518,21 +521,22 @@ static int xan_decode_frame(AVCodecContext *avctx,
     const uint8_t *buf = avpkt->data;
     int ret, buf_size = avpkt->size;
     XanContext *s = avctx->priv_data;
-    const uint8_t *buf_end = buf + buf_size;
+    GetByteContext ctx;
     int tag = 0;
 
-    while (buf_end - buf > 8 && tag != VGA__TAG) {
+    bytestream2_init(&ctx, buf, buf_size);
+    while (bytestream2_get_bytes_left(&ctx) > 8 && tag != VGA__TAG) {
         unsigned *tmpptr;
         uint32_t new_pal;
         int size;
         int i;
-        tag  = bytestream_get_le32(&buf);
-        size = bytestream_get_be32(&buf);
+        tag  = bytestream2_get_le32(&ctx);
+        size = bytestream2_get_be32(&ctx);
         if(size < 0) {
             av_log(avctx, AV_LOG_ERROR, "Invalid tag size %d\n", size);
             return AVERROR_INVALIDDATA;
         }
-        size = FFMIN(size, buf_end - buf);
+        size = FFMIN(size, bytestream2_get_bytes_left(&ctx));
         switch (tag) {
         case PALT_TAG:
             if (size < PALETTE_SIZE)
@@ -547,13 +551,13 @@ static int xan_decode_frame(AVCodecContext *avctx,
             tmpptr += s->palettes_count * AVPALETTE_COUNT;
             for (i = 0; i < PALETTE_COUNT; i++) {
 #if RUNTIME_GAMMA
-                int r = gamma_corr(*buf++);
-                int g = gamma_corr(*buf++);
-                int b = gamma_corr(*buf++);
+                int r = gamma_corr(bytestream2_get_byteu(&ctx));
+                int g = gamma_corr(bytestream2_get_byteu(&ctx));
+                int b = gamma_corr(bytestream2_get_byteu(&ctx));
 #else
-                int r = gamma_lookup[*buf++];
-                int g = gamma_lookup[*buf++];
-                int b = gamma_lookup[*buf++];
+                int r = gamma_lookup[bytestream2_get_byteu(&ctx)];
+                int g = gamma_lookup[bytestream2_get_byteu(&ctx)];
+                int b = gamma_lookup[bytestream2_get_byteu(&ctx)];
 #endif
                 *tmpptr++ = (0xFFU << 24) | (r << 16) | (g << 8) | b;
             }
@@ -562,7 +566,7 @@ static int xan_decode_frame(AVCodecContext *avctx,
         case SHOT_TAG:
             if (size < 4)
                 return AVERROR_INVALIDDATA;
-            new_pal = bytestream_get_le32(&buf);
+            new_pal = bytestream2_get_le32(&ctx);
             if (new_pal < s->palettes_count) {
                 s->cur_palette = new_pal;
             } else
@@ -571,11 +575,11 @@ static int xan_decode_frame(AVCodecContext *avctx,
         case VGA__TAG:
             break;
         default:
-            buf += size;
+            bytestream2_skip(&ctx, size);
             break;
         }
     }
-    buf_size = buf_end - buf;
+    buf_size = bytestream2_get_bytes_left(&ctx);
 
     if (s->palettes_count <= 0) {
         av_log(s->avctx, AV_LOG_ERROR, "No palette found\n");
@@ -594,7 +598,7 @@ static int xan_decode_frame(AVCodecContext *avctx,
     memcpy(s->current_frame.data[1],
            s->palettes + s->cur_palette * AVPALETTE_COUNT, AVPALETTE_SIZE);
 
-    s->buf = buf;
+    s->buf = ctx.buffer;
     s->size = buf_size;
 
     if (xan_wc3_decode_frame(s) < 0)
diff --git a/mythtv/external/FFmpeg/libavcodec/xbmdec.c b/mythtv/external/FFmpeg/libavcodec/xbmdec.c
index 2a418364923..04318f10e86 100644
--- a/mythtv/external/FFmpeg/libavcodec/xbmdec.c
+++ b/mythtv/external/FFmpeg/libavcodec/xbmdec.c
@@ -23,6 +23,7 @@
 #include "avcodec.h"
 #include "internal.h"
 #include "mathops.h"
+#include "libavutil/avstring.h"
 
 static av_cold int xbm_decode_init(AVCodecContext *avctx)
 {
@@ -58,7 +59,7 @@ static int xbm_decode_frame(AVCodecContext *avctx, void *data,
         int number, len;
 
         ptr += strcspn(ptr, "#");
-        if (sscanf(ptr, "#define %256s %u", name, &number) != 2) {
+        if (sscanf(ptr, "#define %255s %u", name, &number) != 2) {
             av_log(avctx, AV_LOG_ERROR, "Unexpected preprocessor directive\n");
             return AVERROR_INVALIDDATA;
         }
@@ -94,10 +95,10 @@ static int xbm_decode_frame(AVCodecContext *avctx, void *data,
             uint8_t val;
 
             ptr += strcspn(ptr, "x") + 1;
-            if (ptr < end && isxdigit(*ptr)) {
+            if (ptr < end && av_isxdigit(*ptr)) {
                 val = convert(*ptr);
                 ptr++;
-                if (isxdigit(*ptr))
+                if (av_isxdigit(*ptr))
                     val = (val << 4) + convert(*ptr);
                 *dst++ = ff_reverse[val];
             } else {
diff --git a/mythtv/external/FFmpeg/libavcodec/xl.c b/mythtv/external/FFmpeg/libavcodec/xl.c
index df354893a5f..e2701d68d24 100644
--- a/mythtv/external/FFmpeg/libavcodec/xl.c
+++ b/mythtv/external/FFmpeg/libavcodec/xl.c
@@ -69,7 +69,7 @@ static int decode_frame(AVCodecContext *avctx,
         avctx->release_buffer(avctx, p);
 
     p->reference = 0;
-    if ((ret = ff_get_buffer(avctx, p)) < 0) {
+    if ((ret = ff_get_buffer(avctx, p)) < 0){
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
diff --git a/mythtv/external/FFmpeg/libavcodec/xxan.c b/mythtv/external/FFmpeg/libavcodec/xxan.c
index 1deafe8bcc2..9168327caf6 100644
--- a/mythtv/external/FFmpeg/libavcodec/xxan.c
+++ b/mythtv/external/FFmpeg/libavcodec/xxan.c
@@ -191,7 +191,7 @@ static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off)
     dec_size = xan_unpack(s, s->scratch_buffer, s->buffer_size);
     if (dec_size < 0) {
         av_log(avctx, AV_LOG_ERROR, "Chroma unpacking failed\n");
-        return AVERROR_INVALIDDATA;
+        return dec_size;
     }
 
     U = s->pic.data[1];
@@ -315,7 +315,7 @@ static int xan_decode_frame_type0(AVCodecContext *avctx)
         int dec_size;
 
         bytestream2_seek(&s->gb, 8 + corr_off, SEEK_SET);
-        dec_size = xan_unpack(s, s->scratch_buffer, s->buffer_size / 2);
+        dec_size = xan_unpack(s, s->scratch_buffer, s->buffer_size);
         if (dec_size < 0)
             dec_size = 0;
         else
diff --git a/mythtv/external/FFmpeg/libavcodec/yop.c b/mythtv/external/FFmpeg/libavcodec/yop.c
index 1db567f456a..234868abbfd 100644
--- a/mythtv/external/FFmpeg/libavcodec/yop.c
+++ b/mythtv/external/FFmpeg/libavcodec/yop.c
@@ -86,7 +86,8 @@ static av_cold int yop_decode_init(AVCodecContext *avctx)
 
     if (avctx->width & 1 || avctx->height & 1 ||
         av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) {
-        return -1;
+        av_log(avctx, AV_LOG_ERROR, "YOP has invalid dimensions\n");
+        return AVERROR_INVALIDDATA;
     }
 
     if (avctx->extradata_size < 3) {
@@ -199,17 +200,15 @@ static int yop_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     if (s->frame.data[0])
         avctx->release_buffer(avctx, &s->frame);
 
-    if (avpkt->size < 4 + 3*s->num_pal_colors) {
-        av_log(avctx, AV_LOG_ERROR, "packet of size %d too small\n", avpkt->size);
-        return AVERROR_INVALIDDATA;
-    }
-
     ret = ff_get_buffer(avctx, &s->frame);
     if (ret < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
 
+    if (!avctx->frame_number)
+        memset(s->frame.data[1], 0, AVPALETTE_SIZE);
+
     s->dstbuf     = s->frame.data[0];
     s->dstptr     = s->frame.data[0];
     s->srcptr     = avpkt->data + 4;
diff --git a/mythtv/external/FFmpeg/libavcodec/zmbv.c b/mythtv/external/FFmpeg/libavcodec/zmbv.c
index 4e5d16f7e4c..47b3468fe7c 100644
--- a/mythtv/external/FFmpeg/libavcodec/zmbv.c
+++ b/mythtv/external/FFmpeg/libavcodec/zmbv.c
@@ -65,6 +65,7 @@ typedef struct ZmbvContext {
     int fmt;
     int comp;
     int flags;
+    int stride;
     int bw, bh, bx, by;
     int decomp_len;
     z_stream zstream;
@@ -410,13 +411,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
     if (c->pic.data[0])
             avctx->release_buffer(avctx, &c->pic);
 
-    c->pic.reference = 3;
-    c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
-    if ((ret = ff_get_buffer(avctx, &c->pic)) < 0) {
-        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
-        return ret;
-    }
-
     /* parse header */
     c->flags = buf[0];
     buf++; len--;
@@ -458,24 +452,35 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
             c->bpp = 8;
             decode_intra = zmbv_decode_intra;
             c->decode_xor = zmbv_decode_xor_8;
+            avctx->pix_fmt = AV_PIX_FMT_PAL8;
+            c->stride = c->width;
             break;
         case ZMBV_FMT_15BPP:
         case ZMBV_FMT_16BPP:
             c->bpp = 16;
             decode_intra = zmbv_decode_intra;
             c->decode_xor = zmbv_decode_xor_16;
+            if (c->fmt == ZMBV_FMT_15BPP)
+                avctx->pix_fmt = AV_PIX_FMT_RGB555LE;
+            else
+                avctx->pix_fmt = AV_PIX_FMT_RGB565LE;
+            c->stride = c->width * 2;
             break;
 #ifdef ZMBV_ENABLE_24BPP
         case ZMBV_FMT_24BPP:
             c->bpp = 24;
             decode_intra = zmbv_decode_intra;
             c->decode_xor = zmbv_decode_xor_24;
+            avctx->pix_fmt = AV_PIX_FMT_RGB24;
+            c->stride = c->width * 3;
             break;
 #endif //ZMBV_ENABLE_24BPP
         case ZMBV_FMT_32BPP:
             c->bpp = 32;
             decode_intra = zmbv_decode_intra;
             c->decode_xor = zmbv_decode_xor_32;
+            avctx->pix_fmt = AV_PIX_FMT_BGR0;
+            c->stride = c->width * 4;
             break;
         default:
             c->decode_xor = NULL;
@@ -487,7 +492,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
         zret = inflateReset(&c->zstream);
         if (zret != Z_OK) {
             av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
-            return -1;
+            return AVERROR_UNKNOWN;
         }
 
         c->cur  = av_realloc_f(c->cur, avctx->width * avctx->height,  (c->bpp / 8));
@@ -506,6 +511,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
         return AVERROR_INVALIDDATA;
     }
 
+    c->pic.reference = 3;
+    c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
+    if ((ret = ff_get_buffer(avctx, &c->pic)) < 0) {
+        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+        return ret;
+    }
+
     if (c->comp == 0) { //Uncompressed data
         if (c->decomp_size < len) {
             av_log(avctx, AV_LOG_ERROR, "decomp buffer too small\n");
@@ -539,62 +551,23 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
     /* update frames */
     {
         uint8_t *out, *src;
-        int i, j;
+        int j;
 
         out = c->pic.data[0];
         src = c->cur;
         switch (c->fmt) {
         case ZMBV_FMT_8BPP:
-            for (j = 0; j < c->height; j++) {
-                for (i = 0; i < c->width; i++) {
-                    out[i * 3 + 0] = c->pal[(*src) * 3 + 0];
-                    out[i * 3 + 1] = c->pal[(*src) * 3 + 1];
-                    out[i * 3 + 2] = c->pal[(*src) * 3 + 2];
-                    src++;
-                }
-                out += c->pic.linesize[0];
-            }
-            break;
+            for (j = 0; j < 256; j++)
+                AV_WN32(&c->pic.data[1][j * 4], 0xFFU << 24 | AV_RB24(&c->pal[j * 3]));
         case ZMBV_FMT_15BPP:
-            for (j = 0; j < c->height; j++) {
-                for (i = 0; i < c->width; i++) {
-                    uint16_t tmp = AV_RL16(src);
-                    src += 2;
-                    out[i * 3 + 0] = (tmp & 0x7C00) >> 7;
-                    out[i * 3 + 1] = (tmp & 0x03E0) >> 2;
-                    out[i * 3 + 2] = (tmp & 0x001F) << 3;
-                }
-                out += c->pic.linesize[0];
-            }
-            break;
         case ZMBV_FMT_16BPP:
-            for (j = 0; j < c->height; j++) {
-                for (i = 0; i < c->width; i++) {
-                    uint16_t tmp = AV_RL16(src);
-                    src += 2;
-                    out[i * 3 + 0] = (tmp & 0xF800) >> 8;
-                    out[i * 3 + 1] = (tmp & 0x07E0) >> 3;
-                    out[i * 3 + 2] = (tmp & 0x001F) << 3;
-                }
-                out += c->pic.linesize[0];
-            }
-            break;
 #ifdef ZMBV_ENABLE_24BPP
         case ZMBV_FMT_24BPP:
-            for (j = 0; j < c->height; j++) {
-                memcpy(out, src, c->width * 3);
-                src += c->width * 3;
-                out += c->pic.linesize[0];
-            }
-            break;
-#endif //ZMBV_ENABLE_24BPP
+#endif
         case ZMBV_FMT_32BPP:
             for (j = 0; j < c->height; j++) {
-                for (i = 0; i < c->width; i++) {
-                    uint32_t tmp = AV_RL32(src);
-                    src += 4;
-                    AV_WB24(out+(i*3), tmp);
-                }
+                memcpy(out, src, c->stride);
+                src += c->stride;
                 out += c->pic.linesize[0];
             }
             break;
@@ -626,7 +599,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
     // Needed if zlib unused or init aborted before inflateInit
     memset(&c->zstream, 0, sizeof(z_stream));
 
-    avctx->pix_fmt = AV_PIX_FMT_RGB24;
     c->decomp_size = (avctx->width + 255) * 4 * (avctx->height + 64);
 
     /* Allocate decompression buffer */
@@ -644,7 +616,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     zret = inflateInit(&c->zstream);
     if (zret != Z_OK) {
         av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
-        return -1;
+        return AVERROR_UNKNOWN;
     }
 
     return 0;
diff --git a/mythtv/external/FFmpeg/libavdevice/alsa-audio-common.c b/mythtv/external/FFmpeg/libavdevice/alsa-audio-common.c
index afe67510d7e..4e63397380f 100644
--- a/mythtv/external/FFmpeg/libavdevice/alsa-audio-common.c
+++ b/mythtv/external/FFmpeg/libavdevice/alsa-audio-common.c
@@ -62,48 +62,45 @@ static av_cold snd_pcm_format_t codec_id_to_pcm_format(int codec_id)
     }
 }
 
-#define REORDER_OUT_50(NAME, TYPE) \
-static void alsa_reorder_ ## NAME ## _out_50(const void *in_v, void *out_v, int n) \
-{ \
-    const TYPE *in = in_v; \
-    TYPE      *out = out_v; \
-\
-    while (n-- > 0) { \
+#define MAKE_REORDER_FUNC(NAME, TYPE, CHANNELS, LAYOUT, MAP)                \
+static void alsa_reorder_ ## NAME ## _ ## LAYOUT(const void *in_v,          \
+                                                 void *out_v,               \
+                                                 int n)                     \
+{                                                                           \
+    const TYPE *in = in_v;                                                  \
+    TYPE      *out = out_v;                                                 \
+                                                                            \
+    while (n-- > 0) {                                                       \
+        MAP                                                                 \
+        in  += CHANNELS;                                                    \
+        out += CHANNELS;                                                    \
+    }                                                                       \
+}
+
+#define MAKE_REORDER_FUNCS(CHANNELS, LAYOUT, MAP) \
+    MAKE_REORDER_FUNC(int8,  int8_t,  CHANNELS, LAYOUT, MAP) \
+    MAKE_REORDER_FUNC(int16, int16_t, CHANNELS, LAYOUT, MAP) \
+    MAKE_REORDER_FUNC(int32, int32_t, CHANNELS, LAYOUT, MAP) \
+    MAKE_REORDER_FUNC(f32,   float,   CHANNELS, LAYOUT, MAP)
+
+MAKE_REORDER_FUNCS(5, out_50, \
         out[0] = in[0]; \
         out[1] = in[1]; \
         out[2] = in[3]; \
         out[3] = in[4]; \
         out[4] = in[2]; \
-        in  += 5; \
-        out += 5; \
-    } \
-}
+        );
 
-#define REORDER_OUT_51(NAME, TYPE) \
-static void alsa_reorder_ ## NAME ## _out_51(const void *in_v, void *out_v, int n) \
-{ \
-    const TYPE *in = in_v; \
-    TYPE      *out = out_v; \
-\
-    while (n-- > 0) { \
+MAKE_REORDER_FUNCS(6, out_51, \
         out[0] = in[0]; \
         out[1] = in[1]; \
         out[2] = in[4]; \
         out[3] = in[5]; \
         out[4] = in[2]; \
         out[5] = in[3]; \
-        in  += 6; \
-        out += 6; \
-    } \
-}
+        );
 
-#define REORDER_OUT_71(NAME, TYPE) \
-static void alsa_reorder_ ## NAME ## _out_71(const void *in_v, void *out_v, int n) \
-{ \
-    const TYPE *in = in_v; \
-    TYPE      *out = out_v; \
-\
-    while (n-- > 0) { \
+MAKE_REORDER_FUNCS(8, out_71, \
         out[0] = in[0]; \
         out[1] = in[1]; \
         out[2] = in[4]; \
@@ -112,23 +109,7 @@ static void alsa_reorder_ ## NAME ## _out_71(const void *in_v, void *out_v, int
         out[5] = in[3]; \
         out[6] = in[6]; \
         out[7] = in[7]; \
-        in  += 8; \
-        out += 8; \
-    } \
-}
-
-REORDER_OUT_50(int8, int8_t)
-REORDER_OUT_51(int8, int8_t)
-REORDER_OUT_71(int8, int8_t)
-REORDER_OUT_50(int16, int16_t)
-REORDER_OUT_51(int16, int16_t)
-REORDER_OUT_71(int16, int16_t)
-REORDER_OUT_50(int32, int32_t)
-REORDER_OUT_51(int32, int32_t)
-REORDER_OUT_71(int32, int32_t)
-REORDER_OUT_50(f32, float)
-REORDER_OUT_51(f32, float)
-REORDER_OUT_71(f32, float)
+        );
 
 #define FORMAT_I8  0
 #define FORMAT_I16 1
diff --git a/mythtv/external/FFmpeg/libavdevice/dshow.c b/mythtv/external/FFmpeg/libavdevice/dshow.c
index 83b5e01042c..4991414e6b4 100644
--- a/mythtv/external/FFmpeg/libavdevice/dshow.c
+++ b/mythtv/external/FFmpeg/libavdevice/dshow.c
@@ -23,8 +23,10 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/opt.h"
 #include "libavformat/internal.h"
+#include "libavformat/riff.h"
 #include "avdevice.h"
 #include "dshow_capture.h"
+#include "libavcodec/raw.h"
 
 struct dshow_ctx {
     const AVClass *class;
@@ -73,12 +75,6 @@ struct dshow_ctx {
 static enum AVPixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount)
 {
     switch(biCompression) {
-    case MKTAG('U', 'Y', 'V', 'Y'):
-        return AV_PIX_FMT_UYVY422;
-    case MKTAG('Y', 'U', 'Y', '2'):
-        return AV_PIX_FMT_YUYV422;
-    case MKTAG('I', '4', '2', '0'):
-        return AV_PIX_FMT_YUV420P;
     case BI_BITFIELDS:
     case BI_RGB:
         switch(biBitCount) { /* 1-8 are untested */
@@ -96,19 +92,7 @@ static enum AVPixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount)
                 return AV_PIX_FMT_RGB32;
         }
     }
-    return AV_PIX_FMT_NONE;
-}
-
-static enum AVCodecID dshow_codecid(DWORD biCompression)
-{
-    switch(biCompression) {
-    case MKTAG('d', 'v', 's', 'd'):
-        return AV_CODEC_ID_DVVIDEO;
-    case MKTAG('M', 'J', 'P', 'G'):
-    case MKTAG('m', 'j', 'p', 'g'):
-        return AV_CODEC_ID_MJPEG;
-    }
-    return AV_CODEC_ID_NONE;
+    return avpriv_find_pix_fmt(ff_raw_pix_fmt_tags, biCompression); // all others
 }
 
 static int
@@ -386,7 +370,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
             if (!pformat_set) {
                 enum AVPixelFormat pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount);
                 if (pix_fmt == AV_PIX_FMT_NONE) {
-                    enum AVCodecID codec_id = dshow_codecid(bih->biCompression);
+                    enum AVCodecID codec_id = ff_codec_get_id(avformat_get_riff_video_tags(), bih->biCompression);
                     AVCodec *codec = avcodec_find_decoder(codec_id);
                     if (codec_id == AV_CODEC_ID_NONE || !codec) {
                         av_log(avctx, AV_LOG_INFO, "  unknown compression type 0x%X", (int) bih->biCompression);
@@ -404,7 +388,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
                 continue;
             }
             if (ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO) {
-                if (ctx->video_codec_id != dshow_codecid(bih->biCompression))
+                if (ctx->video_codec_id != ff_codec_get_id(avformat_get_riff_video_tags(), bih->biCompression))
                     goto next;
             }
             if (ctx->pixel_format != AV_PIX_FMT_NONE &&
@@ -790,11 +774,15 @@ dshow_add_device(AVFormatContext *avctx,
         codec->width      = bih->biWidth;
         codec->height     = bih->biHeight;
         codec->pix_fmt    = dshow_pixfmt(bih->biCompression, bih->biBitCount);
+        if(bih->biCompression == MKTAG('H', 'D', 'Y', 'C')) {
+          av_log(avctx, AV_LOG_DEBUG, "attempt use full range for HDYC...");
+          codec->color_range = AVCOL_RANGE_MPEG; // just in case it needs this...
+        }
         if (codec->pix_fmt == AV_PIX_FMT_NONE) {
-            codec->codec_id = dshow_codecid(bih->biCompression);
+            codec->codec_id = ff_codec_get_id(avformat_get_riff_video_tags(), bih->biCompression);
             if (codec->codec_id == AV_CODEC_ID_NONE) {
                 av_log(avctx, AV_LOG_ERROR, "Unknown compression type. "
-                                 "Please report verbose (-v 9) debug information.\n");
+                                 "Please report type 0x%X.\n", (int) bih->biCompression);
                 return AVERROR_PATCHWELCOME;
             }
             codec->bits_per_coded_sample = bih->biBitCount;
diff --git a/mythtv/external/FFmpeg/libavdevice/lavfi.c b/mythtv/external/FFmpeg/libavdevice/lavfi.c
index e4cacb640e1..3b6f0c382cb 100644
--- a/mythtv/external/FFmpeg/libavdevice/lavfi.c
+++ b/mythtv/external/FFmpeg/libavdevice/lavfi.c
@@ -282,6 +282,10 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx)
             st->codec->height     = link->h;
             st       ->sample_aspect_ratio =
             st->codec->sample_aspect_ratio = link->sample_aspect_ratio;
+            avctx->probesize = FFMAX(avctx->probesize,
+                                     link->w * link->h *
+                                     av_get_padded_bits_per_pixel(av_pix_fmt_desc_get(link->format)) *
+                                     30);
         } else if (link->type == AVMEDIA_TYPE_AUDIO) {
             st->codec->codec_id    = av_get_pcm_codec(link->format, -1);
             st->codec->channels    = av_get_channel_layout_nb_channels(link->channel_layout);
diff --git a/mythtv/external/FFmpeg/libavdevice/v4l2.c b/mythtv/external/FFmpeg/libavdevice/v4l2.c
index b2e5fed27d5..6726b0b89fa 100644
--- a/mythtv/external/FFmpeg/libavdevice/v4l2.c
+++ b/mythtv/external/FFmpeg/libavdevice/v4l2.c
@@ -24,7 +24,7 @@
  * Video4Linux2 grab interface
  *
  * Part of this file is based on the V4L2 video capture example
- * (http://v4l2spec.bytesex.org/v4l2spec/capture.c)
+ * (http://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html)
  *
  * Thanks to Michael Niedermayer for providing the mapping between
  * V4L2_PIX_FMT_* and AV_PIX_FMT_*
@@ -111,16 +111,20 @@ struct video_data {
     int buffers;
     void **buf_start;
     unsigned int *buf_len;
+    int *buf_dequeued;
     char *standard;
+    v4l2_std_id std_id;
     int channel;
     char *pixel_format; /**< Set by a private option. */
     int list_format;    /**< Set by a private option. */
+    int list_standard;  /**< Set by a private option. */
     char *framerate;    /**< Set by a private option. */
 };
 
 struct buff_data {
     int index;
     int fd;
+    int *buf_dequeued;
 };
 
 struct fmt_map {
@@ -138,6 +142,7 @@ static struct fmt_map fmt_conversion_table[] = {
     { AV_PIX_FMT_UYVY422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_UYVY    },
     { AV_PIX_FMT_YUV411P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV411P },
     { AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV410  },
+    { AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YVU410  },
     { AV_PIX_FMT_RGB555LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555  },
     { AV_PIX_FMT_RGB555BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555X },
     { AV_PIX_FMT_RGB565LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565  },
@@ -147,6 +152,9 @@ static struct fmt_map fmt_conversion_table[] = {
     { AV_PIX_FMT_BGR0,    AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR32   },
     { AV_PIX_FMT_0RGB,    AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB32   },
     { AV_PIX_FMT_GRAY8,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_GREY    },
+#ifdef V4L2_PIX_FMT_Y16
+    { AV_PIX_FMT_GRAY16LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_Y16     },
+#endif
     { AV_PIX_FMT_NV12,    AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV12    },
     { AV_PIX_FMT_NONE,    AV_CODEC_ID_MJPEG,    V4L2_PIX_FMT_MJPEG   },
     { AV_PIX_FMT_NONE,    AV_CODEC_ID_MJPEG,    V4L2_PIX_FMT_JPEG    },
@@ -162,7 +170,7 @@ static int device_open(AVFormatContext *ctx)
 {
     struct v4l2_capability cap;
     int fd;
-    int res, err;
+    int ret;
     int flags = O_RDWR;
 
     if (ctx->flags & AVFMT_FLAG_NONBLOCK) {
@@ -171,38 +179,32 @@ static int device_open(AVFormatContext *ctx)
 
     fd = v4l2_open(ctx->filename, flags, 0);
     if (fd < 0) {
-        err = errno;
-
-        av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n",
-               ctx->filename, strerror(err));
-
-        return AVERROR(err);
+        ret = AVERROR(errno);
+        av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s: %s\n",
+               ctx->filename, av_err2str(ret));
+        return ret;
     }
 
-    res = v4l2_ioctl(fd, VIDIOC_QUERYCAP, &cap);
-    if (res < 0) {
-        err = errno;
+    if (v4l2_ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) {
+        ret = AVERROR(errno);
         av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
-               strerror(err));
-
+               av_err2str(ret));
         goto fail;
     }
 
-    av_log(ctx, AV_LOG_VERBOSE, "[%d]Capabilities: %x\n",
+    av_log(ctx, AV_LOG_VERBOSE, "fd:%d capabilities:%x\n",
            fd, cap.capabilities);
 
     if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
         av_log(ctx, AV_LOG_ERROR, "Not a video capture device.\n");
-        err = ENODEV;
-
+        ret = AVERROR(ENODEV);
         goto fail;
     }
 
     if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
         av_log(ctx, AV_LOG_ERROR,
                "The device does not support the streaming I/O method.\n");
-        err = ENOSYS;
-
+        ret = AVERROR(ENOSYS);
         goto fail;
     }
 
@@ -210,7 +212,7 @@ static int device_open(AVFormatContext *ctx)
 
 fail:
     v4l2_close(fd);
-    return AVERROR(err);
+    return ret;
 }
 
 static int device_init(AVFormatContext *ctx, int *width, int *height,
@@ -221,14 +223,15 @@ static int device_init(AVFormatContext *ctx, int *width, int *height,
     struct v4l2_format fmt = { .type = V4L2_BUF_TYPE_VIDEO_CAPTURE };
     struct v4l2_pix_format *pix = &fmt.fmt.pix;
 
-    int res;
+    int res = 0;
 
     pix->width = *width;
     pix->height = *height;
     pix->pixelformat = pix_fmt;
     pix->field = V4L2_FIELD_ANY;
 
-    res = v4l2_ioctl(fd, VIDIOC_S_FMT, &fmt);
+    if (v4l2_ioctl(fd, VIDIOC_S_FMT, &fmt) < 0)
+        res = AVERROR(errno);
 
     if ((*width != fmt.fmt.pix.width) || (*height != fmt.fmt.pix.height)) {
         av_log(ctx, AV_LOG_INFO,
@@ -243,11 +246,12 @@ static int device_init(AVFormatContext *ctx, int *width, int *height,
                "The V4L2 driver changed the pixel format "
                "from 0x%08X to 0x%08X\n",
                pix_fmt, fmt.fmt.pix.pixelformat);
-        res = -1;
+        res = AVERROR(EINVAL);
     }
 
     if (fmt.fmt.pix.field == V4L2_FIELD_INTERLACED) {
-        av_log(ctx, AV_LOG_DEBUG, "The V4L2 driver using the interlaced mode");
+        av_log(ctx, AV_LOG_DEBUG,
+               "The V4L2 driver is using the interlaced mode\n");
         s->interlaced = 1;
     }
 
@@ -352,13 +356,13 @@ static void list_formats(AVFormatContext *ctx, int fd, int type)
         if (!(vfd.flags & V4L2_FMT_FLAG_COMPRESSED) &&
             type & V4L_RAWFORMATS) {
             const char *fmt_name = av_get_pix_fmt_name(pix_fmt);
-            av_log(ctx, AV_LOG_INFO, "R : %9s : %20s :",
+            av_log(ctx, AV_LOG_INFO, "Raw       : %9s : %20s :",
                    fmt_name ? fmt_name : "Unsupported",
                    vfd.description);
         } else if (vfd.flags & V4L2_FMT_FLAG_COMPRESSED &&
                    type & V4L_COMPFORMATS) {
-            AVCodec *codec = avcodec_find_encoder(codec_id);
-            av_log(ctx, AV_LOG_INFO, "C : %9s : %20s :",
+            AVCodec *codec = avcodec_find_decoder(codec_id);
+            av_log(ctx, AV_LOG_INFO, "Compressed: %9s : %20s :",
                    codec ? codec->name : "Unsupported",
                    vfd.description);
         } else {
@@ -378,6 +382,30 @@ static void list_formats(AVFormatContext *ctx, int fd, int type)
     }
 }
 
+static void list_standards(AVFormatContext *ctx)
+{
+    int ret;
+    struct video_data *s = ctx->priv_data;
+    struct v4l2_standard standard;
+
+    if (s->std_id == 0)
+        return;
+
+    for (standard.index = 0; ; standard.index++) {
+        if (v4l2_ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {
+            ret = AVERROR(errno);
+            if (ret == AVERROR(EINVAL)) {
+                break;
+            } else {
+                av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_ENUMSTD): %s\n", av_err2str(ret));
+                return;
+            }
+        }
+        av_log(ctx, AV_LOG_INFO, "%2d, %16llx, %s\n",
+               standard.index, standard.id, standard.name);
+    }
+}
+
 static int mmap_init(AVFormatContext *ctx)
 {
     int i, res;
@@ -388,14 +416,10 @@ static int mmap_init(AVFormatContext *ctx)
         .memory = V4L2_MEMORY_MMAP
     };
 
-    res = v4l2_ioctl(s->fd, VIDIOC_REQBUFS, &req);
-    if (res < 0) {
-        if (errno == EINVAL) {
-            av_log(ctx, AV_LOG_ERROR, "Device does not support mmap\n");
-        } else {
-            av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n");
-        }
-        return AVERROR(errno);
+    if (v4l2_ioctl(s->fd, VIDIOC_REQBUFS, &req) < 0) {
+        res = AVERROR(errno);
+        av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS): %s\n", av_err2str(res));
+        return res;
     }
 
     if (req.count < 2) {
@@ -414,6 +438,11 @@ static int mmap_init(AVFormatContext *ctx)
         av_free(s->buf_start);
         return AVERROR(ENOMEM);
     }
+    s->buf_dequeued = av_mallocz(sizeof(int) * s->buffers);
+    if (s->buf_dequeued == NULL) {
+        av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer array\n");
+        return AVERROR(ENOMEM);
+    }
 
     for (i = 0; i < req.count; i++) {
         struct v4l2_buffer buf = {
@@ -421,53 +450,65 @@ static int mmap_init(AVFormatContext *ctx)
             .index  = i,
             .memory = V4L2_MEMORY_MMAP
         };
-        res = v4l2_ioctl(s->fd, VIDIOC_QUERYBUF, &buf);
-        if (res < 0) {
-            av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n");
-            return AVERROR(errno);
+        if (v4l2_ioctl(s->fd, VIDIOC_QUERYBUF, &buf) < 0) {
+            res = AVERROR(errno);
+            av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF): %s\n", av_err2str(res));
+            return res;
         }
 
         s->buf_len[i] = buf.length;
         if (s->frame_size > 0 && s->buf_len[i] < s->frame_size) {
             av_log(ctx, AV_LOG_ERROR,
-                   "Buffer len [%d] = %d != %d\n",
+                   "buf_len[%d] = %d < expected frame size %d\n",
                    i, s->buf_len[i], s->frame_size);
-
-            return -1;
+            return AVERROR(ENOMEM);
         }
         s->buf_start[i] = v4l2_mmap(NULL, buf.length,
                                PROT_READ | PROT_WRITE, MAP_SHARED,
                                s->fd, buf.m.offset);
 
         if (s->buf_start[i] == MAP_FAILED) {
-            av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", strerror(errno));
-            return AVERROR(errno);
+            res = AVERROR(errno);
+            av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", av_err2str(res));
+            return res;
         }
     }
 
     return 0;
 }
 
-static void mmap_release_buffer(AVPacket *pkt)
+static int enqueue_buffer(int fd, int index)
 {
+    int res;
     struct v4l2_buffer buf = { 0 };
-    int res, fd;
+
+    buf.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    buf.memory = V4L2_MEMORY_MMAP;
+    buf.index  = index;
+
+    if (v4l2_ioctl(fd, VIDIOC_QBUF, &buf) < 0) {
+        res = AVERROR(errno);
+        av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", av_err2str(res));
+        return res;
+    }
+    return 0;
+}
+
+static void mmap_release_buffer(AVPacket *pkt)
+{
     struct buff_data *buf_descriptor = pkt->priv;
 
     if (pkt->data == NULL)
         return;
 
-    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-    buf.memory = V4L2_MEMORY_MMAP;
-    buf.index = buf_descriptor->index;
-    fd = buf_descriptor->fd;
+    if (buf_descriptor->index == -1) {
+        av_free(pkt->data);
+    } else {
+        if (!enqueue_buffer(buf_descriptor->fd, buf_descriptor->index))
+            buf_descriptor->buf_dequeued[buf_descriptor->index] = 0;
+    }
     av_free(buf_descriptor);
 
-    res = v4l2_ioctl(fd, VIDIOC_QBUF, &buf);
-    if (res < 0)
-        av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n",
-               strerror(errno));
-
     pkt->data = NULL;
     pkt->size = 0;
 }
@@ -498,8 +539,8 @@ static int init_convert_timestamp(AVFormatContext *ctx, int64_t ts)
     now = av_gettime_monotonic();
     if (s->ts_mode == V4L_TS_MONO2ABS ||
         (ts <= now + 1 * AV_TIME_BASE && ts >= now - 10 * AV_TIME_BASE)) {
-        int64_t period = av_rescale_q(1, ctx->streams[0]->codec->time_base,
-                                      AV_TIME_BASE_Q);
+        int64_t period = av_rescale_q(1, AV_TIME_BASE_Q,
+                                      ctx->streams[0]->avg_frame_rate);
         av_log(ctx, AV_LOG_INFO, "Detected monotonic timestamps, converting\n");
         /* microseconds instead of seconds, MHz instead of Hz */
         s->timefilter = ff_timefilter_new(1, period, 1.0E-6);
@@ -540,21 +581,22 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
         .memory = V4L2_MEMORY_MMAP
     };
     struct buff_data *buf_descriptor;
-    int res;
+    int res, i, free_buffers;
 
     /* FIXME: Some special treatment might be needed in case of loss of signal... */
     while ((res = v4l2_ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && (errno == EINTR));
     if (res < 0) {
-        if (errno == EAGAIN) {
-            pkt->size = 0;
+        if (errno == EAGAIN)
             return AVERROR(EAGAIN);
-        }
-        av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n",
-               strerror(errno));
+        res = AVERROR(errno);
+        av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", av_err2str(res));
+        return res;
+    }
 
-        return AVERROR(errno);
+    if (buf.index >= s->buffers) {
+        av_log(ctx, AV_LOG_ERROR, "Invalid buffer index received.\n");
+        return AVERROR(EINVAL);
     }
-    av_assert0(buf.index < s->buffers);
 
     /* CPIA is a compressed format and we don't know the exact number of bytes
      * used by a frame, so set it here as the driver announces it.
@@ -566,18 +608,10 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
         av_log(ctx, AV_LOG_ERROR,
                "The v4l2 frame is %d bytes, but %d bytes are expected\n",
                buf.bytesused, s->frame_size);
-
+        enqueue_buffer(s->fd, buf.index);
         return AVERROR_INVALIDDATA;
     }
 
-    /* Image is at s->buff_start[buf.index] */
-    pkt->data= s->buf_start[buf.index];
-    pkt->size = buf.bytesused;
-    pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec;
-    res = convert_timestamp(ctx, &pkt->pts);
-    if (res < 0)
-        return res;
-    pkt->destruct = mmap_release_buffer;
     buf_descriptor = av_malloc(sizeof(struct buff_data));
     if (buf_descriptor == NULL) {
         /* Something went wrong... Since av_malloc() failed, we cannot even
@@ -585,12 +619,39 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
          */
         av_log(ctx, AV_LOG_ERROR, "Failed to allocate a buffer descriptor\n");
         res = v4l2_ioctl(s->fd, VIDIOC_QBUF, &buf);
-
         return AVERROR(ENOMEM);
     }
     buf_descriptor->fd = s->fd;
-    buf_descriptor->index = buf.index;
+    buf_descriptor->buf_dequeued = s->buf_dequeued;
+
+    free_buffers = -1; /* start from -1 because we just dequeued a buffer */
+    for (i = 0; i < s->buffers; i++)
+        if (s->buf_dequeued[i] == 0)
+            free_buffers++;
+
+    if (free_buffers == 0) {
+        if ((res = av_new_packet(pkt, buf.bytesused)) < 0) {
+            enqueue_buffer(s->fd, buf.index);
+            return res;
+        }
+        memcpy(pkt->data, s->buf_start[buf.index], buf.bytesused);
+        enqueue_buffer(s->fd, buf.index);
+        buf_descriptor->index = -1;
+    } else {
+        /* Image is at s->buff_start[buf.index] */
+        pkt->data = s->buf_start[buf.index];
+        buf_descriptor->index = buf.index;
+        buf_descriptor->buf_dequeued[buf.index] = 1;
+    }
+    pkt->size = buf.bytesused;
     pkt->priv = buf_descriptor;
+    pkt->destruct = mmap_release_buffer;
+    pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec;
+    res = convert_timestamp(ctx, &pkt->pts);
+    if (res < 0) {
+        mmap_release_buffer(pkt);
+        return res;
+    }
 
     return s->buf_len[buf.index];
 }
@@ -608,22 +669,18 @@ static int mmap_start(AVFormatContext *ctx)
             .memory = V4L2_MEMORY_MMAP
         };
 
-        res = v4l2_ioctl(s->fd, VIDIOC_QBUF, &buf);
-        if (res < 0) {
-            av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n",
-                   strerror(errno));
-
-            return AVERROR(errno);
+        if (v4l2_ioctl(s->fd, VIDIOC_QBUF, &buf) < 0) {
+            res = AVERROR(errno);
+            av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", av_err2str(res));
+            return res;
         }
     }
 
     type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-    res = v4l2_ioctl(s->fd, VIDIOC_STREAMON, &type);
-    if (res < 0) {
-        av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n",
-               strerror(errno));
-
-        return AVERROR(errno);
+    if (v4l2_ioctl(s->fd, VIDIOC_STREAMON, &type) < 0) {
+        res = AVERROR(errno);
+        av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n", av_err2str(res));
+        return res;
     }
 
     return 0;
@@ -644,20 +701,18 @@ static void mmap_close(struct video_data *s)
     }
     av_free(s->buf_start);
     av_free(s->buf_len);
+    av_free(s->buf_dequeued);
 }
 
 static int v4l2_set_parameters(AVFormatContext *s1)
 {
     struct video_data *s = s1->priv_data;
-    struct v4l2_input input = { 0 };
     struct v4l2_standard standard = { 0 };
     struct v4l2_streamparm streamparm = { 0 };
-    struct v4l2_fract *tpf = &streamparm.parm.capture.timeperframe;
+    struct v4l2_fract *tpf;
     AVRational framerate_q = { 0 };
     int i, ret;
 
-    streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-
     if (s->framerate &&
         (ret = av_parse_video_rate(&framerate_q, s->framerate)) < 0) {
         av_log(s1, AV_LOG_ERROR, "Could not parse framerate '%s'.\n",
@@ -665,113 +720,149 @@ static int v4l2_set_parameters(AVFormatContext *s1)
         return ret;
     }
 
-    /* set tv video input */
-    input.index = s->channel;
-    if (v4l2_ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
-        av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n");
-        return AVERROR(EIO);
-    }
+    if (s->standard) {
+        if (s->std_id) {
+            ret = 0;
+            av_log(s1, AV_LOG_DEBUG, "Setting standard: %s\n", s->standard);
+            /* set tv standard */
+            for (i = 0; ; i++) {
+                standard.index = i;
+                if (v4l2_ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {
+                    ret = AVERROR(errno);
+                    break;
+                }
+                if (!av_strcasecmp(standard.name, s->standard))
+                    break;
+            }
+            if (ret < 0) {
+                av_log(s1, AV_LOG_ERROR, "Unknown or unsupported standard '%s'\n", s->standard);
+                return ret;
+            }
 
-    av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n",
-            s->channel, input.name);
-    if (v4l2_ioctl(s->fd, VIDIOC_S_INPUT, &input.index) < 0) {
-        av_log(s1, AV_LOG_ERROR,
-               "The V4L2 driver ioctl set input(%d) failed\n",
-                s->channel);
-        return AVERROR(EIO);
+            if (v4l2_ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) {
+                ret = AVERROR(errno);
+                av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_S_STD): %s\n", av_err2str(ret));
+                return ret;
+            }
+        } else {
+            av_log(s1, AV_LOG_WARNING,
+                   "This device does not support any standard\n");
+        }
     }
 
-    if (s->standard) {
-        av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n",
-               s->standard);
-        /* set tv standard */
-        for(i=0;;i++) {
+    /* get standard */
+    if (v4l2_ioctl(s->fd, VIDIOC_G_STD, &s->std_id) == 0) {
+        tpf = &standard.frameperiod;
+        for (i = 0; ; i++) {
             standard.index = i;
-            ret = v4l2_ioctl(s->fd, VIDIOC_ENUMSTD, &standard);
-            if (ret < 0 || !av_strcasecmp(standard.name, s->standard))
+            if (v4l2_ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {
+                ret = AVERROR(errno);
+                av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_ENUMSTD): %s\n", av_err2str(ret));
+                return ret;
+            }
+            if (standard.id == s->std_id) {
+                av_log(s1, AV_LOG_DEBUG,
+                       "Current standard: %s, id: %"PRIu64", frameperiod: %d/%d\n",
+                       standard.name, (uint64_t)standard.id, tpf->numerator, tpf->denominator);
                 break;
+            }
         }
-        if (ret < 0) {
-            av_log(s1, AV_LOG_ERROR, "Unknown standard '%s'\n", s->standard);
-            return ret;
-        }
+    } else {
+        tpf = &streamparm.parm.capture.timeperframe;
+    }
 
-        av_log(s1, AV_LOG_DEBUG,
-               "The V4L2 driver set standard: %s, id: %"PRIu64"\n",
-               s->standard, (uint64_t)standard.id);
-        if (v4l2_ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) {
-            av_log(s1, AV_LOG_ERROR,
-                   "The V4L2 driver ioctl set standard(%s) failed\n",
-                   s->standard);
-            return AVERROR(EIO);
-        }
+    streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    if (v4l2_ioctl(s->fd, VIDIOC_G_PARM, &streamparm) < 0) {
+        ret = AVERROR(errno);
+        av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %s\n", av_err2str(ret));
+        return ret;
     }
 
     if (framerate_q.num && framerate_q.den) {
-        av_log(s1, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n",
-               framerate_q.den, framerate_q.num);
-        tpf->numerator   = framerate_q.den;
-        tpf->denominator = framerate_q.num;
-
-        if (v4l2_ioctl(s->fd, VIDIOC_S_PARM, &streamparm) != 0) {
-            av_log(s1, AV_LOG_ERROR,
-                   "ioctl set time per frame(%d/%d) failed\n",
+        if (streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) {
+            tpf = &streamparm.parm.capture.timeperframe;
+
+            av_log(s1, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n",
                    framerate_q.den, framerate_q.num);
-            return AVERROR(EIO);
-        }
+            tpf->numerator   = framerate_q.den;
+            tpf->denominator = framerate_q.num;
 
-        if (framerate_q.num != tpf->denominator ||
-            framerate_q.den != tpf->numerator) {
-            av_log(s1, AV_LOG_INFO,
-                   "The driver changed the time per frame from "
-                   "%d/%d to %d/%d\n",
-                   framerate_q.den, framerate_q.num,
-                   tpf->numerator, tpf->denominator);
-        }
-    } else {
-        if (v4l2_ioctl(s->fd, VIDIOC_G_PARM, &streamparm) != 0) {
-            av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %s\n",
-                   strerror(errno));
-            return AVERROR(errno);
+            if (v4l2_ioctl(s->fd, VIDIOC_S_PARM, &streamparm) < 0) {
+                ret = AVERROR(errno);
+                av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_S_PARM): %s\n", av_err2str(ret));
+                return ret;
+            }
+
+            if (framerate_q.num != tpf->denominator ||
+                framerate_q.den != tpf->numerator) {
+                av_log(s1, AV_LOG_INFO,
+                       "The driver changed the time per frame from "
+                       "%d/%d to %d/%d\n",
+                       framerate_q.den, framerate_q.num,
+                       tpf->numerator, tpf->denominator);
+            }
+        } else {
+            av_log(s1, AV_LOG_WARNING,
+                   "The driver does not allow to change time per frame\n");
         }
     }
-    s1->streams[0]->codec->time_base.den = tpf->denominator;
-    s1->streams[0]->codec->time_base.num = tpf->numerator;
+    s1->streams[0]->avg_frame_rate.num = tpf->denominator;
+    s1->streams[0]->avg_frame_rate.den = tpf->numerator;
+    s1->streams[0]->r_frame_rate = s1->streams[0]->avg_frame_rate;
 
     return 0;
 }
 
-static uint32_t device_try_init(AVFormatContext *s1,
-                                enum AVPixelFormat pix_fmt,
-                                int *width,
-                                int *height,
-                                enum AVCodecID *codec_id)
+static int device_try_init(AVFormatContext *s1,
+                           enum AVPixelFormat pix_fmt,
+                           int *width,
+                           int *height,
+                           uint32_t *desired_format,
+                           enum AVCodecID *codec_id)
 {
-    uint32_t desired_format = fmt_ff2v4l(pix_fmt, s1->video_codec_id);
+    int ret, i;
 
-    if (desired_format == 0 ||
-        device_init(s1, width, height, desired_format) < 0) {
-        int i;
+    *desired_format = fmt_ff2v4l(pix_fmt, s1->video_codec_id);
 
-        desired_format = 0;
+    if (*desired_format) {
+        ret = device_init(s1, width, height, *desired_format);
+        if (ret < 0) {
+            *desired_format = 0;
+            if (ret != AVERROR(EINVAL))
+                return ret;
+        }
+    }
+
+    if (!*desired_format) {
         for (i = 0; ivideo_codec_id == AV_CODEC_ID_NONE ||
                 fmt_conversion_table[i].codec_id == s1->video_codec_id) {
-                desired_format = fmt_conversion_table[i].v4l2_fmt;
-                if (device_init(s1, width, height, desired_format) >= 0) {
+                av_log(s1, AV_LOG_DEBUG, "Trying to set codec:%s pix_fmt:%s\n",
+                       avcodec_get_name(fmt_conversion_table[i].codec_id),
+                       (char *)av_x_if_null(av_get_pix_fmt_name(fmt_conversion_table[i].ff_fmt), "none"));
+
+                *desired_format = fmt_conversion_table[i].v4l2_fmt;
+                ret = device_init(s1, width, height, *desired_format);
+                if (ret >= 0)
                     break;
-                }
-                desired_format = 0;
+                else if (ret != AVERROR(EINVAL))
+                    return ret;
+                *desired_format = 0;
             }
         }
-    }
 
-    if (desired_format != 0) {
-        *codec_id = fmt_v4l2codec(desired_format);
-        av_assert0(*codec_id != AV_CODEC_ID_NONE);
+        if (*desired_format == 0) {
+            av_log(s1, AV_LOG_ERROR, "Cannot find a proper format for "
+                   "codec '%s' (id %d), pixel format '%s' (id %d)\n",
+                   avcodec_get_name(s1->video_codec_id), s1->video_codec_id,
+                   (char *)av_x_if_null(av_get_pix_fmt_name(pix_fmt), "none"), pix_fmt);
+            ret = AVERROR(EINVAL);
+        }
     }
 
-    return desired_format;
+    *codec_id = fmt_v4l2codec(*desired_format);
+    av_assert0(*codec_id != AV_CODEC_ID_NONE);
+    return ret;
 }
 
 static int v4l2_read_header(AVFormatContext *s1)
@@ -782,23 +873,42 @@ static int v4l2_read_header(AVFormatContext *s1)
     uint32_t desired_format;
     enum AVCodecID codec_id = AV_CODEC_ID_NONE;
     enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
+    struct v4l2_input input = { 0 };
 
     st = avformat_new_stream(s1, NULL);
-    if (!st) {
-        res = AVERROR(ENOMEM);
-        goto out;
-    }
+    if (!st)
+        return AVERROR(ENOMEM);
 
     s->fd = device_open(s1);
-    if (s->fd < 0) {
-        res = s->fd;
-        goto out;
+    if (s->fd < 0)
+        return s->fd;
+
+    /* set tv video input */
+    av_log(s1, AV_LOG_DEBUG, "Selecting input_channel: %d\n", s->channel);
+    if (v4l2_ioctl(s->fd, VIDIOC_S_INPUT, &s->channel) < 0) {
+        res = AVERROR(errno);
+        av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_S_INPUT): %s\n", av_err2str(res));
+        return res;
+    }
+
+    input.index = s->channel;
+    if (v4l2_ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
+        res = AVERROR(errno);
+        av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_ENUMINPUT): %s\n", av_err2str(res));
+        return res;
     }
+    s->std_id = input.std;
+    av_log(s1, AV_LOG_DEBUG, "input_channel: %d, input_name: %s\n",
+           s->channel, input.name);
 
     if (s->list_format) {
         list_formats(s1, s->fd, s->list_format);
-        res = AVERROR_EXIT;
-        goto out;
+        return AVERROR_EXIT;
+    }
+
+    if (s->list_standard) {
+        list_standards(s1);
+        return AVERROR_EXIT;
     }
 
     avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
@@ -815,8 +925,7 @@ static int v4l2_read_header(AVFormatContext *s1)
             av_log(s1, AV_LOG_ERROR, "No such input format: %s.\n",
                    s->pixel_format);
 
-            res = AVERROR(EINVAL);
-            goto out;
+            return AVERROR(EINVAL);
         }
     }
 
@@ -827,10 +936,9 @@ static int v4l2_read_header(AVFormatContext *s1)
                "Querying the device for the current frame size\n");
         fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
         if (v4l2_ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) {
-            av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n",
-                   strerror(errno));
             res = AVERROR(errno);
-            goto out;
+            av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n", av_err2str(res));
+            return res;
         }
 
         s->width  = fmt.fmt.pix.width;
@@ -839,8 +947,11 @@ static int v4l2_read_header(AVFormatContext *s1)
                "Setting frame size to %dx%d\n", s->width, s->height);
     }
 
-    desired_format = device_try_init(s1, pix_fmt, &s->width, &s->height,
-                                     &codec_id);
+    res = device_try_init(s1, pix_fmt, &s->width, &s->height, &desired_format, &codec_id);
+    if (res < 0) {
+        v4l2_close(s->fd);
+        return res;
+    }
 
     /* If no pixel_format was specified, the codec_id was not known up
      * until now. Set video_codec_id in the context, as codec_id will
@@ -849,21 +960,13 @@ static int v4l2_read_header(AVFormatContext *s1)
     if (codec_id != AV_CODEC_ID_NONE && s1->video_codec_id == AV_CODEC_ID_NONE)
         s1->video_codec_id = codec_id;
 
-    if (desired_format == 0) {
-        av_log(s1, AV_LOG_ERROR, "Cannot find a proper format for "
-               "codec_id %d, pix_fmt %d.\n", s1->video_codec_id, pix_fmt);
-        v4l2_close(s->fd);
-
-        res = AVERROR(EIO);
-        goto out;
-    }
     if ((res = av_image_check_size(s->width, s->height, 0, s1)) < 0)
-        goto out;
+        return res;
 
     s->frame_format = desired_format;
 
     if ((res = v4l2_set_parameters(s1)) < 0)
-        goto out;
+        return res;
 
     st->codec->pix_fmt = fmt_v4l2ff(desired_format, codec_id);
     s->frame_size =
@@ -872,7 +975,7 @@ static int v4l2_read_header(AVFormatContext *s1)
     if ((res = mmap_init(s1)) ||
         (res = mmap_start(s1)) < 0) {
         v4l2_close(s->fd);
-        goto out;
+        return res;
     }
 
     s->top_field_first = first_field(s->fd);
@@ -884,12 +987,13 @@ static int v4l2_read_header(AVFormatContext *s1)
             avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
     if (desired_format == V4L2_PIX_FMT_YVU420)
         st->codec->codec_tag = MKTAG('Y', 'V', '1', '2');
+    else if (desired_format == V4L2_PIX_FMT_YVU410)
+        st->codec->codec_tag = MKTAG('Y', 'V', 'U', '9');
     st->codec->width = s->width;
     st->codec->height = s->height;
-    st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8;
+    st->codec->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8;
 
-out:
-    return res;
+    return 0;
 }
 
 static int v4l2_read_packet(AVFormatContext *s1, AVPacket *pkt)
@@ -899,6 +1003,8 @@ static int v4l2_read_packet(AVFormatContext *s1, AVPacket *pkt)
     int res;
 
     av_init_packet(pkt);
+    pkt->data = NULL;
+    pkt->size = 0;
     if ((res = mmap_read_frame(s1, pkt)) < 0) {
         return res;
     }
@@ -925,21 +1031,27 @@ static int v4l2_read_close(AVFormatContext *s1)
 #define DEC AV_OPT_FLAG_DECODING_PARAM
 
 static const AVOption options[] = {
-    { "standard",     "TV standard, used only by analog frame grabber",            OFFSET(standard),     AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0,       DEC },
-    { "channel",      "TV channel, used only by frame grabber",                    OFFSET(channel),      AV_OPT_TYPE_INT,    {.i64 = 0 },    0, INT_MAX, DEC },
-    { "video_size",   "A string describing frame size, such as 640x480 or hd720.", OFFSET(width),        AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL},  0, 0,       DEC },
-    { "pixel_format", "Preferred pixel format",                                    OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       DEC },
-    { "input_format", "Preferred pixel format (for raw video) or codec name",      OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       DEC },
-    { "framerate",    "",                                                          OFFSET(framerate),    AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       DEC },
-    { "list_formats", "List available formats and exit",                           OFFSET(list_format),  AV_OPT_TYPE_INT,    {.i64 = 0 },  0, INT_MAX, DEC, "list_formats" },
-    { "all",          "Show all available formats",                                OFFSET(list_format),  AV_OPT_TYPE_CONST,  {.i64 = V4L_ALLFORMATS  },    0, INT_MAX, DEC, "list_formats" },
-    { "raw",          "Show only non-compressed formats",                          OFFSET(list_format),  AV_OPT_TYPE_CONST,  {.i64 = V4L_RAWFORMATS  },    0, INT_MAX, DEC, "list_formats" },
-    { "compressed",   "Show only compressed formats",                              OFFSET(list_format),  AV_OPT_TYPE_CONST,  {.i64 = V4L_COMPFORMATS },    0, INT_MAX, DEC, "list_formats" },
-    { "timestamps",   "Kind of timestamps for grabbed frames",                     OFFSET(ts_mode),      AV_OPT_TYPE_INT,    {.i64 = 0 }, 0, 2, DEC, "timestamps" },
-    { "default",      "Use timestamps from the kernel",                            OFFSET(ts_mode),      AV_OPT_TYPE_CONST,  {.i64 = V4L_TS_DEFAULT  }, 0, 2, DEC, "timestamps" },
-    { "abs",          "Use absolute timestamps (wall clock)",                      OFFSET(ts_mode),      AV_OPT_TYPE_CONST,  {.i64 = V4L_TS_ABS      }, 0, 2, DEC, "timestamps" },
-    { "mono2abs",     "Force conversion from monotonic to absolute timestamps",    OFFSET(ts_mode),      AV_OPT_TYPE_CONST,  {.i64 = V4L_TS_MONO2ABS }, 0, 2, DEC, "timestamps" },
-    { "ts",           "Kind of timestamps for grabbed frames",                     OFFSET(ts_mode),      AV_OPT_TYPE_INT,    {.i64 = 0 }, 0, 2, DEC, "timestamps" },
+    { "standard",     "set TV standard, used only by analog frame grabber",       OFFSET(standard),     AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0,       DEC },
+    { "channel",      "set TV channel, used only by frame grabber",               OFFSET(channel),      AV_OPT_TYPE_INT,    {.i64 = 0 },    0, INT_MAX, DEC },
+    { "video_size",   "set frame size",                                           OFFSET(width),        AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL},  0, 0,   DEC },
+    { "pixel_format", "set preferred pixel format",                               OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       DEC },
+    { "input_format", "set preferred pixel format (for raw video) or codec name", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       DEC },
+    { "framerate",    "set frame rate",                                           OFFSET(framerate),    AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       DEC },
+
+    { "list_formats", "list available formats and exit",                          OFFSET(list_format),  AV_OPT_TYPE_INT,    {.i64 = 0 },  0, INT_MAX, DEC, "list_formats" },
+    { "all",          "show all available formats",                               OFFSET(list_format),  AV_OPT_TYPE_CONST,  {.i64 = V4L_ALLFORMATS  },    0, INT_MAX, DEC, "list_formats" },
+    { "raw",          "show only non-compressed formats",                         OFFSET(list_format),  AV_OPT_TYPE_CONST,  {.i64 = V4L_RAWFORMATS  },    0, INT_MAX, DEC, "list_formats" },
+    { "compressed",   "show only compressed formats",                             OFFSET(list_format),  AV_OPT_TYPE_CONST,  {.i64 = V4L_COMPFORMATS },    0, INT_MAX, DEC, "list_formats" },
+
+    { "list_standards", "list supported standards and exit",                      OFFSET(list_standard), AV_OPT_TYPE_INT,   {.i64 = 0 },  0, 1, DEC, "list_standards" },
+    { "all",            "show all supported standards",                           OFFSET(list_standard), AV_OPT_TYPE_CONST, {.i64 = 1 },  0, 0, DEC, "list_standards" },
+
+    { "timestamps",   "set type of timestamps for grabbed frames",                OFFSET(ts_mode),      AV_OPT_TYPE_INT,    {.i64 = 0 }, 0, 2, DEC, "timestamps" },
+    { "ts",           "set type of timestamps for grabbed frames",                OFFSET(ts_mode),      AV_OPT_TYPE_INT,    {.i64 = 0 }, 0, 2, DEC, "timestamps" },
+    { "default",      "use timestamps from the kernel",                           OFFSET(ts_mode),      AV_OPT_TYPE_CONST,  {.i64 = V4L_TS_DEFAULT  }, 0, 2, DEC, "timestamps" },
+    { "abs",          "use absolute timestamps (wall clock)",                     OFFSET(ts_mode),      AV_OPT_TYPE_CONST,  {.i64 = V4L_TS_ABS      }, 0, 2, DEC, "timestamps" },
+    { "mono2abs",     "force conversion from monotonic to absolute timestamps",   OFFSET(ts_mode),      AV_OPT_TYPE_CONST,  {.i64 = V4L_TS_MONO2ABS }, 0, 2, DEC, "timestamps" },
+
     { NULL },
 };
 
diff --git a/mythtv/external/FFmpeg/libavdevice/version.h b/mythtv/external/FFmpeg/libavdevice/version.h
index 5eed4f5e1a4..9e0c0ae940c 100644
--- a/mythtv/external/FFmpeg/libavdevice/version.h
+++ b/mythtv/external/FFmpeg/libavdevice/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVDEVICE_VERSION_MAJOR  54
 #define LIBAVDEVICE_VERSION_MINOR   3
-#define LIBAVDEVICE_VERSION_MICRO 102
+#define LIBAVDEVICE_VERSION_MICRO 103
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
                                                LIBAVDEVICE_VERSION_MINOR, \
diff --git a/mythtv/external/FFmpeg/libavfilter/Makefile b/mythtv/external/FFmpeg/libavfilter/Makefile
index 9bb9fa333f3..43c63cf6607 100644
--- a/mythtv/external/FFmpeg/libavfilter/Makefile
+++ b/mythtv/external/FFmpeg/libavfilter/Makefile
@@ -51,7 +51,9 @@ OBJS-$(CONFIG_AVFORMAT)                      += lavfutils.o
 OBJS-$(CONFIG_SWSCALE)                       += lswsutils.o
 
 OBJS-$(CONFIG_ACONVERT_FILTER)               += af_aconvert.o
+OBJS-$(CONFIG_AFADE_FILTER)                  += af_afade.o
 OBJS-$(CONFIG_AFORMAT_FILTER)                += af_aformat.o
+OBJS-$(CONFIG_ALLPASS_FILTER)                += af_biquads.o
 OBJS-$(CONFIG_AMERGE_FILTER)                 += af_amerge.o
 OBJS-$(CONFIG_AMIX_FILTER)                   += af_amix.o
 OBJS-$(CONFIG_ANULL_FILTER)                  += af_anull.o
@@ -67,14 +69,22 @@ OBJS-$(CONFIG_ASPLIT_FILTER)                 += split.o
 OBJS-$(CONFIG_ASTREAMSYNC_FILTER)            += af_astreamsync.o
 OBJS-$(CONFIG_ASYNCTS_FILTER)                += af_asyncts.o
 OBJS-$(CONFIG_ATEMPO_FILTER)                 += af_atempo.o
+OBJS-$(CONFIG_BANDPASS_FILTER)               += af_biquads.o
+OBJS-$(CONFIG_BANDREJECT_FILTER)             += af_biquads.o
+OBJS-$(CONFIG_BASS_FILTER)                   += af_biquads.o
+OBJS-$(CONFIG_BIQUAD_FILTER)                 += af_biquads.o
 OBJS-$(CONFIG_CHANNELMAP_FILTER)             += af_channelmap.o
 OBJS-$(CONFIG_CHANNELSPLIT_FILTER)           += af_channelsplit.o
 OBJS-$(CONFIG_EARWAX_FILTER)                 += af_earwax.o
 OBJS-$(CONFIG_EBUR128_FILTER)                += f_ebur128.o
+OBJS-$(CONFIG_EQUALIZER_FILTER)              += af_biquads.o
+OBJS-$(CONFIG_HIGHPASS_FILTER)               += af_biquads.o
 OBJS-$(CONFIG_JOIN_FILTER)                   += af_join.o
+OBJS-$(CONFIG_LOWPASS_FILTER)                += af_biquads.o
 OBJS-$(CONFIG_PAN_FILTER)                    += af_pan.o
 OBJS-$(CONFIG_RESAMPLE_FILTER)               += af_resample.o
 OBJS-$(CONFIG_SILENCEDETECT_FILTER)          += af_silencedetect.o
+OBJS-$(CONFIG_TREBLE_FILTER)                 += af_biquads.o
 OBJS-$(CONFIG_VOLUME_FILTER)                 += af_volume.o
 OBJS-$(CONFIG_VOLUMEDETECT_FILTER)           += af_volumedetect.o
 
@@ -84,12 +94,13 @@ OBJS-$(CONFIG_FLITE_FILTER)                  += asrc_flite.o
 
 OBJS-$(CONFIG_ANULLSINK_FILTER)              += asink_anullsink.o
 
-OBJS-$(CONFIG_ASS_FILTER)                    += vf_ass.o
+OBJS-$(CONFIG_ASS_FILTER)                    += vf_subtitles.o
 OBJS-$(CONFIG_ALPHAEXTRACT_FILTER)           += vf_alphaextract.o
 OBJS-$(CONFIG_ALPHAMERGE_FILTER)             += vf_alphamerge.o
 OBJS-$(CONFIG_BBOX_FILTER)                   += bbox.o vf_bbox.o
 OBJS-$(CONFIG_BLACKDETECT_FILTER)            += vf_blackdetect.o
 OBJS-$(CONFIG_BLACKFRAME_FILTER)             += vf_blackframe.o
+OBJS-$(CONFIG_BLEND_FILTER)                  += vf_blend.o
 OBJS-$(CONFIG_BOXBLUR_FILTER)                += vf_boxblur.o
 OBJS-$(CONFIG_COLORMATRIX_FILTER)            += vf_colormatrix.o
 OBJS-$(CONFIG_COPY_FILTER)                   += vf_copy.o
@@ -112,9 +123,11 @@ OBJS-$(CONFIG_GEQ_FILTER)                    += vf_geq.o
 OBJS-$(CONFIG_GRADFUN_FILTER)                += vf_gradfun.o
 OBJS-$(CONFIG_HFLIP_FILTER)                  += vf_hflip.o
 OBJS-$(CONFIG_HISTEQ_FILTER)                 += vf_histeq.o
+OBJS-$(CONFIG_HISTOGRAM_FILTER)              += vf_histogram.o
 OBJS-$(CONFIG_HQDN3D_FILTER)                 += vf_hqdn3d.o
 OBJS-$(CONFIG_HUE_FILTER)                    += vf_hue.o
 OBJS-$(CONFIG_IDET_FILTER)                   += vf_idet.o
+OBJS-$(CONFIG_IL_FILTER)                     += vf_il.o
 OBJS-$(CONFIG_KERNDEINT_FILTER)              += vf_kerndeint.o
 OBJS-$(CONFIG_LUT_FILTER)                    += vf_lut.o
 OBJS-$(CONFIG_LUTRGB_FILTER)                 += vf_lut.o
@@ -122,6 +135,7 @@ OBJS-$(CONFIG_LUTYUV_FILTER)                 += vf_lut.o
 OBJS-$(CONFIG_MP_FILTER)                     += vf_mp.o
 OBJS-$(CONFIG_NEGATE_FILTER)                 += vf_lut.o
 OBJS-$(CONFIG_NOFORMAT_FILTER)               += vf_format.o
+OBJS-$(CONFIG_NOISE_FILTER)                  += vf_noise.o
 OBJS-$(CONFIG_NULL_FILTER)                   += vf_null.o
 OBJS-$(CONFIG_OCV_FILTER)                    += vf_libopencv.o
 OBJS-$(CONFIG_OVERLAY_FILTER)                += vf_overlay.o
@@ -140,7 +154,8 @@ OBJS-$(CONFIG_SETTB_FILTER)                  += f_settb.o
 OBJS-$(CONFIG_SHOWINFO_FILTER)               += vf_showinfo.o
 OBJS-$(CONFIG_SMARTBLUR_FILTER)              += vf_smartblur.o
 OBJS-$(CONFIG_SPLIT_FILTER)                  += split.o
-OBJS-$(CONFIG_SUBTITLES_FILTER)              += vf_ass.o
+OBJS-$(CONFIG_STEREO3D_FILTER)               += vf_stereo3d.o
+OBJS-$(CONFIG_SUBTITLES_FILTER)              += vf_subtitles.o
 OBJS-$(CONFIG_SUPER2XSAI_FILTER)             += vf_super2xsai.o
 OBJS-$(CONFIG_SWAPUV_FILTER)                 += vf_swapuv.o
 OBJS-$(CONFIG_THUMBNAIL_FILTER)              += vf_thumbnail.o
@@ -170,17 +185,14 @@ OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_detc.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_dint.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_divtc.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_down3dright.o
-OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_dsize.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_eq2.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_eq.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fil.o
 #OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_filmdint.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fspp.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_harddup.o
-OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_il.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ilpack.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ivtc.o
-OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_kerndeint.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_mcdeint.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_noise.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ow.o
@@ -191,12 +203,9 @@ OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_pullup.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_qp.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_sab.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_softpulldown.o
-OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_softskip.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_spp.o
-OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_stereo3d.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_telecine.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_tinterlace.o
-OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_unsharp.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_uspp.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/pullup.o
 
diff --git a/mythtv/external/FFmpeg/libavfilter/af_afade.c b/mythtv/external/FFmpeg/libavfilter/af_afade.c
new file mode 100644
index 00000000000..00a05e2c1ee
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavfilter/af_afade.c
@@ -0,0 +1,307 @@
+/*
+ * Copyright (c) 2013 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * fade audio filter
+ */
+
+#include "libavutil/opt.h"
+#include "audio.h"
+#include "avfilter.h"
+#include "internal.h"
+
+typedef struct {
+    const AVClass *class;
+    int type;
+    int curve;
+    int nb_samples;
+    int64_t start_sample;
+    double duration;
+    double start_time;
+
+    void (*fade_samples)(uint8_t **dst, uint8_t * const *src,
+                         int nb_samples, int channels, int direction,
+                         int64_t start, int range, int curve);
+} AudioFadeContext;
+
+enum CurveType { TRI, QSIN, ESIN, HSIN, LOG, PAR, QUA, CUB, SQU, CBR };
+
+#define OFFSET(x) offsetof(AudioFadeContext, x)
+#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption afade_options[] = {
+    { "type",         "set the fade direction",                      OFFSET(type),         AV_OPT_TYPE_INT,    {.i64 = 0    }, 0, 1, FLAGS, "type" },
+    { "t",            "set the fade direction",                      OFFSET(type),         AV_OPT_TYPE_INT,    {.i64 = 0    }, 0, 1, FLAGS, "type" },
+    { "in",           NULL,                                          0,                    AV_OPT_TYPE_CONST,  {.i64 = 0    }, 0, 0, FLAGS, "type" },
+    { "out",          NULL,                                          0,                    AV_OPT_TYPE_CONST,  {.i64 = 1    }, 0, 0, FLAGS, "type" },
+    { "start_sample", "set expression of sample to start fading",    OFFSET(start_sample), AV_OPT_TYPE_INT64,  {.i64 = 0    }, 0, INT64_MAX, FLAGS },
+    { "ss",           "set expression of sample to start fading",    OFFSET(start_sample), AV_OPT_TYPE_INT64,  {.i64 = 0    }, 0, INT64_MAX, FLAGS },
+    { "nb_samples",   "set expression for fade duration in samples", OFFSET(nb_samples),   AV_OPT_TYPE_INT,    {.i64 = 44100}, 1, INT32_MAX, FLAGS },
+    { "ns",           "set expression for fade duration in samples", OFFSET(nb_samples),   AV_OPT_TYPE_INT,    {.i64 = 44100}, 1, INT32_MAX, FLAGS },
+    { "start_time",   "set expression of second to start fading",    OFFSET(start_time),   AV_OPT_TYPE_DOUBLE, {.dbl = 0.   }, 0, 7*24*60*60,FLAGS },
+    { "st",           "set expression of second to start fading",    OFFSET(start_time),   AV_OPT_TYPE_DOUBLE, {.dbl = 0.   }, 0, 7*24*60*60,FLAGS },
+    { "duration",     "set expression for fade duration in seconds", OFFSET(duration),     AV_OPT_TYPE_DOUBLE, {.dbl = 0.   }, 0, 24*60*60,  FLAGS },
+    { "d",            "set expression for fade duration in seconds", OFFSET(duration),     AV_OPT_TYPE_DOUBLE, {.dbl = 0.   }, 0, 24*60*60,  FLAGS },
+    { "curve",        "set expression for fade curve",               OFFSET(curve),        AV_OPT_TYPE_INT,    {.i64 = TRI  }, TRI, CBR, FLAGS, "curve" },
+    { "c",            "set expression for fade curve",               OFFSET(curve),        AV_OPT_TYPE_INT,    {.i64 = TRI  }, TRI, CBR, FLAGS, "curve" },
+    { "tri",          "linear slope",                                0,                    AV_OPT_TYPE_CONST,  {.i64 = TRI  }, 0, 0, FLAGS, "curve" },
+    { "qsin",         "quarter of sine wave",                        0,                    AV_OPT_TYPE_CONST,  {.i64 = QSIN }, 0, 0, FLAGS, "curve" },
+    { "esin",         "exponential sine wave",                       0,                    AV_OPT_TYPE_CONST,  {.i64 = ESIN }, 0, 0, FLAGS, "curve" },
+    { "hsin",         "half of sine wave",                           0,                    AV_OPT_TYPE_CONST,  {.i64 = HSIN }, 0, 0, FLAGS, "curve" },
+    { "log",          "logarithmic",                                 0,                    AV_OPT_TYPE_CONST,  {.i64 = LOG  }, 0, 0, FLAGS, "curve" },
+    { "par",          "inverted parabola",                           0,                    AV_OPT_TYPE_CONST,  {.i64 = PAR  }, 0, 0, FLAGS, "curve" },
+    { "qua",          "quadratic",                                   0,                    AV_OPT_TYPE_CONST,  {.i64 = QUA  }, 0, 0, FLAGS, "curve" },
+    { "cub",          "cubic",                                       0,                    AV_OPT_TYPE_CONST,  {.i64 = CUB  }, 0, 0, FLAGS, "curve" },
+    { "squ",          "square root",                                 0,                    AV_OPT_TYPE_CONST,  {.i64 = SQU  }, 0, 0, FLAGS, "curve" },
+    { "cbr",          "cubic root",                                  0,                    AV_OPT_TYPE_CONST,  {.i64 = CBR  }, 0, 0, FLAGS, "curve" },
+    {NULL},
+};
+
+AVFILTER_DEFINE_CLASS(afade);
+
+static av_cold int init(AVFilterContext *ctx, const char *args)
+{
+    AudioFadeContext *afade = ctx->priv;
+    int ret;
+
+    afade->class = &afade_class;
+    av_opt_set_defaults(afade);
+
+    if ((ret = av_set_options_string(afade, args, "=", ":")) < 0)
+        return ret;
+
+    if (INT64_MAX - afade->nb_samples < afade->start_sample)
+        return AVERROR(EINVAL);
+
+    return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+    AVFilterFormats *formats;
+    AVFilterChannelLayouts *layouts;
+    static const enum AVSampleFormat sample_fmts[] = {
+        AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
+        AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32P,
+        AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
+        AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBLP,
+        AV_SAMPLE_FMT_NONE
+    };
+
+    layouts = ff_all_channel_layouts();
+    if (!layouts)
+        return AVERROR(ENOMEM);
+    ff_set_common_channel_layouts(ctx, layouts);
+
+    formats = ff_make_format_list(sample_fmts);
+    if (!formats)
+        return AVERROR(ENOMEM);
+    ff_set_common_formats(ctx, formats);
+
+    formats = ff_all_samplerates();
+    if (!formats)
+        return AVERROR(ENOMEM);
+    ff_set_common_samplerates(ctx, formats);
+
+    return 0;
+}
+
+static double fade_gain(int curve, int64_t index, int range)
+{
+    double gain;
+
+    gain = FFMAX(0.0, FFMIN(1.0, 1.0 * index / range));
+
+    switch (curve) {
+    case QSIN:
+        gain = sin(gain * M_PI / 2.0);
+        break;
+    case ESIN:
+        gain = 1.0 - cos(M_PI / 4.0 * (pow(2.0*gain - 1, 3) + 1));
+        break;
+    case HSIN:
+        gain = (1.0 - cos(gain * M_PI)) / 2.0;
+        break;
+    case LOG:
+        gain = pow(0.1, (1 - gain) * 5.0);
+        break;
+    case PAR:
+        gain = (1 - (1 - gain) * (1 - gain));
+        break;
+    case QUA:
+        gain *= gain;
+        break;
+    case CUB:
+        gain = gain * gain * gain;
+        break;
+    case SQU:
+        gain = sqrt(gain);
+        break;
+    case CBR:
+        gain = cbrt(gain);
+        break;
+    }
+
+    return gain;
+}
+
+#define FADE_PLANAR(name, type)                                             \
+static void fade_samples_## name ##p(uint8_t **dst, uint8_t * const *src,   \
+                                     int nb_samples, int channels, int dir, \
+                                     int64_t start, int range, int curve)   \
+{                                                                           \
+    int i, c;                                                               \
+                                                                            \
+    for (i = 0; i < nb_samples; i++) {                                      \
+        double gain = fade_gain(curve, start + i * dir, range);             \
+        for (c = 0; c < channels; c++) {                                    \
+            type *d = (type *)dst[c];                                       \
+            const type *s = (type *)src[c];                                 \
+                                                                            \
+            d[i] = s[i] * gain;                                             \
+        }                                                                   \
+    }                                                                       \
+}
+
+#define FADE(name, type)                                                    \
+static void fade_samples_## name (uint8_t **dst, uint8_t * const *src,      \
+                                  int nb_samples, int channels, int dir,    \
+                                  int64_t start, int range, int curve)      \
+{                                                                           \
+    type *d = (type *)dst[0];                                               \
+    const type *s = (type *)src[0];                                         \
+    int i, c, k = 0;                                                        \
+                                                                            \
+    for (i = 0; i < nb_samples; i++) {                                      \
+        double gain = fade_gain(curve, start + i * dir, range);             \
+        for (c = 0; c < channels; c++, k++)                                 \
+            d[k] = s[k] * gain;                                             \
+    }                                                                       \
+}
+
+FADE_PLANAR(dbl, double)
+FADE_PLANAR(flt, float)
+FADE_PLANAR(s16, int16_t)
+FADE_PLANAR(s32, int32_t)
+
+FADE(dbl, double)
+FADE(flt, float)
+FADE(s16, int16_t)
+FADE(s32, int32_t)
+
+static int config_output(AVFilterLink *outlink)
+{
+    AVFilterContext *ctx    = outlink->src;
+    AudioFadeContext *afade = ctx->priv;
+    AVFilterLink *inlink    = ctx->inputs[0];
+
+    switch (inlink->format) {
+    case AV_SAMPLE_FMT_DBL:  afade->fade_samples = fade_samples_dbl;  break;
+    case AV_SAMPLE_FMT_DBLP: afade->fade_samples = fade_samples_dblp; break;
+    case AV_SAMPLE_FMT_FLT:  afade->fade_samples = fade_samples_flt;  break;
+    case AV_SAMPLE_FMT_FLTP: afade->fade_samples = fade_samples_fltp; break;
+    case AV_SAMPLE_FMT_S16:  afade->fade_samples = fade_samples_s16;  break;
+    case AV_SAMPLE_FMT_S16P: afade->fade_samples = fade_samples_s16p; break;
+    case AV_SAMPLE_FMT_S32:  afade->fade_samples = fade_samples_s32;  break;
+    case AV_SAMPLE_FMT_S32P: afade->fade_samples = fade_samples_s32p; break;
+    }
+
+    if (afade->duration)
+        afade->nb_samples = afade->duration * inlink->sample_rate;
+    if (afade->start_time)
+        afade->start_sample = afade->start_time * inlink->sample_rate;
+
+    return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *buf)
+{
+    AudioFadeContext *afade = inlink->dst->priv;
+    AVFilterLink *outlink   = inlink->dst->outputs[0];
+    int nb_samples          = buf->audio->nb_samples;
+    AVFilterBufferRef *out_buf;
+    int64_t cur_sample = av_rescale_q(buf->pts, (AVRational){1, outlink->sample_rate}, outlink->time_base);
+
+    if ((!afade->type && (afade->start_sample + afade->nb_samples < cur_sample)) ||
+        ( afade->type && (cur_sample + afade->nb_samples < afade->start_sample)))
+        return ff_filter_frame(outlink, buf);
+
+    if (buf->perms & AV_PERM_WRITE) {
+        out_buf = buf;
+    } else {
+        out_buf = ff_get_audio_buffer(inlink, AV_PERM_WRITE, nb_samples);
+        if (!out_buf)
+            return AVERROR(ENOMEM);
+        out_buf->pts = buf->pts;
+    }
+
+    if ((!afade->type && (cur_sample + nb_samples < afade->start_sample)) ||
+        ( afade->type && (afade->start_sample + afade->nb_samples < cur_sample))) {
+        av_samples_set_silence(out_buf->extended_data, 0, nb_samples,
+                               out_buf->audio->channels, out_buf->format);
+    } else {
+        int64_t start;
+
+        if (!afade->type)
+            start = cur_sample - afade->start_sample;
+        else
+            start = afade->start_sample + afade->nb_samples - cur_sample;
+
+        afade->fade_samples(out_buf->extended_data, buf->extended_data,
+                            nb_samples, buf->audio->channels,
+                            afade->type ? -1 : 1, start,
+                            afade->nb_samples, afade->curve);
+    }
+
+    if (buf != out_buf)
+        avfilter_unref_buffer(buf);
+
+    return ff_filter_frame(outlink, out_buf);
+}
+
+static const AVFilterPad avfilter_af_afade_inputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_AUDIO,
+        .filter_frame = filter_frame,
+    },
+    { NULL }
+};
+
+static const AVFilterPad avfilter_af_afade_outputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_AUDIO,
+        .config_props = config_output,
+    },
+    { NULL }
+};
+
+AVFilter avfilter_af_afade = {
+    .name          = "afade",
+    .description   = NULL_IF_CONFIG_SMALL("Fade in/out input audio."),
+    .query_formats = query_formats,
+    .priv_size     = sizeof(AudioFadeContext),
+    .init          = init,
+    .inputs        = avfilter_af_afade_inputs,
+    .outputs       = avfilter_af_afade_outputs,
+    .priv_class    = &afade_class,
+};
diff --git a/mythtv/external/FFmpeg/libavfilter/af_aformat.c b/mythtv/external/FFmpeg/libavfilter/af_aformat.c
index b1d779f9eca..9ac381fc1e1 100644
--- a/mythtv/external/FFmpeg/libavfilter/af_aformat.c
+++ b/mythtv/external/FFmpeg/libavfilter/af_aformat.c
@@ -121,7 +121,7 @@ static int query_formats(AVFilterContext *ctx)
     ff_set_common_samplerates(ctx, s->sample_rates ? s->sample_rates :
                                                      ff_all_samplerates());
     ff_set_common_channel_layouts(ctx, s->channel_layouts ? s->channel_layouts :
-                                                            ff_all_channel_layouts());
+                                                            ff_all_channel_counts());
 
     return 0;
 }
diff --git a/mythtv/external/FFmpeg/libavfilter/af_amerge.c b/mythtv/external/FFmpeg/libavfilter/af_amerge.c
index 44b71e4acbb..2d68ea6126d 100644
--- a/mythtv/external/FFmpeg/libavfilter/af_amerge.c
+++ b/mythtv/external/FFmpeg/libavfilter/af_amerge.c
@@ -63,8 +63,10 @@ static av_cold void uninit(AVFilterContext *ctx)
     int i;
 
     for (i = 0; i < am->nb_inputs; i++) {
-        ff_bufqueue_discard_all(&am->in[i].queue);
-        av_freep(&ctx->input_pads[i].name);
+        if (am->in)
+            ff_bufqueue_discard_all(&am->in[i].queue);
+        if (ctx->input_pads)
+            av_freep(&ctx->input_pads[i].name);
     }
     av_freep(&am->in);
 }
@@ -231,6 +233,11 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamples)
         if (inlink == ctx->inputs[input_number])
             break;
     av_assert1(input_number < am->nb_inputs);
+    if (ff_bufqueue_is_full(&am->in[input_number].queue)) {
+        av_log(ctx, AV_LOG_ERROR, "Buffer queue overflow\n");
+        avfilter_unref_buffer(insamples);
+        return AVERROR(ENOMEM);
+    }
     ff_bufqueue_add(ctx, &am->in[input_number].queue, insamples);
     am->in[input_number].nb_samples += insamples->audio->nb_samples;
     nb_samples = am->in[0].nb_samples;
@@ -255,6 +262,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamples)
 
     outbuf->audio->nb_samples     = nb_samples;
     outbuf->audio->channel_layout = outlink->channel_layout;
+    outbuf->audio->channels       = outlink->channels;
 
     while (nb_samples) {
         ns = nb_samples;
@@ -335,7 +343,7 @@ static const AVFilterPad amerge_outputs[] = {
 
 AVFilter avfilter_af_amerge = {
     .name          = "amerge",
-    .description   = NULL_IF_CONFIG_SMALL("Merge two audio streams into "
+    .description   = NULL_IF_CONFIG_SMALL("Merge two or more audio streams into "
                                           "a single multi-channel stream."),
     .priv_size     = sizeof(AMergeContext),
     .init          = init,
diff --git a/mythtv/external/FFmpeg/libavfilter/af_anull.c b/mythtv/external/FFmpeg/libavfilter/af_anull.c
index 40af7b8bc73..c61da3b4f18 100644
--- a/mythtv/external/FFmpeg/libavfilter/af_anull.c
+++ b/mythtv/external/FFmpeg/libavfilter/af_anull.c
@@ -50,6 +50,8 @@ AVFilter avfilter_af_anull = {
 
     .priv_size = 0,
 
+    .query_formats = ff_query_formats_all,
+
     .inputs    = avfilter_af_anull_inputs,
 
     .outputs   = avfilter_af_anull_outputs,
diff --git a/mythtv/external/FFmpeg/libavfilter/af_aresample.c b/mythtv/external/FFmpeg/libavfilter/af_aresample.c
index 17b7630b5a6..66a8a539f76 100644
--- a/mythtv/external/FFmpeg/libavfilter/af_aresample.c
+++ b/mythtv/external/FFmpeg/libavfilter/af_aresample.c
@@ -98,7 +98,7 @@ static int query_formats(AVFilterContext *ctx)
     AVFilterFormats        *out_formats;
     AVFilterFormats        *in_samplerates  = ff_all_samplerates();
     AVFilterFormats        *out_samplerates;
-    AVFilterChannelLayouts *in_layouts      = ff_all_channel_layouts();
+    AVFilterChannelLayouts *in_layouts      = ff_all_channel_counts();
     AVFilterChannelLayouts *out_layouts;
 
     ff_formats_ref  (in_formats,      &inlink->out_formats);
@@ -121,7 +121,7 @@ static int query_formats(AVFilterContext *ctx)
     if(out_layout) {
         out_layouts = avfilter_make_format64_list((int64_t[]){ out_layout, -1 });
     } else
-        out_layouts = ff_all_channel_layouts();
+        out_layouts = ff_all_channel_counts();
     ff_channel_layouts_ref(out_layouts, &outlink->in_channel_layouts);
 
     return 0;
@@ -145,6 +145,10 @@ static int config_output(AVFilterLink *outlink)
                                         0, ctx);
     if (!aresample->swr)
         return AVERROR(ENOMEM);
+    if (!inlink->channel_layout)
+        av_opt_set_int(aresample->swr, "ich", inlink->channels, 0);
+    if (!outlink->channel_layout)
+        av_opt_set_int(aresample->swr, "och", outlink->channels, 0);
 
     ret = swr_init(aresample->swr);
     if (ret < 0)
@@ -156,17 +160,17 @@ static int config_output(AVFilterLink *outlink)
     outlink->time_base = (AVRational) {1, out_rate};
 
     av_assert0(outlink->sample_rate == out_rate);
-    av_assert0(outlink->channel_layout == out_layout);
+    av_assert0(outlink->channel_layout == out_layout || !outlink->channel_layout);
     av_assert0(outlink->format == out_format);
 
     aresample->ratio = (double)outlink->sample_rate / inlink->sample_rate;
 
-    av_get_channel_layout_string(inchl_buf,  sizeof(inchl_buf),  -1, inlink ->channel_layout);
-    av_get_channel_layout_string(outchl_buf, sizeof(outchl_buf), -1, outlink->channel_layout);
+    av_get_channel_layout_string(inchl_buf,  sizeof(inchl_buf),  inlink ->channels, inlink ->channel_layout);
+    av_get_channel_layout_string(outchl_buf, sizeof(outchl_buf), outlink->channels, outlink->channel_layout);
 
-    av_log(ctx, AV_LOG_VERBOSE, "chl:%s fmt:%s r:%dHz -> chl:%s fmt:%s r:%dHz\n",
-           inchl_buf,  av_get_sample_fmt_name(inlink->format),  inlink->sample_rate,
-           outchl_buf, av_get_sample_fmt_name(outlink->format), outlink->sample_rate);
+    av_log(ctx, AV_LOG_VERBOSE, "ch:%d chl:%s fmt:%s r:%dHz -> ch:%d chl:%s fmt:%s r:%dHz\n",
+           inlink ->channels, inchl_buf,  av_get_sample_fmt_name(inlink->format),  inlink->sample_rate,
+           outlink->channels, outchl_buf, av_get_sample_fmt_name(outlink->format), outlink->sample_rate);
     return 0;
 }
 
diff --git a/mythtv/external/FFmpeg/libavfilter/af_biquads.c b/mythtv/external/FFmpeg/libavfilter/af_biquads.c
new file mode 100644
index 00000000000..cae3e02b496
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavfilter/af_biquads.c
@@ -0,0 +1,627 @@
+/*
+ * Copyright (c) 2013 Paul B Mahol
+ * Copyright (c) 2006-2008 Rob Sykes 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * 2-pole filters designed by Robert Bristow-Johnson 
+ *   see http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
+ *
+ * 1-pole filters based on code (c) 2000 Chris Bagwell 
+ *   Algorithms: Recursive single pole low/high pass filter
+ *   Reference: The Scientist and Engineer's Guide to Digital Signal Processing
+ *
+ *   low-pass: output[N] = input[N] * A + output[N-1] * B
+ *     X = exp(-2.0 * pi * Fc)
+ *     A = 1 - X
+ *     B = X
+ *     Fc = cutoff freq / sample rate
+ *
+ *     Mimics an RC low-pass filter:
+ *
+ *     ---/\/\/\/\----------->
+ *                   |
+ *                  --- C
+ *                  ---
+ *                   |
+ *                   |
+ *                   V
+ *
+ *   high-pass: output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1]
+ *     X  = exp(-2.0 * pi * Fc)
+ *     A0 = (1 + X) / 2
+ *     A1 = -(1 + X) / 2
+ *     B1 = X
+ *     Fc = cutoff freq / sample rate
+ *
+ *     Mimics an RC high-pass filter:
+ *
+ *         || C
+ *     ----||--------->
+ *         ||    |
+ *               <
+ *               > R
+ *               <
+ *               |
+ *               V
+ */
+
+#include "libavutil/opt.h"
+#include "libavutil/avassert.h"
+#include "audio.h"
+#include "avfilter.h"
+#include "internal.h"
+
+enum FilterType {
+    biquad,
+    equalizer,
+    bass,
+    treble,
+    band,
+    bandpass,
+    bandreject,
+    allpass,
+    highpass,
+    lowpass,
+};
+
+enum WidthType {
+    NONE,
+    HZ,
+    OCTAVE,
+    QFACTOR,
+    SLOPE,
+};
+
+typedef struct ChanCache {
+    double i1, i2;
+    double o1, o2;
+} ChanCache;
+
+typedef struct {
+    const AVClass *class;
+
+    enum FilterType filter_type;
+    enum WidthType width_type;
+    int poles;
+    int csg;
+
+    double gain;
+    double frequency;
+    double width;
+
+    double a0, a1, a2;
+    double b0, b1, b2;
+
+    ChanCache *cache;
+
+    void (*filter)(const void *ibuf, void *obuf, int len,
+                   double *i1, double *i2, double *o1, double *o2,
+                   double b0, double b1, double b2, double a1, double a2);
+} BiquadsContext;
+
+static av_cold int init(AVFilterContext *ctx, const char *args)
+{
+    BiquadsContext *p = ctx->priv;
+    int ret;
+
+    av_opt_set_defaults(p);
+
+    if ((ret = av_set_options_string(p, args, "=", ":")) < 0)
+        return ret;
+
+    if (p->filter_type != biquad) {
+        if (p->frequency <= 0 || p->width <= 0) {
+            av_log(ctx, AV_LOG_ERROR, "Invalid frequency %f and/or width %f <= 0\n",
+                   p->frequency, p->width);
+            return AVERROR(EINVAL);
+        }
+    }
+
+    return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+    AVFilterFormats *formats;
+    AVFilterChannelLayouts *layouts;
+    static const enum AVSampleFormat sample_fmts[] = {
+        AV_SAMPLE_FMT_S16P,
+        AV_SAMPLE_FMT_S32P,
+        AV_SAMPLE_FMT_FLTP,
+        AV_SAMPLE_FMT_DBLP,
+        AV_SAMPLE_FMT_NONE
+    };
+
+    layouts = ff_all_channel_layouts();
+    if (!layouts)
+        return AVERROR(ENOMEM);
+    ff_set_common_channel_layouts(ctx, layouts);
+
+    formats = ff_make_format_list(sample_fmts);
+    if (!formats)
+        return AVERROR(ENOMEM);
+    ff_set_common_formats(ctx, formats);
+
+    formats = ff_all_samplerates();
+    if (!formats)
+        return AVERROR(ENOMEM);
+    ff_set_common_samplerates(ctx, formats);
+
+    return 0;
+}
+
+#define BIQUAD_FILTER(name, type, min, max)                                   \
+static void biquad_## name (const void *input, void *output, int len,         \
+                            double *in1, double *in2,                         \
+                            double *out1, double *out2,                       \
+                            double b0, double b1, double b2,                  \
+                            double a1, double a2)                             \
+{                                                                             \
+    const type *ibuf = input;                                                 \
+    type *obuf = output;                                                      \
+    double i1 = *in1;                                                         \
+    double i2 = *in2;                                                         \
+    double o1 = *out1;                                                        \
+    double o2 = *out2;                                                        \
+    int i;                                                                    \
+    a1 = -a1;                                                                 \
+    a2 = -a2;                                                                 \
+                                                                              \
+    for (i = 0; i+1 < len; i++) {                                             \
+        o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1;            \
+        i2 = ibuf[i];                                                         \
+        if (o2 < min) {                                                       \
+            av_log(NULL, AV_LOG_WARNING, "clipping\n");                       \
+            obuf[i] = min;                                                    \
+        } else if (o2 > max) {                                                \
+            av_log(NULL, AV_LOG_WARNING, "clipping\n");                       \
+            obuf[i] = max;                                                    \
+        } else {                                                              \
+            obuf[i] = o2;                                                     \
+        }                                                                     \
+        i++;                                                                  \
+        o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1;            \
+        i1 = ibuf[i];                                                         \
+        if (o1 < min) {                                                       \
+            av_log(NULL, AV_LOG_WARNING, "clipping\n");                       \
+            obuf[i] = min;                                                    \
+        } else if (o1 > max) {                                                \
+            av_log(NULL, AV_LOG_WARNING, "clipping\n");                       \
+            obuf[i] = max;                                                    \
+        } else {                                                              \
+            obuf[i] = o1;                                                     \
+        }                                                                     \
+    }                                                                         \
+    if (i < len) {                                                            \
+        double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2;     \
+        i2 = i1;                                                              \
+        i1 = ibuf[i];                                                         \
+        o2 = o1;                                                              \
+        o1 = o0;                                                              \
+        if (o0 < min) {                                                       \
+            av_log(NULL, AV_LOG_WARNING, "clipping\n");                       \
+            obuf[i] = min;                                                    \
+        } else if (o0 > max) {                                                \
+            av_log(NULL, AV_LOG_WARNING, "clipping\n");                       \
+            obuf[i] = max;                                                    \
+        } else {                                                              \
+            obuf[i] = o0;                                                     \
+        }                                                                     \
+    }                                                                         \
+    *in1  = i1;                                                               \
+    *in2  = i2;                                                               \
+    *out1 = o1;                                                               \
+    *out2 = o2;                                                               \
+}
+
+BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX)
+BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX)
+BIQUAD_FILTER(flt, float,   -1., 1.)
+BIQUAD_FILTER(dbl, double,  -1., 1.)
+
+static int config_output(AVFilterLink *outlink)
+{
+    AVFilterContext *ctx    = outlink->src;
+    BiquadsContext *p       = ctx->priv;
+    AVFilterLink *inlink    = ctx->inputs[0];
+    double A = exp(p->gain / 40 * log(10.));
+    double w0 = 2 * M_PI * p->frequency / inlink->sample_rate;
+    double alpha;
+
+    if (w0 > M_PI) {
+        av_log(ctx, AV_LOG_ERROR,
+               "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
+               p->frequency, inlink->sample_rate);
+        return AVERROR(EINVAL);
+    }
+
+    switch (p->width_type) {
+    case NONE:
+        alpha = 0.0;
+        break;
+    case HZ:
+        alpha = sin(w0) / (2 * p->frequency / p->width);
+        break;
+    case OCTAVE:
+        alpha = sin(w0) * sinh(log(2.) / 2 * p->width * w0 / sin(w0));
+        break;
+    case QFACTOR:
+        alpha = sin(w0) / (2 * p->width);
+        break;
+    case SLOPE:
+        alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / p->width - 1) + 2);
+        break;
+    default:
+        av_assert0(0);
+    }
+
+    switch (p->filter_type) {
+    case biquad:
+        break;
+    case equalizer:
+        p->a0 =   1 + alpha / A;
+        p->a1 =  -2 * cos(w0);
+        p->a2 =   1 - alpha / A;
+        p->b0 =   1 + alpha * A;
+        p->b1 =  -2 * cos(w0);
+        p->b2 =   1 - alpha * A;
+        break;
+    case bass:
+        p->a0 =          (A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
+        p->a1 =    -2 * ((A - 1) + (A + 1) * cos(w0));
+        p->a2 =          (A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) * alpha;
+        p->b0 =     A * ((A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) * alpha);
+        p->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
+        p->b2 =     A * ((A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) * alpha);
+        break;
+    case treble:
+        p->a0 =          (A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
+        p->a1 =     2 * ((A - 1) - (A + 1) * cos(w0));
+        p->a2 =          (A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) * alpha;
+        p->b0 =     A * ((A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha);
+        p->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
+        p->b2 =     A * ((A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) * alpha);
+        break;
+    case bandpass:
+        if (p->csg) {
+            p->a0 =  1 + alpha;
+            p->a1 = -2 * cos(w0);
+            p->a2 =  1 - alpha;
+            p->b0 =  sin(w0) / 2;
+            p->b1 =  0;
+            p->b2 = -sin(w0) / 2;
+        } else {
+            p->a0 =  1 + alpha;
+            p->a1 = -2 * cos(w0);
+            p->a2 =  1 - alpha;
+            p->b0 =  alpha;
+            p->b1 =  0;
+            p->b2 = -alpha;
+        }
+        break;
+    case bandreject:
+        p->a0 =  1 + alpha;
+        p->a1 = -2 * cos(w0);
+        p->a2 =  1 - alpha;
+        p->b0 =  1;
+        p->b1 = -2 * cos(w0);
+        p->b2 =  1;
+        break;
+    case lowpass:
+        if (p->poles == 1) {
+            p->a0 = 1;
+            p->a1 = -exp(-w0);
+            p->a2 = 0;
+            p->b0 = 1 + p->a1;
+            p->b1 = 0;
+            p->b2 = 0;
+        } else {
+            p->a0 =  1 + alpha;
+            p->a1 = -2 * cos(w0);
+            p->a2 =  1 - alpha;
+            p->b0 = (1 - cos(w0)) / 2;
+            p->b1 =  1 - cos(w0);
+            p->b2 = (1 - cos(w0)) / 2;
+        }
+        break;
+    case highpass:
+        if (p->poles == 1) {
+            p->a0 = 1;
+            p->a1 = -exp(-w0);
+            p->a2 = 0;
+            p->b0 = (1 - p->a1) / 2;
+            p->b1 = -p->b0;
+            p->b2 = 0;
+        } else {
+            p->a0 =   1 + alpha;
+            p->a1 =  -2 * cos(w0);
+            p->a2 =   1 - alpha;
+            p->b0 =  (1 + cos(w0)) / 2;
+            p->b1 = -(1 + cos(w0));
+            p->b2 =  (1 + cos(w0)) / 2;
+        }
+        break;
+    case allpass:
+        p->a0 =  1 + alpha;
+        p->a1 = -2 * cos(w0);
+        p->a2 =  1 - alpha;
+        p->b0 =  1 - alpha;
+        p->b1 = -2 * cos(w0);
+        p->b2 =  1 + alpha;
+        break;
+    default:
+        av_assert0(0);
+    }
+
+    p->a1 /= p->a0;
+    p->a2 /= p->a0;
+    p->b0 /= p->a0;
+    p->b1 /= p->a0;
+    p->b2 /= p->a0;
+
+    p->cache = av_realloc_f(p->cache, sizeof(ChanCache), inlink->channels);
+    if (!p->cache)
+        return AVERROR(ENOMEM);
+    memset(p->cache, 0, sizeof(ChanCache) * inlink->channels);
+
+    switch (inlink->format) {
+    case AV_SAMPLE_FMT_S16P: p->filter = biquad_s16; break;
+    case AV_SAMPLE_FMT_S32P: p->filter = biquad_s32; break;
+    case AV_SAMPLE_FMT_FLTP: p->filter = biquad_flt; break;
+    case AV_SAMPLE_FMT_DBLP: p->filter = biquad_dbl; break;
+    default: av_assert0(0);
+    }
+
+    return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *buf)
+{
+    BiquadsContext *p       = inlink->dst->priv;
+    AVFilterLink *outlink   = inlink->dst->outputs[0];
+    AVFilterBufferRef *out_buf;
+    int nb_samples = buf->audio->nb_samples;
+    int ch;
+
+    if (buf->perms & AV_PERM_WRITE) {
+        out_buf = buf;
+    } else {
+        out_buf = ff_get_audio_buffer(inlink, AV_PERM_WRITE, nb_samples);
+        if (!out_buf)
+            return AVERROR(ENOMEM);
+        out_buf->pts = buf->pts;
+    }
+
+    for (ch = 0; ch < buf->audio->channels; ch++)
+        p->filter(buf->extended_data[ch],
+                  out_buf->extended_data[ch], nb_samples,
+                  &p->cache[ch].i1, &p->cache[ch].i2,
+                  &p->cache[ch].o1, &p->cache[ch].o2,
+                  p->b0, p->b1, p->b2, p->a1, p->a2);
+
+    if (buf != out_buf)
+        avfilter_unref_buffer(buf);
+
+    return ff_filter_frame(outlink, out_buf);
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+    BiquadsContext *p = ctx->priv;
+
+    av_freep(&p->cache);
+    av_opt_free(p);
+}
+
+static const AVFilterPad inputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_AUDIO,
+        .filter_frame = filter_frame,
+    },
+    { NULL }
+};
+
+static const AVFilterPad outputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_AUDIO,
+        .config_props = config_output,
+    },
+    { NULL }
+};
+
+#define OFFSET(x) offsetof(BiquadsContext, x)
+#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+#define DEFINE_BIQUAD_FILTER(name_, description_)                       \
+AVFILTER_DEFINE_CLASS(name_);                                           \
+static av_cold int name_##_init(AVFilterContext *ctx, const char *args) \
+{                                                                       \
+    BiquadsContext *p = ctx->priv;                                      \
+    p->class = &name_##_class;                                          \
+    p->filter_type = name_;                                             \
+    return init(ctx, args);                                             \
+}                                                                       \
+                                                         \
+AVFilter avfilter_af_##name_ = {                         \
+    .name          = #name_,                             \
+    .description   = NULL_IF_CONFIG_SMALL(description_), \
+    .priv_size     = sizeof(BiquadsContext),             \
+    .init          = name_##_init,                       \
+    .uninit        = uninit,                             \
+    .query_formats = query_formats,                      \
+    .inputs        = inputs,                             \
+    .outputs       = outputs,                            \
+    .priv_class    = &name_##_class,                     \
+}
+
+#if CONFIG_EQUALIZER_FILTER
+static const AVOption equalizer_options[] = {
+    {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
+    {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
+    {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HZ, SLOPE, FLAGS, "width_type"},
+    {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HZ}, 0, 0, FLAGS, "width_type"},
+    {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
+    {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
+    {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
+    {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 999, FLAGS},
+    {"w",     "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 999, FLAGS},
+    {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
+    {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
+    {NULL},
+};
+
+DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
+#endif  /* CONFIG_EQUALIZER_FILTER */
+#if CONFIG_BASS_FILTER
+static const AVOption bass_options[] = {
+    {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
+    {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
+    {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HZ, SLOPE, FLAGS, "width_type"},
+    {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HZ}, 0, 0, FLAGS, "width_type"},
+    {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
+    {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
+    {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
+    {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
+    {"w",     "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
+    {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
+    {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
+    {NULL},
+};
+
+DEFINE_BIQUAD_FILTER(bass, "Boost or cut lower frequencies.");
+#endif  /* CONFIG_BASS_FILTER */
+#if CONFIG_TREBLE_FILTER
+static const AVOption treble_options[] = {
+    {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
+    {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
+    {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HZ, SLOPE, FLAGS, "width_type"},
+    {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HZ}, 0, 0, FLAGS, "width_type"},
+    {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
+    {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
+    {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
+    {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
+    {"w",     "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
+    {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
+    {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
+    {NULL},
+};
+
+DEFINE_BIQUAD_FILTER(treble, "Boost or cut upper frequencies.");
+#endif  /* CONFIG_TREBLE_FILTER */
+#if CONFIG_BANDPASS_FILTER
+static const AVOption bandpass_options[] = {
+    {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
+    {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
+    {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HZ, SLOPE, FLAGS, "width_type"},
+    {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HZ}, 0, 0, FLAGS, "width_type"},
+    {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
+    {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
+    {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
+    {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
+    {"w",     "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
+    {"csg",   "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS},
+    {NULL},
+};
+
+DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
+#endif  /* CONFIG_BANDPASS_FILTER */
+#if CONFIG_BANDREJECT_FILTER
+static const AVOption bandreject_options[] = {
+    {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
+    {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
+    {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HZ, SLOPE, FLAGS, "width_type"},
+    {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HZ}, 0, 0, FLAGS, "width_type"},
+    {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
+    {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
+    {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
+    {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
+    {"w",     "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
+    {NULL},
+};
+
+DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
+#endif  /* CONFIG_BANDREJECT_FILTER */
+#if CONFIG_LOWPASS_FILTER
+static const AVOption lowpass_options[] = {
+    {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
+    {"f",         "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
+    {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HZ, SLOPE, FLAGS, "width_type"},
+    {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HZ}, 0, 0, FLAGS, "width_type"},
+    {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
+    {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
+    {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
+    {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
+    {"w",     "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
+    {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
+    {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
+    {NULL},
+};
+
+DEFINE_BIQUAD_FILTER(lowpass, "Apply a low-pass filter with 3dB point frequency.");
+#endif  /* CONFIG_LOWPASS_FILTER */
+#if CONFIG_HIGHPASS_FILTER
+static const AVOption highpass_options[] = {
+    {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
+    {"f",         "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
+    {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HZ, SLOPE, FLAGS, "width_type"},
+    {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HZ}, 0, 0, FLAGS, "width_type"},
+    {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
+    {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
+    {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
+    {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
+    {"w",     "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
+    {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
+    {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
+    {NULL},
+};
+
+DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
+#endif  /* CONFIG_HIGHPASS_FILTER */
+#if CONFIG_ALLPASS_FILTER
+static const AVOption allpass_options[] = {
+    {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
+    {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
+    {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HZ}, HZ, SLOPE, FLAGS, "width_type"},
+    {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HZ}, 0, 0, FLAGS, "width_type"},
+    {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
+    {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
+    {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
+    {"width", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
+    {"w",     "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
+    {NULL},
+};
+
+DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter.");
+#endif  /* CONFIG_ALLPASS_FILTER */
+#if CONFIG_BIQUAD_FILTER
+static const AVOption biquad_options[] = {
+    {"a0", NULL, OFFSET(a0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MAX, INT16_MAX, FLAGS},
+    {"a1", NULL, OFFSET(a1), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MAX, INT16_MAX, FLAGS},
+    {"a2", NULL, OFFSET(a2), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MAX, INT16_MAX, FLAGS},
+    {"b0", NULL, OFFSET(b0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MAX, INT16_MAX, FLAGS},
+    {"b1", NULL, OFFSET(b1), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MAX, INT16_MAX, FLAGS},
+    {"b2", NULL, OFFSET(b2), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MAX, INT16_MAX, FLAGS},
+    {NULL},
+};
+
+DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
+#endif  /* CONFIG_BIQUAD_FILTER */
diff --git a/mythtv/external/FFmpeg/libavfilter/af_earwax.c b/mythtv/external/FFmpeg/libavfilter/af_earwax.c
index eaf6b05d7b1..a169d2aaf1f 100644
--- a/mythtv/external/FFmpeg/libavfilter/af_earwax.c
+++ b/mythtv/external/FFmpeg/libavfilter/af_earwax.c
@@ -91,17 +91,6 @@ static int query_formats(AVFilterContext *ctx)
     return 0;
 }
 
-static int config_input(AVFilterLink *inlink)
-{
-    if (inlink->sample_rate != 44100) {
-        av_log(inlink->dst, AV_LOG_ERROR,
-               "The earwax filter only works for 44.1kHz audio. Insert "
-               "a resample filter before this\n");
-        return AVERROR(EINVAL);
-    }
-    return 0;
-}
-
 //FIXME: replace with DSPContext.scalarproduct_int16
 static inline int16_t *scalarproduct(const int16_t *in, const int16_t *endin, int16_t *out)
 {
@@ -158,7 +147,6 @@ static const AVFilterPad earwax_inputs[] = {
         .name         = "default",
         .type         = AVMEDIA_TYPE_AUDIO,
         .filter_frame = filter_frame,
-        .config_props = config_input,
         .min_perms    = AV_PERM_READ,
     },
     { NULL }
diff --git a/mythtv/external/FFmpeg/libavfilter/af_resample.c b/mythtv/external/FFmpeg/libavfilter/af_resample.c
index c712b46d593..84ca8f5501b 100644
--- a/mythtv/external/FFmpeg/libavfilter/af_resample.c
+++ b/mythtv/external/FFmpeg/libavfilter/af_resample.c
@@ -25,6 +25,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/common.h"
+#include "libavutil/dict.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
 
@@ -37,6 +38,7 @@
 
 typedef struct ResampleContext {
     AVAudioResampleContext *avr;
+    AVDictionary *options;
 
     int64_t next_pts;
 
@@ -44,6 +46,29 @@ typedef struct ResampleContext {
     int got_output;
 } ResampleContext;
 
+static av_cold int init(AVFilterContext *ctx, const char *args)
+{
+    ResampleContext *s = ctx->priv;
+
+    if (args) {
+        int ret = av_dict_parse_string(&s->options, args, "=", ":", 0);
+        if (ret < 0) {
+            av_log(ctx, AV_LOG_ERROR, "error setting option string: %s\n", args);
+            return ret;
+        }
+
+        /* do not allow the user to override basic format options */
+        av_dict_set(&s->options,  "in_channel_layout", NULL, 0);
+        av_dict_set(&s->options, "out_channel_layout", NULL, 0);
+        av_dict_set(&s->options,  "in_sample_fmt",     NULL, 0);
+        av_dict_set(&s->options, "out_sample_fmt",     NULL, 0);
+        av_dict_set(&s->options,  "in_sample_rate",    NULL, 0);
+        av_dict_set(&s->options, "out_sample_rate",    NULL, 0);
+    }
+
+    return 0;
+}
+
 static av_cold void uninit(AVFilterContext *ctx)
 {
     ResampleContext *s = ctx->priv;
@@ -52,6 +77,7 @@ static av_cold void uninit(AVFilterContext *ctx)
         avresample_close(s->avr);
         avresample_free(&s->avr);
     }
+    av_dict_free(&s->options);
 }
 
 static int query_formats(AVFilterContext *ctx)
@@ -103,6 +129,14 @@ static int config_output(AVFilterLink *outlink)
     if (!(s->avr = avresample_alloc_context()))
         return AVERROR(ENOMEM);
 
+    if (s->options) {
+        AVDictionaryEntry *e = NULL;
+        while ((e = av_dict_get(s->options, "", e, AV_DICT_IGNORE_SUFFIX)))
+            av_log(ctx, AV_LOG_VERBOSE, "lavr option: %s=%s\n", e->key, e->value);
+
+        av_opt_set_dict(s->avr, &s->options);
+    }
+
     av_opt_set_int(s->avr,  "in_channel_layout", inlink ->channel_layout, 0);
     av_opt_set_int(s->avr, "out_channel_layout", outlink->channel_layout, 0);
     av_opt_set_int(s->avr,  "in_sample_fmt",     inlink ->format,         0);
@@ -264,6 +298,7 @@ AVFilter avfilter_af_resample = {
     .description   = NULL_IF_CONFIG_SMALL("Audio resampling and conversion."),
     .priv_size     = sizeof(ResampleContext),
 
+    .init           = init,
     .uninit         = uninit,
     .query_formats  = query_formats,
 
diff --git a/mythtv/external/FFmpeg/libavfilter/allfilters.c b/mythtv/external/FFmpeg/libavfilter/allfilters.c
index 4815c4aa8e5..8a3f126c729 100644
--- a/mythtv/external/FFmpeg/libavfilter/allfilters.c
+++ b/mythtv/external/FFmpeg/libavfilter/allfilters.c
@@ -45,7 +45,9 @@ void avfilter_register_all(void)
     initialized = 1;
 
     REGISTER_FILTER(ACONVERT,       aconvert,       af);
+    REGISTER_FILTER(AFADE,          afade,          af);
     REGISTER_FILTER(AFORMAT,        aformat,        af);
+    REGISTER_FILTER(ALLPASS,        allpass,        af);
     REGISTER_FILTER(AMERGE,         amerge,         af);
     REGISTER_FILTER(AMIX,           amix,           af);
     REGISTER_FILTER(ANULL,          anull,          af);
@@ -61,14 +63,22 @@ void avfilter_register_all(void)
     REGISTER_FILTER(ASTREAMSYNC,    astreamsync,    af);
     REGISTER_FILTER(ASYNCTS,        asyncts,        af);
     REGISTER_FILTER(ATEMPO,         atempo,         af);
+    REGISTER_FILTER(BANDPASS,       bandpass,       af);
+    REGISTER_FILTER(BANDREJECT,     bandreject,     af);
+    REGISTER_FILTER(BASS,           bass,           af);
+    REGISTER_FILTER(BIQUAD,         biquad,         af);
     REGISTER_FILTER(CHANNELMAP,     channelmap,     af);
     REGISTER_FILTER(CHANNELSPLIT,   channelsplit,   af);
     REGISTER_FILTER(EARWAX,         earwax,         af);
     REGISTER_FILTER(EBUR128,        ebur128,        af);
+    REGISTER_FILTER(EQUALIZER,      equalizer,      af);
+    REGISTER_FILTER(HIGHPASS,       highpass,       af);
     REGISTER_FILTER(JOIN,           join,           af);
+    REGISTER_FILTER(LOWPASS,        lowpass,        af);
     REGISTER_FILTER(PAN,            pan,            af);
     REGISTER_FILTER(RESAMPLE,       resample,       af);
     REGISTER_FILTER(SILENCEDETECT,  silencedetect,  af);
+    REGISTER_FILTER(TREBLE,         treble,         af);
     REGISTER_FILTER(VOLUME,         volume,         af);
     REGISTER_FILTER(VOLUMEDETECT,   volumedetect,   af);
 
@@ -84,6 +94,7 @@ void avfilter_register_all(void)
     REGISTER_FILTER(BBOX,           bbox,           vf);
     REGISTER_FILTER(BLACKDETECT,    blackdetect,    vf);
     REGISTER_FILTER(BLACKFRAME,     blackframe,     vf);
+    REGISTER_FILTER(BLEND,          blend,          vf);
     REGISTER_FILTER(BOXBLUR,        boxblur,        vf);
     REGISTER_FILTER(COLORMATRIX,    colormatrix,    vf);
     REGISTER_FILTER(COPY,           copy,           vf);
@@ -106,9 +117,11 @@ void avfilter_register_all(void)
     REGISTER_FILTER(GRADFUN,        gradfun,        vf);
     REGISTER_FILTER(HFLIP,          hflip,          vf);
     REGISTER_FILTER(HISTEQ,         histeq,         vf);
+    REGISTER_FILTER(HISTOGRAM,      histogram,      vf);
     REGISTER_FILTER(HQDN3D,         hqdn3d,         vf);
     REGISTER_FILTER(HUE,            hue,            vf);
     REGISTER_FILTER(IDET,           idet,           vf);
+    REGISTER_FILTER(IL,             il,             vf);
     REGISTER_FILTER(KERNDEINT,      kerndeint,      vf);
     REGISTER_FILTER(LUT,            lut,            vf);
     REGISTER_FILTER(LUTRGB,         lutrgb,         vf);
@@ -116,6 +129,7 @@ void avfilter_register_all(void)
     REGISTER_FILTER(MP,             mp,             vf);
     REGISTER_FILTER(NEGATE,         negate,         vf);
     REGISTER_FILTER(NOFORMAT,       noformat,       vf);
+    REGISTER_FILTER(NOISE,          noise,          vf);
     REGISTER_FILTER(NULL,           null,           vf);
     REGISTER_FILTER(OCV,            ocv,            vf);
     REGISTER_FILTER(OVERLAY,        overlay,        vf);
@@ -134,6 +148,7 @@ void avfilter_register_all(void)
     REGISTER_FILTER(SHOWINFO,       showinfo,       vf);
     REGISTER_FILTER(SMARTBLUR,      smartblur,      vf);
     REGISTER_FILTER(SPLIT,          split,          vf);
+    REGISTER_FILTER(STEREO3D,       stereo3d,       vf);
     REGISTER_FILTER(SUBTITLES,      subtitles,      vf);
     REGISTER_FILTER(SUPER2XSAI,     super2xsai,     vf);
     REGISTER_FILTER(SWAPUV,         swapuv,         vf);
diff --git a/mythtv/external/FFmpeg/libavfilter/asrc_aevalsrc.c b/mythtv/external/FFmpeg/libavfilter/asrc_aevalsrc.c
index 3315f1f563e..2e5fa98fd75 100644
--- a/mythtv/external/FFmpeg/libavfilter/asrc_aevalsrc.c
+++ b/mythtv/external/FFmpeg/libavfilter/asrc_aevalsrc.c
@@ -214,9 +214,9 @@ static int request_frame(AVFilterLink *outlink)
     EvalContext *eval = outlink->src->priv;
     AVFilterBufferRef *samplesref;
     int i, j;
-    double t = eval->var_values[VAR_N] * (double)1/eval->sample_rate;
+    double t = eval->n * (double)1/eval->sample_rate;
 
-    if (eval->duration >= 0 && t > eval->duration)
+    if (eval->duration >= 0 && t >= eval->duration)
         return AVERROR_EOF;
 
     samplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, eval->nb_samples);
diff --git a/mythtv/external/FFmpeg/libavfilter/audio.c b/mythtv/external/FFmpeg/libavfilter/audio.c
index 72dcd148a46..c72979d4345 100644
--- a/mythtv/external/FFmpeg/libavfilter/audio.c
+++ b/mythtv/external/FFmpeg/libavfilter/audio.c
@@ -44,7 +44,7 @@ AVFilterBufferRef *ff_default_get_audio_buffer(AVFilterLink *link, int perms,
     AVFilterBufferRef *samplesref = NULL;
     uint8_t **data;
     int planar      = av_sample_fmt_is_planar(link->format);
-    int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
+    int nb_channels = link->channels;
     int planes      = planar ? nb_channels : 1;
     int linesize;
     int full_perms = AV_PERM_READ | AV_PERM_WRITE | AV_PERM_PRESERVE |
diff --git a/mythtv/external/FFmpeg/libavfilter/avcodec.c b/mythtv/external/FFmpeg/libavfilter/avcodec.c
index 0c1f02ad8a5..dd3c886df01 100644
--- a/mythtv/external/FFmpeg/libavfilter/avcodec.c
+++ b/mythtv/external/FFmpeg/libavfilter/avcodec.c
@@ -96,16 +96,13 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame
     int channels = av_frame_get_channels(frame);
     int64_t layout = av_frame_get_channel_layout(frame);
 
-    if(av_frame_get_channels(frame) > 8) // libavfilter does not suport more than 8 channels FIXME, remove once libavfilter is fixed
-        return NULL;
-
     if (layout && av_get_channel_layout_nb_channels(layout) != av_frame_get_channels(frame)) {
         av_log(0, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
         return NULL;
     }
 
     samplesref = avfilter_get_audio_buffer_ref_from_arrays_channels(
-        (uint8_t **)frame->data, frame->linesize[0], perms,
+        (uint8_t **)frame->extended_data, frame->linesize[0], perms,
         frame->nb_samples, frame->format, channels, layout);
     if (!samplesref)
         return NULL;
diff --git a/mythtv/external/FFmpeg/libavfilter/avf_showspectrum.c b/mythtv/external/FFmpeg/libavfilter/avf_showspectrum.c
index 977fca92a61..bb8b62f68d5 100644
--- a/mythtv/external/FFmpeg/libavfilter/avf_showspectrum.c
+++ b/mythtv/external/FFmpeg/libavfilter/avf_showspectrum.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2012 Clément Bœsch
+ * Copyright (c) 2013 Rudolf Polzer 
  *
  * This file is part of FFmpeg.
  *
@@ -27,38 +28,75 @@
 #include 
 
 #include "libavcodec/avfft.h"
+#include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
 #include "avfilter.h"
 #include "internal.h"
 
+enum DisplayMode  { COMBINED, SEPARATE, NB_MODES };
+enum DisplayScale { LINEAR, SQRT, CBRT, LOG, NB_SCALES };
+enum ColorMode    { CHANNEL, INTENSITY, NB_CLMODES };
+
 typedef struct {
     const AVClass *class;
     int w, h;
     AVFilterBufferRef *outpicref;
     int req_fullfilled;
+    int nb_display_channels;
+    int channel_height;
     int sliding;                ///< 1 if sliding mode, 0 otherwise
+    enum DisplayMode mode;      ///< channel display mode
+    enum ColorMode color_mode;  ///< display color scheme
+    enum DisplayScale scale;
+    float saturation;           ///< color saturation multiplier
     int xpos;                   ///< x position (current column)
     RDFTContext *rdft;          ///< Real Discrete Fourier Transform context
     int rdft_bits;              ///< number of bits (RDFT window size = 1<priv;
@@ -76,8 +114,12 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
 static av_cold void uninit(AVFilterContext *ctx)
 {
     ShowSpectrumContext *showspectrum = ctx->priv;
+    int i;
 
+    av_freep(&showspectrum->combine_buffer);
     av_rdft_end(showspectrum->rdft);
+    for (i = 0; i < showspectrum->nb_display_channels; i++)
+        av_freep(&showspectrum->rdft_data[i]);
     av_freep(&showspectrum->rdft_data);
     av_freep(&showspectrum->window_func_lut);
     avfilter_unref_bufferp(&showspectrum->outpicref);
@@ -90,7 +132,7 @@ static int query_formats(AVFilterContext *ctx)
     AVFilterLink *inlink = ctx->inputs[0];
     AVFilterLink *outlink = ctx->outputs[0];
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE };
-    static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE };
+    static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_NONE };
 
     /* set input audio formats */
     formats = ff_make_format_list(sample_fmts);
@@ -120,19 +162,23 @@ static int query_formats(AVFilterContext *ctx)
 static int config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
+    AVFilterLink *inlink = ctx->inputs[0];
     ShowSpectrumContext *showspectrum = ctx->priv;
-    int i, rdft_bits, win_size;
+    int i, rdft_bits, win_size, h;
 
     outlink->w = showspectrum->w;
     outlink->h = showspectrum->h;
 
+    h = (showspectrum->mode == COMBINED) ? outlink->h : outlink->h / inlink->channels;
+    showspectrum->channel_height = h;
+
     /* RDFT window size (precision) according to the requested output frame height */
-    for (rdft_bits = 1; 1<h; rdft_bits++);
+    for (rdft_bits = 1; 1 << rdft_bits < 2 * h; rdft_bits++);
     win_size = 1 << rdft_bits;
 
     /* (re-)configuration if the video output changed (or first init) */
     if (rdft_bits != showspectrum->rdft_bits) {
-        size_t rdft_size;
+        size_t rdft_size, rdft_listsize;
         AVFilterBufferRef *outpicref;
 
         av_rdft_end(showspectrum->rdft);
@@ -142,12 +188,25 @@ static int config_output(AVFilterLink *outlink)
         /* RDFT buffers: x2 for each (display) channel buffer.
          * Note: we use free and malloc instead of a realloc-like function to
          * make sure the buffer is aligned in memory for the FFT functions. */
+        for (i = 0; i < showspectrum->nb_display_channels; i++)
+            av_freep(&showspectrum->rdft_data[i]);
         av_freep(&showspectrum->rdft_data);
-        if (av_size_mult(sizeof(*showspectrum->rdft_data), 2 * win_size, &rdft_size) < 0)
+        showspectrum->nb_display_channels = inlink->channels;
+
+        if (av_size_mult(sizeof(*showspectrum->rdft_data),
+                         showspectrum->nb_display_channels, &rdft_listsize) < 0)
+            return AVERROR(EINVAL);
+        if (av_size_mult(sizeof(**showspectrum->rdft_data),
+                         win_size, &rdft_size) < 0)
             return AVERROR(EINVAL);
-        showspectrum->rdft_data = av_malloc(rdft_size);
+        showspectrum->rdft_data = av_malloc(rdft_listsize);
         if (!showspectrum->rdft_data)
             return AVERROR(ENOMEM);
+        for (i = 0; i < showspectrum->nb_display_channels; i++) {
+            showspectrum->rdft_data[i] = av_malloc(rdft_size);
+            if (!showspectrum->rdft_data[i])
+                return AVERROR(ENOMEM);
+        }
         showspectrum->filled = 0;
 
         /* pre-calc windowing function (hann here) */
@@ -173,6 +232,10 @@ static int config_output(AVFilterLink *outlink)
     if (showspectrum->xpos >= outlink->w)
         showspectrum->xpos = 0;
 
+    showspectrum->combine_buffer =
+        av_realloc_f(showspectrum->combine_buffer, outlink->h * 3,
+                     sizeof(*showspectrum->combine_buffer));
+
     av_log(ctx, AV_LOG_VERBOSE, "s:%dx%d RDFT window size:%d\n",
            showspectrum->w, showspectrum->h, win_size);
     return 0;
@@ -213,62 +276,180 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFilterBufferRef *insampl
     AVFilterLink *outlink = ctx->outputs[0];
     ShowSpectrumContext *showspectrum = ctx->priv;
     AVFilterBufferRef *outpicref = showspectrum->outpicref;
-    const int nb_channels = av_get_channel_layout_nb_channels(insamples->audio->channel_layout);
 
     /* nb_freq contains the power of two superior or equal to the output image
      * height (or half the RDFT window size) */
     const int nb_freq = 1 << (showspectrum->rdft_bits - 1);
     const int win_size = nb_freq << 1;
+    const double w = 1. / (sqrt(nb_freq) * 32768.);
 
-    int ch, n, y;
-    FFTSample *data[2];
-    const int nb_display_channels = FFMIN(nb_channels, 2);
+    int ch, plane, n, y;
     const int start = showspectrum->filled;
     const int add_samples = FFMIN(win_size - start, nb_samples);
 
     /* fill RDFT input with the number of samples available */
-    for (ch = 0; ch < nb_display_channels; ch++) {
+    for (ch = 0; ch < showspectrum->nb_display_channels; ch++) {
         const int16_t *p = (int16_t *)insamples->extended_data[ch];
 
         p += showspectrum->consumed;
-        data[ch] = showspectrum->rdft_data + win_size * ch; // select channel buffer
         for (n = 0; n < add_samples; n++)
-            data[ch][start + n] = p[n] * showspectrum->window_func_lut[start + n];
+            showspectrum->rdft_data[ch][start + n] = p[n] * showspectrum->window_func_lut[start + n];
     }
     showspectrum->filled += add_samples;
 
     /* complete RDFT window size? */
     if (showspectrum->filled == win_size) {
 
+        /* channel height */
+        int h = showspectrum->channel_height;
+
         /* run RDFT on each samples set */
-        for (ch = 0; ch < nb_display_channels; ch++)
-            av_rdft_calc(showspectrum->rdft, data[ch]);
+        for (ch = 0; ch < showspectrum->nb_display_channels; ch++)
+            av_rdft_calc(showspectrum->rdft, showspectrum->rdft_data[ch]);
 
         /* fill a new spectrum column */
-#define RE(ch) data[ch][2*y + 0]
-#define IM(ch) data[ch][2*y + 1]
-#define MAGNITUDE(re, im) sqrt((re)*(re) + (im)*(im))
+#define RE(y, ch) showspectrum->rdft_data[ch][2 * y + 0]
+#define IM(y, ch) showspectrum->rdft_data[ch][2 * y + 1]
+#define MAGNITUDE(y, ch) hypot(RE(y, ch), IM(y, ch))
 
+        /* initialize buffer for combining to black */
         for (y = 0; y < outlink->h; y++) {
-            // FIXME: bin[0] contains first and last bins
-            uint8_t *p = outpicref->data[0] + (outlink->h - y - 1) * outpicref->linesize[0];
-            const double w = 1. / sqrt(nb_freq);
-            int a =                           sqrt(w * MAGNITUDE(RE(0), IM(0)));
-            int b = nb_display_channels > 1 ? sqrt(w * MAGNITUDE(RE(1), IM(1))) : a;
-
-            if (showspectrum->sliding) {
-                memmove(p, p + 3, (outlink->w - 1) * 3);
-                p += (outlink->w - 1) * 3;
-            } else {
-                p += showspectrum->xpos * 3;
+            showspectrum->combine_buffer[3 * y    ] = 0;
+            showspectrum->combine_buffer[3 * y + 1] = 127.5;
+            showspectrum->combine_buffer[3 * y + 2] = 127.5;
+        }
+
+        for (ch = 0; ch < showspectrum->nb_display_channels; ch++) {
+            float yf, uf, vf;
+
+            /* decide color range */
+            switch (showspectrum->mode) {
+            case COMBINED:
+                // reduce range by channel count
+                yf = 256.0f / showspectrum->nb_display_channels;
+                switch (showspectrum->color_mode) {
+                case INTENSITY:
+                    uf = yf;
+                    vf = yf;
+                    break;
+                case CHANNEL:
+                    /* adjust saturation for mixed UV coloring */
+                    /* this factor is correct for infinite channels, an approximation otherwise */
+                    uf = yf * M_PI;
+                    vf = yf * M_PI;
+                    break;
+                default:
+                    av_assert0(0);
+                }
+                break;
+            case SEPARATE:
+                // full range
+                yf = 256.0f;
+                uf = 256.0f;
+                vf = 256.0f;
+                break;
+            default:
+                av_assert0(0);
+            }
+
+            if (showspectrum->color_mode == CHANNEL) {
+                if (showspectrum->nb_display_channels > 1) {
+                    uf *= 0.5 * sin((2 * M_PI * ch) / showspectrum->nb_display_channels);
+                    vf *= 0.5 * cos((2 * M_PI * ch) / showspectrum->nb_display_channels);
+                } else {
+                    uf = 0.0f;
+                    vf = 0.0f;
+                }
+            }
+            uf *= showspectrum->saturation;
+            vf *= showspectrum->saturation;
+
+            /* draw the channel */
+            for (y = 0; y < h; y++) {
+                int row = (showspectrum->mode == COMBINED) ? y : ch * h + y;
+                float *out = &showspectrum->combine_buffer[3 * row];
+
+                /* get magnitude */
+                float a = w * MAGNITUDE(y, ch);
+
+                /* apply scale */
+                switch (showspectrum->scale) {
+                case LINEAR:
+                    break;
+                case SQRT:
+                    a = sqrt(a);
+                    break;
+                case CBRT:
+                    a = cbrt(a);
+                    break;
+                case LOG:
+                    a = 1 - log(FFMAX(FFMIN(1, a), 1e-6)) / log(1e-6); // zero = -120dBFS
+                    break;
+                default:
+                    av_assert0(0);
+                }
+
+                if (showspectrum->color_mode == INTENSITY) {
+                    float y, u, v;
+                    int i;
+
+                    for (i = 1; i < sizeof(intensity_color_table) / sizeof(*intensity_color_table) - 1; i++)
+                        if (intensity_color_table[i].a >= a)
+                            break;
+                    // i now is the first item >= the color
+                    // now we know to interpolate between item i - 1 and i
+                    if (a <= intensity_color_table[i - 1].a) {
+                        y = intensity_color_table[i - 1].y;
+                        u = intensity_color_table[i - 1].u;
+                        v = intensity_color_table[i - 1].v;
+                    } else if (a >= intensity_color_table[i].a) {
+                        y = intensity_color_table[i].y;
+                        u = intensity_color_table[i].u;
+                        v = intensity_color_table[i].v;
+                    } else {
+                        float start = intensity_color_table[i - 1].a;
+                        float end = intensity_color_table[i].a;
+                        float lerpfrac = (a - start) / (end - start);
+                        y = intensity_color_table[i - 1].y * (1.0f - lerpfrac)
+                          + intensity_color_table[i].y * lerpfrac;
+                        u = intensity_color_table[i - 1].u * (1.0f - lerpfrac)
+                          + intensity_color_table[i].u * lerpfrac;
+                        v = intensity_color_table[i - 1].v * (1.0f - lerpfrac)
+                          + intensity_color_table[i].v * lerpfrac;
+                    }
+
+                    out[0] += y * yf;
+                    out[1] += u * uf;
+                    out[2] += v * vf;
+                } else {
+                    out[0] += a * yf;
+                    out[1] += a * uf;
+                    out[2] += a * vf;
+                }
             }
+        }
 
-            a = FFMIN(a, 255);
-            b = FFMIN(b, 255);
-            p[0] = a;
-            p[1] = b;
-            p[2] = (a + b) / 2;
+        /* copy to output */
+        if (showspectrum->sliding) {
+            for (plane = 0; plane < 3; plane++) {
+                for (y = 0; y < outlink->h; y++) {
+                    uint8_t *p = outpicref->data[plane] +
+                                 y * outpicref->linesize[plane];
+                    memmove(p, p + 1, outlink->w - 1);
+                }
+            }
+            showspectrum->xpos = outlink->w - 1;
         }
+        for (plane = 0; plane < 3; plane++) {
+            uint8_t *p = outpicref->data[plane] +
+                         (outlink->h - 1) * outpicref->linesize[plane] +
+                         showspectrum->xpos;
+            for (y = 0; y < outlink->h; y++) {
+                *p = rint(FFMAX(0, FFMIN(showspectrum->combine_buffer[3 * y + plane], 255)));
+                p -= outpicref->linesize[plane];
+            }
+        }
+
         outpicref->pts = insamples->pts +
             av_rescale_q(showspectrum->consumed,
                          (AVRational){ 1, inlink->sample_rate },
diff --git a/mythtv/external/FFmpeg/libavfilter/avf_showwaves.c b/mythtv/external/FFmpeg/libavfilter/avf_showwaves.c
index 30a8e1e62fa..1b9d28d487e 100644
--- a/mythtv/external/FFmpeg/libavfilter/avf_showwaves.c
+++ b/mythtv/external/FFmpeg/libavfilter/avf_showwaves.c
@@ -32,6 +32,12 @@
 #include "video.h"
 #include "internal.h"
 
+enum ShowWavesMode {
+    MODE_POINT,
+    MODE_LINE,
+    MODE_NB,
+};
+
 typedef struct {
     const AVClass *class;
     int w, h;
@@ -42,6 +48,7 @@ typedef struct {
     int req_fullfilled;
     int n;
     int sample_count_mod;
+    enum ShowWavesMode mode;
 } ShowWavesContext;
 
 #define OFFSET(x) offsetof(ShowWavesContext, x)
@@ -53,6 +60,10 @@ static const AVOption showwaves_options[] = {
     { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS },
     { "s",    "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS },
     { "n",    "set how many samples to show in the same point", OFFSET(n), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS },
+
+    {"mode",  "select display mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_POINT}, 0, MODE_NB-1, FLAGS, "mode"},
+    {"point", "draw a point for each sample", 0, AV_OPT_TYPE_CONST, {.i64=MODE_POINT}, .flags=FLAGS, .unit="mode"},
+    {"line",  "draw a line for each sample",  0, AV_OPT_TYPE_CONST, {.i64=MODE_LINE},  .flags=FLAGS, .unit="mode"},
     { NULL },
 };
 
@@ -149,14 +160,16 @@ static int config_output(AVFilterLink *outlink)
     return 0;
 }
 
-inline static void push_frame(AVFilterLink *outlink)
+inline static int push_frame(AVFilterLink *outlink)
 {
     ShowWavesContext *showwaves = outlink->src->priv;
+    int ret;
 
-    ff_filter_frame(outlink, showwaves->outpicref);
-    showwaves->req_fullfilled = 1;
+    if ((ret = ff_filter_frame(outlink, showwaves->outpicref)) >= 0)
+        showwaves->req_fullfilled = 1;
     showwaves->outpicref = NULL;
     showwaves->buf_idx = 0;
+    return ret;
 }
 
 static int request_frame(AVFilterLink *outlink)
@@ -187,13 +200,13 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamples)
     int linesize = outpicref ? outpicref->linesize[0] : 0;
     int16_t *p = (int16_t *)insamples->data[0];
     int nb_channels = av_get_channel_layout_nb_channels(insamples->audio->channel_layout);
-    int i, j, h;
+    int i, j, k, h, ret = 0;
     const int n = showwaves->n;
     const int x = 255 / (nb_channels * n); /* multiplication factor, pre-computed to avoid in-loop divisions */
 
     /* draw data in the buffer */
     for (i = 0; i < nb_samples; i++) {
-        if (!outpicref) {
+        if (!showwaves->outpicref) {
             showwaves->outpicref = outpicref =
                 ff_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_ALIGN,
                                     outlink->w, outlink->h);
@@ -210,20 +223,36 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamples)
         }
         for (j = 0; j < nb_channels; j++) {
             h = showwaves->h/2 - av_rescale(*p++, showwaves->h/2, MAX_INT16);
-            if (h >= 0 && h < outlink->h)
-                *(outpicref->data[0] + showwaves->buf_idx + h * linesize) += x;
+            switch (showwaves->mode) {
+            case MODE_POINT:
+                if (h >= 0 && h < outlink->h)
+                    *(outpicref->data[0] + showwaves->buf_idx + h * linesize) += x;
+                break;
+
+            case MODE_LINE:
+            {
+                int start = showwaves->h/2, end = av_clip(h, 0, outlink->h-1);
+                if (start > end) FFSWAP(int16_t, start, end);
+                for (k = start; k < end; k++)
+                    *(outpicref->data[0] + showwaves->buf_idx + k * linesize) += x;
+                break;
+            }
+            }
         }
+
         showwaves->sample_count_mod++;
         if (showwaves->sample_count_mod == n) {
             showwaves->sample_count_mod = 0;
             showwaves->buf_idx++;
         }
         if (showwaves->buf_idx == showwaves->w)
-            push_frame(outlink);
+            if ((ret = push_frame(outlink)) < 0)
+                break;
+        outpicref = showwaves->outpicref;
     }
 
     avfilter_unref_buffer(insamples);
-    return 0;
+    return ret;
 }
 
 static const AVFilterPad showwaves_inputs[] = {
diff --git a/mythtv/external/FFmpeg/libavfilter/avfilter.c b/mythtv/external/FFmpeg/libavfilter/avfilter.c
index 4edd5be30f8..ffd1b4ea191 100644
--- a/mythtv/external/FFmpeg/libavfilter/avfilter.c
+++ b/mythtv/external/FFmpeg/libavfilter/avfilter.c
@@ -222,11 +222,11 @@ int avfilter_config_links(AVFilterContext *filter)
 
     for (i = 0; i < filter->nb_inputs; i ++) {
         AVFilterLink *link = filter->inputs[i];
-        AVFilterLink *inlink = link->src->nb_inputs ?
-            link->src->inputs[0] : NULL;
+        AVFilterLink *inlink;
 
         if (!link) continue;
 
+        inlink = link->src->nb_inputs ? link->src->inputs[0] : NULL;
         link->current_pts = AV_NOPTS_VALUE;
 
         switch (link->init_state) {
@@ -391,7 +391,7 @@ int avfilter_process_command(AVFilterContext *filter, const char *cmd, const cha
     return AVERROR(ENOSYS);
 }
 
-#define MAX_REGISTERED_AVFILTERS_NB 128
+#define MAX_REGISTERED_AVFILTERS_NB 256
 
 static AVFilter *registered_avfilters[MAX_REGISTERED_AVFILTERS_NB + 1];
 
@@ -690,7 +690,7 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFilterBufferRef *frame)
 
         switch (link->type) {
         case AVMEDIA_TYPE_VIDEO:
-            av_image_copy(out->data, out->linesize, frame->data, frame->linesize,
+            av_image_copy(out->data, out->linesize, (const uint8_t **)frame->data, frame->linesize,
                           frame->format, frame->video->w, frame->video->h);
             break;
         case AVMEDIA_TYPE_AUDIO:
@@ -706,7 +706,7 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFilterBufferRef *frame)
     } else
         out = frame;
 
-    while(cmd && cmd->time <= frame->pts * av_q2d(link->time_base)){
+    while(cmd && cmd->time <= out->pts * av_q2d(link->time_base)){
         av_log(link->dst, AV_LOG_DEBUG,
                "Processing command time:%f command:%s arg:%s\n",
                cmd->time, cmd->command, cmd->arg);
diff --git a/mythtv/external/FFmpeg/libavfilter/avfiltergraph.c b/mythtv/external/FFmpeg/libavfilter/avfiltergraph.c
index c05bbb7fe6e..2764b8c85ad 100644
--- a/mythtv/external/FFmpeg/libavfilter/avfiltergraph.c
+++ b/mythtv/external/FFmpeg/libavfilter/avfiltergraph.c
@@ -20,7 +20,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
 #include 
 
 #include "libavutil/avassert.h"
@@ -68,6 +67,7 @@ void avfilter_graph_free(AVFilterGraph **graph)
     av_freep(&(*graph)->sink_links);
     av_freep(&(*graph)->scale_sws_opts);
     av_freep(&(*graph)->aresample_swr_opts);
+    av_freep(&(*graph)->resample_lavr_opts);
     av_freep(&(*graph)->filters);
     av_freep(graph);
 }
@@ -185,9 +185,24 @@ AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name)
     return NULL;
 }
 
+static void sanitize_channel_layouts(void *log, AVFilterChannelLayouts *l)
+{
+    if (!l)
+        return;
+    if (l->nb_channel_layouts) {
+        if (l->all_layouts || l->all_counts)
+            av_log(log, AV_LOG_WARNING, "All layouts set on non-empty list\n");
+        l->all_layouts = l->all_counts = 0;
+    } else {
+        if (l->all_counts && !l->all_layouts)
+            av_log(log, AV_LOG_WARNING, "All counts without all layouts\n");
+        l->all_layouts = 1;
+    }
+}
+
 static int filter_query_formats(AVFilterContext *ctx)
 {
-    int ret;
+    int ret, i;
     AVFilterFormats *formats;
     AVFilterChannelLayouts *chlayouts;
     AVFilterFormats *samplerates;
@@ -201,6 +216,11 @@ static int filter_query_formats(AVFilterContext *ctx)
         return ret;
     }
 
+    for (i = 0; i < ctx->nb_inputs; i++)
+        sanitize_channel_layouts(ctx, ctx->inputs[i]->out_channel_layouts);
+    for (i = 0; i < ctx->nb_outputs; i++)
+        sanitize_channel_layouts(ctx, ctx->outputs[i]->in_channel_layouts);
+
     formats = ff_all_formats(type);
     if (!formats)
         return AVERROR(ENOMEM);
@@ -218,68 +238,9 @@ static int filter_query_formats(AVFilterContext *ctx)
     return 0;
 }
 
-static int insert_conv_filter(AVFilterGraph *graph, AVFilterLink *link,
-                              const char *filt_name, const char *filt_args)
-{
-    static int auto_count = 0, ret;
-    char inst_name[32];
-    AVFilterContext *filt_ctx;
-
-    if (graph->disable_auto_convert) {
-        av_log(NULL, AV_LOG_ERROR,
-               "The filters '%s' and '%s' do not have a common format "
-               "and automatic conversion is disabled.\n",
-               link->src->name, link->dst->name);
-        return AVERROR(EINVAL);
-    }
-
-    snprintf(inst_name, sizeof(inst_name), "auto-inserted %s %d",
-            filt_name, auto_count++);
-
-    if ((ret = avfilter_graph_create_filter(&filt_ctx,
-                                            avfilter_get_by_name(filt_name),
-                                            inst_name, filt_args, NULL, graph)) < 0)
-        return ret;
-    if ((ret = avfilter_insert_filter(link, filt_ctx, 0, 0)) < 0)
-        return ret;
-
-    filter_query_formats(filt_ctx);
-
-    if ( ((link = filt_ctx-> inputs[0]) &&
-           !ff_merge_formats(link->in_formats, link->out_formats)) ||
-         ((link = filt_ctx->outputs[0]) &&
-           !ff_merge_formats(link->in_formats, link->out_formats))
-       ) {
-        av_log(NULL, AV_LOG_ERROR,
-               "Impossible to convert between the formats supported by the filter "
-               "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
-        return AVERROR(EINVAL);
-    }
-
-    if (link->type == AVMEDIA_TYPE_AUDIO &&
-         (((link = filt_ctx-> inputs[0]) &&
-           !ff_merge_channel_layouts(link->in_channel_layouts, link->out_channel_layouts)) ||
-         ((link = filt_ctx->outputs[0]) &&
-           !ff_merge_channel_layouts(link->in_channel_layouts, link->out_channel_layouts)))
-       ) {
-        av_log(NULL, AV_LOG_ERROR,
-               "Impossible to convert between the channel layouts formats supported by the filter "
-               "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
-        return AVERROR(EINVAL);
-    }
-
-    return 0;
-}
-
 static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
 {
     int i, j, ret;
-#if 0
-    char filt_args[128];
-    AVFilterFormats *formats;
-    AVFilterChannelLayouts *chlayouts;
-    AVFilterFormats *samplerates;
-#endif
     int scaler_count = 0, resampler_count = 0;
 
     for (j = 0; j < 2; j++) {
@@ -305,44 +266,14 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
 
         for (j = 0; j < filter->nb_inputs; j++) {
             AVFilterLink *link = filter->inputs[j];
-#if 0
-            if (!link) continue;
-
-            if (!link->in_formats || !link->out_formats)
-                return AVERROR(EINVAL);
-
-            if (link->type == AVMEDIA_TYPE_VIDEO &&
-                !ff_merge_formats(link->in_formats, link->out_formats)) {
-
-                /* couldn't merge format lists, auto-insert scale filter */
-                snprintf(filt_args, sizeof(filt_args), "0:0:%s",
-                         graph->scale_sws_opts);
-                if (ret = insert_conv_filter(graph, link, "scale", filt_args))
-                    return ret;
-            }
-            else if (link->type == AVMEDIA_TYPE_AUDIO) {
-                if (!link->in_channel_layouts || !link->out_channel_layouts)
-                    return AVERROR(EINVAL);
-
-                /* Merge all three list before checking: that way, in all
-                 * three categories, aconvert will use a common format
-                 * whenever possible. */
-                formats     = ff_merge_formats(link->in_formats,   link->out_formats);
-                chlayouts   = ff_merge_channel_layouts(link->in_channel_layouts  , link->out_channel_layouts);
-                samplerates = ff_merge_samplerates    (link->in_samplerates, link->out_samplerates);
-
-                if (!formats || !chlayouts || !samplerates)
-                    if (ret = insert_conv_filter(graph, link, "aresample", NULL))
-                       return ret;
-#else
             int convert_needed = 0;
 
             if (!link)
                 continue;
 
             if (link->in_formats != link->out_formats &&
-                !ff_merge_formats(link->in_formats,
-                                        link->out_formats))
+                !ff_merge_formats(link->in_formats, link->out_formats,
+                                  link->type))
                 convert_needed = 1;
             if (link->type == AVMEDIA_TYPE_AUDIO) {
                 if (link->in_channel_layouts != link->out_channel_layouts &&
@@ -392,8 +323,13 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
 
                     snprintf(inst_name, sizeof(inst_name), "auto-inserted resampler %d",
                              resampler_count++);
+                    scale_args[0] = '\0';
+                    if (graph->aresample_swr_opts)
+                        snprintf(scale_args, sizeof(scale_args), "%s",
+                                 graph->aresample_swr_opts);
                     if ((ret = avfilter_graph_create_filter(&convert, filter,
-                                                            inst_name, graph->aresample_swr_opts, NULL, graph)) < 0)
+                                                            inst_name, graph->aresample_swr_opts,
+                                                            NULL, graph)) < 0)
                         return ret;
                     break;
                 default:
@@ -406,8 +342,8 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
                 filter_query_formats(convert);
                 inlink  = convert->inputs[0];
                 outlink = convert->outputs[0];
-                if (!ff_merge_formats( inlink->in_formats,  inlink->out_formats) ||
-                    !ff_merge_formats(outlink->in_formats, outlink->out_formats))
+                if (!ff_merge_formats( inlink->in_formats,  inlink->out_formats,  inlink->type) ||
+                    !ff_merge_formats(outlink->in_formats, outlink->out_formats, outlink->type))
                     ret |= AVERROR(ENOSYS);
                 if (inlink->type == AVMEDIA_TYPE_AUDIO &&
                     (!ff_merge_samplerates(inlink->in_samplerates,
@@ -428,7 +364,6 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
                            "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
                     return ret;
                 }
-#endif
             }
         }
     }
@@ -470,15 +405,18 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref)
         link->in_samplerates->format_count = 1;
         link->sample_rate = link->in_samplerates->formats[0];
 
-        if (!link->in_channel_layouts->nb_channel_layouts) {
+        if (link->in_channel_layouts->all_layouts) {
             av_log(link->src, AV_LOG_ERROR, "Cannot select channel layout for"
-                   "the link between filters %s and %s.\n", link->src->name,
+                   " the link between filters %s and %s.\n", link->src->name,
                    link->dst->name);
             return AVERROR(EINVAL);
         }
         link->in_channel_layouts->nb_channel_layouts = 1;
         link->channel_layout = link->in_channel_layouts->channel_layouts[0];
-        link->channels = av_get_channel_layout_nb_channels(link->channel_layout);
+        if ((link->channels = FF_LAYOUT2COUNT(link->channel_layout)))
+            link->channel_layout = 0;
+        else
+            link->channels = av_get_channel_layout_nb_channels(link->channel_layout);
     }
 
     ff_formats_unref(&link->in_formats);
@@ -534,8 +472,42 @@ static int reduce_formats_on_filter(AVFilterContext *filter)
                    format_count, ff_add_format);
     REDUCE_FORMATS(int,      AVFilterFormats,        samplerates,     formats,
                    format_count, ff_add_format);
-    REDUCE_FORMATS(uint64_t, AVFilterChannelLayouts, channel_layouts,
-                   channel_layouts, nb_channel_layouts, ff_add_channel_layout);
+
+    /* reduce channel layouts */
+    for (i = 0; i < filter->nb_inputs; i++) {
+        AVFilterLink *inlink = filter->inputs[i];
+        uint64_t fmt;
+
+        if (!inlink->out_channel_layouts ||
+            inlink->out_channel_layouts->nb_channel_layouts != 1)
+            continue;
+        fmt = inlink->out_channel_layouts->channel_layouts[0];
+
+        for (j = 0; j < filter->nb_outputs; j++) {
+            AVFilterLink *outlink = filter->outputs[j];
+            AVFilterChannelLayouts *fmts;
+
+            fmts = outlink->in_channel_layouts;
+            if (inlink->type != outlink->type || fmts->nb_channel_layouts == 1)
+                continue;
+
+            if (fmts->all_layouts) {
+                /* Turn the infinite list into a singleton */
+                fmts->all_layouts = fmts->all_counts  = 0;
+                ff_add_channel_layout(&outlink->in_channel_layouts, fmt);
+                break;
+            }
+
+            for (k = 0; k < outlink->in_channel_layouts->nb_channel_layouts; k++) {
+                if (fmts->channel_layouts[k] == fmt) {
+                    fmts->channel_layouts[0]  = fmt;
+                    fmts->nb_channel_layouts = 1;
+                    ret = 1;
+                    break;
+                }
+            }
+        }
+    }
 
     return ret;
 }
@@ -663,7 +635,23 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter)
             int out_channels      = av_get_channel_layout_nb_channels(out_chlayout);
             int count_diff        = out_channels - in_channels;
             int matched_channels, extra_channels;
-            int score = 0;
+            int score = 100000;
+
+            if (FF_LAYOUT2COUNT(in_chlayout) || FF_LAYOUT2COUNT(out_chlayout)) {
+                /* Compute score in case the input or output layout encodes
+                   a channel count; in this case the score is not altered by
+                   the computation afterwards, as in_chlayout and
+                   out_chlayout have both been set to 0 */
+                if (FF_LAYOUT2COUNT(in_chlayout))
+                    in_channels = FF_LAYOUT2COUNT(in_chlayout);
+                if (FF_LAYOUT2COUNT(out_chlayout))
+                    out_channels = FF_LAYOUT2COUNT(out_chlayout);
+                score -= 10000 + FFABS(out_channels - in_channels) +
+                         (in_channels > out_channels ? 10000 : 0);
+                in_chlayout = out_chlayout = 0;
+                /* Let the remaining computation run, even if the score
+                   value is not altered */
+            }
 
             /* channel substitution */
             for (k = 0; k < FF_ARRAY_ELEMS(ch_subst); k++) {
diff --git a/mythtv/external/FFmpeg/libavfilter/avfiltergraph.h b/mythtv/external/FFmpeg/libavfilter/avfiltergraph.h
index 728bbb5c15b..39654128037 100644
--- a/mythtv/external/FFmpeg/libavfilter/avfiltergraph.h
+++ b/mythtv/external/FFmpeg/libavfilter/avfiltergraph.h
@@ -31,7 +31,7 @@ typedef struct AVFilterGraph {
     AVFilterContext **filters;
 
     char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
-
+    char *resample_lavr_opts;   ///< libavresample options to use for the auto-inserted resample filters
     char *aresample_swr_opts; ///< swr options to use for the auto-inserted aresample filters, Access ONLY through AVOptions
 
     /**
diff --git a/mythtv/external/FFmpeg/libavfilter/bufferqueue.h b/mythtv/external/FFmpeg/libavfilter/bufferqueue.h
index a27fb86112b..34c4c0f08ba 100644
--- a/mythtv/external/FFmpeg/libavfilter/bufferqueue.h
+++ b/mythtv/external/FFmpeg/libavfilter/bufferqueue.h
@@ -54,6 +54,14 @@ struct FFBufQueue {
 
 #define BUCKET(i) queue->queue[(queue->head + (i)) % FF_BUFQUEUE_SIZE]
 
+/**
+ * Test if a buffer queue is full.
+ */
+static inline int ff_bufqueue_is_full(struct FFBufQueue *queue)
+{
+    return queue->available == FF_BUFQUEUE_SIZE;
+}
+
 /**
  * Add a buffer to the queue.
  *
@@ -63,7 +71,7 @@ struct FFBufQueue {
 static inline void ff_bufqueue_add(void *log, struct FFBufQueue *queue,
                                    AVFilterBufferRef *buf)
 {
-    if (queue->available == FF_BUFQUEUE_SIZE) {
+    if (ff_bufqueue_is_full(queue)) {
         av_log(log, AV_LOG_WARNING, "Buffer queue overflow, dropping.\n");
         avfilter_unref_buffer(BUCKET(--queue->available));
     }
diff --git a/mythtv/external/FFmpeg/libavfilter/buffersink.h b/mythtv/external/FFmpeg/libavfilter/buffersink.h
index a4019375d9e..6f8ac5cdf10 100644
--- a/mythtv/external/FFmpeg/libavfilter/buffersink.h
+++ b/mythtv/external/FFmpeg/libavfilter/buffersink.h
@@ -46,6 +46,9 @@ AVBufferSinkParams *av_buffersink_params_alloc(void);
 typedef struct {
     const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
     const int64_t *channel_layouts;         ///< list of allowed channel layouts, terminated by -1
+    const int *channel_counts;              ///< list of allowed channel counts, terminated by -1
+    int all_channel_counts;                 ///< if not 0, accept any channel count or layout
+    int *sample_rates;                      ///< list of allowed sample rates, terminated by -1
 } AVABufferSinkParams;
 
 /**
diff --git a/mythtv/external/FFmpeg/libavfilter/buffersrc.c b/mythtv/external/FFmpeg/libavfilter/buffersrc.c
index 5d0fa92a4b1..d150357ffa3 100644
--- a/mythtv/external/FFmpeg/libavfilter/buffersrc.c
+++ b/mythtv/external/FFmpeg/libavfilter/buffersrc.c
@@ -55,6 +55,7 @@ typedef struct {
     int sample_rate;
     enum AVSampleFormat sample_fmt;
     char               *sample_fmt_str;
+    int channels;
     uint64_t channel_layout;
     char    *channel_layout_str;
 
@@ -120,6 +121,8 @@ int av_buffersrc_add_ref(AVFilterContext *s, AVFilterBufferRef *buf, int flags)
             CHECK_VIDEO_PARAM_CHANGE(s, c, buf->video->w, buf->video->h, buf->format);
             break;
         case AVMEDIA_TYPE_AUDIO:
+            if (!buf->audio->channel_layout)
+                buf->audio->channel_layout = c->channel_layout;
             CHECK_AUDIO_PARAM_CHANGE(s, c, buf->audio->sample_rate, buf->audio->channel_layout,
                                      buf->format);
             break;
@@ -240,6 +243,7 @@ static const AVOption abuffer_options[] = {
     { "time_base",      NULL, OFFSET(time_base),           AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, INT_MAX, FLAGS },
     { "sample_rate",    NULL, OFFSET(sample_rate),         AV_OPT_TYPE_INT,      { .i64 = 0 }, 0, INT_MAX, FLAGS },
     { "sample_fmt",     NULL, OFFSET(sample_fmt_str),      AV_OPT_TYPE_STRING, .flags = FLAGS },
+    { "channels",       NULL, OFFSET(channels),            AV_OPT_TYPE_INT,      { .i64 = 0 }, 0, INT_MAX, FLAGS },
     { "channel_layout", NULL, OFFSET(channel_layout_str),  AV_OPT_TYPE_STRING, .flags = FLAGS },
     { NULL },
 };
@@ -265,6 +269,9 @@ static av_cold int init_audio(AVFilterContext *ctx, const char *args)
         goto fail;
     }
 
+    if (s->channel_layout_str) {
+        int n;
+        /* TODO reindent */
     s->channel_layout = av_get_channel_layout(s->channel_layout_str);
     if (!s->channel_layout) {
         av_log(ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n",
@@ -272,6 +279,24 @@ static av_cold int init_audio(AVFilterContext *ctx, const char *args)
         ret = AVERROR(EINVAL);
         goto fail;
     }
+        n = av_get_channel_layout_nb_channels(s->channel_layout);
+        if (s->channels) {
+            if (n != s->channels) {
+                av_log(ctx, AV_LOG_ERROR,
+                       "Mismatching channel count %d and layout '%s' "
+                       "(%d channels)\n",
+                       s->channels, s->channel_layout_str, n);
+                ret = AVERROR(EINVAL);
+                goto fail;
+            }
+        }
+        s->channels = n;
+    } else if (!s->channels) {
+        av_log(ctx, AV_LOG_ERROR, "Neither number of channels nor "
+                                  "channel layout specified\n");
+        ret = AVERROR(EINVAL);
+        goto fail;
+    }
 
     if (!(s->fifo = av_fifo_alloc(sizeof(AVFilterBufferRef*)))) {
         ret = AVERROR(ENOMEM);
@@ -324,7 +349,9 @@ static int query_formats(AVFilterContext *ctx)
         ff_add_format(&samplerates,       c->sample_rate);
         ff_set_common_samplerates(ctx, samplerates);
 
-        ff_add_channel_layout(&channel_layouts, c->channel_layout);
+        ff_add_channel_layout(&channel_layouts,
+                              c->channel_layout ? c->channel_layout :
+                              FF_COUNT2LAYOUT(c->channels));
         ff_set_common_channel_layouts(ctx, channel_layouts);
         break;
     default:
@@ -345,6 +372,8 @@ static int config_props(AVFilterLink *link)
         link->sample_aspect_ratio = c->pixel_aspect;
         break;
     case AVMEDIA_TYPE_AUDIO:
+        if (!c->channel_layout)
+            c->channel_layout = link->channel_layout;
         break;
     default:
         return AVERROR(EINVAL);
@@ -359,7 +388,6 @@ static int request_frame(AVFilterLink *link)
 {
     BufferSourceContext *c = link->src->priv;
     AVFilterBufferRef *buf;
-    int ret = 0;
 
     if (!av_fifo_size(c->fifo)) {
         if (c->eof)
@@ -369,9 +397,7 @@ static int request_frame(AVFilterLink *link)
     }
     av_fifo_generic_read(c->fifo, &buf, sizeof(buf), NULL);
 
-    ff_filter_frame(link, buf);
-
-    return ret;
+    return ff_filter_frame(link, buf);
 }
 
 static int poll_frame(AVFilterLink *link)
diff --git a/mythtv/external/FFmpeg/libavfilter/f_ebur128.c b/mythtv/external/FFmpeg/libavfilter/f_ebur128.c
index f9da80d1cf8..66cc1337040 100644
--- a/mythtv/external/FFmpeg/libavfilter/f_ebur128.c
+++ b/mythtv/external/FFmpeg/libavfilter/f_ebur128.c
@@ -314,12 +314,15 @@ static int config_video_output(AVFilterLink *outlink)
 static int config_audio_output(AVFilterLink *outlink)
 {
     int i;
+    int idx_bitposn = 0;
     AVFilterContext *ctx = outlink->src;
     EBUR128Context *ebur128 = ctx->priv;
     const int nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout);
 
 #define BACK_MASK (AV_CH_BACK_LEFT    |AV_CH_BACK_CENTER    |AV_CH_BACK_RIGHT| \
-                   AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_BACK_RIGHT)
+                   AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_BACK_RIGHT| \
+                   AV_CH_SIDE_LEFT                          |AV_CH_SIDE_RIGHT| \
+                   AV_CH_SURROUND_DIRECT_LEFT               |AV_CH_SURROUND_DIRECT_RIGHT)
 
     ebur128->nb_channels  = nb_channels;
     ebur128->ch_weighting = av_calloc(nb_channels, sizeof(*ebur128->ch_weighting));
@@ -328,13 +331,24 @@ static int config_audio_output(AVFilterLink *outlink)
 
     for (i = 0; i < nb_channels; i++) {
 
+        /* find the next bit that is set starting from the right */
+        while ((outlink->channel_layout & 1ULL<channel_layout & 1ULL<channel_layout & 1ULL<ch_weighting[i] = 0;
+        } else if (1ULL<ch_weighting[i] = 1.41;
-        else
+        } else {
             ebur128->ch_weighting[i] = 1.0;
+        }
+
+        idx_bitposn++;
+
+        if (!ebur128->ch_weighting[i])
+            continue;
 
         /* bins buffer for the two integration window (400ms and 3s) */
         ebur128->i400.cache[i]  = av_calloc(I400_BINS,  sizeof(*ebur128->i400.cache[0]));
@@ -438,7 +452,7 @@ static int gate_update(struct integrator *integ, double power,
 
 static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamples)
 {
-    int i, ch;
+    int i, ch, idx_insample;
     AVFilterContext *ctx = inlink->dst;
     EBUR128Context *ebur128 = ctx->priv;
     const int nb_channels = ebur128->nb_channels;
@@ -446,7 +460,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamples)
     const double *samples = (double *)insamples->data[0];
     AVFilterBufferRef *pic = ebur128->outpicref;
 
-    for (i = 0; i < nb_samples; i++) {
+    for (idx_insample = 0; idx_insample < nb_samples; idx_insample++) {
         const int bin_id_400  = ebur128->i400.cache_pos;
         const int bin_id_3000 = ebur128->i3000.cache_pos;
 
@@ -464,6 +478,8 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamples)
         for (ch = 0; ch < nb_channels; ch++) {
             double bin;
 
+            ebur128->x[ch * 3] = *samples++; // set X[i]
+
             if (!ebur128->ch_weighting[ch])
                 continue;
 
@@ -477,8 +493,6 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamples)
                                       - dst[1]*name##_A1 - dst[2]*name##_A2;    \
 } while (0)
 
-            ebur128->x[ch * 3] = *samples++; // set X[i]
-
             // TODO: merge both filters in one?
             FILTER(y, x, PRE);  // apply pre-filter
             ebur128->x[ch * 3 + 2] = ebur128->x[ch * 3 + 1];
@@ -505,7 +519,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamples)
             double power_400 = 1e-12, power_3000 = 1e-12;
             AVFilterLink *outlink = ctx->outputs[0];
             const int64_t pts = insamples->pts +
-                av_rescale_q(i, (AVRational){ 1, inlink->sample_rate },
+                av_rescale_q(idx_insample, (AVRational){ 1, inlink->sample_rate },
                              outlink->time_base);
 
             ebur128->sample_count = 0;
diff --git a/mythtv/external/FFmpeg/libavfilter/f_select.c b/mythtv/external/FFmpeg/libavfilter/f_select.c
index 4881a85ece8..0f211454ef7 100644
--- a/mythtv/external/FFmpeg/libavfilter/f_select.c
+++ b/mythtv/external/FFmpeg/libavfilter/f_select.c
@@ -184,6 +184,7 @@ static int config_input(AVFilterLink *inlink)
     select->var_values[VAR_PREV_PTS]          = NAN;
     select->var_values[VAR_PREV_SELECTED_PTS] = NAN;
     select->var_values[VAR_PREV_SELECTED_T]   = NAN;
+    select->var_values[VAR_PREV_T]            = NAN;
     select->var_values[VAR_START_PTS]         = NAN;
     select->var_values[VAR_START_T]           = NAN;
 
@@ -273,7 +274,6 @@ static int select_frame(AVFilterContext *ctx, AVFilterBufferRef *ref)
     select->var_values[VAR_PTS] = TS2D(ref->pts);
     select->var_values[VAR_T  ] = TS2D(ref->pts) * av_q2d(inlink->time_base);
     select->var_values[VAR_POS] = ref->pos == -1 ? NAN : ref->pos;
-    select->var_values[VAR_PREV_PTS] = TS2D(ref ->pts);
 
     switch (inlink->type) {
     case AVMEDIA_TYPE_AUDIO:
@@ -299,11 +299,11 @@ static int select_frame(AVFilterContext *ctx, AVFilterBufferRef *ref)
 
     res = av_expr_eval(select->expr, select->var_values, NULL);
     av_log(inlink->dst, AV_LOG_DEBUG,
-           "n:%d pts:%d t:%f pos:%d key:%d",
-           (int)select->var_values[VAR_N],
-           (int)select->var_values[VAR_PTS],
+           "n:%f pts:%f t:%f pos:%f key:%d",
+           select->var_values[VAR_N],
+           select->var_values[VAR_PTS],
            select->var_values[VAR_T],
-           (int)select->var_values[VAR_POS],
+           select->var_values[VAR_POS],
            (int)select->var_values[VAR_KEY]);
 
     switch (inlink->type) {
@@ -334,6 +334,8 @@ static int select_frame(AVFilterContext *ctx, AVFilterBufferRef *ref)
     }
 
     select->var_values[VAR_N] += 1.0;
+    select->var_values[VAR_PREV_PTS] = select->var_values[VAR_PTS];
+    select->var_values[VAR_PREV_T]   = select->var_values[VAR_T];
 
     return res;
 }
diff --git a/mythtv/external/FFmpeg/libavfilter/f_setpts.c b/mythtv/external/FFmpeg/libavfilter/f_setpts.c
index db1d91cf4e7..1c2edb826b6 100644
--- a/mythtv/external/FFmpeg/libavfilter/f_setpts.c
+++ b/mythtv/external/FFmpeg/libavfilter/f_setpts.c
@@ -27,6 +27,7 @@
 #include "libavutil/eval.h"
 #include "libavutil/internal.h"
 #include "libavutil/mathematics.h"
+#include "libavutil/time.h"
 #include "avfilter.h"
 #include "internal.h"
 #include "audio.h"
@@ -49,6 +50,8 @@ static const char *const var_names[] = {
     "STARTT",      ///< time at start of movie
     "T",           ///< original time in the file of the frame
     "TB",          ///< timebase
+    "RTCTIME",     ///< wallclock (RTC) time in micro seconds
+    "RTCSTART",    ///< wallclock (RTC) time at the start of the movie in micro seconds
     NULL
 };
 
@@ -69,6 +72,8 @@ enum var_name {
     VAR_STARTT,
     VAR_T,
     VAR_TB,
+    VAR_RTCTIME,
+    VAR_RTCSTART,
     VAR_VARS_NB
 };
 
@@ -103,6 +108,7 @@ static int config_input(AVFilterLink *inlink)
 
     setpts->type = inlink->type;
     setpts->var_values[VAR_TB] = av_q2d(inlink->time_base);
+    setpts->var_values[VAR_RTCSTART] = av_gettime();
 
     setpts->var_values[VAR_SAMPLE_RATE] =
         setpts->type == AVMEDIA_TYPE_AUDIO ? inlink->sample_rate : NAN;
@@ -145,6 +151,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame)
     setpts->var_values[VAR_PTS       ] = TS2D(frame->pts);
     setpts->var_values[VAR_T         ] = TS2T(frame->pts, inlink->time_base);
     setpts->var_values[VAR_POS       ] = frame->pos == -1 ? NAN : frame->pos;
+    setpts->var_values[VAR_RTCTIME   ] = av_gettime();
 
     switch (inlink->type) {
     case AVMEDIA_TYPE_VIDEO:
diff --git a/mythtv/external/FFmpeg/libavfilter/formats.c b/mythtv/external/FFmpeg/libavfilter/formats.c
index ea9a184eaac..43718e46557 100644
--- a/mythtv/external/FFmpeg/libavfilter/formats.c
+++ b/mythtv/external/FFmpeg/libavfilter/formats.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
 #include "libavutil/eval.h"
@@ -28,6 +29,8 @@
 #include "internal.h"
 #include "formats.h"
 
+#define KNOWN(l) (!FF_LAYOUT2COUNT(l)) /* for readability */
+
 /**
  * Add all refs from a to ret and destroy a.
  */
@@ -86,13 +89,41 @@ do {
     MERGE_REF(ret, b, fmts, type, fail);                                        \
 } while (0)
 
-AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
+AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b,
+                                  enum AVMediaType type)
 {
     AVFilterFormats *ret = NULL;
+    int i, j;
+    int alpha1=0, alpha2=0;
+    int chroma1=0, chroma2=0;
 
     if (a == b)
         return a;
 
+    /* Do not lose chroma or alpha in merging.
+       It happens if both lists have formats with chroma (resp. alpha), but
+       the only formats in common do not have it (e.g. YUV+gray vs.
+       RGB+gray): in that case, the merging would select the gray format,
+       possibly causing a lossy conversion elsewhere in the graph.
+       To avoid that, pretend that there are no common formats to force the
+       insertion of a conversion filter. */
+    if (type == AVMEDIA_TYPE_VIDEO)
+        for (i = 0; i < a->format_count; i++)
+            for (j = 0; j < b->format_count; j++) {
+                const AVPixFmtDescriptor *adesc = av_pix_fmt_desc_get(a->formats[i]);
+                const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
+                alpha2 |= adesc->flags & bdesc->flags & PIX_FMT_ALPHA;
+                chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
+                if (a->formats[i] == b->formats[j]) {
+                    alpha1 |= adesc->flags & PIX_FMT_ALPHA;
+                    chroma1|= adesc->nb_components > 1;
+                }
+            }
+
+    // If chroma or alpha can be lost through merging then do not merge
+    if (alpha2 > alpha1 || chroma2 > chroma1)
+        return NULL;
+
     MERGE_FORMATS(ret, a, b, formats, format_count, AVFilterFormats, fail);
 
     return ret;
@@ -136,21 +167,77 @@ AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a,
                                                  AVFilterChannelLayouts *b)
 {
     AVFilterChannelLayouts *ret = NULL;
+    unsigned a_all = a->all_layouts + a->all_counts;
+    unsigned b_all = b->all_layouts + b->all_counts;
+    int ret_max, ret_nb = 0, i, j, round;
 
     if (a == b) return a;
 
-    if (a->nb_channel_layouts && b->nb_channel_layouts) {
-        MERGE_FORMATS(ret, a, b, channel_layouts, nb_channel_layouts,
-                      AVFilterChannelLayouts, fail);
-    } else if (a->nb_channel_layouts) {
-        MERGE_REF(a, b, channel_layouts, AVFilterChannelLayouts, fail);
-        ret = a;
-    } else {
+    /* Put the most generic set in a, to avoid doing everything twice */
+    if (a_all < b_all) {
+        FFSWAP(AVFilterChannelLayouts *, a, b);
+        FFSWAP(unsigned, a_all, b_all);
+    }
+    if (a_all) {
+        if (a_all == 1 && !b_all) {
+            /* keep only known layouts in b; works also for b_all = 1 */
+            for (i = j = 0; i < b->nb_channel_layouts; i++)
+                if (KNOWN(b->channel_layouts[i]))
+                    b->channel_layouts[j++] = b->channel_layouts[i];
+            b->nb_channel_layouts = j;
+        }
         MERGE_REF(b, a, channel_layouts, AVFilterChannelLayouts, fail);
-        ret = b;
+        return b;
     }
 
+    ret_max = a->nb_channel_layouts + b->nb_channel_layouts;
+    if (!(ret = av_mallocz(sizeof(*ret))) ||
+        !(ret->channel_layouts = av_malloc(sizeof(*ret->channel_layouts) *
+                                           ret_max)))
+        goto fail;
+
+    /* a[known] intersect b[known] */
+    for (i = 0; i < a->nb_channel_layouts; i++) {
+        if (!KNOWN(a->channel_layouts[i]))
+            continue;
+        for (j = 0; j < b->nb_channel_layouts; j++) {
+            if (a->channel_layouts[i] == b->channel_layouts[j]) {
+                ret->channel_layouts[ret_nb++] = a->channel_layouts[i];
+                a->channel_layouts[i] = b->channel_layouts[j] = 0;
+            }
+        }
+    }
+    /* 1st round: a[known] intersect b[generic]
+       2nd round: a[generic] intersect b[known] */
+    for (round = 0; round < 2; round++) {
+        for (i = 0; i < a->nb_channel_layouts; i++) {
+            uint64_t fmt = a->channel_layouts[i], bfmt;
+            if (!fmt || !KNOWN(fmt))
+                continue;
+            bfmt = FF_COUNT2LAYOUT(av_get_channel_layout_nb_channels(fmt));
+            for (j = 0; j < b->nb_channel_layouts; j++)
+                if (b->channel_layouts[j] == bfmt)
+                    ret->channel_layouts[ret_nb++] = a->channel_layouts[i];
+        }
+        /* 1st round: swap to prepare 2nd round; 2nd round: put it back */
+        FFSWAP(AVFilterChannelLayouts *, a, b);
+    }
+    /* a[generic] intersect b[generic] */
+    for (i = 0; i < a->nb_channel_layouts; i++) {
+        if (KNOWN(a->channel_layouts[i]))
+            continue;
+        for (j = 0; j < b->nb_channel_layouts; j++)
+            if (a->channel_layouts[i] == b->channel_layouts[j])
+                ret->channel_layouts[ret_nb++] = a->channel_layouts[i];
+    }
+
+    ret->nb_channel_layouts = ret_nb;
+    if (!ret->nb_channel_layouts)
+        goto fail;
+    MERGE_REF(ret, a, channel_layouts, AVFilterChannelLayouts, fail);
+    MERGE_REF(ret, b, channel_layouts, AVFilterChannelLayouts, fail);
     return ret;
+
 fail:
     if (ret) {
         av_freep(&ret->refs);
@@ -248,17 +335,19 @@ do {                                                        \
                                                             \
     (*f)->list = fmts;                                      \
     (*f)->list[(*f)->nb++] = fmt;                           \
-    return 0;                                               \
 } while (0)
 
 int ff_add_format(AVFilterFormats **avff, int64_t fmt)
 {
     ADD_FORMAT(avff, fmt, int, formats, format_count);
+    return 0;
 }
 
 int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
 {
+    av_assert1(!(*l && (*l)->all_layouts));
     ADD_FORMAT(l, channel_layout, uint64_t, channel_layouts, nb_channel_layouts);
+    return 0;
 }
 
 AVFilterFormats *ff_all_formats(enum AVMediaType type)
@@ -309,6 +398,18 @@ AVFilterFormats *ff_all_samplerates(void)
 AVFilterChannelLayouts *ff_all_channel_layouts(void)
 {
     AVFilterChannelLayouts *ret = av_mallocz(sizeof(*ret));
+    if (!ret)
+        return NULL;
+    ret->all_layouts = 1;
+    return ret;
+}
+
+AVFilterChannelLayouts *ff_all_channel_counts(void)
+{
+    AVFilterChannelLayouts *ret = av_mallocz(sizeof(*ret));
+    if (!ret)
+        return NULL;
+    ret->all_layouts = ret->all_counts = 1;
     return ret;
 }
 
@@ -443,7 +544,8 @@ void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
                        ff_formats_ref, formats);
 }
 
-int ff_default_query_formats(AVFilterContext *ctx)
+static int default_query_formats_common(AVFilterContext *ctx,
+                                        AVFilterChannelLayouts *(layouts)(void))
 {
     enum AVMediaType type = ctx->inputs  && ctx->inputs [0] ? ctx->inputs [0]->type :
                             ctx->outputs && ctx->outputs[0] ? ctx->outputs[0]->type :
@@ -451,13 +553,23 @@ int ff_default_query_formats(AVFilterContext *ctx)
 
     ff_set_common_formats(ctx, ff_all_formats(type));
     if (type == AVMEDIA_TYPE_AUDIO) {
-        ff_set_common_channel_layouts(ctx, ff_all_channel_layouts());
+        ff_set_common_channel_layouts(ctx, layouts());
         ff_set_common_samplerates(ctx, ff_all_samplerates());
     }
 
     return 0;
 }
 
+int ff_default_query_formats(AVFilterContext *ctx)
+{
+    return default_query_formats_common(ctx, ff_all_channel_layouts);
+}
+
+int ff_query_formats_all(AVFilterContext *ctx)
+{
+    return default_query_formats_common(ctx, ff_all_channel_counts);
+}
+
 /* internal functions for parsing audio format arguments */
 
 int ff_parse_pixel_format(enum AVPixelFormat *ret, const char *arg, void *log_ctx)
diff --git a/mythtv/external/FFmpeg/libavfilter/formats.h b/mythtv/external/FFmpeg/libavfilter/formats.h
index c5a4e3db2b8..c06f6dfa3ca 100644
--- a/mythtv/external/FFmpeg/libavfilter/formats.h
+++ b/mythtv/external/FFmpeg/libavfilter/formats.h
@@ -69,14 +69,45 @@ struct AVFilterFormats {
     struct AVFilterFormats ***refs; ///< references to this list
 };
 
+/**
+ * A list of supported channel layouts.
+ *
+ * The list works the same as AVFilterFormats, except for the following
+ * differences:
+ * - A list with all_layouts = 1 means all channel layouts with a known
+ *   disposition; nb_channel_layouts must then be 0.
+ * - A list with all_counts = 1 means all channel counts, with a known or
+ *   unknown disposition; nb_channel_layouts must then be 0 and all_layouts 1.
+ * - The list must not contain a layout with a known disposition and a
+ *   channel count with unknown disposition with the same number of channels
+ *   (e.g. AV_CH_LAYOUT_STEREO and FF_COUNT2LAYOUT(2).
+ */
 typedef struct AVFilterChannelLayouts {
     uint64_t *channel_layouts;  ///< list of channel layouts
     int    nb_channel_layouts;  ///< number of channel layouts
+    char all_layouts;           ///< accept any known channel layout
+    char all_counts;            ///< accept any channel layout or count
 
     unsigned refcount;          ///< number of references to this list
     struct AVFilterChannelLayouts ***refs; ///< references to this list
 } AVFilterChannelLayouts;
 
+/**
+ * Encode a channel count as a channel layout.
+ * FF_COUNT2LAYOUT(c) means any channel layout with c channels, with a known
+ * or unknown disposition.
+ * The result is only valid inside AVFilterChannelLayouts and immediately
+ * related functions.
+ */
+#define FF_COUNT2LAYOUT(c) (0x8000000000000000ULL | (c))
+
+/**
+ * Decode a channel count encoded as a channel layout.
+ * Return 0 if the channel layout was a real one.
+ */
+#define FF_LAYOUT2COUNT(l) (((l) & 0x8000000000000000ULL) ? \
+                           (int)((l) & 0x7FFFFFFF) : 0)
+
 /**
  * Return a channel layouts/samplerates list which contains the intersection of
  * the layouts/samplerates of a and b. Also, all the references of a, all the
@@ -92,11 +123,17 @@ AVFilterFormats *ff_merge_samplerates(AVFilterFormats *a,
 
 /**
  * Construct an empty AVFilterChannelLayouts/AVFilterFormats struct --
- * representing any channel layout/sample rate.
+ * representing any channel layout (with known disposition)/sample rate.
  */
 AVFilterChannelLayouts *ff_all_channel_layouts(void);
 AVFilterFormats *ff_all_samplerates(void);
 
+/**
+ * Construct an AVFilterChannelLayouts coding for any channel layout, with
+ * known or unknown disposition.
+ */
+AVFilterChannelLayouts *ff_all_channel_counts(void);
+
 AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts);
 
 
@@ -135,6 +172,14 @@ void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref,
 
 int ff_default_query_formats(AVFilterContext *ctx);
 
+/**
+ * Set the formats list to all existing formats.
+ * This function behaves like ff_default_query_formats(), except it also
+ * accepts channel layouts with unknown disposition. It should only be used
+ * with audio filters.
+ */
+int ff_query_formats_all(AVFilterContext *ctx);
+
 
 /**
  * Create a list of supported formats. This is intended for use in
@@ -173,7 +218,8 @@ AVFilterFormats *ff_planar_sample_fmts(void);
  * If a and b do not share any common formats, neither is modified, and NULL
  * is returned.
  */
-AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b);
+AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b,
+                                  enum AVMediaType type);
 
 /**
  * Add *ref as a new reference to formats.
diff --git a/mythtv/external/FFmpeg/libavfilter/graphparser.c b/mythtv/external/FFmpeg/libavfilter/graphparser.c
index 0ce823a10d8..3e85261c382 100644
--- a/mythtv/external/FFmpeg/libavfilter/graphparser.c
+++ b/mythtv/external/FFmpeg/libavfilter/graphparser.c
@@ -20,7 +20,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
 #include 
 #include 
 
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vd_ffmpeg.h b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/av_helpers.h
similarity index 83%
rename from mythtv/external/FFmpeg/libavfilter/libmpcodecs/vd_ffmpeg.h
rename to mythtv/external/FFmpeg/libavfilter/libmpcodecs/av_helpers.h
index 081d6ee5456..90b67d5a0f1 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vd_ffmpeg.h
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/av_helpers.h
@@ -1,4 +1,6 @@
 /*
+ * Generic libav* helpers
+ *
  * This file is part of MPlayer.
  *
  * MPlayer is free software; you can redistribute it and/or modify
@@ -16,9 +18,10 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifndef MPLAYER_VD_FFMPEG_H
-#define MPLAYER_VD_FFMPEG_H
+#ifndef MPLAYER_AV_HELPERS_H
+#define MPLAYER_AV_HELPERS_H
 
 void ff_init_avcodec(void);
+void ff_init_avformat(void);
 
-#endif /* MPLAYER_VD_FFMPEG_H */
+#endif /* MPLAYER_AV_HELPERS_H */
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/cpudetect.h b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/cpudetect.h
index c0bb7b763b1..710f6e65135 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/cpudetect.h
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/cpudetect.h
@@ -19,8 +19,6 @@
 #ifndef MPLAYER_CPUDETECT_H
 #define MPLAYER_CPUDETECT_H
 
-//#include "config.h"
-
 #define CPUTYPE_I386    3
 #define CPUTYPE_I486    4
 #define CPUTYPE_I586    5
@@ -40,7 +38,10 @@ typedef struct cpucaps_s {
     int hasSSE2;
     int hasSSE3;
     int hasSSSE3;
+    int hasSSE4;
+    int hasSSE42;
     int hasSSE4a;
+    int hasAVX;
     int isX86;
     unsigned cl_size; /* size of cache line */
     int hasAltiVec;
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/help_mp.h b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/help_mp.h
index 87b828d9332..6ceb6301f36 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/help_mp.h
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/help_mp.h
@@ -70,12 +70,14 @@ static const char help_text[]=
 #define MSGTR_NoHomeDir "Cannot find HOME directory.\n"
 #define MSGTR_GetpathProblem "get_path(\"config\") problem\n"
 #define MSGTR_CreatingCfgFile "Creating config file: %s\n"
-#define MSGTR_BuiltinCodecsConf "Using built-in default codecs.conf.\n"
-#define MSGTR_CantLoadFont "Cannot load bitmap font: %s\n"
-#define MSGTR_CantLoadSub "Cannot load subtitles: %s\n"
+#define MSGTR_CantLoadFont "Cannot load bitmap font '%s'.\n"
+#define MSGTR_CantLoadSub "Cannot load subtitles '%s'.\n"
 #define MSGTR_DumpSelectedStreamMissing "dump: FATAL: Selected stream missing!\n"
 #define MSGTR_CantOpenDumpfile "Cannot open dump file.\n"
 #define MSGTR_CoreDumped "Core dumped ;)\n"
+#define MSGTR_DumpBytesWrittenPercent "dump: %"PRIu64" bytes written (~%.1f%%)\r"
+#define MSGTR_DumpBytesWritten "dump: %"PRIu64" bytes written\r"
+#define MSGTR_DumpBytesWrittenTo "dump: %"PRIu64" bytes written to '%s'.\n"
 #define MSGTR_FPSnotspecified "FPS not specified in the header or invalid, use the -fps option.\n"
 #define MSGTR_TryForceAudioFmtStr "Trying to force audio codec driver family %s...\n"
 #define MSGTR_CantFindAudioCodec "Cannot find codec for audio format 0x%X.\n"
@@ -112,8 +114,6 @@ static const char help_text[]=
 #define MSGTR_Playing "\nPlaying %s.\n"
 #define MSGTR_NoSound "Audio: no sound\n"
 #define MSGTR_FPSforced "FPS forced to be %5.3f  (ftime: %5.3f).\n"
-#define MSGTR_CompiledWithRuntimeDetection "Compiled with runtime CPU detection.\n"
-#define MSGTR_CompiledWithCPUExtensions "Compiled for x86 CPU with extensions:"
 #define MSGTR_AvailableVideoOutputDrivers "Available video output drivers:\n"
 #define MSGTR_AvailableAudioOutputDrivers "Available audio output drivers:\n"
 #define MSGTR_AvailableAudioCodecs "Available audio codecs:\n"
@@ -121,7 +121,6 @@ static const char help_text[]=
 #define MSGTR_AvailableAudioFm "Available (compiled-in) audio codec families/drivers:\n"
 #define MSGTR_AvailableVideoFm "Available (compiled-in) video codec families/drivers:\n"
 #define MSGTR_AvailableFsType "Available fullscreen layer change modes:\n"
-#define MSGTR_UsingRTCTiming "Using Linux hardware RTC timing (%ldHz).\n"
 #define MSGTR_CannotReadVideoProperties "Video: Cannot read properties.\n"
 #define MSGTR_NoStreamFound "No stream found.\n"
 #define MSGTR_ErrorInitializingVODevice "Error opening/initializing the selected video_out (-vo) device.\n"
@@ -129,7 +128,7 @@ static const char help_text[]=
 #define MSGTR_ForcedAudioCodec "Forced audio codec: %s\n"
 #define MSGTR_Video_NoVideo "Video: no video\n"
 #define MSGTR_NotInitializeVOPorVO "\nFATAL: Could not initialize video filters (-vf) or video output (-vo).\n"
-#define MSGTR_Paused "\n  =====  PAUSE  =====\r" // no more than 23 characters (status line for audio files)
+#define MSGTR_Paused "  =====  PAUSE  =====" // no more than 23 characters (status line for audio files)
 #define MSGTR_PlaylistLoadUnable "\nUnable to load playlist %s.\n"
 #define MSGTR_Exit_SIGILL_RTCpuSel \
 "- MPlayer crashed by an 'Illegal Instruction'.\n"\
@@ -156,15 +155,11 @@ static const char help_text[]=
 #define MSGTR_AddedSubtitleFile "SUB: Added subtitle file (%d): %s\n"
 #define MSGTR_RemovedSubtitleFile "SUB: Removed subtitle file (%d): %s\n"
 #define MSGTR_ErrorOpeningOutputFile "Error opening file [%s] for writing!\n"
-#define MSGTR_CommandLine "CommandLine:"
 #define MSGTR_RTCDeviceNotOpenable "Failed to open %s: %s (it should be readable by the user.)\n"
 #define MSGTR_LinuxRTCInitErrorIrqpSet "Linux RTC init error in ioctl (rtc_irqp_set %lu): %s\n"
 #define MSGTR_IncreaseRTCMaxUserFreq "Try adding \"echo %lu > /proc/sys/dev/rtc/max-user-freq\" to your system startup scripts.\n"
 #define MSGTR_LinuxRTCInitErrorPieOn "Linux RTC init error in ioctl (rtc_pie_on): %s\n"
 #define MSGTR_UsingTimingType "Using %s timing.\n"
-#define MSGTR_NoIdleAndGui "The -idle option cannot be used with GMPlayer.\n"
-#define MSGTR_MenuInitialized "Menu initialized: %s\n"
-#define MSGTR_MenuInitFailed "Menu init failed.\n"
 #define MSGTR_Getch2InitializedTwice "WARNING: getch2_init called twice!\n"
 #define MSGTR_DumpstreamFdUnavailable "Cannot dump this stream - no file descriptor available.\n"
 #define MSGTR_CantOpenLibmenuFilterWithThisRootMenu "Can't open libmenu video filter with root menu %s.\n"
@@ -188,6 +183,17 @@ static const char help_text[]=
 #define MSGTR_MenuCall "Menu call\n"
 #define MSGTR_MasterQuit "Option -udp-slave: exiting because master exited\n"
 #define MSGTR_InvalidIP "Option -udp-ip: invalid IP address\n"
+#define MSGTR_Forking "Forking...\n"
+#define MSGTR_Forked "Forked...\n"
+#define MSGTR_CouldntStartGdb "Couldn't start gdb\n"
+#define MSGTR_CouldntFork "Couldn't fork\n"
+#define MSGTR_FilenameTooLong "Filename is too long, can not load file or directory specific config files\n"
+#define MSGTR_AudioDeviceStuck "Audio device got stuck!\n"
+#define MSGTR_AudioOutputTruncated "Audio output truncated at end.\n"
+#define MSGTR_ASSCannotAddVideoFilter "ASS: cannot add video filter\n"
+#define MSGTR_PtsAfterFiltersMissing "pts after filters MISSING\n"
+#define MSGTR_CommandLine "CommandLine:"
+#define MSGTR_MenuInitFailed "Menu init failed.\n"
 
 // --- edit decision lists
 #define MSGTR_EdlOutOfMem "Can't allocate enough memory to hold EDL data.\n"
@@ -205,7 +211,6 @@ static const char help_text[]=
 #define MSGTR_EdloutBadStop "EDL skip canceled, last start > stop\n"
 #define MSGTR_EdloutStartSkip "EDL skip start, press 'i' again to end block.\n"
 #define MSGTR_EdloutEndSkip "EDL skip end, line written.\n"
-#define MSGTR_MPEndposNoSizeBased "Option -endpos in MPlayer does not yet support size units.\n"
 
 // mplayer.c OSD
 #define MSGTR_OSDenabled "enabled"
@@ -219,6 +224,8 @@ static const char help_text[]=
 #define MSGTR_OSDChapter "Chapter: (%d) %s"
 #define MSGTR_OSDAngle "Angle: %d/%d"
 #define MSGTR_OSDDeinterlace "Deinterlace: %s"
+#define MSGTR_OSDCapturing "Capturing: %s"
+#define MSGTR_OSDCapturingFailure "Capturing failed"
 
 // property values
 #define MSGTR_Enabled "enabled"
@@ -298,12 +305,9 @@ static const char help_text[]=
 #define MSGTR_CannotAllocateBytes "Couldn't allocate %d bytes.\n"
 #define MSGTR_SettingAudioDelay "Setting audio delay to %5.3fs.\n"
 #define MSGTR_SettingVideoDelay "Setting video delay to %5.3fs.\n"
-#define MSGTR_SettingAudioInputGain "Setting audio input gain to %f.\n"
-#define MSGTR_LamePresetEquals "\npreset=%s\n\n"
 #define MSGTR_LimitingAudioPreload "Limiting audio preload to 0.4s.\n"
 #define MSGTR_IncreasingAudioDensity "Increasing audio density to 4.\n"
 #define MSGTR_ZeroingAudioPreloadAndMaxPtsCorrection "Forcing audio preload to 0, max pts correction to 0.\n"
-#define MSGTR_CBRAudioByterate "\n\nCBR audio: %d bytes/sec, %d bytes/block\n"
 #define MSGTR_LameVersion "LAME version %s (%s)\n\n"
 #define MSGTR_InvalidBitrateForLamePreset "Error: The bitrate specified is out of the valid range for this preset.\n"\
 "\n"\
@@ -411,7 +415,7 @@ static const char help_text[]=
 "Cannot set LAME options, check bitrate/samplerate, some very low bitrates\n"\
 "(<32) need lower samplerates (i.e. -srate 8000).\n"\
 "If everything else fails, try a preset."
-#define MSGTR_ConfigFileError "config file error"
+#define MSGTR_ConfigFileError "Config file error"
 #define MSGTR_ErrorParsingCommandLine "error parsing command line"
 #define MSGTR_VideoStreamRequired "Video stream is mandatory!\n"
 #define MSGTR_ForcingInputFPS "Input fps will be interpreted as %5.3f instead.\n"
@@ -490,8 +494,6 @@ static const char help_text[]=
 #define MSGTR_CodecNeedsOutfmt "\ncodec(%s) needs an 'outfmt'!\n"
 #define MSGTR_CantAllocateComment "Can't allocate memory for comment. "
 #define MSGTR_GetTokenMaxNotLessThanMAX_NR_TOKEN "get_token(): max >= MAX_MR_TOKEN!"
-#define MSGTR_ReadingFile "Reading %s: "
-#define MSGTR_CantOpenFileError "Can't open '%s': %s\n"
 #define MSGTR_CantGetMemoryForLine "Can't get memory for 'line': %s\n"
 #define MSGTR_CantReallocCodecsp "Can't realloc '*codecsp': %s\n"
 #define MSGTR_CodecNameNotUnique "Codec name '%s' isn't unique."
@@ -557,10 +559,40 @@ static const char help_text[]=
 #define MSGTR_Preferences "Preferences"
 #define MSGTR_AudioPreferences "Audio driver configuration"
 #define MSGTR_NoMediaOpened "No media opened."
-#define MSGTR_VCDTrack "VCD track %d"
+#define MSGTR_Title "Title %d"
 #define MSGTR_NoChapter "No chapter"
 #define MSGTR_Chapter "Chapter %d"
 #define MSGTR_NoFileLoaded "No file loaded."
+#define MSGTR_Filter_UTF8Subtitles "UTF-8 encoded subtitles (*.utf, *.utf-8, *.utf8)"
+#define MSGTR_Filter_AllSubtitles "All subtitles"
+#define MSGTR_Filter_AllFiles "All files"
+#define MSGTR_Filter_TTF "True Type fonts (*.ttf)"
+#define MSGTR_Filter_Type1 "Type1 fonts (*.pfb)"
+#define MSGTR_Filter_AllFonts "All fonts"
+#define MSGTR_Filter_FontFiles "Font files (*.desc)"
+#define MSGTR_Filter_DDRawAudio "Dolby Digital / PCM (*.ac3, *.pcm)"
+#define MSGTR_Filter_MPEGAudio "MPEG audio (*.mp2, *.mp3, *.mpga, *.m4a, *.aac, *.f4a)"
+#define MSGTR_Filter_MatroskaAudio "Matroska audio (*.mka)"
+#define MSGTR_Filter_OGGAudio "Ogg audio (*.oga, *.ogg, *.spx)"
+#define MSGTR_Filter_WAVAudio "WAV audio (*.wav)"
+#define MSGTR_Filter_WMAAudio "Windows Media audio (*.wma)"
+#define MSGTR_Filter_AllAudioFiles "All audio files"
+#define MSGTR_Filter_AllVideoFiles "All video files"
+#define MSGTR_Filter_AVIFiles "AVI files"
+#define MSGTR_Filter_DivXFiles "DivX files"
+#define MSGTR_Filter_FlashVideo "Flash Video"
+#define MSGTR_Filter_MP3Files "MP3 files"
+#define MSGTR_Filter_MP4Files "MP4 files"
+#define MSGTR_Filter_MPEGFiles "MPEG files"
+#define MSGTR_Filter_MP2TS "MPEG-2 transport streams"
+#define MSGTR_Filter_MatroskaMedia "Matroska media"
+#define MSGTR_Filter_OGGMedia "Ogg media"
+#define MSGTR_Filter_QTMedia "QuickTime media"
+#define MSGTR_Filter_RNMedia "RealNetworks media"
+#define MSGTR_Filter_VideoCDImages "VCD/SVCD images"
+#define MSGTR_Filter_WAVFiles "WAV files"
+#define MSGTR_Filter_WindowsMedia "Windows media"
+#define MSGTR_Filter_Playlists "Playlists"
 
 // --- buttons ---
 #define MSGTR_Ok "OK"
@@ -573,43 +605,43 @@ static const char help_text[]=
 #define MSGTR_Browse "Browse"
 
 // --- error messages ---
-#define MSGTR_NEMDB "Sorry, not enough memory to draw buffer."
+#define MSGTR_NEMDB "Sorry, not enough memory to draw buffer.\n"
 #define MSGTR_NEMFMR "Sorry, not enough memory for menu rendering."
-#define MSGTR_IDFGCVD "Sorry, I did not find a GUI-compatible video output driver."
+#define MSGTR_IDFGCVD "Sorry, no GUI-compatible video output driver found.\n"
 #define MSGTR_NEEDLAVC "Sorry, you cannot play non-MPEG files with your DXR3/H+ device without reencoding.\nPlease enable lavc in the DXR3/H+ configuration box."
-#define MSGTR_UNKNOWNWINDOWTYPE "Unknown window type found ..."
+#define MSGTR_ICONERROR "Icon '%s' (size %d) not found or unsupported format.\n"
 
 // --- skin loader error messages
-#define MSGTR_SKIN_ERRORMESSAGE "[skin] error in skin config file on line %d: %s"
-#define MSGTR_SKIN_WARNING1 "[skin] warning: in config file line %d:\nwidget (%s) found but no \"section\" found before"
-#define MSGTR_SKIN_WARNING2 "[skin] warning: in config file line %d:\nwidget (%s) found but no \"subsection\" found before"
-#define MSGTR_SKIN_WARNING3 "[skin] warning: in config file line %d:\nthis subsection is not supported by widget (%s)"
-#define MSGTR_SKIN_SkinFileNotFound "[skin] file ( %s ) not found.\n"
-#define MSGTR_SKIN_SkinFileNotReadable "[skin] file ( %s ) not readable.\n"
-#define MSGTR_SKIN_BITMAP_16bit  "Bitmaps of 16 bits or less depth not supported (%s).\n"
-#define MSGTR_SKIN_BITMAP_FileNotFound  "File not found (%s)\n"
-#define MSGTR_SKIN_BITMAP_BMPReadError "BMP read error (%s)\n"
-#define MSGTR_SKIN_BITMAP_TGAReadError "TGA read error (%s)\n"
-#define MSGTR_SKIN_BITMAP_PNGReadError "PNG read error (%s)\n"
-#define MSGTR_SKIN_BITMAP_RLENotSupported "RLE packed TGA not supported (%s)\n"
-#define MSGTR_SKIN_BITMAP_UnknownFileType "unknown file type (%s)\n"
-#define MSGTR_SKIN_BITMAP_ConversionError "24 bit to 32 bit conversion error (%s)\n"
-#define MSGTR_SKIN_BITMAP_UnknownMessage "unknown message: %s\n"
-#define MSGTR_SKIN_FONT_NotEnoughtMemory "not enough memory\n"
+#define MSGTR_SKIN_ERRORMESSAGE "Error in skin config file on line %d: %s"
+#define MSGTR_SKIN_ERROR_SECTION "No section specified for '%s'.\n"
+#define MSGTR_SKIN_ERROR_WINDOW "No window specified for '%s'.\n"
+#define MSGTR_SKIN_ERROR_ITEM "This item is not supported by '%s'.\n"
+#define MSGTR_SKIN_UNKNOWN_ITEM "Unknown item '%s'\n"
+#define MSGTR_SKIN_UNKNOWN_NAME "Unknown name '%s'\n"
+#define MSGTR_SKIN_SkinFileNotFound "Skin file %s not found.\n"
+#define MSGTR_SKIN_SkinFileNotReadable "Skin file %s not readable.\n"
+#define MSGTR_SKIN_BITMAP_16bit  "Color depth of bitmap %s is 16 bits or less which is not supported.\n"
+#define MSGTR_SKIN_BITMAP_FileNotFound  "Bitmap %s not found.\n"
+#define MSGTR_SKIN_BITMAP_PNGReadError "PNG read error in %s\n"
+#define MSGTR_SKIN_BITMAP_ConversionError "24 bit to 32 bit conversion error in %s\n"
+#define MSGTR_SKIN_UnknownMessage "Unknown message '%s'\n"
+#define MSGTR_SKIN_NotEnoughMemory "Not enough memory\n"
+#define MSGTR_SKIN_TooManyItemsDeclared "Too many items declared.\n"
 #define MSGTR_SKIN_FONT_TooManyFontsDeclared "Too many fonts declared.\n"
-#define MSGTR_SKIN_FONT_FontFileNotFound "Font file not found.\n"
+#define MSGTR_SKIN_FONT_FontFileNotFound "Font description file not found.\n"
 #define MSGTR_SKIN_FONT_FontImageNotFound "Font image file not found.\n"
-#define MSGTR_SKIN_FONT_NonExistentFontID "non-existent font identifier (%s)\n"
-#define MSGTR_SKIN_UnknownParameter "unknown parameter (%s)\n"
-#define MSGTR_SKIN_SKINCFG_SkinNotFound "Skin not found (%s).\n"
-#define MSGTR_SKIN_SKINCFG_SelectedSkinNotFound "Selected skin ( %s ) not found, trying 'default'...\n"
-#define MSGTR_SKIN_SKINCFG_SkinCfgReadError "skin config file read error (%s)\n"
+#define MSGTR_SKIN_FONT_NonExistentFont "Font '%s' not found.\n"
+#define MSGTR_SKIN_UnknownParameter "Unknown parameter '%s'\n"
+#define MSGTR_SKIN_SKINCFG_SkinNotFound "Skin '%s' not found.\n"
+#define MSGTR_SKIN_SKINCFG_SelectedSkinNotFound "Selected skin '%s' not found, trying skin 'default'...\n"
+#define MSGTR_SKIN_SKINCFG_SkinCfgError "Config file processing error with skin '%s'\n"
 #define MSGTR_SKIN_LABEL "Skins:"
 
 // --- GTK menus
 #define MSGTR_MENU_AboutMPlayer "About MPlayer"
 #define MSGTR_MENU_Open "Open..."
 #define MSGTR_MENU_PlayFile "Play file..."
+#define MSGTR_MENU_PlayCD "Play CD..."
 #define MSGTR_MENU_PlayVCD "Play VCD..."
 #define MSGTR_MENU_PlayDVD "Play DVD..."
 #define MSGTR_MENU_PlayURL "Play URL..."
@@ -627,6 +659,7 @@ static const char help_text[]=
 #define MSGTR_MENU_NormalSize "Normal size"
 #define MSGTR_MENU_DoubleSize "Double size"
 #define MSGTR_MENU_FullScreen "Fullscreen"
+#define MSGTR_MENU_CD "CD"
 #define MSGTR_MENU_DVD "DVD"
 #define MSGTR_MENU_VCD "VCD"
 #define MSGTR_MENU_PlayDisc "Open disc..."
@@ -641,7 +674,7 @@ static const char help_text[]=
 #define MSGTR_MENU_PlayList MSGTR_PlayList
 #define MSGTR_MENU_SkinBrowser "Skin browser"
 #define MSGTR_MENU_Preferences MSGTR_Preferences
-#define MSGTR_MENU_Exit "Exit..."
+#define MSGTR_MENU_Exit "Exit"
 #define MSGTR_MENU_Mute "Mute"
 #define MSGTR_MENU_Original "Original"
 #define MSGTR_MENU_AspectRatio "Aspect ratio"
@@ -702,9 +735,10 @@ static const char help_text[]=
 #define MSGTR_PREFERENCES_HFrameDrop "Enable HARD frame dropping (dangerous)"
 #define MSGTR_PREFERENCES_Flip "Flip image upside down"
 #define MSGTR_PREFERENCES_Panscan "Panscan: "
-#define MSGTR_PREFERENCES_OSDTimer "Timer and indicators"
-#define MSGTR_PREFERENCES_OSDProgress "Progressbars only"
-#define MSGTR_PREFERENCES_OSDTimerPercentageTotalTime "Timer, percentage and total time"
+#define MSGTR_PREFERENCES_OSD_LEVEL0 "Subtitles only"
+#define MSGTR_PREFERENCES_OSD_LEVEL1 "Volume and seek"
+#define MSGTR_PREFERENCES_OSD_LEVEL2 "Volume, seek, timer and percentage"
+#define MSGTR_PREFERENCES_OSD_LEVEL3 "Volume, seek, timer, percentage and total time"
 #define MSGTR_PREFERENCES_Subtitle "Subtitle:"
 #define MSGTR_PREFERENCES_SUB_Delay "Delay: "
 #define MSGTR_PREFERENCES_SUB_FPS "FPS:"
@@ -777,6 +811,7 @@ static const char help_text[]=
 #define MSGTR_PREFERENCES_SaveWinPos "Save window position"
 #define MSGTR_PREFERENCES_XSCREENSAVER "Stop XScreenSaver"
 #define MSGTR_PREFERENCES_PlayBar "Enable playbar"
+#define MSGTR_PREFERENCES_NoIdle "Quit after playing"
 #define MSGTR_PREFERENCES_AutoSync "AutoSync on/off"
 #define MSGTR_PREFERENCES_AutoSyncValue "Autosync: "
 #define MSGTR_PREFERENCES_CDROMDevice "CD-ROM device:"
@@ -798,39 +833,62 @@ static const char help_text[]=
 #define MSGTR_MSGBOX_LABEL_Error "Error!"
 #define MSGTR_MSGBOX_LABEL_Warning "Warning!"
 
-// bitmap.c
-#define MSGTR_NotEnoughMemoryC32To1 "[c32to1] not enough memory for image\n"
-#define MSGTR_NotEnoughMemoryC1To32 "[c1to32] not enough memory for image\n"
-
 // cfg.c
-#define MSGTR_ConfigFileReadError "[cfg] config file read error ...\n"
-#define MSGTR_UnableToSaveOption "[cfg] Unable to save the '%s' option.\n"
+#define MSGTR_UnableToSaveOption "Unable to save option '%s'.\n"
 
 // interface.c
-#define MSGTR_DeletingSubtitles "[GUI] Deleting subtitles.\n"
-#define MSGTR_LoadingSubtitles "[GUI] Loading subtitles: %s\n"
-#define MSGTR_AddingVideoFilter "[GUI] Adding video filter: %s\n"
-#define MSGTR_RemovingVideoFilter "[GUI] Removing video filter: %s\n"
+#define MSGTR_DeletingSubtitles "Deleting subtitles.\n"
+#define MSGTR_LoadingSubtitles "Loading subtitles '%s'.\n"
+#define MSGTR_AddingVideoFilter "Adding video filter '%s'.\n"
 
 // mw.c
 #define MSGTR_NotAFile "This does not seem to be a file: %s !\n"
 
 // ws.c
-#define MSGTR_WS_CouldNotOpenDisplay "[ws] Could not open the display.\n"
-#define MSGTR_WS_RemoteDisplay "[ws] Remote display, disabling XMITSHM.\n"
-#define MSGTR_WS_NoXshm "[ws] Sorry, your system does not support the X shared memory extension.\n"
-#define MSGTR_WS_NoXshape "[ws] Sorry, your system does not support the XShape extension.\n"
-#define MSGTR_WS_ColorDepthTooLow "[ws] Sorry, the color depth is too low.\n"
-#define MSGTR_WS_TooManyOpenWindows "[ws] There are too many open windows.\n"
-#define MSGTR_WS_ShmError "[ws] shared memory extension error\n"
-#define MSGTR_WS_NotEnoughMemoryDrawBuffer "[ws] Sorry, not enough memory to draw buffer.\n"
+#define MSGTR_WS_RemoteDisplay "Remote display, disabling XMITSHM.\n"
+#define MSGTR_WS_NoXshm "Sorry, your system does not support the X shared memory extension.\n"
+#define MSGTR_WS_NoXshape "Sorry, your system does not support the XShape extension.\n"
+#define MSGTR_WS_ColorDepthTooLow "Sorry, the color depth is too low.\n"
+#define MSGTR_WS_TooManyOpenWindows "There are too many open windows.\n"
+#define MSGTR_WS_ShmError "shared memory extension error\n"
+#define MSGTR_WS_NotEnoughMemoryDrawBuffer "Sorry, not enough memory to draw buffer.\n"
 #define MSGTR_WS_DpmsUnavailable "DPMS not available?\n"
 #define MSGTR_WS_DpmsNotEnabled "Could not enable DPMS.\n"
+#define MSGTR_WS_XError "An X11 Error has occurred!\n"
 
 // wsxdnd.c
 #define MSGTR_WS_NotAFile "This does not seem to be a file...\n"
 #define MSGTR_WS_DDNothing "D&D: Nothing returned!\n"
 
+// Win32 GUI
+#define MSGTR_Close "Close"
+#define MSGTR_Default "Defaults"
+#define MSGTR_Down "Down"
+#define MSGTR_Load "Load"
+#define MSGTR_Save "Save"
+#define MSGTR_Up "Up"
+#define MSGTR_DirectorySelect "Select directory..."
+#define MSGTR_PlaylistSave "Save playlist..."
+#define MSGTR_PlaylistSelect "Select playlist..."
+#define MSGTR_SelectTitleChapter "Select title/chapter..."
+#define MSGTR_MENU_DebugConsole "Debug Console"
+#define MSGTR_MENU_OnlineHelp "Online Help"
+#define MSGTR_MENU_PlayDirectory "Play directory..."
+#define MSGTR_MENU_SeekBack "Seek Backwards"
+#define MSGTR_MENU_SeekForw "Seek Forwards"
+#define MSGTR_MENU_ShowHide "Show/Hide"
+#define MSGTR_MENU_SubtitlesOnOff "Subtitle Visibility On/Off"
+#define MSGTR_PLAYLIST_AddFile "Add File..."
+#define MSGTR_PLAYLIST_AddURL "Add URL..."
+#define MSGTR_PREFERENCES_Priority "Priority:"
+#define MSGTR_PREFERENCES_PriorityHigh "high"
+#define MSGTR_PREFERENCES_PriorityLow "low"
+#define MSGTR_PREFERENCES_PriorityNormal "normal"
+#define MSGTR_PREFERENCES_PriorityNormalAbove "above normal"
+#define MSGTR_PREFERENCES_PriorityNormalBelow "below normal"
+#define MSGTR_PREFERENCES_ShowInVideoWin "Display in the video window (DirectX only)"
+
+
 // ======================= video output drivers ========================
 
 #define MSGTR_VOincompCodec "The selected video_out device is incompatible with this codec.\n"\
@@ -984,7 +1042,6 @@ static const char help_text[]=
 // vo_sdl.c
 #define MSGTR_LIBVO_SDL_CouldntGetAnyAcceptableSDLModeForOutput "[VO_SDL] Couldn't get any acceptable SDL Mode for output.\n"
 #define MSGTR_LIBVO_SDL_SetVideoModeFailed "[VO_SDL] set_video_mode: SDL_SetVideoMode failed: %s.\n"
-#define MSGTR_LIBVO_SDL_SetVideoModeFailedFull "[VO_SDL] Set_fullmode: SDL_SetVideoMode failed: %s.\n"
 #define MSGTR_LIBVO_SDL_MappingI420ToIYUV "[VO_SDL] Mapping I420 to IYUV.\n"
 #define MSGTR_LIBVO_SDL_UnsupportedImageFormat "[VO_SDL] Unsupported image format (0x%X).\n"
 #define MSGTR_LIBVO_SDL_InfoPleaseUseVmOrZoom "[VO_SDL] Info - please use -vm or -zoom to switch to the best resolution.\n"
@@ -1151,16 +1208,15 @@ static const char help_text[]=
 // old vo drivers that have been replaced
 #define MSGTR_VO_PGM_HasBeenReplaced "The pgm video output driver has been replaced by -vo pnm:pgmyuv.\n"
 #define MSGTR_VO_MD5_HasBeenReplaced "The md5 video output driver has been replaced by -vo md5sum.\n"
+#define MSGTR_VO_GL2_HasBeenRenamed "The gl2 video output driver has been renamed to -vo gl_tiled, but you really should be using -vo gl instead.\n"
 
 
 // ======================= audio output drivers ========================
 
 // audio_out.c
 #define MSGTR_AO_ALSA9_1x_Removed "audio_out: alsa9 and alsa1x modules were removed, use -ao alsa instead.\n"
-#define MSGTR_AO_TryingPreferredAudioDriver "Trying preferred audio driver '%.*s', options '%s'\n"
 #define MSGTR_AO_NoSuchDriver "No such audio driver '%.*s'\n"
 #define MSGTR_AO_FailedInit "Failed to initialize audio driver '%s'\n"
-#define MSGTR_AO_TryingEveryKnown "Trying every known audio driver...\n"
 
 // ao_oss.c
 #define MSGTR_AO_OSS_CantOpenMixer "[AO OSS] audio_setup: Can't open mixer device %s: %s\n"
@@ -1196,7 +1252,7 @@ static const char help_text[]=
 
 // ao_pcm.c
 #define MSGTR_AO_PCM_FileInfo "[AO PCM] File: %s (%s)\nPCM: Samplerate: %iHz Channels: %s Format %s\n"
-#define MSGTR_AO_PCM_HintInfo "[AO PCM] Info: Faster dumping is achieved with -vc null -vo null -ao pcm:fast\n[AO PCM] Info: To write WAVE files use -ao pcm:waveheader (default).\n"
+#define MSGTR_AO_PCM_HintInfo "[AO PCM] Info: Faster dumping is achieved with -benchmark -vc null -vo null -ao pcm:fast\n[AO PCM] Info: To write WAVE files use -ao pcm:waveheader (default).\n"
 #define MSGTR_AO_PCM_CantOpenOutputFile "[AO PCM] Failed to open %s for writing!\n"
 
 // ao_sdl.c
@@ -1213,7 +1269,7 @@ static const char help_text[]=
 #define MSGTR_AO_SGI_CantSetParms_Samplerate "[AO SGI] init: setparams failed: %s\nCould not set desired samplerate.\n"
 #define MSGTR_AO_SGI_CantSetAlRate "[AO SGI] init: AL_RATE was not accepted on the given resource.\n"
 #define MSGTR_AO_SGI_CantGetParms "[AO SGI] init: getparams failed: %s\n"
-#define MSGTR_AO_SGI_SampleRateInfo "[AO SGI] init: samplerate is now %lf (desired rate is %lf)\n"
+#define MSGTR_AO_SGI_SampleRateInfo "[AO SGI] init: samplerate is now %f (desired rate is %f)\n"
 #define MSGTR_AO_SGI_InitConfigError "[AO SGI] init: %s\n"
 #define MSGTR_AO_SGI_InitOpenAudioFailed "[AO SGI] init: Unable to open audio channel: %s\n"
 #define MSGTR_AO_SGI_Uninit "[AO SGI] uninit: ...\n"
@@ -1229,31 +1285,6 @@ static const char help_text[]=
 #define MSGTR_AO_SUN_CantUseSelect "[AO SUN]\n   ***  Your audio driver DOES NOT support select()  ***\nRecompile MPlayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n"
 #define MSGTR_AO_SUN_CantReopenReset "[AO SUN]\nFatal error: *** CANNOT REOPEN / RESET AUDIO DEVICE (%s) ***\n"
 
-// ao_alsa5.c
-#define MSGTR_AO_ALSA5_InitInfo "[AO ALSA5] alsa-init: requested format: %d Hz, %d channels, %s\n"
-#define MSGTR_AO_ALSA5_SoundCardNotFound "[AO ALSA5] alsa-init: no soundcards found.\n"
-#define MSGTR_AO_ALSA5_InvalidFormatReq "[AO ALSA5] alsa-init: invalid format (%s) requested - output disabled.\n"
-#define MSGTR_AO_ALSA5_PlayBackError "[AO ALSA5] alsa-init: playback open error: %s\n"
-#define MSGTR_AO_ALSA5_PcmInfoError "[AO ALSA5] alsa-init: PCM info error: %s\n"
-#define MSGTR_AO_ALSA5_SoundcardsFound "[AO ALSA5] alsa-init: %d soundcard(s) found, using: %s\n"
-#define MSGTR_AO_ALSA5_PcmChanInfoError "[AO ALSA5] alsa-init: PCM channel info error: %s\n"
-#define MSGTR_AO_ALSA5_CantSetParms "[AO ALSA5] alsa-init: error setting parameters: %s\n"
-#define MSGTR_AO_ALSA5_CantSetChan "[AO ALSA5] alsa-init: error setting up channel: %s\n"
-#define MSGTR_AO_ALSA5_ChanPrepareError "[AO ALSA5] alsa-init: channel prepare error: %s\n"
-#define MSGTR_AO_ALSA5_DrainError "[AO ALSA5] alsa-uninit: playback drain error: %s\n"
-#define MSGTR_AO_ALSA5_FlushError "[AO ALSA5] alsa-uninit: playback flush error: %s\n"
-#define MSGTR_AO_ALSA5_PcmCloseError "[AO ALSA5] alsa-uninit: PCM close error: %s\n"
-#define MSGTR_AO_ALSA5_ResetDrainError "[AO ALSA5] alsa-reset: playback drain error: %s\n"
-#define MSGTR_AO_ALSA5_ResetFlushError "[AO ALSA5] alsa-reset: playback flush error: %s\n"
-#define MSGTR_AO_ALSA5_ResetChanPrepareError "[AO ALSA5] alsa-reset: channel prepare error: %s\n"
-#define MSGTR_AO_ALSA5_PauseDrainError "[AO ALSA5] alsa-pause: playback drain error: %s\n"
-#define MSGTR_AO_ALSA5_PauseFlushError "[AO ALSA5] alsa-pause: playback flush error: %s\n"
-#define MSGTR_AO_ALSA5_ResumePrepareError "[AO ALSA5] alsa-resume: channel prepare error: %s\n"
-#define MSGTR_AO_ALSA5_Underrun "[AO ALSA5] alsa-play: alsa underrun, resetting stream.\n"
-#define MSGTR_AO_ALSA5_PlaybackPrepareError "[AO ALSA5] alsa-play: playback prepare error: %s\n"
-#define MSGTR_AO_ALSA5_WriteErrorAfterReset "[AO ALSA5] alsa-play: write error after reset: %s - giving up.\n"
-#define MSGTR_AO_ALSA5_OutPutError "[AO ALSA5] alsa-play: output error: %s\n"
-
 // ao_alsa.c
 #define MSGTR_AO_ALSA_InvalidMixerIndexDefaultingToZero "[AO_ALSA] Invalid mixer index. Defaulting to 0.\n"
 #define MSGTR_AO_ALSA_MixerOpenError "[AO_ALSA] Mixer open error: %s\n"
@@ -1337,7 +1368,6 @@ static const char help_text[]=
 // ========================== INPUT =========================================
 
 // joystick.c
-#define MSGTR_INPUT_JOYSTICK_Opening "Opening joystick device %s\n"
 #define MSGTR_INPUT_JOYSTICK_CantOpen "Can't open joystick device %s: %s\n"
 #define MSGTR_INPUT_JOYSTICK_ErrReading "Error while reading joystick device: %s\n"
 #define MSGTR_INPUT_JOYSTICK_LoosingBytes "Joystick: We lose %d bytes of data\n"
@@ -1345,8 +1375,6 @@ static const char help_text[]=
 #define MSGTR_INPUT_JOYSTICK_WarnUnknownEvent "Joystick warning unknown event type %d\n"
 
 // appleir.c
-#define MSGTR_INPUT_APPLE_IR_Init "Initializing Apple IR on %s\n"
-#define MSGTR_INPUT_APPLE_IR_Detect "Detected Apple IR on %s\n"
 #define MSGTR_INPUT_APPLE_IR_CantOpen "Can't open Apple IR device: %s\n"
 
 // input.c
@@ -1373,12 +1401,10 @@ static const char help_text[]=
 #define MSGTR_INPUT_INPUT_ErrBuffer2SmallForCmd "Buffer is too small for command %s\n"
 #define MSGTR_INPUT_INPUT_ErrWhyHere "What are we doing here?\n"
 #define MSGTR_INPUT_INPUT_ErrCantInitJoystick "Can't init input joystick\n"
-#define MSGTR_INPUT_INPUT_ErrCantStatFile "Can't stat %s: %s\n"
 #define MSGTR_INPUT_INPUT_ErrCantOpenFile "Can't open %s: %s\n"
 #define MSGTR_INPUT_INPUT_ErrCantInitAppleRemote "Can't init Apple Remote.\n"
 
 // lirc.c
-#define MSGTR_SettingUpLIRC "Setting up LIRC support...\n"
 #define MSGTR_LIRCopenfailed "Failed to open LIRC support. You will not be able to use your remote control.\n"
 #define MSGTR_LIRCcfgerr "Failed to read LIRC config file %s.\n"
 
@@ -1393,7 +1419,6 @@ static const char help_text[]=
 #define MSGTR_WarningLenIsntDivisible "Warning, len isn't divisible by samplesize!\n"
 #define MSGTR_MuxbufMallocErr "Muxer frame buffer cannot allocate memory!\n"
 #define MSGTR_MuxbufReallocErr "Muxer frame buffer cannot reallocate memory!\n"
-#define MSGTR_MuxbufSending "Muxer frame buffer sending %d frame(s) to the muxer.\n"
 #define MSGTR_WritingHeader "Writing header...\n"
 #define MSGTR_WritingTrailer "Writing index...\n"
 
@@ -1411,7 +1436,6 @@ static const char help_text[]=
 #define MSGTR_ON2AviFormat "ON2 AVI format"
 #define MSGTR_Detected_XXX_FileFormat "%s file format detected.\n"
 #define MSGTR_DetectedAudiofile "Audio file detected.\n"
-#define MSGTR_NotSystemStream "Not MPEG System Stream format... (maybe Transport Stream?)\n"
 #define MSGTR_InvalidMPEGES "Invalid MPEG-ES stream??? Contact the author, it may be a bug :(\n"
 #define MSGTR_FormatNotRecognized "============ Sorry, this file format is not recognized/supported =============\n"\
                                   "=== If this file is an AVI, ASF or MPEG stream, please contact the author! ===\n"
@@ -1436,11 +1460,8 @@ static const char help_text[]=
 #define MSGTR_MOVcomprhdr "MOV: Compressed headers support requires ZLIB!\n"
 #define MSGTR_MOVvariableFourCC "MOV: WARNING: Variable FourCC detected!?\n"
 #define MSGTR_MOVtooManyTrk "MOV: WARNING: too many tracks"
-#define MSGTR_FoundAudioStream "==> Found audio stream: %d\n"
-#define MSGTR_FoundVideoStream "==> Found video stream: %d\n"
 #define MSGTR_DetectedTV "TV detected! ;-)\n"
 #define MSGTR_ErrorOpeningOGGDemuxer "Unable to open the Ogg demuxer.\n"
-#define MSGTR_ASFSearchingForAudioStream "ASF: Searching for audio stream (id:%d).\n"
 #define MSGTR_CannotOpenAudioStream "Cannot open audio stream: %s\n"
 #define MSGTR_CannotOpenSubtitlesStream "Cannot open subtitle stream: %s\n"
 #define MSGTR_OpeningAudioDemuxerFailed "Failed to open audio demuxer: %s\n"
@@ -1453,7 +1474,7 @@ static const char help_text[]=
 #define MSGTR_EnterTelecineMode "\ndemux_mpg: 24000/1001fps progressive NTSC content detected, switching framerate.\n"
 
 #define MSGTR_CacheFill "\rCache fill: %5.2f%% (%"PRId64" bytes)   "
-#define MSGTR_NoBindFound "No bind found for key '%s'."
+#define MSGTR_NoBindFound "No bind found for key '%s'.\n"
 #define MSGTR_FailedToOpen "Failed to open %s.\n"
 
 #define MSGTR_VideoID "[%s] Video stream found, -vid %d\n"
@@ -1473,17 +1494,7 @@ static const char help_text[]=
 
 // aviheader.c
 #define MSGTR_MPDEMUX_AVIHDR_EmptyList "** empty list?!\n"
-#define MSGTR_MPDEMUX_AVIHDR_FoundMovieAt "Found movie at 0x%X - 0x%X\n"
-#define MSGTR_MPDEMUX_AVIHDR_FoundBitmapInfoHeader "Found 'bih', %u bytes of %d\n"
-#define MSGTR_MPDEMUX_AVIHDR_RegeneratingKeyfTableForMPG4V1 "Regenerating keyframe table for M$ mpg4v1 video.\n"
-#define MSGTR_MPDEMUX_AVIHDR_RegeneratingKeyfTableForDIVX3 "Regenerating keyframe table for DIVX3 video.\n"
-#define MSGTR_MPDEMUX_AVIHDR_RegeneratingKeyfTableForMPEG4 "Regenerating keyframe table for MPEG-4 video.\n"
-#define MSGTR_MPDEMUX_AVIHDR_FoundWaveFmt "Found 'wf', %d bytes of %d\n"
-#define MSGTR_MPDEMUX_AVIHDR_FoundAVIV2Header "AVI: dmlh found (size=%d) (total_frames=%d)\n"
-#define MSGTR_MPDEMUX_AVIHDR_ReadingIndexBlockChunksForFrames "Reading INDEX block, %d chunks for %d frames (fpos=%"PRId64").\n"
-#define MSGTR_MPDEMUX_AVIHDR_AdditionalRIFFHdr "Additional RIFF header...\n"
 #define MSGTR_MPDEMUX_AVIHDR_WarnNotExtendedAVIHdr "** Warning: this is no extended AVI header..\n"
-#define MSGTR_MPDEMUX_AVIHDR_BrokenChunk "Broken chunk?  chunksize=%d  (id=%.4s)\n"
 #define MSGTR_MPDEMUX_AVIHDR_BuildingODMLidx "AVI: ODML: Building ODML index (%d superindexchunks).\n"
 #define MSGTR_MPDEMUX_AVIHDR_BrokenODMLfile "AVI: ODML: Broken (incomplete?) file detected. Will use traditional index.\n"
 #define MSGTR_MPDEMUX_AVIHDR_CantReadIdxFile "Can't read index file %s: %s\n"
@@ -1497,6 +1508,8 @@ static const char help_text[]=
 #define MSGTR_MPDEMUX_AVIHDR_IdxFileSaved "Saved index file: %s\n"
 
 // demux_audio.c
+#define MSGTR_MPDEMUX_AUDIO_BadID3v2TagSize "Audio demuxer: bad ID3v2 tag size: larger than stream (%u).\n"
+#define MSGTR_MPDEMUX_AUDIO_DamagedAppendedID3v2Tag "Audio demuxer: damaged appended ID3v2 tag detected.\n"
 #define MSGTR_MPDEMUX_AUDIO_UnknownFormat "Audio demuxer: unknown format %d.\n"
 
 // demux_demuxers.c
@@ -1615,21 +1628,15 @@ static const char help_text[]=
 
 #define MSGTR_UsingExternalPP "[PP] Using external postprocessing filter, max q = %d.\n"
 #define MSGTR_UsingCodecPP "[PP] Using codec's postprocessing, max q = %d.\n"
-#define MSGTR_VideoAttributeNotSupportedByVO_VD "Video attribute '%s' is not supported by selected vo & vd.\n"
 #define MSGTR_VideoCodecFamilyNotAvailableStr "Requested video codec family [%s] (vfm=%s) not available.\nEnable it at compilation.\n"
 #define MSGTR_AudioCodecFamilyNotAvailableStr "Requested audio codec family [%s] (afm=%s) not available.\nEnable it at compilation.\n"
 #define MSGTR_OpeningVideoDecoder "Opening video decoder: [%s] %s\n"
 #define MSGTR_SelectedVideoCodec "Selected video codec: [%s] vfm: %s (%s)\n"
 #define MSGTR_OpeningAudioDecoder "Opening audio decoder: [%s] %s\n"
 #define MSGTR_SelectedAudioCodec "Selected audio codec: [%s] afm: %s (%s)\n"
-#define MSGTR_BuildingAudioFilterChain "Building audio filter chain for %dHz/%dch/%s -> %dHz/%dch/%s...\n"
-#define MSGTR_UninitVideoStr "Uninit video: %s\n"
-#define MSGTR_UninitAudioStr "Uninit audio: %s\n"
 #define MSGTR_VDecoderInitFailed "VDecoder init failed :(\n"
 #define MSGTR_ADecoderInitFailed "ADecoder init failed :(\n"
 #define MSGTR_ADecoderPreinitFailed "ADecoder preinit failed :(\n"
-#define MSGTR_AllocatingBytesForInputBuffer "dec_audio: Allocating %d bytes for input buffer.\n"
-#define MSGTR_AllocatingBytesForOutputBuffer "dec_audio: Allocating %d + %d = %d bytes for output buffer.\n"
 
 // ad_dvdpcm.c:
 #define MSGTR_SamplesWanted "Samples of this format are needed to improve support. Please contact the developers.\n"
@@ -1645,8 +1652,6 @@ static const char help_text[]=
 
 // vd_dshow.c, vd_dmo.c
 #define MSGTR_DownloadCodecPackage "You need to upgrade/install the binary codecs package.\nGo to http://www.mplayerhq.hu/dload.html\n"
-#define MSGTR_DShowInitOK "INFO: Win32/DShow video codec init OK.\n"
-#define MSGTR_DMOInitOK "INFO: Win32/DMO video codec init OK.\n"
 
 // libmpcodecs/vd_dmo.c vd_dshow.c vd_vfw.c
 #define MSGTR_MPCODECS_CouldntAllocateImageForCinepakCodec "[VD_DMO] Couldn't allocate image for cinepak codec.\n"
@@ -1774,12 +1779,12 @@ static const char help_text[]=
 
 // ================================== stream ====================================
 
-// ai_alsa1x.c
-#define MSGTR_MPDEMUX_AIALSA1X_CannotSetSamplerate "Cannot set samplerate.\n"
-#define MSGTR_MPDEMUX_AIALSA1X_CannotSetBufferTime "Cannot set buffer time.\n"
-#define MSGTR_MPDEMUX_AIALSA1X_CannotSetPeriodTime "Cannot set period time.\n"
+// ai_alsa.c
+#define MSGTR_MPDEMUX_AIALSA_CannotSetSamplerate "Cannot set samplerate.\n"
+#define MSGTR_MPDEMUX_AIALSA_CannotSetBufferTime "Cannot set buffer time.\n"
+#define MSGTR_MPDEMUX_AIALSA_CannotSetPeriodTime "Cannot set period time.\n"
 
-// ai_alsa1x.c / ai_alsa.c
+// ai_alsa.c
 #define MSGTR_MPDEMUX_AIALSA_PcmBrokenConfig "Broken configuration for this PCM: no configurations available.\n"
 #define MSGTR_MPDEMUX_AIALSA_UnavailableAccessType "Access type not available.\n"
 #define MSGTR_MPDEMUX_AIALSA_UnavailableSampleFmt "Sample format not available.\n"
@@ -1790,7 +1795,6 @@ static const char help_text[]=
 #define MSGTR_MPDEMUX_AIALSA_ErrorOpeningAudio "Error opening audio: %s\n"
 #define MSGTR_MPDEMUX_AIALSA_AlsaStatusError "ALSA status error: %s"
 #define MSGTR_MPDEMUX_AIALSA_AlsaXRUN "ALSA xrun!!! (at least %.3f ms long)\n"
-#define MSGTR_MPDEMUX_AIALSA_AlsaStatus "ALSA Status:\n"
 #define MSGTR_MPDEMUX_AIALSA_AlsaXRUNPrepareError "ALSA xrun: prepare error: %s"
 #define MSGTR_MPDEMUX_AIALSA_AlsaReadWriteError "ALSA read/write error"
 
@@ -1850,7 +1854,7 @@ static const char help_text[]=
 #define MSGTR_MPDEMUX_ASF_UnknownASFStreamType "unknown ASF stream type\n"
 #define MSGTR_MPDEMUX_ASF_Failed2ParseHTTPResponse "Failed to parse HTTP response.\n"
 #define MSGTR_MPDEMUX_ASF_ServerReturn "Server returned %d:%s\n"
-#define MSGTR_MPDEMUX_ASF_ASFHTTPParseWarnCuttedPragma "ASF HTTP PARSE WARNING : Pragma %s cut from %zd bytes to %d\n"
+#define MSGTR_MPDEMUX_ASF_ASFHTTPParseWarnCuttedPragma "ASF HTTP PARSE WARNING : Pragma %s cut from %zu bytes to %zu\n"
 #define MSGTR_MPDEMUX_ASF_SocketWriteError "socket write error: %s\n"
 #define MSGTR_MPDEMUX_ASF_HeaderParseFailed "Failed to parse header.\n"
 #define MSGTR_MPDEMUX_ASF_NoStreamFound "No stream found.\n"
@@ -1907,6 +1911,17 @@ static const char help_text[]=
 #define MSGTR_CantOpenBluray "Couldn't open Blu-ray device: %s\n"
 #define MSGTR_CantOpenDVD "Couldn't open DVD device: %s (%s)\n"
 
+#define MSGTR_URLParsingFailed "URL parsing failed on url %s\n"
+#define MSGTR_FailedSetStreamOption "Failed to set stream option %s=%s\n"
+#define MSGTR_StreamNeedType "Streams need a type!\n"
+#define MSGTR_StreamProtocolNULL "Stream type %s has protocols == NULL, it's a bug\n"
+#define MSGTR_StreamCantHandleURL "No stream found to handle url %s\n"
+#define MSGTR_StreamNULLFilename "open_output_stream(), NULL filename, report this bug\n"
+#define MSGTR_StreamErrorWritingCapture "Error writing capture file: %s\n"
+#define MSGTR_StreamSeekFailed "Seek failed\n"
+#define MSGTR_StreamNotSeekable "Stream not seekable!\n"
+#define MSGTR_StreamCannotSeekBackward "Cannot seek backward in linear streams!\n"
+
 // stream_cdda.c
 #define MSGTR_MPDEMUX_CDDA_CantOpenCDDADevice "Can't open CDDA device.\n"
 #define MSGTR_MPDEMUX_CDDA_CantOpenDisc "Can't open disc.\n"
@@ -1979,21 +1994,16 @@ static const char help_text[]=
 // stream_bluray.c
 #define MSGTR_BlurayNoDevice "No Blu-ray device/location was specified ...\n"
 #define MSGTR_BlurayNoTitles "Can't find any Blu-ray-compatible title here.\n"
-#define MSGTR_BlurayOK "Blu-ray successfully opened.\n"
 
 // stream_radio.c
 #define MSGTR_RADIO_ChannelNamesDetected "[radio] Radio channel names detected.\n"
-#define MSGTR_RADIO_FreqRange "[radio] Allowed frequency range is %.2f-%.2f MHz.\n"
 #define MSGTR_RADIO_WrongFreqForChannel "[radio] Wrong frequency for channel %s\n"
 #define MSGTR_RADIO_WrongChannelNumberFloat "[radio] Wrong channel number: %.2f\n"
 #define MSGTR_RADIO_WrongChannelNumberInt "[radio] Wrong channel number: %d\n"
 #define MSGTR_RADIO_WrongChannelName "[radio] Wrong channel name: %s\n"
 #define MSGTR_RADIO_FreqParameterDetected "[radio] Radio frequency parameter detected.\n"
-#define MSGTR_RADIO_DoneParsingChannels "[radio] Done parsing channels.\n"
 #define MSGTR_RADIO_GetTunerFailed "[radio] Warning: ioctl get tuner failed: %s. Setting frac to %d.\n"
 #define MSGTR_RADIO_NotRadioDevice "[radio] %s is no radio device!\n"
-#define MSGTR_RADIO_TunerCapLowYes "[radio] tuner is low:yes frac=%d\n"
-#define MSGTR_RADIO_TunerCapLowNo "[radio] tuner is low:no frac=%d\n"
 #define MSGTR_RADIO_SetFreqFailed "[radio] ioctl set frequency 0x%x (%.2f) failed: %s\n"
 #define MSGTR_RADIO_GetFreqFailed "[radio] ioctl get frequency failed: %s\n"
 #define MSGTR_RADIO_SetMuteFailed "[radio] ioctl set mute failed: %s\n"
@@ -2003,27 +2013,22 @@ static const char help_text[]=
 #define MSGTR_RADIO_DroppingFrame "\n[radio] too bad - dropping audio frame (%d bytes)!\n"
 #define MSGTR_RADIO_BufferEmpty "[radio] grab_audio_frame: buffer empty, waiting for %d data bytes.\n"
 #define MSGTR_RADIO_AudioInitFailed "[radio] audio_in_init failed: %s\n"
-#define MSGTR_RADIO_AudioBuffer "[radio] Audio capture - buffer=%d bytes (block=%d bytes).\n"
 #define MSGTR_RADIO_AllocateBufferFailed "[radio] cannot allocate audio buffer (block=%d,buf=%d): %s\n"
 #define MSGTR_RADIO_CurrentFreq "[radio] Current frequency: %.2f\n"
 #define MSGTR_RADIO_SelectedChannel "[radio] Selected channel: %d - %s (freq: %.2f)\n"
 #define MSGTR_RADIO_ChangeChannelNoChannelList "[radio] Can not change channel: no channel list given.\n"
 #define MSGTR_RADIO_UnableOpenDevice "[radio] Unable to open '%s': %s\n"
-#define MSGTR_RADIO_RadioDevice "[radio] Radio fd: %d, %s\n"
 #define MSGTR_RADIO_InitFracFailed "[radio] init_frac failed.\n"
 #define MSGTR_RADIO_WrongFreq "[radio] Wrong frequency: %.2f\n"
 #define MSGTR_RADIO_UsingFreq "[radio] Using frequency: %.2f.\n"
 #define MSGTR_RADIO_AudioInInitFailed "[radio] audio_in_init failed.\n"
-#define MSGTR_RADIO_BufferString "[radio] %s: in buffer=%d dropped=%d\n"
 #define MSGTR_RADIO_AudioInSetupFailed "[radio] audio_in_setup call failed: %s\n"
-#define MSGTR_RADIO_CaptureStarting "[radio] Starting capture stuff.\n"
 #define MSGTR_RADIO_ClearBufferFailed "[radio] Clearing buffer failed: %s\n"
 #define MSGTR_RADIO_StreamEnableCacheFailed "[radio] Call to stream_enable_cache failed: %s\n"
 #define MSGTR_RADIO_DriverUnknownStr "[radio] Unknown driver name: %s\n"
 #define MSGTR_RADIO_DriverV4L2 "[radio] Using V4Lv2 radio interface.\n"
 #define MSGTR_RADIO_DriverV4L "[radio] Using V4Lv1 radio interface.\n"
 #define MSGTR_RADIO_DriverBSDBT848 "[radio] Using *BSD BT848 radio interface.\n"
-#define MSGTR_RADIO_AvailableDrivers "[radio] Available drivers: "
 
 //tv.c
 #define MSGTR_TV_BogusNormParameter "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n"
@@ -2035,30 +2040,23 @@ static const char help_text[]=
 " be ignored! You should try again with YV12 (which is the default\n"\
 " colorspace) and read the documentation!\n"\
 "==================================================================\n"
-#define MSGTR_TV_SelectedNormId "Selected norm id: %d\n"
-#define MSGTR_TV_SelectedNorm "Selected norm : %s\n"
 #define MSGTR_TV_CannotSetNorm "Error: Cannot set norm!\n"
 #define MSGTR_TV_MJP_WidthHeight "  MJP: width %d height %d\n"
 #define MSGTR_TV_UnableToSetWidth "Unable to set requested width: %d\n"
 #define MSGTR_TV_UnableToSetHeight "Unable to set requested height: %d\n"
 #define MSGTR_TV_NoTuner "Selected input hasn't got a tuner!\n"
 #define MSGTR_TV_UnableFindChanlist "Unable to find selected channel list! (%s)\n"
-#define MSGTR_TV_SelectedChanlist "Selected channel list: %s (including %d channels)\n"
 #define MSGTR_TV_ChannelFreqParamConflict "You can't set frequency and channel simultaneously!\n"
 #define MSGTR_TV_ChannelNamesDetected "TV channel names detected.\n"
 #define MSGTR_TV_NoFreqForChannel "Couldn't find frequency for channel %s (%s)\n"
 #define MSGTR_TV_SelectedChannel3 "Selected channel: %s - %s (freq: %.3f)\n"
 #define MSGTR_TV_SelectedChannel2 "Selected channel: %s (freq: %.3f)\n"
-#define MSGTR_TV_SelectedFrequency "Selected frequency: %lu (%.3f)\n"
-#define MSGTR_TV_RequestedChannel "Requested channel: %s\n"
 #define MSGTR_TV_UnsupportedAudioType "Audio type '%s (%x)' unsupported!\n"
-#define MSGTR_TV_AudioFormat "  TV audio: %d channels, %d bits, %d Hz\n"
 #define MSGTR_TV_AvailableDrivers "Available drivers:\n"
 #define MSGTR_TV_DriverInfo "Selected driver: %s\n name: %s\n author: %s\n comment: %s\n"
 #define MSGTR_TV_NoSuchDriver "No such driver: %s\n"
 #define MSGTR_TV_DriverAutoDetectionFailed "TV driver autodetection failed.\n"
 #define MSGTR_TV_UnknownColorOption "Unknown color option (%d) specified!\n"
-#define MSGTR_TV_CurrentFrequency "Current frequency: %lu (%.3f)\n"
 #define MSGTR_TV_NoTeletext "No teletext"
 #define MSGTR_TV_Bt848IoctlFailed "tvi_bsdbt848: Call to %s ioctl failed. Error: %s\n"
 #define MSGTR_TV_Bt848InvalidAudioRate "tvi_bsdbt848: Invalid audio rate. Error: %s\n"
@@ -2086,14 +2084,7 @@ static const char help_text[]=
 #define MSGTR_TVI_DS_DeviceNotFound "tvi_dshow: Device #%d not found\n"
 #define MSGTR_TVI_DS_UnableGetDeviceName "tvi_dshow: Unable to get name for device #%d\n"
 #define MSGTR_TVI_DS_UsingDevice "tvi_dshow: Using device #%d: %s\n"
-#define MSGTR_TVI_DS_DeviceName  "tvi_dshow: Device #%d: %s\n"
 #define MSGTR_TVI_DS_DirectGetFreqFailed "tvi_dshow: Unable to get frequency directly. OS built-in channels table will be used.\n"
-#define MSGTR_TVI_DS_DirectSetFreqFailed "tvi_dshow: Unable to set frequency directly. OS built-in channels table will be used.\n"
-#define MSGTR_TVI_DS_SupportedNorms "tvi_dshow: supported norms:"
-#define MSGTR_TVI_DS_AvailableVideoInputs "tvi_dshow: available video inputs:"
-#define MSGTR_TVI_DS_AvailableAudioInputs "tvi_dshow: available audio inputs:"
-//following phrase will be printed near the selected audio/video input
-#define MSGTR_TVI_DS_InputSelected "(selected)"
 #define MSGTR_TVI_DS_UnableExtractFreqTable "tvi_dshow: Unable to load frequency table from kstvtune.ax\n"
 #define MSGTR_TVI_DS_WrongDeviceParam "tvi_dshow: Wrong device parameter: %s\n"
 #define MSGTR_TVI_DS_WrongDeviceIndex "tvi_dshow: Wrong device index: %d\n"
@@ -2105,7 +2096,6 @@ static const char help_text[]=
 
 #define MSGTR_TVI_DS_ChangingWidthHeightNotSupported "tvi_dshow: Changing video width/height is not supported by device.\n"
 #define MSGTR_TVI_DS_SelectingInputNotSupported  "tvi_dshow: Selection of capture source is not supported by device\n"
-#define MSGTR_TVI_DS_FreqTableLoaded "tvi_dshow: loaded system (%s) frequency table for country id=%d (channels:%d).\n"
 #define MSGTR_TVI_DS_ErrorParsingAudioFormatStruct "tvi_dshow: Unable to parse audio format structure.\n"
 #define MSGTR_TVI_DS_ErrorParsingVideoFormatStruct "tvi_dshow: Unable to parse video format structure.\n"
 #define MSGTR_TVI_DS_UnableSetAudioMode "tvi_dshow: Unable to set audio mode %d. Error:0x%x\n"
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/img_format.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/img_format.c
index 380f3b03288..61bf8988016 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/img_format.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/img_format.c
@@ -19,53 +19,88 @@
 #include "config.h"
 #include "img_format.h"
 #include "stdio.h"
+#include "libavutil/bswap.h"
 
 const char *ff_vo_format_name(int format)
 {
     static char unknown_format[20];
     switch(format)
     {
-    case IMGFMT_RGB1: return "RGB 1-bit";
-    case IMGFMT_RGB4: return "RGB 4-bit";
-    case IMGFMT_RG4B: return "RGB 4-bit per byte";
-    case IMGFMT_RGB8: return "RGB 8-bit";
-    case IMGFMT_RGB12: return "RGB 12-bit";
-    case IMGFMT_RGB15: return "RGB 15-bit";
-    case IMGFMT_RGB16: return "RGB 16-bit";
-    case IMGFMT_RGB24: return "RGB 24-bit";
-//  case IMGFMT_RGB32: return "RGB 32-bit";
+    case IMGFMT_RGB1:    return "RGB 1-bit";
+    case IMGFMT_RGB4:    return "RGB 4-bit";
+    case IMGFMT_RG4B:    return "RGB 4-bit per byte";
+    case IMGFMT_RGB8:    return "RGB 8-bit";
+    case IMGFMT_RGB12:   return "RGB 12-bit";
+    case IMGFMT_RGB15:   return "RGB 15-bit";
+    case IMGFMT_RGB16:   return "RGB 16-bit";
+    case IMGFMT_RGB24:   return "RGB 24-bit";
+//  case IMGFMT_RGB32:   return "RGB 32-bit";
     case IMGFMT_RGB48LE: return "RGB 48-bit LE";
     case IMGFMT_RGB48BE: return "RGB 48-bit BE";
-    case IMGFMT_BGR1: return "BGR 1-bit";
-    case IMGFMT_BGR4: return "BGR 4-bit";
-    case IMGFMT_BG4B: return "BGR 4-bit per byte";
-    case IMGFMT_BGR8: return "BGR 8-bit";
-    case IMGFMT_BGR12: return "BGR 12-bit";
-    case IMGFMT_BGR15: return "BGR 15-bit";
-    case IMGFMT_BGR16: return "BGR 16-bit";
-    case IMGFMT_BGR24: return "BGR 24-bit";
-//  case IMGFMT_BGR32: return "BGR 32-bit";
-    case IMGFMT_ABGR: return "ABGR";
-    case IMGFMT_BGRA: return "BGRA";
-    case IMGFMT_ARGB: return "ARGB";
-    case IMGFMT_RGBA: return "RGBA";
-    case IMGFMT_YVU9: return "Planar YVU9";
-    case IMGFMT_IF09: return "Planar IF09";
-    case IMGFMT_YV12: return "Planar YV12";
-    case IMGFMT_I420: return "Planar I420";
-    case IMGFMT_IYUV: return "Planar IYUV";
-    case IMGFMT_CLPL: return "Planar CLPL";
-    case IMGFMT_Y800: return "Planar Y800";
-    case IMGFMT_Y8: return "Planar Y8";
+    case IMGFMT_RGB64LE: return "RGB 64-bit LE";
+    case IMGFMT_RGB64BE: return "RGB 64-bit BE";
+    case IMGFMT_BGR1:    return "BGR 1-bit";
+    case IMGFMT_BGR4:    return "BGR 4-bit";
+    case IMGFMT_BG4B:    return "BGR 4-bit per byte";
+    case IMGFMT_BGR8:    return "BGR 8-bit";
+    case IMGFMT_BGR12:   return "BGR 12-bit";
+    case IMGFMT_BGR15:   return "BGR 15-bit";
+    case IMGFMT_BGR16:   return "BGR 16-bit";
+    case IMGFMT_BGR24:   return "BGR 24-bit";
+//  case IMGFMT_BGR32:   return "BGR 32-bit";
+    case IMGFMT_ABGR:    return "ABGR";
+    case IMGFMT_BGRA:    return "BGRA";
+    case IMGFMT_ARGB:    return "ARGB";
+    case IMGFMT_RGBA:    return "RGBA";
+    case IMGFMT_GBR24P:  return "Planar GBR 24-bit";
+    case IMGFMT_GBR12P:  return "Planar GBR 36-bit";
+    case IMGFMT_GBR14P:  return "Planar GBR 42-bit";
+    case IMGFMT_YVU9:    return "Planar YVU9";
+    case IMGFMT_IF09:    return "Planar IF09";
+    case IMGFMT_YV12:    return "Planar YV12";
+    case IMGFMT_I420:    return "Planar I420";
+    case IMGFMT_IYUV:    return "Planar IYUV";
+    case IMGFMT_CLPL:    return "Planar CLPL";
+    case IMGFMT_Y800:    return "Planar Y800";
+    case IMGFMT_Y8:      return "Planar Y8";
+    case IMGFMT_Y8A:     return "Planar Y8 with alpha";
+    case IMGFMT_Y16_LE:  return "Planar Y16 little-endian";
+    case IMGFMT_Y16_BE:  return "Planar Y16 big-endian";
     case IMGFMT_420P16_LE: return "Planar 420P 16-bit little-endian";
     case IMGFMT_420P16_BE: return "Planar 420P 16-bit big-endian";
+    case IMGFMT_420P14_LE: return "Planar 420P 14-bit little-endian";
+    case IMGFMT_420P14_BE: return "Planar 420P 14-bit big-endian";
+    case IMGFMT_420P12_LE: return "Planar 420P 12-bit little-endian";
+    case IMGFMT_420P12_BE: return "Planar 420P 12-bit big-endian";
+    case IMGFMT_420P10_LE: return "Planar 420P 10-bit little-endian";
+    case IMGFMT_420P10_BE: return "Planar 420P 10-bit big-endian";
+    case IMGFMT_420P9_LE:  return "Planar 420P 9-bit little-endian";
+    case IMGFMT_420P9_BE:  return "Planar 420P 9-bit big-endian";
     case IMGFMT_422P16_LE: return "Planar 422P 16-bit little-endian";
     case IMGFMT_422P16_BE: return "Planar 422P 16-bit big-endian";
+    case IMGFMT_422P14_LE: return "Planar 422P 14-bit little-endian";
+    case IMGFMT_422P14_BE: return "Planar 422P 14-bit big-endian";
+    case IMGFMT_422P12_LE: return "Planar 422P 12-bit little-endian";
+    case IMGFMT_422P12_BE: return "Planar 422P 12-bit big-endian";
+    case IMGFMT_422P10_LE: return "Planar 422P 10-bit little-endian";
+    case IMGFMT_422P10_BE: return "Planar 422P 10-bit big-endian";
+    case IMGFMT_422P9_LE:  return "Planar 422P 9-bit little-endian";
+    case IMGFMT_422P9_BE:  return "Planar 422P 9-bit big-endian";
     case IMGFMT_444P16_LE: return "Planar 444P 16-bit little-endian";
     case IMGFMT_444P16_BE: return "Planar 444P 16-bit big-endian";
+    case IMGFMT_444P14_LE: return "Planar 444P 14-bit little-endian";
+    case IMGFMT_444P14_BE: return "Planar 444P 14-bit big-endian";
+    case IMGFMT_444P12_LE: return "Planar 444P 12-bit little-endian";
+    case IMGFMT_444P12_BE: return "Planar 444P 12-bit big-endian";
+    case IMGFMT_444P10_LE: return "Planar 444P 10-bit little-endian";
+    case IMGFMT_444P10_BE: return "Planar 444P 10-bit big-endian";
+    case IMGFMT_444P9_LE:  return "Planar 444P 9-bit little-endian";
+    case IMGFMT_444P9_BE:  return "Planar 444P 9-bit big-endian";
     case IMGFMT_420A: return "Planar 420P with alpha";
     case IMGFMT_444P: return "Planar 444P";
+    case IMGFMT_444A: return "Planar 444P with alpha";
     case IMGFMT_422P: return "Planar 422P";
+    case IMGFMT_422A: return "Planar 422P with alpha";
     case IMGFMT_411P: return "Planar 411P";
     case IMGFMT_NV12: return "Planar NV12";
     case IMGFMT_NV21: return "Planar NV21";
@@ -90,33 +125,82 @@ const char *ff_vo_format_name(int format)
     case IMGFMT_CLJR: return "Packed CLJR";
     case IMGFMT_YUVP: return "Packed YUVP";
     case IMGFMT_UYVP: return "Packed UYVP";
-    case IMGFMT_MPEGPES: return "Mpeg PES";
-    case IMGFMT_ZRMJPEGNI: return "Zoran MJPEG non-interlaced";
-    case IMGFMT_ZRMJPEGIT: return "Zoran MJPEG top field first";
-    case IMGFMT_ZRMJPEGIB: return "Zoran MJPEG bottom field first";
+    case IMGFMT_MPEGPES:         return "Mpeg PES";
+    case IMGFMT_ZRMJPEGNI:       return "Zoran MJPEG non-interlaced";
+    case IMGFMT_ZRMJPEGIT:       return "Zoran MJPEG top field first";
+    case IMGFMT_ZRMJPEGIB:       return "Zoran MJPEG bottom field first";
     case IMGFMT_XVMC_MOCO_MPEG2: return "MPEG1/2 Motion Compensation";
     case IMGFMT_XVMC_IDCT_MPEG2: return "MPEG1/2 Motion Compensation and IDCT";
-    case IMGFMT_VDPAU_MPEG1: return "MPEG1 VDPAU acceleration";
-    case IMGFMT_VDPAU_MPEG2: return "MPEG2 VDPAU acceleration";
-    case IMGFMT_VDPAU_H264: return "H.264 VDPAU acceleration";
-    case IMGFMT_VDPAU_MPEG4: return "MPEG-4 Part 2 VDPAU acceleration";
-    case IMGFMT_VDPAU_WMV3: return "WMV3 VDPAU acceleration";
-    case IMGFMT_VDPAU_VC1: return "VC1 VDPAU acceleration";
+    case IMGFMT_VDPAU_MPEG1:     return "MPEG1 VDPAU acceleration";
+    case IMGFMT_VDPAU_MPEG2:     return "MPEG2 VDPAU acceleration";
+    case IMGFMT_VDPAU_H264:      return "H.264 VDPAU acceleration";
+    case IMGFMT_VDPAU_MPEG4:     return "MPEG-4 Part 2 VDPAU acceleration";
+    case IMGFMT_VDPAU_WMV3:      return "WMV3 VDPAU acceleration";
+    case IMGFMT_VDPAU_VC1:       return "VC1 VDPAU acceleration";
     }
     snprintf(unknown_format,20,"Unknown 0x%04x",format);
     return unknown_format;
 }
 
-int ff_mp_get_chroma_shift(int format, int *x_shift, int *y_shift)
+int ff_mp_get_chroma_shift(int format, int *x_shift, int *y_shift, int *component_bits)
 {
     int xs = 0, ys = 0;
     int bpp;
-    int bpp_factor = 1;
     int err = 0;
-    switch (format) {
-    case IMGFMT_420P16_LE:
-    case IMGFMT_420P16_BE:
-        bpp_factor = 2;
+    int bits = 8;
+    if ((format & 0xff0000f0) == 0x34000050)
+        format = av_bswap32(format);
+    if ((format & 0xf00000ff) == 0x50000034) {
+        switch (format >> 24) {
+        case 0x50:
+            break;
+        case 0x51:
+            bits = 16;
+            break;
+        case 0x52:
+            bits = 10;
+            break;
+        case 0x53:
+            bits = 9;
+            break;
+        default:
+            err = 1;
+            break;
+        }
+        switch (format & 0x00ffffff) {
+        case 0x00343434: // 444
+            xs = 0;
+            ys = 0;
+            break;
+        case 0x00323234: // 422
+            xs = 1;
+            ys = 0;
+            break;
+        case 0x00303234: // 420
+            xs = 1;
+            ys = 1;
+            break;
+        case 0x00313134: // 411
+            xs = 2;
+            ys = 0;
+            break;
+        case 0x00303434: // 440
+            xs = 0;
+            ys = 1;
+            break;
+        default:
+            err = 1;
+            break;
+        }
+    } else switch (format) {
+    case IMGFMT_444A:
+        xs = 0;
+        ys = 0;
+        break;
+    case IMGFMT_422A:
+        xs = 1;
+        ys = 0;
+        break;
     case IMGFMT_420A:
     case IMGFMT_I420:
     case IMGFMT_IYUV:
@@ -129,28 +213,6 @@ int ff_mp_get_chroma_shift(int format, int *x_shift, int *y_shift)
         xs = 2;
         ys = 2;
         break;
-    case IMGFMT_444P16_LE:
-    case IMGFMT_444P16_BE:
-        bpp_factor = 2;
-    case IMGFMT_444P:
-        xs = 0;
-        ys = 0;
-        break;
-    case IMGFMT_422P16_LE:
-    case IMGFMT_422P16_BE:
-        bpp_factor = 2;
-    case IMGFMT_422P:
-        xs = 1;
-        ys = 0;
-        break;
-    case IMGFMT_411P:
-        xs = 2;
-        ys = 0;
-        break;
-    case IMGFMT_440P:
-        xs = 0;
-        ys = 1;
-        break;
     case IMGFMT_Y8:
     case IMGFMT_Y800:
         xs = 31;
@@ -162,9 +224,10 @@ int ff_mp_get_chroma_shift(int format, int *x_shift, int *y_shift)
     }
     if (x_shift) *x_shift = xs;
     if (y_shift) *y_shift = ys;
+    if (component_bits) *component_bits = bits;
     bpp = 8 + ((16 >> xs) >> ys);
-    if (format == IMGFMT_420A)
+    if (format == IMGFMT_420A || format == IMGFMT_422A || format == IMGFMT_444A)
         bpp += 8;
-    bpp *= bpp_factor;
+    bpp *= (bits + 7) >> 3;
     return err ? 0 : bpp;
 }
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/img_format.h b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/img_format.h
index 6f972b560df..d4d64d8d35a 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/img_format.h
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/img_format.h
@@ -36,55 +36,69 @@
 #define IMGFMT_RGB32 (IMGFMT_RGB|32)
 #define IMGFMT_RGB48LE (IMGFMT_RGB|48)
 #define IMGFMT_RGB48BE (IMGFMT_RGB|48|128)
+#define IMGFMT_RGB64LE (IMGFMT_RGB|64)
+#define IMGFMT_RGB64BE (IMGFMT_RGB|64|128)
 
 #define IMGFMT_BGR_MASK 0xFFFFFF00
 #define IMGFMT_BGR (('B'<<24)|('G'<<16)|('R'<<8))
-#define IMGFMT_BGR1 (IMGFMT_BGR|1)
-#define IMGFMT_BGR4 (IMGFMT_BGR|4)
+#define IMGFMT_BGR1  (IMGFMT_BGR|1)
+#define IMGFMT_BGR4  (IMGFMT_BGR|4)
 #define IMGFMT_BGR4_CHAR (IMGFMT_BGR|4|128) // BGR4 with 1 pixel per byte
-#define IMGFMT_BGR8 (IMGFMT_BGR|8)
+#define IMGFMT_BGR8  (IMGFMT_BGR|8)
 #define IMGFMT_BGR12 (IMGFMT_BGR|12)
 #define IMGFMT_BGR15 (IMGFMT_BGR|15)
 #define IMGFMT_BGR16 (IMGFMT_BGR|16)
 #define IMGFMT_BGR24 (IMGFMT_BGR|24)
 #define IMGFMT_BGR32 (IMGFMT_BGR|32)
 
+#define IMGFMT_GBR24P (('G'<<24)|('B'<<16)|('R'<<8)|24)
+#define IMGFMT_GBR12PLE (('G'<<24)|('B'<<16)|('R'<<8)|36)
+#define IMGFMT_GBR12PBE (('G'<<24)|('B'<<16)|('R'<<8)|36|128)
+#define IMGFMT_GBR14PLE (('G'<<24)|('B'<<16)|('R'<<8)|42)
+#define IMGFMT_GBR14PBE (('G'<<24)|('B'<<16)|('R'<<8)|42|128)
+
 #if HAVE_BIGENDIAN
-#define IMGFMT_ABGR IMGFMT_RGB32
-#define IMGFMT_BGRA (IMGFMT_RGB32|64)
-#define IMGFMT_ARGB IMGFMT_BGR32
-#define IMGFMT_RGBA (IMGFMT_BGR32|64)
+#define IMGFMT_ABGR    IMGFMT_RGB32
+#define IMGFMT_BGRA    (IMGFMT_RGB32|128)
+#define IMGFMT_ARGB    IMGFMT_BGR32
+#define IMGFMT_RGBA    (IMGFMT_BGR32|128)
+#define IMGFMT_RGB64NE IMGFMT_RGB64BE
 #define IMGFMT_RGB48NE IMGFMT_RGB48BE
 #define IMGFMT_RGB12BE IMGFMT_RGB12
-#define IMGFMT_RGB12LE (IMGFMT_RGB12|64)
+#define IMGFMT_RGB12LE (IMGFMT_RGB12|128)
 #define IMGFMT_RGB15BE IMGFMT_RGB15
-#define IMGFMT_RGB15LE (IMGFMT_RGB15|64)
+#define IMGFMT_RGB15LE (IMGFMT_RGB15|128)
 #define IMGFMT_RGB16BE IMGFMT_RGB16
-#define IMGFMT_RGB16LE (IMGFMT_RGB16|64)
+#define IMGFMT_RGB16LE (IMGFMT_RGB16|128)
 #define IMGFMT_BGR12BE IMGFMT_BGR12
-#define IMGFMT_BGR12LE (IMGFMT_BGR12|64)
+#define IMGFMT_BGR12LE (IMGFMT_BGR12|128)
 #define IMGFMT_BGR15BE IMGFMT_BGR15
-#define IMGFMT_BGR15LE (IMGFMT_BGR15|64)
+#define IMGFMT_BGR15LE (IMGFMT_BGR15|128)
 #define IMGFMT_BGR16BE IMGFMT_BGR16
-#define IMGFMT_BGR16LE (IMGFMT_BGR16|64)
+#define IMGFMT_BGR16LE (IMGFMT_BGR16|128)
+#define IMGFMT_GBR12P IMGFMT_GBR12PBE
+#define IMGFMT_GBR14P IMGFMT_GBR14PBE
 #else
-#define IMGFMT_ABGR (IMGFMT_BGR32|64)
+#define IMGFMT_ABGR (IMGFMT_BGR32|128)
 #define IMGFMT_BGRA IMGFMT_BGR32
-#define IMGFMT_ARGB (IMGFMT_RGB32|64)
+#define IMGFMT_ARGB (IMGFMT_RGB32|128)
 #define IMGFMT_RGBA IMGFMT_RGB32
+#define IMGFMT_RGB64NE IMGFMT_RGB64LE
 #define IMGFMT_RGB48NE IMGFMT_RGB48LE
-#define IMGFMT_RGB12BE (IMGFMT_RGB12|64)
+#define IMGFMT_RGB12BE (IMGFMT_RGB12|128)
 #define IMGFMT_RGB12LE IMGFMT_RGB12
-#define IMGFMT_RGB15BE (IMGFMT_RGB15|64)
+#define IMGFMT_RGB15BE (IMGFMT_RGB15|128)
 #define IMGFMT_RGB15LE IMGFMT_RGB15
-#define IMGFMT_RGB16BE (IMGFMT_RGB16|64)
+#define IMGFMT_RGB16BE (IMGFMT_RGB16|128)
 #define IMGFMT_RGB16LE IMGFMT_RGB16
-#define IMGFMT_BGR12BE (IMGFMT_BGR12|64)
+#define IMGFMT_BGR12BE (IMGFMT_BGR12|128)
 #define IMGFMT_BGR12LE IMGFMT_BGR12
-#define IMGFMT_BGR15BE (IMGFMT_BGR15|64)
+#define IMGFMT_BGR15BE (IMGFMT_BGR15|128)
 #define IMGFMT_BGR15LE IMGFMT_BGR15
-#define IMGFMT_BGR16BE (IMGFMT_BGR16|64)
+#define IMGFMT_BGR16BE (IMGFMT_BGR16|128)
 #define IMGFMT_BGR16LE IMGFMT_BGR16
+#define IMGFMT_GBR12P IMGFMT_GBR12PLE
+#define IMGFMT_GBR14P IMGFMT_GBR14PLE
 #endif
 
 /* old names for compatibility */
@@ -94,8 +108,8 @@
 #define IMGFMT_IS_RGB(fmt) (((fmt)&IMGFMT_RGB_MASK)==IMGFMT_RGB)
 #define IMGFMT_IS_BGR(fmt) (((fmt)&IMGFMT_BGR_MASK)==IMGFMT_BGR)
 
-#define IMGFMT_RGB_DEPTH(fmt) ((fmt)&0x3F)
-#define IMGFMT_BGR_DEPTH(fmt) ((fmt)&0x3F)
+#define IMGFMT_RGB_DEPTH(fmt) ((fmt)&0x7F)
+#define IMGFMT_BGR_DEPTH(fmt) ((fmt)&0x7F)
 
 
 /* Planar YUV Formats */
@@ -110,6 +124,7 @@
 #define IMGFMT_Y8   0x20203859
 #define IMGFMT_NV12 0x3231564E
 #define IMGFMT_NV21 0x3132564E
+#define IMGFMT_Y16_LE 0x20363159
 
 /* unofficial Planar Formats, FIXME if official 4CC exists */
 #define IMGFMT_444P 0x50343434
@@ -117,53 +132,123 @@
 #define IMGFMT_411P 0x50313134
 #define IMGFMT_440P 0x50303434
 #define IMGFMT_HM12 0x32314D48
+#define IMGFMT_Y16_BE 0x59313620
 
+// Gray with alpha
+#define IMGFMT_Y8A 0x59320008
 // 4:2:0 planar with alpha
 #define IMGFMT_420A 0x41303234
+// 4:2:2 planar with alpha
+#define IMGFMT_422A 0x41323234
+// 4:4:4 planar with alpha
+#define IMGFMT_444A 0x41343434
 
 #define IMGFMT_444P16_LE 0x51343434
 #define IMGFMT_444P16_BE 0x34343451
+#define IMGFMT_444P14_LE 0x54343434
+#define IMGFMT_444P14_BE 0x34343454
+#define IMGFMT_444P12_LE 0x55343434
+#define IMGFMT_444P12_BE 0x34343455
+#define IMGFMT_444P10_LE 0x52343434
+#define IMGFMT_444P10_BE 0x34343452
+#define IMGFMT_444P9_LE  0x53343434
+#define IMGFMT_444P9_BE  0x34343453
 #define IMGFMT_422P16_LE 0x51323234
 #define IMGFMT_422P16_BE 0x34323251
+#define IMGFMT_422P14_LE 0x54323234
+#define IMGFMT_422P14_BE 0x34323254
+#define IMGFMT_422P12_LE 0x55323234
+#define IMGFMT_422P12_BE 0x34323255
+#define IMGFMT_422P10_LE 0x52323234
+#define IMGFMT_422P10_BE 0x34323252
+#define IMGFMT_422P9_LE  0x53323234
+#define IMGFMT_422P9_BE  0x34323253
 #define IMGFMT_420P16_LE 0x51303234
 #define IMGFMT_420P16_BE 0x34323051
+#define IMGFMT_420P14_LE 0x54303234
+#define IMGFMT_420P14_BE 0x34323054
+#define IMGFMT_420P12_LE 0x55303234
+#define IMGFMT_420P12_BE 0x34323055
+#define IMGFMT_420P10_LE 0x52303234
+#define IMGFMT_420P10_BE 0x34323052
+#define IMGFMT_420P9_LE  0x53303234
+#define IMGFMT_420P9_BE  0x34323053
 #if HAVE_BIGENDIAN
 #define IMGFMT_444P16 IMGFMT_444P16_BE
+#define IMGFMT_444P14 IMGFMT_444P14_BE
+#define IMGFMT_444P12 IMGFMT_444P12_BE
+#define IMGFMT_444P10 IMGFMT_444P10_BE
+#define IMGFMT_444P9  IMGFMT_444P9_BE
 #define IMGFMT_422P16 IMGFMT_422P16_BE
+#define IMGFMT_422P14 IMGFMT_422P14_BE
+#define IMGFMT_422P12 IMGFMT_422P12_BE
+#define IMGFMT_422P10 IMGFMT_422P10_BE
+#define IMGFMT_422P9  IMGFMT_422P9_BE
 #define IMGFMT_420P16 IMGFMT_420P16_BE
+#define IMGFMT_420P14 IMGFMT_420P14_BE
+#define IMGFMT_420P12 IMGFMT_420P12_BE
+#define IMGFMT_420P10 IMGFMT_420P10_BE
+#define IMGFMT_420P9  IMGFMT_420P9_BE
+#define IMGFMT_Y16    IMGFMT_Y16_BE
+#define IMGFMT_IS_YUVP16_NE(fmt) IMGFMT_IS_YUVP16_BE(fmt)
 #else
 #define IMGFMT_444P16 IMGFMT_444P16_LE
+#define IMGFMT_444P14 IMGFMT_444P14_LE
+#define IMGFMT_444P12 IMGFMT_444P12_LE
+#define IMGFMT_444P10 IMGFMT_444P10_LE
+#define IMGFMT_444P9  IMGFMT_444P9_LE
 #define IMGFMT_422P16 IMGFMT_422P16_LE
+#define IMGFMT_422P14 IMGFMT_422P14_LE
+#define IMGFMT_422P12 IMGFMT_422P12_LE
+#define IMGFMT_422P10 IMGFMT_422P10_LE
+#define IMGFMT_422P9  IMGFMT_422P9_LE
 #define IMGFMT_420P16 IMGFMT_420P16_LE
+#define IMGFMT_420P14 IMGFMT_420P14_LE
+#define IMGFMT_420P12 IMGFMT_420P12_LE
+#define IMGFMT_420P10 IMGFMT_420P10_LE
+#define IMGFMT_420P9  IMGFMT_420P9_LE
+#define IMGFMT_Y16    IMGFMT_Y16_LE
+#define IMGFMT_IS_YUVP16_NE(fmt) IMGFMT_IS_YUVP16_LE(fmt)
 #endif
 
-#define IMGFMT_IS_YUVP16_LE(fmt) (((fmt  ^ IMGFMT_420P16_LE) & 0xff0000ff) == 0)
-#define IMGFMT_IS_YUVP16_BE(fmt) (((fmt  ^ IMGFMT_420P16_BE) & 0xff0000ff) == 0)
-#define IMGFMT_IS_YUVP16_NE(fmt) (((fmt  ^ IMGFMT_420P16   ) & 0xff0000ff) == 0)
+#define IMGFMT_IS_YUVP16_LE(fmt) (((fmt - 0x51000034) & 0xfc0000ff) == 0)
+#define IMGFMT_IS_YUVP16_BE(fmt) (((fmt - 0x34000051) & 0xff0000fc) == 0)
 #define IMGFMT_IS_YUVP16(fmt)    (IMGFMT_IS_YUVP16_LE(fmt) || IMGFMT_IS_YUVP16_BE(fmt))
 
+/**
+ * \brief Find the corresponding full 16 bit format, i.e. IMGFMT_420P10_LE -> IMGFMT_420P16_LE
+ * \return normalized format ID or 0 if none exists.
+ */
+static inline int normalize_yuvp16(int fmt) {
+    if (IMGFMT_IS_YUVP16_LE(fmt))
+        return (fmt & 0x00ffffff) | 0x51000000;
+    if (IMGFMT_IS_YUVP16_BE(fmt))
+        return (fmt & 0xffffff00) | 0x00000051;
+    return 0;
+}
+
 /* Packed YUV Formats */
 
-#define IMGFMT_IUYV 0x56595549
-#define IMGFMT_IY41 0x31435949
+#define IMGFMT_IUYV 0x56595549 // Interlaced UYVY
+#define IMGFMT_IY41 0x31435949 // Interlaced Y41P
 #define IMGFMT_IYU1 0x31555949
 #define IMGFMT_IYU2 0x32555949
 #define IMGFMT_UYVY 0x59565955
-#define IMGFMT_UYNV 0x564E5955
-#define IMGFMT_cyuv 0x76757963
-#define IMGFMT_Y422 0x32323459
+#define IMGFMT_UYNV 0x564E5955 // Exactly same as UYVY
+#define IMGFMT_cyuv 0x76757963 // upside-down UYVY
+#define IMGFMT_Y422 0x32323459 // Exactly same as UYVY
 #define IMGFMT_YUY2 0x32595559
-#define IMGFMT_YUNV 0x564E5559
+#define IMGFMT_YUNV 0x564E5559 // Exactly same as YUY2
 #define IMGFMT_YVYU 0x55595659
 #define IMGFMT_Y41P 0x50313459
 #define IMGFMT_Y211 0x31313259
-#define IMGFMT_Y41T 0x54313459
-#define IMGFMT_Y42T 0x54323459
-#define IMGFMT_V422 0x32323456
+#define IMGFMT_Y41T 0x54313459 // Y41P, Y lsb = transparency
+#define IMGFMT_Y42T 0x54323459 // UYVY, Y lsb = transparency
+#define IMGFMT_V422 0x32323456 // upside-down UYVY?
 #define IMGFMT_V655 0x35353656
 #define IMGFMT_CLJR 0x524A4C43
-#define IMGFMT_YUVP 0x50565559
-#define IMGFMT_UYVP 0x50565955
+#define IMGFMT_YUVP 0x50565559 // 10-bit YUYV
+#define IMGFMT_UYVP 0x50565955 // 10-bit UYVY
 
 /* Compressed Formats */
 #define IMGFMT_MPEGPES (('M'<<24)|('P'<<16)|('E'<<8)|('S'))
@@ -207,8 +292,9 @@ const char *ff_vo_format_name(int format);
 /**
  * Calculates the scale shifts for the chroma planes for planar YUV
  *
+ * \param component_bits bits per component
  * \return bits-per-pixel for format if successful (i.e. format is 3 or 4-planes planar YUV), 0 otherwise
  */
-int ff_mp_get_chroma_shift(int format, int *x_shift, int *y_shift);
+int ff_mp_get_chroma_shift(int format, int *x_shift, int *y_shift, int *component_bits);
 
 #endif /* MPLAYER_IMG_FORMAT_H */
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/mp_image.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/mp_image.c
index dbc1d62eb74..100ace92cac 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/mp_image.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/mp_image.c
@@ -128,11 +128,24 @@ void ff_mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt){
         mpi->flags|=MP_IMGFLAG_SWAPPED;
         return;
     }
-    mpi->flags|=MP_IMGFLAG_YUV;
     mpi->num_planes=3;
-    if (ff_mp_get_chroma_shift(out_fmt, NULL, NULL)) {
+    if (out_fmt == IMGFMT_GBR24P) {
+        mpi->bpp=24;
+        mpi->flags|=MP_IMGFLAG_PLANAR;
+        return;
+    } else if (out_fmt == IMGFMT_GBR12P) {
+        mpi->bpp=36;
+        mpi->flags|=MP_IMGFLAG_PLANAR;
+        return;
+    } else if (out_fmt == IMGFMT_GBR14P) {
+        mpi->bpp=42;
+        mpi->flags|=MP_IMGFLAG_PLANAR;
+        return;
+    }
+    mpi->flags|=MP_IMGFLAG_YUV;
+    if (ff_mp_get_chroma_shift(out_fmt, NULL, NULL, NULL)) {
         mpi->flags|=MP_IMGFLAG_PLANAR;
-        mpi->bpp = ff_mp_get_chroma_shift(out_fmt, &mpi->chroma_x_shift, &mpi->chroma_y_shift);
+        mpi->bpp = ff_mp_get_chroma_shift(out_fmt, &mpi->chroma_x_shift, &mpi->chroma_y_shift, NULL);
         mpi->chroma_width  = mpi->width  >> mpi->chroma_x_shift;
         mpi->chroma_height = mpi->height >> mpi->chroma_y_shift;
     }
@@ -143,6 +156,8 @@ void ff_mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt){
     case IMGFMT_YV12:
         return;
     case IMGFMT_420A:
+    case IMGFMT_422A:
+    case IMGFMT_444A:
     case IMGFMT_IF09:
         mpi->num_planes=4;
     case IMGFMT_YVU9:
@@ -152,20 +167,51 @@ void ff_mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt){
     case IMGFMT_440P:
     case IMGFMT_444P16_LE:
     case IMGFMT_444P16_BE:
+    case IMGFMT_444P14_LE:
+    case IMGFMT_444P14_BE:
+    case IMGFMT_444P12_LE:
+    case IMGFMT_444P12_BE:
+    case IMGFMT_444P10_LE:
+    case IMGFMT_444P10_BE:
+    case IMGFMT_444P9_LE:
+    case IMGFMT_444P9_BE:
     case IMGFMT_422P16_LE:
     case IMGFMT_422P16_BE:
+    case IMGFMT_422P14_LE:
+    case IMGFMT_422P14_BE:
+    case IMGFMT_422P12_LE:
+    case IMGFMT_422P12_BE:
+    case IMGFMT_422P10_LE:
+    case IMGFMT_422P10_BE:
+    case IMGFMT_422P9_LE:
+    case IMGFMT_422P9_BE:
     case IMGFMT_420P16_LE:
     case IMGFMT_420P16_BE:
+    case IMGFMT_420P14_LE:
+    case IMGFMT_420P14_BE:
+    case IMGFMT_420P12_LE:
+    case IMGFMT_420P12_BE:
+    case IMGFMT_420P10_LE:
+    case IMGFMT_420P10_BE:
+    case IMGFMT_420P9_LE:
+    case IMGFMT_420P9_BE:
         return;
+    case IMGFMT_Y16_LE:
+    case IMGFMT_Y16_BE:
+        mpi->bpp=16;
     case IMGFMT_Y800:
     case IMGFMT_Y8:
         /* they're planar ones, but for easier handling use them as packed */
         mpi->flags&=~MP_IMGFLAG_PLANAR;
         mpi->num_planes=1;
         return;
+    case IMGFMT_Y8A:
+        mpi->num_planes=2;
+        return;
     case IMGFMT_UYVY:
         mpi->flags|=MP_IMGFLAG_SWAPPED;
     case IMGFMT_YUY2:
+        mpi->chroma_x_shift = 1;
         mpi->bpp=16;
         mpi->num_planes=1;
         return;
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/mp_image.h b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/mp_image.h
index c33703b77e7..aedf4510cdd 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/mp_image.h
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/mp_image.h
@@ -44,7 +44,14 @@ enum AVPixelFormat ff_mp2ff_pix_fmt(int mp);
 //--- buffer content restrictions:
 // set if buffer content shouldn't be modified:
 #define MP_IMGFLAG_PRESERVE 0x01
-// set if buffer content will be READ for next frame's MC: (I/P mpeg frames)
+// set if buffer content will be READ.
+// This can be e.g. for next frame's MC: (I/P mpeg frames) -
+// then in combination with MP_IMGFLAG_PRESERVE - or it
+// can be because a video filter or codec will read a significant
+// amount of data while processing that frame (e.g. blending something
+// onto the frame, MV based intra prediction).
+// A frame marked like this should not be placed in to uncachable
+// video RAM for example.
 #define MP_IMGFLAG_READABLE 0x02
 
 //--- buffer width/stride/plane restrictions: (used for direct rendering)
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/mp_msg.h b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/mp_msg.h
index 250bfb27523..51cdff3cef0 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/mp_msg.h
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/mp_msg.h
@@ -148,14 +148,16 @@ void ff_mp_msg(int mod, int lev, const char *format, ... ) __attribute__ ((forma
 #   ifdef MP_DEBUG
 #      define mp_dbg(mod,lev, args... ) ff_mp_msg(mod, lev, ## args )
 #   else
-#      define mp_dbg(mod,lev, args... ) /* only useful for developers */
+       // only useful for developers, disable but check syntax
+#      define mp_dbg(mod,lev, args... ) do { if (0) ff_mp_msg(mod, lev, ## args ); } while (0)
 #   endif
 #else // not GNU C
 void ff_mp_msg(int mod, int lev, const char *format, ... );
 #   ifdef MP_DEBUG
 #      define mp_dbg(mod,lev, ... ) ff_mp_msg(mod, lev, __VA_ARGS__)
 #   else
-#      define mp_dbg(mod,lev, ... ) /* only useful for developers */
+       // only useful for developers, disable but check syntax
+#      define mp_dbg(mod,lev, ... ) do { if (0) ff_mp_msg(mod, lev, __VA_ARGS__); } while (0)
 #   endif
 #endif /* __GNUC__ */
 
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/pullup.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/pullup.c
index a28b8cfc275..b5fae9ba614 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/pullup.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/pullup.c
@@ -19,9 +19,10 @@
 #include 
 #include 
 #include 
+
+#include "libavutil/x86/asm.h"
 #include "config.h"
 #include "pullup.h"
-#include "cpudetect.h"
 
 
 
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_divtc.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_divtc.c
index 0e023f3fcfb..61f6e35f097 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_divtc.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_divtc.c
@@ -26,6 +26,7 @@
 #include "mp_msg.h"
 #include "cpudetect.h"
 #include "libavutil/common.h"
+#include "libavutil/x86/asm.h"
 #include "mpbswap.h"
 
 #include "img_format.h"
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_dsize.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_dsize.c
deleted file mode 100644
index 21e0bf84dfa..00000000000
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_dsize.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include 
-#include 
-#include 
-#include 
-
-#include "config.h"
-#include "mp_msg.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-struct vf_priv_s {
-    int w, h;
-    int method; // aspect method, 0 -> downscale, 1-> upscale. +2 -> original aspect.
-    int round;
-    float aspect;
-};
-
-static int config(struct vf_instance *vf,
-    int width, int height, int d_width, int d_height,
-    unsigned int flags, unsigned int outfmt)
-{
-    if (vf->priv->aspect < 0.001) { // did the user input aspect or w,h params
-        if (vf->priv->w == 0) vf->priv->w = d_width;
-        if (vf->priv->h == 0) vf->priv->h = d_height;
-        if (vf->priv->w == -1) vf->priv->w = width;
-        if (vf->priv->h == -1) vf->priv->h = height;
-        if (vf->priv->w == -2) vf->priv->w = vf->priv->h * (double)d_width / d_height;
-        if (vf->priv->w == -3) vf->priv->w = vf->priv->h * (double)width / height;
-        if (vf->priv->h == -2) vf->priv->h = vf->priv->w * (double)d_height / d_width;
-        if (vf->priv->h == -3) vf->priv->h = vf->priv->w * (double)height / width;
-        if (vf->priv->method > -1) {
-            double aspect = (vf->priv->method & 2) ? ((double)height / width) : ((double)d_height / d_width);
-            if ((vf->priv->h > vf->priv->w * aspect) ^ (vf->priv->method & 1)) {
-                vf->priv->h = vf->priv->w * aspect;
-            } else {
-                vf->priv->w = vf->priv->h / aspect;
-            }
-        }
-        if (vf->priv->round > 1) { // round up
-            vf->priv->w += (vf->priv->round - 1 - (vf->priv->w - 1) % vf->priv->round);
-            vf->priv->h += (vf->priv->round - 1 - (vf->priv->h - 1) % vf->priv->round);
-        }
-        d_width = vf->priv->w;
-        d_height = vf->priv->h;
-    } else {
-        if (vf->priv->aspect * height > width) {
-            d_width = height * vf->priv->aspect + .5;
-            d_height = height;
-        } else {
-            d_height = width / vf->priv->aspect + .5;
-            d_width = width;
-        }
-    }
-    return ff_vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
-}
-
-static void uninit(vf_instance_t *vf) {
-    free(vf->priv);
-    vf->priv = NULL;
-}
-
-static int vf_open(vf_instance_t *vf, char *args)
-{
-    vf->config = config;
-    vf->draw_slice = ff_vf_next_draw_slice;
-    vf->uninit = uninit;
-    //vf->default_caps = 0;
-    vf->priv = calloc(sizeof(struct vf_priv_s), 1);
-    vf->priv->aspect = 0.;
-    vf->priv->w = -1;
-    vf->priv->h = -1;
-    vf->priv->method = -1;
-    vf->priv->round = 1;
-    if (args) {
-        if (strchr(args, '/')) {
-            int w, h;
-            sscanf(args, "%d/%d", &w, &h);
-            vf->priv->aspect = (float)w/h;
-        } else if (strchr(args, '.')) {
-            sscanf(args, "%f", &vf->priv->aspect);
-        } else {
-            sscanf(args, "%d:%d:%d:%d", &vf->priv->w, &vf->priv->h, &vf->priv->method, &vf->priv->round);
-        }
-    }
-    if ((vf->priv->aspect < 0.) || (vf->priv->w < -3) || (vf->priv->h < -3) ||
-            ((vf->priv->w < -1) && (vf->priv->h < -1)) ||
-            (vf->priv->method < -1) || (vf->priv->method > 3) ||
-            (vf->priv->round < 0)) {
-        ff_mp_msg(MSGT_VFILTER, MSGL_ERR, "[dsize] Illegal value(s): aspect: %f w: %d h: %d aspect_method: %d round: %d\n", vf->priv->aspect, vf->priv->w, vf->priv->h, vf->priv->method, vf->priv->round);
-        free(vf->priv); vf->priv = NULL;
-        return -1;
-    }
-    return 1;
-}
-
-const vf_info_t ff_vf_info_dsize = {
-    "reset displaysize/aspect",
-    "dsize",
-    "Rich Felker",
-    "",
-    vf_open,
-    NULL
-};
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_filmdint.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_filmdint.c
index db31f426e9d..93354e2ec0f 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_filmdint.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_filmdint.c
@@ -30,7 +30,7 @@
 #include "vd.h"
 #include "vf.h"
 #include "cmmx.h"
-
+#include "libavutil/x86/asm.h"
 #include "libvo/fastmemcpy.h"
 
 #define NUM_STORED 4
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_fspp.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_fspp.c
index 6f806b21c70..a8a33e2644b 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_fspp.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_fspp.c
@@ -45,12 +45,13 @@
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 #include "libvo/fastmemcpy.h"
 
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mem.h"
+#include "libavutil/x86/asm.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/dsputil.h"
 
@@ -164,10 +165,10 @@ static void mul_thrmat_c(struct vf_priv_s *p,int q)
         ((short*)p->threshold_mtx)[a]=q * ((short*)p->threshold_mtx_noq)[a];//ints faster in C
 }
 
-static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt);
-static void row_idct_c(DCTELEM* workspace,
+static void column_fidct_c(int16_t* thr_adr, int16_t *data, int16_t *output, int cnt);
+static void row_idct_c(int16_t* workspace,
                        int16_t* output_adr, int output_stride, int cnt);
-static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt);
+static void row_fdct_c(int16_t *data, const uint8_t *pixels, int line_size, int cnt);
 
 //this is rather ugly, but there is no need for function pointers
 #define store_slice_s store_slice_c
@@ -393,10 +394,10 @@ static void mul_thrmat_mmx(struct vf_priv_s *p, int q)
         );
 }
 
-static void column_fidct_mmx(int16_t* thr_adr,  DCTELEM *data,  DCTELEM *output,  int cnt);
-static void row_idct_mmx(DCTELEM* workspace,
+static void column_fidct_mmx(int16_t* thr_adr,  int16_t *data,  int16_t *output,  int cnt);
+static void row_idct_mmx(int16_t* workspace,
                          int16_t* output_adr,  int output_stride,  int cnt);
-static void row_fdct_mmx(DCTELEM *data,  const uint8_t *pixels,  int line_size,  int cnt);
+static void row_fdct_mmx(int16_t *data,  const uint8_t *pixels,  int line_size,  int cnt);
 
 #define store_slice_s store_slice_mmx
 #define store_slice2_s store_slice2_mmx
@@ -416,8 +417,8 @@ static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src,
     const int step=6-p->log2_count;
     const int qps= 3 + is_luma;
     int32_t __attribute__((aligned(32))) block_align[4*8*BLOCKSZ+ 4*8*BLOCKSZ];
-    DCTELEM *block= (DCTELEM *)block_align;
-    DCTELEM *block3=(DCTELEM *)(block_align+4*8*BLOCKSZ);
+    int16_t *block= (int16_t *)block_align;
+    int16_t *block3=(int16_t *)(block_align+4*8*BLOCKSZ);
 
     memset(block3, 0, 4*8*BLOCKSZ);
 
@@ -460,8 +461,8 @@ static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src,
                     column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+x*8, block3+x*8, 8); //yes, this is a HOTSPOT
                 }
             row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, 2*(BLOCKSZ-1));
-            memmove(block, block+(BLOCKSZ-1)*64, 8*8*sizeof(DCTELEM)); //cycling
-            memmove(block3, block3+(BLOCKSZ-1)*64, 6*8*sizeof(DCTELEM));
+            memmove(block, block+(BLOCKSZ-1)*64, 8*8*sizeof(int16_t)); //cycling
+            memmove(block3, block3+(BLOCKSZ-1)*64, 6*8*sizeof(int16_t));
         }
         //
         es=width+8-x0; //  8, ...
@@ -694,7 +695,7 @@ const vf_info_t ff_vf_info_fspp = {
 
 //#define MANGLE(a) #a
 
-//typedef int16_t DCTELEM; //! only int16_t
+//typedef int16_t int16_t; //! only int16_t
 
 #define DCTSIZE 8
 #define DCTSIZE_S "8"
@@ -745,15 +746,15 @@ static const int16_t FIX_1_082392200=FIX(1.082392200, 13);
 
 #if !HAVE_MMX
 
-static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
+static void column_fidct_c(int16_t* thr_adr, int16_t *data, int16_t *output, int cnt)
 {
     int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
     int_simd16_t tmp10, tmp11, tmp12, tmp13;
     int_simd16_t z1,z2,z3,z4,z5, z10, z11, z12, z13;
     int_simd16_t d0, d1, d2, d3, d4, d5, d6, d7;
 
-    DCTELEM* dataptr;
-    DCTELEM* wsptr;
+    int16_t* dataptr;
+    int16_t* wsptr;
     int16_t *threshold;
     int ctr;
 
@@ -870,7 +871,7 @@ static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int
 
 #else /* HAVE_MMX */
 
-static void column_fidct_mmx(int16_t* thr_adr,  DCTELEM *data,  DCTELEM *output,  int cnt)
+static void column_fidct_mmx(int16_t* thr_adr,  int16_t *data,  int16_t *output,  int cnt)
 {
     uint64_t __attribute__((aligned(8))) temps[4];
     __asm__ volatile(
@@ -1605,14 +1606,14 @@ static void column_fidct_mmx(int16_t* thr_adr,  DCTELEM *data,  DCTELEM *output,
 
 #if !HAVE_MMX
 
-static void row_idct_c(DCTELEM* workspace,
+static void row_idct_c(int16_t* workspace,
                        int16_t* output_adr, int output_stride, int cnt)
 {
     int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
     int_simd16_t tmp10, tmp11, tmp12, tmp13;
     int_simd16_t z5, z10, z11, z12, z13;
     int16_t* outptr;
-    DCTELEM* wsptr;
+    int16_t* wsptr;
 
     cnt*=4;
     wsptr = workspace;
@@ -1670,7 +1671,7 @@ static void row_idct_c(DCTELEM* workspace,
 
 #else /* HAVE_MMX */
 
-static void row_idct_mmx (DCTELEM* workspace,
+static void row_idct_mmx (int16_t* workspace,
                           int16_t* output_adr,  int output_stride,  int cnt)
 {
     uint64_t __attribute__((aligned(8))) temps[4];
@@ -1874,12 +1875,12 @@ static void row_idct_mmx (DCTELEM* workspace,
 
 #if !HAVE_MMX
 
-static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
+static void row_fdct_c(int16_t *data, const uint8_t *pixels, int line_size, int cnt)
 {
     int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
     int_simd16_t tmp10, tmp11, tmp12, tmp13;
     int_simd16_t z1, z2, z3, z4, z5, z11, z13;
-    DCTELEM *dataptr;
+    int16_t *dataptr;
 
     cnt*=4;
     // Pass 1: process rows.
@@ -1937,7 +1938,7 @@ static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int
 
 #else /* HAVE_MMX */
 
-static void row_fdct_mmx(DCTELEM *data,  const uint8_t *pixels,  int line_size,  int cnt)
+static void row_fdct_mmx(int16_t *data,  const uint8_t *pixels,  int line_size,  int cnt)
 {
     uint64_t __attribute__((aligned(8))) temps[4];
     __asm__ volatile(
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_il.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_il.c
deleted file mode 100644
index ee10d7b402c..00000000000
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_il.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (C) 2002 Michael Niedermayer 
- *
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "mp_msg.h"
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-#include "libvo/fastmemcpy.h"
-
-
-//===========================================================================//
-
-typedef struct FilterParam{
-    int interleave;
-    int swap;
-}FilterParam;
-
-struct vf_priv_s {
-    FilterParam lumaParam;
-    FilterParam chromaParam;
-};
-
-/***************************************************************************/
-
-static void interleave(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, int interleave, int swap){
-    const int a= swap;
-    const int b= 1-a;
-    const int m= h>>1;
-    int y;
-
-    switch(interleave){
-    case -1:
-        for(y=0; y < m; y++){
-            fast_memcpy(dst + dstStride* y     , src + srcStride*(y*2 + a), w);
-            fast_memcpy(dst + dstStride*(y + m), src + srcStride*(y*2 + b), w);
-        }
-        break;
-    case 0:
-        for(y=0; y < m; y++){
-            fast_memcpy(dst + dstStride* y*2   , src + srcStride*(y*2 + a), w);
-            fast_memcpy(dst + dstStride*(y*2+1), src + srcStride*(y*2 + b), w);
-        }
-        break;
-    case 1:
-        for(y=0; y < m; y++){
-            fast_memcpy(dst + dstStride*(y*2+a), src + srcStride* y     , w);
-            fast_memcpy(dst + dstStride*(y*2+b), src + srcStride*(y + m), w);
-        }
-        break;
-    }
-}
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
-    int w;
-    FilterParam *luma  = &vf->priv->lumaParam;
-    FilterParam *chroma= &vf->priv->chromaParam;
-
-    mp_image_t *dmpi=ff_vf_get_image(vf->next,mpi->imgfmt,
-        MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
-        mpi->w,mpi->h);
-
-    if(mpi->flags&MP_IMGFLAG_PLANAR)
-        w= mpi->w;
-    else
-        w= mpi->w * mpi->bpp/8;
-
-    interleave(dmpi->planes[0], mpi->planes[0],
-        w, mpi->h, dmpi->stride[0], mpi->stride[0], luma->interleave, luma->swap);
-
-    if(mpi->flags&MP_IMGFLAG_PLANAR){
-        int cw= mpi->w >> mpi->chroma_x_shift;
-        int ch= mpi->h >> mpi->chroma_y_shift;
-
-        interleave(dmpi->planes[1], mpi->planes[1], cw,ch,
-            dmpi->stride[1], mpi->stride[1], chroma->interleave, luma->swap);
-        interleave(dmpi->planes[2], mpi->planes[2], cw,ch,
-            dmpi->stride[2], mpi->stride[2], chroma->interleave, luma->swap);
-    }
-
-    return ff_vf_next_put_image(vf,dmpi, pts);
-}
-
-//===========================================================================//
-
-static void parse(FilterParam *fp, char* args){
-    char *pos;
-    char *max= strchr(args, ':');
-
-    if(!max) max= args + strlen(args);
-
-    pos= strchr(args, 's');
-    if(pos && posswap=1;
-    pos= strchr(args, 'i');
-    if(pos && posinterleave=1;
-    pos= strchr(args, 'd');
-    if(pos && posinterleave=-1;
-}
-
-static int vf_open(vf_instance_t *vf, char *args){
-
-    vf->put_image=put_image;
-//    vf->get_image=get_image;
-    vf->priv=malloc(sizeof(struct vf_priv_s));
-    memset(vf->priv, 0, sizeof(struct vf_priv_s));
-
-    if(args)
-    {
-        char *arg2= strchr(args,':');
-        if(arg2) parse(&vf->priv->chromaParam, arg2+1);
-        parse(&vf->priv->lumaParam, args);
-    }
-
-    return 1;
-}
-
-const vf_info_t ff_vf_info_il = {
-    "(de)interleave",
-    "il",
-    "Michael Niedermayer",
-    "",
-    vf_open,
-    NULL
-};
-
-//===========================================================================//
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_ilpack.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_ilpack.c
index 17d6ae44508..4db6c0a8b70 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_ilpack.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_ilpack.c
@@ -29,6 +29,7 @@
 #include "mp_image.h"
 #include "vf.h"
 #include "libavutil/attributes.h"
+#include "libavutil/x86/asm.h"
 
 typedef void (pack_func_t)(unsigned char *dst, unsigned char *y,
     unsigned char *u, unsigned char *v, int w, int us, int vs);
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_ivtc.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_ivtc.c
index 2418358a3bf..8a47a57748e 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_ivtc.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_ivtc.c
@@ -27,7 +27,7 @@
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
-
+#include "libavutil/x86/asm.h"
 #include "libvo/fastmemcpy.h"
 
 
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_kerndeint.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_kerndeint.c
deleted file mode 100644
index fca1ff17ad8..00000000000
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_kerndeint.c
+++ /dev/null
@@ -1,345 +0,0 @@
-/*
- * Original AVISynth Filter Copyright (C) 2003 Donald A. Graft
- *  Adapted to MPlayer by Tobias Diedrich
- *
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "mp_msg.h"
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-#include "libvo/fastmemcpy.h"
-
-//===========================================================================//
-
-struct vf_priv_s {
-    int    frame;
-    int    map;
-    int    order;
-    int    thresh;
-    int    sharp;
-    int    twoway;
-    int    do_deinterlace;
-};
-
-
-/***************************************************************************/
-
-
-static int config(struct vf_instance *vf,
-    int width, int height, int d_width, int d_height,
-    unsigned int flags, unsigned int outfmt){
-
-    return ff_vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
-}
-
-
-static void uninit(struct vf_instance *vf)
-{
-    free(vf->priv);
-}
-
-static inline int IsRGB(mp_image_t *mpi)
-{
-    return mpi->imgfmt == IMGFMT_RGB;
-}
-
-static inline int IsYUY2(mp_image_t *mpi)
-{
-    return mpi->imgfmt == IMGFMT_YUY2;
-}
-
-#define PLANAR_Y 0
-#define PLANAR_U 1
-#define PLANAR_V 2
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
-    int cw= mpi->w >> mpi->chroma_x_shift;
-    int ch= mpi->h >> mpi->chroma_y_shift;
-    int W = mpi->w, H = mpi->h;
-    const unsigned char *prvp, *prvpp, *prvpn, *prvpnn, *prvppp, *prvp4p, *prvp4n;
-    const unsigned char *srcp_saved;
-    const unsigned char *srcp, *srcpp, *srcpn, *srcpnn, *srcppp, *srcp3p, *srcp3n, *srcp4p, *srcp4n;
-    unsigned char *dstp, *dstp_saved;
-    int src_pitch;
-    int psrc_pitch;
-    int dst_pitch;
-    int x, y, z;
-    int n = vf->priv->frame++;
-    int val, hi, lo, w, h;
-    double valf;
-    int plane;
-    int threshold = vf->priv->thresh;
-    int order = vf->priv->order;
-    int map = vf->priv->map;
-    int sharp = vf->priv->sharp;
-    int twoway = vf->priv->twoway;
-    mp_image_t *dmpi, *pmpi;
-
-    if(!vf->priv->do_deinterlace)
-        return ff_vf_next_put_image(vf, mpi, pts);
-
-    dmpi=ff_vf_get_image(vf->next,mpi->imgfmt,
-        MP_IMGTYPE_IP, MP_IMGFLAG_ACCEPT_STRIDE,
-        mpi->w,mpi->h);
-    pmpi=ff_vf_get_image(vf->next,mpi->imgfmt,
-        MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
-        mpi->w,mpi->h);
-    if(!dmpi) return 0;
-
-    for (z=0; znum_planes; z++) {
-        if (z == 0) plane = PLANAR_Y;
-        else if (z == 1) plane = PLANAR_U;
-        else plane = PLANAR_V;
-
-        h = plane == PLANAR_Y ? H : ch;
-        w = plane == PLANAR_Y ? W : cw;
-
-        srcp = srcp_saved = mpi->planes[z];
-        src_pitch = mpi->stride[z];
-        psrc_pitch = pmpi->stride[z];
-        dstp = dstp_saved = dmpi->planes[z];
-        dst_pitch = dmpi->stride[z];
-        srcp = srcp_saved + (1-order) * src_pitch;
-        dstp = dstp_saved + (1-order) * dst_pitch;
-
-        for (y=0; yplanes[z] + 5*psrc_pitch - (1-order)*psrc_pitch;
-        prvpp = prvp - psrc_pitch;
-        prvppp = prvp - 2*psrc_pitch;
-        prvp4p = prvp - 4*psrc_pitch;
-        prvpn = prvp + psrc_pitch;
-        prvpnn = prvp + 2*psrc_pitch;
-        prvp4n = prvp + 4*psrc_pitch;
-        srcp = srcp_saved + 5*src_pitch - (1-order)*src_pitch;
-        srcpp = srcp - src_pitch;
-        srcppp = srcp - 2*src_pitch;
-        srcp3p = srcp - 3*src_pitch;
-        srcp4p = srcp - 4*src_pitch;
-        srcpn = srcp + src_pitch;
-        srcpnn = srcp + 2*src_pitch;
-        srcp3n = srcp + 3*src_pitch;
-        srcp4n = srcp + 4*src_pitch;
-        dstp =  dstp_saved  + 5*dst_pitch - (1-order)*dst_pitch;
-        for (y = 5 - (1-order); y <= h - 5 - (1-order); y+=2)
-        {
-            for (x = 0; x < w; x++)
-            {
-                if ((threshold == 0) || (n == 0) ||
-                    (abs((int)prvp[x] - (int)srcp[x]) > threshold) ||
-                    (abs((int)prvpp[x] - (int)srcpp[x]) > threshold) ||
-                    (abs((int)prvpn[x] - (int)srcpn[x]) > threshold))
-                {
-                    if (map == 1)
-                    {
-                        int g = x & ~3;
-                        if (IsRGB(mpi) == 1)
-                        {
-                            dstp[g++] = 255;
-                            dstp[g++] = 255;
-                            dstp[g++] = 255;
-                            dstp[g] = 255;
-                            x = g;
-                        }
-                        else if (IsYUY2(mpi) == 1)
-                        {
-                            dstp[g++] = 235;
-                            dstp[g++] = 128;
-                            dstp[g++] = 235;
-                            dstp[g] = 128;
-                            x = g;
-                        }
-                        else
-                        {
-                            if (plane == PLANAR_Y) dstp[x] = 235;
-                            else dstp[x] = 128;
-                        }
-                    }
-                    else
-                    {
-                        if (IsRGB(mpi))
-                        {
-                            hi = 255;
-                            lo = 0;
-                        }
-                        else if (IsYUY2(mpi))
-                        {
-                            hi = (x & 1) ? 240 : 235;
-                            lo = 16;
-                        }
-                        else
-                        {
-                            hi = (plane == PLANAR_Y) ? 235 : 240;
-                            lo = 16;
-                        }
-
-                        if (sharp == 1)
-                        {
-                            if (twoway == 1)
-                                valf = + 0.526*((int)srcpp[x] + (int)srcpn[x])
-                                   + 0.170*((int)srcp[x] + (int)prvp[x])
-                                   - 0.116*((int)srcppp[x] + (int)srcpnn[x] + (int)prvppp[x] + (int)prvpnn[x])
-                                   - 0.026*((int)srcp3p[x] + (int)srcp3n[x])
-                                   + 0.031*((int)srcp4p[x] + (int)srcp4n[x] + (int)prvp4p[x] + (int)prvp4n[x]);
-                            else
-                                valf = + 0.526*((int)srcpp[x] + (int)srcpn[x])
-                                   + 0.170*((int)prvp[x])
-                                   - 0.116*((int)prvppp[x] + (int)prvpnn[x])
-                                   - 0.026*((int)srcp3p[x] + (int)srcp3n[x])
-                                   + 0.031*((int)prvp4p[x] + (int)prvp4p[x]);
-                            if (valf > hi) valf = hi;
-                            else if (valf < lo) valf = lo;
-                            dstp[x] = (int) valf;
-                        }
-                        else
-                        {
-                            if (twoway == 1)
-                                val = (8*((int)srcpp[x] + (int)srcpn[x]) + 2*((int)srcp[x] + (int)prvp[x]) -
-                                    (int)(srcppp[x]) - (int)(srcpnn[x]) -
-                                    (int)(prvppp[x]) - (int)(prvpnn[x])) >> 4;
-                            else
-                                val = (8*((int)srcpp[x] + (int)srcpn[x]) + 2*((int)prvp[x]) -
-                                    (int)(prvppp[x]) - (int)(prvpnn[x])) >> 4;
-                            if (val > hi) val = hi;
-                            else if (val < lo) val = lo;
-                            dstp[x] = (int) val;
-                        }
-                    }
-                }
-                else
-                {
-                    dstp[x] = srcp[x];
-                }
-            }
-            prvp  += 2*psrc_pitch;
-            prvpp  += 2*psrc_pitch;
-            prvppp  += 2*psrc_pitch;
-            prvpn  += 2*psrc_pitch;
-            prvpnn  += 2*psrc_pitch;
-            prvp4p  += 2*psrc_pitch;
-            prvp4n  += 2*psrc_pitch;
-            srcp  += 2*src_pitch;
-            srcpp += 2*src_pitch;
-            srcppp += 2*src_pitch;
-            srcp3p += 2*src_pitch;
-            srcp4p += 2*src_pitch;
-            srcpn += 2*src_pitch;
-            srcpnn += 2*src_pitch;
-            srcp3n += 2*src_pitch;
-            srcp4n += 2*src_pitch;
-            dstp  += 2*dst_pitch;
-        }
-
-        srcp = mpi->planes[z];
-        dstp = pmpi->planes[z];
-        for (y=0; ypriv->do_deinterlace;
-        return CONTROL_OK;
-    case VFCTRL_SET_DEINTERLACE:
-        vf->priv->do_deinterlace = *(int*)data;
-        return CONTROL_OK;
-    }
-    return ff_vf_next_control (vf, request, data);
-}
-
-static int vf_open(vf_instance_t *vf, char *args){
-
-    vf->control=control;
-    vf->config=config;
-    vf->put_image=put_image;
-        vf->query_format=query_format;
-        vf->uninit=uninit;
-    vf->priv=malloc(sizeof(struct vf_priv_s));
-        memset(vf->priv, 0, sizeof(struct vf_priv_s));
-
-    vf->priv->frame = 0;
-
-    vf->priv->map = 0;
-    vf->priv->order = 0;
-    vf->priv->thresh = 10;
-    vf->priv->sharp = 0;
-    vf->priv->twoway = 0;
-    vf->priv->do_deinterlace=1;
-
-        if (args)
-        {
-            sscanf(args, "%d:%d:%d:%d:%d",
-        &vf->priv->thresh, &vf->priv->map,
-        &vf->priv->order, &vf->priv->sharp,
-        &vf->priv->twoway);
-        }
-    if (vf->priv->order > 1) vf->priv->order = 1;
-
-    return 1;
-}
-
-const vf_info_t ff_vf_info_kerndeint = {
-    "Kernel Deinterlacer",
-    "kerndeint",
-    "Donald Graft",
-    "",
-    vf_open,
-    NULL
-};
-
-//===========================================================================//
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_mcdeint.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_mcdeint.c
index 6ae255dde37..b9ffaf21cab 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_mcdeint.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_mcdeint.c
@@ -54,6 +54,7 @@ Known Issues:
 #include "mp_msg.h"
 #include "cpudetect.h"
 
+#include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavcodec/avcodec.h"
@@ -66,7 +67,7 @@ Known Issues:
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 
 #define MIN(a,b) ((a) > (b) ? (b) : (a))
 #define MAX(a,b) ((a) < (b) ? (b) : (a))
@@ -186,6 +187,7 @@ static int config(struct vf_instance *vf,
 
         for(i=0; i<3; i++){
             AVCodecContext *avctx_enc;
+            AVDictionary *opts = NULL;
 #if 0
             int is_chroma= !!i;
             int w= ((width  + 31) & (~31))>>is_chroma;
@@ -196,7 +198,7 @@ static int config(struct vf_instance *vf,
             vf->priv->src [i]= malloc(vf->priv->temp_stride[i]*h*sizeof(uint8_t));
 #endif
             avctx_enc=
-            vf->priv->avctx_enc= avcodec_alloc_context();
+            vf->priv->avctx_enc= avcodec_alloc_context3(enc);
             avctx_enc->width = width;
             avctx_enc->height = height;
             avctx_enc->time_base= (AVRational){1,25};  // meaningless
@@ -206,7 +208,7 @@ static int config(struct vf_instance *vf,
             avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY;
             avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
             avctx_enc->global_quality= 1;
-            avctx_enc->flags2= CODEC_FLAG2_MEMC_ONLY;
+            av_dict_set(&opts, "memc_only", "1", 0);
             avctx_enc->me_cmp=
             avctx_enc->me_sub_cmp= FF_CMP_SAD; //SSE;
             avctx_enc->mb_cmp= FF_CMP_SSE;
@@ -224,7 +226,8 @@ static int config(struct vf_instance *vf,
                 avctx_enc->flags |= CODEC_FLAG_QPEL;
             }
 
-            avcodec_open(avctx_enc, enc);
+            avcodec_open2(avctx_enc, enc, &opts);
+            av_dict_free(&opts);
 
         }
         vf->priv->frame= avcodec_alloc_frame();
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_noise.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_noise.c
index e141e6b022b..3b946e99bbc 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_noise.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_noise.c
@@ -37,6 +37,7 @@
 #include "vf.h"
 #include "libvo/fastmemcpy.h"
 #include "libavutil/mem.h"
+#include "libavutil/x86/asm.h"
 
 #define MAX_NOISE 4096
 #define MAX_SHIFT 1024
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_pp7.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_pp7.c
index 7f0e39d6ffa..30f95307bb1 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_pp7.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_pp7.c
@@ -44,8 +44,6 @@
 #define XMIN(a,b) ((a) < (b) ? (a) : (b))
 #define XMAX(a,b) ((a) > (b) ? (a) : (b))
 
-typedef short DCTELEM;
-
 //===========================================================================//
 static const uint8_t  __attribute__((aligned(8))) dither[8][8]={
 {  0,  48,  12,  60,   3,  51,  15,  63, },
@@ -66,7 +64,7 @@ struct vf_priv_s {
     uint8_t *src;
 };
 #if 0
-static inline void dct7_c(DCTELEM *dst, int s0, int s1, int s2, int s3, int step){
+static inline void dct7_c(int16_t *dst, int s0, int s1, int s2, int s3, int step){
     int s, d;
     int dst2[64];
 //#define S0 (1024/0.37796447300922719759)
@@ -113,7 +111,7 @@ static inline void dct7_c(DCTELEM *dst, int s0, int s1, int s2, int s3, int step
 }
 #endif
 
-static inline void dctA_c(DCTELEM *dst, uint8_t *src, int stride){
+static inline void dctA_c(int16_t *dst, uint8_t *src, int stride){
     int i;
 
     for(i=0; i<4; i++){
@@ -135,7 +133,7 @@ static inline void dctA_c(DCTELEM *dst, uint8_t *src, int stride){
     }
 }
 
-static void dctB_c(DCTELEM *dst, DCTELEM *src){
+static void dctB_c(int16_t *dst, int16_t *src){
     int i;
 
     for(i=0; i<4; i++){
@@ -158,7 +156,7 @@ static void dctB_c(DCTELEM *dst, DCTELEM *src){
 }
 
 #if HAVE_MMX
-static void dctB_mmx(DCTELEM *dst, DCTELEM *src){
+static void dctB_mmx(int16_t *dst, int16_t *src){
     __asm__ volatile (
         "movq  (%0), %%mm0      \n\t"
         "movq  1*4*2(%0), %%mm1 \n\t"
@@ -191,7 +189,7 @@ static void dctB_mmx(DCTELEM *dst, DCTELEM *src){
 }
 #endif
 
-static void (*dctB)(DCTELEM *dst, DCTELEM *src)= dctB_c;
+static void (*dctB)(int16_t *dst, int16_t *src)= dctB_c;
 
 #define N0 4
 #define N1 5
@@ -228,7 +226,7 @@ static void init_thres2(void){
     }
 }
 
-static int hardthresh_c(DCTELEM *src, int qp){
+static int hardthresh_c(int16_t *src, int qp){
     int i;
     int a;
 
@@ -244,7 +242,7 @@ static int hardthresh_c(DCTELEM *src, int qp){
     return (a + (1<<11))>>12;
 }
 
-static int mediumthresh_c(DCTELEM *src, int qp){
+static int mediumthresh_c(int16_t *src, int qp){
     int i;
     int a;
 
@@ -265,7 +263,7 @@ static int mediumthresh_c(DCTELEM *src, int qp){
     return (a + (1<<11))>>12;
 }
 
-static int softthresh_c(DCTELEM *src, int qp){
+static int softthresh_c(int16_t *src, int qp){
     int i;
     int a;
 
@@ -282,14 +280,14 @@ static int softthresh_c(DCTELEM *src, int qp){
     return (a + (1<<11))>>12;
 }
 
-static int (*requantize)(DCTELEM *src, int qp)= hardthresh_c;
+static int (*requantize)(int16_t *src, int qp)= hardthresh_c;
 
 static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, uint8_t *qp_store, int qp_stride, int is_luma){
     int x, y;
     const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15));
     uint8_t  *p_src= p->src + 8*stride;
-    DCTELEM *block= (DCTELEM *)p->src;
-    DCTELEM *temp= (DCTELEM *)(p->src + 32);
+    int16_t *block= (int16_t *)p->src;
+    int16_t *temp= (int16_t *)(p->src + 32);
 
     if (!src || !dst) return; // HACK avoid crash for Y8 colourspace
     for(y=0; y
-#include 
-#include 
-
-#include "config.h"
-#include "mp_msg.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-struct vf_priv_s {
-    int skipflag;
-};
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
-{
-    mp_image_t *dmpi;
-
-    if (vf->priv->skipflag)
-        return vf->priv->skipflag = 0;
-
-    dmpi = ff_vf_get_image(vf->next, mpi->imgfmt,
-        MP_IMGTYPE_EXPORT, 0, mpi->width, mpi->height);
-    ff_vf_clone_mpi_attributes(dmpi, mpi);
-
-    dmpi->planes[0] = mpi->planes[0];
-    dmpi->stride[0] = mpi->stride[0];
-    if (dmpi->flags&MP_IMGFLAG_PLANAR) {
-        dmpi->planes[1] = mpi->planes[1];
-        dmpi->stride[1] = mpi->stride[1];
-        dmpi->planes[2] = mpi->planes[2];
-        dmpi->stride[2] = mpi->stride[2];
-    }
-
-    return ff_vf_next_put_image(vf, dmpi, pts);
-}
-
-static int control(struct vf_instance *vf, int request, void* data)
-{
-    switch (request) {
-    case VFCTRL_SKIP_NEXT_FRAME:
-        vf->priv->skipflag = 1;
-        return CONTROL_TRUE;
-    }
-    return ff_vf_next_control(vf, request, data);
-}
-
-#if 0
-static int query_format(struct vf_instance *vf, unsigned int fmt)
-{
-    /* FIXME - figure out which other formats work */
-    switch (fmt) {
-    case IMGFMT_YV12:
-    case IMGFMT_IYUV:
-    case IMGFMT_I420:
-        return ff_vf_next_query_format(vf, fmt);
-    }
-    return 0;
-}
-#endif
-
-static void uninit(struct vf_instance *vf)
-{
-    free(vf->priv);
-}
-
-static int vf_open(vf_instance_t *vf, char *args)
-{
-    vf->put_image = put_image;
-    vf->control = control;
-    vf->uninit = uninit;
-    vf->priv = calloc(1, sizeof(struct vf_priv_s));
-    return 1;
-}
-
-const vf_info_t ff_vf_info_softskip = {
-    "soft (post-filter) frame skipping for encoding",
-    "softskip",
-    "Rich Felker",
-    "",
-    vf_open,
-    NULL
-};
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_spp.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_spp.c
index b53b57edc9c..75ede23ccbb 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_spp.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_spp.c
@@ -37,6 +37,7 @@
 #include "mp_msg.h"
 #include "cpudetect.h"
 
+#include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavcodec/avcodec.h"
@@ -49,7 +50,7 @@
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 #include "libvo/fastmemcpy.h"
 
 #define XMIN(a,b) ((a) < (b) ? (a) : (b))
@@ -105,7 +106,7 @@ struct vf_priv_s {
 
 #define SHIFT 22
 
-static void hardthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
+static void hardthresh_c(int16_t dst[64], int16_t src[64], int qp, uint8_t *permutation){
         int i;
         int bias= 0; //FIXME
         unsigned int threshold1, threshold2;
@@ -113,7 +114,7 @@ static void hardthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *perm
         threshold1= qp*((1<<4) - bias) - 1;
         threshold2= (threshold1<<1);
 
-        memset(dst, 0, 64*sizeof(DCTELEM));
+        memset(dst, 0, 64*sizeof(int16_t));
         dst[0]= (src[0] + 4)>>3;
 
         for(i=1; i<64; i++){
@@ -125,7 +126,7 @@ static void hardthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *perm
         }
 }
 
-static void softthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
+static void softthresh_c(int16_t dst[64], int16_t src[64], int qp, uint8_t *permutation){
         int i;
         int bias= 0; //FIXME
         unsigned int threshold1, threshold2;
@@ -133,7 +134,7 @@ static void softthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *perm
         threshold1= qp*((1<<4) - bias) - 1;
         threshold2= (threshold1<<1);
 
-        memset(dst, 0, 64*sizeof(DCTELEM));
+        memset(dst, 0, 64*sizeof(int16_t));
         dst[0]= (src[0] + 4)>>3;
 
         for(i=1; i<64; i++){
@@ -149,7 +150,7 @@ static void softthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *perm
 }
 
 #if HAVE_MMX
-static void hardthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
+static void hardthresh_mmx(int16_t dst[64], int16_t src[64], int qp, uint8_t *permutation){
         int bias= 0; //FIXME
         unsigned int threshold1;
 
@@ -217,7 +218,7 @@ static void hardthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *pe
         dst[0]= (src[0] + 4)>>3;
 }
 
-static void softthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
+static void softthresh_mmx(int16_t dst[64], int16_t src[64], int qp, uint8_t *permutation){
         int bias= 0; //FIXME
         unsigned int threshold1;
 
@@ -294,7 +295,7 @@ static void softthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *pe
 }
 #endif
 
-static inline void add_block(int16_t *dst, int stride, DCTELEM block[64]){
+static inline void add_block(int16_t *dst, int stride, int16_t block[64]){
         int y;
 
         for(y=0; y<8; y++){
@@ -372,15 +373,15 @@ static void store_slice_mmx(uint8_t *dst, int16_t *src, int dst_stride, int src_
 
 static void (*store_slice)(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)= store_slice_c;
 
-static void (*requantize)(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation)= hardthresh_c;
+static void (*requantize)(int16_t dst[64], int16_t src[64], int qp, uint8_t *permutation)= hardthresh_c;
 
 static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, uint8_t *qp_store, int qp_stride, int is_luma){
         int x, y, i;
         const int count= 1<log2_count;
         const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15));
         uint64_t __attribute__((aligned(16))) block_align[32];
-        DCTELEM *block = (DCTELEM *)block_align;
-        DCTELEM *block2= (DCTELEM *)(block_align+16);
+        int16_t *block = (int16_t *)block_align;
+        int16_t *block2= (int16_t *)(block_align+16);
 
         if (!src || !dst) return; // HACK avoid crash for Y8 colourspace
         for(y=0; ypriv->avctx= avcodec_alloc_context();
-    dsputil_init(&vf->priv->dsp, vf->priv->avctx);
+    vf->priv->avctx= avcodec_alloc_context3(NULL);
+    ff_dsputil_init(&vf->priv->dsp, vf->priv->avctx);
 
     vf->priv->log2_count= 3;
 
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_stereo3d.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_stereo3d.c
deleted file mode 100644
index 3dd1df9a66a..00000000000
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_stereo3d.c
+++ /dev/null
@@ -1,512 +0,0 @@
-/*
- * Copyright (C) 2010 Gordon Schmidt  s2000.tu-chemnitz.de>
- *
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-//==includes==//
-#include 
-#include 
-#include 
-
-#include "config.h"
-#include "mp_msg.h"
-#include "help_mp.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-#include "libavutil/common.h"
-#include "libvo/fastmemcpy.h"
-
-//==types==//
-typedef enum stereo_code {
-    ANAGLYPH_RC_GRAY,   //anaglyph red/cyan gray
-    ANAGLYPH_RC_HALF,   //anaglyph red/cyan half colored
-    ANAGLYPH_RC_COLOR,  //anaglyph red/cyan colored
-    ANAGLYPH_RC_DUBOIS, //anaglyph red/cyan dubois
-    ANAGLYPH_GM_GRAY,   //anaglyph green/magenta gray
-    ANAGLYPH_GM_HALF,   //anaglyph green/magenta half colored
-    ANAGLYPH_GM_COLOR,  //anaglyph green/magenta colored
-    ANAGLYPH_YB_GRAY,   //anaglyph yellow/blue gray
-    ANAGLYPH_YB_HALF,   //anaglyph yellow/blue half colored
-    ANAGLYPH_YB_COLOR,  //anaglyph yellow/blue colored
-    MONO_L,             //mono output for debugging (left eye only)
-    MONO_R,             //mono output for debugging (right eye only)
-    SIDE_BY_SIDE_LR,    //side by side parallel (left eye left, right eye right)
-    SIDE_BY_SIDE_RL,    //side by side crosseye (right eye left, left eye right)
-    SIDE_BY_SIDE_2_LR,  //side by side parallel with half width resolution
-    SIDE_BY_SIDE_2_RL,  //side by side crosseye with half width resolution
-    ABOVE_BELOW_LR,     //above-below (left eye above, right eye below)
-    ABOVE_BELOW_RL,     //above-below (right eye above, left eye below)
-    ABOVE_BELOW_2_LR,   //above-below with half height resolution
-    ABOVE_BELOW_2_RL,   //above-below with half height resolution
-    INTERLEAVE_ROWS_LR, //row-interleave (left eye has top row)
-    INTERLEAVE_ROWS_RL, //row-interleave (right eye has top row)
-    STEREO_CODE_COUNT   //no value set - TODO: needs autodetection
-} stereo_code;
-
-typedef struct component {
-    stereo_code  fmt;
-    unsigned int width;
-    unsigned int height;
-    unsigned int off_left;
-    unsigned int off_right;
-    unsigned int row_left;
-    unsigned int row_right;
-} component;
-
-//==global variables==//
-static const int ana_coeff[10][3][6] = {
-    {{19595, 38470,  7471,     0,     0,     0},    //ANAGLYPH_RC_GRAY
-     {    0,     0,     0, 19595, 38470,  7471},
-     {    0,     0,     0, 19595, 38470,  7471}},
-    {{19595, 38470,  7471,     0,     0,     0},    //ANAGLYPH_RC_HALF
-     {    0,     0,     0,     0, 65536,     0},
-     {    0,     0,     0,     0,     0, 65536}},
-    {{65536,     0,     0,     0,     0,     0},    //ANAGLYPH_RC_COLOR
-     {    0,     0,     0,     0, 65536,     0},
-     {    0,     0,     0,     0,     0, 65536}},
-    {{29891, 32800, 11559, -2849, -5763,  -102},    //ANAGLYPH_RC_DUBOIS
-     {-2627, -2479, -1033, 24804, 48080, -1209},
-     { -997, -1350,  -358, -4729, -7403, 80373}},
-    {{    0,     0,     0, 19595, 38470,  7471},    //ANAGLYPH_GM_GRAY
-     {19595, 38470,  7471,     0,     0,     0},
-     {    0,     0,     0, 19595, 38470,  7471}},
-    {{    0,     0,     0, 65536,     0,     0},    //ANAGLYPH_GM_HALF
-     {19595, 38470,  7471,     0,     0,     0},
-     {    0,     0,     0,     0,     0, 65536}},
-    {{    0,     0,     0, 65536,     0,     0},    //ANAGLYPH_GM_COLOR
-     {    0, 65536,     0,     0,     0,     0},
-     {    0,     0,     0,     0,     0, 65536}},
-    {{    0,     0,     0, 19595, 38470,  7471},    //ANAGLYPH_YB_GRAY
-     {    0,     0,     0, 19595, 38470,  7471},
-     {19595, 38470,  7471,     0,     0,     0}},
-    {{    0,     0,     0, 65536,     0,     0},    //ANAGLYPH_YB_HALF
-     {    0,     0,     0,     0, 65536,     0},
-     {19595, 38470,  7471,     0,     0,     0}},
-    {{    0,     0,     0, 65536,     0,     0},    //ANAGLYPH_YB_COLOR
-     {    0,     0,     0,     0, 65536,     0},
-     {    0,     0, 65536,     0,     0,     0}}
-};
-
-struct vf_priv_s {
-    component in;
-    component out;
-    int ana_matrix[3][6];
-    unsigned int width;
-    unsigned int height;
-    unsigned int row_step;
-} const ff_vf_priv_default = {
-  {SIDE_BY_SIDE_LR},
-  {ANAGLYPH_RC_DUBOIS}
-};
-
-//==functions==//
-static inline uint8_t ana_convert(int coeff[6], uint8_t left[3], uint8_t right[3])
-{
-    int sum;
-
-    sum  = coeff[0] * left[0] + coeff[3] * right[0]; //red in
-    sum += coeff[1] * left[1] + coeff[4] * right[1]; //green in
-    sum += coeff[2] * left[2] + coeff[5] * right[2]; //blue in
-    return av_clip_uint8(sum >> 16);
-}
-
-static int config(struct vf_instance *vf, int width, int height, int d_width,
-                  int d_height, unsigned int flags, unsigned int outfmt)
-{
-    if ((width & 1) || (height & 1)) {
-        ff_mp_msg(MSGT_VFILTER, MSGL_WARN, "[stereo3d] invalid height or width\n");
-        return 0;
-    }
-    //default input values
-    vf->priv->width             = width;
-    vf->priv->height            = height;
-    vf->priv->row_step          = 1;
-    vf->priv->in.width          = width;
-    vf->priv->in.height         = height;
-    vf->priv->in.off_left       = 0;
-    vf->priv->in.off_right      = 0;
-    vf->priv->in.row_left       = 0;
-    vf->priv->in.row_right      = 0;
-
-    //check input format
-    switch (vf->priv->in.fmt) {
-    case SIDE_BY_SIDE_2_LR:
-        d_width                *= 2;
-    case SIDE_BY_SIDE_LR:
-        vf->priv->width         = width / 2;
-        vf->priv->in.off_right  = vf->priv->width * 3;
-        break;
-    case SIDE_BY_SIDE_2_RL:
-        d_width                *= 2;
-    case SIDE_BY_SIDE_RL:
-        vf->priv->width         = width / 2;
-        vf->priv->in.off_left   = vf->priv->width * 3;
-        break;
-    case ABOVE_BELOW_2_LR:
-        d_height               *= 2;
-    case ABOVE_BELOW_LR:
-        vf->priv->height        = height / 2;
-        vf->priv->in.row_right  = vf->priv->height;
-        break;
-    case ABOVE_BELOW_2_RL:
-        d_height               *= 2;
-    case ABOVE_BELOW_RL:
-        vf->priv->height        = height / 2;
-        vf->priv->in.row_left   = vf->priv->height;
-        break;
-    default:
-        ff_mp_msg(MSGT_VFILTER, MSGL_WARN,
-               "[stereo3d] stereo format of input is not supported\n");
-        return 0;
-        break;
-    }
-    //default output values
-    vf->priv->out.width         = vf->priv->width;
-    vf->priv->out.height        = vf->priv->height;
-    vf->priv->out.off_left      = 0;
-    vf->priv->out.off_right     = 0;
-    vf->priv->out.row_left      = 0;
-    vf->priv->out.row_right     = 0;
-
-    //check output format
-    switch (vf->priv->out.fmt) {
-    case ANAGLYPH_RC_GRAY:
-    case ANAGLYPH_RC_HALF:
-    case ANAGLYPH_RC_COLOR:
-    case ANAGLYPH_RC_DUBOIS:
-    case ANAGLYPH_GM_GRAY:
-    case ANAGLYPH_GM_HALF:
-    case ANAGLYPH_GM_COLOR:
-    case ANAGLYPH_YB_GRAY:
-    case ANAGLYPH_YB_HALF:
-    case ANAGLYPH_YB_COLOR:
-        memcpy(vf->priv->ana_matrix, ana_coeff[vf->priv->out.fmt],
-               sizeof(vf->priv->ana_matrix));
-        break;
-    case SIDE_BY_SIDE_2_LR:
-        d_width                /= 2;
-    case SIDE_BY_SIDE_LR:
-        vf->priv->out.width     = vf->priv->width * 2;
-        vf->priv->out.off_right = vf->priv->width * 3;
-        break;
-    case SIDE_BY_SIDE_2_RL:
-        d_width                /= 2;
-    case SIDE_BY_SIDE_RL:
-        vf->priv->out.width     = vf->priv->width * 2;
-        vf->priv->out.off_left  = vf->priv->width * 3;
-        break;
-    case ABOVE_BELOW_2_LR:
-        d_height               /= 2;
-    case ABOVE_BELOW_LR:
-        vf->priv->out.height    = vf->priv->height * 2;
-        vf->priv->out.row_right = vf->priv->height;
-        break;
-    case ABOVE_BELOW_2_RL:
-        d_height               /= 2;
-    case ABOVE_BELOW_RL:
-        vf->priv->out.height    = vf->priv->height * 2;
-        vf->priv->out.row_left  = vf->priv->height;
-        break;
-    case INTERLEAVE_ROWS_LR:
-        vf->priv->row_step      = 2;
-        vf->priv->height        = vf->priv->height / 2;
-        vf->priv->out.off_right = vf->priv->width * 3;
-        vf->priv->in.off_right += vf->priv->in.width * 3;
-        break;
-    case INTERLEAVE_ROWS_RL:
-        vf->priv->row_step      = 2;
-        vf->priv->height        = vf->priv->height / 2;
-        vf->priv->out.off_left  = vf->priv->width * 3;
-        vf->priv->in.off_left  += vf->priv->in.width * 3;
-        break;
-    case MONO_R:
-        //same as MONO_L only needs switching of input offsets
-        vf->priv->in.off_left   = vf->priv->in.off_right;
-        vf->priv->in.row_left   = vf->priv->in.row_right;
-        //nobreak;
-    case MONO_L:
-        //use default settings
-        break;
-    default:
-        ff_mp_msg(MSGT_VFILTER, MSGL_WARN,
-            "[stereo3d] stereo format of output is not supported\n");
-        return 0;
-        break;
-    }
-//    if (!opt_screen_size_x && !opt_screen_size_y) {
-        d_width     = d_width  * vf->priv->out.width  / width;
-        d_height    = d_height * vf->priv->out.height / height;
-//    }
-
-    return ff_vf_next_config(vf, vf->priv->out.width, vf->priv->out.height,
-                          d_width, d_height, flags, outfmt);
-}
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
-{
-    mp_image_t *dmpi;
-    if (vf->priv->in.fmt == vf->priv->out.fmt) { //nothing to do
-        dmpi = mpi;
-    } else {
-        int out_off_left, out_off_right;
-        int in_off_left  = vf->priv->in.row_left   * mpi->stride[0]  +
-                           vf->priv->in.off_left;
-        int in_off_right = vf->priv->in.row_right  * mpi->stride[0]  +
-                           vf->priv->in.off_right;
-
-        dmpi = ff_vf_get_image(vf->next, IMGFMT_RGB24, MP_IMGTYPE_TEMP,
-                            MP_IMGFLAG_ACCEPT_STRIDE,
-                            vf->priv->out.width, vf->priv->out.height);
-        out_off_left   = vf->priv->out.row_left  * dmpi->stride[0] +
-                         vf->priv->out.off_left;
-        out_off_right  = vf->priv->out.row_right * dmpi->stride[0] +
-                         vf->priv->out.off_right;
-
-        switch (vf->priv->out.fmt) {
-        case SIDE_BY_SIDE_LR:
-        case SIDE_BY_SIDE_RL:
-        case SIDE_BY_SIDE_2_LR:
-        case SIDE_BY_SIDE_2_RL:
-        case ABOVE_BELOW_LR:
-        case ABOVE_BELOW_RL:
-        case ABOVE_BELOW_2_LR:
-        case ABOVE_BELOW_2_RL:
-        case INTERLEAVE_ROWS_LR:
-        case INTERLEAVE_ROWS_RL:
-            memcpy_pic2(dmpi->planes[0] + out_off_left,
-                       mpi->planes[0] + in_off_left,
-                       3 * vf->priv->width,
-                       vf->priv->height,
-                       dmpi->stride[0] * vf->priv->row_step,
-                       mpi->stride[0] * vf->priv->row_step,
-                       vf->priv->row_step != 1);
-            memcpy_pic2(dmpi->planes[0] + out_off_right,
-                       mpi->planes[0] + in_off_right,
-                       3 * vf->priv->width,
-                       vf->priv->height,
-                       dmpi->stride[0] * vf->priv->row_step,
-                       mpi->stride[0] * vf->priv->row_step,
-                       vf->priv->row_step != 1);
-            break;
-        case MONO_L:
-        case MONO_R:
-            memcpy_pic(dmpi->planes[0],
-                       mpi->planes[0] + in_off_left,
-                       3 * vf->priv->width,
-                       vf->priv->height,
-                       dmpi->stride[0],
-                       mpi->stride[0]);
-            break;
-        case ANAGLYPH_RC_GRAY:
-        case ANAGLYPH_RC_HALF:
-        case ANAGLYPH_RC_COLOR:
-        case ANAGLYPH_RC_DUBOIS:
-        case ANAGLYPH_GM_GRAY:
-        case ANAGLYPH_GM_HALF:
-        case ANAGLYPH_GM_COLOR:
-        case ANAGLYPH_YB_GRAY:
-        case ANAGLYPH_YB_HALF:
-        case ANAGLYPH_YB_COLOR: {
-            int i,x,y,il,ir,o;
-            unsigned char *source     = mpi->planes[0];
-            unsigned char *dest       = dmpi->planes[0];
-            unsigned int   out_width  = vf->priv->out.width;
-            int           *ana_matrix[3];
-
-            for(i = 0; i < 3; i++)
-                ana_matrix[i] = vf->priv->ana_matrix[i];
-
-            for (y = 0; y < vf->priv->out.height; y++) {
-                o   = dmpi->stride[0] * y;
-                il  = in_off_left  + y * mpi->stride[0];
-                ir  = in_off_right + y * mpi->stride[0];
-                for (x = 0; x < out_width; x++) {
-                    dest[o    ]  = ana_convert(
-                                   ana_matrix[0], source + il, source + ir); //red out
-                    dest[o + 1]  = ana_convert(
-                                   ana_matrix[1], source + il, source + ir); //green out
-                    dest[o + 2]  = ana_convert(
-                                   ana_matrix[2], source + il, source + ir); //blue out
-                    il += 3;
-                    ir += 3;
-                    o  += 3;
-                }
-            }
-            break;
-        }
-        default:
-            ff_mp_msg(MSGT_VFILTER, MSGL_WARN,
-                   "[stereo3d] stereo format of output is not supported\n");
-            return 0;
-            break;
-        }
-    }
-    return ff_vf_next_put_image(vf, dmpi, pts);
-}
-
-static int query_format(struct vf_instance *vf, unsigned int fmt)
-{
-    switch (fmt)
-    case IMGFMT_RGB24:
-        return ff_vf_next_query_format(vf, fmt);
-    return 0;
-}
-
-static void uninit(vf_instance_t *vf)
-{
-    free(vf->priv);
-}
-
-static int vf_open(vf_instance_t *vf, char *args)
-{
-    vf->config          = config;
-    vf->uninit          = uninit;
-    vf->put_image       = put_image;
-    vf->query_format    = query_format;
-    vf->priv=malloc(sizeof(struct vf_priv_s));
-    memset(vf->priv, 0, sizeof(struct vf_priv_s));
-
-    vf->priv->in.fmt = SIDE_BY_SIDE_LR;
-    vf->priv->out.fmt= ANAGLYPH_RC_DUBOIS;
-    if (args) sscanf(args, "%d:%d", &vf->priv->in.fmt, &vf->priv->out.fmt);
-
-    return 1;
-}
-#if 0
-///Presets usage
-static const struct format_preset {
-  char* name;
-  stereo_code scode;
-} vf_format_presets_defs[] = {
-    {"arcg",                             ANAGLYPH_RC_GRAY},
-    {"anaglyph_red_cyan_gray",           ANAGLYPH_RC_GRAY},
-    {"arch",                             ANAGLYPH_RC_HALF},
-    {"anaglyph_red_cyan_half_color",     ANAGLYPH_RC_HALF},
-    {"arcc",                             ANAGLYPH_RC_COLOR},
-    {"anaglyph_red_cyan_color",          ANAGLYPH_RC_COLOR},
-    {"arcd",                             ANAGLYPH_RC_DUBOIS},
-    {"anaglyph_red_cyan_dubios",         ANAGLYPH_RC_DUBOIS},
-    {"agmg",                             ANAGLYPH_GM_GRAY},
-    {"anaglyph_green_magenta_gray",      ANAGLYPH_GM_GRAY},
-    {"agmh",                             ANAGLYPH_GM_HALF},
-    {"anaglyph_green_magenta_half_color",ANAGLYPH_GM_HALF},
-    {"agmc",                             ANAGLYPH_GM_COLOR},
-    {"anaglyph_green_magenta_color",     ANAGLYPH_GM_COLOR},
-    {"aybg",                             ANAGLYPH_YB_GRAY},
-    {"anaglyph_yellow_blue_gray",        ANAGLYPH_YB_GRAY},
-    {"aybh",                             ANAGLYPH_YB_HALF},
-    {"anaglyph_yellow_blue_half_color",  ANAGLYPH_YB_HALF},
-    {"aybc",                             ANAGLYPH_YB_COLOR},
-    {"anaglyph_yellow_blue_color",       ANAGLYPH_YB_COLOR},
-    {"ml",                               MONO_L},
-    {"mono_left",                        MONO_L},
-    {"mr",                               MONO_R},
-    {"mono_right",                       MONO_R},
-    {"sbsl",                             SIDE_BY_SIDE_LR},
-    {"side_by_side_left_first",          SIDE_BY_SIDE_LR},
-    {"sbsr",                             SIDE_BY_SIDE_RL},
-    {"side_by_side_right_first",         SIDE_BY_SIDE_RL},
-    {"sbs2l",                              SIDE_BY_SIDE_2_LR},
-    {"side_by_side_half_width_left_first", SIDE_BY_SIDE_2_LR},
-    {"sbs2r",                              SIDE_BY_SIDE_2_RL},
-    {"side_by_side_half_width_right_first",SIDE_BY_SIDE_2_RL},
-    {"abl",                              ABOVE_BELOW_LR},
-    {"above_below_left_first",           ABOVE_BELOW_LR},
-    {"abr",                              ABOVE_BELOW_RL},
-    {"above_below_right_first",          ABOVE_BELOW_RL},
-    {"ab2l",                               ABOVE_BELOW_2_LR},
-    {"above_below_half_height_left_first", ABOVE_BELOW_2_LR},
-    {"ab2r",                               ABOVE_BELOW_2_RL},
-    {"above_below_half_height_right_first",ABOVE_BELOW_2_RL},
-    {"irl",                                INTERLEAVE_ROWS_LR},
-    {"interleave_rows_left_first",         INTERLEAVE_ROWS_LR},
-    {"irr",                                INTERLEAVE_ROWS_RL},
-    {"interleave_rows_right_first",        INTERLEAVE_ROWS_RL},
-    { NULL, 0}
-};
-
-#define ST_OFF(f) M_ST_OFF(struct format_preset,f)
-static const m_option_t vf_format_preset_fields_in[] = {
-  {"in", ST_OFF(scode), CONF_TYPE_INT, 0,0,0, NULL},
-  { NULL, NULL, 0, 0, 0, 0,  NULL }
-};
-static const m_option_t vf_format_preset_fields_out[] = {
-  {"out", ST_OFF(scode), CONF_TYPE_INT, 0,0,0, NULL},
-  { NULL, NULL, 0, 0, 0, 0,  NULL }
-};
-
-static const m_struct_t vf_format_preset_in = {
-  "stereo_format_preset_in",
-  sizeof(struct format_preset),
-  NULL,
-  vf_format_preset_fields_in
-};
-static const m_struct_t vf_format_preset_out = {
-  "stereo_format_preset_out",
-  sizeof(struct format_preset),
-  NULL,
-  vf_format_preset_fields_out
-};
-
-static const m_struct_t vf_opts;
-static const m_obj_presets_t format_preset_in = {
-  (struct m_struct_st*)&vf_format_preset_in,
-  (struct m_struct_st*)&vf_opts,
-  (struct format_preset*)vf_format_presets_defs,
-  ST_OFF(name)
-};
-static const m_obj_presets_t format_preset_out = {
-  (struct m_struct_st*)&vf_format_preset_out,
-  (struct m_struct_st*)&vf_opts,
-  (struct format_preset*)vf_format_presets_defs,
-  ST_OFF(name)
-};
-
-/// Now the options
-#undef ST_OFF
-#define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
-static const m_option_t vf_opts_fields[] = {
-  {"stereo_in", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0,
-                   (m_obj_presets_t*)&format_preset_in},
-  {"stereo_out", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0,
-                    (m_obj_presets_t*)&format_preset_out},
-  {"in", ST_OFF(in.fmt), CONF_TYPE_INT, 0,0,0, NULL},
-  {"out", ST_OFF(out.fmt), CONF_TYPE_INT, 0,0,0, NULL},
-  { NULL, NULL, 0, 0, 0, 0,  NULL }
-};
-
-static const m_struct_t vf_opts = {
-  "stereo3d",
-  sizeof(struct vf_priv_s),
-  &ff_vf_priv_default,
-  vf_opts_fields
-};
-#endif
-
-//==info struct==//
-const vf_info_t ff_vf_info_stereo3d = {
-    "stereoscopic 3d view",
-    "stereo3d",
-    "Gordon Schmidt",
-    "view stereoscopic videos",
-    vf_open,
-//    &vf_opts
-};
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_unsharp.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_unsharp.c
deleted file mode 100644
index b947769fc29..00000000000
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_unsharp.c
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * Copyright (C) 2002 Remi Guyomarch 
- *
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "config.h"
-#include "mp_msg.h"
-#include "cpudetect.h"
-
-#if HAVE_MALLOC_H
-#include 
-#endif
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-#include "libvo/fastmemcpy.h"
-#include "libavutil/common.h"
-
-//===========================================================================//
-
-#define MIN_MATRIX_SIZE 3
-#define MAX_MATRIX_SIZE 63
-
-typedef struct FilterParam {
-    int msizeX, msizeY;
-    double amount;
-    uint32_t *SC[MAX_MATRIX_SIZE-1];
-} FilterParam;
-
-struct vf_priv_s {
-    FilterParam lumaParam;
-    FilterParam chromaParam;
-    unsigned int outfmt;
-};
-
-
-//===========================================================================//
-
-/* This code is based on :
-
-An Efficient algorithm for Gaussian blur using finite-state machines
-Frederick M. Waltz and John W. V. Miller
-
-SPIE Conf. on Machine Vision Systems for Inspection and Metrology VII
-Originally published Boston, Nov 98
-
-*/
-
-static void unsharp( uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int width, int height, FilterParam *fp ) {
-
-    uint32_t **SC = fp->SC;
-    uint32_t SR[MAX_MATRIX_SIZE-1], Tmp1, Tmp2;
-    uint8_t* src2 = src; // avoid gcc warning
-
-    int32_t res;
-    int x, y, z;
-    int amount = fp->amount * 65536.0;
-    int stepsX = fp->msizeX/2;
-    int stepsY = fp->msizeY/2;
-    int scalebits = (stepsX+stepsY)*2;
-    int32_t halfscale = 1 << ((stepsX+stepsY)*2-1);
-
-    if( !fp->amount ) {
-        if( src == dst )
-            return;
-        if( dstStride == srcStride )
-            fast_memcpy( dst, src, srcStride*height );
-        else
-            for( y=0; y=width ? src2[width-1] : src2[x];
-            for( z=0; z=stepsX && y>=stepsY ) {
-                uint8_t* srx = src - stepsY*srcStride + x - stepsX;
-                uint8_t* dsx = dst - stepsY*dstStride + x - stepsX;
-
-                res = (int32_t)*srx + ( ( ( (int32_t)*srx - (int32_t)((Tmp1+halfscale) >> scalebits) ) * amount ) >> 16 );
-                *dsx = res>255 ? 255 : res<0 ? 0 : (uint8_t)res;
-            }
-        }
-        if( y >= 0 ) {
-            dst += dstStride;
-            src += srcStride;
-        }
-    }
-}
-
-//===========================================================================//
-
-static int config( struct vf_instance *vf,
-                   int width, int height, int d_width, int d_height,
-                   unsigned int flags, unsigned int outfmt ) {
-
-    int z, stepsX, stepsY;
-    FilterParam *fp;
-    const char *effect;
-
-    // allocate buffers
-
-    fp = &vf->priv->lumaParam;
-    effect = fp->amount == 0 ? "don't touch" : fp->amount < 0 ? "blur" : "sharpen";
-    ff_mp_msg( MSGT_VFILTER, MSGL_INFO, "unsharp: %dx%d:%0.2f (%s luma) \n", fp->msizeX, fp->msizeY, fp->amount, effect );
-    memset( fp->SC, 0, sizeof( fp->SC ) );
-    stepsX = fp->msizeX/2;
-    stepsY = fp->msizeY/2;
-    for( z=0; z<2*stepsY; z++ )
-        fp->SC[z] = av_malloc(sizeof(*(fp->SC[z])) * (width+2*stepsX));
-
-    fp = &vf->priv->chromaParam;
-    effect = fp->amount == 0 ? "don't touch" : fp->amount < 0 ? "blur" : "sharpen";
-    ff_mp_msg( MSGT_VFILTER, MSGL_INFO, "unsharp: %dx%d:%0.2f (%s chroma)\n", fp->msizeX, fp->msizeY, fp->amount, effect );
-    memset( fp->SC, 0, sizeof( fp->SC ) );
-    stepsX = fp->msizeX/2;
-    stepsY = fp->msizeY/2;
-    for( z=0; z<2*stepsY; z++ )
-        fp->SC[z] = av_malloc(sizeof(*(fp->SC[z])) * (width+2*stepsX));
-
-    return ff_vf_next_config( vf, width, height, d_width, d_height, flags, outfmt );
-}
-
-//===========================================================================//
-
-static void get_image( struct vf_instance *vf, mp_image_t *mpi ) {
-    if( mpi->flags & MP_IMGFLAG_PRESERVE )
-        return; // don't change
-    if( mpi->imgfmt!=vf->priv->outfmt )
-        return; // colorspace differ
-
-    vf->dmpi = ff_vf_get_image( vf->next, mpi->imgfmt, mpi->type, mpi->flags, mpi->w, mpi->h );
-    mpi->planes[0] = vf->dmpi->planes[0];
-    mpi->stride[0] = vf->dmpi->stride[0];
-    mpi->width = vf->dmpi->width;
-    if( mpi->flags & MP_IMGFLAG_PLANAR ) {
-        mpi->planes[1] = vf->dmpi->planes[1];
-        mpi->planes[2] = vf->dmpi->planes[2];
-        mpi->stride[1] = vf->dmpi->stride[1];
-        mpi->stride[2] = vf->dmpi->stride[2];
-    }
-    mpi->flags |= MP_IMGFLAG_DIRECT;
-}
-
-static int put_image( struct vf_instance *vf, mp_image_t *mpi, double pts) {
-    mp_image_t *dmpi;
-
-    if( !(mpi->flags & MP_IMGFLAG_DIRECT) )
-        // no DR, so get a new image! hope we'll get DR buffer:
-        vf->dmpi = ff_vf_get_image( vf->next,vf->priv->outfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, mpi->w, mpi->h);
-    dmpi= vf->dmpi;
-
-    unsharp( dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w,   mpi->h,   &vf->priv->lumaParam );
-    unsharp( dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, &vf->priv->chromaParam );
-    unsharp( dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2, &vf->priv->chromaParam );
-
-    ff_vf_clone_mpi_attributes(dmpi, mpi);
-
-#if HAVE_MMX
-    if(ff_gCpuCaps.hasMMX)
-        __asm__ volatile ("emms\n\t");
-#endif
-#if HAVE_MMX2
-    if(ff_gCpuCaps.hasMMX2)
-        __asm__ volatile ("sfence\n\t");
-#endif
-
-    return ff_vf_next_put_image( vf, dmpi, pts);
-}
-
-static void uninit( struct vf_instance *vf ) {
-    unsigned int z;
-    FilterParam *fp;
-
-    if( !vf->priv ) return;
-
-    fp = &vf->priv->lumaParam;
-    for( z=0; zSC)/sizeof(fp->SC[0]); z++ ) {
-        av_free( fp->SC[z] );
-        fp->SC[z] = NULL;
-    }
-    fp = &vf->priv->chromaParam;
-    for( z=0; zSC)/sizeof(fp->SC[0]); z++ ) {
-        av_free( fp->SC[z] );
-        fp->SC[z] = NULL;
-    }
-
-    free( vf->priv );
-    vf->priv = NULL;
-}
-
-//===========================================================================//
-
-static int query_format( struct vf_instance *vf, unsigned int fmt ) {
-    switch(fmt) {
-    case IMGFMT_YV12:
-    case IMGFMT_I420:
-    case IMGFMT_IYUV:
-        return ff_vf_next_query_format( vf, vf->priv->outfmt );
-    }
-    return 0;
-}
-
-//===========================================================================//
-
-static void parse( FilterParam *fp, char* args ) {
-
-    // l7x5:0.8:c3x3:-0.2
-
-    char *z;
-    char *pos = args;
-    char *max = args + strlen(args);
-
-    // parse matrix sizes
-    fp->msizeX = ( pos && pos+1msizeY = ( z && z+1msizeX;
-
-    // min/max & odd
-    fp->msizeX = 1 | av_clip(fp->msizeX, MIN_MATRIX_SIZE, MAX_MATRIX_SIZE);
-    fp->msizeY = 1 | av_clip(fp->msizeY, MIN_MATRIX_SIZE, MAX_MATRIX_SIZE);
-
-    // parse amount
-    pos = strchr( pos+1, ':' );
-    fp->amount = ( pos && pos+1config       = config;
-    vf->put_image    = put_image;
-    vf->get_image    = get_image;
-    vf->query_format = query_format;
-    vf->uninit       = uninit;
-    vf->priv         = malloc( sizeof(struct vf_priv_s) );
-    memset( vf->priv, 0, sizeof(struct vf_priv_s) );
-
-    if( args ) {
-        char *args2 = strchr( args, 'l' );
-        if( args2 )
-            parse( &vf->priv->lumaParam, args2 );
-        else {
-            vf->priv->lumaParam.amount =
-            vf->priv->lumaParam.msizeX =
-            vf->priv->lumaParam.msizeY = 0;
-        }
-
-        args2 = strchr( args, 'c' );
-        if( args2 )
-            parse( &vf->priv->chromaParam, args2 );
-        else {
-            vf->priv->chromaParam.amount =
-            vf->priv->chromaParam.msizeX =
-            vf->priv->chromaParam.msizeY = 0;
-        }
-
-        if( !vf->priv->lumaParam.msizeX && !vf->priv->chromaParam.msizeX )
-            return 0; // nothing to do
-    }
-
-    // check csp:
-    vf->priv->outfmt = ff_vf_match_csp( &vf->next, fmt_list, IMGFMT_YV12 );
-    if( !vf->priv->outfmt ) {
-        uninit( vf );
-        return 0; // no csp match :(
-    }
-
-    return 1;
-}
-
-const vf_info_t ff_vf_info_unsharp = {
-    "unsharp mask & gaussian blur",
-    "unsharp",
-    "Remi Guyomarch",
-    "",
-    vf_open,
-    NULL
-};
-
-//===========================================================================//
diff --git a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_uspp.c b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_uspp.c
index 7444e03328b..54cc0f9e115 100644
--- a/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_uspp.c
+++ b/mythtv/external/FFmpeg/libavfilter/libmpcodecs/vf_uspp.c
@@ -30,12 +30,13 @@
 #include "mp_msg.h"
 #include "cpudetect.h"
 
+#include "libavutil/mem.h"
 #include "libavcodec/avcodec.h"
 
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 #include "libvo/fastmemcpy.h"
 
 #define XMIN(a,b) ((a) < (b) ? (a) : (b))
@@ -94,7 +95,9 @@ static const uint8_t offset[511][2]= {
 { 7, 1}, {15, 1}, { 7, 9}, {15, 9}, { 7, 3}, {15, 3}, { 7,11}, {15,11},
 { 7, 5}, {15, 5}, { 7,13}, {15,13}, { 7, 7}, {15, 7}, { 7,15}, {15,15},
 
-{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 4, 4}, {12, 4}, { 4,12}, {12,12}, { 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 4, 0}, {12, 0}, { 4, 8}, {12, 8}, { 2, 2}, {10, 2}, { 2,10}, {10,10}, { 6, 6}, {14, 6}, { 6,14}, {14,14}, { 2, 6}, {10, 6}, { 2,14}, {10,14}, { 6, 2}, {14, 2}, { 6,10}, {14,10}, { 0, 2}, { 8, 2}, { 0,10}, { 8,10}, { 4, 6}, {12, 6}, { 4,14}, {12,14}, { 0, 6}, { 8, 6}, { 0,14}, { 8,14}, { 4, 2}, {12, 2}, { 4,10}, {12,10}, { 2, 0}, {10, 0}, { 2, 8}, {10, 8}, { 6, 4}, {14, 4}, { 6,12}, {14,12}, { 2, 4}, {10, 4}, { 2,12}, {10,12}, { 6, 0}, {14, 0}, { 6, 8}, {14, 8}, { 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 5, 5}, {13, 5}, { 5,13}, {13,13}, { 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9}, { 3, 3}, {11, 3}, { 3,11}, {11,11}, { 7, 7}, {15, 7}, { 7,15}, {15,15}, { 3, 7}, {11, 7}, { 3,15}, {11,15}, { 7, 3}, {15, 3}, { 7,11}, {15,11}, { 1, 3}, { 9, 3}, { 1,11}, { 9,11}, { 5, 7}, {13, 7}, { 5,15}, {13,15}, { 1, 7}, { 9, 7}, { 1,15}, { 9,15}, { 5, 3}, {13, 3}, { 5,11}, {13,11}, { 3, 1}, {11,1}, { 3, 9}, {11, 9}, { 7, 5}, {15, 5}, { 7,13}, {15,13}, { 3, 5}, {11, 5}, { 3,13}, {11,13}, { 7, 1}, {15, 1}, { 7, 9}, {15, 9}, { 0, 1}, { 8, 1}, { 0, 9}, { 8, 9}, { 4, 5}, {12, 5}, { 4,13}, {12,13}, { 0, 5}, { 8, 5}, { 0,13}, { 8,13}, { 4, 1}, {12, 1}, { 4, 9}, {12, 9}, { 2, 3}, {10, 3}, { 2,11}, {10,11}, { 6, 7}, {14, 7}, { 6,15}, {14,15}, { 2, 7}, {10, 7}, { 2,15}, {10,15}, { 6, 3}, {14, 3}, { 6,11}, {14,11}, { 0, 3}, { 8, 3}, { 0,11}, { 8,11}, { 4, 7}, {12, 7}, { 4,15}, {12,15}, { 0, 7}, { 8, 7}, { 0,15}, { 8,15}, { 4, 3}, {12, 3}, { 4,11}, {12,11}, { 2, 1}, {10, 1}, { 2, 9}, {10, 9}, { 6, 5}, {14, 5}, { 6,13}, {14,13}, { 2, 5}, {10, 5}, { 2,13}, {10,13}, { 6, 1}, {14, 1}, { 6, 9}, {14, 9}, { 1, 0}, { 9, 0}, { 1, 8}, { 9, 8}, { 5, 4}, {13, 4}, { 5,12}, {13,12}, { 1, 4}, { 9, 4}, { 1,12}, { 9,12}, { 5, 0}, {13, 0}, { 5, 8}, {13, 8}, { 3, 2}, {11, 2}, { 3,10}, {11,10}, { 7, 6}, {15, 6}, { 7,14}, {15,14}, { 3, 6}, {11, 6}, { 3,14}, {11,14}, { 7, 2}, {15, 2}, { 7,10}, {15,10}, { 1, 2}, { 9, 2}, { 1,10}, {9,10}, { 5, 6}, {13, 6}, { 5,14}, {13,14}, { 1, 6}, { 9, 6}, { 1,14}, { 9,14}, { 5, 2}, {13, 2}, { 5,10}, {13,10}, { 3, 0}, {11, 0}, { 3, 8}, {11, 8}, { 7, 4}, {15, 4}, { 7,12}, {15,12}, { 3, 4}, {11, 4}, { 3,12}, {11,12}, { 7, 0}, {15, 0}, { 7, 8}, {15, 8},
+{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 4, 4}, {12, 4}, { 4,12}, {12,12}, { 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 4, 0}, {12, 0}, { 4, 8}, {12, 8}, { 2, 2}, {10, 2}, { 2,10}, {10,10}, { 6, 6}, {14, 6}, { 6,14}, {14,14}, { 2, 6}, {10, 6}, { 2,14}, {10,14}, { 6, 2}, {14, 2}, { 6,10}, {14,10}, { 0, 2}, { 8, 2}, { 0,10}, { 8,10}, { 4, 6}, {12, 6}, { 4,14}, {12,14}, { 0, 6}, { 8, 6}, { 0,14}, { 8,14}, { 4, 2}, {12, 2}, { 4,10}, {12,10}, { 2, 0}, {10, 0}, { 2, 8}, {10, 8}, { 6, 4}, {14, 4}, { 6,12}, {14,12}, { 2, 4}, {10, 4}, { 2,12}, {10,12}, { 6, 0}, {14, 0}, { 6, 8}, {14, 8}, { 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 5, 5}, {13, 5}, { 5,13}, {13,13}, { 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9}, { 3, 3}, {11, 3}, { 3,11}, {11,11}, { 7, 7}, {15, 7}, { 7,15}, {15,15}, { 3, 7}, {11, 7}, { 3,15}, {11,15}, { 7, 3}, {15, 3}, { 7,11}, {15,11}, { 1, 3}, { 9, 3}, { 1,11}, { 9,11}, { 5, 7}, {13, 7}, { 5,15}, {13,15}, { 1, 7}, { 9, 7}, { 1,15}, { 9,15}, { 5, 3}, {13, 3}, { 5,11}, {13,11}, { 3, 1}, {11, 1}
+, { 3, 9}, {11, 9}, { 7, 5}, {15, 5}, { 7,13}, {15,13}, { 3, 5}, {11, 5}, { 3,13}, {11,13}, { 7, 1}, {15, 1}, { 7, 9}, {15, 9}, { 0, 1}, { 8, 1}, { 0, 9}, { 8, 9}, { 4, 5}, {12, 5}, { 4,13}, {12,13}, { 0, 5}, { 8, 5}, { 0,13}, { 8,13}, { 4, 1}, {12, 1}, { 4, 9}, {12, 9}, { 2, 3}, {10, 3}, { 2,11}, {10,11}, { 6, 7}, {14, 7}, { 6,15}, {14,15}, { 2, 7}, {10, 7}, { 2,15}, {10,15}, { 6, 3}, {14, 3}, { 6,11}, {14,11}, { 0, 3}, { 8, 3}, { 0,11}, { 8,11}, { 4, 7}, {12, 7}, { 4,15}, {12,15}, { 0, 7}, { 8, 7}, { 0,15}, { 8,15}, { 4, 3}, {12, 3}, { 4,11}, {12,11}, { 2, 1}, {10, 1}, { 2, 9}, {10, 9}, { 6, 5}, {14, 5}, { 6,13}, {14,13}, { 2, 5}, {10, 5}, { 2,13}, {10,13}, { 6, 1}, {14, 1}, { 6, 9}, {14, 9}, { 1, 0}, { 9, 0}, { 1, 8}, { 9, 8}, { 5, 4}, {13, 4}, { 5,12}, {13,12}, { 1, 4}, { 9, 4}, { 1,12}, { 9,12}, { 5, 0}, {13, 0}, { 5, 8}, {13, 8}, { 3, 2}, {11, 2}, { 3,10}, {11,10}, { 7, 6}, {15, 6}, { 7,14}, {15,14}, { 3, 6}, {11, 6}, { 3,14}, {11,14}, { 7, 2}, {15, 2}, { 7,10}, {15,10}, { 1, 2}, { 9, 2}, { 1,10}, { 9,
+10}, { 5, 6}, {13, 6}, { 5,14}, {13,14}, { 1, 6}, { 9, 6}, { 1,14}, { 9,14}, { 5, 2}, {13, 2}, { 5,10}, {13,10}, { 3, 0}, {11, 0}, { 3, 8}, {11, 8}, { 7, 4}, {15, 4}, { 7,12}, {15,12}, { 3, 4}, {11, 4}, { 3,12}, {11,12}, { 7, 0}, {15, 0}, { 7, 8}, {15, 8},
 };
 
 struct vf_priv_s {
@@ -201,6 +204,8 @@ static void filter(struct vf_priv_s *p, uint8_t *dst[3], uint8_t *src[3], int ds
 
     for(j=0; j<3; j++){
         int is_chroma= !!j;
+        if (!dst[j])
+            continue; // HACK avoid crash for Y8 colourspace
         store_slice_c(dst[j], p->temp[j], dst_stride[j], p->temp_stride[j], width>>is_chroma, height>>is_chroma, 8-p->log2_count);
     }
 }
@@ -222,9 +227,10 @@ static int config(struct vf_instance *vf,
         }
         for(i=0; i< (1<priv->log2_count); i++){
             AVCodecContext *avctx_enc;
+            AVDictionary *opts = NULL;
 
             avctx_enc=
-            vf->priv->avctx_enc[i]= avcodec_alloc_context();
+            vf->priv->avctx_enc[i]= avcodec_alloc_context3(NULL);
             avctx_enc->width = width + BLOCK;
             avctx_enc->height = height + BLOCK;
             avctx_enc->time_base= (AVRational){1,25};  // meaningless
@@ -234,7 +240,9 @@ static int config(struct vf_instance *vf,
             avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY;
             avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
             avctx_enc->global_quality= 123;
-            avcodec_open(avctx_enc, enc);
+            av_dict_set(&opts, "no_bitstream", "1", 0);
+            avcodec_open2(avctx_enc, enc, &opts);
+            av_dict_free(&opts);
             assert(avctx_enc->codec);
         }
         vf->priv->frame= avcodec_alloc_frame();
diff --git a/mythtv/external/FFmpeg/libavfilter/sink_buffer.c b/mythtv/external/FFmpeg/libavfilter/sink_buffer.c
index a34cb24d213..9a99b565366 100644
--- a/mythtv/external/FFmpeg/libavfilter/sink_buffer.c
+++ b/mythtv/external/FFmpeg/libavfilter/sink_buffer.c
@@ -44,15 +44,10 @@ AVBufferSinkParams *av_buffersink_params_alloc(void)
 
 AVABufferSinkParams *av_abuffersink_params_alloc(void)
 {
-    static const int sample_fmts[] = { AV_SAMPLE_FMT_NONE };
-    static const int64_t channel_layouts[] = { -1 };
-    AVABufferSinkParams *params = av_malloc(sizeof(AVABufferSinkParams));
+    AVABufferSinkParams *params = av_mallocz(sizeof(AVABufferSinkParams));
 
     if (!params)
         return NULL;
-
-    params->sample_fmts = sample_fmts;
-    params->channel_layouts = channel_layouts;
     return params;
 }
 
@@ -66,6 +61,8 @@ typedef struct {
     /* only used for audio */
     enum AVSampleFormat *sample_fmts;       ///< list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE
     int64_t *channel_layouts;               ///< list of accepted channel layouts, terminated by -1
+    int all_channel_counts;
+    int *sample_rates;                      ///< list of accepted sample rates, terminated by -1
 } BufferSinkContext;
 
 #define FIFO_INIT_SIZE 8
@@ -276,28 +273,56 @@ AVFilter avfilter_vsink_buffersink = {
     .outputs       = NULL,
 };
 
+static int64_t *concat_channels_lists(const int64_t *layouts, const int *counts)
+{
+    int nb_layouts = 0, nb_counts = 0, i;
+    int64_t *list;
+
+    if (layouts)
+        for (; layouts[nb_layouts] != -1; nb_layouts++);
+    if (counts)
+        for (; counts[nb_counts] != -1; nb_counts++);
+    if (nb_counts > INT_MAX - 1 - nb_layouts)
+        return NULL;
+    if (!(list = av_calloc(nb_layouts + nb_counts + 1, sizeof(*list))))
+        return NULL;
+    for (i = 0; i < nb_layouts; i++)
+        list[i] = layouts[i];
+    for (i = 0; i < nb_counts; i++)
+        list[nb_layouts + i] = FF_COUNT2LAYOUT(counts[i]);
+    list[nb_layouts + nb_counts] = -1;
+    return list;
+}
+
 static av_cold int asink_init(AVFilterContext *ctx, const char *args, void *opaque)
 {
     BufferSinkContext *buf = ctx->priv;
     AVABufferSinkParams *params = opaque;
 
     if (params && params->sample_fmts) {
-        buf->sample_fmts     = ff_copy_int_list  (params->sample_fmts);
+        buf->sample_fmts = ff_copy_int_list(params->sample_fmts);
         if (!buf->sample_fmts)
-            goto fail_enomem;
+            return AVERROR(ENOMEM);
+    }
+    if (params && params->sample_rates) {
+        buf->sample_rates = ff_copy_int_list(params->sample_rates);
+        if (!buf->sample_rates)
+            return AVERROR(ENOMEM);
     }
-    if (params && params->channel_layouts) {
-        buf->channel_layouts = ff_copy_int64_list(params->channel_layouts);
+    if (params && (params->channel_layouts || params->channel_counts)) {
+        if (params->all_channel_counts) {
+            av_log(ctx, AV_LOG_ERROR,
+                   "Conflicting all_channel_counts and list in parameters\n");
+            return AVERROR(EINVAL);
+        }
+        buf->channel_layouts = concat_channels_lists(params->channel_layouts,
+                                                     params->channel_counts);
         if (!buf->channel_layouts)
-            goto fail_enomem;
+            return AVERROR(ENOMEM);
     }
-    if (!common_init(ctx))
-        return 0;
-
-fail_enomem:
-    av_freep(&buf->sample_fmts);
-    av_freep(&buf->channel_layouts);
-    return AVERROR(ENOMEM);
+    if (params)
+        buf->all_channel_counts = params->all_channel_counts;
+    return common_init(ctx);
 }
 
 static av_cold void asink_uninit(AVFilterContext *ctx)
@@ -305,6 +330,7 @@ static av_cold void asink_uninit(AVFilterContext *ctx)
     BufferSinkContext *buf = ctx->priv;
 
     av_freep(&buf->sample_fmts);
+    av_freep(&buf->sample_rates);
     av_freep(&buf->channel_layouts);
     common_uninit(ctx);
 }
@@ -316,15 +342,24 @@ static int asink_query_formats(AVFilterContext *ctx)
     AVFilterChannelLayouts *layouts = NULL;
 
     if (buf->sample_fmts) {
-    if (!(formats = ff_make_format_list(buf->sample_fmts)))
-        return AVERROR(ENOMEM);
-    ff_set_common_formats(ctx, formats);
+        if (!(formats = ff_make_format_list(buf->sample_fmts)))
+            return AVERROR(ENOMEM);
+        ff_set_common_formats(ctx, formats);
     }
 
-    if (buf->channel_layouts) {
-    if (!(layouts = avfilter_make_format64_list(buf->channel_layouts)))
-        return AVERROR(ENOMEM);
-    ff_set_common_channel_layouts(ctx, layouts);
+    if (buf->channel_layouts || buf->all_channel_counts) {
+            layouts = buf->all_channel_counts ? ff_all_channel_counts() :
+                      avfilter_make_format64_list(buf->channel_layouts);
+        if (!layouts)
+            return AVERROR(ENOMEM);
+        ff_set_common_channel_layouts(ctx, layouts);
+    }
+
+    if (buf->sample_rates) {
+        formats = ff_make_format_list(buf->sample_rates);
+        if (!formats)
+            return AVERROR(ENOMEM);
+        ff_set_common_samplerates(ctx, formats);
     }
 
     return 0;
diff --git a/mythtv/external/FFmpeg/libavfilter/src_movie.c b/mythtv/external/FFmpeg/libavfilter/src_movie.c
index bd45766641a..ec9131ecabc 100644
--- a/mythtv/external/FFmpeg/libavfilter/src_movie.c
+++ b/mythtv/external/FFmpeg/libavfilter/src_movie.c
@@ -91,13 +91,13 @@ static int movie_request_frame(AVFilterLink *outlink);
 static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec)
 {
     int i, ret, already = 0, stream_id = -1;
-    char type_char, dummy;
+    char type_char[2], dummy;
     AVStream *found = NULL;
     enum AVMediaType type;
 
-    ret = sscanf(spec, "d%[av]%d%c", &type_char, &stream_id, &dummy);
+    ret = sscanf(spec, "d%1[av]%d%c", type_char, &stream_id, &dummy);
     if (ret >= 1 && ret <= 2) {
-        type = type_char == 'v' ? AVMEDIA_TYPE_VIDEO : AVMEDIA_TYPE_AUDIO;
+        type = type_char[0] == 'v' ? AVMEDIA_TYPE_VIDEO : AVMEDIA_TYPE_AUDIO;
         ret = av_find_best_stream(avf, type, stream_id, -1, NULL, 0);
         if (ret < 0) {
             av_log(log, AV_LOG_ERROR, "No %s stream with index '%d' found\n",
diff --git a/mythtv/external/FFmpeg/libavfilter/version.h b/mythtv/external/FFmpeg/libavfilter/version.h
index 9f1f8bfc586..29bc060072a 100644
--- a/mythtv/external/FFmpeg/libavfilter/version.h
+++ b/mythtv/external/FFmpeg/libavfilter/version.h
@@ -29,8 +29,8 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  3
-#define LIBAVFILTER_VERSION_MINOR  32
-#define LIBAVFILTER_VERSION_MICRO 100
+#define LIBAVFILTER_VERSION_MINOR  42
+#define LIBAVFILTER_VERSION_MICRO 103
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
                                                LIBAVFILTER_VERSION_MINOR, \
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_aspect.c b/mythtv/external/FFmpeg/libavfilter/vf_aspect.c
index 7869d228eb1..8e19162cd2d 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_aspect.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_aspect.c
@@ -59,7 +59,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, const AVClass *c
     aspect->class = class;
     av_opt_set_defaults(aspect);
 
-    if (sscanf(args, "%d:%d%c", &q.num, &q.den, &c) == 2) {
+    if (args && sscanf(args, "%d:%d%c", &q.num, &q.den, &c) == 2) {
         aspect->ratio_str = av_strdup(args);
         av_log(ctx, AV_LOG_WARNING,
                "num:den syntax is deprecated, please use num/den or named options instead\n");
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_blend.c b/mythtv/external/FFmpeg/libavfilter/vf_blend.c
new file mode 100644
index 00000000000..27d94b4e4a6
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavfilter/vf_blend.c
@@ -0,0 +1,474 @@
+/*
+ * Copyright (c) 2013 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/imgutils.h"
+#include "libavutil/eval.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixfmt.h"
+#include "avfilter.h"
+#include "bufferqueue.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+#define TOP    0
+#define BOTTOM 1
+
+enum BlendMode {
+    BLEND_UNSET = -1,
+    BLEND_NORMAL,
+    BLEND_ADDITION,
+    BLEND_AND,
+    BLEND_AVERAGE,
+    BLEND_BURN,
+    BLEND_DARKEN,
+    BLEND_DIFFERENCE,
+    BLEND_DIVIDE,
+    BLEND_DODGE,
+    BLEND_EXCLUSION,
+    BLEND_HARDLIGHT,
+    BLEND_LIGHTEN,
+    BLEND_MULTIPLY,
+    BLEND_NEGATION,
+    BLEND_OR,
+    BLEND_OVERLAY,
+    BLEND_PHOENIX,
+    BLEND_PINLIGHT,
+    BLEND_REFLECT,
+    BLEND_SCREEN,
+    BLEND_SOFTLIGHT,
+    BLEND_SUBTRACT,
+    BLEND_VIVIDLIGHT,
+    BLEND_XOR,
+    BLEND_NB
+};
+
+static const char *const var_names[] = {   "X",   "Y",   "W",   "H",   "SW",   "SH",   "T",     "A",        "B",   "TOP",   "BOTTOM",        NULL };
+enum                                   { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_SW, VAR_SH, VAR_T,   VAR_A,      VAR_B, VAR_TOP, VAR_BOTTOM, VAR_VARS_NB };
+
+typedef struct FilterParams {
+    enum BlendMode mode;
+    double values[VAR_VARS_NB];
+    double opacity;
+    AVExpr *e;
+    char *expr_str;
+    void (*blend)(const uint8_t *top, int top_linesize,
+                  const uint8_t *bottom, int bottom_linesize,
+                  uint8_t *dst, int dst_linesize,
+                  int width, int height, struct FilterParams *param);
+} FilterParams;
+
+typedef struct {
+    const AVClass *class;
+    struct FFBufQueue queue_top;
+    struct FFBufQueue queue_bottom;
+    int hsub, vsub;             ///< chroma subsampling values
+    int frame_requested;
+    char *all_expr;
+    enum BlendMode all_mode;
+    double all_opacity;
+
+    FilterParams params[4];
+} BlendContext;
+
+#define OFFSET(x) offsetof(BlendContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption blend_options[] = {
+    { "c0_mode", "set component #0 blend mode", OFFSET(params[0].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},
+    { "c1_mode", "set component #1 blend mode", OFFSET(params[1].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},
+    { "c2_mode", "set component #2 blend mode", OFFSET(params[2].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},
+    { "c3_mode", "set component #3 blend mode", OFFSET(params[3].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},
+    { "all_mode", "set blend mode for all components", OFFSET(all_mode), AV_OPT_TYPE_INT, {.i64=-1},-1, BLEND_NB-1, FLAGS, "mode"},
+    { "addition",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_ADDITION},   0, 0, FLAGS, "mode" },
+    { "and",        "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AND},        0, 0, FLAGS, "mode" },
+    { "average",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AVERAGE},    0, 0, FLAGS, "mode" },
+    { "burn",       "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_BURN},       0, 0, FLAGS, "mode" },
+    { "darken",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DARKEN},     0, 0, FLAGS, "mode" },
+    { "difference", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIFFERENCE}, 0, 0, FLAGS, "mode" },
+    { "divide",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIVIDE},     0, 0, FLAGS, "mode" },
+    { "dodge",      "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DODGE},      0, 0, FLAGS, "mode" },
+    { "exclusion",  "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_EXCLUSION},  0, 0, FLAGS, "mode" },
+    { "hardlight",  "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDLIGHT},  0, 0, FLAGS, "mode" },
+    { "lighten",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_LIGHTEN},    0, 0, FLAGS, "mode" },
+    { "multiply",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_MULTIPLY},   0, 0, FLAGS, "mode" },
+    { "negation",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NEGATION},   0, 0, FLAGS, "mode" },
+    { "normal",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NORMAL},     0, 0, FLAGS, "mode" },
+    { "or",         "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OR},         0, 0, FLAGS, "mode" },
+    { "overlay",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OVERLAY},    0, 0, FLAGS, "mode" },
+    { "phoenix",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PHOENIX},    0, 0, FLAGS, "mode" },
+    { "pinlight",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PINLIGHT},   0, 0, FLAGS, "mode" },
+    { "reflect",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_REFLECT},    0, 0, FLAGS, "mode" },
+    { "screen",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SCREEN},     0, 0, FLAGS, "mode" },
+    { "softlight",  "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SOFTLIGHT},  0, 0, FLAGS, "mode" },
+    { "subtract",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SUBTRACT},   0, 0, FLAGS, "mode" },
+    { "vividlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_VIVIDLIGHT}, 0, 0, FLAGS, "mode" },
+    { "xor",        "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_XOR},        0, 0, FLAGS, "mode" },
+    { "c0_expr",  "set color component #0 expression", OFFSET(params[0].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "c1_expr",  "set color component #1 expression", OFFSET(params[1].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "c2_expr",  "set color component #2 expression", OFFSET(params[2].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "c3_expr",  "set color component #3 expression", OFFSET(params[3].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "all_expr", "set expression for all color components", OFFSET(all_expr), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "c0_opacity",  "set color component #0 opacity", OFFSET(params[0].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
+    { "c1_opacity",  "set color component #1 opacity", OFFSET(params[1].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
+    { "c2_opacity",  "set color component #2 opacity", OFFSET(params[2].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
+    { "c3_opacity",  "set color component #3 opacity", OFFSET(params[3].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
+    { "all_opacity", "set opacity for all color components", OFFSET(all_opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
+    { NULL },
+};
+
+AVFILTER_DEFINE_CLASS(blend);
+
+static void blend_normal(const uint8_t *top, int top_linesize,
+                         const uint8_t *bottom, int bottom_linesize,
+                         uint8_t *dst, int dst_linesize,
+                         int width, int height, FilterParams *param)
+{
+    av_image_copy_plane(dst, dst_linesize, top, top_linesize, width, height);
+}
+
+#define DEFINE_BLEND(name, expr)                                      \
+static void blend_## name(const uint8_t *top, int top_linesize,       \
+                          const uint8_t *bottom, int bottom_linesize, \
+                          uint8_t *dst, int dst_linesize,             \
+                          int width, int height, FilterParams *param) \
+{                                                                     \
+    double opacity = param->opacity;                                  \
+    int i, j;                                                         \
+                                                                      \
+    for (i = 0; i < height; i++) {                                    \
+        for (j = 0; j < width; j++) {                                 \
+            dst[j] = top[j] + ((expr) - top[j]) * opacity;            \
+        }                                                             \
+        dst    += dst_linesize;                                       \
+        top    += top_linesize;                                       \
+        bottom += bottom_linesize;                                    \
+    }                                                                 \
+}
+
+#define A top[j]
+#define B bottom[j]
+
+#define MULTIPLY(x, a, b) (x * ((a * b) / 255))
+#define SCREEN(x, a, b)   (255 - x * ((255 - a) * (255 - b) / 255))
+#define BURN(a, b)        ((a == 0) ? a : FFMAX(0, 255 - ((255 - b) << 8) / a))
+#define DODGE(a, b)       ((a == 255) ? a : FFMIN(255, ((b << 8) / (255 - a))))
+
+DEFINE_BLEND(addition,   FFMIN(255, A + B))
+DEFINE_BLEND(average,    (A + B) / 2)
+DEFINE_BLEND(subtract,   FFMAX(0, A - B))
+DEFINE_BLEND(multiply,   MULTIPLY(1, A, B))
+DEFINE_BLEND(negation,   255 - FFABS(255 - A - B))
+DEFINE_BLEND(difference, FFABS(A - B))
+DEFINE_BLEND(screen,     SCREEN(1, A, B))
+DEFINE_BLEND(overlay,    (A < 128) ? MULTIPLY(2, A, B) : SCREEN(2, A, B))
+DEFINE_BLEND(hardlight,  (B < 128) ? MULTIPLY(2, B, A) : SCREEN(2, B, A))
+DEFINE_BLEND(darken,     FFMIN(A, B))
+DEFINE_BLEND(lighten,    FFMAX(A, B))
+DEFINE_BLEND(divide,     ((float)A / ((float)B) * 255))
+DEFINE_BLEND(dodge,      DODGE(A, B))
+DEFINE_BLEND(burn,       BURN(A, B))
+DEFINE_BLEND(softlight,  (A > 127) ? B + (255 - B) * (A - 127.5) / 127.5 * (0.5 - FFABS(B - 127.5) / 255): B - B * ((127.5 - A) / 127.5) * (0.5 - FFABS(B - 127.5)/255))
+DEFINE_BLEND(exclusion,  A + B - 2 * A * B / 255)
+DEFINE_BLEND(pinlight,   (B < 128) ? FFMIN(A, 2 * B) : FFMAX(A, 2 * (B - 128)))
+DEFINE_BLEND(phoenix,    FFMIN(A, B) - FFMAX(A, B) + 255)
+DEFINE_BLEND(reflect,    (B == 255) ? B : FFMIN(255, (A * A / (255 - B))))
+DEFINE_BLEND(and,        A & B)
+DEFINE_BLEND(or,         A | B)
+DEFINE_BLEND(xor,        A ^ B)
+DEFINE_BLEND(vividlight, (B < 128) ? BURN(A, 2 * B) : DODGE(A, 2 * (B - 128)))
+
+static void blend_expr(const uint8_t *top, int top_linesize,
+                       const uint8_t *bottom, int bottom_linesize,
+                       uint8_t *dst, int dst_linesize,
+                       int width, int height,
+                       FilterParams *param)
+{
+    AVExpr *e = param->e;
+    double *values = param->values;
+    int y, x;
+
+    for (y = 0; y < height; y++) {
+        values[VAR_Y] = y;
+        for (x = 0; x < width; x++) {
+            values[VAR_X]      = x;
+            values[VAR_TOP]    = values[VAR_A] = top[x];
+            values[VAR_BOTTOM] = values[VAR_B] = bottom[x];
+            dst[x] = av_expr_eval(e, values, NULL);
+        }
+        dst    += dst_linesize;
+        top    += top_linesize;
+        bottom += bottom_linesize;
+    }
+}
+
+static av_cold int init(AVFilterContext *ctx, const char *args)
+{
+    BlendContext *b = ctx->priv;
+    int ret, plane;
+
+    b->class = &blend_class;
+    av_opt_set_defaults(b);
+
+    if ((ret = av_set_options_string(b, args, "=", ":")) < 0)
+        return ret;
+
+    for (plane = 0; plane < FF_ARRAY_ELEMS(b->params); plane++) {
+        FilterParams *param = &b->params[plane];
+
+        if (b->all_mode >= 0)
+            param->mode = b->all_mode;
+        if (b->all_opacity < 1)
+            param->opacity = b->all_opacity;
+
+        switch (param->mode) {
+        case BLEND_ADDITION:   param->blend = blend_addition;   break;
+        case BLEND_AND:        param->blend = blend_and;        break;
+        case BLEND_AVERAGE:    param->blend = blend_average;    break;
+        case BLEND_BURN:       param->blend = blend_burn;       break;
+        case BLEND_DARKEN:     param->blend = blend_darken;     break;
+        case BLEND_DIFFERENCE: param->blend = blend_difference; break;
+        case BLEND_DIVIDE:     param->blend = blend_divide;     break;
+        case BLEND_DODGE:      param->blend = blend_dodge;      break;
+        case BLEND_EXCLUSION:  param->blend = blend_exclusion;  break;
+        case BLEND_HARDLIGHT:  param->blend = blend_hardlight;  break;
+        case BLEND_LIGHTEN:    param->blend = blend_lighten;    break;
+        case BLEND_MULTIPLY:   param->blend = blend_multiply;   break;
+        case BLEND_NEGATION:   param->blend = blend_negation;   break;
+        case BLEND_NORMAL:     param->blend = blend_normal;     break;
+        case BLEND_OR:         param->blend = blend_or;         break;
+        case BLEND_OVERLAY:    param->blend = blend_overlay;    break;
+        case BLEND_PHOENIX:    param->blend = blend_phoenix;    break;
+        case BLEND_PINLIGHT:   param->blend = blend_pinlight;   break;
+        case BLEND_REFLECT:    param->blend = blend_reflect;    break;
+        case BLEND_SCREEN:     param->blend = blend_screen;     break;
+        case BLEND_SOFTLIGHT:  param->blend = blend_softlight;  break;
+        case BLEND_SUBTRACT:   param->blend = blend_subtract;   break;
+        case BLEND_VIVIDLIGHT: param->blend = blend_vividlight; break;
+        case BLEND_XOR:        param->blend = blend_xor;        break;
+        }
+
+        if (b->all_expr && !param->expr_str) {
+            param->expr_str = av_strdup(b->all_expr);
+            if (!param->expr_str)
+                return AVERROR(ENOMEM);
+        }
+        if (param->expr_str) {
+            ret = av_expr_parse(¶m->e, param->expr_str, var_names,
+                                NULL, NULL, NULL, NULL, 0, ctx);
+            if (ret < 0)
+                return ret;
+            param->blend = blend_expr;
+        }
+    }
+
+    return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+    static const enum AVPixelFormat pix_fmts[] = {
+        AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
+        AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
+        AV_PIX_FMT_GBRP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE
+    };
+
+    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+    return 0;
+}
+
+static int config_output(AVFilterLink *outlink)
+{
+    AVFilterContext *ctx = outlink->src;
+    AVFilterLink *toplink = ctx->inputs[TOP];
+    AVFilterLink *bottomlink = ctx->inputs[BOTTOM];
+
+    if (toplink->format != bottomlink->format) {
+        av_log(ctx, AV_LOG_ERROR, "inputs must be of same pixel format\n");
+        return AVERROR(EINVAL);
+    }
+    if (toplink->w                        != bottomlink->w ||
+        toplink->h                        != bottomlink->h ||
+        toplink->sample_aspect_ratio.num != bottomlink->sample_aspect_ratio.num ||
+        toplink->sample_aspect_ratio.den != bottomlink->sample_aspect_ratio.den) {
+        av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
+               "(size %dx%d, SAR %d:%d) do not match the corresponding "
+               "second input link %s parameters (%dx%d, SAR %d:%d)\n",
+               ctx->input_pads[TOP].name, toplink->w, toplink->h,
+               toplink->sample_aspect_ratio.num,
+               toplink->sample_aspect_ratio.den,
+               ctx->input_pads[BOTTOM].name, bottomlink->w, bottomlink->h,
+               bottomlink->sample_aspect_ratio.num,
+               bottomlink->sample_aspect_ratio.den);
+        return AVERROR(EINVAL);
+    }
+
+    outlink->w = toplink->w;
+    outlink->h = bottomlink->h;
+    outlink->time_base = toplink->time_base;
+    outlink->sample_aspect_ratio = toplink->sample_aspect_ratio;
+    outlink->frame_rate = toplink->frame_rate;
+    return 0;
+}
+
+static int config_input_top(AVFilterLink *inlink)
+{
+    BlendContext *b = inlink->dst->priv;
+    const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
+
+    b->hsub = pix_desc->log2_chroma_w;
+    b->vsub = pix_desc->log2_chroma_h;
+    return 0;
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+    BlendContext *b = ctx->priv;
+    int i;
+
+    av_opt_free(b);
+    ff_bufqueue_discard_all(&b->queue_top);
+    ff_bufqueue_discard_all(&b->queue_bottom);
+
+    for (i = 0; i < FF_ARRAY_ELEMS(b->params); i++)
+        av_expr_free(b->params[i].e);
+}
+
+static int request_frame(AVFilterLink *outlink)
+{
+    AVFilterContext *ctx = outlink->src;
+    BlendContext *b = ctx->priv;
+    int in, ret;
+
+    b->frame_requested = 1;
+    while (b->frame_requested) {
+        in = ff_bufqueue_peek(&b->queue_top, TOP) ? BOTTOM : TOP;
+        ret = ff_request_frame(ctx->inputs[in]);
+        if (ret < 0)
+            return ret;
+    }
+    return 0;
+}
+
+static void blend_frame(AVFilterContext *ctx,
+                        AVFilterBufferRef *top_buf,
+                        AVFilterBufferRef *bottom_buf,
+                        AVFilterBufferRef *dst_buf)
+{
+    BlendContext *b = ctx->priv;
+    AVFilterLink *inlink = ctx->inputs[0];
+    FilterParams *param;
+    int plane;
+
+    for (plane = 0; dst_buf->data[plane]; plane++) {
+        int hsub = plane == 1 || plane == 2 ? b->hsub : 0;
+        int vsub = plane == 1 || plane == 2 ? b->vsub : 0;
+        int outw = dst_buf->video->w >> hsub;
+        int outh = dst_buf->video->h >> vsub;
+        uint8_t *dst    = dst_buf->data[plane];
+        uint8_t *top    = top_buf->data[plane];
+        uint8_t *bottom = bottom_buf->data[plane];
+
+        param = &b->params[plane];
+        param->values[VAR_T]  = dst_buf->pts == AV_NOPTS_VALUE ? NAN : dst_buf->pts * av_q2d(inlink->time_base);
+        param->values[VAR_W]  = outw;
+        param->values[VAR_H]  = outh;
+        param->values[VAR_SW] = outw / dst_buf->video->w;
+        param->values[VAR_SH] = outh / dst_buf->video->h;
+        param->blend(top, top_buf->linesize[plane],
+                     bottom, bottom_buf->linesize[plane],
+                     dst, dst_buf->linesize[plane], outw, outh, param);
+    }
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *buf)
+{
+    AVFilterContext *ctx = inlink->dst;
+    AVFilterLink *outlink = ctx->outputs[0];
+    BlendContext *b = ctx->priv;
+
+    int ret = 0;
+    int is_bottom = (inlink == ctx->inputs[BOTTOM]);
+    struct FFBufQueue *queue =
+        (is_bottom ? &b->queue_bottom : &b->queue_top);
+    ff_bufqueue_add(ctx, queue, buf);
+
+    while (1) {
+        AVFilterBufferRef *top_buf, *bottom_buf, *out_buf;
+
+        if (!ff_bufqueue_peek(&b->queue_top, TOP) ||
+            !ff_bufqueue_peek(&b->queue_bottom, BOTTOM)) break;
+
+        top_buf = ff_bufqueue_get(&b->queue_top);
+        bottom_buf = ff_bufqueue_get(&b->queue_bottom);
+
+        out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
+                                      outlink->w, outlink->h);
+        if (!out_buf) {
+            return AVERROR(ENOMEM);
+        }
+        avfilter_copy_buffer_ref_props(out_buf, top_buf);
+
+        b->frame_requested = 0;
+        blend_frame(ctx, top_buf, bottom_buf, out_buf);
+        ret = ff_filter_frame(ctx->outputs[0], out_buf);
+        avfilter_unref_buffer(top_buf);
+        avfilter_unref_buffer(bottom_buf);
+    }
+    return ret;
+}
+
+static const AVFilterPad blend_inputs[] = {
+    {
+        .name             = "top",
+        .type             = AVMEDIA_TYPE_VIDEO,
+        .config_props     = config_input_top,
+        .filter_frame     = filter_frame,
+        .min_perms        = AV_PERM_READ | AV_PERM_PRESERVE,
+    },{
+        .name             = "bottom",
+        .type             = AVMEDIA_TYPE_VIDEO,
+        .filter_frame     = filter_frame,
+        .min_perms        = AV_PERM_READ | AV_PERM_PRESERVE,
+    },
+    { NULL }
+};
+
+static const AVFilterPad blend_outputs[] = {
+    {
+        .name          = "default",
+        .type          = AVMEDIA_TYPE_VIDEO,
+        .config_props  = config_output,
+        .request_frame = request_frame,
+    },
+    { NULL }
+};
+
+AVFilter avfilter_vf_blend = {
+    .name          = "blend",
+    .description   = NULL_IF_CONFIG_SMALL("Blend two video frames into each other."),
+    .init          = init,
+    .uninit        = uninit,
+    .priv_size     = sizeof(BlendContext),
+    .query_formats = query_formats,
+    .inputs        = blend_inputs,
+    .outputs       = blend_outputs,
+    .priv_class    = &blend_class,
+};
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_boxblur.c b/mythtv/external/FFmpeg/libavfilter/vf_boxblur.c
index 9ee3ea5bc73..a4ac50afd53 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_boxblur.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_boxblur.c
@@ -28,6 +28,7 @@
 #include "libavutil/avstring.h"
 #include "libavutil/common.h"
 #include "libavutil/eval.h"
+#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "formats.h"
@@ -57,15 +58,14 @@ enum var_name {
 typedef struct {
     int radius;
     int power;
+    char *radius_expr;
 } FilterParam;
 
 typedef struct {
+    const AVClass *class;
     FilterParam luma_param;
     FilterParam chroma_param;
     FilterParam alpha_param;
-    char luma_radius_expr  [256];
-    char chroma_radius_expr[256];
-    char alpha_radius_expr [256];
 
     int hsub, vsub;
     int radius[4];
@@ -73,6 +73,30 @@ typedef struct {
     uint8_t *temp[2]; ///< temporary buffer used in blur_power()
 } BoxBlurContext;
 
+#define OFFSET(x) offsetof(BoxBlurContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption boxblur_options[] = {
+    { "luma_radius", "set luma radius", OFFSET(luma_param.radius_expr), AV_OPT_TYPE_STRING, {.str="2"}, .flags = FLAGS },
+    { "lr",          "set luma radius", OFFSET(luma_param.radius_expr), AV_OPT_TYPE_STRING, {.str="2"}, .flags = FLAGS },
+    { "luma_power",  "set luma power",  OFFSET(luma_param.power), AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags = FLAGS },
+    { "lp",          "set luma power",  OFFSET(luma_param.power), AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags = FLAGS },
+
+    { "chroma_radius", "set chroma radius", OFFSET(chroma_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+    { "cr",            "set chroma radius", OFFSET(chroma_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+    { "chroma_power",  "set chroma power",  OFFSET(chroma_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+    { "cp",            "set chroma power",  OFFSET(chroma_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+
+    { "alpha_radius", "set alpha radius", OFFSET(alpha_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+    { "ar",           "set alpha radius", OFFSET(alpha_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+    { "alpha_power",  "set alpha power",  OFFSET(alpha_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+    { "ap",           "set alpha power",  OFFSET(alpha_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(boxblur);
+
 #define Y 0
 #define U 1
 #define V 2
@@ -81,35 +105,36 @@ typedef struct {
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     BoxBlurContext *boxblur = ctx->priv;
-    int e;
+    static const char *shorthand[] = {
+        "luma_radius",   "luma_power",
+        "chroma_radius", "chroma_power",
+        "alpha_radius",  "alpha_power",
+        NULL
+    };
+    int ret;
 
-    if (!args) {
-        av_log(ctx, AV_LOG_ERROR,
-               "Filter expects 2 or 4 or 6 arguments, none provided\n");
-        return AVERROR(EINVAL);
-    }
+    boxblur->class = &boxblur_class;
+    av_opt_set_defaults(boxblur);
 
-    e = sscanf(args, "%255[^:]:%d:%255[^:]:%d:%255[^:]:%d",
-               boxblur->luma_radius_expr,   &boxblur->luma_param  .power,
-               boxblur->chroma_radius_expr, &boxblur->chroma_param.power,
-               boxblur->alpha_radius_expr,  &boxblur->alpha_param .power);
+    if ((ret = av_opt_set_from_string(boxblur, args, shorthand, "=", ":")) < 0)
+        return ret;
 
-    if (e != 2 && e != 4 && e != 6) {
-        av_log(ctx, AV_LOG_ERROR,
-               "Filter expects 2 or 4 or 6 params, provided %d\n", e);
-        return AVERROR(EINVAL);
+    /* fill missing params */
+    if (!boxblur->chroma_param.radius_expr) {
+        boxblur->chroma_param.radius_expr = av_strdup(boxblur->luma_param.radius_expr);
+        if (!boxblur->chroma_param.radius_expr)
+            return AVERROR(ENOMEM);
     }
-
-    if (e < 4) {
+    if (boxblur->chroma_param.power < 0)
         boxblur->chroma_param.power = boxblur->luma_param.power;
-        av_strlcpy(boxblur->chroma_radius_expr, boxblur->luma_radius_expr,
-                   sizeof(boxblur->chroma_radius_expr));
+
+    if (!boxblur->alpha_param.radius_expr) {
+        boxblur->alpha_param.radius_expr = av_strdup(boxblur->luma_param.radius_expr);
+        if (!boxblur->alpha_param.radius_expr)
+            return AVERROR(ENOMEM);
     }
-    if (e < 6) {
+    if (boxblur->alpha_param.power < 0)
         boxblur->alpha_param.power = boxblur->luma_param.power;
-        av_strlcpy(boxblur->alpha_radius_expr, boxblur->luma_radius_expr,
-                   sizeof(boxblur->alpha_radius_expr));
-    }
 
     return 0;
 }
@@ -120,6 +145,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 
     av_freep(&boxblur->temp[0]);
     av_freep(&boxblur->temp[1]);
+    av_opt_free(boxblur);
 }
 
 static int query_formats(AVFilterContext *ctx)
@@ -163,7 +189,7 @@ static int config_input(AVFilterLink *inlink)
     var_values[VAR_VSUB]    = 1<vsub;
 
 #define EVAL_RADIUS_EXPR(comp)                                          \
-    expr = boxblur->comp##_radius_expr;                                 \
+    expr = boxblur->comp##_param.radius_expr;                           \
     ret = av_expr_parse_and_eval(&res, expr, var_names, var_values,     \
                                  NULL, NULL, NULL, NULL, NULL, 0, ctx); \
     boxblur->comp##_param.radius = res;                                 \
@@ -366,4 +392,6 @@ AVFilter avfilter_vf_boxblur = {
 
     .inputs    = avfilter_vf_boxblur_inputs,
     .outputs   = avfilter_vf_boxblur_outputs,
+
+    .priv_class = &boxblur_class,
 };
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_crop.c b/mythtv/external/FFmpeg/libavfilter/vf_crop.c
index 1ff949327ac..8df95955501 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_crop.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_crop.c
@@ -102,7 +102,7 @@ static const AVOption crop_options[] = {
     { "w",           "set the width crop area expression",   OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS },
     { "out_h",       "set the height crop area expression",  OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS },
     { "h",           "set the height crop area expression",  OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS },
-    { "keep_aspect", "force packed RGB in input and output", OFFSET(keep_aspect), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
+    { "keep_aspect", "keep aspect ratio",                    OFFSET(keep_aspect), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
     {NULL}
 };
 
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_decimate.c b/mythtv/external/FFmpeg/libavfilter/vf_decimate.c
index b81c3ee8f27..c5761adcfad 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_decimate.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_decimate.c
@@ -24,6 +24,7 @@
  * Rich Felker.
  */
 
+#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/timestamp.h"
 #include "libavcodec/dsputil.h"
@@ -33,6 +34,7 @@
 #include "video.h"
 
 typedef struct {
+    const AVClass *class;
     int lo, hi;                    ///< lower and higher threshold number of differences
                                    ///< values for 8x8 blocks
 
@@ -50,6 +52,20 @@ typedef struct {
     AVCodecContext *avctx;         ///< codec context required for the DSPContext
 } DecimateContext;
 
+#define OFFSET(x) offsetof(DecimateContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption decimate_options[] = {
+    { "max",  "set the maximum number of consecutive dropped frames (positive), or the minimum interval between dropped frames (negative)",
+      OFFSET(max_drop_count), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS },
+    { "hi",   "set high dropping threshold", OFFSET(hi), AV_OPT_TYPE_INT, {.i64=64*12}, INT_MIN, INT_MAX, FLAGS },
+    { "lo",   "set low dropping threshold", OFFSET(lo), AV_OPT_TYPE_INT, {.i64=64*5}, INT_MIN, INT_MAX, FLAGS },
+    { "frac", "set fraction dropping threshold",  OFFSET(frac), AV_OPT_TYPE_FLOAT, {.dbl=0.33}, 0, 1, FLAGS },
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(decimate);
+
 /**
  * Return 1 if the two planes are different, 0 otherwise.
  */
@@ -63,7 +79,7 @@ static int diff_planes(AVFilterContext *ctx,
     int x, y;
     int d, c = 0;
     int t = (w/16)*(h/16)*decimate->frac;
-    DCTELEM block[8*8];
+    int16_t block[8*8];
 
     /* compute difference for blocks of 8x8 bytes */
     for (y = 0; y < h-7; y += 4) {
@@ -116,29 +132,14 @@ static int decimate_frame(AVFilterContext *ctx,
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     DecimateContext *decimate = ctx->priv;
+    static const char *shorthand[] = { "max", "hi", "lo", "frac", NULL };
+    int ret;
 
-    /* set default values */
-    decimate->drop_count = decimate->max_drop_count = 0;
-    decimate->lo = 64*5;
-    decimate->hi = 64*12;
-    decimate->frac = 0.33;
-
-    if (args) {
-        char c1, c2, c3, c4;
-        int n = sscanf(args, "%d%c%d%c%d%c%f%c",
-                       &decimate->max_drop_count, &c1,
-                       &decimate->hi, &c2, &decimate->lo, &c3,
-                       &decimate->frac, &c4);
-        if (n != 1 &&
-            (n != 3 || c1 != ':') &&
-            (n != 5 || c1 != ':' || c2 != ':') &&
-            (n != 7 || c1 != ':' || c2 != ':' || c3 != ':')) {
-            av_log(ctx, AV_LOG_ERROR,
-                   "Invalid syntax for argument '%s': "
-                   "must be in the form 'max:hi:lo:frac'\n", args);
-            return AVERROR(EINVAL);
-        }
-    }
+    decimate->class = &decimate_class;
+    av_opt_set_defaults(decimate);
+
+    if ((ret = av_opt_set_from_string(decimate, args, shorthand, "=", ":")) < 0)
+        return ret;
 
     av_log(ctx, AV_LOG_VERBOSE, "max_drop_count:%d hi:%d lo:%d frac:%f\n",
            decimate->max_drop_count, decimate->hi, decimate->lo, decimate->frac);
@@ -156,6 +157,7 @@ static av_cold void uninit(AVFilterContext *ctx)
     DecimateContext *decimate = ctx->priv;
     avfilter_unref_bufferp(&decimate->ref);
     avcodec_close(decimate->avctx);
+    av_opt_free(decimate);
     av_freep(&decimate->avctx);
 }
 
@@ -260,4 +262,5 @@ AVFilter avfilter_vf_decimate = {
     .query_formats = query_formats,
     .inputs        = decimate_inputs,
     .outputs       = decimate_outputs,
+    .priv_class    = &decimate_class,
 };
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_delogo.c b/mythtv/external/FFmpeg/libavfilter/vf_delogo.c
index 9a22a63b631..bf0ac62117c 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_delogo.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_delogo.c
@@ -83,8 +83,8 @@ static void apply_delogo(uint8_t *dst, int dst_linesize,
     if (!direct)
         av_image_copy_plane(dst, dst_linesize, src, src_linesize, w, h);
 
-    dst += (logo_y1+1)*dst_linesize;
-    src += (logo_y1+1)*src_linesize;
+    dst += (logo_y1 + 1) * dst_linesize;
+    src += (logo_y1 + 1) * src_linesize;
 
     for (y = logo_y1+1; y < logo_y2-1; y++) {
         for (x = logo_x1+1,
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_deshake.c b/mythtv/external/FFmpeg/libavfilter/vf_deshake.c
index c03919c96db..26f92f4dff0 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_deshake.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_deshake.c
@@ -55,6 +55,7 @@
 #include "video.h"
 #include "libavutil/common.h"
 #include "libavutil/mem.h"
+#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavcodec/dsputil.h"
 
@@ -86,7 +87,7 @@ typedef struct {
 } Transform;
 
 typedef struct {
-    AVClass av_class;
+    const AVClass *class;
     AVFilterBufferRef *ref;    ///< Previous frame
     int rx;                    ///< Maximum horizontal shift
     int ry;                    ///< Maximum vertical shift
@@ -104,8 +105,35 @@ typedef struct {
     int ch;
     int cx;
     int cy;
+    char *filename;            ///< Motion search detailed log filename
 } DeshakeContext;
 
+#define OFFSET(x) offsetof(DeshakeContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption deshake_options[] = {
+    { "x", "set x for the rectangular search area",      OFFSET(cx), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+    { "y", "set y for the rectangular search area",      OFFSET(cy), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+    { "w", "set width for the rectangular search area",  OFFSET(cw), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+    { "h", "set height for the rectangular search area", OFFSET(ch), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+    { "rx", "set x for the rectangular search area",     OFFSET(rx), AV_OPT_TYPE_INT, {.i64=16}, 0, 64, .flags = FLAGS },
+    { "ry", "set y for the rectangular search area",     OFFSET(ry), AV_OPT_TYPE_INT, {.i64=16}, 0, 64, .flags = FLAGS },
+    { "edge", "set edge mode", OFFSET(edge), AV_OPT_TYPE_INT, {.i64=FILL_MIRROR}, FILL_BLANK, FILL_COUNT-1, FLAGS, "edge"},
+        { "blank",    "fill zeroes at blank locations",         0, AV_OPT_TYPE_CONST, {.i64=FILL_BLANK},    INT_MIN, INT_MAX, FLAGS, "edge" },
+        { "original", "original image at blank locations",      0, AV_OPT_TYPE_CONST, {.i64=FILL_ORIGINAL}, INT_MIN, INT_MAX, FLAGS, "edge" },
+        { "clamp",    "extruded edge value at blank locations", 0, AV_OPT_TYPE_CONST, {.i64=FILL_CLAMP},    INT_MIN, INT_MAX, FLAGS, "edge" },
+        { "mirror",   "mirrored edge at blank locations",       0, AV_OPT_TYPE_CONST, {.i64=FILL_MIRROR},   INT_MIN, INT_MAX, FLAGS, "edge" },
+    { "blocksize", "set motion search blocksize",       OFFSET(blocksize), AV_OPT_TYPE_INT, {.i64=8},   4, 128, .flags = FLAGS },
+    { "contrast",  "set contrast threshold for blocks", OFFSET(contrast),  AV_OPT_TYPE_INT, {.i64=125}, 1, 255, .flags = FLAGS },
+    { "search",  "set search strategy", OFFSET(search), AV_OPT_TYPE_INT, {.i64=EXHAUSTIVE}, EXHAUSTIVE, SEARCH_COUNT-1, FLAGS, "smode" },
+        { "exhaustive", "exhaustive search",      0, AV_OPT_TYPE_CONST, {.i64=EXHAUSTIVE},       INT_MIN, INT_MAX, FLAGS, "smode" },
+        { "less",       "less exhaustive search", 0, AV_OPT_TYPE_CONST, {.i64=SMART_EXHAUSTIVE}, INT_MIN, INT_MAX, FLAGS, "smode" },
+    { "filename", "set motion search detailed log file name", OFFSET(filename), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(deshake);
+
 static int cmp(const double *a, const double *b)
 {
     return *a < *b ? -1 : ( *a > *b ? 1 : 0 );
@@ -334,40 +362,28 @@ static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2,
 
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
+    int ret;
     DeshakeContext *deshake = ctx->priv;
-    char filename[256] = {0};
-
-    deshake->rx = 16;
-    deshake->ry = 16;
-    deshake->edge = FILL_MIRROR;
-    deshake->blocksize = 8;
-    deshake->contrast = 125;
-    deshake->search = EXHAUSTIVE;
-    deshake->refcount = 20;
-
-    deshake->cw = -1;
-    deshake->ch = -1;
-    deshake->cx = -1;
-    deshake->cy = -1;
-
-    if (args) {
-        sscanf(args, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%255s",
-               &deshake->cx, &deshake->cy, &deshake->cw, &deshake->ch,
-               &deshake->rx, &deshake->ry, &deshake->edge,
-               &deshake->blocksize, &deshake->contrast, &deshake->search, filename);
-
-        deshake->blocksize /= 2;
-
-        deshake->rx = av_clip(deshake->rx, 0, 64);
-        deshake->ry = av_clip(deshake->ry, 0, 64);
-        deshake->edge = av_clip(deshake->edge, FILL_BLANK, FILL_COUNT - 1);
-        deshake->blocksize = av_clip(deshake->blocksize, 4, 128);
-        deshake->contrast = av_clip(deshake->contrast, 1, 255);
-        deshake->search = av_clip(deshake->search, EXHAUSTIVE, SEARCH_COUNT - 1);
+    static const char *shorthand[] = {
+        "x", "y", "w", "h", "rx", "ry", "edge",
+        "blocksize", "contrast", "search", "filename",
+        NULL
+    };
 
-    }
-    if (*filename)
-        deshake->fp = fopen(filename, "w");
+    deshake->refcount = 20; // XXX: add to options?
+
+    deshake->class = &deshake_class;
+    av_opt_set_defaults(deshake);
+
+    ret = av_opt_set_from_string(deshake, args, shorthand, "=", ":");
+    if (ret < 0)
+        return ret;
+
+    deshake->blocksize /= 2;
+    deshake->blocksize = av_clip(deshake->blocksize, 4, 128);
+
+    if (deshake->filename)
+        deshake->fp = fopen(deshake->filename, "w");
     if (deshake->fp)
         fwrite("Ori x, Avg x, Fin x, Ori y, Avg y, Fin y, Ori angle, Avg angle, Fin angle, Ori zoom, Avg zoom, Fin zoom\n", sizeof(char), 104, deshake->fp);
 
@@ -424,6 +440,7 @@ static av_cold void uninit(AVFilterContext *ctx)
     if (deshake->avctx)
         avcodec_close(deshake->avctx);
     av_freep(&deshake->avctx);
+    av_opt_free(deshake);
 }
 
 static int filter_frame(AVFilterLink *link, AVFilterBufferRef *in)
@@ -565,4 +582,5 @@ AVFilter avfilter_vf_deshake = {
     .query_formats = query_formats,
     .inputs        = deshake_inputs,
     .outputs       = deshake_outputs,
+    .priv_class    = &deshake_class,
 };
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_drawtext.c b/mythtv/external/FFmpeg/libavfilter/vf_drawtext.c
index 53a60b16797..2358e35c26a 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_drawtext.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_drawtext.c
@@ -188,7 +188,7 @@ static const AVOption drawtext_options[]= {
 {"basetime", "set base time",        OFFSET(basetime),           AV_OPT_TYPE_INT64,  {.i64=AV_NOPTS_VALUE}, INT64_MIN, INT64_MAX , FLAGS},
 {"draw",     "if false do not draw", OFFSET(draw_expr),          AV_OPT_TYPE_STRING, {.str="1"},   CHAR_MIN, CHAR_MAX, FLAGS},
 
-{"expansion","set the expansion mode", OFFSET(exp_mode),         AV_OPT_TYPE_INT,    {.i64=EXP_STRFTIME}, 0,        2, FLAGS, "expansion"},
+{"expansion","set the expansion mode", OFFSET(exp_mode),         AV_OPT_TYPE_INT,    {.i64=EXP_NORMAL},   0,        2, FLAGS, "expansion"},
 {"none",     "set no expansion",     OFFSET(exp_mode),           AV_OPT_TYPE_CONST,  {.i64=EXP_NONE},     0,        0, FLAGS, "expansion"},
 {"normal",   "set normal expansion", OFFSET(exp_mode),           AV_OPT_TYPE_CONST,  {.i64=EXP_NORMAL},   0,        0, FLAGS, "expansion"},
 {"strftime", "set strftime expansion (deprecated)", OFFSET(exp_mode), AV_OPT_TYPE_CONST, {.i64=EXP_STRFTIME}, 0,    0, FLAGS, "expansion"},
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_fade.c b/mythtv/external/FFmpeg/libavfilter/vf_fade.c
index 5be0ec144ac..df222747be8 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_fade.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_fade.c
@@ -78,41 +78,14 @@ AVFILTER_DEFINE_CLASS(fade);
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     FadeContext *fade = ctx->priv;
-    int ret = 0;
-    char *args1, *expr, *bufptr = NULL;
+    static const char *shorthand[] = { "type", "start_frame", "nb_frames", NULL };
+    int ret;
 
     fade->class = &fade_class;
     av_opt_set_defaults(fade);
 
-    if (!(args1 = av_strdup(args))) {
-        ret = AVERROR(ENOMEM);
-        goto end;
-    }
-
-    if (expr = av_strtok(args1, ":", &bufptr)) {
-        av_free(fade->type);
-        if (!(fade->type = av_strdup(expr))) {
-            ret = AVERROR(ENOMEM);
-            goto end;
-        }
-    }
-    if (expr = av_strtok(NULL, ":", &bufptr)) {
-        if ((ret = av_opt_set(fade, "start_frame", expr, 0)) < 0) {
-            av_log(ctx, AV_LOG_ERROR,
-                   "Invalid value '%s' for start_frame option\n", expr);
-            goto end;
-        }
-    }
-    if (expr = av_strtok(NULL, ":", &bufptr)) {
-        if ((ret = av_opt_set(fade, "nb_frames", expr, 0)) < 0) {
-            av_log(ctx, AV_LOG_ERROR,
-                   "Invalid value '%s' for nb_frames option\n", expr);
-            goto end;
-        }
-    }
-
-    if (bufptr && (ret = av_set_options_string(fade, bufptr, "=", ":")) < 0)
-        goto end;
+    if ((ret = av_opt_set_from_string(fade, args, shorthand, "=", ":")) < 0)
+        return ret;
 
     fade->fade_per_frame = (1 << 16) / fade->nb_frames;
     if (!strcmp(fade->type, "in"))
@@ -123,25 +96,21 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     } else {
         av_log(ctx, AV_LOG_ERROR,
                "Type argument must be 'in' or 'out' but '%s' was specified\n", fade->type);
-        ret = AVERROR(EINVAL);
-        goto end;
+        return AVERROR(EINVAL);
     }
     fade->stop_frame = fade->start_frame + fade->nb_frames;
 
     av_log(ctx, AV_LOG_VERBOSE,
            "type:%s start_frame:%d nb_frames:%d alpha:%d\n",
            fade->type, fade->start_frame, fade->nb_frames, fade->alpha);
-
-end:
-    av_free(args1);
-    return ret;
+    return 0;
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
 {
     FadeContext *fade = ctx->priv;
 
-    av_freep(&fade->type);
+    av_opt_free(fade);
 }
 
 static int query_formats(AVFilterContext *ctx)
@@ -151,7 +120,7 @@ static int query_formats(AVFilterContext *ctx)
         AV_PIX_FMT_YUV411P,  AV_PIX_FMT_YUV410P,
         AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
         AV_PIX_FMT_YUV440P,  AV_PIX_FMT_YUVJ440P,
-        AV_PIX_FMT_YUVA420P,
+        AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P,
         AV_PIX_FMT_RGB24,    AV_PIX_FMT_BGR24,
         AV_PIX_FMT_ARGB,     AV_PIX_FMT_ABGR,
         AV_PIX_FMT_RGBA,     AV_PIX_FMT_BGRA,
@@ -169,13 +138,6 @@ const static enum AVPixelFormat studio_level_pix_fmts[] = {
     AV_PIX_FMT_NONE
 };
 
-static enum AVPixelFormat alpha_pix_fmts[] = {
-    AV_PIX_FMT_YUVA420P,
-    AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR,
-    AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA,
-    AV_PIX_FMT_NONE
-};
-
 static int config_props(AVFilterLink *inlink)
 {
     FadeContext *fade = inlink->dst->priv;
@@ -185,7 +147,7 @@ static int config_props(AVFilterLink *inlink)
     fade->vsub = pixdesc->log2_chroma_h;
 
     fade->bpp = av_get_bits_per_pixel(pixdesc) >> 3;
-    fade->alpha = fade->alpha ? ff_fmt_is_in(inlink->format, alpha_pix_fmts) : 0;
+    fade->alpha &= pixdesc->flags & PIX_FMT_ALPHA;
     fade->is_packed_rgb = ff_fill_rgba_map(fade->rgba_map, inlink->format) >= 0;
 
     /* use CCIR601/709 black level for studio-level pixel non-alpha components */
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_fps.c b/mythtv/external/FFmpeg/libavfilter/vf_fps.c
index d4305e72734..29eedc7cf52 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_fps.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_fps.c
@@ -109,6 +109,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 {
     FPSContext *s = ctx->priv;
     if (s->fifo) {
+        s->drop += av_fifo_size(s->fifo) / sizeof(AVFilterBufferRef*);
         flush_fifo(s->fifo);
         av_fifo_free(s->fifo);
     }
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_geq.c b/mythtv/external/FFmpeg/libavfilter/vf_geq.c
index 2f7b50b6475..72ecda0af11 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_geq.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_geq.c
@@ -34,20 +34,22 @@
 
 typedef struct {
     const AVClass *class;
-    AVExpr *e[3];               ///< expressions for each plane
-    char *expr_str[3];          ///< expression strings for each plane
+    AVExpr *e[4];               ///< expressions for each plane
+    char *expr_str[4];          ///< expression strings for each plane
     int framenum;               ///< frame counter
     AVFilterBufferRef *picref;  ///< current input buffer
     int hsub, vsub;             ///< chroma subsampling
+    int planes;                 ///< number of planes
 } GEQContext;
 
 #define OFFSET(x) offsetof(GEQContext, x)
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
 static const AVOption geq_options[] = {
-    { "lum_expr",   "set luminance expression",   OFFSET(expr_str),                   AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
-    { "cb_expr",    "set chroma blue expression", OFFSET(expr_str) +   sizeof(char*), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
-    { "cr_expr",    "set chroma red expression",  OFFSET(expr_str) + 2*sizeof(char*), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "lum_expr",   "set luminance expression",   OFFSET(expr_str[0]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "cb_expr",    "set chroma blue expression", OFFSET(expr_str[1]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "cr_expr",    "set chroma red expression",  OFFSET(expr_str[2]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "alpha_expr", "set alpha expression",       OFFSET(expr_str[3]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
     {NULL},
 };
 
@@ -60,8 +62,11 @@ static inline double getpix(void *priv, double x, double y, int plane)
     AVFilterBufferRef *picref = geq->picref;
     const uint8_t *src = picref->data[plane];
     const int linesize = picref->linesize[plane];
-    const int w = picref->video->w >> (plane ? geq->hsub : 0);
-    const int h = picref->video->h >> (plane ? geq->vsub : 0);
+    const int w = picref->video->w >> ((plane == 1 || plane == 2) ? geq->hsub : 0);
+    const int h = picref->video->h >> ((plane == 1 || plane == 2) ? geq->vsub : 0);
+
+    if (!src)
+        return 0;
 
     xi = x = av_clipf(x, 0, w - 2);
     yi = y = av_clipf(y, 0, h - 2);
@@ -78,6 +83,7 @@ static inline double getpix(void *priv, double x, double y, int plane)
 static double lum(void *priv, double x, double y) { return getpix(priv, x, y, 0); }
 static double  cb(void *priv, double x, double y) { return getpix(priv, x, y, 1); }
 static double  cr(void *priv, double x, double y) { return getpix(priv, x, y, 2); }
+static double alpha(void *priv, double x, double y) { return getpix(priv, x, y, 3); }
 
 static const char *const var_names[] = {   "X",   "Y",   "W",   "H",   "N",   "SW",   "SH",   "T",        NULL };
 enum                                   { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_N, VAR_SW, VAR_SH, VAR_T, VAR_VARS_NB };
@@ -86,7 +92,7 @@ static av_cold int geq_init(AVFilterContext *ctx, const char *args)
 {
     GEQContext *geq = ctx->priv;
     int plane, ret = 0;
-    static const char *shorthand[] = { "lum_expr", "cb_expr", "cr_expr", NULL };
+    static const char *shorthand[] = { "lum_expr", "cb_expr", "cr_expr", "alpha_expr", NULL };
 
     geq->class = &geq_class;
     av_opt_set_defaults(geq);
@@ -110,15 +116,18 @@ static av_cold int geq_init(AVFilterContext *ctx, const char *args)
         if (!geq->expr_str[2]) geq->expr_str[2] = av_strdup(geq->expr_str[1]);
     }
 
-    if (!geq->expr_str[1] || !geq->expr_str[2]) {
+    if (!geq->expr_str[3])
+        geq->expr_str[3] = av_strdup("255");
+
+    if (!geq->expr_str[1] || !geq->expr_str[2] || !geq->expr_str[3]) {
         ret = AVERROR(ENOMEM);
         goto end;
     }
 
-    for (plane = 0; plane < 3; plane++) {
-        static double (*p[])(void *, double, double) = { lum, cb, cr };
-        static const char *const func2_names[]    = { "lum", "cb", "cr", "p", NULL };
-        double (*func2[])(void *, double, double) = { lum, cb, cr, p[plane], NULL };
+    for (plane = 0; plane < 4; plane++) {
+        static double (*p[])(void *, double, double) = { lum, cb, cr, alpha };
+        static const char *const func2_names[]    = { "lum", "cb", "cr", "alpha", "p", NULL };
+        double (*func2[])(void *, double, double) = { lum, cb, cr, alpha, p[plane], NULL };
 
         ret = av_expr_parse(&geq->e[plane], geq->expr_str[plane], var_names,
                             NULL, NULL, func2_names, func2, 0, ctx);
@@ -135,7 +144,8 @@ static int geq_query_formats(AVFilterContext *ctx)
     static const enum PixelFormat pix_fmts[] = {
         AV_PIX_FMT_YUV444P,  AV_PIX_FMT_YUV422P,  AV_PIX_FMT_YUV420P,
         AV_PIX_FMT_YUV411P,  AV_PIX_FMT_YUV410P,  AV_PIX_FMT_YUV440P,
-        AV_PIX_FMT_YUVA420P,
+        AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
+        AV_PIX_FMT_GRAY8,
         AV_PIX_FMT_NONE
     };
     ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
@@ -149,6 +159,7 @@ static int geq_config_props(AVFilterLink *inlink)
 
     geq->hsub = desc->log2_chroma_w;
     geq->vsub = desc->log2_chroma_h;
+    geq->planes = desc->nb_components;
     return 0;
 }
 
@@ -171,12 +182,12 @@ static int geq_filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
     }
     avfilter_copy_buffer_ref_props(out, in);
 
-    for (plane = 0; plane < 3; plane++) {
+    for (plane = 0; plane < geq->planes && out->data[plane]; plane++) {
         int x, y;
         uint8_t *dst = out->data[plane];
         const int linesize = out->linesize[plane];
-        const int w = inlink->w >> (plane ? geq->hsub : 0);
-        const int h = inlink->h >> (plane ? geq->vsub : 0);
+        const int w = inlink->w >> ((plane == 1 || plane == 2) ? geq->hsub : 0);
+        const int h = inlink->h >> ((plane == 1 || plane == 2) ? geq->vsub : 0);
 
         values[VAR_W]  = w;
         values[VAR_H]  = h;
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_gradfun.c b/mythtv/external/FFmpeg/libavfilter/vf_gradfun.c
index 93ac76824bf..13154f09e56 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_gradfun.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_gradfun.c
@@ -170,6 +170,7 @@ static int query_formats(AVFilterContext *ctx)
         AV_PIX_FMT_GRAY8,              AV_PIX_FMT_NV12,
         AV_PIX_FMT_NV21,               AV_PIX_FMT_YUV444P,
         AV_PIX_FMT_YUV422P,            AV_PIX_FMT_YUV411P,
+        AV_PIX_FMT_YUV440P,
         AV_PIX_FMT_NONE
     };
 
@@ -201,13 +202,12 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
     GradFunContext *gf = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
     AVFilterBufferRef *out;
-    int p, direct;
+    int p, direct = 0;
 
     if (in->perms & AV_PERM_WRITE) {
         direct = 1;
         out = in;
     } else {
-        direct = 0;
         out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
         if (!out) {
             avfilter_unref_bufferp(&in);
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_hflip.c b/mythtv/external/FFmpeg/libavfilter/vf_hflip.c
index c583ffdd9d7..c3b92c25df0 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_hflip.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_hflip.c
@@ -42,35 +42,19 @@ typedef struct {
 
 static int query_formats(AVFilterContext *ctx)
 {
-    static const enum AVPixelFormat pix_fmts[] = {
-        AV_PIX_FMT_RGB48BE,      AV_PIX_FMT_RGB48LE,
-        AV_PIX_FMT_BGR48BE,      AV_PIX_FMT_BGR48LE,
-        AV_PIX_FMT_ARGB,         AV_PIX_FMT_RGBA,
-        AV_PIX_FMT_ABGR,         AV_PIX_FMT_BGRA,
-        AV_PIX_FMT_RGB24,        AV_PIX_FMT_BGR24,
-        AV_PIX_FMT_RGB565BE,     AV_PIX_FMT_RGB565LE,
-        AV_PIX_FMT_RGB555BE,     AV_PIX_FMT_RGB555LE,
-        AV_PIX_FMT_RGB444BE,     AV_PIX_FMT_RGB444LE,
-        AV_PIX_FMT_BGR565BE,     AV_PIX_FMT_BGR565LE,
-        AV_PIX_FMT_BGR555BE,     AV_PIX_FMT_BGR555LE,
-        AV_PIX_FMT_BGR444BE,     AV_PIX_FMT_BGR444LE,
-        AV_PIX_FMT_GRAY16BE,     AV_PIX_FMT_GRAY16LE,
-        AV_PIX_FMT_YUV420P16LE,  AV_PIX_FMT_YUV420P16BE,
-        AV_PIX_FMT_YUV422P16LE,  AV_PIX_FMT_YUV422P16BE,
-        AV_PIX_FMT_YUV444P16LE,  AV_PIX_FMT_YUV444P16BE,
-        AV_PIX_FMT_YUV444P,      AV_PIX_FMT_YUV422P,
-        AV_PIX_FMT_YUV420P,      AV_PIX_FMT_YUV411P,
-        AV_PIX_FMT_YUV410P,      AV_PIX_FMT_YUV440P,
-        AV_PIX_FMT_YUVJ444P,     AV_PIX_FMT_YUVJ422P,
-        AV_PIX_FMT_YUVJ420P,     AV_PIX_FMT_YUVJ440P,
-        AV_PIX_FMT_YUVA420P,
-        AV_PIX_FMT_RGB8,         AV_PIX_FMT_BGR8,
-        AV_PIX_FMT_RGB4_BYTE,    AV_PIX_FMT_BGR4_BYTE,
-        AV_PIX_FMT_PAL8,         AV_PIX_FMT_GRAY8,
-        AV_PIX_FMT_NONE
-    };
-
-    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+    AVFilterFormats *pix_fmts = NULL;
+    int fmt;
+
+    for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
+        if (!(desc->flags & PIX_FMT_HWACCEL ||
+              desc->flags & PIX_FMT_BITSTREAM ||
+              (desc->log2_chroma_w != desc->log2_chroma_h &&
+               desc->comp[0].plane == desc->comp[1].plane)))
+            ff_add_format(&pix_fmts, fmt);
+    }
+
+    ff_set_common_formats(ctx, pix_fmts);
     return 0;
 }
 
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_histogram.c b/mythtv/external/FFmpeg/libavfilter/vf_histogram.c
new file mode 100644
index 00000000000..279e44aba16
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavfilter/vf_histogram.c
@@ -0,0 +1,347 @@
+/*
+ * Copyright (c) 2012-2013 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/avassert.h"
+#include "libavutil/opt.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/pixdesc.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+enum HistogramMode {
+    MODE_LEVELS,
+    MODE_WAVEFORM,
+    MODE_COLOR,
+    MODE_COLOR2,
+    MODE_NB
+};
+
+typedef struct HistogramContext {
+    const AVClass *class;               ///< AVClass context for log and options purpose
+    enum HistogramMode mode;
+    unsigned       histogram[256];
+    unsigned       max_hval;
+    int            ncomp;
+    const uint8_t  *bg_color;
+    const uint8_t  *fg_color;
+    int            level_height;
+    int            scale_height;
+    int            step;
+    int            waveform_mode;
+    int            display_mode;
+} HistogramContext;
+
+#define OFFSET(x) offsetof(HistogramContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption histogram_options[] = {
+    { "mode", "set histogram mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_LEVELS}, 0, MODE_NB-1, FLAGS, "mode"},
+    { "levels", "standard histogram", 0, AV_OPT_TYPE_CONST, {.i64=MODE_LEVELS}, 0, 0, FLAGS, "mode" },
+    { "waveform", "per row/column luminance graph", 0, AV_OPT_TYPE_CONST, {.i64=MODE_WAVEFORM}, 0, 0, FLAGS, "mode" },
+    { "color", "chroma values in vectorscope", 0, AV_OPT_TYPE_CONST, {.i64=MODE_COLOR}, 0, 0, FLAGS, "mode" },
+    { "color2", "chroma values in vectorscope", 0, AV_OPT_TYPE_CONST, {.i64=MODE_COLOR2}, 0, 0, FLAGS, "mode" },
+    { "level_height", "set level height", OFFSET(level_height), AV_OPT_TYPE_INT, {.i64=200}, 50, 2048, FLAGS},
+    { "scale_height", "set scale height", OFFSET(scale_height), AV_OPT_TYPE_INT, {.i64=12}, 0, 40, FLAGS},
+    { "step", "set waveform step value", OFFSET(step), AV_OPT_TYPE_INT, {.i64=10}, 1, 255, FLAGS},
+    { "waveform_mode", "set waveform mode", OFFSET(waveform_mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "waveform_mode"},
+    { "row",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "waveform_mode" },
+    { "column", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "waveform_mode" },
+    { "display_mode", "set display mode", OFFSET(display_mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "display_mode"},
+    { "parade",  NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "display_mode" },
+    { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "display_mode" },
+    { NULL },
+};
+
+AVFILTER_DEFINE_CLASS(histogram);
+
+static av_cold int init(AVFilterContext *ctx, const char *args)
+{
+    HistogramContext *h = ctx->priv;
+    int ret;
+
+    h->class = &histogram_class;
+    av_opt_set_defaults(h);
+
+    if ((ret = (av_set_options_string(h, args, "=", ":"))) < 0)
+        return ret;
+
+    return 0;
+}
+
+static const enum AVPixelFormat color_pix_fmts[] = {
+    AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVJ444P,
+    AV_PIX_FMT_NONE
+};
+
+static const enum AVPixelFormat levels_pix_fmts[] = {
+    AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVJ444P,
+    AV_PIX_FMT_GRAY8, AV_PIX_FMT_GBRP, AV_PIX_FMT_NONE
+};
+
+static int query_formats(AVFilterContext *ctx)
+{
+    HistogramContext *h = ctx->priv;
+    const enum AVPixelFormat *pix_fmts;
+
+    switch (h->mode) {
+    case MODE_WAVEFORM:
+    case MODE_LEVELS:
+        pix_fmts = levels_pix_fmts;
+        break;
+    case MODE_COLOR:
+    case MODE_COLOR2:
+        pix_fmts = color_pix_fmts;
+        break;
+    default:
+        av_assert0(0);
+    }
+
+    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+
+    return 0;
+}
+
+static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
+static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
+static const uint8_t white_yuva_color[4] = { 255, 127, 127, 255 };
+static const uint8_t white_gbrp_color[4] = { 255, 255, 255, 255 };
+
+static int config_input(AVFilterLink *inlink)
+{
+    HistogramContext *h = inlink->dst->priv;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+
+    h->ncomp = desc->nb_components;
+
+    switch (inlink->format) {
+    case AV_PIX_FMT_GBRP:
+        h->bg_color = black_gbrp_color;
+        h->fg_color = white_gbrp_color;
+        break;
+    default:
+        h->bg_color = black_yuva_color;
+        h->fg_color = white_yuva_color;
+    }
+
+    return 0;
+}
+
+static int config_output(AVFilterLink *outlink)
+{
+    AVFilterContext *ctx = outlink->src;
+    HistogramContext *h = ctx->priv;
+
+    switch (h->mode) {
+    case MODE_LEVELS:
+        outlink->w = 256;
+        outlink->h = (h->level_height + h->scale_height) * FFMAX(h->ncomp * h->display_mode, 1);
+        break;
+    case MODE_WAVEFORM:
+        if (h->waveform_mode)
+            outlink->h = 256 * FFMAX(h->ncomp * h->display_mode, 1);
+        else
+            outlink->w = 256 * FFMAX(h->ncomp * h->display_mode, 1);
+        break;
+    case MODE_COLOR:
+    case MODE_COLOR2:
+        outlink->h = outlink->w = 256;
+        break;
+    default:
+        av_assert0(0);
+    }
+
+    outlink->sample_aspect_ratio = (AVRational){1,1};
+
+    return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
+{
+    HistogramContext *h   = inlink->dst->priv;
+    AVFilterContext *ctx  = inlink->dst;
+    AVFilterLink *outlink = ctx->outputs[0];
+    AVFilterBufferRef *out;
+    const uint8_t *src;
+    uint8_t *dst;
+    int i, j, k, l, ret;
+
+    out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
+    if (!out) {
+        avfilter_unref_bufferp(&in);
+        return AVERROR(ENOMEM);
+    }
+
+    out->pts = in->pts;
+    out->pos = in->pos;
+
+    for (k = 0; k < h->ncomp; k++)
+        for (i = 0; i < outlink->h; i++)
+            memset(out->data[k] + i * out->linesize[k], h->bg_color[k], outlink->w);
+
+    switch (h->mode) {
+    case MODE_LEVELS:
+        for (k = 0; k < h->ncomp; k++) {
+            int start = k * (h->level_height + h->scale_height) * h->display_mode;
+
+            for (i = 0; i < in->video->h; i++) {
+                src = in->data[k] + i * in->linesize[k];
+                for (j = 0; j < in->video->w; j++)
+                    h->histogram[src[j]]++;
+            }
+
+            for (i = 0; i < 256; i++)
+                h->max_hval = FFMAX(h->max_hval, h->histogram[i]);
+
+            for (i = 0; i < outlink->w; i++) {
+                int col_height = h->level_height - (float)h->histogram[i] / h->max_hval * h->level_height;
+
+                for (j = h->level_height - 1; j >= col_height; j--) {
+                    if (h->display_mode) {
+                        for (l = 0; l < h->ncomp; l++)
+                            out->data[l][(j + start) * out->linesize[l] + i] = h->fg_color[l];
+                    } else {
+                        out->data[k][(j + start) * out->linesize[k] + i] = 255;
+                    }
+                }
+                for (j = h->level_height + h->scale_height - 1; j >= h->level_height; j--)
+                    out->data[k][(j + start) * out->linesize[k] + i] = i;
+            }
+
+            memset(h->histogram, 0, 256 * sizeof(unsigned));
+            h->max_hval = 0;
+        }
+        break;
+    case MODE_WAVEFORM:
+        if (h->waveform_mode) {
+            for (k = 0; k < h->ncomp; k++) {
+                int offset = k * 256 * h->display_mode;
+                for (i = 0; i < inlink->w; i++) {
+                    for (j = 0; j < inlink->h; j++) {
+                        int pos = (offset +
+                                   in->data[k][j * in->linesize[k] + i]) *
+                                  out->linesize[k] + i;
+                        unsigned value = out->data[k][pos];
+                        value = FFMIN(value + h->step, 255);
+                        out->data[k][pos] = value;
+                    }
+                }
+            }
+        } else {
+            for (k = 0; k < h->ncomp; k++) {
+                int offset = k * 256 * h->display_mode;
+                for (i = 0; i < inlink->h; i++) {
+                    src = in ->data[k] + i * in ->linesize[k];
+                    dst = out->data[k] + i * out->linesize[k];
+                    for (j = 0; j < inlink->w; j++) {
+                        int pos = src[j] + offset;
+                        unsigned value = dst[pos];
+                        value = FFMIN(value + h->step, 255);
+                        dst[pos] = value;
+                    }
+                }
+            }
+        }
+        break;
+    case MODE_COLOR:
+        for (i = 0; i < inlink->h; i++) {
+            int iw1 = i * in->linesize[1];
+            int iw2 = i * in->linesize[2];
+            for (j = 0; j < inlink->w; j++) {
+                int pos = in->data[1][iw1 + j] * out->linesize[0] + in->data[2][iw2 + j];
+                if (out->data[0][pos] < 255)
+                    out->data[0][pos]++;
+            }
+        }
+        for (i = 0; i < 256; i++) {
+            dst = out->data[0] + i * out->linesize[0];
+            for (j = 0; j < 256; j++) {
+                if (!dst[j]) {
+                    out->data[1][i * out->linesize[0] + j] = i;
+                    out->data[2][i * out->linesize[0] + j] = j;
+                }
+            }
+        }
+        break;
+    case MODE_COLOR2:
+        for (i = 0; i < inlink->h; i++) {
+            int iw1 = i * in->linesize[1];
+            int iw2 = i * in->linesize[2];
+            for (j = 0; j < inlink->w; j++) {
+                int u = in->data[1][iw1 + j];
+                int v = in->data[2][iw2 + j];
+                int pos = u * out->linesize[0] + v;
+                if (!out->data[0][pos])
+                    out->data[0][pos] = FFABS(128 - u) + FFABS(128 - v);
+                out->data[1][pos] = u;
+                out->data[2][pos] = v;
+            }
+        }
+        break;
+    default:
+        av_assert0(0);
+    }
+
+    ret = ff_filter_frame(outlink, out);
+    avfilter_unref_bufferp(&in);
+    if (ret < 0)
+        return ret;
+    return 0;
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+    HistogramContext *h = ctx->priv;
+
+    av_opt_free(h);
+}
+
+static const AVFilterPad inputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_VIDEO,
+        .filter_frame = filter_frame,
+        .config_props = config_input,
+        .min_perms    = AV_PERM_READ,
+    },
+    { NULL }
+};
+
+static const AVFilterPad outputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_VIDEO,
+        .config_props = config_output,
+    },
+    { NULL }
+};
+
+AVFilter avfilter_vf_histogram = {
+    .name          = "histogram",
+    .description   = NULL_IF_CONFIG_SMALL("Compute and draw a histogram."),
+    .priv_size     = sizeof(HistogramContext),
+    .init          = init,
+    .uninit        = uninit,
+    .query_formats = query_formats,
+    .inputs        = inputs,
+    .outputs       = outputs,
+    .priv_class    = &histogram_class,
+};
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_hqdn3d.c b/mythtv/external/FFmpeg/libavfilter/vf_hqdn3d.c
index 15d63bab1cc..4381586bec3 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_hqdn3d.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_hqdn3d.c
@@ -26,6 +26,7 @@
  * libmpcodecs/vf_hqdn3d.c.
  */
 
+#include "config.h"
 #include "libavutil/common.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/intreadwrite.h"
@@ -33,27 +34,12 @@
 #include "formats.h"
 #include "internal.h"
 #include "video.h"
-
-typedef struct {
-    int16_t *coefs[4];
-    uint16_t *line;
-    uint16_t *frame_prev[3];
-    double strength[4];
-    int hsub, vsub;
-    int depth;
-    void (*denoise_row[17])(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal);
-} HQDN3DContext;
-
-void ff_hqdn3d_row_8_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal);
-void ff_hqdn3d_row_9_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal);
-void ff_hqdn3d_row_10_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal);
-void ff_hqdn3d_row_16_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal);
+#include "vf_hqdn3d.h"
 
 #define LUT_BITS (depth==16 ? 8 : 4)
-#define LOAD(x) (((depth == 8 ? src[x] : AV_RN16A(src + (x) * 2)) << (16 - depth))\
-                 + (((1 << (16 - depth)) - 1) >> 1))
-#define STORE(x,val) (depth == 8 ? dst[x] = (val) >> (16 - depth) : \
-                                   AV_WN16A(dst + (x) * 2, (val) >> (16 - depth)))
+#define LOAD(x) (((depth==8 ? src[x] : AV_RN16A(src+(x)*2)) << (16-depth)) + (((1<<(16-depth))-1)>>1))
+#define STORE(x,val) (depth==8 ? dst[x] = (val) >> (16-depth)\
+                    : AV_WN16A(dst+(x)*2, (val) >> (16-depth)))
 
 av_always_inline
 static uint32_t lowpass(int prev, int cur, int16_t *coef, int depth)
@@ -312,12 +298,8 @@ static int config_input(AVFilterLink *inlink)
             return AVERROR(ENOMEM);
     }
 
-#if HAVE_YASM
-    hqdn3d->denoise_row[ 8] = ff_hqdn3d_row_8_x86;
-    hqdn3d->denoise_row[ 9] = ff_hqdn3d_row_9_x86;
-    hqdn3d->denoise_row[10] = ff_hqdn3d_row_10_x86;
-    hqdn3d->denoise_row[16] = ff_hqdn3d_row_16_x86;
-#endif
+    if (ARCH_X86)
+        ff_hqdn3d_init_x86(hqdn3d);
 
     return 0;
 }
@@ -328,13 +310,12 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
     AVFilterLink *outlink = inlink->dst->outputs[0];
 
     AVFilterBufferRef *out;
-    int direct, c;
+    int direct = 0, c;
 
     if (in->perms & AV_PERM_WRITE) {
         direct = 1;
         out = in;
     } else {
-        direct = 0;
         out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
         if (!out) {
             avfilter_unref_bufferp(&in);
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_hqdn3d.h b/mythtv/external/FFmpeg/libavfilter/vf_hqdn3d.h
new file mode 100644
index 00000000000..dfc69e140fb
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavfilter/vf_hqdn3d.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2003 Daniel Moreno 
+ * Copyright (c) 2010 Baptiste Coudurier
+ * Copyright (c) 2012 Loren Merritt
+ *
+ * This file is part of FFmpeg, ported from MPlayer.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef AVFILTER_VF_HQDN3D_H
+#define AVFILTER_VF_HQDN3D_H
+
+#include 
+#include 
+
+typedef struct {
+    int16_t *coefs[4];
+    uint16_t *line;
+    uint16_t *frame_prev[3];
+    double strength[4];
+    int hsub, vsub;
+    int depth;
+    void (*denoise_row[17])(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal);
+} HQDN3DContext;
+
+void ff_hqdn3d_init_x86(HQDN3DContext *hqdn3d);
+
+#endif /* AVFILTER_VF_HQDN3D_H */
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_hue.c b/mythtv/external/FFmpeg/libavfilter/vf_hue.c
index 7bc3d37dad5..59fc62cef12 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_hue.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_hue.c
@@ -130,74 +130,43 @@ static inline void compute_sin_and_cos(HueContext *hue)
 static inline int set_options(AVFilterContext *ctx, const char *args)
 {
     HueContext *hue = ctx->priv;
-    int n, ret;
-    char c1 = 0, c2 = 0;
+    int ret;
     char   *old_hue_expr,  *old_hue_deg_expr,  *old_saturation_expr;
     AVExpr *old_hue_pexpr, *old_hue_deg_pexpr, *old_saturation_pexpr;
+    static const char *shorthand[] = { "h", "s", NULL };
+    old_hue_expr        = hue->hue_expr;
+    old_hue_deg_expr    = hue->hue_deg_expr;
+    old_saturation_expr = hue->saturation_expr;
+
+    old_hue_pexpr        = hue->hue_pexpr;
+    old_hue_deg_pexpr    = hue->hue_deg_pexpr;
+    old_saturation_pexpr = hue->saturation_pexpr;
+
+    hue->hue_expr     = NULL;
+    hue->hue_deg_expr = NULL;
+    hue->saturation_expr = NULL;
+
+    if ((ret = av_opt_set_from_string(hue, args, shorthand, "=", ":")) < 0)
+        return ret;
+    if (hue->hue_expr && hue->hue_deg_expr) {
+        av_log(ctx, AV_LOG_ERROR,
+               "H and h options are incompatible and cannot be specified "
+               "at the same time\n");
+        hue->hue_expr     = old_hue_expr;
+        hue->hue_deg_expr = old_hue_deg_expr;
+
+        return AVERROR(EINVAL);
+    }
 
-    if (args) {
-        /* named options syntax */
-        if (strchr(args, '=')) {
-            old_hue_expr        = hue->hue_expr;
-            old_hue_deg_expr    = hue->hue_deg_expr;
-            old_saturation_expr = hue->saturation_expr;
-
-            old_hue_pexpr        = hue->hue_pexpr;
-            old_hue_deg_pexpr    = hue->hue_deg_pexpr;
-            old_saturation_pexpr = hue->saturation_pexpr;
-
-            hue->hue_expr     = NULL;
-            hue->hue_deg_expr = NULL;
-            hue->saturation_expr = NULL;
-
-            if ((ret = av_set_options_string(hue, args, "=", ":")) < 0)
-                return ret;
-            if (hue->hue_expr && hue->hue_deg_expr) {
-                av_log(ctx, AV_LOG_ERROR,
-                       "H and h options are incompatible and cannot be specified "
-                       "at the same time\n");
-                hue->hue_expr     = old_hue_expr;
-                hue->hue_deg_expr = old_hue_deg_expr;
-
-                return AVERROR(EINVAL);
-            }
-
-            SET_EXPRESSION(hue_deg, h);
-            SET_EXPRESSION(hue, H);
-            SET_EXPRESSION(saturation, s);
-
-            hue->flat_syntax = 0;
-
-            av_log(ctx, AV_LOG_VERBOSE,
-                   "H_expr:%s h_deg_expr:%s s_expr:%s\n",
-                   hue->hue_expr, hue->hue_deg_expr, hue->saturation_expr);
-
-        /* compatibility h:s syntax */
-        } else {
-            n = sscanf(args, "%f%c%f%c", &hue->hue_deg, &c1, &hue->saturation, &c2);
-            if (n != 1 && (n != 3 || c1 != ':')) {
-                av_log(ctx, AV_LOG_ERROR,
-                       "Invalid syntax for argument '%s': "
-                       "must be in the form 'hue[:saturation]'\n", args);
-                return AVERROR(EINVAL);
-            }
-
-            if (hue->saturation < SAT_MIN_VAL || hue->saturation > SAT_MAX_VAL) {
-                av_log(ctx, AV_LOG_ERROR,
-                       "Invalid value for saturation %0.1f: "
-                       "must be included between range %d and +%d\n",
-                       hue->saturation, SAT_MIN_VAL, SAT_MAX_VAL);
-                return AVERROR(EINVAL);
-            }
+    SET_EXPRESSION(hue_deg, h);
+    SET_EXPRESSION(hue, H);
+    SET_EXPRESSION(saturation, s);
 
-            hue->hue = hue->hue_deg * M_PI / 180;
-            hue->flat_syntax = 1;
+    hue->flat_syntax = 0;
 
-            av_log(ctx, AV_LOG_VERBOSE,
-                   "H:%0.1f h:%0.1f s:%0.1f\n",
-                   hue->hue, hue->hue_deg, hue->saturation);
-        }
-    }
+    av_log(ctx, AV_LOG_VERBOSE,
+           "H_expr:%s h_deg_expr:%s s_expr:%s\n",
+           hue->hue_expr, hue->hue_deg_expr, hue->saturation_expr);
 
     compute_sin_and_cos(hue);
 
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_idet.c b/mythtv/external/FFmpeg/libavfilter/vf_idet.c
index 513a8e397a2..5023630ecbf 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_idet.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_idet.c
@@ -59,8 +59,8 @@ typedef struct {
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
 static const AVOption idet_options[] = {
-    { "intl_thres", "set interlacing threshold", OFFSET(interlace_threshold),   AV_OPT_TYPE_FLOAT, {.dbl = 1.01}, -1, FLT_MAX, FLAGS },
-    { "prog_thres", "set progressive threshold", OFFSET(progressive_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 2.5},  -1, FLT_MAX, FLAGS },
+    { "intl_thres", "set interlacing threshold", OFFSET(interlace_threshold),   AV_OPT_TYPE_FLOAT, {.dbl = 1.04}, -1, FLT_MAX, FLAGS },
+    { "prog_thres", "set progressive threshold", OFFSET(progressive_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 1.5},  -1, FLT_MAX, FLAGS },
     { NULL }
 };
 
@@ -83,7 +83,8 @@ static int filter_line_c(const uint8_t *a, const uint8_t *b, const uint8_t *c, i
     int ret=0;
 
     for(x=0; x
+ * Copyright (c) 2013 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * (de)interleave fields filter
+ */
+
+#include "libavutil/opt.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/pixdesc.h"
+#include "avfilter.h"
+#include "internal.h"
+
+enum FilterMode {
+    MODE_NONE,
+    MODE_INTERLEAVE,
+    MODE_DEINTERLEAVE
+};
+
+typedef struct {
+    const AVClass *class;
+    enum FilterMode luma_mode, chroma_mode, alpha_mode;
+    int luma_swap, chroma_swap, alpha_swap;
+    int nb_planes;
+    int linesize[4], chroma_height;
+    int has_alpha;
+} IlContext;
+
+#define OFFSET(x) offsetof(IlContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption il_options[] = {
+    {"luma_mode",   "select luma mode", OFFSET(luma_mode), AV_OPT_TYPE_INT, {.i64=MODE_NONE}, MODE_NONE, MODE_DEINTERLEAVE, FLAGS, "luma_mode"},
+    {"l",           "select luma mode", OFFSET(luma_mode), AV_OPT_TYPE_INT, {.i64=MODE_NONE}, MODE_NONE, MODE_DEINTERLEAVE, FLAGS, "luma_mode"},
+    {"none",         NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_NONE},         0, 0, FLAGS, "luma_mode"},
+    {"interleave",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE},   0, 0, FLAGS, "luma_mode"},
+    {"i",            NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE},   0, 0, FLAGS, "luma_mode"},
+    {"deinterleave", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_DEINTERLEAVE}, 0, 0, FLAGS, "luma_mode"},
+    {"d",            NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_DEINTERLEAVE}, 0, 0, FLAGS, "luma_mode"},
+    {"chroma_mode", "select chroma mode", OFFSET(chroma_mode), AV_OPT_TYPE_INT, {.i64=MODE_NONE}, MODE_NONE, MODE_DEINTERLEAVE, FLAGS, "chroma_mode"},
+    {"c",           "select chroma mode", OFFSET(chroma_mode), AV_OPT_TYPE_INT, {.i64=MODE_NONE}, MODE_NONE, MODE_DEINTERLEAVE, FLAGS, "chroma_mode"},
+    {"none",         NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_NONE},         0, 0, FLAGS, "chroma_mode"},
+    {"interleave",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE},   0, 0, FLAGS, "chroma_mode"},
+    {"i",            NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE},   0, 0, FLAGS, "chroma_mode"},
+    {"deinterleave", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_DEINTERLEAVE}, 0, 0, FLAGS, "chroma_mode"},
+    {"d",            NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_DEINTERLEAVE}, 0, 0, FLAGS, "chroma_mode"},
+    {"alpha_mode", "select alpha mode", OFFSET(alpha_mode), AV_OPT_TYPE_INT, {.i64=MODE_NONE}, MODE_NONE, MODE_DEINTERLEAVE, FLAGS, "alpha_mode"},
+    {"a",          "select alpha mode", OFFSET(alpha_mode), AV_OPT_TYPE_INT, {.i64=MODE_NONE}, MODE_NONE, MODE_DEINTERLEAVE, FLAGS, "alpha_mode"},
+    {"none",         NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_NONE},         0, 0, FLAGS, "alpha_mode"},
+    {"interleave",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE},   0, 0, FLAGS, "alpha_mode"},
+    {"i",            NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE},   0, 0, FLAGS, "alpha_mode"},
+    {"deinterleave", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_DEINTERLEAVE}, 0, 0, FLAGS, "alpha_mode"},
+    {"d",            NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_DEINTERLEAVE}, 0, 0, FLAGS, "alpha_mode"},
+    {"luma_swap",   "swap luma fields",   OFFSET(luma_swap),   AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS},
+    {"ls",          "swap luma fields",   OFFSET(luma_swap),   AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS},
+    {"chroma_swap", "swap chroma fields", OFFSET(chroma_swap), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS},
+    {"cs",          "swap chroma fields", OFFSET(chroma_swap), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS},
+    {"alpha_swap",  "swap alpha fields",  OFFSET(alpha_swap),  AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS},
+    {"as",          "swap alpha fields",  OFFSET(alpha_swap),  AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS},
+    {NULL}
+};
+
+AVFILTER_DEFINE_CLASS(il);
+
+static av_cold int init(AVFilterContext *ctx, const char *args)
+{
+    IlContext *il = ctx->priv;
+    int ret;
+
+    il->class = &il_class;
+    av_opt_set_defaults(il);
+
+    if ((ret = av_set_options_string(il, args, "=", ":")) < 0)
+        return ret;
+
+    return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+    AVFilterFormats *formats = NULL;
+    int fmt;
+
+    for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
+        if (!(desc->flags & PIX_FMT_PAL) && !(desc->flags & PIX_FMT_HWACCEL))
+            ff_add_format(&formats, fmt);
+    }
+
+    ff_set_common_formats(ctx, formats);
+    return 0;
+}
+
+static int config_input(AVFilterLink *inlink)
+{
+    IlContext *il = inlink->dst->priv;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+    int i, ret;
+
+    for (i = 0; i < desc->nb_components; i++)
+        il->nb_planes = FFMAX(il->nb_planes, desc->comp[i].plane);
+    il->nb_planes++;
+
+    il->has_alpha = !!(desc->flags & PIX_FMT_ALPHA);
+    if ((ret = av_image_fill_linesizes(il->linesize, inlink->format, inlink->w)) < 0)
+        return ret;
+
+    il->chroma_height = inlink->h >> desc->log2_chroma_h;
+
+    return 0;
+}
+
+static void interleave(uint8_t *dst, uint8_t *src, int w, int h,
+                       int dst_linesize, int src_linesize,
+                       enum FilterMode mode, int swap)
+{
+    const int a = swap;
+    const int b = 1 - a;
+    const int m = h >> 1;
+    int y;
+
+    switch (mode) {
+    case MODE_DEINTERLEAVE:
+        for (y = 0; y < m; y++) {
+            memcpy(dst + dst_linesize *  y     , src + src_linesize * (y * 2 + a), w);
+            memcpy(dst + dst_linesize * (y + m), src + src_linesize * (y * 2 + b), w);
+        }
+        break;
+    case MODE_NONE:
+        for (y = 0; y < m; y++) {
+            memcpy(dst + dst_linesize *  y * 2     , src + src_linesize * (y * 2 + a), w);
+            memcpy(dst + dst_linesize * (y * 2 + 1), src + src_linesize * (y * 2 + b), w);
+        }
+        break;
+    case MODE_INTERLEAVE:
+        for (y = 0; y < m; y++) {
+            memcpy(dst + dst_linesize * (y * 2 + a), src + src_linesize *  y     , w);
+            memcpy(dst + dst_linesize * (y * 2 + b), src + src_linesize * (y + m), w);
+        }
+        break;
+    }
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+{
+    IlContext *il = inlink->dst->priv;
+    AVFilterLink *outlink = inlink->dst->outputs[0];
+    AVFilterBufferRef *out;
+    int ret, comp;
+
+    out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
+    if (!out) {
+        avfilter_unref_bufferp(&inpicref);
+        return AVERROR(ENOMEM);
+    }
+    avfilter_copy_buffer_ref_props(out, inpicref);
+
+    interleave(out->data[0], inpicref->data[0],
+               il->linesize[0], inlink->h,
+               out->linesize[0], inpicref->linesize[0],
+               il->luma_mode, il->luma_swap);
+
+    for (comp = 1; comp < (il->nb_planes - il->has_alpha); comp++) {
+        interleave(out->data[comp], inpicref->data[comp],
+                   il->linesize[comp], il->chroma_height,
+                   out->linesize[comp], inpicref->linesize[comp],
+                   il->chroma_mode, il->chroma_swap);
+    }
+
+    if (il->has_alpha) {
+        int comp = il->nb_planes - 1;
+        interleave(out->data[comp], inpicref->data[comp],
+                   il->linesize[comp], inlink->h,
+                   out->linesize[comp], inpicref->linesize[comp],
+                   il->alpha_mode, il->alpha_swap);
+    }
+
+    ret = ff_filter_frame(outlink, out);
+    avfilter_unref_bufferp(&inpicref);
+    return ret;
+}
+
+static const AVFilterPad inputs[] = {
+    {
+        .name             = "default",
+        .type             = AVMEDIA_TYPE_VIDEO,
+        .get_video_buffer = ff_null_get_video_buffer,
+        .filter_frame     = filter_frame,
+        .config_props     = config_input,
+    },
+    { NULL }
+};
+
+static const AVFilterPad outputs[] = {
+    {
+        .name          = "default",
+        .type          = AVMEDIA_TYPE_VIDEO,
+    },
+    { NULL }
+};
+
+AVFilter avfilter_vf_il = {
+    .name          = "il",
+    .description   = NULL_IF_CONFIG_SMALL("Deinterleave or interleave fields."),
+    .priv_size     = sizeof(IlContext),
+    .init          = init,
+    .query_formats = query_formats,
+    .inputs        = inputs,
+    .outputs       = outputs,
+    .priv_class    = &il_class,
+};
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_kerndeint.c b/mythtv/external/FFmpeg/libavfilter/vf_kerndeint.c
index 12eb969b22b..9b77e09e585 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_kerndeint.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_kerndeint.c
@@ -40,8 +40,10 @@ typedef struct {
     int           frame; ///< frame count, starting from 0
     int           thresh, map, order, sharp, twoway;
     int           vsub;
-    uint8_t       *tmp_data [4];  ///< temporary plane data buffer
-    int           tmp_bwidth[4];  ///< temporary plane byte width
+    int           is_packed_rgb;
+    uint8_t       *tmp_data    [4];  ///< temporary plane data buffer
+    int            tmp_linesize[4];  ///< temporary plane byte linesize
+    int            tmp_bwidth  [4];  ///< temporary plane byte width
 } KerndeintContext;
 
 #define OFFSET(x) offsetof(KerndeintContext, x)
@@ -99,13 +101,18 @@ static int config_props(AVFilterLink *inlink)
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
     int ret;
 
+    kerndeint->is_packed_rgb = av_pix_fmt_desc_get(inlink->format)->flags & PIX_FMT_RGB;
     kerndeint->vsub = desc->log2_chroma_h;
 
-    ret = av_image_alloc(kerndeint->tmp_data, kerndeint->tmp_bwidth,
-                          inlink->w, inlink->h, inlink->format, 1);
+    ret = av_image_alloc(kerndeint->tmp_data, kerndeint->tmp_linesize,
+                         inlink->w, inlink->h, inlink->format, 16);
     if (ret < 0)
         return ret;
     memset(kerndeint->tmp_data[0], 0, ret);
+
+    if ((ret = av_image_fill_linesizes(kerndeint->tmp_bwidth, inlink->format, inlink->w)) < 0)
+        return ret;
+
     return 0;
 }
 
@@ -145,7 +152,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpic)
     const int sharp  = kerndeint->sharp;
     const int twoway = kerndeint->twoway;
 
-    const int is_packed_rgb = av_pix_fmt_desc_get(inlink->format)->flags & PIX_FMT_RGB;
+    const int is_packed_rgb = kerndeint->is_packed_rgb;
 
     outpic = ff_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_ALIGN, outlink->w, outlink->h);
     if (!outpic) {
@@ -161,7 +168,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpic)
 
         srcp = srcp_saved = inpic->data[plane];
         src_linesize      = inpic->linesize[plane];
-        psrc_linesize     = kerndeint->tmp_bwidth[plane];
+        psrc_linesize     = kerndeint->tmp_linesize[plane];
         dstp = dstp_saved = outpic->data[plane];
         dst_linesize      = outpic->linesize[plane];
         srcp              = srcp_saved + (1 - order) * src_linesize;
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_libopencv.c b/mythtv/external/FFmpeg/libavfilter/vf_libopencv.c
index 1b8a5dcc574..2d26b380378 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_libopencv.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_libopencv.c
@@ -177,7 +177,7 @@ static int read_shape_from_file(int *cols, int *rows, int **values, const char *
                 p++;
                 break;
             } else
-                (*values)[*cols*i + j] = !!isgraph(*(p++));
+                (*values)[*cols*i + j] = !!av_isgraph(*(p++));
         }
     }
     av_file_unmap(buf, size);
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_lut.c b/mythtv/external/FFmpeg/libavfilter/vf_lut.c
index 73f909d038c..bdfe712cf46 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_lut.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_lut.c
@@ -178,7 +178,7 @@ static int config_props(AVFilterLink *inlink)
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
     uint8_t rgba_map[4]; /* component index -> RGBA color index map */
     int min[4], max[4];
-    int val, comp, ret;
+    int val, color, ret;
 
     lut->hsub = desc->log2_chroma_w;
     lut->vsub = desc->log2_chroma_h;
@@ -213,9 +213,9 @@ static int config_props(AVFilterLink *inlink)
         lut->step = av_get_bits_per_pixel(desc) >> 3;
     }
 
-    for (comp = 0; comp < desc->nb_components; comp++) {
+    for (color = 0; color < desc->nb_components; color++) {
         double res;
-        int color = lut->is_rgb ? rgba_map[comp] : comp;
+        int comp = lut->is_rgb ? rgba_map[color] : color;
 
         /* create the parsed expression */
         ret = av_expr_parse(&lut->comp_expr[color], lut->comp_expr_str[color],
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_mp.c b/mythtv/external/FFmpeg/libavfilter/vf_mp.c
index 70d1797435f..4321d92acf6 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_mp.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_mp.c
@@ -36,7 +36,7 @@
 #include "libmpcodecs/vf.h"
 #include "libmpcodecs/img_format.h"
 #include "libmpcodecs/cpudetect.h"
-#include "libmpcodecs/vd_ffmpeg.h"
+#include "libmpcodecs/av_helpers.h"
 #include "libmpcodecs/vf_scale.h"
 #include "libmpcodecs/libvo/fastmemcpy.h"
 
@@ -126,17 +126,14 @@ extern const vf_info_t ff_vf_info_detc;
 extern const vf_info_t ff_vf_info_dint;
 extern const vf_info_t ff_vf_info_divtc;
 extern const vf_info_t ff_vf_info_down3dright;
-extern const vf_info_t ff_vf_info_dsize;
 extern const vf_info_t ff_vf_info_eq2;
 extern const vf_info_t ff_vf_info_eq;
 extern const vf_info_t ff_vf_info_fil;
 //extern const vf_info_t ff_vf_info_filmdint;
 extern const vf_info_t ff_vf_info_fspp;
 extern const vf_info_t ff_vf_info_harddup;
-extern const vf_info_t ff_vf_info_il;
 extern const vf_info_t ff_vf_info_ilpack;
 extern const vf_info_t ff_vf_info_ivtc;
-extern const vf_info_t ff_vf_info_kerndeint;
 extern const vf_info_t ff_vf_info_mcdeint;
 extern const vf_info_t ff_vf_info_noise;
 extern const vf_info_t ff_vf_info_ow;
@@ -147,12 +144,9 @@ extern const vf_info_t ff_vf_info_pullup;
 extern const vf_info_t ff_vf_info_qp;
 extern const vf_info_t ff_vf_info_sab;
 extern const vf_info_t ff_vf_info_softpulldown;
-extern const vf_info_t ff_vf_info_softskip;
 extern const vf_info_t ff_vf_info_spp;
-extern const vf_info_t ff_vf_info_stereo3d;
 extern const vf_info_t ff_vf_info_telecine;
 extern const vf_info_t ff_vf_info_tinterlace;
-extern const vf_info_t ff_vf_info_unsharp;
 extern const vf_info_t ff_vf_info_uspp;
 
 
@@ -161,17 +155,14 @@ static const vf_info_t* const filters[]={
     &ff_vf_info_dint,
     &ff_vf_info_divtc,
     &ff_vf_info_down3dright,
-    &ff_vf_info_dsize,
     &ff_vf_info_eq2,
     &ff_vf_info_eq,
     &ff_vf_info_fil,
 //    &ff_vf_info_filmdint, cmmx.h vd.h ‘opt_screen_size_x’
     &ff_vf_info_fspp,
     &ff_vf_info_harddup,
-    &ff_vf_info_il,
     &ff_vf_info_ilpack,
     &ff_vf_info_ivtc,
-    &ff_vf_info_kerndeint,
     &ff_vf_info_mcdeint,
     &ff_vf_info_noise,
     &ff_vf_info_ow,
@@ -182,12 +173,9 @@ static const vf_info_t* const filters[]={
     &ff_vf_info_qp,
     &ff_vf_info_sab,
     &ff_vf_info_softpulldown,
-    &ff_vf_info_softskip,
     &ff_vf_info_spp,
-    &ff_vf_info_stereo3d,
     &ff_vf_info_telecine,
     &ff_vf_info_tinterlace,
-    &ff_vf_info_unsharp,
     &ff_vf_info_uspp,
 
     NULL
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_noise.c b/mythtv/external/FFmpeg/libavfilter/vf_noise.c
new file mode 100644
index 00000000000..d3e443b65b4
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavfilter/vf_noise.c
@@ -0,0 +1,369 @@
+/*
+ * Copyright (c) 2002 Michael Niedermayer 
+ * Copyright (c) 2013 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * noise generator
+ */
+
+#include "libavutil/opt.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/lfg.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/pixdesc.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+#define MAX_NOISE 4096
+#define MAX_SHIFT 1024
+#define MAX_RES (MAX_NOISE-MAX_SHIFT)
+
+#define NOISE_UNIFORM  1
+#define NOISE_TEMPORAL 2
+#define NOISE_QUALITY  4
+#define NOISE_AVERAGED 8
+#define NOISE_PATTERN  16
+
+typedef struct {
+    int strength;
+    unsigned flags;
+    int shiftptr;
+    AVLFG lfg;
+    int seed;
+    int8_t *noise;
+    int8_t *prev_shift[MAX_RES][3];
+} FilterParams;
+
+typedef struct {
+    const AVClass *class;
+    int nb_planes;
+    int linesize[4];
+    int height[4];
+    FilterParams all;
+    FilterParams param[4];
+    int rand_shift[MAX_RES];
+    int rand_shift_init;
+} NoiseContext;
+
+#define OFFSET(x) offsetof(NoiseContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+#define NOISE_PARAMS(name, x, param)                                                                                             \
+    {#name"_seed", "set component #"#x" noise seed", OFFSET(param.seed), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, FLAGS},        \
+    {#name"_strength", "set component #"#x" strength", OFFSET(param.strength), AV_OPT_TYPE_INT, {.i64=0}, 0, 100, FLAGS},        \
+    {#name"s",         "set component #"#x" strength", OFFSET(param.strength), AV_OPT_TYPE_INT, {.i64=0}, 0, 100, FLAGS},        \
+    {#name"_flags", "set component #"#x" flags", OFFSET(param.flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 31, FLAGS, #name"_flags"}, \
+    {#name"f", "set component #"#x" flags", OFFSET(param.flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 31, FLAGS, #name"_flags"},      \
+    {"a", "averaged noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_AVERAGED}, 0, 0, FLAGS, #name"_flags"},                            \
+    {"p", "(semi)regular pattern", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_PATTERN},  0, 0, FLAGS, #name"_flags"},                     \
+    {"q", "high quality",   0, AV_OPT_TYPE_CONST, {.i64=NOISE_QUALITY},  0, 0, FLAGS, #name"_flags"},                            \
+    {"t", "temporal noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_TEMPORAL}, 0, 0, FLAGS, #name"_flags"},                            \
+    {"u", "uniform noise",  0, AV_OPT_TYPE_CONST, {.i64=NOISE_UNIFORM},  0, 0, FLAGS, #name"_flags"},
+
+static const AVOption noise_options[] = {
+    NOISE_PARAMS(all, 0, all)
+    NOISE_PARAMS(c0,  0, param[0])
+    NOISE_PARAMS(c1,  1, param[1])
+    NOISE_PARAMS(c2,  2, param[2])
+    NOISE_PARAMS(c3,  3, param[3])
+    {NULL}
+};
+
+AVFILTER_DEFINE_CLASS(noise);
+
+static const int8_t patt[4] = { -1, 0, 1, 0 };
+
+#define RAND_N(range) ((int) ((double) range * av_lfg_get(lfg) / (UINT_MAX + 1.0)))
+static int init_noise(NoiseContext *n, int comp)
+{
+    int8_t *noise = av_malloc(MAX_NOISE * sizeof(int8_t));
+    FilterParams *fp = &n->param[comp];
+    AVLFG *lfg = &n->param[comp].lfg;
+    int strength = fp->strength;
+    int flags = fp->flags;
+    int i, j;
+
+    if (!noise)
+        return AVERROR(ENOMEM);
+
+    av_lfg_init(&fp->lfg, fp->seed);
+
+    for (i = 0, j = 0; i < MAX_NOISE; i++, j++) {
+        if (flags & NOISE_UNIFORM) {
+            if (flags & NOISE_AVERAGED) {
+                if (flags & NOISE_PATTERN) {
+                    noise[i] = (RAND_N(strength) - strength / 2) / 6
+                        + patt[j % 4] * strength * 0.25 / 3;
+                } else {
+                    noise[i] = (RAND_N(strength) - strength / 2) / 3;
+                }
+            } else {
+                if (flags & NOISE_PATTERN) {
+                    noise[i] = (RAND_N(strength) - strength / 2) / 2
+                        + patt[j % 4] * strength * 0.25;
+                } else {
+                    noise[i] = RAND_N(strength) - strength / 2;
+                }
+            }
+        } else {
+            double x1, x2, w, y1;
+            do {
+                x1 = 2.0 * av_lfg_get(lfg) / (float)RAND_MAX - 1.0;
+                x2 = 2.0 * av_lfg_get(lfg) / (float)RAND_MAX - 1.0;
+                w = x1 * x1 + x2 * x2;
+            } while (w >= 1.0);
+
+            w   = sqrt((-2.0 * log(w)) / w);
+            y1  = x1 * w;
+            y1 *= strength / sqrt(3.0);
+            if (flags & NOISE_PATTERN) {
+                y1 /= 2;
+                y1 += patt[j % 4] * strength * 0.35;
+            }
+            y1 = av_clipf(y1, -128, 127);
+            if (flags & NOISE_AVERAGED)
+                y1 /= 3.0;
+            noise[i] = (int)y1;
+        }
+        if (RAND_N(6) == 0)
+            j--;
+    }
+
+    for (i = 0; i < MAX_RES; i++)
+        for (j = 0; j < 3; j++)
+            fp->prev_shift[i][j] = noise + (av_lfg_get(lfg) & (MAX_SHIFT - 1));
+
+    if (!n->rand_shift_init) {
+        for (i = 0; i < MAX_RES; i++)
+            n->rand_shift[i] = av_lfg_get(lfg) & (MAX_SHIFT - 1);
+        n->rand_shift_init = 1;
+    }
+
+    fp->noise = noise;
+    fp->shiftptr = 0;
+    return 0;
+}
+
+static av_cold int init(AVFilterContext *ctx, const char *args)
+{
+    NoiseContext *n = ctx->priv;
+    int ret, i;
+
+    n->class = &noise_class;
+    av_opt_set_defaults(n);
+
+    if ((ret = av_set_options_string(n, args, "=", ":")) < 0)
+        return ret;
+
+    for (i = 0; i < 4; i++) {
+        if (n->all.seed >= 0)
+            n->param[i].seed = n->all.seed;
+        else
+            n->param[i].seed = 123457;
+        if (n->all.strength)
+            n->param[i].strength = n->all.strength;
+        if (n->all.flags)
+            n->param[i].flags = n->all.flags;
+    }
+
+    for (i = 0; i < 4; i++) {
+        if (n->param[i].strength && ((ret = init_noise(n, i)) < 0))
+            return ret;
+    }
+
+    return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+    AVFilterFormats *formats = NULL;
+    int fmt;
+
+    for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
+        if (desc->flags & PIX_FMT_PLANAR && !((desc->comp[0].depth_minus1 + 1) & 7))
+            ff_add_format(&formats, fmt);
+    }
+
+    ff_set_common_formats(ctx, formats);
+    return 0;
+}
+
+static int config_input(AVFilterLink *inlink)
+{
+    NoiseContext *n = inlink->dst->priv;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+    int i, ret;
+
+    for (i = 0; i < desc->nb_components; i++)
+        n->nb_planes = FFMAX(n->nb_planes, desc->comp[i].plane);
+    n->nb_planes++;
+
+    if ((ret = av_image_fill_linesizes(n->linesize, inlink->format, inlink->w)) < 0)
+        return ret;
+
+    n->height[1] = n->height[2] = inlink->h >> desc->log2_chroma_h;
+    n->height[0] = n->height[3] = inlink->h;
+
+    return 0;
+}
+
+static void line_noise(uint8_t *dst, const uint8_t *src, int8_t *noise,
+                       int len, int shift)
+{
+    int i;
+
+    noise += shift;
+    for (i = 0; i < len; i++) {
+        int v = src[i] + noise[i];
+
+        dst[i] = av_clip_uint8(v);
+    }
+}
+
+static void line_noise_avg(uint8_t *dst, const uint8_t *src,
+                           int len, int8_t **shift)
+{
+    int i;
+    int8_t *src2 = (int8_t*)src;
+
+    for (i = 0; i < len; i++) {
+        const int n = shift[0][i] + shift[1][i] + shift[2][i];
+        dst[i] = src2[i] + ((n * src2[i]) >> 7);
+    }
+}
+
+static void noise(uint8_t *dst, const uint8_t *src,
+                  int dst_linesize, int src_linesize,
+                  int width, int height, NoiseContext *n, int comp)
+{
+    int8_t *noise = n->param[comp].noise;
+    int flags = n->param[comp].flags;
+    AVLFG *lfg = &n->param[comp].lfg;
+    int shift, y;
+
+    if (!noise) {
+        if (dst != src) {
+            for (y = 0; y < height; y++) {
+                memcpy(dst, src, width);
+                dst += dst_linesize;
+                src += src_linesize;
+            }
+        }
+
+        return;
+    }
+
+    for (y = 0; y < height; y++) {
+        if (flags & NOISE_TEMPORAL)
+            shift = av_lfg_get(lfg) & (MAX_SHIFT - 1);
+        else
+            shift = n->rand_shift[y];
+
+        if (!(flags & NOISE_QUALITY))
+            shift &= ~7;
+
+        if (flags & NOISE_AVERAGED) {
+            line_noise_avg(dst, src, width, n->param[comp].prev_shift[y]);
+            n->param[comp].prev_shift[y][n->param[comp].shiftptr] = noise + shift;
+        } else {
+            line_noise(dst, src, noise, width, shift);
+        }
+        dst += dst_linesize;
+        src += src_linesize;
+    }
+
+    n->param[comp].shiftptr++;
+    if (n->param[comp].shiftptr == 3)
+        n->param[comp].shiftptr = 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+{
+    NoiseContext *n = inlink->dst->priv;
+    AVFilterLink *outlink = inlink->dst->outputs[0];
+    AVFilterBufferRef *out;
+    int ret, i;
+
+    if (inpicref->perms & AV_PERM_WRITE) {
+        out = inpicref;
+    } else {
+        out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
+        if (!out) {
+            avfilter_unref_bufferp(&inpicref);
+            return AVERROR(ENOMEM);
+        }
+        avfilter_copy_buffer_ref_props(out, inpicref);
+    }
+
+    for (i = 0; i < n->nb_planes; i++)
+        noise(out->data[i], inpicref->data[i], out->linesize[i],
+              inpicref->linesize[i], n->linesize[i], n->height[i], n, i);
+
+    ret = ff_filter_frame(outlink, out);
+    if (inpicref != out)
+        avfilter_unref_buffer(inpicref);
+    return ret;
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+    NoiseContext *n = ctx->priv;
+    int i;
+
+    for (i = 0; i < 4; i++)
+        av_freep(&n->param[i].noise);
+    av_opt_free(n);
+}
+
+static const AVFilterPad noise_inputs[] = {
+    {
+        .name             = "default",
+        .type             = AVMEDIA_TYPE_VIDEO,
+        .get_video_buffer = ff_null_get_video_buffer,
+        .filter_frame     = filter_frame,
+        .config_props     = config_input,
+        .min_perms        = AV_PERM_READ,
+    },
+    { NULL }
+};
+
+static const AVFilterPad noise_outputs[] = {
+    {
+        .name          = "default",
+        .type          = AVMEDIA_TYPE_VIDEO,
+    },
+    { NULL }
+};
+
+AVFilter avfilter_vf_noise = {
+    .name          = "noise",
+    .description   = NULL_IF_CONFIG_SMALL("Add noise."),
+    .priv_size     = sizeof(NoiseContext),
+    .init          = init,
+    .uninit        = uninit,
+    .query_formats = query_formats,
+    .inputs        = noise_inputs,
+    .outputs       = noise_outputs,
+    .priv_class    = &noise_class,
+};
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_overlay.c b/mythtv/external/FFmpeg/libavfilter/vf_overlay.c
index b71ef41392e..1a76ecccd74 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_overlay.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_overlay.c
@@ -83,6 +83,7 @@ typedef struct {
     uint8_t overlay_is_packed_rgb;
     uint8_t overlay_rgba_map[4];
     uint8_t overlay_has_alpha;
+    enum OverlayFormat { OVERLAY_FORMAT_YUV420, OVERLAY_FORMAT_YUV444, OVERLAY_FORMAT_RGB, OVERLAY_FORMAT_NB} format;
 
     AVFilterBufferRef *overpicref;
     struct FFBufQueue queue_main;
@@ -91,6 +92,7 @@ typedef struct {
     int main_pix_step[4];       ///< steps per pixel for each plane of the main output
     int overlay_pix_step[4];    ///< steps per pixel for each plane of the overlay
     int hsub, vsub;             ///< chroma subsampling values
+    int shortest;               ///< terminate stream when the shortest input terminates
 
     char *x_expr, *y_expr;
 } OverlayContext;
@@ -101,8 +103,15 @@ typedef struct {
 static const AVOption overlay_options[] = {
     { "x", "set the x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
     { "y", "set the y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
-    {"rgb", "force packed RGB in input and output", OFFSET(allow_packed_rgb), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
-    {NULL},
+    { "rgb", "force packed RGB in input and output (deprecated)", OFFSET(allow_packed_rgb), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
+    { "shortest", "force termination when the shortest input terminates", OFFSET(shortest), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
+
+    { "format", "set output format", OFFSET(format), AV_OPT_TYPE_INT, {.i64=OVERLAY_FORMAT_YUV420}, 0, OVERLAY_FORMAT_NB-1, FLAGS, "format" },
+    { "yuv420", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV420}, .flags = FLAGS, .unit = "format" },
+    { "yuv444", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV444}, .flags = FLAGS, .unit = "format" },
+    { "rgb",    "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_RGB},    .flags = FLAGS, .unit = "format" },
+
+    { NULL }
 };
 
 AVFILTER_DEFINE_CLASS(overlay);
@@ -111,11 +120,21 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     OverlayContext *over = ctx->priv;
     static const char *shorthand[] = { "x", "y", NULL };
+    int ret;
 
     over->class = &overlay_class;
     av_opt_set_defaults(over);
 
-    return av_opt_set_from_string(over, args, shorthand, "=", ":");
+    ret = av_opt_set_from_string(over, args, shorthand, "=", ":");
+    if (ret < 0)
+        return ret;
+
+    if (over->allow_packed_rgb) {
+        av_log(ctx, AV_LOG_WARNING,
+               "The rgb option is deprecated and is overriding the format option, use format instead\n");
+        over->format = OVERLAY_FORMAT_RGB;
+    }
+    return 0;
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
@@ -134,8 +153,20 @@ static int query_formats(AVFilterContext *ctx)
     OverlayContext *over = ctx->priv;
 
     /* overlay formats contains alpha, for avoiding conversion with alpha information loss */
-    static const enum AVPixelFormat main_pix_fmts_yuv[] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE };
-    static const enum AVPixelFormat overlay_pix_fmts_yuv[] = { AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE };
+    static const enum AVPixelFormat main_pix_fmts_yuv420[] = {
+        AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE
+    };
+    static const enum AVPixelFormat overlay_pix_fmts_yuv420[] = {
+        AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE
+    };
+
+    static const enum AVPixelFormat main_pix_fmts_yuv444[] = {
+        AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVA444P, AV_PIX_FMT_NONE
+    };
+    static const enum AVPixelFormat overlay_pix_fmts_yuv444[] = {
+        AV_PIX_FMT_YUVA444P, AV_PIX_FMT_NONE
+    };
+
     static const enum AVPixelFormat main_pix_fmts_rgb[] = {
         AV_PIX_FMT_ARGB,  AV_PIX_FMT_RGBA,
         AV_PIX_FMT_ABGR,  AV_PIX_FMT_BGRA,
@@ -151,12 +182,21 @@ static int query_formats(AVFilterContext *ctx)
     AVFilterFormats *main_formats;
     AVFilterFormats *overlay_formats;
 
-    if (over->allow_packed_rgb) {
+    switch (over->format) {
+    case OVERLAY_FORMAT_YUV420:
+        main_formats    = ff_make_format_list(main_pix_fmts_yuv420);
+        overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv420);
+        break;
+    case OVERLAY_FORMAT_YUV444:
+        main_formats    = ff_make_format_list(main_pix_fmts_yuv444);
+        overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv444);
+        break;
+    case OVERLAY_FORMAT_RGB:
         main_formats    = ff_make_format_list(main_pix_fmts_rgb);
         overlay_formats = ff_make_format_list(overlay_pix_fmts_rgb);
-    } else {
-        main_formats    = ff_make_format_list(main_pix_fmts_yuv);
-        overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv);
+        break;
+    default:
+        av_assert0(0);
     }
 
     ff_formats_ref(main_formats,    &ctx->inputs [MAIN   ]->out_formats);
@@ -167,7 +207,8 @@ static int query_formats(AVFilterContext *ctx)
 }
 
 static const enum AVPixelFormat alpha_pix_fmts[] = {
-    AV_PIX_FMT_YUVA420P, AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, AV_PIX_FMT_RGBA,
+    AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA444P,
+    AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, AV_PIX_FMT_RGBA,
     AV_PIX_FMT_BGRA, AV_PIX_FMT_NONE
 };
 
@@ -234,13 +275,13 @@ static int config_input_overlay(AVFilterLink *inlink)
     if (over->x < 0 || over->y < 0 ||
         over->x + var_values[VAR_OVERLAY_W] > var_values[VAR_MAIN_W] ||
         over->y + var_values[VAR_OVERLAY_H] > var_values[VAR_MAIN_H]) {
-        av_log(ctx, AV_LOG_ERROR,
-               "Overlay area (%d,%d)<->(%d,%d) not within the main area (0,0)<->(%d,%d) or zero-sized\n",
+        av_log(ctx, AV_LOG_WARNING,
+               "Overlay area with coordinates x1:%d y1:%d x2:%d y2:%d "
+               "is not completely contained within the output with size %dx%d\n",
                over->x, over->y,
                (int)(over->x + var_values[VAR_OVERLAY_W]),
                (int)(over->y + var_values[VAR_OVERLAY_H]),
                (int)var_values[VAR_MAIN_W], (int)var_values[VAR_MAIN_H]);
-        return AVERROR(EINVAL);
     }
     return 0;
 
@@ -273,23 +314,23 @@ static int config_output(AVFilterLink *outlink)
 
 /**
  * Blend image in src to destination buffer dst at position (x, y).
- *
- * It is assumed that the src image at position (x, y) is contained in
- * dst.
  */
 static void blend_image(AVFilterContext *ctx,
                         AVFilterBufferRef *dst, AVFilterBufferRef *src,
                         int x, int y)
 {
     OverlayContext *over = ctx->priv;
-    int i, j, k;
-    int width   = src->video->w;
-    int height  = src->video->h;
+    int i, imax, j, jmax, k, kmax;
+    const int src_w = src->video->w;
+    const int src_h = src->video->h;
+    const int dst_w = dst->video->w;
+    const int dst_h = dst->video->h;
+
+    if (x >= dst_w || x+dst_w  < 0 ||
+        y >= dst_h || y+dst_h < 0)
+        return; /* no intersection */
 
     if (over->main_is_packed_rgb) {
-        uint8_t *dp = dst->data[0] + x * over->main_pix_step[0] +
-                      y * dst->linesize[0];
-        uint8_t *sp = src->data[0];
         uint8_t alpha;          ///< the amount of overlay to blend on to main
         const int dr = over->main_rgba_map[R];
         const int dg = over->main_rgba_map[G];
@@ -302,9 +343,18 @@ static void blend_image(AVFilterContext *ctx,
         const int sa = over->overlay_rgba_map[A];
         const int sstep = over->overlay_pix_step[0];
         const int main_has_alpha = over->main_has_alpha;
-        for (i = 0; i < height; i++) {
-            uint8_t *d = dp, *s = sp;
-            for (j = 0; j < width; j++) {
+        uint8_t *s, *sp, *d, *dp;
+
+        i = FFMAX(-y, 0);
+        sp = src->data[0] + i     * src->linesize[0];
+        dp = dst->data[0] + (y+i) * dst->linesize[0];
+
+        for (imax = FFMIN(-y + dst_h, src_h); i < imax; i++) {
+            j = FFMAX(-x, 0);
+            s = sp + j     * sstep;
+            d = dp + (x+j) * dstep;
+
+            for (jmax = FFMIN(-x + dst_w, src_w); j < jmax; j++) {
                 alpha = s[sa];
 
                 // if the main channel has an alpha channel, alpha has to be calculated
@@ -350,13 +400,19 @@ static void blend_image(AVFilterContext *ctx,
     } else {
         const int main_has_alpha = over->main_has_alpha;
         if (main_has_alpha) {
-            uint8_t *da = dst->data[3] + x * over->main_pix_step[3] +
-                          y * dst->linesize[3];
-            uint8_t *sa = src->data[3];
             uint8_t alpha;          ///< the amount of overlay to blend on to main
-            for (i = 0; i < height; i++) {
-                uint8_t *d = da, *s = sa;
-                for (j = 0; j < width; j++) {
+            uint8_t *s, *sa, *d, *da;
+
+            i = FFMAX(-y, 0);
+            sa = src->data[3] + i     * src->linesize[3];
+            da = dst->data[3] + (y+i) * dst->linesize[3];
+
+            for (imax = FFMIN(-y + dst_h, src_h); i < imax; i++) {
+                j = FFMAX(-x, 0);
+                s = sa + j;
+                d = da + x+j;
+
+                for (jmax = FFMIN(-x + dst_w, src_w); j < jmax; j++) {
                     alpha = *s;
                     if (alpha != 0 && alpha != 255) {
                         uint8_t alpha_d = *d;
@@ -382,24 +438,36 @@ static void blend_image(AVFilterContext *ctx,
         for (i = 0; i < 3; i++) {
             int hsub = i ? over->hsub : 0;
             int vsub = i ? over->vsub : 0;
-            uint8_t *dp = dst->data[i] + (x >> hsub) +
-                (y >> vsub) * dst->linesize[i];
-            uint8_t *sp = src->data[i];
-            uint8_t *ap = src->data[3];
-            int wp = FFALIGN(width, 1<> hsub;
-            int hp = FFALIGN(height, 1<> vsub;
-            for (j = 0; j < hp; j++) {
-                uint8_t *d = dp, *s = sp, *a = ap;
-                for (k = 0; k < wp; k++) {
-                    // average alpha for color components, improve quality
+            int src_wp = FFALIGN(src_w, 1<> hsub;
+            int src_hp = FFALIGN(src_h, 1<> vsub;
+            int dst_wp = FFALIGN(dst_w, 1<> hsub;
+            int dst_hp = FFALIGN(dst_h, 1<> vsub;
+            int yp = y>>vsub;
+            int xp = x>>hsub;
+            uint8_t *s, *sp, *d, *dp, *a, *ap;
+
+            j = FFMAX(-yp, 0);
+            sp = src->data[i] + j         * src->linesize[i];
+            dp = dst->data[i] + (yp+j)    * dst->linesize[i];
+            ap = src->data[3] + (j<linesize[3];
+
+            for (jmax = FFMIN(-yp + dst_hp, src_hp); j < jmax; j++) {
+                k = FFMAX(-xp, 0);
+                d = dp + xp+k;
+                s = sp + k;
+                a = ap + (k<linesize[3]] +
                                  a[1] + a[src->linesize[3]+1]) >> 2;
                     } else if (hsub || vsub) {
-                        alpha_h = hsub && k+1 < wp ?
+                        alpha_h = hsub && k+1 < src_wp ?
                             (a[0] + a[1]) >> 1 : a[0];
-                        alpha_v = vsub && j+1 < hp ?
+                        alpha_v = vsub && j+1 < src_hp ?
                             (a[0] + a[src->linesize[3]]) >> 1 : a[0];
                         alpha = (alpha_v + alpha_h) >> 1;
                     } else
@@ -409,13 +477,13 @@ static void blend_image(AVFilterContext *ctx,
                     if (main_has_alpha && alpha != 0 && alpha != 255) {
                         // average alpha for color components, improve quality
                         uint8_t alpha_d;
-                        if (hsub && vsub && j+1 < hp && k+1 < wp) {
+                        if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
                             alpha_d = (d[0] + d[src->linesize[3]] +
                                        d[1] + d[src->linesize[3]+1]) >> 2;
                         } else if (hsub || vsub) {
-                            alpha_h = hsub && k+1 < wp ?
+                            alpha_h = hsub && k+1 < src_wp ?
                                 (d[0] + d[1]) >> 1 : d[0];
-                            alpha_v = vsub && j+1 < hp ?
+                            alpha_v = vsub && j+1 < src_hp ?
                                 (d[0] + d[src->linesize[3]]) >> 1 : d[0];
                             alpha_d = (alpha_v + alpha_h) >> 1;
                         } else
@@ -473,6 +541,7 @@ static int try_filter_frame(AVFilterContext *ctx, AVFilterBufferRef *mainpic)
     if (over->overpicref)
         blend_image(ctx, mainpic, over->overpicref, over->x, over->y);
     ret = ff_filter_frame(ctx->outputs[0], mainpic);
+    av_assert1(ret != AVERROR(EAGAIN));
     over->frame_requested = 0;
     return ret;
 }
@@ -551,6 +620,8 @@ static int request_frame(AVFilterLink *outlink)
         /* EOF on main is reported immediately */
         if (ret == AVERROR_EOF && input == OVERLAY) {
             over->overlay_eof = 1;
+            if (over->shortest)
+                return ret;
             if ((ret = try_filter_next_frame(ctx)) != AVERROR(EAGAIN))
                 return ret;
             ret = 0; /* continue requesting frames on main */
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_pad.c b/mythtv/external/FFmpeg/libavfilter/vf_pad.c
index bbd37b160c6..5c146f208f3 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_pad.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_pad.c
@@ -35,6 +35,7 @@
 #include "libavutil/colorspace.h"
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/mathematics.h"
 #include "drawutils.h"
@@ -76,40 +77,61 @@ static int query_formats(AVFilterContext *ctx)
 }
 
 typedef struct {
+    const AVClass *class;
     int w, h;               ///< output dimensions, a value of 0 will result in the input size
     int x, y;               ///< offsets of the input area with respect to the padded area
     int in_w, in_h;         ///< width and height for the padded input video, which has to be aligned to the chroma values in order to avoid chroma issues
 
-    char w_expr[256];       ///< width  expression string
-    char h_expr[256];       ///< height expression string
-    char x_expr[256];       ///< width  expression string
-    char y_expr[256];       ///< height expression string
-
+    char *w_expr;       ///< width  expression string
+    char *h_expr;       ///< height expression string
+    char *x_expr;       ///< width  expression string
+    char *y_expr;       ///< height expression string
+    char *color_str;
     uint8_t rgba_color[4];  ///< color for the padding area
     FFDrawContext draw;
     FFDrawColor color;
 } PadContext;
 
+#define OFFSET(x) offsetof(PadContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption pad_options[] = {
+    { "width",  "set the pad area width expression",       OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "w",      "set the pad area width expression",       OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "height", "set the pad area height expression",      OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "h",      "set the pad area height expression",      OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "x",      "set the x offset expression for the input image position", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "y",      "set the y offset expression for the input image position", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "color",  "set the color of the padded area border", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = "black"}, .flags = FLAGS },
+    {NULL}
+};
+
+AVFILTER_DEFINE_CLASS(pad);
+
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     PadContext *pad = ctx->priv;
-    char color_string[128] = "black";
+    static const char *shorthand[] = { "width", "height", "x", "y", "color", NULL };
+    int ret;
 
-    av_strlcpy(pad->w_expr, "iw", sizeof(pad->w_expr));
-    av_strlcpy(pad->h_expr, "ih", sizeof(pad->h_expr));
-    av_strlcpy(pad->x_expr, "0" , sizeof(pad->w_expr));
-    av_strlcpy(pad->y_expr, "0" , sizeof(pad->h_expr));
+    pad->class = &pad_class;
+    av_opt_set_defaults(pad);
 
-    if (args)
-        sscanf(args, "%255[^:]:%255[^:]:%255[^:]:%255[^:]:%127s",
-               pad->w_expr, pad->h_expr, pad->x_expr, pad->y_expr, color_string);
+    if ((ret = av_opt_set_from_string(pad, args, shorthand, "=", ":")) < 0)
+        return ret;
 
-    if (av_parse_color(pad->rgba_color, color_string, -1, ctx) < 0)
+    if (av_parse_color(pad->rgba_color, pad->color_str, -1, ctx) < 0)
         return AVERROR(EINVAL);
 
     return 0;
 }
 
+static av_cold void uninit(AVFilterContext *ctx)
+{
+    PadContext *pad = ctx->priv;
+    av_opt_free(pad);
+}
+
 static int config_input(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
@@ -368,9 +390,11 @@ AVFilter avfilter_vf_pad = {
 
     .priv_size     = sizeof(PadContext),
     .init          = init,
+    .uninit        = uninit,
     .query_formats = query_formats,
 
     .inputs    = avfilter_vf_pad_inputs,
 
     .outputs   = avfilter_vf_pad_outputs,
+    .priv_class = &pad_class,
 };
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_stereo3d.c b/mythtv/external/FFmpeg/libavfilter/vf_stereo3d.c
new file mode 100644
index 00000000000..37579157112
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavfilter/vf_stereo3d.c
@@ -0,0 +1,479 @@
+/*
+ * Copyright (c) 2010 Gordon Schmidt  s2000.tu-chemnitz.de>
+ * Copyright (c) 2013 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 "libavutil/avassert.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/pixdesc.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+enum StereoCode {
+    ANAGLYPH_RC_GRAY,   // anaglyph red/cyan gray
+    ANAGLYPH_RC_HALF,   // anaglyph red/cyan half colored
+    ANAGLYPH_RC_COLOR,  // anaglyph red/cyan colored
+    ANAGLYPH_RC_DUBOIS, // anaglyph red/cyan dubois
+    ANAGLYPH_GM_GRAY,   // anaglyph green/magenta gray
+    ANAGLYPH_GM_HALF,   // anaglyph green/magenta half colored
+    ANAGLYPH_GM_COLOR,  // anaglyph green/magenta colored
+    ANAGLYPH_GM_DUBOIS, // anaglyph green/magenta dubois
+    ANAGLYPH_YB_GRAY,   // anaglyph yellow/blue gray
+    ANAGLYPH_YB_HALF,   // anaglyph yellow/blue half colored
+    ANAGLYPH_YB_COLOR,  // anaglyph yellow/blue colored
+    ANAGLYPH_YB_DUBOIS, // anaglyph yellow/blue dubois
+    ANAGLYPH_RB_GRAY,   // anaglyph red/blue gray
+    ANAGLYPH_RG_GRAY,   // anaglyph red/green gray
+    MONO_L,             // mono output for debugging (left eye only)
+    MONO_R,             // mono output for debugging (right eye only)
+    INTERLEAVE_ROWS_LR, // row-interleave (left eye has top row)
+    INTERLEAVE_ROWS_RL, // row-interleave (right eye has top row)
+    SIDE_BY_SIDE_LR,    // side by side parallel (left eye left, right eye right)
+    SIDE_BY_SIDE_RL,    // side by side crosseye (right eye left, left eye right)
+    SIDE_BY_SIDE_2_LR,  // side by side parallel with half width resolution
+    SIDE_BY_SIDE_2_RL,  // side by side crosseye with half width resolution
+    ABOVE_BELOW_LR,     // above-below (left eye above, right eye below)
+    ABOVE_BELOW_RL,     // above-below (right eye above, left eye below)
+    ABOVE_BELOW_2_LR,   // above-below with half height resolution
+    ABOVE_BELOW_2_RL,   // above-below with half height resolution
+    STEREO_CODE_COUNT   // TODO: needs autodetection
+};
+
+typedef struct StereoComponent {
+    enum StereoCode format;
+    int width, height;
+    int off_left, off_right;
+    int row_left, row_right;
+} StereoComponent;
+
+static const int ana_coeff[][3][6] = {
+  [ANAGLYPH_RB_GRAY]   =
+    {{19595, 38470,  7471,     0,     0,     0},
+     {    0,     0,     0,     0,     0,     0},
+     {    0,     0,     0, 19595, 38470,  7471}},
+  [ANAGLYPH_RG_GRAY]   =
+    {{19595, 38470,  7471,     0,     0,     0},
+     {    0,     0,     0, 19595, 38470,  7471},
+     {    0,     0,     0,     0,     0,     0}},
+  [ANAGLYPH_RC_GRAY]   =
+    {{19595, 38470,  7471,     0,     0,     0},
+     {    0,     0,     0, 19595, 38470,  7471},
+     {    0,     0,     0, 19595, 38470,  7471}},
+  [ANAGLYPH_RC_HALF]   =
+    {{19595, 38470,  7471,     0,     0,     0},
+     {    0,     0,     0,     0, 65536,     0},
+     {    0,     0,     0,     0,     0, 65536}},
+  [ANAGLYPH_RC_COLOR]  =
+    {{65536,     0,     0,     0,     0,     0},
+     {    0,     0,     0,     0, 65536,     0},
+     {    0,     0,     0,     0,     0, 65536}},
+  [ANAGLYPH_RC_DUBOIS] =
+    {{29891, 32800, 11559, -2849, -5763,  -102},
+     {-2627, -2479, -1033, 24804, 48080, -1209},
+     { -997, -1350,  -358, -4729, -7403, 80373}},
+  [ANAGLYPH_GM_GRAY]   =
+    {{    0,     0,     0, 19595, 38470,  7471},
+     {19595, 38470,  7471,     0,     0,     0},
+     {    0,     0,     0, 19595, 38470,  7471}},
+  [ANAGLYPH_GM_HALF]   =
+    {{    0,     0,     0, 65536,     0,     0},
+     {19595, 38470,  7471,     0,     0,     0},
+     {    0,     0,     0,     0,     0, 65536}},
+  [ANAGLYPH_GM_COLOR]  =
+    {{    0,     0,     0, 65536,     0,     0},
+     {    0, 65536,     0,     0,     0,     0},
+     {    0,     0,     0,     0,     0, 65536}},
+  [ANAGLYPH_GM_DUBOIS]  =
+    {{-4063,-10354, -2556, 34669, 46203,  1573},
+     {18612, 43778,  9372, -1049,  -983, -4260},
+     { -983, -1769,  1376,   590,  4915, 61407}},
+  [ANAGLYPH_YB_GRAY]   =
+    {{    0,     0,     0, 19595, 38470,  7471},
+     {    0,     0,     0, 19595, 38470,  7471},
+     {19595, 38470,  7471,     0,     0,     0}},
+  [ANAGLYPH_YB_HALF]   =
+    {{    0,     0,     0, 65536,     0,     0},
+     {    0,     0,     0,     0, 65536,     0},
+     {19595, 38470,  7471,     0,     0,     0}},
+  [ANAGLYPH_YB_COLOR]  =
+    {{    0,     0,     0, 65536,     0,     0},
+     {    0,     0,     0,     0, 65536,     0},
+     {    0,     0, 65536,     0,     0,     0}},
+  [ANAGLYPH_YB_DUBOIS] =
+    {{65535,-12650,18451,   -987, -7590, -1049},
+     {-1604, 56032, 4196,    370,  3826, -1049},
+     {-2345,-10676, 1358,   5801, 11416, 56217}},
+};
+
+typedef struct Stereo3DContext {
+    const AVClass *class;
+    StereoComponent in, out;
+    int width, height;
+    int row_step;
+    int ana_matrix[3][6];
+} Stereo3DContext;
+
+#define OFFSET(x) offsetof(Stereo3DContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption stereo3d_options[] = {
+    { "in",    "set input format",  OFFSET(in.format),  AV_OPT_TYPE_INT, {.i64=SIDE_BY_SIDE_LR}, SIDE_BY_SIDE_LR, ABOVE_BELOW_2_RL, FLAGS, "in"},
+    { "ab2l",  "above below half height left first",  0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR},  0, 0, FLAGS, "in" },
+    { "ab2r",  "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL},  0, 0, FLAGS, "in" },
+    { "abl",   "above below left first",              0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR},    0, 0, FLAGS, "in" },
+    { "abr",   "above below right first",             0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL},    0, 0, FLAGS, "in" },
+    { "sbs2l", "side by side half width left first",  0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_LR}, 0, 0, FLAGS, "in" },
+    { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL}, 0, 0, FLAGS, "in" },
+    { "sbsl",  "side by side left first",             0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR},   0, 0, FLAGS, "in" },
+    { "sbsr",  "side by side right first",            0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL},   0, 0, FLAGS, "in" },
+    { "out",   "set output format", OFFSET(out.format), AV_OPT_TYPE_INT, {.i64=ANAGLYPH_RC_DUBOIS}, 0, STEREO_CODE_COUNT-1, FLAGS, "out"},
+    { "ab2l",  "above below half height left first",  0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR},   0, 0, FLAGS, "out" },
+    { "ab2r",  "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL},   0, 0, FLAGS, "out" },
+    { "abl",   "above below left first",              0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR},     0, 0, FLAGS, "out" },
+    { "abr",   "above below right first",             0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL},     0, 0, FLAGS, "out" },
+    { "agmc",  "anaglyph green magenta color",        0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_COLOR},  0, 0, FLAGS, "out" },
+    { "agmd",  "anaglyph green magenta dubois",       0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_DUBOIS}, 0, 0, FLAGS, "out" },
+    { "agmg",  "anaglyph green magenta gray",         0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_GRAY},   0, 0, FLAGS, "out" },
+    { "agmh",  "anaglyph green magenta half color",   0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_HALF},   0, 0, FLAGS, "out" },
+    { "arbg",  "anaglyph red blue gray",              0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RB_GRAY},   0, 0, FLAGS, "out" },
+    { "arcc",  "anaglyph red cyan color",             0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_COLOR},  0, 0, FLAGS, "out" },
+    { "arcd",  "anaglyph red cyan dubois",            0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_DUBOIS}, 0, 0, FLAGS, "out" },
+    { "arcg",  "anaglyph red cyan gray",              0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_GRAY},   0, 0, FLAGS, "out" },
+    { "arch",  "anaglyph red cyan half color",        0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_HALF},   0, 0, FLAGS, "out" },
+    { "argg",  "anaglyph red green gray",             0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RG_GRAY},   0, 0, FLAGS, "out" },
+    { "aybc",  "anaglyph yellow blue color",          0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_COLOR},  0, 0, FLAGS, "out" },
+    { "aybd",  "anaglyph yellow blue dubois",         0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_DUBOIS}, 0, 0, FLAGS, "out" },
+    { "aybg",  "anaglyph yellow blue gray",           0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_GRAY},   0, 0, FLAGS, "out" },
+    { "aybh",  "anaglyph yellow blue half color",     0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_HALF},   0, 0, FLAGS, "out" },
+    { "irl",   "interleave rows left first",          0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_LR}, 0, 0, FLAGS, "out" },
+    { "irr",   "interleave rows right first",         0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_RL}, 0, 0, FLAGS, "out" },
+    { "ml",    "mono left",                           0, AV_OPT_TYPE_CONST, {.i64=MONO_L},             0, 0, FLAGS, "out" },
+    { "mr",    "mono right",                          0, AV_OPT_TYPE_CONST, {.i64=MONO_R},             0, 0, FLAGS, "out" },
+    { "sbs2l", "side by side half width left first",  0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_LR},  0, 0, FLAGS, "out" },
+    { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL},  0, 0, FLAGS, "out" },
+    { "sbsl",  "side by side left first",             0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR},    0, 0, FLAGS, "out" },
+    { "sbsr",  "side by side right first",            0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL},    0, 0, FLAGS, "out" },
+    {NULL},
+};
+
+AVFILTER_DEFINE_CLASS(stereo3d);
+
+static av_cold int init(AVFilterContext *ctx, const char *args)
+{
+    Stereo3DContext *s = ctx->priv;
+    static const char *shorthand[] = { "in", "out", NULL };
+    int ret;
+
+    s->class = &stereo3d_class;
+    av_opt_set_defaults(s);
+
+    if ((ret = av_opt_set_from_string(s, args, shorthand, "=", ":")) < 0)
+        return ret;
+
+    return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+    static const enum AVPixelFormat pix_fmts[] = {
+        AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
+    };
+
+    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+
+    return 0;
+}
+
+static int config_output(AVFilterLink *outlink)
+{
+    AVFilterContext *ctx = outlink->src;
+    AVFilterLink *inlink = ctx->inputs[0];
+    Stereo3DContext *s = ctx->priv;
+    AVRational aspect = inlink->sample_aspect_ratio;
+
+    s->in.width     =
+    s->width        = inlink->w;
+    s->in.height    =
+    s->height       = inlink->h;
+    s->row_step     = 1;
+    s->in.off_left  =
+    s->in.off_right =
+    s->in.row_left  =
+    s->in.row_right = 0;
+
+    switch (s->in.format) {
+    case SIDE_BY_SIDE_2_LR:
+        aspect.num     *= 2;
+    case SIDE_BY_SIDE_LR:
+        s->width        = inlink->w / 2;
+        s->in.off_right = s->width * 3;
+        break;
+    case SIDE_BY_SIDE_2_RL:
+        aspect.num     *= 2;
+    case SIDE_BY_SIDE_RL:
+        s->width        = inlink->w / 2;
+        s->in.off_left  = s->width * 3;
+        break;
+    case ABOVE_BELOW_2_LR:
+        aspect.den     *= 2;
+    case ABOVE_BELOW_LR:
+        s->in.row_right =
+        s->height       = inlink->h / 2;
+        break;
+    case ABOVE_BELOW_2_RL:
+        aspect.den     *= 2;
+    case ABOVE_BELOW_RL:
+        s->in.row_left  =
+        s->height       = inlink->h / 2;
+        break;
+    default:
+        av_log(ctx, AV_LOG_ERROR, "input format %d is not supported\n", s->in.format);
+        return AVERROR(EINVAL);
+    }
+
+    s->out.width     = s->width;
+    s->out.height    = s->height;
+    s->out.off_left  =
+    s->out.off_right =
+    s->out.row_left  =
+    s->out.row_right = 0;
+
+    switch (s->out.format) {
+    case ANAGLYPH_RB_GRAY:
+    case ANAGLYPH_RG_GRAY:
+    case ANAGLYPH_RC_GRAY:
+    case ANAGLYPH_RC_HALF:
+    case ANAGLYPH_RC_COLOR:
+    case ANAGLYPH_RC_DUBOIS:
+    case ANAGLYPH_GM_GRAY:
+    case ANAGLYPH_GM_HALF:
+    case ANAGLYPH_GM_COLOR:
+    case ANAGLYPH_GM_DUBOIS:
+    case ANAGLYPH_YB_GRAY:
+    case ANAGLYPH_YB_HALF:
+    case ANAGLYPH_YB_COLOR:
+    case ANAGLYPH_YB_DUBOIS:
+        memcpy(s->ana_matrix, ana_coeff[s->out.format], sizeof(s->ana_matrix));
+        break;
+    case SIDE_BY_SIDE_2_LR:
+        aspect.num      /= 2;
+    case SIDE_BY_SIDE_LR:
+        s->out.width     =
+        s->out.off_right = s->width * 3;
+        break;
+    case SIDE_BY_SIDE_2_RL:
+        aspect.num      /= 2;
+    case SIDE_BY_SIDE_RL:
+        s->out.width     = s->width * 2;
+        s->out.off_left  = s->width * 3;
+        break;
+    case ABOVE_BELOW_2_LR:
+        aspect.den      /= 2;
+    case ABOVE_BELOW_LR:
+        s->out.height    = s->height * 2;
+        s->out.row_right = s->height;
+        break;
+    case ABOVE_BELOW_2_RL:
+        aspect.den      /= 2;
+    case ABOVE_BELOW_RL:
+        s->out.height    = s->height * 2;
+        s->out.row_left  = s->height;
+        break;
+    case INTERLEAVE_ROWS_LR:
+        s->row_step      = 2;
+        s->height        = s->height / 2;
+        s->out.off_right = s->width * 3;
+        s->in.off_right += s->in.width * 3;
+        break;
+    case INTERLEAVE_ROWS_RL:
+        s->row_step      = 2;
+        s->height        = s->height / 2;
+        s->out.off_left  = s->width * 3;
+        s->in.off_left  += s->in.width * 3;
+        break;
+    case MONO_R:
+        s->in.off_left   = s->in.off_right;
+        s->in.row_left   = s->in.row_right;
+    case MONO_L:
+        break;
+    default:
+        av_log(ctx, AV_LOG_ERROR, "output format is not supported\n");
+        return AVERROR(EINVAL);
+    }
+
+    outlink->w = s->out.width;
+    outlink->h = s->out.height;
+    outlink->sample_aspect_ratio = aspect;
+
+    return 0;
+}
+
+static inline uint8_t ana_convert(const int *coeff, uint8_t *left, uint8_t *right)
+{
+    int sum;
+
+    sum  = coeff[0] * left[0] + coeff[3] * right[0]; //red in
+    sum += coeff[1] * left[1] + coeff[4] * right[1]; //green in
+    sum += coeff[2] * left[2] + coeff[5] * right[2]; //blue in
+
+    return av_clip_uint8(sum >> 16);
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+{
+    AVFilterContext *ctx  = inlink->dst;
+    Stereo3DContext *s = ctx->priv;
+    AVFilterLink *outlink = ctx->outputs[0];
+    AVFilterBufferRef *out;
+    int out_off_left, out_off_right;
+    int in_off_left, in_off_right;
+    int ret;
+
+    out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
+    if (!out) {
+        avfilter_unref_bufferp(&inpicref);
+        return AVERROR(ENOMEM);
+    }
+
+    out->pts = inpicref->pts;
+    out->pos = inpicref->pos;
+
+    in_off_left   = s->in.row_left  * inpicref->linesize[0] + s->in.off_left;
+    in_off_right  = s->in.row_right * inpicref->linesize[0] + s->in.off_right;
+    out_off_left  = s->out.row_left  * out->linesize[0] + s->out.off_left;
+    out_off_right = s->out.row_right * out->linesize[0] + s->out.off_right;
+
+    switch (s->out.format) {
+    case SIDE_BY_SIDE_LR:
+    case SIDE_BY_SIDE_RL:
+    case SIDE_BY_SIDE_2_LR:
+    case SIDE_BY_SIDE_2_RL:
+    case ABOVE_BELOW_LR:
+    case ABOVE_BELOW_RL:
+    case ABOVE_BELOW_2_LR:
+    case ABOVE_BELOW_2_RL:
+    case INTERLEAVE_ROWS_LR:
+    case INTERLEAVE_ROWS_RL:
+        av_image_copy_plane(out->data[0] + out_off_left,
+                            out->linesize[0] * s->row_step,
+                            inpicref->data[0] + in_off_left,
+                            inpicref->linesize[0] * s->row_step,
+                            3 * s->width, s->height);
+        av_image_copy_plane(out->data[0] + out_off_right,
+                            out->linesize[0] * s->row_step,
+                            inpicref->data[0] + in_off_right,
+                            inpicref->linesize[0] * s->row_step,
+                            3 * s->width, s->height);
+        break;
+    case MONO_L:
+    case MONO_R:
+        av_image_copy_plane(out->data[0], out->linesize[0],
+                            inpicref->data[0] + in_off_left,
+                            inpicref->linesize[0],
+                            3 * s->width, s->height);
+        break;
+    case ANAGLYPH_RB_GRAY:
+    case ANAGLYPH_RG_GRAY:
+    case ANAGLYPH_RC_GRAY:
+    case ANAGLYPH_RC_HALF:
+    case ANAGLYPH_RC_COLOR:
+    case ANAGLYPH_RC_DUBOIS:
+    case ANAGLYPH_GM_GRAY:
+    case ANAGLYPH_GM_HALF:
+    case ANAGLYPH_GM_COLOR:
+    case ANAGLYPH_GM_DUBOIS:
+    case ANAGLYPH_YB_GRAY:
+    case ANAGLYPH_YB_HALF:
+    case ANAGLYPH_YB_COLOR:
+    case ANAGLYPH_YB_DUBOIS: {
+        int i, x, y, il, ir, o;
+        uint8_t *src = inpicref->data[0];
+        uint8_t *dst = out->data[0];
+        int out_width = s->out.width;
+        int *ana_matrix[3];
+
+        for (i = 0; i < 3; i++)
+            ana_matrix[i] = s->ana_matrix[i];
+
+        for (y = 0; y < s->out.height; y++) {
+            o   = out->linesize[0] * y;
+            il  = in_off_left  + y * inpicref->linesize[0];
+            ir  = in_off_right + y * inpicref->linesize[0];
+            for (x = 0; x < out_width; x++, il += 3, ir += 3, o+= 3) {
+                dst[o    ] = ana_convert(ana_matrix[0], src + il, src + ir);
+                dst[o + 1] = ana_convert(ana_matrix[1], src + il, src + ir);
+                dst[o + 2] = ana_convert(ana_matrix[2], src + il, src + ir);
+            }
+        }
+        break;
+    }
+    default:
+        av_assert0(0);
+    }
+
+    ret = ff_filter_frame(outlink, out);
+    avfilter_unref_bufferp(&inpicref);
+    if (ret < 0)
+        return ret;
+    return 0;
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+    Stereo3DContext *s = ctx->priv;
+
+    av_opt_free(s);
+}
+
+static const AVFilterPad stereo3d_inputs[] = {
+    {
+        .name             = "default",
+        .type             = AVMEDIA_TYPE_VIDEO,
+        .get_video_buffer = ff_null_get_video_buffer,
+        .filter_frame     = filter_frame,
+        .min_perms        = AV_PERM_READ,
+    },
+    { NULL }
+};
+
+static const AVFilterPad stereo3d_outputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_VIDEO,
+        .config_props = config_output,
+        .min_perms    = AV_PERM_WRITE,
+    },
+    { NULL }
+};
+
+AVFilter avfilter_vf_stereo3d = {
+    .name          = "stereo3d",
+    .description   = NULL_IF_CONFIG_SMALL("Convert video stereoscopic 3D view."),
+    .priv_size     = sizeof(Stereo3DContext),
+    .init          = init,
+    .uninit        = uninit,
+    .query_formats = query_formats,
+    .inputs        = stereo3d_inputs,
+    .outputs       = stereo3d_outputs,
+    .priv_class    = &stereo3d_class,
+};
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_ass.c b/mythtv/external/FFmpeg/libavfilter/vf_subtitles.c
similarity index 85%
rename from mythtv/external/FFmpeg/libavfilter/vf_ass.c
rename to mythtv/external/FFmpeg/libavfilter/vf_subtitles.c
index ade1b37374c..7ba883a1686 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_ass.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_subtitles.c
@@ -50,6 +50,7 @@ typedef struct {
     ASS_Renderer *renderer;
     ASS_Track    *track;
     char *filename;
+    char *charenc;
     uint8_t rgba_map[4];
     int     pix_step[4];       ///< steps per pixel for each plane of the main output
     int original_w, original_h;
@@ -59,12 +60,10 @@ typedef struct {
 #define OFFSET(x) offsetof(AssContext, x)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
-static const AVOption options[] = {
-    {"filename",       "set the filename of file to read",                         OFFSET(filename),   AV_OPT_TYPE_STRING,     {.str = NULL},  CHAR_MIN, CHAR_MAX, FLAGS },
-    {"f",              "set the filename of file to read",                         OFFSET(filename),   AV_OPT_TYPE_STRING,     {.str = NULL},  CHAR_MIN, CHAR_MAX, FLAGS },
-    {"original_size",  "set the size of the original video (used to scale fonts)", OFFSET(original_w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL},  CHAR_MIN, CHAR_MAX, FLAGS },
-    {NULL},
-};
+#define COMMON_OPTIONS \
+    {"filename",       "set the filename of file to read",                         OFFSET(filename),   AV_OPT_TYPE_STRING,     {.str = NULL},  CHAR_MIN, CHAR_MAX, FLAGS }, \
+    {"f",              "set the filename of file to read",                         OFFSET(filename),   AV_OPT_TYPE_STRING,     {.str = NULL},  CHAR_MIN, CHAR_MAX, FLAGS }, \
+    {"original_size",  "set the size of the original video (used to scale fonts)", OFFSET(original_w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL},  CHAR_MIN, CHAR_MAX, FLAGS }, \
 
 /* libass supports a log level ranging from 0 to 7 */
 static const int ass_libavfilter_log_level_map[] = {
@@ -213,7 +212,11 @@ static const AVFilterPad ass_outputs[] = {
 
 #if CONFIG_ASS_FILTER
 
-#define ass_options options
+static const AVOption ass_options[] = {
+    COMMON_OPTIONS
+    {NULL},
+};
+
 AVFILTER_DEFINE_CLASS(ass);
 
 static av_cold int init_ass(AVFilterContext *ctx, const char *args)
@@ -236,7 +239,7 @@ static av_cold int init_ass(AVFilterContext *ctx, const char *args)
 
 AVFilter avfilter_vf_ass = {
     .name          = "ass",
-    .description   = NULL_IF_CONFIG_SMALL("Render subtitles onto input video using the libass library."),
+    .description   = NULL_IF_CONFIG_SMALL("Render ASS subtitles onto input video using the libass library."),
     .priv_size     = sizeof(AssContext),
     .init          = init_ass,
     .uninit        = uninit,
@@ -249,15 +252,22 @@ AVFilter avfilter_vf_ass = {
 
 #if CONFIG_SUBTITLES_FILTER
 
-#define subtitles_options options
+static const AVOption subtitles_options[] = {
+    COMMON_OPTIONS
+    {"charenc", "set input character encoding", OFFSET(charenc), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS},
+    {NULL},
+};
+
 AVFILTER_DEFINE_CLASS(subtitles);
 
 static av_cold int init_subtitles(AVFilterContext *ctx, const char *args)
 {
     int ret, sid;
+    AVDictionary *codec_opts = NULL;
     AVFormatContext *fmt = NULL;
     AVCodecContext *dec_ctx = NULL;
     AVCodec *dec = NULL;
+    const AVCodecDescriptor *dec_desc;
     AVStream *st;
     AVPacket pkt;
     AssContext *ass = ctx->priv;
@@ -300,7 +310,15 @@ static av_cold int init_subtitles(AVFilterContext *ctx, const char *args)
                avcodec_get_name(dec_ctx->codec_id));
         return AVERROR(EINVAL);
     }
-    ret = avcodec_open2(dec_ctx, dec, NULL);
+    dec_desc = avcodec_descriptor_get(dec_ctx->codec_id);
+    if (dec_desc && (dec_desc->props & AV_CODEC_PROP_BITMAP_SUB)) {
+        av_log(ctx, AV_LOG_ERROR,
+               "Only text based subtitles are currently supported\n");
+        return AVERROR_PATCHWELCOME;
+    }
+    if (ass->charenc)
+        av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0);
+    ret = avcodec_open2(dec_ctx, dec, &codec_opts);
     if (ret < 0)
         goto end;
 
@@ -314,17 +332,20 @@ static av_cold int init_subtitles(AVFilterContext *ctx, const char *args)
     pkt.size = 0;
     while (av_read_frame(fmt, &pkt) >= 0) {
         int i, got_subtitle;
-        AVSubtitle sub;
+        AVSubtitle sub = {0};
 
         if (pkt.stream_index == sid) {
             ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_subtitle, &pkt);
-            if (ret < 0 || !got_subtitle)
-                break;
-            for (i = 0; i < sub.num_rects; i++) {
-                char *ass_line = sub.rects[i]->ass;
-                if (!ass_line)
-                    break;
-                ass_process_data(ass->track, ass_line, strlen(ass_line));
+            if (ret < 0) {
+                av_log(ctx, AV_LOG_WARNING, "Error decoding: %s (ignored)\n",
+                       av_err2str(ret));
+            } else if (got_subtitle) {
+                for (i = 0; i < sub.num_rects; i++) {
+                    char *ass_line = sub.rects[i]->ass;
+                    if (!ass_line)
+                        break;
+                    ass_process_data(ass->track, ass_line, strlen(ass_line));
+                }
             }
         }
         av_free_packet(&pkt);
@@ -332,6 +353,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx, const char *args)
     }
 
 end:
+    av_dict_free(&codec_opts);
     if (dec_ctx)
         avcodec_close(dec_ctx);
     if (fmt)
@@ -341,7 +363,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx, const char *args)
 
 AVFilter avfilter_vf_subtitles = {
     .name          = "subtitles",
-    .description   = NULL_IF_CONFIG_SMALL("Render subtitles onto input video using the libass library."),
+    .description   = NULL_IF_CONFIG_SMALL("Render text subtitles onto input video using the libass library."),
     .priv_size     = sizeof(AssContext),
     .init          = init_subtitles,
     .uninit        = uninit,
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_swapuv.c b/mythtv/external/FFmpeg/libavfilter/vf_swapuv.c
index e7e5e88abdb..82cc07c8dc1 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_swapuv.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_swapuv.c
@@ -23,6 +23,7 @@
  * swap UV filter
  */
 
+#include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "formats.h"
 #include "internal.h"
@@ -48,18 +49,36 @@ static int filter_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
     return ff_filter_frame(link->dst->outputs[0], inpicref);
 }
 
+static int is_planar_yuv(const AVPixFmtDescriptor *desc)
+{
+    int i;
+
+    if (desc->flags & ~(PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_ALPHA) ||
+        desc->nb_components < 3 ||
+        (desc->comp[1].depth_minus1 != desc->comp[2].depth_minus1))
+        return 0;
+    for (i = 0; i < desc->nb_components; i++) {
+        if (desc->comp[i].offset_plus1 != 1 ||
+            desc->comp[i].shift != 0 ||
+            desc->comp[i].plane != i)
+            return 0;
+    }
+
+    return 1;
+}
+
 static int query_formats(AVFilterContext *ctx)
 {
-    static const enum AVPixelFormat pix_fmts[] = {
-        AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVA420P,
-        AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P,
-        AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUVJ440P,
-        AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVJ422P,
-        AV_PIX_FMT_YUV411P,
-        AV_PIX_FMT_NONE,
-    };
-
-    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+    AVFilterFormats *formats = NULL;
+    int fmt;
+
+    for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
+        if (is_planar_yuv(desc))
+            ff_add_format(&formats, fmt);
+    }
+
+    ff_set_common_formats(ctx, formats);
     return 0;
 }
 
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_transpose.c b/mythtv/external/FFmpeg/libavfilter/vf_transpose.c
index c381ecc74eb..270d346f05a 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_transpose.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_transpose.c
@@ -86,28 +86,20 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
 
 static int query_formats(AVFilterContext *ctx)
 {
-    static const enum AVPixelFormat pix_fmts[] = {
-        AV_PIX_FMT_ARGB,         AV_PIX_FMT_RGBA,
-        AV_PIX_FMT_ABGR,         AV_PIX_FMT_BGRA,
-        AV_PIX_FMT_RGB24,        AV_PIX_FMT_BGR24,
-        AV_PIX_FMT_RGB565BE,     AV_PIX_FMT_RGB565LE,
-        AV_PIX_FMT_RGB555BE,     AV_PIX_FMT_RGB555LE,
-        AV_PIX_FMT_BGR565BE,     AV_PIX_FMT_BGR565LE,
-        AV_PIX_FMT_BGR555BE,     AV_PIX_FMT_BGR555LE,
-        AV_PIX_FMT_GRAY16BE,     AV_PIX_FMT_GRAY16LE,
-        AV_PIX_FMT_YUV420P16LE,  AV_PIX_FMT_YUV420P16BE,
-        AV_PIX_FMT_YUV444P16LE,  AV_PIX_FMT_YUV444P16BE,
-        AV_PIX_FMT_NV12,         AV_PIX_FMT_NV21,
-        AV_PIX_FMT_RGB8,         AV_PIX_FMT_BGR8,
-        AV_PIX_FMT_RGB4_BYTE,    AV_PIX_FMT_BGR4_BYTE,
-        AV_PIX_FMT_YUV444P,      AV_PIX_FMT_YUVJ444P,
-        AV_PIX_FMT_YUV420P,      AV_PIX_FMT_YUVJ420P,
-        AV_PIX_FMT_YUV410P,
-        AV_PIX_FMT_YUVA420P,     AV_PIX_FMT_GRAY8,
-        AV_PIX_FMT_NONE
-    };
-
-    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+    AVFilterFormats *pix_fmts = NULL;
+    int fmt;
+
+    for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
+        if (!(desc->flags & PIX_FMT_PAL ||
+              desc->flags & PIX_FMT_HWACCEL ||
+              desc->flags & PIX_FMT_BITSTREAM ||
+              desc->log2_chroma_w != desc->log2_chroma_h))
+            ff_add_format(&pix_fmts, fmt);
+    }
+
+
+    ff_set_common_formats(ctx, pix_fmts);
     return 0;
 }
 
@@ -236,6 +228,16 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
                 for (x = 0; x < outw; x++)
                     *((uint32_t *)(dst + 4*x)) = *((uint32_t *)(src + x*srclinesize + y*4));
                 break;
+            case 6:
+                for (x = 0; x < outw; x++) {
+                    int64_t v = AV_RB48(src + x*srclinesize + y*6);
+                    AV_WB48(dst + 6*x, v);
+                }
+                break;
+            case 8:
+                for (x = 0; x < outw; x++)
+                    *((uint64_t *)(dst + 8*x)) = *((uint64_t *)(src + x*srclinesize + y*8));
+                break;
             }
             dst += dstlinesize;
         }
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_unsharp.c b/mythtv/external/FFmpeg/libavfilter/vf_unsharp.c
index 3a9b0b68498..8c6e18a1128 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_unsharp.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_unsharp.c
@@ -36,16 +36,19 @@
  * http://www.engin.umd.umich.edu/~jwvm/ece581/21_GBlur.pdf
  */
 
+#include  /* DBL_MAX */
+
 #include "avfilter.h"
 #include "formats.h"
 #include "internal.h"
 #include "video.h"
 #include "libavutil/common.h"
 #include "libavutil/mem.h"
+#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 
-#define MIN_SIZE 3
-#define MAX_SIZE 13
+#define MIN_MATRIX_SIZE 3
+#define MAX_MATRIX_SIZE 63
 
 /* right-shift and round-up */
 #define SHIFTUP(x,shift) (-((-(x))>>(shift)))
@@ -58,27 +61,57 @@ typedef struct FilterParam {
     int steps_y;                             ///< vertical step count
     int scalebits;                           ///< bits to shift pixel
     int32_t halfscale;                       ///< amount to add to pixel
-    uint32_t *sc[(MAX_SIZE * MAX_SIZE) - 1]; ///< finite state machine storage
+    uint32_t *sc[MAX_MATRIX_SIZE - 1];       ///< finite state machine storage
 } FilterParam;
 
 typedef struct {
+    const AVClass *class;
     FilterParam luma;   ///< luma parameters (width, height, amount)
     FilterParam chroma; ///< chroma parameters (width, height, amount)
     int hsub, vsub;
+    int luma_msize_x, luma_msize_y, chroma_msize_x, chroma_msize_y;
+    double luma_amount, chroma_amount;
 } UnsharpContext;
 
+#define OFFSET(x) offsetof(UnsharpContext, x)
+
+static const AVOption unsharp_options[] = {
+    { "luma_msize_x",    "set luma matrix x size",     OFFSET(luma_msize_x),    AV_OPT_TYPE_INT,    {.i64=5}, 3, 63 },
+    { "lx",              "set luma matrix x size",     OFFSET(luma_msize_x),    AV_OPT_TYPE_INT,    {.i64=5}, 3, 63 },
+    { "luma_msize_y",    "set luma matrix y size",     OFFSET(luma_msize_y),    AV_OPT_TYPE_INT,    {.i64=5}, 3, 63 },
+    { "ly",              "set luma matrix y size",     OFFSET(luma_msize_y),    AV_OPT_TYPE_INT,    {.i64=5}, 3, 63 },
+    { "luma_amount",     "set luma effect amount",     OFFSET(luma_amount),     AV_OPT_TYPE_DOUBLE, {.dbl=1.0}, -DBL_MAX, DBL_MAX },
+    { "la",              "set luma effect amount",     OFFSET(luma_amount),     AV_OPT_TYPE_DOUBLE, {.dbl=1.0}, -DBL_MAX, DBL_MAX },
+
+    { "chroma_msize_x",  "set chroma matrix x size",   OFFSET(chroma_msize_x), AV_OPT_TYPE_INT,    {.i64=5}, 3, 63 },
+    { "cx",              "set chroma matrix x size",   OFFSET(chroma_msize_x), AV_OPT_TYPE_INT,    {.i64=5}, 3, 63 },
+    { "chroma_msize_y",  "set chroma matrix y size",   OFFSET(chroma_msize_y), AV_OPT_TYPE_INT,    {.i64=5}, 3, 63 },
+    { "cy"          ,    "set chroma matrix y size",   OFFSET(chroma_msize_y), AV_OPT_TYPE_INT,    {.i64=5}, 3, 63 },
+    { "chroma_amount",   "set chroma effect strenght", OFFSET(chroma_amount),  AV_OPT_TYPE_DOUBLE, {.dbl=0.0}, -DBL_MAX, DBL_MAX },
+    { "ca",              "set chroma effect strenght", OFFSET(chroma_amount),  AV_OPT_TYPE_DOUBLE, {.dbl=0.0}, -DBL_MAX, DBL_MAX },
+
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(unsharp);
+
 static void apply_unsharp(      uint8_t *dst, int dst_stride,
                           const uint8_t *src, int src_stride,
                           int width, int height, FilterParam *fp)
 {
     uint32_t **sc = fp->sc;
-    uint32_t sr[(MAX_SIZE * MAX_SIZE) - 1], tmp1, tmp2;
+    uint32_t sr[MAX_MATRIX_SIZE - 1], tmp1, tmp2;
 
     int32_t res;
     int x, y, z;
     const uint8_t *src2 = NULL;  //silence a warning
+    const int amount = fp->amount;
+    const int steps_x = fp->steps_x;
+    const int steps_y = fp->steps_y;
+    const int scalebits = fp->scalebits;
+    const int32_t halfscale = fp->halfscale;
 
-    if (!fp->amount) {
+    if (!amount) {
         if (dst_stride == src_stride)
             memcpy(dst, src, src_stride * height);
         else
@@ -87,29 +120,29 @@ static void apply_unsharp(      uint8_t *dst, int dst_stride,
         return;
     }
 
-    for (y = 0; y < 2 * fp->steps_y; y++)
-        memset(sc[y], 0, sizeof(sc[y][0]) * (width + 2 * fp->steps_x));
+    for (y = 0; y < 2 * steps_y; y++)
+        memset(sc[y], 0, sizeof(sc[y][0]) * (width + 2 * steps_x));
 
-    for (y = -fp->steps_y; y < height + fp->steps_y; y++) {
+    for (y = -steps_y; y < height + steps_y; y++) {
         if (y < height)
             src2 = src;
 
-        memset(sr, 0, sizeof(sr[0]) * (2 * fp->steps_x - 1));
-        for (x = -fp->steps_x; x < width + fp->steps_x; x++) {
+        memset(sr, 0, sizeof(sr[0]) * (2 * steps_x - 1));
+        for (x = -steps_x; x < width + steps_x; x++) {
             tmp1 = x <= 0 ? src2[0] : x >= width ? src2[width-1] : src2[x];
-            for (z = 0; z < fp->steps_x * 2; z += 2) {
+            for (z = 0; z < steps_x * 2; z += 2) {
                 tmp2 = sr[z + 0] + tmp1; sr[z + 0] = tmp1;
                 tmp1 = sr[z + 1] + tmp2; sr[z + 1] = tmp2;
             }
-            for (z = 0; z < fp->steps_y * 2; z += 2) {
-                tmp2 = sc[z + 0][x + fp->steps_x] + tmp1; sc[z + 0][x + fp->steps_x] = tmp1;
-                tmp1 = sc[z + 1][x + fp->steps_x] + tmp2; sc[z + 1][x + fp->steps_x] = tmp2;
+            for (z = 0; z < steps_y * 2; z += 2) {
+                tmp2 = sc[z + 0][x + steps_x] + tmp1; sc[z + 0][x + steps_x] = tmp1;
+                tmp1 = sc[z + 1][x + steps_x] + tmp2; sc[z + 1][x + steps_x] = tmp2;
             }
-            if (x >= fp->steps_x && y >= fp->steps_y) {
-                const uint8_t *srx = src - fp->steps_y * src_stride + x - fp->steps_x;
-                uint8_t *dsx       = dst - fp->steps_y * dst_stride + x - fp->steps_x;
+            if (x >= steps_x && y >= steps_y) {
+                const uint8_t *srx = src - steps_y * src_stride + x - steps_x;
+                uint8_t *dsx       = dst - steps_y * dst_stride + x - steps_x;
 
-                res = (int32_t)*srx + ((((int32_t) * srx - (int32_t)((tmp1 + fp->halfscale) >> fp->scalebits)) * fp->amount) >> 16);
+                res = (int32_t)*srx + ((((int32_t) * srx - (int32_t)((tmp1 + halfscale) >> scalebits)) * amount) >> 16);
                 *dsx = av_clip_uint8(res);
             }
         }
@@ -135,24 +168,21 @@ static void set_filter_param(FilterParam *fp, int msize_x, int msize_y, double a
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     UnsharpContext *unsharp = ctx->priv;
-    int lmsize_x = 5, cmsize_x = 5;
-    int lmsize_y = 5, cmsize_y = 5;
-    double lamount = 1.0f, camount = 0.0f;
+    static const char *shorthand[] = {
+        "luma_msize_x", "luma_msize_y", "luma_amount",
+        "chroma_msize_x", "chroma_msize_y", "chroma_amount",
+        NULL
+    };
+    int ret;
 
-    if (args)
-        sscanf(args, "%d:%d:%lf:%d:%d:%lf", &lmsize_x, &lmsize_y, &lamount,
-                                            &cmsize_x, &cmsize_y, &camount);
+    unsharp->class = &unsharp_class;
+    av_opt_set_defaults(unsharp);
 
-    if ((lamount && (lmsize_x < 2 || lmsize_y < 2)) ||
-        (camount && (cmsize_x < 2 || cmsize_y < 2))) {
-        av_log(ctx, AV_LOG_ERROR,
-               "Invalid value <2 for lmsize_x:%d or lmsize_y:%d or cmsize_x:%d or cmsize_y:%d\n",
-               lmsize_x, lmsize_y, cmsize_x, cmsize_y);
-        return AVERROR(EINVAL);
-    }
+    if ((ret = av_opt_set_from_string(unsharp, args, shorthand, "=", ":")) < 0)
+        return ret;
 
-    set_filter_param(&unsharp->luma,   lmsize_x, lmsize_y, lamount);
-    set_filter_param(&unsharp->chroma, cmsize_x, cmsize_y, camount);
+    set_filter_param(&unsharp->luma,   unsharp->luma_msize_x,   unsharp->luma_msize_y,   unsharp->luma_amount);
+    set_filter_param(&unsharp->chroma, unsharp->chroma_msize_x, unsharp->chroma_msize_y, unsharp->chroma_amount);
 
     return 0;
 }
@@ -170,30 +200,43 @@ static int query_formats(AVFilterContext *ctx)
     return 0;
 }
 
-static void init_filter_param(AVFilterContext *ctx, FilterParam *fp, const char *effect_type, int width)
+static int init_filter_param(AVFilterContext *ctx, FilterParam *fp, const char *effect_type, int width)
 {
     int z;
-    const char *effect;
+    const char *effect = fp->amount == 0 ? "none" : fp->amount < 0 ? "blur" : "sharpen";
 
-    effect = fp->amount == 0 ? "none" : fp->amount < 0 ? "blur" : "sharpen";
+    if  (!(fp->msize_x & fp->msize_y & 1)) {
+        av_log(ctx, AV_LOG_ERROR,
+               "Invalid even size for %s matrix size %dx%d\n",
+               effect_type, fp->msize_x, fp->msize_y);
+        return AVERROR(EINVAL);
+    }
 
     av_log(ctx, AV_LOG_VERBOSE, "effect:%s type:%s msize_x:%d msize_y:%d amount:%0.2f\n",
            effect, effect_type, fp->msize_x, fp->msize_y, fp->amount / 65535.0);
 
     for (z = 0; z < 2 * fp->steps_y; z++)
-        fp->sc[z] = av_malloc(sizeof(*(fp->sc[z])) * (width + 2 * fp->steps_x));
+        if (!(fp->sc[z] = av_malloc(sizeof(*(fp->sc[z])) * (width + 2 * fp->steps_x))))
+            return AVERROR(ENOMEM);
+
+    return 0;
 }
 
 static int config_props(AVFilterLink *link)
 {
     UnsharpContext *unsharp = link->dst->priv;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
+    int ret;
 
     unsharp->hsub = desc->log2_chroma_w;
     unsharp->vsub = desc->log2_chroma_h;
 
-    init_filter_param(link->dst, &unsharp->luma,   "luma",   link->w);
-    init_filter_param(link->dst, &unsharp->chroma, "chroma", SHIFTUP(link->w, unsharp->hsub));
+    ret = init_filter_param(link->dst, &unsharp->luma,   "luma",   link->w);
+    if (ret < 0)
+        return ret;
+    ret = init_filter_param(link->dst, &unsharp->chroma, "chroma", SHIFTUP(link->w, unsharp->hsub));
+    if (ret < 0)
+        return ret;
 
     return 0;
 }
@@ -212,6 +255,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 
     free_filter_param(&unsharp->luma);
     free_filter_param(&unsharp->chroma);
+    av_opt_free(unsharp);
 }
 
 static int filter_frame(AVFilterLink *link, AVFilterBufferRef *in)
@@ -269,4 +313,6 @@ AVFilter avfilter_vf_unsharp = {
     .inputs    = avfilter_vf_unsharp_inputs,
 
     .outputs   = avfilter_vf_unsharp_outputs,
+
+    .priv_class = &unsharp_class,
 };
diff --git a/mythtv/external/FFmpeg/libavfilter/vf_yadif.c b/mythtv/external/FFmpeg/libavfilter/vf_yadif.c
index 74eafcbd123..b7c2d8073ab 100644
--- a/mythtv/external/FFmpeg/libavfilter/vf_yadif.c
+++ b/mythtv/external/FFmpeg/libavfilter/vf_yadif.c
@@ -34,15 +34,15 @@
 #define PERM_RWP AV_PERM_WRITE | AV_PERM_PRESERVE | AV_PERM_REUSE
 
 #define CHECK(j)\
-    {   int score = FFABS(cur[mrefs-1+(j)] - cur[prefs-1-(j)])\
+    {   int score = FFABS(cur[mrefs + off_left + (j)] - cur[prefs + off_left - (j)])\
                   + FFABS(cur[mrefs  +(j)] - cur[prefs  -(j)])\
-                  + FFABS(cur[mrefs+1+(j)] - cur[prefs+1-(j)]);\
+                  + FFABS(cur[mrefs + off_right + (j)] - cur[prefs + off_right - (j)]);\
         if (score < spatial_score) {\
             spatial_score= score;\
             spatial_pred= (cur[mrefs  +(j)] + cur[prefs  -(j)])>>1;\
 
-#define FILTER \
-    for (x = 0;  x < w; x++) { \
+#define FILTER(start, end) \
+    for (x = start;  x < end; x++) { \
         int c = cur[mrefs]; \
         int d = (prev2[0] + next2[0])>>1; \
         int e = cur[prefs]; \
@@ -51,11 +51,15 @@
         int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1; \
         int diff = FFMAX3(temporal_diff0 >> 1, temporal_diff1, temporal_diff2); \
         int spatial_pred = (c+e) >> 1; \
-        int spatial_score = FFABS(cur[mrefs - 1] - cur[prefs - 1]) + FFABS(c-e) \
-                          + FFABS(cur[mrefs + 1] - cur[prefs + 1]) - 1; \
+        int off_right = (x < w - 1) ? 1 : -1;\
+        int off_left  = x ? -1 : 1;\
+        int spatial_score = FFABS(cur[mrefs + off_left]  - cur[prefs + off_left]) + FFABS(c-e) \
+                          + FFABS(cur[mrefs + off_right] - cur[prefs + off_right]) - 1; \
  \
-        CHECK(-1) CHECK(-2) }} }} \
-        CHECK( 1) CHECK( 2) }} }} \
+        if (x > 2 && x < w - 3) {\
+            CHECK(-1) CHECK(-2) }} }} \
+            CHECK( 1) CHECK( 2) }} }} \
+        }\
  \
         if (mode < 2) { \
             int b = (prev2[2 * mrefs] + next2[2 * mrefs])>>1; \
@@ -81,29 +85,86 @@
         next2++; \
     }
 
-static void filter_line_c(uint8_t *dst,
-                          uint8_t *prev, uint8_t *cur, uint8_t *next,
+static void filter_line_c(void *dst1,
+                          void *prev1, void *cur1, void *next1,
                           int w, int prefs, int mrefs, int parity, int mode)
 {
+    uint8_t *dst  = dst1;
+    uint8_t *prev = prev1;
+    uint8_t *cur  = cur1;
+    uint8_t *next = next1;
     int x;
     uint8_t *prev2 = parity ? prev : cur ;
     uint8_t *next2 = parity ? cur  : next;
 
-    FILTER
+    FILTER(0, w)
 }
 
-static void filter_line_c_16bit(uint16_t *dst,
-                                uint16_t *prev, uint16_t *cur, uint16_t *next,
+static void filter_edges(void *dst1, void *prev1, void *cur1, void *next1,
+                         int w, int prefs, int mrefs, int parity, int mode,
+                         int l_edge)
+{
+    uint8_t *dst  = dst1;
+    uint8_t *prev = prev1;
+    uint8_t *cur  = cur1;
+    uint8_t *next = next1;
+    int x;
+    uint8_t *prev2 = parity ? prev : cur ;
+    uint8_t *next2 = parity ? cur  : next;
+
+    FILTER(0, l_edge)
+
+    dst  = (uint8_t*)dst1  + w - 3;
+    prev = (uint8_t*)prev1 + w - 3;
+    cur  = (uint8_t*)cur1  + w - 3;
+    next = (uint8_t*)next1 + w - 3;
+    prev2 = (uint8_t*)(parity ? prev : cur);
+    next2 = (uint8_t*)(parity ? cur  : next);
+
+    FILTER(w - 3, w)
+}
+
+
+static void filter_line_c_16bit(void *dst1,
+                                void *prev1, void *cur1, void *next1,
                                 int w, int prefs, int mrefs, int parity,
                                 int mode)
 {
+    uint16_t *dst  = dst1;
+    uint16_t *prev = prev1;
+    uint16_t *cur  = cur1;
+    uint16_t *next = next1;
     int x;
     uint16_t *prev2 = parity ? prev : cur ;
     uint16_t *next2 = parity ? cur  : next;
     mrefs /= 2;
     prefs /= 2;
 
-    FILTER
+    FILTER(0, w)
+}
+
+static void filter_edges_16bit(void *dst1, void *prev1, void *cur1, void *next1,
+                               int w, int prefs, int mrefs, int parity, int mode,
+                               int l_edge)
+{
+    uint16_t *dst  = dst1;
+    uint16_t *prev = prev1;
+    uint16_t *cur  = cur1;
+    uint16_t *next = next1;
+    int x;
+    uint16_t *prev2 = parity ? prev : cur ;
+    uint16_t *next2 = parity ? cur  : next;
+
+    FILTER(0, l_edge)
+
+    dst   = (uint16_t*)dst1  + w - 3;
+    prev  = (uint16_t*)prev1 + w - 3;
+    cur   = (uint16_t*)cur1  + w - 3;
+    next  = (uint16_t*)next1 + w - 3;
+    prev2 = (uint16_t*)(parity ? prev : cur);
+    next2 = (uint16_t*)(parity ? cur  : next);
+
+    FILTER(w - 3, w)
 }
 
 static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic,
@@ -116,8 +177,8 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic,
         int w = dstpic->video->w;
         int h = dstpic->video->h;
         int refs = yadif->cur->linesize[i];
-        int absrefs = FFABS(refs);
         int df = (yadif->csp->comp[i].depth_minus1 + 8) / 8;
+        int l_edge, l_edge_pix;
 
         if (i == 1 || i == 2) {
         /* Why is this not part of the per-plane description thing? */
@@ -125,11 +186,11 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic,
             h >>= yadif->csp->log2_chroma_h;
         }
 
-        if(yadif->temp_line_size < absrefs) {
-            av_free(yadif->temp_line);
-            yadif->temp_line = av_mallocz(2*64 + 5*absrefs);
-            yadif->temp_line_size = absrefs;
-        }
+        /* filtering reads 3 pixels to the left/right; to avoid invalid reads,
+         * we need to call the c variant which avoids this for border pixels
+         */
+        l_edge     = yadif->req_align;
+        l_edge_pix = l_edge / df;
 
         for (y = 0; y < h; y++) {
             if ((y ^ parity) & 1) {
@@ -138,26 +199,22 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic,
                 uint8_t *next = &yadif->next->data[i][y * refs];
                 uint8_t *dst  = &dstpic->data[i][y * dstpic->linesize[i]];
                 int     mode  = y == 1 || y + 2 == h ? 2 : yadif->mode;
-                int     prefs = y+1=h) {
-                    uint8_t *tmp = yadif->temp_line + 64 + 2*absrefs;
-                    if(mode<2)
-                        memcpy(tmp+2*mrefs, cur+2*mrefs, w*df);
-                    memcpy(tmp+mrefs, cur+mrefs, w*df);
-                    memcpy(tmp      , cur      , w*df);
-                    if(prefs != mrefs) {
-                        memcpy(tmp+prefs, cur+prefs, w*df);
-                        if(mode<2)
-                            memcpy(tmp+2*prefs, cur+2*prefs, w*df);
-                    }
-                    cur = tmp;
+                if (yadif->req_align) {
+                    yadif->filter_line(dst + l_edge, prev + l_edge, cur + l_edge,
+                                       next + l_edge, w - l_edge_pix - 3,
+                                       y + 1 < h ? refs : -refs,
+                                       y ? -refs : refs,
+                                       parity ^ tff, mode);
+                    yadif->filter_edges(dst, prev, cur, next, w,
+                                         y + 1 < h ? refs : -refs,
+                                         y ? -refs : refs,
+                                         parity ^ tff, mode, l_edge_pix);
+                } else {
+                    yadif->filter_line(dst, prev, cur, next + l_edge, w,
+                                       y + 1 < h ? refs : -refs,
+                                       y ? -refs : refs,
+                                       parity ^ tff, mode);
                 }
-
-                yadif->filter_line(dst, prev, cur, next, w,
-                                   prefs, mrefs,
-                                   parity ^ tff, mode);
             } else {
                 memcpy(&dstpic->data[i][y * dstpic->linesize[i]],
                        &yadif->cur->data[i][y * refs], w * df);
@@ -190,11 +247,6 @@ static int return_frame(AVFilterContext *ctx, int is_second)
         yadif->out->video->interlaced = 0;
     }
 
-    if (!yadif->csp)
-        yadif->csp = av_pix_fmt_desc_get(link->format);
-    if (yadif->csp->comp[0].depth_minus1 / 8 == 1)
-        yadif->filter_line = (void*)filter_line_c_16bit;
-
     filter(ctx, yadif->out, tff ^ !is_second, tff);
 
     if (is_second) {
@@ -330,7 +382,6 @@ static av_cold void uninit(AVFilterContext *ctx)
     avfilter_unref_bufferp(&yadif->prev);
     avfilter_unref_bufferp(&yadif->cur );
     avfilter_unref_bufferp(&yadif->next);
-    av_freep(&yadif->temp_line); yadif->temp_line_size = 0;
     av_opt_free(yadif);
 }
 
@@ -349,9 +400,18 @@ static int query_formats(AVFilterContext *ctx)
         AV_NE( AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_GRAY16LE ),
         AV_PIX_FMT_YUV440P,
         AV_PIX_FMT_YUVJ440P,
+        AV_NE( AV_PIX_FMT_YUV420P9BE,  AV_PIX_FMT_YUV420P9LE ),
+        AV_NE( AV_PIX_FMT_YUV422P9BE,  AV_PIX_FMT_YUV422P9LE ),
+        AV_NE( AV_PIX_FMT_YUV444P9BE,  AV_PIX_FMT_YUV444P9LE ),
         AV_NE( AV_PIX_FMT_YUV420P10BE, AV_PIX_FMT_YUV420P10LE ),
         AV_NE( AV_PIX_FMT_YUV422P10BE, AV_PIX_FMT_YUV422P10LE ),
         AV_NE( AV_PIX_FMT_YUV444P10BE, AV_PIX_FMT_YUV444P10LE ),
+        AV_NE( AV_PIX_FMT_YUV420P12BE, AV_PIX_FMT_YUV420P12LE ),
+        AV_NE( AV_PIX_FMT_YUV422P12BE, AV_PIX_FMT_YUV422P12LE ),
+        AV_NE( AV_PIX_FMT_YUV444P12BE, AV_PIX_FMT_YUV444P12LE ),
+        AV_NE( AV_PIX_FMT_YUV420P14BE, AV_PIX_FMT_YUV420P14LE ),
+        AV_NE( AV_PIX_FMT_YUV422P14BE, AV_PIX_FMT_YUV422P14LE ),
+        AV_NE( AV_PIX_FMT_YUV444P14BE, AV_PIX_FMT_YUV444P14LE ),
         AV_NE( AV_PIX_FMT_YUV420P16BE, AV_PIX_FMT_YUV420P16LE ),
         AV_NE( AV_PIX_FMT_YUV422P16BE, AV_PIX_FMT_YUV422P16LE ),
         AV_NE( AV_PIX_FMT_YUV444P16BE, AV_PIX_FMT_YUV444P16LE ),
@@ -372,19 +432,12 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     static const char *shorthand[] = { "mode", "parity", "deint", NULL };
     int ret;
 
-    yadif->csp = NULL;
-
     yadif->class = &yadif_class;
     av_opt_set_defaults(yadif);
 
     if ((ret = av_opt_set_from_string(yadif, args, shorthand, "=", ":")) < 0)
         return ret;
 
-    yadif->filter_line = filter_line_c;
-
-    if (ARCH_X86)
-        ff_yadif_init_x86(yadif);
-
     av_log(ctx, AV_LOG_VERBOSE, "mode:%d parity:%d deint:%d\n",
            yadif->mode, yadif->parity, yadif->deint);
 
@@ -394,14 +447,14 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
 static int config_props(AVFilterLink *link)
 {
     AVFilterContext *ctx = link->src;
-    YADIFContext *yadif = ctx->priv;
+    YADIFContext *s = link->src->priv;
 
     link->time_base.num = link->src->inputs[0]->time_base.num;
     link->time_base.den = link->src->inputs[0]->time_base.den * 2;
     link->w             = link->src->inputs[0]->w;
     link->h             = link->src->inputs[0]->h;
 
-    if(yadif->mode&1)
+    if(s->mode&1)
         link->frame_rate = av_mul_q(link->src->inputs[0]->frame_rate, (AVRational){2,1});
 
     if (link->w < 3 || link->h < 3) {
@@ -409,6 +462,18 @@ static int config_props(AVFilterLink *link)
         return AVERROR(EINVAL);
     }
 
+    s->csp = av_pix_fmt_desc_get(link->format);
+    if (s->csp->comp[0].depth_minus1 / 8 == 1) {
+        s->filter_line  = filter_line_c_16bit;
+        s->filter_edges = filter_edges_16bit;
+    } else {
+        s->filter_line  = filter_line_c;
+        s->filter_edges = filter_edges;
+
+        if (ARCH_X86)
+            ff_yadif_init_x86(s);
+    }
+
     return 0;
 }
 
diff --git a/mythtv/external/FFmpeg/libavfilter/vsrc_cellauto.c b/mythtv/external/FFmpeg/libavfilter/vsrc_cellauto.c
index 06d9f9aa138..1431717a5f0 100644
--- a/mythtv/external/FFmpeg/libavfilter/vsrc_cellauto.c
+++ b/mythtv/external/FFmpeg/libavfilter/vsrc_cellauto.c
@@ -30,6 +30,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/random_seed.h"
+#include "libavutil/avstring.h"
 #include "avfilter.h"
 #include "internal.h"
 #include "formats.h"
@@ -133,7 +134,7 @@ static int init_pattern_from_string(AVFilterContext *ctx)
         if (*p == '\n' || !*p)
             break;
         else
-            cellauto->buf[i] = !!isgraph(*(p++));
+            cellauto->buf[i] = !!av_isgraph(*(p++));
     }
 
     return 0;
diff --git a/mythtv/external/FFmpeg/libavfilter/vsrc_life.c b/mythtv/external/FFmpeg/libavfilter/vsrc_life.c
index d8b83551266..d548ab46e08 100644
--- a/mythtv/external/FFmpeg/libavfilter/vsrc_life.c
+++ b/mythtv/external/FFmpeg/libavfilter/vsrc_life.c
@@ -31,6 +31,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/random_seed.h"
+#include "libavutil/avstring.h"
 #include "avfilter.h"
 #include "internal.h"
 #include "formats.h"
@@ -212,7 +213,7 @@ static int init_pattern_from_file(AVFilterContext *ctx)
             if (*p == '\n') {
                 p++; break;
             } else
-                life->buf[0][i*life->w + j] = isgraph(*(p++)) ? ALIVE_CELL : 0;
+                life->buf[0][i*life->w + j] = av_isgraph(*(p++)) ? ALIVE_CELL : 0;
         }
     }
     life->buf_idx = 0;
diff --git a/mythtv/external/FFmpeg/libavfilter/x86/Makefile b/mythtv/external/FFmpeg/libavfilter/x86/Makefile
index 0f08e396919..59cefe8988f 100644
--- a/mythtv/external/FFmpeg/libavfilter/x86/Makefile
+++ b/mythtv/external/FFmpeg/libavfilter/x86/Makefile
@@ -1,6 +1,8 @@
-OBJS-$(CONFIG_GRADFUN_FILTER)                += x86/gradfun.o
+OBJS-$(CONFIG_GRADFUN_FILTER)                += x86/vf_gradfun.o
+OBJS-$(CONFIG_HQDN3D_FILTER)                 += x86/vf_hqdn3d_init.o
 OBJS-$(CONFIG_VOLUME_FILTER)                 += x86/af_volume_init.o
-OBJS-$(CONFIG_YADIF_FILTER)                  += x86/yadif.o
+OBJS-$(CONFIG_YADIF_FILTER)                  += x86/vf_yadif_init.o
 
-YASM-OBJS-$(CONFIG_HQDN3D_FILTER)            += x86/hqdn3d.o
+YASM-OBJS-$(CONFIG_HQDN3D_FILTER)            += x86/vf_hqdn3d.o
 YASM-OBJS-$(CONFIG_VOLUME_FILTER)            += x86/af_volume.o
+YASM-OBJS-$(CONFIG_YADIF_FILTER)             += x86/vf_yadif.o
diff --git a/mythtv/external/FFmpeg/libavfilter/x86/gradfun.c b/mythtv/external/FFmpeg/libavfilter/x86/vf_gradfun.c
similarity index 100%
rename from mythtv/external/FFmpeg/libavfilter/x86/gradfun.c
rename to mythtv/external/FFmpeg/libavfilter/x86/vf_gradfun.c
diff --git a/mythtv/external/FFmpeg/libavfilter/x86/hqdn3d.asm b/mythtv/external/FFmpeg/libavfilter/x86/vf_hqdn3d.asm
similarity index 100%
rename from mythtv/external/FFmpeg/libavfilter/x86/hqdn3d.asm
rename to mythtv/external/FFmpeg/libavfilter/x86/vf_hqdn3d.asm
diff --git a/mythtv/external/FFmpeg/libavfilter/x86/vf_hqdn3d_init.c b/mythtv/external/FFmpeg/libavfilter/x86/vf_hqdn3d_init.c
new file mode 100644
index 00000000000..4abb87888e8
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavfilter/x86/vf_hqdn3d_init.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2012 Loren Merritt
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 
+#include 
+
+#include "libavutil/attributes.h"
+#include "libavfilter/vf_hqdn3d.h"
+#include "config.h"
+
+void ff_hqdn3d_row_8_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal);
+void ff_hqdn3d_row_9_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal);
+void ff_hqdn3d_row_10_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal);
+void ff_hqdn3d_row_16_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal);
+
+av_cold void ff_hqdn3d_init_x86(HQDN3DContext *hqdn3d)
+{
+#if HAVE_YASM
+    hqdn3d->denoise_row[ 8] = ff_hqdn3d_row_8_x86;
+    hqdn3d->denoise_row[ 9] = ff_hqdn3d_row_9_x86;
+    hqdn3d->denoise_row[10] = ff_hqdn3d_row_10_x86;
+    hqdn3d->denoise_row[16] = ff_hqdn3d_row_16_x86;
+#endif
+}
diff --git a/mythtv/external/FFmpeg/libavfilter/x86/vf_yadif.asm b/mythtv/external/FFmpeg/libavfilter/x86/vf_yadif.asm
new file mode 100644
index 00000000000..a8f798771fc
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavfilter/x86/vf_yadif.asm
@@ -0,0 +1,254 @@
+;*****************************************************************************
+;* x86-optimized functions for yadif filter
+;*
+;* Copyright (C) 2006 Michael Niedermayer 
+;* Copyright (c) 2013 Daniel Kang 
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg is free software; you can redistribute it and/or modify
+;* it under the terms of the GNU General Public License as published by
+;* the Free Software Foundation; either version 2 of the License, or
+;* (at your option) any later version.
+;*
+;* FFmpeg is distributed in the hope that it will be useful,
+;* but WITHOUT ANY WARRANTY; without even the implied warranty of
+;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;* GNU General Public License for more details.
+;*
+;* You should have received a copy of the GNU 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 "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+
+pb_1: times 16 db 1
+pw_1: times  8 dw 1
+
+SECTION .text
+
+%macro CHECK 2
+    movu      m2, [curq+t1+%1]
+    movu      m3, [curq+t0+%2]
+    mova      m4, m2
+    mova      m5, m2
+    pxor      m4, m3
+    pavgb     m5, m3
+    pand      m4, [pb_1]
+    psubusb   m5, m4
+%if mmsize == 16
+    psrldq    m5, 1
+%else
+    psrlq     m5, 8
+%endif
+    punpcklbw m5, m7
+    mova      m4, m2
+    psubusb   m2, m3
+    psubusb   m3, m4
+    pmaxub    m2, m3
+    mova      m3, m2
+    mova      m4, m2
+%if mmsize == 16
+    psrldq    m3, 1
+    psrldq    m4, 2
+%else
+    psrlq     m3, 8
+    psrlq     m4, 16
+%endif
+    punpcklbw m2, m7
+    punpcklbw m3, m7
+    punpcklbw m4, m7
+    paddw     m2, m3
+    paddw     m2, m4
+%endmacro
+
+%macro CHECK1 0
+    mova    m3, m0
+    pcmpgtw m3, m2
+    pminsw  m0, m2
+    mova    m6, m3
+    pand    m5, m3
+    pandn   m3, m1
+    por     m3, m5
+    mova    m1, m3
+%endmacro
+
+%macro CHECK2 0
+    paddw   m6, [pw_1]
+    psllw   m6, 14
+    paddsw  m2, m6
+    mova    m3, m0
+    pcmpgtw m3, m2
+    pminsw  m0, m2
+    pand    m5, m3
+    pandn   m3, m1
+    por     m3, m5
+    mova    m1, m3
+%endmacro
+
+%macro LOAD 2
+    movh      m%1, %2
+    punpcklbw m%1, m7
+%endmacro
+
+%macro FILTER 3
+.loop%1:
+    pxor         m7, m7
+    LOAD          0, [curq+t1]
+    LOAD          1, [curq+t0]
+    LOAD          2, [%2]
+    LOAD          3, [%3]
+    mova         m4, m3
+    paddw        m3, m2
+    psraw        m3, 1
+    mova   [rsp+ 0], m0
+    mova   [rsp+16], m3
+    mova   [rsp+32], m1
+    psubw        m2, m4
+    ABS1         m2, m4
+    LOAD          3, [prevq+t1]
+    LOAD          4, [prevq+t0]
+    psubw        m3, m0
+    psubw        m4, m1
+    ABS1         m3, m5
+    ABS1         m4, m5
+    paddw        m3, m4
+    psrlw        m2, 1
+    psrlw        m3, 1
+    pmaxsw       m2, m3
+    LOAD          3, [nextq+t1]
+    LOAD          4, [nextq+t0]
+    psubw        m3, m0
+    psubw        m4, m1
+    ABS1         m3, m5
+    ABS1         m4, m5
+    paddw        m3, m4
+    psrlw        m3, 1
+    pmaxsw       m2, m3
+    mova   [rsp+48], m2
+
+    paddw        m1, m0
+    paddw        m0, m0
+    psubw        m0, m1
+    psrlw        m1, 1
+    ABS1         m0, m2
+
+    movu         m2, [curq+t1-1]
+    movu         m3, [curq+t0-1]
+    mova         m4, m2
+    psubusb      m2, m3
+    psubusb      m3, m4
+    pmaxub       m2, m3
+%if mmsize == 16
+    mova         m3, m2
+    psrldq       m3, 2
+%else
+    pshufw       m3, m2, q0021
+%endif
+    punpcklbw    m2, m7
+    punpcklbw    m3, m7
+    paddw        m0, m2
+    paddw        m0, m3
+    psubw        m0, [pw_1]
+
+    CHECK -2, 0
+    CHECK1
+    CHECK -3, 1
+    CHECK2
+    CHECK 0, -2
+    CHECK1
+    CHECK 1, -3
+    CHECK2
+
+    mova         m6, [rsp+48]
+    cmp   DWORD r8m, 2
+    jge .end%1
+    LOAD          2, [%2+t1*2]
+    LOAD          4, [%3+t1*2]
+    LOAD          3, [%2+t0*2]
+    LOAD          5, [%3+t0*2]
+    paddw        m2, m4
+    paddw        m3, m5
+    psrlw        m2, 1
+    psrlw        m3, 1
+    mova         m4, [rsp+ 0]
+    mova         m5, [rsp+16]
+    mova         m7, [rsp+32]
+    psubw        m2, m4
+    psubw        m3, m7
+    mova         m0, m5
+    psubw        m5, m4
+    psubw        m0, m7
+    mova         m4, m2
+    pminsw       m2, m3
+    pmaxsw       m3, m4
+    pmaxsw       m2, m5
+    pminsw       m3, m5
+    pmaxsw       m2, m0
+    pminsw       m3, m0
+    pxor         m4, m4
+    pmaxsw       m6, m3
+    psubw        m4, m2
+    pmaxsw       m6, m4
+
+.end%1:
+    mova         m2, [rsp+16]
+    mova         m3, m2
+    psubw        m2, m6
+    paddw        m3, m6
+    pmaxsw       m1, m2
+    pminsw       m1, m3
+    packuswb     m1, m1
+
+    movh     [dstq], m1
+    add        dstq, mmsize/2
+    add       prevq, mmsize/2
+    add        curq, mmsize/2
+    add       nextq, mmsize/2
+    sub   DWORD r4m, mmsize/2
+    jg .loop%1
+%endmacro
+
+%macro YADIF 0
+%if ARCH_X86_32
+cglobal yadif_filter_line, 4, 6, 8, 80, dst, prev, cur, next, w, prefs, \
+                                        mrefs, parity, mode
+%else
+cglobal yadif_filter_line, 4, 7, 8, 80, dst, prev, cur, next, w, prefs, \
+                                        mrefs, parity, mode
+%endif
+    cmp      DWORD wm, 0
+    jle .ret
+%if ARCH_X86_32
+    mov            r4, r5mp
+    mov            r5, r6mp
+    DECLARE_REG_TMP 4,5
+%else
+    movsxd         r5, DWORD r5m
+    movsxd         r6, DWORD r6m
+    DECLARE_REG_TMP 5,6
+%endif
+
+    cmp DWORD paritym, 0
+    je .parity0
+    FILTER 1, prevq, curq
+    jmp .ret
+
+.parity0:
+    FILTER 0, curq, nextq
+
+.ret:
+    RET
+%endmacro
+
+INIT_XMM ssse3
+YADIF
+INIT_XMM sse2
+YADIF
+%if ARCH_X86_32
+INIT_MMX mmxext
+YADIF
+%endif
diff --git a/mythtv/external/FFmpeg/libavfilter/x86/yadif.c b/mythtv/external/FFmpeg/libavfilter/x86/vf_yadif_init.c
similarity index 50%
rename from mythtv/external/FFmpeg/libavfilter/x86/yadif.c
rename to mythtv/external/FFmpeg/libavfilter/x86/vf_yadif_init.c
index b48a3d6f76a..2873744d4bb 100644
--- a/mythtv/external/FFmpeg/libavfilter/x86/yadif.c
+++ b/mythtv/external/FFmpeg/libavfilter/x86/vf_yadif_init.c
@@ -22,52 +22,38 @@
 #include "libavutil/cpu.h"
 #include "libavutil/mem.h"
 #include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/x86/dsputil_mmx.h"
 #include "libavfilter/yadif.h"
 
-#if HAVE_INLINE_ASM
-
-DECLARE_ASM_CONST(16, const xmm_reg, pb_1) = {0x0101010101010101ULL, 0x0101010101010101ULL};
-DECLARE_ASM_CONST(16, const xmm_reg, pw_1) = {0x0001000100010001ULL, 0x0001000100010001ULL};
-
-#if HAVE_SSSE3_INLINE
-#define COMPILE_TEMPLATE_SSE2 1
-#define COMPILE_TEMPLATE_SSSE3 1
-#undef RENAME
-#define RENAME(a) a ## _ssse3
-#include "yadif_template.c"
-#undef COMPILE_TEMPLATE_SSSE3
-#endif
-
-#if HAVE_SSE2_INLINE
-#undef RENAME
-#define RENAME(a) a ## _sse2
-#include "yadif_template.c"
-#undef COMPILE_TEMPLATE_SSE2
-#endif
-
-#if HAVE_MMXEXT_INLINE
-#undef RENAME
-#define RENAME(a) a ## _mmxext
-#include "yadif_template.c"
-#endif
-
-#endif /* HAVE_INLINE_ASM */
+void ff_yadif_filter_line_mmxext(void *dst, void *prev, void *cur,
+                                 void *next, int w, int prefs,
+                                 int mrefs, int parity, int mode);
+void ff_yadif_filter_line_sse2(void *dst, void *prev, void *cur,
+                               void *next, int w, int prefs,
+                               int mrefs, int parity, int mode);
+void ff_yadif_filter_line_ssse3(void *dst, void *prev, void *cur,
+                                void *next, int w, int prefs,
+                                int mrefs, int parity, int mode);
 
 av_cold void ff_yadif_init_x86(YADIFContext *yadif)
 {
     int cpu_flags = av_get_cpu_flags();
 
-#if HAVE_MMXEXT_INLINE
-    if (cpu_flags & AV_CPU_FLAG_MMXEXT)
-        yadif->filter_line = yadif_filter_line_mmxext;
-#endif
-#if HAVE_SSE2_INLINE
-    if (cpu_flags & AV_CPU_FLAG_SSE2)
-        yadif->filter_line = yadif_filter_line_sse2;
-#endif
-#if HAVE_SSSE3_INLINE
-    if (cpu_flags & AV_CPU_FLAG_SSSE3)
-        yadif->filter_line = yadif_filter_line_ssse3;
-#endif
+#if HAVE_YASM
+#if ARCH_X86_32
+    if (EXTERNAL_MMXEXT(cpu_flags)) {
+        yadif->filter_line = ff_yadif_filter_line_mmxext;
+        yadif->req_align   = 8;
+    }
+#endif /* ARCH_X86_32 */
+    if (EXTERNAL_SSE2(cpu_flags)) {
+        yadif->filter_line = ff_yadif_filter_line_sse2;
+        yadif->req_align   = 16;
+    }
+    if (EXTERNAL_SSSE3(cpu_flags)) {
+        yadif->filter_line = ff_yadif_filter_line_ssse3;
+        yadif->req_align   = 16;
+    }
+#endif /* HAVE_YASM */
 }
diff --git a/mythtv/external/FFmpeg/libavfilter/x86/yadif_template.c b/mythtv/external/FFmpeg/libavfilter/x86/yadif_template.c
deleted file mode 100644
index 674c0884712..00000000000
--- a/mythtv/external/FFmpeg/libavfilter/x86/yadif_template.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright (C) 2006 Michael Niedermayer 
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU 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.
- */
-
-#ifdef COMPILE_TEMPLATE_SSE2
-#define MM "%%xmm"
-#define MOV  "movq"
-#define MOVQ "movdqa"
-#define MOVQU "movdqu"
-#define STEP 8
-#define LOAD(mem,dst) \
-            MOV"       "mem", "dst" \n\t"\
-            "punpcklbw "MM"7, "dst" \n\t"
-#define PSRL1(reg) "psrldq $1, "reg" \n\t"
-#define PSRL2(reg) "psrldq $2, "reg" \n\t"
-#define PSHUF(src,dst) "movdqa "dst", "src" \n\t"\
-                       "psrldq $2, "src"     \n\t"
-#else
-#define MM "%%mm"
-#define MOV  "movd"
-#define MOVQ "movq"
-#define MOVQU "movq"
-#define STEP 4
-#define LOAD(mem,dst) \
-            MOV"       "mem", "dst" \n\t"\
-            "punpcklbw "MM"7, "dst" \n\t"
-#define PSRL1(reg) "psrlq $8, "reg" \n\t"
-#define PSRL2(reg) "psrlq $16, "reg" \n\t"
-#define PSHUF(src,dst) "pshufw $9, "dst", "src" \n\t"
-#endif
-
-#ifdef COMPILE_TEMPLATE_SSSE3
-#define PABS(tmp,dst) \
-            "pabsw     "dst", "dst" \n\t"
-#else
-#define PABS(tmp,dst) \
-            "pxor     "tmp", "tmp" \n\t"\
-            "psubw    "dst", "tmp" \n\t"\
-            "pmaxsw   "tmp", "dst" \n\t"
-#endif
-
-#define CHECK(pj,mj) \
-            MOVQU" "#pj"(%[cur],%[mrefs]), "MM"2 \n\t" /* cur[x-refs-1+j] */\
-            MOVQU" "#mj"(%[cur],%[prefs]), "MM"3 \n\t" /* cur[x+refs-1-j] */\
-            MOVQ"      "MM"2, "MM"4 \n\t"\
-            MOVQ"      "MM"2, "MM"5 \n\t"\
-            "pxor      "MM"3, "MM"4 \n\t"\
-            "pavgb     "MM"3, "MM"5 \n\t"\
-            "pand     "MANGLE(pb_1)", "MM"4 \n\t"\
-            "psubusb   "MM"4, "MM"5 \n\t"\
-            PSRL1(MM"5")                 \
-            "punpcklbw "MM"7, "MM"5 \n\t" /* (cur[x-refs+j] + cur[x+refs-j])>>1 */\
-            MOVQ"      "MM"2, "MM"4 \n\t"\
-            "psubusb   "MM"3, "MM"2 \n\t"\
-            "psubusb   "MM"4, "MM"3 \n\t"\
-            "pmaxub    "MM"3, "MM"2 \n\t"\
-            MOVQ"      "MM"2, "MM"3 \n\t"\
-            MOVQ"      "MM"2, "MM"4 \n\t" /* ABS(cur[x-refs-1+j] - cur[x+refs-1-j]) */\
-            PSRL1(MM"3")                  /* ABS(cur[x-refs  +j] - cur[x+refs  -j]) */\
-            PSRL2(MM"4")                  /* ABS(cur[x-refs+1+j] - cur[x+refs+1-j]) */\
-            "punpcklbw "MM"7, "MM"2 \n\t"\
-            "punpcklbw "MM"7, "MM"3 \n\t"\
-            "punpcklbw "MM"7, "MM"4 \n\t"\
-            "paddw     "MM"3, "MM"2 \n\t"\
-            "paddw     "MM"4, "MM"2 \n\t" /* score */
-
-#define CHECK1 \
-            MOVQ"      "MM"0, "MM"3 \n\t"\
-            "pcmpgtw   "MM"2, "MM"3 \n\t" /* if(score < spatial_score) */\
-            "pminsw    "MM"2, "MM"0 \n\t" /* spatial_score= score; */\
-            MOVQ"      "MM"3, "MM"6 \n\t"\
-            "pand      "MM"3, "MM"5 \n\t"\
-            "pandn     "MM"1, "MM"3 \n\t"\
-            "por       "MM"5, "MM"3 \n\t"\
-            MOVQ"      "MM"3, "MM"1 \n\t" /* spatial_pred= (cur[x-refs+j] + cur[x+refs-j])>>1; */
-
-#define CHECK2 /* pretend not to have checked dir=2 if dir=1 was bad.\
-                  hurts both quality and speed, but matches the C version. */\
-            "paddw    "MANGLE(pw_1)", "MM"6 \n\t"\
-            "psllw     $14,   "MM"6 \n\t"\
-            "paddsw    "MM"6, "MM"2 \n\t"\
-            MOVQ"      "MM"0, "MM"3 \n\t"\
-            "pcmpgtw   "MM"2, "MM"3 \n\t"\
-            "pminsw    "MM"2, "MM"0 \n\t"\
-            "pand      "MM"3, "MM"5 \n\t"\
-            "pandn     "MM"1, "MM"3 \n\t"\
-            "por       "MM"5, "MM"3 \n\t"\
-            MOVQ"      "MM"3, "MM"1 \n\t"
-
-static void RENAME(yadif_filter_line)(uint8_t *dst, uint8_t *prev, uint8_t *cur,
-                                      uint8_t *next, int w, int prefs,
-                                      int mrefs, int parity, int mode)
-{
-    uint8_t tmpU[5*16];
-    uint8_t *tmp= (uint8_t*)(((uint64_t)(tmpU+15)) & ~15);
-    int x;
-
-#define FILTER\
-    for(x=0; x>1 */\
-            MOVQ"      "MM"0,   (%[tmp]) \n\t" /* c */\
-            MOVQ"      "MM"3, 16(%[tmp]) \n\t" /* d */\
-            MOVQ"      "MM"1, 32(%[tmp]) \n\t" /* e */\
-            "psubw     "MM"4, "MM"2 \n\t"\
-            PABS(      MM"4", MM"2") /* temporal_diff0 */\
-            LOAD("(%[prev],%[mrefs])", MM"3") /* prev[x-refs] */\
-            LOAD("(%[prev],%[prefs])", MM"4") /* prev[x+refs] */\
-            "psubw     "MM"0, "MM"3 \n\t"\
-            "psubw     "MM"1, "MM"4 \n\t"\
-            PABS(      MM"5", MM"3")\
-            PABS(      MM"5", MM"4")\
-            "paddw     "MM"4, "MM"3 \n\t" /* temporal_diff1 */\
-            "psrlw     $1,    "MM"2 \n\t"\
-            "psrlw     $1,    "MM"3 \n\t"\
-            "pmaxsw    "MM"3, "MM"2 \n\t"\
-            LOAD("(%[next],%[mrefs])", MM"3") /* next[x-refs] */\
-            LOAD("(%[next],%[prefs])", MM"4") /* next[x+refs] */\
-            "psubw     "MM"0, "MM"3 \n\t"\
-            "psubw     "MM"1, "MM"4 \n\t"\
-            PABS(      MM"5", MM"3")\
-            PABS(      MM"5", MM"4")\
-            "paddw     "MM"4, "MM"3 \n\t" /* temporal_diff2 */\
-            "psrlw     $1,    "MM"3 \n\t"\
-            "pmaxsw    "MM"3, "MM"2 \n\t"\
-            MOVQ"      "MM"2, 48(%[tmp]) \n\t" /* diff */\
-\
-            "paddw     "MM"0, "MM"1 \n\t"\
-            "paddw     "MM"0, "MM"0 \n\t"\
-            "psubw     "MM"1, "MM"0 \n\t"\
-            "psrlw     $1,    "MM"1 \n\t" /* spatial_pred */\
-            PABS(      MM"2", MM"0")      /* ABS(c-e) */\
-\
-            MOVQU" -1(%[cur],%[mrefs]), "MM"2 \n\t" /* cur[x-refs-1] */\
-            MOVQU" -1(%[cur],%[prefs]), "MM"3 \n\t" /* cur[x+refs-1] */\
-            MOVQ"      "MM"2, "MM"4 \n\t"\
-            "psubusb   "MM"3, "MM"2 \n\t"\
-            "psubusb   "MM"4, "MM"3 \n\t"\
-            "pmaxub    "MM"3, "MM"2 \n\t"\
-            PSHUF(MM"3", MM"2") \
-            "punpcklbw "MM"7, "MM"2 \n\t" /* ABS(cur[x-refs-1] - cur[x+refs-1]) */\
-            "punpcklbw "MM"7, "MM"3 \n\t" /* ABS(cur[x-refs+1] - cur[x+refs+1]) */\
-            "paddw     "MM"2, "MM"0 \n\t"\
-            "paddw     "MM"3, "MM"0 \n\t"\
-            "psubw    "MANGLE(pw_1)", "MM"0 \n\t" /* spatial_score */\
-\
-            CHECK(-2,0)\
-            CHECK1\
-            CHECK(-3,1)\
-            CHECK2\
-            CHECK(0,-2)\
-            CHECK1\
-            CHECK(1,-3)\
-            CHECK2\
-\
-            /* if(p->mode<2) ... */\
-            MOVQ" 48(%[tmp]), "MM"6 \n\t" /* diff */\
-            "cmpl      $2, %[mode] \n\t"\
-            "jge       1f \n\t"\
-            LOAD("(%["prev2"],%[mrefs],2)", MM"2") /* prev2[x-2*refs] */\
-            LOAD("(%["next2"],%[mrefs],2)", MM"4") /* next2[x-2*refs] */\
-            LOAD("(%["prev2"],%[prefs],2)", MM"3") /* prev2[x+2*refs] */\
-            LOAD("(%["next2"],%[prefs],2)", MM"5") /* next2[x+2*refs] */\
-            "paddw     "MM"4, "MM"2 \n\t"\
-            "paddw     "MM"5, "MM"3 \n\t"\
-            "psrlw     $1,    "MM"2 \n\t" /* b */\
-            "psrlw     $1,    "MM"3 \n\t" /* f */\
-            MOVQ"   (%[tmp]), "MM"4 \n\t" /* c */\
-            MOVQ" 16(%[tmp]), "MM"5 \n\t" /* d */\
-            MOVQ" 32(%[tmp]), "MM"7 \n\t" /* e */\
-            "psubw     "MM"4, "MM"2 \n\t" /* b-c */\
-            "psubw     "MM"7, "MM"3 \n\t" /* f-e */\
-            MOVQ"      "MM"5, "MM"0 \n\t"\
-            "psubw     "MM"4, "MM"5 \n\t" /* d-c */\
-            "psubw     "MM"7, "MM"0 \n\t" /* d-e */\
-            MOVQ"      "MM"2, "MM"4 \n\t"\
-            "pminsw    "MM"3, "MM"2 \n\t"\
-            "pmaxsw    "MM"4, "MM"3 \n\t"\
-            "pmaxsw    "MM"5, "MM"2 \n\t"\
-            "pminsw    "MM"5, "MM"3 \n\t"\
-            "pmaxsw    "MM"0, "MM"2 \n\t" /* max */\
-            "pminsw    "MM"0, "MM"3 \n\t" /* min */\
-            "pxor      "MM"4, "MM"4 \n\t"\
-            "pmaxsw    "MM"3, "MM"6 \n\t"\
-            "psubw     "MM"2, "MM"4 \n\t" /* -max */\
-            "pmaxsw    "MM"4, "MM"6 \n\t" /* diff= MAX3(diff, min, -max); */\
-            "1: \n\t"\
-\
-            MOVQ" 16(%[tmp]), "MM"2 \n\t" /* d */\
-            MOVQ"      "MM"2, "MM"3 \n\t"\
-            "psubw     "MM"6, "MM"2 \n\t" /* d-diff */\
-            "paddw     "MM"6, "MM"3 \n\t" /* d+diff */\
-            "pmaxsw    "MM"2, "MM"1 \n\t"\
-            "pminsw    "MM"3, "MM"1 \n\t" /* d = clip(spatial_pred, d-diff, d+diff); */\
-            "packuswb  "MM"1, "MM"1 \n\t"\
-\
-            ::[prev] "r"(prev),\
-             [cur]  "r"(cur),\
-             [next] "r"(next),\
-             [prefs]"r"((x86_reg)prefs),\
-             [mrefs]"r"((x86_reg)mrefs),\
-             [mode] "g"(mode),\
-             [tmp]  "r"(tmp)\
-        );\
-        __asm__ volatile(MOV" "MM"1, %0" :"=m"(*dst));\
-        dst += STEP;\
-        prev+= STEP;\
-        cur += STEP;\
-        next+= STEP;\
-    }
-
-    if (parity) {
-#define prev2 "prev"
-#define next2 "cur"
-        FILTER
-#undef prev2
-#undef next2
-    } else {
-#define prev2 "cur"
-#define next2 "next"
-        FILTER
-#undef prev2
-#undef next2
-    }
-}
-#undef STEP
-#undef MM
-#undef MOV
-#undef MOVQ
-#undef MOVQU
-#undef PSHUF
-#undef PSRL1
-#undef PSRL2
-#undef LOAD
-#undef PABS
-#undef CHECK
-#undef CHECK1
-#undef CHECK2
-#undef FILTER
diff --git a/mythtv/external/FFmpeg/libavfilter/yadif.h b/mythtv/external/FFmpeg/libavfilter/yadif.h
index d2084fa86e3..50fc856bf2c 100644
--- a/mythtv/external/FFmpeg/libavfilter/yadif.h
+++ b/mythtv/external/FFmpeg/libavfilter/yadif.h
@@ -53,9 +53,17 @@ typedef struct YADIFContext {
     AVFilterBufferRef *next;
     AVFilterBufferRef *prev;
     AVFilterBufferRef *out;
-    void (*filter_line)(uint8_t *dst,
-                        uint8_t *prev, uint8_t *cur, uint8_t *next,
+
+    /**
+     * Required alignment for filter_line
+     */
+    int req_align;
+    void (*filter_line)(void *dst,
+                        void *prev, void *cur, void *next,
                         int w, int prefs, int mrefs, int parity, int mode);
+    void (*filter_edges)(void *dst, void *prev, void *cur, void *next,
+                         int w, int prefs, int mrefs, int parity, int mode,
+                         int l_edge);
 
     const AVPixFmtDescriptor *csp;
     int eof;
diff --git a/mythtv/external/FFmpeg/libavformat/Makefile b/mythtv/external/FFmpeg/libavformat/Makefile
index cc71629a373..00fb41e62dc 100644
--- a/mythtv/external/FFmpeg/libavformat/Makefile
+++ b/mythtv/external/FFmpeg/libavformat/Makefile
@@ -37,13 +37,16 @@ OBJS-$(CONFIG_RTPDEC)                    += rdt.o                       \
                                             rtpdec_ilbc.o               \
                                             rtpdec_jpeg.o               \
                                             rtpdec_latm.o               \
+                                            rtpdec_mpeg12.o             \
                                             rtpdec_mpeg4.o              \
+                                            rtpdec_mpegts.o             \
                                             rtpdec_qcelp.o              \
                                             rtpdec_qdm2.o               \
                                             rtpdec_qt.o                 \
                                             rtpdec_svq3.o               \
                                             rtpdec_vp8.o                \
-                                            rtpdec_xiph.o
+                                            rtpdec_xiph.o               \
+                                            srtp.o
 OBJS-$(CONFIG_RTPENC_CHAIN)              += rtpenc_chain.o rtp.o
 OBJS-$(CONFIG_SHARED)                    += log2_tab.o
 
@@ -61,7 +64,7 @@ OBJS-$(CONFIG_AEA_DEMUXER)               += aea.o pcm.o
 OBJS-$(CONFIG_AFC_DEMUXER)               += afc.o
 OBJS-$(CONFIG_AIFF_DEMUXER)              += aiffdec.o pcm.o isom.o \
                                             mov_chan.o
-OBJS-$(CONFIG_AIFF_MUXER)                += aiffenc.o isom.o rawenc.o
+OBJS-$(CONFIG_AIFF_MUXER)                += aiffenc.o isom.o id3v2enc.o
 OBJS-$(CONFIG_AMR_DEMUXER)               += amr.o
 OBJS-$(CONFIG_AMR_MUXER)                 += amr.o
 OBJS-$(CONFIG_ANM_DEMUXER)               += anm.o
@@ -181,7 +184,7 @@ OBJS-$(CONFIG_JV_DEMUXER)                += jvdec.o
 OBJS-$(CONFIG_LATM_DEMUXER)              += rawdec.o
 OBJS-$(CONFIG_LATM_MUXER)                += latmenc.o rawenc.o
 OBJS-$(CONFIG_LMLM4_DEMUXER)             += lmlm4.o
-OBJS-$(CONFIG_LOAS_DEMUXER)              += loasdec.o
+OBJS-$(CONFIG_LOAS_DEMUXER)              += loasdec.o rawdec.o
 OBJS-$(CONFIG_LVF_DEMUXER)               += lvfdec.o
 OBJS-$(CONFIG_LXF_DEMUXER)               += lxfdec.o
 OBJS-$(CONFIG_M4V_DEMUXER)               += m4vdec.o rawdec.o
@@ -194,7 +197,7 @@ OBJS-$(CONFIG_MATROSKA_MUXER)            += matroskaenc.o matroska.o \
 OBJS-$(CONFIG_MD5_MUXER)                 += md5enc.o
 OBJS-$(CONFIG_MGSTS_DEMUXER)             += mgsts.o
 OBJS-$(CONFIG_MICRODVD_DEMUXER)          += microdvddec.o
-OBJS-$(CONFIG_MICRODVD_MUXER)            += microdvdenc.o rawenc.o
+OBJS-$(CONFIG_MICRODVD_MUXER)            += microdvdenc.o
 OBJS-$(CONFIG_MJPEG_DEMUXER)             += rawdec.o
 OBJS-$(CONFIG_MJPEG_MUXER)               += rawenc.o
 OBJS-$(CONFIG_MLP_DEMUXER)               += rawdec.o
@@ -357,6 +360,7 @@ OBJS-$(CONFIG_SWF_DEMUXER)               += swfdec.o swf.o
 OBJS-$(CONFIG_SWF_MUXER)                 += swfenc.o swf.o
 OBJS-$(CONFIG_TAK_DEMUXER)               += takdec.o apetag.o img2.o rawdec.o
 OBJS-$(CONFIG_TEDCAPTIONS_DEMUXER)       += tedcaptionsdec.o
+OBJS-$(CONFIG_TEE_MUXER)                 += tee.o
 OBJS-$(CONFIG_THP_DEMUXER)               += thp.o
 OBJS-$(CONFIG_TIERTEXSEQ_DEMUXER)        += tiertexseq.o
 OBJS-$(CONFIG_MKVTIMESTAMP_V2_MUXER)     += mkvtimestamp_v2.o
@@ -432,16 +436,20 @@ OBJS-$(CONFIG_RTMPTE_PROTOCOL)           += rtmpproto.o rtmppkt.o
 OBJS-$(CONFIG_RTMPTS_PROTOCOL)           += rtmpproto.o rtmppkt.o
 OBJS-$(CONFIG_RTP_PROTOCOL)              += rtpproto.o
 OBJS-$(CONFIG_SCTP_PROTOCOL)             += sctp.o
+OBJS-$(CONFIG_SRTP_PROTOCOL)             += srtpproto.o srtp.o
 OBJS-$(CONFIG_TCP_PROTOCOL)              += tcp.o
 OBJS-$(CONFIG_TLS_PROTOCOL)              += tls.o
 OBJS-$(CONFIG_UDP_PROTOCOL)              += udp.o
 
 SKIPHEADERS-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += rtmpdh.h
 SKIPHEADERS-$(CONFIG_NETWORK)            += network.h rtsp.h
-TESTPROGS = seek                                                        \
+TESTPROGS = noproxy                                                     \
+            seek                                                        \
+            srtp                                                        \
             url                                                         \
 
 TOOLS     = aviocat                                                     \
             ismindex                                                    \
             pktdumper                                                   \
             probetest                                                   \
+            seek_print                                                  \
diff --git a/mythtv/external/FFmpeg/libavformat/aiffenc.c b/mythtv/external/FFmpeg/libavformat/aiffenc.c
index 525bd496231..7c0b4fb8033 100644
--- a/mythtv/external/FFmpeg/libavformat/aiffenc.c
+++ b/mythtv/external/FFmpeg/libavformat/aiffenc.c
@@ -20,19 +20,66 @@
  */
 
 #include "libavutil/intfloat.h"
+#include "libavutil/opt.h"
 #include "avformat.h"
 #include "internal.h"
 #include "aiff.h"
 #include "avio_internal.h"
 #include "isom.h"
-#include "rawenc.h"
+#include "id3v2.h"
 
 typedef struct {
+    const AVClass *class;
     int64_t form;
     int64_t frames;
     int64_t ssnd;
+    int audio_stream_idx;
+    AVPacketList *pict_list;
+    int write_id3v2;
+    int id3v2_version;
 } AIFFOutputContext;
 
+static int put_id3v2_tags(AVFormatContext *s, AIFFOutputContext *aiff)
+{
+    int ret;
+    uint64_t pos, end, size;
+    ID3v2EncContext id3v2 = { 0 };
+    AVIOContext *pb = s->pb;
+    AVPacketList *pict_list = aiff->pict_list;
+
+    if (!pb->seekable)
+        return 0;
+
+    if (!s->metadata && !aiff->pict_list)
+        return 0;
+
+    avio_wl32(pb, MKTAG('I', 'D', '3', ' '));
+    avio_wb32(pb, 0);
+    pos = avio_tell(pb);
+
+    ff_id3v2_start(&id3v2, pb, aiff->id3v2_version, ID3v2_DEFAULT_MAGIC);
+    ff_id3v2_write_metadata(s, &id3v2);
+    while (pict_list) {
+        if ((ret = ff_id3v2_write_apic(s, &id3v2, &pict_list->pkt)) < 0)
+            return ret;
+        pict_list = pict_list->next;
+    }
+    ff_id3v2_finish(&id3v2, pb);
+
+    end = avio_tell(pb);
+    size = end - pos;
+
+    /* Update chunk size */
+    avio_seek(pb, pos - 4, SEEK_SET);
+    avio_wb32(pb, size);
+    avio_seek(pb, end, SEEK_SET);
+
+    if (size & 1)
+        avio_w8(pb, 0);
+
+    return 0;
+}
+
 static void put_meta(AVFormatContext *s, const char *key, uint32_t id)
 {
     AVDictionaryEntry *tag;
@@ -53,9 +100,26 @@ static int aiff_write_header(AVFormatContext *s)
 {
     AIFFOutputContext *aiff = s->priv_data;
     AVIOContext *pb = s->pb;
-    AVCodecContext *enc = s->streams[0]->codec;
+    AVCodecContext *enc;
     uint64_t sample_rate;
-    int aifc = 0;
+    int i, aifc = 0;
+
+    aiff->audio_stream_idx = -1;
+    for (i = 0; i < s->nb_streams; i++) {
+        AVStream *st = s->streams[i];
+        if (aiff->audio_stream_idx < 0 && st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+            aiff->audio_stream_idx = i;
+        } else if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO) {
+            av_log(s, AV_LOG_ERROR, "Only audio streams and pictures are allowed in AIFF.\n");
+            return AVERROR(EINVAL);
+        }
+    }
+    if (aiff->audio_stream_idx < 0) {
+        av_log(s, AV_LOG_ERROR, "No audio stream present.\n");
+        return AVERROR(EINVAL);
+    }
+
+    enc = s->streams[aiff->audio_stream_idx]->codec;
 
     /* First verify if format is ok */
     if (!enc->codec_tag)
@@ -132,7 +196,8 @@ static int aiff_write_header(AVFormatContext *s)
     avio_wb32(pb, 0);                    /* Data offset */
     avio_wb32(pb, 0);                    /* Block-size (block align) */
 
-    avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
+    avpriv_set_pts_info(s->streams[aiff->audio_stream_idx], 64, 1,
+                        s->streams[aiff->audio_stream_idx]->codec->sample_rate);
 
     /* Data is starting here */
     avio_flush(pb);
@@ -140,11 +205,56 @@ static int aiff_write_header(AVFormatContext *s)
     return 0;
 }
 
+static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    AIFFOutputContext *aiff = s->priv_data;
+    AVIOContext *pb = s->pb;
+    if (pkt->stream_index == aiff->audio_stream_idx)
+        avio_write(pb, pkt->data, pkt->size);
+    else {
+        int ret;
+        AVPacketList *pict_list, *last;
+
+        if (s->streams[pkt->stream_index]->codec->codec_type != AVMEDIA_TYPE_VIDEO)
+            return 0;
+
+        /* warn only once for each stream */
+        if (s->streams[pkt->stream_index]->nb_frames == 1) {
+            av_log(s, AV_LOG_WARNING, "Got more than one picture in stream %d,"
+                   " ignoring.\n", pkt->stream_index);
+        }
+        if (s->streams[pkt->stream_index]->nb_frames >= 1)
+            return 0;
+
+        pict_list = av_mallocz(sizeof(AVPacketList));
+        if (!pict_list)
+            return AVERROR(ENOMEM);
+
+        if ((ret = av_copy_packet(&pict_list->pkt, pkt)) < 0) {
+            av_freep(&pict_list);
+            return ret;
+        }
+
+        if (!aiff->pict_list)
+            aiff->pict_list = pict_list;
+        else {
+            last = aiff->pict_list;
+            while (last->next)
+                last = last->next;
+            last->next = pict_list;
+        }
+    }
+
+    return 0;
+}
+
 static int aiff_write_trailer(AVFormatContext *s)
 {
+    int ret;
     AVIOContext *pb = s->pb;
     AIFFOutputContext *aiff = s->priv_data;
-    AVCodecContext *enc = s->streams[0]->codec;
+    AVPacketList *pict_list = aiff->pict_list;
+    AVCodecContext *enc = s->streams[aiff->audio_stream_idx]->codec;
 
     /* Chunks sizes must be even */
     int64_t file_size, end_size;
@@ -155,10 +265,6 @@ static int aiff_write_trailer(AVFormatContext *s)
     }
 
     if (s->pb->seekable) {
-        /* File length */
-        avio_seek(pb, aiff->form, SEEK_SET);
-        avio_wb32(pb, file_size - aiff->form - 4);
-
         /* Number of sample frames */
         avio_seek(pb, aiff->frames, SEEK_SET);
         avio_wb32(pb, (file_size-aiff->ssnd-12)/enc->block_align);
@@ -170,12 +276,46 @@ static int aiff_write_trailer(AVFormatContext *s)
         /* return to the end */
         avio_seek(pb, end_size, SEEK_SET);
 
+        /* Write ID3 tags */
+        if (aiff->write_id3v2)
+            if ((ret = put_id3v2_tags(s, aiff)) < 0)
+                return ret;
+
+        /* File length */
+        file_size = avio_tell(pb);
+        avio_seek(pb, aiff->form, SEEK_SET);
+        avio_wb32(pb, file_size - aiff->form - 4);
+
         avio_flush(pb);
     }
 
+    while (pict_list) {
+        AVPacketList *next = pict_list->next;
+        av_free_packet(&pict_list->pkt);
+        av_freep(&pict_list);
+        pict_list = next;
+    }
+
     return 0;
 }
 
+#define OFFSET(x) offsetof(AIFFOutputContext, x)
+#define ENC AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+    { "write_id3v2", "Enable ID3 tags writing.",
+      OFFSET(write_id3v2), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, ENC },
+    { "id3v2_version", "Select ID3v2 version to write. Currently 3 and 4 are supported.",
+      OFFSET(id3v2_version), AV_OPT_TYPE_INT, {.i64 = 4}, 3, 4, ENC },
+    { NULL },
+};
+
+static const AVClass aiff_muxer_class = {
+    .class_name     = "AIFF muxer",
+    .item_name      = av_default_item_name,
+    .option         = options,
+    .version        = LIBAVUTIL_VERSION_INT,
+};
+
 AVOutputFormat ff_aiff_muxer = {
     .name              = "aiff",
     .long_name         = NULL_IF_CONFIG_SMALL("Audio IFF"),
@@ -183,9 +323,10 @@ AVOutputFormat ff_aiff_muxer = {
     .extensions        = "aif,aiff,afc,aifc",
     .priv_data_size    = sizeof(AIFFOutputContext),
     .audio_codec       = AV_CODEC_ID_PCM_S16BE,
-    .video_codec       = AV_CODEC_ID_NONE,
+    .video_codec       = AV_CODEC_ID_PNG,
     .write_header      = aiff_write_header,
-    .write_packet      = ff_raw_write_packet,
+    .write_packet      = aiff_write_packet,
     .write_trailer     = aiff_write_trailer,
     .codec_tag         = (const AVCodecTag* const []){ ff_codec_aiff_tags, 0 },
+    .priv_class        = &aiff_muxer_class,
 };
diff --git a/mythtv/external/FFmpeg/libavformat/allformats.c b/mythtv/external/FFmpeg/libavformat/allformats.c
index 2894813824a..3d5cca9e765 100644
--- a/mythtv/external/FFmpeg/libavformat/allformats.c
+++ b/mythtv/external/FFmpeg/libavformat/allformats.c
@@ -266,6 +266,7 @@ void av_register_all(void)
     REGISTER_DEMUXER (SUBVIEWER,        subviewer);
     REGISTER_MUXDEMUX(SWF,              swf);
     REGISTER_DEMUXER (TAK,              tak);
+    REGISTER_MUXER   (TEE, tee);
     REGISTER_DEMUXER (TEDCAPTIONS,      tedcaptions);
     REGISTER_MUXER   (TG2,              tg2);
     REGISTER_MUXER   (TGP,              tgp);
@@ -330,6 +331,7 @@ void av_register_all(void)
     REGISTER_PROTOCOL(RTMPTS,           rtmpts);
     REGISTER_PROTOCOL(RTP,              rtp);
     REGISTER_PROTOCOL(SCTP,             sctp);
+    REGISTER_PROTOCOL(SRTP,             srtp);
     REGISTER_PROTOCOL(TCP,              tcp);
     REGISTER_PROTOCOL(TLS,              tls);
     REGISTER_PROTOCOL(UDP,              udp);
diff --git a/mythtv/external/FFmpeg/libavformat/asf.c b/mythtv/external/FFmpeg/libavformat/asf.c
index 8e360d3596b..dd64a3fbd05 100644
--- a/mythtv/external/FFmpeg/libavformat/asf.c
+++ b/mythtv/external/FFmpeg/libavformat/asf.c
@@ -20,7 +20,6 @@
 
 #include "asf.h"
 
-
 const ff_asf_guid ff_asf_header = {
     0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C
 };
@@ -48,7 +47,7 @@ const ff_asf_guid ff_asf_audio_conceal_none = {
 };
 
 const ff_asf_guid ff_asf_audio_conceal_spread = {
-     0x50, 0xCD, 0xC3, 0xBF, 0x8F, 0x61, 0xCF, 0x11, 0x8B, 0xB2, 0x00, 0xAA, 0x00, 0xB4, 0xE2, 0x20
+    0x50, 0xCD, 0xC3, 0xBF, 0x8F, 0x61, 0xCF, 0x11, 0x8B, 0xB2, 0x00, 0xAA, 0x00, 0xB4, 0xE2, 0x20
 };
 
 const ff_asf_guid ff_asf_video_stream = {
@@ -91,31 +90,35 @@ const ff_asf_guid ff_asf_head2_guid = {
 };
 
 const ff_asf_guid ff_asf_extended_content_header = {
-        0x40, 0xA4, 0xD0, 0xD2, 0x07, 0xE3, 0xD2, 0x11, 0x97, 0xF0, 0x00, 0xA0, 0xC9, 0x5E, 0xA8, 0x50
+    0x40, 0xA4, 0xD0, 0xD2, 0x07, 0xE3, 0xD2, 0x11, 0x97, 0xF0, 0x00, 0xA0, 0xC9, 0x5E, 0xA8, 0x50
 };
 
 const ff_asf_guid ff_asf_simple_index_header = {
-        0x90, 0x08, 0x00, 0x33, 0xB1, 0xE5, 0xCF, 0x11, 0x89, 0xF4, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB
+    0x90, 0x08, 0x00, 0x33, 0xB1, 0xE5, 0xCF, 0x11, 0x89, 0xF4, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB
 };
 
 const ff_asf_guid ff_asf_ext_stream_embed_stream_header = {
-        0xe2, 0x65, 0xfb, 0x3a, 0xEF, 0x47, 0xF2, 0x40, 0xac, 0x2c, 0x70, 0xa9, 0x0d, 0x71, 0xd3, 0x43
+    0xe2, 0x65, 0xfb, 0x3a, 0xEF, 0x47, 0xF2, 0x40, 0xac, 0x2c, 0x70, 0xa9, 0x0d, 0x71, 0xd3, 0x43
 };
 
 const ff_asf_guid ff_asf_ext_stream_audio_stream = {
-        0x9d, 0x8c, 0x17, 0x31, 0xE1, 0x03, 0x28, 0x45, 0xb5, 0x82, 0x3d, 0xf9, 0xdb, 0x22, 0xf5, 0x03
+    0x9d, 0x8c, 0x17, 0x31, 0xE1, 0x03, 0x28, 0x45, 0xb5, 0x82, 0x3d, 0xf9, 0xdb, 0x22, 0xf5, 0x03
 };
 
 const ff_asf_guid ff_asf_metadata_header = {
-        0xea, 0xcb, 0xf8, 0xc5, 0xaf, 0x5b, 0x77, 0x48, 0x84, 0x67, 0xaa, 0x8c, 0x44, 0xfa, 0x4c, 0xca
+    0xea, 0xcb, 0xf8, 0xc5, 0xaf, 0x5b, 0x77, 0x48, 0x84, 0x67, 0xaa, 0x8c, 0x44, 0xfa, 0x4c, 0xca
+};
+
+const ff_asf_guid ff_asf_metadata_library_header = {
+    0x94, 0x1c, 0x23, 0x44, 0x98, 0x94, 0xd1, 0x49, 0xa1, 0x41, 0x1d, 0x13, 0x4e, 0x45, 0x70, 0x54
 };
 
 const ff_asf_guid ff_asf_marker_header = {
-        0x01, 0xCD, 0x87, 0xF4, 0x51, 0xA9, 0xCF, 0x11, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65
+    0x01, 0xCD, 0x87, 0xF4, 0x51, 0xA9, 0xCF, 0x11, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65
 };
 
 /* I am not a number !!! This GUID is the one found on the PC used to
-   generate the stream */
+ * generate the stream */
 const ff_asf_guid ff_asf_my_guid = {
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
@@ -138,22 +141,22 @@ const ff_asf_guid ff_asf_digital_signature = {
 
 /* List of official tags at http://msdn.microsoft.com/en-us/library/dd743066(VS.85).aspx */
 const AVMetadataConv ff_asf_metadata_conv[] = {
-    { "WM/AlbumArtist"     , "album_artist"},
-    { "WM/AlbumTitle"      , "album"       },
-    { "Author"             , "artist"      },
-    { "Description"        , "comment"     },
-    { "WM/Composer"        , "composer"    },
-    { "WM/EncodedBy"       , "encoded_by"  },
-    { "WM/EncodingSettings", "encoder"     },
-    { "WM/Genre"           , "genre"       },
-    { "WM/Language"        , "language"    },
-    { "WM/OriginalFilename", "filename"    },
-    { "WM/PartOfSet"       , "disc"        },
-    { "WM/Publisher"       , "publisher"   },
-    { "WM/Tool"            , "encoder"     },
-    { "WM/TrackNumber"     , "track"       },
+    { "WM/AlbumArtist",          "album_artist"     },
+    { "WM/AlbumTitle",           "album"            },
+    { "Author",                  "artist"           },
+    { "Description",             "comment"          },
+    { "WM/Composer",             "composer"         },
+    { "WM/EncodedBy",            "encoded_by"       },
+    { "WM/EncodingSettings",     "encoder"          },
+    { "WM/Genre",                "genre"            },
+    { "WM/Language",             "language"         },
+    { "WM/OriginalFilename",     "filename"         },
+    { "WM/PartOfSet",            "disc"             },
+    { "WM/Publisher",            "publisher"        },
+    { "WM/Tool",                 "encoder"          },
+    { "WM/TrackNumber",          "track"            },
     { "WM/MediaStationCallSign", "service_provider" },
-    { "WM/MediaStationName", "service_name" },
+    { "WM/MediaStationName",     "service_name"     },
 //  { "Year"               , "date"        }, TODO: conversion year<->date
     { 0 }
 };
diff --git a/mythtv/external/FFmpeg/libavformat/asf.h b/mythtv/external/FFmpeg/libavformat/asf.h
index 528d4c17738..5ffc7465a86 100644
--- a/mythtv/external/FFmpeg/libavformat/asf.h
+++ b/mythtv/external/FFmpeg/libavformat/asf.h
@@ -110,6 +110,7 @@ extern const ff_asf_guid ff_asf_simple_index_header;
 extern const ff_asf_guid ff_asf_ext_stream_embed_stream_header;
 extern const ff_asf_guid ff_asf_ext_stream_audio_stream;
 extern const ff_asf_guid ff_asf_metadata_header;
+extern const ff_asf_guid ff_asf_metadata_library_header;
 extern const ff_asf_guid ff_asf_marker_header;
 extern const ff_asf_guid ff_asf_my_guid;
 extern const ff_asf_guid ff_asf_language_guid;
diff --git a/mythtv/external/FFmpeg/libavformat/asfcrypt.c b/mythtv/external/FFmpeg/libavformat/asfcrypt.c
index 6a51c0426e7..a402758d0a8 100644
--- a/mythtv/external/FFmpeg/libavformat/asfcrypt.c
+++ b/mythtv/external/FFmpeg/libavformat/asfcrypt.c
@@ -20,10 +20,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavutil/common.h"
-#include "libavutil/intreadwrite.h"
 #include "libavutil/bswap.h"
+#include "libavutil/common.h"
 #include "libavutil/des.h"
+#include "libavutil/intreadwrite.h"
 #include "libavutil/rc4.h"
 #include "asfcrypt.h"
 
@@ -32,7 +32,8 @@
  * @param v number to invert, must be odd!
  * @return number so that result * v = 1 (mod 2^32)
  */
-static uint32_t inverse(uint32_t v) {
+static uint32_t inverse(uint32_t v)
+{
     // v ^ 3 gives the inverse (mod 16), could also be implemented
     // as table etc. (only lowest 4 bits matter!)
     uint32_t inverse = v * v * v;
@@ -50,7 +51,8 @@ static uint32_t inverse(uint32_t v) {
  * @param keys output key array containing the keys for encryption in
  *             native endianness
  */
-static void multiswap_init(const uint8_t keybuf[48], uint32_t keys[12]) {
+static void multiswap_init(const uint8_t keybuf[48], uint32_t keys[12])
+{
     int i;
     for (i = 0; i < 12; i++)
         keys[i] = AV_RL32(keybuf + (i << 2)) | 1;
@@ -61,7 +63,8 @@ static void multiswap_init(const uint8_t keybuf[48], uint32_t keys[12]) {
  *        the other way round.
  * @param keys key array of ints to invert
  */
-static void multiswap_invert_keys(uint32_t keys[12]) {
+static void multiswap_invert_keys(uint32_t keys[12])
+{
     int i;
     for (i = 0; i < 5; i++)
         keys[i] = inverse(keys[i]);
@@ -69,23 +72,25 @@ static void multiswap_invert_keys(uint32_t keys[12]) {
         keys[i] = inverse(keys[i]);
 }
 
-static uint32_t multiswap_step(const uint32_t keys[12], uint32_t v) {
+static uint32_t multiswap_step(const uint32_t keys[12], uint32_t v)
+{
     int i;
     v *= keys[0];
     for (i = 1; i < 5; i++) {
-        v = (v >> 16) | (v << 16);
+        v  = (v >> 16) | (v << 16);
         v *= keys[i];
     }
     v += keys[5];
     return v;
 }
 
-static uint32_t multiswap_inv_step(const uint32_t keys[12], uint32_t v) {
+static uint32_t multiswap_inv_step(const uint32_t keys[12], uint32_t v)
+{
     int i;
     v -= keys[5];
     for (i = 4; i > 0; i--) {
         v *= keys[i];
-        v = (v >> 16) | (v << 16);
+        v  = (v >> 16) | (v << 16);
     }
     v *= keys[0];
     return v;
@@ -99,17 +104,19 @@ static uint32_t multiswap_inv_step(const uint32_t keys[12], uint32_t v) {
  * @param data data to encrypt
  * @return encrypted data
  */
-static uint64_t multiswap_enc(const uint32_t keys[12], uint64_t key, uint64_t data) {
+static uint64_t multiswap_enc(const uint32_t keys[12],
+                              uint64_t key, uint64_t data)
+{
     uint32_t a = data;
     uint32_t b = data >> 32;
     uint32_t c;
     uint32_t tmp;
-    a += key;
-    tmp = multiswap_step(keys    , a);
-    b += tmp;
-    c = (key >> 32) + tmp;
+    a  += key;
+    tmp = multiswap_step(keys, a);
+    b  += tmp;
+    c   = (key >> 32) + tmp;
     tmp = multiswap_step(keys + 6, b);
-    c += tmp;
+    c  += tmp;
     return ((uint64_t)c << 32) | tmp;
 }
 
@@ -121,25 +128,28 @@ static uint64_t multiswap_enc(const uint32_t keys[12], uint64_t key, uint64_t da
  * @param data data to decrypt
  * @return decrypted data
  */
-static uint64_t multiswap_dec(const uint32_t keys[12], uint64_t key, uint64_t data) {
+static uint64_t multiswap_dec(const uint32_t keys[12],
+                              uint64_t key, uint64_t data)
+{
     uint32_t a;
     uint32_t b;
-    uint32_t c = data >> 32;
+    uint32_t c   = data >> 32;
     uint32_t tmp = data;
-    c -= tmp;
-    b = multiswap_inv_step(keys + 6, tmp);
+    c  -= tmp;
+    b   = multiswap_inv_step(keys + 6, tmp);
     tmp = c - (key >> 32);
-    b -= tmp;
-    a = multiswap_inv_step(keys    , tmp);
-    a -= key;
+    b  -= tmp;
+    a   = multiswap_inv_step(keys, tmp);
+    a  -= key;
     return ((uint64_t)b << 32) | a;
 }
 
-void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) {
+void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len)
+{
     struct AVDES des;
     struct AVRC4 rc4;
-    int num_qwords = len >> 3;
-    uint8_t *qwords = data;
+    int num_qwords      = len >> 3;
+    uint8_t *qwords     = data;
     uint64_t rc4buff[8] = { 0 };
     uint64_t packetkey;
     uint32_t ms_keys[12];
@@ -155,7 +165,7 @@ void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) {
     av_rc4_crypt(&rc4, (uint8_t *)rc4buff, NULL, sizeof(rc4buff), NULL, 1);
     multiswap_init((uint8_t *)rc4buff, ms_keys);
 
-    packetkey = AV_RN64(&qwords[num_qwords*8 - 8]);
+    packetkey  = AV_RN64(&qwords[num_qwords * 8 - 8]);
     packetkey ^= rc4buff[7];
     av_des_init(&des, key + 12, 64, 1);
     av_des_crypt(&des, (uint8_t *)&packetkey, (uint8_t *)&packetkey, 1, NULL, 1);
diff --git a/mythtv/external/FFmpeg/libavformat/asfdec.c b/mythtv/external/FFmpeg/libavformat/asfdec.c
index 2dcdf56adbf..de42b45a8ec 100644
--- a/mythtv/external/FFmpeg/libavformat/asfdec.c
+++ b/mythtv/external/FFmpeg/libavformat/asfdec.c
@@ -22,20 +22,21 @@
 //#define DEBUG
 
 #include "libavutil/attributes.h"
+#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
 #include "libavutil/bswap.h"
 #include "libavutil/common.h"
-#include "libavutil/avstring.h"
 #include "libavutil/dict.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
 #include "avformat.h"
-#include "internal.h"
 #include "avio_internal.h"
+#include "avlanguage.h"
 #include "id3v2.h"
+#include "internal.h"
 #include "riff.h"
 #include "asf.h"
 #include "asfcrypt.h"
-#include "avlanguage.h"
 
 typedef struct {
     const AVClass *class;
@@ -75,13 +76,13 @@ typedef struct {
 
     int stream_index;
 
-    ASFStream* asf_st;                   ///< currently decoded stream
+    ASFStream *asf_st;                   ///< currently decoded stream
 
     int no_resync_search;
 } ASFContext;
 
 static const AVOption options[] = {
-    {"no_resync_search", "Don't try to resynchronize by looking for a certain optional start code", offsetof(ASFContext, no_resync_search), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
+    { "no_resync_search", "Don't try to resynchronize by looking for a certain optional start code", offsetof(ASFContext, no_resync_search), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
     { NULL },
 };
 
@@ -104,11 +105,11 @@ static const ff_asf_guid stream_bitrate_guid = { /* (http://get.to/sdp) */
     0xce, 0x75, 0xf8, 0x7b, 0x8d, 0x46, 0xd1, 0x11, 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2
 };
 
-#define PRINT_IF_GUID(g,cmp) \
-if (!ff_guidcmp(g, &cmp)) \
-    av_dlog(NULL, "(GUID: %s) ", #cmp)
+#define PRINT_IF_GUID(g, cmp) \
+    if (!ff_guidcmp(g, &cmp)) \
+        av_dlog(NULL, "(GUID: %s) ", # cmp)
 
-static void print_guid(const ff_asf_guid *g)
+static void print_guid(ff_asf_guid *g)
 {
     int i;
     PRINT_IF_GUID(g, ff_asf_header);
@@ -132,12 +133,13 @@ static void print_guid(const ff_asf_guid *g)
     else PRINT_IF_GUID(g, ff_asf_ext_stream_embed_stream_header);
     else PRINT_IF_GUID(g, ff_asf_ext_stream_audio_stream);
     else PRINT_IF_GUID(g, ff_asf_metadata_header);
+    else PRINT_IF_GUID(g, ff_asf_metadata_library_header);
     else PRINT_IF_GUID(g, ff_asf_marker_header);
     else PRINT_IF_GUID(g, stream_bitrate_guid);
     else PRINT_IF_GUID(g, ff_asf_language_guid);
     else
         av_dlog(NULL, "(GUID: unknown) ");
-    for(i=0;i<16;i++)
+    for (i = 0; i < 16; i++)
         av_dlog(NULL, " 0x%02x,", (*g)[i]);
     av_dlog(NULL, "}\n");
 }
@@ -155,13 +157,21 @@ static int asf_probe(AVProbeData *pd)
         return 0;
 }
 
-static int get_value(AVIOContext *pb, int type){
-    switch(type){
-        case 2: return avio_rl32(pb);
-        case 3: return avio_rl32(pb);
-        case 4: return avio_rl64(pb);
-        case 5: return avio_rl16(pb);
-        default:return INT_MIN;
+/* size of type 2 (BOOL) is 32bit for "Extended Content Description Object"
+ * but 16 bit for "Metadata Object" and "Metadata Library Object" */
+static int get_value(AVIOContext *pb, int type, int type2_size)
+{
+    switch (type) {
+    case 2:
+        return (type2_size == 32) ? avio_rl32(pb) : avio_rl16(pb);
+    case 3:
+        return avio_rl32(pb);
+    case 4:
+        return avio_rl64(pb);
+    case 5:
+        return avio_rl16(pb);
+    default:
+        return INT_MIN;
     }
 }
 
@@ -169,12 +179,11 @@ static int get_value(AVIOContext *pb, int type){
  * but in reality this is only loosely similar */
 static int asf_read_picture(AVFormatContext *s, int len)
 {
-    AVPacket pkt = { 0 };
+    AVPacket pkt          = { 0 };
     const CodecMime *mime = ff_id3v2_mime_tags;
-    enum  AVCodecID      id = AV_CODEC_ID_NONE;
+    enum  AVCodecID id    = AV_CODEC_ID_NONE;
     char mimetype[64];
     uint8_t  *desc = NULL;
-    ASFStream *ast = NULL;
     AVStream   *st = NULL;
     int ret, type, picsize, desc_len;
 
@@ -194,7 +203,7 @@ static int asf_read_picture(AVFormatContext *s, int len)
 
     /* picture data size */
     picsize = avio_rl32(s->pb);
-    len -= 4;
+    len    -= 4;
 
     /* picture MIME type */
     len -= avio_get_str16le(s->pb, len, mimetype, sizeof(mimetype));
@@ -228,21 +237,17 @@ static int asf_read_picture(AVFormatContext *s, int len)
     if (ret < 0)
         goto fail;
 
-    st = avformat_new_stream(s, NULL);
-    ast = av_mallocz(sizeof(*ast));
-    if (!st || !ast) {
+    st  = avformat_new_stream(s, NULL);
+    if (!st) {
         ret = AVERROR(ENOMEM);
         goto fail;
     }
-    st->priv_data = ast;
-
-    st->disposition      |= AV_DISPOSITION_ATTACHED_PIC;
-    st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
-    st->codec->codec_id   = id;
-
-    st->attached_pic      = pkt;
+    st->disposition              |= AV_DISPOSITION_ATTACHED_PIC;
+    st->codec->codec_type         = AVMEDIA_TYPE_VIDEO;
+    st->codec->codec_id           = id;
+    st->attached_pic              = pkt;
     st->attached_pic.stream_index = st->index;
-    st->attached_pic.flags |= AV_PKT_FLAG_KEY;
+    st->attached_pic.flags       |= AV_PKT_FLAG_KEY;
 
     if (*desc)
         av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL);
@@ -254,41 +259,62 @@ static int asf_read_picture(AVFormatContext *s, int len)
     return 0;
 
 fail:
-    av_freep(&ast);
     av_freep(&desc);
     av_free_packet(&pkt);
     return ret;
 }
 
-static void get_tag(AVFormatContext *s, const char *key, int type, int len)
+static void get_id3_tag(AVFormatContext *s, int len)
+{
+    ID3v2ExtraMeta *id3v2_extra_meta = NULL;
+
+    ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
+    if (id3v2_extra_meta)
+        ff_id3v2_parse_apic(s, &id3v2_extra_meta);
+    ff_id3v2_free_extra_meta(&id3v2_extra_meta);
+}
+
+static void get_tag(AVFormatContext *s, const char *key, int type, int len, int type2_size)
 {
     char *value;
     int64_t off = avio_tell(s->pb);
+#define LEN 22
 
-    if ((unsigned)len >= (UINT_MAX - 1)/2)
+    if ((unsigned)len >= (UINT_MAX - LEN) / 2)
         return;
 
-    value = av_malloc(2*len+1);
+    value = av_malloc(2 * len + LEN);
     if (!value)
         goto finish;
 
     if (type == 0) {         // UTF16-LE
-        avio_get_str16le(s->pb, len, value, 2*len + 1);
+        avio_get_str16le(s->pb, len, value, 2 * len + 1);
     } else if (type == -1) { // ASCII
         avio_read(s->pb, value, len);
         value[len]=0;
+    } else if (type == 1) {  // byte array
+        if (!strcmp(key, "WM/Picture")) { // handle cover art
+            asf_read_picture(s, len);
+        } else if (!strcmp(key, "ID3")) { // handle ID3 tag
+            get_id3_tag(s, len);
+        } else {
+            av_log(s, AV_LOG_VERBOSE, "Unsupported byte array in tag %s.\n", key);
+        }
+        goto finish;
     } else if (type > 1 && type <= 5) {  // boolean or DWORD or QWORD or WORD
-        uint64_t num = get_value(s->pb, type);
-        snprintf(value, len, "%"PRIu64, num);
-    } else if (type == 1 && !strcmp(key, "WM/Picture")) { // handle cover art
-        asf_read_picture(s, len);
+        uint64_t num = get_value(s->pb, type, type2_size);
+        snprintf(value, LEN, "%"PRIu64, num);
+    } else if (type == 6) { // (don't) handle GUID
+        av_log(s, AV_LOG_DEBUG, "Unsupported GUID value in tag %s.\n", key);
         goto finish;
     } else {
-        av_log(s, AV_LOG_DEBUG, "Unsupported value type %d in tag %s.\n", type, key);
+        av_log(s, AV_LOG_DEBUG,
+               "Unsupported value type %d in tag %s.\n", type, key);
         goto finish;
     }
     if (*value)
         av_dict_set(&s->metadata, key, value, 0);
+
 finish:
     av_freep(&value);
     avio_seek(s->pb, off + len, SEEK_SET);
@@ -300,20 +326,20 @@ static int asf_read_file_properties(AVFormatContext *s, int64_t size)
     AVIOContext *pb = s->pb;
 
     ff_get_guid(pb, &asf->hdr.guid);
-    asf->hdr.file_size          = avio_rl64(pb);
-    asf->hdr.create_time        = avio_rl64(pb);
+    asf->hdr.file_size   = avio_rl64(pb);
+    asf->hdr.create_time = avio_rl64(pb);
     avio_rl64(pb);                               /* number of packets */
-    asf->hdr.play_time          = avio_rl64(pb);
-    asf->hdr.send_time          = avio_rl64(pb);
-    asf->hdr.preroll            = avio_rl32(pb);
-    asf->hdr.ignore             = avio_rl32(pb);
-    asf->hdr.flags              = avio_rl32(pb);
-    asf->hdr.min_pktsize        = avio_rl32(pb);
-    asf->hdr.max_pktsize        = avio_rl32(pb);
-    if (asf->hdr.min_pktsize >= (1U<<29))
+    asf->hdr.play_time   = avio_rl64(pb);
+    asf->hdr.send_time   = avio_rl64(pb);
+    asf->hdr.preroll     = avio_rl32(pb);
+    asf->hdr.ignore      = avio_rl32(pb);
+    asf->hdr.flags       = avio_rl32(pb);
+    asf->hdr.min_pktsize = avio_rl32(pb);
+    asf->hdr.max_pktsize = avio_rl32(pb);
+    if (asf->hdr.min_pktsize >= (1U << 29))
         return AVERROR_INVALIDDATA;
-    asf->hdr.max_bitrate        = avio_rl32(pb);
-    s->packet_size = asf->hdr.max_pktsize;
+    asf->hdr.max_bitrate = avio_rl32(pb);
+    s->packet_size       = asf->hdr.max_pktsize;
 
     return 0;
 }
@@ -329,7 +355,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
     int type_specific_size, sizeX;
     unsigned int tag1;
     int64_t pos1, pos2, start_time;
-    int test_for_ext_stream_audio, is_dvr_ms_audio=0;
+    int test_for_ext_stream_audio, is_dvr_ms_audio = 0;
 
     if (s->nb_streams == ASF_MAX_STREAMS) {
         av_log(s, AV_LOG_ERROR, "too many streams\n");
@@ -345,16 +371,16 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
     asf_st = av_mallocz(sizeof(ASFStream));
     if (!asf_st)
         return AVERROR(ENOMEM);
-    st->priv_data = asf_st;
-    start_time = asf->hdr.preroll;
+    st->priv_data  = asf_st;
+    start_time     = asf->hdr.preroll;
 
     asf_st->stream_language_index = 128; // invalid stream index means no language info
 
-    if(!(asf->hdr.flags & 0x01)) { // if we aren't streaming...
+    if (!(asf->hdr.flags & 0x01)) { // if we aren't streaming...
         int64_t fsize = avio_size(pb);
         if (fsize <= 0 || (int64_t)asf->hdr.file_size <= 0 || FFABS(fsize - (int64_t)asf->hdr.file_size) < 10000)
             st->duration = asf->hdr.play_time /
-                (10000000 / 1000) - start_time;
+                       (10000000 / 1000) - start_time;
     }
     ff_get_guid(pb, &g);
 
@@ -364,13 +390,13 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
     } else if (!ff_guidcmp(&g, &ff_asf_video_stream)) {
         type = AVMEDIA_TYPE_VIDEO;
     } else if (!ff_guidcmp(&g, &ff_asf_jfif_media)) {
-        type = AVMEDIA_TYPE_VIDEO;
+        type                = AVMEDIA_TYPE_VIDEO;
         st->codec->codec_id = AV_CODEC_ID_MJPEG;
     } else if (!ff_guidcmp(&g, &ff_asf_command_stream)) {
         type = AVMEDIA_TYPE_DATA;
     } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_embed_stream_header)) {
         test_for_ext_stream_audio = 1;
-        type = AVMEDIA_TYPE_UNKNOWN;
+        type                      = AVMEDIA_TYPE_UNKNOWN;
     } else {
         return -1;
     }
@@ -387,8 +413,8 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
     if (test_for_ext_stream_audio) {
         ff_get_guid(pb, &g);
         if (!ff_guidcmp(&g, &ff_asf_ext_stream_audio_stream)) {
-            type = AVMEDIA_TYPE_AUDIO;
-            is_dvr_ms_audio=1;
+            type            = AVMEDIA_TYPE_AUDIO;
+            is_dvr_ms_audio = 1;
             ff_get_guid(pb, &g);
             avio_rl32(pb);
             avio_rl32(pb);
@@ -406,46 +432,46 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
         if (is_dvr_ms_audio) {
             // codec_id and codec_tag are unreliable in dvr_ms
             // files. Set them later by probing stream.
-            st->request_probe= 1;
+            st->request_probe    = 1;
             st->codec->codec_tag = 0;
         }
-        if (st->codec->codec_id == AV_CODEC_ID_AAC) {
+        if (st->codec->codec_id == AV_CODEC_ID_AAC)
             st->need_parsing = AVSTREAM_PARSE_NONE;
-        } else {
+        else
             st->need_parsing = AVSTREAM_PARSE_FULL;
-        }
         /* We have to init the frame size at some point .... */
         pos2 = avio_tell(pb);
         if (size >= (pos2 + 8 - pos1 + 24)) {
-            asf_st->ds_span = avio_r8(pb);
+            asf_st->ds_span        = avio_r8(pb);
             asf_st->ds_packet_size = avio_rl16(pb);
-            asf_st->ds_chunk_size = avio_rl16(pb);
-            avio_rl16(pb); //ds_data_size
-            avio_r8(pb);   //ds_silence_data
+            asf_st->ds_chunk_size  = avio_rl16(pb);
+            avio_rl16(pb);  // ds_data_size
+            avio_r8(pb);    // ds_silence_data
         }
         if (asf_st->ds_span > 1) {
-            if (!asf_st->ds_chunk_size
-                    || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1)
-                    || asf_st->ds_packet_size % asf_st->ds_chunk_size)
-                asf_st->ds_span = 0; // disable descrambling
+            if (!asf_st->ds_chunk_size                                ||
+                (asf_st->ds_packet_size / asf_st->ds_chunk_size <= 1) ||
+                asf_st->ds_packet_size % asf_st->ds_chunk_size)
+                asf_st->ds_span = 0;  // disable descrambling
         }
     } else if (type == AVMEDIA_TYPE_VIDEO &&
-            size - (avio_tell(pb) - pos1 + 24) >= 51) {
+               size - (avio_tell(pb) - pos1 + 24) >= 51) {
         avio_rl32(pb);
         avio_rl32(pb);
         avio_r8(pb);
         avio_rl16(pb);        /* size */
-        sizeX= avio_rl32(pb); /* size */
-        st->codec->width = avio_rl32(pb);
+        sizeX             = avio_rl32(pb); /* size */
+        st->codec->width  = avio_rl32(pb);
         st->codec->height = avio_rl32(pb);
         /* not available for asf */
         avio_rl16(pb); /* panes */
         st->codec->bits_per_coded_sample = avio_rl16(pb); /* depth */
-        tag1 = avio_rl32(pb);
+        tag1                             = avio_rl32(pb);
         avio_skip(pb, 20);
         if (sizeX > 40) {
             st->codec->extradata_size = ffio_limit(pb, sizeX - 40);
-            st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+            st->codec->extradata      = av_mallocz(st->codec->extradata_size +
+                                                   FF_INPUT_BUFFER_PADDING_SIZE);
             avio_read(pb, st->codec->extradata, st->codec->extradata_size);
         }
 
@@ -455,8 +481,8 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
         if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) {
 #if HAVE_BIGENDIAN
             int i;
-            for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++)
-                asf_st->palette[i] = av_bswap32(((uint32_t*)st->codec->extradata)[i]);
+            for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE) / 4; i++)
+                asf_st->palette[i] = av_bswap32(((uint32_t *)st->codec->extradata)[i]);
 #else
             memcpy(asf_st->palette, st->codec->extradata,
                    FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));
@@ -465,16 +491,18 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
         }
 
         st->codec->codec_tag = tag1;
-        st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1);
-        if(tag1 == MKTAG('D', 'V', 'R', ' ')){
+        st->codec->codec_id  = ff_codec_get_id(ff_codec_bmp_tags, tag1);
+        if (tag1 == MKTAG('D', 'V', 'R', ' ')) {
             st->need_parsing = AVSTREAM_PARSE_FULL;
-            // issue658 containse wrong w/h and MS even puts a fake seq header with wrong w/h in extradata while a correct one is in te stream. maximum lameness
-            st->codec->width  =
+            /* issue658 contains wrong w/h and MS even puts a fake seq header
+             * with wrong w/h in extradata while a correct one is in the stream.
+             * maximum lameness */
+            st->codec->width      =
                 st->codec->height = 0;
             av_freep(&st->codec->extradata);
-            st->codec->extradata_size=0;
+            st->codec->extradata_size = 0;
         }
-        if(st->codec->codec_id == AV_CODEC_ID_H264)
+        if (st->codec->codec_id == AV_CODEC_ID_H264)
             st->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
     }
     pos2 = avio_tell(pb);
@@ -509,25 +537,25 @@ static int asf_read_ext_stream_properties(AVFormatContext *s, int64_t size)
         asf->streams[stream_num].stream_language_index = stream_languageid_index;
 
     avio_rl64(pb); // avg frametime in 100ns units
-    stream_ct = avio_rl16(pb); //stream-name-count
-    payload_ext_ct = avio_rl16(pb); //payload-extension-system-count
+    stream_ct      = avio_rl16(pb); // stream-name-count
+    payload_ext_ct = avio_rl16(pb); // payload-extension-system-count
 
     if (stream_num < 128) {
         asf->stream_bitrates[stream_num] = leak_rate;
         asf->streams[stream_num].payload_ext_ct = 0;
     }
 
-    for (i=0; istreams[stream_num].payload)) {
             ASFPayload *p = &asf->streams[stream_num].payload[i];
@@ -551,10 +579,10 @@ static int asf_read_content_desc(AVFormatContext *s, int64_t size)
     len3 = avio_rl16(pb);
     len4 = avio_rl16(pb);
     len5 = avio_rl16(pb);
-    get_tag(s, "title"    , 0, len1);
-    get_tag(s, "author"   , 0, len2);
-    get_tag(s, "copyright", 0, len3);
-    get_tag(s, "comment"  , 0, len4);
+    get_tag(s, "title", 0, len1, 32);
+    get_tag(s, "author", 0, len2, 32);
+    get_tag(s, "copyright", 0, len3, 32);
+    get_tag(s, "comment", 0, len4, 32);
     avio_skip(pb, len5);
 
     return 0;
@@ -567,29 +595,28 @@ static int asf_read_ext_content_desc(AVFormatContext *s, int64_t size)
     int desc_count, i, ret;
 
     desc_count = avio_rl16(pb);
-    for(i=0;idar[0].num= get_value(s->pb, value_type);
-        } else if(!strcmp(name, "AspectRatioY")){
-            asf->dar[0].den= get_value(s->pb, value_type);
-        } else
-            get_tag(s, name, value_type, value_len);
+        /* My sample has that stream set to 0 maybe that mean the container.
+         * ASF stream count starts at 1. I am using 0 to the container value
+         * since it's unused. */
+        if (!strcmp(name, "AspectRatioX"))
+            asf->dar[0].num = get_value(s->pb, value_type, 32);
+        else if (!strcmp(name, "AspectRatioY"))
+            asf->dar[0].den = get_value(s->pb, value_type, 32);
+        else
+            get_tag(s, name, value_type, value_len, 32);
     }
 
     return 0;
@@ -601,13 +628,15 @@ static int asf_read_language_list(AVFormatContext *s, int64_t size)
     ASFContext *asf = s->priv_data;
     int j, ret;
     int stream_count = avio_rl16(pb);
-    for(j = 0; j < stream_count; j++) {
+    for (j = 0; j < stream_count; j++) {
         char lang[6];
         unsigned int lang_len = avio_r8(pb);
-        if ((ret = avio_get_str16le(pb, lang_len, lang, sizeof(lang))) < lang_len)
+        if ((ret = avio_get_str16le(pb, lang_len, lang,
+                                    sizeof(lang))) < lang_len)
             avio_skip(pb, lang_len - ret);
         if (j < 128)
-            av_strlcpy(asf->stream_languages[j], lang, sizeof(*asf->stream_languages));
+            av_strlcpy(asf->stream_languages[j], lang,
+                       sizeof(*asf->stream_languages));
     }
 
     return 0;
@@ -617,30 +646,35 @@ static int asf_read_metadata(AVFormatContext *s, int64_t size)
 {
     AVIOContext *pb = s->pb;
     ASFContext *asf = s->priv_data;
-    int n, stream_num, name_len, value_len, value_num;
+    int n, stream_num, name_len, value_len;
     int ret, i;
     n = avio_rl16(pb);
 
-    for(i=0;i\n",
+        av_dlog(s, "%d stream %d name_len %2d type %d len %4d <%s>\n",
                 i, stream_num, name_len, value_type, value_len, name);
-        value_num= avio_rl16(pb);//we should use get_value() here but it does not work 2 is le16 here but le32 elsewhere
-        avio_skip(pb, value_len - 2);
 
-        if(stream_num<128){
-            if     (!strcmp(name, "AspectRatioX")) asf->dar[stream_num].num= value_num;
-            else if(!strcmp(name, "AspectRatioY")) asf->dar[stream_num].den= value_num;
+        if (!strcmp(name, "AspectRatioX")){
+            int aspect_x = get_value(s->pb, value_type, 16);
+            if(stream_num < 128)
+                asf->dar[stream_num].num = aspect_x;
+        } else if(!strcmp(name, "AspectRatioY")){
+            int aspect_y = get_value(s->pb, value_type, 16);
+            if(stream_num < 128)
+                asf->dar[stream_num].den = aspect_y;
+        } else {
+            get_tag(s, name, value_type, value_len, 16);
         }
     }
 
@@ -658,11 +692,10 @@ static int asf_read_marker(AVFormatContext *s, int64_t size)
     count = avio_rl32(pb);    // markers count
     avio_rl16(pb);            // reserved 2 bytes
     name_len = avio_rl16(pb); // name length
-    for(i=0;iasfid2avid, -1, sizeof(asf->asfid2avid));
-    for(;;) {
-        uint64_t gpos= avio_tell(pb);
+    for (;;) {
+        uint64_t gpos = avio_tell(pb);
         ff_get_guid(pb, &g);
         gsize = avio_rl64(pb);
         print_guid(&g);
         if (!ff_guidcmp(&g, &ff_asf_data_header)) {
             asf->data_object_offset = avio_tell(pb);
-            // if not streaming, gsize is not unlimited (how?), and there is enough space in the file..
-            if (!(asf->hdr.flags & 0x01) && gsize >= 100) {
+            /* If not streaming, gsize is not unlimited (how?),
+             * and there is enough space in the file.. */
+            if (!(asf->hdr.flags & 0x01) && gsize >= 100)
                 asf->data_object_size = gsize - 24;
-            } else {
+            else
                 asf->data_object_size = (uint64_t)-1;
-            }
             break;
         }
         if (gsize < 24)
@@ -727,6 +762,8 @@ static int asf_read_header(AVFormatContext *s)
             asf_read_ext_content_desc(s, gsize);
         } else if (!ff_guidcmp(&g, &ff_asf_metadata_header)) {
             asf_read_metadata(s, gsize);
+        } else if (!ff_guidcmp(&g, &ff_asf_metadata_library_header)) {
+            asf_read_metadata(s, gsize);
         } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_header)) {
             asf_read_ext_stream_properties(s, gsize);
 
@@ -746,26 +783,30 @@ static int asf_read_header(AVFormatContext *s)
                 if (!ff_guidcmp(&g, &ff_asf_content_encryption)) {
                     unsigned int len;
                     AVPacket pkt;
-                    av_log(s, AV_LOG_WARNING, "DRM protected stream detected, decoding will likely fail!\n");
+                    av_log(s, AV_LOG_WARNING,
+                           "DRM protected stream detected, decoding will likely fail!\n");
                     len= avio_rl32(pb);
                     av_log(s, AV_LOG_DEBUG, "Secret data:\n");
                     av_get_packet(pb, &pkt, len); av_hex_dump_log(s, AV_LOG_DEBUG, pkt.data, pkt.size); av_free_packet(&pkt);
                     len= avio_rl32(pb);
-                    get_tag(s, "ASF_Protection_Type", -1, len);
+                    get_tag(s, "ASF_Protection_Type", -1, len, 32);
                     len= avio_rl32(pb);
-                    get_tag(s, "ASF_Key_ID", -1, len);
+                    get_tag(s, "ASF_Key_ID", -1, len, 32);
                     len= avio_rl32(pb);
-                    get_tag(s, "ASF_License_URL", -1, len);
+                    get_tag(s, "ASF_License_URL", -1, len, 32);
                 } else if (!ff_guidcmp(&g, &ff_asf_ext_content_encryption)) {
-                    av_log(s, AV_LOG_WARNING, "Ext DRM protected stream detected, decoding will likely fail!\n");
+                    av_log(s, AV_LOG_WARNING,
+                           "Ext DRM protected stream detected, decoding will likely fail!\n");
                     av_dict_set(&s->metadata, "encryption", "ASF Extended Content Encryption", 0);
                 } else if (!ff_guidcmp(&g, &ff_asf_digital_signature)) {
                     av_log(s, AV_LOG_INFO, "Digital signature detected!\n");
                 }
             }
         }
-        if(avio_tell(pb) != gpos + gsize)
-            av_log(s, AV_LOG_DEBUG, "gpos mismatch our pos=%"PRIu64", end=%"PRIu64"\n", avio_tell(pb)-gpos, gsize);
+        if (avio_tell(pb) != gpos + gsize)
+            av_log(s, AV_LOG_DEBUG,
+                   "gpos mismatch our pos=%"PRIu64", end=%"PRId64"\n",
+                   avio_tell(pb) - gpos, gsize);
         avio_seek(pb, gpos + gsize, SEEK_SET);
     }
     ff_get_guid(pb, &g);
@@ -774,21 +815,22 @@ static int asf_read_header(AVFormatContext *s)
     avio_r8(pb);
     if (url_feof(pb))
         return AVERROR_EOF;
-    asf->data_offset = avio_tell(pb);
+    asf->data_offset      = avio_tell(pb);
     asf->packet_size_left = 0;
 
-
-    for(i=0; i<128; i++){
-        int stream_num= asf->asfid2avid[i];
-        if(stream_num>=0){
+    for (i = 0; i < 128; i++) {
+        int stream_num = asf->asfid2avid[i];
+        if (stream_num >= 0) {
             AVStream *st = s->streams[stream_num];
             if (!st->codec->bit_rate)
                 st->codec->bit_rate = asf->stream_bitrates[i];
-            if (asf->dar[i].num > 0 && asf->dar[i].den > 0){
+            if (asf->dar[i].num > 0 && asf->dar[i].den > 0) {
                 av_reduce(&st->sample_aspect_ratio.num,
                           &st->sample_aspect_ratio.den,
                           asf->dar[i].num, asf->dar[i].den, INT_MAX);
-            } else if ((asf->dar[0].num > 0) && (asf->dar[0].den > 0) && (st->codec->codec_type==AVMEDIA_TYPE_VIDEO)) // Use ASF container value if the stream doesn't AR set.
+            } else if ((asf->dar[0].num > 0) && (asf->dar[0].den > 0) &&
+                       // Use ASF container value if the stream doesn't set AR.
+                       (st->codec->codec_type == AVMEDIA_TYPE_VIDEO))
                 av_reduce(&st->sample_aspect_ratio.num,
                           &st->sample_aspect_ratio.den,
                           asf->dar[0].num, asf->dar[0].den, INT_MAX);
@@ -802,7 +844,8 @@ static int asf_read_header(AVFormatContext *s)
                 const char *rfc1766 = asf->stream_languages[asf->streams[i].stream_language_index];
                 if (rfc1766 && strlen(rfc1766) > 1) {
                     const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; // ignore country code if any
-                    const char *iso6392 = av_convert_lang_to(primary_tag, AV_LANG_ISO639_2_BIBL);
+                    const char *iso6392       = av_convert_lang_to(primary_tag,
+                                                                   AV_LANG_ISO639_2_BIBL);
                     if (iso6392)
                         av_dict_set(&st->metadata, "language", iso6392, 0);
                 }
@@ -815,13 +858,23 @@ static int asf_read_header(AVFormatContext *s)
     return 0;
 }
 
-#define DO_2BITS(bits, var, defval) \
-    switch (bits & 3) \
-    { \
-    case 3: var = avio_rl32(pb); rsize += 4; break; \
-    case 2: var = avio_rl16(pb); rsize += 2; break; \
-    case 1: var = avio_r8(pb);   rsize++; break; \
-    default: var = defval; break; \
+#define DO_2BITS(bits, var, defval)             \
+    switch (bits & 3) {                         \
+    case 3:                                     \
+        var = avio_rl32(pb);                    \
+        rsize += 4;                             \
+        break;                                  \
+    case 2:                                     \
+        var = avio_rl16(pb);                    \
+        rsize += 2;                             \
+        break;                                  \
+    case 1:                                     \
+        var = avio_r8(pb);                      \
+        rsize++;                                \
+        break;                                  \
+    default:                                    \
+        var = defval;                           \
+        break;                                  \
     }
 
 /**
@@ -838,31 +891,31 @@ static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)
     int c, d, e, off;
 
     // if we do not know packet size, allow skipping up to 32 kB
-    off= 32768;
+    off = 32768;
     if (asf->no_resync_search)
         off = 3;
     else if (s->packet_size > 0)
-        off= (avio_tell(pb) - s->data_offset) % s->packet_size + 3;
-
-    c=d=e=-1;
-    while(off-- > 0){
-        c=d; d=e;
-        e= avio_r8(pb);
-        if(c == 0x82 && !d && !e)
+        off = (avio_tell(pb) - s->data_offset) % s->packet_size + 3;
+
+    c = d = e = -1;
+    while (off-- > 0) {
+        c = d;
+        d = e;
+        e = avio_r8(pb);
+        if (c == 0x82 && !d && !e)
             break;
     }
 
     if (c != 0x82) {
-        /**
-         * This code allows handling of -EAGAIN at packet boundaries (i.e.
+        /* This code allows handling of -EAGAIN at packet boundaries (i.e.
          * if the packet sync code above triggers -EAGAIN). This does not
          * imply complete -EAGAIN handling support at random positions in
-         * the stream.
-         */
+         * the stream. */
         if (pb->error == AVERROR(EAGAIN))
             return AVERROR(EAGAIN);
         if (!url_feof(pb))
-            av_log(s, AV_LOG_ERROR, "ff asf bad header %x  at:%"PRId64"\n", c, avio_tell(pb));
+            av_log(s, AV_LOG_ERROR,
+                   "ff asf bad header %x  at:%"PRId64"\n", c, avio_tell(pb));
     }
     if ((c & 0x8f) == 0x82) {
         if (d || e) {
@@ -870,11 +923,11 @@ static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)
                 av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n");
             return AVERROR_INVALIDDATA;
         }
-        c= avio_r8(pb);
-        d= avio_r8(pb);
-        rsize+=3;
-    }else if(!url_feof(pb)){
-        avio_seek(pb, -1, SEEK_CUR); //FIXME
+        c      = avio_r8(pb);
+        d      = avio_r8(pb);
+        rsize += 3;
+    } else if(!url_feof(pb)) {
+        avio_seek(pb, -1, SEEK_CUR); // FIXME
     }
 
     asf->packet_flags    = c;
@@ -884,13 +937,16 @@ static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)
     DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
     DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
 
-    //the following checks prevent overflows and infinite loops
-    if(!packet_length || packet_length >= (1U<<29)){
-        av_log(s, AV_LOG_ERROR, "invalid packet_length %d at:%"PRId64"\n", packet_length, avio_tell(pb));
+    // the following checks prevent overflows and infinite loops
+    if (!packet_length || packet_length >= (1U << 29)) {
+        av_log(s, AV_LOG_ERROR,
+               "invalid packet_length %d at:%"PRId64"\n",
+               packet_length, avio_tell(pb));
         return AVERROR_INVALIDDATA;
     }
-    if(padsize >= packet_length){
-        av_log(s, AV_LOG_ERROR, "invalid padsize %d at:%"PRId64"\n", padsize, avio_tell(pb));
+    if (padsize >= packet_length) {
+        av_log(s, AV_LOG_ERROR,
+               "invalid padsize %d at:%"PRId64"\n", padsize, avio_tell(pb));
         return AVERROR_INVALIDDATA;
     }
 
@@ -899,10 +955,11 @@ static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)
     // rsize has at least 11 bytes which have to be present
 
     if (asf->packet_flags & 0x01) {
-        asf->packet_segsizetype = avio_r8(pb); rsize++;
+        asf->packet_segsizetype = avio_r8(pb);
+        rsize++;
         asf->packet_segments = asf->packet_segsizetype & 0x3f;
     } else {
-        asf->packet_segments = 1;
+        asf->packet_segments    = 1;
         asf->packet_segsizetype = 0x80;
     }
     if (rsize > packet_length - padsize) {
@@ -916,7 +973,8 @@ static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)
     if (packet_length < asf->hdr.min_pktsize)
         padsize += asf->hdr.min_pktsize - packet_length;
     asf->packet_padsize = padsize;
-    av_dlog(s, "packet: size=%d padsize=%d  left=%d\n", s->packet_size, asf->packet_padsize, asf->packet_size_left);
+    av_dlog(s, "packet: size=%d padsize=%d  left=%d\n",
+            s->packet_size, asf->packet_padsize, asf->packet_size_left);
     return 0;
 }
 
@@ -924,18 +982,19 @@ static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)
  *
  * @return <0 if error
  */
-static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){
+static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb)
+{
     ASFContext *asf = s->priv_data;
     ASFStream *asfst;
-    int rsize = 1;
-    int num = avio_r8(pb);
+    int rsize       = 1;
+    int num         = avio_r8(pb);
     int i;
     int64_t ts0, ts1 av_unused;
 
     asf->packet_segments--;
     asf->packet_key_frame = num >> 7;
-    asf->stream_index = asf->asfid2avid[num & 0x7f];
-    asfst = &asf->streams[num & 0x7f];
+    asf->stream_index     = asf->asfid2avid[num & 0x7f];
+    asfst                 = &asf->streams[num & 0x7f];
     // sequence should be ignored!
     DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
     DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
@@ -943,7 +1002,7 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){
     av_dlog(asf, "key:%d stream:%d seq:%d offset:%d replic_size:%d\n",
             asf->packet_key_frame, asf->stream_index, asf->packet_seq,
             asf->packet_frag_offset, asf->packet_replic_size);
-    if (rsize+asf->packet_replic_size > asf->packet_size_left) {
+    if (rsize+(int64_t)asf->packet_replic_size > asf->packet_size_left) {
         av_log(s, AV_LOG_ERROR, "packet_replic_size %d is invalid\n", asf->packet_replic_size);
         return AVERROR_INVALIDDATA;
     }
@@ -951,24 +1010,25 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){
         int64_t end = avio_tell(pb) + asf->packet_replic_size;
         AVRational aspect;
         asf->packet_obj_size = avio_rl32(pb);
-        if(asf->packet_obj_size >= (1<<24) || asf->packet_obj_size <= 0){
+        if (asf->packet_obj_size >= (1 << 24) || asf->packet_obj_size <= 0) {
             av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n");
+            asf->packet_obj_size = 0;
             return AVERROR_INVALIDDATA;
         }
         asf->packet_frag_timestamp = avio_rl32(pb); // timestamp
 
-        for (i=0; ipayload_ext_ct; i++) {
+        for (i = 0; i < asfst->payload_ext_ct; i++) {
             ASFPayload *p = &asfst->payload[i];
             int size = p->size;
             int64_t payend;
-            if(size == 0xFFFF)
+            if (size == 0xFFFF)
                 size = avio_rl16(pb);
             payend = avio_tell(pb) + size;
             if (payend > end) {
                 av_log(s, AV_LOG_ERROR, "too long payload\n");
                 break;
             }
-            switch(p->type) {
+            switch (p->type) {
             case 0x50:
 //              duration = avio_rl16(pb);
                 break;
@@ -981,10 +1041,10 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){
                 break;
             case 0x2A:
                 avio_skip(pb, 8);
-                ts0= avio_rl64(pb);
-                ts1= avio_rl64(pb);
-                if(ts0!= -1) asf->packet_frag_timestamp= ts0/10000;
-                else         asf->packet_frag_timestamp= AV_NOPTS_VALUE;
+                ts0 = avio_rl64(pb);
+                ts1 = avio_rl64(pb);
+                if (ts0!= -1) asf->packet_frag_timestamp = ts0/10000;
+                else          asf->packet_frag_timestamp = AV_NOPTS_VALUE;
                 break;
             case 0x5B:
             case 0xB7:
@@ -999,16 +1059,17 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){
 
         avio_seek(pb, end, SEEK_SET);
         rsize += asf->packet_replic_size; // FIXME - check validity
-    } else if (asf->packet_replic_size==1){
+    } else if (asf->packet_replic_size == 1) {
         // multipacket - frag_offset is beginning timestamp
-        asf->packet_time_start = asf->packet_frag_offset;
-        asf->packet_frag_offset = 0;
+        asf->packet_time_start     = asf->packet_frag_offset;
+        asf->packet_frag_offset    = 0;
         asf->packet_frag_timestamp = asf->packet_timestamp;
 
         asf->packet_time_delta = avio_r8(pb);
         rsize++;
-    }else if(asf->packet_replic_size!=0){
-        av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n", asf->packet_replic_size);
+    } else if (asf->packet_replic_size != 0) {
+        av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n",
+               asf->packet_replic_size);
         return AVERROR_INVALIDDATA;
     }
     if (asf->packet_flags & 0x01) {
@@ -1016,9 +1077,10 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){
         if (rsize > asf->packet_size_left) {
             av_log(s, AV_LOG_ERROR, "packet_replic_size is invalid\n");
             return AVERROR_INVALIDDATA;
-        } else if(asf->packet_frag_size > asf->packet_size_left - rsize){
+        } else if (asf->packet_frag_size > asf->packet_size_left - rsize) {
             if (asf->packet_frag_size > asf->packet_size_left - rsize + asf->packet_padsize) {
-                av_log(s, AV_LOG_ERROR, "packet_frag_size is invalid (%d-%d)\n", asf->packet_size_left, rsize);
+                av_log(s, AV_LOG_ERROR, "packet_frag_size is invalid (%d-%d)\n",
+                       asf->packet_size_left, rsize);
                 return AVERROR_INVALIDDATA;
             } else {
                 int diff = asf->packet_frag_size - (asf->packet_size_left - rsize);
@@ -1050,7 +1112,7 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){
  */
 static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt)
 {
-    ASFContext *asf = s->priv_data;
+    ASFContext *asf   = s->priv_data;
     ASFStream *asf_st = 0;
     for (;;) {
         int ret;
@@ -1065,10 +1127,10 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
             /* fail safe */
             avio_skip(pb, ret);
 
-            asf->packet_pos= avio_tell(pb);
+            asf->packet_pos = avio_tell(pb);
             if (asf->data_object_size != (uint64_t)-1 &&
                 (asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
-                return AVERROR_EOF; /* Do not exceed the size of the data object */
+                return AVERROR_EOF;  /* Do not exceed the size of the data object */
             return 1;
         }
         if (asf->packet_time_start == 0) {
@@ -1085,12 +1147,14 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
                 avio_skip(pb, asf->packet_frag_size);
                 asf->packet_size_left -= asf->packet_frag_size;
                 if (asf->stream_index < 0)
-                    av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n", asf->packet_frag_size);
+                    av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n",
+                           asf->packet_frag_size);
                 continue;
             }
             asf->asf_st = s->streams[asf->stream_index]->priv_data;
         }
         asf_st = asf->asf_st;
+        av_assert0(asf_st);
 
         if (asf->packet_replic_size == 1) {
             // frag_offset is here used as the beginning timestamp
@@ -1116,11 +1180,12 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
         }
 
         if (asf_st->pkt.size != asf->packet_obj_size ||
-            //FIXME is this condition sufficient?
+            // FIXME is this condition sufficient?
             asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) {
             if (asf_st->pkt.data) {
-                av_log(s, AV_LOG_INFO, "freeing incomplete packet size %d, "
-                       "new %d\n", asf_st->pkt.size, asf->packet_obj_size);
+                av_log(s, AV_LOG_INFO,
+                       "freeing incomplete packet size %d, new %d\n",
+                       asf_st->pkt.size, asf->packet_obj_size);
                 asf_st->frag_offset = 0;
                 av_free_packet(&asf_st->pkt);
             }
@@ -1163,8 +1228,10 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
 
         if (asf->packet_frag_offset >= asf_st->pkt.size ||
             asf->packet_frag_size > asf_st->pkt.size - asf->packet_frag_offset) {
-            av_log(s, AV_LOG_ERROR, "packet fragment position invalid %u,%u not in %u\n",
-                   asf->packet_frag_offset, asf->packet_frag_size, asf_st->pkt.size);
+            av_log(s, AV_LOG_ERROR,
+                   "packet fragment position invalid %u,%u not in %u\n",
+                   asf->packet_frag_offset, asf->packet_frag_size,
+                   asf_st->pkt.size);
             continue;
         }
 
@@ -1192,11 +1259,12 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
         asf_st->frag_offset += ret;
         /* test if whole packet is read */
         if (asf_st->frag_offset == asf_st->pkt.size) {
-            //workaround for macroshit radio DVR-MS files
+            // workaround for macroshit radio DVR-MS files
             if (s->streams[asf->stream_index]->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO &&
                 asf_st->pkt.size > 100) {
                 int i;
-                for (i = 0; i < asf_st->pkt.size && !asf_st->pkt.data[i]; i++);
+                for (i = 0; i < asf_st->pkt.size && !asf_st->pkt.data[i]; i++)
+                    ;
                 if (i == asf_st->pkt.size) {
                     av_log(s, AV_LOG_DEBUG, "discarding ms fart\n");
                     asf_st->frag_offset = 0;
@@ -1207,23 +1275,26 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
 
             /* return packet */
             if (asf_st->ds_span > 1) {
-                if(asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span) {
-                    av_log(s, AV_LOG_ERROR, "pkt.size != ds_packet_size * "
-                           "ds_span (%d %d %d)\n", asf_st->pkt.size,
-                           asf_st->ds_packet_size, asf_st->ds_span);
+                if (asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span) {
+                    av_log(s, AV_LOG_ERROR,
+                           "pkt.size != ds_packet_size * ds_span (%d %d %d)\n",
+                           asf_st->pkt.size, asf_st->ds_packet_size,
+                           asf_st->ds_span);
                 } else {
                     /* packet descrambling */
-                    uint8_t *newdata = av_malloc(asf_st->pkt.size + FF_INPUT_BUFFER_PADDING_SIZE);
+                    uint8_t *newdata = av_malloc(asf_st->pkt.size +
+                                                 FF_INPUT_BUFFER_PADDING_SIZE);
                     if (newdata) {
                         int offset = 0;
-                        memset(newdata + asf_st->pkt.size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+                        memset(newdata + asf_st->pkt.size, 0,
+                               FF_INPUT_BUFFER_PADDING_SIZE);
                         while (offset < asf_st->pkt.size) {
                             int off = offset / asf_st->ds_chunk_size;
                             int row = off / asf_st->ds_span;
                             int col = off % asf_st->ds_span;
                             int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
                             assert(offset + asf_st->ds_chunk_size <= asf_st->pkt.size);
-                            assert(idx+1 <= asf_st->pkt.size / asf_st->ds_chunk_size);
+                            assert(idx + 1 <= asf_st->pkt.size / asf_st->ds_chunk_size);
                             memcpy(newdata + offset,
                                    asf_st->pkt.data + idx * asf_st->ds_chunk_size,
                                    asf_st->ds_chunk_size);
@@ -1257,7 +1328,8 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
         if ((ret = ff_asf_parse_packet(s, s->pb, pkt)) <= 0)
             return ret;
         if ((ret = ff_asf_get_packet(s, s->pb)) < 0)
-            assert(asf->packet_size_left < FRAME_HEADER_SIZE || asf->packet_segments < 1);
+            assert(asf->packet_size_left < FRAME_HEADER_SIZE ||
+                   asf->packet_segments < 1);
         asf->packet_time_start = 0;
     }
 }
@@ -1271,32 +1343,34 @@ static void asf_reset_header(AVFormatContext *s)
     ASFStream *asf_st;
     int i;
 
-    asf->packet_size_left = 0;
-    asf->packet_segments = 0;
-    asf->packet_flags = 0;
-    asf->packet_property = 0;
-    asf->packet_timestamp = 0;
-    asf->packet_segsizetype = 0;
-    asf->packet_segments = 0;
-    asf->packet_seq = 0;
-    asf->packet_replic_size = 0;
-    asf->packet_key_frame = 0;
-    asf->packet_padsize = 0;
-    asf->packet_frag_offset = 0;
-    asf->packet_frag_size = 0;
+    asf->packet_size_left      = 0;
+    asf->packet_segments       = 0;
+    asf->packet_flags          = 0;
+    asf->packet_property       = 0;
+    asf->packet_timestamp      = 0;
+    asf->packet_segsizetype    = 0;
+    asf->packet_segments       = 0;
+    asf->packet_seq            = 0;
+    asf->packet_replic_size    = 0;
+    asf->packet_key_frame      = 0;
+    asf->packet_padsize        = 0;
+    asf->packet_frag_offset    = 0;
+    asf->packet_frag_size      = 0;
     asf->packet_frag_timestamp = 0;
-    asf->packet_multi_size = 0;
-    asf->packet_obj_size = 0;
-    asf->packet_time_delta = 0;
-    asf->packet_time_start = 0;
-
-    for(i=0; inb_streams; i++){
-        asf_st= s->streams[i]->priv_data;
+    asf->packet_multi_size     = 0;
+    asf->packet_obj_size       = 0;
+    asf->packet_time_delta     = 0;
+    asf->packet_time_start     = 0;
+
+    for (i = 0; i < s->nb_streams; i++) {
+        asf_st = s->streams[i]->priv_data;
+        if (!asf_st)
+            continue;
         av_free_packet(&asf_st->pkt);
-        asf_st->frag_offset=0;
-        asf_st->seq=0;
+        asf_st->frag_offset = 0;
+        asf_st->seq         = 0;
     }
-    asf->asf_st= NULL;
+    asf->asf_st = NULL;
 }
 
 static int asf_read_close(AVFormatContext *s)
@@ -1306,28 +1380,30 @@ static int asf_read_close(AVFormatContext *s)
     return 0;
 }
 
-static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
+static int64_t asf_read_pts(AVFormatContext *s, int stream_index,
+                            int64_t *ppos, int64_t pos_limit)
 {
     AVPacket pkt1, *pkt = &pkt1;
     ASFStream *asf_st;
     int64_t pts;
-    int64_t pos= *ppos;
+    int64_t pos = *ppos;
     int i;
     int64_t start_pos[ASF_MAX_STREAMS];
 
-    for(i=0; inb_streams; i++){
-        start_pos[i]= pos;
-    }
+    for (i = 0; i < s->nb_streams; i++)
+        start_pos[i] = pos;
 
     if (s->packet_size > 0)
-        pos= (pos+s->packet_size-1-s->data_offset)/s->packet_size*s->packet_size+ s->data_offset;
-    *ppos= pos;
+        pos = (pos + s->packet_size - 1 - s->data_offset) /
+              s->packet_size * s->packet_size +
+              s->data_offset;
+    *ppos = pos;
     if (avio_seek(s->pb, pos, SEEK_SET) < 0)
         return AV_NOPTS_VALUE;
 
     asf_reset_header(s);
-    for(;;){
-        if (av_read_frame(s, pkt) < 0){
+    for (;;) {
+        if (av_read_frame(s, pkt) < 0) {
             av_log(s, AV_LOG_INFO, "asf_read_pts failed\n");
             return AV_NOPTS_VALUE;
         }
@@ -1335,31 +1411,33 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos,
         pts = pkt->dts;
 
         av_free_packet(pkt);
-        if(pkt->flags&AV_PKT_FLAG_KEY){
-            i= pkt->stream_index;
+        if (pkt->flags & AV_PKT_FLAG_KEY) {
+            i = pkt->stream_index;
 
-            asf_st= s->streams[i]->priv_data;
+            asf_st = s->streams[i]->priv_data;
+            av_assert0(asf_st);
 
 //            assert((asf_st->packet_pos - s->data_offset) % s->packet_size == 0);
-            pos= asf_st->packet_pos;
+            pos = asf_st->packet_pos;
 
-            av_add_index_entry(s->streams[i], pos, pts, pkt->size, pos - start_pos[i] + 1, AVINDEX_KEYFRAME);
-            start_pos[i]= asf_st->packet_pos + 1;
+            av_add_index_entry(s->streams[i], pos, pts, pkt->size,
+                               pos - start_pos[i] + 1, AVINDEX_KEYFRAME);
+            start_pos[i] = asf_st->packet_pos + 1;
 
-            if(pkt->stream_index == stream_index)
-               break;
+            if (pkt->stream_index == stream_index)
+                break;
         }
     }
 
-    *ppos= pos;
+    *ppos = pos;
     return pts;
 }
 
 static void asf_build_simple_index(AVFormatContext *s, int stream_index)
 {
     ff_asf_guid g;
-    ASFContext *asf = s->priv_data;
-    int64_t current_pos= avio_tell(s->pb);
+    ASFContext *asf     = s->priv_data;
+    int64_t current_pos = avio_tell(s->pb);
 
     if(avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET) < 0) {
         asf->index_read= -1;
@@ -1369,58 +1447,62 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
     ff_get_guid(s->pb, &g);
 
     /* the data object can be followed by other top-level objects,
-       skip them until the simple index object is reached */
+     * skip them until the simple index object is reached */
     while (ff_guidcmp(&g, &ff_asf_simple_index_header)) {
-        int64_t gsize= avio_rl64(s->pb);
+        int64_t gsize = avio_rl64(s->pb);
         if (gsize < 24 || url_feof(s->pb)) {
             avio_seek(s->pb, current_pos, SEEK_SET);
             asf->index_read= -1;
             return;
         }
-        avio_skip(s->pb, gsize-24);
+        avio_skip(s->pb, gsize - 24);
         ff_get_guid(s->pb, &g);
     }
 
     {
-        int64_t itime, last_pos=-1;
+        int64_t itime, last_pos = -1;
         int pct, ict;
         int i;
-        int64_t av_unused gsize= avio_rl64(s->pb);
+        int64_t av_unused gsize = avio_rl64(s->pb);
         ff_get_guid(s->pb, &g);
-        itime=avio_rl64(s->pb);
-        pct=avio_rl32(s->pb);
-        ict=avio_rl32(s->pb);
-        av_log(s, AV_LOG_DEBUG, "itime:0x%"PRIx64", pct:%d, ict:%d\n",itime,pct,ict);
-
-        for (i=0;ipb);
-            int pktct =avio_rl16(s->pb);
-            int64_t pos      = s->data_offset + s->packet_size*(int64_t)pktnum;
-            int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
-
-            if(pos != last_pos){
-            av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d  pts: %"PRId64"\n", pktnum, pktct, index_pts);
-            av_add_index_entry(s->streams[stream_index], pos, index_pts, s->packet_size, 0, AVINDEX_KEYFRAME);
-            last_pos=pos;
+        itime = avio_rl64(s->pb);
+        pct   = avio_rl32(s->pb);
+        ict   = avio_rl32(s->pb);
+        av_log(s, AV_LOG_DEBUG,
+               "itime:0x%"PRIx64", pct:%d, ict:%d\n", itime, pct, ict);
+
+        for (i = 0; i < ict; i++) {
+            int pktnum        = avio_rl32(s->pb);
+            int pktct         = avio_rl16(s->pb);
+            int64_t pos       = s->data_offset + s->packet_size * (int64_t)pktnum;
+            int64_t index_pts = FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
+
+            if (pos != last_pos) {
+                av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d  pts: %"PRId64"\n",
+                       pktnum, pktct, index_pts);
+                av_add_index_entry(s->streams[stream_index], pos, index_pts,
+                                   s->packet_size, 0, AVINDEX_KEYFRAME);
+                last_pos = pos;
             }
         }
-        asf->index_read= ict > 1;
+        asf->index_read = ict > 1;
     }
     avio_seek(s->pb, current_pos, SEEK_SET);
 }
 
-static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
+static int asf_read_seek(AVFormatContext *s, int stream_index,
+                         int64_t pts, int flags)
 {
     ASFContext *asf = s->priv_data;
-    AVStream *st = s->streams[stream_index];
+    AVStream *st    = s->streams[stream_index];
 
     if (s->packet_size <= 0)
         return -1;
 
     /* Try using the protocol's read_seek if available */
-    if(s->pb) {
+    if (s->pb) {
         int ret = avio_seek_time(s->pb, stream_index, pts, flags);
-        if(ret >= 0)
+        if (ret >= 0)
             asf_reset_header(s);
         if (ret != AVERROR(ENOSYS))
             return ret;
@@ -1429,9 +1511,9 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int
     if (!asf->index_read)
         asf_build_simple_index(s, stream_index);
 
-    if((asf->index_read > 0 && st->index_entries)){
-        int index= av_index_search_timestamp(st, pts, flags);
-        if(index >= 0) {
+    if ((asf->index_read > 0 && st->index_entries)) {
+        int index = av_index_search_timestamp(st, pts, flags);
+        if (index >= 0) {
             /* find the position */
             uint64_t pos = st->index_entries[index].pos;
 
diff --git a/mythtv/external/FFmpeg/libavformat/asfenc.c b/mythtv/external/FFmpeg/libavformat/asfenc.c
index 82681d24f14..f3aec9c845a 100644
--- a/mythtv/external/FFmpeg/libavformat/asfenc.c
+++ b/mythtv/external/FFmpeg/libavformat/asfenc.c
@@ -18,12 +18,13 @@
  * 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/dict.h"
 #include "avformat.h"
+#include "avio_internal.h"
 #include "internal.h"
 #include "riff.h"
 #include "asf.h"
-#include "avio_internal.h"
-#include "libavutil/dict.h"
 
 #undef NDEBUG
 #include 
@@ -33,10 +34,9 @@
 #define ASF_INDEX_BLOCK         (1<<9)
 
 #define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE 0x2
-#define ASF_PACKET_ERROR_CORRECTION_FLAGS (\
-                ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT | \
-                ASF_PACKET_ERROR_CORRECTION_DATA_SIZE\
-                )
+#define ASF_PACKET_ERROR_CORRECTION_FLAGS          \
+    (ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT |    \
+     ASF_PACKET_ERROR_CORRECTION_DATA_SIZE)
 
 #if (ASF_PACKET_ERROR_CORRECTION_FLAGS != 0)
 #   define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 1
@@ -44,12 +44,11 @@
 #   define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 0
 #endif
 
-#define ASF_PPI_PROPERTY_FLAGS (\
-                ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE | \
-                ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD | \
-                ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE | \
-                ASF_PL_FLAG_STREAM_NUMBER_LENGTH_FIELD_IS_BYTE \
-                )
+#define ASF_PPI_PROPERTY_FLAGS                                       \
+    (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE           |    \
+     ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD |    \
+     ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE       |    \
+     ASF_PL_FLAG_STREAM_NUMBER_LENGTH_FIELD_IS_BYTE)
 
 #define ASF_PPI_LENGTH_TYPE_FLAGS 0
 
@@ -68,7 +67,6 @@
 #   define ASF_PPI_SEQUENCE_FIELD_SIZE 0
 #endif
 
-
 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
 #   define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 1
 #endif
@@ -144,51 +142,45 @@
 #   define ASF_PAYLOAD_LENGTH_FIELD_SIZE 0
 #endif
 
-#define PACKET_HEADER_MIN_SIZE (\
-                ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE + \
-                ASF_PACKET_ERROR_CORRECTION_DATA_SIZE + \
-                1 + /*Length Type Flags*/ \
-                1 + /*Property Flags*/ \
-                ASF_PPI_PACKET_LENGTH_FIELD_SIZE + \
-                ASF_PPI_SEQUENCE_FIELD_SIZE + \
-                ASF_PPI_PADDING_LENGTH_FIELD_SIZE + \
-                4 + /*Send Time Field*/ \
-                2   /*Duration Field*/ \
-                )
-
+#define PACKET_HEADER_MIN_SIZE \
+    (ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE +       \
+     ASF_PACKET_ERROR_CORRECTION_DATA_SIZE +              \
+     1 +        /* Length Type Flags */                   \
+     1 +        /* Property Flags */                      \
+     ASF_PPI_PACKET_LENGTH_FIELD_SIZE +                   \
+     ASF_PPI_SEQUENCE_FIELD_SIZE +                        \
+     ASF_PPI_PADDING_LENGTH_FIELD_SIZE +                  \
+     4 +        /* Send Time Field */                     \
+     2)         /* Duration Field */
 
 // Replicated Data shall be at least 8 bytes long.
 #define ASF_PAYLOAD_REPLICATED_DATA_LENGTH 0x08
 
-#define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD (\
-                1 + /*Stream Number*/ \
-                ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
-                ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
-                ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
-                ASF_PAYLOAD_REPLICATED_DATA_LENGTH \
-                )
-
-#define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS (\
-                1 + /*Stream Number*/ \
-                ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
-                ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
-                ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
-                ASF_PAYLOAD_REPLICATED_DATA_LENGTH + \
-                ASF_PAYLOAD_LENGTH_FIELD_SIZE \
-                )
-
-#define SINGLE_PAYLOAD_DATA_LENGTH (\
-                PACKET_SIZE - \
-                PACKET_HEADER_MIN_SIZE - \
-                PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD \
-                )
-
-#define MULTI_PAYLOAD_CONSTANT (\
-                PACKET_SIZE - \
-                PACKET_HEADER_MIN_SIZE - \
-                1 - /*Payload Flags*/ \
-                2*PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS \
-                )
+#define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD                \
+    (1 +     /* Stream Number */                          \
+     ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE +         \
+     ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE +    \
+     ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE +      \
+     ASF_PAYLOAD_REPLICATED_DATA_LENGTH)
+
+#define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS             \
+    (1 +        /* Stream Number */                       \
+     ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE +         \
+     ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE +    \
+     ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE +      \
+     ASF_PAYLOAD_REPLICATED_DATA_LENGTH +                 \
+     ASF_PAYLOAD_LENGTH_FIELD_SIZE)
+
+#define SINGLE_PAYLOAD_DATA_LENGTH                        \
+    (PACKET_SIZE -                                        \
+     PACKET_HEADER_MIN_SIZE -                             \
+     PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD)
+
+#define MULTI_PAYLOAD_CONSTANT                            \
+    (PACKET_SIZE -                                        \
+     PACKET_HEADER_MIN_SIZE -                             \
+     1 -         /* Payload Flags */                      \
+     2 * PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS)
 
 typedef struct {
     uint32_t seqno;
@@ -208,7 +200,7 @@ typedef struct {
     /* only for reading */
     uint64_t data_offset;                ///< beginning of the first data packet
 
-    ASFIndex* index_ptr;
+    ASFIndex *index_ptr;
     uint32_t nb_index_memory_alloc;
     uint16_t maximum_packet;
     uint32_t next_packet_number;
@@ -218,10 +210,10 @@ typedef struct {
 } ASFContext;
 
 static const AVCodecTag codec_asf_bmp_tags[] = {
-    { AV_CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
-    { AV_CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
+    { AV_CODEC_ID_MPEG4,     MKTAG('M', '4', 'S', '2') },
+    { AV_CODEC_ID_MPEG4,     MKTAG('M', 'P', '4', 'S') },
     { AV_CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
-    { AV_CODEC_ID_NONE, 0 },
+    { AV_CODEC_ID_NONE,      0 },
 };
 
 #define PREROLL_TIME 3100
@@ -269,7 +261,8 @@ static void end_header(AVIOContext *pb, int64_t pos)
 }
 
 /* write an asf chunk (only used in streaming case) */
-static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
+static void put_chunk(AVFormatContext *s, int type,
+                      int payload_length, int flags)
 {
     ASFContext *asf = s->priv_data;
     AVIOContext *pb = s->pb;
@@ -277,10 +270,10 @@ static void put_chunk(AVFormatContext *s, int type, int payload_length, int flag
 
     length = payload_length + 8;
     avio_wl16(pb, type);
-    avio_wl16(pb, length);    //size
-    avio_wl32(pb, asf->seqno);//sequence number
-    avio_wl16(pb, flags); /* unknown bytes */
-    avio_wl16(pb, length);    //size_confirm
+    avio_wl16(pb, length);      // size
+    avio_wl32(pb, asf->seqno);  // sequence number
+    avio_wl16(pb, flags);       // unknown bytes
+    avio_wl16(pb, length);      // size_confirm
     asf->seqno++;
 }
 
@@ -289,13 +282,14 @@ static int64_t unix_to_file_time(int ti)
 {
     int64_t t;
 
-    t = ti * INT64_C(10000000);
+    t  = ti * INT64_C(10000000);
     t += INT64_C(116444736000000000);
     return t;
 }
 
 /* write the header (used two times if non streamed) */
-static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
+static int asf_write_header1(AVFormatContext *s, int64_t file_size,
+                             int64_t data_chunk_size)
 {
     ASFContext *asf = s->priv_data;
     AVIOContext *pb = s->pb;
@@ -310,18 +304,18 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
 
     ff_metadata_conv(&s->metadata, ff_asf_metadata_conv, NULL);
 
-    tags[0] = av_dict_get(s->metadata, "title"    , NULL, 0);
-    tags[1] = av_dict_get(s->metadata, "author"   , NULL, 0);
+    tags[0] = av_dict_get(s->metadata, "title", NULL, 0);
+    tags[1] = av_dict_get(s->metadata, "author", NULL, 0);
     tags[2] = av_dict_get(s->metadata, "copyright", NULL, 0);
-    tags[3] = av_dict_get(s->metadata, "comment"  , NULL, 0);
-    tags[4] = av_dict_get(s->metadata, "rating"   , NULL, 0);
+    tags[3] = av_dict_get(s->metadata, "comment", NULL, 0);
+    tags[4] = av_dict_get(s->metadata, "rating", NULL, 0);
 
-    duration = asf->duration + PREROLL_TIME * 10000;
-    has_title = tags[0] || tags[1] || tags[2] || tags[3] || tags[4];
+    duration       = asf->duration + PREROLL_TIME * 10000;
+    has_title      = tags[0] || tags[1] || tags[2] || tags[3] || tags[4];
     metadata_count = av_dict_count(s->metadata);
 
     bit_rate = 0;
-    for(n=0;nnb_streams;n++) {
+    for (n = 0; n < s->nb_streams; n++) {
         enc = s->streams[n]->codec;
 
         avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */
@@ -341,7 +335,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
 
     /* file header */
     header_offset = avio_tell(pb);
-    hpos = put_header(pb, &ff_asf_file_header);
+    hpos          = put_header(pb, &ff_asf_file_header);
     ff_put_guid(pb, &ff_asf_my_guid);
     avio_wl64(pb, file_size);
     file_time = 0;
@@ -350,7 +344,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
     avio_wl64(pb, duration); /* end time stamp (in 100ns units) */
     avio_wl64(pb, asf->duration); /* duration (in 100ns units) */
     avio_wl64(pb, PREROLL_TIME); /* start time stamp */
-    avio_wl32(pb, (asf->is_streamed || !pb->seekable ) ? 3 : 2); /* ??? */
+    avio_wl32(pb, (asf->is_streamed || !pb->seekable) ? 3 : 2);  /* ??? */
     avio_wl32(pb, s->packet_size); /* packet size */
     avio_wl32(pb, s->packet_size); /* packet size */
     avio_wl32(pb, bit_rate); /* Nominal data rate in bps */
@@ -396,26 +390,25 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
     }
 
     /* stream headers */
-    for(n=0;nnb_streams;n++) {
+    for (n = 0; n < s->nb_streams; n++) {
         int64_t es_pos;
         //        ASFStream *stream = &asf->streams[n];
 
-        enc = s->streams[n]->codec;
+        enc                 = s->streams[n]->codec;
         asf->streams[n].num = n + 1;
         asf->streams[n].seq = 1;
 
-
-        switch(enc->codec_type) {
+        switch (enc->codec_type) {
         case AVMEDIA_TYPE_AUDIO:
             wav_extra_size = 0;
-            extra_size = 18 + wav_extra_size;
-            extra_size2 = 8;
+            extra_size     = 18 + wav_extra_size;
+            extra_size2    = 8;
             break;
         default:
         case AVMEDIA_TYPE_VIDEO:
             wav_extra_size = enc->extradata_size;
-            extra_size = 0x33 + wav_extra_size;
-            extra_size2 = 0;
+            extra_size     = 0x33 + wav_extra_size;
+            extra_size2    = 0;
             break;
         }
 
@@ -448,10 +441,10 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
             }
             /* ERROR Correction */
             avio_w8(pb, 0x01);
-            if(enc->codec_id == AV_CODEC_ID_ADPCM_G726 || !enc->block_align){
+            if (enc->codec_id == AV_CODEC_ID_ADPCM_G726 || !enc->block_align) {
                 avio_wl16(pb, 0x0190);
                 avio_wl16(pb, 0x0190);
-            }else{
+            } else {
                 avio_wl16(pb, enc->block_align);
                 avio_wl16(pb, enc->block_align);
             }
@@ -474,7 +467,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
     hpos = put_header(pb, &ff_asf_codec_comment_header);
     ff_put_guid(pb, &ff_asf_codec_comment1_header);
     avio_wl32(pb, s->nb_streams);
-    for(n=0;nnb_streams;n++) {
+    for (n = 0; n < s->nb_streams; n++) {
         AVCodec *p;
         const char *desc;
         int len;
@@ -482,21 +475,21 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
         AVIOContext *dyn_buf;
 
         enc = s->streams[n]->codec;
-        p = avcodec_find_encoder(enc->codec_id);
+        p   = avcodec_find_encoder(enc->codec_id);
 
-        if(enc->codec_type == AVMEDIA_TYPE_AUDIO)
+        if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
             avio_wl16(pb, 2);
-        else if(enc->codec_type == AVMEDIA_TYPE_VIDEO)
+        else if (enc->codec_type == AVMEDIA_TYPE_VIDEO)
             avio_wl16(pb, 1);
         else
             avio_wl16(pb, -1);
 
-        if(enc->codec_id == AV_CODEC_ID_WMAV2)
+        if (enc->codec_id == AV_CODEC_ID_WMAV2)
             desc = "Windows Media Audio V8";
         else
             desc = p ? p->name : enc->codec_name;
 
-        if ( avio_open_dyn_buf(&dyn_buf) < 0)
+        if (avio_open_dyn_buf(&dyn_buf) < 0)
             return AVERROR(ENOMEM);
 
         avio_put_str16le(dyn_buf, desc);
@@ -508,7 +501,6 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
 
         avio_wl16(pb, 0); /* no parameters */
 
-
         /* id */
         if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
             avio_wl16(pb, 2);
@@ -517,14 +509,14 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
             avio_wl16(pb, 4);
             avio_wl32(pb, enc->codec_tag);
         }
-        if(!enc->codec_tag)
+        if (!enc->codec_tag)
             return -1;
     }
     end_header(pb, hpos);
 
     /* patch the header size fields */
 
-    cur_pos = avio_tell(pb);
+    cur_pos     = avio_tell(pb);
     header_size = cur_pos - header_offset;
     if (asf->is_streamed) {
         header_size += 8 + 30 + 50;
@@ -559,9 +551,9 @@ static int asf_write_header(AVFormatContext *s)
     s->packet_size  = PACKET_SIZE;
     asf->nb_packets = 0;
 
-    asf->index_ptr = av_malloc( sizeof(ASFIndex) * ASF_INDEX_BLOCK );
+    asf->index_ptr             = av_malloc(sizeof(ASFIndex) * ASF_INDEX_BLOCK);
     asf->nb_index_memory_alloc = ASF_INDEX_BLOCK;
-    asf->maximum_packet = 0;
+    asf->maximum_packet        = 0;
 
     /* the data-chunk-size has to be 50, which is data_size - asf->data_offset
      *  at the moment this function is done. It is needed to use asf as
@@ -573,11 +565,11 @@ static int asf_write_header(AVFormatContext *s)
 
     avio_flush(s->pb);
 
-    asf->packet_nb_payloads = 0;
+    asf->packet_nb_payloads     = 0;
     asf->packet_timestamp_start = -1;
-    asf->packet_timestamp_end = -1;
+    asf->packet_timestamp_end   = -1;
     ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
-                  NULL, NULL, NULL, NULL);
+                      NULL, NULL, NULL, NULL);
 
     if (s->avoid_negative_ts < 0)
         s->avoid_negative_ts = 1;
@@ -594,30 +586,25 @@ static int asf_write_stream_header(AVFormatContext *s)
     return asf_write_header(s);
 }
 
-static int put_payload_parsing_info(
-                                AVFormatContext *s,
-                                unsigned int    sendtime,
-                                unsigned int    duration,
-                                int             nb_payloads,
-                                int             padsize
-            )
+static int put_payload_parsing_info(AVFormatContext *s,
+                                    unsigned sendtime, unsigned duration,
+                                    int nb_payloads, int padsize)
 {
     ASFContext *asf = s->priv_data;
     AVIOContext *pb = s->pb;
     int ppi_size, i;
-    int64_t start= avio_tell(pb);
+    int64_t start = avio_tell(pb);
 
     int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS;
 
     padsize -= PACKET_HEADER_MIN_SIZE;
-    if(asf->multi_payloads_present)
+    if (asf->multi_payloads_present)
         padsize--;
-    assert(padsize>=0);
+    assert(padsize >= 0);
 
     avio_w8(pb, ASF_PACKET_ERROR_CORRECTION_FLAGS);
-    for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++){
+    for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++)
         avio_w8(pb, 0x0);
-    }
 
     if (asf->multi_payloads_present)
         iLengthTypeFlags |= ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT;
@@ -654,17 +641,14 @@ static void flush_packet(AVFormatContext *s)
 
     assert(asf->packet_timestamp_end >= asf->packet_timestamp_start);
 
-    if (asf->is_streamed) {
+    if (asf->is_streamed)
         put_chunk(s, 0x4424, s->packet_size, 0);
-    }
 
-    packet_hdr_size = put_payload_parsing_info(
-                            s,
-                            asf->packet_timestamp_start,
-                            asf->packet_timestamp_end - asf->packet_timestamp_start,
-                            asf->packet_nb_payloads,
-                            asf->packet_size_left
-                        );
+    packet_hdr_size = put_payload_parsing_info(s,
+                                               asf->packet_timestamp_start,
+                                               asf->packet_timestamp_end - asf->packet_timestamp_start,
+                                               asf->packet_nb_payloads,
+                                               asf->packet_size_left);
 
     packet_filled_size = PACKET_SIZE - asf->packet_size_left;
     assert(packet_hdr_size <= asf->packet_size_left);
@@ -674,22 +658,16 @@ static void flush_packet(AVFormatContext *s)
 
     avio_flush(s->pb);
     asf->nb_packets++;
-    asf->packet_nb_payloads = 0;
+    asf->packet_nb_payloads     = 0;
     asf->packet_timestamp_start = -1;
-    asf->packet_timestamp_end = -1;
+    asf->packet_timestamp_end   = -1;
     ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
-                  NULL, NULL, NULL, NULL);
+                      NULL, NULL, NULL, NULL);
 }
 
-static void put_payload_header(
-                                AVFormatContext *s,
-                                ASFStream       *stream,
-                                int64_t         presentation_time,
-                                int             m_obj_size,
-                                int             m_obj_offset,
-                                int             payload_len,
-                                int             flags
-            )
+static void put_payload_header(AVFormatContext *s, ASFStream *stream,
+                               int64_t presentation_time, int m_obj_size,
+                               int m_obj_offset, int payload_len, int flags)
 {
     ASFContext *asf = s->priv_data;
     AVIOContext *pb = &asf->pb;
@@ -700,8 +678,8 @@ static void put_payload_header(
         val |= ASF_PL_FLAG_KEY_FRAME;
     avio_w8(pb, val);
 
-    avio_w8(pb, stream->seq);  //Media object number
-    avio_wl32(pb, m_obj_offset); //Offset Into Media Object
+    avio_w8(pb, stream->seq);     // Media object number
+    avio_wl32(pb, m_obj_offset);  // Offset Into Media Object
 
     // Replicated Data shall be at least 8 bytes long.
     // The first 4 bytes of data shall contain the
@@ -710,23 +688,17 @@ static void put_payload_header(
     // Presentation Time for the media object that the payload belongs to.
     avio_w8(pb, ASF_PAYLOAD_REPLICATED_DATA_LENGTH);
 
-    avio_wl32(pb, m_obj_size);       //Replicated Data - Media Object Size
-    avio_wl32(pb, (uint32_t) presentation_time);//Replicated Data - Presentation Time
+    avio_wl32(pb, m_obj_size);        // Replicated Data - Media Object Size
+    avio_wl32(pb, (uint32_t) presentation_time); // Replicated Data - Presentation Time
 
-    if (asf->multi_payloads_present){
-        avio_wl16(pb, payload_len);   //payload length
+    if (asf->multi_payloads_present) {
+        avio_wl16(pb, payload_len);   // payload length
     }
 }
 
-static void put_frame(
-                    AVFormatContext *s,
-                    ASFStream       *stream,
-                    AVStream        *avst,
-                    int64_t         timestamp,
-                    const uint8_t   *buf,
-                    int             m_obj_size,
-                    int             flags
-                )
+static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst,
+                      int64_t timestamp, const uint8_t *buf,
+                      int m_obj_size, int flags)
 {
     ASFContext *asf = s->priv_data;
     int m_obj_offset, payload_len, frag_len1;
@@ -738,19 +710,20 @@ static void put_frame(
             asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);
 
             asf->packet_size_left = PACKET_SIZE;
-            if (asf->multi_payloads_present){
+            if (asf->multi_payloads_present) {
                 frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;
-            }
-            else {
+            } else {
                 frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;
             }
             asf->packet_timestamp_start = timestamp;
-        }
-        else {
+        } else {
             // multi payloads
-            frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS - PACKET_HEADER_MIN_SIZE - 1;
+            frag_len1 = asf->packet_size_left -
+                        PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS -
+                        PACKET_HEADER_MIN_SIZE - 1;
 
-            if(frag_len1 < payload_len && avst->codec->codec_type == AVMEDIA_TYPE_AUDIO){
+            if (frag_len1 < payload_len &&
+                avst->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
                 flush_packet(s);
                 continue;
             }
@@ -759,9 +732,10 @@ static void put_frame(
             if (payload_len > frag_len1)
                 payload_len = frag_len1;
             else if (payload_len == (frag_len1 - 1))
-                payload_len = frag_len1 - 2;  //additional byte need to put padding length
+                payload_len = frag_len1 - 2;  // additional byte need to put padding length
 
-            put_payload_header(s, stream, timestamp+PREROLL_TIME, m_obj_size, m_obj_offset, payload_len, flags);
+            put_payload_header(s, stream, timestamp + PREROLL_TIME,
+                               m_obj_size, m_obj_offset, payload_len, flags);
             avio_write(&asf->pb, buf, payload_len);
 
             if (asf->multi_payloads_present)
@@ -775,7 +749,7 @@ static void put_frame(
             payload_len = 0;
         }
         m_obj_offset += payload_len;
-        buf += payload_len;
+        buf          += payload_len;
 
         if (!asf->multi_payloads_present)
             flush_packet(s);
@@ -821,21 +795,22 @@ static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
     uint32_t packet_number;
     int64_t pts;
     int start_sec;
-    int flags= pkt->flags;
+    int flags = pkt->flags;
 
-    codec = s->streams[pkt->stream_index]->codec;
+    codec  = s->streams[pkt->stream_index]->codec;
     stream = &asf->streams[pkt->stream_index];
 
-    if(codec->codec_type == AVMEDIA_TYPE_AUDIO)
+    if (codec->codec_type == AVMEDIA_TYPE_AUDIO)
         flags &= ~AV_PKT_FLAG_KEY;
 
     pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts;
     assert(pts != AV_NOPTS_VALUE);
     pts *= 10000;
-    asf->duration= FFMAX(asf->duration, pts + pkt->duration * 10000);
+    asf->duration = FFMAX(asf->duration, pts + pkt->duration * 10000);
 
     packet_number = asf->nb_packets;
-    put_frame(s, stream, s->streams[pkt->stream_index], pkt->dts, pkt->data, pkt->size, flags);
+    put_frame(s, stream, s->streams[pkt->stream_index],
+              pkt->dts, pkt->data, pkt->size, flags);
 
     start_sec = (int)((PREROLL_TIME * 10000 + pts + ASF_INDEXED_INTERVAL - 1)
               / ASF_INDEXED_INTERVAL);
@@ -850,19 +825,19 @@ static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
     return 0;
 }
 
-//
-static int asf_write_index(AVFormatContext *s, ASFIndex *index, uint16_t max, uint32_t count)
+static int asf_write_index(AVFormatContext *s, ASFIndex *index,
+                           uint16_t max, uint32_t count)
 {
     AVIOContext *pb = s->pb;
     int i;
 
     ff_put_guid(pb, &ff_asf_simple_index_header);
-    avio_wl64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2)*count);
+    avio_wl64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2) * count);
     ff_put_guid(pb, &ff_asf_my_guid);
     avio_wl64(pb, ASF_INDEXED_INTERVAL);
     avio_wl32(pb, max);
     avio_wl32(pb, count);
-    for(i=0; ipriv_data;
-    int64_t file_size,data_size;
+    int64_t file_size, data_size;
 
     /* flush the current packet */
     if (asf->pb.buf_ptr > asf->pb.buffer)
@@ -913,11 +888,11 @@ AVOutputFormat ff_asf_muxer = {
     .write_packet   = asf_write_packet,
     .write_trailer  = asf_write_trailer,
     .flags          = AVFMT_GLOBALHEADER,
-    .codec_tag      = (const AVCodecTag* const []){
+    .codec_tag      = (const AVCodecTag * const []) {
         codec_asf_bmp_tags, ff_codec_bmp_tags, ff_codec_wav_tags, 0
     },
 };
-#endif
+#endif /* CONFIG_ASF_MUXER */
 
 #if CONFIG_ASF_STREAM_MUXER
 AVOutputFormat ff_asf_stream_muxer = {
@@ -932,8 +907,8 @@ AVOutputFormat ff_asf_stream_muxer = {
     .write_packet   = asf_write_packet,
     .write_trailer  = asf_write_trailer,
     .flags          = AVFMT_GLOBALHEADER,
-    .codec_tag      = (const AVCodecTag* const []){
+    .codec_tag      = (const AVCodecTag * const []) {
         codec_asf_bmp_tags, ff_codec_bmp_tags, ff_codec_wav_tags, 0
     },
 };
-#endif //CONFIG_ASF_STREAM_MUXER
+#endif /* CONFIG_ASF_STREAM_MUXER */
diff --git a/mythtv/external/FFmpeg/libavformat/au.c b/mythtv/external/FFmpeg/libavformat/au.c
index 2e54a185fff..db2ab275587 100644
--- a/mythtv/external/FFmpeg/libavformat/au.c
+++ b/mythtv/external/FFmpeg/libavformat/au.c
@@ -37,25 +37,23 @@
 /* the specification requires an annotation field of at least eight bytes */
 #define AU_HEADER_SIZE (24+8)
 
-/* The libavcodec codecs we support, and the IDs they have in the file */
 static const AVCodecTag codec_au_tags[] = {
-    { AV_CODEC_ID_PCM_MULAW, 1 },
-    { AV_CODEC_ID_PCM_S8, 2 },
-    { AV_CODEC_ID_PCM_S16BE, 3 },
-    { AV_CODEC_ID_PCM_S24BE, 4 },
-    { AV_CODEC_ID_PCM_S32BE, 5 },
-    { AV_CODEC_ID_PCM_F32BE, 6 },
-    { AV_CODEC_ID_PCM_F64BE, 7 },
-    { AV_CODEC_ID_ADPCM_G722, 24 },
-    { AV_CODEC_ID_PCM_ALAW, 27 },
-    { AV_CODEC_ID_NONE, 0 },
+    { AV_CODEC_ID_PCM_MULAW,  1 },
+    { AV_CODEC_ID_PCM_S8,     2 },
+    { AV_CODEC_ID_PCM_S16BE,  3 },
+    { AV_CODEC_ID_PCM_S24BE,  4 },
+    { AV_CODEC_ID_PCM_S32BE,  5 },
+    { AV_CODEC_ID_PCM_F32BE,  6 },
+    { AV_CODEC_ID_PCM_F64BE,  7 },
+    { AV_CODEC_ID_ADPCM_G722,24 },
+    { AV_CODEC_ID_PCM_ALAW,  27 },
+    { AV_CODEC_ID_NONE,       0 },
 };
 
 #if CONFIG_AU_DEMUXER
 
 static int au_probe(AVProbeData *p)
 {
-    /* check file header */
     if (p->buf[0] == '.' && p->buf[1] == 's' &&
         p->buf[2] == 'n' && p->buf[3] == 'd')
         return AVPROBE_SCORE_MAX;
@@ -63,17 +61,18 @@ static int au_probe(AVProbeData *p)
         return 0;
 }
 
-/* au input */
+#define BLOCK_SIZE 1024
+
 static int au_read_header(AVFormatContext *s)
 {
-    int size, bps, data_size = 0;
+    int size, data_size = 0;
     unsigned int tag;
     AVIOContext *pb = s->pb;
     unsigned int id, channels, rate;
+    int bps;
     enum AVCodecID codec;
     AVStream *st;
 
-    /* check ".snd" header */
     tag = avio_rl32(pb);
     if (tag != MKTAG('.', 's', 'n', 'd'))
         return AVERROR_INVALIDDATA;
@@ -85,82 +84,96 @@ static int au_read_header(AVFormatContext *s)
         return AVERROR_INVALIDDATA;
     }
 
-    id = avio_rb32(pb);
-    rate = avio_rb32(pb);
+    id       = avio_rb32(pb);
+    rate     = avio_rb32(pb);
     channels = avio_rb32(pb);
 
+    if (size > 24) {
+        /* skip unused data */
+        avio_skip(pb, size - 24);
+    }
+
     codec = ff_codec_get_id(codec_au_tags, id);
 
-    if (!(bps = av_get_bits_per_sample(codec))) {
+    if (codec == AV_CODEC_ID_NONE) {
+        av_log_ask_for_sample(s, "unknown or unsupported codec tag: %u\n", id);
+        return AVERROR_PATCHWELCOME;
+    }
+
+    bps = av_get_bits_per_sample(codec);
+    if (!bps) {
         av_log_ask_for_sample(s, "could not determine bits per sample\n");
         return AVERROR_PATCHWELCOME;
     }
 
-    if (channels == 0 || channels > 64) {
-        av_log(s, AV_LOG_ERROR, "Invalid number of channels %d\n", channels);
+    if (channels == 0 || channels >= INT_MAX / (BLOCK_SIZE * bps >> 3)) {
+        av_log(s, AV_LOG_ERROR, "Invalid number of channels %u\n", channels);
         return AVERROR_INVALIDDATA;
     }
 
-    if (size >= 24) {
-        /* skip unused data */
-        avio_skip(pb, size - 24);
+    if (rate == 0 || rate > INT_MAX) {
+        av_log(s, AV_LOG_ERROR, "Invalid sample rate: %u\n", rate);
+        return AVERROR_INVALIDDATA;
     }
 
-    /* now we are ready: build format streams */
     st = avformat_new_stream(s, NULL);
     if (!st)
         return AVERROR(ENOMEM);
-    st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
-    st->codec->codec_tag = id;
-    st->codec->codec_id = codec;
-    st->codec->channels = channels;
+    st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
+    st->codec->codec_tag   = id;
+    st->codec->codec_id    = codec;
+    st->codec->channels    = channels;
     st->codec->sample_rate = rate;
+    st->codec->bit_rate    = channels * rate * bps;
     st->codec->block_align = FFMAX(bps * st->codec->channels / 8, 1);
     if (data_size != AU_UNKNOWN_SIZE)
     st->duration = (((int64_t)data_size)<<3) / (st->codec->channels * (int64_t)bps);
+
+    st->start_time = 0;
     avpriv_set_pts_info(st, 64, 1, rate);
+
     return 0;
 }
 
 AVInputFormat ff_au_demuxer = {
-    .name           = "au",
-    .long_name      = NULL_IF_CONFIG_SMALL("Sun AU"),
-    .read_probe     = au_probe,
-    .read_header    = au_read_header,
-    .read_packet    = ff_pcm_read_packet,
-    .read_seek      = ff_pcm_read_seek,
-    .codec_tag      = (const AVCodecTag* const []){ codec_au_tags, 0 },
+    .name        = "au",
+    .long_name   = NULL_IF_CONFIG_SMALL("Sun AU"),
+    .read_probe  = au_probe,
+    .read_header = au_read_header,
+    .read_packet = ff_pcm_read_packet,
+    .read_seek   = ff_pcm_read_seek,
+    .codec_tag   = (const AVCodecTag* const []) { codec_au_tags, 0 },
 };
+
 #endif /* CONFIG_AU_DEMUXER */
 
 #if CONFIG_AU_MUXER
 
 #include "rawenc.h"
 
-/* AUDIO_FILE header */
-static int put_au_header(AVIOContext *pb, AVCodecContext *enc)
-{
-    if(!enc->codec_tag)
-        return -1;
-    ffio_wfourcc(pb, ".snd");    /* magic number */
-    avio_wb32(pb, AU_HEADER_SIZE);  /* header size */
-    avio_wb32(pb, AU_UNKNOWN_SIZE); /* data size */
-    avio_wb32(pb, (uint32_t)enc->codec_tag);     /* codec ID */
-    avio_wb32(pb, enc->sample_rate);
-    avio_wb32(pb, (uint32_t)enc->channels);
-    avio_wb64(pb, 0); /* annotation field */
-    return 0;
-}
-
 static int au_write_header(AVFormatContext *s)
 {
     AVIOContext *pb = s->pb;
+    AVCodecContext *enc = s->streams[0]->codec;
 
-    /* format header */
-    if (put_au_header(pb, s->streams[0]->codec) < 0) {
+    if (s->nb_streams != 1) {
+        av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
         return AVERROR(EINVAL);
     }
 
+    enc->codec_tag = ff_codec_get_tag(codec_au_tags, enc->codec_id);
+    if (!enc->codec_tag) {
+        av_log(s, AV_LOG_ERROR, "unsupported codec\n");
+        return AVERROR(EINVAL);
+    }
+
+    ffio_wfourcc(pb, ".snd");                   /* magic number */
+    avio_wb32(pb, AU_HEADER_SIZE);              /* header size */
+    avio_wb32(pb, AU_UNKNOWN_SIZE);             /* data size */
+    avio_wb32(pb, enc->codec_tag);              /* codec ID */
+    avio_wb32(pb, enc->sample_rate);
+    avio_wb32(pb, enc->channels);
+    avio_wb64(pb, 0); /* annotation field */
     avio_flush(pb);
 
     return 0;
@@ -176,7 +189,6 @@ static int au_write_trailer(AVFormatContext *s)
         avio_seek(pb, 8, SEEK_SET);
         avio_wb32(pb, (uint32_t)(file_size - AU_HEADER_SIZE));
         avio_seek(pb, file_size, SEEK_SET);
-
         avio_flush(pb);
     }
 
@@ -184,15 +196,16 @@ static int au_write_trailer(AVFormatContext *s)
 }
 
 AVOutputFormat ff_au_muxer = {
-    .name              = "au",
-    .long_name         = NULL_IF_CONFIG_SMALL("Sun AU"),
-    .mime_type         = "audio/basic",
-    .extensions        = "au",
-    .audio_codec       = AV_CODEC_ID_PCM_S16BE,
-    .video_codec       = AV_CODEC_ID_NONE,
-    .write_header      = au_write_header,
-    .write_packet      = ff_raw_write_packet,
-    .write_trailer     = au_write_trailer,
-    .codec_tag         = (const AVCodecTag* const []){ codec_au_tags, 0 },
+    .name          = "au",
+    .long_name     = NULL_IF_CONFIG_SMALL("Sun AU"),
+    .mime_type     = "audio/basic",
+    .extensions    = "au",
+    .audio_codec   = AV_CODEC_ID_PCM_S16BE,
+    .video_codec   = AV_CODEC_ID_NONE,
+    .write_header  = au_write_header,
+    .write_packet  = ff_raw_write_packet,
+    .write_trailer = au_write_trailer,
+    .codec_tag     = (const AVCodecTag* const []) { codec_au_tags, 0 },
 };
+
 #endif /* CONFIG_AU_MUXER */
diff --git a/mythtv/external/FFmpeg/libavformat/avformat.h b/mythtv/external/FFmpeg/libavformat/avformat.h
index 1f93c4cb56a..8bd2b6c5e28 100644
--- a/mythtv/external/FFmpeg/libavformat/avformat.h
+++ b/mythtv/external/FFmpeg/libavformat/avformat.h
@@ -754,11 +754,13 @@ typedef struct AVStream {
         int64_t last_dts;
         int64_t duration_gcd;
         int duration_count;
-        double duration_error[2][2][MAX_STD_TIMEBASES];
+        double (*duration_error)[2][MAX_STD_TIMEBASES];
         int64_t codec_info_duration;
         int64_t codec_info_duration_fields;
         int found_decoder;
 
+        int64_t last_duration;
+
         /**
          * Those are used for average framerate estimation.
          */
@@ -850,7 +852,7 @@ typedef struct AVStream {
 
     /**
      * Number of internally decoded frames, used internally in libavformat, do not access
-     * its lifetime differs from info which is why its not in that structure.
+     * its lifetime differs from info which is why it is not in that structure.
      */
     int nb_decoded_frames;
 
@@ -1219,6 +1221,13 @@ typedef struct AVFormatContext {
      */
     unsigned int correct_ts_overflow;
 
+    /**
+     * Force seeking to any (also non key) frames.
+     * - encoding: unused
+     * - decoding: Set by user via AVOPtions (NO direct access)
+     */
+    int seek2any;
+
     /*****************************************************************
      * All fields below this line are not part of the public API. They
      * may not be used outside of libavformat and can be changed and
@@ -1946,6 +1955,18 @@ enum AVCodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned i
  */
 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum AVCodecID id);
 
+/**
+ * Get the codec tag for the given codec id.
+ *
+ * @param tags list of supported codec_id - codec_tag pairs, as stored
+ * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
+ * @param id codec id that should be searched for in the list
+ * @param tag A pointer to the found tag
+ * @return 0 if id was not found in tags, > 0 if it was found
+ */
+int av_codec_get_tag2(const struct AVCodecTag * const *tags, enum AVCodecID id,
+                      unsigned int *tag);
+
 int av_find_default_stream_index(AVFormatContext *s);
 
 /**
diff --git a/mythtv/external/FFmpeg/libavformat/avidec.c b/mythtv/external/FFmpeg/libavformat/avidec.c
index 8ce307101e4..d1c5848306a 100644
--- a/mythtv/external/FFmpeg/libavformat/avidec.c
+++ b/mythtv/external/FFmpeg/libavformat/avidec.c
@@ -140,7 +140,7 @@ static int get_riff(AVFormatContext *s, AVIOContext *pb)
         if(!memcmp(header, avi_headers[i], 8))
             break;
     if(!avi_headers[i][0])
-        return -1;
+        return AVERROR_INVALIDDATA;
 
     if(header[7] == 0x19)
         av_log(s, AV_LOG_INFO, "This file has been generated by a totally broken muxer.\n");
@@ -168,26 +168,26 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
             longs_pre_entry,index_type, entries_in_use, chunk_id, base);
 
     if(stream_id >= s->nb_streams || stream_id < 0)
-        return -1;
+        return AVERROR_INVALIDDATA;
     st= s->streams[stream_id];
     ast = st->priv_data;
 
     if(index_sub_type)
-        return -1;
+        return AVERROR_INVALIDDATA;
 
     avio_rl32(pb);
 
     if(index_type && longs_pre_entry != 2)
-        return -1;
+        return AVERROR_INVALIDDATA;
     if(index_type>1)
-        return -1;
+        return AVERROR_INVALIDDATA;
 
     if(filesize > 0 && base >= filesize){
         av_log(s, AV_LOG_ERROR, "ODML index invalid\n");
         if(base>>32 == (base & 0xFFFFFFFF) && (base & 0xFFFFFFFF) < filesize && filesize <= 0xFFFFFFFF)
             base &= 0xFFFFFFFF;
         else
-            return -1;
+            return AVERROR_INVALIDDATA;
     }
 
     for(i=0; inon_interleaved= 1;
@@ -218,13 +218,13 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
             duration = avio_rl32(pb);
 
             if(url_feof(pb))
-                return -1;
+                return AVERROR_INVALIDDATA;
 
             pos = avio_tell(pb);
 
             if(avi->odml_depth > MAX_ODML_DEPTH){
                 av_log(s, AV_LOG_ERROR, "Too deeply nested ODML indexes\n");
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
 
             if(avio_seek(pb, offset+8, SEEK_SET) < 0)
@@ -279,10 +279,10 @@ static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag, uint32_t
     size += (size & 1);
 
     if (size == UINT_MAX)
-        return -1;
+        return AVERROR(EINVAL);
     value = av_malloc(size+1);
     if (!value)
-        return -1;
+        return AVERROR(ENOMEM);
     avio_read(pb, value, size);
     value[size]=0;
 
@@ -367,8 +367,9 @@ static int avi_read_header(AVFormatContext *s)
 
     avi->stream_index= -1;
 
-    if (get_riff(s, pb) < 0)
-        return -1;
+    ret = get_riff(s, pb);
+    if (ret < 0)
+        return ret;
 
     av_log(avi, AV_LOG_DEBUG, "use odml:%d\n", avi->use_odml);
 
@@ -483,6 +484,8 @@ static int avi_read_header(AVFormatContext *s)
                 ast = s->streams[0]->priv_data;
                 av_freep(&s->streams[0]->codec->extradata);
                 av_freep(&s->streams[0]->codec);
+                if (s->streams[0]->info)
+                    av_freep(&s->streams[0]->info->duration_error);
                 av_freep(&s->streams[0]->info);
                 av_freep(&s->streams[0]);
                 s->nb_streams = 0;
@@ -761,7 +764,9 @@ static int avi_read_header(AVFormatContext *s)
             break;
         case MKTAG('s', 't', 'r', 'n'):
             if(s->nb_streams){
-                avi_read_tag(s, s->streams[s->nb_streams-1], tag, size);
+                ret = avi_read_tag(s, s->streams[s->nb_streams-1], tag, size);
+                if (ret < 0)
+                    return ret;
                 break;
             }
         default:
@@ -784,7 +789,7 @@ static int avi_read_header(AVFormatContext *s)
     /* check stream number */
     if (stream_index != s->nb_streams - 1) {
     fail:
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if(!avi->index_loaded && pb->seekable)
@@ -1262,7 +1267,7 @@ static int avi_read_idx1(AVFormatContext *s, int size)
 
     nb_index_entries = size / 16;
     if (nb_index_entries <= 0)
-        return -1;
+        return AVERROR_INVALIDDATA;
 
     idx1_pos = avio_tell(pb);
     avio_seek(pb, avi->movi_list+4, SEEK_SET);
@@ -1304,7 +1309,6 @@ static int avi_read_idx1(AVFormatContext *s, int size)
 
         av_dlog(s, "%d cum_len=%"PRId64"\n", len, ast->cum_len);
 
-
         // even if we have only a single stream, we should
         // switch to non-interleaved to get correct timestamps
         if(last_pos == pos)
@@ -1474,7 +1478,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
                    timestamp * FFMAX(ast->sample_size, 1),
                    st->index_entries[0].timestamp,
                    st->index_entries[st->nb_index_entries - 1].timestamp);
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     /* find the position */
diff --git a/mythtv/external/FFmpeg/libavformat/avio.c b/mythtv/external/FFmpeg/libavformat/avio.c
index 56f810ec765..f6af0cb9e6d 100644
--- a/mythtv/external/FFmpeg/libavformat/avio.c
+++ b/mythtv/external/FFmpeg/libavformat/avio.c
@@ -119,6 +119,16 @@ static int url_alloc_for_protocol (URLContext **puc, struct URLProtocol *up,
     if (up->flags & URL_PROTOCOL_FLAG_NETWORK && !ff_network_init())
         return AVERROR(EIO);
 #endif
+    if ((flags & AVIO_FLAG_READ) && !up->url_read) {
+        av_log(NULL, AV_LOG_ERROR,
+               "Impossible to open the '%s' protocol for reading\n", up->name);
+        return AVERROR(EIO);
+    }
+    if ((flags & AVIO_FLAG_WRITE) && !up->url_write) {
+        av_log(NULL, AV_LOG_ERROR,
+               "Impossible to open the '%s' protocol for writing\n", up->name);
+        return AVERROR(EIO);
+    }
     uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1);
     if (!uc) {
         err = AVERROR(ENOMEM);
diff --git a/mythtv/external/FFmpeg/libavformat/avisynth.c b/mythtv/external/FFmpeg/libavformat/avisynth.c
index e5d9b7626f3..1e4dee1b004 100644
--- a/mythtv/external/FFmpeg/libavformat/avisynth.c
+++ b/mythtv/external/FFmpeg/libavformat/avisynth.c
@@ -226,7 +226,7 @@ static int avisynth_read_seek(AVFormatContext *s, int stream_index, int64_t pts,
 }
 
 AVInputFormat ff_avisynth_demuxer = {
-    .name           = "avs",
+    .name           = "avisynth",
     .long_name      = NULL_IF_CONFIG_SMALL("AVISynth"),
     .priv_data_size = sizeof(AVISynthContext),
     .read_header    = avisynth_read_header,
diff --git a/mythtv/external/FFmpeg/libavformat/bink.c b/mythtv/external/FFmpeg/libavformat/bink.c
index c77a8f84e74..887f70a5128 100644
--- a/mythtv/external/FFmpeg/libavformat/bink.c
+++ b/mythtv/external/FFmpeg/libavformat/bink.c
@@ -112,6 +112,7 @@ static int read_header(AVFormatContext *s)
         return AVERROR(EIO);
     }
     avpriv_set_pts_info(vst, 64, fps_den, fps_num);
+    vst->avg_frame_rate = av_inv_q(vst->time_base);
 
     vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
     vst->codec->codec_id   = AV_CODEC_ID_BINKVIDEO;
diff --git a/mythtv/external/FFmpeg/libavformat/cafdec.c b/mythtv/external/FFmpeg/libavformat/cafdec.c
index f12226a8f53..337758ee127 100644
--- a/mythtv/external/FFmpeg/libavformat/cafdec.c
+++ b/mythtv/external/FFmpeg/libavformat/cafdec.c
@@ -300,7 +300,7 @@ static int read_header(AVFormatContext *s)
         }
 
         if (size > 0) {
-            if (pos + size < pos)
+            if (pos > INT64_MAX - size)
                 return AVERROR_INVALIDDATA;
             avio_skip(pb, FFMAX(0, pos + size - avio_tell(pb)));
         }
diff --git a/mythtv/external/FFmpeg/libavformat/cafenc.c b/mythtv/external/FFmpeg/libavformat/cafenc.c
index 40ccd48c2da..11bb0559657 100644
--- a/mythtv/external/FFmpeg/libavformat/cafenc.c
+++ b/mythtv/external/FFmpeg/libavformat/cafenc.c
@@ -238,11 +238,11 @@ static int caf_write_packet(AVFormatContext *s, AVPacket *pkt)
 
 static int caf_write_trailer(AVFormatContext *s)
 {
+    CAFContext *caf = s->priv_data;
     AVIOContext *pb = s->pb;
     AVCodecContext *enc = s->streams[0]->codec;
 
     if (pb->seekable) {
-        CAFContext *caf = s->priv_data;
         int64_t file_size = avio_tell(pb);
 
         avio_seek(pb, caf->data, SEEK_SET);
@@ -256,11 +256,11 @@ static int caf_write_trailer(AVFormatContext *s)
             avio_wb32(pb, 0); ///< mPrimingFrames
             avio_wb32(pb, 0); ///< mRemainderFrames
             avio_write(pb, caf->pkt_sizes, caf->size_entries_used);
-            av_freep(&caf->pkt_sizes);
             caf->size_buffer_size = 0;
         }
         avio_flush(pb);
     }
+    av_freep(&caf->pkt_sizes);
     return 0;
 }
 
diff --git a/mythtv/external/FFmpeg/libavformat/concatdec.c b/mythtv/external/FFmpeg/libavformat/concatdec.c
index 0514755e0a5..a9fcc76a035 100644
--- a/mythtv/external/FFmpeg/libavformat/concatdec.c
+++ b/mythtv/external/FFmpeg/libavformat/concatdec.c
@@ -19,6 +19,8 @@
  */
 
 #include "libavutil/avstring.h"
+#include "libavutil/opt.h"
+#include "libavutil/parseutils.h"
 #include "avformat.h"
 #include "internal.h"
 
@@ -29,15 +31,18 @@ typedef struct {
 } ConcatFile;
 
 typedef struct {
+    AVClass *class;
     ConcatFile *files;
     ConcatFile *cur_file;
     unsigned nb_files;
     AVFormatContext *avf;
+    int safe;
 } ConcatContext;
 
 static int concat_probe(AVProbeData *probe)
 {
-    return 0;
+    return memcmp(probe->buf, "ffconcat version 1.0", 20) ?
+           0 : AVPROBE_SCORE_MAX;
 }
 
 static char *get_keyword(uint8_t **cursor)
@@ -51,6 +56,25 @@ static char *get_keyword(uint8_t **cursor)
     return ret;
 }
 
+static int safe_filename(const char *f)
+{
+    const char *start = f;
+
+    for (; *f; f++) {
+        /* A-Za-z0-9_- */
+        if (!((unsigned)((*f | 32) - 'a') < 26 ||
+              (unsigned)(*f - '0') < 10 || *f == '_' || *f == '-')) {
+            if (f == start)
+                return 0;
+            else if (*f == '/')
+                start = f + 1;
+            else if (*f != '.')
+                return 0;
+        }
+    }
+    return 1;
+}
+
 #define FAIL(retcode) do { ret = (retcode); goto fail; } while(0)
 
 static int add_file(AVFormatContext *avf, char *filename, ConcatFile **rfile,
@@ -61,6 +85,10 @@ static int add_file(AVFormatContext *avf, char *filename, ConcatFile **rfile,
     char *url;
     size_t url_len;
 
+    if (cat->safe > 0 && !safe_filename(filename)) {
+        av_log(avf, AV_LOG_ERROR, "Unsafe file name '%s'\n", filename);
+        return AVERROR(EPERM);
+    }
     url_len = strlen(avf->filename) + strlen(filename) + 16;
     if (!(url = av_malloc(url_len)))
         return AVERROR(ENOMEM);
@@ -129,6 +157,7 @@ static int concat_read_header(AVFormatContext *avf)
     unsigned nb_files_alloc = 0;
     ConcatFile *file = NULL;
     AVStream *st, *source_st;
+    int64_t time = 0;
 
     while (1) {
         if ((ret = ff_get_line(avf->pb, buf, sizeof(buf))) <= 0)
@@ -147,6 +176,29 @@ static int concat_read_header(AVFormatContext *avf)
             }
             if ((ret = add_file(avf, filename, &file, &nb_files_alloc)) < 0)
                 FAIL(ret);
+        } else if (!strcmp(keyword, "duration")) {
+            char *dur_str = get_keyword(&cursor);
+            int64_t dur;
+            if (!file) {
+                av_log(avf, AV_LOG_ERROR, "Line %d: duration without file\n",
+                       line);
+                FAIL(AVERROR_INVALIDDATA);
+            }
+            if ((ret = av_parse_time(&dur, dur_str, 1)) < 0) {
+                av_log(avf, AV_LOG_ERROR, "Line %d: invalid duration '%s'\n",
+                       line, dur_str);
+                FAIL(ret);
+            }
+            file->duration = dur;
+        } else if (!strcmp(keyword, "ffconcat")) {
+            char *ver_kw  = get_keyword(&cursor);
+            char *ver_val = get_keyword(&cursor);
+            if (strcmp(ver_kw, "version") || strcmp(ver_val, "1.0")) {
+                av_log(avf, AV_LOG_ERROR, "Line %d: invalid version\n", line);
+                FAIL(AVERROR_INVALIDDATA);
+            }
+            if (cat->safe < 0)
+                cat->safe = 1;
         } else {
             av_log(avf, AV_LOG_ERROR, "Line %d: unknown keyword '%s'\n",
                    line, keyword);
@@ -156,6 +208,18 @@ static int concat_read_header(AVFormatContext *avf)
     if (ret < 0)
         FAIL(ret);
 
+    for (i = 0; i < cat->nb_files; i++) {
+        if (cat->files[i].start_time == AV_NOPTS_VALUE)
+            cat->files[i].start_time = time;
+        else
+            time = cat->files[i].start_time;
+        if (cat->files[i].duration == AV_NOPTS_VALUE)
+            break;
+        time += cat->files[i].duration;
+    }
+    if (i == cat->nb_files)
+        avf->duration = time;
+
     if ((ret = open_file(avf, 0)) < 0)
         FAIL(ret);
     for (i = 0; i < cat->avf->nb_streams; i++) {
@@ -212,6 +276,23 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt)
     return ret;
 }
 
+#define OFFSET(x) offsetof(ConcatContext, x)
+#define DEC AV_OPT_FLAG_DECODING_PARAM
+
+static const AVOption options[] = {
+    { "safe", "enable safe mode",
+      OFFSET(safe), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, DEC },
+    { NULL }
+};
+
+static const AVClass concat_class = {
+    .class_name = "concat demuxer",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+
 AVInputFormat ff_concat_demuxer = {
     .name           = "concat",
     .long_name      = NULL_IF_CONFIG_SMALL("Virtual concatenation script"),
@@ -220,4 +301,5 @@ AVInputFormat ff_concat_demuxer = {
     .read_header    = concat_read_header,
     .read_packet    = concat_read_packet,
     .read_close     = concat_read_close,
+    .priv_class     = &concat_class,
 };
diff --git a/mythtv/external/FFmpeg/libavformat/eacdata.c b/mythtv/external/FFmpeg/libavformat/eacdata.c
index be31d007e04..57e514566f1 100644
--- a/mythtv/external/FFmpeg/libavformat/eacdata.c
+++ b/mythtv/external/FFmpeg/libavformat/eacdata.c
@@ -76,7 +76,6 @@ static int cdata_read_header(AVFormatContext *s)
     st->codec->channels = cdata->channels;
     st->codec->channel_layout = channel_layout;
     st->codec->sample_rate = sample_rate;
-    st->codec->sample_fmt = AV_SAMPLE_FMT_S16;
     avpriv_set_pts_info(st, 64, 1, sample_rate);
 
     cdata->audio_pts = 0;
diff --git a/mythtv/external/FFmpeg/libavformat/flacdec.c b/mythtv/external/FFmpeg/libavformat/flacdec.c
index 6b19cd59236..ecc47e6ccd3 100644
--- a/mythtv/external/FFmpeg/libavformat/flacdec.c
+++ b/mythtv/external/FFmpeg/libavformat/flacdec.c
@@ -277,9 +277,11 @@ static int flac_read_header(AVFormatContext *s)
 
 static int flac_probe(AVProbeData *p)
 {
-    if (p->buf_size < 4 || memcmp(p->buf, "fLaC", 4))
-        return 0;
-    return AVPROBE_SCORE_MAX/2;
+    const uint8_t *bufptr = p->buf;
+    const uint8_t *end    = p->buf + p->buf_size;
+
+    if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
+    else                                            return AVPROBE_SCORE_MAX/2;
 }
 
 AVInputFormat ff_flac_demuxer = {
diff --git a/mythtv/external/FFmpeg/libavformat/flic.c b/mythtv/external/FFmpeg/libavformat/flic.c
index 2b9ee67d460..8d49116acf9 100644
--- a/mythtv/external/FFmpeg/libavformat/flic.c
+++ b/mythtv/external/FFmpeg/libavformat/flic.c
@@ -158,7 +158,6 @@ static int flic_read_header(AVFormatContext *s)
         ast->codec->codec_tag = 0;
         ast->codec->sample_rate = FLIC_TFTD_SAMPLE_RATE;
         ast->codec->channels = 1;
-        ast->codec->sample_fmt = AV_SAMPLE_FMT_U8;
         ast->codec->bit_rate = st->codec->sample_rate * 8;
         ast->codec->bits_per_coded_sample = 8;
         ast->codec->channel_layout = AV_CH_LAYOUT_MONO;
diff --git a/mythtv/external/FFmpeg/libavformat/framecrcenc.c b/mythtv/external/FFmpeg/libavformat/framecrcenc.c
index 8a6974891ed..92f2e9112a7 100644
--- a/mythtv/external/FFmpeg/libavformat/framecrcenc.c
+++ b/mythtv/external/FFmpeg/libavformat/framecrcenc.c
@@ -33,8 +33,17 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
              pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size, crc);
     if (pkt->flags != AV_PKT_FLAG_KEY)
         av_strlcatf(buf, sizeof(buf), ", F=0x%0X", pkt->flags);
-    if (pkt->side_data_elems)
+    if (pkt->side_data_elems) {
+        int i;
         av_strlcatf(buf, sizeof(buf), ", S=%d", pkt->side_data_elems);
+
+        for (i=0; iside_data_elems; i++) {
+            uint32_t side_data_crc = av_adler32_update(0,
+                                                    pkt->side_data[i].data,
+                                                    pkt->side_data[i].size);
+            av_strlcatf(buf, sizeof(buf), ", %8d, 0x%08x", pkt->side_data[i].size, side_data_crc);
+        }
+    }
     av_strlcatf(buf, sizeof(buf), "\n");
     avio_write(s->pb, buf, strlen(buf));
     avio_flush(s->pb);
diff --git a/mythtv/external/FFmpeg/libavformat/frmdec.c b/mythtv/external/FFmpeg/libavformat/frmdec.c
index 1dc2358aa7e..a6f19afcd41 100644
--- a/mythtv/external/FFmpeg/libavformat/frmdec.c
+++ b/mythtv/external/FFmpeg/libavformat/frmdec.c
@@ -24,16 +24,17 @@
  * Megalux Frame demuxer
  */
 
+#include "libavcodec/raw.h"
 #include "libavutil/intreadwrite.h"
 #include "avformat.h"
-#include "riff.h"
-
-static const AVCodecTag frm_pix_fmt_tags[] = {
-    { PIX_FMT_RGB555, 1 },
-    { PIX_FMT_BGR32,  2 },
-    { PIX_FMT_RGB24,  3 },
-    { PIX_FMT_BGR0,   4 },
-    { PIX_FMT_BGR0,   5 },
+
+static const PixelFormatTag frm_pix_fmt_tags[] = {
+    { AV_PIX_FMT_RGB555, 1 },
+    { AV_PIX_FMT_RGB0,   2 },
+    { AV_PIX_FMT_RGB24,  3 },
+    { AV_PIX_FMT_BGR0,   4 },
+    { AV_PIX_FMT_BGRA,   5 },
+    { AV_PIX_FMT_NONE,   0 },
 };
 
 typedef struct {
@@ -60,7 +61,7 @@ static int frm_read_header(AVFormatContext *avctx)
     st->codec->codec_id   = AV_CODEC_ID_RAWVIDEO;
     avio_skip(pb, 3);
 
-    st->codec->pix_fmt    = ff_codec_get_id(frm_pix_fmt_tags, avio_r8(pb));
+    st->codec->pix_fmt    = avpriv_find_pix_fmt(frm_pix_fmt_tags, avio_r8(pb));
     if (!st->codec->pix_fmt)
         return AVERROR_INVALIDDATA;
 
@@ -87,6 +88,12 @@ static int frm_read_packet(AVFormatContext *avctx, AVPacket *pkt)
     if (ret < 0)
         return ret;
 
+    if (stc->pix_fmt == AV_PIX_FMT_BGRA) {
+        int i;
+        for (i = 3; i + 1 <= pkt->size; i += 4)
+            pkt->data[i] = 0xFF - pkt->data[i];
+    }
+
     pkt->stream_index = 0;
     s->count++;
 
diff --git a/mythtv/external/FFmpeg/libavformat/gifdec.c b/mythtv/external/FFmpeg/libavformat/gifdec.c
index 4f4ce2ca956..1122849abdf 100644
--- a/mythtv/external/FFmpeg/libavformat/gifdec.c
+++ b/mythtv/external/FFmpeg/libavformat/gifdec.c
@@ -70,6 +70,19 @@ static int gif_probe(AVProbeData *p)
     return AVPROBE_SCORE_MAX;
 }
 
+static int resync(AVIOContext *pb)
+{
+    int i;
+    for (i = 0; i < 6; i++) {
+        int b = avio_r8(pb);
+        if (b != gif87a_sig[i] && b != gif89a_sig[i])
+            i = -(b != 'G');
+        if (url_feof(pb))
+            return AVERROR_EOF;
+    }
+    return 0;
+}
+
 static int gif_read_header(AVFormatContext *s)
 {
     GIFDemuxContext *gdc = s->priv_data;
@@ -77,8 +90,7 @@ static int gif_read_header(AVFormatContext *s)
     AVStream        *st;
     int width, height, ret;
 
-    /* skip 6-byte magick */
-    if ((ret = avio_skip(pb, 6)) < 0)
+    if ((ret = resync(pb)) < 0)
         return ret;
 
     gdc->delay  = gdc->default_delay;
@@ -171,6 +183,7 @@ static int gif_read_packet(AVFormatContext *s, AVPacket *pkt)
     }
 
     if (keyframe) {
+parse_keyframe:
         /* skip 2 bytes of width and 2 of height */
         if ((ret = avio_skip(pb, 4)) < 0)
             return ret;
@@ -181,7 +194,7 @@ static int gif_read_packet(AVFormatContext *s, AVPacket *pkt)
         if ((ret = avio_skip(pb, 2)) < 0)
             return ret;
 
-        /* glogal color table presence */
+        /* global color table presence */
         if (packed_fields & 0x80) {
             ct_size = 3 * (1 << ((packed_fields & 0x07) + 1));
 
@@ -196,7 +209,7 @@ static int gif_read_packet(AVFormatContext *s, AVPacket *pkt)
     while (GIF_TRAILER != (block_label = avio_r8(pb)) && !url_feof(pb)) {
         if (block_label == GIF_EXTENSION_INTRODUCER) {
             if ((ret = gif_read_ext (s)) < 0 )
-                return ret;
+                goto resync;
         } else if (block_label == GIF_IMAGE_SEPARATOR) {
             /* skip to last byte of Image Descriptor header */
             if ((ret = avio_skip(pb, 8)) < 0)
@@ -215,11 +228,11 @@ static int gif_read_packet(AVFormatContext *s, AVPacket *pkt)
             /* read LZW Minimum Code Size */
             if (avio_r8(pb) < 1) {
                 av_log(s, AV_LOG_ERROR, "lzw minimum code size must be >= 1\n");
-                return AVERROR_INVALIDDATA;
+                goto resync;
             }
 
             if ((ret = gif_skip_subblocks(pb)) < 0)
-                return ret;
+                goto resync;
 
             frame_end = avio_tell(pb);
 
@@ -244,14 +257,21 @@ static int gif_read_packet(AVFormatContext *s, AVPacket *pkt)
             break;
         } else {
             av_log(s, AV_LOG_ERROR, "invalid block label\n");
-            return AVERROR_INVALIDDATA;
+resync:
+            if (!keyframe)
+                avio_seek(pb, frame_start, SEEK_SET);
+            if ((ret = resync(pb)) < 0)
+                return ret;
+            frame_start = avio_tell(pb) - 6;
+            keyframe = 1;
+            goto parse_keyframe;
         }
     }
 
     if (ret >= 0 && !frame_parsed) {
         /* This might happen when there is no image block
          * between extension blocks and GIF_TRAILER or EOF */
-        return  AVERROR_EOF;
+        return AVERROR_EOF;
     } else
         return ret;
 }
diff --git a/mythtv/external/FFmpeg/libavformat/hls.c b/mythtv/external/FFmpeg/libavformat/hls.c
index 4a67c2db69e..7de6059c5a2 100644
--- a/mythtv/external/FFmpeg/libavformat/hls.c
+++ b/mythtv/external/FFmpeg/libavformat/hls.c
@@ -103,12 +103,14 @@ typedef struct HLSContext {
     int64_t seek_timestamp;
     int seek_flags;
     AVIOInterruptCB *interrupt_callback;
+    char *user_agent;                    ///< holds HTTP user agent set as an AVOption to the HTTP protocol context
+    char *cookies;                       ///< holds HTTP cookie values set in either the initial response or as an AVOption to the HTTP protocol context
 } HLSContext;
 
 static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
 {
     int len = ff_get_line(s, buf, maxlen);
-    while (len > 0 && isspace(buf[len - 1]))
+    while (len > 0 && av_isspace(buf[len - 1]))
         buf[--len] = '\0';
     return len;
 }
@@ -139,6 +141,8 @@ static void free_variant_list(HLSContext *c)
         av_free(var);
     }
     av_freep(&c->variants);
+    av_freep(&c->cookies);
+    av_freep(&c->user_agent);
     c->n_variants = 0;
 }
 
@@ -216,6 +220,11 @@ static int parse_playlist(HLSContext *c, const char *url,
         close_in = 1;
         /* Some HLS servers dont like being sent the range header */
         av_dict_set(&opts, "seekable", "0", 0);
+
+        // broker prior HTTP options that should be consistent across requests
+        av_dict_set(&opts, "user-agent", c->user_agent, 0);
+        av_dict_set(&opts, "cookies", c->cookies, 0);
+
         ret = avio_open2(&in, url, AVIO_FLAG_READ,
                          c->interrupt_callback, &opts);
         av_dict_free(&opts);
@@ -328,12 +337,17 @@ static int parse_playlist(HLSContext *c, const char *url,
     return ret;
 }
 
-static int open_input(struct variant *var)
+static int open_input(HLSContext *c, struct variant *var)
 {
     AVDictionary *opts = NULL;
     int ret;
     struct segment *seg = var->segments[var->cur_seq_no - var->start_seq_no];
+
+    // broker prior HTTP options that should be consistent across requests
+    av_dict_set(&opts, "user-agent", c->user_agent, 0);
+    av_dict_set(&opts, "cookies", c->cookies, 0);
     av_dict_set(&opts, "seekable", "0", 0);
+
     if (seg->key_type == KEY_NONE) {
         ret = ffurl_open(&var->input, seg->url, AVIO_FLAG_READ,
                           &var->parent->interrupt_callback, &opts);
@@ -429,7 +443,7 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
             goto reload;
         }
 
-        ret = open_input(v);
+        ret = open_input(c, v);
         if (ret < 0)
             return ret;
     }
@@ -461,11 +475,27 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
 
 static int hls_read_header(AVFormatContext *s)
 {
+    URLContext *u = (s->flags & AVFMT_FLAG_CUSTOM_IO) ? NULL : s->pb->opaque;
     HLSContext *c = s->priv_data;
     int ret = 0, i, j, stream_offset = 0;
 
     c->interrupt_callback = &s->interrupt_callback;
 
+    // if the URL context is good, read important options we must broker later
+    if (u && u->prot->priv_data_class) {
+        // get the previous user agent & set back to null if string size is zero
+        av_freep(&c->user_agent);
+        av_opt_get(u->priv_data, "user-agent", 0, (uint8_t**)&(c->user_agent));
+        if (c->user_agent && !strlen(c->user_agent))
+            av_freep(&c->user_agent);
+
+        // get the previous cookies & set back to null if string size is zero
+        av_freep(&c->cookies);
+        av_opt_get(u->priv_data, "cookies", 0, (uint8_t**)&(c->cookies));
+        if (c->cookies && !strlen(c->cookies))
+            av_freep(&c->cookies);
+    }
+
     if ((ret = parse_playlist(c, s->filename, NULL, s->pb)) < 0)
         goto fail;
 
diff --git a/mythtv/external/FFmpeg/libavformat/hlsenc.c b/mythtv/external/FFmpeg/libavformat/hlsenc.c
index 9eed9577b8c..18914c026a9 100644
--- a/mythtv/external/FFmpeg/libavformat/hlsenc.c
+++ b/mythtv/external/FFmpeg/libavformat/hlsenc.c
@@ -49,6 +49,7 @@ typedef struct HLSContext {
     int has_video;
     int64_t start_pts;
     int64_t end_pts;
+    int64_t duration;      ///< last segment duration computed so far, in seconds
     int nb_entries;
     ListEntry *list;
     ListEntry *end_list;
@@ -252,7 +253,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
     AVFormatContext *oc = hls->avf;
     AVStream *st = s->streams[pkt->stream_index];
     int64_t end_pts = hls->recording_time * hls->number;
-    int ret;
+    int ret, is_ref_pkt = 0;
 
     if (hls->start_pts == AV_NOPTS_VALUE) {
         hls->start_pts = pkt->pts;
@@ -260,17 +261,23 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
     }
 
     if ((hls->has_video && st->codec->codec_type == AVMEDIA_TYPE_VIDEO)      &&
+        pkt->pts != AV_NOPTS_VALUE) {
+        is_ref_pkt = 1;
+        hls->duration = av_rescale(pkt->pts - hls->end_pts,
+                                   st->time_base.num, st->time_base.den);
+    }
+
+    if (is_ref_pkt &&
         av_compare_ts(pkt->pts - hls->start_pts, st->time_base,
                       end_pts, AV_TIME_BASE_Q) >= 0 &&
         pkt->flags & AV_PKT_FLAG_KEY) {
 
-        ret = append_entry(hls, av_rescale(pkt->pts - hls->end_pts,
-                                           st->time_base.num,
-                                           st->time_base.den));
+        ret = append_entry(hls, hls->duration);
         if (ret)
             return ret;
 
         hls->end_pts = pkt->pts;
+        hls->duration = 0;
 
         av_write_frame(oc, NULL); /* Flush any buffered data */
         avio_close(oc->pb);
@@ -300,6 +307,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
     avio_closep(&oc->pb);
     avformat_free_context(oc);
     av_free(hls->basename);
+    append_entry(hls, hls->duration);
     hls_window(s, 1);
 
     free_entries(hls);
@@ -310,10 +318,10 @@ static int hls_write_trailer(struct AVFormatContext *s)
 #define OFFSET(x) offsetof(HLSContext, x)
 #define E AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
-    { "start_number", "set first number in the sequence",        OFFSET(number),  AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
-    { "hls_time",     "set segment length in seconds",           OFFSET(time),    AV_OPT_TYPE_FLOAT,  {.dbl = 2},     0, FLT_MAX, E},
-    { "hls_list_size","set maximum number of playlist entries",  OFFSET(size),    AV_OPT_TYPE_INT,    {.i64 = 5},     0, INT_MAX, E},
-    { "hls_wrap",     "set number after which the index wraps",  OFFSET(wrap),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
+    {"start_number",  "set first number in the sequence",        OFFSET(sequence),AV_OPT_TYPE_INT64,  {.i64 = 0},     0, INT64_MAX, E},
+    {"hls_time",      "set segment length in seconds",           OFFSET(time),    AV_OPT_TYPE_FLOAT,  {.dbl = 2},     0, FLT_MAX, E},
+    {"hls_list_size", "set maximum number of playlist entries",  OFFSET(size),    AV_OPT_TYPE_INT,    {.i64 = 5},     0, INT_MAX, E},
+    {"hls_wrap",      "set number after which the index wraps",  OFFSET(wrap),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
     { NULL },
 };
 
diff --git a/mythtv/external/FFmpeg/libavformat/hlsproto.c b/mythtv/external/FFmpeg/libavformat/hlsproto.c
index 79cf0e498bb..8dedcfd7cad 100644
--- a/mythtv/external/FFmpeg/libavformat/hlsproto.c
+++ b/mythtv/external/FFmpeg/libavformat/hlsproto.c
@@ -71,7 +71,7 @@ typedef struct HLSContext {
 static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
 {
     int len = ff_get_line(s, buf, maxlen);
-    while (len > 0 && isspace(buf[len - 1]))
+    while (len > 0 && av_isspace(buf[len - 1]))
         buf[--len] = '\0';
     return len;
 }
diff --git a/mythtv/external/FFmpeg/libavformat/http.c b/mythtv/external/FFmpeg/libavformat/http.c
index 576875f43a4..1e3cff7947c 100644
--- a/mythtv/external/FFmpeg/libavformat/http.c
+++ b/mythtv/external/FFmpeg/libavformat/http.c
@@ -64,6 +64,7 @@ typedef struct {
     int is_akamai;
     int rw_timeout;
     char *mime_type;
+    char *cookies;          ///< holds newline (\n) delimited Set-Cookie header field values (without the "Set-Cookie: " field name)
 } HTTPContext;
 
 #define OFFSET(x) offsetof(HTTPContext, x)
@@ -71,15 +72,16 @@ typedef struct {
 #define E AV_OPT_FLAG_ENCODING_PARAM
 #define DEC AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
-{"seekable", "Control seekability of connection", OFFSET(seekable), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, D },
+{"seekable", "control seekability of connection", OFFSET(seekable), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, D },
 {"chunked_post", "use chunked transfer-encoding for posts", OFFSET(chunked_post), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E },
-{"headers", "custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
+{"headers", "set custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
 {"content_type", "force a content type", OFFSET(content_type), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
 {"user-agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC},
 {"multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D|E },
-{"post_data", "custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D|E },
-{"timeout", "timeout of socket i/o operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, D|E },
-{"mime_type", "", OFFSET(mime_type), AV_OPT_TYPE_STRING, {0}, 0, 0, 0 },
+{"post_data", "set custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D|E },
+{"timeout", "set timeout of socket I/O operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, D|E },
+{"mime_type", "set MIME type", OFFSET(mime_type), AV_OPT_TYPE_STRING, {0}, 0, 0, 0 },
+{"cookies", "set cookies to be sent in applicable future requests, use newline delimited Set-Cookie HTTP field value syntax", OFFSET(cookies), AV_OPT_TYPE_STRING, {0}, 0, 0, 0 },
 {NULL}
 };
 #define HTTP_CLASS(flavor)\
@@ -118,10 +120,6 @@ static int http_open_cnx(URLContext *h)
     HTTPAuthType cur_auth_type, cur_proxy_auth_type;
     HTTPContext *s = h->priv_data;
 
-    proxy_path = getenv("http_proxy");
-    use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
-        av_strstart(proxy_path, "http://", NULL);
-
     /* fill the dest addr */
  redo:
     /* needed in any case to build the host string */
@@ -130,6 +128,10 @@ static int http_open_cnx(URLContext *h)
                  path1, sizeof(path1), s->location);
     ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);
 
+    proxy_path = getenv("http_proxy");
+    use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), hostname) &&
+                proxy_path != NULL && av_strstart(proxy_path, "http://", NULL);
+
     if (!strcmp(proto, "https")) {
         lower_proto = "tls";
         use_proxy = 0;
@@ -296,9 +298,9 @@ static int process_line(URLContext *h, char *line, int line_count,
 
     p = line;
     if (line_count == 0) {
-        while (!isspace(*p) && *p != '\0')
+        while (!av_isspace(*p) && *p != '\0')
             p++;
-        while (isspace(*p))
+        while (av_isspace(*p))
             p++;
         s->http_code = strtol(p, &end, 10);
 
@@ -323,7 +325,7 @@ static int process_line(URLContext *h, char *line, int line_count,
         *p = '\0';
         tag = line;
         p++;
-        while (isspace(*p))
+        while (av_isspace(*p))
             p++;
         if (!av_strcasecmp(tag, "Location")) {
             av_strlcpy(s->location, p, sizeof(s->location));
@@ -359,11 +361,120 @@ static int process_line(URLContext *h, char *line, int line_count,
             s->is_akamai = 1;
         } else if (!av_strcasecmp (tag, "Content-Type")) {
             av_free(s->mime_type); s->mime_type = av_strdup(p);
+        } else if (!av_strcasecmp (tag, "Set-Cookie")) {
+            if (!s->cookies) {
+                if (!(s->cookies = av_strdup(p)))
+                    return AVERROR(ENOMEM);
+            } else {
+                char *tmp = s->cookies;
+                size_t str_size = strlen(tmp) + strlen(p) + 2;
+                if (!(s->cookies = av_malloc(str_size))) {
+                    s->cookies = tmp;
+                    return AVERROR(ENOMEM);
+                }
+                snprintf(s->cookies, str_size, "%s\n%s", tmp, p);
+                av_free(tmp);
+            }
         }
     }
     return 1;
 }
 
+/**
+ * Create a string containing cookie values for use as a HTTP cookie header
+ * field value for a particular path and domain from the cookie values stored in
+ * the HTTP protocol context. The cookie string is stored in *cookies.
+ *
+ * @return a negative value if an error condition occurred, 0 otherwise
+ */
+static int get_cookies(HTTPContext *s, char **cookies, const char *path,
+                       const char *domain)
+{
+    // cookie strings will look like Set-Cookie header field values.  Multiple
+    // Set-Cookie fields will result in multiple values delimited by a newline
+    int ret = 0;
+    char *next, *cookie, *set_cookies = av_strdup(s->cookies), *cset_cookies = set_cookies;
+
+    if (!set_cookies) return AVERROR(EINVAL);
+
+    *cookies = NULL;
+    while ((cookie = av_strtok(set_cookies, "\n", &next))) {
+        int domain_offset = 0;
+        char *param, *next_param, *cdomain = NULL, *cpath = NULL, *cvalue = NULL;
+        set_cookies = NULL;
+
+        while ((param = av_strtok(cookie, "; ", &next_param))) {
+            cookie = NULL;
+            if        (!av_strncasecmp("path=",   param, 5)) {
+                av_free(cpath);
+                cpath = av_strdup(¶m[5]);
+            } else if (!av_strncasecmp("domain=", param, 7)) {
+                av_free(cdomain);
+                cdomain = av_strdup(¶m[7]);
+            } else if (!av_strncasecmp("secure",  param, 6) ||
+                       !av_strncasecmp("comment", param, 7) ||
+                       !av_strncasecmp("max-age", param, 7) ||
+                       !av_strncasecmp("version", param, 7)) {
+                // ignore Comment, Max-Age, Secure and Version
+            } else {
+                av_free(cvalue);
+                cvalue = av_strdup(param);
+            }
+        }
+
+        // ensure all of the necessary values are valid
+        if (!cdomain || !cpath || !cvalue) {
+            av_log(s, AV_LOG_WARNING,
+                   "Invalid cookie found, no value, path or domain specified\n");
+            goto done_cookie;
+        }
+
+        // check if the request path matches the cookie path
+        if (av_strncasecmp(path, cpath, strlen(cpath)))
+            goto done_cookie;
+
+        // the domain should be at least the size of our cookie domain
+        domain_offset = strlen(domain) - strlen(cdomain);
+        if (domain_offset < 0)
+            goto done_cookie;
+
+        // match the cookie domain
+        if (av_strcasecmp(&domain[domain_offset], cdomain))
+            goto done_cookie;
+
+        // cookie parameters match, so copy the value
+        if (!*cookies) {
+            if (!(*cookies = av_strdup(cvalue))) {
+                ret = AVERROR(ENOMEM);
+                goto done_cookie;
+            }
+        } else {
+            char *tmp = *cookies;
+            size_t str_size = strlen(cvalue) + strlen(*cookies) + 3;
+            if (!(*cookies = av_malloc(str_size))) {
+                ret = AVERROR(ENOMEM);
+                goto done_cookie;
+            }
+            snprintf(*cookies, str_size, "%s; %s", tmp, cvalue);
+            av_free(tmp);
+        }
+
+        done_cookie:
+        av_free(cdomain);
+        av_free(cpath);
+        av_free(cvalue);
+        if (ret < 0) {
+            if (*cookies) av_freep(cookies);
+            av_free(cset_cookies);
+            return ret;
+        }
+    }
+
+    av_free(cset_cookies);
+
+    return 0;
+}
+
 static inline int has_header(const char *str, const char *header)
 {
     /* header + 2 to skip over CRLF prefix. (make sure you have one!) */
@@ -460,6 +571,14 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
     if (!has_header(s->headers, "\r\nContent-Type: ") && s->content_type)
         len += av_strlcatf(headers + len, sizeof(headers) - len,
                            "Content-Type: %s\r\n", s->content_type);
+    if (!has_header(s->headers, "\r\nCookie: ") && s->cookies) {
+        char *cookies = NULL;
+        if (!get_cookies(s, &cookies, path, hoststr)) {
+            len += av_strlcatf(headers + len, sizeof(headers) - len,
+                               "Cookie: %s\r\n", cookies);
+            av_free(cookies);
+        }
+    }
 
     /* now add in custom headers */
     if (s->headers)
diff --git a/mythtv/external/FFmpeg/libavformat/httpauth.c b/mythtv/external/FFmpeg/libavformat/httpauth.c
index e97aee1f665..5ca48b9c1de 100644
--- a/mythtv/external/FFmpeg/libavformat/httpauth.c
+++ b/mythtv/external/FFmpeg/libavformat/httpauth.c
@@ -27,7 +27,6 @@
 #include "libavutil/md5.h"
 #include "urldecode.h"
 #include "avformat.h"
-#include 
 
 static void handle_basic_params(HTTPAuthState *state, const char *key,
                                 int key_len, char **dest, int *dest_len)
@@ -80,8 +79,8 @@ static void choose_qop(char *qop, int size)
     char *ptr = strstr(qop, "auth");
     char *end = ptr + strlen("auth");
 
-    if (ptr && (!*end || isspace(*end) || *end == ',') &&
-        (ptr == qop || isspace(ptr[-1]) || ptr[-1] == ',')) {
+    if (ptr && (!*end || av_isspace(*end) || *end == ',') &&
+        (ptr == qop || av_isspace(ptr[-1]) || ptr[-1] == ',')) {
         av_strlcpy(qop, "auth", size);
     } else {
         qop[0] = 0;
diff --git a/mythtv/external/FFmpeg/libavformat/id3v2.c b/mythtv/external/FFmpeg/libavformat/id3v2.c
index f805f5bac22..2cab5ac3045 100644
--- a/mythtv/external/FFmpeg/libavformat/id3v2.c
+++ b/mythtv/external/FFmpeg/libavformat/id3v2.c
@@ -788,10 +788,12 @@ void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra
         /* save the current offset in case there's nothing to read/skip */
         off = avio_tell(s->pb);
         ret = avio_read(s->pb, buf, ID3v2_HEADER_SIZE);
-        if (ret != ID3v2_HEADER_SIZE)
+        if (ret != ID3v2_HEADER_SIZE) {
+            avio_seek(s->pb, off, SEEK_SET);
             break;
-            found_header = ff_id3v2_match(buf, magic);
-            if (found_header) {
+        }
+        found_header = ff_id3v2_match(buf, magic);
+        if (found_header) {
             /* parse ID3v2 header */
             len = ((buf[6] & 0x7f) << 21) |
                   ((buf[7] & 0x7f) << 14) |
diff --git a/mythtv/external/FFmpeg/libavformat/idcin.c b/mythtv/external/FFmpeg/libavformat/idcin.c
index bede04075e0..c32607def23 100644
--- a/mythtv/external/FFmpeg/libavformat/idcin.c
+++ b/mythtv/external/FFmpeg/libavformat/idcin.c
@@ -68,6 +68,8 @@
  *       transmitting them to the video decoder
  */
 
+#include "libavutil/audioconvert.h"
+#include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "internal.h"
@@ -80,13 +82,13 @@ typedef struct IdcinDemuxContext {
     int audio_stream_index;
     int audio_chunk_size1;
     int audio_chunk_size2;
+    int block_align;
 
     /* demux state variables */
     int current_audio_chunk;
     int next_chunk_is_video;
     int audio_present;
-
-    int64_t pts;
+    int64_t first_pkt_pos;
 } IdcinDemuxContext;
 
 static int idcin_probe(AVProbeData *p)
@@ -145,6 +147,7 @@ static int idcin_read_header(AVFormatContext *s)
     AVStream *st;
     unsigned int width, height;
     unsigned int sample_rate, bytes_per_sample, channels;
+    int ret;
 
     /* get the 5 header parameters */
     width = avio_rl32(pb);
@@ -153,10 +156,38 @@ static int idcin_read_header(AVFormatContext *s)
     bytes_per_sample = avio_rl32(pb);
     channels = avio_rl32(pb);
 
+    if (s->pb->eof_reached) {
+        av_log(s, AV_LOG_ERROR, "incomplete header\n");
+        return s->pb->error ? s->pb->error : AVERROR_EOF;
+    }
+
+    if (av_image_check_size(width, height, 0, s) < 0)
+        return AVERROR_INVALIDDATA;
+    if (sample_rate > 0) {
+        if (sample_rate < 14 || sample_rate > INT_MAX) {
+            av_log(s, AV_LOG_ERROR, "invalid sample rate: %u\n", sample_rate);
+            return AVERROR_INVALIDDATA;
+        }
+        if (bytes_per_sample < 1 || bytes_per_sample > 2) {
+            av_log(s, AV_LOG_ERROR, "invalid bytes per sample: %u\n",
+                   bytes_per_sample);
+            return AVERROR_INVALIDDATA;
+        }
+        if (channels < 1 || channels > 2) {
+            av_log(s, AV_LOG_ERROR, "invalid channels: %u\n", channels);
+            return AVERROR_INVALIDDATA;
+        }
+        idcin->audio_present = 1;
+    } else {
+        /* if sample rate is 0, assume no audio */
+        idcin->audio_present = 0;
+    }
+
     st = avformat_new_stream(s, NULL);
     if (!st)
         return AVERROR(ENOMEM);
     avpriv_set_pts_info(st, 33, 1, IDCIN_FPS);
+    st->start_time = 0;
     idcin->video_stream_index = st->index;
     st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
     st->codec->codec_id = AV_CODEC_ID_IDCIN;
@@ -167,25 +198,31 @@ static int idcin_read_header(AVFormatContext *s)
     /* load up the Huffman tables into extradata */
     st->codec->extradata_size = HUFFMAN_TABLE_SIZE;
     st->codec->extradata = av_malloc(HUFFMAN_TABLE_SIZE);
-    if (avio_read(pb, st->codec->extradata, HUFFMAN_TABLE_SIZE) !=
-        HUFFMAN_TABLE_SIZE)
+    ret = avio_read(pb, st->codec->extradata, HUFFMAN_TABLE_SIZE);
+    if (ret < 0) {
+        return ret;
+    } else if (ret != HUFFMAN_TABLE_SIZE) {
+        av_log(s, AV_LOG_ERROR, "incomplete header\n");
         return AVERROR(EIO);
+    }
 
-    /* if sample rate is 0, assume no audio */
-    if (sample_rate) {
+    if (idcin->audio_present) {
         idcin->audio_present = 1;
         st = avformat_new_stream(s, NULL);
         if (!st)
             return AVERROR(ENOMEM);
-        avpriv_set_pts_info(st, 33, 1, IDCIN_FPS);
+        avpriv_set_pts_info(st, 63, 1, sample_rate);
+        st->start_time = 0;
         idcin->audio_stream_index = st->index;
         st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
         st->codec->codec_tag = 1;
         st->codec->channels = channels;
+        st->codec->channel_layout = channels > 1 ? AV_CH_LAYOUT_STEREO :
+                                                   AV_CH_LAYOUT_MONO;
         st->codec->sample_rate = sample_rate;
         st->codec->bits_per_coded_sample = bytes_per_sample * 8;
         st->codec->bit_rate = sample_rate * bytes_per_sample * 8 * channels;
-        st->codec->block_align = bytes_per_sample * channels;
+        st->codec->block_align = idcin->block_align = bytes_per_sample * channels;
         if (bytes_per_sample == 1)
             st->codec->codec_id = AV_CODEC_ID_PCM_U8;
         else
@@ -201,11 +238,10 @@ static int idcin_read_header(AVFormatContext *s)
                 (sample_rate / 14) * bytes_per_sample * channels;
         }
         idcin->current_audio_chunk = 0;
-    } else
-        idcin->audio_present = 1;
+    }
 
     idcin->next_chunk_is_video = 1;
-    idcin->pts = 0;
+    idcin->first_pkt_pos = avio_tell(s->pb);
 
     return 0;
 }
@@ -225,7 +261,7 @@ static int idcin_read_packet(AVFormatContext *s,
     uint32_t palette[256];
 
     if (url_feof(s->pb))
-        return AVERROR(EIO);
+        return s->pb->error ? s->pb->error : AVERROR_EOF;
 
     if (idcin->next_chunk_is_video) {
         command = avio_rl32(pb);
@@ -233,8 +269,13 @@ static int idcin_read_packet(AVFormatContext *s,
             return AVERROR(EIO);
         } else if (command == 1) {
             /* trigger a palette change */
-            if (avio_read(pb, palette_buffer, 768) != 768)
+            ret = avio_read(pb, palette_buffer, 768);
+            if (ret < 0) {
+                return ret;
+            } else if (ret != 768) {
+                av_log(s, AV_LOG_ERROR, "incomplete packet\n");
                 return AVERROR(EIO);
+            }
             /* scale the palette as necessary */
             palette_scale = 2;
             for (i = 0; i < 768; i++)
@@ -253,7 +294,15 @@ static int idcin_read_packet(AVFormatContext *s,
             }
         }
 
+        if (s->pb->eof_reached) {
+            av_log(s, AV_LOG_ERROR, "incomplete packet\n");
+            return s->pb->error ? s->pb->error : AVERROR_EOF;
+        }
         chunk_size = avio_rl32(pb);
+        if (chunk_size < 4 || chunk_size > INT_MAX - 4) {
+            av_log(s, AV_LOG_ERROR, "invalid chunk size: %u\n", chunk_size);
+            return AVERROR_INVALIDDATA;
+        }
         /* skip the number of decoded bytes (always equal to width * height) */
         avio_skip(pb, 4);
         if (chunk_size < 4)
@@ -262,17 +311,25 @@ static int idcin_read_packet(AVFormatContext *s,
         ret= av_get_packet(pb, pkt, chunk_size);
         if (ret < 0)
             return ret;
+        else if (ret != chunk_size) {
+            av_log(s, AV_LOG_ERROR, "incomplete packet\n");
+            av_free_packet(pkt);
+            return AVERROR(EIO);
+        }
         if (command == 1) {
             uint8_t *pal;
 
             pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE,
                                           AVPALETTE_SIZE);
-            if (!pal)
+            if (!pal) {
+                av_free_packet(pkt);
                 return AVERROR(ENOMEM);
+            }
             memcpy(pal, palette, AVPALETTE_SIZE);
+            pkt->flags |= AV_PKT_FLAG_KEY;
         }
         pkt->stream_index = idcin->video_stream_index;
-        pkt->pts = idcin->pts;
+        pkt->duration     = 1;
     } else {
         /* send out the audio chunk */
         if (idcin->current_audio_chunk)
@@ -283,16 +340,32 @@ static int idcin_read_packet(AVFormatContext *s,
         if (ret < 0)
             return ret;
         pkt->stream_index = idcin->audio_stream_index;
-        pkt->pts = idcin->pts;
+        pkt->duration     = chunk_size / idcin->block_align;
 
         idcin->current_audio_chunk ^= 1;
-        idcin->pts++;
     }
 
     if (idcin->audio_present)
         idcin->next_chunk_is_video ^= 1;
 
-    return ret;
+    return 0;
+}
+
+static int idcin_read_seek(AVFormatContext *s, int stream_index,
+                           int64_t timestamp, int flags)
+{
+    IdcinDemuxContext *idcin = s->priv_data;
+
+    if (idcin->first_pkt_pos > 0) {
+        int ret = avio_seek(s->pb, idcin->first_pkt_pos, SEEK_SET);
+        if (ret < 0)
+            return ret;
+        ff_update_cur_dts(s, s->streams[idcin->video_stream_index], 0);
+        idcin->next_chunk_is_video = 1;
+        idcin->current_audio_chunk = 0;
+        return 0;
+    }
+    return -1;
 }
 
 AVInputFormat ff_idcin_demuxer = {
@@ -302,4 +375,6 @@ AVInputFormat ff_idcin_demuxer = {
     .read_probe     = idcin_probe,
     .read_header    = idcin_read_header,
     .read_packet    = idcin_read_packet,
+    .read_seek      = idcin_read_seek,
+    .flags          = AVFMT_NO_BYTE_SEEK,
 };
diff --git a/mythtv/external/FFmpeg/libavformat/iff.c b/mythtv/external/FFmpeg/libavformat/iff.c
index ffd9231fc9b..100d981cab3 100644
--- a/mythtv/external/FFmpeg/libavformat/iff.c
+++ b/mythtv/external/FFmpeg/libavformat/iff.c
@@ -93,9 +93,9 @@ typedef enum {
 } svx8_compression_type;
 
 typedef struct {
-    uint64_t  body_pos;
+    int64_t  body_pos;
+    int64_t  body_end;
     uint32_t  body_size;
-    uint32_t  sent_bytes;
     svx8_compression_type   svx8_compression;
     unsigned  maud_bits;
     unsigned  maud_compression;
@@ -227,6 +227,7 @@ static int iff_read_header(AVFormatContext *s)
         case ID_DBOD:
         case ID_MDAT:
             iff->body_pos = avio_tell(pb);
+            iff->body_end = iff->body_pos + data_size;
             iff->body_size = data_size;
             break;
 
@@ -437,14 +438,14 @@ static int iff_read_packet(AVFormatContext *s,
     AVIOContext *pb = s->pb;
     AVStream *st = s->streams[0];
     int ret;
+    int64_t pos = avio_tell(pb);
 
-    if(iff->sent_bytes >= iff->body_size)
+    if (pos >= iff->body_end)
         return AVERROR_EOF;
 
     if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
         if (st->codec->codec_tag == ID_MAUD) {
-            ret = av_get_packet(pb, pkt,
-                                FFMIN(iff->body_size - iff->sent_bytes, 1024 * st->codec->block_align));
+            ret = av_get_packet(pb, pkt, FFMIN(iff->body_end - pos, 1024 * st->codec->block_align));
         } else {
             ret = av_get_packet(pb, pkt, iff->body_size);
         }
@@ -462,11 +463,10 @@ static int iff_read_packet(AVFormatContext *s,
         av_assert0(0);
     }
 
-    if(iff->sent_bytes == 0)
+    if (pos == iff->body_pos)
         pkt->flags |= AV_PKT_FLAG_KEY;
     if (ret < 0)
         return ret;
-    iff->sent_bytes += ret;
     pkt->stream_index = 0;
     return ret;
 }
@@ -478,4 +478,5 @@ AVInputFormat ff_iff_demuxer = {
     .read_probe     = iff_probe,
     .read_header    = iff_read_header,
     .read_packet    = iff_read_packet,
+    .flags          = AVFMT_GENERIC_INDEX,
 };
diff --git a/mythtv/external/FFmpeg/libavformat/img2dec.c b/mythtv/external/FFmpeg/libavformat/img2dec.c
index f492bba8299..882abb98589 100644
--- a/mythtv/external/FFmpeg/libavformat/img2dec.c
+++ b/mythtv/external/FFmpeg/libavformat/img2dec.c
@@ -46,6 +46,7 @@ typedef struct {
     int img_first;
     int img_last;
     int img_number;
+    int64_t pts;
     int img_count;
     int is_pipe;
     int split_planes;       /**< use independent file for each Y, U, V plane */
@@ -393,6 +394,8 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
         return AVERROR(ENOMEM);
     pkt->stream_index = 0;
     pkt->flags       |= AV_PKT_FLAG_KEY;
+    if (!s->is_pipe)
+        pkt->pts      = s->pts;
 
     pkt->size = 0;
     for (i = 0; i < 3; i++) {
@@ -411,6 +414,7 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
     } else {
         s->img_count++;
         s->img_number++;
+        s->pts++;
         return 0;
     }
 }
@@ -426,6 +430,17 @@ static int img_read_close(struct AVFormatContext* s1)
     return 0;
 }
 
+static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
+{
+    VideoDemuxData *s1 = s->priv_data;
+
+    if (timestamp < 0 || !s1->loop && timestamp > s1->img_last - s1->img_first)
+        return -1;
+    s1->img_number = timestamp%(s1->img_last - s1->img_first + 1) + s1->img_first;
+    s1->pts = timestamp;
+    return 0;
+}
+
 #define OFFSET(x) offsetof(VideoDemuxData, x)
 #define DEC AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
@@ -433,9 +448,9 @@ static const AVOption options[] = {
     { "loop",         "force loop over input file sequence", OFFSET(loop),         AV_OPT_TYPE_INT,    {.i64 = 0   }, 0, 1,       DEC },
 
     { "pattern_type", "set pattern type",                    OFFSET(pattern_type), AV_OPT_TYPE_INT,    {.i64=PT_GLOB_SEQUENCE}, 0,       INT_MAX, DEC, "pattern_type"},
-    { "glob_sequence","glob/sequence pattern type",          0,                    AV_OPT_TYPE_CONST,  {.i64=PT_GLOB_SEQUENCE}, INT_MIN, INT_MAX, DEC, "pattern_type" },
-    { "glob",         "glob pattern type",                   0,                    AV_OPT_TYPE_CONST,  {.i64=PT_GLOB         }, INT_MIN, INT_MAX, DEC, "pattern_type" },
-    { "sequence",     "glob pattern type",                   0,                    AV_OPT_TYPE_CONST,  {.i64=PT_SEQUENCE     }, INT_MIN, INT_MAX, DEC, "pattern_type" },
+    { "glob_sequence","select glob/sequence pattern type",   0, AV_OPT_TYPE_CONST,  {.i64=PT_GLOB_SEQUENCE}, INT_MIN, INT_MAX, DEC, "pattern_type" },
+    { "glob",         "select glob pattern type",            0, AV_OPT_TYPE_CONST,  {.i64=PT_GLOB         }, INT_MIN, INT_MAX, DEC, "pattern_type" },
+    { "sequence",     "select sequence pattern type",        0, AV_OPT_TYPE_CONST,  {.i64=PT_SEQUENCE     }, INT_MIN, INT_MAX, DEC, "pattern_type" },
 
     { "pixel_format", "set video pixel format",              OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0,       DEC },
     { "start_number", "set first number in the sequence",    OFFSET(start_number), AV_OPT_TYPE_INT,    {.i64 = 0   }, 0, INT_MAX, DEC },
@@ -460,6 +475,7 @@ AVInputFormat ff_image2_demuxer = {
     .read_header    = img_read_header,
     .read_packet    = img_read_packet,
     .read_close     = img_read_close,
+    .read_seek      = img_read_seek,
     .flags          = AVFMT_NOFILE,
     .priv_class     = &img2_class,
 };
diff --git a/mythtv/external/FFmpeg/libavformat/img2enc.c b/mythtv/external/FFmpeg/libavformat/img2enc.c
index 0e362f81d4a..67b5819dc93 100644
--- a/mythtv/external/FFmpeg/libavformat/img2enc.c
+++ b/mythtv/external/FFmpeg/libavformat/img2enc.c
@@ -128,8 +128,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
 #define OFFSET(x) offsetof(VideoMuxData, x)
 #define ENC AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption muxoptions[] = {
-    { "updatefirst",  "",                            OFFSET(updatefirst), AV_OPT_TYPE_INT, { .i64 = 0 }, 0,       1, ENC },
-    { "start_number", "first number in the sequence", OFFSET(img_number), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, INT_MAX, ENC },
+    { "updatefirst",  "update the first image file",      OFFSET(updatefirst), AV_OPT_TYPE_INT, { .i64 = 0 }, 0,       1, ENC },
+    { "start_number", "set first number in the sequence", OFFSET(img_number), AV_OPT_TYPE_INT,  { .i64 = 1 }, 1, INT_MAX, ENC },
     { NULL },
 };
 
diff --git a/mythtv/external/FFmpeg/libavformat/internal.h b/mythtv/external/FFmpeg/libavformat/internal.h
index d1bbf336039..4d563883128 100644
--- a/mythtv/external/FFmpeg/libavformat/internal.h
+++ b/mythtv/external/FFmpeg/libavformat/internal.h
@@ -390,4 +390,6 @@ AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precissi
  */
 void ff_generate_avci_extradata(AVStream *st);
 
+int ff_http_match_no_proxy(const char *no_proxy, const char *hostname);
+
 #endif /* AVFORMAT_INTERNAL_H */
diff --git a/mythtv/external/FFmpeg/libavformat/isom.c b/mythtv/external/FFmpeg/libavformat/isom.c
index 3b609db00a9..3f419a83dd3 100644
--- a/mythtv/external/FFmpeg/libavformat/isom.c
+++ b/mythtv/external/FFmpeg/libavformat/isom.c
@@ -294,6 +294,8 @@ const AVCodecTag ff_codec_movaudio_tags[] = {
     { AV_CODEC_ID_QDMC,            MKTAG('Q', 'D', 'M', 'C') },
     { AV_CODEC_ID_SPEEX,           MKTAG('s', 'p', 'e', 'x') }, /* Flash Media Server */
     { AV_CODEC_ID_WMAV2,           MKTAG('W', 'M', 'A', '2') },
+    { AV_CODEC_ID_EVRC,            MKTAG('s', 'e', 'v', 'c') }, /* 3GPP2 */
+    { AV_CODEC_ID_SMV,             MKTAG('s', 's', 'm', 'v') }, /* 3GPP2 */
     { AV_CODEC_ID_NONE, 0 },
 };
 
diff --git a/mythtv/external/FFmpeg/libavformat/isom.h b/mythtv/external/FFmpeg/libavformat/isom.h
index 032b5b91b87..0bd49bf6ae8 100644
--- a/mythtv/external/FFmpeg/libavformat/isom.h
+++ b/mythtv/external/FFmpeg/libavformat/isom.h
@@ -94,6 +94,7 @@ typedef struct MOVSbgp {
 
 typedef struct MOVStreamContext {
     AVIOContext *pb;
+    int pb_is_copied;
     int ffindex;          ///< AVStream index
     int next_chunk;
     unsigned int chunk_count;
diff --git a/mythtv/external/FFmpeg/libavformat/libavformat.v b/mythtv/external/FFmpeg/libavformat/libavformat.v
index a5e7d63f983..3a2ba30dd28 100644
--- a/mythtv/external/FFmpeg/libavformat/libavformat.v
+++ b/mythtv/external/FFmpeg/libavformat/libavformat.v
@@ -25,11 +25,7 @@ LIBAVFORMAT_$MAJOR {
                 url_open;
                 url_close;
                 url_write;
-                url_get_max_packet_size;
                 #those are deprecated, remove on next bump
-                find_info_tag;
-                parse_date;
-                dump_format;
                 url_*;
                 ff_timefilter_destroy;
                 ff_timefilter_new;
@@ -37,10 +33,7 @@ LIBAVFORMAT_$MAJOR {
                 ff_timefilter_reset;
                 get_*;
                 put_*;
-                udp_set_remote_url;
-                udp_get_local_port;
-                init_checksum;
-                init_put_byte;
+                ff_codec_get_id;
 		ff_read_frame_flush;
         local: *;
 };
diff --git a/mythtv/external/FFmpeg/libavformat/matroska.c b/mythtv/external/FFmpeg/libavformat/matroska.c
index 1e92073921a..09eecf20f63 100644
--- a/mythtv/external/FFmpeg/libavformat/matroska.c
+++ b/mythtv/external/FFmpeg/libavformat/matroska.c
@@ -35,6 +35,7 @@ const CodecTags ff_mkv_codec_tags[]={
     {"A_MPEG/L2"        , AV_CODEC_ID_MP2},
     {"A_MPEG/L1"        , AV_CODEC_ID_MP2},
     {"A_MPEG/L3"        , AV_CODEC_ID_MP3},
+    {"A_OPUS/EXPERIMENTAL",AV_CODEC_ID_OPUS},
     {"A_OPUS",            AV_CODEC_ID_OPUS},
     {"A_PCM/FLOAT/IEEE" , AV_CODEC_ID_PCM_F32LE},
     {"A_PCM/FLOAT/IEEE" , AV_CODEC_ID_PCM_F64LE},
@@ -65,6 +66,7 @@ const CodecTags ff_mkv_codec_tags[]={
     {"S_ASS"            , AV_CODEC_ID_SSA},
     {"S_SSA"            , AV_CODEC_ID_SSA},
     {"S_VOBSUB"         , AV_CODEC_ID_DVD_SUBTITLE},
+    {"S_DVBSUB"         , AV_CODEC_ID_DVB_SUBTITLE},
     {"S_HDMV/PGS"       , AV_CODEC_ID_HDMV_PGS_SUBTITLE},
 
     {"V_DIRAC"          , AV_CODEC_ID_DIRAC},
@@ -85,6 +87,7 @@ const CodecTags ff_mkv_codec_tags[]={
     {"V_THEORA"         , AV_CODEC_ID_THEORA},
     {"V_UNCOMPRESSED"   , AV_CODEC_ID_RAWVIDEO},
     {"V_VP8"            , AV_CODEC_ID_VP8},
+    {"V_VP9"            , AV_CODEC_ID_VP9},
 
     {""                 , AV_CODEC_ID_NONE}
 };
diff --git a/mythtv/external/FFmpeg/libavformat/matroska.h b/mythtv/external/FFmpeg/libavformat/matroska.h
index 8411633f0a7..8e6f8cc3391 100644
--- a/mythtv/external/FFmpeg/libavformat/matroska.h
+++ b/mythtv/external/FFmpeg/libavformat/matroska.h
@@ -118,6 +118,7 @@
 #define MATROSKA_ID_VIDEODISPLAYUNIT 0x54B2
 #define MATROSKA_ID_VIDEOFLAGINTERLACED 0x9A
 #define MATROSKA_ID_VIDEOSTEREOMODE 0x53B8
+#define MATROSKA_ID_VIDEOALPHAMODE 0x53C0
 #define MATROSKA_ID_VIDEOASPECTRATIO 0x54B3
 #define MATROSKA_ID_VIDEOCOLORSPACE 0x2EB524
 
@@ -175,6 +176,10 @@
 #define MATROSKA_ID_CLUSTERPOSITION 0xA7
 #define MATROSKA_ID_CLUSTERPREVSIZE 0xAB
 #define MATROSKA_ID_BLOCKGROUP 0xA0
+#define MATROSKA_ID_BLOCKADDITIONS 0x75A1
+#define MATROSKA_ID_BLOCKMORE 0xA6
+#define MATROSKA_ID_BLOCKADDID 0xEE
+#define MATROSKA_ID_BLOCKADDITIONAL 0xA5
 #define MATROSKA_ID_SIMPLEBLOCK 0xA3
 
 /* IDs in the blockgroup master */
diff --git a/mythtv/external/FFmpeg/libavformat/matroskadec.c b/mythtv/external/FFmpeg/libavformat/matroskadec.c
index 87c4a39d0e9..f8cd81f2ba7 100644
--- a/mythtv/external/FFmpeg/libavformat/matroskadec.c
+++ b/mythtv/external/FFmpeg/libavformat/matroskadec.c
@@ -115,6 +115,7 @@ typedef struct {
     uint64_t pixel_height;
     EbmlBin color_space;
     uint64_t stereo_mode;
+    uint64_t alpha_mode;
 } MatroskaTrackVideo;
 
 typedef struct {
@@ -163,6 +164,7 @@ typedef struct {
     AVStream *stream;
     int64_t end_timecode;
     int ms_compat;
+    uint64_t max_block_additional_id;
 } MatroskaTrack;
 
 typedef struct {
@@ -279,6 +281,8 @@ typedef struct {
     int64_t  reference;
     uint64_t non_simple;
     EbmlBin  bin;
+    uint64_t additional_id;
+    EbmlBin  additional;
 } MatroskaBlock;
 
 static EbmlSyntax ebml_header[] = {
@@ -316,6 +320,7 @@ static EbmlSyntax matroska_track_video[] = {
     { MATROSKA_ID_VIDEOPIXELHEIGHT,   EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_height) },
     { MATROSKA_ID_VIDEOCOLORSPACE,    EBML_BIN,  0, offsetof(MatroskaTrackVideo,color_space) },
     { MATROSKA_ID_VIDEOSTEREOMODE,    EBML_UINT, 0, offsetof(MatroskaTrackVideo,stereo_mode) },
+    { MATROSKA_ID_VIDEOALPHAMODE,     EBML_UINT, 0, offsetof(MatroskaTrackVideo,alpha_mode) },
     { MATROSKA_ID_VIDEOPIXELCROPB,    EBML_NONE },
     { MATROSKA_ID_VIDEOPIXELCROPT,    EBML_NONE },
     { MATROSKA_ID_VIDEOPIXELCROPL,    EBML_NONE },
@@ -385,6 +390,7 @@ static EbmlSyntax matroska_track[] = {
     { MATROSKA_ID_TRACKAUDIO,           EBML_NEST, 0, offsetof(MatroskaTrack,audio), {.n=matroska_track_audio} },
     { MATROSKA_ID_TRACKOPERATION,       EBML_NEST, 0, offsetof(MatroskaTrack,operation), {.n=matroska_track_operation} },
     { MATROSKA_ID_TRACKCONTENTENCODINGS,EBML_NEST, 0, 0, {.n=matroska_track_encodings} },
+    { MATROSKA_ID_TRACKMAXBLKADDID,     EBML_UINT, 0, offsetof(MatroskaTrack,max_block_additional_id) },
     { MATROSKA_ID_TRACKFLAGENABLED,     EBML_NONE },
     { MATROSKA_ID_TRACKFLAGLACING,      EBML_NONE },
     { MATROSKA_ID_CODECNAME,            EBML_NONE },
@@ -393,7 +399,6 @@ static EbmlSyntax matroska_track[] = {
     { MATROSKA_ID_CODECDOWNLOADURL,     EBML_NONE },
     { MATROSKA_ID_TRACKMINCACHE,        EBML_NONE },
     { MATROSKA_ID_TRACKMAXCACHE,        EBML_NONE },
-    { MATROSKA_ID_TRACKMAXBLKADDID,     EBML_NONE },
     { 0 }
 };
 
@@ -524,8 +529,20 @@ static EbmlSyntax matroska_segments[] = {
     { 0 }
 };
 
+static EbmlSyntax matroska_blockmore[] = {
+    { MATROSKA_ID_BLOCKADDID,      EBML_UINT, 0, offsetof(MatroskaBlock,additional_id) },
+    { MATROSKA_ID_BLOCKADDITIONAL, EBML_BIN,  0, offsetof(MatroskaBlock,additional) },
+    { 0 }
+};
+
+static EbmlSyntax matroska_blockadditions[] = {
+    { MATROSKA_ID_BLOCKMORE, EBML_NEST, 0, 0, {.n=matroska_blockmore} },
+    { 0 }
+};
+
 static EbmlSyntax matroska_blockgroup[] = {
     { MATROSKA_ID_BLOCK,          EBML_BIN,  0, offsetof(MatroskaBlock,bin) },
+    { MATROSKA_ID_BLOCKADDITIONS, EBML_NEST, 0, 0, {.n=matroska_blockadditions} },
     { MATROSKA_ID_SIMPLEBLOCK,    EBML_BIN,  0, offsetof(MatroskaBlock,bin) },
     { MATROSKA_ID_BLOCKDURATION,  EBML_UINT, 0, offsetof(MatroskaBlock,duration) },
     { MATROSKA_ID_BLOCKREFERENCE, EBML_UINT, 0, offsetof(MatroskaBlock,reference) },
@@ -1770,6 +1787,10 @@ static int matroska_read_header(AVFormatContext *s)
             if (track->video.stereo_mode && track->video.stereo_mode < MATROSKA_VIDEO_STEREO_MODE_COUNT)
                 av_dict_set(&st->metadata, "stereo_mode", ff_matroska_video_stereo_mode[track->video.stereo_mode], 0);
 
+            /* export alpha mode flag as metadata tag  */
+            if (track->video.alpha_mode)
+                av_dict_set(&st->metadata, "alpha_mode", "1", 0);
+
             /* if we have virtual track, mark the real tracks */
             for (j=0; j < track->operation.combine_planes.nb_elem; j++) {
                 char buf[32];
@@ -1788,6 +1809,7 @@ static int matroska_read_header(AVFormatContext *s)
             st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
             st->codec->sample_rate = track->audio.out_samplerate;
             st->codec->channels = track->audio.channels;
+            st->codec->bits_per_coded_sample = track->audio.bitdepth;
             if (st->codec->codec_id != AV_CODEC_ID_AAC)
             st->need_parsing = AVSTREAM_PARSE_HEADERS;
         } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
@@ -1894,10 +1916,10 @@ static void matroska_clear_queue(MatroskaDemuxContext *matroska)
 }
 
 static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
-                                int size, int type,
+                                int* buf_size, int type,
                                 uint32_t **lace_buf, int *laces)
 {
-    int res = 0, n;
+    int res = 0, n, size = *buf_size;
     uint8_t *data = *buf;
     uint32_t *lace_size;
 
@@ -1995,6 +2017,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
 
     *buf      = data;
     *lace_buf = lace_size;
+    *buf_size = size;
 
     return res;
 }
@@ -2073,7 +2096,8 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska,
                                 AVStream *st,
                                 uint8_t *data, int pkt_size,
                                 uint64_t timecode, uint64_t lace_duration,
-                                int64_t pos, int is_keyframe)
+                                int64_t pos, int is_keyframe,
+                                uint8_t *additional, uint64_t additional_id, int additional_size)
 {
     MatroskaTrackEncoding *encodings = track->encodings.elem;
     uint8_t *pkt_data = data;
@@ -2110,6 +2134,17 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska,
     pkt->flags = is_keyframe;
     pkt->stream_index = st->index;
 
+    if (additional_size > 0) {
+        uint8_t *side_data = av_packet_new_side_data(pkt,
+                                                     AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,
+                                                     additional_size + 8);
+        if(side_data == NULL) {
+            return AVERROR(ENOMEM);
+        }
+        AV_WB64(side_data, additional_id);
+        memcpy(side_data + 8, additional, additional_size);
+    }
+
     if (track->ms_compat)
         pkt->dts = timecode;
     else
@@ -2159,6 +2194,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska,
 static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
                                 int size, int64_t pos, uint64_t cluster_time,
                                 uint64_t block_duration, int is_keyframe,
+                                uint8_t *additional, uint64_t additional_id, int additional_size,
                                 int64_t cluster_pos)
 {
     uint64_t timecode = AV_NOPTS_VALUE;
@@ -2217,7 +2253,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
             matroska->skip_to_keyframe = 0;
     }
 
-    res = matroska_parse_laces(matroska, &data, size, (flags & 0x06) >> 1,
+    res = matroska_parse_laces(matroska, &data, &size, (flags & 0x06) >> 1,
                                &lace_size, &laces);
 
     if (res)
@@ -2252,7 +2288,8 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
         } else {
             res = matroska_parse_frame(matroska, track, st, data, lace_size[n],
                                       timecode, lace_duration,
-                                      pos, !n? is_keyframe : 0);
+                                      pos, !n? is_keyframe : 0,
+                                      additional, additional_id, additional_size);
             if (res)
                 goto end;
         }
@@ -2308,6 +2345,8 @@ static int matroska_parse_cluster_incremental(MatroskaDemuxContext *matroska)
         i = blocks_list->nb_elem - 1;
         if (blocks[i].bin.size > 0 && blocks[i].bin.data) {
             int is_keyframe = blocks[i].non_simple ? !blocks[i].reference : -1;
+            uint8_t* additional = blocks[i].additional.size > 0 ?
+                                    blocks[i].additional.data : NULL;
             if (!blocks[i].non_simple)
                 blocks[i].duration = 0;
             res = matroska_parse_block(matroska,
@@ -2315,11 +2354,12 @@ static int matroska_parse_cluster_incremental(MatroskaDemuxContext *matroska)
                                        blocks[i].bin.pos,
                                        matroska->current_cluster.timecode,
                                        blocks[i].duration, is_keyframe,
+                                       additional, blocks[i].additional_id,
+                                       blocks[i].additional.size,
                                        matroska->current_cluster_pos);
         }
     }
 
-    if (res < 0)  matroska->done = 1;
     return res;
 }
 
@@ -2345,7 +2385,7 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska)
             res=matroska_parse_block(matroska,
                                      blocks[i].bin.data, blocks[i].bin.size,
                                      blocks[i].bin.pos,  cluster.timecode,
-                                     blocks[i].duration, is_keyframe,
+                                     blocks[i].duration, is_keyframe, NULL, 0, 0,
                                      pos);
         }
     ebml_free(matroska_cluster, &cluster);
@@ -2417,9 +2457,14 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
 
     avio_seek(s->pb, st->index_entries[index_min].pos, SEEK_SET);
     matroska->current_id = 0;
-    st->skip_to_keyframe =
-    matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY);
-    matroska->skip_to_timecode = st->index_entries[index].timestamp;
+    if (flags & AVSEEK_FLAG_ANY) {
+        st->skip_to_keyframe = 0;
+        matroska->skip_to_timecode = timestamp;
+    } else {
+        st->skip_to_keyframe = 1;
+        matroska->skip_to_timecode = st->index_entries[index].timestamp;
+    }
+    matroska->skip_to_keyframe = 1;
     matroska->done = 0;
     matroska->num_levels = 0;
     ff_update_cur_dts(s, st, st->index_entries[index].timestamp);
diff --git a/mythtv/external/FFmpeg/libavformat/matroskaenc.c b/mythtv/external/FFmpeg/libavformat/matroskaenc.c
index 12efbe2b8f2..4544f8e871d 100644
--- a/mythtv/external/FFmpeg/libavformat/matroskaenc.c
+++ b/mythtv/external/FFmpeg/libavformat/matroskaenc.c
@@ -72,6 +72,7 @@ typedef struct {
 
 typedef struct {
     int             write_dts;
+    int             has_cue;
 } mkv_track;
 
 #define MODE_MATROSKAv2 0x01
@@ -384,7 +385,7 @@ static int mkv_add_cuepoint(mkv_cues *cues, int stream, int64_t ts, int64_t clus
     return 0;
 }
 
-static int64_t mkv_write_cues(AVIOContext *pb, mkv_cues *cues, int num_tracks)
+static int64_t mkv_write_cues(AVIOContext *pb, mkv_cues *cues, mkv_track *tracks, int num_tracks)
 {
     ebml_master cues_element;
     int64_t currentpos;
@@ -403,7 +404,14 @@ static int64_t mkv_write_cues(AVIOContext *pb, mkv_cues *cues, int num_tracks)
 
         // put all the entries from different tracks that have the exact same
         // timestamp into the same CuePoint
+        for (j = 0; j < num_tracks; j++)
+            tracks[j].has_cue = 0;
         for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) {
+            int tracknum = entry[j].tracknum - 1;
+            av_assert0(tracknum>=0 && tracknumextradata + 12,
                                    codec->extradata_size - 12);
         }
-        else if (codec->extradata_size)
+        else if (codec->extradata_size && codec->codec_id != AV_CODEC_ID_TTA)
             avio_write(dyn_cp, codec->extradata, codec->extradata_size);
     } else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) {
         if (qt_id) {
@@ -498,8 +506,9 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, AVCodecCo
             if (!codec->codec_tag)
                 codec->codec_tag = ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id);
             if (!codec->codec_tag) {
-                av_log(s, AV_LOG_ERROR, "No bmp codec ID found.\n");
-                ret = -1;
+                av_log(s, AV_LOG_ERROR, "No bmp codec tag found for codec %s\n",
+                       avcodec_get_name(codec->codec_id));
+                ret = AVERROR(EINVAL);
             }
 
             ff_put_bmp_header(dyn_cp, codec, ff_codec_bmp_tags, 0);
@@ -509,8 +518,9 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, AVCodecCo
         unsigned int tag;
         tag = ff_codec_get_tag(ff_codec_wav_tags, codec->codec_id);
         if (!tag) {
-            av_log(s, AV_LOG_ERROR, "No wav codec ID found.\n");
-            ret = -1;
+            av_log(s, AV_LOG_ERROR, "No wav codec tag found for codec %s\n",
+                   avcodec_get_name(codec->codec_id));
+            ret = AVERROR(EINVAL);
         }
         if (!codec->codec_tag)
             codec->codec_tag = tag;
@@ -530,12 +540,16 @@ static int mkv_write_tracks(AVFormatContext *s)
     MatroskaMuxContext *mkv = s->priv_data;
     AVIOContext *pb = s->pb;
     ebml_master tracks;
-    int i, j, ret;
+    int i, j, ret, default_stream_exists = 0;
 
     ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, avio_tell(pb));
     if (ret < 0) return ret;
 
     tracks = start_ebml_master(pb, MATROSKA_ID_TRACKS, 0);
+    for (i = 0; i < s->nb_streams; i++) {
+        AVStream *st = s->streams[i];
+        default_stream_exists |= st->disposition & AV_DISPOSITION_DEFAULT;
+    }
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
         AVCodecContext *codec = st->codec;
@@ -554,6 +568,8 @@ static int mkv_write_tracks(AVFormatContext *s)
 
         if (!bit_depth)
             bit_depth = av_get_bytes_per_sample(codec->sample_fmt) << 3;
+        if (!bit_depth)
+            bit_depth = codec->bits_per_coded_sample;
 
         if (codec->codec_id == AV_CODEC_ID_AAC)
             get_aac_sample_rates(s, codec, &sample_rate, &output_sample_rate);
@@ -568,8 +584,11 @@ static int mkv_write_tracks(AVFormatContext *s)
         tag = av_dict_get(st->metadata, "language", NULL, 0);
         put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag ? tag->value:"und");
 
-        if (st->disposition)
+        if (default_stream_exists) {
             put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT));
+        }
+        if (st->disposition & AV_DISPOSITION_FORCED)
+            put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGFORCED, 1);
 
         // look for a codec ID string specific to mkv to use,
         // if none are found, use AVI codes
@@ -927,6 +946,19 @@ static int mkv_write_header(AVFormatContext *s)
     if (s->avoid_negative_ts < 0)
         s->avoid_negative_ts = 1;
 
+    for (i = 0; i < s->nb_streams; i++)
+        if (s->streams[i]->codec->codec_id == AV_CODEC_ID_ATRAC3 ||
+            s->streams[i]->codec->codec_id == AV_CODEC_ID_COOK ||
+            s->streams[i]->codec->codec_id == AV_CODEC_ID_RA_288 ||
+            s->streams[i]->codec->codec_id == AV_CODEC_ID_SIPR ||
+            s->streams[i]->codec->codec_id == AV_CODEC_ID_RV10 ||
+            s->streams[i]->codec->codec_id == AV_CODEC_ID_RV20) {
+            av_log(s, AV_LOG_ERROR,
+                   "The Matroska muxer does not yet support muxing %s\n",
+                   avcodec_get_name(s->streams[i]->codec->codec_id));
+            return AVERROR_PATCHWELCOME;
+        }
+
     mkv->tracks = av_mallocz(s->nb_streams * sizeof(*mkv->tracks));
     if (!mkv->tracks)
         return AVERROR(ENOMEM);
@@ -1311,7 +1343,7 @@ static int mkv_write_trailer(AVFormatContext *s)
 
     if (pb->seekable) {
         if (mkv->cues->num_entries) {
-            cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams);
+            cuespos = mkv_write_cues(pb, mkv->cues, mkv->tracks, s->nb_streams);
 
             ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CUES, cuespos);
             if (ret < 0) return ret;
@@ -1366,7 +1398,6 @@ const AVCodecTag additional_audio_tags[] = {
     { AV_CODEC_ID_RA_288,    0xFFFFFFFF },
     { AV_CODEC_ID_COOK,      0xFFFFFFFF },
     { AV_CODEC_ID_TRUEHD,    0xFFFFFFFF },
-    { AV_CODEC_ID_TTA,       0xFFFFFFFF },
     { AV_CODEC_ID_WAVPACK,   0xFFFFFFFF },
     { AV_CODEC_ID_NONE,      0xFFFFFFFF }
 };
@@ -1377,6 +1408,7 @@ const AVCodecTag additional_video_tags[] = {
     { AV_CODEC_ID_RV20,      0xFFFFFFFF },
     { AV_CODEC_ID_RV30,      0xFFFFFFFF },
     { AV_CODEC_ID_RV40,      0xFFFFFFFF },
+    { AV_CODEC_ID_VP9,       0xFFFFFFFF },
     { AV_CODEC_ID_NONE,      0xFFFFFFFF }
 };
 
diff --git a/mythtv/external/FFmpeg/libavformat/microdvdenc.c b/mythtv/external/FFmpeg/libavformat/microdvdenc.c
index ba97444044d..30fd0ea3a62 100644
--- a/mythtv/external/FFmpeg/libavformat/microdvdenc.c
+++ b/mythtv/external/FFmpeg/libavformat/microdvdenc.c
@@ -19,12 +19,14 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
 #include "avformat.h"
-#include "rawenc.h"
+#include "internal.h"
 
 static int microdvd_write_header(struct AVFormatContext *s)
 {
     AVCodecContext *avctx = s->streams[0]->codec;
+    AVRational tb = avctx->time_base;
 
     if (s->nb_streams != 1 || avctx->codec_id != AV_CODEC_ID_MICRODVD) {
         av_log(s, AV_LOG_ERROR, "Exactly one MicroDVD stream is needed.\n");
@@ -36,6 +38,21 @@ static int microdvd_write_header(struct AVFormatContext *s)
         avio_write(s->pb, avctx->extradata, avctx->extradata_size);
         avio_flush(s->pb);
     }
+
+    avpriv_set_pts_info(s->streams[0], 64, tb.num, tb.den);
+    return 0;
+}
+
+static int microdvd_write_packet(AVFormatContext *avf, AVPacket *pkt)
+{
+    avio_printf(avf->pb, "{%"PRId64"}", pkt->pts);
+    if (pkt->duration < 0)
+        avio_write(avf->pb, "{}", 2);
+    else
+        avio_printf(avf->pb, "{%"PRId64"}", pkt->pts + pkt->duration);
+    avio_write(avf->pb, pkt->data, pkt->size);
+    avio_write(avf->pb, "\n", 1);
+    avio_flush(avf->pb);
     return 0;
 }
 
@@ -45,7 +62,7 @@ AVOutputFormat ff_microdvd_muxer = {
     .mime_type      = "text/x-microdvd",
     .extensions     = "sub",
     .write_header   = microdvd_write_header,
-    .write_packet   = ff_raw_write_packet,
+    .write_packet   = microdvd_write_packet,
     .flags          = AVFMT_NOTIMESTAMPS,
     .subtitle_codec = AV_CODEC_ID_MICRODVD,
 };
diff --git a/mythtv/external/FFmpeg/libavformat/mov.c b/mythtv/external/FFmpeg/libavformat/mov.c
index 2f6e52d955b..bf90ec8eb3b 100644
--- a/mythtv/external/FFmpeg/libavformat/mov.c
+++ b/mythtv/external/FFmpeg/libavformat/mov.c
@@ -2233,8 +2233,10 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
                    "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n",
                    st->index, dref->path, dref->dir, dref->filename,
                    dref->volume, dref->nlvl_from, dref->nlvl_to);
-    } else
+    } else {
         sc->pb = c->fc->pb;
+        sc->pb_is_copied = 1;
+    }
 
     if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
         if (!st->sample_aspect_ratio.num &&
@@ -2696,15 +2698,6 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     return 0;
 }
 
-static int mov_read_chan2(MOVContext *c, AVIOContext *pb, MOVAtom atom)
-{
-    if (atom.size < 16)
-        return 0;
-    avio_skip(pb, 4);
-    ff_mov_read_chan(c->fc, pb, c->fc->streams[0],  atom.size - 4);
-    return 0;
-}
-
 static int mov_read_tmcd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     MOVStreamContext *sc;
@@ -3074,7 +3067,7 @@ static int mov_read_close(AVFormatContext *s)
             av_freep(&sc->drefs[j].dir);
         }
         av_freep(&sc->drefs);
-        if (sc->pb && sc->pb != s->pb)
+        if (!sc->pb_is_copied)
             avio_close(sc->pb);
         sc->pb = NULL;
         av_freep(&sc->chunk_offsets);
@@ -3180,7 +3173,7 @@ static int mov_read_header(AVFormatContext *s)
                 if (s->streams[j]->id == sc->timecode_track)
                     tmcd_st_id = j;
 
-            if (tmcd_st_id < 0)
+            if (tmcd_st_id < 0 || tmcd_st_id == i)
                 continue;
             tcr = av_dict_get(s->streams[tmcd_st_id]->metadata, "timecode", NULL, 0);
             if (tcr)
diff --git a/mythtv/external/FFmpeg/libavformat/movenc.c b/mythtv/external/FFmpeg/libavformat/movenc.c
index bc50ccd8e0e..8f3b1bc57a3 100644
--- a/mythtv/external/FFmpeg/libavformat/movenc.c
+++ b/mythtv/external/FFmpeg/libavformat/movenc.c
@@ -356,8 +356,7 @@ static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic
     else
         avio_w8(pb, 0x11); // flags (= Visualstream)
 
-    avio_w8(pb,  track->enc->rc_buffer_size>>(3+16));      // Buffersize DB (24 bits)
-    avio_wb16(pb, (track->enc->rc_buffer_size>>3)&0xFFFF); // Buffersize DB
+    avio_wb24(pb, track->enc->rc_buffer_size >> 3); // Buffersize DB
 
     avg_bitrate = compute_avg_bitrate(track);
     // maxbitrate (FIXME should be max rate in any 1 sec window)
@@ -1603,7 +1602,7 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVTrack *track, AVStream *st)
     (version == 1) ? avio_wb32(pb, 104) : avio_wb32(pb, 92); /* size */
     ffio_wfourcc(pb, "tkhd");
     avio_w8(pb, version);
-    avio_wb24(pb, 0xf); /* flags (track enabled) */
+    avio_wb24(pb, track->secondary ? 0x2 : 0xf); /* flags (first track enabled) */
     if (version == 1) {
         avio_wb64(pb, track->time);
         avio_wb64(pb, track->time);
@@ -2316,6 +2315,7 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,
 {
     int i;
     int64_t pos = avio_tell(pb);
+    int not_first[AVMEDIA_TYPE_NB]={0};
     avio_wb32(pb, 0); /* size placeholder*/
     ffio_wfourcc(pb, "moov");
 
@@ -2356,6 +2356,13 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,
         mov_write_iods_tag(pb, mov);
     for (i=0; inb_streams; i++) {
         if (mov->tracks[i].entry > 0 || mov->flags & FF_MOV_FLAG_FRAGMENT) {
+            if(i < s->nb_streams){
+                int codec_type= s->streams[i]->codec->codec_type;
+                if(codec_type==AVMEDIA_TYPE_AUDIO || codec_type==AVMEDIA_TYPE_SUBTITLE){
+                    mov->tracks[i].secondary= not_first[codec_type];
+                    not_first[codec_type]= 1;
+                }
+            }
             mov_write_trak_tag(pb, mov, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL);
         }
     }
diff --git a/mythtv/external/FFmpeg/libavformat/movenc.h b/mythtv/external/FFmpeg/libavformat/movenc.h
index b5d066f4d94..a5db8950ab9 100644
--- a/mythtv/external/FFmpeg/libavformat/movenc.h
+++ b/mythtv/external/FFmpeg/libavformat/movenc.h
@@ -94,6 +94,7 @@ typedef struct MOVIndex {
 #define MOV_TIMECODE_FLAG_ALLOWNEGATIVE 0x0004
     uint32_t    timecode_flags;
     int         language;
+    int         secondary;
     int         track_id;
     int         tag; ///< stsd fourcc
     AVCodecContext *enc;
diff --git a/mythtv/external/FFmpeg/libavformat/mpc8.c b/mythtv/external/FFmpeg/libavformat/mpc8.c
index 011c7c8e645..73f805711d2 100644
--- a/mythtv/external/FFmpeg/libavformat/mpc8.c
+++ b/mythtv/external/FFmpeg/libavformat/mpc8.c
@@ -139,6 +139,11 @@ static void mpc8_parse_seektable(AVFormatContext *s, int64_t off)
     int i, t, seekd;
     GetBitContext gb;
 
+    if (s->nb_streams<=0) {
+        av_log(s, AV_LOG_ERROR, "cannot parse stream table before stream header\n");
+        return;
+    }
+
     avio_seek(s->pb, off, SEEK_SET);
     mpc8_get_chunk_header(s->pb, &tag, &size);
     if(tag != TAG_SEEKTABLE){
diff --git a/mythtv/external/FFmpeg/libavformat/mpeg.c b/mythtv/external/FFmpeg/libavformat/mpeg.c
index 3313d701c04..782dcca203c 100644
--- a/mythtv/external/FFmpeg/libavformat/mpeg.c
+++ b/mythtv/external/FFmpeg/libavformat/mpeg.c
@@ -416,7 +416,6 @@ static int mpegps_read_packet(AVFormatContext *s,
     }
 
     es_type = m->psm_es_type[startcode & 0xff];
-    if(es_type > 0 && es_type != STREAM_TYPE_PRIVATE_DATA){
         if(es_type == STREAM_TYPE_VIDEO_MPEG1){
             codec_id = AV_CODEC_ID_MPEG2VIDEO;
             type = AVMEDIA_TYPE_VIDEO;
@@ -442,9 +441,6 @@ static int mpegps_read_packet(AVFormatContext *s,
         } else if(es_type == STREAM_TYPE_AUDIO_AC3){
             codec_id = AV_CODEC_ID_AC3;
             type = AVMEDIA_TYPE_AUDIO;
-        } else {
-            goto skip;
-        }
     } else if (startcode >= 0x1e0 && startcode <= 0x1ef) {
         static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 };
         unsigned char buf[8];
diff --git a/mythtv/external/FFmpeg/libavformat/mpegts.c b/mythtv/external/FFmpeg/libavformat/mpegts.c
index ba363b86944..0643c7624d9 100644
--- a/mythtv/external/FFmpeg/libavformat/mpegts.c
+++ b/mythtv/external/FFmpeg/libavformat/mpegts.c
@@ -561,7 +561,9 @@ static const StreamType ISO_types[] = {
     { 0x10, AVMEDIA_TYPE_VIDEO,      AV_CODEC_ID_MPEG4 },
     /* Makito encoder sets stream type 0x11 for AAC,
      * so auto-detect LOAS/LATM instead of hardcoding it. */
-//  { 0x11, AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_AAC_LATM }, /* LATM syntax */
+#if !CONFIG_LOAS_DEMUXER
+    { 0x11, AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_AAC_LATM }, /* LATM syntax */
+#endif
     { 0x1b, AVMEDIA_TYPE_VIDEO,       AV_CODEC_ID_H264 },
     { 0xd1, AVMEDIA_TYPE_VIDEO,      AV_CODEC_ID_DIRAC },
     { 0xea, AVMEDIA_TYPE_VIDEO,        AV_CODEC_ID_VC1 },
@@ -2152,16 +2154,20 @@ static int mpegts_read_packet(AVFormatContext *s,
     return ret;
 }
 
-static int mpegts_read_close(AVFormatContext *s)
+static void mpegts_free(MpegTSContext *ts)
 {
-    MpegTSContext *ts = s->priv_data;
     int i;
 
     clear_programs(ts);
 
     for(i=0;ipids[i]) mpegts_close_filter(ts, ts->pids[i]);
+}
 
+static int mpegts_read_close(AVFormatContext *s)
+{
+    MpegTSContext *ts = s->priv_data;
+    mpegts_free(ts);
     return 0;
 }
 
@@ -2275,10 +2281,7 @@ int ff_old_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt,
 
 void ff_old_mpegts_parse_close(MpegTSContext *ts)
 {
-    int i;
-
-    for(i=0;ipids[i]);
+    mpegts_free(ts);
     av_free(ts);
 }
 
diff --git a/mythtv/external/FFmpeg/libavformat/mux.c b/mythtv/external/FFmpeg/libavformat/mux.c
index 649b4961d94..98ec7a4cf2d 100644
--- a/mythtv/external/FFmpeg/libavformat/mux.c
+++ b/mythtv/external/FFmpeg/libavformat/mux.c
@@ -549,20 +549,26 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
         next_point = &s->packet_buffer;
     }
 
-    if (*next_point) {
-        if (chunked) {
-            uint64_t max= av_rescale_q(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base);
-            if (   st->interleaver_chunk_size     + pkt->size     <= s->max_chunk_size-1U
-                && st->interleaver_chunk_duration + pkt->duration <= max-1U) {
-                st->interleaver_chunk_size     += pkt->size;
-                st->interleaver_chunk_duration += pkt->duration;
-                goto next_non_null;
-            } else {
-                st->interleaver_chunk_size     =
+    if (chunked) {
+        uint64_t max= av_rescale_q_rnd(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base, AV_ROUND_UP);
+        st->interleaver_chunk_size     += pkt->size;
+        st->interleaver_chunk_duration += pkt->duration;
+        if (   (s->max_chunk_size && st->interleaver_chunk_size > s->max_chunk_size)
+            || (max && st->interleaver_chunk_duration           > max)) {
+            st->interleaver_chunk_size      = 0;
+            this_pktl->pkt.flags |= CHUNK_START;
+            if (max && st->interleaver_chunk_duration > max) {
+                int64_t syncoffset = (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)*max/2;
+                int64_t syncto = av_rescale(pkt->dts + syncoffset, 1, max)*max - syncoffset;
+
+                st->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max;
+            } else
                 st->interleaver_chunk_duration = 0;
-                this_pktl->pkt.flags |= CHUNK_START;
-            }
         }
+    }
+    if (*next_point) {
+        if (chunked && !(this_pktl->pkt.flags & CHUNK_START))
+            goto next_non_null;
 
         if (compare(s, &s->packet_buffer_end->pkt, pkt)) {
             while (   *next_point
diff --git a/mythtv/external/FFmpeg/libavformat/mvdec.c b/mythtv/external/FFmpeg/libavformat/mvdec.c
index bb1c5d0dd81..103a40af6d2 100644
--- a/mythtv/external/FFmpeg/libavformat/mvdec.c
+++ b/mythtv/external/FFmpeg/libavformat/mvdec.c
@@ -88,6 +88,16 @@ static void var_read_metadata(AVFormatContext *avctx, const char *tag, int size)
         av_dict_set(&avctx->metadata, tag, value, AV_DICT_DONT_STRDUP_VAL);
 }
 
+static int set_channels(AVFormatContext *avctx, AVStream *st, int channels) {
+    if (channels <= 0) {
+        av_log(avctx, AV_LOG_ERROR, "Channel count %d invalid\n", channels);
+        return AVERROR_INVALIDDATA;
+    }
+    st->codec->channels = channels;
+    st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
+    return 0;
+}
+
 /**
  * Parse global variable
  * @return < 0 if unknown
@@ -126,8 +136,7 @@ static int parse_audio_var(AVFormatContext *avctx, AVStream *st, const char *nam
     } else if (!strcmp(name, "DEFAULT_VOL")) {
         var_read_metadata(avctx, name, size);
     } else if (!strcmp(name, "NUM_CHANNELS")) {
-        st->codec->channels = var_read_int(pb, size);
-        st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
+        return set_channels(avctx, st, var_read_int(pb, size));
     } else if (!strcmp(name, "SAMPLE_RATE")) {
         st->codec->sample_rate = var_read_int(pb, size);
         avpriv_set_pts_info(st, 33, 1, st->codec->sample_rate);
@@ -149,6 +158,8 @@ static int parse_video_var(AVFormatContext *avctx, AVStream *st, const char *nam
         st->nb_frames = st->duration = var_read_int(pb, size);
     } else if (!strcmp(name, "COMPRESSION")) {
         char * str = var_read_string(pb, size);
+        if (!str)
+            return AVERROR_INVALIDDATA;
         if (!strcmp(str, "1")) {
             st->codec->codec_id = AV_CODEC_ID_MVC1;
         } else if (!strcmp(str, "2")) {
@@ -165,7 +176,8 @@ static int parse_video_var(AVFormatContext *avctx, AVStream *st, const char *nam
         }
         av_free(str);
     } else if (!strcmp(name, "FPS")) {
-        st->time_base = av_inv_q(var_read_float(pb, size));
+        AVRational fps = var_read_float(pb, size);
+        avpriv_set_pts_info(st, 64, fps.den, fps.num);
     } else if (!strcmp(name, "HEIGHT")) {
         st->codec->height = var_read_int(pb, size);
     } else if (!strcmp(name, "PIXEL_ASPECT")) {
@@ -250,7 +262,7 @@ static int mv_read_header(AVFormatContext *avctx)
         if (!vst)
             return AVERROR(ENOMEM);
         vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
-        vst->time_base = (AVRational){1, 15};
+        avpriv_set_pts_info(vst, 64, 1, 15);
         vst->nb_frames = avio_rb32(pb);
         v = avio_rb32(pb);
         switch (v) {
@@ -274,8 +286,9 @@ static int mv_read_header(AVFormatContext *avctx)
         ast->nb_frames             = vst->nb_frames;
         ast->codec->sample_rate    = avio_rb32(pb);
         avpriv_set_pts_info(ast, 33, 1, ast->codec->sample_rate);
-        ast->codec->channels       = avio_rb32(pb);
-        ast->codec->channel_layout = (ast->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
+        if (set_channels(avctx, ast, avio_rb32(pb)) < 0)
+            return AVERROR_INVALIDDATA;
+
         v = avio_rb32(pb);
         if (v == AUDIO_FORMAT_SIGNED) {
             ast->codec->codec_id = AV_CODEC_ID_PCM_S16BE;
@@ -321,6 +334,10 @@ static int mv_read_header(AVFormatContext *avctx)
                 ast->codec->codec_id = AV_CODEC_ID_NONE;
             }
             ast->codec->codec_tag = 0;
+            if (ast->codec->channels <= 0) {
+                av_log(avctx, AV_LOG_ERROR, "No valid channel count found\n");
+                return AVERROR_INVALIDDATA;
+            }
         }
 
         if (mv->nb_video_tracks > 1) {
@@ -357,7 +374,7 @@ static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt)
     int ret;
     uint64_t pos;
 
-    if (frame  < st->nb_frames) {
+    if (frame  < st->nb_index_entries) {
         index = &st->index_entries[frame];
         pos = avio_tell(pb);
         if (index->pos > pos)
diff --git a/mythtv/external/FFmpeg/libavformat/mvi.c b/mythtv/external/FFmpeg/libavformat/mvi.c
index 9184927a2f7..953c1824faa 100644
--- a/mythtv/external/FFmpeg/libavformat/mvi.c
+++ b/mythtv/external/FFmpeg/libavformat/mvi.c
@@ -89,12 +89,17 @@ static int read_header(AVFormatContext *s)
     ast->codec->bit_rate        = ast->codec->sample_rate * 8;
 
     avpriv_set_pts_info(vst, 64, msecs_per_frame, 1000000);
+    vst->avg_frame_rate    = av_inv_q(vst->time_base);
     vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
     vst->codec->codec_id   = AV_CODEC_ID_MOTIONPIXELS;
 
     mvi->get_int = (vst->codec->width * vst->codec->height < (1 << 16)) ? avio_rl16 : avio_rl24;
 
     mvi->audio_frame_size   = ((uint64_t)mvi->audio_data_size << MVI_FRAC_BITS) / frames_count;
+    if (!mvi->audio_frame_size) {
+        av_log(s, AV_LOG_ERROR, "audio_frame_size is 0\n");
+        return AVERROR_INVALIDDATA;
+    }
     mvi->audio_size_counter = (ast->codec->sample_rate * 830 / mvi->audio_frame_size - 1) * mvi->audio_frame_size;
     mvi->audio_size_left    = mvi->audio_data_size;
 
diff --git a/mythtv/external/FFmpeg/libavformat/mxfdec.c b/mythtv/external/FFmpeg/libavformat/mxfdec.c
index bb5f4a78083..f7aaa5a9de4 100644
--- a/mythtv/external/FFmpeg/libavformat/mxfdec.c
+++ b/mythtv/external/FFmpeg/libavformat/mxfdec.c
@@ -1506,6 +1506,15 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
         /* TODO: drop PictureEssenceCoding and SoundEssenceCompression, only check EssenceContainer */
         codec_ul = mxf_get_codec_ul(ff_mxf_codec_uls, &descriptor->essence_codec_ul);
         st->codec->codec_id = (enum AVCodecID)codec_ul->id;
+        av_log(mxf->fc, AV_LOG_VERBOSE, "%s: Universal Label: ",
+               avcodec_get_name(st->codec->codec_id));
+        for (k = 0; k < 16; k++) {
+            av_log(mxf->fc, AV_LOG_VERBOSE, "%.2x",
+                   descriptor->essence_codec_ul[k]);
+            if (!(k+1 & 19) || k == 5)
+                av_log(mxf->fc, AV_LOG_VERBOSE, ".");
+        }
+        av_log(mxf->fc, AV_LOG_VERBOSE, "\n");
         if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
             source_track->intra_only = mxf_is_intra_only(descriptor);
             container_ul = mxf_get_codec_ul(mxf_picture_essence_container_uls, essence_container_ul);
@@ -2070,7 +2079,7 @@ static int mxf_set_audio_pts(MXFContext *mxf, AVCodecContext *codec, AVPacket *p
     pkt->pts = track->sample_count;
     if (codec->channels <= 0 || av_get_bits_per_sample(codec->codec_id) <= 0)
         return AVERROR(EINVAL);
-    track->sample_count += pkt->size / (codec->channels * av_get_bits_per_sample(codec->codec_id) / 8);
+    track->sample_count += pkt->size / (codec->channels * (int64_t)av_get_bits_per_sample(codec->codec_id) / 8);
     return 0;
 }
 
diff --git a/mythtv/external/FFmpeg/libavformat/mxg.c b/mythtv/external/FFmpeg/libavformat/mxg.c
index d911a33e7f9..e9a6f22b207 100644
--- a/mythtv/external/FFmpeg/libavformat/mxg.c
+++ b/mythtv/external/FFmpeg/libavformat/mxg.c
@@ -101,17 +101,19 @@ static int mxg_update_cache(AVFormatContext *s, unsigned int cache_size)
     MXGContext *mxg = s->priv_data;
     unsigned int current_pos = mxg->buffer_ptr - mxg->buffer;
     unsigned int soi_pos;
+    uint8_t *buffer;
     int ret;
 
     /* reallocate internal buffer */
     if (current_pos > current_pos + cache_size)
         return AVERROR(ENOMEM);
     soi_pos = mxg->soi_ptr - mxg->buffer;
-    mxg->buffer = av_fast_realloc(mxg->buffer, &mxg->buffer_size,
-                                  current_pos + cache_size +
-                                  FF_INPUT_BUFFER_PADDING_SIZE);
-    if (!mxg->buffer)
+    buffer = av_fast_realloc(mxg->buffer, &mxg->buffer_size,
+                             current_pos + cache_size +
+                             FF_INPUT_BUFFER_PADDING_SIZE);
+    if (!buffer)
         return AVERROR(ENOMEM);
+    mxg->buffer = buffer;
     mxg->buffer_ptr = mxg->buffer + current_pos;
     if (mxg->soi_ptr) mxg->soi_ptr = mxg->buffer + soi_pos;
 
diff --git a/mythtv/external/FFmpeg/libavformat/noproxy-test.c b/mythtv/external/FFmpeg/libavformat/noproxy-test.c
new file mode 100644
index 00000000000..a156620271a
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavformat/noproxy-test.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013 Martin Storsjo
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "internal.h"
+
+static void test(const char *pattern, const char *host)
+{
+    int res = ff_http_match_no_proxy(pattern, host);
+    printf("The pattern \"%s\" %s the hostname %s\n",
+           pattern ? pattern : "(null)", res ? "matches" : "does not match",
+           host);
+}
+
+int main(void)
+{
+    test(NULL, "domain.com");
+    test("example.com domain.com", "domain.com");
+    test("example.com other.com", "domain.com");
+    test("example.com,domain.com", "domain.com");
+    test("example.com,domain.com", "otherdomain.com");
+    test("example.com, *.domain.com", "sub.domain.com");
+    test("example.com, *.domain.com", "domain.com");
+    test("example.com, .domain.com", "domain.com");
+    test("*", "domain.com");
+    return 0;
+}
diff --git a/mythtv/external/FFmpeg/libavformat/nut.c b/mythtv/external/FFmpeg/libavformat/nut.c
index 62a650dbede..2abe9693080 100644
--- a/mythtv/external/FFmpeg/libavformat/nut.c
+++ b/mythtv/external/FFmpeg/libavformat/nut.c
@@ -40,6 +40,7 @@ const AVCodecTag ff_nut_data_tags[] = {
 };
 
 const AVCodecTag ff_nut_video_tags[] = {
+    { AV_CODEC_ID_VP9,      MKTAG('V', 'P', '9', '0') },
     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 15 ) },
     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 15 ) },
     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 16 ) },
diff --git a/mythtv/external/FFmpeg/libavformat/nutdec.c b/mythtv/external/FFmpeg/libavformat/nutdec.c
index f260a3e4fd4..88965181424 100644
--- a/mythtv/external/FFmpeg/libavformat/nutdec.c
+++ b/mythtv/external/FFmpeg/libavformat/nutdec.c
@@ -73,8 +73,10 @@ static uint64_t get_fourcc(AVIOContext *bc)
         return avio_rl16(bc);
     else if (len == 4)
         return avio_rl32(bc);
-    else
+    else {
+        av_log(NULL, AV_LOG_ERROR, "Unsupported fourcc length %d\n", len);
         return -1;
+    }
 }
 
 #ifdef TRACE
@@ -555,14 +557,14 @@ static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
     tmp       = ffio_read_varlen(bc);
     *back_ptr = nut->last_syncpoint_pos - 16 * ffio_read_varlen(bc);
     if (*back_ptr < 0)
-        return -1;
+        return AVERROR_INVALIDDATA;
 
     ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count],
                     tmp / nut->time_base_count);
 
     if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
         av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     *ts = tmp / nut->time_base_count *
diff --git a/mythtv/external/FFmpeg/libavformat/nutenc.c b/mythtv/external/FFmpeg/libavformat/nutenc.c
index 46711528a04..2d8d2652ee5 100644
--- a/mythtv/external/FFmpeg/libavformat/nutenc.c
+++ b/mythtv/external/FFmpeg/libavformat/nutenc.c
@@ -990,7 +990,7 @@ static int nut_write_trailer(AVFormatContext *s)
         write_headers(s, bc);
 
     ret = avio_open_dyn_buf(&dyn_bc);
-    if (ret >= 0) {
+    if (ret >= 0 && nut->sp_count) {
         write_index(nut, dyn_bc);
         put_packet(nut, bc, dyn_bc, 1, INDEX_STARTCODE);
     }
diff --git a/mythtv/external/FFmpeg/libavformat/oggdec.c b/mythtv/external/FFmpeg/libavformat/oggdec.c
index e51db613574..5cb03fe13a2 100644
--- a/mythtv/external/FFmpeg/libavformat/oggdec.c
+++ b/mythtv/external/FFmpeg/libavformat/oggdec.c
@@ -57,7 +57,7 @@ static const struct ogg_codec * const ogg_codecs[] = {
 };
 
 static int64_t ogg_calc_pts(AVFormatContext *s, int idx, int64_t *dts);
-static int ogg_read_close(AVFormatContext *s);
+static int ogg_new_stream(AVFormatContext *s, uint32_t serial);
 
 //FIXME We could avoid some structure duplication
 static int ogg_save(AVFormatContext *s)
@@ -170,30 +170,47 @@ static const struct ogg_codec *ogg_find_codec(uint8_t *buf, int size)
  * situation where a new audio stream spawn (identified with a new serial) and
  * must replace the previous one (track switch).
  */
-static int ogg_replace_stream(AVFormatContext *s, uint32_t serial)
+static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, int nsegs)
 {
     struct ogg *ogg = s->priv_data;
     struct ogg_stream *os;
-    unsigned bufsize;
-    uint8_t *buf;
     const struct ogg_codec *codec;
-
-    if (ogg->nstreams != 1) {
+    int i = 0;
+
+    if (s->pb->seekable) {
+        uint8_t magic[8];
+        int64_t pos = avio_tell(s->pb);
+        avio_skip(s->pb, nsegs);
+        avio_read(s->pb, magic, sizeof(magic));
+        avio_seek(s->pb, pos, SEEK_SET);
+        codec = ogg_find_codec(magic, sizeof(magic));
+        if (!codec) {
+            av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
+            return AVERROR_INVALIDDATA;
+        }
+        for (i = 0; i < ogg->nstreams; i++) {
+            if (ogg->streams[i].codec == codec)
+                break;
+        }
+        if (i >= ogg->nstreams)
+            return ogg_new_stream(s, serial);
+    } else if (ogg->nstreams != 1) {
         av_log_missing_feature(s, "Changing stream parameters in multistream ogg", 0);
         return AVERROR_PATCHWELCOME;
     }
 
-    os = &ogg->streams[0];
+    os = &ogg->streams[i];
 
     os->serial  = serial;
-    return 0;
+    return i;
 
+#if 0
     buf     = os->buf;
     bufsize = os->bufsize;
     codec   = os->codec;
 
-    if (!ogg->state || ogg->state->streams[0].private != os->private)
-        av_freep(&ogg->streams[0].private);
+    if (!ogg->state || ogg->state->streams[i].private != os->private)
+        av_freep(&ogg->streams[i].private);
 
     /* Set Ogg stream settings similar to what is done in ogg_new_stream(). We
      * also re-use the ogg_stream allocated buffer */
@@ -204,7 +221,8 @@ static int ogg_replace_stream(AVFormatContext *s, uint32_t serial)
     os->header  = -1;
     os->codec   = codec;
 
-    return 0;
+    return i;
+#endif
 }
 
 static int ogg_new_stream(AVFormatContext *s, uint32_t serial)
@@ -335,7 +353,7 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
     idx = ogg_find_stream(ogg, serial);
     if (idx < 0) {
         if (data_packets_seen(ogg))
-            idx = ogg_replace_stream(s, serial);
+            idx = ogg_replace_stream(s, serial, nsegs);
         else
             idx = ogg_new_stream(s, serial);
 
@@ -831,5 +849,5 @@ AVInputFormat ff_ogg_demuxer = {
     .read_seek      = ogg_read_seek,
     .read_timestamp = ogg_read_timestamp,
     .extensions     = "ogg",
-    .flags          = AVFMT_GENERIC_INDEX,
+    .flags          = AVFMT_GENERIC_INDEX | AVFMT_TS_DISCONT,
 };
diff --git a/mythtv/external/FFmpeg/libavformat/oggenc.c b/mythtv/external/FFmpeg/libavformat/oggenc.c
index 2ff6704698b..3d4519c1acb 100644
--- a/mythtv/external/FFmpeg/libavformat/oggenc.c
+++ b/mythtv/external/FFmpeg/libavformat/oggenc.c
@@ -35,6 +35,7 @@
 #define MAX_PAGE_SIZE 65025
 
 typedef struct {
+    int64_t start_granule;
     int64_t granule;
     int stream_index;
     uint8_t flags;
@@ -68,6 +69,7 @@ typedef struct {
     const AVClass *class;
     OGGPageList *page_list;
     int pref_size; ///< preferred page size (0 => fill all segments)
+    int64_t pref_duration;      ///< preferred page duration (0 => fill all segments)
 } OGGContext;
 
 #define OFFSET(x) offsetof(OGGContext, x)
@@ -76,8 +78,10 @@ typedef struct {
 static const AVOption options[] = {
     { "oggpagesize", "Set preferred Ogg page size.",
       offsetof(OGGContext, pref_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, MAX_PAGE_SIZE, AV_OPT_FLAG_ENCODING_PARAM},
-    { "pagesize", "preferred page size in bytes",
+    { "pagesize", "preferred page size in bytes (deprecated)",
         OFFSET(pref_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_PAGE_SIZE, PARAM },
+    { "page_duration", "preferred page duration, in microseconds",
+        OFFSET(pref_duration), AV_OPT_TYPE_INT, { .i64 = 1000000 }, 0, INT64_MAX, PARAM },
     { NULL },
 };
 
@@ -185,6 +189,7 @@ static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream)
         return AVERROR(ENOMEM);
     l->page = oggstream->page;
 
+    oggstream->page.start_granule = oggstream->page.granule;
     oggstream->page_count++;
     ogg_reset_cur_page(oggstream);
 
@@ -223,6 +228,12 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st,
         flush = 1;
     }
 
+    // avoid a continued page
+    if (!header && oggstream->page.size > 0 &&
+        MAX_PAGE_SIZE - oggstream->page.size < size) {
+        ogg_buffer_page(s, oggstream);
+    }
+
     for (i = 0; i < total_segments; ) {
         OGGPage *page = &oggstream->page;
 
@@ -245,9 +256,19 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st,
         if (i == total_segments)
             page->granule = granule;
 
-        if (!header && (page->segments_count == 255 ||
-            (ogg->pref_size > 0 && page->size >= ogg->pref_size))) {
-           ogg_buffer_page(s, oggstream);
+        if (!header) {
+            AVStream *st = s->streams[page->stream_index];
+
+            int64_t start = av_rescale_q(page->start_granule, st->time_base,
+                                         AV_TIME_BASE_Q);
+            int64_t next  = av_rescale_q(page->granule, st->time_base,
+                                         AV_TIME_BASE_Q);
+
+            if (page->segments_count == 255 ||
+                (ogg->pref_size     > 0 && page->size   >= ogg->pref_size) ||
+                (ogg->pref_duration > 0 && next - start >= ogg->pref_duration)) {
+                ogg_buffer_page(s, oggstream);
+            }
         }
     }
 
@@ -380,9 +401,13 @@ static int ogg_build_opus_headers(AVCodecContext *avctx,
 
 static int ogg_write_header(AVFormatContext *s)
 {
-    OGGStreamContext *oggstream;
+    OGGContext *ogg = s->priv_data;
+    OGGStreamContext *oggstream = NULL;
     int i, j;
 
+    if (ogg->pref_size)
+        av_log(s, AV_LOG_WARNING, "The pagesize option is deprecated\n");
+
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
         unsigned serial_num = i;
@@ -502,6 +527,9 @@ static int ogg_write_header(AVFormatContext *s)
         }
         ogg_buffer_page(s, oggstream);
     }
+
+    oggstream->page.start_granule = AV_NOPTS_VALUE;
+
     return 0;
 }
 
@@ -551,6 +579,9 @@ static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
     else
         granule = pkt->pts + pkt->duration;
 
+    if (oggstream->page.start_granule == AV_NOPTS_VALUE)
+        oggstream->page.start_granule = pkt->pts;
+
     ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule, 0);
     if (ret < 0)
         return ret;
@@ -566,9 +597,13 @@ static int ogg_write_trailer(AVFormatContext *s)
 {
     int i;
 
-    /* flush current page */
-    for (i = 0; i < s->nb_streams; i++)
-        ogg_buffer_page(s, s->streams[i]->priv_data);
+    /* flush current page if needed */
+    for (i = 0; i < s->nb_streams; i++) {
+        OGGStreamContext *oggstream = s->streams[i]->priv_data;
+
+        if (oggstream->page.size > 0)
+            ogg_buffer_page(s, oggstream);
+    }
 
     ogg_write_pages(s, 1);
 
diff --git a/mythtv/external/FFmpeg/libavformat/oggparseskeleton.c b/mythtv/external/FFmpeg/libavformat/oggparseskeleton.c
index f9ad7011451..b6959a6543d 100644
--- a/mythtv/external/FFmpeg/libavformat/oggparseskeleton.c
+++ b/mythtv/external/FFmpeg/libavformat/oggparseskeleton.c
@@ -61,7 +61,7 @@ static int skeleton_header(AVFormatContext *s, int idx)
         start_num = AV_RL64(buf+12);
         start_den = AV_RL64(buf+20);
 
-        if (start_den) {
+        if (start_den > 0 && start_num > 0) {
             int base_den;
             av_reduce(&start_time, &base_den, start_num, start_den, INT_MAX);
             avpriv_set_pts_info(st, 64, 1, base_den);
diff --git a/mythtv/external/FFmpeg/libavformat/oggparsevorbis.c b/mythtv/external/FFmpeg/libavformat/oggparsevorbis.c
index 16bcaefd4d6..da029a47df8 100644
--- a/mythtv/external/FFmpeg/libavformat/oggparsevorbis.c
+++ b/mythtv/external/FFmpeg/libavformat/oggparsevorbis.c
@@ -122,7 +122,7 @@ ff_vorbis_comment(AVFormatContext * as, AVDictionary **m, const uint8_t *buf, in
             }
 
             for (j = 0; j < tl; j++)
-                tt[j] = toupper(t[j]);
+                tt[j] = av_toupper(t[j]);
             tt[tl] = 0;
 
             memcpy(ct, v, vl);
@@ -173,11 +173,15 @@ static unsigned int
 fixup_vorbis_headers(AVFormatContext * as, struct oggvorbis_private *priv,
                      uint8_t **buf)
 {
-    int i,offset, len;
+    int i,offset, len, buf_len;
     unsigned char *ptr;
 
     len = priv->len[0] + priv->len[1] + priv->len[2];
-    ptr = *buf = av_mallocz(len + len/255 + 64);
+    buf_len = len + len/255 + 64;
+    ptr = *buf = av_realloc(NULL, buf_len);
+    if (!*buf)
+        return 0;
+    memset(*buf, '\0', buf_len);
 
     ptr[0] = 2;
     offset = 1;
diff --git a/mythtv/external/FFmpeg/libavformat/options_table.h b/mythtv/external/FFmpeg/libavformat/options_table.h
index dbe37d70722..6750050c1f7 100644
--- a/mythtv/external/FFmpeg/libavformat/options_table.h
+++ b/mythtv/external/FFmpeg/libavformat/options_table.h
@@ -48,7 +48,8 @@ static const AVOption options[]={
 {"keepside", "dont merge side data", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_KEEP_SIDE_DATA }, INT_MIN, INT_MAX, D, "fflags"},
 {"latm", "enable RTP MP4A-LATM payload", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_MP4A_LATM }, INT_MIN, INT_MAX, E, "fflags"},
 {"nobuffer", "reduce the latency introduced by optional buffering", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_NOBUFFER }, 0, INT_MAX, D, "fflags"},
-{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), AV_OPT_TYPE_INT, {.i64 = 5*AV_TIME_BASE }, 0, INT_MAX, D},
+{"seek2any", "forces seeking to enable seek to any mode", OFFSET(seek2any), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, D},
+{"analyzeduration", "specify how many microseconds are analyzed to probe the input", OFFSET(max_analyze_duration), AV_OPT_TYPE_INT, {.i64 = 5*AV_TIME_BASE }, 0, INT_MAX, D},
 {"cryptokey", "decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, {.dbl = 0}, 0, 0, D},
 {"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), AV_OPT_TYPE_INT, {.i64 = 1<<20 }, 0, INT_MAX, D},
 {"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), AV_OPT_TYPE_INT, {.i64 = 3041280 }, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */
diff --git a/mythtv/external/FFmpeg/libavformat/pmpdec.c b/mythtv/external/FFmpeg/libavformat/pmpdec.c
index 2ea37ef030d..e0394a95136 100644
--- a/mythtv/external/FFmpeg/libavformat/pmpdec.c
+++ b/mythtv/external/FFmpeg/libavformat/pmpdec.c
@@ -44,11 +44,13 @@ static int pmp_header(AVFormatContext *s)
     PMPContext *pmp = s->priv_data;
     AVIOContext *pb = s->pb;
     int tb_num, tb_den;
-    int index_cnt;
+    uint32_t index_cnt;
     int audio_codec_id = AV_CODEC_ID_NONE;
     int srate, channels;
-    int i;
+    unsigned i;
     uint64_t pos;
+    int64_t fsize = avio_size(pb);
+
     AVStream *vst = avformat_new_stream(s, NULL);
     if (!vst)
         return AVERROR(ENOMEM);
@@ -91,6 +93,26 @@ static int pmp_header(AVFormatContext *s)
     avio_skip(pb, 10);
     srate = avio_rl32(pb);
     channels = avio_rl32(pb) + 1;
+    pos = avio_tell(pb) + 4LL*index_cnt;
+    for (i = 0; i < index_cnt; i++) {
+        uint32_t size = avio_rl32(pb);
+        int flags = size & 1 ? AVINDEX_KEYFRAME : 0;
+        if (url_feof(pb)) {
+            av_log(s, AV_LOG_FATAL, "Encountered EOF while reading index.\n");
+            return AVERROR_INVALIDDATA;
+        }
+        size >>= 1;
+        if (size < 9 + 4*pmp->num_streams) {
+            av_log(s, AV_LOG_ERROR, "Packet too small\n");
+            return AVERROR_INVALIDDATA;
+        }
+        av_add_index_entry(vst, pos, i, size, 0, flags);
+        pos += size;
+        if (fsize > 0 && i == 0 && pos > fsize) {
+            av_log(s, AV_LOG_ERROR, "File ends before first packet\n");
+            return AVERROR_INVALIDDATA;
+        }
+    }
     for (i = 1; i < pmp->num_streams; i++) {
         AVStream *ast = avformat_new_stream(s, NULL);
         if (!ast)
@@ -101,14 +123,6 @@ static int pmp_header(AVFormatContext *s)
         ast->codec->sample_rate = srate;
         avpriv_set_pts_info(ast, 32, 1, srate);
     }
-    pos = avio_tell(pb) + 4*index_cnt;
-    for (i = 0; i < index_cnt; i++) {
-        int size = avio_rl32(pb);
-        int flags = size & 1 ? AVINDEX_KEYFRAME : 0;
-        size >>= 1;
-        av_add_index_entry(vst, pos, i, size, 0, flags);
-        pos += size;
-    }
     return 0;
 }
 
diff --git a/mythtv/external/FFmpeg/libavformat/qcp.c b/mythtv/external/FFmpeg/libavformat/qcp.c
index 3cb85fb00a6..1ef86fe34d8 100644
--- a/mythtv/external/FFmpeg/libavformat/qcp.c
+++ b/mythtv/external/FFmpeg/libavformat/qcp.c
@@ -102,11 +102,9 @@ static int qcp_read_header(AVFormatContext *s)
     if (is_qcelp_13k_guid(buf)) {
         st->codec->codec_id = AV_CODEC_ID_QCELP;
     } else if (!memcmp(buf, guid_evrc, 16)) {
-        av_log(s, AV_LOG_ERROR, "EVRC codec is not supported.\n");
-        return AVERROR_PATCHWELCOME;
+        st->codec->codec_id = AV_CODEC_ID_EVRC;
     } else if (!memcmp(buf, guid_smv, 16)) {
-        av_log(s, AV_LOG_ERROR, "SMV codec is not supported.\n");
-        return AVERROR_PATCHWELCOME;
+        st->codec->codec_id = AV_CODEC_ID_SMV;
     } else {
         av_log(s, AV_LOG_ERROR, "Unknown codec GUID.\n");
         return AVERROR_INVALIDDATA;
diff --git a/mythtv/external/FFmpeg/libavformat/r3d.c b/mythtv/external/FFmpeg/libavformat/r3d.c
index 35da81eff11..3b3ecce3d93 100644
--- a/mythtv/external/FFmpeg/libavformat/r3d.c
+++ b/mythtv/external/FFmpeg/libavformat/r3d.c
@@ -285,6 +285,10 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom)
     dts = avio_rb32(s->pb);
 
     st->codec->sample_rate = avio_rb32(s->pb);
+    if (st->codec->sample_rate < 0) {
+        av_log(s, AV_LOG_ERROR, "negative sample rate\n");
+        return AVERROR_INVALIDDATA;
+    }
 
     samples = avio_rb32(s->pb);
 
@@ -312,7 +316,8 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom)
 
     pkt->stream_index = 1;
     pkt->dts = dts;
-    pkt->duration = av_rescale(samples, st->time_base.den, st->codec->sample_rate);
+    if (st->codec->sample_rate)
+        pkt->duration = av_rescale(samples, st->time_base.den, st->codec->sample_rate);
     av_dlog(s, "pkt dts %"PRId64" duration %d samples %d sample rate %d\n",
             pkt->dts, pkt->duration, samples, st->codec->sample_rate);
 
diff --git a/mythtv/external/FFmpeg/libavformat/rawvideodec.c b/mythtv/external/FFmpeg/libavformat/rawvideodec.c
index a35f957fdd9..84607810dad 100644
--- a/mythtv/external/FFmpeg/libavformat/rawvideodec.c
+++ b/mythtv/external/FFmpeg/libavformat/rawvideodec.c
@@ -103,9 +103,9 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
 #define OFFSET(x) offsetof(RawVideoDemuxerContext, x)
 #define DEC AV_OPT_FLAG_DECODING_PARAM
 static const AVOption rawvideo_options[] = {
-    { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
-    { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC },
-    { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
+    { "video_size", "set frame size", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+    { "pixel_format", "set pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC },
+    { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
     { NULL },
 };
 
diff --git a/mythtv/external/FFmpeg/libavformat/riff.c b/mythtv/external/FFmpeg/libavformat/riff.c
index c0b42c1f669..ac1a4ff3682 100644
--- a/mythtv/external/FFmpeg/libavformat/riff.c
+++ b/mythtv/external/FFmpeg/libavformat/riff.c
@@ -62,6 +62,7 @@ const AVCodecTag ff_codec_bmp_tags[] = {
     { AV_CODEC_ID_MPEG4,        MKTAG('M', 'P', '4', 'S') },
     { AV_CODEC_ID_MPEG4,        MKTAG('M', '4', 'S', '2') },
     { AV_CODEC_ID_MPEG4,        MKTAG( 4 ,  0 ,  0 ,  0 ) }, /* some broken avi use this */
+    { AV_CODEC_ID_MPEG4,        MKTAG('Z', 'M', 'P', '4') }, /* some broken avi use this */
     { AV_CODEC_ID_MPEG4,        MKTAG('D', 'I', 'V', '1') },
     { AV_CODEC_ID_MPEG4,        MKTAG('B', 'L', 'Z', '0') },
     { AV_CODEC_ID_MPEG4,        MKTAG('m', 'p', '4', 'v') },
@@ -426,10 +427,14 @@ void ff_end_tag(AVIOContext *pb, int64_t start)
 {
     int64_t pos;
 
+    av_assert0((start&1) == 0);
+
     pos = avio_tell(pb);
+    if (pos & 1)
+        avio_w8(pb, 0);
     avio_seek(pb, start - 4, SEEK_SET);
     avio_wl32(pb, (uint32_t)(pos - start));
-    avio_seek(pb, pos, SEEK_SET);
+    avio_seek(pb, FFALIGN(pos, 2), SEEK_SET);
 }
 
 /* WAVEFORMATEX header */
diff --git a/mythtv/external/FFmpeg/libavformat/riff.h b/mythtv/external/FFmpeg/libavformat/riff.h
index 8579a953c86..70b2f761710 100644
--- a/mythtv/external/FFmpeg/libavformat/riff.h
+++ b/mythtv/external/FFmpeg/libavformat/riff.h
@@ -51,7 +51,7 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc);
 enum AVCodecID ff_wav_codec_get_id(unsigned int tag, int bps);
 int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size);
 
-extern const AVCodecTag ff_codec_bmp_tags[];
+extern const AVCodecTag ff_codec_bmp_tags[]; // exposed through avformat_get_riff_video_tags()
 extern const AVCodecTag ff_codec_wav_tags[];
 
 void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale);
diff --git a/mythtv/external/FFmpeg/libavformat/rmdec.c b/mythtv/external/FFmpeg/libavformat/rmdec.c
index 142567b3ad9..243c693343e 100644
--- a/mythtv/external/FFmpeg/libavformat/rmdec.c
+++ b/mythtv/external/FFmpeg/libavformat/rmdec.c
@@ -25,6 +25,7 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/dict.h"
 #include "avformat.h"
+#include "avio_internal.h"
 #include "internal.h"
 #include "rmsipr.h"
 #include "rm.h"
@@ -696,6 +697,10 @@ static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb,
 
     *pseq = seq;
     if((seq & 0x7F) == 1 || vst->curpic_num != pic_num){
+        if (len2 > ffio_limit(pb, len2)) {
+            av_log(s, AV_LOG_ERROR, "Impossibly sized packet\n");
+            return AVERROR_INVALIDDATA;
+        }
         vst->slices = ((hdr & 0x3F) << 1) + 1;
         vst->videobufsize = len2 + 8*vst->slices + 1;
         av_free_packet(&vst->pkt); //FIXME this should be output.
diff --git a/mythtv/external/FFmpeg/libavformat/rtmphttp.c b/mythtv/external/FFmpeg/libavformat/rtmphttp.c
index d21ac673159..3a51f7c429c 100644
--- a/mythtv/external/FFmpeg/libavformat/rtmphttp.c
+++ b/mythtv/external/FFmpeg/libavformat/rtmphttp.c
@@ -236,7 +236,7 @@ static int rtmp_http_open(URLContext *h, const char *uri, int flags)
             goto fail;
         }
     }
-    while (off > 0 && isspace(rt->client_id[off - 1]))
+    while (off > 0 && av_isspace(rt->client_id[off - 1]))
         off--;
     rt->client_id[off] = '\0';
 
diff --git a/mythtv/external/FFmpeg/libavformat/rtmpproto.c b/mythtv/external/FFmpeg/libavformat/rtmpproto.c
index fa661ee5528..598122a229e 100644
--- a/mythtv/external/FFmpeg/libavformat/rtmpproto.c
+++ b/mythtv/external/FFmpeg/libavformat/rtmpproto.c
@@ -50,7 +50,7 @@
 
 //#define DEBUG
 
-#define APP_MAX_LENGTH 128
+#define APP_MAX_LENGTH 1024
 #define PLAYPATH_MAX_LENGTH 256
 #define TCURL_MAX_LENGTH 512
 #define FLASHVER_MAX_LENGTH 64
@@ -312,7 +312,7 @@ static int gen_connect(URLContext *s, RTMPContext *rt)
     int ret;
 
     if ((ret = ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE,
-                                     0, 4096)) < 0)
+                                     0, 4096 + APP_MAX_LENGTH)) < 0)
         return ret;
 
     p = pkt.data;
diff --git a/mythtv/external/FFmpeg/libavformat/rtp.c b/mythtv/external/FFmpeg/libavformat/rtp.c
index c8eebac5cb2..c4dcf6ae8d4 100644
--- a/mythtv/external/FFmpeg/libavformat/rtp.c
+++ b/mythtv/external/FFmpeg/libavformat/rtp.c
@@ -24,24 +24,20 @@
 
 #include "rtp.h"
 
-//#define DEBUG
-
 /* from http://www.iana.org/assignments/rtp-parameters last updated 05 January 2005 */
 /* payload types >= 96 are dynamic;
  * payload types between 72 and 76 are reserved for RTCP conflict avoidance;
  * all the other payload types not present in the table are unassigned or
  * reserved
  */
-static const struct
-{
+static const struct {
     int pt;
     const char enc_name[6];
     enum AVMediaType codec_type;
     enum AVCodecID codec_id;
     int clock_rate;
     int audio_channels;
-} AVRtpPayloadTypes[]=
-{
+} rtp_payload_types[] = {
   {0, "PCMU",        AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_PCM_MULAW, 8000, 1},
   {3, "GSM",         AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_NONE, 8000, 1},
   {4, "G723",        AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_G723_1, 8000, 1},
@@ -75,15 +71,15 @@ int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type)
 {
     int i = 0;
 
-    for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++)
-        if (AVRtpPayloadTypes[i].pt == payload_type) {
-            if (AVRtpPayloadTypes[i].codec_id != AV_CODEC_ID_NONE) {
-                codec->codec_type = AVRtpPayloadTypes[i].codec_type;
-                codec->codec_id = AVRtpPayloadTypes[i].codec_id;
-                if (AVRtpPayloadTypes[i].audio_channels > 0)
-                    codec->channels = AVRtpPayloadTypes[i].audio_channels;
-                if (AVRtpPayloadTypes[i].clock_rate > 0)
-                    codec->sample_rate = AVRtpPayloadTypes[i].clock_rate;
+    for (i = 0; rtp_payload_types[i].pt >= 0; i++)
+        if (rtp_payload_types[i].pt == payload_type) {
+            if (rtp_payload_types[i].codec_id != AV_CODEC_ID_NONE) {
+                codec->codec_type = rtp_payload_types[i].codec_type;
+                codec->codec_id = rtp_payload_types[i].codec_id;
+                if (rtp_payload_types[i].audio_channels > 0)
+                    codec->channels = rtp_payload_types[i].audio_channels;
+                if (rtp_payload_types[i].clock_rate > 0)
+                    codec->sample_rate = rtp_payload_types[i].clock_rate;
                 return 0;
             }
         }
@@ -105,8 +101,8 @@ int ff_rtp_get_payload_type(AVFormatContext *fmt,
     }
 
     /* static payload type */
-    for (i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i)
-        if (AVRtpPayloadTypes[i].codec_id == codec->codec_id) {
+    for (i = 0; rtp_payload_types[i].pt >= 0; ++i)
+        if (rtp_payload_types[i].codec_id == codec->codec_id) {
             if (codec->codec_id == AV_CODEC_ID_H263 && (!fmt || !fmt->oformat ||
                 !fmt->oformat->priv_class || !fmt->priv_data ||
                 !av_opt_flag_is_set(fmt->priv_data, "rtpflags", "rfc2190")))
@@ -115,14 +111,14 @@ int ff_rtp_get_payload_type(AVFormatContext *fmt,
              * see section 4.5.2 in RFC 3551. */
             if (codec->codec_id == AV_CODEC_ID_ADPCM_G722 &&
                 codec->sample_rate == 16000 && codec->channels == 1)
-                return AVRtpPayloadTypes[i].pt;
+                return rtp_payload_types[i].pt;
             if (codec->codec_type == AVMEDIA_TYPE_AUDIO &&
-                ((AVRtpPayloadTypes[i].clock_rate > 0 &&
-                  codec->sample_rate != AVRtpPayloadTypes[i].clock_rate) ||
-                 (AVRtpPayloadTypes[i].audio_channels > 0 &&
-                  codec->channels != AVRtpPayloadTypes[i].audio_channels)))
+                ((rtp_payload_types[i].clock_rate > 0 &&
+                  codec->sample_rate != rtp_payload_types[i].clock_rate) ||
+                 (rtp_payload_types[i].audio_channels > 0 &&
+                  codec->channels != rtp_payload_types[i].audio_channels)))
                 continue;
-            return AVRtpPayloadTypes[i].pt;
+            return rtp_payload_types[i].pt;
         }
 
     if (idx < 0)
@@ -136,10 +132,9 @@ const char *ff_rtp_enc_name(int payload_type)
 {
     int i;
 
-    for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++)
-        if (AVRtpPayloadTypes[i].pt == payload_type) {
-            return AVRtpPayloadTypes[i].enc_name;
-        }
+    for (i = 0; rtp_payload_types[i].pt >= 0; i++)
+        if (rtp_payload_types[i].pt == payload_type)
+            return rtp_payload_types[i].enc_name;
 
     return "";
 }
@@ -148,10 +143,9 @@ enum AVCodecID ff_rtp_codec_id(const char *buf, enum AVMediaType codec_type)
 {
     int i;
 
-    for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++)
-        if (!strcmp(buf, AVRtpPayloadTypes[i].enc_name) && (codec_type == AVRtpPayloadTypes[i].codec_type)){
-            return AVRtpPayloadTypes[i].codec_id;
-        }
+    for (i = 0; rtp_payload_types[i].pt >= 0; i++)
+        if (!strcmp(buf, rtp_payload_types[i].enc_name) && (codec_type == rtp_payload_types[i].codec_type))
+            return rtp_payload_types[i].codec_id;
 
     return AV_CODEC_ID_NONE;
 }
diff --git a/mythtv/external/FFmpeg/libavformat/rtpdec.c b/mythtv/external/FFmpeg/libavformat/rtpdec.c
index 3bfa8783ce0..3d74f597298 100644
--- a/mythtv/external/FFmpeg/libavformat/rtpdec.c
+++ b/mythtv/external/FFmpeg/libavformat/rtpdec.c
@@ -24,12 +24,14 @@
 #include "libavutil/time.h"
 #include "libavcodec/get_bits.h"
 #include "avformat.h"
-#include "mpegts-mythtv.h"
 #include "network.h"
+#include "srtp.h"
 #include "url.h"
 #include "rtpdec.h"
 #include "rtpdec_formats.h"
 
+#define MIN_FEEDBACK_INTERVAL 200000 /* 200 ms in us */
+
 static RTPDynamicProtocolHandler realmedia_mp3_dynamic_handler = {
     .enc_name   = "X-MP3-draft-00",
     .codec_type = AVMEDIA_TYPE_AUDIO,
@@ -48,7 +50,6 @@ static RTPDynamicProtocolHandler opus_dynamic_handler = {
     .codec_id   = AV_CODEC_ID_OPUS,
 };
 
-/* statistics functions */
 static RTPDynamicProtocolHandler *rtp_first_dynamic_payload_handler = NULL;
 
 void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler)
@@ -59,39 +60,39 @@ void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler)
 
 void av_register_rtp_dynamic_payload_handlers(void)
 {
-    ff_register_dynamic_payload_handler(&ff_mp4v_es_dynamic_handler);
-    ff_register_dynamic_payload_handler(&ff_mpeg4_generic_dynamic_handler);
     ff_register_dynamic_payload_handler(&ff_amr_nb_dynamic_handler);
     ff_register_dynamic_payload_handler(&ff_amr_wb_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_g726_16_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_g726_24_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_g726_32_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_g726_40_dynamic_handler);
     ff_register_dynamic_payload_handler(&ff_h263_1998_dynamic_handler);
     ff_register_dynamic_payload_handler(&ff_h263_2000_dynamic_handler);
     ff_register_dynamic_payload_handler(&ff_h263_rfc2190_dynamic_handler);
     ff_register_dynamic_payload_handler(&ff_h264_dynamic_handler);
     ff_register_dynamic_payload_handler(&ff_ilbc_dynamic_handler);
     ff_register_dynamic_payload_handler(&ff_jpeg_dynamic_handler);
-    ff_register_dynamic_payload_handler(&ff_vorbis_dynamic_handler);
-    ff_register_dynamic_payload_handler(&ff_theora_dynamic_handler);
-    ff_register_dynamic_payload_handler(&ff_qdm2_dynamic_handler);
-    ff_register_dynamic_payload_handler(&ff_svq3_dynamic_handler);
     ff_register_dynamic_payload_handler(&ff_mp4a_latm_dynamic_handler);
-    ff_register_dynamic_payload_handler(&ff_vp8_dynamic_handler);
-    ff_register_dynamic_payload_handler(&ff_qcelp_dynamic_handler);
-    ff_register_dynamic_payload_handler(&realmedia_mp3_dynamic_handler);
-    ff_register_dynamic_payload_handler(&speex_dynamic_handler);
-    ff_register_dynamic_payload_handler(&opus_dynamic_handler);
-
+    ff_register_dynamic_payload_handler(&ff_mp4v_es_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_mpeg_audio_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_mpeg_video_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_mpeg4_generic_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_mpegts_dynamic_handler);
     ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfv_handler);
     ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfa_handler);
-
+    ff_register_dynamic_payload_handler(&ff_qcelp_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_qdm2_dynamic_handler);
     ff_register_dynamic_payload_handler(&ff_qt_rtp_aud_handler);
     ff_register_dynamic_payload_handler(&ff_qt_rtp_vid_handler);
     ff_register_dynamic_payload_handler(&ff_quicktime_rtp_aud_handler);
     ff_register_dynamic_payload_handler(&ff_quicktime_rtp_vid_handler);
-
-    ff_register_dynamic_payload_handler(&ff_g726_16_dynamic_handler);
-    ff_register_dynamic_payload_handler(&ff_g726_24_dynamic_handler);
-    ff_register_dynamic_payload_handler(&ff_g726_32_dynamic_handler);
-    ff_register_dynamic_payload_handler(&ff_g726_40_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_svq3_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_theora_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_vorbis_dynamic_handler);
+    ff_register_dynamic_payload_handler(&ff_vp8_dynamic_handler);
+    ff_register_dynamic_payload_handler(&opus_dynamic_handler);
+    ff_register_dynamic_payload_handler(&realmedia_mp3_dynamic_handler);
+    ff_register_dynamic_payload_handler(&speex_dynamic_handler);
 }
 
 RTPDynamicProtocolHandler *ff_rtp_handler_find_by_name(const char *name,
@@ -133,6 +134,7 @@ static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf,
                 return AVERROR_INVALIDDATA;
             }
 
+            s->last_rtcp_reception_time = av_gettime();
             s->last_rtcp_ntp_time  = AV_RB64(buf + 8);
             s->last_rtcp_timestamp = AV_RB32(buf + 16);
             if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE) {
@@ -226,6 +228,24 @@ static int rtp_valid_packet_in_sequence(RTPStatistics *s, uint16_t seq)
     return 1;
 }
 
+static void rtcp_update_jitter(RTPStatistics *s, uint32_t sent_timestamp,
+                               uint32_t arrival_timestamp)
+{
+    // Most of this is pretty straight from RFC 3550 appendix A.8
+    uint32_t transit = arrival_timestamp - sent_timestamp;
+    uint32_t prev_transit = s->transit;
+    int32_t d = transit - prev_transit;
+    // Doing the FFABS() call directly on the "transit - prev_transit"
+    // expression doesn't work, since it's an unsigned expression. Doing the
+    // transit calculation in unsigned is desired though, since it most
+    // probably will need to wrap around.
+    d = FFABS(d);
+    s->transit = transit;
+    if (!prev_transit)
+        return;
+    s->jitter += d - (int32_t) ((s->jitter + 8) >> 4);
+}
+
 int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd,
                                   AVIOContext *avio, int count)
 {
@@ -238,10 +258,9 @@ int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd,
     uint32_t extended_max;
     uint32_t expected_interval;
     uint32_t received_interval;
-    uint32_t lost_interval;
+    int32_t  lost_interval;
     uint32_t expected;
     uint32_t fraction;
-    uint64_t ntp_time = s->last_rtcp_ntp_time; // TODO: Get local ntp time?
 
     if ((!fd && !avio) || (count < 1))
         return -1;
@@ -271,7 +290,7 @@ int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd,
     // some placeholders we should really fill...
     // RFC 1889/p64
     extended_max          = stats->cycles + stats->max_seq;
-    expected              = extended_max - stats->base_seq + 1;
+    expected              = extended_max - stats->base_seq;
     lost                  = expected - stats->received;
     lost                  = FFMIN(lost, 0xffffff); // clamp it since it's only 24 bits...
     expected_interval     = expected - stats->expected_prior;
@@ -295,7 +314,8 @@ int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd,
         avio_wb32(pb, 0); /* delay since last SR */
     } else {
         uint32_t middle_32_bits   = s->last_rtcp_ntp_time >> 16; // this is valid, right? do we need to handle 64 bit values special?
-        uint32_t delay_since_last = ntp_time - s->last_rtcp_ntp_time;
+        uint32_t delay_since_last = av_rescale(av_gettime() - s->last_rtcp_reception_time,
+                                               65536, AV_TIME_BASE);
 
         avio_wb32(pb, middle_32_bits); /* last SR timestamp */
         avio_wb32(pb, delay_since_last); /* delay since last SR */
@@ -305,13 +325,14 @@ int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd,
     avio_w8(pb, (RTP_VERSION << 6) + 1); /* 1 report block */
     avio_w8(pb, RTCP_SDES);
     len = strlen(s->hostname);
-    avio_wb16(pb, (6 + len + 3) / 4); /* length in words - 1 */
+    avio_wb16(pb, (7 + len + 3) / 4); /* length in words - 1 */
     avio_wb32(pb, s->ssrc + 1);
     avio_w8(pb, 0x01);
     avio_w8(pb, len);
     avio_write(pb, s->hostname, len);
+    avio_w8(pb, 0); /* END */
     // padding
-    for (len = (6 + len) % 4; len % 4; len++)
+    for (len = (7 + len) % 4; len % 4; len++)
         avio_w8(pb, 0);
 
     avio_flush(pb);
@@ -366,10 +387,103 @@ void ff_rtp_send_punch_packets(URLContext *rtp_handle)
     av_free(buf);
 }
 
+static int find_missing_packets(RTPDemuxContext *s, uint16_t *first_missing,
+                                uint16_t *missing_mask)
+{
+    int i;
+    uint16_t next_seq = s->seq + 1;
+    RTPPacket *pkt = s->queue;
+
+    if (!pkt || pkt->seq == next_seq)
+        return 0;
+
+    *missing_mask = 0;
+    for (i = 1; i <= 16; i++) {
+        uint16_t missing_seq = next_seq + i;
+        while (pkt) {
+            int16_t diff = pkt->seq - missing_seq;
+            if (diff >= 0)
+                break;
+            pkt = pkt->next;
+        }
+        if (!pkt)
+            break;
+        if (pkt->seq == missing_seq)
+            continue;
+        *missing_mask |= 1 << (i - 1);
+    }
+
+    *first_missing = next_seq;
+    return 1;
+}
+
+int ff_rtp_send_rtcp_feedback(RTPDemuxContext *s, URLContext *fd,
+                              AVIOContext *avio)
+{
+    int len, need_keyframe, missing_packets;
+    AVIOContext *pb;
+    uint8_t *buf;
+    int64_t now;
+    uint16_t first_missing = 0, missing_mask = 0;
+
+    if (!fd && !avio)
+        return -1;
+
+    need_keyframe = s->handler && s->handler->need_keyframe &&
+                    s->handler->need_keyframe(s->dynamic_protocol_context);
+    missing_packets = find_missing_packets(s, &first_missing, &missing_mask);
+
+    if (!need_keyframe && !missing_packets)
+        return 0;
+
+    /* Send new feedback if enough time has elapsed since the last
+     * feedback packet. */
+
+    now = av_gettime();
+    if (s->last_feedback_time &&
+        (now - s->last_feedback_time) < MIN_FEEDBACK_INTERVAL)
+        return 0;
+    s->last_feedback_time = now;
+
+    if (!fd)
+        pb = avio;
+    else if (avio_open_dyn_buf(&pb) < 0)
+        return -1;
+
+    if (need_keyframe) {
+        avio_w8(pb, (RTP_VERSION << 6) | 1); /* PLI */
+        avio_w8(pb, RTCP_PSFB);
+        avio_wb16(pb, 2); /* length in words - 1 */
+        // our own SSRC: we use the server's SSRC + 1 to avoid conflicts
+        avio_wb32(pb, s->ssrc + 1);
+        avio_wb32(pb, s->ssrc); // server SSRC
+    }
+
+    if (missing_packets) {
+        avio_w8(pb, (RTP_VERSION << 6) | 1); /* NACK */
+        avio_w8(pb, RTCP_RTPFB);
+        avio_wb16(pb, 3); /* length in words - 1 */
+        avio_wb32(pb, s->ssrc + 1);
+        avio_wb32(pb, s->ssrc); // server SSRC
+
+        avio_wb16(pb, first_missing);
+        avio_wb16(pb, missing_mask);
+    }
+
+    avio_flush(pb);
+    if (!fd)
+        return 0;
+    len = avio_close_dyn_buf(pb, &buf);
+    if (len > 0 && buf) {
+        ffurl_write(fd, buf, len);
+        av_free(buf);
+    }
+    return 0;
+}
+
 /**
  * open a new RTP parse context for stream 'st'. 'st' can be NULL for
- * MPEG2-TS streams to indicate that they should be demuxed inside the
- * rtp demux (otherwise AV_CODEC_ID_MPEG2TS packets are returned)
+ * MPEG2-TS streams.
  */
 RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st,
                                    int payload_type, int queue_size)
@@ -385,27 +499,9 @@ RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st,
     s->ic                  = s1;
     s->st                  = st;
     s->queue_size          = queue_size;
-    rtp_init_statistics(&s->statistics, 0); // do we know the initial sequence from sdp?
-    if (!strcmp(ff_rtp_enc_name(payload_type), "MP2T")) {
-        s->ts = ff_mpegts_parse_open(s->ic);
-        if (s->ts == NULL) {
-            av_free(s);
-            return NULL;
-        }
-    } else if (st) {
+    rtp_init_statistics(&s->statistics, 0);
+    if (st) {
         switch (st->codec->codec_id) {
-        case AV_CODEC_ID_MPEG1VIDEO:
-        case AV_CODEC_ID_MPEG2VIDEO:
-        case AV_CODEC_ID_MP2:
-        case AV_CODEC_ID_MP3:
-        case AV_CODEC_ID_MPEG4:
-        case AV_CODEC_ID_H263:
-        case AV_CODEC_ID_H264:
-            st->need_parsing = AVSTREAM_PARSE_FULL;
-            break;
-        case AV_CODEC_ID_VORBIS:
-            st->need_parsing = AVSTREAM_PARSE_HEADERS;
-            break;
         case AV_CODEC_ID_ADPCM_G722:
             /* According to RFC 3551, the stream clock rate is 8000
              * even if the sample rate is 16000. */
@@ -425,7 +521,14 @@ void ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx,
                                        RTPDynamicProtocolHandler *handler)
 {
     s->dynamic_protocol_context = ctx;
-    s->parse_packet             = handler->parse_packet;
+    s->handler                  = handler;
+}
+
+void ff_rtp_parse_set_crypto(RTPDemuxContext *s, const char *suite,
+                             const char *params)
+{
+    if (!ff_srtp_set_crypto(&s->srtp, suite, params))
+        s->srtp_enabled = 1;
 }
 
 /**
@@ -470,13 +573,14 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam
 static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt,
                                      const uint8_t *buf, int len)
 {
-    unsigned int ssrc, h;
-    int payload_type, seq, ret, flags = 0;
-    int ext;
+    unsigned int ssrc;
+    int payload_type, seq, flags = 0;
+    int ext, csrc;
     AVStream *st;
     uint32_t timestamp;
     int rv = 0;
 
+    csrc         = buf[0] & 0x0f;
     ext          = buf[0] & 0x10;
     payload_type = buf[1] & 0x7f;
     if (buf[1] & 0x80)
@@ -510,6 +614,11 @@ static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt,
     len   -= 12;
     buf   += 12;
 
+    len   -= 4 * csrc;
+    buf   += 4 * csrc;
+    if (len < 0)
+        return AVERROR_INVALIDDATA;
+
     /* RFC 3550 Section 5.3.1 RTP Header Extension handling */
     if (ext) {
         if (len < 4)
@@ -525,67 +634,17 @@ static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt,
         buf += ext;
     }
 
-    if (!st) {
-        /* specific MPEG2-TS demux support */
-        ret = ff_mpegts_parse_packet(s->ts, pkt, buf, len);
-        /* The only error that can be returned from ff_mpegts_parse_packet
-         * is "no more data to return from the provided buffer", so return
-         * AVERROR(EAGAIN) for all errors */
-        if (ret < 0)
-            return AVERROR(EAGAIN);
-        if (ret < len) {
-            s->read_buf_size = FFMIN(len - ret, sizeof(s->buf));
-            memcpy(s->buf, buf + ret, s->read_buf_size);
-            s->read_buf_index = 0;
-            return 1;
-        }
-        return 0;
-    } else if (s->parse_packet) {
-        rv = s->parse_packet(s->ic, s->dynamic_protocol_context,
-                             s->st, pkt, ×tamp, buf, len, seq, flags);
-    } else {
-        /* At this point, the RTP header has been stripped;
-         * This is ASSUMING that there is only 1 CSRC, which isn't wise. */
-        switch (st->codec->codec_id) {
-        case AV_CODEC_ID_MP2:
-        case AV_CODEC_ID_MP3:
-            /* better than nothing: skip MPEG audio RTP header */
-            if (len <= 4)
-                return -1;
-            h    = AV_RB32(buf);
-            len -= 4;
-            buf += 4;
-            if (av_new_packet(pkt, len) < 0)
-                return AVERROR(ENOMEM);
-            memcpy(pkt->data, buf, len);
-            break;
-        case AV_CODEC_ID_MPEG1VIDEO:
-        case AV_CODEC_ID_MPEG2VIDEO:
-            /* better than nothing: skip MPEG video RTP header */
-            if (len <= 4)
-                return -1;
-            h    = AV_RB32(buf);
-            buf += 4;
-            len -= 4;
-            if (h & (1 << 26)) {
-                /* MPEG-2 */
-                if (len <= 4)
-                    return -1;
-                buf += 4;
-                len -= 4;
-            }
-            if (av_new_packet(pkt, len) < 0)
-                return AVERROR(ENOMEM);
-            memcpy(pkt->data, buf, len);
-            break;
-        default:
-            if (av_new_packet(pkt, len) < 0)
-                return AVERROR(ENOMEM);
-            memcpy(pkt->data, buf, len);
-            break;
-        }
-
+    if (s->handler && s->handler->parse_packet) {
+        rv = s->handler->parse_packet(s->ic, s->dynamic_protocol_context,
+                                      s->st, pkt, ×tamp, buf, len, seq,
+                                      flags);
+    } else if (st) {
+        if ((rv = av_new_packet(pkt, len)) < 0)
+            return rv;
+        memcpy(pkt->data, buf, len);
         pkt->stream_index = st->index;
+    } else {
+        return AVERROR(EINVAL);
     }
 
     // now perform timestamp things....
@@ -610,15 +669,14 @@ void ff_rtp_reset_packet_queue(RTPDemuxContext *s)
 static void enqueue_packet(RTPDemuxContext *s, uint8_t *buf, int len)
 {
     uint16_t seq   = AV_RB16(buf + 2);
-    RTPPacket *cur = s->queue, *prev = NULL, *packet;
+    RTPPacket **cur = &s->queue, *packet;
 
     /* Find the correct place in the queue to insert the packet */
-    while (cur) {
-        int16_t diff = seq - cur->seq;
+    while (*cur) {
+        int16_t diff = seq - (*cur)->seq;
         if (diff < 0)
             break;
-        prev = cur;
-        cur  = cur->next;
+        cur = &(*cur)->next;
     }
 
     packet = av_mallocz(sizeof(*packet));
@@ -628,11 +686,8 @@ static void enqueue_packet(RTPDemuxContext *s, uint8_t *buf, int len)
     packet->seq      = seq;
     packet->len      = len;
     packet->buf      = buf;
-    packet->next     = cur;
-    if (prev)
-        prev->next = packet;
-    else
-        s->queue = packet;
+    packet->next     = *cur;
+    *cur = packet;
     s->queue_len++;
 }
 
@@ -672,7 +727,7 @@ static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
                                 uint8_t **bufptr, int len)
 {
     uint8_t *buf = bufptr ? *bufptr : NULL;
-    int ret, flags = 0;
+    int flags = 0;
     uint32_t timestamp;
     int rv = 0;
 
@@ -683,28 +738,15 @@ static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
         if (s->prev_ret <= 0)
             return rtp_parse_queued_packet(s, pkt);
         /* return the next packets, if any */
-        if (s->st && s->parse_packet) {
+        if (s->handler && s->handler->parse_packet) {
             /* timestamp should be overwritten by parse_packet, if not,
              * the packet is left with pts == AV_NOPTS_VALUE */
             timestamp = RTP_NOTS_VALUE;
-            rv        = s->parse_packet(s->ic, s->dynamic_protocol_context,
-                                        s->st, pkt, ×tamp, NULL, 0, 0,
-                                        flags);
+            rv        = s->handler->parse_packet(s->ic, s->dynamic_protocol_context,
+                                                 s->st, pkt, ×tamp, NULL, 0, 0,
+                                                 flags);
             finalize_packet(s, pkt, timestamp);
             return rv;
-        } else {
-            // TODO: Move to a dynamic packet handler (like above)
-            if (s->read_buf_index >= s->read_buf_size)
-                return AVERROR(EAGAIN);
-            ret = ff_mpegts_parse_packet(s->ts, pkt, s->buf + s->read_buf_index,
-                                         s->read_buf_size - s->read_buf_index);
-            if (ret < 0)
-                return AVERROR(EAGAIN);
-            s->read_buf_index += ret;
-            if (s->read_buf_index < s->read_buf_size)
-                return 1;
-            else
-                return 0;
         }
     }
 
@@ -717,6 +759,16 @@ static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
         return rtcp_parse_packet(s, buf, len);
     }
 
+    if (s->st) {
+        int64_t received = av_gettime();
+        uint32_t arrival_ts = av_rescale_q(received, AV_TIME_BASE_Q,
+                                           s->st->time_base);
+        timestamp = AV_RB32(buf + 4);
+        // Calculate the jitter immediately, before queueing the packet
+        // into the reordering queue.
+        rtcp_update_jitter(&s->statistics, timestamp, arrival_ts);
+    }
+
     if ((s->seq == 0 && !s->queue) || s->queue_size <= 1) {
         /* First packet, or no reordering */
         return rtp_parse_packet_internal(s, pkt, buf, len);
@@ -757,7 +809,10 @@ static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
 int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
                         uint8_t **bufptr, int len)
 {
-    int rv = rtp_parse_one_packet(s, pkt, bufptr, len);
+    int rv;
+    if (s->srtp_enabled && bufptr && ff_srtp_decrypt(&s->srtp, *bufptr, &len) < 0)
+        return -1;
+    rv = rtp_parse_one_packet(s, pkt, bufptr, len);
     s->prev_ret = rv;
     while (rv == AVERROR(EAGAIN) && has_next_packet(s))
         rv = rtp_parse_queued_packet(s, pkt);
@@ -767,9 +822,7 @@ int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
 void ff_rtp_parse_close(RTPDemuxContext *s)
 {
     ff_rtp_reset_packet_queue(s);
-    if (!strcmp(ff_rtp_enc_name(s->payload_type), "MP2T")) {
-        ff_mpegts_parse_close(s->ts);
-    }
+    ff_srtp_free(&s->srtp);
     av_free(s);
 }
 
diff --git a/mythtv/external/FFmpeg/libavformat/rtpdec.h b/mythtv/external/FFmpeg/libavformat/rtpdec.h
index d7ade3bb41e..e469c0f61ca 100644
--- a/mythtv/external/FFmpeg/libavformat/rtpdec.h
+++ b/mythtv/external/FFmpeg/libavformat/rtpdec.h
@@ -27,6 +27,7 @@
 #include "avformat.h"
 #include "rtp.h"
 #include "url.h"
+#include "srtp.h"
 
 typedef struct PayloadContext PayloadContext;
 typedef struct RTPDynamicProtocolHandler RTPDynamicProtocolHandler;
@@ -43,6 +44,8 @@ RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st,
                                    int payload_type, int queue_size);
 void ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx,
                                        RTPDynamicProtocolHandler *handler);
+void ff_rtp_parse_set_crypto(RTPDemuxContext *s, const char *suite,
+                             const char *params);
 int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
                         uint8_t **buf, int len);
 void ff_rtp_parse_close(RTPDemuxContext *s);
@@ -73,6 +76,8 @@ void ff_rtp_send_punch_packets(URLContext* rtp_handle);
  */
 int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd,
                                   AVIOContext *avio, int count);
+int ff_rtp_send_rtcp_feedback(RTPDemuxContext *s, URLContext *fd,
+                              AVIOContext *avio);
 
 // these statistics are used for rtcp receiver reports...
 typedef struct RTPStatistics {
@@ -81,9 +86,9 @@ typedef struct RTPStatistics {
     uint32_t base_seq;          ///< base sequence number
     uint32_t bad_seq;           ///< last bad sequence number + 1
     int probation;              ///< sequence packets till source is valid
-    int received;               ///< packets received
-    int expected_prior;         ///< packets expected in last interval
-    int received_prior;         ///< packets received in last interval
+    uint32_t received;          ///< packets received
+    uint32_t expected_prior;    ///< packets expected in last interval
+    uint32_t received_prior;    ///< packets received in last interval
     uint32_t transit;           ///< relative transit time for previous packet
     uint32_t jitter;            ///< estimated jitter.
 } RTPStatistics;
@@ -130,6 +135,7 @@ struct RTPDynamicProtocolHandler {
     void (*free)(PayloadContext *protocol_data);
     /** Parse handler for this dynamic packet */
     DynamicPayloadPacketHandlerProc parse_packet;
+    int (*need_keyframe)(PayloadContext *context);
 
     struct RTPDynamicProtocolHandler *next;
 };
@@ -154,12 +160,12 @@ struct RTPDemuxContext {
     int64_t  unwrapped_timestamp;
     int64_t  range_start_offset;
     int max_payload_size;
-    struct MpegTSContext *ts;   /* only used for MP2T payloads */
-    int read_buf_index;
-    int read_buf_size;
     /* used to send back RTCP RR */
     char hostname[256];
 
+    int srtp_enabled;
+    struct SRTPContext srtp;
+
     /** Statistics for this stream (used by RTCP receiver reports) */
     RTPStatistics statistics;
 
@@ -172,6 +178,7 @@ struct RTPDemuxContext {
 
     /* rtcp sender statistics receive */
     int64_t last_rtcp_ntp_time;
+    int64_t last_rtcp_reception_time;
     int64_t first_rtcp_ntp_time;
     uint32_t last_rtcp_timestamp;
     int64_t rtcp_ts_offset;
@@ -180,11 +187,10 @@ struct RTPDemuxContext {
     unsigned int packet_count;
     unsigned int octet_count;
     unsigned int last_octet_count;
-    /* buffer for partially parsed packets */
-    uint8_t buf[RTP_MAX_PACKET_LENGTH];
+    int64_t last_feedback_time;
 
     /* dynamic payload stuff */
-    DynamicPayloadPacketHandlerProc parse_packet;
+    const RTPDynamicProtocolHandler *handler;
     PayloadContext *dynamic_protocol_context;
 };
 
diff --git a/mythtv/external/FFmpeg/libavformat/rtpdec_formats.h b/mythtv/external/FFmpeg/libavformat/rtpdec_formats.h
index 6b6fcd3a2b8..9caeb5c71d8 100644
--- a/mythtv/external/FFmpeg/libavformat/rtpdec_formats.h
+++ b/mythtv/external/FFmpeg/libavformat/rtpdec_formats.h
@@ -49,7 +49,10 @@ extern RTPDynamicProtocolHandler ff_ilbc_dynamic_handler;
 extern RTPDynamicProtocolHandler ff_jpeg_dynamic_handler;
 extern RTPDynamicProtocolHandler ff_mp4a_latm_dynamic_handler;
 extern RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler;
+extern RTPDynamicProtocolHandler ff_mpeg_audio_dynamic_handler;
+extern RTPDynamicProtocolHandler ff_mpeg_video_dynamic_handler;
 extern RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler;
+extern RTPDynamicProtocolHandler ff_mpegts_dynamic_handler;
 extern RTPDynamicProtocolHandler ff_ms_rtp_asf_pfa_handler;
 extern RTPDynamicProtocolHandler ff_ms_rtp_asf_pfv_handler;
 extern RTPDynamicProtocolHandler ff_qcelp_dynamic_handler;
diff --git a/mythtv/external/FFmpeg/libavformat/rtpdec_h263.c b/mythtv/external/FFmpeg/libavformat/rtpdec_h263.c
index ce02dc1c21f..dd7aa60fd51 100644
--- a/mythtv/external/FFmpeg/libavformat/rtpdec_h263.c
+++ b/mythtv/external/FFmpeg/libavformat/rtpdec_h263.c
@@ -23,6 +23,14 @@
 #include "rtpdec_formats.h"
 #include "libavutil/intreadwrite.h"
 
+static int h263_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
+{
+    if (st_index < 0)
+        return 0;
+    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
+    return 0;
+}
+
 int ff_h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                           AVStream *st, AVPacket *pkt, uint32_t *timestamp,
                           const uint8_t *buf, int len, uint16_t seq, int flags)
@@ -92,6 +100,7 @@ RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler = {
     .enc_name         = "H263-1998",
     .codec_type       = AVMEDIA_TYPE_VIDEO,
     .codec_id         = AV_CODEC_ID_H263,
+    .init             = h263_init,
     .parse_packet     = ff_h263_handle_packet,
 };
 
@@ -99,5 +108,6 @@ RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler = {
     .enc_name         = "H263-2000",
     .codec_type       = AVMEDIA_TYPE_VIDEO,
     .codec_id         = AV_CODEC_ID_H263,
+    .init             = h263_init,
     .parse_packet     = ff_h263_handle_packet,
 };
diff --git a/mythtv/external/FFmpeg/libavformat/rtpdec_h263_rfc2190.c b/mythtv/external/FFmpeg/libavformat/rtpdec_h263_rfc2190.c
index 4792a9fdc5f..4b6e9967701 100644
--- a/mythtv/external/FFmpeg/libavformat/rtpdec_h263_rfc2190.c
+++ b/mythtv/external/FFmpeg/libavformat/rtpdec_h263_rfc2190.c
@@ -55,6 +55,14 @@ static void h263_free_context(PayloadContext *data)
     av_free(data);
 }
 
+static int h263_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
+{
+    if (st_index < 0)
+        return 0;
+    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
+    return 0;
+}
+
 static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                               AVStream *st, AVPacket *pkt, uint32_t *timestamp,
                               const uint8_t *buf, int len, uint16_t seq,
@@ -198,6 +206,7 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
 RTPDynamicProtocolHandler ff_h263_rfc2190_dynamic_handler = {
     .codec_type        = AVMEDIA_TYPE_VIDEO,
     .codec_id          = AV_CODEC_ID_H263,
+    .init              = h263_init,
     .parse_packet      = h263_handle_packet,
     .alloc             = h263_new_context,
     .free              = h263_free_context,
diff --git a/mythtv/external/FFmpeg/libavformat/rtpdec_h264.c b/mythtv/external/FFmpeg/libavformat/rtpdec_h264.c
index 2cab9c917c8..d1133b78e1b 100644
--- a/mythtv/external/FFmpeg/libavformat/rtpdec_h264.c
+++ b/mythtv/external/FFmpeg/libavformat/rtpdec_h264.c
@@ -338,6 +338,14 @@ static void h264_free_context(PayloadContext *data)
     av_free(data);
 }
 
+static int h264_init(AVFormatContext *s, int st_index, PayloadContext *data)
+{
+    if (st_index < 0)
+        return 0;
+    s->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
+    return 0;
+}
+
 static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
                                PayloadContext *h264_data, const char *line)
 {
@@ -383,6 +391,7 @@ RTPDynamicProtocolHandler ff_h264_dynamic_handler = {
     .enc_name         = "H264",
     .codec_type       = AVMEDIA_TYPE_VIDEO,
     .codec_id         = AV_CODEC_ID_H264,
+    .init             = h264_init,
     .parse_sdp_a_line = parse_h264_sdp_line,
     .alloc            = h264_new_context,
     .free             = h264_free_context,
diff --git a/mythtv/external/FFmpeg/libavformat/rtpdec_mpeg12.c b/mythtv/external/FFmpeg/libavformat/rtpdec_mpeg12.c
new file mode 100644
index 00000000000..82e58a097ab
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavformat/rtpdec_mpeg12.c
@@ -0,0 +1,72 @@
+/*
+ * Common code for the RTP depacketization of MPEG-1/2 formats.
+ * Copyright (c) 2002 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "rtpdec_formats.h"
+#include "libavutil/intreadwrite.h"
+
+static int mpeg_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
+{
+    if (st_index < 0)
+        return 0;
+    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
+    return 0;
+}
+
+static int mpeg_parse_packet(AVFormatContext *ctx, PayloadContext *data,
+                             AVStream *st, AVPacket *pkt, uint32_t *timestamp,
+                             const uint8_t *buf, int len, uint16_t seq,
+                             int flags)
+{
+    unsigned int h;
+    if (len <= 4)
+        return AVERROR_INVALIDDATA;
+    h    = AV_RB32(buf);
+    buf += 4;
+    len -= 4;
+    if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && h & (1 << 26)) {
+        /* MPEG-2 */
+        if (len <= 4)
+            return AVERROR_INVALIDDATA;
+        buf += 4;
+        len -= 4;
+    }
+    if (av_new_packet(pkt, len) < 0)
+        return AVERROR(ENOMEM);
+    memcpy(pkt->data, buf, len);
+    pkt->stream_index = st->index;
+    return 0;
+}
+
+RTPDynamicProtocolHandler ff_mpeg_audio_dynamic_handler = {
+    .codec_type        = AVMEDIA_TYPE_AUDIO,
+    .codec_id          = AV_CODEC_ID_MP3,
+    .init              = mpeg_init,
+    .parse_packet      = mpeg_parse_packet,
+    .static_payload_id = 14,
+};
+
+RTPDynamicProtocolHandler ff_mpeg_video_dynamic_handler = {
+    .codec_type        = AVMEDIA_TYPE_VIDEO,
+    .codec_id          = AV_CODEC_ID_MPEG2VIDEO,
+    .init              = mpeg_init,
+    .parse_packet      = mpeg_parse_packet,
+    .static_payload_id = 32,
+};
diff --git a/mythtv/external/FFmpeg/libavformat/rtpdec_mpeg4.c b/mythtv/external/FFmpeg/libavformat/rtpdec_mpeg4.c
index a3f60d348d8..3f1f244b83d 100644
--- a/mythtv/external/FFmpeg/libavformat/rtpdec_mpeg4.c
+++ b/mythtv/external/FFmpeg/libavformat/rtpdec_mpeg4.c
@@ -57,6 +57,9 @@ struct PayloadContext {
     int nb_au_headers;
     int au_headers_length_bytes;
     int cur_au_index;
+
+    uint8_t buf[RTP_MAX_PACKET_LENGTH];
+    int buf_pos, buf_size;
 };
 
 typedef struct {
@@ -109,11 +112,14 @@ static int parse_fmtp_config(AVCodecContext *codec, char *value)
     return 0;
 }
 
-static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf)
+static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len)
 {
     int au_headers_length, au_header_size, i;
     GetBitContext getbitcontext;
 
+    if (len < 2)
+        return AVERROR_INVALIDDATA;
+
     /* decode the first 2 bytes where the AUHeader sections are stored
        length in bits */
     au_headers_length = AV_RB16(buf);
@@ -125,6 +131,10 @@ static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf)
 
     /* skip AU headers length section (2 bytes) */
     buf += 2;
+    len -= 2;
+
+    if (len < data->au_headers_length_bytes)
+        return AVERROR_INVALIDDATA;
 
     init_get_bits(&getbitcontext, buf, data->au_headers_length_bytes * 8);
 
@@ -137,21 +147,16 @@ static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf)
     if (!data->au_headers || data->au_headers_allocated < data->nb_au_headers) {
         av_free(data->au_headers);
         data->au_headers = av_malloc(sizeof(struct AUHeaders) * data->nb_au_headers);
+        if (!data->au_headers)
+            return AVERROR(ENOMEM);
         data->au_headers_allocated = data->nb_au_headers;
     }
 
-    /* XXX: We handle multiple AU Section as only one (need to fix this for interleaving)
-       In my test, the FAAD decoder does not behave correctly when sending each AU one by one
-       but does when sending the whole as one big packet...  */
-    data->au_headers[0].size = 0;
-    data->au_headers[0].index = 0;
     for (i = 0; i < data->nb_au_headers; ++i) {
-        data->au_headers[0].size += get_bits_long(&getbitcontext, data->sizelength);
-        data->au_headers[0].index = get_bits_long(&getbitcontext, data->indexlength);
+        data->au_headers[i].size  = get_bits_long(&getbitcontext, data->sizelength);
+        data->au_headers[i].index = get_bits_long(&getbitcontext, data->indexlength);
     }
 
-    data->nb_au_headers = 1;
-
     return 0;
 }
 
@@ -162,18 +167,45 @@ static int aac_parse_packet(AVFormatContext *ctx, PayloadContext *data,
                             const uint8_t *buf, int len, uint16_t seq,
                             int flags)
 {
-    if (rtp_parse_mp4_au(data, buf))
+    int ret;
+
+    if (!buf) {
+        if (data->cur_au_index > data->nb_au_headers)
+            return AVERROR_INVALIDDATA;
+        if (data->buf_size - data->buf_pos < data->au_headers[data->cur_au_index].size)
+            return AVERROR_INVALIDDATA;
+        if ((ret = av_new_packet(pkt, data->au_headers[data->cur_au_index].size)) < 0)
+            return ret;
+        memcpy(pkt->data, &data->buf[data->buf_pos], data->au_headers[data->cur_au_index].size);
+        data->buf_pos += data->au_headers[data->cur_au_index].size;
+        pkt->stream_index = st->index;
+        data->cur_au_index++;
+        return data->cur_au_index < data->nb_au_headers;
+    }
+
+    if (rtp_parse_mp4_au(data, buf, len))
         return -1;
 
     buf += data->au_headers_length_bytes + 2;
     len -= data->au_headers_length_bytes + 2;
 
-    /* XXX: Fixme we only handle the case where rtp_parse_mp4_au define
-                    one au_header */
-    av_new_packet(pkt, data->au_headers[0].size);
+    if (len < data->au_headers[0].size)
+        return AVERROR_INVALIDDATA;
+    if ((ret = av_new_packet(pkt, data->au_headers[0].size)) < 0)
+        return ret;
     memcpy(pkt->data, buf, data->au_headers[0].size);
-
+    len -= data->au_headers[0].size;
+    buf += data->au_headers[0].size;
     pkt->stream_index = st->index;
+
+    if (len > 0 && data->nb_au_headers > 1) {
+        data->buf_size = FFMIN(len, sizeof(data->buf));
+        memcpy(data->buf, buf, data->buf_size);
+        data->cur_au_index = 1;
+        data->buf_pos = 0;
+        return 1;
+    }
+
     return 0;
 }
 
@@ -220,10 +252,19 @@ static int parse_sdp_line(AVFormatContext *s, int st_index,
     return 0;
 }
 
+static int init_video(AVFormatContext *s, int st_index, PayloadContext *data)
+{
+    if (st_index < 0)
+        return 0;
+    s->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
+    return 0;
+}
+
 RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler = {
     .enc_name           = "MP4V-ES",
     .codec_type         = AVMEDIA_TYPE_VIDEO,
     .codec_id           = AV_CODEC_ID_MPEG4,
+    .init               = init_video,
     .parse_sdp_a_line   = parse_sdp_line,
 };
 
diff --git a/mythtv/external/FFmpeg/libavformat/rtpdec_mpegts.c b/mythtv/external/FFmpeg/libavformat/rtpdec_mpegts.c
new file mode 100644
index 00000000000..c0b1442a910
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavformat/rtpdec_mpegts.c
@@ -0,0 +1,106 @@
+/*
+ * RTP MPEG2TS depacketizer
+ * Copyright (c) 2003 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "mpegts-mythtv.h"
+#include "rtpdec_formats.h"
+
+struct PayloadContext {
+    struct MpegTSContext *ts;
+    int read_buf_index;
+    int read_buf_size;
+    uint8_t buf[RTP_MAX_PACKET_LENGTH];
+};
+
+static PayloadContext *mpegts_new_context(void)
+{
+    return av_mallocz(sizeof(PayloadContext));
+}
+
+static void mpegts_free_context(PayloadContext *data)
+{
+    if (!data)
+        return;
+    if (data->ts)
+        ff_mpegts_parse_close(data->ts);
+    av_free(data);
+}
+
+static int mpegts_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
+{
+    data->ts = ff_mpegts_parse_open(ctx);
+    if (!data->ts)
+        return AVERROR(ENOMEM);
+    return 0;
+}
+
+static int mpegts_handle_packet(AVFormatContext *ctx, PayloadContext *data,
+                                AVStream *st, AVPacket *pkt, uint32_t *timestamp,
+                                const uint8_t *buf, int len, uint16_t seq,
+                                int flags)
+{
+    int ret;
+
+    // We don't want to use the RTP timestamps at all. If the mpegts demuxer
+    // doesn't set any pts/dts, the generic rtpdec code shouldn't try to
+    // fill it in either, since the mpegts and RTP timestamps are in totally
+    // different ranges.
+    *timestamp = RTP_NOTS_VALUE;
+
+    if (!data->ts)
+        return AVERROR(EINVAL);
+
+    if (!buf) {
+        if (data->read_buf_index >= data->read_buf_size)
+            return AVERROR(EAGAIN);
+        ret = ff_mpegts_parse_packet(data->ts, pkt, data->buf + data->read_buf_index,
+                                     data->read_buf_size - data->read_buf_index);
+        if (ret < 0)
+            return AVERROR(EAGAIN);
+        data->read_buf_index += ret;
+        if (data->read_buf_index < data->read_buf_size)
+            return 1;
+        else
+            return 0;
+    }
+
+    ret = ff_mpegts_parse_packet(data->ts, pkt, buf, len);
+    /* The only error that can be returned from ff_mpegts_parse_packet
+     * is "no more data to return from the provided buffer", so return
+     * AVERROR(EAGAIN) for all errors */
+    if (ret < 0)
+        return AVERROR(EAGAIN);
+    if (ret < len) {
+        data->read_buf_size = FFMIN(len - ret, sizeof(data->buf));
+        memcpy(data->buf, buf + ret, data->read_buf_size);
+        data->read_buf_index = 0;
+        return 1;
+    }
+    return 0;
+}
+
+RTPDynamicProtocolHandler ff_mpegts_dynamic_handler = {
+    .codec_type        = AVMEDIA_TYPE_DATA,
+    .parse_packet      = mpegts_handle_packet,
+    .alloc             = mpegts_new_context,
+    .init              = mpegts_init,
+    .free              = mpegts_free_context,
+    .static_payload_id = 33,
+};
diff --git a/mythtv/external/FFmpeg/libavformat/rtpdec_vp8.c b/mythtv/external/FFmpeg/libavformat/rtpdec_vp8.c
index bfac77d6ef9..b4b4f2207d0 100644
--- a/mythtv/external/FFmpeg/libavformat/rtpdec_vp8.c
+++ b/mythtv/external/FFmpeg/libavformat/rtpdec_vp8.c
@@ -35,11 +35,21 @@ struct PayloadContext {
     AVIOContext *data;
     uint32_t     timestamp;
     int          is_keyframe;
+    /* If sequence_ok is set, we keep returning data (even if we might have
+     * lost some data, but we haven't lost any too critical data that would
+     * cause the decoder to desynchronize and output random garbage).
+     */
     int          sequence_ok;
     int          first_part_size;
     uint16_t     prev_seq;
     int          prev_pictureid;
     int          broken_frame;
+    /* If sequence_dirty is set, we have lost some data (critical or
+     * non-critical) and decoding will have some sort of artefacts, and
+     * we thus should request a new keyframe.
+     */
+    int          sequence_dirty;
+    int          got_keyframe;
 };
 
 static void vp8_free_buffer(PayloadContext *vp8)
@@ -70,15 +80,18 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8,
     int extended_bits, part_id;
     int pictureid_present = 0, tl0picidx_present = 0, tid_present = 0,
         keyidx_present = 0;
-    int pictureid = -1, pictureid_mask;
+    int pictureid = -1, pictureid_mask = 0;
     int returned_old_frame = 0;
-    uint32_t old_timestamp;
+    uint32_t old_timestamp = 0;
 
     if (!buf) {
         if (vp8->data) {
             int ret = ff_rtp_finalize_packet(pkt, &vp8->data, st->index);
             if (ret < 0)
                 return ret;
+            *timestamp = vp8->timestamp;
+            if (vp8->sequence_dirty)
+                pkt->flags |= AV_PKT_FLAG_CORRUPT;
             return 0;
         }
         return AVERROR(EAGAIN);
@@ -140,11 +153,15 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8,
             vp8_free_buffer(vp8);
             // Keyframe, decoding ok again
             vp8->sequence_ok = 1;
+            vp8->sequence_dirty = 0;
+            vp8->got_keyframe = 1;
         } else {
             int can_continue = vp8->data && !vp8->is_keyframe &&
                                avio_tell(vp8->data) >= vp8->first_part_size;
             if (!vp8->sequence_ok)
                 return AVERROR(EAGAIN);
+            if (!vp8->got_keyframe)
+                return vp8_broken_sequence(ctx, vp8, "Keyframe missing\n");
             if (pictureid >= 0) {
                 if (pictureid != ((vp8->prev_pictureid + 1) & pictureid_mask)) {
                     return vp8_broken_sequence(ctx, vp8,
@@ -178,11 +195,12 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8,
                 }
             }
             if (vp8->data) {
+                vp8->sequence_dirty = 1;
                 if (avio_tell(vp8->data) >= vp8->first_part_size) {
                     int ret = ff_rtp_finalize_packet(pkt, &vp8->data, st->index);
                     if (ret < 0)
                         return ret;
-                    pkt->size = vp8->first_part_size;
+                    pkt->flags |= AV_PKT_FLAG_CORRUPT;
                     returned_old_frame = 1;
                     old_timestamp = vp8->timestamp;
                 } else {
@@ -206,11 +224,8 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8,
 
         if (vp8->timestamp != *timestamp) {
             // Missed the start of the new frame, sequence broken
-            vp8->sequence_ok = 0;
-            av_log(ctx, AV_LOG_WARNING,
-                   "Received no start marker; dropping frame\n");
-            vp8_free_buffer(vp8);
-            return AVERROR(EAGAIN);
+            return vp8_broken_sequence(ctx, vp8,
+                                       "Received no start marker; dropping frame\n");
         }
 
         if (seq != expected_seq) {
@@ -219,6 +234,7 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8,
                                            "Missed part of a keyframe, sequence broken\n");
             } else if (vp8->data && avio_tell(vp8->data) >= vp8->first_part_size) {
                 vp8->broken_frame = 1;
+                vp8->sequence_dirty = 1;
             } else {
                 return vp8_broken_sequence(ctx, vp8,
                                            "Missed part of the first partition, sequence broken\n");
@@ -230,19 +246,21 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8,
         return vp8_broken_sequence(ctx, vp8, "Received no start marker\n");
 
     vp8->prev_seq = seq;
-    avio_write(vp8->data, buf, len);
+    if (!vp8->broken_frame)
+        avio_write(vp8->data, buf, len);
+
+    if (returned_old_frame) {
+        *timestamp = old_timestamp;
+        return end_packet ? 1 : 0;
+    }
 
     if (end_packet) {
         int ret;
-        if (returned_old_frame) {
-            *timestamp = old_timestamp;
-            return 1;
-        }
         ret = ff_rtp_finalize_packet(pkt, &vp8->data, st->index);
         if (ret < 0)
             return ret;
-        if (vp8->broken_frame)
-            pkt->size = vp8->first_part_size;
+        if (vp8->sequence_dirty)
+            pkt->flags |= AV_PKT_FLAG_CORRUPT;
         return 0;
     }
 
@@ -251,7 +269,11 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8,
 
 static PayloadContext *vp8_new_context(void)
 {
-    return av_mallocz(sizeof(PayloadContext));
+    PayloadContext *vp8 = av_mallocz(sizeof(PayloadContext));
+    if (!vp8)
+        return NULL;
+    vp8->sequence_ok = 1;
+    return vp8;
 }
 
 static void vp8_free_context(PayloadContext *vp8)
@@ -260,6 +282,11 @@ static void vp8_free_context(PayloadContext *vp8)
     av_free(vp8);
 }
 
+static int vp8_need_keyframe(PayloadContext *vp8)
+{
+    return vp8->sequence_dirty || !vp8->sequence_ok;
+}
+
 RTPDynamicProtocolHandler ff_vp8_dynamic_handler = {
     .enc_name       = "VP8",
     .codec_type     = AVMEDIA_TYPE_VIDEO,
@@ -267,4 +294,5 @@ RTPDynamicProtocolHandler ff_vp8_dynamic_handler = {
     .alloc          = vp8_new_context,
     .free           = vp8_free_context,
     .parse_packet   = vp8_handle_packet,
+    .need_keyframe  = vp8_need_keyframe,
 };
diff --git a/mythtv/external/FFmpeg/libavformat/rtpdec_xiph.c b/mythtv/external/FFmpeg/libavformat/rtpdec_xiph.c
index d66b17af5ef..eddb781ddb8 100644
--- a/mythtv/external/FFmpeg/libavformat/rtpdec_xiph.c
+++ b/mythtv/external/FFmpeg/libavformat/rtpdec_xiph.c
@@ -69,6 +69,16 @@ static void xiph_free_context(PayloadContext * data)
     av_free(data);
 }
 
+static int xiph_vorbis_init(AVFormatContext *ctx, int st_index,
+                            PayloadContext *data)
+{
+    if (st_index < 0)
+        return 0;
+    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_HEADERS;
+    return 0;
+}
+
+
 static int xiph_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                               AVStream *st, AVPacket *pkt, uint32_t *timestamp,
                               const uint8_t *buf, int len, uint16_t seq,
@@ -391,6 +401,7 @@ RTPDynamicProtocolHandler ff_vorbis_dynamic_handler = {
     .enc_name         = "vorbis",
     .codec_type       = AVMEDIA_TYPE_AUDIO,
     .codec_id         = AV_CODEC_ID_VORBIS,
+    .init             = xiph_vorbis_init,
     .parse_sdp_a_line = xiph_parse_sdp_line,
     .alloc            = xiph_new_context,
     .free             = xiph_free_context,
diff --git a/mythtv/external/FFmpeg/libavformat/rtpenc.c b/mythtv/external/FFmpeg/libavformat/rtpenc.c
index b7502704b16..7adf687c7f9 100644
--- a/mythtv/external/FFmpeg/libavformat/rtpenc.c
+++ b/mythtv/external/FFmpeg/libavformat/rtpenc.c
@@ -35,6 +35,7 @@ static const AVOption options[] = {
     { "payload_type", "Specify RTP payload type", offsetof(RTPMuxContext, payload_type), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 127, AV_OPT_FLAG_ENCODING_PARAM },
     { "ssrc", "Stream identifier", offsetof(RTPMuxContext, ssrc), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
     { "cname", "CNAME to include in RTCP SR packets", offsetof(RTPMuxContext, cname), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
+    { "seq", "Starting sequence number", offsetof(RTPMuxContext, seq), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 65535, AV_OPT_FLAG_ENCODING_PARAM },
     { NULL },
 };
 
@@ -124,6 +125,16 @@ static int rtp_write_header(AVFormatContext *s1)
         /* Round the NTP time to whole milliseconds. */
         s->first_rtcp_ntp_time = (s1->start_time_realtime / 1000) * 1000 +
                                  NTP_OFFSET_US;
+    // Pick a random sequence start number, but in the lower end of the
+    // available range, so that any wraparound doesn't happen immediately.
+    // (Immediate wraparound would be an issue for SRTP.)
+    if (s->seq < 0) {
+        if (st->codec->flags & CODEC_FLAG_BITEXACT) {
+            s->seq = 0;
+        } else
+            s->seq = av_get_random_seed() & 0x0fff;
+    } else
+        s->seq &= 0xffff; // Use the given parameter, wrapped to the right interval
 
     if (s1->packet_size) {
         if (s1->pb->max_packet_size)
@@ -309,7 +320,7 @@ void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
     avio_write(s1->pb, buf1, len);
     avio_flush(s1->pb);
 
-    s->seq++;
+    s->seq = (s->seq + 1) & 0xffff;
     s->octet_count += len;
     s->packet_count++;
 }
diff --git a/mythtv/external/FFmpeg/libavformat/rtpenc.h b/mythtv/external/FFmpeg/libavformat/rtpenc.h
index f304ea8c581..72a5fa4c8f4 100644
--- a/mythtv/external/FFmpeg/libavformat/rtpenc.h
+++ b/mythtv/external/FFmpeg/libavformat/rtpenc.h
@@ -31,7 +31,7 @@ struct RTPMuxContext {
     int payload_type;
     uint32_t ssrc;
     const char *cname;
-    uint16_t seq;
+    int seq;
     uint32_t timestamp;
     uint32_t base_timestamp;
     uint32_t cur_timestamp;
diff --git a/mythtv/external/FFmpeg/libavformat/rtsp.c b/mythtv/external/FFmpeg/libavformat/rtsp.c
index d993b0ec454..e32b79ae137 100644
--- a/mythtv/external/FFmpeg/libavformat/rtsp.c
+++ b/mythtv/external/FFmpeg/libavformat/rtsp.c
@@ -181,7 +181,8 @@ static void init_rtp_handler(RTPDynamicProtocolHandler *handler,
 {
     if (!handler)
         return;
-    codec->codec_id          = handler->codec_id;
+    if (codec)
+        codec->codec_id          = handler->codec_id;
     rtsp_st->dynamic_handler = handler;
     if (handler->alloc) {
         rtsp_st->dynamic_protocol_context = handler->alloc();
@@ -201,8 +202,7 @@ static int sdp_parse_rtpmap(AVFormatContext *s,
     AVCodec *c;
     const char *c_name;
 
-    /* Loop into AVRtpDynamicPayloadTypes[] and AVRtpPayloadTypes[] and
-     * see if we can handle this kind of payload.
+    /* See if we can handle this kind of payload.
      * The space should normally not be there but some Real streams or
      * particular servers ("RealServer Version 6.1.3.970", see issue 1658)
      * have a trailing space. */
@@ -210,7 +210,6 @@ static int sdp_parse_rtpmap(AVFormatContext *s,
     if (payload_type < RTP_PT_PRIVATE) {
         /* We are in a standard case
          * (from http://www.iana.org/assignments/rtp-parameters). */
-        /* search into AVRtpPayloadTypes[] */
         codec->codec_id = ff_rtp_codec_id(buf, codec->codec_type);
     }
 
@@ -246,10 +245,6 @@ static int sdp_parse_rtpmap(AVFormatContext *s,
             i = atoi(buf);
             if (i > 0)
                 codec->channels = i;
-            // TODO: there is a bug here; if it is a mono stream, and
-            // less than 22000Hz, faad upconverts to stereo and twice
-            // the frequency.  No problem, but the sample rate is being
-            // set here by the sdp line. Patch on its way. (rdm)
         }
         av_log(s, AV_LOG_DEBUG, "audio samplerate set to: %i\n",
                codec->sample_rate);
@@ -380,6 +375,8 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
         get_word(buf1, sizeof(buf1), &p); /* protocol */
         if (!strcmp(buf1, "udp"))
             rt->transport = RTSP_TRANSPORT_RAW;
+        else if (strstr(buf1, "/AVPF") || strstr(buf1, "/SAVPF"))
+            rtsp_st->feedback = 1;
 
         /* XXX: handle list of formats */
         get_word(buf1, sizeof(buf1), &p); /* format list */
@@ -387,8 +384,17 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
 
         if (!strcmp(ff_rtp_enc_name(rtsp_st->sdp_payload_type), "MP2T")) {
             /* no corresponding stream */
-            if (rt->transport == RTSP_TRANSPORT_RAW && !rt->ts && CONFIG_RTPDEC)
-                rt->ts = ff_mpegts_parse_open(s);
+            if (rt->transport == RTSP_TRANSPORT_RAW) {
+                if (!rt->ts && CONFIG_RTPDEC)
+                    rt->ts = ff_mpegts_parse_open(s);
+            } else {
+                RTPDynamicProtocolHandler *handler;
+                handler = ff_rtp_handler_find_by_id(
+                              rtsp_st->sdp_payload_type, AVMEDIA_TYPE_DATA);
+                init_rtp_handler(handler, rtsp_st, NULL);
+                if (handler && handler->init)
+                    handler->init(s, -1, rtsp_st->dynamic_protocol_context);
+            }
         } else if (rt->server_type == RTSP_SERVER_WMS &&
                    codec_type == AVMEDIA_TYPE_DATA) {
             /* RTX stream, a stream that carries all the other actual
@@ -484,6 +490,14 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
                    s->nb_streams > 0) {
             st = s->streams[s->nb_streams - 1];
             st->codec->sample_rate = atoi(p);
+        } else if (av_strstart(p, "crypto:", &p) && s->nb_streams > 0) {
+            // RFC 4568
+            rtsp_st = rt->rtsp_streams[rt->nb_rtsp_streams - 1];
+            get_word(buf1, sizeof(buf1), &p); // ignore tag
+            get_word(rtsp_st->crypto_suite, sizeof(rtsp_st->crypto_suite), &p);
+            p += strspn(p, SPACE_CHARS);
+            if (av_strstart(p, "inline:", &p))
+                get_word(rtsp_st->crypto_params, sizeof(rtsp_st->crypto_params), &p);
         } else {
             if (rt->server_type == RTSP_SERVER_WMS)
                 ff_wms_parse_sdp_a_line(s, p);
@@ -657,6 +671,10 @@ int ff_rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)
                                               rtsp_st->dynamic_protocol_context,
                                               rtsp_st->dynamic_handler);
         }
+        if (rtsp_st->crypto_suite[0])
+            ff_rtp_parse_set_crypto(rtsp_st->transport_priv,
+                                    rtsp_st->crypto_suite,
+                                    rtsp_st->crypto_params);
     }
 
     return 0;
@@ -1863,6 +1881,7 @@ int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
             rt->cur_transport_priv = NULL;
     }
 
+redo:
     if (rt->transport == RTSP_TRANSPORT_RTP) {
         int i;
         int64_t first_queue_time = 0;
@@ -1878,12 +1897,15 @@ int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
                 first_queue_st   = rt->rtsp_streams[i];
             }
         }
-        if (first_queue_time)
+        if (first_queue_time) {
             wait_end = first_queue_time + s->max_delay;
+        } else {
+            wait_end = 0;
+            first_queue_st = NULL;
+        }
     }
 
     /* read next RTP packet */
- redo:
     if (!rt->recvbuf) {
         rt->recvbuf = av_malloc(RECVBUF_SIZE);
         if (!rt->recvbuf)
@@ -1904,7 +1926,11 @@ int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
             ff_rtp_check_and_send_back_rr(rtsp_st->transport_priv, rtsp_st->rtp_handle, NULL, len);
         break;
     case RTSP_LOWER_TRANSPORT_CUSTOM:
-        len = ffio_read_partial(s->pb, rt->recvbuf, RECVBUF_SIZE);
+        if (first_queue_st && rt->transport == RTSP_TRANSPORT_RTP &&
+            wait_end && wait_end < av_gettime())
+            len = AVERROR(EAGAIN);
+        else
+            len = ffio_read_partial(s->pb, rt->recvbuf, RECVBUF_SIZE);
         len = pick_stream(s, &rtsp_st, rt->recvbuf, len);
         if (len > 0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP)
             ff_rtp_check_and_send_back_rr(rtsp_st->transport_priv, NULL, s->pb, len);
@@ -1924,6 +1950,12 @@ int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
         ret = ff_rdt_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len);
     } else if (rt->transport == RTSP_TRANSPORT_RTP) {
         ret = ff_rtp_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len);
+        if (rtsp_st->feedback) {
+            AVIOContext *pb = NULL;
+            if (rt->lower_transport == RTSP_LOWER_TRANSPORT_CUSTOM)
+                pb = s->pb;
+            ff_rtp_send_rtcp_feedback(rtsp_st->transport_priv, rtsp_st->rtp_handle, pb);
+        }
         if (ret < 0) {
             /* Either bad packet, or a RTCP packet. Check if the
              * first_rtcp_ntp_time field was initialized. */
diff --git a/mythtv/external/FFmpeg/libavformat/rtsp.h b/mythtv/external/FFmpeg/libavformat/rtsp.h
index 7ca8f645699..321cd7a1f8b 100644
--- a/mythtv/external/FFmpeg/libavformat/rtsp.h
+++ b/mythtv/external/FFmpeg/libavformat/rtsp.h
@@ -437,6 +437,12 @@ typedef struct RTSPStream {
     /** private data associated with the dynamic protocol */
     PayloadContext *dynamic_protocol_context;
     //@}
+
+    /** Enable sending RTCP feedback messages according to RFC 4585 */
+    int feedback;
+
+    char crypto_suite[40];
+    char crypto_params[100];
 } RTSPStream;
 
 void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf,
diff --git a/mythtv/external/FFmpeg/libavformat/sdp.c b/mythtv/external/FFmpeg/libavformat/sdp.c
index cdc3e212efe..01242184958 100644
--- a/mythtv/external/FFmpeg/libavformat/sdp.c
+++ b/mythtv/external/FFmpeg/libavformat/sdp.c
@@ -128,7 +128,7 @@ static int sdp_get_address(char *dest_addr, int size, int *ttl, const char *url)
 
     *ttl = 0;
 
-    if (strcmp(proto, "rtp")) {
+    if (strcmp(proto, "rtp") && strcmp(proto, "srtp")) {
         /* The url isn't for the actual rtp sessions,
          * don't parse out anything else than the destination.
          */
@@ -681,6 +681,19 @@ int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size)
                 av_strlcatf(buf, size,
                                    "a=control:streamid=%d\r\n", i + j);
             }
+            if (ac[i]->pb && ac[i]->pb->av_class) {
+                uint8_t *crypto_suite = NULL, *crypto_params = NULL;
+                av_opt_get(ac[i]->pb, "srtp_out_suite",  AV_OPT_SEARCH_CHILDREN,
+                           &crypto_suite);
+                av_opt_get(ac[i]->pb, "srtp_out_params", AV_OPT_SEARCH_CHILDREN,
+                           &crypto_params);
+                if (crypto_suite && crypto_suite[0])
+                    av_strlcatf(buf, size,
+                                "a=crypto:1 %s inline:%s\r\n",
+                                crypto_suite, crypto_params);
+                av_free(crypto_suite);
+                av_free(crypto_params);
+            }
         }
     }
 
diff --git a/mythtv/external/FFmpeg/libavformat/segment.c b/mythtv/external/FFmpeg/libavformat/segment.c
index efc35c8bf5c..124a09fa414 100644
--- a/mythtv/external/FFmpeg/libavformat/segment.c
+++ b/mythtv/external/FFmpeg/libavformat/segment.c
@@ -21,7 +21,7 @@
 /**
  * @file generic segmenter
  * M3U8 specification can be find here:
- * @url{http://tools.ietf.org/id/draft-pantos-http-live-streaming-08.txt}
+ * @url{http://tools.ietf.org/id/draft-pantos-http-live-streaming}
  */
 
 /* #define DEBUG */
@@ -31,6 +31,7 @@
 #include "avformat.h"
 #include "internal.h"
 
+#include "libavutil/avassert.h"
 #include "libavutil/log.h"
 #include "libavutil/opt.h"
 #include "libavutil/avstring.h"
@@ -38,12 +39,21 @@
 #include "libavutil/mathematics.h"
 #include "libavutil/timestamp.h"
 
+typedef struct SegmentListEntry {
+    int index;
+    double start_time, end_time;
+    int64_t start_pts;
+    char filename[1024];
+    struct SegmentListEntry *next;
+} SegmentListEntry;
+
 typedef enum {
     LIST_TYPE_UNDEFINED = -1,
     LIST_TYPE_FLAT = 0,
     LIST_TYPE_CSV,
     LIST_TYPE_M3U8,
     LIST_TYPE_EXT, ///< deprecated
+    LIST_TYPE_FFCONCAT,
     LIST_TYPE_NB,
 } ListType;
 
@@ -61,7 +71,6 @@ typedef struct {
     char *list;            ///< filename for the segment list file
     int   list_flags;      ///< flags affecting list generation
     int   list_size;       ///< number of entries for the segment list file
-    double list_max_segment_time; ///< max segment time in the current list
     ListType list_type;    ///< set the list type
     AVIOContext *list_pb;  ///< list file put-byte context
     char *time_str;        ///< segment duration specification string
@@ -85,8 +94,10 @@ typedef struct {
     char *reference_stream_specifier; ///< reference stream specifier
     int   reference_stream_index;
 
-    double start_time, end_time;
-    int64_t start_pts, start_dts;
+    SegmentListEntry cur_entry;
+    SegmentListEntry *segment_list_entries;
+    SegmentListEntry *segment_list_entries_end;
+
     int is_first_pkt;      ///< tells if it is the first packet in the segment
 } SegmentContext;
 
@@ -153,6 +164,7 @@ static int set_segment_filename(AVFormatContext *s)
         av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s'\n", s->filename);
         return AVERROR(EINVAL);
     }
+    av_strlcpy(seg->cur_entry.filename, oc->filename, sizeof(seg->cur_entry.filename));
     return 0;
 }
 
@@ -200,37 +212,63 @@ static int segment_list_open(AVFormatContext *s)
                      &s->interrupt_callback, NULL);
     if (ret < 0)
         return ret;
-    seg->list_max_segment_time = 0;
 
-    if (seg->list_type == LIST_TYPE_M3U8) {
+    if (seg->list_type == LIST_TYPE_M3U8 && seg->segment_list_entries) {
+        SegmentListEntry *entry;
+        double max_duration = 0;
+
         avio_printf(seg->list_pb, "#EXTM3U\n");
         avio_printf(seg->list_pb, "#EXT-X-VERSION:3\n");
-        avio_printf(seg->list_pb, "#EXT-X-MEDIA-SEQUENCE:%d\n", seg->segment_idx);
-        avio_printf(seg->list_pb, "#EXT-X-ALLOWCACHE:%d\n",
-                    !!(seg->list_flags & SEGMENT_LIST_FLAG_CACHE));
-        if (seg->list_flags & SEGMENT_LIST_FLAG_LIVE)
-            avio_printf(seg->list_pb,
-                        "#EXT-X-TARGETDURATION:%"PRId64"\n", seg->time / 1000000);
+        avio_printf(seg->list_pb, "#EXT-X-MEDIA-SEQUENCE:%d\n", seg->segment_list_entries->index);
+        avio_printf(seg->list_pb, "#EXT-X-ALLOW-CACHE:%s\n",
+                    seg->list_flags & SEGMENT_LIST_FLAG_CACHE ? "YES" : "NO");
+
+        for (entry = seg->segment_list_entries; entry; entry = entry->next)
+            max_duration = FFMAX(max_duration, entry->end_time - entry->start_time);
+        avio_printf(seg->list_pb, "#EXT-X-TARGETDURATION:%"PRId64"\n", (int64_t)ceil(max_duration));
+    } else if (seg->list_type == LIST_TYPE_FFCONCAT) {
+        avio_printf(seg->list_pb, "ffconcat version 1.0\n");
     }
 
     return ret;
 }
 
-static void segment_list_close(AVFormatContext *s)
+static void segment_list_print_entry(AVIOContext      *list_ioctx,
+                                     ListType          list_type,
+                                     const SegmentListEntry *list_entry,
+                                     void *log_ctx)
 {
-    SegmentContext *seg = s->priv_data;
-
-    if (seg->list_type == LIST_TYPE_M3U8) {
-        if (!(seg->list_flags & SEGMENT_LIST_FLAG_LIVE))
-            avio_printf(seg->list_pb, "#EXT-X-TARGETDURATION:%d\n",
-                        (int)ceil(seg->list_max_segment_time));
-        avio_printf(seg->list_pb, "#EXT-X-ENDLIST\n");
+    switch (list_type) {
+    case LIST_TYPE_FLAT:
+        avio_printf(list_ioctx, "%s\n", list_entry->filename);
+        break;
+    case LIST_TYPE_CSV:
+    case LIST_TYPE_EXT:
+        print_csv_escaped_str(list_ioctx, list_entry->filename);
+        avio_printf(list_ioctx, ",%f,%f\n", list_entry->start_time, list_entry->end_time);
+        break;
+    case LIST_TYPE_M3U8:
+        avio_printf(list_ioctx, "#EXTINF:%f,\n%s\n",
+                    list_entry->end_time - list_entry->start_time, list_entry->filename);
+        break;
+    case LIST_TYPE_FFCONCAT:
+    {
+        char *buf;
+        if (av_escape(&buf, list_entry->filename, NULL, AV_ESCAPE_MODE_AUTO, AV_ESCAPE_FLAG_WHITESPACE) < 0) {
+            av_log(log_ctx, AV_LOG_WARNING,
+                   "Error writing list entry '%s' in list file\n", list_entry->filename);
+            return;
+        }
+        avio_printf(list_ioctx, "file %s\n", buf);
+        av_free(buf);
+        break;
+    }
+    default:
+        av_assert0(!"Invalid list type");
     }
-
-    avio_close(seg->list_pb);
 }
 
-static int segment_end(AVFormatContext *s, int write_trailer)
+static int segment_end(AVFormatContext *s, int write_trailer, int is_last)
 {
     SegmentContext *seg = s->priv_data;
     AVFormatContext *oc = seg->avf;
@@ -245,22 +283,38 @@ static int segment_end(AVFormatContext *s, int write_trailer)
                oc->filename);
 
     if (seg->list) {
-        if (seg->list_size && !(seg->segment_count % seg->list_size)) {
-            segment_list_close(s);
-            if ((ret = segment_list_open(s)) < 0)
+        if (seg->list_size || seg->list_type == LIST_TYPE_M3U8) {
+            SegmentListEntry *entry = av_mallocz(sizeof(*entry));
+            if (!entry) {
+                ret = AVERROR(ENOMEM);
                 goto end;
-        }
+            }
+
+            /* append new element */
+            memcpy(entry, &seg->cur_entry, sizeof(*entry));
+            if (!seg->segment_list_entries)
+                seg->segment_list_entries = seg->segment_list_entries_end = entry;
+            else
+                seg->segment_list_entries_end->next = entry;
+            seg->segment_list_entries_end = entry;
+
+            /* drop first item */
+            if (seg->list_size && seg->segment_count > seg->list_size) {
+                entry = seg->segment_list_entries;
+                seg->segment_list_entries = seg->segment_list_entries->next;
+                av_freep(&entry);
+            }
 
-        if (seg->list_type == LIST_TYPE_FLAT) {
-            avio_printf(seg->list_pb, "%s\n", oc->filename);
-        } else if (seg->list_type == LIST_TYPE_CSV || seg->list_type == LIST_TYPE_EXT) {
-            print_csv_escaped_str(seg->list_pb, oc->filename);
-            avio_printf(seg->list_pb, ",%f,%f\n", seg->start_time, seg->end_time);
-        } else if (seg->list_type == LIST_TYPE_M3U8) {
-            avio_printf(seg->list_pb, "#EXTINF:%f,\n%s\n",
-                        seg->end_time - seg->start_time, oc->filename);
+            avio_close(seg->list_pb);
+            if ((ret = segment_list_open(s)) < 0)
+                goto end;
+            for (entry = seg->segment_list_entries; entry; entry = entry->next)
+                segment_list_print_entry(seg->list_pb, seg->list_type, entry, s);
+            if (seg->list_type == LIST_TYPE_M3U8 && is_last)
+                avio_printf(seg->list_pb, "#EXT-X-ENDLIST\n");
+        } else {
+            segment_list_print_entry(seg->list_pb, seg->list_type, &seg->cur_entry, s);
         }
-        seg->list_max_segment_time = FFMAX(seg->end_time - seg->start_time, seg->list_max_segment_time);
         avio_flush(seg->list_pb);
     }
 
@@ -407,11 +461,68 @@ static void close_null_ctx(AVIOContext *pb)
     av_free(pb);
 }
 
+static int select_reference_stream(AVFormatContext *s)
+{
+    SegmentContext *seg = s->priv_data;
+    int ret, i;
+
+    seg->reference_stream_index = -1;
+    if (!strcmp(seg->reference_stream_specifier, "auto")) {
+        /* select first index of type with highest priority */
+        int type_index_map[AVMEDIA_TYPE_NB];
+        static const enum AVMediaType type_priority_list[] = {
+            AVMEDIA_TYPE_VIDEO,
+            AVMEDIA_TYPE_AUDIO,
+            AVMEDIA_TYPE_SUBTITLE,
+            AVMEDIA_TYPE_DATA,
+            AVMEDIA_TYPE_ATTACHMENT
+        };
+        enum AVMediaType type;
+
+        for (i = 0; i < AVMEDIA_TYPE_NB; i++)
+            type_index_map[i] = -1;
+
+        /* select first index for each type */
+        for (i = 0; i < s->nb_streams; i++) {
+            type = s->streams[i]->codec->codec_type;
+            if ((unsigned)type < AVMEDIA_TYPE_NB && type_index_map[type] == -1
+                /* ignore attached pictures/cover art streams */
+                && !(s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC))
+                type_index_map[type] = i;
+        }
+
+        for (i = 0; i < FF_ARRAY_ELEMS(type_priority_list); i++) {
+            type = type_priority_list[i];
+            if ((seg->reference_stream_index = type_index_map[type]) >= 0)
+                break;
+        }
+    } else {
+        for (i = 0; i < s->nb_streams; i++) {
+            ret = avformat_match_stream_specifier(s, s->streams[i],
+                                                  seg->reference_stream_specifier);
+            if (ret < 0)
+                return ret;
+            if (ret > 0) {
+                seg->reference_stream_index = i;
+                break;
+            }
+        }
+    }
+
+    if (seg->reference_stream_index < 0) {
+        av_log(s, AV_LOG_ERROR, "Could not select stream matching identifier '%s'\n",
+               seg->reference_stream_specifier);
+        return AVERROR(EINVAL);
+    }
+
+    return 0;
+}
+
 static int seg_write_header(AVFormatContext *s)
 {
     SegmentContext *seg = s->priv_data;
     AVFormatContext *oc = NULL;
-    int ret, i;
+    int ret;
 
     seg->segment_count = 0;
     if (!seg->write_header_trailer)
@@ -424,13 +535,6 @@ static int seg_write_header(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
-    if ((seg->list_flags & SEGMENT_LIST_FLAG_LIVE) && (seg->times_str || seg->frames_str)) {
-        av_log(s, AV_LOG_ERROR,
-               "segment_flags +live and segment_times or segment_frames options are mutually exclusive: "
-               "specify segment_time option if you want a live-friendly list\n");
-        return AVERROR(EINVAL);
-    }
-
     if (seg->times_str) {
         if ((ret = parse_times(s, &seg->times, &seg->nb_times, seg->times_str)) < 0)
             return ret;
@@ -463,6 +567,7 @@ static int seg_write_header(AVFormatContext *s)
             if      (av_match_ext(seg->list, "csv" )) seg->list_type = LIST_TYPE_CSV;
             else if (av_match_ext(seg->list, "ext" )) seg->list_type = LIST_TYPE_EXT;
             else if (av_match_ext(seg->list, "m3u8")) seg->list_type = LIST_TYPE_M3U8;
+            else if (av_match_ext(seg->list, "ffcat,ffconcat")) seg->list_type = LIST_TYPE_FFCONCAT;
             else                                      seg->list_type = LIST_TYPE_FLAT;
         }
         if ((ret = segment_list_open(s)) < 0)
@@ -471,54 +576,8 @@ static int seg_write_header(AVFormatContext *s)
     if (seg->list_type == LIST_TYPE_EXT)
         av_log(s, AV_LOG_WARNING, "'ext' list type option is deprecated in favor of 'csv'\n");
 
-    seg->reference_stream_index = -1;
-    if (!strcmp(seg->reference_stream_specifier, "auto")) {
-        /* select first index of type with highest priority */
-        int type_index_map[AVMEDIA_TYPE_NB];
-        static const enum AVMediaType type_priority_list[] = {
-            AVMEDIA_TYPE_VIDEO,
-            AVMEDIA_TYPE_AUDIO,
-            AVMEDIA_TYPE_SUBTITLE,
-            AVMEDIA_TYPE_DATA,
-            AVMEDIA_TYPE_ATTACHMENT
-        };
-        enum AVMediaType type;
-
-        for (i = 0; i < AVMEDIA_TYPE_NB; i++)
-            type_index_map[i] = -1;
-
-        /* select first index for each type */
-        for (i = 0; i < s->nb_streams; i++) {
-            type = s->streams[i]->codec->codec_type;
-            if ((unsigned)type < AVMEDIA_TYPE_NB && type_index_map[type] == -1)
-                type_index_map[type] = i;
-        }
-
-        for (i = 0; i < FF_ARRAY_ELEMS(type_priority_list); i++) {
-            type = type_priority_list[i];
-            if ((seg->reference_stream_index = type_index_map[type]) >= 0)
-                break;
-        }
-    } else {
-        for (i = 0; i < s->nb_streams; i++) {
-            ret = avformat_match_stream_specifier(s, s->streams[i],
-                                                  seg->reference_stream_specifier);
-            if (ret < 0)
-                goto fail;
-            if (ret > 0) {
-                seg->reference_stream_index = i;
-                break;
-            }
-        }
-    }
-
-    if (seg->reference_stream_index < 0) {
-        av_log(s, AV_LOG_ERROR, "Could not select stream matching identifier '%s'\n",
-               seg->reference_stream_specifier);
-        ret = AVERROR(EINVAL);
+    if ((ret = select_reference_stream(s)) < 0)
         goto fail;
-    }
-
     av_log(s, AV_LOG_VERBOSE, "Selected stream id:%d type:%s\n",
            seg->reference_stream_index,
            av_get_media_type_string(s->streams[seg->reference_stream_index]->codec->codec_type));
@@ -572,7 +631,7 @@ static int seg_write_header(AVFormatContext *s)
 fail:
     if (ret) {
         if (seg->list)
-            segment_list_close(s);
+            avio_close(seg->list_pb);
         if (seg->avf)
             avformat_free_context(seg->avf);
     }
@@ -609,7 +668,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
          (pkt->pts != AV_NOPTS_VALUE &&
           av_compare_ts(pkt->pts, st->time_base,
                         end_pts-seg->time_delta, AV_TIME_BASE_Q) >= 0))) {
-        ret = segment_end(s, seg->individual_header_trailer);
+        ret = segment_end(s, seg->individual_header_trailer, 0);
 
         if (!ret)
             ret = segment_start(s, seg->individual_header_trailer);
@@ -619,13 +678,12 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
 
         oc = seg->avf;
 
-        seg->start_time = (double)pkt->pts * av_q2d(st->time_base);
-        seg->start_pts = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q);
-        seg->start_dts = pkt->dts != AV_NOPTS_VALUE ?
-            av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q) : seg->start_pts;
+        seg->cur_entry.index = seg->segment_idx;
+        seg->cur_entry.start_time = (double)pkt->pts * av_q2d(st->time_base);
+        seg->cur_entry.start_pts = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q);
     } else if (pkt->pts != AV_NOPTS_VALUE) {
-        seg->end_time = FFMAX(seg->end_time,
-                              (double)(pkt->pts + pkt->duration) * av_q2d(st->time_base));
+        seg->cur_entry.end_time =
+            FFMAX(seg->cur_entry.end_time, (double)(pkt->pts + pkt->duration) * av_q2d(st->time_base));
     }
 
     if (seg->is_first_pkt) {
@@ -636,18 +694,21 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
     }
 
     if (seg->reset_timestamps) {
-        av_log(s, AV_LOG_DEBUG, "start_pts:%s pts:%s start_dts:%s dts:%s",
-               av_ts2timestr(seg->start_pts, &AV_TIME_BASE_Q), av_ts2timestr(pkt->pts, &st->time_base),
-               av_ts2timestr(seg->start_dts, &AV_TIME_BASE_Q), av_ts2timestr(pkt->dts, &st->time_base));
+        av_log(s, AV_LOG_DEBUG, "stream:%d start_pts_time:%s pts:%s pts_time:%s dts:%s dts_time:%s",
+               pkt->stream_index,
+               av_ts2timestr(seg->cur_entry.start_pts, &AV_TIME_BASE_Q),
+               av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
+               av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
 
         /* compute new timestamps */
         if (pkt->pts != AV_NOPTS_VALUE)
-            pkt->pts -= av_rescale_q(seg->start_pts, AV_TIME_BASE_Q, st->time_base);
+            pkt->pts -= av_rescale_q(seg->cur_entry.start_pts, AV_TIME_BASE_Q, st->time_base);
         if (pkt->dts != AV_NOPTS_VALUE)
-            pkt->dts -= av_rescale_q(seg->start_dts, AV_TIME_BASE_Q, st->time_base);
+            pkt->dts -= av_rescale_q(seg->cur_entry.start_pts, AV_TIME_BASE_Q, st->time_base);
 
-        av_log(s, AV_LOG_DEBUG, " -> pts:%s dts:%s\n",
-               av_ts2timestr(pkt->pts, &st->time_base), av_ts2timestr(pkt->dts, &st->time_base));
+        av_log(s, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
+               av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
+               av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
     }
 
     ret = ff_write_chained(oc, pkt->stream_index, pkt, s);
@@ -669,24 +730,33 @@ static int seg_write_trailer(struct AVFormatContext *s)
 {
     SegmentContext *seg = s->priv_data;
     AVFormatContext *oc = seg->avf;
+    SegmentListEntry *cur, *next;
+
     int ret;
     if (!seg->write_header_trailer) {
-        if ((ret = segment_end(s, 0)) < 0)
+        if ((ret = segment_end(s, 0, 1)) < 0)
             goto fail;
         open_null_ctx(&oc->pb);
         ret = av_write_trailer(oc);
         close_null_ctx(oc->pb);
     } else {
-        ret = segment_end(s, 1);
+        ret = segment_end(s, 1, 1);
     }
 fail:
     if (seg->list)
-        segment_list_close(s);
+        avio_close(seg->list_pb);
 
     av_opt_free(seg);
     av_freep(&seg->times);
     av_freep(&seg->frames);
 
+    cur = seg->segment_list_entries;
+    while (cur) {
+        next = cur->next;
+        av_free(cur);
+        cur = next;
+    }
+
     avformat_free_context(oc);
     return ret;
 }
@@ -708,6 +778,7 @@ static const AVOption options[] = {
     { "flat", "flat format",     0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_FLAT }, INT_MIN, INT_MAX, E, "list_type" },
     { "csv",  "csv format",      0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_CSV  }, INT_MIN, INT_MAX, E, "list_type" },
     { "ext",  "extended format", 0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_EXT  }, INT_MIN, INT_MAX, E, "list_type" },
+    { "ffconcat", "ffconcat format", 0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_FFCONCAT }, INT_MIN, INT_MAX, E, "list_type" },
     { "m3u8", "M3U8 format",     0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_M3U8 }, INT_MIN, INT_MAX, E, "list_type" },
     { "hls", "Apple HTTP Live Streaming compatible", 0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_M3U8 }, INT_MIN, INT_MAX, E, "list_type" },
 
diff --git a/mythtv/external/FFmpeg/libavformat/srtp.c b/mythtv/external/FFmpeg/libavformat/srtp.c
new file mode 100644
index 00000000000..65309d07635
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavformat/srtp.c
@@ -0,0 +1,471 @@
+/*
+ * SRTP encryption/decryption
+ * Copyright (c) 2012 Martin Storsjo
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/base64.h"
+#include "libavutil/aes.h"
+#include "libavutil/hmac.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/log.h"
+#include "rtp.h"
+#include "srtp.h"
+
+void ff_srtp_free(struct SRTPContext *s)
+{
+    if (!s)
+        return;
+    av_freep(&s->aes);
+    if (s->hmac)
+        av_hmac_free(s->hmac);
+    s->hmac = NULL;
+}
+
+static void encrypt_counter(struct AVAES *aes, uint8_t *iv, uint8_t *outbuf,
+                            int outlen)
+{
+    int i, j, outpos;
+    for (i = 0, outpos = 0; outpos < outlen; i++) {
+        uint8_t keystream[16];
+        AV_WB16(&iv[14], i);
+        av_aes_crypt(aes, keystream, iv, 1, NULL, 0);
+        for (j = 0; j < 16 && outpos < outlen; j++, outpos++)
+            outbuf[outpos] ^= keystream[j];
+    }
+}
+
+static void derive_key(struct AVAES *aes, const uint8_t *salt, int label,
+                       uint8_t *out, int outlen)
+{
+    uint8_t input[16] = { 0 };
+    memcpy(input, salt, 14);
+    // Key derivation rate assumed to be zero
+    input[14 - 7] ^= label;
+    memset(out, 0, outlen);
+    encrypt_counter(aes, input, out, outlen);
+}
+
+int ff_srtp_set_crypto(struct SRTPContext *s, const char *suite,
+                       const char *params)
+{
+    uint8_t buf[30];
+
+    ff_srtp_free(s);
+
+    // RFC 4568
+    if (!strcmp(suite, "AES_CM_128_HMAC_SHA1_80") ||
+        !strcmp(suite, "SRTP_AES128_CM_HMAC_SHA1_80")) {
+        s->rtp_hmac_size = s->rtcp_hmac_size = 10;
+    } else if (!strcmp(suite, "AES_CM_128_HMAC_SHA1_32")) {
+        s->rtp_hmac_size = s->rtcp_hmac_size = 4;
+    } else if (!strcmp(suite, "SRTP_AES128_CM_HMAC_SHA1_32")) {
+        // RFC 5764 section 4.1.2
+        s->rtp_hmac_size  = 4;
+        s->rtcp_hmac_size = 10;
+    } else {
+        av_log(NULL, AV_LOG_WARNING, "SRTP Crypto suite %s not supported\n",
+                                     suite);
+        return AVERROR(EINVAL);
+    }
+    if (av_base64_decode(buf, params, sizeof(buf)) != sizeof(buf)) {
+        av_log(NULL, AV_LOG_WARNING, "Incorrect amount of SRTP params\n");
+        return AVERROR(EINVAL);
+    }
+    // MKI and lifetime not handled yet
+    s->aes  = av_aes_alloc();
+    s->hmac = av_hmac_alloc(AV_HMAC_SHA1);
+    if (!s->aes || !s->hmac)
+        return AVERROR(ENOMEM);
+    memcpy(s->master_key, buf, 16);
+    memcpy(s->master_salt, buf + 16, 14);
+
+    // RFC 3711
+    av_aes_init(s->aes, s->master_key, 128, 0);
+
+    derive_key(s->aes, s->master_salt, 0x00, s->rtp_key, sizeof(s->rtp_key));
+    derive_key(s->aes, s->master_salt, 0x02, s->rtp_salt, sizeof(s->rtp_salt));
+    derive_key(s->aes, s->master_salt, 0x01, s->rtp_auth, sizeof(s->rtp_auth));
+
+    derive_key(s->aes, s->master_salt, 0x03, s->rtcp_key, sizeof(s->rtcp_key));
+    derive_key(s->aes, s->master_salt, 0x05, s->rtcp_salt, sizeof(s->rtcp_salt));
+    derive_key(s->aes, s->master_salt, 0x04, s->rtcp_auth, sizeof(s->rtcp_auth));
+    return 0;
+}
+
+static void create_iv(uint8_t *iv, const uint8_t *salt, uint64_t index,
+                      uint32_t ssrc)
+{
+    uint8_t indexbuf[8];
+    int i;
+    memset(iv, 0, 16);
+    AV_WB32(&iv[4], ssrc);
+    AV_WB64(indexbuf, index);
+    for (i = 0; i < 8; i++) // index << 16
+        iv[6 + i] ^= indexbuf[i];
+    for (i = 0; i < 14; i++)
+        iv[i] ^= salt[i];
+}
+
+int ff_srtp_decrypt(struct SRTPContext *s, uint8_t *buf, int *lenptr)
+{
+    uint8_t iv[16] = { 0 }, hmac[20];
+    int len = *lenptr;
+    int av_uninit(seq_largest);
+    uint32_t ssrc, av_uninit(roc);
+    uint64_t index;
+    int rtcp, hmac_size;
+
+    // TODO: Missing replay protection
+
+    if (len < 2)
+        return AVERROR_INVALIDDATA;
+
+    rtcp = RTP_PT_IS_RTCP(buf[1]);
+    hmac_size = rtcp ? s->rtcp_hmac_size : s->rtp_hmac_size;
+
+    if (len < hmac_size)
+        return AVERROR_INVALIDDATA;
+
+    // Authentication HMAC
+    av_hmac_init(s->hmac, rtcp ? s->rtcp_auth : s->rtp_auth, sizeof(s->rtp_auth));
+    // If MKI is used, this should exclude the MKI as well
+    av_hmac_update(s->hmac, buf, len - hmac_size);
+
+    if (!rtcp) {
+        int seq = AV_RB16(buf + 2);
+        uint32_t v;
+        uint8_t rocbuf[4];
+
+        // RFC 3711 section 3.3.1, appendix A
+        seq_largest = s->seq_initialized ? s->seq_largest : seq;
+        v = roc = s->roc;
+        if (seq_largest < 32768) {
+            if (seq - seq_largest > 32768)
+                v = roc - 1;
+        } else {
+            if (seq_largest - 32768 > seq)
+                v = roc + 1;
+        }
+        if (v == roc) {
+            seq_largest = FFMAX(seq_largest, seq);
+        } else if (v == roc + 1) {
+            seq_largest = seq;
+            roc = v;
+        }
+        index = seq + (((uint64_t)v) << 16);
+
+        AV_WB32(rocbuf, roc);
+        av_hmac_update(s->hmac, rocbuf, 4);
+    }
+
+    av_hmac_final(s->hmac, hmac, sizeof(hmac));
+    if (memcmp(hmac, buf + len - hmac_size, hmac_size)) {
+        av_log(NULL, AV_LOG_WARNING, "HMAC mismatch\n");
+        return AVERROR_INVALIDDATA;
+    }
+
+    len -= hmac_size;
+    *lenptr = len;
+
+    if (len < 12)
+        return AVERROR_INVALIDDATA;
+
+    if (rtcp) {
+        uint32_t srtcp_index = AV_RB32(buf + len - 4);
+        len -= 4;
+        *lenptr = len;
+
+        ssrc = AV_RB32(buf + 4);
+        index = srtcp_index & 0x7fffffff;
+
+        buf += 8;
+        len -= 8;
+        if (!(srtcp_index & 0x80000000))
+            return 0;
+    } else {
+        int ext, csrc;
+        s->seq_initialized = 1;
+        s->seq_largest     = seq_largest;
+        s->roc             = roc;
+
+        csrc = buf[0] & 0x0f;
+        ext  = buf[0] & 0x10;
+        ssrc = AV_RB32(buf + 8);
+
+        buf += 12;
+        len -= 12;
+
+        buf += 4 * csrc;
+        len -= 4 * csrc;
+        if (len < 0)
+            return AVERROR_INVALIDDATA;
+
+        if (ext) {
+            if (len < 4)
+                return AVERROR_INVALIDDATA;
+            ext = (AV_RB16(buf + 2) + 1) * 4;
+            if (len < ext)
+                return AVERROR_INVALIDDATA;
+            len -= ext;
+            buf += ext;
+        }
+    }
+
+    create_iv(iv, rtcp ? s->rtcp_salt : s->rtp_salt, index, ssrc);
+    av_aes_init(s->aes, rtcp ? s->rtcp_key : s->rtp_key, 128, 0);
+    encrypt_counter(s->aes, iv, buf, len);
+
+    return 0;
+}
+
+int ff_srtp_encrypt(struct SRTPContext *s, const uint8_t *in, int len,
+                    uint8_t *out, int outlen)
+{
+    uint8_t iv[16] = { 0 }, hmac[20];
+    uint64_t index;
+    uint32_t ssrc;
+    int rtcp, hmac_size, padding;
+    uint8_t *buf;
+
+    if (len < 8)
+        return AVERROR_INVALIDDATA;
+
+    rtcp = RTP_PT_IS_RTCP(in[1]);
+    hmac_size = rtcp ? s->rtcp_hmac_size : s->rtp_hmac_size;
+    padding = hmac_size;
+    if (rtcp)
+        padding += 4; // For the RTCP index
+
+    if (len + padding > outlen)
+        return 0;
+
+    memcpy(out, in, len);
+    buf = out;
+
+    if (rtcp) {
+        ssrc = AV_RB32(buf + 4);
+        index = s->rtcp_index++;
+
+        buf += 8;
+        len -= 8;
+    } else {
+        int ext, csrc;
+        int seq = AV_RB16(buf + 2);
+
+        if (len < 12)
+            return AVERROR_INVALIDDATA;
+
+        ssrc = AV_RB32(buf + 8);
+
+        if (seq < s->seq_largest)
+            s->roc++;
+        s->seq_largest = seq;
+        index = seq + (((uint64_t)s->roc) << 16);
+
+        csrc = buf[0] & 0x0f;
+        ext = buf[0] & 0x10;
+
+        buf += 12;
+        len -= 12;
+
+        buf += 4 * csrc;
+        len -= 4 * csrc;
+        if (len < 0)
+            return AVERROR_INVALIDDATA;
+
+        if (ext) {
+            if (len < 4)
+                return AVERROR_INVALIDDATA;
+            ext = (AV_RB16(buf + 2) + 1) * 4;
+            if (len < ext)
+                return AVERROR_INVALIDDATA;
+            len -= ext;
+            buf += ext;
+        }
+    }
+
+    create_iv(iv, rtcp ? s->rtcp_salt : s->rtp_salt, index, ssrc);
+    av_aes_init(s->aes, rtcp ? s->rtcp_key : s->rtp_key, 128, 0);
+    encrypt_counter(s->aes, iv, buf, len);
+
+    if (rtcp) {
+        AV_WB32(buf + len, 0x80000000 | index);
+        len += 4;
+    }
+
+    av_hmac_init(s->hmac, rtcp ? s->rtcp_auth : s->rtp_auth, sizeof(s->rtp_auth));
+    av_hmac_update(s->hmac, out, buf + len - out);
+    if (!rtcp) {
+        uint8_t rocbuf[4];
+        AV_WB32(rocbuf, s->roc);
+        av_hmac_update(s->hmac, rocbuf, 4);
+    }
+    av_hmac_final(s->hmac, hmac, sizeof(hmac));
+
+    memcpy(buf + len, hmac, hmac_size);
+    len += hmac_size;
+    return buf + len - out;
+}
+
+#ifdef TEST
+#include 
+
+static const char *aes128_80_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn";
+
+static const uint8_t rtp_aes128_80[] = {
+    // RTP header
+    0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
+    // encrypted payload
+    0x62, 0x69, 0x76, 0xca, 0xc5,
+    // HMAC
+    0xa1, 0xac, 0x1b, 0xb4, 0xa0, 0x1c, 0xd5, 0x49, 0x28, 0x99,
+};
+
+static const uint8_t rtcp_aes128_80[] = {
+    // RTCP header
+    0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
+    // encrypted payload
+    0x8a, 0xac, 0xdc, 0xa5, 0x4c, 0xf6, 0x78, 0xa6, 0x62, 0x8f, 0x24, 0xda,
+    0x6c, 0x09, 0x3f, 0xa9, 0x28, 0x7a, 0xb5, 0x7f, 0x1f, 0x0f, 0xc9, 0x35,
+    // RTCP index
+    0x80, 0x00, 0x00, 0x03,
+    // HMAC
+    0xe9, 0x3b, 0xc0, 0x5c, 0x0c, 0x06, 0x9f, 0xab, 0xc0, 0xde,
+};
+
+static const char *aes128_32_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn";
+
+static const uint8_t rtp_aes128_32[] = {
+    // RTP header
+    0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
+    // encrypted payload
+    0x62, 0x69, 0x76, 0xca, 0xc5,
+    // HMAC
+    0xa1, 0xac, 0x1b, 0xb4,
+};
+
+static const uint8_t rtcp_aes128_32[] = {
+    // RTCP header
+    0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
+    // encrypted payload
+    0x35, 0xe9, 0xb5, 0xff, 0x0d, 0xd1, 0xde, 0x70, 0x74, 0x10, 0xaa, 0x1b,
+    0xb2, 0x8d, 0xf0, 0x20, 0x02, 0x99, 0x6b, 0x1b, 0x0b, 0xd0, 0x47, 0x34,
+    // RTCP index
+    0x80, 0x00, 0x00, 0x04,
+    // HMAC
+    0x5b, 0xd2, 0xa9, 0x9d,
+};
+
+static const char *aes128_80_32_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn";
+
+static const uint8_t rtp_aes128_80_32[] = {
+    // RTP header
+    0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
+    // encrypted payload
+    0x62, 0x69, 0x76, 0xca, 0xc5,
+    // HMAC
+    0xa1, 0xac, 0x1b, 0xb4,
+};
+
+static const uint8_t rtcp_aes128_80_32[] = {
+    // RTCP header
+    0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
+    // encrypted payload
+    0xd6, 0xae, 0xc1, 0x58, 0x63, 0x70, 0xc9, 0x88, 0x66, 0x26, 0x1c, 0x53,
+    0xff, 0x5d, 0x5d, 0x2b, 0x0f, 0x8c, 0x72, 0x3e, 0xc9, 0x1d, 0x43, 0xf9,
+    // RTCP index
+    0x80, 0x00, 0x00, 0x05,
+    // HMAC
+    0x09, 0x16, 0xb4, 0x27, 0x9a, 0xe9, 0x92, 0x26, 0x4e, 0x10,
+};
+
+static void print_data(const uint8_t *buf, int len)
+{
+    int i;
+    for (i = 0; i < len; i++)
+        printf("%02x", buf[i]);
+    printf("\n");
+}
+
+static int test_decrypt(struct SRTPContext *srtp, const uint8_t *in, int len,
+                        uint8_t *out)
+{
+    memcpy(out, in, len);
+    if (!ff_srtp_decrypt(srtp, out, &len)) {
+        print_data(out, len);
+        return len;
+    } else
+        return -1;
+}
+
+static void test_encrypt(const uint8_t *data, int in_len, const char *suite,
+                         const char *key)
+{
+    struct SRTPContext enc = { 0 }, dec = { 0 };
+    int len;
+    char buf[1500];
+    ff_srtp_set_crypto(&enc, suite, key);
+    ff_srtp_set_crypto(&dec, suite, key);
+    len = ff_srtp_encrypt(&enc, data, in_len, buf, sizeof(buf));
+    if (!ff_srtp_decrypt(&dec, buf, &len)) {
+        if (len == in_len && !memcmp(buf, data, len))
+            printf("Decrypted content matches input\n");
+        else
+            printf("Decrypted content doesn't match input\n");
+    } else {
+        printf("Decryption failed\n");
+    }
+    ff_srtp_free(&enc);
+    ff_srtp_free(&dec);
+}
+
+int main(void)
+{
+    static const char *aes128_80_suite = "AES_CM_128_HMAC_SHA1_80";
+    static const char *aes128_32_suite = "AES_CM_128_HMAC_SHA1_32";
+    static const char *aes128_80_32_suite = "SRTP_AES128_CM_HMAC_SHA1_32";
+    static const char *test_key = "abcdefghijklmnopqrstuvwxyz1234567890ABCD";
+    uint8_t buf[1500];
+    struct SRTPContext srtp = { 0 };
+    int len;
+    ff_srtp_set_crypto(&srtp, aes128_80_suite, aes128_80_key);
+    len = test_decrypt(&srtp, rtp_aes128_80, sizeof(rtp_aes128_80), buf);
+    test_encrypt(buf, len, aes128_80_suite, test_key);
+    test_encrypt(buf, len, aes128_32_suite, test_key);
+    test_encrypt(buf, len, aes128_80_32_suite, test_key);
+    test_decrypt(&srtp, rtcp_aes128_80, sizeof(rtcp_aes128_80), buf);
+    test_encrypt(buf, len, aes128_80_suite, test_key);
+    test_encrypt(buf, len, aes128_32_suite, test_key);
+    test_encrypt(buf, len, aes128_80_32_suite, test_key);
+    ff_srtp_free(&srtp);
+
+    memset(&srtp, 0, sizeof(srtp)); // Clear the context
+    ff_srtp_set_crypto(&srtp, aes128_32_suite, aes128_32_key);
+    test_decrypt(&srtp, rtp_aes128_32, sizeof(rtp_aes128_32), buf);
+    test_decrypt(&srtp, rtcp_aes128_32, sizeof(rtcp_aes128_32), buf);
+    ff_srtp_free(&srtp);
+
+    memset(&srtp, 0, sizeof(srtp)); // Clear the context
+    ff_srtp_set_crypto(&srtp, aes128_80_32_suite, aes128_80_32_key);
+    test_decrypt(&srtp, rtp_aes128_80_32, sizeof(rtp_aes128_80_32), buf);
+    test_decrypt(&srtp, rtcp_aes128_80_32, sizeof(rtcp_aes128_80_32), buf);
+    ff_srtp_free(&srtp);
+    return 0;
+}
+#endif /* TEST */
diff --git a/mythtv/external/FFmpeg/libavformat/srtp.h b/mythtv/external/FFmpeg/libavformat/srtp.h
new file mode 100644
index 00000000000..3189f8f54bd
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavformat/srtp.h
@@ -0,0 +1,52 @@
+/*
+ * SRTP encryption/decryption
+ * Copyright (c) 2012 Martin Storsjo
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_SRTP_H
+#define AVFORMAT_SRTP_H
+
+#include 
+
+struct AVAES;
+struct AVHMAC;
+
+struct SRTPContext {
+    struct AVAES *aes;
+    struct AVHMAC *hmac;
+    int rtp_hmac_size, rtcp_hmac_size;
+    uint8_t master_key[16];
+    uint8_t master_salt[14];
+    uint8_t rtp_key[16],  rtcp_key[16];
+    uint8_t rtp_salt[14], rtcp_salt[14];
+    uint8_t rtp_auth[20], rtcp_auth[20];
+    int seq_largest, seq_initialized;
+    uint32_t roc;
+
+    uint32_t rtcp_index;
+};
+
+int ff_srtp_set_crypto(struct SRTPContext *s, const char *suite,
+                       const char *params);
+void ff_srtp_free(struct SRTPContext *s);
+int ff_srtp_decrypt(struct SRTPContext *s, uint8_t *buf, int *lenptr);
+int ff_srtp_encrypt(struct SRTPContext *s, const uint8_t *in, int len,
+                    uint8_t *out, int outlen);
+
+#endif /* AVFORMAT_SRTP_H */
diff --git a/mythtv/external/FFmpeg/libavformat/srtpproto.c b/mythtv/external/FFmpeg/libavformat/srtpproto.c
new file mode 100644
index 00000000000..f5e3d140903
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavformat/srtpproto.c
@@ -0,0 +1,144 @@
+/*
+ * SRTP network protocol
+ * Copyright (c) 2012 Martin Storsjo
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/opt.h"
+#include "avformat.h"
+#include "avio_internal.h"
+#include "url.h"
+
+#include "internal.h"
+#include "srtp.h"
+
+typedef struct SRTPProtoContext {
+    const AVClass *class;
+    URLContext *rtp_hd;
+    const char *out_suite, *out_params;
+    const char *in_suite, *in_params;
+    struct SRTPContext srtp_out, srtp_in;
+    uint8_t encryptbuf[1500];
+} SRTPProtoContext;
+
+#define D AV_OPT_FLAG_DECODING_PARAM
+#define E AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+    { "srtp_out_suite", "", offsetof(SRTPProtoContext, out_suite), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
+    { "srtp_out_params", "", offsetof(SRTPProtoContext, out_params), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
+    { "srtp_in_suite", "", offsetof(SRTPProtoContext, in_suite), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
+    { "srtp_in_params", "", offsetof(SRTPProtoContext, in_params), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
+    { NULL }
+};
+
+static const AVClass srtp_context_class = {
+    .class_name     = "srtp",
+    .item_name      = av_default_item_name,
+    .option         = options,
+    .version        = LIBAVUTIL_VERSION_INT,
+};
+
+static int srtp_close(URLContext *h)
+{
+    SRTPProtoContext *s = h->priv_data;
+    ff_srtp_free(&s->srtp_out);
+    ff_srtp_free(&s->srtp_in);
+    ffurl_close(s->rtp_hd);
+    s->rtp_hd = NULL;
+    return 0;
+}
+
+static int srtp_open(URLContext *h, const char *uri, int flags)
+{
+    SRTPProtoContext *s = h->priv_data;
+    char hostname[256], buf[1024], path[1024];
+    int rtp_port, ret;
+
+    if (s->out_suite && s->out_params)
+        if ((ret = ff_srtp_set_crypto(&s->srtp_out, s->out_suite, s->out_params)) < 0)
+            goto fail;
+    if (s->in_suite && s->in_params)
+        if ((ret = ff_srtp_set_crypto(&s->srtp_in, s->in_suite, s->in_params)) < 0)
+            goto fail;
+
+    av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port,
+                 path, sizeof(path), uri);
+    ff_url_join(buf, sizeof(buf), "rtp", NULL, hostname, rtp_port, "%s", path);
+    if ((ret = ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL)) < 0)
+        goto fail;
+
+    h->max_packet_size = FFMIN(s->rtp_hd->max_packet_size,
+                               sizeof(s->encryptbuf)) - 14;
+    h->is_streamed = 1;
+    return 0;
+
+fail:
+    srtp_close(h);
+    return ret;
+}
+
+static int srtp_read(URLContext *h, uint8_t *buf, int size)
+{
+    SRTPProtoContext *s = h->priv_data;
+    int ret;
+start:
+    ret = ffurl_read(s->rtp_hd, buf, size);
+    if (ret > 0 && s->srtp_in.aes) {
+        if (ff_srtp_decrypt(&s->srtp_in, buf, &ret) < 0)
+            goto start;
+    }
+    return ret;
+}
+
+static int srtp_write(URLContext *h, const uint8_t *buf, int size)
+{
+    SRTPProtoContext *s = h->priv_data;
+    if (!s->srtp_out.aes)
+        return ffurl_write(s->rtp_hd, buf, size);
+    size = ff_srtp_encrypt(&s->srtp_out, buf, size, s->encryptbuf,
+                           sizeof(s->encryptbuf));
+    if (size < 0)
+        return size;
+    return ffurl_write(s->rtp_hd, s->encryptbuf, size);
+}
+
+static int srtp_get_file_handle(URLContext *h)
+{
+    SRTPProtoContext *s = h->priv_data;
+    return ffurl_get_file_handle(s->rtp_hd);
+}
+
+static int srtp_get_multi_file_handle(URLContext *h, int **handles,
+                                      int *numhandles)
+{
+    SRTPProtoContext *s = h->priv_data;
+    return ffurl_get_multi_file_handle(s->rtp_hd, handles, numhandles);
+}
+
+URLProtocol ff_srtp_protocol = {
+    .name                      = "srtp",
+    .url_open                  = srtp_open,
+    .url_read                  = srtp_read,
+    .url_write                 = srtp_write,
+    .url_close                 = srtp_close,
+    .url_get_file_handle       = srtp_get_file_handle,
+    .url_get_multi_file_handle = srtp_get_multi_file_handle,
+    .priv_data_size            = sizeof(SRTPProtoContext),
+    .priv_data_class           = &srtp_context_class,
+    .flags                     = URL_PROTOCOL_FLAG_NETWORK,
+};
diff --git a/mythtv/external/FFmpeg/libavformat/subtitles.c b/mythtv/external/FFmpeg/libavformat/subtitles.c
index 546261605f2..37ba0cb0b6b 100644
--- a/mythtv/external/FFmpeg/libavformat/subtitles.c
+++ b/mythtv/external/FFmpeg/libavformat/subtitles.c
@@ -170,12 +170,12 @@ const char *ff_smil_get_attr_ptr(const char *s, const char *attr)
 
     while (*s) {
         while (*s) {
-            if (!in_quotes && isspace(*s))
+            if (!in_quotes && av_isspace(*s))
                 break;
             in_quotes ^= *s == '"'; // XXX: support escaping?
             s++;
         }
-        while (isspace(*s))
+        while (av_isspace(*s))
             s++;
         if (!av_strncasecmp(s, attr, len) && s[len] == '=')
             return s + len + 1 + (s[len + 1] == '"');
diff --git a/mythtv/external/FFmpeg/libavformat/swfdec.c b/mythtv/external/FFmpeg/libavformat/swfdec.c
index 8fb4aeb37a3..54e0f6dc0ee 100644
--- a/mythtv/external/FFmpeg/libavformat/swfdec.c
+++ b/mythtv/external/FFmpeg/libavformat/swfdec.c
@@ -138,6 +138,32 @@ static int swf_read_header(AVFormatContext *s)
     return 0;
 }
 
+static AVStream *create_new_audio_stream(AVFormatContext *s, int id, int info)
+{
+    int sample_rate_code, sample_size_code;
+    AVStream *ast = avformat_new_stream(s, NULL);
+    if (!ast)
+        return NULL;
+    ast->id = id;
+    if (info & 1) {
+        ast->codec->channels       = 2;
+        ast->codec->channel_layout = AV_CH_LAYOUT_STEREO;
+    } else {
+        ast->codec->channels       = 1;
+        ast->codec->channel_layout = AV_CH_LAYOUT_MONO;
+    }
+    ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+    ast->codec->codec_id   = ff_codec_get_id(swf_audio_codec_tags, info>>4 & 15);
+    ast->need_parsing = AVSTREAM_PARSE_FULL;
+    sample_rate_code = info>>2 & 3;
+    sample_size_code = info>>1 & 1;
+    if (!sample_size_code && ast->codec->codec_id == AV_CODEC_ID_PCM_S16LE)
+        ast->codec->codec_id = AV_CODEC_ID_PCM_U8;
+    ast->codec->sample_rate = 44100 >> (3 - sample_rate_code);
+    avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
+    return ast;
+}
+
 static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     SWFContext *swf = s->priv_data;
@@ -184,7 +210,6 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
             len -= 8;
         } else if (tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2) {
             /* streaming found */
-            int sample_rate_code;
 
             for (i=0; inb_streams; i++) {
                 st = s->streams[i];
@@ -195,27 +220,12 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
             avio_r8(pb);
             v = avio_r8(pb);
             swf->samples_per_frame = avio_rl16(pb);
-            ast = avformat_new_stream(s, NULL);
+            ast = create_new_audio_stream(s, -1, v); /* -1 to avoid clash with video stream ch_id */
             if (!ast)
                 return AVERROR(ENOMEM);
-            ast->id = -1; /* -1 to avoid clash with video stream ch_id */
-            if (v & 1) {
-                ast->codec->channels       = 2;
-                ast->codec->channel_layout = AV_CH_LAYOUT_STEREO;
-            } else {
-                ast->codec->channels       = 1;
-                ast->codec->channel_layout = AV_CH_LAYOUT_MONO;
-            }
-            ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
-            ast->codec->codec_id = ff_codec_get_id(swf_audio_codec_tags, (v>>4) & 15);
-            ast->need_parsing = AVSTREAM_PARSE_FULL;
-            sample_rate_code= (v>>2) & 3;
-            ast->codec->sample_rate = 44100 >> (3 - sample_rate_code);
-            avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
             len -= 4;
         } else if (tag == TAG_DEFINESOUND) {
             /* audio stream */
-            int sample_rate_code;
             int ch_id = avio_rl16(pb);
 
             for (i=0; inb_streams; i++) {
@@ -224,22 +234,13 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
                     goto skip;
             }
 
-            // FIXME: 8-bit uncompressed PCM audio will be interpreted as 16-bit
             // FIXME: The entire audio stream is stored in a single chunk/tag. Normally,
             // these are smaller audio streams in DEFINESOUND tags, but it's technically
             // possible they could be huge. Break it up into multiple packets if it's big.
             v = avio_r8(pb);
-            ast = avformat_new_stream(s, NULL);
+            ast = create_new_audio_stream(s, ch_id, v);
             if (!ast)
                 return AVERROR(ENOMEM);
-            ast->id = ch_id;
-            ast->codec->channels = 1 + (v&1);
-            ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
-            ast->codec->codec_id = ff_codec_get_id(swf_audio_codec_tags, (v>>4) & 15);
-            ast->need_parsing = AVSTREAM_PARSE_FULL;
-            sample_rate_code= (v>>2) & 3;
-            ast->codec->sample_rate = 44100 >> (3 - sample_rate_code);
-            avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
             ast->duration = avio_rl32(pb); // number of samples
             if (((v>>4) & 15) == 2) { // MP3 sound data record
                 ast->skip_samples = avio_rl16(pb);
diff --git a/mythtv/external/FFmpeg/libavformat/tee.c b/mythtv/external/FFmpeg/libavformat/tee.c
new file mode 100644
index 00000000000..f41327bc7e1
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavformat/tee.c
@@ -0,0 +1,278 @@
+/*
+ * Tee pesudo-muxer
+ * Copyright (c) 2012 Nicolas George
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with FFmpeg; if not, write to the Free Software * Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#include "libavutil/avutil.h"
+#include "libavutil/avstring.h"
+#include "libavutil/opt.h"
+#include "avformat.h"
+
+#define MAX_SLAVES 16
+
+typedef struct TeeContext {
+    const AVClass *class;
+    unsigned nb_slaves;
+    AVFormatContext *slaves[MAX_SLAVES];
+} TeeContext;
+
+static const char *const slave_delim     = "|";
+static const char *const slave_opt_open  = "[";
+static const char *const slave_opt_close = "]";
+static const char *const slave_opt_delim = ":]"; /* must have the close too */
+
+static const AVClass tee_muxer_class = {
+    .class_name = "Tee muxer",
+    .item_name  = av_default_item_name,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+static int parse_slave_options(void *log, char *slave,
+                               AVDictionary **options, char **filename)
+{
+    const char *p;
+    char *key, *val;
+    int ret;
+
+    if (!strspn(slave, slave_opt_open)) {
+        *filename = slave;
+        return 0;
+    }
+    p = slave + 1;
+    if (strspn(p, slave_opt_close)) {
+        *filename = (char *)p + 1;
+        return 0;
+    }
+    while (1) {
+        ret = av_opt_get_key_value(&p, "=", slave_opt_delim, 0, &key, &val);
+        if (ret < 0) {
+            av_log(log, AV_LOG_ERROR, "No option found near \"%s\"\n", p);
+            goto fail;
+        }
+        ret = av_dict_set(options, key, val,
+                          AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
+        if (ret < 0)
+            goto fail;
+        if (strspn(p, slave_opt_close))
+            break;
+        p++;
+    }
+    *filename = (char *)p + 1;
+    return 0;
+
+fail:
+    av_dict_free(options);
+    return ret;
+}
+
+static int open_slave(AVFormatContext *avf, char *slave, AVFormatContext **ravf)
+{
+    int i, ret;
+    AVDictionary *options = NULL;
+    AVDictionaryEntry *entry;
+    char *filename;
+    char *format = NULL;
+    AVFormatContext *avf2 = NULL;
+    AVStream *st, *st2;
+
+    if ((ret = parse_slave_options(avf, slave, &options, &filename)) < 0)
+        return ret;
+    if ((entry = av_dict_get(options, "f", NULL, 0))) {
+        format = entry->value;
+        entry->value = NULL; /* prevent it from being freed */
+        av_dict_set(&options, "f", NULL, 0);
+    }
+
+    avformat_alloc_output_context2(&avf2, NULL, format, filename);
+    if (ret < 0)
+        goto fail;
+    av_free(format);
+
+    for (i = 0; i < avf->nb_streams; i++) {
+        st = avf->streams[i];
+        if (!(st2 = avformat_new_stream(avf2, NULL))) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+        st2->id = st->id;
+        st2->r_frame_rate        = st->r_frame_rate;
+        st2->time_base           = st->time_base;
+        st2->start_time          = st->start_time;
+        st2->duration            = st->duration;
+        st2->nb_frames           = st->nb_frames;
+        st2->disposition         = st->disposition;
+        st2->sample_aspect_ratio = st->sample_aspect_ratio;
+        st2->avg_frame_rate      = st->avg_frame_rate;
+        av_dict_copy(&st2->metadata, st->metadata, 0);
+        if ((ret = avcodec_copy_context(st2->codec, st->codec)) < 0)
+            goto fail;
+    }
+
+    if (!(avf2->oformat->flags & AVFMT_NOFILE)) {
+        if ((ret = avio_open(&avf2->pb, filename, AVIO_FLAG_WRITE)) < 0) {
+            av_log(avf, AV_LOG_ERROR, "Slave '%s': error opening: %s\n",
+                   slave, av_err2str(ret));
+            goto fail;
+        }
+    }
+
+    if ((ret = avformat_write_header(avf2, &options)) < 0) {
+        av_log(avf, AV_LOG_ERROR, "Slave '%s': error writing header: %s\n",
+               slave, av_err2str(ret));
+        goto fail;
+    }
+    if (options) {
+        entry = NULL;
+        while ((entry = av_dict_get(options, "", entry, AV_DICT_IGNORE_SUFFIX)))
+            av_log(avf2, AV_LOG_ERROR, "Unknown option '%s'\n", entry->key);
+        ret = AVERROR_OPTION_NOT_FOUND;
+        goto fail;
+    }
+
+    *ravf = avf2;
+    return 0;
+
+fail:
+    av_dict_free(&options);
+    return ret;
+}
+
+static void close_slaves(AVFormatContext *avf)
+{
+    TeeContext *tee = avf->priv_data;
+    AVFormatContext *avf2;
+    unsigned i;
+
+    for (i = 0; i < tee->nb_slaves; i++) {
+        avf2 = tee->slaves[i];
+        avio_close(avf2->pb);
+        avf2->pb = NULL;
+        avformat_free_context(avf2);
+        tee->slaves[i] = NULL;
+    }
+}
+
+static int tee_write_header(AVFormatContext *avf)
+{
+    TeeContext *tee = avf->priv_data;
+    unsigned nb_slaves = 0, i;
+    const char *filename = avf->filename;
+    char *slaves[MAX_SLAVES];
+    int ret;
+
+    while (*filename) {
+        if (nb_slaves == MAX_SLAVES) {
+            av_log(avf, AV_LOG_ERROR, "Maximum %d slave muxers reached.\n",
+                   MAX_SLAVES);
+            ret = AVERROR_PATCHWELCOME;
+            goto fail;
+        }
+        if (!(slaves[nb_slaves++] = av_get_token(&filename, slave_delim))) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+        if (strspn(filename, slave_delim))
+            filename++;
+    }
+
+    for (i = 0; i < nb_slaves; i++) {
+        if ((ret = open_slave(avf, slaves[i], &tee->slaves[i])) < 0)
+            goto fail;
+        av_freep(&slaves[i]);
+    }
+
+    tee->nb_slaves = nb_slaves;
+    return 0;
+
+fail:
+    for (i = 0; i < nb_slaves; i++)
+        av_freep(&slaves[i]);
+    close_slaves(avf);
+    return ret;
+}
+
+static int tee_write_trailer(AVFormatContext *avf)
+{
+    TeeContext *tee = avf->priv_data;
+    AVFormatContext *avf2;
+    int ret_all = 0, ret;
+    unsigned i;
+
+    for (i = 0; i < tee->nb_slaves; i++) {
+        avf2 = tee->slaves[i];
+        if ((ret = av_write_trailer(avf2)) < 0)
+            if (!ret_all)
+                ret_all = ret;
+        if (!(avf2->oformat->flags & AVFMT_NOFILE)) {
+            if ((ret = avio_close(avf2->pb)) < 0)
+                if (!ret_all)
+                    ret_all = ret;
+            avf2->pb = NULL;
+        }
+    }
+    close_slaves(avf);
+    return ret_all;
+}
+
+static int tee_write_packet(AVFormatContext *avf, AVPacket *pkt)
+{
+    TeeContext *tee = avf->priv_data;
+    AVFormatContext *avf2;
+    AVPacket pkt2;
+    int ret_all = 0, ret;
+    unsigned i, s;
+    AVRational tb, tb2;
+
+    for (i = 0; i < tee->nb_slaves; i++) {
+        avf2 = tee->slaves[i];
+        s = pkt->stream_index;
+        if (s >= avf2->nb_streams) {
+            if (!ret_all)
+                ret_all = AVERROR(EINVAL);
+            continue;
+        }
+        if ((ret = av_copy_packet(&pkt2, pkt)) < 0 ||
+            (ret = av_dup_packet(&pkt2))< 0)
+            if (!ret_all) {
+                ret = ret_all;
+                continue;
+            }
+        tb  = avf ->streams[s]->time_base;
+        tb2 = avf2->streams[s]->time_base;
+        pkt2.pts      = av_rescale_q(pkt->pts,      tb, tb2);
+        pkt2.dts      = av_rescale_q(pkt->dts,      tb, tb2);
+        pkt2.duration = av_rescale_q(pkt->duration, tb, tb2);
+        if ((ret = av_interleaved_write_frame(avf2, &pkt2)) < 0)
+            if (!ret_all)
+                ret_all = ret;
+    }
+    return ret_all;
+}
+
+AVOutputFormat ff_tee_muxer = {
+    .name              = "tee",
+    .long_name         = NULL_IF_CONFIG_SMALL("Multiple muxer tee"),
+    .priv_data_size    = sizeof(TeeContext),
+    .write_header      = tee_write_header,
+    .write_trailer     = tee_write_trailer,
+    .write_packet      = tee_write_packet,
+    .priv_class        = &tee_muxer_class,
+    .flags             = AVFMT_NOFILE,
+};
diff --git a/mythtv/external/FFmpeg/libavformat/tls.c b/mythtv/external/FFmpeg/libavformat/tls.c
index 38dd70c9df6..2c85d1dedc9 100644
--- a/mythtv/external/FFmpeg/libavformat/tls.c
+++ b/mythtv/external/FFmpeg/libavformat/tls.c
@@ -172,10 +172,6 @@ static int tls_open(URLContext *h, const char *uri, int flags)
 
     ff_tls_init();
 
-    proxy_path = getenv("http_proxy");
-    use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
-        av_strstart(proxy_path, "http://", NULL);
-
     av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, path, sizeof(path), uri);
     ff_url_join(buf, sizeof(buf), "tcp", NULL, host, port, "%s", path);
 
@@ -185,6 +181,10 @@ static int tls_open(URLContext *h, const char *uri, int flags)
         freeaddrinfo(ai);
     }
 
+    proxy_path = getenv("http_proxy");
+    use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), host) &&
+                proxy_path != NULL && av_strstart(proxy_path, "http://", NULL);
+
     if (use_proxy) {
         char proxy_host[200], proxy_auth[200], dest[200];
         int proxy_port;
diff --git a/mythtv/external/FFmpeg/libavformat/urldecode.c b/mythtv/external/FFmpeg/libavformat/urldecode.c
index b1009037a84..283d9126716 100644
--- a/mythtv/external/FFmpeg/libavformat/urldecode.c
+++ b/mythtv/external/FFmpeg/libavformat/urldecode.c
@@ -26,7 +26,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
 #include 
 
 #include "libavutil/mem.h"
@@ -54,7 +53,7 @@ char *ff_urldecode(const char *url)
         if (c == '%' && s + 2 < url_len) {
             char c2 = url[s++];
             char c3 = url[s++];
-            if (isxdigit(c2) && isxdigit(c3)) {
+            if (av_isxdigit(c2) && av_isxdigit(c3)) {
                 c2 = av_tolower(c2);
                 c3 = av_tolower(c3);
 
diff --git a/mythtv/external/FFmpeg/libavformat/utils.c b/mythtv/external/FFmpeg/libavformat/utils.c
index 0b2445442a7..94265b8bf3d 100644
--- a/mythtv/external/FFmpeg/libavformat/utils.c
+++ b/mythtv/external/FFmpeg/libavformat/utils.c
@@ -459,6 +459,8 @@ int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
     } else if (max_probe_size > PROBE_BUF_MAX) {
         max_probe_size = PROBE_BUF_MAX;
     } else if (max_probe_size < PROBE_BUF_MIN) {
+        av_log(logctx, AV_LOG_ERROR,
+               "Specified probe size value %u cannot be < %u\n", max_probe_size, PROBE_BUF_MIN);
         return AVERROR(EINVAL);
     }
 
@@ -1809,7 +1811,10 @@ int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp,
 static int64_t ff_read_timestamp(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit,
                                  int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ))
 {
-    return wrap_timestamp(s->streams[stream_index], read_timestamp(s, stream_index, ppos, pos_limit));
+    int64_t ts = read_timestamp(s, stream_index, ppos, pos_limit);
+    if (stream_index >= 0)
+        ts = wrap_timestamp(s->streams[stream_index], ts);
+    return ts;
 }
 
 int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags)
@@ -1902,10 +1907,10 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts,
         filesize = avio_size(s->pb);
         pos_max = filesize - 1;
         do{
-            pos_max -= step;
+            pos_max = FFMAX(0, pos_max - step);
             ts_max = ff_read_timestamp(s, stream_index, &pos_max, pos_max + step, read_timestamp);
             step += step;
-        }while(ts_max == AV_NOPTS_VALUE && pos_max >= step);
+        }while(ts_max == AV_NOPTS_VALUE && pos_max > 0);
         if (ts_max == AV_NOPTS_VALUE)
             return -1;
 
@@ -2134,6 +2139,9 @@ int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int
     if(min_ts > ts || max_ts < ts)
         return -1;
 
+    if(s->seek2any>0)
+        flags |= AVSEEK_FLAG_ANY;
+
     if (s->iformat->read_seek2) {
         int ret;
         ff_read_frame_flush(s);
@@ -2266,8 +2274,10 @@ static void update_stream_timings(AVFormatContext *ic)
     }
         if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration != AV_NOPTS_VALUE) {
             /* compute the bitrate */
-            ic->bit_rate = (double)filesize * 8.0 * AV_TIME_BASE /
+            double bitrate = (double)filesize * 8.0 * AV_TIME_BASE /
                 (double)ic->duration;
+            if (bitrate >= 0 && bitrate <= INT_MAX)
+                ic->bit_rate = bitrate;
         }
 }
 
@@ -2390,8 +2400,10 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
                 else
                     duration -= st->first_dts;
                 if (duration > 0) {
-                    if (st->duration == AV_NOPTS_VALUE || st->duration < duration)
+                    if (st->duration == AV_NOPTS_VALUE || st->info->last_duration<=0 ||
+                        (st->duration < duration && FFABS(duration - st->info->last_duration) < 60LL*st->time_base.den / st->time_base.num))
                         st->duration = duration;
+                    st->info->last_duration = duration;
                 }
             }
             av_free_packet(pkt);
@@ -2494,6 +2506,9 @@ static int has_codec_parameters(AVStream *st, const char **errmsg_ptr)
             FAIL("unspecified size");
         if (st->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE)
             FAIL("unspecified pixel format");
+        if (st->codec->codec_id == AV_CODEC_ID_RV30 || st->codec->codec_id == AV_CODEC_ID_RV40)
+            if (!st->sample_aspect_ratio.num && !st->codec->sample_aspect_ratio.num && !st->codec_info_nb_frames)
+                FAIL("no frame in rv30/40 and no sar");
         break;
     case AVMEDIA_TYPE_SUBTITLE:
         if (avctx->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE && !avctx->width)
@@ -2647,11 +2662,26 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags)
 }
 
 unsigned int av_codec_get_tag(const AVCodecTag * const *tags, enum AVCodecID id)
+{
+    unsigned int tag;
+    if (!av_codec_get_tag2(tags, id, &tag))
+        return 0;
+    return tag;
+}
+
+int av_codec_get_tag2(const AVCodecTag * const *tags, enum AVCodecID id,
+                      unsigned int *tag)
 {
     int i;
     for(i=0; tags && tags[i]; i++){
-        int tag= ff_codec_get_tag(tags[i], id);
-        if(tag) return tag;
+        const AVCodecTag *codec_tags = tags[i];
+        while (codec_tags->id != AV_CODEC_ID_NONE) {
+            if (codec_tags->id == id) {
+                *tag = codec_tags->tag;
+                return 1;
+            }
+            codec_tags++;
+        }
     }
     return 0;
 }
@@ -2823,6 +2853,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
                 fps_analyze_framecount *= 2;
             if (ic->fps_probe_size >= 0)
                 fps_analyze_framecount = ic->fps_probe_size;
+            if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+                fps_analyze_framecount = 0;
             /* variable fps and no guess at the real fps */
             if(   tb_unreliable(st->codec) && !(st->r_frame_rate.num && st->avg_frame_rate.num)
                && st->info->duration_count < fps_analyze_framecount
@@ -2861,7 +2893,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
         /* we did not get all the codec info, but we read too much data */
         if (read_size >= ic->probesize) {
             ret = count;
-            av_log(ic, AV_LOG_DEBUG, "Probe buffer size limit %d reached\n", ic->probesize);
+            av_log(ic, AV_LOG_DEBUG, "Probe buffer size limit of %d bytes reached\n", ic->probesize);
             for (i = 0; i < ic->nb_streams; i++)
                 if (!ic->streams[i]->r_frame_rate.num &&
                     ic->streams[i]->info->duration_count <= 1)
@@ -2937,7 +2969,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
                 t = FFMAX(t, av_rescale_q(st->codec_info_nb_frames, av_inv_q(st->avg_frame_rate), AV_TIME_BASE_Q));
 
             if (t >= ic->max_analyze_duration) {
-                av_log(ic, AV_LOG_WARNING, "max_analyze_duration %d reached at %"PRId64"\n", ic->max_analyze_duration, t);
+                av_log(ic, AV_LOG_WARNING, "max_analyze_duration %d reached at %"PRId64" microseconds\n", ic->max_analyze_duration, t);
                 break;
             }
             if (pkt->duration) {
@@ -2949,13 +2981,17 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
         {
             int64_t last = st->info->last_dts;
 
-            if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && pkt->dts > last){
+            if(   pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && pkt->dts > last
+               && pkt->dts - (uint64_t)last < INT64_MAX){
                 double dts= (is_relative(pkt->dts) ?  pkt->dts - RELATIVE_TS_BASE : pkt->dts) * av_q2d(st->time_base);
                 int64_t duration= pkt->dts - last;
 
+                if (!st->info->duration_error)
+                    st->info->duration_error = av_mallocz(sizeof(st->info->duration_error[0])*2);
+
 //                 if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
 //                     av_log(NULL, AV_LOG_ERROR, "%f\n", dts);
-                for (i=0; iinfo->duration_error[0][0]); i++) {
+                for (i=0; icodec->codec_type == AVMEDIA_TYPE_VIDEO) {
             if(st->codec->codec_id == AV_CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_coded_sample){
                 uint32_t tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
-                if(ff_find_pix_fmt(ff_raw_pix_fmt_tags, tag) == st->codec->pix_fmt)
+                if (avpriv_find_pix_fmt(ff_raw_pix_fmt_tags, tag) == st->codec->pix_fmt)
                     st->codec->codec_tag= tag;
             }
 
@@ -3088,7 +3124,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
                 int num = 0;
                 double best_error= 0.01;
 
-                for (j=0; jinfo->duration_error[0][0]); j++) {
+                for (j=0; jinfo->codec_info_duration && st->info->codec_info_duration*av_q2d(st->time_base) < (1001*12.0)/get_std_framerate(j))
@@ -3149,8 +3185,11 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
 
  find_stream_info_err:
     for (i=0; i < ic->nb_streams; i++) {
+        st = ic->streams[i];
         if (ic->streams[i]->codec)
             ic->streams[i]->codec->thread_count = 0;
+        if (st->info)
+            av_freep(&st->info->duration_error);
         av_freep(&ic->streams[i]->info);
     }
     if(ic->pb)
@@ -3270,6 +3309,8 @@ void ff_free_stream(AVFormatContext *s, AVStream *st){
     av_freep(&st->codec->subtitle_header);
     av_freep(&st->codec);
     av_freep(&st->priv_data);
+    if (st->info)
+        av_freep(&st->info->duration_error);
     av_freep(&st->info);
     av_freep(&st->probe_data.buf);
     av_freep(&s->streams[ --s->nb_streams ]);
@@ -3692,11 +3733,11 @@ int av_get_frame_filename(char *buf, int buf_size,
         if (c == '%') {
             do {
                 nd = 0;
-                while (isdigit(*p)) {
+                while (av_isdigit(*p)) {
                     nd = nd * 10 + *p++ - '0';
                 }
                 c = *p++;
-            } while (isdigit(c));
+            } while (av_isdigit(c));
 
             switch(c) {
             case '%':
@@ -3917,7 +3958,7 @@ int ff_hex_to_data(uint8_t *data, const char *p)
         p += strspn(p, SPACE_CHARS);
         if (*p == '\0')
             break;
-        c = toupper((unsigned char) *p++);
+        c = av_toupper((unsigned char) *p++);
         if (c >= '0' && c <= '9')
             c = c - '0';
         else if (c >= 'A' && c <= 'F')
@@ -4021,6 +4062,10 @@ int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
         local_pkt.dts = av_rescale_q(pkt->dts,
                                      src->streams[pkt->stream_index]->time_base,
                                      dst->streams[dst_stream]->time_base);
+    if (pkt->duration)
+        local_pkt.duration = av_rescale_q(pkt->duration,
+                                          src->streams[pkt->stream_index]->time_base,
+                                          dst->streams[dst_stream]->time_base);
     return av_write_frame(dst, &local_pkt);
 }
 
@@ -4036,7 +4081,7 @@ void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
         int key_len, dest_len = 0;
 
         /* Skip whitespace and potential commas. */
-        while (*ptr && (isspace(*ptr) || *ptr == ','))
+        while (*ptr && (av_isspace(*ptr) || *ptr == ','))
             ptr++;
         if (!*ptr)
             break;
@@ -4069,7 +4114,7 @@ void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
             if (*ptr == '\"')
                 ptr++;
         } else {
-            for (; *ptr && !(isspace(*ptr) || *ptr == ','); ptr++)
+            for (; *ptr && !(av_isspace(*ptr) || *ptr == ','); ptr++)
                 if (dest && dest < dest_end)
                     *dest++ = *ptr;
         }
@@ -4433,3 +4478,57 @@ void ff_generate_avci_extradata(AVStream *st)
     memcpy(st->codec->extradata, data, size);
     st->codec->extradata_size = size;
 }
+
+static int match_host_pattern(const char *pattern, const char *hostname)
+{
+    int len_p, len_h;
+    if (!strcmp(pattern, "*"))
+        return 1;
+    // Skip a possible *. at the start of the pattern
+    if (pattern[0] == '*')
+        pattern++;
+    if (pattern[0] == '.')
+        pattern++;
+    len_p = strlen(pattern);
+    len_h = strlen(hostname);
+    if (len_p > len_h)
+        return 0;
+    // Simply check if the end of hostname is equal to 'pattern'
+    if (!strcmp(pattern, &hostname[len_h - len_p])) {
+        if (len_h == len_p)
+            return 1; // Exact match
+        if (hostname[len_h - len_p - 1] == '.')
+            return 1; // The matched substring is a domain and not just a substring of a domain
+    }
+    return 0;
+}
+
+int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
+{
+    char *buf, *start;
+    int ret = 0;
+    if (!no_proxy)
+        return 0;
+    if (!hostname)
+        return 0;
+    buf = av_strdup(no_proxy);
+    if (!buf)
+        return 0;
+    start = buf;
+    while (start) {
+        char *sep, *next = NULL;
+        start += strspn(start, " ,");
+        sep = start + strcspn(start, " ,");
+        if (*sep) {
+            next = sep + 1;
+            *sep = '\0';
+        }
+        if (match_host_pattern(start, hostname)) {
+            ret = 1;
+            break;
+        }
+        start = next;
+    }
+    av_free(buf);
+    return ret;
+}
diff --git a/mythtv/external/FFmpeg/libavformat/version.h b/mythtv/external/FFmpeg/libavformat/version.h
index 49cd01a9d8b..672b9003bff 100644
--- a/mythtv/external/FFmpeg/libavformat/version.h
+++ b/mythtv/external/FFmpeg/libavformat/version.h
@@ -30,8 +30,8 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 54
-#define LIBAVFORMAT_VERSION_MINOR 59
-#define LIBAVFORMAT_VERSION_MICRO 106
+#define LIBAVFORMAT_VERSION_MINOR 63
+#define LIBAVFORMAT_VERSION_MICRO 104
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \
diff --git a/mythtv/external/FFmpeg/libavformat/w64.c b/mythtv/external/FFmpeg/libavformat/w64.c
index dc0f63c7b3d..7bf5502f7cd 100644
--- a/mythtv/external/FFmpeg/libavformat/w64.c
+++ b/mythtv/external/FFmpeg/libavformat/w64.c
@@ -29,6 +29,9 @@ const uint8_t ff_w64_guid_wave[16] = { 'w', 'a', 'v', 'e',
 const uint8_t ff_w64_guid_fmt [16] = { 'f', 'm', 't', ' ',
     0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
 
+const uint8_t ff_w64_guid_fact[16] = { 'f', 'a', 'c', 't',
+    0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
+
 const uint8_t ff_w64_guid_data[16] = { 'd', 'a', 't', 'a',
     0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
 
diff --git a/mythtv/external/FFmpeg/libavformat/w64.h b/mythtv/external/FFmpeg/libavformat/w64.h
index e9f6d2b475c..0ec3fa91413 100644
--- a/mythtv/external/FFmpeg/libavformat/w64.h
+++ b/mythtv/external/FFmpeg/libavformat/w64.h
@@ -24,6 +24,7 @@
 extern const uint8_t ff_w64_guid_riff[16];
 extern const uint8_t ff_w64_guid_wave[16];
 extern const uint8_t ff_w64_guid_fmt [16];
+extern const uint8_t ff_w64_guid_fact[16];
 extern const uint8_t ff_w64_guid_data[16];
 extern const uint8_t ff_w64_guid_summarylist[16];
 
diff --git a/mythtv/external/FFmpeg/libavformat/wavdec.c b/mythtv/external/FFmpeg/libavformat/wavdec.c
index 451187739ff..782fa6416d1 100644
--- a/mythtv/external/FFmpeg/libavformat/wavdec.c
+++ b/mythtv/external/FFmpeg/libavformat/wavdec.c
@@ -610,6 +610,12 @@ static int w64_read_header(AVFormatContext *s)
             avio_skip(pb, FFALIGN(size, INT64_C(8)) - size);
 
             avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+        } else if (!memcmp(guid, ff_w64_guid_fact, 16)) {
+            int64_t samples;
+
+            samples = avio_rl64(pb);
+            if (samples > 0)
+                st->duration = samples;
         } else if (!memcmp(guid, ff_w64_guid_data, 16)) {
             wav->data_end = avio_tell(pb) + size - 24;
 
diff --git a/mythtv/external/FFmpeg/libavformat/wavenc.c b/mythtv/external/FFmpeg/libavformat/wavenc.c
index 79e3713a9b5..fea38cf3260 100644
--- a/mythtv/external/FFmpeg/libavformat/wavenc.c
+++ b/mythtv/external/FFmpeg/libavformat/wavenc.c
@@ -5,6 +5,9 @@
  * Sony Wave64 muxer
  * Copyright (c) 2012 Paul B Mahol
  *
+ * WAV muxer RF64 support
+ * Copyright (c) 2013 Daniel Verkamp 
+ *
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -36,14 +39,20 @@
 #include "internal.h"
 #include "riff.h"
 
+#define RF64_AUTO   (-1)
+#define RF64_NEVER  0
+#define RF64_ALWAYS 1
+
 typedef struct WAVMuxContext {
     const AVClass *class;
     int64_t data;
     int64_t fact_pos;
+    int64_t ds64;
     int64_t minpts;
     int64_t maxpts;
     int last_duration;
     int write_bext;
+    int rf64;
 } WAVMuxContext;
 
 #if CONFIG_WAV_MUXER
@@ -107,10 +116,24 @@ static int wav_write_header(AVFormatContext *s)
     AVIOContext *pb = s->pb;
     int64_t fmt;
 
-    ffio_wfourcc(pb, "RIFF");
-    avio_wl32(pb, 0); /* file length */
+    if (wav->rf64 == RF64_ALWAYS) {
+        ffio_wfourcc(pb, "RF64");
+        avio_wl32(pb, -1); /* RF64 chunk size: use size in ds64 */
+    } else {
+        ffio_wfourcc(pb, "RIFF");
+        avio_wl32(pb, 0); /* file length */
+    }
+
     ffio_wfourcc(pb, "WAVE");
 
+    if (wav->rf64 != RF64_NEVER) {
+        /* write empty ds64 chunk or JUNK chunk to reserve space for ds64 */
+        ffio_wfourcc(pb, wav->rf64 == RF64_ALWAYS ? "ds64" : "JUNK");
+        avio_wl32(pb, 28); /* chunk size */
+        wav->ds64 = avio_tell(pb);
+        ffio_fill(pb, 0, 28);
+    }
+
     /* format header */
     fmt = ff_start_tag(pb, "fmt ");
     if (ff_put_wav_header(pb, s->streams[0]->codec) < 0) {
@@ -163,29 +186,63 @@ static int wav_write_trailer(AVFormatContext *s)
 {
     AVIOContext *pb  = s->pb;
     WAVMuxContext    *wav = s->priv_data;
-    int64_t file_size;
+    int64_t file_size, data_size;
+    int64_t number_of_samples = 0;
+    int rf64 = 0;
 
     avio_flush(pb);
 
     if (s->pb->seekable) {
-        ff_end_tag(pb, wav->data);
-
         /* update file size */
         file_size = avio_tell(pb);
-        avio_seek(pb, 4, SEEK_SET);
-        avio_wl32(pb, (uint32_t)(file_size - 8));
-        avio_seek(pb, file_size, SEEK_SET);
+        data_size = file_size - wav->data;
+        if (wav->rf64 == RF64_ALWAYS || (wav->rf64 == RF64_AUTO && file_size - 8 > UINT32_MAX)) {
+            rf64 = 1;
+        } else {
+            avio_seek(pb, 4, SEEK_SET);
+            avio_wl32(pb, (uint32_t)(file_size - 8));
+            avio_seek(pb, file_size, SEEK_SET);
 
-        avio_flush(pb);
+            ff_end_tag(pb, wav->data);
+            avio_flush(pb);
+        }
+
+        number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration,
+                                       s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num,
+                                       s->streams[0]->time_base.den);
 
         if(s->streams[0]->codec->codec_tag != 0x01) {
             /* Update num_samps in fact chunk */
-            int number_of_samples;
-            number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration,
-                                           s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num,
-                                           s->streams[0]->time_base.den);
             avio_seek(pb, wav->fact_pos, SEEK_SET);
-            avio_wl32(pb, number_of_samples);
+            if (rf64 || (wav->rf64 == RF64_AUTO && number_of_samples > UINT32_MAX)) {
+                rf64 = 1;
+                avio_wl32(pb, -1);
+            } else {
+                avio_wl32(pb, number_of_samples);
+                avio_seek(pb, file_size, SEEK_SET);
+                avio_flush(pb);
+            }
+        }
+
+        if (rf64) {
+            /* overwrite RIFF with RF64 */
+            avio_seek(pb, 0, SEEK_SET);
+            ffio_wfourcc(pb, "RF64");
+            avio_wl32(pb, -1);
+
+            /* write ds64 chunk (overwrite JUNK if rf64 == RF64_AUTO) */
+            avio_seek(pb, wav->ds64 - 8, SEEK_SET);
+            ffio_wfourcc(pb, "ds64");
+            avio_wl32(pb, 28);                  /* ds64 chunk size */
+            avio_wl64(pb, file_size - 8);       /* RF64 chunk size */
+            avio_wl64(pb, data_size);           /* data chunk size */
+            avio_wl64(pb, number_of_samples);   /* fact chunk number of samples */
+            avio_wl32(pb, 0);                   /* number of table entries for non-'data' chunks */
+
+            /* write -1 in data chunk size */
+            avio_seek(pb, wav->data - 4, SEEK_SET);
+            avio_wl32(pb, -1);
+
             avio_seek(pb, file_size, SEEK_SET);
             avio_flush(pb);
         }
@@ -197,6 +254,10 @@ static int wav_write_trailer(AVFormatContext *s)
 #define ENC AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
     { "write_bext", "Write BEXT chunk.", OFFSET(write_bext), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, ENC },
+    { "rf64",       "Use RF64 header rather than RIFF for large files.",    OFFSET(rf64), AV_OPT_TYPE_INT,   { .i64 = RF64_NEVER  },-1, 1, ENC, "rf64" },
+    { "auto",       "Write RF64 header if file grows large enough.",        0,            AV_OPT_TYPE_CONST, { .i64 = RF64_AUTO   }, 0, 0, ENC, "rf64" },
+    { "always",     "Always write RF64 header regardless of file size.",    0,            AV_OPT_TYPE_CONST, { .i64 = RF64_ALWAYS }, 0, 0, ENC, "rf64" },
+    { "never",      "Never write RF64 header regardless of file size.",     0,            AV_OPT_TYPE_CONST, { .i64 = RF64_NEVER  }, 0, 0, ENC, "rf64" },
     { NULL },
 };
 
@@ -263,6 +324,14 @@ static int w64_write_header(AVFormatContext *s)
         return ret;
     }
     end_guid(pb, start);
+
+    if (s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */
+        && s->pb->seekable) {
+        start_guid(pb, ff_w64_guid_fact, &wav->fact_pos);
+        avio_wl64(pb, 0);
+        end_guid(pb, wav->fact_pos);
+    }
+
     start_guid(pb, ff_w64_guid_data, &wav->data);
 
     return 0;
@@ -280,8 +349,18 @@ static int w64_write_trailer(AVFormatContext *s)
         file_size = avio_tell(pb);
         avio_seek(pb, 16, SEEK_SET);
         avio_wl64(pb, file_size);
-        avio_seek(pb, file_size, SEEK_SET);
 
+        if (s->streams[0]->codec->codec_tag != 0x01) {
+            int64_t number_of_samples;
+
+            number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration,
+                                           s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num,
+                                           s->streams[0]->time_base.den);
+            avio_seek(pb, wav->fact_pos + 24, SEEK_SET);
+            avio_wl64(pb, number_of_samples);
+        }
+
+        avio_seek(pb, file_size, SEEK_SET);
         avio_flush(pb);
     }
 
diff --git a/mythtv/external/FFmpeg/libavformat/wtvdec.c b/mythtv/external/FFmpeg/libavformat/wtvdec.c
index 55c99d634a1..676e0f72a2b 100644
--- a/mythtv/external/FFmpeg/libavformat/wtvdec.c
+++ b/mythtv/external/FFmpeg/libavformat/wtvdec.c
@@ -200,6 +200,9 @@ static AVIOContext * wtvfile_open_sector(int first_sector, uint64_t length, int
         return NULL;
     }
 
+    if ((int64_t)wf->sectors[wf->nb_sectors - 1] << WTV_SECTOR_BITS > avio_tell(s->pb))
+        av_log(s, AV_LOG_WARNING, "truncated file\n");
+
     /* check length */
     length &= 0xFFFFFFFFFFFF;
     if (length > ((int64_t)wf->nb_sectors << wf->sector_bits)) {
@@ -445,8 +448,16 @@ static void get_attachment(AVFormatContext *s, AVIOContext *pb, int length)
 
 static void get_tag(AVFormatContext *s, AVIOContext *pb, const char *key, int type, int length)
 {
-    int buf_size = FFMAX(2*length, LEN_PRETTY_GUID) + 1;
-    char *buf = av_malloc(buf_size);
+    int buf_size;
+    char *buf;
+
+    if (!strcmp(key, "WM/MediaThumbType")) {
+        avio_skip(pb, length);
+        return;
+    }
+
+    buf_size = FFMAX(2*length, LEN_PRETTY_GUID) + 1;
+    buf = av_malloc(buf_size);
     if (!buf)
         return;
 
diff --git a/mythtv/external/FFmpeg/libavformat/wtvenc.c b/mythtv/external/FFmpeg/libavformat/wtvenc.c
index 304bd14f746..22917a454cf 100644
--- a/mythtv/external/FFmpeg/libavformat/wtvenc.c
+++ b/mythtv/external/FFmpeg/libavformat/wtvenc.c
@@ -103,6 +103,8 @@ typedef struct {
 
     int64_t last_pts;
     int64_t last_serial;
+
+    AVPacket thumbnail;
 } WtvContext;
 
 
@@ -378,6 +380,8 @@ static int write_header(AVFormatContext *s)
 
     for (i = 0; i < s->nb_streams; i++) {
         st = s->streams[i];
+        if (st->codec->codec_id == AV_CODEC_ID_MJPEG)
+            continue;
         ret = write_stream_codec(s, st);
         if (ret < 0) {
             av_log(s, AV_LOG_ERROR, "write stream codec failed codec_type(0x%x)\n", st->codec->codec_type);
@@ -389,6 +393,8 @@ static int write_header(AVFormatContext *s)
 
     for (i = 0; i < s->nb_streams; i++) {
         st = s->streams[i];
+        if (st->codec->codec_id == AV_CODEC_ID_MJPEG)
+            continue;
         ret  = write_stream_data(s, st);
         if (ret < 0) {
             av_log(s, AV_LOG_ERROR, "write stream data failed codec_type(0x%x)\n", st->codec->codec_type);
@@ -425,6 +431,11 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
     AVIOContext *pb = s->pb;
     WtvContext  *wctx = s->priv_data;
 
+    if (s->streams[pkt->stream_index]->codec->codec_id == AV_CODEC_ID_MJPEG && !wctx->thumbnail.size) {
+        av_copy_packet(&wctx->thumbnail, pkt);
+        return 0;
+    }
+
     /* emit sync chunk and 'timeline.table.0.entries.Event' record every 50 frames */
     if (wctx->serial - (wctx->nb_sp_pairs ? wctx->sp_pairs[wctx->nb_sp_pairs - 1].serial : 0) >= 50)
         write_sync(s);
@@ -590,27 +601,66 @@ static void write_table_entries_time(AVFormatContext *s)
     avio_wl64(pb, wctx->last_serial);
 }
 
-static void write_tag(AVIOContext *pb, const char *key, const char *value)
+static void write_metadata_header(AVIOContext *pb, int type, const char *key, int value_size)
 {
     ff_put_guid(pb, &ff_metadata_guid);
-    avio_wl32(pb, 1);
-    avio_wl32(pb, strlen(value)*2 + 2);
+    avio_wl32(pb, type);
+    avio_wl32(pb, value_size);
     avio_put_str16le(pb, key);
+}
+
+static int metadata_header_size(const char *key)
+{
+    return 16 + 4 + 4 + strlen(key)*2 + 2;
+}
+
+static void write_tag_int32(AVIOContext *pb, const char *key, int value)
+{
+    write_metadata_header(pb, 0, key, 4);
+    avio_wl32(pb, value);
+}
+
+static void write_tag(AVIOContext *pb, const char *key, const char *value)
+{
+    write_metadata_header(pb, 1, key, strlen(value)*2 + 2);
     avio_put_str16le(pb, value);
 }
 
+static int attachment_value_size(const AVPacket *pkt, const AVDictionaryEntry *e)
+{
+    return strlen("image/jpeg")*2 + 2 + 1 + (e ? strlen(e->value)*2 : 0) + 2 + 4 + pkt->size;
+}
+
 static void write_table_entries_attrib(AVFormatContext *s)
 {
+    WtvContext *wctx = s->priv_data;
+    AVIOContext *pb = s->pb;
     AVDictionaryEntry *tag = 0;
 
     //FIXME: translate special tags (e.g. WM/Bitrate) to binary representation
     ff_metadata_conv(&s->metadata, ff_asf_metadata_conv, NULL);
     while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))
-        write_tag(s->pb, tag->key, tag->value);
+        write_tag(pb, tag->key, tag->value);
+
+    if (wctx->thumbnail.size) {
+        AVStream *st = s->streams[wctx->thumbnail.stream_index];
+        tag = av_dict_get(st->metadata, "title", NULL, 0);
+        write_metadata_header(pb, 2, "WM/Picture", attachment_value_size(&wctx->thumbnail, tag));
+
+        avio_put_str16le(pb, "image/jpeg");
+        avio_w8(pb, 0x10);
+        avio_put_str16le(pb, tag ? tag->value : "");
+
+        avio_wl32(pb, wctx->thumbnail.size);
+        avio_write(pb, wctx->thumbnail.data, wctx->thumbnail.size);
+
+        write_tag_int32(pb, "WM/MediaThumbType", 2);
+    }
 }
 
 static void write_table_redirector_legacy_attrib(AVFormatContext *s)
 {
+    WtvContext *wctx = s->priv_data;
     AVIOContext *pb = s->pb;
     AVDictionaryEntry *tag = 0;
     int64_t pos = 0;
@@ -618,7 +668,16 @@ static void write_table_redirector_legacy_attrib(AVFormatContext *s)
     //FIXME: translate special tags to binary representation
     while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
         avio_wl64(pb, pos);
-        pos += 16 + 4 + 4 + strlen(tag->key)*2 + 2 + strlen(tag->value)*2 + 2;
+        pos += metadata_header_size(tag->key) + strlen(tag->value)*2 + 2;
+    }
+
+    if (wctx->thumbnail.size) {
+        AVStream *st = s->streams[wctx->thumbnail.stream_index];
+        avio_wl64(pb, pos);
+        pos += metadata_header_size("WM/Picture") + attachment_value_size(&wctx->thumbnail, av_dict_get(st->metadata, "title", NULL, 0));
+
+        avio_wl64(pb, pos);
+        pos += metadata_header_size("WM/MediaThumbType") + 4;
     }
 }
 
@@ -732,6 +791,7 @@ static int write_trailer(AVFormatContext *s)
 
     av_free(wctx->sp_pairs);
     av_free(wctx->st_pairs);
+    av_free_packet(&wctx->thumbnail);
     return 0;
 }
 
diff --git a/mythtv/external/FFmpeg/libavformat/yuv4mpeg.c b/mythtv/external/FFmpeg/libavformat/yuv4mpeg.c
index 9c9c7fa8fe6..f34a4afce1c 100644
--- a/mythtv/external/FFmpeg/libavformat/yuv4mpeg.c
+++ b/mythtv/external/FFmpeg/libavformat/yuv4mpeg.c
@@ -18,6 +18,8 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/pixdesc.h"
 #include "avformat.h"
 #include "internal.h"
 #include "libavutil/pixdesc.h"
@@ -26,11 +28,6 @@
 #define Y4M_FRAME_MAGIC "FRAME"
 #define Y4M_LINE_MAX 256
 
-struct frame_attributes {
-    int interlaced_frame;
-    int top_field_first;
-};
-
 #if CONFIG_YUV4MPEGPIPE_MUXER
 static int yuv4_generate_header(AVFormatContext *s, char* buf)
 {
@@ -56,6 +53,13 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf)
     inter = 'p'; /* progressive is the default */
     if (st->codec->coded_frame && st->codec->coded_frame->interlaced_frame)
         inter = st->codec->coded_frame->top_field_first ? 't' : 'b';
+    if (st->codec->field_order == AV_FIELD_PROGRESSIVE) {
+        inter = 'p';
+    } else if (st->codec->field_order == AV_FIELD_TB || st->codec->field_order == AV_FIELD_TT) {
+        inter = 't';
+    } else if (st->codec->field_order == AV_FIELD_BT || st->codec->field_order == AV_FIELD_BB) {
+        inter = 'b';
+    }
 
     switch (st->codec->pix_fmt) {
     case AV_PIX_FMT_GRAY8:
@@ -211,8 +215,8 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt)
     if (st->codec->pix_fmt != AV_PIX_FMT_GRAY8 &&
         st->codec->pix_fmt != AV_PIX_FMT_GRAY16) {
         // Adjust for smaller Cb and Cr planes
-        avcodec_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift,
-                                      &v_chroma_shift);
+        av_pix_fmt_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift,
+                                         &v_chroma_shift);
         width  >>= h_chroma_shift;
         height >>= v_chroma_shift;
 
@@ -317,7 +321,7 @@ static int yuv4_read_header(AVFormatContext *s)
 {
     char header[MAX_YUV4_HEADER + 10];  // Include headroom for
                                         // the longest option
-    char *tokstart, *tokend, *header_end;
+    char *tokstart, *tokend, *header_end, interlaced = '?';
     int i;
     AVIOContext *pb = s->pb;
     int width = -1, height  = -1, raten   = 0,
@@ -325,7 +329,6 @@ static int yuv4_read_header(AVFormatContext *s)
     enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE, alt_pix_fmt = AV_PIX_FMT_NONE;
     enum AVChromaLocation chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
     AVStream *st;
-    struct frame_attributes *s1 = s->priv_data;
 
     for (i = 0; i < MAX_YUV4_HEADER; i++) {
         header[i] = avio_r8(pb);
@@ -341,8 +344,6 @@ static int yuv4_read_header(AVFormatContext *s)
     if (strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC)))
         return -1;
 
-    s1->interlaced_frame = 0;
-    s1->top_field_first = 0;
     header_end = &header[i + 1]; // Include space
     for (tokstart = &header[strlen(Y4M_MAGIC) + 1];
          tokstart < header_end; tokstart++) {
@@ -423,28 +424,7 @@ static int yuv4_read_header(AVFormatContext *s)
                 tokstart++;
             break;
         case 'I': // Interlace type
-            switch (*tokstart++){
-            case '?':
-                break;
-            case 'p':
-                s1->interlaced_frame = 0;
-                break;
-            case 't':
-                s1->interlaced_frame = 1;
-                s1->top_field_first = 1;
-                break;
-            case 'b':
-                s1->interlaced_frame = 1;
-                s1->top_field_first = 0;
-                break;
-            case 'm':
-                av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains mixed "
-                       "interlaced and non-interlaced frames.\n");
-                return -1;
-            default:
-                av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n");
-                return -1;
-            }
+            interlaced = *tokstart++;
             break;
         case 'F': // Frame rate
             sscanf(tokstart, "%d:%d", &raten, &rated); // 0:0 if unknown
@@ -545,6 +525,27 @@ static int yuv4_read_header(AVFormatContext *s)
     st->sample_aspect_ratio           = (AVRational){ aspectn, aspectd };
     st->codec->chroma_sample_location = chroma_sample_location;
 
+    switch (interlaced){
+    case 'p':
+        st->codec->field_order = AV_FIELD_PROGRESSIVE;
+        break;
+    case 't':
+        st->codec->field_order = AV_FIELD_TB;
+        break;
+    case 'b':
+        st->codec->field_order = AV_FIELD_BT;
+        break;
+    case 'm':
+        av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains mixed "
+               "interlaced and non-interlaced frames.\n");
+    case '?':
+        st->codec->field_order = AV_FIELD_UNKNOWN;
+        break;
+    default:
+        av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n");
+        return AVERROR(EINVAL);
+    }
+
     return 0;
 }
 
@@ -554,7 +555,6 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
     char header[MAX_FRAME_HEADER+1];
     int packet_size, width, height, ret;
     AVStream *st = s->streams[0];
-    struct frame_attributes *s1 = s->priv_data;
 
     for (i = 0; i < MAX_FRAME_HEADER; i++) {
         header[i] = avio_r8(s->pb);
@@ -586,11 +586,6 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
     else if (ret != packet_size)
         return s->pb->eof_reached ? AVERROR_EOF : AVERROR(EIO);
 
-    if (st->codec->coded_frame) {
-        st->codec->coded_frame->interlaced_frame = s1->interlaced_frame;
-        st->codec->coded_frame->top_field_first  = s1->top_field_first;
-    }
-
     pkt->stream_index = 0;
     return 0;
 }
@@ -608,7 +603,6 @@ static int yuv4_probe(AVProbeData *pd)
 AVInputFormat ff_yuv4mpegpipe_demuxer = {
     .name           = "yuv4mpegpipe",
     .long_name      = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
-    .priv_data_size = sizeof(struct frame_attributes),
     .read_probe     = yuv4_probe,
     .read_header    = yuv4_read_header,
     .read_packet    = yuv4_read_packet,
diff --git a/mythtv/external/FFmpeg/libavresample/audio_convert.c b/mythtv/external/FFmpeg/libavresample/audio_convert.c
index eb3bc1f1de1..371617cc254 100644
--- a/mythtv/external/FFmpeg/libavresample/audio_convert.c
+++ b/mythtv/external/FFmpeg/libavresample/audio_convert.c
@@ -30,7 +30,6 @@
 #include "audio_convert.h"
 #include "audio_data.h"
 #include "dither.h"
-#include "internal.h"
 
 enum ConvFuncType {
     CONV_FUNC_TYPE_FLAT,
@@ -51,6 +50,7 @@ struct AudioConvert {
     DitherContext *dc;
     enum AVSampleFormat in_fmt;
     enum AVSampleFormat out_fmt;
+    int apply_map;
     int channels;
     int planes;
     int ptr_align;
@@ -260,7 +260,8 @@ void ff_audio_convert_free(AudioConvert **ac)
 AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr,
                                      enum AVSampleFormat out_fmt,
                                      enum AVSampleFormat in_fmt,
-                                     int channels, int sample_rate)
+                                     int channels, int sample_rate,
+                                     int apply_map)
 {
     AudioConvert *ac;
     int in_planar, out_planar;
@@ -273,11 +274,13 @@ AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr,
     ac->out_fmt  = out_fmt;
     ac->in_fmt   = in_fmt;
     ac->channels = channels;
+    ac->apply_map = apply_map;
 
     if (avr->dither_method != AV_RESAMPLE_DITHER_NONE          &&
         av_get_packed_sample_fmt(out_fmt) == AV_SAMPLE_FMT_S16 &&
         av_get_bytes_per_sample(in_fmt) > 2) {
-        ac->dc = ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate);
+        ac->dc = ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate,
+                                 apply_map);
         if (!ac->dc) {
             av_free(ac);
             return NULL;
@@ -310,6 +313,7 @@ int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in)
 {
     int use_generic = 1;
     int len         = in->nb_samples;
+    int p;
 
     if (ac->dc) {
         /* dithered conversion */
@@ -336,32 +340,73 @@ int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in)
             av_get_sample_fmt_name(ac->out_fmt),
             use_generic ? ac->func_descr_generic : ac->func_descr);
 
-    switch (ac->func_type) {
-    case CONV_FUNC_TYPE_FLAT: {
-        int p;
-        if (!in->is_planar)
-            len *= in->channels;
-        if (use_generic) {
-            for (p = 0; p < ac->planes; p++)
-                ac->conv_flat_generic(out->data[p], in->data[p], len);
-        } else {
-            for (p = 0; p < ac->planes; p++)
-                ac->conv_flat(out->data[p], in->data[p], len);
+    if (ac->apply_map) {
+        ChannelMapInfo *map = &ac->avr->ch_map_info;
+
+        if (!av_sample_fmt_is_planar(ac->out_fmt)) {
+            av_log(ac->avr, AV_LOG_ERROR, "cannot remap packed format during conversion\n");
+            return AVERROR(EINVAL);
+        }
+
+        if (map->do_remap) {
+            if (av_sample_fmt_is_planar(ac->in_fmt)) {
+                conv_func_flat *convert = use_generic ? ac->conv_flat_generic :
+                                                        ac->conv_flat;
+
+                for (p = 0; p < ac->planes; p++)
+                    if (map->channel_map[p] >= 0)
+                        convert(out->data[p], in->data[map->channel_map[p]], len);
+            } else {
+                uint8_t *data[AVRESAMPLE_MAX_CHANNELS];
+                conv_func_deinterleave *convert = use_generic ?
+                                                  ac->conv_deinterleave_generic :
+                                                  ac->conv_deinterleave;
+
+                for (p = 0; p < ac->channels; p++)
+                    data[map->input_map[p]] = out->data[p];
+
+                convert(data, in->data[0], len, ac->channels);
+            }
+        }
+        if (map->do_copy || map->do_zero) {
+            for (p = 0; p < ac->planes; p++) {
+                if (map->channel_copy[p])
+                    memcpy(out->data[p], out->data[map->channel_copy[p]],
+                           len * out->stride);
+                else if (map->channel_zero[p])
+                    av_samples_set_silence(&out->data[p], 0, len, 1, ac->out_fmt);
+            }
+        }
+    } else {
+        switch (ac->func_type) {
+        case CONV_FUNC_TYPE_FLAT: {
+            if (!in->is_planar)
+                len *= in->channels;
+            if (use_generic) {
+                for (p = 0; p < ac->planes; p++)
+                    ac->conv_flat_generic(out->data[p], in->data[p], len);
+            } else {
+                for (p = 0; p < ac->planes; p++)
+                    ac->conv_flat(out->data[p], in->data[p], len);
+            }
+            break;
+        }
+        case CONV_FUNC_TYPE_INTERLEAVE:
+            if (use_generic)
+                ac->conv_interleave_generic(out->data[0], in->data, len,
+                                            ac->channels);
+            else
+                ac->conv_interleave(out->data[0], in->data, len, ac->channels);
+            break;
+        case CONV_FUNC_TYPE_DEINTERLEAVE:
+            if (use_generic)
+                ac->conv_deinterleave_generic(out->data, in->data[0], len,
+                                              ac->channels);
+            else
+                ac->conv_deinterleave(out->data, in->data[0], len,
+                                      ac->channels);
+            break;
         }
-        break;
-    }
-    case CONV_FUNC_TYPE_INTERLEAVE:
-        if (use_generic)
-            ac->conv_interleave_generic(out->data[0], in->data, len, ac->channels);
-        else
-            ac->conv_interleave(out->data[0], in->data, len, ac->channels);
-        break;
-    case CONV_FUNC_TYPE_DEINTERLEAVE:
-        if (use_generic)
-            ac->conv_deinterleave_generic(out->data, in->data[0], len, ac->channels);
-        else
-            ac->conv_deinterleave(out->data, in->data[0], len, ac->channels);
-        break;
     }
 
     out->nb_samples = in->nb_samples;
diff --git a/mythtv/external/FFmpeg/libavresample/audio_convert.h b/mythtv/external/FFmpeg/libavresample/audio_convert.h
index b8808f176d1..6a3089d4fbd 100644
--- a/mythtv/external/FFmpeg/libavresample/audio_convert.h
+++ b/mythtv/external/FFmpeg/libavresample/audio_convert.h
@@ -23,10 +23,9 @@
 
 #include "libavutil/samplefmt.h"
 #include "avresample.h"
+#include "internal.h"
 #include "audio_data.h"
 
-typedef struct AudioConvert AudioConvert;
-
 /**
  * Set conversion function if the parameters match.
  *
@@ -59,12 +58,14 @@ void ff_audio_convert_set_func(AudioConvert *ac, enum AVSampleFormat out_fmt,
  * @param in_fmt      input sample format
  * @param channels    number of channels
  * @param sample_rate sample rate (used for dithering)
+ * @param apply_map   apply channel map during conversion
  * @return            newly-allocated AudioConvert context
  */
 AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr,
                                      enum AVSampleFormat out_fmt,
                                      enum AVSampleFormat in_fmt,
-                                     int channels, int sample_rate);
+                                     int channels, int sample_rate,
+                                     int apply_map);
 
 /**
  * Free AudioConvert.
diff --git a/mythtv/external/FFmpeg/libavresample/audio_data.c b/mythtv/external/FFmpeg/libavresample/audio_data.c
index 199a68cb11f..c52f518e9a2 100644
--- a/mythtv/external/FFmpeg/libavresample/audio_data.c
+++ b/mythtv/external/FFmpeg/libavresample/audio_data.c
@@ -213,7 +213,7 @@ void ff_audio_data_free(AudioData **a)
     av_freep(a);
 }
 
-int ff_audio_data_copy(AudioData *dst, AudioData *src)
+int ff_audio_data_copy(AudioData *dst, AudioData *src, ChannelMapInfo *map)
 {
     int ret, p;
 
@@ -221,6 +221,11 @@ int ff_audio_data_copy(AudioData *dst, AudioData *src)
     if (dst->sample_fmt != src->sample_fmt || dst->channels < src->channels)
         return AVERROR(EINVAL);
 
+    if (map && !src->is_planar) {
+        av_log(src, AV_LOG_ERROR, "cannot remap packed format during copy\n");
+        return AVERROR(EINVAL);
+    }
+
     /* if the input is empty, just empty the output */
     if (!src->nb_samples) {
         dst->nb_samples = 0;
@@ -233,8 +238,29 @@ int ff_audio_data_copy(AudioData *dst, AudioData *src)
         return ret;
 
     /* copy data */
-    for (p = 0; p < src->planes; p++)
-        memcpy(dst->data[p], src->data[p], src->nb_samples * src->stride);
+    if (map) {
+        if (map->do_remap) {
+            for (p = 0; p < src->planes; p++) {
+                if (map->channel_map[p] >= 0)
+                    memcpy(dst->data[p], src->data[map->channel_map[p]],
+                           src->nb_samples * src->stride);
+            }
+        }
+        if (map->do_copy || map->do_zero) {
+            for (p = 0; p < src->planes; p++) {
+                if (map->channel_copy[p])
+                    memcpy(dst->data[p], dst->data[map->channel_copy[p]],
+                           src->nb_samples * src->stride);
+                else if (map->channel_zero[p])
+                    av_samples_set_silence(&dst->data[p], 0, src->nb_samples,
+                                           1, dst->sample_fmt);
+            }
+        }
+    } else {
+        for (p = 0; p < src->planes; p++)
+            memcpy(dst->data[p], src->data[p], src->nb_samples * src->stride);
+    }
+
     dst->nb_samples = src->nb_samples;
 
     return 0;
diff --git a/mythtv/external/FFmpeg/libavresample/audio_data.h b/mythtv/external/FFmpeg/libavresample/audio_data.h
index 558e7e67ecb..97236bb5de9 100644
--- a/mythtv/external/FFmpeg/libavresample/audio_data.h
+++ b/mythtv/external/FFmpeg/libavresample/audio_data.h
@@ -27,11 +27,12 @@
 #include "libavutil/log.h"
 #include "libavutil/samplefmt.h"
 #include "avresample.h"
+#include "internal.h"
 
 /**
  * Audio buffer used for intermediate storage between conversion phases.
  */
-typedef struct AudioData {
+struct AudioData {
     const AVClass *class;               /**< AVClass for logging            */
     uint8_t *data[AVRESAMPLE_MAX_CHANNELS]; /**< data plane pointers        */
     uint8_t *buffer;                    /**< data buffer                    */
@@ -50,7 +51,7 @@ typedef struct AudioData {
     int ptr_align;                      /**< minimum data pointer alignment */
     int samples_align;                  /**< allocated samples alignment    */
     const char *name;                   /**< name for debug logging         */
-} AudioData;
+};
 
 int ff_audio_data_set_channels(AudioData *a, int channels);
 
@@ -117,9 +118,10 @@ void ff_audio_data_free(AudioData **a);
  *
  * @param out  output AudioData
  * @param in   input AudioData
+ * @param map  channel map, NULL if not remapping
  * @return     0 on success, negative AVERROR value on error
  */
-int ff_audio_data_copy(AudioData *out, AudioData *in);
+int ff_audio_data_copy(AudioData *out, AudioData *in, ChannelMapInfo *map);
 
 /**
  * Append data from one AudioData to the end of another.
diff --git a/mythtv/external/FFmpeg/libavresample/audio_mix.c b/mythtv/external/FFmpeg/libavresample/audio_mix.c
index c0560288a50..b69bfbcf3ed 100644
--- a/mythtv/external/FFmpeg/libavresample/audio_mix.c
+++ b/mythtv/external/FFmpeg/libavresample/audio_mix.c
@@ -47,6 +47,11 @@ struct AudioMix {
     mix_func *mix;
     mix_func *mix_generic;
 
+    int in_matrix_channels;
+    int out_matrix_channels;
+    int output_zero[AVRESAMPLE_MAX_CHANNELS];
+    int input_skip[AVRESAMPLE_MAX_CHANNELS];
+    int output_skip[AVRESAMPLE_MAX_CHANNELS];
     int16_t *matrix_q8[AVRESAMPLE_MAX_CHANNELS];
     int32_t *matrix_q15[AVRESAMPLE_MAX_CHANNELS];
     float   *matrix_flt[AVRESAMPLE_MAX_CHANNELS];
@@ -59,8 +64,8 @@ void ff_audio_mix_set_func(AudioMix *am, enum AVSampleFormat fmt,
                            const char *descr, void *mix_func)
 {
     if (fmt == am->fmt && coeff_type == am->coeff_type &&
-        ( in_channels ==  am->in_channels ||  in_channels == 0) &&
-        (out_channels == am->out_channels || out_channels == 0)) {
+        ( in_channels ==  am->in_matrix_channels ||  in_channels == 0) &&
+        (out_channels == am->out_matrix_channels || out_channels == 0)) {
         char chan_str[16];
         am->mix           = mix_func;
         am->func_descr    = descr;
@@ -82,11 +87,12 @@ void ff_audio_mix_set_func(AudioMix *am, enum AVSampleFormat fmt,
         } else if (out_channels) {
                 snprintf(chan_str, sizeof(chan_str), "[any to %d] ",
                          out_channels);
+        } else {
+            snprintf(chan_str, sizeof(chan_str), "[any to any] ");
         }
         av_log(am->avr, AV_LOG_DEBUG, "audio_mix: found function: [fmt=%s] "
                "[c=%s] %s(%s)\n", av_get_sample_fmt_name(fmt),
-               coeff_type_names[coeff_type],
-               (in_channels || out_channels) ? chan_str : "", descr);
+               coeff_type_names[coeff_type], chan_str, descr);
     }
 }
 
@@ -278,6 +284,13 @@ static void mix_2_to_6_fltp_flt_c(float **samples, float **matrix, int len,
 
 static int mix_function_init(AudioMix *am)
 {
+    am->func_descr = am->func_descr_generic = "n/a";
+    am->mix = am->mix_generic = NULL;
+
+    /* no need to set a mix function when we're skipping mixing */
+    if (!am->in_matrix_channels || !am->out_matrix_channels)
+        return 0;
+
     /* any-to-any C versions */
 
     ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
@@ -357,9 +370,6 @@ AudioMix *ff_audio_mix_alloc(AVAudioResampleContext *avr)
             goto error;
         av_freep(&avr->mix_matrix);
     } else {
-        int i, j;
-        char in_layout_name[128];
-        char out_layout_name[128];
         double *matrix_dbl = av_mallocz(avr->out_channels * avr->in_channels *
                                         sizeof(*matrix_dbl));
         if (!matrix_dbl)
@@ -379,25 +389,13 @@ AudioMix *ff_audio_mix_alloc(AVAudioResampleContext *avr)
             goto error;
         }
 
-        av_get_channel_layout_string(in_layout_name, sizeof(in_layout_name),
-                                     avr->in_channels, avr->in_channel_layout);
-        av_get_channel_layout_string(out_layout_name, sizeof(out_layout_name),
-                                     avr->out_channels, avr->out_channel_layout);
-        av_log(avr, AV_LOG_DEBUG, "audio_mix: %s to %s\n",
-               in_layout_name, out_layout_name);
-        for (i = 0; i < avr->out_channels; i++) {
-            for (j = 0; j < avr->in_channels; j++) {
-                av_log(avr, AV_LOG_DEBUG, "  %0.3f ",
-                       matrix_dbl[i * avr->in_channels + j]);
-            }
-            av_log(avr, AV_LOG_DEBUG, "\n");
-        }
-
         ret = ff_audio_mix_set_matrix(am, matrix_dbl, avr->in_channels);
         if (ret < 0) {
+            av_log(avr, AV_LOG_ERROR, "error setting mix matrix\n");
             av_free(matrix_dbl);
             goto error;
         }
+
         av_free(matrix_dbl);
     }
 
@@ -431,6 +429,7 @@ int ff_audio_mix(AudioMix *am, AudioData *src)
 {
     int use_generic = 1;
     int len = src->nb_samples;
+    int i, j;
 
     /* determine whether to use the optimized function based on pointer and
        samples alignment in both the input and output */
@@ -446,11 +445,35 @@ int ff_audio_mix(AudioMix *am, AudioData *src)
             src->nb_samples, am->in_channels, am->out_channels,
             use_generic ? am->func_descr_generic : am->func_descr);
 
-    if (use_generic)
-        am->mix_generic(src->data, am->matrix, len, am->out_channels,
-                        am->in_channels);
-    else
-        am->mix(src->data, am->matrix, len, am->out_channels, am->in_channels);
+    if (am->in_matrix_channels && am->out_matrix_channels) {
+        uint8_t **data;
+        uint8_t *data0[AVRESAMPLE_MAX_CHANNELS];
+
+        if (am->out_matrix_channels < am->out_channels ||
+             am->in_matrix_channels <  am->in_channels) {
+            for (i = 0, j = 0; i < FFMAX(am->in_channels, am->out_channels); i++) {
+                if (am->input_skip[i] || am->output_skip[i] || am->output_zero[i])
+                    continue;
+                data0[j++] = src->data[i];
+            }
+            data = data0;
+        } else {
+            data = src->data;
+        }
+
+        if (use_generic)
+            am->mix_generic(data, am->matrix, len, am->out_matrix_channels,
+                            am->in_matrix_channels);
+        else
+            am->mix(data, am->matrix, len, am->out_matrix_channels,
+                    am->in_matrix_channels);
+    }
+
+    if (am->out_matrix_channels < am->out_channels) {
+        for (i = 0; i < am->out_channels; i++)
+            if (am->output_zero[i])
+                av_samples_set_silence(&src->data[i], 0, len, 1, am->fmt);
+    }
 
     ff_audio_data_set_channels(src, am->out_channels);
 
@@ -459,7 +482,7 @@ int ff_audio_mix(AudioMix *am, AudioData *src)
 
 int ff_audio_mix_get_matrix(AudioMix *am, double *matrix, int stride)
 {
-    int i, o;
+    int i, o, i0, o0;
 
     if ( am->in_channels <= 0 ||  am->in_channels > AVRESAMPLE_MAX_CHANNELS ||
         am->out_channels <= 0 || am->out_channels > AVRESAMPLE_MAX_CHANNELS) {
@@ -472,9 +495,19 @@ int ff_audio_mix_get_matrix(AudioMix *am, double *matrix, int stride)
         av_log(am->avr, AV_LOG_ERROR, "matrix is not set\n");               \
         return AVERROR(EINVAL);                                             \
     }                                                                       \
-    for (o = 0; o < am->out_channels; o++)                                  \
-        for (i = 0; i < am->in_channels; i++)                               \
-            matrix[o * stride + i] = am->matrix_ ## suffix[o][i] * (scale);
+    for (o = 0, o0 = 0; o < am->out_channels; o++) {                        \
+        for (i = 0, i0 = 0; i < am->in_channels; i++) {                     \
+            if (am->input_skip[i] || am->output_zero[o])                    \
+                matrix[o * stride + i] = 0.0;                               \
+            else                                                            \
+                matrix[o * stride + i] = am->matrix_ ## suffix[o0][i0] *    \
+                                         (scale);                           \
+            if (!am->input_skip[i])                                         \
+                i0++;                                                       \
+        }                                                                   \
+        if (!am->output_zero[o])                                            \
+            o0++;                                                           \
+    }
 
     switch (am->coeff_type) {
     case AV_MIX_COEFF_TYPE_Q8:
@@ -494,10 +527,132 @@ int ff_audio_mix_get_matrix(AudioMix *am, double *matrix, int stride)
     return 0;
 }
 
-int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
+static void reduce_matrix(AudioMix *am, const double *matrix, int stride)
 {
     int i, o;
 
+    memset(am->output_zero, 0, sizeof(am->output_zero));
+    memset(am->input_skip,  0, sizeof(am->input_skip));
+    memset(am->output_skip, 0, sizeof(am->output_skip));
+
+    /* exclude output channels if they can be zeroed instead of mixed */
+    for (o = 0; o < am->out_channels; o++) {
+        int zero = 1;
+
+        /* check if the output is always silent */
+        for (i = 0; i < am->in_channels; i++) {
+            if (matrix[o * stride + i] != 0.0) {
+                zero = 0;
+                break;
+            }
+        }
+        /* check if the corresponding input channel makes a contribution to
+           any output channel */
+        if (o < am->in_channels) {
+            for (i = 0; i < am->out_channels; i++) {
+                if (matrix[i * stride + o] != 0.0) {
+                    zero = 0;
+                    break;
+                }
+            }
+        }
+        if (zero) {
+            am->output_zero[o] = 1;
+            am->out_matrix_channels--;
+        }
+    }
+    if (am->out_matrix_channels == 0) {
+        am->in_matrix_channels = 0;
+        return;
+    }
+
+    /* skip input channels that contribute fully only to the corresponding
+       output channel */
+    for (i = 0; i < FFMIN(am->in_channels, am->out_channels); i++) {
+        int skip = 1;
+
+        for (o = 0; o < am->out_channels; o++) {
+            int i0;
+            if ((o != i && matrix[o * stride + i] != 0.0) ||
+                (o == i && matrix[o * stride + i] != 1.0)) {
+                skip = 0;
+                break;
+            }
+            /* if the input contributes fully to the output, also check that no
+               other inputs contribute to this output */
+            if (o == i) {
+                for (i0 = 0; i0 < am->in_channels; i0++) {
+                    if (i0 != i && matrix[o * stride + i0] != 0.0) {
+                        skip = 0;
+                        break;
+                    }
+                }
+            }
+        }
+        if (skip) {
+            am->input_skip[i] = 1;
+            am->in_matrix_channels--;
+        }
+    }
+    /* skip input channels that do not contribute to any output channel */
+    for (; i < am->in_channels; i++) {
+        int contrib = 0;
+
+        for (o = 0; o < am->out_channels; o++) {
+            if (matrix[o * stride + i] != 0.0) {
+                contrib = 1;
+                break;
+            }
+        }
+        if (!contrib) {
+            am->input_skip[i] = 1;
+            am->in_matrix_channels--;
+        }
+    }
+    if (am->in_matrix_channels == 0) {
+        am->out_matrix_channels = 0;
+        return;
+    }
+
+    /* skip output channels that only get full contribution from the
+       corresponding input channel */
+    for (o = 0; o < FFMIN(am->in_channels, am->out_channels); o++) {
+        int skip = 1;
+        int o0;
+
+        for (i = 0; i < am->in_channels; i++) {
+            if ((o != i && matrix[o * stride + i] != 0.0) ||
+                (o == i && matrix[o * stride + i] != 1.0)) {
+                skip = 0;
+                break;
+            }
+        }
+        /* check if the corresponding input channel makes a contribution to
+           any other output channel */
+        i = o;
+        for (o0 = 0; o0 < am->out_channels; o0++) {
+            if (o0 != i && matrix[o0 * stride + i] != 0.0) {
+                skip = 0;
+                break;
+            }
+        }
+        if (skip) {
+            am->output_skip[o] = 1;
+            am->out_matrix_channels--;
+        }
+    }
+    if (am->out_matrix_channels == 0) {
+        am->in_matrix_channels = 0;
+        return;
+    }
+}
+
+int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
+{
+    int i, o, i0, o0, ret;
+    char in_layout_name[128];
+    char out_layout_name[128];
+
     if ( am->in_channels <= 0 ||  am->in_channels > AVRESAMPLE_MAX_CHANNELS ||
         am->out_channels <= 0 || am->out_channels > AVRESAMPLE_MAX_CHANNELS) {
         av_log(am->avr, AV_LOG_ERROR, "Invalid channel counts\n");
@@ -509,36 +664,76 @@ int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
         am->matrix = NULL;
     }
 
+    am->in_matrix_channels  = am->in_channels;
+    am->out_matrix_channels = am->out_channels;
+
+    reduce_matrix(am, matrix, stride);
+
 #define CONVERT_MATRIX(type, expr)                                          \
-    am->matrix_## type[0] = av_mallocz(am->out_channels * am->in_channels * \
+    am->matrix_## type[0] = av_mallocz(am->out_matrix_channels *            \
+                                       am->in_matrix_channels  *            \
                                        sizeof(*am->matrix_## type[0]));     \
     if (!am->matrix_## type[0])                                             \
         return AVERROR(ENOMEM);                                             \
-    for (o = 0; o < am->out_channels; o++) {                                \
-        if (o > 0)                                                          \
-            am->matrix_## type[o] = am->matrix_## type[o - 1] +             \
-                                    am->in_channels;                        \
-        for (i = 0; i < am->in_channels; i++) {                             \
-            double v = matrix[o * stride + i];                              \
-            am->matrix_## type[o][i] = expr;                                \
+    for (o = 0, o0 = 0; o < am->out_channels; o++) {                        \
+        if (am->output_zero[o] || am->output_skip[o])                       \
+            continue;                                                       \
+        if (o0 > 0)                                                         \
+            am->matrix_## type[o0] = am->matrix_## type[o0 - 1] +           \
+                                     am->in_matrix_channels;                \
+        for (i = 0, i0 = 0; i < am->in_channels; i++) {                     \
+            double v;                                                       \
+            if (am->input_skip[i])                                          \
+                continue;                                                   \
+            v = matrix[o * stride + i];                                     \
+            am->matrix_## type[o0][i0] = expr;                              \
+            i0++;                                                           \
         }                                                                   \
+        o0++;                                                               \
     }                                                                       \
     am->matrix = (void **)am->matrix_## type;
 
-    switch (am->coeff_type) {
-    case AV_MIX_COEFF_TYPE_Q8:
-        CONVERT_MATRIX(q8, av_clip_int16(lrint(256.0 * v)))
-        break;
-    case AV_MIX_COEFF_TYPE_Q15:
-        CONVERT_MATRIX(q15, av_clipl_int32(llrint(32768.0 * v)))
-        break;
-    case AV_MIX_COEFF_TYPE_FLT:
-        CONVERT_MATRIX(flt, v)
-        break;
-    default:
-        av_log(am->avr, AV_LOG_ERROR, "Invalid mix coeff type\n");
-        return AVERROR(EINVAL);
+    if (am->in_matrix_channels && am->out_matrix_channels) {
+        switch (am->coeff_type) {
+        case AV_MIX_COEFF_TYPE_Q8:
+            CONVERT_MATRIX(q8, av_clip_int16(lrint(256.0 * v)))
+            break;
+        case AV_MIX_COEFF_TYPE_Q15:
+            CONVERT_MATRIX(q15, av_clipl_int32(llrint(32768.0 * v)))
+            break;
+        case AV_MIX_COEFF_TYPE_FLT:
+            CONVERT_MATRIX(flt, v)
+            break;
+        default:
+            av_log(am->avr, AV_LOG_ERROR, "Invalid mix coeff type\n");
+            return AVERROR(EINVAL);
+        }
     }
 
-    return mix_function_init(am);
+    ret = mix_function_init(am);
+    if (ret < 0)
+        return ret;
+
+    av_get_channel_layout_string(in_layout_name, sizeof(in_layout_name),
+                                 am->in_channels, am->in_layout);
+    av_get_channel_layout_string(out_layout_name, sizeof(out_layout_name),
+                                 am->out_channels, am->out_layout);
+    av_log(am->avr, AV_LOG_DEBUG, "audio_mix: %s to %s\n",
+           in_layout_name, out_layout_name);
+    av_log(am->avr, AV_LOG_DEBUG, "matrix size: %d x %d\n",
+           am->in_matrix_channels, am->out_matrix_channels);
+    for (o = 0; o < am->out_channels; o++) {
+        for (i = 0; i < am->in_channels; i++) {
+            if (am->output_zero[o])
+                av_log(am->avr, AV_LOG_DEBUG, "  (ZERO)");
+            else if (am->input_skip[i] || am->output_skip[o])
+                av_log(am->avr, AV_LOG_DEBUG, "  (SKIP)");
+            else
+                av_log(am->avr, AV_LOG_DEBUG, "  %0.3f ",
+                       matrix[o * am->in_channels + i]);
+        }
+        av_log(am->avr, AV_LOG_DEBUG, "\n");
+    }
+
+    return 0;
 }
diff --git a/mythtv/external/FFmpeg/libavresample/audio_mix.h b/mythtv/external/FFmpeg/libavresample/audio_mix.h
index 4ccfc1fd284..5bae5ab6daf 100644
--- a/mythtv/external/FFmpeg/libavresample/audio_mix.h
+++ b/mythtv/external/FFmpeg/libavresample/audio_mix.h
@@ -25,13 +25,12 @@
 
 #include "libavutil/samplefmt.h"
 #include "avresample.h"
+#include "internal.h"
 #include "audio_data.h"
 
 typedef void (mix_func)(uint8_t **src, void **matrix, int len, int out_ch,
                         int in_ch);
 
-typedef struct AudioMix AudioMix;
-
 /**
  * Set mixing function if the parameters match.
  *
diff --git a/mythtv/external/FFmpeg/libavresample/avresample.h b/mythtv/external/FFmpeg/libavresample/avresample.h
index 0012787404a..d26f2ca2234 100644
--- a/mythtv/external/FFmpeg/libavresample/avresample.h
+++ b/mythtv/external/FFmpeg/libavresample/avresample.h
@@ -258,6 +258,36 @@ int avresample_get_matrix(AVAudioResampleContext *avr, double *matrix,
 int avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix,
                           int stride);
 
+/**
+ * Set a customized input channel mapping.
+ *
+ * This function can only be called when the allocated context is not open.
+ * Also, the input channel layout must have already been set.
+ *
+ * Calling avresample_close() on the context will clear the channel mapping.
+ *
+ * The map for each input channel specifies the channel index in the source to
+ * use for that particular channel, or -1 to mute the channel. Source channels
+ * can be duplicated by using the same index for multiple input channels.
+ *
+ * Examples:
+ *
+ * Reordering 5.1 AAC order (C,L,R,Ls,Rs,LFE) to Libav order (L,R,C,LFE,Ls,Rs):
+ * { 1, 2, 0, 5, 3, 4 }
+ *
+ * Muting the 3rd channel in 4-channel input:
+ * { 0, 1, -1, 3 }
+ *
+ * Duplicating the left channel of stereo input:
+ * { 0, 0 }
+ *
+ * @param avr         audio resample context
+ * @param channel_map customized input channel mapping
+ * @return            0 on success, negative AVERROR code on failure
+ */
+int avresample_set_channel_mapping(AVAudioResampleContext *avr,
+                                   const int *channel_map);
+
 /**
  * Set compensation for resampling.
  *
diff --git a/mythtv/external/FFmpeg/libavresample/dither.c b/mythtv/external/FFmpeg/libavresample/dither.c
index 9c1e1c11011..f24bf5c7651 100644
--- a/mythtv/external/FFmpeg/libavresample/dither.c
+++ b/mythtv/external/FFmpeg/libavresample/dither.c
@@ -53,6 +53,8 @@ typedef struct DitherState {
 struct DitherContext {
     DitherDSPContext  ddsp;
     enum AVResampleDitherMethod method;
+    int apply_map;
+    ChannelMapInfo *ch_map_info;
 
     int mute_dither_threshold;  // threshold for disabling dither
     int mute_reset_threshold;   // threshold for resetting noise shaping
@@ -251,17 +253,23 @@ int ff_convert_dither(DitherContext *c, AudioData *dst, AudioData *src)
             return ret;
     }
 
-    if (src->sample_fmt != AV_SAMPLE_FMT_FLTP) {
+    if (src->sample_fmt != AV_SAMPLE_FMT_FLTP || c->apply_map) {
         /* make sure flt_data is large enough for the input */
         ret = ff_audio_data_realloc(c->flt_data, src->nb_samples);
         if (ret < 0)
             return ret;
         flt_data = c->flt_data;
+    }
 
+    if (src->sample_fmt != AV_SAMPLE_FMT_FLTP) {
         /* convert input samples to fltp and scale to s16 range */
         ret = ff_audio_convert(c->ac_in, flt_data, src);
         if (ret < 0)
             return ret;
+    } else if (c->apply_map) {
+        ret = ff_audio_data_copy(flt_data, src, c->ch_map_info);
+        if (ret < 0)
+            return ret;
     } else {
         flt_data = src;
     }
@@ -328,12 +336,15 @@ static void dither_init(DitherDSPContext *ddsp,
         ddsp->dither_int_to_float = dither_int_to_float_rectangular_c;
     else
         ddsp->dither_int_to_float = dither_int_to_float_triangular_c;
+
+    if (ARCH_X86)
+        ff_dither_init_x86(ddsp, method);
 }
 
 DitherContext *ff_dither_alloc(AVAudioResampleContext *avr,
                                enum AVSampleFormat out_fmt,
                                enum AVSampleFormat in_fmt,
-                               int channels, int sample_rate)
+                               int channels, int sample_rate, int apply_map)
 {
     AVLFG seed_gen;
     DitherContext *c;
@@ -350,6 +361,10 @@ DitherContext *ff_dither_alloc(AVAudioResampleContext *avr,
     if (!c)
         return NULL;
 
+    c->apply_map = apply_map;
+    if (apply_map)
+        c->ch_map_info = &avr->ch_map_info;
+
     if (avr->dither_method == AV_RESAMPLE_DITHER_TRIANGULAR_NS &&
         sample_rate != 48000 && sample_rate != 44100) {
         av_log(avr, AV_LOG_WARNING, "sample rate must be 48000 or 44100 Hz "
@@ -379,19 +394,20 @@ DitherContext *ff_dither_alloc(AVAudioResampleContext *avr,
             goto fail;
 
         c->ac_out = ff_audio_convert_alloc(avr, out_fmt, AV_SAMPLE_FMT_S16P,
-                                           channels, sample_rate);
+                                           channels, sample_rate, 0);
         if (!c->ac_out)
             goto fail;
     }
 
-    if (in_fmt != AV_SAMPLE_FMT_FLTP) {
+    if (in_fmt != AV_SAMPLE_FMT_FLTP || c->apply_map) {
         c->flt_data = ff_audio_data_alloc(channels, 1024, AV_SAMPLE_FMT_FLTP,
                                           "dither flt buffer");
         if (!c->flt_data)
             goto fail;
-
+    }
+    if (in_fmt != AV_SAMPLE_FMT_FLTP) {
         c->ac_in = ff_audio_convert_alloc(avr, AV_SAMPLE_FMT_FLTP, in_fmt,
-                                          channels, sample_rate);
+                                          channels, sample_rate, c->apply_map);
         if (!c->ac_in)
             goto fail;
     }
diff --git a/mythtv/external/FFmpeg/libavresample/dither.h b/mythtv/external/FFmpeg/libavresample/dither.h
index 8b30dd23e0b..8db37146fa3 100644
--- a/mythtv/external/FFmpeg/libavresample/dither.h
+++ b/mythtv/external/FFmpeg/libavresample/dither.h
@@ -66,7 +66,7 @@ typedef struct DitherDSPContext {
 DitherContext *ff_dither_alloc(AVAudioResampleContext *avr,
                                enum AVSampleFormat out_fmt,
                                enum AVSampleFormat in_fmt,
-                               int channels, int sample_rate);
+                               int channels, int sample_rate, int apply_map);
 
 /**
  * Free a DitherContext.
@@ -85,4 +85,9 @@ void ff_dither_free(DitherContext **c);
  */
 int ff_convert_dither(DitherContext *c, AudioData *dst, AudioData *src);
 
+/* arch-specific initialization functions */
+
+void ff_dither_init_x86(DitherDSPContext *ddsp,
+                        enum AVResampleDitherMethod method);
+
 #endif /* AVRESAMPLE_DITHER_H */
diff --git a/mythtv/external/FFmpeg/libavresample/internal.h b/mythtv/external/FFmpeg/libavresample/internal.h
index 2e139abf2b1..057f89a49c8 100644
--- a/mythtv/external/FFmpeg/libavresample/internal.h
+++ b/mythtv/external/FFmpeg/libavresample/internal.h
@@ -26,10 +26,29 @@
 #include "libavutil/opt.h"
 #include "libavutil/samplefmt.h"
 #include "avresample.h"
-#include "audio_convert.h"
-#include "audio_data.h"
-#include "audio_mix.h"
-#include "resample.h"
+
+typedef struct AudioData AudioData;
+typedef struct AudioConvert AudioConvert;
+typedef struct AudioMix AudioMix;
+typedef struct ResampleContext ResampleContext;
+
+enum RemapPoint {
+    REMAP_NONE,
+    REMAP_IN_COPY,
+    REMAP_IN_CONVERT,
+    REMAP_OUT_COPY,
+    REMAP_OUT_CONVERT,
+};
+
+typedef struct ChannelMapInfo {
+    int channel_map[AVRESAMPLE_MAX_CHANNELS];   /**< source index of each output channel, -1 if not remapped */
+    int do_remap;                               /**< remap needed */
+    int channel_copy[AVRESAMPLE_MAX_CHANNELS];  /**< dest index to copy from */
+    int do_copy;                                /**< copy needed */
+    int channel_zero[AVRESAMPLE_MAX_CHANNELS];  /**< dest index to zero */
+    int do_zero;                                /**< zeroing needed */
+    int input_map[AVRESAMPLE_MAX_CHANNELS];     /**< dest index of each input channel */
+} ChannelMapInfo;
 
 struct AVAudioResampleContext {
     const AVClass *av_class;        /**< AVClass for logging and AVOptions  */
@@ -64,6 +83,7 @@ struct AVAudioResampleContext {
     int resample_needed;    /**< resampling is needed                       */
     int in_convert_needed;  /**< input sample format conversion is needed   */
     int out_convert_needed; /**< output sample format conversion is needed  */
+    int in_copy_needed;     /**< input data copy is needed                  */
 
     AudioData *in_buffer;           /**< buffer for converted input         */
     AudioData *resample_out_buffer; /**< buffer for output from resampler   */
@@ -81,6 +101,10 @@ struct AVAudioResampleContext {
      * only used if avresample_set_matrix() is called before avresample_open()
      */
     double *mix_matrix;
+
+    int use_channel_map;
+    enum RemapPoint remap_point;
+    ChannelMapInfo ch_map_info;
 };
 
 #endif /* AVRESAMPLE_INTERNAL_H */
diff --git a/mythtv/external/FFmpeg/libavresample/options.c b/mythtv/external/FFmpeg/libavresample/options.c
index 68548f04946..39c415b8b88 100644
--- a/mythtv/external/FFmpeg/libavresample/options.c
+++ b/mythtv/external/FFmpeg/libavresample/options.c
@@ -40,7 +40,17 @@ static const AVOption options[] = {
     { "out_channel_layout",     "Output Channel Layout",    OFFSET(out_channel_layout),     AV_OPT_TYPE_INT64,  { .i64 = 0              }, INT64_MIN,            INT64_MAX,              PARAM },
     { "out_sample_fmt",         "Output Sample Format",     OFFSET(out_sample_fmt),         AV_OPT_TYPE_INT,    { .i64 = AV_SAMPLE_FMT_S16 }, AV_SAMPLE_FMT_U8,     AV_SAMPLE_FMT_NB-1,     PARAM },
     { "out_sample_rate",        "Output Sample Rate",       OFFSET(out_sample_rate),        AV_OPT_TYPE_INT,    { .i64 = 48000          }, 1,                    INT_MAX,                PARAM },
-    { "internal_sample_fmt",    "Internal Sample Format",   OFFSET(internal_sample_fmt),    AV_OPT_TYPE_INT,    { .i64 = AV_SAMPLE_FMT_NONE }, AV_SAMPLE_FMT_NONE,   AV_SAMPLE_FMT_NB-1,     PARAM },
+    { "internal_sample_fmt",    "Internal Sample Format",   OFFSET(internal_sample_fmt),    AV_OPT_TYPE_INT,    { .i64 = AV_SAMPLE_FMT_NONE }, AV_SAMPLE_FMT_NONE,   AV_SAMPLE_FMT_NB-1,     PARAM, "internal_sample_fmt" },
+        {"u8" ,  "8-bit unsigned integer",        0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_U8   }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
+        {"s16",  "16-bit signed integer",         0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_S16  }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
+        {"s32",  "32-bit signed integer",         0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_S32  }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
+        {"flt",  "32-bit float",                  0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_FLT  }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
+        {"dbl",  "64-bit double",                 0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_DBL  }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
+        {"u8p" , "8-bit unsigned integer planar", 0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_U8P  }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
+        {"s16p", "16-bit signed integer planar",  0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_S16P }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
+        {"s32p", "32-bit signed integer planar",  0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_S32P }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
+        {"fltp", "32-bit float planar",           0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_FLTP }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
+        {"dblp", "64-bit double planar",          0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_DBLP }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
     { "mix_coeff_type",         "Mixing Coefficient Type",  OFFSET(mix_coeff_type),         AV_OPT_TYPE_INT,    { .i64 = AV_MIX_COEFF_TYPE_FLT }, AV_MIX_COEFF_TYPE_Q8, AV_MIX_COEFF_TYPE_NB-1, PARAM, "mix_coeff_type" },
         { "q8",  "16-bit 8.8 Fixed-Point",   0, AV_OPT_TYPE_CONST, { .i64 = AV_MIX_COEFF_TYPE_Q8  }, INT_MIN, INT_MAX, PARAM, "mix_coeff_type" },
         { "q15", "32-bit 17.15 Fixed-Point", 0, AV_OPT_TYPE_CONST, { .i64 = AV_MIX_COEFF_TYPE_Q15 }, INT_MIN, INT_MAX, PARAM, "mix_coeff_type" },
@@ -54,6 +64,8 @@ static const AVOption options[] = {
     { "phase_shift",            "Resampling Phase Shift",   OFFSET(phase_shift),            AV_OPT_TYPE_INT,    { .i64 = 10             }, 0,                    30, /* ??? */           PARAM },
     { "linear_interp",          "Use Linear Interpolation", OFFSET(linear_interp),          AV_OPT_TYPE_INT,    { .i64 = 0              }, 0,                    1,                      PARAM },
     { "cutoff",                 "Cutoff Frequency Ratio",   OFFSET(cutoff),                 AV_OPT_TYPE_DOUBLE, { .dbl = 0.8            }, 0.0,                  1.0,                    PARAM },
+    /* duplicate option in order to work with avconv */
+    { "resample_cutoff",        "Cutoff Frequency Ratio",   OFFSET(cutoff),                 AV_OPT_TYPE_DOUBLE, { .dbl = 0.8            }, 0.0,                  1.0,                    PARAM },
     { "matrix_encoding",        "Matrixed Stereo Encoding", OFFSET(matrix_encoding),        AV_OPT_TYPE_INT,    {.i64 =  AV_MATRIX_ENCODING_NONE}, AV_MATRIX_ENCODING_NONE,     AV_MATRIX_ENCODING_NB-1, PARAM, "matrix_encoding" },
         { "none",  "None",               0, AV_OPT_TYPE_CONST, { .i64 = AV_MATRIX_ENCODING_NONE  }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
         { "dolby", "Dolby",              0, AV_OPT_TYPE_CONST, { .i64 = AV_MATRIX_ENCODING_DOLBY }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
diff --git a/mythtv/external/FFmpeg/libavresample/resample.c b/mythtv/external/FFmpeg/libavresample/resample.c
index dc121fe56d4..69c9bab8932 100644
--- a/mythtv/external/FFmpeg/libavresample/resample.c
+++ b/mythtv/external/FFmpeg/libavresample/resample.c
@@ -23,6 +23,7 @@
 #include "libavutil/libm.h"
 #include "libavutil/log.h"
 #include "internal.h"
+#include "resample.h"
 #include "audio_data.h"
 
 struct ResampleContext {
diff --git a/mythtv/external/FFmpeg/libavresample/resample.h b/mythtv/external/FFmpeg/libavresample/resample.h
index 7534e26ad4e..4544dab92f1 100644
--- a/mythtv/external/FFmpeg/libavresample/resample.h
+++ b/mythtv/external/FFmpeg/libavresample/resample.h
@@ -22,10 +22,9 @@
 #define AVRESAMPLE_RESAMPLE_H
 
 #include "avresample.h"
+#include "internal.h"
 #include "audio_data.h"
 
-typedef struct ResampleContext ResampleContext;
-
 /**
  * Allocate and initialize a ResampleContext.
  *
diff --git a/mythtv/external/FFmpeg/libavresample/utils.c b/mythtv/external/FFmpeg/libavresample/utils.c
index 8f6583d6e8e..c159e332065 100644
--- a/mythtv/external/FFmpeg/libavresample/utils.c
+++ b/mythtv/external/FFmpeg/libavresample/utils.c
@@ -26,8 +26,11 @@
 #include "libavutil/opt.h"
 
 #include "avresample.h"
-#include "audio_data.h"
 #include "internal.h"
+#include "audio_data.h"
+#include "audio_convert.h"
+#include "audio_mix.h"
+#include "resample.h"
 
 int avresample_open(AVAudioResampleContext *avr)
 {
@@ -93,20 +96,84 @@ int avresample_open(AVAudioResampleContext *avr)
                av_get_sample_fmt_name(avr->internal_sample_fmt));
     }
 
-    /* set sample format conversion parameters */
+    /* treat all mono as planar for easier comparison */
     if (avr->in_channels == 1)
         avr->in_sample_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt);
     if (avr->out_channels == 1)
         avr->out_sample_fmt = av_get_planar_sample_fmt(avr->out_sample_fmt);
-    avr->in_convert_needed = (avr->resample_needed || avr->mixing_needed) &&
-                              avr->in_sample_fmt != avr->internal_sample_fmt;
+
+    /* we may need to add an extra conversion in order to remap channels if
+       the output format is not planar */
+    if (avr->use_channel_map && !avr->mixing_needed && !avr->resample_needed &&
+        !av_sample_fmt_is_planar(avr->out_sample_fmt)) {
+        avr->internal_sample_fmt = av_get_planar_sample_fmt(avr->out_sample_fmt);
+    }
+
+    /* set sample format conversion parameters */
     if (avr->resample_needed || avr->mixing_needed)
+        avr->in_convert_needed = avr->in_sample_fmt != avr->internal_sample_fmt;
+    else
+        avr->in_convert_needed = avr->use_channel_map &&
+                                 !av_sample_fmt_is_planar(avr->out_sample_fmt);
+
+    if (avr->resample_needed || avr->mixing_needed || avr->in_convert_needed)
         avr->out_convert_needed = avr->internal_sample_fmt != avr->out_sample_fmt;
     else
         avr->out_convert_needed = avr->in_sample_fmt != avr->out_sample_fmt;
 
+    avr->in_copy_needed = !avr->in_convert_needed && (avr->mixing_needed ||
+                          (avr->use_channel_map && avr->resample_needed));
+
+    if (avr->use_channel_map) {
+        if (avr->in_copy_needed) {
+            avr->remap_point = REMAP_IN_COPY;
+            av_dlog(avr, "remap channels during in_copy\n");
+        } else if (avr->in_convert_needed) {
+            avr->remap_point = REMAP_IN_CONVERT;
+            av_dlog(avr, "remap channels during in_convert\n");
+        } else if (avr->out_convert_needed) {
+            avr->remap_point = REMAP_OUT_CONVERT;
+            av_dlog(avr, "remap channels during out_convert\n");
+        } else {
+            avr->remap_point = REMAP_OUT_COPY;
+            av_dlog(avr, "remap channels during out_copy\n");
+        }
+
+#ifdef DEBUG
+        {
+            int ch;
+            av_dlog(avr, "output map: ");
+            if (avr->ch_map_info.do_remap)
+                for (ch = 0; ch < avr->in_channels; ch++)
+                    av_dlog(avr, " % 2d", avr->ch_map_info.channel_map[ch]);
+            else
+                av_dlog(avr, "n/a");
+            av_dlog(avr, "\n");
+            av_dlog(avr, "copy map:   ");
+            if (avr->ch_map_info.do_copy)
+                for (ch = 0; ch < avr->in_channels; ch++)
+                    av_dlog(avr, " % 2d", avr->ch_map_info.channel_copy[ch]);
+            else
+                av_dlog(avr, "n/a");
+            av_dlog(avr, "\n");
+            av_dlog(avr, "zero map:   ");
+            if (avr->ch_map_info.do_zero)
+                for (ch = 0; ch < avr->in_channels; ch++)
+                    av_dlog(avr, " % 2d", avr->ch_map_info.channel_zero[ch]);
+            else
+                av_dlog(avr, "n/a");
+            av_dlog(avr, "\n");
+            av_dlog(avr, "input map:  ");
+            for (ch = 0; ch < avr->in_channels; ch++)
+                av_dlog(avr, " % 2d", avr->ch_map_info.input_map[ch]);
+            av_dlog(avr, "\n");
+        }
+#endif
+    } else
+        avr->remap_point = REMAP_NONE;
+
     /* allocate buffers */
-    if (avr->mixing_needed || avr->in_convert_needed) {
+    if (avr->in_copy_needed || avr->in_convert_needed) {
         avr->in_buffer = ff_audio_data_alloc(FFMAX(avr->in_channels, avr->out_channels),
                                              0, avr->internal_sample_fmt,
                                              "in_buffer");
@@ -143,7 +210,8 @@ int avresample_open(AVAudioResampleContext *avr)
     if (avr->in_convert_needed) {
         avr->ac_in = ff_audio_convert_alloc(avr, avr->internal_sample_fmt,
                                             avr->in_sample_fmt, avr->in_channels,
-                                            avr->in_sample_rate);
+                                            avr->in_sample_rate,
+                                            avr->remap_point == REMAP_IN_CONVERT);
         if (!avr->ac_in) {
             ret = AVERROR(ENOMEM);
             goto error;
@@ -157,7 +225,8 @@ int avresample_open(AVAudioResampleContext *avr)
             src_fmt = avr->in_sample_fmt;
         avr->ac_out = ff_audio_convert_alloc(avr, avr->out_sample_fmt, src_fmt,
                                              avr->out_channels,
-                                             avr->out_sample_rate);
+                                             avr->out_sample_rate,
+                                             avr->remap_point == REMAP_OUT_CONVERT);
         if (!avr->ac_out) {
             ret = AVERROR(ENOMEM);
             goto error;
@@ -197,6 +266,8 @@ void avresample_close(AVAudioResampleContext *avr)
     ff_audio_resample_free(&avr->resample);
     ff_audio_mix_free(&avr->am);
     av_freep(&avr->mix_matrix);
+
+    avr->use_channel_map = 0;
 }
 
 void avresample_free(AVAudioResampleContext **avr)
@@ -239,7 +310,9 @@ static int handle_buffered_output(AVAudioResampleContext *avr,
            data in the output FIFO */
         av_dlog(avr, "[copy] %s to output\n", converted->name);
         output->nb_samples = 0;
-        ret = ff_audio_data_copy(output, converted);
+        ret = ff_audio_data_copy(output, converted,
+                                 avr->remap_point == REMAP_OUT_COPY ?
+                                 &avr->ch_map_info : NULL);
         if (ret < 0)
             return ret;
         av_dlog(avr, "[end conversion]\n");
@@ -303,11 +376,24 @@ int attribute_align_arg avresample_convert(AVAudioResampleContext *avr,
             /* in some rare cases we can copy input to output and upmix
                directly in the output buffer */
             av_dlog(avr, "[copy] %s to output\n", current_buffer->name);
-            ret = ff_audio_data_copy(&output_buffer, current_buffer);
+            ret = ff_audio_data_copy(&output_buffer, current_buffer,
+                                     avr->remap_point == REMAP_OUT_COPY ?
+                                     &avr->ch_map_info : NULL);
             if (ret < 0)
                 return ret;
             current_buffer = &output_buffer;
-        } else if (avr->mixing_needed || avr->in_convert_needed) {
+        } else if (avr->remap_point == REMAP_OUT_COPY &&
+                   (!direct_output || out_samples < in_samples)) {
+            /* if remapping channels during output copy, we may need to
+             * use an intermediate buffer in order to remap before adding
+             * samples to the output fifo */
+            av_dlog(avr, "[copy] %s to out_buffer\n", current_buffer->name);
+            ret = ff_audio_data_copy(avr->out_buffer, current_buffer,
+                                     &avr->ch_map_info);
+            if (ret < 0)
+                return ret;
+            current_buffer = avr->out_buffer;
+        } else if (avr->in_copy_needed || avr->in_convert_needed) {
             /* if needed, copy or convert input to in_buffer, and downmix if
                applicable */
             if (avr->in_convert_needed) {
@@ -322,7 +408,9 @@ int attribute_align_arg avresample_convert(AVAudioResampleContext *avr,
                     return ret;
             } else {
                 av_dlog(avr, "[copy] %s to in_buffer\n", current_buffer->name);
-                ret = ff_audio_data_copy(avr->in_buffer, current_buffer);
+                ret = ff_audio_data_copy(avr->in_buffer, current_buffer,
+                                         avr->remap_point == REMAP_IN_COPY ?
+                                         &avr->ch_map_info : NULL);
                 if (ret < 0)
                     return ret;
             }
@@ -467,6 +555,57 @@ int avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix,
     return 0;
 }
 
+int avresample_set_channel_mapping(AVAudioResampleContext *avr,
+                                   const int *channel_map)
+{
+    ChannelMapInfo *info = &avr->ch_map_info;
+    int in_channels, ch, i;
+
+    in_channels = av_get_channel_layout_nb_channels(avr->in_channel_layout);
+    if (in_channels <= 0 ||  in_channels > AVRESAMPLE_MAX_CHANNELS) {
+        av_log(avr, AV_LOG_ERROR, "Invalid input channel layout\n");
+        return AVERROR(EINVAL);
+    }
+
+    memset(info, 0, sizeof(*info));
+    memset(info->input_map, -1, sizeof(info->input_map));
+
+    for (ch = 0; ch < in_channels; ch++) {
+        if (channel_map[ch] >= in_channels) {
+            av_log(avr, AV_LOG_ERROR, "Invalid channel map\n");
+            return AVERROR(EINVAL);
+        }
+        if (channel_map[ch] < 0) {
+            info->channel_zero[ch] =  1;
+            info->channel_map[ch]  = -1;
+            info->do_zero          =  1;
+        } else if (info->input_map[channel_map[ch]] >= 0) {
+            info->channel_copy[ch] = info->input_map[channel_map[ch]];
+            info->channel_map[ch]  = -1;
+            info->do_copy          =  1;
+        } else {
+            info->channel_map[ch]            = channel_map[ch];
+            info->input_map[channel_map[ch]] = ch;
+            info->do_remap                   =  1;
+        }
+    }
+    /* Fill-in unmapped input channels with unmapped output channels.
+       This is used when remapping during conversion from interleaved to
+       planar format. */
+    for (ch = 0, i = 0; ch < in_channels && i < in_channels; ch++, i++) {
+        while (ch < in_channels && info->input_map[ch] >= 0)
+            ch++;
+        while (i < in_channels && info->channel_map[i] >= 0)
+            i++;
+        if (ch >= in_channels || i >= in_channels)
+            break;
+        info->input_map[ch] = i;
+    }
+
+    avr->use_channel_map = 1;
+    return 0;
+}
+
 int avresample_available(AVAudioResampleContext *avr)
 {
     return av_audio_fifo_size(avr->out_fifo);
diff --git a/mythtv/external/FFmpeg/libavresample/version.h b/mythtv/external/FFmpeg/libavresample/version.h
index ebcd07f57cc..387d097d3a4 100644
--- a/mythtv/external/FFmpeg/libavresample/version.h
+++ b/mythtv/external/FFmpeg/libavresample/version.h
@@ -20,8 +20,8 @@
 #define AVRESAMPLE_VERSION_H
 
 #define LIBAVRESAMPLE_VERSION_MAJOR  1
-#define LIBAVRESAMPLE_VERSION_MINOR  0
-#define LIBAVRESAMPLE_VERSION_MICRO  1
+#define LIBAVRESAMPLE_VERSION_MINOR  1
+#define LIBAVRESAMPLE_VERSION_MICRO  0
 
 #define LIBAVRESAMPLE_VERSION_INT  AV_VERSION_INT(LIBAVRESAMPLE_VERSION_MAJOR, \
                                                   LIBAVRESAMPLE_VERSION_MINOR, \
diff --git a/mythtv/external/FFmpeg/libavresample/x86/Makefile b/mythtv/external/FFmpeg/libavresample/x86/Makefile
index 65bed899ba1..2e8786fb907 100644
--- a/mythtv/external/FFmpeg/libavresample/x86/Makefile
+++ b/mythtv/external/FFmpeg/libavresample/x86/Makefile
@@ -1,5 +1,7 @@
 OBJS      += x86/audio_convert_init.o                                   \
              x86/audio_mix_init.o                                       \
+             x86/dither_init.o                                          \
 
 YASM-OBJS += x86/audio_convert.o                                        \
              x86/audio_mix.o                                            \
+             x86/dither.o                                               \
diff --git a/mythtv/external/FFmpeg/libavresample/x86/dither.asm b/mythtv/external/FFmpeg/libavresample/x86/dither.asm
new file mode 100644
index 00000000000..757f2800bce
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavresample/x86/dither.asm
@@ -0,0 +1,117 @@
+;******************************************************************************
+;* x86 optimized dithering format conversion
+;* Copyright (c) 2012 Justin Ruggles 
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg is free software; you can redistribute it and/or
+;* modify it under the terms of the GNU Lesser General Public
+;* License as published by the Free Software Foundation; either
+;* version 2.1 of the License, or (at your option) any later version.
+;*
+;* FFmpeg is distributed in the hope that it will be useful,
+;* but WITHOUT ANY WARRANTY; without even the implied warranty of
+;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;* Lesser General Public License for more details.
+;*
+;* You should have received a copy of the GNU Lesser General Public
+;* License along with FFmpeg; if not, write to the Free Software
+;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;******************************************************************************
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA 32
+
+; 1.0f / (2.0f * INT32_MAX)
+pf_dither_scale: times 8 dd 2.32830643762e-10
+
+pf_s16_scale: times 4 dd 32753.0
+
+SECTION_TEXT
+
+;------------------------------------------------------------------------------
+; void ff_quantize(int16_t *dst, float *src, float *dither, int len);
+;------------------------------------------------------------------------------
+
+INIT_XMM sse2
+cglobal quantize, 4,4,3, dst, src, dither, len
+    lea         lenq, [2*lend]
+    add         dstq, lenq
+    lea         srcq, [srcq+2*lenq]
+    lea      ditherq, [ditherq+2*lenq]
+    neg         lenq
+    mova          m2, [pf_s16_scale]
+.loop:
+    mulps         m0, m2, [srcq+2*lenq]
+    mulps         m1, m2, [srcq+2*lenq+mmsize]
+    addps         m0, [ditherq+2*lenq]
+    addps         m1, [ditherq+2*lenq+mmsize]
+    cvtps2dq      m0, m0
+    cvtps2dq      m1, m1
+    packssdw      m0, m1
+    mova     [dstq+lenq], m0
+    add         lenq, mmsize
+    jl .loop
+    REP_RET
+
+;------------------------------------------------------------------------------
+; void ff_dither_int_to_float_rectangular(float *dst, int *src, int len)
+;------------------------------------------------------------------------------
+
+%macro DITHER_INT_TO_FLOAT_RECTANGULAR 0
+cglobal dither_int_to_float_rectangular, 3,3,3, dst, src, len
+    lea         lenq, [4*lend]
+    add         srcq, lenq
+    add         dstq, lenq
+    neg         lenq
+    mova          m0, [pf_dither_scale]
+.loop:
+    cvtdq2ps      m1, [srcq+lenq]
+    cvtdq2ps      m2, [srcq+lenq+mmsize]
+    mulps         m1, m1, m0
+    mulps         m2, m2, m0
+    mova  [dstq+lenq], m1
+    mova  [dstq+lenq+mmsize], m2
+    add         lenq, 2*mmsize
+    jl .loop
+    REP_RET
+%endmacro
+
+INIT_XMM sse2
+DITHER_INT_TO_FLOAT_RECTANGULAR
+INIT_YMM avx
+DITHER_INT_TO_FLOAT_RECTANGULAR
+
+;------------------------------------------------------------------------------
+; void ff_dither_int_to_float_triangular(float *dst, int *src0, int len)
+;------------------------------------------------------------------------------
+
+%macro DITHER_INT_TO_FLOAT_TRIANGULAR 0
+cglobal dither_int_to_float_triangular, 3,4,5, dst, src0, len, src1
+    lea         lenq, [4*lend]
+    lea        src1q, [src0q+2*lenq]
+    add        src0q, lenq
+    add         dstq, lenq
+    neg         lenq
+    mova          m0, [pf_dither_scale]
+.loop:
+    cvtdq2ps      m1, [src0q+lenq]
+    cvtdq2ps      m2, [src0q+lenq+mmsize]
+    cvtdq2ps      m3, [src1q+lenq]
+    cvtdq2ps      m4, [src1q+lenq+mmsize]
+    addps         m1, m1, m3
+    addps         m2, m2, m4
+    mulps         m1, m1, m0
+    mulps         m2, m2, m0
+    mova  [dstq+lenq], m1
+    mova  [dstq+lenq+mmsize], m2
+    add         lenq, 2*mmsize
+    jl .loop
+    REP_RET
+%endmacro
+
+INIT_XMM sse2
+DITHER_INT_TO_FLOAT_TRIANGULAR
+INIT_YMM avx
+DITHER_INT_TO_FLOAT_TRIANGULAR
diff --git a/mythtv/external/FFmpeg/libavresample/x86/dither_init.c b/mythtv/external/FFmpeg/libavresample/x86/dither_init.c
new file mode 100644
index 00000000000..6532887c09a
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavresample/x86/dither_init.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012 Justin Ruggles 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "libavutil/cpu.h"
+#include "libavutil/x86/cpu.h"
+#include "libavresample/dither.h"
+
+extern void ff_quantize_sse2(int16_t *dst, const float *src, float *dither,
+                             int len);
+
+extern void ff_dither_int_to_float_rectangular_sse2(float *dst, int *src, int len);
+extern void ff_dither_int_to_float_rectangular_avx(float *dst, int *src, int len);
+
+extern void ff_dither_int_to_float_triangular_sse2(float *dst, int *src0, int len);
+extern void ff_dither_int_to_float_triangular_avx(float *dst, int *src0, int len);
+
+av_cold void ff_dither_init_x86(DitherDSPContext *ddsp,
+                                enum AVResampleDitherMethod method)
+{
+    int mm_flags = av_get_cpu_flags();
+
+    if (EXTERNAL_SSE2(mm_flags)) {
+        ddsp->quantize      = ff_quantize_sse2;
+        ddsp->ptr_align     = 16;
+        ddsp->samples_align = 8;
+    }
+
+    if (method == AV_RESAMPLE_DITHER_RECTANGULAR) {
+        if (EXTERNAL_SSE2(mm_flags)) {
+            ddsp->dither_int_to_float = ff_dither_int_to_float_rectangular_sse2;
+        }
+        if (EXTERNAL_AVX(mm_flags)) {
+            ddsp->dither_int_to_float = ff_dither_int_to_float_rectangular_avx;
+        }
+    } else {
+        if (EXTERNAL_SSE2(mm_flags)) {
+            ddsp->dither_int_to_float = ff_dither_int_to_float_triangular_sse2;
+        }
+        if (EXTERNAL_AVX(mm_flags)) {
+            ddsp->dither_int_to_float = ff_dither_int_to_float_triangular_avx;
+        }
+    }
+}
diff --git a/mythtv/external/FFmpeg/libavutil/Makefile b/mythtv/external/FFmpeg/libavutil/Makefile
index 61ddc9a3fcf..544c33f240e 100644
--- a/mythtv/external/FFmpeg/libavutil/Makefile
+++ b/mythtv/external/FFmpeg/libavutil/Makefile
@@ -22,6 +22,7 @@ HEADERS = adler32.h                                                     \
           eval.h                                                        \
           fifo.h                                                        \
           file.h                                                        \
+          hmac.h                                                        \
           imgutils.h                                                    \
           intfloat.h                                                    \
           intfloat_readwrite.h                                          \
@@ -72,6 +73,7 @@ OBJS = adler32.o                                                        \
        fifo.o                                                           \
        file.o                                                           \
        float_dsp.o                                                      \
+       hmac.o                                                           \
        imgutils.o                                                       \
        intfloat_readwrite.o                                             \
        intmath.o                                                        \
@@ -117,6 +119,7 @@ TESTPROGS = adler32                                                     \
             eval                                                        \
             file                                                        \
             fifo                                                        \
+            hmac                                                        \
             lfg                                                         \
             lls                                                         \
             md5                                                         \
diff --git a/mythtv/external/FFmpeg/libavutil/arm/float_dsp_init_neon.c b/mythtv/external/FFmpeg/libavutil/arm/float_dsp_init_neon.c
index 88eb4b3d2a8..a7245ad92b9 100644
--- a/mythtv/external/FFmpeg/libavutil/arm/float_dsp_init_neon.c
+++ b/mythtv/external/FFmpeg/libavutil/arm/float_dsp_init_neon.c
@@ -32,9 +32,27 @@ void ff_vector_fmac_scalar_neon(float *dst, const float *src, float mul,
 void ff_vector_fmul_scalar_neon(float *dst, const float *src, float mul,
                                 int len);
 
+void ff_vector_fmul_window_neon(float *dst, const float *src0,
+                                const float *src1, const float *win, int len);
+
+void ff_vector_fmul_add_neon(float *dst, const float *src0, const float *src1,
+                             const float *src2, int len);
+
+void ff_vector_fmul_reverse_neon(float *dst, const float *src0,
+                                 const float *src1, int len);
+
+void ff_butterflies_float_neon(float *v1, float *v2, int len);
+
+float ff_scalarproduct_float_neon(const float *v1, const float *v2, int len);
+
 void ff_float_dsp_init_neon(AVFloatDSPContext *fdsp)
 {
     fdsp->vector_fmul = ff_vector_fmul_neon;
     fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_neon;
     fdsp->vector_fmul_scalar = ff_vector_fmul_scalar_neon;
+    fdsp->vector_fmul_window = ff_vector_fmul_window_neon;
+    fdsp->vector_fmul_add    = ff_vector_fmul_add_neon;
+    fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_neon;
+    fdsp->butterflies_float = ff_butterflies_float_neon;
+    fdsp->scalarproduct_float = ff_scalarproduct_float_neon;
 }
diff --git a/mythtv/external/FFmpeg/libavutil/arm/float_dsp_init_vfp.c b/mythtv/external/FFmpeg/libavutil/arm/float_dsp_init_vfp.c
index 7abc3322cf4..f7e2f54601b 100644
--- a/mythtv/external/FFmpeg/libavutil/arm/float_dsp_init_vfp.c
+++ b/mythtv/external/FFmpeg/libavutil/arm/float_dsp_init_vfp.c
@@ -25,10 +25,14 @@
 void ff_vector_fmul_vfp(float *dst, const float *src0, const float *src1,
                         int len);
 
+void ff_vector_fmul_reverse_vfp(float *dst, const float *src0,
+                                const float *src1, int len);
+
 void ff_float_dsp_init_vfp(AVFloatDSPContext *fdsp)
 {
     int cpu_flags = av_get_cpu_flags();
 
     if (!have_vfpv3(cpu_flags))
         fdsp->vector_fmul = ff_vector_fmul_vfp;
+    fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_vfp;
 }
diff --git a/mythtv/external/FFmpeg/libavutil/arm/float_dsp_neon.S b/mythtv/external/FFmpeg/libavutil/arm/float_dsp_neon.S
index 6d7bd5236ec..559b5656280 100644
--- a/mythtv/external/FFmpeg/libavutil/arm/float_dsp_neon.S
+++ b/mythtv/external/FFmpeg/libavutil/arm/float_dsp_neon.S
@@ -146,3 +146,126 @@ NOVFP   vdup.32         q8,  r2
         bx              lr
         .unreq          len
 endfunc
+
+function ff_vector_fmul_window_neon, export=1
+        push            {r4,r5,lr}
+        ldr             lr,  [sp, #12]
+        sub             r2,  r2,  #8
+        sub             r5,  lr,  #2
+        add             r2,  r2,  r5, lsl #2
+        add             r4,  r3,  r5, lsl #3
+        add             ip,  r0,  r5, lsl #3
+        mov             r5,  #-16
+        vld1.32         {d0,d1},  [r1,:128]!
+        vld1.32         {d2,d3},  [r2,:128], r5
+        vld1.32         {d4,d5},  [r3,:128]!
+        vld1.32         {d6,d7},  [r4,:128], r5
+1:      subs            lr,  lr,  #4
+        vmul.f32        d22, d0,  d4
+        vrev64.32       q3,  q3
+        vmul.f32        d23, d1,  d5
+        vrev64.32       q1,  q1
+        vmul.f32        d20, d0,  d7
+        vmul.f32        d21, d1,  d6
+        beq             2f
+        vmla.f32        d22, d3,  d7
+        vld1.32         {d0,d1},  [r1,:128]!
+        vmla.f32        d23, d2,  d6
+        vld1.32         {d18,d19},[r2,:128], r5
+        vmls.f32        d20, d3,  d4
+        vld1.32         {d24,d25},[r3,:128]!
+        vmls.f32        d21, d2,  d5
+        vld1.32         {d6,d7},  [r4,:128], r5
+        vmov            q1,  q9
+        vrev64.32       q11, q11
+        vmov            q2,  q12
+        vswp            d22, d23
+        vst1.32         {d20,d21},[r0,:128]!
+        vst1.32         {d22,d23},[ip,:128], r5
+        b               1b
+2:      vmla.f32        d22, d3,  d7
+        vmla.f32        d23, d2,  d6
+        vmls.f32        d20, d3,  d4
+        vmls.f32        d21, d2,  d5
+        vrev64.32       q11, q11
+        vswp            d22, d23
+        vst1.32         {d20,d21},[r0,:128]!
+        vst1.32         {d22,d23},[ip,:128], r5
+        pop             {r4,r5,pc}
+endfunc
+
+function ff_vector_fmul_add_neon, export=1
+        ldr             r12, [sp]
+        vld1.32         {q0-q1},  [r1,:128]!
+        vld1.32         {q8-q9},  [r2,:128]!
+        vld1.32         {q2-q3},  [r3,:128]!
+        vmul.f32        q10, q0,  q8
+        vmul.f32        q11, q1,  q9
+1:      vadd.f32        q12, q2,  q10
+        vadd.f32        q13, q3,  q11
+        pld             [r1, #16]
+        pld             [r2, #16]
+        pld             [r3, #16]
+        subs            r12, r12, #8
+        beq             2f
+        vld1.32         {q0},     [r1,:128]!
+        vld1.32         {q8},     [r2,:128]!
+        vmul.f32        q10, q0,  q8
+        vld1.32         {q1},     [r1,:128]!
+        vld1.32         {q9},     [r2,:128]!
+        vmul.f32        q11, q1,  q9
+        vld1.32         {q2-q3},  [r3,:128]!
+        vst1.32         {q12-q13},[r0,:128]!
+        b               1b
+2:      vst1.32         {q12-q13},[r0,:128]!
+        bx              lr
+endfunc
+
+function ff_vector_fmul_reverse_neon, export=1
+        add             r2,  r2,  r3,  lsl #2
+        sub             r2,  r2,  #32
+        mov             r12, #-32
+        vld1.32         {q0-q1},  [r1,:128]!
+        vld1.32         {q2-q3},  [r2,:128], r12
+1:      pld             [r1, #32]
+        vrev64.32       q3,  q3
+        vmul.f32        d16, d0,  d7
+        vmul.f32        d17, d1,  d6
+        pld             [r2, #-32]
+        vrev64.32       q2,  q2
+        vmul.f32        d18, d2,  d5
+        vmul.f32        d19, d3,  d4
+        subs            r3,  r3,  #8
+        beq             2f
+        vld1.32         {q0-q1},  [r1,:128]!
+        vld1.32         {q2-q3},  [r2,:128], r12
+        vst1.32         {q8-q9},  [r0,:128]!
+        b               1b
+2:      vst1.32         {q8-q9},  [r0,:128]!
+        bx              lr
+endfunc
+
+function ff_butterflies_float_neon, export=1
+1:      vld1.32         {q0},[r0,:128]
+        vld1.32         {q1},[r1,:128]
+        vsub.f32        q2,  q0,  q1
+        vadd.f32        q1,  q0,  q1
+        vst1.32         {q2},[r1,:128]!
+        vst1.32         {q1},[r0,:128]!
+        subs            r2,  r2,  #4
+        bgt             1b
+        bx              lr
+endfunc
+
+function ff_scalarproduct_float_neon, export=1
+        vmov.f32        q2,  #0.0
+1:      vld1.32         {q0},[r0,:128]!
+        vld1.32         {q1},[r1,:128]!
+        vmla.f32        q2,  q0,  q1
+        subs            r2,  r2,  #4
+        bgt             1b
+        vadd.f32        d0,  d4,  d5
+        vpadd.f32       d0,  d0,  d0
+NOVFP   vmov.32         r0,  d0[0]
+        bx              lr
+endfunc
diff --git a/mythtv/external/FFmpeg/libavutil/arm/float_dsp_vfp.S b/mythtv/external/FFmpeg/libavutil/arm/float_dsp_vfp.S
index db63e5a6757..8695fbd981e 100644
--- a/mythtv/external/FFmpeg/libavutil/arm/float_dsp_vfp.S
+++ b/mythtv/external/FFmpeg/libavutil/arm/float_dsp_vfp.S
@@ -66,3 +66,72 @@ function ff_vector_fmul_vfp, export=1
         vpop            {d8-d15}
         bx              lr
 endfunc
+
+/**
+ * ARM VFP optimized implementation of 'vector_fmul_reverse_c' function.
+ * Assume that len is a positive number and is multiple of 8
+ */
+@ void ff_vector_fmul_reverse_vfp(float *dst, const float *src0,
+@                                 const float *src1, int len)
+function ff_vector_fmul_reverse_vfp, export=1
+        vpush           {d8-d15}
+        add             r2,  r2,  r3, lsl #2
+        vldmdb          r2!, {s0-s3}
+        vldmia          r1!, {s8-s11}
+        vldmdb          r2!, {s4-s7}
+        vldmia          r1!, {s12-s15}
+        vmul.f32        s8,  s3,  s8
+        vmul.f32        s9,  s2,  s9
+        vmul.f32        s10, s1,  s10
+        vmul.f32        s11, s0,  s11
+1:
+        subs            r3,  r3,  #16
+        it              ge
+        vldmdbge        r2!, {s16-s19}
+        vmul.f32        s12, s7,  s12
+        it              ge
+        vldmiage        r1!, {s24-s27}
+        vmul.f32        s13, s6,  s13
+        it              ge
+        vldmdbge        r2!, {s20-s23}
+        vmul.f32        s14, s5,  s14
+        it              ge
+        vldmiage        r1!, {s28-s31}
+        vmul.f32        s15, s4,  s15
+        it              ge
+        vmulge.f32      s24, s19, s24
+        it              gt
+        vldmdbgt        r2!, {s0-s3}
+        it              ge
+        vmulge.f32      s25, s18, s25
+        vstmia          r0!, {s8-s13}
+        it              ge
+        vmulge.f32      s26, s17, s26
+        it              gt
+        vldmiagt        r1!, {s8-s11}
+        itt             ge
+        vmulge.f32      s27, s16, s27
+        vmulge.f32      s28, s23, s28
+        it              gt
+        vldmdbgt        r2!, {s4-s7}
+        it              ge
+        vmulge.f32      s29, s22, s29
+        vstmia          r0!, {s14-s15}
+        ittt            ge
+        vmulge.f32      s30, s21, s30
+        vmulge.f32      s31, s20, s31
+        vmulge.f32      s8,  s3,  s8
+        it              gt
+        vldmiagt        r1!, {s12-s15}
+        itttt           ge
+        vmulge.f32      s9,  s2,  s9
+        vmulge.f32      s10, s1,  s10
+        vstmiage        r0!, {s24-s27}
+        vmulge.f32      s11, s0,  s11
+        it              ge
+        vstmiage        r0!, {s28-s31}
+        bgt             1b
+
+        vpop            {d8-d15}
+        bx              lr
+endfunc
diff --git a/mythtv/external/FFmpeg/libavutil/avstring.c b/mythtv/external/FFmpeg/libavutil/avstring.c
index 7072a55cf3b..45f8d781723 100644
--- a/mythtv/external/FFmpeg/libavutil/avstring.c
+++ b/mythtv/external/FFmpeg/libavutil/avstring.c
@@ -23,11 +23,12 @@
 #include 
 #include 
 #include 
-#include 
-#include "avstring.h"
+
 #include "config.h"
 #include "common.h"
 #include "mem.h"
+#include "avstring.h"
+#include "bprint.h"
 
 int av_strstart(const char *str, const char *pfx, const char **ptr)
 {
@@ -42,7 +43,7 @@ int av_strstart(const char *str, const char *pfx, const char **ptr)
 
 int av_stristart(const char *str, const char *pfx, const char **ptr)
 {
-    while (*pfx && toupper((unsigned)*pfx) == toupper((unsigned)*str)) {
+    while (*pfx && av_toupper((unsigned)*pfx) == av_toupper((unsigned)*str)) {
         pfx++;
         str++;
     }
@@ -56,11 +57,25 @@ char *av_stristr(const char *s1, const char *s2)
     if (!*s2)
         return (char*)(intptr_t)s1;
 
-    do {
+    do
         if (av_stristart(s1, s2, NULL))
             return (char*)(intptr_t)s1;
-    } while (*s1++);
+    while (*s1++);
+
+    return NULL;
+}
 
+char *av_strnstr(const char *haystack, const char *needle, size_t hay_length)
+{
+    size_t needle_len = strlen(needle);
+    if (!needle_len)
+        return (char*)haystack;
+    while (hay_length >= needle_len) {
+        hay_length--;
+        if (!memcmp(haystack, needle, needle_len))
+            return (char*)haystack;
+        haystack++;
+    }
     return NULL;
 }
 
@@ -122,8 +137,9 @@ char *av_asprintf(const char *fmt, ...)
 
 char *av_d2str(double d)
 {
-    char *str= av_malloc(16);
-    if(str) snprintf(str, 16, "%f", d);
+    char *str = av_malloc(16);
+    if (str)
+        snprintf(str, 16, "%f", d);
     return str;
 }
 
@@ -131,32 +147,33 @@ char *av_d2str(double d)
 
 char *av_get_token(const char **buf, const char *term)
 {
-    char *out = av_malloc(strlen(*buf) + 1);
-    char *ret= out, *end= out;
+    char *out     = av_malloc(strlen(*buf) + 1);
+    char *ret     = out, *end = out;
     const char *p = *buf;
-    if (!out) return NULL;
+    if (!out)
+        return NULL;
     p += strspn(p, WHITESPACES);
 
-    while(*p && !strspn(p, term)) {
+    while (*p && !strspn(p, term)) {
         char c = *p++;
-        if(c == '\\' && *p){
+        if (c == '\\' && *p) {
             *out++ = *p++;
-            end= out;
-        }else if(c == '\''){
-            while(*p && *p != '\'')
+            end    = out;
+        } else if (c == '\'') {
+            while (*p && *p != '\'')
                 *out++ = *p++;
-            if(*p){
+            if (*p) {
                 p++;
-                end= out;
+                end = out;
             }
-        }else{
+        } else {
             *out++ = c;
         }
     }
 
-    do{
+    do
         *out-- = 0;
-    }while(out >= end && strspn(out, WHITESPACES));
+    while (out >= end && strspn(out, WHITESPACES));
 
     *buf = p;
 
@@ -251,55 +268,66 @@ const char *av_dirname(char *path)
     return path;
 }
 
+int av_escape(char **dst, const char *src, const char *special_chars,
+              enum AVEscapeMode mode, int flags)
+{
+    AVBPrint dstbuf;
 
-#ifdef TEST
+    av_bprint_init(&dstbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
+    av_bprint_escape(&dstbuf, src, special_chars, mode, flags);
 
-#include "common.h"
+    if (!av_bprint_is_complete(&dstbuf)) {
+        av_bprint_finalize(&dstbuf, NULL);
+        return AVERROR(ENOMEM);
+    } else {
+        av_bprint_finalize(&dstbuf, dst);
+        return dstbuf.len;
+    }
+}
+
+#ifdef TEST
 
 int main(void)
 {
     int i;
+    const char *strings[] = {
+        "''",
+        "",
+        ":",
+        "\\",
+        "'",
+        "    ''    :",
+        "    ''  ''  :",
+        "foo   '' :",
+        "'foo'",
+        "foo     ",
+        "  '  foo  '  ",
+        "foo\\",
+        "foo':  blah:blah",
+        "foo\\:  blah:blah",
+        "foo\'",
+        "'foo :  '  :blahblah",
+        "\\ :blah",
+        "     foo",
+        "      foo       ",
+        "      foo     \\ ",
+        "foo ':blah",
+        " foo   bar    :   blahblah",
+        "\\f\\o\\o",
+        "'foo : \\ \\  '   : blahblah",
+        "'\\fo\\o:': blahblah",
+        "\\'fo\\o\\:':  foo  '  :blahblah"
+    };
 
     printf("Testing av_get_token()\n");
-    {
-        const char *strings[] = {
-            "''",
-            "",
-            ":",
-            "\\",
-            "'",
-            "    ''    :",
-            "    ''  ''  :",
-            "foo   '' :",
-            "'foo'",
-            "foo     ",
-            "  '  foo  '  ",
-            "foo\\",
-            "foo':  blah:blah",
-            "foo\\:  blah:blah",
-            "foo\'",
-            "'foo :  '  :blahblah",
-            "\\ :blah",
-            "     foo",
-            "      foo       ",
-            "      foo     \\ ",
-            "foo ':blah",
-            " foo   bar    :   blahblah",
-            "\\f\\o\\o",
-            "'foo : \\ \\  '   : blahblah",
-            "'\\fo\\o:': blahblah",
-            "\\'fo\\o\\:':  foo  '  :blahblah"
-        };
-
-        for (i=0; i < FF_ARRAY_ELEMS(strings); i++) {
-            const char *p = strings[i];
-            char *q;
-            printf("|%s|", p);
-            q = av_get_token(&p, ":");
-            printf(" -> |%s|", q);
-            printf(" + |%s|\n", p);
-            av_free(q);
-        }
+    for (i = 0; i < FF_ARRAY_ELEMS(strings); i++) {
+        const char *p = strings[i];
+        char *q;
+        printf("|%s|", p);
+        q = av_get_token(&p, ":");
+        printf(" -> |%s|", q);
+        printf(" + |%s|\n", p);
+        av_free(q);
     }
 
     return 0;
diff --git a/mythtv/external/FFmpeg/libavutil/avstring.h b/mythtv/external/FFmpeg/libavutil/avstring.h
index d7af9ec7c3d..5b078f15ae3 100644
--- a/mythtv/external/FFmpeg/libavutil/avstring.h
+++ b/mythtv/external/FFmpeg/libavutil/avstring.h
@@ -66,6 +66,21 @@ int av_stristart(const char *str, const char *pfx, const char **ptr);
  */
 char *av_stristr(const char *haystack, const char *needle);
 
+/**
+ * Locate the first occurrence of the string needle in the string haystack
+ * where not more than hay_length characters are searched. A zero-length
+ * string needle is considered to match at the start of haystack.
+ *
+ * This function is a length-limited version of the standard strstr().
+ *
+ * @param haystack   string to search in
+ * @param needle     string to search for
+ * @param hay_length length of string to search in
+ * @return           pointer to the located match within haystack
+ *                   or a null pointer if no match
+ */
+char *av_strnstr(const char *haystack, const char *needle, size_t hay_length);
+
 /**
  * Copy the string src to dst, but no more than size - 1 bytes, and
  * null-terminate dst.
@@ -170,6 +185,30 @@ char *av_get_token(const char **buf, const char *term);
  */
 char *av_strtok(char *s, const char *delim, char **saveptr);
 
+/**
+ * Locale-independent conversion of ASCII isdigit.
+ */
+static inline int av_isdigit(int c)
+{
+    return c >= '0' && c <= '9';
+}
+
+/**
+ * Locale-independent conversion of ASCII isgraph.
+ */
+static inline int av_isgraph(int c)
+{
+    return c > 32 && c < 127;
+}
+
+/**
+ * Locale-independent conversion of ASCII isspace.
+ */
+static inline int av_isspace(int c)
+{
+    return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v';
+}
+
 /**
  * Locale-independent conversion of ASCII characters to uppercase.
  */
@@ -190,6 +229,15 @@ static inline int av_tolower(int c)
     return c;
 }
 
+/**
+ * Locale-independent conversion of ASCII isxdigit.
+ */
+static inline int av_isxdigit(int c)
+{
+    c = av_tolower(c);
+    return av_isdigit(c) || (c >= 'a' && c <= 'z');
+}
+
 /**
  * Locale-independent case-insensitive compare.
  * @note This means only ASCII-range characters are case-insensitive
@@ -218,6 +266,48 @@ const char *av_basename(const char *path);
  */
 const char *av_dirname(char *path);
 
+enum AVEscapeMode {
+    AV_ESCAPE_MODE_AUTO,      ///< Use auto-selected escaping mode.
+    AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping.
+    AV_ESCAPE_MODE_QUOTE,     ///< Use single-quote escaping.
+};
+
+/**
+ * Consider spaces special and escape them even in the middle of the
+ * string.
+ *
+ * This is equivalent to adding the whitespace characters to the special
+ * characters lists, except it is guaranteed to use the exact same list
+ * of whitespace characters as the rest of libavutil.
+ */
+#define AV_ESCAPE_FLAG_WHITESPACE 0x01
+
+/**
+ * Escape only specified special characters.
+ * Without this flag, escape also any characters that may be considered
+ * special by av_get_token(), such as the single quote.
+ */
+#define AV_ESCAPE_FLAG_STRICT 0x02
+
+/**
+ * Escape string in src, and put the escaped string in an allocated
+ * string in *dst, which must be freed with av_free().
+ *
+ * @param dst           pointer where an allocated string is put
+ * @param src           string to escape, must be non-NULL
+ * @param special_chars string containing the special characters which
+ *                      need to be escaped, can be NULL
+ * @param mode          escape mode to employ, see AV_ESCAPE_MODE_* macros.
+ *                      Any unknown value for mode will be considered equivalent to
+ *                      AV_ESCAPE_MODE_BACKSLASH, but this behaviour can change without
+ *                      notice.
+ * @param flags         flags which control how to escape, see AV_ESCAPE_FLAG_ macros
+ * @return the length of the allocated string, or a negative error code in case of error
+ * @see av_bprint_escape()
+ */
+int av_escape(char **dst, const char *src, const char *special_chars,
+              enum AVEscapeMode mode, int flags);
+
 /**
  * @}
  */
diff --git a/mythtv/external/FFmpeg/libavutil/bprint.c b/mythtv/external/FFmpeg/libavutil/bprint.c
index 4684ab49790..fd7611aaed8 100644
--- a/mythtv/external/FFmpeg/libavutil/bprint.c
+++ b/mythtv/external/FFmpeg/libavutil/bprint.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include "avassert.h"
+#include "avstring.h"
 #include "bprint.h"
 #include "common.h"
 #include "error.h"
@@ -217,6 +218,50 @@ int av_bprint_finalize(AVBPrint *buf, char **ret_str)
     return ret;
 }
 
+#define WHITESPACES " \n\t"
+
+void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_chars,
+                      enum AVEscapeMode mode, int flags)
+{
+    const char *src0 = src;
+
+    if (mode == AV_ESCAPE_MODE_AUTO)
+        mode = AV_ESCAPE_MODE_BACKSLASH; /* TODO: implement a heuristic */
+
+    switch (mode) {
+    case AV_ESCAPE_MODE_QUOTE:
+        /* enclose the string between '' */
+        av_bprint_chars(dstbuf, '\'', 1);
+        for (; *src; src++) {
+            if (*src == '\'')
+                av_bprintf(dstbuf, "'\\''");
+            else
+                av_bprint_chars(dstbuf, *src, 1);
+        }
+        av_bprint_chars(dstbuf, '\'', 1);
+        break;
+
+    /* case AV_ESCAPE_MODE_BACKSLASH or unknown mode */
+    default:
+        /* \-escape characters */
+        for (; *src; src++) {
+            int is_first_last       = src == src0 || !*(src+1);
+            int is_ws               = !!strchr(WHITESPACES, *src);
+            int is_strictly_special = special_chars && strchr(special_chars, *src);
+            int is_special          =
+                is_strictly_special || strchr("'\\", *src) ||
+                (is_ws && (flags & AV_ESCAPE_FLAG_WHITESPACE));
+
+            if (is_strictly_special ||
+                (!(flags & AV_ESCAPE_FLAG_STRICT) &&
+                 (is_special || (is_ws && is_first_last))))
+                av_bprint_chars(dstbuf, '\\', 1);
+            av_bprint_chars(dstbuf, *src, 1);
+        }
+        break;
+    }
+}
+
 #ifdef TEST
 
 #undef printf
diff --git a/mythtv/external/FFmpeg/libavutil/bprint.h b/mythtv/external/FFmpeg/libavutil/bprint.h
index f3915fe7b1d..df78916f4ad 100644
--- a/mythtv/external/FFmpeg/libavutil/bprint.h
+++ b/mythtv/external/FFmpeg/libavutil/bprint.h
@@ -22,6 +22,7 @@
 #define AVUTIL_BPRINT_H
 
 #include "attributes.h"
+#include "avstring.h"
 
 /**
  * Define a structure with extra padding to a fixed size
@@ -180,4 +181,20 @@ static inline int av_bprint_is_complete(AVBPrint *buf)
  */
 int av_bprint_finalize(AVBPrint *buf, char **ret_str);
 
+/**
+ * Escape the content in src and append it to dstbuf.
+ *
+ * @param dstbuf        already inited destination bprint buffer
+ * @param src           string containing the text to escape
+ * @param special_chars string containing the special characters which
+ *                      need to be escaped, can be NULL
+ * @param mode          escape mode to employ, see AV_ESCAPE_MODE_* macros.
+ *                      Any unknown value for mode will be considered equivalent to
+ *                      AV_ESCAPE_MODE_BACKSLASH, but this behaviour can change without
+ *                      notice.
+ * @param flags         flags which control how to escape, see AV_ESCAPE_FLAG_* macros
+ */
+void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_chars,
+                      enum AVEscapeMode mode, int flags);
+
 #endif /* AVUTIL_BPRINT_H */
diff --git a/mythtv/external/FFmpeg/libavutil/channel_layout.c b/mythtv/external/FFmpeg/libavutil/channel_layout.c
index ef6bad788bf..e5827605ea9 100644
--- a/mythtv/external/FFmpeg/libavutil/channel_layout.c
+++ b/mythtv/external/FFmpeg/libavutil/channel_layout.c
@@ -97,7 +97,8 @@ static const struct {
     { "7.0",         7,  AV_CH_LAYOUT_7POINT0 },
     { "7.0(front)",  7,  AV_CH_LAYOUT_7POINT0_FRONT },
     { "7.1",         8,  AV_CH_LAYOUT_7POINT1 },
-    { "7.1(wide)",   8,  AV_CH_LAYOUT_7POINT1_WIDE },
+    { "7.1(wide)",   8,  AV_CH_LAYOUT_7POINT1_WIDE_BACK },
+    { "7.1(wide-side)",   8,  AV_CH_LAYOUT_7POINT1_WIDE },
     { "octagonal",   8,  AV_CH_LAYOUT_OCTAGONAL },
     { "downmix",     2,  AV_CH_LAYOUT_STEREO_DOWNMIX, },
 };
diff --git a/mythtv/external/FFmpeg/libavutil/common.h b/mythtv/external/FFmpeg/libavutil/common.h
index 778c757b69a..beaf9f76357 100644
--- a/mythtv/external/FFmpeg/libavutil/common.h
+++ b/mythtv/external/FFmpeg/libavutil/common.h
@@ -26,7 +26,6 @@
 #ifndef AVUTIL_COMMON_H
 #define AVUTIL_COMMON_H
 
-#include 
 #include 
 #include 
 #include 
diff --git a/mythtv/external/FFmpeg/libavutil/crc.c b/mythtv/external/FFmpeg/libavutil/crc.c
index aeb9e466abd..9ee5efe9db9 100644
--- a/mythtv/external/FFmpeg/libavutil/crc.c
+++ b/mythtv/external/FFmpeg/libavutil/crc.c
@@ -24,7 +24,192 @@
 #include "crc.h"
 
 #if CONFIG_HARDCODED_TABLES
-#include "crc_data.h"
+static const AVCRC av_crc_table[AV_CRC_MAX][257] = {
+    [AV_CRC_8_ATM] = {
+        0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31,
+        0x24, 0x23, 0x2A, 0x2D, 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
+        0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, 0xE0, 0xE7, 0xEE, 0xE9,
+        0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
+        0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1,
+        0xB4, 0xB3, 0xBA, 0xBD, 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
+        0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA, 0xB7, 0xB0, 0xB9, 0xBE,
+        0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
+        0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16,
+        0x03, 0x04, 0x0D, 0x0A, 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
+        0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A, 0x89, 0x8E, 0x87, 0x80,
+        0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
+        0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8,
+        0xDD, 0xDA, 0xD3, 0xD4, 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
+        0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44, 0x19, 0x1E, 0x17, 0x10,
+        0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
+        0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F,
+        0x6A, 0x6D, 0x64, 0x63, 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
+        0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13, 0xAE, 0xA9, 0xA0, 0xA7,
+        0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
+        0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF,
+        0xFA, 0xFD, 0xF4, 0xF3, 0x01
+    },
+    [AV_CRC_16_ANSI] = {
+        0x0000, 0x0580, 0x0F80, 0x0A00, 0x1B80, 0x1E00, 0x1400, 0x1180,
+        0x3380, 0x3600, 0x3C00, 0x3980, 0x2800, 0x2D80, 0x2780, 0x2200,
+        0x6380, 0x6600, 0x6C00, 0x6980, 0x7800, 0x7D80, 0x7780, 0x7200,
+        0x5000, 0x5580, 0x5F80, 0x5A00, 0x4B80, 0x4E00, 0x4400, 0x4180,
+        0xC380, 0xC600, 0xCC00, 0xC980, 0xD800, 0xDD80, 0xD780, 0xD200,
+        0xF000, 0xF580, 0xFF80, 0xFA00, 0xEB80, 0xEE00, 0xE400, 0xE180,
+        0xA000, 0xA580, 0xAF80, 0xAA00, 0xBB80, 0xBE00, 0xB400, 0xB180,
+        0x9380, 0x9600, 0x9C00, 0x9980, 0x8800, 0x8D80, 0x8780, 0x8200,
+        0x8381, 0x8601, 0x8C01, 0x8981, 0x9801, 0x9D81, 0x9781, 0x9201,
+        0xB001, 0xB581, 0xBF81, 0xBA01, 0xAB81, 0xAE01, 0xA401, 0xA181,
+        0xE001, 0xE581, 0xEF81, 0xEA01, 0xFB81, 0xFE01, 0xF401, 0xF181,
+        0xD381, 0xD601, 0xDC01, 0xD981, 0xC801, 0xCD81, 0xC781, 0xC201,
+        0x4001, 0x4581, 0x4F81, 0x4A01, 0x5B81, 0x5E01, 0x5401, 0x5181,
+        0x7381, 0x7601, 0x7C01, 0x7981, 0x6801, 0x6D81, 0x6781, 0x6201,
+        0x2381, 0x2601, 0x2C01, 0x2981, 0x3801, 0x3D81, 0x3781, 0x3201,
+        0x1001, 0x1581, 0x1F81, 0x1A01, 0x0B81, 0x0E01, 0x0401, 0x0181,
+        0x0383, 0x0603, 0x0C03, 0x0983, 0x1803, 0x1D83, 0x1783, 0x1203,
+        0x3003, 0x3583, 0x3F83, 0x3A03, 0x2B83, 0x2E03, 0x2403, 0x2183,
+        0x6003, 0x6583, 0x6F83, 0x6A03, 0x7B83, 0x7E03, 0x7403, 0x7183,
+        0x5383, 0x5603, 0x5C03, 0x5983, 0x4803, 0x4D83, 0x4783, 0x4203,
+        0xC003, 0xC583, 0xCF83, 0xCA03, 0xDB83, 0xDE03, 0xD403, 0xD183,
+        0xF383, 0xF603, 0xFC03, 0xF983, 0xE803, 0xED83, 0xE783, 0xE203,
+        0xA383, 0xA603, 0xAC03, 0xA983, 0xB803, 0xBD83, 0xB783, 0xB203,
+        0x9003, 0x9583, 0x9F83, 0x9A03, 0x8B83, 0x8E03, 0x8403, 0x8183,
+        0x8002, 0x8582, 0x8F82, 0x8A02, 0x9B82, 0x9E02, 0x9402, 0x9182,
+        0xB382, 0xB602, 0xBC02, 0xB982, 0xA802, 0xAD82, 0xA782, 0xA202,
+        0xE382, 0xE602, 0xEC02, 0xE982, 0xF802, 0xFD82, 0xF782, 0xF202,
+        0xD002, 0xD582, 0xDF82, 0xDA02, 0xCB82, 0xCE02, 0xC402, 0xC182,
+        0x4382, 0x4602, 0x4C02, 0x4982, 0x5802, 0x5D82, 0x5782, 0x5202,
+        0x7002, 0x7582, 0x7F82, 0x7A02, 0x6B82, 0x6E02, 0x6402, 0x6182,
+        0x2002, 0x2582, 0x2F82, 0x2A02, 0x3B82, 0x3E02, 0x3402, 0x3182,
+        0x1382, 0x1602, 0x1C02, 0x1982, 0x0802, 0x0D82, 0x0782, 0x0202,
+        0x0001
+    },
+    [AV_CRC_16_CCITT] = {
+        0x0000, 0x2110, 0x4220, 0x6330, 0x8440, 0xA550, 0xC660, 0xE770,
+        0x0881, 0x2991, 0x4AA1, 0x6BB1, 0x8CC1, 0xADD1, 0xCEE1, 0xEFF1,
+        0x3112, 0x1002, 0x7332, 0x5222, 0xB552, 0x9442, 0xF772, 0xD662,
+        0x3993, 0x1883, 0x7BB3, 0x5AA3, 0xBDD3, 0x9CC3, 0xFFF3, 0xDEE3,
+        0x6224, 0x4334, 0x2004, 0x0114, 0xE664, 0xC774, 0xA444, 0x8554,
+        0x6AA5, 0x4BB5, 0x2885, 0x0995, 0xEEE5, 0xCFF5, 0xACC5, 0x8DD5,
+        0x5336, 0x7226, 0x1116, 0x3006, 0xD776, 0xF666, 0x9556, 0xB446,
+        0x5BB7, 0x7AA7, 0x1997, 0x3887, 0xDFF7, 0xFEE7, 0x9DD7, 0xBCC7,
+        0xC448, 0xE558, 0x8668, 0xA778, 0x4008, 0x6118, 0x0228, 0x2338,
+        0xCCC9, 0xEDD9, 0x8EE9, 0xAFF9, 0x4889, 0x6999, 0x0AA9, 0x2BB9,
+        0xF55A, 0xD44A, 0xB77A, 0x966A, 0x711A, 0x500A, 0x333A, 0x122A,
+        0xFDDB, 0xDCCB, 0xBFFB, 0x9EEB, 0x799B, 0x588B, 0x3BBB, 0x1AAB,
+        0xA66C, 0x877C, 0xE44C, 0xC55C, 0x222C, 0x033C, 0x600C, 0x411C,
+        0xAEED, 0x8FFD, 0xECCD, 0xCDDD, 0x2AAD, 0x0BBD, 0x688D, 0x499D,
+        0x977E, 0xB66E, 0xD55E, 0xF44E, 0x133E, 0x322E, 0x511E, 0x700E,
+        0x9FFF, 0xBEEF, 0xDDDF, 0xFCCF, 0x1BBF, 0x3AAF, 0x599F, 0x788F,
+        0x8891, 0xA981, 0xCAB1, 0xEBA1, 0x0CD1, 0x2DC1, 0x4EF1, 0x6FE1,
+        0x8010, 0xA100, 0xC230, 0xE320, 0x0450, 0x2540, 0x4670, 0x6760,
+        0xB983, 0x9893, 0xFBA3, 0xDAB3, 0x3DC3, 0x1CD3, 0x7FE3, 0x5EF3,
+        0xB102, 0x9012, 0xF322, 0xD232, 0x3542, 0x1452, 0x7762, 0x5672,
+        0xEAB5, 0xCBA5, 0xA895, 0x8985, 0x6EF5, 0x4FE5, 0x2CD5, 0x0DC5,
+        0xE234, 0xC324, 0xA014, 0x8104, 0x6674, 0x4764, 0x2454, 0x0544,
+        0xDBA7, 0xFAB7, 0x9987, 0xB897, 0x5FE7, 0x7EF7, 0x1DC7, 0x3CD7,
+        0xD326, 0xF236, 0x9106, 0xB016, 0x5766, 0x7676, 0x1546, 0x3456,
+        0x4CD9, 0x6DC9, 0x0EF9, 0x2FE9, 0xC899, 0xE989, 0x8AB9, 0xABA9,
+        0x4458, 0x6548, 0x0678, 0x2768, 0xC018, 0xE108, 0x8238, 0xA328,
+        0x7DCB, 0x5CDB, 0x3FEB, 0x1EFB, 0xF98B, 0xD89B, 0xBBAB, 0x9ABB,
+        0x754A, 0x545A, 0x376A, 0x167A, 0xF10A, 0xD01A, 0xB32A, 0x923A,
+        0x2EFD, 0x0FED, 0x6CDD, 0x4DCD, 0xAABD, 0x8BAD, 0xE89D, 0xC98D,
+        0x267C, 0x076C, 0x645C, 0x454C, 0xA23C, 0x832C, 0xE01C, 0xC10C,
+        0x1FEF, 0x3EFF, 0x5DCF, 0x7CDF, 0x9BAF, 0xBABF, 0xD98F, 0xF89F,
+        0x176E, 0x367E, 0x554E, 0x745E, 0x932E, 0xB23E, 0xD10E, 0xF01E,
+        0x0001
+    },
+    [AV_CRC_32_IEEE] = {
+        0x00000000, 0xB71DC104, 0x6E3B8209, 0xD926430D, 0xDC760413, 0x6B6BC517,
+        0xB24D861A, 0x0550471E, 0xB8ED0826, 0x0FF0C922, 0xD6D68A2F, 0x61CB4B2B,
+        0x649B0C35, 0xD386CD31, 0x0AA08E3C, 0xBDBD4F38, 0x70DB114C, 0xC7C6D048,
+        0x1EE09345, 0xA9FD5241, 0xACAD155F, 0x1BB0D45B, 0xC2969756, 0x758B5652,
+        0xC836196A, 0x7F2BD86E, 0xA60D9B63, 0x11105A67, 0x14401D79, 0xA35DDC7D,
+        0x7A7B9F70, 0xCD665E74, 0xE0B62398, 0x57ABE29C, 0x8E8DA191, 0x39906095,
+        0x3CC0278B, 0x8BDDE68F, 0x52FBA582, 0xE5E66486, 0x585B2BBE, 0xEF46EABA,
+        0x3660A9B7, 0x817D68B3, 0x842D2FAD, 0x3330EEA9, 0xEA16ADA4, 0x5D0B6CA0,
+        0x906D32D4, 0x2770F3D0, 0xFE56B0DD, 0x494B71D9, 0x4C1B36C7, 0xFB06F7C3,
+        0x2220B4CE, 0x953D75CA, 0x28803AF2, 0x9F9DFBF6, 0x46BBB8FB, 0xF1A679FF,
+        0xF4F63EE1, 0x43EBFFE5, 0x9ACDBCE8, 0x2DD07DEC, 0x77708634, 0xC06D4730,
+        0x194B043D, 0xAE56C539, 0xAB068227, 0x1C1B4323, 0xC53D002E, 0x7220C12A,
+        0xCF9D8E12, 0x78804F16, 0xA1A60C1B, 0x16BBCD1F, 0x13EB8A01, 0xA4F64B05,
+        0x7DD00808, 0xCACDC90C, 0x07AB9778, 0xB0B6567C, 0x69901571, 0xDE8DD475,
+        0xDBDD936B, 0x6CC0526F, 0xB5E61162, 0x02FBD066, 0xBF469F5E, 0x085B5E5A,
+        0xD17D1D57, 0x6660DC53, 0x63309B4D, 0xD42D5A49, 0x0D0B1944, 0xBA16D840,
+        0x97C6A5AC, 0x20DB64A8, 0xF9FD27A5, 0x4EE0E6A1, 0x4BB0A1BF, 0xFCAD60BB,
+        0x258B23B6, 0x9296E2B2, 0x2F2BAD8A, 0x98366C8E, 0x41102F83, 0xF60DEE87,
+        0xF35DA999, 0x4440689D, 0x9D662B90, 0x2A7BEA94, 0xE71DB4E0, 0x500075E4,
+        0x892636E9, 0x3E3BF7ED, 0x3B6BB0F3, 0x8C7671F7, 0x555032FA, 0xE24DF3FE,
+        0x5FF0BCC6, 0xE8ED7DC2, 0x31CB3ECF, 0x86D6FFCB, 0x8386B8D5, 0x349B79D1,
+        0xEDBD3ADC, 0x5AA0FBD8, 0xEEE00C69, 0x59FDCD6D, 0x80DB8E60, 0x37C64F64,
+        0x3296087A, 0x858BC97E, 0x5CAD8A73, 0xEBB04B77, 0x560D044F, 0xE110C54B,
+        0x38368646, 0x8F2B4742, 0x8A7B005C, 0x3D66C158, 0xE4408255, 0x535D4351,
+        0x9E3B1D25, 0x2926DC21, 0xF0009F2C, 0x471D5E28, 0x424D1936, 0xF550D832,
+        0x2C769B3F, 0x9B6B5A3B, 0x26D61503, 0x91CBD407, 0x48ED970A, 0xFFF0560E,
+        0xFAA01110, 0x4DBDD014, 0x949B9319, 0x2386521D, 0x0E562FF1, 0xB94BEEF5,
+        0x606DADF8, 0xD7706CFC, 0xD2202BE2, 0x653DEAE6, 0xBC1BA9EB, 0x0B0668EF,
+        0xB6BB27D7, 0x01A6E6D3, 0xD880A5DE, 0x6F9D64DA, 0x6ACD23C4, 0xDDD0E2C0,
+        0x04F6A1CD, 0xB3EB60C9, 0x7E8D3EBD, 0xC990FFB9, 0x10B6BCB4, 0xA7AB7DB0,
+        0xA2FB3AAE, 0x15E6FBAA, 0xCCC0B8A7, 0x7BDD79A3, 0xC660369B, 0x717DF79F,
+        0xA85BB492, 0x1F467596, 0x1A163288, 0xAD0BF38C, 0x742DB081, 0xC3307185,
+        0x99908A5D, 0x2E8D4B59, 0xF7AB0854, 0x40B6C950, 0x45E68E4E, 0xF2FB4F4A,
+        0x2BDD0C47, 0x9CC0CD43, 0x217D827B, 0x9660437F, 0x4F460072, 0xF85BC176,
+        0xFD0B8668, 0x4A16476C, 0x93300461, 0x242DC565, 0xE94B9B11, 0x5E565A15,
+        0x87701918, 0x306DD81C, 0x353D9F02, 0x82205E06, 0x5B061D0B, 0xEC1BDC0F,
+        0x51A69337, 0xE6BB5233, 0x3F9D113E, 0x8880D03A, 0x8DD09724, 0x3ACD5620,
+        0xE3EB152D, 0x54F6D429, 0x7926A9C5, 0xCE3B68C1, 0x171D2BCC, 0xA000EAC8,
+        0xA550ADD6, 0x124D6CD2, 0xCB6B2FDF, 0x7C76EEDB, 0xC1CBA1E3, 0x76D660E7,
+        0xAFF023EA, 0x18EDE2EE, 0x1DBDA5F0, 0xAAA064F4, 0x738627F9, 0xC49BE6FD,
+        0x09FDB889, 0xBEE0798D, 0x67C63A80, 0xD0DBFB84, 0xD58BBC9A, 0x62967D9E,
+        0xBBB03E93, 0x0CADFF97, 0xB110B0AF, 0x060D71AB, 0xDF2B32A6, 0x6836F3A2,
+        0x6D66B4BC, 0xDA7B75B8, 0x035D36B5, 0xB440F7B1, 0x00000001
+    },
+    [AV_CRC_32_IEEE_LE] = {
+        0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
+        0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
+        0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
+        0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
+        0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
+        0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
+        0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C,
+        0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
+        0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423,
+        0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
+        0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106,
+        0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
+        0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D,
+        0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
+        0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
+        0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
+        0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7,
+        0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
+        0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA,
+        0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
+        0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
+        0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
+        0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84,
+        0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
+        0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
+        0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
+        0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E,
+        0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
+        0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55,
+        0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
+        0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28,
+        0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
+        0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,
+        0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
+        0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
+        0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
+        0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69,
+        0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
+        0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC,
+        0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
+        0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693,
+        0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
+        0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, 0x00000001
+    },
+};
 #else
 static struct {
     uint8_t  le;
diff --git a/mythtv/external/FFmpeg/libavutil/crc_data.h b/mythtv/external/FFmpeg/libavutil/crc_data.h
deleted file mode 100644
index afa25e7cfcf..00000000000
--- a/mythtv/external/FFmpeg/libavutil/crc_data.h
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * copyright (c) 2008 Aurelien Jacobs 
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef AVUTIL_CRC_DATA_H
-#define AVUTIL_CRC_DATA_H
-
-#include "crc.h"
-
-static const AVCRC av_crc_table[AV_CRC_MAX][257] = {
-    [AV_CRC_8_ATM] = {
-        0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31,
-        0x24, 0x23, 0x2A, 0x2D, 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
-        0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, 0xE0, 0xE7, 0xEE, 0xE9,
-        0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
-        0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1,
-        0xB4, 0xB3, 0xBA, 0xBD, 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
-        0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA, 0xB7, 0xB0, 0xB9, 0xBE,
-        0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
-        0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16,
-        0x03, 0x04, 0x0D, 0x0A, 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
-        0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A, 0x89, 0x8E, 0x87, 0x80,
-        0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
-        0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8,
-        0xDD, 0xDA, 0xD3, 0xD4, 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
-        0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44, 0x19, 0x1E, 0x17, 0x10,
-        0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
-        0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F,
-        0x6A, 0x6D, 0x64, 0x63, 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
-        0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13, 0xAE, 0xA9, 0xA0, 0xA7,
-        0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
-        0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF,
-        0xFA, 0xFD, 0xF4, 0xF3, 0x01
-    },
-    [AV_CRC_16_ANSI] = {
-        0x0000, 0x0580, 0x0F80, 0x0A00, 0x1B80, 0x1E00, 0x1400, 0x1180,
-        0x3380, 0x3600, 0x3C00, 0x3980, 0x2800, 0x2D80, 0x2780, 0x2200,
-        0x6380, 0x6600, 0x6C00, 0x6980, 0x7800, 0x7D80, 0x7780, 0x7200,
-        0x5000, 0x5580, 0x5F80, 0x5A00, 0x4B80, 0x4E00, 0x4400, 0x4180,
-        0xC380, 0xC600, 0xCC00, 0xC980, 0xD800, 0xDD80, 0xD780, 0xD200,
-        0xF000, 0xF580, 0xFF80, 0xFA00, 0xEB80, 0xEE00, 0xE400, 0xE180,
-        0xA000, 0xA580, 0xAF80, 0xAA00, 0xBB80, 0xBE00, 0xB400, 0xB180,
-        0x9380, 0x9600, 0x9C00, 0x9980, 0x8800, 0x8D80, 0x8780, 0x8200,
-        0x8381, 0x8601, 0x8C01, 0x8981, 0x9801, 0x9D81, 0x9781, 0x9201,
-        0xB001, 0xB581, 0xBF81, 0xBA01, 0xAB81, 0xAE01, 0xA401, 0xA181,
-        0xE001, 0xE581, 0xEF81, 0xEA01, 0xFB81, 0xFE01, 0xF401, 0xF181,
-        0xD381, 0xD601, 0xDC01, 0xD981, 0xC801, 0xCD81, 0xC781, 0xC201,
-        0x4001, 0x4581, 0x4F81, 0x4A01, 0x5B81, 0x5E01, 0x5401, 0x5181,
-        0x7381, 0x7601, 0x7C01, 0x7981, 0x6801, 0x6D81, 0x6781, 0x6201,
-        0x2381, 0x2601, 0x2C01, 0x2981, 0x3801, 0x3D81, 0x3781, 0x3201,
-        0x1001, 0x1581, 0x1F81, 0x1A01, 0x0B81, 0x0E01, 0x0401, 0x0181,
-        0x0383, 0x0603, 0x0C03, 0x0983, 0x1803, 0x1D83, 0x1783, 0x1203,
-        0x3003, 0x3583, 0x3F83, 0x3A03, 0x2B83, 0x2E03, 0x2403, 0x2183,
-        0x6003, 0x6583, 0x6F83, 0x6A03, 0x7B83, 0x7E03, 0x7403, 0x7183,
-        0x5383, 0x5603, 0x5C03, 0x5983, 0x4803, 0x4D83, 0x4783, 0x4203,
-        0xC003, 0xC583, 0xCF83, 0xCA03, 0xDB83, 0xDE03, 0xD403, 0xD183,
-        0xF383, 0xF603, 0xFC03, 0xF983, 0xE803, 0xED83, 0xE783, 0xE203,
-        0xA383, 0xA603, 0xAC03, 0xA983, 0xB803, 0xBD83, 0xB783, 0xB203,
-        0x9003, 0x9583, 0x9F83, 0x9A03, 0x8B83, 0x8E03, 0x8403, 0x8183,
-        0x8002, 0x8582, 0x8F82, 0x8A02, 0x9B82, 0x9E02, 0x9402, 0x9182,
-        0xB382, 0xB602, 0xBC02, 0xB982, 0xA802, 0xAD82, 0xA782, 0xA202,
-        0xE382, 0xE602, 0xEC02, 0xE982, 0xF802, 0xFD82, 0xF782, 0xF202,
-        0xD002, 0xD582, 0xDF82, 0xDA02, 0xCB82, 0xCE02, 0xC402, 0xC182,
-        0x4382, 0x4602, 0x4C02, 0x4982, 0x5802, 0x5D82, 0x5782, 0x5202,
-        0x7002, 0x7582, 0x7F82, 0x7A02, 0x6B82, 0x6E02, 0x6402, 0x6182,
-        0x2002, 0x2582, 0x2F82, 0x2A02, 0x3B82, 0x3E02, 0x3402, 0x3182,
-        0x1382, 0x1602, 0x1C02, 0x1982, 0x0802, 0x0D82, 0x0782, 0x0202,
-        0x0001
-    },
-    [AV_CRC_16_CCITT] = {
-        0x0000, 0x2110, 0x4220, 0x6330, 0x8440, 0xA550, 0xC660, 0xE770,
-        0x0881, 0x2991, 0x4AA1, 0x6BB1, 0x8CC1, 0xADD1, 0xCEE1, 0xEFF1,
-        0x3112, 0x1002, 0x7332, 0x5222, 0xB552, 0x9442, 0xF772, 0xD662,
-        0x3993, 0x1883, 0x7BB3, 0x5AA3, 0xBDD3, 0x9CC3, 0xFFF3, 0xDEE3,
-        0x6224, 0x4334, 0x2004, 0x0114, 0xE664, 0xC774, 0xA444, 0x8554,
-        0x6AA5, 0x4BB5, 0x2885, 0x0995, 0xEEE5, 0xCFF5, 0xACC5, 0x8DD5,
-        0x5336, 0x7226, 0x1116, 0x3006, 0xD776, 0xF666, 0x9556, 0xB446,
-        0x5BB7, 0x7AA7, 0x1997, 0x3887, 0xDFF7, 0xFEE7, 0x9DD7, 0xBCC7,
-        0xC448, 0xE558, 0x8668, 0xA778, 0x4008, 0x6118, 0x0228, 0x2338,
-        0xCCC9, 0xEDD9, 0x8EE9, 0xAFF9, 0x4889, 0x6999, 0x0AA9, 0x2BB9,
-        0xF55A, 0xD44A, 0xB77A, 0x966A, 0x711A, 0x500A, 0x333A, 0x122A,
-        0xFDDB, 0xDCCB, 0xBFFB, 0x9EEB, 0x799B, 0x588B, 0x3BBB, 0x1AAB,
-        0xA66C, 0x877C, 0xE44C, 0xC55C, 0x222C, 0x033C, 0x600C, 0x411C,
-        0xAEED, 0x8FFD, 0xECCD, 0xCDDD, 0x2AAD, 0x0BBD, 0x688D, 0x499D,
-        0x977E, 0xB66E, 0xD55E, 0xF44E, 0x133E, 0x322E, 0x511E, 0x700E,
-        0x9FFF, 0xBEEF, 0xDDDF, 0xFCCF, 0x1BBF, 0x3AAF, 0x599F, 0x788F,
-        0x8891, 0xA981, 0xCAB1, 0xEBA1, 0x0CD1, 0x2DC1, 0x4EF1, 0x6FE1,
-        0x8010, 0xA100, 0xC230, 0xE320, 0x0450, 0x2540, 0x4670, 0x6760,
-        0xB983, 0x9893, 0xFBA3, 0xDAB3, 0x3DC3, 0x1CD3, 0x7FE3, 0x5EF3,
-        0xB102, 0x9012, 0xF322, 0xD232, 0x3542, 0x1452, 0x7762, 0x5672,
-        0xEAB5, 0xCBA5, 0xA895, 0x8985, 0x6EF5, 0x4FE5, 0x2CD5, 0x0DC5,
-        0xE234, 0xC324, 0xA014, 0x8104, 0x6674, 0x4764, 0x2454, 0x0544,
-        0xDBA7, 0xFAB7, 0x9987, 0xB897, 0x5FE7, 0x7EF7, 0x1DC7, 0x3CD7,
-        0xD326, 0xF236, 0x9106, 0xB016, 0x5766, 0x7676, 0x1546, 0x3456,
-        0x4CD9, 0x6DC9, 0x0EF9, 0x2FE9, 0xC899, 0xE989, 0x8AB9, 0xABA9,
-        0x4458, 0x6548, 0x0678, 0x2768, 0xC018, 0xE108, 0x8238, 0xA328,
-        0x7DCB, 0x5CDB, 0x3FEB, 0x1EFB, 0xF98B, 0xD89B, 0xBBAB, 0x9ABB,
-        0x754A, 0x545A, 0x376A, 0x167A, 0xF10A, 0xD01A, 0xB32A, 0x923A,
-        0x2EFD, 0x0FED, 0x6CDD, 0x4DCD, 0xAABD, 0x8BAD, 0xE89D, 0xC98D,
-        0x267C, 0x076C, 0x645C, 0x454C, 0xA23C, 0x832C, 0xE01C, 0xC10C,
-        0x1FEF, 0x3EFF, 0x5DCF, 0x7CDF, 0x9BAF, 0xBABF, 0xD98F, 0xF89F,
-        0x176E, 0x367E, 0x554E, 0x745E, 0x932E, 0xB23E, 0xD10E, 0xF01E,
-        0x0001
-    },
-    [AV_CRC_32_IEEE] = {
-        0x00000000, 0xB71DC104, 0x6E3B8209, 0xD926430D, 0xDC760413, 0x6B6BC517,
-        0xB24D861A, 0x0550471E, 0xB8ED0826, 0x0FF0C922, 0xD6D68A2F, 0x61CB4B2B,
-        0x649B0C35, 0xD386CD31, 0x0AA08E3C, 0xBDBD4F38, 0x70DB114C, 0xC7C6D048,
-        0x1EE09345, 0xA9FD5241, 0xACAD155F, 0x1BB0D45B, 0xC2969756, 0x758B5652,
-        0xC836196A, 0x7F2BD86E, 0xA60D9B63, 0x11105A67, 0x14401D79, 0xA35DDC7D,
-        0x7A7B9F70, 0xCD665E74, 0xE0B62398, 0x57ABE29C, 0x8E8DA191, 0x39906095,
-        0x3CC0278B, 0x8BDDE68F, 0x52FBA582, 0xE5E66486, 0x585B2BBE, 0xEF46EABA,
-        0x3660A9B7, 0x817D68B3, 0x842D2FAD, 0x3330EEA9, 0xEA16ADA4, 0x5D0B6CA0,
-        0x906D32D4, 0x2770F3D0, 0xFE56B0DD, 0x494B71D9, 0x4C1B36C7, 0xFB06F7C3,
-        0x2220B4CE, 0x953D75CA, 0x28803AF2, 0x9F9DFBF6, 0x46BBB8FB, 0xF1A679FF,
-        0xF4F63EE1, 0x43EBFFE5, 0x9ACDBCE8, 0x2DD07DEC, 0x77708634, 0xC06D4730,
-        0x194B043D, 0xAE56C539, 0xAB068227, 0x1C1B4323, 0xC53D002E, 0x7220C12A,
-        0xCF9D8E12, 0x78804F16, 0xA1A60C1B, 0x16BBCD1F, 0x13EB8A01, 0xA4F64B05,
-        0x7DD00808, 0xCACDC90C, 0x07AB9778, 0xB0B6567C, 0x69901571, 0xDE8DD475,
-        0xDBDD936B, 0x6CC0526F, 0xB5E61162, 0x02FBD066, 0xBF469F5E, 0x085B5E5A,
-        0xD17D1D57, 0x6660DC53, 0x63309B4D, 0xD42D5A49, 0x0D0B1944, 0xBA16D840,
-        0x97C6A5AC, 0x20DB64A8, 0xF9FD27A5, 0x4EE0E6A1, 0x4BB0A1BF, 0xFCAD60BB,
-        0x258B23B6, 0x9296E2B2, 0x2F2BAD8A, 0x98366C8E, 0x41102F83, 0xF60DEE87,
-        0xF35DA999, 0x4440689D, 0x9D662B90, 0x2A7BEA94, 0xE71DB4E0, 0x500075E4,
-        0x892636E9, 0x3E3BF7ED, 0x3B6BB0F3, 0x8C7671F7, 0x555032FA, 0xE24DF3FE,
-        0x5FF0BCC6, 0xE8ED7DC2, 0x31CB3ECF, 0x86D6FFCB, 0x8386B8D5, 0x349B79D1,
-        0xEDBD3ADC, 0x5AA0FBD8, 0xEEE00C69, 0x59FDCD6D, 0x80DB8E60, 0x37C64F64,
-        0x3296087A, 0x858BC97E, 0x5CAD8A73, 0xEBB04B77, 0x560D044F, 0xE110C54B,
-        0x38368646, 0x8F2B4742, 0x8A7B005C, 0x3D66C158, 0xE4408255, 0x535D4351,
-        0x9E3B1D25, 0x2926DC21, 0xF0009F2C, 0x471D5E28, 0x424D1936, 0xF550D832,
-        0x2C769B3F, 0x9B6B5A3B, 0x26D61503, 0x91CBD407, 0x48ED970A, 0xFFF0560E,
-        0xFAA01110, 0x4DBDD014, 0x949B9319, 0x2386521D, 0x0E562FF1, 0xB94BEEF5,
-        0x606DADF8, 0xD7706CFC, 0xD2202BE2, 0x653DEAE6, 0xBC1BA9EB, 0x0B0668EF,
-        0xB6BB27D7, 0x01A6E6D3, 0xD880A5DE, 0x6F9D64DA, 0x6ACD23C4, 0xDDD0E2C0,
-        0x04F6A1CD, 0xB3EB60C9, 0x7E8D3EBD, 0xC990FFB9, 0x10B6BCB4, 0xA7AB7DB0,
-        0xA2FB3AAE, 0x15E6FBAA, 0xCCC0B8A7, 0x7BDD79A3, 0xC660369B, 0x717DF79F,
-        0xA85BB492, 0x1F467596, 0x1A163288, 0xAD0BF38C, 0x742DB081, 0xC3307185,
-        0x99908A5D, 0x2E8D4B59, 0xF7AB0854, 0x40B6C950, 0x45E68E4E, 0xF2FB4F4A,
-        0x2BDD0C47, 0x9CC0CD43, 0x217D827B, 0x9660437F, 0x4F460072, 0xF85BC176,
-        0xFD0B8668, 0x4A16476C, 0x93300461, 0x242DC565, 0xE94B9B11, 0x5E565A15,
-        0x87701918, 0x306DD81C, 0x353D9F02, 0x82205E06, 0x5B061D0B, 0xEC1BDC0F,
-        0x51A69337, 0xE6BB5233, 0x3F9D113E, 0x8880D03A, 0x8DD09724, 0x3ACD5620,
-        0xE3EB152D, 0x54F6D429, 0x7926A9C5, 0xCE3B68C1, 0x171D2BCC, 0xA000EAC8,
-        0xA550ADD6, 0x124D6CD2, 0xCB6B2FDF, 0x7C76EEDB, 0xC1CBA1E3, 0x76D660E7,
-        0xAFF023EA, 0x18EDE2EE, 0x1DBDA5F0, 0xAAA064F4, 0x738627F9, 0xC49BE6FD,
-        0x09FDB889, 0xBEE0798D, 0x67C63A80, 0xD0DBFB84, 0xD58BBC9A, 0x62967D9E,
-        0xBBB03E93, 0x0CADFF97, 0xB110B0AF, 0x060D71AB, 0xDF2B32A6, 0x6836F3A2,
-        0x6D66B4BC, 0xDA7B75B8, 0x035D36B5, 0xB440F7B1, 0x00000001
-    },
-    [AV_CRC_32_IEEE_LE] = {
-        0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
-        0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
-        0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
-        0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
-        0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
-        0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
-        0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C,
-        0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
-        0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423,
-        0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
-        0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106,
-        0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
-        0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D,
-        0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
-        0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
-        0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
-        0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7,
-        0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
-        0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA,
-        0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
-        0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
-        0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
-        0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84,
-        0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
-        0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
-        0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
-        0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E,
-        0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
-        0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55,
-        0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
-        0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28,
-        0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
-        0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,
-        0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
-        0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
-        0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
-        0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69,
-        0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
-        0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC,
-        0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
-        0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693,
-        0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
-        0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, 0x00000001
-    },
-};
-
-#endif /* AVUTIL_CRC_DATA_H */
diff --git a/mythtv/external/FFmpeg/libavutil/dict.c b/mythtv/external/FFmpeg/libavutil/dict.c
index 7e7d1cc4a89..3cd7156a043 100644
--- a/mythtv/external/FFmpeg/libavutil/dict.c
+++ b/mythtv/external/FFmpeg/libavutil/dict.c
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
 #include 
 
 #include "avstring.h"
@@ -50,7 +49,7 @@ av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int
     for(; icount; i++){
         const char *s= m->elems[i].key;
         if(flags & AV_DICT_MATCH_CASE) for(j=0;         s[j]  ==         key[j]  && key[j]; j++);
-        else                               for(j=0; toupper(s[j]) == toupper(key[j]) && key[j]; j++);
+        else                               for(j=0; av_toupper(s[j]) == av_toupper(key[j]) && key[j]; j++);
         if(key[j])
             continue;
         if(s[j] && !(flags & AV_DICT_IGNORE_SUFFIX))
@@ -94,10 +93,13 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags
             m->elems[m->count].value = (char*)(intptr_t)value;
         } else if (oldval && flags & AV_DICT_APPEND) {
             int len = strlen(oldval) + strlen(value) + 1;
-            if (!(oldval = av_realloc(oldval, len)))
+            char *newval = av_mallocz(len);
+            if (!newval)
                 return AVERROR(ENOMEM);
-            av_strlcat(oldval, value, len);
-            m->elems[m->count].value = oldval;
+            av_strlcat(newval, oldval, len);
+            av_freep(&oldval);
+            av_strlcat(newval, value, len);
+            m->elems[m->count].value = newval;
         } else
             m->elems[m->count].value = av_strdup(value);
         m->count++;
@@ -110,6 +112,53 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags
     return 0;
 }
 
+static int parse_key_value_pair(AVDictionary **pm, const char **buf,
+                                const char *key_val_sep, const char *pairs_sep,
+                                int flags)
+{
+    char *key = av_get_token(buf, key_val_sep);
+    char *val = NULL;
+    int ret;
+
+    if (key && *key && strspn(*buf, key_val_sep)) {
+        (*buf)++;
+        val = av_get_token(buf, pairs_sep);
+    }
+
+    if (key && *key && val && *val)
+        ret = av_dict_set(pm, key, val, flags);
+    else
+        ret = AVERROR(EINVAL);
+
+    av_freep(&key);
+    av_freep(&val);
+
+    return ret;
+}
+
+int av_dict_parse_string(AVDictionary **pm, const char *str,
+                         const char *key_val_sep, const char *pairs_sep,
+                         int flags)
+{
+    int ret;
+
+    if (!str)
+        return 0;
+
+    /* ignore STRDUP flags */
+    flags &= ~(AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
+
+    while (*str) {
+        if ((ret = parse_key_value_pair(pm, &str, key_val_sep, pairs_sep, flags)) < 0)
+            return ret;
+
+        if (*str)
+            str++;
+    }
+
+    return 0;
+}
+
 void av_dict_free(AVDictionary **pm)
 {
     AVDictionary *m = *pm;
diff --git a/mythtv/external/FFmpeg/libavutil/dict.h b/mythtv/external/FFmpeg/libavutil/dict.h
index fde3650184c..38f03a407f3 100644
--- a/mythtv/external/FFmpeg/libavutil/dict.h
+++ b/mythtv/external/FFmpeg/libavutil/dict.h
@@ -112,6 +112,23 @@ int av_dict_count(const AVDictionary *m);
  */
 int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags);
 
+/**
+ * Parse the key/value pairs list and add to a dictionary.
+ *
+ * @param key_val_sep  a 0-terminated list of characters used to separate
+ *                     key from value
+ * @param pairs_sep    a 0-terminated list of characters used to separate
+ *                     two pairs from each other
+ * @param flags        flags to use when adding to dictionary.
+ *                     AV_DICT_DONT_STRDUP_KEY and AV_DICT_DONT_STRDUP_VAL
+ *                     are ignored since the key/value tokens will always
+ *                     be duplicated.
+ * @return             0 on success, negative AVERROR code on failure
+ */
+int av_dict_parse_string(AVDictionary **pm, const char *str,
+                         const char *key_val_sep, const char *pairs_sep,
+                         int flags);
+
 /**
  * Copy entries from one AVDictionary struct into another.
  * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
diff --git a/mythtv/external/FFmpeg/libavutil/eval.c b/mythtv/external/FFmpeg/libavutil/eval.c
index 6687b646f5a..48757258867 100644
--- a/mythtv/external/FFmpeg/libavutil/eval.c
+++ b/mythtv/external/FFmpeg/libavutil/eval.c
@@ -32,6 +32,8 @@
 #include "eval.h"
 #include "log.h"
 #include "mathematics.h"
+#include "time.h"
+#include "avstring.h"
 
 typedef struct Parser {
     const AVClass *class;
@@ -139,11 +141,11 @@ struct AVExpr {
     enum {
         e_value, e_const, e_func0, e_func1, e_func2,
         e_squish, e_gauss, e_ld, e_isnan, e_isinf,
-        e_mod, e_max, e_min, e_eq, e_gt, e_gte,
+        e_mod, e_max, e_min, e_eq, e_gt, e_gte, e_lte, e_lt,
         e_pow, e_mul, e_div, e_add,
         e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc,
         e_sqrt, e_not, e_random, e_hypot, e_gcd,
-        e_if, e_ifnot,
+        e_if, e_ifnot, e_print,
     } type;
     double value; // is sign in other types
     union {
@@ -156,6 +158,11 @@ struct AVExpr {
     double *var;
 };
 
+static double etime(double v)
+{
+    return av_gettime() * 0.000001;
+}
+
 static double eval_expr(Parser *p, AVExpr *e)
 {
     switch (e->type) {
@@ -174,8 +181,16 @@ static double eval_expr(Parser *p, AVExpr *e)
         case e_trunc:  return e->value * trunc(eval_expr(p, e->param[0]));
         case e_sqrt:   return e->value * sqrt (eval_expr(p, e->param[0]));
         case e_not:    return e->value * (eval_expr(p, e->param[0]) == 0);
-        case e_if:     return e->value * ( eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) : 0);
-        case e_ifnot:  return e->value * (!eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) : 0);
+        case e_if:     return e->value * (eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) :
+                                          e->param[2] ? eval_expr(p, e->param[2]) : 0);
+        case e_ifnot:  return e->value * (!eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) :
+                                          e->param[2] ? eval_expr(p, e->param[2]) : 0);
+        case e_print: {
+            double x = eval_expr(p, e->param[0]);
+            int level = e->param[1] ? av_clip(eval_expr(p, e->param[1]), INT_MIN, INT_MAX) : AV_LOG_INFO;
+            av_log(p, level, "%f\n", x);
+            return x;
+        }
         case e_random:{
             int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1);
             uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx];
@@ -260,6 +275,8 @@ static double eval_expr(Parser *p, AVExpr *e)
                 case e_eq:  return e->value * (d == d2 ? 1.0 : 0.0);
                 case e_gt:  return e->value * (d >  d2 ? 1.0 : 0.0);
                 case e_gte: return e->value * (d >= d2 ? 1.0 : 0.0);
+                case e_lt:  return e->value * (d <  d2 ? 1.0 : 0.0);
+                case e_lte: return e->value * (d <= d2 ? 1.0 : 0.0);
                 case e_pow: return e->value * pow(d, d2);
                 case e_mul: return e->value * (d * d2);
                 case e_div: return e->value * ((!CONFIG_FTRAPV || d2 ) ? (d / d2) : d * INFINITY);
@@ -377,6 +394,7 @@ static int parse_primary(AVExpr **e, Parser *p)
     else if (strmatch(next, "exp"   )) d->a.func0 = exp;
     else if (strmatch(next, "log"   )) d->a.func0 = log;
     else if (strmatch(next, "abs"   )) d->a.func0 = fabs;
+    else if (strmatch(next, "time"  )) d->a.func0 = etime;
     else if (strmatch(next, "squish")) d->type = e_squish;
     else if (strmatch(next, "gauss" )) d->type = e_gauss;
     else if (strmatch(next, "mod"   )) d->type = e_mod;
@@ -385,8 +403,8 @@ static int parse_primary(AVExpr **e, Parser *p)
     else if (strmatch(next, "eq"    )) d->type = e_eq;
     else if (strmatch(next, "gte"   )) d->type = e_gte;
     else if (strmatch(next, "gt"    )) d->type = e_gt;
-    else if (strmatch(next, "lte"   )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gte; }
-    else if (strmatch(next, "lt"    )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gt; }
+    else if (strmatch(next, "lte"   )) d->type = e_lte;
+    else if (strmatch(next, "lt"    )) d->type = e_lt;
     else if (strmatch(next, "ld"    )) d->type = e_ld;
     else if (strmatch(next, "isnan" )) d->type = e_isnan;
     else if (strmatch(next, "isinf" )) d->type = e_isinf;
@@ -400,6 +418,7 @@ static int parse_primary(AVExpr **e, Parser *p)
     else if (strmatch(next, "sqrt"  )) d->type = e_sqrt;
     else if (strmatch(next, "not"   )) d->type = e_not;
     else if (strmatch(next, "pow"   )) d->type = e_pow;
+    else if (strmatch(next, "print" )) d->type = e_print;
     else if (strmatch(next, "random")) d->type = e_random;
     else if (strmatch(next, "hypot" )) d->type = e_hypot;
     else if (strmatch(next, "gcd"   )) d->type = e_gcd;
@@ -458,7 +477,7 @@ static int parse_dB(AVExpr **e, Parser *p, int *sign)
        for example, -3dB is not the same as -(3dB) */
     if (*p->s == '-') {
         char *next;
-        strtod(p->s, &next);
+        double av_unused v = strtod(p->s, &next);
         if (next != p->s && next[0] == 'd' && next[1] == 'B') {
             *sign = 0;
             return parse_primary(e, p);
@@ -592,6 +611,11 @@ static int verify_expr(AVExpr *e)
         case e_not:
         case e_random:
             return verify_expr(e->param[0]) && !e->param[1];
+        case e_print:
+            return verify_expr(e->param[0])
+                   && (!e->param[1] || verify_expr(e->param[1]));
+        case e_if:
+        case e_ifnot:
         case e_taylor:
             return verify_expr(e->param[0]) && verify_expr(e->param[1])
                    && (!e->param[2] || verify_expr(e->param[2]));
@@ -616,7 +640,7 @@ int av_expr_parse(AVExpr **expr, const char *s,
         return AVERROR(ENOMEM);
 
     while (*s)
-        if (!isspace(*s++)) *wp++ = s[-1];
+        if (!av_isspace(*s++)) *wp++ = s[-1];
     *wp++ = 0;
 
     p.class      = &class;
@@ -770,8 +794,12 @@ int main(int argc, char **argv)
         "PI^1.23",
         "pow(-1,1.23)",
         "if(1, 2)",
+        "if(1, 1, 2)",
+        "if(0, 1, 2)",
         "ifnot(0, 23)",
         "ifnot(1, NaN) + if(0, 1)",
+        "ifnot(1, 1, 2)",
+        "ifnot(0, 1, 2)",
         "taylor(1, 1)",
         "taylor(eq(mod(ld(1),4),1)-eq(mod(ld(1),4),3), PI/2, 1)",
         "root(sin(ld(0))-1, 2)",
@@ -780,7 +808,7 @@ int main(int argc, char **argv)
         "squish(2)",
         "gauss(0.1)",
         "hypot(4,3)",
-        "gcd(30,55)*min(9,1)",
+        "gcd(30,55)*print(min(9,1))",
         NULL
     };
 
diff --git a/mythtv/external/FFmpeg/libavutil/float_dsp.c b/mythtv/external/FFmpeg/libavutil/float_dsp.c
index c8b2c65c3ca..76413138cea 100644
--- a/mythtv/external/FFmpeg/libavutil/float_dsp.c
+++ b/mythtv/external/FFmpeg/libavutil/float_dsp.c
@@ -55,12 +55,77 @@ static void vector_dmul_scalar_c(double *dst, const double *src, double mul,
         dst[i] = src[i] * mul;
 }
 
+static void vector_fmul_window_c(float *dst, const float *src0,
+                                 const float *src1, const float *win, int len)
+{
+    int i, j;
+
+    dst  += len;
+    win  += len;
+    src0 += len;
+
+    for (i = -len, j = len - 1; i < 0; i++, j--) {
+        float s0 = src0[i];
+        float s1 = src1[j];
+        float wi = win[i];
+        float wj = win[j];
+        dst[i] = s0 * wj - s1 * wi;
+        dst[j] = s0 * wi + s1 * wj;
+    }
+}
+
+static void vector_fmul_add_c(float *dst, const float *src0, const float *src1,
+                              const float *src2, int len){
+    int i;
+
+    for (i = 0; i < len; i++)
+        dst[i] = src0[i] * src1[i] + src2[i];
+}
+
+static void vector_fmul_reverse_c(float *dst, const float *src0,
+                                  const float *src1, int len)
+{
+    int i;
+
+    src1 += len-1;
+    for (i = 0; i < len; i++)
+        dst[i] = src0[i] * src1[-i];
+}
+
+static void butterflies_float_c(float *av_restrict v1, float *av_restrict v2,
+                                int len)
+{
+    int i;
+
+    for (i = 0; i < len; i++) {
+        float t = v1[i] - v2[i];
+        v1[i] += v2[i];
+        v2[i] = t;
+    }
+}
+
+float avpriv_scalarproduct_float_c(const float *v1, const float *v2, int len)
+{
+    float p = 0.0;
+    int i;
+
+    for (i = 0; i < len; i++)
+        p += v1[i] * v2[i];
+
+    return p;
+}
+
 void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
 {
     fdsp->vector_fmul = vector_fmul_c;
     fdsp->vector_fmac_scalar = vector_fmac_scalar_c;
     fdsp->vector_fmul_scalar = vector_fmul_scalar_c;
     fdsp->vector_dmul_scalar = vector_dmul_scalar_c;
+    fdsp->vector_fmul_window = vector_fmul_window_c;
+    fdsp->vector_fmul_add = vector_fmul_add_c;
+    fdsp->vector_fmul_reverse = vector_fmul_reverse_c;
+    fdsp->butterflies_float = butterflies_float_c;
+    fdsp->scalarproduct_float = avpriv_scalarproduct_float_c;
 
 #if ARCH_ARM
     ff_float_dsp_init_arm(fdsp);
diff --git a/mythtv/external/FFmpeg/libavutil/float_dsp.h b/mythtv/external/FFmpeg/libavutil/float_dsp.h
index a3dc9472686..d0447d63462 100644
--- a/mythtv/external/FFmpeg/libavutil/float_dsp.h
+++ b/mythtv/external/FFmpeg/libavutil/float_dsp.h
@@ -19,6 +19,8 @@
 #ifndef AVUTIL_FLOAT_DSP_H
 #define AVUTIL_FLOAT_DSP_H
 
+#include "config.h"
+
 typedef struct AVFloatDSPContext {
     /**
      * Calculate the product of two vectors of floats and store the result in
@@ -81,8 +83,95 @@ typedef struct AVFloatDSPContext {
      */
     void (*vector_dmul_scalar)(double *dst, const double *src, double mul,
                                int len);
+
+    /**
+     * Overlap/add with window function.
+     * Used primarily by MDCT-based audio codecs.
+     * Source and destination vectors must overlap exactly or not at all.
+     *
+     * @param dst  result vector
+     *             constraints: 16-byte aligned
+     * @param src0 first source vector
+     *             constraints: 16-byte aligned
+     * @param src1 second source vector
+     *             constraints: 16-byte aligned
+     * @param win  half-window vector
+     *             constraints: 16-byte aligned
+     * @param len  length of vector
+     *             constraints: multiple of 4
+     */
+    void (*vector_fmul_window)(float *dst, const float *src0,
+                               const float *src1, const float *win, int len);
+
+    /**
+     * Calculate the product of two vectors of floats, add a third vector of
+     * floats and store the result in a vector of floats.
+     *
+     * @param dst  output vector
+     *             constraints: 32-byte aligned
+     * @param src0 first input vector
+     *             constraints: 32-byte aligned
+     * @param src1 second input vector
+     *             constraints: 32-byte aligned
+     * @param src1 third input vector
+     *             constraints: 32-byte aligned
+     * @param len  number of elements in the input
+     *             constraints: multiple of 16
+     */
+    void (*vector_fmul_add)(float *dst, const float *src0, const float *src1,
+                            const float *src2, int len);
+
+    /**
+     * Calculate the product of two vectors of floats, and store the result
+     * in a vector of floats. The second vector of floats is iterated over
+     * in reverse order.
+     *
+     * @param dst  output vector
+     *             constraints: 32-byte aligned
+     * @param src0 first input vector
+     *             constraints: 32-byte aligned
+     * @param src1 second input vector
+     *             constraints: 32-byte aligned
+     * @param src1 third input vector
+     *             constraints: 32-byte aligned
+     * @param len  number of elements in the input
+     *             constraints: multiple of 16
+     */
+    void (*vector_fmul_reverse)(float *dst, const float *src0,
+                                const float *src1, int len);
+
+    /**
+     * Calculate the sum and difference of two vectors of floats.
+     *
+     * @param v1  first input vector, sum output, 16-byte aligned
+     * @param v2  second input vector, difference output, 16-byte aligned
+     * @param len length of vectors, multiple of 4
+     */
+    void (*butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len);
+
+    /**
+     * Calculate the scalar product of two vectors of floats.
+     *
+     * @param v1  first vector, 16-byte aligned
+     * @param v2  second vector, 16-byte aligned
+     * @param len length of vectors, multiple of 4
+     *
+     * @return sum of elementwise products
+     */
+    float (*scalarproduct_float)(const float *v1, const float *v2, int len);
 } AVFloatDSPContext;
 
+/**
+ * Return the scalar product of two vectors.
+ *
+ * @param v1  first input vector
+ * @param v2  first input vector
+ * @param len number of elements
+ *
+ * @return sum of elementwise products
+ */
+float avpriv_scalarproduct_float_c(const float *v1, const float *v2, int len);
+
 /**
  * Initialize a float DSP context.
  *
diff --git a/mythtv/external/FFmpeg/libavutil/hmac.c b/mythtv/external/FFmpeg/libavutil/hmac.c
new file mode 100644
index 00000000000..e5f1434f9aa
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavutil/hmac.c
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2012 Martin Storsjo
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "hmac.h"
+#include "md5.h"
+#include "sha.h"
+#include "mem.h"
+
+#define MAX_HASHLEN 20
+#define MAX_BLOCKLEN 64
+
+struct AVHMAC {
+    void *hash;
+    int blocklen, hashlen;
+    void (*final)(void*, uint8_t*);
+    void (*update)(void*, const uint8_t*, int len);
+    void (*init)(void*);
+    uint8_t key[MAX_BLOCKLEN];
+    int keylen;
+};
+
+static void sha1_init(void *ctx)
+{
+    av_sha_init(ctx, 160);
+}
+
+AVHMAC *av_hmac_alloc(enum AVHMACType type)
+{
+    AVHMAC *c = av_mallocz(sizeof(*c));
+    if (!c)
+        return NULL;
+    switch (type) {
+    case AV_HMAC_MD5:
+        c->blocklen = 64;
+        c->hashlen  = 16;
+        c->init     = av_md5_init;
+        c->update   = av_md5_update;
+        c->final    = av_md5_final;
+        c->hash     = av_md5_alloc();
+        break;
+    case AV_HMAC_SHA1:
+        c->blocklen = 64;
+        c->hashlen  = 20;
+        c->init     = sha1_init;
+        c->update   = av_sha_update;
+        c->final    = av_sha_final;
+        c->hash     = av_sha_alloc();
+        break;
+    default:
+        av_free(c);
+        return NULL;
+    }
+    if (!c->hash) {
+        av_free(c);
+        return NULL;
+    }
+    return c;
+}
+
+void av_hmac_free(AVHMAC *c)
+{
+    if (!c)
+        return;
+    av_free(c->hash);
+    av_free(c);
+}
+
+void av_hmac_init(AVHMAC *c, const uint8_t *key, unsigned int keylen)
+{
+    int i;
+    uint8_t block[MAX_BLOCKLEN];
+    if (keylen > c->blocklen) {
+        c->init(c->hash);
+        c->update(c->hash, key, keylen);
+        c->final(c->hash, c->key);
+        c->keylen = c->hashlen;
+    } else {
+        memcpy(c->key, key, keylen);
+        c->keylen = keylen;
+    }
+    c->init(c->hash);
+    for (i = 0; i < c->keylen; i++)
+        block[i] = c->key[i] ^ 0x36;
+    for (i = c->keylen; i < c->blocklen; i++)
+        block[i] = 0x36;
+    c->update(c->hash, block, c->blocklen);
+}
+
+void av_hmac_update(AVHMAC *c, const uint8_t *data, unsigned int len)
+{
+    c->update(c->hash, data, len);
+}
+
+int av_hmac_final(AVHMAC *c, uint8_t *out, unsigned int outlen)
+{
+    uint8_t block[MAX_BLOCKLEN];
+    int i;
+    if (outlen < c->hashlen)
+        return AVERROR(EINVAL);
+    c->final(c->hash, out);
+    c->init(c->hash);
+    for (i = 0; i < c->keylen; i++)
+        block[i] = c->key[i] ^ 0x5C;
+    for (i = c->keylen; i < c->blocklen; i++)
+        block[i] = 0x5C;
+    c->update(c->hash, block, c->blocklen);
+    c->update(c->hash, out, c->hashlen);
+    c->final(c->hash, out);
+    return c->hashlen;
+}
+
+int av_hmac_calc(AVHMAC *c, const uint8_t *data, unsigned int len,
+                 const uint8_t *key, unsigned int keylen,
+                 uint8_t *out, unsigned int outlen)
+{
+    av_hmac_init(c, key, keylen);
+    av_hmac_update(c, data, len);
+    return av_hmac_final(c, out, outlen);
+}
+
+#ifdef TEST
+#include 
+
+static void test(AVHMAC *hmac, const uint8_t *key, int keylen,
+                 const uint8_t *data, int datalen)
+{
+    uint8_t buf[MAX_HASHLEN];
+    int out, i;
+    // Some of the test vectors are strings, where sizeof() includes the
+    // trailing null byte - remove that.
+    if (!key[keylen - 1])
+        keylen--;
+    if (!data[datalen - 1])
+        datalen--;
+    out = av_hmac_calc(hmac, data, datalen, key, keylen, buf, sizeof(buf));
+    for (i = 0; i < out; i++)
+        printf("%02x", buf[i]);
+    printf("\n");
+}
+
+int main(void)
+{
+    uint8_t key1[16], key3[16], data3[50], key4[63], key5[64], key6[65];
+    const uint8_t key2[]  = "Jefe";
+    const uint8_t data1[] = "Hi There";
+    const uint8_t data2[] = "what do ya want for nothing?";
+    AVHMAC *hmac = av_hmac_alloc(AV_HMAC_MD5);
+    if (!hmac)
+        return 1;
+    memset(key1, 0x0b, sizeof(key1));
+    memset(key3, 0xaa, sizeof(key3));
+    memset(key4, 0x44, sizeof(key4));
+    memset(key5, 0x55, sizeof(key5));
+    memset(key6, 0x66, sizeof(key6));
+    memset(data3, 0xdd, sizeof(data3));
+    // RFC 2104 test vectors
+    test(hmac, key1, sizeof(key1), data1, sizeof(data1));
+    test(hmac, key2, sizeof(key2), data2, sizeof(data2));
+    test(hmac, key3, sizeof(key3), data3, sizeof(data3));
+    // Additional tests, to test cases where the key is too long
+    test(hmac, key4, sizeof(key4), data1, sizeof(data1));
+    test(hmac, key5, sizeof(key5), data2, sizeof(data2));
+    test(hmac, key6, sizeof(key6), data3, sizeof(data3));
+    av_hmac_free(hmac);
+    return 0;
+}
+#endif /* TEST */
diff --git a/mythtv/external/FFmpeg/libavutil/hmac.h b/mythtv/external/FFmpeg/libavutil/hmac.h
new file mode 100644
index 00000000000..aef84c64398
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavutil/hmac.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2012 Martin Storsjo
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_HMAC_H
+#define AVUTIL_HMAC_H
+
+#include 
+
+/**
+ * @defgroup lavu_hmac HMAC
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+enum AVHMACType {
+    AV_HMAC_MD5,
+    AV_HMAC_SHA1,
+};
+
+typedef struct AVHMAC AVHMAC;
+
+/**
+ * Allocate an AVHMAC context.
+ * @param type The hash function used for the HMAC.
+ */
+AVHMAC *av_hmac_alloc(enum AVHMACType type);
+
+/**
+ * Free an AVHMAC context.
+ * @param ctx The context to free, may be NULL
+ */
+void av_hmac_free(AVHMAC *ctx);
+
+/**
+ * Initialize an AVHMAC context with an authentication key.
+ * @param ctx    The HMAC context
+ * @param key    The authentication key
+ * @param keylen The length of the key, in bytes
+ */
+void av_hmac_init(AVHMAC *ctx, const uint8_t *key, unsigned int keylen);
+
+/**
+ * Hash data with the HMAC.
+ * @param ctx  The HMAC context
+ * @param data The data to hash
+ * @param len  The length of the data, in bytes
+ */
+void av_hmac_update(AVHMAC *ctx, const uint8_t *data, unsigned int len);
+
+/**
+ * Finish hashing and output the HMAC digest.
+ * @param ctx    The HMAC context
+ * @param out    The output buffer to write the digest into
+ * @param outlen The length of the out buffer, in bytes
+ * @return       The number of bytes written to out, or a negative error code.
+ */
+int av_hmac_final(AVHMAC *ctx, uint8_t *out, unsigned int outlen);
+
+/**
+ * Hash an array of data with a key.
+ * @param ctx    The HMAC context
+ * @param data   The data to hash
+ * @param len    The length of the data, in bytes
+ * @param key    The authentication key
+ * @param keylen The length of the key, in bytes
+ * @param out    The output buffer to write the digest into
+ * @param outlen The length of the out buffer, in bytes
+ * @return       The number of bytes written to out, or a negative error code.
+ */
+int av_hmac_calc(AVHMAC *ctx, const uint8_t *data, unsigned int len,
+                 const uint8_t *key, unsigned int keylen,
+                 uint8_t *out, unsigned int outlen);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_HMAC_H */
diff --git a/mythtv/external/FFmpeg/libavutil/internal.h b/mythtv/external/FFmpeg/libavutil/internal.h
index 4400c5c4396..a105fe6b445 100644
--- a/mythtv/external/FFmpeg/libavutil/internal.h
+++ b/mythtv/external/FFmpeg/libavutil/internal.h
@@ -40,6 +40,14 @@
 #include "cpu.h"
 #include "dict.h"
 
+#if ARCH_X86
+#   include "x86/emms.h"
+#endif
+
+#ifndef emms_c
+#   define emms_c()
+#endif
+
 #ifndef attribute_align_arg
 #if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2)
 #    define attribute_align_arg __attribute__((force_align_arg_pointer))
@@ -58,6 +66,32 @@
 #    define INT_BIT (CHAR_BIT * sizeof(int))
 #endif
 
+// Some broken preprocessors need a second expansion
+// to be forced to tokenize __VA_ARGS__
+#define E1(x) x
+
+#define LOCAL_ALIGNED_A(a, t, v, s, o, ...)             \
+    uint8_t la_##v[sizeof(t s o) + (a)];                \
+    t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a)
+
+#define LOCAL_ALIGNED_D(a, t, v, s, o, ...)             \
+    DECLARE_ALIGNED(a, t, la_##v) s o;                  \
+    t (*v) o = la_##v
+
+#define LOCAL_ALIGNED(a, t, v, ...) E1(LOCAL_ALIGNED_A(a, t, v, __VA_ARGS__,,))
+
+#if HAVE_LOCAL_ALIGNED_8
+#   define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,))
+#else
+#   define LOCAL_ALIGNED_8(t, v, ...) LOCAL_ALIGNED(8, t, v, __VA_ARGS__)
+#endif
+
+#if HAVE_LOCAL_ALIGNED_16
+#   define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,))
+#else
+#   define LOCAL_ALIGNED_16(t, v, ...) LOCAL_ALIGNED(16, t, v, __VA_ARGS__)
+#endif
+
 #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
 {\
     p = av_malloc(size);\
@@ -128,22 +162,4 @@
 #   define ONLY_IF_THREADS_ENABLED(x) NULL
 #endif
 
-#if HAVE_MMX_INLINE
-/**
- * Empty mmx state.
- * this must be called between any dsp function and float/double code.
- * for example sin(); dsp->idct_put(); emms_c(); cos()
- */
-static av_always_inline void emms_c(void)
-{
-    if(av_get_cpu_flags() & AV_CPU_FLAG_MMX)
-        __asm__ volatile ("emms" ::: "memory");
-}
-#elif HAVE_MMX && HAVE_MM_EMPTY
-#   include 
-#   define emms_c _mm_empty
-#else
-#   define emms_c()
-#endif /* HAVE_MMX_INLINE */
-
 #endif /* AVUTIL_INTERNAL_H */
diff --git a/mythtv/external/FFmpeg/libavutil/intfloat_readwrite.c b/mythtv/external/FFmpeg/libavutil/intfloat_readwrite.c
index 2998229e494..142331dac10 100644
--- a/mythtv/external/FFmpeg/libavutil/intfloat_readwrite.c
+++ b/mythtv/external/FFmpeg/libavutil/intfloat_readwrite.c
@@ -26,6 +26,7 @@
  */
 
 #include 
+#include "common.h"
 #include "mathematics.h"
 #include "intfloat_readwrite.h"
 
@@ -88,7 +89,7 @@ AVExtFloat av_dbl2ext(double d){
             ext.mantissa[i] = m>>(56-(i<<3));
     } else if (f != 0.0) {
         ext.exponent[0] = 0x7f; ext.exponent[1] = 0xff;
-        if (f != INFINITY)
+        if (!isinf(f))
             ext.mantissa[0] = ~0;
     }
     if (d < 0)
diff --git a/mythtv/external/FFmpeg/libavutil/intreadwrite.h b/mythtv/external/FFmpeg/libavutil/intreadwrite.h
index 34e21d42fa4..7ee69775547 100644
--- a/mythtv/external/FFmpeg/libavutil/intreadwrite.h
+++ b/mythtv/external/FFmpeg/libavutil/intreadwrite.h
@@ -47,7 +47,7 @@ typedef union {
 
 /*
  * Arch-specific headers can provide any combination of
- * AV_[RW][BLN](16|24|32|64) and AV_(COPY|SWAP|ZERO)(64|128) macros.
+ * AV_[RW][BLN](16|24|32|48|64) and AV_(COPY|SWAP|ZERO)(64|128) macros.
  * Preprocessor symbols must be defined, even if these are implemented
  * as inline functions.
  */
@@ -114,6 +114,18 @@ typedef union {
 #       define AV_WN32(p, v) AV_WB32(p, v)
 #   endif
 
+#   if    defined(AV_RN48) && !defined(AV_RB48)
+#       define AV_RB48(p) AV_RN48(p)
+#   elif !defined(AV_RN48) &&  defined(AV_RB48)
+#       define AV_RN48(p) AV_RB48(p)
+#   endif
+
+#   if    defined(AV_WN48) && !defined(AV_WB48)
+#       define AV_WB48(p, v) AV_WN48(p, v)
+#   elif !defined(AV_WN48) &&  defined(AV_WB48)
+#       define AV_WN48(p, v) AV_WB48(p, v)
+#   endif
+
 #   if    defined(AV_RN64) && !defined(AV_RB64)
 #       define AV_RB64(p) AV_RN64(p)
 #   elif !defined(AV_RN64) &&  defined(AV_RB64)
@@ -164,6 +176,18 @@ typedef union {
 #       define AV_WN32(p, v) AV_WL32(p, v)
 #   endif
 
+#   if    defined(AV_RN48) && !defined(AV_RL48)
+#       define AV_RL48(p) AV_RN48(p)
+#   elif !defined(AV_RN48) &&  defined(AV_RL48)
+#       define AV_RN48(p) AV_RL48(p)
+#   endif
+
+#   if    defined(AV_WN48) && !defined(AV_WL48)
+#       define AV_WL48(p, v) AV_WN48(p, v)
+#   elif !defined(AV_WN48) &&  defined(AV_WL48)
+#       define AV_WN48(p, v) AV_WL48(p, v)
+#   endif
+
 #   if    defined(AV_RN64) && !defined(AV_RL64)
 #       define AV_RL64(p) AV_RN64(p)
 #   elif !defined(AV_RN64) &&  defined(AV_RL64)
@@ -436,6 +460,48 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
     } while(0)
 #endif
 
+#ifndef AV_RB48
+#   define AV_RB48(x)                                     \
+    (((uint64_t)((const uint8_t*)(x))[0] << 40) |         \
+     ((uint64_t)((const uint8_t*)(x))[1] << 32) |         \
+     ((uint64_t)((const uint8_t*)(x))[2] << 24) |         \
+     ((uint64_t)((const uint8_t*)(x))[3] << 16) |         \
+     ((uint64_t)((const uint8_t*)(x))[4] <<  8) |         \
+      (uint64_t)((const uint8_t*)(x))[5])
+#endif
+#ifndef AV_WB48
+#   define AV_WB48(p, darg) do {                \
+        uint64_t d = (darg);                    \
+        ((uint8_t*)(p))[5] = (d);               \
+        ((uint8_t*)(p))[4] = (d)>>8;            \
+        ((uint8_t*)(p))[3] = (d)>>16;           \
+        ((uint8_t*)(p))[2] = (d)>>24;           \
+        ((uint8_t*)(p))[1] = (d)>>32;           \
+        ((uint8_t*)(p))[0] = (d)>>40;           \
+    } while(0)
+#endif
+
+#ifndef AV_RL48
+#   define AV_RL48(x)                                     \
+    (((uint64_t)((const uint8_t*)(x))[5] << 40) |         \
+     ((uint64_t)((const uint8_t*)(x))[4] << 32) |         \
+     ((uint64_t)((const uint8_t*)(x))[3] << 24) |         \
+     ((uint64_t)((const uint8_t*)(x))[2] << 16) |         \
+     ((uint64_t)((const uint8_t*)(x))[1] <<  8) |         \
+      (uint64_t)((const uint8_t*)(x))[0])
+#endif
+#ifndef AV_WL48
+#   define AV_WL48(p, darg) do {                \
+        uint64_t d = (darg);                    \
+        ((uint8_t*)(p))[0] = (d);               \
+        ((uint8_t*)(p))[1] = (d)>>8;            \
+        ((uint8_t*)(p))[2] = (d)>>16;           \
+        ((uint8_t*)(p))[3] = (d)>>24;           \
+        ((uint8_t*)(p))[4] = (d)>>32;           \
+        ((uint8_t*)(p))[5] = (d)>>40;           \
+    } while(0)
+#endif
+
 /*
  * The AV_[RW]NA macros access naturally aligned data
  * in a type-safe way.
diff --git a/mythtv/external/FFmpeg/libavutil/libm.h b/mythtv/external/FFmpeg/libavutil/libm.h
index bfcc21c5daf..6c17b287b45 100644
--- a/mythtv/external/FFmpeg/libavutil/libm.h
+++ b/mythtv/external/FFmpeg/libavutil/libm.h
@@ -48,6 +48,13 @@
 #define powf(x, y) ((float)pow(x, y))
 #endif
 
+#if !HAVE_CBRT
+static av_always_inline double cbrt(double x)
+{
+    return x < 0 ? -pow(-x, 1.0 / 3.0) : pow(x, 1.0 / 3.0);
+}
+#endif
+
 #if !HAVE_CBRTF
 static av_always_inline float cbrtf(float x)
 {
diff --git a/mythtv/external/FFmpeg/libavutil/lls.c b/mythtv/external/FFmpeg/libavutil/lls.c
index dcefc2cbad8..a27c7ae8ba0 100644
--- a/mythtv/external/FFmpeg/libavutil/lls.c
+++ b/mythtv/external/FFmpeg/libavutil/lls.c
@@ -28,15 +28,16 @@
 #include 
 #include 
 
+#include "version.h"
 #include "lls.h"
 
-void av_init_lls(LLSModel *m, int indep_count)
+void avpriv_init_lls(LLSModel *m, int indep_count)
 {
     memset(m, 0, sizeof(LLSModel));
     m->indep_count = indep_count;
 }
 
-void av_update_lls(LLSModel *m, double *var, double decay)
+void avpriv_update_lls(LLSModel *m, double *var, double decay)
 {
     int i, j;
 
@@ -48,7 +49,7 @@ void av_update_lls(LLSModel *m, double *var, double decay)
     }
 }
 
-void av_solve_lls(LLSModel *m, double threshold, int min_order)
+void avpriv_solve_lls(LLSModel *m, double threshold, unsigned short min_order)
 {
     int i, j, k;
     double (*factor)[MAX_VARS + 1] = (void *) &m->covariance[1][0];
@@ -105,7 +106,7 @@ void av_solve_lls(LLSModel *m, double threshold, int min_order)
     }
 }
 
-double av_evaluate_lls(LLSModel *m, double *param, int order)
+double avpriv_evaluate_lls(LLSModel *m, double *param, int order)
 {
     int i;
     double out = 0;
@@ -116,6 +117,25 @@ double av_evaluate_lls(LLSModel *m, double *param, int order)
     return out;
 }
 
+#if FF_API_LLS_PRIVATE
+void av_init_lls(LLSModel *m, int indep_count)
+{
+    avpriv_init_lls(m, indep_count);
+}
+void av_update_lls(LLSModel *m, double *param, double decay)
+{
+    avpriv_update_lls(m, param, decay);
+}
+void av_solve_lls(LLSModel *m, double threshold, int min_order)
+{
+    avpriv_solve_lls(m, threshold, min_order);
+}
+double av_evaluate_lls(LLSModel *m, double *param, int order)
+{
+    return avpriv_evaluate_lls(m, param, order);
+}
+#endif /* FF_API_LLS_PRIVATE */
+
 #ifdef TEST
 
 #include 
@@ -129,7 +149,7 @@ int main(void)
     AVLFG lfg;
 
     av_lfg_init(&lfg, 1);
-    av_init_lls(&m, 3);
+    avpriv_init_lls(&m, 3);
 
     for (i = 0; i < 100; i++) {
         double var[4];
@@ -139,10 +159,10 @@ int main(void)
         var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
         var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
         var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
-        av_update_lls(&m, var, 0.99);
-        av_solve_lls(&m, 0.001, 0);
+        avpriv_update_lls(&m, var, 0.99);
+        avpriv_solve_lls(&m, 0.001, 0);
         for (order = 0; order < 3; order++) {
-            eval = av_evaluate_lls(&m, var + 1, order);
+            eval = avpriv_evaluate_lls(&m, var + 1, order);
             printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
                    var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
                    m.coeff[order][0], m.coeff[order][1],
diff --git a/mythtv/external/FFmpeg/libavutil/lls.h b/mythtv/external/FFmpeg/libavutil/lls.h
index d168e597492..c785d44421b 100644
--- a/mythtv/external/FFmpeg/libavutil/lls.h
+++ b/mythtv/external/FFmpeg/libavutil/lls.h
@@ -23,6 +23,8 @@
 #ifndef AVUTIL_LLS_H
 #define AVUTIL_LLS_H
 
+#include "version.h"
+
 #define MAX_VARS 32
 
 //FIXME avoid direct access to LLSModel from outside
@@ -30,16 +32,23 @@
 /**
  * Linear least squares model.
  */
-typedef struct LLSModel{
-    double covariance[MAX_VARS+1][MAX_VARS+1];
+typedef struct LLSModel {
+    double covariance[MAX_VARS + 1][MAX_VARS + 1];
     double coeff[MAX_VARS][MAX_VARS];
     double variance[MAX_VARS];
     int indep_count;
-}LLSModel;
+} LLSModel;
+
+void avpriv_init_lls(LLSModel *m, int indep_count);
+void avpriv_update_lls(LLSModel *m, double *param, double decay);
+void avpriv_solve_lls(LLSModel *m, double threshold, unsigned short min_order);
+double avpriv_evaluate_lls(LLSModel *m, double *param, int order);
 
+#if FF_API_LLS_PRIVATE
 void av_init_lls(LLSModel *m, int indep_count);
 void av_update_lls(LLSModel *m, double *param, double decay);
 void av_solve_lls(LLSModel *m, double threshold, int min_order);
 double av_evaluate_lls(LLSModel *m, double *param, int order);
+#endif /* FF_API_LLS_PRIVATE */
 
 #endif /* AVUTIL_LLS_H */
diff --git a/mythtv/external/FFmpeg/libavutil/log.c b/mythtv/external/FFmpeg/libavutil/log.c
index 700e89fa977..49dd4d18973 100644
--- a/mythtv/external/FFmpeg/libavutil/log.c
+++ b/mythtv/external/FFmpeg/libavutil/log.c
@@ -178,7 +178,7 @@ static void format_line(void *ptr, int level, const char *fmt, va_list vl,
             if (parent && *parent) {
                 snprintf(part[0], part_size, "[%s @ %p] ",
                          (*parent)->item_name(parent), parent);
-                if(type) type[0] = get_category(((uint8_t *) ptr) + avc->parent_log_context_offset);
+                if(type) type[0] = get_category(parent);
             }
         }
         snprintf(part[1], part_size, "[%s @ %p] ",
diff --git a/mythtv/external/FFmpeg/libavutil/lzo.c b/mythtv/external/FFmpeg/libavutil/lzo.c
index 221a66b9ab9..c7232572122 100644
--- a/mythtv/external/FFmpeg/libavutil/lzo.c
+++ b/mythtv/external/FFmpeg/libavutil/lzo.c
@@ -110,8 +110,9 @@ static inline void copy(LZOContext *c, int cnt)
  */
 static inline void copy_backptr(LZOContext *c, int back, int cnt)
 {
+    register const uint8_t *src = &c->out[-back];
     register uint8_t *dst       = c->out;
-    if (dst - c->out_start < back) {
+    if (src < c->out_start || src > dst) {
         c->error |= AV_LZO_INVALID_BACKPTR;
         return;
     }
diff --git a/mythtv/external/FFmpeg/libavutil/mem.c b/mythtv/external/FFmpeg/libavutil/mem.c
index 250b5f745ef..860c0111eb5 100644
--- a/mythtv/external/FFmpeg/libavutil/mem.c
+++ b/mythtv/external/FFmpeg/libavutil/mem.c
@@ -36,6 +36,7 @@
 #include 
 #endif
 
+#include "avassert.h"
 #include "avutil.h"
 #include "intreadwrite.h"
 #include "mem.h"
@@ -94,7 +95,11 @@ void *av_malloc(size_t size)
 #elif HAVE_ALIGNED_MALLOC
     ptr = _aligned_malloc(size, ALIGN);
 #elif HAVE_MEMALIGN
+#ifndef __DJGPP__
     ptr = memalign(ALIGN, size);
+#else
+    ptr = memalign(size, ALIGN);
+#endif
     /* Why 64?
      * Indeed, we should align it:
      *   on  4 for 386
@@ -148,6 +153,7 @@ void *av_realloc(void *ptr, size_t size)
     if (!ptr)
         return av_malloc(size);
     diff = ((char *)ptr)[-1];
+    av_assert0(diff>0 && diff<=ALIGN);
     ptr = realloc((char *)ptr - diff, size + diff);
     if (ptr)
         ptr = (char *)ptr + diff;
@@ -177,8 +183,11 @@ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
 void av_free(void *ptr)
 {
 #if CONFIG_MEMALIGN_HACK
-    if (ptr)
-        free((char *)ptr - ((char *)ptr)[-1]);
+    if (ptr) {
+        int v= ((char *)ptr)[-1];
+        av_assert0(v>0 && v<=ALIGN);
+        free((char *)ptr - v);
+    }
 #elif HAVE_ALIGNED_MALLOC
     _aligned_free(ptr);
 #else
@@ -318,7 +327,10 @@ static void fill32(uint8_t *dst, int len)
 void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
 {
     const uint8_t *src = &dst[-back];
-    if (back <= 1) {
+    if (!back)
+        return;
+
+    if (back == 1) {
         memset(dst, *src, cnt);
     } else if (back == 2) {
         fill16(dst, cnt);
diff --git a/mythtv/external/FFmpeg/libavutil/mips/float_dsp_mips.c b/mythtv/external/FFmpeg/libavutil/mips/float_dsp_mips.c
index 8c3611d963d..06d52dc2581 100644
--- a/mythtv/external/FFmpeg/libavutil/mips/float_dsp_mips.c
+++ b/mythtv/external/FFmpeg/libavutil/mips/float_dsp_mips.c
@@ -27,6 +27,7 @@
  * SUCH DAMAGE.
  *
  * Author:  Branimir Vasic (bvasic@mips.com)
+ * Author:  Zoran Lukic (zoranl@mips.com)
  *
  * This file is part of FFmpeg.
  *
@@ -104,10 +105,279 @@ static void vector_fmul_mips(float *dst, const float *src0, const float *src1,
         );
     }
 }
+
+static void vector_fmul_scalar_mips(float *dst, const float *src, float mul,
+                                 int len)
+{
+    float temp0, temp1, temp2, temp3;
+    float *local_src = (float*)src;
+    float *end = local_src + len;
+
+    /* loop unrolled 4 times */
+    __asm__ volatile(
+        ".set    push                             \n\t"
+        ".set    noreorder                        \n\t"
+    "1:                                           \n\t"
+        "lwc1    %[temp0],   0(%[src])            \n\t"
+        "lwc1    %[temp1],   4(%[src])            \n\t"
+        "lwc1    %[temp2],   8(%[src])            \n\t"
+        "lwc1    %[temp3],   12(%[src])           \n\t"
+        "addiu   %[dst],     %[dst],     16       \n\t"
+        "mul.s   %[temp0],   %[temp0],   %[mul]   \n\t"
+        "mul.s   %[temp1],   %[temp1],   %[mul]   \n\t"
+        "mul.s   %[temp2],   %[temp2],   %[mul]   \n\t"
+        "mul.s   %[temp3],   %[temp3],   %[mul]   \n\t"
+        "addiu   %[src],     %[src],     16       \n\t"
+        "swc1    %[temp0],   -16(%[dst])          \n\t"
+        "swc1    %[temp1],   -12(%[dst])          \n\t"
+        "swc1    %[temp2],   -8(%[dst])           \n\t"
+        "bne     %[src],     %[end],     1b       \n\t"
+        " swc1   %[temp3],   -4(%[dst])           \n\t"
+        ".set    pop                              \n\t"
+
+        : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1),
+          [temp2]"=&f"(temp2), [temp3]"=&f"(temp3),
+          [dst]"+r"(dst), [src]"+r"(local_src)
+        : [end]"r"(end), [mul]"f"(mul)
+        : "memory"
+    );
+}
+
+static void vector_fmul_window_mips(float *dst, const float *src0,
+        const float *src1, const float *win, int len)
+{
+    int i, j;
+    /*
+     * variables used in inline assembler
+     */
+    float * dst_i, * dst_j, * dst_i2, * dst_j2;
+    float temp, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
+
+    dst  += len;
+    win  += len;
+    src0 += len;
+
+    for (i = -len, j = len - 1; i < 0; i += 8, j -= 8) {
+
+        dst_i = dst + i;
+        dst_j = dst + j;
+
+        dst_i2 = dst + i + 4;
+        dst_j2 = dst + j - 4;
+
+        __asm__ volatile (
+            "mul.s   %[temp],   %[s1],       %[wi]            \n\t"
+            "mul.s   %[temp1],  %[s1],       %[wj]            \n\t"
+            "mul.s   %[temp2],  %[s11],      %[wi1]           \n\t"
+            "mul.s   %[temp3],  %[s11],      %[wj1]           \n\t"
+
+            "msub.s  %[temp],   %[temp],     %[s0],  %[wj]    \n\t"
+            "madd.s  %[temp1],  %[temp1],    %[s0],  %[wi]    \n\t"
+            "msub.s  %[temp2],  %[temp2],    %[s01], %[wj1]   \n\t"
+            "madd.s  %[temp3],  %[temp3],    %[s01], %[wi1]   \n\t"
+
+            "swc1    %[temp],   0(%[dst_i])                   \n\t" /* dst[i] = s0*wj - s1*wi; */
+            "swc1    %[temp1],  0(%[dst_j])                   \n\t" /* dst[j] = s0*wi + s1*wj; */
+            "swc1    %[temp2],  4(%[dst_i])                   \n\t" /* dst[i+1] = s01*wj1 - s11*wi1; */
+            "swc1    %[temp3], -4(%[dst_j])                   \n\t" /* dst[j-1] = s01*wi1 + s11*wj1; */
+
+            "mul.s   %[temp4],  %[s12],      %[wi2]           \n\t"
+            "mul.s   %[temp5],  %[s12],      %[wj2]           \n\t"
+            "mul.s   %[temp6],  %[s13],      %[wi3]           \n\t"
+            "mul.s   %[temp7],  %[s13],      %[wj3]           \n\t"
+
+            "msub.s  %[temp4],  %[temp4],    %[s02], %[wj2]   \n\t"
+            "madd.s  %[temp5],  %[temp5],    %[s02], %[wi2]   \n\t"
+            "msub.s  %[temp6],  %[temp6],    %[s03], %[wj3]   \n\t"
+            "madd.s  %[temp7],  %[temp7],    %[s03], %[wi3]   \n\t"
+
+            "swc1    %[temp4],  8(%[dst_i])                   \n\t" /* dst[i+2] = s02*wj2 - s12*wi2; */
+            "swc1    %[temp5], -8(%[dst_j])                   \n\t" /* dst[j-2] = s02*wi2 + s12*wj2; */
+            "swc1    %[temp6],  12(%[dst_i])                  \n\t" /* dst[i+2] = s03*wj3 - s13*wi3; */
+            "swc1    %[temp7], -12(%[dst_j])                  \n\t" /* dst[j-3] = s03*wi3 + s13*wj3; */
+            : [temp]"=&f"(temp),  [temp1]"=&f"(temp1), [temp2]"=&f"(temp2),
+              [temp3]"=&f"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5),
+              [temp6]"=&f"(temp6), [temp7]"=&f"(temp7)
+            : [dst_j]"r"(dst_j),     [dst_i]"r" (dst_i),
+              [s0] "f"(src0[i]),     [wj] "f"(win[j]),     [s1] "f"(src1[j]),
+              [wi] "f"(win[i]),      [s01]"f"(src0[i + 1]),[wj1]"f"(win[j - 1]),
+              [s11]"f"(src1[j - 1]), [wi1]"f"(win[i + 1]), [s02]"f"(src0[i + 2]),
+              [wj2]"f"(win[j - 2]),  [s12]"f"(src1[j - 2]),[wi2]"f"(win[i + 2]),
+              [s03]"f"(src0[i + 3]), [wj3]"f"(win[j - 3]), [s13]"f"(src1[j - 3]),
+              [wi3]"f"(win[i + 3])
+            : "memory"
+        );
+
+        __asm__ volatile (
+            "mul.s  %[temp],   %[s1],       %[wi]            \n\t"
+            "mul.s  %[temp1],  %[s1],       %[wj]            \n\t"
+            "mul.s  %[temp2],  %[s11],      %[wi1]           \n\t"
+            "mul.s  %[temp3],  %[s11],      %[wj1]           \n\t"
+
+            "msub.s %[temp],   %[temp],     %[s0],  %[wj]    \n\t"
+            "madd.s %[temp1],  %[temp1],    %[s0],  %[wi]    \n\t"
+            "msub.s %[temp2],  %[temp2],    %[s01], %[wj1]   \n\t"
+            "madd.s %[temp3],  %[temp3],    %[s01], %[wi1]   \n\t"
+
+            "swc1   %[temp],   0(%[dst_i2])                  \n\t" /* dst[i] = s0*wj - s1*wi; */
+            "swc1   %[temp1],  0(%[dst_j2])                  \n\t" /* dst[j] = s0*wi + s1*wj; */
+            "swc1   %[temp2],  4(%[dst_i2])                  \n\t" /* dst[i+1] = s01*wj1 - s11*wi1; */
+            "swc1   %[temp3], -4(%[dst_j2])                  \n\t" /* dst[j-1] = s01*wi1 + s11*wj1; */
+
+            "mul.s  %[temp4],  %[s12],      %[wi2]           \n\t"
+            "mul.s  %[temp5],  %[s12],      %[wj2]           \n\t"
+            "mul.s  %[temp6],  %[s13],      %[wi3]           \n\t"
+            "mul.s  %[temp7],  %[s13],      %[wj3]           \n\t"
+
+            "msub.s %[temp4],  %[temp4],    %[s02], %[wj2]   \n\t"
+            "madd.s %[temp5],  %[temp5],    %[s02], %[wi2]   \n\t"
+            "msub.s %[temp6],  %[temp6],    %[s03], %[wj3]   \n\t"
+            "madd.s %[temp7],  %[temp7],    %[s03], %[wi3]   \n\t"
+
+            "swc1   %[temp4],  8(%[dst_i2])                  \n\t" /* dst[i+2] = s02*wj2 - s12*wi2; */
+            "swc1   %[temp5], -8(%[dst_j2])                  \n\t" /* dst[j-2] = s02*wi2 + s12*wj2; */
+            "swc1   %[temp6],  12(%[dst_i2])                 \n\t" /* dst[i+2] = s03*wj3 - s13*wi3; */
+            "swc1   %[temp7], -12(%[dst_j2])                 \n\t" /* dst[j-3] = s03*wi3 + s13*wj3; */
+            : [temp]"=&f"(temp),
+              [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), [temp3]"=&f"(temp3),
+              [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), [temp6]"=&f"(temp6),
+              [temp7]  "=&f" (temp7)
+            : [dst_j2]"r"(dst_j2),   [dst_i2]"r"(dst_i2),
+              [s0] "f"(src0[i + 4]), [wj] "f"(win[j - 4]), [s1] "f"(src1[j - 4]),
+              [wi] "f"(win[i + 4]),  [s01]"f"(src0[i + 5]),[wj1]"f"(win[j - 5]),
+              [s11]"f"(src1[j - 5]), [wi1]"f"(win[i + 5]), [s02]"f"(src0[i + 6]),
+              [wj2]"f"(win[j - 6]),  [s12]"f"(src1[j - 6]),[wi2]"f"(win[i + 6]),
+              [s03]"f"(src0[i + 7]), [wj3]"f"(win[j - 7]), [s13]"f"(src1[j - 7]),
+              [wi3]"f"(win[i + 7])
+            : "memory"
+        );
+    }
+}
+
+static void butterflies_float_mips(float *av_restrict v1, float *av_restrict v2,
+                                int len)
+{
+    float temp0, temp1, temp2, temp3, temp4;
+    float temp5, temp6, temp7, temp8, temp9;
+    float temp10, temp11, temp12, temp13, temp14, temp15;
+    int pom;
+    pom = (len >> 2)-1;
+
+    /* loop unrolled 4 times */
+    __asm__ volatile (
+        "lwc1     %[temp0],    0(%[v1])                 \n\t"
+        "lwc1     %[temp1],    4(%[v1])                 \n\t"
+        "lwc1     %[temp2],    8(%[v1])                 \n\t"
+        "lwc1     %[temp3],    12(%[v1])                \n\t"
+        "lwc1     %[temp4],    0(%[v2])                 \n\t"
+        "lwc1     %[temp5],    4(%[v2])                 \n\t"
+        "lwc1     %[temp6],    8(%[v2])                 \n\t"
+        "lwc1     %[temp7],    12(%[v2])                \n\t"
+        "beq      %[pom],      $zero,       2f          \n\t"
+    "1:                                                 \n\t"
+        "sub.s    %[temp8],    %[temp0],    %[temp4]    \n\t"
+        "add.s    %[temp9],    %[temp0],    %[temp4]    \n\t"
+        "sub.s    %[temp10],   %[temp1],    %[temp5]    \n\t"
+        "add.s    %[temp11],   %[temp1],    %[temp5]    \n\t"
+        "sub.s    %[temp12],   %[temp2],    %[temp6]    \n\t"
+        "add.s    %[temp13],   %[temp2],    %[temp6]    \n\t"
+        "sub.s    %[temp14],   %[temp3],    %[temp7]    \n\t"
+        "add.s    %[temp15],   %[temp3],    %[temp7]    \n\t"
+        "addiu    %[v1],       %[v1],       16          \n\t"
+        "addiu    %[v2],       %[v2],       16          \n\t"
+        "addiu    %[pom],      %[pom],      -1          \n\t"
+        "lwc1     %[temp0],    0(%[v1])                 \n\t"
+        "lwc1     %[temp1],    4(%[v1])                 \n\t"
+        "lwc1     %[temp2],    8(%[v1])                 \n\t"
+        "lwc1     %[temp3],    12(%[v1])                \n\t"
+        "lwc1     %[temp4],    0(%[v2])                 \n\t"
+        "lwc1     %[temp5],    4(%[v2])                 \n\t"
+        "lwc1     %[temp6],    8(%[v2])                 \n\t"
+        "lwc1     %[temp7],    12(%[v2])                \n\t"
+        "swc1     %[temp9],    -16(%[v1])               \n\t"
+        "swc1     %[temp8],    -16(%[v2])               \n\t"
+        "swc1     %[temp11],   -12(%[v1])               \n\t"
+        "swc1     %[temp10],   -12(%[v2])               \n\t"
+        "swc1     %[temp13],   -8(%[v1])                \n\t"
+        "swc1     %[temp12],   -8(%[v2])                \n\t"
+        "swc1     %[temp15],   -4(%[v1])                \n\t"
+        "swc1     %[temp14],   -4(%[v2])                \n\t"
+        "bgtz     %[pom],      1b                       \n\t"
+    "2:                                                 \n\t"
+        "sub.s    %[temp8],    %[temp0],    %[temp4]    \n\t"
+        "add.s    %[temp9],    %[temp0],    %[temp4]    \n\t"
+        "sub.s    %[temp10],   %[temp1],    %[temp5]    \n\t"
+        "add.s    %[temp11],   %[temp1],    %[temp5]    \n\t"
+        "sub.s    %[temp12],   %[temp2],    %[temp6]    \n\t"
+        "add.s    %[temp13],   %[temp2],    %[temp6]    \n\t"
+        "sub.s    %[temp14],   %[temp3],    %[temp7]    \n\t"
+        "add.s    %[temp15],   %[temp3],    %[temp7]    \n\t"
+        "swc1     %[temp9],    0(%[v1])                 \n\t"
+        "swc1     %[temp8],    0(%[v2])                 \n\t"
+        "swc1     %[temp11],   4(%[v1])                 \n\t"
+        "swc1     %[temp10],   4(%[v2])                 \n\t"
+        "swc1     %[temp13],   8(%[v1])                 \n\t"
+        "swc1     %[temp12],   8(%[v2])                 \n\t"
+        "swc1     %[temp15],   12(%[v1])                \n\t"
+        "swc1     %[temp14],   12(%[v2])                \n\t"
+
+        : [v1]"+r"(v1), [v2]"+r"(v2), [pom]"+r"(pom), [temp0] "=&f" (temp0),
+          [temp1]"=&f"(temp1), [temp2]"=&f"(temp2), [temp3]"=&f"(temp3),
+          [temp4]"=&f"(temp4), [temp5]"=&f"(temp5), [temp6]"=&f"(temp6),
+          [temp7]"=&f"(temp7), [temp8]"=&f"(temp8), [temp9]"=&f"(temp9),
+          [temp10]"=&f"(temp10), [temp11]"=&f"(temp11), [temp12]"=&f"(temp12),
+          [temp13]"=&f"(temp13), [temp14]"=&f"(temp14), [temp15]"=&f"(temp15)
+        :
+        : "memory"
+    );
+}
+
+static void vector_fmul_reverse_mips(float *dst, const float *src0, const float *src1, int len){
+    int i;
+    float temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
+    src1 += len-1;
+
+    for(i=0; i<(len>>2); i++)
+    {
+        /* loop unrolled 4 times */
+        __asm__ volatile(
+            "lwc1      %[temp0],     0(%[src0])                 \n\t"
+            "lwc1      %[temp1],     0(%[src1])                 \n\t"
+            "lwc1      %[temp2],     4(%[src0])                 \n\t"
+            "lwc1      %[temp3],     -4(%[src1])                \n\t"
+            "lwc1      %[temp4],     8(%[src0])                 \n\t"
+            "lwc1      %[temp5],     -8(%[src1])                \n\t"
+            "lwc1      %[temp6],     12(%[src0])                \n\t"
+            "lwc1      %[temp7],     -12(%[src1])               \n\t"
+            "mul.s     %[temp0],     %[temp1],     %[temp0]     \n\t"
+            "mul.s     %[temp2],     %[temp3],     %[temp2]     \n\t"
+            "mul.s     %[temp4],     %[temp5],     %[temp4]     \n\t"
+            "mul.s     %[temp6],     %[temp7],     %[temp6]     \n\t"
+            "addiu     %[src0],      %[src0],      16           \n\t"
+            "addiu     %[src1],      %[src1],      -16          \n\t"
+            "addiu     %[dst],       %[dst],       16           \n\t"
+            "swc1      %[temp0],     -16(%[dst])                \n\t"
+            "swc1      %[temp2],     -12(%[dst])                \n\t"
+            "swc1      %[temp4],     -8(%[dst])                 \n\t"
+            "swc1      %[temp6],     -4(%[dst])                 \n\t"
+
+            : [dst]"+r"(dst), [src0]"+r"(src0), [src1]"+r"(src1),
+              [temp0]"=&f"(temp0), [temp1]"=&f"(temp1),[temp2]"=&f"(temp2),
+              [temp3]"=&f"(temp3), [temp4]"=&f"(temp4), [temp5]"=&f"(temp5),
+              [temp6]"=&f"(temp6), [temp7]"=&f"(temp7)
+            :
+            : "memory"
+        );
+    }
+}
 #endif /* HAVE_INLINE_ASM && HAVE_MIPSFPU */
 
 void ff_float_dsp_init_mips(AVFloatDSPContext *fdsp) {
 #if HAVE_INLINE_ASM && HAVE_MIPSFPU
     fdsp->vector_fmul = vector_fmul_mips;
+    fdsp->vector_fmul_scalar  = vector_fmul_scalar_mips;
+    fdsp->vector_fmul_window = vector_fmul_window_mips;
+    fdsp->butterflies_float = butterflies_float_mips;
+    fdsp->vector_fmul_reverse = vector_fmul_reverse_mips;
 #endif /* HAVE_INLINE_ASM && HAVE_MIPSFPU */
 }
diff --git a/mythtv/external/FFmpeg/libavutil/opt.c b/mythtv/external/FFmpeg/libavutil/opt.c
index 61c76daa6ed..f91d18b198f 100644
--- a/mythtv/external/FFmpeg/libavutil/opt.c
+++ b/mythtv/external/FFmpeg/libavutil/opt.c
@@ -1322,8 +1322,8 @@ typedef struct TestContext
 static const AVOption test_options[]= {
 {"num",      "set num",        OFFSET(num),      AV_OPT_TYPE_INT,      {.i64 = 0},       0,        100                 },
 {"toggle",   "set toggle",     OFFSET(toggle),   AV_OPT_TYPE_INT,      {.i64 = 0},       0,        1                   },
-{"rational", "set rational",   OFFSET(rational), AV_OPT_TYPE_RATIONAL, {.dbl = 0},  0,        10                  },
-{"string",   "set string",     OFFSET(string),   AV_OPT_TYPE_STRING,   {0},              CHAR_MIN, CHAR_MAX            },
+{"rational", "set rational",   OFFSET(rational), AV_OPT_TYPE_RATIONAL, {.dbl = 0},       0,        10                  },
+{"string",   "set string",     OFFSET(string),   AV_OPT_TYPE_STRING,   {.str = "default"}, CHAR_MIN, CHAR_MAX          },
 {"flags",    "set flags",      OFFSET(flags),    AV_OPT_TYPE_FLAGS,    {.i64 = 0},       0,        INT_MAX, 0, "flags" },
 {"cool",     "set cool flag ", 0,                AV_OPT_TYPE_CONST,    {.i64 = TEST_FLAG_COOL}, INT_MIN,  INT_MAX, 0, "flags" },
 {"lame",     "set lame flag ", 0,                AV_OPT_TYPE_CONST,    {.i64 = TEST_FLAG_LAME}, INT_MIN,  INT_MAX, 0, "flags" },
@@ -1385,7 +1385,6 @@ int main(void)
 
         test_ctx.class = &test_class;
         av_opt_set_defaults(&test_ctx);
-        test_ctx.string = av_strdup("default");
 
         av_log_set_level(AV_LOG_DEBUG);
 
diff --git a/mythtv/external/FFmpeg/libavutil/parseutils.c b/mythtv/external/FFmpeg/libavutil/parseutils.c
index ca40569e6ae..f2f8f18437e 100644
--- a/mythtv/external/FFmpeg/libavutil/parseutils.c
+++ b/mythtv/external/FFmpeg/libavutil/parseutils.c
@@ -109,6 +109,12 @@ static const VideoSizeAbbr video_size_abbrs[] = {
     { "hd480",     852, 480 },
     { "hd720",    1280, 720 },
     { "hd1080",   1920,1080 },
+    { "2k",       2048,1080 }, /* Digital Cinema System Specification */
+    { "2kflat",   1998,1080 },
+    { "2kscope",  2048, 858 },
+    { "4k",       4096,2160 }, /* Digital Cinema System Specification */
+    { "4kflat",   3996,2160 },
+    { "4kscope",  4096,1716 },
 };
 
 static const VideoRateAbbr video_rate_abbrs[]= {
@@ -420,7 +426,7 @@ static int date_get_num(const char **pp,
     val = 0;
     for(i = 0; i < len_max; i++) {
         c = *p;
-        if (!isdigit(c))
+        if (!av_isdigit(c))
             break;
         val = (val * 10) + c - '0';
         p++;
@@ -440,8 +446,8 @@ char *av_small_strptime(const char *p, const char *fmt, struct tm *dt)
 
     for(;;) {
         /* consume time string until a non whitespace char is found */
-        while (isspace(*fmt)) {
-            while (isspace(*p))
+        while (av_isspace(*fmt)) {
+            while (av_isspace(*p))
                 p++;
             fmt++;
         }
@@ -513,7 +519,7 @@ time_t av_timegm(struct tm *tm)
         y--;
     }
 
-    t = 86400 *
+    t = 86400LL *
         (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469);
 
     t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
@@ -581,6 +587,11 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
         }
         /* parse timestr as HH:MM:SS */
         q = av_small_strptime(p, "%J:%M:%S", &dt);
+        if (!q) {
+            /* parse timestr as MM:SS */
+            q = av_small_strptime(p, "%M:%S", &dt);
+            dt.tm_hour = 0;
+        }
         if (!q) {
             /* parse timestr as S+ */
             dt.tm_sec = strtol(p, (void *)&q, 10);
@@ -600,11 +611,11 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
         int n;
         q++;
         for (n = 100000; n >= 1; n /= 10, q++) {
-            if (!isdigit(*q))
+            if (!av_isdigit(*q))
                 break;
             microseconds += n * (*q - '0');
         }
-        while (isdigit(*q))
+        while (av_isdigit(*q))
             q++;
     }
 
diff --git a/mythtv/external/FFmpeg/libavutil/parseutils.h b/mythtv/external/FFmpeg/libavutil/parseutils.h
index 1f56a7a7cc1..3eb35fc0501 100644
--- a/mythtv/external/FFmpeg/libavutil/parseutils.h
+++ b/mythtv/external/FFmpeg/libavutil/parseutils.h
@@ -122,7 +122,7 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
  * year-month-day.
  * - If a duration the syntax is:
  * @code
- * [-]HH:MM:SS[.m...]]]
+ * [-][HH:]MM:SS[.m...]
  * [-]S+[.m...]
  * @endcode
  * @param duration flag which tells how to interpret timestr, if not
diff --git a/mythtv/external/FFmpeg/libavutil/pixdesc.c b/mythtv/external/FFmpeg/libavutil/pixdesc.c
index f9be147ad9b..1016dbaecba 100644
--- a/mythtv/external/FFmpeg/libavutil/pixdesc.c
+++ b/mythtv/external/FFmpeg/libavutil/pixdesc.c
@@ -1654,6 +1654,12 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[AV_PIX_FMT_NB] = {
         },
         .flags = PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_RGB,
     },
+    [AV_PIX_FMT_VDPAU] = {
+        .name = "vdpau",
+        .log2_chroma_w = 1,
+        .log2_chroma_h = 1,
+        .flags = PIX_FMT_HWACCEL,
+    },
 };
 
 static enum AVPixelFormat get_pix_fmt_internal(const char *name)
diff --git a/mythtv/external/FFmpeg/libavutil/pixfmt.h b/mythtv/external/FFmpeg/libavutil/pixfmt.h
index 457d9a8cc9c..1c00ac4796b 100644
--- a/mythtv/external/FFmpeg/libavutil/pixfmt.h
+++ b/mythtv/external/FFmpeg/libavutil/pixfmt.h
@@ -200,6 +200,8 @@ enum AVPixelFormat {
     AV_PIX_FMT_YUVA444P16BE, ///< planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
     AV_PIX_FMT_YUVA444P16LE, ///< planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
 
+    AV_PIX_FMT_VDPAU,     ///< HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface
+
 #ifndef AV_PIX_FMT_ABI_GIT_MASTER
     AV_PIX_FMT_RGBA64BE=0x123,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
     AV_PIX_FMT_RGBA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
@@ -229,7 +231,6 @@ enum AVPixelFormat {
     AV_PIX_FMT_GBRP12LE,    ///< planar GBR 4:4:4 36bpp, little-endian
     AV_PIX_FMT_GBRP14BE,    ///< planar GBR 4:4:4 42bpp, big-endian
     AV_PIX_FMT_GBRP14LE,    ///< planar GBR 4:4:4 42bpp, little-endian
-
     AV_PIX_FMT_NB,        ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
 
 #if FF_API_PIX_FMT
diff --git a/mythtv/external/FFmpeg/libavutil/ppc/float_dsp_altivec.c b/mythtv/external/FFmpeg/libavutil/ppc/float_dsp_altivec.c
index 6340e6c17b4..8cee82c1c7c 100644
--- a/mythtv/external/FFmpeg/libavutil/ppc/float_dsp_altivec.c
+++ b/mythtv/external/FFmpeg/libavutil/ppc/float_dsp_altivec.c
@@ -36,3 +36,89 @@ void ff_vector_fmul_altivec(float *dst, const float *src0, const float *src1,
         vec_st(d1, 16, dst + i);
     }
 }
+
+void ff_vector_fmul_window_altivec(float *dst, const float *src0,
+                                   const float *src1, const float *win, int len)
+{
+    vector float zero, t0, t1, s0, s1, wi, wj;
+    const vector unsigned char reverse = vcprm(3, 2, 1, 0);
+    int i, j;
+
+    dst  += len;
+    win  += len;
+    src0 += len;
+
+    zero = (vector float)vec_splat_u32(0);
+
+    for (i = -len * 4, j = len * 4 - 16; i < 0; i += 16, j -= 16) {
+        s0 = vec_ld(i, src0);
+        s1 = vec_ld(j, src1);
+        wi = vec_ld(i, win);
+        wj = vec_ld(j, win);
+
+        s1 = vec_perm(s1, s1, reverse);
+        wj = vec_perm(wj, wj, reverse);
+
+        t0 = vec_madd(s0, wj, zero);
+        t0 = vec_nmsub(s1, wi, t0);
+        t1 = vec_madd(s0, wi, zero);
+        t1 = vec_madd(s1, wj, t1);
+        t1 = vec_perm(t1, t1, reverse);
+
+        vec_st(t0, i, dst);
+        vec_st(t1, j, dst);
+    }
+}
+
+void ff_vector_fmul_add_altivec(float *dst, const float *src0,
+                                const float *src1, const float *src2,
+                                int len)
+{
+    int i;
+    vector float d, s0, s1, s2, t0, t1, edges;
+    vector unsigned char align = vec_lvsr(0,dst),
+                         mask = vec_lvsl(0, dst);
+
+    for (i = 0; i < len - 3; i += 4) {
+        t0 = vec_ld(0, dst + i);
+        t1 = vec_ld(15, dst + i);
+        s0 = vec_ld(0, src0 + i);
+        s1 = vec_ld(0, src1 + i);
+        s2 = vec_ld(0, src2 + i);
+        edges = vec_perm(t1, t0, mask);
+        d = vec_madd(s0, s1, s2);
+        t1 = vec_perm(d, edges, align);
+        t0 = vec_perm(edges, d, align);
+        vec_st(t1, 15, dst + i);
+        vec_st(t0, 0, dst + i);
+    }
+}
+
+void ff_vector_fmul_reverse_altivec(float *dst, const float *src0,
+                                    const float *src1, int len)
+{
+    int i;
+    vector float d, s0, s1, h0, l0,
+                s2, s3, zero = (vector float) vec_splat_u32(0);
+
+    src1 += len-4;
+    for(i = 0; i < len - 7; i += 8) {
+        s1 = vec_ld(0, src1 - i);              // [a,b,c,d]
+        s0 = vec_ld(0, src0 + i);
+        l0 = vec_mergel(s1, s1);               // [c,c,d,d]
+        s3 = vec_ld(-16, src1 - i);
+        h0 = vec_mergeh(s1, s1);               // [a,a,b,b]
+        s2 = vec_ld(16, src0 + i);
+        s1 = vec_mergeh(vec_mergel(l0, h0),    // [d,b,d,b]
+                        vec_mergeh(l0, h0));   // [c,a,c,a]
+        // [d,c,b,a]
+        l0 = vec_mergel(s3, s3);
+        d = vec_madd(s0, s1, zero);
+        h0 = vec_mergeh(s3, s3);
+        vec_st(d, 0, dst + i);
+        s3 = vec_mergeh(vec_mergel(l0, h0),
+                        vec_mergeh(l0, h0));
+        d = vec_madd(s2, s3, zero);
+        vec_st(d, 16, dst + i);
+    }
+}
diff --git a/mythtv/external/FFmpeg/libavutil/ppc/float_dsp_altivec.h b/mythtv/external/FFmpeg/libavutil/ppc/float_dsp_altivec.h
index 20c89c23386..b262a83548c 100644
--- a/mythtv/external/FFmpeg/libavutil/ppc/float_dsp_altivec.h
+++ b/mythtv/external/FFmpeg/libavutil/ppc/float_dsp_altivec.h
@@ -24,4 +24,15 @@
 extern void ff_vector_fmul_altivec(float *dst, const float *src0,
                                    const float *src1, int len);
 
+extern void ff_vector_fmul_window_altivec(float *dst, const float *src0,
+                                          const float *src1, const float *win,
+                                          int len);
+
+extern void ff_vector_fmul_add_altivec(float *dst, const float *src0,
+                                       const float *src1, const float *src2,
+                                       int len);
+
+extern void ff_vector_fmul_reverse_altivec(float *dst, const float *src0,
+                                           const float *src1, int len);
+
 #endif /* AVUTIL_PPC_FLOAT_DSP_ALTIVEC_H */
diff --git a/mythtv/external/FFmpeg/libavutil/ppc/float_dsp_init.c b/mythtv/external/FFmpeg/libavutil/ppc/float_dsp_init.c
index d0ae788779c..d9ca53eeec6 100644
--- a/mythtv/external/FFmpeg/libavutil/ppc/float_dsp_init.c
+++ b/mythtv/external/FFmpeg/libavutil/ppc/float_dsp_init.c
@@ -32,5 +32,11 @@ void ff_float_dsp_init_ppc(AVFloatDSPContext *fdsp, int bit_exact)
         return;
 
     fdsp->vector_fmul = ff_vector_fmul_altivec;
+    fdsp->vector_fmul_add = ff_vector_fmul_add_altivec;
+    fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_altivec;
+
+    if (!bit_exact) {
+        fdsp->vector_fmul_window = ff_vector_fmul_window_altivec;
+    }
 #endif
 }
diff --git a/mythtv/external/FFmpeg/libavutil/timecode.c b/mythtv/external/FFmpeg/libavutil/timecode.c
index 77d828d56f0..d396032b9c8 100644
--- a/mythtv/external/FFmpeg/libavutil/timecode.c
+++ b/mythtv/external/FFmpeg/libavutil/timecode.c
@@ -35,18 +35,21 @@ int av_timecode_adjust_ntsc_framenum2(int framenum, int fps)
 {
     /* only works for NTSC 29.97 and 59.94 */
     int drop_frames = 0;
-    int d = framenum / 17982;
-    int m = framenum % 17982;
+    int d, m, frames_per_10mins;
 
-    if (fps == 30)
+    if (fps == 30) {
         drop_frames = 2;
-    else if (fps == 60)
+        frames_per_10mins = 17982;
+    } else if (fps == 60) {
         drop_frames = 4;
-    else
+        frames_per_10mins = 35964;
+    } else
         return framenum;
 
-    //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */
-    return framenum + 9 * drop_frames * d + drop_frames * ((m - 2) / 1798);
+    d = framenum / frames_per_10mins;
+    m = framenum % frames_per_10mins;
+
+    return framenum + 9 * drop_frames * d + drop_frames * ((m - drop_frames) / (frames_per_10mins / 10));
 }
 
 uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum)
@@ -152,8 +155,8 @@ static int check_timecode(void *log_ctx, AVTimecode *tc)
         av_log(log_ctx, AV_LOG_ERROR, "Timecode frame rate must be specified\n");
         return AVERROR(EINVAL);
     }
-    if ((tc->flags & AV_TIMECODE_FLAG_DROPFRAME) && tc->fps != 30) {
-        av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed with 30000/1001 FPS\n");
+    if ((tc->flags & AV_TIMECODE_FLAG_DROPFRAME) && tc->fps != 30 && tc->fps != 60) {
+        av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed with 30000/1001 or 60000/1001 FPS\n");
         return AVERROR(EINVAL);
     }
     if (check_fps(tc->fps) < 0) {
diff --git a/mythtv/external/FFmpeg/libavutil/tomi/intreadwrite.h b/mythtv/external/FFmpeg/libavutil/tomi/intreadwrite.h
index 778b804ca12..7dec4158d3c 100644
--- a/mythtv/external/FFmpeg/libavutil/tomi/intreadwrite.h
+++ b/mythtv/external/FFmpeg/libavutil/tomi/intreadwrite.h
@@ -22,7 +22,9 @@
 #define AVUTIL_TOMI_INTREADWRITE_H
 
 #include 
+
 #include "config.h"
+#include "libavutil/attributes.h"
 
 #define AV_RB16 AV_RB16
 static av_always_inline uint16_t AV_RB16(const void *p)
diff --git a/mythtv/external/FFmpeg/libavutil/version.h b/mythtv/external/FFmpeg/libavutil/version.h
index e47e0d12b3f..4cd82268db9 100644
--- a/mythtv/external/FFmpeg/libavutil/version.h
+++ b/mythtv/external/FFmpeg/libavutil/version.h
@@ -75,7 +75,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  52
-#define LIBAVUTIL_VERSION_MINOR  13
+#define LIBAVUTIL_VERSION_MINOR  18
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
@@ -129,6 +129,10 @@
 #ifndef FF_API_SAMPLES_UTILS_RETURN_ZERO
 #define FF_API_SAMPLES_UTILS_RETURN_ZERO (LIBAVUTIL_VERSION_MAJOR < 53)
 #endif
+#ifndef FF_API_LLS_PRIVATE
+#define FF_API_LLS_PRIVATE              (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+
 
 /**
  * @}
diff --git a/mythtv/external/FFmpeg/libavutil/x86/Makefile b/mythtv/external/FFmpeg/libavutil/x86/Makefile
index 3dd696c26a2..ae07470b176 100644
--- a/mythtv/external/FFmpeg/libavutil/x86/Makefile
+++ b/mythtv/external/FFmpeg/libavutil/x86/Makefile
@@ -2,4 +2,5 @@ OBJS += x86/cpu.o                                                       \
         x86/float_dsp_init.o                                            \
 
 YASM-OBJS += x86/cpuid.o                                                \
+             x86/emms.o                                                 \
              x86/float_dsp.o                                            \
diff --git a/mythtv/external/FFmpeg/libavutil/x86/emms.asm b/mythtv/external/FFmpeg/libavutil/x86/emms.asm
new file mode 100644
index 00000000000..0aad34af3fa
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavutil/x86/emms.asm
@@ -0,0 +1,30 @@
+;*****************************************************************************
+;* Copyright (C) 2013 Martin Storsjo
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg is free software; you can redistribute it and/or
+;* modify it under the terms of the GNU Lesser General Public
+;* License as published by the Free Software Foundation; either
+;* version 2.1 of the License, or (at your option) any later version.
+;*
+;* FFmpeg is distributed in the hope that it will be useful,
+;* but WITHOUT ANY WARRANTY; without even the implied warranty of
+;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;* Lesser General Public License for more details.
+;*
+;* You should have received a copy of the GNU Lesser General Public
+;* License along with FFmpeg; if not, write to the Free Software
+;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;******************************************************************************
+
+%include "x86util.asm"
+
+SECTION .text
+
+;-----------------------------------------------------------------------------
+; void avpriv_emms_yasm(void)
+;-----------------------------------------------------------------------------
+cvisible emms_yasm, 0, 0
+    emms
+    RET
diff --git a/mythtv/external/FFmpeg/libavutil/x86/emms.h b/mythtv/external/FFmpeg/libavutil/x86/emms.h
new file mode 100644
index 00000000000..a529b6bbbe3
--- /dev/null
+++ b/mythtv/external/FFmpeg/libavutil/x86/emms.h
@@ -0,0 +1,47 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_X86_EMMS_H
+#define AVUTIL_X86_EMMS_H
+
+#include "config.h"
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+
+void avpriv_emms_yasm(void);
+
+#if HAVE_MMX_INLINE
+#   define emms_c emms_c
+/**
+ * Empty mmx state.
+ * this must be called between any dsp function and float/double code.
+ * for example sin(); dsp->idct_put(); emms_c(); cos()
+ */
+static av_always_inline void emms_c(void)
+{
+    if(av_get_cpu_flags() & AV_CPU_FLAG_MMX)
+        __asm__ volatile ("emms" ::: "memory");
+}
+#elif HAVE_MMX && HAVE_MM_EMPTY
+#   include 
+#   define emms_c _mm_empty
+#elif HAVE_MMX_EXTERNAL
+#   define emms_c avpriv_emms_yasm
+#endif /* HAVE_MMX_INLINE */
+
+#endif /* AVUTIL_X86_EMMS_H */
diff --git a/mythtv/external/FFmpeg/libavutil/x86/float_dsp.asm b/mythtv/external/FFmpeg/libavutil/x86/float_dsp.asm
index b6892d4e10d..004e6cf1fe5 100644
--- a/mythtv/external/FFmpeg/libavutil/x86/float_dsp.asm
+++ b/mythtv/external/FFmpeg/libavutil/x86/float_dsp.asm
@@ -168,3 +168,98 @@ VECTOR_DMUL_SCALAR
 INIT_YMM avx
 VECTOR_DMUL_SCALAR
 %endif
+
+;-----------------------------------------------------------------------------
+; vector_fmul_add(float *dst, const float *src0, const float *src1,
+;                 const float *src2, int len)
+;-----------------------------------------------------------------------------
+%macro VECTOR_FMUL_ADD 0
+cglobal vector_fmul_add, 5,5,2, dst, src0, src1, src2, len
+    lea       lenq, [lend*4 - 2*mmsize]
+ALIGN 16
+.loop:
+    mova    m0,   [src0q + lenq]
+    mova    m1,   [src0q + lenq + mmsize]
+    mulps   m0, m0, [src1q + lenq]
+    mulps   m1, m1, [src1q + lenq + mmsize]
+    addps   m0, m0, [src2q + lenq]
+    addps   m1, m1, [src2q + lenq + mmsize]
+    mova    [dstq + lenq], m0
+    mova    [dstq + lenq + mmsize], m1
+
+    sub     lenq,   2*mmsize
+    jge     .loop
+    REP_RET
+%endmacro
+
+INIT_XMM sse
+VECTOR_FMUL_ADD
+%if HAVE_AVX_EXTERNAL
+INIT_YMM avx
+VECTOR_FMUL_ADD
+%endif
+
+;-----------------------------------------------------------------------------
+; void vector_fmul_reverse(float *dst, const float *src0, const float *src1,
+;                          int len)
+;-----------------------------------------------------------------------------
+%macro VECTOR_FMUL_REVERSE 0
+cglobal vector_fmul_reverse, 4,4,2, dst, src0, src1, len
+    lea       lenq, [lend*4 - 2*mmsize]
+ALIGN 16
+.loop:
+%if cpuflag(avx)
+    vmovaps     xmm0, [src1q + 16]
+    vinsertf128 m0, m0, [src1q], 1
+    vshufps     m0, m0, m0, q0123
+    vmovaps     xmm1, [src1q + mmsize + 16]
+    vinsertf128 m1, m1, [src1q + mmsize], 1
+    vshufps     m1, m1, m1, q0123
+%else
+    mova    m0, [src1q]
+    mova    m1, [src1q + mmsize]
+    shufps  m0, m0, q0123
+    shufps  m1, m1, q0123
+%endif
+    mulps   m0, m0, [src0q + lenq + mmsize]
+    mulps   m1, m1, [src0q + lenq]
+    mova    [dstq + lenq + mmsize], m0
+    mova    [dstq + lenq], m1
+    add     src1q, 2*mmsize
+    sub     lenq,  2*mmsize
+    jge     .loop
+    REP_RET
+%endmacro
+
+INIT_XMM sse
+VECTOR_FMUL_REVERSE
+%if HAVE_AVX_EXTERNAL
+INIT_YMM avx
+VECTOR_FMUL_REVERSE
+%endif
+
+; float scalarproduct_float_sse(const float *v1, const float *v2, int len)
+INIT_XMM sse
+cglobal scalarproduct_float, 3,3,2, v1, v2, offset
+    neg   offsetq
+    shl   offsetq, 2
+    sub       v1q, offsetq
+    sub       v2q, offsetq
+    xorps    xmm0, xmm0
+.loop:
+    movaps   xmm1, [v1q+offsetq]
+    mulps    xmm1, [v2q+offsetq]
+    addps    xmm0, xmm1
+    add   offsetq, 16
+    js .loop
+    movhlps  xmm1, xmm0
+    addps    xmm0, xmm1
+    movss    xmm1, xmm0
+    shufps   xmm0, xmm0, 1
+    addss    xmm0, xmm1
+%if ARCH_X86_64 == 0
+    movss     r0m,  xmm0
+    fld dword r0m
+%endif
+    RET
+
diff --git a/mythtv/external/FFmpeg/libavutil/x86/float_dsp_init.c b/mythtv/external/FFmpeg/libavutil/x86/float_dsp_init.c
index e5112e7f8ea..5c6383bc74a 100644
--- a/mythtv/external/FFmpeg/libavutil/x86/float_dsp_init.c
+++ b/mythtv/external/FFmpeg/libavutil/x86/float_dsp_init.c
@@ -21,6 +21,7 @@
 #include "libavutil/cpu.h"
 #include "libavutil/float_dsp.h"
 #include "cpu.h"
+#include "asm.h"
 
 extern void ff_vector_fmul_sse(float *dst, const float *src0, const float *src1,
                                int len);
@@ -40,14 +41,103 @@ extern void ff_vector_dmul_scalar_sse2(double *dst, const double *src,
 extern void ff_vector_dmul_scalar_avx(double *dst, const double *src,
                                       double mul, int len);
 
+void ff_vector_fmul_add_sse(float *dst, const float *src0, const float *src1,
+                            const float *src2, int len);
+void ff_vector_fmul_add_avx(float *dst, const float *src0, const float *src1,
+                            const float *src2, int len);
+
+void ff_vector_fmul_reverse_sse(float *dst, const float *src0,
+                                const float *src1, int len);
+void ff_vector_fmul_reverse_avx(float *dst, const float *src0,
+                                const float *src1, int len);
+
+float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
+
+#if HAVE_6REGS && HAVE_INLINE_ASM
+static void vector_fmul_window_3dnowext(float *dst, const float *src0,
+                                        const float *src1, const float *win,
+                                        int len)
+{
+    x86_reg i = -len * 4;
+    x86_reg j =  len * 4 - 8;
+    __asm__ volatile (
+        "1:                             \n"
+        "pswapd (%5, %1), %%mm1         \n"
+        "movq   (%5, %0), %%mm0         \n"
+        "pswapd (%4, %1), %%mm5         \n"
+        "movq   (%3, %0), %%mm4         \n"
+        "movq      %%mm0, %%mm2         \n"
+        "movq      %%mm1, %%mm3         \n"
+        "pfmul     %%mm4, %%mm2         \n" // src0[len + i] * win[len + i]
+        "pfmul     %%mm5, %%mm3         \n" // src1[j]       * win[len + j]
+        "pfmul     %%mm4, %%mm1         \n" // src0[len + i] * win[len + j]
+        "pfmul     %%mm5, %%mm0         \n" // src1[j]       * win[len + i]
+        "pfadd     %%mm3, %%mm2         \n"
+        "pfsub     %%mm0, %%mm1         \n"
+        "pswapd    %%mm2, %%mm2         \n"
+        "movq      %%mm1, (%2, %0)      \n"
+        "movq      %%mm2, (%2, %1)      \n"
+        "sub          $8, %1            \n"
+        "add          $8, %0            \n"
+        "jl           1b                \n"
+        "femms                          \n"
+        : "+r"(i), "+r"(j)
+        : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
+    );
+}
+
+static void vector_fmul_window_sse(float *dst, const float *src0,
+                                   const float *src1, const float *win, int len)
+{
+    x86_reg i = -len * 4;
+    x86_reg j =  len * 4 - 16;
+    __asm__ volatile (
+        "1:                             \n"
+        "movaps      (%5, %1), %%xmm1   \n"
+        "movaps      (%5, %0), %%xmm0   \n"
+        "movaps      (%4, %1), %%xmm5   \n"
+        "movaps      (%3, %0), %%xmm4   \n"
+        "shufps $0x1b, %%xmm1, %%xmm1   \n"
+        "shufps $0x1b, %%xmm5, %%xmm5   \n"
+        "movaps        %%xmm0, %%xmm2   \n"
+        "movaps        %%xmm1, %%xmm3   \n"
+        "mulps         %%xmm4, %%xmm2   \n" // src0[len + i] * win[len + i]
+        "mulps         %%xmm5, %%xmm3   \n" // src1[j]       * win[len + j]
+        "mulps         %%xmm4, %%xmm1   \n" // src0[len + i] * win[len + j]
+        "mulps         %%xmm5, %%xmm0   \n" // src1[j]       * win[len + i]
+        "addps         %%xmm3, %%xmm2   \n"
+        "subps         %%xmm0, %%xmm1   \n"
+        "shufps $0x1b, %%xmm2, %%xmm2   \n"
+        "movaps        %%xmm1, (%2, %0) \n"
+        "movaps        %%xmm2, (%2, %1) \n"
+        "sub              $16, %1       \n"
+        "add              $16, %0       \n"
+        "jl                1b           \n"
+        : "+r"(i), "+r"(j)
+        : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
+    );
+}
+#endif /* HAVE_6REGS && HAVE_INLINE_ASM */
+
 void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp)
 {
     int mm_flags = av_get_cpu_flags();
 
+#if HAVE_6REGS && HAVE_INLINE_ASM
+    if (INLINE_AMD3DNOWEXT(mm_flags)) {
+        fdsp->vector_fmul_window  = vector_fmul_window_3dnowext;
+    }
+    if (INLINE_SSE(mm_flags)) {
+        fdsp->vector_fmul_window = vector_fmul_window_sse;
+    }
+#endif
     if (EXTERNAL_SSE(mm_flags)) {
         fdsp->vector_fmul = ff_vector_fmul_sse;
         fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_sse;
         fdsp->vector_fmul_scalar = ff_vector_fmul_scalar_sse;
+        fdsp->vector_fmul_add    = ff_vector_fmul_add_sse;
+        fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_sse;
+        fdsp->scalarproduct_float = ff_scalarproduct_float_sse;
     }
     if (EXTERNAL_SSE2(mm_flags)) {
         fdsp->vector_dmul_scalar = ff_vector_dmul_scalar_sse2;
@@ -56,5 +146,7 @@ void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp)
         fdsp->vector_fmul = ff_vector_fmul_avx;
         fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_avx;
         fdsp->vector_dmul_scalar = ff_vector_dmul_scalar_avx;
+        fdsp->vector_fmul_add    = ff_vector_fmul_add_avx;
+        fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_avx;
     }
 }
diff --git a/mythtv/external/FFmpeg/libavutil/x86/x86inc.asm b/mythtv/external/FFmpeg/libavutil/x86/x86inc.asm
index 8fb28767e5a..068e3cf5c87 100644
--- a/mythtv/external/FFmpeg/libavutil/x86/x86inc.asm
+++ b/mythtv/external/FFmpeg/libavutil/x86/x86inc.asm
@@ -34,8 +34,12 @@
 ; as this feature might be useful for others as well.  Send patches or ideas
 ; to x264-devel@videolan.org .
 
-%ifndef program_name
-    %define program_name x264
+%ifndef private_prefix
+    %define private_prefix x264
+%endif
+
+%ifndef public_prefix
+    %define public_prefix private_prefix
 %endif
 
 %define WIN64  0
@@ -643,38 +647,48 @@ DECLARE_ARG 7, 8, 9, 10, 11, 12, 13, 14
 ; Applies any symbol mangling needed for C linkage, and sets up a define such that
 ; subsequent uses of the function name automatically refer to the mangled version.
 ; Appends cpuflags to the function name if cpuflags has been specified.
+; The "" empty default parameter is a workaround for nasm, which fails if SUFFIX
+; is empty and we call cglobal_internal with just %1 %+ SUFFIX (without %2).
 %macro cglobal 1-2+ "" ; name, [PROLOGUE args]
-    ; the "" is a workaround for nasm, which fails if SUFFIX is empty
-    ; and we call cglobal_internal with just %1 %+ SUFFIX (without %2)
-    cglobal_internal %1 %+ SUFFIX, %2
+    cglobal_internal 1, %1 %+ SUFFIX, %2
+%endmacro
+%macro cvisible 1-2+ "" ; name, [PROLOGUE args]
+    cglobal_internal 0, %1 %+ SUFFIX, %2
 %endmacro
-%macro cglobal_internal 1-2+
-    %ifndef cglobaled_%1
-        %xdefine %1 mangle(program_name %+ _ %+ %1)
-        %xdefine %1.skip_prologue %1 %+ .skip_prologue
-        CAT_XDEFINE cglobaled_, %1, 1
+%macro cglobal_internal 2-3+
+    %if %1
+        %xdefine %%FUNCTION_PREFIX private_prefix
+        %xdefine %%VISIBILITY hidden
+    %else
+        %xdefine %%FUNCTION_PREFIX public_prefix
+        %xdefine %%VISIBILITY
+    %endif
+    %ifndef cglobaled_%2
+        %xdefine %2 mangle(%%FUNCTION_PREFIX %+ _ %+ %2)
+        %xdefine %2.skip_prologue %2 %+ .skip_prologue
+        CAT_XDEFINE cglobaled_, %2, 1
     %endif
-    %xdefine current_function %1
+    %xdefine current_function %2
     %ifidn __OUTPUT_FORMAT__,elf
-        global %1:function hidden
+        global %2:function %%VISIBILITY
     %else
-        global %1
+        global %2
     %endif
     align function_align
-    %1:
+    %2:
     RESET_MM_PERMUTATION ; not really needed, but makes disassembly somewhat nicer
     %xdefine rstk rsp
     %assign stack_offset 0
     %assign stack_size 0
     %assign stack_size_padded 0
     %assign xmm_regs_used 0
-    %ifnidn %2, ""
-        PROLOGUE %2
+    %ifnidn %3, ""
+        PROLOGUE %3
     %endif
 %endmacro
 
 %macro cextern 1
-    %xdefine %1 mangle(program_name %+ _ %+ %1)
+    %xdefine %1 mangle(private_prefix %+ _ %+ %1)
     CAT_XDEFINE cglobaled_, %1, 1
     extern %1
 %endmacro
@@ -687,7 +701,7 @@ DECLARE_ARG 7, 8, 9, 10, 11, 12, 13, 14
 %endmacro
 
 %macro const 2+
-    %xdefine %1 mangle(program_name %+ _ %+ %1)
+    %xdefine %1 mangle(private_prefix %+ _ %+ %1)
     global %1
     %1: %2
 %endmacro
@@ -757,7 +771,7 @@ SECTION .note.GNU-stack noalloc noexec nowrite progbits
         %elifidn %1, sse3
             %define movu lddqu
         %endif
-        %if notcpuflag(mmx2)
+        %if notcpuflag(sse2)
             CPUNOP basicnop
         %endif
     %else
diff --git a/mythtv/external/FFmpeg/libavutil/x86/x86util.asm b/mythtv/external/FFmpeg/libavutil/x86/x86util.asm
index 00fa7b1827b..8908444950c 100644
--- a/mythtv/external/FFmpeg/libavutil/x86/x86util.asm
+++ b/mythtv/external/FFmpeg/libavutil/x86/x86util.asm
@@ -23,7 +23,8 @@
 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 ;******************************************************************************
 
-%define program_name ff
+%define private_prefix ff
+%define public_prefix  avpriv
 %define cpuflags_mmxext cpuflags_mmx2
 
 %include "libavutil/x86/x86inc.asm"
@@ -172,14 +173,33 @@
     psignw     %1, %2
 %endmacro
 
-%macro ABS1_MMX 2    ; a, tmp
+%macro ABS1 2
+%if cpuflag(ssse3)
+    pabsw   %1, %1
+%elif cpuflag(mmxext) ; a, tmp
+    pxor    %2, %2
+    psubw   %2, %1
+    pmaxsw  %1, %2
+%else ; a, tmp
     pxor       %2, %2
     pcmpgtw    %2, %1
     pxor       %1, %2
     psubw      %1, %2
+%endif
 %endmacro
 
-%macro ABS2_MMX 4    ; a, b, tmp0, tmp1
+%macro ABS2 4
+%if cpuflag(ssse3)
+    pabsw   %1, %1
+    pabsw   %2, %2
+%elif cpuflag(mmxext) ; a, b, tmp0, tmp1
+    pxor    %3, %3
+    pxor    %4, %4
+    psubw   %3, %1
+    psubw   %4, %2
+    pmaxsw  %1, %3
+    pmaxsw  %2, %4
+%else ; a, b, tmp0, tmp1
     pxor       %3, %3
     pxor       %4, %4
     pcmpgtw    %3, %1
@@ -188,45 +208,31 @@
     pxor       %2, %4
     psubw      %1, %3
     psubw      %2, %4
+%endif
 %endmacro
 
-%macro ABS1_MMXEXT 2 ; a, tmp
-    pxor    %2, %2
-    psubw   %2, %1
-    pmaxsw  %1, %2
-%endmacro
-
-%macro ABS2_MMXEXT 4 ; a, b, tmp0, tmp1
-    pxor    %3, %3
-    pxor    %4, %4
-    psubw   %3, %1
-    psubw   %4, %2
-    pmaxsw  %1, %3
-    pmaxsw  %2, %4
-%endmacro
-
-%macro ABS1_SSSE3 2
-    pabsw   %1, %1
-%endmacro
-
-%macro ABS2_SSSE3 4
-    pabsw   %1, %1
-    pabsw   %2, %2
-%endmacro
-
-%macro ABSB_MMX 2
+%macro ABSB 2 ; source mmreg, temp mmreg (unused for ssse3)
+%if cpuflag(ssse3)
+    pabsb   %1, %1
+%else
     pxor    %2, %2
     psubb   %2, %1
     pminub  %1, %2
+%endif
 %endmacro
 
-%macro ABSB2_MMX 4
+%macro ABSB2 4 ; src1, src2, tmp1, tmp2 (tmp1/2 unused for SSSE3)
+%if cpuflag(ssse3)
+    pabsb   %1, %1
+    pabsb   %2, %2
+%else
     pxor    %3, %3
     pxor    %4, %4
     psubb   %3, %1
     psubb   %4, %2
     pminub  %1, %3
     pminub  %2, %4
+%endif
 %endmacro
 
 %macro ABSD2_MMX 4
@@ -240,25 +246,11 @@
     psubd   %2, %4
 %endmacro
 
-%macro ABSB_SSSE3 2
-    pabsb   %1, %1
-%endmacro
-
-%macro ABSB2_SSSE3 4
-    pabsb   %1, %1
-    pabsb   %2, %2
-%endmacro
-
 %macro ABS4 6
     ABS2 %1, %2, %5, %6
     ABS2 %3, %4, %5, %6
 %endmacro
 
-%define ABS1 ABS1_MMX
-%define ABS2 ABS2_MMX
-%define ABSB ABSB_MMX
-%define ABSB2 ABSB2_MMX
-
 %macro SPLATB_LOAD 3
 %if cpuflag(ssse3)
     movd      %1, [%2-3]
@@ -310,6 +302,14 @@
 %endif
 %endmacro
 
+%macro PAVGB 2
+%if cpuflag(mmxext)
+    pavgb   %1, %2
+%elif cpuflag(3dnow)
+    pavgusb %1, %2
+%endif
+%endmacro
+
 %macro PSHUFLW 1+
     %if mmsize == 8
         pshufw %1
diff --git a/mythtv/external/FFmpeg/libpostproc/postprocess_template.c b/mythtv/external/FFmpeg/libpostproc/postprocess_template.c
index 4152f671319..ad0404f76bc 100644
--- a/mythtv/external/FFmpeg/libpostproc/postprocess_template.c
+++ b/mythtv/external/FFmpeg/libpostproc/postprocess_template.c
@@ -1089,7 +1089,7 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
 #if !TEMPLATE_PP_ALTIVEC
 static inline void RENAME(dering)(uint8_t src[], int stride, PPContext *c)
 {
-#if TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
+#if HAVE_7REGS && (TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW)
     DECLARE_ALIGNED(8, uint64_t, tmp)[3];
     __asm__ volatile(
         "pxor %%mm6, %%mm6                      \n\t"
@@ -1315,7 +1315,7 @@ DERING_CORE((%0, %1, 8)    ,(%%REGd, %1, 4),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,
         : : "r" (src), "r" ((x86_reg)stride), "m" (c->pQPb), "m"(c->pQPb2), "q"(tmp)
         : "%"REG_a, "%"REG_d
     );
-#else //TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
+#else // HAVE_7REGS && (TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW)
     int y;
     int min=255;
     int max=0;
diff --git a/mythtv/external/FFmpeg/library.mak b/mythtv/external/FFmpeg/library.mak
index 21537cb3da7..dba444bd5c3 100644
--- a/mythtv/external/FFmpeg/library.mak
+++ b/mythtv/external/FFmpeg/library.mak
@@ -4,6 +4,7 @@ include $(SRC_PATH_BARE)/external/FFmpeg/common.mak
 
 LIBVERSION := $(lib$(NAME)_VERSION)
 LIBMAJOR   := $(lib$(NAME)_VERSION_MAJOR)
+LIBMINOR   := $(lib$(NAME)_VERSION_MINOR)
 INCINSTDIR := $(INCDIR)/lib$(NAME)
 
 INSTHEADERS := $(INSTHEADERS) $(HEADERS:%=$(SUBDIR)%)
@@ -72,7 +73,7 @@ install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
 	$(Q)mkdir -p "$(SHLIBDIR)"
 	$$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
 	$$(STRIP) "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
-	$(Q)$(foreach F,$(SLIB_INSTALL_LINKS),cd "$(SHLIBDIR)" && $(LN_S) $(SLIB_INSTALL_NAME) $(F);)
+	$(Q)$(foreach F,$(SLIB_INSTALL_LINKS),(cd "$(SHLIBDIR)" && $(LN_S) $(SLIB_INSTALL_NAME) $(F));)
 	$(if $(SLIB_INSTALL_EXTRA_SHLIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_SHLIB:%=$(SUBDIR)%) "$(SHLIBDIR)")
 	$(if $(SLIB_INSTALL_EXTRA_LIB),$(Q)mkdir -p "$(LIBDIR)")
 	$(if $(SLIB_INSTALL_EXTRA_LIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_LIB:%=$(SUBDIR)%) "$(LIBDIR)")
@@ -86,7 +87,7 @@ install-lib$(NAME)-headers: $(addprefix $(SUBDIR),$(HEADERS) $(BUILT_HEADERS))
 	$(Q)mkdir -p "$(INCINSTDIR)"
 	$$(INSTALL) -m 644 $$^ "$(INCINSTDIR)"
 
-install-lib$(NAME)-pkgconfig: $(SUBDIR)lib$(NAME).pc
+install-lib$(NAME)-pkgconfig: $(SUBDIR)lib$(FULLNAME).pc
 	$(Q)mkdir -p "$(LIBDIR)/pkgconfig"
 	$$(INSTALL) -m 644 $$^ "$(LIBDIR)/pkgconfig"
 
@@ -100,7 +101,7 @@ uninstall-libs::
 
 uninstall-headers::
 	$(RM) $(addprefix "$(INCINSTDIR)/",$(HEADERS) $(BUILT_HEADERS))
-	$(RM) "$(LIBDIR)/pkgconfig/lib$(NAME).pc"
+	$(RM) "$(LIBDIR)/pkgconfig/lib$(FULLNAME).pc"
 	-rmdir "$(INCINSTDIR)"
 endef
 
diff --git a/mythtv/external/FFmpeg/libswresample/dither.c b/mythtv/external/FFmpeg/libswresample/dither.c
index 79113f4c23d..d0193dda461 100644
--- a/mythtv/external/FFmpeg/libswresample/dither.c
+++ b/mythtv/external/FFmpeg/libswresample/dither.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Michael Niedermayer (michaelni@gmx.at)
+ * Copyright (C) 2012-2013 Michael Niedermayer (michaelni@gmx.at)
  *
  * This file is part of libswresample
  *
@@ -21,39 +21,26 @@
 #include "libavutil/avassert.h"
 #include "swresample_internal.h"
 
-void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt) {
-    double scale = 0;
+#include "noise_shaping_data.c"
+
+void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat noise_fmt) {
+    double scale = s->dither.noise_scale;
 #define TMP_EXTRA 2
     double *tmp = av_malloc((len + TMP_EXTRA) * sizeof(double));
     int i;
 
-    out_fmt = av_get_packed_sample_fmt(out_fmt);
-    in_fmt  = av_get_packed_sample_fmt( in_fmt);
-
-    if(in_fmt == AV_SAMPLE_FMT_FLT || in_fmt == AV_SAMPLE_FMT_DBL){
-        if(out_fmt == AV_SAMPLE_FMT_S32) scale = 1.0/(1L<<31);
-        if(out_fmt == AV_SAMPLE_FMT_S16) scale = 1.0/(1L<<15);
-        if(out_fmt == AV_SAMPLE_FMT_U8 ) scale = 1.0/(1L<< 7);
-    }
-    if(in_fmt == AV_SAMPLE_FMT_S32 && out_fmt == AV_SAMPLE_FMT_S16) scale = 1L<<16;
-    if(in_fmt == AV_SAMPLE_FMT_S32 && out_fmt == AV_SAMPLE_FMT_U8 ) scale = 1L<<24;
-    if(in_fmt == AV_SAMPLE_FMT_S16 && out_fmt == AV_SAMPLE_FMT_U8 ) scale = 1L<<8;
-
-    scale *= s->dither_scale;
-
     for(i=0; idither_method){
+        switch(s->dither.method){
             case SWR_DITHER_RECTANGULAR: v= ((double)seed) / UINT_MAX - 0.5; break;
-            case SWR_DITHER_TRIANGULAR :
-            case SWR_DITHER_TRIANGULAR_HIGHPASS :
+            default:
+                av_assert0(s->dither.method < SWR_DITHER_NB);
                 v = ((double)seed) / UINT_MAX;
                 seed = seed*1664525 + 1013904223;
                 v-= ((double)seed) / UINT_MAX;
                 break;
-            default: av_assert0(0);
         }
         tmp[i] = v;
     }
@@ -61,27 +48,100 @@ void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSa
     for(i=0; idither_method){
-            case SWR_DITHER_RECTANGULAR:
-            case SWR_DITHER_TRIANGULAR :
+        switch(s->dither.method){
+            default:
+                av_assert0(s->dither.method < SWR_DITHER_NB);
                 v = tmp[i];
                 break;
             case SWR_DITHER_TRIANGULAR_HIGHPASS :
                 v = (- tmp[i] + 2*tmp[i+1] - tmp[i+2]) / sqrt(6);
                 break;
-            default: av_assert0(0);
         }
 
         v*= scale;
 
-        switch(in_fmt){
-            case AV_SAMPLE_FMT_S16: ((int16_t*)dst)[i] = v; break;
-            case AV_SAMPLE_FMT_S32: ((int32_t*)dst)[i] = v; break;
-            case AV_SAMPLE_FMT_FLT: ((float  *)dst)[i] = v; break;
-            case AV_SAMPLE_FMT_DBL: ((double *)dst)[i] = v; break;
+        switch(noise_fmt){
+            case AV_SAMPLE_FMT_S16P: ((int16_t*)dst)[i] = v; break;
+            case AV_SAMPLE_FMT_S32P: ((int32_t*)dst)[i] = v; break;
+            case AV_SAMPLE_FMT_FLTP: ((float  *)dst)[i] = v; break;
+            case AV_SAMPLE_FMT_DBLP: ((double *)dst)[i] = v; break;
             default: av_assert0(0);
         }
     }
 
     av_free(tmp);
 }
+
+int swri_dither_init(SwrContext *s, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt)
+{
+    int i;
+    double scale = 0;
+
+    if (s->dither.method > SWR_DITHER_TRIANGULAR_HIGHPASS && s->dither.method <= SWR_DITHER_NS)
+        return AVERROR(EINVAL);
+
+    out_fmt = av_get_packed_sample_fmt(out_fmt);
+    in_fmt  = av_get_packed_sample_fmt( in_fmt);
+
+    if(in_fmt == AV_SAMPLE_FMT_FLT || in_fmt == AV_SAMPLE_FMT_DBL){
+        if(out_fmt == AV_SAMPLE_FMT_S32) scale = 1.0/(1L<<31);
+        if(out_fmt == AV_SAMPLE_FMT_S16) scale = 1.0/(1L<<15);
+        if(out_fmt == AV_SAMPLE_FMT_U8 ) scale = 1.0/(1L<< 7);
+    }
+    if(in_fmt == AV_SAMPLE_FMT_S32 && out_fmt == AV_SAMPLE_FMT_S16) scale = 1L<<16;
+    if(in_fmt == AV_SAMPLE_FMT_S32 && out_fmt == AV_SAMPLE_FMT_U8 ) scale = 1L<<24;
+    if(in_fmt == AV_SAMPLE_FMT_S16 && out_fmt == AV_SAMPLE_FMT_U8 ) scale = 1L<<8;
+
+    scale *= s->dither.scale;
+
+    if (out_fmt == AV_SAMPLE_FMT_S32 && s->dither.output_sample_bits)
+        scale *= 1<<(32-s->dither.output_sample_bits);
+
+    s->dither.ns_pos = 0;
+    s->dither.noise_scale=   scale;
+    s->dither.ns_scale   =   scale;
+    s->dither.ns_scale_1 = scale ? 1/scale : 0;
+    memset(s->dither.ns_errors, 0, sizeof(s->dither.ns_errors));
+    for (i=0; filters[i].coefs; i++) {
+        const filter_t *f = &filters[i];
+        if (fabs(s->out_sample_rate - f->rate) / f->rate <= .05 && f->name == s->dither.method) {
+            int j;
+            s->dither.ns_taps = f->len;
+            for (j=0; jlen; j++)
+                s->dither.ns_coeffs[j] = f->coefs[j];
+            s->dither.ns_scale_1 *= 1 - exp(f->gain_cB * M_LN10 * 0.005) * 2 / (1<<(8*av_get_bytes_per_sample(out_fmt)));
+            break;
+        }
+    }
+    if (!filters[i].coefs && s->dither.method > SWR_DITHER_NS) {
+        av_log(s, AV_LOG_WARNING, "Requested noise shaping dither not available at this sampling rate, using triangular hp dither\n");
+        s->dither.method = SWR_DITHER_TRIANGULAR_HIGHPASS;
+    }
+
+    av_assert0(!s->preout.count);
+    s->dither.noise = s->preout;
+    s->dither.temp  = s->preout;
+    if (s->dither.method > SWR_DITHER_NS) {
+        s->dither.noise.bps = 4;
+        s->dither.noise.fmt = AV_SAMPLE_FMT_FLTP;
+        s->dither.noise_scale = 1;
+    }
+
+    return 0;
+}
+
+#define TEMPLATE_DITHER_S16
+#include "dither_template.c"
+#undef TEMPLATE_DITHER_S16
+
+#define TEMPLATE_DITHER_S32
+#include "dither_template.c"
+#undef TEMPLATE_DITHER_S32
+
+#define TEMPLATE_DITHER_FLT
+#include "dither_template.c"
+#undef TEMPLATE_DITHER_FLT
+
+#define TEMPLATE_DITHER_DBL
+#include "dither_template.c"
+#undef TEMPLATE_DITHER_DBL
diff --git a/mythtv/external/FFmpeg/libswresample/dither_template.c b/mythtv/external/FFmpeg/libswresample/dither_template.c
new file mode 100644
index 00000000000..4af73127790
--- /dev/null
+++ b/mythtv/external/FFmpeg/libswresample/dither_template.c
@@ -0,0 +1,67 @@
+
+#if defined(TEMPLATE_DITHER_DBL)
+#    define RENAME(N) N ## _double
+#    define DELEM  double
+#    define CLIP(v)
+
+#elif defined(TEMPLATE_DITHER_FLT)
+#    define RENAME(N) N ## _float
+#    define DELEM  float
+#    define CLIP(v)
+
+#elif defined(TEMPLATE_DITHER_S32)
+#    define RENAME(N) N ## _int32
+#    define DELEM  int32_t
+#    define CLIP(v) v = FFMAX(FFMIN(v, INT32_MAX), INT32_MIN)
+
+#elif defined(TEMPLATE_DITHER_S16)
+#    define RENAME(N) N ## _int16
+#    define DELEM  int16_t
+#    define CLIP(v) v = FFMAX(FFMIN(v, INT16_MAX), INT16_MIN)
+
+#else
+ERROR
+#endif
+
+void RENAME(swri_noise_shaping)(SwrContext *s, AudioData *dsts, const AudioData *srcs, const AudioData *noises, int count){
+    int pos = s->dither.ns_pos;
+    int i, j, ch;
+    int taps  = s->dither.ns_taps;
+    float S   = s->dither.ns_scale;
+    float S_1 = s->dither.ns_scale_1;
+
+    av_assert2((taps&3) != 2);
+    av_assert2((taps&3) != 3 || s->dither.ns_coeffs[taps] == 0);
+
+    for (ch=0; chch_count; ch++) {
+        const float *noise = ((const float *)noises->ch[ch]) + s->dither.noise_pos;
+        const DELEM *src = (const DELEM*)srcs->ch[ch];
+        DELEM *dst = (DELEM*)dsts->ch[ch];
+        float *ns_errors = s->dither.ns_errors[ch];
+        const float *ns_coeffs = s->dither.ns_coeffs;
+        pos  = s->dither.ns_pos;
+        for (i=0; idither.ns_pos = pos;
+}
+
+#undef RENAME
+#undef DELEM
+#undef CLIP
diff --git a/mythtv/external/FFmpeg/libswresample/noise_shaping_data.c b/mythtv/external/FFmpeg/libswresample/noise_shaping_data.c
new file mode 100644
index 00000000000..77e0f2eafce
--- /dev/null
+++ b/mythtv/external/FFmpeg/libswresample/noise_shaping_data.c
@@ -0,0 +1,224 @@
+/* Effect: dither/noise-shape   Copyright (c) 2008-9 robs@users.sourceforge.net
+ *
+ * This library 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.
+ *
+ * This library 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 this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+typedef struct {
+  int  rate;
+  enum {fir, iir} type;
+  size_t len;
+  int gain_cB; /* Chosen so clips are few if any, but not guaranteed none. */
+  double const * coefs;
+  enum SwrDitherType name;
+} filter_t;
+
+static double const lip44[] = {2.033, -2.165, 1.959, -1.590, .6149};
+static double const fwe44[] = {
+  2.412, -3.370, 3.937, -4.174, 3.353, -2.205, 1.281, -.569, .0847};
+static double const mew44[] = {
+  1.662, -1.263, .4827, -.2913, .1268, -.1124, .03252, -.01265, -.03524};
+static double const iew44[] = {
+  2.847, -4.685, 6.214, -7.184, 6.639, -5.032, 3.263, -1.632, .4191};
+static double const ges44[] = {
+  2.2061, -.4706, -.2534, -.6214, 1.0587, .0676, -.6054, -.2738};
+static double const ges48[] = {
+  2.2374, -.7339, -.1251, -.6033, .903, .0116, -.5853, -.2571};
+
+static double const shi48[] = {
+  2.8720729351043701172,  -5.0413231849670410156,   6.2442994117736816406,
+  -5.8483986854553222656, 3.7067542076110839844,  -1.0495119094848632812,
+  -1.1830236911773681641,   2.1126792430877685547, -1.9094531536102294922,
+  0.99913084506988525391, -0.17090806365013122559, -0.32615602016448974609,
+  0.39127644896507263184, -0.26876461505889892578,  0.097676105797290802002,
+  -0.023473845794796943665,
+};
+static double const shi44[] = {
+  2.6773197650909423828,  -4.8308925628662109375,   6.570110321044921875,
+  -7.4572014808654785156, 6.7263274192810058594,  -4.8481650352478027344,
+  2.0412089824676513672,   0.7006359100341796875, -2.9537565708160400391,
+  4.0800385475158691406,  -4.1845216751098632812,   3.3311812877655029297,
+  -2.1179926395416259766,   0.879302978515625,      -0.031759146600961685181,
+  -0.42382788658142089844, 0.47882103919982910156, -0.35490813851356506348,
+  0.17496839165687561035, -0.060908168554306030273,
+};
+static double const shi38[] = {
+  1.6335992813110351562,  -2.2615492343902587891,   2.4077029228210449219,
+  -2.6341717243194580078, 2.1440362930297851562,  -1.8153258562088012695,
+  1.0816224813461303711,  -0.70302653312683105469, 0.15991993248462677002,
+  0.041549518704414367676, -0.29416576027870178223,  0.2518316805362701416,
+  -0.27766478061676025391,  0.15785403549671173096, -0.10165894031524658203,
+  0.016833892092108726501,
+};
+static double const shi32[] =
+{ /* dmaker 32000: bestmax=4.99659 (inverted) */
+0.82118552923202515,
+-1.0063692331314087,
+0.62341964244842529,
+-1.0447187423706055,
+0.64532512426376343,
+-0.87615132331848145,
+0.52219754457473755,
+-0.67434263229370117,
+0.44954317808151245,
+-0.52557498216629028,
+0.34567299485206604,
+-0.39618203043937683,
+0.26791760325431824,
+-0.28936097025871277,
+0.1883765310049057,
+-0.19097308814525604,
+0.10431359708309174,
+-0.10633844882249832,
+0.046832218766212463,
+-0.039653312414884567,
+};
+static double const shi22[] =
+{ /* dmaker 22050: bestmax=5.77762 (inverted) */
+0.056581053882837296,
+-0.56956905126571655,
+-0.40727734565734863,
+-0.33870288729667664,
+-0.29810553789138794,
+-0.19039161503314972,
+-0.16510021686553955,
+-0.13468159735202789,
+-0.096633769571781158,
+-0.081049129366874695,
+-0.064953058958053589,
+-0.054459091275930405,
+-0.043378707021474838,
+-0.03660014271736145,
+-0.026256965473294258,
+-0.018786206841468811,
+-0.013387725688517094,
+-0.0090983230620622635,
+-0.0026585909072309732,
+-0.00042083300650119781,
+};
+static double const shi16[] =
+{ /* dmaker 16000: bestmax=5.97128 (inverted) */
+-0.37251132726669312,
+-0.81423574686050415,
+-0.55010956525802612,
+-0.47405767440795898,
+-0.32624706625938416,
+-0.3161766529083252,
+-0.2286367267370224,
+-0.22916607558727264,
+-0.19565616548061371,
+-0.18160104751586914,
+-0.15423151850700378,
+-0.14104481041431427,
+-0.11844276636838913,
+-0.097583092749118805,
+-0.076493598520755768,
+-0.068106919527053833,
+-0.041881654411554337,
+-0.036922425031661987,
+-0.019364040344953537,
+-0.014994367957115173,
+};
+static double const shi11[] =
+{ /* dmaker 11025: bestmax=5.9406 (inverted) */
+-0.9264228343963623,
+-0.98695987462997437,
+-0.631156325340271,
+-0.51966935396194458,
+-0.39738872647285461,
+-0.35679301619529724,
+-0.29720726609230042,
+-0.26310476660728455,
+-0.21719355881214142,
+-0.18561814725399017,
+-0.15404847264289856,
+-0.12687471508979797,
+-0.10339745879173279,
+-0.083688631653785706,
+-0.05875682458281517,
+-0.046893671154975891,
+-0.027950936928391457,
+-0.020740609616041183,
+-0.009366452693939209,
+-0.0060260160826146603,
+};
+static double const shi08[] =
+{ /* dmaker 8000: bestmax=5.56234 (inverted) */
+-1.202863335609436,
+-0.94103097915649414,
+-0.67878556251525879,
+-0.57650017738342285,
+-0.50004476308822632,
+-0.44349345564842224,
+-0.37833768129348755,
+-0.34028723835945129,
+-0.29413089156150818,
+-0.24994957447052002,
+-0.21715600788593292,
+-0.18792112171649933,
+-0.15268312394618988,
+-0.12135542929172516,
+-0.099610626697540283,
+-0.075273610651493073,
+-0.048787496984004974,
+-0.042586319148540497,
+-0.028991291299462318,
+-0.011869125068187714,
+};
+static double const shl48[] = {
+  2.3925774097442626953,  -3.4350297451019287109,   3.1853709220886230469,
+  -1.8117271661758422852, -0.20124770700931549072,  1.4759907722473144531,
+  -1.7210904359817504883,   0.97746700048446655273, -0.13790138065814971924,
+  -0.38185903429985046387,  0.27421241998672485352,  0.066584214568138122559,
+  -0.35223302245140075684,  0.37672343850135803223, -0.23964276909828186035,
+  0.068674825131893157959,
+};
+static double const shl44[] = {
+  2.0833916664123535156,  -3.0418450832366943359,   3.2047898769378662109,
+  -2.7571926116943359375, 1.4978630542755126953,  -0.3427594602108001709,
+  -0.71733748912811279297,  1.0737057924270629883, -1.0225815773010253906,
+  0.56649994850158691406, -0.20968692004680633545, -0.065378531813621520996,
+  0.10322438180446624756, -0.067442022264003753662, -0.00495197344571352005,
+  0,
+};
+static double const shh44[] = {
+   3.0259189605712890625, -6.0268716812133789062,   9.195003509521484375,
+   -11.824929237365722656, 12.767142295837402344, -11.917946815490722656,
+   9.1739168167114257812,  -5.3712320327758789062, 1.1393624544143676758,
+   2.4484779834747314453,  -4.9719839096069335938,   6.0392003059387207031,
+   -5.9359521865844726562,  4.903278350830078125,   -3.5527443885803222656,
+   2.1909697055816650391, -1.1672389507293701172,  0.4903914332389831543,
+   -0.16519790887832641602,  0.023217858746647834778,
+};
+
+static const filter_t filters[] = {
+  {44100, fir,  5, 210, lip44,          SWR_DITHER_NS_LIPSHITZ},
+  {46000, fir,  9, 276, fwe44,          SWR_DITHER_NS_F_WEIGHTED},
+  {46000, fir,  9, 160, mew44,          SWR_DITHER_NS_MODIFIED_E_WEIGHTED},
+  {46000, fir,  9, 321, iew44,          SWR_DITHER_NS_IMPROVED_E_WEIGHTED},
+//   {48000, iir,  4, 220, ges48, SWR_DITHER_NS_GESEMANN},
+//   {44100, iir,  4, 230, ges44, SWR_DITHER_NS_GESEMANN},
+  {48000, fir, 16, 301, shi48,          SWR_DITHER_NS_SHIBATA},
+  {44100, fir, 20, 333, shi44,          SWR_DITHER_NS_SHIBATA},
+  {37800, fir, 16, 240, shi38,          SWR_DITHER_NS_SHIBATA},
+  {32000, fir, 20, 240/*TBD*/, shi32,   SWR_DITHER_NS_SHIBATA},
+  {22050, fir, 20, 240/*TBD*/, shi22,   SWR_DITHER_NS_SHIBATA},
+  {16000, fir, 20, 240/*TBD*/, shi16,   SWR_DITHER_NS_SHIBATA},
+  {11025, fir, 20, 240/*TBD*/, shi11,   SWR_DITHER_NS_SHIBATA},
+  { 8000, fir, 20, 240/*TBD*/, shi08,   SWR_DITHER_NS_SHIBATA},
+  {48000, fir, 16, 250, shl48,          SWR_DITHER_NS_LOW_SHIBATA},
+  {44100, fir, 15, 250, shl44,          SWR_DITHER_NS_LOW_SHIBATA},
+  {44100, fir, 20, 383, shh44,          SWR_DITHER_NS_HIGH_SHIBATA},
+  {    0, fir,  0,   0,  NULL,          SWR_DITHER_NONE},
+};
diff --git a/mythtv/external/FFmpeg/libswresample/resample.c b/mythtv/external/FFmpeg/libswresample/resample.c
index 6cd2b8cbcb6..fb9da7c3541 100644
--- a/mythtv/external/FFmpeg/libswresample/resample.c
+++ b/mythtv/external/FFmpeg/libswresample/resample.c
@@ -142,7 +142,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap
             break;
         case AV_SAMPLE_FMT_S32P:
             for(i=0;ifactor        = factor;
         c->filter_length = FFMAX((int)ceil(filter_size/factor), 1);
         c->filter_alloc  = FFALIGN(c->filter_length, 8);
-        c->filter_bank   = av_mallocz(c->filter_alloc*(phase_count+1)*c->felem_size);
+        c->filter_bank   = av_calloc(c->filter_alloc, (phase_count+1)*c->felem_size);
         c->filter_type   = filter_type;
         c->kaiser_beta   = kaiser_beta;
         if (!c->filter_bank)
diff --git a/mythtv/external/FFmpeg/libswresample/resample_template.c b/mythtv/external/FFmpeg/libswresample/resample_template.c
index b62901d69d8..5bc12bcb712 100644
--- a/mythtv/external/FFmpeg/libswresample/resample_template.c
+++ b/mythtv/external/FFmpeg/libswresample/resample_template.c
@@ -151,7 +151,7 @@ int RENAME(swri_resample)(ResampleContext *c, DELEM *dst, const DELEM *src, int
                 break;
             }else if(sample_index < 0){
                 for(i=0; ifilter_length; i++)
-                    val += src[FFABS(sample_index + i)] * filter[i];
+                    val += src[FFABS(sample_index + i)] * (FELEM2)filter[i];
             }else if(c->linear){
                 FELEM2 v2=0;
                 for(i=0; ifilter_length; i++){
diff --git a/mythtv/external/FFmpeg/libswresample/soxr_resample.c b/mythtv/external/FFmpeg/libswresample/soxr_resample.c
index 15fcc83bf18..4c000db0ca7 100644
--- a/mythtv/external/FFmpeg/libswresample/soxr_resample.c
+++ b/mythtv/external/FFmpeg/libswresample/soxr_resample.c
@@ -47,7 +47,11 @@ static struct ResampleContext *create(struct ResampleContext *c, int out_rate, i
 
     soxr_quality_spec_t q_spec = soxr_quality_spec((int)((precision-2)/4), (SOXR_HI_PREC_CLOCK|SOXR_ROLLOFF_NONE)*!!cheby);
     q_spec.precision = linear? 0 : precision;
+#if !defined SOXR_VERSION /* Deprecated @ March 2013: */
     q_spec.bw_pc = cutoff? FFMAX(FFMIN(cutoff,.995),.8)*100 : q_spec.bw_pc;
+#else
+    q_spec.passband_end = cutoff? FFMAX(FFMIN(cutoff,.995),.8) : q_spec.passband_end;
+#endif
 
     soxr_delete((soxr_t)c);
     c = (struct ResampleContext *)
diff --git a/mythtv/external/FFmpeg/libswresample/swresample-test.c b/mythtv/external/FFmpeg/libswresample/swresample-test.c
index 7f50cb48d0e..379d385315a 100644
--- a/mythtv/external/FFmpeg/libswresample/swresample-test.c
+++ b/mythtv/external/FFmpeg/libswresample/swresample-test.c
@@ -65,7 +65,7 @@ static void  set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFor
     switch(f){
     case AV_SAMPLE_FMT_U8 : ((uint8_t*)p)[index]= av_clip_uint8 (lrint((v+1.0)*127));     break;
     case AV_SAMPLE_FMT_S16: ((int16_t*)p)[index]= av_clip_int16 (lrint(v*32767));         break;
-    case AV_SAMPLE_FMT_S32: ((int32_t*)p)[index]= av_clipl_int32(lrint(v*2147483647));    break;
+    case AV_SAMPLE_FMT_S32: ((int32_t*)p)[index]= av_clipl_int32(llrint(v*2147483647));   break;
     case AV_SAMPLE_FMT_FLT: ((float  *)p)[index]= v;                                      break;
     case AV_SAMPLE_FMT_DBL: ((double *)p)[index]= v;                                      break;
     default: av_assert2(0);
diff --git a/mythtv/external/FFmpeg/libswresample/swresample.c b/mythtv/external/FFmpeg/libswresample/swresample.c
index e93f707390c..9b71b2e1221 100644
--- a/mythtv/external/FFmpeg/libswresample/swresample.c
+++ b/mythtv/external/FFmpeg/libswresample/swresample.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011-2012 Michael Niedermayer (michaelni@gmx.at)
+ * Copyright (C) 2011-2013 Michael Niedermayer (michaelni@gmx.at)
  *
  * This file is part of libswresample
  *
@@ -73,17 +73,28 @@ static const AVOption options[]={
 {"swr_flags"            , "set flags"                   , OFFSET(flags          ), AV_OPT_TYPE_FLAGS, {.i64=0                     }, 0      , UINT_MAX  , PARAM, "flags"},
 {"res"                  , "force resampling"            , 0                      , AV_OPT_TYPE_CONST, {.i64=SWR_FLAG_RESAMPLE     }, INT_MIN, INT_MAX   , PARAM, "flags"},
 
-{"dither_scale"         , "set dither scale"            , OFFSET(dither_scale   ), AV_OPT_TYPE_FLOAT, {.dbl=1                     }, 0      , INT_MAX   , PARAM},
+{"dither_scale"         , "set dither scale"            , OFFSET(dither.scale   ), AV_OPT_TYPE_FLOAT, {.dbl=1                     }, 0      , INT_MAX   , PARAM},
 
-{"dither_method"        , "set dither method"           , OFFSET(dither_method  ), AV_OPT_TYPE_INT  , {.i64=0                     }, 0      , SWR_DITHER_NB-1, PARAM, "dither_method"},
+{"dither_method"        , "set dither method"           , OFFSET(dither.method  ), AV_OPT_TYPE_INT  , {.i64=0                     }, 0      , SWR_DITHER_NB-1, PARAM, "dither_method"},
 {"rectangular"          , "select rectangular dither"   , 0                      , AV_OPT_TYPE_CONST, {.i64=SWR_DITHER_RECTANGULAR}, INT_MIN, INT_MAX   , PARAM, "dither_method"},
 {"triangular"           , "select triangular dither"    , 0                      , AV_OPT_TYPE_CONST, {.i64=SWR_DITHER_TRIANGULAR }, INT_MIN, INT_MAX   , PARAM, "dither_method"},
-{"triangular_hp"        , "select triangular dither with high pass" , 0                 , AV_OPT_TYPE_CONST, {.i64=SWR_DITHER_TRIANGULAR_HIGHPASS }, INT_MIN, INT_MAX, PARAM, "dither_method"},
+{"triangular_hp"        , "select triangular dither with high pass" , 0          , AV_OPT_TYPE_CONST, {.i64=SWR_DITHER_TRIANGULAR_HIGHPASS }, INT_MIN, INT_MAX, PARAM, "dither_method"},
+{"lipshitz"             , "select lipshitz noise shaping dither" , 0             , AV_OPT_TYPE_CONST, {.i64=SWR_DITHER_NS_LIPSHITZ}, INT_MIN, INT_MAX, PARAM, "dither_method"},
+{"shibata"              , "select shibata noise shaping dither" , 0              , AV_OPT_TYPE_CONST, {.i64=SWR_DITHER_NS_SHIBATA }, INT_MIN, INT_MAX, PARAM, "dither_method"},
+{"low_shibata"          , "select low shibata noise shaping dither" , 0          , AV_OPT_TYPE_CONST, {.i64=SWR_DITHER_NS_LOW_SHIBATA }, INT_MIN, INT_MAX, PARAM, "dither_method"},
+{"high_shibata"         , "select high shibata noise shaping dither" , 0         , AV_OPT_TYPE_CONST, {.i64=SWR_DITHER_NS_HIGH_SHIBATA }, INT_MIN, INT_MAX, PARAM, "dither_method"},
+{"f_weighted"           , "select f-weighted noise shaping dither" , 0           , AV_OPT_TYPE_CONST, {.i64=SWR_DITHER_NS_F_WEIGHTED }, INT_MIN, INT_MAX, PARAM, "dither_method"},
+{"modified_e_weighted"  , "select modified-e-weighted noise shaping dither" , 0  , AV_OPT_TYPE_CONST, {.i64=SWR_DITHER_NS_MODIFIED_E_WEIGHTED }, INT_MIN, INT_MAX, PARAM, "dither_method"},
+{"improved_e_weighted"  , "select improved-e-weighted noise shaping dither" , 0  , AV_OPT_TYPE_CONST, {.i64=SWR_DITHER_NS_IMPROVED_E_WEIGHTED }, INT_MIN, INT_MAX, PARAM, "dither_method"},
 
 {"filter_size"          , "set swr resampling filter size", OFFSET(filter_size)  , AV_OPT_TYPE_INT  , {.i64=32                    }, 0      , INT_MAX   , PARAM },
-{"phase_shift"          , "set swr resampling phase shift", OFFSET(phase_shift)  , AV_OPT_TYPE_INT  , {.i64=10                    }, 0      , 30        , PARAM },
+{"phase_shift"          , "set swr resampling phase shift", OFFSET(phase_shift)  , AV_OPT_TYPE_INT  , {.i64=10                    }, 0      , 24        , PARAM },
 {"linear_interp"        , "enable linear interpolation" , OFFSET(linear_interp)  , AV_OPT_TYPE_INT  , {.i64=0                     }, 0      , 1         , PARAM },
 {"cutoff"               , "set cutoff frequency ratio"  , OFFSET(cutoff)         , AV_OPT_TYPE_DOUBLE,{.dbl=0.                    }, 0      , 1         , PARAM },
+
+/* duplicate option in order to work with avconv */
+{"resample_cutoff"      , "set cutoff frequency ratio"  , OFFSET(cutoff)         , AV_OPT_TYPE_DOUBLE,{.dbl=0.                    }, 0      , 1         , PARAM },
+
 {"resampler"            , "set resampling Engine"       , OFFSET(engine)         , AV_OPT_TYPE_INT  , {.i64=0                     }, 0      , SWR_ENGINE_NB-1, PARAM, "resampler"},
 {"swr"                  , "select SW Resampler"         , 0                      , AV_OPT_TYPE_CONST, {.i64=SWR_ENGINE_SWR        }, INT_MIN, INT_MAX   , PARAM, "resampler"},
 {"soxr"                 , "select SoX Resampler"        , 0                      , AV_OPT_TYPE_CONST, {.i64=SWR_ENGINE_SOXR       }, INT_MIN, INT_MAX   , PARAM, "resampler"},
@@ -101,6 +112,8 @@ static const AVOption options[]={
                                                         , OFFSET(max_soft_compensation),AV_OPT_TYPE_FLOAT ,{.dbl=0                     }, INT_MIN, INT_MAX   , PARAM },
 {"async"                , "simplified 1 parameter audio timestamp matching, 0(disabled), 1(filling and trimming), >1(maximum stretch/squeeze in samples per second)"
                                                         , OFFSET(async)          , AV_OPT_TYPE_FLOAT ,{.dbl=0                     }, INT_MIN, INT_MAX   , PARAM },
+{"first_pts"            , "Assume the first pts should be this value (in samples)."
+                                                        , OFFSET(firstpts_in_samples), AV_OPT_TYPE_INT64 ,{.i64=AV_NOPTS_VALUE    }, INT64_MIN,INT64_MAX, PARAM },
 
 { "matrix_encoding"     , "set matrixed stereo encoding" , OFFSET(matrix_encoding), AV_OPT_TYPE_INT   ,{.i64 = AV_MATRIX_ENCODING_NONE}, AV_MATRIX_ENCODING_NONE,     AV_MATRIX_ENCODING_NB-1, PARAM, "matrix_encoding" },
     { "none",  "select none",               0, AV_OPT_TYPE_CONST, { .i64 = AV_MATRIX_ENCODING_NONE  }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
@@ -114,6 +127,7 @@ static const AVOption options[]={
 
 { "kaiser_beta"         , "set swr Kaiser Window Beta"  , OFFSET(kaiser_beta)    , AV_OPT_TYPE_INT  , {.i64=9                     }, 2      , 16        , PARAM },
 
+{ "output_sample_bits"   , ""  , OFFSET(dither.output_sample_bits)               , AV_OPT_TYPE_INT  , {.i64=0                     }, 0      , 64        , 0 },
 {0}
 };
 
@@ -210,7 +224,10 @@ av_cold void swr_free(SwrContext **ss){
         free_temp(&s->midbuf);
         free_temp(&s->preout);
         free_temp(&s->in_buffer);
-        free_temp(&s->dither);
+        free_temp(&s->silence);
+        free_temp(&s->drop_temp);
+        free_temp(&s->dither.noise);
+        free_temp(&s->dither.temp);
         swri_audio_convert_free(&s-> in_convert);
         swri_audio_convert_free(&s->out_convert);
         swri_audio_convert_free(&s->full_convert);
@@ -223,6 +240,7 @@ av_cold void swr_free(SwrContext **ss){
 }
 
 av_cold int swr_init(struct SwrContext *s){
+    int ret;
     s->in_buffer_index= 0;
     s->in_buffer_count= 0;
     s->resample_in_constraint= 0;
@@ -230,7 +248,10 @@ av_cold int swr_init(struct SwrContext *s){
     free_temp(&s->midbuf);
     free_temp(&s->preout);
     free_temp(&s->in_buffer);
-    free_temp(&s->dither);
+    free_temp(&s->silence);
+    free_temp(&s->drop_temp);
+    free_temp(&s->dither.noise);
+    free_temp(&s->dither.temp);
     memset(s->in.ch, 0, sizeof(s->in.ch));
     memset(s->out.ch, 0, sizeof(s->out.ch));
     swri_audio_convert_free(&s-> in_convert);
@@ -259,9 +280,41 @@ av_cold int swr_init(struct SwrContext *s){
         s->out_ch_layout = 0;
     }
 
+    switch(s->engine){
+#if CONFIG_LIBSOXR
+        extern struct Resampler const soxr_resampler;
+        case SWR_ENGINE_SOXR: s->resampler = &soxr_resampler; break;
+#endif
+        case SWR_ENGINE_SWR : s->resampler = &swri_resampler; break;
+        default:
+            av_log(s, AV_LOG_ERROR, "Requested resampling engine is unavailable\n");
+            return AVERROR(EINVAL);
+    }
+
+    if(!s->used_ch_count)
+        s->used_ch_count= s->in.ch_count;
+
+    if(s->used_ch_count && s-> in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){
+        av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
+        s-> in_ch_layout= 0;
+    }
+
+    if(!s-> in_ch_layout)
+        s-> in_ch_layout= av_get_default_channel_layout(s->used_ch_count);
+    if(!s->out_ch_layout)
+        s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count);
+
+    s->rematrix= s->out_ch_layout  !=s->in_ch_layout || s->rematrix_volume!=1.0 ||
+                 s->rematrix_custom;
+
     if(s->int_sample_fmt == AV_SAMPLE_FMT_NONE){
         if(av_get_planar_sample_fmt(s->in_sample_fmt) <= AV_SAMPLE_FMT_S16P){
             s->int_sample_fmt= AV_SAMPLE_FMT_S16P;
+        }else if(   av_get_planar_sample_fmt(s-> in_sample_fmt) == AV_SAMPLE_FMT_S32P
+                 && av_get_planar_sample_fmt(s->out_sample_fmt) == AV_SAMPLE_FMT_S32P
+                 && !s->rematrix
+                 && s->engine != SWR_ENGINE_SOXR){
+            s->int_sample_fmt= AV_SAMPLE_FMT_S32P;
         }else if(av_get_planar_sample_fmt(s->in_sample_fmt) <= AV_SAMPLE_FMT_FLTP){
             s->int_sample_fmt= AV_SAMPLE_FMT_FLTP;
         }else{
@@ -278,20 +331,17 @@ av_cold int swr_init(struct SwrContext *s){
         return AVERROR(EINVAL);
     }
 
-    switch(s->engine){
-#if CONFIG_LIBSOXR
-        extern struct Resampler const soxr_resampler;
-        case SWR_ENGINE_SOXR: s->resampler = &soxr_resampler; break;
-#endif
-        case SWR_ENGINE_SWR : s->resampler = &swri_resampler; break;
-        default:
-            av_log(s, AV_LOG_ERROR, "Requested resampling engine is unavailable\n");
-            return AVERROR(EINVAL);
-    }
-
     set_audiodata_fmt(&s-> in, s-> in_sample_fmt);
     set_audiodata_fmt(&s->out, s->out_sample_fmt);
 
+    if (s->firstpts_in_samples != AV_NOPTS_VALUE) {
+        if (!s->async && s->min_compensation >= FLT_MAX/2)
+            s->async = 1;
+        s->firstpts =
+        s->outpts   = s->firstpts_in_samples * s->out_sample_rate;
+    } else
+        s->firstpts = AV_NOPTS_VALUE;
+
     if (s->async) {
         if (s->min_compensation >= FLT_MAX/2)
             s->min_compensation = 0.001;
@@ -313,22 +363,6 @@ av_cold int swr_init(struct SwrContext *s){
         return -1;
     }
 
-    if(!s->used_ch_count)
-        s->used_ch_count= s->in.ch_count;
-
-    if(s->used_ch_count && s-> in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){
-        av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
-        s-> in_ch_layout= 0;
-    }
-
-    if(!s-> in_ch_layout)
-        s-> in_ch_layout= av_get_default_channel_layout(s->used_ch_count);
-    if(!s->out_ch_layout)
-        s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count);
-
-    s->rematrix= s->out_ch_layout  !=s->in_ch_layout || s->rematrix_volume!=1.0 ||
-                 s->rematrix_custom;
-
 #define RSC 1 //FIXME finetune
     if(!s-> in.ch_count)
         s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout);
@@ -357,8 +391,10 @@ av_assert0(s->out.ch_count);
     s->resample_first= RSC*s->out.ch_count/s->in.ch_count - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0;
 
     s->in_buffer= s->in;
+    s->silence  = s->in;
+    s->drop_temp= s->out;
 
-    if(!s->resample && !s->rematrix && !s->channel_map && !s->dither_method){
+    if(!s->resample && !s->rematrix && !s->channel_map && !s->dither.method){
         s->full_convert = swri_audio_convert_alloc(s->out_sample_fmt,
                                                    s-> in_sample_fmt, s-> in.ch_count, NULL, 0);
         return 0;
@@ -369,6 +405,8 @@ av_assert0(s->out.ch_count);
     s->out_convert= swri_audio_convert_alloc(s->out_sample_fmt,
                                              s->int_sample_fmt, s->out.ch_count, NULL, 0);
 
+    if (!s->in_convert || !s->out_convert)
+        return AVERROR(ENOMEM);
 
     s->postin= s->in;
     s->preout= s->out;
@@ -394,9 +432,10 @@ av_assert0(s->out.ch_count);
         set_audiodata_fmt(&s->in_buffer, s->int_sample_fmt);
     }
 
-    s->dither = s->preout;
+    if ((ret = swri_dither_init(s, s->out_sample_fmt, s->int_sample_fmt)) < 0)
+        return ret;
 
-    if(s->rematrix || s->dither_method)
+    if(s->rematrix || s->dither.method)
         return swri_rematrix_init(s);
 
     return 0;
@@ -641,28 +680,54 @@ static int swr_convert_internal(struct SwrContext *s, AudioData *out, int out_co
     }
 
     if(preout != out && out_count){
-        if(s->dither_method){
+        AudioData *conv_src = preout;
+        if(s->dither.method){
             int ch;
             int dither_count= FFMAX(out_count, 1<<16);
-            av_assert0(preout != in);
 
-            if((ret=swri_realloc_audio(&s->dither, dither_count))<0)
+            if (preout == in) {
+                conv_src = &s->dither.temp;
+                if((ret=swri_realloc_audio(&s->dither.temp, dither_count))<0)
+                    return ret;
+            }
+
+            if((ret=swri_realloc_audio(&s->dither.noise, dither_count))<0)
                 return ret;
             if(ret)
-                for(ch=0; chdither.ch_count; ch++)
-                    swri_get_dither(s, s->dither.ch[ch], s->dither.count, 12345678913579<out_sample_fmt, s->int_sample_fmt);
-            av_assert0(s->dither.ch_count == preout->ch_count);
-
-            if(s->dither_pos + out_count > s->dither.count)
-                s->dither_pos = 0;
-
-            for(ch=0; chch_count; ch++)
-                s->mix_2_1_f(preout->ch[ch], preout->ch[ch], s->dither.ch[ch] + s->dither.bps * s->dither_pos, s->native_one, 0, 0, out_count);
-
-            s->dither_pos += out_count;
+                for(ch=0; chdither.noise.ch_count; ch++)
+                    swri_get_dither(s, s->dither.noise.ch[ch], s->dither.noise.count, 12345678913579<dither.noise.fmt);
+            av_assert0(s->dither.noise.ch_count == preout->ch_count);
+
+            if(s->dither.noise_pos + out_count > s->dither.noise.count)
+                s->dither.noise_pos = 0;
+
+            if (s->dither.method < SWR_DITHER_NS){
+                if (s->mix_2_1_simd) {
+                    int len1= out_count&~15;
+                    int off = len1 * preout->bps;
+
+                    if(len1)
+                        for(ch=0; chch_count; ch++)
+                            s->mix_2_1_simd(conv_src->ch[ch], preout->ch[ch], s->dither.noise.ch[ch] + s->dither.noise.bps * s->dither.noise_pos, s->native_one, 0, 0, len1);
+                    if(out_count != len1)
+                        for(ch=0; chch_count; ch++)
+                            s->mix_2_1_f(conv_src->ch[ch] + off, preout->ch[ch] + off, s->dither.noise.ch[ch] + s->dither.noise.bps * s->dither.noise_pos + off + len1, s->native_one, 0, 0, out_count - len1);
+                } else {
+                    for(ch=0; chch_count; ch++)
+                        s->mix_2_1_f(conv_src->ch[ch], preout->ch[ch], s->dither.noise.ch[ch] + s->dither.noise.bps * s->dither.noise_pos, s->native_one, 0, 0, out_count);
+                }
+            } else {
+                switch(s->int_sample_fmt) {
+                case AV_SAMPLE_FMT_S16P :swri_noise_shaping_int16(s, conv_src, preout, &s->dither.noise, out_count); break;
+                case AV_SAMPLE_FMT_S32P :swri_noise_shaping_int32(s, conv_src, preout, &s->dither.noise, out_count); break;
+                case AV_SAMPLE_FMT_FLTP :swri_noise_shaping_float(s, conv_src, preout, &s->dither.noise, out_count); break;
+                case AV_SAMPLE_FMT_DBLP :swri_noise_shaping_double(s,conv_src, preout, &s->dither.noise, out_count); break;
+                }
+            }
+            s->dither.noise_pos += out_count;
         }
 //FIXME packed doesnt need more than 1 chan here!
-        swri_audio_convert(s->out_convert, out, preout, out_count);
+        swri_audio_convert(s->out_convert, out, conv_src, out_count);
     }
     return out_count;
 }
@@ -672,26 +737,25 @@ int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_coun
     AudioData * in= &s->in;
     AudioData *out= &s->out;
 
-    if(s->drop_output > 0){
+    while(s->drop_output > 0){
         int ret;
-        AudioData tmp = s->out;
         uint8_t *tmp_arg[SWR_CH_MAX];
-        tmp.count = 0;
-        tmp.data  = NULL;
-        if((ret=swri_realloc_audio(&tmp, s->drop_output))<0)
+#define MAX_DROP_STEP 16384
+        if((ret=swri_realloc_audio(&s->drop_temp, FFMIN(s->drop_output, MAX_DROP_STEP)))<0)
             return ret;
 
-        reversefill_audiodata(&tmp, tmp_arg);
+        reversefill_audiodata(&s->drop_temp, tmp_arg);
         s->drop_output *= -1; //FIXME find a less hackish solution
-        ret = swr_convert(s, tmp_arg, -s->drop_output, in_arg, in_count); //FIXME optimize but this is as good as never called so maybe it doesnt matter
+        ret = swr_convert(s, tmp_arg, FFMIN(-s->drop_output, MAX_DROP_STEP), in_arg, in_count); //FIXME optimize but this is as good as never called so maybe it doesnt matter
         s->drop_output *= -1;
-        if(ret>0)
+        in_count = 0;
+        if(ret>0) {
             s->drop_output -= ret;
+            continue;
+        }
 
-        av_freep(&tmp.data);
         if(s->drop_output || !out_arg)
             return 0;
-        in_count = 0;
     }
 
     if(!in_arg){
@@ -779,26 +843,29 @@ int swr_drop_output(struct SwrContext *s, int count){
 
 int swr_inject_silence(struct SwrContext *s, int count){
     int ret, i;
-    AudioData silence = s->in;
     uint8_t *tmp_arg[SWR_CH_MAX];
 
     if(count <= 0)
         return 0;
 
-    silence.count = 0;
-    silence.data  = NULL;
-    if((ret=swri_realloc_audio(&silence, count))<0)
+#define MAX_SILENCE_STEP 16384
+    while (count > MAX_SILENCE_STEP) {
+        if ((ret = swr_inject_silence(s, MAX_SILENCE_STEP)) < 0)
+            return ret;
+        count -= MAX_SILENCE_STEP;
+    }
+
+    if((ret=swri_realloc_audio(&s->silence, count))<0)
         return ret;
 
-    if(silence.planar) for(i=0; isilence.planar) for(i=0; isilence.ch_count; i++) {
+        memset(s->silence.ch[i], s->silence.bps==1 ? 0x80 : 0, count*s->silence.bps);
     } else
-        memset(silence.ch[0], silence.bps==1 ? 0x80 : 0, count*silence.bps*silence.ch_count);
+        memset(s->silence.ch[0], s->silence.bps==1 ? 0x80 : 0, count*s->silence.bps*s->silence.ch_count);
 
-    reversefill_audiodata(&silence, tmp_arg);
+    reversefill_audiodata(&s->silence, tmp_arg);
     av_log(s, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", count);
     ret = swr_convert(s, NULL, 0, (const uint8_t**)tmp_arg, count);
-    av_freep(&silence.data);
     return ret;
 }
 
@@ -833,6 +900,10 @@ int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensatio
 int64_t swr_next_pts(struct SwrContext *s, int64_t pts){
     if(pts == INT64_MIN)
         return s->outpts;
+
+    if (s->firstpts == AV_NOPTS_VALUE)
+        s->outpts = s->firstpts = pts;
+
     if(s->min_compensation >= FLT_MAX) {
         return (s->outpts = pts - swr_get_delay(s, s->in_sample_rate * (int64_t)s->out_sample_rate));
     } else {
@@ -840,7 +911,7 @@ int64_t swr_next_pts(struct SwrContext *s, int64_t pts){
         double fdelta = delta /(double)(s->in_sample_rate * (int64_t)s->out_sample_rate);
 
         if(fabs(fdelta) > s->min_compensation) {
-            if(!s->outpts || fabs(fdelta) > s->min_hard_compensation){
+            if(s->outpts == s->firstpts || fabs(fdelta) > s->min_hard_compensation){
                 int ret;
                 if(delta > 0) ret = swr_inject_silence(s,  delta / s->out_sample_rate);
                 else          ret = swr_drop_output   (s, -delta / s-> in_sample_rate);
diff --git a/mythtv/external/FFmpeg/libswresample/swresample.h b/mythtv/external/FFmpeg/libswresample/swresample.h
index 1c6090dfbf2..95e8a5a0931 100644
--- a/mythtv/external/FFmpeg/libswresample/swresample.h
+++ b/mythtv/external/FFmpeg/libswresample/swresample.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011-2012 Michael Niedermayer (michaelni@gmx.at)
+ * Copyright (C) 2011-2013 Michael Niedermayer (michaelni@gmx.at)
  *
  * This file is part of libswresample
  *
@@ -111,6 +111,15 @@ enum SwrDitherType {
     SWR_DITHER_RECTANGULAR,
     SWR_DITHER_TRIANGULAR,
     SWR_DITHER_TRIANGULAR_HIGHPASS,
+
+    SWR_DITHER_NS = 64,         ///< not part of API/ABI
+    SWR_DITHER_NS_LIPSHITZ,
+    SWR_DITHER_NS_F_WEIGHTED,
+    SWR_DITHER_NS_MODIFIED_E_WEIGHTED,
+    SWR_DITHER_NS_IMPROVED_E_WEIGHTED,
+    SWR_DITHER_NS_SHIBATA,
+    SWR_DITHER_NS_LOW_SHIBATA,
+    SWR_DITHER_NS_HIGH_SHIBATA,
     SWR_DITHER_NB,              ///< not part of API/ABI
 };
 
diff --git a/mythtv/external/FFmpeg/libswresample/swresample_internal.h b/mythtv/external/FFmpeg/libswresample/swresample_internal.h
index 70a361ba9e2..17b85d52634 100644
--- a/mythtv/external/FFmpeg/libswresample/swresample_internal.h
+++ b/mythtv/external/FFmpeg/libswresample/swresample_internal.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011-2012 Michael Niedermayer (michaelni@gmx.at)
+ * Copyright (C) 2011-2013 Michael Niedermayer (michaelni@gmx.at)
  *
  * This file is part of libswresample
  *
@@ -27,6 +27,8 @@
 
 #define SQRT3_2      1.22474487139158904909  /* sqrt(3/2) */
 
+#define NS_TAPS 20
+
 #if ARCH_X86_64
 typedef int64_t integer;
 #else
@@ -48,6 +50,22 @@ typedef struct AudioData{
     enum AVSampleFormat fmt;    ///< sample format
 } AudioData;
 
+struct DitherContext {
+    enum SwrDitherType method;
+    int noise_pos;
+    float scale;
+    float noise_scale;                              ///< Noise scale
+    int ns_taps;                                    ///< Noise shaping dither taps
+    float ns_scale;                                 ///< Noise shaping dither scale
+    float ns_scale_1;                               ///< Noise shaping dither scale^-1
+    int ns_pos;                                     ///< Noise shaping dither position
+    float ns_coeffs[NS_TAPS];                       ///< Noise shaping filter coefficients
+    float ns_errors[SWR_CH_MAX][2*NS_TAPS];
+    AudioData noise;                                ///< noise used for dithering
+    AudioData temp;                                 ///< temporary storage when writing into the input buffer isnt possible
+    int output_sample_bits;                         ///< the number of used output bits, needed to scale dither correctly
+};
+
 struct SwrContext {
     const AVClass *av_class;                        ///< AVClass used for AVOption and av_log()
     int log_level_offset;                           ///< logging level offset
@@ -68,9 +86,9 @@ struct SwrContext {
     const int *channel_map;                         ///< channel index (or -1 if muted channel) map
     int used_ch_count;                              ///< number of used input channels (mapped channel count if channel_map, otherwise in.ch_count)
     enum SwrEngine engine;
-    enum SwrDitherType dither_method;
-    int dither_pos;
-    float dither_scale;
+
+    struct DitherContext dither;
+
     int filter_size;                                /**< length of each FIR filter in the resampling filterbank relative to the cutoff frequency */
     int phase_shift;                                /**< log2 of the number of entries in the resampling polyphase filterbank */
     int linear_interp;                              /**< if 1 then the resampling FIR filter will be linearly interpolated */
@@ -85,6 +103,7 @@ struct SwrContext {
     float soft_compensation_duration;               ///< swr duration over which soft compensation is applied
     float max_soft_compensation;                    ///< swr maximum soft compensation in seconds over soft_compensation_duration
     float async;                                    ///< swr simple 1 parameter async, similar to ffmpegs -async
+    int64_t firstpts_in_samples;                    ///< swr first pts in samples
 
     int resample_first;                             ///< 1 if resampling must come first, 0 if rematrixing
     int rematrix;                                   ///< flag to indicate if rematrixing is needed (basically if input and output layouts mismatch)
@@ -96,12 +115,14 @@ struct SwrContext {
     AudioData preout;                               ///< pre-output audio data: used for rematrix/resample
     AudioData out;                                  ///< converted output audio data
     AudioData in_buffer;                            ///< cached audio data (convert and resample purpose)
-    AudioData dither;                               ///< noise used for dithering
+    AudioData silence;                              ///< temporary with silence
+    AudioData drop_temp;                            ///< temporary used to discard output
     int in_buffer_index;                            ///< cached buffer position
     int in_buffer_count;                            ///< cached buffer length
     int resample_in_constraint;                     ///< 1 if the input end was reach before the output end, 0 otherwise
     int flushed;                                    ///< 1 if data is to be flushed and no further input is expected
     int64_t outpts;                                 ///< output PTS
+    int64_t firstpts;                               ///< first PTS
     int drop_output;                                ///< number of output samples to drop
 
     struct AudioConvert *in_convert;                ///< input conversion context
@@ -152,12 +173,18 @@ int swri_resample_int32(struct ResampleContext *c, int32_t *dst, const int32_t *
 int swri_resample_float(struct ResampleContext *c, float   *dst, const float   *src, int *consumed, int src_size, int dst_size, int update_ctx);
 int swri_resample_double(struct ResampleContext *c,double  *dst, const double  *src, int *consumed, int src_size, int dst_size, int update_ctx);
 
+void swri_noise_shaping_int16 (SwrContext *s, AudioData *dsts, const AudioData *srcs, const AudioData *noises, int count);
+void swri_noise_shaping_int32 (SwrContext *s, AudioData *dsts, const AudioData *srcs, const AudioData *noises, int count);
+void swri_noise_shaping_float (SwrContext *s, AudioData *dsts, const AudioData *srcs, const AudioData *noises, int count);
+void swri_noise_shaping_double(SwrContext *s, AudioData *dsts, const AudioData *srcs, const AudioData *noises, int count);
+
 int swri_rematrix_init(SwrContext *s);
 void swri_rematrix_free(SwrContext *s);
 int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy);
 void swri_rematrix_init_x86(struct SwrContext *s);
 
-void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt);
+void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat noise_fmt);
+int swri_dither_init(SwrContext *s, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt);
 
 void swri_audio_convert_init_arm(struct AudioConvert *ac,
                                  enum AVSampleFormat out_fmt,
diff --git a/mythtv/external/FFmpeg/libswscale/input.c b/mythtv/external/FFmpeg/libswscale/input.c
index d3aeb221518..2def2de6c85 100644
--- a/mythtv/external/FFmpeg/libswscale/input.c
+++ b/mythtv/external/FFmpeg/libswscale/input.c
@@ -729,7 +729,7 @@ static av_always_inline void planar_rgb16_to_y(uint8_t *_dst, const uint8_t *_sr
         int b = rdpx(src[1] + i);
         int r = rdpx(src[2] + i);
 
-        dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT);
+        dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> (RGB2YUV_SHIFT + bpc - 14));
     }
 }
 
@@ -796,8 +796,8 @@ static av_always_inline void planar_rgb16_to_uv(uint8_t *_dstU, uint8_t *_dstV,
         int b = rdpx(src[1] + i);
         int r = rdpx(src[2] + i);
 
-        dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT;
-        dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT;
+        dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> (RGB2YUV_SHIFT + bpc - 14);
+        dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> (RGB2YUV_SHIFT + bpc - 14);
     }
 }
 #undef rdpx
diff --git a/mythtv/external/FFmpeg/libswscale/options.c b/mythtv/external/FFmpeg/libswscale/options.c
index f7d261cfcc8..fc571acd152 100644
--- a/mythtv/external/FFmpeg/libswscale/options.c
+++ b/mythtv/external/FFmpeg/libswscale/options.c
@@ -51,6 +51,7 @@ static const AVOption options[] = {
     { "full_chroma_int", "full chroma interpolation",     0,                 AV_OPT_TYPE_CONST,  { .i64  = SWS_FULL_CHR_H_INT }, INT_MIN, INT_MAX,        VE, "sws_flags" },
     { "full_chroma_inp", "full chroma input",             0,                 AV_OPT_TYPE_CONST,  { .i64  = SWS_FULL_CHR_H_INP }, INT_MIN, INT_MAX,        VE, "sws_flags" },
     { "bitexact",        "",                              0,                 AV_OPT_TYPE_CONST,  { .i64  = SWS_BITEXACT       }, INT_MIN, INT_MAX,        VE, "sws_flags" },
+    { "error_diffusion", "error diffusion dither",        0,                 AV_OPT_TYPE_CONST,  { .i64  = SWS_ERROR_DIFFUSION}, INT_MIN, INT_MAX,        VE, "sws_flags" },
 
     { "srcw",            "source width",                  OFFSET(srcW),      AV_OPT_TYPE_INT,    { .i64 = 16                 }, 1,       INT_MAX,        VE },
     { "srch",            "source height",                 OFFSET(srcH),      AV_OPT_TYPE_INT,    { .i64 = 16                 }, 1,       INT_MAX,        VE },
diff --git a/mythtv/external/FFmpeg/libswscale/output.c b/mythtv/external/FFmpeg/libswscale/output.c
index 8c200685a98..d9745fbab82 100644
--- a/mythtv/external/FFmpeg/libswscale/output.c
+++ b/mythtv/external/FFmpeg/libswscale/output.c
@@ -333,6 +333,7 @@ yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
     const uint8_t * const d128=dither_8x8_220[y&7];
     int i;
     unsigned acc = 0;
+    int err = 0;
 
     for (i = 0; i < dstW; i += 2) {
         int j;
@@ -349,12 +350,25 @@ yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
             Y1 = av_clip_uint8(Y1);
             Y2 = av_clip_uint8(Y2);
         }
-        accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
-        accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
+        if (c->flags & SWS_ERROR_DIFFUSION) {
+            Y1 += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
+            c->dither_error[0][i] = err;
+            acc = 2*acc + (Y1 >= 128);
+            Y1 -= 220*(acc&1);
+
+            err = Y2 + ((7*Y1 + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4);
+            c->dither_error[0][i+1] = Y1;
+            acc = 2*acc + (err >= 128);
+            err -= 220*(acc&1);
+        } else {
+            accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
+            accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
+        }
         if ((i & 7) == 6) {
             output_pixel(*dest++, acc);
         }
     }
+    c->dither_error[0][i] = err;
 
     if (i & 6) {
         output_pixel(*dest, acc);
@@ -373,6 +387,29 @@ yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
     int  yalpha1 = 4096 - yalpha;
     int i;
 
+    if (c->flags & SWS_ERROR_DIFFUSION) {
+        int err = 0;
+        int acc = 0;
+        for (i = 0; i < dstW; i +=2) {
+            int Y;
+
+            Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
+            Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
+            c->dither_error[0][i] = err;
+            acc = 2*acc + (Y >= 128);
+            Y -= 220*(acc&1);
+
+            err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
+            err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
+            c->dither_error[0][i+1] = Y;
+            acc = 2*acc + (err >= 128);
+            err -= 220*(acc&1);
+
+            if ((i & 7) == 6)
+                output_pixel(*dest++, acc);
+        }
+        c->dither_error[0][i] = err;
+    } else {
     for (i = 0; i < dstW; i += 8) {
         int Y, acc = 0;
 
@@ -395,6 +432,7 @@ yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
 
         output_pixel(*dest++, acc);
     }
+    }
 }
 
 static av_always_inline void
@@ -406,9 +444,31 @@ yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
     const uint8_t * const d128 = dither_8x8_220[y & 7];
     int i;
 
+    if (c->flags & SWS_ERROR_DIFFUSION) {
+        int err = 0;
+        int acc = 0;
+        for (i = 0; i < dstW; i +=2) {
+            int Y;
+
+            Y = ((buf0[i + 0] + 64) >> 7);
+            Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
+            c->dither_error[0][i] = err;
+            acc = 2*acc + (Y >= 128);
+            Y -= 220*(acc&1);
+
+            err = ((buf0[i + 1] + 64) >> 7);
+            err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
+            c->dither_error[0][i+1] = Y;
+            acc = 2*acc + (err >= 128);
+            err -= 220*(acc&1);
+
+            if ((i & 7) == 6)
+                output_pixel(*dest++, acc);
+        }
+        c->dither_error[0][i] = err;
+    } else {
     for (i = 0; i < dstW; i += 8) {
         int acc = 0;
-
         accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
         accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
         accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
@@ -420,6 +480,7 @@ yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
 
         output_pixel(*dest++, acc);
     }
+    }
 }
 
 #undef output_pixel
@@ -1166,6 +1227,8 @@ yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
 {
     int i;
     int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
+    int err[4] = {0};
+    int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
 
     for (i = 0; i < dstW; i++) {
         int j;
@@ -1240,9 +1303,48 @@ yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
             dest[2] = R >> 22;
             dest[3] = hasAlpha ? A : 255;
             break;
+        case AV_PIX_FMT_BGR4_BYTE:
+        case AV_PIX_FMT_RGB4_BYTE:
+        case AV_PIX_FMT_BGR8:
+        case AV_PIX_FMT_RGB8:
+        {
+            int r,g,b;
+            R >>= 22;
+            G >>= 22;
+            B >>= 22;
+            R += (7*err[0] + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2])>>4;
+            G += (7*err[1] + 1*c->dither_error[1][i] + 5*c->dither_error[1][i+1] + 3*c->dither_error[1][i+2])>>4;
+            B += (7*err[2] + 1*c->dither_error[2][i] + 5*c->dither_error[2][i+1] + 3*c->dither_error[2][i+2])>>4;
+            c->dither_error[0][i] = err[0];
+            c->dither_error[1][i] = err[1];
+            c->dither_error[2][i] = err[2];
+            r = R >> (isrgb8 ? 5 : 7);
+            g = G >> (isrgb8 ? 5 : 6);
+            b = B >> (isrgb8 ? 6 : 7);
+            r = av_clip(r, 0, isrgb8 ? 7 : 1);
+            g = av_clip(g, 0, isrgb8 ? 7 : 3);
+            b = av_clip(b, 0, isrgb8 ? 3 : 1);
+            err[0] = R - r*(isrgb8 ? 36 : 255);
+            err[1] = G - g*(isrgb8 ? 36 : 85);
+            err[2] = B - b*(isrgb8 ? 85 : 255);
+            if(target == AV_PIX_FMT_BGR4_BYTE) {
+                dest[0] = r + 2*g + 8*b;
+            } else if(target == AV_PIX_FMT_RGB4_BYTE) {
+                dest[0] = b + 2*g + 8*r;
+            } else if(target == AV_PIX_FMT_BGR8) {
+                dest[0] = r + 8*g + 64*b;
+            } else if(target == AV_PIX_FMT_RGB8) {
+                dest[0] = b + 4*g + 32*r;
+            } else
+                av_assert2(0);
+            step = 1;
+            break;}
         }
         dest += step;
     }
+    c->dither_error[0][i] = err[0];
+    c->dither_error[1][i] = err[1];
+    c->dither_error[2][i] = err[2];
 }
 
 #if CONFIG_SMALL
@@ -1265,13 +1367,96 @@ YUV2RGBWRAPPERX(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB,  0)
 YUV2RGBWRAPPERX(yuv2, rgb_full, bgr24_full,  AV_PIX_FMT_BGR24, 0)
 YUV2RGBWRAPPERX(yuv2, rgb_full, rgb24_full,  AV_PIX_FMT_RGB24, 0)
 
+YUV2RGBWRAPPERX(yuv2, rgb_full, bgr4_byte_full,  AV_PIX_FMT_BGR4_BYTE, 0)
+YUV2RGBWRAPPERX(yuv2, rgb_full, rgb4_byte_full,  AV_PIX_FMT_RGB4_BYTE, 0)
+YUV2RGBWRAPPERX(yuv2, rgb_full, bgr8_full,   AV_PIX_FMT_BGR8,  0)
+YUV2RGBWRAPPERX(yuv2, rgb_full, rgb8_full,   AV_PIX_FMT_RGB8,  0)
+
+static void
+yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
+                  const int16_t **lumSrc, int lumFilterSize,
+                  const int16_t *chrFilter, const int16_t **chrUSrc,
+                  const int16_t **chrVSrc, int chrFilterSize,
+                  const int16_t **alpSrc, uint8_t **dest,
+                  int dstW, int y)
+{
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
+    int i;
+    int hasAlpha = 0;
+    uint16_t **dest16 = (uint16_t**)dest;
+    int SH = 22 + 7 - desc->comp[0].depth_minus1;
+
+    for (i = 0; i < dstW; i++) {
+        int j;
+        int Y = 1 << 9;
+        int U = (1 << 9) - (128 << 19);
+        int V = (1 << 9) - (128 << 19);
+        int R, G, B, A;
+
+        for (j = 0; j < lumFilterSize; j++)
+            Y += lumSrc[j][i] * lumFilter[j];
+
+        for (j = 0; j < chrFilterSize; j++) {
+            U += chrUSrc[j][i] * chrFilter[j];
+            V += chrVSrc[j][i] * chrFilter[j];
+        }
+
+        Y >>= 10;
+        U >>= 10;
+        V >>= 10;
+
+        if (hasAlpha) {
+            A = 1 << 18;
+
+            for (j = 0; j < lumFilterSize; j++)
+                A += alpSrc[j][i] * lumFilter[j];
+
+            A >>= 19;
+
+            if (A & 0x100)
+                A = av_clip_uint8(A);
+        }
+
+        Y -= c->yuv2rgb_y_offset;
+        Y *= c->yuv2rgb_y_coeff;
+        Y += 1 << 21;
+        R = Y + V * c->yuv2rgb_v2r_coeff;
+        G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
+        B = Y +                            U * c->yuv2rgb_u2b_coeff;
+
+        if ((R | G | B) & 0xC0000000) {
+            R = av_clip_uintp2(R, 30);
+            G = av_clip_uintp2(G, 30);
+            B = av_clip_uintp2(B, 30);
+        }
+
+        if (SH != 22) {
+            dest16[0][i] = G >> SH;
+            dest16[1][i] = B >> SH;
+            dest16[2][i] = R >> SH;
+        } else {
+            dest[0][i] = G >> 22;
+            dest[1][i] = B >> 22;
+            dest[2][i] = R >> 22;
+        }
+    }
+    if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
+        for (i = 0; i < dstW; i++) {
+            dest16[0][i] = av_bswap16(dest16[0][i]);
+            dest16[1][i] = av_bswap16(dest16[1][i]);
+            dest16[2][i] = av_bswap16(dest16[2][i]);
+        }
+    }
+}
+
 av_cold void ff_sws_init_output_funcs(SwsContext *c,
                                       yuv2planar1_fn *yuv2plane1,
                                       yuv2planarX_fn *yuv2planeX,
                                       yuv2interleavedX_fn *yuv2nv12cX,
                                       yuv2packed1_fn *yuv2packed1,
                                       yuv2packed2_fn *yuv2packed2,
-                                      yuv2packedX_fn *yuv2packedX)
+                                      yuv2packedX_fn *yuv2packedX,
+                                      yuv2anyX_fn *yuv2anyX)
 {
     enum AVPixelFormat dstFormat = c->dstFormat;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
@@ -1365,8 +1550,33 @@ av_cold void ff_sws_init_output_funcs(SwsContext *c,
         case AV_PIX_FMT_BGR24:
             *yuv2packedX = yuv2bgr24_full_X_c;
             break;
+        case AV_PIX_FMT_BGR4_BYTE:
+            *yuv2packedX = yuv2bgr4_byte_full_X_c;
+            break;
+        case AV_PIX_FMT_RGB4_BYTE:
+            *yuv2packedX = yuv2rgb4_byte_full_X_c;
+            break;
+        case AV_PIX_FMT_BGR8:
+            *yuv2packedX = yuv2bgr8_full_X_c;
+            break;
+        case AV_PIX_FMT_RGB8:
+            *yuv2packedX = yuv2rgb8_full_X_c;
+            break;
+        case AV_PIX_FMT_GBRP:
+        case AV_PIX_FMT_GBRP9BE:
+        case AV_PIX_FMT_GBRP9LE:
+        case AV_PIX_FMT_GBRP10BE:
+        case AV_PIX_FMT_GBRP10LE:
+        case AV_PIX_FMT_GBRP12BE:
+        case AV_PIX_FMT_GBRP12LE:
+        case AV_PIX_FMT_GBRP14BE:
+        case AV_PIX_FMT_GBRP14LE:
+        case AV_PIX_FMT_GBRP16BE:
+        case AV_PIX_FMT_GBRP16LE:
+            *yuv2anyX = yuv2gbrp_full_X_c;
+            break;
         }
-        if(!*yuv2packedX)
+        if (!*yuv2packedX && !*yuv2anyX)
             goto YUV_PACKED;
     } else {
         YUV_PACKED:
diff --git a/mythtv/external/FFmpeg/libswscale/swscale-test.c b/mythtv/external/FFmpeg/libswscale/swscale-test.c
index 7e5f09e295b..aece61e8664 100644
--- a/mythtv/external/FFmpeg/libswscale/swscale-test.c
+++ b/mythtv/external/FFmpeg/libswscale/swscale-test.c
@@ -124,7 +124,7 @@ static int doTest(uint8_t *ref[4], int refStride[4], int w, int h,
             res = -1;
             goto end;
         }
-        sws_scale(srcContext, ref, refStride, 0, h, src, srcStride);
+        sws_scale(srcContext, (const uint8_t * const*)ref, refStride, 0, h, src, srcStride);
         sws_freeContext(srcContext);
 
         cur_srcFormat = srcFormat;
@@ -166,7 +166,7 @@ static int doTest(uint8_t *ref[4], int refStride[4], int w, int h,
            flags);
     fflush(stdout);
 
-    sws_scale(dstContext, src, srcStride, 0, srcH, dst, dstStride);
+    sws_scale(dstContext, (const uint8_t * const*)src, srcStride, 0, srcH, dst, dstStride);
 
     for (i = 0; i < 4 && dstStride[i]; i++)
         crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), crc, dst[i],
@@ -198,7 +198,7 @@ static int doTest(uint8_t *ref[4], int refStride[4], int w, int h,
             res = -1;
             goto end;
         }
-        sws_scale(outContext, dst, dstStride, 0, dstH, out, refStride);
+        sws_scale(outContext, (const uint8_t * const*)dst, dstStride, 0, dstH, out, refStride);
 
         ssdY = getSSD(ref[0], out[0], refStride[0], refStride[0], w, h);
         if (hasChroma(srcFormat) && hasChroma(dstFormat)) {
diff --git a/mythtv/external/FFmpeg/libswscale/swscale.c b/mythtv/external/FFmpeg/libswscale/swscale.c
index 2c9e3da86e0..bb908191dc4 100644
--- a/mythtv/external/FFmpeg/libswscale/swscale.c
+++ b/mythtv/external/FFmpeg/libswscale/swscale.c
@@ -369,6 +369,7 @@ static int swScale(SwsContext *c, const uint8_t *src[],
     yuv2packed1_fn yuv2packed1       = c->yuv2packed1;
     yuv2packed2_fn yuv2packed2       = c->yuv2packed2;
     yuv2packedX_fn yuv2packedX       = c->yuv2packedX;
+    yuv2anyX_fn yuv2anyX             = c->yuv2anyX;
     const int chrSrcSliceY           =     srcSliceY  >> c->chrSrcVSubSample;
     const int chrSrcSliceH           = -((-srcSliceH) >> c->chrSrcVSubSample);
     int should_dither                = is9_OR_10BPS(c->srcFormat) ||
@@ -557,7 +558,7 @@ static int swScale(SwsContext *c, const uint8_t *src[],
             /* hmm looks like we can't use MMX here without overwriting
              * this array's tail */
             ff_sws_init_output_funcs(c, &yuv2plane1, &yuv2planeX, &yuv2nv12cX,
-                                     &yuv2packed1, &yuv2packed2, &yuv2packedX);
+                                     &yuv2packed1, &yuv2packed2, &yuv2packedX, &yuv2anyX);
             use_mmx_vfilter= 0;
         }
 
@@ -630,9 +631,9 @@ static int swScale(SwsContext *c, const uint8_t *src[],
                                    dstW, c->lumDither8, 0);
                     }
                 }
-            } else {
-                av_assert1(lumSrcPtr  + vLumFilterSize - 1 < lumPixBuf  + vLumBufSize * 2);
-                av_assert1(chrUSrcPtr + vChrFilterSize - 1 < chrUPixBuf + vChrBufSize * 2);
+            } else if (yuv2packedX) {
+                av_assert1(lumSrcPtr  + vLumFilterSize - 1 < (const int16_t **)lumPixBuf  + vLumBufSize * 2);
+                av_assert1(chrUSrcPtr + vChrFilterSize - 1 < (const int16_t **)chrUPixBuf + vChrBufSize * 2);
                 if (c->yuv2packed1 && vLumFilterSize == 1 &&
                     vChrFilterSize <= 2) { // unscaled RGB
                     int chrAlpha = vChrFilterSize == 1 ? 0 : vChrFilter[2 * dstY + 1];
@@ -657,6 +658,13 @@ static int swScale(SwsContext *c, const uint8_t *src[],
                                 chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
                                 alpSrcPtr, dest[0], dstW, dstY);
                 }
+            } else {
+                av_assert1(!yuv2packed1 && !yuv2packed2);
+                yuv2anyX(c, vLumFilter + dstY * vLumFilterSize,
+                         lumSrcPtr, vLumFilterSize,
+                         vChrFilter + dstY * vChrFilterSize,
+                         chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
+                         alpSrcPtr, dest, dstW, dstY);
             }
         }
     }
@@ -695,7 +703,7 @@ static av_cold void sws_init_swScale_c(SwsContext *c)
 
     ff_sws_init_output_funcs(c, &c->yuv2plane1, &c->yuv2planeX,
                              &c->yuv2nv12cX, &c->yuv2packed1,
-                             &c->yuv2packed2, &c->yuv2packedX);
+                             &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
 
     ff_sws_init_input_funcs(c);
 
@@ -910,6 +918,11 @@ int attribute_align_arg sws_scale(struct SwsContext *c,
         src2[0] = base;
     }
 
+    if (!srcSliceY && (c->flags & SWS_BITEXACT) && (c->flags & SWS_ERROR_DIFFUSION) && c->dither_error[0])
+        for (i = 0; i < 4; i++)
+            memset(c->dither_error[i], 0, sizeof(c->dither_error[0][0]) * (c->dstW+2));
+
+
     // copy strides, so they can safely be modified
     if (c->sliceDir == 1) {
         // slices go from top to bottom
diff --git a/mythtv/external/FFmpeg/libswscale/swscale.h b/mythtv/external/FFmpeg/libswscale/swscale.h
index ac789412a1f..5f6ae0ff469 100644
--- a/mythtv/external/FFmpeg/libswscale/swscale.h
+++ b/mythtv/external/FFmpeg/libswscale/swscale.h
@@ -82,6 +82,7 @@ const char *swscale_license(void);
 #define SWS_DIRECT_BGR        0x8000
 #define SWS_ACCURATE_RND      0x40000
 #define SWS_BITEXACT          0x80000
+#define SWS_ERROR_DIFFUSION  0x800000
 
 #if FF_API_SWS_CPU_CAPS
 /**
diff --git a/mythtv/external/FFmpeg/libswscale/swscale_internal.h b/mythtv/external/FFmpeg/libswscale/swscale_internal.h
index 6a942d67998..83d3a0049c3 100644
--- a/mythtv/external/FFmpeg/libswscale/swscale_internal.h
+++ b/mythtv/external/FFmpeg/libswscale/swscale_internal.h
@@ -223,6 +223,40 @@ typedef void (*yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter,
                                const int16_t **alpSrc, uint8_t *dest,
                                int dstW, int y);
 
+/**
+ * Write one line of horizontally scaled Y/U/V/A to YUV/RGB
+ * output by doing multi-point vertical scaling between input pixels.
+ *
+ * @param c             SWS scaling context
+ * @param lumFilter     vertical luma/alpha scaling coefficients, 12bit [0,4096]
+ * @param lumSrc        scaled luma (Y) source data, 15bit for 8-10bit output,
+ *                      19-bit for 16bit output (in int32_t)
+ * @param lumFilterSize number of vertical luma/alpha input lines to scale
+ * @param chrFilter     vertical chroma scaling coefficients, 12bit [0,4096]
+ * @param chrUSrc       scaled chroma (U) source data, 15bit for 8-10bit output,
+ *                      19-bit for 16bit output (in int32_t)
+ * @param chrVSrc       scaled chroma (V) source data, 15bit for 8-10bit output,
+ *                      19-bit for 16bit output (in int32_t)
+ * @param chrFilterSize number of vertical chroma input lines to scale
+ * @param alpSrc        scaled alpha (A) source data, 15bit for 8-10bit output,
+ *                      19-bit for 16bit output (in int32_t)
+ * @param dest          pointer to the output planes. For 16bit output, this is
+ *                      uint16_t
+ * @param dstW          width of lumSrc and alpSrc in pixels, number of pixels
+ *                      to write into dest[]
+ * @param y             vertical line number for this output. This does not need
+ *                      to be used to calculate the offset in the destination,
+ *                      but can be used to generate comfort noise using dithering
+ *                      or some output formats.
+ */
+typedef void (*yuv2anyX_fn)(struct SwsContext *c, const int16_t *lumFilter,
+                            const int16_t **lumSrc, int lumFilterSize,
+                            const int16_t *chrFilter,
+                            const int16_t **chrUSrc,
+                            const int16_t **chrVSrc, int chrFilterSize,
+                            const int16_t **alpSrc, uint8_t **dest,
+                            int dstW, int y);
+
 /* This struct should be aligned on at least a 32-byte boundary. */
 typedef struct SwsContext {
     /**
@@ -327,6 +361,8 @@ typedef struct SwsContext {
     int table_gV[256 + 2*YUVRGB_TABLE_HEADROOM];
     uint8_t *table_bU[256 + 2*YUVRGB_TABLE_HEADROOM];
 
+    int *dither_error[4];
+
     //Colorspace stuff
     int contrast, brightness, saturation;    // for sws_getColorspaceDetails
     int srcColorspaceTable[4];
@@ -435,6 +471,7 @@ typedef struct SwsContext {
     yuv2packed1_fn yuv2packed1;
     yuv2packed2_fn yuv2packed2;
     yuv2packedX_fn yuv2packedX;
+    yuv2anyX_fn yuv2anyX;
 
     /// Unscaled conversion of luma plane to YV12 for horizontal scaler.
     void (*lumToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
@@ -679,6 +716,15 @@ static av_always_inline int isRGB(enum AVPixelFormat pix_fmt)
     (           \
           isRGBinInt(x)       ||    \
           isBGRinInt(x)       ||    \
+          isRGB(x)            ||    \
+          (x)==AV_PIX_FMT_GBRP9LE  || \
+          (x)==AV_PIX_FMT_GBRP9BE  || \
+          (x)==AV_PIX_FMT_GBRP10LE || \
+          (x)==AV_PIX_FMT_GBRP10BE || \
+          (x)==AV_PIX_FMT_GBRP12LE || \
+          (x)==AV_PIX_FMT_GBRP12BE || \
+          (x)==AV_PIX_FMT_GBRP14LE || \
+          (x)==AV_PIX_FMT_GBRP14BE || \
           (x)==AV_PIX_FMT_GBR24P     \
     )
 
@@ -686,7 +732,7 @@ static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
 {
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     av_assert0(desc);
-    return desc->nb_components == 2 || desc->nb_components == 4;
+    return desc->flags & PIX_FMT_ALPHA;
 }
 
 #if 1
@@ -766,7 +812,8 @@ void ff_sws_init_output_funcs(SwsContext *c,
                               yuv2interleavedX_fn *yuv2nv12cX,
                               yuv2packed1_fn *yuv2packed1,
                               yuv2packed2_fn *yuv2packed2,
-                              yuv2packedX_fn *yuv2packedX);
+                              yuv2packedX_fn *yuv2packedX,
+                              yuv2anyX_fn *yuv2anyX);
 void ff_sws_init_swScale_altivec(SwsContext *c);
 void ff_sws_init_swScale_mmx(SwsContext *c);
 
diff --git a/mythtv/external/FFmpeg/libswscale/swscale_unscaled.c b/mythtv/external/FFmpeg/libswscale/swscale_unscaled.c
index 44a6902e243..8da73b26c2d 100644
--- a/mythtv/external/FFmpeg/libswscale/swscale_unscaled.c
+++ b/mythtv/external/FFmpeg/libswscale/swscale_unscaled.c
@@ -488,6 +488,80 @@ static int planarRgbToRgbWrapper(SwsContext *c, const uint8_t *src[],
     return srcSliceH;
 }
 
+static void packedtogbr24p(const uint8_t *src, int srcStride,
+                           uint8_t *dst[], int dstStride[], int srcSliceH,
+                           int alpha_first, int inc_size, int width)
+{
+    uint8_t *dest[3];
+    int x, h;
+
+    dest[0] = dst[0];
+    dest[1] = dst[1];
+    dest[2] = dst[2];
+
+    if (alpha_first)
+        src++;
+
+    for (h = 0; h < srcSliceH; h++) {
+        for (x = 0; x < width; x++) {
+            dest[0][x] = src[0];
+            dest[1][x] = src[1];
+            dest[2][x] = src[2];
+
+            src += inc_size;
+        }
+        src     += srcStride - width * inc_size;
+        dest[0] += dstStride[0];
+        dest[1] += dstStride[1];
+        dest[2] += dstStride[2];
+    }
+}
+
+static int rgbToPlanarRgbWrapper(SwsContext *c, const uint8_t *src[],
+                                 int srcStride[], int srcSliceY, int srcSliceH,
+                                 uint8_t *dst[], int dstStride[])
+{
+    int alpha_first = 0;
+    int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
+    int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
+    uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
+                          dst[0] + srcSliceY * dstStride[0],
+                          dst[2] + srcSliceY * dstStride[2] };
+    uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
+                          dst[0] + srcSliceY * dstStride[0],
+                          dst[1] + srcSliceY * dstStride[1] };
+
+    switch (c->srcFormat) {
+    case PIX_FMT_RGB24:
+        packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
+                       stride201, srcSliceH, alpha_first, 3, c->srcW);
+        break;
+    case PIX_FMT_BGR24:
+        packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
+                       stride102, srcSliceH, alpha_first, 3, c->srcW);
+        break;
+    case PIX_FMT_ARGB:
+        alpha_first = 1;
+    case PIX_FMT_RGBA:
+        packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
+                       stride201, srcSliceH, alpha_first, 4, c->srcW);
+        break;
+    case PIX_FMT_ABGR:
+        alpha_first = 1;
+    case PIX_FMT_BGRA:
+        packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
+                       stride102, srcSliceH, alpha_first, 4, c->srcW);
+        break;
+    default:
+        av_log(c, AV_LOG_ERROR,
+               "unsupported planar RGB conversion %s -> %s\n",
+               av_get_pix_fmt_name(c->srcFormat),
+               av_get_pix_fmt_name(c->dstFormat));
+    }
+
+    return srcSliceH;
+}
+
 #define isRGBA32(x) (            \
            (x) == AV_PIX_FMT_ARGB   \
         || (x) == AV_PIX_FMT_RGBA   \
@@ -939,7 +1013,7 @@ void ff_get_unscaled_swscale(SwsContext *c)
     /* yuv2bgr */
     if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUV422P ||
          srcFormat == AV_PIX_FMT_YUVA420P) && isAnyRGB(dstFormat) &&
-        !(flags & SWS_ACCURATE_RND) && !(dstH & 1)) {
+        !(flags & (SWS_ACCURATE_RND|SWS_ERROR_DIFFUSION)) && !(dstH & 1)) {
         c->swScale = ff_yuv2rgb_get_func_ptr(c);
     }
 
@@ -960,17 +1034,21 @@ void ff_get_unscaled_swscale(SwsContext *c)
         && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT))))
         c->swScale= rgbToRgbWrapper;
 
-#define isByteRGB(f) (\
-        f == AV_PIX_FMT_RGB32   ||\
-        f == AV_PIX_FMT_RGB32_1 ||\
-        f == AV_PIX_FMT_RGB24   ||\
-        f == AV_PIX_FMT_BGR32   ||\
-        f == AV_PIX_FMT_BGR32_1 ||\
+#define isByteRGB(f) (             \
+        f == AV_PIX_FMT_RGB32   || \
+        f == AV_PIX_FMT_RGB32_1 || \
+        f == AV_PIX_FMT_RGB24   || \
+        f == AV_PIX_FMT_BGR32   || \
+        f == AV_PIX_FMT_BGR32_1 || \
         f == AV_PIX_FMT_BGR24)
 
-    if (isAnyRGB(srcFormat) && isPlanar(srcFormat) && isByteRGB(dstFormat))
+    if (srcFormat == AV_PIX_FMT_GBRP && isPlanar(srcFormat) && isByteRGB(dstFormat))
         c->swScale = planarRgbToRgbWrapper;
 
+    if (av_pix_fmt_desc_get(srcFormat)->comp[0].depth_minus1 == 7 &&
+        isPackedRGB(srcFormat) && dstFormat == AV_PIX_FMT_GBRP)
+        c->swScale = rgbToPlanarRgbWrapper;
+
     /* bswap 16 bits per pixel/component packed formats */
     if (IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR444) ||
         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR48)  ||
diff --git a/mythtv/external/FFmpeg/libswscale/utils.c b/mythtv/external/FFmpeg/libswscale/utils.c
index 89bf0da59bd..932cf9424c0 100644
--- a/mythtv/external/FFmpeg/libswscale/utils.c
+++ b/mythtv/external/FFmpeg/libswscale/utils.c
@@ -185,15 +185,15 @@ static const FormatEntry format_entries[AV_PIX_FMT_NB] = {
     [AV_PIX_FMT_YUV444P12LE] = { 1, 1 },
     [AV_PIX_FMT_YUV444P14BE] = { 1, 1 },
     [AV_PIX_FMT_YUV444P14LE] = { 1, 1 },
-    [AV_PIX_FMT_GBRP]        = { 1, 0 },
-    [AV_PIX_FMT_GBRP9LE]     = { 1, 0 },
-    [AV_PIX_FMT_GBRP9BE]     = { 1, 0 },
-    [AV_PIX_FMT_GBRP10LE]    = { 1, 0 },
-    [AV_PIX_FMT_GBRP10BE]    = { 1, 0 },
-    [AV_PIX_FMT_GBRP12LE]    = { 1, 0 },
-    [AV_PIX_FMT_GBRP12BE]    = { 1, 0 },
-    [AV_PIX_FMT_GBRP14LE]    = { 1, 0 },
-    [AV_PIX_FMT_GBRP14BE]    = { 1, 0 },
+    [AV_PIX_FMT_GBRP]        = { 1, 1 },
+    [AV_PIX_FMT_GBRP9LE]     = { 1, 1 },
+    [AV_PIX_FMT_GBRP9BE]     = { 1, 1 },
+    [AV_PIX_FMT_GBRP10LE]    = { 1, 1 },
+    [AV_PIX_FMT_GBRP10BE]    = { 1, 1 },
+    [AV_PIX_FMT_GBRP12LE]    = { 1, 1 },
+    [AV_PIX_FMT_GBRP12BE]    = { 1, 1 },
+    [AV_PIX_FMT_GBRP14LE]    = { 1, 1 },
+    [AV_PIX_FMT_GBRP14BE]    = { 1, 1 },
     [AV_PIX_FMT_GBRP16LE]    = { 1, 0 },
     [AV_PIX_FMT_GBRP16BE]    = { 1, 0 },
 };
@@ -991,7 +991,6 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
     getSubSampleFactors(&c->chrSrcHSubSample, &c->chrSrcVSubSample, srcFormat);
     getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat);
 
-
     if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) {
         if (dstW&1) {
             av_log(c, AV_LOG_DEBUG, "Forcing full internal H chroma due to odd output size\n");
@@ -999,16 +998,52 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
             c->flags = flags;
         }
     }
+
+    if(dstFormat == AV_PIX_FMT_BGR4_BYTE ||
+       dstFormat == AV_PIX_FMT_RGB4_BYTE ||
+       dstFormat == AV_PIX_FMT_BGR8 ||
+       dstFormat == AV_PIX_FMT_RGB8) {
+        if (flags & SWS_ERROR_DIFFUSION && !(flags & SWS_FULL_CHR_H_INT)) {
+            av_log(c, AV_LOG_DEBUG,
+                "Error diffusion dither is only supported in full chroma interpolation for destination format '%s'\n",
+                av_get_pix_fmt_name(dstFormat));
+            flags   |= SWS_FULL_CHR_H_INT;
+            c->flags = flags;
+        }
+        if (!(flags & SWS_ERROR_DIFFUSION) && (flags & SWS_FULL_CHR_H_INT)) {
+            av_log(c, AV_LOG_DEBUG,
+                "Ordered dither is not supported in full chroma interpolation for destination format '%s'\n",
+                av_get_pix_fmt_name(dstFormat));
+            flags   |= SWS_ERROR_DIFFUSION;
+            c->flags = flags;
+        }
+    }
+    if (isPlanarRGB(dstFormat)) {
+        if (!(flags & SWS_FULL_CHR_H_INT)) {
+            av_log(c, AV_LOG_DEBUG,
+                   "%s output is not supported with half chroma resolution, switching to full\n",
+                   av_get_pix_fmt_name(dstFormat));
+            flags   |= SWS_FULL_CHR_H_INT;
+            c->flags = flags;
+        }
+    }
+
     /* reuse chroma for 2 pixels RGB/BGR unless user wants full
      * chroma interpolation */
     if (flags & SWS_FULL_CHR_H_INT &&
         isAnyRGB(dstFormat)        &&
+        !isPlanarRGB(dstFormat)    &&
         dstFormat != AV_PIX_FMT_RGBA  &&
         dstFormat != AV_PIX_FMT_ARGB  &&
         dstFormat != AV_PIX_FMT_BGRA  &&
         dstFormat != AV_PIX_FMT_ABGR  &&
         dstFormat != AV_PIX_FMT_RGB24 &&
-        dstFormat != AV_PIX_FMT_BGR24) {
+        dstFormat != AV_PIX_FMT_BGR24 &&
+        dstFormat != AV_PIX_FMT_BGR4_BYTE &&
+        dstFormat != AV_PIX_FMT_RGB4_BYTE &&
+        dstFormat != AV_PIX_FMT_BGR8 &&
+        dstFormat != AV_PIX_FMT_RGB8
+    ) {
         av_log(c, AV_LOG_WARNING,
                "full chroma interpolation for destination format '%s' not yet implemented\n",
                av_get_pix_fmt_name(dstFormat));
@@ -1029,6 +1064,11 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
         srcFormat != AV_PIX_FMT_RGB8 && srcFormat != AV_PIX_FMT_BGR8 &&
         srcFormat != AV_PIX_FMT_RGB4 && srcFormat != AV_PIX_FMT_BGR4 &&
         srcFormat != AV_PIX_FMT_RGB4_BYTE && srcFormat != AV_PIX_FMT_BGR4_BYTE &&
+        srcFormat != AV_PIX_FMT_GBRP9BE   && srcFormat != AV_PIX_FMT_GBRP9LE  &&
+        srcFormat != AV_PIX_FMT_GBRP10BE  && srcFormat != AV_PIX_FMT_GBRP10LE &&
+        srcFormat != AV_PIX_FMT_GBRP12BE  && srcFormat != AV_PIX_FMT_GBRP12LE &&
+        srcFormat != AV_PIX_FMT_GBRP14BE  && srcFormat != AV_PIX_FMT_GBRP14LE &&
+        srcFormat != AV_PIX_FMT_GBRP16BE  && srcFormat != AV_PIX_FMT_GBRP16LE &&
         ((dstW >> c->chrDstHSubSample) <= (srcW >> 1) ||
          (flags & SWS_FAST_BILINEAR)))
         c->chrSrcHSubSample = 1;
@@ -1247,6 +1287,9 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
                              c->vChrFilterPos[chrI];
     }
 
+    for (i = 0; i < 4; i++)
+        FF_ALLOCZ_OR_GOTO(c, c->dither_error[i], (c->dstW+2) * sizeof(int), fail);
+
     /* Allocate pixbufs (we use dynamic allocation because otherwise we would
      * need to allocate several megabytes to handle all possible cases) */
     FF_ALLOC_OR_GOTO(c, c->lumPixBuf,  c->vLumBufSize * 3 * sizeof(int16_t *), fail);
@@ -1740,6 +1783,9 @@ void sws_freeContext(SwsContext *c)
         av_freep(&c->alpPixBuf);
     }
 
+    for (i = 0; i < 4; i++)
+        av_freep(&c->dither_error[i]);
+
     av_freep(&c->vLumFilter);
     av_freep(&c->vChrFilter);
     av_freep(&c->hLumFilter);
diff --git a/mythtv/external/FFmpeg/libswscale/version.h b/mythtv/external/FFmpeg/libswscale/version.h
index 49e280d3c88..c430f2def82 100644
--- a/mythtv/external/FFmpeg/libswscale/version.h
+++ b/mythtv/external/FFmpeg/libswscale/version.h
@@ -27,8 +27,8 @@
 #include "libavutil/avutil.h"
 
 #define LIBSWSCALE_VERSION_MAJOR 2
-#define LIBSWSCALE_VERSION_MINOR 1
-#define LIBSWSCALE_VERSION_MICRO 103
+#define LIBSWSCALE_VERSION_MINOR 2
+#define LIBSWSCALE_VERSION_MICRO 100
 
 #define LIBSWSCALE_VERSION_INT  AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \
                                                LIBSWSCALE_VERSION_MINOR, \
diff --git a/mythtv/external/FFmpeg/libswscale/x86/input.asm b/mythtv/external/FFmpeg/libswscale/x86/input.asm
index 327b9f0bc5e..9d5a8712550 100644
--- a/mythtv/external/FFmpeg/libswscale/x86/input.asm
+++ b/mythtv/external/FFmpeg/libswscale/x86/input.asm
@@ -98,7 +98,7 @@ cglobal %2 %+ 24ToY, 6, 6, %1, dst, src, u1, u2, w, u3
 %define coeff2 [%2_Ycoeff_3x56]
 %endif ; x86-32/64 && mmsize == 8/16
 %if (ARCH_X86_64 || mmsize == 8) && %0 == 3
-    jmp mangle(program_name %+ _ %+ %3 %+ 24ToY %+ SUFFIX).body
+    jmp mangle(private_prefix %+ _ %+ %3 %+ 24ToY %+ SUFFIX).body
 %else ; (ARCH_X86_64 && %0 == 3) || mmsize == 8
 .body:
 %if cpuflag(ssse3)
@@ -188,7 +188,7 @@ cglobal %2 %+ 24ToUV, 7, 7, %1, dstU, dstV, u1, src, u2, w, u3
 %define coeffV2 [%2_Vcoeff_3x56]
 %endif ; x86-32/64
 %if ARCH_X86_64 && %0 == 3
-    jmp mangle(program_name %+ _ %+ %3 %+ 24ToUV %+ SUFFIX).body
+    jmp mangle(private_prefix %+ _ %+ %3 %+ 24ToUV %+ SUFFIX).body
 %else ; ARCH_X86_64 && %0 == 3
 .body:
 %if cpuflag(ssse3)
@@ -315,7 +315,7 @@ cglobal %2%3%4%5 %+ ToY, 6, 6, %1, dst, src, u1, u2, w, u3
     mova           m5, [rgba_Ycoeff_%2%4]
     mova           m6, [rgba_Ycoeff_%3%5]
 %if %0 == 6
-    jmp mangle(program_name %+ _ %+ %6 %+ ToY %+ SUFFIX).body
+    jmp mangle(private_prefix %+ _ %+ %6 %+ ToY %+ SUFFIX).body
 %else ; %0 == 6
 .body:
 %if ARCH_X86_64
@@ -371,7 +371,7 @@ cglobal %2%3%4%5 %+ ToUV, 7, 7, %1, dstU, dstV, u1, src, u2, w, u3
 %define coeffV2 [rgba_Vcoeff_%3%5]
 %endif ; x86-64/32
 %if ARCH_X86_64 && %0 == 6
-    jmp mangle(program_name %+ _ %+ %6 %+ ToUV %+ SUFFIX).body
+    jmp mangle(private_prefix %+ _ %+ %6 %+ ToUV %+ SUFFIX).body
 %else ; ARCH_X86_64 && %0 == 6
 .body:
 %if ARCH_X86_64
diff --git a/mythtv/external/FFmpeg/libswscale/x86/swscale.c b/mythtv/external/FFmpeg/libswscale/x86/swscale.c
index 02c454e08f9..2f67b1b03f8 100644
--- a/mythtv/external/FFmpeg/libswscale/x86/swscale.c
+++ b/mythtv/external/FFmpeg/libswscale/x86/swscale.c
@@ -226,10 +226,20 @@ static void yuv2yuvX_sse3(const int16_t *filter, int filterSize,
                          :: "r"(dither)
                          );
     }
+    filterSize--;
     __asm__ volatile(
         "pxor      %%xmm0, %%xmm0\n\t"
         "punpcklbw %%xmm0, %%xmm3\n\t"
-        "psraw        $4, %%xmm3\n\t"
+        "movd          %0, %%xmm1\n\t"
+        "punpcklwd %%xmm1, %%xmm1\n\t"
+        "punpckldq %%xmm1, %%xmm1\n\t"
+        "punpcklqdq %%xmm1, %%xmm1\n\t"
+        "psllw         $3, %%xmm1\n\t"
+        "paddw     %%xmm1, %%xmm3\n\t"
+        "psraw         $4, %%xmm3\n\t"
+        ::"m"(filterSize)
+     );
+    __asm__ volatile(
         "movdqa    %%xmm3, %%xmm4\n\t"
         "movdqa    %%xmm3, %%xmm7\n\t"
         "movl %3, %%ecx\n\t"
diff --git a/mythtv/external/FFmpeg/libswscale/x86/swscale_template.c b/mythtv/external/FFmpeg/libswscale/x86/swscale_template.c
index 62265db30ff..f2567c1d8b5 100644
--- a/mythtv/external/FFmpeg/libswscale/x86/swscale_template.c
+++ b/mythtv/external/FFmpeg/libswscale/x86/swscale_template.c
@@ -71,9 +71,20 @@ static void RENAME(yuv2yuvX)(const int16_t *filter, int filterSize,
                            const uint8_t *dither, int offset)
 {
     dither_8to16(dither, offset);
-    __asm__ volatile(\
+    filterSize--;
+    __asm__ volatile(
+        "movd %0, %%mm1\n\t"
+        "punpcklwd %%mm1, %%mm1\n\t"
+        "punpckldq %%mm1, %%mm1\n\t"
+        "psllw        $3, %%mm1\n\t"
+        "paddw     %%mm1, %%mm3\n\t"
+        "paddw     %%mm1, %%mm4\n\t"
         "psraw        $4, %%mm3\n\t"
         "psraw        $4, %%mm4\n\t"
+        ::"m"(filterSize)
+     );
+
+    __asm__ volatile(\
         "movq    %%mm3, %%mm6\n\t"
         "movq    %%mm4, %%mm7\n\t"
         "movl %3, %%ecx\n\t"
diff --git a/mythtv/external/FFmpeg/libswscale/yuv2rgb.c b/mythtv/external/FFmpeg/libswscale/yuv2rgb.c
index 53b69d0f73b..d12abda9a87 100644
--- a/mythtv/external/FFmpeg/libswscale/yuv2rgb.c
+++ b/mythtv/external/FFmpeg/libswscale/yuv2rgb.c
@@ -919,7 +919,8 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
         break;
     default:
         c->yuvTable = NULL;
-        av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
+        if(!isPlanar(c->dstFormat) || bpp <= 24)
+            av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
         return -1;
     }
     return 0;
diff --git a/mythtv/external/FFmpeg/tests/Makefile b/mythtv/external/FFmpeg/tests/Makefile
index 9bb914eed37..73ee2d9c5d6 100644
--- a/mythtv/external/FFmpeg/tests/Makefile
+++ b/mythtv/external/FFmpeg/tests/Makefile
@@ -86,6 +86,7 @@ include $(SRC_PATH)/tests/fate/ffprobe.mak
 include $(SRC_PATH)/tests/fate/filter.mak
 include $(SRC_PATH)/tests/fate/flac.mak
 include $(SRC_PATH)/tests/fate/fft.mak
+include $(SRC_PATH)/tests/fate/gif.mak
 include $(SRC_PATH)/tests/fate/h264.mak
 include $(SRC_PATH)/tests/fate/image.mak
 include $(SRC_PATH)/tests/fate/indeo.mak
diff --git a/mythtv/external/FFmpeg/tests/fate/aac.mak b/mythtv/external/FFmpeg/tests/fate/aac.mak
index c5c47e6e729..0b3999da41a 100644
--- a/mythtv/external/FFmpeg/tests/fate/aac.mak
+++ b/mythtv/external/FFmpeg/tests/fate/aac.mak
@@ -98,7 +98,9 @@ FATE_AAC_ALL = $(FATE_AAC-yes) $(FATE_AAC_LATM-yes)
 $(FATE_AAC_ALL): CMP  = oneoff
 $(FATE_AAC_ALL): FUZZ = 2
 
-FATE_SAMPLES_FFMPEG += $(FATE_AAC_ALL) $(FATE_AAC_ENCODE)
+FATE_AAC_ENCODE-$(call ENCMUX, AAC, ADTS) += $(FATE_AAC_ENCODE)
+
+FATE_SAMPLES_FFMPEG += $(FATE_AAC_ALL) $(FATE_AAC_ENCODE-yes)
 
 fate-aac: $(FATE_AAC_ALL) $(FATE_AAC_ENCODE)
 fate-aac-latm: $(FATE_AAC_LATM-yes)
diff --git a/mythtv/external/FFmpeg/tests/fate/ac3.mak b/mythtv/external/FFmpeg/tests/fate/ac3.mak
index 2985a0e69a7..90dfc411f2e 100644
--- a/mythtv/external/FFmpeg/tests/fate/ac3.mak
+++ b/mythtv/external/FFmpeg/tests/fate/ac3.mak
@@ -1,46 +1,46 @@
 FATE_AC3 += fate-ac3-2.0
 fate-ac3-2.0: CMD = pcm -i $(SAMPLES)/ac3/monsters_inc_2.0_192_small.ac3
-fate-ac3-2.0: REF = $(SAMPLES)/ac3/monsters_inc_2.0_192_small.pcm
+fate-ac3-2.0: REF = $(SAMPLES)/ac3/monsters_inc_2.0_192_small_v2.pcm
 
 FATE_AC3 += fate-ac3-4.0
 fate-ac3-4.0: CMD = pcm -i $(SAMPLES)/ac3/millers_crossing_4.0.ac3
-fate-ac3-4.0: REF = $(SAMPLES)/ac3/millers_crossing_4.0.pcm
+fate-ac3-4.0: REF = $(SAMPLES)/ac3/millers_crossing_4.0_v2.pcm
 
 FATE_AC3 += fate-ac3-4.0-downmix-mono
 fate-ac3-4.0-downmix-mono: CMD = pcm -request_channels 1 -i $(SAMPLES)/ac3/millers_crossing_4.0.ac3
-fate-ac3-4.0-downmix-mono: REF = $(SAMPLES)/ac3/millers_crossing_4.0_mono.pcm
+fate-ac3-4.0-downmix-mono: REF = $(SAMPLES)/ac3/millers_crossing_4.0_mono_v2.pcm
 
 FATE_AC3 += fate-ac3-4.0-downmix-stereo
 fate-ac3-4.0-downmix-stereo: CMD = pcm -request_channels 2 -i $(SAMPLES)/ac3/millers_crossing_4.0.ac3
-fate-ac3-4.0-downmix-stereo: REF = $(SAMPLES)/ac3/millers_crossing_4.0_stereo.pcm
+fate-ac3-4.0-downmix-stereo: REF = $(SAMPLES)/ac3/millers_crossing_4.0_stereo_v2.pcm
 
 FATE_AC3 += fate-ac3-5.1
 fate-ac3-5.1: CMD = pcm -i $(SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
-fate-ac3-5.1: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small.pcm
+fate-ac3-5.1: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_v2.pcm
 
 FATE_AC3 += fate-ac3-5.1-downmix-mono
 fate-ac3-5.1-downmix-mono: CMD = pcm -request_channels 1 -i $(SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
-fate-ac3-5.1-downmix-mono: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_mono.pcm
+fate-ac3-5.1-downmix-mono: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_mono_v2.pcm
 
 FATE_AC3 += fate-ac3-5.1-downmix-stereo
 fate-ac3-5.1-downmix-stereo: CMD = pcm -request_channels 2 -i $(SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
-fate-ac3-5.1-downmix-stereo: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_stereo.pcm
+fate-ac3-5.1-downmix-stereo: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_stereo_v2.pcm
 
 FATE_EAC3 += fate-eac3-1
 fate-eac3-1: CMD = pcm -i $(SAMPLES)/eac3/csi_miami_5.1_256_spx_small.eac3
-fate-eac3-1: REF = $(SAMPLES)/eac3/csi_miami_5.1_256_spx_small.pcm
+fate-eac3-1: REF = $(SAMPLES)/eac3/csi_miami_5.1_256_spx_small_v2.pcm
 
 FATE_EAC3 += fate-eac3-2
 fate-eac3-2: CMD = pcm -i $(SAMPLES)/eac3/csi_miami_stereo_128_spx_small.eac3
-fate-eac3-2: REF = $(SAMPLES)/eac3/csi_miami_stereo_128_spx_small.pcm
+fate-eac3-2: REF = $(SAMPLES)/eac3/csi_miami_stereo_128_spx_small_v2.pcm
 
 FATE_EAC3 += fate-eac3-3
 fate-eac3-3: CMD = pcm -i $(SAMPLES)/eac3/matrix2_commentary1_stereo_192_small.eac3
-fate-eac3-3: REF = $(SAMPLES)/eac3/matrix2_commentary1_stereo_192_small.pcm
+fate-eac3-3: REF = $(SAMPLES)/eac3/matrix2_commentary1_stereo_192_small_v2.pcm
 
 FATE_EAC3 += fate-eac3-4
 fate-eac3-4: CMD = pcm -i $(SAMPLES)/eac3/serenity_english_5.1_1536_small.eac3
-fate-eac3-4: REF = $(SAMPLES)/eac3/serenity_english_5.1_1536_small.pcm
+fate-eac3-4: REF = $(SAMPLES)/eac3/serenity_english_5.1_1536_small_v2.pcm
 
 $(FATE_AC3) $(FATE_EAC3): CMP = oneoff
 
@@ -50,14 +50,14 @@ FATE_EAC3-$(call DEMDEC, EAC3, EAC3) += $(FATE_EAC3)
 FATE_AC3-$(call ENCDEC, AC3, AC3) += fate-ac3-encode
 fate-ac3-encode: CMD = enc_dec_pcm ac3 wav s16le $(REF) -c:a ac3 -b:a 128k
 fate-ac3-encode: CMP_SHIFT = -1024
-fate-ac3-encode: CMP_TARGET = 399.62
+fate-ac3-encode: CMP_TARGET = 404.53
 fate-ac3-encode: SIZE_TOLERANCE = 488
 fate-ac3-encode: FUZZ = 4
 
 FATE_EAC3-$(call ENCDEC, EAC3, EAC3) += fate-eac3-encode
 fate-eac3-encode: CMD = enc_dec_pcm eac3 wav s16le $(REF) -c:a eac3 -b:a 128k
 fate-eac3-encode: CMP_SHIFT = -1024
-fate-eac3-encode: CMP_TARGET = 514.02
+fate-eac3-encode: CMP_TARGET = 516.94
 fate-eac3-encode: SIZE_TOLERANCE = 488
 fate-eac3-encode: FUZZ = 3
 
diff --git a/mythtv/external/FFmpeg/tests/fate/avfilter.mak b/mythtv/external/FFmpeg/tests/fate/avfilter.mak
index 872ebc7b9c6..8ac8d41bb1d 100644
--- a/mythtv/external/FFmpeg/tests/fate/avfilter.mak
+++ b/mythtv/external/FFmpeg/tests/fate/avfilter.mak
@@ -11,9 +11,12 @@ FATE_LAVFI = fate-lavfi-alphaextract_rgb                                \
              fate-lavfi-fade                                            \
              fate-lavfi-field                                           \
              fate-lavfi-idet                                            \
+             fate-lavfi-il                                              \
              fate-lavfi-life                                            \
              fate-lavfi-null                                            \
-             fate-lavfi-overlay                                         \
+             fate-lavfi-overlay_rgb                                     \
+             fate-lavfi-overlay_yuv420                                  \
+             fate-lavfi-overlay_yuv444                                  \
              fate-lavfi-pad                                             \
              fate-lavfi-pixfmts_copy                                    \
              fate-lavfi-pixfmts_crop                                    \
diff --git a/mythtv/external/FFmpeg/tests/fate/cdxl.mak b/mythtv/external/FFmpeg/tests/fate/cdxl.mak
index 2c69e397492..11ff902a469 100644
--- a/mythtv/external/FFmpeg/tests/fate/cdxl.mak
+++ b/mythtv/external/FFmpeg/tests/fate/cdxl.mak
@@ -1,3 +1,6 @@
+FATE_CDXL += fate-cdxl-bitline-ham6
+fate-cdxl-bitline-ham6: CMD = framecrc -i $(SAMPLES)/cdxl/bitline.cdxl -frames:v 10
+
 FATE_CDXL += fate-cdxl-ham6
 fate-cdxl-ham6: CMD = framecrc -i $(SAMPLES)/cdxl/cat.cdxl -an -frames:v 16
 
@@ -10,9 +13,6 @@ fate-cdxl-pal8: CMD = framecrc -i $(SAMPLES)/cdxl/maku.cdxl -pix_fmt rgb24 -fram
 FATE_CDXL += fate-cdxl-pal8-small
 fate-cdxl-pal8-small: CMD = framecrc -i $(SAMPLES)/cdxl/fruit.cdxl -an -pix_fmt rgb24 -frames:v 46
 
-FATE_CDXL += fate-cdxl-bitline-ham6
-fate-cdxl-bitline-ham6: CMD = framecrc -i $(SAMPLES)/cdxl/bitline.cdxl -frames:v 10
-
 FATE_CDXL-$(call DEMDEC, CDXL, CDXL) += $(FATE_CDXL)
 
 FATE_SAMPLES_AVCONV += $(FATE_CDXL-yes)
diff --git a/mythtv/external/FFmpeg/tests/fate/cover-art.mak b/mythtv/external/FFmpeg/tests/fate/cover-art.mak
index dadfcd8901a..56a384e5fbc 100644
--- a/mythtv/external/FFmpeg/tests/fate/cover-art.mak
+++ b/mythtv/external/FFmpeg/tests/fate/cover-art.mak
@@ -14,6 +14,14 @@ FATE_COVER_ART += fate-cover-art-wma
 fate-cover-art-wma: CMD = md5 -i $(SAMPLES)/cover_art/Californication_cover.wma -an -c:v copy -f rawvideo
 fate-cover-art-wma: REF = 0808bd0e1b61542a16e1906812dd924b
 
+FATE_COVER_ART += fate-cover-art-wma-id3
+fate-cover-art-wma-id3: CMD = md5 -i $(SAMPLES)/cover_art/wma_with_ID3_APIC_trimmed.wma -an -c:v copy -f rawvideo
+fate-cover-art-wma-id3: REF = e6a8dd03687d5178bc13fc7d3316696e
+
+FATE_COVER_ART += fate-cover-art-wma-metadatalib
+fate-cover-art-wma-metadatalib: CMD = md5 -i $(SAMPLES)/cover_art/wma_with_metadata_library_object_tag_trimmed.wma -map 0:v -c:v copy -f rawvideo
+fate-cover-art-wma-metadatalib: REF = 32e8bd4fad546f63d881a0256f083aea
+
 FATE_COVER_ART += fate-cover-art-wv
 fate-cover-art-wv: CMD = md5 -i $(SAMPLES)/cover_art/luckynight_cover.wv -an -c:v copy -f rawvideo
 fate-cover-art-wv: REF = 45333c983c45af54449dff10af144317
diff --git a/mythtv/external/FFmpeg/tests/fate/demux.mak b/mythtv/external/FFmpeg/tests/fate/demux.mak
index 721f2b9cb0e..189ef27287e 100644
--- a/mythtv/external/FFmpeg/tests/fate/demux.mak
+++ b/mythtv/external/FFmpeg/tests/fate/demux.mak
@@ -25,6 +25,9 @@ fate-cdxl-demux: CMD = framecrc -i $(SAMPLES)/cdxl/mirage.cdxl -vcodec copy -aco
 FATE_SAMPLES_DEMUX-$(CONFIG_DAUD_DEMUXER) += fate-d-cinema-demux
 fate-d-cinema-demux: CMD = framecrc -i $(SAMPLES)/d-cinema/THX_Science_FLT_1920-partial.302 -acodec copy
 
+FATE_SAMPLES_DEMUX-$(CONFIG_GIF_DEMUXER) += fate-gif-demux
+fate-gif-demux: CMD = framecrc -i $(SAMPLES)/gif/Newtons_cradle_animation_book_2.gif -vcodec copy
+
 FATE_SAMPLES_DEMUX-$(CONFIG_IV8_DEMUXER) += fate-iv8-demux
 fate-iv8-demux: CMD = framecrc -i $(SAMPLES)/iv8/zzz-partial.mpg -vcodec copy
 
@@ -73,8 +76,8 @@ fate-qcp-demux: CMD = crc -i $(SAMPLES)/qcp/0036580847.QCP -acodec copy
 FATE_SAMPLES_DEMUX-$(CONFIG_R3D_DEMUXER) += fate-redcode-demux
 fate-redcode-demux: CMD = framecrc -i $(SAMPLES)/r3d/4MB-sample.r3d -vcodec copy -acodec copy
 
-FATE_SAMPLES_DEMUX-$(CONFIG_SIFF_DEMUXER) += fate-siff
-fate-siff: CMD = framecrc -i $(SAMPLES)/SIFF/INTRO_B.VB -t 3 -pix_fmt rgb24
+FATE_SAMPLES_DEMUX-$(CONFIG_SIFF_DEMUXER) += fate-siff-demux
+fate-siff-demux: CMD = framecrc -i $(SAMPLES)/SIFF/INTRO_B.VB -c copy
 
 FATE_SAMPLES_DEMUX-$(CONFIG_SMJPEG_DEMUXER) += fate-smjpeg-demux
 fate-smjpeg-demux: CMD = framecrc -i $(SAMPLES)/smjpeg/scenwin.mjpg -c copy
diff --git a/mythtv/external/FFmpeg/tests/fate/filter.mak b/mythtv/external/FFmpeg/tests/fate/filter.mak
index 589d4296418..e9742266fc3 100644
--- a/mythtv/external/FFmpeg/tests/fate/filter.mak
+++ b/mythtv/external/FFmpeg/tests/fate/filter.mak
@@ -28,7 +28,7 @@ fate-filter-asyncts: REF = $(SAMPLES)/nellymoser/nellymoser-discont-async-v2.pcm
 
 FATE_FILTER-$(CONFIG_ARESAMPLE_FILTER) += fate-filter-aresample
 fate-filter-aresample: SRC = $(SAMPLES)/nellymoser/nellymoser-discont.flv
-fate-filter-aresample: CMD = pcm -i $(SRC) -af aresample=min_comp=0.001:min_hard_comp=0.1
+fate-filter-aresample: CMD = pcm -i $(SRC) -af aresample=min_comp=0.001:min_hard_comp=0.1:first_pts=0
 fate-filter-aresample: CMP = oneoff
 fate-filter-aresample: REF = $(SAMPLES)/nellymoser/nellymoser-discont.pcm
 
diff --git a/mythtv/external/FFmpeg/tests/fate/flac.mak b/mythtv/external/FFmpeg/tests/fate/flac.mak
index 92eb7430dbf..172f661b790 100644
--- a/mythtv/external/FFmpeg/tests/fate/flac.mak
+++ b/mythtv/external/FFmpeg/tests/fate/flac.mak
@@ -22,5 +22,7 @@ fate-flac-24-%: CMD = enc_dec_pcm flac wav s24le $(REF) -c flac $(OPTS)
 fate-flac-%: CMP = oneoff
 fate-flac-%: FUZZ = 0
 
-FATE_SAMPLES_AVCONV += $(FATE_FLAC)
+FATE_FLAC-$(call ENCMUX, FLAC, FLAC) += $(FATE_FLAC)
+
+FATE_SAMPLES_AVCONV += $(FATE_FLAC-yes)
 fate-flac: $(FATE_FLAC)
diff --git a/mythtv/external/FFmpeg/tests/fate/gif.mak b/mythtv/external/FFmpeg/tests/fate/gif.mak
new file mode 100644
index 00000000000..97b0545381f
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/fate/gif.mak
@@ -0,0 +1,13 @@
+FATE_GIF += fate-gif-color
+fate-gif-color: CMD = framecrc -i $(SAMPLES)/gif/tc217.gif -pix_fmt bgra
+
+FATE_GIF += fate-gif-disposal-restore
+fate-gif-disposal-restore: CMD = framecrc -i $(SAMPLES)/gif/banner2.gif -pix_fmt bgra
+
+FATE_GIF += fate-gif-gray
+fate-gif-gray: CMD = framecrc -i $(SAMPLES)/gif/Newtons_cradle_animation_book_2.gif -pix_fmt bgra
+
+FATE_GIF-$(call DEMDEC, GIF, GIF) += $(FATE_GIF)
+
+FATE_SAMPLES_AVCONV += $(FATE_GIF-yes)
+fate-gif: $(FATE_GIF-yes)
diff --git a/mythtv/external/FFmpeg/tests/fate/image.mak b/mythtv/external/FFmpeg/tests/fate/image.mak
index abafd5f9079..2a6a4b27e7b 100644
--- a/mythtv/external/FFmpeg/tests/fate/image.mak
+++ b/mythtv/external/FFmpeg/tests/fate/image.mak
@@ -76,7 +76,7 @@ FATE_TIFF-$(call DEMDEC, IMAGE2, TIFF) += $(FATE_TIFF)
 FATE_IMAGE += $(FATE_TIFF-yes)
 fate-tiff: $(FATE_TIFF-yes)
 
-FATE_IMAGE += fate-xface
+FATE_IMAGE-$(call DEMDEC, IMAGE2, XFACE) += fate-xface
 fate-xface: CMD = framecrc -i $(SAMPLES)/xface/lena.xface
 
 FATE_IMAGE += $(FATE_IMAGE-yes)
diff --git a/mythtv/external/FFmpeg/tests/fate/libavformat.mak b/mythtv/external/FFmpeg/tests/fate/libavformat.mak
index b6eda42a63c..8332246949e 100644
--- a/mythtv/external/FFmpeg/tests/fate/libavformat.mak
+++ b/mythtv/external/FFmpeg/tests/fate/libavformat.mak
@@ -1,3 +1,11 @@
+FATE_LIBAVFORMAT += fate-noproxy
+fate-noproxy: libavformat/noproxy-test$(EXESUF)
+fate-noproxy: CMD = run libavformat/noproxy-test
+
+FATE_LIBAVFORMAT += fate-srtp
+fate-srtp: libavformat/srtp-test$(EXESUF)
+fate-srtp: CMD = run libavformat/srtp-test
+
 FATE_LIBAVFORMAT += fate-url
 fate-url: libavformat/url-test$(EXESUF)
 fate-url: CMD = run libavformat/url-test
diff --git a/mythtv/external/FFmpeg/tests/fate/libavutil.mak b/mythtv/external/FFmpeg/tests/fate/libavutil.mak
index b2484a57f95..ac5e9330b11 100644
--- a/mythtv/external/FFmpeg/tests/fate/libavutil.mak
+++ b/mythtv/external/FFmpeg/tests/fate/libavutil.mak
@@ -41,6 +41,10 @@ FATE_LIBAVUTIL += fate-fifo
 fate-fifo: libavutil/fifo-test$(EXESUF)
 fate-fifo: CMD = run libavutil/fifo-test
 
+FATE_LIBAVUTIL += fate-hmac
+fate-hmac: libavutil/hmac-test$(EXESUF)
+fate-hmac: CMD = run libavutil/hmac-test
+
 FATE_LIBAVUTIL += fate-md5
 fate-md5: libavutil/md5-test$(EXESUF)
 fate-md5: CMD = run libavutil/md5-test
diff --git a/mythtv/external/FFmpeg/tests/fate/lossless-audio.mak b/mythtv/external/FFmpeg/tests/fate/lossless-audio.mak
index 57aa3aa54b4..8dc0f063347 100644
--- a/mythtv/external/FFmpeg/tests/fate/lossless-audio.mak
+++ b/mythtv/external/FFmpeg/tests/fate/lossless-audio.mak
@@ -19,6 +19,9 @@ fate-lossless-tak: CMD = crc -i $(SAMPLES)/lossless-audio/luckynight-partial.tak
 FATE_SAMPLES_LOSSLESS_AUDIO-$(call DEMDEC, TTA, TTA) += fate-lossless-tta
 fate-lossless-tta: CMD = crc -i $(SAMPLES)/lossless-audio/inside.tta
 
+FATE_SAMPLES_LOSSLESS_AUDIO-$(call DEMDEC, TTA, TTA) += fate-lossless-tta-encrypted
+fate-lossless-tta-encrypted: CMD = crc -password ffmpeg -i $(SAMPLES)/lossless-audio/encrypted.tta
+
 FATE_SAMPLES_LOSSLESS_AUDIO-$(call DEMDEC, ASF, WMALOSSLESS) += fate-lossless-wma
 fate-lossless-wma: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.wma -f s16le
 
diff --git a/mythtv/external/FFmpeg/tests/fate/lossless-video.mak b/mythtv/external/FFmpeg/tests/fate/lossless-video.mak
index b648b082d1f..f918ac42d84 100644
--- a/mythtv/external/FFmpeg/tests/fate/lossless-video.mak
+++ b/mythtv/external/FFmpeg/tests/fate/lossless-video.mak
@@ -1,9 +1,9 @@
-FATE_CLLC += fate-cllc-rgb
-fate-cllc-rgb: CMD = framecrc -i $(SAMPLES)/cllc/sample-cllc-rgb.avi
-
 FATE_CLLC += fate-cllc-argb
 fate-cllc-argb: CMD = framecrc -i $(SAMPLES)/cllc/sample-cllc-argb.avi
 
+FATE_CLLC += fate-cllc-rgb
+fate-cllc-rgb: CMD = framecrc -i $(SAMPLES)/cllc/sample-cllc-rgb.avi
+
 FATE_LOSSLESS_VIDEO-$(call DEMDEC, AVI, CLLC) += $(FATE_CLLC)
 fate-cllc: $(FATE_CLLC)
 
@@ -40,12 +40,12 @@ fate-mszh: CMD = framecrc -i $(SAMPLES)/lcl/mszh-1frame.avi
 FATE_LOSSLESS_VIDEO-$(call DEMDEC, AVI, VBLE) += fate-vble
 fate-vble: CMD = framecrc -i $(SAMPLES)/vble/flowers-partial-2MB.avi
 
-FATE_LOSSLESS_VIDEO-$(call DEMDEC, AVI, ZLIB) += fate-zlib
-fate-zlib: CMD = framecrc -i $(SAMPLES)/lcl/zlib-1frame.avi
-
 FATE_LOSSLESS_VIDEO-$(call DEMDEC, AVI, ZEROCODEC) += fate-zerocodec
 fate-zerocodec: CMD = framecrc -i $(SAMPLES)/zerocodec/sample-zeco.avi
 
+FATE_LOSSLESS_VIDEO-$(call DEMDEC, AVI, ZLIB) += fate-zlib
+fate-zlib: CMD = framecrc -i $(SAMPLES)/lcl/zlib-1frame.avi
+
 FATE_LOSSLESS_VIDEO += $(FATE_LOSSLESS_VIDEO-yes)
 
 FATE_SAMPLES_FFMPEG += $(FATE_LOSSLESS_VIDEO)
diff --git a/mythtv/external/FFmpeg/tests/fate/microsoft.mak b/mythtv/external/FFmpeg/tests/fate/microsoft.mak
index a2b3f1f228a..10aeaf66818 100644
--- a/mythtv/external/FFmpeg/tests/fate/microsoft.mak
+++ b/mythtv/external/FFmpeg/tests/fate/microsoft.mak
@@ -1,12 +1,12 @@
 FATE_MICROSOFT-$(call DEMDEC, AVI, MSMPEG4V1) += fate-msmpeg4v1
 fate-msmpeg4v1: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/msmpeg4v1/mpg4.avi -an
 
-FATE_MSVIDEO1 += fate-msvideo1-16bit
-fate-msvideo1-16bit: CMD = framecrc -i $(SAMPLES)/cram/clock-cram16.avi -pix_fmt rgb24
-
 FATE_MSVIDEO1 += fate-msvideo1-8bit
 fate-msvideo1-8bit: CMD = framecrc -i $(SAMPLES)/cram/skating.avi -t 1 -pix_fmt rgb24
 
+FATE_MSVIDEO1 += fate-msvideo1-16bit
+fate-msvideo1-16bit: CMD = framecrc -i $(SAMPLES)/cram/clock-cram16.avi -pix_fmt rgb24
+
 FATE_MICROSOFT-$(call DEMDEC, AVI, MSVIDEO1) += $(FATE_MSVIDEO1)
 fate-msvideo1: $(FATE_MSVIDEO1)
 
@@ -33,12 +33,12 @@ fate-vc1_sa00050: CMD = framecrc -i $(SAMPLES)/vc1/SA00050.vc1
 FATE_VC1-$(CONFIG_VC1_DEMUXER) += fate-vc1_sa10091
 fate-vc1_sa10091: CMD = framecrc -i $(SAMPLES)/vc1/SA10091.vc1
 
-FATE_VC1-$(CONFIG_VC1_DEMUXER) += fate-vc1_sa20021
-fate-vc1_sa20021: CMD = framecrc -i $(SAMPLES)/vc1/SA20021.vc1
-
 FATE_VC1-$(CONFIG_VC1_DEMUXER) += fate-vc1_sa10143
 fate-vc1_sa10143: CMD = framecrc -i $(SAMPLES)/vc1/SA10143.vc1
 
+FATE_VC1-$(CONFIG_VC1_DEMUXER) += fate-vc1_sa20021
+fate-vc1_sa20021: CMD = framecrc -i $(SAMPLES)/vc1/SA20021.vc1
+
 FATE_VC1-$(CONFIG_MOV_DEMUXER) += fate-vc1-ism
 fate-vc1-ism: CMD = framecrc -i $(SAMPLES)/isom/vc1-wmapro.ism -an
 
diff --git a/mythtv/external/FFmpeg/tests/fate/seek.mak b/mythtv/external/FFmpeg/tests/fate/seek.mak
index fa1f790d4c5..fe8d3ab9106 100644
--- a/mythtv/external/FFmpeg/tests/fate/seek.mak
+++ b/mythtv/external/FFmpeg/tests/fate/seek.mak
@@ -1,5 +1,13 @@
 # files from fate-acodec
 
+FATE_SEEK_ACODEC-$(call ENCDEC, ADPCM_IMA_QT,  AIFF)    += adpcm-ima_qt
+FATE_SEEK_ACODEC-$(call ENCDEC, ADPCM_IMA_WAV, WAV)     += adpcm-ima_wav
+FATE_SEEK_ACODEC-$(call ENCDEC, ADPCM_MS,      WAV)     += adpcm-ms
+FATE_SEEK_ACODEC-$(call ENCDEC, ADPCM_SWF,     FLV)     += adpcm-swf
+FATE_SEEK_ACODEC-$(call ENCDEC, ADPCM_YAMAHA,  WAV)     += adpcm-yamaha
+FATE_SEEK_ACODEC-$(call ENCDEC, ALAC,          MOV)     += alac
+FATE_SEEK_ACODEC-$(call ENCDEC, FLAC,          FLAC)    += flac
+FATE_SEEK_ACODEC-$(call ENCDEC, MP2,           MP2 MP3) += mp2
 FATE_SEEK_ACODEC-$(call ENCDEC, PCM_ALAW,      WAV)     += pcm-alaw
 FATE_SEEK_ACODEC-$(call ENCDEC, PCM_MULAW,     WAV)     += pcm-mulaw
 FATE_SEEK_ACODEC-$(call ENCDEC, PCM_S8,        MOV)     += pcm-s8
@@ -14,14 +22,6 @@ FATE_SEEK_ACODEC-$(call ENCDEC, PCM_F32BE,     AU)      += pcm-f32be
 FATE_SEEK_ACODEC-$(call ENCDEC, PCM_F32LE,     WAV)     += pcm-f32le
 FATE_SEEK_ACODEC-$(call ENCDEC, PCM_F64BE,     AU)      += pcm-f64be
 FATE_SEEK_ACODEC-$(call ENCDEC, PCM_F64LE,     WAV)     += pcm-f64le
-FATE_SEEK_ACODEC-$(call ENCDEC, ADPCM_IMA_QT,  AIFF)    += adpcm-ima_qt
-FATE_SEEK_ACODEC-$(call ENCDEC, ADPCM_IMA_WAV, WAV)     += adpcm-ima_wav
-FATE_SEEK_ACODEC-$(call ENCDEC, ADPCM_MS,      WAV)     += adpcm-ms
-FATE_SEEK_ACODEC-$(call ENCDEC, ADPCM_SWF,     FLV)     += adpcm-swf
-FATE_SEEK_ACODEC-$(call ENCDEC, ADPCM_YAMAHA,  WAV)     += adpcm-yamaha
-FATE_SEEK_ACODEC-$(call ENCDEC, ALAC,          MOV)     += alac
-FATE_SEEK_ACODEC-$(call ENCDEC, FLAC,          FLAC)    += flac
-FATE_SEEK_ACODEC-$(call ENCDEC, MP2,           MP2 MP3) += mp2
 
 fate-seek-acodec-adpcm-ima_qt:  SRC = fate/acodec-adpcm-ima_qt.aiff
 fate-seek-acodec-adpcm-ima_wav: SRC = fate/acodec-adpcm-ima_wav.wav
diff --git a/mythtv/external/FFmpeg/tests/fate/subtitles.mak b/mythtv/external/FFmpeg/tests/fate/subtitles.mak
index 2c4f87855b4..8e586fbe8a5 100644
--- a/mythtv/external/FFmpeg/tests/fate/subtitles.mak
+++ b/mythtv/external/FFmpeg/tests/fate/subtitles.mak
@@ -7,6 +7,9 @@ fate-sub-jacosub: CMD = md5 -i $(SAMPLES)/sub/JACOsub_capability_tester.jss -f a
 FATE_SUBTITLES_ASS-$(call DEMDEC, MICRODVD, MICRODVD) += fate-sub-microdvd
 fate-sub-microdvd: CMD = md5 -i $(SAMPLES)/sub/MicroDVD_capability_tester.sub -f ass
 
+FATE_SUBTITLES-$(call ALLYES, MICRODVD_DEMUXER MICRODVD_MUXER) += fate-sub-microdvd-remux
+fate-sub-microdvd-remux: CMD = md5 -i $(SAMPLES)/sub/MicroDVD_capability_tester.sub -c:s copy -f microdvd
+
 FATE_SUBTITLES_ASS-$(call DEMDEC, MOV, MOVTEXT) += fate-sub-movtext
 fate-sub-movtext: CMD = md5 -i $(SAMPLES)/sub/MovText_capability_tester.mp4 -f ass
 
@@ -49,6 +52,9 @@ fate-sub-vplayer: CMD = md5 -i $(SAMPLES)/sub/VPlayer_capability_tester.txt -f a
 FATE_SUBTITLES_ASS-$(call DEMDEC, WEBVTT, WEBVTT) += fate-sub-webvtt
 fate-sub-webvtt: CMD = md5 -i $(SAMPLES)/sub/WebVTT_capability_tester.vtt -f ass
 
+FATE_SUBTITLES_ASS-$(call ALLYES, MICRODVD_DEMUXER MICRODVD_DECODER ICONV) += fate-sub-charenc
+fate-sub-charenc: CMD = md5 -sub_charenc cp1251 -i $(SAMPLES)/sub/cp1251-subtitles.sub -f ass
+
 FATE_SUBTITLES-$(call ENCMUX, ASS, ASS) += $(FATE_SUBTITLES_ASS-yes)
 FATE_SUBTITLES += $(FATE_SUBTITLES-yes)
 
diff --git a/mythtv/external/FFmpeg/tests/fate/utvideo.mak b/mythtv/external/FFmpeg/tests/fate/utvideo.mak
index 44e03144ce2..c6ce2176e04 100644
--- a/mythtv/external/FFmpeg/tests/fate/utvideo.mak
+++ b/mythtv/external/FFmpeg/tests/fate/utvideo.mak
@@ -1,3 +1,9 @@
+FATE_UTVIDEO += fate-utvideo_rgb_left
+fate-utvideo_rgb_left: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_rgb_left.avi
+
+FATE_UTVIDEO += fate-utvideo_rgb_median
+fate-utvideo_rgb_median: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_rgb_median.avi
+
 FATE_UTVIDEO += fate-utvideo_rgba_left
 fate-utvideo_rgba_left: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_rgba_left.avi
 
@@ -7,12 +13,6 @@ fate-utvideo_rgba_median: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_rgba_medi
 FATE_UTVIDEO += fate-utvideo_rgba_single_symbol
 fate-utvideo_rgba_single_symbol: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_rgba_single_symbol.avi
 
-FATE_UTVIDEO += fate-utvideo_rgb_left
-fate-utvideo_rgb_left: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_rgb_left.avi
-
-FATE_UTVIDEO += fate-utvideo_rgb_median
-fate-utvideo_rgb_median: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_rgb_median.avi
-
 FATE_UTVIDEO += fate-utvideo_yuv420_left
 fate-utvideo_yuv420_left: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_yuv420_left.avi
 
@@ -30,17 +30,14 @@ fate-utvideo: $(FATE_UTVIDEO)
 
 fate-utvideoenc%: CMD = framemd5 -f image2 -vcodec pgmyuv -i $(TARGET_PATH)/tests/vsynth1/%02d.pgm -vcodec utvideo -sws_flags +accurate_rnd+bitexact ${OPTS}
 
-FATE_UTVIDEOENC += fate-utvideoenc_rgba_none
-fate-utvideoenc_rgba_none: OPTS = -pix_fmt rgba -pred 3
-
 FATE_UTVIDEOENC += fate-utvideoenc_rgba_left
 fate-utvideoenc_rgba_left: OPTS = -pix_fmt rgba -pred left
 
 FATE_UTVIDEOENC += fate-utvideoenc_rgba_median
 fate-utvideoenc_rgba_median: OPTS = -pix_fmt rgba -pred median
 
-FATE_UTVIDEOENC += fate-utvideoenc_rgb_none
-fate-utvideoenc_rgb_none: OPTS = -pix_fmt rgb24 -pred 3
+FATE_UTVIDEOENC += fate-utvideoenc_rgba_none
+fate-utvideoenc_rgba_none: OPTS = -pix_fmt rgba -pred 3
 
 FATE_UTVIDEOENC += fate-utvideoenc_rgb_left
 fate-utvideoenc_rgb_left: OPTS = -pix_fmt rgb24 -pred left
@@ -48,8 +45,8 @@ fate-utvideoenc_rgb_left: OPTS = -pix_fmt rgb24 -pred left
 FATE_UTVIDEOENC += fate-utvideoenc_rgb_median
 fate-utvideoenc_rgb_median: OPTS = -pix_fmt rgb24 -pred median
 
-FATE_UTVIDEOENC += fate-utvideoenc_yuv420_none
-fate-utvideoenc_yuv420_none: OPTS = -pix_fmt yuv420p -pred 3
+FATE_UTVIDEOENC += fate-utvideoenc_rgb_none
+fate-utvideoenc_rgb_none: OPTS = -pix_fmt rgb24 -pred 3
 
 FATE_UTVIDEOENC += fate-utvideoenc_yuv420_left
 fate-utvideoenc_yuv420_left: OPTS = -pix_fmt yuv420p -pred left
@@ -57,8 +54,8 @@ fate-utvideoenc_yuv420_left: OPTS = -pix_fmt yuv420p -pred left
 FATE_UTVIDEOENC += fate-utvideoenc_yuv420_median
 fate-utvideoenc_yuv420_median: OPTS = -pix_fmt yuv420p -pred median
 
-FATE_UTVIDEOENC += fate-utvideoenc_yuv422_none
-fate-utvideoenc_yuv422_none: OPTS = -pix_fmt yuv422p -pred 3
+FATE_UTVIDEOENC += fate-utvideoenc_yuv420_none
+fate-utvideoenc_yuv420_none: OPTS = -pix_fmt yuv420p -pred 3
 
 FATE_UTVIDEOENC += fate-utvideoenc_yuv422_left
 fate-utvideoenc_yuv422_left: OPTS = -pix_fmt yuv422p -pred left
@@ -66,6 +63,9 @@ fate-utvideoenc_yuv422_left: OPTS = -pix_fmt yuv422p -pred left
 FATE_UTVIDEOENC += fate-utvideoenc_yuv422_median
 fate-utvideoenc_yuv422_median: OPTS = -pix_fmt yuv422p -pred median
 
+FATE_UTVIDEOENC += fate-utvideoenc_yuv422_none
+fate-utvideoenc_yuv422_none: OPTS = -pix_fmt yuv422p -pred 3
+
 $(FATE_UTVIDEOENC): tests/vsynth1/00.pgm
 
 FATE_AVCONV-$(call ENCMUX, UTVIDEO, AVI) += $(FATE_UTVIDEOENC)
diff --git a/mythtv/external/FFmpeg/tests/fate/vcodec.mak b/mythtv/external/FFmpeg/tests/fate/vcodec.mak
index 6995c4a230a..f10e80c3e78 100644
--- a/mythtv/external/FFmpeg/tests/fate/vcodec.mak
+++ b/mythtv/external/FFmpeg/tests/fate/vcodec.mak
@@ -163,34 +163,34 @@ FATE_VCODEC-$(call ENCDEC, MPEG4, AVI)     += $(FATE_MPEG4_AVI)
 fate-vsynth%-mpeg4:              ENCOPTS = -qscale 10 -flags +mv4 -mbd bits
 fate-vsynth%-mpeg4:              FMT     = mp4
 
-fate-vsynth%-mpeg4-rc:           ENCOPTS = -b 400k -bf 2
+fate-vsynth%-mpeg4-adap:         ENCOPTS = -b 550k -bf 2 -flags +mv4+mv0 \
+                                           -trellis 1 -cmp 1 -subcmp 2   \
+                                           -mbd rd -scplx_mask 0.3
 
 fate-vsynth%-mpeg4-adv:          ENCOPTS = -qscale 9 -flags +mv4+aic       \
                                            -data_partitioning 1 -trellis 1 \
                                            -mbd bits -ps 200
 
-fate-vsynth%-mpeg4-qprd:         ENCOPTS = -b 450k -bf 2 -trellis 1          \
-                                           -flags +mv4+mv0 -mpv_flags +qp_rd \
-                                           -cmp 2 -subcmp 2 -mbd rd
+fate-vsynth%-mpeg4-error:        ENCOPTS = -qscale 7 -flags +mv4+aic    \
+                                           -data_partitioning 1 -mbd rd \
+                                           -ps 250 -error 10
 
-fate-vsynth%-mpeg4-adap:         ENCOPTS = -b 550k -bf 2 -flags +mv4+mv0 \
-                                           -trellis 1 -cmp 1 -subcmp 2   \
-                                           -mbd rd -scplx_mask 0.3
+fate-vsynth%-mpeg4-nr:           ENCOPTS = -qscale 8 -flags +mv4 -mbd rd -nr 200
 
 fate-vsynth%-mpeg4-qpel:         ENCOPTS = -qscale 7 -flags +mv4+qpel -mbd 2 \
                                            -bf 2 -cmp 1 -subcmp 2
 
+fate-vsynth%-mpeg4-qprd:         ENCOPTS = -b 450k -bf 2 -trellis 1          \
+                                           -flags +mv4+mv0 -mpv_flags +qp_rd \
+                                           -cmp 2 -subcmp 2 -mbd rd
+
+fate-vsynth%-mpeg4-rc:           ENCOPTS = -b 400k -bf 2
+
 fate-vsynth%-mpeg4-thread:       ENCOPTS = -b 500k -flags +mv4+aic         \
                                            -data_partitioning 1 -trellis 1 \
                                            -mbd bits -ps 200 -bf 2         \
                                            -threads 2 -slices 2
 
-fate-vsynth%-mpeg4-error:        ENCOPTS = -qscale 7 -flags +mv4+aic    \
-                                           -data_partitioning 1 -mbd rd \
-                                           -ps 250 -error 10
-
-fate-vsynth%-mpeg4-nr:           ENCOPTS = -qscale 8 -flags +mv4 -mbd rd -nr 200
-
 FATE_VCODEC-$(call ENCDEC, MSMPEG4V3, AVI) += msmpeg4
 fate-vsynth%-msmpeg4:            ENCOPTS = -qscale 10
 
diff --git a/mythtv/external/FFmpeg/tests/fate/video.mak b/mythtv/external/FFmpeg/tests/fate/video.mak
index f8725b6e3d6..1b835c7de40 100644
--- a/mythtv/external/FFmpeg/tests/fate/video.mak
+++ b/mythtv/external/FFmpeg/tests/fate/video.mak
@@ -66,12 +66,12 @@ fate-corepng: CMD = framecrc -i $(SAMPLES)/png1/corepng-partial.avi
 FATE_VIDEO-$(call DEMDEC, AVS, AVS) += fate-creatureshock-avs
 fate-creatureshock-avs: CMD = framecrc -i $(SAMPLES)/creatureshock-avs/OUTATIME.AVS -pix_fmt rgb24
 
-FATE_CVID-$(CONFIG_AVI_DEMUXER) += fate-cvid-partial
-fate-cvid-partial: CMD = framecrc -i $(SAMPLES)/cvid/laracroft-cinepak-partial.avi -an
-
 FATE_CVID-$(CONFIG_MOV_DEMUXER) += fate-cvid-palette
 fate-cvid-palette: CMD = framecrc -i $(SAMPLES)/cvid/catfight-cvid-pal8-partial.mov -pix_fmt rgb24 -an
 
+FATE_CVID-$(CONFIG_AVI_DEMUXER) += fate-cvid-partial
+fate-cvid-partial: CMD = framecrc -i $(SAMPLES)/cvid/laracroft-cinepak-partial.avi -an
+
 FATE_CVID-$(CONFIG_AVI_DEMUXER) += fate-cvid-grayscale
 fate-cvid-grayscale: CMD = framecrc -i $(SAMPLES)/cvid/pcitva15.avi -an
 
@@ -90,6 +90,9 @@ fate-delphine-cin-video: CMD = framecrc -i $(SAMPLES)/delphine-cin/LOGO-partial.
 FATE_VIDEO-$(call DEMDEC, ANM, ANM) += fate-deluxepaint-anm
 fate-deluxepaint-anm: CMD = framecrc -i $(SAMPLES)/deluxepaint-anm/INTRO1.ANM -pix_fmt rgb24
 
+FATE_VIDEO-$(call DEMDEC, DIRAC, DIRAC) += fate-dirac
+fate-dirac: CMD = framecrc -i $(SAMPLES)/dirac/vts.profile-main.drc
+
 FATE_TRUEMOTION1 += fate-truemotion1-15
 fate-truemotion1-15: CMD = framecrc -i $(SAMPLES)/duck/phant2-940.duk -pix_fmt rgb24 -an
 
@@ -178,7 +181,7 @@ FATE_VIDEO-$(call DEMDEC, MVI, MOTIONPIXELS) += fate-motionpixels
 fate-motionpixels: CMD = framecrc -i $(SAMPLES)/motion-pixels/INTRO-partial.MVI -an -pix_fmt rgb24 -vframes 111
 
 FATE_VIDEO-$(call DEMDEC, MPEGTS, MPEG2VIDEO) += fate-mpeg2-field-enc
-fate-mpeg2-field-enc: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -an
+fate-mpeg2-field-enc: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -an -vframes 30
 
 FATE_VIDEO-$(call DEMDEC, MXG, MXPEG) += fate-mxpeg
 fate-mxpeg: CMD = framecrc -idct simple -flags +bitexact -i $(SAMPLES)/mxpeg/m1.mxg -an
@@ -254,6 +257,9 @@ FATE_VIDEO-$(call ENCDEC, V410 PGMYUV, AVI IMAGE2) += fate-v410enc
 fate-v410enc: tests/vsynth1/00.pgm
 fate-v410enc: CMD = md5 -f image2 -vcodec pgmyuv -i $(TARGET_PATH)/tests/vsynth1/%02d.pgm -flags +bitexact -vcodec v410 -f avi
 
+FATE_VIDEO-$(call DEMDEC, SIFF, VB) += fate-vb
+fate-vb: CMD = framecrc -i $(SAMPLES)/SIFF/INTRO_B.VB -t 3 -pix_fmt rgb24 -an
+
 FATE_VIDEO-$(call DEMDEC, AVI, VCR1) += fate-vcr1
 fate-vcr1: CMD = framecrc -i $(SAMPLES)/vcr1/VCR1test.avi -an
 
diff --git a/mythtv/external/FFmpeg/tests/fate/voice.mak b/mythtv/external/FFmpeg/tests/fate/voice.mak
index 3535d55b1e4..f27be1818bc 100644
--- a/mythtv/external/FFmpeg/tests/fate/voice.mak
+++ b/mythtv/external/FFmpeg/tests/fate/voice.mak
@@ -1,12 +1,12 @@
-FATE_G722 += fate-g722dec-1
+FATE_G722-$(call DEMDEC, G722, ADPCM_G722) += fate-g722dec-1
 fate-g722dec-1: CMD = framecrc -i $(SAMPLES)/g722/conf-adminmenu-162.g722
 
-FATE_G722 += fate-g722-encode
+FATE_G722-$(call ENCMUX, ADPCM_G722, WAV) += fate-g722-encode
 fate-g722-encode: tests/data/asynth-16000-1.wav
 fate-g722-encode: SRC = tests/data/asynth-16000-1.wav
 fate-g722-encode: CMD = enc_dec_pcm wav md5 s16le $(SRC) -c:a g722
 
-FATE_VOICE += $(FATE_G722)
+FATE_VOICE-yes += $(FATE_G722-yes)
 fate-g722: $(FATE_G722)
 
 FATE_G723_1 += fate-g723_1-dec-1
@@ -33,7 +33,8 @@ fate-g723_1-dec-7: CMD = framecrc -postfilter 1 -i $(SAMPLES)/g723_1/dtx63b.tco
 FATE_G723_1 += fate-g723_1-dec-8
 fate-g723_1-dec-8: CMD = framecrc -postfilter 1 -i $(SAMPLES)/g723_1/dtx63e.tco
 
-FATE_SAMPLES_AVCONV += $(FATE_G723_1)
+FATE_G723_1-$(call DEMDEC, G723_1, G723_1) += $(FATE_G723_1)
+FATE_SAMPLES_AVCONV += $(FATE_G723_1-yes)
 fate-g723_1: $(FATE_G723_1)
 
 FATE_G726 += fate-g726-encode-2bit
@@ -51,27 +52,27 @@ fate-g726-encode-5bit: CMD = enc_dec_pcm wav md5 s16le $(SRC) -c:a g726 -b:a 40k
 $(FATE_G726): tests/data/asynth-8000-1.wav
 $(FATE_G726): SRC = tests/data/asynth-8000-1.wav
 
-FATE_VOICE += $(FATE_G726)
+FATE_VOICE-$(call ENCMUX, ADPCM_G726, WAV) += $(FATE_G726)
 fate-g726: $(FATE_G726)
 
-FATE_GSM += fate-gsm-ms
+FATE_GSM-$(call DEMDEC, WAV, GSM) += fate-gsm-ms
 fate-gsm-ms: CMD = framecrc -i $(SAMPLES)/gsm/ciao.wav
 
-FATE_GSM += fate-gsm-toast
+FATE_GSM-$(call DEMDEC, MOV, GSM) += fate-gsm-toast
 fate-gsm-toast: CMD = framecrc -i $(SAMPLES)/gsm/sample-gsm-8000.mov -t 10
 
-FATE_VOICE += $(FATE_GSM)
+FATE_VOICE-yes += $(FATE_GSM-yes)
 fate-gsm: $(FATE_GSM)
 
-FATE_VOICE += fate-qcelp
+FATE_VOICE-$(call DEMDEC, QCP, QCELP) += fate-qcelp
 fate-qcelp: CMD = pcm -i $(SAMPLES)/qcp/0036580847.QCP
 fate-qcelp: CMP = oneoff
 fate-qcelp: REF = $(SAMPLES)/qcp/0036580847.pcm
 
-FATE_VOICE += fate-truespeech
+FATE_VOICE-$(call DEMDEC, WAV, TRUESPEECH) += fate-truespeech
 fate-truespeech: CMD = pcm -i $(SAMPLES)/truespeech/a6.wav
 fate-truespeech: CMP = oneoff
 fate-truespeech: REF = $(SAMPLES)/truespeech/a6.pcm
 
-FATE_SAMPLES_FFMPEG += $(FATE_VOICE)
-fate-voice: $(FATE_VOICE)
+FATE_SAMPLES_FFMPEG += $(FATE_VOICE-yes)
+fate-voice: $(FATE_VOICE-yes)
diff --git a/mythtv/external/FFmpeg/tests/fate/vpx.mak b/mythtv/external/FFmpeg/tests/fate/vpx.mak
index fd9c905b4e5..061a1e89159 100644
--- a/mythtv/external/FFmpeg/tests/fate/vpx.mak
+++ b/mythtv/external/FFmpeg/tests/fate/vpx.mak
@@ -1,10 +1,10 @@
-FATE_VP3-$(CONFIG_AVI_DEMUXER) += fate-vp31
-fate-vp31: CMD = framecrc -i $(SAMPLES)/vp3/vp31.avi
+FATE_VP3-$(call DEMDEC, MATROSKA, THEORA) += fate-theora-coeff-level64
+fate-theora-coeff-level64: CMD = framecrc -i $(SAMPLES)/vp3/coeff_level64.mkv
 
-FATE_VP3-$(CONFIG_MATROSKA_DEMUXER) += fate-vp3-coeff-level64
-fate-vp3-coeff-level64: CMD = framecrc -i $(SAMPLES)/vp3/coeff_level64.mkv
+FATE_VP3-$(call DEMDEC, AVI, VP3) += fate-vp31
+fate-vp31: CMD = framecrc -i $(SAMPLES)/vp3/vp31.avi
 
-FATE_SAMPLES_AVCONV-$(CONFIG_VP3_DECODER) += $(FATE_VP3-yes)
+FATE_SAMPLES_AVCONV += $(FATE_VP3-yes)
 fate-vp3: $(FATE_VP3-yes)
 
 FATE_SAMPLES_AVCONV-$(call DEMDEC, AVI, VP5) += fate-vp5
@@ -22,6 +22,9 @@ fate-vp6a: CMD = framecrc -i $(SAMPLES)/flash-vp6/300x180-Scr-f8-056alpha.flv
 FATE_VP6-$(call DEMDEC, FLV, VP6F) += fate-vp6f
 fate-vp6f: CMD = framecrc -i $(SAMPLES)/flash-vp6/clip1024.flv
 
+FATE_VP8-$(call DEMDEC, FLV, VP8) += fate-vp8-alpha
+fate-vp8-alpha: CMD = framecrc -i $(SAMPLES)/vp8_alpha/vp8_video_with_alpha.webm -vcodec copy
+
 FATE_SAMPLES_AVCONV += $(FATE_VP6-yes)
 fate-vp6: $(FATE_VP6-yes)
 
diff --git a/mythtv/external/FFmpeg/tests/fate/wavpack.mak b/mythtv/external/FFmpeg/tests/fate/wavpack.mak
index ef190fa89ed..8a1c301cac6 100644
--- a/mythtv/external/FFmpeg/tests/fate/wavpack.mak
+++ b/mythtv/external/FFmpeg/tests/fate/wavpack.mak
@@ -1,8 +1,5 @@
 # lossless
 
-FATE_WAVPACK += fate-wavpack-lossless-float
-fate-wavpack-lossless-float: CMD = md5 -i $(SAMPLES)/wavpack/lossless/32bit_float-partial.wv -f f32le
-
 FATE_WAVPACK += fate-wavpack-lossless-8bit
 fate-wavpack-lossless-8bit: CMD = md5 -i $(SAMPLES)/wavpack/lossless/8bit-partial.wv -f s8
 
@@ -18,10 +15,10 @@ fate-wavpack-lossless-24bit: CMD = md5 -i $(SAMPLES)/wavpack/lossless/24bit-part
 FATE_WAVPACK += fate-wavpack-lossless-32bit
 fate-wavpack-lossless-32bit: CMD = md5 -i $(SAMPLES)/wavpack/lossless/32bit_int-partial.wv -f s32le
 
-# lossy
+FATE_WAVPACK += fate-wavpack-lossless-float
+fate-wavpack-lossless-float: CMD = md5 -i $(SAMPLES)/wavpack/lossless/32bit_float-partial.wv -f f32le
 
-FATE_WAVPACK += fate-wavpack-lossy-float
-fate-wavpack-lossy-float: CMD = md5 -i $(SAMPLES)/wavpack/lossy/2.0_32-bit_float.wv -f f32le
+# lossy
 
 FATE_WAVPACK += fate-wavpack-lossy-8bit
 fate-wavpack-lossy-8bit: CMD = md5 -i $(SAMPLES)/wavpack/lossy/4.0_8-bit.wv -f s8
@@ -35,6 +32,9 @@ fate-wavpack-lossy-24bit: CMD = md5 -i $(SAMPLES)/wavpack/lossy/4.0_24-bit.wv -f
 FATE_WAVPACK += fate-wavpack-lossy-32bit
 fate-wavpack-lossy-32bit: CMD = md5 -i $(SAMPLES)/wavpack/lossy/4.0_32-bit_int.wv -f s32le
 
+FATE_WAVPACK += fate-wavpack-lossy-float
+fate-wavpack-lossy-float: CMD = md5 -i $(SAMPLES)/wavpack/lossy/2.0_32-bit_float.wv -f f32le
+
 # channel configurations
 
 FATE_WAVPACK += fate-wavpack-channels-monofloat
@@ -71,18 +71,18 @@ fate-wavpack-speed-vhigh: CMD = md5 -i $(SAMPLES)/wavpack/speed_modes/vhigh-part
 
 # special cases
 
-FATE_WAVPACK += fate-wavpack-cuesheet
-fate-wavpack-cuesheet: CMD = md5 -i $(SAMPLES)/wavpack/special/cue_sheet.wv -f s16le
-
-FATE_WAVPACK += fate-wavpack-zerolsbs
-fate-wavpack-zerolsbs: CMD = md5 -i $(SAMPLES)/wavpack/special/zero_lsbs.wv -f s16le
-
 FATE_WAVPACK += fate-wavpack-clipping
 fate-wavpack-clipping: CMD = md5 -i $(SAMPLES)/wavpack/special/clipping.wv -f s16le
 
+FATE_WAVPACK += fate-wavpack-cuesheet
+fate-wavpack-cuesheet: CMD = md5 -i $(SAMPLES)/wavpack/special/cue_sheet.wv -f s16le
+
 FATE_WAVPACK += fate-wavpack-falsestereo
 fate-wavpack-falsestereo: CMD = md5 -i $(SAMPLES)/wavpack/special/false_stereo.wv -f s16le
 
+FATE_WAVPACK += fate-wavpack-zerolsbs
+fate-wavpack-zerolsbs: CMD = md5 -i $(SAMPLES)/wavpack/special/zero_lsbs.wv -f s16le
+
 FATE_WAVPACK-$(call DEMDEC, WV, WAVPACK) += $(FATE_WAVPACK)
 
 FATE_WAVPACK-$(call DEMDEC, MATROSKA, WAVPACK) += fate-wavpack-matroskamode
diff --git a/mythtv/external/FFmpeg/tests/lavf-regression.sh b/mythtv/external/FFmpeg/tests/lavf-regression.sh
index cc21f8d33eb..d0335c1c6fe 100755
--- a/mythtv/external/FFmpeg/tests/lavf-regression.sh
+++ b/mythtv/external/FFmpeg/tests/lavf-regression.sh
@@ -137,6 +137,8 @@ do_lavf nut "" "-acodec mp2 -ab 64k"
 fi
 
 if [ -n "$do_mkv" ] ; then
+do_lavf mkv "" "-acodec mp2 -ab 64k -vcodec mpeg4 \
+ -attach ${raw_src%/*}/00.pgm -metadata:s:t mimetype=image/x-portable-greymap"
 do_lavf mkv "" "-acodec mp2 -ab 64k -vcodec mpeg4"
 fi
 
diff --git a/mythtv/external/FFmpeg/tests/lavfi-regression.sh b/mythtv/external/FFmpeg/tests/lavfi-regression.sh
index d9542e15843..93351247ba2 100755
--- a/mythtv/external/FFmpeg/tests/lavfi-regression.sh
+++ b/mythtv/external/FFmpeg/tests/lavfi-regression.sh
@@ -47,7 +47,9 @@ do_lavfi "fade"               "fade=in:5:15,fade=out:30:15"
 do_lavfi "hue"                "hue=s=sin(2*PI*t)+1"
 do_lavfi "idet"               "idet"
 do_lavfi "null"               "null"
-do_lavfi "overlay"            "split[m],scale=88:72,pad=96:80:4:4[o2];[m]fifo[o1],[o1][o2]overlay=240:16"
+do_lavfi "overlay_rgb"        "split[m],scale=88:72,pad=96:80:4:4[o2];[m]fifo[o1],[o1][o2]overlay=240:16:format=rgb"
+do_lavfi "overlay_yuv420"     "split[m],scale=88:72,pad=96:80:4:4[o2];[m]fifo[o1],[o1][o2]overlay=240:16:format=yuv420"
+do_lavfi "overlay_yuv444"     "split[m],scale=88:72,pad=96:80:4:4[o2];[m]fifo[o1],[o1][o2]overlay=240:16:format=yuv444"
 do_lavfi "pad"                "pad=iw*1.5:ih*1.5:iw*0.3:ih*0.2"
 do_lavfi "pp"                 "pp=be/hb/vb/tn/l5/al"
 do_lavfi "pp2"                "pp=be/fq:16/h1/v1/lb"
@@ -63,7 +65,7 @@ do_lavfi "setsar"             "setsar=16/11"
 do_lavfi "thumbnail"          "thumbnail=10"
 do_lavfi "tile"               "tile=3x3:nb_frames=5:padding=7:margin=2"
 do_lavfi "transpose"          "transpose"
-do_lavfi "unsharp"            "unsharp=10:10:-1.5:10:10:-1.5"
+do_lavfi "unsharp"            "unsharp=11:11:-1.5:11:11:-1.5"
 do_lavfi "vflip"              "vflip"
 do_lavfi "vflip_crop"         "vflip,crop=iw-100:ih-100:100:100"
 do_lavfi "vflip_vflip"        "vflip,vflip"
@@ -106,6 +108,7 @@ do_lavfi_pixfmts(){
 # all these filters have exactly one input and exactly one output
 do_lavfi_pixfmts "field"               "field"   "bottom"
 do_lavfi_pixfmts "histeq"              "histeq"  "antibanding=strong"
+do_lavfi_pixfmts "il"                  "il"      "luma_mode=d:chroma_mode=d:alpha_mode=d"
 do_lavfi_pixfmts "kerndeint"           "kerndeint" "" "tinterlace=interleave_top,"
 do_lavfi_pixfmts "pixfmts_copy"        "copy"    ""
 do_lavfi_pixfmts "pixfmts_crop"        "crop"    "100:100:100:100"
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/cdgraphics b/mythtv/external/FFmpeg/tests/ref/fate/cdgraphics
index 1e5cc6f1e3f..a7820591c98 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/cdgraphics
+++ b/mythtv/external/FFmpeg/tests/ref/fate/cdgraphics
@@ -1,20 +1,20 @@
 #tb 0: 1/300
-0,          0,          0,        1,   194400, 0xd919c635
-0,          1,          1,        1,   194400, 0xd919c635
-0,          2,          2,        1,   194400, 0x516a1007
-0,          3,          3,        1,   194400, 0x516a1007
-0,          4,          4,        1,   194400, 0x516a1007
-0,          5,          5,        1,   194400, 0x516a1007
-0,          6,          6,        1,   194400, 0x516a1007
-0,          7,          7,        1,   194400, 0x516a1007
-0,          8,          8,        1,   194400, 0x516a1007
-0,          9,          9,        1,   194400, 0x516a1007
-0,         10,         10,        1,   194400, 0x516a1007
-0,         11,         11,        1,   194400, 0x516a1007
-0,         12,         12,        1,   194400, 0x516a1007
-0,         13,         13,        1,   194400, 0x516a1007
-0,         14,         14,        1,   194400, 0x516a1007
-0,         15,         15,        1,   194400, 0x516a1007
+0,          0,          0,        1,   194400, 0x46ad80da
+0,          1,          1,        1,   194400, 0x46ad80da
+0,          2,          2,        1,   194400, 0x9392c3b9
+0,          3,          3,        1,   194400, 0x9392c3b9
+0,          4,          4,        1,   194400, 0x9392c3b9
+0,          5,          5,        1,   194400, 0x9392c3b9
+0,          6,          6,        1,   194400, 0x9392c3b9
+0,          7,          7,        1,   194400, 0x9392c3b9
+0,          8,          8,        1,   194400, 0x9392c3b9
+0,          9,          9,        1,   194400, 0x9392c3b9
+0,         10,         10,        1,   194400, 0x9392c3b9
+0,         11,         11,        1,   194400, 0x9392c3b9
+0,         12,         12,        1,   194400, 0x9392c3b9
+0,         13,         13,        1,   194400, 0x9392c3b9
+0,         14,         14,        1,   194400, 0x9392c3b9
+0,         15,         15,        1,   194400, 0x9392c3b9
 0,         16,         16,        1,   194400, 0x46ad80da
 0,         17,         17,        1,   194400, 0x46ad80da
 0,         18,         18,        1,   194400, 0x46ad80da
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/cvid-grayscale b/mythtv/external/FFmpeg/tests/ref/fate/cvid-grayscale
index 87ca600add2..1b586b3ddeb 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/cvid-grayscale
+++ b/mythtv/external/FFmpeg/tests/ref/fate/cvid-grayscale
@@ -1,153 +1,153 @@
 #tb 0: 99561/500000
-0,          0,          0,        1,    11300, 0x46c78923
-0,          1,          1,        1,    11300, 0x3f2a1175
-0,          2,          2,        1,    11300, 0x722de221
-0,          3,          3,        1,    11300, 0x01746b88
-0,          4,          4,        1,    11300, 0x549587a7
-0,          5,          5,        1,    11300, 0x843ab943
-0,          6,          6,        1,    11300, 0x62fdee48
-0,          7,          7,        1,    11300, 0x74a62867
-0,          8,          8,        1,    11300, 0x35a20e2f
-0,          9,          9,        1,    11300, 0x4e9ef54d
-0,         10,         10,        1,    11300, 0xec7201f5
-0,         11,         11,        1,    11300, 0x363bfe27
-0,         12,         12,        1,    11300, 0x2aaab418
-0,         13,         13,        1,    11300, 0x6a48ab3f
-0,         14,         14,        1,    11300, 0x3fecea34
-0,         15,         15,        1,    11300, 0xa371f55e
-0,         16,         16,        1,    11300, 0xa86b147c
-0,         17,         17,        1,    11300, 0x49e9206e
-0,         18,         18,        1,    11300, 0x6c9a2155
-0,         19,         19,        1,    11300, 0x2c8a4798
-0,         20,         20,        1,    11300, 0x3485676c
-0,         21,         21,        1,    11300, 0xb0b293f2
-0,         22,         22,        1,    11300, 0xe4a9b068
-0,         23,         23,        1,    11300, 0xd68d0556
-0,         24,         24,        1,    11300, 0xc28e5193
-0,         25,         25,        1,    11300, 0xf6948483
-0,         26,         26,        1,    11300, 0xf21fbf57
-0,         27,         27,        1,    11300, 0x8345eb44
-0,         28,         28,        1,    11300, 0x8124f045
-0,         29,         29,        1,    11300, 0x18e31f10
-0,         30,         30,        1,    11300, 0xdb1943fc
-0,         31,         31,        1,    11300, 0x8701699f
-0,         32,         32,        1,    11300, 0xd7b18550
-0,         33,         33,        1,    11300, 0xa56faccc
-0,         34,         34,        1,    11300, 0xf8bcc17c
-0,         35,         35,        1,    11300, 0x446acab9
-0,         36,         36,        1,    11300, 0x755fd295
-0,         37,         37,        1,    11300, 0x92e3d100
-0,         38,         38,        1,    11300, 0x54895bb3
-0,         39,         39,        1,    11300, 0xd18bffda
-0,         40,         40,        1,    11300, 0x480dbe4f
-0,         41,         41,        1,    11300, 0x49ea9dbe
-0,         42,         42,        1,    11300, 0x00d3a003
-0,         43,         43,        1,    11300, 0xda7bbfb2
-0,         44,         44,        1,    11300, 0x9700d9c2
-0,         45,         45,        1,    11300, 0xa0a9e490
-0,         46,         46,        1,    11300, 0x00eb0979
-0,         47,         47,        1,    11300, 0x32b04630
-0,         48,         48,        1,    11300, 0xdfb73e51
-0,         49,         49,        1,    11300, 0x3d8e4f96
-0,         50,         50,        1,    11300, 0x2ca83271
-0,         51,         51,        1,    11300, 0xb5b123c0
-0,         52,         52,        1,    11300, 0x8a570e58
-0,         53,         53,        1,    11300, 0xc6c805bc
-0,         54,         54,        1,    11300, 0x27caf7a5
-0,         55,         55,        1,    11300, 0x5319ecb0
-0,         56,         56,        1,    11300, 0x5471e3fd
-0,         57,         57,        1,    11300, 0x6d68a6f4
-0,         58,         58,        1,    11300, 0x872b7194
-0,         59,         59,        1,    11300, 0x007c36bd
-0,         60,         60,        1,    11300, 0x2714f1b5
-0,         61,         61,        1,    11300, 0x6c8eb50f
-0,         62,         62,        1,    11300, 0xf5d57be8
-0,         63,         63,        1,    11300, 0x981f412b
-0,         64,         64,        1,    11300, 0x1a9804a1
-0,         65,         65,        1,    11300, 0xf0c1d24a
-0,         66,         66,        1,    11300, 0xa70a9d9b
-0,         67,         67,        1,    11300, 0x8c466876
-0,         68,         68,        1,    11300, 0xcf2e32df
-0,         69,         69,        1,    11300, 0xcb8cfebf
-0,         70,         70,        1,    11300, 0xb961ca99
-0,         71,         71,        1,    11300, 0x666d9619
-0,         72,         72,        1,    11300, 0x84bf5b55
-0,         73,         73,        1,    11300, 0xbfa22ccc
-0,         74,         74,        1,    11300, 0xcde41849
-0,         75,         75,        1,    11300, 0x71372dcd
-0,         76,         76,        1,    11300, 0x13402cfd
-0,         77,         77,        1,    11300, 0xdebdd321
-0,         78,         78,        1,    11300, 0xdda66de1
-0,         79,         79,        1,    11300, 0x7f4bb682
-0,         80,         80,        1,    11300, 0xf67fd528
-0,         81,         81,        1,    11300, 0xe739ff8c
-0,         82,         82,        1,    11300, 0x2e131774
-0,         83,         83,        1,    11300, 0xfa942811
-0,         84,         84,        1,    11300, 0x0cd93ac2
-0,         85,         85,        1,    11300, 0xd0445e0e
-0,         86,         86,        1,    11300, 0x3f3497c7
-0,         87,         87,        1,    11300, 0x11b5bd2c
-0,         88,         88,        1,    11300, 0xccd5e62a
-0,         89,         89,        1,    11300, 0xa9d4fcb5
-0,         90,         90,        1,    11300, 0x34aa1a03
-0,         91,         91,        1,    11300, 0x1ce6299e
-0,         92,         92,        1,    11300, 0x661c2745
-0,         93,         93,        1,    11300, 0x27d8a8b3
-0,         94,         94,        1,    11300, 0x9eb07467
-0,         95,         95,        1,    11300, 0x128374d2
-0,         96,         96,        1,    11300, 0x05c36ff5
-0,         97,         97,        1,    11300, 0x8a136bde
-0,         98,         98,        1,    11300, 0x15c47c99
-0,         99,         99,        1,    11300, 0xcc4a93f4
-0,        100,        100,        1,    11300, 0x19529b2b
-0,        101,        101,        1,    11300, 0x9943c076
-0,        102,        102,        1,    11300, 0xf898e583
-0,        103,        103,        1,    11300, 0x40f71f94
-0,        104,        104,        1,    11300, 0x5b604afb
-0,        105,        105,        1,    11300, 0x8c176af4
-0,        106,        106,        1,    11300, 0x0f1a6216
-0,        107,        107,        1,    11300, 0x38bbd13d
-0,        108,        108,        1,    11300, 0x90c8d1fc
-0,        109,        109,        1,    11300, 0x253000d7
-0,        110,        110,        1,    11300, 0xb94b03b1
-0,        111,        111,        1,    11300, 0xbc872268
-0,        112,        112,        1,    11300, 0xe77adb8c
-0,        113,        113,        1,    11300, 0xa38936b7
-0,        114,        114,        1,    11300, 0xd6153632
-0,        115,        115,        1,    11300, 0x1ae633cc
-0,        116,        116,        1,    11300, 0xb90c286e
-0,        117,        117,        1,    11300, 0xbc7e333d
-0,        118,        118,        1,    11300, 0x1b5421f8
-0,        119,        119,        1,    11300, 0xdde6506d
-0,        120,        120,        1,    11300, 0xd3eb757e
-0,        121,        121,        1,    11300, 0x5ad1929c
-0,        122,        122,        1,    11300, 0x4f6aa47d
-0,        123,        123,        1,    11300, 0xab3caf55
-0,        124,        124,        1,    11300, 0x5ff9b39a
-0,        125,        125,        1,    11300, 0x1454e12e
-0,        126,        126,        1,    11300, 0xf18216e8
-0,        127,        127,        1,    11300, 0x62144880
-0,        128,        128,        1,    11300, 0x54284241
-0,        129,        129,        1,    11300, 0x8e8c7228
-0,        130,        130,        1,    11300, 0xb498d06e
-0,        131,        131,        1,    11300, 0x7b1e6be1
-0,        132,        132,        1,    11300, 0x5e5ea1f4
-0,        133,        133,        1,    11300, 0x41eda28e
-0,        134,        134,        1,    11300, 0x7ba6aa92
-0,        135,        135,        1,    11300, 0xa8a8b1c7
-0,        136,        136,        1,    11300, 0x0d30bd08
-0,        137,        137,        1,    11300, 0xc610bf16
-0,        138,        138,        1,    11300, 0xed57c075
-0,        139,        139,        1,    11300, 0xb86dbfea
-0,        140,        140,        1,    11300, 0x0970c03d
-0,        141,        141,        1,    11300, 0x743ac2ac
-0,        142,        142,        1,    11300, 0x0a44c816
-0,        143,        143,        1,    11300, 0xe32acd6b
-0,        144,        144,        1,    11300, 0x209bcdab
-0,        145,        145,        1,    11300, 0x3cd0d105
-0,        146,        146,        1,    11300, 0xc0bcd330
-0,        147,        147,        1,    11300, 0x4785d6dc
-0,        148,        148,        1,    11300, 0xe85f9c90
-0,        149,        149,        1,    11300, 0xd4a72850
-0,        150,        150,        1,    11300, 0x04766e41
-0,        151,        151,        1,    11300, 0x04766e41
+0,          0,          0,        1,    22500, 0x0f8e562e
+0,          1,          1,        1,    22500, 0x507aef06
+0,          2,          2,        1,    22500, 0x059d6137
+0,          3,          3,        1,    22500, 0xfb1bfd4e
+0,          4,          4,        1,    22500, 0xe97a51ba
+0,          5,          5,        1,    22500, 0xfc77e68e
+0,          6,          6,        1,    22500, 0x7f1985ac
+0,          7,          7,        1,    22500, 0xdfb933eb
+0,          8,          8,        1,    22500, 0x6dafe534
+0,          9,          9,        1,    22500, 0xb7b69abb
+0,         10,         10,        1,    22500, 0xc435c086
+0,         11,         11,        1,    22500, 0xf8ddb549
+0,         12,         12,        1,    22500, 0x76c0d70d
+0,         13,         13,        1,    22500, 0x1120bc82
+0,         14,         14,        1,    22500, 0x3f7c7970
+0,         15,         15,        1,    22500, 0xd37c9aee
+0,         16,         16,        1,    22500, 0x7407f81b
+0,         17,         17,        1,    22500, 0xce2f1c00
+0,         18,         18,        1,    22500, 0x70921eb5
+0,         19,         19,        1,    22500, 0x0abc917e
+0,         20,         20,        1,    22500, 0xeff1f0fa
+0,         21,         21,        1,    22500, 0x5e0d769b
+0,         22,         22,        1,    22500, 0xc984cbfd
+0,         23,         23,        1,    22500, 0x73f1caa9
+0,         24,         24,        1,    22500, 0x9108af6f
+0,         25,         25,        1,    22500, 0x4f33484e
+0,         26,         26,        1,    22500, 0x9810f8ca
+0,         27,         27,        1,    22500, 0xa0b97ca0
+0,         28,         28,        1,    22500, 0xd9c28ba3
+0,         29,         29,        1,    22500, 0xc97e17e6
+0,         30,         30,        1,    22500, 0x85cf86aa
+0,         31,         31,        1,    22500, 0xf15ff793
+0,         32,         32,        1,    22500, 0x35c54ab5
+0,         33,         33,        1,    22500, 0xe80ec129
+0,         34,         34,        1,    22500, 0x3d6cff39
+0,         35,         35,        1,    22500, 0x54e41aff
+0,         36,         36,        1,    22500, 0xc1d63293
+0,         37,         37,        1,    22500, 0x362c2dd4
+0,         38,         38,        1,    22500, 0xa1f8cdcf
+0,         39,         39,        1,    22500, 0x5b59ba62
+0,         40,         40,        1,    22500, 0x6d02f5b2
+0,         41,         41,        1,    22500, 0x899293ff
+0,         42,         42,        1,    22500, 0xad0e9ace
+0,         43,         43,        1,    22500, 0x4263f9db
+0,         44,         44,        1,    22500, 0xff1e481a
+0,         45,         45,        1,    22500, 0x70c86884
+0,         46,         46,        1,    22500, 0x203ed712
+0,         47,         47,        1,    22500, 0x2f0e8d46
+0,         48,         48,        1,    22500, 0x215075a9
+0,         49,         49,        1,    22500, 0x9882a978
+0,         50,         50,        1,    22500, 0xc2fd5209
+0,         51,         51,        1,    22500, 0xe1c925f6
+0,         52,         52,        1,    22500, 0x012be5af
+0,         53,         53,        1,    22500, 0xa718cbdb
+0,         54,         54,        1,    22500, 0x2494a1c3
+0,         55,         55,        1,    22500, 0xeb8980e4
+0,         56,         56,        1,    22500, 0x7f2766cb
+0,         57,         57,        1,    22500, 0xdf3cafa1
+0,         58,         58,        1,    22500, 0x9a390f81
+0,         59,         59,        1,    22500, 0xfdad5eed
+0,         60,         60,        1,    22500, 0x94f58ff3
+0,         61,         61,        1,    22500, 0xd7c6d9f2
+0,         62,         62,        1,    22500, 0x48b72e7d
+0,         63,         63,        1,    22500, 0x8a7a7e37
+0,         64,         64,        1,    22500, 0x5413c88a
+0,         65,         65,        1,    22500, 0x3f4531b2
+0,         66,         66,        1,    22500, 0x152d9396
+0,         67,         67,        1,    22500, 0x2ac3f418
+0,         68,         68,        1,    22500, 0x0e1c5353
+0,         69,         69,        1,    22500, 0xe058b711
+0,         70,         70,        1,    22500, 0x262e1a9f
+0,         71,         71,        1,    22500, 0x20057d10
+0,         72,         72,        1,    22500, 0x65c5ccb5
+0,         73,         73,        1,    22500, 0x3e36411a
+0,         74,         74,        1,    22500, 0xd9740391
+0,         75,         75,        1,    22500, 0x53d1441d
+0,         76,         76,        1,    22500, 0x9a3941ad
+0,         77,         77,        1,    22500, 0x61553437
+0,         78,         78,        1,    22500, 0xfe0c0468
+0,         79,         79,        1,    22500, 0xd57bde4b
+0,         80,         80,        1,    22500, 0x4a183a4c
+0,         81,         81,        1,    22500, 0xd618b978
+0,         82,         82,        1,    22500, 0x6b480112
+0,         83,         83,        1,    22500, 0x7a1732e9
+0,         84,         84,        1,    22500, 0x45836afc
+0,         85,         85,        1,    22500, 0x3548d4e0
+0,         86,         86,        1,    22500, 0x476c821a
+0,         87,         87,        1,    22500, 0x6be5f249
+0,         88,         88,        1,    22500, 0xf79b6d52
+0,         89,         89,        1,    22500, 0x2edeb0f3
+0,         90,         90,        1,    22500, 0xbaf808bf
+0,         91,         91,        1,    22500, 0x71013790
+0,         92,         92,        1,    22500, 0xbf4e3085
+0,         93,         93,        1,    22500, 0x15c2b4de
+0,         94,         94,        1,    22500, 0x031d17fa
+0,         95,         95,        1,    22500, 0x3a2c193b
+0,         96,         96,        1,    22500, 0xb0420aa4
+0,         97,         97,        1,    22500, 0xe448fe50
+0,         98,         98,        1,    22500, 0x02173090
+0,         99,         99,        1,    22500, 0x4b2f76a1
+0,        100,        100,        1,    22500, 0xd6458c46
+0,        101,        101,        1,    22500, 0xa698fc27
+0,        102,        102,        1,    22500, 0xaeca6b5d
+0,        103,        103,        1,    22500, 0x4a591972
+0,        104,        104,        1,    22500, 0x19e49ba7
+0,        105,        105,        1,    22500, 0x1d4ffb92
+0,        106,        106,        1,    22500, 0xb1f8e0f8
+0,        107,        107,        1,    22500, 0x32c82e8b
+0,        108,        108,        1,    22500, 0x96e930c8
+0,        109,        109,        1,    22500, 0x0e6ebd2c
+0,        110,        110,        1,    22500, 0x315bc5ba
+0,        111,        111,        1,    22500, 0xb22321ee
+0,        112,        112,        1,    22500, 0xbe464d78
+0,        113,        113,        1,    22500, 0xdb4b5edb
+0,        114,        114,        1,    22500, 0x0ff65d4c
+0,        115,        115,        1,    22500, 0xff68561a
+0,        116,        116,        1,    22500, 0xa0033400
+0,        117,        117,        1,    22500, 0x5414546d
+0,        118,        118,        1,    22500, 0x7e43209e
+0,        119,        119,        1,    22500, 0x0037abfd
+0,        120,        120,        1,    22500, 0x3dd31b3f
+0,        121,        121,        1,    22500, 0xe0777299
+0,        122,        122,        1,    22500, 0x35a2a83c
+0,        123,        123,        1,    22500, 0x5282c8c4
+0,        124,        124,        1,    22500, 0x1ccdd593
+0,        125,        125,        1,    22500, 0x92525e5e
+0,        126,        126,        1,    22500, 0x5fa3ff5f
+0,        127,        127,        1,    22500, 0xd1169436
+0,        128,        128,        1,    22500, 0x07dc8179
+0,        129,        129,        1,    22500, 0x9a83113d
+0,        130,        130,        1,    22500, 0x9c722c1e
+0,        131,        131,        1,    22500, 0xccbcfe59
+0,        132,        132,        1,    22500, 0x8606a0a1
+0,        133,        133,        1,    22500, 0x2210a26f
+0,        134,        134,        1,    22500, 0xfc73ba7b
+0,        135,        135,        1,    22500, 0x731fd01a
+0,        136,        136,        1,    22500, 0x0e21f1dd
+0,        137,        137,        1,    22500, 0xf9c4f807
+0,        138,        138,        1,    22500, 0x2123fc24
+0,        139,        139,        1,    22500, 0xd42cfa83
+0,        140,        140,        1,    22500, 0x5927fb7c
+0,        141,        141,        1,    22500, 0xe32e02d8
+0,        142,        142,        1,    22500, 0xa5c11316
+0,        143,        143,        1,    22500, 0xb9112315
+0,        144,        144,        1,    22500, 0x78f223d5
+0,        145,        145,        1,    22500, 0x93202de3
+0,        146,        146,        1,    22500, 0x7eb03464
+0,        147,        147,        1,    22500, 0x899c3f68
+0,        148,        148,        1,    22500, 0xc2169075
+0,        149,        149,        1,    22500, 0x419f33a6
+0,        150,        150,        1,    22500, 0x3de50588
+0,        151,        151,        1,    22500, 0x3de50588
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/cvid-partial b/mythtv/external/FFmpeg/tests/ref/fate/cvid-partial
index 907ef4a5d28..bb368a1eaef 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/cvid-partial
+++ b/mythtv/external/FFmpeg/tests/ref/fate/cvid-partial
@@ -1,80 +1,80 @@
 #tb 0: 1/12
-0,          0,          0,        1,   112400, 0x829180d8
-0,          1,          1,        1,   112400, 0xdbebac5b
-0,          2,          2,        1,   112400, 0xc5adc0f7
-0,          3,          3,        1,   112400, 0xbe1fc030
-0,          4,          4,        1,   112400, 0xe08ab460
-0,          5,          5,        1,   112400, 0xfde0dbc5
-0,          6,          6,        1,   112400, 0xed9242b0
-0,          7,          7,        1,   112400, 0x1ae3933a
-0,          8,          8,        1,   112400, 0xc82d2f5b
-0,          9,          9,        1,   112400, 0xbae9ddfc
-0,         10,         10,        1,   112400, 0xa350a1f7
-0,         11,         11,        1,   112400, 0x3cf78029
-0,         12,         12,        1,   112400, 0xaa0b82bf
-0,         13,         13,        1,   112400, 0x71aa4794
-0,         14,         14,        1,   112400, 0x2fe57373
-0,         15,         15,        1,   112400, 0x429c6f82
-0,         16,         16,        1,   112400, 0xfb2d917d
-0,         17,         17,        1,   112400, 0xcc84cb9a
-0,         18,         18,        1,   112400, 0xc68f0613
-0,         19,         19,        1,   112400, 0x05f30e6a
-0,         20,         20,        1,   112400, 0x5c5d853d
-0,         21,         21,        1,   112400, 0x01e0aff2
-0,         22,         22,        1,   112400, 0xc3b2cf4a
-0,         23,         23,        1,   112400, 0xc0a3cf19
-0,         24,         24,        1,   112400, 0xc743abda
-0,         25,         25,        1,   112400, 0x54bd17a2
-0,         26,         26,        1,   112400, 0x616ef28d
-0,         27,         27,        1,   112400, 0x04b51f59
-0,         28,         28,        1,   112400, 0x857511a2
-0,         29,         29,        1,   112400, 0x25c62440
-0,         30,         30,        1,   112400, 0x8c78198d
-0,         31,         31,        1,   112400, 0xc046c912
-0,         32,         32,        1,   112400, 0x0d828630
-0,         33,         33,        1,   112400, 0x48999b80
-0,         34,         34,        1,   112400, 0x9a869e77
-0,         35,         35,        1,   112400, 0x16d893df
-0,         36,         36,        1,   112400, 0xf6b86132
-0,         37,         37,        1,   112400, 0xfa564ea4
-0,         38,         38,        1,   112400, 0xdd473f69
-0,         39,         39,        1,   112400, 0xf89625a6
-0,         40,         40,        1,   112400, 0x823a58aa
-0,         41,         41,        1,   112400, 0x25e0fe43
-0,         42,         42,        1,   112400, 0x41034522
-0,         43,         43,        1,   112400, 0xb8da4f00
-0,         44,         44,        1,   112400, 0x9f684fce
-0,         45,         45,        1,   112400, 0xf7188710
-0,         46,         46,        1,   112400, 0x428fbfc6
-0,         47,         47,        1,   112400, 0x535bace0
-0,         48,         48,        1,   112400, 0x23216059
-0,         49,         49,        1,   112400, 0x9b8bbfa6
-0,         50,         50,        1,   112400, 0x932be522
-0,         51,         51,        1,   112400, 0xdbd31409
-0,         52,         52,        1,   112400, 0x0a69bf18
-0,         53,         53,        1,   112400, 0xa15ef128
-0,         54,         54,        1,   112400, 0x49a1fa92
-0,         55,         55,        1,   112400, 0xadeeaf62
-0,         56,         56,        1,   112400, 0xc1ce636e
-0,         57,         57,        1,   112400, 0x5ca544eb
-0,         58,         58,        1,   112400, 0x07230a36
-0,         59,         59,        1,   112400, 0x12ae2b53
-0,         60,         60,        1,   112400, 0x62453ef6
-0,         61,         61,        1,   112400, 0xe0588a98
-0,         62,         62,        1,   112400, 0xacd3927a
-0,         63,         63,        1,   112400, 0x5d3c6b01
-0,         64,         64,        1,   112400, 0xda671808
-0,         65,         65,        1,   112400, 0x61d0b492
-0,         66,         66,        1,   112400, 0x068b1293
-0,         67,         67,        1,   112400, 0x75b99287
-0,         68,         68,        1,   112400, 0xe657e7d6
-0,         69,         69,        1,   112400, 0x17873df6
-0,         70,         70,        1,   112400, 0xa8db5e31
-0,         71,         71,        1,   112400, 0x4f633b8e
-0,         72,         72,        1,   112400, 0x22266252
-0,         73,         73,        1,   112400, 0x308a6282
-0,         74,         74,        1,   112400, 0xfdb356ce
-0,         75,         75,        1,   112400, 0xe4394f1f
-0,         76,         76,        1,   112400, 0x8ca8649f
-0,         77,         77,        1,   112400, 0x804d44eb
-0,         78,         78,        1,   112400, 0x3864488b
+0,          0,          0,        1,   224400, 0xd8f2f310
+0,          1,          1,        1,   224400, 0xe38676c2
+0,          2,          2,        1,   224400, 0x7163b6ad
+0,          3,          3,        1,   224400, 0xa514b0f7
+0,          4,          4,        1,   224400, 0xeed48b96
+0,          5,          5,        1,   224400, 0x5e9f02b2
+0,          6,          6,        1,   224400, 0x70822c53
+0,          7,          7,        1,   224400, 0x93101067
+0,          8,          8,        1,   224400, 0x0710e900
+0,          9,          9,        1,   224400, 0x0e8add6a
+0,         10,         10,        1,   224400, 0x53fb2c5a
+0,         11,         11,        1,   224400, 0xa58cc02f
+0,         12,         12,        1,   224400, 0x0a5cc76b
+0,         13,         13,        1,   224400, 0xfa551631
+0,         14,         14,        1,   224400, 0xde9f99bf
+0,         15,         15,        1,   224400, 0xe66a8690
+0,         16,         16,        1,   224400, 0xd9e6f3d1
+0,         17,         17,        1,   224400, 0xa479a5c6
+0,         18,         18,        1,   224400, 0xdaa3531f
+0,         19,         19,        1,   224400, 0xde3e6843
+0,         20,         20,        1,   224400, 0x181adafd
+0,         21,         21,        1,   224400, 0x784b6429
+0,         22,         22,        1,   224400, 0x91cdc30e
+0,         23,         23,        1,   224400, 0x6e78be49
+0,         24,         24,        1,   224400, 0x7515644c
+0,         25,         25,        1,   224400, 0xcc32a91b
+0,         26,         26,        1,   224400, 0xc63e3831
+0,         27,         27,        1,   224400, 0xfb53b651
+0,         28,         28,        1,   224400, 0x12ec8a01
+0,         29,         29,        1,   224400, 0x136fcb2c
+0,         30,         30,        1,   224400, 0x827fa546
+0,         31,         31,        1,   224400, 0x1773b7f5
+0,         32,         32,        1,   224400, 0x732defc1
+0,         33,         33,        1,   224400, 0x84292372
+0,         34,         34,        1,   224400, 0x20f22365
+0,         35,         35,        1,   224400, 0xb39a0700
+0,         36,         36,        1,   224400, 0xf245706c
+0,         37,         37,        1,   224400, 0xdb702ae7
+0,         38,         38,        1,   224400, 0xadfefe5b
+0,         39,         39,        1,   224400, 0xa667adcb
+0,         40,         40,        1,   224400, 0x4d645191
+0,         41,         41,        1,   224400, 0x33802f58
+0,         42,         42,        1,   224400, 0x24eff4b8
+0,         43,         43,        1,   224400, 0x4dc817a6
+0,         44,         44,        1,   224400, 0x9a891d35
+0,         45,         45,        1,   224400, 0x2d0bb83b
+0,         46,         46,        1,   224400, 0xd13469c1
+0,         47,         47,        1,   224400, 0xd2e6302a
+0,         48,         48,        1,   224400, 0xc7594ee1
+0,         49,         49,        1,   224400, 0xc6da714c
+0,         50,         50,        1,   224400, 0xf675e838
+0,         51,         51,        1,   224400, 0xdc047c76
+0,         52,         52,        1,   224400, 0xe5727de5
+0,         53,         53,        1,   224400, 0x153b0f62
+0,         54,         54,        1,   224400, 0x65922f68
+0,         55,         55,        1,   224400, 0x04e04bfb
+0,         56,         56,        1,   224400, 0x1dde6c88
+0,         57,         57,        1,   224400, 0xed3905f2
+0,         58,         58,        1,   224400, 0x211a5996
+0,         59,         59,        1,   224400, 0xd010baaf
+0,         60,         60,        1,   224400, 0xcbc9f272
+0,         61,         61,        1,   224400, 0x7380d6f0
+0,         62,         62,        1,   224400, 0xfd0bf084
+0,         63,         63,        1,   224400, 0xc4d671d9
+0,         64,         64,        1,   224400, 0x84236aa5
+0,         65,         65,        1,   224400, 0x9c584ede
+0,         66,         66,        1,   224400, 0xdb0c6029
+0,         67,         67,        1,   224400, 0x775ae560
+0,         68,         68,        1,   224400, 0xe3800916
+0,         69,         69,        1,   224400, 0x9313a8e8
+0,         70,         70,        1,   224400, 0x3a5d07cc
+0,         71,         71,        1,   224400, 0x4651a10b
+0,         72,         72,        1,   224400, 0xc2d72183
+0,         73,         73,        1,   224400, 0xcd971625
+0,         74,         74,        1,   224400, 0x9fb0f3c2
+0,         75,         75,        1,   224400, 0x920ee561
+0,         76,         76,        1,   224400, 0x8a2c1bbf
+0,         77,         77,        1,   224400, 0x6150c072
+0,         78,         78,        1,   224400, 0x499dc869
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/dirac b/mythtv/external/FFmpeg/tests/ref/fate/dirac
new file mode 100644
index 00000000000..7781b4e5ddd
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/dirac
@@ -0,0 +1,3 @@
+#tb 0: 1/30
+0,          0,          0,        1,   115200, 0xf73819e8
+0,          1,          1,        1,   115200, 0x082e3788
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/eval b/mythtv/external/FFmpeg/tests/ref/fate/eval
index 8dda06b9982..59e3fe40a49 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/eval
+++ b/mythtv/external/FFmpeg/tests/ref/fate/eval
@@ -205,12 +205,24 @@ Evaluating 'pow(-1,1.23)'
 Evaluating 'if(1, 2)'
 'if(1, 2)' -> 2.000000
 
+Evaluating 'if(1, 1, 2)'
+'if(1, 1, 2)' -> 1.000000
+
+Evaluating 'if(0, 1, 2)'
+'if(0, 1, 2)' -> 2.000000
+
 Evaluating 'ifnot(0, 23)'
 'ifnot(0, 23)' -> 23.000000
 
 Evaluating 'ifnot(1, NaN) + if(0, 1)'
 'ifnot(1, NaN) + if(0, 1)' -> 0.000000
 
+Evaluating 'ifnot(1, 1, 2)'
+'ifnot(1, 1, 2)' -> 2.000000
+
+Evaluating 'ifnot(0, 1, 2)'
+'ifnot(0, 1, 2)' -> 1.000000
+
 Evaluating 'taylor(1, 1)'
 'taylor(1, 1)' -> 2.718282
 
@@ -235,8 +247,8 @@ Evaluating 'gauss(0.1)'
 Evaluating 'hypot(4,3)'
 'hypot(4,3)' -> 5.000000
 
-Evaluating 'gcd(30,55)*min(9,1)'
-'gcd(30,55)*min(9,1)' -> 5.000000
+Evaluating 'gcd(30,55)*print(min(9,1))'
+'gcd(30,55)*print(min(9,1))' -> 5.000000
 
 12.700000 == 12.7
 0.931323 == 0.931322575
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/film-cvid b/mythtv/external/FFmpeg/tests/ref/fate/film-cvid
index 12b1f1cdcba..3ca7b5981c8 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/film-cvid
+++ b/mythtv/external/FFmpeg/tests/ref/fate/film-cvid
@@ -1,111 +1,111 @@
 #tb 0: 1/30
-0,          0,          0,        1,   107520, 0xa6c9fdd2
-0,          2,          2,        1,   107520, 0x61eb28c1
-0,          4,          4,        1,   107520, 0x45e20af7
-0,          6,          6,        1,   107520, 0x366970fc
-0,          8,          8,        1,   107520, 0xa392bcb3
-0,         10,         10,        1,   107520, 0xcf7bac98
-0,         12,         12,        1,   107520, 0x222eba53
-0,         14,         14,        1,   107520, 0x74e255a1
-0,         16,         16,        1,   107520, 0xc19eec6f
-0,         18,         18,        1,   107520, 0xa3880681
-0,         20,         20,        1,   107520, 0x957878db
-0,         22,         22,        1,   107520, 0x18340692
-0,         24,         24,        1,   107520, 0x9970f24d
-0,         26,         26,        1,   107520, 0xf08618aa
-0,         28,         28,        1,   107520, 0xee7324f0
-0,         30,         30,        1,   107520, 0xe15025b3
-0,         32,         32,        1,   107520, 0x8afa312e
-0,         34,         34,        1,   107520, 0x717a7d0f
-0,         36,         36,        1,   107520, 0x355c6e23
-0,         38,         38,        1,   107520, 0x7015a50f
-0,         40,         40,        1,   107520, 0xcdfc1a16
-0,         42,         42,        1,   107520, 0x38d929e7
-0,         44,         44,        1,   107520, 0x52913423
-0,         46,         46,        1,   107520, 0xe2c91c10
-0,         48,         48,        1,   107520, 0x85516e9c
-0,         50,         50,        1,   107520, 0xd1626030
-0,         52,         52,        1,   107520, 0xea7b16de
-0,         54,         54,        1,   107520, 0xa33eaa0d
-0,         56,         56,        1,   107520, 0x8e3be6a6
-0,         58,         58,        1,   107520, 0x14147bd6
-0,         60,         60,        1,   107520, 0x07d54bec
-0,         62,         62,        1,   107520, 0xe287a0a7
-0,         64,         64,        1,   107520, 0xc023a14d
-0,         66,         66,        1,   107520, 0x2437085d
-0,         68,         68,        1,   107520, 0x63823918
-0,         70,         70,        1,   107520, 0xbc17e198
-0,         72,         72,        1,   107520, 0x9d99bc81
-0,         74,         74,        1,   107520, 0x7e4ec71e
-0,         76,         76,        1,   107520, 0x55b98376
-0,         78,         78,        1,   107520, 0x356d8e9e
-0,         80,         80,        1,   107520, 0xf77e8a61
-0,         82,         82,        1,   107520, 0x5ae7c8c7
-0,         84,         84,        1,   107520, 0x8acf9322
-0,         86,         86,        1,   107520, 0x40a9177e
-0,         88,         88,        1,   107520, 0x3e0e4d8d
-0,         90,         90,        1,   107520, 0xd268865b
-0,         92,         92,        1,   107520, 0x89a4efeb
-0,         94,         94,        1,   107520, 0x70ca2478
-0,         96,         96,        1,   107520, 0xcc9ec981
-0,         98,         98,        1,   107520, 0xf0648459
-0,        100,        100,        1,   107520, 0x7e4a4cca
-0,        102,        102,        1,   107520, 0xb315dc65
-0,        104,        104,        1,   107520, 0x2aecc7b4
-0,        106,        106,        1,   107520, 0x81742f51
-0,        108,        108,        1,   107520, 0x3a1d7571
-0,        110,        110,        1,   107520, 0x3a1d7571
-0,        112,        112,        1,   107520, 0x3a1d7571
-0,        114,        114,        1,   107520, 0x3a1d7571
-0,        116,        116,        1,   107520, 0x3a1d7571
-0,        118,        118,        1,   107520, 0x3a1d7571
-0,        120,        120,        1,   107520, 0x3a1d7571
-0,        122,        122,        1,   107520, 0xe974733e
-0,        124,        124,        1,   107520, 0x999c6fbf
-0,        126,        126,        1,   107520, 0x26b56b6e
-0,        128,        128,        1,   107520, 0xc9f9647b
-0,        130,        130,        1,   107520, 0x6d025d00
-0,        132,        132,        1,   107520, 0xf9c056c1
-0,        134,        134,        1,   107520, 0xa5cc4d0b
-0,        136,        136,        1,   107520, 0x1a4c4236
-0,        138,        138,        1,   107520, 0xa9d538b6
-0,        140,        140,        1,   107520, 0x14682d00
-0,        142,        142,        1,   107520, 0x6236204f
-0,        144,        144,        1,   107520, 0x303e14aa
-0,        146,        146,        1,   107520, 0x943b0837
-0,        148,        148,        1,   107520, 0xfce5fd07
-0,        150,        150,        1,   107520, 0xd993f193
-0,        152,        152,        1,   107520, 0x4d48e7b4
-0,        154,        154,        1,   107520, 0x61ccdf83
-0,        156,        156,        1,   107520, 0xfb4fd608
-0,        158,        158,        1,   107520, 0x5efdcdb3
-0,        160,        160,        1,   107520, 0xb03ec886
-0,        162,        162,        1,   107520, 0xf464c343
-0,        164,        164,        1,   107520, 0xf464c343
-0,        166,        166,        1,   107520, 0xf464c343
-0,        168,        168,        1,   107520, 0xf464c343
-0,        170,        170,        1,   107520, 0xf464c343
-0,        172,        172,        1,   107520, 0xf464c343
-0,        174,        174,        1,   107520, 0xf464c343
-0,        176,        176,        1,   107520, 0xf464c343
-0,        178,        178,        1,   107520, 0xf464c343
-0,        180,        180,        1,   107520, 0xf464c343
-0,        182,        182,        1,   107520, 0xf464c343
-0,        184,        184,        1,   107520, 0xf2b2c712
-0,        186,        186,        1,   107520, 0xf2b2c712
-0,        188,        188,        1,   107520, 0xf2b2c712
-0,        190,        190,        1,   107520, 0xf2b2c712
-0,        192,        192,        1,   107520, 0xb95e6bc8
-0,        194,        194,        1,   107520, 0x33feee37
-0,        196,        196,        1,   107520, 0x36ee3cd5
-0,        198,        198,        1,   107520, 0x59096471
-0,        200,        200,        1,   107520, 0x53b470c6
-0,        202,        202,        1,   107520, 0xdb7c64ff
-0,        204,        204,        1,   107520, 0xe5a1596a
-0,        206,        206,        1,   107520, 0x8c8942eb
-0,        208,        208,        1,   107520, 0x5ecc379e
-0,        210,        210,        1,   107520, 0xea09432a
-0,        212,        212,        1,   107520, 0xe01e6b73
-0,        214,        214,        1,   107520, 0x1d13bba8
-0,        216,        216,        1,   107520, 0x3a993a6c
-0,        218,        218,        1,   107520, 0x2ede041a
+0,          0,          0,        1,   215040, 0x067c5362
+0,          2,          2,        1,   215040, 0xd9eacb98
+0,          4,          4,        1,   215040, 0x3c8a4cbd
+0,          6,          6,        1,   215040, 0xbdf996e1
+0,          8,          8,        1,   215040, 0x1b7fa123
+0,         10,         10,        1,   215040, 0x834b4a8d
+0,         12,         12,        1,   215040, 0xf4b1bebe
+0,         14,         14,        1,   215040, 0x088c3802
+0,         16,         16,        1,   215040, 0xf6ddedb9
+0,         18,         18,        1,   215040, 0x2791d538
+0,         20,         20,        1,   215040, 0x81fe4688
+0,         22,         22,        1,   215040, 0xad864fbd
+0,         24,         24,        1,   215040, 0xa637a97a
+0,         26,         26,        1,   215040, 0x2287e378
+0,         28,         28,        1,   215040, 0x13a017d7
+0,         30,         30,        1,   215040, 0x89a4acee
+0,         32,         32,        1,   215040, 0x97888ffc
+0,         34,         34,        1,   215040, 0x7c2c3b58
+0,         36,         36,        1,   215040, 0x2e3ab808
+0,         38,         38,        1,   215040, 0x2d553af2
+0,         40,         40,        1,   215040, 0x929c420e
+0,         42,         42,        1,   215040, 0x4841bd6d
+0,         44,         44,        1,   215040, 0xb350fbcd
+0,         46,         46,        1,   215040, 0x0d70b918
+0,         48,         48,        1,   215040, 0xf98b0f47
+0,         50,         50,        1,   215040, 0x748b8ff2
+0,         52,         52,        1,   215040, 0x62017c38
+0,         54,         54,        1,   215040, 0x46042bb4
+0,         56,         56,        1,   215040, 0xe7a74806
+0,         58,         58,        1,   215040, 0xb4c856e6
+0,         60,         60,        1,   215040, 0xb21a28dd
+0,         62,         62,        1,   215040, 0x2a6e0834
+0,         64,         64,        1,   215040, 0x7044d6ca
+0,         66,         66,        1,   215040, 0x17780335
+0,         68,         68,        1,   215040, 0x94f51e7a
+0,         70,         70,        1,   215040, 0x5beb5f5f
+0,         72,         72,        1,   215040, 0xc7d59527
+0,         74,         74,        1,   215040, 0x40f69049
+0,         76,         76,        1,   215040, 0x1f78740e
+0,         78,         78,        1,   215040, 0x49f7265d
+0,         80,         80,        1,   215040, 0x057ac5c9
+0,         82,         82,        1,   215040, 0x649bd476
+0,         84,         84,        1,   215040, 0x1c75aa43
+0,         86,         86,        1,   215040, 0xc4bd1e29
+0,         88,         88,        1,   215040, 0x5033fa74
+0,         90,         90,        1,   215040, 0xba5c949e
+0,         92,         92,        1,   215040, 0x2fa78a0e
+0,         94,         94,        1,   215040, 0x9d363dce
+0,         96,         96,        1,   215040, 0xd1dc82b0
+0,         98,         98,        1,   215040, 0xd25be322
+0,        100,        100,        1,   215040, 0xf1374ef9
+0,        102,        102,        1,   215040, 0x33467b42
+0,        104,        104,        1,   215040, 0x7ec7dfad
+0,        106,        106,        1,   215040, 0x706ed416
+0,        108,        108,        1,   215040, 0x6576b3eb
+0,        110,        110,        1,   215040, 0x6576b3eb
+0,        112,        112,        1,   215040, 0x6576b3eb
+0,        114,        114,        1,   215040, 0x6576b3eb
+0,        116,        116,        1,   215040, 0x6576b3eb
+0,        118,        118,        1,   215040, 0x6576b3eb
+0,        120,        120,        1,   215040, 0x6576b3eb
+0,        122,        122,        1,   215040, 0x6873993d
+0,        124,        124,        1,   215040, 0x8c2a84d8
+0,        126,        126,        1,   215040, 0xdd456bd5
+0,        128,        128,        1,   215040, 0x50fa4f3d
+0,        130,        130,        1,   215040, 0x00c4369c
+0,        132,        132,        1,   215040, 0xe4c220d2
+0,        134,        134,        1,   215040, 0xe43a033b
+0,        136,        136,        1,   215040, 0x72f6e32c
+0,        138,        138,        1,   215040, 0xb738c69c
+0,        140,        140,        1,   215040, 0x56bda3fe
+0,        142,        142,        1,   215040, 0xaa2f7da3
+0,        144,        144,        1,   215040, 0xf21f5c24
+0,        146,        146,        1,   215040, 0xd33e3579
+0,        148,        148,        1,   215040, 0x6a601495
+0,        150,        150,        1,   215040, 0xdfcff1e0
+0,        152,        152,        1,   215040, 0xa774d327
+0,        154,        154,        1,   215040, 0x8e9db8c9
+0,        156,        156,        1,   215040, 0xb4fd9689
+0,        158,        158,        1,   215040, 0xa80b77ff
+0,        160,        160,        1,   215040, 0x1d9c6568
+0,        162,        162,        1,   215040, 0x388c515a
+0,        164,        164,        1,   215040, 0x388c515a
+0,        166,        166,        1,   215040, 0x388c515a
+0,        168,        168,        1,   215040, 0x388c515a
+0,        170,        170,        1,   215040, 0x388c515a
+0,        172,        172,        1,   215040, 0x388c515a
+0,        174,        174,        1,   215040, 0x388c515a
+0,        176,        176,        1,   215040, 0x388c515a
+0,        178,        178,        1,   215040, 0x388c515a
+0,        180,        180,        1,   215040, 0x388c515a
+0,        182,        182,        1,   215040, 0x388c515a
+0,        184,        184,        1,   215040, 0x3aef5fee
+0,        186,        186,        1,   215040, 0x3aef5fee
+0,        188,        188,        1,   215040, 0x3aef5fee
+0,        190,        190,        1,   215040, 0x3aef5fee
+0,        192,        192,        1,   215040, 0x7f8e4b62
+0,        194,        194,        1,   215040, 0xbf9fcae8
+0,        196,        196,        1,   215040, 0x02f9a66c
+0,        198,        198,        1,   215040, 0x00ef062f
+0,        200,        200,        1,   215040, 0xe83b132c
+0,        202,        202,        1,   215040, 0x2701d21b
+0,        204,        204,        1,   215040, 0xbea79188
+0,        206,        206,        1,   215040, 0x6f6d3109
+0,        208,        208,        1,   215040, 0x4173f1e8
+0,        210,        210,        1,   215040, 0xd7adfce1
+0,        212,        212,        1,   215040, 0xa3825ffd
+0,        214,        214,        1,   215040, 0x41e63fe4
+0,        216,        216,        1,   215040, 0xb525b9c5
+0,        218,        218,        1,   215040, 0x00000000
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/filter-yadif-mode0 b/mythtv/external/FFmpeg/tests/ref/fate/filter-yadif-mode0
index 7014333c4c0..162ba96ac1e 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/filter-yadif-mode0
+++ b/mythtv/external/FFmpeg/tests/ref/fate/filter-yadif-mode0
@@ -1,32 +1,32 @@
 #tb 0: 1/25
-0,          9,          9,        1,   622080, 0x4440caef
-0,         10,         10,        1,   622080, 0xce67e69d
-0,         11,         11,        1,   622080, 0x1dbdc653
-0,         12,         12,        1,   622080, 0x55c791d0
-0,         13,         13,        1,   622080, 0x8193740b
-0,         14,         14,        1,   622080, 0x7125970f
-0,         15,         15,        1,   622080, 0xeb63783a
-0,         16,         16,        1,   622080, 0x7080590b
-0,         17,         17,        1,   622080, 0x13f8175b
-0,         18,         18,        1,   622080, 0x3e550e94
-0,         19,         19,        1,   622080, 0x7f9d66f7
-0,         20,         20,        1,   622080, 0x068eda80
-0,         21,         21,        1,   622080, 0x843997f7
-0,         22,         22,        1,   622080, 0x88207ca3
-0,         23,         23,        1,   622080, 0x353eed75
-0,         24,         24,        1,   622080, 0xf93e92b0
-0,         25,         25,        1,   622080, 0xd0811094
-0,         26,         26,        1,   622080, 0xb04a3141
-0,         27,         27,        1,   622080, 0x4ab84909
-0,         28,         28,        1,   622080, 0x4700b8f9
-0,         29,         29,        1,   622080, 0x6305aeba
-0,         30,         30,        1,   622080, 0x153faa3e
-0,         31,         31,        1,   622080, 0xae724063
-0,         32,         32,        1,   622080, 0xbe4fe779
-0,         33,         33,        1,   622080, 0x209ed8c7
-0,         34,         34,        1,   622080, 0xe2bbac96
-0,         35,         35,        1,   622080, 0xe945441e
-0,         36,         36,        1,   622080, 0x3590bd5d
-0,         37,         37,        1,   622080, 0x8f3ef716
-0,         38,         38,        1,   622080, 0x0109f125
-0,         39,         39,        1,   622080, 0x230c373f
+0,          9,          9,        1,   622080, 0x6331caee
+0,         10,         10,        1,   622080, 0xa459e690
+0,         11,         11,        1,   622080, 0x6429c648
+0,         12,         12,        1,   622080, 0xa49891ca
+0,         13,         13,        1,   622080, 0x2a887404
+0,         14,         14,        1,   622080, 0xe8d49705
+0,         15,         15,        1,   622080, 0x1b627835
+0,         16,         16,        1,   622080, 0x686858fd
+0,         17,         17,        1,   622080, 0x2675174f
+0,         18,         18,        1,   622080, 0x78470e7f
+0,         19,         19,        1,   622080, 0xffb366ec
+0,         20,         20,        1,   622080, 0xd575da72
+0,         21,         21,        1,   622080, 0x5fb297f7
+0,         22,         22,        1,   622080, 0xbac77ca0
+0,         23,         23,        1,   622080, 0x3276ed72
+0,         24,         24,        1,   622080, 0x264092b2
+0,         25,         25,        1,   622080, 0x20ba1094
+0,         26,         26,        1,   622080, 0x76cc3139
+0,         27,         27,        1,   622080, 0x469a4902
+0,         28,         28,        1,   622080, 0x0ed7b8f5
+0,         29,         29,        1,   622080, 0xdc51aeac
+0,         30,         30,        1,   622080, 0xee06aa36
+0,         31,         31,        1,   622080, 0x7372405f
+0,         32,         32,        1,   622080, 0x9e0ee776
+0,         33,         33,        1,   622080, 0x39e6d8c9
+0,         34,         34,        1,   622080, 0x51d9ac9a
+0,         35,         35,        1,   622080, 0x2b63441d
+0,         36,         36,        1,   622080, 0x58afbd5e
+0,         37,         37,        1,   622080, 0xb972f716
+0,         38,         38,        1,   622080, 0x6a6df129
+0,         39,         39,        1,   622080, 0x28b1373d
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/filter-yadif-mode1 b/mythtv/external/FFmpeg/tests/ref/fate/filter-yadif-mode1
index 87c8d97b6db..f1f513ef3c0 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/filter-yadif-mode1
+++ b/mythtv/external/FFmpeg/tests/ref/fate/filter-yadif-mode1
@@ -1,63 +1,63 @@
 #tb 0: 1/50
-0,         18,         18,        1,   622080, 0x4440caef
-0,         19,         19,        1,   622080, 0xa5cea88b
-0,         20,         20,        1,   622080, 0xce67e69d
-0,         21,         21,        1,   622080, 0x9a57891f
-0,         22,         22,        1,   622080, 0x1dbdc653
-0,         23,         23,        1,   622080, 0xc171c0c5
-0,         24,         24,        1,   622080, 0x55c791d0
-0,         25,         25,        1,   622080, 0x20db9890
-0,         26,         26,        1,   622080, 0x8193740b
-0,         27,         27,        1,   622080, 0xdb181d52
-0,         28,         28,        1,   622080, 0x7125970f
-0,         29,         29,        1,   622080, 0xc2b913d1
-0,         30,         30,        1,   622080, 0xeb63783a
-0,         31,         31,        1,   622080, 0xf1d9c5fb
-0,         32,         32,        1,   622080, 0x7080590b
-0,         33,         33,        1,   622080, 0xeda55774
-0,         34,         34,        1,   622080, 0x13f8175b
-0,         35,         35,        1,   622080, 0x01921a16
-0,         36,         36,        1,   622080, 0x3e550e94
-0,         37,         37,        1,   622080, 0xd5047bc9
-0,         38,         38,        1,   622080, 0x7f9d66f7
-0,         39,         39,        1,   622080, 0x2fc806ea
-0,         40,         40,        1,   622080, 0x068eda80
-0,         41,         41,        1,   622080, 0xf0e125a7
-0,         42,         42,        1,   622080, 0x843997f7
-0,         43,         43,        1,   622080, 0x4afe2976
-0,         44,         44,        1,   622080, 0x88207ca3
-0,         45,         45,        1,   622080, 0x637fcbfe
-0,         46,         46,        1,   622080, 0x353eed75
-0,         47,         47,        1,   622080, 0xd9a8f5ac
-0,         48,         48,        1,   622080, 0xf93e92b0
-0,         49,         49,        1,   622080, 0x4540039f
-0,         50,         50,        1,   622080, 0xd0811094
-0,         51,         51,        1,   622080, 0x3039906f
-0,         52,         52,        1,   622080, 0xb04a3141
-0,         53,         53,        1,   622080, 0xe62d2cfa
-0,         54,         54,        1,   622080, 0x4ab84909
-0,         55,         55,        1,   622080, 0x82de12ee
-0,         56,         56,        1,   622080, 0x4700b8f9
-0,         57,         57,        1,   622080, 0x7e849cc9
-0,         58,         58,        1,   622080, 0x6305aeba
-0,         59,         59,        1,   622080, 0x939bf771
-0,         60,         60,        1,   622080, 0x153faa3e
-0,         61,         61,        1,   622080, 0xb67f3233
-0,         62,         62,        1,   622080, 0xae724063
-0,         63,         63,        1,   622080, 0xed2b44b3
-0,         64,         64,        1,   622080, 0xbe4fe779
-0,         65,         65,        1,   622080, 0x380f8563
-0,         66,         66,        1,   622080, 0x209ed8c7
-0,         67,         67,        1,   622080, 0xb964d70f
-0,         68,         68,        1,   622080, 0xe2bbac96
-0,         69,         69,        1,   622080, 0x4f60f7f4
-0,         70,         70,        1,   622080, 0xe945441e
-0,         71,         71,        1,   622080, 0xded0b740
-0,         72,         72,        1,   622080, 0x3590bd5d
-0,         73,         73,        1,   622080, 0xb9a15294
-0,         74,         74,        1,   622080, 0x8f3ef716
-0,         75,         75,        1,   622080, 0x3e2301a8
-0,         76,         76,        1,   622080, 0x0109f125
-0,         77,         77,        1,   622080, 0x5252371e
-0,         78,         78,        1,   622080, 0x230c373f
-0,         79,         79,        1,   622080, 0x5a1ab1f1
+0,         18,         18,        1,   622080, 0x6331caee
+0,         19,         19,        1,   622080, 0x625da883
+0,         20,         20,        1,   622080, 0xa459e690
+0,         21,         21,        1,   622080, 0xce5d891e
+0,         22,         22,        1,   622080, 0x6429c648
+0,         23,         23,        1,   622080, 0x608cc0ba
+0,         24,         24,        1,   622080, 0xa49891ca
+0,         25,         25,        1,   622080, 0x9721987f
+0,         26,         26,        1,   622080, 0x2a887404
+0,         27,         27,        1,   622080, 0x60d71d47
+0,         28,         28,        1,   622080, 0xe8d49705
+0,         29,         29,        1,   622080, 0x821e13cb
+0,         30,         30,        1,   622080, 0x1b627835
+0,         31,         31,        1,   622080, 0x1806c5f4
+0,         32,         32,        1,   622080, 0x686858fd
+0,         33,         33,        1,   622080, 0xab865773
+0,         34,         34,        1,   622080, 0x2675174f
+0,         35,         35,        1,   622080, 0x43a61a14
+0,         36,         36,        1,   622080, 0x78470e7f
+0,         37,         37,        1,   622080, 0xeb877bc6
+0,         38,         38,        1,   622080, 0xffb366ec
+0,         39,         39,        1,   622080, 0xda0906e7
+0,         40,         40,        1,   622080, 0xd575da72
+0,         41,         41,        1,   622080, 0x23ae25a4
+0,         42,         42,        1,   622080, 0x5fb297f7
+0,         43,         43,        1,   622080, 0x99b32978
+0,         44,         44,        1,   622080, 0xbac77ca0
+0,         45,         45,        1,   622080, 0xc1cdcbf9
+0,         46,         46,        1,   622080, 0x3276ed72
+0,         47,         47,        1,   622080, 0x4061f5ab
+0,         48,         48,        1,   622080, 0x264092b2
+0,         49,         49,        1,   622080, 0xa4e2039e
+0,         50,         50,        1,   622080, 0x20ba1094
+0,         51,         51,        1,   622080, 0x984e906e
+0,         52,         52,        1,   622080, 0x76cc3139
+0,         53,         53,        1,   622080, 0xf70e2cf6
+0,         54,         54,        1,   622080, 0x469a4902
+0,         55,         55,        1,   622080, 0x235312e6
+0,         56,         56,        1,   622080, 0x0ed7b8f5
+0,         57,         57,        1,   622080, 0xd0269cc3
+0,         58,         58,        1,   622080, 0xdc51aeac
+0,         59,         59,        1,   622080, 0x1aa5f76e
+0,         60,         60,        1,   622080, 0xee06aa36
+0,         61,         61,        1,   622080, 0xa7103230
+0,         62,         62,        1,   622080, 0x7372405f
+0,         63,         63,        1,   622080, 0x8d7a44b5
+0,         64,         64,        1,   622080, 0x9e0ee776
+0,         65,         65,        1,   622080, 0xd41e8560
+0,         66,         66,        1,   622080, 0x39e6d8c9
+0,         67,         67,        1,   622080, 0x7a23d70c
+0,         68,         68,        1,   622080, 0x51d9ac9a
+0,         69,         69,        1,   622080, 0x8eacf7f2
+0,         70,         70,        1,   622080, 0x2b63441d
+0,         71,         71,        1,   622080, 0x9f71b742
+0,         72,         72,        1,   622080, 0x58afbd5e
+0,         73,         73,        1,   622080, 0x4d645292
+0,         74,         74,        1,   622080, 0xb972f716
+0,         75,         75,        1,   622080, 0xbb5d01a2
+0,         76,         76,        1,   622080, 0x6a6df129
+0,         77,         77,        1,   622080, 0x9e45371e
+0,         78,         78,        1,   622080, 0x28b1373d
+0,         79,         79,        1,   622080, 0xa1cdb1f2
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/gif-color b/mythtv/external/FFmpeg/tests/ref/fate/gif-color
new file mode 100644
index 00000000000..6abb565783a
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/gif-color
@@ -0,0 +1,174 @@
+#tb 0: 1/100
+0,          0,          0,        1,   188356, 0xf0944065
+0,         10,         10,        1,   188356, 0x146ed4c4
+0,         20,         20,        1,   188356, 0x96866a6f
+0,         30,         30,        1,   188356, 0xe15e1f1c
+0,         40,         40,        1,   188356, 0x0662c1d0
+0,         50,         50,        1,   188356, 0x88fa6cc4
+0,         60,         60,        1,   188356, 0x3cce2f71
+0,         70,         70,        1,   188356, 0x1510f9f3
+0,         80,         80,        1,   188356, 0xf27e9fa8
+0,         90,         90,        1,   188356, 0x0f4b64a2
+0,        100,        100,        1,   188356, 0x3d2714a5
+0,        110,        110,        1,   188356, 0x392ce45d
+0,        120,        120,        1,   188356, 0x2eadb79f
+0,        130,        130,        1,   188356, 0x68109314
+0,        140,        140,        1,   188356, 0x4eca71ac
+0,        150,        150,        1,   188356, 0xa9aa5907
+0,        160,        160,        1,   188356, 0x2a5d08c0
+0,        170,        170,        1,   188356, 0x942bba84
+0,        180,        180,        1,   188356, 0xbee38983
+0,        190,        190,        1,   188356, 0xa0d65a5a
+0,        200,        200,        1,   188356, 0x47270bee
+0,        210,        210,        1,   188356, 0xc020dc40
+0,        220,        220,        1,   188356, 0x978dbc8f
+0,        230,        230,        1,   188356, 0x6b1e9f1b
+0,        240,        240,        1,   188356, 0xd8078bf4
+0,        250,        250,        1,   188356, 0x94ca7bd7
+0,        260,        260,        1,   188356, 0xac745e77
+0,        270,        270,        1,   188356, 0x73154f2c
+0,        280,        280,        1,   188356, 0x31200601
+0,        290,        290,        1,   188356, 0x6525dd42
+0,        300,        300,        1,   188356, 0xa29b985a
+0,        310,        310,        1,   188356, 0xe3e074d8
+0,        320,        320,        1,   188356, 0xb87b3222
+0,        330,        330,        1,   188356, 0x5b9a11f2
+0,        340,        340,        1,   188356, 0x25f7f8c9
+0,        350,        350,        1,   188356, 0x0235e93c
+0,        360,        360,        1,   188356, 0x2a42d643
+0,        370,        370,        1,   188356, 0xfb7acddb
+0,        380,        380,        1,   188356, 0xecbbbf5e
+0,        390,        390,        1,   188356, 0xeba4bc9a
+0,        400,        400,        1,   188356, 0x4317b36b
+0,        410,        410,        1,   188356, 0x7316ae1a
+0,        420,        420,        1,   188356, 0xb5ccad05
+0,        430,        430,        1,   188356, 0x38afb0dc
+0,        440,        440,        1,   188356, 0xf11cad55
+0,        450,        450,        1,   188356, 0x3d77b400
+0,        460,        460,        1,   188356, 0xf084b9b9
+0,        470,        470,        1,   188356, 0x02a4c584
+0,        480,        480,        1,   188356, 0x14f4d52e
+0,        490,        490,        1,   188356, 0x55118432
+0,        500,        500,        1,   188356, 0x4ad82e9f
+0,        510,        510,        1,   188356, 0xc6eafc52
+0,        520,        520,        1,   188356, 0xf4bdc575
+0,        530,        530,        1,   188356, 0x8429689e
+0,        540,        540,        1,   188356, 0xaa23019e
+0,        550,        550,        1,   188356, 0xaf52c3a5
+0,        560,        560,        1,   188356, 0x1d387c32
+0,        570,        570,        1,   188356, 0x543d5cd2
+0,        580,        580,        1,   188356, 0x8cdb399c
+0,        590,        590,        1,   188356, 0xcceb292f
+0,        600,        600,        1,   188356, 0xa87115e8
+0,        610,        610,        1,   188356, 0x9665ec8f
+0,        620,        620,        1,   188356, 0xad99baf4
+0,        630,        630,        1,   188356, 0xc6e5a2b5
+0,        640,        640,        1,   188356, 0xe2a48359
+0,        650,        650,        1,   188356, 0x3a270df0
+0,        660,        660,        1,   188356, 0xcc34826b
+0,        670,        670,        1,   188356, 0x15ec2dcc
+0,        680,        680,        1,   188356, 0x8874c5f9
+0,        690,        690,        1,   188356, 0x829966e8
+0,        700,        700,        1,   188356, 0x691f1ebb
+0,        710,        710,        1,   188356, 0x00e3e184
+0,        720,        720,        1,   188356, 0x97739332
+0,        730,        730,        1,   188356, 0x507769aa
+0,        740,        740,        1,   188356, 0xddfb3069
+0,        750,        750,        1,   188356, 0x7296f749
+0,        760,        760,        1,   188356, 0x0555ca32
+0,        770,        770,        1,   188356, 0x4554c683
+0,        780,        780,        1,   188356, 0x2398c10f
+0,        790,        790,        1,   188356, 0x1c5ccfa0
+0,        800,        800,        1,   188356, 0xa580f3c8
+0,        810,        810,        1,   188356, 0x4fadea78
+0,        820,        820,        1,   188356, 0x4a57db38
+0,        830,        830,        1,   188356, 0x9e98df6d
+0,        840,        840,        1,   188356, 0xfeb3dec9
+0,        850,        850,        1,   188356, 0xbf16ef7a
+0,        860,        860,        1,   188356, 0xdc23fc48
+0,        870,        870,        1,   188356, 0x3bf2e401
+0,        880,        880,        1,   188356, 0xc832bcf4
+0,        890,        890,        1,   188356, 0x977db44f
+0,        900,        900,        1,   188356, 0x18d39d96
+0,        910,        910,        1,   188356, 0x9adf60d8
+0,        920,        920,        1,   188356, 0x567b667a
+0,        930,        930,        1,   188356, 0xd4a45e8e
+0,        940,        940,        1,   188356, 0x94a24cc7
+0,        950,        950,        1,   188356, 0x086f0a53
+0,        960,        960,        1,   188356, 0xcbf3ebcb
+0,        970,        970,        1,   188356, 0x1a40a7b9
+0,        980,        980,        1,   188356, 0xe16d8964
+0,        990,        990,        1,   188356, 0x3edd7dfa
+0,       1000,       1000,        1,   188356, 0xba417fa5
+0,       1010,       1010,        1,   188356, 0x734a7611
+0,       1020,       1020,        1,   188356, 0xfa1e7b1e
+0,       1030,       1030,        1,   188356, 0x1af23355
+0,       1040,       1040,        1,   188356, 0x28d41390
+0,       1050,       1050,        1,   188356, 0x2838c58d
+0,       1060,       1060,        1,   188356, 0x4e2ba2a8
+0,       1070,       1070,        1,   188356, 0xcedc99ae
+0,       1080,       1080,        1,   188356, 0xb06ba12d
+0,       1090,       1090,        1,   188356, 0x38c997b6
+0,       1100,       1100,        1,   188356, 0x12dba0dc
+0,       1110,       1110,        1,   188356, 0x5f86496a
+0,       1120,       1120,        1,   188356, 0x0b74216d
+0,       1130,       1130,        1,   188356, 0xdbddbada
+0,       1140,       1140,        1,   188356, 0x7d168af2
+0,       1150,       1150,        1,   188356, 0x22d4462b
+0,       1160,       1160,        1,   188356, 0xc248265d
+0,       1170,       1170,        1,   188356, 0x37a41b0d
+0,       1180,       1180,        1,   188356, 0x9ebd24f1
+0,       1190,       1190,        1,   188356, 0xf21f1633
+0,       1200,       1200,        1,   188356, 0x1db62004
+0,       1210,       1210,        1,   188356, 0xcc241ac1
+0,       1220,       1220,        1,   188356, 0x224d2637
+0,       1230,       1230,        1,   188356, 0x1bd8390c
+0,       1240,       1240,        1,   188356, 0xd8e64966
+0,       1250,       1250,        1,   188356, 0x96e66287
+0,       1260,       1260,        1,   188356, 0xa83c9a32
+0,       1270,       1270,        1,   188356, 0x3a5faeba
+0,       1280,       1280,        1,   188356, 0x8200cd87
+0,       1290,       1290,        1,   188356, 0x6326e591
+0,       1300,       1300,        1,   188356, 0xb5d70993
+0,       1310,       1310,        1,   188356, 0x954d5da2
+0,       1320,       1320,        1,   188356, 0x38b1788b
+0,       1330,       1330,        1,   188356, 0x4aafa131
+0,       1340,       1340,        1,   188356, 0xaff2be78
+0,       1350,       1350,        1,   188356, 0x9bd7eb69
+0,       1360,       1360,        1,   188356, 0x0d2b17c9
+0,       1370,       1370,        1,   188356, 0xf5d8a764
+0,       1380,       1380,        1,   188356, 0xa302dfb2
+0,       1390,       1390,        1,   188356, 0xe8a32ac1
+0,       1400,       1400,        1,   188356, 0x50a8470d
+0,       1410,       1410,        1,   188356, 0x52826061
+0,       1420,       1420,        1,   188356, 0x26e88798
+0,       1430,       1430,        1,   188356, 0x1448acb8
+0,       1440,       1440,        1,   188356, 0xfb380972
+0,       1450,       1450,        1,   188356, 0x184976e8
+0,       1460,       1460,        1,   188356, 0xa349a871
+0,       1470,       1470,        1,   188356, 0x617ed8b1
+0,       1480,       1480,        1,   188356, 0xb6bc1425
+0,       1490,       1490,        1,   188356, 0xafe74efd
+0,       1500,       1500,        1,   188356, 0x0b8b61e5
+0,       1510,       1510,        1,   188356, 0xc6ad67a7
+0,       1520,       1520,        1,   188356, 0x4da186fe
+0,       1530,       1530,        1,   188356, 0xe08f9975
+0,       1540,       1540,        1,   188356, 0xa43f8ba4
+0,       1550,       1550,        1,   188356, 0xcad4b6b5
+0,       1560,       1560,        1,   188356, 0x7e70d51e
+0,       1570,       1570,        1,   188356, 0x429b0b5b
+0,       1580,       1580,        1,   188356, 0xea92350d
+0,       1590,       1590,        1,   188356, 0x9a7440f8
+0,       1600,       1600,        1,   188356, 0x63a2be6e
+0,       1610,       1610,        1,   188356, 0x59b64b50
+0,       1620,       1620,        1,   188356, 0x63c4a10e
+0,       1630,       1630,        1,   188356, 0x6146e5e0
+0,       1640,       1640,        1,   188356, 0x603b2ae5
+0,       1650,       1650,        1,   188356, 0x818bc774
+0,       1660,       1660,        1,   188356, 0xa5ce278f
+0,       1670,       1670,        1,   188356, 0x4d85684d
+0,       1680,       1680,        1,   188356, 0xbbda9cad
+0,       1690,       1690,        1,   188356, 0xfee2e78e
+0,       1700,       1700,        1,   188356, 0x681d2635
+0,       1710,       1710,        1,   188356, 0x05354903
+0,       1720,       1720,        1,   188356, 0x8eecac99
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/gif-demux b/mythtv/external/FFmpeg/tests/ref/fate/gif-demux
new file mode 100644
index 00000000000..547b9ce3d6e
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/gif-demux
@@ -0,0 +1,37 @@
+#tb 0: 1/100
+0,          0,          0,        5,    74699, 0xef7e91c8
+0,          5,          5,        2,    10079, 0x2892d9e2, F=0x0
+0,          7,          7,        2,    12369, 0xd7d73286, F=0x0
+0,          9,          9,        2,     8868, 0x4bb59b6d, F=0x0
+0,         11,         11,        2,     8249, 0x23d5d174, F=0x0
+0,         13,         13,        2,     8381, 0x10acf0cd, F=0x0
+0,         15,         15,        2,     8579, 0xdfe108b2, F=0x0
+0,         17,         17,        2,     8200, 0x46ec6c55, F=0x0
+0,         19,         19,        2,     7261, 0xaf328999, F=0x0
+0,         21,         21,        4,     7047, 0xab3d2bd0, F=0x0
+0,         25,         25,        2,     6486, 0xa1629769, F=0x0
+0,         27,         27,        2,     7278, 0x4c55b7ce, F=0x0
+0,         29,         29,        2,     7761, 0x54368171, F=0x0
+0,         31,         31,        2,     7794, 0xbde2dbcd, F=0x0
+0,         33,         33,        2,     7935, 0xe6202c65, F=0x0
+0,         35,         35,        2,     8499, 0x1d5ceb7e, F=0x0
+0,         37,         37,        2,     8841, 0xc962be37, F=0x0
+0,         39,         39,        2,     9281, 0x7ec29c31, F=0x0
+0,         41,         41,        5,     9606, 0x3de06d48, F=0x0
+0,         46,         46,        2,     6319, 0xb3e94478, F=0x0
+0,         48,         48,        2,     5521, 0xc8157edc, F=0x0
+0,         50,         50,        2,     5052, 0x23e8ea7c, F=0x0
+0,         52,         52,        2,     4651, 0xa73f25c9, F=0x0
+0,         54,         54,        2,     4477, 0x1ddcc2c3, F=0x0
+0,         56,         56,        2,     4736, 0x6ead0d5e, F=0x0
+0,         58,         58,        2,     4609, 0x8bc7faa3, F=0x0
+0,         60,         60,        2,     4474, 0x3926975e, F=0x0
+0,         62,         62,        4,     4381, 0x28c392d5, F=0x0
+0,         66,         66,        2,     4443, 0x9c33b143, F=0x0
+0,         68,         68,        2,     4540, 0xb1d1c8b9, F=0x0
+0,         70,         70,        2,     4530, 0x773bc617, F=0x0
+0,         72,         72,        2,     4558, 0xa1e8cdf3, F=0x0
+0,         74,         74,        2,     4633, 0x8f64fda7, F=0x0
+0,         76,         76,        2,     4700, 0x45f40805, F=0x0
+0,         78,         78,        2,     5117, 0x4eb4c5fb, F=0x0
+0,         80,         80,        2,     5370, 0xb10c6910, F=0x0
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/gif-disposal-restore b/mythtv/external/FFmpeg/tests/ref/fate/gif-disposal-restore
new file mode 100644
index 00000000000..0ce4112f2be
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/gif-disposal-restore
@@ -0,0 +1,4 @@
+#tb 0: 1/100
+0,          0,          0,        1,   112320, 0xb8afe429
+0,         10,         10,        1,   112320, 0xae588a4b
+0,        310,        310,        1,   112320, 0xccdd27b7
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/gif-gray b/mythtv/external/FFmpeg/tests/ref/fate/gif-gray
new file mode 100644
index 00000000000..5a133bd0300
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/gif-gray
@@ -0,0 +1,37 @@
+#tb 0: 1/100
+0,          0,          0,        1,   691200, 0xef6c0f3d
+0,          5,          5,        1,   691200, 0xc18b32de
+0,          7,          7,        1,   691200, 0x2395a3d7
+0,          9,          9,        1,   691200, 0x81dc3cf2
+0,         11,         11,        1,   691200, 0xabe2390e
+0,         13,         13,        1,   691200, 0xb2955c2a
+0,         15,         15,        1,   691200, 0x868d9ca2
+0,         17,         17,        1,   691200, 0x3016c2b6
+0,         19,         19,        1,   691200, 0x4501cffa
+0,         21,         21,        1,   691200, 0x8661d79e
+0,         25,         25,        1,   691200, 0xbc96d02e
+0,         27,         27,        1,   691200, 0x5f90bf5e
+0,         29,         29,        1,   691200, 0xf18da09a
+0,         31,         31,        1,   691200, 0x540467ce
+0,         33,         33,        1,   691200, 0x60d24012
+0,         35,         35,        1,   691200, 0x24323d36
+0,         37,         37,        1,   691200, 0x9e07c84b
+0,         39,         39,        1,   691200, 0xc18b32de
+0,         41,         41,        1,   691200, 0xef6c0f3d
+0,         46,         46,        1,   691200, 0xc9461045
+0,         48,         48,        1,   691200, 0x23ed4b99
+0,         50,         50,        1,   691200, 0x7e351d69
+0,         52,         52,        1,   691200, 0x0513e0aa
+0,         54,         54,        1,   691200, 0x28a4b6f2
+0,         56,         56,        1,   691200, 0xce10a94e
+0,         58,         58,        1,   691200, 0x63929d4e
+0,         60,         60,        1,   691200, 0xd26c9bb6
+0,         62,         62,        1,   691200, 0xb2a29842
+0,         66,         66,        1,   691200, 0x9fd69a16
+0,         68,         68,        1,   691200, 0x10f99e46
+0,         70,         70,        1,   691200, 0xea95a9fa
+0,         72,         72,        1,   691200, 0x97dbb9d6
+0,         74,         74,        1,   691200, 0xf4e9e2d6
+0,         76,         76,        1,   691200, 0x46b1230d
+0,         78,         78,        1,   691200, 0xb4a54ccd
+0,         80,         80,        1,   691200, 0x40cc103d
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/hmac b/mythtv/external/FFmpeg/tests/ref/fate/hmac
new file mode 100644
index 00000000000..7d2a437c69e
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/hmac
@@ -0,0 +1,6 @@
+9294727a3638bb1c13f48ef8158bfc9d
+750c783e6ab0b503eaa86e310a5db738
+56be34521d144c88dbb8c733f0e8b3f6
+467cb2560355d7fa3ab2d6b939e6e47c
+5a6ffd741d3e23b12f78b1baee9e609a
+8b4b9d11c9e186c58f2a53b08ddfa436
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/idroq-video-encode b/mythtv/external/FFmpeg/tests/ref/fate/idroq-video-encode
index 24f3f0d8238..9d25b13a858 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/idroq-video-encode
+++ b/mythtv/external/FFmpeg/tests/ref/fate/idroq-video-encode
@@ -1 +1 @@
-2be5ade557acab688d58f1c5ec0773f4
+50fa863f7820bb22ddeb74d5adf5f0bc
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/lossless-tta-encrypted b/mythtv/external/FFmpeg/tests/ref/fate/lossless-tta-encrypted
new file mode 100644
index 00000000000..39aec95e88a
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/lossless-tta-encrypted
@@ -0,0 +1 @@
+CRC=0x4563745f
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/mpeg2-field-enc b/mythtv/external/FFmpeg/tests/ref/fate/mpeg2-field-enc
index 903adb56b84..bf8a01a7cc2 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/mpeg2-field-enc
+++ b/mythtv/external/FFmpeg/tests/ref/fate/mpeg2-field-enc
@@ -29,4 +29,3 @@
 0,         36,         36,        1,   622080, 0xa45e1d95
 0,         37,         37,        1,   622080, 0x6cc61d6c
 0,         38,         38,        1,   622080, 0x6983b417
-0,         39,         39,        1,   622080, 0x982363c0
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/noproxy b/mythtv/external/FFmpeg/tests/ref/fate/noproxy
new file mode 100644
index 00000000000..7707609d0f1
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/noproxy
@@ -0,0 +1,9 @@
+The pattern "(null)" does not match the hostname domain.com
+The pattern "example.com domain.com" matches the hostname domain.com
+The pattern "example.com other.com" does not match the hostname domain.com
+The pattern "example.com,domain.com" matches the hostname domain.com
+The pattern "example.com,domain.com" does not match the hostname otherdomain.com
+The pattern "example.com, *.domain.com" matches the hostname sub.domain.com
+The pattern "example.com, *.domain.com" matches the hostname domain.com
+The pattern "example.com, .domain.com" matches the hostname domain.com
+The pattern "*" matches the hostname domain.com
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/nuv-rtjpeg-fh b/mythtv/external/FFmpeg/tests/ref/fate/nuv-rtjpeg-fh
index beb6ccde062..b2e04cb0153 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/nuv-rtjpeg-fh
+++ b/mythtv/external/FFmpeg/tests/ref/fate/nuv-rtjpeg-fh
@@ -1,11 +1,11 @@
 #tb 0: 1/50
-0,         80,         80,        1,   221184, 0xf48c94f6
-0,         82,         82,        1,   221184, 0x89b625b2
-0,         83,         83,        1,   221184, 0x37e04714
-0,         84,         84,        1,   221184, 0x4f4c5224
-0,         85,         85,        1,   221184, 0x9193c9f1
-0,         86,         86,        1,   221184, 0x5d1a6197
-0,         87,         87,        1,   221184, 0x40cd51e7
+0,         80,         80,        1,   221184, 0xdaf54f83
+0,         82,         82,        1,   221184, 0xeea3e3b4
+0,         83,         83,        1,   221184, 0x5f1a8525
+0,         84,         84,        1,   221184, 0x950bb170
+0,         85,         85,        1,   221184, 0x6262e94c
+0,         86,         86,        1,   221184, 0x28752197
+0,         87,         87,        1,   221184, 0x0c2811e7
 0,         88,         88,        1,   221184, 0xb2c1a729
 0,         90,         90,        1,   221184, 0x998d6144
 0,         91,         91,        1,   221184, 0xf5d52311
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/parseutils b/mythtv/external/FFmpeg/tests/ref/fate/parseutils
index 36756a8ac8f..5fa3bf4e1c3 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/parseutils
+++ b/mythtv/external/FFmpeg/tests/ref/fate/parseutils
@@ -79,4 +79,4 @@ now                      ->     1331972053.000000 = 2012-03-17T08:14:13Z
 -1:23:45.67              ->           -5025670000
 42.1729                  ->             +42172900
 -1729.42                 ->           -1729420000
-12:34                    -> error
+12:34                    ->            +754000000
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/siff-demux b/mythtv/external/FFmpeg/tests/ref/fate/siff-demux
new file mode 100644
index 00000000000..692e5047553
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/siff-demux
@@ -0,0 +1,112 @@
+#tb 0: 1/12
+#tb 1: 1/22050
+0,          0,          0,        1,    15152, 0x14fc0f1f
+1,          0,          0,    22050,    22050, 0xa7d60d27
+0,          1,          1,        1,    15344, 0x31614bd7
+0,          2,          2,        1,    15163, 0x88c46248
+0,          3,          3,        1,    15152, 0x43c9c0e6
+0,          4,          4,        1,    15341, 0x813f6f01
+0,          5,          5,        1,    15152, 0x7598d01c
+0,          6,          6,        1,    15152, 0x40b5cdb1
+0,          7,          7,        1,    15347, 0xe061c843
+0,          8,          8,        1,    15159, 0x2e3c2242
+0,          9,          9,        1,    15151, 0x7201abc5
+0,         10,         10,        1,    15346, 0xeb5a349e
+0,         11,         11,        1,    15154, 0xda9907c9
+0,         12,         12,        1,    15159, 0x8d4d63b0
+1,      22050,      22050,    22050,    22050, 0xeb11185c
+0,         13,         13,        1,    15337, 0xd988436d
+0,         14,         14,        1,    15162, 0x0b495da7
+0,         15,         15,        1,    15164, 0xd8837439
+0,         16,         16,        1,    15339, 0x7ad372cc
+0,         17,         17,        1,    15161, 0xc45d4590
+0,         18,         18,        1,    15159, 0x5bdd9801
+0,         19,         19,        1,    15335, 0x8e17c83e
+0,         20,         20,        1,    15160, 0x5cdbdc04
+0,         21,         21,        1,    15157, 0xf480a643
+0,         22,         22,        1,    15346, 0x0c61b206
+0,         23,         23,        1,    15160, 0x05d9acfd
+0,         24,         24,        1,    15158, 0xebdc3ac4
+1,      44100,      44100,    22050,    22050, 0xd6dc0e17
+0,         25,         25,        1,    15334, 0xb51fd1b9
+0,         26,         26,        1,    15152, 0x81f74e5c
+0,         27,         27,        1,    15161, 0xafeca32c
+0,         28,         28,        1,    15347, 0x8f5e5874
+0,         29,         29,        1,    15157, 0xdeff353c
+0,         30,         30,        1,    15160, 0x93a19aa0
+0,         31,         31,        1,    15347, 0x94224071
+0,         32,         32,        1,    15153, 0x9982aff5
+0,         33,         33,        1,    15164, 0x044bcf2b
+0,         34,         34,        1,    15347, 0x40aca6e9
+0,         35,         35,        1,    15160, 0xf820e2c7
+0,         36,         36,        1,    15154, 0x457832b5
+1,      66150,      66150,    22050,    22050, 0x020412c4
+0,         37,         37,        1,    15334, 0xbb1704f0
+0,         38,         38,        1,    15156, 0xc0672ed1
+0,         39,         39,        1,    15159, 0x9a82c7c1
+0,         40,         40,        1,    15338, 0x03857aae
+0,         41,         41,        1,    15158, 0xe6177548
+0,         42,         42,        1,    15159, 0xf8ecafc4
+0,         43,         43,        1,    15345, 0x0a10882e
+0,         44,         44,        1,    15161, 0xec4339fb
+0,         45,         45,        1,    15157, 0x071935a2
+0,         46,         46,        1,    15340, 0x68aad418
+0,         47,         47,        1,    15151, 0x891bc3fe
+0,         48,         48,        1,    15153, 0xf522e54c
+1,      88200,      88200,    22050,    22050, 0x5d9606ae
+0,         49,         49,        1,    15346, 0x5a018842
+0,         50,         50,        1,    15164, 0x6842ac50
+0,         51,         51,        1,    15156, 0x32369159
+0,         52,         52,        1,    15347, 0xf5be31aa
+0,         53,         53,        1,    15157, 0xd2da28bd
+0,         54,         54,        1,    15152, 0x389feda6
+0,         55,         55,        1,    15345, 0x69187603
+0,         56,         56,        1,    15154, 0x5dc60365
+0,         57,         57,        1,    15159, 0x8c811193
+0,         58,         58,        1,    15344, 0x3db4bf13
+0,         59,         59,        1,    15156, 0xf729ebe1
+0,         60,         60,        1,    15162, 0xf10a4ce5
+1,     110250,     110250,    22050,    22050, 0x08171bca
+0,         61,         61,        1,    15345, 0x749b0604
+0,         62,         62,        1,    15160, 0xfe3bbbce
+0,         63,         63,        1,    15160, 0x6dcc4b85
+0,         64,         64,        1,    15337, 0xab87dd97
+0,         65,         65,        1,    15163, 0x1ce60db8
+0,         66,         66,        1,    15164, 0xfc4a2002
+0,         67,         67,        1,    15345, 0x9108e072
+0,         68,         68,        1,    15153, 0x83fc9055
+0,         69,         69,        1,    15155, 0xa1101e1a
+0,         70,         70,        1,    15343, 0x6418f0e9
+0,         71,         71,        1,    15157, 0x8c743049
+0,         72,         72,        1,    15153, 0x9c0e33eb
+1,     132300,     132300,    22050,    22050, 0xd43b0cf9
+0,         73,         73,        1,    15337, 0x64bae0b6
+0,         74,         74,        1,    15162, 0x5f6b91d5
+0,         75,         75,        1,    15162, 0x44e5dd3d
+0,         76,         76,        1,    15342, 0x968dc44c
+0,         77,         77,        1,    15158, 0x0e706c4d
+0,         78,         78,        1,    15153, 0xa7d2199a
+0,         79,         79,        1,    15345, 0x834d0f2e
+0,         80,         80,        1,    15163, 0x3d5d38c3
+0,         81,         81,        1,    15151, 0xf7d49515
+0,         82,         82,        1,    15337, 0x5f362f2a
+0,         83,         83,        1,    15162, 0xea87d814
+0,         84,         84,        1,    15164, 0xeb0a2662
+1,     154350,     154350,    22050,    22050, 0x486d1bc2
+0,         85,         85,        1,    15340, 0x772109e6
+0,         86,         86,        1,    15156, 0x9459cda5
+0,         87,         87,        1,    15152, 0x4f174e2d
+0,         88,         88,        1,    15343, 0x10d42a59
+0,         89,         89,        1,    15162, 0xd65ec2ec
+0,         90,         90,        1,    15156, 0x1e382319
+0,         91,         91,        1,    15335, 0xec904c2a
+0,         92,         92,        1,    15161, 0x56d49e44
+0,         93,         93,        1,    15154, 0x51d02cd0
+0,         94,         94,        1,    15340, 0xec3e14ee
+0,         95,         95,        1,    15160, 0xe43b5305
+0,         96,         96,        1,    15156, 0x8f2876a5
+1,     176400,     176400,    22050,    22050, 0x5c5508d3
+0,         97,         97,        1,    15340, 0xb26a9059
+0,         98,         98,        1,    15156, 0xf9570ec0
+0,         99,         99,        1,    15151, 0x862ffa1f
+1,     198450,     198450,     1984,     1984, 0x9cb4dfb7
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/srtp b/mythtv/external/FFmpeg/tests/ref/fate/srtp
new file mode 100644
index 00000000000..687a59f78b8
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/srtp
@@ -0,0 +1,12 @@
+80e0123412345678123456780102030405
+Decrypted content matches input
+Decrypted content matches input
+Decrypted content matches input
+81c90007123456788765432100000000000012340000069ec73069ba000001fd
+Decrypted content matches input
+Decrypted content matches input
+Decrypted content matches input
+80e0123412345678123456780102030405
+81c90007123456788765432100000000000012340000069ec73069ba000001fd
+80e0123412345678123456780102030405
+81c90007123456788765432100000000000012340000069ec73069ba000001fd
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/sub-charenc b/mythtv/external/FFmpeg/tests/ref/fate/sub-charenc
new file mode 100644
index 00000000000..ef727546fd1
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/sub-charenc
@@ -0,0 +1 @@
+9615088d613931b50fd5016c7535b99a
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/sub-microdvd-remux b/mythtv/external/FFmpeg/tests/ref/fate/sub-microdvd-remux
new file mode 100644
index 00000000000..24b5d3dc188
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/sub-microdvd-remux
@@ -0,0 +1 @@
+669e51e357f8a8bd060f2499149c2ded
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/vp3-coeff-level64 b/mythtv/external/FFmpeg/tests/ref/fate/theora-coeff-level64
similarity index 100%
rename from mythtv/external/FFmpeg/tests/ref/fate/vp3-coeff-level64
rename to mythtv/external/FFmpeg/tests/ref/fate/theora-coeff-level64
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/siff b/mythtv/external/FFmpeg/tests/ref/fate/vb
similarity index 91%
rename from mythtv/external/FFmpeg/tests/ref/fate/siff
rename to mythtv/external/FFmpeg/tests/ref/fate/vb
index 8cc6d7f4458..336d42657b2 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/siff
+++ b/mythtv/external/FFmpeg/tests/ref/fate/vb
@@ -1,7 +1,5 @@
 #tb 0: 1/12
-#tb 1: 1/22050
 0,          0,          0,        1,   230400, 0x3bd1d731
-1,          0,          0,    22050,    44100, 0xd0a49e09
 0,          1,          1,        1,   230400, 0x9d0774c3
 0,          2,          2,        1,   230400, 0xa0faafe2
 0,          3,          3,        1,   230400, 0x38325309
@@ -14,7 +12,6 @@
 0,         10,         10,        1,   230400, 0xf52b8db4
 0,         11,         11,        1,   230400, 0x2b70c1dc
 0,         12,         12,        1,   230400, 0x8157a6e9
-1,      22050,      22050,    22050,    44100, 0xf151af4d
 0,         13,         13,        1,   230400, 0xd4a3c357
 0,         14,         14,        1,   230400, 0x703861bb
 0,         15,         15,        1,   230400, 0xa13cf75e
@@ -27,7 +24,6 @@
 0,         22,         22,        1,   230400, 0x0f5c8a0d
 0,         23,         23,        1,   230400, 0x3475df44
 0,         24,         24,        1,   230400, 0x65354e06
-1,      44100,      44100,    22050,    44100, 0xecd3cd08
 0,         25,         25,        1,   230400, 0xb9a01978
 0,         26,         26,        1,   230400, 0x15207ee1
 0,         27,         27,        1,   230400, 0x3b214f0b
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/vc1_sa10143 b/mythtv/external/FFmpeg/tests/ref/fate/vc1_sa10143
index 0d2e6979895..6a5137f7121 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/vc1_sa10143
+++ b/mythtv/external/FFmpeg/tests/ref/fate/vc1_sa10143
@@ -1,31 +1,31 @@
 #tb 0: 1/25
 0,          0,          0,        1,   518400, 0x89407f55
-0,          2,          2,        1,   518400, 0x1480849d
+0,          2,          2,        1,   518400, 0x8611849c
 0,          3,          3,        1,   518400, 0x0e69ff59
-0,          4,          4,        1,   518400, 0x00d6db06
+0,          4,          4,        1,   518400, 0xf31adb03
 0,          5,          5,        1,   518400, 0x1a5b6a69
-0,          6,          6,        1,   518400, 0xc1a1232e
+0,          6,          6,        1,   518400, 0x6ae6232e
 0,          7,          7,        1,   518400, 0x9a4e3c54
-0,          8,          8,        1,   518400, 0x04122b44
+0,          8,          8,        1,   518400, 0xe5852b45
 0,          9,          9,        1,   518400, 0x0fcfeebc
-0,         10,         10,        1,   518400, 0xc7882dc1
+0,         10,         10,        1,   518400, 0x06e22dc3
 0,         11,         11,        1,   518400, 0x9d79df09
-0,         12,         12,        1,   518400, 0xff6b716f
+0,         12,         12,        1,   518400, 0xcb2c716f
 0,         13,         13,        1,   518400, 0x638a8746
-0,         14,         14,        1,   518400, 0x07572efb
+0,         14,         14,        1,   518400, 0xf7032efd
 0,         15,         15,        1,   518400, 0x306f6cef
-0,         16,         16,        1,   518400, 0xd7602518
+0,         16,         16,        1,   518400, 0xe83d2518
 0,         17,         17,        1,   518400, 0x49ab5bf5
-0,         18,         18,        1,   518400, 0x3c736b6c
+0,         18,         18,        1,   518400, 0x6b336b6f
 0,         19,         19,        1,   518400, 0x95ae00c9
-0,         20,         20,        1,   518400, 0x7b9ab64e
+0,         20,         20,        1,   518400, 0x68ddb64f
 0,         21,         21,        1,   518400, 0x5205ea68
-0,         22,         22,        1,   518400, 0xb486e618
+0,         22,         22,        1,   518400, 0xb088e617
 0,         23,         23,        1,   518400, 0xa3217616
-0,         24,         24,        1,   518400, 0xc66bbc56
+0,         24,         24,        1,   518400, 0x1723bc53
 0,         25,         25,        1,   518400, 0xf024872a
-0,         26,         26,        1,   518400, 0x97d2a8ba
+0,         26,         26,        1,   518400, 0x2e81a8bb
 0,         27,         27,        1,   518400, 0xa3a2418e
-0,         28,         28,        1,   518400, 0x08460005
+0,         28,         28,        1,   518400, 0xb7beffed
 0,         29,         29,        1,   518400, 0x50fb6c94
 0,         30,         30,        1,   518400, 0x5584bb40
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/vp8-alpha b/mythtv/external/FFmpeg/tests/ref/fate/vp8-alpha
new file mode 100644
index 00000000000..f857a875046
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/fate/vp8-alpha
@@ -0,0 +1,121 @@
+#tb 0: 1/1000
+0,          1,          1,        0,     2108, 0x59b92a34, S=1,     1900, 0x8fb3adc5
+0,         33,         33,        0,      142, 0x2f2a3fed, F=0x0, S=1,      160, 0xa13346af
+0,         66,         66,        0,      157, 0x17804767, F=0x0, S=1,      209, 0x64115f15
+0,        100,        100,        0,      206, 0x537262ca, F=0x0, S=1,      317, 0x44a09dd0
+0,        133,        133,        0,      259, 0x73ff74b6, F=0x0, S=1,      384, 0x2ee2c588
+0,        166,        166,        0,      320, 0x0fcf8ce4, F=0x0, S=1,      415, 0xff68c953
+0,        200,        200,        0,      377, 0x8fffb5f5, F=0x0, S=1,      475, 0x4166f3eb
+0,        233,        233,        0,      407, 0xe476c19e, F=0x0, S=1,      193, 0x3ff75489
+0,        266,        266,        0,      539, 0x90202334, F=0x0, S=1,      681, 0x776656b0
+0,        300,        300,        0,      560, 0xc6e2168d, F=0x0, S=1,      585, 0xddc81b8a
+0,        333,        333,        0,      597, 0x201a32a7, F=0x0, S=1,      574, 0x8baa1d65
+0,        366,        366,        0,      770, 0xab2b8891, F=0x0, S=1,      666, 0xcd8e51eb
+0,        400,        400,        0,      708, 0xc2386711, F=0x0, S=1,      706, 0x046b6444
+0,        433,        433,        0,      905, 0x7211c52d, F=0x0, S=1,      814, 0x5e288def
+0,        466,        466,        0,      770, 0xda4f8574, F=0x0, S=1,      829, 0xa0e8a949
+0,        500,        500,        0,      955, 0xf9a1d77a, F=0x0, S=1,      857, 0x9b63b955
+0,        533,        533,        0,      970, 0xff4de39a, F=0x0, S=1,      153, 0x3b00416c
+0,        566,        566,        0,      978, 0x12bcf81f, F=0x0, S=1,     1181, 0xce175555
+0,        600,        600,        0,     1233, 0x2903744a, F=0x0, S=1,      860, 0x737eb566
+0,        633,        633,        0,     1118, 0x7f274f50, F=0x0, S=1,      933, 0xb669c6b6
+0,        666,        666,        0,      941, 0x6bffd4b1, F=0x0, S=1,     1058, 0x07581cee
+0,        700,        700,        0,     1598, 0xc007219f, F=0x0, S=1,      939, 0x2c0bdc45
+0,        733,        733,        0,     1218, 0x25d962b6, F=0x0, S=1,     1090, 0x96482341
+0,        766,        766,        0,     1200, 0x86b85be3, F=0x0, S=1,      189, 0x3f085309
+0,        800,        800,        0,     1329, 0x298a848a, F=0x0, S=1,     1426, 0x6ea3df12
+0,        833,        833,        0,     1500, 0xe437edec, F=0x0, S=1,     1244, 0x32836b8d
+0,        866,        866,        0,     1288, 0xc4447dd5, F=0x0, S=1,     1289, 0x06a57b0f
+0,        900,        900,        0,     1281, 0xb5bf7e9f, F=0x0, S=1,     1227, 0xd96d5697
+0,        933,        933,        0,     1372, 0x09be9014, F=0x0, S=1,     1556, 0x2630fbff
+0,        966,        966,        0,     1238, 0x42ce6316, F=0x0, S=1,     1287, 0x1d3084f6
+0,       1000,       1000,        0,     1655, 0xb94b45c2, F=0x0, S=1,     1494, 0x34dbd1a4
+0,       1033,       1033,        0,     1164, 0xf6b93ad0, F=0x0, S=1,     1337, 0xba6d9673
+0,       1066,       1066,        0,     1084, 0x58c50fb5, F=0x0, S=1,     1384, 0x3fabb82b
+0,       1100,       1100,        0,     1151, 0x0b3f3359, F=0x0, S=1,     1353, 0x08e2a1d7
+0,       1133,       1133,        0,     1277, 0xa3ae77e1, F=0x0, S=1,     1409, 0xf65cb9f7
+0,       1166,       1166,        0,      782, 0xdcf671ff, F=0x0, S=1,     1408, 0x01e2ac53
+0,       1200,       1200,        0,      926, 0xe913c286, F=0x0, S=1,     1320, 0x32e38e42
+0,       1233,       1233,        0,      970, 0x3d86e5ae, F=0x0, S=1,     1608, 0x40b52618
+0,       1266,       1266,        0,     1353, 0xe4f197b2, F=0x0, S=1,     1272, 0xf1d272a5
+0,       1300,       1300,        0,      685, 0x629b4ce4, F=0x0, S=1,     1257, 0x14845de9
+0,       1333,       1333,        0,      743, 0x6f1172a3, F=0x0, S=1,     1260, 0xa6c66fda
+0,       1366,       1366,        0,      789, 0x94fc84cd, F=0x0, S=1,     1009, 0x7daaf2b0
+0,       1400,       1400,        0,     1460, 0x668adb82, F=0x0, S=1,      944, 0x44b6ccf5
+0,       1433,       1433,        0,      766, 0x49c884ef, F=0x0, S=1,      996, 0x8646e6dd
+0,       1466,       1466,        0,     1037, 0x24831498, F=0x0, S=1,      983, 0x14a9e7a6
+0,       1500,       1500,        0,      943, 0x1f53d180, F=0x0, S=1,     1107, 0x02f72acb
+0,       1533,       1533,        0,     1152, 0xbf6a35ae, F=0x0, S=1,     1026, 0xd57afda0
+0,       1566,       1566,        0,      730, 0x42806abf, F=0x0, S=1,     1029, 0xfb0402d5
+0,       1600,       1600,        0,      975, 0xa5ffec57, F=0x0, S=1,     1081, 0xe2890cea
+0,       1633,       1633,        0,      970, 0xbe8ee224, F=0x0, S=1,     1151, 0x7b0d3b20
+0,       1666,       1666,        0,     1012, 0x20c6f0d8, F=0x0, S=1,      979, 0xc25cd69c
+0,       1700,       1700,        0,      874, 0x1a2fb4da, F=0x0, S=1,      943, 0xdb2dc9f8
+0,       1733,       1733,        0,      869, 0xab0caf3d, F=0x0, S=1,      934, 0x48b9bfcc
+0,       1766,       1766,        0,      863, 0xd8caa2e5, F=0x0, S=1,      874, 0x0b34b026
+0,       1800,       1800,        0,     1246, 0x47866cdc, F=0x0, S=1,      818, 0x0c908eeb
+0,       1833,       1833,        0,      742, 0xa6296ac1, F=0x0, S=1,      921, 0x97b6b053
+0,       1866,       1866,        0,      828, 0x0b568d7a, F=0x0, S=1,      969, 0x3314dbfa
+0,       1900,       1900,        0,      825, 0x6d329394, F=0x0, S=1,      982, 0x5f66e68c
+0,       1933,       1933,        0,      836, 0x8ace8dfb, F=0x0, S=1,      929, 0x9ffdc2fd
+0,       1966,       1966,        0,     1774, 0xd4686726, F=0x0, S=1,      909, 0x11a9c07a
+0,       2000,       2000,        0,     1803, 0x08c879ce, F=0x0, S=1,     1525, 0x1e11f02f
+0,       2033,       2033,        0,      518, 0x7c32fc72, F=0x0, S=1,      785, 0xfc1f792a
+0,       2066,       2066,        0,      790, 0x3dac8aa0, F=0x0, S=1,      876, 0x0918c88d
+0,       2100,       2100,        0,      927, 0x4feccb24, F=0x0, S=1,     1059, 0xbcaa05c7
+0,       2133,       2133,        0,      835, 0x29d39266, F=0x0, S=1,      980, 0x4913e409
+0,       2166,       2166,        0,      951, 0xc1dddd12, F=0x0, S=1,     1041, 0x0541047e
+0,       2200,       2200,        0,      876, 0x2f6eb89d, F=0x0, S=1,      949, 0x2d56c53b
+0,       2233,       2233,        0,      959, 0xf0dedabd, F=0x0, S=1,     1022, 0x8d33f5fa
+0,       2266,       2266,        0,      860, 0x9274ab39, F=0x0, S=1,     1061, 0x289c0132
+0,       2300,       2300,        0,      863, 0x7058ba30, F=0x0, S=1,      940, 0x1f32d4a3
+0,       2333,       2333,        0,     1021, 0xcabdf84f, F=0x0, S=1,      887, 0xda8ab95e
+0,       2366,       2366,        0,      897, 0x9867c8e8, F=0x0, S=1,      840, 0xd93eaaf5
+0,       2400,       2400,        0,      897, 0x6a16b5db, F=0x0, S=1,      977, 0x7b77dc9b
+0,       2433,       2433,        0,      953, 0xe9b4cf1f, F=0x0, S=1,      921, 0x75a8ca45
+0,       2466,       2466,        0,      847, 0x0335ad37, F=0x0, S=1,     1000, 0x2691f3bd
+0,       2500,       2500,        0,      902, 0x3360b315, F=0x0, S=1,     1008, 0xd5e1deb6
+0,       2533,       2533,        0,      881, 0xf5309d59, F=0x0, S=1,     1113, 0xdbef3065
+0,       2566,       2566,        0,      974, 0x7c2de3ce, F=0x0, S=1,     1086, 0x365626bb
+0,       2600,       2600,        0,      974, 0xf42bd9f5, F=0x0, S=1,     1039, 0xa7e9060d
+0,       2633,       2633,        0,     1029, 0x7c33f4d0, F=0x0, S=1,     1041, 0xf4affa59
+0,       2666,       2666,        0,      881, 0x9021a565, F=0x0, S=1,     1039, 0xc1e00521
+0,       2700,       2700,        0,     1157, 0xe1c136f7, F=0x0, S=1,      917, 0x357ac7d3
+0,       2733,       2733,        0,      649, 0xdffb3cb7, F=0x0, S=1,      976, 0xa386e05e
+0,       2766,       2766,        0,      758, 0xb67875f3, F=0x0, S=1,     1041, 0xae4e0a63
+0,       2800,       2800,        0,     1105, 0x8ffb1a26, F=0x0, S=1,      962, 0x211ddc5e
+0,       2833,       2833,        0,      866, 0xa60eb2d9, F=0x0, S=1,      929, 0xe9e4c84b
+0,       2866,       2866,        0,      912, 0xcd34bf9b, F=0x0, S=1,      946, 0xfce9d359
+0,       2900,       2900,        0,      868, 0x5651a343, F=0x0, S=1,      809, 0x624a8ef9
+0,       2933,       2933,        0,      997, 0xfa66eaeb, F=0x0, S=1,      992, 0xc913e5e2
+0,       2966,       2966,        0,     1111, 0x3f272497, F=0x0, S=1,     1007, 0xf78ee6a7
+0,       3000,       3000,        0,      842, 0xe442999f, F=0x0, S=1,      972, 0x25a0d25c
+0,       3033,       3033,        0,     1030, 0x6f97ffad, F=0x0, S=1,      993, 0x4059fd6b
+0,       3066,       3066,        0,     1176, 0x66e64926, F=0x0, S=1,      951, 0x2762cdf1
+0,       3100,       3100,        0,      803, 0xfd1699cb, F=0x0, S=1,      959, 0x5cf9d56c
+0,       3133,       3133,        0,      972, 0x1cdff00e, F=0x0, S=1,     1023, 0xeaf20900
+0,       3166,       3166,        0,      907, 0x17f8acca, F=0x0, S=1,     1054, 0xeb010c4d
+0,       3200,       3200,        0,      915, 0x3569b545, F=0x0, S=1,      987, 0x73b2e159
+0,       3233,       3233,        0,     1021, 0x14c5076a, F=0x0, S=1,     1007, 0x6c4bf7f0
+0,       3266,       3266,        0,      837, 0xbf86b0ef, F=0x0, S=1,      963, 0xf472d31a
+0,       3300,       3300,        0,      885, 0x1caac123, F=0x0, S=1,     1052, 0x2b7bfd20
+0,       3333,       3333,        0,     1355, 0x299e8d3c, F=0x0, S=1,      858, 0x2bbca3f0
+0,       3366,       3366,        0,      784, 0xb0bd7e9d, F=0x0, S=1,      969, 0xc865dc00
+0,       3400,       3400,        0,      991, 0xbc7ddda9, F=0x0, S=1,     1028, 0x801b00a6
+0,       3433,       3433,        0,      986, 0xb356f6b1, F=0x0, S=1,     1056, 0x8b840add
+0,       3466,       3466,        0,      978, 0x94a3e87e, F=0x0, S=1,     1018, 0xe766fa52
+0,       3500,       3500,        0,      976, 0x55ddd14a, F=0x0, S=1,      992, 0x58a9ddfe
+0,       3533,       3533,        0,     1241, 0x1ec867f7, F=0x0, S=1,      966, 0xa329e84f
+0,       3566,       3566,        0,      975, 0xecf5dbb3, F=0x0, S=1,      899, 0xa7539f4d
+0,       3600,       3600,        0,     1129, 0xb7243037, F=0x0, S=1,     1057, 0xbd0d10bd
+0,       3633,       3633,        0,      913, 0xe5f1d03d, F=0x0, S=1,     1092, 0xeb9621f8
+0,       3666,       3666,        0,      943, 0x87d0ed78, F=0x0, S=1,     1057, 0x079c1054
+0,       3700,       3700,        0,      917, 0x536cc3fd, F=0x0, S=1,      946, 0xd2b9d0e2
+0,       3733,       3733,        0,      892, 0x4dffb1e2, F=0x0, S=1,      930, 0x70c9cc40
+0,       3766,       3766,        0,      957, 0x1a98e71c, F=0x0, S=1,      719, 0x6fec614a
+0,       3800,       3800,        0,      893, 0xf405b2c3, F=0x0, S=1,      821, 0x63529cab
+0,       3833,       3833,        0,      978, 0xa0a8d5f6, F=0x0, S=1,      745, 0x3c616219
+0,       3866,       3866,        0,      887, 0xfa7cb65d, F=0x0, S=1,      768, 0xb8f07885
+0,       3900,       3900,        0,      867, 0xd808ade7, F=0x0, S=1,      783, 0xf82b6b9a
+0,       3933,       3933,        0,     1068, 0x6f8b135a, F=0x0, S=1,      807, 0x52028d50
+0,       3966,       3966,        0,     2010, 0x536fe0b6, F=0x0, S=1,     1512, 0x690aeb55
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/yop b/mythtv/external/FFmpeg/tests/ref/fate/yop
index 758eacb8645..1920281a40f 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/yop
+++ b/mythtv/external/FFmpeg/tests/ref/fate/yop
@@ -1,7 +1,7 @@
 #tb 0: 1/12
 0,          0,          0,        1,   302760, 0xf24dfa37
 0,          1,          1,        1,   302760, 0xcedcbb6c
-0,          2,          2,        1,   302760, 0x8c2d19a2
-0,          3,          3,        1,   302760, 0xe0fc92da
-0,          4,          4,        1,   302760, 0xd7699bb4
+0,          2,          2,        1,   302760, 0xc87716a2
+0,          3,          3,        1,   302760, 0x7e378e5a
+0,          4,          4,        1,   302760, 0xd4a19734
 0,          5,          5,        1,   302760, 0x26e93266
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/zmbv-15bit b/mythtv/external/FFmpeg/tests/ref/fate/zmbv-15bit
index f054a9d7819..384bb650b7a 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/zmbv-15bit
+++ b/mythtv/external/FFmpeg/tests/ref/fate/zmbv-15bit
@@ -1,160 +1,160 @@
 #tb 0: 250000/1585341
-0,          0,          0,        1,   192000, 0xe1d317d6
-0,          1,          1,        1,   192000, 0xe100109d
-0,          2,          2,        1,   192000, 0xecc69c65
-0,          3,          3,        1,   192000, 0x68f06324
-0,          4,          4,        1,   192000, 0x68f06324
-0,          5,          5,        1,   192000, 0x68f06324
-0,          6,          6,        1,   192000, 0x68f06324
-0,          7,          7,        1,   192000, 0x68f06324
-0,          8,          8,        1,   192000, 0x68f06324
-0,          9,          9,        1,   192000, 0x68f06324
-0,         10,         10,        1,   192000, 0x68f06324
-0,         11,         11,        1,   192000, 0x68f06324
-0,         12,         12,        1,   192000, 0x68f06324
-0,         13,         13,        1,   192000, 0x68f06324
-0,         14,         14,        1,   192000, 0x68f06324
-0,         15,         15,        1,   192000, 0x68f06324
-0,         16,         16,        1,   192000, 0x68f06324
-0,         17,         17,        1,   192000, 0x4c03d2e3
-0,         18,         18,        1,   192000, 0x4c03d2e3
-0,         19,         19,        1,   192000, 0x4c03d2e3
-0,         20,         20,        1,   192000, 0x4c03d2e3
-0,         21,         21,        1,   192000, 0xb562cf68
-0,         22,         22,        1,   192000, 0xb562cf68
-0,         23,         23,        1,   192000, 0xb562cf68
-0,         24,         24,        1,   192000, 0xb562cf68
-0,         25,         25,        1,   192000, 0xb562cf68
-0,         26,         26,        1,   192000, 0x0e5e03c7
-0,         27,         27,        1,   192000, 0x0e5e03c7
-0,         28,         28,        1,   192000, 0x0e5e03c7
-0,         29,         29,        1,   192000, 0x0e5e03c7
-0,         30,         30,        1,   192000, 0xeb2e0f67
-0,         31,         31,        1,   192000, 0xeb2e0f67
-0,         32,         32,        1,   192000, 0xeb2e0f67
-0,         33,         33,        1,   192000, 0xeb2e0f67
-0,         34,         34,        1,   192000, 0xeb2e0f67
-0,         35,         35,        1,   192000, 0xdce603c7
-0,         36,         36,        1,   192000, 0xdce603c7
-0,         37,         37,        1,   192000, 0xdce603c7
-0,         38,         38,        1,   192000, 0xdce603c7
-0,         39,         39,        1,   192000, 0xa8e7db08
-0,         40,         40,        1,   192000, 0xa8e7db08
-0,         41,         41,        1,   192000, 0xa8e7db08
-0,         42,         42,        1,   192000, 0xa8e7db08
-0,         43,         43,        1,   192000, 0xa8e7db08
-0,         44,         44,        1,   192000, 0x322a1b07
-0,         45,         45,        1,   192000, 0x322a1b07
-0,         46,         46,        1,   192000, 0x322a1b07
-0,         47,         47,        1,   192000, 0x322a1b07
-0,         48,         48,        1,   192000, 0x743206af
-0,         49,         49,        1,   192000, 0x743206af
-0,         50,         50,        1,   192000, 0x743206af
-0,         51,         51,        1,   192000, 0x743206af
-0,         52,         52,        1,   192000, 0x743206af
-0,         53,         53,        1,   192000, 0x50195ddf
-0,         54,         54,        1,   192000, 0x50195ddf
-0,         55,         55,        1,   192000, 0x50195ddf
-0,         56,         56,        1,   192000, 0x50195ddf
-0,         57,         57,        1,   192000, 0xd31620d7
-0,         58,         58,        1,   192000, 0xd31620d7
-0,         59,         59,        1,   192000, 0xd31620d7
-0,         60,         60,        1,   192000, 0xd31620d7
-0,         61,         61,        1,   192000, 0xd31620d7
-0,         62,         62,        1,   192000, 0x3af023bf
-0,         63,         63,        1,   192000, 0x3af023bf
-0,         64,         64,        1,   192000, 0x3af023bf
-0,         65,         65,        1,   192000, 0x3af023bf
-0,         66,         66,        1,   192000, 0x561a124f
-0,         67,         67,        1,   192000, 0x561a124f
-0,         68,         68,        1,   192000, 0x561a124f
-0,         69,         69,        1,   192000, 0x561a124f
-0,         70,         70,        1,   192000, 0x561a124f
-0,         71,         71,        1,   192000, 0x99210c7f
-0,         72,         72,        1,   192000, 0x99210c7f
-0,         73,         73,        1,   192000, 0x99210c7f
-0,         74,         74,        1,   192000, 0x99210c7f
-0,         75,         75,        1,   192000, 0xc77b03c7
-0,         76,         76,        1,   192000, 0xc77b03c7
-0,         77,         77,        1,   192000, 0xc77b03c7
-0,         78,         78,        1,   192000, 0xc77b03c7
-0,         79,         79,        1,   192000, 0xc77b03c7
-0,         80,         80,        1,   192000, 0x83ea7550
-0,         81,         81,        1,   192000, 0xec285270
-0,         82,         82,        1,   192000, 0x0e075558
-0,         83,         83,        1,   192000, 0x880c2108
-0,         84,         84,        1,   192000, 0x40c523f0
-0,         85,         85,        1,   192000, 0x01378f78
-0,         86,         86,        1,   192000, 0x42045558
-0,         87,         87,        1,   192000, 0xde8f3278
-0,         88,         88,        1,   192000, 0xa58c0110
-0,         89,         89,        1,   192000, 0x335ea9d1
-0,         90,         90,        1,   192000, 0x7e94bb41
-0,         91,         91,        1,   192000, 0x9cc5d569
-0,         92,         92,        1,   192000, 0xe942e109
-0,         93,         93,        1,   192000, 0x4cb83848
-0,         94,         94,        1,   192000, 0x6986fe19
-0,         95,         95,        1,   192000, 0xbb8c23f0
-0,         96,         96,        1,   192000, 0x296766c8
-0,         97,         97,        1,   192000, 0xb4230cb0
-0,         98,         98,        1,   192000, 0x2c2f1850
-0,         99,         99,        1,   192000, 0x93c70110
-0,        100,        100,        1,   192000, 0xb830a9d1
-0,        101,        101,        1,   192000, 0xbed48fa9
-0,        102,        102,        1,   192000, 0xc087bb41
-0,        103,        103,        1,   192000, 0x792de6d9
-0,        104,        104,        1,   192000, 0x1edaf849
-0,        105,        105,        1,   192000, 0x6564bb41
-0,        106,        106,        1,   192000, 0x9153d569
-0,        107,        107,        1,   192000, 0xe73ff561
-0,        108,        108,        1,   192000, 0xfa3be3f1
-0,        109,        109,        1,   192000, 0x8008fe19
-0,        110,        110,        1,   192000, 0xd2561b38
-0,        111,        111,        1,   192000, 0xae3c26d8
-0,        112,        112,        1,   192000, 0xb0114f88
-0,        113,        113,        1,   192000, 0x117e1e20
-0,        114,        114,        1,   192000, 0x482d1280
-0,        115,        115,        1,   192000, 0x425106e0
-0,        116,        116,        1,   192000, 0x0e6b0cb0
-0,        117,        117,        1,   192000, 0x95dc2ca8
-0,        118,        118,        1,   192000, 0x52097b20
-0,        119,        119,        1,   192000, 0x41a84f88
-0,        120,        120,        1,   192000, 0xb78d7268
-0,        121,        121,        1,   192000, 0x2cd366c8
-0,        122,        122,        1,   192000, 0xbf39e109
-0,        123,        123,        1,   192000, 0xecbaeca9
-0,        124,        124,        1,   192000, 0x3254eca9
-0,        125,        125,        1,   192000, 0x3fc903f8
-0,        126,        126,        1,   192000, 0x0bbc5e10
-0,        127,        127,        1,   192000, 0xe9103560
-0,        128,        128,        1,   192000, 0xbd5d2f90
-0,        129,        129,        1,   192000, 0x7ace2ca8
-0,        130,        130,        1,   192000, 0x7354c6e1
-0,        131,        131,        1,   192000, 0x72e0d569
-0,        132,        132,        1,   192000, 0xa4ade3f1
-0,        133,        133,        1,   192000, 0xf2f8cf99
-0,        134,        134,        1,   192000, 0x2b7ee6d9
-0,        135,        135,        1,   192000, 0x548d1b38
-0,        136,        136,        1,   192000, 0xa1551b38
-0,        137,        137,        1,   192000, 0xfb3e3560
-0,        138,        138,        1,   192000, 0x3aaaccb1
-0,        139,        139,        1,   192000, 0xa85ee109
-0,        140,        140,        1,   192000, 0xc1bff849
-0,        141,        141,        1,   192000, 0xa62bef91
-0,        142,        142,        1,   192000, 0xddf40cb0
-0,        143,        143,        1,   192000, 0x15bb3e18
-0,        144,        144,        1,   192000, 0x92fd5558
-0,        145,        145,        1,   192000, 0x2d365270
-0,        146,        146,        1,   192000, 0xb5f343e8
-0,        147,        147,        1,   192000, 0x93042108
-0,        148,        148,        1,   192000, 0x96d59830
-0,        149,        149,        1,   192000, 0x1f69ddf0
-0,        150,        150,        1,   192000, 0x8eb0124f
-0,        151,        151,        1,   192000, 0xae727dd7
-0,        152,        152,        1,   192000, 0xb8a63aff
-0,        153,        153,        1,   192000, 0xfae83de7
-0,        154,        154,        1,   192000, 0x2f034987
-0,        155,        155,        1,   192000, 0xa99e1537
-0,        156,        156,        1,   192000, 0x0ad70c7f
-0,        157,        157,        1,   192000, 0x74b3e990
-0,        158,        158,        1,   192000, 0x1bf0d250
+0,          0,          0,        1,   192000, 0x8f9020f2
+0,          1,          1,        1,   192000, 0xbfba7f63
+0,          2,          2,        1,   192000, 0x96b48d11
+0,          3,          3,        1,   192000, 0xf91727d5
+0,          4,          4,        1,   192000, 0xf91727d5
+0,          5,          5,        1,   192000, 0xf91727d5
+0,          6,          6,        1,   192000, 0xf91727d5
+0,          7,          7,        1,   192000, 0xf91727d5
+0,          8,          8,        1,   192000, 0xf91727d5
+0,          9,          9,        1,   192000, 0xf91727d5
+0,         10,         10,        1,   192000, 0xf91727d5
+0,         11,         11,        1,   192000, 0xf91727d5
+0,         12,         12,        1,   192000, 0xf91727d5
+0,         13,         13,        1,   192000, 0xf91727d5
+0,         14,         14,        1,   192000, 0xf91727d5
+0,         15,         15,        1,   192000, 0xf91727d5
+0,         16,         16,        1,   192000, 0xf91727d5
+0,         17,         17,        1,   192000, 0x61c4e431
+0,         18,         18,        1,   192000, 0x61c4e431
+0,         19,         19,        1,   192000, 0x61c4e431
+0,         20,         20,        1,   192000, 0x61c4e431
+0,         21,         21,        1,   192000, 0x1fb3f649
+0,         22,         22,        1,   192000, 0x1fb3f649
+0,         23,         23,        1,   192000, 0x1fb3f649
+0,         24,         24,        1,   192000, 0x1fb3f649
+0,         25,         25,        1,   192000, 0x1fb3f649
+0,         26,         26,        1,   192000, 0x14f72c22
+0,         27,         27,        1,   192000, 0x14f72c22
+0,         28,         28,        1,   192000, 0x14f72c22
+0,         29,         29,        1,   192000, 0x14f72c22
+0,         30,         30,        1,   192000, 0x8cae3816
+0,         31,         31,        1,   192000, 0x8cae3816
+0,         32,         32,        1,   192000, 0x8cae3816
+0,         33,         33,        1,   192000, 0x8cae3816
+0,         34,         34,        1,   192000, 0x8cae3816
+0,         35,         35,        1,   192000, 0x2b6f2c22
+0,         36,         36,        1,   192000, 0x2b6f2c22
+0,         37,         37,        1,   192000, 0x2b6f2c22
+0,         38,         38,        1,   192000, 0x2b6f2c22
+0,         39,         39,        1,   192000, 0xc568024c
+0,         40,         40,        1,   192000, 0xc568024c
+0,         41,         41,        1,   192000, 0xc568024c
+0,         42,         42,        1,   192000, 0xc568024c
+0,         43,         43,        1,   192000, 0xc568024c
+0,         44,         44,        1,   192000, 0xa93b440a
+0,         45,         45,        1,   192000, 0xa93b440a
+0,         46,         46,        1,   192000, 0xa93b440a
+0,         47,         47,        1,   192000, 0xa93b440a
+0,         48,         48,        1,   192000, 0x798a2f1f
+0,         49,         49,        1,   192000, 0x798a2f1f
+0,         50,         50,        1,   192000, 0x798a2f1f
+0,         51,         51,        1,   192000, 0x798a2f1f
+0,         52,         52,        1,   192000, 0x798a2f1f
+0,         53,         53,        1,   192000, 0xf04288c5
+0,         54,         54,        1,   192000, 0xf04288c5
+0,         55,         55,        1,   192000, 0xf04288c5
+0,         56,         56,        1,   192000, 0xf04288c5
+0,         57,         57,        1,   192000, 0x4aa04a04
+0,         58,         58,        1,   192000, 0x4aa04a04
+0,         59,         59,        1,   192000, 0x4aa04a04
+0,         60,         60,        1,   192000, 0x4aa04a04
+0,         61,         61,        1,   192000, 0x4aa04a04
+0,         62,         62,        1,   192000, 0xb0304d01
+0,         63,         63,        1,   192000, 0xb0304d01
+0,         64,         64,        1,   192000, 0xb0304d01
+0,         65,         65,        1,   192000, 0xb0304d01
+0,         66,         66,        1,   192000, 0xef353b13
+0,         67,         67,        1,   192000, 0xef353b13
+0,         68,         68,        1,   192000, 0xef353b13
+0,         69,         69,        1,   192000, 0xef353b13
+0,         70,         70,        1,   192000, 0xef353b13
+0,         71,         71,        1,   192000, 0xbf823519
+0,         72,         72,        1,   192000, 0xbf823519
+0,         73,         73,        1,   192000, 0xbf823519
+0,         74,         74,        1,   192000, 0xbf823519
+0,         75,         75,        1,   192000, 0xd0352c22
+0,         76,         76,        1,   192000, 0xd0352c22
+0,         77,         77,        1,   192000, 0xd0352c22
+0,         78,         78,        1,   192000, 0xd0352c22
+0,         79,         79,        1,   192000, 0xd0352c22
+0,         80,         80,        1,   192000, 0x817299a6
+0,         81,         81,        1,   192000, 0xfb1475ca
+0,         82,         82,        1,   192000, 0xfcd278c7
+0,         83,         83,        1,   192000, 0xa08742fd
+0,         84,         84,        1,   192000, 0x47c245fa
+0,         85,         85,        1,   192000, 0xf7e7b48b
+0,         86,         86,        1,   192000, 0xf56378c7
+0,         87,         87,        1,   192000, 0x80bc54eb
+0,         88,         88,        1,   192000, 0xae59221e
+0,         89,         89,        1,   192000, 0x7d0fc869
+0,         90,         90,        1,   192000, 0x8e89da57
+0,         91,         91,        1,   192000, 0xf0a9f53c
+0,         92,         92,        1,   192000, 0x658d013f
+0,         93,         93,        1,   192000, 0x90ef5ae5
+0,         94,         94,        1,   192000, 0x93b81f21
+0,         95,         95,        1,   192000, 0x61e545fa
+0,         96,         96,        1,   192000, 0xc6688ab5
+0,         97,         97,        1,   192000, 0x72032e12
+0,         98,         98,        1,   192000, 0xf28c3a06
+0,         99,         99,        1,   192000, 0xf1bc221e
+0,        100,        100,        1,   192000, 0x941bc869
+0,        101,        101,        1,   192000, 0xe95ead84
+0,        102,        102,        1,   192000, 0x61dbda57
+0,        103,        103,        1,   192000, 0x79800739
+0,        104,        104,        1,   192000, 0x00c31927
+0,        105,        105,        1,   192000, 0x74a3da57
+0,        106,        106,        1,   192000, 0xb98cf53c
+0,        107,        107,        1,   192000, 0xd3f9162a
+0,        108,        108,        1,   192000, 0x888c043c
+0,        109,        109,        1,   192000, 0x100f1f21
+0,        110,        110,        1,   192000, 0x41993d03
+0,        111,        111,        1,   192000, 0x01a548f7
+0,        112,        112,        1,   192000, 0xbe5372cd
+0,        113,        113,        1,   192000, 0x0fec4000
+0,        114,        114,        1,   192000, 0x80e9340c
+0,        115,        115,        1,   192000, 0xea582818
+0,        116,        116,        1,   192000, 0x5c3a2e12
+0,        117,        117,        1,   192000, 0x5c2b4ef1
+0,        118,        118,        1,   192000, 0xf2409fa0
+0,        119,        119,        1,   192000, 0x4bc472cd
+0,        120,        120,        1,   192000, 0x3dcb96a9
+0,        121,        121,        1,   192000, 0xff978ab5
+0,        122,        122,        1,   192000, 0xff72013f
+0,        123,        123,        1,   192000, 0x2f530d33
+0,        124,        124,        1,   192000, 0xa3350d33
+0,        125,        125,        1,   192000, 0x6be6251b
+0,        126,        126,        1,   192000, 0x07f081be
+0,        127,        127,        1,   192000, 0xb5d957e8
+0,        128,        128,        1,   192000, 0x43c551ee
+0,        129,        129,        1,   192000, 0x19224ef1
+0,        130,        130,        1,   192000, 0x0720e64b
+0,        131,        131,        1,   192000, 0x3c53f53c
+0,        132,        132,        1,   192000, 0x8534043c
+0,        133,        133,        1,   192000, 0xb7c7ef42
+0,        134,        134,        1,   192000, 0x9e3e0739
+0,        135,        135,        1,   192000, 0x95e43d03
+0,        136,        136,        1,   192000, 0x92473d03
+0,        137,        137,        1,   192000, 0x636757e8
+0,        138,        138,        1,   192000, 0xba3aec45
+0,        139,        139,        1,   192000, 0xfd9e013f
+0,        140,        140,        1,   192000, 0x108c1927
+0,        141,        141,        1,   192000, 0x29db1030
+0,        142,        142,        1,   192000, 0xe0172e12
+0,        143,        143,        1,   192000, 0x744260df
+0,        144,        144,        1,   192000, 0xc59478c7
+0,        145,        145,        1,   192000, 0xa84475ca
+0,        146,        146,        1,   192000, 0x9d2866d9
+0,        147,        147,        1,   192000, 0xc49342fd
+0,        148,        148,        1,   192000, 0x13e5bd82
+0,        149,        149,        1,   192000, 0x10d10549
+0,        150,        150,        1,   192000, 0xf5ca3b13
+0,        151,        151,        1,   192000, 0x8c27a9a4
+0,        152,        152,        1,   192000, 0xcc4f64e9
+0,        153,        153,        1,   192000, 0x020c67e6
+0,        154,        154,        1,   192000, 0xaf4773da
+0,        155,        155,        1,   192000, 0x62093e10
+0,        156,        156,        1,   192000, 0x96783519
+0,        157,        157,        1,   192000, 0x8b9a113d
+0,        158,        158,        1,   192000, 0x9050f946
diff --git a/mythtv/external/FFmpeg/tests/ref/fate/zmbv-16bit b/mythtv/external/FFmpeg/tests/ref/fate/zmbv-16bit
index b0c3df55132..cb390148f14 100644
--- a/mythtv/external/FFmpeg/tests/ref/fate/zmbv-16bit
+++ b/mythtv/external/FFmpeg/tests/ref/fate/zmbv-16bit
@@ -1,123 +1,123 @@
 #tb 0: 250000/1585341
-0,          0,          0,        1,   192000, 0x11e62dbe
-0,          1,          1,        1,   192000, 0x31698b8f
-0,          2,          2,        1,   192000, 0x31698b8f
-0,          3,          3,        1,   192000, 0x31698b8f
-0,          4,          4,        1,   192000, 0x31698b8f
-0,          5,          5,        1,   192000, 0x31698b8f
-0,          6,          6,        1,   192000, 0x31698b8f
-0,          7,          7,        1,   192000, 0x31698b8f
-0,          8,          8,        1,   192000, 0x31698b8f
-0,          9,          9,        1,   192000, 0x31698b8f
-0,         10,         10,        1,   192000, 0x31698b8f
-0,         11,         11,        1,   192000, 0x31698b8f
-0,         12,         12,        1,   192000, 0x31698b8f
-0,         13,         13,        1,   192000, 0x4ca609ea
-0,         14,         14,        1,   192000, 0x4ca609ea
-0,         15,         15,        1,   192000, 0x4ca609ea
-0,         16,         16,        1,   192000, 0x4ca609ea
-0,         17,         17,        1,   192000, 0x33dd0a8b
-0,         18,         18,        1,   192000, 0x33dd0a8b
-0,         19,         19,        1,   192000, 0x33dd0a8b
-0,         20,         20,        1,   192000, 0x33dd0a8b
-0,         21,         21,        1,   192000, 0x33dd0a8b
-0,         22,         22,        1,   192000, 0x08e2420f
-0,         23,         23,        1,   192000, 0x08e2420f
-0,         24,         24,        1,   192000, 0x08e2420f
-0,         25,         25,        1,   192000, 0x08e2420f
-0,         26,         26,        1,   192000, 0x7b7b50ab
-0,         27,         27,        1,   192000, 0x7b7b50ab
-0,         28,         28,        1,   192000, 0x7b7b50ab
-0,         29,         29,        1,   192000, 0x7b7b50ab
-0,         30,         30,        1,   192000, 0x7b7b50ab
-0,         31,         31,        1,   192000, 0x128744fb
-0,         32,         32,        1,   192000, 0x128744fb
-0,         33,         33,        1,   192000, 0x128744fb
-0,         34,         34,        1,   192000, 0x128744fb
-0,         35,         35,        1,   192000, 0x8643163b
-0,         36,         36,        1,   192000, 0x8643163b
-0,         37,         37,        1,   192000, 0x8643163b
-0,         38,         38,        1,   192000, 0x8643163b
-0,         39,         39,        1,   192000, 0x8643163b
-0,         40,         40,        1,   192000, 0x4f7c596f
-0,         41,         41,        1,   192000, 0x4f7c596f
-0,         42,         42,        1,   192000, 0x4f7c596f
-0,         43,         43,        1,   192000, 0x4f7c596f
-0,         44,         44,        1,   192000, 0xa275420f
-0,         45,         45,        1,   192000, 0xa275420f
-0,         46,         46,        1,   192000, 0xa275420f
-0,         47,         47,        1,   192000, 0xa275420f
-0,         48,         48,        1,   192000, 0xa275420f
-0,         49,         49,        1,   192000, 0x2e4796cb
-0,         50,         50,        1,   192000, 0x2e4796cb
-0,         51,         51,        1,   192000, 0x2e4796cb
-0,         52,         52,        1,   192000, 0x2e4796cb
-0,         53,         53,        1,   192000, 0xebd45683
-0,         54,         54,        1,   192000, 0xebd45683
-0,         55,         55,        1,   192000, 0xebd45683
-0,         56,         56,        1,   192000, 0xebd45683
-0,         57,         57,        1,   192000, 0xebd45683
-0,         58,         58,        1,   192000, 0x0bf6596f
-0,         59,         59,        1,   192000, 0x0bf6596f
-0,         60,         60,        1,   192000, 0x0bf6596f
-0,         61,         61,        1,   192000, 0x0bf6596f
-0,         62,         62,        1,   192000, 0xb7af47e7
-0,         63,         63,        1,   192000, 0xb7af47e7
-0,         64,         64,        1,   192000, 0xb7af47e7
-0,         65,         65,        1,   192000, 0xb7af47e7
-0,         66,         66,        1,   192000, 0xb7af47e7
-0,         67,         67,        1,   192000, 0x8bc344fb
-0,         68,         68,        1,   192000, 0x8bc344fb
-0,         69,         69,        1,   192000, 0x8bc344fb
-0,         70,         70,        1,   192000, 0x8bc344fb
-0,         71,         71,        1,   192000, 0x8bc344fb
-0,         72,         72,        1,   192000, 0x02a23f23
-0,         73,         73,        1,   192000, 0x02a23f23
-0,         74,         74,        1,   192000, 0x02a23f23
-0,         75,         75,        1,   192000, 0x02a23f23
-0,         76,         76,        1,   192000, 0x17be3087
-0,         77,         77,        1,   192000, 0x52c7b2d4
-0,         78,         78,        1,   192000, 0xa05e9888
-0,         79,         79,        1,   192000, 0x4d6a6cb4
-0,         80,         80,        1,   192000, 0x3e2189ec
-0,         81,         81,        1,   192000, 0xfbe3ca34
-0,         82,         82,        1,   192000, 0xa9cd8fc4
-0,         83,         83,        1,   192000, 0x986e6cb4
-0,         84,         84,        1,   192000, 0x42373b08
-0,         85,         85,        1,   192000, 0xab96e351
-0,         86,         86,        1,   192000, 0x28ccf4d9
-0,         87,         87,        1,   192000, 0xc19e0f34
-0,         88,         88,        1,   192000, 0xd8da1ae4
-0,         89,         89,        1,   192000, 0xd015728c
-0,         90,         90,        1,   192000, 0x550623a8
-0,         91,         91,        1,   192000, 0x3c5c5268
-0,         92,         92,        1,   192000, 0x3eae8128
-0,         93,         93,        1,   192000, 0x3c51381c
-0,         94,         94,        1,   192000, 0x745046b8
-0,         95,         95,        1,   192000, 0xa8bd43cc
-0,         96,         96,        1,   192000, 0xde8fe351
-0,         97,         97,        1,   192000, 0x3d5cc905
-0,         98,         98,        1,   192000, 0xcf8df4d9
-0,         99,         99,        1,   192000, 0x698b20bc
-0,        100,        100,        1,   192000, 0x159d3244
-0,        101,        101,        1,   192000, 0xba1af4d9
-0,        102,        102,        1,   192000, 0x033a0f34
-0,        103,        103,        1,   192000, 0x72612f58
-0,        104,        104,        1,   192000, 0x11e11dd0
-0,        105,        105,        1,   192000, 0x4fc04f7c
-0,        106,        106,        1,   192000, 0x37779888
-0,        107,        107,        1,   192000, 0xabfc5e18
-0,        108,        108,        1,   192000, 0x0ad97e3c
-0,        109,        109,        1,   192000, 0xddf492b0
-0,        110,        110,        1,   192000, 0x198b23a8
-0,        111,        111,        1,   192000, 0x6b491220
-0,        112,        112,        1,   192000, 0x632417f8
-0,        113,        113,        1,   192000, 0x0dc5381c
-0,        114,        114,        1,   192000, 0x6d548700
-0,        115,        115,        1,   192000, 0xae0c5b2c
-0,        116,        116,        1,   192000, 0x23427e3c
-0,        117,        117,        1,   192000, 0x5def728c
-0,        118,        118,        1,   192000, 0xec831ae4
+0,          0,          0,        1,   192000, 0xe869dc94
+0,          1,          1,        1,   192000, 0x742932f2
+0,          2,          2,        1,   192000, 0x742932f2
+0,          3,          3,        1,   192000, 0x742932f2
+0,          4,          4,        1,   192000, 0x742932f2
+0,          5,          5,        1,   192000, 0x742932f2
+0,          6,          6,        1,   192000, 0x742932f2
+0,          7,          7,        1,   192000, 0x742932f2
+0,          8,          8,        1,   192000, 0x742932f2
+0,          9,          9,        1,   192000, 0x742932f2
+0,         10,         10,        1,   192000, 0x742932f2
+0,         11,         11,        1,   192000, 0x742932f2
+0,         12,         12,        1,   192000, 0x742932f2
+0,         13,         13,        1,   192000, 0xb718e72e
+0,         14,         14,        1,   192000, 0xb718e72e
+0,         15,         15,        1,   192000, 0xb718e72e
+0,         16,         16,        1,   192000, 0xb718e72e
+0,         17,         17,        1,   192000, 0x7507f946
+0,         18,         18,        1,   192000, 0x7507f946
+0,         19,         19,        1,   192000, 0x7507f946
+0,         20,         20,        1,   192000, 0x7507f946
+0,         21,         21,        1,   192000, 0x7507f946
+0,         22,         22,        1,   192000, 0xe620321c
+0,         23,         23,        1,   192000, 0xe620321c
+0,         24,         24,        1,   192000, 0xe620321c
+0,         25,         25,        1,   192000, 0xe620321c
+0,         26,         26,        1,   192000, 0x9b5f410d
+0,         27,         27,        1,   192000, 0x9b5f410d
+0,         28,         28,        1,   192000, 0x9b5f410d
+0,         29,         29,        1,   192000, 0x9b5f410d
+0,         30,         30,        1,   192000, 0x9b5f410d
+0,         31,         31,        1,   192000, 0xea2c3519
+0,         32,         32,        1,   192000, 0xea2c3519
+0,         33,         33,        1,   192000, 0xea2c3519
+0,         34,         34,        1,   192000, 0xea2c3519
+0,         35,         35,        1,   192000, 0x1acb0549
+0,         36,         36,        1,   192000, 0x1acb0549
+0,         37,         37,        1,   192000, 0x1acb0549
+0,         38,         38,        1,   192000, 0x1acb0549
+0,         39,         39,        1,   192000, 0x1acb0549
+0,         40,         40,        1,   192000, 0x3a064a04
+0,         41,         41,        1,   192000, 0x3a064a04
+0,         42,         42,        1,   192000, 0x3a064a04
+0,         43,         43,        1,   192000, 0x3a064a04
+0,         44,         44,        1,   192000, 0xcede321c
+0,         45,         45,        1,   192000, 0xcede321c
+0,         46,         46,        1,   192000, 0xcede321c
+0,         47,         47,        1,   192000, 0xcede321c
+0,         48,         48,        1,   192000, 0xcede321c
+0,         49,         49,        1,   192000, 0xef4988c5
+0,         50,         50,        1,   192000, 0xef4988c5
+0,         51,         51,        1,   192000, 0xef4988c5
+0,         52,         52,        1,   192000, 0xef4988c5
+0,         53,         53,        1,   192000, 0x1fc84707
+0,         54,         54,        1,   192000, 0x1fc84707
+0,         55,         55,        1,   192000, 0x1fc84707
+0,         56,         56,        1,   192000, 0x1fc84707
+0,         57,         57,        1,   192000, 0x1fc84707
+0,         58,         58,        1,   192000, 0xbabd4a04
+0,         59,         59,        1,   192000, 0xbabd4a04
+0,         60,         60,        1,   192000, 0xbabd4a04
+0,         61,         61,        1,   192000, 0xbabd4a04
+0,         62,         62,        1,   192000, 0x649b3816
+0,         63,         63,        1,   192000, 0x649b3816
+0,         64,         64,        1,   192000, 0x649b3816
+0,         65,         65,        1,   192000, 0x649b3816
+0,         66,         66,        1,   192000, 0x649b3816
+0,         67,         67,        1,   192000, 0x206b3519
+0,         68,         68,        1,   192000, 0x206b3519
+0,         69,         69,        1,   192000, 0x206b3519
+0,         70,         70,        1,   192000, 0x206b3519
+0,         71,         71,        1,   192000, 0x206b3519
+0,         72,         72,        1,   192000, 0x25982f1f
+0,         73,         73,        1,   192000, 0x25982f1f
+0,         74,         74,        1,   192000, 0x25982f1f
+0,         75,         75,        1,   192000, 0x25982f1f
+0,         76,         76,        1,   192000, 0xde0e202e
+0,         77,         77,        1,   192000, 0xced09fa0
+0,         78,         78,        1,   192000, 0x3b4f84bb
+0,         79,         79,        1,   192000, 0xa09c57e8
+0,         80,         80,        1,   192000, 0xf3dd75ca
+0,         81,         81,        1,   192000, 0x4d4ab788
+0,         82,         82,        1,   192000, 0x4ac67bc4
+0,         83,         83,        1,   192000, 0xd61057e8
+0,         84,         84,        1,   192000, 0x03bc251b
+0,         85,         85,        1,   192000, 0xd263cb66
+0,         86,         86,        1,   192000, 0xe3dddd54
+0,         87,         87,        1,   192000, 0x460cf839
+0,         88,         88,        1,   192000, 0xbae1043c
+0,         89,         89,        1,   192000, 0xe6435de2
+0,         90,         90,        1,   192000, 0x340e0d33
+0,         91,         91,        1,   192000, 0x9acd3d03
+0,         92,         92,        1,   192000, 0x1d346cd3
+0,         93,         93,        1,   192000, 0xdabe221e
+0,         94,         94,        1,   192000, 0xeb4b310f
+0,         95,         95,        1,   192000, 0xec8f2e12
+0,         96,         96,        1,   192000, 0xe96fcb66
+0,         97,         97,        1,   192000, 0x3ec1b081
+0,         98,         98,        1,   192000, 0xb72fdd54
+0,         99,         99,        1,   192000, 0xced40a36
+0,        100,        100,        1,   192000, 0x56171c24
+0,        101,        101,        1,   192000, 0xc9f7dd54
+0,        102,        102,        1,   192000, 0x0eeff839
+0,        103,        103,        1,   192000, 0x295c1927
+0,        104,        104,        1,   192000, 0xdde00739
+0,        105,        105,        1,   192000, 0x51903a06
+0,        106,        106,        1,   192000, 0xe16a84bb
+0,        107,        107,        1,   192000, 0xf5b248f7
+0,        108,        108,        1,   192000, 0x054769d6
+0,        109,        109,        1,   192000, 0x9d327ec1
+0,        110,        110,        1,   192000, 0x94470d33
+0,        111,        111,        1,   192000, 0x9671fb36
+0,        112,        112,        1,   192000, 0x0853013f
+0,        113,        113,        1,   192000, 0x0844221e
+0,        114,        114,        1,   192000, 0x9e5972cd
+0,        115,        115,        1,   192000, 0xf7ce45fa
+0,        116,        116,        1,   192000, 0xe9d569d6
+0,        117,        117,        1,   192000, 0xabb05de2
+0,        118,        118,        1,   192000, 0x54d5043c
 0,        119,        119,        1,   192000, 0x00000000
 0,        120,        120,        1,   192000, 0x00000000
 0,        121,        121,        1,   192000, 0x00000000
diff --git a/mythtv/external/FFmpeg/tests/ref/lavf/dpx b/mythtv/external/FFmpeg/tests/ref/lavf/dpx
index 70371d8115b..0206bd7d025 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavf/dpx
+++ b/mythtv/external/FFmpeg/tests/ref/lavf/dpx
@@ -5,5 +5,5 @@ d2f0b4e854fda2d3b3bee84cef80593c *./tests/data/images/dpx/02.dpx
 ./tests/data/images/dpx/%02d.dpx CRC=0xe5b9c023
 609920 ./tests/data/images/dpx/02.dpx
 b9f22728f8ff393bf30cf6cbd624fa95 *./tests/data/images/dpx/02.dpx
-./tests/data/images/dpx/%02d.dpx CRC=0xf0a1c097
+./tests/data/images/dpx/%02d.dpx CRC=0xb6310a70
 407168 ./tests/data/images/dpx/02.dpx
diff --git a/mythtv/external/FFmpeg/tests/ref/lavf/dv_fmt b/mythtv/external/FFmpeg/tests/ref/lavf/dv_fmt
index 92092a62bd7..ed8c5cc14cb 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavf/dv_fmt
+++ b/mythtv/external/FFmpeg/tests/ref/lavf/dv_fmt
@@ -1,9 +1,9 @@
 11be3e5caa2892236b3475c3f7807b76 *./tests/data/lavf/lavf.dv
 3600000 ./tests/data/lavf/lavf.dv
 ./tests/data/lavf/lavf.dv CRC=0x25bdd732
-7c789e3559b5102de9459211ae4acf06 *./tests/data/lavf/lavf.dv
+78db8504eefb660ed205b417157d4f44 *./tests/data/lavf/lavf.dv
 3600000 ./tests/data/lavf/lavf.dv
-./tests/data/lavf/lavf.dv CRC=0x3f43a4f5
+./tests/data/lavf/lavf.dv CRC=0x1cec8738
 87d3b20f656235671383a7eaa2f66330 *./tests/data/lavf/lavf.dv
 3600000 ./tests/data/lavf/lavf.dv
 ./tests/data/lavf/lavf.dv CRC=0x0e868a82
diff --git a/mythtv/external/FFmpeg/tests/ref/lavf/gxf b/mythtv/external/FFmpeg/tests/ref/lavf/gxf
index 6238a3187c0..9e7871d6155 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavf/gxf
+++ b/mythtv/external/FFmpeg/tests/ref/lavf/gxf
@@ -1,9 +1,9 @@
 c8b3a8e3ba0185ce39122ac150c12bc3 *./tests/data/lavf/lavf.gxf
 795876 ./tests/data/lavf/lavf.gxf
 ./tests/data/lavf/lavf.gxf CRC=0x147ff044
-4c6594c58da57af745eb511bdd65bca7 *./tests/data/lavf/lavf.gxf
-816752 ./tests/data/lavf/lavf.gxf
-./tests/data/lavf/lavf.gxf CRC=0xfa7c375a
+b26bd3cb439dff8b33cd74a27a3fc2d6 *./tests/data/lavf/lavf.gxf
+794656 ./tests/data/lavf/lavf.gxf
+./tests/data/lavf/lavf.gxf CRC=0xe0199511
 e4721383461d7a9feae41435567c9257 *./tests/data/lavf/lavf.gxf
 795876 ./tests/data/lavf/lavf.gxf
 ./tests/data/lavf/lavf.gxf CRC=0xd9d58865
diff --git a/mythtv/external/FFmpeg/tests/ref/lavf/ismv b/mythtv/external/FFmpeg/tests/ref/lavf/ismv
index c6651b5c599..6f9f57be22b 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavf/ismv
+++ b/mythtv/external/FFmpeg/tests/ref/lavf/ismv
@@ -1,9 +1,9 @@
 a24a0426b5f8dc896daaf18502e38790 *./tests/data/lavf/lavf.ismv
 312263 ./tests/data/lavf/lavf.ismv
 ./tests/data/lavf/lavf.ismv CRC=0x9d9a638a
-33d07ab6c5485d639e7052ccc73aeb70 *./tests/data/lavf/lavf.ismv
-331253 ./tests/data/lavf/lavf.ismv
-./tests/data/lavf/lavf.ismv CRC=0x2a63dc62
+1b98502911dd19a9792777de67922db2 *./tests/data/lavf/lavf.ismv
+321189 ./tests/data/lavf/lavf.ismv
+./tests/data/lavf/lavf.ismv CRC=0xe8130120
 a24a0426b5f8dc896daaf18502e38790 *./tests/data/lavf/lavf.ismv
 312263 ./tests/data/lavf/lavf.ismv
 ./tests/data/lavf/lavf.ismv CRC=0x9d9a638a
diff --git a/mythtv/external/FFmpeg/tests/ref/lavf/mkv b/mythtv/external/FFmpeg/tests/ref/lavf/mkv
index d92aaa8c814..64979b225fe 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavf/mkv
+++ b/mythtv/external/FFmpeg/tests/ref/lavf/mkv
@@ -1,3 +1,6 @@
+b53f31e572394f225aff0bc82b5d1cc9 *./tests/data/lavf/lavf.mkv
+472553 ./tests/data/lavf/lavf.mkv
+./tests/data/lavf/lavf.mkv CRC=0x4780846b
 84dcb326fe85aeeb5768beb44372f248 *./tests/data/lavf/lavf.mkv
 320297 ./tests/data/lavf/lavf.mkv
 ./tests/data/lavf/lavf.mkv CRC=0x4780846b
diff --git a/mythtv/external/FFmpeg/tests/ref/lavf/mov b/mythtv/external/FFmpeg/tests/ref/lavf/mov
index 4554ea65d9d..2ed8ad02da9 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavf/mov
+++ b/mythtv/external/FFmpeg/tests/ref/lavf/mov
@@ -4,9 +4,9 @@ fcbe7806047914d9751fd9053009df69 *./tests/data/lavf/lavf.mov
 72eac0051107a16e41d5263dab640f26 *./tests/data/lavf/lavf.mov
 358455 ./tests/data/lavf/lavf.mov
 ./tests/data/lavf/lavf.mov CRC=0xb2f59ab4
-cbc587335946df1f08d838f48ef396f0 *./tests/data/lavf/lavf.mov
-377613 ./tests/data/lavf/lavf.mov
-./tests/data/lavf/lavf.mov CRC=0xc882139b
+cf6ea2e8d4d16626d9dbd9e3fb802ce6 *./tests/data/lavf/lavf.mov
+367549 ./tests/data/lavf/lavf.mov
+./tests/data/lavf/lavf.mov CRC=0x6e82384a
 7c932d24837f46ef57d3e40a61331565 *./tests/data/lavf/lavf.mov
 357837 ./tests/data/lavf/lavf.mov
 ./tests/data/lavf/lavf.mov CRC=0xb2f59ab4
diff --git a/mythtv/external/FFmpeg/tests/ref/lavf/mpg b/mythtv/external/FFmpeg/tests/ref/lavf/mpg
index 35465ed1270..798ee03ae6b 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavf/mpg
+++ b/mythtv/external/FFmpeg/tests/ref/lavf/mpg
@@ -1,9 +1,9 @@
 ddc5cd5469eb8a0500f8a725baead5e5 *./tests/data/lavf/lavf.mpg
 372736 ./tests/data/lavf/lavf.mpg
 ./tests/data/lavf/lavf.mpg CRC=0x5b136bb1
-c4e9026e5f57777a71762d68994fc3a9 *./tests/data/lavf/lavf.mpg
-399360 ./tests/data/lavf/lavf.mpg
-./tests/data/lavf/lavf.mpg CRC=0xd21e5631
+7962eab004026dd7a8c0417470cdf574 *./tests/data/lavf/lavf.mpg
+389120 ./tests/data/lavf/lavf.mpg
+./tests/data/lavf/lavf.mpg CRC=0xbbbf92bc
 bb22933de60193bce9032f67ce6fcc23 *./tests/data/lavf/lavf.mpg
 372736 ./tests/data/lavf/lavf.mpg
 ./tests/data/lavf/lavf.mpg CRC=0x5b136bb1
diff --git a/mythtv/external/FFmpeg/tests/ref/lavf/mxf b/mythtv/external/FFmpeg/tests/ref/lavf/mxf
index 6ca82c81d13..b1e46e9be80 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavf/mxf
+++ b/mythtv/external/FFmpeg/tests/ref/lavf/mxf
@@ -1,9 +1,9 @@
 967f6ee9223c865328f4891465191108 *./tests/data/lavf/lavf.mxf
 525369 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0xdbfff6f1
-ec951485333c0b320d2ede8692c602ae *./tests/data/lavf/lavf.mxf
-554553 ./tests/data/lavf/lavf.mxf
-./tests/data/lavf/lavf.mxf CRC=0xfbaac0b0
+7788939d349d09a7f9b546e59376a496 *./tests/data/lavf/lavf.mxf
+560697 ./tests/data/lavf/lavf.mxf
+./tests/data/lavf/lavf.mxf CRC=0xb69f428b
 ce535b606423d117675213b16275206a *./tests/data/lavf/lavf.mxf
 525369 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0xdbfff6f1
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/field b/mythtv/external/FFmpeg/tests/ref/lavfi/field
index 2d4a6b06ab9..68a4643ea25 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavfi/field
+++ b/mythtv/external/FFmpeg/tests/ref/lavfi/field
@@ -15,6 +15,15 @@ bgr565be            bf955b9a035af0e613cf1de249f55f9d
 bgr565le            6dd85cd5e19266c53a54cbcf06d396a7
 bgr8                9669f6974f0fc1c0afa1c7d4df093c0b
 bgra                f7cabae31dd7465dab2203f45db646f8
+gbrp                55eab469e3e02ccc5a358565d9b1eaa7
+gbrp10be            38753e9ac21e13d76d1a83bd7272c026
+gbrp10le            a65ff11ee79ae698550218549288e6cc
+gbrp12be            5f49bf3190b98221dab95056ab46bd96
+gbrp12le            3d1cd386205bc690407c81a007a79170
+gbrp14be            60e2efec11a36e7cb0db95e01603d9eb
+gbrp14le            fdcdecdd2c8dc13561a3788ce0487c85
+gbrp9be             86380bf8eaeee32ec40d776f699394e5
+gbrp9le             1286d4558d9bc7c3d68261f4b43e3ba9
 gray                66a09b53f7d3f79dcb6096f3ec3740c5
 gray16be            a447af6482b922c9997ac02e5d3535f1
 gray16le            c1dd0db327295898ff282d07f48c105d
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/il b/mythtv/external/FFmpeg/tests/ref/lavfi/il
new file mode 100644
index 00000000000..d4a81426307
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/lavfi/il
@@ -0,0 +1,109 @@
+0bgr                b85afb77d7c3198ad7ff9ca5cceb970b
+0rgb                7ca2257e526092027c67311e273767bf
+abgr                4df961441de91db58f5a8a80603de585
+argb                db1e1e487a489674fbf260f56ac2705d
+bgr0                4335fb9738bb6ca5d6d39d738b934bbd
+bgr24               7446301030e6a26853aca2036309fa8a
+bgr444be            f80a44936b1295d14b0bac1db624d02e
+bgr444le            cfc1511a390f7ca18516540c31c097c3
+bgr48be             0b1084ac65d328552bd62b4e819ab91d
+bgr48le             04e4f510b6d586dc9082af43a59c0ede
+bgr4_byte           2dfd29e0705fbb2b590458028cb2939d
+bgr555be            5622aa808b389095658a203970bd6028
+bgr555le            6a5ad1e35cbacc45aeb9fd593c6f61ba
+bgr565be            5ff7a76d9f58800e38f21a84d88c7129
+bgr565le            485b2b6f589a936d6fb12d0033809dca
+bgr8                d7fae34b87a67556c273585d9140ff96
+bgra                7b4abc57f0ee99a0226e9bfd5d25cf9e
+gbrp                b85cfeb0e34559ffb4b2e4f1209a3712
+gbrp10be            5487219fee31607d6b19aa0d302fb42f
+gbrp10le            7975e53a9e03a8acfa877334ae5e9d1d
+gbrp12be            34bd529e3b085e813e7471e5a5951423
+gbrp12le            14716b36ee4043158f24b49b6a723213
+gbrp14be            426ac36ea666041afd39f842dbdd683c
+gbrp14le            e0823115de7b2e44c25e1c59dd204ac1
+gbrp9be             0db6ce2fe6a7fc2d5c7d6d4f0decd112
+gbrp9le             00a1a9fe310753a28c0512568a317c67
+gray                4dd4ea934fdbf689fdcf665856c402ff
+gray16be            cd9c1367dabd2f1858ae4f31693e622f
+gray16le            4ef774c282280d7ed4780690df6e5cb4
+monob               07cffe7f5f25f39c3aa38866303791c6
+monow               f2d1bdb939813a49abd6348ecfbb2703
+nv12                6847b3f7141ca1e3c40d3a494f0e13cb
+nv21                e7a8e94001151e2bdd68a0ee7e4ac544
+rgb0                0d1dfb1edc9b4a7ad28dde9a1b0bee23
+rgb24               15781da8615974ed12b18f7439a25d6f
+rgb444be            19bc79cdbafee996eb48feea597d761e
+rgb444le            de61209ae25f005d357b68e0836c4739
+rgb48be             fa24415175a0759ac49949a948820f27
+rgb48le             82d5d55b03dfd9a74f0cc087793cdfc6
+rgb4_byte           7ec4d55df1bfb02ffa9956d85ade89f7
+rgb555be            34ef691ed2b6d22136c086d37bb0fefd
+rgb555le            04b20c057eed7dcaee1858d45500ba54
+rgb565be            077604cc5dc91008b018264db73c8f0c
+rgb565le            a97549f25e63dd0dd404db41bbe05c07
+rgb8                a35d3c3b9b87261c7417076a8b18fdb8
+rgba                8ca9c8db589615ebbaa964be4ce62d08
+uyvy422             8be40aded4b407ff66305911ba5ce2ce
+yuv410p             92112d85ba4f74cbd3044945c0f33402
+yuv411p             b6b22000e5275c92baf5afc417c32a70
+yuv420p             fca7fbbff753612a718ee13e1dfe2af2
+yuv420p10be         15c655b60ff5d212657e0620ed69fadf
+yuv420p10le         c9c71c78e00034af1b0fdcfe68615c6f
+yuv420p12be         a5377d262bd05698b2bbcfc8dd2b15ea
+yuv420p12le         7d076ea30985ecf2eb590041a45f2cc6
+yuv420p14be         7a33da52fed0ffdc7f90ebcb677dc155
+yuv420p14le         f431bf16d8204fb919ba0abf4ea54288
+yuv420p16be         254b78ba00a928d22cba98380546fe9d
+yuv420p16le         e6c182b47c3b57814d28248dbbaaea35
+yuv420p9be          b1eafb2e864fa86c08684d8dd4628535
+yuv420p9le          f07b2282c50f8eb6f138029d748eadfe
+yuv422p             ffc2693b9e1d39b59aabb9a7e1dffe05
+yuv422p10be         e83db7f2f485bea0ea808f22ffcdb7bc
+yuv422p10le         bfd8fbeb5d89ba3904514d835aa6947d
+yuv422p12be         5f31197795eda7998a0ec813496e57f1
+yuv422p12le         903939621d457a034c0181032164b3c1
+yuv422p14be         8d08189d27d3a97fbecec7edd690c691
+yuv422p14le         01b717875b85707185acd48ac75dd6f9
+yuv422p16be         0feb24228cc5ec3963dc0bde913d14be
+yuv422p16le         0d6fe6924f14e77b2fef02e7ad1c47c8
+yuv422p9be          003b2032a30281845dfb6f9a7ebccc71
+yuv422p9le          427c505eb27af0059aeafffd1a858189
+yuv440p             23b55dcf6c876f0c53cf46960b13e6a3
+yuv444p             7730197c0570d46493d50bc163244754
+yuv444p10be         74b13f67114ac0f92af7bb427d6335ae
+yuv444p10le         9ab09ae4acc46a2fa04fdbde1373a9f9
+yuv444p12be         76320bae89f10947e692b6ce1fa22b93
+yuv444p12le         a79e40c464df640ba97c13456616b25c
+yuv444p14be         de7f737796d1de38a8227511b91d3378
+yuv444p14le         7c27d1b7846beb3565ce086c7df1131f
+yuv444p16be         1d51af32b9e077bf1ad750c6a1787b2c
+yuv444p16le         94a936f571861f25f2539ba099cafd56
+yuv444p9be          384dd0aa411d00b2deb2363a9f345db9
+yuv444p9le          77758bad5ca383b3a698fdcb38a85f20
+yuva420p            24337fc952d7f9c633756549a7b94146
+yuva420p10be        f586830e7605b5bbc307f6f5c532958c
+yuva420p10le        7bc9e81d18021dbb7c96ceeef4a18090
+yuva420p16be        54362c9d57d26ead878b9eb05a523785
+yuva420p16le        af55baa12d11c0ac6c9065df730d81ef
+yuva420p9be         a290f1b1e1fe18ac22fed3535562ff98
+yuva420p9le         89d0fa6679548757044c0e1971c1cbfd
+yuva422p            e3fe9f137a37e1b3817fe8579d2d2acc
+yuva422p10be        4aa77b690225054f9b5c7ce7c66950e8
+yuva422p10le        e7c6538112fc1d9539f4635dedf52eae
+yuva422p16be        0e5a1b0b52d42f4f07d7e63dbe4ab83b
+yuva422p16le        5b3a1219d7224650929e6272693f1cd3
+yuva422p9be         9d6f936fa9666e2bcbada5188e2a4942
+yuva422p9le         0f97c4d357e103e7263705b918a37824
+yuva444p            fe4dbba35f355d68b6c254c06db1cbad
+yuva444p10be        3926a29639556a11acc95888e29517d6
+yuva444p10le        1b68842a69b3b9d5a23854217b410c69
+yuva444p16be        45ec67a0828aedf18f1ed54fcfb0ff83
+yuva444p16le        7b8e5963f19e6fe7fd409b34af014489
+yuva444p9be         6d2905a9e61ce4ff5b3d7b972a7333eb
+yuva444p9le         e2ffdb1d867a1b78f3bd38d600b17193
+yuvj420p            d1a8d9cf6b4035ac5d6439ab2754b09d
+yuvj422p            d20df6138cdf62d7f3b93eb1277827d6
+yuvj440p            17a24a86f279febaebb66d65509088e8
+yuvj444p            326bb83d1aec23d941894a1324984c56
+yuyv422             f9121733169ca5437e95e7600a7c5aea
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/overlay b/mythtv/external/FFmpeg/tests/ref/lavfi/overlay
deleted file mode 100644
index ca70370a02a..00000000000
--- a/mythtv/external/FFmpeg/tests/ref/lavfi/overlay
+++ /dev/null
@@ -1 +0,0 @@
-overlay             4e85d551db9e56e8faddc1fc70fd6a00
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/overlay_rgb b/mythtv/external/FFmpeg/tests/ref/lavfi/overlay_rgb
new file mode 100644
index 00000000000..ce4e30bba74
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/lavfi/overlay_rgb
@@ -0,0 +1 @@
+overlay_rgb         abea47d9e61d7eab40c4734294519524
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/overlay_yuv420 b/mythtv/external/FFmpeg/tests/ref/lavfi/overlay_yuv420
new file mode 100644
index 00000000000..3d12251f59b
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/lavfi/overlay_yuv420
@@ -0,0 +1 @@
+overlay_yuv420      4e85d551db9e56e8faddc1fc70fd6a00
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/overlay_yuv444 b/mythtv/external/FFmpeg/tests/ref/lavfi/overlay_yuv444
new file mode 100644
index 00000000000..b83e60590f1
--- /dev/null
+++ b/mythtv/external/FFmpeg/tests/ref/lavfi/overlay_yuv444
@@ -0,0 +1 @@
+overlay_yuv444      16215d0b4054a44bbe7f6c46bd97d235
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_copy b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_copy
index 340b3a9567f..68ec82837ac 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_copy
+++ b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_copy
@@ -15,6 +15,15 @@ bgr565be            13a36d6502be88fc0c2aec05b8d2d501
 bgr565le            ed027571692aecd522aa65a90cc7e09b
 bgr8                71ef789609c746c2e7e4be9dec29062c
 bgra                0364b074268682ea46168742a8239f7d
+gbrp                89d6e4b116e3bd542fa09a19a977ad16
+gbrp10be            5dc62e2d01fa7c19a57abe48246f2232
+gbrp10le            0cac205a304b59811ce30fcad49b3527
+gbrp12be            de1d2a6b1d189bce9b9a2cf322c31c24
+gbrp12le            e3267ef00bb48778df21a386416d2e14
+gbrp14be            7979d158b30c0b45db97aba2228d15fc
+gbrp14le            d32b6c73a820f9d03a779a996924893d
+gbrp9be             2478d1c27ae4ec94ec4b5e439128af0c
+gbrp9le             640240ca2663e48f0bacd8edb5242c7d
 gray                1e5e2b8548843a6898eedd9c974c422c
 gray16be            389f4e5a8ab413b3af32767b59ed7f9e
 gray16le            a1f912941247e45b394b9cf4f0e81130
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_hflip b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_hflip
index e696997d2c5..ee5c2d36ab8 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_hflip
+++ b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_hflip
@@ -1,5 +1,8 @@
+0bgr                03d8a8920dbb408218376baee8665649
+0rgb                6ee5f3b85ec38953df0762ddd0bdf561
 abgr                8ab842e280c8b31f66450e8951dfedfa
 argb                cdb6aa47939d49c0ff72537bfc8c82e0
+bgr0                1b0b59382ddbbf045be6b160b7df5881
 bgr24               5b64fd60e2050946b50da1f4945127fb
 bgr444be            b52c1b9d9dc02cb46c04e80d97139e60
 bgr444le            48172797fa65a25c0ad30ddc7e8f5bcb
@@ -12,10 +15,22 @@ bgr565be            3b464a00c619410eac7bdea9c96faf60
 bgr565le            4b4c708d4ad222f41734dce68e9d48b6
 bgr8                ad1db7a17cdfab2ede6f22c2415a3fbf
 bgra                85fa06ad9fd156c3179a647a2e741b60
+gbrp                95fde5b6a767cf8d2679a4a6d18fdbe7
+gbrp10be            5ddc834dbf2198f6b1af36c66b185e2c
+gbrp10le            04814cbb805b66e8e085c7db4a548deb
+gbrp12be            8184b00342421c366764c091e9174260
+gbrp12le            1519cba0b6ddd7ee3df7c97670f1cbd5
+gbrp14be            10872df155aab67a13b98ad162908896
+gbrp14le            5fd363517fca5ef0ac725d1c047f2e75
+gbrp9be             187c83736d4fe1d7c8491609debc8f86
+gbrp9le             5476b0787da2d928d98d4cda60537fb5
 gray                35b50e78d5d27255f43e642a404dd708
 gray16be            d206a080739d89cb7dc0009ad4082ed4
 gray16le            7ebcfd9401ba85e584230de8fc02986d
+nv12                719adbc47fa74e92f83150921917483f
+nv21                9c833b3ce53539d270e1f21e4319797b
 pal8                19c8735b23feeed18ec2d37913a5f3f8
+rgb0                ce26538ebe1ec09dec3dde5e4d8a1405
 rgb24               c2752464ac2b549268e9638745dba857
 rgb444be            85586541cc7eb12e05ff7162b12304c2
 rgb444le            670da20b82403e00609bf2c1f5611223
@@ -31,16 +46,60 @@ rgba                a37789c4df73c3bd8648ad1fe9d3f991
 yuv410p             a1280c2b9b562dba3c2d35a1e5fc4b23
 yuv411p             6bf10756ac5c7841db63a97106ff911b
 yuv420p             45f4a06481f2cd8e28fb29c7c151e110
+yuv420p10be         ddfef981d53de0f808173bb267203ca6
+yuv420p10le         966b8c55de4d8a12bdc8db3d9ad3ae6d
+yuv420p12be         735da68f3ac8380a993f46a460c02432
+yuv420p12le         3a71ae4e6a7b106b3e1532c6d148fa61
+yuv420p14be         d921d7b364d0a7bde183ba717a77f1d4
+yuv420p14le         ab410b636acd41234cc396967f66c859
 yuv420p16be         cde798cad650bcb087943442a399c8ea
 yuv420p16le         b7124c56605eeb12f3d13287ddc77f3a
+yuv420p9be          b0f6044fb40cf0ef41cc536311566cc6
+yuv420p9le          086f9320167a755faed18c0a3a36c0e6
 yuv422p             c3982fbb57e796881efedae11b8346de
+yuv422p10be         a3db158525c7794fd06b4d20e558e64d
+yuv422p10le         31cf611e502584fcf846d3ba2583028a
+yuv422p12be         8cafc31b579b168a71f7093a161b8023
+yuv422p12le         be83ffe86cb99ecfef76affb2b73d5b2
+yuv422p14be         96870c66856e2669095ccdea034558ab
+yuv422p14le         46dcb0160aa8ada4025b365873a78d6c
 yuv422p16be         4b96fb571e686185d96b4a97e3413d5f
 yuv422p16le         503bc49bace58dae1767173746a16056
+yuv422p9be          0ffc1bfde0b679e6e7b7e0c8c84e686a
+yuv422p9le          3c061cdb9f302c8f8806b409bd2b0aca
 yuv440p             44f78792c5766ab896fbe0d718976946
 yuv444p             a36b8ce12de27971b52e93267fe6583f
+yuv444p10be         90e94770d3eb4693b09925f549d7311e
+yuv444p10le         8a26fba7c2223d72cd5ad00c1941948f
+yuv444p12be         24bdad5d7ddca614da7d105e931c49e8
+yuv444p12le         a996cb8a1c062d2238b58a5db9b990dd
+yuv444p14be         a9f7dd66b6f54bbdbf176894b01d7422
+yuv444p14le         6204f763af4a0d26f41ddca1d1ae9741
 yuv444p16be         9370058632b2582ab7a21725ec4f4e1d
 yuv444p16le         0674c63a0e8debbfc010a2730da66a13
+yuv444p9be          b1327e7ca47a950ee99bd2a7e05f56d0
+yuv444p9le          2f89171f0470eefa9f89fdc43874dc1d
 yuva420p            a62cf0a72905b54a7ef10fcaeff723bc
+yuva420p10be        602b6a8c0b16ce2b55ddcae443e75dac
+yuva420p10le        1c086d4ee0619ac65cb5a69481b981ca
+yuva420p16be        51c45f4227ba86159f46c65783d64cef
+yuva420p16le        e87030429a965f2ddc8f07ca49014573
+yuva420p9be         a48309403dc66dc5242cac19cc7598e5
+yuva420p9le         ae2dcb326eb3a2ff170f498077ae5624
+yuva422p            6e7c30ea252a41b70d26250f624ab284
+yuva422p10be        e0ee8576f9328ca4ec174a8c084f2235
+yuva422p10le        b489c203b9b0ebc42adb794bb10a3c4f
+yuva422p16be        550b1d2ecbc3d5f50041816090d62a02
+yuva422p16le        73a426eb63685247ea037389595cb43a
+yuva422p9be         c65251c422cd3c81ff5d97d207312292
+yuva422p9le         3405924773c6bdc42325a8a1ff658595
+yuva444p            e32ba5dcb01ba848e7dead04112b1aa5
+yuva444p10be        97549388c7f9fbc1425b1663b46c43d1
+yuva444p10le        0b88bed194caea2fa06f458034b1b90e
+yuva444p16be        2dd545e4ddb0f134322eee1c1de4c2ff
+yuva444p16le        1e144cc9ea16429c1655c67e2f12f5c9
+yuva444p9be         e37fa0743bf720fbe31605714d7f7ad6
+yuva444p9le         9bd4083c1384a55e91f02630161dc4c3
 yuvj420p            86370b945c5d19d809ee92386d476a53
 yuvj422p            d3bda08bd4b92a256a8ec8432c4767d1
 yuvj440p            dbae7083c82f20a38fc55e6f8bc374bc
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_null b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_null
index 340b3a9567f..68ec82837ac 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_null
+++ b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_null
@@ -15,6 +15,15 @@ bgr565be            13a36d6502be88fc0c2aec05b8d2d501
 bgr565le            ed027571692aecd522aa65a90cc7e09b
 bgr8                71ef789609c746c2e7e4be9dec29062c
 bgra                0364b074268682ea46168742a8239f7d
+gbrp                89d6e4b116e3bd542fa09a19a977ad16
+gbrp10be            5dc62e2d01fa7c19a57abe48246f2232
+gbrp10le            0cac205a304b59811ce30fcad49b3527
+gbrp12be            de1d2a6b1d189bce9b9a2cf322c31c24
+gbrp12le            e3267ef00bb48778df21a386416d2e14
+gbrp14be            7979d158b30c0b45db97aba2228d15fc
+gbrp14le            d32b6c73a820f9d03a779a996924893d
+gbrp9be             2478d1c27ae4ec94ec4b5e439128af0c
+gbrp9le             640240ca2663e48f0bacd8edb5242c7d
 gray                1e5e2b8548843a6898eedd9c974c422c
 gray16be            389f4e5a8ab413b3af32767b59ed7f9e
 gray16le            a1f912941247e45b394b9cf4f0e81130
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_pad b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_pad
index 9c319744e0d..192ff6a430f 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_pad
+++ b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_pad
@@ -5,6 +5,7 @@ argb                e5fbb7bb282a80897b8f730627f68876
 bgr0                c55368036cccbb0af471d6bd82abe02a
 bgr24               67f9fd70dc6d9896b7122976b33932b4
 bgra                c8dd017b5a3b55e8b9d0ac1cdcf327bd
+gbrp                74f83deee9866bbdce3f91fa2aeddaaa
 gray                b1abadae3718522aa57a7972da8cbe17
 rgb0                b1977b45634c4db58a183a07feb2acff
 rgb24               e73de9dc0fdd78f4853c168603cc7aba
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_pixdesctest b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_pixdesctest
index 95db3de59d5..05d5e0f7356 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_pixdesctest
+++ b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_pixdesctest
@@ -15,6 +15,15 @@ bgr565be            13a36d6502be88fc0c2aec05b8d2d501
 bgr565le            ed027571692aecd522aa65a90cc7e09b
 bgr8                71ef789609c746c2e7e4be9dec29062c
 bgra                0364b074268682ea46168742a8239f7d
+gbrp                89d6e4b116e3bd542fa09a19a977ad16
+gbrp10be            5dc62e2d01fa7c19a57abe48246f2232
+gbrp10le            0cac205a304b59811ce30fcad49b3527
+gbrp12be            de1d2a6b1d189bce9b9a2cf322c31c24
+gbrp12le            e3267ef00bb48778df21a386416d2e14
+gbrp14be            7979d158b30c0b45db97aba2228d15fc
+gbrp14le            d32b6c73a820f9d03a779a996924893d
+gbrp9be             2478d1c27ae4ec94ec4b5e439128af0c
+gbrp9le             640240ca2663e48f0bacd8edb5242c7d
 gray                1e5e2b8548843a6898eedd9c974c422c
 gray16be            389f4e5a8ab413b3af32767b59ed7f9e
 gray16le            a1f912941247e45b394b9cf4f0e81130
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_scale b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_scale
index a85fbdd9b85..9bc3ced29ac 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_scale
+++ b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_scale
@@ -15,6 +15,15 @@ bgr565be            fca6f07daf23d9dd84381dd4c9afd959
 bgr565le            f524e9f16bdd68b247dbcb621e543fc0
 bgr8                68a3a395043dc57335ad1f8e891229c5
 bgra                3eaf5489b8aa13a3388aad3751b597bf
+gbrp                7b83ae32c1f76bd634e50f4797a74e92
+gbrp10be            77dae432c42fad019c286753b0e4b0a8
+gbrp10le            7d3e7341423b1206e8a6a3a02b48b5d7
+gbrp12be            2c237c413e765024eb3f73d8c5e03df8
+gbrp12le            9a0c9eda1f16d640663c729d4bb88024
+gbrp14be            2b4f1928a5ef53d0a216b3b10fa11ca0
+gbrp14le            47100ec39fad45579de1dff56fe17117
+gbrp9be             c345137de0aa4b0536a00009e8e11267
+gbrp9le             b798662b2ba4cdf21ad6a6d4c1fe1b72
 gray                045c35e6cc7d41460f2b96b3e254deab
 gray16be            70064f9acdc5e3935ccda67e765bf2fb
 gray16le            578241fb43029e5ae841a3c94d940dce
diff --git a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_vflip b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_vflip
index 89ce078074f..7990c3ec343 100644
--- a/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_vflip
+++ b/mythtv/external/FFmpeg/tests/ref/lavfi/pixfmts_vflip
@@ -15,6 +15,15 @@ bgr565be            7100c2ddfee42e7efafec1ccefecf7c6
 bgr565le            9fab295d966386d4ef99d5b43066da47
 bgr8                275ce12eeb05de67a6915f67cbb43ce5
 bgra                d29c35871248c476c366e678db580982
+gbrp                7852e9bbe52cfad9bab8081a5c7a5a31
+gbrp10be            f591c6c98396baf3242837827081f2f7
+gbrp10le            c5edb9bb566edbc8c478595ac6ab070f
+gbrp12be            c61c19ad1bcca18719dd071e2cb77287
+gbrp12le            334a6c802ae0e15d9e0950c27ce4a457
+gbrp14be            e24459d3b4a1e9c56ec3658c525b7a32
+gbrp14le            99207ef7c7dcb1d1369dc3fe3b5dc261
+gbrp9be             1daea1677f8a62c5a1ef8959c5e0e4b0
+gbrp9le             e3cca50b844e7dd326eadf6e38fab84b
 gray                a53528cdf80ed31c9897042a2ea16618
 gray16be            9b23f3e79c54a6ccb62e0135a32e3045
 gray16le            93cfa8fbb2a86ead275ce1817444e6d5
diff --git a/mythtv/external/FFmpeg/tests/ref/seek/lavf-bmp b/mythtv/external/FFmpeg/tests/ref/seek/lavf-bmp
index d60729b24c1..0f0b152fb8e 100644
--- a/mythtv/external/FFmpeg/tests/ref/seek/lavf-bmp
+++ b/mythtv/external/FFmpeg/tests/ref/seek/lavf-bmp
@@ -5,7 +5,8 @@ ret:-EINVAL    st: 0 flags:0  ts: 0.800000
 ret:-EINVAL    st: 0 flags:1  ts:-0.320000
 ret:-EINVAL    st:-1 flags:0  ts: 2.576668
 ret:-EINVAL    st:-1 flags:1  ts: 1.470835
-ret:-EINVAL    st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:     -1 size:304182
 ret:-EINVAL    st: 0 flags:1  ts:-0.760000
 ret:-EINVAL    st:-1 flags:0  ts: 2.153336
 ret:-EINVAL    st:-1 flags:1  ts: 1.047503
@@ -16,12 +17,14 @@ ret:-EINVAL    st:-1 flags:1  ts: 0.624171
 ret:-EINVAL    st: 0 flags:0  ts:-0.480000
 ret:-EINVAL    st: 0 flags:1  ts: 2.400000
 ret:-EINVAL    st:-1 flags:0  ts: 1.306672
-ret:-EINVAL    st:-1 flags:1  ts: 0.200839
+ret: 0         st:-1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:     -1 size:304182
 ret:-EINVAL    st: 0 flags:0  ts:-0.920000
 ret:-EINVAL    st: 0 flags:1  ts: 2.000000
 ret:-EINVAL    st:-1 flags:0  ts: 0.883340
 ret:-EINVAL    st:-1 flags:1  ts:-0.222493
 ret:-EINVAL    st: 0 flags:0  ts: 2.680000
 ret:-EINVAL    st: 0 flags:1  ts: 1.560000
-ret:-EINVAL    st:-1 flags:0  ts: 0.460008
+ret: 0         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:     -1 size:304182
 ret:-EINVAL    st:-1 flags:1  ts:-0.645825
diff --git a/mythtv/external/FFmpeg/tests/ref/seek/lavf-jpg b/mythtv/external/FFmpeg/tests/ref/seek/lavf-jpg
index 88964cad053..4f3a14ca84d 100644
--- a/mythtv/external/FFmpeg/tests/ref/seek/lavf-jpg
+++ b/mythtv/external/FFmpeg/tests/ref/seek/lavf-jpg
@@ -5,7 +5,8 @@ ret:-EINVAL    st: 0 flags:0  ts: 0.800000
 ret:-EINVAL    st: 0 flags:1  ts:-0.320000
 ret:-EINVAL    st:-1 flags:0  ts: 2.576668
 ret:-EINVAL    st:-1 flags:1  ts: 1.470835
-ret:-EINVAL    st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:     -1 size: 27771
 ret:-EINVAL    st: 0 flags:1  ts:-0.760000
 ret:-EINVAL    st:-1 flags:0  ts: 2.153336
 ret:-EINVAL    st:-1 flags:1  ts: 1.047503
@@ -16,12 +17,14 @@ ret:-EINVAL    st:-1 flags:1  ts: 0.624171
 ret:-EINVAL    st: 0 flags:0  ts:-0.480000
 ret:-EINVAL    st: 0 flags:1  ts: 2.400000
 ret:-EINVAL    st:-1 flags:0  ts: 1.306672
-ret:-EINVAL    st:-1 flags:1  ts: 0.200839
+ret: 0         st:-1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:     -1 size: 28197
 ret:-EINVAL    st: 0 flags:0  ts:-0.920000
 ret:-EINVAL    st: 0 flags:1  ts: 2.000000
 ret:-EINVAL    st:-1 flags:0  ts: 0.883340
 ret:-EINVAL    st:-1 flags:1  ts:-0.222493
 ret:-EINVAL    st: 0 flags:0  ts: 2.680000
 ret:-EINVAL    st: 0 flags:1  ts: 1.560000
-ret:-EINVAL    st:-1 flags:0  ts: 0.460008
+ret: 0         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:     -1 size: 27950
 ret:-EINVAL    st:-1 flags:1  ts:-0.645825
diff --git a/mythtv/external/FFmpeg/tests/ref/seek/lavf-ogg b/mythtv/external/FFmpeg/tests/ref/seek/lavf-ogg
index 2898d10a7d4..583526ef59b 100644
--- a/mythtv/external/FFmpeg/tests/ref/seek/lavf-ogg
+++ b/mythtv/external/FFmpeg/tests/ref/seek/lavf-ogg
@@ -1,35 +1,53 @@
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
 ret: 0         st:-1 flags:0  ts:-1.000000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
-ret:-1         st:-1 flags:1  ts: 1.894167
-ret:-1         st: 0 flags:0  ts: 0.788345
+ret: 0         st:-1 flags:1  ts: 1.894167
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
+ret: 0         st: 0 flags:0  ts: 0.788345
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
 ret: 0         st: 0 flags:1  ts:-0.317506
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
-ret:-1         st:-1 flags:0  ts: 2.576668
-ret:-1         st:-1 flags:1  ts: 1.470835
-ret:-1         st: 0 flags:0  ts: 0.365011
+ret: 0         st:-1 flags:0  ts: 2.576668
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
+ret: 0         st:-1 flags:1  ts: 1.470835
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
+ret: 0         st: 0 flags:0  ts: 0.365011
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
 ret: 0         st: 0 flags:1  ts:-0.740839
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
-ret:-1         st:-1 flags:0  ts: 2.153336
-ret:-1         st:-1 flags:1  ts: 1.047503
+ret: 0         st:-1 flags:0  ts: 2.153336
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
+ret: 0         st:-1 flags:1  ts: 1.047503
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
 ret: 0         st: 0 flags:0  ts:-0.058322
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
-ret:-1         st: 0 flags:1  ts: 2.835828
-ret:-1         st:-1 flags:0  ts: 1.730004
-ret:-1         st:-1 flags:1  ts: 0.624171
+ret: 0         st: 0 flags:1  ts: 2.835828
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
+ret: 0         st:-1 flags:0  ts: 1.730004
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
+ret: 0         st:-1 flags:1  ts: 0.624171
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
 ret: 0         st: 0 flags:0  ts:-0.481655
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
-ret:-1         st: 0 flags:1  ts: 2.412494
-ret:-1         st:-1 flags:0  ts: 1.306672
-ret:-1         st:-1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1  ts: 2.412494
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
+ret: 0         st:-1 flags:0  ts: 1.306672
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
+ret: 0         st:-1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
 ret: 0         st: 0 flags:0  ts:-0.904989
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
-ret:-1         st: 0 flags:1  ts: 1.989184
-ret:-1         st:-1 flags:0  ts: 0.883340
+ret: 0         st: 0 flags:1  ts: 1.989184
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
+ret: 0         st:-1 flags:0  ts: 0.883340
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
 ret: 0         st:-1 flags:1  ts:-0.222493
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
-ret:-1         st: 0 flags:0  ts: 2.671678
-ret:-1         st: 0 flags:1  ts: 1.565850
-ret:-1         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:0  ts: 2.671678
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
+ret: 0         st: 0 flags:1  ts: 1.565850
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
+ret: 0         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
 ret: 0         st:-1 flags:1  ts:-0.645825
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    143 size:  1364
diff --git a/mythtv/external/FFmpeg/tests/ref/seek/lavf-pcx b/mythtv/external/FFmpeg/tests/ref/seek/lavf-pcx
index 418674f7a23..ba21627e86b 100644
--- a/mythtv/external/FFmpeg/tests/ref/seek/lavf-pcx
+++ b/mythtv/external/FFmpeg/tests/ref/seek/lavf-pcx
@@ -5,7 +5,8 @@ ret:-EINVAL    st: 0 flags:0  ts: 0.800000
 ret:-EINVAL    st: 0 flags:1  ts:-0.320000
 ret:-EINVAL    st:-1 flags:0  ts: 2.576668
 ret:-EINVAL    st:-1 flags:1  ts: 1.470835
-ret:-EINVAL    st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:     -1 size:363107
 ret:-EINVAL    st: 0 flags:1  ts:-0.760000
 ret:-EINVAL    st:-1 flags:0  ts: 2.153336
 ret:-EINVAL    st:-1 flags:1  ts: 1.047503
@@ -16,12 +17,14 @@ ret:-EINVAL    st:-1 flags:1  ts: 0.624171
 ret:-EINVAL    st: 0 flags:0  ts:-0.480000
 ret:-EINVAL    st: 0 flags:1  ts: 2.400000
 ret:-EINVAL    st:-1 flags:0  ts: 1.306672
-ret:-EINVAL    st:-1 flags:1  ts: 0.200839
+ret: 0         st:-1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:     -1 size:364760
 ret:-EINVAL    st: 0 flags:0  ts:-0.920000
 ret:-EINVAL    st: 0 flags:1  ts: 2.000000
 ret:-EINVAL    st:-1 flags:0  ts: 0.883340
 ret:-EINVAL    st:-1 flags:1  ts:-0.222493
 ret:-EINVAL    st: 0 flags:0  ts: 2.680000
 ret:-EINVAL    st: 0 flags:1  ts: 1.560000
-ret:-EINVAL    st:-1 flags:0  ts: 0.460008
+ret: 0         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:     -1 size:362983
 ret:-EINVAL    st:-1 flags:1  ts:-0.645825
diff --git a/mythtv/external/FFmpeg/tests/ref/seek/lavf-pgm b/mythtv/external/FFmpeg/tests/ref/seek/lavf-pgm
index 2836367b041..ceac0085bc7 100644
--- a/mythtv/external/FFmpeg/tests/ref/seek/lavf-pgm
+++ b/mythtv/external/FFmpeg/tests/ref/seek/lavf-pgm
@@ -5,7 +5,8 @@ ret:-EINVAL    st: 0 flags:0  ts: 0.800000
 ret:-EINVAL    st: 0 flags:1  ts:-0.320000
 ret:-EINVAL    st:-1 flags:0  ts: 2.576668
 ret:-EINVAL    st:-1 flags:1  ts: 1.470835
-ret:-EINVAL    st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:     -1 size:101391
 ret:-EINVAL    st: 0 flags:1  ts:-0.760000
 ret:-EINVAL    st:-1 flags:0  ts: 2.153336
 ret:-EINVAL    st:-1 flags:1  ts: 1.047503
@@ -16,12 +17,14 @@ ret:-EINVAL    st:-1 flags:1  ts: 0.624171
 ret:-EINVAL    st: 0 flags:0  ts:-0.480000
 ret:-EINVAL    st: 0 flags:1  ts: 2.400000
 ret:-EINVAL    st:-1 flags:0  ts: 1.306672
-ret:-EINVAL    st:-1 flags:1  ts: 0.200839
+ret: 0         st:-1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:     -1 size:101391
 ret:-EINVAL    st: 0 flags:0  ts:-0.920000
 ret:-EINVAL    st: 0 flags:1  ts: 2.000000
 ret:-EINVAL    st:-1 flags:0  ts: 0.883340
 ret:-EINVAL    st:-1 flags:1  ts:-0.222493
 ret:-EINVAL    st: 0 flags:0  ts: 2.680000
 ret:-EINVAL    st: 0 flags:1  ts: 1.560000
-ret:-EINVAL    st:-1 flags:0  ts: 0.460008
+ret: 0         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:     -1 size:101391
 ret:-EINVAL    st:-1 flags:1  ts:-0.645825
diff --git a/mythtv/external/FFmpeg/tests/ref/seek/lavf-ppm b/mythtv/external/FFmpeg/tests/ref/seek/lavf-ppm
index 6376b5ec4ab..6d53ce06e6a 100644
--- a/mythtv/external/FFmpeg/tests/ref/seek/lavf-ppm
+++ b/mythtv/external/FFmpeg/tests/ref/seek/lavf-ppm
@@ -5,7 +5,8 @@ ret:-EINVAL    st: 0 flags:0  ts: 0.800000
 ret:-EINVAL    st: 0 flags:1  ts:-0.320000
 ret:-EINVAL    st:-1 flags:0  ts: 2.576668
 ret:-EINVAL    st:-1 flags:1  ts: 1.470835
-ret:-EINVAL    st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:     -1 size:304143
 ret:-EINVAL    st: 0 flags:1  ts:-0.760000
 ret:-EINVAL    st:-1 flags:0  ts: 2.153336
 ret:-EINVAL    st:-1 flags:1  ts: 1.047503
@@ -16,12 +17,14 @@ ret:-EINVAL    st:-1 flags:1  ts: 0.624171
 ret:-EINVAL    st: 0 flags:0  ts:-0.480000
 ret:-EINVAL    st: 0 flags:1  ts: 2.400000
 ret:-EINVAL    st:-1 flags:0  ts: 1.306672
-ret:-EINVAL    st:-1 flags:1  ts: 0.200839
+ret: 0         st:-1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:     -1 size:304143
 ret:-EINVAL    st: 0 flags:0  ts:-0.920000
 ret:-EINVAL    st: 0 flags:1  ts: 2.000000
 ret:-EINVAL    st:-1 flags:0  ts: 0.883340
 ret:-EINVAL    st:-1 flags:1  ts:-0.222493
 ret:-EINVAL    st: 0 flags:0  ts: 2.680000
 ret:-EINVAL    st: 0 flags:1  ts: 1.560000
-ret:-EINVAL    st:-1 flags:0  ts: 0.460008
+ret: 0         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:     -1 size:304143
 ret:-EINVAL    st:-1 flags:1  ts:-0.645825
diff --git a/mythtv/external/FFmpeg/tests/ref/seek/lavf-sgi b/mythtv/external/FFmpeg/tests/ref/seek/lavf-sgi
index b2f605ad94a..b07132a6695 100644
--- a/mythtv/external/FFmpeg/tests/ref/seek/lavf-sgi
+++ b/mythtv/external/FFmpeg/tests/ref/seek/lavf-sgi
@@ -5,7 +5,8 @@ ret:-EINVAL    st: 0 flags:0  ts: 0.800000
 ret:-EINVAL    st: 0 flags:1  ts:-0.320000
 ret:-EINVAL    st:-1 flags:0  ts: 2.576668
 ret:-EINVAL    st:-1 flags:1  ts: 1.470835
-ret:-EINVAL    st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:     -1 size:308572
 ret:-EINVAL    st: 0 flags:1  ts:-0.760000
 ret:-EINVAL    st:-1 flags:0  ts: 2.153336
 ret:-EINVAL    st:-1 flags:1  ts: 1.047503
@@ -16,12 +17,14 @@ ret:-EINVAL    st:-1 flags:1  ts: 0.624171
 ret:-EINVAL    st: 0 flags:0  ts:-0.480000
 ret:-EINVAL    st: 0 flags:1  ts: 2.400000
 ret:-EINVAL    st:-1 flags:0  ts: 1.306672
-ret:-EINVAL    st:-1 flags:1  ts: 0.200839
+ret: 0         st:-1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:     -1 size:308294
 ret:-EINVAL    st: 0 flags:0  ts:-0.920000
 ret:-EINVAL    st: 0 flags:1  ts: 2.000000
 ret:-EINVAL    st:-1 flags:0  ts: 0.883340
 ret:-EINVAL    st:-1 flags:1  ts:-0.222493
 ret:-EINVAL    st: 0 flags:0  ts: 2.680000
 ret:-EINVAL    st: 0 flags:1  ts: 1.560000
-ret:-EINVAL    st:-1 flags:0  ts: 0.460008
+ret: 0         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:     -1 size:307773
 ret:-EINVAL    st:-1 flags:1  ts:-0.645825
diff --git a/mythtv/external/FFmpeg/tests/ref/seek/lavf-tga b/mythtv/external/FFmpeg/tests/ref/seek/lavf-tga
index 8f9075364f7..ee7552a15d2 100644
--- a/mythtv/external/FFmpeg/tests/ref/seek/lavf-tga
+++ b/mythtv/external/FFmpeg/tests/ref/seek/lavf-tga
@@ -5,7 +5,8 @@ ret:-EINVAL    st: 0 flags:0  ts: 0.800000
 ret:-EINVAL    st: 0 flags:1  ts:-0.320000
 ret:-EINVAL    st:-1 flags:0  ts: 2.576668
 ret:-EINVAL    st:-1 flags:1  ts: 1.470835
-ret:-EINVAL    st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:     -1 size:304172
 ret:-EINVAL    st: 0 flags:1  ts:-0.760000
 ret:-EINVAL    st:-1 flags:0  ts: 2.153336
 ret:-EINVAL    st:-1 flags:1  ts: 1.047503
@@ -16,12 +17,14 @@ ret:-EINVAL    st:-1 flags:1  ts: 0.624171
 ret:-EINVAL    st: 0 flags:0  ts:-0.480000
 ret:-EINVAL    st: 0 flags:1  ts: 2.400000
 ret:-EINVAL    st:-1 flags:0  ts: 1.306672
-ret:-EINVAL    st:-1 flags:1  ts: 0.200839
+ret: 0         st:-1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:     -1 size:304172
 ret:-EINVAL    st: 0 flags:0  ts:-0.920000
 ret:-EINVAL    st: 0 flags:1  ts: 2.000000
 ret:-EINVAL    st:-1 flags:0  ts: 0.883340
 ret:-EINVAL    st:-1 flags:1  ts:-0.222493
 ret:-EINVAL    st: 0 flags:0  ts: 2.680000
 ret:-EINVAL    st: 0 flags:1  ts: 1.560000
-ret:-EINVAL    st:-1 flags:0  ts: 0.460008
+ret: 0         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:     -1 size:304172
 ret:-EINVAL    st:-1 flags:1  ts:-0.645825
diff --git a/mythtv/external/FFmpeg/tests/ref/seek/lavf-tiff b/mythtv/external/FFmpeg/tests/ref/seek/lavf-tiff
index 1b49f2f2e79..0d9fb044848 100644
--- a/mythtv/external/FFmpeg/tests/ref/seek/lavf-tiff
+++ b/mythtv/external/FFmpeg/tests/ref/seek/lavf-tiff
@@ -5,7 +5,8 @@ ret:-EINVAL    st: 0 flags:0  ts: 0.800000
 ret:-EINVAL    st: 0 flags:1  ts:-0.320000
 ret:-EINVAL    st:-1 flags:0  ts: 2.576668
 ret:-EINVAL    st:-1 flags:1  ts: 1.470835
-ret:-EINVAL    st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:0  ts: 0.360000
+ret: 0         st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:     -1 size:307150
 ret:-EINVAL    st: 0 flags:1  ts:-0.760000
 ret:-EINVAL    st:-1 flags:0  ts: 2.153336
 ret:-EINVAL    st:-1 flags:1  ts: 1.047503
@@ -16,12 +17,14 @@ ret:-EINVAL    st:-1 flags:1  ts: 0.624171
 ret:-EINVAL    st: 0 flags:0  ts:-0.480000
 ret:-EINVAL    st: 0 flags:1  ts: 2.400000
 ret:-EINVAL    st:-1 flags:0  ts: 1.306672
-ret:-EINVAL    st:-1 flags:1  ts: 0.200839
+ret: 0         st:-1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:     -1 size:307140
 ret:-EINVAL    st: 0 flags:0  ts:-0.920000
 ret:-EINVAL    st: 0 flags:1  ts: 2.000000
 ret:-EINVAL    st:-1 flags:0  ts: 0.883340
 ret:-EINVAL    st:-1 flags:1  ts:-0.222493
 ret:-EINVAL    st: 0 flags:0  ts: 2.680000
 ret:-EINVAL    st: 0 flags:1  ts: 1.560000
-ret:-EINVAL    st:-1 flags:0  ts: 0.460008
+ret: 0         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:     -1 size:307140
 ret:-EINVAL    st:-1 flags:1  ts:-0.645825
diff --git a/mythtv/external/FFmpeg/tests/ref/seek/vsynth2-wmv2 b/mythtv/external/FFmpeg/tests/ref/seek/vsynth2-wmv2
index 8b9d3f336c2..a29f0d4de51 100644
--- a/mythtv/external/FFmpeg/tests/ref/seek/vsynth2-wmv2
+++ b/mythtv/external/FFmpeg/tests/ref/seek/vsynth2-wmv2
@@ -2,45 +2,45 @@ ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:   5652 size:  8917
 ret: 0         st:-1 flags:0  ts:-1.000000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:   5652 size:  8917
 ret: 0         st:-1 flags:1  ts: 1.894167
-ret: 0         st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos:  83790 size: 11169
+ret: 0         st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos:  83764 size: 11169
 ret: 0         st: 0 flags:0  ts: 0.800000
-ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:  54572 size:  9989
+ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:  54534 size:  9989
 ret:-1         st: 0 flags:1  ts:-0.320000
 ret:-1         st:-1 flags:0  ts: 2.576668
 ret: 0         st:-1 flags:1  ts: 1.470835
-ret: 0         st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos:  83790 size: 11169
+ret: 0         st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos:  83764 size: 11169
 ret: 0         st: 0 flags:0  ts: 0.360000
-ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:  29632 size:  8839
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:  29588 size:  8839
 ret:-1         st: 0 flags:1  ts:-0.760000
 ret:-1         st:-1 flags:0  ts: 2.153336
 ret: 0         st:-1 flags:1  ts: 1.047503
-ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:  54572 size:  9989
+ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:  54534 size:  9989
 ret: 0         st: 0 flags:0  ts:-0.040000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:   5652 size:  8917
 ret: 0         st: 0 flags:1  ts: 2.840000
-ret: 0         st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 116044 size: 11554
+ret: 0         st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 116066 size: 11554
 ret: 0         st:-1 flags:0  ts: 1.730004
-ret: 0         st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 116044 size: 11554
+ret: 0         st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 116066 size: 11554
 ret: 0         st:-1 flags:1  ts: 0.624171
-ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:  29632 size:  8839
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:  29588 size:  8839
 ret: 0         st: 0 flags:0  ts:-0.480000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:   5652 size:  8917
 ret: 0         st: 0 flags:1  ts: 2.400000
-ret: 0         st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 116044 size: 11554
+ret: 0         st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 116066 size: 11554
 ret: 0         st:-1 flags:0  ts: 1.306672
-ret: 0         st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos:  83790 size: 11169
+ret: 0         st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos:  83764 size: 11169
 ret: 0         st:-1 flags:1  ts: 0.200839
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:   5652 size:  8917
 ret: 0         st: 0 flags:0  ts:-0.920000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:   5652 size:  8917
 ret: 0         st: 0 flags:1  ts: 2.000000
-ret: 0         st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 116044 size: 11554
+ret: 0         st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 116066 size: 11554
 ret: 0         st:-1 flags:0  ts: 0.883340
-ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:  54572 size:  9989
+ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:  54534 size:  9989
 ret:-1         st:-1 flags:1  ts:-0.222493
 ret:-1         st: 0 flags:0  ts: 2.680000
 ret: 0         st: 0 flags:1  ts: 1.560000
-ret: 0         st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos:  83790 size: 11169
+ret: 0         st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos:  83764 size: 11169
 ret: 0         st:-1 flags:0  ts: 0.460008
-ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:  29632 size:  8839
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:  29588 size:  8839
 ret:-1         st:-1 flags:1  ts:-0.645825
diff --git a/mythtv/external/FFmpeg/tests/ref/vsynth/vsynth1-wmv2 b/mythtv/external/FFmpeg/tests/ref/vsynth/vsynth1-wmv2
index 79a1302305a..872ffc91962 100644
--- a/mythtv/external/FFmpeg/tests/ref/vsynth/vsynth1-wmv2
+++ b/mythtv/external/FFmpeg/tests/ref/vsynth/vsynth1-wmv2
@@ -1,4 +1,4 @@
-532f99495482015c12a2773ec1065a4d *tests/data/fate/vsynth1-wmv2.avi
-659832 tests/data/fate/vsynth1-wmv2.avi
-3354066ebdd8cd8098394be2384744e7 *tests/data/fate/vsynth1-wmv2.out.rawvideo
-stddev:    7.97 PSNR: 30.09 MAXDIFF:  110 bytes:  7603200/  7603200
+4ab9357e6369c81fecb1ebcbc7551f0c *tests/data/fate/vsynth1-wmv2.avi
+659138 tests/data/fate/vsynth1-wmv2.avi
+8a6061ef825e79d887705db656d51247 *tests/data/fate/vsynth1-wmv2.out.rawvideo
+stddev:    7.97 PSNR: 30.09 MAXDIFF:  105 bytes:  7603200/  7603200
diff --git a/mythtv/external/FFmpeg/tests/ref/vsynth/vsynth2-wmv2 b/mythtv/external/FFmpeg/tests/ref/vsynth/vsynth2-wmv2
index 41beb4eb5e8..5de48986fbb 100644
--- a/mythtv/external/FFmpeg/tests/ref/vsynth/vsynth2-wmv2
+++ b/mythtv/external/FFmpeg/tests/ref/vsynth/vsynth2-wmv2
@@ -1,4 +1,4 @@
-f2a29f4e98a526e104067ca381716e47 *tests/data/fate/vsynth2-wmv2.avi
-129834 tests/data/fate/vsynth2-wmv2.avi
-dec44e3c04db4fef49a7728f164d9159 *tests/data/fate/vsynth2-wmv2.out.rawvideo
-stddev:    5.33 PSNR: 33.60 MAXDIFF:   77 bytes:  7603200/  7603200
+1b0e968e180346914c11875f4eec57eb *tests/data/fate/vsynth2-wmv2.avi
+129852 tests/data/fate/vsynth2-wmv2.avi
+b4de16a0d302c52702f7a4362da989bc *tests/data/fate/vsynth2-wmv2.out.rawvideo
+stddev:    5.33 PSNR: 33.59 MAXDIFF:   77 bytes:  7603200/  7603200
diff --git a/mythtv/external/FFmpeg/tools/ffescape.c b/mythtv/external/FFmpeg/tools/ffescape.c
index d777fe4572d..0530d28c6d6 100644
--- a/mythtv/external/FFmpeg/tools/ffescape.c
+++ b/mythtv/external/FFmpeg/tools/ffescape.c
@@ -42,80 +42,16 @@ static void usage(void)
     printf("\n"
            "Options:\n"
            "-e                echo each input line on output\n"
+           "-f flag           select an escape flag, can assume the values 'whitespace' and 'strict'\n"
            "-h                print this help\n"
            "-i INFILE         set INFILE as input file, stdin if omitted\n"
            "-l LEVEL          set the number of escaping levels, 1 if omitted\n"
-           "-m ESCAPE_MODE    select escape mode between 'full', 'lazy', 'quote', default is 'lazy'\n"
+           "-m ESCAPE_MODE    select escape mode between 'auto', 'backslash', 'quote'\n"
            "-o OUTFILE        set OUTFILE as output file, stdout if omitted\n"
            "-p PROMPT         set output prompt, is '=> ' by default\n"
            "-s SPECIAL_CHARS  set the list of special characters\n");
 }
 
-#define WHITESPACES " \n\t"
-
-enum EscapeMode {
-    ESCAPE_MODE_FULL,
-    ESCAPE_MODE_LAZY,
-    ESCAPE_MODE_QUOTE,
-};
-
-static int escape(char **dst, const char *src, const char *special_chars,
-                  enum EscapeMode mode)
-{
-    AVBPrint dstbuf;
-
-    av_bprint_init(&dstbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
-
-    switch (mode) {
-    case ESCAPE_MODE_FULL:
-    case ESCAPE_MODE_LAZY:
-        /* \-escape characters */
-
-        if (mode == ESCAPE_MODE_LAZY && strchr(WHITESPACES, *src))
-            av_bprintf(&dstbuf, "\\%c", *src++);
-
-        for (; *src; src++) {
-            if ((special_chars && strchr(special_chars, *src)) ||
-                strchr("'\\", *src) ||
-                (mode == ESCAPE_MODE_FULL && strchr(WHITESPACES, *src)))
-                av_bprintf(&dstbuf, "\\%c", *src);
-            else
-                av_bprint_chars(&dstbuf, *src, 1);
-        }
-
-        if (mode == ESCAPE_MODE_LAZY && strchr(WHITESPACES, dstbuf.str[dstbuf.len-1])) {
-            char c = dstbuf.str[dstbuf.len-1];
-            dstbuf.str[dstbuf.len-1] = '\\';
-            av_bprint_chars(&dstbuf, c, 1);
-        }
-        break;
-
-    case ESCAPE_MODE_QUOTE:
-        /* enclose between '' the string */
-        av_bprint_chars(&dstbuf, '\'', 1);
-        for (; *src; src++) {
-            if (*src == '\'')
-                av_bprintf(&dstbuf, "'\\''");
-            else
-                av_bprint_chars(&dstbuf, *src, 1);
-        }
-        av_bprint_chars(&dstbuf, '\'', 1);
-        break;
-
-    default:
-        /* unknown escape mode */
-        return AVERROR(EINVAL);
-    }
-
-    if (!av_bprint_is_complete(&dstbuf)) {
-        av_bprint_finalize(&dstbuf, NULL);
-        return AVERROR(ENOMEM);
-    } else {
-        av_bprint_finalize(&dstbuf, dst);
-        return 0;
-    }
-}
-
 int main(int argc, char **argv)
 {
     AVBPrint src;
@@ -123,13 +59,14 @@ int main(int argc, char **argv)
     const char *outfilename = NULL, *infilename = NULL;
     FILE *outfile = NULL, *infile = NULL;
     const char *prompt = "=> ";
-    enum EscapeMode escape_mode = ESCAPE_MODE_LAZY;
+    enum AVEscapeMode escape_mode = AV_ESCAPE_MODE_AUTO;
+    int escape_flags = 0;
     int level = 1;
     int echo = 0;
     char *special_chars = NULL;
     int c;
 
-    while ((c = getopt(argc, argv, "ehi:l:o:m:p:s:")) != -1) {
+    while ((c = getopt(argc, argv, "ef:hi:l:o:m:p:s:")) != -1) {
         switch (c) {
         case 'e':
             echo = 1;
@@ -140,6 +77,16 @@ int main(int argc, char **argv)
         case 'i':
             infilename = optarg;
             break;
+        case 'f':
+            if      (!strcmp(optarg, "whitespace")) escape_flags |= AV_ESCAPE_FLAG_WHITESPACE;
+            else if (!strcmp(optarg, "strict"))     escape_flags |= AV_ESCAPE_FLAG_STRICT;
+            else {
+                av_log(NULL, AV_LOG_ERROR,
+                       "Invalid value '%s' for option -f, "
+                       "valid arguments are 'whitespace', and 'strict'\n", optarg);
+                return 1;
+            }
+            break;
         case 'l':
         {
             char *tail;
@@ -154,13 +101,13 @@ int main(int argc, char **argv)
             break;
         }
         case 'm':
-            if      (!strcmp(optarg, "full"))  escape_mode = ESCAPE_MODE_FULL;
-            else if (!strcmp(optarg, "lazy"))  escape_mode = ESCAPE_MODE_LAZY;
-            else if (!strcmp(optarg, "quote")) escape_mode = ESCAPE_MODE_QUOTE;
+            if      (!strcmp(optarg, "auto"))      escape_mode = AV_ESCAPE_MODE_AUTO;
+            else if (!strcmp(optarg, "backslash")) escape_mode = AV_ESCAPE_MODE_BACKSLASH;
+            else if (!strcmp(optarg, "quote"))     escape_mode = AV_ESCAPE_MODE_QUOTE;
             else {
                 av_log(NULL, AV_LOG_ERROR,
                        "Invalid value '%s' for option -m, "
-                       "valid arguments are 'full', 'lazy', 'quote'\n", optarg);
+                       "valid arguments are 'backslash', and 'quote'\n", optarg);
                 return 1;
             }
             break;
@@ -219,7 +166,7 @@ int main(int argc, char **argv)
     /* escape */
     dst_buf = src_buf;
     while (level--) {
-        if (escape(&dst_buf, src_buf, special_chars, escape_mode) < 0) {
+        if (av_escape(&dst_buf, src_buf, special_chars, escape_mode, escape_flags) < 0) {
             av_log(NULL, AV_LOG_ERROR, "Could not escape string\n");
             return 1;
         }
diff --git a/mythtv/external/FFmpeg/tools/ismindex.c b/mythtv/external/FFmpeg/tools/ismindex.c
index 9efdebec285..803c5b72864 100644
--- a/mythtv/external/FFmpeg/tools/ismindex.c
+++ b/mythtv/external/FFmpeg/tools/ismindex.c
@@ -40,6 +40,8 @@
 #define mkdir(a, b) _mkdir(a)
 #endif
 
+#include "cmdutils.h"
+
 #include "libavformat/avformat.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mathematics.h"
diff --git a/mythtv/external/FFmpeg/tools/patcheck b/mythtv/external/FFmpeg/tools/patcheck
index a1d4c06e803..83db4c04389 100755
--- a/mythtv/external/FFmpeg/tools/patcheck
+++ b/mythtv/external/FFmpeg/tools/patcheck
@@ -173,7 +173,7 @@ vertical align =
 /* and * align
 arrays fitting in smaller types
 variables written to twice with no interspaced read
-memset(block, 0, 6*64*sizeof(DCTELEM)); -> clear_blocks
+memset(block, 0, 6*64*sizeof(int16_t)); -> clear_blocks
 check existence of long_name in AVCodec
 check that the patch does not touch codec & (de)muxer layer at the same time ->split
 
diff --git a/mythtv/external/FFmpeg/tools/plotframes b/mythtv/external/FFmpeg/tools/plotframes
new file mode 100644
index 00000000000..f379723a9b8
--- /dev/null
+++ b/mythtv/external/FFmpeg/tools/plotframes
@@ -0,0 +1,164 @@
+#!/usr/bin/env perl
+
+# Copyright (c) 2007-2013 Stefano Sabatini
+#
+# This file is part of FFmpeg.
+#
+# FFmpeg is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# FFmpeg is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+=head1 NAME
+
+plotframes - Plot video frame sizes using ffprobe and gnuplot
+
+=head1 SYNOPSIS
+
+plotframes [I] [I]
+
+=head1 DESCRIPTION
+
+plotframes reads a multimedia files with ffprobe, and plots the
+collected video sizes with gnuplot.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<--input|-i> I
+
+Specify multimedia file to read. This is the file passed to the
+ffprobe command. If not specified it is the first argument passed to
+the script.
+
+=item B<--help|--usage|-h|-?>
+
+Print a brief help message and exit.
+
+=item B<--manpage|-m>
+
+Print the man page.
+
+=item B<--output|-o> I
+
+Set the name of the output used by gnuplot. If not specified no output
+is created. Must be used in conjunction with the B option.
+
+=item B<--stream|--s> I
+
+Specify stream. The value must be a string containing a stream
+specifier. Default value is "v".
+
+=item B<--terminal|-t> I
+
+Set the name of the terminal used by gnuplot. By default it is
+"x11". Must be used in conjunction with the B option. Check
+the gnuplot manual for the valid values.
+
+=back
+
+=cut
+
+=head1 SEE ALSO
+
+ffprobe(1), gnuplot(1)
+
+=cut
+
+use warnings;
+use strict;
+
+use File::Temp;
+use JSON -support_by_pp;
+use Getopt::Long;
+use Pod::Usage;
+
+my $input = $ARGV[0];
+my $stream_specifier = "v";
+my $gnuplot_terminal = "x11";
+my $gnuplot_output;
+
+GetOptions (
+    'input|i=s'      => \$input,
+    'help|usage|?|h' => sub { pod2usage ( { -verbose => 1, -exitval => 0 }) },
+    'manpage|m'      => sub { pod2usage ( { -verbose => 2, -exitval => 0 }) },
+    'stream|s=s'     => \$stream_specifier,
+    'terminal|t=s'   => \$gnuplot_terminal,
+    'output|o=s'     => \$gnuplot_output,
+    ) or pod2usage( { -message=> "Parsing error", -verbose => 1, -exitval => 1 });
+
+die "You must specify an input file\n" unless $input;
+
+# fetch data
+my @cmd = (qw{ffprobe -show_entries frame -select_streams}, $stream_specifier, "-of", "json", $input);
+print STDERR "Executing command: @cmd\n";
+my $json_struct;
+{
+    open(FH, "-|", @cmd) or die "ffprobe command failed: $!\n";
+    local $/;
+    my $json_text = ;
+    close FH;
+    die "ffprobe command failed" if $?;
+    eval { $json_struct = decode_json($json_text); };
+    die "JSON parsing error: $@\n" if $@;
+}
+
+# collect and print frame statistics per pict_type
+my %stats;
+my $frames = $json_struct->{frames};
+my $frame_count = 0;
+foreach my $frame (@{$frames}) {
+    my $type = $frame->{pict_type};
+    $frame->{count} = $frame_count++;
+    if (not $stats{$type}) {
+        $stats{$type}->{tmpfile} = File::Temp->new(SUFFIX => '.dat');
+        my $fn = $stats{$type}->{tmpfile}->filename;
+        open($stats{$type}->{fh}, ">", $fn) or die "Can't open $fn";
+    }
+
+    print { $stats{$type}->{fh} }
+        "$frame->{count} ", $frame->{pkt_size} * 8 / 1000, "\n";
+}
+foreach (keys %stats) { close $stats{$_}->{fh}; }
+
+# write gnuplot script
+my %type_color_map = (
+    "I" => "red",
+    "P" => "green",
+    "B" => "blue"
+    );
+
+my $gnuplot_script_tmpfile = File::Temp->new(SUFFIX => '.gnuplot');
+my $fn = $gnuplot_script_tmpfile->filename;
+open(FH, ">", $fn) or die "Couldn't open $fn: $!";
+print FH << "EOF";
+set title "video frame sizes"
+set xlabel "frame time"
+set ylabel "frame size (Kbits)"
+set grid
+set terminal "$gnuplot_terminal"
+EOF
+
+print FH "set output \"$gnuplot_output\"\n" if $gnuplot_output;
+print FH "plot";
+my $sep = "";
+foreach my $type (keys %stats) {
+    my $fn = $stats{$type}->{tmpfile}->filename;
+    print FH "$sep\"$fn\" title \"$type frames\" with impulses";
+    print FH " linecolor rgb \"$type_color_map{$type}\"" if $type_color_map{$type};
+    $sep = ", ";
+}
+close FH;
+
+# launch gnuplot with the generated script
+system ("gnuplot", "--persist", $gnuplot_script_tmpfile->filename);
diff --git a/mythtv/external/FFmpeg/tools/seek_print.c b/mythtv/external/FFmpeg/tools/seek_print.c
new file mode 100644
index 00000000000..a99a0ad832d
--- /dev/null
+++ b/mythtv/external/FFmpeg/tools/seek_print.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2013 Nicolas George
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "config.h"
+#if HAVE_UNISTD_H
+#include              /* getopt */
+#endif
+
+#include "libavformat/avformat.h"
+#include "libavutil/timestamp.h"
+
+#if !HAVE_GETOPT
+#include "compat/getopt.c"
+#endif
+
+static void usage(int ret)
+{
+    fprintf(ret ? stderr : stdout,
+            "Usage: seek_print file [command ...]\n"
+            "Commands:\n"
+            "    read\n"
+            "    seek:stream:min_ts:ts:max_ts:flags\n"
+            );
+    exit(ret);
+}
+
+int main(int argc, char **argv)
+{
+    int opt, ret, stream, flags;
+    const char *filename;
+    AVFormatContext *avf = NULL;
+    int64_t min_ts, max_ts, ts;
+    AVPacket packet;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            usage(0);
+        default:
+            usage(1);
+        }
+    }
+    argc -= optind;
+    argv += optind;
+    if (!argc)
+        usage(1);
+    filename = *argv;
+    argv++;
+    argc--;
+
+    av_register_all();
+    if ((ret = avformat_open_input(&avf, filename, NULL, NULL)) < 0) {
+        fprintf(stderr, "%s: %s\n", filename, av_err2str(ret));
+        return 1;
+    }
+    if ((ret = avformat_find_stream_info(avf, NULL)) < 0) {
+        fprintf(stderr, "%s: could not find codec parameters: %s\n", filename,
+                av_err2str(ret));
+        return 1;
+    }
+
+    for (; argc; argc--, argv++) {
+        if (!strcmp(*argv, "read")) {
+            ret = av_read_frame(avf, &packet);
+            if (ret < 0) {
+                printf("read: %d (%s)\n", ret, av_err2str(ret));
+            } else {
+                AVRational *tb = &avf->streams[packet.stream_index]->time_base;
+                printf("read: %d size=%d stream=%d dts=%s (%s) pts=%s (%s)\n",
+                       ret, packet.size, packet.stream_index,
+                       av_ts2str(packet.dts), av_ts2timestr(packet.dts, tb),
+                       av_ts2str(packet.pts), av_ts2timestr(packet.pts, tb));
+                av_free_packet(&packet);
+            }
+        } else if (sscanf(*argv, "seek:%i:%"PRIi64":%"PRIi64":%"PRIi64":%i",
+                   &stream, &min_ts, &ts, &max_ts, &flags) == 5) {
+            ret = avformat_seek_file(avf, stream, min_ts, ts, max_ts, flags);
+            printf("seek: %d (%s)\n", ret, av_err2str(ret));
+        } else {
+            fprintf(stderr, "'%s': unknown command\n", *argv);
+            return 1;
+        }
+    }
+
+    avformat_close_input(&avf);
+
+    return 0;
+}