serviceWindowGenerationFromText.cpp
2.77 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
#include "serviceWindowGenerationFromText.h"
#define PATH_LIBRAS "libras/video/"
#define OUTPUT_VIDEO_WEB "../gtaaas-plugin-server/videos/libras.webm"
#define MAX_SIZE_PATH 256
ServiceWindowGenerationFromText::ServiceWindowGenerationFromText (char* _path_file, char* _video_path_file, int _transp, int _serviceType, char* _client_type) {
path_file = _path_file;
client_type = _client_type;
setTransparency(_transp);
setServiceType(_serviceType);
char* final_path = new char[MAX_SIZE_PATH];
strcpy(final_path, PATH_LIBRAS);
strcat(final_path, _video_path_file);
strcat(final_path, ".ts");
setPathLibras(final_path);
alive = true;
DPRINTF("Done!\n");
}
ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() {
DDDPRINTF("Service Text finished!\n");
}
int ServiceWindowGenerationFromText::readTextFile() {
string line;
string all_text = "";
std::ifstream file (path_file, std::ifstream::binary);
int bytes = 0;
if (file.is_open()) {
while (file.good()) {
getline (file,line);
all_text.append(line);
}
file.close();
}
bytes = all_text.length();
if (bytes > 1) { // 1 = " "
char* tbuffer = new char[bytes+1];
std::strcpy (tbuffer, all_text.c_str());
text_buff = tbuffer;
DDPRINTF("Texto extraido.\n");
return bytes;
}
return -1;
}
void ServiceWindowGenerationFromText::initialize() {
DDPRINTF("Service Text Initialize.\n");
if (readTextFile() > 1) {
ServiceWindowGeneration::initialize();
notificaTradutor(text_buff);
} else {
printf("Problema ao ler arquivo!\n");
}
free(text_buff);
}
void ServiceWindowGenerationFromText::notificaTradutor(char *legenda) {
char* chars_array = strtok(legenda, ".");
while(chars_array){
tradutor->traduz((unsigned char *) chars_array);
chars_array = strtok(NULL, ".");
}
free(chars_array);
}
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() {
FILE *video_webm;
video_webm = fopen(OUTPUT_VIDEO_WEB, "r");
if (video_webm != NULL) {
string cmd = "rm ";
cmd.append(OUTPUT_VIDEO_WEB);
printf("[INFO]: Remove video libras.webm: %s\n", cmd.c_str());
system(cmd.c_str());
fclose(video_webm);
}
char* command = (char*) malloc (INT_MAX);
strcpy(command, "ffmpeg -i ");
strcat(command, PATH_LIBRAS);
strcat(command, " -vcodec libvpx -acodec libvorbis ");
strcat(command, OUTPUT_VIDEO_WEB);
printf("[INFO]: Transcodification command -> %s\n", command);
system(command);
free(video_webm);
free(command);
}