[SCM] mplayer2/upstream: Imported Upstream version 2.0-726-g6c87a98

alessio at users.alioth.debian.org alessio at users.alioth.debian.org
Tue Aug 20 21:21:36 UTC 2013


The following commit has been merged in the upstream branch:
commit 9fba569ad2d15c9606d44865991551803fa23d4e
Author: Alessio Treglia <alessio at debian.org>
Date:   Tue Aug 20 22:18:36 2013 +0100

    Imported Upstream version 2.0-726-g6c87a98

diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index e5ae752..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,25 +0,0 @@
-*.o
-*.a
-*.d
-.depend
-
-/config.h
-/config.mak
-/config.log
-/mplayer
-/mplayer2.app
-/version.h
-/codecs.conf.h
-/codec-cfg
-/cpuinfo
-/tags
-/TAGS
-/locale
-/po
-/DOCS/man/*/mplayer.1
-/input/input.conf.h
-/libmpdemux/ebml_defs.c
-/libmpdemux/ebml_types.h
-/libvo/vdpau_template.c
-/libvo/vo_gl3_shaders.h
-/sub/osd_font.h
diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst
index 59e9241..a6f5d0d 100644
--- a/DOCS/man/en/options.rst
+++ b/DOCS/man/en/options.rst
@@ -1113,19 +1113,6 @@
         For best decoding quality use the same IDCT algorithm for decoding and
         encoding. This may come at a price in accuracy, though.
 
-    lowres=<number>[,<w>]
-        Decode at lower resolutions. Low resolution decoding is not supported
-        by all codecs, and it will often result in ugly artifacts. This is not
-        a bug, but a side effect of not decoding at full resolution.
-
-        :0: disabled
-        :1: 1/2 resolution
-        :2: 1/4 resolution
-        :3: 1/8 resolution
-
-        If <w> is specified lowres decoding will be used only if the width of
-        the video is major than or equal to <w>.
-
     o=<key>=<value>[,<key>=<value>[,...]]
         Pass AVOptions to libavcodec decoder. Note, a patch to make the o=
         unneeded and pass all unknown options through the AVOption system is
diff --git a/DOCS/man/en/vf.rst b/DOCS/man/en/vf.rst
index 5e5007d..ebdd628 100644
--- a/DOCS/man/en/vf.rst
+++ b/DOCS/man/en/vf.rst
@@ -428,44 +428,11 @@ pp[=filter1[:option1[:option2...]]/[-]filter2...]
         Horizontal deblocking on luminance only, and switch vertical
         deblocking on or off automatically depending on available CPU time.
 
-spp[=quality[:qp[:mode]]]
-    Simple postprocessing filter that compresses and decompresses the image at
-    several (or - in the case of quality level 6 - all) shifts and averages
-    the results.
-
-    <quality>
-        0-6 (default: 3)
-
-    <qp>
-        Force quantization parameter (default: 0, use QP from video).
-
-    <mode>
-
-        :0: hard thresholding (default)
-        :1: soft thresholding (better deringing, but blurrier)
-        :4: like 0, but also use B-frames' QP (may cause flicker)
-        :5: like 1, but also use B-frames' QP (may cause flicker)
-
-uspp[=quality[:qp]]
-    Ultra simple & slow postprocessing filter that compresses and decompresses
-    the image at several (or - in the case of quality level 8 - all) shifts
-    and averages the results.
-
-    The way this differs from the behavior of spp is that uspp actually
-    encodes & decodes each case with libavcodec Snow, whereas spp uses a
-    simplified intra only 8x8 DCT similar to MJPEG.
-
-    <quality>
-        0-8 (default: 3)
-
-    <qp>
-        Force quantization parameter (default: 0, use QP from video).
-
 fspp[=quality[:qp[:strength[:bframes]]]]
-    faster version of the simple postprocessing filter
+    simple postprocessing filter
 
     <quality>
-        4-5 (equivalent to spp; default: 4)
+        4-5 (default: 4)
 
     <qp>
         Force quantization parameter (default: 0, use QP from video).
@@ -480,8 +447,7 @@ fspp[=quality[:qp[:strength[:bframes]]]]
         1: use QP from B-frames too (may cause flicker)
 
 pp7[=qp[:mode]]
-    Variant of the spp filter, similar to spp=6 with 7 point DCT where only
-    the center sample is used after IDCT.
+    Another postprocessing filter
 
     <qp>
         Force quantization parameter (default: 0, use QP from video).
@@ -1097,23 +1063,6 @@ yadif=[mode[:field_dominance]]
         *NOTE*: This option will possibly be removed in a future version. Use
         ``--field-dominance`` instead.
 
-mcdeint=[mode[:parity[:qp]]]
-    Motion compensating deinterlacer. It needs one field per frame as input
-    and must thus be used together with tfields=1 or yadif=1/3 or equivalent.
-
-    <mode>
-        :0: fast
-        :1: medium
-        :2: slow, iterative motion estimation
-        :3: extra slow, like 2 plus multiple reference frames
-
-    <parity>
-        0 or 1 selects which field to use (note: no autodetection yet!).
-
-    <qp>
-        Higher values should result in a smoother motion vector field but less
-        optimal individual vectors.
-
 boxblur=radius:power[:radius:power]
     box blur
 
diff --git a/Makefile b/Makefile
index d649847..371de28 100644
--- a/Makefile
+++ b/Makefile
@@ -58,10 +58,6 @@ SRCS_COMMON-$(DVDREAD_INTERNAL)      += libdvdread4/bitreader.c \
 SRCS_COMMON-$(FAAD)                  += libmpcodecs/ad_faad.c
 SRCS_COMMON-$(FASTMEMCPY)            += libvo/aclib.c
 
-# These filters use private headers and do not work with shared libavcodec.
-SRCS_COMMON-$(FFMPEG_INTERNALS)      += libmpcodecs/vf_mcdeint.c \
-                                        libmpcodecs/vf_spp.c \
-
 SRCS_COMMON-$(FTP)                   += stream/stream_ftp.c
 SRCS_COMMON-$(GIF)                   += libmpdemux/demux_gif.c
 SRCS_COMMON-$(HAVE_POSIX_SELECT)     += libmpcodecs/vf_bmovl.c
@@ -113,8 +109,7 @@ SRCS_COMMON-$(NEED_SHMEM)            += osdep/shmem.c
 SRCS_COMMON-$(NEED_STRSEP)           += osdep/strsep.c
 SRCS_COMMON-$(NEED_SWAB)             += osdep/swab.c
 SRCS_COMMON-$(NEED_VSSCANF)          += osdep/vsscanf.c
-SRCS_COMMON-$(NETWORKING)            += stream/stream_netstream.c \
-                                        stream/asf_mmst_streaming.c \
+SRCS_COMMON-$(NETWORKING)            += stream/asf_mmst_streaming.c \
                                         stream/asf_streaming.c \
                                         stream/cookies.c \
                                         stream/http.c \
@@ -145,7 +140,6 @@ SRCS_COMMON-$(TV_DSHOW)              += stream/tvi_dshow.c \
                                         loader/dshow/guids.c \
                                         loader/dshow/mediatype.c \
 
-SRCS_COMMON-$(TV_V4L1)               += stream/tvi_v4l.c  stream/audio_in.c
 SRCS_COMMON-$(TV_V4L2)               += stream/tvi_v4l2.c stream/audio_in.c
 SRCS_COMMON-$(UNRAR_EXEC)            += sub/unrar_exec.c
 SRCS_COMMON-$(VCD)                   += stream/stream_vcd.c
@@ -338,7 +332,6 @@ SRCS_COMMON = asxparser.c \
               libmpcodecs/vf_tile.c \
               libmpcodecs/vf_tinterlace.c \
               libmpcodecs/vf_unsharp.c \
-              libmpcodecs/vf_uspp.c \
               libmpcodecs/vf_vo.c \
               libmpcodecs/vf_yadif.c \
               libmpcodecs/vf_yuvcsp.c \
@@ -573,7 +566,7 @@ libmpdemux/ebml_types.h: TOOLS/matroska.py
 libmpdemux/ebml_defs.c: TOOLS/matroska.py
 	./$< --generate-definitions > $@
 
-sub/osd_font.h: TOOLS/file2string.py sub/osd_font.pfb
+sub/osd_font.h: TOOLS/file2string.py sub/osd_font.otf
 	./$^ >$@
 
 # ./configure must be rerun if it changed
@@ -616,9 +609,6 @@ libmpdemux/ebml.o libmpdemux/demux_mkv.o: libmpdemux/ebml_types.h
 libmpdemux/ebml.o: libmpdemux/ebml_defs.c
 sub/osd_libass.o: sub/osd_font.h
 
-# Files that depend on libavcodec internals
-libmpcodecs/vf_fspp.o libmpcodecs/vf_mcdeint.o libmpcodecs/vf_spp.o: CFLAGS := -I$(FFMPEG_SOURCE_PATH) $(CFLAGS)
-
 osdep/mplayer-rc.o: osdep/mplayer.exe.manifest
 
 libdvdcss/%:   CFLAGS := -Ilibdvdcss -D_GNU_SOURCE -DVERSION=\"1.2.10\" $(CFLAGS_LIBDVDCSS) $(CFLAGS)
@@ -726,7 +716,7 @@ tests: $(addsuffix $(EXESUF),$(TESTS))
 testsclean:
 	-$(RM) $(call ADD_ALL_EXESUFS,$(TESTS))
 
-TOOLS = $(addprefix TOOLS/,alaw-gen asfinfo avi-fix avisubdump compare dump_mp4 movinfo netstream subrip vivodump)
+TOOLS = $(addprefix TOOLS/,alaw-gen asfinfo avi-fix avisubdump compare dump_mp4 movinfo subrip vivodump)
 
 ifdef ARCH_X86
 TOOLS += TOOLS/fastmemcpybench TOOLS/modify_reg
@@ -751,9 +741,8 @@ TOOLS/vfw2menc$(EXESUF): -lwinmm -lole32
 mplayer-nomain.o: mplayer.c
 	$(CC) $(CFLAGS) -DDISABLE_MAIN -c -o $@ $<
 
-TOOLS/netstream$(EXESUF): TOOLS/netstream.c
 TOOLS/vivodump$(EXESUF): TOOLS/vivodump.c
-TOOLS/netstream$(EXESUF) TOOLS/vivodump$(EXESUF): $(subst mplayer.o,mplayer-nomain.o,$(OBJS_MPLAYER)) $(OBJS_COMMON) $(COMMON_LIBS)
+TOOLS/vivodump$(EXESUF): $(subst mplayer.o,mplayer-nomain.o,$(OBJS_MPLAYER)) $(OBJS_COMMON) $(COMMON_LIBS)
 	$(CC) $(CFLAGS) -o $@ $^ $(EXTRALIBS_MPLAYER) $(EXTRALIBS)
 
 REAL_SRCS    = $(wildcard TOOLS/realcodecs/*.c)
diff --git a/TOOLS/README b/TOOLS/README
index d1e3775..58c1ade 100644
--- a/TOOLS/README
+++ b/TOOLS/README
@@ -440,38 +440,3 @@ Usage:        - Set the path to the RealPlayer codecs directory in the C files.
               - Put the wrappers in the RealPlayer codecs directory.
 
 Notes:        Known to work at least on Linux x86 with RealPlayer8.
-
-
-
-netstream - access remote streams
----------------------------------
-
-netstream allows you to access most MPlayer stream types from a remote host.
-The main purpose of this feature is to make it possible to directly use the
-CD or DVD drive of another computer on the network (provided you have the
-required bandwidth). On the downside some stream types (currently TV and MF)
-are not usable remotely because they are implemented at the demuxer level.
-
-Be aware that currently the server is not secure at all.
-
-Compile the server by running 'make TOOLS/netstream' ('make TOOLS/netstream.exe'
-on windows) from the root of mplayer source and then copy the netstream binary
-to the right place on your system (usually /usr/local/bin on Unix). Start the
-netstream server on the computer you intend to access remotely. There are no
-command line arguments.
-
-Play the second track of a VCD on the server with:
-
-  mplayer -cache 5000 mpst://servername/vcd://2
-
-Access files on this server with:
-
-  mplayer -cache 5000 mpst://servername//usr/local/movies/lol.avi
-
-Note that paths which do not start with a / will be interpreted as relative to
-the directory where the server is running. The '-cache' option is not needed
-but highly recommended.
-
-netstream will not take -dvd-device, so you must either symlink
-your drive to /dev/dvd/ or use the dvd:///path/to/dvd.
-for example: mpst://audioserver/dvd:////dev/optical/lg_black_dvd
diff --git a/TOOLS/netstream.c b/TOOLS/netstream.c
deleted file mode 100644
index e7f9581..0000000
--- a/TOOLS/netstream.c
+++ /dev/null
@@ -1,366 +0,0 @@
-/*
- * Copyright (C) Alban Bedel - 04/2003
- *
- * 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 <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <inttypes.h>
-#include <errno.h>
-#include <signal.h>
-#include <sys/types.h>
-
-#include "config.h"
-
-#if !HAVE_WINSOCK2_H
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#else
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#endif
-
-#include "stream/stream.h"
-#include "libmpdemux/demuxer.h"
-#include "mp_msg.h"
-#include "libavutil/common.h"
-#include "mpbswap.h"
-
-/// Netstream packets def and some helpers
-#include "stream/stream_netstream.h"
-
-// linking hacks
-char *info_name;
-char *info_artist;
-char *info_genre;
-char *info_subject;
-char *info_copyright;
-char *info_sourceform;
-char *info_comment;
-
-char* out_filename = NULL;
-char* force_fourcc=NULL;
-char* passtmpfile="divx2pass.log";
-
-static unsigned short int port = 10000;
-
-typedef struct client_st client_t;
-struct client_st {
-  int fd;
-  stream_t* stream;
-  client_t* next;
-  client_t* prev;
-};
-
-static int write_error(int fd,char* msg) {
-  int len = strlen(msg) + 1;
-  return write_packet(fd,NET_STREAM_ERROR,msg,len);
-}
-
-static int net_stream_open(client_t* cl,char* url) {
-  int file_format=DEMUXER_TYPE_UNKNOWN;
-  mp_net_stream_opened_t ret;
-
-  if(cl->stream) {
-    if(!write_error(cl->fd,"A stream is currently opened\n"))
-      return 0;
-    return 1;
-  }
-
-  mp_msg(MSGT_NETST,MSGL_V,"Open stream %s\n",url);
-  cl->stream = open_stream(url,NULL,&file_format);
-  if(!cl->stream) {
-    if(!write_error(cl->fd,"Open failed\n"))
-      return 0;
-    return 1;
-  }
-  stream_reset(cl->stream);
-  stream_seek(cl->stream,cl->stream->start_pos);
-  ret.file_format = file_format;
-  ret.flags = cl->stream->flags;
-  ret.sector_size = cl->stream->sector_size;
-  ret.start_pos = cl->stream->start_pos;
-  ret.end_pos = cl->stream->end_pos;
-  net_stream_opened_2_me(&ret);
-
-  if(!write_packet(cl->fd,NET_STREAM_OK,(char*)&ret,sizeof(mp_net_stream_opened_t)))
-    return 0;
-  return 1;
-}
-
-static int net_stream_fill_buffer(client_t* cl,uint16_t max_len) {
-  int r;
-  mp_net_stream_packet_t *pack;
-
-  if(!cl->stream) {
-    if(!write_error(cl->fd,"No stream is currently opened\n"))
-      return 0;
-    return 1;
-  }
-  if(max_len == 0) {
-    if(!write_error(cl->fd,"Fill buffer called with 0 length\n"))
-      return 0;
-    return 1;
-  }
-  pack = malloc(max_len + sizeof(mp_net_stream_packet_t));
-  pack->cmd = NET_STREAM_OK;
-  r = stream_read(cl->stream,pack->data,max_len);
-  pack->len = le2me_16(r + sizeof(mp_net_stream_packet_t));
-  if(!net_write(cl->fd,(char*)pack,le2me_16(pack->len))) {
-    free(pack);
-    return 0;
-  }
-  free(pack);
-  return 1;
-}
-
-static int net_stream_seek(client_t* cl, uint64_t pos) {
-
-  if(!cl->stream) {
-    if(!write_error(cl->fd,"No stream is currently opened\n"))
-      return 0;
-    return 1;
-  }
-
-  if(!stream_seek(cl->stream,(off_t)pos)) {
-    if(!write_error(cl->fd,"Seek failed\n"))
-      return 0;
-    return 1;
-  }
-  if(!write_packet(cl->fd,NET_STREAM_OK,NULL,0))
-    return 0;
-  return 1;
-}
-
-static int net_stream_reset(client_t* cl) {
-  if(!cl->stream) {
-    if(!write_error(cl->fd,"No stream is currently opened\n"))
-      return 0;
-    return 1;
-  }
-  stream_reset(cl->stream);
-  if(!write_packet(cl->fd,NET_STREAM_OK,NULL,0))
-    return 0;
-  return 1;
-}
-
-static int net_stream_close(client_t* cl) {
-  if(!cl->stream) {
-    if(!write_error(cl->fd,"No stream is currently opened\n"))
-      return 0;
-    return 1;
-  }
-
-  free_stream(cl->stream);
-  cl->stream = NULL;
-
-  if(!write_packet(cl->fd,NET_STREAM_OK,NULL,0))
-    return 0;
-  return 1;
-}
-
-static int handle_client(client_t* cl,mp_net_stream_packet_t* pack) {
-
-  if(!pack)
-    return 0;
-
-  switch(pack->cmd) {
-  case NET_STREAM_OPEN:
-    if(((char*)pack)[pack->len-1] != '\0') {
-      mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid open packet\n");
-      return 0;
-    }
-    return net_stream_open(cl,pack->data);
-  case NET_STREAM_FILL_BUFFER:
-    if(pack->len != sizeof(mp_net_stream_packet_t) + 2) {
-      mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid fill buffer packet\n");
-      return 0;
-    }
-    return net_stream_fill_buffer(cl,le2me_16(*((uint16_t*)pack->data)));
-  case NET_STREAM_SEEK:
-    if(pack->len != sizeof(mp_net_stream_packet_t) + 8) {
-      mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid fill buffer packet\n");
-      return 0;
-    }
-    return net_stream_seek(cl,le2me_64(*((uint64_t*)pack->data)));
-  case NET_STREAM_RESET:
-    return net_stream_reset(cl);
-  case NET_STREAM_CLOSE:
-    if(pack->len != sizeof(mp_net_stream_packet_t)){
-      mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid fill buffer packet\n");
-      return 0;
-    }
-    return net_stream_close(cl);
-  default:
-    mp_msg(MSGT_NETST,MSGL_WARN,"Got unknown command %d\n",pack->cmd);
-    if(!write_error(cl->fd,"Unknown command\n"))
-      return 0;
-  }
-  return 0;
-}
-
-static client_t* add_client(client_t *head,int fd) {
-  client_t *new = calloc(1,sizeof(client_t));
-  new->fd = fd;
-  if(!head) return new;
-  new->next = head;
-  head->prev = new;
-  return new;
-}
-
-static int make_fd_set(fd_set* fds, client_t** _cl, int listen) {
-  int max_fd = listen;
-  client_t *cl = *_cl;
-  FD_ZERO(fds);
-  FD_SET(listen,fds);
-  while(cl) {
-    // Remove this client
-    if(cl->fd < 0) {
-      client_t* f = cl;
-      if(cl->prev) cl->prev->next = cl->next;
-      if(cl->next) cl->next->prev = cl->prev;
-      if(cl->stream) free_stream(cl->stream);
-      if(!cl->prev) // Remove the head
-	*_cl = cl->next;
-      cl = cl->next;
-      free(f);
-      continue;
-    }
-    FD_SET(cl->fd,fds);
-    if(cl->fd > max_fd) max_fd = cl->fd;
-    cl = cl->next;
-  }
-  return max_fd+1;
-}
-
-/// Hack to 'cleanly' exit
-static int run_server = 1;
-
-void exit_sig(int sig) {
-  static int count = 0;
-  sig++; // gcc warning
-  count++;
-  if(count==3) exit(1);
-  if(count > 3)
-#ifdef __MINGW32__
-    WSACleanup();
-#else
-    kill(getpid(),SIGKILL);
-#endif
-  run_server = 0;
-}
-
-static int main_loop(int listen_fd) {
-  client_t *clients = NULL,*iter;
-  fd_set fds;
-
-  signal(SIGTERM,exit_sig); // kill
-#ifndef __MINGW32__
-  signal(SIGHUP,exit_sig);  // kill -HUP  /  xterm closed
-  signal(SIGINT,exit_sig);  // Interrupt from keyboard
-  signal(SIGQUIT,exit_sig); // Quit from keyboard
-#endif
-
-  while(run_server) {
-    int sel_n = make_fd_set(&fds,&clients,listen_fd);
-    int n = select(sel_n,&fds,NULL,NULL,NULL);
-    if(n < 0) {
-      if(errno == EINTR)
-	continue;
-      mp_msg(MSGT_NETST,MSGL_FATAL,"Select error: %s\n",strerror(errno));
-      return 1;
-    }
-    // New connection
-    if(FD_ISSET(listen_fd,&fds)) {
-      struct sockaddr_in addr;
-      socklen_t slen = sizeof(struct sockaddr_in);
-      int client_fd = accept(listen_fd,(struct sockaddr*)&addr,&slen);
-      if(client_fd < 0) {
-	mp_msg(MSGT_NETST,MSGL_ERR,"accept failed: %s\n",strerror(errno));
-	continue;
-      }
-      mp_msg(MSGT_NETST,MSGL_V,"New client from %s\n",inet_ntoa(addr.sin_addr));
-      clients = add_client(clients,client_fd);
-      if(n == 1) continue;
-    }
-    // Look for the clients
-    for(iter = clients ; iter ; iter = iter->next) {
-      mp_net_stream_packet_t* pack;
-      if(!FD_ISSET(iter->fd,&fds)) continue;
-      pack = read_packet(iter->fd);
-      if(!pack) {
-	close(iter->fd);
-	iter->fd = -1;
-	continue;
-      }
-      if(!handle_client(iter,pack)) {
-	close(iter->fd);
-	iter->fd = -1;
-      }
-      free(pack);
-    }
-  }
-  mp_msg(MSGT_NETST,MSGL_INFO,"Exit ....\n");
-  close(listen_fd);
-#ifdef __MINGW32__
-  WSACleanup();
-#endif
-  while(clients) {
-    client_t* f = clients;
-    if(f->stream) free_stream(f->stream);
-    if(f->fd > 0) close(f->fd);
-    free(f);
-    clients = clients->next;
-  }
-  return 0;
-}
-
-int main(void) {
-  int listen_fd;
-  struct sockaddr_in addr;
-
-  mp_msg_init();
-  //  mp_msg_set_level(verbose+MSGL_STATUS);
-
-#ifdef __MINGW32__
-  WSADATA wsaData;
-  WSAStartup(MAKEWORD(1,1), &wsaData);
-#endif
-  listen_fd = socket(AF_INET, SOCK_STREAM, 0);
-  if(listen_fd < 0) {
-    mp_msg(MSGT_NETST,MSGL_FATAL,"Failed to create listen_fd: %s\n",strerror(errno));
-    return -1;
-  }
-  memset(&addr,0,sizeof(struct sockaddr));
-  addr.sin_addr.s_addr = INADDR_ANY;
-  addr.sin_port = htons(port);
-  addr.sin_family = AF_INET;
-  if(bind(listen_fd,(struct sockaddr*)&addr,sizeof(struct sockaddr))) {
-    mp_msg(MSGT_NETST,MSGL_FATAL,"Failed to bind listen socket: %s\n",strerror(errno));
-    return -1;
-  }
-
-
-  if(listen(listen_fd,1)) {
-    mp_msg(MSGT_NETST,MSGL_FATAL,"Failed to turn the socket in listen state: %s\n",strerror(errno));
-    return -1;
-  }
-  return main_loop(listen_fd);
-}
diff --git a/cfg-mplayer.h b/cfg-mplayer.h
index 4d23fca..ff8868f 100644
--- a/cfg-mplayer.h
+++ b/cfg-mplayer.h
@@ -128,12 +128,12 @@ const m_option_t tvopts_conf[]={
     {"hue", &stream_tv_defaults.hue, CONF_TYPE_INT, CONF_RANGE, -100, 100, NULL},
     {"saturation", &stream_tv_defaults.saturation, CONF_TYPE_INT, CONF_RANGE, -100, 100, NULL},
     {"gain", &stream_tv_defaults.gain, CONF_TYPE_INT, CONF_RANGE, -1, 100, NULL},
-#if defined(CONFIG_TV_V4L) || defined(CONFIG_TV_V4L2) || defined(CONFIG_TV_DSHOW)
+#if defined(CONFIG_TV_V4L2) || defined(CONFIG_TV_DSHOW)
     {"buffersize", &stream_tv_defaults.buffer_size, CONF_TYPE_INT, CONF_RANGE, 16, 1024, NULL},
     {"amode", &stream_tv_defaults.amode, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL},
     {"volume", &stream_tv_defaults.volume, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL},
 #endif
-#if defined(CONFIG_TV_V4L) || defined(CONFIG_TV_V4L2)
+#if defined(CONFIG_TV_V4L2)
     {"bass", &stream_tv_defaults.bass, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL},
     {"treble", &stream_tv_defaults.treble, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL},
     {"balance", &stream_tv_defaults.balance, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL},
@@ -146,7 +146,7 @@ const m_option_t tvopts_conf[]={
 #ifdef CONFIG_ALSA
     {"alsa", &stream_tv_defaults.alsa, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 #endif /* CONFIG_ALSA */
-#endif /* defined(CONFIG_TV_V4L) || defined(CONFIG_TV_V4L2) */
+#endif /* defined(CONFIG_TV_V4L2) */
     {"adevice", &stream_tv_defaults.adevice, CONF_TYPE_STRING, 0, 0, 0, NULL},
     {"tdevice", &stream_tv_defaults.teletext.device, CONF_TYPE_STRING, 0, 0, 0, NULL},
     {"tpage", &stream_tv_defaults.teletext.page, CONF_TYPE_INT, CONF_RANGE, 100, 899, NULL},
@@ -298,11 +298,9 @@ const m_option_t msgl_config[]={
     { "network", &mp_msg_levels[MSGT_NETWORK], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL },
     { "cpudetect", &mp_msg_levels[MSGT_CPUDETECT], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL },
     { "codeccfg", &mp_msg_levels[MSGT_CODECCFG], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL },
-    { "sws", &mp_msg_levels[MSGT_SWS], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL },
     { "vobsub", &mp_msg_levels[MSGT_VOBSUB], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL },
     { "subreader", &mp_msg_levels[MSGT_SUBREADER], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL },
     { "afilter", &mp_msg_levels[MSGT_AFILTER], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL },
-    { "netst", &mp_msg_levels[MSGT_NETST], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL },
     { "muxer", &mp_msg_levels[MSGT_MUXER], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL },
     { "identify", &mp_msg_levels[MSGT_IDENTIFY], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL },
     { "ass", &mp_msg_levels[MSGT_ASS], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL },
@@ -341,11 +339,9 @@ const m_option_t msgl_config[]={
     "   network\n"
     "   cpudetect\n"
     "   codeccfg\n"
-    "   sws\n"
     "   vobsub\n"
     "   subreader\n"
     "   afilter    - Audio filter messages\n"
-    "   netst      - Netstream\n"
     "   muxer      - muxer layer\n"
     "   identify   - identify output\n"
     "   ass        - libass messages\n"
diff --git a/configure b/configure
index 9b42b44..95a5ae8 100755
--- a/configure
+++ b/configure
@@ -148,19 +148,6 @@ EOF
   compile_check $TMPC $@
 }
 
-yasm_check() {
-  echo >> "$TMPLOG"
-  cat "$TMPS" >> "$TMPLOG"
-  echo >> "$TMPLOG"
-  echo "$_yasm $YASMFLAGS -o $TMPEXE $TMPS $@" >> "$TMPLOG"
-  rm -f "$TMPEXE"
-  $_yasm $YASMFLAGS -o "$TMPEXE" "$TMPS" "$@" >> "$TMPLOG" 2>&1
-  TMPRES="$?"
-  echo >> "$TMPLOG"
-  echo >> "$TMPLOG"
-  return "$TMPRES"
-}
-
 pkg_config_add() {
   unset IFS  # shell should not be used for programming
   echo >> "$TMPLOG"
@@ -294,8 +281,6 @@ Configuration:
 Installation directories:
   --prefix=DIR           prefix directory for installation [/usr/local]
   --bindir=DIR           directory for installing binaries [PREFIX/bin]
-  --datadir=DIR          directory for installing machine independent
-                         data files (skins, etc) [PREFIX/share/mplayer]
   --mandir=DIR           directory for installing man pages [PREFIX/share/man]
   --confdir=DIR          directory for installing configuration files
                          [PREFIX/etc/mplayer]
@@ -321,7 +306,6 @@ Optional features:
   --disable-radio-v4l2   disable Video4Linux2 radio interface [autodetect]
   --disable-radio-bsdbt848   disable BSD BT848 radio interface [autodetect]
   --disable-tv           disable TV interface (TV/DVB grabbers) [enable]
-  --disable-tv-v4l1      disable Video4Linux TV interface [autodetect]
   --disable-tv-v4l2      disable Video4Linux2 TV interface [autodetect]
   --disable-tv-bsdbt848  disable BSD BT848 interface [autodetect]
   --disable-pvr          disable Video4Linux2 MPEG PVR [autodetect]
@@ -396,7 +380,6 @@ Video output:
   --enable-vm              enable XF86VidMode support [autodetect]
   --enable-xinerama        enable Xinerama support [autodetect]
   --enable-x11             enable X11 video output [autodetect]
-  --enable-xshape          enable XShape support [autodetect]
   --disable-xss            disable screensaver support via xss [autodetect]
   --enable-directfb        enable DirectFB video output [autodetect]
   --disable-tga            disable Targa video output [enable]
@@ -440,12 +423,7 @@ Miscellaneous options:
   --enable-runtime-cpudetection    enable runtime CPU detection [disable]
   --enable-cross-compile enable cross-compilation [disable]
   --cc=COMPILER          C compiler to build MPlayer [gcc]
-  --as=ASSEMBLER         assembler to build MPlayer [as]
-  --nm=NM                nm tool to build MPlayer [nm]
-  --yasm=YASM            Yasm assembler to build MPlayer [yasm]
-  --ar=AR                librarian to build MPlayer [ar]
   --pkg-config=PKGCONFIG pkg-config to find some libraries [pkg-config]
-  --ranlib=RANLIB        ranlib to build MPlayer [ranlib]
   --windres=WINDRES      windres to build MPlayer [windres]
   --target=PLATFORM      target platform (i386-linux, arm-linux, etc)
   --enable-static        build a statically linked binary
@@ -514,28 +492,21 @@ _iwmmxt=auto
 _altivec=auto
 _install=install
 _pkg_config=auto
-_ranlib=auto
 _windres=auto
 _cc=auto
-_ar=auto
 test "$CC" && _cc="$CC"
 _as=auto
-_nm=auto
-_yasm=auto
 _runtime_cpudetection=no
 _cross_compile=no
 _prefix="/usr/local"
 ffmpeg=auto
-ffmpeg_internals=no
 _x11=auto
-_xshape=auto
 _xss=auto
 _xv=auto
 _vdpau=auto
 _sdl=auto
 _direct3d=auto
 _directx=auto
-_nas=auto
 _png=auto
 _mng=auto
 _jpeg=auto
@@ -591,11 +562,9 @@ _win32dll=auto
 _select=yes
 _radio=no
 _radio_capture=no
-_radio_v4l=auto
 _radio_v4l2=auto
 _radio_bsdbt848=auto
 _tv=yes
-_tv_v4l1=auto
 _tv_v4l2=auto
 _tv_bsdbt848=auto
 _tv_dshow=auto
@@ -664,9 +633,6 @@ for ac_option do
   --bindir=*)
     _bindir=$(echo $ac_option | cut -d '=' -f 2)
     ;;
-  --datadir=*)
-    _datadir=$(echo $ac_option | cut -d '=' -f 2)
-    ;;
   --mandir=*)
     _mandir=$(echo $ac_option | cut -d '=' -f 2)
     ;;
@@ -716,24 +682,9 @@ for ac_option do
   --cc=*)
     _cc=$(echo $ac_option | cut -d '=' -f 2)
     ;;
-  --as=*)
-    _as=$(echo $ac_option | cut -d '=' -f 2)
-    ;;
-  --nm=*)
-    _nm=$(echo $ac_option | cut -d '=' -f 2)
-    ;;
-  --yasm=*)
-    _yasm=$(echo $ac_option | cut -d '=' -f 2)
-    ;;
-  --ar=*)
-    _ar=$(echo $ac_option | cut -d '=' -f 2)
-    ;;
   --pkg-config=*)
     _pkg_config=$(echo $ac_option | cut -d '=' -f 2)
     ;;
-  --ranlib=*)
-    _ranlib=$(echo $ac_option | cut -d '=' -f 2)
-    ;;
   --windres=*)
     _windres=$(echo $ac_option | cut -d '=' -f 2)
     ;;
@@ -782,8 +733,6 @@ for ac_option do
   --disable-cross-compile)          _cross_compile=no           ;;
   --enable-x11)         _x11=yes        ;;
   --disable-x11)        _x11=no         ;;
-  --enable-xshape)      _xshape=yes     ;;
-  --disable-xshape)     _xshape=no      ;;
   --enable-xss)         _xss=yes        ;;
   --disable-xss)        _xss=no         ;;
   --enable-xv)          _xv=yes         ;;
@@ -896,8 +845,6 @@ for ac_option do
   --disable-tv)         _tv=no          ;;
   --enable-tv-bsdbt848)  _tv_bsdbt848=yes ;;
   --disable-tv-bsdbt848) _tv_bsdbt848=no  ;;
-  --enable-tv-v4l1)     _tv_v4l1=yes    ;;
-  --disable-tv-v4l1)    _tv_v4l1=no     ;;
   --enable-tv-v4l2)     _tv_v4l2=yes    ;;
   --disable-tv-v4l2)    _tv_v4l2=no     ;;
   --enable-tv-dshow)    _tv_dshow=yes   ;;
@@ -906,8 +853,6 @@ for ac_option do
   --enable-radio-capture)       _radio_capture=yes      ;;
   --disable-radio-capture)      _radio_capture=no       ;;
   --disable-radio)      _radio=no       ;;
-  --enable-radio-v4l)   _radio_v4l=yes  ;;
-  --disable-radio-v4l)  _radio_v4l=no   ;;
   --enable-radio-v4l2)  _radio_v4l2=yes ;;
   --disable-radio-v4l2) _radio_v4l2=no  ;;
   --enable-radio-bsdbt848)      _radio_bsdbt848=yes     ;;
@@ -931,8 +876,6 @@ for ac_option do
   --enable-libnut)      _libnut=yes     ;;
   --disable-libnut)     _libnut=no      ;;
   --enable-libav)       ffmpeg=yes      ;;
-  --ffmpeg-source-dir=*)
-    _ffmpeg_source=$(echo $ac_option | cut -d '=' -f 2 ) ;;
 
   --enable-lirc)        _lirc=yes       ;;
   --disable-lirc)       _lirc=no        ;;
@@ -1055,7 +998,6 @@ done
 
 # Atmos: moved this here, to be correct, if --prefix is specified
 test -z "$_bindir"  && _bindir="$_prefix/bin"
-test -z "$_datadir" && _datadir="$_prefix/share/mplayer"
 test -z "$_mandir"  && _mandir="$_prefix/share/man"
 test -z "$_confdir" && _confdir="$_prefix/etc/mplayer"
 test -z "$_libdir"  && _libdir="$_prefix/lib"
@@ -1098,10 +1040,7 @@ if test $_cross_compile = yes ; then
     test -n "$_target" && tool_prefix="$_target"-
 fi
 
