changeset 210:12004b385a96 trunk

[svn] Sync with xmms-wma instead of bmp-wma & GThreadify. Does not explode, but does not play either.
author chainsaw
date Sat, 19 Nov 2005 14:42:28 -0800
parents bd8457b077cf
children 0b48662886e9
files Plugins/Input/wma/iir.c Plugins/Input/wma/iir.h Plugins/Input/wma/libffwma/Makefile.am Plugins/Input/wma/libffwma/allcodecs.c Plugins/Input/wma/libffwma/allformats.c Plugins/Input/wma/libffwma/asf.c Plugins/Input/wma/libffwma/avcodec.h Plugins/Input/wma/libffwma/avio.c Plugins/Input/wma/libffwma/aviobuf.c Plugins/Input/wma/libffwma/common.c Plugins/Input/wma/libffwma/common.h Plugins/Input/wma/libffwma/config.h Plugins/Input/wma/libffwma/cutils.c Plugins/Input/wma/libffwma/dsputil.c Plugins/Input/wma/libffwma/dsputil.h Plugins/Input/wma/libffwma/fft.c Plugins/Input/wma/libffwma/file.c Plugins/Input/wma/libffwma/futils.c Plugins/Input/wma/libffwma/mdct.c Plugins/Input/wma/libffwma/mem.c Plugins/Input/wma/libffwma/os_support.c Plugins/Input/wma/libffwma/parser.c Plugins/Input/wma/libffwma/utils.c Plugins/Input/wma/libffwma/wmadec.c Plugins/Input/wma/wma.c
diffstat 25 files changed, 6066 insertions(+), 961 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/Input/wma/iir.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/iir.c	Sat Nov 19 14:42:28 2005 -0800
@@ -17,7 +17,7 @@
  *   along with this program; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- *   $Id: iir.c,v 1.1.1.1 2004/12/19 12:48:13 bogorodskiy Exp $
+ *   $Id: iir.c,v 1.5 2003/09/10 21:53:08 liebremx Exp $
  */
 
 /* IIR filter coefficients */
@@ -154,11 +154,11 @@
 			out[channel] += (data[index+channel]>>2);
 
 			/* Round and convert to integer */
-			/*#ifdef X86*/
+#ifdef __i386__
                         tempgint = round_trick(out[channel]);
-/*#else
+#else
 			tempgint = (int)lroundf(out[channel]);
-#endif*/
+#endif
 
 			/* Limit the output */
 			if (tempgint < -32768)
--- a/Plugins/Input/wma/iir.h	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/iir.h	Sat Nov 19 14:42:28 2005 -0800
@@ -17,20 +17,23 @@
  *   along with this program; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- *   $Id: iir.h,v 1.1.1.1 2004/12/19 12:48:13 bogorodskiy Exp $
+ *   $Id: iir.h,v 1.1 2003/05/21 13:59:59 liebremx Exp $
  */
 #ifndef IIR_H
 #define IIR_H
 
 #include <stdio.h>
+#if 0
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include <glib.h>
+#endif
+#include <pthread.h>
 #include <string.h>
+#include <math.h>
 
-/* XMMS public headers */
 #include <audacious/plugin.h>
-#include <audacious/util.h>
+#include <libaudacious/util.h>
 
 #define EQ_MAX_BANDS 10
 /* Number of channels (Stereo) */
--- a/Plugins/Input/wma/libffwma/Makefile.am	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/Makefile.am	Sat Nov 19 14:42:28 2005 -0800
@@ -6,7 +6,7 @@
 			bswap.h common.c common.h \
 			cutils.c dsputil.c dsputil.h \
 			fft.c file.c futils.c mdct.c \
-			os_support.c os_support.h \
+			mem.c os_support.c os_support.h \
 			parser.c simple_idct.c \
 			simple_idct.h utils.c wmadata.h \
 			wmadec.c
--- a/Plugins/Input/wma/libffwma/allcodecs.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/allcodecs.c	Sat Nov 19 14:42:28 2005 -0800
@@ -1,7 +1,6 @@
 /*
  * Utils for libavcodec
  * Copyright (c) 2002 Fabrice Bellard.
- * Copyright (c) 2004 Roman Bogorodskiy (bmp-wma specific stuff)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,17 +17,33 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+/**
+ * @file allcodecs.c
+ * Utils for libavcodec.
+ */
+
 #include "avcodec.h"
 
+/* If you do not call this function, then you can select exactly which
+   formats you want to support */
+
+/**
+ * simple call to register all the codecs. 
+ */
 void avcodec_register_all(void)
 {
-	static int inited = 0;
+    static int inited = 0;
     
-    	if (inited != 0)
-		return;
-    	inited = 1;
+    if (inited != 0)
+	return;
+    inited = 1;
 
-    	register_avcodec(&wmav1_decoder);
-    	register_avcodec(&wmav2_decoder);
+    /* decoders */
+#ifdef CONFIG_DECODERS
+#ifdef CONFIG_RISKY
+    register_avcodec(&wmav1_decoder);
+    register_avcodec(&wmav2_decoder);
+#endif
+#endif
 }
 
--- a/Plugins/Input/wma/libffwma/allformats.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/allformats.c	Sat Nov 19 14:42:28 2005 -0800
@@ -18,14 +18,110 @@
  */
 #include "avformat.h"
 
+/* If you do not call this function, then you can select exactly which
+   formats you want to support */
+
+/**
+ * Initialize libavcodec and register all the codecs and formats.
+ */
 void av_register_all(void)
 {
     avcodec_init();
     avcodec_register_all();
 
+    //mpegps_init();
+    //mpegts_init();
+#ifdef CONFIG_ENCODERS
+    crc_init();
+    img_init();
+#endif //CONFIG_ENCODERS
+    //raw_init();
+    //mp3_init();
+    //rm_init();
+#ifdef CONFIG_RISKY
     asf_init();
+#endif
+#ifdef CONFIG_ENCODERS
+    avienc_init();
+#endif //CONFIG_ENCODERS
+    //avidec_init();
+    //wav_init();
+    //swf_init();
+    //au_init();
+#ifdef CONFIG_ENCODERS
+    gif_init();
+#endif //CONFIG_ENCODERS
+    //mov_init();
+#ifdef CONFIG_ENCODERS
+    movenc_init();
+    jpeg_init();
+#endif //CONFIG_ENCODERS
+    //dv_init();
+    //fourxm_init();
+#ifdef CONFIG_ENCODERS
+    flvenc_init();
+#endif //CONFIG_ENCODERS
+    //flvdec_init();
+    //str_init();
+    //roq_init();
+    //ipmovie_init();
+    //wc3_init();
+    //westwood_init();
+    //film_init();
+    //idcin_init();
+    //flic_init();
+    //vmd_init();
+
+#if defined(AMR_NB) || defined(AMR_NB_FIXED) || defined(AMR_WB)
+    amr_init();
+#endif
+    //yuv4mpeg_init();
+    
+#ifdef CONFIG_VORBIS
+    ogg_init();
+#endif
+
+#ifndef CONFIG_WIN32
+    //ffm_init();
+#endif
+#ifdef CONFIG_VIDEO4LINUX
+    video_grab_init();
+#endif
+#if defined(CONFIG_AUDIO_OSS) || defined(CONFIG_AUDIO_BEOS)
+    audio_init();
+#endif
+
+#ifdef CONFIG_DV1394
+    dv1394_init();
+#endif
+
+    //nut_init();
+
+#ifdef CONFIG_ENCODERS
+    /* image formats */
+    av_register_image_format(&pnm_image_format);
+    av_register_image_format(&pbm_image_format);
+    av_register_image_format(&pgm_image_format);
+    av_register_image_format(&ppm_image_format);
+    av_register_image_format(&pam_image_format);
+    av_register_image_format(&pgmyuv_image_format);
+    av_register_image_format(&yuv_image_format);
+#ifdef CONFIG_ZLIB
+    av_register_image_format(&png_image_format);
+#endif
+    av_register_image_format(&jpeg_image_format);
+    av_register_image_format(&gif_image_format);
+#endif //CONFIG_ENCODERS
 
     /* file protocols */
     register_protocol(&file_protocol);
     register_protocol(&pipe_protocol);
+#ifdef CONFIG_NETWORK
+    rtsp_init();
+    rtp_init();
+    register_protocol(&udp_protocol);
+    register_protocol(&rtp_protocol);
+    register_protocol(&tcp_protocol);
+    register_protocol(&http_protocol);
+#endif
 }
--- a/Plugins/Input/wma/libffwma/asf.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/asf.c	Sat Nov 19 14:42:28 2005 -0800
@@ -16,15 +16,12 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
+#include "avformat.h"
+#include "avi.h"
+//#include "mpegaudio.h"
+#include <iconv.h>
 
-#include "avformat.h"
-#include "avcodec.h"
-#include "avi.h"
-
+#undef NDEBUG
 #include <assert.h>
 #define MPA_FRAME_SIZE 1152
 #define PACKET_SIZE 3200
@@ -150,6 +147,14 @@
     0x20fb5700, 0x5b55, 0x11cf, { 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b },
 };
 
+static const GUID video_stream = {
+    0xBC19EFC0, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
+};
+
+static const GUID video_conceal_none = {
+    0x20FB5700, 0x5B55, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
+};
+
 
 static const GUID comment_header = {
     0x75b22633, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c },
@@ -189,17 +194,17 @@
 };
 
 const CodecTag codec_wav_tags[] = {
-/*    { CODEC_ID_MP2, 0x50 },
+    { CODEC_ID_MP2, 0x50 },
     { CODEC_ID_MP3, 0x55 },
     { CODEC_ID_AC3, 0x2000 },
     { CODEC_ID_PCM_S16LE, 0x01 },
-    { CODEC_ID_PCM_U8, 0x01 }, 
+    { CODEC_ID_PCM_U8, 0x01 }, /* must come after s16le in this list */
     { CODEC_ID_PCM_ALAW, 0x06 },
     { CODEC_ID_PCM_MULAW, 0x07 },
     { CODEC_ID_ADPCM_MS, 0x02 },
     { CODEC_ID_ADPCM_IMA_WAV, 0x11 },
-    { CODEC_ID_ADPCM_IMA_DK4, 0x61 },  
-    { CODEC_ID_ADPCM_IMA_DK3, 0x62 },*/
+    { CODEC_ID_ADPCM_IMA_DK4, 0x61 },  /* rogue format number */
+    { CODEC_ID_ADPCM_IMA_DK3, 0x62 },  /* rogue format number */
     { CODEC_ID_WMAV1, 0x160 },
     { CODEC_ID_WMAV2, 0x161 },
     { 0, 0 },
@@ -252,7 +257,7 @@
         if (codec->extradata_size > 0) {
             if (codec->extradata_size > size - 18)
                 codec->extradata_size = size - 18;
-            codec->extradata = malloc(codec->extradata_size);
+            codec->extradata = av_mallocz(codec->extradata_size);
             get_buffer(pb, codec->extradata, codec->extradata_size);
         } else
             codec->extradata_size = 0;
@@ -263,9 +268,493 @@
     }
 }
 
+#ifdef CONFIG_ENCODERS
+static void put_guid(ByteIOContext *s, const GUID *g)
+{
+    int i;
+
+    put_le32(s, g->v1);
+    put_le16(s, g->v2);
+    put_le16(s, g->v3);
+    for(i=0;i<8;i++)
+        put_byte(s, g->v4[i]);
+}
+
+static void put_str16(ByteIOContext *s, const char *tag)
+{
+    int c;
+
+    put_le16(s,strlen(tag) + 1);
+    for(;;) {
+        c = (uint8_t)*tag++;
+        put_le16(s, c);
+        if (c == '\0')
+            break;
+    }
+}
+
+static void put_str16_nolen(ByteIOContext *s, const char *tag)
+{
+    int c;
+
+    for(;;) {
+        c = (uint8_t)*tag++;
+        put_le16(s, c);
+        if (c == '\0')
+            break;
+    }
+}
+
+static int64_t put_header(ByteIOContext *pb, const GUID *g)
+{
+    int64_t pos;
+
+    pos = url_ftell(pb);
+    put_guid(pb, g);
+    put_le64(pb, 24);
+    return pos;
+}
+
+/* update header size */
+static void end_header(ByteIOContext *pb, int64_t pos)
+{
+    int64_t pos1;
+
+    pos1 = url_ftell(pb);
+    url_fseek(pb, pos + 16, SEEK_SET);
+    put_le64(pb, pos1 - pos);
+    url_fseek(pb, pos1, SEEK_SET);
+}
+
+/* write an asf chunk (only used in streaming case) */
+static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
+{
+    ASFContext *asf = s->priv_data;
+    ByteIOContext *pb = &s->pb;
+    int length;
+
+    length = payload_length + 8;
+    put_le16(pb, type);
+    put_le16(pb, length);
+    put_le32(pb, asf->seqno);
+    put_le16(pb, flags); /* unknown bytes */
+    put_le16(pb, length);
+    asf->seqno++;
+}
+
+/* convert from unix to windows time */
+static int64_t unix_to_file_time(int ti)
+{
+    int64_t t;
+
+    t = ti * int64_t_C(10000000);
+    t += int64_t_C(116444736000000000);
+    return t;
+}
+
+/* write the header (used two times if non streamed) */
+static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
+{
+    ASFContext *asf = s->priv_data;
+    ByteIOContext *pb = &s->pb;
+    int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
+    int has_title;
+    AVCodecContext *enc;
+    int64_t header_offset, cur_pos, hpos;
+    int bit_rate;
+
+    has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);
+
+    bit_rate = 0;
+    for(n=0;n<s->nb_streams;n++) {
+        enc = &s->streams[n]->codec;
+
+        bit_rate += enc->bit_rate;
+    }
+
+    if (asf->is_streamed) {
+        put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
+    }
+
+    put_guid(pb, &asf_header);
+    put_le64(pb, -1); /* header length, will be patched after */
+    put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */
+    put_byte(pb, 1); /* ??? */
+    put_byte(pb, 2); /* ??? */
+
+    /* file header */
+    header_offset = url_ftell(pb);
+    hpos = put_header(pb, &file_header);
+    put_guid(pb, &my_guid);
+    put_le64(pb, file_size);
+    file_time = 0;
+    put_le64(pb, unix_to_file_time(file_time));
+    put_le64(pb, asf->nb_packets); /* number of packets */
+    put_le64(pb, asf->duration); /* end time stamp (in 100ns units) */
+    put_le64(pb, asf->duration); /* duration (in 100ns units) */
+    put_le32(pb, 0); /* start time stamp */
+    put_le32(pb, 0); /* ??? */
+    put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */
+    put_le32(pb, asf->packet_size); /* packet size */
+    put_le32(pb, asf->packet_size); /* packet size */
+    put_le32(pb, bit_rate); /* Nominal data rate in bps */
+    end_header(pb, hpos);
+
+    /* unknown headers */
+    hpos = put_header(pb, &head1_guid);
+    put_guid(pb, &head2_guid);
+    put_le32(pb, 6);
+    put_le16(pb, 0);
+    end_header(pb, hpos);
+
+    /* title and other infos */
+    if (has_title) {
+        hpos = put_header(pb, &comment_header);
+        put_le16(pb, 2 * (strlen(s->title) + 1));
+        put_le16(pb, 2 * (strlen(s->author) + 1));
+        put_le16(pb, 2 * (strlen(s->copyright) + 1));
+        put_le16(pb, 2 * (strlen(s->comment) + 1));
+        put_le16(pb, 0);
+        put_str16_nolen(pb, s->title);
+        put_str16_nolen(pb, s->author);
+        put_str16_nolen(pb, s->copyright);
+        put_str16_nolen(pb, s->comment);
+        end_header(pb, hpos);
+    }
+
+    /* stream headers */
+    for(n=0;n<s->nb_streams;n++) {
+        int64_t es_pos;
+        //        ASFStream *stream = &asf->streams[n];
+
+        enc = &s->streams[n]->codec;
+        asf->streams[n].num = n + 1;
+        asf->streams[n].seq = 0;
+
+        switch(enc->codec_type) {
+        case CODEC_TYPE_AUDIO:
+            wav_extra_size = 0;
+            extra_size = 18 + wav_extra_size;
+            extra_size2 = 0;
+            break;
+        default:
+        case CODEC_TYPE_VIDEO:
+            wav_extra_size = 0;
+            extra_size = 0x33;
+            extra_size2 = 0;
+            break;
+        }
+
+        hpos = put_header(pb, &stream_header);
+        if (enc->codec_type == CODEC_TYPE_AUDIO) {
+            put_guid(pb, &audio_stream);
+            put_guid(pb, &audio_conceal_none);
+        } else {
+            put_guid(pb, &video_stream);
+            put_guid(pb, &video_conceal_none);
+        }
+        put_le64(pb, 0); /* ??? */
+        es_pos = url_ftell(pb);
+        put_le32(pb, extra_size); /* wav header len */
+        put_le32(pb, extra_size2); /* additional data len */
+        put_le16(pb, n + 1); /* stream number */
+        put_le32(pb, 0); /* ??? */
+
+        if (enc->codec_type == CODEC_TYPE_AUDIO) {
+            /* WAVEFORMATEX header */
+            int wavsize = put_wav_header(pb, enc);
+
+            if (wavsize < 0)
+                return -1;
+            if (wavsize != extra_size) {
+                cur_pos = url_ftell(pb);
+                url_fseek(pb, es_pos, SEEK_SET);
+                put_le32(pb, wavsize); /* wav header len */
+                url_fseek(pb, cur_pos, SEEK_SET);
+            }
+        } else {
+            put_le32(pb, enc->width);
+            put_le32(pb, enc->height);
+            put_byte(pb, 2); /* ??? */
+            put_le16(pb, 40); /* size */
+
+            /* BITMAPINFOHEADER header */
+            put_bmp_header(pb, enc, codec_bmp_tags, 1);
+        }
+        end_header(pb, hpos);
+    }
+
+    /* media comments */
+
+    hpos = put_header(pb, &codec_comment_header);
+    put_guid(pb, &codec_comment1_header);
+    put_le32(pb, s->nb_streams);
+    for(n=0;n<s->nb_streams;n++) {
+        AVCodec *p;
+
+        enc = &s->streams[n]->codec;
+        p = avcodec_find_encoder(enc->codec_id);
+
+        put_le16(pb, asf->streams[n].num);
+        put_str16(pb, p ? p->name : enc->codec_name);
+        put_le16(pb, 0); /* no parameters */
+        
+        
+        /* id */
+        if (enc->codec_type == CODEC_TYPE_AUDIO) {
+            put_le16(pb, 2);
+            if(!enc->codec_tag)
+                enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id);
+            if(!enc->codec_tag)
+                return -1;
+            put_le16(pb, enc->codec_tag);
+        } else {
+            put_le16(pb, 4);
+            if(!enc->codec_tag)
+                enc->codec_tag = codec_get_tag(codec_bmp_tags, enc->codec_id);
+            if(!enc->codec_tag)
+                return -1;
+            put_le32(pb, enc->codec_tag);
+        }
+    }
+    end_header(pb, hpos);
+
+    /* patch the header size fields */
+
+    cur_pos = url_ftell(pb);
+    header_size = cur_pos - header_offset;
+    if (asf->is_streamed) {
+        header_size += 8 + 30 + 50;
+
+        url_fseek(pb, header_offset - 10 - 30, SEEK_SET);
+        put_le16(pb, header_size);
+        url_fseek(pb, header_offset - 2 - 30, SEEK_SET);
+        put_le16(pb, header_size);
+
+        header_size -= 8 + 30 + 50;
+    }
+    header_size += 24 + 6;
+    url_fseek(pb, header_offset - 14, SEEK_SET);
+    put_le64(pb, header_size);
+    url_fseek(pb, cur_pos, SEEK_SET);
+
+    /* movie chunk, followed by packets of packet_size */
+    asf->data_offset = cur_pos;
+    put_guid(pb, &data_header);
+    put_le64(pb, data_chunk_size);
+    put_guid(pb, &my_guid);
+    put_le64(pb, asf->nb_packets); /* nb packets */
+    put_byte(pb, 1); /* ??? */
+    put_byte(pb, 1); /* ??? */
+    return 0;
+}
+
+static int asf_write_header(AVFormatContext *s)
+{
+    ASFContext *asf = s->priv_data;
+
+    av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
+
+    asf->packet_size = PACKET_SIZE;
+    asf->nb_packets = 0;
+
+    if (asf_write_header1(s, 0, 50) < 0) {
+        //av_free(asf);
+        return -1;
+    }
+
+    put_flush_packet(&s->pb);
+
+    asf->packet_nb_frames = 0;
+    asf->packet_timestamp_start = -1;
+    asf->packet_timestamp_end = -1;
+    asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
+    init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
+                  NULL, NULL, NULL, NULL);
+
+    return 0;
+}
+
+static int asf_write_stream_header(AVFormatContext *s)
+{
+    ASFContext *asf = s->priv_data;
+
+    asf->is_streamed = 1;
+
+    return asf_write_header(s);
+}
+
+/* write a fixed size packet */
+static int put_packet(AVFormatContext *s,
+                       unsigned int timestamp, unsigned int duration,
+                       int nb_frames, int padsize)
+{
+    ASFContext *asf = s->priv_data;
+    ByteIOContext *pb = &s->pb;
+    int flags;
+
+    if (asf->is_streamed) {
+        put_chunk(s, 0x4424, asf->packet_size, 0);
+    }
+
+    put_byte(pb, 0x82);
+    put_le16(pb, 0);
+
+    flags = 0x01; /* nb segments present */
+    if (padsize > 0) {
+        if (padsize < 256)
+            flags |= 0x08;
+        else
+            flags |= 0x10;
+    }
+    put_byte(pb, flags); /* flags */
+    put_byte(pb, 0x5d);
+    if (flags & 0x10)
+        put_le16(pb, padsize - 2);
+    if (flags & 0x08)
+        put_byte(pb, padsize - 1);
+    put_le32(pb, timestamp);
+    put_le16(pb, duration);
+    put_byte(pb, nb_frames | 0x80);
+
+    return PACKET_HEADER_SIZE + ((flags & 0x18) >> 3);
+}
+
+static void flush_packet(AVFormatContext *s)
+{
+    ASFContext *asf = s->priv_data;
+    int hdr_size, ptr;
+
+    hdr_size = put_packet(s, asf->packet_timestamp_start,
+               asf->packet_timestamp_end - asf->packet_timestamp_start,
+               asf->packet_nb_frames, asf->packet_size_left);
+
+    /* Clear out the padding bytes */
+    ptr = asf->packet_size - hdr_size - asf->packet_size_left;
+    memset(asf->packet_buf + ptr, 0, asf->packet_size_left);
+
+    put_buffer(&s->pb, asf->packet_buf, asf->packet_size - hdr_size);
+
+    put_flush_packet(&s->pb);
+    asf->nb_packets++;
+    asf->packet_nb_frames = 0;
+    asf->packet_timestamp_start = -1;
+    asf->packet_timestamp_end = -1;
+    asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
+    init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
+                  NULL, NULL, NULL, NULL);
+}
+
+static void put_frame_header(AVFormatContext *s, ASFStream *stream, int timestamp,
+                             int payload_size, int frag_offset, int frag_len)
+{
+    ASFContext *asf = s->priv_data;
+    ByteIOContext *pb = &asf->pb;
+    int val;
+
+    val = stream->num;
+    if (s->streams[val - 1]->codec.coded_frame->key_frame /* && frag_offset == 0 */)
+        val |= 0x80;
+    put_byte(pb, val);
+    put_byte(pb, stream->seq);
+    put_le32(pb, frag_offset); /* fragment offset */
+    put_byte(pb, 0x08); /* flags */
+    put_le32(pb, payload_size);
+    put_le32(pb, timestamp);
+    put_le16(pb, frag_len);
+}
+
+
+/* Output a frame. We suppose that payload_size <= PACKET_SIZE.
+
+   It is there that you understand that the ASF format is really
+   crap. They have misread the MPEG Systems spec !
+ */
+static void put_frame(AVFormatContext *s, ASFStream *stream, int timestamp,
+                      const uint8_t *buf, int payload_size)
+{
+    ASFContext *asf = s->priv_data;
+    int frag_pos, frag_len, frag_len1;
+
+    frag_pos = 0;
+    while (frag_pos < payload_size) {
+        frag_len = payload_size - frag_pos;
+        frag_len1 = asf->packet_size_left - FRAME_HEADER_SIZE;
+        if (frag_len1 > 0) {
+            if (frag_len > frag_len1)
+                frag_len = frag_len1;
+            put_frame_header(s, stream, timestamp+1, payload_size, frag_pos, frag_len);
+            put_buffer(&asf->pb, buf, frag_len);
+            asf->packet_size_left -= (frag_len + FRAME_HEADER_SIZE);
+            asf->packet_timestamp_end = timestamp;
+            if (asf->packet_timestamp_start == -1)
+                asf->packet_timestamp_start = timestamp;
+            asf->packet_nb_frames++;
+        } else {
+            frag_len = 0;
+        }
+        frag_pos += frag_len;
+        buf += frag_len;
+        /* output the frame if filled */
+        if (asf->packet_size_left <= FRAME_HEADER_SIZE)
+            flush_packet(s);
+    }
+    stream->seq++;
+}
+
+
+static int asf_write_packet(AVFormatContext *s, int stream_index,
+                            const uint8_t *buf, int size, int64_t timestamp)
+{
+    ASFContext *asf = s->priv_data;
+    ASFStream *stream;
+    int64_t duration;
+    AVCodecContext *codec;
+
+    codec = &s->streams[stream_index]->codec;
+    stream = &asf->streams[stream_index];
+
+    if (codec->codec_type == CODEC_TYPE_AUDIO) {
+        duration = (codec->frame_number * codec->frame_size * int64_t_C(10000000)) /
+            codec->sample_rate;
+    } else {
+        duration = av_rescale(codec->frame_number * codec->frame_rate_base, 10000000, codec->frame_rate);
+    }
+    if (duration > asf->duration)
+        asf->duration = duration;
+
+    put_frame(s, stream, timestamp, buf, size);
+    return 0;
+}
+
+static int asf_write_trailer(AVFormatContext *s)
+{
+    ASFContext *asf = s->priv_data;
+    int64_t file_size;
+
+    /* flush the current packet */
+    if (asf->pb.buf_ptr > asf->pb.buffer)
+        flush_packet(s);
+
+    if (asf->is_streamed) {
+        put_chunk(s, 0x4524, 0, 0); /* end of stream */
+    } else {
+        /* rewrite an updated header */
+        file_size = url_ftell(&s->pb);
+        url_fseek(&s->pb, 0, SEEK_SET);
+        asf_write_header1(s, file_size, file_size - asf->data_offset);
+    }
+
+    put_flush_packet(&s->pb);
+    return 0;
+}
+#endif //CONFIG_ENCODERS
+
 /**********************************/
 /* decoding */
 
+//#define DEBUG
+
 #ifdef DEBUG
 #define PRINT_IF_GUID(g,cmp) \
 if (!memcmp(g, &cmp, sizeof(GUID))) \
@@ -279,6 +768,8 @@
     else PRINT_IF_GUID(g, stream_header);
     else PRINT_IF_GUID(g, audio_stream);
     else PRINT_IF_GUID(g, audio_conceal_none);
+    else PRINT_IF_GUID(g, video_stream);
+    else PRINT_IF_GUID(g, video_conceal_none);
     else PRINT_IF_GUID(g, comment_header);
     else PRINT_IF_GUID(g, codec_comment_header);
     else PRINT_IF_GUID(g, codec_comment1_header);
@@ -294,7 +785,7 @@
         printf(" 0x%02x,", g->v4[i]);
     printf("}\n");
 }
-#undef PRINT_IF_GUID
+#undef PRINT_IF_GUID(g,cmp)
 #endif
 
 static void get_guid(ByteIOContext *s, GUID *g)
@@ -308,19 +799,81 @@
         g->v4[i] = get_byte(s);
 }
 
+#if 0
+static void get_str16(ByteIOContext *pb, char *buf, int buf_size)
+{
+    int len, c;
+    char *q;
+
+    len = get_le16(pb);
+    q = buf;
+    while (len > 0) {
+        c = get_le16(pb);
+        if ((q - buf) < buf_size - 1)
+            *q++ = c;
+        len--;
+    }
+    *q = '\0';
+}
+#endif
+
+static char *getlocale()
+{
+    char *str;
+
+    str = strstr(getenv("LANG"), ".");
+    if(str)
+        *str++;
+    else
+        str = "US-ASCII";
+
+    return str;
+}
+
+static void tag_recode(char *before, unsigned int len)
+{
+       int result;
+       iconv_t frt;
+       char ansb[len];
+       char ansa[len];
+       char *ansbptr = ansb;
+       char *ansaptr = ansa;
+       unsigned int len1 = 2 * len;
+       unsigned int length = len;
+
+       memcpy(ansb, before, len);
+       frt = iconv_open(getlocale(), "UNICODE");
+       if (frt == (iconv_t) - 1)
+       {
+           return;
+       }
+       result = iconv(frt, &ansbptr, &len, &ansaptr, &len1);
+       if (result == (size_t) - 1)
+       {
+           return;
+       }
+       else
+           memcpy(before, ansa, length);
+       if (iconv_close(frt) != 0)
+	   if (iconv_close(frt) != 0)
+		return;
+       return;
+}
+
 static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size)
 {
-    int c;
+    int c, lenz;
     char *q;
 
     q = buf;
+    lenz = len;
     while (len > 0) {
-    	c = get_le16(pb);
-	if ((q - buf) < buf_size - 1)
-	*q++ = c;
-	len-=2;
-	}
-	   *q = '\0';
+        c = get_byte(pb);
+        if ((q - buf) < buf_size-1)
+            *q++ = c;
+        len--;
+    }
+    tag_recode(buf, lenz);
 }
 
 static int asf_probe(AVProbeData *pd)
@@ -404,7 +957,7 @@
             st = av_new_stream(s, 0);
             if (!st)
                 goto fail;
-            asf_st = malloc(sizeof(ASFStream));
+            asf_st = av_mallocz(sizeof(ASFStream));
             if (!asf_st)
                 goto fail;
             st->priv_data = asf_st;
@@ -414,6 +967,8 @@
             get_guid(pb, &g);
             if (!memcmp(&g, &audio_stream, sizeof(GUID))) {
                 type = CODEC_TYPE_AUDIO;
+            } else if (!memcmp(&g, &video_stream, sizeof(GUID))) {
+                type = CODEC_TYPE_VIDEO;
             } else {
                 goto fail;
             }
@@ -451,6 +1006,9 @@
 			asf_st->ds_span = 0; // disable descrambling
 		}
                 switch (st->codec.codec_id) {
+                case CODEC_ID_MP3:
+                    st->codec.frame_size = MPA_FRAME_SIZE;
+                    break;
                 case CODEC_ID_PCM_S16LE:
                 case CODEC_ID_PCM_S16BE:
                 case CODEC_ID_PCM_U16LE:
@@ -467,6 +1025,45 @@
                     break;
                 }
 	    }
