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.

192 lines
6.7 KiB

  1. /* File: sv_h263_gethdr.c */
  2. /*****************************************************************************
  3. ** Copyright (c) Digital Equipment Corporation, 1995, 1997 **
  4. ** **
  5. ** All Rights Reserved. Unpublished rights reserved under the copyright **
  6. ** laws of the United States. **
  7. ** **
  8. ** The software contained on this media is proprietary to and embodies **
  9. ** the confidential technology of Digital Equipment Corporation. **
  10. ** Possession, use, duplication or dissemination of the software and **
  11. ** media is authorized only pursuant to a valid written license from **
  12. ** Digital Equipment Corporation. **
  13. ** **
  14. ** RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by the U.S. **
  15. ** Government is subject to restrictions as set forth in Subparagraph **
  16. ** (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable. **
  17. ******************************************************************************/
  18. /*
  19. #define _SLIBDEBUG_
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include "sv_h263.h"
  24. #include "sv_intrn.h"
  25. #include "SC_err.h"
  26. #include "proto.h"
  27. #ifdef _SLIBDEBUG_
  28. #include "sc_debug.h"
  29. #define _DEBUG_ 0 /* detailed debuging statements */
  30. #define _VERBOSE_ 1 /* show progress */
  31. #define _VERIFY_ 0 /* verify correct operation */
  32. #define _WARN_ 1 /* warnings about strange behavior */
  33. void *dbg=NULL;
  34. #endif
  35. /* private prototypes */
  36. static void getpicturehdr(SvH263DecompressInfo_t *H263Info, ScBitstream_t *BSIn);
  37. /*
  38. * decode headers from one input stream
  39. * until an End of Sequence or picture start code
  40. * is found
  41. */
  42. SvStatus_t sv_H263GetHeader(SvH263DecompressInfo_t *H263Info, ScBitstream_t *BSIn, int *pgob)
  43. {
  44. unsigned int code, gob;
  45. _SlibDebug(_VERBOSE_, ScDebugPrintf(H263Info->dbg, "sv_H263GetHeader() In: bytespos=%ld, EOI=%d\n",
  46. ScBSBytePosition(BSIn), BSIn->EOI) );
  47. #ifdef _SLIBDEBUG_
  48. dbg=H263Info->dbg;
  49. #endif
  50. /* look for startcode */
  51. if (sv_H263StartCode(BSIn)!=SvErrorNone)
  52. return(SvErrorEndBitstream);
  53. code = (unsigned int)ScBSGetBits(BSIn, H263_PSC_LENGTH);
  54. gob = (unsigned int)ScBSGetBits(BSIn, 5);
  55. if (gob == H263_SE_CODE)
  56. return 0;
  57. if (gob == 0) {
  58. getpicturehdr(H263Info, BSIn);
  59. if (H263Info->syntax_arith_coding) /* reset decoder after receiving */
  60. sv_H263SACDecoderReset(BSIn); /* fixed length PSC string */
  61. }
  62. if (pgob)
  63. *pgob=gob;
  64. _SlibDebug(_VERBOSE_, ScDebugPrintf(H263Info->dbg, "sv_H263GetHeader() Out: bytespos=%ld, EOI=%d, gob=%d\n",
  65. ScBSBytePosition(BSIn), BSIn->EOI, gob) );
  66. return(SvErrorNone); /* return gob + 1; */
  67. }
  68. /* align to start of next startcode */
  69. SvStatus_t sv_H263StartCode(ScBitstream_t *BSIn)
  70. {
  71. _SlibDebug(_VERBOSE_, ScDebugPrintf(dbg, "sv_H263StartCode() In: bytespos=%ld, EOI=%d\n",
  72. ScBSBytePosition(BSIn), BSIn->EOI) );
  73. /* search for new picture start code */
  74. while (ScBSPeekBits(BSIn, H263_PSC_LENGTH)!=1l && !BSIn->EOI)
  75. ScBSSkipBit(BSIn);
  76. _SlibDebug(_VERBOSE_, ScDebugPrintf(dbg, "sv_H263StartCode() Out: bytespos=%ld, EOI=%d\n",
  77. ScBSBytePosition(BSIn), BSIn->EOI) );
  78. if (BSIn->EOI) return(SvErrorEndBitstream);
  79. return(SvErrorNone);
  80. }
  81. /* decode picture header */
  82. static void getpicturehdr(SvH263DecompressInfo_t *H263Info, ScBitstream_t *BSIn)
  83. {
  84. ScBSPosition_t pos;
  85. int pei, tmp;
  86. static int prev_temp_ref; /* Burkhard */
  87. pos = ScBSBitPosition(BSIn);
  88. prev_temp_ref = H263Info->temp_ref;
  89. H263Info->temp_ref = (int)ScBSGetBits(BSIn, 8);
  90. H263Info->trd = (int)H263Info->temp_ref - prev_temp_ref;
  91. if (H263Info->trd < 0)
  92. H263Info->trd += 256;
  93. tmp = ScBSGetBit(BSIn); /* always "1" */
  94. if (!tmp)
  95. if (!H263Info->quiet)
  96. printf("warning: spare in picture header should be \"1\"\n");
  97. tmp = ScBSGetBit(BSIn); /* always "0" */
  98. if (tmp)
  99. if (!H263Info->quiet)
  100. printf("warning: H.261 distinction bit should be \"0\"\n");
  101. tmp = ScBSGetBit(BSIn);
  102. if (tmp) {
  103. if (!H263Info->quiet)
  104. printf("error: split-screen not supported in this version\n");
  105. exit (-1);
  106. }
  107. tmp = ScBSGetBit(BSIn); /* document_camera_indicator */
  108. if (tmp)
  109. if (!H263Info->quiet)
  110. printf("warning: document camera indicator not supported in this version\n");
  111. tmp = ScBSGetBit(BSIn); /* freeze_picture_release */
  112. if (tmp)
  113. if (!H263Info->quiet)
  114. printf("warning: frozen picture not supported in this version\n");
  115. H263Info->source_format = (int)ScBSGetBits(BSIn, 3);
  116. H263Info->pict_type = ScBSGetBit(BSIn);
  117. H263Info->mv_outside_frame = ScBSGetBit(BSIn);
  118. H263Info->long_vectors = (H263Info->mv_outside_frame ? 1 : 0);
  119. H263Info->syntax_arith_coding = ScBSGetBit(BSIn);
  120. H263Info->adv_pred_mode = ScBSGetBit(BSIn);
  121. H263Info->mv_outside_frame = (H263Info->adv_pred_mode ? 1 : H263Info->mv_outside_frame);
  122. H263Info->pb_frame = ScBSGetBit(BSIn);
  123. H263Info->quant = (int)ScBSGetBits(BSIn, 5);
  124. tmp = ScBSGetBit(BSIn);
  125. if (tmp) {
  126. if (!H263Info->quiet)
  127. printf("error: CPM not supported in this version\n");
  128. exit(-1);
  129. }
  130. if (H263Info->pb_frame) {
  131. H263Info->trb = (int)ScBSGetBits(BSIn, 3);
  132. H263Info->bquant = (int)ScBSGetBits(BSIn, 2);
  133. }
  134. /* Burkhard
  135. else {
  136. trb = 0;
  137. }
  138. */
  139. pei = ScBSGetBit(BSIn);
  140. pspare:
  141. if (pei) {
  142. /* extra info for possible future backward compatible additions */
  143. ScBSGetBits(BSIn, 8); /* not used */
  144. pei = ScBSGetBit(BSIn);
  145. if (pei) goto pspare; /* keep on reading pspare until pei=0 */
  146. }
  147. _SlibDebug(_VERBOSE_,
  148. ScDebugPrintf(dbg, "******picture header (byte %d)******\n",(pos>>3)-4);
  149. ScDebugPrintf(dbg, " temp_ref=%d\n",H263Info->temp_ref);
  150. ScDebugPrintf(dbg, " pict_type=%d\n",H263Info->pict_type);
  151. ScDebugPrintf(dbg, " source_format=%d\n", H263Info->source_format);
  152. ScDebugPrintf(dbg, " quant=%d\n",H263Info->quant);
  153. if (H263Info->syntax_arith_coding)
  154. ScDebugPrintf(dbg, " SAC coding mode used \n");
  155. if (H263Info->mv_outside_frame)
  156. ScDebugPrintf(dbg, " unrestricted motion vector mode used\n");
  157. if (H263Info->adv_pred_mode)
  158. ScDebugPrintf(dbg, " advanced prediction mode used\n");
  159. if (H263Info->pb_frame)
  160. {
  161. ScDebugPrintf(dbg, " pb-frames mode used\n");
  162. ScDebugPrintf(dbg, " trb=%d\n",H263Info->trb);
  163. ScDebugPrintf(dbg, " bquant=%d\n", H263Info->bquant);
  164. }
  165. );
  166. }