-test "$_ranlib" = auto && _ranlib="$tool_prefix"ranlib
 test "$_windres" = auto && _windres="$tool_prefix"windres
-test "$_ar" = auto && _ar="$tool_prefix"ar
-test "$_yasm" = auto && _yasm="$tool_prefix"yasm
 test "$_pkg_config" = auto && _pkg_config="$tool_prefix"pkg-config
 
 if test "$_cc" = auto ; then
@@ -1226,10 +1165,6 @@ if aix ; then
   extra_ldflags="$extra_ldflags -lC"
 fi
 
-if linux ; then
-  _ranlib='true'
-fi
-
 if win32 ; then
   _exesuf=".exe"
   extra_cflags="$extra_cflags -fno-common"
@@ -1351,18 +1286,6 @@ echo "Detected host architecture: $host_arch"
 
 # ---
 
-# now that we know what compiler should be used for compilation, try to find
-# out which assembler is used by the $_cc compiler
-if test "$_as" = auto ; then
-  _as=$($_cc -print-prog-name=as)
-  test -z "$_as" && _as=as
-fi
-
-if test "$_nm" = auto ; then
-  _nm=$($_cc -print-prog-name=nm)
-  test -z "$_nm" && _nm=nm
-fi
-
 # XXX: this should be ok..
 _cpuinfo="echo"
 
@@ -1847,7 +1770,6 @@ case "$host_arch" in
 
   ppc|ppc64|powerpc|powerpc64)
     arch='ppc'
-    def_dcbzl='#define HAVE_DCBZL 0'
     def_fast_unaligned='#define HAVE_FAST_UNALIGNED 1'
     iproc='ppc'
 
@@ -1919,8 +1841,7 @@ case "$host_arch" in
         # gcc 3.2 and up supports 970
         if test "$_cc_major" -ge "3" && test "$_cc_minor" -ge "3" || test "$_cc_major" -ge "4"; then
             case "$proc" in
-                970*|PPC970*) _march='-mcpu=970' _mcpu='-mtune=970'
-                      def_dcbzl='#define HAVE_DCBZL 1' ;;
+                970*|PPC970*) _march='-mcpu=970' _mcpu='-mtune=970' ;;
                 *) ;;
             esac
         fi
@@ -2095,18 +2016,6 @@ fi
 echores "$_byte_order"
 
 
-echocheck "extern symbol prefix"
-cat > $TMPC << EOF
-int ff_extern;
-EOF
-cc_check -c || die "Symbol mangling check failed."
-sym=$($_nm -P -g $TMPEXE)
-extern_prefix=${sym%%ff_extern*}
-def_extern_asm="#define EXTERN_ASM $extern_prefix"
-def_extern_prefix="#define EXTERN_PREFIX \"$extern_prefix\""
-echores $extern_prefix
-
-
 echocheck "assembler support of -pipe option"
 # -I. helps to detect compilers that just misunderstand -pipe like Sun C
 cflag_check -pipe -I. && _pipe="-pipe" && echores "yes" || echores "no"
@@ -2191,58 +2100,6 @@ fi
 
 
 
-if x86_32 ; then
-  # Checking assembler (_as) compatibility...
-  # Added workaround for older as that reads from stdin by default - atmos
-  as_version=$(echo '' | $_as -version 2>&1 | sed -n 's/^.*assembler \(version \)*\([0-9.]*\).*$/\2/p')
-  echocheck "assembler ($_as $as_version)"
-
-  _pref_as_version='2.9.1'
-  echo 'nop' > $TMPS
-  if test "$_mmx" = yes ; then
-    echo 'emms' >> $TMPS
-  fi
-  if test "$_3dnow" = yes ; then
-    _pref_as_version='2.10.1'
-    echo 'femms' >> $TMPS
-  fi
-  if test "$_3dnowext" = yes ; then
-    _pref_as_version='2.10.1'
-    echo 'pswapd %mm0, %mm0' >> $TMPS
-  fi
-  if test "$_mmxext" = yes ; then
-    _pref_as_version='2.10.1'
-    echo 'movntq %mm0, (%eax)' >> $TMPS
-  fi
-  if test "$_sse" = yes ; then
-    _pref_as_version='2.10.1'
-    echo 'xorps %xmm0, %xmm0' >> $TMPS
-  fi
-  #if test "$_sse2" = yes ; then
-  #  _pref_as_version='2.11'
-  #  echo 'xorpd %xmm0, %xmm0' >> $TMPS
-  #fi
-  if test "$_cmov" = yes ; then
-    _pref_as_version='2.10.1'
-    echo 'cmovb %eax, %ebx' >> $TMPS
-  fi
-  if test "$_ssse3" = yes ; then
-    _pref_as_version='2.16.92'
-    echo 'pabsd %xmm0, %xmm1' >> $TMPS
-  fi
-  $_as $TMPS -o $TMPEXE > /dev/null 2>&1 || as_verc_fail=yes
-
-  if test "$as_verc_fail" != yes ; then
-    echores "ok"
-  else
-    res_comment="Upgrade binutils to ${_pref_as_version} or use --disable-ssse3 etc."
-    echores "failed"
-    die "obsolete binutils version"
-  fi
-
-fi #if x86_32
-
-
 echocheck "PIC"
 pic=no
 cat > $TMPC << EOF
@@ -2292,48 +2149,8 @@ EOF
 cc_check && ebx_available=yes && def_ebx_available='#define HAVE_EBX_AVAILABLE 1'
 echores $ebx_available
 
-
-echocheck "yasm"
-if test -z "$YASMFLAGS" ; then
-  if darwin ; then
-    x86_64 && objformat="macho64" || objformat="macho"
-  elif win32 ; then
-    objformat="win32"
-  else
-    objformat="elf"
-  fi
-  # currently tested for Linux x86, x86_64
-  YASMFLAGS="-f $objformat"
-  x86_64 && YASMFLAGS="$YASMFLAGS -DARCH_X86_64 -m amd64"
-  test "$pic" = "yes" && YASMFLAGS="$YASMFLAGS -DPIC"
-  case "$objformat" in
-    elf) test $_debug && YASMFLAGS="$YASMFLAGS -g dwarf2" ;;
-    *)                   YASMFLAGS="$YASMFLAGS -DPREFIX"  ;;
-  esac
-else
-  warn_cflags=yes
-fi
-
-echo "pabsw xmm0, xmm0" > $TMPS
-yasm_check || _yasm=""
-if test $_yasm ; then
-  def_yasm='#define HAVE_YASM 1'
-  have_yasm="yes"
-  echores "$_yasm"
-else
-  def_yasm='#define HAVE_YASM 0'
-  have_yasm="no"
-  echores "no"
-fi
-
-echocheck "bswap"
-def_bswap='#define HAVE_BSWAP 0'
-echo 'bswap %eax' > $TMPS
-$_as $TMPS -o $TMPEXE > /dev/null 2>&1 && def_bswap='#define HAVE_BSWAP 1' && bswap=yes || bswap=no
-echores "$bswap"
 fi #if x86
 
-
 #FIXME: This should happen before the check for CFLAGS..
 def_altivec_h='#define HAVE_ALTIVEC_H 0'
 if ppc && ( test "$_altivec" = yes || test "$_runtime_cpudetection" = yes ) ; then
@@ -2377,15 +2194,6 @@ EOF
     test "$_altivec" = yes && CFLAGS="$CFLAGS $_altivec_gcc_flags"
 fi
 
-if ppc ; then
-def_xform_asm='#define HAVE_XFORM_ASM 0'
-xform_asm=no
-echocheck "XFORM ASM support"
-inline_asm_check '"lwzx %1, %y0" :: "Z"(*(int*)0), "r"(0)' &&
-  xform_asm=yes && def_xform_asm='#define HAVE_XFORM_ASM 1'
-echores "$xform_asm"
-fi
-
 if arm ; then
   echocheck "ARMv5TE (Enhanced DSP Extensions)"
   if test $_armv5te = "auto" ; then
@@ -2644,30 +2452,6 @@ if test "$_posix4" = yes ; then
 fi
 echores "$_posix4"
 
-for func in exp2 exp2f llrint log2 log2f lrint lrintf round roundf truncf; do
-echocheck $func
-eval _$func=no
-statement_check math.h "${func}(2.0)" -D_ISOC99_SOURCE $_ld_lm && eval _$func=yes
-if eval test "x\$_$func" = "xyes"; then
-  eval def_$func="\"#define HAVE_$(echo $func | tr '[a-z]' '[A-Z]') 1\""
-  echores yes
-else
-  eval def_$func="\"#define HAVE_$(echo $func | tr '[a-z]' '[A-Z]') 0\""
-  echores no
-fi
-done
-
-
-echocheck "mkstemp"
-_mkstemp=no
-define_statement_check "_XOPEN_SOURCE 600" "stdlib.h" 'mkstemp("")' && _mkstemp=yes
-if test "$_mkstemp" = yes ; then
-  def_mkstemp='#define HAVE_MKSTEMP 1'
-else
-  def_mkstemp='#define HAVE_MKSTEMP 0'
-fi
-echores "$_mkstemp"
-
 
 echocheck "nanosleep"
 _nanosleep=no
@@ -2709,14 +2493,6 @@ else
 fi
 
 
-echocheck "arpa/inet.h"
-arpa_inet_h=no
-def_arpa_inet_h='#define HAVE_ARPA_INET_H 0'
-header_check arpa/inet.h && arpa_inet_h=yes &&
-  def_arpa_inet_h='#define HAVE_ARPA_INET_H 1'
-echores "$arpa_inet_h"
-
-
 echocheck "inet_pton()"
 def_inet_pton='#define HAVE_INET_PTON 0'
 inet_pton=no
@@ -2845,40 +2621,6 @@ if test "$_inttypes" = no ; then
 fi
 
 
-echocheck "malloc.h"
-_malloc=no
-header_check malloc.h && _malloc=yes
-if test "$_malloc" = yes ; then
-  def_malloc_h='#define HAVE_MALLOC_H 1'
-else
-  def_malloc_h='#define HAVE_MALLOC_H 0'
-fi
-echores "$_malloc"
-
-
-echocheck "memalign()"
-# XXX restrict to x86 ? extend to other CPUs/cacheline sizes ?
-def_memalign_hack='#define CONFIG_MEMALIGN_HACK 0'
-_memalign=no
-statement_check malloc.h 'memalign(64, sizeof(char))' && _memalign=yes
-if test "$_memalign" = yes ; then
-  def_memalign='#define HAVE_MEMALIGN 1'
-else
-  def_memalign='#define HAVE_MEMALIGN 0'
-  def_map_memalign='#define memalign(a, b) malloc(b)'
-  darwin || def_memalign_hack='#define CONFIG_MEMALIGN_HACK 1'
-fi
-echores "$_memalign"
-
-
-echocheck "posix_memalign()"
-posix_memalign=no
-def_posix_memalign='#define HAVE_POSIX_MEMALIGN 0'
-define_statement_check "_XOPEN_SOURCE 600" "stdlib.h" 'posix_memalign(NULL, 0, 0)' &&
-    posix_memalign=yes && def_posix_memalign='#define HAVE_POSIX_MEMALIGN 1'
-echores "$posix_memalign"
-
-
 echocheck "alloca.h"
 _alloca=no
 statement_check alloca.h 'alloca(0)' && _alloca=yes
@@ -2930,8 +2672,6 @@ fi
 echores "$_dl"
 
 
-def_threads='#define HAVE_THREADS 0'
-
 echocheck "pthread"
 if linux ; then
   THREAD_CFLAGS=-D_REENTRANT
@@ -2966,12 +2706,11 @@ fi
 if test "$_pthreads" = yes ; then
   test $_ld_pthread && res_comment="using $_ld_pthread"
   def_pthreads='#define HAVE_PTHREADS 1'
-  def_threads='#define HAVE_THREADS 1'
   extra_cflags="$extra_cflags $THREAD_CFLAGS"
 else
-  res_comment="v4l, v4l2, ao_nas, win32 loader disabled"
+  res_comment="v4l2, win32 loader disabled"
   def_pthreads='#undef HAVE_PTHREADS'
-  _nas=no ; _tv_v4l1=no ; _tv_v4l2=no
+  _tv_v4l2=no
   mingw32 || _win32dll=no
 fi
 echores "$_pthreads"
@@ -2994,7 +2733,6 @@ if test "$_w32threads" = auto ; then
   _w32threads=no
   mingw32 && _w32threads=yes
 fi
-test "$_w32threads" = yes && def_threads='#define HAVE_THREADS 1'
 echores "$_w32threads"
 
 echocheck "rpath"
@@ -3798,21 +3536,10 @@ echores "$_xf86keysym"
 echocheck "CACA"
 if test "$_caca" = auto ; then
   _caca=no
-  if ( caca-config --version ) >> "$TMPLOG" 2>&1 ; then
-  cat > $TMPC << EOF
-#include <caca.h>
-#ifdef CACA_API_VERSION_1
-  #include <caca0.h>
-#endif
-int main(void) { caca_init(); return 0; }
-EOF
-  cc_check $(caca-config --libs) && _caca=yes
-  fi
+  pkg_config_add 'caca' && _caca=yes
 fi
 if test "$_caca" = yes ; then
   def_caca='#define CONFIG_CACA 1'
-  extra_cflags="$extra_cflags $(caca-config --cflags)"
-  libs_mplayer="$libs_mplayer $(caca-config --libs)"
   vomodules="caca $vomodules"
 else
   def_caca='#undef CONFIG_CACA'
@@ -5006,9 +4733,7 @@ fi
 echores "$_lcms2"
 
 
-# Test with > against Libav 0.8 versions which will NOT work rather than
-# specify minimum version, to allow (future) point releases to possibly work.
-all_libav_libs="libavutil > 51.21.0:libavcodec > 53.34.0:libavformat > 53.20.0:libswscale >= 2.0.0"
+all_libav_libs="libavutil > 51.21.0:libavcodec >= 54.25.0:libavformat > 53.20.0:libswscale >= 2.0.0"
 echocheck "Libav ($all_libav_libs)"
 if test "$ffmpeg" = auto ; then
   IFS=":"   # shell should not be used for programming
@@ -5018,11 +4743,6 @@ if test "$ffmpeg" = auto ; then
 fi
 echores "yes"
 
-def_ffmpeg_internals="#undef CONFIG_FFMPEG_INTERNALS"
-if ! test -z "$_ffmpeg_source" ; then
-  def_ffmpeg_internals="#define CONFIG_FFMPEG_INTERNALS 1" && ffmpeg_internals=yes
-fi
-
 echocheck "libpostproc >= 52.0.0"
 if test "$libpostproc" = auto ; then
     libpostproc=no
@@ -5217,26 +4937,6 @@ fi
 echores "$_tv_dshow"
 
 
-echocheck "Video 4 Linux TV interface"
-if test "$_tv_v4l1" = auto ; then
-  _tv_v4l1=no
-  if test "$_tv" = yes && linux ; then
-    header_check_broken sys/time.h linux/videodev.h && _tv_v4l1=yes
-  fi
-fi
-if test "$_tv_v4l1" = yes ; then
-  _audio_input=yes
-  _tv_v4l=yes
-  def_tv_v4l='#define CONFIG_TV_V4L 1'
-  def_tv_v4l1='#define CONFIG_TV_V4L1 1'
-  inputmodules="tv-v4l $inputmodules"
-else
-  noinputmodules="tv-v4l1 $noinputmodules"
-  def_tv_v4l='#undef CONFIG_TV_V4L'
-fi
-echores "$_tv_v4l1"
-
-
 echocheck "Video 4 Linux 2 TV interface"
 if test "$_tv_v4l2" = auto ; then
   _tv_v4l2=no
@@ -5248,8 +4948,6 @@ if test "$_tv_v4l2" = auto ; then
 fi
 if test "$_tv_v4l2" = yes ; then
   _audio_input=yes
-  _tv_v4l=yes
-  def_tv_v4l='#define CONFIG_TV_V4L 1'
   def_tv_v4l2='#define CONFIG_TV_V4L2 1'
   inputmodules="tv-v4l2 $inputmodules"
 else
@@ -5296,20 +4994,6 @@ else
 fi
 echores "$_radio_v4l2"
 
-echocheck "Video 4 Linux Radio interface"
-if test "$_radio_v4l" = auto ; then
-  _radio_v4l=no
-  if test "$_radio" = yes && linux ; then
-    header_check linux/videodev.h && _radio_v4l=yes
-  fi
-fi
-if test "$_radio_v4l" = yes ; then
-  def_radio_v4l='#define CONFIG_RADIO_V4L 1'
-else
-  def_radio_v4l='#undef CONFIG_RADIO_V4L'
-fi
-echores "$_radio_v4l"
-
 if freebsd || netbsd || openbsd || dragonfly || bsdos &&
   test "$_radio" = yes && test "$_radio_bsdbt848" = auto ; then
 echocheck "*BSD BrookTree 848 Radio interface"
@@ -5332,9 +5016,9 @@ else
   def_radio_bsdbt848='#undef CONFIG_RADIO_BSDBT848'
 fi
 
-if test "$_radio_v4l" = no && test "$_radio_v4l2" = no &&
+if test "$_radio_v4l2" = no &&
    test "$_radio_bsdbt848" = no && test "$_radio" = yes ; then
-    die "Radio driver requires BSD BT848,  V4L or V4L2!"
+    die "Radio driver requires BSD BT848 or V4L2!"
 fi
 
 echocheck "Video 4 Linux 2 MPEG PVR interface"
@@ -5583,14 +5267,11 @@ MSG_LANG_ALL = $msg_lang_all
 
 prefix  = \$(DESTDIR)$_prefix
 BINDIR  = \$(DESTDIR)$_bindir
-DATADIR = \$(DESTDIR)$_datadir
 LIBDIR  = \$(DESTDIR)$_libdir
 MANDIR  = \$(DESTDIR)$_mandir
 CONFDIR = \$(DESTDIR)$_confdir
 LOCALEDIR = \$(DESTDIR)$_localedir
 
-AR      = $_ar
-AS      = $_cc
 CC      = $_cc
 INSTALL = $_install
 INSTALLSTRIP = $_install_strip
@@ -5709,8 +5390,6 @@ TGA = $_tga
 TV = $_tv
 TV_BSDBT848 = $_tv_bsdbt848
 TV_DSHOW = $_tv_dshow
-TV_V4L  = $_tv_v4l
-TV_V4L1 = $_tv_v4l1
 TV_V4L2 = $_tv_v4l2
 UNRAR_EXEC = $_unrar_exec
 V4L2 = $_v4l2
@@ -5727,21 +5406,12 @@ XV = $_xv
 XVID4 = $_xvid
 YUV4MPEG = $_yuv4mpeg
 
-# FFmpeg
-FFMPEG_INTERNALS = $ffmpeg_internals
-FFMPEG_SOURCE_PATH = $_ffmpeg_source
-
-RANLIB     = $_ranlib
-YASM       = $_yasm
-YASMFLAGS  = $YASMFLAGS
-
 CONFIG_VDPAU    = $_vdpau
 CONFIG_ZLIB     = $_zlib
 
 HAVE_PTHREADS   = $_pthreads
 HAVE_SHM        = $_shm
 HAVE_W32THREADS = $_w32threads
-HAVE_YASM       = $have_yasm
 
 EOF
 
@@ -5775,7 +5445,6 @@ cat > $TMPH << EOF
 
 #define CONFIGURATION "$configuration"
 
-#define MPLAYER_DATADIR "$_datadir"
 #define MPLAYER_CONFDIR "$_confdir"
 #define MPLAYER_LOCALEDIR "$_localedir"
 
@@ -5802,7 +5471,6 @@ $def_dvdcss
 /* system headers */
 $def_alloca_h
 $def_altivec_h
-$def_malloc_h
 $def_mman_h
 $def_mman_has_map_failed
 $def_soundcard_h
@@ -5819,9 +5487,6 @@ $def_gethostbyname2
 $def_gettimeofday
 $def_glob
 $def_langinfo
-$def_lrintf
-$def_map_memalign
-$def_memalign
 $def_nanosleep
 $def_posix_select
 $def_select
@@ -5934,7 +5599,6 @@ $def_xmms
 $def_alsa
 $def_coreaudio
 $def_jack
-$def_nas
 $def_openal
 $def_openal_h
 $def_ossaudio
@@ -5960,13 +5624,10 @@ $def_pvr
 $def_radio
 $def_radio_bsdbt848
 $def_radio_capture
-$def_radio_v4l
 $def_radio_v4l2
 $def_tv
 $def_tv_bsdbt848
 $def_tv_dshow
-$def_tv_v4l
-$def_tv_v4l1
 $def_tv_v4l2
 
 
@@ -6026,32 +5687,9 @@ $def_xv
 $def_yuv4mpeg
 
 
-/* FFmpeg */
-$def_ffmpeg_internals
-
-$def_arpa_inet_h
-$def_bswap
-$def_dcbzl
-$def_exp2
-$def_exp2f
 $def_fast_64bit
 $def_fast_unaligned
-$def_llrint
-$def_log2
-$def_log2f
-$def_lrint
-$def_memalign_hack
-$def_mkstemp
-$def_posix_memalign
 $def_pthreads
-$def_round
-$def_roundf
-$def_threads
-$def_truncf
-$def_xform_asm
-$def_yasm
-
-#define HAVE_INLINE_ASM 1
 
 /* Use these registers in x86 inline asm. No proper detection yet. */
 #define HAVE_EBP_AVAILABLE 1
@@ -6069,7 +5707,6 @@ cat << EOF
 Config files successfully generated by ./configure $configuration !
 
   Install prefix: $_prefix
-  Data directory: $_datadir
   Config direct.: $_confdir
 
   Byte order: $_byte_order
@@ -6123,7 +5760,7 @@ EOF
 if test "$warn_cflags" = yes; then
   cat <<EOF
 
-MPlayer compilation will use the CPPFLAGS/CFLAGS/LDFLAGS/YASMFLAGS set by you,
+MPlayer compilation will use the CPPFLAGS/CFLAGS/LDFLAGS set by you,
 but:
 
     *** ***  DO NOT REPORT BUGS IF IT DOES NOT COMPILE/WORK!  *** ***
diff --git a/input/input.c b/input/input.c
index d7c260f..ed4e933 100644
--- a/input/input.c
+++ b/input/input.c
@@ -548,7 +548,7 @@ static char *get_key_combo_name(int *keys, int max)
     while (1) {
         ret = get_key_name(*keys, ret);
         if (--max && *++keys)
-            talloc_asprintf_append_buffer(ret, "-");
+            ret = talloc_asprintf_append_buffer(ret, "-");
         else
             break;
     }
@@ -1658,9 +1658,9 @@ void mp_input_register_options(m_config_t *cfg)
 static int print_key_list(m_option_t *cfg, char *optname, char *optparam)
 {
     int i;
-    printf("\n");
+    mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
     for (i = 0; key_names[i].name != NULL; i++)
-        printf("%s\n", key_names[i].name);
+        mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s\n", key_names[i].name);
     return M_OPT_EXIT;
 }
 
@@ -1671,7 +1671,7 @@ static int print_cmd_list(m_option_t *cfg, char *optname, char *optparam)
     const char *type;
 
     for (i = 0; (cmd = &mp_cmds[i])->name != NULL; i++) {
-        printf("%-20.20s", cmd->name);
+        mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%-20.20s", cmd->name);
         for (j = 0; j < MP_CMD_MAX_ARGS && cmd->args[j].type; j++) {
             switch (cmd->args[j].type) {
             case MP_CMD_ARG_INT:
@@ -1687,11 +1687,11 @@ static int print_cmd_list(m_option_t *cfg, char *optname, char *optparam)
                 type = "??";
             }
             if (cmd->args[j].optional)
-                printf(" [%s]", type);
+                mp_msg(MSGT_CFGPARSER, MSGL_INFO, " [%s]", type);
             else
-                printf(" %s", type);
+                mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", type);
         }
-        printf("\n");
+        mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
     }
     return M_OPT_EXIT;
 }
diff --git a/libmpcodecs/ad_ffmpeg.c b/libmpcodecs/ad_ffmpeg.c
index 19c2f87..2b85b6d 100644
--- a/libmpcodecs/ad_ffmpeg.c
+++ b/libmpcodecs/ad_ffmpeg.c
@@ -175,7 +175,7 @@ static int setup_format(sh_audio_t *sh_audio)
     int container_samplerate = sh_audio->container_out_samplerate;
     if (!container_samplerate && sh_audio->wf)
         container_samplerate = sh_audio->wf->nSamplesPerSec;
-    if (codec->codec_id == CODEC_ID_AAC
+    if (codec->codec_id == AV_CODEC_ID_AAC
         && samplerate == 2 * container_samplerate)
         broken_srate = true;
     else if (container_samplerate)
diff --git a/libmpcodecs/vd_dmo.c b/libmpcodecs/vd_dmo.c
index 31d9f1e..e300edd 100644
--- a/libmpcodecs/vd_dmo.c
+++ b/libmpcodecs/vd_dmo.c
@@ -18,9 +18,6 @@
 
 #include "config.h"
 
-#if HAVE_MALLOC_H
-#include <malloc.h>
-#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c
index 0de4d41..e8f5d9c 100644
--- a/libmpcodecs/vd_ffmpeg.c
+++ b/libmpcodecs/vd_ffmpeg.c
@@ -97,7 +97,6 @@ const m_option_t lavc_decode_opts_conf[] = {
     OPT_INTRANGE("st", lavc_param.skip_top, 0, 0, 999),
     OPT_INTRANGE("sb", lavc_param.skip_bottom, 0, 0, 999),
     OPT_FLAG_CONSTANTS("fast", lavc_param.fast, 0, 0, CODEC_FLAG2_FAST),
-    OPT_STRING("lowres", lavc_param.lowres_str, 0),
     OPT_STRING("skiploopfilter", lavc_param.skip_loop_filter_str, 0),
     OPT_STRING("skipidct", lavc_param.skip_idct_str, 0),
     OPT_STRING("skipframe", lavc_param.skip_frame_str, 0),
@@ -163,10 +162,10 @@ static int init(sh_video_t *sh)
         ctx->do_slices = 1;
 
     if (lavc_codec->capabilities & CODEC_CAP_DR1 && !do_vis_debug
-            && lavc_codec->id != CODEC_ID_H264
-            && lavc_codec->id != CODEC_ID_INTERPLAY_VIDEO
-            && lavc_codec->id != CODEC_ID_ROQ && lavc_codec->id != CODEC_ID_VP8
-            && lavc_codec->id != CODEC_ID_LAGARITH)
+            && lavc_codec->id != AV_CODEC_ID_H264
+            && lavc_codec->id != AV_CODEC_ID_INTERPLAY_VIDEO
+            && lavc_codec->id != AV_CODEC_ID_ROQ && lavc_codec->id != AV_CODEC_ID_VP8
+            && lavc_codec->id != AV_CODEC_ID_LAGARITH)
         ctx->do_dr1 = 1;
     ctx->ip_count = ctx->b_count = 0;
 
@@ -237,14 +236,6 @@ static int init(sh_video_t *sh)
     avctx->debug_mv = lavc_param->vismv;
     avctx->skip_top   = lavc_param->skip_top;
     avctx->skip_bottom = lavc_param->skip_bottom;
-    if (lavc_param->lowres_str != NULL) {
-        int lowres, lowres_w;
-        sscanf(lavc_param->lowres_str, "%d,%d", &lowres, &lowres_w);
-        if (lowres < 1 || lowres > 16 ||
-                lowres_w > 0 && avctx->width < lowres_w)
-            lowres = 0;
-        avctx->lowres = lowres;
-    }
     avctx->skip_loop_filter = str2AVDiscard(lavc_param->skip_loop_filter_str);
     avctx->skip_idct = str2AVDiscard(lavc_param->skip_idct_str);
     avctx->skip_frame = str2AVDiscard(lavc_param->skip_frame_str);
@@ -447,8 +438,8 @@ static int init_vo(sh_video_t *sh, enum PixelFormat pix_fmt)
     // if sh->ImageDesc is non-NULL, it means we decode QuickTime(tm) video.
     // use dimensions from BIH to avoid black borders at the right and bottom.
     if (sh->bih && sh->ImageDesc) {
-        width = sh->bih->biWidth >> avctx->lowres;
-        height = sh->bih->biHeight >> avctx->lowres;
+        width = sh->bih->biWidth;
+        height = sh->bih->biHeight;
     }
 
     /* Reconfiguring filter/VO chain may invalidate direct rendering buffers
@@ -728,8 +719,8 @@ static struct mp_image *decode(struct sh_video *sh, struct demux_packet *packet,
         // average MB quantizer
         {
             int x, y;
-            int w = ((avctx->width << avctx->lowres) + 15) >> 4;
-            int h = ((avctx->height << avctx->lowres) + 15) >> 4;
+            int w = (avctx->width + 15) >> 4;
+            int h = (avctx->height + 15) >> 4;
             int8_t *q = pic->qscale_table;
             for (y = 0; y < h; y++) {
                 for (x = 0; x < w; x++)
diff --git a/libmpcodecs/vf.c b/libmpcodecs/vf.c
index f4d6768..45a93ef 100644
--- a/libmpcodecs/vf.c
+++ b/libmpcodecs/vf.c
@@ -22,9 +22,6 @@
 #include <assert.h>
 
 #include "config.h"
-#if HAVE_MALLOC_H
-#include <malloc.h>
-#endif
 
 #include "mp_msg.h"
 #include "m_option.h"
@@ -93,8 +90,6 @@ extern const vf_info_t vf_info_tile;
 extern const vf_info_t vf_info_delogo;
 extern const vf_info_t vf_info_remove_logo;
 extern const vf_info_t vf_info_hue;
-extern const vf_info_t vf_info_spp;
-extern const vf_info_t vf_info_uspp;
 extern const vf_info_t vf_info_fspp;
 extern const vf_info_t vf_info_pp7;
 extern const vf_info_t vf_info_yuvcsp;
@@ -107,7 +102,6 @@ extern const vf_info_t vf_info_harddup;
 extern const vf_info_t vf_info_softskip;
 extern const vf_info_t vf_info_screenshot;
 extern const vf_info_t vf_info_ass;
-extern const vf_info_t vf_info_mcdeint;
 extern const vf_info_t vf_info_yadif;
 extern const vf_info_t vf_info_blackframe;
 extern const vf_info_t vf_info_geq;
@@ -141,7 +135,6 @@ static const vf_info_t *const filter_list[] = {
     &vf_info_lavcdeint,
     &vf_info_screenshot,
     &vf_info_fspp,
-    &vf_info_uspp,
 
     &vf_info_dvbscale,
     &vf_info_cropdetect,
@@ -183,10 +176,6 @@ static const vf_info_t *const filter_list[] = {
     &vf_info_delogo,
     &vf_info_remove_logo,
     &vf_info_hue,
-#ifdef CONFIG_FFMPEG_INTERNALS
-    &vf_info_spp,
-    &vf_info_mcdeint,
-#endif
     &vf_info_geq,
     &vf_info_qp,
     &vf_info_yuvcsp,
diff --git a/libmpcodecs/vf_mcdeint.c b/libmpcodecs/vf_mcdeint.c
deleted file mode 100644
index 82635e5..0000000
--- a/libmpcodecs/vf_mcdeint.c
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * Copyright (C) 2006 Michael Niedermayer <michaelni at gmx.at>
- *
- * 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.
- */
-
-
-/*
-Known Issues:
-* The motion estimation is somewhat at the mercy of the input, if the input
-  frames are created purely based on spatial interpolation then for example
-  a thin black line or another random and not interpolateable pattern
-  will cause problems
-  Note: completly ignoring the "unavailable" lines during motion estimation
-  didnt look any better, so the most obvious solution would be to improve
-  tfields or penalize problematic motion vectors ...
-
-* If non iterative ME is used then snow currently ignores the OBMC window
-  and as a result sometimes creates artifacts
-
-* only past frames are used, we should ideally use future frames too, something
-  like filtering the whole movie in forward and then backward direction seems
-  like a interresting idea but the current filter framework is FAR from
-  supporting such things
-
-* combining the motion compensated image with the input image also isnt
-  as trivial as it seems, simple blindly taking even lines from one and
-  odd ones from the other doesnt work at all as ME/MC sometimes simple
-  has nothing in the previous frames which matches the current, the current
-  algo has been found by trial and error and almost certainly can be
-  improved ...
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include <math.h>
-
-#include "mp_msg.h"
-#include "cpudetect.h"
-
-#include "libavutil/intreadwrite.h"
-#include "libavcodec/avcodec.h"
-#include "libavcodec/dsputil.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-#define MIN(a,b) ((a) > (b) ? (b) : (a))
-#define MAX(a,b) ((a) < (b) ? (b) : (a))
-#define ABS(a) ((a) > 0 ? (a) : (-(a)))
-
-//===========================================================================//
-
-struct vf_priv_s {
-    int mode;
-    int qp;
-    int parity;
-#if 0
-    int temp_stride[3];
-    uint8_t *src[3];
-    int16_t *temp[3];
-#endif
-    int outbuf_size;
-    uint8_t *outbuf;
-    AVCodecContext *avctx_enc;
-    AVFrame *frame;
-    AVFrame *frame_dec;
-};
-
-static void filter(struct vf_priv_s *p, uint8_t *dst[3], uint8_t *src[3], int dst_stride[3], int src_stride[3], int width, int height){
-    int x, y, i;
-    int out_size;
-
-    for(i=0; i<3; i++){
-        p->frame->data[i]= src[i];
-        p->frame->linesize[i]= src_stride[i];
-    }
-
-    p->avctx_enc->me_cmp=
-    p->avctx_enc->me_sub_cmp= FF_CMP_SAD /*| (p->parity ? FF_CMP_ODD : FF_CMP_EVEN)*/;
-    p->frame->quality= p->qp*FF_QP2LAMBDA;
-    out_size = avcodec_encode_video(p->avctx_enc, p->outbuf, p->outbuf_size, p->frame);
-    p->frame_dec = p->avctx_enc->coded_frame;
-
-    for(i=0; i<3; i++){
-        int is_chroma= !!i;
-        int w= width >>is_chroma;
-        int h= height>>is_chroma;
-        int fils= p->frame_dec->linesize[i];
-        int srcs= src_stride[i];
-
-        for(y=0; y<h; y++){
-            if((y ^ p->parity) & 1){
-                for(x=0; x<w; x++){
-                    if((x-2)+(y-1)*w>=0 && (x+2)+(y+1)*w<w*h){ //FIXME either alloc larger images or optimize this
-                        uint8_t *filp= &p->frame_dec->data[i][x + y*fils];
-                        uint8_t *srcp= &src[i][x + y*srcs];
-                        int diff0= filp[-fils] - srcp[-srcs];
-                        int diff1= filp[+fils] - srcp[+srcs];
-                        int spatial_score= ABS(srcp[-srcs-1] - srcp[+srcs-1])
-                                          +ABS(srcp[-srcs  ] - srcp[+srcs  ])
-                                          +ABS(srcp[-srcs+1] - srcp[+srcs+1]) - 1;
-                        int temp= filp[0];
-
-#define CHECK(j)\
-    {   int score= ABS(srcp[-srcs-1+j] - srcp[+srcs-1-j])\
-                 + ABS(srcp[-srcs  +j] - srcp[+srcs  -j])\
-                 + ABS(srcp[-srcs+1+j] - srcp[+srcs+1-j]);\
-        if(score < spatial_score){\
-            spatial_score= score;\
-            diff0= filp[-fils+j] - srcp[-srcs+j];\
-            diff1= filp[+fils-j] - srcp[+srcs-j];
-
-                        CHECK(-1) CHECK(-2) }} }}
-                        CHECK( 1) CHECK( 2) }} }}
-#if 0
-                        if((diff0 ^ diff1) > 0){
-                            int mindiff= ABS(diff0) > ABS(diff1) ? diff1 : diff0;
-                            temp-= mindiff;
-                        }
-#elif 1
-                        if(diff0 + diff1 > 0)
-                            temp-= (diff0 + diff1 - ABS( ABS(diff0) - ABS(diff1) )/2)/2;
-                        else
-                            temp-= (diff0 + diff1 + ABS( ABS(diff0) - ABS(diff1) )/2)/2;
-#else
-                        temp-= (diff0 + diff1)/2;
-#endif
-#if 1
-                        filp[0]=
-                        dst[i][x + y*dst_stride[i]]= temp > 255U ? ~(temp>>31) : temp;
-#else
-                        dst[i][x + y*dst_stride[i]]= filp[0];
-                        filp[0]= temp > 255U ? ~(temp>>31) : temp;
-#endif
-                    }else
-                        dst[i][x + y*dst_stride[i]]= p->frame_dec->data[i][x + y*fils];
-                }
-            }
-        }
-        for(y=0; y<h; y++){
-            if(!((y ^ p->parity) & 1)){
-                for(x=0; x<w; x++){
-#if 1
-                    p->frame_dec->data[i][x + y*fils]=
-                    dst[i][x + y*dst_stride[i]]= src[i][x + y*srcs];
-#else
-                    dst[i][x + y*dst_stride[i]]= p->frame_dec->data[i][x + y*fils];
-                    p->frame_dec->data[i][x + y*fils]= src[i][x + y*srcs];
-#endif
-                }
-            }
-        }
-    }
-    p->parity ^= 1;
-
-}
-
-static int config(struct vf_instance *vf,
-        int width, int height, int d_width, int d_height,
-	unsigned int flags, unsigned int outfmt){
-        int i;
-        AVCodec *enc= avcodec_find_encoder(CODEC_ID_SNOW);
-
-        for(i=0; i<3; i++){
-            AVCodecContext *avctx_enc;
-#if 0
-            int is_chroma= !!i;
-            int w= ((width  + 31) & (~31))>>is_chroma;
-            int h= ((height + 31) & (~31))>>is_chroma;
-
-            vf->priv->temp_stride[i]= w;
-            vf->priv->temp[i]= malloc(vf->priv->temp_stride[i]*h*sizeof(int16_t));
-            vf->priv->src [i]= malloc(vf->priv->temp_stride[i]*h*sizeof(uint8_t));
-#endif
-            avctx_enc=
-            vf->priv->avctx_enc= avcodec_alloc_context();
-            avctx_enc->width = width;
-            avctx_enc->height = height;
-            avctx_enc->time_base= (AVRational){1,25};  // meaningless
-            avctx_enc->gop_size = 300;
-            avctx_enc->max_b_frames= 0;
-            avctx_enc->pix_fmt = PIX_FMT_YUV420P;
-            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;
-            avctx_enc->me_cmp=
-            avctx_enc->me_sub_cmp= FF_CMP_SAD; //SSE;
-            avctx_enc->mb_cmp= FF_CMP_SSE;
-
-            switch(vf->priv->mode){
-            case 3:
-                avctx_enc->refs= 3;
-            case 2:
-                avctx_enc->me_method= ME_ITER;
-            case 1:
-                avctx_enc->flags |= CODEC_FLAG_4MV;
-                avctx_enc->dia_size=2;
-//                avctx_enc->mb_decision = MB_DECISION_RD;
-            case 0:
-                avctx_enc->flags |= CODEC_FLAG_QPEL;
-            }
-
-            avcodec_open(avctx_enc, enc);
-
-        }
-        vf->priv->frame= avcodec_alloc_frame();
-
-        vf->priv->outbuf_size= width*height*10;
-        vf->priv->outbuf= malloc(vf->priv->outbuf_size);
-
-	return 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
-return; //caused problems, dunno why
-    // ok, we can do pp in-place (or pp disabled):
-    vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
-        mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
-    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:
-        dmpi=vf_get_image(vf->next,mpi->imgfmt,
-            MP_IMGTYPE_TEMP,
-            MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
-            mpi->width,mpi->height);
-        vf_clone_mpi_attributes(dmpi, mpi);
-    }else{
-        dmpi=vf->dmpi;
-    }
-
-    filter(vf->priv, dmpi->planes, mpi->planes, dmpi->stride, mpi->stride, mpi->w, mpi->h);
-
-    return vf_next_put_image(vf,dmpi, pts);
-}
-
-static void uninit(struct vf_instance *vf){
-    if(!vf->priv) return;
-
-#if 0
-    for(i=0; i<3; i++){
-        free(vf->priv->temp[i]);
-        vf->priv->temp[i]= NULL;
-        free(vf->priv->src[i]);
-        vf->priv->src[i]= NULL;
-    }
-#endif
-    if (vf->priv->avctx_enc) {
-    avcodec_close(vf->priv->avctx_enc);
-    av_freep(&vf->priv->avctx_enc);
-    }
-
-    free(vf->priv->outbuf);
-    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:
-	case IMGFMT_Y800:
-	case IMGFMT_Y8:
-	    return vf_next_query_format(vf,fmt);
-    }
-    return 0;
-}
-
-static int vf_open(vf_instance_t *vf, char *args){
-
-    vf->config=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));
-
-    vf->priv->mode=0;
-    vf->priv->parity= -1;
-    vf->priv->qp=1;
-
-    if (args) sscanf(args, "%d:%d:%d", &vf->priv->mode, &vf->priv->parity, &vf->priv->qp);
-
-    return 1;
-}
-
-const vf_info_t vf_info_mcdeint = {
-    "motion compensating deinterlacer",
-    "mcdeint",
-    "Michael Niedermayer",
-    "",
-    vf_open,
-    NULL
-};
diff --git a/libmpcodecs/vf_noise.c b/libmpcodecs/vf_noise.c
index f8d4c2e..c623e11 100644
--- a/libmpcodecs/vf_noise.c
+++ b/libmpcodecs/vf_noise.c
@@ -28,10 +28,6 @@
 #include "mp_msg.h"
 #include "cpudetect.h"
 
