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.

288 lines
9.5 KiB

  1. /*
  2. * @DEC_COPYRIGHT@
  3. */
  4. /*
  5. * HISTORY
  6. * $Log: sv_h263_common.c,v $
  7. * $EndLog$
  8. */
  9. /*****************************************************************************
  10. ** Copyright (c) Digital Equipment Corporation, 1995, 1997 **
  11. ** **
  12. ** All Rights Reserved. Unpublished rights reserved under the copyright **
  13. ** laws of the United States. **
  14. ** **
  15. ** The software contained on this media is proprietary to and embodies **
  16. ** the confidential technology of Digital Equipment Corporation. **
  17. ** Possession, use, duplication or dissemination of the software and **
  18. ** media is authorized only pursuant to a valid written license from **
  19. ** Digital Equipment Corporation. **
  20. ** **
  21. ** RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by the U.S. **
  22. ** Government is subject to restrictions as set forth in Subparagraph **
  23. ** (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable. **
  24. ******************************************************************************/
  25. /*
  26. #define _SLIBDEBUG_
  27. */
  28. #include "SC_err.h"
  29. #include "sv_h263.h"
  30. #include "sv_intrn.h"
  31. #include "sv_proto.h"
  32. #include "proto.h"
  33. #ifdef WIN32
  34. #include <mmsystem.h>
  35. #endif
  36. #ifdef _SLIBDEBUG_
  37. #define _DEBUG_ 0 /* detailed debuging statements */
  38. #define _VERBOSE_ 0 /* show progress */
  39. #define _VERIFY_ 1 /* verify correct operation */
  40. #define _WARN_ 1 /* warnings about strange behavior */
  41. #endif
  42. SvStatus_t svH263SetParamInt(SvHandle_t Svh, SvParameter_t param,
  43. qword value)
  44. {
  45. SvCodecInfo_t *Info = (SvCodecInfo_t *)Svh;
  46. if (!Svh)
  47. return(SvErrorCodecHandle);
  48. if (Info->mode == SV_H263_DECODE)
  49. switch (param)
  50. {
  51. case SV_PARAM_QUALITY:
  52. if (value>99)
  53. Info->h263dcmp->quality=99;
  54. else if (value<0)
  55. Info->h263dcmp->quality=0;
  56. else
  57. Info->h263dcmp->quality=(int)value;
  58. break;
  59. case SV_PARAM_DEBUG:
  60. Info->h263dcmp->dbg=(void *)value;
  61. break;
  62. }
  63. else if (Info->mode == SV_H263_ENCODE)
  64. switch (param)
  65. {
  66. case SV_PARAM_MOTIONALG:
  67. Info->h263comp->ME_method=(int)value;
  68. return(SvErrorNone);
  69. case SV_PARAM_BITRATE:
  70. if (value>=0)
  71. Info->h263comp->bit_rate = (int)value;
  72. sv_H263UpdateQuality(Info);
  73. break;
  74. case SV_PARAM_QUALITY:
  75. if (value>99)
  76. Info->h263comp->quality=99;
  77. else if (value<0)
  78. Info->h263comp->quality=0;
  79. else
  80. Info->h263comp->quality=(int)value;
  81. sv_H263UpdateQuality(Info);
  82. break;
  83. case SV_PARAM_DEBUG:
  84. Info->h263comp->dbg=(void *)value;
  85. break;
  86. case SV_PARAM_ALGFLAGS:
  87. Info->h263comp->pb_frames = (value&PARAM_ALGFLAG_PB) ? TRUE : FALSE;
  88. Info->h263comp->syntax_arith_coding = (value&PARAM_ALGFLAG_SAC) ? TRUE : FALSE;
  89. Info->h263comp->unrestricted = (value&PARAM_ALGFLAG_UMV) ? TRUE : FALSE;
  90. Info->h263comp->advanced = (value&PARAM_ALGFLAG_ADVANCED) ? TRUE : FALSE;
  91. return(SvErrorNone);
  92. case SV_PARAM_FORMATEXT:
  93. Info->h263comp->extbitstream = (int)value;
  94. return(SvErrorNone);
  95. case SV_PARAM_QUANTI:
  96. if (value>0)
  97. Info->h263comp->QPI=(int)value;
  98. break;
  99. case SV_PARAM_QUANTP:
  100. if (value>0)
  101. {
  102. if (value>31) value=31;
  103. Info->h263comp->QP=Info->h263comp->QP_init=(int)value;
  104. if (Info->h263comp->bit_rate==0 && Info->h263comp->pic)
  105. Info->h263comp->pic->QUANT=(int)value;
  106. }
  107. break;
  108. case SV_PARAM_KEYSPACING:
  109. Info->h263comp->end = (int)value;
  110. break;
  111. case SV_PARAM_FRAMETYPE:
  112. if (value==FRAME_TYPE_I) /* next key should be key */
  113. sv_H263RefreshCompressor(Info);
  114. return(SvErrorNone);
  115. case SV_PARAM_PACKETSIZE:
  116. Info->h263comp->packetsize = (int)value*8;
  117. break;
  118. }
  119. return(SvErrorNone);
  120. }
  121. SvStatus_t svH263SetParamFloat(SvHandle_t Svh, SvParameter_t param,
  122. float value)
  123. {
  124. SvCodecInfo_t *Info = (SvCodecInfo_t *)Svh;
  125. if (!Svh)
  126. return(SvErrorCodecHandle);
  127. if (Info->mode == SV_H263_ENCODE)
  128. switch (param)
  129. {
  130. case SV_PARAM_FPS:
  131. if (value<1.0)
  132. Info->h263comp->frame_rate = 1.0F;
  133. else if (value>30.0)
  134. Info->h263comp->frame_rate = 30.0F;
  135. else
  136. Info->h263comp->frame_rate = value;
  137. _SlibDebug(_DEBUG_,
  138. printf("frame_rate = %f\n", Info->h263comp->frame_rate) );
  139. sv_H263UpdateQuality(Info);
  140. return(SvErrorNone);
  141. }
  142. return(svH263SetParamInt(Svh, param, (long)value));
  143. }
  144. qword svH263GetParamInt(SvHandle_t Svh, SvParameter_t param)
  145. {
  146. SvCodecInfo_t *Info = (SvCodecInfo_t *)Svh;
  147. if (!Svh)
  148. return((qword)0);
  149. if (Info->mode == SV_H263_ENCODE)
  150. switch (param)
  151. {
  152. case SV_PARAM_BITRATE:
  153. return((qword)Info->h263comp->bit_rate);
  154. case SV_PARAM_FPS:
  155. return((qword)svH263GetParamFloat(Svh, param));
  156. case SV_PARAM_QUALITY:
  157. return((qword)Info->h263comp->quality);
  158. case SV_PARAM_NATIVEFORMAT:
  159. return((qword)BI_YU12SEP);
  160. case SV_PARAM_FINALFORMAT:
  161. return((qword)BI_YU12SEP);
  162. case SV_PARAM_ALGFLAGS:
  163. {
  164. qword flags=0;
  165. flags|=Info->h263comp->pb_frames ? PARAM_ALGFLAG_PB : 0;
  166. flags|=Info->h263comp->syntax_arith_coding ? PARAM_ALGFLAG_SAC : 0;
  167. flags|=Info->h263comp->unrestricted ? PARAM_ALGFLAG_UMV : 0;
  168. flags|=Info->h263comp->advanced ? PARAM_ALGFLAG_ADVANCED : 0;
  169. return(flags);
  170. }
  171. break;
  172. case SV_PARAM_QUANTI:
  173. return((qword)Info->h263comp->QPI);
  174. case SV_PARAM_QUANTP:
  175. return((qword)Info->h263comp->QP);
  176. case SV_PARAM_KEYSPACING:
  177. return((qword)Info->h263comp->end);
  178. case SV_PARAM_PACKETSIZE:
  179. return((qword)Info->h263comp->packetsize/8);
  180. }
  181. else if (Info->mode == SV_H263_DECODE)
  182. switch (param)
  183. {
  184. case SV_PARAM_MOTIONALG:
  185. return((qword)Info->h263comp->ME_method);
  186. case SV_PARAM_BITRATE:
  187. return((qword)Info->h263dcmp->bit_rate);
  188. case SV_PARAM_FPS:
  189. return((qword)svH263GetParamFloat(Svh, param));
  190. case SV_PARAM_WIDTH:
  191. return((qword)Info->h263dcmp->horizontal_size);
  192. case SV_PARAM_HEIGHT:
  193. return((qword)Info->h263dcmp->vertical_size);
  194. case SV_PARAM_FRAME:
  195. return((qword)Info->h263dcmp->framenum);
  196. case SV_PARAM_NATIVEFORMAT:
  197. return((qword)BI_YU12SEP);
  198. case SV_PARAM_FINALFORMAT:
  199. return((qword)BI_YU12SEP);
  200. case SV_PARAM_QUALITY:
  201. return((qword)Info->h263dcmp->quality);
  202. }
  203. return((qword)0);
  204. }
  205. float svH263GetParamFloat(SvHandle_t Svh, SvParameter_t param)
  206. {
  207. SvCodecInfo_t *Info = (SvCodecInfo_t *)Svh;
  208. if (!Svh)
  209. return((float)0.0);
  210. if (Info->mode == SV_H263_ENCODE)
  211. switch (param)
  212. {
  213. case SV_PARAM_FPS:
  214. return((float)Info->h263comp->frame_rate);
  215. }
  216. else if (Info->mode == SV_H263_DECODE)
  217. switch (param)
  218. {
  219. case SV_PARAM_FPS:
  220. return((float)Info->h263dcmp->frame_rate);
  221. }
  222. return((float)svH263GetParamInt(Svh, param));
  223. }
  224. SvStatus_t svH263SetParamBoolean(SvHandle_t Svh, SvParameter_t param,
  225. ScBoolean_t value)
  226. {
  227. SvCodecInfo_t *Info = (SvCodecInfo_t *)Svh;
  228. if (!Svh)
  229. return(0);
  230. if (Info->mode == SV_H263_ENCODE)
  231. switch (param)
  232. {
  233. case SV_PARAM_FASTENCODE:
  234. return(SvErrorNone);
  235. case SV_PARAM_FASTDECODE:
  236. return(SvErrorNone);
  237. }
  238. else if (Info->mode == SV_H263_DECODE)
  239. switch (param)
  240. {
  241. case SV_PARAM_FASTDECODE:
  242. return(SvErrorNone);
  243. }
  244. return(SvErrorNone);
  245. }
  246. ScBoolean_t svH263GetParamBoolean(SvHandle_t Svh, SvParameter_t param)
  247. {
  248. SvCodecInfo_t *Info = (SvCodecInfo_t *)Svh;
  249. if (!Svh)
  250. return(0);
  251. #if 0
  252. if (Info->mode == SV_H263_ENCODE)
  253. switch (param)
  254. {
  255. case SV_PARAM_FASTENCODE:
  256. return((ScBoolean_t)Info->h263comp->fastencode);
  257. case SV_PARAM_FASTDECODE:
  258. return((ScBoolean_t)Info->h263comp->fastdecode);
  259. case SV_PARAM_MOTIONALG:
  260. return((ScBoolean_t)Info->h263comp->motionalg);
  261. case SV_PARAM_HALFPEL:
  262. return((ScBoolean_t)Info->h263comp->halfpel);
  263. case SV_PARAM_SKIPPEL:
  264. return((ScBoolean_t)Info->h263comp->skippel);
  265. }
  266. else if (Info->mode == SV_H263_DECODE)
  267. switch (param)
  268. {
  269. case SV_PARAM_FASTDECODE:
  270. return((ScBoolean_t)Info->h263dcmp->fastdecode);
  271. }
  272. #endif
  273. return(FALSE);
  274. }