Changeset 172
- Timestamp:
- 10/10/07 11:18:13
(11 months ago)
- Author:
- sip
- Message:
Length check and signess correction.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r168 |
r172 |
|
| 131 | 131 | { |
|---|
| 132 | 132 | int mark = 0; |
|---|
| 133 | | int i = 0; |
|---|
| | 133 | unsigned int i = 0; |
|---|
| | 134 | short j = 0; |
|---|
| 134 | 135 | int found = 0; |
|---|
| 135 | | int len; |
|---|
| | 136 | unsigned int len = 0; |
|---|
| 136 | 137 | struct ast_frame* send; |
|---|
| 137 | 138 | |
|---|
| … | … | |
| 148 | 149 | /* exit */ |
|---|
| 149 | 150 | return NULL; |
|---|
| | 151 | |
|---|
| 150 | 152 | ast_log(LOG_DEBUG, "create_ast_frame: received AMR frame with %d bytes\n",framelength); |
|---|
| | 153 | |
|---|
| | 154 | /*Get header*/ |
|---|
| | 155 | unsigned char header = framedata[0]; |
|---|
| | 156 | /*Get mode*/ |
|---|
| | 157 | unsigned char mode = header & 0x0F; |
|---|
| | 158 | /*Get number of stuffing bits*/ |
|---|
| | 159 | unsigned int stuf = if2stuffing[mode]; |
|---|
| | 160 | |
|---|
| | 161 | /*Get Block Size*/ |
|---|
| | 162 | short bs = blockSize[mode]; |
|---|
| | 163 | |
|---|
| | 164 | /* Check correct mode and length */ |
|---|
| | 165 | if (bs==-1 || framelength<bs) |
|---|
| | 166 | /* Exit */ |
|---|
| | 167 | return NULL; |
|---|
| | 168 | |
|---|
| 151 | 169 | /* Create frame */ |
|---|
| 152 | 170 | send = (struct ast_frame *) malloc(sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET + framelength + 3); |
|---|
| … | … | |
| 161 | 179 | /*Convert IF2 into AMR MIME format*/ |
|---|
| 162 | 180 | |
|---|
| 163 | | /*Get header*/ |
|---|
| 164 | | unsigned char header = ((unsigned char *)(send->data+1))[0]; |
|---|
| 165 | | /*Get mode*/ |
|---|
| 166 | | unsigned char mode = header & 0x0F; |
|---|
| 167 | | /*Get number of stuffing bits*/ |
|---|
| 168 | | unsigned int stuf = if2stuffing[mode]; |
|---|
| 169 | | /*Get Block Size*/ |
|---|
| 170 | | unsigned int bs = blockSize[mode]; |
|---|
| 171 | | |
|---|
| 172 | | |
|---|
| 173 | 181 | /*Reverse bytes*/ |
|---|
| 174 | 182 | TIFFReverseBits(send->data+1, framelength); |
|---|
| 175 | 183 | |
|---|
| 176 | | //It amr has a byte more then if2 |
|---|
| | 184 | /*If amr has a byte more than if2 */ |
|---|
| 177 | 185 | if(stuf < 4) |
|---|
| 178 | 186 | { |
|---|
| | 187 | /* Set last byte */ |
|---|
| 179 | 188 | ((unsigned char *)(send->data+1))[bs] = ((unsigned char *)(send->data+1))[bs - 1] << 4; |
|---|
| 180 | 189 | /*Increase size of frame*/ |
|---|
| … | … | |
| 182 | 191 | } |
|---|
| 183 | 192 | |
|---|
| 184 | | //For each byte |
|---|
| 185 | | for(i=bs-1; i>0; i--) |
|---|
| 186 | | { |
|---|
| 187 | | ((unsigned char *)(send->data+1))[i] = ((unsigned char *)(send->data+1))[i] >> 4 | ((unsigned char *)(send->data+1))[i-1] << 4; |
|---|
| 188 | | } |
|---|
| 189 | | |
|---|
| 190 | | //Calculate first |
|---|
| | 193 | /* For each byte */ |
|---|
| | 194 | for(j=bs-1; j>0; j--) |
|---|
| | 195 | ((unsigned char *)(send->data+1))[j] = ((unsigned char *)(send->data+1))[j] >> 4 | ((unsigned char *)(send->data+1))[j-1] << 4; |
|---|
| | 196 | |
|---|
| | 197 | /* Calculate first byte */ |
|---|
| 191 | 198 | ((unsigned char *)(send->data+1))[0] = mode << 3 | 0x04; |
|---|
| 192 | 199 | |
|---|
| … | … | |
| 212 | 219 | i = 0; |
|---|
| 213 | 220 | found = 0; |
|---|
| 214 | | /* Try to find begining of frame */ |
|---|
| 215 | | while (!found && i<framelength-4) |
|---|
| 216 | | { |
|---|
| 217 | | /* Check if we found start code */ |
|---|
| 218 | | if (framedata[i] == 0 && framedata[i+1] == 0 && (framedata[i+2] & 0xFC) == 0x80) |
|---|
| 219 | | /* We found it */ |
|---|
| 220 | | found = 1; |
|---|
| 221 | | else |
|---|
| 222 | | /* Increase pointer */ |
|---|
| 223 | | i++; |
|---|
| | 221 | |
|---|
| | 222 | /* Check length*/ |
|---|
| | 223 | if(framelength>2) |
|---|
| | 224 | { |
|---|
| | 225 | /* Try to find begining of frame */ |
|---|
| | 226 | while (!found && i<framelength-4) |
|---|
| | 227 | { |
|---|
| | 228 | /* Check if we found start code */ |
|---|
| | 229 | if (framedata[i] == 0 && framedata[i+1] == 0 && (framedata[i+2] & 0xFC) == 0x80) |
|---|
| | 230 | /* We found it */ |
|---|
| | 231 | found = 1; |
|---|
| | 232 | else |
|---|
| | 233 | /* Increase pointer */ |
|---|
| | 234 | i++; |
|---|
| | 235 | } |
|---|
| 224 | 236 | } |
|---|
| 225 | 237 | |
|---|
Download in other formats:
|
|