+#if 0
+	    } else {
+		get_le32(pb);
+                get_le32(pb);
+                get_byte(pb);
+                size = get_le16(pb); /* size */
+                get_le32(pb); /* size */
+                st->codec.width = get_le32(pb);
+		st->codec.height = get_le32(pb);
+                /* not available for asf */
+                get_le16(pb); /* panes */
+		st->codec.bits_per_sample = get_le16(pb); /* depth */
+                tag1 = get_le32(pb);
+		url_fskip(pb, 20);
+		if (size > 40) {
+		    st->codec.extradata_size = size - 40;
+		    st->codec.extradata = av_mallocz(st->codec.extradata_size);
+		    get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
+		}
+
+        /* Extract palette from extradata if bpp <= 8 */
+        /* This code assumes that extradata contains only palette */
+        /* This is true for all paletted codecs implemented in ffmpeg */
+        if (st->codec.extradata_size && (st->codec.bits_per_sample <= 8)) {
+            st->codec.palctrl = av_mallocz(sizeof(AVPaletteControl));
+#ifdef WORDS_BIGENDIAN
+            for (i = 0; i < FFMIN(st->codec.extradata_size, AVPALETTE_SIZE)/4; i++)
+                st->codec.palctrl->palette[i] = bswap_32(((uint32_t*)st->codec.extradata)[i]);
+#else
+            memcpy(st->codec.palctrl->palette, st->codec.extradata,
+                   FFMIN(st->codec.extradata_size, AVPALETTE_SIZE));
+#endif
+            st->codec.palctrl->palette_changed = 1;
+        }
+
+                st->codec.codec_tag = tag1;
+		st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
+            }
+#endif	    
             pos2 = url_ftell(pb);
             url_fskip(pb, gsize - (pos2 - pos1 + 24));
         } else if (!memcmp(&g, &data_header, sizeof(GUID))) {
@@ -494,18 +1091,18 @@
                         char *name, *value;
 
                         name_len = get_le16(pb);
-                        name = (char *)malloc(name_len);
+                        name = (char *)av_mallocz(name_len);
                         get_str16_nolen(pb, name_len, name, name_len);
                         value_type = get_le16(pb);
                         value_len = get_le16(pb);
                         if ((value_type == 0) || (value_type == 1)) // unicode or byte
                         {
-                                value = (char *)malloc(value_len);
+                                value = (char *)av_mallocz(value_len);
                                 get_str16_nolen(pb, value_len, value, value_len);
                                 if (strcmp(name,"WM/AlbumTitle")==0) { strcpy(s->album, value); }
                                 if (strcmp(name,"WM/Genre")==0) { strcpy(s->genre, value); }
                                 if (strcmp(name,"WM/Year")==0) s->year = atoi(value);
-                                free(value);
+                                av_free(value);
                         }
                         if ((value_type >= 2) || (value_type <= 5)) // boolean or DWORD or QWORD or WORD
                         {
@@ -516,8 +1113,38 @@
                                 if (strcmp(name,"WM/Track")==0) s->track = value_num + 1;
                                 if (strcmp(name,"WM/TrackNumber")==0) s->track = value_num;
                         }
-                        free(name);
+                        av_free(name);
                 }
+#if 0
+        } else if (!memcmp(&g, &head1_guid, sizeof(GUID))) {
+            int v1, v2;
+            get_guid(pb, &g);
+            v1 = get_le32(pb);
+            v2 = get_le16(pb);
+        } else if (!memcmp(&g, &codec_comment_header, sizeof(GUID))) {
+            int len, v1, n, num;
+            char str[256], *q;
+            char tag[16];
+
+            get_guid(pb, &g);
+            print_guid(&g);
+
+            n = get_le32(pb);
+            for(i=0;i<n;i++) {
+                num = get_le16(pb); /* stream number */
+                get_str16(pb, str, sizeof(str));
+                get_str16(pb, str, sizeof(str));
+                len = get_le16(pb);
+                q = tag;
+                while (len > 0) {
+                    v1 = get_byte(pb);
+                    if ((q - tag) < sizeof(tag) - 1)
+                        *q++ = v1;
+                    len--;
+                }
+                *q = '\0';
+            }
+#endif
         } else if (url_feof(pb)) {
             goto fail;
         } else {
@@ -539,10 +1166,10 @@
      for(i=0;i<s->nb_streams;i++) {
         AVStream *st = s->streams[i];
 	if (st) {
-	    free(st->priv_data);
-            free(st->codec.extradata);
+	    av_free(st->priv_data);
+            av_free(st->codec.extradata);
 	}
-        free(st);
+        av_free(st);
     }
     return -1;
 }
@@ -765,7 +1392,7 @@
 	    /* return packet */
 	    if (asf_st->ds_span > 1) {
 		/* packet descrambling */
-		char* newdata = malloc(asf_st->pkt.size);
+		unsigned char* newdata = av_malloc(asf_st->pkt.size);
 		if (newdata) {
 		    int offset = 0;
 		    while (offset < asf_st->pkt.size) {
@@ -779,7 +1406,7 @@
 			       asf_st->ds_chunk_size);
 			offset += asf_st->ds_chunk_size;
 		    }
-		    free(asf_st->pkt.data);
+		    av_free(asf_st->pkt.data);
 		    asf_st->pkt.data = newdata;
 		}
 	    }
@@ -800,9 +1427,9 @@
 
     for(i=0;i<s->nb_streams;i++) {
 	AVStream *st = s->streams[i];
-	free(st->priv_data);
-	free(st->codec.extradata);
-    	free(st->codec.palctrl);
+	av_free(st->priv_data);
+	av_free(st->codec.extradata);
+    av_free(st->codec.palctrl);
     }
     return 0;
 }
@@ -922,6 +1549,10 @@
         if(e->timestamp <= pts){
             pos_min= e->pos;
             pts_min= e->timestamp;
+#ifdef DEBUG_SEEK
+        printf("unsing cached pos_min=0x%llx dts_min=%0.3f\n", 
+               pos_min,pts_min / 90000.0);
+#endif
         }else{
             assert(index==0);
         }
@@ -932,6 +1563,10 @@
             pos_max= e->pos;
             pts_max= e->timestamp;
             pos_limit= pos_max - e->min_distance;
+#ifdef DEBUG_SEEK
+        printf("unsing cached pos_max=0x%llx dts_max=%0.3f\n", 
+               pos_max,pts_max / 90000.0);
+#endif
         }
     }
 
@@ -977,6 +1612,9 @@
         else
             no_change=0;
 
+#ifdef DEBUG_SEEK
+printf("%Ld %Ld %Ld / %Ld %Ld %Ld target:%Ld limit:%Ld start:%Ld\n", pos_min, pos, pos_max, pts_min, cur_pts, pts_max, pts, pos_limit, start_pos);
+#endif
         assert (cur_pts != AV_NOPTS_VALUE);
         if (pts < cur_pts) {
             pos_limit = start_pos - 1;
@@ -1007,9 +1645,48 @@
     asf_read_seek,
 };
 
+#ifdef CONFIG_ENCODERS
+static AVOutputFormat asf_oformat = {
+    "asf",
+    "asf format",
+    "video/x-ms-asf",
+    "asf,wmv",
+    sizeof(ASFContext),
+#ifdef CONFIG_MP3LAME
+    CODEC_ID_MP3,
+#else
+    CODEC_ID_MP2,
+#endif
+    CODEC_ID_MSMPEG4V3,
+    asf_write_header,
+    asf_write_packet,
+    asf_write_trailer,
+};
+
+static AVOutputFormat asf_stream_oformat = {
+    "asf_stream",
+    "asf format",
+    "video/x-ms-asf",
+    "asf,wmv",
+    sizeof(ASFContext),
+#ifdef CONFIG_MP3LAME
+    CODEC_ID_MP3,
+#else
+    CODEC_ID_MP2,
+#endif
+    CODEC_ID_MSMPEG4V3,
+    asf_write_stream_header,
+    asf_write_packet,
+    asf_write_trailer,
+};
+#endif //CONFIG_ENCODERS
+
 int asf_init(void)
 {
     av_register_input_format(&asf_iformat);
-    
+#ifdef CONFIG_ENCODERS
+    av_register_output_format(&asf_oformat);
+    av_register_output_format(&asf_stream_oformat);
+#endif //CONFIG_ENCODERS
     return 0;
 }
--- a/Plugins/Input/wma/libffwma/avcodec.h	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/avcodec.h	Sat Nov 19 14:42:28 2005 -0800
@@ -12,6 +12,7 @@
 #endif
 
 #include "common.h"
+//#include "rational.h"
 #include <sys/types.h> /* size_t */
 
 #define FFMPEG_VERSION_INT     0x000408
@@ -27,9 +28,73 @@
 
 enum CodecID {
     CODEC_ID_NONE, 
+    CODEC_ID_MPEG1VIDEO,
+    CODEC_ID_MPEG2VIDEO, /* prefered ID for MPEG Video 1 or 2 decoding */
+    CODEC_ID_MPEG2VIDEO_XVMC,
+    CODEC_ID_H263,
+    CODEC_ID_RV10,
+    CODEC_ID_RV20,
+    CODEC_ID_MP2,
+    CODEC_ID_MP3, /* prefered ID for MPEG Audio layer 1, 2 or3 decoding */
+    CODEC_ID_VORBIS,
+    CODEC_ID_AC3,
+    CODEC_ID_MJPEG,
+    CODEC_ID_MJPEGB,
+    CODEC_ID_LJPEG,
+    CODEC_ID_SP5X,
+    CODEC_ID_MPEG4,
+    CODEC_ID_RAWVIDEO,
+    CODEC_ID_MSMPEG4V1,
+    CODEC_ID_MSMPEG4V2,
+    CODEC_ID_MSMPEG4V3,
+    CODEC_ID_WMV1,
+    CODEC_ID_WMV2,
+    CODEC_ID_H263P,
+    CODEC_ID_H263I,
+    CODEC_ID_FLV1,
+    CODEC_ID_SVQ1,
+    CODEC_ID_SVQ3,
+    CODEC_ID_DVVIDEO,
+    CODEC_ID_DVAUDIO,
     CODEC_ID_WMAV1,
     CODEC_ID_WMAV2,
-    
+    CODEC_ID_MACE3,
+    CODEC_ID_MACE6,
+    CODEC_ID_HUFFYUV,
+    CODEC_ID_CYUV,
+    CODEC_ID_H264,
+    CODEC_ID_INDEO3,
+    CODEC_ID_VP3,
+    CODEC_ID_THEORA,
+    CODEC_ID_AAC,
+    CODEC_ID_MPEG4AAC,
+    CODEC_ID_ASV1,
+    CODEC_ID_ASV2,
+    CODEC_ID_FFV1,
+    CODEC_ID_4XM,
+    CODEC_ID_VCR1,
+    CODEC_ID_CLJR,
+    CODEC_ID_MDEC,
+    CODEC_ID_ROQ,
+    CODEC_ID_INTERPLAY_VIDEO,
+    CODEC_ID_XAN_WC3,
+    CODEC_ID_XAN_WC4,
+    CODEC_ID_RPZA,
+    CODEC_ID_CINEPAK,
+    CODEC_ID_WS_VQA,
+    CODEC_ID_MSRLE,
+    CODEC_ID_MSVIDEO1,
+    CODEC_ID_IDCIN,
+    CODEC_ID_8BPS,
+    CODEC_ID_SMC,
+    CODEC_ID_FLIC,
+    CODEC_ID_TRUEMOTION1,
+    CODEC_ID_VMDVIDEO,
+    CODEC_ID_VMDAUDIO,
+    CODEC_ID_MSZH,
+    CODEC_ID_ZLIB,
+    CODEC_ID_QTRLE,
+
     /* various pcm "codecs" */
     CODEC_ID_PCM_S16LE,
     CODEC_ID_PCM_S16BE,
@@ -39,15 +104,65 @@
     CODEC_ID_PCM_U8,
     CODEC_ID_PCM_MULAW,
     CODEC_ID_PCM_ALAW,
+
+    /* various adpcm codecs */
+    CODEC_ID_ADPCM_IMA_QT,
+    CODEC_ID_ADPCM_IMA_WAV,
+    CODEC_ID_ADPCM_IMA_DK3,
+    CODEC_ID_ADPCM_IMA_DK4,
+    CODEC_ID_ADPCM_IMA_WS,
+    CODEC_ID_ADPCM_IMA_SMJPEG,
+    CODEC_ID_ADPCM_MS,
+    CODEC_ID_ADPCM_4XM,
+    CODEC_ID_ADPCM_XA,
+    CODEC_ID_ADPCM_ADX,
+    CODEC_ID_ADPCM_EA,
+
+	/* AMR */
+    CODEC_ID_AMR_NB,
+    CODEC_ID_AMR_WB,
+
+    /* RealAudio codecs*/
+    CODEC_ID_RA_144,
+    CODEC_ID_RA_288,
+
+    /* various DPCM codecs */
+    CODEC_ID_ROQ_DPCM,
+    CODEC_ID_INTERPLAY_DPCM,
+    CODEC_ID_XAN_DPCM,
+    
+    CODEC_ID_MPEG2TS, /* _FAKE_ codec to indicate a raw MPEG2 transport
+                         stream (only used by libavformat) */
 };
 
+/* CODEC_ID_MP3LAME is absolete */
+#define CODEC_ID_MP3LAME CODEC_ID_MP3
 
 enum CodecType {
     CODEC_TYPE_UNKNOWN = -1,
+    CODEC_TYPE_VIDEO,
     CODEC_TYPE_AUDIO,
     CODEC_TYPE_DATA,
 };
 
+/**
+ * Pixel format. Notes: 
+ *
+ * PIX_FMT_RGBA32 is handled in an endian-specific manner. A RGBA
+ * color is put together as:
+ *  (A << 24) | (R << 16) | (G << 8) | B
+ * This is stored as BGRA on little endian CPU architectures and ARGB on
+ * big endian CPUs.
+ *
+ * When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized
+ * image data is stored in AVFrame.data[0]. The palette is transported in
+ * AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is
+ * formatted the same as in PIX_FMT_RGBA32 described above (i.e., it is
+ * also endian-specific). Note also that the individual RGB palette
+ * components stored in AVFrame.data[1] should be in the range 0..255.
+ * This is important as many custom PAL8 video codecs that were designed
+ * to run on the IBM VGA graphics adapter use 6-bit palette components.
+ */
 enum PixelFormat {
     PIX_FMT_YUV420P,   ///< Planar YUV 4:2:0 (1 Cr & Cb sample per 2x2 Y samples)
     PIX_FMT_YUV422,    
@@ -1488,8 +1603,105 @@
 
 } AVPaletteControl;
 
+extern AVCodec ac3_encoder;
+extern AVCodec mp2_encoder;
+extern AVCodec mp3lame_encoder;
+extern AVCodec oggvorbis_encoder;
+extern AVCodec faac_encoder;
+extern AVCodec mpeg1video_encoder;
+extern AVCodec mpeg2video_encoder;
+extern AVCodec h263_encoder;
+extern AVCodec h263p_encoder;
+extern AVCodec flv_encoder;
+extern AVCodec rv10_encoder;
+extern AVCodec rv20_encoder;
+extern AVCodec mjpeg_encoder;
+extern AVCodec ljpeg_encoder;
+extern AVCodec mpeg4_encoder;
+extern AVCodec msmpeg4v1_encoder;
+extern AVCodec msmpeg4v2_encoder;
+extern AVCodec msmpeg4v3_encoder;
+extern AVCodec wmv1_encoder;
+extern AVCodec wmv2_encoder;
+extern AVCodec huffyuv_encoder;
+extern AVCodec h264_encoder;
+extern AVCodec asv1_encoder;
+extern AVCodec asv2_encoder;
+extern AVCodec vcr1_encoder;
+extern AVCodec ffv1_encoder;
+extern AVCodec mdec_encoder;
+extern AVCodec zlib_encoder;
+
+extern AVCodec h263_decoder;
+extern AVCodec mpeg4_decoder;
+extern AVCodec msmpeg4v1_decoder;
+extern AVCodec msmpeg4v2_decoder;
+extern AVCodec msmpeg4v3_decoder;
+extern AVCodec wmv1_decoder;
+extern AVCodec wmv2_decoder;
+extern AVCodec mpeg1video_decoder;
+extern AVCodec mpeg2video_decoder;
+extern AVCodec mpegvideo_decoder;
+extern AVCodec mpeg_xvmc_decoder;
+extern AVCodec h263i_decoder;
+extern AVCodec flv_decoder;
+extern AVCodec rv10_decoder;
+extern AVCodec rv20_decoder;
+extern AVCodec svq1_decoder;
+extern AVCodec svq3_decoder;
+extern AVCodec dvvideo_decoder;
 extern AVCodec wmav1_decoder;
 extern AVCodec wmav2_decoder;
+extern AVCodec mjpeg_decoder;
+extern AVCodec mjpegb_decoder;
+extern AVCodec sp5x_decoder;
+extern AVCodec mp2_decoder;
+extern AVCodec mp3_decoder;
+extern AVCodec mace3_decoder;
+extern AVCodec mace6_decoder;
+extern AVCodec huffyuv_decoder;
+extern AVCodec oggvorbis_decoder;
+extern AVCodec cyuv_decoder;
+extern AVCodec h264_decoder;
+extern AVCodec indeo3_decoder;
+extern AVCodec vp3_decoder;
+extern AVCodec theora_decoder;
+extern AVCodec amr_nb_decoder;
+extern AVCodec amr_nb_encoder;
+extern AVCodec amr_wb_encoder;
+extern AVCodec amr_wb_decoder;
+extern AVCodec aac_decoder;
+extern AVCodec mpeg4aac_decoder;
+extern AVCodec asv1_decoder;
+extern AVCodec asv2_decoder;
+extern AVCodec vcr1_decoder;
+extern AVCodec cljr_decoder;
+extern AVCodec ffv1_decoder;
+extern AVCodec fourxm_decoder;
+extern AVCodec mdec_decoder;
+extern AVCodec roq_decoder;
+extern AVCodec interplay_video_decoder;
+extern AVCodec xan_wc3_decoder;
+extern AVCodec rpza_decoder;
+extern AVCodec cinepak_decoder;
+extern AVCodec msrle_decoder;
+extern AVCodec msvideo1_decoder;
+extern AVCodec vqa_decoder;
+extern AVCodec idcin_decoder;
+extern AVCodec eightbps_decoder;
+extern AVCodec smc_decoder;
+extern AVCodec flic_decoder;
+extern AVCodec vmdvideo_decoder;
+extern AVCodec vmdaudio_decoder;
+extern AVCodec truemotion1_decoder;
+extern AVCodec mszh_decoder;
+extern AVCodec zlib_decoder;
+extern AVCodec ra_144_decoder;
+extern AVCodec ra_288_decoder;
+extern AVCodec roq_dpcm_decoder;
+extern AVCodec interplay_dpcm_decoder;
+extern AVCodec xan_dpcm_decoder;
+extern AVCodec qtrle_decoder;
 
 /* pcm codecs */
 #define PCM_CODEC(id, name) \
@@ -1521,7 +1733,12 @@
 
 #undef PCM_CODEC
 
+/* dummy raw video codec */
+extern AVCodec rawvideo_encoder;
+extern AVCodec rawvideo_decoder;
 
+/* the following codecs use external GPL libs */
+extern AVCodec ac3_decoder;
 
 /* resample.c */
 
@@ -1564,6 +1781,14 @@
  */
 int avpicture_alloc(AVPicture *picture, int pix_fmt, int width, int height);
 
+/* Free a picture previously allocated by avpicture_alloc. */
+void avpicture_free(AVPicture *picture);
+
+int avpicture_fill(AVPicture *picture, uint8_t *ptr,
+                   int pix_fmt, int width, int height);
+int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
+                     unsigned char *dest, int dest_size);
+int avpicture_get_size(int pix_fmt, int width, int height);
 void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
 const char *avcodec_get_pix_fmt_name(int pix_fmt);
 enum PixelFormat avcodec_get_pix_fmt(const char* name);
@@ -1628,11 +1853,16 @@
 int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, 
                          int *frame_size_ptr,
                          uint8_t *buf, int buf_size);
+int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, 
+                         int *got_picture_ptr,
+                         uint8_t *buf, int buf_size);
 int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata, 
                         int *data_size_ptr,
                         uint8_t *buf, int buf_size);
 int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, 
                          const short *samples);
+int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, 
+                         const AVFrame *pict);
 
 int avcodec_close(AVCodecContext *avctx);
 
@@ -1793,7 +2023,12 @@
 extern AVCodecParser mpegaudio_parser;
 extern AVCodecParser ac3_parser;
 
-/*char *av_strdup(const char *s);*/
+/* memory */
+void *av_malloc(unsigned int size);
+void *av_mallocz(unsigned int size);
+void *av_realloc(void *ptr, unsigned int size);
+void av_free(void *ptr);
+char *av_strdup(const char *s);
 void __av_freep(void **ptr);
 #define av_freep(p) __av_freep((void **)(p))
 void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
--- a/Plugins/Input/wma/libffwma/avio.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/avio.c	Sat Nov 19 14:42:28 2005 -0800
@@ -68,7 +68,7 @@
     err = -ENOENT;
     goto fail;
  found:
-    uc = malloc(sizeof(URLContext) + strlen(filename));
+    uc = av_malloc(sizeof(URLContext) + strlen(filename));
     if (!uc) {
         err = -ENOMEM;
         goto fail;
@@ -80,7 +80,7 @@
     uc->max_packet_size = 0; /* default: stream file */
     err = up->url_open(uc, filename, flags);
     if (err < 0) {
-        free(uc);
+        av_free(uc);
         *puc = NULL;
         return err;
     }
@@ -100,6 +100,20 @@
     return ret;
 }
 
+#ifdef CONFIG_ENCODERS
+int url_write(URLContext *h, unsigned char *buf, int size)
+{
+    int ret;
+    if (!(h->flags & (URL_WRONLY | URL_RDWR)))
+        return -EIO;
+    /* avoid sending too big packets */
+    if (h->max_packet_size && size > h->max_packet_size)
+        return -EIO; 
+    ret = h->prot->url_write(h, buf, size);
+    return ret;
+}
+#endif //CONFIG_ENCODERS
+
 offset_t url_seek(URLContext *h, offset_t pos, int whence)
 {
     offset_t ret;
@@ -112,12 +126,11 @@
 
 int url_close(URLContext *h)
 {
-	int ret;
+    int ret;
 
-    	ret = h->prot->url_close(h);
-    	free(h);
-    
-	return ret;
+    ret = h->prot->url_close(h);
+    av_free(h);
+    return ret;
 }
 
 int url_exist(const char *filename)
--- a/Plugins/Input/wma/libffwma/aviobuf.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/aviobuf.c	Sat Nov 19 14:42:28 2005 -0800
@@ -18,6 +18,7 @@
  */
 #include "avformat.h"
 #include "avio.h"
+#include "avcodec.h"
 #include <stdarg.h>
 
 #define IO_BUFFER_SIZE 32768
@@ -51,13 +52,82 @@
     return 0;
 }
                   
+
+#ifdef CONFIG_ENCODERS
+static void flush_buffer(ByteIOContext *s)
+{
+    if (s->buf_ptr > s->buffer) {
+        if (s->write_packet)
+            s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer);
+        s->pos += s->buf_ptr - s->buffer;
+    }
+    s->buf_ptr = s->buffer;
+}
+
+void put_byte(ByteIOContext *s, int b)
+{
+    *(s->buf_ptr)++ = b;
+    if (s->buf_ptr >= s->buf_end) 
+        flush_buffer(s);
+}
+
+void put_buffer(ByteIOContext *s, const unsigned char *buf, int size)
+{
+    int len;
+
+    while (size > 0) {
+        len = (s->buf_end - s->buf_ptr);
+        if (len > size)
+            len = size;
+        memcpy(s->buf_ptr, buf, len);
+        s->buf_ptr += len;
+
+        if (s->buf_ptr >= s->buf_end) 
+            flush_buffer(s);
+
+        buf += len;
+        size -= len;
+    }
+}
+
+void put_flush_packet(ByteIOContext *s)
+{
+    flush_buffer(s);
+    s->must_flush = 0;
+}
+#endif //CONFIG_ENCODERS
+
 offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence)
 {
     offset_t offset1;
 
     if (whence != SEEK_CUR && whence != SEEK_SET)
         return -EINVAL;
-   
+    
+#ifdef CONFIG_ENCODERS
+    if (s->write_flag) {
+        if (whence == SEEK_CUR) {
+            offset1 = s->pos + (s->buf_ptr - s->buffer);
+            if (offset == 0)
+                return offset1;
+            offset += offset1;
+        }
+        offset1 = offset - s->pos;
+        if (!s->must_flush && 
+            offset1 >= 0 && offset1 < (s->buf_end - s->buffer)) {
+            /* can do the seek inside the buffer */
+            s->buf_ptr = s->buffer + offset1;
+        } else {
+            if (!s->seek)
+                return -EPIPE;
+            flush_buffer(s);
+            s->must_flush = 1;
+            s->buf_ptr = s->buffer;
+            s->seek(s->opaque, offset, SEEK_SET);
+            s->pos = offset;
+        }
+    } else 
+#endif //CONFIG_ENCODERS
     {
         if (whence == SEEK_CUR) {
             offset1 = s->pos - (s->buf_end - s->buffer) + (s->buf_ptr - s->buffer);
@@ -97,6 +167,74 @@
     return s->eof_reached;
 }
 
+#ifdef CONFIG_ENCODERS
+void put_le32(ByteIOContext *s, unsigned int val)
+{
+    put_byte(s, val);
+    put_byte(s, val >> 8);
+    put_byte(s, val >> 16);
+    put_byte(s, val >> 24);
+}
+
+void put_be32(ByteIOContext *s, unsigned int val)
+{
+    put_byte(s, val >> 24);
+    put_byte(s, val >> 16);
+    put_byte(s, val >> 8);
+    put_byte(s, val);
+}
+
+/* IEEE format is assumed */
+void put_be64_double(ByteIOContext *s, double val)
+{
+    union {
+        double d;
+        uint64_t ull;
+    } u;
+    u.d = val;
+    put_be64(s, u.ull);
+}
+
+void put_strz(ByteIOContext *s, const char *str)
+{
+    if (str)
+        put_buffer(s, (const unsigned char *) str, strlen(str) + 1);
+    else
+        put_byte(s, 0);
+}
+
+void put_le64(ByteIOContext *s, uint64_t val)
+{
+    put_le32(s, (uint32_t)(val & 0xffffffff));
+    put_le32(s, (uint32_t)(val >> 32));
+}
+
+void put_be64(ByteIOContext *s, uint64_t val)
+{
+    put_be32(s, (uint32_t)(val >> 32));
+    put_be32(s, (uint32_t)(val & 0xffffffff));
+}
+
+void put_le16(ByteIOContext *s, unsigned int val)
+{
+    put_byte(s, val);
+    put_byte(s, val >> 8);
+}
+
+void put_be16(ByteIOContext *s, unsigned int val)
+{
+    put_byte(s, val >> 8);
+    put_byte(s, val);
+}
+
+void put_tag(ByteIOContext *s, const char *tag)
+{
+    while (*tag) {
+        put_byte(s, *tag++);
+    }
+}
+#endif //CONFIG_ENCODERS
+
 /* Input stream */
 
 static void fill_buffer(ByteIOContext *s)
@@ -252,7 +390,15 @@
 
 /* link with avio functions */
 
+#ifdef CONFIG_ENCODERS
+static void url_write_packet(void *opaque, uint8_t *buf, int buf_size)
+{
+    URLContext *h = opaque;
+    url_write(h, buf, buf_size);
+}
+#else
 #define	url_write_packet NULL
+#endif //CONFIG_ENCODERS
 
 static int url_read_packet(void *opaque, uint8_t *buf, int buf_size)
 {
@@ -279,14 +425,14 @@
     } else {
         buffer_size = IO_BUFFER_SIZE;
     }
-    buffer = malloc(buffer_size);
+    buffer = av_malloc(buffer_size);
     if (!buffer)
         return -ENOMEM;
 
     if (init_put_byte(s, buffer, buffer_size, 
                       (h->flags & URL_WRONLY) != 0, h,
                       url_read_packet, url_write_packet, url_seek_packet) < 0) {
-        free(buffer);
+        av_free(buffer);
         return -EIO;
     }
     s->is_streamed = h->is_streamed;
@@ -298,11 +444,11 @@
 int url_setbufsize(ByteIOContext *s, int buf_size)
 {
     uint8_t *buffer;
-    buffer = malloc(buf_size);
+    buffer = av_malloc(buf_size);
     if (!buffer)
         return -ENOMEM;
 
-    free(s->buffer);
+    av_free(s->buffer);
     s->buffer = buffer;
     s->buffer_size = buf_size;
     s->buf_ptr = buffer;
@@ -335,7 +481,7 @@
 {
     URLContext *h = s->opaque;
     
-    free(s->buffer);
+    av_free(s->buffer);
     memset(s, 0, sizeof(ByteIOContext));
     return url_close(h);
 }
@@ -345,6 +491,22 @@
     return s->opaque;
 }
 
+#ifdef CONFIG_ENCODERS
+/* XXX: currently size is limited */
+int url_fprintf(ByteIOContext *s, const char *fmt, ...)
+{
+    va_list ap;
+    char buf[4096];
+    int ret;
+
+    va_start(ap, fmt);
+    ret = vsnprintf(buf, sizeof(buf), fmt, ap);
+    va_end(ap);
+    put_buffer(s, buf, strlen(buf));
+    return ret;
+}
+#endif //CONFIG_ENCODERS
+
 /* note: unlike fgets, the EOL character is not returned and a whole
    line is parsed. return NULL if first char read was EOF */
 char *url_fgets(ByteIOContext *s, char *buf, int buf_size)
@@ -381,3 +543,158 @@
     return s->max_packet_size;
 }
 
+#ifdef CONFIG_ENCODERS
+/* buffer handling */
+int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags)
+{
+    return init_put_byte(s, buf, buf_size, 
+                         (flags & URL_WRONLY) != 0, NULL, NULL, NULL, NULL);
+}
+
+/* return the written or read size */
+int url_close_buf(ByteIOContext *s)
+{
+    put_flush_packet(s);
+    return s->buf_ptr - s->buffer;
+}
+
+/* output in a dynamic buffer */
+
+typedef struct DynBuffer {
+    int pos, size, allocated_size;
+    uint8_t *buffer;
+    int io_buffer_size;
+    uint8_t io_buffer[1];
+} DynBuffer;
+
+static void dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
+{
+    DynBuffer *d = opaque;
+    int new_size, new_allocated_size;
+    
+    /* reallocate buffer if needed */
+    new_size = d->pos + buf_size;
+    new_allocated_size = d->allocated_size;
+    while (new_size > new_allocated_size) {
+        if (!new_allocated_size)
+            new_allocated_size = new_size;
+        else
+            new_allocated_size = (new_allocated_size * 3) / 2 + 1;    
+    }
+    
+    if (new_allocated_size > d->allocated_size) {
+        d->buffer = av_realloc(d->buffer, new_allocated_size);
+        if(d->buffer == NULL)
+             return ;
+        d->allocated_size = new_allocated_size;
+    }
+    memcpy(d->buffer + d->pos, buf, buf_size);
+    d->pos = new_size;
+    if (d->pos > d->size)
+        d->size = d->pos;
+}
+
+static void dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
+{
+    unsigned char buf1[4];
+
+    /* packetized write: output the header */
+    buf1[0] = (buf_size >> 24);
+    buf1[1] = (buf_size >> 16);
+    buf1[2] = (buf_size >> 8);
+    buf1[3] = (buf_size);
+    dyn_buf_write(opaque, buf1, 4);
+
+    /* then the data */
+    dyn_buf_write(opaque, buf, buf_size);
+}
+
+static int dyn_buf_seek(void *opaque, offset_t offset, int whence)
+{
+    DynBuffer *d = opaque;
+
+    if (whence == SEEK_CUR)
+        offset += d->pos;
+    else if (whence == SEEK_END)
+        offset += d->size;
+    if (offset < 0 || offset > 0x7fffffffLL)
+        return -1;
+    d->pos = offset;
+    return 0;
+}
+
+static int url_open_dyn_buf_internal(ByteIOContext *s, int max_packet_size)
+{
+    DynBuffer *d;
+    int io_buffer_size, ret;
+    
+    if (max_packet_size) 
+        io_buffer_size = max_packet_size;
+    else
+        io_buffer_size = 1024;
+        
+    d = av_malloc(sizeof(DynBuffer) + io_buffer_size);
+    if (!d)
+        return -1;
+    d->io_buffer_size = io_buffer_size;
+    d->buffer = NULL;
+    d->pos = 0;
+    d->size = 0;
+    d->allocated_size = 0;
+    ret = init_put_byte(s, d->io_buffer, io_buffer_size, 
+                        1, d, NULL, 
+                        max_packet_size ? dyn_packet_buf_write : dyn_buf_write, 
+                        max_packet_size ? NULL : dyn_buf_seek);
+    if (ret == 0) {
+        s->max_packet_size = max_packet_size;
+    }
+    return ret;
+}
+
+/*
+ * Open a write only memory stream.
+ * 
+ * @param s new IO context
+ * @return zero if no error.
+ */
+int url_open_dyn_buf(ByteIOContext *s)
+{
+    return url_open_dyn_buf_internal(s, 0);
+}
+
+/*
+ * Open a write only packetized memory stream with a maximum packet
+ * size of 'max_packet_size'.  The stream is stored in a memory buffer
+ * with a big endian 4 byte header giving the packet size in bytes.
+ * 
+ * @param s new IO context
+ * @param max_packet_size maximum packet size (must be > 0) 
+ * @return zero if no error.
+ */
+int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size)
+{
+    if (max_packet_size <= 0)
+        return -1;
+    return url_open_dyn_buf_internal(s, max_packet_size);
+}
+
+/* 
+ * Return the written size and a pointer to the buffer. The buffer
+ *  must be freed with av_free(). 
+ * @param s IO context
+ * @param pointer to a byte buffer
+ * @return the length of the byte buffer
+ */
+int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer)
+{
+    DynBuffer *d = s->opaque;
+    int size;
+
+    put_flush_packet(s);
+
+    *pbuffer = d->buffer;
+    size = d->size;
+    av_free(d);
+    return size;
+}
+#endif //CONFIG_ENCODERS
--- a/Plugins/Input/wma/libffwma/common.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/common.c	Sat Nov 19 14:42:28 2005 -0800
@@ -2,7 +2,6 @@
  * Common bit i/o utils
  * Copyright (c) 2000, 2001 Fabrice Bellard.
  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- * Copyright (c) 2004 Roman Bogorodskiy (bmp-wma specific stuff)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -50,11 +49,74 @@
 {
     s->buf = buffer;
     s->buf_end = s->buf + buffer_size;
+#ifdef ALT_BITSTREAM_WRITER
+    s->index=0;
+    ((uint32_t*)(s->buf))[0]=0;
+//    memset(buffer, 0, buffer_size);
+#else
     s->buf_ptr = s->buf;
     s->bit_left=32;
     s->bit_buf=0;
+#endif
 }
 
