preprocif.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /****************************************************************************
  2. *
  3. * Module Title : PreProcIf.c
  4. *
  5. * Description : Pre-processor dll interface module.
  6. *
  7. * AUTHOR : Paul Wilkins
  8. *
  9. *****************************************************************************
  10. * Revision History
  11. *
  12. * 1.09 PGW 27 Apr 01 Changes to use last frame coded list passed in from codec.
  13. * Removed code to set Y from UV.
  14. * 1.08 PGW 28 Feb 01 Removal of history buffer functionality.
  15. * 1.07 PGW 28 Feb 01 Removal of pre-processor output buffer.
  16. * 1.06 JBB 03 Aug 00 Added Malloc Checks
  17. * 1.05 PGW 27 Jul 00 Removed SetVcapParams() plus other housekeeping.
  18. * 1.04 PGW 10 Jul 00 Removed unused functions GetBlockStats(), BlockChangeVariance()
  19. * and GetBlockCategories().
  20. * Change interface to YUVAnalyseFrame() to include KF indicator.
  21. * 1.03 PGW 22/06/00 Removed speed specific code.
  22. * 1.02 JBB 30/05/00 Removed hard coded size limits
  23. * 1.01 PGW 12/07/99 Changes to reduce uneccessary dependancies.
  24. * 1.00 PGW 14/06/99 Configuration baseline
  25. *
  26. *****************************************************************************
  27. */
  28. /****************************************************************************
  29. * Header Frames
  30. *****************************************************************************
  31. */
  32. #define STRICT /* Strict type checking. */
  33. #include <string.h>
  34. #include "type_aliases.h"
  35. #include "preproc.h"
  36. /****************************************************************************
  37. * Module constants.
  38. *****************************************************************************
  39. */
  40. #define MIN_STEP_THRESH 6
  41. #define VARIANCE_THRESH 200
  42. #define LOW_VARIANCE_THRESH 100
  43. #define HIGH_SCORE 400
  44. /****************************************************************************
  45. * Explicit Imports
  46. *****************************************************************************
  47. */
  48. /****************************************************************************
  49. * Exported Global Variables
  50. *****************************************************************************
  51. */
  52. /****************************************************************************
  53. * Foreward References
  54. *****************************************************************************
  55. */
  56. /****************************************************************************
  57. * Module Statics
  58. *****************************************************************************
  59. */
  60. /****************************************************************************
  61. *
  62. * ROUTINE : ScanYUVInit
  63. *
  64. * INPUTS : SCAN_CONFIG_DATA * ScanConfigPtr
  65. * Configuration data.
  66. *
  67. * OUTPUTS : None.
  68. *
  69. * RETURNS : None.
  70. *
  71. * FUNCTION : Initialises the scan process.
  72. *
  73. * SPECIAL NOTES : None.
  74. *
  75. *
  76. * ERRORS : None.
  77. *
  78. ****************************************************************************/
  79. extern BOOL PAllocateFrameInfo(PP_INSTANCE * ppi);
  80. BOOL ScanYUVInit( PP_INSTANCE * ppi, SCAN_CONFIG_DATA * ScanConfigPtr)
  81. {
  82. // Test machine specific features such as MMX support
  83. MachineSpecificConfig(ppi);
  84. /* Set up the various imported data structure pointers. */
  85. ppi->ScanConfig.Yuv0ptr = ScanConfigPtr->Yuv0ptr;
  86. ppi->ScanConfig.Yuv1ptr = ScanConfigPtr->Yuv1ptr;
  87. ppi->ScanConfig.FragInfo = ScanConfigPtr->FragInfo;
  88. ppi->ScanConfig.FragInfoElementSize = ScanConfigPtr->FragInfoElementSize;
  89. ppi->ScanConfig.FragInfoCodedMask = ScanConfigPtr->FragInfoCodedMask ;
  90. ppi->ScanConfig.RegionIndex = ScanConfigPtr->RegionIndex;
  91. ppi->ScanConfig.HFragPixels = ScanConfigPtr->HFragPixels;
  92. ppi->ScanConfig.VFragPixels = ScanConfigPtr->VFragPixels;
  93. ppi->ScanConfig.VideoFrameWidth = ScanConfigPtr->VideoFrameWidth;
  94. ppi->ScanConfig.VideoFrameHeight = ScanConfigPtr->VideoFrameHeight;
  95. // UV plane sizes.
  96. ppi->VideoUVPlaneWidth = ScanConfigPtr->VideoFrameWidth / 2;
  97. ppi->VideoUVPlaneHeight = ScanConfigPtr->VideoFrameHeight / 2;
  98. /* Note the size of the entire frame and plaes in pixels. */
  99. ppi->YFramePixels = ppi->ScanConfig.VideoFrameWidth * ppi->ScanConfig.VideoFrameHeight;
  100. ppi->UVFramePixels = ppi->VideoUVPlaneWidth * ppi->VideoUVPlaneHeight;
  101. ppi->TotFramePixels = ppi->YFramePixels + (2 * ppi->UVFramePixels);
  102. /* Work out various fragment related values. */
  103. ppi->ScanYPlaneFragments = ppi->YFramePixels / (ppi->HFragPixels * ppi->VFragPixels);
  104. ppi->ScanUVPlaneFragments = ppi->UVFramePixels / (ppi->HFragPixels * ppi->VFragPixels);;
  105. ppi->ScanHFragments = ppi->ScanConfig.VideoFrameWidth / ppi->HFragPixels;
  106. ppi->ScanVFragments = ppi->ScanConfig.VideoFrameHeight / ppi->VFragPixels;
  107. ppi->ScanFrameFragments = ppi->ScanYPlaneFragments + (2 * ppi->ScanUVPlaneFragments);
  108. if(!PAllocateFrameInfo(ppi))
  109. return FALSE;
  110. /* Set up the scan pixel index table. */
  111. ScanCalcPixelIndexTable(ppi);
  112. /* Initialise scan arrays */
  113. InitScanMapArrays(ppi);
  114. return TRUE;
  115. }
  116. /****************************************************************************
  117. *
  118. * ROUTINE : YUVAnalyseFrame
  119. *
  120. * INPUTS : None
  121. *
  122. * OUTPUTS : None.
  123. *
  124. * RETURNS : Number of "output" blocks to be updated.
  125. *
  126. * FUNCTION : Scores the fragments for the YUV planes
  127. *
  128. * SPECIAL NOTES : None.
  129. *
  130. *
  131. * ERRORS : None.
  132. *
  133. ****************************************************************************/
  134. UINT32 YUVAnalyseFrame( PP_INSTANCE *ppi, UINT32 * KFIndicator )
  135. {
  136. UINT32 UpdatedYBlocks = 0;
  137. UINT32 UpdatedUVBlocks = 0;
  138. UINT32 i;
  139. /* Initialise the map arrays. */
  140. InitScanMapArrays(ppi);
  141. /********** PGW 27/APR/2001 ***********/
  142. // If the block is already marked as coded in the input block map then
  143. // mark it as coded here to avoid unnecessary pre-processor work.
  144. for ( i = 0; i < ppi->ScanFrameFragments; i++ )
  145. {
  146. if ( blockCoded(i) )
  147. ppi->ScanDisplayFragments[i] = BLOCK_ALREADY_MARKED_FOR_CODING;
  148. }
  149. // If the motion level in the previous frame was high then adjust the high and low SAD
  150. // thresholds to speed things up.
  151. ppi->ModifiedGrpLowSadThresh = ppi->GrpLowSadThresh;
  152. ppi->ModifiedGrpHighSadThresh = ppi->GrpHighSadThresh;
  153. // testing force every block with any change to get coded
  154. //ppi->ModifiedGrpHighSadThresh = 0;
  155. // Set up the internal plane height and width variables.
  156. ppi->VideoYPlaneWidth = ppi->ScanConfig.VideoFrameWidth;
  157. ppi->VideoYPlaneHeight = ppi->ScanConfig.VideoFrameHeight;
  158. ppi->VideoUVPlaneWidth = ppi->ScanConfig.VideoFrameWidth / 2;
  159. ppi->VideoUVPlaneHeight = ppi->ScanConfig.VideoFrameHeight / 2;
  160. // To start with *** TBD **** the stides will be set from the widths
  161. ppi->VideoYPlaneStride = ppi->VideoYPlaneWidth;
  162. ppi->VideoUPlaneStride = ppi->VideoUVPlaneWidth;
  163. ppi->VideoVPlaneStride = ppi->VideoUVPlaneWidth;
  164. // Set up the plane pointers
  165. ppi->YPlanePtr0 = ppi->ScanConfig.Yuv0ptr;
  166. ppi->YPlanePtr1 = ppi->ScanConfig.Yuv1ptr;
  167. ppi->UPlanePtr0 = (ppi->ScanConfig.Yuv0ptr + ppi->YFramePixels);
  168. ppi->UPlanePtr1 = (ppi->ScanConfig.Yuv1ptr + ppi->YFramePixels);
  169. ppi->VPlanePtr0 = (ppi->ScanConfig.Yuv0ptr + ppi->YFramePixels + ppi->UVFramePixels);
  170. ppi->VPlanePtr1 = (ppi->ScanConfig.Yuv1ptr + ppi->YFramePixels + ppi->UVFramePixels);
  171. // Ananlyse the U and V palnes.
  172. AnalysePlane( ppi, ppi->UPlanePtr0, ppi->UPlanePtr1, ppi->ScanYPlaneFragments, ppi->VideoUVPlaneWidth, ppi->VideoUVPlaneHeight, ppi->VideoUPlaneStride );
  173. AnalysePlane( ppi, ppi->VPlanePtr0, ppi->VPlanePtr1, (ppi->ScanYPlaneFragments + ppi->ScanUVPlaneFragments), ppi->VideoUVPlaneWidth, ppi->VideoUVPlaneHeight, ppi->VideoVPlaneStride );
  174. // Now analyse the Y plane.
  175. AnalysePlane( ppi, ppi->YPlanePtr0, ppi->YPlanePtr1, 0, ppi->VideoYPlaneWidth, ppi->VideoYPlaneHeight, ppi->VideoYPlaneStride );
  176. // Create an output block map for the calling process.
  177. CreateOutputDisplayMap( ppi, ppi->ScanDisplayFragments);
  178. // Set the candidate key frame indicator (0-100)
  179. *KFIndicator = ppi->KFIndicator;
  180. // Return the normalised block count (this is actually a motion level
  181. // weighting not a true block count).
  182. return ppi->OutputBlocksUpdated;
  183. }
  184. /****************************************************************************
  185. *
  186. * ROUTINE : SetScanParam
  187. *
  188. * INPUTS : ParamID
  189. * ParamValue
  190. *
  191. * OUTPUTS : None.
  192. *
  193. * RETURNS : None.
  194. *
  195. * FUNCTION : Sets a scan parameter.
  196. *
  197. * SPECIAL NOTES : None.
  198. *
  199. *
  200. * ERRORS : None.
  201. *
  202. ****************************************************************************/
  203. void SetScanParam( PP_INSTANCE *ppi, UINT32 ParamId, INT32 ParamValue )
  204. {
  205. switch (ParamId)
  206. {
  207. case SCP_SET_VCAP_LEVEL_OFFSET:
  208. SetVcapLevelOffset(ppi, ParamValue);
  209. break;
  210. }
  211. }