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.

120 lines
4.3 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // INTEL Corporation Proprietary Information
  3. // This listing is supplied under the terms of a license agreement with Intel
  4. // Corporation and many not be copied nor disclosed except in accordance
  5. // with the terms of that agreement.
  6. // Copyright (c) 1995, 1996 Intel Corporation.
  7. //
  8. //
  9. // Module Name: lhsnd.cpp
  10. // Environment: MSVC 4.0, OLE 2
  11. /////////////////////////////////////////////////////////////////////////////////
  12. #include "lhsnd.h"
  13. #include "ppmerr.h"
  14. #include "debug.h"
  15. LH_ppmSend::LH_ppmSend(IUnknown* pUnkOuter, IUnknown** ppUnkInner) :
  16. ppmSend(-1, 0, 8000, pUnkOuter, ppUnkInner), m_delta(120),
  17. m_dwLastTimeStamp(0)
  18. {
  19. }
  20. LH_ppmSend::~LH_ppmSend()
  21. {
  22. }
  23. IMPLEMENT_CREATEPROC(LH_ppmSend);
  24. //////////////////////////////////////////////////////////////////////////////
  25. // IPPMSend Functions (Overrides)
  26. //////////////////////////////////////////////////////////////////////////////
  27. HRESULT LH_ppmSend::SetSession(PPMSESSPARAM_T *pSessparam)
  28. {
  29. HRESULT hr = ppmSend::SetSession(pSessparam);
  30. LHSESSPARAM_T *pLHSessparam = (LHSESSPARAM_T *)pSessparam;
  31. if (pLHSessparam != NULL && pLHSessparam->msec > 0)
  32. m_delta = pLHSessparam->msec;
  33. else {
  34. DBG_MSG(DBG_ERROR, ("LH_ppmSend::SetSession: ERROR - invalid session parameters"));
  35. return PPMERR(PPM_E_INVALID_PARAM);
  36. }
  37. return hr;
  38. }
  39. //////////////////////////////////////////////////////////////////////////////
  40. // PPMSend Functions (Overrides)
  41. //////////////////////////////////////////////////////////////////////////////
  42. //////////////////////////////////////////////////////////////////////////////////////////
  43. //SetMarkerBit: Determines whether to set the marker bit or not. lastPacket is TRUE if
  44. // this is the last packet of the frame; FALSE if not. With audio, we don't
  45. // don't care about fragmentation, just the start of a talkspurt.
  46. //////////////////////////////////////////////////////////////////////////////////////////
  47. BOOL LH_ppmSend::SetMarkerBit(BOOL lastPacket)
  48. {
  49. return m_markTalkSpurt;
  50. }
  51. //////////////////////////////////////////////////////////////////////////////////////////
  52. //MakeTimeStamp: Generate a time stamp based on the frequency specified in the Profile Spec.
  53. //////////////////////////////////////////////////////////////////////////////////////////
  54. DWORD LH_ppmSend::MakeTimeStamp(MsgDescriptor* pMsgDescrip,
  55. BOOL bStartStream,
  56. BOOL bUseInputTime)
  57. {
  58. #ifndef TIMESTAMP_OFF
  59. DWORD ThisTimeStamp;
  60. DWORD CurTime = timeGetTime();
  61. DWORD epsilon;
  62. if (bUseInputTime) CurTime = pMsgDescrip->m_TimeStamp;
  63. // calculate the time span encoded in this packet
  64. epsilon = m_delta/2;
  65. // init, do it here so it is set when we get the first packet
  66. // not at init time, they may be significantly different
  67. // Generate our first time stamp based on the current time.
  68. if (m_dwStartTime == 0)
  69. {
  70. m_dwStartTime = CurTime;
  71. m_dwLastTime = m_dwStartTime - m_delta;
  72. ThisTimeStamp = (((CurTime - m_dwStartTime) + (epsilon)) / m_delta) * m_delta * (m_Frequency/1000);
  73. }
  74. else
  75. if (bStartStream)
  76. {
  77. // bStartStream will be set if this is the first packet after a break in a
  78. // data stream. We need to get our time stamps back on track, so we'll generate a time
  79. // based on the current time. This case can happen if for some reason the capture device
  80. // gets starved or we are in half duplex and we are switching to talk mode.
  81. ThisTimeStamp = (((CurTime - m_dwStartTime) + (epsilon)) / m_delta) * m_delta * (m_Frequency/1000);
  82. }
  83. else
  84. {
  85. // if we are in a continuous audio data stream, then we just want to increment our timestamp
  86. // for this data packet. We don't want to use the current time because we don't know how long
  87. // it took from the time the data was acutally captured to the time we got it. We have to rely
  88. // on the person feeding us data to let us know more information about the data stream.
  89. ThisTimeStamp = m_dwLastTimeStamp + m_delta * (m_Frequency/1000);
  90. }
  91. m_dwLastTimeStamp = ThisTimeStamp;
  92. m_dwLastTime = CurTime;
  93. return ThisTimeStamp;
  94. #else
  95. //I changed this because the times I was getting were widely spaced. When I was in debugging
  96. //mode.
  97. static DWORD CurTime = 0;
  98. CurTime++;
  99. #endif
  100. return CurTime;
  101. }