summaryrefslogtreecommitdiffstats
path: root/dec_audio.c
diff options
context:
space:
mode:
authorarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-09-02 17:21:52 +0000
committerarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-09-02 17:21:52 +0000
commit96e19cb3a2f7dec0d487d29fda9d430cad1658a4 (patch)
treec48978102f11133c27697025ed5b66220acc65d9 /dec_audio.c
parenta62f04fbe3e39260faa9bb52bbdc3b75a8d2c46e (diff)
downloadmpv-96e19cb3a2f7dec0d487d29fda9d430cad1658a4.tar.bz2
mpv-96e19cb3a2f7dec0d487d29fda9d430cad1658a4.tar.xz
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@1838 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'dec_audio.c')
-rw-r--r--dec_audio.c68
1 files changed, 39 insertions, 29 deletions
diff --git a/dec_audio.c b/dec_audio.c
index 8015986c18..5851398eb5 100644
--- a/dec_audio.c
+++ b/dec_audio.c
@@ -137,7 +137,7 @@ case AFM_VORBIS:
driver=0;
#else
/* OggVorbis audio via libvorbis, compatible with files created by nandub and zorannt codec */
- sh_audio->audio_out_minsize=4096;
+ sh_audio->audio_out_minsize=1024*4; // 1024 samples/frame
#endif
break;
case AFM_PCM:
@@ -335,9 +335,9 @@ case AFM_VORBIS: {
vorbis_info_init(&sh_audio->ov->vi);
vorbis_comment_init(&sh_audio->ov->vc);
- printf("OggVorbis: cbsize: %i\n", sh_audio->wf->cbSize);
+ mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"OggVorbis: cbsize: %i\n", sh_audio->wf->cbSize);
memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX), 3*sizeof(uint32_t));
- printf("OggVorbis: Read header sizes: initial: %i comment: %i codebook: %i\n", hdrsizes[0], hdrsizes[1], hdrsizes[2]);
+ mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"OggVorbis: Read header sizes: initial: %i comment: %i codebook: %i\n", hdrsizes[0], hdrsizes[1], hdrsizes[2]);
/*for(i=12; i <= 40; i+=2) { // header bruteforce :)
memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+i, 3*sizeof(uint32_t));
printf("OggVorbis: Read header sizes (%i): %ld %ld %ld\n", i, hdrsizes[0], hdrsizes[1], hdrsizes[2]);
@@ -350,18 +350,18 @@ case AFM_VORBIS: {
hdr.packet = realloc(hdr.packet,hdr.bytes);
memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t),hdr.bytes);
if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0)
- printf("OggVorbis: initial (identification) header broken!\n");
+ mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: initial (identification) header broken!\n");
hdr.b_o_s = 0;
hdr.bytes = hdrsizes[1];
hdr.packet = realloc(hdr.packet,hdr.bytes);
memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0],hdr.bytes);
if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0)
- printf("OggVorbis: comment header broken!\n");
+ mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: comment header broken!\n");
hdr.bytes = hdrsizes[2];
hdr.packet = realloc(hdr.packet,hdr.bytes);
memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0]+hdrsizes[1],hdr.bytes);
if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0)
- printf("OggVorbis: codebook header broken!\n");
+ mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: codebook header broken!\n");
hdr.bytes=0;
hdr.packet = realloc(hdr.packet,hdr.bytes); /* free */
/* done with the headers */
@@ -372,18 +372,18 @@ case AFM_VORBIS: {
{
char **ptr=sh_audio->ov->vc.user_comments;
while(*ptr){
- printf("OggVorbisComment: %s\n",*ptr);
+ mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbisComment: %s\n",*ptr);
++ptr;
}
- printf("OggVorbis: Bitstream is %d channel, %ldHz, %ldkbit/s %cBR\n",sh_audio->ov->vi.channels,sh_audio->ov->vi.rate,sh_audio->ov->vi.bitrate_nominal/1000, (sh_audio->ov->vi.bitrate_lower!=sh_audio->ov->vi.bitrate_nominal)||(sh_audio->ov->vi.bitrate_upper!=sh_audio->ov->vi.bitrate_nominal)?'V':'C');
- printf("OggVorbis: Encoded by: %s\n",sh_audio->ov->vc.vendor);
+ mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Bitstream is %d channel, %ldHz, %ldkbit/s %cBR\n",sh_audio->ov->vi.channels,sh_audio->ov->vi.rate,sh_audio->ov->vi.bitrate_nominal/1000, (sh_audio->ov->vi.bitrate_lower!=sh_audio->ov->vi.bitrate_nominal)||(sh_audio->ov->vi.bitrate_upper!=sh_audio->ov->vi.bitrate_nominal)?'V':'C');
+ mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Encoded by: %s\n",sh_audio->ov->vc.vendor);
}
sh_audio->channels=sh_audio->ov->vi.channels;
sh_audio->samplerate=sh_audio->ov->vi.rate;
sh_audio->i_bps=sh_audio->ov->vi.bitrate_nominal/8;
// printf("[\n");
- sh_audio->a_buffer_len=sh_audio->audio_out_minsize;///ov->vi.channels;
+// sh_audio->a_buffer_len=sh_audio->audio_out_minsize;///ov->vi.channels;
// printf("]\n");
/* OK, got and parsed all three headers. Initialize the Vorbis
@@ -399,16 +399,16 @@ case AFM_VORBIS: {
while((ret = ogg_sync_pageout(&sh_audio->ov->oy,&sh_audio->ov->og))!=1) {
if(ret == -1)
- printf("OggVorbis: Pageout: not properly synced, had to skip some bytes.\n");
+ mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: Pageout: not properly synced, had to skip some bytes.\n");
else
if(ret == 0) {
- printf("OggVorbis: Pageout: need more data to verify page, reading more data.\n");
+ mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: need more data to verify page, reading more data.\n");
/* submit a a_buffer_len block to libvorbis' Ogg layer */
- buffer=ogg_sync_buffer(&sh_audio->ov->oy,sh_audio->a_buffer_len);
- ogg_sync_wrote(&sh_audio->ov->oy,demux_read_data(sh_audio->ds,buffer,sh_audio->a_buffer_len));
+ buffer=ogg_sync_buffer(&sh_audio->ov->oy,256);
+ ogg_sync_wrote(&sh_audio->ov->oy,demux_read_data(sh_audio->ds,buffer,256));
}
}
- printf("OggVorbis: Pageout: successfull.\n");
+ mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: successfull.\n");
/* commenting out pagein to leave data (hopefully) to the decoder - atmos */
ogg_stream_pagein(&sh_audio->ov->os,&sh_audio->ov->og); /* we can ignore any errors here
as they'll also become apparent
@@ -418,7 +418,7 @@ case AFM_VORBIS: {
/* serialno first; use it to set up a logical stream */
ogg_stream_init(&sh_audio->ov->os,ogg_page_serialno(&sh_audio->ov->og));
- printf("OggVorbis: Init OK!\n");
+ mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Init OK!\n");
break;
}
@@ -461,37 +461,40 @@ int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){
int bytes;
int samples;
float **pcm;
- ogg_int16_t convbuffer[4096];
- int convsize;
- int readlen=4096;
+ //ogg_int16_t convbuffer[4096];
+// int convsize;
+ int readlen=1024;
len=0;
- convsize=readlen/sh_audio->ov->vi.channels;
+// convsize=minlen/sh_audio->ov->vi.channels;
while(len < minlen) { /* double loop allows for break in inner loop */
while(len < minlen) { /* without aborting the outer loop - atmos */
ret=ogg_stream_packetout(&sh_audio->ov->os,&sh_audio->ov->op);
if(ret==0) {
+ int xxx=0;
//printf("OggVorbis: Packetout: need more data, paging!\n");
while((ret = ogg_sync_pageout(&sh_audio->ov->oy,&sh_audio->ov->og))!=1) {
if(ret == -1)
- printf("OggVorbis: Pageout: not properly synced, had to skip some bytes.\n");
+ mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: not properly synced, had to skip some bytes.\n");
else
if(ret == 0) {
//printf("OggVorbis: Pageout: need more data to verify page, reading more data.\n");
/* submit a readlen k block to libvorbis' Ogg layer */
buffer=ogg_sync_buffer(&sh_audio->ov->oy,readlen);
bytes=demux_read_data(sh_audio->ds,buffer,readlen);
+ xxx+=bytes;
ogg_sync_wrote(&sh_audio->ov->oy,bytes);
if(bytes==0)
- printf("OggVorbis: 0Bytes written, possible End of Stream\n");
+ mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: 0Bytes written, possible End of Stream\n");
}
}
+ mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[sync: %d ]\n",xxx);
//printf("OggVorbis: Pageout: successfull, pagin in.\n");
if(ogg_stream_pagein(&sh_audio->ov->os,&sh_audio->ov->og)<0)
- printf("OggVorbis: Pagein failed!\n");
+ mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pagein failed!\n");
break;
} else if(ret<0) {
- printf("OggVorbis: Packetout: missing or corrupt data, skipping packet!\n");
+ mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Packetout: missing or corrupt data, skipping packet!\n");
break;
} else {
@@ -508,11 +511,15 @@ int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){
while((samples=vorbis_synthesis_pcmout(&sh_audio->ov->vd,&pcm))>0){
int i,j;
int clipflag=0;
+ int convsize=(maxlen-len)/(2*sh_audio->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<sh_audio->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++){
@@ -536,12 +543,14 @@ int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){
}
if(clipflag)
- printf("Clipping in frame %ld\n",(long)(sh_audio->ov->vd.sequence));
+ mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"Clipping in frame %ld\n",(long)(sh_audio->ov->vd.sequence));
//fwrite(convbuffer,2*sh_audio->ov->vi.channels,bout,stderr); //dump pcm to file for debugging
- memcpy(buf+len,convbuffer,2*sh_audio->ov->vi.channels*bout);
+ //memcpy(buf+len,convbuffer,2*sh_audio->ov->vi.channels*bout);
len+=2*sh_audio->ov->vi.channels*bout;
-
+
+ mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[decoded: %d / %d ]\n",bout,samples);
+
vorbis_synthesis_read(&sh_audio->ov->vd,bout); /* tell libvorbis how
many samples we
actually consumed */
@@ -550,8 +559,9 @@ int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){
} // while len
} // outer while len
if(ogg_page_eos(&sh_audio->ov->og))
- printf("OggVorbis: End of Stream reached!\n"); // FIXME clearup decoder, notify mplayer - atmos
+ mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: End of Stream reached!\n"); // FIXME clearup decoder, notify mplayer - atmos
+ mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[len: %d ]\n",len);
break;
}