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.

128 lines
2.8 KiB

  1. #include <win32.h>
  2. #include <vfw.h>
  3. #include "debug.h"
  4. // !!! Note: doesn't take AVI File overhead into account
  5. // !!! Doesn't take padding into account!
  6. // AVIDataSize:
  7. // Calculates the amount of data in the given PAVISTREAM
  8. // from time msStart to msStart + ms
  9. LONG AVIDataSize(PAVISTREAM ps, LONG msStart, LONG ms)
  10. {
  11. LONG lBytes;
  12. LONG l;
  13. LONG sampStart;
  14. LONG sampEnd;
  15. LONG samp;
  16. AVISTREAMINFOW sinfo;
  17. HRESULT hr;
  18. sampStart = AVIStreamTimeToSample(ps, msStart);
  19. sampEnd = AVIStreamTimeToSample(ps, msStart + ms);
  20. AVIStreamInfoW(ps, &sinfo, sizeof(sinfo));
  21. if (sinfo.dwSampleSize > 0) {
  22. hr = AVIStreamRead(ps,
  23. sampStart,
  24. sampEnd - sampStart,
  25. NULL, 0,
  26. &lBytes, &l);
  27. if (hr != NOERROR)
  28. return 0;
  29. if (l != sampEnd - sampStart) {
  30. DPF("Ack: wrong number of samples!\n");
  31. }
  32. } else {
  33. lBytes = 0;
  34. for (samp = sampStart; samp < sampEnd; samp++) {
  35. hr = AVIStreamSampleSize(ps, samp, &l);
  36. if (hr != NOERROR)
  37. return 0;
  38. lBytes += l;
  39. }
  40. }
  41. return lBytes;
  42. }
  43. #define MAXSTREAMS 64
  44. #define TIMEINT 250
  45. #define TIMELEN 1000
  46. STDAPI CalculateFileDataRate(PAVIFILE pf, LONG FAR *plMaxBytesPerSec)
  47. {
  48. PAVISTREAM aps[MAXSTREAMS];
  49. LONG alMaxData[MAXSTREAMS];
  50. AVIFILEINFO finfo;
  51. int stream;
  52. HRESULT hr;
  53. LONG msecLength = 0;
  54. LONG l;
  55. LONG lStart;
  56. LONG lDataSize;
  57. LONG lMaxDataSize = 0;
  58. AVIFileInfo(pf, &finfo, sizeof(finfo));
  59. for (stream = 0; stream < (int) finfo.dwStreams; stream++) {
  60. hr = AVIFileGetStream(pf, &aps[stream], 0, stream);
  61. if (hr != NOERROR) {
  62. while (--stream >= 0)
  63. AVIStreamRelease(aps[stream]);
  64. return hr;
  65. }
  66. l = AVIStreamEndTime(aps[stream]);
  67. msecLength = max(l, msecLength);
  68. alMaxData[stream] = 0;
  69. }
  70. lStart = 0;
  71. DPF("Time\t\t\tData Rate\n");
  72. do {
  73. lStart += TIMEINT;
  74. lDataSize = 0;
  75. for (stream = 0; stream < (int) finfo.dwStreams; stream++) {
  76. l = AVIDataSize(aps[stream], lStart, TIMELEN);
  77. lDataSize += l;
  78. alMaxData[stream] = max(alMaxData[stream], l);
  79. }
  80. lMaxDataSize = max(lDataSize, lMaxDataSize);
  81. #ifdef DEBUG
  82. if (lStart < 50 * TIMEINT) { // print at most 50 debug lines....
  83. DPF("%lu\t\t\t%lu\n", lStart, muldiv32(lDataSize, 1000, TIMELEN));
  84. }
  85. #endif
  86. } while (lStart < msecLength);
  87. *plMaxBytesPerSec = muldiv32(lMaxDataSize, 1000, TIMELEN);
  88. DPF("Max data rate for file: %ld\n", muldiv32(lMaxDataSize, 1000, TIMELEN));
  89. for (stream = 0; stream < (int) finfo.dwStreams; stream++) {
  90. DPF("Max data rate for stream %u: %ld\n", stream, muldiv32(alMaxData[stream], 1000, TIMELEN));
  91. AVIStreamRelease(aps[stream]);
  92. }
  93. return NOERROR;
  94. }