--- a/misc/libtremor/tremor/info.c Sun Oct 28 03:48:37 2012 +0100
+++ b/misc/libtremor/tremor/info.c Sun Oct 28 04:00:07 2012 +0100
@@ -25,8 +25,9 @@
#include "ivorbiscodec.h"
#include "codec_internal.h"
#include "codebook.h"
+#include "registry.h"
+#include "window.h"
#include "misc.h"
-#include "os.h"
/* helpers */
static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
@@ -95,8 +96,8 @@
if(vc->user_comments)_ogg_free(vc->user_comments);
if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
if(vc->vendor)_ogg_free(vc->vendor);
+ memset(vc,0,sizeof(*vc));
}
- memset(vc,0,sizeof(*vc));
}
/* blocksize 0 is guaranteed to be short, 1 is guarantted to be long.
@@ -118,35 +119,31 @@
if(ci){
- if(ci->mode_param)_ogg_free(ci->mode_param);
+ for(i=0;i<ci->modes;i++)
+ if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
- if(ci->map_param){
- for(i=0;i<ci->maps;i++) /* unpack does the range checking */
- mapping_clear_info(ci->map_param+i);
- _ogg_free(ci->map_param);
- }
+ for(i=0;i<ci->maps;i++) /* unpack does the range checking */
+ if(ci->map_param[i])
+ _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
- if(ci->floor_param){
- for(i=0;i<ci->floors;i++) /* unpack does the range checking */
- if(ci->floor_type[i])
- floor1_free_info(ci->floor_param[i]);
- else
- floor0_free_info(ci->floor_param[i]);
- _ogg_free(ci->floor_param);
- _ogg_free(ci->floor_type);
- }
+ for(i=0;i<ci->floors;i++) /* unpack does the range checking */
+ if(ci->floor_param[i])
+ _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
+
+ for(i=0;i<ci->residues;i++) /* unpack does the range checking */
+ if(ci->residue_param[i])
+ _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
- if(ci->residue_param){
- for(i=0;i<ci->residues;i++) /* unpack does the range checking */
- res_clear_info(ci->residue_param+i);
- _ogg_free(ci->residue_param);
+ for(i=0;i<ci->books;i++){
+ if(ci->book_param[i]){
+ /* knows if the book was not alloced */
+ vorbis_staticbook_destroy(ci->book_param[i]);
+ }
+ if(ci->fullbooks)
+ vorbis_book_clear(ci->fullbooks+i);
}
-
- if(ci->book_param){
- for(i=0;i<ci->books;i++)
- vorbis_book_clear(ci->book_param+i);
- _ogg_free(ci->book_param);
- }
+ if(ci->fullbooks)
+ _ogg_free(ci->fullbooks);
_ogg_free(ci);
}
@@ -222,53 +219,70 @@
/* codebooks */
ci->books=oggpack_read(opb,8)+1;
- ci->book_param=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->book_param));
- for(i=0;i<ci->books;i++)
- if(vorbis_book_unpack(opb,ci->book_param+i))goto err_out;
+ /*ci->book_param=_ogg_calloc(ci->books,sizeof(*ci->book_param));*/
+ for(i=0;i<ci->books;i++){
+ ci->book_param[i]=(static_codebook *)_ogg_calloc(1,sizeof(*ci->book_param[i]));
+ if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
+ }
- /* time backend settings, not actually used */
- i=oggpack_read(opb,6);
- for(;i>=0;i--)
- if(oggpack_read(opb,16)!=0)goto err_out;
+ /* time backend settings */
+ ci->times=oggpack_read(opb,6)+1;
+ /*ci->time_type=_ogg_malloc(ci->times*sizeof(*ci->time_type));*/
+ /*ci->time_param=_ogg_calloc(ci->times,sizeof(void *));*/
+ for(i=0;i<ci->times;i++){
+ ci->time_type[i]=oggpack_read(opb,16);
+ if(ci->time_type[i]<0 || ci->time_type[i]>=VI_TIMEB)goto err_out;
+ /* ci->time_param[i]=_time_P[ci->time_type[i]]->unpack(vi,opb);
+ Vorbis I has no time backend */
+ /*if(!ci->time_param[i])goto err_out;*/
+ }
/* floor backend settings */
ci->floors=oggpack_read(opb,6)+1;
- ci->floor_param=_ogg_malloc(sizeof(*ci->floor_param)*ci->floors);
- ci->floor_type=_ogg_malloc(sizeof(*ci->floor_type)*ci->floors);
+ /*ci->floor_type=_ogg_malloc(ci->floors*sizeof(*ci->floor_type));*/
+ /*ci->floor_param=_ogg_calloc(ci->floors,sizeof(void *));*/
for(i=0;i<ci->floors;i++){
ci->floor_type[i]=oggpack_read(opb,16);
if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
- if(ci->floor_type[i])
- ci->floor_param[i]=floor1_info_unpack(vi,opb);
- else
- ci->floor_param[i]=floor0_info_unpack(vi,opb);
+ ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
if(!ci->floor_param[i])goto err_out;
}
/* residue backend settings */
ci->residues=oggpack_read(opb,6)+1;
- ci->residue_param=_ogg_malloc(sizeof(*ci->residue_param)*ci->residues);
- for(i=0;i<ci->residues;i++)
- if(res_unpack(ci->residue_param+i,vi,opb))goto err_out;
+ /*ci->residue_type=_ogg_malloc(ci->residues*sizeof(*ci->residue_type));*/
+ /*ci->residue_param=_ogg_calloc(ci->residues,sizeof(void *));*/
+ for(i=0;i<ci->residues;i++){
+ ci->residue_type[i]=oggpack_read(opb,16);
+ if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
+ ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
+ if(!ci->residue_param[i])goto err_out;
+ }
/* map backend settings */
ci->maps=oggpack_read(opb,6)+1;
- ci->map_param=_ogg_malloc(sizeof(*ci->map_param)*ci->maps);
+ /*ci->map_type=_ogg_malloc(ci->maps*sizeof(*ci->map_type));*/
+ /*ci->map_param=_ogg_calloc(ci->maps,sizeof(void *));*/
for(i=0;i<ci->maps;i++){
- if(oggpack_read(opb,16)!=0)goto err_out;
- if(mapping_info_unpack(ci->map_param+i,vi,opb))goto err_out;
+ ci->map_type[i]=oggpack_read(opb,16);
+ if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
+ ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
+ if(!ci->map_param[i])goto err_out;
}
/* mode settings */
ci->modes=oggpack_read(opb,6)+1;
- ci->mode_param=
- (vorbis_info_mode *)_ogg_malloc(ci->modes*sizeof(*ci->mode_param));
+ /*vi->mode_param=_ogg_calloc(vi->modes,sizeof(void *));*/
for(i=0;i<ci->modes;i++){
- ci->mode_param[i].blockflag=oggpack_read(opb,1);
- if(oggpack_read(opb,16))goto err_out;
- if(oggpack_read(opb,16))goto err_out;
- ci->mode_param[i].mapping=oggpack_read(opb,8);
- if(ci->mode_param[i].mapping>=ci->maps)goto err_out;
+ ci->mode_param[i]=(vorbis_info_mode *)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
+ ci->mode_param[i]->blockflag=oggpack_read(opb,1);
+ ci->mode_param[i]->windowtype=oggpack_read(opb,16);
+ ci->mode_param[i]->transformtype=oggpack_read(opb,16);
+ ci->mode_param[i]->mapping=oggpack_read(opb,8);
+
+ if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
+ if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
+ if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
}
if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
@@ -284,7 +298,7 @@
with bitstream comments and a third packet that holds the
codebook. */
-int vorbis_dsp_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
+int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
oggpack_buffer opb;
if(op){