Skip to content

Commit

Permalink
Merge pull request #1826 from cdmahoney/cdm-recorder
Browse files Browse the repository at this point in the history
CJamRecorder: Add currentSession pointer initialization and improve locking
  • Loading branch information
pljones authored Jun 6, 2021
2 parents 4960af6 + 504cda9 commit 7dcd207
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
50 changes: 21 additions & 29 deletions src/recorder/jamrecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ void CJamRecorder::Start()

QString error;

// needs to be after OnEnd() as that also locks
ChIdMutex.lock();
{
// needs to be after OnEnd() as that also locks
QMutexLocker mutexLocker ( &ChIdMutex );
try
{
currentSession = new CJamSession ( recordBaseDir );
Expand All @@ -413,7 +413,6 @@ void CJamRecorder::Start()
error = err.GetErrorText();
}
}
ChIdMutex.unlock();

if ( !currentSession )
{
Expand All @@ -429,21 +428,18 @@ void CJamRecorder::Start()
*/
void CJamRecorder::OnEnd()
{
ChIdMutex.lock(); // iChId used in currentSession->End()
QMutexLocker mutexLocker ( &ChIdMutex );
if ( isRecording )
{
if ( isRecording )
{
isRecording = false;
currentSession->End();
isRecording = false;
currentSession->End();

ReaperProjectFromCurrentSession();
AudacityLofFromCurrentSession();
ReaperProjectFromCurrentSession();
AudacityLofFromCurrentSession();

delete currentSession;
currentSession = nullptr;
}
delete currentSession;
currentSession = nullptr;
}
ChIdMutex.unlock();
}

/**
Expand Down Expand Up @@ -571,21 +567,18 @@ void CJamRecorder::SessionDirToReaper ( QString& strSessionDirName, int serverFr
*/
void CJamRecorder::OnDisconnected ( int iChID )
{
ChIdMutex.lock();
QMutexLocker mutexLocker ( &ChIdMutex );
if ( !isRecording )
{
if ( !isRecording )
{
qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but not recording";
}
if ( currentSession == nullptr )
{
qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but no currentSession";
return;
}

currentSession->DisconnectClient ( iChID );
qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but not recording";
}
ChIdMutex.unlock();
if ( currentSession == nullptr )
{
qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but no currentSession";
return;
}

currentSession->DisconnectClient ( iChID );
}

/**
Expand Down Expand Up @@ -617,9 +610,8 @@ void CJamRecorder::OnFrame ( const int iChID,
}

// needs to be after Start() as that also locks
ChIdMutex.lock();
{
QMutexLocker mutexLocker ( &ChIdMutex );
currentSession->Frame ( iChID, name, address, numAudioChannels, data, iServerFrameSizeSamples );
}
ChIdMutex.unlock();
}
3 changes: 2 additions & 1 deletion src/recorder/jamrecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class CJamRecorder : public QObject
CJamRecorder ( const QString strRecordingBaseDir, const int iServerFrameSizeSamples ) :
recordBaseDir ( strRecordingBaseDir ),
iServerFrameSizeSamples ( iServerFrameSizeSamples ),
isRecording ( false )
isRecording ( false ),
currentSession ( nullptr )
{}

/**
Expand Down

0 comments on commit 7dcd207

Please sign in to comment.