serviceWindowGenerationFromSRT.cpp
4.98 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "serviceWindowGenerationFromSRT.h"
#include "dprintf.h"
#define PATH_LIBRAS "libras/video/"
using namespace std;
ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(
char* path_video, char* path_srt, int sublanguage, int position, int size, int transparency, int _serviceType) {
DPRINTF("Done!\n");
setPathInput(path_video, path_srt);
setPosition(position);
setSize(size);
setTransparency(transparency);
setSubLanguage(sublanguage);
setServiceType(_serviceType);
//numero_legendas = 0;
this->finish = false;
//initialize();
}
/* Eduardo */
ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* path_srt, char* _video_path_file, int transparency, int _serviceType){
DPRINTF("Done!\n");
setPathInput(path_srt);
setTransparency(transparency);
setServiceType(_serviceType);
string new_path_libras = PATH_LIBRAS;
new_path_libras.append((string) _video_path_file).append(".ts");
char* pathl = new char[strlen(new_path_libras.c_str()) + 1];
strcpy(pathl, (char*)new_path_libras.c_str());
setPathLibras(pathl);
finish_srt = false;
}
ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() {
DDDPRINTF("Service SRT finalized!\n");
}
void ServiceWindowGenerationFromSRT::setPathInput(char* path_video, char* path_srt) {
this->path_input = path_video;
this->path_srt = path_srt;
}
void ServiceWindowGenerationFromSRT::setPathInput(char* path_srt){
this->path_srt = path_srt;
}
void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) {
DDPRINTF("Service SRT recebeu: %d legendas.\n", sub_size);
setSizeOfSubtitles(sub_size);
//finalizouSincronizacao();
}
void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *legenda, int64_t pts){
//printf("Service from SRT received the subtitle: %s\n", legenda);
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)+1];
strcpy(legenda_copy, constchar);
//printf("ServiceFromSRT notifying Tradutor: text = %s\n", legenda_copy);
tradutor->traduz((unsigned char*) legenda_copy);
}
void ServiceWindowGenerationFromSRT::initialize() {
DDPRINTF("Service SRT Initialize.\n");
//printf("*1-path_libras: %s\n", this->path_libras);
if(serviceType == 2){
/*
Este serviço utiliza o arquivo de vídeo (em formato TS) do usuário para
capturar as informações referente ao relógio (PCR) para calcular as
etiquetas de apresentação (PTS) dos sinais em Libras.
*/
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);
//printf("ServiceSRT::initialize() enviando o caminho do arquivo: %s\n", path_srt);
extratorSRT->setFilePath((char*) path_srt);
ServiceWindowGeneration::initialize();
extratorSRT->initialize();
extratorSRT->Start();
this->inputfile->initialize();
this->Start();
} else if(serviceType == 5) {
/**
Este serviço utiliza apenas o arquivo de legendas (SRT) como entrada,
portanto, não é preciso monitorar as informações do PCR a partir do
objeto InputFile().
*/
extratorSRT = new ExtratorSRT();
monitor_pcr_base = new MonitorPCR();
monitor_pcr_base->addListenerPCRBase(extratorSRT);
extratorSRT->addListener(this);
extratorSRT->setFilePath((char*) path_srt);
ServiceWindowGeneration::initialize();
//FIXME: adicionar um PCR base!
uint64_t pcr_base = (uint64_t) 1000;
extratorSRT->notifyPCRBase(pcr_base);
extratorSRT->Start();
}
}
bool ServiceWindowGenerationFromSRT::finished() {
return finish_srt;
}
void ServiceWindowGenerationFromSRT::Run() {
//while (true) {
while (isRunning()) {
//if (extratorSRT->isFinished()) {
// finish = true;
// if (getRunningOption() == '3' || serviceType == 5) {
//sincronizador->encerrouLegendas();
// break;
// }
//}
usleep(200000); //200ms
}
finish_srt = true;
//sincronizador->encerrouLegendas();
DDDPRINTF("Service STR finalized!\n");
}