+//#ifdef CONFIG_ENCODERS
+#if 1
+
+/* return the number of bits output */
+int get_bit_count(PutBitContext *s)
+{
+#ifdef ALT_BITSTREAM_WRITER
+    return s->index;
+#else
+    return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
+#endif
+}
+
+void align_put_bits(PutBitContext *s)
+{
+#ifdef ALT_BITSTREAM_WRITER
+    put_bits(s,(  - s->index) & 7,0);
+#else
+    put_bits(s,s->bit_left & 7,0);
+#endif
+}
+
+#endif //CONFIG_ENCODERS
+
+/* pad the end of the output stream with zeros */
+void flush_put_bits(PutBitContext *s)
+{
+#ifdef ALT_BITSTREAM_WRITER
+    align_put_bits(s);
+#else
+    s->bit_buf<<= s->bit_left;
+    while (s->bit_left < 32) {
+        /* XXX: should test end of buffer */
+        *s->buf_ptr++=s->bit_buf >> 24;
+        s->bit_buf<<=8;
+        s->bit_left+=8;
+    }
+    s->bit_left=32;
+    s->bit_buf=0;
+#endif
+}
+
+#ifdef CONFIG_ENCODERS
+
+void put_string(PutBitContext * pbc, char *s)
+{
+    while(*s){
+        put_bits(pbc, 8, *s);
+        s++;
+    }
+    put_bits(pbc, 8, 0);
+}
+
+/* bit input functions */
+
+#endif //CONFIG_ENCODERS
+
 /**
  * init GetBitContext.
  * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
@@ -169,7 +231,7 @@
     vlc->table_size += size;
     if (vlc->table_size > vlc->table_allocated) {
         vlc->table_allocated += (1 << vlc->bits);
-        vlc->table = realloc(vlc->table,
+        vlc->table = av_realloc(vlc->table,
                                 sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
         if (!vlc->table)
             return -1;
@@ -189,7 +251,10 @@
 
     table_size = 1 << table_nb_bits;
     table_index = alloc_table(vlc, table_size);
-    
+#ifdef DEBUG_VLC
+    printf("new table index=%d size=%d code_prefix=%x n=%d\n",
+           table_index, table_size, code_prefix, n_prefix);
+#endif
     if (table_index < 0)
         return -1;
     table = &vlc->table[table_index];
@@ -206,6 +271,9 @@
         /* we accept tables with holes */
         if (n <= 0)
             continue;
