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.

121 lines
4.1 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: g711snd.cpp
  10. // Environment: MSVC 4.0, OLE 2
  11. /////////////////////////////////////////////////////////////////////////////////
  12. #include "g711snd.h"
  13. G711_ppmSend::G711_ppmSend(IUnknown* pUnkOuter,
  14. IUnknown** ppUnkInner) :
  15. ppmSend(G711_PT, 0,
  16. 8000, pUnkOuter, ppUnkInner),
  17. m_dwLastTimeStamp(0)
  18. {
  19. }
  20. G711_ppmSend::~G711_ppmSend()
  21. {
  22. }
  23. IMPLEMENT_CREATEPROC(G711_ppmSend);
  24. //////////////////////////////////////////////////////////////////////////////////////////
  25. //SetMarkerBit: Determines whether to set the marker bit or not. lastPacket is TRUE if
  26. // this is the last packet of the frame; FALSE if not. With audio, we don't
  27. // don't care about fragmentation, just the start of a talkspurt.
  28. //////////////////////////////////////////////////////////////////////////////////////////
  29. BOOL G711_ppmSend::SetMarkerBit(BOOL lastPacket)
  30. {
  31. return m_markTalkSpurt;
  32. }
  33. //////////////////////////////////////////////////////////////////////////////////////////
  34. //MakeTimeStamp: Generate a time stamp based on the frequency specified in the Profile Spec.
  35. //////////////////////////////////////////////////////////////////////////////////////////
  36. DWORD G711_ppmSend::MakeTimeStamp(MsgDescriptor* pMsgDescrip,
  37. BOOL bStartStream,
  38. BOOL bUseInputTime)
  39. {
  40. #ifndef TIMESTAMP_OFF
  41. DWORD ThisTimeStamp;
  42. DWORD CurTime = timeGetTime();
  43. DWORD delta;
  44. DWORD epsilon;
  45. if (bUseInputTime) CurTime = pMsgDescrip->m_TimeStamp;
  46. // calculate the time span encoded in this packet
  47. delta = CountFrames((char *) pMsgDescrip->m_pBuffer, pMsgDescrip->m_Size) / (m_Frequency/1000);
  48. epsilon = delta/2;
  49. // init, do it here so it is set when we get the first packet
  50. // not at init time, they may be significantly different
  51. // Generate our first time stamp based on the current time.
  52. if (m_dwStartTime == 0)
  53. {
  54. // if the first packet we receive is a drop or silence then the delta will
  55. // be zero. We just won't do anything until we receive valid data.
  56. if (delta != 0)
  57. {
  58. m_dwStartTime = CurTime;
  59. m_dwLastTime = m_dwStartTime - delta;
  60. ThisTimeStamp = (((CurTime - m_dwStartTime) + (epsilon)) / delta) * delta * (m_Frequency/1000);
  61. }
  62. }
  63. else
  64. if (bStartStream)
  65. {
  66. // bStartStream will be set if this is the first packet after a break in a
  67. // data stream. We need to get our time stamps back on track, so we'll generate a time
  68. // based on the current time. This case can happen if for some reason the capture device
  69. // gets starved or we are in half duplex and we are switching to talk mode.
  70. if (delta != 0)
  71. {
  72. ThisTimeStamp = (((CurTime - m_dwStartTime) + (epsilon)) / delta) * delta * (m_Frequency/1000);
  73. }
  74. else
  75. {
  76. ThisTimeStamp = (((CurTime - m_dwStartTime) + (epsilon)) / m_dwLastDelta) * m_dwLastDelta * (m_Frequency/1000);
  77. ThisTimeStamp -= m_dwLastDelta * (m_Frequency/1000);
  78. }
  79. }
  80. else
  81. {
  82. // if we are in a continuous audio data stream, then we just want to increment our timestamp
  83. // for this data packet. We don't want to use the current time because we don't know how long
  84. // it took from the time the data was acutally captured to the time we got it. We have to rely
  85. // on the person feeding us data to let us know more information about the data stream.
  86. ThisTimeStamp = m_dwLastTimeStamp + CountFrames((char *) pMsgDescrip->m_pBuffer, pMsgDescrip->m_Size);
  87. }
  88. m_dwLastTimeStamp = ThisTimeStamp;
  89. m_dwLastTime = CurTime;
  90. if (delta != 0)
  91. {
  92. m_dwLastDelta = delta;
  93. }
  94. return ThisTimeStamp;
  95. #else
  96. //I changed this because the times I was getting were widely spaced. When I was in debugging
  97. //mode.
  98. static DWORD CurTime = 0;
  99. CurTime++;
  100. #endif
  101. return CurTime;
  102. }
  103. int G711_ppmSend::CountFrames(char *ipBuffer, int len)
  104. {
  105. return len; //1 byte per frame
  106. }