Skip to content

Commit 7dcd207

Browse files
authored
Merge pull request #1826 from cdmahoney/cdm-recorder
CJamRecorder: Add currentSession pointer initialization and improve locking
2 parents 4960af6 + 504cda9 commit 7dcd207

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

src/recorder/jamrecorder.cpp

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,9 @@ void CJamRecorder::Start()
399399

400400
QString error;
401401

402-
// needs to be after OnEnd() as that also locks
403-
ChIdMutex.lock();
404402
{
403+
// needs to be after OnEnd() as that also locks
404+
QMutexLocker mutexLocker ( &ChIdMutex );
405405
try
406406
{
407407
currentSession = new CJamSession ( recordBaseDir );
@@ -413,7 +413,6 @@ void CJamRecorder::Start()
413413
error = err.GetErrorText();
414414
}
415415
}
416-
ChIdMutex.unlock();
417416

418417
if ( !currentSession )
419418
{
@@ -429,21 +428,18 @@ void CJamRecorder::Start()
429428
*/
430429
void CJamRecorder::OnEnd()
431430
{
432-
ChIdMutex.lock(); // iChId used in currentSession->End()
431+
QMutexLocker mutexLocker ( &ChIdMutex );
432+
if ( isRecording )
433433
{
434-
if ( isRecording )
435-
{
436-
isRecording = false;
437-
currentSession->End();
434+
isRecording = false;
435+
currentSession->End();
438436

439-
ReaperProjectFromCurrentSession();
440-
AudacityLofFromCurrentSession();
437+
ReaperProjectFromCurrentSession();
438+
AudacityLofFromCurrentSession();
441439

442-
delete currentSession;
443-
currentSession = nullptr;
444-
}
440+
delete currentSession;
441+
currentSession = nullptr;
445442
}
446-
ChIdMutex.unlock();
447443
}
448444

449445
/**
@@ -571,21 +567,18 @@ void CJamRecorder::SessionDirToReaper ( QString& strSessionDirName, int serverFr
571567
*/
572568
void CJamRecorder::OnDisconnected ( int iChID )
573569
{
574-
ChIdMutex.lock();
570+
QMutexLocker mutexLocker ( &ChIdMutex );
571+
if ( !isRecording )
575572
{
576-
if ( !isRecording )
577-
{
578-
qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but not recording";
579-
}
580-
if ( currentSession == nullptr )
581-
{
582-
qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but no currentSession";
583-
return;
584-
}
585-
586-
currentSession->DisconnectClient ( iChID );
573+
qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but not recording";
587574
}
588-
ChIdMutex.unlock();
575+
if ( currentSession == nullptr )
576+
{
577+
qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but no currentSession";
578+
return;
579+
}
580+
581+
currentSession->DisconnectClient ( iChID );
589582
}
590583

591584
/**
@@ -617,9 +610,8 @@ void CJamRecorder::OnFrame ( const int iChID,
617610
}
618611

619612
// needs to be after Start() as that also locks
620-
ChIdMutex.lock();
621613
{
614+
QMutexLocker mutexLocker ( &ChIdMutex );
622615
currentSession->Frame ( iChID, name, address, numAudioChannels, data, iServerFrameSizeSamples );
623616
}
624-
ChIdMutex.unlock();
625617
}

src/recorder/jamrecorder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ class CJamRecorder : public QObject
157157
CJamRecorder ( const QString strRecordingBaseDir, const int iServerFrameSizeSamples ) :
158158
recordBaseDir ( strRecordingBaseDir ),
159159
iServerFrameSizeSamples ( iServerFrameSizeSamples ),
160-
isRecording ( false )
160+
isRecording ( false ),
161+
currentSession ( nullptr )
161162
{}
162163

163164
/**

0 commit comments

Comments
 (0)