changeset 5600:e9c611e71605

unused files
author arpi
date Sat, 13 Apr 2002 17:34:20 +0000
parents 3dde5e5eef90
children fd85802f755b
files adpcm.c adpcm.h dec_audio.c dec_video.c ducktm1.c mpng.c
diffstat 6 files changed, 0 insertions(+), 3448 deletions(-) [+]
line wrap: on
line diff
--- a/adpcm.c	Sat Apr 13 17:28:33 2002 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,505 +0,0 @@
-/*
-    Unified ADPCM Decoder for MPlayer
-
-    This file is in charge of decoding all of the various ADPCM data
-    formats that various entities have created. Details about the data
-    formats can be found here:
-      http://www.pcisys.net/~melanson/codecs/
-
-    (C) 2001 Mike Melanson
-*/
-
-#if 0
-#include "config.h"
-#include "bswap.h"
-#include "adpcm.h"
-#include "mp_msg.h"
-
-#define BE_16(x) (be2me_16(*(unsigned short *)(x)))
-#define BE_32(x) (be2me_32(*(unsigned int *)(x)))
-#define LE_16(x) (le2me_16(*(unsigned short *)(x)))
-#define LE_32(x) (le2me_32(*(unsigned int *)(x)))
-
-// pertinent tables
-static int adpcm_step[89] =
-{
-  7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
-  19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
-  50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
-  130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
-  337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
-  876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
-  2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
-  5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
-  15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
-};
-
-static int adpcm_index[16] =
-{
-  -1, -1, -1, -1, 2, 4, 6, 8,
-  -1, -1, -1, -1, 2, 4, 6, 8
-};
-
-static int ms_adapt_table[] =
-{
-  230, 230, 230, 230, 307, 409, 512, 614,
-  768, 614, 512, 409, 307, 230, 230, 230
-};
-
-static int ms_adapt_coeff1[] =
-{
-  256, 512, 0, 192, 240, 460, 392
-};
-
-static int ms_adapt_coeff2[] =
-{
-  0, -256, 0, 64, 0, -208, -232
-};
-
-// useful macros
-// clamp a number between 0 and 88
-#define CLAMP_0_TO_88(x)  if (x < 0) x = 0; else if (x > 88) x = 88;
-// clamp a number within a signed 16-bit range
-#define CLAMP_S16(x)  if (x < -32768) x = -32768; \
-  else if (x > 32767) x = 32767;
-// clamp a number above 16
-#define CLAMP_ABOVE_16(x)  if (x < 16) x = 16;
-// sign extend a 16-bit value
-#define SE_16BIT(x)  if (x & 0x8000) x -= 0x10000;
-// sign extend a 4-bit value
-#define SE_4BIT(x)  if (x & 0x8) x -= 0x10;
-
-void decode_nibbles(unsigned short *output,
-  int output_size, int channels,
-  int predictor_l, int index_l,
-  int predictor_r, int index_r)
-{
-  int step[2];
-  int predictor[2];
-  int index[2];
-  int diff;
-  int i;
-  int sign;
-  int delta;
-  int channel_number = 0;
-
-  step[0] = adpcm_step[index_l];
-  step[1] = adpcm_step[index_r];
-  predictor[0] = predictor_l;
-  predictor[1] = predictor_r;
-  index[0] = index_l;
-  index[1] = index_r;
-
-  for (i = 0; i < output_size; i++)
-  {
-    delta = output[i];
-
-    index[channel_number] += adpcm_index[delta];
-    CLAMP_0_TO_88(index[channel_number]);
-
-    sign = delta & 8;
-    delta = delta & 7;
-
-    diff = step[channel_number] >> 3;
-    if (delta & 4) diff += step[channel_number];
-    if (delta & 2) diff += step[channel_number] >> 1;
-    if (delta & 1) diff += step[channel_number] >> 2;
-
-    if (sign)
-      predictor[channel_number] -= diff;
-    else
-      predictor[channel_number] += diff;
-
-    CLAMP_S16(predictor[channel_number]);
-    output[i] = predictor[channel_number];
-    step[channel_number] = adpcm_step[index[channel_number]];
-
-    // toggle channel
-    channel_number ^= channels - 1;
-
-  }
-}
-
-int qt_ima_adpcm_decode_block(unsigned short *output, unsigned char *input,
-  int channels)
-{
-  int initial_predictor_l = 0;
-  int initial_predictor_r = 0;
-  int initial_index_l = 0;
-  int initial_index_r = 0;
-  int i;
-
-  initial_predictor_l = BE_16(&input[0]);
-  initial_index_l = initial_predictor_l;
-
-  // mask, sign-extend, and clamp the predictor portion
-  initial_predictor_l &= 0xFF80;
-  SE_16BIT(initial_predictor_l);
-  CLAMP_S16(initial_predictor_l);
-
-  // mask and clamp the index portion
-  initial_index_l &= 0x7F;
-  CLAMP_0_TO_88(initial_index_l);
-
-  // handle stereo
-  if (channels > 1)
-  {
-    initial_predictor_r = BE_16(&input[IMA_ADPCM_BLOCK_SIZE]);
-    initial_index_r = initial_predictor_r;
-
-    // mask, sign-extend, and clamp the predictor portion
-    initial_predictor_r &= 0xFF80;
-    SE_16BIT(initial_predictor_r);
-    CLAMP_S16(initial_predictor_r);
-
-    // mask and clamp the index portion
-    initial_index_r &= 0x7F;
-    CLAMP_0_TO_88(initial_index_r);
-  }
-
-  // break apart all of the nibbles in the block
-  if (channels == 1)
-    for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK / 2; i++)
-    {
-      output[i * 2 + 0] = input[2 + i] & 0x0F;
-      output[i * 2 + 1] = input[2 + i] >> 4;
-    }  
-  else
-    for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK / 2 * 2; i++)
-    {
-      output[i * 4 + 0] = input[2 + i] & 0x0F;
-      output[i * 4 + 1] = input[2 + IMA_ADPCM_BLOCK_SIZE + i] & 0x0F;
-      output[i * 4 + 2] = input[2 + i] >> 4;
-      output[i * 4 + 3] = input[2 + IMA_ADPCM_BLOCK_SIZE + i] >> 4;
-    }  
-
-  decode_nibbles(output,
-    IMA_ADPCM_SAMPLES_PER_BLOCK * channels, channels,
-    initial_predictor_l, initial_index_l,
-    initial_predictor_r, initial_index_r);
-
-  return IMA_ADPCM_SAMPLES_PER_BLOCK * channels;
-}
-
-int ms_ima_adpcm_decode_block(unsigned short *output, unsigned char *input,
-  int channels, int block_size)
-{
-  int initial_predictor_l = 0;
-  int initial_predictor_r = 0;
-  int initial_index_l = 0;
-  int initial_index_r = 0;
-  int i;
-
-  initial_predictor_l = BE_16(&input[0]);
-  initial_index_l = initial_predictor_l;
-
-  // mask, sign-extend, and clamp the predictor portion
-  initial_predictor_l &= 0xFF80;
-  SE_16BIT(initial_predictor_l);
-  CLAMP_S16(initial_predictor_l);
-
-  // mask and clamp the index portion
-  initial_index_l &= 0x7F;
-  CLAMP_0_TO_88(initial_index_l);
-
-  // handle stereo
-  if (channels > 1)
-  {
-    initial_predictor_r = BE_16(&input[IMA_ADPCM_BLOCK_SIZE]);
-    initial_index_r = initial_predictor_r;
-
-    // mask, sign-extend, and clamp the predictor portion
-    initial_predictor_r &= 0xFF80;
-    SE_16BIT(initial_predictor_r);
-    CLAMP_S16(initial_predictor_r);
-
-    // mask and clamp the index portion
-    initial_index_r &= 0x7F;
-    CLAMP_0_TO_88(initial_index_r);
-  }
-
-  // break apart all of the nibbles in the block
-  if (channels == 1)
-    for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK / 2; i++)
-    {
-      output[i * 2 + 0] = input[2 + i] & 0x0F;
-      output[i * 2 + 1] = input[2 + i] >> 4;
-    }  
-  else
-    for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK / 2 * 2; i++)
-    {
-      output[i * 4 + 0] = input[2 + i] & 0x0F;
-      output[i * 4 + 1] = input[2 + IMA_ADPCM_BLOCK_SIZE + i] & 0x0F;
-      output[i * 4 + 2] = input[2 + i] >> 4;
-      output[i * 4 + 3] = input[2 + IMA_ADPCM_BLOCK_SIZE + i] >> 4;
-    }  
-
-  decode_nibbles(output,
-    IMA_ADPCM_SAMPLES_PER_BLOCK * channels, channels,
-    initial_predictor_l, initial_index_l,
-    initial_predictor_r, initial_index_r);
-
-  return IMA_ADPCM_SAMPLES_PER_BLOCK * channels;
-}
-
-int ms_adpcm_decode_block(unsigned short *output, unsigned char *input,
-  int channels, int block_size)
-{
-  int current_channel = 0;
-  int idelta[2];
-  int sample1[2];
-  int sample2[2];
-  int coeff1[2];
-  int coeff2[2];
-  int stream_ptr = 0;
-  int out_ptr = 0;
-  int upper_nibble = 1;
-  int nibble;
-  int snibble;  // signed nibble
-  int predictor;
-
-  // fetch the header information, in stereo if both channels are present
-  if (input[stream_ptr] > 6)
-    mp_msg(MSGT_DECAUDIO, MSGL_WARN,
-      "MS ADPCM: coefficient (%d) out of range (should be [0..6])\n",
-      input[stream_ptr]);
-  coeff1[0] = ms_adapt_coeff1[input[stream_ptr]];
-  coeff2[0] = ms_adapt_coeff2[input[stream_ptr]];
-  stream_ptr++;
-  if (channels == 2)
-  {
-    if (input[stream_ptr] > 6)
-     mp_msg(MSGT_DECAUDIO, MSGL_WARN,
-       "MS ADPCM: coefficient (%d) out of range (should be [0..6])\n",
-       input[stream_ptr]);
-    coeff1[1] = ms_adapt_coeff1[input[stream_ptr]];
-    coeff2[1] = ms_adapt_coeff2[input[stream_ptr]];
-    stream_ptr++;
-  }
-
-  idelta[0] = LE_16(&input[stream_ptr]);
-  stream_ptr += 2;
-  SE_16BIT(idelta[0]);
-  if (channels == 2)
-  {
-    idelta[1] = LE_16(&input[stream_ptr]);
-    stream_ptr += 2;
-    SE_16BIT(idelta[1]);
-  }
-
-  sample1[0] = LE_16(&input[stream_ptr]);
-  stream_ptr += 2;
-  SE_16BIT(sample1[0]);
-  if (channels == 2)
-  {
-    sample1[1] = LE_16(&input[stream_ptr]);
-    stream_ptr += 2;
-    SE_16BIT(sample1[1]);
-  }
-
-  sample2[0] = LE_16(&input[stream_ptr]);
-  stream_ptr += 2;
-  SE_16BIT(sample2[0]);
-  if (channels == 2)
-  {
-    sample2[1] = LE_16(&input[stream_ptr]);
-    stream_ptr += 2;
-    SE_16BIT(sample2[1]);
-  }
-
-  while (stream_ptr < block_size)
-  {
-    // get the next nibble
-    if (upper_nibble)
-      nibble = snibble = input[stream_ptr] >> 4;
-    else
-      nibble = snibble = input[stream_ptr++] & 0x0F;
-    upper_nibble ^= 1;
-    SE_4BIT(snibble);
-
-    predictor = (
-      ((sample1[current_channel] * coeff1[current_channel]) +
-       (sample2[current_channel] * coeff2[current_channel])) / 256) +
-      (snibble * idelta[current_channel]);
-    CLAMP_S16(predictor);
-    sample2[current_channel] = sample1[current_channel];
-    sample1[current_channel] = predictor;
-    output[out_ptr++] = predictor;
-
-    // compute the next adaptive scale factor (a.k.a. the variable idelta)
-    idelta[current_channel] = 
-      (ms_adapt_table[nibble] * idelta[current_channel]) / 256;
-    CLAMP_ABOVE_16(idelta[current_channel]);
-
-    // toggle the channel
-    current_channel ^= channels - 1;
-  }
-
-  return (block_size - (MS_ADPCM_PREAMBLE_SIZE * channels)) * 2;
-}
-
-int dk4_adpcm_decode_block(unsigned short *output, unsigned char *input,
-  int channels, int block_size)
-{
-  int i;
-  int output_ptr;
-  int predictor_l = 0;
-  int predictor_r = 0;
-  int index_l = 0;
-  int index_r = 0;
-
-  // the first predictor value goes straight to the output
-  predictor_l = output[0] = LE_16(&input[0]);
-  SE_16BIT(predictor_l);
-  index_l = input[2];
-  if (channels == 2)
-  {
-    predictor_r = output[1] = LE_16(&input[4]);
-    SE_16BIT(predictor_r);
-    index_r = input[6];
-  }
-
-  output_ptr = channels;
-  for (i = DK4_ADPCM_PREAMBLE_SIZE * channels; i < block_size; i++)
-  {
-    output[output_ptr++] = input[i] >> 4;
-    output[output_ptr++] = input[i] & 0x0F;
-  }  
-
-  decode_nibbles(&output[channels],
-  (block_size - DK4_ADPCM_PREAMBLE_SIZE * channels) * 2 - channels,
-  channels,
-  predictor_l, index_l,
-  predictor_r, index_r);
-
-  return (block_size - DK4_ADPCM_PREAMBLE_SIZE * channels) * 2 - channels;
-}
-
-#define DK3_GET_NEXT_NIBBLE() \
-    if (decode_top_nibble_next) \
-    { \
-      nibble = (last_byte >> 4) & 0x0F; \
-      decode_top_nibble_next = 0; \
-    } \
-    else \
-    { \
-      last_byte = input[in_ptr++]; \
-      nibble = last_byte & 0x0F; \
-      decode_top_nibble_next = 1; \
-    }
-
-// note: This decoder assumes the format 0x62 data always comes in
-// stereo flavor
-int dk3_adpcm_decode_block(unsigned short *output, unsigned char *input)
-{
-  int sum_pred;
-  int diff_pred;
-  int sum_index;
-  int diff_index;
-  int diff_channel;
-  int in_ptr = 0x10;
-  int out_ptr = 0;
-
-  unsigned char last_byte = 0;
-  unsigned char nibble;
-  int decode_top_nibble_next = 0;
-
-  // ADPCM work variables
-  int sign;
-  int delta;
-  int step;
-  int diff;
-
-  sum_pred = LE_16(&input[10]);
-  diff_pred = LE_16(&input[12]);
-  SE_16BIT(sum_pred);
-  SE_16BIT(diff_pred);
-  diff_channel = diff_pred;
-  sum_index = input[14];
-  diff_index = input[15];
-
-  while (in_ptr < 2048)
-  {
-    // process the first predictor of the sum channel
-    DK3_GET_NEXT_NIBBLE();
-
-    step = adpcm_step[sum_index];
-
-    sign = nibble & 8;
-    delta = nibble & 7;
-
-    diff = step >> 3;
-    if (delta & 4) diff += step;
-    if (delta & 2) diff += step >> 1;
-    if (delta & 1) diff += step >> 2;
-
-    if (sign)
-      sum_pred -= diff;
-    else
-      sum_pred += diff;
-
-    CLAMP_S16(sum_pred);
-
-    sum_index += adpcm_index[nibble];
-    CLAMP_0_TO_88(sum_index);
-    
-    // process the diff channel predictor
-    DK3_GET_NEXT_NIBBLE();
-
-    step = adpcm_step[diff_index];
-
-    sign = nibble & 8;
-    delta = nibble & 7;
-
-    diff = step >> 3;
-    if (delta & 4) diff += step;
-    if (delta & 2) diff += step >> 1;
-    if (delta & 1) diff += step >> 2;
-
-    if (sign)
-      diff_pred -= diff;
-    else
-      diff_pred += diff;
-
-    CLAMP_S16(diff_pred);
-
-    diff_index += adpcm_index[nibble];
-    CLAMP_0_TO_88(diff_index);
-
-    // output the first pair of stereo PCM samples
-    diff_channel = (diff_channel + diff_pred) / 2;
-    output[out_ptr++] = sum_pred + diff_channel;
-    output[out_ptr++] = sum_pred - diff_channel;
-
-    // process the second predictor of the sum channel
-    DK3_GET_NEXT_NIBBLE();
-
-    step = adpcm_step[sum_index];
-
-    sign = nibble & 8;
-    delta = nibble & 7;
-
-    diff = step >> 3;
-    if (delta & 4) diff += step;
-    if (delta & 2) diff += step >> 1;
-    if (delta & 1) diff += step >> 2;
-
-    if (sign)
-      sum_pred -= diff;
-    else
-      sum_pred += diff;
-
-    CLAMP_S16(sum_pred);
-
-    sum_index += adpcm_index[nibble];
-    CLAMP_0_TO_88(sum_index);
-
-    // output the second pair of stereo PCM samples
-    output[out_ptr++] = sum_pred + diff_channel;
-    output[out_ptr++] = sum_pred - diff_channel;
-  }
-
-  return out_ptr;
-}
-#endif
-
--- a/adpcm.h	Sat Apr 13 17:28:33 2002 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-#ifndef ADPCM_H
-#define ADPCM_H
-
-#define IMA_ADPCM_PREAMBLE_SIZE 2
-#define IMA_ADPCM_BLOCK_SIZE 0x22
-#define IMA_ADPCM_SAMPLES_PER_BLOCK \
-  ((IMA_ADPCM_BLOCK_SIZE - IMA_ADPCM_PREAMBLE_SIZE) * 2)
-
-#define MS_ADPCM_PREAMBLE_SIZE 7
-#define MS_ADPCM_SAMPLES_PER_BLOCK \
-  ((sh_audio->wf->nBlockAlign - MS_ADPCM_PREAMBLE_SIZE) * 2)
-
-#define DK4_ADPCM_PREAMBLE_SIZE 4
-#define DK4_ADPCM_SAMPLES_PER_BLOCK \
-  (((sh_audio->wf->nBlockAlign - DK4_ADPCM_PREAMBLE_SIZE) * 2) + 1)
-
-// pretend there's such a thing as mono for this format
-#define DK3_ADPCM_PREAMBLE_SIZE 8
-#define DK3_ADPCM_BLOCK_SIZE 0x400
-// this isn't exact
-#define DK3_ADPCM_SAMPLES_PER_BLOCK 6000
-
-int qt_ima_adpcm_decode_block(unsigned short *output, unsigned char *input,
-  int channels);
-int ms_ima_adpcm_decode_block(unsigned short *output, unsigned char *input,
-  int channels, int block_size);
-int ms_adpcm_decode_block(unsigned short *output, unsigned char *input,
-  int channels, int block_size);
-int dk4_adpcm_decode_block(unsigned short *output, unsigned char *input,
-  int channels, int block_size);
-int dk3_adpcm_decode_block(unsigned short *output, unsigned char *input);
-
-#endif
--- a/dec_audio.c	Sat Apr 13 17:28:33 2002 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1444 +0,0 @@
-
-#define USE_G72X
-//#define USE_LIBAC3
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "config.h"
-#include "mp_msg.h"
-#include "help_mp.h"
-
-extern int verbose; // defined in mplayer.c
-
-#include "stream.h"
-#include "demuxer.h"
-
-#include "codec-cfg.h"
-#include "stheader.h"
-
-#include "dec_audio.h"
-
-#include "roqav.h"
-
-//==========================================================================
-
-#include "libao2/afmt.h"
-
-#include "dll_init.h"
-
-#include "mp3lib/mp3.h"
-
-#ifdef USE_LIBAC3
-#include "libac3/ac3.h"
-#endif
-
-#include "liba52/a52.h"
-#include "liba52/mm_accel.h"
-static sample_t * a52_samples;
-static a52_state_t a52_state;
-static uint32_t a52_accel=0;
-static uint32_t a52_flags=0;
-
-#ifdef USE_G72X
-#include "g72x/g72x.h"
-static G72x_DATA g72x_data;
-#endif
-
-#include "alaw.h"
-
-#include "xa/xa_gsm.h"
-
-#include "ac3-iec958.h"
-
-#include "adpcm.h"
-
-#include "cpudetect.h"
-
-/* used for ac3surround decoder - set using -channels option */
-int audio_output_channels = 2;
-
-#ifdef USE_FAKE_MONO
-int fakemono=0;
-#endif
-
-#ifdef USE_DIRECTSHOW
-#include "loader/dshow/DS_AudioDecoder.h"
-static DS_AudioDecoder* ds_adec=NULL;
-#endif
-
-#ifdef HAVE_OGGVORBIS
-/* XXX is math.h really needed? - atmos */
-#include <math.h>
-#include <vorbis/codec.h>
-
-// This struct is also defined in demux_ogg.c => common header ?
-typedef struct ov_struct_st {
-  vorbis_info      vi; /* struct that stores all the static vorbis bitstream
-			  settings */
-  vorbis_comment   vc; /* struct that stores all the bitstream user comments */
-  vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
-  vorbis_block     vb; /* local working space for packet->PCM decode */
-} ov_struct_t;
-#endif
-
-#ifdef HAVE_FAAD
-#include <faad.h>
-static faacDecHandle faac_hdec;
-static faacDecFrameInfo faac_finfo;
-static int faac_bytesconsumed = 0;
-static unsigned char *faac_buffer;
-/* configure maximum supported channels, *
- * this is theoretically max. 64 chans   */
-#define FAAD_MAX_CHANNELS 6
-#define FAAD_BUFFLEN (FAAD_MIN_STREAMSIZE*FAAD_MAX_CHANNELS)		       
-#endif
-
-#ifdef USE_LIBAVCODEC
-#ifdef USE_LIBAVCODEC_SO
-#include <libffmpeg/avcodec.h>
-#else
-#include "libavcodec/avcodec.h"
-#endif
-    static AVCodec *lavc_codec=NULL;
-    static AVCodecContext lavc_context;
-    extern int avcodec_inited;
-#endif
-
-
-
-#ifdef USE_LIBMAD
-#include <mad.h>
-
-#define MAD_SINGLE_BUFFER_SIZE 8192
-#define MAD_TOTAL_BUFFER_SIZE  ((MAD_SINGLE_BUFFER_SIZE)*3)
-
-static struct mad_stream mad_stream;
-static struct mad_frame  mad_frame;
-static struct mad_synth  mad_synth;
-static char*  mad_in_buffer = 0; /* base pointer of buffer */
-
-// ensure buffer is filled with some data
-static void mad_prepare_buffer(sh_audio_t* sh_audio, struct mad_stream* ms, int length)
-{
-  if(sh_audio->a_in_buffer_len < length) {
-    int len = demux_read_data(sh_audio->ds, sh_audio->a_in_buffer+sh_audio->a_in_buffer_len, length-sh_audio->a_in_buffer_len);
-    sh_audio->a_in_buffer_len += len;
-//    printf("mad_prepare_buffer: read %d bytes\n", len);
-  }
-}
-
-static void mad_postprocess_buffer(sh_audio_t* sh_audio, struct mad_stream* ms)
-{
-  /* rotate buffer while possible, in order to reduce the overhead of endless memcpy */
-  int delta = (unsigned char*)ms->next_frame - (unsigned char *)sh_audio->a_in_buffer;
-  if((unsigned long)(sh_audio->a_in_buffer) - (unsigned long)mad_in_buffer < 
-     (MAD_TOTAL_BUFFER_SIZE - MAD_SINGLE_BUFFER_SIZE - delta)) {
-    sh_audio->a_in_buffer += delta;
-    sh_audio->a_in_buffer_len -= delta;
-  } else {
-    sh_audio->a_in_buffer = mad_in_buffer;
-    sh_audio->a_in_buffer_len -= delta;
-    memcpy(sh_audio->a_in_buffer, ms->next_frame, sh_audio->a_in_buffer_len);
-  }
-}
-
-static inline
-signed short mad_scale(mad_fixed_t sample)
-{
-  /* round */
-  sample += (1L << (MAD_F_FRACBITS - 16));
-
-  /* clip */
-  if (sample >= MAD_F_ONE)
-    sample = MAD_F_ONE - 1;
-  else if (sample < -MAD_F_ONE)
-    sample = -MAD_F_ONE;
-
-  /* quantize */
-  return sample >> (MAD_F_FRACBITS + 1 - 16);
-
-}
-
-static void mad_sync(sh_audio_t* sh_audio, struct mad_stream* ms)
-{
-    int len;
-#if 1
-    int skipped = 0;
-
-//    printf("buffer len: %d\n", sh_audio->a_in_buffer_len);    
-    while(sh_audio->a_in_buffer_len - skipped)
-    {
-	len = mp_decode_mp3_header(sh_audio->a_in_buffer+skipped);
-	if (len != -1)
-	{
-//	    printf("Frame len=%d\n", len);
-	    break;
-	}
-	else
-	    skipped++;
-    }
-    if (skipped)
-    {
-	mp_msg(MSGT_DECAUDIO, MSGL_INFO, "mad: audio synced, skipped bytes: %d\n", skipped);
-//	ms->skiplen += skipped;
-//	printf("skiplen: %d (skipped: %d)\n", ms->skiplen, skipped);
-
-//	if (sh_audio->a_in_buffer_len - skipped < MAD_BUFFER_GUARD)
-//	    printf("Mad reports: too small buffer\n");
-
-//	mad_stream_buffer(ms, sh_audio->a_in_buffer+skipped, sh_audio->a_in_buffer_len-skipped);
-//	mad_prepare_buffer(sh_audio, ms, sh_audio->a_in_buffer_len-skipped);
-
-	/* move frame to the beginning of the buffer and fill up to a_in_buffer_size */
-	sh_audio->a_in_buffer_len -= skipped;
-	memcpy(sh_audio->a_in_buffer, sh_audio->a_in_buffer+skipped, sh_audio->a_in_buffer_len);
-	mad_prepare_buffer(sh_audio, ms, sh_audio->a_in_buffer_size);
-	mad_stream_buffer(ms, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len);
-//	printf("bufflen: %d\n", sh_audio->a_in_buffer_len);
-	
-//	len = mp_decode_mp3_header(sh_audio->a_in_buffer);
-//	printf("len: %d\n", len);
-	ms->md_len = len;
-    }
-#else
-    len = mad_stream_sync(&ms);
-    if (len == -1)
-    {
-	mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Mad sync failed\n");
-    }
-#endif
-}
-
-static void mad_print_error(struct mad_stream *mad_stream)
-{
-    printf("error (0x%x): ", mad_stream->error);
-    switch(mad_stream->error)
-    {
-	case MAD_ERROR_BUFLEN:	printf("buffer too small");		break;
-	case MAD_ERROR_BUFPTR:	printf("invalid buffer pointer"); 	break;
-	case MAD_ERROR_NOMEM:	printf("not enought memory");		break;
-	case MAD_ERROR_LOSTSYNC:	printf("lost sync");		break;
-	case MAD_ERROR_BADLAYER:	printf("bad layer");		break;
-	case MAD_ERROR_BADBITRATE:	printf("bad bitrate");		break;
-	case MAD_ERROR_BADSAMPLERATE:	printf("bad samplerate");	break;
-	case MAD_ERROR_BADEMPHASIS:	printf("bad emphasis");		break;
-	case MAD_ERROR_BADCRC:		printf("bad crc");		break;
-	case MAD_ERROR_BADBITALLOC:	printf("forbidden bit alloc val"); break;
-	case MAD_ERROR_BADSCALEFACTOR:	printf("bad scalefactor index"); break;
-	case MAD_ERROR_BADFRAMELEN:	printf("bad frame length");	break;
-	case MAD_ERROR_BADBIGVALUES:	printf("bad bigvalues count");	break;
-	case MAD_ERROR_BADBLOCKTYPE:	printf("reserved blocktype");	break;
-	case MAD_ERROR_BADSCFSI:	printf("bad scalefactor selinfo"); break;
-	case MAD_ERROR_BADDATAPTR:	printf("bad maindatabegin ptr"); break;
-	case MAD_ERROR_BADPART3LEN:	printf("bad audio data len");	break;
-	case MAD_ERROR_BADHUFFTABLE:	printf("bad huffman table sel"); break;
-	case MAD_ERROR_BADHUFFDATA:	printf("huffman data overrun");	break;
-	case MAD_ERROR_BADSTEREO:	printf("incomp. blocktype for JS"); break;
-	default:
-	    printf("unknown error");
-    }
-    printf("\n");
-}
-#endif
-
-
-static int a52_fillbuff(sh_audio_t *sh_audio){
-int length=0;
-int flags=0;
-int sample_rate=0;
-int bit_rate=0;
-
-    sh_audio->a_in_buffer_len=0;
-    // sync frame:
-while(1){
-    while(sh_audio->a_in_buffer_len<7){
-	int c=demux_getc(sh_audio->ds);
-	if(c<0) return -1; // EOF
-        sh_audio->a_in_buffer[sh_audio->a_in_buffer_len++]=c;
-    }
-    length = a52_syncinfo (sh_audio->a_in_buffer, &flags, &sample_rate, &bit_rate);
-    if(length>=7 && length<=3840) break; // we're done.
-    // bad file => resync
-    memcpy(sh_audio->a_in_buffer,sh_audio->a_in_buffer+1,6);
-    --sh_audio->a_in_buffer_len;
-}
-    mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"a52: len=%d  flags=0x%X  %d Hz %d bit/s\n",length,flags,sample_rate,bit_rate);
-    sh_audio->samplerate=sample_rate;
-    sh_audio->i_bps=bit_rate/8;
-    demux_read_data(sh_audio->ds,sh_audio->a_in_buffer+7,length-7);
-    
-    if(crc16_block(sh_audio->a_in_buffer+2,length-2)!=0)
-	mp_msg(MSGT_DECAUDIO,MSGL_STATUS,"a52: CRC check failed!  \n");
-    
-    return length;
-}
-
-// returns: number of available channels
-static int a52_printinfo(sh_audio_t *sh_audio){
-int flags, sample_rate, bit_rate;
-char* mode="unknown";
-int channels=0;
-  a52_syncinfo (sh_audio->a_in_buffer, &flags, &sample_rate, &bit_rate);
-  switch(flags&A52_CHANNEL_MASK){
-    case A52_CHANNEL: mode="channel"; channels=2; break;
-    case A52_MONO: mode="mono"; channels=1; break;
-    case A52_STEREO: mode="stereo"; channels=2; break;
-    case A52_3F: mode="3f";channels=3;break;
-    case A52_2F1R: mode="2f+1r";channels=3;break;
-    case A52_3F1R: mode="3f+1r";channels=4;break;
-    case A52_2F2R: mode="2f+2r";channels=4;break;
-    case A52_3F2R: mode="3f+2r";channels=5;break;
-    case A52_CHANNEL1: mode="channel1"; channels=2; break;
-    case A52_CHANNEL2: mode="channel2"; channels=2; break;
-    case A52_DOLBY: mode="dolby"; channels=2; break;
-  }
-  mp_msg(MSGT_DECAUDIO,MSGL_INFO,"AC3: %d.%d (%s%s)  %d Hz  %3.1f kbit/s\n",
-	channels, (flags&A52_LFE)?1:0,
-	mode, (flags&A52_LFE)?"+lfe":"",
-	sample_rate, bit_rate*0.001f);
-  return (flags&A52_LFE) ? (channels+1) : channels;
-}
-
-int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen);
-
-
-static sh_audio_t* dec_audio_sh=NULL;
-
-#ifdef USE_LIBAC3
-// AC3 decoder buffer callback:
-static void ac3_fill_buffer(uint8_t **start,uint8_t **end){
-    int len=ds_get_packet(dec_audio_sh->ds,start);
-    //printf("<ac3:%d>\n",len);
-    if(len<0)
-          *start = *end = NULL;
-    else
-          *end = *start + len;
-}
-#endif
-
-// MP3 decoder buffer callback:
-int mplayer_audio_read(char *buf,int size){
-  int len;
-  len=demux_read_data(dec_audio_sh->ds,buf,size);
-  return len;
-}
-
-int init_audio(sh_audio_t *sh_audio){
-int driver=sh_audio->codec->driver;
-
-if(!sh_audio->samplesize)
-  sh_audio->samplesize=2;
-if(!sh_audio->sample_format)
-#ifdef WORDS_BIGENDIAN
-  sh_audio->sample_format=AFMT_S16_BE;
-#else
-  sh_audio->sample_format=AFMT_S16_LE;
-#endif
-//sh_audio->samplerate=0;
-//sh_audio->pcm_bswap=0;
-//sh_audio->o_bps=0;
-
-sh_audio->a_buffer_size=0;
-sh_audio->a_buffer=NULL;
-
-sh_audio->a_in_buffer_len=0;
-
-// setup required min. in/out buffer size:
-sh_audio->audio_out_minsize=8192;// default size, maybe not enough for Win32/ACM
-
-switch(driver){
-case AFM_ACM:
-#ifndef	USE_WIN32DLL
-  mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoACMSupport);
-  driver=0;
-#else
-  // Win32 ACM audio codec:
-  if(init_acm_audio_codec(sh_audio)){
-    sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
-    sh_audio->channels=sh_audio->o_wf.nChannels;
-    sh_audio->samplerate=sh_audio->o_wf.nSamplesPerSec;
-//    if(sh_audio->audio_out_minsize>16384) sh_audio->audio_out_minsize=16384;
-//    sh_audio->a_buffer_size=sh_audio->audio_out_minsize;
-//    if(sh_audio->a_buffer_size<sh_audio->audio_out_minsize+MAX_OUTBURST)
-//        sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST;
-  } else {
-    mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ACMiniterror);
-    driver=0;
-  }
-#endif
-  break;
-case AFM_DSHOW:
-#ifndef USE_DIRECTSHOW
-  mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoDShowAudio);
-  driver=0;
-#else
-  // Win32 DShow audio codec:
-//  printf("DShow_audio: channs=%d  rate=%d\n",sh_audio->channels,sh_audio->samplerate);
-  if(!(ds_adec=DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf))){
-    mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_audio->codec->dll);
-    driver=0;
-  } else {
-    sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
-    sh_audio->channels=sh_audio->wf->nChannels;
-    sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
-    sh_audio->audio_in_minsize=2*sh_audio->wf->nBlockAlign;
-    if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192;
-    sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize;
-    sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
-    sh_audio->a_in_buffer_len=0;
-    sh_audio->audio_out_minsize=16384;
-  }
-#endif
-  break;
-case AFM_VORBIS:
-#ifndef	HAVE_OGGVORBIS
-  mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoOggVorbis);
-  driver=0;
-#else
-  /* OggVorbis audio via libvorbis, compatible with files created by nandub and zorannt codec */
-  // Is there always 1024 samples/frame ? ***** Albeu
-  sh_audio->audio_out_minsize=1024*4; // 1024 samples/frame
-#endif
-  break;
-case AFM_AAC:
-  // AAC (MPEG2 Audio, MPEG4 Audio)
-#ifndef HAVE_FAAD
-  mp_msg(MSGT_DECAUDIO,MSGL_ERR,"Error: Cannot decode AAC data, because MPlayer was compiled without FAAD support\n"/*MSGTR_NoFAAD*/);
-  driver=0;
-#else  
-  mp_msg(MSGT_DECAUDIO,MSGL_V,"Using FAAD to decode AAC content!\n"/*MSGTR_UseFAAD*/);
-  // Samples per frame * channels per frame, this might not work with >2 chan AAC, need test samples! ::atmos
-  sh_audio->audio_out_minsize=2048*2;
-#endif  
-  break;
-case AFM_PCM:
-case AFM_DVDPCM:
-case AFM_ALAW:
-  // PCM, aLaw
-  sh_audio->audio_out_minsize=2048;
-  break;
-case AFM_AC3:
-case AFM_A52:
-  // Dolby AC3 audio:
-  // however many channels, 2 bytes in a word, 256 samples in a block, 6 blocks in a frame
-  sh_audio->audio_out_minsize=audio_output_channels*2*256*6;
-  break;
-case AFM_HWAC3:
-  // Dolby AC3 audio:
-  sh_audio->audio_out_minsize=4*256*6;
-//  sh_audio->sample_format = AFMT_AC3;
-//  sh_audio->sample_format = AFMT_S16_LE;
-  sh_audio->channels=2;
-  break;
-case AFM_GSM:
-  // MS-GSM audio codec:
-  sh_audio->audio_out_minsize=4*320;
-  break;
-case AFM_IMAADPCM:
-  sh_audio->audio_out_minsize=4096;
-  sh_audio->ds->ss_div=IMA_ADPCM_SAMPLES_PER_BLOCK;
-  sh_audio->ds->ss_mul=IMA_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels;
-  break;
-case AFM_MSADPCM:
-  sh_audio->audio_out_minsize=sh_audio->wf->nBlockAlign * 8;
-  sh_audio->ds->ss_div = MS_ADPCM_SAMPLES_PER_BLOCK;
-  sh_audio->ds->ss_mul = sh_audio->wf->nBlockAlign;
-  break;
-case AFM_DK4ADPCM:
-  sh_audio->audio_out_minsize=DK4_ADPCM_SAMPLES_PER_BLOCK * 4;
-  sh_audio->ds->ss_div=DK4_ADPCM_SAMPLES_PER_BLOCK;
-  sh_audio->ds->ss_mul=sh_audio->wf->nBlockAlign;
-  break;
-case AFM_DK3ADPCM:
-  sh_audio->audio_out_minsize=DK3_ADPCM_SAMPLES_PER_BLOCK * 4;
-  sh_audio->ds->ss_div=DK3_ADPCM_SAMPLES_PER_BLOCK;
-  sh_audio->ds->ss_mul=DK3_ADPCM_BLOCK_SIZE;
-  break;
-case AFM_ROQAUDIO:
-  // minsize was stored in wf->nBlockAlign by the RoQ demuxer
-  sh_audio->audio_out_minsize=sh_audio->wf->nBlockAlign;
-  sh_audio->ds->ss_div=DK3_ADPCM_SAMPLES_PER_BLOCK;
-  sh_audio->ds->ss_mul=DK3_ADPCM_BLOCK_SIZE;
-  sh_audio->context = roq_decode_audio_init();
-  break;
-case AFM_MPEG:
-  // MPEG Audio:
-  sh_audio->audio_out_minsize=4608;
-  break;
-#ifdef USE_G72X
-case AFM_G72X:
-//  g72x_reader_init(&g72x_data,G723_16_BITS_PER_SAMPLE);
-  g72x_reader_init(&g72x_data,G723_24_BITS_PER_SAMPLE);
-//  g72x_reader_init(&g72x_data,G721_32_BITS_PER_SAMPLE);
-//  g72x_reader_init(&g72x_data,G721_40_BITS_PER_SAMPLE);
-  sh_audio->audio_out_minsize=g72x_data.samplesperblock*4;
-  break;
-#endif
-case AFM_FFMPEG:
-#ifndef USE_LIBAVCODEC
-   mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoLAVCsupport);
-   return 0;
-#else
-  // FFmpeg Audio:
-  sh_audio->audio_out_minsize=AVCODEC_MAX_AUDIO_FRAME_SIZE;
-  break;
-#endif
-
-#ifdef USE_LIBMAD
- case AFM_MAD:
-   mp_msg(MSGT_DECVIDEO, MSGL_V, "mad: setting minimum outputsize\n");
-   sh_audio->audio_out_minsize=4608;
-   if(sh_audio->audio_in_minsize<MAD_SINGLE_BUFFER_SIZE) sh_audio->audio_in_minsize=MAD_SINGLE_BUFFER_SIZE;
-   sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize;
-   mad_in_buffer = sh_audio->a_in_buffer = malloc(MAD_TOTAL_BUFFER_SIZE);
-   sh_audio->a_in_buffer_len=0;
-   break;
-#endif
-}
-
-if(!driver) return 0;
-
-// allocate audio out buffer:
-sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; // worst case calc.
-
-mp_msg(MSGT_DECAUDIO,MSGL_V,"dec_audio: Allocating %d + %d = %d bytes for output buffer\n",
-    sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size);
-
-sh_audio->a_buffer=malloc(sh_audio->a_buffer_size);
-if(!sh_audio->a_buffer){
-    mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf);
-    return 0;
-}
-memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size);
-sh_audio->a_buffer_len=0;
-
-switch(driver){
-#ifdef USE_WIN32DLL
-case AFM_ACM: {
-    int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,4096,sh_audio->a_buffer_size);
-    if(ret<0){
-        mp_msg(MSGT_DECAUDIO,MSGL_INFO,"ACM decoding error: %d\n",ret);
-        driver=0;
-    }
-    sh_audio->a_buffer_len=ret;
-    break;
-}
-#endif
-case AFM_PCM: {
-    // AVI PCM Audio:
-    WAVEFORMATEX *h=sh_audio->wf;
-    sh_audio->i_bps=h->nAvgBytesPerSec;
-    sh_audio->channels=h->nChannels;
-    sh_audio->samplerate=h->nSamplesPerSec;
-    sh_audio->samplesize=(h->wBitsPerSample+7)/8;
-    switch(sh_audio->format){ // hardware formats:
-    case 0x6:  sh_audio->sample_format=AFMT_A_LAW;break;
-    case 0x7:  sh_audio->sample_format=AFMT_MU_LAW;break;
-    case 0x11: sh_audio->sample_format=AFMT_IMA_ADPCM;break;
-    case 0x50: sh_audio->sample_format=AFMT_MPEG;break;
-    case 0x736F7774: sh_audio->sample_format=AFMT_S16_LE;sh_audio->codec->driver=AFM_DVDPCM;break;
-//    case 0x2000: sh_audio->sample_format=AFMT_AC3;
-    default: sh_audio->sample_format=(sh_audio->samplesize==2)?AFMT_S16_LE:AFMT_U8;
-    }
-    break;
-}
-case AFM_DVDPCM: {
-    // DVD PCM Audio:
-    sh_audio->channels=2;
-    sh_audio->samplerate=48000;
-    sh_audio->i_bps=2*2*48000;
-//    sh_audio->pcm_bswap=1;
-    break;
-}
-case AFM_AC3: {
-#ifndef USE_LIBAC3
-  mp_msg(MSGT_DECAUDIO,MSGL_WARN,"WARNING: libac3 support is disabled. (hint: upgrade codecs.conf)\n");
-  driver=0;
-#else
-  // Dolby AC3 audio:
-  dec_audio_sh=sh_audio; // save sh_audio for the callback:
-  ac3_config.fill_buffer_callback = ac3_fill_buffer;
-  ac3_config.num_output_ch = audio_output_channels;
-  ac3_config.flags = 0;
-if(gCpuCaps.hasMMX){
-  ac3_config.flags |= AC3_MMX_ENABLE;
-}
-if(gCpuCaps.has3DNow){
-  ac3_config.flags |= AC3_3DNOW_ENABLE;
-}
-  ac3_init();
-  sh_audio->ac3_frame = ac3_decode_frame();
-  if(sh_audio->ac3_frame){
-    ac3_frame_t* fr=(ac3_frame_t*)sh_audio->ac3_frame;
-    sh_audio->samplerate=fr->sampling_rate;
-    sh_audio->channels=ac3_config.num_output_ch;
-    // 1 frame: 6*256 samples     1 sec: sh_audio->samplerate samples
-    //sh_audio->i_bps=fr->frame_size*fr->sampling_rate/(6*256);
-    sh_audio->i_bps=fr->bit_rate*(1000/8);
-  } else {
-    driver=0; // bad frame -> disable audio
-  }
-#endif
-  break;
-}
-case AFM_A52: {
-  sample_t level=1, bias=384;
-  int flags=0;
-  // Dolby AC3 audio:
-  if(gCpuCaps.hasSSE) a52_accel|=MM_ACCEL_X86_SSE;
-  if(gCpuCaps.hasMMX) a52_accel|=MM_ACCEL_X86_MMX;
-  if(gCpuCaps.hasMMX2) a52_accel|=MM_ACCEL_X86_MMXEXT;
-  if(gCpuCaps.has3DNow) a52_accel|=MM_ACCEL_X86_3DNOW;
-  if(gCpuCaps.has3DNowExt) a52_accel|=MM_ACCEL_X86_3DNOWEXT;
-  a52_samples=a52_init (a52_accel);
-  if (a52_samples == NULL) {
-	mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 init failed\n");
-	driver=0;break;
-  }
-   sh_audio->a_in_buffer_size=3840;
-   sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
-   sh_audio->a_in_buffer_len=0;
-  if(a52_fillbuff(sh_audio)<0){
-	mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n");
-	driver=0;break;
-  }
-  // 'a52 cannot upmix' hotfix:
-  a52_printinfo(sh_audio);
-//  if(audio_output_channels<sh_audio->channels)
-//      sh_audio->channels=audio_output_channels;
-  // channels setup:
-  sh_audio->channels=audio_output_channels;
-while(sh_audio->channels>0){
-  switch(sh_audio->channels){
-	    case 1: a52_flags=A52_MONO; break;
-//	    case 2: a52_flags=A52_STEREO; break;
-	    case 2: a52_flags=A52_DOLBY; break;
-//	    case 3: a52_flags=A52_3F; break;
-	    case 3: a52_flags=A52_2F1R; break;
-	    case 4: a52_flags=A52_2F2R; break; // 2+2
-	    case 5: a52_flags=A52_3F2R; break;
-	    case 6: a52_flags=A52_3F2R|A52_LFE; break; // 5.1
-  }
-  // test:
-  flags=a52_flags|A52_ADJUST_LEVEL;
-  mp_msg(MSGT_DECAUDIO,MSGL_V,"A52 flags before a52_frame: 0x%X\n",flags);
-  if (a52_frame (&a52_state, sh_audio->a_in_buffer, &flags, &level, bias)){
-    mp_msg(MSGT_DECAUDIO,MSGL_ERR,"a52: error decoding frame -> nosound\n");
-    driver=0;break;
-  }
-  mp_msg(MSGT_DECAUDIO,MSGL_V,"A52 flags after a52_frame: 0x%X\n",flags);
-  // frame decoded, let's init resampler:
-  if(a52_resample_init(a52_accel,flags,sh_audio->channels)) break;
-  --sh_audio->channels; // try to decrease no. of channels
-}
-  if(sh_audio->channels<=0){
-    mp_msg(MSGT_DECAUDIO,MSGL_ERR,"a52: no resampler. try different channel setup!\n");
-    driver=0;break;
-  }
-  break;
-}
-case AFM_HWAC3: {
-  // Dolby AC3 passthrough:
-  a52_samples=a52_init (a52_accel);
-  if (a52_samples == NULL) {
-       mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 init failed\n");
-       driver=0;break;
-  }
-  sh_audio->a_in_buffer_size=3840;
-  sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
-  sh_audio->a_in_buffer_len=0;
-  if(a52_fillbuff(sh_audio)<0) {
-       mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n");
-       driver=0;break;
-  }
-  
-  //sh_audio->samplerate=ai.samplerate;   // SET by a52_fillbuff()
-  //sh_audio->samplesize=ai.framesize;
-  //sh_audio->i_bps=ai.bitrate*(1000/8);  // SET by a52_fillbuff()
-  //sh_audio->ac3_frame=malloc(6144);
-  //sh_audio->o_bps=sh_audio->i_bps;  // XXX FIXME!!! XXX
-
-  // o_bps is calculated from samplesize*channels*samplerate
-  // a single ac3 frame is always translated to 6144 byte packet. (zero padding)
-  sh_audio->channels=2;
-  sh_audio->samplesize=2;   // 2*2*(6*256) = 6144 (very TRICKY!)
-
-  break;
-}
-case AFM_ALAW: {
-  // aLaw audio codec:
-  sh_audio->channels=sh_audio->wf->nChannels;
-  sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
-  sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate;
-  break;
-}
-#ifdef USE_G72X
-case AFM_G72X: {
-  // GSM 723 audio codec:
-  sh_audio->channels=sh_audio->wf->nChannels;
-  sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
-  sh_audio->i_bps=(sh_audio->samplerate/g72x_data.samplesperblock)*g72x_data.blocksize;
-  break;
-}
-#endif
-#ifdef USE_LIBAVCODEC
-case AFM_FFMPEG: {
-   int x;
-   mp_msg(MSGT_DECAUDIO,MSGL_V,"FFmpeg's libavcodec audio codec\n");
-    if(!avcodec_inited){
-      avcodec_init();
-      avcodec_register_all();
-      avcodec_inited=1;
-    }
-    lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_audio->codec->dll);
-    if(!lavc_codec){
-	mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh_audio->codec->dll);
-	return 0;
-    }
-    memset(&lavc_context, 0, sizeof(lavc_context));
-    /* open it */
-    if (avcodec_open(&lavc_context, lavc_codec) < 0) {
-        mp_msg(MSGT_DECAUDIO,MSGL_ERR, MSGTR_CantOpenCodec);
-        return 0;
-    }
-   mp_msg(MSGT_DECAUDIO,MSGL_V,"INFO: libavcodec init OK!\n");
-
-   // Decode at least 1 byte:  (to get header filled)
-   x=decode_audio(sh_audio,sh_audio->a_buffer,1,sh_audio->a_buffer_size);
-   if(x>0) sh_audio->a_buffer_len=x;
-
-#if 1
-  sh_audio->channels=lavc_context.channels;
-  sh_audio->samplerate=lavc_context.sample_rate;
-  sh_audio->i_bps=lavc_context.bit_rate/8;
-#else
-  sh_audio->channels=sh_audio->wf->nChannels;
-  sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
-  sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
-#endif
-  break;
-}
-#endif
-case AFM_GSM: {
-  // MS-GSM audio codec:
-  GSM_Init();
-  sh_audio->channels=sh_audio->wf->nChannels;
-  sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
-  // decodes 65 byte -> 320 short
-  // 1 sec: sh_audio->channels*sh_audio->samplerate  samples
-  // 1 frame: 320 samples
-  sh_audio->i_bps=65*(sh_audio->channels*sh_audio->samplerate)/320;  // 1:10
-  break;
-}
-case AFM_IMAADPCM:
-  // IMA-ADPCM 4:1 audio codec:
-  sh_audio->channels=sh_audio->wf->nChannels;
-  sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
-  // decodes 34 byte -> 64 short
-  sh_audio->i_bps=IMA_ADPCM_BLOCK_SIZE*(sh_audio->channels*sh_audio->samplerate)/IMA_ADPCM_SAMPLES_PER_BLOCK;  // 1:4
-  break;
-case AFM_MSADPCM:
-  sh_audio->channels=sh_audio->wf->nChannels;
-  sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
-  sh_audio->i_bps = sh_audio->wf->nBlockAlign *
-    (sh_audio->channels*sh_audio->samplerate) / MS_ADPCM_SAMPLES_PER_BLOCK;
-  break;
-case AFM_DK4ADPCM:
-  sh_audio->channels=sh_audio->wf->nChannels;
-  sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
-  sh_audio->i_bps = sh_audio->wf->nBlockAlign *
-    (sh_audio->channels*sh_audio->samplerate) / DK4_ADPCM_SAMPLES_PER_BLOCK;
-  break;
-case AFM_DK3ADPCM:
-  sh_audio->channels=sh_audio->wf->nChannels;
-  sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
-  sh_audio->i_bps=DK3_ADPCM_BLOCK_SIZE*
-    (sh_audio->channels*sh_audio->samplerate) / DK3_ADPCM_SAMPLES_PER_BLOCK;
-  break;
-case AFM_ROQAUDIO:
-  sh_audio->channels=sh_audio->wf->nChannels;
-  sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
-  sh_audio->i_bps = (sh_audio->channels * 22050) / 2;
-  break;
-case AFM_MPEG: {
-  // MPEG Audio:
-  dec_audio_sh=sh_audio; // save sh_audio for the callback:
-#ifdef USE_FAKE_MONO
-  MP3_Init(fakemono);
-#else
-  MP3_Init();
-#endif
-  MP3_samplerate=MP3_channels=0;
-  sh_audio->a_buffer_len=MP3_DecodeFrame(sh_audio->a_buffer,-1);
-  sh_audio->channels=2; // hack
-  sh_audio->samplerate=MP3_samplerate;
-  sh_audio->i_bps=MP3_bitrate*(1000/8);
-  MP3_PrintHeader();
-  break;
-}
-#ifdef HAVE_OGGVORBIS
-case AFM_VORBIS: {
-  ogg_packet op;
-  vorbis_comment vc;
-  struct ov_struct_st *ov;
-
-  /// Init the decoder with the 3 header packets
-  ov = (struct ov_struct_st*)malloc(sizeof(struct ov_struct_st));
-  vorbis_info_init(&ov->vi);
-  vorbis_comment_init(&vc);
-  op.bytes = ds_get_packet(sh_audio->ds,&op.packet);
-  op.b_o_s  = 1;
-  /// Header
-  if(vorbis_synthesis_headerin(&ov->vi,&vc,&op) <0) {
-    mp_msg(MSGT_DECAUDIO,MSGL_ERR,"OggVorbis: initial (identification) header broken!\n");
-    driver = 0;
-    free(ov);
-    break;
-  }
-  op.bytes = ds_get_packet(sh_audio->ds,&op.packet);
-  op.b_o_s  = 0;
-  /// Comments
-  if(vorbis_synthesis_headerin(&ov->vi,&vc,&op) <0) {
-    mp_msg(MSGT_DECAUDIO,MSGL_ERR,"OggVorbis: comment header broken!\n");
-    driver = 0;
-    free(ov);
-    break;
-  }
-  op.bytes = ds_get_packet(sh_audio->ds,&op.packet);
-  //// Codebook
-  if(vorbis_synthesis_headerin(&ov->vi,&vc,&op)<0) {
-    mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: codebook header broken!\n");
-    driver = 0;
-    free(ov);
-    break;
-  } else { /// Print the infos
-    char **ptr=vc.user_comments;
-    while(*ptr){
-      mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbisComment: %s\n",*ptr);
-      ++ptr;
-    }
-    mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Bitstream is %d channel, %ldHz, %ldkbit/s %cBR\n",ov->vi.channels,ov->vi.rate,ov->vi.bitrate_nominal/1000, (ov->vi.bitrate_lower!=ov->vi.bitrate_nominal)||(ov->vi.bitrate_upper!=ov->vi.bitrate_nominal)?'V':'C');
-    mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Encoded by: %s\n",vc.vendor);
-  }
-
-  // Setup the decoder
-  sh_audio->channels=ov->vi.channels; 
-  sh_audio->samplerate=ov->vi.rate;
-  sh_audio->i_bps=ov->vi.bitrate_nominal/8;
-  sh_audio->context = ov;
-
-  /// Finish the decoder init
-  vorbis_synthesis_init(&ov->vd,&ov->vi);
-  vorbis_block_init(&ov->vd,&ov->vb);
-  mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Init OK!\n");
-} break;
-#endif
-
-#ifdef HAVE_FAAD
-case AFM_AAC: {
-  unsigned long faac_samplerate, faac_channels;
-  faacDecConfigurationPtr faac_conf;
-  faac_hdec = faacDecOpen();
-
-  if(faac_buffer == NULL)
-    faac_buffer = (unsigned char*)calloc(1,FAAD_BUFFLEN);
-  demux_read_data(sh_audio->ds, faac_buffer, FAAD_BUFFLEN);
-
-  // If we don't get the ES descriptor, try manual config
-  if(!sh_audio->codecdata_len) {
-#if 1
-    /* Set the default object type and samplerate */
-    /* This is useful for RAW AAC files */
-    faac_conf = faacDecGetCurrentConfiguration(faac_hdec);
-    if(sh_audio->samplerate)
-      faac_conf->defSampleRate = sh_audio->samplerate;
-    /* XXX: FAAD support FLOAT output, how do we handle
-      * that (FAAD_FMT_FLOAT)? ::atmos
-      */
-    if(sh_audio->samplesize)
-      switch(sh_audio->samplesize){
-	case 1: // 8Bit
-	  mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: 8Bit samplesize not supported by FAAD, assuming 16Bit!\n");
-	default:
-	case 2: // 16Bit
-	  faac_conf->outputFormat = FAAD_FMT_16BIT;
-	  break;
-	case 3: // 24Bit
-	  faac_conf->outputFormat = FAAD_FMT_24BIT;
-	  break;
-	case 4: // 32Bit
-	  faac_conf->outputFormat = FAAD_FMT_32BIT;
-	  break;
-      }
-    //faac_conf->defObjectType = LTP; // => MAIN, LC, SSR, LTP available.
-
-    faacDecSetConfiguration(faac_hdec, faac_conf);
-#endif
-
-    /* init the codec */
-    faac_bytesconsumed = faacDecInit(faac_hdec, faac_buffer,
-       &faac_samplerate, &faac_channels);
-
-  } else { // We have ES DS in codecdata
-    /*int i;
-    for(i = 0; i < sh_audio->codecdata_len; i++)
-      printf("codecdata_dump %d: 0x%02X\n", i, sh_audio->codecdata[i]);*/
-
-    faac_bytesconsumed = faacDecInit2(faac_hdec, sh_audio->codecdata,
-       sh_audio->codecdata_len,	&faac_samplerate, &faac_channels);
-  }
-  if(faac_bytesconsumed < 0) {
-    mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: Failed to initialize the decoder!\n"); // XXX: deal with cleanup!
-    faacDecClose(faac_hdec);
-    free(faac_buffer);
-    faac_buffer = NULL;
-    driver = 0;
-  } else {
-    mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: Decoder init done (%dBytes)!\n", faac_bytesconsumed); // XXX: remove or move to debug!
-    mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: Negotiated samplerate: %dHz  channels: %d\n", faac_samplerate, faac_channels);
-    sh_audio->channels = faac_channels;
-    sh_audio->samplerate = faac_samplerate;
-    //sh_audio->o_bps = sh_audio->samplesize*faac_channels*faac_samplerate;
-    if(!sh_audio->i_bps) {
-      mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: compressed input bitrate missing, assuming 128kbit/s!\n");
-      sh_audio->i_bps = 128*1000/8; // XXX: HACK!!! ::atmos
-    } else 
-      mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: got %dkbit/s bitrate from MP4 header!\n",sh_audio->i_bps*8/1000);
-  }  
-	    
-} break;		
-#endif
-
-#ifdef USE_LIBMAD
- case AFM_MAD:
-   {
-     printf("%s %s %s (%s)\n", mad_version, mad_copyright, mad_author, mad_build);
-
-     mp_msg(MSGT_DECVIDEO, MSGL_V, "mad: initialising\n");
-     mad_frame_init(&mad_frame);
-     mad_stream_init(&mad_stream);
-
-     mp_msg(MSGT_DECVIDEO, MSGL_V, "mad: preparing buffer\n");
-     mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size);
-     mad_stream_buffer(&mad_stream, (unsigned char*)(sh_audio->a_in_buffer), sh_audio->a_in_buffer_len);
-//     mad_stream_sync(&mad_stream);
-     mad_sync(sh_audio, &mad_stream);
-     mad_synth_init(&mad_synth);
-
-     if(mad_frame_decode(&mad_frame, &mad_stream) == 0)
-       {
-	 mp_msg(MSGT_DECVIDEO, MSGL_V, "mad: post processing buffer\n");
-	 mad_postprocess_buffer(sh_audio, &mad_stream);
-       }
-     else
-       {
-	 mp_msg(MSGT_DECVIDEO, MSGL_V, "mad: frame decoding failed\n");
-	 mad_print_error(&mad_stream);
-       }
-     
-     switch (mad_frame.header.mode)
-     {
-        case MAD_MODE_SINGLE_CHANNEL:
-	    sh_audio->channels=1;
-	    break;
-	case MAD_MODE_DUAL_CHANNEL:
-	case MAD_MODE_JOINT_STEREO:
-	case MAD_MODE_STEREO:
-	    sh_audio->channels=2;
-	    break;
-	default:
-	    mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "mad: unknown number of channels\n");
-     }
-     mp_msg(MSGT_DECAUDIO, MSGL_HINT, "mad: channels: %d (mad channel mode: %d)\n",
-        sh_audio->channels, mad_frame.header.mode);
-/* var. name changed in 0.13.0 (beta) (libmad/CHANGES) -- alex */
-#if (MAD_VERSION_MAJOR >= 0) && (MAD_VERSION_MINOR >= 13)
-     sh_audio->samplerate=mad_frame.header.samplerate;
-#else
-     sh_audio->samplerate=mad_frame.header.sfreq;
-#endif
-     sh_audio->i_bps=mad_frame.header.bitrate;
-     mp_msg(MSGT_DECVIDEO, MSGL_V, "mad: continuing\n");
-     break;
-   }
-#endif
-}
-
-if(!sh_audio->channels || !sh_audio->samplerate){
-  mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio);
-  driver=0;
-}
-
-  if(!driver){
-      if(sh_audio->a_buffer) free(sh_audio->a_buffer);
-      sh_audio->a_buffer=NULL;
-      return 0;
-  }
-
-  if(!sh_audio->o_bps)
-  sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize;
-  return driver;
-}
-
-// Audio decoding:
-
-// Decode a single frame (mp3,acm etc) or 'minlen' bytes (pcm/alaw etc)
-// buffer length is 'maxlen' bytes, it shouldn't be exceeded...
-
-int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){
-    int len=-1;
-    switch(sh_audio->codec->driver){
-#ifdef USE_LIBAVCODEC
-      case AFM_FFMPEG: {
-          unsigned char *start=NULL;
-	  int y;
-	  while(len<minlen){
-	    int len2=0;
-	    int x=ds_get_packet(sh_audio->ds,&start);
-	    if(x<=0) break; // error
-	    y=avcodec_decode_audio(&lavc_context,(INT16*)buf,&len2,start,x);
-	    if(y<0){ mp_msg(MSGT_DECAUDIO,MSGL_V,"lavc_audio: error\n");break; }
-	    if(y<x) sh_audio->ds->buffer_pos+=y-x;  // put back data (HACK!)
-	    if(len2>0){
-	      //len=len2;break;
-	      if(len<0) len=len2; else len+=len2;
-	      buf+=len2;
-	    }
-            mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"Decoded %d -> %d  \n",y,len2);
-	  }
-        }
-        break;
-#endif
-      case AFM_MPEG: // MPEG layer 2 or 3
-        len=MP3_DecodeFrame(buf,-1);
-//        len=MP3_DecodeFrame(buf,3);
-        break;
-#ifdef HAVE_OGGVORBIS
-      case AFM_VORBIS: { // Vorbis
-        int samples;
-        float **pcm;
-        ogg_packet op;
-        char* np;
-        struct ov_struct_st *ov = sh_audio->context;
-        len = 0;
-        op.b_o_s =  op.e_o_s = 0;
-	while(len < minlen) {
-	  op.bytes = ds_get_packet(sh_audio->ds,&op.packet);
-	  if(!op.packet)
-	    break;
-	  if(vorbis_synthesis(&ov->vb,&op)==0) /* test for success! */
-	    vorbis_synthesis_blockin(&ov->vd,&ov->vb);
-	  while((samples=vorbis_synthesis_pcmout(&ov->vd,&pcm))>0){
-	    int i,j;
-	    int clipflag=0;
-	    int convsize=(maxlen-len)/(2*ov->vi.channels); // max size!
-	    int bout=(samples<convsize?samples:convsize);
-	  
-	    if(bout<=0) break;
-
-	    /* convert floats to 16 bit signed ints (host order) and
-	       interleave */
-	    for(i=0;i<ov->vi.channels;i++){
-	      ogg_int16_t *convbuffer=(ogg_int16_t *)(&buf[len]);
-	      ogg_int16_t *ptr=convbuffer+i;
-	      float  *mono=pcm[i];
-	      for(j=0;j<bout;j++){
-#if 1
-		int val=mono[j]*32767.f;
-#else /* optional dither */
-		int val=mono[j]*32767.f+drand48()-0.5f;
-#endif
-		/* might as well guard against clipping */
-		if(val>32767){
-		  val=32767;
-		  clipflag=1;
-		}
-		if(val<-32768){
-		  val=-32768;
-		  clipflag=1;
-		}
-		*ptr=val;
-		ptr+=ov->vi.channels;
-	      }
-	    }
-		
-	    if(clipflag)
-	      mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"Clipping in frame %ld\n",(long)(ov->vd.sequence));
-	    len+=2*ov->vi.channels*bout;
-	    mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[decoded: %d / %d ]\n",bout,samples);
-	    vorbis_synthesis_read(&ov->vd,bout); /* tell libvorbis how
-						    many samples we
-						    actually consumed */
-	  }
-	}
-      } break;
-#endif
-		       
-#ifdef HAVE_FAAD		       
-      case AFM_AAC: {
-	int /*i,*/ k, j = 0;	      
-	void *faac_sample_buffer;
-
-	len = 0;
-	while(len < minlen) {
-	  /* update buffer */
-    	  if (faac_bytesconsumed > 0) {
-	    for (k = 0; k < (FAAD_BUFFLEN - faac_bytesconsumed); k++)
-	      faac_buffer[k] = faac_buffer[k + faac_bytesconsumed];
-	    demux_read_data(sh_audio->ds, faac_buffer + (FAAD_BUFFLEN) - faac_bytesconsumed, faac_bytesconsumed);
-	    faac_bytesconsumed = 0;
-	  }
-	  /*for (i = 0; i < 16; i++)
-	    printf ("%02X ", faac_buffer[i]);
-	  printf ("\n");*/
-	  do {
-	    faac_sample_buffer = faacDecDecode(faac_hdec, &faac_finfo, faac_buffer+j);
-	    /* update buffer index after faacDecDecode */
-	    faac_bytesconsumed += faac_finfo.bytesconsumed;
-	    if(faac_finfo.error > 0) {
-	      mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: Trying to resync!\n");
-	      j++;
-	    } else
-	      break;
-	  } while(j < FAAD_BUFFLEN);	  
-
-
-	  if(faac_finfo.error > 0) {
-	    mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: Failed to decode frame: %s \n",
-	      faacDecGetErrorMessage(faac_finfo.error));
-	  } else if (faac_finfo.samples == 0)
-	    mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"FAAD: Decoded zero samples!\n");
-	  else {
-	    /* XXX: samples already multiplied by channels! */
-	    mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"FAAD: Successfully decoded frame (%d Bytes)!\n",
-	       sh_audio->samplesize*faac_finfo.samples);
-	    memcpy(buf+len,faac_sample_buffer, sh_audio->samplesize*faac_finfo.samples);
-	    len += sh_audio->samplesize*faac_finfo.samples;
-	    //printf("FAAD: buffer: %d bytes  consumed: %d \n", k, faac_finfo.bytesconsumed);
-	  }
-	}
-
-      } break;
-#endif		    
-      case AFM_PCM: // AVI PCM
-        len=demux_read_data(sh_audio->ds,buf,minlen);
-        break;
-      case AFM_DVDPCM: // DVD PCM
-      { int j;
-        len=demux_read_data(sh_audio->ds,buf,minlen);
-          //if(i&1){ printf("Warning! pcm_audio_size&1 !=0  (%d)\n",i);i&=~1; }
-          // swap endian:
-          for(j=0;j<len;j+=2){
-            char x=buf[j];
-            buf[j]=buf[j+1];
-            buf[j+1]=x;
-          }
-        break;
-      }
-      case AFM_ALAW:  // aLaw decoder
-      { int l=demux_read_data(sh_audio->ds,buf,minlen/2);
-        unsigned short *d=(unsigned short *) buf;
-        unsigned char *s=buf;
-        len=2*l;
-        if(sh_audio->format==6){
-        // aLaw
-          while(l>0){ --l; d[l]=alaw2short[s[l]]; }
-        } else {
-        // uLaw
-          while(l>0){ --l; d[l]=ulaw2short[s[l]]; }
-        }
-        break;
-      }
-      case AFM_GSM:  // MS-GSM decoder
-      { unsigned char ibuf[65]; // 65 bytes / frame
-        if(demux_read_data(sh_audio->ds,ibuf,65)!=65) break; // EOF
-        XA_MSGSM_Decoder(ibuf,(unsigned short *) buf); // decodes 65 byte -> 320 short
-//  	    XA_GSM_Decoder(buf,(unsigned short *) &sh_audio->a_buffer[sh_audio->a_buffer_len]); // decodes 33 byte -> 160 short
-        len=2*320;
-        break;
-      }
-#ifdef USE_G72X
-      case AFM_G72X:  // GSM 723 decoder
-      { if(demux_read_data(sh_audio->ds,g72x_data.block, g72x_data.blocksize)!=g72x_data.blocksize) break; // EOF
-        g72x_decode_block(&g72x_data);
-	len=2*g72x_data.samplesperblock;
-	memcpy(buf,g72x_data.samples,len);
-        break;
-      }
-#endif
-      case AFM_IMAADPCM:
-      { unsigned char ibuf[IMA_ADPCM_BLOCK_SIZE * 2]; // bytes / stereo frame
-        if (demux_read_data(sh_audio->ds, ibuf,
-          IMA_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) != 
-          IMA_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) 
-          break; // EOF
-        len=2*ima_adpcm_decode_block((unsigned short*)buf,ibuf, sh_audio->wf->nChannels);
-        break;
-      }
-      case AFM_MSADPCM:
-      { static unsigned char *ibuf = NULL;
-        if (!ibuf)
-          ibuf = (unsigned char *)malloc
-            (sh_audio->wf->nBlockAlign * sh_audio->wf->nChannels);
-        if (demux_read_data(sh_audio->ds, ibuf,
-          sh_audio->wf->nBlockAlign) != 
-          sh_audio->wf->nBlockAlign) 
-          break; // EOF
-        len= 2 * ms_adpcm_decode_block(
-          (unsigned short*)buf,ibuf, sh_audio->wf->nChannels,
-          sh_audio->wf->nBlockAlign);
-        break;
-      }
-      case AFM_DK4ADPCM:
-      { static unsigned char *ibuf = NULL;
-        if (!ibuf)
-          ibuf = (unsigned char *)malloc(sh_audio->wf->nBlockAlign);
-        if (demux_read_data(sh_audio->ds, ibuf, sh_audio->wf->nBlockAlign) != 
-          sh_audio->wf->nBlockAlign)
-          break; // EOF
-        len=2*dk4_adpcm_decode_block((unsigned short*)buf,ibuf,
-          sh_audio->wf->nChannels, sh_audio->wf->nBlockAlign);
-        break;
-      }
-      case AFM_DK3ADPCM:
-      { unsigned char ibuf[DK3_ADPCM_BLOCK_SIZE * 2]; // bytes / stereo frame
-        if (demux_read_data(sh_audio->ds, ibuf,
-          DK3_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) != 
-          DK3_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) 
-          break; // EOF
-        len = 2 * dk3_adpcm_decode_block(
-          (unsigned short*)buf,ibuf);
-        break;
-      }
-      case AFM_ROQAUDIO:
-      {
-        static unsigned char *ibuf = NULL;
-        unsigned char header_data[6];
-        int read_len;
-
-        if (!ibuf)
-          ibuf = (unsigned char *)malloc(sh_audio->audio_out_minsize / 2);
-
-        // figure out how much data to read
-        if (demux_read_data(sh_audio->ds, header_data, 6) != 6)
-          break; // EOF
-        read_len = (header_data[5] << 24) | (header_data[4] << 16) |
-          (header_data[3] << 8) | header_data[2];
-        read_len += 2;  // 16-bit arguments
-        if (demux_read_data(sh_audio->ds, ibuf, read_len) != read_len)
-          break;
-        len = 2 * roq_decode_audio((unsigned short *)buf, ibuf,
-          read_len, sh_audio->channels, sh_audio->context);          
-        break;
-      }
-#ifdef USE_LIBAC3
-      case AFM_AC3: // AC3 decoder
-        //printf("{1:%d}",avi_header.idx_pos);fflush(stdout);
-        if(!sh_audio->ac3_frame) sh_audio->ac3_frame=ac3_decode_frame();
-        //printf("{2:%d}",avi_header.idx_pos);fflush(stdout);
-        if(sh_audio->ac3_frame){
-          len = 256 * 6 *sh_audio->channels*sh_audio->samplesize;
-          memcpy(buf,((ac3_frame_t*)sh_audio->ac3_frame)->audio_data,len);
-          sh_audio->ac3_frame=NULL;
-        }
-        //printf("{3:%d}",avi_header.idx_pos);fflush(stdout);
-        break;
-#endif
-      case AFM_A52: { // AC3 decoder
-	sample_t level=1, bias=384;
-        int flags=a52_flags|A52_ADJUST_LEVEL;
-	int i;
-        if(!sh_audio->a_in_buffer_len) 
-	    if(a52_fillbuff(sh_audio)<0) break; // EOF
-	sh_audio->a_in_buffer_len=0;
-	if (a52_frame (&a52_state, sh_audio->a_in_buffer, &flags, &level, bias)){
-	    mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error decoding frame\n");
-	    break;
-	}
-	// a52_dynrng (&state, NULL, NULL); // disable dynamic range compensation
-
-	// frame decoded, let's resample:
-	//a52_resample_init(a52_accel,flags,sh_audio->channels);
-	len=0;
-	for (i = 0; i < 6; i++) {
-	    if (a52_block (&a52_state, a52_samples)){
-		mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error at resampling\n");
-		break;
-	    }
-	    len+=2*a52_resample(a52_samples,&buf[len]);
-	}
-	// printf("len = %d      \n",len); // 6144 on all vobs I tried so far... (5.1 and 2.0) ::atmos
-	break;
-      }
-      case AFM_HWAC3: // AC3 through SPDIF
-        if(!sh_audio->a_in_buffer_len)
-	    if((len=a52_fillbuff(sh_audio))<0) break; //EOF
-	sh_audio->a_in_buffer_len=0;
-	len = ac3_iec958_build_burst(len, 0x01, 1, sh_audio->a_in_buffer, buf);
-	// len = 6144 = 4*(6*256)
-	break;
-#ifdef USE_WIN32DLL
-      case AFM_ACM:
-//        len=sh_audio->audio_out_minsize; // optimal decoded fragment size
-//        if(len<minlen) len=minlen; else
-//        if(len>maxlen) len=maxlen;
-//        len=acm_decode_audio(sh_audio,buf,len);
-        len=acm_decode_audio(sh_audio,buf,minlen,maxlen);
-        break;
-#endif
-
-#ifdef USE_DIRECTSHOW
-      case AFM_DSHOW: // DirectShow
-      { int size_in=0;
-        int size_out=0;
-        int srcsize=DS_AudioDecoder_GetSrcSize(ds_adec, maxlen);
-        mp_msg(MSGT_DECAUDIO,MSGL_DBG3,"DShow says: srcsize=%d  (buffsize=%d)  out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen);
-        if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!!
-        if(sh_audio->a_in_buffer_len<srcsize){
-          sh_audio->a_in_buffer_len+=
-            demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len],
-            srcsize-sh_audio->a_in_buffer_len);
-        }
-        DS_AudioDecoder_Convert(ds_adec, sh_audio->a_in_buffer,sh_audio->a_in_buffer_len,
-            buf,maxlen, &size_in,&size_out);
-        mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"DShow: audio %d -> %d converted  (in_buf_len=%d of %d)  %d\n",size_in,size_out,sh_audio->a_in_buffer_len,sh_audio->a_in_buffer_size,ds_tell_pts(sh_audio->ds));
-        if(size_in>=sh_audio->a_in_buffer_len){
-          sh_audio->a_in_buffer_len=0;
-        } else {
-          sh_audio->a_in_buffer_len-=size_in;
-          memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len);
-        }
-        len=size_out;
-        break;
-      }
-#endif
-
-#ifdef USE_LIBMAD
-    case AFM_MAD:
-      {
-	mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size);
-	mad_stream_buffer(&mad_stream, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len);
-//        mad_stream_sync(&mad_stream);
-	mad_sync(sh_audio, &mad_stream);
-	if(mad_frame_decode(&mad_frame, &mad_stream) == 0)
-	  {
-	    mad_synth_frame(&mad_synth, &mad_frame);
-	    mad_postprocess_buffer(sh_audio, &mad_stream);
-	    
-	    /* and fill buffer */
-	    
-	    {
-	      int i;
-	      int end_size = mad_synth.pcm.length;
-	      signed short* samples = (signed short*)buf;
-	      if(end_size > maxlen/4)
-		end_size=maxlen/4;
-	      
-	      for(i=0; i<mad_synth.pcm.length; ++i) {
-		*samples++ = mad_scale(mad_synth.pcm.samples[0][i]);
-		*samples++ = mad_scale(mad_synth.pcm.samples[0][i]);
-		//		*buf++ = mad_scale(mad_synth.pcm.sampAles[1][i]);
-	      }
-	      len = end_size*4;
-	    }
-	  }
-	else
-	  {
-	    mp_msg(MSGT_DECVIDEO, MSGL_ERR, "mad: frame decoding failed (error: %d)\n",
-		mad_stream.error);
-	    mad_print_error(&mad_stream);
-	  }
-	
-	break;
-      }
-#endif
-    }
-    return len;
-}
-
-void resync_audio_stream(sh_audio_t *sh_audio){
-        switch(sh_audio->codec->driver){
-        case AFM_MPEG:
-          MP3_DecodeFrame(NULL,-2); // resync
-          MP3_DecodeFrame(NULL,-2); // resync
-          MP3_DecodeFrame(NULL,-2); // resync
-          break;
-#ifdef USE_LIBAC3
-        case AFM_AC3:
-          ac3_bitstream_reset();    // reset AC3 bitstream buffer
-    //      if(verbose){ printf("Resyncing AC3 audio...");fflush(stdout);}
-          sh_audio->ac3_frame=ac3_decode_frame(); // resync
-    //      if(verbose) printf(" OK!\n");
-          break;
-#endif
-#ifdef HAVE_FAAD
-	case AFM_AAC:
-	  //if(faac_buffer != NULL)
-	  faac_bytesconsumed = 0;
-	  memset(faac_buffer, 0, FAAD_BUFFLEN);
-  	  //demux_read_data(sh_audio->ds, faac_buffer, FAAD_BUFFLEN);
-	  break;
-#endif
-        case AFM_A52:
-        case AFM_ACM:
-        case AFM_DSHOW:
-	case AFM_HWAC3:
-          sh_audio->a_in_buffer_len=0;        // reset ACM/DShow audio buffer
-          break;
-
-#ifdef USE_LIBMAD
-	case AFM_MAD:
-	  mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size);
-	  mad_stream_buffer(&mad_stream, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len);
-//	  mad_stream_sync(&mad_stream);
-	  mad_sync(sh_audio, &mad_stream);
-	  mad_postprocess_buffer(sh_audio, &mad_stream);
-	  break;
-#endif	
-        }
-}
-
-void skip_audio_frame(sh_audio_t *sh_audio){
-              switch(sh_audio->codec->driver){
-                case AFM_MPEG: MP3_DecodeFrame(NULL,-2);break; // skip MPEG frame
-#ifdef USE_LIBAC3
-                case AFM_AC3: sh_audio->ac3_frame=ac3_decode_frame();break; // skip AC3 frame
-#endif
-		case AFM_HWAC3:
-                case AFM_A52: a52_fillbuff(sh_audio);break; // skip AC3 frame
-		case AFM_ACM:
-		case AFM_DSHOW: {
-		    int skip=sh_audio->wf->nBlockAlign;
-		    if(skip<16){
-		      skip=(sh_audio->wf->nAvgBytesPerSec/16)&(~7);
-		      if(skip<16) skip=16;
-		    }
-		    demux_read_data(sh_audio->ds,NULL,skip);
-		    break;
-		}
-		case AFM_PCM:
-		case AFM_DVDPCM:
-		case AFM_ALAW: {
-		    int skip=sh_audio->i_bps/16;
-		    skip=skip&(~3);
-		    demux_read_data(sh_audio->ds,NULL,skip);
-		    break;
-		}
-#ifdef USE_LIBMAD
-	      case AFM_MAD:
-		{
-		  mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size);
-		  mad_stream_buffer(&mad_stream, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len);
-		  mad_stream_skip(&mad_stream, 2);
-//		  mad_stream_sync(&mad_stream);
-		  mad_sync(sh_audio, &mad_stream);
-		  mad_postprocess_buffer(sh_audio, &mad_stream);
-		  break;
-		}
-#endif
-
-                default: ds_fill_buffer(sh_audio->ds);  // skip PCM frame
-              }
-}
--- a/dec_video.c	Sat Apr 13 17:28:33 2002 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1323 +0,0 @@
-
-// This file is OBSOLETED. DO not modify, stuff moved to libmpcodecs/ from here
-#error OBSOLETED
-
-#define USE_MP_IMAGE
-
-#include "config.h"
-
-#include <stdio.h>
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "mp_msg.h"
-#include "help_mp.h"
-
-#include "linux/timer.h"
-#include "linux/shmem.h"
-
-extern int verbose; // defined in mplayer.c
-
-#include "stream.h"
-#include "demuxer.h"
-#include "parse_es.h"
-
-#include "codec-cfg.h"
-
-#ifdef USE_LIBVO2
-#include "libvo2/libvo2.h"
-#else
-#include "libvo/video_out.h"
-#endif
-
-#include "stheader.h"
-
-#include "dec_video.h"
-
-#include "roqav.h"
-
-// ===================================================================
-
-extern int benchmark;
-extern double video_time_usage;
-extern double vout_time_usage;
-extern double max_video_time_usage;
-extern double max_vout_time_usage;
-extern double cur_video_time_usage;
-extern double cur_vout_time_usage;
-extern vo_vaa_t vo_vaa;
-
-extern int frameratecode2framerate[16];
-
-#include "dll_init.h"
-
-//#include <inttypes.h>
-//#include "libvo/img_format.h"
-
-#include "libmpeg2/mpeg2.h"
-#include "libmpeg2/mpeg2_internal.h"
-
-#include "postproc/postprocess.h"
-
-#include "cpudetect.h"
-
-extern picture_t *picture;	// exported from libmpeg2/decode.c
-
-int divx_quality=0;
-
-#ifdef USE_DIRECTSHOW
-#include "loader/dshow/DS_VideoDecoder.h"
-static DS_VideoDecoder* ds_vdec=NULL;
-#endif
-
-#ifdef USE_LIBAVCODEC
-#ifdef USE_LIBAVCODEC_SO
-#include <libffmpeg/avcodec.h>
-#else
-#include "libavcodec/avcodec.h"
-#endif
-    static AVCodec *lavc_codec=NULL;
-    static AVCodecContext lavc_context;
-    static AVPicture lavc_picture;
-    int avcodec_inited=0;
-#endif
-#ifdef FF_POSTPROCESS
-    unsigned int lavc_pp=0;
-#endif
-
-#ifdef USE_DIVX
-#ifndef NEW_DECORE
-#include "opendivx/decore.h"
-#else
-#include <decore.h>
-#endif
-#endif
-
-#ifdef USE_XANIM
-#include "xacodec.h"
-#endif
-
-#ifdef USE_TV
-#include "libmpdemux/tv.h"
-extern int tv_param_on;
-extern tvi_handle_t *tv_handler;
-#endif
-
-void AVI_Decode_RLE8(char *image,char *delta,int tdsize,
-    unsigned int *map,int imagex,int imagey,unsigned char x11_bytes_pixel);
-
-void AVI_Decode_Video1_16(
-  char *encoded,
-  int encoded_size,
-  char *decoded,
-  int width,
-  int height,
-  int bytes_per_pixel);
-
-void AVI_Decode_Video1_8(
-  char *encoded,
-  int encoded_size,
-  char *decoded,
-  int width,
-  int height,
-  unsigned char *palette_map,
-  int bytes_per_pixel);
-
-void *init_fli_decoder(int width, int height);
-
-void decode_fli_frame(
-  unsigned char *encoded,
-  int encoded_size,
-  unsigned char *decoded,
-  int width,
-  int height,
-  int bytes_per_pixel,
-  void *context);
-
-void qt_decode_rle(
-  unsigned char *encoded,
-  int encoded_size,
-  unsigned char *decoded,
-  int width,
-  int height,
-  int encoded_bpp,
-  int bytes_per_pixel);
-
-void decode_nuv(
-  unsigned char *encoded,
-  int encoded_size,
-  unsigned char *decoded,
-  int width,
-  int height);
-
-void *decode_cinepak_init(void);
-
-void decode_cinepak(
-  void *context,
-  unsigned char *buf,
-  int size,
-  mp_image_t *mpi);
-
-void decode_cyuv(
-  unsigned char *buf,
-  int size,
-  unsigned char *frame,
-  int width,
-  int height,
-  int bit_per_pixel);
-
-int qt_init_decode_smc(void);
-
-void qt_decode_smc(
-  unsigned char *encoded,
-  int encoded_size,
-  unsigned char *decoded,
-  int width,
-  int height,
-  unsigned char *palette_map,
-  int bytes_per_pixel);
-
-void decode_duck_tm1(
-  unsigned char *encoded,
-  int encoded_size,
-  unsigned char *decoded,
-  int width,
-  int height,
-  int bytes_per_pixel);
-
-#ifdef HAVE_PNG
-void decode_mpng(
-  unsigned char *encoded,
-  int encoded_size,
-  unsigned char *decoded,
-  int width,
-  int height,
-  int bytes_per_pixel);
-#endif
-
-void qt_decode_rpza(
-  unsigned char *encoded,
-  int encoded_size,
-  unsigned char *decoded,
-  int width,
-  int height,
-  int bytes_per_pixel);
-
-//**************************************************************************//
-//             The OpenDivX stuff:
-//**************************************************************************//
-
-#ifndef NEW_DECORE
-
-static unsigned char *opendivx_src[3];
-static int opendivx_stride[3];
-
-// callback, the opendivx decoder calls this for each frame:
-void convert_linux(unsigned char *puc_y, int stride_y,
-	unsigned char *puc_u, unsigned char *puc_v, int stride_uv,
-	unsigned char *bmp, int width_y, int height_y){
-
-//    printf("convert_yuv called  %dx%d  stride: %d,%d\n",width_y,height_y,stride_y,stride_uv);
-
-    opendivx_src[0]=puc_y;
-    opendivx_src[1]=puc_u;
-    opendivx_src[2]=puc_v;
-    
-    opendivx_stride[0]=stride_y;
-    opendivx_stride[1]=stride_uv;
-    opendivx_stride[2]=stride_uv;
-}
-#endif
-
-int get_video_quality_max(sh_video_t *sh_video){
- switch(sh_video->codec->driver){
-#ifdef USE_WIN32DLL
-  case VFM_VFW:
-  case VFM_VFWEX:
-      return 9; // for Divx.dll (divx4)
-#endif
-#ifdef USE_DIRECTSHOW
-  case VFM_DSHOW:
-      return 4;
-#endif
-#ifdef MPEG12_POSTPROC
-  case VFM_MPEG:
-      return GET_PP_QUALITY_MAX;
-#endif
-#ifdef FF_POSTPROCESS
-  case VFM_FFMPEG:
-      return GET_PP_QUALITY_MAX;
-#endif
-#ifdef USE_DIVX
-  case VFM_DIVX4:
-  case VFM_ODIVX:
-#ifdef NEW_DECORE
-      return 9; // for divx4linux
-#else
-      return GET_PP_QUALITY_MAX;  // for opendivx
-#endif
-#endif
- }
- return 0;
-}
-
-void set_video_quality(sh_video_t *sh_video,int quality){
- switch(sh_video->codec->driver){
-#ifdef USE_WIN32DLL
-  case VFM_VFW:
-  case VFM_VFWEX:
-   vfw_set_postproc(sh_video,10*quality);
-  break;
-#endif
-#ifdef USE_DIRECTSHOW
-  case VFM_DSHOW: {
-   if(quality<0 || quality>4) quality=4;
-   DS_VideoDecoder_SetValue(ds_vdec,"Quality",quality);
-  }
-  break;
-#endif
-#ifdef MPEG12_POSTPROC
-  case VFM_MPEG: {
-   if(quality<0 || quality>GET_PP_QUALITY_MAX) quality=GET_PP_QUALITY_MAX;
-   picture->pp_options=getPpModeForQuality(quality);
-  }
-  break;
-#endif
-#ifdef FF_POSTPROCESS
-  case VFM_FFMPEG:
-    if(quality<0 || quality>GET_PP_QUALITY_MAX) quality=GET_PP_QUALITY_MAX;
-    lavc_pp=getPpModeForQuality(quality);
-    break;
-#endif
-#ifdef USE_DIVX
-  case VFM_DIVX4:
-  case VFM_ODIVX: {
-   DEC_SET dec_set;
-#ifdef NEW_DECORE
-   if(quality<0 || quality>9) quality=9;
-   dec_set.postproc_level=quality*10;
-#else
-   if(quality<0 || quality>GET_PP_QUALITY_MAX) quality=GET_PP_QUALITY_MAX;
-   dec_set.postproc_level=getPpModeForQuality(quality);
-#endif
-   decore(0x123,DEC_OPT_SETPP,&dec_set,NULL);
-  }
-#endif
-  break;
- }
-}
-
-int set_video_colors(sh_video_t *sh_video,char *item,int value)
-{
-    if(vo_vaa.get_video_eq)
-    {
-	vidix_video_eq_t veq;
-	if(vo_vaa.get_video_eq(&veq) == 0)
-	{
-	    int v_hw_equ_cap = veq.cap;
-	    if(v_hw_equ_cap != 0)
-	    {
-		if(vo_vaa.set_video_eq)
-		{
-		    vidix_video_eq_t veq;
-		    veq.flags = VEQ_FLG_ITU_R_BT_601; /* Fixme please !!! */
-		    if(strcmp(item,"Brightness") == 0)
-		    {
-			if(!(v_hw_equ_cap & VEQ_CAP_BRIGHTNESS)) goto try_sw_control;
-			veq.brightness = value*10;
-			veq.cap = VEQ_CAP_BRIGHTNESS;
-		    }
-		    else
-		    if(strcmp(item,"Contrast") == 0)
-		    {
-			if(!(v_hw_equ_cap & VEQ_CAP_CONTRAST)) goto try_sw_control;
-			veq.contrast = value*10;
-			veq.cap = VEQ_CAP_CONTRAST;
-		    }
-		    else
-		    if(strcmp(item,"Saturation") == 0)
-		    {
-			if(!(v_hw_equ_cap & VEQ_CAP_SATURATION)) goto try_sw_control;
-			veq.saturation = value*10;
-			veq.cap = VEQ_CAP_SATURATION;
-		    }
-		    else
-		    if(strcmp(item,"Hue") == 0)
-		    {
-			if(!(v_hw_equ_cap & VEQ_CAP_HUE)) goto try_sw_control;
-			veq.hue = value*10;
-			veq.cap = VEQ_CAP_HUE;
-		    }
-		    else goto try_sw_control;;
-		    vo_vaa.set_video_eq(&veq);
-		}
-		return 1;
-	    }
-	}
-    }
-    try_sw_control:
-#ifdef USE_DIRECTSHOW
-    if(sh_video->codec->driver==VFM_DSHOW){
-	DS_VideoDecoder_SetValue(ds_vdec,item,value);
-	return 1;
-    }
-#endif
-
-#ifdef NEW_DECORE
-#ifdef DECORE_VERSION
-#if DECORE_VERSION >= 20011010
-    if(sh_video->codec->driver==VFM_DIVX4){
-         int option;
-         if(!strcmp(item,"Brightness")) option=DEC_GAMMA_BRIGHTNESS;
-         else if(!strcmp(item, "Contrast")) option=DEC_GAMMA_CONTRAST;
-         else if(!strcmp(item,"Saturation")) option=DEC_GAMMA_SATURATION;
-         else return 0;
-         value = (value * 256) / 100 - 128;
-         decore(0x123, DEC_OPT_GAMMA, (void *)option, (void *) value);
-         return 1;
-    }
-#endif
-#endif
-#endif
-
-#ifdef USE_TV
-    
-    if (tv_param_on == 1)
-    {
-	if (!strcmp(item, "Brightness"))
-	{
-	    tv_set_color_options(tv_handler, TV_COLOR_BRIGHTNESS, value);
-	    return(1);
-	}
-	if (!strcmp(item, "Hue"))
-	{
-	    tv_set_color_options(tv_handler, TV_COLOR_HUE, value);
-	    return(1);
-	}
-	if (!strcmp(item, "Saturation"))
-	{
-	    tv_set_color_options(tv_handler, TV_COLOR_SATURATION, value);
-	    return(1);
-	}
-	if (!strcmp(item, "Contrast"))
-	{
-	    tv_set_color_options(tv_handler, TV_COLOR_CONTRAST, value);
-	    return(1);
-	}
-    }
-#endif
-    return 0;
-}
-
-void uninit_video(sh_video_t *sh_video){
-    if(!sh_video->inited) return;
-    mp_msg(MSGT_DECVIDEO,MSGL_V,"uninit video: %d  \n",sh_video->codec->driver);
-    switch(sh_video->codec->driver){
-#ifdef USE_LIBAVCODEC
-    case VFM_FFMPEG:
-        if (avcodec_close(&lavc_context) < 0)
-    	    mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec);
-	break;
-#endif
-#ifdef USE_DIRECTSHOW
-    case VFM_DSHOW: // Win32/DirectShow
-	if(ds_vdec){ DS_VideoDecoder_Destroy(ds_vdec); ds_vdec=NULL; }
-	break;
-#endif
-    case VFM_MPEG:
-	mpeg2_free_image_buffers (picture);
-	break;
-#ifdef USE_XANIM
-    case VFM_XANIM:
-	xacodec_exit();
-	break;
-#endif
-#ifdef USE_DIVX
-    case VFM_DIVX4:
-    case VFM_ODIVX:
-      decore(0x123,DEC_OPT_RELEASE,NULL,NULL);
-      break;
-#endif
-    }
-    if(sh_video->our_out_buffer){
-	free(sh_video->our_out_buffer);
-	sh_video->our_out_buffer=NULL;
-    }
-    sh_video->inited=0;
-}
-
-int init_video(sh_video_t *sh_video,int *pitches)
-{
-unsigned int out_fmt=sh_video->codec->outfmt[sh_video->outfmtidx];
-pitches[0] = pitches[1] =pitches[2] = 0; /* fake unknown */
-
-sh_video->our_out_buffer=NULL;
-sh_video->our_out_buffer_size=0U;
-
-sh_video->image=new_mp_image(sh_video->disp_w,sh_video->disp_h);
-mp_image_setfmt(sh_video->image,out_fmt);
-
-switch(sh_video->codec->driver){
- case VFM_ROQVIDEO:
-#ifdef USE_MP_IMAGE
-   sh_video->image->type=MP_IMGTYPE_IP;
-#else
-   sh_video->our_out_buffer_size = sh_video->disp_w * sh_video->disp_h * 1.5;
-   sh_video->our_out_buffer = (char*)memalign(64, sh_video->our_out_buffer_size);
-#endif
-   sh_video->context = roq_decode_video_init();
-   break;
- case VFM_CINEPAK: {
-#ifdef USE_MP_IMAGE
-   sh_video->image->type=MP_IMGTYPE_STATIC;
-   sh_video->image->width=(sh_video->image->width+3)&(~3);
-   sh_video->image->height=(sh_video->image->height+3)&(~3);
-#else
-   int bpp=((out_fmt&255)+7)/8;
-   sh_video->our_out_buffer_size = sh_video->disp_w*sh_video->disp_h*bpp;
-   sh_video->our_out_buffer = (char*)memalign(64, sh_video->our_out_buffer_size);
-#endif
-   sh_video->context = decode_cinepak_init();
-   break;
- }
- case VFM_XANIM: {
-#ifdef USE_XANIM
-	   int ret=xacodec_init_video(sh_video,out_fmt);
-   if(!ret) return 0;
-#else
-//   mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_NoXAnimSupport);
-   mp_msg(MSGT_DECVIDEO, MSGL_ERR, "MPlayer was compiled WIHTOUT XAnim support!\n");
-   return 0;
-#endif
-   break;
- }
-#ifdef USE_WIN32DLL
- case VFM_VFW: {
-   if(!init_vfw_video_codec(sh_video,0)) {
-      return 0;
-   }  
-   mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32 video codec init OK!\n");
-   /* Warning: these pitches tested only with YUY2 fourcc */
-   pitches[0] = 16; pitches[1] = pitches[2] = 8;
-   break;
- }
- case VFM_VFWEX: {
-   if(!init_vfw_video_codec(sh_video,1)) {
-      return 0;
-   }  
-   mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32Ex video codec init OK!\n");
-   /* Warning: these pitches tested only with YUY2 fourcc */
-   pitches[0] = 16; pitches[1] = pitches[2] = 8;
-   break;
- }
- case VFM_DSHOW: { // Win32/DirectShow
-#ifndef USE_DIRECTSHOW
-   mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_NoDShowSupport);
-   return 0;
-#else
-   int bpp;
-   if(!(ds_vdec=DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, 0))){
-//   if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, NULL)){
-        mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_video->codec->dll);
-        mp_msg(MSGT_DECVIDEO,MSGL_HINT,"Maybe you forget to upgrade your win32 codecs?? It's time to download the new\n");
-        mp_msg(MSGT_DECVIDEO,MSGL_HINT,"package from:  ftp://mplayerhq.hu/MPlayer/releases/w32codec.zip  !\n");
-//        mp_msg(MSGT_DECVIDEO,MSGL_HINT,"Or you should disable DShow support: make distclean;make -f Makefile.No-DS\n");
-      return 0;
-   }
-
-#ifdef USE_MP_IMAGE
-   sh_video->image->type=MP_IMGTYPE_STATIC;
-   bpp=sh_video->image->bpp;
-   if(sh_video->image->flags&MP_IMGFLAG_YUV){
-     DS_VideoDecoder_SetDestFmt(ds_vdec,bpp,out_fmt);     // YUV
-   } else {
-     DS_VideoDecoder_SetDestFmt(ds_vdec,out_fmt&255,0);           // RGB/BGR
-   }
-#else
-   switch(out_fmt){
-   case IMGFMT_YUY2:
-   case IMGFMT_UYVY:
-     bpp=16;
-     DS_VideoDecoder_SetDestFmt(ds_vdec,16,out_fmt);break;        // packed YUV
-   case IMGFMT_YV12:
-   case IMGFMT_I420:
-   case IMGFMT_IYUV:
-     bpp=12;
-     DS_VideoDecoder_SetDestFmt(ds_vdec,12,out_fmt);break;        // planar YUV
-   default:
-     bpp=((out_fmt&255)+7)&(~7);
-     DS_VideoDecoder_SetDestFmt(ds_vdec,out_fmt&255,0);           // RGB/BGR
-   }
-   sh_video->our_out_buffer_size = sh_video->disp_w*sh_video->disp_h*bpp/8; // FIXME!!!
-   sh_video->our_out_buffer = (char*)memalign(64,sh_video->our_out_buffer_size); 
-#endif
-   /* Warning: these pitches tested only with YUY2 fourcc */
-   pitches[0] = 16; pitches[1] = pitches[2] = 8;
-   DS_SetAttr_DivX("Quality",divx_quality);
-
-   DS_VideoDecoder_StartInternal(ds_vdec);
-//   printf("DivX setting result = %d\n", DS_SetAttr_DivX("Quality",divx_quality) );
-//   printf("DivX setting result = %d\n", DS_SetValue_DivX("Brightness",60) );
-   
-   mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32/DShow video codec init OK!\n");
-   break;
-#endif
- }
-#else	/* !USE_WIN32DLL */
- case VFM_VFW:
- case VFM_DSHOW:
- case VFM_VFWEX:
-   mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_NoWfvSupport);
-   return 0;
-#endif	/* !USE_WIN32DLL */
- case VFM_ODIVX: {  // OpenDivX
-#ifndef USE_DIVX
-   mp_msg(MSGT_DECVIDEO,MSGL_ERR,"MPlayer was compiled WITHOUT OpenDivx support!\n");
-   return 0;
-#else
-   mp_msg(MSGT_DECVIDEO,MSGL_V,"OpenDivX video codec\n");
-   { DEC_PARAM dec_param;
-     DEC_SET dec_set;
-        memset(&dec_param,0,sizeof(dec_param));
-#ifdef NEW_DECORE
-        dec_param.output_format=DEC_USER;
-#else
-        dec_param.color_depth = 32;
-#endif
-#ifdef DECORE_DIVX5
-	/* codec_version should be 311, 400 or 500 according
-	 * to DivX version used in video, let's hope 500 is 
-	 * compatible with all DivX4 content, otherwise we
-	 * should find some logic to also choose between
-	 * 400 and 500 - Atmos
-	 */
-	dec_param.codec_version = (sh_video->format==mmioFOURCC('D','I','V','3'))?311:500;
-	dec_param.build_number = 0;
-#endif
-	dec_param.x_dim = sh_video->bih->biWidth;
-	dec_param.y_dim = sh_video->bih->biHeight;
-	decore(0x123, DEC_OPT_INIT, &dec_param, NULL);
-	dec_set.postproc_level = divx_quality;
-	decore(0x123, DEC_OPT_SETPP, &dec_set, NULL);
-   }
-   mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: OpenDivX video codec init OK!\n");
-   break;
-#endif
- }
- case VFM_DIVX4: {  // DivX4Linux
-#ifndef NEW_DECORE
-   mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_NoDivx4Support);
-   return 0;
-#else
-   mp_msg(MSGT_DECVIDEO,MSGL_V,"DivX4Linux video codec\n");
-   { DEC_PARAM dec_param;
-     DEC_SET dec_set;
-     int bits=16;
-        memset(&dec_param,0,sizeof(dec_param));
-	switch(out_fmt){
-	case IMGFMT_YV12: dec_param.output_format=DEC_YV12;bits=12;break;
-	case IMGFMT_YUY2: dec_param.output_format=DEC_YUY2;break;
-	case IMGFMT_UYVY: dec_param.output_format=DEC_UYVY;break;
-	case IMGFMT_I420: dec_param.output_format=DEC_420;bits=12;break;
-	case IMGFMT_BGR15: dec_param.output_format=DEC_RGB555_INV;break;
-	case IMGFMT_BGR16: dec_param.output_format=DEC_RGB565_INV;break;
-	case IMGFMT_BGR24: dec_param.output_format=DEC_RGB24_INV;bits=24;break;
-	case IMGFMT_BGR32: dec_param.output_format=DEC_RGB32_INV;bits=32;break;
-	default:
-	  mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Unsupported out_fmt: 0x%X\n",out_fmt);
-	  return 0;
-	}
-#ifdef DECORE_DIVX5
-	dec_param.codec_version = (sh_video->format==mmioFOURCC('D','I','V','3'))?311:500;
-	dec_param.build_number = 0;
-#endif
-	dec_param.x_dim = sh_video->bih->biWidth;
-	dec_param.y_dim = sh_video->bih->biHeight;
-	decore(0x123, DEC_OPT_INIT, &dec_param, NULL);
-	dec_set.postproc_level = divx_quality;
-	decore(0x123, DEC_OPT_SETPP, &dec_set, NULL);
-#ifdef USE_MP_IMAGE
-	sh_video->image->type=MP_IMGTYPE_STATIC;
-#else
-	sh_video->our_out_buffer_size = ((bits*dec_param.x_dim+7)/8)*dec_param.y_dim;
-	sh_video->our_out_buffer = (char*)memalign(64,sh_video->our_out_buffer_size);
-//	sh_video->our_out_buffer = shmem_alloc(dec_param.x_dim*dec_param.y_dim*5);
-#endif
-   }
-   mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: OpenDivX video codec init OK!\n");
-   break;
-#endif
- }
- case VFM_FFMPEG: {  // FFmpeg's libavcodec
-#ifndef USE_LIBAVCODEC
-   mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_NoLAVCsupport);
-   return 0;
-#else
-   /* Just because we know that */
-   pitches[0] = 16;
-   pitches[1] = pitches[2] = 8;
-   mp_msg(MSGT_DECVIDEO,MSGL_V,"FFmpeg's libavcodec video codec\n");
-    if(!avcodec_inited){
-      avcodec_init();
-      avcodec_register_all();
-      avcodec_inited=1;
-    }
-    lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_video->codec->dll);
-    if(!lavc_codec){
-	mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh_video->codec->dll);
-	return 0;
-    }
-    memset(&lavc_context, 0, sizeof(lavc_context));
-//    sh_video->disp_h/=2; // !!
-    lavc_context.width=sh_video->disp_w;
-    lavc_context.height=sh_video->disp_h;
-    mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",lavc_context.width,lavc_context.height);
-    if (sh_video->format == mmioFOURCC('R', 'V', '1', '3'))
-	lavc_context.sub_id = 3;
-    /* open it */
-    if (avcodec_open(&lavc_context, lavc_codec) < 0) {
-        mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec);
-        return 0;
-    }
-#ifdef FF_POSTPROCESS
-   lavc_pp=divx_quality;
-#endif
-   mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n");
-   break;
-#endif
- }
-
- case VFM_MPEG: {
-   // init libmpeg2:
-   mpeg2_init();
-#ifdef MPEG12_POSTPROC
-   picture->pp_options=divx_quality;
-#else
-   if(divx_quality) mp_msg(MSGT_DECVIDEO,MSGL_HINT,MSGTR_MpegPPhint);
-#endif
-   /* Just because we know that */
-   pitches[0] = 16;
-   pitches[1] = pitches[2] = 8;
-   // send seq header to the decoder:
-   mpeg2_decode_data(NULL,videobuffer,videobuffer+videobuf_len,0);
-   mpeg2_allocate_image_buffers (picture);
-   break;
- }
- case VFM_RAW: {
-   if (sh_video->format != 0x0)
-    /* set out_fmt */
-	sh_video->codec->outfmt[sh_video->outfmtidx] = sh_video->format;
-   break;
- }
- case VFM_RLE: {
-   int bpp=((out_fmt&255)+7)/8; // RGB only
-#ifdef USE_MP_IMAGE
-    sh_video->image->type=MP_IMGTYPE_STATIC;
-#else
-    sh_video->our_out_buffer_size = sh_video->disp_w*sh_video->disp_h*bpp; // FIXME!!!
-    sh_video->our_out_buffer = (char*)memalign(64,sh_video->our_out_buffer_size); 
-#endif
-   if(bpp==2){  // 15 or 16 bpp ==> palette conversion!
-     unsigned int* pal=(unsigned int*)(((char*)sh_video->bih)+40);
-     int cols=(sh_video->bih->biSize-40)/4;
-     //int cols=1<<(sh_video->bih->biBitCount);
-     int i;
-     if(cols>256) cols=256;
-     mp_msg(MSGT_DECVIDEO,MSGL_V,"RLE: converting palette for %d colors.\n",cols);
-     for(i=0;i<cols;i++){
-        unsigned int c=pal[i];
-	unsigned int b=c&255;
-	unsigned int g=(c>>8)&255;
-	unsigned int r=(c>>16)&255;
-	if((out_fmt&255)==15)
-	  pal[i]=((r>>3)<<10)|((g>>3)<<5)|((b>>3));
-	else
-	  pal[i]=((r>>3)<<11)|((g>>2)<<5)|((b>>3));
-     }
-   }
-   break;
- case VFM_FLI:
-   sh_video->context = init_fli_decoder(sh_video->disp_w, sh_video->disp_h);
- case VFM_MSVIDC:
- case VFM_QTRLE:
- case VFM_DUCKTM1:
-#ifdef HAVE_PNG
- case VFM_MPNG:
-#endif
- case VFM_QTRPZA:
-   {
-#ifdef USE_MP_IMAGE
-    sh_video->image->type=MP_IMGTYPE_STATIC;
-#else
-   int bpp=((out_fmt&255)+7)/8; // RGB only
-   sh_video->our_out_buffer_size =  sh_video->disp_w*sh_video->disp_h*bpp; // FIXME!!!
-   sh_video->our_out_buffer = (char*)memalign(64,sh_video->our_out_buffer_size); 
-#endif
-if ((sh_video->codec->driver == VFM_QTRLE) && (sh_video->bih->biBitCount != 24))
-  printf (
-    "    *** FYI: This Quicktime file is using %d-bit RLE Animation\n" \
-    "    encoding, which is not yet supported by MPlayer. But if you upload\n" \
-    "    this Quicktime file to the MPlayer FTP, the team could look at it.\n",
-    sh_video->bih->biBitCount);
-
-   break;
-   }
- case VFM_QTSMC:
-   {
-   if (qt_init_decode_smc() != 0)
-     mp_msg(MSGT_DECVIDEO, MSGL_ERR, "SMC decoder could not allocate enough memory");
-#ifdef USE_MP_IMAGE
-    sh_video->image->type=MP_IMGTYPE_STATIC;
-#else
-   int bpp=((out_fmt&255)+7)/8; // RGB only
-   sh_video->our_out_buffer_size = sh_video->disp_w*sh_video->disp_h*bpp; // FIXME!!!
-   sh_video->our_out_buffer = (char*)memalign(64, sh_video->our_out_buffer_size); 
-#endif
-   break;
-   }
- case VFM_NUV:
-#ifdef USE_MP_IMAGE
-    sh_video->image->type=MP_IMGTYPE_STATIC;
-#else
-    sh_video->our_out_buffer_size =  sh_video->disp_w*sh_video->disp_h*3/2;
-    sh_video->our_out_buffer = (char *)memalign(64,sh_video->our_out_buffer_size);
-#endif
-   break;
- case VFM_CYUV: {
-//   int bpp=((out_fmt&255)+7)/8;
-#ifdef USE_MP_IMAGE
-    sh_video->image->type=MP_IMGTYPE_STATIC;
-#else
-   sh_video->our_out_buffer_size = sh_video->disp_w*sh_video->disp_h*3;
-   sh_video->our_out_buffer = (char*)memalign(64, sh_video->our_out_buffer_size);
-#endif
-   break;
-   }
- }
-}
-  sh_video->inited=1;
-  return 1;
-}
-
-extern int vo_directrendering;
-
-static int use_dr=0,use_dr_422=0;
-static bes_da_t bda;
-static int multi_buff_num = 0;
-void init_video_vaa( unsigned width )
-{
-  unsigned adp;
-  memset(&bda,0,sizeof(bes_da_t));
-  if(vo_vaa.query_bes_da)
-    use_dr = vo_vaa.query_bes_da(&bda) ? 0 : 1;
-  if(!vo_directrendering) use_dr = 0;
-  if(use_dr)
-  {
-    uint32_t sstride,dstride;
-    sstride=width*2;
-    adp = bda.dest.pitch.y-1;
-    dstride=(width*2+adp)&~adp;
-    if(sstride == dstride) use_dr_422 = 1;
-  }
-}
-
-#ifdef USE_LIBVO2
-int decode_video(vo2_handle_t *video_out,sh_video_t *sh_video,unsigned char *start,int in_size,int drop_frame){
-#else
-int decode_video(vo_functions_t *video_out,sh_video_t *sh_video,unsigned char *start,int in_size,int drop_frame){
-#endif
-
-mp_image_t *mpi=sh_video->image;
-unsigned int out_fmt=mpi->imgfmt; //sh_video->codec->outfmt[sh_video->outfmtidx];
-int planar=(mpi->flags&MP_IMGFLAG_PLANAR)!=0; //(out_fmt==IMGFMT_YV12||out_fmt==IMGFMT_IYUV||out_fmt==IMGFMT_I420);
-int blit_frame=0;
-void *vmem;
-int painted;
-
-//uint8_t* planes_[3];
-//uint8_t** planes=planes_;
-//int stride_[3];
-//int* stride=stride_;
-
-unsigned int t=GetTimer();
-unsigned int t2;
-double tt;
-
-  painted = 0;
-#ifdef USE_MP_IMAGE
-if(mpi->type!=MP_IMGTYPE_EXPORT)
-if( !(mpi->flags&MP_IMGFLAG_ALLOCATED) && !(mpi->flags&MP_IMGFLAG_DIRECT) ){
-    // allocate image buffer:
-    sh_video->our_out_buffer = (char *)memalign(64, mpi->width*mpi->height*mpi->bpp/8);
-    if((mpi->flags|MP_IMGFLAG_PLANAR) && (mpi->flags|MP_IMGFLAG_YUV)){
-	// planar YUV
-	mpi->stride[0]=mpi->width;
-	mpi->stride[1]=mpi->stride[2]=mpi->width/2;
-	mpi->planes[0]=sh_video->our_out_buffer;
-	mpi->planes[1]=mpi->planes[0]+mpi->stride[0]*mpi->height;
-	mpi->planes[2]=mpi->planes[1]+mpi->stride[0]*mpi->height/4;
-    } else {
-	// packed YUV / RGB
-	mpi->stride[0]=mpi->width*mpi->bpp;
-	mpi->planes[0]=sh_video->our_out_buffer;
-    }
-    mpi->flags|=MP_IMGFLAG_ALLOCATED;
-    mp_msg(MSGT_DECVIDEO,MSGL_INFO,"mp_image: allocated %d bytes for %dx%dx%d [0x%X] image\n", 
-	    mpi->width*mpi->height*mpi->bpp/8, mpi->width, mpi->height, mpi->bpp, mpi->imgfmt);
-}
-#endif
-
-//printf("decode_frame(start: %p, size: %d, w: %d, h: %d)\n",
-//    start, in_size, sh_video->disp_w, sh_video->disp_h);
-
-  //--------------------  Decode a frame: -----------------------
-switch(sh_video->codec->driver){
- case VFM_CINEPAK:
-   if (in_size == 0)
-     blit_frame = 0;
-   else
-   {
-     decode_cinepak(sh_video->context, start, in_size, mpi);
-     blit_frame = 2;
-   }
-   break;
-#ifdef USE_XANIM
-  case VFM_XANIM: {
-    xacodec_image_t* image=xacodec_decode_frame(start,in_size,drop_frame?1:0);
-    if(image){
-	blit_frame=2;
-	//planes=image->planes;
-	//stride=image->stride;
-	mpi->planes[0]=image->planes[0];
-	mpi->planes[1]=image->planes[1];
-	mpi->planes[2]=image->planes[2];
-	mpi->stride[0]=image->stride[0];
-	mpi->stride[1]=image->stride[1];
-	mpi->stride[2]=image->stride[2];
-    }
-    break;
-  }
-#endif
-#ifdef USE_DIVX
-  case VFM_ODIVX: {
-    // OpenDivX
-    DEC_FRAME dec_frame;
-#ifdef NEW_DECORE
-    DEC_PICTURE dec_pic;
-#endif
-    // let's decode
-        dec_frame.length = in_size;
-	dec_frame.bitstream = start;
-	dec_frame.render_flag = drop_frame?0:1;
-
-#ifdef NEW_DECORE
-        dec_frame.bmp=&dec_pic;
-        dec_pic.y=dec_pic.u=dec_pic.v=NULL;
-#ifdef DECORE_DIVX5
-	decore(0x123, DEC_OPT_FRAME, &dec_frame, NULL);
-#else
-	decore(0x123, (sh_video->format==mmioFOURCC('D','I','V','3'))?DEC_OPT_FRAME_311:DEC_OPT_FRAME, &dec_frame, NULL);
-#endif
-#else
-        opendivx_src[0]=NULL;
-	decore(0x123, 0, &dec_frame, NULL);
-#endif
-  
-      if(!drop_frame)
-
-    // let's display
-#ifdef NEW_DECORE
-      if(dec_pic.y){
-        mpi->planes[0]=dec_pic.y;
-        mpi->planes[1]=dec_pic.u;
-        mpi->planes[2]=dec_pic.v;
-        mpi->stride[0]=dec_pic.stride_y;
-        mpi->stride[1]=mpi->stride[2]=dec_pic.stride_uv;
-        blit_frame=2;
-      }
-#else
-      if(opendivx_src[0]){
-//        planes=opendivx_src;
-//	stride=opendivx_stride;
-	mpi->planes[0]=opendivx_src[0];
-	mpi->planes[1]=opendivx_src[1];
-	mpi->planes[2]=opendivx_src[2];
-	mpi->stride[0]=opendivx_stride[0];
-	mpi->stride[1]=opendivx_stride[1];
-	mpi->stride[2]=opendivx_stride[2];
-        blit_frame=2;
-      }
-#endif
-
-    break;
-  }
-#endif
-#ifdef NEW_DECORE
-  case VFM_DIVX4: {
-    // DivX4Linux
-    DEC_FRAME dec_frame;
-    // let's decode
-        dec_frame.length = in_size;
-	dec_frame.bitstream = start;
-	dec_frame.render_flag = drop_frame?0:1;
-        dec_frame.bmp=sh_video->our_out_buffer;
-        dec_frame.stride=sh_video->disp_w;
-//	printf("Decoding DivX4 frame\n");
-#ifdef DECORE_DIVX5
-	decore(0x123, DEC_OPT_FRAME, &dec_frame, NULL);
-#else
-	decore(0x123, (sh_video->format==mmioFOURCC('D','I','V','3'))?DEC_OPT_FRAME_311:DEC_OPT_FRAME, &dec_frame, NULL);
-#endif
-    if(!drop_frame) blit_frame=3;
-    break;
-  }
-#endif
-#ifdef USE_DIRECTSHOW
-  case VFM_DSHOW: {        // W32/DirectShow
-    if(drop_frame<2)
-    {
-	/* FIXME: WILL WORK ONLY FOR PACKED FOURCC. BUT WHAT ABOUT PLANAR? */
-        vmem = 0;
-	if(use_dr_422)
-	{
-	    vmem = bda.dga_addr + bda.offsets[0] + bda.offset.y;
-	    if(vo_doublebuffering && bda.num_frames>1)
-	    {
-		vmem = bda.dga_addr + bda.offsets[multi_buff_num] + bda.offset.y;
-		multi_buff_num=(multi_buff_num+1)%bda.num_frames;
-	    }
-	}
-	DS_VideoDecoder_DecodeInternal(ds_vdec, start, in_size, 0, drop_frame ? 0 : vmem ? vmem : sh_video->our_out_buffer);
-	if(vmem) painted = 1; 
-    }
-    if(!drop_frame && sh_video->our_out_buffer) blit_frame=3;
-    break;
-  }
-#endif
-#ifdef USE_LIBAVCODEC
-  case VFM_FFMPEG: {        // libavcodec
-    int got_picture=0;
-    mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"Calling ffmpeg...\n");
-    if(drop_frame<2 && in_size>0){
-        int ret = avcodec_decode_video(&lavc_context, &lavc_picture,
-	     &got_picture, start, in_size);
-if(verbose>1){
-     unsigned char *x="???";
-     switch(lavc_context.pix_fmt){
-     case PIX_FMT_YUV420P: x="YUV420P";break;
-     case PIX_FMT_YUV422: x="YUV422";break;
-     case PIX_FMT_RGB24: x="RGB24";break;
-     case PIX_FMT_BGR24: x="BGR24";break;
-#ifdef PIX_FMT_YUV422P
-     case PIX_FMT_YUV422P: x="YUV422P";break;
-     case PIX_FMT_YUV444P: x="YUV444P";break;
-#endif
-     }
-     mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"DONE -> got_picture=%d  format=0x%X (%s) \n",got_picture,
-	lavc_context.pix_fmt,x);
-}
-	if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n");
-	if(!drop_frame && got_picture){
-//	if(!drop_frame){
-	  if(planar){
-#ifdef FF_POSTPROCESS
-#ifdef MBC
-	    if(lavc_pp){
-		// postprocess
-		int w=(sh_video->disp_w+15)&(~15);
-		int h=(sh_video->disp_h+15)&(~15);
-		int xoff=0; //(w-sh_video->disp_w)/2;
-		int yoff=0; //(h-sh_video->disp_h)/2;
-		if(!sh_video->our_out_buffer){
-		    sh_video->our_out_buffer = (char*)memalign(64,w*h*3/2);
-		    memset(sh_video->our_out_buffer,0,w*h*3/2);
-		}
-    		mpi->stride[0]=w;
-    		mpi->stride[1]=mpi->stride[2]=w/2;
-    		mpi->planes[0]=sh_video->our_out_buffer+mpi->stride[0]*yoff+xoff;
-    		mpi->planes[2]=sh_video->our_out_buffer+w*h+mpi->stride[2]*(yoff>>1)+(xoff>>1);
-    		mpi->planes[1]=mpi->planes[2]+w*h/4;
-		postprocess(lavc_picture.data,lavc_picture.linesize[0],
-			    mpi->planes,mpi->stride[0],
-			    sh_video->disp_w,sh_video->disp_h,
-			    &quant_store[0][0],MBC+1,lavc_pp);
-	    } else
-#endif
-#endif
-	    {
-		//planes=lavc_picture.data;
-		//stride=lavc_picture.linesize;
-		mpi->planes[0]=lavc_picture.data[0];
-		mpi->planes[1]=lavc_picture.data[1];
-		mpi->planes[2]=lavc_picture.data[2];
-		mpi->stride[0]=lavc_picture.linesize[0];
-		mpi->stride[1]=lavc_picture.linesize[1];
-		mpi->stride[2]=lavc_picture.linesize[2];
-		if(lavc_context.pix_fmt==PIX_FMT_YUV422P){
-		    mpi->stride[1]*=2;
-		    mpi->stride[2]*=2;
-		}
-		
-		//stride[1]=stride[2]=0;
-		//stride[0]/=2;
-	    }
-    	    blit_frame=2;
-	  } else {
-	    int y;
-	    // temporary hack - FIXME
-	    if(!sh_video->our_out_buffer)
-		sh_video->our_out_buffer = (char*)memalign(64,sh_video->disp_w*sh_video->disp_h*2);
-	    for(y=0;y<sh_video->disp_h;y++){
-	      unsigned char *s0=lavc_picture.data[0]+lavc_picture.linesize[0]*y;
-	      unsigned char *s1=lavc_picture.data[1]+lavc_picture.linesize[1]*y;
-	      unsigned char *s2=lavc_picture.data[2]+lavc_picture.linesize[2]*y;
-	      unsigned char *d=sh_video->our_out_buffer+y*2*sh_video->disp_w;
-	      int x;
-	      for(x=0;x<sh_video->disp_w/2;x++){
-	          d[4*x+0]=s0[2*x+0];
-	          d[4*x+1]=s1[x];
-	          d[4*x+2]=s0[2*x+1];
-	          d[4*x+3]=s2[x];
-	      }
-	    }
-            blit_frame=3;
-	  }
-
-	}
-    }
-    break;
-  }
-#endif
-#ifdef USE_WIN32DLL
-  case VFM_VFWEX:
-  case VFM_VFW:
-  {
-    int ret;
-    if(!in_size) break;
-	/* FIXME: WILL WORK ONLY FOR PACKED FOURCC. BUT WHAT ABOUT PLANAR? */
-        vmem = 0;
-	if(use_dr_422)
-	{
-	    vmem = bda.dga_addr + bda.offsets[0] + bda.offset.y;
-	    if(vo_doublebuffering && bda.num_frames>1)
-	    {
-		vmem = bda.dga_addr + bda.offsets[multi_buff_num] + bda.offset.y;
-		multi_buff_num=(multi_buff_num+1)%bda.num_frames;
-	    }
-	    sh_video->our_out_buffer = vmem;
-	}
-    if((ret=vfw_decode_video(sh_video,start,in_size,drop_frame,(sh_video->codec->driver==VFM_VFWEX) ))){
-      mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error decompressing frame, err=%d\n",ret);
-      break;
-    }
-    if(vmem) painted=1;
-    if(!drop_frame) blit_frame=3;
-    break;
-  }
-#endif
-  case VFM_MPEG:
-    if(out_fmt==IMGFMT_MPEGPES){
-	// hardware decoding:
-	static vo_mpegpes_t packet;
-	mpeg2_decode_data(video_out, start, start+in_size,3); // parse headers
-	packet.data=start;
-	packet.size=in_size-4;
-	packet.timestamp=sh_video->timer*90000.0;
-	packet.id=0x1E0; //+sh_video->ds->id;
-	mpi->planes[0]=(uint8_t*)(&packet);
-	blit_frame=2;
-    } else {
-	// software decoding:
-	if(
-	mpeg2_decode_data(video_out, start, start+in_size,drop_frame) > 0 // decode
-	&& (!drop_frame)
-	   ) blit_frame=1;
-    }
-    break;
-  case VFM_RAW:
-//    planes[0]=start;
-//    blit_frame=2;
-    sh_video->our_out_buffer = start;
-    blit_frame=3;
-    break;
-  case VFM_RLE:
-//void AVI_Decode_RLE8(char *image,char *delta,int tdsize,
-//    unsigned int *map,int imagex,int imagey,unsigned char x11_bytes_pixel);
-    AVI_Decode_RLE8(sh_video->our_out_buffer,start,in_size, 
-       (int*)(((char*)sh_video->bih)+40),
-      sh_video->disp_w,sh_video->disp_h,((out_fmt&255)+7)/8);
-    blit_frame=3;
-    break;
-  case VFM_MSVIDC:
-    if (sh_video->bih->biBitCount == 16)
-      AVI_Decode_Video1_16(
-        start, in_size, sh_video->our_out_buffer,
-        sh_video->disp_w, sh_video->disp_h,
-        ((out_fmt&255)+7)/8);
-    else
-      AVI_Decode_Video1_8(
-        start, in_size, sh_video->our_out_buffer,
-        sh_video->disp_w, sh_video->disp_h,
-        (char *)sh_video->bih+40, ((out_fmt&255)+7)/8);
-    blit_frame = 3;
-    break;
-  case VFM_FLI:
-    decode_fli_frame(
-        start, in_size, sh_video->our_out_buffer,
-        sh_video->disp_w, sh_video->disp_h,
-        ((out_fmt&255)+7)/8,
-        sh_video->context);
-    blit_frame = 3;
-    break;
-  case VFM_NUV:
-    decode_nuv(
-        start, in_size, sh_video->our_out_buffer,
-        sh_video->disp_w, sh_video->disp_h);
-    blit_frame = 3;
-    break;
-  case VFM_QTRLE:
-    qt_decode_rle(
-        start, in_size, sh_video->our_out_buffer,
-        sh_video->disp_w, sh_video->disp_h,
-        sh_video->bih->biBitCount,
-        ((out_fmt&255)+7)/8);
-    blit_frame = 3;
-    break;
-  case VFM_QTSMC:
-    qt_decode_smc(
-        start, in_size, sh_video->our_out_buffer,
-        sh_video->disp_w, sh_video->disp_h,
-        (unsigned char *)sh_video->bih+40,
-        ((out_fmt&255)+7)/8);
-    blit_frame = 3;
-    break;
-  case VFM_DUCKTM1:
-    decode_duck_tm1(
-        start, in_size, sh_video->our_out_buffer,
-        sh_video->disp_w, sh_video->disp_h,
-        ((out_fmt&255)+7)/8);
-    blit_frame = 3;
-    break;
-#ifdef HAVE_PNG
- case VFM_MPNG:
-    decode_mpng(
-        start, in_size, sh_video->our_out_buffer,
-	sh_video->disp_w,sh_video->disp_h,
-	((out_fmt&255)+7)/8
-    );
-    blit_frame = 3;
-    break;
-#endif
- case VFM_CYUV:
-   decode_cyuv(start, in_size, sh_video->our_out_buffer,
-      sh_video->disp_w, sh_video->disp_h, (out_fmt==IMGFMT_YUY2)?16:(out_fmt&255));
-   blit_frame = 3;
-   break;
- case VFM_ROQVIDEO:
-   roq_decode_video(sh_video->context, start, in_size, mpi);
-   blit_frame = 2;
-   break;
-  case VFM_QTRPZA:
-    qt_decode_rpza(
-        start, in_size, sh_video->our_out_buffer,
-        sh_video->disp_w, sh_video->disp_h,
-        ((out_fmt&255)+7)/8);
-    blit_frame = 3;
-    break;
-} // switch
-//------------------------ frame decoded. --------------------
-
-#ifdef ARCH_X86
-	// some codecs is broken, and doesn't restore MMX state :(
-	// it happens usually with broken/damaged files.
-if(gCpuCaps.has3DNow){
-	__asm __volatile ("femms\n\t":::"memory");
-}
-else if(gCpuCaps.hasMMX){
-	__asm __volatile ("emms\n\t":::"memory");
-}
-#endif
-
-t2=GetTimer();t=t2-t;
-tt = t*0.000001f;
-video_time_usage+=tt;
-if(benchmark)
-{
-    if(tt > max_video_time_usage) max_video_time_usage=tt;
-    cur_video_time_usage=tt;
-}
-if(painted) return 1;
-switch(blit_frame){
-case 3:
-      if(planar){
-        mpi->stride[0]=sh_video->disp_w;
-        mpi->stride[1]=mpi->stride[2]=sh_video->disp_w/2;
-        mpi->planes[0]=sh_video->our_out_buffer;
-        mpi->planes[2]=mpi->planes[0]+sh_video->disp_w*sh_video->disp_h;
-        mpi->planes[1]=mpi->planes[2]+sh_video->disp_w*sh_video->disp_h/4;
-      } else {
-        mpi->planes[0]=sh_video->our_out_buffer;
-	mpi->stride[0]=sh_video->disp_w*mpi->bpp;
-	if(sh_video->bih && sh_video->bih->biSize==1064)
-	    mpi->planes[1]=&sh_video->bih[1]; // pointer to palette
-	else
-	    mpi->planes[1]=NULL;
-      }
-//#define VFM_RAW_POSTPROC
-#ifdef VFM_RAW_POSTPROC
-    if (sh_video->codec->driver == VFM_RAW)
-    {
-	mp_dbg(MSGT_DECVIDEO, MSGL_V, "Postprocessing raw %s!\n",
-	    vo_format_name(out_fmt));
-	switch(out_fmt)
-	{
-	    case IMGFMT_YV12:
-		postprocess(planes, stride[0], planes, stride[0],
-		    sh_video->disp_w, sh_video->disp_h, planes[0],
-		    0, /*0x20000*/divx_quality);
-		break;
-//	    case IMGFMT_UYVY:
-//		uyvytoyv12(start, planes[0], planes[1], planes[2],
-//		    sh_video->disp_w, sh_video->disp_h, stride[0], stride[1],
-//		    sh_video->disp_w*2);
-//		postprocess(planes, stride[0], planes, stride[0],
-//		    sh_video->disp_w, sh_video->disp_h, planes[0],
-//		    0, /*0x20000*/divx_quality);
-//		break;
-	    default:
-		mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, "Unsuitable outformat (%s) for raw pp!\n",
-		    vo_format_name(out_fmt));
-	}
-    }
-#endif
-case 2:
-#ifdef USE_LIBVO2
-    if(planar)
-        vo2_draw_slice(video_out,planes,stride,sh_video->disp_w,sh_video->disp_h,0,0);
-    else
-        vo2_draw_frame(video_out,planes[0],sh_video->disp_w,sh_video->disp_w,sh_video->disp_h);
-#else
-    if(planar)
-        video_out->draw_slice(mpi->planes,mpi->stride,sh_video->disp_w,sh_video->disp_h,0,0);
-    else
-        video_out->draw_frame(mpi->planes);
-#endif
-    t2=GetTimer()-t2;
-    tt=t2*0.000001f;
-    vout_time_usage+=tt;
-    if(benchmark)
-    {
-	if(tt > max_vout_time_usage) max_vout_time_usage = tt;
-	cur_vout_time_usage=tt;
-    }
-    blit_frame=1;
-    break;
-}
-
-  return blit_frame;
-}
-
-
--- a/ducktm1.c	Sat Apr 13 17:28:33 2002 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-/*
-    Duck Truemotion v1 Decoder for MPlayer
-    by Mike Melanson
-*/
-
-#include "config.h"
-#include "bswap.h"
-
-void decode_duck_tm1(
-  unsigned char *encoded,
-  int encoded_size,
-  unsigned char *decoded,
-  int width,
-  int height,
-  int bytes_per_pixel)
-{
-}
--- a/mpng.c	Sat Apr 13 17:28:33 2002 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-#include <stdlib.h>
-
-#include "config.h"
-#include "bswap.h"
-#include "postproc/rgb2rgb.h"
-#include "libvo/fastmemcpy.h"
-#include "mp_msg.h"
-#include "png.h"
-
-static int    pngPointer;
-
-static void pngReadFN( png_structp pngstr,png_bytep buffer,png_size_t size )
-{
- char * p = pngstr->io_ptr;
- memcpy( buffer,(char *)&p[pngPointer],size );
- pngPointer+=size;
-}
-
-void decode_mpng(
-  unsigned char *encoded,
-  int encoded_size,
-  unsigned char *decoded,
-  int width,
-  int height,
-  int bytes_per_pixel)
-{
- png_structp     png;
- png_infop       info;
- png_infop       endinfo;
- png_bytep       data;
- png_bytep     * row_p;
- png_uint_32     png_width,png_height;
- char	       * palette = NULL;
- int             depth,color;
- png_uint_32     i;
-
- /* currently supporting only 24 and 32bpp */
- if ((bytes_per_pixel != 3) && (bytes_per_pixel != 4))
- {
-    /* is this memset really needed? */
-    memset(decoded, 0, width*height*bytes_per_pixel);
-    return;
- }
-
- png=png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL );
- info=png_create_info_struct( png );
- endinfo=png_create_info_struct( png );
-
- pngPointer=8;
- png_set_read_fn( png,encoded,pngReadFN );
- png_set_sig_bytes( png,8 );
- png_read_info( png,info );
- png_get_IHDR( png,info,&png_width,&png_height,&depth,&color,NULL,NULL,NULL );
-
- png_set_bgr( png );
-
-#if 0
- switch( info->color_type )
-  {
-   case PNG_COLOR_TYPE_GRAY_ALPHA: printf( "[png] used GrayA -> stripping alpha channel\n" ); break;
-   case PNG_COLOR_TYPE_GRAY:       printf( "[png] used Gray -> rgb\n" ); break;
-   case PNG_COLOR_TYPE_PALETTE:    printf( "[png] used palette -> rgb\n" ); break;
-   case PNG_COLOR_TYPE_RGB_ALPHA:  printf( "[png] used RGBA -> stripping alpha channel\n" ); break;
-   case PNG_COLOR_TYPE_RGB:        printf( "[png] read rgb datas.\n" ); break;
-  }
-#endif
-
- if ( info->color_type == PNG_COLOR_TYPE_RGB ) data=decoded;
-  else data=(png_bytep)malloc( png_get_rowbytes( png,info ) * height );
-
- row_p=(png_bytep*)malloc( sizeof( png_bytep ) * png_height );
- for ( i=0; i < png_height; i++ ) row_p[i]=&data[png_get_rowbytes( png,info ) * i];
- png_read_image( png,row_p );
- free( row_p );
-						     
- switch( info->color_type )
-  {
-   case PNG_COLOR_TYPE_GRAY_ALPHA:
-          mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry gray scaled png with alpha channel not supported at moment.\n" );
-          free( data );
-	  break;
-   case PNG_COLOR_TYPE_GRAY:
-	  /* constant 256 colors */
-          palette=malloc( 1024 );
-          for ( i=0;i < 256;i++ ) palette[(i*4)]=palette[(i*4)+1]=palette[(i*4)+2]=(char)i;
-	  if (bytes_per_pixel == 4)
-	    palette8torgb32( data,decoded,png_width * png_height,palette );
-	  else
-	    palette8torgb24( data,decoded,png_width * png_height,palette );
-          free( data );
-	  break;
-   case PNG_COLOR_TYPE_PALETTE:
-          { 
-           int    cols;
-	   unsigned char * pal;
-           png_get_PLTE( png,info,(png_colorp*)&pal,&cols ); 
-           palette=calloc( 1,cols*4 );
-	   mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, "[mPNG] palette. used colors: %d\n", cols);
-	   for ( i=0;i < cols;i++ )
-	    {
-	     palette[(i*4)  ]=pal[(i*3)+2];
-	     palette[(i*4)+1]=pal[(i*3)+1];
-	     palette[(i*4)+2]=pal[(i*3)  ];
-	    }
-	  }
-	  if (bytes_per_pixel == 4)
-	    palette8torgb32( data,decoded,png_width * png_height,palette );
-	  else
-	    palette8torgb24( data,decoded,png_width * png_height,palette );
-          free( data );
-	  break;
-   case PNG_COLOR_TYPE_RGB_ALPHA:
-	  if (bytes_per_pixel == 4)
-	    memcpy(decoded, data, png_width * png_height * 4);
-	  else
-            rgb32to24( data,decoded,png_width * png_height * 4 );
-          free( data );
-	  break;
-  }
-
- if ( palette ) free( palette );
-
- png_read_end( png,endinfo );
- png_destroy_read_struct( &png,&info,&endinfo );
-}
-