From 70b43222297565a0418bb2ee9db0de9a34155f7a Mon Sep 17 00:00:00 2001 From: palana Date: Tue, 16 Sep 2014 17:48:23 +0200 Subject: [PATCH] Add ClosableStream support to file recording --- Source/OBS.h | 3 ++- Source/OBSCapture.cpp | 27 ++++++++++++++++++++++----- Source/OBSVideoCapture.cpp | 5 ++++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Source/OBS.h b/Source/OBS.h index 6b6080919..c785489e5 100644 --- a/Source/OBS.h +++ b/Source/OBS.h @@ -847,6 +847,7 @@ class OBS bool bWriteToFile; std::unique_ptr fileStream; + StopInfo fileStreamStop; std::unique_ptr replayBufferStream; ReplayBuffer *replayBuffer; @@ -1020,7 +1021,7 @@ class OBS void Start(bool recordingOnly=false, bool replayBufferOnly=false); void Stop(bool overrideKeepRecording=false, bool stopReplayBuffer=false); bool StartRecording(bool force=false); - void StopRecording(); + void StopRecording(bool immediate=false); void StartReplayBuffer(); void StopReplayBuffer(bool immediate=false); diff --git a/Source/OBSCapture.cpp b/Source/OBSCapture.cpp index 6ef188b60..d0729605f 100644 --- a/Source/OBSCapture.cpp +++ b/Source/OBSCapture.cpp @@ -296,7 +296,7 @@ bool OBS::StartRecording(bool force) return success; } -void OBS::StopRecording() +void OBS::StopRecording(bool immediate) { if (!bStreaming && !bRecordingReplayBuffer && bRunning && bRecording) Stop(true); @@ -304,11 +304,28 @@ void OBS::StopRecording() // Prevent the encoder thread from trying to write to fileStream while it's closing - auto stream = move(fileStream); + if (!immediate && fileStreamStop.func) + return; - ReportStopRecordingTrigger(); + auto shutdown = [this]() + { + AddPendingStream(fileStream.release()); - ConfigureStreamButtons(); + bRecording = false; + + ReportStopRecordingTrigger(); + + ConfigureStreamButtons(); + + if (!bStreaming && !bRecordingReplayBuffer && bRunning && !bRecording) PostStopMessage(true); + }; + + if (immediate) + return shutdown(); + + fileStreamStop.func = shutdown; + + fileStreamStop.time = (DWORD)(GetVideoTime() - firstFrameTimestamp); } void OBS::Start(bool recordingOnly, bool replayBufferOnly) @@ -978,7 +995,7 @@ void OBS::Stop(bool overrideKeepRecording, bool stopReplayBuffer) if (bStreaming) ReportStopStreamingTrigger(); bStreaming = false; - if(bRecording) StopRecording(); + if (bRecording) StopRecording(true); if (bRecordingReplayBuffer) StopReplayBuffer(true); delete micAudio; diff --git a/Source/OBSVideoCapture.cpp b/Source/OBSVideoCapture.cpp index 439402584..4816c7b33 100644 --- a/Source/OBSVideoCapture.cpp +++ b/Source/OBSVideoCapture.cpp @@ -215,7 +215,10 @@ void OBS::SendFrame(VideoSegment &curSegment, QWORD firstFrameTime) { auto shared_data = std::make_shared>(packet.data.Array(), packet.data.Array() + packet.data.Num()); if (fileStream) - fileStream->AddPacket(shared_data, curSegment.timestamp, curSegment.pts, packet.type); + { + if (!HandleStreamStopInfo(fileStreamStop, packet.type, curSegment)) + fileStream->AddPacket(shared_data, curSegment.timestamp, curSegment.pts, packet.type); + } if (replayBufferStream) { if (!HandleStreamStopInfo(replayBufferStop, packet.type, curSegment))