serviceWindowGenerationFromText.cpp
2.2 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
#include "serviceWindowGenerationFromText.h"
#define PATH_LIBRAS "libras/video/"
#define OUTPUT_VIDEO_WEB "vlibras_user/gtaaas-plugin-server/videos/"
#define MAX_SIZE_PATH 256
ServiceWindowGenerationFromText::ServiceWindowGenerationFromText (char* _path_file, char* _username, int _transp, int _serviceType, char* _client_type) {
path_file = _path_file;
client_type = _client_type;
id = _username;
setTransparency(_transp);
setServiceType(_serviceType);
char* final_path = new char[MAX_SIZE_PATH];
strcpy(final_path, PATH_LIBRAS);
strcat(final_path, _username);
strcat(final_path, ".ts");
setPathLibras(final_path);
alive = true;
DPRINTF("Done!\n");
}
ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() {
delete extratorTXT;
DDDPRINTF("Service Text finished!\n");
}
void ServiceWindowGenerationFromText::initialize() {
DDPRINTF("Service Text Initialize.\n");
extratorTXT = new ExtratorTXT();
extratorTXT->addListener(this);
extratorTXT->setFilePath((char*) path_file);
ServiceWindowGeneration::initialize();
try{
extratorTXT->initialize();
}catch(ExtratorTxtException ex){
throw ServiceException(ex.getMessage());
}
this->Start();
}
void ServiceWindowGenerationFromText::notifyEnd(int line_size) {
DDPRINTF("Service SRT recebeu: %d linhas.\n", line_size);
setSizeOfSubtitles(line_size);
}
void ServiceWindowGenerationFromText::notificaTradutor(unsigned char* line) {
tradutor->traduz(line);
}
bool ServiceWindowGenerationFromText::isAlive() {
return alive;
}
void ServiceWindowGenerationFromText::Run() {
while (isRunning()) {
usleep(200000); //200ms
}
if (strcmp(client_type, (char*)"WEB") == 0) {
printf("[INFO]: A transcodificação para .webm está ativada!\n");
transcodeVideoToWebm();
}
alive = false;
}
void ServiceWindowGenerationFromText::transcodeVideoToWebm() {
string command = "ffmpeg -i ";
command.append(getPathLibras())
.append(" -vcodec libvpx -acodec libvorbis ")
.append(OUTPUT_VIDEO_WEB)
.append(id)
.append(".webm")
.append(" && rm ")
.append(getPathLibras());
printf("[INFO]: Transcodification command -> %s\n", command.c_str());
system(command.c_str());
}