-#if HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
diff --git a/libmpcodecs/vf_perspective.c b/libmpcodecs/vf_perspective.c
index b835e6b..df196bb 100644
--- a/libmpcodecs/vf_perspective.c
+++ b/libmpcodecs/vf_perspective.c
@@ -28,10 +28,6 @@
 #include "config.h"
 #include "mp_msg.h"
 
-#if HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
 #include "libavutil/mem.h"
 
 #include "img_format.h"
diff --git a/libmpcodecs/vf_pp.c b/libmpcodecs/vf_pp.c
index 694fa09..4bf649c 100644
--- a/libmpcodecs/vf_pp.c
+++ b/libmpcodecs/vf_pp.c
@@ -26,10 +26,6 @@
 #include "mp_msg.h"
 #include "cpudetect.h"
 
-#if HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
diff --git a/libmpcodecs/vf_pp7.c b/libmpcodecs/vf_pp7.c
index 1c0274d..0a30022 100644
--- a/libmpcodecs/vf_pp7.c
+++ b/libmpcodecs/vf_pp7.c
@@ -30,10 +30,6 @@
 #include "mp_msg.h"
 #include "cpudetect.h"
 
-#if HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
 #include "libavutil/mem.h"
 
 #include "img_format.h"
diff --git a/libmpcodecs/vf_sab.c b/libmpcodecs/vf_sab.c
index 1f2b17a..33f6754 100644
--- a/libmpcodecs/vf_sab.c
+++ b/libmpcodecs/vf_sab.c
@@ -30,10 +30,6 @@
 #include "config.h"
 #include "mp_msg.h"
 
-#if HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
diff --git a/libmpcodecs/vf_spp.c b/libmpcodecs/vf_spp.c
deleted file mode 100644
index 2402d72..0000000
--- a/libmpcodecs/vf_spp.c
+++ /dev/null
@@ -1,612 +0,0 @@
-/*
- * Copyright (C) 2003 Michael Niedermayer <michaelni at gmx.at>
- *
- * 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.
- */
-
-/*
- * This implementation is based on an algorithm described in
- * "Aria Nosratinia Embedded Post-Processing for
- * Enhancement of Compressed Images (1999)"
- * (http://citeseer.nj.nec.com/nosratinia99embedded.html)
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include <math.h>
-
-#include "config.h"
-
-#include "mp_msg.h"
-#include "cpudetect.h"
-
-#include "libavutil/intreadwrite.h"
-#include "libavcodec/avcodec.h"
-#include "libavcodec/dsputil.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-#include "libvo/fastmemcpy.h"
-
-#define XMIN(a,b) ((a) < (b) ? (a) : (b))
-
-//===========================================================================//
-static const uint8_t  __attribute__((aligned(8))) dither[8][8]={
-{  0,  48,  12,  60,   3,  51,  15,  63, },
-{ 32,  16,  44,  28,  35,  19,  47,  31, },
-{  8,  56,   4,  52,  11,  59,   7,  55, },
-{ 40,  24,  36,  20,  43,  27,  39,  23, },
-{  2,  50,  14,  62,   1,  49,  13,  61, },
-{ 34,  18,  46,  30,  33,  17,  45,  29, },
-{ 10,  58,   6,  54,   9,  57,   5,  53, },
-{ 42,  26,  38,  22,  41,  25,  37,  21, },
-};
-
-static const uint8_t offset[127][2]= {
-{0,0},
-{0,0}, {4,4},
-{0,0}, {2,2}, {6,4}, {4,6},
-{0,0}, {5,1}, {2,2}, {7,3}, {4,4}, {1,5}, {6,6}, {3,7},
-
-{0,0}, {4,0}, {1,1}, {5,1}, {3,2}, {7,2}, {2,3}, {6,3},
-{0,4}, {4,4}, {1,5}, {5,5}, {3,6}, {7,6}, {2,7}, {6,7},
-
-{0,0}, {0,2}, {0,4}, {0,6}, {1,1}, {1,3}, {1,5}, {1,7},
-{2,0}, {2,2}, {2,4}, {2,6}, {3,1}, {3,3}, {3,5}, {3,7},
-{4,0}, {4,2}, {4,4}, {4,6}, {5,1}, {5,3}, {5,5}, {5,7},
-{6,0}, {6,2}, {6,4}, {6,6}, {7,1}, {7,3}, {7,5}, {7,7},
-
-{0,0}, {4,4}, {0,4}, {4,0}, {2,2}, {6,6}, {2,6}, {6,2},
-{0,2}, {4,6}, {0,6}, {4,2}, {2,0}, {6,4}, {2,4}, {6,0},
-{1,1}, {5,5}, {1,5}, {5,1}, {3,3}, {7,7}, {3,7}, {7,3},
-{1,3}, {5,7}, {1,7}, {5,3}, {3,1}, {7,5}, {3,5}, {7,1},
-{0,1}, {4,5}, {0,5}, {4,1}, {2,3}, {6,7}, {2,7}, {6,3},
-{0,3}, {4,7}, {0,7}, {4,3}, {2,1}, {6,5}, {2,5}, {6,1},
-{1,0}, {5,4}, {1,4}, {5,0}, {3,2}, {7,6}, {3,6}, {7,2},
-{1,2}, {5,6}, {1,6}, {5,2}, {3,0}, {7,4}, {3,4}, {7,0},
-};
-
-struct vf_priv_s {
-	int log2_count;
-	int qp;
-	int mode;
-	int mpeg2;
-	int temp_stride;
-	uint8_t *src;
-	int16_t *temp;
-	AVCodecContext *avctx;
-	DSPContext dsp;
-        char *non_b_qp;
-};
-
-#define SHIFT 22
-
-static void hardthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
-	int i;
-	int bias= 0; //FIXME
-	unsigned int threshold1, threshold2;
-
-	threshold1= qp*((1<<4) - bias) - 1;
-	threshold2= (threshold1<<1);
-
-	memset(dst, 0, 64*sizeof(DCTELEM));
-	dst[0]= (src[0] + 4)>>3;
-
-        for(i=1; i<64; i++){
-		int level= src[i];
-		if(((unsigned)(level+threshold1))>threshold2){
-			const int j= permutation[i];
-			dst[j]= (level + 4)>>3;
-		}
-	}
-}
-
-static void softthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
-	int i;
-	int bias= 0; //FIXME
-	unsigned int threshold1, threshold2;
-
-	threshold1= qp*((1<<4) - bias) - 1;
-	threshold2= (threshold1<<1);
-
-	memset(dst, 0, 64*sizeof(DCTELEM));
-	dst[0]= (src[0] + 4)>>3;
-
-        for(i=1; i<64; i++){
-		int level= src[i];
-		if(((unsigned)(level+threshold1))>threshold2){
-			const int j= permutation[i];
-			if(level>0)
-				dst[j]= (level - threshold1 + 4)>>3;
-			else
-				dst[j]= (level + threshold1 + 4)>>3;
-		}
-	}
-}
-
-#if HAVE_MMX
-static void hardthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
-	int bias= 0; //FIXME
-	unsigned int threshold1;
-
-	threshold1= qp*((1<<4) - bias) - 1;
-
-        __asm__ volatile(
-#define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \
-		"movq " #src0 ", %%mm0	\n\t"\
-		"movq " #src1 ", %%mm1	\n\t"\
-		"movq " #src2 ", %%mm2	\n\t"\
-		"movq " #src3 ", %%mm3	\n\t"\
-		"psubw %%mm4, %%mm0	\n\t"\
-		"psubw %%mm4, %%mm1	\n\t"\
-		"psubw %%mm4, %%mm2	\n\t"\
-		"psubw %%mm4, %%mm3	\n\t"\
-		"paddusw %%mm5, %%mm0	\n\t"\
-		"paddusw %%mm5, %%mm1	\n\t"\
-		"paddusw %%mm5, %%mm2	\n\t"\
-		"paddusw %%mm5, %%mm3	\n\t"\
-		"paddw %%mm6, %%mm0	\n\t"\
-		"paddw %%mm6, %%mm1	\n\t"\
-		"paddw %%mm6, %%mm2	\n\t"\
-		"paddw %%mm6, %%mm3	\n\t"\
-		"psubusw %%mm6, %%mm0	\n\t"\
-		"psubusw %%mm6, %%mm1	\n\t"\
-		"psubusw %%mm6, %%mm2	\n\t"\
-		"psubusw %%mm6, %%mm3	\n\t"\
-		"psraw $3, %%mm0	\n\t"\
-		"psraw $3, %%mm1	\n\t"\
-		"psraw $3, %%mm2	\n\t"\
-		"psraw $3, %%mm3	\n\t"\
-\
-		"movq %%mm0, %%mm7	\n\t"\
-		"punpcklwd %%mm2, %%mm0	\n\t" /*A*/\
-		"punpckhwd %%mm2, %%mm7	\n\t" /*C*/\
-		"movq %%mm1, %%mm2	\n\t"\
-		"punpcklwd %%mm3, %%mm1	\n\t" /*B*/\
-		"punpckhwd %%mm3, %%mm2	\n\t" /*D*/\
-		"movq %%mm0, %%mm3	\n\t"\
-		"punpcklwd %%mm1, %%mm0	\n\t" /*A*/\
-		"punpckhwd %%mm7, %%mm3	\n\t" /*C*/\
-		"punpcklwd %%mm2, %%mm7	\n\t" /*B*/\
-		"punpckhwd %%mm2, %%mm1	\n\t" /*D*/\
-\
-		"movq %%mm0, " #dst0 "	\n\t"\
-		"movq %%mm7, " #dst1 "	\n\t"\
-		"movq %%mm3, " #dst2 "	\n\t"\
-		"movq %%mm1, " #dst3 "	\n\t"
-
-		"movd %2, %%mm4		\n\t"
-		"movd %3, %%mm5		\n\t"
-		"movd %4, %%mm6		\n\t"
-		"packssdw %%mm4, %%mm4	\n\t"
-		"packssdw %%mm5, %%mm5	\n\t"
-		"packssdw %%mm6, %%mm6	\n\t"
-		"packssdw %%mm4, %%mm4	\n\t"
-		"packssdw %%mm5, %%mm5	\n\t"
-		"packssdw %%mm6, %%mm6	\n\t"
-		REQUANT_CORE(  (%1),  8(%1), 16(%1), 24(%1),  (%0), 8(%0), 64(%0), 72(%0))
-		REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0))
-		REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0))
-		REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0))
-		: : "r" (src), "r" (dst), "g" (threshold1+1), "g" (threshold1+5), "g" (threshold1-4) //FIXME maybe more accurate then needed?
-	);
-	dst[0]= (src[0] + 4)>>3;
-}
-
-static void softthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
-	int bias= 0; //FIXME
-	unsigned int threshold1;
-
-	threshold1= qp*((1<<4) - bias) - 1;
-
-        __asm__ volatile(
-#undef REQUANT_CORE
-#define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \
-		"movq " #src0 ", %%mm0	\n\t"\
-		"movq " #src1 ", %%mm1	\n\t"\
-		"pxor %%mm6, %%mm6	\n\t"\
-		"pxor %%mm7, %%mm7	\n\t"\
-		"pcmpgtw %%mm0, %%mm6	\n\t"\
-		"pcmpgtw %%mm1, %%mm7	\n\t"\
-		"pxor %%mm6, %%mm0	\n\t"\
-		"pxor %%mm7, %%mm1	\n\t"\
-		"psubusw %%mm4, %%mm0	\n\t"\
-		"psubusw %%mm4, %%mm1	\n\t"\
-		"pxor %%mm6, %%mm0	\n\t"\
-		"pxor %%mm7, %%mm1	\n\t"\
-		"movq " #src2 ", %%mm2	\n\t"\
-		"movq " #src3 ", %%mm3	\n\t"\
-		"pxor %%mm6, %%mm6	\n\t"\
-		"pxor %%mm7, %%mm7	\n\t"\
-		"pcmpgtw %%mm2, %%mm6	\n\t"\
-		"pcmpgtw %%mm3, %%mm7	\n\t"\
-		"pxor %%mm6, %%mm2	\n\t"\
-		"pxor %%mm7, %%mm3	\n\t"\
-		"psubusw %%mm4, %%mm2	\n\t"\
-		"psubusw %%mm4, %%mm3	\n\t"\
-		"pxor %%mm6, %%mm2	\n\t"\
-		"pxor %%mm7, %%mm3	\n\t"\
-\
-		"paddsw %%mm5, %%mm0	\n\t"\
-		"paddsw %%mm5, %%mm1	\n\t"\
-		"paddsw %%mm5, %%mm2	\n\t"\
-		"paddsw %%mm5, %%mm3	\n\t"\
-		"psraw $3, %%mm0	\n\t"\
-		"psraw $3, %%mm1	\n\t"\
-		"psraw $3, %%mm2	\n\t"\
-		"psraw $3, %%mm3	\n\t"\
-\
-		"movq %%mm0, %%mm7	\n\t"\
-		"punpcklwd %%mm2, %%mm0	\n\t" /*A*/\
-		"punpckhwd %%mm2, %%mm7	\n\t" /*C*/\
-		"movq %%mm1, %%mm2	\n\t"\
-		"punpcklwd %%mm3, %%mm1	\n\t" /*B*/\
-		"punpckhwd %%mm3, %%mm2	\n\t" /*D*/\
-		"movq %%mm0, %%mm3	\n\t"\
-		"punpcklwd %%mm1, %%mm0	\n\t" /*A*/\
-		"punpckhwd %%mm7, %%mm3	\n\t" /*C*/\
-		"punpcklwd %%mm2, %%mm7	\n\t" /*B*/\
-		"punpckhwd %%mm2, %%mm1	\n\t" /*D*/\
-\
-		"movq %%mm0, " #dst0 "	\n\t"\
-		"movq %%mm7, " #dst1 "	\n\t"\
-		"movq %%mm3, " #dst2 "	\n\t"\
-		"movq %%mm1, " #dst3 "	\n\t"
-
-		"movd %2, %%mm4		\n\t"
-		"movd %3, %%mm5		\n\t"
-		"packssdw %%mm4, %%mm4	\n\t"
-		"packssdw %%mm5, %%mm5	\n\t"
-		"packssdw %%mm4, %%mm4	\n\t"
-		"packssdw %%mm5, %%mm5	\n\t"
-		REQUANT_CORE(  (%1),  8(%1), 16(%1), 24(%1),  (%0), 8(%0), 64(%0), 72(%0))
-		REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0))
-		REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0))
-		REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0))
-		: : "r" (src), "r" (dst), "g" (threshold1), "rm" (4) //FIXME maybe more accurate then needed?
-	);
-
-	dst[0]= (src[0] + 4)>>3;
-}
-#endif
-
-static inline void add_block(int16_t *dst, int stride, DCTELEM block[64]){
-	int y;
-
-	for(y=0; y<8; y++){
-		*(uint32_t*)&dst[0 + y*stride]+= *(uint32_t*)&block[0 + y*8];
-		*(uint32_t*)&dst[2 + y*stride]+= *(uint32_t*)&block[2 + y*8];
-		*(uint32_t*)&dst[4 + y*stride]+= *(uint32_t*)&block[4 + y*8];
-		*(uint32_t*)&dst[6 + y*stride]+= *(uint32_t*)&block[6 + y*8];
-	}
-}
-
-static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){
-	int y, x;
-
-#define STORE(pos) \
-	temp= ((src[x + y*src_stride + pos]<<log2_scale) + d[pos])>>6;\
-	if(temp & 0x100) temp= ~(temp>>31);\
-	dst[x + y*dst_stride + pos]= temp;
-
-	for(y=0; y<height; y++){
-		const uint8_t *d= dither[y];
-		for(x=0; x<width; x+=8){
-			int temp;
-			STORE(0);
-			STORE(1);
-			STORE(2);
-			STORE(3);
-			STORE(4);
-			STORE(5);
-			STORE(6);
-			STORE(7);
-		}
-	}
-}
-
-#if HAVE_MMX
-static void store_slice_mmx(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){
-	int y;
-
-	for(y=0; y<height; y++){
-		uint8_t *dst1= dst;
-		int16_t *src1= src;
-		__asm__ volatile(
-			"movq (%3), %%mm3	\n\t"
-			"movq (%3), %%mm4	\n\t"
-			"movd %4, %%mm2		\n\t"
-			"pxor %%mm0, %%mm0	\n\t"
-			"punpcklbw %%mm0, %%mm3	\n\t"
-			"punpckhbw %%mm0, %%mm4	\n\t"
-			"psraw %%mm2, %%mm3	\n\t"
-			"psraw %%mm2, %%mm4	\n\t"
-			"movd %5, %%mm2		\n\t"
-			"1:			\n\t"
-			"movq (%0), %%mm0	\n\t"
-			"movq 8(%0), %%mm1	\n\t"
-			"paddw %%mm3, %%mm0	\n\t"
-			"paddw %%mm4, %%mm1	\n\t"
-			"psraw %%mm2, %%mm0	\n\t"
-			"psraw %%mm2, %%mm1	\n\t"
-			"packuswb %%mm1, %%mm0	\n\t"
-			"movq %%mm0, (%1) 	\n\t"
-			"add $16, %0		\n\t"
-			"add $8, %1		\n\t"
-			"cmp %2, %1		\n\t"
-			" jb 1b			\n\t"
-			: "+r" (src1), "+r"(dst1)
-			: "r"(dst + width), "r"(dither[y]), "g"(log2_scale), "g"(6-log2_scale)
-		);
-		src += src_stride;
-		dst += dst_stride;
-	}
-//	if(width != mmxw)
-//		store_slice_c(dst + mmxw, src + mmxw, dst_stride, src_stride, width - mmxw, log2_scale);
-}
-#endif
-
-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 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<<p->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);
-
-	if (!src || !dst) return; // HACK avoid crash for Y8 colourspace
-	for(y=0; y<height; y++){
-		int index= 8 + 8*stride + y*stride;
-		fast_memcpy(p->src + index, src + y*src_stride, width);
-		for(x=0; x<8; x++){
-			p->src[index         - x - 1]= p->src[index +         x    ];
-			p->src[index + width + x    ]= p->src[index + width - x - 1];
-		}
-	}
-	for(y=0; y<8; y++){
-		fast_memcpy(p->src + (      7-y)*stride, p->src + (      y+8)*stride, stride);
-		fast_memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride);
-	}
-	//FIXME (try edge emu)
-
-	for(y=0; y<height+8; y+=8){
-		memset(p->temp + (8+y)*stride, 0, 8*stride*sizeof(int16_t));
-		for(x=0; x<width+8; x+=8){
-			const int qps= 3 + is_luma;
-			int qp;
-
-			if(p->qp)
-				qp= p->qp;
-			else{
-				qp= qp_store[ (XMIN(x, width-1)>>qps) + (XMIN(y, height-1)>>qps) * qp_stride];
-				qp = FFMAX(1, norm_qscale(qp, p->mpeg2));
-			}
-			for(i=0; i<count; i++){
-				const int x1= x + offset[i+count-1][0];
-				const int y1= y + offset[i+count-1][1];
-				const int index= x1 + y1*stride;
-				p->dsp.get_pixels(block, p->src + index, stride);
-				p->dsp.fdct(block);
-				requantize(block2, block, qp, p->dsp.idct_permutation);
-				p->dsp.idct(block2);
-				add_block(p->temp + index, stride, block2);
-			}
-		}
-		if(y)
-			store_slice(dst + (y-8)*dst_stride, p->temp + 8 + y*stride, dst_stride, stride, width, XMIN(8, height+8-y), 6-p->log2_count);
-	}
-#if 0
-	for(y=0; y<height; y++){
-		for(x=0; x<width; x++){
-			if((((x>>6) ^ (y>>6)) & 1) == 0)
-				dst[x + y*dst_stride]= p->src[8 + 8*stride  + x + y*stride];
-			if((x&63) == 0 || (y&63)==0)
-				dst[x + y*dst_stride] += 128;
-                }
-	}
-#endif
-	//FIXME reorder for better caching
-}
-
-static int config(struct vf_instance *vf,
-        int width, int height, int d_width, int d_height,
-	unsigned int flags, unsigned int outfmt){
-	int h= (height+16+15)&(~15);
-
-	vf->priv->temp_stride= (width+16+15)&(~15);
-        vf->priv->temp= malloc(vf->priv->temp_stride*h*sizeof(int16_t));
-        vf->priv->src = malloc(vf->priv->temp_stride*h*sizeof(uint8_t));
-
-	return 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
-    // ok, we can do pp in-place (or pp disabled):
-    vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
-        mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
-    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:
-                dmpi=vf_get_image(vf->next,mpi->imgfmt,
-                    MP_IMGTYPE_TEMP,
-                    MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
-                    mpi->width,mpi->height);
-                vf_clone_mpi_attributes(dmpi, mpi);
-        }else{
-           dmpi=vf->dmpi;
-        }
-
-        vf->priv->mpeg2= mpi->qscale_type;
-        if(mpi->pict_type != 3 && mpi->qscale && !vf->priv->qp){
-            int w = mpi->qstride;
-            int h = (mpi->h + 15) >> 4;
-            if (!w) {
-                w = (mpi->w + 15) >> 4;
-                h = 1;
-            }
-            if(!vf->priv->non_b_qp)
-                vf->priv->non_b_qp= malloc(w*h);
-            fast_memcpy(vf->priv->non_b_qp, mpi->qscale, w*h);
-        }
-	if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
-            char *qp_tab= vf->priv->non_b_qp;
-            if((vf->priv->mode&4) || !qp_tab)
-                qp_tab= mpi->qscale;
-
-	    if(qp_tab || vf->priv->qp){
-		filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, qp_tab, mpi->qstride, 1);
-		filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
-		filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
-	    }else{
-		memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
-		memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
-		memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
-	    }
-	}
-
-#if HAVE_MMX
-	if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
-#endif
-#if HAVE_MMX2
-	if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
-#endif
-
-	return vf_next_put_image(vf,dmpi, pts);
-}
-
-static void uninit(struct vf_instance *vf){
-	if(!vf->priv) return;
-
-	free(vf->priv->temp);
-	vf->priv->temp= NULL;
-	free(vf->priv->src);
-	vf->priv->src= NULL;
-        free(vf->priv->avctx);
-        vf->priv->avctx= NULL;
-        free(vf->priv->non_b_qp);
-        vf->priv->non_b_qp= NULL;
-
-	free(vf->priv);
-	vf->priv=NULL;
-}
-
-//===========================================================================//
-static int query_format(struct vf_instance *vf, unsigned int fmt){
-    switch(fmt){
-	case IMGFMT_YVU9:
-	case IMGFMT_IF09:
-	case IMGFMT_YV12:
-	case IMGFMT_I420:
-	case IMGFMT_IYUV:
-	case IMGFMT_CLPL:
-	case IMGFMT_Y800:
-	case IMGFMT_Y8:
-	case IMGFMT_444P:
-	case IMGFMT_422P:
-	case IMGFMT_411P:
-	    return vf_next_query_format(vf,fmt);
-    }
-    return 0;
-}
-
-static int control(struct vf_instance *vf, int request, void* data){
-    switch(request){
-    case VFCTRL_QUERY_MAX_PP_LEVEL:
-	return 6;
-    case VFCTRL_SET_PP_LEVEL:
-	vf->priv->log2_count= *((unsigned int*)data);
-	return CONTROL_TRUE;
-    }
-    return vf_next_control(vf,request,data);
-}
-
-static int vf_open(vf_instance_t *vf, char *args){
-
-    int log2c=-1;
-
-    vf->config=config;
-    vf->put_image=put_image;
-    vf->get_image=get_image;
-    vf->query_format=query_format;
-    vf->uninit=uninit;
-    vf->control= control;
-    vf->priv=malloc(sizeof(struct vf_priv_s));
-    memset(vf->priv, 0, sizeof(struct vf_priv_s));
-
-    vf->priv->avctx= avcodec_alloc_context();
-    dsputil_init(&vf->priv->dsp, vf->priv->avctx);
-
-    vf->priv->log2_count= 3;
-
-    if (args) sscanf(args, "%d:%d:%d", &log2c, &vf->priv->qp, &vf->priv->mode);
-
-    if( log2c >=0 && log2c <=6 )
-        vf->priv->log2_count = log2c;
-
-    if(vf->priv->qp < 0)
-        vf->priv->qp = 0;
-
-    switch(vf->priv->mode&3){
-        default:
-	case 0: requantize= hardthresh_c; break;
-	case 1: requantize= softthresh_c; break;
-    }
-
-#if HAVE_MMX
-    if(gCpuCaps.hasMMX){
-	store_slice= store_slice_mmx;
-	switch(vf->priv->mode&3){
-	    case 0: requantize= hardthresh_mmx; break;
-	    case 1: requantize= softthresh_mmx; break;
-	}
-    }
-#endif
-
-    return 1;
-}
-
-const vf_info_t vf_info_spp = {
-    "simple postprocess",
-    "spp",
-    "Michael Niedermayer",
-    "",
-    vf_open,
-    NULL
-};
diff --git a/libmpcodecs/vf_unsharp.c b/libmpcodecs/vf_unsharp.c
index 9014a2b..864c998 100644
--- a/libmpcodecs/vf_unsharp.c
+++ b/libmpcodecs/vf_unsharp.c
@@ -28,10 +28,6 @@
 #include "mp_msg.h"
 #include "cpudetect.h"
 