+#if defined(DEBUG_VLC) && 0
+        printf("i=%d n=%d code=0x%x\n", i, n, code);
+#endif
         /* if code matches the prefix, it is in the table */
         n -= n_prefix;
         if (n > 0 && (code >> n) == code_prefix) {
@@ -214,6 +282,10 @@
                 j = (code << (table_nb_bits - n)) & (table_size - 1);
                 nb = 1 << (table_nb_bits - n);
                 for(k=0;k<nb;k++) {
+#ifdef DEBUG_VLC
+                    av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n",
+                           j, i, n);
+#endif
                     if (table[j][1] /*bits*/ != 0) {
                         av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");
                         av_abort();
@@ -225,6 +297,10 @@
             } else {
                 n -= table_nb_bits;
                 j = (code >> n) & ((1 << table_nb_bits) - 1);
+#ifdef DEBUG_VLC
+                printf("%4x: n=%d (subtable)\n",
+                       j, n);
+#endif
                 /* compute table size */
                 n1 = -table[j][1]; //bits
                 if (n > n1)
@@ -288,12 +364,15 @@
     vlc->table = NULL;
     vlc->table_allocated = 0;
     vlc->table_size = 0;
+#ifdef DEBUG_VLC
+    printf("build table nb_codes=%d\n", nb_codes);
+#endif
 
     if (build_table(vlc, nb_bits, nb_codes,
                     bits, bits_wrap, bits_size,
                     codes, codes_wrap, codes_size,
                     0, 0) < 0) {
-        free(vlc->table);
+        av_free(vlc->table);
         return -1;
     }
     return 0;
@@ -302,7 +381,7 @@
 
 void free_vlc(VLC *vlc)
 {
-	free(vlc->table);
+    av_free(vlc->table);
 }
 
 int64_t ff_gcd(int64_t a, int64_t b){
--- a/Plugins/Input/wma/libffwma/common.h	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/common.h	Sat Nov 19 14:42:28 2005 -0800
@@ -6,40 +6,35 @@
 #ifndef COMMON_H
 #define COMMON_H
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
+#define HAVE_AV_CONFIG_H
+
+#if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
+#    define CONFIG_WIN32
 #endif
 
-#define TUNECPU generic
-#undef HAVE_MMX
-#define __CPU__ 586
-#define HAVE_BUILTIN_VECTOR 1
-#define CONFIG_DECODERS 1
-/*#define CONFIG_HAVE_DLOPEN 1
-#define CONFIG_HAVE_DLFCN 1*/
-/*#undef CONFIG_AUDIO_OSS*/
-#define SIMPLE_IDCT 1
-/*#undef CONFIG_FFSERVER*/
-#define CONFIG_RISKY 1
+//#define ALT_BITSTREAM_WRITER
+//#define ALIGNED_BITSTREAM_WRITER
 
 #define ALT_BITSTREAM_READER
 //#define LIBMPEG2_BITSTREAM_READER
 //#define A32_BITSTREAM_READER
-//#define LIBMPEG2_BITSTREAM_READER_HACK //add BERO
+#define LIBMPEG2_BITSTREAM_READER_HACK //add BERO
 
 #ifndef M_PI
 #define M_PI    3.14159265358979323846
 #endif
 
-#if 1
-/* only include the following when compiling package */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <errno.h>
-#include <math.h>
+#ifdef HAVE_AV_CONFIG_H
+#    include <stdlib.h>
+#    include <stdio.h>
+#    include <string.h>
+#    include <ctype.h>
+#    ifndef __BEOS__
+#        include <errno.h>
+#    else
+#        include "berrno.h"
+#    endif
+#    include <math.h>
 
 #    ifndef ENODATA
 #        define ENODATA  61
@@ -66,12 +61,6 @@
 #define AVOPTION_END() AVOPTION_SUB(NULL)
 
 struct AVOption;
-#ifdef HAVE_MMX
-extern const struct AVOption avoptions_common[3 + 5];
-#else
-extern const struct AVOption avoptions_common[3];
-#endif
-extern const struct AVOption avoptions_workaround_bug[11];
 
 #endif /* HAVE_AV_CONFIG_H */
 
@@ -95,8 +84,14 @@
     typedef unsigned char  uint8_t;
     typedef unsigned short uint16_t;
     typedef unsigned int   uint32_t;
-    typedef signed long long   int64_t;
-    typedef unsigned long long uint64_t;
+
+#   ifdef CONFIG_WIN32
+        typedef signed __int64   int64_t;
+        typedef unsigned __int64 uint64_t;
+#   else /* other OS */
+        typedef signed long long   int64_t;
+        typedef unsigned long long uint64_t;
+#   endif /* other OS */
 #endif /* HAVE_INTTYPES_H */
 
 #ifndef INT64_MAX
@@ -113,21 +108,68 @@
 typedef unsigned int  uint_fast32_t;
 #endif
 
-#if 1
+#if defined(CONFIG_OS2) || defined(CONFIG_SUNOS)
+static inline float floorf(float f) { 
+    return floor(f); 
+}
+#endif
+
+#ifdef CONFIG_WIN32
+
+/* windows */
+
+#    ifndef __MINGW32__
+#        define int64_t_C(c)     (c ## i64)
+#        define uint64_t_C(c)    (c ## i64)
+
+#    ifdef HAVE_AV_CONFIG_H
+#            define inline __inline
+#    endif
+
+#    else
+#        define int64_t_C(c)     (c ## LL)
+#        define uint64_t_C(c)    (c ## ULL)
+#    endif /* __MINGW32__ */
+
+#    ifdef HAVE_AV_CONFIG_H
+#        ifdef _DEBUG
+#            define DEBUG
+#        endif
+
+#        define snprintf _snprintf
+#        define vsnprintf _vsnprintf
+#    endif
+
+/* CONFIG_WIN32 end */
+#elif defined (CONFIG_OS2)
+/* OS/2 EMX */
+
+#ifndef int64_t_C
+#define int64_t_C(c)     (c ## LL)
+#define uint64_t_C(c)    (c ## ULL)
+#endif
+
+#ifdef HAVE_AV_CONFIG_H
+
+#ifdef USE_FASTMEMCPY
+#include "fastmemcpy.h"
+#endif
 
 #include <float.h>
 
 #endif /* HAVE_AV_CONFIG_H */
 
 /* CONFIG_OS2 end */
+#else
 
 /* unix */
 
 #ifndef int64_t_C
 #define int64_t_C(c)     (c ## LL)
 #define uint64_t_C(c)    (c ## ULL)
+#endif
 
-#if 1 
+#ifdef HAVE_AV_CONFIG_H
 
 #        ifdef USE_FASTMEMCPY
 #            include "fastmemcpy.h"
@@ -136,7 +178,7 @@
 
 #endif /* !CONFIG_WIN32 && !CONFIG_OS2 */
 
-#if 1 
+#ifdef HAVE_AV_CONFIG_H
 
 #    include "bswap.h"
 
@@ -175,17 +217,14 @@
 #define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b))
 /* assume b>0 */
 #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
+#define ABS(a) ((a) >= 0 ? (a) : (-(a)))
 
-#ifndef ABS
-#define ABS(a) ((a) >= 0 ? (a) : (-(a)))
-#endif
-				    
 #define FFMAX(a,b) ((a) > (b) ? (a) : (b))
 #define FFMIN(a,b) ((a) > (b) ? (b) : (a))
 
 extern const uint32_t inverse[256];
 
-#ifdef ARCH_X86
+#ifdef __i386__
 #    define FASTDIV(a,b) \
     ({\
         int ret,dmy;\
@@ -202,7 +241,7 @@
 #    define FASTDIV(a,b)   ((a)/(b))
 #endif
  
-#ifdef ARCH_X86
+#ifdef __i386__
 // avoid +32 for shift optimization (gcc should do that ...)
 static inline  int32_t NEG_SSR32( int32_t a, int8_t s){
     asm ("sarl %1, %0\n\t"
@@ -230,25 +269,39 @@
 typedef void (*WriteDataFunc)(void *, uint8_t *, int);
 
 typedef struct PutBitContext {
+#ifdef ALT_BITSTREAM_WRITER
+    uint8_t *buf, *buf_end;
+    int index;
+#else
     uint32_t bit_buf;
     int bit_left;
     uint8_t *buf, *buf_ptr, *buf_end;
+#endif
 } PutBitContext;
 
 void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size);
 
-// XXX XXX XXX
-#if 0 
 int get_bit_count(PutBitContext *s); /* XXX: change function name */
 void align_put_bits(PutBitContext *s);
 void flush_put_bits(PutBitContext *s);
-#endif
+void put_string(PutBitContext * pbc, char *s);
 
 /* bit input */
 
 typedef struct GetBitContext {
     const uint8_t *buffer, *buffer_end;
+#ifdef ALT_BITSTREAM_READER
     int index;
+#elif defined LIBMPEG2_BITSTREAM_READER
+    uint8_t *buffer_ptr;
+    uint32_t cache;
+    int bit_count;
+#elif defined A32_BITSTREAM_READER
+    uint32_t *buffer_ptr;
+    uint32_t cache0;
+    uint32_t cache1;
+    int bit_count;
+#endif
     int size_in_bits;
 } GetBitContext;
 
@@ -273,7 +326,7 @@
 #endif
 
 /* used to avoid missaligned exceptions on some archs (alpha, ...) */
-#ifdef ARCH_X86
+#ifdef __i386__
 #    define unaligned32(a) (*(uint32_t*)(a))
 #else
 #    ifdef __GNUC__
@@ -295,6 +348,7 @@
 #    endif
 #endif //!ARCH_X86
 
+#ifndef ALT_BITSTREAM_WRITER
 static inline void put_bits(PutBitContext *s, int n, unsigned int value)
 {
     unsigned int bit_buf;
@@ -335,10 +389,83 @@
     s->bit_buf = bit_buf;
     s->bit_left = bit_left;
 }
+#endif
+
+
+#ifdef ALT_BITSTREAM_WRITER
+static inline void put_bits(PutBitContext *s, int n, unsigned int value)
+{
+#    ifdef ALIGNED_BITSTREAM_WRITER
+#        ifdef ARCH_X86
+    asm volatile(
+	"movl %0, %%ecx			\n\t"
+	"xorl %%eax, %%eax		\n\t"
+	"shrdl %%cl, %1, %%eax		\n\t"
+	"shrl %%cl, %1			\n\t"
+	"movl %0, %%ecx			\n\t"
+	"shrl $3, %%ecx			\n\t"
+	"andl $0xFFFFFFFC, %%ecx	\n\t"
+	"bswapl %1			\n\t"
+	"orl %1, (%2, %%ecx)		\n\t"
+	"bswapl %%eax			\n\t"
+	"addl %3, %0			\n\t"
+	"movl %%eax, 4(%2, %%ecx)	\n\t"
+	: "=&r" (s->index), "=&r" (value)
+	: "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
+	: "%eax", "%ecx"
+    );
+#        else
+    int index= s->index;
+    uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
+    
+    value<<= 32-n; 
+    
+    ptr[0] |= be2me_32(value>>(index&31));
+    ptr[1]  = be2me_32(value<<(32-(index&31)));
+//if(n>24) printf("%d %d\n", n, value);
+    index+= n;
+    s->index= index;
+#        endif
+#    else //ALIGNED_BITSTREAM_WRITER
+#        ifdef ARCH_X86
+    asm volatile(
+	"movl $7, %%ecx			\n\t"
+	"andl %0, %%ecx			\n\t"
+	"addl %3, %%ecx			\n\t"
+	"negl %%ecx			\n\t"
+	"shll %%cl, %1			\n\t"
+	"bswapl %1			\n\t"
+	"movl %0, %%ecx			\n\t"
+	"shrl $3, %%ecx			\n\t"
+	"orl %1, (%%ecx, %2)		\n\t"
+	"addl %3, %0			\n\t"
+	"movl $0, 4(%%ecx, %2)		\n\t"
+	: "=&r" (s->index), "=&r" (value)
+	: "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
+	: "%ecx"
+    );
+#        else
+    int index= s->index;
+    uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
+    
+    ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
+    ptr[1] = 0;
+//if(n>24) printf("%d %d\n", n, value);
+    index+= n;
+    s->index= index;
+#        endif
+#    endif //!ALIGNED_BITSTREAM_WRITER
+}
+#endif
+
 
 static inline uint8_t* pbBufPtr(PutBitContext *s)
 {
+#ifdef ALT_BITSTREAM_WRITER
+	return s->buf + (s->index>>3);
+#else
 	return s->buf_ptr;
+#endif
 }
 
 /* Bitstream reader API docs:
@@ -396,6 +523,7 @@
 #endif
 }
 
+#ifdef ALT_BITSTREAM_READER
 #   define MIN_CACHE_BITS 25
 
 #   define OPEN_READER(name, gb)\
@@ -436,6 +564,135 @@
 static inline int get_bits_count(GetBitContext *s){
     return s->index;
 }
+#elif defined LIBMPEG2_BITSTREAM_READER
+//libmpeg2 like reader
+
+#   define MIN_CACHE_BITS 17
+
+#   define OPEN_READER(name, gb)\
+        int name##_bit_count=(gb)->bit_count;\
+        int name##_cache= (gb)->cache;\
+        uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
+
+#   define CLOSE_READER(name, gb)\
+        (gb)->bit_count= name##_bit_count;\
+        (gb)->cache= name##_cache;\
+        (gb)->buffer_ptr= name##_buffer_ptr;\
+
+#ifdef LIBMPEG2_BITSTREAM_READER_HACK
+
+#   define UPDATE_CACHE(name, gb)\
+    if(name##_bit_count >= 0){\
+        name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr) << name##_bit_count;\
+        ((uint16_t*)name##_buffer_ptr)++;\
+        name##_bit_count-= 16;\
+    }\
+
+#else
+
+#   define UPDATE_CACHE(name, gb)\
+    if(name##_bit_count >= 0){\
+        name##_cache+= ((name##_buffer_ptr[0]<<8) + name##_buffer_ptr[1]) << name##_bit_count;\
+        name##_buffer_ptr+=2;\
+        name##_bit_count-= 16;\
+    }\
+
+#endif
+
+#   define SKIP_CACHE(name, gb, num)\
+        name##_cache <<= (num);\
+
+#   define SKIP_COUNTER(name, gb, num)\
+        name##_bit_count += (num);\
+
+#   define SKIP_BITS(name, gb, num)\
+        {\
+            SKIP_CACHE(name, gb, num)\
+            SKIP_COUNTER(name, gb, num)\
+        }\
+
+#   define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
+#   define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
+
+#   define SHOW_UBITS(name, gb, num)\
+        NEG_USR32(name##_cache, num)
+
+#   define SHOW_SBITS(name, gb, num)\
+        NEG_SSR32(name##_cache, num)
+
+#   define GET_CACHE(name, gb)\
+        ((uint32_t)name##_cache)
+
+static inline int get_bits_count(GetBitContext *s){
+    return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
+}
+
+#elif defined A32_BITSTREAM_READER
+
+#   define MIN_CACHE_BITS 32
+
+#   define OPEN_READER(name, gb)\
+        int name##_bit_count=(gb)->bit_count;\
+        uint32_t name##_cache0= (gb)->cache0;\
+        uint32_t name##_cache1= (gb)->cache1;\
+        uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
+
+#   define CLOSE_READER(name, gb)\
+        (gb)->bit_count= name##_bit_count;\
+        (gb)->cache0= name##_cache0;\
+        (gb)->cache1= name##_cache1;\
+        (gb)->buffer_ptr= name##_buffer_ptr;\
+
+#   define UPDATE_CACHE(name, gb)\
+    if(name##_bit_count > 0){\
+        const uint32_t next= be2me_32( *name##_buffer_ptr );\
+        name##_cache0 |= NEG_USR32(next,name##_bit_count);\
+        name##_cache1 |= next<<name##_bit_count;\
+        name##_buffer_ptr++;\
+        name##_bit_count-= 32;\
+    }\
+
+#ifdef __i386__
+#   define SKIP_CACHE(name, gb, num)\
+        asm(\
+            "shldl %2, %1, %0		\n\t"\
+            "shll %2, %1		\n\t"\
+            : "+r" (name##_cache0), "+r" (name##_cache1)\
+            : "Ic" ((uint8_t)num)\
+           );
+#else
+#   define SKIP_CACHE(name, gb, num)\
+        name##_cache0 <<= (num);\
+        name##_cache0 |= NEG_USR32(name##_cache1,num);\
+        name##_cache1 <<= (num);
+#endif
+
+#   define SKIP_COUNTER(name, gb, num)\
+        name##_bit_count += (num);\
+
+#   define SKIP_BITS(name, gb, num)\
+        {\
+            SKIP_CACHE(name, gb, num)\
+            SKIP_COUNTER(name, gb, num)\
+        }\
+
+#   define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
+#   define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
+
+#   define SHOW_UBITS(name, gb, num)\
+        NEG_USR32(name##_cache0, num)
+
+#   define SHOW_SBITS(name, gb, num)\
+        NEG_SSR32(name##_cache0, num)
+
+#   define GET_CACHE(name, gb)\
+        (name##_cache0)
+
+static inline int get_bits_count(GetBitContext *s){
+    return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
+}
+
+#endif
 
 /**
  * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
@@ -825,7 +1082,7 @@
 #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
 
 
-#ifdef ARCH_X86
+#ifdef __i386__
 #define MASK_ABS(mask, level)\
             asm volatile(\
 		"cdq			\n\t"\
@@ -859,7 +1116,7 @@
 }
 #endif
 
-#ifdef ARCH_X86
+#ifdef __i386__
 static inline long long rdtsc()
 {
 	long long l;
@@ -891,9 +1148,9 @@
 #define CLAMP_TO_8BIT(d) ((d > 0xff) ? 0xff : (d < 0) ? 0 : d)
 
 /* avoid usage of various functions */
-/*#define malloc please_use_av_malloc
+#define malloc please_use_av_malloc
 #define free please_use_av_free
-#define realloc please_use_av_realloc*/
+#define realloc please_use_av_realloc
 
 #define CHECKED_ALLOCZ(p, size)\
 {\
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Input/wma/libffwma/config.h	Sat Nov 19 14:42:28 2005 -0800
@@ -0,0 +1,25 @@
+/* Automatically generated by configure - do not modify */
+#define ARCH_X86 1
+#define TUNECPU generic
+#undef HAVE_MMX
+#define __CPU__ 586
+#define HAVE_BUILTIN_VECTOR 1
+#define HAVE_LOCALTIME_R 1
+#define HAVE_LRINTF 1
+#undef HAVE_VHOOK
+#undef CONFIG_ENCODERS
+#define CONFIG_DECODERS 1
+#undef CONFIG_MPEGAUDIO_HP 
+#undef CONFIG_VIDEO4LINUX
+#undef CONFIG_DV1394
+#define CONFIG_HAVE_DLOPEN 1
+#define CONFIG_HAVE_DLFCN 1
+#undef CONFIG_AUDIO_OSS
+#undef CONFIG_NETWORK
+#undef CONFIG_ZLIB
+#define HAVE_MALLOC_H 1
+#define HAVE_MEMALIGN 1
+#define SIMPLE_IDCT 1
+#undef CONFIG_FFSERVER
+#define CONFIG_RISKY 1
+#define restrict __restrict__
--- a/Plugins/Input/wma/libffwma/cutils.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/cutils.c	Sat Nov 19 14:42:28 2005 -0800
@@ -17,6 +17,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include "avformat.h"
+#include "avcodec.h"
 
 #if !defined(CONFIG_NOCUTILS)
 /**
@@ -121,7 +122,7 @@
             nb_alloc = 1;
         else
             nb_alloc = nb * 2;
-        tab = realloc(tab, nb_alloc * sizeof(unsigned long));
+        tab = av_realloc(tab, nb_alloc * sizeof(unsigned long));
         *tab_ptr = tab;
     }
     tab[nb++] = elem;
--- a/Plugins/Input/wma/libffwma/dsputil.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/dsputil.c	Sat Nov 19 14:42:28 2005 -0800
@@ -27,7 +27,9 @@
  
 #include "avcodec.h"
 #include "dsputil.h"
+//#include "mpegvideo.h"
 #include "simple_idct.h"
+//#include "faandct.h"
 
 uint8_t cropTbl[256 + 2 * MAX_NEG_CROP];
 uint32_t squareTbl[512];
@@ -873,6 +875,2202 @@
 #define avg2(a,b) ((a+b+1)>>1)
 #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
 
+#if 0
+static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
+{
+    const int A=(16-x16)*(16-y16);
+    const int B=(   x16)*(16-y16);
+    const int C=(16-x16)*(   y16);
+    const int D=(   x16)*(   y16);
+    int i;
+
+    for(i=0; i<h; i++)
+    {
+        dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
+        dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
+        dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
+        dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
+        dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
+        dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
+        dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
+        dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
+        dst+= stride;
+        src+= stride;
+    }
+}
+
+static void gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy, 
+                  int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
+{
+    int y, vx, vy;
+    const int s= 1<<shift;
+    
+    width--;
+    height--;
+
+    for(y=0; y<h; y++){
+        int x;
+
+        vx= ox;
+        vy= oy;
+        for(x=0; x<8; x++){ //XXX FIXME optimize
+            int src_x, src_y, frac_x, frac_y, index;
+
+            src_x= vx>>16;
+            src_y= vy>>16;
+            frac_x= src_x&(s-1);
+            frac_y= src_y&(s-1);
+            src_x>>=shift;
+            src_y>>=shift;
+  
+            if((unsigned)src_x < width){
+                if((unsigned)src_y < height){
+                    index= src_x + src_y*stride;
+                    dst[y*stride + x]= (  (  src[index         ]*(s-frac_x)
+                                           + src[index       +1]*   frac_x )*(s-frac_y)
+                                        + (  src[index+stride  ]*(s-frac_x)
+                                           + src[index+stride+1]*   frac_x )*   frac_y
+                                        + r)>>(shift*2);
+                }else{
+                    index= src_x + clip(src_y, 0, height)*stride;                    
+                    dst[y*stride + x]= ( (  src[index         ]*(s-frac_x) 
+                                          + src[index       +1]*   frac_x )*s
+                                        + r)>>(shift*2);
+                }
+            }else{
+                if((unsigned)src_y < height){
+                    index= clip(src_x, 0, width) + src_y*stride;                    
+                    dst[y*stride + x]= (  (  src[index         ]*(s-frac_y) 
+                                           + src[index+stride  ]*   frac_y )*s
+                                        + r)>>(shift*2);
+                }else{
+                    index= clip(src_x, 0, width) + clip(src_y, 0, height)*stride;                    
+                    dst[y*stride + x]=    src[index         ];
+                }
+            }
+            
+            vx+= dxx;
+            vy+= dyx;
+        }
+        ox += dxy;
+        oy += dyy;
+    }
+}
+
+static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    switch(width){
+    case 2: put_pixels2_c (dst, src, stride, height); break;
+    case 4: put_pixels4_c (dst, src, stride, height); break;
+    case 8: put_pixels8_c (dst, src, stride, height); break;
+    case 16:put_pixels16_c(dst, src, stride, height); break;
+    }
+}
+
+static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+
+static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+    
+static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+    
+static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+
+static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+
+static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+
+static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+
+static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+
+static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    switch(width){
+    case 2: avg_pixels2_c (dst, src, stride, height); break;
+    case 4: avg_pixels4_c (dst, src, stride, height); break;
+    case 8: avg_pixels8_c (dst, src, stride, height); break;
+    case 16:avg_pixels16_c(dst, src, stride, height); break;
+    }
+}
+
+static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+
+static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+    
+static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+    
+static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (dst[j] + ((2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+
+static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (dst[j] + ((2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+
+static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+
+static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (dst[j] + ((2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+
+static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+    int i,j;
+    for (i=0; i < height; i++) {
+      for (j=0; j < width; j++) {
+	dst[j] = (dst[j] + ((2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
+      }
+      src += stride;
+      dst += stride;
+    }
+}
+#if 0
+#define TPEL_WIDTH(width)\
+static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+    void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+    void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+    void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+    void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+    void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+    void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+    void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+    void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+    void put_tpel_pixels_mc22_c(dst, src, stride, width, height);}
+#endif
+
+#define H264_CHROMA_MC(OPNAME, OP)\
+static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
+    const int A=(8-x)*(8-y);\
+    const int B=(  x)*(8-y);\
+    const int C=(8-x)*(  y);\
+    const int D=(  x)*(  y);\
+    int i;\
+    \
+    assert(x<8 && y<8 && x>=0 && y>=0);\
+\
+    for(i=0; i<h; i++)\
+    {\
+        OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
+        OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
+        dst+= stride;\
+        src+= stride;\
+    }\
+}\
+\
+static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
+    const int A=(8-x)*(8-y);\
+    const int B=(  x)*(8-y);\
+    const int C=(8-x)*(  y);\
+    const int D=(  x)*(  y);\
+    int i;\
+    \
+    assert(x<8 && y<8 && x>=0 && y>=0);\
+\
+    for(i=0; i<h; i++)\
+    {\
+        OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
+        OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
+        OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
+        OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
+        dst+= stride;\
+        src+= stride;\
+    }\
+}\
+\
+static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
+    const int A=(8-x)*(8-y);\
+    const int B=(  x)*(8-y);\
+    const int C=(8-x)*(  y);\
+    const int D=(  x)*(  y);\
+    int i;\
+    \
+    assert(x<8 && y<8 && x>=0 && y>=0);\
+\
+    for(i=0; i<h; i++)\
+    {\
+        OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
+        OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
+        OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
+        OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
+        OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
+        OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
+        OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
+        OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
+        dst+= stride;\
+        src+= stride;\
+    }\
+}
+
+#define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
+#define op_put(a, b) a = (((b) + 32)>>6)
+
+H264_CHROMA_MC(put_       , op_put)
+H264_CHROMA_MC(avg_       , op_avg)
+#undef op_avg
+#undef op_put
+
+static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
+{
+    int i;
+    for(i=0; i<h; i++)
+    {
+        ST32(dst   , LD32(src   ));
+        dst+=dstStride;
+        src+=srcStride;
+    }
+}
+
+static inline void copy_block8(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
+{
+    int i;
+    for(i=0; i<h; i++)
+    {
+        ST32(dst   , LD32(src   ));
+        ST32(dst+4 , LD32(src+4 ));
+        dst+=dstStride;
+        src+=srcStride;
+    }
+}
+
+static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
+{
+    int i;
+    for(i=0; i<h; i++)
+    {
+        ST32(dst   , LD32(src   ));
+        ST32(dst+4 , LD32(src+4 ));
+        ST32(dst+8 , LD32(src+8 ));
+        ST32(dst+12, LD32(src+12));
+        dst+=dstStride;
+        src+=srcStride;
+    }
+}
+
+static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
+{
+    int i;
+    for(i=0; i<h; i++)
+    {
+        ST32(dst   , LD32(src   ));
+        ST32(dst+4 , LD32(src+4 ));
+        ST32(dst+8 , LD32(src+8 ));
+        ST32(dst+12, LD32(src+12));
+        dst[16]= src[16];
+        dst+=dstStride;
+        src+=srcStride;
+    }
+}
+
+static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
+{
+    int i;
+    for(i=0; i<h; i++)
+    {
+        ST32(dst   , LD32(src   ));
+        ST32(dst+4 , LD32(src+4 ));
+        dst[8]= src[8];
+        dst+=dstStride;
+        src+=srcStride;
+    }
+}
+
+
+#define QPEL_MC(r, OPNAME, RND, OP) \
+static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
+    int i;\
+    for(i=0; i<h; i++)\
+    {\
+        OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
+        OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
+        OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
+        OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
+        OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
+        OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
+        OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
+        OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
+        dst+=dstStride;\
+        src+=srcStride;\
+    }\
+}\
+\
+static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+    const int w=8;\
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
+    int i;\
+    for(i=0; i<w; i++)\
+    {\
+        const int src0= src[0*srcStride];\
+        const int src1= src[1*srcStride];\
+        const int src2= src[2*srcStride];\
+        const int src3= src[3*srcStride];\
+        const int src4= src[4*srcStride];\
+        const int src5= src[5*srcStride];\
+        const int src6= src[6*srcStride];\
+        const int src7= src[7*srcStride];\
+        const int src8= src[8*srcStride];\
+        OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
+        OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
+        OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
+        OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
+        OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
+        OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
+        OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
+        OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
+        dst++;\
+        src++;\
+    }\
+}\
+\
+static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
+    int i;\
+    \
+    for(i=0; i<h; i++)\
+    {\
+        OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
+        OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
+        OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
+        OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
+        OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
+        OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
+        OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
+        OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
+        OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
+        OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
+        OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
+        OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
+        OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
+        OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
+        OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
+        OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
+        dst+=dstStride;\
+        src+=srcStride;\
+    }\
+}\
+\
+static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
+    int i;\
+    const int w=16;\
+    for(i=0; i<w; i++)\
+    {\
+        const int src0= src[0*srcStride];\
+        const int src1= src[1*srcStride];\
+        const int src2= src[2*srcStride];\
+        const int src3= src[3*srcStride];\
+        const int src4= src[4*srcStride];\
+        const int src5= src[5*srcStride];\
+        const int src6= src[6*srcStride];\
+        const int src7= src[7*srcStride];\
+        const int src8= src[8*srcStride];\
+        const int src9= src[9*srcStride];\
+        const int src10= src[10*srcStride];\
+        const int src11= src[11*srcStride];\
+        const int src12= src[12*srcStride];\
+        const int src13= src[13*srcStride];\
+        const int src14= src[14*srcStride];\
+        const int src15= src[15*srcStride];\
+        const int src16= src[16*srcStride];\
+        OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
+        OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
+        OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
+        OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
+        OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
+        OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
+        OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
+        OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
+        OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
+        OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
+        OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
+        OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
+        OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
+        OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
+        OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
+        OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
+        dst++;\
+        src++;\
+    }\
+}\
+\
+static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
+    OPNAME ## pixels8_c(dst, src, stride, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t half[64];\
+    put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
+    OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
+    OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t half[64];\
+    put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
+    OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t half[64];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
+    OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    copy_block9(full, src, 16, stride, 9);\
+    OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
+}\
+\
+static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t half[64];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
+    OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
+}\
+void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t halfH[72];\
+    uint8_t halfV[64];\
+    uint8_t halfHV[64];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+    OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t halfH[72];\
+    uint8_t halfHV[64];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+    put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+    OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
+}\
+void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t halfH[72];\
+    uint8_t halfV[64];\
+    uint8_t halfHV[64];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+    OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t halfH[72];\
+    uint8_t halfHV[64];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+    put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+    OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
+}\
+void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t halfH[72];\
+    uint8_t halfV[64];\
+    uint8_t halfHV[64];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+    OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t halfH[72];\
+    uint8_t halfHV[64];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+    put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+    OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
+}\
+void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t halfH[72];\
+    uint8_t halfV[64];\
+    uint8_t halfHV[64];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full  , 8, 16, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+    OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t halfH[72];\
+    uint8_t halfHV[64];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+    put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+    OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t halfH[72];\
+    uint8_t halfHV[64];\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+    OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t halfH[72];\
+    uint8_t halfHV[64];\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+    OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
+}\
+void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t halfH[72];\
+    uint8_t halfV[64];\
+    uint8_t halfHV[64];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+    OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t halfH[72];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+    put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
+    OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
+}\
+void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t halfH[72];\
+    uint8_t halfV[64];\
+    uint8_t halfHV[64];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
+    put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+    OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[16*9];\
+    uint8_t halfH[72];\
+    copy_block9(full, src, 16, stride, 9);\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+    put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
+    OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
+}\
+static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t halfH[72];\
+    put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
+    OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
+}\
+static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
+    OPNAME ## pixels16_c(dst, src, stride, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t half[256];\
+    put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
+    OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
+    OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t half[256];\
+    put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
+    OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t half[256];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
+    OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    copy_block17(full, src, 24, stride, 17);\
+    OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
+}\
+\
+static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t half[256];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
+    OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
+}\
+void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t halfH[272];\
+    uint8_t halfV[256];\
+    uint8_t halfHV[256];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+    OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t halfH[272];\
+    uint8_t halfHV[256];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+    put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+    OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
+}\
+void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t halfH[272];\
+    uint8_t halfV[256];\
+    uint8_t halfHV[256];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+    OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t halfH[272];\
+    uint8_t halfHV[256];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+    put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+    OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
+}\
+void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t halfH[272];\
+    uint8_t halfV[256];\
+    uint8_t halfHV[256];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+    OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t halfH[272];\
+    uint8_t halfHV[256];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+    put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+    OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
+}\
+void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t halfH[272];\
+    uint8_t halfV[256];\
+    uint8_t halfHV[256];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full  , 16, 24, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+    OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t halfH[272];\
+    uint8_t halfHV[256];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+    put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+    OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t halfH[272];\
+    uint8_t halfHV[256];\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+    OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t halfH[272];\
+    uint8_t halfHV[256];\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+    OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
+}\
+void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t halfH[272];\
+    uint8_t halfV[256];\
+    uint8_t halfHV[256];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+    OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t halfH[272];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+    put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
+    OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
+}\
+void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t halfH[272];\
+    uint8_t halfV[256];\
+    uint8_t halfHV[256];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
+    put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+    OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[24*17];\
+    uint8_t halfH[272];\
+    copy_block17(full, src, 24, stride, 17);\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+    put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
+    OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
+}\
+static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t halfH[272];\
+    put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
+    OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
+}
+
+#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
+#define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
+#define op_put(a, b) a = cm[((b) + 16)>>5]
+#define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
+
+QPEL_MC(0, put_       , _       , op_put)
+QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
+QPEL_MC(0, avg_       , _       , op_avg)
+//QPEL_MC(1, avg_no_rnd , _       , op_avg)
+#undef op_avg
+#undef op_avg_no_rnd
+#undef op_put
+#undef op_put_no_rnd
+
+#if 1
+#define H264_LOWPASS(OPNAME, OP, OP2) \
+static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+    const int h=4;\
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
+    int i;\
+    for(i=0; i<h; i++)\
+    {\
+        OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
+        OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
+        OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
+        OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
+        dst+=dstStride;\
+        src+=srcStride;\
+    }\
+}\
+\
+static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+    const int w=4;\
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
+    int i;\
+    for(i=0; i<w; i++)\
+    {\
+        const int srcB= src[-2*srcStride];\
+        const int srcA= src[-1*srcStride];\
+        const int src0= src[0 *srcStride];\
+        const int src1= src[1 *srcStride];\
+        const int src2= src[2 *srcStride];\
+        const int src3= src[3 *srcStride];\
+        const int src4= src[4 *srcStride];\
+        const int src5= src[5 *srcStride];\
+        const int src6= src[6 *srcStride];\
+        OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
+        OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
+        OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
+        OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
+        dst++;\
+        src++;\
+    }\
+}\
+\
+static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+    const int h=4;\
+    const int w=4;\
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
+    int i;\
+    src -= 2*srcStride;\
+    for(i=0; i<h+5; i++)\
+    {\
+        tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
+        tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
+        tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
+        tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
+        tmp+=tmpStride;\
+        src+=srcStride;\
+    }\
+    tmp -= tmpStride*(h+5-2);\
+    for(i=0; i<w; i++)\
+    {\
+        const int tmpB= tmp[-2*tmpStride];\
+        const int tmpA= tmp[-1*tmpStride];\
+        const int tmp0= tmp[0 *tmpStride];\
+        const int tmp1= tmp[1 *tmpStride];\
+        const int tmp2= tmp[2 *tmpStride];\
+        const int tmp3= tmp[3 *tmpStride];\
+        const int tmp4= tmp[4 *tmpStride];\
+        const int tmp5= tmp[5 *tmpStride];\
+        const int tmp6= tmp[6 *tmpStride];\
+        OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
+        OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
+        OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
+        OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
+        dst++;\
+        tmp++;\
+    }\
+}\
+\
+static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+    const int h=8;\
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
+    int i;\
+    for(i=0; i<h; i++)\
+    {\
+        OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
+        OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
+        OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
+        OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
+        OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
+        OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
+        OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
+        OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
+        dst+=dstStride;\
+        src+=srcStride;\
+    }\
+}\
+\
+static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+    const int w=8;\
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
+    int i;\
+    for(i=0; i<w; i++)\
+    {\
+        const int srcB= src[-2*srcStride];\
+        const int srcA= src[-1*srcStride];\
+        const int src0= src[0 *srcStride];\
+        const int src1= src[1 *srcStride];\
+        const int src2= src[2 *srcStride];\
+        const int src3= src[3 *srcStride];\
+        const int src4= src[4 *srcStride];\
+        const int src5= src[5 *srcStride];\
+        const int src6= src[6 *srcStride];\
+        const int src7= src[7 *srcStride];\
+        const int src8= src[8 *srcStride];\
+        const int src9= src[9 *srcStride];\
+        const int src10=src[10*srcStride];\
+        OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
+        OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
+        OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
+        OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
+        OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
+        OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
+        OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
+        OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
+        dst++;\
+        src++;\
+    }\
+}\
+\
+static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+    const int h=8;\
+    const int w=8;\
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
+    int i;\
+    src -= 2*srcStride;\
+    for(i=0; i<h+5; i++)\
+    {\
+        tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
+        tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
+        tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
+        tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
+        tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
+        tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
+        tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
+        tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
+        tmp+=tmpStride;\
+        src+=srcStride;\
+    }\
+    tmp -= tmpStride*(h+5-2);\
+    for(i=0; i<w; i++)\
+    {\
+        const int tmpB= tmp[-2*tmpStride];\
+        const int tmpA= tmp[-1*tmpStride];\
+        const int tmp0= tmp[0 *tmpStride];\
+        const int tmp1= tmp[1 *tmpStride];\
+        const int tmp2= tmp[2 *tmpStride];\
+        const int tmp3= tmp[3 *tmpStride];\
+        const int tmp4= tmp[4 *tmpStride];\
+        const int tmp5= tmp[5 *tmpStride];\
+        const int tmp6= tmp[6 *tmpStride];\
+        const int tmp7= tmp[7 *tmpStride];\
+        const int tmp8= tmp[8 *tmpStride];\
+        const int tmp9= tmp[9 *tmpStride];\
+        const int tmp10=tmp[10*tmpStride];\
+        OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
+        OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
+        OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
+        OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
+        OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
+        OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
+        OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
+        OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
+        dst++;\
+        tmp++;\
+    }\
+}\
+\
+static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+    OPNAME ## h264_qpel8_v_lowpass(dst  , src  , dstStride, srcStride);\
+    OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
+    src += 8*srcStride;\
+    dst += 8*dstStride;\
+    OPNAME ## h264_qpel8_v_lowpass(dst  , src  , dstStride, srcStride);\
+    OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
+}\
+\
+static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+    OPNAME ## h264_qpel8_h_lowpass(dst  , src  , dstStride, srcStride);\
+    OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
+    src += 8*srcStride;\
+    dst += 8*dstStride;\
+    OPNAME ## h264_qpel8_h_lowpass(dst  , src  , dstStride, srcStride);\
+    OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
+}\
+\
+static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+    OPNAME ## h264_qpel8_hv_lowpass(dst  , tmp  , src  , dstStride, tmpStride, srcStride);\
+    OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
+    src += 8*srcStride;\
+    tmp += 8*tmpStride;\
+    dst += 8*dstStride;\
+    OPNAME ## h264_qpel8_hv_lowpass(dst  , tmp  , src  , dstStride, tmpStride, srcStride);\
+    OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
+}\
+
+#define H264_MC(OPNAME, SIZE) \
+static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
+    OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t half[SIZE*SIZE];\
+    put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
+    OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
+    OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t half[SIZE*SIZE];\
+    put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
+    OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[SIZE*(SIZE+5)];\
+    uint8_t * const full_mid= full + SIZE*2;\
+    uint8_t half[SIZE*SIZE];\
+    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
+    put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
+    OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[SIZE*(SIZE+5)];\
+    uint8_t * const full_mid= full + SIZE*2;\
+    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
+    OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[SIZE*(SIZE+5)];\
+    uint8_t * const full_mid= full + SIZE*2;\
+    uint8_t half[SIZE*SIZE];\
+    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
+    put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
+    OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[SIZE*(SIZE+5)];\
+    uint8_t * const full_mid= full + SIZE*2;\
+    uint8_t halfH[SIZE*SIZE];\
+    uint8_t halfV[SIZE*SIZE];\
+    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
+    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
+    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+    OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[SIZE*(SIZE+5)];\
+    uint8_t * const full_mid= full + SIZE*2;\
+    uint8_t halfH[SIZE*SIZE];\
+    uint8_t halfV[SIZE*SIZE];\
+    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
+    copy_block ## SIZE (full, src - stride*2 + 1, SIZE,  stride, SIZE + 5);\
+    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+    OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[SIZE*(SIZE+5)];\
+    uint8_t * const full_mid= full + SIZE*2;\
+    uint8_t halfH[SIZE*SIZE];\
+    uint8_t halfV[SIZE*SIZE];\
+    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
+    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
+    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+    OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[SIZE*(SIZE+5)];\
+    uint8_t * const full_mid= full + SIZE*2;\
+    uint8_t halfH[SIZE*SIZE];\
+    uint8_t halfV[SIZE*SIZE];\
+    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
+    copy_block ## SIZE (full, src - stride*2 + 1, SIZE,  stride, SIZE + 5);\
+    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+    OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
+    int16_t tmp[SIZE*(SIZE+5)];\
+    OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
+    int16_t tmp[SIZE*(SIZE+5)];\
+    uint8_t halfH[SIZE*SIZE];\
+    uint8_t halfHV[SIZE*SIZE];\
+    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
+    put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
+    OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
+    int16_t tmp[SIZE*(SIZE+5)];\
+    uint8_t halfH[SIZE*SIZE];\
+    uint8_t halfHV[SIZE*SIZE];\
+    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
+    put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
+    OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[SIZE*(SIZE+5)];\
+    uint8_t * const full_mid= full + SIZE*2;\
+    int16_t tmp[SIZE*(SIZE+5)];\
+    uint8_t halfV[SIZE*SIZE];\
+    uint8_t halfHV[SIZE*SIZE];\
+    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
+    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+    put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
+    OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
+    uint8_t full[SIZE*(SIZE+5)];\
+    uint8_t * const full_mid= full + SIZE*2;\
+    int16_t tmp[SIZE*(SIZE+5)];\
+    uint8_t halfV[SIZE*SIZE];\
+    uint8_t halfHV[SIZE*SIZE];\
+    copy_block ## SIZE (full, src - stride*2 + 1, SIZE,  stride, SIZE + 5);\
+    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+    put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
+    OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
+}\
+
+#define op_avg(a, b)  a = (((a)+cm[((b) + 16)>>5]+1)>>1)
+//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
+#define op_put(a, b)  a = cm[((b) + 16)>>5]
+#define op2_avg(a, b)  a = (((a)+cm[((b) + 512)>>10]+1)>>1)
+#define op2_put(a, b)  a = cm[((b) + 512)>>10]
+
+H264_LOWPASS(put_       , op_put, op2_put)
+H264_LOWPASS(avg_       , op_avg, op2_avg)
+H264_MC(put_, 4)
+H264_MC(put_, 8)
+H264_MC(put_, 16)
+H264_MC(avg_, 4)
+H264_MC(avg_, 8)
+H264_MC(avg_, 16)
+
+#undef op_avg
+#undef op_put
+#undef op2_avg
+#undef op2_put
+#endif
+
+static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;
+    int i;
+
+    for(i=0; i<h; i++){
+        dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
+        dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
+        dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
+        dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
+        dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
+        dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
+        dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
+        dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
+        dst+=dstStride;
+        src+=srcStride;        
+    }
+}
+
+static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
+    uint8_t *cm = cropTbl + MAX_NEG_CROP;
+    int i;
+
+    for(i=0; i<w; i++){
+        const int src_1= src[ -srcStride];
+        const int src0 = src[0          ];
+        const int src1 = src[  srcStride];
+        const int src2 = src[2*srcStride];
+        const int src3 = src[3*srcStride];
+        const int src4 = src[4*srcStride];
+        const int src5 = src[5*srcStride];
+        const int src6 = src[6*srcStride];
+        const int src7 = src[7*srcStride];
+        const int src8 = src[8*srcStride];
+        const int src9 = src[9*srcStride];
+        dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
+        dst[1*dstStride]= cm[(9*(src1 + src2) - (src0  + src3) + 8)>>4];
+        dst[2*dstStride]= cm[(9*(src2 + src3) - (src1  + src4) + 8)>>4];
+        dst[3*dstStride]= cm[(9*(src3 + src4) - (src2  + src5) + 8)>>4];
+        dst[4*dstStride]= cm[(9*(src4 + src5) - (src3  + src6) + 8)>>4];
+        dst[5*dstStride]= cm[(9*(src5 + src6) - (src4  + src7) + 8)>>4];
+        dst[6*dstStride]= cm[(9*(src6 + src7) - (src5  + src8) + 8)>>4];
+        dst[7*dstStride]= cm[(9*(src7 + src8) - (src6  + src9) + 8)>>4];
+        src++;
+        dst++;
+    }
+}
+
+static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
+    put_pixels8_c(dst, src, stride, 8);
+}
+
+static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
+    uint8_t half[64];
+    wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
+    put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
+}
+
+static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
+    wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
+}
+
+static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
+    uint8_t half[64];
+    wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
+    put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
+}
+
+static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
+    wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
+}
+
+static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
+    uint8_t halfH[88];
+    uint8_t halfV[64];
+    uint8_t halfHV[64];
+    wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
+    wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
+    wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
+    put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
+}
+static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
+    uint8_t halfH[88];
+    uint8_t halfV[64];
+    uint8_t halfHV[64];
+    wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
+    wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
+    wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
+    put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
+}
+static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
+    uint8_t halfH[88];
+    wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
+    wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
+}
+#endif
+#if 0
+static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
+    int x;
+    const int strength= ff_h263_loop_filter_strength[qscale];
+    
+    for(x=0; x<8; x++){
+        int d1, d2, ad1;
+        int p0= src[x-2*stride];
+        int p1= src[x-1*stride];
+        int p2= src[x+0*stride];
+        int p3= src[x+1*stride];
+        int d = (p0 - p3 + 4*(p2 - p1)) / 8;
+
+        if     (d<-2*strength) d1= 0;
+        else if(d<-  strength) d1=-2*strength - d;
+        else if(d<   strength) d1= d;
+        else if(d< 2*strength) d1= 2*strength - d;
+        else                   d1= 0;
+        
+        p1 += d1;
+        p2 -= d1;
+        if(p1&256) p1= ~(p1>>31);
+        if(p2&256) p2= ~(p2>>31);
+        
+        src[x-1*stride] = p1;
+        src[x+0*stride] = p2;
+
+        ad1= ABS(d1)>>1;
+        
+        d2= clip((p0-p3)/4, -ad1, ad1);
+        
+        src[x-2*stride] = p0 - d2;
+        src[x+  stride] = p3 + d2;
+    }
+}
+
+static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
+    int y;
+    const int strength= ff_h263_loop_filter_strength[qscale];
+    
+    for(y=0; y<8; y++){
+        int d1, d2, ad1;
+        int p0= src[y*stride-2];
+        int p1= src[y*stride-1];
+        int p2= src[y*stride+0];
+        int p3= src[y*stride+1];
+        int d = (p0 - p3 + 4*(p2 - p1)) / 8;
+
+        if     (d<-2*strength) d1= 0;
+        else if(d<-  strength) d1=-2*strength - d;
+        else if(d<   strength) d1= d;
+        else if(d< 2*strength) d1= 2*strength - d;
+        else                   d1= 0;
+        
+        p1 += d1;
+        p2 -= d1;
+        if(p1&256) p1= ~(p1>>31);
+        if(p2&256) p2= ~(p2>>31);
+        
+        src[y*stride-1] = p1;
+        src[y*stride+0] = p2;
+
+        ad1= ABS(d1)>>1;
+        
+        d2= clip((p0-p3)/4, -ad1, ad1);
+        
+        src[y*stride-2] = p0 - d2;
+        src[y*stride+1] = p3 + d2;
+    }
+}
+#endif
+#if 0
+static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+    int s, i;
+
+    s = 0;
+    for(i=0;i<h;i++) {
+        s += abs(pix1[0] - pix2[0]);
+        s += abs(pix1[1] - pix2[1]);
+        s += abs(pix1[2] - pix2[2]);
+        s += abs(pix1[3] - pix2[3]);
+        s += abs(pix1[4] - pix2[4]);
+        s += abs(pix1[5] - pix2[5]);
+        s += abs(pix1[6] - pix2[6]);
+        s += abs(pix1[7] - pix2[7]);
+        s += abs(pix1[8] - pix2[8]);
+        s += abs(pix1[9] - pix2[9]);
+        s += abs(pix1[10] - pix2[10]);
+        s += abs(pix1[11] - pix2[11]);
+        s += abs(pix1[12] - pix2[12]);
+        s += abs(pix1[13] - pix2[13]);
+        s += abs(pix1[14] - pix2[14]);
+        s += abs(pix1[15] - pix2[15]);
+        pix1 += line_size;
+        pix2 += line_size;
+    }
+    return s;
+}
+
+static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+    int s, i;
+
+    s = 0;
+    for(i=0;i<h;i++) {
+        s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
+        s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
+        s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
+        s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
+        s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
+        s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
+        s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
+        s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
+        s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
+        s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
+        s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
+        s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
+        s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
+        s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
+        s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
+        s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
+        pix1 += line_size;
+        pix2 += line_size;
+    }
+    return s;
+}
+
+static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+    int s, i;
+    uint8_t *pix3 = pix2 + line_size;
+
+    s = 0;
+    for(i=0;i<h;i++) {
+        s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
+        s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
+        s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
+        s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
+        s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
+        s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
+        s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
+        s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
+        s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
+        s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
+        s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
+        s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
+        s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
+        s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
+        s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
+        s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
+        pix1 += line_size;
+        pix2 += line_size;
+        pix3 += line_size;
+    }
+    return s;
+}
+
+static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+    int s, i;
+    uint8_t *pix3 = pix2 + line_size;
+
+    s = 0;
+    for(i=0;i<h;i++) {
+        s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
+        s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
+        s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
+        s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
+        s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
+        s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
+        s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
+        s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
+        s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
+        s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
+        s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
+        s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
+        s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
+        s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
+        s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
+        s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
+        pix1 += line_size;
+        pix2 += line_size;
+        pix3 += line_size;
+    }
+    return s;
+}
+
+static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+    int s, i;
+
+    s = 0;
+    for(i=0;i<h;i++) {
+        s += abs(pix1[0] - pix2[0]);
+        s += abs(pix1[1] - pix2[1]);
+        s += abs(pix1[2] - pix2[2]);
+        s += abs(pix1[3] - pix2[3]);
+        s += abs(pix1[4] - pix2[4]);
+        s += abs(pix1[5] - pix2[5]);
+        s += abs(pix1[6] - pix2[6]);
+        s += abs(pix1[7] - pix2[7]);
+        pix1 += line_size;
+        pix2 += line_size;
+    }
+    return s;
+}
+
+static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+    int s, i;
+
+    s = 0;
+    for(i=0;i<h;i++) {
+        s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
+        s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
+        s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
+        s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
+        s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
+        s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
+        s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
+        s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
+        pix1 += line_size;
+        pix2 += line_size;
+    }
+    return s;
+}
+
+static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+    int s, i;
+    uint8_t *pix3 = pix2 + line_size;
+
+    s = 0;
+    for(i=0;i<h;i++) {
+        s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
+        s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
+        s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
+        s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
+        s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
+        s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
+        s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
+        s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
+        pix1 += line_size;
+        pix2 += line_size;
+        pix3 += line_size;
+    }
+    return s;
+}
+
+static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+    int s, i;
+    uint8_t *pix3 = pix2 + line_size;
+
+    s = 0;
+    for(i=0;i<h;i++) {
+        s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
+        s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
+        s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
+        s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
+        s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
+        s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
+        s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
+        s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
+        pix1 += line_size;
+        pix2 += line_size;
+        pix3 += line_size;
+    }
+    return s;
+}
+
+static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
+    int i;
+    unsigned int sum=0;
+
+    for(i=0; i<8*8; i++){
+        int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
+        int w= weight[i];
+        b>>= RECON_SHIFT;
+        assert(-512<b && b<512);
+
+        sum += (w*b)*(w*b)>>4;
+    }
+    return sum>>2;
+}
+
+static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
+    int i;
+
+    for(i=0; i<8*8; i++){
+        rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
+    }    
+}
+
+/**
+ * permutes an 8x8 block.
+ * @param block the block which will be permuted according to the given permutation vector
+ * @param permutation the permutation vector
+ * @param last the last non zero coefficient in scantable order, used to speed the permutation up
+ * @param scantable the used scantable, this is only used to speed the permutation up, the block is not 
+ *                  (inverse) permutated to scantable order!
+ */
+void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
+{
+    int i;
+    DCTELEM temp[64];
+    
+    if(last<=0) return;
+    //if(permutation[1]==1) return; //FIXME its ok but not clean and might fail for some perms
+
+    for(i=0; i<=last; i++){
+        const int j= scantable[i];
+        temp[j]= block[j];
+        block[j]=0;
+    }
+    
+    for(i=0; i<=last; i++){
+        const int j= scantable[i];
+        const int perm_j= permutation[j];
+        block[perm_j]= temp[j];
+    }
+}
+
+static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
+    return 0;
+}
+
+void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
+    int i;
+    
+    memset(cmp, 0, sizeof(void*)*5);
+        
+    for(i=0; i<5; i++){
+        switch(type&0xFF){
+        case FF_CMP_SAD:
+            cmp[i]= c->sad[i];
+            break;
+        case FF_CMP_SATD:
+            cmp[i]= c->hadamard8_diff[i];
+            break;
+        case FF_CMP_SSE:
+            cmp[i]= c->sse[i];
+            break;
+        case FF_CMP_DCT:
+            cmp[i]= c->dct_sad[i];
+            break;
+        case FF_CMP_PSNR:
+            cmp[i]= c->quant_psnr[i];
+            break;
+        case FF_CMP_BIT:
+            cmp[i]= c->bit[i];
+            break;
+        case FF_CMP_RD:
+            cmp[i]= c->rd[i];
+            break;
+        case FF_CMP_VSAD:
+            cmp[i]= c->vsad[i];
+            break;
+        case FF_CMP_VSSE:
+            cmp[i]= c->vsse[i];
+            break;
+        case FF_CMP_ZERO:
+            cmp[i]= zero_cmp;
+            break;
+        default:
+            av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
+        }
+    }
+}
+
+/**
+ * memset(blocks, 0, sizeof(DCTELEM)*6*64)
+ */
+static void clear_blocks_c(DCTELEM *blocks)
+{
+    memset(blocks, 0, sizeof(DCTELEM)*6*64);
+}
+
+static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
+    int i;
+    for(i=0; i+7<w; i+=8){
+        dst[i+0] += src[i+0];
+        dst[i+1] += src[i+1];
+        dst[i+2] += src[i+2];
+        dst[i+3] += src[i+3];
+        dst[i+4] += src[i+4];
+        dst[i+5] += src[i+5];
+        dst[i+6] += src[i+6];
+        dst[i+7] += src[i+7];
+    }
+    for(; i<w; i++)
+        dst[i+0] += src[i+0];
+}
+
+static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
+    int i;
+    for(i=0; i+7<w; i+=8){
+        dst[i+0] = src1[i+0]-src2[i+0];
+        dst[i+1] = src1[i+1]-src2[i+1];
+        dst[i+2] = src1[i+2]-src2[i+2];
+        dst[i+3] = src1[i+3]-src2[i+3];
+        dst[i+4] = src1[i+4]-src2[i+4];
+        dst[i+5] = src1[i+5]-src2[i+5];
+        dst[i+6] = src1[i+6]-src2[i+6];
+        dst[i+7] = src1[i+7]-src2[i+7];
+    }
+    for(; i<w; i++)
+        dst[i+0] = src1[i+0]-src2[i+0];
+}
+
+static void sub_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
+    int i;
+    uint8_t l, lt;
+
+    l= *left;
+    lt= *left_top;
+
+    for(i=0; i<w; i++){
+        const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
+        lt= src1[i];
+        l= src2[i];
+        dst[i]= l - pred;
+    }    
+
+    *left= l;
+    *left_top= lt;
+}
+#endif
+#if 0
+#define BUTTERFLY2(o1,o2,i1,i2) \
+o1= (i1)+(i2);\
+o2= (i1)-(i2);
+
+#define BUTTERFLY1(x,y) \
+{\
+    int a,b;\
+    a= x;\
+    b= y;\
+    x= a+b;\
+    y= a-b;\
+}
+
+#define BUTTERFLYA(x,y) (ABS((x)+(y)) + ABS((x)-(y)))
+
+static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
+    int i;
+    int temp[64];
+    int sum=0;
+    
+    assert(h==8);
+
+    for(i=0; i<8; i++){
+        //FIXME try pointer walks
+        BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-dst[stride*i+0],src[stride*i+1]-dst[stride*i+1]);
+        BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-dst[stride*i+2],src[stride*i+3]-dst[stride*i+3]);
+        BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-dst[stride*i+4],src[stride*i+5]-dst[stride*i+5]);
+        BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-dst[stride*i+6],src[stride*i+7]-dst[stride*i+7]);
+        
+        BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
+        BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
+        BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
+        BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
+        
+        BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
+        BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
+        BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
+        BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
+    }
+
+    for(i=0; i<8; i++){
+        BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
+        BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
+        BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
+        BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
+        
+        BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
+        BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
+        BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
+        BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
+
+        sum += 
+             BUTTERFLYA(temp[8*0+i], temp[8*4+i])
+            +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
+            +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
+            +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
+    }
+#if 0
+static int maxi=0;
+if(sum>maxi){
+    maxi=sum;
+    printf("MAX:%d\n", maxi);
+}
+#endif
+    return sum;
+}
+
+static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
+    int i;
+    int temp[64];
+    int sum=0;
+    
+    assert(h==8);
+    
+    for(i=0; i<8; i++){
+        //FIXME try pointer walks
+        BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
+        BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
+        BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
+        BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
+        
+        BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
+        BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
+        BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
+        BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
+        
+        BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
+        BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
+        BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
+        BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
+    }
+
+    for(i=0; i<8; i++){
+        BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
+        BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
+        BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
+        BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
+        
+        BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
+        BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
+        BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
+        BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
+    
+        sum += 
+             BUTTERFLYA(temp[8*0+i], temp[8*4+i])
+            +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
+            +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
+            +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
+    }
+    
+    sum -= ABS(temp[8*0] + temp[8*4]); // -mean
+    
+    return sum;
+}
+
+static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
+    MpegEncContext * const s= (MpegEncContext *)c;
+    uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
+    DCTELEM * const temp= (DCTELEM*)aligned_temp;
+    int sum=0, i;
+    
+    assert(h==8);
+
+    s->dsp.diff_pixels(temp, src1, src2, stride);
+    s->dsp.fdct(temp);
+
+    for(i=0; i<64; i++)
+        sum+= ABS(temp[i]);
+        
+    return sum;
+}
+
+void simple_idct(DCTELEM *block); //FIXME
+
+static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
+    MpegEncContext * const s= (MpegEncContext *)c;
+    uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64*2/8];
+    DCTELEM * const temp= (DCTELEM*)aligned_temp;
+    DCTELEM * const bak = ((DCTELEM*)aligned_temp)+64;
+    int sum=0, i;
+
+    assert(h==8);
+    s->mb_intra=0;
+    
+    s->dsp.diff_pixels(temp, src1, src2, stride);
+    
+    memcpy(bak, temp, 64*sizeof(DCTELEM));
+    
+    s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
+    s->dct_unquantize_inter(s, temp, 0, s->qscale);
+    simple_idct(temp); //FIXME 
+    
+    for(i=0; i<64; i++)
+        sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
+        
+    return sum;
+}
+
+static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
+    MpegEncContext * const s= (MpegEncContext *)c;
+    const uint8_t *scantable= s->intra_scantable.permutated;
+    uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
+    uint64_t __align8 aligned_bak[stride];
+    DCTELEM * const temp= (DCTELEM*)aligned_temp;
+    uint8_t * const bak= (uint8_t*)aligned_bak;
+    int i, last, run, bits, level, distoration, start_i;
+    const int esc_length= s->ac_esc_length;
+    uint8_t * length;
+    uint8_t * last_length;
+    
+    assert(h==8);
+
+    for(i=0; i<8; i++){
+        ((uint32_t*)(bak + i*stride))[0]= ((uint32_t*)(src2 + i*stride))[0];
+        ((uint32_t*)(bak + i*stride))[1]= ((uint32_t*)(src2 + i*stride))[1];
+    }
+
+    s->dsp.diff_pixels(temp, src1, src2, stride);
+
+    s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
+
+    bits=0;
+    
+    if (s->mb_intra) {
+        start_i = 1; 
+        length     = s->intra_ac_vlc_length;
+        last_length= s->intra_ac_vlc_last_length;
+        bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
+    } else {
+        start_i = 0;
+        length     = s->inter_ac_vlc_length;
+        last_length= s->inter_ac_vlc_last_length;
+    }
+    
+    if(last>=start_i){
+        run=0;
+        for(i=start_i; i<last; i++){
+            int j= scantable[i];
+            level= temp[j];
+        
+            if(level){
+                level+=64;
+                if((level&(~127)) == 0){
+                    bits+= length[UNI_AC_ENC_INDEX(run, level)];
+                }else
+                    bits+= esc_length;
+                run=0;
+            }else
+                run++;
+        }
+        i= scantable[last];
+       
+        level= temp[i] + 64;
+
+        assert(level - 64);
+        
+        if((level&(~127)) == 0){
+            bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
+        }else
+            bits+= esc_length;
+    
+    }
+
+    if(last>=0){
+        if(s->mb_intra)
+            s->dct_unquantize_intra(s, temp, 0, s->qscale);
+        else
+            s->dct_unquantize_inter(s, temp, 0, s->qscale);
+    }
+    
+    s->dsp.idct_add(bak, stride, temp);
+    
+    distoration= s->dsp.sse[1](NULL, bak, src1, stride, 8);
+
+    return distoration + ((bits*s->qscale*s->qscale*109 + 64)>>7);
+}
+
+static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
+    MpegEncContext * const s= (MpegEncContext *)c;
+    const uint8_t *scantable= s->intra_scantable.permutated;
+    uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
+    DCTELEM * const temp= (DCTELEM*)aligned_temp;
+    int i, last, run, bits, level, start_i;
+    const int esc_length= s->ac_esc_length;
+    uint8_t * length;
+    uint8_t * last_length;
+
+    assert(h==8);
+    
+    s->dsp.diff_pixels(temp, src1, src2, stride);
+
+    s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
+
+    bits=0;
+    
+    if (s->mb_intra) {
+        start_i = 1; 
+        length     = s->intra_ac_vlc_length;
+        last_length= s->intra_ac_vlc_last_length;
+        bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
+    } else {
+        start_i = 0;
+        length     = s->inter_ac_vlc_length;
+        last_length= s->inter_ac_vlc_last_length;
+    }
+    
+    if(last>=start_i){
+        run=0;
+        for(i=start_i; i<last; i++){
+            int j= scantable[i];
+            level= temp[j];
+        
+            if(level){
+                level+=64;
+                if((level&(~127)) == 0){
+                    bits+= length[UNI_AC_ENC_INDEX(run, level)];
+                }else
+                    bits+= esc_length;
+                run=0;
+            }else
+                run++;
+        }
+        i= scantable[last];
+                
+        level= temp[i] + 64;
+        
+        assert(level - 64);
+        
+        if((level&(~127)) == 0){
+            bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
+        }else
+            bits+= esc_length;
+    }
+
+    return bits;
+}
+
+static int vsad_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
+    int score=0;
+    int x,y;
+    
+    for(y=1; y<h; y++){
+        for(x=0; x<16; x+=4){
+            score+= ABS(s[x  ] - s[x  +stride]) + ABS(s[x+1] - s[x+1+stride]) 
+                   +ABS(s[x+2] - s[x+2+stride]) + ABS(s[x+3] - s[x+3+stride]);
+        }
+        s+= stride;
+    }
+    
+    return score;
+}
+
+static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
+    int score=0;
+    int x,y;
+    
+    for(y=1; y<h; y++){
+        for(x=0; x<16; x++){
+            score+= ABS(s1[x  ] - s2[x ] - s1[x  +stride] + s2[x +stride]);
+        }
+        s1+= stride;
+        s2+= stride;
+    }
+    
+    return score;
+}
+
+#define SQ(a) ((a)*(a))
+static int vsse_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
+    int score=0;
+    int x,y;
+    
+    for(y=1; y<h; y++){
+        for(x=0; x<16; x+=4){
+            score+= SQ(s[x  ] - s[x  +stride]) + SQ(s[x+1] - s[x+1+stride]) 
+                   +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]);
+        }
+        s+= stride;
+    }
+    
+    return score;
+}
+
+static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
+    int score=0;
+    int x,y;
+    
+    for(y=1; y<h; y++){
+        for(x=0; x<16; x++){
+            score+= SQ(s1[x  ] - s2[x ] - s1[x  +stride] + s2[x +stride]);
+        }
+        s1+= stride;
+        s2+= stride;
+    }
+    
+    return score;
+}
+
+WARPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
+WARPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
+WARPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
+WARPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
+WARPER8_16_SQ(rd8x8_c, rd16_c)
+WARPER8_16_SQ(bit8x8_c, bit16_c)
+
+/* XXX: those functions should be suppressed ASAP when all IDCTs are
+ converted */
+static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+    j_rev_dct (block);
+    put_pixels_clamped_c(block, dest, line_size);
+}
+static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+    j_rev_dct (block);
+    add_pixels_clamped_c(block, dest, line_size);
+}
+#endif
 /* init static data */
 void dsputil_static_init(void)
 {
@@ -890,3 +3088,225 @@
     
     for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
 }
