Skip to content

Commit 5662902

Browse files
committed
feat: improve Output.Stop method with timeout handling and return status
1 parent f853018 commit 5662902

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

src/ObsKit.NET/Outputs/Output.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,24 @@ public bool Start()
124124
/// Stops the output.
125125
/// </summary>
126126
/// <param name="waitForCompletion">If true, waits for the output to fully stop.</param>
127-
/// <param name="timeoutMs">Maximum time to wait in milliseconds (default 5000).</param>
128-
public void Stop(bool waitForCompletion = true, int timeoutMs = 5000)
127+
/// <param name="timeoutMs">Maximum time to wait in milliseconds (default 30000).</param>
128+
/// <returns>True if the output stopped successfully, false if timed out.</returns>
129+
public bool Stop(bool waitForCompletion = true, int timeoutMs = 30000)
129130
{
131+
if (!IsActive) return true;
132+
130133
ObsOutput.obs_output_stop(Handle);
131134

132135
if (waitForCompletion)
133136
{
134-
var startTime = Environment.TickCount;
135-
while (IsActive && (Environment.TickCount - startTime) < timeoutMs)
137+
var startTime = Environment.TickCount64;
138+
while (IsActive && (Environment.TickCount64 - startTime) < timeoutMs)
136139
{
137-
Thread.Sleep(10);
140+
Thread.Sleep(50);
138141
}
139142
}
143+
144+
return !IsActive;
140145
}
141146

142147
/// <summary>

src/ObsKit.NET/Outputs/RecordingOutput.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,8 @@ public RecordingOutput WithNvencEncoders(int videoBitrate = 6000, int audioBitra
199199
}
200200

201201
/// <summary>Stops the recording.</summary>
202-
public void Stop()
203-
{
204-
base.Stop();
205-
}
202+
/// <returns>True if the recording stopped successfully, false if timed out.</returns>
203+
public bool Stop() => base.Stop();
206204

207205
/// <inheritdoc/>
208206
protected override void Dispose(bool disposing)

src/ObsKit.NET/Outputs/ReplayBuffer.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,8 @@ public void Save()
197197
}
198198

199199
/// <summary>Stops the replay buffer.</summary>
200-
public void Stop()
201-
{
202-
base.Stop();
203-
}
200+
/// <returns>True if the replay buffer stopped successfully, false if timed out.</returns>
201+
public bool Stop() => base.Stop();
204202

205203
/// <inheritdoc/>
206204
protected override void Dispose(bool disposing)

0 commit comments

Comments
 (0)