Mercurial > hg > svcore
comparison transform/FeatureExtractionModelTransformer.cpp @ 1237:a83541a1f100 project-file-rework
Ensure plugin is deleted in same thread that created and used it
author | Chris Cannam |
---|---|
date | Fri, 28 Oct 2016 11:32:36 +0100 |
parents | 91ff08313375 |
children | cbdd534f517a |
comparison
equal
deleted
inserted
replaced
1236:fe391a7b8376 | 1237:a83541a1f100 |
---|---|
45 ModelTransformer(in, transform), | 45 ModelTransformer(in, transform), |
46 m_plugin(0), | 46 m_plugin(0), |
47 m_haveOutputs(false) | 47 m_haveOutputs(false) |
48 { | 48 { |
49 SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: plugin " << m_transforms.begin()->getPluginIdentifier() << ", outputName " << m_transforms.begin()->getOutput() << endl; | 49 SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: plugin " << m_transforms.begin()->getPluginIdentifier() << ", outputName " << m_transforms.begin()->getOutput() << endl; |
50 | |
51 // initialise(); | |
52 } | 50 } |
53 | 51 |
54 FeatureExtractionModelTransformer::FeatureExtractionModelTransformer(Input in, | 52 FeatureExtractionModelTransformer::FeatureExtractionModelTransformer(Input in, |
55 const Transforms &transforms) : | 53 const Transforms &transforms) : |
56 ModelTransformer(in, transforms), | 54 ModelTransformer(in, transforms), |
60 if (m_transforms.empty()) { | 58 if (m_transforms.empty()) { |
61 SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: " << transforms.size() << " transform(s)" << endl; | 59 SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: " << transforms.size() << " transform(s)" << endl; |
62 } else { | 60 } else { |
63 SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: " << transforms.size() << " transform(s), first has plugin " << m_transforms.begin()->getPluginIdentifier() << ", outputName " << m_transforms.begin()->getOutput() << endl; | 61 SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: " << transforms.size() << " transform(s), first has plugin " << m_transforms.begin()->getPluginIdentifier() << ", outputName " << m_transforms.begin()->getOutput() << endl; |
64 } | 62 } |
65 | |
66 // initialise(); | |
67 } | 63 } |
68 | 64 |
69 static bool | 65 static bool |
70 areTransformsSimilar(const Transform &t1, const Transform &t2) | 66 areTransformsSimilar(const Transform &t1, const Transform &t2) |
71 { | 67 { |
75 } | 71 } |
76 | 72 |
77 bool | 73 bool |
78 FeatureExtractionModelTransformer::initialise() | 74 FeatureExtractionModelTransformer::initialise() |
79 { | 75 { |
76 // This is (now) called from the run thread. The plugin is | |
77 // constructed, initialised, used, and destroyed all from a single | |
78 // thread. | |
79 | |
80 // All transforms must use the same plugin, parameters, and | 80 // All transforms must use the same plugin, parameters, and |
81 // inputs: they can differ only in choice of plugin output. So we | 81 // inputs: they can differ only in choice of plugin output. So we |
82 // initialise based purely on the first transform in the list (but | 82 // initialise based purely on the first transform in the list (but |
83 // first check that they are actually similar as promised) | 83 // first check that they are actually similar as promised) |
84 | 84 |
230 m_haveOutputs = true; | 230 m_haveOutputs = true; |
231 m_outputsCondition.wakeAll(); | 231 m_outputsCondition.wakeAll(); |
232 m_outputMutex.unlock(); | 232 m_outputMutex.unlock(); |
233 | 233 |
234 return true; | 234 return true; |
235 } | |
236 | |
237 void | |
238 FeatureExtractionModelTransformer::deinitialise() | |
239 { | |
240 cerr << "deleting plugin for transform in thread " | |
241 << QThread::currentThreadId() << endl; | |
242 | |
243 delete m_plugin; | |
244 for (int j = 0; j < (int)m_descriptors.size(); ++j) { | |
245 delete m_descriptors[j]; | |
246 } | |
235 } | 247 } |
236 | 248 |
237 void | 249 void |
238 FeatureExtractionModelTransformer::createOutputModels(int n) | 250 FeatureExtractionModelTransformer::createOutputModels(int n) |
239 { | 251 { |
500 m_outputMutex.unlock(); | 512 m_outputMutex.unlock(); |
501 } | 513 } |
502 | 514 |
503 FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer() | 515 FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer() |
504 { | 516 { |
505 // SVDEBUG << "FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer()" << endl; | 517 // Parent class dtor set the abandoned flag and waited for the run |
506 delete m_plugin; | 518 // thread to exit; the run thread owns the plugin, and should have |
507 for (int j = 0; j < (int)m_descriptors.size(); ++j) { | 519 // destroyed it before exiting (via a call to deinitialise) |
508 delete m_descriptors[j]; | |
509 } | |
510 } | 520 } |
511 | 521 |
512 FeatureExtractionModelTransformer::Models | 522 FeatureExtractionModelTransformer::Models |
513 FeatureExtractionModelTransformer::getAdditionalOutputModels() | 523 FeatureExtractionModelTransformer::getAdditionalOutputModels() |
514 { | 524 { |
779 | 789 |
780 for (int ch = 0; ch < channelCount; ++ch) { | 790 for (int ch = 0; ch < channelCount; ++ch) { |
781 delete[] buffers[ch]; | 791 delete[] buffers[ch]; |
782 } | 792 } |
783 delete[] buffers; | 793 delete[] buffers; |
794 | |
795 deinitialise(); | |
784 } | 796 } |
785 | 797 |
786 void | 798 void |
787 FeatureExtractionModelTransformer::getFrames(int channelCount, | 799 FeatureExtractionModelTransformer::getFrames(int channelCount, |
788 sv_frame_t startFrame, | 800 sv_frame_t startFrame, |