Print a warning if ao_pcm wrote more data than what can be specified in the

WAV header (ca. 2GB currently) or if it can not update the header at all.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@29035 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2009-03-22 14:23:07 +00:00
parent 9dea062bcc
commit 412cddeb2c
1 changed files with 11 additions and 5 deletions

View File

@ -77,6 +77,7 @@ struct WaveHeader
/* init with default values */ /* init with default values */
static struct WaveHeader wavhdr; static struct WaveHeader wavhdr;
uint64_t data_length;
static FILE *fp = NULL; static FILE *fp = NULL;
@ -162,7 +163,6 @@ static int init(int rate,int channels,int format,int flags){
if(fp) { if(fp) {
if(ao_pcm_waveheader){ /* Reserve space for wave header */ if(ao_pcm_waveheader){ /* Reserve space for wave header */
fwrite(&wavhdr,sizeof(wavhdr),1,fp); fwrite(&wavhdr,sizeof(wavhdr),1,fp);
wavhdr.file_length=wavhdr.data_length=0;
} }
return 1; return 1;
} }
@ -174,12 +174,18 @@ static int init(int rate,int channels,int format,int flags){
// close audio device // close audio device
static void uninit(int immed){ static void uninit(int immed){
if(ao_pcm_waveheader && fseek(fp, 0, SEEK_SET) == 0){ /* Write wave header */ if(ao_pcm_waveheader){ /* Rewrite wave header */
wavhdr.file_length = wavhdr.data_length + sizeof(wavhdr) - 8; if (fseek(fp, 0, SEEK_SET) != 0)
mp_msg(MSGT_AO, MSGL_ERR, "Could not seek to start, WAV size headers not updated!\n");
else if (data_length > 0x7ffff000)
mp_msg(MSGT_AO, MSGL_ERR, "File larger than allowed for WAV files, may play truncated!\n");
else {
wavhdr.file_length = data_length + sizeof(wavhdr) - 8;
wavhdr.file_length = le2me_32(wavhdr.file_length); wavhdr.file_length = le2me_32(wavhdr.file_length);
wavhdr.data_length = le2me_32(wavhdr.data_length); wavhdr.data_length = le2me_32(data_length);
fwrite(&wavhdr,sizeof(wavhdr),1,fp); fwrite(&wavhdr,sizeof(wavhdr),1,fp);
} }
}
fclose(fp); fclose(fp);
if (ao_outputfilename) if (ao_outputfilename)
free(ao_outputfilename); free(ao_outputfilename);
@ -241,7 +247,7 @@ static int play(void* data,int len,int flags){
fwrite(data,len,1,fp); fwrite(data,len,1,fp);
if(ao_pcm_waveheader) if(ao_pcm_waveheader)
wavhdr.data_length += len; data_length += len;
return len; return len;
} }