serviceWindowGenerationFromREC.cpp
1.63 KB
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
#include "serviceWindowGenerationFromREC.h"
using namespace std;
ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC(
char* path_video, int sublanguage, int position, int size, int transparency, int _serviceType) {
path_input = path_video;
setSubLanguage(sublanguage);
setPosition(position);
setSize(size);
setTransparency(transparency);
setServiceType(_serviceType);
DPRINTF("Done!\n");
}
ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() {
delete rec;
DDDPRINTF("Service REC finished!\n");
}
void ServiceWindowGenerationFromREC::initialize() {
rec = new Recognize(path_input);
rec->addListener(this);
ServiceWindowGeneration::initialize();
try{
rec->initialize();
}catch(RecognizeException ex){
throw ServiceException(ex.getMessage());
}
this->Start();
}
void ServiceWindowGenerationFromREC::notifyTextRecognized(unsigned char* text, int64_t pts) {
if (getRunningOption() == '3') {
notifySynchWithoutTranslator(text, pts);
} else {
adicionaPTS(pts);
notifyTranslator(text);
}
}
void ServiceWindowGenerationFromREC::notifyTranslator(unsigned char *text) {
tradutor->traduz(text);
}
void ServiceWindowGenerationFromREC::notifySynchWithoutTranslator(unsigned char *text, int64_t pts) {
char* pch = strtok((char*) text, " ");
while (pch != NULL) {
string pch_string = (string) pch;
sincronizador->recebeglosa(pch_string, pts);
pch = strtok(NULL, " ");
}
free(pch);
}
void ServiceWindowGenerationFromREC::Run() {
while (!rec->isFinished()) {
sleep(2);
}
sincronizador->stop();
}