Source code of Windows XP (NT5)
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.

127 lines
4.5 KiB

  1. /* Copyright (c) 1997 Microsoft Corporation. All Rights Reserved. */
  2. #ifndef __CCDECODE_H
  3. #define __CCDECODE_H
  4. typedef struct cc_state_struct CCState;
  5. typedef struct cc_line_stats_struct CCLineStats;
  6. /* Create a new "CC Decoder state".
  7. A separate CC state should be maintained for each separate
  8. simultaneous source to the CC filter (i.e., each channel). (If
  9. different lines of CC are known to come from different inserters,
  10. better results may be possible by keeping a separate CC state for
  11. each line, at the cost of more CPU and memory overhead. This
  12. shouldn't be necessary under normal circumstances.)
  13. CCStartRetrain(fDiscardOld = TRUE) is implicitly called upon
  14. creation of a new state.
  15. Returns NULL on error.
  16. */
  17. CCState *CCStateNew(CCState *mem);
  18. /* Destroys a CC state */
  19. void CCStateDestroy(CCState *pState);
  20. struct cc_state_struct {
  21. unsigned short magic; // Magic number; used for validity test
  22. unsigned short no_free; // Memory for this was pre-allocated; don't free
  23. unsigned long period; // # of samples per bit at the current sampling rate
  24. unsigned long lastFreq; // The last sampling frequency computed
  25. int cc_sync_points[16];
  26. };
  27. #define CC_STATE_MAGIC_10 0xCC01
  28. #define MCHECK(pState) (pState->magic == CC_STATE_MAGIC_10)
  29. #define MASSERT(pState) ASSERT(pState && MCHECK(pState))
  30. /* The period of the CC samples is CCState.period/CC_MULTIPLE. (This can
  31. be thought of as representing the period in fixed-point, with two
  32. digits after the decimal point. If we rounded this off to the nearest
  33. integral number of samples, the inaccuracy would accumulate unacceptably
  34. as we scanned across the scanline.) */
  35. #define CC_MULTIPLE 8
  36. /* Dereference a block of CC samples, taking CC_MULTIPLE into account. */
  37. #define CC_DATA(x, y) ((x)[(y)/CC_MULTIPLE])
  38. /* Tells the CC decoder to initiate a "fast retrain". This is useful
  39. if you suspect that conditions have changed sufficiently to be
  40. worth a CPU hit. If the fDiscardOld flag is TRUE, then the old
  41. trained state is discarded; this would be used on channel changes,
  42. for instance. If the fDiscardOld flag is FALSE, then the
  43. retraining is cumulative on the previous training. (Is this
  44. useful?) */
  45. void CCStartRetrain(CCState *pState, BOOL fDiscardOld);
  46. /*
  47. * Inputs:
  48. * pbSamples: pointer to 8-bit raw VBI samples
  49. * pState: CCState to use for decoding
  50. *
  51. * Outputs:
  52. * pbDest: decoded data (2 bytes long)
  53. * Note that "standard" CC (as specified in EIA-608) uses 7 data bits
  54. * and 1 parity bit. This function does not check or remove the parity
  55. * bits, for increased flexibility with nonstandard CC lines.
  56. * pLineStats: stats on decoded data
  57. *
  58. * Errors:
  59. *
  60. * Returns 0 if no error
  61. * Returns CC_ERROR_ILLEGAL_STATE if state is illegal or uses
  62. * unsupported settings
  63. * Returns CC_ERROR_ILLEGAL_STATS if stats is passed incorrectly
  64. * Returns CC_ERROR_ILLEGAL_VBIINFOHEADER if vbi info header is invalid
  65. *
  66. * Notes:
  67. * pbDest must point to a buffer at least 2 bytes long
  68. * pLineStats->nSize must be set to sizeof(*pLineStats) prior to call
  69. * (so that the decoder can signal an error if CCLineStats changes
  70. * incompatibly)
  71. */
  72. int CCDecodeLine(unsigned char *pbDest, CCLineStats *pLineStats,
  73. unsigned char *pbSamples, CCState *pState,
  74. PKS_VBIINFOHEADER pVBIINFO);
  75. enum cc_errors {CC_OK, CC_ERROR_ILLEGAL_STATE, CC_ERROR_ILLEGAL_STATS,
  76. CC_ERROR_ILLEGAL_VBIINFOHEADER};
  77. struct cc_line_stats_struct {
  78. int nSize; /* Should be set to the size of this structure.
  79. Used to maintain backwards compatibility as we add fields */
  80. int nConfidence; /* Set to 0-100 as a measure of expected reliability.
  81. Low numbers are caused either by a noisy signal, or
  82. if the line is in fact not CC */
  83. int nFirstBit; /* The position of the center of
  84. the first sync bit sample */
  85. int nDC; /* the calculated DC offset used to threshold samples.
  86. This is dependent on the current way we decode CC
  87. and may not be used in the future */
  88. int bCheckBits; /* The CC standard specifies that there are 3 bits whose
  89. values are fixed. This is a 3-bit number which
  90. says how those 3 bits were decoded; it should always
  91. be equal to 4. (If this field is not set to 4, then
  92. either the line was very noisy, and probably not
  93. decoded correctly, or it is not CC data at all.) */
  94. int nBitVals[19]; /* debugging */
  95. };
  96. #endif /*__CCDECODE_H*/