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.

227 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. Confaud.h
  5. Abstract:
  6. Definitions for audio streams
  7. Author:
  8. Mu Han (muhan) 15-September-1998
  9. --*/
  10. #ifndef __CONFAUD_H_
  11. #define __CONFAUD_H_
  12. #include <amrtpdmx.h> // demux guid
  13. #include <amrtpss.h> // AGC events
  14. #define USE_WIDEBAND_CODEC 1
  15. const DWORD g_dwMaxAudioPacketDuration = 80;
  16. const DWORD g_dwAudioThreadPriority = THREAD_PRIORITY_TIME_CRITICAL;
  17. const WORD g_wAudioDemuxPins = 5;
  18. const WORD g_wAudioChannels = 1;
  19. const DWORD g_wAudioCaptureBitPerSample = 16;
  20. const DWORD g_dwAudioCaptureNumBufffers = 32;
  21. const DWORD g_dwRTPHeaderSize = 12;
  22. const DWORD g_dwG711MSPerPacket = 30; // 30ms samples.
  23. const DWORD g_dwG711BytesPerPacket = 240; // 30ms samples.
  24. const DWORD g_dwG711AudioSampleRate = 8000;
  25. const DWORD g_dwMaxG711PacketSize =
  26. g_dwMaxAudioPacketDuration * g_dwG711BytesPerPacket / g_dwG711MSPerPacket
  27. + g_dwRTPHeaderSize;
  28. const DWORD g_dwGSMMSPerPacket = 40; // 40ms samples.
  29. const DWORD g_dwGSMBytesPerPacket = 65; // 40ms samples.
  30. const DWORD g_dwGSMAudioSampleRate = 8000;
  31. const WORD g_wGSMBlockAlignment = 65; // 40ms samples.
  32. const DWORD g_dwGSMBytesPerSecond =
  33. g_dwGSMBytesPerPacket * 1000 / g_dwGSMMSPerPacket;
  34. const DWORD g_wGSMSamplesPerBlock =
  35. g_dwGSMMSPerPacket * g_dwGSMAudioSampleRate / 1000;
  36. const DWORD g_dwMaxGSMPacketSize =
  37. g_dwMaxAudioPacketDuration / g_dwGSMMSPerPacket * g_dwGSMBytesPerPacket
  38. + g_dwRTPHeaderSize;
  39. #ifdef DVI
  40. const DWORD g_dwDVI4MSPerPacket = 80; // 80 ms samples.
  41. const WORD g_wDVI4BlockAlignment = 324;
  42. const DWORD g_dwDVI4BytesPerPacket = g_wDVI4BlockAlignment;
  43. const DWORD g_wDVI4BitsPerSample = 4;
  44. const DWORD g_dwDVI4AudioSampleRate = 8000;
  45. const DWORD g_dwMaxDVI4PacketSize = g_dwDVI4BytesPerPacket + g_dwRTPHeaderSize;
  46. const DWORD g_dwDVI4BytesPerSecond = 4000; // ignore header here.
  47. const DWORD g_wDVI4SamplesPerBlock =
  48. (g_wDVI4BlockAlignment - 4) * 8 / g_wDVI4BitsPerSample + 1;
  49. #endif
  50. // MSAudio defines
  51. #define WAVE_FORMAT_MSAUDIO1 0x0160
  52. typedef struct msaudio1waveformat_tag {
  53. WAVEFORMATEX wfx;
  54. //only counting "new" samples "= half of what will be used due to overlapping
  55. WORD wSamplesPerBlock;
  56. } MSAUDIO1WAVEFORMAT;
  57. #define MSAUDIO1_BITS_PER_SAMPLE 0
  58. #define MSAUDIO1_MAX_CHANNELS 1
  59. #define MSAUDIO1_WFX_EXTRA_BYTES 2
  60. #ifdef USE_WIDEBAND_CODEC
  61. // At 16kHz,
  62. #define FRAME_TIME 64
  63. #define PACKET_SIZE 64
  64. #define BYTES_PER_SECOND 1920
  65. #define SAMPLES_PER_BLOCK 512
  66. #else
  67. // At 8kHz,
  68. #define FRAME_TIME 64
  69. #define PACKET_SIZE 32
  70. #define BYTES_PER_SECOND 960
  71. #define SAMPLES_PER_BLOCK 256
  72. #endif
  73. const DWORD g_dwMSAudioMSPerPacket = FRAME_TIME; // This will make sure that we always capture 1024 byte PCM16 buffers (at 8kHz: 512 samples = 64ms, at 16kHz: 512 samples = 32ms)
  74. const DWORD g_dwMSAudioBytesPerPacket = PACKET_SIZE; // The MS Audio codec will only use 512 bytes of an PCM16 input buffer of size 1024 bytes and generate a 32 bytes frame
  75. const DWORD g_dwMSAudioSampleRate = 16000;
  76. const WORD g_wMSAudioBlockAlignment = PACKET_SIZE; // 32 bytes of block alignment.
  77. const DWORD g_dwMSAudioBytesPerSecond = BYTES_PER_SECOND; // 8kHz: Measurements show that a 8000 samples buffer is compressed to 960 bytes
  78. const WORD g_wMSAudioExtraDataSize = 2;
  79. const DWORD g_wMSAudioSamplesPerBlock = SAMPLES_PER_BLOCK;
  80. // We only care to be able to send and receive MSAudio packets that contain 64ms worth of data.
  81. const DWORD g_dwMaxMSAudioPacketSize = g_dwMSAudioBytesPerPacket + g_dwRTPHeaderSize; // 8kHz: 32 + 12 bytes
  82. inline DWORD AudioCaptureBufferSize(DWORD dwMillisecondPerPacket, DWORD dwAudioSampleRate)
  83. {
  84. return dwMillisecondPerPacket
  85. * (dwAudioSampleRate / 1000)
  86. * (g_wAudioCaptureBitPerSample / 8);
  87. }
  88. class ATL_NO_VTABLE CStreamAudioRecv :
  89. public CIPConfMSPStream
  90. {
  91. public:
  92. CStreamAudioRecv();
  93. void FinalRelease();
  94. HRESULT Configure(
  95. IN STREAMSETTINGS & StreamSettings
  96. );
  97. protected:
  98. HRESULT SetUpFilters();
  99. HRESULT ConfigureRTPFilter(
  100. IN IBaseFilter * pIBaseFilter
  101. );
  102. HRESULT SetUpInternalFilters();
  103. HRESULT ConnectTerminal(
  104. IN ITTerminal * pITTerminal
  105. );
  106. HRESULT ProcessSSRCMappedEvent(
  107. IN DWORD dwSSRC
  108. );
  109. HRESULT ProcessSSRCUnmapEvent(
  110. IN DWORD dwSSRC
  111. );
  112. HRESULT ProcessGraphEvent(
  113. IN long lEventCode,
  114. IN long lParam1,
  115. IN long lParam2
  116. );
  117. HRESULT ProcessParticipantLeave(
  118. IN DWORD dwSSRC
  119. );
  120. HRESULT NewParticipantPostProcess(
  121. IN DWORD dwSSRC,
  122. IN ITParticipant *pITParticipant
  123. );
  124. protected:
  125. BOOL m_fUseACM;
  126. DWORD m_dwMaxPacketSize;
  127. DWORD m_dwAudioSampleRate;
  128. BYTE * m_pWaveFormatEx;
  129. DWORD m_dwSizeWaveFormatEx;
  130. // a small buffer to queue up pin mapped events.
  131. CMSPArray <DWORD> m_PendingSSRCs;
  132. };
  133. class ATL_NO_VTABLE CStreamAudioSend : public CIPConfMSPStream
  134. {
  135. public:
  136. CStreamAudioSend();
  137. virtual HRESULT Configure(
  138. IN STREAMSETTINGS &StreamSettings
  139. );
  140. protected:
  141. HRESULT SetUpFilters();
  142. HRESULT ConnectTerminal(
  143. IN ITTerminal * pITTerminal
  144. );
  145. HRESULT CreateSendFilters(
  146. IN IPin *pPin
  147. );
  148. HRESULT ConfigureRTPFilter(
  149. IN IBaseFilter * pIBaseFilter
  150. );
  151. HRESULT ConfigureAudioCaptureTerminal(
  152. IN ITTerminalControl * pTerminal,
  153. OUT IPin ** ppIPin
  154. );
  155. HRESULT ProcessAGCEvent(
  156. IN AGC_EVENT Event,
  157. IN long lPercent
  158. );
  159. HRESULT ProcessGraphEvent(
  160. IN long lEventCode,
  161. IN long lParam1,
  162. IN long lParam2
  163. );
  164. protected:
  165. BOOL m_fUseACM;
  166. int m_iACMID;
  167. DWORD m_dwMSPerPacket;
  168. DWORD m_dwMaxPacketSize;
  169. DWORD m_dwAudioSampleRate;
  170. };
  171. #endif