Skip to content

Commit

Permalink
Add ClosableStream support to file recording
Browse files Browse the repository at this point in the history
  • Loading branch information
palana committed Sep 24, 2014
1 parent 25c1a11 commit 70b4322
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Source/OBS.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ class OBS

bool bWriteToFile;
std::unique_ptr<VideoFileStream> fileStream;
StopInfo fileStreamStop;

std::unique_ptr<VideoFileStream> replayBufferStream;
ReplayBuffer *replayBuffer;
Expand Down Expand Up @@ -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);

Expand Down
27 changes: 22 additions & 5 deletions Source/OBSCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,36 @@ bool OBS::StartRecording(bool force)
return success;
}

void OBS::StopRecording()
void OBS::StopRecording(bool immediate)
{
if (!bStreaming && !bRecordingReplayBuffer && bRunning && bRecording) Stop(true);

if(!bRecording) return;

// 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)
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion Source/OBSVideoCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ void OBS::SendFrame(VideoSegment &curSegment, QWORD firstFrameTime)
{
auto shared_data = std::make_shared<const std::vector<BYTE>>(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))
Expand Down

0 comments on commit 70b4322

Please sign in to comment.