diff options
-rw-r--r-- | adpcm.c | 505 | ||||
-rw-r--r-- | adpcm.h | 33 | ||||
-rw-r--r-- | dec_audio.c | 1444 | ||||
-rw-r--r-- | dec_video.c | 1323 | ||||
-rw-r--r-- | ducktm1.c | 17 | ||||
-rw-r--r-- | mpng.c | 126 |
6 files changed, 0 insertions, 3448 deletions
diff --git a/adpcm.c b/adpcm.c deleted file mode 100644 index c48afddc21..0000000000 --- a/adpcm.c +++ /dev/null @@ -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 - diff --git a/adpcm.h b/adpcm.h deleted file mode 100644 index e4048c4ca1..0000000000 --- a/adpcm.h +++ /dev/null @@ -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 diff --git a/dec_audio.c b/dec_audio.c deleted file mode 100644 index 8cf576a8ca..0000000000 --- a/dec_audio.c +++ /dev/null @@ -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; |