Changeset 628 for pjproject/trunk/pjmedia/src/pjmedia-codec/speex/bits.c
- Timestamp:
- Jul 26, 2006 5:04:54 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-codec/speex/bits.c
r278 r628 94 94 { 95 95 int i; 96 if (len > bits->buf_size) 96 int nchars = len / BYTES_PER_CHAR; 97 if (nchars > bits->buf_size) 97 98 { 98 99 speex_warning_int("Packet is larger than allocated buffer: ", len); 99 100 if (bits->owner) 100 101 { 101 char *tmp = (char*)speex_realloc(bits->chars, len);102 char *tmp = (char*)speex_realloc(bits->chars, nchars); 102 103 if (tmp) 103 104 { 104 bits->buf_size= len;105 bits->buf_size=nchars; 105 106 bits->chars=tmp; 106 107 } else { 107 len=bits->buf_size;108 nchars=bits->buf_size; 108 109 speex_warning("Could not resize input buffer: truncating input"); 109 110 } 110 111 } else { 111 112 speex_warning("Do not own input buffer: truncating input"); 112 len=bits->buf_size; 113 } 114 } 115 for (i=0;i<len;i++) 116 bits->chars[i]=chars[i]; 117 bits->nbBits=len<<3; 113 nchars=bits->buf_size; 114 } 115 } 116 #if (BYTES_PER_CHAR==2) 117 /* Swap bytes to proper endian order (could be done externally) */ 118 #define HTOLS(A) ((((A) >> 8)&0xff)|(((A) & 0xff)<<8)) 119 #else 120 #define HTOLS(A) (A) 121 #endif 122 for (i=0;i<nchars;i++) 123 bits->chars[i]=HTOLS(chars[i]); 124 125 bits->nbBits=nchars<<LOG2_BITS_PER_CHAR; 118 126 bits->charPtr=0; 119 127 bits->bitPtr=0; … … 162 170 pos=bits->nbBits>>LOG2_BITS_PER_CHAR; 163 171 for (i=0;i<nchars;i++) 164 bits->chars[pos+i]= chars[i];172 bits->chars[pos+i]=HTOLS(chars[i]); 165 173 bits->nbBits+=nchars<<LOG2_BITS_PER_CHAR; 166 174 } … … 183 191 if (max_nchars > ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR)) 184 192 max_nchars = ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR); 185 #if BYTES_PER_CHAR==1 186 #define HTOLS(A) (A) 187 #else 188 #define HTOLS(A) ((((A) >> 8)&0xff)|(((A) & 0xff)<<8)) 189 #endif 193 190 194 for (i=0;i<max_nchars;i++) 191 195 chars[i]=HTOLS(bits->chars[i]); … … 200 204 max_nchars = ((bits->nbBits)>>LOG2_BITS_PER_CHAR); 201 205 for (i=0;i<max_nchars;i++) 202 chars[i]= bits->chars[i];203 206 chars[i]=HTOLS(bits->chars[i]); 207 204 208 if (bits->bitPtr>0) 205 209 bits->chars[0]=bits->chars[max_nchars];
Note: See TracChangeset
for help on using the changeset viewer.