# HG changeset patch # User arpi # Date 999451312 0 # Node ID 9fd8b5e0b86427018ce434dc4896e7d8bad107e8 # Parent 7c1671842ee7251d4a787f95c804437ea6a67fe5 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg diff -r 7c1671842ee7 -r 9fd8b5e0b864 dec_audio.c --- a/dec_audio.c Sun Sep 02 17:21:22 2001 +0000 +++ b/dec_audio.c Sun Sep 02 17:21:52 2001 +0000 @@ -137,7 +137,7 @@ 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 @@ 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 @@ 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 @@ { 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 @@ 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 @@ /* 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 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 @@ 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=(samplesov->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;jov->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 @@ } // 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; }