-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencodingmanager.cpp
80 lines (60 loc) · 1.66 KB
/
encodingmanager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <QDebug>
#include "encodingmanager.h"
EncodingManager::EncodingManager(Controller *controller)
{
m_controller = controller;
m_runningThreads = 0;
}
void EncodingManager::dispatchEncoder()
{
//No cores? Crap out...
if (!isCoreAvailable() || !m_controller->hasInputFiles())
return;
++m_runningThreads;
QString filename = m_controller->takeTopInputFile();
emit convertingFile(filename);
Encoder *encoder = new Encoder(filename);
connect(encoder, SIGNAL(finishedEncoding(Encoder *)), this, SLOT(encoderFinished(Encoder *)));
encoder->start();
}
void EncodingManager::encoderFinished(Encoder *encoder)
{
--m_runningThreads;
QString filename = encoder->getFilename();
int errorcode = encoder->getErrorcode();
delete encoder;
qDebug() << "Encodingmanager finished encoder with" << filename << "and " << errorcode;
emit completedFile(filename);
dispatchEncoder();
}
bool EncodingManager::isRunning()
{
return m_runningThreads != 0;
}
bool EncodingManager::isCoreAvailable()
{
ConsumptionLevel level = m_controller->getConsumptionLevel();
int availableCores = QThread::idealThreadCount();
switch (level)
{
case Low:
availableCores = 1;
break;
case Medium:
availableCores = availableCores/2;
break;
case Max:
break;
}
availableCores -= m_runningThreads;
return (availableCores > 0);
}
void EncodingManager::dispatch()
{
while (isCoreAvailable() && m_controller->hasInputFiles())
dispatchEncoder();
}
void EncodingManager::run()
{
dispatch();
}