-#if HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
diff --git a/libmpcodecs/vf_uspp.c b/libmpcodecs/vf_uspp.c
deleted file mode 100644
index 558a409..0000000
--- a/libmpcodecs/vf_uspp.c
+++ /dev/null
@@ -1,382 +0,0 @@
-/*
- * Copyright (C) 2005 Michael Niedermayer <michaelni at gmx.at>
- *
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include <math.h>
-#include <assert.h>
-
-#include <libavcodec/avcodec.h>
-#include <libavutil/mem.h>
-
-#include "config.h"
-
-#include "mp_msg.h"
-#include "cpudetect.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-#include "libvo/fastmemcpy.h"
-
-#define XMIN(a,b) ((a) < (b) ? (a) : (b))
-
-#define BLOCK 16
-
-//===========================================================================//
-static const uint8_t  __attribute__((aligned(8))) dither[8][8]={
-{  0*4,  48*4,  12*4,  60*4,   3*4,  51*4,  15*4,  63*4, },
-{ 32*4,  16*4,  44*4,  28*4,  35*4,  19*4,  47*4,  31*4, },
-{  8*4,  56*4,   4*4,  52*4,  11*4,  59*4,   7*4,  55*4, },
-{ 40*4,  24*4,  36*4,  20*4,  43*4,  27*4,  39*4,  23*4, },
-{  2*4,  50*4,  14*4,  62*4,   1*4,  49*4,  13*4,  61*4, },
-{ 34*4,  18*4,  46*4,  30*4,  33*4,  17*4,  45*4,  29*4, },
-{ 10*4,  58*4,   6*4,  54*4,   9*4,  57*4,   5*4,  53*4, },
-{ 42*4,  26*4,  38*4,  22*4,  41*4,  25*4,  37*4,  21*4, },
-};
-
-static const uint8_t offset[511][2]= {
-{ 0, 0},
-{ 0, 0}, { 8, 8},
-{ 0, 0}, { 4, 4}, {12, 8}, { 8,12},
-{ 0, 0}, {10, 2}, { 4, 4}, {14, 6}, { 8, 8}, { 2,10}, {12,12}, { 6,14},
-
-{ 0, 0}, {10, 2}, { 4, 4}, {14, 6}, { 8, 8}, { 2,10}, {12,12}, { 6,14},
-{ 5, 1}, {15, 3}, { 9, 5}, { 3, 7}, {13, 9}, { 7,11}, { 1,13}, {11,15},
-
-{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9},
-{ 2, 2}, {10, 2}, { 2,10}, {10,10}, { 7, 3}, {15, 3}, { 7,11}, {15,11},
-{ 4, 4}, {12, 4}, { 4,12}, {12,12}, { 1, 5}, { 9, 5}, { 1,13}, { 9,13},
-{ 6, 6}, {14, 6}, { 6,14}, {14,14}, { 3, 7}, {11, 7}, { 3,15}, {11,15},
-
-{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 4, 0}, {12, 0}, { 4, 8}, {12, 8},
-{ 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9},
-{ 3, 2}, {11, 2}, { 3,10}, {11,10}, { 7, 2}, {15, 2}, { 7,10}, {15,10},
-{ 2, 3}, {10, 3}, { 2,11}, {10,11}, { 6, 3}, {14, 3}, { 6,11}, {14,11},
-{ 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 4, 4}, {12, 4}, { 4,12}, {12,12},
-{ 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 5, 5}, {13, 5}, { 5,13}, {13,13},
-{ 3, 6}, {11, 6}, { 3,14}, {11,14}, { 7, 6}, {15, 6}, { 7,14}, {15,14},
-{ 2, 7}, {10, 7}, { 2,15}, {10,15}, { 6, 7}, {14, 7}, { 6,15}, {14,15},
-
-{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 0, 2}, { 8, 2}, { 0,10}, { 8,10},
-{ 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 0, 6}, { 8, 6}, { 0,14}, { 8,14},
-{ 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 1, 3}, { 9, 3}, { 1,11}, { 9,11},
-{ 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 1, 7}, { 9, 7}, { 1,15}, { 9,15},
-{ 2, 0}, {10, 0}, { 2, 8}, {10, 8}, { 2, 2}, {10, 2}, { 2,10}, {10,10},
-{ 2, 4}, {10, 4}, { 2,12}, {10,12}, { 2, 6}, {10, 6}, { 2,14}, {10,14},
-{ 3, 1}, {11, 1}, { 3, 9}, {11, 9}, { 3, 3}, {11, 3}, { 3,11}, {11,11},
-{ 3, 5}, {11, 5}, { 3,13}, {11,13}, { 3, 7}, {11, 7}, { 3,15}, {11,15},
-{ 4, 0}, {12, 0}, { 4, 8}, {12, 8}, { 4, 2}, {12, 2}, { 4,10}, {12,10},
-{ 4, 4}, {12, 4}, { 4,12}, {12,12}, { 4, 6}, {12, 6}, { 4,14}, {12,14},
-{ 5, 1}, {13, 1}, { 5, 9}, {13, 9}, { 5, 3}, {13, 3}, { 5,11}, {13,11},
-{ 5, 5}, {13, 5}, { 5,13}, {13,13}, { 5, 7}, {13, 7}, { 5,15}, {13,15},
-{ 6, 0}, {14, 0}, { 6, 8}, {14, 8}, { 6, 2}, {14, 2}, { 6,10}, {14,10},
-{ 6, 4}, {14, 4}, { 6,12}, {14,12}, { 6, 6}, {14, 6}, { 6,14}, {14,14},
-{ 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},
-};
-
-struct vf_priv_s {
-    int log2_count;
-    int qp;
-    int mode;
-    int mpeg2;
-    int temp_stride[3];
-    uint8_t *src[3];
-    int16_t *temp[3];
-    int outbuf_size;
-    uint8_t *outbuf;
-    AVCodecContext *avctx_enc[BLOCK*BLOCK];
-    AVFrame *frame;
-    AVFrame *frame_dec;
-};
-
-static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){
-	int y, x;
-
-#define STORE(pos) \
-	temp= ((src[x + y*src_stride + pos]<<log2_scale) + d[pos])>>8;\
-	if(temp & 0x100) temp= ~(temp>>31);\
-	dst[x + y*dst_stride + pos]= temp;
-
-	for(y=0; y<height; y++){
-		const uint8_t *d= dither[y&7];
-		for(x=0; x<width; x+=8){
-			int temp;
-			STORE(0);
-			STORE(1);
-			STORE(2);
-			STORE(3);
-			STORE(4);
-			STORE(5);
-			STORE(6);
-			STORE(7);
-		}
-	}
-}
-
-static void filter(struct vf_priv_s *p, uint8_t *dst[3], uint8_t *src[3], int dst_stride[3], int src_stride[3], int width, int height, uint8_t *qp_store, int qp_stride){
-    int x, y, i, j;
-    const int count= 1<<p->log2_count;
-
-    for(i=0; i<3; i++){
-        int is_chroma= !!i;
-        int w= width >>is_chroma;
-        int h= height>>is_chroma;
-        int stride= p->temp_stride[i];
-        int block= BLOCK>>is_chroma;
-
-        if (!src[i] || !dst[i])
-            continue; // HACK avoid crash for Y8 colourspace
-        for(y=0; y<h; y++){
-            int index= block + block*stride + y*stride;
-            fast_memcpy(p->src[i] + index, src[i] + y*src_stride[i], w);
-            for(x=0; x<block; x++){
-                p->src[i][index     - x - 1]= p->src[i][index +     x    ];
-                p->src[i][index + w + x    ]= p->src[i][index + w - x - 1];
-            }
-        }
-        for(y=0; y<block; y++){
-            fast_memcpy(p->src[i] + (  block-1-y)*stride, p->src[i] + (  y+block  )*stride, stride);
-            fast_memcpy(p->src[i] + (h+block  +y)*stride, p->src[i] + (h-y+block-1)*stride, stride);
-        }
-
-        p->frame->linesize[i]= stride;
-        memset(p->temp[i], 0, (h+2*block)*stride*sizeof(int16_t));
-    }
-
-    if(p->qp)
-        p->frame->quality= p->qp * FF_QP2LAMBDA;
-    else
-        p->frame->quality= norm_qscale(qp_store[0], p->mpeg2) * FF_QP2LAMBDA;
-//    init per MB qscale stuff FIXME
-
-    for(i=0; i<count; i++){
-        const int x1= offset[i+count-1][0];
-        const int y1= offset[i+count-1][1];
-        int offset;
-        p->frame->data[0]= p->src[0] + x1 + y1 * p->frame->linesize[0];
-        p->frame->data[1]= p->src[1] + x1/2 + y1/2 * p->frame->linesize[1];
-        p->frame->data[2]= p->src[2] + x1/2 + y1/2 * p->frame->linesize[2];
-
-        avcodec_encode_video(p->avctx_enc[i], p->outbuf, p->outbuf_size, p->frame);
-        p->frame_dec = p->avctx_enc[i]->coded_frame;
-
-        offset= (BLOCK-x1) + (BLOCK-y1)*p->frame_dec->linesize[0];
-        //FIXME optimize
-        for(y=0; y<height; y++){
-            for(x=0; x<width; x++){
-                p->temp[0][ x + y*p->temp_stride[0] ] += p->frame_dec->data[0][ x + y*p->frame_dec->linesize[0] + offset ];
-            }
-        }
-        offset= (BLOCK/2-x1/2) + (BLOCK/2-y1/2)*p->frame_dec->linesize[1];
-        for(y=0; y<height/2; y++){
-            for(x=0; x<width/2; x++){
-                p->temp[1][ x + y*p->temp_stride[1] ] += p->frame_dec->data[1][ x + y*p->frame_dec->linesize[1] + offset ];
-                p->temp[2][ x + y*p->temp_stride[2] ] += p->frame_dec->data[2][ x + y*p->frame_dec->linesize[2] + offset ];
-            }
-        }
-    }
-
-    for(j=0; j<3; j++){
-        int is_chroma= !!j;
-        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);
-    }
-}
-
-static int config(struct vf_instance *vf,
-        int width, int height, int d_width, int d_height,
-	unsigned int flags, unsigned int outfmt){
-        int i;
-        AVCodec *enc= avcodec_find_encoder(CODEC_ID_SNOW);
-
-        for(i=0; i<3; i++){
-            int is_chroma= !!i;
-            int w= ((width  + 4*BLOCK-1) & (~(2*BLOCK-1)))>>is_chroma;
-            int h= ((height + 4*BLOCK-1) & (~(2*BLOCK-1)))>>is_chroma;
-
-            vf->priv->temp_stride[i]= w;
-            vf->priv->temp[i]= malloc(vf->priv->temp_stride[i]*h*sizeof(int16_t));
-            vf->priv->src [i]= malloc(vf->priv->temp_stride[i]*h*sizeof(uint8_t));
-        }
-        for(i=0; i< (1<<vf->priv->log2_count); i++){
-            AVCodecContext *avctx_enc;
-
-            avctx_enc = vf->priv->avctx_enc[i] = avcodec_alloc_context3(enc);
-            avctx_enc->width = width + BLOCK;
-            avctx_enc->height = height + BLOCK;
-            avctx_enc->time_base= (AVRational){1,25};  // meaningless
-            avctx_enc->gop_size = 300;
-            avctx_enc->max_b_frames= 0;
-            avctx_enc->pix_fmt = PIX_FMT_YUV420P;
-            avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY;
-            avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
-            avctx_enc->global_quality= 123;
-            int res = avcodec_open2(avctx_enc, enc, NULL);
-            assert(res >= 0);
-        }
-        vf->priv->frame= avcodec_alloc_frame();
-        vf->priv->frame_dec= avcodec_alloc_frame();
-
-        vf->priv->outbuf_size= (width + BLOCK)*(height + BLOCK)*10;
-        vf->priv->outbuf= malloc(vf->priv->outbuf_size);
-
-	return 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
-    // ok, we can do pp in-place (or pp disabled):
-    vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
-        mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
-    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:
-        dmpi=vf_get_image(vf->next,mpi->imgfmt,
-            MP_IMGTYPE_TEMP,
-            MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
-            mpi->width,mpi->height);
-        vf_clone_mpi_attributes(dmpi, mpi);
-    }else{
-        dmpi=vf->dmpi;
-    }
-
-    vf->priv->mpeg2= mpi->qscale_type;
-    if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
-        if(mpi->qscale || vf->priv->qp){
-            filter(vf->priv, dmpi->planes, mpi->planes, dmpi->stride, mpi->stride, mpi->w, mpi->h, mpi->qscale, mpi->qstride);
-        }else{
-            memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
-            memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
-            memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
-        }
-    }
-
-#if HAVE_MMX
-    if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
-#endif
-#if HAVE_MMX2
-    if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
-#endif
-
-    return vf_next_put_image(vf,dmpi, pts);
-}
-
-static void uninit(struct vf_instance *vf){
-    int i;
-    if(!vf->priv) return;
-
-    for(i=0; i<3; i++){
-        free(vf->priv->temp[i]);
-        vf->priv->temp[i]= NULL;
-        free(vf->priv->src[i]);
-        vf->priv->src[i]= NULL;
-    }
-    for(i=0; i<BLOCK*BLOCK; i++){
-        av_freep(&vf->priv->avctx_enc[i]);
-    }
-
-    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:
-	case IMGFMT_Y800:
-	case IMGFMT_Y8:
-	    return vf_next_query_format(vf,fmt);
-    }
-    return 0;
-}
-
-static int control(struct vf_instance *vf, int request, void* data){
-    switch(request){
-    case VFCTRL_QUERY_MAX_PP_LEVEL:
-	return 8;
-    case VFCTRL_SET_PP_LEVEL:
-	vf->priv->log2_count= *((unsigned int*)data);
-        //FIXME we have to realloc a few things here
-	return CONTROL_TRUE;
-    }
-    return vf_next_control(vf,request,data);
-}
-
-static int vf_open(vf_instance_t *vf, char *args){
-
-    int log2c=-1;
-
-    vf->config=config;
-    vf->put_image=put_image;
-    vf->get_image=get_image;
-    vf->query_format=query_format;
-    vf->uninit=uninit;
-    vf->control= control;
-    vf->priv=malloc(sizeof(struct vf_priv_s));
-    memset(vf->priv, 0, sizeof(struct vf_priv_s));
-
-    vf->priv->log2_count= 4;
-
-    if (args) sscanf(args, "%d:%d:%d", &log2c, &vf->priv->qp, &vf->priv->mode);
-
-    if( log2c >=0 && log2c <=8 )
-        vf->priv->log2_count = log2c;
-
-    if(vf->priv->qp < 0)
-        vf->priv->qp = 0;
-
-// #if HAVE_MMX
-//     if(gCpuCaps.hasMMX){
-// 	store_slice= store_slice_mmx;
-//     }
-// #endif
-
-    return 1;
-}
-
-const vf_info_t vf_info_uspp = {
-    "ultra simple/slow postprocess",
-    "uspp",
-    "Michael Niedermayer",
-    "",
-    vf_open,
-    NULL
-};
diff --git a/libmpdemux/demux_lavf.c b/libmpdemux/demux_lavf.c
index 7103a5e..5f13b3b 100644
--- a/libmpdemux/demux_lavf.c
+++ b/libmpdemux/demux_lavf.c
@@ -295,7 +295,7 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
             matches_avinputformat_name(priv, "mpegts"))
         codec->codec_tag = 0;
     int override_tag = mp_taglist_override(codec->codec_id);
-    // For some formats (like PCM) always trust CODEC_ID_* more than codec_tag
+    // For some formats (like PCM) always trust codec_id more than codec_tag
     if (override_tag)
         codec->codec_tag = override_tag;
 
@@ -345,10 +345,10 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
         sh_audio->samplerate = codec->sample_rate;
         sh_audio->i_bps = codec->bit_rate / 8;
         switch (codec->codec_id) {
-        case CODEC_ID_PCM_ALAW:
+        case AV_CODEC_ID_PCM_ALAW:
             sh_audio->format = 0x6;
             break;
-        case CODEC_ID_PCM_MULAW:
+        case AV_CODEC_ID_PCM_MULAW:
             sh_audio->format = 0x7;
             break;
         }
@@ -381,7 +381,7 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
         sh_video->libav_codec_id = codec->codec_id;
         bih = calloc(sizeof(*bih) + codec->extradata_size, 1);
 
-        if (codec->codec_id == CODEC_ID_RAWVIDEO) {
+        if (codec->codec_id == AV_CODEC_ID_RAWVIDEO) {
             switch (codec->pix_fmt) {
             case PIX_FMT_RGB24:
                 codec->codec_tag = MKTAG(24, 'B', 'G', 'R');
@@ -450,6 +450,10 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
         sh_video->ds = demuxer->video;
         if (codec->extradata_size)
             memcpy(sh_video->bih + 1, codec->extradata, codec->extradata_size);
+#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(54, 2, 0)
+        sh_video->is_attached_pic =
+            st->disposition & AV_DISPOSITION_ATTACHED_PIC;
+#endif
         if ( mp_msg_test(MSGT_HEADER, MSGL_V))
             print_video_header(sh_video->bih, MSGL_V);
         st->discard = AVDISCARD_ALL;
@@ -460,21 +464,21 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
         sh_sub_t *sh_sub;
         char type;
         /* only support text subtitles for now */
-        if (codec->codec_id == CODEC_ID_TEXT)
+        if (codec->codec_id == AV_CODEC_ID_TEXT)
             type = 't';
-        else if (codec->codec_id == CODEC_ID_MOV_TEXT)
+        else if (codec->codec_id == AV_CODEC_ID_MOV_TEXT)
             type = 'm';
-        else if (codec->codec_id == CODEC_ID_SSA)
+        else if (codec->codec_id == AV_CODEC_ID_SSA)
             type = 'a';
-        else if (codec->codec_id == CODEC_ID_DVD_SUBTITLE)
+        else if (codec->codec_id == AV_CODEC_ID_DVD_SUBTITLE)
             type = 'v';
-        else if (codec->codec_id == CODEC_ID_XSUB)
+        else if (codec->codec_id == AV_CODEC_ID_XSUB)
             type = 'x';
-        else if (codec->codec_id == CODEC_ID_DVB_SUBTITLE)
+        else if (codec->codec_id == AV_CODEC_ID_DVB_SUBTITLE)
             type = 'b';
-        else if (codec->codec_id == CODEC_ID_DVB_TELETEXT)
+        else if (codec->codec_id == AV_CODEC_ID_DVB_TELETEXT)
             type = 'd';
-        else if (codec->codec_id == CODEC_ID_HDMV_PGS_SUBTITLE)
+        else if (codec->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE)
             type = 'p';
         else
             break;
@@ -509,7 +513,7 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
         AVDictionaryEntry *ftag = av_dict_get(st->metadata, "filename",
                                               NULL, 0);
         char *filename = ftag ? ftag->value : NULL;
-        if (st->codec->codec_id == CODEC_ID_TTF)
+        if (st->codec->codec_id == AV_CODEC_ID_TTF)
             demuxer_add_attachment(demuxer, bstr(filename),
                                    bstr("application/x-truetype-font"),
                                    (struct bstr){codec->extradata,
@@ -663,8 +667,16 @@ static demuxer_t *demux_open_lavf(demuxer_t *demuxer)
     int vid = demuxer->video->id;
     demuxer->video->id = -2;
     demuxer->desc->control(demuxer, DEMUXER_CTRL_SWITCH_VIDEO, &vid);
-    if (demuxer->video->id >= 0)
-        demuxer->video->sh = demuxer->v_streams[demuxer->video->id];
+    while (demuxer->video->id >= 0) {
+        struct sh_video *v = demuxer->v_streams[demuxer->video->id];
+        if (v->is_attached_pic) {
+            demuxer->desc->control(demuxer, DEMUXER_CTRL_SWITCH_VIDEO,
+                                   &(int){-1});
+        } else {
+            demuxer->video->sh = v;
+            break;
+        }
+    }
 
     // disabled because unreliable per-stream bitrate values returned
     // by libavformat trigger this heuristic incorrectly and break things
@@ -954,7 +966,7 @@ redo:
                     prog->aid = program->stream_index[i];
                 break;
             case AVMEDIA_TYPE_SUBTITLE:
-                if (prog->sid == -2 && priv->avfc->streams[program->stream_index[i]]->codec->codec_id == CODEC_ID_TEXT)
+                if (prog->sid == -2 && priv->avfc->streams[program->stream_index[i]]->codec->codec_id == AV_CODEC_ID_TEXT)
                     prog->sid = program->stream_index[i];
                 break;
             }
diff --git a/libmpdemux/demux_viv.c b/libmpdemux/demux_viv.c
index 7da37ac..06193e9 100644
--- a/libmpdemux/demux_viv.c
+++ b/libmpdemux/demux_viv.c
@@ -96,7 +96,6 @@ static void vivo_parse_text_header(demuxer_t *demux, int header_len)
 {
     vivo_priv_t* priv = demux->priv;
     char *buf;
-    int i;
     char *token;
     char *opt, *param;
     int parser_in_audio_block = 0;
@@ -109,25 +108,23 @@ static void vivo_parse_text_header(demuxer_t *demux, int header_len)
 	priv->supported = 0;
     }
 
-    buf = malloc(header_len);
-    opt = malloc(header_len);
-    param = malloc(header_len);
+    buf = malloc(header_len + 1);
+    opt = malloc(header_len + 1);
+    param = malloc(header_len + 1);
     stream_read(demux->stream, buf, header_len);
-    i=0;
-    while(i<header_len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines
+    buf[header_len] = 0;
 
     token = strtok(buf, (char *)&("\x0d\x0a"));
-    while (token && (header_len>2))
+    while (token)
     {
-	header_len -= strlen(token)+2;
 	if (sscanf(token, "%[^:]:%[^\n]", opt, param) != 2)
 	{
 	    mp_msg(MSGT_DEMUX, MSGL_V, "viv_text_header_parser: bad line: '%s' at ~%#"PRIx64"\n",
 		token, (int64_t)stream_tell(demux->stream));
 	    break;
 	}
-	mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token: '%s' (%zd bytes/%d bytes left)\n",
-	    token, strlen(token), header_len);
+	mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token: '%s' (%zd bytes)\n",
+	    token, strlen(token));
 	mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token => o: '%s', p: '%s'\n",
 	    opt, param);
 
diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c
index e2df5ca..f6d769d 100644
--- a/libmpdemux/demuxer.c
+++ b/libmpdemux/demuxer.c
@@ -488,37 +488,38 @@ void ds_add_packet(demux_stream_t *ds, demux_packet_t *dp)
            ds->demuxer->video->packs);
 }
 
