From 63b5875bb5741b85042057b1d86f8d528171668b Mon Sep 17 00:00:00 2001 From: albeu Date: Sun, 21 Jul 2002 14:36:33 +0000 Subject: [PATCH] Fix vbr muxing and win32 codec crash on init git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@6764 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/demux_audio.c | 16 +++++++++++++--- libmpdemux/mp3_hdr.c | 4 +++- libmpdemux/mp3_hdr.h | 4 +++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/libmpdemux/demux_audio.c b/libmpdemux/demux_audio.c index 442df9f915..64dc64ffba 100644 --- a/libmpdemux/demux_audio.c +++ b/libmpdemux/demux_audio.c @@ -8,6 +8,7 @@ #include "demuxer.h" #include "stheader.h" #include "genres.h" +#include "mp3_hdr.h" #include #ifdef MP_DEBUG @@ -25,7 +26,6 @@ typedef struct da_priv { float last_pts; } da_priv_t; -extern int mp_decode_mp3_header(unsigned char* hbuf); extern void free_sh_audio(sh_audio_t* sh); extern void resync_audio_stream(sh_audio_t *sh_audio); @@ -35,7 +35,7 @@ int demux_audio_open(demuxer_t* demuxer) { stream_t *s; sh_audio_t* sh_audio; uint8_t hdr[HDR_SIZE]; - int st_pos = 0,frmt = 0, n = 0, pos = 0, step; + int st_pos = 0,frmt = 0, n = 0, pos = 0, step, mp3_freq,mp3_chans; da_priv_t* priv; #ifdef MP_DEBUG assert(demuxer != NULL); @@ -68,7 +68,7 @@ int demux_audio_open(demuxer_t* demuxer) { } else if( hdr[0] == 'f' && hdr[1] == 'm' && hdr[2] == 't' && hdr[3] == ' ' ) { frmt = WAV; break; - } else if((n = mp_decode_mp3_header(hdr)) > 0) { + } else if((n = mp_get_mp3_header(hdr,&mp3_chans,&mp3_freq)) > 0) { frmt = MP3; break; } @@ -87,6 +87,16 @@ int demux_audio_open(demuxer_t* demuxer) { case MP3: sh_audio->format = 0x55; demuxer->movi_start = st_pos-HDR_SIZE+n; + sh_audio->audio.dwSampleSize= 0; + sh_audio->audio.dwScale = 1152; + sh_audio->audio.dwRate = mp3_freq; + sh_audio->wf = malloc(sizeof(WAVEFORMATEX)); + sh_audio->wf->wFormatTag = sh_audio->format; + sh_audio->wf->nChannels = mp3_chans; + sh_audio->wf->nSamplesPerSec = mp3_freq; + sh_audio->wf->nBlockAlign = 1; + sh_audio->wf->wBitsPerSample = 16; + sh_audio->wf->cbSize = 0; for(n = 0; n < 5 ; n++) { pos = mp_decode_mp3_header(hdr); if(pos < 0) diff --git a/libmpdemux/mp3_hdr.c b/libmpdemux/mp3_hdr.c index 78ed2fc0a1..fd0b1537f6 100644 --- a/libmpdemux/mp3_hdr.c +++ b/libmpdemux/mp3_hdr.c @@ -31,7 +31,7 @@ int mp_mp3_get_lsf(unsigned char* hbuf){ /* * return frame size or -1 (bad frame) */ -int mp_decode_mp3_header(unsigned char* hbuf){ +int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* srate){ int stereo,ssize,crc,lsf,mpeg25,framesize,padding,bitrate_index,sampling_frequency; unsigned long newhead = hbuf[0] << 24 | @@ -101,6 +101,8 @@ int mp_decode_mp3_header(unsigned char* hbuf){ framesize += padding; // if(framesize<=0 || framesize>MAXFRAMESIZE) return FALSE; + if(srate) *srate = freqs[sampling_frequency]; + if(chans) *chans = stereo; return framesize; } diff --git a/libmpdemux/mp3_hdr.h b/libmpdemux/mp3_hdr.h index 9635760a95..2dfa484e10 100644 --- a/libmpdemux/mp3_hdr.h +++ b/libmpdemux/mp3_hdr.h @@ -1,5 +1,7 @@ -int mp_decode_mp3_header(unsigned char* hbuf); +int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* freq); + +#define mp_decode_mp3_header(hbuf) mp_get_mp3_header(hbuf,NULL,NULL) static inline int mp_check_mp3_header(unsigned int head){ if( (head & 0x0000e0ff) != 0x0000e0ff ||