evrc2Pcm.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. evrcPacketDecode
  3. rtp语音包语音内容解密
  4. */
  5. #include "evrc2Pcm.h"
  6. #include <string.h>
  7. unsigned short evrcPacketDecode(unsigned char *outBuf,unsigned char *playload, unsigned char playlen)
  8. {
  9. T_BOOL fullRate;
  10. unsigned char index;
  11. unsigned char offset=0;
  12. unsigned char offsetN=VOICE_DATA_INDEX;
  13. int i;
  14. unsigned short retLen;
  15. if(playload[CNT_EVRC_FRAME_INDEX]==HAS_AMRNB_RATE){
  16. retLen=playlen-16;
  17. for(i=0;i<retLen;i++)
  18. outBuf[i]=playload[VOICE_DATA_INDEX+i]^playload[VOICE_MAGIC_INDEX];
  19. return retLen;
  20. }else if(playload[CNT_EVRC_FRAME_INDEX]==ALL_FULL_RATE){
  21. for(index = 0; index < (UDP_VOICE_PKT_FRAME_CNT*FULL_FRAME_SIZE); index++)
  22. playload[VOICE_DATA_INDEX+index] = (playload[VOICE_DATA_INDEX+index] ^ playload[VOICE_MAGIC_INDEX]);
  23. for(index = 0; index < UDP_VOICE_PKT_FRAME_CNT; index++){
  24. outBuf[offset++] = FULL_FRAME_I;
  25. outBuf[offset++] = FULL_FRAME_SIZE;
  26. memcpy(&outBuf[offset],&playload[offsetN], FULL_FRAME_SIZE);
  27. offsetN += FULL_FRAME_SIZE;
  28. offset += FULL_FRAME_SIZE;
  29. }
  30. return offset;
  31. }else{
  32. if(HAS_FULL_RATE==playload[CNT_EVRC_FRAME_INDEX]){
  33. fullRate=TRUE;
  34. for(index = 0; index < (FULL_FRAME_SIZE+ (UDP_VOICE_PKT_FRAME_CNT-1)*HALF_FRAME_SIZE); index++)
  35. playload[VOICE_DATA_INDEX+index] = (playload[VOICE_DATA_INDEX+index] ^ playload[VOICE_MAGIC_INDEX]);
  36. }else{
  37. fullRate=FALSE;
  38. for(index = 0; index < UDP_VOICE_PKT_FRAME_CNT*HALF_FRAME_SIZE; index++){
  39. playload[VOICE_DATA_INDEX+index] = (playload[VOICE_DATA_INDEX+index] ^ playload[VOICE_MAGIC_INDEX]);
  40. }
  41. }
  42. outBuf[0]=(fullRate ? FULL_FRAME_I : HALF_FRAME_I);
  43. outBuf[1] = (fullRate ? FULL_FRAME_SIZE : HALF_FRAME_SIZE);
  44. memcpy(&outBuf[2],&playload[VOICE_DATA_INDEX], (fullRate ? FULL_FRAME_SIZE : HALF_FRAME_SIZE));
  45. offset += (2+(fullRate ? FULL_FRAME_SIZE : HALF_FRAME_SIZE));
  46. offsetN += (fullRate ? FULL_FRAME_SIZE : HALF_FRAME_SIZE);
  47. for(index = 0; index < (UDP_VOICE_PKT_FRAME_CNT-1); index++){
  48. outBuf[offset++] = HALF_FRAME_I;
  49. outBuf[offset++] = HALF_FRAME_SIZE;
  50. memcpy(&outBuf[offset],&playload[offsetN], HALF_FRAME_SIZE);
  51. offsetN += HALF_FRAME_SIZE;
  52. offset += HALF_FRAME_SIZE;
  53. }
  54. return offset;
  55. }
  56. }