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.

263 lines
7.3 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\d1rtp.cpv 1.3 24 Jan 1997 17:10:04 RHAZRA $
  15. // $Log: S:\h26x\src\dec\d1rtp.cpv $
  16. //
  17. // Rev 1.3 24 Jan 1997 17:10:04 RHAZRA
  18. // Since the PPM now fills in 0 for QCIF, 1 for CIF and 2 for unknown
  19. // in the trailer's source format field, we now check for the unknown
  20. // format and bug out.
  21. //
  22. // Rev 1.2 10 Sep 1996 15:53:52 RHAZRA
  23. // Added code to return motion vector predictor in RtpFindNextPacket().
  24. //
  25. // Rev 1.1 04 Sep 1996 09:47:24 RHAZRA
  26. // No change.
  27. //
  28. // Rev 1.0 21 Aug 1996 18:35:34 RHAZRA
  29. // Initial revision.
  30. //
  31. // Rev 1.4 23 Jul 1996 11:22:16 CZHU
  32. //
  33. // Added a MV recovery. Hursitic will be added in later.
  34. //
  35. // Rev 1.3 15 Jul 1996 16:22:42 CZHU
  36. // Added checking bitstream extension when PSC is lost.
  37. //
  38. // Rev 1.2 03 May 1996 13:04:22 CZHU
  39. // Change logic such that bitstream verification is invoked only when bit erro
  40. // is encountered.
  41. //
  42. // Rev 1.1 28 Apr 1996 21:18:58 BECHOLS
  43. // Removed ifdef RTP_HEADER.
  44. //
  45. // Rev 1.0 22 Apr 1996 17:47:08 BECHOLS
  46. // Initial revision.
  47. //
  48. // Rev 1.7 10 Apr 1996 13:35:58 CZHU
  49. //
  50. // Added subroutine to recover picture header information from extended bitstr
  51. //
  52. // Rev 1.6 29 Mar 1996 14:39:56 CZHU
  53. //
  54. // cleaning
  55. //
  56. // Rev 1.5 29 Mar 1996 13:39:16 CZHU
  57. //
  58. // Moved bs verification to c3rtp.cpp
  59. //
  60. // Rev 1.4 28 Mar 1996 18:40:28 CZHU
  61. // Support packet loss recovery
  62. //
  63. // Rev 1.3 23 Feb 1996 16:21:22 CZHU
  64. // No change.
  65. //
  66. // Rev 1.2 15 Feb 1996 12:01:50 CZHU
  67. //
  68. // More clean up
  69. //
  70. // Rev 1.1 14 Feb 1996 15:00:10 CZHU
  71. // Added support Mode A and Mode B
  72. //
  73. // Rev 1.0 12 Feb 1996 17:05:56 CZHU
  74. // Initial revision.
  75. //
  76. // Rev 1.2 25 Jan 1996 16:13:54 CZHU
  77. // changed name to the spec
  78. //
  79. // Rev 1.1 15 Dec 1995 13:07:30 CZHU
  80. //
  81. //
  82. //
  83. // Rev 1.0 11 Dec 1995 14:54:22 CZHU
  84. // Initial revision.
  85. */
  86. #include "precomp.h"
  87. /*
  88. * RtpH263FindNextPacket() look through the extended bitstream and
  89. * find the next BITSTREAM_INFO structure that point to a valid packet
  90. * return indicates what mode the next packet is in mode A, or mode B,
  91. * mode C is not supported at this point.Chad, 3/28/96
  92. *
  93. */
  94. I32 RtpH261FindNextPacket( //DC, fpbsState, &pN, fpMBInfo, &uNewMB, &uNewGOB)
  95. T_H263DecoderCatalog FAR * DC,
  96. BITSTREAM_STATE FAR * fpbsState,
  97. U32 **pN,
  98. U32 *pQuant,
  99. int *pMB,
  100. int *pGOB
  101. )
  102. { I32 iret=ICERR_OK;
  103. //#ifdef LOSS_RECOVERY
  104. U32 u;
  105. U32 uBitOffset;
  106. U32 uBitstream = (U32)((U32)DC + DC->X32_BitStream);
  107. T_RTP_H261_BSINFO *pBsInfo;
  108. U32 mask[]={0xff,0x7f, 0x3f, 0x1f,0x0f, 0x07, 0x03,0x01};
  109. //verify bitstream extension first
  110. if (!DC->iVerifiedBsExt)
  111. H26XRTP_VerifyBsInfoStream(DC,(U8 *)((U8 *)DC + DC->X32_BitStream),DC->Sz_BitStream);
  112. if (!DC->iValidBsExt) {
  113. iret=ICERR_UNSUPPORTED;
  114. goto done;
  115. }
  116. uBitOffset = ((U32)fpbsState->fpu8 - uBitstream)*8 - 8 + fpbsState->uBitsReady;
  117. //travser through the BITSTREAM_INFO to find the next PACKET.
  118. //update pNewMB and pNewGOB if succeed, return Ok otherwise return error
  119. pBsInfo=(T_RTP_H261_BSINFO*)DC->pBsInfo;
  120. for ( u=0; u<DC->uNumOfPackets;u++)
  121. {
  122. if (!(pBsInfo->uFlags & RTP_H26X_PACKET_LOST))
  123. {
  124. if (uBitOffset < pBsInfo->uBitOffset) break;
  125. }
  126. pBsInfo++;
  127. }
  128. //find it?
  129. if (u<DC->uNumOfPackets) //find next packet
  130. {
  131. if (pBsInfo->u8Quant == 0)
  132. { //adjust bit stream pointer according to received packet
  133. fpbsState->fpu8 = (U8 *)(uBitstream + pBsInfo->uBitOffset /8 );
  134. fpbsState->uBitsReady = 8 - pBsInfo->uBitOffset % 8;
  135. if (fpbsState->uBitsReady)
  136. {
  137. fpbsState->uWork =(U32)*fpbsState->fpu8++;
  138. fpbsState->uWork &= mask[8- fpbsState->uBitsReady];
  139. }
  140. else
  141. fpbsState->uWork =0;
  142. //update m, g, MV in fpBlockAction, fpMBInfo for block type
  143. *pGOB = pBsInfo->u8GOBN;
  144. *pMB = pBsInfo->u8MBA;
  145. *pQuant = pBsInfo->u8Quant;
  146. DC->i8MVDH = pBsInfo->i8HMV;
  147. DC->i8MVDV = pBsInfo->i8VMV;
  148. iret = NEXT_MODE_STARTS_GOB;
  149. }
  150. else //read Quant, GOB, MBA, MVs, from Payload Header
  151. {
  152. //update m, g, MV in fpBlockAction, fpMBInfo for block type
  153. *pGOB = pBsInfo->u8GOBN;
  154. *pMB = pBsInfo->u8MBA;
  155. *pQuant = pBsInfo->u8Quant;
  156. DC->i8MVDH = pBsInfo->i8HMV;
  157. DC->i8MVDV = pBsInfo->i8VMV;
  158. //update the bit pointer and offset
  159. fpbsState->fpu8 = (U8 *)(uBitstream + pBsInfo->uBitOffset / 8 );
  160. fpbsState->uBitsReady = 8 - pBsInfo->uBitOffset % 8;
  161. if (fpbsState->uBitsReady)
  162. {
  163. fpbsState->uWork =(U32)*fpbsState->fpu8++;
  164. fpbsState->uWork &= mask[8- fpbsState->uBitsReady];
  165. }
  166. else
  167. fpbsState->uWork =0;
  168. iret = NEXT_MODE_STARTS_MB;
  169. //file MV indexed by fpBlockAction,
  170. }
  171. }
  172. else // no more valid packet in this frame
  173. { // need to set all the rest of MB to be not coded
  174. iret = NEXT_MODE_LAST;
  175. }
  176. done:
  177. //#endif
  178. return iret;
  179. }
  180. /*
  181. * Use the extended bitstream to get the information lost
  182. * in the picture header
  183. */
  184. I32 RtpGetPicHeaderFromBsExt(T_H263DecoderCatalog FAR * DC)
  185. {I32 iret = ICERR_OK;
  186. //#ifdef LOSS_RECOVERY
  187. T_H26X_RTP_BSINFO_TRAILER *pTrailer;
  188. if (!DC->iVerifiedBsExt)
  189. {
  190. H26XRTP_VerifyBsInfoStream(DC,(U8 *)((U8 *)DC + DC->X32_BitStream),DC->Sz_BitStream);
  191. }
  192. if (!DC->iValidBsExt) {
  193. iret=ICERR_UNSUPPORTED;
  194. goto done;
  195. }
  196. pTrailer = ( T_H26X_RTP_BSINFO_TRAILER *)DC->pBsTrailer;
  197. //update DC info for Pict header.Src, INTRA, TR, etc.
  198. DC->uTempRef = pTrailer->u8TR;
  199. // PPM writes 0 for QCIF and 1 for CIF
  200. ASSERT ( (pTrailer->u8Src != 2) )
  201. ASSERT ( (pTrailer->u8Src >= 0) && (pTrailer->u8Src < 2) )
  202. if (pTrailer->u8Src == 2) { // PPM indicates a bad format using 2
  203. iret = ICERR_UNSUPPORTED;
  204. goto done;
  205. }
  206. DC->uSrcFormat = pTrailer->u8Src;
  207. DC->bFreezeRelease = 0;
  208. DC->bCameraOn = 0;
  209. DC->bSplitScreen = 0;
  210. DC->bKeyFrame = (U16) (pTrailer->uFlags & RTP_H26X_INTRA_CODED) ;//(U16) !uResult;
  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. } */