-static void allocate_parser(AVCodecContext **avctx, AVCodecParserContext **parser, unsigned format)
+static void allocate_parser(AVCodecContext **avctx,
+                            AVCodecParserContext **parser, unsigned format)
 {
-    enum CodecID codec_id = CODEC_ID_NONE;
+    enum AVCodecID codec_id = AV_CODEC_ID_NONE;
 
     switch (format) {
     case MKTAG('M', 'P', '4', 'L'):
-        codec_id = CODEC_ID_AAC_LATM;
+        codec_id = AV_CODEC_ID_AAC_LATM;
         break;
     case 0x2000:
     case 0x332D6361:
     case 0x332D4341:
     case 0x20736D:
     case MKTAG('s', 'a', 'c', '3'):
-        codec_id = CODEC_ID_AC3;
+        codec_id = AV_CODEC_ID_AC3;
         break;
     case MKTAG('d', 'n', 'e', 't'):
         // DNET/byte-swapped AC-3 - there is no parser for that yet
-        //codec_id = CODEC_ID_DNET;
+        //codec_id = AV_CODEC_ID_DNET;
         break;
     case MKTAG('E', 'A', 'C', '3'):
-        codec_id = CODEC_ID_EAC3;
+        codec_id = AV_CODEC_ID_EAC3;
         break;
     case 0x2001:
     case 0x86:
-        codec_id = CODEC_ID_DTS;
+        codec_id = AV_CODEC_ID_DTS;
         break;
     case MKTAG('f', 'L', 'a', 'C'):
-        codec_id = CODEC_ID_FLAC;
+        codec_id = AV_CODEC_ID_FLAC;
         break;
     case MKTAG('M', 'L', 'P', ' '):
-        codec_id = CODEC_ID_MLP;
+        codec_id = AV_CODEC_ID_MLP;
         break;
     case 0x55:
     case 0x5500736d:
@@ -526,19 +527,19 @@ static void allocate_parser(AVCodecContext **avctx, AVCodecParserContext **parse
     case MKTAG('.', 'm', 'p', '3'):
     case MKTAG('M', 'P', '3', ' '):
     case MKTAG('L', 'A', 'M', 'E'):
-        codec_id = CODEC_ID_MP3;
+        codec_id = AV_CODEC_ID_MP3;
         break;
     case 0x50:
     case 0x5000736d:
     case MKTAG('.', 'm', 'p', '2'):
     case MKTAG('.', 'm', 'p', '1'):
-        codec_id = CODEC_ID_MP2;
+        codec_id = AV_CODEC_ID_MP2;
         break;
     case MKTAG('T', 'R', 'H', 'D'):
-        codec_id = CODEC_ID_TRUEHD;
+        codec_id = AV_CODEC_ID_TRUEHD;
         break;
     }
-    if (codec_id != CODEC_ID_NONE) {
+    if (codec_id != AV_CODEC_ID_NONE) {
         *avctx = avcodec_alloc_context3(NULL);
         if (!*avctx)
             return;
diff --git a/libmpdemux/mp_taglists.c b/libmpdemux/mp_taglists.c
index afd1b97..3c55343 100644
--- a/libmpdemux/mp_taglists.c
+++ b/libmpdemux/mp_taglists.c
@@ -22,111 +22,111 @@
 #include "mp_taglists.h"
 
 struct tag {
-    enum CodecID id;
+    enum AVCodecID id;
     unsigned int tag;
 };
 
 static const struct tag mp_wav_tags[] = {
-    { CODEC_ID_ADPCM_4XM,         MKTAG('4', 'X', 'M', 'A')},
-    { CODEC_ID_ADPCM_ADX,         MKTAG('S', 'a', 'd', 'x')},
-    { CODEC_ID_ADPCM_EA,          MKTAG('A', 'D', 'E', 'A')},
-    { CODEC_ID_ADPCM_EA_MAXIS_XA, MKTAG('A', 'D', 'X', 'A')},
-    { CODEC_ID_ADPCM_IMA_WS,      MKTAG('A', 'I', 'W', 'S')},
-    { CODEC_ID_ADPCM_THP,         MKTAG('T', 'H', 'P', 'A')},
-    { CODEC_ID_ADPCM_XA,          MKTAG('P', 'S', 'X', 'A')},
-    { CODEC_ID_AMR_NB,            MKTAG('n', 'b',   0,   0)},
-    { CODEC_ID_COOK,              MKTAG('c', 'o', 'o', 'k')},
-    { CODEC_ID_DSICINAUDIO,       MKTAG('D', 'C', 'I', 'A')},
-    { CODEC_ID_EAC3,              MKTAG('E', 'A', 'C', '3')},
-    { CODEC_ID_INTERPLAY_DPCM,    MKTAG('I', 'N', 'P', 'A')},
-    { CODEC_ID_MLP,               MKTAG('M', 'L', 'P', ' ')},
-    { CODEC_ID_MP1,               0x50},
-    { CODEC_ID_MP4ALS,            MKTAG('A', 'L', 'S', ' ')},
-    { CODEC_ID_MUSEPACK7,         MKTAG('M', 'P', 'C', ' ')},
-    { CODEC_ID_MUSEPACK8,         MKTAG('M', 'P', 'C', '8')},
-    { CODEC_ID_NELLYMOSER,        MKTAG('N', 'E', 'L', 'L')},
-    { CODEC_ID_PCM_LXF,           MKTAG('P', 'L', 'X', 'F')},
-    { CODEC_ID_QCELP,             MKTAG('Q', 'c', 'l', 'p')},
-    { CODEC_ID_QDM2,              MKTAG('Q', 'D', 'M', '2')},
-    { CODEC_ID_RA_144,            MKTAG('1', '4', '_', '4')},
-    { CODEC_ID_RA_288,            MKTAG('2', '8', '_', '8')},
-    { CODEC_ID_ROQ_DPCM,          MKTAG('R', 'o', 'Q', 'A')},
-    { CODEC_ID_SHORTEN,           MKTAG('s', 'h', 'r', 'n')},
-    { CODEC_ID_SPEEX,             MKTAG('s', 'p', 'x', ' ')},
-    { CODEC_ID_TTA,               MKTAG('T', 'T', 'A', '1')},
-    { CODEC_ID_TWINVQ,            MKTAG('T', 'W', 'I', '2')},
-    { CODEC_ID_WAVPACK,           MKTAG('W', 'V', 'P', 'K')},
-    { CODEC_ID_WESTWOOD_SND1,     MKTAG('S', 'N', 'D', '1')},
-    { CODEC_ID_XAN_DPCM,          MKTAG('A', 'x', 'a', 'n')},
+    { AV_CODEC_ID_ADPCM_4XM,         MKTAG('4', 'X', 'M', 'A')},
+    { AV_CODEC_ID_ADPCM_ADX,         MKTAG('S', 'a', 'd', 'x')},
+    { AV_CODEC_ID_ADPCM_EA,          MKTAG('A', 'D', 'E', 'A')},
+    { AV_CODEC_ID_ADPCM_EA_MAXIS_XA, MKTAG('A', 'D', 'X', 'A')},
+    { AV_CODEC_ID_ADPCM_IMA_WS,      MKTAG('A', 'I', 'W', 'S')},
+    { AV_CODEC_ID_ADPCM_THP,         MKTAG('T', 'H', 'P', 'A')},
+    { AV_CODEC_ID_ADPCM_XA,          MKTAG('P', 'S', 'X', 'A')},
+    { AV_CODEC_ID_AMR_NB,            MKTAG('n', 'b',   0,   0)},
+    { AV_CODEC_ID_COOK,              MKTAG('c', 'o', 'o', 'k')},
+    { AV_CODEC_ID_DSICINAUDIO,       MKTAG('D', 'C', 'I', 'A')},
+    { AV_CODEC_ID_EAC3,              MKTAG('E', 'A', 'C', '3')},
+    { AV_CODEC_ID_INTERPLAY_DPCM,    MKTAG('I', 'N', 'P', 'A')},
+    { AV_CODEC_ID_MLP,               MKTAG('M', 'L', 'P', ' ')},
+    { AV_CODEC_ID_MP1,               0x50},
+    { AV_CODEC_ID_MP4ALS,            MKTAG('A', 'L', 'S', ' ')},
+    { AV_CODEC_ID_MUSEPACK7,         MKTAG('M', 'P', 'C', ' ')},
+    { AV_CODEC_ID_MUSEPACK8,         MKTAG('M', 'P', 'C', '8')},
+    { AV_CODEC_ID_NELLYMOSER,        MKTAG('N', 'E', 'L', 'L')},
+    { AV_CODEC_ID_PCM_LXF,           MKTAG('P', 'L', 'X', 'F')},
+    { AV_CODEC_ID_QCELP,             MKTAG('Q', 'c', 'l', 'p')},
+    { AV_CODEC_ID_QDM2,              MKTAG('Q', 'D', 'M', '2')},
+    { AV_CODEC_ID_RA_144,            MKTAG('1', '4', '_', '4')},
+    { AV_CODEC_ID_RA_288,            MKTAG('2', '8', '_', '8')},
+    { AV_CODEC_ID_ROQ_DPCM,          MKTAG('R', 'o', 'Q', 'A')},
+    { AV_CODEC_ID_SHORTEN,           MKTAG('s', 'h', 'r', 'n')},
+    { AV_CODEC_ID_SPEEX,             MKTAG('s', 'p', 'x', ' ')},
+    { AV_CODEC_ID_TTA,               MKTAG('T', 'T', 'A', '1')},
+    { AV_CODEC_ID_TWINVQ,            MKTAG('T', 'W', 'I', '2')},
+    { AV_CODEC_ID_WAVPACK,           MKTAG('W', 'V', 'P', 'K')},
+    { AV_CODEC_ID_WESTWOOD_SND1,     MKTAG('S', 'N', 'D', '1')},
+    { AV_CODEC_ID_XAN_DPCM,          MKTAG('A', 'x', 'a', 'n')},
     { 0, 0 },
 };
 
 static const struct tag mp_codecid_override_tags[] = {
-    { CODEC_ID_AAC,               MKTAG('M', 'P', '4', 'A')},
-    { CODEC_ID_AAC_LATM,          MKTAG('M', 'P', '4', 'L')},
-    { CODEC_ID_AC3,               0x2000},
-    { CODEC_ID_ADPCM_IMA_AMV,     MKTAG('A', 'M', 'V', 'A')},
-    { CODEC_ID_BINKAUDIO_DCT,     MKTAG('B', 'A', 'U', '1')},
-    { CODEC_ID_BINKAUDIO_RDFT,    MKTAG('B', 'A', 'U', '2')},
-    { CODEC_ID_DTS,               0x2001},
-    { CODEC_ID_DVVIDEO,           MKTAG('d', 'v', 's', 'd')},
-    { CODEC_ID_EAC3,              MKTAG('E', 'A', 'C', '3')},
-    { CODEC_ID_H264,              MKTAG('H', '2', '6', '4')},
-    { CODEC_ID_MPEG4,             MKTAG('M', 'P', '4', 'V')},
-    { CODEC_ID_PCM_BLURAY,        MKTAG('B', 'P', 'C', 'M')},
-    { CODEC_ID_PCM_S8,            MKTAG('t', 'w', 'o', 's')},
-    { CODEC_ID_PCM_U8,            1},
-    { CODEC_ID_PCM_S16BE,         MKTAG('t', 'w', 'o', 's')},
-    { CODEC_ID_PCM_S16LE,         1},
-    { CODEC_ID_PCM_S24BE,         MKTAG('i', 'n', '2', '4')},
-    { CODEC_ID_PCM_S24LE,         1},
-    { CODEC_ID_PCM_S32BE,         MKTAG('i', 'n', '3', '2')},
-    { CODEC_ID_PCM_S32LE,         1},
-    { CODEC_ID_MP2,               0x50},
-    { CODEC_ID_MPEG2VIDEO,        MKTAG('M', 'P', 'G', '2')},
-    { CODEC_ID_TRUEHD,            MKTAG('T', 'R', 'H', 'D')},
+    { AV_CODEC_ID_AAC,               MKTAG('M', 'P', '4', 'A')},
+    { AV_CODEC_ID_AAC_LATM,          MKTAG('M', 'P', '4', 'L')},
+    { AV_CODEC_ID_AC3,               0x2000},
+    { AV_CODEC_ID_ADPCM_IMA_AMV,     MKTAG('A', 'M', 'V', 'A')},
+    { AV_CODEC_ID_BINKAUDIO_DCT,     MKTAG('B', 'A', 'U', '1')},
+    { AV_CODEC_ID_BINKAUDIO_RDFT,    MKTAG('B', 'A', 'U', '2')},
+    { AV_CODEC_ID_DTS,               0x2001},
+    { AV_CODEC_ID_DVVIDEO,           MKTAG('d', 'v', 's', 'd')},
+    { AV_CODEC_ID_EAC3,              MKTAG('E', 'A', 'C', '3')},
+    { AV_CODEC_ID_H264,              MKTAG('H', '2', '6', '4')},
+    { AV_CODEC_ID_MPEG4,             MKTAG('M', 'P', '4', 'V')},
+    { AV_CODEC_ID_PCM_BLURAY,        MKTAG('B', 'P', 'C', 'M')},
+    { AV_CODEC_ID_PCM_S8,            MKTAG('t', 'w', 'o', 's')},
+    { AV_CODEC_ID_PCM_U8,            1},
+    { AV_CODEC_ID_PCM_S16BE,         MKTAG('t', 'w', 'o', 's')},
+    { AV_CODEC_ID_PCM_S16LE,         1},
+    { AV_CODEC_ID_PCM_S24BE,         MKTAG('i', 'n', '2', '4')},
+    { AV_CODEC_ID_PCM_S24LE,         1},
+    { AV_CODEC_ID_PCM_S32BE,         MKTAG('i', 'n', '3', '2')},
+    { AV_CODEC_ID_PCM_S32LE,         1},
+    { AV_CODEC_ID_MP2,               0x50},
+    { AV_CODEC_ID_MPEG2VIDEO,        MKTAG('M', 'P', 'G', '2')},
+    { AV_CODEC_ID_TRUEHD,            MKTAG('T', 'R', 'H', 'D')},
     { 0, 0 },
 };
 
 static const struct tag mp_bmp_tags[] = {
-    { CODEC_ID_AMV,               MKTAG('A', 'M', 'V', 'V')},
-    { CODEC_ID_ANM,               MKTAG('A', 'N', 'M', ' ')},
-    { CODEC_ID_AVS,               MKTAG('A', 'V', 'S', ' ')},
-    { CODEC_ID_BETHSOFTVID,       MKTAG('B', 'E', 'T', 'H')},
-    { CODEC_ID_BFI,               MKTAG('B', 'F', 'I', 'V')},
-    { CODEC_ID_C93,               MKTAG('C', '9', '3', 'V')},
-    { CODEC_ID_CDGRAPHICS,        MKTAG('C', 'D', 'G', 'R')},
-    { CODEC_ID_DNXHD,             MKTAG('A', 'V', 'd', 'n')},
-    { CODEC_ID_DSICINVIDEO,       MKTAG('D', 'C', 'I', 'V')},
-    { CODEC_ID_DXA,               MKTAG('D', 'X', 'A', '1')},
-    { CODEC_ID_FLIC,              MKTAG('F', 'L', 'I', 'C')},
-    { CODEC_ID_IDCIN,             MKTAG('I', 'D', 'C', 'I')},
-    { CODEC_ID_INTERPLAY_VIDEO,   MKTAG('I', 'N', 'P', 'V')},
-    { CODEC_ID_JV,                MKTAG('F', 'F', 'J', 'V')},
-    { CODEC_ID_MDEC,              MKTAG('M', 'D', 'E', 'C')},
-    { CODEC_ID_MOTIONPIXELS,      MKTAG('M', 'V', 'I', '1')},
-    { CODEC_ID_NUV,               MKTAG('N', 'U', 'V', '1')},
-    { CODEC_ID_RL2,               MKTAG('R', 'L', '2', 'V')},
-    { CODEC_ID_ROQ,               MKTAG('R', 'o', 'Q', 'V')},
-    { CODEC_ID_RV10,              MKTAG('R', 'V', '1', '0')},
-    { CODEC_ID_RV20,              MKTAG('R', 'V', '2', '0')},
-    { CODEC_ID_RV30,              MKTAG('R', 'V', '3', '0')},
-    { CODEC_ID_RV40,              MKTAG('R', 'V', '4', '0')},
-    { CODEC_ID_SVQ3,              MKTAG('S', 'V', 'Q', '3')},
-    { CODEC_ID_TGV,               MKTAG('f', 'V', 'G', 'T')},
-    { CODEC_ID_THP,               MKTAG('T', 'H', 'P', 'V')},
-    { CODEC_ID_TIERTEXSEQVIDEO,   MKTAG('T', 'S', 'E', 'Q')},
-    { CODEC_ID_TXD,               MKTAG('T', 'X', 'D', 'V')},
-    { CODEC_ID_VP6A,              MKTAG('V', 'P', '6', 'A')},
-    { CODEC_ID_VMDVIDEO,          MKTAG('V', 'M', 'D', 'V')},
-    { CODEC_ID_WS_VQA,            MKTAG('V', 'Q', 'A', 'V')},
-    { CODEC_ID_XAN_WC3,           MKTAG('W', 'C', '3', 'V')},
+    { AV_CODEC_ID_AMV,               MKTAG('A', 'M', 'V', 'V')},
+    { AV_CODEC_ID_ANM,               MKTAG('A', 'N', 'M', ' ')},
+    { AV_CODEC_ID_AVS,               MKTAG('A', 'V', 'S', ' ')},
+    { AV_CODEC_ID_BETHSOFTVID,       MKTAG('B', 'E', 'T', 'H')},
+    { AV_CODEC_ID_BFI,               MKTAG('B', 'F', 'I', 'V')},
+    { AV_CODEC_ID_C93,               MKTAG('C', '9', '3', 'V')},
+    { AV_CODEC_ID_CDGRAPHICS,        MKTAG('C', 'D', 'G', 'R')},
+    { AV_CODEC_ID_DNXHD,             MKTAG('A', 'V', 'd', 'n')},
+    { AV_CODEC_ID_DSICINVIDEO,       MKTAG('D', 'C', 'I', 'V')},
+    { AV_CODEC_ID_DXA,               MKTAG('D', 'X', 'A', '1')},
+    { AV_CODEC_ID_FLIC,              MKTAG('F', 'L', 'I', 'C')},
+    { AV_CODEC_ID_IDCIN,             MKTAG('I', 'D', 'C', 'I')},
+    { AV_CODEC_ID_INTERPLAY_VIDEO,   MKTAG('I', 'N', 'P', 'V')},
+    { AV_CODEC_ID_JV,                MKTAG('F', 'F', 'J', 'V')},
+    { AV_CODEC_ID_MDEC,              MKTAG('M', 'D', 'E', 'C')},
+    { AV_CODEC_ID_MOTIONPIXELS,      MKTAG('M', 'V', 'I', '1')},
+    { AV_CODEC_ID_NUV,               MKTAG('N', 'U', 'V', '1')},
+    { AV_CODEC_ID_RL2,               MKTAG('R', 'L', '2', 'V')},
+    { AV_CODEC_ID_ROQ,               MKTAG('R', 'o', 'Q', 'V')},
+    { AV_CODEC_ID_RV10,              MKTAG('R', 'V', '1', '0')},
+    { AV_CODEC_ID_RV20,              MKTAG('R', 'V', '2', '0')},
+    { AV_CODEC_ID_RV30,              MKTAG('R', 'V', '3', '0')},
+    { AV_CODEC_ID_RV40,              MKTAG('R', 'V', '4', '0')},
+    { AV_CODEC_ID_SVQ3,              MKTAG('S', 'V', 'Q', '3')},
+    { AV_CODEC_ID_TGV,               MKTAG('f', 'V', 'G', 'T')},
+    { AV_CODEC_ID_THP,               MKTAG('T', 'H', 'P', 'V')},
+    { AV_CODEC_ID_TIERTEXSEQVIDEO,   MKTAG('T', 'S', 'E', 'Q')},
+    { AV_CODEC_ID_TXD,               MKTAG('T', 'X', 'D', 'V')},
+    { AV_CODEC_ID_VP6A,              MKTAG('V', 'P', '6', 'A')},
+    { AV_CODEC_ID_VMDVIDEO,          MKTAG('V', 'M', 'D', 'V')},
+    { AV_CODEC_ID_WS_VQA,            MKTAG('V', 'Q', 'A', 'V')},
+    { AV_CODEC_ID_XAN_WC3,           MKTAG('W', 'C', '3', 'V')},
     { 0, 0 },
 };
 
-static unsigned int codec_get_tag(const struct tag *tags, enum CodecID id)
+static unsigned int codec_get_tag(const struct tag *tags, enum AVCodecID id)
 {
-    while (tags->id != CODEC_ID_NONE) {
+    while (tags->id != AV_CODEC_ID_NONE) {
         if (tags->id == id)
             return tags->tag;
         tags++;
@@ -134,12 +134,12 @@ static unsigned int codec_get_tag(const struct tag *tags, enum CodecID id)
     return 0;
 }
 
-unsigned int mp_taglist_override(enum CodecID id)
+unsigned int mp_taglist_override(enum AVCodecID id)
 {
     return codec_get_tag(mp_codecid_override_tags, id);
 }
 
-unsigned int mp_taglist_video(enum CodecID id)
+unsigned int mp_taglist_video(enum AVCodecID id)
 {
     const struct AVCodecTag *tags[] = {avformat_get_riff_video_tags(), NULL };
     unsigned int tag = av_codec_get_tag(tags, id);
@@ -148,7 +148,7 @@ unsigned int mp_taglist_video(enum CodecID id)
     return codec_get_tag(mp_bmp_tags, id);
 }
 
-unsigned int mp_taglist_audio(enum CodecID id)
+unsigned int mp_taglist_audio(enum AVCodecID id)
 {
     const struct AVCodecTag *tags[] = {avformat_get_riff_audio_tags(), NULL };
     unsigned int tag = av_codec_get_tag(tags, id);
diff --git a/libmpdemux/mp_taglists.h b/libmpdemux/mp_taglists.h
index d23a982..251bf2d 100644
--- a/libmpdemux/mp_taglists.h
+++ b/libmpdemux/mp_taglists.h
@@ -21,8 +21,8 @@
 
 #include <libavcodec/avcodec.h>
 
-unsigned int mp_taglist_override(enum CodecID id);
-unsigned int mp_taglist_video(enum CodecID id);
-unsigned int mp_taglist_audio(enum CodecID id);
+unsigned int mp_taglist_override(enum AVCodecID id);
+unsigned int mp_taglist_video(enum AVCodecID id);
+unsigned int mp_taglist_audio(enum AVCodecID id);
 
 #endif /* MPLAYER_MP_TAGLISTS_H */
diff --git a/libmpdemux/stheader.h b/libmpdemux/stheader.h
index bbcaed0..9c1efb2 100644
--- a/libmpdemux/stheader.h
+++ b/libmpdemux/stheader.h
@@ -127,6 +127,7 @@ typedef struct sh_video {
     AVIStreamHeader video;
     BITMAPINFOHEADER *bih;
     void *ImageDesc; // for quicktime codecs
+    bool is_attached_pic;
 } sh_video_t;
 
 typedef struct sh_sub {
diff --git a/libmpdemux/video.c b/libmpdemux/video.c
index def9cac..1ea8519 100644
--- a/libmpdemux/video.c
+++ b/libmpdemux/video.c
@@ -21,9 +21,6 @@
 #include "config.h"
 
 #include <stdio.h>
-#if HAVE_MALLOC_H
-#include <malloc.h>
-#endif
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -124,7 +121,7 @@ switch(video_codec){
    }
    mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
    if(!videobuffer) {
-     videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
      if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"Cannot allocate shared memory.\n");
@@ -219,7 +216,7 @@ switch(video_codec){
    }
    mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
    if(!videobuffer) {
-     videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
      if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"Cannot allocate shared memory.\n");
@@ -284,7 +281,7 @@ mpeg_header_parser:
    mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
    // ========= Read & process sequence header & extension ============
    if(!videobuffer) {
-     videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
      if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"Cannot allocate shared memory.\n");
@@ -352,7 +349,7 @@ mpeg_header_parser:
    }
    mp_msg(MSGT_DECVIDEO,MSGL_INFO,"found\n");
    if(!videobuffer) {
-     videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
      if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"Cannot allocate shared memory.\n");
diff --git a/libvo/vo_gl3.c b/libvo/vo_gl3.c
index 99a1380..9647c85 100644
--- a/libvo/vo_gl3.c
+++ b/libvo/vo_gl3.c
@@ -1462,6 +1462,11 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
         gl->Disable(GL_BLEND);
         gl->BindTexture(GL_TEXTURE_2D, 0);
     }
+
+    // The playloop calls this last before waiting some time until it decides
+    // to call flip_page(). Tell OpenGL to start execution of the GPU commands
+    // while we sleep (this happens asynchronously).
+    gl->Flush();
 }
 
 static void gen_eosd(struct gl_priv *p, mp_eosd_images_t *imgs)
diff --git a/libvo/vo_png.c b/libvo/vo_png.c
index ea2b763..50dffb7 100644
--- a/libvo/vo_png.c
+++ b/libvo/vo_png.c
@@ -66,7 +66,7 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin
 
     mp_msg(MSGT_VO,MSGL_DBG2, "PNG Compression level %i\n", z_compression);
     uninit();
-    struct AVCodec *png_codec = avcodec_find_encoder(CODEC_ID_PNG);
+    struct AVCodec *png_codec = avcodec_find_encoder(AV_CODEC_ID_PNG);
     if (!png_codec)
         goto error;
     avctx = avcodec_alloc_context3(png_codec);
diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c
index 0c99f5d..6102714 100644
--- a/libvo/vo_vdpau.c
+++ b/libvo/vo_vdpau.c
@@ -870,7 +870,6 @@ static int config(struct vo *vo, uint32_t width, uint32_t height,
     XSetWindowAttributes xswa;
     XWindowAttributes attribs;
     unsigned long xswamask;
-    int depth;
 
 #ifdef CONFIG_XF86VM
     int vm = flags & VOFLAG_MODESWITCHING;
@@ -898,10 +897,8 @@ static int config(struct vo *vo, uint32_t width, uint32_t height,
 #endif
     XGetWindowAttributes(x11->display, DefaultRootWindow(x11->display),
                          &attribs);
-    depth = attribs.depth;
-    if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
-        depth = 24;
-    XMatchVisualInfo(x11->display, x11->screen, depth, TrueColor, &vinfo);
+    XMatchVisualInfo(x11->display, x11->screen, attribs.depth, TrueColor,
+                     &vinfo);
 
     xswa.background_pixel = 0;
     xswa.border_pixel     = 0;
diff --git a/libvo/vo_x11.c b/libvo/vo_x11.c
index 03f73de..4a641fb 100644
--- a/libvo/vo_x11.c
+++ b/libvo/vo_x11.c
@@ -77,6 +77,7 @@ static unsigned char *ImageDataOrig;
 static XImage *myximage = NULL;
 static int depth, bpp;
 static XWindowAttributes attribs;
+int vo_depthonscreen;
 
 static int int_pause;
 
@@ -152,6 +153,58 @@ extern int sws_flags;
 
 static XVisualInfo vinfo;
 
+/*
+ * Scan the available visuals on this Display/Screen.  Try to find
+ * the 'best' available TrueColor visual that has a decent color
+ * depth (at least 15bit).  If there are multiple visuals with depth
+ * >= 15bit, we prefer visuals with a smaller color depth.
+ */
+static int vo_find_depth_from_visuals(Display * dpy, int screen,
+                                      Visual ** visual_return)
+{
+    XVisualInfo visual_tmpl;
+    XVisualInfo *visuals;
+    int nvisuals, i;
+    int bestvisual = -1;
+    int bestvisual_depth = -1;
+
+    visual_tmpl.screen = screen;
+    visual_tmpl.class = TrueColor;
+    visuals = XGetVisualInfo(dpy,
+                             VisualScreenMask | VisualClassMask,
+                             &visual_tmpl, &nvisuals);
+    if (visuals != NULL)
+    {
+        for (i = 0; i < nvisuals; i++)
+        {
+            mp_msg(MSGT_VO, MSGL_V,
+                   "vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n",
+                   visuals[i].visualid, visuals[i].depth,
+                   visuals[i].red_mask, visuals[i].green_mask,
+                   visuals[i].blue_mask);
+            /*
+             * Save the visual index and its depth, if this is the first
+             * truecolor visul, or a visual that is 'preferred' over the
+             * previous 'best' visual.
+             */
+            if (bestvisual_depth == -1
+                || (visuals[i].depth >= 15
+                    && (visuals[i].depth < bestvisual_depth
+                        || bestvisual_depth < 15)))
+            {
+                bestvisual = i;
+                bestvisual_depth = visuals[i].depth;
+            }
+        }
+
+        if (bestvisual != -1 && visual_return != NULL)
+            *visual_return = visuals[bestvisual].visual;
+
+        XFree(visuals);
+    }
+    return bestvisual_depth;
+}
+
 static void getMyXImage(void)
 {
 #ifdef HAVE_SHM
@@ -634,6 +687,54 @@ static int preinit(const char *arg)
 
     if (!vo_init())
         return -1;              // Can't open X11
+
+    XWindowAttributes attribs;
+    XGetWindowAttributes(mDisplay, mRootWin, &attribs);
+    depth = attribs.depth;
+    XImage *mXImage = NULL;
+    if (depth != 15 && depth != 16 && depth != 24 && depth != 32) {
+        Visual *visual;
+
+        depth = vo_find_depth_from_visuals(mDisplay, mScreen, &visual);
+        if (depth != -1)
+            mXImage = XCreateImage(mDisplay, visual, depth, ZPixmap,
+                                   0, NULL, 1, 1, 8, 1);
+    } else
+        mXImage =
+            XGetImage(mDisplay, mRootWin, 0, 0, 1, 1, AllPlanes, ZPixmap);
+
+    vo_depthonscreen = depth;   // display depth on screen
+
+    // get bits/pixel from XImage structure:
+    unsigned int mask;
+    if (mXImage == NULL) {
+        mask = 0;
+    } else {
+        /*
+         * for the depth==24 case, the XImage structures might use
+         * 24 or 32 bits of data per pixel.  The vo_depthonscreen
+         * field stores the amount of data per pixel in the
+         * XImage structure!
+         *
+         * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
+         */
+        bpp = mXImage->bits_per_pixel;
+        if ((vo_depthonscreen + 7) / 8 != (bpp + 7) / 8)
+            vo_depthonscreen = bpp;     // by A'rpi
+        mask =
+            mXImage->red_mask | mXImage->green_mask | mXImage->blue_mask;
+        mp_msg(MSGT_VO, MSGL_V,
+               "vo: X11 color mask:  %X  (R:%lX G:%lX B:%lX)\n", mask,
+               mXImage->red_mask, mXImage->green_mask, mXImage->blue_mask);
+        XDestroyImage(mXImage);
+    }
+    if (((vo_depthonscreen + 7) / 8) == 2)
+    {
+        if (mask == 0x7FFF)
+            vo_depthonscreen = 15;
+        else if (mask == 0xFFFF)
+            vo_depthonscreen = 16;
+    }
     return 0;
 }
 
diff --git a/libvo/vo_xv.c b/libvo/vo_xv.c
index e737754..2300cc6 100644
--- a/libvo/vo_xv.c
+++ b/libvo/vo_xv.c
@@ -186,7 +186,6 @@ static int config(struct vo *vo, uint32_t width, uint32_t height,
     XSetWindowAttributes xswa;
     XWindowAttributes attribs;
     unsigned long xswamask;
-    int depth;
     struct xvctx *ctx = vo->priv;
     int i;
 
@@ -230,10 +229,8 @@ static int config(struct vo *vo, uint32_t width, uint32_t height,
 #endif
         XGetWindowAttributes(x11->display, DefaultRootWindow(x11->display),
                              &attribs);
-        depth = attribs.depth;
-        if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
-            depth = 24;
-        XMatchVisualInfo(x11->display, x11->screen, depth, TrueColor, &vinfo);
+        XMatchVisualInfo(x11->display, x11->screen, attribs.depth, TrueColor,
+                         &vinfo);
 
         xswa.border_pixel = 0;
         xswamask = CWBorderPixel;
diff --git a/libvo/x11_common.c b/libvo/x11_common.c
index b41e30e..7caa5c6 100644
--- a/libvo/x11_common.c
+++ b/libvo/x11_common.c
@@ -381,16 +381,7 @@ void update_xinerama_info(struct vo *vo) {
 int vo_init(struct vo *vo)
 {
     struct MPOpts *opts = vo->opts;
-// int       mScreen;
-    int depth, bpp;
-    unsigned int mask;
 
-// char    * DisplayName = ":0.0";
-// Display * mDisplay;
-    XImage *mXImage = NULL;
-
-// Window    mRootWin;
-    XWindowAttributes attribs;
     char *dispName;
 
     assert(vo->x11 == NULL);
@@ -447,54 +438,9 @@ int vo_init(struct vo *vo)
             opts->vo_screenheight = DisplayHeight(x11->display, x11->screen);
     }
     // get color depth (from root window, or the best visual):
+    XWindowAttributes attribs;
     XGetWindowAttributes(x11->display, x11->rootwin, &attribs);
-    depth = attribs.depth;
-
-    if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
-    {
-        Visual *visual;
-
-        depth = vo_find_depth_from_visuals(x11->display, x11->screen, &visual);
-        if (depth != -1)
-            mXImage = XCreateImage(x11->display, visual, depth, ZPixmap,
-                                   0, NULL, 1, 1, 8, 1);
-    } else
-        mXImage =
-            XGetImage(x11->display, x11->rootwin, 0, 0, 1, 1, AllPlanes, ZPixmap);
-
-    x11->depthonscreen = depth;   // display depth on screen
 
-    // get bits/pixel from XImage structure:
-    if (mXImage == NULL)
-    {
-        mask = 0;
-    } else
-    {
-        /*
-         * for the depth==24 case, the XImage structures might use
-         * 24 or 32 bits of data per pixel.  The x11->depthonscreen
-         * field stores the amount of data per pixel in the
-         * XImage structure!
-         *
-         * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
-         */
-        bpp = mXImage->bits_per_pixel;
-        if ((x11->depthonscreen + 7) / 8 != (bpp + 7) / 8)
-            x11->depthonscreen = bpp;     // by A'rpi
-        mask =
-            mXImage->red_mask | mXImage->green_mask | mXImage->blue_mask;
-        mp_msg(MSGT_VO, MSGL_V,
-               "vo: X11 color mask:  %X  (R:%lX G:%lX B:%lX)\n", mask,
-               mXImage->red_mask, mXImage->green_mask, mXImage->blue_mask);
-        XDestroyImage(mXImage);
-    }
-    if (((x11->depthonscreen + 7) / 8) == 2)
-    {
-        if (mask == 0x7FFF)
-            x11->depthonscreen = 15;
-        else if (mask == 0xFFFF)
-            x11->depthonscreen = 16;
-    }
 // XCloseDisplay( mDisplay );
 /* slightly improved local display detection AST */
     if (strncmp(dispName, "unix:", 5) == 0)
@@ -506,8 +452,8 @@ int vo_init(struct vo *vo)
     else
         x11->display_is_local = 0;
     mp_msg(MSGT_VO, MSGL_V,
-           "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
-           opts->vo_screenwidth, opts->vo_screenheight, depth, x11->depthonscreen,
+           "vo: X11 running at %dx%d with depth %d (\"%s\" => %s display)\n",
+           opts->vo_screenwidth, opts->vo_screenheight, attribs.depth,
            dispName, x11->display_is_local ? "local" : "remote");
 
     x11->wm_type = vo_wm_detect(vo);
@@ -534,7 +480,6 @@ void vo_uninit(struct vo_x11_state *x11)
             XCloseIM(x11->xim);
         XSetErrorHandler(NULL);
         XCloseDisplay(x11->display);
-        x11->depthonscreen = 0;
         x11->display = NULL;
     }
     talloc_free(x11);
@@ -1741,59 +1686,6 @@ double vo_vm_get_fps(struct vo *vo)
 #endif
 
 
-/*
- * Scan the available visuals on this Display/Screen.  Try to find
- * the 'best' available TrueColor visual that has a decent color
- * depth (at least 15bit).  If there are multiple visuals with depth
- * >= 15bit, we prefer visuals with a smaller color depth.
- */
-int vo_find_depth_from_visuals(Display * dpy, int screen,
-                               Visual ** visual_return)
-{
-    XVisualInfo visual_tmpl;
-    XVisualInfo *visuals;
-    int nvisuals, i;
-    int bestvisual = -1;
-    int bestvisual_depth = -1;
-
-    visual_tmpl.screen = screen;
-    visual_tmpl.class = TrueColor;
-    visuals = XGetVisualInfo(dpy,
-                             VisualScreenMask | VisualClassMask,
-                             &visual_tmpl, &nvisuals);
-    if (visuals != NULL)
-    {
-        for (i = 0; i < nvisuals; i++)
-        {
-            mp_msg(MSGT_VO, MSGL_V,
-                   "vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n",
-                   visuals[i].visualid, visuals[i].depth,
-                   visuals[i].red_mask, visuals[i].green_mask,
-                   visuals[i].blue_mask);
-            /*
-             * Save the visual index and its depth, if this is the first
-             * truecolor visul, or a visual that is 'preferred' over the
-             * previous 'best' visual.
-             */
-            if (bestvisual_depth == -1
-                || (visuals[i].depth >= 15
-                    && (visuals[i].depth < bestvisual_depth
-                        || bestvisual_depth < 15)))
-            {
-                bestvisual = i;
-                bestvisual_depth = visuals[i].depth;
-            }
-        }
-
-        if (bestvisual != -1 && visual_return != NULL)
-            *visual_return = visuals[bestvisual].visual;
-
-        XFree(visuals);
-    }
-    return bestvisual_depth;
-}
-
-
 static Colormap cmap = None;
 static XColor cols[256];
 static int cm_size, red_mask, green_mask, blue_mask;
diff --git a/libvo/x11_common.h b/libvo/x11_common.h
index 57353e4..e0292c5 100644
--- a/libvo/x11_common.h
+++ b/libvo/x11_common.h
@@ -34,7 +34,6 @@ struct vo_x11_state {
     Window rootwin;
     int screen;
     int display_is_local;
-    int depthonscreen;
 
     XIM xim;
     XIC xic;
@@ -178,7 +177,6 @@ double vo_vm_get_fps(struct vo *vo);
 
 void update_xinerama_info(struct vo *vo);
 
-int vo_find_depth_from_visuals(Display *dpy, int screen, Visual **visual_return);
 void xscreensaver_heartbeat(struct vo_x11_state *x11);
 
 // Old VOs use incompatible function calls, translate them to new
@@ -213,7 +211,6 @@ void xscreensaver_heartbeat(struct vo_x11_state *x11);
 #define vo_x11_border() vo_x11_border(global_vo)
 
 #define mDisplay global_vo->x11->display
-#define vo_depthonscreen global_vo->x11->depthonscreen
 #define vo_window global_vo->x11->window
 #define xv_ck_info global_vo->x11->xv_ck_info
 #define xv_colorkey global_vo->x11->xv_colorkey
diff --git a/loader/wrapper.S b/loader/wrapper.S
index fbf3ce2..b0c8389 100644
--- a/loader/wrapper.S
+++ b/loader/wrapper.S
@@ -2,6 +2,7 @@
 
 #define GLUE(a, b) a ## b
 #define JOIN(a, b) GLUE(a, b)
+#define EXTERN_ASM
 #define MANGLE(s)  JOIN(EXTERN_ASM, s)
 
 .data
diff --git a/mangle.h b/mangle.h
index 64c6f75..fbec0d0 100644
--- a/mangle.h
+++ b/mangle.h
@@ -31,6 +31,12 @@
 #define attribute_used
 #endif
 
+#if defined(_WIN32) && !defined(_WIN64) || defined(__APPLE__)
+#define EXTERN_PREFIX "_"
+#else
+#define EXTERN_PREFIX ""
+#endif
+
 #if ARCH_X86_64 && defined(PIC)
 #define MANGLE(a) EXTERN_PREFIX #a "(%%rip)"
 #else
diff --git a/mp_msg.c b/mp_msg.c
index 7b97d28..eea6567 100644
--- a/mp_msg.c
+++ b/mp_msg.c
@@ -244,7 +244,7 @@ static void print_msg_module(FILE* stream, int mod)
 void mp_msg_va(int mod, int lev, const char *format, va_list va)
 {
     char tmp[MSGSIZE_MAX];
-    FILE *stream = lev <= MSGL_WARN ? stderr : stdout;
+    FILE *stream = mod == MSGT_STATUSLINE ? stderr : stdout;
     static int header = 1;
     // indicates if last line printed was a status line
     static int statusline;
@@ -298,9 +298,9 @@ void mp_msg_va(int mod, int lev, const char *format, va_list va)
     /* A status line is normally intended to be overwritten by the next
      * status line, and does not end with a '\n'. If we're printing a normal
      * line instead after the status one print '\n' to change line. */
-    if (statusline && lev != MSGL_STATUS)
-        fprintf(stream, "\n");
-    statusline = lev == MSGL_STATUS;
+    if (statusline && mod != MSGT_STATUSLINE)
+        fprintf(stderr, "\n");
+    statusline = mod == MSGT_STATUSLINE;
 
     if (header)
         print_msg_module(stream, mod);
@@ -314,7 +314,7 @@ void mp_msg_va(int mod, int lev, const char *format, va_list va)
     if (mp_msg_color)
     {
 #ifdef _WIN32
-        HANDLE *wstream = lev <= MSGL_WARN ? hSTDERR : hSTDOUT;
+        HANDLE *wstream = stream == stderr ? hSTDERR : hSTDOUT;
         SetConsoleTextAttribute(wstream, stdoutAttrs);
 #else
         fprintf(stream, "\033[0m");
diff --git a/mp_msg.h b/mp_msg.h
index 686ed83..300ee3c 100644
--- a/mp_msg.h
+++ b/mp_msg.h
@@ -101,15 +101,11 @@ extern int verbose;
 
 #define MSGT_CODECCFG 33
 
-#define MSGT_SWS 34
-
 #define MSGT_VOBSUB 35
 #define MSGT_SUBREADER 36
 
 #define MSGT_AFILTER 37  // Audio filter messages
 
-#define MSGT_NETST 38 // Netstream
-
 #define MSGT_MUXER 39 // muxer layer
 
 #define MSGT_IDENTIFY 41  // -identify output
diff --git a/mplayer.c b/mplayer.c
index 9feca0a..dab8535 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -251,23 +251,7 @@ static const char help_text[] = _(
 "           ************************************************\n"\
 "           **** Your system is too SLOW to play this!  ****\n"\
 "           ************************************************\n\n"\
-"Possible reasons, problems, workarounds:\n"\
-"- Most common: broken/buggy _audio_ driver\n"\
-"  - Try -ao sdl or use the OSS emulation of ALSA.\n"\
-"  - Experiment with different values for -autosync, 30 is a good start.\n"\
-"- Slow video output\n"\
-"  - Try a different -vo driver (-vo help for a list) or try -framedrop!\n"\
-"- Slow CPU\n"\
-"  - Don't try to play a big DVD/DivX on a slow CPU! Try some of the lavdopts,\n"\
-"    e.g. -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all.\n"\
-"- Broken file\n"\
-"  - Try various combinations of -nobps -ni -forceidx -mc 0.\n"\
-"- Slow media (NFS/SMB mounts, DVD, VCD etc)\n"\
-"  - Try -cache 8192.\n"\
-"- Are you using -cache to play a non-interleaved AVI file?\n"\
-"  - Try -nocache.\n"\
-"Read DOCS/HTML/en/video.html for tuning/speedup tips.\n"\
-"If none of this helps you, read DOCS/HTML/en/bugreports.html.\n\n")
+)
 
 
 //**************************************************************************//
@@ -1669,7 +1653,7 @@ static void update_osd_msg(struct MPContext *mpctx)
             if (mpctx->sh_video)
                 vo_osd_changed(OSDTYPE_OSD);
             else if (opts->term_osd)
-                mp_msg(MSGT_CPLAYER, MSGL_STATUS, "%s%s\n", opts->term_osd_esc,
+                mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "%s%s\n", opts->term_osd_esc,
                        msg->msg);
         }
         return;
@@ -1750,7 +1734,7 @@ static void update_osd_msg(struct MPContext *mpctx)
     // Clear the term osd line
     if (opts->term_osd && osd->osd_text[0]) {
         osd->osd_text[0] = 0;
-        mp_msg(MSGT_CPLAYER, MSGL_STATUS, "%s\n", opts->term_osd_esc);
+        mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "%s\n", opts->term_osd_esc);
     }
 }
 
@@ -2944,8 +2928,8 @@ static void update_pause_message(struct MPContext *mpctx)
         update_osd_msg(mpctx);
     } else {
         if (mpctx->status_printed)
-            mp_msg(MSGT_CPLAYER, MSGL_STATUS, "\n");
-        mp_msg(MSGT_CPLAYER, MSGL_STATUS, "%s\r", msg);
+            mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "\n");
+        mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "%s\r", msg);
     }
 
     mpctx->paused_cache_fill = cache_fill;
diff --git a/options.h b/options.h
index a0e9b39..8ea635f 100644
--- a/options.h
+++ b/options.h
@@ -129,7 +129,6 @@ typedef struct MPOpts {
         int skip_top;
         int skip_bottom;
         int fast;
-        char *lowres_str;
         char *skip_loop_filter_str;
         char *skip_idct_str;
         char *skip_frame_str;
diff --git a/osdep/io.c b/osdep/io.c
index e3e750e..fc0da61 100644
--- a/osdep/io.c
+++ b/osdep/io.c
@@ -87,7 +87,7 @@ void mp_get_converted_argv(int *argc, char ***argv)
 int mp_stat(const char *path, struct stat *buf)
 {
     wchar_t *wpath = mp_from_utf8(NULL, path);
-    int res = _wstat64(wpath, buf);
+    int res = _wstati64(wpath, buf);
     talloc_free(wpath);
     return res;
 }
diff --git a/osdep/io.h b/osdep/io.h
index 462a849..a1fd273 100644
--- a/osdep/io.h
+++ b/osdep/io.h
@@ -55,7 +55,7 @@ struct dirent *mp_readdir(DIR *dir);
 int mp_closedir(DIR *dir);
 int mp_mkdir(const char *path, int mode);
 
-// NOTE: Stat is not overridden with mp_stat, because MinGW-w64 defines it as
+// NOTE: stat is not overridden with mp_stat, because MinGW-w64 defines it as
 //       macro.
 
 #define fprintf(...) mp_fprintf(__VA_ARGS__)
diff --git a/screenshot.c b/screenshot.c
index 38043da..81ae2d0 100644
--- a/screenshot.c
+++ b/screenshot.c
@@ -83,7 +83,7 @@ static int write_png(screenshot_ctx *ctx, struct mp_image *image)
     void *outbuffer = NULL;
     int success = 0;
 
-    struct AVCodec *png_codec = avcodec_find_encoder(CODEC_ID_PNG);
+    struct AVCodec *png_codec = avcodec_find_encoder(AV_CODEC_ID_PNG);
     AVCodecContext *avctx = NULL;
     if (!png_codec)
         goto print_open_fail;
diff --git a/stream/cache2.c b/stream/cache2.c
index 1f948e0..ab87426 100644
--- a/stream/cache2.c
+++ b/stream/cache2.c
@@ -477,7 +477,7 @@ int stream_enable_cache(stream_t *stream, int size, int min, int seek_limit)
     mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %"PRId64" [%"PRId64"] %"PRId64"  pre:%d  eof:%d  \n",
 	(int64_t)s->min_filepos,(int64_t)s->read_filepos,(int64_t)s->max_filepos,min,s->eof);
     while(s->read_filepos<s->min_filepos || s->max_filepos-s->read_filepos<min){
-	mp_tmsg(MSGT_CACHE,MSGL_STATUS,"\rCache fill: %5.2f%% (%"PRId64" bytes)   ",
+	mp_tmsg(MSGT_STATUSLINE, MSGL_STATUS, "\rCache fill: %5.2f%% (%"PRId64" bytes)   ",
 	    100.0*(float)(s->max_filepos-s->read_filepos)/(float)(s->buffer_size),
 	    (int64_t)s->max_filepos-s->read_filepos
 	);
@@ -487,7 +487,6 @@ int stream_enable_cache(stream_t *stream, int size, int min, int seek_limit)
 	  goto err_out;
         }
     }
-    mp_msg(MSGT_CACHE,MSGL_STATUS,"\n");
     stream->cached = true;
     return 1; // parent exits
 
diff --git a/stream/stream.c b/stream/stream.c
index 1f61ba2..d4d08a5 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -64,7 +64,6 @@ static struct input_ctx *stream_check_interrupt_ctx;
 
 extern const stream_info_t stream_info_vcd;
 extern const stream_info_t stream_info_cdda;
-extern const stream_info_t stream_info_netstream;
 extern const stream_info_t stream_info_pnm;
 extern const stream_info_t stream_info_asf;
 extern const stream_info_t stream_info_rtp;
@@ -98,7 +97,6 @@ static const stream_info_t* const auto_open_streams[] = {
 #endif
   &stream_info_ffmpeg,  // use for rstp:// before http fallback
 #ifdef CONFIG_NETWORKING
-  &stream_info_netstream,
   &stream_info_http1,
   &stream_info_asf,
   &stream_info_pnm,
diff --git a/stream/stream_cdda.c b/stream/stream_cdda.c
index 0fcd3db..162cc3d 100644
--- a/stream/stream_cdda.c
+++ b/stream/stream_cdda.c
@@ -17,9 +17,20 @@
  */
 
 #include "config.h"
+
+#include <cdio/cdio.h>
+
+#if CDIO_API_VERSION < 6
+#define OLD_API
+#endif
+
+#ifdef OLD_API
 #include <cdio/cdda.h>
 #include <cdio/paranoia.h>
-#include <cdio/cdio.h>
+#else
+#include <cdio/paranoia/cdda.h>
+#include <cdio/paranoia/paranoia.h>
+#endif
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -116,6 +127,7 @@ const m_option_t cdda_opts[] = {
 };
 
 static const char *cdtext_name[] = {
+#ifdef OLD_API
     [CDTEXT_ARRANGER] = "Arranger",
     [CDTEXT_COMPOSER] = "Composer",
     [CDTEXT_MESSAGE]  =  "Message",
@@ -124,17 +136,35 @@ static const char *cdtext_name[] = {
     [CDTEXT_SONGWRITER] =  "Songwriter",
     [CDTEXT_TITLE] =  "Title",
     [CDTEXT_UPC_EAN] = "UPC_EAN",
+#else
+    [CDTEXT_FIELD_ARRANGER] = "Arranger",
+    [CDTEXT_FIELD_COMPOSER] = "Composer",
+    [CDTEXT_FIELD_MESSAGE]  =  "Message",
+    [CDTEXT_FIELD_ISRC] =  "ISRC",
+    [CDTEXT_FIELD_PERFORMER] = "Performer",
+    [CDTEXT_FIELD_SONGWRITER] =  "Songwriter",
+    [CDTEXT_FIELD_TITLE] =  "Title",
+    [CDTEXT_FIELD_UPC_EAN] = "UPC_EAN",
+#endif
 };
 
 static bool print_cdtext(stream_t *s, int track)
 {
     cdda_priv* p = (cdda_priv*)s->priv;
+#ifdef OLD_API
     cdtext_t *text = cdio_get_cdtext(p->cd->p_cdio, track);
+#else
+    cdtext_t *text = cdio_get_cdtext(p->cd->p_cdio);
+#endif
     if (text) {
         mp_msg(MSGT_SEEK, MSGL_INFO, "CD-Text (%s):\n", track ? "track" : "CD");
         for (int i = 0; i < sizeof(cdtext_name) / sizeof(cdtext_name[0]); i++) {
             const char *name = cdtext_name[i];
+#ifdef OLD_API
             const char *value = cdtext_get_const(i, text);
+#else
+            const char *value = cdtext_get_const(text, i, track);
+#endif
             if (name && value)
                 mp_msg(MSGT_SEEK, MSGL_INFO, "  %s: '%s'\n", name, value);
         }
diff --git a/stream/stream_netstream.c b/stream/stream_netstream.c
deleted file mode 100644
index 6240aa7..0000000
--- a/stream/stream_netstream.c
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * Copyright (C) Alban Bedel - 04/2003
- *
- * 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.
- */
-
-/*
- *  Net stream allow you to access MPlayer stream accross a tcp
- *  connection.
- *  Note that at least mf and tv use a dummy stream (they are
- *  implemented at the demuxer level) so you won't be able to
- *  access those :(( but dvd, vcd and so on should work perfectly
- *  (if you have the bandwidth ;)
- *   A simple server is in TOOLS/netstream.
- *
- */
-
-
-#include "config.h"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <inttypes.h>
-#include <errno.h>
-
-#if !HAVE_WINSOCK2_H
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#else
-#include <winsock2.h>
-#endif
-
-#include "mp_msg.h"
-#include "stream.h"
-#include "m_option.h"
-#include "m_struct.h"
-#include "libavutil/common.h"
-#include "mpbswap.h"
-
-#include "network.h"
-#include "stream_netstream.h"
-#include "tcp.h"
-
-static struct stream_priv_s {
-  char* host;
-  int port;
-  char* url;
-} stream_priv_dflts = {
-  NULL,
-  10000,
-  NULL
-};
-
-#define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
-/// URL definition
-static const m_option_t stream_opts_fields[] = {
-  {"hostname", ST_OFF(host), CONF_TYPE_STRING, 0, 0 ,0, NULL},
-  {"port", ST_OFF(port), CONF_TYPE_INT, M_OPT_MIN, 1 ,0, NULL},
-  {"filename", ST_OFF(url), CONF_TYPE_STRING, 0, 0 ,0, NULL},
-  { NULL, NULL, 0, 0, 0, 0,  NULL }
-};
-static const struct m_struct_st stream_opts = {
-  "netstream",
-  sizeof(struct stream_priv_s),
-  &stream_priv_dflts,
-  stream_opts_fields
-};
-
-//// When the cache is running we need a lock as
-//// fill_buffer is called from another proccess
-static int lock_fd(int fd) {
-#if !HAVE_WINSOCK2_H
-  struct flock lock;
-
-  memset(&lock,0,sizeof(struct flock));
-  lock.l_type = F_WRLCK;
-
-  mp_msg(MSGT_STREAM,MSGL_DBG2, "Lock (%d)\n",getpid());
-  do {
-    if(fcntl(fd,F_SETLKW,&lock)) {
-      if(errno == EAGAIN) continue;
-      mp_msg(MSGT_STREAM,MSGL_ERR, "Failed to get the lock: %s\n",
-	     strerror(errno));
-      return 0;
-    }
-  } while(0);
-  mp_msg(MSGT_STREAM,MSGL_DBG2, "Locked (%d)\n",getpid());
-#else
-printf("FIXME? should lock here\n");
-#endif
-  return 1;
-}
-
-static int unlock_fd(int fd) {
-#if !HAVE_WINSOCK2_H
-  struct flock lock;
-
-  memset(&lock,0,sizeof(struct flock));
-  lock.l_type = F_UNLCK;
-
-  mp_msg(MSGT_STREAM,MSGL_DBG2, "Unlock (%d)\n",getpid());
-  if(fcntl(fd,F_SETLK,&lock)) {
-    mp_msg(MSGT_STREAM,MSGL_ERR, "Failed to release the lock: %s\n",
-	   strerror(errno));
-    return 0;
-  }
-#else
-printf("FIXME? should unlock here\n");
-#endif
-  return 1;
-}
-
-static mp_net_stream_packet_t* send_net_stream_cmd(stream_t *s,uint16_t cmd,char* data,int len) {
-  mp_net_stream_packet_t* pack;
-
-  // Cache is enabled : lock
-  if(s->cache_data && !lock_fd(s->fd))
-    return NULL;
-  // Send a command
-  if(!write_packet(s->fd,cmd,data,len)) {
-    if(s->cache_data) unlock_fd(s->fd);
-    return 0;
-  }
-  // Read the response
-  pack = read_packet(s->fd);
-  // Now we can unlock
-  if(s->cache_data) unlock_fd(s->fd);
-
-  if(!pack)
-    return NULL;
-
-  switch(pack->cmd) {
-  case NET_STREAM_OK:
-    return pack;
-  case NET_STREAM_ERROR:
-    if(pack->len > sizeof(mp_net_stream_packet_t))
-      mp_msg(MSGT_STREAM,MSGL_ERR, "Fill buffer failed: %s\n",pack->data);
-    else
-      mp_msg(MSGT_STREAM,MSGL_ERR, "Fill buffer failed\n");
-    free(pack);
-    return NULL;
-  }
-
-  mp_msg(MSGT_STREAM,MSGL_ERR, "Unknown response to %d: %d\n",cmd,pack->cmd);
-  free(pack);
-  return NULL;
-}
-
-static int fill_buffer(stream_t *s, char* buffer, int max_len){
-  uint16_t len = le2me_16(max_len);
-  mp_net_stream_packet_t* pack;
-
-  pack = send_net_stream_cmd(s,NET_STREAM_FILL_BUFFER,(char*)&len,2);
-  if(!pack) {
-    return -1;
-  }
-  len = pack->len - sizeof(mp_net_stream_packet_t);
-  if(len > max_len) {
-    mp_msg(MSGT_STREAM,MSGL_ERR, "Got a too big a packet %d / %d\n",len,max_len);
-    free(pack);
-    return 0;
-  }
-  if(len > 0)
-    memcpy(buffer,pack->data,len);
-  free(pack);
-  return len;
-}
-
-
-static int seek(stream_t *s,off_t newpos) {
-  uint64_t pos = le2me_64((uint64_t)newpos);
-  mp_net_stream_packet_t* pack;
-
-  pack = send_net_stream_cmd(s,NET_STREAM_SEEK,(char*)&pos,8);
-  if(!pack) {
-    return 0;
-  }
-  s->pos = newpos;
-  free(pack);
-  return 1;
-}
-
-static int net_stream_reset(struct stream *s) {
-  mp_net_stream_packet_t* pack;
-
-  pack = send_net_stream_cmd(s,NET_STREAM_RESET,NULL,0);
-  if(!pack) {
-    return 0;
-  }
-  free(pack);
-  return 1;
-}
-
-static int control(struct stream *s,int cmd,void* arg) {
-  switch(cmd) {
-  case STREAM_CTRL_RESET:
-    return net_stream_reset(s);
-  }
-  return STREAM_UNSUPPORTED;
-}
-
-static void close_s(struct stream *s) {
-  mp_net_stream_packet_t* pack;
-
-  pack = send_net_stream_cmd(s,NET_STREAM_CLOSE,NULL,0);
-  free(pack);
-}
-
-static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
-  int f;
-  struct stream_priv_s* p = (struct stream_priv_s*)opts;
-  mp_net_stream_packet_t* pack;
-  mp_net_stream_opened_t* opened;
-
-  if(mode != STREAM_READ)
-    return STREAM_UNSUPPORTED;
-
-  if(!p->host) {
-    mp_msg(MSGT_OPEN,MSGL_ERR, "We need an host name (ex: mpst://server.net/cdda://5)\n");
-    m_struct_free(&stream_opts,opts);
-    return STREAM_ERROR;
-  }
-  if(!p->url || strlen(p->url) == 0) {
-    mp_msg(MSGT_OPEN,MSGL_ERR, "We need a remote url (ex: mpst://server.net/cdda://5)\n");
-    m_struct_free(&stream_opts,opts);
-    return STREAM_ERROR;
-  }
-
-  f = connect2Server(p->host,p->port,1);
-  if(f < 0) {
-    mp_msg(MSGT_OPEN,MSGL_ERR, "Connection to %s:%d failed\n",p->host,p->port);
-    m_struct_free(&stream_opts,opts);
-    return STREAM_ERROR;
-  }
-  stream->fd = f;
-  /// Now send an open command
-  pack = send_net_stream_cmd(stream,NET_STREAM_OPEN,p->url,strlen(p->url) + 1);
-  if(!pack) {
-    goto error;
-  }
-
-  if(pack->len != sizeof(mp_net_stream_packet_t) +
-     sizeof(mp_net_stream_opened_t)) {
-    mp_msg(MSGT_OPEN,MSGL_ERR, "Invalid open response packet len (%d bytes)\n",pack->len);
-    free(pack);
-    goto error;
-  }
-
-  opened = (mp_net_stream_opened_t*)pack->data;
-  net_stream_opened_2_me(opened);
-
-  *file_format = opened->file_format;
-  stream->flags = opened->flags;
-  stream->sector_size = opened->sector_size;
-  stream->start_pos = opened->start_pos;
-  stream->end_pos = opened->end_pos;
-
-  stream->fill_buffer = fill_buffer;
-  stream->control = control;
-  if(stream->flags & MP_STREAM_SEEK)
-    stream->seek = seek;
-  stream->close = close_s;
-
-  free(pack);
-  m_struct_free(&stream_opts,opts);
-
-  return STREAM_OK;
-
-  error:
-  closesocket(f);
-  m_struct_free(&stream_opts,opts);
-  return STREAM_ERROR;
-}
-
-const stream_info_t stream_info_netstream = {
-  "Net stream",
-  "netstream",
-  "Albeu",
-  "",
-  open_s,
-  { "mpst",NULL },
-  &stream_opts,
-  1 // Url is an option string
-};
diff --git a/stream/stream_netstream.h b/stream/stream_netstream.h
deleted file mode 100644
index 3843ee9..0000000
--- a/stream/stream_netstream.h
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Common stuff for netstream
- * Packets and so on are defined here along with a few helpers
- * wich are used by both the client and the server
- *
- * Data is always low endian
- *
- * 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.
- */
-
-#ifndef MPLAYER_NETSTREAM_H
-#define MPLAYER_NETSTREAM_H
-
-#include "config.h"
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#if !HAVE_WINSOCK2_H
-#include <sys/socket.h>
-#endif
-#include "mp_msg.h"
-#include "mpbswap.h"
-
-typedef struct mp_net_stream_packet_st {
-  uint16_t len;
-  uint8_t cmd;
-  char data[0];
-} __attribute__ ((packed))  mp_net_stream_packet_t;
-
-#define PACKET_MAX_SIZE 4096
-
-// Commands sent by the client
-#define NET_STREAM_OPEN 0
-// data is the url
-#define NET_STREAM_FILL_BUFFER 1
-// data is an uint16 wich is the max len of the data to return
-#define NET_STREAM_SEEK 3
-// data is an uint64 wich the pos where to seek
-#define NET_STREAM_CLOSE 4
-// no data
-#define NET_STREAM_RESET 5
-// no data
-
-// Server response
-#define NET_STREAM_OK 128
-// Data returned if open is successful
-typedef struct mp_net_stream_opened_st {
-  uint32_t file_format;
-  uint32_t flags;
-  uint32_t sector_size;
-  uint64_t start_pos;
-  uint64_t end_pos;
-}  __attribute__ ((packed))  mp_net_stream_opened_t;
-// FILL_BUFFER return the data
-// CLOSE return nothing
-#define NET_STREAM_ERROR 129
-// Data is the error message (if any ;)
-
-static int net_read(int fd, char* buf, int len) {
-  int r = 0;
-  while(len) {
-    r = recv(fd,buf,len,0);
-    if(r <= 0) {
-      if(errno == EINTR) continue;
-      if(r < 0)
-	mp_msg(MSGT_NETST,MSGL_ERR,"Read failed: %s\n",strerror(errno));
-      return 0;
-    }
-    len -= r;
-    buf += r;
-  }
-  return 1;
-}
-
-static mp_net_stream_packet_t* read_packet(int fd) {
-  uint16_t len;
-  mp_net_stream_packet_t* pack = malloc(sizeof(mp_net_stream_packet_t));
-
-  if(!net_read(fd,(char*)pack,sizeof(mp_net_stream_packet_t))) {
-    free(pack);
-    return NULL;
-  }
-  pack->len = le2me_16(pack->len);
-
-  if(pack->len < sizeof(mp_net_stream_packet_t)) {
-    mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid packet (too small: %d)\n",pack->len);
-    free(pack);
-    return NULL;
-  }
-  if(pack->len > PACKET_MAX_SIZE) {
-    mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid packet (too big: %d)\n",pack->len);
-    free(pack);
-    return NULL;
-  }
-  len = pack->len;
-  if(len > sizeof(mp_net_stream_packet_t)) {
-    pack = realloc(pack,len);
-    if(!pack) {
-      mp_msg(MSGT_NETST,MSGL_ERR,"Failed to get memory for the packet (%d bytes)\n",len);
-      return NULL;
-    }
-    if(!net_read(fd,pack->data,len - sizeof(mp_net_stream_packet_t)))
-      return NULL;
-  }
-  //  printf ("Read packet %d %d %d\n",fd,pack->cmd,pack->len);
-  return pack;
-}
-
-static int net_write(int fd, char* buf, int len) {
-  int w;
-  while(len) {
-    w = send(fd,buf,len,DEFAULT_SEND_FLAGS);
-    if(w <= 0) {
-      if(errno == EINTR) continue;
-      if(w < 0)
-	mp_msg(MSGT_NETST,MSGL_ERR,"Write failed: %s\n",strerror(errno));
-      return 0;
-    }
-    len -= w;
-    buf += w;
-  }
-  return 1;
-}
-
-static int write_packet(int fd, uint8_t cmd,char* data,int len) {
-  mp_net_stream_packet_t* pack = malloc(len + sizeof(mp_net_stream_packet_t));
-
-  if(len > 0 && data)
-    memcpy(pack->data,data,len);
-  pack->len = len + sizeof(mp_net_stream_packet_t);
-  pack->cmd = cmd;
-
-  //  printf("Write packet %d %d (%p) %d\n",fd,cmd,data,len);
-  pack->len = le2me_16(pack->len);
-  if(net_write(fd,(char*)pack,pack->len)) {
-    free(pack);
-    return 1;
-  }
-  free(pack);
-  return 0;
-}
-
-static void net_stream_opened_2_me(mp_net_stream_opened_t* o) {
-  o->file_format = le2me_32(o->file_format);
-  o->flags = le2me_32(o->flags);
-  o->sector_size = le2me_32(o->sector_size);
-  o->start_pos = le2me_64(o->start_pos);
-  o->end_pos = le2me_64(o->end_pos);
-}
-
-#endif /* MPLAYER_NETSTREAM_H */
diff --git a/stream/stream_radio.c b/stream/stream_radio.c
index f7612f0..245f889 100644
--- a/stream/stream_radio.c
+++ b/stream/stream_radio.c
@@ -49,10 +49,6 @@
 #include <linux/videodev2.h>
 #endif
 
-#ifdef CONFIG_RADIO_V4L
-#include <linux/videodev.h>
-#endif
-
 #endif // !IOCTL_BT848_H_NAME
 
 
@@ -408,137 +404,6 @@ static const radio_driver_t radio_driver_v4l2={
     get_frequency_v4l2
 };
 #endif /* CONFIG_RADIO_V4L2 */
-#ifdef CONFIG_RADIO_V4L
-/*****************************************************************
- * \brief get fraction value for using in set_frequency and get_frequency
- * \return STREAM_OK if success, STREAM_ERROR otherwise
- *
- * V4L2_TUNER_CAP_LOW:
- * unit=62.5Hz
- * frac= 1MHz/unit=1000000/62.5 =16000
- *
- * otherwise:
- * unit=62500Hz
- * frac= 1MHz/unit=1000000/62500 =16
- *
- */
-static int init_frac_v4l(radio_priv_t* priv){
-    struct video_tuner tuner;
-    memset(&tuner,0,sizeof(tuner));
-    if (ioctl(priv->radio_fd, VIDIOCGTUNER, &tuner) <0){
-        mp_tmsg(MSGT_RADIO,MSGL_WARN,"[radio] Warning: ioctl get tuner failed: %s. Setting frac to %d.\n",strerror(errno),priv->frac);
-        return  STREAM_ERROR;
-    }
-    if(tuner.flags & VIDEO_TUNER_LOW){
-        priv->frac=16000;
-        mp_tmsg(MSGT_RADIO,MSGL_DBG2,"[radio] tuner is low:yes frac=%d\n",priv->frac);
-    }else{
-        priv->frac=16;
-        mp_tmsg(MSGT_RADIO,MSGL_DBG2,"[radio] tuner is low:no frac=%d\n",priv->frac);
-    }
-
-    priv->rangelow=((float)tuner.rangelow)/priv->frac;
-    priv->rangehigh=((float)tuner.rangehigh)/priv->frac;
-    mp_tmsg(MSGT_RADIO,MSGL_V,"[radio] Allowed frequency range is %.2f-%.2f MHz.\n",priv->rangelow,priv->rangehigh);
-
-    return STREAM_OK;
-}
-
-/*****************************************************************
- * \brief tune card to given frequency
- * \param frequency frequency in MHz
- * \return STREAM_OK if success, STREAM_ERROR otherwise
- */
-static int set_frequency_v4l(radio_priv_t* priv,float frequency){
-    __u32 freq;
-    freq=frequency*priv->frac;
-    if (ioctl(priv->radio_fd, VIDIOCSFREQ, &freq) < 0) {
-        mp_tmsg(MSGT_RADIO,MSGL_ERR,"[radio] ioctl set frequency 0x%x (%.2f) failed: %s\n",freq,frequency,strerror(errno));
-        return  STREAM_ERROR;
-    }
-    return STREAM_OK;
-}
-/*****************************************************************
- * \brief get current tuned frequency from card
- * \param frequency where to store frequency in MHz
- * \return STREAM_OK if success, STREAM_ERROR otherwise
- */
-static int get_frequency_v4l(radio_priv_t* priv,float* frequency){
-    __u32 freq;
-    if (ioctl(priv->radio_fd, VIDIOCGFREQ, &freq) < 0) {
-        mp_tmsg(MSGT_RADIO,MSGL_ERR,"[radio] ioctl get frequency failed: %s\n",strerror(errno));
-        return  STREAM_ERROR;
-    }
-    *frequency=((float)freq)/priv->frac;
-    return STREAM_OK;
-}
-
-/*****************************************************************
- * \brief set volume on radio card
- * \param volume volume level (0..100)
- * \return STREAM_OK if success, STREAM_ERROR otherwise
- */
-static void set_volume_v4l(radio_priv_t* priv,int volume){
-    struct video_audio audio;
-
-    /*arg must be between 0 and 100*/
-    if (volume > 100) volume = 100;
-    if (volume < 0) volume = 0;
-
-    memset(&audio,0,sizeof(audio));
-    audio.flags = (volume==0?VIDEO_AUDIO_MUTE:0);
-    if (ioctl(priv->radio_fd, VIDIOCSAUDIO, &audio)<0){
-        mp_tmsg(MSGT_RADIO,MSGL_WARN,"[radio] ioctl set mute failed: %s\n",strerror(errno));
-    }
-
-    memset(&audio,0,sizeof(audio));
-    audio.flags = VIDEO_AUDIO_VOLUME;
-    audio.mode = VIDEO_SOUND_STEREO;
-    audio.audio = 0;
-    audio.volume =  volume* (65535 / 100);
-
-    if (ioctl(priv->radio_fd, VIDIOCSAUDIO, &audio) < 0){
-        mp_tmsg(MSGT_RADIO,MSGL_ERR,"[radio] ioctl set volume failed: %s\n",strerror(errno));
-    }
-}
-
-/*****************************************************************
- * \brief get current volume from radio card
- * \param volume where to store volume level (0..100)
- * \return STREAM_OK if success, STREAM_ERROR otherwise
- */
-static int get_volume_v4l(radio_priv_t* priv,int* volume){
-    struct video_audio audio;
-
-    memset(&audio,0,sizeof(audio));
-    audio.audio=0;
-    if (ioctl(priv->radio_fd, VIDIOCGAUDIO, &audio) < 0){
-        mp_tmsg(MSGT_RADIO,MSGL_ERR,"[radio] ioctl get volume failed: %s\n",strerror(errno));
-        return STREAM_ERROR;
-    }
-
-    if (audio.flags & VIDEO_AUDIO_VOLUME){
-        *volume=100*audio.volume/65535;
-        /*arg must be between 0 and 100*/
-        if (*volume > 100) *volume = 100;
-        if (*volume < 0) *volume = 0;
-        return STREAM_OK;
-    }
-
-    return STREAM_ERROR;
-}
-
-/* v4l driver info structure */
-static const radio_driver_t radio_driver_v4l={
-    "v4l",
-    _("[radio] Using V4Lv1 radio interface.\n"),
-    init_frac_v4l,
-    set_volume_v4l,
-    get_volume_v4l,
-    set_frequency_v4l,
-    get_frequency_v4l
-};
-#endif /* CONFIG_RADIO_V4L */
 #ifdef CONFIG_RADIO_BSDBT848
 
 /*****************************************************************
@@ -1084,9 +949,6 @@ static const radio_driver_t* radio_drivers[]={
 #ifdef CONFIG_RADIO_V4L2
     &radio_driver_v4l2,
 #endif
-#ifdef CONFIG_RADIO_V4L
-    &radio_driver_v4l,
-#endif
     0
 };
 
diff --git a/stream/tv.c b/stream/tv.c
index 07fb027..3ce7264 100644
--- a/stream/tv.c
+++ b/stream/tv.c
@@ -58,7 +58,6 @@ char *tv_channel_last_real;
 /* enumerating drivers (like in stream.c) */
 extern const tvi_info_t tvi_info_dummy;
 extern const tvi_info_t tvi_info_dshow;
-extern const tvi_info_t tvi_info_v4l;
 extern const tvi_info_t tvi_info_v4l2;
 extern const tvi_info_t tvi_info_bsdbt848;
 
@@ -67,9 +66,6 @@ static const tvi_info_t* tvi_driver_list[]={
 #ifdef CONFIG_TV_V4L2
     &tvi_info_v4l2,
 #endif
-#ifdef CONFIG_TV_V4L1
-    &tvi_info_v4l,
-#endif
 #ifdef CONFIG_TV_BSDBT848
     &tvi_info_bsdbt848,
 #endif
@@ -478,26 +474,6 @@ static int open_tv(tvi_handle_t *tvh)
 #endif
     tv_set_norm(tvh,tvh->tv_param->norm);
 
-#ifdef CONFIG_TV_V4L1
-    if ( tvh->tv_param->mjpeg )
-    {
-      /* set width to expected value */
-      if (tvh->tv_param->width == -1)
-        {
-          tvh->tv_param->width = 704/tvh->tv_param->decimation;
-        }
-      if (tvh->tv_param->height == -1)
-        {
-	  if ( tvh->norm != TV_NORM_NTSC )
-            tvh->tv_param->height = 576/tvh->tv_param->decimation;
-	  else
-            tvh->tv_param->height = 480/tvh->tv_param->decimation;
-        }
-      mp_tmsg(MSGT_TV, MSGL_INFO,
-	       "  MJP: width %d height %d\n", tvh->tv_param->width, tvh->tv_param->height);
-    }
-#endif
-
     /* limits on w&h are norm-dependent -- JM */
     if (tvh->tv_param->width != -1 && tvh->tv_param->height != -1) {
         // first tell the driver both width and height, some drivers do not support setting them independently.
diff --git a/stream/tvi_v4l.c b/stream/tvi_v4l.c
deleted file mode 100644
index 31f7678..0000000
--- a/stream/tvi_v4l.c
+++ /dev/null
@@ -1,1910 +0,0 @@
-/*
- * Video 4 Linux input
- *
- * Copyright (C) 2001 Alex Beregszaszi
- *
- * Some ideas are based on xawtv/libng's grab-v4l.c written by
- *   Gerd Knorr <kraxel at bytesex.org>
- *
- * Multithreading, a/v sync and native ALSA support by
- *   Jindrich Makovicka <makovick at gmail.com>
- *
- * MJPEG hardware encoding support by
- *   Ivan Szanto <szivan at freemail.hu>
- *
- * CODE IS UNDER DEVELOPMENT, NO FEATURE REQUESTS PLEASE!
- *
- * 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 "config.h"
-
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/time.h>
-
-/* Necessary to prevent collisions between <linux/time.h> and <sys/time.h> when V4L2 is installed. */
-#define _LINUX_TIME_H
-
-#include <linux/videodev.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <stdlib.h>
-#include <string.h>
-#include <pthread.h>
-#ifdef HAVE_SYS_SYSINFO_H
-#include <sys/sysinfo.h>
-#endif
-
-#include "mp_msg.h"
-#include "libaf/af_format.h"
-#include "libmpcodecs/img_format.h"
-#include "libmpcodecs/dec_teletext.h"
-#include "libvo/fastmemcpy.h"
-#include "libvo/videodev_mjpeg.h"
-
-#include "tv.h"
-
-#include "audio_in.h"
-
-static tvi_handle_t *tvi_init_v4l(tv_param_t* tv_param);
-
-const tvi_info_t tvi_info_v4l = {
-    tvi_init_v4l,
-    "Video 4 Linux input",
-    "v4l",
-    "Alex Beregszaszi",
-    "under development"
-};
-
-#define PAL_WIDTH  768
-#define PAL_HEIGHT 576
-#define PAL_FPS    25
-
-#define NTSC_WIDTH  640
-#define NTSC_HEIGHT 480
-#define NTSC_FPS    (30000.0/1001.0)
-
-#define MAX_AUDIO_CHANNELS      10
-
-#define VID_BUF_SIZE_IMMEDIATE   2
-#define VIDEO_AVG_BUFFER_SIZE  600
-
-typedef struct priv {
-    /* general */
-    char                        *video_device;
-    int                         video_fd;
-    struct video_capability     capability;
-    struct video_channel        *channels;
-    int                         act_channel;
-    struct video_tuner          tuner;
-
-    /* video */
-    struct video_picture        picture;
-    int                         format;         /* output format */
-    int                         width;
-    int                         height;
-    int                         bytesperline;
-    float                       fps;
-
-    struct video_mbuf           mbuf;
-    unsigned char               *mmap;
-    struct video_mmap           *buf;
-    int                         nbuf;
-
-    /* audio */
-    char                        *audio_device;
-    audio_in_t                  audio_in;
-
-    int                         audio_id;
-    struct video_audio          audio[MAX_AUDIO_CHANNELS];
-    int                         audio_channels[MAX_AUDIO_CHANNELS];
-
-    /* buffering stuff */
-    int                         immediate_mode;
-
-    int                         audio_buffer_size;
-    int                         aud_skew_cnt;
-    unsigned char               *audio_ringbuffer;
-    long long                   *audio_skew_buffer;
-    volatile int                audio_head;
-    volatile int                audio_tail;
-    volatile int                audio_cnt;
-    volatile long long          audio_skew;
-    volatile double             audio_skew_factor;
-    volatile long long          audio_skew_measure_time;
-    volatile int                audio_drop;
-
-    int                         first;
-    int                         video_buffer_size_max;
-    volatile int                video_buffer_size_current;
-    unsigned char               **video_ringbuffer;
-    long long                   *video_timebuffer;
-    long long                   *video_avg_buffer;
-    int                         video_avg_ptr;
-    int                         video_interval_sum;
-    volatile int                video_head;
-    volatile int                video_tail;
-    volatile int                video_cnt;
-
-    volatile int                shutdown;
-
-    pthread_t                   audio_grabber_thread;
-    pthread_t                   video_grabber_thread;
-    pthread_mutex_t             audio_starter;
-    pthread_mutex_t             skew_mutex;
-    pthread_mutex_t             video_buffer_mutex;
-
-    long long                   starttime;
-    double                      audio_secs_per_block;
-    long long                   audio_skew_total;
-    long                        audio_recv_blocks_total;
-    long                        audio_sent_blocks_total;
-    long                        mjpeg_bufsize;
-    char                        *vbi_dev;
-    int                         vbi_fd;
-    int                         vbi_bufsize;
-    int                         vbi_shutdown;
-    pthread_t                   vbi_grabber_thread;
-    void                        *priv_vbi;
-
-    tv_param_t                  *tv_param;
-} priv_t;
-
-#include "tvi_def.h"
-
-static const char *device_cap2name[] = {
-    "capture", "tuner", "teletext", "overlay", "chromakey", "clipping",
-    "frameram", "scales", "monochrome", "subcapture", "mpeg-decoder",
-    "mpeg-encoder", "mjpeg-decoder", "mjpeg-encoder", NULL
-};
-
-static const char *device_palette2name[] = {
-    "-", "grey", "hi240", "rgb16", "rgb24", "rgb32", "rgb15", "yuv422",
-    "yuyv", "uyvy", "yuv420", "yuv411", "raw", "yuv422p", "yuv411p",
-    "yuv420p", "yuv410p"
-};
-#define PALETTE(x) ((x < sizeof(device_palette2name)/sizeof(char*)) ? device_palette2name[x] : "UNKNOWN")
-
-static const struct {
-    char* name;
-    int normid;
-    int tuner_flags;
-    int tuner_mode;
-    int input_norm;
-    float fps;
-} supported_norms[]={
-    {"pal",   TV_NORM_PAL,    VIDEO_TUNER_PAL,   VIDEO_MODE_PAL,  VIDEO_MODE_PAL,  PAL_FPS },
-    {"ntsc",  TV_NORM_NTSC,   VIDEO_TUNER_NTSC,  VIDEO_MODE_NTSC, VIDEO_MODE_NTSC, NTSC_FPS},
-    {"secam", TV_NORM_SECAM,  VIDEO_TUNER_SECAM, VIDEO_MODE_SECAM,VIDEO_MODE_SECAM,PAL_FPS },
-    {"palnc", TV_NORM_PALNC,  VIDEO_TUNER_PAL,   VIDEO_MODE_PAL,  3,               PAL_FPS },
-    {"palm",  TV_NORM_PALM,   VIDEO_TUNER_NTSC,  VIDEO_MODE_NTSC, 4,               NTSC_FPS},
-    {"paln",  TV_NORM_PALN,   VIDEO_TUNER_PAL,   VIDEO_MODE_PAL,  5,               PAL_FPS },
-    {"ntscjp",TV_NORM_NTSCJP, VIDEO_TUNER_NTSC,  VIDEO_MODE_NTSC, 6,               NTSC_FPS},
-    {"auto",  -1,             -1,                -1,              VIDEO_MODE_AUTO, -1      },
-    {NULL,    -1,             -1,                -1,              -1      }
-};
-
-static const char *norm2name(int mode)
-{
-    int i;
-    for(i=0;supported_norms[i].name; i++)
-        if(supported_norms[i].input_norm==mode)
-            return supported_norms[i].name;
-    return "unknown";
-};
-
-static const char *audio_mode2name(int mode)
-{
-    switch (mode) {
-    case VIDEO_SOUND_MONO:
-        return "mono";
-    case VIDEO_SOUND_STEREO:
-        return "stereo";
-    case VIDEO_SOUND_LANG1:
-        return "language1";
-    case VIDEO_SOUND_LANG2:
-        return "language2";
-    default:
-        return "unknown";
-    }
-};
-
-static void *audio_grabber(void *data);
-static void *video_grabber(void *data);
-
-static int palette2depth(int palette)
-{
-    switch(palette)
-    {
-        /* component */
-        case VIDEO_PALETTE_RGB555:
-            return 15;
-        case VIDEO_PALETTE_RGB565:
-            return 16;
-        case VIDEO_PALETTE_RGB24:
-            return 24;
-        case VIDEO_PALETTE_RGB32:
-            return 32;
-        /* planar */
-        case VIDEO_PALETTE_YUV411P:
-        case VIDEO_PALETTE_YUV420P:
-        case VIDEO_PALETTE_YUV410P:
-            return 12;
-        /* packed */
-        case VIDEO_PALETTE_YUV422P:
-        case VIDEO_PALETTE_YUV422:
-        case VIDEO_PALETTE_YUYV:
-        case VIDEO_PALETTE_UYVY:
-        case VIDEO_PALETTE_YUV420:
-        case VIDEO_PALETTE_YUV411:
-            return 16;
-    }
-    return -1;
-}
-
-static int format2palette(int format)
-{
-    switch(format)
-    {
-        case IMGFMT_BGR15:
-            return VIDEO_PALETTE_RGB555;
-        case IMGFMT_BGR16:
-            return VIDEO_PALETTE_RGB565;
-        case IMGFMT_BGR24:
-            return VIDEO_PALETTE_RGB24;
-        case IMGFMT_BGR32:
-            return VIDEO_PALETTE_RGB32;
-        case IMGFMT_YV12:
-        case IMGFMT_I420:
-            return VIDEO_PALETTE_YUV420P;
-        case IMGFMT_YUY2:
-            return VIDEO_PALETTE_YUV422;
-    case IMGFMT_UYVY:
-       return VIDEO_PALETTE_UYVY;
-    }
-    return -1;
-}
-
-// sets and sanitizes audio buffer/block sizes
-static void setup_audio_buffer_sizes(priv_t *priv)
-{
-    int bytes_per_sample = priv->audio_in.bytes_per_sample;
-
-    // make the audio buffer at least 5 seconds long
-    priv->audio_buffer_size = 1 + 5*priv->audio_in.samplerate
-        *priv->audio_in.channels
-        *bytes_per_sample/priv->audio_in.blocksize;
-    if (priv->audio_buffer_size < 256) priv->audio_buffer_size = 256;
-
-    // make the skew buffer at least 1 second long
-    priv->aud_skew_cnt = 1 + 1*priv->audio_in.samplerate
-        *priv->audio_in.channels
-        *bytes_per_sample/priv->audio_in.blocksize;
-    if (priv->aud_skew_cnt < 16) priv->aud_skew_cnt = 16;
-
-    mp_msg(MSGT_TV, MSGL_V, "Audio capture - buffer %d blocks of %d bytes, skew average from %d meas.\n",
-           priv->audio_buffer_size, priv->audio_in.blocksize, priv->aud_skew_cnt);
-}
-
-static tvi_handle_t *tvi_init_v4l(tv_param_t* tv_param)
-{
-    tvi_handle_t *h;
-    priv_t *priv;
-
-    h = tv_new_handle(sizeof(priv_t), &functions);
-    if (!h)
-        return NULL;
-
-    priv = h->priv;
-
-    /* set video device name */
-    if (!tv_param->device)
-        priv->video_device = strdup("/dev/video0");
-    else
-        priv->video_device = strdup(tv_param->device);
-
-    /* set video device name */
-    if (!tv_param->adevice)
-        priv->audio_device = NULL;
-    else {
-        priv->audio_device = strdup(tv_param->adevice);
-    }
-
-    /* allocation failed */
-    if (!priv->video_device) {
-        tv_free_handle(h);
-        return NULL;
-    }
-
-    priv->tv_param=tv_param;
-    return h;
-}
-
-/* retrieves info about audio channels from the BTTV */
-static void init_v4l_audio(priv_t *priv)
-{
-    int i;
-    int reqmode;
-
-    if (!priv->capability.audios) return;
-
-    /* audio chanlist */
-
-    mp_msg(MSGT_TV, MSGL_V, " Audio devices: %d\n", priv->capability.audios);
-
-    mp_msg(MSGT_TV, MSGL_V, "Video capture card reports the audio setup as follows:\n");
-    for (i = 0; i < priv->capability.audios; i++)
-    {
-        if (i >= MAX_AUDIO_CHANNELS)
-        {
-            mp_msg(MSGT_TV, MSGL_ERR, "no space for more audio channels (increase in source!) (%d > %d)\n",
-                   i, MAX_AUDIO_CHANNELS);
-            i = priv->capability.audios;
-            break;
-        }
-
-        priv->audio[i].audio = i;
-        if (ioctl(priv->video_fd, VIDIOCGAUDIO, &priv->audio[i]) == -1)
-        {
-            mp_msg(MSGT_TV, MSGL_ERR, "ioctl get audio failed: %s\n", strerror(errno));
-            break;
-        }
-
-        /* mute all channels */
-        priv->audio[i].flags |= VIDEO_AUDIO_MUTE;
-        reqmode = -1;
-        if (priv->tv_param->amode >= 0) {
-            switch (priv->tv_param->amode) {
-            case 0:
-                reqmode = VIDEO_SOUND_MONO;
-                break;
-            case 1:
-                reqmode = VIDEO_SOUND_STEREO;
-                break;
-            case 2:
-                reqmode = VIDEO_SOUND_LANG1;
-                break;
-            case 3:
-                reqmode = VIDEO_SOUND_LANG2;
-                break;
-            default:
-                mp_msg(MSGT_TV, MSGL_ERR, "Unknown audio mode requested.\n");
-                break;
-            }
-            if (reqmode >= 0) priv->audio[i].mode = reqmode;
-        }
-        ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[i]);
-
-        // get the parameters back
-        if (ioctl(priv->video_fd, VIDIOCGAUDIO, &priv->audio[i]) == -1)
-        {
-            mp_msg(MSGT_TV, MSGL_ERR, "ioctl get audio failed: %s\n", strerror(errno));
-            break;
-        }
-
-        switch(priv->audio[i].mode)
-        {
-        case VIDEO_SOUND_MONO:
-        case VIDEO_SOUND_LANG1:
-        case VIDEO_SOUND_LANG2:
-            priv->audio_channels[i] = 1;
-            break;
-        case VIDEO_SOUND_STEREO:
-            priv->audio_channels[i] = 2;
-            break;
-        default:
-            mp_msg(MSGT_TV, MSGL_ERR, "Card reports an unknown audio mode !\n");
-            mp_msg(MSGT_TV, MSGL_ERR, "Trying two channel audio. Use forcechan to override.\n");
-            priv->audio_channels[i] = 2;
-            break;
-        }
-
-        if (reqmode >= 0 && priv->audio[i].mode != reqmode) {
-            mp_msg(MSGT_TV, MSGL_ERR, "Audio mode setup warning!\n");
-            mp_msg(MSGT_TV, MSGL_ERR, "Requested mode was %s, but v4l still reports %s.\n",
-                   audio_mode2name(reqmode), audio_mode2name(priv->audio[i].mode));
-            mp_msg(MSGT_TV, MSGL_ERR, "You may need \"forcechan\" option to force stereo/mono audio recording.\n");
-        }
-
-        /* display stuff */
-        mp_msg(MSGT_TV, MSGL_V, "  %d: %s: ", priv->audio[i].audio,
-               priv->audio[i].name);
-        if (priv->audio[i].flags & VIDEO_AUDIO_MUTABLE) {
-            mp_msg(MSGT_TV, MSGL_V, "muted=%s ",
-                   (priv->audio[i].flags & VIDEO_AUDIO_MUTE) ? "yes" : "no");
-        }
-        mp_msg(MSGT_TV, MSGL_V, "vol=%d bass=%d treble=%d balance=%d mode=%s",
-               priv->audio[i].volume, priv->audio[i].bass, priv->audio[i].treble,
-               priv->audio[i].balance, audio_mode2name(priv->audio[i].mode));
-        mp_msg(MSGT_TV, MSGL_V, " chan=%d\n", priv->audio_channels[i]);
-
-        if (priv->tv_param->forcechan >= 0)
-            priv->audio_channels[i] = priv->tv_param->forcechan;
-
-        // we'll call VIDIOCSAUDIO again when starting capture
-        // let's set audio mode to requested mode again for the case
-        // when VIDIOCGAUDIO just cannot report the mode correctly
-        if (reqmode >= 0) priv->audio[i].mode = reqmode;
-    }
-}
-
-#if !defined(__LINUX_VIDEODEV2_H) && !defined(VIDIOC_QUERYCAP)
-struct v4l2_capability
-{
-        __u8    driver[16];     /* i.e. "bttv" */
-        __u8    card[32];       /* i.e. "Hauppauge WinTV" */
-        __u8    bus_info[32];   /* "PCI:" + pci_dev->slot_name */
-        __u32   version;        /* should use KERNEL_VERSION() */
-        __u32   capabilities;   /* Device capabilities */
-        __u32   reserved[4];
-};
-
-#define VIDIOC_QUERYCAP         _IOR  ('V',  0, struct v4l2_capability)
-#endif
-
-static int init(priv_t *priv)
-{
-    int i;
-
-    if (priv->tv_param->immediate == 1)
-        priv->tv_param->noaudio = 1;
-
-    priv->video_ringbuffer = NULL;
-    priv->video_timebuffer = NULL;
-    priv->video_avg_buffer = NULL;
-    priv->audio_ringbuffer = NULL;
-    priv->audio_skew_buffer = NULL;
-
-    priv->video_fd = open(priv->video_device, O_RDWR);
-    mp_msg(MSGT_TV, MSGL_DBG2, "Video fd: %d, %p\n", priv->video_fd,
-        priv->video_device);
-    if (priv->video_fd == -1)
-    {
-        mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n",
-            priv->video_device, strerror(errno));
-        goto err;
-    }
-
-    /* check for v4l2 */
-    if (ioctl(priv->video_fd, VIDIOC_QUERYCAP, &priv->capability) == 0) {
-        mp_msg(MSGT_TV, MSGL_ERR, "=================================================================\n");
-        mp_msg(MSGT_TV, MSGL_ERR, " WARNING: YOU ARE USING V4L DEMUXER WITH V4L2 DRIVERS!!!\n");
-        mp_msg(MSGT_TV, MSGL_ERR, " As the V4L1 compatibility layer is broken, this may not work.\n");
-        mp_msg(MSGT_TV, MSGL_ERR, " If you encounter any problems, use driver=v4l2 instead.\n");
-        mp_msg(MSGT_TV, MSGL_ERR, " Bugreports on driver=v4l with v4l2 drivers will be ignored.\n");
-        mp_msg(MSGT_TV, MSGL_ERR, "=================================================================\n");
-    }
-
-    /* get capabilities (priv->capability is needed!) */
-    if (ioctl(priv->video_fd, VIDIOCGCAP, &priv->capability) == -1)
-    {
-        mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilities failed: %s\n", strerror(errno));
-        goto err;
-    }
-
-    fcntl(priv->video_fd, F_SETFD, FD_CLOEXEC);
-
-    mp_msg(MSGT_TV, MSGL_INFO, "Selected device: %s\n", priv->capability.name);
-    mp_msg(MSGT_TV, MSGL_INFO, " Capabilities: ");
-    for (i = 0; device_cap2name[i] != NULL; i++)
-        if (priv->capability.type & (1 << i))
-            mp_msg(MSGT_TV, MSGL_INFO, "%s ", device_cap2name[i]);
-    mp_msg(MSGT_TV, MSGL_INFO, "\n");
-    mp_msg(MSGT_TV, MSGL_INFO, " Device type: %d\n", priv->capability.type);
-    mp_msg(MSGT_TV, MSGL_INFO, " Supported sizes: %dx%d => %dx%d\n",
-        priv->capability.minwidth, priv->capability.minheight,
-        priv->capability.maxwidth, priv->capability.maxheight);
-    priv->width = priv->capability.minwidth;
-    priv->height = priv->capability.minheight;
-
-    /* somewhere here could disable priv->tv_param->mjpeg, if it is not a capability */
-
-    /* initialize if necessary */
-    if ( priv->tv_param->mjpeg )
-    {
-        struct mjpeg_params bparm;
-        struct mjpeg_requestbuffers breq;          /* buffer requests */
-
-        if (ioctl(priv->video_fd, MJPIOC_G_PARAMS, &bparm) < 0)
-        {
-            mp_msg(MSGT_TV, MSGL_ERR,
-                   "  MJP: Error getting video parameters: %s\n", strerror(errno));
-            goto err;
-        }
-
-        mp_msg(MSGT_TV, MSGL_INFO,
-               "  MJP: previous params: x: %d, y: %d, w: %d, h: %d, decim: %d, fields: %d,\n",
-               bparm.img_x, bparm.img_y, bparm.img_width, bparm.img_height,
-               bparm.decimation, bparm.field_per_buff);
-
-        mp_msg(MSGT_TV, MSGL_INFO,
-               "  MJP: HorDcm: %d, VerDcm: %d, TmpDcm: %d\n",
-               bparm.HorDcm, bparm.VerDcm, bparm.TmpDcm);
-
-        bparm.input = priv->tv_param->input; /* tv */
-        if (!strcasecmp(priv->tv_param->norm, "pal"))
-            bparm.norm =  0; /* PAL */
-        else if (!strcasecmp(priv->tv_param->norm, "ntsc"))
-            bparm.norm =  1; /* NTSC */
-        else if (!strcasecmp(priv->tv_param->norm, "secam"))
-            bparm.norm =  2; /* SECAM */
-        bparm.quality = priv->tv_param->quality;
-        bparm.decimation = priv->tv_param->decimation;
-
-        mp_msg(MSGT_TV, MSGL_INFO, "  MJP: setting params to decimation: %d, quality: %d\n",
-               bparm.decimation, bparm.quality);
-
-        if (ioctl(priv->video_fd, MJPIOC_S_PARAMS, &bparm) < 0)
-        {
-            mp_msg(MSGT_TV, MSGL_ERR,
-                   "  MJP: Error setting video parameters: %s\n", strerror(errno));
-            goto err;
-        }
-
-        if (ioctl(priv->video_fd, MJPIOC_G_PARAMS, &bparm) < 0)
-        {
-            mp_msg(MSGT_TV, MSGL_ERR,
-                   "  MJP: Error getting video parameters: %s\n", strerror(errno));
-            goto err;
-        }
-
-        mp_msg(MSGT_TV, MSGL_INFO,
-               "  MJP: current params: x: %d, y: %d, w: %d, h: %d, decim: %d, fields: %d,\n",
-               bparm.img_x, bparm.img_y, bparm.img_width, bparm.img_height,
-               bparm.decimation, bparm.field_per_buff);
-
-        mp_msg(MSGT_TV, MSGL_INFO,
-               "  MJP: HorDcm: %d, VerDcm: %d, TmpDcm: %d\n",
-               bparm.HorDcm, bparm.VerDcm, bparm.TmpDcm);
-
-
-        breq.count = 64;
-        priv -> nbuf = breq.count;
-        priv->mbuf.frames = priv -> nbuf;
-        priv->mjpeg_bufsize = 256*1024;
-        if (priv->tv_param->buffer_size >= 0)
-            priv->mjpeg_bufsize = priv->tv_param->buffer_size*1024;
-        breq.size  = priv -> mjpeg_bufsize;
-        if (ioctl(priv->video_fd, MJPIOC_REQBUFS,&(breq)) < 0)
-        {
-           mp_msg (MSGT_TV, MSGL_ERR,
-              "  MJP: Error requesting video buffers: %s\n", strerror(errno));
-           goto err;
-        }
-        mp_msg(MSGT_TV, MSGL_INFO,
-               "  MJP: Got %ld buffers of size %ld KB\n",
-               breq.count, breq.size/1024);
-
-        priv -> mmap = mmap(0, breq.count * breq.size,
-            PROT_READ|PROT_WRITE, MAP_SHARED, priv->video_fd, 0);
-        if (priv -> mmap == MAP_FAILED)
-        {
-            mp_msg(MSGT_TV, MSGL_INFO,
-                   "  MJP: Error mapping video buffers: %s\n", strerror(errno));
-            goto err;
-        }
-    }
-
-    mp_msg(MSGT_TV, MSGL_INFO, " Inputs: %d\n", priv->capability.channels);
-    priv->channels = calloc(priv->capability.channels, sizeof(struct video_channel));
-    if (!priv->channels)
-        goto malloc_failed;
-    memset(priv->channels, 0, sizeof(struct video_channel)*priv->capability.channels);
-    for (i = 0; i < priv->capability.channels; i++)
-    {
-        priv->channels[i].channel = i;
-        if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1)
-        {
-            mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno));
-            break;
-        }
-        mp_msg(MSGT_TV, MSGL_INFO, "  %d: %s: %s%s%s%s (tuner:%d, norm:%s)\n", i,
-            priv->channels[i].name,
-            (priv->channels[i].flags & VIDEO_VC_TUNER) ? "tuner " : "",
-            (priv->channels[i].flags & VIDEO_VC_AUDIO) ? "audio " : "",
-            (priv->channels[i].flags & VIDEO_TYPE_TV) ? "tv " : "",
-            (priv->channels[i].flags & VIDEO_TYPE_CAMERA) ? "camera " : "",
-            priv->channels[i].tuners,
-            norm2name(priv->channels[i].norm));
-    }
-    priv->act_channel = 0;
-
-    if (!(priv->capability.type & VID_TYPE_CAPTURE))
-    {
-        mp_msg(MSGT_TV, MSGL_ERR, "Only grabbing supported (for overlay use another program)\n");
-        goto err;
-    }
-
-
-    /* init v4l audio even when we don't capture */
-    init_v4l_audio(priv);
-
-    if (!priv->capability.audios && !priv->tv_param->force_audio) priv->tv_param->noaudio = 1;
-
-    /* audio init */
-    if (!priv->tv_param->noaudio) {
-
-#ifdef CONFIG_ALSA
-        if (priv->tv_param->alsa)
-            audio_in_init(&priv->audio_in, AUDIO_IN_ALSA);
-        else
-            audio_in_init(&priv->audio_in, AUDIO_IN_OSS);
-#else
-        audio_in_init(&priv->audio_in, AUDIO_IN_OSS);
-#endif
-
-        if (priv->audio_device) {
-            audio_in_set_device(&priv->audio_in, priv->audio_device);
-        }
-
-        if (priv->tv_param->audio_id < priv->capability.audios)
-            priv->audio_id = priv->tv_param->audio_id;
-        else
-            priv->audio_id = 0;
-        audio_in_set_samplerate(&priv->audio_in, 44100);
-        if (priv->capability.audios) {
-            audio_in_set_channels(&priv->audio_in, priv->audio_channels[priv->audio_id]);
-        } else {
-            if (priv->tv_param->forcechan >= 0) {
-                audio_in_set_channels(&priv->audio_in, priv->tv_param->forcechan);
-            } else {
-                audio_in_set_channels(&priv->audio_in, 2);
-            }
-        }
-        if (audio_in_setup(&priv->audio_in) < 0) return 0;
-        setup_audio_buffer_sizes(priv);
-    }
-
-    return 1;
-
-malloc_failed:
-    free(priv->channels);
-    free(priv->buf);
-err:
-    if (priv->video_fd != -1)
-        close(priv->video_fd);
-    return 0;
-}
-
-static int uninit(priv_t *priv)
-{
-    unsigned long num;
-
-    priv->vbi_shutdown=1;
-    if(priv->vbi_grabber_thread)
-        pthread_join(priv->vbi_grabber_thread, NULL);
-
-    teletext_control(priv->priv_vbi,TV_VBI_CONTROL_STOP,(void*)1);
-    priv->priv_vbi=NULL;
-
-    if(priv->vbi_fd){
-        close(priv->vbi_fd);
-        priv->vbi_fd=0;
-    }
-
-    free(priv->vbi_dev);
-    priv->vbi_dev = NULL;
-
-    priv->shutdown = 1;
-
-    mp_msg(MSGT_TV, MSGL_V, "Waiting for threads to finish... ");
-    if (!priv->tv_param->noaudio) {
-        pthread_join(priv->audio_grabber_thread, NULL);
-        pthread_mutex_destroy(&priv->audio_starter);
-        pthread_mutex_destroy(&priv->skew_mutex);
-    }
-    pthread_mutex_destroy(&priv->video_buffer_mutex);
-    if(priv->video_grabber_thread)
-        pthread_join(priv->video_grabber_thread, NULL);
-
-    mp_msg(MSGT_TV, MSGL_V, "done\n");
-
-    if (priv->capability.audios) {
-        priv->audio[priv->audio_id].flags |= VIDEO_AUDIO_MUTE;
-        ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]);
-    }
-
-    if ( priv->tv_param->mjpeg )
-    {
-        num = -1;
-        if (ioctl(priv->video_fd, MJPIOC_QBUF_CAPT, &num) < 0)
-            mp_msg(MSGT_TV, MSGL_ERR, "\n  MJP: ioctl MJPIOC_QBUF_CAPT failed: %s\n", strerror(errno));
-    }
-    else
-    {
-        // We need to munmap as close don't close mem mappings
-        if(munmap(priv->mmap,priv->mbuf.size))
-            mp_msg(MSGT_TV, MSGL_ERR, "Munmap failed: %s\n",strerror(errno));
-    }
-
-    if(close(priv->video_fd))
-        mp_msg(MSGT_TV, MSGL_ERR, "Close tv failed: %s\n",strerror(errno));
-
-    audio_in_uninit(&priv->audio_in);
-
-    if (priv->video_ringbuffer) {
-        int i;
-        for (i = 0; i < priv->video_buffer_size_current; i++) {
-            free(priv->video_ringbuffer[i]);
-        }
-        free(priv->video_ringbuffer);
-    }
-
-    free(priv->video_timebuffer);
-    free(priv->video_avg_buffer);
-    if (!priv->tv_param->noaudio) {
-        free(priv->audio_ringbuffer);
-        free(priv->audio_skew_buffer);
-    }
-
-    return 1;
-}
-
-static int get_capture_buffer_size(priv_t *priv)
-{
-    uint64_t bufsize;
-    int cnt;
-
-    if (priv->tv_param->buffer_size >= 0) {
-        bufsize = priv->tv_param->buffer_size*1024*1024;
-    } else {
-#ifdef HAVE_SYS_SYSINFO_H
-        struct sysinfo si;
-
-        sysinfo(&si);
-        bufsize = (si.freeram/2)*si.mem_unit;
-        if (bufsize < 16*1024*1024)
-#endif
-        bufsize = 16*1024*1024;
-    }
-
-    cnt = bufsize/(priv->height*priv->bytesperline);
-    if (cnt < 2) cnt = 2;
-
-    return cnt;
-}
-
-static int vbi_init(priv_t* priv,char* device)
-{
-    int vbi_fd=0;
-    struct video_capability cap;
-
-    if(!device)
-        return TVI_CONTROL_FALSE;
-
-    priv->vbi_dev=strdup(device);
-
-    vbi_fd=open(priv->vbi_dev,O_RDWR);
-    if(vbi_fd<0){
-        mp_msg(MSGT_TV,MSGL_ERR,"vbi: could not open device %s\n",priv->vbi_dev);
-        return  TVI_CONTROL_FALSE;
-    }
-
-    if(ioctl(vbi_fd,VIDIOCGCAP,&cap)<0){
-        mp_msg(MSGT_TV,MSGL_ERR,"vbi: Query capabilities failed for %s\n",priv->vbi_dev);
-        close(vbi_fd);
-        return  TVI_CONTROL_FALSE;
-    }
-    if(!cap.type & VID_TYPE_CAPTURE){
-        mp_msg(MSGT_TV,MSGL_ERR,"vbi: %s is not capture device\n",priv->vbi_dev);
-        close(vbi_fd);
-        return  TVI_CONTROL_FALSE;
-    }
-
-    priv->vbi_fd=vbi_fd;
-    mp_msg(MSGT_TV,MSGL_DBG3,"vbi: init ok\n");
-    return TVI_CONTROL_TRUE;
-}
-
-static int vbi_get_props(priv_t* priv,tt_stream_props* ptsp)
-{
-    struct vbi_format fmt;
-    int res;
-    if(!priv || !ptsp)
-        return TVI_CONTROL_FALSE;
-
-    memset(&fmt,0,sizeof(struct vbi_format));
-    if((res=ioctl(priv->vbi_fd,VIDIOCGVBIFMT,&fmt))<0){
-        mp_msg(MSGT_TV,MSGL_ERR,"vbi_get_props: Query format failed: %x\n",res);
-        return  TVI_CONTROL_FALSE;
-    }
-
-    ptsp->interlaced=(fmt.flags& VBI_INTERLACED?1:0);
-    if(fmt.start[1]>0 && fmt.count[1]){
-        if(fmt.start[1]>=286)
-            //625
-            ptsp->offset=10.2e-6*fmt.sampling_rate;
-        else
-            //525
-            ptsp->offset=9.2e-6*fmt.sampling_rate;
-    }else
-        ptsp->offset=9.7e-6*fmt.sampling_rate;
-
-    ptsp->sampling_rate=fmt.sampling_rate;
-    ptsp->samples_per_line=fmt.samples_per_line,
-
-    ptsp->count[0]=fmt.count[0];
-    ptsp->count[1]=fmt.count[1];
-    ptsp->bufsize = ptsp->samples_per_line * (ptsp->count[0] + ptsp->count[1]);
-
-    mp_msg(MSGT_TV,MSGL_V,"vbi_get_props: sampling_rate=%d,offset:%d,samples_per_line: %d\n interlaced:%s, count=[%d,%d]\n",
-        ptsp->sampling_rate,
-        ptsp->offset,
-        ptsp->samples_per_line,
-        ptsp->interlaced?"Yes":"No",
-        ptsp->count[0],
-        ptsp->count[1]);
-
-    return TVI_CONTROL_TRUE;
-}
-
-static void *vbi_grabber(void *data)
-{
-    priv_t *priv = (priv_t *) data;
-    int bytes,seq,prev_seq;
-    unsigned char* buf;
-    tt_stream_props tsp;
-
-    if(!priv->priv_vbi){
-        mp_msg(MSGT_TV,MSGL_WARN,"vbi: vbi not initialized. stopping thread.\n");
-        return NULL;
-    }
-
-    if(vbi_get_props(priv,&tsp)!=TVI_CONTROL_TRUE)
-        return NULL;
-
-    buf=malloc(tsp.bufsize);
-    seq=0;
-    prev_seq=0;
-    mp_msg(MSGT_TV,MSGL_V,"vbi: vbi capture thread started.\n");
-
-    while (!priv->vbi_shutdown){
-        bytes=read(priv->vbi_fd,buf,tsp.bufsize);
-        if(bytes<0 && errno==EINTR)
-            continue;
-        if (bytes!=tsp.bufsize){
-            mp_msg(MSGT_TV,MSGL_WARN,"vbi: expecting bytes: %d, got: %d",tsp.bufsize,bytes);
-            break;
-        }
-        seq=*(int*)(buf+bytes-4);
-        if(seq<=1) continue;
-        if (prev_seq && seq!=prev_seq+1){
-            prev_seq=0;
-            seq=0;
-        }
-        prev_seq=seq;
-        teletext_control(priv->priv_vbi,TV_VBI_CONTROL_DECODE_PAGE,&buf);
-        mp_msg(MSGT_TV,MSGL_DBG3,"grabber: seq:%d\n",seq);
-    }
-    free(buf);
-    return NULL;
-}
-
-static int start(priv_t *priv)
-{
-    int i;
-    int bytes_per_sample;
-    struct video_window win;
-
-    if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1)
-    {
-        mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno));
-        return 0;
-    }
-
-    priv->picture.palette = format2palette(priv->format);
-    priv->picture.depth = palette2depth(priv->picture.palette);
-
-    if (priv->format != IMGFMT_BGR15) {
-        priv->bytesperline = priv->width * priv->picture.depth / 8;
-    } else {
-        priv->bytesperline = priv->width * 2;
-    }
-
-    mp_msg(MSGT_TV, MSGL_V, "Picture values:\n");
-    mp_msg(MSGT_TV, MSGL_V, " Depth: %d, Palette: %s (Format: %s)\n", priv->picture.depth,
-        PALETTE(priv->picture.palette), vo_format_name(priv->format));
-    mp_msg(MSGT_TV, MSGL_V, " Brightness: %d, Hue: %d, Colour: %d, Contrast: %d\n",
-        priv->picture.brightness, priv->picture.hue,
-        priv->picture.colour, priv->picture.contrast);
-
-    if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1)
-    {
-        mp_msg(MSGT_TV, MSGL_ERR, "ioctl set picture failed: %s\n", strerror(errno));
-        mp_msg(MSGT_TV, MSGL_ERR, "The 'outfmt' of '%s' is likely not supported by your card\n",
-               vo_format_name(priv->format));
-        return 0;
-    }
-
-    /* Set capture size */
-    win.x = 0;
-    win.y = 0;
-    win.width = priv->width;
-    win.height = priv->height;
-    win.chromakey = -1;
-    win.flags = 0;
-    win.clipcount = 0;
-    if (ioctl(priv->video_fd, VIDIOCSWIN, &win) == -1)
-        mp_msg(MSGT_TV, MSGL_ERR, "ioctl set window failed: %s\n", strerror(errno));
-
-    if ( !priv->tv_param->mjpeg )
-    {
-        /* map grab buffer */
-        if (ioctl(priv->video_fd, VIDIOCGMBUF, &priv->mbuf) == -1)
-        {
-            mp_msg(MSGT_TV, MSGL_ERR, "ioctl get mbuf failed: %s\n", strerror(errno));
-            return 0;
-        }
-
-        mp_msg(MSGT_TV, MSGL_V, "mbuf: size=%d, frames=%d\n",
-            priv->mbuf.size, priv->mbuf.frames);
-        priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE,
-                          MAP_SHARED, priv->video_fd, 0);
-        if (priv->mmap == (unsigned char *)-1)
-        {
-            mp_msg(MSGT_TV, MSGL_ERR, "Unable to map memory for buffers: %s\n", strerror(errno));
-            return 0;
-        }
-        mp_msg(MSGT_TV, MSGL_DBG2, "our buffer: %p\n", priv->mmap);
-
-        /* num of buffers */
-        priv->nbuf = priv->mbuf.frames;
-
-        /* video buffers */
-        priv->buf = calloc(priv->nbuf, sizeof(struct video_mmap));
-        if (!priv->buf)
-            return 0;
-        memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap));
-    }
-
-    if ( !priv->tv_param->mjpeg )
-    {
-        priv->nbuf = priv->mbuf.frames;
-        for (i=0; i < priv->nbuf; i++)
-        {
-            priv->buf[i].format = priv->picture.palette;
-            priv->buf[i].frame = i;
-            priv->buf[i].width = priv->width;
-            priv->buf[i].height = priv->height;
-            mp_msg(MSGT_TV, MSGL_DBG2, "buffer: %d => %p\n", i, &priv->buf[i]);
-        }
-    }
-
-#if 0
-    {
-        struct video_play_mode pmode;
-
-        pmode.mode = VID_PLAY_NORMAL;
-        pmode.p1 = 1;
-        pmode.p2 = 0;
-        if (ioctl(priv->video_fd, VIDIOCSPLAYMODE, &pmode) == -1)
-        {
-            mp_msg(MSGT_TV, MSGL_ERR, "ioctl set play mode failed: %s\n", strerror(errno));
-//          return 0;
-        }
-    }
-#endif
-
-#if 0
-    // initialize video capture
-    if (ioctl(priv->video_fd, VIDIOCCAPTURE, &one) == -1)
-    {
-        mp_msg(MSGT_TV, MSGL_ERR, "FATAL: ioctl ccapture failed: %s\n", strerror(errno));
-        return 0;
-    }
-#endif
-
-    /* setup audio parameters */
-    if (!priv->tv_param->noaudio) {
-        setup_audio_buffer_sizes(priv);
-        bytes_per_sample = priv->audio_in.bytes_per_sample;
-        priv->audio_skew_buffer = calloc(priv->aud_skew_cnt, sizeof(long long));
-        if (!priv->audio_skew_buffer) {
-            mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate skew buffer: %s\n", strerror(errno));
-            return 0;
-        }
-
-        priv->audio_ringbuffer = calloc(priv->audio_in.blocksize, priv->audio_buffer_size);
-        if (!priv->audio_ringbuffer) {
-            mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate audio buffer: %s\n", strerror(errno));
-            return 0;
-        }
-
-        priv->audio_secs_per_block = (double)priv->audio_in.blocksize/(priv->audio_in.samplerate
-                                                                    *priv->audio_in.channels
-                                                                    *bytes_per_sample);
-        priv->audio_head = 0;
-        priv->audio_tail = 0;
-        priv->audio_cnt = 0;
-        priv->audio_drop = 0;
-        priv->audio_skew = 0;
-        priv->audio_skew_total = 0;
-        priv->audio_recv_blocks_total = 0;
-        priv->audio_sent_blocks_total = 0;
-    }
-
-    /* setup video parameters */
-    if (priv->immediate_mode) {
-        priv->video_buffer_size_max = VID_BUF_SIZE_IMMEDIATE;
-    } else {
-        priv->video_buffer_size_max = get_capture_buffer_size(priv);
-    }
-    priv->video_buffer_size_current = 0;
-
-    if (!priv->tv_param->noaudio) {
-        if (priv->video_buffer_size_max < 3.0*priv->fps*priv->audio_secs_per_block) {
-            mp_msg(MSGT_TV, MSGL_ERR, "Video buffer shorter than 3 times audio frame duration.\n"
-                   "You will probably experience heavy framedrops.\n");
-        }
-    }
-
-    mp_msg(MSGT_TV, MSGL_V, "Using a ring buffer for maximum %d frames, %d MB total size.\n",
-           priv->video_buffer_size_max,
-           priv->video_buffer_size_max*priv->height*priv->bytesperline/(1024*1024));
-
-    priv->video_ringbuffer = calloc(priv->video_buffer_size_max, sizeof(unsigned char*));
-    if (!priv->video_ringbuffer) {
-        mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate video buffer: %s\n", strerror(errno));
-        return 0;
-    }
-    for (i = 0; i < priv->video_buffer_size_max; i++)
-        priv->video_ringbuffer[i] = NULL;
-
-    priv->video_timebuffer = calloc(priv->video_buffer_size_max, sizeof(long long));
-    if (!priv->video_timebuffer) {
-        mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate time buffer: %s\n", strerror(errno));
-        return 0;
-    }
-    priv->video_avg_buffer = malloc(sizeof(long long) * VIDEO_AVG_BUFFER_SIZE);
-    if (!priv->video_avg_buffer) {
-        mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate period buffer: %s\n", strerror(errno));
-        return 0;
-    }
-    priv->video_interval_sum = (1e6/priv->fps)*VIDEO_AVG_BUFFER_SIZE;
-    for (i = 0; i < VIDEO_AVG_BUFFER_SIZE; i++) {
-        priv->video_avg_buffer[i] = 1e6/priv->fps;
-    }
-
-    priv->video_avg_ptr = 0;
-
-    priv->video_head = 0;
-    priv->video_tail = 0;
-    priv->video_cnt = 0;
-    priv->first = 1;
-
-    if (priv->capability.audios) {
-        /* enable audio */
-        if (priv->tv_param->volume >= 0)
-            priv->audio[priv->audio_id].volume = priv->tv_param->volume;
-        if (priv->tv_param->bass >= 0)
-            priv->audio[priv->audio_id].bass = priv->tv_param->bass;
-        if (priv->tv_param->treble >= 0)
-            priv->audio[priv->audio_id].treble = priv->tv_param->treble;
-        if (priv->tv_param->balance >= 0)
-            priv->audio[priv->audio_id].balance = priv->tv_param->balance;
-        priv->audio[priv->audio_id].flags &= ~VIDEO_AUDIO_MUTE;
-        mp_msg(MSGT_TV, MSGL_V, "Enabling tv audio. Requested setup is:\n");
-        mp_msg(MSGT_TV, MSGL_V, "id=%d vol=%d bass=%d treble=%d balance=%d mode=%s",
-               priv->audio_id,
-               priv->audio[priv->audio_id].volume, priv->audio[priv->audio_id].bass, priv->audio[priv->audio_id].treble,
-               priv->audio[priv->audio_id].balance, audio_mode2name(priv->audio[priv->audio_id].mode));
-        mp_msg(MSGT_TV, MSGL_V, " chan=%d\n", priv->audio_channels[priv->audio_id]);
-        ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]);
-    }
-
-    /* start vbi thread */
-    if(priv->priv_vbi){
-        priv->vbi_shutdown = 0;
-        pthread_create(&priv->vbi_grabber_thread, NULL, vbi_grabber, priv);
-    }
-
-    /* launch capture threads */
-    priv->shutdown = 0;
-    if (!priv->tv_param->noaudio) {
-        pthread_mutex_init(&priv->audio_starter, NULL);
-        pthread_mutex_init(&priv->skew_mutex, NULL);
-        pthread_mutex_lock(&priv->audio_starter);
-        pthread_create(&priv->audio_grabber_thread, NULL, audio_grabber, priv);
-    }
-    pthread_mutex_init(&priv->video_buffer_mutex, NULL);
-    /* we'll launch the video capture later, when a first request for a frame arrives */
-
-    return 1;
-}
-
-
-static int control(priv_t *priv, int cmd, void *arg)
-{
-    mp_msg(MSGT_TV, MSGL_DBG2, "\ndebug: control(priv=%p, cmd=%d, arg=%p)\n",
-        priv, cmd, arg);
-    switch(cmd)
-    {
-        /* ========== GENERIC controls =========== */
-        case TVI_CONTROL_IS_VIDEO:
-        {
-            if (priv->capability.type & VID_TYPE_CAPTURE)
-                return TVI_CONTROL_TRUE;
-            return TVI_CONTROL_FALSE;
-        }
-        case TVI_CONTROL_IS_AUDIO:
-            if (priv->tv_param->force_audio) return TVI_CONTROL_TRUE;
-            if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO)
-            {
-                return TVI_CONTROL_TRUE;
-            }
-            return TVI_CONTROL_FALSE;
-        case TVI_CONTROL_IS_TUNER:
-        {
-//          if (priv->capability.type & VID_TYPE_TUNER)
-            if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER)
-                return TVI_CONTROL_TRUE;
-            return TVI_CONTROL_FALSE;
-        }
-
-        /* ========== VIDEO controls =========== */
-        case TVI_CONTROL_VID_GET_FORMAT:
-        {
-            int output_fmt = -1;
-
-            output_fmt = priv->format;
-            if ( priv->tv_param->mjpeg )
-            {
-                mp_msg(MSGT_TV, MSGL_INFO, "  MJP: setting sh_video->format to mjpg\n");
-                output_fmt = 0x47504a4d;
-                output_fmt = 0x67706a6d;
-                *(int *)arg = output_fmt;
-                mp_msg(MSGT_TV, MSGL_V, "Output format: %s\n", "mjpg");
-            }
-            else
-            {
-                *(int *)arg = output_fmt;
-                mp_msg(MSGT_TV, MSGL_V, "Output format: %s\n", vo_format_name(output_fmt));
-            }
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_VID_SET_FORMAT:
-            priv->format = *(int *)arg;
-            // !HACK! v4l uses BGR format instead of RGB
-            // and we have to correct this. Fortunately,
-            // tv.c reads later the format back so we
-            // can persuade it to use what we want.
-            if (IMGFMT_IS_RGB(priv->format)) {
-                priv->format &= ~IMGFMT_RGB_MASK;
-                priv->format |= IMGFMT_BGR;
-            }
-            return TVI_CONTROL_TRUE;
-        case TVI_CONTROL_VID_GET_PLANES:
-            *(int *)arg = 1; /* FIXME, also not needed at this time */
-            return TVI_CONTROL_TRUE;
-        case TVI_CONTROL_VID_GET_BITS:
-            *(int *)arg = palette2depth(format2palette(priv->format));
-            return TVI_CONTROL_TRUE;
-        case TVI_CONTROL_VID_GET_WIDTH:
-            *(int *)arg = priv->width;
-            return TVI_CONTROL_TRUE;
-        case TVI_CONTROL_VID_CHK_WIDTH:
-        {
-            int req_width = *(int *)arg;
-
-            mp_msg(MSGT_TV, MSGL_V, "Requested width: %d\n", req_width);
-            if ((req_width >= priv->capability.minwidth) &&
-                (req_width <= priv->capability.maxwidth))
-                return TVI_CONTROL_TRUE;
-            return TVI_CONTROL_FALSE;
-        }
-        case TVI_CONTROL_VID_SET_WIDTH:
-            priv->width = *(int *)arg;
-            return TVI_CONTROL_TRUE;
-        case TVI_CONTROL_VID_GET_HEIGHT:
-            *(int *)arg = priv->height;
-            return TVI_CONTROL_TRUE;
-        case TVI_CONTROL_VID_CHK_HEIGHT:
-        {
-            int req_height = *(int *)arg;
-
-            mp_msg(MSGT_TV, MSGL_V, "Requested height: %d\n", req_height);
-            if ((req_height >= priv->capability.minheight) &&
-                (req_height <= priv->capability.maxheight))
-                return TVI_CONTROL_TRUE;
-            return TVI_CONTROL_FALSE;
-        }
-        case TVI_CONTROL_VID_SET_HEIGHT:
-            priv->height = *(int *)arg;
-            return TVI_CONTROL_TRUE;
-        case TVI_CONTROL_VID_GET_PICTURE:
-            if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1)
-            {
-                mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno));
-                return TVI_CONTROL_FALSE;
-            }
-            return TVI_CONTROL_TRUE;
-        case TVI_CONTROL_VID_SET_PICTURE:
-            if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1)
-            {
-                mp_msg(MSGT_TV, MSGL_ERR, "ioctl set picture failed: %s\n", strerror(errno));
-                return TVI_CONTROL_FALSE;
-            }
-            return TVI_CONTROL_TRUE;
-        case TVI_CONTROL_VID_SET_BRIGHTNESS:
-            priv->picture.brightness = (327*(*(int *)arg+100)) + 68;
-            return control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
-        case TVI_CONTROL_VID_SET_HUE:
-            priv->picture.hue = (327*(*(int *)arg+100)) + 68;
-            return control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
-        case TVI_CONTROL_VID_SET_SATURATION:
-            priv->picture.colour = (327*(*(int *)arg+100)) + 68;
-            return control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
-        case TVI_CONTROL_VID_SET_CONTRAST:
-            priv->picture.contrast = (327*(*(int *)arg+100)) + 68;
-            return control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
-        case TVI_CONTROL_VID_GET_BRIGHTNESS:
-            if(!control(priv, TVI_CONTROL_VID_GET_PICTURE, 0)) return 0;
-            *(int*)arg = ((int)priv->picture.brightness-68)/327-100;
-            return 1;
-        case TVI_CONTROL_VID_GET_HUE:
-            if(!control(priv, TVI_CONTROL_VID_GET_PICTURE, 0)) return 0;
-            *(int*)arg = ((int)priv->picture.hue-68)/327-100;
-            return 1;
-        case TVI_CONTROL_VID_GET_SATURATION:
-            if(!control(priv, TVI_CONTROL_VID_GET_PICTURE, 0)) return 0;
-            *(int*)arg = ((int)priv->picture.colour-68)/327-100;
-            return 1;
-        case TVI_CONTROL_VID_GET_CONTRAST:
-            if(!control(priv, TVI_CONTROL_VID_GET_PICTURE, 0)) return 0;
-            *(int*)arg = ((int)priv->picture.contrast-68)/327-100;
-            return 1;
-        case TVI_CONTROL_VID_GET_FPS:
-            *(float *)arg=priv->fps;
-            return TVI_CONTROL_TRUE;
-
-        /* ========== TUNER controls =========== */
-        case TVI_CONTROL_TUN_GET_FREQ:
-        {
-            unsigned long freq;
-
-            if (ioctl(priv->video_fd, VIDIOCGFREQ, &freq) == -1)
-            {
-                mp_msg(MSGT_TV, MSGL_ERR, "ioctl get freq failed: %s\n", strerror(errno));
-                return TVI_CONTROL_FALSE;
-            }
-
-            /* tuner uses khz not mhz ! */
-//          if (priv->tuner.flags & VIDEO_TUNER_LOW)
-//              freq /= 1000;
-            *(unsigned long *)arg = freq;
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_TUN_SET_FREQ:
-        {
-            /* argument is in MHz ! */
-            unsigned long freq = *(unsigned long *)arg;
-
-            if (priv->capability.audios) {
-                priv->audio[priv->audio_id].flags |= VIDEO_AUDIO_MUTE;
-                ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]);
-            }
-
-            mp_msg(MSGT_TV, MSGL_V, "requested frequency: %.3f\n", (float)freq/16);
-
-            /* tuner uses khz not mhz ! */
-//          if (priv->tuner.flags & VIDEO_TUNER_LOW)
-//              freq *= 1000;
-//          mp_msg(MSGT_TV, MSGL_V, " requesting from driver: freq=%.3f\n", (float)freq/16);
-            if (ioctl(priv->video_fd, VIDIOCSFREQ, &freq) == -1)
-            {
-                mp_msg(MSGT_TV, MSGL_ERR, "ioctl set freq failed: %s\n", strerror(errno));
-                return TVI_CONTROL_FALSE;
-            }
-            usleep(100000); // wait to suppress noise during switching
-
-            if (priv->capability.audios) {
-                priv->audio[priv->audio_id].flags &= ~VIDEO_AUDIO_MUTE;
-                ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]);
-            }
-
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_TUN_GET_TUNER:
-        {
-            if (ioctl(priv->video_fd, VIDIOCGTUNER, &priv->tuner) == -1)
-            {
-                mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno));
-                return TVI_CONTROL_FALSE;
-            }
-
-            mp_msg(MSGT_TV, MSGL_V, "Tuner (%s) range: %lu -> %lu\n", priv->tuner.name,
-                priv->tuner.rangelow, priv->tuner.rangehigh);
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_TUN_SET_TUNER:
-        {
-            if (ioctl(priv->video_fd, VIDIOCSTUNER, &priv->tuner) == -1)
-            {
-                mp_msg(MSGT_TV, MSGL_ERR, "ioctl set tuner failed: %s\n", strerror(errno));
-                return TVI_CONTROL_FALSE;
-            }
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_TUN_SET_NORM:
-        {
-            int req_mode = *(int *)arg;
-            int norm_index;
-            for(norm_index=0;supported_norms[norm_index].name; norm_index++)
-                if(req_mode==supported_norms[norm_index].normid)
-                    break;
-
-            if(!supported_norms[norm_index].name) {
-                mp_msg(MSGT_TV, MSGL_ERR, "Unknown norm!\n");
-                return TVI_CONTROL_FALSE;
-            }
-
-            if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER) {
-                int prev_mode;
-
-                control(priv, TVI_CONTROL_TUN_GET_TUNER, 0);
-                if(!(priv->tuner.flags & supported_norms[norm_index].tuner_flags))
-                {
-                    mp_msg(MSGT_TV, MSGL_ERR, "Tuner isn't capable to set norm!\n");
-                    return TVI_CONTROL_FALSE;
-                }
-
-                prev_mode = priv->tuner.mode;
-
-                priv->tuner.mode = supported_norms[norm_index].tuner_mode;
-
-                if (control(priv, TVI_CONTROL_TUN_SET_TUNER, &priv->tuner) != TVI_CONTROL_TRUE) {
-                    // norm setting failed, but maybe it's only because it's fixed
-                    if (priv->tuner.mode != prev_mode) return TVI_CONTROL_FALSE; // no it really failed
-                }
-
-            }
-
-            priv->channels[priv->act_channel].norm = supported_norms[norm_index].input_norm;
-
-            if (ioctl(priv->video_fd, VIDIOCSCHAN, &priv->channels[priv->act_channel]) == -1)
-            {
-                mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno));
-                return TVI_CONTROL_FALSE;
-            }
-
-            if (ioctl(priv->video_fd, VIDIOCGCAP, &priv->capability) == -1) {
-                mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilities failed: %s\n", strerror(errno));
-                return TVI_CONTROL_FALSE;
-            }
-
-            priv->fps = supported_norms[norm_index].fps;
-
-            if(priv->height > priv->capability.maxheight) {
-                priv->height = priv->capability.maxheight;
-            }
-
-            if(priv->width > priv->capability.maxwidth) {
-                priv->width = priv->capability.maxwidth;
-            }
-
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_TUN_GET_NORM:
-        {
-            *(int *)arg = priv->tuner.mode;
-
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_TUN_GET_SIGNAL:
-        {
-            if (ioctl(priv->video_fd, VIDIOCGTUNER, &priv->tuner) == -1)
-            {
-                mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno));
-                return TVI_CONTROL_FALSE;
-            }
-            *(int*)arg=100*(priv->tuner.signal>>8)/255;
-            return TVI_CONTROL_TRUE;
-        }
-
-        /* ========== AUDIO controls =========== */
-        case TVI_CONTROL_AUD_GET_FORMAT:
-        {
-            *(int *)arg = AF_FORMAT_S16_LE;
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_AUD_GET_CHANNELS:
-        {
-            *(int *)arg = priv->audio_in.channels;
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_AUD_GET_SAMPLERATE:
-        {
-            *(int *)arg = priv->audio_in.samplerate;
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_AUD_GET_SAMPLESIZE:
-        {
-            *(int *)arg = priv->audio_in.bytes_per_sample;
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_AUD_SET_SAMPLERATE:
-        {
-            if (audio_in_set_samplerate(&priv->audio_in, *(int *)arg) < 0) return TVI_CONTROL_FALSE;
-            setup_audio_buffer_sizes(priv);
-            return TVI_CONTROL_TRUE;
-        }
-        /* ========== SPECIFIC controls =========== */
-        case TVI_CONTROL_SPC_GET_INPUT:
-        {
-            int req_chan = *(int *)arg;
-            int i;
-
-            for (i = 0; i < priv->capability.channels; i++)
-            {
-                if (priv->channels[i].channel == req_chan)
-                    break;
-            }
-
-            priv->act_channel = i;
-
-            if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1)
-            {
-                mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno));
-                return TVI_CONTROL_FALSE;
-            }
-            return TVI_CONTROL_TRUE;
-        }
-
-        case TVI_CONTROL_SPC_SET_INPUT:
-        {
-            struct video_channel chan;
-            int req_chan = *(int *)arg;
-            int i;
-
-            if (req_chan >= priv->capability.channels)
-            {
-                mp_msg(MSGT_TV, MSGL_ERR, "Invalid input requested: %d, valid: 0-%d\n",
-                       req_chan, priv->capability.channels - 1);
-                return TVI_CONTROL_FALSE;
-            }
-
-            for (i = 0; i < priv->capability.channels; i++)
-            {
-                if (priv->channels[i].channel == req_chan)
-                    chan = priv->channels[i];
-            }
-
-            if (ioctl(priv->video_fd, VIDIOCSCHAN, &chan) == -1)
-            {
-                mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno));
-                return TVI_CONTROL_FALSE;
-            }
-            mp_msg(MSGT_TV, MSGL_INFO, "Using input '%s'\n", chan.name);
-
-            priv->act_channel = i;
-
-            /* update tuner state */
-//          if (priv->capability.type & VID_TYPE_TUNER)
-            if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER)
-                control(priv, TVI_CONTROL_TUN_GET_TUNER, 0);
-
-            /* update local channel list */
-            control(priv, TVI_CONTROL_SPC_GET_INPUT, &req_chan);
-            return TVI_CONTROL_TRUE;
-        case TVI_CONTROL_IMMEDIATE:
-            priv->immediate_mode = 1;
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_VBI_INIT:
-        {
-            void* ptr;
-            tt_stream_props tsp;
-
-            if (vbi_init(priv,*(char**)arg)!=TVI_CONTROL_TRUE)
-                return TVI_CONTROL_FALSE;
-            if(vbi_get_props(priv,&tsp)==TVI_CONTROL_TRUE)
-            {
-                ptr=&tsp;
-                if(teletext_control(NULL,TV_VBI_CONTROL_START,&ptr)==VBI_CONTROL_TRUE)
-                    priv->priv_vbi=ptr;
-                else
-                    priv->priv_vbi=NULL;
-            }
-            return TVI_CONTROL_TRUE;
-        }
-        case TVI_CONTROL_GET_VBI_PTR:
-            *(void **)arg=priv->priv_vbi;
-            return TVI_CONTROL_TRUE;
-    }
-
-    return TVI_CONTROL_UNKNOWN;
-}
-
-static int set_mute(priv_t* priv,int value)
-{
-    if (!priv->capability.audios) {
-        return 0;
-
-    if(value)
-        priv->audio[priv->audio_id].flags |=VIDEO_AUDIO_MUTE;
-    else
-        priv->audio[priv->audio_id].flags &= ~VIDEO_AUDIO_MUTE;
-    }
-    if(ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id])<0)
-        return 0;
-    return 1;
-}
-
-// copies a video frame
-// for YV12 swaps the 2nd and 3rd plane
-static inline void copy_frame(priv_t *priv, unsigned char *dest, unsigned char *source)
-{
-    if(priv->tv_param->automute>0){
-        if (ioctl(priv->video_fd, VIDIOCGTUNER, &priv->tuner) >= 0) {
-            if(priv->tv_param->automute<<8>priv->tuner.signal){
-                fill_blank_frame(dest,priv->bytesperline * priv->height,priv->format);
-                set_mute(priv,1);
-                return;
-            }
-        }
-        set_mute(priv,0);
-    }
-    // YV12 uses VIDEO_PALETTE_YUV420P, but the planes are swapped
-    if (priv->format == IMGFMT_YV12) {
-        fast_memcpy(dest, source, priv->width * priv->height);
-        fast_memcpy(dest+priv->width * priv->height*5/4, source+priv->width * priv->height, priv->width * priv->height/4);
-        fast_memcpy(dest+priv->width * priv->height, source+priv->width * priv->height*5/4, priv->width * priv->height/4);
-        return;
-    }
-
-    fast_memcpy(dest, source, priv->bytesperline * priv->height);
-}
-
-// maximum skew change, in frames
-#define MAX_SKEW_DELTA 0.6
-static void *video_grabber(void *data)
-{
-#define MAXTOL (priv->nbuf)
-    priv_t *priv = (priv_t*)data;
-    struct timeval curtime;
-    long long skew, prev_skew, xskew, interval, prev_interval;
-    int frame;
-    int i;
-    int framecount;
-    int tolerance;
-    unsigned long num;
-
-    /* start the capture process */
-
-    if ( priv->tv_param->mjpeg )
-    {
-        mp_msg(MSGT_TV, MSGL_INFO, "  MJP: gonna capture ! \n");
-        for (i=0; i < priv->nbuf; i++) {
-            num = i;
-            if (ioctl(priv->video_fd, MJPIOC_QBUF_CAPT, &num) < 0)
-                mp_msg(MSGT_TV, MSGL_ERR,
-                       "\n  MJP: ioctl MJPIOC_QBUF_CAPT b failed: %s\n", strerror(errno));
-        }
-    }
-    else
-    {
-        for (i=0; i < priv->nbuf; i++) {
-            if (ioctl(priv->video_fd, VIDIOCMCAPTURE, &priv->buf[i]) == -1)
-                mp_msg(MSGT_TV, MSGL_ERR, "\nioctl mcapture failed: %s\n", strerror(errno));
-        }
-    }
-
-    gettimeofday(&curtime, NULL);
-    priv->starttime = (long long)1e6*curtime.tv_sec + curtime.tv_usec;
-    priv->audio_skew_measure_time = 0;
-    pthread_mutex_unlock(&priv->audio_starter);
-    xskew = 0;
-    skew = 0;
-    interval = 0;
-
-    prev_interval = 0;
-    prev_skew = 0;
-
-    tolerance = MAXTOL;
-
-    for (framecount = 0; !priv->shutdown;)
-    {
-        for (i = 0; i < priv->nbuf && !priv->shutdown; i++, framecount++) {
-
-            if (priv->immediate_mode) {
-                while (priv->video_cnt == priv->video_buffer_size_max) {
-                    usleep(10000);
-                    if (priv->shutdown) {
-                        return NULL;
-                    }
-                }
-            }
-
-            frame = i;
-
-            if ( priv->tv_param->mjpeg )
-            {
-                while (ioctl(priv->video_fd, MJPIOC_SYNC, &priv->buf[frame].frame) < 0 &&
-                       (errno == EAGAIN || errno == EINTR));
-            }
-            else
-            {
-                while (ioctl(priv->video_fd, VIDIOCSYNC, &priv->buf[frame].frame) < 0 &&
-                       (errno == EAGAIN || errno == EINTR));
-            }
-            mp_dbg(MSGT_TV, MSGL_DBG3, "\npicture sync failed\n");
-
-            gettimeofday(&curtime, NULL);
-            if (!priv->immediate_mode) {
-                interval = (long long)1e6*curtime.tv_sec + curtime.tv_usec - priv->starttime;
-            } else {
-                interval = (long long)1e6*framecount/priv->fps;
-            }
-
-            if (!priv->immediate_mode) {
-                long long period, orig_interval;
-
-                if (tolerance == 0) {
-                    if (interval - prev_interval == 0) {
-                        mp_msg(MSGT_TV, MSGL_V, "\nvideo capture thread: frame delta = 0\n");
-                    } else if ((interval - prev_interval < (long long)0.85e6/priv->fps)
-                               || (interval - prev_interval > (long long)1.15e6/priv->fps) ) {
-                        mp_msg(MSGT_TV, MSGL_V, "\nvideo capture thread: frame delta ~ %.1f fps\n",
-                               (double)1e6/(interval - prev_interval));
-                    }
-                }
-
-                // correct the rate fluctuations on a small scale
-                orig_interval = interval;
-                period = priv->video_interval_sum/VIDEO_AVG_BUFFER_SIZE;
-                if (interval - prev_interval > 105*period/100) {
-                    if (tolerance > 0) {
-                        mp_msg(MSGT_TV, MSGL_DBG3, "correcting timestamp\n");
-                        interval = prev_interval + priv->video_interval_sum/VIDEO_AVG_BUFFER_SIZE;
-                        tolerance--;
-                    } else {
-                        mp_msg(MSGT_TV, MSGL_DBG3, "bad - frames were dropped\n");
-                        tolerance = MAXTOL;
-                    }
-                } else {
-                    if (tolerance < MAXTOL) {
-                        mp_msg(MSGT_TV, MSGL_DBG3, "fluctuation overcome\n");
-                    }
-                    tolerance = MAXTOL;
-                }
-
-                priv->video_interval_sum -= priv->video_avg_buffer[priv->video_avg_ptr];
-                priv->video_avg_buffer[priv->video_avg_ptr++] = orig_interval-prev_interval;
-                priv->video_interval_sum += orig_interval-prev_interval;
-                if (priv->video_avg_ptr >= VIDEO_AVG_BUFFER_SIZE) priv->video_avg_ptr = 0;
-
-//              fprintf(stderr, "fps: %f\n", (double)1e6*VIDEO_AVG_BUFFER_SIZE/priv->video_interval_sum);
-
-                // interpolate the skew in time
-                pthread_mutex_lock(&priv->skew_mutex);
-                xskew = priv->audio_skew + (interval - priv->audio_skew_measure_time)*priv->audio_skew_factor;
-                pthread_mutex_unlock(&priv->skew_mutex);
-                // correct extreme skew changes to avoid (especially) moving backwards in time
-                if (xskew - prev_skew > (interval - prev_interval)*MAX_SKEW_DELTA) {
-                    skew = prev_skew + (interval - prev_interval)*MAX_SKEW_DELTA;
-                } else if (xskew - prev_skew < -(interval - prev_interval)*MAX_SKEW_DELTA) {
-                    skew = prev_skew - (interval - prev_interval)*MAX_SKEW_DELTA;
-                } else {
-                    skew = xskew;
-                }
-            }
-
-            mp_msg(MSGT_TV, MSGL_DBG3, "\nfps = %f, interval = %f, a_skew = %f, corr_skew = %f\n",
-                   (interval != prev_interval) ? (double)1e6/(interval - prev_interval) : -1,
-                   (double)1e-6*interval, (double)1e-6*xskew, (double)1e-6*skew);
-            mp_msg(MSGT_TV, MSGL_DBG3, "vcnt = %d, acnt = %d\n", priv->video_cnt, priv->audio_cnt);
-
-            prev_skew = skew;
-            prev_interval = interval;
-
-            /* allocate a new buffer, if needed */
-            pthread_mutex_lock(&priv->video_buffer_mutex);
-            if (priv->video_buffer_size_current < priv->video_buffer_size_max) {
-                if (priv->video_cnt == priv->video_buffer_size_current) {
-                    unsigned char *newbuf = calloc(priv->bytesperline, priv->height);
-                    if (newbuf) {
-                        memmove(priv->video_ringbuffer+priv->video_tail+1, priv->video_ringbuffer+priv->video_tail,
-                               (priv->video_buffer_size_current-priv->video_tail)*sizeof(unsigned char *));
-                        memmove(priv->video_timebuffer+priv->video_tail+1, priv->video_timebuffer+priv->video_tail,
-                               (priv->video_buffer_size_current-priv->video_tail)*sizeof(long long));
-                        priv->video_ringbuffer[priv->video_tail] = newbuf;
-                        if ((priv->video_head >= priv->video_tail) && (priv->video_cnt > 0)) priv->video_head++;
-                        priv->video_buffer_size_current++;
-                    }
-                }
-            }
-            pthread_mutex_unlock(&priv->video_buffer_mutex);
-
-            if (priv->video_cnt == priv->video_buffer_size_current) {
-                if (!priv->immediate_mode) {
-                    mp_msg(MSGT_TV, MSGL_ERR, "\nvideo buffer full - dropping frame\n");
-                }
-            } else {
-                if (priv->immediate_mode) {
-                    priv->video_timebuffer[priv->video_tail] = interval;
-                } else {
-                    // compensate for audio skew
-                    // negative skew => there are more audio samples, increase interval
-                    // positive skew => less samples, shorten the interval
-                    priv->video_timebuffer[priv->video_tail] = interval - skew;
-                }
-
-                if ( priv->tv_param->mjpeg )
-                    copy_frame(priv, priv->video_ringbuffer[priv->video_tail],
-                               priv->mmap+(priv->mjpeg_bufsize)*i);
-                else
-                    copy_frame(priv, priv->video_ringbuffer[priv->video_tail],
-                               priv->mmap+priv->mbuf.offsets[frame]);
-                priv->video_tail = (priv->video_tail+1)%priv->video_buffer_size_current;
-                priv->video_cnt++;
-            }
-
-            if ( priv->tv_param->mjpeg )
-            {
-                num = frame;
-                if (ioctl(priv->video_fd, MJPIOC_QBUF_CAPT, &num) < 0)
-                {
-                    mp_msg(MSGT_TV, MSGL_ERR, "\n  MJP: ioctl MJPIOC_QBUF_CAPT end failed: %s\n",
-                           strerror(errno));
-                    continue;
-                }
-            }
-            else
-            {
-                if (ioctl(priv->video_fd, VIDIOCMCAPTURE, &priv->buf[frame]) == -1)
-                {
-                    mp_msg(MSGT_TV, MSGL_ERR, "\nioctl mcapture failed: %s\n", strerror(errno));
-                    continue;
-                }
-            }
-        }
-    }
-    mp_msg(MSGT_TV, MSGL_INFO, "  MJP: returning! \n");
-    return NULL;
-}
-
-static double grab_video_frame(priv_t *priv, char *buffer, int len)
-{
-    double interval;
-
-    if (priv->first) {
-        pthread_create(&priv->video_grabber_thread, NULL, video_grabber, priv);
-        priv->first = 0;
-    }
-
-    while (priv->video_cnt == 0) {
-        usleep(10000);
-    }
-
-    pthread_mutex_lock(&priv->video_buffer_mutex);
-    interval = (double)priv->video_timebuffer[priv->video_head]*1e-6;
-    fast_memcpy(buffer, priv->video_ringbuffer[priv->video_head], len);
-    priv->video_cnt--;
-    priv->video_head = (priv->video_head+1)%priv->video_buffer_size_current;
-    pthread_mutex_unlock(&priv->video_buffer_mutex);
-
-    return interval;
-}
-
-static int get_video_framesize(priv_t *priv)
-{
-    return priv->bytesperline * priv->height;
-}
-
-static void *audio_grabber(void *data)
-{
-    priv_t *priv = (priv_t*)data;
-    struct timeval tv;
-    int i, audio_skew_ptr = 0;
-    long long current_time, prev_skew = 0;
-
-    pthread_mutex_lock(&priv->audio_starter);
-
-    audio_in_start_capture(&priv->audio_in);
-    for (i = 0; i < priv->aud_skew_cnt; i++)
-        priv->audio_skew_buffer[i] = 0;
-
-    for (; !priv->shutdown;)
-    {
-        if (audio_in_read_chunk(&priv->audio_in, priv->audio_ringbuffer+priv->audio_tail*priv->audio_in.blocksize) < 0)
-            continue;
-
-        gettimeofday(&tv, NULL);
-
-        priv->audio_recv_blocks_total++;
-        current_time = (long long)1e6*tv.tv_sec + tv.tv_usec - priv->starttime;
-
-        priv->audio_skew_total -= priv->audio_skew_buffer[audio_skew_ptr];
-        priv->audio_skew_buffer[audio_skew_ptr] = current_time
-            - 1e6*priv->audio_secs_per_block*priv->audio_recv_blocks_total;
-        priv->audio_skew_total += priv->audio_skew_buffer[audio_skew_ptr];
-        audio_skew_ptr = (audio_skew_ptr+1) % priv->aud_skew_cnt;
-
-        pthread_mutex_lock(&priv->skew_mutex);
-        // linear interpolation - here we interpolate current skew value
-        // from the moving average, which we expect to be in the middle
-        // of the interval
-        if (priv->audio_recv_blocks_total > priv->aud_skew_cnt) {
-            priv->audio_skew = priv->audio_skew_total/priv->aud_skew_cnt;
-            priv->audio_skew += (priv->audio_skew*priv->aud_skew_cnt)/(2*priv->audio_recv_blocks_total-priv->aud_skew_cnt);
-        } else {
-            // this smoothes the evolution of audio_skew at startup a bit
-            priv->audio_skew = ((priv->aud_skew_cnt+priv->audio_recv_blocks_total)*priv->audio_skew_total)/(priv->aud_skew_cnt*priv->audio_recv_blocks_total);
-        }
-        // current skew factor (assuming linearity)
-        // used for further interpolation in video_grabber
-        // probably overkill but seems to be necessary for
-        // stress testing by dropping half of the audio frames ;)
-        // especially when using ALSA with large block sizes
-        // where audio_skew remains a long while behind
-        if ((priv->audio_skew_measure_time != 0) && (current_time - priv->audio_skew_measure_time != 0)) {
-            priv->audio_skew_factor = (double)(priv->audio_skew-prev_skew)/(current_time - priv->audio_skew_measure_time);
-        } else {
-            priv->audio_skew_factor = 0.0;
-        }
-
-        priv->audio_skew_measure_time = current_time;
-        prev_skew = priv->audio_skew;
-        pthread_mutex_unlock(&priv->skew_mutex);
-
-        if ((priv->audio_tail+1) % priv->audio_buffer_size == priv->audio_head) {
-            mp_msg(MSGT_TV, MSGL_ERR, "\ntoo bad - dropping audio frame !\n");
-            priv->audio_drop++;
-        } else {
-            priv->audio_tail = (priv->audio_tail+1) % priv->audio_buffer_size;
-            priv->audio_cnt++;
-        }
-    }
-    return NULL;
-}
-
-static double grab_audio_frame(priv_t *priv, char *buffer, int len)
-{
-    mp_dbg(MSGT_TV, MSGL_DBG2, "grab_audio_frame(priv=%p, buffer=%p, len=%d)\n",
-        priv, buffer, len);
-
-    if (priv->first) {
-        pthread_create(&priv->video_grabber_thread, NULL, video_grabber, priv);
-        priv->first = 0;
-    }
-
-    // compensate for dropped audio frames
-    if (priv->audio_drop && (priv->audio_head == priv->audio_tail)) {
-        priv->audio_drop--;
-        priv->audio_sent_blocks_total++;
-        memset(buffer, 0, len);
-        return (double)priv->audio_sent_blocks_total*priv->audio_secs_per_block;
-    }
-
-    while (priv->audio_head == priv->audio_tail) {
-        usleep(10000);
-    }
-    fast_memcpy(buffer, priv->audio_ringbuffer+priv->audio_head*priv->audio_in.blocksize, len);
-    priv->audio_head = (priv->audio_head+1) % priv->audio_buffer_size;
-    priv->audio_cnt--;
-    priv->audio_sent_blocks_total++;
-    return (double)priv->audio_sent_blocks_total*priv->audio_secs_per_block;
-}
-
-static int get_audio_framesize(priv_t *priv)
-{
-    return priv->audio_in.blocksize;
-}
diff --git a/sub/osd_font.otf b/sub/osd_font.otf
new file mode 100644
index 0000000..d8ebec0
Binary files /dev/null and b/sub/osd_font.otf differ
diff --git a/sub/osd_font.pfb b/sub/osd_font.pfb
deleted file mode 100644
index a4a65a1..0000000
Binary files a/sub/osd_font.pfb and /dev/null differ
diff --git a/sub/sd_ass.c b/sub/sd_ass.c
index 1cdc1e5..3b02a77 100644
--- a/sub/sd_ass.c
+++ b/sub/sd_ass.c
@@ -180,7 +180,7 @@ struct sh_sub *sd_ass_create_from_track(struct ass_track *track,
                                         bool vsfilter_aspect,
                                         struct MPOpts *opts)
 {
-    struct sh_sub *sh = talloc(NULL, struct sh_sub);
+    struct sh_sub *sh = talloc_zero(NULL, struct sh_sub);
     sh->opts = opts;
     sh->type = 'a';
     sh->title = track->name;
diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c
index deedc0b..f9b3cc1 100644
--- a/sub/sd_lavc.c
+++ b/sub/sd_lavc.c
@@ -40,16 +40,16 @@ static int init(struct sh_sub *sh, struct osd_state *osd)
     if (sh->initialized)
         return 0;
     struct sd_lavc_priv *priv = talloc_zero(NULL, struct sd_lavc_priv);
-    enum CodecID cid = CODEC_ID_NONE;
+    enum AVCodecID cid = AV_CODEC_ID_NONE;
     switch (sh->type) {
     case 'b':
-        cid = CODEC_ID_DVB_SUBTITLE; break;
+        cid = AV_CODEC_ID_DVB_SUBTITLE; break;
     case 'p':
-        cid = CODEC_ID_HDMV_PGS_SUBTITLE; break;
+        cid = AV_CODEC_ID_HDMV_PGS_SUBTITLE; break;
     case 'x':
-        cid = CODEC_ID_XSUB; break;
+        cid = AV_CODEC_ID_XSUB; break;
     case 'v':
-        cid = CODEC_ID_DVD_SUBTITLE; break;
+        cid = AV_CODEC_ID_DVD_SUBTITLE; break;
     }
     AVCodecContext *ctx = NULL;
     AVCodec *sub_codec = avcodec_find_decoder(cid);
diff --git a/sub/sub.c b/sub/sub.c
index a8a6d03..0d9d443 100644
--- a/sub/sub.c
+++ b/sub/sub.c
@@ -20,10 +20,10 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <libavutil/common.h>
+#include <libavutil/mem.h>
+
 #include "config.h"
-#if HAVE_MALLOC_H
-#include <malloc.h>
-#endif
 
 #include "stream/stream.h"
 #include "stream/stream_dvdnav.h"
@@ -40,7 +40,6 @@
 #include "sub.h"
 #include "sub/ass_mp.h"
 #include "spudec.h"
-#include "libavutil/common.h"
 
 
 char * const sub_osd_names[]={
@@ -105,10 +104,10 @@ void osd_alloc_buf(mp_osd_obj_t* obj)
     len = obj->stride*(obj->bbox.y2-obj->bbox.y1);
     if (obj->allocated<len) {
 	obj->allocated = len;
-	free(obj->bitmap_buffer);
-	free(obj->alpha_buffer);
-	obj->bitmap_buffer = memalign(16, len);
-	obj->alpha_buffer  = memalign(16, len);
+	av_free(obj->bitmap_buffer);
+	av_free(obj->alpha_buffer);
+	obj->bitmap_buffer = av_malloc(len);
+	obj->alpha_buffer  = av_malloc(len);
     }
     memset(obj->bitmap_buffer, sub_bg_color, len);
     memset(obj->alpha_buffer, sub_bg_alpha, len);
@@ -217,8 +216,8 @@ void osd_free(struct osd_state *osd)
     mp_osd_obj_t* obj=vo_osd_list;
     while(obj){
 	mp_osd_obj_t* next=obj->next;
-	free(obj->alpha_buffer);
-	free(obj->bitmap_buffer);
+	av_free(obj->alpha_buffer);
+	av_free(obj->bitmap_buffer);
 	free(obj);
 	obj=next;
     }
diff --git a/sub/subassconvert.c b/sub/subassconvert.c
index 7be4c48..6bf3c5b 100644
--- a/sub/subassconvert.c
+++ b/sub/subassconvert.c
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdbool.h>
+#include <ctype.h>
 
 #include "mp_msg.h"
 #include "subassconvert.h"
@@ -54,6 +55,11 @@ static void append_text(struct line *dst, char *fmt, ...)
     va_end(va);
 }
 
+static void append_text_n(struct line *dst, char *start, int length)
+{
+    append_text(dst, "%.*s", length, start);
+}
+
 static int indexof(const char *s, int c)
 {
     char *f = strchr(s, c);
@@ -87,7 +93,7 @@ static const struct tag_conv {
     {"<b>", "{\\b1}"}, {"</b>", "{\\b0}"},
     {"<u>", "{\\u1}"}, {"</u>", "{\\u0}"},
     {"<s>", "{\\s1}"}, {"</s>", "{\\s0}"},
-    {"{", "\\{"}, {"}", "\\}"},
+    {"}", "\\}"},
     {"\r\n", "\\N"}, {"\n", "\\N"}, {"\r", "\\N"},
 };
 
@@ -277,6 +283,19 @@ void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size)
                 sp++;
                 line++;
             }
