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.

209 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. ** All Rights Reserved.
  11. **
  12. ** *************************************************************************
  13. */
  14. /*****************************************************************************
  15. *
  16. * d3gob.cpp
  17. *
  18. * Description:
  19. * This modules contains the GOB header support routines
  20. *
  21. * Routines:
  22. * H263SetGOBHeaderInfo
  23. *
  24. * Data:
  25. */
  26. /*
  27. * $Header: S:\h26x\src\dec\d3gob.cpv 1.13 20 Oct 1996 15:51:00 AGUPTA2 $
  28. * $Log: S:\h26x\src\dec\d3gob.cpv $
  29. //
  30. // Rev 1.13 20 Oct 1996 15:51:00 AGUPTA2
  31. // Adjusted DbgLog trace levels; 4:Frame, 5:GOB, 6:MB, 8:everything
  32. //
  33. // Rev 1.12 20 Oct 1996 13:21:00 AGUPTA2
  34. // Changed DBOUT into DbgLog. ASSERT is not changed to DbgAssert.
  35. //
  36. //
  37. // Rev 1.11 03 May 1996 13:07:26 CZHU
  38. //
  39. // Remove assertion of GOB number because of packet loss
  40. //
  41. // Rev 1.10 28 Apr 1996 17:34:12 BECHOLS
  42. // Fixed warning due to iLength declaration. This variable was only used
  43. // by a piece of code that was wrapped with IFDEF DEBUG_GOB, so I wrapped
  44. // it with the same define.
  45. //
  46. // Rev 1.9 08 Mar 1996 16:46:14 AGUPTA2
  47. // Changed defines to const int declarations. Added pragmas code_seg and
  48. // data_seg. ifdef'd wsprintf call.
  49. //
  50. //
  51. // Rev 1.8 27 Dec 1995 14:36:04 RMCKENZX
  52. // Added copyright notice
  53. */
  54. #include "precomp.h"
  55. /* BIT field Constants
  56. */
  57. #define BITS_GOB_STARTCODE 17
  58. #define BITS_GROUP_NUMBER 5
  59. #define BITS_GFID 2
  60. #define BITS_GQUANT 5
  61. #define MAX_GBSC_LOOKAHEAD_NUMBER 7
  62. /* GBSC_VALUE - 0000 0000 0000 0000 - 1xxx xxxx xxxx xxxx
  63. */
  64. #define GBSC_VALUE (0x00008000 >> (32-BITS_GOB_STARTCODE))
  65. /*****************************************************************************
  66. *
  67. * H263DecodeGOBHeader
  68. *
  69. * Set the GOB header information in the decoder catalog. GOB numbers 2 thru
  70. * N may have a GOB header. Look for one if it is there read it storing the
  71. * information in the catalog. If a GOB header is not there set the information
  72. * to default values.
  73. *
  74. * Returns an ICERR_STATUS
  75. */
  76. #pragma data_seg("IADATA1")
  77. #pragma code_seg("IACODE1")
  78. extern I32 H263DecodeGOBHeader(
  79. T_H263DecoderCatalog FAR * DC,
  80. BITSTREAM_STATE FAR * fpbsState,
  81. U32 uAssumedGroupNumber)
  82. {
  83. U8 FAR * fpu8;
  84. U32 uBitsReady = 0;
  85. U32 uWork = 0;
  86. I32 iReturn;
  87. U32 uResult;
  88. int iLookAhead;
  89. U32 uData;
  90. FX_ENTRY("H263DecodeGOBHeader")
  91. // Decrement group number since the standard counts from 0
  92. // but this decoder counts from 1.
  93. --uAssumedGroupNumber;
  94. DC->bGOBHeaderPresent=0;
  95. if (uAssumedGroupNumber == 0) {
  96. // Initialize the flag
  97. DC->bFoundGOBFrameID = 0;
  98. }
  99. else
  100. {
  101. // Look for the GOB header Start Code
  102. GET_BITS_RESTORE_STATE(fpu8, uWork, uBitsReady, fpbsState)
  103. GET_FIXED_BITS((U32) BITS_GOB_STARTCODE, fpu8, uWork, uBitsReady,
  104. uResult);
  105. iLookAhead = 0;
  106. while (uResult != GBSC_VALUE)
  107. {
  108. uResult = uResult << 1;
  109. uResult &= GetBitsMask[BITS_GOB_STARTCODE];
  110. GET_ONE_BIT(fpu8, uWork, uBitsReady, uData);
  111. uResult |= uData;
  112. iLookAhead++;
  113. if (iLookAhead >= MAX_GBSC_LOOKAHEAD_NUMBER) {
  114. break; // only look ahead so far
  115. }
  116. }
  117. if (uResult == GBSC_VALUE)
  118. {
  119. DC->bGOBHeaderPresent=1;
  120. }
  121. }
  122. if (DC->bGOBHeaderPresent)
  123. {
  124. // GN
  125. GET_FIXED_BITS((U32) BITS_GROUP_NUMBER, fpu8, uWork, uBitsReady,
  126. uResult);
  127. // ASSERT(uResult == uAssumedGroupNumber);
  128. DC->uGroupNumber = uResult;
  129. /* I am assuming that GOB numbers start at 1 because if it starts at
  130. * zero it makes the GOB start code look like a picture start code.
  131. * Correction by TRG: GOB numbers start at 0, but there can't be a
  132. * GOB header for the 0th GOB.
  133. */
  134. // ASSERT(DC->uGroupNumber > 0);
  135. if (DC->uGroupNumber == 0)
  136. {
  137. ERRORMESSAGE(("%s: There can't be a GOB header for the 0th GOB\r\n", _fx_));
  138. iReturn = ICERR_ERROR;
  139. goto done;
  140. }
  141. // GLCI
  142. if (DC->bCPM)
  143. {
  144. ERRORMESSAGE(("%s: CPM is not supported\r\n", _fx_));
  145. iReturn = ICERR_ERROR;
  146. goto done;
  147. }
  148. // GFID
  149. GET_FIXED_BITS((U32) BITS_GFID, fpu8, uWork, uBitsReady, uResult);
  150. if (DC->bFoundGOBFrameID)
  151. {
  152. if (uResult != DC->uGOBFrameID)
  153. {
  154. ERRORMESSAGE(("%s: GOBFrameID mismatch\r\n", _fx_));
  155. iReturn = ICERR_ERROR;
  156. goto done;
  157. }
  158. /* Should we also check it against the GOBFrameID of the previous
  159. * picture when the PTYPE has not changed?
  160. */
  161. }
  162. DC->uGOBFrameID = uResult;
  163. DC->bFoundGOBFrameID = 1;
  164. // GQUANT
  165. GET_FIXED_BITS((U32) BITS_GQUANT, fpu8, uWork, uBitsReady, uResult);
  166. DC->uGQuant = uResult;
  167. DC->uPQuant = uResult;
  168. // Save the modified bitstream state
  169. GET_BITS_SAVE_STATE(fpu8, uWork, uBitsReady, fpbsState)
  170. }
  171. else
  172. {
  173. // We can only assume
  174. DC->uGroupNumber = uAssumedGroupNumber;
  175. /* If we already found the GOBFrameID leave it alone. Otherwise
  176. * clear it using a value indicating that it is not valid.
  177. */
  178. if (! DC->bFoundGOBFrameID)
  179. DC->uGOBFrameID = 12345678;
  180. // Default the group Quantization to the picture Quant
  181. DC->uGQuant = DC->uPQuant;
  182. }
  183. DEBUGMSG(ZONE_DECODE_GOB_HEADER, (" %s: HeaderPresent=%ld GN=%ld GFID=%ld GQ=%ld\r\n", _fx_, DC->bGOBHeaderPresent, DC->uGroupNumber, DC->uGOBFrameID, DC->uGQuant));
  184. iReturn = ICERR_OK;
  185. done:
  186. return iReturn;
  187. } /* end H263DecodeGOBHeader() */
  188. #pragma code_seg()