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.

260 lines
7.4 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\dec\d3rtp.cpv 1.6 06 Nov 1996 15:23:02 CZHU $
  15. // $Log: S:\h26x\src\dec\d3rtp.cpv $
  16. //
  17. // Rev 1.6 06 Nov 1996 15:23:02 CZHU
  18. //
  19. // Returning MVs in FindNextPacket()
  20. //
  21. // Rev 1.5 03 Nov 1996 18:41:40 gmlim
  22. // Modified RTPH263FindNextPacket() to support mode c.
  23. //
  24. // Rev 1.4 23 Jul 1996 11:22:16 CZHU
  25. //
  26. // Added a MV recovery. Hursitic will be added in later.
  27. //
  28. // Rev 1.3 15 Jul 1996 16:22:42 CZHU
  29. // Added checking bitstream extension when PSC is lost.
  30. //
  31. // Rev 1.2 03 May 1996 13:04:22 CZHU
  32. // Change logic such that bitstream verification is invoked only when bit erro
  33. // is encountered.
  34. //
  35. // Rev 1.1 28 Apr 1996 21:18:58 BECHOLS
  36. // Removed ifdef RTP_HEADER.
  37. //
  38. // Rev 1.0 22 Apr 1996 17:47:08 BECHOLS
  39. // Initial revision.
  40. //
  41. // Rev 1.7 10 Apr 1996 13:35:58 CZHU
  42. //
  43. // Added subroutine to recover picture header information from extended bitstr
  44. //
  45. // Rev 1.6 29 Mar 1996 14:39:56 CZHU
  46. //
  47. // cleaning
  48. //
  49. // Rev 1.5 29 Mar 1996 13:39:16 CZHU
  50. //
  51. // Moved bs verification to c3rtp.cpp
  52. //
  53. // Rev 1.4 28 Mar 1996 18:40:28 CZHU
  54. // Support packet loss recovery
  55. //
  56. // Rev 1.3 23 Feb 1996 16:21:22 CZHU
  57. // No change.
  58. //
  59. // Rev 1.2 15 Feb 1996 12:01:50 CZHU
  60. //
  61. // More clean up
  62. //
  63. // Rev 1.1 14 Feb 1996 15:00:10 CZHU
  64. // Added support Mode A and Mode B
  65. //
  66. // Rev 1.0 12 Feb 1996 17:05:56 CZHU
  67. // Initial revision.
  68. //
  69. // Rev 1.2 25 Jan 1996 16:13:54 CZHU
  70. // changed name to the spec
  71. //
  72. // Rev 1.1 15 Dec 1995 13:07:30 CZHU
  73. //
  74. //
  75. //
  76. // Rev 1.0 11 Dec 1995 14:54:22 CZHU
  77. // Initial revision.
  78. */
  79. #include "precomp.h"
  80. /*
  81. * RtpH263FindNextPacket() look through the extended bitstream and
  82. * find the next BITSTREAM_INFO structure that point to a valid packet
  83. * return indicates what mode the next packet is in mode A, or mode B,
  84. * mode C is not supported at this point.Chad, 3/28/96
  85. *
  86. * Mode C is supported now. And a special case LAST packet is lost is also
  87. * covered. Chad, 11/6/96
  88. *
  89. */
  90. I32 RtpH263FindNextPacket( //DC, fpbsState, &pN, fpMBInfo, &uNewMB, &uNewGOB)
  91. T_H263DecoderCatalog FAR * DC,
  92. BITSTREAM_STATE FAR * fpbsState,
  93. U32 **pN,
  94. U32 *pQuant,
  95. int *pMB,
  96. int *pGOB,
  97. I8 MVs[4]
  98. )
  99. { I32 iret=ICERR_OK;
  100. //#ifdef LOSS_RECOVERY
  101. U32 u;
  102. U32 uBitOffset;
  103. U32 uBitstream = (U32)((U32)DC + DC->X32_BitStream);
  104. T_RTP_H263_BSINFO *pBsInfo;
  105. U32 mask[]={0xff,0x7f, 0x3f, 0x1f,0x0f, 0x07, 0x03,0x01};
  106. //verify bitstream extension first
  107. if (!DC->iVerifiedBsExt)
  108. H263RTP_VerifyBsInfoStream(DC,(U8 *)((U8 *)DC + DC->X32_BitStream),DC->Sz_BitStream);
  109. if (!DC->iValidBsExt) {
  110. iret=ICERR_UNSUPPORTED;
  111. goto done;
  112. }
  113. uBitOffset = ((U32)fpbsState->fpu8 - uBitstream)*8 - 8 + fpbsState->uBitsReady;
  114. //travser through the BITSTREAM_INFO to find the next PACKET.
  115. //update pNewMB and pNewGOB if succeed, return Ok otherwise return error
  116. pBsInfo=(T_RTP_H263_BSINFO*)DC->pBsInfo;
  117. for ( u=0; u<DC->uNumOfPackets;u++)
  118. {
  119. if (!(pBsInfo->uFlags & RTP_H26X_PACKET_LOST))
  120. {
  121. if (uBitOffset < pBsInfo->uBitOffset) break;
  122. }
  123. pBsInfo++;
  124. }
  125. //find it?
  126. if (u<DC->uNumOfPackets) //find next packet
  127. {
  128. if (pBsInfo->u8Mode == RTP_H263_MODE_A)
  129. { //adjust bit stream pointer according to received packet
  130. fpbsState->fpu8 = (U8 *)(uBitstream + pBsInfo->uBitOffset /8 );
  131. fpbsState->uBitsReady = 8 - pBsInfo->uBitOffset % 8;
  132. if (fpbsState->uBitsReady)
  133. {
  134. fpbsState->uWork =(U32)*fpbsState->fpu8++;
  135. fpbsState->uWork &= mask[8- fpbsState->uBitsReady];
  136. }
  137. else
  138. fpbsState->uWork =0;
  139. //update m, g, MV in fpBlockAction, fpMBInfo for block type
  140. *pGOB = pBsInfo->u8GOBN;
  141. *pMB = pBsInfo->u8MBA;
  142. *pQuant = pBsInfo->u8Quant;
  143. iret = NEXT_MODE_A;
  144. }
  145. else //read Quant, GOB, MBA, MVs, from Payload Header
  146. {
  147. //update m, g, MV in fpBlockAction, fpMBInfo for block type
  148. *pGOB = pBsInfo->u8GOBN;
  149. *pMB = pBsInfo->u8MBA;
  150. *pQuant = pBsInfo->u8Quant;
  151. //update the bit pointer and offset
  152. fpbsState->fpu8 = (U8 *)(uBitstream + pBsInfo->uBitOffset /8 );
  153. fpbsState->uBitsReady = 8 - pBsInfo->uBitOffset % 8;
  154. if (fpbsState->uBitsReady)
  155. {
  156. fpbsState->uWork =(U32)*fpbsState->fpu8++;
  157. fpbsState->uWork &= mask[8- fpbsState->uBitsReady];
  158. }
  159. else
  160. fpbsState->uWork =0;
  161. //recovery MVs depending on AP,
  162. MVs[0] = pBsInfo->i8HMV1;
  163. MVs[1] = pBsInfo->i8VMV1;
  164. MVs[2] = pBsInfo->i8HMV2;
  165. MVs[3] = pBsInfo->i8VMV2;
  166. iret = pBsInfo->u8Mode == RTP_H263_MODE_B ? NEXT_MODE_B :
  167. NEXT_MODE_C;
  168. //file MV indexed by fpBlockAction,
  169. }
  170. }
  171. else // no more valid packet in this frame
  172. { // need to set all the rest of MB to be not coded
  173. iret = NEXT_MODE_LAST;
  174. }
  175. done:
  176. //#endif
  177. return iret;
  178. }
  179. /*
  180. * Use the extended bitstream to get the information lost
  181. * in the picture header
  182. */
  183. I32 RtpGetPicHeaderFromBsExt(T_H263DecoderCatalog FAR * DC)
  184. {I32 iret = ICERR_OK;
  185. //#ifdef LOSS_RECOVERY
  186. T_H263_RTP_BSINFO_TRAILER *pTrailer;
  187. if (!DC->iVerifiedBsExt)
  188. {
  189. H263RTP_VerifyBsInfoStream(DC,(U8 *)((U8 *)DC + DC->X32_BitStream),DC->Sz_BitStream);
  190. }
  191. if (!DC->iValidBsExt) {
  192. iret=ICERR_UNSUPPORTED;
  193. goto done;
  194. }
  195. pTrailer = ( T_H263_RTP_BSINFO_TRAILER *)DC->pBsTrailer;
  196. //update DC info for Pict header.Src, INTRA, TR, etc.
  197. DC->uTempRef = pTrailer->u8TR;
  198. DC->uSrcFormat = pTrailer->u8Src;
  199. DC->bFreezeRelease = 0;
  200. DC->bCameraOn = 0;
  201. DC->bSplitScreen = 0;
  202. DC->bKeyFrame = (U16) (pTrailer->uFlags & RTP_H26X_INTRA_CODED) ;//(U16) !uResult;
  203. //DC->bUnrestrictedMotionVectors = pTrailer->uFlags & ;
  204. DC->bArithmeticCoding = (U16)(pTrailer->uFlags & RTP_H263_SAC);
  205. DC->bAdvancedPrediction = (U16)(pTrailer->uFlags & RTP_H263_AP);
  206. DC->bPBFrame = (U16)(pTrailer->uFlags & RTP_H263_PB);
  207. //Mode C reovery PB related header info.
  208. // to be added for TRB,u8DBQ,
  209. DC->uBFrameTempRef=(U32)pTrailer->u8TRB;
  210. DC->uDBQuant =(U32)pTrailer->u8DBQ;
  211. done:
  212. //#endif
  213. return iret;
  214. }
  215. /*
  216. * MVAdjustment(pBlackAction, iBlock, old_g, old_m, new_g, new_m)
  217. * reuse the motion vector from the GOB above, when current is lost
  218. * EXPERIMENTAL
  219. */
  220. void MVAdjustment(
  221. T_BlkAction *fpBlockAction,
  222. int iBlockNum, //block number
  223. int iOld_gob,
  224. int iOld_mb,
  225. int iNew_gob,
  226. int iNew_mb,
  227. const int iNumberOfMBs
  228. )
  229. { int i,j;
  230. T_BlkAction *pBA=fpBlockAction;
  231. int iAbove = -6 * iNumberOfMBs;
  232. for (i=iOld_gob*iNumberOfMBs+iOld_mb;i<iNew_gob*iNumberOfMBs+iNew_mb; i++,pBA += 6)
  233. {
  234. if ((i+iAbove) >= 0)
  235. for (j=0;j<6;j++)
  236. { pBA[i+j].i8MVx2 = pBA[iAbove+i+j].i8MVx2;
  237. pBA[i+j].i8MVy2 = pBA[iAbove+i+j].i8MVy2;
  238. }
  239. }
  240. return;
  241. }