+
+#if 0
+void dsputil_init(DSPContext* c, AVCodecContext *avctx)
+{
+    int i;
+
+#ifdef CONFIG_ENCODERS
+    if(avctx->dct_algo==FF_DCT_FASTINT) {
+        c->fdct = fdct_ifast;
+	c->fdct248 = fdct_ifast248;
+    } 
+    else if(avctx->dct_algo==FF_DCT_FAAN) {
+        c->fdct = ff_faandct;
+	c->fdct248 = ff_faandct248; 
+    } 
+    else {
+        c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
+	c->fdct248 = ff_fdct248_islow;
+    }
+#endif //CONFIG_ENCODERS
+
+    if(avctx->idct_algo==FF_IDCT_INT){
+        c->idct_put= ff_jref_idct_put;
+        c->idct_add= ff_jref_idct_add;
+        c->idct    = j_rev_dct;
+        c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
+    }else{ //accurate/default
+        c->idct_put= simple_idct_put;
+        c->idct_add= simple_idct_add;
+        c->idct    = simple_idct;
+        c->idct_permutation_type= FF_NO_IDCT_PERM;
+    }
+
+    c->get_pixels = get_pixels_c;
+    c->diff_pixels = diff_pixels_c;
+    c->put_pixels_clamped = put_pixels_clamped_c;
+    c->add_pixels_clamped = add_pixels_clamped_c;
+    c->gmc1 = gmc1_c;
+    c->gmc = gmc_c;
+    c->clear_blocks = clear_blocks_c;
+    c->pix_sum = pix_sum_c;
+    c->pix_norm1 = pix_norm1_c;
+
+    /* TODO [0] 16  [1] 8 */
+    c->pix_abs[0][0] = pix_abs16_c;
+    c->pix_abs[0][1] = pix_abs16_x2_c;
+    c->pix_abs[0][2] = pix_abs16_y2_c;
+    c->pix_abs[0][3] = pix_abs16_xy2_c;
+    c->pix_abs[1][0] = pix_abs8_c;
+    c->pix_abs[1][1] = pix_abs8_x2_c;
+    c->pix_abs[1][2] = pix_abs8_y2_c;
+    c->pix_abs[1][3] = pix_abs8_xy2_c;
+
+#define dspfunc(PFX, IDX, NUM) \
+    c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c;     \
+    c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c;  \
+    c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c;  \
+    c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
+
+    dspfunc(put, 0, 16);
+    dspfunc(put_no_rnd, 0, 16);
+    dspfunc(put, 1, 8);
+    dspfunc(put_no_rnd, 1, 8);
+    dspfunc(put, 2, 4);
+    dspfunc(put, 3, 2);
+
+    dspfunc(avg, 0, 16);
+    dspfunc(avg_no_rnd, 0, 16);
+    dspfunc(avg, 1, 8);
+    dspfunc(avg_no_rnd, 1, 8);
+    dspfunc(avg, 2, 4);
+    dspfunc(avg, 3, 2);
+#undef dspfunc
+
+    c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
+    c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
+    c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
+    c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
+    c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
+    c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
+    c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
+    c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
+    c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
+
+    c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
+    c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
+    c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
+    c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
+    c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
+    c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
+    c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
+    c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
+    c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
+
+#define dspfunc(PFX, IDX, NUM) \
+    c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
+    c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
+    c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
+    c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
+    c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
+    c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
+    c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
+    c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
+    c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
+    c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
+    c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
+    c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
+    c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
+    c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
+    c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
+    c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
+
+    dspfunc(put_qpel, 0, 16);
+    dspfunc(put_no_rnd_qpel, 0, 16);
+
+    dspfunc(avg_qpel, 0, 16);
+    /* dspfunc(avg_no_rnd_qpel, 0, 16); */
+
+    dspfunc(put_qpel, 1, 8);
+    dspfunc(put_no_rnd_qpel, 1, 8);
+
+    dspfunc(avg_qpel, 1, 8);
+    /* dspfunc(avg_no_rnd_qpel, 1, 8); */
+
+    dspfunc(put_h264_qpel, 0, 16);
+    dspfunc(put_h264_qpel, 1, 8);
+    dspfunc(put_h264_qpel, 2, 4);
+    dspfunc(avg_h264_qpel, 0, 16);
+    dspfunc(avg_h264_qpel, 1, 8);
+    dspfunc(avg_h264_qpel, 2, 4);
+
+#undef dspfunc
+    c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
+    c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
+    c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
+    c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
+    c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
+    c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
+
+    c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
+    c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
+    c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
+    c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
+    c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
+    c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
+    c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
+    c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
+        
+#define SET_CMP_FUNC(name) \
+    c->name[0]= name ## 16_c;\
+    c->name[1]= name ## 8x8_c;
+    
+    SET_CMP_FUNC(hadamard8_diff)
+    c->hadamard8_diff[4]= hadamard8_intra16_c;
+    SET_CMP_FUNC(dct_sad)
+    c->sad[0]= pix_abs16_c;
+    c->sad[1]= pix_abs8_c;
+    c->sse[0]= sse16_c;
+    c->sse[1]= sse8_c;
+    SET_CMP_FUNC(quant_psnr)
+    SET_CMP_FUNC(rd)
+    SET_CMP_FUNC(bit)
+    c->vsad[0]= vsad16_c;
+    c->vsad[4]= vsad_intra16_c;
+    c->vsse[0]= vsse16_c;
+    c->vsse[4]= vsse_intra16_c;
+        
+    c->add_bytes= add_bytes_c;
+    c->diff_bytes= diff_bytes_c;
+    c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
+    c->bswap_buf= bswap_buf;
+#if 0    
+    c->h263_h_loop_filter= h263_h_loop_filter_c;
+    c->h263_v_loop_filter= h263_v_loop_filter_c;
+#endif    
+    c->try_8x8basis= try_8x8basis_c;
+    c->add_8x8basis= add_8x8basis_c;
+
+#ifdef HAVE_MMX
+    dsputil_init_mmx(c, avctx);
+#endif
+#ifdef ARCH_ARMV4L
+    dsputil_init_armv4l(c, avctx);
+#endif
+#ifdef HAVE_MLIB
+    dsputil_init_mlib(c, avctx);
+#endif
+#ifdef ARCH_ALPHA
+    dsputil_init_alpha(c, avctx);
+#endif
+#ifdef ARCH_POWERPC
+    dsputil_init_ppc(c, avctx);
+#endif
+#ifdef HAVE_MMI
+    dsputil_init_mmi(c, avctx);
+#endif
+#ifdef ARCH_SH4
+    dsputil_init_sh4(c,avctx);
+#endif
+
+    switch(c->idct_permutation_type){
+    case FF_NO_IDCT_PERM:
+        for(i=0; i<64; i++)
+            c->idct_permutation[i]= i;
+        break;
+    case FF_LIBMPEG2_IDCT_PERM:
+        for(i=0; i<64; i++)
+            c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
+        break;
+    case FF_SIMPLE_IDCT_PERM:
+        for(i=0; i<64; i++)
+            c->idct_permutation[i]= simple_mmx_permutation[i];
+        break;
+    case FF_TRANSPOSE_IDCT_PERM:
+        for(i=0; i<64; i++)
+            c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
+        break;
+    default:
+        av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
+    }
+}
+#endif
--- a/Plugins/Input/wma/libffwma/dsputil.h	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/dsputil.h	Sat Nov 19 14:42:28 2005 -0800
@@ -515,7 +515,12 @@
 /* btw, rintf() is existing on fbsd too -- alex */
 static inline long int lrintf(float x)
 {
+#ifdef CONFIG_WIN32
+    /* XXX: incorrect, but make it compile */
+    return (int)(x);
+#else
     return (int)(rint(x));
+#endif
 }
 #endif
 
--- a/Plugins/Input/wma/libffwma/fft.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/fft.c	Sat Nov 19 14:42:28 2005 -0800
@@ -36,10 +36,10 @@
     s->nbits = nbits;
     n = 1 << nbits;
 
-    s->exptab = malloc((n / 2) * sizeof(FFTComplex));
+    s->exptab = av_malloc((n / 2) * sizeof(FFTComplex));
     if (!s->exptab)
         goto fail;
-    s->revtab = malloc(n * sizeof(uint16_t));
+    s->revtab = av_malloc(n * sizeof(uint16_t));
     if (!s->revtab)
         goto fail;
     s->inverse = inverse;
@@ -73,7 +73,7 @@
             np = 1 << nbits;
             nblocks = np >> 3;
             np2 = np >> 1;
-            s->exptab1 = malloc(np * 2 * sizeof(FFTComplex));
+            s->exptab1 = av_malloc(np * 2 * sizeof(FFTComplex));
             if (!s->exptab1)
                 goto fail;
             q = s->exptab1;
--- a/Plugins/Input/wma/libffwma/file.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/file.c	Sat Nov 19 14:42:28 2005 -0800
@@ -18,9 +18,15 @@
  */
 #include "avformat.h"
 #include <fcntl.h>
+#ifndef CONFIG_WIN32
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
+#else
+#include <io.h>
+#define open(fname,oflag,pmode) _open(fname,oflag,pmode)
+#endif /* CONFIG_WIN32 */
+
 
 /* standard file protocol */
 
@@ -36,7 +42,9 @@
     } else {
         access = O_RDONLY;
     }
-    
+#if defined(CONFIG_WIN32) || defined(CONFIG_OS2) || defined(__CYGWIN__)
+    access |= O_BINARY;
+#endif
     fd = open(filename, access, 0666);
     if (fd < 0)
         return -ENOENT;
@@ -60,7 +68,11 @@
 static offset_t file_seek(URLContext *h, offset_t pos, int whence)
 {
     int fd = (int)h->priv_data;
+#ifdef CONFIG_WIN32
+    return _lseeki64(fd, pos, whence);
+#else
     return lseek(fd, pos, whence);
+#endif
 }
 
 static int file_close(URLContext *h)
--- a/Plugins/Input/wma/libffwma/futils.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/futils.c	Sat Nov 19 14:42:28 2005 -0800
@@ -16,7 +16,6 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-
 #include "avformat.h"
 
 #undef NDEBUG
@@ -35,6 +34,15 @@
     format->next = NULL;
 }
 
+void av_register_output_format(AVOutputFormat *format)
+{
+    AVOutputFormat **p;
+    p = &first_oformat;
+    while (*p != NULL) p = &(*p)->next;
+    *p = format;
+    format->next = NULL;
+}
+
 int match_ext(const char *filename, const char *extensions)
 {
     const char *ext, *p;
@@ -131,8 +139,8 @@
  */
 static void av_destruct_packet(AVPacket *pkt)
 {
-	free(pkt->data);
-    	pkt->data = NULL; pkt->size = 0;
+    av_free(pkt->data);
+    pkt->data = NULL; pkt->size = 0;
 }
 
 /**
@@ -144,7 +152,7 @@
  */
 int av_new_packet(AVPacket *pkt, int size)
 {
-    void *data = malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+    void *data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
     if (!data)
         return AVERROR_NOMEM;
     memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
@@ -164,7 +172,7 @@
         uint8_t *data;
         /* we duplicate the packet and don't forget to put the padding
            again */
-        data = malloc(pkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
+        data = av_malloc(pkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
         if (!data) {
             return AVERROR_NOMEM;
         }
@@ -180,7 +188,7 @@
 
 int fifo_init(FifoBuffer *f, int size)
 {
-    f->buffer = malloc(size);
+    f->buffer = av_malloc(size);
     if (!f->buffer)
         return -1;
     f->end = f->buffer + size;
@@ -190,7 +198,7 @@
 
 void fifo_free(FifoBuffer *f)
 {
-	free(f->buffer);
+    av_free(f->buffer);
 }
 
 int fifo_size(FifoBuffer *f, uint8_t *rptr)
@@ -299,7 +307,7 @@
     int err;
     AVFormatContext *ic;
 
-    ic = malloc(sizeof(AVFormatContext));
+    ic = av_mallocz(sizeof(AVFormatContext));
     if (!ic) {
         err = AVERROR_NOMEM;
         goto fail;
@@ -313,7 +321,7 @@
 
     /* allocate private data */
     if (fmt->priv_data_size > 0) {
-        ic->priv_data = malloc(fmt->priv_data_size);
+        ic->priv_data = av_mallocz(fmt->priv_data_size);
         if (!ic->priv_data) {
             err = AVERROR_NOMEM;
             goto fail;
@@ -342,7 +350,7 @@
     if (ic) {
         av_freep(&ic->priv_data);
     }
-    free(ic);
+    av_free(ic);
     *ic_ptr = NULL;
     return err;
 }
@@ -417,6 +425,15 @@
         goto fail;
     }
         
+    /* XXX: suppress this hack for redirectors */
+#ifdef CONFIG_NETWORK
+    if (fmt == &redir_demux) {
+        err = redir_open(ic_ptr, pb);
+        url_fclose(pb);
+        return err;
+    }
+#endif
+
     /* check filename in case of an image number is expected */
     if (fmt->flags & AVFMT_NEEDNUMBER) {
         if (filename_number_test(filename) < 0) { 
@@ -542,6 +559,14 @@
     *pnum = 0;
     *pden = 0;
     switch(st->codec.codec_type) {
+    case CODEC_TYPE_VIDEO:
+        *pnum = st->codec.frame_rate_base;
+        *pden = st->codec.frame_rate;
+        if (pc && pc->repeat_pict) {
+            *pden *= 2;
+            *pnum = (*pnum) * (2 + pc->repeat_pict);
+        }
+        break;
     case CODEC_TYPE_AUDIO:
         frame_size = get_audio_frame_size(&st->codec, pkt->size);
         if (frame_size < 0)
@@ -568,7 +593,17 @@
 
     /* do we have a video B frame ? */
     presentation_delayed = 0;
-    
+    if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
+        /* XXX: need has_b_frame, but cannot get it if the codec is
+           not initialized */
+        if ((st->codec.codec_id == CODEC_ID_MPEG1VIDEO ||
+             st->codec.codec_id == CODEC_ID_MPEG2VIDEO ||
+             st->codec.codec_id == CODEC_ID_MPEG4 ||
+             st->codec.codec_id == CODEC_ID_H264) && 
+            pc && pc->pict_type != FF_B_TYPE)
+            presentation_delayed = 1;
+    }
+
     /* interpolate PTS and DTS if they are not present */
     if (presentation_delayed) {
         /* DTS = decompression time stamp */
@@ -602,8 +637,12 @@
     /* update flags */
     if (pc) {
         pkt->flags = 0;
-       /* XXX: that's odd, fix it later */ 
-	switch(st->codec.codec_type) {
+        /* key frame computation */
+        switch(st->codec.codec_type) {
+        case CODEC_TYPE_VIDEO:
+            if (pc->pict_type == FF_I_TYPE)
+                pkt->flags |= PKT_FLAG_KEY;
+            break;
         case CODEC_TYPE_AUDIO:
             pkt->flags |= PKT_FLAG_KEY;
             break;
@@ -750,7 +789,7 @@
         /* read packet from packet buffer, if there is data */
         *pkt = pktl->pkt;
         s->packet_buffer = pktl->next;
-        free(pktl);
+        av_free(pktl);
         return 0;
     } else {
         return av_read_frame_internal(s, pkt);
@@ -768,7 +807,7 @@
             break;
         s->packet_buffer = pktl->next;
         av_free_packet(&pktl->pkt);
-        free(pktl);
+        av_free(pktl);
     }
 }
 
@@ -784,7 +823,9 @@
         return -1;
     for(i = 0; i < s->nb_streams; i++) {
         st = s->streams[i];
-        
+        if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
+            return i;
+        }
     }
     return 0;
 }
@@ -827,7 +868,7 @@
     int index;
     
     entries = av_fast_realloc(st->index_entries,
-                              &st->index_entries_allocated_size,
+                              (unsigned int*)&st->index_entries_allocated_size,
                               (st->nb_index_entries + 1) * 
                               sizeof(AVIndexEntry));
     st->index_entries= entries;
@@ -1275,6 +1316,9 @@
     case CODEC_TYPE_AUDIO:
         val = enc->sample_rate;
         break;
+    case CODEC_TYPE_VIDEO:
+        val = enc->width;
+        break;
     default:
         val = 1;
         break;
@@ -1287,6 +1331,7 @@
     int16_t *samples;
     AVCodec *codec;
     int got_picture, ret;
+    AVFrame picture;
     
     codec = avcodec_find_decoder(st->codec.codec_id);
     if (!codec)
@@ -1295,18 +1340,20 @@
     if (ret < 0)
         return ret;
     switch(st->codec.codec_type) {
-    	case CODEC_TYPE_AUDIO:
-        	samples = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
-        	if (!samples)
-            		goto fail;
-        	
-		ret = avcodec_decode_audio(&st->codec, samples, 
+    case CODEC_TYPE_VIDEO:
+        ret = avcodec_decode_video(&st->codec, &picture, 
                                    &got_picture, (uint8_t *)data, size);
-        	free(samples);
-        	
-		break;
-    	default:
-        	break;
+        break;
+    case CODEC_TYPE_AUDIO:
+        samples = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
+        if (!samples)
+            goto fail;
+        ret = avcodec_decode_audio(&st->codec, samples, 
+                                   &got_picture, (uint8_t *)data, size);
+        av_free(samples);
+        break;
+    default:
+        break;
     }
  fail:
     avcodec_close(&st->codec);
@@ -1375,7 +1422,7 @@
             break;
         }
 
-        pktl = malloc(sizeof(AVPacketList));
+        pktl = av_mallocz(sizeof(AVPacketList));
         if (!pktl) {
             ret = AVERROR_NOMEM;
             break;
@@ -1405,6 +1452,13 @@
            decompress the frame. We try to avoid that in most cases as
            it takes longer and uses more memory. For MPEG4, we need to
            decompress for Quicktime. */
+        if (!has_codec_parameters(&st->codec) &&
+            (st->codec.codec_id == CODEC_ID_FLV1 ||
+             st->codec.codec_id == CODEC_ID_H264 ||
+             st->codec.codec_id == CODEC_ID_H263 ||
+             (st->codec.codec_id == CODEC_ID_MPEG4 && !st->need_parsing)))
+            try_decode_frame(st, pkt->data, pkt->size);
+        
         if (st->codec_info_duration >= MAX_STREAM_DURATION) {
             break;
         }
@@ -1414,6 +1468,37 @@
     /* set real frame rate info */
     for(i=0;i<ic->nb_streams;i++) {
         st = ic->streams[i];
+        if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
+            /* compute the real frame rate for telecine */
+            if ((st->codec.codec_id == CODEC_ID_MPEG1VIDEO ||
+                 st->codec.codec_id == CODEC_ID_MPEG2VIDEO) &&
+                st->codec.sub_id == 2) {
+                if (st->codec_info_nb_frames >= 20) {
+                    float coded_frame_rate, est_frame_rate;
+                    est_frame_rate = ((double)st->codec_info_nb_frames * AV_TIME_BASE) / 
+                        (double)st->codec_info_duration ;
+                    coded_frame_rate = (double)st->codec.frame_rate /
+                        (double)st->codec.frame_rate_base;
+#if 0
+                    printf("telecine: coded_frame_rate=%0.3f est_frame_rate=%0.3f\n", 
+                           coded_frame_rate, est_frame_rate);
+#endif
+                    /* if we detect that it could be a telecine, we
+                       signal it. It would be better to do it at a
+                       higher level as it can change in a film */
+                    if (coded_frame_rate >= 24.97 && 
+                        (est_frame_rate >= 23.5 && est_frame_rate < 24.5)) {
+                        st->r_frame_rate = 24024;
+                        st->r_frame_rate_base = 1001;
+                    }
+                }
+            }
+            /* if no real frame rate, use the codec one */
+            if (!st->r_frame_rate){
+                st->r_frame_rate      = st->codec.frame_rate;
+                st->r_frame_rate_base = st->codec.frame_rate_base;
+            }
+        }
     }
 
     av_estimate_timings(ic);
@@ -1466,8 +1551,8 @@
         if (st->parser) {
             av_parser_close(st->parser);
         }
-        free(st->index_entries);
-        free(st);
+        av_free(st->index_entries);
+        av_free(st);
     }
     flush_packet_queue(s);
     must_open_file = 1;
@@ -1478,7 +1563,7 @@
         url_fclose(&s->pb);
     }
     av_freep(&s->priv_data);
-    free(s);
+    av_free(s);
 }
 
 /**
@@ -1497,12 +1582,7 @@
     if (s->nb_streams >= MAX_STREAMS)
         return NULL;
 
-#if 0
-    /* we shouldn't have to do this but ffmpeg sucks --nenolod */
-    *s->streams = malloc(sizeof(AVStream *) * s->nb_streams);
-#endif
-
-    st = malloc(sizeof(AVStream));
+    st = av_mallocz(sizeof(AVStream));
     if (!st)
         return NULL;
     avcodec_get_context_defaults(&st->codec);
@@ -1514,8 +1594,7 @@
     st->id = id;
     st->start_time = AV_NOPTS_VALUE;
     st->duration = AV_NOPTS_VALUE;
-    s->streams[st->index] = st;
-    s->nb_streams++;	// WTF?
+    s->streams[s->nb_streams++] = st;
     return st;
 }
 
@@ -1527,7 +1606,7 @@
     int ret;
     
     if (s->oformat->priv_data_size > 0) {
-        s->priv_data = malloc(s->oformat->priv_data_size);
+        s->priv_data = av_mallocz(s->oformat->priv_data_size);
         if (!s->priv_data)
             return AVERROR_NOMEM;
     } else
@@ -1568,6 +1647,10 @@
             av_frac_init(&st->pts, 0, 0, 
                          (int64_t)s->pts_num * st->codec.sample_rate);
             break;
+        case CODEC_TYPE_VIDEO:
+            av_frac_init(&st->pts, 0, 0, 
+                         (int64_t)s->pts_num * st->codec.frame_rate);
+            break;
         default:
             break;
         }
@@ -1608,6 +1691,10 @@
                         (int64_t)s->pts_den * frame_size);
         }
         break;
+    case CODEC_TYPE_VIDEO:
+        av_frac_add(&st->pts, 
+                    (int64_t)s->pts_den * st->codec.frame_rate_base);
+        break;
     default:
         break;
     }
