From f1d07420122e1d8a4bd221c1942a12daee862311 Mon Sep 17 00:00:00 2001 From: roytam1 Date: Sun, 27 Aug 2023 18:05:50 +0800 Subject: [PATCH] tremor: update to https://github.com/sezero/tremor/tree/91decb5f1b11a84a2157a6326d9135b22627024b since upstream(i.e. xiph) doesn't update it since 2018. locally added NOMINMAX guard as well. --- media/libtremor/README_MCP | 4 +- media/libtremor/include/tremor/ivorbiscodec.h | 3 - media/libtremor/lib/misc.h | 31 ++++------- media/libtremor/lib/moz.build | 5 ++ media/libtremor/lib/os.h | 55 ++++++++++++++----- media/libtremor/lib/tremor_codebook.c | 11 ++-- media/libtremor/lib/tremor_floor0.c | 4 +- media/libtremor/lib/tremor_floor1.c | 1 - media/libtremor/lib/tremor_info.c | 21 ++++--- media/libtremor/lib/tremor_mapping0.c | 10 ++-- media/libtremor/lib/tremor_mdct.c | 10 ++-- media/libtremor/lib/tremor_res012.c | 3 +- media/libtremor/lib/tremor_sharedbook.c | 10 ++-- media/libtremor/lib/tremor_window.c | 6 +- 14 files changed, 93 insertions(+), 81 deletions(-) diff --git a/media/libtremor/README_MCP b/media/libtremor/README_MCP index a1d2bd12ec..23ebfb4a82 100644 --- a/media/libtremor/README_MCP +++ b/media/libtremor/README_MCP @@ -3,5 +3,5 @@ git repository using the update.sh script. The only changes made were those applied by update.sh and the addition/update of Makefile.in files for the UXP build system. -The upstream release used was https://gitlab.xiph.org/xiph/tremor -The git revision used was 7c30a66346199f3f09017a09567c6c8a3a0eedc8. +The upstream release used was https://github.com/sezero/tremor +The git revision used was 91decb5f1b11a84a2157a6326d9135b22627024b. diff --git a/media/libtremor/include/tremor/ivorbiscodec.h b/media/libtremor/include/tremor/ivorbiscodec.h index 17eab58d46..46d1c4db8d 100644 --- a/media/libtremor/include/tremor/ivorbiscodec.h +++ b/media/libtremor/include/tremor/ivorbiscodec.h @@ -153,9 +153,6 @@ extern void vorbis_info_init(vorbis_info *vi); extern void vorbis_info_clear(vorbis_info *vi); extern int vorbis_info_blocksize(vorbis_info *vi,int zo); extern void vorbis_comment_init(vorbis_comment *vc); -extern void vorbis_comment_add(vorbis_comment *vc, char *comment); -extern void vorbis_comment_add_tag(vorbis_comment *vc, - char *tag, char *contents); extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count); extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag); extern void vorbis_comment_clear(vorbis_comment *vc); diff --git a/media/libtremor/lib/misc.h b/media/libtremor/lib/misc.h index 1ae4d2e813..cdc646d4ed 100644 --- a/media/libtremor/lib/misc.h +++ b/media/libtremor/lib/misc.h @@ -22,10 +22,10 @@ #ifdef _LOW_ACCURACY_ # define X(n) (((((n)>>22)+1)>>1) - ((((n)>>22)+1)>>9)) -# define LOOKUP_T const unsigned char +# define LOOKUP_T unsigned char #else # define X(n) (n) -# define LOOKUP_T const ogg_int32_t +# define LOOKUP_T ogg_int32_t #endif #include "asm_arm.h" @@ -37,29 +37,22 @@ #ifndef _LOW_ACCURACY_ /* 64 bit multiply */ -#if !(defined WIN32 && defined WINCE) +#ifdef HAVE_SYS_TYPES_H #include #endif -#if BYTE_ORDER==LITTLE_ENDIAN -union magic { - struct { - ogg_int32_t lo; - ogg_int32_t hi; - } halves; - ogg_int64_t whole; -}; -#endif - -#if BYTE_ORDER==BIG_ENDIAN union magic { struct { +#ifdef WORDS_BIGENDIAN ogg_int32_t hi; ogg_int32_t lo; - } halves; - ogg_int64_t whole; -}; +#else /* little endian */ + ogg_int32_t lo; + ogg_int32_t hi; #endif + } halves; + ogg_int64_t whole; +}; STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { union magic magic; @@ -246,7 +239,3 @@ STIN ogg_int32_t VFLOAT_ADD(ogg_int32_t a,ogg_int32_t ap, } #endif - - - - diff --git a/media/libtremor/lib/moz.build b/media/libtremor/lib/moz.build index 94d07583b7..c201c4c518 100644 --- a/media/libtremor/lib/moz.build +++ b/media/libtremor/lib/moz.build @@ -20,6 +20,11 @@ SOURCES += [ FINAL_LIBRARY = 'gkmedias' +DEFINES['HAVE_ALLOCA'] = True + +if CONFIG['OS_ARCH'] == 'WINNT': + DEFINES['NOMINMAX'] = True + if CONFIG['OS_ARCH'] == 'AIX': DEFINES['alloca'] = '__alloca' diff --git a/media/libtremor/lib/os.h b/media/libtremor/lib/os.h index 130d27de32..09936367a8 100644 --- a/media/libtremor/lib/os.h +++ b/media/libtremor/lib/os.h @@ -17,7 +17,10 @@ ********************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #ifndef _V_IFDEFJAIL_H_ @@ -25,34 +28,55 @@ # ifdef __GNUC__ # define STIN static __inline__ -# elif _WIN32 +# elif defined(__VBCC__) +# define STIN static inline +# elif defined(_WIN32) # define STIN static __inline +# elif defined(__WATCOMC__) +# define STIN static __inline +# else +# define STIN static # endif -#else -# define STIN static -#endif - -#ifndef M_PI -# define M_PI (3.1415926536f) #endif #ifdef _WIN32 # include -# define rint(x) (floor((x)+0.5f)) -# define NO_FLOAT_MATH_LIB -# define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b)) -# define LITTLE_ENDIAN 1 -# define BYTE_ORDER LITTLE_ENDIAN #endif -#ifdef HAVE_ALLOCA_H -# include +#if defined HAVE_ALLOCA + +# ifdef _WIN32 +# include +# define VAR_STACK(type, var, size) type *var = ((type*)_alloca(sizeof(type)*(size))) +# else +# ifdef HAVE_ALLOCA_H +# include +# else +# include +# endif +# if defined(__AROS__) && defined(__GNUC__) + /* bypass __alloca_get_stack_limit() call in alloca.h + from old AROS SDKs, directly use __builtin_alloca(). */ +# undef alloca +# define alloca __builtin_alloca +# endif +# define VAR_STACK(type, var, size) type *var = ((type*) alloca(sizeof(type)*(size))) +# endif + +#elif defined VAR_ARRAYS + +# define VAR_STACK(type, var, size) type var[size] + +#else + +#error "Either VAR_ARRAYS or HAVE_ALLOCA must be defined to select the stack allocation mode" #endif #ifdef USE_MEMORY_H # include #endif +#ifndef NOMINMAX #ifndef min # define min(x,y) ((x)>(y)?(y):(x)) #endif @@ -60,5 +84,6 @@ #ifndef max # define max(x,y) ((x)<(y)?(y):(x)) #endif +#endif #endif /* _OS_H */ diff --git a/media/libtremor/lib/tremor_codebook.c b/media/libtremor/lib/tremor_codebook.c index 1e1ae8a916..c0a06ec6fe 100644 --- a/media/libtremor/lib/tremor_codebook.c +++ b/media/libtremor/lib/tremor_codebook.c @@ -17,7 +17,6 @@ #include #include -#include #include #include "ivorbiscodec.h" #include "codebook.h" @@ -168,7 +167,7 @@ STIN long decode_packed_entry_number(codebook *book, int read=book->dec_maxlength; long lo,hi; long lok = oggpack_look(b,book->dec_firsttablen); - + if (lok >= 0) { long entry = book->dec_firsttable[lok]; if(entry&0x80000000UL){ @@ -245,9 +244,9 @@ long vorbis_book_decode(codebook *book, oggpack_buffer *b){ long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a, oggpack_buffer *b,int n,int point){ if(book->used_entries>0){ - int step=n/book->dim; - long *entry = (long *)alloca(sizeof(*entry)*step); - ogg_int32_t **t = (ogg_int32_t **)alloca(sizeof(*t)*step); + const int step=n/book->dim; + VAR_STACK(long, entry, step); + VAR_STACK(ogg_int32_t *, t, step); int i,j,o; int shift=point-book->binarypoint; @@ -336,7 +335,7 @@ long vorbis_book_decodev_set(codebook *book,ogg_int32_t *a, } }else{ - int i,j; + int i; for(i=0;i #include -#include #include #include "ivorbiscodec.h" #include "codec_internal.h" @@ -145,7 +144,7 @@ void vorbis_lsp_to_curve(ogg_int32_t *curve,int *map,int n,int ln, int i; int ampoffseti=ampoffset*4096; int ampi=amp; - ogg_int32_t *ilsp=(ogg_int32_t *)alloca(m*sizeof(*ilsp)); + VAR_STACK(ogg_int32_t, ilsp, m); /* lsp is in 8.24, range 0 to PI; coslook wants it in .16 0 to 1*/ for(i=0;i #include -#include #include #include "ivorbiscodec.h" #include "codec_internal.h" diff --git a/media/libtremor/lib/tremor_info.c b/media/libtremor/lib/tremor_info.c index 24e24ac728..469b482b1a 100644 --- a/media/libtremor/lib/tremor_info.c +++ b/media/libtremor/lib/tremor_info.c @@ -20,7 +20,6 @@ #include #include -#include #include #include #include "ivorbiscodec.h" @@ -37,6 +36,10 @@ static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){ } } +STIN int _v_toupper(int c) { + return (c >= 'a' && c <= 'z') ? (c & ~('a' - 'A')) : c; +} + void vorbis_comment_init(vorbis_comment *vc){ memset(vc,0,sizeof(*vc)); } @@ -46,7 +49,7 @@ void vorbis_comment_init(vorbis_comment *vc){ static int tagcompare(const char *s1, const char *s2, int n){ int c=0; while(c < n){ - if(toupper(s1[c]) != toupper(s2[c])) + if(_v_toupper(s1[c]) != _v_toupper(s2[c])) return !0; c++; } @@ -56,8 +59,8 @@ static int tagcompare(const char *s1, const char *s2, int n){ char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){ long i; int found = 0; - int taglen = strlen(tag)+1; /* +1 for the = we append */ - char *fulltag = (char *)alloca(taglen+ 1); + const int taglen = strlen(tag)+1; /* +1 for the = we append */ + VAR_STACK(char, fulltag, taglen+1); strcpy(fulltag, tag); strcat(fulltag, "="); @@ -76,8 +79,8 @@ char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){ int vorbis_comment_query_count(vorbis_comment *vc, char *tag){ int i,count=0; - int taglen = strlen(tag)+1; /* +1 for the = we append */ - char *fulltag = (char *)alloca(taglen+1); + const int taglen = strlen(tag)+1; /* +1 for the = we append */ + VAR_STACK(char, fulltag, taglen+1); strcpy(fulltag,tag); strcat(fulltag, "="); @@ -166,9 +169,9 @@ static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){ vi->channels=oggpack_read(opb,8); vi->rate=oggpack_read(opb,32); - vi->bitrate_upper=oggpack_read(opb,32); - vi->bitrate_nominal=oggpack_read(opb,32); - vi->bitrate_lower=oggpack_read(opb,32); + vi->bitrate_upper=(ogg_int32_t)oggpack_read(opb,32); + vi->bitrate_nominal=(ogg_int32_t)oggpack_read(opb,32); + vi->bitrate_lower=(ogg_int32_t)oggpack_read(opb,32); ci->blocksizes[0]=1<blocksizes[1]=1< #include #include -#include #include #include "ivorbiscodec.h" #include "mdct.h" @@ -129,7 +128,6 @@ static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb) int i,b; vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)_ogg_calloc(1,sizeof(*info)); codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; - memset(info,0,sizeof(*info)); b=oggpack_read(opb,1); if(b<0)goto err_out; @@ -194,11 +192,11 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){ int i,j; long n=vb->pcmend=ci->blocksizes[vb->W]; - ogg_int32_t **pcmbundle=(ogg_int32_t **)alloca(sizeof(*pcmbundle)*vi->channels); - int *zerobundle=(int *)alloca(sizeof(*zerobundle)*vi->channels); + VAR_STACK(ogg_int32_t *, pcmbundle, vi->channels); + VAR_STACK(int, zerobundle, vi->channels); - int *nonzero =(int *)alloca(sizeof(*nonzero)*vi->channels); - void **floormemo=(void **)alloca(sizeof(*floormemo)*vi->channels); + VAR_STACK(int, nonzero, vi->channels); + VAR_STACK(void *, floormemo, vi->channels); /* time domain information decode (note that applying the information would have to happen later; we'll probably add a diff --git a/media/libtremor/lib/tremor_mdct.c b/media/libtremor/lib/tremor_mdct.c index 2aed62c51c..3ad4483fdd 100644 --- a/media/libtremor/lib/tremor_mdct.c +++ b/media/libtremor/lib/tremor_mdct.c @@ -147,7 +147,7 @@ STIN void mdct_butterfly_32(DATA_TYPE *x){ /* N/stage point generic N stage butterfly (in place, 2 register) */ STIN void mdct_butterfly_generic(DATA_TYPE *x,int points,int step){ - LOOKUP_T *T = sincos_lookup0; + const LOOKUP_T *T = sincos_lookup0; DATA_TYPE *x1 = x + points - 8; DATA_TYPE *x2 = x + (points>>1) - 8; REG_TYPE r0; @@ -257,8 +257,8 @@ STIN void mdct_bitreverse(DATA_TYPE *x,int n,int step,int shift){ int bit = 0; DATA_TYPE *w0 = x; DATA_TYPE *w1 = x = w0+(n>>1); - LOOKUP_T *T = (step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1; - LOOKUP_T *Ttop = T+1024; + const LOOKUP_T *T = (step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1; + const LOOKUP_T *Ttop = T+1024; DATA_TYPE r2; do{ @@ -342,8 +342,8 @@ void mdct_backward(int n, DATA_TYPE *in, DATA_TYPE *out){ int n4=n>>2; DATA_TYPE *iX; DATA_TYPE *oX; - LOOKUP_T *T; - LOOKUP_T *V; + const LOOKUP_T *T; + const LOOKUP_T *V; int shift; int step; diff --git a/media/libtremor/lib/tremor_res012.c b/media/libtremor/lib/tremor_res012.c index f036caaa48..4e3a54bfe2 100644 --- a/media/libtremor/lib/tremor_res012.c +++ b/media/libtremor/lib/tremor_res012.c @@ -17,7 +17,6 @@ #include #include -#include #include #include "ivorbiscodec.h" #include "codec_internal.h" @@ -226,7 +225,7 @@ static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl, if(n>0){ int partvals=n/samples_per_partition; int partwords=(partvals+partitions_per_word-1)/partitions_per_word; - int ***partword=(int ***)alloca(ch*sizeof(*partword)); + VAR_STACK(int **, partword, ch); for(j=0;j -#include #include #include #include "misc.h" @@ -330,7 +329,7 @@ static int sort32a(const void *a,const void *b){ /* decode codebook arrangement is more heavily optimized than encode */ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ int i,j,n=0,tabn; - int *sortindex; + memset(c,0,sizeof(*c)); /* count actually used entries */ @@ -355,7 +354,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ /* perform sort */ ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries); - ogg_uint32_t **codep=(ogg_uint32_t **)alloca(sizeof(*codep)*n); + VAR_STACK(ogg_uint32_t *, codep, n); if(codes==NULL)goto err_out; @@ -366,7 +365,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ qsort(codep,n,sizeof(*codep),sort32a); - sortindex=(int *)alloca(n*sizeof(*sortindex)); + { VAR_STACK(int, sortindex, n); c->codelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist)); /* the index is a reverse index */ for(i=0;ientries;i++) if(s->lengthlist[i]>0) c->dec_codelengths[sortindex[n++]]=s->lengthlist[i]; - + } c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */ if(c->dec_firsttablen<5)c->dec_firsttablen=5; if(c->dec_firsttablen>8)c->dec_firsttablen=8; @@ -444,4 +443,3 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ vorbis_book_clear(c); return(-1); } - diff --git a/media/libtremor/lib/tremor_window.c b/media/libtremor/lib/tremor_window.c index 006a1ee6b5..80da7f383f 100644 --- a/media/libtremor/lib/tremor_window.c +++ b/media/libtremor/lib/tremor_window.c @@ -16,7 +16,6 @@ ********************************************************************/ #include -#include #include "misc.h" #include "window.h" #include "window_lookup.h" @@ -56,7 +55,7 @@ void _vorbis_apply_window(ogg_int32_t *d,const void *window_p[2], long *blocksizes, int lW,int W,int nW){ - LOOKUP_T *window[2]={window_p[0],window_p[1]}; + const LOOKUP_T *window[2]; long n=blocksizes[W]; long ln=blocksizes[lW]; long rn=blocksizes[nW]; @@ -69,6 +68,9 @@ void _vorbis_apply_window(ogg_int32_t *d,const void *window_p[2], int i,p; + window[0] = (const LOOKUP_T *)window_p[0]; + window[1] = (const LOOKUP_T *)window_p[1]; + for(i=0;i