+        } else if (*line == '{') {
+            char *end = strchr(line, '}');
+            if (line[1] == '\\' && end) {
+                /* Likely ASS tag, pass them through.
+                 * Note that ASS tags like {something\an8} are legal too (i.e.
+                 * the first character after '{' doesn't have to be '\'), but
+                 * consider these fringe cases not worth supporting. */
+                append_text_n(&new_line, line, end - line + 1);
+                line = end + 1;
+            } else {
+                append_text(&new_line, "\\{");   // escape '{'
+                line++;
+            }
         }
 
         /* Tag conversion code didn't match */
diff --git a/sub/subreader.c b/sub/subreader.c
index 370e21e..79e307e 100644
--- a/sub/subreader.c
+++ b/sub/subreader.c
@@ -26,6 +26,7 @@
 #include <string.h>
 #include <sys/types.h>
 #include <dirent.h>
+#include <ctype.h>
 
 #include "config.h"
 #include "mp_msg.h"
@@ -383,14 +384,14 @@ static subtitle *sub_ass_read_line_subviewer(stream_t *st, subtitle *current,
     int a1, a2, a3, a4, b1, b2, b3, b4, j = 0;
 
     while (!current->text[0]) {
-        char line[LINE_LEN + 1], full_line[LINE_LEN + 1], sep;
+        char line[LINE_LEN + 1], full_line[LINE_LEN + 1];
         int i;
 
         /* Parse SubRip header */
         if (!stream_read_line(st, line, LINE_LEN, utf16))
             return NULL;
-        if (sscanf(line, "%d:%d:%d%[,.:]%d --> %d:%d:%d%[,.:]%d",
-                     &a1, &a2, &a3, &sep, &a4, &b1, &b2, &b3, &sep, &b4) < 10)
+        if (sscanf(line, "%d:%d:%d%*1[,.:]%d --> %d:%d:%d%*1[,.:]%d",
+                     &a1, &a2, &a3, &a4, &b1, &b2, &b3, &b4) < 8)
             continue;
 
         current->start = a1 * 360000 + a2 * 6000 + a3 * 100 + a4 / 10;
@@ -447,7 +448,7 @@ static subtitle *sub_read_line_subviewer(stream_t *st,subtitle *current,
         return sub_ass_read_line_subviewer(st, current, args);
     while (!current->text[0]) {
 	if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL;
-	if ((len=sscanf (line, "%d:%d:%d%[,.:]%d --> %d:%d:%d%[,.:]%d",&a1,&a2,&a3,(char *)&i,&a4,&b1,&b2,&b3,(char *)&i,&b4)) < 10)
+	if ((len=sscanf (line, "%d:%d:%d%*1[,.:]%d --> %d:%d:%d%*1[,.:]%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8)
 	    continue;
 	current->start = a1*360000+a2*6000+a3*100+a4/10;
 	current->end   = b1*360000+b2*6000+b3*100+b4/10;
@@ -1097,7 +1098,7 @@ static int sub_autodetect (stream_t* st, int *uses_time, int utf16) {
 		{*uses_time=1;return SUB_MPL2;}
 	if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",     &i, &i, &i, &i, &i, &i, &i, &i)==8)
 		{*uses_time=1;return SUB_SUBRIP;}
-	if (sscanf (line, "%d:%d:%d%[,.:]%d --> %d:%d:%d%[,.:]%d", &i, &i, &i, (char *)&i, &i, &i, &i, &i, (char *)&i, &i)==10)
+	if (sscanf (line, "%d:%d:%d%*1[,.:]%d --> %d:%d:%d%*1[,.:]%d", &i, &i, &i, &i, &i, &i, &i, &i) == 8)
 		{*uses_time=1;return SUB_SUBVIEWER;}
 	if (sscanf (line, "{T %d:%d:%d:%d",&i, &i, &i, &i)==4)
 		{*uses_time=1;return SUB_SUBVIEWER2;}

-- 
mplayer2 packaging



More information about the pkg-multimedia-commits mailing list