@@ -2213,7 +2300,7 @@
                   AVImageFormat *fmt,
                   int (*alloc_cb)(void *, AVImageInfo *info), void *opaque)
 {
-    char buf[PROBE_BUF_SIZE];
+    unsigned char buf[PROBE_BUF_SIZE];
     AVProbeData probe_data, *pd = &probe_data;
     offset_t pos;
     int ret;
--- a/Plugins/Input/wma/libffwma/mdct.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/mdct.c	Sat Nov 19 14:42:28 2005 -0800
@@ -36,10 +36,10 @@
     s->nbits = nbits;
     s->n = n;
     n4 = n >> 2;
-    s->tcos = malloc(n4 * sizeof(FFTSample));
+    s->tcos = av_malloc(n4 * sizeof(FFTSample));
     if (!s->tcos)
         goto fail;
-    s->tsin = malloc(n4 * sizeof(FFTSample));
+    s->tsin = av_malloc(n4 * sizeof(FFTSample));
     if (!s->tsin)
         goto fail;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Input/wma/libffwma/mem.c	Sat Nov 19 14:42:28 2005 -0800
@@ -0,0 +1,100 @@
+/*
+ * default memory allocator for libavcodec
+ * Copyright (c) 2002 Fabrice Bellard.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+ 
+/**
+ * @file mem.c
+ * default memory allocator for libavcodec.
+ */
+ 
+#include "avcodec.h"
+
+/* here we can use OS dependant allocation functions */
+#undef malloc
+#undef free
+#undef realloc
+
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+/* you can redefine av_malloc and av_free in your project to use your
+   memory allocator. You do not need to suppress this file because the
+   linker will do it automatically */
+
+/** 
+ * Memory allocation of size byte with alignment suitable for all
+ * memory accesses (including vectors if available on the
+ * CPU). av_malloc(0) must return a non NULL pointer.
+ */
+void *av_malloc(unsigned int size)
+{
+    void *ptr;
+    
+#if defined (HAVE_MEMALIGN)
+    ptr = memalign(16,size);
+    /* Why 64? 
+       Indeed, we should align it:
+         on 4 for 386
+         on 16 for 486
+	 on 32 for 586, PPro - k6-III
+	 on 64 for K7 (maybe for P3 too).
+       Because L1 and L2 caches are aligned on those values.
+       But I don't want to code such logic here!
+     */
+     /* Why 16?
+        because some cpus need alignment, for example SSE2 on P4, & most RISC cpus
+        it will just trigger an exception and the unaligned load will be done in the
+        exception handler or it will just segfault (SSE2 on P4)
+        Why not larger? because i didnt see a difference in benchmarks ...
+     */
+     /* benchmarks with p3
+        memalign(64)+1		3071,3051,3032
+        memalign(64)+2		3051,3032,3041
+        memalign(64)+4		2911,2896,2915
+        memalign(64)+8		2545,2554,2550
+        memalign(64)+16		2543,2572,2563
+        memalign(64)+32		2546,2545,2571
+        memalign(64)+64		2570,2533,2558
+        
+        btw, malloc seems to do 8 byte alignment by default here
+     */
+#else
+    ptr = malloc(size);
+#endif
+    return ptr;
+}
+
+/**
+ * av_realloc semantics (same as glibc): if ptr is NULL and size > 0,
+ * identical to malloc(size). If size is zero, it is identical to
+ * free(ptr) and NULL is returned.  
+ */
+void *av_realloc(void *ptr, unsigned int size)
+{
+    return realloc(ptr, size);
+}
+
+/* NOTE: ptr = NULL is explicetly allowed */
+void av_free(void *ptr)
+{
+    /* XXX: this test should not be needed on most libcs */
+    if (ptr)
+        free(ptr);
+}
+
--- a/Plugins/Input/wma/libffwma/os_support.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/os_support.c	Sat Nov 19 14:42:28 2005 -0800
@@ -17,17 +17,30 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include "avformat.h"
-
+#ifdef CONFIG_WIN32
+#include <sys/types.h>
+#include <sys/timeb.h>
+#elif defined(CONFIG_OS2)
+#include <string.h>
+#include <sys/time.h>
+#else
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/time.h>
+#endif
 #include <time.h>
 
 int64_t av_gettime(void)
 {
+#ifdef CONFIG_WIN32
+    struct _timeb tb;
+    _ftime(&tb);
+    return ((int64_t)tb.time * int64_t_C(1000) + (int64_t)tb.millitm) * int64_t_C(1000);
+#else
     struct timeval tv;
     gettimeofday(&tv,NULL);
     return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
+#endif
 }
 
 #if !defined(HAVE_LOCALTIME_R)
--- a/Plugins/Input/wma/libffwma/parser.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/parser.c	Sat Nov 19 14:42:28 2005 -0800
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include "avcodec.h"
+//#include "mpegvideo.h"
+//#include "mpegaudio.h"
 
 AVCodecParser *av_first_parser = NULL;
 
@@ -41,20 +43,20 @@
     }
     return NULL;
  found:
-    s = malloc(sizeof(AVCodecParserContext));
+    s = av_mallocz(sizeof(AVCodecParserContext));
     if (!s)
         return NULL;
     s->parser = parser;
-    s->priv_data = malloc(parser->priv_data_size);
+    s->priv_data = av_mallocz(parser->priv_data_size);
     if (!s->priv_data) {
-        free(s);
+        av_free(s);
         return NULL;
     }
     if (parser->parser_init) {
         ret = parser->parser_init(s);
         if (ret != 0) {
-            free(s->priv_data);
-            free(s);
+            av_free(s->priv_data);
+            av_free(s);
             return NULL;
         }
     }
@@ -125,10 +127,834 @@
 
 void av_parser_close(AVCodecParserContext *s)
 {
-    	if (s->parser->parser_close)
-        	s->parser->parser_close(s);
-	
-    	free(s->priv_data);
-	free(s);
+    if (s->parser->parser_close)
+        s->parser->parser_close(s);
+    av_free(s->priv_data);
+    av_free(s);
+}
+
+#if 0
+/*****************************************************/
+
+//#define END_NOT_FOUND (-100)
+
+#define PICTURE_START_CODE	0x00000100
+#define SEQ_START_CODE		0x000001b3
+#define EXT_START_CODE		0x000001b5
+#define SLICE_MIN_START_CODE	0x00000101
+#define SLICE_MAX_START_CODE	0x000001af
+
+typedef struct ParseContext1{
+    uint8_t *buffer;
+    int index;
+    int last_index;
+    int buffer_size;
+    uint32_t state;             ///< contains the last few bytes in MSB order
+    int frame_start_found;
+    int overread;               ///< the number of bytes which where irreversibly read from the next frame
+    int overread_index;         ///< the index into ParseContext1.buffer of the overreaded bytes
+
+    /* MPEG2 specific */
+    int frame_rate;
+    int progressive_sequence;
+    int width, height;
+
+    /* XXX: suppress that, needed by MPEG4 */
+    MpegEncContext *enc;
+    int first_picture;
+} ParseContext1;
+
+/**
+ * combines the (truncated) bitstream to a complete frame
+ * @returns -1 if no complete frame could be created
+ */
+static int ff_combine_frame1(ParseContext1 *pc, int next, uint8_t **buf, int *buf_size)
+{
+#if 0
+    if(pc->overread){
+        printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
+        printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
+    }
+#endif
+
+    /* copy overreaded bytes from last frame into buffer */
+    for(; pc->overread>0; pc->overread--){
+        pc->buffer[pc->index++]= pc->buffer[pc->overread_index++];
+    }
+    
+    pc->last_index= pc->index;
+
+    /* copy into buffer end return */
+    if(next == END_NOT_FOUND){
+        pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
+
+        memcpy(&pc->buffer[pc->index], *buf, *buf_size);
+        pc->index += *buf_size;
+        return -1;
+    }
+
+    *buf_size=
+    pc->overread_index= pc->index + next;
+    
+    /* append to buffer */
+    if(pc->index){
+        pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
+
+        memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE );
+        pc->index = 0;
+        *buf= pc->buffer;
+    }
+
+    /* store overread bytes */
+    for(;next < 0; next++){
+        pc->state = (pc->state<<8) | pc->buffer[pc->last_index + next];
+        pc->overread++;
+    }
+
+#if 0
+    if(pc->overread){
+        printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
+        printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
+    }
+#endif
+
+    return 0;
+}
+
+/**
+ * finds the end of the current frame in the bitstream.
+ * @return the position of the first byte of the next frame, or -1
+ */
+static int mpeg1_find_frame_end(ParseContext1 *pc, const uint8_t *buf, int buf_size)
+{
+    int i;
+    uint32_t state;
+    
+    state= pc->state;
+    
+    i=0;
+    if(!pc->frame_start_found){
+        for(i=0; i<buf_size; i++){
+            state= (state<<8) | buf[i];
+            if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){
+                i++;
+                pc->frame_start_found=1;
+                break;
+            }
+        }
+    }
+    
+    if(pc->frame_start_found){
+        /* EOF considered as end of frame */
+        if (buf_size == 0)
+            return 0;
+        for(; i<buf_size; i++){
+            state= (state<<8) | buf[i];
+            if((state&0xFFFFFF00) == 0x100){
+                if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
+                    pc->frame_start_found=0;
+                    pc->state=-1; 
+                    return i-3;
+                }
+            }
+        }
+    }        
+    pc->state= state;
+    return END_NOT_FOUND;
+}
+
+static int find_start_code(const uint8_t **pbuf_ptr, const uint8_t *buf_end)
+{
+    const uint8_t *buf_ptr;
+    unsigned int state=0xFFFFFFFF, v;
+    int val;
+
+    buf_ptr = *pbuf_ptr;
+    while (buf_ptr < buf_end) {
+        v = *buf_ptr++;
+        if (state == 0x000001) {
+            state = ((state << 8) | v) & 0xffffff;
+            val = state;
+            goto found;
+        }
+        state = ((state << 8) | v) & 0xffffff;
+    }
+    val = -1;
+ found:
+    *pbuf_ptr = buf_ptr;
+    return val;
+}
+
+/* XXX: merge with libavcodec ? */
+#define MPEG1_FRAME_RATE_BASE 1001
+
+static const int frame_rate_tab[16] = {
+        0,        
+    24000,
+    24024,
+    25025,
+    30000,
+    30030,
+    50050,
+    60000,
+    60060,
+  // Xing's 15fps: (9)
+    15015,
+  // libmpeg3's "Unofficial economy rates": (10-13)
+     5005,
+    10010,
+    12012,
+    15015,
+  // random, just to avoid segfault !never encode these
+    25025,
+    25025,
+};
+
+static void mpegvideo_extract_headers(AVCodecParserContext *s, 
+                                      AVCodecContext *avctx,
+                                      const uint8_t *buf, int buf_size)
+{
+    ParseContext1 *pc = s->priv_data;
+    const uint8_t *buf_end;
+    int32_t start_code;
+    int frame_rate_index, ext_type, bytes_left;
+    int frame_rate_ext_n, frame_rate_ext_d;
+    int top_field_first, repeat_first_field, progressive_frame;
+    int horiz_size_ext, vert_size_ext;
+
+    s->repeat_pict = 0;
+    buf_end = buf + buf_size;
+    while (buf < buf_end) {
+        start_code = find_start_code(&buf, buf_end);
+        bytes_left = buf_end - buf;
+        switch(start_code) {
+        case PICTURE_START_CODE:
+            if (bytes_left >= 2) {
+                s->pict_type = (buf[1] >> 3) & 7;
+            }
+            break;
+        case SEQ_START_CODE:
+            if (bytes_left >= 4) {
+                pc->width = avctx->width = (buf[0] << 4) | (buf[1] >> 4);
+                pc->height = avctx->height = ((buf[1] & 0x0f) << 8) | buf[2];
+                frame_rate_index = buf[3] & 0xf;
+                pc->frame_rate = avctx->frame_rate = frame_rate_tab[frame_rate_index];
+                avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE;
+                avctx->codec_id = CODEC_ID_MPEG1VIDEO;
+                avctx->sub_id = 1;
+            }
+            break;
+        case EXT_START_CODE:
+            if (bytes_left >= 1) {
+                ext_type = (buf[0] >> 4);
+                switch(ext_type) {
+                case 0x1: /* sequence extension */
+                    if (bytes_left >= 6) {
+                        horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7);
+                        vert_size_ext = (buf[2] >> 5) & 3;
+                        frame_rate_ext_n = (buf[5] >> 5) & 3;
+                        frame_rate_ext_d = (buf[5] & 0x1f);
+                        pc->progressive_sequence = buf[1] & (1 << 3);
+
+                        avctx->width = pc->width | (horiz_size_ext << 12);
+                        avctx->height = pc->height | (vert_size_ext << 12);
+                        avctx->frame_rate = pc->frame_rate * (frame_rate_ext_n + 1);
+                        avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d + 1);
+                        avctx->codec_id = CODEC_ID_MPEG2VIDEO;
+                        avctx->sub_id = 2; /* forces MPEG2 */
+                    }
+                    break;
+                case 0x8: /* picture coding extension */
+                    if (bytes_left >= 5) {
+                        top_field_first = buf[3] & (1 << 7);
+                        repeat_first_field = buf[3] & (1 << 1);
+                        progressive_frame = buf[4] & (1 << 7);
+                    
+                        /* check if we must repeat the frame */
+                        if (repeat_first_field) {
+                            if (pc->progressive_sequence) {
+                                if (top_field_first)
+                                    s->repeat_pict = 4;
+                                else
+                                    s->repeat_pict = 2;
+                            } else if (progressive_frame) {
+                                s->repeat_pict = 1;
+                            }
+                        }
+                    }
+                    break;
+                }
+            }
+            break;
+        case -1:
+            goto the_end;
+        default:
+            /* we stop parsing when we encounter a slice. It ensures
+               that this function takes a negligible amount of time */
+            if (start_code >= SLICE_MIN_START_CODE && 
+                start_code <= SLICE_MAX_START_CODE)
+                goto the_end;
+            break;
+        }
+    }
+ the_end: ;
+}
+
+static int mpegvideo_parse(AVCodecParserContext *s,
+                           AVCodecContext *avctx,
+                           uint8_t **poutbuf, int *poutbuf_size, 
+                           const uint8_t *buf, int buf_size)
+{
+    ParseContext1 *pc = s->priv_data;
+    int next;
+    
+    next= mpeg1_find_frame_end(pc, buf, buf_size);
+    
+    if (ff_combine_frame1(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+        *poutbuf = NULL;
+        *poutbuf_size = 0;
+        return buf_size;
+    }
+    /* we have a full frame : we just parse the first few MPEG headers
+       to have the full timing information. The time take by this
+       function should be negligible for uncorrupted streams */
+    mpegvideo_extract_headers(s, avctx, buf, buf_size);
+#if 0
+    printf("pict_type=%d frame_rate=%0.3f repeat_pict=%d\n", 
+           s->pict_type, (double)avctx->frame_rate / avctx->frame_rate_base, s->repeat_pict);
+#endif
+
+    *poutbuf = (uint8_t *)buf;
+    *poutbuf_size = buf_size;
+    return next;
+}
+
+static void mpegvideo_parse_close(AVCodecParserContext *s)
+{
+    ParseContext1 *pc = s->priv_data;
+
+    av_free(pc->buffer);
+    av_free(pc->enc);
+}
+
+/*************************/
+
+/**
+ * finds the end of the current frame in the bitstream.
+ * @return the position of the first byte of the next frame, or -1
+ */
+static int mpeg4_find_frame_end(ParseContext1 *pc, 
+                                const uint8_t *buf, int buf_size)
+{
+    int vop_found, i;
+    uint32_t state;
+    
+    vop_found= pc->frame_start_found;
+    state= pc->state;
+    
+    i=0;
+    if(!vop_found){
+        for(i=0; i<buf_size; i++){
+            state= (state<<8) | buf[i];
+            if(state == 0x1B6){
+                i++;
+                vop_found=1;
+                break;
+            }
+        }
+    }
+
+    if(vop_found){    
+        /* EOF considered as end of frame */
+        if (buf_size == 0)
+            return 0;
+        for(; i<buf_size; i++){
+            state= (state<<8) | buf[i];
+            if((state&0xFFFFFF00) == 0x100){
+                pc->frame_start_found=0;
+                pc->state=-1; 
+                return i-3;
+            }
+        }
+    }
+    pc->frame_start_found= vop_found;
+    pc->state= state;
+    return END_NOT_FOUND;
+}
+
+/* used by parser */
+/* XXX: make it use less memory */
+#if 0
+static int av_mpeg4_decode_header(AVCodecParserContext *s1, 
+                                  AVCodecContext *avctx,
+                                  const uint8_t *buf, int buf_size)
+{
+    ParseContext1 *pc = s1->priv_data;
+    MpegEncContext *s = pc->enc;
+    GetBitContext gb1, *gb = &gb1;
+    int ret;
+
+    s->avctx = avctx;
+    s->current_picture_ptr = &s->current_picture;
+
+    if (avctx->extradata_size && pc->first_picture){
+        init_get_bits(gb, avctx->extradata, avctx->extradata_size*8);
+        ret = ff_mpeg4_decode_picture_header(s, gb);
+    }
+
+    init_get_bits(gb, buf, 8 * buf_size);
+    ret = ff_mpeg4_decode_picture_header(s, gb);
+    if (s->width) {
+        avctx->width = s->width;
+        avctx->height = s->height;
+    }
+    pc->first_picture = 0;
+    return ret;
+}
+#endif
+
+int mpeg4video_parse_init(AVCodecParserContext *s)
+{
+    ParseContext1 *pc = s->priv_data;
+
+    pc->enc = av_mallocz(sizeof(MpegEncContext));
+    if (!pc->enc)
+        return -1;
+    pc->first_picture = 1;
+    return 0;
 }
 
+static int mpeg4video_parse(AVCodecParserContext *s,
+                           AVCodecContext *avctx,
+                           uint8_t **poutbuf, int *poutbuf_size, 
+                           const uint8_t *buf, int buf_size)
+{
+    ParseContext1 *pc = s->priv_data;
+    int next;
+    
+    next= mpeg4_find_frame_end(pc, buf, buf_size);
+
+    if (ff_combine_frame1(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+        *poutbuf = NULL;
+        *poutbuf_size = 0;
+        return buf_size;
+    }
+    av_mpeg4_decode_header(s, avctx, buf, buf_size);
+
+    *poutbuf = (uint8_t *)buf;
+    *poutbuf_size = buf_size;
+    return next;
+}
+
+/*************************/
+
+static int h263_find_frame_end(ParseContext1 *pc, const uint8_t *buf, int buf_size)
+{
+    int vop_found, i;
+    uint32_t state;
+    
+    vop_found= pc->frame_start_found;
+    state= pc->state;
+    
+    i=0;
+    if(!vop_found){
+        for(i=0; i<buf_size; i++){
+            state= (state<<8) | buf[i];
+            if(state>>(32-22) == 0x20){
+                i++;
+                vop_found=1;
+                break;
+            }
+        }
+    }
+
+    if(vop_found){    
+      for(; i<buf_size; i++){
+        state= (state<<8) | buf[i];
+        if(state>>(32-22) == 0x20){
+            pc->frame_start_found=0;
+            pc->state=-1; 
+            return i-3;
+        }
+      }
+    }
+    pc->frame_start_found= vop_found;
+    pc->state= state;
+    
+    return END_NOT_FOUND;
+}
+
+static int h263_parse(AVCodecParserContext *s,
+                           AVCodecContext *avctx,
+                           uint8_t **poutbuf, int *poutbuf_size, 
+                           const uint8_t *buf, int buf_size)
+{
+    ParseContext1 *pc = s->priv_data;
+    int next;
+    
+    next= h263_find_frame_end(pc, buf, buf_size);
+
+    if (ff_combine_frame1(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+        *poutbuf = NULL;
+        *poutbuf_size = 0;
+        return buf_size;
+    }
+
+    *poutbuf = (uint8_t *)buf;
+    *poutbuf_size = buf_size;
+    return next;
+}
+
+/*************************/
+
+/**
+ * finds the end of the current frame in the bitstream.
+ * @return the position of the first byte of the next frame, or -1
+ */
+static int h264_find_frame_end(ParseContext1 *pc, const uint8_t *buf, int buf_size)
+{
+    int i;
+    uint32_t state;
+//printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]);
+//    mb_addr= pc->mb_addr - 1;
+    state= pc->state;
+    //FIXME this will fail with slices
+    for(i=0; i<buf_size; i++){
+        state= (state<<8) | buf[i];
+        if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){
+            if(pc->frame_start_found){
+                pc->state=-1; 
+                pc->frame_start_found= 0;
+                return i-3;
+            }
+            pc->frame_start_found= 1;
+        }
+    }
+    
+    pc->state= state;
+    return END_NOT_FOUND;
+}
+
+static int h264_parse(AVCodecParserContext *s,
+                      AVCodecContext *avctx,
+                      uint8_t **poutbuf, int *poutbuf_size, 
+                      const uint8_t *buf, int buf_size)
+{
+    ParseContext1 *pc = s->priv_data;
+    int next;
+    
+    next= h264_find_frame_end(pc, buf, buf_size);
+
+    if (ff_combine_frame1(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+        *poutbuf = NULL;
+        *poutbuf_size = 0;
+        return buf_size;
+    }
+
+    *poutbuf = (uint8_t *)buf;
+    *poutbuf_size = buf_size;
+    return next;
+}
+
+/*************************/
+
+typedef struct MpegAudioParseContext {
+    uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE];	/* input buffer */
+    uint8_t *inbuf_ptr;
+    int frame_size;
+    int free_format_frame_size;
+    int free_format_next_header;
+} MpegAudioParseContext;
+
+#define MPA_HEADER_SIZE 4
+
+/* header + layer + bitrate + freq + lsf/mpeg25 */
+#define SAME_HEADER_MASK \
+   (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
+
+static int mpegaudio_parse_init(AVCodecParserContext *s1)
+{
+    MpegAudioParseContext *s = s1->priv_data;
+    s->inbuf_ptr = s->inbuf;
+    return 0;
+}
+
+static int mpegaudio_parse(AVCodecParserContext *s1,
+                           AVCodecContext *avctx,
+                           uint8_t **poutbuf, int *poutbuf_size, 
+                           const uint8_t *buf, int buf_size)
+{
+    MpegAudioParseContext *s = s1->priv_data;
+    int len, ret;
+    uint32_t header;
+    const uint8_t *buf_ptr;
+
+    *poutbuf = NULL;
+    *poutbuf_size = 0;
+    buf_ptr = buf;
+    while (buf_size > 0) {
+	len = s->inbuf_ptr - s->inbuf;
+	if (s->frame_size == 0) {
+            /* special case for next header for first frame in free
+               format case (XXX: find a simpler method) */
+            if (s->free_format_next_header != 0) {
+                s->inbuf[0] = s->free_format_next_header >> 24;
+                s->inbuf[1] = s->free_format_next_header >> 16;
+                s->inbuf[2] = s->free_format_next_header >> 8;
+                s->inbuf[3] = s->free_format_next_header;
+                s->inbuf_ptr = s->inbuf + 4;
+                s->free_format_next_header = 0;
+                goto got_header;
+            }
+	    /* no header seen : find one. We need at least MPA_HEADER_SIZE
+               bytes to parse it */
+	    len = MPA_HEADER_SIZE - len;
+	    if (len > buf_size)
+		len = buf_size;
+	    if (len > 0) {
+		memcpy(s->inbuf_ptr, buf_ptr, len);
+		buf_ptr += len;
+		buf_size -= len;
+		s->inbuf_ptr += len;
+	    }
+	    if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) {
+            got_header:
+		header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
+		    (s->inbuf[2] << 8) | s->inbuf[3];
+
+                ret = mpa_decode_header(avctx, header);
+                if (ret < 0) {
+		    /* no sync found : move by one byte (inefficient, but simple!) */
+		    memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
+		    s->inbuf_ptr--;
+                    dprintf("skip %x\n", header);
+                    /* reset free format frame size to give a chance
+                       to get a new bitrate */
+                    s->free_format_frame_size = 0;
+		} else {
+                    s->frame_size = ret;
+#if 0
+                    /* free format: prepare to compute frame size */
+		    if (decode_header(s, header) == 1) {
+			s->frame_size = -1;
+                    }
+#endif
+		}
+	    }
+        } else 
+#if 0
+        if (s->frame_size == -1) {
+            /* free format : find next sync to compute frame size */
+	    len = MPA_MAX_CODED_FRAME_SIZE - len;
+	    if (len > buf_size)
+		len = buf_size;
+            if (len == 0) {
+		/* frame too long: resync */
+                s->frame_size = 0;
+		memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
+		s->inbuf_ptr--;
+            } else {
+                uint8_t *p, *pend;
+                uint32_t header1;
+                int padding;
+
+                memcpy(s->inbuf_ptr, buf_ptr, len);
+                /* check for header */
+                p = s->inbuf_ptr - 3;
+                pend = s->inbuf_ptr + len - 4;
+                while (p <= pend) {
+                    header = (p[0] << 24) | (p[1] << 16) |
+                        (p[2] << 8) | p[3];
+                    header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
+                        (s->inbuf[2] << 8) | s->inbuf[3];
+                    /* check with high probability that we have a
+                       valid header */
+                    if ((header & SAME_HEADER_MASK) ==
+                        (header1 & SAME_HEADER_MASK)) {
+                        /* header found: update pointers */
+                        len = (p + 4) - s->inbuf_ptr;
+                        buf_ptr += len;
+                        buf_size -= len;
+                        s->inbuf_ptr = p;
+                        /* compute frame size */
+                        s->free_format_next_header = header;
+                        s->free_format_frame_size = s->inbuf_ptr - s->inbuf;
+                        padding = (header1 >> 9) & 1;
+                        if (s->layer == 1)
+                            s->free_format_frame_size -= padding * 4;
+                        else
+                            s->free_format_frame_size -= padding;
+                        dprintf("free frame size=%d padding=%d\n", 
+                                s->free_format_frame_size, padding);
+                        decode_header(s, header1);
+                        goto next_data;
+                    }
+                    p++;
+                }
+                /* not found: simply increase pointers */
+                buf_ptr += len;
+                s->inbuf_ptr += len;
+                buf_size -= len;
+            }
+	} else 
+#endif
+        if (len < s->frame_size) {
+            if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE)
+                s->frame_size = MPA_MAX_CODED_FRAME_SIZE;
+	    len = s->frame_size - len;
+	    if (len > buf_size)
+		len = buf_size;
+	    memcpy(s->inbuf_ptr, buf_ptr, len);
+	    buf_ptr += len;
+	    s->inbuf_ptr += len;
+	    buf_size -= len;
+	}
+        //    next_data:
+        if (s->frame_size > 0 && 
+            (s->inbuf_ptr - s->inbuf) >= s->frame_size) {
+            *poutbuf = s->inbuf;
+            *poutbuf_size = s->inbuf_ptr - s->inbuf;
+	    s->inbuf_ptr = s->inbuf;
+	    s->frame_size = 0;
+	    break;
+	}
+    }
+    return buf_ptr - buf;
+}
+
+#ifdef CONFIG_AC3
+extern int a52_syncinfo (const uint8_t * buf, int * flags,
+                         int * sample_rate, int * bit_rate);
+
+typedef struct AC3ParseContext {
+    uint8_t inbuf[4096]; /* input buffer */
+    uint8_t *inbuf_ptr;
+    int frame_size;
+    int flags;
+} AC3ParseContext;
+
+#define AC3_HEADER_SIZE 7
+#define A52_LFE 16
+
+static int ac3_parse_init(AVCodecParserContext *s1)
+{
+    AC3ParseContext *s = s1->priv_data;
+    s->inbuf_ptr = s->inbuf;
+    return 0;
+}
+
+static int ac3_parse(AVCodecParserContext *s1,
+                     AVCodecContext *avctx,
+                     uint8_t **poutbuf, int *poutbuf_size, 
+                     const uint8_t *buf, int buf_size)
+{
+    AC3ParseContext *s = s1->priv_data;
+    const uint8_t *buf_ptr;
+    int len, sample_rate, bit_rate;
+    static const int ac3_channels[8] = {
+	2, 1, 2, 3, 3, 4, 4, 5
+    };
+
+    *poutbuf = NULL;
+    *poutbuf_size = 0;
+
+    buf_ptr = buf;
+    while (buf_size > 0) {
+        len = s->inbuf_ptr - s->inbuf;
+        if (s->frame_size == 0) {
+            /* no header seen : find one. We need at least 7 bytes to parse it */
+            len = AC3_HEADER_SIZE - len;
+            if (len > buf_size)
+                len = buf_size;
+            memcpy(s->inbuf_ptr, buf_ptr, len);
+            buf_ptr += len;
+            s->inbuf_ptr += len;
+            buf_size -= len;
+            if ((s->inbuf_ptr - s->inbuf) == AC3_HEADER_SIZE) {
+                len = a52_syncinfo(s->inbuf, &s->flags, &sample_rate, &bit_rate);
+                if (len == 0) {
+                    /* no sync found : move by one byte (inefficient, but simple!) */
+                    memmove(s->inbuf, s->inbuf + 1, AC3_HEADER_SIZE - 1);
+                    s->inbuf_ptr--;
+                } else {
+		    s->frame_size = len;
+                    /* update codec info */
+                    avctx->sample_rate = sample_rate;
+                    avctx->channels = ac3_channels[s->flags & 7];
+                    if (s->flags & A52_LFE)
+			avctx->channels++;
+		    avctx->bit_rate = bit_rate;
+                    avctx->frame_size = 6 * 256;
+                }
+            }
+        } else if (len < s->frame_size) {
+            len = s->frame_size - len;
+            if (len > buf_size)
+                len = buf_size;
+
+            memcpy(s->inbuf_ptr, buf_ptr, len);
+            buf_ptr += len;
+            s->inbuf_ptr += len;
+            buf_size -= len;
+        } else {
+            *poutbuf = s->inbuf;
+            *poutbuf_size = s->frame_size;
+            s->inbuf_ptr = s->inbuf;
+            s->frame_size = 0;
+            break;
+        }
+    }
+    return buf_ptr - buf;
+}
+#endif
+
+AVCodecParser mpegvideo_parser = {
+    { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO },
+    sizeof(ParseContext1),
+    NULL,
+    mpegvideo_parse,
+    mpegvideo_parse_close,
+};
+
+AVCodecParser mpeg4video_parser = {
+    { CODEC_ID_MPEG4 },
+    sizeof(ParseContext1),
+    mpeg4video_parse_init,
+    mpeg4video_parse,
+    mpegvideo_parse_close,
+};
+
+AVCodecParser h263_parser = {
+    { CODEC_ID_H263 },
+    sizeof(ParseContext1),
+    NULL,
+    h263_parse,
+    mpegvideo_parse_close,
+};
+
+AVCodecParser h264_parser = {
+    { CODEC_ID_H264 },
+    sizeof(ParseContext1),
+    NULL,
+    h264_parse,
+    mpegvideo_parse_close,
+};
+
+AVCodecParser mpegaudio_parser = {
+    { CODEC_ID_MP2, CODEC_ID_MP3 },
+    sizeof(MpegAudioParseContext),
+    mpegaudio_parse_init,
+    mpegaudio_parse,
+    NULL,
+};
+
+#ifdef CONFIG_AC3
+AVCodecParser ac3_parser = {
+    { CODEC_ID_AC3 },
+    sizeof(AC3ParseContext),
+    ac3_parse_init,
+    ac3_parse,
+    NULL,
+};
+#endif
+#endif
--- a/Plugins/Input/wma/libffwma/utils.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/utils.c	Sat Nov 19 14:42:28 2005 -0800
@@ -3,7 +3,6 @@
  * Copyright (c) 2001 Fabrice Bellard.
  * Copyright (c) 2003 Michel Bardiaux for the av_log API
  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- * Copyright (c) 2004 Roman Bogorodskiy (bmp-wma specific stuff)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -20,21 +19,37 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
  
+/**
+ * @file utils.c
+ * utils.
+ */
+ 
 #include "avcodec.h"
 #include "dsputil.h"
+//#include "mpegvideo.h"
 #include <stdarg.h>
 
 void *av_mallocz(unsigned int size)
 {
-	void *ptr;
+    void *ptr;
     
-    	ptr = malloc(size);
-    	if (!ptr)
-        	return NULL;
-    
-	memset(ptr, 0, size);
-    
-	return ptr;
+    ptr = av_malloc(size);
+    if (!ptr)
+        return NULL;
+    memset(ptr, 0, size);
+    return ptr;
+}
+
+char *av_strdup(const char *s)
+{
+    char *ptr;
+    int len;
+    len = strlen(s) + 1;
+    ptr = av_malloc(len);
+    if (!ptr)
+        return NULL;
+    memcpy(ptr, s, len);
+    return ptr;
 }
 
 /**
@@ -42,12 +57,12 @@
  */
 void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
 {
-	if(min_size < *size) 
-        	return ptr;
+    if(min_size < *size) 
+        return ptr;
     
-    	*size= min_size + 10*1024;
+    *size= min_size + 10*1024;
 
-    	return realloc(ptr, *size);
+    return av_realloc(ptr, *size);
 }
 
 
@@ -65,7 +80,7 @@
     if (location)
     {
 	if (l > last_static)
-	    array_static = realloc(array_static, l);
+	    array_static = av_realloc(array_static, l);
 	array_static[last_static++] = (char**) location;
 	*location = ptr;
     }
@@ -79,10 +94,10 @@
 	unsigned i;
 	for (i = 0; i < last_static; i++)
 	{
-	    free(*array_static[i]);
+	    av_free(*array_static[i]);
             *array_static[i] = NULL;
 	}
-	free(array_static);
+	av_free(array_static);
 	array_static = 0;
     }
     last_static = 0;
@@ -91,8 +106,8 @@
 /* cannot call it directly because of 'void **' casting is not automatic */
 void __av_freep(void **ptr)
 {
-	free(*ptr);
-    	*ptr = NULL;
+    av_free(*ptr);
+    *ptr = NULL;
 }
 
 /* encoder management */
@@ -139,6 +154,11 @@
         h_align=8;
         break;
     case PIX_FMT_YUV410P:
