Mercurial > mplayer.hg
changeset 7172:33c38a0c20e8
renamed to match driver family name
author | arpi |
---|---|
date | Fri, 30 Aug 2002 19:49:37 +0000 |
parents | 772f853f32a1 |
children | 228a210c6aa7 |
files | libmpcodecs/ad_a52.c libmpcodecs/ad_liba52.c libmpcodecs/ad_libvorbis.c libmpcodecs/ad_real.c libmpcodecs/ad_realaud.c libmpcodecs/ad_vorbis.c libmpcodecs/vd_real.c libmpcodecs/vd_realvid.c |
diffstat | 8 files changed, 856 insertions(+), 856 deletions(-) [+] |
line wrap: on
line diff
--- a/libmpcodecs/ad_a52.c Fri Aug 30 19:40:24 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,192 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include "config.h" -#include "mp_msg.h" -#include "help_mp.h" - -#include "ad_internal.h" - -#include "cpudetect.h" - -#include "../liba52/a52.h" -#include "../liba52/mm_accel.h" - -static sample_t * a52_samples; -static a52_state_t a52_state; -static uint32_t a52_flags=0; - -#include "bswap.h" - -static ad_info_t info = -{ - "AC3-liba52", - "liba52", - AFM_A52, - "Nick Kurshev", - "Michel LESPINASSE", - "" -}; - -LIBAD_EXTERN(liba52) - -extern int audio_output_channels; - -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; -} - - -static int preinit(sh_audio_t *sh) -{ - /* Dolby AC3 audio: */ - /* however many channels, 2 bytes in a word, 256 samples in a block, 6 blocks in a frame */ - sh->audio_out_minsize=audio_output_channels*2*256*6; - sh->audio_in_minsize=3840; - return 1; -} - -static int init(sh_audio_t *sh_audio) -{ - uint32_t a52_accel=0; - 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"); - return 0; - } - if(a52_fillbuff(sh_audio)<0){ - mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n"); - return 0; - } - /* 'a52 cannot upmix' hotfix:*/ - a52_printinfo(sh_audio); - 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"); - return 0; - } - 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"); - return 0; - } - return 1; -} - -static void uninit(sh_audio_t *sh) -{ -} - -static int control(sh_audio_t *sh,int cmd,void* arg, ...) -{ - switch(cmd) - { - case ADCTRL_SKIP_FRAME: - a52_fillbuff(sh); break; // skip AC3 frame - return CONTROL_TRUE; - } - return CONTROL_UNKNOWN; -} - -static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen) -{ - sample_t level=1, bias=384; - int flags=a52_flags|A52_ADJUST_LEVEL; - int i,len=-1; - if(!sh_audio->a_in_buffer_len) - if(a52_fillbuff(sh_audio)<0) return len; /* 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"); - return len; - } - 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,(int16_t *)&buf[len]); - } - return len; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libmpcodecs/ad_liba52.c Fri Aug 30 19:49:37 2002 +0000 @@ -0,0 +1,192 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "config.h" +#include "mp_msg.h" +#include "help_mp.h" + +#include "ad_internal.h" + +#include "cpudetect.h" + +#include "../liba52/a52.h" +#include "../liba52/mm_accel.h" + +static sample_t * a52_samples; +static a52_state_t a52_state; +static uint32_t a52_flags=0; + +#include "bswap.h" + +static ad_info_t info = +{ + "AC3-liba52", + "liba52", + AFM_A52, + "Nick Kurshev", + "Michel LESPINASSE", + "" +}; + +LIBAD_EXTERN(liba52) + +extern int audio_output_channels; + +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; +} + + +static int preinit(sh_audio_t *sh) +{ + /* Dolby AC3 audio: */ + /* however many channels, 2 bytes in a word, 256 samples in a block, 6 blocks in a frame */ + sh->audio_out_minsize=audio_output_channels*2*256*6; + sh->audio_in_minsize=3840; + return 1; +} + +static int init(sh_audio_t *sh_audio) +{ + uint32_t a52_accel=0; + 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"); + return 0; + } + if(a52_fillbuff(sh_audio)<0){ + mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n"); + return 0; + } + /* 'a52 cannot upmix' hotfix:*/ + a52_printinfo(sh_audio); + 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"); + return 0; + } + 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"); + return 0; + } + return 1; +} + +static void uninit(sh_audio_t *sh) +{ +} + +static int control(sh_audio_t *sh,int cmd,void* arg, ...) +{ + switch(cmd) + { + case ADCTRL_SKIP_FRAME: + a52_fillbuff(sh); break; // skip AC3 frame + return CONTROL_TRUE; + } + return CONTROL_UNKNOWN; +} + +static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen) +{ + sample_t level=1, bias=384; + int flags=a52_flags|A52_ADJUST_LEVEL; + int i,len=-1; + if(!sh_audio->a_in_buffer_len) + if(a52_fillbuff(sh_audio)<0) return len; /* 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"); + return len; + } + 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,(int16_t *)&buf[len]); + } + return len; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libmpcodecs/ad_libvorbis.c Fri Aug 30 19:49:37 2002 +0000 @@ -0,0 +1,189 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "config.h" +#include "ad_internal.h" + +#ifdef HAVE_OGGVORBIS + +static ad_info_t info = +{ + "Ogg/Vorbis audio decoder", + "libvorbis", + AFM_VORBIS, + "Felix Buenemann, A'rpi", + "libvorbis", + "buggy" +}; + +LIBAD_EXTERN(vorbis) + +#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; + +static int preinit(sh_audio_t *sh) +{ + sh->audio_out_minsize=1024*4; // 1024 samples/frame + return 1; +} + +static int init(sh_audio_t *sh) +{ + ogg_packet op; + vorbis_comment vc; + struct ov_struct_st *ov; +#define ERROR() { \ + vorbis_comment_clear(&vc); \ + vorbis_info_clear(&ov->vi); \ + free(ov); \ + return 0; \ + } + /// 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->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"); + ERROR(); + } + op.bytes = ds_get_packet(sh->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"); + ERROR(); + } + op.bytes = ds_get_packet(sh->ds,&op.packet); + //// Codebook + if(vorbis_synthesis_headerin(&ov->vi,&vc,&op)<0) { + mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: codebook header broken!\n"); + ERROR(); + } 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, %dHz, %dbit/s %cBR\n",(int)ov->vi.channels,(int)ov->vi.rate,(int)ov->vi.bitrate_nominal, + (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); + } + vorbis_comment_clear(&vc); + +// printf("lower=%d upper=%d \n",(int)ov->vi.bitrate_lower,(int)ov->vi.bitrate_upper); + + // Setup the decoder + sh->channels=ov->vi.channels; + sh->samplerate=ov->vi.rate; + // assume 128kbit if bitrate not specified in the header + sh->i_bps=((ov->vi.bitrate_nominal>0) ? ov->vi.bitrate_nominal : 128000)/8; + sh->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"); + + return 1; +} + +static void uninit(sh_audio_t *sh) +{ + struct ov_struct_st *ov = sh->context; + vorbis_block_clear(&ov->vb); + vorbis_info_clear(&ov->vi); + free(ov); +} + +static int control(sh_audio_t *sh,int cmd,void* arg, ...) +{ + switch(cmd) + { +#if 0 + case ADCTRL_RESYNC_STREAM: + return CONTROL_TRUE; + case ADCTRL_SKIP_FRAME: + return CONTROL_TRUE; +#endif + } + return CONTROL_UNKNOWN; +} + +static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen) +{ + int len = 0; + int samples; + float **pcm; + ogg_packet op; + struct ov_struct_st *ov = sh->context; + op.b_o_s = op.e_o_s = 0; + while(len < minlen) { + op.bytes = ds_get_packet(sh->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 */ + } + } + + + + return len; +} + +#endif /* !HAVE_OGGVORBIS */ +
--- a/libmpcodecs/ad_real.c Fri Aug 30 19:40:24 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,251 +0,0 @@ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include "config.h" - -#ifdef USE_REALCODECS - -#include <stddef.h> -#include <dlfcn.h> - -#include "ad_internal.h" - -static ad_info_t info = { - "RealAudio decoder", - "real", - AFM_REAL, - "A'rpi", - "Florian Schneider", - "binary real audio codecs" -}; - -LIBAD_EXTERN(real) - -static void *handle=NULL; - -void *__builtin_new(unsigned long size) { - return malloc(size); -} - -#if defined(__FreeBSD__) || defined(__NetBSD__) -void *__ctype_b=NULL; -#endif - -static unsigned long (*raCloseCodec)(unsigned long); -static unsigned long (*raDecode)(unsigned long,unsigned long,unsigned long,unsigned long,unsigned long,unsigned long); -static unsigned long (*raFlush)(unsigned long,unsigned long,unsigned long); -static unsigned long (*raFreeDecoder)(unsigned long); -static unsigned long (*raGetFlavorProperty)(unsigned long,unsigned long,unsigned long,unsigned long); -//static unsigned long (*raGetNumberOfFlavors2)(void); -static unsigned long (*raInitDecoder)(unsigned long,unsigned long); -static unsigned long (*raOpenCodec2)(unsigned long); -static unsigned long (*raSetFlavor)(unsigned long,unsigned long); -//static void (*raSetDLLAccessPath)(unsigned long); -static void (*raSetPwd)(char*,char*); - -typedef struct { - int samplerate; - short bits; - short channels; - int unk1; - int unk2; - int packetsize; - int unk3; - void* unk4; -} ra_init_t; - -static int preinit(sh_audio_t *sh){ - // let's check if the driver is available, return 0 if not. - // (you should do that if you use external lib(s) which is optional) - unsigned int result; - int len; - void* prop; - char path[4096]; - sprintf(path, REALCODEC_PATH "/%s", sh->codec->dll); - handle = dlopen (path, RTLD_LAZY); - if(!handle){ - mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot open dll: %s\n",dlerror()); - return 0; - } - - raCloseCodec = dlsym(handle, "RACloseCodec"); - raDecode = dlsym(handle, "RADecode"); - raFlush = dlsym(handle, "RAFlush"); - raFreeDecoder = dlsym(handle, "RAFreeDecoder"); - raGetFlavorProperty = dlsym(handle, "RAGetFlavorProperty"); - raOpenCodec2 = dlsym(handle, "RAOpenCodec2"); - raInitDecoder = dlsym(handle, "RAInitDecoder"); - raSetFlavor = dlsym(handle, "RASetFlavor"); -// raSetDLLAccessPath = dlsym(handle, "SetDLLAccessPath"); - raSetPwd = dlsym(handle, "RASetPwd"); // optional, used by SIPR - - if(!raCloseCodec || !raDecode || !raFlush || !raFreeDecoder || - !raGetFlavorProperty || !raOpenCodec2 || !raSetFlavor || - /*!raSetDLLAccessPath ||*/ !raInitDecoder){ - mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot resolve symbols - incompatible dll\n"); - return 0; - } - - result=raOpenCodec2(&sh->context); - if(result){ - mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder open failed, error code: 0x%X\n",result); - return 0; - } - - sh->samplerate=sh->wf->nSamplesPerSec; - sh->samplesize=sh->wf->wBitsPerSample/8; - sh->channels=sh->wf->nChannels; - - { unsigned char temp2[16]={1,0,0,3,4,0,0,0x14,0,0,0,0,0,1,0,3}; - // note: temp2[] come from audio stream extra header (last 16 of the total 24 bytes) - ra_init_t init_data={ - sh->wf->nSamplesPerSec,sh->wf->wBitsPerSample,sh->wf->nChannels, - 100, // ??? - ((short*)(sh->wf+1))[0], // subpacket size - sh->wf->nBlockAlign, - 16, // ?? - ((char*)(sh->wf+1))+6+8 - }; - result=raInitDecoder(sh->context,&init_data); - if(result){ - mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder init failed, error code: 0x%X\n",result); - return 0; - } - } - - if(raSetPwd){ - // used by 'SIPR' - raSetPwd(sh->context,"Ardubancel Quazanga"); // set password... lol. - } - - result=raSetFlavor(sh->context,((short*)(sh->wf+1))[2]); - if(result){ - mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder flavor setup failed, error code: 0x%X\n",result); - return 0; - } - - prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],0,&len); - mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Audio codec: [%d] %s\n",((short*)(sh->wf+1))[2],prop); - - prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],1,&len); - sh->i_bps=((*((int*)prop))+4)/8; - mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Audio bitrate: %5.3f kbit/s (%d bps) \n",(*((int*)prop))*0.001f,sh->i_bps); - -// prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],0x13,&len); -// mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Samples/block?: %d \n",(*((int*)prop))); - - sh->audio_out_minsize=128000; // no idea how to get... :( - sh->audio_in_minsize=((short*)(sh->wf+1))[1]*sh->wf->nBlockAlign; - - return 1; // return values: 1=OK 0=ERROR -} - -static int init(sh_audio_t *sh_audio){ - // initialize the decoder, set tables etc... - - // you can store HANDLE or private struct pointer at sh->context - // you can access WAVEFORMATEX header at sh->wf - - // set sample format/rate parameters if you didn't do it in preinit() yet. - - return 1; // return values: 1=OK 0=ERROR -} - -static void uninit(sh_audio_t *sh){ - // uninit the decoder etc... - // again: you don't have to free() a_in_buffer here! it's done by the core. -} - -static unsigned char sipr_swaps[38][2]={ - {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68}, - {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46}, - {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56}, - {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83}, - {77,80} }; - -static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen){ - int result; - int len=-1; - int sps=((short*)(sh->wf+1))[0]; - int w=sh->wf->nBlockAlign; // 5 - int h=((short*)(sh->wf+1))[1]; - -// printf("bs=%d sps=%d w=%d h=%d \n",sh->wf->nBlockAlign,sps,w,h); - -#if 1 - if(sh->a_in_buffer_len<=0){ - // fill the buffer! - if(!sps){ - // 'sipr' way - int j,n; - int bs=h*w*2/96; // nibbles per subpacket - unsigned char *p=sh->a_in_buffer; - demux_read_data(sh->ds, p, h*w); - for(n=0;n<38;n++){ - int i=bs*sipr_swaps[n][0]; - int o=bs*sipr_swaps[n][1]; - // swap nibbles of block 'i' with 'o' TODO: optimize - for(j=0;j<bs;j++){ - int x=(i&1) ? (p[(i>>1)]>>4) : (p[(i>>1)]&15); - int y=(o&1) ? (p[(o>>1)]>>4) : (p[(o>>1)]&15); - if(o&1) p[(o>>1)]=(p[(o>>1)]&0x0F)|(x<<4); - else p[(o>>1)]=(p[(o>>1)]&0xF0)|x; - if(i&1) p[(i>>1)]=(p[(i>>1)]&0x0F)|(y<<4); - else p[(i>>1)]=(p[(i>>1)]&0xF0)|y; - ++i;++o; - } - } - sh->a_in_buffer_size= - sh->a_in_buffer_len=w*h; - } else { - // 'cook' way - int x,y; - w/=sps; - for(y=0;y<h;y++) - for(x=0;x<w;x++){ - demux_read_data(sh->ds, sh->a_in_buffer+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps); - } - sh->a_in_buffer_size= - sh->a_in_buffer_len=w*h*sps; - } - } - -#else - if(sh->a_in_buffer_len<=0){ - // fill the buffer! - demux_read_data(sh->ds, sh->a_in_buffer, sh->wf->nBlockAlign); - sh->a_in_buffer_size= - sh->a_in_buffer_len=sh->wf->nBlockAlign; - } -#endif - - result=raDecode(sh->context, sh->a_in_buffer+sh->a_in_buffer_size-sh->a_in_buffer_len, sh->wf->nBlockAlign, - buf, &len, -1); - sh->a_in_buffer_len-=sh->wf->nBlockAlign; - -// printf("radecode: %d bytes, res=0x%X \n",len,result); - - return len; // return value: number of _bytes_ written to output buffer, - // or -1 for EOF (or uncorrectable error) -} - -static int control(sh_audio_t *sh,int cmd,void* arg, ...){ - // various optional functions you MAY implement: - switch(cmd){ - case ADCTRL_RESYNC_STREAM: - // it is called once after seeking, to resync. - // Note: sh_audio->a_in_buffer_len=0; is done _before_ this call! - return CONTROL_TRUE; - case ADCTRL_SKIP_FRAME: - // it is called to skip (jump over) small amount (1/10 sec or 1 frame) - // of audio data - used to sync audio to video after seeking - // if you don't return CONTROL_TRUE, it will defaults to: - // ds_fill_buffer(sh_audio->ds); // skip 1 demux packet - return CONTROL_TRUE; - } - return CONTROL_UNKNOWN; -} - -#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libmpcodecs/ad_realaud.c Fri Aug 30 19:49:37 2002 +0000 @@ -0,0 +1,251 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "config.h" + +#ifdef USE_REALCODECS + +#include <stddef.h> +#include <dlfcn.h> + +#include "ad_internal.h" + +static ad_info_t info = { + "RealAudio decoder", + "real", + AFM_REAL, + "A'rpi", + "Florian Schneider", + "binary real audio codecs" +}; + +LIBAD_EXTERN(real) + +static void *handle=NULL; + +void *__builtin_new(unsigned long size) { + return malloc(size); +} + +#if defined(__FreeBSD__) || defined(__NetBSD__) +void *__ctype_b=NULL; +#endif + +static unsigned long (*raCloseCodec)(unsigned long); +static unsigned long (*raDecode)(unsigned long,unsigned long,unsigned long,unsigned long,unsigned long,unsigned long); +static unsigned long (*raFlush)(unsigned long,unsigned long,unsigned long); +static unsigned long (*raFreeDecoder)(unsigned long); +static unsigned long (*raGetFlavorProperty)(unsigned long,unsigned long,unsigned long,unsigned long); +//static unsigned long (*raGetNumberOfFlavors2)(void); +static unsigned long (*raInitDecoder)(unsigned long,unsigned long); +static unsigned long (*raOpenCodec2)(unsigned long); +static unsigned long (*raSetFlavor)(unsigned long,unsigned long); +//static void (*raSetDLLAccessPath)(unsigned long); +static void (*raSetPwd)(char*,char*); + +typedef struct { + int samplerate; + short bits; + short channels; + int unk1; + int unk2; + int packetsize; + int unk3; + void* unk4; +} ra_init_t; + +static int preinit(sh_audio_t *sh){ + // let's check if the driver is available, return 0 if not. + // (you should do that if you use external lib(s) which is optional) + unsigned int result; + int len; + void* prop; + char path[4096]; + sprintf(path, REALCODEC_PATH "/%s", sh->codec->dll); + handle = dlopen (path, RTLD_LAZY); + if(!handle){ + mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot open dll: %s\n",dlerror()); + return 0; + } + + raCloseCodec = dlsym(handle, "RACloseCodec"); + raDecode = dlsym(handle, "RADecode"); + raFlush = dlsym(handle, "RAFlush"); + raFreeDecoder = dlsym(handle, "RAFreeDecoder"); + raGetFlavorProperty = dlsym(handle, "RAGetFlavorProperty"); + raOpenCodec2 = dlsym(handle, "RAOpenCodec2"); + raInitDecoder = dlsym(handle, "RAInitDecoder"); + raSetFlavor = dlsym(handle, "RASetFlavor"); +// raSetDLLAccessPath = dlsym(handle, "SetDLLAccessPath"); + raSetPwd = dlsym(handle, "RASetPwd"); // optional, used by SIPR + + if(!raCloseCodec || !raDecode || !raFlush || !raFreeDecoder || + !raGetFlavorProperty || !raOpenCodec2 || !raSetFlavor || + /*!raSetDLLAccessPath ||*/ !raInitDecoder){ + mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot resolve symbols - incompatible dll\n"); + return 0; + } + + result=raOpenCodec2(&sh->context); + if(result){ + mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder open failed, error code: 0x%X\n",result); + return 0; + } + + sh->samplerate=sh->wf->nSamplesPerSec; + sh->samplesize=sh->wf->wBitsPerSample/8; + sh->channels=sh->wf->nChannels; + + { unsigned char temp2[16]={1,0,0,3,4,0,0,0x14,0,0,0,0,0,1,0,3}; + // note: temp2[] come from audio stream extra header (last 16 of the total 24 bytes) + ra_init_t init_data={ + sh->wf->nSamplesPerSec,sh->wf->wBitsPerSample,sh->wf->nChannels, + 100, // ??? + ((short*)(sh->wf+1))[0], // subpacket size + sh->wf->nBlockAlign, + 16, // ?? + ((char*)(sh->wf+1))+6+8 + }; + result=raInitDecoder(sh->context,&init_data); + if(result){ + mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder init failed, error code: 0x%X\n",result); + return 0; + } + } + + if(raSetPwd){ + // used by 'SIPR' + raSetPwd(sh->context,"Ardubancel Quazanga"); // set password... lol. + } + + result=raSetFlavor(sh->context,((short*)(sh->wf+1))[2]); + if(result){ + mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder flavor setup failed, error code: 0x%X\n",result); + return 0; + } + + prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],0,&len); + mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Audio codec: [%d] %s\n",((short*)(sh->wf+1))[2],prop); + + prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],1,&len); + sh->i_bps=((*((int*)prop))+4)/8; + mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Audio bitrate: %5.3f kbit/s (%d bps) \n",(*((int*)prop))*0.001f,sh->i_bps); + +// prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],0x13,&len); +// mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Samples/block?: %d \n",(*((int*)prop))); + + sh->audio_out_minsize=128000; // no idea how to get... :( + sh->audio_in_minsize=((short*)(sh->wf+1))[1]*sh->wf->nBlockAlign; + + return 1; // return values: 1=OK 0=ERROR +} + +static int init(sh_audio_t *sh_audio){ + // initialize the decoder, set tables etc... + + // you can store HANDLE or private struct pointer at sh->context + // you can access WAVEFORMATEX header at sh->wf + + // set sample format/rate parameters if you didn't do it in preinit() yet. + + return 1; // return values: 1=OK 0=ERROR +} + +static void uninit(sh_audio_t *sh){ + // uninit the decoder etc... + // again: you don't have to free() a_in_buffer here! it's done by the core. +} + +static unsigned char sipr_swaps[38][2]={ + {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68}, + {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46}, + {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56}, + {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83}, + {77,80} }; + +static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen){ + int result; + int len=-1; + int sps=((short*)(sh->wf+1))[0]; + int w=sh->wf->nBlockAlign; // 5 + int h=((short*)(sh->wf+1))[1]; + +// printf("bs=%d sps=%d w=%d h=%d \n",sh->wf->nBlockAlign,sps,w,h); + +#if 1 + if(sh->a_in_buffer_len<=0){ + // fill the buffer! + if(!sps){ + // 'sipr' way + int j,n; + int bs=h*w*2/96; // nibbles per subpacket + unsigned char *p=sh->a_in_buffer; + demux_read_data(sh->ds, p, h*w); + for(n=0;n<38;n++){ + int i=bs*sipr_swaps[n][0]; + int o=bs*sipr_swaps[n][1]; + // swap nibbles of block 'i' with 'o' TODO: optimize + for(j=0;j<bs;j++){ + int x=(i&1) ? (p[(i>>1)]>>4) : (p[(i>>1)]&15); + int y=(o&1) ? (p[(o>>1)]>>4) : (p[(o>>1)]&15); + if(o&1) p[(o>>1)]=(p[(o>>1)]&0x0F)|(x<<4); + else p[(o>>1)]=(p[(o>>1)]&0xF0)|x; + if(i&1) p[(i>>1)]=(p[(i>>1)]&0x0F)|(y<<4); + else p[(i>>1)]=(p[(i>>1)]&0xF0)|y; + ++i;++o; + } + } + sh->a_in_buffer_size= + sh->a_in_buffer_len=w*h; + } else { + // 'cook' way + int x,y; + w/=sps; + for(y=0;y<h;y++) + for(x=0;x<w;x++){ + demux_read_data(sh->ds, sh->a_in_buffer+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps); + } + sh->a_in_buffer_size= + sh->a_in_buffer_len=w*h*sps; + } + } + +#else + if(sh->a_in_buffer_len<=0){ + // fill the buffer! + demux_read_data(sh->ds, sh->a_in_buffer, sh->wf->nBlockAlign); + sh->a_in_buffer_size= + sh->a_in_buffer_len=sh->wf->nBlockAlign; + } +#endif + + result=raDecode(sh->context, sh->a_in_buffer+sh->a_in_buffer_size-sh->a_in_buffer_len, sh->wf->nBlockAlign, + buf, &len, -1); + sh->a_in_buffer_len-=sh->wf->nBlockAlign; + +// printf("radecode: %d bytes, res=0x%X \n",len,result); + + return len; // return value: number of _bytes_ written to output buffer, + // or -1 for EOF (or uncorrectable error) +} + +static int control(sh_audio_t *sh,int cmd,void* arg, ...){ + // various optional functions you MAY implement: + switch(cmd){ + case ADCTRL_RESYNC_STREAM: + // it is called once after seeking, to resync. + // Note: sh_audio->a_in_buffer_len=0; is done _before_ this call! + return CONTROL_TRUE; + case ADCTRL_SKIP_FRAME: + // it is called to skip (jump over) small amount (1/10 sec or 1 frame) + // of audio data - used to sync audio to video after seeking + // if you don't return CONTROL_TRUE, it will defaults to: + // ds_fill_buffer(sh_audio->ds); // skip 1 demux packet + return CONTROL_TRUE; + } + return CONTROL_UNKNOWN; +} + +#endif
--- a/libmpcodecs/ad_vorbis.c Fri Aug 30 19:40:24 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,189 +0,0 @@ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include "config.h" -#include "ad_internal.h" - -#ifdef HAVE_OGGVORBIS - -static ad_info_t info = -{ - "Ogg/Vorbis audio decoder", - "libvorbis", - AFM_VORBIS, - "Felix Buenemann, A'rpi", - "libvorbis", - "buggy" -}; - -LIBAD_EXTERN(vorbis) - -#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; - -static int preinit(sh_audio_t *sh) -{ - sh->audio_out_minsize=1024*4; // 1024 samples/frame - return 1; -} - -static int init(sh_audio_t *sh) -{ - ogg_packet op; - vorbis_comment vc; - struct ov_struct_st *ov; -#define ERROR() { \ - vorbis_comment_clear(&vc); \ - vorbis_info_clear(&ov->vi); \ - free(ov); \ - return 0; \ - } - /// 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->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"); - ERROR(); - } - op.bytes = ds_get_packet(sh->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"); - ERROR(); - } - op.bytes = ds_get_packet(sh->ds,&op.packet); - //// Codebook - if(vorbis_synthesis_headerin(&ov->vi,&vc,&op)<0) { - mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: codebook header broken!\n"); - ERROR(); - } 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, %dHz, %dbit/s %cBR\n",(int)ov->vi.channels,(int)ov->vi.rate,(int)ov->vi.bitrate_nominal, - (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); - } - vorbis_comment_clear(&vc); - -// printf("lower=%d upper=%d \n",(int)ov->vi.bitrate_lower,(int)ov->vi.bitrate_upper); - - // Setup the decoder - sh->channels=ov->vi.channels; - sh->samplerate=ov->vi.rate; - // assume 128kbit if bitrate not specified in the header - sh->i_bps=((ov->vi.bitrate_nominal>0) ? ov->vi.bitrate_nominal : 128000)/8; - sh->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"); - - return 1; -} - -static void uninit(sh_audio_t *sh) -{ - struct ov_struct_st *ov = sh->context; - vorbis_block_clear(&ov->vb); - vorbis_info_clear(&ov->vi); - free(ov); -} - -static int control(sh_audio_t *sh,int cmd,void* arg, ...) -{ - switch(cmd) - { -#if 0 - case ADCTRL_RESYNC_STREAM: - return CONTROL_TRUE; - case ADCTRL_SKIP_FRAME: - return CONTROL_TRUE; -#endif - } - return CONTROL_UNKNOWN; -} - -static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen) -{ - int len = 0; - int samples; - float **pcm; - ogg_packet op; - struct ov_struct_st *ov = sh->context; - op.b_o_s = op.e_o_s = 0; - while(len < minlen) { - op.bytes = ds_get_packet(sh->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 */ - } - } - - - - return len; -} - -#endif /* !HAVE_OGGVORBIS */ -
--- a/libmpcodecs/vd_real.c Fri Aug 30 19:40:24 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,224 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#include "config.h" -#ifdef USE_REALCODECS - -#include <dlfcn.h> - -#include "mp_msg.h" -#include "help_mp.h" - -#include "vd_internal.h" - -static vd_info_t info = { - "RealVideo decoder", - "real", - VFM_REAL, - "Florian Schneider & A'rpi", - "using original closed source codecs for Linux", - "binary real video codecs" -}; - -LIBVD_EXTERN(real) - - -unsigned long (*rvyuv_custom_message)(unsigned long,unsigned long); -unsigned long (*rvyuv_free)(unsigned long); -unsigned long (*rvyuv_hive_message)(unsigned long,unsigned long); -unsigned long (*rvyuv_init)(unsigned long,unsigned long); -unsigned long (*rvyuv_transform)(unsigned long,unsigned long,unsigned long,unsigned long,unsigned long); - -void *rv_handle=NULL; - -void *__builtin_vec_new(unsigned long size) { - return malloc(size); -} - -void __builtin_vec_delete(void *mem) { - free(mem); -} - -void __pure_virtual(void) { - printf("FATAL: __pure_virtual() called!\n"); -// exit(1); -} - -#if defined(__FreeBSD__) || defined(__NetBSD__) -void ___brk_addr(void) {exit(0);} -char **__environ={NULL}; -#undef stderr -FILE *stderr=NULL; -#endif - -// to set/get/query special features/parameters -static int control(sh_video_t *sh,int cmd,void* arg,...){ -// switch(cmd){ -// case VDCTRL_QUERY_MAX_PP_LEVEL: -// return 9; -// case VDCTRL_SET_PP_LEVEL: -// vfw_set_postproc(sh,10*(*((int*)arg))); -// return CONTROL_OK; -// } - return CONTROL_UNKNOWN; -} - -/* exits program when failure */ -int load_syms_linux(char *path) { - void *handle; - char *error; - - mp_msg(MSGT_DECVIDEO,MSGL_INFO, "opening shared obj '%s'\n", path); - rv_handle = dlopen (path, RTLD_LAZY); - handle=rv_handle; - if (!handle) { - mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error: %s\n",dlerror()); - return 0; - } - - rvyuv_custom_message = dlsym(handle, "RV20toYUV420CustomMessage"); - rvyuv_free = dlsym(handle, "RV20toYUV420Free"); - rvyuv_hive_message = dlsym(handle, "RV20toYUV420HiveMessage"); - rvyuv_init = dlsym(handle, "RV20toYUV420Init"); - rvyuv_transform = dlsym(handle, "RV20toYUV420Transform"); - - if(rvyuv_custom_message && - rvyuv_free && - rvyuv_hive_message && - rvyuv_init && - rvyuv_transform) return 1; - - mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error resolving symbols! (version incompatibility?)\n"); - return 0; -} - -#ifdef USE_WIN32DLL - -#include "../loader/ldt_keeper.h" -void* LoadLibraryA(char* name); -void* GetProcAddress(void* handle,char* func); - -int load_syms_windows(char *path) { - void *handle; - Setup_LDT_Keeper(); - rv_handle = handle = LoadLibraryA(path); - mp_msg(MSGT_DECVIDEO,MSGL_V,"win32 real codec handle=%p \n",handle); - - rvyuv_custom_message = GetProcAddress(handle, "RV20toYUV420CustomMessage"); - rvyuv_free = GetProcAddress(handle, "RV20toYUV420Free"); - rvyuv_hive_message = GetProcAddress(handle, "RV20toYUV420HiveMessage"); - rvyuv_init = GetProcAddress(handle, "RV20toYUV420Init"); - rvyuv_transform = GetProcAddress(handle, "RV20toYUV420Transform"); - - if(rvyuv_custom_message && - rvyuv_free && - rvyuv_hive_message && - rvyuv_init && - rvyuv_transform) return 1; - return 0; // error -} -#endif - -/* we need exact positions */ -struct rv_init_t { - short unk1; - short w; - short h; - short unk3; - int unk2; - int subformat; - int unk5; - int format; -} rv_init_t; - -// init driver -static int init(sh_video_t *sh){ - //unsigned int out_fmt; - char path[4096]; - int result; - // we export codec id and sub-id from demuxer in bitmapinfohdr: - unsigned int* extrahdr=(unsigned int*)(sh->bih+1); - struct rv_init_t init_data={ - 11, sh->disp_w, sh->disp_h,0,0,extrahdr[0], - 1,extrahdr[1]}; // rv30 - - mp_msg(MSGT_DECVIDEO,MSGL_V,"realvideo codec id: 0x%08X sub-id: 0x%08X\n",extrahdr[1],extrahdr[0]); - - sprintf(path, REALCODEC_PATH "/%s", sh->codec->dll); - - /* first try to load linux dlls, if failed and we're supporting win32 dlls, - then try to load the windows ones */ - if(!load_syms_linux(path)) -#ifdef USE_WIN32DLL - if (!load_syms_windows(path)) -#endif - { - mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh->codec->dll); - mp_msg(MSGT_DECVIDEO,MSGL_HINT,"You need to copy the contents from the RealPlayer codecs directory\n"); - mp_msg(MSGT_DECVIDEO,MSGL_HINT,"into " REALCODEC_PATH "/ !\n"); - return 0; - } - // only I420 supported - if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_I420)) return 0; - // init codec: - sh->context=NULL; - result=(*rvyuv_init)(&init_data, &sh->context); - if (result){ - mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Couldn't open RealVideo codec, error code: 0x%X \n",result); - return 0; - } - // setup rv30 codec (codec sub-type and image dimensions): - if(extrahdr[1]>=0x20200002){ - unsigned long cmsg24[4]={sh->disp_w,sh->disp_h,sh->disp_w,sh->disp_h}; - unsigned long cmsg_data[3]={0x24,1+((extrahdr[0]>>16)&7),&cmsg24}; - (*rvyuv_custom_message)(cmsg_data,sh->context); - } - mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: RealVideo codec init OK!\n"); - return 1; -} - -// uninit driver -static void uninit(sh_video_t *sh){ - if(rv_handle) dlclose(rv_handle); - rv_handle=NULL; -} - -// copypaste from demux_real.c - it should match to get it working! -typedef struct dp_hdr_s { - uint32_t chunks; // number of chunks - uint32_t timestamp; // timestamp from packet header - uint32_t len; // length of actual data - uint32_t chunktab; // offset to chunk offset array -} dp_hdr_t; - -// decode a frame -static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ - mp_image_t* mpi; - unsigned long result; - dp_hdr_t* dp_hdr=(dp_hdr_t*)data; - unsigned char* dp_data=((unsigned char*)data)+sizeof(dp_hdr_t); - uint32_t* extra=(uint32_t*)(((char*)data)+dp_hdr->chunktab); - - unsigned long transform_out[5]; - unsigned long transform_in[6]={ - dp_hdr->len, // length of the packet (sub-packets appended) - 0, // unknown, seems to be unused - dp_hdr->chunks, // number of sub-packets - 1 - extra, // table of sub-packet offsets - 0, // unknown, seems to be unused - dp_hdr->timestamp,// timestamp (the integer value from the stream) - }; - - if(len<=0 || flags&2) return NULL; // skipped frame || hardframedrop - - mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0 /*MP_IMGFLAG_ACCEPT_STRIDE*/, - sh->disp_w, sh->disp_h); - if(!mpi) return NULL; - - result=(*rvyuv_transform)(dp_data, mpi->planes[0], transform_in, - transform_out, sh->context); - - return (result?NULL:mpi); -} - -#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libmpcodecs/vd_realvid.c Fri Aug 30 19:49:37 2002 +0000 @@ -0,0 +1,224 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "config.h" +#ifdef USE_REALCODECS + +#include <dlfcn.h> + +#include "mp_msg.h" +#include "help_mp.h" + +#include "vd_internal.h" + +static vd_info_t info = { + "RealVideo decoder", + "real", + VFM_REAL, + "Florian Schneider & A'rpi", + "using original closed source codecs for Linux", + "binary real video codecs" +}; + +LIBVD_EXTERN(real) + + +unsigned long (*rvyuv_custom_message)(unsigned long,unsigned long); +unsigned long (*rvyuv_free)(unsigned long); +unsigned long (*rvyuv_hive_message)(unsigned long,unsigned long); +unsigned long (*rvyuv_init)(unsigned long,unsigned long); +unsigned long (*rvyuv_transform)(unsigned long,unsigned long,unsigned long,unsigned long,unsigned long); + +void *rv_handle=NULL; + +void *__builtin_vec_new(unsigned long size) { + return malloc(size); +} + +void __builtin_vec_delete(void *mem) { + free(mem); +} + +void __pure_virtual(void) { + printf("FATAL: __pure_virtual() called!\n"); +// exit(1); +} + +#if defined(__FreeBSD__) || defined(__NetBSD__) +void ___brk_addr(void) {exit(0);} +char **__environ={NULL}; +#undef stderr +FILE *stderr=NULL; +#endif + +// to set/get/query special features/parameters +static int control(sh_video_t *sh,int cmd,void* arg,...){ +// switch(cmd){ +// case VDCTRL_QUERY_MAX_PP_LEVEL: +// return 9; +// case VDCTRL_SET_PP_LEVEL: +// vfw_set_postproc(sh,10*(*((int*)arg))); +// return CONTROL_OK; +// } + return CONTROL_UNKNOWN; +} + +/* exits program when failure */ +int load_syms_linux(char *path) { + void *handle; + char *error; + + mp_msg(MSGT_DECVIDEO,MSGL_INFO, "opening shared obj '%s'\n", path); + rv_handle = dlopen (path, RTLD_LAZY); + handle=rv_handle; + if (!handle) { + mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error: %s\n",dlerror()); + return 0; + } + + rvyuv_custom_message = dlsym(handle, "RV20toYUV420CustomMessage"); + rvyuv_free = dlsym(handle, "RV20toYUV420Free"); + rvyuv_hive_message = dlsym(handle, "RV20toYUV420HiveMessage"); + rvyuv_init = dlsym(handle, "RV20toYUV420Init"); + rvyuv_transform = dlsym(handle, "RV20toYUV420Transform"); + + if(rvyuv_custom_message && + rvyuv_free && + rvyuv_hive_message && + rvyuv_init && + rvyuv_transform) return 1; + + mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error resolving symbols! (version incompatibility?)\n"); + return 0; +} + +#ifdef USE_WIN32DLL + +#include "../loader/ldt_keeper.h" +void* LoadLibraryA(char* name); +void* GetProcAddress(void* handle,char* func); + +int load_syms_windows(char *path) { + void *handle; + Setup_LDT_Keeper(); + rv_handle = handle = LoadLibraryA(path); + mp_msg(MSGT_DECVIDEO,MSGL_V,"win32 real codec handle=%p \n",handle); + + rvyuv_custom_message = GetProcAddress(handle, "RV20toYUV420CustomMessage"); + rvyuv_free = GetProcAddress(handle, "RV20toYUV420Free"); + rvyuv_hive_message = GetProcAddress(handle, "RV20toYUV420HiveMessage"); + rvyuv_init = GetProcAddress(handle, "RV20toYUV420Init"); + rvyuv_transform = GetProcAddress(handle, "RV20toYUV420Transform"); + + if(rvyuv_custom_message && + rvyuv_free && + rvyuv_hive_message && + rvyuv_init && + rvyuv_transform) return 1; + return 0; // error +} +#endif + +/* we need exact positions */ +struct rv_init_t { + short unk1; + short w; + short h; + short unk3; + int unk2; + int subformat; + int unk5; + int format; +} rv_init_t; + +// init driver +static int init(sh_video_t *sh){ + //unsigned int out_fmt; + char path[4096]; + int result; + // we export codec id and sub-id from demuxer in bitmapinfohdr: + unsigned int* extrahdr=(unsigned int*)(sh->bih+1); + struct rv_init_t init_data={ + 11, sh->disp_w, sh->disp_h,0,0,extrahdr[0], + 1,extrahdr[1]}; // rv30 + + mp_msg(MSGT_DECVIDEO,MSGL_V,"realvideo codec id: 0x%08X sub-id: 0x%08X\n",extrahdr[1],extrahdr[0]); + + sprintf(path, REALCODEC_PATH "/%s", sh->codec->dll); + + /* first try to load linux dlls, if failed and we're supporting win32 dlls, + then try to load the windows ones */ + if(!load_syms_linux(path)) +#ifdef USE_WIN32DLL + if (!load_syms_windows(path)) +#endif + { + mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh->codec->dll); + mp_msg(MSGT_DECVIDEO,MSGL_HINT,"You need to copy the contents from the RealPlayer codecs directory\n"); + mp_msg(MSGT_DECVIDEO,MSGL_HINT,"into " REALCODEC_PATH "/ !\n"); + return 0; + } + // only I420 supported + if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_I420)) return 0; + // init codec: + sh->context=NULL; + result=(*rvyuv_init)(&init_data, &sh->context); + if (result){ + mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Couldn't open RealVideo codec, error code: 0x%X \n",result); + return 0; + } + // setup rv30 codec (codec sub-type and image dimensions): + if(extrahdr[1]>=0x20200002){ + unsigned long cmsg24[4]={sh->disp_w,sh->disp_h,sh->disp_w,sh->disp_h}; + unsigned long cmsg_data[3]={0x24,1+((extrahdr[0]>>16)&7),&cmsg24}; + (*rvyuv_custom_message)(cmsg_data,sh->context); + } + mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: RealVideo codec init OK!\n"); + return 1; +} + +// uninit driver +static void uninit(sh_video_t *sh){ + if(rv_handle) dlclose(rv_handle); + rv_handle=NULL; +} + +// copypaste from demux_real.c - it should match to get it working! +typedef struct dp_hdr_s { + uint32_t chunks; // number of chunks + uint32_t timestamp; // timestamp from packet header + uint32_t len; // length of actual data + uint32_t chunktab; // offset to chunk offset array +} dp_hdr_t; + +// decode a frame +static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ + mp_image_t* mpi; + unsigned long result; + dp_hdr_t* dp_hdr=(dp_hdr_t*)data; + unsigned char* dp_data=((unsigned char*)data)+sizeof(dp_hdr_t); + uint32_t* extra=(uint32_t*)(((char*)data)+dp_hdr->chunktab); + + unsigned long transform_out[5]; + unsigned long transform_in[6]={ + dp_hdr->len, // length of the packet (sub-packets appended) + 0, // unknown, seems to be unused + dp_hdr->chunks, // number of sub-packets - 1 + extra, // table of sub-packet offsets + 0, // unknown, seems to be unused + dp_hdr->timestamp,// timestamp (the integer value from the stream) + }; + + if(len<=0 || flags&2) return NULL; // skipped frame || hardframedrop + + mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0 /*MP_IMGFLAG_ACCEPT_STRIDE*/, + sh->disp_w, sh->disp_h); + if(!mpi) return NULL; + + result=(*rvyuv_transform)(dp_data, mpi->planes[0], transform_in, + transform_out, sh->context); + + return (result?NULL:mpi); +} + +#endif