serviceWindowGenerationFromSRT.cpp
2.9 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "serviceWindowGenerationFromSRT.h"
using namespace std;
ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(
char* path_video, char* path_srt, int sublanguage, int position, int size, int transparency, int _serviceType) {
setPathInput(path_video, path_srt);
setPosition(position);
setSize(size);
setTransparency(transparency);
setSubLanguage(sublanguage);
setServiceType(_serviceType);
//numero_legendas = 0;
this->finish = false;
//initialize();
}
ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() {
}
void ServiceWindowGenerationFromSRT::setPathInput(char* path_video, char* path_srt) {
this->path_input = path_video;
this->path_srt = path_srt;
}
void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *legenda, int64_t pts){
cout << "1-Chegou LEGENDA no ServiceFromSRT\n" << endl;
printf("Glosa: %s PTS: %lld\n", legenda, pts);
if (!strcmp((const char*) legenda, "Homem supermercado falar nao vender.")) {
//printf("\nIGUAL\n");
return;
} else {
//printf("\nDIFERENTE\n");
}
this->numero_legendas++;
char op = this->getRunningOption();
if (op == '3') {
notificaSincronizadorSemTradutor(legenda, pts);
} else {
adicionaPTS(pts);
notificaTradutor(legenda);
}
}
void ServiceWindowGenerationFromSRT::notificaSincronizadorSemTradutor(unsigned char * legenda, int64_t pts) {
char* pch = strtok((char*) legenda, " ");
while (pch != NULL) {
string pch_string = (string) pch;
sincronizador->recebeglosa(pch_string, pts);
printf("%s\n", pch);
pch = strtok(NULL, " ");
}
}
void ServiceWindowGenerationFromSRT::notificaTradutor(unsigned char* legenda) {
const char* constchar = (const char*) legenda;
char* legenda_copy = new char[strlen(constchar)];
strcpy(legenda_copy, constchar);
tradutor->traduz((unsigned char*) legenda_copy);
}
void ServiceWindowGenerationFromSRT::initialize() {
printf("###ServiceWindowGenerationFromSRT::initialize() \n");
this->inputfile = new InputFile(this->path_input);
extratorSRT = new ExtratorSRT();
monitor_pcr_base = new MonitorPCR();
monitor_pcr_base->addListenerPCRBase(extratorSRT);
inputfile->registraOuvinte(monitor_pcr_base);
extratorSRT->addListener(this);
extratorSRT->setFilePath((char*)this->path_srt);
ServiceWindowGeneration::initialize();
extratorSRT->initialize();
this->inputfile->initialize();
this->Start();
}
void ServiceWindowGenerationFromSRT::Run() {
while (true) {
if (extratorSRT->isFinished()) {
this->finish = true;
if (getRunningOption() == '3') {
//printf("\n\n\nEncerrei\n\n\n");
sincronizador->encerrouLegendas();
}
}
sleep(5);
}
}