+        if(s->codec_id == CODEC_ID_SVQ1){
+            w_align=64;
+            h_align=64;
+        }
+        break;
     default:
         w_align= 1;
         h_align= 1;
@@ -148,7 +168,102 @@
     *width = ALIGN(*width , w_align);
     *height= ALIGN(*height, h_align);
 }
+#if 0
+int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
+    int i;
+    int w= s->width;
+    int h= s->height;
+    InternalBuffer *buf;
+    int *picture_number;
+    
+    assert(pic->data[0]==NULL);
+    assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count);
 
+    if(s->internal_buffer==NULL){
+        s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer));
+    }
+#if 0
+    s->internal_buffer= av_fast_realloc(
+        s->internal_buffer, 
+        &s->internal_buffer_size, 
+        sizeof(InternalBuffer)*FFMAX(99,  s->internal_buffer_count+1)/*FIXME*/
+        );
+#endif
+     
+    buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
+    picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE-1]).last_pic_num; //FIXME ugly hack
+    (*picture_number)++;
+
+    if(buf->base[0]){
+        pic->age= *picture_number - buf->last_pic_num;
+        buf->last_pic_num= *picture_number;
+    }else{
+        int h_chroma_shift, v_chroma_shift;
+        int s_align, pixel_size;
+        
+        avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
+        
+        switch(s->pix_fmt){
+        case PIX_FMT_RGB555:
+        case PIX_FMT_RGB565:
+        case PIX_FMT_YUV422:
+            pixel_size=2;
+            break;
+        case PIX_FMT_RGB24:
+        case PIX_FMT_BGR24:
+            pixel_size=3;
+            break;
+        case PIX_FMT_RGBA32:
+            pixel_size=4;
+            break;
+        default:
+            pixel_size=1;
+        }
+
+        avcodec_align_dimensions(s, &w, &h);
+#if defined(ARCH_POWERPC) || defined(HAVE_MMI) //FIXME some cleaner check
+        s_align= 16;
+#else
+        s_align= 8;
+#endif
+#if 0            
+        if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
+            w+= EDGE_WIDTH*2;
+            h+= EDGE_WIDTH*2;
+        }
+#endif        
+        buf->last_pic_num= -256*256*256*64;
+
+        for(i=0; i<3; i++){
+            const int h_shift= i==0 ? 0 : h_chroma_shift;
+            const int v_shift= i==0 ? 0 : v_chroma_shift;
+
+            buf->linesize[i]= ALIGN(pixel_size*w>>h_shift, s_align);
+
+            buf->base[i]= av_mallocz((buf->linesize[i]*h>>v_shift)+16); //FIXME 16
+            if(buf->base[i]==NULL) return -1;
+            memset(buf->base[i], 128, buf->linesize[i]*h>>v_shift);
+#if 0        
+            if(s->flags&CODEC_FLAG_EMU_EDGE)
+                buf->data[i] = buf->base[i];
+            else
+                buf->data[i] = buf->base[i] + ALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), s_align);
+#endif
+        }
+        pic->age= 256*256*256*64;
+    }
+    pic->type= FF_BUFFER_TYPE_INTERNAL;
+
+    for(i=0; i<4; i++){
+        pic->base[i]= buf->base[i];
+        pic->data[i]= buf->data[i];
+        pic->linesize[i]= buf->linesize[i];
+    }
+    s->internal_buffer_count++;
+
+    return 0;
+}
+#endif
 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
     int i;
     InternalBuffer *buf, *last, temp;
@@ -174,8 +289,41 @@
         pic->data[i]=NULL;
 //        pic->base[i]=NULL;
     }
+//printf("R%X\n", pic->opaque);
 }
+#if 0
+int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
+    AVFrame temp_pic;
+    int i;
 
+    /* If no picture return a new buffer */
+    if(pic->data[0] == NULL) {
+        /* We will copy from buffer, so must be readable */
+        pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
+        return s->get_buffer(s, pic);
+    }
+
+    /* If internal buffer type return the same buffer */
+    if(pic->type == FF_BUFFER_TYPE_INTERNAL)
+        return 0;
+
+    /*
+     * Not internal type and reget_buffer not overridden, emulate cr buffer
+     */
+    temp_pic = *pic;
+    for(i = 0; i < 4; i++)
+        pic->data[i] = pic->base[i] = NULL;
+    pic->opaque = NULL;
+    /* Allocate new frame */
+    if (s->get_buffer(s, pic))
+        return -1;
+    /* Copy image data from old buffer to new buffer */
+    img_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
+             s->height);
+    s->release_buffer(s, &temp_pic); // Release old frame
+    return 0;
+}
+#endif
 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, enum PixelFormat * fmt){
     return fmt[0];
 }
