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.

216 lines
6.5 KiB

  1. // LOG.C
  2. // low overhead logging routines
  3. // can be used in time-critical situations
  4. // LogInit should be called once to create the memory mapped file
  5. // use LOGVIEW.EXE to view the log.
  6. #include "precomp.h"
  7. #ifdef LOGGING
  8. // storage in log.c
  9. // Strings corresponding to LOGMSG_XXX
  10. // Note: cant use %s in format string
  11. char LogStringTable [][MAX_STRING_SIZE] = {
  12. // dont exceed the size of the string below!
  13. // "123456789012345678901234567890123456789012345678901234567890123"
  14. "Sent at %d\n",
  15. "NetRecv ts = %d, seq = %d at %d\n",
  16. "AP::Send (%d), %d bytes, ts =%d\n",
  17. "AP::Silent (%d) %d\n",
  18. "AP::Record (%d)\n",
  19. "AP::Recv (%d) seq = %d len=%d\n",
  20. "Rx::Reset1 MaxT=%d PlayT=%d PlayPos=%d\n",
  21. "Rx::Reset2 MaxT=%d PlayT=%d PlayPos=%d\n",
  22. "AP::Encoded(%d)\n",
  23. "AP::Decoded(%d)\n",
  24. "AP::Playing(%d) at %d\n",
  25. "AP::PlaySil(%d)\n",
  26. "RcrdTh:: try to open audio dev\n",
  27. "PlayTh: too many missings and Yield\n",
  28. "RcrdTh:: too many silence and Yield\n",
  29. "AP::Recycle(%d)\n",
  30. "AutoSilence: strength=%d,threshold=%d,avgSilence=%d\n",
  31. "Tx -Presend(%d)\n",
  32. "Rx-Skipping(%d)\n",
  33. "Tx::Reset FreePos=%d SendPos=%d\n",
  34. "Rx::VarDelay=%d samples, avgVarDelay=%d, delayPos=%d\n",
  35. "AP::PlayInterpolated(%d)\n",
  36. "AP::Interpolated (%d) %d\n",
  37. "VP::Send (%d), %d bytes, ts =%d\n",
  38. "VP::Recv (%d) seq = %d len=%d\n",
  39. "VP::Recycle(%d)\n",
  40. "VP::Record (%d)\n",
  41. "VP::Playing(%d) at %d\n",
  42. "VP::PlaySil(%d)\n",
  43. "VP::PlayInterpolated(%d)\n",
  44. "VP::Interpolated (%d) %d\n",
  45. "VP::Encoded(%d)\n",
  46. "VP::Decoded(%d)\n",
  47. "Vid::Trying to open Capture\n",
  48. "Vid:GetSendFrame (%d)\n",
  49. "Vid:GetRecvFrame (%d)\n",
  50. "Vid:ReleaseSendFrame(%d)\n",
  51. "Vid:ReleaseRecvFrame(%d)\n",
  52. "Vid:Playing back TS %d aud sync %d\n",
  53. "DGSOCK:->OnRead (%d)\n",
  54. "DGSOCK:<-OnRead (%d)\n",
  55. "DGSOCK:->OnReadDone (%d)\n",
  56. "DGSOCK:<-OnReadDone (%d)\n",
  57. "DGSOCK:->RecvFrom (%d)\n",
  58. "DGSOCK:<-RecvFrom (%d)\n",
  59. "DGSOCK:ReadWouldBlock (%d)\n",
  60. "VidSend: VP::Queue %d bytes, ts =%d at %d\n",
  61. "VidSend: AP::Queue %d bytes, ts =%d at %d\n",
  62. "VidSend: VP::Send %d bytes, ts =%d at %d\n",
  63. "VidSend: AP::Send %d bytes, ts =%d at %d\n",
  64. "VidSend: VP::!Send %d bytes, ts =%d\n",
  65. "VidSend: AP::!Send %d bytes, ts =%d\n",
  66. "VidSend: IO Pending\n",
  67. "VidSend: Audio queue is empty\n",
  68. "VidSend: Video queue is empty\n",
  69. "AudSend: VP::Queue %d bytes, ts =%d\n",
  70. "AudSend: AP::Queue %d bytes, ts =%d at %d\n",
  71. "AudSend: VP::Send %d bytes, ts =%d\n",
  72. "AudSend: AP::Send %d bytes, ts =%d at %d\n",
  73. "AudSend: VP::!Send %d bytes, ts =%d\n",
  74. "AudSend: AP::!Send %d bytes, ts =%d\n",
  75. "AudSend: IO Pending\n",
  76. "AudSend: Audio queue is empty\n",
  77. "AudSend: Video queue is empty\n",
  78. "Send blocked for %d ms\n",
  79. "DS PlayBuf: Play=%d, Write=%d, len=%d\n",
  80. "DS Empty : Play=%d, lastPlay=%d, nextWrite=%d\n",
  81. "DS Timeout: Play=%d, nextWrite=%d at %d\n",
  82. "DS PlayBuf Overflow! SetPlayPosition to %d (hr=%d)\n",
  83. "DS Create: (hr = %d)\n",
  84. "DS Release: (uref = %d)\n",
  85. "DS PlayBuf: Dropped out of sequence packet\n",
  86. "DS PlayBuf: timestamp=%d, seq=%d, fMark=%d\n",
  87. "DS PlayBuf: GetTickCount=%d\n",
  88. "DS PlayBuf: PlayPos=%d, WritePos=%d\n",
  89. "DS PlayBuf: Dropping packet due to overflow\n",
  90. "m_Next=%d, curDelay=%d, bufSize=%d\n",
  91. "Send Audio Config took %ld ms\r\n",
  92. "Send Audio UnConfig took %ld ms\r\n",
  93. "Send Video Config took %ld ms\r\n",
  94. "Send Video UnConfig took %ld ms\r\n",
  95. "Recv Audio Config took %ld ms\r\n",
  96. "Recv Audio UnConfig took %ld ms\r\n",
  97. "Recv Video Config took %ld ms\r\n",
  98. "Recv Video UnConfig took %ld ms\r\n",
  99. "DSC Timestamp: %d\r\n",
  100. "DSC GetCurrentPos: capPos=%d ReadPos=%d\r\n",
  101. "DSC Timeout: A timeout has occured\r\n",
  102. "DSC Lagging condition: Lag=%d NextExpect=%d\r\n",
  103. "DSC Sending: Num=%d, dwFirstPos=%d, dwLastPos=%d\r\n",
  104. "DSC Stats: BufferSize=%d, FrameSize=%d\r\n",
  105. "DSC Early condition detected\r\n"
  106. };
  107. #define MAX_LOG_ENTRIES 2048
  108. // IMPORTANT: should be identical to definition in viewer app.
  109. typedef struct {
  110. int locked; // set to TRUE while viewer is accessing log
  111. int cdwEntrySize;
  112. int cMaxEntries;
  113. int cbOffsetBase; // from start of this struct
  114. int cbOffsetStringTable; // from start of this struct
  115. int cStrings; // number of strings
  116. int cCurrent; // index of current log position
  117. } LOG_HEADER;
  118. struct LogEntry {
  119. DWORD dw[4];
  120. } *pLogBase;
  121. #define MAX_LOG_SIZE (sizeof(LOG_HEADER)+sizeof(struct LogEntry)*MAX_LOG_ENTRIES + sizeof(LogStringTable))
  122. HANDLE hMapFile = NULL;
  123. char szLogViewMap[] = "LogViewMap";
  124. LOG_HEADER *pLog=NULL;
  125. CRITICAL_SECTION logCritSect; // not used
  126. void Log (UINT n, UINT arg1, UINT arg2, UINT arg3)
  127. {
  128. struct LogEntry *pCurEntry;
  129. if (pLog == NULL || pLog->locked)
  130. return;
  131. //EnterCriticalSection(&logCritSect);
  132. // sideeffect of multiple access are not serious so
  133. // dont bother with synchronization.
  134. pLog->cCurrent++;
  135. if (pLog->cCurrent >= pLog->cMaxEntries) {
  136. pLog->cCurrent = 0; //wraparound
  137. }
  138. pCurEntry = pLogBase + pLog->cCurrent;
  139. pCurEntry->dw[0] = n;
  140. pCurEntry->dw[1] = arg1;
  141. pCurEntry->dw[2] = arg2;
  142. pCurEntry->dw[3] = arg3;
  143. //LeaveCriticalSection(&logCritSect);
  144. }
  145. int LogInit()
  146. {
  147. int fSuccess;
  148. hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE,
  149. NULL,
  150. PAGE_READWRITE,
  151. 0,
  152. MAX_LOG_SIZE,
  153. szLogViewMap);
  154. if (hMapFile == NULL) {
  155. //printf("Couldnt open Map: %s\n",szLogViewMap);
  156. fSuccess = FALSE;
  157. goto Exit;
  158. }
  159. pLog = (LOG_HEADER *)MapViewOfFile(hMapFile,
  160. FILE_MAP_ALL_ACCESS,
  161. 0,
  162. 0,
  163. 0); // entire file starting from offset 0
  164. if (pLog == NULL) {
  165. //printf("Couldnt map view %s\n",szLogViewMap);
  166. fSuccess = FALSE;
  167. goto Exit;
  168. }
  169. InitializeCriticalSection(&logCritSect);
  170. // initialize log
  171. pLog->locked = 0;
  172. pLog->cdwEntrySize = sizeof(struct LogEntry)/sizeof(DWORD); // size in dwords
  173. pLog->cMaxEntries = MAX_LOG_ENTRIES;
  174. pLog->cbOffsetBase = sizeof(LOG_HEADER)+sizeof(LogStringTable);
  175. pLog->cbOffsetStringTable = sizeof(LOG_HEADER);
  176. pLog->cStrings = sizeof(LogStringTable)/MAX_STRING_SIZE;
  177. pLog->cCurrent = 0; // current position
  178. pLogBase = (struct LogEntry *)((PBYTE)pLog + pLog->cbOffsetBase);
  179. memcpy((PBYTE)pLog + pLog->cbOffsetStringTable, LogStringTable, sizeof(LogStringTable));
  180. memset((PBYTE)pLogBase,0,MAX_LOG_ENTRIES*pLog->cdwEntrySize*4);
  181. fSuccess = TRUE;
  182. Exit:
  183. return fSuccess;
  184. }
  185. LogClose()
  186. {
  187. if (pLog)
  188. {
  189. DeleteCriticalSection(&logCritSect);
  190. UnmapViewOfFile(pLog);
  191. pLog = NULL;
  192. CloseHandle(hMapFile);
  193. hMapFile = NULL;
  194. }
  195. return TRUE;
  196. }
  197. #endif // LOGGING enabled
  198.