Skip to content

Commit

Permalink
Move NetworkStream and FileStream to std::unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
palana committed Sep 24, 2014
1 parent e7804fc commit 858991b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
7 changes: 2 additions & 5 deletions Source/OBS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2146,17 +2146,14 @@ NetworkStream* CreateNullNetwork();

void OBS::RestartNetwork()
{
NetworkStream *tmp;
OSEnterMutex(App->hStartupShutdownMutex);

//delete the old one
tmp = App->network;
App->network = nullptr;
delete tmp;
App->network.reset();

//start up a new one
App->bSentHeaders = false;
App->network = CreateRTMPPublisher();
App->network.reset(CreateRTMPPublisher());

OSLeaveMutex(App->hStartupShutdownMutex);
}
4 changes: 2 additions & 2 deletions Source/OBS.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ class OBS

//---------------------------------------------------

NetworkStream *network;
std::unique_ptr<NetworkStream> network;

//---------------------------------------------------
// audio sources/encoder
Expand Down Expand Up @@ -828,7 +828,7 @@ class OBS
bool bUseCFR;

bool bWriteToFile;
VideoFileStream *fileStream;
std::unique_ptr<VideoFileStream> fileStream;

std::unique_ptr<VideoFileStream> replayBufferStream;
ReplayBuffer *replayBuffer;
Expand Down
35 changes: 9 additions & 26 deletions Source/OBSCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ bool OBS::StartRecording(bool force)
bool success = true;
if(!bTestStream && bWriteToFile && strOutputFile.IsValid())
{
fileStream = CreateFileStream(strOutputFile);
fileStream.reset(CreateFileStream(strOutputFile));

if(!fileStream)
{
Expand All @@ -290,15 +290,9 @@ void OBS::StopRecording()

if(!bRecording) return;

VideoFileStream *tempStream = NULL;

tempStream = fileStream;
// Prevent the encoder thread from trying to write to fileStream while it's closing
fileStream = NULL;

delete tempStream;
tempStream = NULL;
bRecording = false;
auto stream = move(fileStream);

ReportStopRecordingTrigger();

Expand All @@ -317,13 +311,7 @@ void OBS::Start(bool recordingOnly, bool replayBufferOnly)
if((bRecording || bRecordingReplayBuffer) && networkMode == 0 && delayTime == 0 && !recordingOnly && !replayBufferOnly) {
bFirstConnect = !bReconnecting;

if (network)
{
NetworkStream *net = network;
network = nullptr;
delete net;
}
network = CreateRTMPPublisher();
network.reset(CreateRTMPPublisher());

Log(TEXT("=====Stream Start (while recording): %s============================="), CurrentDateTimeString().Array());

Expand Down Expand Up @@ -444,13 +432,13 @@ void OBS::Start(bool recordingOnly, bool replayBufferOnly)
bFirstConnect = !bReconnecting;

if(bTestStream || recordingOnly || replayBufferOnly)
network = CreateNullNetwork();
network.reset(CreateNullNetwork());
else
{
switch(networkMode)
{
case 0: network = (delayTime > 0) ? CreateDelayedPublisher(delayTime) : CreateRTMPPublisher(); break;
case 1: network = CreateNullNetwork(); break;
case 0: network.reset((delayTime > 0) ? CreateDelayedPublisher(delayTime) : CreateRTMPPublisher()); break;
case 1: network.reset(CreateNullNetwork()); break;
}
}

Expand Down Expand Up @@ -529,7 +517,7 @@ void OBS::Start(bool recordingOnly, bool replayBufferOnly)
if (ret == IDABORT)
{
//FIXME: really need a better way to abort startup than this...
delete network;
network.reset();
delete GS;

DisableMenusWhileStreaming(false);
Expand Down Expand Up @@ -899,15 +887,11 @@ void OBS::Stop(bool overrideKeepRecording)
int networkMode = AppConfig->GetInt(TEXT("Publish"), TEXT("Mode"), 2);

if(((!overrideKeepRecording && bRecording && bKeepRecording) || bRecordingReplayBuffer) && networkMode == 0) {
NetworkStream *tempStream = NULL;

videoEncoder->RequestKeyframe();
tempStream = network;
network = NULL;

Log(TEXT("=====Stream End (recording continues): %s========================="), CurrentDateTimeString().Array());
network.reset();

delete tempStream;

bStreaming = false;
bSentHeaders = false;
Expand Down Expand Up @@ -978,8 +962,7 @@ void OBS::Stop(bool overrideKeepRecording)

//-------------------------------------------------------------

delete network;
network = NULL;
network.reset();
if (bStreaming) ReportStopStreamingTrigger();
bStreaming = false;

Expand Down

0 comments on commit 858991b

Please sign in to comment.