Search Unity

Voip application using winmm.dll make unity not responding

Discussion in 'Editor & General Support' started by tushar1985, Jun 10, 2019.

  1. tushar1985

    tushar1985

    Joined:
    May 7, 2013
    Posts:
    5
    Hi,

    I am trying to convert a VOIP application into unity application

    https://www.codeproject.com/Articles/482735/TCP-Audio-Streamer-and-Player-Voice-Chat-over-IP

    ,and there is a code for the timer which is basically a high precision timer implement using winmm.dll.

    starting the Timer:
    Code (CSharp):
    1.  
    2. global::WinSound.Win32.TimeCaps tc = new global::WinSound.Win32.TimeCaps();
    3. global::WinSound.Win32.TimeGetDevCaps(ref tc,                       (uint)Marshal.SizeOf(typeof(global::WinSound.Win32.TimeCaps)));
    4.  m_ResolutionInMilliseconds = Math.Max(tc.wPeriodMin, 0);
    5.  
    6. global::WinSound.Win32.TimeBeginPeriod(m_ResolutionInMilliseconds);
    7.  
    8. m_TimerId = global::WinSound.Win32.TimeSetEvent(m_Milliseconds, m_ResolutionInMilliseconds, m_DelegateTimeEvent, ref m_UserData, (UInt32)Win32.TIME_PERIODIC);
    9.  
    10. if (m_TimerId > 0)
    11.  {
    12.         m_GCHandleTimer = GCHandle.Alloc(m_TimerId, GCHandleType.Pinned);
    13.         m_IsRunning = true;
    14.   }
    15.  
    16.  
    and stop the timer:

    Code (CSharp):
    1.  
    2. global:: WinSound.Win32.TimeKillEvent(m_TimerId);
    3. global::WinSound.Win32.TimeEndPeriod(m_ResolutionInMilliseconds);
    4. if (m_GCHandleTimer.IsAllocated)
    5. {
    6.          m_GCHandleTimer.Free();
    7. }
    8.  
    but global:: WinSound.Win32.TimeKillEvent(m_TimerId); is somehow making unity not responding, if i try to rerun by going into the play mode again or try to quit the editor.

    I also tried CreateTimerQueueTimer after reading the MSDN documentation but same result.

    starting the Timer:
    Code (CSharp):
    1.  
    2.  
    3. global::WinSound.Win32.TimeBeginPeriod(m_ResolutionInMilliseconds);
    4.  
    5. m_HandleTimerQueue = global::WinSound.Win32.CreateTimerQueue();
    6. m_GCHandleTimerQueue = GCHandle.Alloc(m_HandleTimerQueue);
    7.  
    8.            
    9.  bool resultCreate = global::WinSound.Win32.CreateTimerQueueTimer(out m_HandleTimer, m_HandleTimerQueue, m_DelegateTimerProc, IntPtr.Zero, dueTimeInMilliseconds, m_Milliseconds,
    10. global::WinSound.Win32.WT_EXECUTEINTIMERTHREAD);
    11.  
    12.  if (resultCreate)
    13.  {
    14.         m_GCHandleTimer = GCHandle.Alloc(m_HandleTimer, GCHandleType.Pinned);
    15.         m_IsRunning = true;
    16.  }
    17.  
    Stoping the Timer:
    Code (CSharp):
    1.  
    2. global:: WinSound.Win32.DeleteTimerQueueTimer(IntPtr.Zero, m_HandleTimer, IntPtr.Zero);
    3.  
    4. global::WinSound.Win32.TimeEndPeriod(m_ResolutionInMilliseconds);
    5.  
    6. if (m_HandleTimerQueue != IntPtr.Zero)
    7. {
    8.      global::WinSound.Win32.DeleteTimerQueue(m_HandleTimerQueue);
    9. }
    10.  
    11. if (m_GCHandleTimer.IsAllocated)
    12. {
    13.      m_GCHandleTimer.Free();
    14. }
    15.  
    16. if (m_GCHandleTimerQueue.IsAllocated)
    17. {
    18.     m_GCHandleTimerQueue.Free();
    19. }
    20.  
    21.  
    this time on instruction global::WinSound.Win32.DeleteTimerQueue(m_HandleTimerQueue);

    anyone has any idea why ?
     
  2. melanchall

    melanchall

    Joined:
    May 25, 2018
    Posts:
    17
    I have the same problem with winmm timers. Did you find a solution?
     
  3. melanchall

    melanchall

    Joined:
    May 25, 2018
    Posts:
    17