Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
5.8 KiB

  1. /* *************************************************************************
  2. ** INTEL Corporation Proprietary Information
  3. **
  4. ** This listing is supplied under the terms of a license
  5. ** agreement with INTEL Corporation and may not be copied
  6. ** nor disclosed except in accordance with the terms of
  7. ** that agreement.
  8. **
  9. ** Copyright (c) 1995 Intel Corporation.
  10. ** Copyright (c) 1996 Intel Corporation.
  11. ** All Rights Reserved.
  12. **
  13. ** *************************************************************************
  14. // $Header: S:\h26x\src\common\c3rtp.cpv 1.8 03 Dec 1996 13:16:16 CZHU $
  15. // $Log: S:\h26x\src\common\c3rtp.cpv $
  16. //
  17. // Rev 1.8 03 Dec 1996 13:16:16 CZHU
  18. // adjust format of debug message.
  19. //
  20. // Rev 1.7 26 Nov 1996 16:00:26 GMLIM
  21. // Increase size returned by getrtpBsInfoSize() for larger PB bs info buffer.
  22. //
  23. // Rev 1.6 06 Nov 1996 15:11:42 CZHU
  24. // Added minor change for debug output
  25. //
  26. // Rev 1.5 31 Oct 1996 10:12:36 KLILLEVO
  27. // changed from DBOUT to DBgLog
  28. //
  29. // Rev 1.4 17 Sep 1996 09:22:58 CZHU
  30. // minor cleaning
  31. //
  32. // Rev 1.3 16 Sep 1996 16:38:44 CZHU
  33. // Extended the minimum packet size to 128 bytes. Fixed buffer overflow bug
  34. //
  35. // Rev 1.2 02 May 1996 13:27:04 CZHU
  36. // Adjust for merging with main database in the decoder
  37. //
  38. // Rev 1.1 28 Apr 1996 20:34:50 BECHOLS
  39. //
  40. // Removed IFDEF -- RTP_HEADER.
  41. //
  42. // Rev 1.0 22 Apr 1996 17:47:54 BECHOLS
  43. // Initial revision.
  44. //
  45. // Rev 1.3 10 Apr 1996 13:32:08 CZHU
  46. //
  47. // Moved testing packet loss into this module for common use by encoder or dec
  48. //
  49. // Rev 1.2 29 Mar 1996 14:45:06 CZHU
  50. //
  51. // Rev 1.1 29 Mar 1996 14:39:34 CZHU
  52. // Some cleaning
  53. //
  54. // Rev 1.0 29 Mar 1996 13:32:42 CZHU
  55. // Initial revision.
  56. //
  57. */
  58. #include "precomp.h"
  59. const int MAX_RATE = 2*1024*1024 ;//set this limit for now
  60. I32 H263RTP_VerifyBsInfoStream(
  61. T_H263DecoderCatalog *DC,
  62. U8 *pu8Src,
  63. U32 uSize
  64. )
  65. {
  66. T_H263_RTP_BSINFO_TRAILER *pBsTrailer;
  67. T_RTP_H263_BSINFO *pBsInfo;
  68. int i;
  69. int iRet = FALSE;
  70. FX_ENTRY("H263RTP_VerifyBsInfoStream")
  71. ASSERT(!DC->iVerifiedBsExt);
  72. DC->iVerifiedBsExt=TRUE;
  73. pBsTrailer =(T_H263_RTP_BSINFO_TRAILER *)(pu8Src + uSize);
  74. pBsTrailer--;
  75. DEBUGMSG (ZONE_DECODE_RTP, ("%s: StartCode = %8ld, CompSize=%8ld, No.Pack=%4ld, SRC=%4d, TR=%4d, TRB=%4d, DBQ=%2d\r\n", _fx_, pBsTrailer->uUniqueCode, pBsTrailer->uCompressedSize, pBsTrailer->uNumOfPackets, pBsTrailer->u8Src, pBsTrailer->u8TR,pBsTrailer->u8TRB,pBsTrailer->u8DBQ));
  76. if (pBsTrailer->uUniqueCode != H263_RTP_BS_START_CODE)
  77. {
  78. //#ifdef LOSS_RECOVERY
  79. DEBUGMSG (ZONE_DECODE_RTP, ("%s: No RTP BS Extension found\r\n", _fx_));
  80. DC->iValidBsExt = FALSE;
  81. DC->uNumOfPackets = 0;
  82. DC->pBsInfo = NULL;
  83. DC->pBsTrailer = NULL;
  84. //#endif
  85. return FALSE;
  86. }
  87. //bitstream is valid, so...
  88. pBsInfo = (T_RTP_H263_BSINFO *)pBsTrailer;
  89. pBsInfo -= pBsTrailer->uNumOfPackets;
  90. //#ifdef LOSS_RECOVERY
  91. DC->pBsTrailer = (void *)pBsTrailer;
  92. DC->uNumOfPackets = pBsTrailer->uNumOfPackets;
  93. DC->iValidBsExt =TRUE;
  94. DC->pBsInfo = (void *)pBsInfo;
  95. //#endif
  96. for (i=0; i< (int)pBsTrailer->uNumOfPackets; i++)
  97. {
  98. DEBUGMSG (ZONE_DECODE_RTP, ("%s: uFlag =%2d,BitOffset=%8d, Mode=%2d, MBA=%4d, uQuant=%2d,GOBN=%2d\r\n", _fx_, pBsInfo->uFlags, pBsInfo->uBitOffset, pBsInfo->u8Mode, pBsInfo->u8MBA, pBsInfo->u8Quant, pBsInfo->u8GOBN));
  99. pBsInfo++;
  100. }
  101. return TRUE;
  102. }
  103. //#ifdef LOSS_RECOVERY
  104. void RtpForcePacketLoss(
  105. U8 * pDst,
  106. U32 uExtSize,
  107. U32 uLossNum)
  108. {
  109. T_H263_RTP_BSINFO_TRAILER *pTrailer;
  110. T_RTP_H263_BSINFO *pBsInfo, *pBsInfoNext;
  111. U32 uNum;
  112. // U32 uDelta,u, U32 uToCopy;
  113. U8 * ptr;
  114. U8 mask[]={0, 0x80, 0xc0, 0xe0, 0xf0,0xf8,0xfc,0xfe};
  115. //throw away packet number uPNum packet
  116. pTrailer =(T_H263_RTP_BSINFO_TRAILER *)(pDst+uExtSize);
  117. pTrailer--;
  118. if (pTrailer->uUniqueCode != H263_RTP_BS_START_CODE)
  119. {
  120. goto ret;
  121. }
  122. pBsInfo = (T_RTP_H263_BSINFO *)pTrailer;
  123. pBsInfo -= pTrailer->uNumOfPackets; //point at the beginning of the BS_INFO
  124. for (uNum =0; uNum < pTrailer->uNumOfPackets-1; uNum++)
  125. { pBsInfoNext = pBsInfo+1; //exclude the last packet
  126. // if (pBsInfoNext->u8Mode == RTP_H263_MODE_B)
  127. if (uNum == uLossNum)
  128. {
  129. pBsInfo->uFlags |= RTP_H26X_PACKET_LOST;
  130. ptr = (U8 *)(pDst + (pBsInfo->uBitOffset)/8);
  131. *ptr = *ptr & mask[pBsInfo->uBitOffset % 8];
  132. if ( pBsInfo->uBitOffset % 8) ptr++;
  133. *ptr++ = 0; //add dword of 0
  134. *ptr++ = 0;
  135. if (uNum)
  136. {
  137. *ptr++ = 0;
  138. *ptr++ = 0;
  139. }
  140. else
  141. {//first packet with PSC
  142. *ptr++ = 128;
  143. *ptr++ =3;
  144. }
  145. break;
  146. }
  147. pBsInfo++;
  148. }
  149. ret:
  150. return;
  151. }
  152. /////////////////////////////////////////////////////////
  153. // return the size of memory used for bitstream extension
  154. // rate up limit set to 1MB for now.
  155. // Chad, 9/13/96
  156. /////////////////////////////////////////////////////////
  157. DWORD getRTPBsInfoSize(LPCODINST lpInst)
  158. {
  159. FX_ENTRY("getRTPBsInfoSize");
  160. DWORD dwExtSize = 1024UL;
  161. DWORD dwNumGOBs;
  162. DWORD dwNumPacketsPerGOB;
  163. // Get the max number of GOBs
  164. dwNumGOBs = (lpInst->FrameSz == SQCIF) ? 6 : (lpInst->FrameSz == QCIF) ? 9 : (lpInst->FrameSz == QCIF) ? 18 : 0;
  165. // Assume there will be at least one header per GOB - worse case
  166. // Double estimated size to be safe
  167. if ((lpInst->FrameRate != 0.0f) && dwNumGOBs && lpInst->Configuration.unPacketSize)
  168. {
  169. dwNumPacketsPerGOB = (DWORD)(lpInst->DataRate / lpInst->FrameRate) / dwNumGOBs / lpInst->Configuration.unPacketSize + 1;
  170. dwExtSize = (DWORD)(dwNumPacketsPerGOB * dwNumGOBs * sizeof(T_RTP_H263_BSINFO) + sizeof(T_H263_RTP_BSINFO_TRAILER)) << 1;
  171. }
  172. return (dwExtSize);
  173. }
  174. //#endif