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.

176 lines
7.7 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <conio.h>
  5. #include <windows.h>
  6. #include <wincon.h>
  7. #include <nabts.h>
  8. #define ENTRIES(a) (sizeof(a)/sizeof(*(a)))
  9. #define CONCURRENT_READS 180
  10. #define READ_BUFFER_SIZE sizeof(NABTSFEC_BUFFER)
  11. /* Update statistics every n milliseconds (16ms is generally too fast) */
  12. #define UPDATE_PERIOD 100
  13. void
  14. PrintStatistics( INabts &Driver, int row, int column, BOOL bSavePosition)
  15. {
  16. HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
  17. COORD Pos = {(short)row, (short)column};
  18. CONSOLE_SCREEN_BUFFER_INFO SavedPos;
  19. VBICODECFILTERING_STATISTICS_NABTS Statistics;
  20. VBICODECFILTERING_STATISTICS_COMMON_PIN PinStatistics;
  21. if ( Driver.GetCodecStatistics( Statistics ) == 0
  22. && Driver.GetPinStatistics( PinStatistics ) == 0 )
  23. {
  24. char szBuffer[13][80] = { 0 };
  25. if ( bSavePosition )
  26. GetConsoleScreenBufferInfo( hStdout, &SavedPos );
  27. SetConsoleCursorPosition( hStdout, Pos );
  28. sprintf(szBuffer[0], "-------------------------- NABTS Codec Statistics -----------------------------");
  29. sprintf(szBuffer[1], "InputSRBsProcessed: %u, OutputSRBsProcessed: %u, SRBsIgnored: %u",
  30. Statistics.Common.InputSRBsProcessed, Statistics.Common.OutputSRBsProcessed, Statistics.Common.SRBsIgnored );
  31. sprintf(szBuffer[2], "InputSRBsMissing: %u, OutputSRBsMissing: %u, OutputFailures: %u",
  32. Statistics.Common.InputSRBsMissing, Statistics.Common.OutputSRBsMissing, Statistics.Common.OutputFailures );
  33. sprintf(szBuffer[3], "InternalErrors: %u, ExternalErrors: %u, InputDiscontinuities: %u",
  34. Statistics.Common.InternalErrors, Statistics.Common.ExternalErrors, Statistics.Common.InputDiscontinuities );
  35. sprintf(szBuffer[4], "DSPFailures: %u, TvTunerChanges: %u, VBIHeaderChanges: %u",
  36. Statistics.Common.DSPFailures, Statistics.Common.TvTunerChanges, Statistics.Common.VBIHeaderChanges );
  37. sprintf(szBuffer[5], "LineConfidenceAvg: %u, BytesOutput: %u, FECBundleBadLines: %u",
  38. Statistics.Common.LineConfidenceAvg, Statistics.Common.BytesOutput, Statistics.FECBundleBadLines );
  39. sprintf(szBuffer[6], "FECQueueOverflows: %u, FECCorrectedLines: %u, FECUncorrectableLines: %u",
  40. Statistics.FECQueueOverflows, Statistics.FECCorrectedLines, Statistics.FECUncorrectableLines );
  41. sprintf(szBuffer[7], "BundlesProcessed: %u, BundlesSent2IP: %u, FilteredLines: %u",
  42. Statistics.BundlesProcessed, Statistics.BundlesSent2IP, Statistics.FilteredLines );
  43. sprintf(szBuffer[8], "---------------------------- Raw Pin Statistics -------------------------------");
  44. sprintf(szBuffer[9], "SRBsProcessed: %u, SRBsMissing: %u, SRBsIgnored: %u",
  45. PinStatistics.SRBsProcessed, PinStatistics.SRBsMissing, PinStatistics.SRBsIgnored );
  46. sprintf(szBuffer[10], "InternalErrors: %u, ExternalErrors: %u, Discontinuities: %u",
  47. PinStatistics.InternalErrors, PinStatistics.ExternalErrors, PinStatistics.Discontinuities );
  48. sprintf(szBuffer[11], "LineConfidenceAvg: %u, BytesOutput: %u",
  49. PinStatistics.LineConfidenceAvg, PinStatistics.BytesOutput );
  50. sprintf(szBuffer[12], "===============================================================================");
  51. printf("%-79.79s\n%-79.79s\n%-79.79s\n%-79.79s\n%-79.79s\n%-79.79s\n%-79.79s\n%-79.79s\n%-79.79s\n%-79.79s\n%-79.79s\n%-79.79s\n%-79.79s\n",
  52. szBuffer[0], szBuffer[1], szBuffer[2], szBuffer[3], szBuffer[4],
  53. szBuffer[5], szBuffer[6], szBuffer[7], szBuffer[8], szBuffer[9],
  54. szBuffer[10], szBuffer[11], szBuffer[12] );
  55. if ( bSavePosition )
  56. SetConsoleCursorPosition( hStdout, SavedPos.dwCursorPosition );
  57. }
  58. }
  59. int __cdecl
  60. main( int argc, char *argv[] )
  61. {
  62. int nStatus = 0;
  63. int arg = 1; // Next unparsed command line parameter
  64. const int bStatistics = arg < argc && strcmp(argv[arg],"-s") == 0 ? arg++ : 0;
  65. long nLastUpdate = 0;
  66. int nScanline = 13; // Scanlines can vary by station(This one is arbitrary)
  67. if ( nScanline )
  68. {
  69. try {
  70. INabts Driver;
  71. if ( Driver.IsValid() )
  72. {
  73. SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL );
  74. if ( bStatistics )
  75. PrintStatistics( Driver, 0, 0, FALSE );
  76. if ( ( nStatus = Driver.ClearRequestedScanlines() ) == 0 )
  77. {
  78. do
  79. {
  80. if ( arg < argc )
  81. if ( !(nScanline = atoi( argv[arg] ) ) )
  82. printf( "Invalid scanline: '%s'\n", argv[arg] );
  83. printf( "Scanline:%d ", nScanline );
  84. if ( ( nStatus = Driver.AddRequestedScanline(nScanline) ) != 0 )
  85. {
  86. fprintf( stderr, "\nFailed to AddRequestedScanline(%d)=%d\n", nScanline, nStatus );
  87. return nStatus;
  88. }
  89. }
  90. while ( ++arg < argc );
  91. }
  92. else
  93. {
  94. fprintf( stderr, "\nFailed to ClearRequestedScanlines()=%d\n", nStatus );
  95. return nStatus;
  96. }
  97. printf("\n");
  98. int nNextRead = 0;
  99. DWORD nBytes = 0;
  100. OVERLAPPED Overlapped[CONCURRENT_READS] = {0};
  101. NABTS_BUFFER NabtsBuffer[CONCURRENT_READS];
  102. for( nNextRead = 0; !nStatus && nNextRead < CONCURRENT_READS; nNextRead++ )
  103. {
  104. if ( !( Overlapped[nNextRead].hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ) ) )
  105. {
  106. nStatus = GetLastError();
  107. break;
  108. }
  109. nStatus = Driver.ReadData( NabtsBuffer+nNextRead, READ_BUFFER_SIZE, &nBytes, Overlapped + nNextRead );
  110. if ( !nStatus || nStatus == ERROR_IO_PENDING )
  111. nStatus = 0;
  112. else
  113. break;
  114. }
  115. nNextRead = 0;
  116. while ( !nStatus && !_kbhit() )
  117. {
  118. if ( !(nStatus = Driver.GetOverlappedResult(Overlapped+nNextRead, &nBytes, FALSE ) ) )
  119. {
  120. nBytes = min(nBytes, READ_BUFFER_SIZE);
  121. printf("[%06X]", NabtsBuffer[nNextRead].ScanlinesRequested.DwordBitArray[0] );
  122. nStatus = Driver.ReadData( NabtsBuffer+nNextRead, READ_BUFFER_SIZE, &nBytes, Overlapped + nNextRead );
  123. if ( !nStatus || nStatus == ERROR_IO_PENDING )
  124. {
  125. nNextRead = ++nNextRead % CONCURRENT_READS;
  126. nStatus = 0;
  127. }
  128. }
  129. else if ( nStatus == ERROR_IO_INCOMPLETE || nStatus == ERROR_IO_PENDING )
  130. {
  131. Sleep(10); // Chill out a few milliseconds so we don't run full tilt.
  132. nStatus = 0;
  133. }
  134. if ( bStatistics && GetTickCount()-nLastUpdate > UPDATE_PERIOD )
  135. {
  136. PrintStatistics( Driver, 0, 0, TRUE );
  137. nLastUpdate = GetTickCount();
  138. }
  139. }
  140. }
  141. }
  142. catch (...)
  143. {
  144. nStatus = GetLastError();
  145. }
  146. }
  147. else
  148. printf( "Syntax: TESTNAB [-s] [ scanline1 [scanline2] ]\n" );
  149. if ( nStatus )
  150. fprintf( stderr, "Program failed with LastErrorCode=%d!\n", nStatus );
  151. return nStatus;
  152. }