1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-16 09:31:14 +01:00

ODTask cloners return smart pointers

This commit is contained in:
Paul Licameli
2016-03-31 13:53:41 -04:00
parent 5477781ea8
commit c9d50dc20b
11 changed files with 21 additions and 23 deletions

View File

@@ -35,11 +35,11 @@ ODComputeSummaryTask::ODComputeSummaryTask()
mHasUpdateRan=false;
}
ODTask* ODComputeSummaryTask::Clone()
std::unique_ptr<ODTask> ODComputeSummaryTask::Clone() const
{
ODComputeSummaryTask* clone = new ODComputeSummaryTask;
clone->mDemandSample=GetDemandSample();
return clone;
auto clone = std::make_unique<ODComputeSummaryTask>();
clone->mDemandSample = GetDemandSample();
return std::move(clone);
}

View File

@@ -36,7 +36,7 @@ class ODComputeSummaryTask final : public ODTask
ODComputeSummaryTask();
virtual ~ODComputeSummaryTask(){};
ODTask* Clone() override;
std::unique_ptr<ODTask> Clone() const override;
///Subclasses should override to return respective type.
unsigned int GetODType() override { return eODPCMSummary; }

View File

@@ -140,13 +140,13 @@ ODDecodeFFmpegTask::~ODDecodeFFmpegTask()
}
ODTask *ODDecodeFFmpegTask::Clone()
std::unique_ptr<ODTask> ODDecodeFFmpegTask::Clone() const
{
auto clone = std::make_unique<ODDecodeFFmpegTask>(mScs, Streams{ mChannels }, mFormatContext, mStreamIndex);
clone->mDemandSample=GetDemandSample();
//the decoders and blockfiles should not be copied. They are created as the task runs.
return clone.release();
return std::move(clone);
}
///Creates an ODFileDecoder that decodes a file of filetype the subclass handles.

View File

@@ -36,7 +36,7 @@ public:
ODDecodeFFmpegTask(const ScsPtr &scs, Streams &&channels, void* formatContext, int streamIndex);
virtual ~ODDecodeFFmpegTask();
ODTask *Clone() override;
std::unique_ptr<ODTask> Clone() const override;
///Creates an ODFileDecoder that decodes a file of filetype the subclass handles.
ODFileDecoder* CreateFileDecoder(const wxString & fileName) override;

View File

@@ -32,13 +32,13 @@ ODDecodeFlacTask::~ODDecodeFlacTask()
}
ODTask* ODDecodeFlacTask::Clone()
std::unique_ptr<ODTask> ODDecodeFlacTask::Clone() const
{
ODDecodeFlacTask* clone = new ODDecodeFlacTask;
clone->mDemandSample=GetDemandSample();
auto clone = std::make_unique<ODDecodeFlacTask>();
clone->mDemandSample = GetDemandSample();
//the decoders and blockfiles should not be copied. They are created as the task runs.
return clone;
return std::move(clone);
}

View File

@@ -51,7 +51,7 @@ class ODDecodeFlacTask final : public ODDecodeTask
virtual ~ODDecodeFlacTask();
ODTask* Clone() override;
std::unique_ptr<ODTask> Clone() const override;
///Creates an ODFileDecoder that decodes a file of filetype the subclass handles.
ODFileDecoder* CreateFileDecoder(const wxString & fileName) override;

View File

@@ -44,8 +44,6 @@ class ODDecodeTask /* not final */ : public ODTask
ODDecodeTask();
virtual ~ODDecodeTask(){};
virtual ODTask* Clone()=0;
// NEW virtual:
virtual bool SeekingAllowed();

View File

@@ -227,7 +227,7 @@ bool ODTask::IsRunning()
return ret;
}
sampleCount ODTask::GetDemandSample()
sampleCount ODTask::GetDemandSample() const
{
sampleCount retval;
mDemandSampleMutex.Lock();

View File

@@ -27,6 +27,7 @@ in a background thread.
#include "../BlockFile.h"
#include "../Project.h"
#include "../MemoryX.h"
#include <vector>
#include <wx/wx.h>
class WaveTrack;
@@ -54,7 +55,7 @@ class ODTask /* not final */
virtual ~ODTask(){};
//clones everything except information about the tracks.
virtual ODTask* Clone()=0;
virtual std::unique_ptr<ODTask> Clone() const = 0;
///Subclasses should override to return respective type.
virtual unsigned int GetODType(){return eODNone;}
@@ -101,7 +102,7 @@ class ODTask /* not final */
virtual const char* GetTaskName(){return "ODTask";}
virtual sampleCount GetDemandSample();
virtual sampleCount GetDemandSample() const;
virtual void SetDemandSample(sampleCount sample);
@@ -159,7 +160,7 @@ class ODTask /* not final */
ODLock mWaveTrackMutex;
volatile sampleCount mDemandSample;
ODLock mDemandSampleMutex;
mutable ODLock mDemandSampleMutex;
volatile bool mIsRunning;
ODLock mIsRunningMutex;

View File

@@ -163,17 +163,16 @@ void ODWaveTrackTaskQueue::MakeWaveTrackIndependent(WaveTrack* track)
//clone the items in order and add them to the ODManager.
mTasksMutex.Lock();
ODTask* task;
for(unsigned int j=0;j<mTasks.size();j++)
{
task=mTasks[j]->Clone();
auto task = mTasks[j]->Clone();
task->AddWaveTrack(track);
//AddNewTask requires us to relinquish this lock. However, it is safe because ODManager::MakeWaveTrackIndependent
//has already locked the m_queuesMutex.
mTasksMutex.Unlock();
//AddNewTask locks the m_queuesMutex which is already locked by ODManager::MakeWaveTrackIndependent,
//so we pass a boolean flag telling it not to lock again.
ODManager::Instance()->AddNewTask(task,false);
ODManager::Instance()->AddNewTask(task.release(), false);
mTasksMutex.Lock();
}
mTasksMutex.Unlock();