@@ -221,7 +369,7 @@
  * this can be deallocated by simply calling free() 
  */
 AVCodecContext *avcodec_alloc_context(void){
-    AVCodecContext *avctx= malloc(sizeof(AVCodecContext));
+    AVCodecContext *avctx= av_mallocz(sizeof(AVCodecContext));
     
     if(avctx==NULL) return NULL;
     
@@ -235,7 +383,7 @@
  * this can be deallocated by simply calling free() 
  */
 AVFrame *avcodec_alloc_frame(void){
-    AVFrame *pic= malloc(sizeof(AVFrame));
+    AVFrame *pic= av_mallocz(sizeof(AVFrame));
     
     return pic;
 }
@@ -251,7 +399,7 @@
     avctx->codec_id = codec->id;
     avctx->frame_number = 0;
     if (codec->priv_data_size > 0) {
-        avctx->priv_data = malloc(codec->priv_data_size);
+        avctx->priv_data = av_mallocz(codec->priv_data_size);
         if (!avctx->priv_data) 
             return -ENOMEM;
     } else {
@@ -275,6 +423,44 @@
     return ret;
 }
 
+int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, 
+                         const AVFrame *pict)
+{
+    int ret;
+
+    ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict);
+    
+    emms_c(); //needed to avoid a emms_c() call before every return;
+
+    avctx->frame_number++;
+    return ret;
+}
+
+/** 
+ * decode a frame. 
+ * @param buf bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE larger then the actual read bytes
+ * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
+ * @param buf_size the size of the buffer in bytes
+ * @param got_picture_ptr zero if no frame could be decompressed, Otherwise, it is non zero
+ * @return -1 if error, otherwise return the number of
+ * bytes used. 
+ */
+int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, 
+                         int *got_picture_ptr,
+                         uint8_t *buf, int buf_size)
+{
+    int ret;
+    
+    ret = avctx->codec->decode(avctx, picture, got_picture_ptr, 
+                               buf, buf_size);
+
+    emms_c(); //needed to avoid a emms_c() call before every return;
+    
+    if (*got_picture_ptr)                           
+        avctx->frame_number++;
+    return ret;
+}
+
 /* decode an audio frame. return -1 if error, otherwise return the
    *number of bytes used. If no frame could be decompressed,
    *frame_size_ptr is zero. Otherwise, it is the decompressed frame
@@ -374,15 +560,56 @@
 
     if (p) {
         codec_name = p->name;
+        if (!encode && enc->codec_id == CODEC_ID_MP3) {
+            if (enc->sub_id == 2)
+                codec_name = "mp2";
+            else if (enc->sub_id == 1)
+                codec_name = "mp1";
+        }
+    } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
+        /* fake mpeg2 transport stream codec (currently not
+           registered) */
+        codec_name = "mpeg2ts";
     } else if (enc->codec_name[0] != '\0') {
         codec_name = enc->codec_name;
     } else {
         /* output avi tags */
-        snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
+        if (enc->codec_type == CODEC_TYPE_VIDEO) {
+            snprintf(buf1, sizeof(buf1), "%c%c%c%c", 
+                     enc->codec_tag & 0xff,
+                     (enc->codec_tag >> 8) & 0xff,
+                     (enc->codec_tag >> 16) & 0xff,
+                     (enc->codec_tag >> 24) & 0xff);
+        } else {
+            snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
+        }
         codec_name = buf1;
     }
 
     switch(enc->codec_type) {
+#if 0
+    case CODEC_TYPE_VIDEO:
+        snprintf(buf, buf_size,
+                 "Video: %s%s",
+                 codec_name, enc->mb_decision ? " (hq)" : "");
+        if (enc->codec_id == CODEC_ID_RAWVIDEO) {
+            snprintf(buf + strlen(buf), buf_size - strlen(buf),
+                     ", %s",
+                     avcodec_get_pix_fmt_name(enc->pix_fmt));
+        }
+        if (enc->width) {
+            snprintf(buf + strlen(buf), buf_size - strlen(buf),
+                     ", %dx%d, %0.2f fps",
+                     enc->width, enc->height, 
+                     (float)enc->frame_rate / enc->frame_rate_base);
+        }
+        if (encode) {
+            snprintf(buf + strlen(buf), buf_size - strlen(buf),
+                     ", q=%d-%d", enc->qmin, enc->qmax);
+        }
+        bitrate = enc->bit_rate;
+        break;
+#endif
     case CODEC_TYPE_AUDIO:
         snprintf(buf, buf_size,
                  "Audio: %s",
--- a/Plugins/Input/wma/libffwma/wmadec.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/libffwma/wmadec.c	Sat Nov 19 14:42:28 2005 -0800
@@ -175,8 +175,8 @@
 
     init_vlc(vlc, 9, n, table_bits, 1, 1, table_codes, 4, 4);
 
-    run_table = malloc(n * sizeof(uint16_t));
-    level_table = malloc(n * sizeof(uint16_t));
+    run_table = av_malloc(n * sizeof(uint16_t));
+    level_table = av_malloc(n * sizeof(uint16_t));
     p = levels_table;
     i = 2;
     level = 1;
@@ -449,7 +449,7 @@
         int n, j;
         float alpha;
         n = 1 << (s->frame_len_bits - i);
-        window = malloc(sizeof(float) * n);
+        window = av_malloc(sizeof(float) * n);
         alpha = M_PI / (2.0 * n);
         for(j=0;j<n;j++) {
             window[n - j - 1] = sin((j + 0.5) * alpha);
@@ -849,7 +849,7 @@
             VLC *coef_vlc;
             int level, run, sign, tindex;
             int16_t *ptr, *eptr;
-            const int16_t *level_table, *run_table;
+            const uint16_t *level_table, *run_table;
 
             /* special VLC tables are used for ms stereo because
                there is potentially less energy there */
@@ -1155,7 +1155,7 @@
         iptr = s->frame_out[ch];
 
         for(i=0;i<n;i++) {
-            a = rintf(*iptr++);
+            a = lrintf(*iptr++);
             if (a > 32767)
                 a = 32767;
             else if (a < -32768)
@@ -1272,52 +1272,49 @@
 
 static int wma_decode_end(AVCodecContext *avctx)
 {
-	WMADecodeContext *s = avctx->priv_data;
-    	int i;
+    WMADecodeContext *s = avctx->priv_data;
+    int i;
 
-    	for (i = 0; i < s->nb_block_sizes; i++)
-        	ff_mdct_end(&s->mdct_ctx[i]);
-	
-    	for (i = 0; i < s->nb_block_sizes; i++)
-        	free(s->windows[i]);
+    for(i = 0; i < s->nb_block_sizes; i++)
+        ff_mdct_end(&s->mdct_ctx[i]);
+    for(i = 0; i < s->nb_block_sizes; i++)
+        av_free(s->windows[i]);
 
-    	if (s->use_exp_vlc) {
-        	free_vlc(&s->exp_vlc);
-    	}
-    
-	if (s->use_noise_coding) {
-        	free_vlc(&s->hgain_vlc);
-    	}
+    if (s->use_exp_vlc) {
+        free_vlc(&s->exp_vlc);
+    }
+    if (s->use_noise_coding) {
+        free_vlc(&s->hgain_vlc);
+    }
+    for(i = 0;i < 2; i++) {
+        free_vlc(&s->coef_vlc[i]);
+        av_free(s->run_table[i]);
+        av_free(s->level_table[i]);
+    }
     
-	for (i = 0; i < 2; i++) {
-        	free_vlc(&s->coef_vlc[i]);
-        	free(s->run_table[i]);
-        	free(s->level_table[i]);
-    	}
-    
-    	return 0;
+    return 0;
 }
 
 AVCodec wmav1_decoder =
 {
-	"wmav1",
-    	CODEC_TYPE_AUDIO,
-    	CODEC_ID_WMAV1,
-    	sizeof(WMADecodeContext),
-    	wma_decode_init,
-    	NULL,
-    	wma_decode_end,
-    	wma_decode_superframe,
+    "wmav1",
+    CODEC_TYPE_AUDIO,
+    CODEC_ID_WMAV1,
+    sizeof(WMADecodeContext),
+    wma_decode_init,
+    NULL,
+    wma_decode_end,
+    wma_decode_superframe,
 };
 
 AVCodec wmav2_decoder =
 {
-	"wmav2",
-    	CODEC_TYPE_AUDIO,
-    	CODEC_ID_WMAV2,
-    	sizeof(WMADecodeContext),
-    	wma_decode_init,
-    	NULL,
-    	wma_decode_end,
-    	wma_decode_superframe,
+    "wmav2",
+    CODEC_TYPE_AUDIO,
+    CODEC_ID_WMAV2,
+    sizeof(WMADecodeContext),
+    wma_decode_init,
+    NULL,
+    wma_decode_end,
+    wma_decode_superframe,
 };
--- a/Plugins/Input/wma/wma.c	Sat Nov 19 05:49:16 2005 -0800
+++ b/Plugins/Input/wma/wma.c	Sat Nov 19 14:42:28 2005 -0800
@@ -1,9 +1,10 @@
-/*  
- *  Audacious, a cross-platform multimedia player.
- *  Copyright (C) 2005 Audacious Team
+/*
+ *  Audacious WMA input support
+ *  (C) 2005 Audacious development team
  *
- *  Based on BMP-WMA:
- *  Copyright (C) 2004 Roman Bogorodskiy <bogorodskiy@inbox.ru>
+ *  Based on:
+ *  xmms-wma - WMA player for BMP
+ *  Copyright (C) 2004,2005 McMCC <mcmcc@mail.ru>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -19,29 +20,41 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
-
-#include <glib.h>
-#include <glib/gprintf.h>
+#ifndef __XMMS_WMA_C__
+#define __XMMS_WMA_C__
 
-#include "audacious/plugin.h"
-#include "libaudacious/configfile.h"
-#include "libaudacious/util.h"
-#include "libaudacious/titlestring.h"
-#include "libaudacious/vfs.h"
+#include <malloc.h>
+#include <math.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
 
-#ifdef HAVE_CONFIG_H
-#	include "config.h"
-#endif
+#include <audacious/plugin.h>
+#include <libaudacious/configfile.h>
+#include <libaudacious/util.h>
+#include <libaudacious/titlestring.h>
 
 #include "avcodec.h"
 #include "avformat.h"
 #include "iir.h"
 
+#define ABOUT_TXT "Copyright (C) 2004,2005 Mokrushin I.V. aka McMCC (mcmcc@mail.ru).\n \
+This plugin based on source code " LIBAVCODEC_IDENT "\nby Fabrice Bellard from \
+http://ffmpeg.sourceforge.net.\n\n \
+This program is free software; you can redistribute it and/or modify \n \
+it under the terms of the GNU General Public License as published by \n \
+the Free Software Foundation; either version 2 of the License, or \n \
+(at your option) any later version. \n\n \
+This program is distributed in the hope that it will be useful, \n \
+but WITHOUT ANY WARRANTY; without even the implied warranty of \n \
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. \n \
+See the GNU General Public License for more details.\n"
+#define NAME "BEEPMP-WMA"
+#define VERSION "v.1.0.5"
 #define ST_BUFF 1024
 
-static GtkWidget *about_dialog;
-static GtkWidget *dialog;
-
+static GtkWidget *dialog1, *button1, *label1;
+static GtkWidget *dialog, *button, *label;
 static gboolean wma_decode = 0;
 static gboolean wma_pause = 0;
 static gboolean wma_eq_on = 0;
@@ -72,809 +85,496 @@
 
 InputPlugin wma_ip =
 {
-	NULL,           	/* Filled in by xmms */
-	NULL,           	/* Filled in by xmms */
-    	description,    	/* The description that is shown in the preferences box */
-    	wma_init,           	/* Called when the plugin is loaded */
-    	wma_about,          	/* Show the about box */
-    	NULL,  	    		/* Show the configure box */
-    	wma_is_our_file,    	/* Return 1 if the plugin can handle the file */
-    	NULL,           	/* Scan dir */
-    	wma_play_file,      	/* Play file */
-    	wma_stop,           	/* Stop */
-    	wma_do_pause,       	/* Pause */
-    	wma_seek,           	/* Seek */
-    	wma_set_eq,         	/* Set the equalizer, most plugins won't be able to do this */
-    	wma_get_time,       	/* Get the time, usually returns the output plugins output time */
-    	NULL,           	/* Get volume */
-    	NULL,           	/* Set volume */
-    	NULL,           	/* OBSOLETE! */
-    	NULL,           	/* OBSOLETE! */
-    	NULL,           	/* Send data to the visualization plugins */
-    	NULL,           	/* Fill in the stuff that is shown in the player window */
-    	NULL,           	/* Show some text in the song title box. */
-    	wma_get_song_info,  	/* Function to grab the title string */
-    	wma_file_info_box,  	/* Bring up an info window for the filename passed in */
-    	NULL            	/* Handle to the current output plugin. */
+    NULL,           	// Filled in by xmms
+    NULL,           	// Filled in by xmms
+    description,    	// The description that is shown in the preferences box
+    wma_init,           // Called when the plugin is loaded
+    wma_about,          // Show the about box
+    NULL,  	    	// Show the configure box
+    wma_is_our_file,    // Return 1 if the plugin can handle the file
+    NULL,           	// Scan dir
+    wma_play_file,      // Play file
+    wma_stop,           // Stop
+    wma_do_pause,       // Pause
+    wma_seek,           // Seek
+    wma_set_eq,         // Set the equalizer, most plugins won't be able to do this
+    wma_get_time,       // Get the time, usually returns the output plugins output time
+    NULL,           	// Get volume
+    NULL,           	// Set volume
+    NULL,           	// OBSOLETE!
+    NULL,           	// OBSOLETE!
+    NULL,           	// Send data to the visualization plugins
+    NULL,           	// Fill in the stuff that is shown in the player window
+    NULL,           	// Show some text in the song title box. Filled in by xmms
+    wma_get_song_info,  // Function to grab the title string
+    wma_file_info_box,  // Bring up an info window for the filename passed in
+    NULL            	// Handle to the current output plugin. Filled in by xmms
 };
 
 InputPlugin *get_iplugin_info(void)
 {
-	wma_ip.description = g_strdup_printf("WMA Audio Plugin");
-	return &wma_ip;
+    memset(description, 0, 64);
+    wma_ip.description = g_strdup_printf("WMA Player %s", VERSION);
+    return &wma_ip;
+}
+
+static gchar *str_twenty_to_space(gchar * str)
+{
+    gchar *match, *match_end;
+
+    g_return_val_if_fail(str != NULL, NULL);
+
+    while ((match = strstr(str, "%20"))) {
+        match_end = match + 3;
+        *match++ = ' ';
+        while (*match_end)
+            *match++ = *match_end++;
+        *match = 0;
+    }
+
+    return str;
 }
 
 static void wma_about(void) 
 {
-	static GtkWidget *aboutbox;
-	gchar *text;
+    char *title;
+    char *message;
+
+    if (dialog1) return;
     
-	if (aboutbox)
- 		return;
-	
-	text = g_strdup_printf("WMA Plugin %s\n\n"
-        		"Created by Roman Bogorodskiy <bogorodskiy@inbox.ru>\n"
-		       	"Based on xmms-wma written by Mokrushin I.V. aka McMCC <mcmcc@mail.ru>\n"
-			"See AUTHORS for details\n",
-                        VERSION);
+    title = (char *)g_malloc(80);
+    message = (char *)g_malloc(1000);
+    memset(title, 0, 80);
+    memset(message, 0, 1000);
+
+    sprintf(title, "About %s", NAME);
+    sprintf(message, "%s %s\n\n%s", NAME, VERSION, ABOUT_TXT);
 
-	aboutbox = xmms_show_message("About the WMA decoder",
-                             	text,
-                             	"OK", FALSE, NULL, NULL);
-             
-	g_free(text);
-	gtk_signal_connect(GTK_OBJECT(aboutbox), "destroy",
-                           GTK_SIGNAL_FUNC(gtk_widget_destroyed), &aboutbox);
+    dialog1 = gtk_dialog_new();
+    gtk_signal_connect(GTK_OBJECT(dialog1), "destroy",
+                        GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dialog1);
+    gtk_window_set_title(GTK_WINDOW(dialog1), title);
+    gtk_window_set_policy(GTK_WINDOW(dialog1), FALSE, FALSE, FALSE);
+    gtk_container_border_width(GTK_CONTAINER(dialog1), 5);
+    label1 = gtk_label_new(message);
+    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog1)->vbox), label1, TRUE, TRUE, 0);
+    gtk_widget_show(label1);
+
+    button1 = gtk_button_new_with_label(" Close ");
+    gtk_signal_connect_object(GTK_OBJECT(button1), "clicked",
+	                        GTK_SIGNAL_FUNC(gtk_widget_destroy),
+    	                        GTK_OBJECT(dialog1));
+    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog1)->action_area), button1,
+                     FALSE, FALSE, 0);
+
+    gtk_widget_show(button1);
+    gtk_widget_show(dialog1);
+    gtk_widget_grab_focus(button1);
+    g_free(title);
+    g_free(message);
 }
 
 static void wma_init(void)
 {
-    	avcodec_init();
-    	avcodec_register_all();
-    	av_register_all();
-    	init_iir();
+    avcodec_init();
+    avcodec_register_all();
+    av_register_all();
+    init_iir();
 }
 
 static int wma_is_our_file(char *filename)
 {
-	gchar *ext;
-    	ext = strrchr(filename, '.');
-    
-	if (ext)
-   		if (!strncasecmp(ext, ".wma", 4))
-            		return TRUE;
-    
-	return FALSE;
+    gchar *ext;
+    ext = strrchr(filename, '.');
+    if(ext)
+        if(!strcasecmp(ext, ".wma"))
+            return 1;
+    return 0;
 }
 
 static void wma_do_pause(short p)
 {
-	wma_pause = p;
-    	wma_ip.output->pause(wma_pause);
+    wma_pause = p;
+    wma_ip.output->pause(wma_pause);
 }
 
 static void wma_seek(int time) 
 {
-	wma_seekpos = time;
-    	if (wma_pause)
-		wma_ip.output->pause(0);
-	
-    	while (wma_decode && wma_seekpos!=-1) 
-		xmms_usleep(10000);
-	
-    	if (wma_pause)
-		wma_ip.output->pause(1);
+    wma_seekpos = time;
+    if(wma_pause) wma_ip.output->pause(0);
+    while(wma_decode && wma_seekpos!=-1) xmms_usleep(10000);
+    if(wma_pause) wma_ip.output->pause(1);
 }
 
 static int wma_get_time(void)
 {
-	wma_ip.output->buffer_free();
-    	if (wma_decode) 
-		return wma_ip.output->output_time();
-    
-	return -1;
+    wma_ip.output->buffer_free();
+    if(wma_decode) return wma_ip.output->output_time();
+    return -1;
 }
 
 static void wma_set_eq(int q_on, float q_preamp, float *q_bands)
 {
-	int chn;
-    	int index;
-    	float value;
+    int chn;
+    int index;
+    float value;
 
-    	wma_eq_on = q_on;
-    
-	if (wma_eq_on) {
-		q_preamp = q_preamp/1.6;
-        	for (chn = 0; chn < c->channels; chn++)
-            		preamp[chn] = 1.0 + 0.0932471 * q_preamp + 0.00279033 * q_preamp * q_preamp;
-        
-		for (index = 0; index < 10; index++) {
-            		value = q_bands[index]/1.2;
-            	
-			for (chn = 0; chn < c->channels; chn++)
-                		gain[index][chn] = 0.03 * value + 0.000999999 * value * value;
-        	}
-    	}
+    wma_eq_on = q_on;
+    if(wma_eq_on)
+    {
+	q_preamp = q_preamp/1.6;
+        for(chn = 0; chn < c->channels; chn++)
+            preamp[chn] = 1.0 + 0.0932471 * q_preamp + 0.00279033 * q_preamp * q_preamp;
+        for(index = 0; index < 10; index++)
+        {
+            value = q_bands[index]/1.2;
+            for(chn = 0; chn < c->channels; chn++)
+                gain[index][chn] = 0.03 * value + 0.000999999 * value * value;
+        }
+    }
 }
 
 static gchar *extname(const char *filename)
 {
-	gchar *ext = strrchr(filename, '.');
-    	
-	if (ext != NULL)
-        	++ext;
-    	return ext;
+    gchar *ext = strrchr(filename, '.');
+    if(ext != NULL) ++ext;
+    return ext;
+}
+
+static char *slashkill(gchar *fullname)
+{
+    gchar *splitname = strrchr(fullname, '/');
+    if(splitname != NULL) ++splitname;
+    return splitname;
 }
 
 static char* w_getstr(char* str)
 {
-	/* TODO
-	 * Seems, this function was stolen from mpg123 xmms plugin,
-	 * we need to get rid of it since I feel it is not useful)
-	 */
-	
-	if (str && strlen(str) > 0)
-        	return str;
-    
-    	return NULL;
+    if(str && strlen(str) > 0) return str;
+    return NULL;
 }
 
 static gchar *get_song_title(AVFormatContext *in, gchar * filename)
 {
-	gchar *ret = NULL;
-    	TitleInput *input;
+    gchar *ret = NULL;
+    TitleInput *input;
 
-    	XMMS_NEW_TITLEINPUT(input);
+    input = bmp_title_input_new();
     
-    	if ((in->title[0] != '\0') || (in->author[0] != '\0') || (in->album[0] != '\0') ||
-       		(in->comment[0] != '\0') || (in->genre[0] != '\0') || (in->year != 0) || (in->track != 0))
-    	{	
-		input->performer = w_getstr(in->author);
-		input->album_name = w_getstr(in->album);
-		input->track_name = w_getstr(in->title);
-		input->year = in->year;
-		input->track_number = in->track;
-		input->genre = w_getstr(in->genre);
-		input->comment = w_getstr(in->comment);
-    	}
-    
-	input->file_name = (gchar *)g_basename(filename);
-    	input->file_path = filename;
-    	input->file_ext = extname(filename);
-    	ret = xmms_get_titlestring(xmms_get_gentitle_format(), input);
-    	
-	g_free(input);
+    if((in->title[0] != '\0') || (in->author[0] != '\0') || (in->album[0] != '\0') ||
+       (in->comment[0] != '\0') || (in->genre[0] != '\0') || (in->year != 0) || (in->track != 0))
+    {	
+	input->performer = w_getstr(in->author);
+	input->album_name = w_getstr(in->album);
+	input->track_name = w_getstr(in->title);
+	input->year = in->year;
+	input->track_number = in->track;
+	input->genre = w_getstr(in->genre);
+	input->comment = w_getstr(in->comment);
+    }
+    input->file_name = g_path_get_basename(filename);
+    input->file_path = g_path_get_dirname(filename);
+    input->file_ext = extname(filename);
+    ret = xmms_get_titlestring(xmms_get_gentitle_format(), input);
+    if(input) g_free(input);
 
-    	if (!ret) {
-        	ret = g_strdup(g_basename(filename));
-            
-		if (extname(ret) != NULL)
-                	*(extname(ret) - 1) = '\0';
-    	}
-    
-	return ret;
+    if(!ret)
+    {
+	    ret = g_strdup(input->file_name);
+            if (extname(ret) != NULL)
+                    *(extname(ret) - 1) = '\0';
+    }
+    return ret;
 }
 
 static guint get_song_time(AVFormatContext *in)
 {
-	if (in->duration)
-		return in->duration/1000;
-    	else
-		return 0;
+    if(in->duration)
+	return in->duration/1000;
+    else
+	return 0;
 }
 
 static void wma_get_song_info(char *filename, char **title_real, int *len_real)
 {
-	AVFormatContext *in = NULL;
+    AVFormatContext *in = NULL;
     
-    	(*len_real) = -1;
-    	(*title_real) = NULL;
+    (*len_real) = -1;
+    (*title_real) = NULL;
 
-    	if (av_open_input_file(&in, filename, NULL, 0, NULL) < 0)
-		return;
+    if (av_open_input_file(&in, str_twenty_to_space(filename), NULL, 0, NULL) < 0)
+	return;
 	
-    	av_find_stream_info(in);
-    	(*len_real) = get_song_time(in);
-    	(*title_real) = get_song_title(in, filename);
-    	av_close_input_file(in);
+    av_find_stream_info(in);
+    (*len_real) = get_song_time(in);
+    (*title_real) = get_song_title(in, filename);
+    av_close_input_file(in);
 }
 
 static void wma_playbuff(int out_size)
 {
-	FifoBuffer f;
-    	int sst_buff;
-    
-    	fifo_init(&f, out_size*2);
-    	fifo_write(&f, wma_outbuf, out_size, &f.wptr);
+    FifoBuffer f;
+    int sst_buff;
     
-	while (!fifo_read(&f, wma_s_outbuf, wma_st_buff, &f.rptr) && wma_decode) {
-        	if (wma_eq_on)
-            		sst_buff = iir((gpointer)&wma_s_outbuf, wma_st_buff);
-        	else
-	    		sst_buff = wma_st_buff;
-		
-		if (wma_pause)
-	    		memset(wma_s_outbuf, 0, sst_buff);	
-    	
-		while (wma_ip.output->buffer_free() < wma_st_buff)
-    			xmms_usleep(20000);
-		
-		if (wma_seekpos == -1)
-			wma_ip.add_vis_pcm(wma_ip.output->written_time(), FMT_S16_NE,
-            			    	c->channels, sst_buff, (short *)wma_s_outbuf);
-	
-		wma_ip.output->write_audio((short *)wma_s_outbuf, sst_buff);
-		memset(wma_s_outbuf, 0, sst_buff);
-    	}
-    
-	fifo_free(&f);
-    	
-	return;
+    fifo_init(&f, out_size*2);
+    fifo_write(&f, wma_outbuf, out_size, &f.wptr);
+    while(!fifo_read(&f, wma_s_outbuf, wma_st_buff, &f.rptr) && wma_decode)
+    {
+        if(wma_eq_on)
+            sst_buff = iir((gpointer)&wma_s_outbuf, wma_st_buff);
+        else
+	    sst_buff = wma_st_buff;
+	if(wma_pause) memset(wma_s_outbuf, 0, sst_buff);	
+    	while(wma_ip.output->buffer_free() < wma_st_buff) xmms_usleep(20000);
+	if(wma_seekpos == -1)
+	    wma_ip.add_vis_pcm(wma_ip.output->written_time(), FMT_S16_NE,
+            			    c->channels, sst_buff, (short *)wma_s_outbuf);
+	wma_ip.output->write_audio((short *)wma_s_outbuf, sst_buff);
+	memset(wma_s_outbuf, 0, sst_buff);
+    }
+    fifo_free(&f);
+    return;
 }
 
 static void *wma_play_loop(void *arg)
 {
-	uint8_t *inbuf_ptr;
-    	int out_size, size, len;
-    	AVPacket pkt;
+    uint8_t *inbuf_ptr;
+    int out_size, size, len;
+    AVPacket pkt;
     
-	g_static_mutex_lock(&wma_mutex);
-    	
-	while (wma_decode) {
-		if (wma_seekpos != -1) {
-	    		av_seek_frame(ic, wma_idx, wma_seekpos * 1000000LL);
-	    		wma_ip.output->flush(wma_seekpos * 1000);
-	    		wma_seekpos = -1;
-		}
-
-        	if (av_read_frame(ic, &pkt) < 0)
-        		break;
+    g_static_mutex_lock(&wma_mutex);
+    while(wma_decode){
 
-        	size = pkt.size;
-        	inbuf_ptr = pkt.data;
-	
-        	if (size == 0)
-            		break;
-	
-        	while (size > 0) {
-            		len = avcodec_decode_audio(c, (short *)wma_outbuf, 
-					&out_size, inbuf_ptr, size);
-	    	
-			if (len < 0)
-        			break;
-	    
-            		if (out_size <= 0)
-                		continue;
+	if(wma_seekpos != -1)
+	{
+	    av_seek_frame(ic, wma_idx, wma_seekpos * 1000000LL);
+	    wma_ip.output->flush(wma_seekpos * 1000);
+	    wma_seekpos = -1;
+	}
 
-	    		wma_playbuff(out_size);
+        if(av_read_frame(ic, &pkt) < 0) break;
 
-            		size -= len;
-            		inbuf_ptr += len;
-            
-			if (pkt.data)
-                		av_free_packet(&pkt);
-        	}
-    	}
+        size = pkt.size;
+        inbuf_ptr = pkt.data;
 	
-    	while (wma_decode && wma_ip.output->buffer_playing()) 
-		xmms_usleep(30000);
-    
-	wma_decode = 0;
-    
-	/* XXX
-	 * that's all odd 
-	 */
+        if(size == 0) break;
 	
-	if (wma_s_outbuf)
-        	g_free(wma_s_outbuf);
-    
-	if (wma_outbuf)
-		g_free(wma_outbuf);
-    
-	if (pkt.data)
-    		av_free_packet(&pkt);
-    	if (c)
-		avcodec_close(c);
-    	if (ic)
-        	av_close_input_file(ic);
-    
-	g_static_mutex_unlock(&wma_mutex);
-    	g_thread_exit(NULL);
-	return(NULL);
+        while(size > 0){
+            len = avcodec_decode_audio(c, (short *)wma_outbuf, &out_size,
+                                       inbuf_ptr, size);
+	    if(len < 0) break;
+	    
+            if(out_size <= 0) continue;
+
+	    wma_playbuff(out_size);
+
+            size -= len;
+            inbuf_ptr += len;
+            if(pkt.data) av_free_packet(&pkt);
+        }
+    }
+    while(wma_decode && wma_ip.output->buffer_playing()) xmms_usleep(30000);
+    wma_decode = 0;
+    if(wma_s_outbuf) g_free(wma_s_outbuf);
+    if(wma_outbuf) g_free(wma_outbuf);
+    if(pkt.data) av_free_packet(&pkt);
+    if(c) avcodec_close(c);
+    if(ic) av_close_input_file(ic);
+    g_static_mutex_unlock(&wma_mutex);
+    g_thread_exit(NULL);
 }
 
 static void wma_play_file(char *filename) 
 {
-	return;
-	/*
-	Need to see if this is the cause of the big explosion
-
-	AVCodec *codec;
-
-    	if (av_open_input_file(&ic, filename, NULL, 0, NULL) < 0)
-		return;
+    AVCodec *codec;
+    
+    if(av_open_input_file(&ic, str_twenty_to_space(filename), NULL, 0, NULL) < 0) return;
+    
+    for(wma_idx = 0; wma_idx < ic->nb_streams; wma_idx++) {
+        c = &ic->streams[wma_idx]->codec;
+        if(c->codec_type == CODEC_TYPE_AUDIO) break;
+    }
 
-    	for (wma_idx = 0; wma_idx < ic->nb_streams; wma_idx++) {
-        	c = &ic->streams[wma_idx]->codec;
-        	
-		if(c->codec_type == CODEC_TYPE_AUDIO)
-            	break;
- 	}
+    av_find_stream_info(ic);
 
-    	av_find_stream_info(ic);
-
-    	codec = avcodec_find_decoder(c->codec_id);
+    codec = avcodec_find_decoder(c->codec_id);
 
-    	if (!codec)
-		return;
+    if(!codec) return;
 	
-    	if (avcodec_open(c, codec) < 0)
-		return;
+    if(avcodec_open(c, codec) < 0) return;
 	    	    
-    	wsong_title = get_song_title(ic, filename);
-    	wsong_time = get_song_time(ic);
+    wsong_title = get_song_title(ic, filename);
+    wsong_time = get_song_time(ic);
+
+    if(wma_ip.output->open_audio( FMT_S16_NE, c->sample_rate, c->channels) <= 0) return;
 
-    	if (wma_ip.output->open_audio(FMT_S16_NE, c->sample_rate, c->channels) <= 0)
-		return;
-
-    	wma_st_buff  = ST_BUFF;
-
-    	wma_ip.set_info(wsong_title, wsong_time, c->bit_rate, c->sample_rate, c->channels);
+    wma_st_buff  = ST_BUFF;
+	
+    wma_ip.set_info(wsong_title, wsong_time, c->bit_rate, c->sample_rate, c->channels);
 
-    	wma_s_outbuf = g_malloc0(wma_st_buff);
-    	wma_outbuf = g_malloc0(AVCODEC_MAX_AUDIO_FRAME_SIZE);
-    	wma_seekpos = -1;
-    	wma_decode = 1;
-    	wma_decode_thread = g_thread_create((GThreadFunc)wma_play_loop, NULL, TRUE, NULL);
-	*/
+    wma_s_outbuf = g_malloc0(wma_st_buff);
+    wma_outbuf = g_malloc0(AVCODEC_MAX_AUDIO_FRAME_SIZE);
+    wma_seekpos = -1;
+    wma_decode = 1;
+    wma_decode_thread = g_thread_create((GThreadFunc)wma_play_loop, NULL, TRUE, NULL);
 }
 
 static void wma_stop(void) 
 {
-	wma_decode = 0;
-    	
-	if (wma_pause)
-		wma_do_pause(0);
-    	
-	g_thread_join(wma_decode_thread);
-    	wma_ip.output->close_audio();
+    wma_decode = 0;
+    if(wma_pause) wma_do_pause(0);
+    g_thread_join(wma_decode_thread);
+    wma_ip.output->close_audio();
 }	
 
 static void wma_file_info_box (char *filename) 
 {
-	GtkWidget *dialog_vbox1;
-  	GtkWidget *vbox1;
-  	GtkWidget *hbox1;
-  	GtkWidget *label_name;
-  	GtkWidget *entry_filename;
-  	GtkWidget *hbox2;
-  	GtkWidget *frame_wma_info;
-  	GtkWidget *alignment1;
-  	GtkWidget *table1;
-  	GtkWidget *label_album;
-  	GtkWidget *label_year;
-  	GtkWidget *label_track;
-  	GtkWidget *label_genre;
-  	GtkWidget *label_comments;
-  	/*GtkWidget *label_copyright;*/
-  	GtkWidget *label_wma_version;
-  	GtkWidget *label_bitrate;
-  	GtkWidget *label_rate;
- 	GtkWidget *label_chans;
-  	GtkWidget *label_play_time;
-  	GtkWidget *label_filesize;
-  	GtkWidget *label_wma_vers_val;
-  	GtkWidget *label_bitrate_val;
-  	GtkWidget *label_rate_val;
-  	GtkWidget *label_chans_val;
-  	GtkWidget *label_playtime_val;
-  	GtkWidget *label_filesize_val;
-  	GtkWidget *label4;
-  	GtkWidget *frame_tags;
-  	GtkWidget *alignment2;
-  	GtkWidget *table2;
-  	GtkWidget *label_artist;
-  	GtkWidget *label_title;
-  	GtkWidget *entry_artist;
-  	GtkWidget *entry_album;
-  	GtkWidget *entry_year;
-  	GtkWidget *entry_title;
-  	GtkWidget *entry_track;
-  	GtkWidget *entry_genre;
-  	GtkWidget *entry_comments;
-  /*	GtkWidget *entry_copyright;*/
-  	GtkWidget *label5;
-  	GtkWidget *dialog_action_area1;
-  	GtkWidget *okbutton;
-	
-	AVFormatContext *in = NULL;
-    	AVCodecContext *s = NULL;
-    	AVCodec *codec;
-	gint tns, thh, tmm, tss;
-	gint i;
-	gchar *title,
-	      *channels,
-	      *bitrate,
-	      *playtime,
-	      *samplerate,
-	      *filesize;
-	VFSFile *f;
+    char *title;
+    char *tmp;
+    char *message;
+    AVFormatContext *in = NULL;
+    AVCodecContext *s = NULL;
+    AVCodec *codec;
+    int tns, thh, tmm, tss, i;
 
-	if (dialog) {
-		(void)g_printf("Info dialog is already opened!\n");
-		return;
-	}
-
-	if (av_open_input_file(&in, filename, NULL, 0, NULL) < 0) 
-		return;
-
-    	for(i = 0; i < in->nb_streams; i++) {
-        	s = &in->streams[i]->codec;
-        	if(s->codec_type == CODEC_TYPE_AUDIO)
-            		break;
-    	}
-	
-    	av_find_stream_info(in);
-    	codec = avcodec_find_decoder(s->codec_id);
+    if(dialog) return;
 
-	/* window title */
-  	title = g_strdup_printf("File Info - %s", g_basename(filename));
-  	
-	/* channels */
-    	if (s->channels == 1)
-		channels = g_strdup("MONO");
-	else
-		channels = g_strdup("STEREO");
-
-	/* bitrate */
-	bitrate = g_strdup_printf("%d Kb/s", (s->bit_rate / 1000));
-	
-	/* playtime */
-	if (in->duration != 0) {
-        	tns = in->duration/1000000LL;
-        	thh = tns/3600;
-        	tmm = (tns%3600)/60;
-        	tss = (tns%60);
-		playtime = g_strdup_printf("%02d:%02d:%02d", thh, tmm, tss);
-    	} else 
-		playtime = g_strdup("N/A");
-
-	/* samplerate */
-	samplerate = g_strdup_printf("%d Hz", s->sample_rate);
-
-	/* filesize */
-	f = vfs_fopen(filename, "rb");
+    if(av_open_input_file(&in, str_twenty_to_space(filename), NULL, 0, NULL) < 0) return;
 
-	if (f == NULL)
-		return;
-
-	vfs_fseek(f, 0, SEEK_END);
-	filesize = g_strdup_printf("%lu Bytes", vfs_ftell(f));
-	vfs_fclose(f);
-	
-  	dialog = gtk_dialog_new();
-  	
-	gtk_signal_connect(GTK_OBJECT(dialog), "destroy",
-			GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dialog);
-	
-	gtk_window_set_title(GTK_WINDOW(dialog), title);
-  	gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
-	gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
-	
-  	dialog_vbox1 = GTK_DIALOG(dialog)->vbox;
-  	gtk_widget_show(dialog_vbox1);
-
-  	vbox1 = gtk_vbox_new(FALSE, 0);
-  	gtk_widget_show(vbox1);
-  	gtk_box_pack_start(GTK_BOX(dialog_vbox1), vbox1, TRUE, TRUE, 0);
-
-  	hbox1 = gtk_hbox_new (FALSE, 0);
-  	gtk_widget_show (hbox1);
-  	gtk_box_pack_start(GTK_BOX(vbox1), hbox1, FALSE, FALSE, 0);
-
-  	label_name = gtk_label_new("<b>Name:</b>");
-  	gtk_widget_show(label_name);
-  	gtk_box_pack_start(GTK_BOX (hbox1), label_name, FALSE, FALSE, 0);
-  	gtk_misc_set_alignment(GTK_MISC (label_name), 0.48, 0.51);
-  	gtk_misc_set_padding(GTK_MISC (label_name), 10, 10);
-	gtk_label_set_use_markup(GTK_LABEL(label_name), TRUE);
-  
-  	entry_filename = gtk_entry_new();
-  	gtk_widget_show(entry_filename);
-  	gtk_box_pack_start(GTK_BOX(hbox1), entry_filename, TRUE, TRUE, 4);
-  	gtk_editable_set_editable(GTK_EDITABLE(entry_filename), FALSE);
-	gtk_entry_set_text(GTK_ENTRY(entry_filename), filename);
-  
-  	hbox2 = gtk_hbox_new(FALSE, 0);
-  	gtk_widget_show(hbox2);
-  	gtk_box_pack_start(GTK_BOX(vbox1), hbox2, TRUE, TRUE, 0);
-
-	frame_wma_info = gtk_frame_new(NULL);
-  	gtk_widget_show(frame_wma_info);
-  	gtk_box_pack_start(GTK_BOX(hbox2), frame_wma_info, TRUE, TRUE, 0);
-  	gtk_frame_set_shadow_type(GTK_FRAME (frame_wma_info), GTK_SHADOW_ETCHED_IN);
-	gtk_container_set_border_width (GTK_CONTAINER(frame_wma_info), 10);
+    for(i = 0; i < in->nb_streams; i++) {
+        s = &in->streams[i]->codec;
+        if(s->codec_type == CODEC_TYPE_AUDIO) break;
+    }
 	
-  	alignment1 = gtk_alignment_new(0.5, 0.5, 1, 1);
-  	gtk_widget_show(alignment1);
-  	gtk_container_add(GTK_CONTAINER(frame_wma_info), alignment1);
-  	gtk_alignment_set_padding(GTK_ALIGNMENT(alignment1), 0, 0, 0, 0);
-  	gtk_container_set_border_width(GTK_CONTAINER(alignment1), 2);
-
-  	table1 = gtk_table_new(6, 2, FALSE);
-  	gtk_widget_show(table1);
-  	gtk_container_add(GTK_CONTAINER(alignment1), table1);
-  	gtk_container_set_border_width(GTK_CONTAINER(table1), 6);
-  	gtk_table_set_row_spacings(GTK_TABLE(table1), 3);
-  	gtk_table_set_col_spacings(GTK_TABLE(table1), 8);
-
-  	/* WMA Version label */
-	label_wma_version = gtk_label_new("<b>WMA Version:</b>");
-  	gtk_widget_show(label_wma_version);
-  	gtk_table_attach(GTK_TABLE(table1), label_wma_version, 0, 1, 0, 1,
-                    	(GtkAttachOptions) (GTK_FILL),
-                    	(GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_wma_version), 0, 0.5);
-	gtk_label_set_use_markup(GTK_LABEL(label_wma_version), TRUE);
+    av_find_stream_info(in);
+    codec = avcodec_find_decoder(s->codec_id);
 
-	/* Bitrate */
-  	label_bitrate = gtk_label_new("<b>Bitrate:</b>");
-  	gtk_widget_show(label_bitrate);
-  	gtk_table_attach(GTK_TABLE(table1), label_bitrate, 0, 1, 1, 2,
-                    	(GtkAttachOptions) (GTK_FILL),
-                    	(GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_bitrate), 0, 0.5);
-  	gtk_label_set_use_markup(GTK_LABEL(label_bitrate), TRUE);
-
-	/* Samplerate */
-  	label_rate = gtk_label_new("<b>Samplerate:</b>");
-  	gtk_widget_show(label_rate);
-  	gtk_table_attach(GTK_TABLE(table1), label_rate, 0, 1, 2, 3,
-                    	(GtkAttachOptions) (GTK_FILL),
-                    	(GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_rate), 0, 0.5);
-  	gtk_label_set_use_markup(GTK_LABEL(label_rate), TRUE);
-
-	/* Channels */
-  	label_chans = gtk_label_new("<b>Channels:</b>");
-  	gtk_widget_show(label_chans);
-  	gtk_table_attach(GTK_TABLE (table1), label_chans, 0, 1, 3, 4,
-                    	(GtkAttachOptions) (GTK_FILL),
-                    	(GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_chans), 0, 0.5);
-  	gtk_label_set_use_markup(GTK_LABEL(label_chans), TRUE);
-
-	/* Play time */
-  	label_play_time = gtk_label_new("<b>Play time:</b>");
-  	gtk_widget_show(label_play_time);
-  	gtk_table_attach(GTK_TABLE (table1), label_play_time, 0, 1, 4, 5,
-                    	(GtkAttachOptions) (GTK_FILL),
-                    	(GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_play_time), 0, 0.5);
-  	gtk_label_set_use_markup(GTK_LABEL(label_play_time), TRUE);
+    title = (char *)g_malloc(15);
+    message = (char *)g_malloc(10000);
+    tmp = (char *)g_malloc(256);
+    memset(tmp, 0, 256);
+    memset(title, 0, 15);
+    memset(message, 0, 10000);
 
-	/* Filesize */
-  	label_filesize = gtk_label_new("<b>Filesize:</b>");
-  	gtk_widget_show(label_filesize);
-  	gtk_table_attach(GTK_TABLE(table1), label_filesize, 0, 1, 5, 6,
-                    	(GtkAttachOptions) (GTK_FILL),
-                    	(GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_filesize), 0, 0.5);
-  	gtk_label_set_use_markup(GTK_LABEL(label_filesize), TRUE);
-
-  	
-	label_wma_vers_val = gtk_label_new(codec->name);
-  	gtk_widget_show(label_wma_vers_val);
-  	gtk_table_attach(GTK_TABLE(table1), label_wma_vers_val, 1, 2, 0, 1,
-                    	(GtkAttachOptions)(GTK_FILL),
-                    	(GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_wma_vers_val), 0, 0.5);
-
-  	label_bitrate_val = gtk_label_new(bitrate);
-  	gtk_widget_show(label_bitrate_val);
-  	gtk_table_attach(GTK_TABLE(table1), label_bitrate_val, 1, 2, 1, 2,
-                    (GtkAttachOptions)(GTK_FILL),
-                    (GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_bitrate_val), 0, 0.5);
-
-  	label_rate_val = gtk_label_new(samplerate);
-  	gtk_widget_show(label_rate_val);
-  	gtk_table_attach(GTK_TABLE(table1), label_rate_val, 1, 2, 2, 3,
-                    (GtkAttachOptions)(GTK_FILL),
-                    (GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_rate_val), 0, 0.5);
-
-  	label_chans_val = gtk_label_new(channels);
-  	gtk_widget_show(label_chans_val);
-  	gtk_table_attach(GTK_TABLE(table1), label_chans_val, 1, 2, 3, 4,
-                    	(GtkAttachOptions)(GTK_FILL),
-                    	(GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC (label_chans_val), 0, 0.5);
-
-  	label_playtime_val = gtk_label_new(playtime);
-  	gtk_widget_show(label_playtime_val);
-  	gtk_table_attach(GTK_TABLE(table1), label_playtime_val, 1, 2, 4, 5,
-                    (GtkAttachOptions)(GTK_FILL),
-                    (GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_playtime_val), 0, 0.5);
-
-  	label_filesize_val = gtk_label_new(filesize);
-  	gtk_widget_show(label_filesize_val);
-  	gtk_table_attach(GTK_TABLE (table1), label_filesize_val, 1, 2, 5, 6,
-                    	(GtkAttachOptions)(GTK_FILL),
-                    	(GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_filesize_val), 0, 0.5);
-
-  	label4 = gtk_label_new ("WMA Info");
-  	gtk_widget_show(label4);
-  	gtk_frame_set_label_widget(GTK_FRAME(frame_wma_info), label4);
-
-  	frame_tags = gtk_frame_new (NULL);
-  	gtk_widget_show (frame_tags);
-  	gtk_box_pack_start (GTK_BOX (hbox2), frame_tags, TRUE, TRUE, 0);
-  	gtk_frame_set_shadow_type (GTK_FRAME (frame_tags), GTK_SHADOW_ETCHED_IN);
-	gtk_container_set_border_width (GTK_CONTAINER (frame_tags), 10);
-
-  
-  	alignment2 = gtk_alignment_new (0.5, 0.5, 1, 1);
-  	gtk_widget_show (alignment2);
- 	gtk_container_add (GTK_CONTAINER (frame_tags), alignment2);
-  	gtk_alignment_set_padding (GTK_ALIGNMENT (alignment2), 0, 0, 12, 0);
-	gtk_container_set_border_width (GTK_CONTAINER (alignment2), 2);
-
-  
-  	table2 = gtk_table_new(8, 2, FALSE);
-  	gtk_widget_show(table2);
-  	gtk_container_add(GTK_CONTAINER(alignment2), table2);
-  	gtk_container_set_border_width(GTK_CONTAINER(table2), 6);
-  	gtk_table_set_row_spacings(GTK_TABLE(table2), 3);
-  	gtk_table_set_col_spacings(GTK_TABLE(table2), 8);
-
-  	/* Artist */
-  	label_artist = gtk_label_new("<b>Artist:</b>");
-  	gtk_widget_show(label_artist);
-  	gtk_table_attach(GTK_TABLE (table2), label_artist, 0, 1, 0, 1,
-                    (GtkAttachOptions) (GTK_FILL),
-                    (GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_artist), 0, 0.5);
-	gtk_label_set_use_markup(GTK_LABEL(label_artist), TRUE);
-
-	/* Title */
-  	label_title = gtk_label_new("<b>Title:</b>");
-  	gtk_widget_show(label_title);
-  	gtk_table_attach(GTK_TABLE (table2), label_title, 0, 1, 1, 2,
-                    (GtkAttachOptions) (GTK_FILL),
-                    (GtkAttachOptions) (0), 0, 0);
-  	gtk_misc_set_alignment(GTK_MISC(label_title), 0, 0.5);
-	gtk_label_set_use_markup(GTK_LABEL(label_title), TRUE);
+    strcpy(message, "\n\n\n");
+    strcat(message, "File Name: ");
+    strcat(message, slashkill(filename));
+    strcat(message, "\n\n");
+    strcat(message, "Audio Info:\n");
+    strcat(message, "WMA Version: ");
+    strcat(message, codec->name);
+    strcat(message, "\n");
+    strcat(message, "Bitrate: ");
+    sprintf(tmp, "%d", s->bit_rate / 1000);
+    strcat(message, tmp);
+    memset(tmp, 0, 256);
+    strcat(message, " kb/s");
+    strcat(message, "\n");
+    strcat(message, "Samplerate: ");
+    sprintf(tmp, "%d", s->sample_rate);
+    strcat(message, tmp);
+    memset(tmp, 0, 256);
+    strcat(message, " Hz");
+    strcat(message, "\n");
+    strcat(message, "Channels: ");
+    if(s->channels == 1)
+	strcat(message, "MONO\n");
+    else
+	strcat(message, "STEREO\n");
+    if (in->duration != 0)
+    {
+        tns = in->duration/1000000LL;
+        thh = tns/3600;
+        tmm = (tns%3600)/60;
+        tss = (tns%60);
+	strcat(message, "Play Time: ");
+	sprintf(tmp, "%2d:%02d:%02d",thh, tmm, tss);
+        strcat(message, tmp);
+	memset(tmp, 0, 256);
+	strcat(message, "\n");
+    }
+    strcat(message, "\n");
+    strcat(message, "Text Info:\n");
+    if (in->title[0] != '\0')
+    {
+	strcat(message, "Title: ");
+	strcat(message, in->title);
+	strcat(message, "\n");
+    }	
+    if (in->author[0] != '\0')
+    {
+	strcat(message, "Author: ");
+	strcat(message, in->author);
+	strcat(message, "\n");
+    }	
+    if (in->album[0] != '\0')
+    {
+	strcat(message, "Album: ");
+	strcat(message, in->album);
+	strcat(message, "\n");
+    }
+    if (in->year != 0)
+    {
+	strcat(message, "Year: ");
+	sprintf(tmp, "%d", in->year);
+	strcat(message, tmp);
+	memset(tmp, 0, 256);
+	strcat(message, "\n");
+    }
+    if (in->track != 0)
+    {
+	strcat(message, "Track: ");
+	sprintf(tmp, "%d", in->track);
+	strcat(message, tmp);
+	memset(tmp, 0, 256);
+	strcat(message, "\n");
+    }
+    if (in->genre[0] != '\0')
+    {
+	strcat(message, "Genre: ");
+	strcat(message, in->genre);
+	strcat(message, "\n");
+    }
+    if (in->comment[0] != '\0')
+    {
+	strcat(message, "Comments: ");
+	strcat(message, in->comment);
+	strcat(message, "\n");
+    }
+    if (in->copyright[0] != '\0')
+    {
+	strcat(message, "Copyright: ");
+	strcat(message, in->copyright);
+	strcat(message, "\n");
+    }
+    strcat(message, "\n\n");
+    strcpy(title, "WMA file info:");
+    
+    if(tmp) g_free(tmp);
+    if(in) av_close_input_file(in);
 
-	/* Album */
-	label_album = gtk_label_new("<b>Album:</b>");
-	gtk_widget_show(label_album);
-	gtk_table_attach(GTK_TABLE (table2), label_album, 0, 1, 2, 3,
-			(GtkAttachOptions) (GTK_FILL),
-			(GtkAttachOptions) (0), 0, 0);
-	gtk_misc_set_alignment(GTK_MISC(label_album), 0, 0.5);
-	gtk_label_set_use_markup(GTK_LABEL(label_album), TRUE);
-			
-	/* Comments */
-	label_comments = gtk_label_new("<b>Comments:</b>");
-	gtk_widget_show(label_comments);
-	gtk_table_attach(GTK_TABLE(table2), label_comments, 0, 1, 3, 4,
-			(GtkAttachOptions) (GTK_FILL),
-			(GtkAttachOptions) (0), 0, 0);
-        gtk_misc_set_alignment(GTK_MISC(label_comments), 0, 0.5);
-	gtk_label_set_use_markup(GTK_LABEL(label_comments), TRUE);
-	
-	/* Year */
-	label_year = gtk_label_new("<b>Year:</b>");
-	gtk_widget_show(label_year);
-	gtk_table_attach(GTK_TABLE (table2), label_year, 0, 1, 4, 5,
-			(GtkAttachOptions) (GTK_FILL),
-			(GtkAttachOptions) (0), 0, 0);
-        gtk_misc_set_alignment(GTK_MISC(label_year), 0, 0.5);
-	gtk_label_set_use_markup(GTK_LABEL(label_year), TRUE);
-
-	/* Track */
-	label_track = gtk_label_new("<b>Track:</b>");
-	gtk_widget_show(label_track);
-	gtk_table_attach(GTK_TABLE (table2), label_track, 0, 1, 5, 6,
-			(GtkAttachOptions) (GTK_FILL),
-			(GtkAttachOptions) (0), 0, 0);
-        gtk_misc_set_alignment(GTK_MISC(label_track), 0, 0.5);
-	gtk_label_set_use_markup(GTK_LABEL(label_track), TRUE);
-
-	/* Genre */
-	label_genre = gtk_label_new("<b>Genre:</b>");
-	gtk_widget_show(label_genre);
-	gtk_table_attach(GTK_TABLE (table2), label_genre, 0, 1, 6, 7,
-			(GtkAttachOptions) (GTK_FILL),
-			(GtkAttachOptions) (0), 0, 0);
-        gtk_misc_set_alignment(GTK_MISC (label_genre), 0, 0.5);
-	gtk_label_set_use_markup(GTK_LABEL(label_genre), TRUE);
-		
-  
-  	entry_artist = gtk_entry_new();
-  	gtk_widget_show (entry_artist);
-  	gtk_table_attach (GTK_TABLE (table2), entry_artist, 1, 2, 0, 1,
-                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
-                    (GtkAttachOptions) (0), 0, 0);
- 	gtk_editable_set_editable (GTK_EDITABLE (entry_artist), FALSE);
-	gtk_entry_set_text(GTK_ENTRY(entry_artist), in->author);
-  
-  	entry_title = gtk_entry_new();
-  	gtk_widget_show(entry_title);
-  	gtk_table_attach (GTK_TABLE (table2), entry_title, 1, 2, 1, 2,
-                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
-                    (GtkAttachOptions) (0), 0, 0);
-  	gtk_editable_set_editable(GTK_EDITABLE (entry_title), FALSE);
-	gtk_entry_set_text(GTK_ENTRY(entry_title), in->title);
+    dialog = gtk_dialog_new();
+    gtk_signal_connect(GTK_OBJECT(dialog), "destroy",
+                        GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dialog);
+    gtk_window_set_title(GTK_WINDOW(dialog), title);
+    gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
+    gtk_container_border_width(GTK_CONTAINER(dialog), 5);
+    label = gtk_label_new(message);
+    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label, TRUE, TRUE, 0);
+    gtk_widget_show(label);
 
-	entry_album = gtk_entry_new();
-	gtk_widget_show(entry_album);
-	gtk_table_attach(GTK_TABLE (table2), entry_album, 1, 2, 2, 3,
-			(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
-			(GtkAttachOptions) (0), 0, 0);
-        gtk_editable_set_editable(GTK_EDITABLE (entry_album), FALSE);
-	gtk_entry_set_text(GTK_ENTRY(entry_album), in->album);
-
-	entry_comments = gtk_entry_new();
-	gtk_widget_show(entry_comments);
-	gtk_table_attach(GTK_TABLE (table2), entry_comments, 1, 2, 3, 4,
-			(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
-			(GtkAttachOptions) (0), 0, 0);
-        gtk_editable_set_editable(GTK_EDITABLE (entry_comments), FALSE);
-	gtk_entry_set_text(GTK_ENTRY(entry_comments), in->comment);
-
-	entry_year = gtk_entry_new();
-	gtk_widget_show(entry_year);
-	gtk_table_attach(GTK_TABLE (table2), entry_year, 1, 2, 4, 5,
-			(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
-			(GtkAttachOptions) (0), 0, 0);
-        gtk_editable_set_editable(GTK_EDITABLE (entry_year), FALSE);
-	gtk_entry_set_text(GTK_ENTRY(entry_year), g_strdup_printf("%d", in->year));
-
-	entry_track = gtk_entry_new();
-	gtk_widget_show(entry_track);
-	gtk_table_attach(GTK_TABLE (table2), entry_track, 1, 2, 5, 6,
-			(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
-	                (GtkAttachOptions) (0), 0, 0);
-        gtk_editable_set_editable(GTK_EDITABLE (entry_track), FALSE);
-	gtk_entry_set_text(GTK_ENTRY(entry_track), g_strdup_printf("%d", in->track));
+    button = gtk_button_new_with_label(" Close ");
+    gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
+	                        GTK_SIGNAL_FUNC(gtk_widget_destroy),
+    	                        GTK_OBJECT(dialog));
+    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), button,
+                     FALSE, FALSE, 0);
 
-	entry_genre = gtk_entry_new();
-	gtk_widget_show(entry_genre);
-	gtk_table_attach(GTK_TABLE (table2), entry_genre, 1, 2, 6, 7,
-			(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
-			(GtkAttachOptions) (0), 0, 0);
-        gtk_editable_set_editable(GTK_EDITABLE (entry_genre), FALSE);
-	gtk_entry_set_text(GTK_ENTRY(entry_genre), in->genre);
-		
-		
-  	label5 = gtk_label_new("Tags");
-  	gtk_widget_show(label5);
-  	gtk_frame_set_label_widget(GTK_FRAME(frame_tags), label5);
-  
-
-  	dialog_action_area1 = GTK_DIALOG(dialog)->action_area;
-  	gtk_widget_show(dialog_action_area1);
-  	gtk_button_box_set_layout(GTK_BUTTON_BOX(dialog_action_area1), GTK_BUTTONBOX_END);
-
-  	okbutton = gtk_button_new_from_stock("gtk-ok");
-  	gtk_widget_show(okbutton);
-  	gtk_dialog_add_action_widget(GTK_DIALOG(dialog), okbutton, GTK_RESPONSE_OK);
-  	GTK_WIDGET_SET_FLAGS(okbutton, GTK_CAN_DEFAULT);
-
-       	gtk_signal_connect_object(GTK_OBJECT(okbutton), "clicked",
-			GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(dialog));
-  
-	gtk_widget_show(dialog);
-
-      	g_free(title);
-	g_free(channels);
-	g_free(bitrate);
-	g_free(playtime);
-	g_free(samplerate);
-	g_free(filesize);	
+    gtk_widget_show(button);
+    gtk_widget_show(dialog);
+    gtk_widget_grab_focus(button);
+    g_free(title);
+    g_free(message);
 }
 
+#endif