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.

166 lines
6.7 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: ClientRecordSubSystem.h
  6. * Content: Recording sub-system.
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 07/19/99 rodtoll Modified from original
  12. * 08/25/99 rodtoll General Cleanup/Modifications to support new
  13. * compression sub-system.
  14. * 08/27/99 rodtoll General cleanup/Simplification of recording subsystem
  15. * Added reset of message when target changes
  16. * Fixed recording start/stop notifications
  17. * 09/29/99 pnewson Major AGC overhaul
  18. * 10/29/99 rodtoll Bug #113726 - Integrate Voxware Codecs, updating to use new
  19. * pluggable codec architecture.
  20. * 11/12/99 rodtoll Updated to use new recording classes, improved error
  21. * handling and new initialize function.
  22. * rodtoll Added new high CPU handling code for record.
  23. * 11/13/99 rodtoll Added parameter to GetNextFrame
  24. * 11/18/99 rodtoll Re-activated recording pointer lockup detection code
  25. * 01/10/00 pnewson AGC and VA tuning
  26. * 01/14/2000 rodtoll Updated to handle new multiple targets
  27. * 02/08/2000 rodtoll Bug #131496 - Selecting DVTHRESHOLD_DEFAULT results in voice
  28. * never being detected
  29. * 02/17/2000 rodtoll Bug #133691 - Choppy audio - queue was not adapting
  30. * Added instrumentation
  31. * 04/05/2000 rodtoll Updated to use new async, no buffer copy sends, removed old transmit buffer
  32. * 04/19/2000 pnewson Fix to make AGC code work properly with VA off
  33. * 07/09/2000 rodtoll Added signature bytes
  34. * 08/18/2000 rodtoll Bug #42542 - DPVoice retrofit: Voice retrofit locks up after host migration
  35. * 08/29/2000 rodtoll Bug #43553 - Start() returns 0x80004005 after lockup
  36. * rodtoll Bug #43620 - DPVOICE: Recording buffer locks up on Aureal Vortex (VxD).
  37. * Updated reset procedure so it ignores Stop failures and if Start() fails
  38. * it tries resetting the recording system.
  39. * 08/31/2000 rodtoll Bug #43804 - DVOICE: dwSensitivity structure member is confusing - should be dwThreshold
  40. * 04/11/2001 rodtoll WINBUG #221494 DPVOICE: Updates to lockup detection methods
  41. *
  42. ***************************************************************************/
  43. #ifndef __CLIENTRECORDSUBSYSTEM_H
  44. #define __CLIENTRECORDSUBSYSTEM_H
  45. class CAGCVA;
  46. // CClientRecordSubSystem
  47. //
  48. // This class implements the recording subsystem for the BattleCom client.
  49. // It works closely with the control CShadowClientControl object to
  50. // provide the recording / compression and transmissions portions of the
  51. // client. This includes addition of microphone clicks to outgoing
  52. // audio streams when appropriate.
  53. //
  54. // The core of the recording system is a finite state machine which
  55. // is used to provide a way of managing the recording system's
  56. // state and to provide smooth transitions between various
  57. // states.
  58. //
  59. // It looks to the CShadowClientControl object to detect when keys
  60. // are pressed and to provide neccessary parameters.
  61. //
  62. #define VSIG_CLIENTRECORDSYSTEM 'SRCV'
  63. #define VSIG_CLIENTRECORDSYSTEM_FREE 'SRC_'
  64. //
  65. class CClientRecordSubSystem
  66. {
  67. protected: // State Machine States
  68. typedef enum {
  69. RECORDSTATE_IDLE = 0, // Recording is idle, no transmissions required
  70. RECORDSTATE_VA, // Voice activated mode
  71. RECORDSTATE_PTT // Push to talk mode
  72. } RecordState;
  73. public:
  74. CClientRecordSubSystem( CDirectVoiceClientEngine *clientEngine );
  75. ~CClientRecordSubSystem();
  76. protected:
  77. friend class CDirectVoiceClientEngine;
  78. HRESULT Initialize();
  79. HRESULT GetNextFrame( LPBOOL fContinue );
  80. BOOL IsMuted();
  81. BOOL IsValidTarget();
  82. inline BOOL IsPTT() { return !IsVA(); };
  83. inline BOOL IsVA() { return (m_clientEngine->m_dvClientConfig.dwFlags & DVCLIENTCONFIG_MANUALVOICEACTIVATED || m_clientEngine->m_dvClientConfig.dwFlags & DVCLIENTCONFIG_AUTOVOICEACTIVATED); };
  84. BOOL CheckVA();
  85. HRESULT DoAGC();
  86. void EndMessage();
  87. void StartMessage();
  88. HRESULT TransmitFrame();
  89. protected: // FSM
  90. HRESULT BuildAndTransmitSpeechHeader( BOOL bSendToServer );
  91. HRESULT BuildAndTransmitSpeechWithTarget( BOOL bSendToServer );
  92. HRESULT RecordFSM();
  93. HRESULT HandleAutoVolumeAdjust();
  94. HRESULT CleanupForReset();
  95. HRESULT ResetForLockup();
  96. void InitStats();
  97. void BeginStats();
  98. void CompleteStats();
  99. protected:
  100. DWORD m_dwSignature;
  101. DWORD m_dwSilentTime; // # of ms that the input has been silent
  102. DWORD m_dwFrameTime; // Amount of ms per frame
  103. CAGCVA* m_pagcva; // Auto Gain control and Voice Activation algorithm
  104. void DoFrameCheck();
  105. protected:
  106. RecordState m_recordState; // Current state of the FSM
  107. PDPVCOMPRESSOR m_converter; // AudioConverter for outgoing data
  108. DWORD m_uncompressedSize; // Size of frame in uncompressed format
  109. DWORD m_compressedSize; // Maximum size in bytes of compressed frame
  110. BOOL m_eightBit; // Is recording format 8-bit?
  111. DWORD m_remain; // # of trailing frames we should have
  112. unsigned char m_currentBuffer; // Buffer ID of current recording buffer
  113. unsigned long m_framesPerPeriod; // # of subbuffers in the recording bfufer
  114. CDirectVoiceClientEngine *m_clientEngine; // The client engine this subsystem is for
  115. BOOL m_transmitFrame; // Transmit Current frame?
  116. unsigned char *m_bufferPtr; // Pointer to current buffer?
  117. DWORD m_dwSilenceTimeout; // Amount of silence in ms before transmissions tops
  118. BOOL m_lastFrameTransmitted;
  119. // Was the last frame transmitted
  120. unsigned char m_msgNum; // Current message number
  121. unsigned char m_seqNum; // Current sequence #
  122. LPBYTE m_pbConstructBuffer;
  123. DWORD m_dwCurrentPower; // Power level of the last packet
  124. DWORD m_dwLastTargetVersion; // Version of target info on last frame (to check for changes)
  125. LONG m_lSavedVolume; // System record volume when recording started
  126. BOOL m_fRecordVolumeSaved; // Was the system record volume saved?
  127. DWORD m_dwResetCount;
  128. DWORD m_dwNextReadPos;
  129. DWORD m_dwLastReadPos;
  130. DWORD m_dwLastBufferPos;
  131. DWORD m_dwPassesSincePosChange;
  132. BOOL m_fIgnoreFrame;
  133. DWORD m_dwLastFrameTime; // GetTickCount() at last frame
  134. BOOL m_fLostFocus;
  135. DWORD m_dwFrameCount;
  136. DVID *m_prgdvidTargetCache;
  137. DWORD m_dwTargetCacheSize;
  138. DWORD m_dwTargetCacheEntries;
  139. DWORD m_dwFullBufferSize; // Cached version of m_uncompressedSize*m_framesPerPeriod
  140. };
  141. #endif