Changeset 172

Show
Ignore:
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
  • app_h324m/app_h324m.c

    r168 r172  
    131131{ 
    132132        int mark = 0; 
    133         int i = 0; 
     133        unsigned int i = 0; 
     134        short j = 0; 
    134135        int found = 0; 
    135         int len
     136        unsigned int len = 0
    136137        struct ast_frame* send; 
    137138 
     
    148149                                /* exit */ 
    149150                                return NULL; 
     151 
    150152                        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 
    151169                        /* Create frame */ 
    152170                        send = (struct ast_frame *) malloc(sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET + framelength + 3); 
     
    161179                        /*Convert IF2 into AMR MIME format*/ 
    162180 
    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  
    173181                        /*Reverse bytes*/ 
    174182                        TIFFReverseBits(send->data+1, framelength); 
    175183 
    176                         //It amr has a byte more then if2 
     184                        /*If amr has a byte more than if2 */ 
    177185                        if(stuf < 4) 
    178186                        { 
     187                                /* Set last byte */ 
    179188                                ((unsigned char *)(send->data+1))[bs] = ((unsigned char *)(send->data+1))[bs - 1] << 4; 
    180189                                /*Increase size of frame*/ 
     
    182191                        } 
    183192                         
    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 */ 
    191198                        ((unsigned char *)(send->data+1))[0] = mode << 3 | 0x04; 
    192199 
     
    212219                        i = 0; 
    213220                        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                                } 
    224236                        } 
    225237 
Copyright 2006 - Sergio García Murillo
Powered by Trac - Edgewall Software