-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from GetStream/PBE-6272-Reduce-microphone-del…
…ay-attempt Fix Microphone delay -> Sync Mic recording & playback buffers + play AudioSource right after recording started
- Loading branch information
Showing
6 changed files
with
139 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Packages/StreamVideo/Runtime/Core/Utils/DebugStopwatchScope.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using StreamVideo.Libs.Logs; | ||
|
||
namespace StreamVideo.Core.Utils | ||
{ | ||
/// <summary> | ||
/// [ONLY IF STREAM_DEBUG_ENABLED] Measure scope execution. | ||
/// </summary> | ||
internal class DebugStopwatchScope : IDisposable | ||
{ | ||
public enum Units | ||
{ | ||
MilliSeconds, | ||
Seconds, | ||
Minutes | ||
} | ||
|
||
public DebugStopwatchScope(ILogs logs, string message, Units units = Units.MilliSeconds) | ||
{ | ||
#if STREAM_DEBUG_ENABLED | ||
_message = !message.IsNullOrEmpty() ? message : throw new ArgumentException(""); | ||
_units = units; | ||
_logs = logs ?? throw new ArgumentNullException(nameof(logs)); | ||
_sw = new Stopwatch(); | ||
_sw.Start(); | ||
#endif | ||
} | ||
|
||
private readonly ILogs _logs; | ||
private readonly Stopwatch _sw; | ||
private readonly Units _units; | ||
private readonly string _message; | ||
|
||
public void Dispose() | ||
{ | ||
#if STREAM_DEBUG_ENABLED | ||
_sw.Stop(); | ||
_logs.Warning($"`{_message}` executed in: {GetTimeLog()}"); | ||
#endif | ||
} | ||
|
||
private string GetTimeLog() | ||
{ | ||
switch (_units) | ||
{ | ||
case Units.MilliSeconds: return $"{_sw.Elapsed.TotalMilliseconds} ms"; | ||
case Units.Seconds: return $"{_sw.Elapsed.TotalSeconds} s"; | ||
case Units.Minutes: return $"{_sw.Elapsed.TotalMinutes} min"; | ||
default: | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Packages/StreamVideo/Runtime/Core/Utils/DebugStopwatchScope.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters