Commit 1562909b2708f9c69c715dcfcc740645828478f1
1 parent
18e68e96
Exists in
master
and in
1 other branch
Alterações nos parâmetros de entrada
Showing
28 changed files
with
1065 additions
and
898 deletions
Show diff stats
Makefile
@@ -43,9 +43,8 @@ inputObjs= \ | @@ -43,9 +43,8 @@ inputObjs= \ | ||
43 | inputException.o | 43 | inputException.o |
44 | 44 | ||
45 | servicoObjs= \ | 45 | servicoObjs= \ |
46 | - serviceWindowGeneration.o \ | ||
47 | serviceWindowGenerationFromSRT.o \ | 46 | serviceWindowGenerationFromSRT.o \ |
48 | - serviceWindowGenerationFromREC.o \ | 47 | + serviceWindowGenerationFromRec.o \ |
49 | serviceWindowGenerationFromText.o \ | 48 | serviceWindowGenerationFromText.o \ |
50 | serviceException.o | 49 | serviceException.o |
51 | 50 |
extrator/src/extratorFactory.cpp
@@ -8,9 +8,12 @@ ExtratorFactory::~ExtratorFactory(){ | @@ -8,9 +8,12 @@ ExtratorFactory::~ExtratorFactory(){ | ||
8 | //TODO | 8 | //TODO |
9 | } | 9 | } |
10 | 10 | ||
11 | -Extrator* ExtratorFactory::getExtrator(int extrator_type){ | ||
12 | - if(extrator_type == SRT) | ||
13 | - return new ExtratorSRT(); | ||
14 | - if(extrator_type == TXT) | ||
15 | - return new ExtratorTXT(); | 11 | +Extrator* ExtratorFactory::getExtrator(Extrator::ExtratorType extrator_type) { |
12 | + extrator = extrator_type; | ||
13 | + switch(extrator){ | ||
14 | + case Extrator::SRT: | ||
15 | + return new ExtratorSRT(); | ||
16 | + case Extrator::TXT: | ||
17 | + return new ExtratorTXT(); | ||
18 | + } | ||
16 | } | 19 | } |
17 | \ No newline at end of file | 20 | \ No newline at end of file |
extrator/src/extratorSRT.cpp
@@ -43,7 +43,7 @@ void ExtratorSRT::notifyListeners(unsigned char* subtitle, int64_t pts) { | @@ -43,7 +43,7 @@ void ExtratorSRT::notifyListeners(unsigned char* subtitle, int64_t pts) { | ||
43 | } | 43 | } |
44 | 44 | ||
45 | void ExtratorSRT::notifyEndExtraction(int size) { | 45 | void ExtratorSRT::notifyEndExtraction(int size) { |
46 | - DDPRINTF("Extrator SRT concluiu a extração: %d legendas.\n", size); | 46 | + DPRINTF("Extrator SRT concluiu a extração: %d legendas.\n", size); |
47 | for(list<ListenerSRT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | 47 | for(list<ListenerSRT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ |
48 | (*it)->notifyEnd(size); | 48 | (*it)->notifyEnd(size); |
49 | } | 49 | } |
@@ -72,8 +72,7 @@ bool ExtratorSRT::hasNextSubtitle() { | @@ -72,8 +72,7 @@ bool ExtratorSRT::hasNextSubtitle() { | ||
72 | } | 72 | } |
73 | 73 | ||
74 | void ExtratorSRT::Run(){ | 74 | void ExtratorSRT::Run(){ |
75 | - printf("\n"); | ||
76 | - DDPRINTF("[AGUARDE] Extraindo Legendas...\n"); | 75 | + DPRINTF("[AGUARDE] Extraindo Legendas...\n"); |
77 | 76 | ||
78 | int sub_index = 0; | 77 | int sub_index = 0; |
79 | string sub_text = ""; | 78 | string sub_text = ""; |
@@ -89,7 +88,6 @@ void ExtratorSRT::Run(){ | @@ -89,7 +88,6 @@ void ExtratorSRT::Run(){ | ||
89 | } | 88 | } |
90 | if(sub_index == 0) | 89 | if(sub_index == 0) |
91 | notifyListeners((unsigned char*)"ARQUIVO_VAZIO", 0); | 90 | notifyListeners((unsigned char*)"ARQUIVO_VAZIO", 0); |
92 | - printf("\n"); | ||
93 | finish = true; | 91 | finish = true; |
94 | notifyEndExtraction(sub_index); | 92 | notifyEndExtraction(sub_index); |
95 | } | 93 | } |
extrator/src/extratorTXT.cpp
@@ -50,7 +50,7 @@ void ExtratorTXT::notifyListeners(unsigned char* line) { | @@ -50,7 +50,7 @@ void ExtratorTXT::notifyListeners(unsigned char* line) { | ||
50 | } | 50 | } |
51 | 51 | ||
52 | void ExtratorTXT::notifyEndExtraction(int size) { | 52 | void ExtratorTXT::notifyEndExtraction(int size) { |
53 | - DDPRINTF("ExtratorTXT concluiu a extração: %d linhas.\n", size); | 53 | + DPRINTF("ExtratorTXT concluiu a extração: %d linhas.\n", size); |
54 | for(list<ListenerTXT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | 54 | for(list<ListenerTXT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ |
55 | (*it)->notifyEnd(size); | 55 | (*it)->notifyEnd(size); |
56 | } | 56 | } |
@@ -76,7 +76,7 @@ bool ExtratorTXT::isFinished(){ | @@ -76,7 +76,7 @@ bool ExtratorTXT::isFinished(){ | ||
76 | 76 | ||
77 | void ExtratorTXT::Run(){ | 77 | void ExtratorTXT::Run(){ |
78 | 78 | ||
79 | - DDPRINTF("[AGUARDE] Extraindo Texto...\n") | 79 | + DPRINTF("[AGUARDE] Extraindo Texto...\n") |
80 | 80 | ||
81 | int line_index = 0; | 81 | int line_index = 0; |
82 | bool hasNext = true; | 82 | bool hasNext = true; |
@@ -99,7 +99,6 @@ void ExtratorTXT::Run(){ | @@ -99,7 +99,6 @@ void ExtratorTXT::Run(){ | ||
99 | throw ExtratorException("Falha desconhecida na leitura do arquivo. Tente novamente."); | 99 | throw ExtratorException("Falha desconhecida na leitura do arquivo. Tente novamente."); |
100 | } | 100 | } |
101 | } | 101 | } |
102 | - printf("\n"); | ||
103 | finish = true; | 102 | finish = true; |
104 | notifyEndExtraction(line_index); | 103 | notifyEndExtraction(line_index); |
105 | } | 104 | } |
extrator/src/include/extrator.h
@@ -20,6 +20,10 @@ protected: | @@ -20,6 +20,10 @@ protected: | ||
20 | BufferedReader* bff_reader; | 20 | BufferedReader* bff_reader; |
21 | 21 | ||
22 | public: | 22 | public: |
23 | + enum ExtratorType { | ||
24 | + SRT, | ||
25 | + TXT | ||
26 | + }; | ||
23 | virtual void notifyEndExtraction(int size) = 0; | 27 | virtual void notifyEndExtraction(int size) = 0; |
24 | virtual void setFilePath(char* path) = 0; | 28 | virtual void setFilePath(char* path) = 0; |
25 | virtual void initialize() = 0; | 29 | virtual void initialize() = 0; |
extrator/src/include/extratorFactory.h
@@ -5,16 +5,16 @@ | @@ -5,16 +5,16 @@ | ||
5 | #include "extratorSRT.h" | 5 | #include "extratorSRT.h" |
6 | #include "extratorTXT.h" | 6 | #include "extratorTXT.h" |
7 | 7 | ||
8 | -#define SRT 1 | ||
9 | -#define TXT 2 | ||
10 | - | ||
11 | class ExtratorFactory{ | 8 | class ExtratorFactory{ |
12 | 9 | ||
13 | public: | 10 | public: |
14 | ExtratorFactory(); | 11 | ExtratorFactory(); |
15 | ~ExtratorFactory(); | 12 | ~ExtratorFactory(); |
16 | 13 | ||
17 | - Extrator* getExtrator(int extrator_type); | 14 | + Extrator* getExtrator(Extrator::ExtratorType extrator_type); |
15 | + | ||
16 | +private: | ||
17 | + Extrator::ExtratorType extrator; | ||
18 | 18 | ||
19 | }; | 19 | }; |
20 | 20 |
log/log
main.cpp
@@ -12,11 +12,9 @@ | @@ -12,11 +12,9 @@ | ||
12 | * Edit on 03 de Fevereiro de 2014 | 12 | * Edit on 03 de Fevereiro de 2014 |
13 | */ | 13 | */ |
14 | #include "serviceWindowGenerationFromSRT.h" | 14 | #include "serviceWindowGenerationFromSRT.h" |
15 | -#include "serviceWindowGenerationFromREC.h" | 15 | +#include "serviceWindowGenerationFromRec.h" |
16 | #include "serviceWindowGenerationFromText.h" | 16 | #include "serviceWindowGenerationFromText.h" |
17 | #include "serviceException.h" | 17 | #include "serviceException.h" |
18 | -#include "property.h" | ||
19 | - | ||
20 | #include <sys/time.h> | 18 | #include <sys/time.h> |
21 | #include <stdlib.h> | 19 | #include <stdlib.h> |
22 | 20 | ||
@@ -32,7 +30,6 @@ void serviceText(char* service, char* path_text, char* transparency, char* id, c | @@ -32,7 +30,6 @@ void serviceText(char* service, char* path_text, char* transparency, char* id, c | ||
32 | 30 | ||
33 | void help(); | 31 | void help(); |
34 | void serviceHelp(int service); | 32 | void serviceHelp(int service); |
35 | -void setStatusOfReady(char* ready); | ||
36 | void fail(string msg); | 33 | void fail(string msg); |
37 | void hasFailed(); | 34 | void hasFailed(); |
38 | void hasInvalid(); | 35 | void hasInvalid(); |
@@ -47,91 +44,61 @@ int main(int argc, char* argv[]) { | @@ -47,91 +44,61 @@ int main(int argc, char* argv[]) { | ||
47 | 44 | ||
48 | gettimeofday(&tv1, NULL); | 45 | gettimeofday(&tv1, NULL); |
49 | t1 = (double)(tv1.tv_sec) + (double)(tv1.tv_usec)/ 1000000.00; | 46 | t1 = (double)(tv1.tv_sec) + (double)(tv1.tv_usec)/ 1000000.00; |
50 | - | ||
51 | - printf("\n################## VLIBRAS : LAVID ##################\n\n"); | ||
52 | - | ||
53 | - if(argc >= 2) { | ||
54 | - | 47 | + |
48 | + if(argc > 2) { | ||
49 | + printf("\n################## VLIBRAS : LAVID ##################\n\n"); | ||
55 | DDPRINTF("Service Type: %s\n", argv[1]); | 50 | DDPRINTF("Service Type: %s\n", argv[1]); |
56 | - | ||
57 | switch((int) atoi(argv[1])){ | 51 | switch((int) atoi(argv[1])){ |
58 | - | ||
59 | case 1: | 52 | case 1: |
60 | - if(argc < 9){ | 53 | + if(argc <= 9){ |
61 | serviceHelp(1); | 54 | serviceHelp(1); |
62 | hasInvalid(); | 55 | hasInvalid(); |
63 | - break; | ||
64 | - } | ||
65 | - if(argc == 9){ | ||
66 | - setStatusOfReady("0"); | ||
67 | - serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], "user"); | ||
68 | - setStatusOfReady("1"); | ||
69 | - }else | 56 | + }else{ |
70 | serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); | 57 | serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); |
71 | - | 58 | + } |
72 | break; | 59 | break; |
73 | case 2: | 60 | case 2: |
74 | - if(argc < 8){ | 61 | + if(argc <= 8){ |
75 | serviceHelp(2); | 62 | serviceHelp(2); |
76 | hasInvalid(); | 63 | hasInvalid(); |
77 | - break; | ||
78 | - } | ||
79 | - if(argc == 8){ | ||
80 | - setStatusOfReady("0"); | ||
81 | - serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], "user"); | ||
82 | - setStatusOfReady("1"); | ||
83 | - }else | 64 | + }else{ |
84 | serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); | 65 | serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); |
66 | + } | ||
85 | break; | 67 | break; |
86 | case 3: | 68 | case 3: |
87 | - if(argc < 5){ | 69 | + if(argc <= 5){ |
88 | serviceHelp(3); | 70 | serviceHelp(3); |
89 | hasInvalid(); | 71 | hasInvalid(); |
90 | - break; | ||
91 | - } | ||
92 | - if(argc == 5){ | ||
93 | - setStatusOfReady("0"); | ||
94 | - serviceText(argv[1], argv[2], argv[3], argv[4], "user"); | ||
95 | - setStatusOfReady("1"); | ||
96 | - }else | 72 | + }else{ |
97 | serviceText(argv[1], argv[2], argv[3], argv[4], argv[5]); | 73 | serviceText(argv[1], argv[2], argv[3], argv[4], argv[5]); |
74 | + } | ||
98 | break; | 75 | break; |
99 | case 4: | 76 | case 4: |
100 | - if(argc < 5){ | 77 | + if(argc <= 5){ |
101 | serviceHelp(4); | 78 | serviceHelp(4); |
102 | hasInvalid(); | 79 | hasInvalid(); |
103 | - break; | ||
104 | - } | ||
105 | - if(argc == 5 ){ | ||
106 | - setStatusOfReady("0"); | ||
107 | - serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], "user"); | ||
108 | - setStatusOfReady("1"); | ||
109 | - }else | 80 | + }else{ |
110 | serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], argv[5]); | 81 | serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], argv[5]); |
82 | + } | ||
111 | break; | 83 | break; |
112 | case 5: | 84 | case 5: |
113 | - printf("[INFO] Serviço em manutenção!!!\n"); | ||
114 | - exit(0); | ||
115 | - if(argc < 5){ | 85 | + if(argc <= 5){ |
116 | serviceHelp(5); | 86 | serviceHelp(5); |
117 | hasInvalid(); | 87 | hasInvalid(); |
118 | - break; | ||
119 | - } | ||
120 | - if (argc == 5){ | ||
121 | - setStatusOfReady("0"); | ||
122 | - serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], "user"); | ||
123 | - setStatusOfReady("1"); | ||
124 | - }else | 88 | + }else{ |
125 | serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], argv[5]); | 89 | serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], argv[5]); |
90 | + } | ||
126 | break; | 91 | break; |
127 | default: | 92 | default: |
128 | - cout << "\nServiço inválido. Tente novamente." << endl; | ||
129 | - help(); | 93 | + cout << "\nFAIL VLibras: Serviço inválido! Tente --help" << endl; |
130 | hasInvalid(); | 94 | hasInvalid(); |
131 | break; | 95 | break; |
132 | } | 96 | } |
97 | + }else if(argc == 2 && (strcmp(argv[1], "--help")) == 0){ | ||
98 | + help(); | ||
99 | + exit(0); | ||
133 | }else{ | 100 | }else{ |
134 | - help(); | 101 | + cout << "\nFAIL VLibras: Tente --help para obter informações.\n" << endl; |
135 | hasInvalid(); | 102 | hasInvalid(); |
136 | } | 103 | } |
137 | 104 | ||
@@ -142,18 +109,9 @@ int main(int argc, char* argv[]) { | @@ -142,18 +109,9 @@ int main(int argc, char* argv[]) { | ||
142 | 109 | ||
143 | gettimeofday(&tv2, NULL); | 110 | gettimeofday(&tv2, NULL); |
144 | t2 = (double)(tv2.tv_sec) + (double)(tv2.tv_usec)/ 1000000.00; | 111 | t2 = (double)(tv2.tv_sec) + (double)(tv2.tv_usec)/ 1000000.00; |
145 | - cout << endl; | ||
146 | DDPRINTF("Time: %lf\n", (t2-t1)); | 112 | DDPRINTF("Time: %lf\n", (t2-t1)); |
147 | - DDPRINTF("VLibras concluído!\n\n"); | 113 | + DDPRINTF("VLibras finalized!\n\n"); |
148 | exit(0); | 114 | exit(0); |
149 | - | ||
150 | -} | ||
151 | - | ||
152 | -void setStatusOfReady(char* ready){ | ||
153 | - char* status = new char[256]; | ||
154 | - strcpy(status, "READY="); | ||
155 | - strcat(status,ready); | ||
156 | - Util::Logger::Instance()->writeInfoLog("/home/wesnydy/.vlibras-conf/service/log-vbox", status); | ||
157 | } | 115 | } |
158 | 116 | ||
159 | void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position, | 117 | void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position, |
@@ -180,8 +138,8 @@ void serviceSRT(char* service, char* path_video, char* path_srt, char* sublangua | @@ -180,8 +138,8 @@ void serviceSRT(char* service, char* path_video, char* path_srt, char* sublangua | ||
180 | void serviceREC(char* service, char* path_video, char* sublanguage, char* position, char* size, | 138 | void serviceREC(char* service, char* path_video, char* sublanguage, char* position, char* size, |
181 | char* transparency, char* id, char* client_type){ | 139 | char* transparency, char* id, char* client_type){ |
182 | 140 | ||
183 | - ServiceWindowGenerationFromREC * service_rec; | ||
184 | - service_rec = new ServiceWindowGenerationFromREC(path_video, (int) atoi(sublanguage), | 141 | + ServiceWindowGenerationFromRec * service_rec; |
142 | + service_rec = new ServiceWindowGenerationFromRec(path_video, (int) atoi(sublanguage), | ||
185 | (int) atoi(position), (int) atoi(size), (int) atoi(transparency), id, client_type, (int) atoi(service)); | 143 | (int) atoi(position), (int) atoi(size), (int) atoi(transparency), id, client_type, (int) atoi(service)); |
186 | 144 | ||
187 | try{ | 145 | try{ |
@@ -200,7 +158,7 @@ void serviceREC(char* service, char* path_video, char* sublanguage, char* positi | @@ -200,7 +158,7 @@ void serviceREC(char* service, char* path_video, char* sublanguage, char* positi | ||
200 | void serviceText(char* service, char* path_text, char* transparency, char* id, char* client_type){ | 158 | void serviceText(char* service, char* path_text, char* transparency, char* id, char* client_type){ |
201 | 159 | ||
202 | ServiceWindowGenerationFromText *service_text; | 160 | ServiceWindowGenerationFromText *service_text; |
203 | - service_text = new ServiceWindowGenerationFromText(path_text, id, (int) atoi(transparency), (int) atoi(service), client_type); | 161 | + service_text = new ServiceWindowGenerationFromText(path_text, (int) atoi(transparency), id, client_type); |
204 | 162 | ||
205 | try{ | 163 | try{ |
206 | service_text->initialize(); | 164 | service_text->initialize(); |
@@ -236,8 +194,8 @@ void serviceOnlySRT(char* service, char* path_file, char* transparency, char* id | @@ -236,8 +194,8 @@ void serviceOnlySRT(char* service, char* path_file, char* transparency, char* id | ||
236 | 194 | ||
237 | void serviceOnlyAudio(char* service, char* path_audio, char* transparency, char* id, char* client_type){ | 195 | void serviceOnlyAudio(char* service, char* path_audio, char* transparency, char* id, char* client_type){ |
238 | 196 | ||
239 | - ServiceWindowGenerationFromREC * service_rec; | ||
240 | - service_rec = new ServiceWindowGenerationFromREC(path_audio, 0, 0, 0, (int) atoi(transparency), id, client_type, (int) atoi(service)); | 197 | + ServiceWindowGenerationFromRec * service_rec; |
198 | + service_rec = new ServiceWindowGenerationFromRec(path_audio, 0, 0, 0, (int) atoi(transparency), id, client_type, (int) atoi(service)); | ||
241 | 199 | ||
242 | try{ | 200 | try{ |
243 | service_rec->initialize(); | 201 | service_rec->initialize(); |
@@ -349,21 +307,21 @@ void help() { | @@ -349,21 +307,21 @@ void help() { | ||
349 | cout << endl | 307 | cout << endl |
350 | << "Usage Summary: vlibras [SERVICE] [INPUT] ... [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" | 308 | << "Usage Summary: vlibras [SERVICE] [INPUT] ... [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" |
351 | << "\nSERVICE:\n" | 309 | << "\nSERVICE:\n" |
352 | - << "1 Video with Subtitles (SRT) - requires INPUT_VIDEO and INPUT_SRT\n" | ||
353 | - << "2 Video Recognize - requires INPUT_VIDEO\n" | ||
354 | - << "3 Text - requires INPUT_TEXT_FILE\n" | ||
355 | - << "4 Subtitles only (SRT) - requires INPUT_SRT\n" | ||
356 | - << "5 Audio Recognize - requires INPUT_AUDIO\n" | 310 | + << "1 Video with Subtitles (SRT) - requires INPUT_VIDEO and INPUT_SRT\n" |
311 | + << "2 Video Recognize - requires INPUT_VIDEO\n" | ||
312 | + << "3 Text - requires INPUT_TEXT_FILE\n" | ||
313 | + << "4 Subtitles only (SRT) - requires INPUT_SRT\n" | ||
314 | + << "5 Audio Recognize - requires INPUT_AUDIO\n" | ||
357 | << "\nSERVICES PARAMETERS:\n" | 315 | << "\nSERVICES PARAMETERS:\n" |
358 | << "Video with subtitles:\n" | 316 | << "Video with subtitles:\n" |
359 | << " [INPUT_VIDEO] [INPUT_SRT] [LANGUAGE] [POSITION] [SIZE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" | 317 | << " [INPUT_VIDEO] [INPUT_SRT] [LANGUAGE] [POSITION] [SIZE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" |
360 | - << "Video Recognize:\n" | 318 | + << "\nVideo Recognize:\n" |
361 | << " [INPUT_VIDEO] [LANGUAGE] [POSITION] [SIZE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" | 319 | << " [INPUT_VIDEO] [LANGUAGE] [POSITION] [SIZE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" |
362 | - << "Text:\n" | 320 | + << "\nText:\n" |
363 | << " [INPUT_TEXT_FILE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" | 321 | << " [INPUT_TEXT_FILE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" |
364 | - << "Subtitles only:\n" | 322 | + << "\nSubtitles only:\n" |
365 | << " [INPUT_SRT] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" | 323 | << " [INPUT_SRT] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" |
366 | - << "Audio Recognize\n" | 324 | + << "\nAudio Recognize\n" |
367 | << " [INPUT_AUDIO] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" | 325 | << " [INPUT_AUDIO] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" |
368 | << "\nPARAMETERS:\n" | 326 | << "\nPARAMETERS:\n" |
369 | << "INPUT_VIDEO Path of the video file\n" | 327 | << "INPUT_VIDEO Path of the video file\n" |
@@ -375,5 +333,6 @@ void help() { | @@ -375,5 +333,6 @@ void help() { | ||
375 | << "SIZE 1 - means Small, 2 - means Medium, 3 - means Large\n" | 333 | << "SIZE 1 - means Small, 2 - means Medium, 3 - means Large\n" |
376 | << "TRANSPARENCY 0 - means that the background is opaque , 1 - means that the background is transparent\n" | 334 | << "TRANSPARENCY 0 - means that the background is opaque , 1 - means that the background is transparent\n" |
377 | << "ID Relative to the unique ID on the Database\n" | 335 | << "ID Relative to the unique ID on the Database\n" |
378 | - << "CLIENT_TYPE web - necessary only for web clients, others clients can ignore this parameter\n"; | 336 | + << "CLIENT_TYPE prod - means that the client is web/cloud, devel - means that the client is developer\n" |
337 | + << endl; | ||
379 | } | 338 | } |
380 | \ No newline at end of file | 339 | \ No newline at end of file |
mixer/src/Mixer.cpp
@@ -24,11 +24,12 @@ Mixer::~Mixer() { | @@ -24,11 +24,12 @@ Mixer::~Mixer() { | ||
24 | 24 | ||
25 | /*Faz a chamada ffmpeg no terminal.*/ | 25 | /*Faz a chamada ffmpeg no terminal.*/ |
26 | 26 | ||
27 | -void Mixer::initialize(string mainVideo, string slVideo, int positionSecondaryVideo, int sizeSecondaryVideo, int transparency, char* _id, char* client_type){ | 27 | +void Mixer::initialize(string mainVideo, string slVideo, int positionSecondaryVideo, int sizeSecondaryVideo, |
28 | + int transparency, char* _id, char* path_uploads, char* path_contents){ | ||
28 | 29 | ||
29 | - DDPRINTF("[AGUARDE] Mixando...\n") | ||
30 | - | ||
31 | - client = client_type; | 30 | + DPRINTF("[AGUARDE] Mixando...\n") |
31 | + uploads = path_uploads; | ||
32 | + contents = path_contents; | ||
32 | stringstream ss; | 33 | stringstream ss; |
33 | ss << _id; | 34 | ss << _id; |
34 | ss >> user_id; | 35 | ss >> user_id; |
@@ -146,24 +147,10 @@ void Mixer::mixVideos () { | @@ -146,24 +147,10 @@ void Mixer::mixVideos () { | ||
146 | } | 147 | } |
147 | 148 | ||
148 | void Mixer::setPathFinal(){ | 149 | void Mixer::setPathFinal(){ |
149 | - | ||
150 | - char* final_path = new char[256]; | ||
151 | - | ||
152 | - if(strcmp(client, (char*)WEB_USER) == 0){ | ||
153 | - pathFinal = PATH_API; | ||
154 | - pathFinal.append(user_id).append(".mp4"); | ||
155 | - }else{ | ||
156 | - try{ | ||
157 | - PropertyHandler* reader = new PropertyHandler("vlibras_user/.vlibras-conf/configuration/params-vbox.conf"); | ||
158 | - strcpy(final_path, reader->getAttributeValue("STORAGE")); | ||
159 | - stringstream ss; | ||
160 | - ss << final_path; | ||
161 | - ss >> pathFinal; | ||
162 | - pathFinal.append("/").append(user_id).append(".mp4"); | ||
163 | - }catch(RuntimeException &ex){ | ||
164 | - printf("%s\n", ex.getMessage().c_str()); | ||
165 | - } | ||
166 | - } | 150 | + stringstream ss; |
151 | + ss << contents; | ||
152 | + ss >> pathFinal; | ||
153 | + pathFinal.append(user_id).append(".mp4"); | ||
167 | } | 154 | } |
168 | 155 | ||
169 | /*Ajusta o FPS do vídeo principal para 45 se preciso...*/ | 156 | /*Ajusta o FPS do vídeo principal para 45 se preciso...*/ |
@@ -330,15 +317,11 @@ void Mixer::setMainVideo(string mainVideo){ | @@ -330,15 +317,11 @@ void Mixer::setMainVideo(string mainVideo){ | ||
330 | } | 317 | } |
331 | //ajeitar isso depois | 318 | //ajeitar isso depois |
332 | string nameOfMainVideo = mainVideo.substr(0, dotPosition); | 319 | string nameOfMainVideo = mainVideo.substr(0, dotPosition); |
333 | - char* final_path = new char[256]; | ||
334 | - | ||
335 | - if(strcmp(client, (char*)WEB_USER) == 0){ | ||
336 | - this->temporaryTextFile = "vlibras_user/vlibras-api/uploads/"; | ||
337 | - temporaryTextFile.append(this->user_id).append("/tamanho.txt"); | ||
338 | - }else{ | ||
339 | - this->temporaryTextFile = "vlibras_user/.vlibras-conf/contents/"; | ||
340 | - temporaryTextFile.append("tamanho.txt"); | ||
341 | - } | 320 | + |
321 | + stringstream ss; | ||
322 | + ss << uploads; | ||
323 | + ss >> temporaryTextFile; | ||
324 | + temporaryTextFile.append(this->user_id).append("/tamanho.txt"); | ||
342 | //printf("##########temporaryTextFile: %s\n", temporaryTextFile.c_str()); | 325 | //printf("##########temporaryTextFile: %s\n", temporaryTextFile.c_str()); |
343 | } | 326 | } |
344 | string Mixer::getMainVideo(){ | 327 | string Mixer::getMainVideo(){ |
mixer/src/include/Mixer.h
@@ -18,9 +18,6 @@ | @@ -18,9 +18,6 @@ | ||
18 | #include <fstream> | 18 | #include <fstream> |
19 | #include "dprintf.h" | 19 | #include "dprintf.h" |
20 | #include "property.h" | 20 | #include "property.h" |
21 | - | ||
22 | -using namespace std; | ||
23 | -using namespace sndesc; | ||
24 | 21 | ||
25 | //SL Video Position | 22 | //SL Video Position |
26 | #define TOP_LEFT 1 | 23 | #define TOP_LEFT 1 |
@@ -37,11 +34,8 @@ using namespace sndesc; | @@ -37,11 +34,8 @@ using namespace sndesc; | ||
37 | #define LARGE_HEIGHT 540 //0.5*1080 | 34 | #define LARGE_HEIGHT 540 //0.5*1080 |
38 | 35 | ||
39 | #define MAX_SIZE_PATH 256 | 36 | #define MAX_SIZE_PATH 256 |
40 | -#define WEB_USER "web" | ||
41 | -#define PATH_API "vlibras_user/vlibras-api/videos/" | ||
42 | 37 | ||
43 | using namespace std; | 38 | using namespace std; |
44 | -using namespace sndesc; | ||
45 | 39 | ||
46 | class Mixer { | 40 | class Mixer { |
47 | public: | 41 | public: |
@@ -66,7 +60,7 @@ public: | @@ -66,7 +60,7 @@ public: | ||
66 | int getTransparency(); | 60 | int getTransparency(); |
67 | void setNumThreads(string); | 61 | void setNumThreads(string); |
68 | string getNumThreads(); | 62 | string getNumThreads(); |
69 | - void initialize(string mainVideo, string slVideo, int, int, int, char*, char*); | 63 | + void initialize(string mainVideo, string slVideo, int, int, int, char*, char*, char*); |
70 | void setPathFinal(); | 64 | void setPathFinal(); |
71 | 65 | ||
72 | private: | 66 | private: |
@@ -82,7 +76,8 @@ private: | @@ -82,7 +76,8 @@ private: | ||
82 | void convertSecondaryVideoFPS(double); | 76 | void convertSecondaryVideoFPS(double); |
83 | 77 | ||
84 | string mainVideo, secondaryVideo, temporaryTextFile, numThreads, pathFinal, user_id; | 78 | string mainVideo, secondaryVideo, temporaryTextFile, numThreads, pathFinal, user_id; |
85 | - char* client; | 79 | + char* contents; |
80 | + char* uploads; | ||
86 | int positionSecondaryVideo; | 81 | int positionSecondaryVideo; |
87 | double widthSecondaryVideo, heightSecondaryVideo; | 82 | double widthSecondaryVideo, heightSecondaryVideo; |
88 | int transparency; | 83 | int transparency; |
recognize/src/include/recognize.h
@@ -23,9 +23,6 @@ | @@ -23,9 +23,6 @@ | ||
23 | #define SIZE_BUFFER 256 | 23 | #define SIZE_BUFFER 256 |
24 | #define CONFIDENCE_RATE 0.10 | 24 | #define CONFIDENCE_RATE 0.10 |
25 | 25 | ||
26 | -#define WEB_USER 1 | ||
27 | -#define PATH_API_UPLOADS "vlibras_user/vlibras-api/uploads/" | ||
28 | -#define PATH_VBOX_CONTENTS "vlibras_user/.vlibras-conf/contents/" | ||
29 | #define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav" | 26 | #define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav" |
30 | #define PATH_AUDIO_PARTS "/audio/parts/" | 27 | #define PATH_AUDIO_PARTS "/audio/parts/" |
31 | #define FILENAME_RECOGNIZED_OUT "/audio/recognized.out" | 28 | #define FILENAME_RECOGNIZED_OUT "/audio/recognized.out" |
@@ -49,7 +46,7 @@ class Recognize: public Thread { | @@ -49,7 +46,7 @@ class Recognize: public Thread { | ||
49 | 46 | ||
50 | public: | 47 | public: |
51 | 48 | ||
52 | - Recognize(char* _pathVideo, char* id, int client_type); | 49 | + Recognize(char* _pathVideo, char* id); |
53 | Recognize(char* _pathVideo, char* id, char* rate); | 50 | Recognize(char* _pathVideo, char* id, char* rate); |
54 | Recognize(char* _pathVideo, int _inputType, char* id); | 51 | Recognize(char* _pathVideo, int _inputType, char* id); |
55 | ~Recognize(); | 52 | ~Recognize(); |
@@ -68,6 +65,7 @@ public: | @@ -68,6 +65,7 @@ public: | ||
68 | * Define o tamanho em segundos de cada parte retirada do audio original. | 65 | * Define o tamanho em segundos de cada parte retirada do audio original. |
69 | */ | 66 | */ |
70 | void setSizeAudioBlocs(int sec); | 67 | void setSizeAudioBlocs(int sec); |
68 | + void setPathAudioContents(char* path); | ||
71 | 69 | ||
72 | void addListener(RecognizeListener* listener); | 70 | void addListener(RecognizeListener* listener); |
73 | 71 |
recognize/src/recognize.cpp
1 | #include <recognize.h> | 1 | #include <recognize.h> |
2 | 2 | ||
3 | -Recognize::Recognize(char* _pathVideo, char* _id, int client_type) { | 3 | +Recognize::Recognize(char* _pathVideo, char* _id) { |
4 | 4 | ||
5 | listeners = new list<RecognizeListener*>(); | 5 | listeners = new list<RecognizeListener*>(); |
6 | pathVideo = _pathVideo; | 6 | pathVideo = _pathVideo; |
@@ -11,12 +11,6 @@ Recognize::Recognize(char* _pathVideo, char* _id, int client_type) { | @@ -11,12 +11,6 @@ Recognize::Recognize(char* _pathVideo, char* _id, int client_type) { | ||
11 | ss << _id; | 11 | ss << _id; |
12 | ss >> id; | 12 | ss >> id; |
13 | confidenceRate=CONFIDENCE_RATE; | 13 | confidenceRate=CONFIDENCE_RATE; |
14 | - if(client_type == WEB_USER){ | ||
15 | - path_contents = (char*) PATH_API_UPLOADS; | ||
16 | - }else{ | ||
17 | - path_contents = (char*) PATH_VBOX_CONTENTS; | ||
18 | - } | ||
19 | - | ||
20 | DPRINTF("Done!\n"); | 14 | DPRINTF("Done!\n"); |
21 | } | 15 | } |
22 | 16 | ||
@@ -56,7 +50,7 @@ Recognize::~Recognize() { | @@ -56,7 +50,7 @@ Recognize::~Recognize() { | ||
56 | 50 | ||
57 | void Recognize::initialize() { | 51 | void Recognize::initialize() { |
58 | 52 | ||
59 | - DDPRINTF("Recognizing...\n"); | 53 | + DPRINTF("Recognizing...\n"); |
60 | /**printf("*** Initialized Recognition ***\n\nVideo: %s\nType [1-File; 2-Mic]: %d\nFrequency: %d\n\n", | 54 | /**printf("*** Initialized Recognition ***\n\nVideo: %s\nType [1-File; 2-Mic]: %d\nFrequency: %d\n\n", |
61 | this->pathVideo, this->inputType, this->frequency);**/ | 55 | this->pathVideo, this->inputType, this->frequency);**/ |
62 | 56 | ||
@@ -93,6 +87,10 @@ void Recognize::setSizeAudioBlocs(int sec) { | @@ -93,6 +87,10 @@ void Recognize::setSizeAudioBlocs(int sec) { | ||
93 | sizeBlocs = sec; | 87 | sizeBlocs = sec; |
94 | } | 88 | } |
95 | 89 | ||
90 | +void Recognize::setPathAudioContents(char* path){ | ||
91 | + path_contents = path; | ||
92 | +} | ||
93 | + | ||
96 | 94 | ||
97 | char* Recognize::extractAudioFromVideo() { | 95 | char* Recognize::extractAudioFromVideo() { |
98 | 96 | ||
@@ -208,7 +206,6 @@ void Recognize::breakVideoParts(int timeTotal) { | @@ -208,7 +206,6 @@ void Recognize::breakVideoParts(int timeTotal) { | ||
208 | 206 | ||
209 | } | 207 | } |
210 | 208 | ||
211 | - | ||
212 | void Recognize::executeJuliusEngine() { | 209 | void Recognize::executeJuliusEngine() { |
213 | 210 | ||
214 | string command, type, freqStr; | 211 | string command, type, freqStr; |
@@ -225,7 +222,7 @@ void Recognize::executeJuliusEngine() { | @@ -225,7 +222,7 @@ void Recognize::executeJuliusEngine() { | ||
225 | sprintf(cfreq, "%i", frequency); | 222 | sprintf(cfreq, "%i", frequency); |
226 | command.append(" -smpFreq "). | 223 | command.append(" -smpFreq "). |
227 | append(cfreq). | 224 | append(cfreq). |
228 | - append(" -nolog >> "); | 225 | + append(" >> "); |
229 | command.append(path_contents).append(id).append(FILENAME_RECOGNIZED_OUT); | 226 | command.append(path_contents).append(id).append(FILENAME_RECOGNIZED_OUT); |
230 | //Command of execute Julius | 227 | //Command of execute Julius |
231 | //printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str()); | 228 | //printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str()); |
@@ -286,7 +283,6 @@ void Recognize::generateConfidence() { | @@ -286,7 +283,6 @@ void Recognize::generateConfidence() { | ||
286 | scores.push_back(avgScores/sizeAvgScores); | 283 | scores.push_back(avgScores/sizeAvgScores); |
287 | 284 | ||
288 | }else if(pass==0){ | 285 | }else if(pass==0){ |
289 | - | ||
290 | notifyListeners((char*) "SENTENCA_COM_BAIXA_QUALIDADE", 0); | 286 | notifyListeners((char*) "SENTENCA_COM_BAIXA_QUALIDADE", 0); |
291 | notifyEndExtraction(count_lines); | 287 | notifyEndExtraction(count_lines); |
292 | return; | 288 | return; |
@@ -341,7 +337,6 @@ void Recognize::filterOutputJulius() { | @@ -341,7 +337,6 @@ void Recognize::filterOutputJulius() { | ||
341 | if(getConfidence()) | 337 | if(getConfidence()) |
342 | notifyListeners(sentence_ptr, pts.front()); | 338 | notifyListeners(sentence_ptr, pts.front()); |
343 | else{ | 339 | else{ |
344 | - | ||
345 | notifyListeners((char*) "SENTENCA_COM_BAIXA_QUALIDADE", pts.front()); | 340 | notifyListeners((char*) "SENTENCA_COM_BAIXA_QUALIDADE", pts.front()); |
346 | } | 341 | } |
347 | scores.erase(scores.begin()); | 342 | scores.erase(scores.begin()); |
@@ -371,7 +366,7 @@ void Recognize::notifyListeners(char* text, int64_t pts) { | @@ -371,7 +366,7 @@ void Recognize::notifyListeners(char* text, int64_t pts) { | ||
371 | } | 366 | } |
372 | 367 | ||
373 | void Recognize::notifyEndExtraction(int sentences_size) { | 368 | void Recognize::notifyEndExtraction(int sentences_size) { |
374 | - DDPRINTF("Recognizer concluiu o reconhecimento: %d sentenças.\n", sentences_size); | 369 | + DPRINTF("Recognizer concluiu o reconhecimento: %d sentenças.\n", sentences_size); |
375 | for(list<RecognizeListener*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | 370 | for(list<RecognizeListener*>::iterator it = listeners->begin(); it != listeners->end(); it++){ |
376 | (*it)->notifyEnd(sentences_size); | 371 | (*it)->notifyEnd(sentences_size); |
377 | } | 372 | } |
@@ -409,8 +404,7 @@ void Recognize::cleanFiles() { | @@ -409,8 +404,7 @@ void Recognize::cleanFiles() { | ||
409 | void Recognize::createDir(){ | 404 | void Recognize::createDir(){ |
410 | 405 | ||
411 | string command = "mkdir "; | 406 | string command = "mkdir "; |
412 | - command.append(path_contents).append(id) | ||
413 | - .append(" && mkdir ").append(path_contents).append(id).append("/audio") | 407 | + command.append(path_contents).append(id).append("/audio") |
414 | .append(" && mkdir ").append(path_contents).append(id).append("/audio/parts") | 408 | .append(" && mkdir ").append(path_contents).append(id).append("/audio/parts") |
415 | .append(" && mkdir ").append(path_contents).append(id).append("/audio/origin"); | 409 | .append(" && mkdir ").append(path_contents).append(id).append("/audio/origin"); |
416 | system(command.c_str()); | 410 | system(command.c_str()); |
servico/src/include/serviceException.h
@@ -9,17 +9,20 @@ | @@ -9,17 +9,20 @@ | ||
9 | * * | 9 | * * |
10 | **************************************************************************/ | 10 | **************************************************************************/ |
11 | 11 | ||
12 | - #ifndef SERVICEEXCEPTION_H | ||
13 | - #define SERVICEEXCEPTION_H | 12 | +#ifndef SERVICEEXCEPTION_H |
13 | +#define SERVICEEXCEPTION_H | ||
14 | 14 | ||
15 | - #include <lavidlib/base/RuntimeException.h> | 15 | +#include <lavidlib/base/RuntimeException.h> |
16 | 16 | ||
17 | - using namespace lavidlib; | 17 | +using namespace std; |
18 | +using namespace lavidlib; | ||
18 | 19 | ||
19 | - class ServiceException : public RuntimeException { | ||
20 | - public: | ||
21 | - ServiceException(const std::string message); | ||
22 | - ServiceException(const char* message); | ||
23 | - }; | 20 | +class ServiceException : public RuntimeException { |
21 | + | ||
22 | +public: | ||
23 | + ServiceException(const string message); | ||
24 | + ServiceException(const char* message); | ||
25 | + | ||
26 | +}; | ||
24 | 27 | ||
25 | - #endif /* SERVICEEXCEPTION_H */ | ||
26 | \ No newline at end of file | 28 | \ No newline at end of file |
29 | +#endif /* SERVICEEXCEPTION_H */ | ||
27 | \ No newline at end of file | 30 | \ No newline at end of file |
servico/src/include/serviceWindowGeneration.h
1 | #ifndef SERVICEWINDOWGENERATION_H | 1 | #ifndef SERVICEWINDOWGENERATION_H |
2 | -#define SERVICEWINDOWGENERATION_H | 2 | +#define SERVICEWINDOWGENERATION_H |
3 | 3 | ||
4 | -#include <stdlib.h> | ||
5 | -#include <locale> | ||
6 | -#include <string> | ||
7 | -#include <iostream> | ||
8 | #include <vector> | 4 | #include <vector> |
9 | -#include <fcntl.h> | ||
10 | -#include <sys/time.h> | ||
11 | -#include <limits.h> | 5 | +#include <stdint.h> |
6 | +#include <string> | ||
7 | +#include <locale> | ||
8 | +#include "jthread.h" | ||
12 | #include "dprintf.h" | 9 | #include "dprintf.h" |
13 | -#include "Mixer.h" | ||
14 | -//#include "inputFile.h" | ||
15 | #include "property.h" | 10 | #include "property.h" |
16 | -#include "listenerTradutor.h" | ||
17 | -#include "tradutorPortGlosa.h" | ||
18 | -//#include "httpstreamer.h" | 11 | +#include "Mixer.h" |
19 | #include "synchronizer.h" | 12 | #include "synchronizer.h" |
20 | #include "listenerSynchronizer.h" | 13 | #include "listenerSynchronizer.h" |
14 | +#include "listenerTradutor.h" | ||
15 | +#include "tradutorPortGlosa.h" | ||
21 | #include "serviceException.h" | 16 | #include "serviceException.h" |
22 | #include <lavidlib/base/RuntimeException.h> | 17 | #include <lavidlib/base/RuntimeException.h> |
23 | 18 | ||
24 | -#define WEB_USER "web" | ||
25 | -#define VIDEO_POSE_NEUTRA "poseneutra" | 19 | +#define DEVELOPER "devel" |
20 | +#define PRODUCTION "prod" | ||
26 | #define BASEDIR "vlibras_user/dicionario_libras/" | 21 | #define BASEDIR "vlibras_user/dicionario_libras/" |
27 | #define BASEDIRTRANSP "vlibras_user/dicionarioTransp_libras/" | 22 | #define BASEDIRTRANSP "vlibras_user/dicionarioTransp_libras/" |
23 | +#define VIDEO_POSE_NEUTRA "poseneutra" | ||
28 | #define EXTENSAO_DICIONARIO ".ts" | 24 | #define EXTENSAO_DICIONARIO ".ts" |
29 | -#define PATH_CONTENTS "vlibras_user/.vlibras-conf/contents/" | ||
30 | -#define PATH_API "vlibras_user/vlibras-api/videos/" | 25 | +#define PATH_DEVEL "vlibras_user/vlibras-contents/videos/" |
26 | +#define PATH_DEVEL_UPLOADS "vlibras_user/vlibras-contents/uploads/" | ||
27 | +#define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-conf/uploads/" | ||
28 | +#define PATH_CONF_FILE "vlibras_user/.vlibras-conf/configuration/params-vbox.conf" | ||
31 | #define MAX_SIZE_PATH 256 | 29 | #define MAX_SIZE_PATH 256 |
32 | 30 | ||
33 | -#define SERVICE_TYPE_SRT 1 /* Subtitle SRT */ | ||
34 | -#define SERVICE_TYPE_REC 2 /* Reconhecimento de Voz */ | ||
35 | -#define SERVICE_TYPE_TEXT 3 /* Texto */ | ||
36 | -#define SERVICE_TYPE_SRT_ONLY 4 /* Subtitle SRT ONLY */ | ||
37 | -#define SERVICE_TYPE_REC_ONLY_AUDIO 5 /* Subtitle AUDIO ONLY */ | ||
38 | - | ||
39 | using namespace Tradutor; | 31 | using namespace Tradutor; |
40 | -//using namespace Util; | 32 | +using namespace jthread; |
41 | using namespace std; | 33 | using namespace std; |
42 | -using namespace sndesc; | ||
43 | 34 | ||
44 | -class ServiceWindowGeneration : public ListenerTradutor, public ListenerSynchronizer{ | 35 | +class ServiceWindowGeneration { |
45 | 36 | ||
46 | protected: | 37 | protected: |
38 | + TradutorPortGlosa* tradutor; | ||
39 | + Synchronizer* sincronizador; | ||
40 | + PropertyHandler* ppty_h; | ||
41 | + Mixer* mixer; | ||
42 | + | ||
43 | + vector<int64_t>* vetor_pts; | ||
47 | 44 | ||
48 | - TradutorPortGlosa * tradutor; | ||
49 | - //HttpStreamer *sincronizador; | ||
50 | - Synchronizer * sincronizador; | ||
51 | - //InputFile * inputfile; | ||
52 | - Mixer * mixer; | ||
53 | - PropertyHandler* reader; | 45 | + bool finish; |
46 | + bool running; | ||
54 | 47 | ||
55 | - vector<int64_t> * vetor_pts; | ||
56 | - | ||
57 | - char* path_input; | ||
58 | - char* path_audio; | 48 | + char* path_input; |
59 | char* path_libras; | 49 | char* path_libras; |
50 | + char* path_contents; | ||
51 | + char* path_uploads; | ||
60 | char* client_type; | 52 | char* client_type; |
61 | char* user_id; | 53 | char* user_id; |
62 | 54 | ||
63 | - bool running; | 55 | + int size; |
56 | + int position; | ||
57 | + int transparency; | ||
58 | + int sub_language; | ||
59 | + int service_type; | ||
60 | + int numero_legendas; | ||
61 | + int legendas_enviadas; | ||
62 | + | ||
63 | + virtual void setSizeOfSubtitles(int sub_size) = 0; | ||
64 | + virtual void setPathContents() = 0; | ||
65 | + virtual void setPathLibras() = 0; | ||
66 | + virtual void setBackground() = 0; | ||
67 | + | ||
68 | + //virtual void transcodeVideoToWebm(); | ||
69 | + virtual void transcodeVideoToMp4() = 0; | ||
64 | 70 | ||
65 | - int size, position, transparency, sublanguage, serviceType, numero_legendas, legendas_enviadas; | ||
66 | - | ||
67 | - void setSize(int); | ||
68 | - void setPosition(int); | ||
69 | - void setTransparency(int); | ||
70 | - void setSubLanguage(int sublang); | ||
71 | - void setServiceType(int type); | ||
72 | - void setUserId(char* _userId); | ||
73 | - void setClientType(char* client_type); | ||
74 | - void setPathInput(char* _path_input); | ||
75 | - | ||
76 | - void transcodeVideoToWebm(); | ||
77 | - void transcodeVideoToMp4(); | ||
78 | - void createThumbnail(); | ||
79 | - | ||
80 | public: | 71 | public: |
81 | - | ||
82 | - ServiceWindowGeneration(); | ||
83 | - ~ServiceWindowGeneration(); | ||
84 | - | ||
85 | - virtual void notifyTranslation(vector<string>* glosas); | ||
86 | - virtual void notifyEndOfSynchronization(); | ||
87 | - | ||
88 | - void initialize(); | ||
89 | - bool isRunning(); | ||
90 | - | ||
91 | - char* getPathLibras(); | ||
92 | - char* getUserId(); | ||
93 | - char* getClientType(); | ||
94 | - char* getPathInput(); | ||
95 | - string getPathAPI(); | ||
96 | - TradutorPortGlosa * getTradutor(); | ||
97 | - | ||
98 | - void setPathLibras(); | ||
99 | - void setSizeOfSubtitles(int sub_size); | ||
100 | - void adicionaPTS(int64_t pts); | 72 | + virtual void initialize() = 0; |
73 | + virtual bool isFinished() = 0; | ||
74 | + virtual void notifyTranslator(unsigned char* text) = 0; | ||
101 | }; | 75 | }; |
102 | 76 | ||
103 | -#endif /* SERVICEWINDOWGENERATION_H */ | 77 | -#endif /* SERVICEWINDOWGENERATION_H */ |
78 | +#endif /* SERVICEWINDOWGENERATION_H */ | ||
104 | \ No newline at end of file | 79 | \ No newline at end of file |
servico/src/include/serviceWindowGenerationFromREC.h
@@ -1,35 +0,0 @@ | @@ -1,35 +0,0 @@ | ||
1 | -#ifndef SERVICEWINDOWGENERATIONFROMREC_H | ||
2 | -#define SERVICEWINDOWGENERATIONFROMREC_H | ||
3 | - | ||
4 | -#include <stdint.h> | ||
5 | -#include <stdio.h> | ||
6 | -#include "jthread.h" | ||
7 | -#include "serviceWindowGeneration.h" | ||
8 | -#include "recognize.h" | ||
9 | -#include "inputFile.h" | ||
10 | - | ||
11 | -using namespace std; | ||
12 | -using namespace jthread; | ||
13 | - | ||
14 | -class ServiceWindowGenerationFromREC : public ServiceWindowGeneration, public RecognizeListener, public Thread { | ||
15 | - | ||
16 | -private: | ||
17 | - Recognize *rec; | ||
18 | - bool finish; | ||
19 | - | ||
20 | -public: | ||
21 | - | ||
22 | - ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType, char* rate); | ||
23 | - ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, char* client_type, int _serviceType); | ||
24 | - ~ServiceWindowGenerationFromREC(); | ||
25 | - | ||
26 | - virtual void notifyTextRecognized(unsigned char* text, int64_t pts); | ||
27 | - virtual void notifyEnd(int sentences_size); | ||
28 | - void notifyTranslator(unsigned char *text); | ||
29 | - | ||
30 | - void initialize(); | ||
31 | - bool isFinished(); | ||
32 | - void Run(); | ||
33 | -}; | ||
34 | - | ||
35 | -#endif /* SERVICEWINDOWGENERATIONFROMREC_H */ |
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +#ifndef SERVICEWINDOWGENERATIONFROMREC_H | ||
2 | +#define SERVICEWINDOWGENERATIONFROMREC_H | ||
3 | + | ||
4 | +#include "recognize.h" | ||
5 | +#include "recognizeListener.h" | ||
6 | +#include "serviceWindowGeneration.h" | ||
7 | + | ||
8 | +#define SERVICE_TYPE_REC 2 | ||
9 | +#define SERVICE_TYPE_REC_ONLY_AUDIO 5 | ||
10 | + | ||
11 | +class ServiceWindowGenerationFromRec : public ServiceWindowGeneration, public RecognizeListener, public ListenerTradutor, public ListenerSynchronizer, public Thread { | ||
12 | + | ||
13 | +private: | ||
14 | + Recognize* rec; | ||
15 | + | ||
16 | + void addPTS(int64_t pts); | ||
17 | + void setSizeOfSubtitles(int sub_size); | ||
18 | + void setPathContents(); | ||
19 | + void setPathLibras(); | ||
20 | + void setBackground(); | ||
21 | + | ||
22 | + void transcodeVideoToMp4(); | ||
23 | + void createThumbnail(); | ||
24 | + bool isRunning(); | ||
25 | +public: | ||
26 | + ServiceWindowGenerationFromRec(char* pathVideo, int sublanguage, int position, int size, | ||
27 | + int transparency, char* id, int serviceType, char* rate); | ||
28 | + ServiceWindowGenerationFromRec(char* pathVideo, int sublanguage, int pos, int size, | ||
29 | + int transp, char* id, char* client, int serviceType); | ||
30 | + ~ServiceWindowGenerationFromRec(); | ||
31 | + | ||
32 | + void notifyTextRecognized(unsigned char* text, int64_t pts); | ||
33 | + void notifyTranslation(vector<string>* glosas); | ||
34 | + void notifyTranslator(unsigned char* text); | ||
35 | + void notifyEndOfSynchronization(); | ||
36 | + void notifyEnd(int sentences_size); | ||
37 | + | ||
38 | + void initialize(); | ||
39 | + bool isFinished(); | ||
40 | + void Run(); | ||
41 | +}; | ||
42 | + | ||
43 | +#endif /* SERVICEWINDOWGENERATIONFROMREC_H */ | ||
0 | \ No newline at end of file | 44 | \ No newline at end of file |
servico/src/include/serviceWindowGenerationFromSRT.h
1 | #ifndef SERVICEWINDOWGENERATIONFROMSRT_H | 1 | #ifndef SERVICEWINDOWGENERATIONFROMSRT_H |
2 | -#define SERVICEWINDOWGENERATIONFROMSRT_H | 2 | +#define SERVICEWINDOWGENERATIONFROMSRT_H |
3 | 3 | ||
4 | -#include "serviceWindowGeneration.h" | ||
5 | -#include <pthread.h> | ||
6 | -#include "inputFile.h" | ||
7 | -#include "extratorFactory.h" | ||
8 | #include "listenerSRT.h" | 4 | #include "listenerSRT.h" |
9 | -#include "stdint.h" | ||
10 | -#include <vector> | ||
11 | -#include "jthread.h" | ||
12 | - | ||
13 | -#define SRT 1 | 5 | +#include "extratorFactory.h" |
6 | +#include "serviceWindowGeneration.h" | ||
14 | 7 | ||
15 | -using namespace std; | ||
16 | -using namespace jthread; | ||
17 | -using namespace Util; | 8 | +#define SERVICE_TYPE_SRT 1 |
9 | +#define SERVICE_TYPE_SRT_ONLY 4 | ||
18 | 10 | ||
19 | -class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public Thread { | 11 | +class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public ListenerTradutor, public ListenerSynchronizer, public Thread { |
20 | 12 | ||
21 | private: | 13 | private: |
22 | - pthread_mutex_t *mutex_serviceSRT; | ||
23 | - ExtratorFactory *extrator_factory; | ||
24 | - ExtratorSRT * extratorSRT; | ||
25 | - char* path_srt; | ||
26 | - bool finish; | ||
27 | - | ||
28 | -public: | 14 | + ExtratorFactory* extrator_factory; |
15 | + ExtratorSRT* extratorSRT; | ||
29 | 16 | ||
30 | - /* Construtor 1 - legenda e vídeo */ | ||
31 | - ServiceWindowGenerationFromSRT(char* path_video, char* path_srt, int sublanguage, | ||
32 | - int position, int size, int transparency, char* id, char* client_type, int _serviceType); | ||
33 | - /* Construtor 2 - só legenda */ | ||
34 | - ServiceWindowGenerationFromSRT(char* path_srt, int transparency, char* id, char* client_type, int _serviceType); | 17 | + char* path_srt; |
18 | + | ||
19 | + void addPTS(int64_t pts); | ||
20 | + void setSizeOfSubtitles(int sub_size); | ||
21 | + void setPathContents(); | ||
22 | + void setPathLibras(); | ||
23 | + void setBackground(); | ||
24 | + | ||
25 | + void transcodeVideoToMp4(); | ||
26 | + void createThumbnail(); | ||
27 | + bool isRunning(); | ||
28 | +public: | ||
29 | + //construtor de serviço de video e legenda | ||
30 | + ServiceWindowGenerationFromSRT(char* pathVideo, char* pathSRT, int sublanguage, int pos, | ||
31 | + int size, int transp, char* id, char* client, int serviceType); | ||
32 | + //construtor de serviço de somente legenda | ||
33 | + ServiceWindowGenerationFromSRT(char* pathSRT, int transparency, char* id, char* client, int serviceType); | ||
35 | ~ServiceWindowGenerationFromSRT(); | 34 | ~ServiceWindowGenerationFromSRT(); |
36 | - | ||
37 | - virtual void notifySubtitle(unsigned char* subtitle, int64_t pts); | ||
38 | - virtual void notifyEnd(int sub_size); | ||
39 | - void notifyTranslator(unsigned char* subtitle); | 35 | + |
36 | + void notifySubtitle(unsigned char* subtitle, int64_t pts); | ||
37 | + void notifyTranslation(vector<string>* glosas); | ||
38 | + void notifyTranslator(unsigned char* text); | ||
39 | + void notifyEndOfSynchronization(); | ||
40 | + void notifyEnd(int sub_size); | ||
40 | 41 | ||
41 | void initialize(); | 42 | void initialize(); |
42 | bool isFinished(); | 43 | bool isFinished(); |
43 | void Run(); | 44 | void Run(); |
44 | - | ||
45 | - void setPathSRT(char* path_srt); | ||
46 | - | ||
47 | }; | 45 | }; |
48 | 46 | ||
49 | -#endif /* SERVICEWINDOWGENERATIONFROMSRT_H */ | 47 | +#endif /* SERVICEWINDOWGENERATIONFROMSRT_H_ */ |
50 | \ No newline at end of file | 48 | \ No newline at end of file |
servico/src/include/serviceWindowGenerationFromText.h
1 | -#ifndef _SERVICEWINDOWGENERATIONFROMTEXT_H | ||
2 | -#define _SERVICEWINDOWGENERATIONFROMTEXT_H | 1 | +#ifndef SERVICEWINDOWGENERATIONFROMTEXT_H |
2 | +#define SERVICEWINDOWGENERATIONFROMTEXT_H | ||
3 | 3 | ||
4 | -#include "serviceWindowGeneration.h" | ||
5 | -#include "extratorFactory.h" | ||
6 | #include "listenerTXT.h" | 4 | #include "listenerTXT.h" |
5 | +#include "extratorFactory.h" | ||
6 | +#include "serviceWindowGeneration.h" | ||
7 | 7 | ||
8 | -#define TXT 2 | ||
9 | -/*FIXME: está restrito a 2K bytes de texto */ | ||
10 | -#define MAX_TEXT_SIZE 2048 | 8 | +#define MAX_TEXT_SIZE 2048 //FIXME: está restrito a 2K bytes de texto |
11 | 9 | ||
12 | -class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public Thread { | 10 | +class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public ListenerTradutor, public ListenerSynchronizer, public Thread { |
13 | 11 | ||
14 | private: | 12 | private: |
15 | - ExtratorFactory *extrator_factory; | ||
16 | - ExtratorTXT * extratorTXT; | ||
17 | - bool finish; | ||
18 | - | 13 | + ExtratorFactory* extrator_factory; |
14 | + ExtratorTXT* extratorTXT; | ||
15 | + | ||
16 | + void setSizeOfSubtitles(int sub_size); | ||
17 | + void setPathContents(); | ||
18 | + void setPathLibras(); | ||
19 | + void setBackground(); | ||
20 | + | ||
21 | + void transcodeVideoToMp4(); | ||
22 | + bool isRunning(); | ||
19 | public: | 23 | public: |
20 | - ServiceWindowGenerationFromText (char* _path_file, char* user_id, int _transp, int _serviceType, char* _client_type); | ||
21 | - ~ServiceWindowGenerationFromText (); | 24 | + ServiceWindowGenerationFromText(char* pathFile, int transparency, char* id, char* client); |
25 | + ~ServiceWindowGenerationFromText(); | ||
22 | 26 | ||
23 | void notifyLine(unsigned char* line); | 27 | void notifyLine(unsigned char* line); |
28 | + void notifyTranslation(vector<string>* glosas); | ||
29 | + void notifyTranslator(unsigned char* text); | ||
30 | + void notifyEndOfSynchronization(); | ||
24 | void notifyEnd(int line_size); | 31 | void notifyEnd(int line_size); |
25 | 32 | ||
26 | void initialize(); | 33 | void initialize(); |
27 | bool isFinished(); | 34 | bool isFinished(); |
28 | - void Run(); | 35 | + void Run(); |
29 | }; | 36 | }; |
30 | 37 | ||
31 | -#endif /* _SERVICEWINDOWGENERATIONFROMTEXT_H */ | 38 | +#endif /* SERVICEWINDOWGENERATIONFROMTEXT_H */ |
32 | \ No newline at end of file | 39 | \ No newline at end of file |
servico/src/serviceException.cpp
@@ -11,10 +11,10 @@ | @@ -11,10 +11,10 @@ | ||
11 | 11 | ||
12 | 12 | ||
13 | 13 | ||
14 | - #include "serviceException.h" | 14 | +#include "serviceException.h" |
15 | 15 | ||
16 | - ServiceException::ServiceException(const std::string message) | ||
17 | - : RuntimeException(message) | 16 | + ServiceException::ServiceException(const std::string message) |
17 | + : RuntimeException(message) | ||
18 | { /* TODO */ } | 18 | { /* TODO */ } |
19 | ServiceException::ServiceException(const char* message) | 19 | ServiceException::ServiceException(const char* message) |
20 | : RuntimeException(message) | 20 | : RuntimeException(message) |
servico/src/serviceWindowGeneration.cpp
@@ -1,283 +0,0 @@ | @@ -1,283 +0,0 @@ | ||
1 | - | ||
2 | -#include "serviceWindowGeneration.h" | ||
3 | - | ||
4 | -ServiceWindowGeneration::ServiceWindowGeneration() { | ||
5 | - tradutor = new TradutorPortGlosa(); | ||
6 | - vetor_pts = new vector<int64_t >(); | ||
7 | - try{ | ||
8 | - reader = new PropertyHandler("vlibras_user/.vlibras-conf/configuration/params-vbox.conf"); | ||
9 | - }catch(RuntimeException &ex){printf("%s\n", ex.getMessage().c_str());} | ||
10 | - numero_legendas = INT_MAX; | ||
11 | - legendas_enviadas = 0; | ||
12 | - this->running = true; | ||
13 | - serviceType = 0; | ||
14 | - DPRINTF("Done!\n"); | ||
15 | -} | ||
16 | - | ||
17 | -ServiceWindowGeneration::~ServiceWindowGeneration() { | ||
18 | - free(vetor_pts); | ||
19 | - free(path_libras); | ||
20 | - if (mixer) delete mixer; | ||
21 | - if (tradutor) delete tradutor; | ||
22 | - if (sincronizador) delete sincronizador; | ||
23 | - DDDPRINTF("Service finalized!\n"); | ||
24 | -} | ||
25 | - | ||
26 | -char* ServiceWindowGeneration::getPathLibras() { | ||
27 | - return path_libras; | ||
28 | -} | ||
29 | - | ||
30 | -char* ServiceWindowGeneration::getPathInput() { | ||
31 | - return path_input; | ||
32 | -} | ||
33 | - | ||
34 | -string ServiceWindowGeneration::getPathAPI() { | ||
35 | - return PATH_API; | ||
36 | -} | ||
37 | - | ||
38 | -char* ServiceWindowGeneration::getClientType(){ | ||
39 | - return client_type; | ||
40 | -} | ||
41 | - | ||
42 | -char* ServiceWindowGeneration::getUserId() { | ||
43 | - return user_id; | ||
44 | -} | ||
45 | - | ||
46 | -void ServiceWindowGeneration::setPathInput(char* _path_input) { | ||
47 | - this->path_input = _path_input; | ||
48 | -} | ||
49 | - | ||
50 | -void ServiceWindowGeneration::setClientType(char* client_type) { | ||
51 | - this->client_type = client_type; | ||
52 | -} | ||
53 | - | ||
54 | -void ServiceWindowGeneration::setUserId(char* _userId) { | ||
55 | - this->user_id = _userId; | ||
56 | -} | ||
57 | - | ||
58 | -void ServiceWindowGeneration::setServiceType(int type) { | ||
59 | - serviceType = type; | ||
60 | -} | ||
61 | - | ||
62 | -void ServiceWindowGeneration::setSubLanguage(int sublang){ | ||
63 | - this->sublanguage = sublang; | ||
64 | -} | ||
65 | - | ||
66 | -void ServiceWindowGeneration::setSize(int size){ | ||
67 | - this->size = size; | ||
68 | -} | ||
69 | - | ||
70 | -void ServiceWindowGeneration::setPosition(int position){ | ||
71 | - this->position = position; | ||
72 | -} | ||
73 | - | ||
74 | -void ServiceWindowGeneration::setTransparency(int transparency){ | ||
75 | - this->transparency = transparency; | ||
76 | -} | ||
77 | - | ||
78 | -void ServiceWindowGeneration::setPathLibras() { | ||
79 | - | ||
80 | - char* final_path = new char[MAX_SIZE_PATH]; | ||
81 | - | ||
82 | - if(strcmp(client_type, (char*)WEB_USER) == 0){ | ||
83 | - strcpy(final_path, "vlibras_user/vlibras-api/uploads/"); | ||
84 | - strcat(final_path, this->user_id); | ||
85 | - strcat(final_path, "/libras.ts"); | ||
86 | - }else{ | ||
87 | - strcpy(final_path, PATH_CONTENTS); | ||
88 | - strcat(final_path, "libras.ts"); | ||
89 | - } | ||
90 | - | ||
91 | - this->path_libras = final_path; | ||
92 | - //DDPRINTF("Path TS File: %s\n", this->path_libras); | ||
93 | -} | ||
94 | - | ||
95 | -void ServiceWindowGeneration::setSizeOfSubtitles(int sub_size) { | ||
96 | - numero_legendas = sub_size; | ||
97 | - if (legendas_enviadas >= numero_legendas){ | ||
98 | - sincronizador->stop(); | ||
99 | - } | ||
100 | - | ||
101 | -} | ||
102 | - | ||
103 | -void ServiceWindowGeneration::adicionaPTS(int64_t pts) { | ||
104 | - vetor_pts->push_back(pts); | ||
105 | -} | ||
106 | - | ||
107 | -/* Checado pela subclasse para saber quando o sincronizador terminar. */ | ||
108 | -bool ServiceWindowGeneration::isRunning() { | ||
109 | - return this->running; | ||
110 | -} | ||
111 | - | ||
112 | -/* Quando o sincronizador termina, ele invoca esse método para avisar! */ | ||
113 | -void ServiceWindowGeneration::notifyEndOfSynchronization() { | ||
114 | - if (serviceType == SERVICE_TYPE_REC || serviceType == SERVICE_TYPE_SRT) { | ||
115 | - mixer = new Mixer(); | ||
116 | - mixer->initialize(this->path_input, this->path_libras,this->position,this->size,this->transparency, this->user_id, this->client_type); | ||
117 | - createThumbnail(); | ||
118 | - }else{ | ||
119 | - transcodeVideoToMp4(); | ||
120 | - } | ||
121 | - this->running = false; | ||
122 | -} | ||
123 | - | ||
124 | -void ServiceWindowGeneration::initialize() { | ||
125 | - | ||
126 | - setPathLibras(); | ||
127 | - | ||
128 | - if (this->sublanguage == 1) { | ||
129 | - tradutor->addListener(this); | ||
130 | - } | ||
131 | - | ||
132 | - // o path do arquivo só poderá conter um "."(ponto), esse identifica a extensão. | ||
133 | - | ||
134 | - vector<string> tokens; | ||
135 | - /* Se for texto não é necessário vídeo de entrada (path_input) */ | ||
136 | - if (serviceType != SERVICE_TYPE_TEXT && serviceType != SERVICE_TYPE_SRT_ONLY && | ||
137 | - serviceType != SERVICE_TYPE_REC_ONLY_AUDIO) { | ||
138 | - char * pathtmp = this->path_input; | ||
139 | - int size = strlen(pathtmp); | ||
140 | - char vtemp [size]; | ||
141 | - strcpy(vtemp, pathtmp); | ||
142 | - pathtmp = strtok(vtemp, "."); | ||
143 | - while (pathtmp != NULL) { | ||
144 | - tokens.push_back(string(pathtmp)); | ||
145 | - pathtmp = strtok(NULL, "."); | ||
146 | - } | ||
147 | - string buildstrpath = tokens[0] + "_libras" + EXTENSAO_DICIONARIO; | ||
148 | - this->path_libras = new char[buildstrpath.size()]; | ||
149 | - strcpy(this->path_libras, buildstrpath.c_str()); | ||
150 | - //printf("O ServiceWGeneration montou o seguinte path para o vídeo de Libras: %s\n", path_libras); | ||
151 | - | ||
152 | - } else { | ||
153 | - tradutor->addListener(this); | ||
154 | - } | ||
155 | - | ||
156 | - if(this->transparency == 0) { //pega dicionario com BackGround opaco | ||
157 | - sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, | ||
158 | - this->path_libras, this->transparency); | ||
159 | - } else { | ||
160 | - if(this->transparency == 1) { //pega dicionario com BackGround transparente | ||
161 | - sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, | ||
162 | - this->path_libras,this->transparency); | ||
163 | - } | ||
164 | - } | ||
165 | - | ||
166 | - if (serviceType != SERVICE_TYPE_SRT) { | ||
167 | - uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro | ||
168 | - sincronizador->setPCRBase(pcr_base); | ||
169 | - } | ||
170 | - sincronizador->addListener(this); | ||
171 | - sincronizador->Start(); | ||
172 | -} | ||
173 | - | ||
174 | -/* Método utilizado pelo Tradutor para notificar o texto traduzido. */ | ||
175 | -void ServiceWindowGeneration::notifyTranslation(vector<string> * glosas) { | ||
176 | - | ||
177 | - if (serviceType != SERVICE_TYPE_TEXT) { | ||
178 | - for (int i = 0; i < glosas->size(); i++) { | ||
179 | - std::locale loc; | ||
180 | - std::string glosa_lower = ""; | ||
181 | - for (int k = 0; k < glosas->at(i).length(); k++) | ||
182 | - glosa_lower += std::tolower(glosas->at(i).at(k), loc); | ||
183 | - | ||
184 | - //cout << "__Glosa [" << i << "] = " << glosa_lower << endl; | ||
185 | - int64_t pts_notificado = vetor_pts->front(); | ||
186 | - sincronizador->recebeglosa(glosa_lower, pts_notificado); | ||
187 | - } | ||
188 | - /* O 'numero_legendas' é informado pela subclasse através do método setSizeOfSubtitles. | ||
189 | - Então, inicialmente, seu valor corresponde a um número inteiro máximo. | ||
190 | - */ | ||
191 | - /*printf("numero_legendas = %d\nlegendas_enviadas = %d\n", numero_legendas, legendas_enviadas); | ||
192 | - if (legendas_enviadas >= numero_legendas) { | ||
193 | - sincronizador->stop(); | ||
194 | - }*/ | ||
195 | - vetor_pts->erase(vetor_pts->begin()); | ||
196 | - } else { | ||
197 | - //Nova versão! | ||
198 | - for (int i = 0; i < glosas->size(); i++) { | ||
199 | - std::locale loc; | ||
200 | - std::string glosa_lower = ""; | ||
201 | - for (int k = 0; k < glosas->at(i).length(); k++) | ||
202 | - glosa_lower += std::tolower(glosas->at(i).at(k), loc); | ||
203 | - | ||
204 | - //cout << "__Glosa [" << i << "] = " << glosa_lower << endl; | ||
205 | - sincronizador->recebeglosa(glosa_lower, 1000); | ||
206 | - } | ||
207 | - sincronizador->stop(); | ||
208 | - } | ||
209 | - legendas_enviadas++; | ||
210 | -} | ||
211 | - | ||
212 | -void ServiceWindowGeneration::transcodeVideoToWebm() { | ||
213 | - //printf("[INFO]: A transcodificação para .webm está ativada!\n"); | ||
214 | - DDDPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); | ||
215 | - string command = "ffmpeg -i "; | ||
216 | - command.append(path_libras) | ||
217 | - .append(" -vcodec libvpx -acodec libvorbis ") | ||
218 | - //.append(" -v quiet ") | ||
219 | - .append(PATH_API) | ||
220 | - .append(getUserId()) | ||
221 | - .append(".webm"); | ||
222 | - //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); | ||
223 | - system(command.c_str()); | ||
224 | -} | ||
225 | - | ||
226 | -void ServiceWindowGeneration::transcodeVideoToMp4() { | ||
227 | - //if (serviceType == SERVICE_TYPE_TEXT && strcmp(client_type, (char*)"WEB") == 0) | ||
228 | - // transcodeVideoToWebm(); | ||
229 | - //else{ | ||
230 | - //printf("[INFO]: A transcodificação para .mp4 está ativada!\n"); | ||
231 | - DDDPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); | ||
232 | - string command = "ffmpeg -i "; | ||
233 | - command.append(path_libras) | ||
234 | - .append(" -qscale 0 -strict experimental -vcodec libx264 -preset fast -r 30 "); | ||
235 | - //.append(" -v quiet "); | ||
236 | - | ||
237 | - if(strcmp(client_type, (char*)WEB_USER) == 0){ | ||
238 | - command.append(PATH_API).append(getUserId()); | ||
239 | - | ||
240 | - }else{ | ||
241 | - try{ | ||
242 | - char* vPath = new char[256]; | ||
243 | - vPath = reader->getAttributeValue("STORAGE"); | ||
244 | - command.append(vPath).append("/").append(getUserId()); | ||
245 | - }catch(RuntimeException &ex){ | ||
246 | - printf("%s\n", ex.getMessage().c_str()); | ||
247 | - } | ||
248 | - } | ||
249 | - | ||
250 | - command.append(".mp4"); | ||
251 | - //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); | ||
252 | - system(command.c_str()); | ||
253 | - | ||
254 | - //.append(" -strict experimental -vcodec mjpeg -r 30 -pix_fmt yuvj422p ") | ||
255 | - //.append(" -strict experimental -vcodec mpeg2video -r 30 ") | ||
256 | - //} | ||
257 | -} | ||
258 | - | ||
259 | -void ServiceWindowGeneration::createThumbnail(){ | ||
260 | - string command = "ffmpeg -ss 10 -i "; | ||
261 | - //command.append(PATH_API).append(user_id).append(".mp4") | ||
262 | - //.append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 "); | ||
263 | - //.append(" -v quiet "); | ||
264 | - | ||
265 | - if(strcmp(client_type, (char*)WEB_USER) == 0){ | ||
266 | - command.append(PATH_API).append(user_id).append(".mp4") | ||
267 | - .append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 ") | ||
268 | - .append(PATH_API).append(getUserId()); | ||
269 | - }else{ | ||
270 | - try{ | ||
271 | - char* pPath = new char[256]; | ||
272 | - pPath = reader->getAttributeValue("STORAGE"); | ||
273 | - command.append(pPath).append("/").append(getUserId()).append(".mp4"); | ||
274 | - }catch(RuntimeException &ex){ | ||
275 | - printf("%s\n", ex.getMessage().c_str()); | ||
276 | - } | ||
277 | - command.append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 ") | ||
278 | - .append(" -v quiet ") | ||
279 | - .append(PATH_CONTENTS).append(getUserId()); | ||
280 | - } | ||
281 | - command.append(".png"); | ||
282 | - system(command.c_str()); | ||
283 | -} | ||
284 | \ No newline at end of file | 0 | \ No newline at end of file |
servico/src/serviceWindowGenerationFromREC.cpp
@@ -1,81 +0,0 @@ | @@ -1,81 +0,0 @@ | ||
1 | -#include "serviceWindowGenerationFromREC.h" | ||
2 | - | ||
3 | -ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( | ||
4 | - char* path_video, int sublanguage, int position, int size, int transparency, char* id, int serviceType, char* rate) { | ||
5 | - | ||
6 | - setPathInput(path_video); | ||
7 | - setSubLanguage(sublanguage); | ||
8 | - setPosition(position); | ||
9 | - setSize(size); | ||
10 | - setTransparency(transparency); | ||
11 | - setServiceType(serviceType); | ||
12 | - setUserId(id); | ||
13 | - rec = new Recognize(path_video, id, rate); | ||
14 | - finish = false; | ||
15 | - DPRINTF("Done!\n"); | ||
16 | -} | ||
17 | - | ||
18 | -ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( | ||
19 | - char* path_video, int sublanguage, int position, int size, int transparency, char* id, char* client_type, int serviceType) { | ||
20 | - | ||
21 | - setPathInput(path_video); | ||
22 | - setSubLanguage(sublanguage); | ||
23 | - setPosition(position); | ||
24 | - setSize(size); | ||
25 | - setTransparency(transparency); | ||
26 | - setServiceType(serviceType); | ||
27 | - setClientType(client_type); | ||
28 | - setUserId(id); | ||
29 | - if(strcmp(client_type, "web") == 0) | ||
30 | - rec = new Recognize(path_video, id, 1);// parametro 1 indica que é um cliente web | ||
31 | - else | ||
32 | - rec = new Recognize(path_video, id, 0);// parametro 0 indica que é um cliente diferente, ex: cloud | ||
33 | - | ||
34 | - finish = false; | ||
35 | - DPRINTF("Done!\n"); | ||
36 | -} | ||
37 | - | ||
38 | -ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() { | ||
39 | - delete rec; | ||
40 | - DDDPRINTF("Service REC finished!\n"); | ||
41 | -} | ||
42 | - | ||
43 | -void ServiceWindowGenerationFromREC::notifyTranslator(unsigned char *text) { | ||
44 | - tradutor->traduz(text); | ||
45 | -} | ||
46 | - | ||
47 | -void ServiceWindowGenerationFromREC::notifyTextRecognized(unsigned char* text, int64_t pts) { | ||
48 | - adicionaPTS(pts); | ||
49 | - notifyTranslator(text); | ||
50 | -} | ||
51 | - | ||
52 | -bool ServiceWindowGenerationFromREC::isFinished(){ | ||
53 | - return finish; | ||
54 | -} | ||
55 | - | ||
56 | -void ServiceWindowGenerationFromREC::notifyEnd(int sentences_size) { | ||
57 | - DDPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); | ||
58 | - setSizeOfSubtitles(sentences_size); | ||
59 | -} | ||
60 | - | ||
61 | -void ServiceWindowGenerationFromREC::initialize() { | ||
62 | - | ||
63 | - rec->addListener(this); | ||
64 | - | ||
65 | - ServiceWindowGeneration::initialize(); | ||
66 | - | ||
67 | - try{ | ||
68 | - rec->initialize(); | ||
69 | - } catch(RecognizeException ex){ | ||
70 | - throw ServiceException(ex.getMessage()); | ||
71 | - } | ||
72 | - this->Start(); | ||
73 | -} | ||
74 | - | ||
75 | -void ServiceWindowGenerationFromREC::Run() { | ||
76 | - | ||
77 | - while (isRunning()) { | ||
78 | - usleep(200000); | ||
79 | - } | ||
80 | - finish = true; | ||
81 | -} |
@@ -0,0 +1,224 @@ | @@ -0,0 +1,224 @@ | ||
1 | +#include "serviceWindowGenerationFromRec.h" | ||
2 | + | ||
3 | +ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( | ||
4 | + char* pathVideo, int sublanguage, int pos, int size, int transp, char* id, int serviceType, char* rate){ | ||
5 | + | ||
6 | + this->path_input = pathVideo; | ||
7 | + this->sub_language = sublanguage; | ||
8 | + this->position = pos; | ||
9 | + this->size = size; | ||
10 | + this->transparency = transp; | ||
11 | + this->user_id = id; | ||
12 | + this->service_type = serviceType; | ||
13 | + numero_legendas = INT_MAX; | ||
14 | + legendas_enviadas = 0; | ||
15 | + vetor_pts = new vector<int64_t >(); | ||
16 | + rec = new Recognize(pathVideo, id, rate); | ||
17 | + tradutor = new TradutorPortGlosa(); | ||
18 | + running = true; | ||
19 | + finish = false; | ||
20 | + DPRINTF("Done!\n"); | ||
21 | +} | ||
22 | + | ||
23 | +ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( | ||
24 | + char* pathVideo, int sublanguage, int pos, int size, int transp, char* id, char* client, int serviceType){ | ||
25 | + | ||
26 | + this->path_input = pathVideo; | ||
27 | + this->sub_language = sublanguage; | ||
28 | + this->position = pos; | ||
29 | + this->size = size; | ||
30 | + this->transparency = transp; | ||
31 | + this->user_id = id; | ||
32 | + this->client_type = client; | ||
33 | + this->service_type = serviceType; | ||
34 | + numero_legendas = INT_MAX; | ||
35 | + legendas_enviadas = 0; | ||
36 | + vetor_pts = new vector<int64_t >(); | ||
37 | + rec = new Recognize(path_input, id);// parametro 1 indica que é um cliente web | ||
38 | + tradutor = new TradutorPortGlosa(); | ||
39 | + setPathContents(); | ||
40 | + running = true; | ||
41 | + finish = false; | ||
42 | + DPRINTF("Done!\n"); | ||
43 | +} | ||
44 | + | ||
45 | +ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){ | ||
46 | + free(vetor_pts); | ||
47 | + delete(ppty_h); | ||
48 | + if (tradutor) delete tradutor; | ||
49 | + if (rec) delete rec; | ||
50 | + if (sincronizador) delete sincronizador; | ||
51 | + if (mixer) delete mixer; | ||
52 | + DDDPRINTF("Service Rec finished!\n"); | ||
53 | +} | ||
54 | + | ||
55 | +void ServiceWindowGenerationFromRec::setPathContents(){ | ||
56 | + if(strcmp(client_type,DEVELOPER) == 0){ | ||
57 | + this->path_contents = PATH_DEVEL; | ||
58 | + this->path_uploads = PATH_DEVEL_UPLOADS; | ||
59 | + rec->setPathAudioContents(path_uploads); | ||
60 | + }else if(strcmp(client_type, PRODUCTION) == 0){ | ||
61 | + try{ | ||
62 | + ppty_h = new PropertyHandler(PATH_CONF_FILE, PropertyHandler::READ); | ||
63 | + this->path_contents = (char*) ppty_h->get_attibute_value("STORAGE"); | ||
64 | + }catch(RuntimeException &ex){ | ||
65 | + printf("%s\n", ex.getMessage().c_str()); | ||
66 | + } | ||
67 | + this->path_uploads = PATH_VBOX_UPLOADS; | ||
68 | + rec->setPathAudioContents(path_uploads); | ||
69 | + }else{ | ||
70 | + throw new ServiceException("Invalid client!"); | ||
71 | + } | ||
72 | +} | ||
73 | + | ||
74 | +void ServiceWindowGenerationFromRec::setPathLibras(){ | ||
75 | + char* final_path = new char[MAX_SIZE_PATH]; | ||
76 | + strcpy(final_path, this->path_uploads); | ||
77 | + strcat(final_path, this->user_id); | ||
78 | + strcat(final_path, "/video_libras.ts"); | ||
79 | + | ||
80 | + this->path_libras = final_path; | ||
81 | +} | ||
82 | + | ||
83 | +void ServiceWindowGenerationFromRec::setBackground(){ | ||
84 | + if(this->transparency == 0) { //pega dicionario com BackGround opaco | ||
85 | + sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, | ||
86 | + this->path_libras, this->transparency); | ||
87 | + } else { | ||
88 | + if(this->transparency == 1) { //pega dicionario com BackGround transparente | ||
89 | + sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, | ||
90 | + this->path_libras, this->transparency); | ||
91 | + } | ||
92 | + } | ||
93 | +} | ||
94 | + | ||
95 | +void ServiceWindowGenerationFromRec::setSizeOfSubtitles(int sub_size){ | ||
96 | + numero_legendas = sub_size; | ||
97 | + if (legendas_enviadas >= numero_legendas) | ||
98 | + sincronizador->stop(); | ||
99 | +} | ||
100 | + | ||
101 | +void ServiceWindowGenerationFromRec::addPTS(int64_t pts){ | ||
102 | + vetor_pts->push_back(pts); | ||
103 | +} | ||
104 | + | ||
105 | +void ServiceWindowGenerationFromRec::notifyTranslator(unsigned char* text){ | ||
106 | + tradutor->traduz(text); | ||
107 | +} | ||
108 | + | ||
109 | +//Metodo utilizado pelo reconhecedor para avisar sobre novas sentenças reconhecidas | ||
110 | +void ServiceWindowGenerationFromRec::notifyTextRecognized(unsigned char* text, int64_t pts){ | ||
111 | + addPTS(pts); | ||
112 | + notifyTranslator(text); | ||
113 | +} | ||
114 | + | ||
115 | +//Quando o sincronizador termina, ele invoca esse método para avisar | ||
116 | +void ServiceWindowGenerationFromRec::notifyEndOfSynchronization() { | ||
117 | + if (this->service_type == SERVICE_TYPE_REC) { | ||
118 | + mixer = new Mixer(); | ||
119 | + mixer->initialize(this->path_input, this->path_libras,this->position,this->size, | ||
120 | + this->transparency, this->user_id, this->path_uploads, this->path_contents); | ||
121 | + createThumbnail(); | ||
122 | + }else{ | ||
123 | + transcodeVideoToMp4(); | ||
124 | + } | ||
125 | + this->running = false; | ||
126 | +} | ||
127 | + | ||
128 | +void ServiceWindowGenerationFromRec::notifyTranslation(vector<string> * glosas) { | ||
129 | + for (int i = 0; i < glosas->size(); i++) { | ||
130 | + locale loc; | ||
131 | + string glosa_lower = ""; | ||
132 | + for (int k = 0; k < glosas->at(i).length(); k++){ | ||
133 | + glosa_lower += std::tolower(glosas->at(i).at(k), loc); | ||
134 | + } | ||
135 | + int64_t pts_notificado = vetor_pts->front(); | ||
136 | + sincronizador->recebeglosa(glosa_lower, pts_notificado); | ||
137 | + } | ||
138 | + vetor_pts->erase(vetor_pts->begin()); | ||
139 | + legendas_enviadas++; | ||
140 | +} | ||
141 | + | ||
142 | +void ServiceWindowGenerationFromRec::notifyEnd(int sentences_size){ | ||
143 | + DPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); | ||
144 | + setSizeOfSubtitles(sentences_size); | ||
145 | +} | ||
146 | + | ||
147 | +bool ServiceWindowGenerationFromRec::isRunning(){ | ||
148 | + return this->running; | ||
149 | +} | ||
150 | + | ||
151 | +bool ServiceWindowGenerationFromRec::isFinished(){ | ||
152 | + return this->finish; | ||
153 | +} | ||
154 | + | ||
155 | +void ServiceWindowGenerationFromRec::initialize(){ | ||
156 | + DPRINTF("Service REC Initialize.\n"); | ||
157 | + rec->addListener(this); | ||
158 | + setPathLibras(); | ||
159 | + | ||
160 | + if(this->sub_language == 1) | ||
161 | + tradutor->addListener(this); | ||
162 | + | ||
163 | + if(this->service_type != SERVICE_TYPE_REC_ONLY_AUDIO){ | ||
164 | + vector<string> tokens; | ||
165 | + char* pathtmp = this->path_input; | ||
166 | + int size = strlen(pathtmp); | ||
167 | + char vtemp [size]; | ||
168 | + | ||
169 | + strcpy(vtemp, pathtmp); | ||
170 | + pathtmp = strtok(vtemp, "."); | ||
171 | + while (pathtmp != NULL) { | ||
172 | + tokens.push_back(string(pathtmp)); | ||
173 | + pathtmp = strtok(NULL, "."); | ||
174 | + } | ||
175 | + | ||
176 | + string buildstrpath = tokens[0] + "_libras" + EXTENSAO_DICIONARIO; | ||
177 | + this->path_libras = new char[buildstrpath.size()]; | ||
178 | + strcpy(this->path_libras, buildstrpath.c_str()); | ||
179 | + //printf("O Serviço montou o seguinte path para o vídeo de Libras: %s\n", path_libras); | ||
180 | + | ||
181 | + }else{ | ||
182 | + tradutor->addListener(this); | ||
183 | + } | ||
184 | + | ||
185 | + setBackground(); | ||
186 | + | ||
187 | + uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro | ||
188 | + sincronizador->setPCRBase(pcr_base); | ||
189 | + sincronizador->addListener(this); | ||
190 | + sincronizador->Start(); | ||
191 | + | ||
192 | + try{ | ||
193 | + rec->initialize(); | ||
194 | + } catch(RecognizeException ex){ | ||
195 | + throw ServiceException(ex.getMessage()); | ||
196 | + } | ||
197 | + this->Start(); | ||
198 | +} | ||
199 | + | ||
200 | +void ServiceWindowGenerationFromRec::transcodeVideoToMp4(){ | ||
201 | + DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); | ||
202 | + string command = "ffmpeg -i "; | ||
203 | + command.append(path_libras) | ||
204 | + .append(" -qscale 0 -strict experimental -vcodec libx264 -preset fast -r 30 ").append(" -v quiet ") | ||
205 | + .append(path_contents).append(user_id).append(".mp4"); | ||
206 | + //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); | ||
207 | + system(command.c_str()); | ||
208 | +} | ||
209 | + | ||
210 | +void ServiceWindowGenerationFromRec::createThumbnail(){ | ||
211 | + string command = "ffmpeg -ss 10 -i "; | ||
212 | + command.append(path_contents).append(user_id).append(".mp4") | ||
213 | + .append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 ").append(" -v quiet ") | ||
214 | + .append(path_contents).append(user_id).append(".png"); | ||
215 | + //printf("[INFO]: Thumbnail command -> %s\n", command.c_str()); | ||
216 | + system(command.c_str()); | ||
217 | +} | ||
218 | + | ||
219 | +void ServiceWindowGenerationFromRec::Run(){ | ||
220 | + while(isRunning()){ | ||
221 | + usleep(200000); | ||
222 | + } | ||
223 | + finish = true; | ||
224 | +} | ||
0 | \ No newline at end of file | 225 | \ No newline at end of file |
servico/src/serviceWindowGenerationFromSRT.cpp
1 | #include "serviceWindowGenerationFromSRT.h" | 1 | #include "serviceWindowGenerationFromSRT.h" |
2 | 2 | ||
3 | +ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathVideo, char* pathSRT, int sublanguage, | ||
4 | + int pos, int size, int transp, char* id, char* client, int serviceType) { | ||
5 | + | ||
6 | + this->path_input = pathVideo; | ||
7 | + this->path_srt = pathSRT; | ||
8 | + this-> sub_language = sublanguage; | ||
9 | + this->position = pos; | ||
10 | + this->size = size; | ||
11 | + this->transparency = transp; | ||
12 | + this->user_id = id; | ||
13 | + this->client_type = client; | ||
14 | + this->service_type = serviceType; | ||
15 | + numero_legendas = INT_MAX; | ||
16 | + legendas_enviadas = 0; | ||
17 | + vetor_pts = new vector<int64_t >(); | ||
18 | + tradutor = new TradutorPortGlosa(); | ||
19 | + extrator_factory = new ExtratorFactory(); | ||
20 | + setPathContents(); | ||
21 | + running = true; | ||
22 | + finish = false; | ||
23 | + DPRINTF("Done!\n"); | ||
24 | +} | ||
3 | 25 | ||
4 | -//Construtor Service 1 | ||
5 | -ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* path_video, char* path_srt, int sublanguage, | ||
6 | - int position, int size, int transparency, char* id, char* client_type, int serviceType) { | ||
7 | - | 26 | +ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, int transp, char* id, char* client, int serviceType) { |
27 | + | ||
28 | + this->path_srt = pathSRT; | ||
29 | + this->transparency = transp; | ||
30 | + this->user_id = id; | ||
31 | + this->client_type = client; | ||
32 | + this->service_type = serviceType; | ||
33 | + numero_legendas = INT_MAX; | ||
34 | + legendas_enviadas = 0; | ||
35 | + vetor_pts = new vector<int64_t >(); | ||
36 | + tradutor = new TradutorPortGlosa(); | ||
8 | extrator_factory = new ExtratorFactory(); | 37 | extrator_factory = new ExtratorFactory(); |
9 | - setPathInput(path_video); | ||
10 | - setPathSRT(path_srt); | ||
11 | - setClientType(client_type); | ||
12 | - setPosition(position); | ||
13 | - setSize(size); | ||
14 | - setTransparency(transparency); | ||
15 | - setSubLanguage(sublanguage); | ||
16 | - setServiceType(serviceType); | ||
17 | - setUserId(id); | ||
18 | - finish = false; | ||
19 | - DPRINTF("Done!\n"); | ||
20 | -} | ||
21 | - | ||
22 | -//Construtor Service 4 | ||
23 | -ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* path_srt, int transparency, char* id, char* client_type, int serviceType) { | ||
24 | - | ||
25 | - extrator_factory = new ExtratorFactory(); | ||
26 | - setPathInput(path_srt); | ||
27 | - setClientType(client_type); | ||
28 | - setTransparency(transparency); | ||
29 | - setServiceType(serviceType); | ||
30 | - setUserId(id); | ||
31 | - finish = false; | ||
32 | - DPRINTF("Done!\n"); | 38 | + setPathContents(); |
39 | + running = true; | ||
40 | + finish = false; | ||
41 | + DPRINTF("Done!\n"); | ||
33 | } | 42 | } |
34 | 43 | ||
35 | ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { | 44 | ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { |
36 | - if (mutex_serviceSRT) delete mutex_serviceSRT; | ||
37 | - delete extratorSRT; | 45 | + free(vetor_pts); |
46 | + delete(ppty_h); | ||
47 | + if (mixer) delete mixer; | ||
48 | + if (tradutor) delete tradutor; | ||
49 | + if (sincronizador) delete sincronizador; | ||
50 | + if (extratorSRT)delete extratorSRT; | ||
51 | + if (extrator_factory) delete extrator_factory; | ||
38 | DDDPRINTF("Service SRT finalized!\n"); | 52 | DDDPRINTF("Service SRT finalized!\n"); |
39 | } | 53 | } |
40 | 54 | ||
41 | -void ServiceWindowGenerationFromSRT::notifyTranslator(unsigned char* subtitle) { | 55 | +void ServiceWindowGenerationFromSRT::setPathContents() { |
56 | + if(strcmp(client_type,DEVELOPER) == 0){ | ||
57 | + this->path_contents = PATH_DEVEL; | ||
58 | + this->path_uploads = PATH_DEVEL_UPLOADS; | ||
59 | + }else if(strcmp(client_type, PRODUCTION) == 0){ | ||
60 | + try{ | ||
61 | + ppty_h = new PropertyHandler(PATH_CONF_FILE, PropertyHandler::READ); | ||
62 | + this->path_contents = (char*) ppty_h->get_attibute_value("STORAGE"); | ||
63 | + }catch(RuntimeException &ex){ | ||
64 | + printf("%s\n", ex.getMessage().c_str()); | ||
65 | + } | ||
66 | + this->path_uploads = PATH_VBOX_UPLOADS; | ||
67 | + }else{ | ||
68 | + throw new ServiceException("Invalid client!"); | ||
69 | + } | ||
70 | +} | ||
71 | + | ||
72 | +void ServiceWindowGenerationFromSRT::setPathLibras() { | ||
73 | + char* final_path = new char[MAX_SIZE_PATH]; | ||
74 | + strcpy(final_path, this->path_uploads); | ||
75 | + strcat(final_path, this->user_id); | ||
76 | + strcat(final_path, "/video_libras.ts"); | ||
77 | + | ||
78 | + this->path_libras = final_path; | ||
79 | +} | ||
80 | + | ||
81 | +void ServiceWindowGenerationFromSRT::setBackground() { | ||
82 | + if(this->transparency == 0) { //pega dicionario com BackGround opaco | ||
83 | + sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, | ||
84 | + this->path_libras, this->transparency); | ||
85 | + } else { | ||
86 | + if(this->transparency == 1) { //pega dicionario com BackGround transparente | ||
87 | + sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, | ||
88 | + this->path_libras, this->transparency); | ||
89 | + } | ||
90 | + } | ||
91 | +} | ||
42 | 92 | ||
93 | +void ServiceWindowGenerationFromSRT::setSizeOfSubtitles(int sub_size) { | ||
94 | + numero_legendas = sub_size; | ||
95 | + if (legendas_enviadas >= numero_legendas) | ||
96 | + sincronizador->stop(); | ||
97 | +} | ||
98 | + | ||
99 | +void ServiceWindowGenerationFromSRT::addPTS(int64_t pts){ | ||
100 | + vetor_pts->push_back(pts); | ||
101 | +} | ||
102 | + | ||
103 | +void ServiceWindowGenerationFromSRT::notifyTranslator(unsigned char* subtitle) { | ||
43 | const char* constchar = (const char*) subtitle; | 104 | const char* constchar = (const char*) subtitle; |
44 | char* legenda_copy = new char[strlen(constchar)+1]; | 105 | char* legenda_copy = new char[strlen(constchar)+1]; |
45 | strcpy(legenda_copy, constchar); | 106 | strcpy(legenda_copy, constchar); |
@@ -48,67 +109,122 @@ void ServiceWindowGenerationFromSRT::notifyTranslator(unsigned char* subtitle) { | @@ -48,67 +109,122 @@ void ServiceWindowGenerationFromSRT::notifyTranslator(unsigned char* subtitle) { | ||
48 | } | 109 | } |
49 | 110 | ||
50 | void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int64_t pts){ | 111 | void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int64_t pts){ |
51 | - adicionaPTS(pts); | ||
52 | - notifyTranslator(subtitle); | 112 | + addPTS(pts); |
113 | + notifyTranslator(subtitle); | ||
53 | } | 114 | } |
54 | 115 | ||
55 | -bool ServiceWindowGenerationFromSRT::isFinished(){ | ||
56 | - return finish; | 116 | +void ServiceWindowGenerationFromSRT::notifyEndOfSynchronization() { |
117 | + if (this->service_type == SERVICE_TYPE_SRT) { | ||
118 | + mixer = new Mixer(); | ||
119 | + mixer->initialize(this->path_input, this->path_libras,this->position,this->size, | ||
120 | + this->transparency, this->user_id, this->path_uploads, this->path_contents); | ||
121 | + createThumbnail(); | ||
122 | + }else{ | ||
123 | + transcodeVideoToMp4(); | ||
124 | + } | ||
125 | + this->running = false; | ||
126 | +} | ||
127 | + | ||
128 | +void ServiceWindowGenerationFromSRT::notifyTranslation(vector<string> * glosas) { | ||
129 | + for (int i = 0; i < glosas->size(); i++) { | ||
130 | + locale loc; | ||
131 | + string glosa_lower = ""; | ||
132 | + for (int k = 0; k < glosas->at(i).length(); k++){ | ||
133 | + glosa_lower += std::tolower(glosas->at(i).at(k), loc); | ||
134 | + } | ||
135 | + int64_t pts_notificado = vetor_pts->front(); | ||
136 | + sincronizador->recebeglosa(glosa_lower, pts_notificado); | ||
137 | + } | ||
138 | + vetor_pts->erase(vetor_pts->begin()); | ||
139 | + legendas_enviadas++; | ||
57 | } | 140 | } |
58 | 141 | ||
59 | void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { | 142 | void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { |
60 | - DDPRINTF("Service SRT recebeu: %d legendas.\n", sub_size); | 143 | + DPRINTF("Service SRT recebeu: %d legendas.\n", sub_size); |
61 | setSizeOfSubtitles(sub_size); | 144 | setSizeOfSubtitles(sub_size); |
62 | } | 145 | } |
63 | 146 | ||
64 | -void ServiceWindowGenerationFromSRT::setPathSRT(char* path_srt) { | ||
65 | - this->path_srt = path_srt; | 147 | +bool ServiceWindowGenerationFromSRT::isRunning() { |
148 | + return this->running; | ||
149 | +} | ||
150 | + | ||
151 | +bool ServiceWindowGenerationFromSRT::isFinished() { | ||
152 | + return this->finish; | ||
66 | } | 153 | } |
67 | 154 | ||
68 | void ServiceWindowGenerationFromSRT::initialize() { | 155 | void ServiceWindowGenerationFromSRT::initialize() { |
156 | + DPRINTF("Service SRT Initialize.\n"); | ||
157 | + extratorSRT = (ExtratorSRT*) extrator_factory->getExtrator(Extrator::SRT); | ||
158 | + extratorSRT->addListener(this); | ||
159 | + extratorSRT->setFilePath(path_srt); | ||
69 | 160 | ||
70 | - DDPRINTF("Service SRT Initialize.\n"); | 161 | + setPathLibras(); |
162 | + | ||
163 | + if (this->sub_language == 1) | ||
164 | + tradutor->addListener(this); | ||
71 | 165 | ||
72 | - //codigo abaixo sera arrumado apos a aplicação do factory pattern | ||
73 | - | ||
74 | - if(serviceType == 1){ | ||
75 | - | ||
76 | - extratorSRT = (ExtratorSRT*)extrator_factory->getExtrator(SRT); | ||
77 | - extratorSRT->addListener(this); | ||
78 | - extratorSRT->setFilePath(path_srt); | ||
79 | - | ||
80 | - ServiceWindowGeneration::initialize(); | ||
81 | - | ||
82 | - try{ | ||
83 | - extratorSRT->initialize(); | ||
84 | - }catch(ExtratorException ex){ | ||
85 | - throw ServiceException(ex.getMessage()); | ||
86 | - } | ||
87 | - this->Start(); | ||
88 | - | ||
89 | - } else{ | ||
90 | - /*Este serviço utiliza apenas o arquivo de legendas (SRT) como entrada, | ||
91 | - portanto, não é preciso monitorar as informações do PCR a partir do | ||
92 | - objeto InputFile().*/ | ||
93 | - extratorSRT = (ExtratorSRT*)extrator_factory->getExtrator(SRT); | ||
94 | - extratorSRT->addListener(this); | ||
95 | - extratorSRT->setFilePath(path_input); | ||
96 | - | ||
97 | - ServiceWindowGeneration::initialize(); | ||
98 | - | ||
99 | - try{ | ||
100 | - extratorSRT->initialize(); | ||
101 | - }catch(ExtratorException ex){ | ||
102 | - throw ServiceException(ex.getMessage()); | ||
103 | - } | ||
104 | - this->Start(); | 166 | + if(this->service_type != SERVICE_TYPE_SRT_ONLY){ |
167 | + vector<string> tokens; | ||
168 | + char* pathtmp = this->path_input; | ||
169 | + int size = strlen(pathtmp); | ||
170 | + char vtemp [size]; | ||
171 | + | ||
172 | + strcpy(vtemp, pathtmp); | ||
173 | + pathtmp = strtok(vtemp, "."); | ||
174 | + while (pathtmp != NULL) { | ||
175 | + tokens.push_back(string(pathtmp)); | ||
176 | + pathtmp = strtok(NULL, "."); | ||
177 | + } | ||
178 | + | ||
179 | + string buildstrpath = tokens[0] + "_libras" + EXTENSAO_DICIONARIO; | ||
180 | + this->path_libras = new char[buildstrpath.size()]; | ||
181 | + strcpy(this->path_libras, buildstrpath.c_str()); | ||
182 | + //printf("O Serviço montou o seguinte path para o vídeo de Libras: %s\n", path_libras); | ||
183 | + | ||
184 | + }else{ | ||
185 | + tradutor->addListener(this); | ||
186 | + } | ||
187 | + | ||
188 | + setBackground(); | ||
189 | + | ||
190 | + if (service_type != SERVICE_TYPE_SRT) { | ||
191 | + uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro | ||
192 | + sincronizador->setPCRBase(pcr_base); | ||
193 | + } | ||
194 | + | ||
195 | + sincronizador->addListener(this); | ||
196 | + sincronizador->Start(); | ||
197 | + | ||
198 | + try{ | ||
199 | + extratorSRT->initialize(); | ||
200 | + }catch(ExtratorException ex){ | ||
201 | + throw ServiceException(ex.getMessage()); | ||
105 | } | 202 | } |
203 | + this->Start(); | ||
204 | +} | ||
106 | 205 | ||
206 | +void ServiceWindowGenerationFromSRT::transcodeVideoToMp4(){ | ||
207 | + DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); | ||
208 | + string command = "ffmpeg -i "; | ||
209 | + command.append(path_libras) | ||
210 | + .append(" -qscale 0 -strict experimental -vcodec libx264 -preset fast -r 30 ").append(" -v quiet ") | ||
211 | + .append(path_contents).append(user_id).append(".mp4"); | ||
212 | + //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); | ||
213 | + system(command.c_str()); | ||
107 | } | 214 | } |
108 | 215 | ||
109 | -void ServiceWindowGenerationFromSRT::Run() { | ||
110 | - while (isRunning()) { | ||
111 | - usleep(200000); //200ms | ||
112 | - } | ||
113 | - finish = true; | 216 | +void ServiceWindowGenerationFromSRT::createThumbnail(){ |
217 | + string command = "ffmpeg -ss 10 -i "; | ||
218 | + command.append(path_contents).append(user_id).append(".mp4") | ||
219 | + .append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 ").append(" -v quiet ") | ||
220 | + .append(path_contents).append(user_id).append(".png"); | ||
221 | + //printf("[INFO]: Thumbnail command -> %s\n", command.c_str()); | ||
222 | + system(command.c_str()); | ||
114 | } | 223 | } |
224 | + | ||
225 | +void ServiceWindowGenerationFromSRT::Run() { | ||
226 | + while(isRunning()){ | ||
227 | + usleep(200000); | ||
228 | + } | ||
229 | + finish = true; | ||
230 | +} | ||
115 | \ No newline at end of file | 231 | \ No newline at end of file |
servico/src/serviceWindowGenerationFromText.cpp
1 | #include "serviceWindowGenerationFromText.h" | 1 | #include "serviceWindowGenerationFromText.h" |
2 | 2 | ||
3 | -ServiceWindowGenerationFromText::ServiceWindowGenerationFromText ( | ||
4 | - char* path_file, char* username, int transp, int serviceType, char* client_type) { | ||
5 | - | ||
6 | - extrator_factory = new ExtratorFactory(); | ||
7 | - setPathInput(path_file); | ||
8 | - setClientType(client_type); | ||
9 | - setUserId(username); | ||
10 | - setTransparency(transp); | ||
11 | - setServiceType(serviceType); | 3 | +ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, int transp, char* id, char* client) { |
4 | + this->path_input = pathFile; | ||
5 | + this->transparency = transp; | ||
6 | + this->user_id = id; | ||
7 | + client_type = client; | ||
8 | + running = true; | ||
12 | finish = false; | 9 | finish = false; |
10 | + numero_legendas = INT_MAX; | ||
11 | + legendas_enviadas = 0; | ||
12 | + vetor_pts = new vector<int64_t >(); | ||
13 | + tradutor = new TradutorPortGlosa(); | ||
14 | + extrator_factory = new ExtratorFactory(); | ||
15 | + setPathContents(); | ||
16 | + running = true; | ||
17 | + finish = false; | ||
18 | + DPRINTF("Done!\n"); | ||
13 | } | 19 | } |
14 | 20 | ||
15 | ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { | 21 | ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { |
16 | - delete extratorTXT; | ||
17 | - DDDPRINTF("Service Text finished!\n"); | 22 | + free(vetor_pts); |
23 | + delete(ppty_h); | ||
24 | + if (tradutor) delete tradutor; | ||
25 | + if (sincronizador) delete sincronizador; | ||
26 | + if (extratorTXT)delete extratorTXT; | ||
27 | + if (extrator_factory) delete extrator_factory; | ||
28 | + DDDPRINTF("Service Text finalized!\n"); | ||
29 | +} | ||
30 | + | ||
31 | +void ServiceWindowGenerationFromText::setPathContents() { | ||
32 | + if(strcmp(client_type,DEVELOPER) == 0){ | ||
33 | + this->path_contents = PATH_DEVEL; | ||
34 | + this->path_uploads = PATH_DEVEL_UPLOADS; | ||
35 | + }else if(strcmp(client_type, PRODUCTION) == 0){ | ||
36 | + try{ | ||
37 | + ppty_h = new PropertyHandler(PATH_CONF_FILE, PropertyHandler::READ); | ||
38 | + this->path_contents = (char*) ppty_h->get_attibute_value("STORAGE"); | ||
39 | + }catch(RuntimeException &ex){ | ||
40 | + printf("%s\n", ex.getMessage().c_str()); | ||
41 | + } | ||
42 | + this->path_uploads = PATH_VBOX_UPLOADS; | ||
43 | + }else{ | ||
44 | + throw new ServiceException("Invalid client!"); | ||
45 | + } | ||
46 | +} | ||
47 | + | ||
48 | +void ServiceWindowGenerationFromText::setPathLibras() { | ||
49 | + char* final_path = new char[MAX_SIZE_PATH]; | ||
50 | + strcpy(final_path, this->path_uploads); | ||
51 | + strcat(final_path, this->user_id); | ||
52 | + strcat(final_path, "/video_libras.ts"); | ||
53 | + | ||
54 | + this->path_libras = final_path; | ||
55 | +} | ||
56 | + | ||
57 | +void ServiceWindowGenerationFromText::setBackground() { | ||
58 | + if(this->transparency == 0) { //pega dicionario com BackGround opaco | ||
59 | + sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, | ||
60 | + this->path_libras, this->transparency); | ||
61 | + } else { | ||
62 | + if(this->transparency == 1) { //pega dicionario com BackGround transparente | ||
63 | + sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, | ||
64 | + this->path_libras, this->transparency); | ||
65 | + } | ||
66 | + } | ||
67 | +} | ||
68 | + | ||
69 | +void ServiceWindowGenerationFromText::setSizeOfSubtitles(int sub_size) { | ||
70 | + numero_legendas = sub_size; | ||
71 | + if (legendas_enviadas >= numero_legendas) | ||
72 | + sincronizador->stop(); | ||
73 | +} | ||
74 | + | ||
75 | +void ServiceWindowGenerationFromText::notifyTranslator(unsigned char* text) { | ||
76 | + tradutor->traduz(text); | ||
18 | } | 77 | } |
19 | 78 | ||
20 | void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { | 79 | void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { |
21 | - tradutor->traduz(line); | 80 | + notifyTranslator(line); |
81 | +} | ||
82 | + | ||
83 | +void ServiceWindowGenerationFromText::notifyEndOfSynchronization() { | ||
84 | + transcodeVideoToMp4(); | ||
85 | + this->running = false; | ||
22 | } | 86 | } |
23 | 87 | ||
88 | +void ServiceWindowGenerationFromText::notifyTranslation(vector<string> * glosas) { | ||
89 | + for (int i = 0; i < glosas->size(); i++) { | ||
90 | + locale loc; | ||
91 | + string glosa_lower = ""; | ||
92 | + for (int k = 0; k < glosas->at(i).length(); k++){ | ||
93 | + glosa_lower += std::tolower(glosas->at(i).at(k), loc); | ||
94 | + } | ||
95 | + sincronizador->recebeglosa(glosa_lower, 1000); | ||
96 | + } | ||
97 | + sincronizador->stop(); | ||
98 | + legendas_enviadas++; | ||
99 | +} | ||
100 | + | ||
101 | + | ||
24 | void ServiceWindowGenerationFromText::notifyEnd(int line_size) { | 102 | void ServiceWindowGenerationFromText::notifyEnd(int line_size) { |
25 | - DDPRINTF("Service TXT recebeu: %d linhas.\n", line_size); | 103 | + DPRINTF("Service Text recebeu: %d linhas.\n", line_size); |
26 | setSizeOfSubtitles(line_size); | 104 | setSizeOfSubtitles(line_size); |
27 | } | 105 | } |
28 | 106 | ||
107 | +bool ServiceWindowGenerationFromText::isRunning() { | ||
108 | + return this->running; | ||
109 | +} | ||
110 | + | ||
29 | bool ServiceWindowGenerationFromText::isFinished() { | 111 | bool ServiceWindowGenerationFromText::isFinished() { |
30 | - return finish; | 112 | + return this->finish; |
31 | } | 113 | } |
32 | 114 | ||
33 | void ServiceWindowGenerationFromText::initialize() { | 115 | void ServiceWindowGenerationFromText::initialize() { |
34 | - DDPRINTF("Service Text Initialize.\n"); | ||
35 | - | ||
36 | - extratorTXT = (ExtratorTXT*) extrator_factory->getExtrator(TXT); | 116 | + DPRINTF("Service Text Initialize.\n"); |
117 | + extratorTXT = (ExtratorTXT*) extrator_factory->getExtrator(Extrator::TXT); | ||
37 | extratorTXT->addListener(this); | 118 | extratorTXT->addListener(this); |
38 | - extratorTXT->setFilePath(getPathInput()); | ||
39 | - | ||
40 | - ServiceWindowGeneration::initialize(); | 119 | + extratorTXT->setFilePath(path_input); |
120 | + | ||
121 | + setPathLibras(); | ||
122 | + | ||
123 | + tradutor->addListener(this); | ||
124 | + | ||
125 | + setBackground(); | ||
126 | + | ||
127 | + uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro | ||
128 | + sincronizador->setPCRBase(pcr_base); | ||
129 | + sincronizador->addListener(this); | ||
130 | + sincronizador->Start(); | ||
41 | 131 | ||
42 | try{ | 132 | try{ |
43 | extratorTXT->initialize(); | 133 | extratorTXT->initialize(); |
@@ -47,9 +137,19 @@ void ServiceWindowGenerationFromText::initialize() { | @@ -47,9 +137,19 @@ void ServiceWindowGenerationFromText::initialize() { | ||
47 | this->Start(); | 137 | this->Start(); |
48 | } | 138 | } |
49 | 139 | ||
50 | -void ServiceWindowGenerationFromText::Run() { | ||
51 | - while (isRunning()) { | ||
52 | - usleep(200000); //200ms | ||
53 | - } | ||
54 | - finish = true; | 140 | +void ServiceWindowGenerationFromText::transcodeVideoToMp4(){ |
141 | + DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); | ||
142 | + string command = "ffmpeg -i "; | ||
143 | + command.append(path_libras) | ||
144 | + .append(" -qscale 0 -strict experimental -vcodec libx264 -preset fast -r 30 ").append(" -v quiet ") | ||
145 | + .append(path_contents).append(user_id).append(".mp4"); | ||
146 | + //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); | ||
147 | + system(command.c_str()); | ||
55 | } | 148 | } |
149 | + | ||
150 | +void ServiceWindowGenerationFromText::Run(){ | ||
151 | + while(isRunning()){ | ||
152 | + usleep(200000); | ||
153 | + } | ||
154 | + finish = true; | ||
155 | +} | ||
56 | \ No newline at end of file | 156 | \ No newline at end of file |
synchronizer/src/synchronizer.cpp
@@ -175,27 +175,28 @@ char * Synchronizer::getproximoarquivo() { | @@ -175,27 +175,28 @@ char * Synchronizer::getproximoarquivo() { | ||
175 | //proximo = NULL; | 175 | //proximo = NULL; |
176 | 176 | ||
177 | if (videos->size() == 0) { | 177 | if (videos->size() == 0) { |
178 | - if(this->transparency == 0) | ||
179 | - return VIDEO_PADRAO; | ||
180 | - else | ||
181 | - return VIDEOTRANSP_PADRAO; | 178 | + if(this->transparency == 0){ |
179 | + return VIDEO_PADRAO; | ||
180 | + }else{ | ||
181 | + return VIDEOTRANSP_PADRAO; | ||
182 | + } | ||
182 | } | 183 | } |
183 | 184 | ||
184 | mutexi->Lock(); | 185 | mutexi->Lock(); |
185 | video = videos->front(); | 186 | video = videos->front(); |
187 | + | ||
186 | videos->erase(videos->begin()); | 188 | videos->erase(videos->begin()); |
187 | mutexi->Unlock(); | 189 | mutexi->Unlock(); |
188 | 190 | ||
189 | if (video == NULL) { | 191 | if (video == NULL) { |
190 | - if(this->transparency == 0) | ||
191 | - return VIDEO_PADRAO; | ||
192 | - else | ||
193 | - return VIDEOTRANSP_PADRAO; | ||
194 | - | ||
195 | - } else { | 192 | + if(this->transparency == 0){ |
193 | + return VIDEO_PADRAO; | ||
194 | + }else{ | ||
195 | + return VIDEOTRANSP_PADRAO; | ||
196 | + } | ||
197 | + }else{ | ||
196 | return video; | 198 | return video; |
197 | } | 199 | } |
198 | - | ||
199 | } | 200 | } |
200 | 201 | ||
201 | void Synchronizer::analisaPCR(unsigned char *pacote) { | 202 | void Synchronizer::analisaPCR(unsigned char *pacote) { |
@@ -420,7 +421,6 @@ void Synchronizer::soletraGlosa(string glosa, int64_t pts) { | @@ -420,7 +421,6 @@ void Synchronizer::soletraGlosa(string glosa, int64_t pts) { | ||
420 | return; | 421 | return; |
421 | char c = glosa[i]; | 422 | char c = glosa[i]; |
422 | if (c >= 97 && c <= 122) { | 423 | if (c >= 97 && c <= 122) { |
423 | - //cout << "soletrando a letra: " << glosa[i] << endl; | ||
424 | string path2 = (string) baseDir + glosa[i] + (string) extensao; | 424 | string path2 = (string) baseDir + glosa[i] + (string) extensao; |
425 | char* path2_char = converteString(path2); | 425 | char* path2_char = converteString(path2); |
426 | recebeglosa(converteString(path2), strlen(path2_char), pts); | 426 | recebeglosa(converteString(path2), strlen(path2_char), pts); |
@@ -505,6 +505,7 @@ void Synchronizer::Run() { | @@ -505,6 +505,7 @@ void Synchronizer::Run() { | ||
505 | int desc_out = -1; | 505 | int desc_out = -1; |
506 | 506 | ||
507 | while (videos_processed <= count_tasks || service_running) { | 507 | while (videos_processed <= count_tasks || service_running) { |
508 | + | ||
508 | cnt = read(filefd, buff, bufferSize); | 509 | cnt = read(filefd, buff, bufferSize); |
509 | 510 | ||
510 | // atualiza os valores de PCR e PTS/DTS para cada video | 511 | // atualiza os valores de PCR e PTS/DTS para cada video |
@@ -551,8 +552,6 @@ void Synchronizer::Run() { | @@ -551,8 +552,6 @@ void Synchronizer::Run() { | ||
551 | contagemPCR = 0; | 552 | contagemPCR = 0; |
552 | ultimoPCRBaseMod = 0; | 553 | ultimoPCRBaseMod = 0; |
553 | } | 554 | } |
554 | - | ||
555 | - | ||
556 | } else if (finalcnt == -1) { | 555 | } else if (finalcnt == -1) { |
557 | printf("Erro: Finalizando Sincronizador!\n"); | 556 | printf("Erro: Finalizando Sincronizador!\n"); |
558 | this->stop(); | 557 | this->stop(); |
util/src/include/property.h
@@ -6,43 +6,60 @@ | @@ -6,43 +6,60 @@ | ||
6 | * João Pessoa - PB - Brasil * | 6 | * João Pessoa - PB - Brasil * |
7 | * * | 7 | * * |
8 | * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * | 8 | * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * |
9 | - * Date: Qui Nov 28 14:05:39 BRT 2013 * | 9 | + * Date: Mon Jun 1 19:29:50 BRT 2015 * |
10 | * * | 10 | * * |
11 | **************************************************************************/ | 11 | **************************************************************************/ |
12 | 12 | ||
13 | - #ifndef PROPERTY_H | ||
14 | - #define PROPERTY_H | 13 | + #ifndef PROPERTYHANDLER_H |
14 | + #define PROPERTYHANDLER_H | ||
15 | 15 | ||
16 | - #include "logger.h" | ||
17 | #include <stdio.h> | 16 | #include <stdio.h> |
18 | #include <stdlib.h> | 17 | #include <stdlib.h> |
18 | + #include <map> | ||
19 | #include <string> | 19 | #include <string> |
20 | #include <string.h> | 20 | #include <string.h> |
21 | - #include <lavidlib/io/BufferedReader.h> | 21 | + #include <lavidlib/io/File.h> |
22 | #include <lavidlib/io/FileIO.h> | 22 | #include <lavidlib/io/FileIO.h> |
23 | + #include <lavidlib/io/BufferedReader.h> | ||
23 | #include <lavidlib/io/IOException.h> | 24 | #include <lavidlib/io/IOException.h> |
24 | #include <lavidlib/io/EOFException.h> | 25 | #include <lavidlib/io/EOFException.h> |
25 | #include <lavidlib/base/RuntimeException.h> | 26 | #include <lavidlib/base/RuntimeException.h> |
26 | 27 | ||
27 | - #define EXTENSION ".conf" | ||
28 | - | ||
29 | - using namespace std; | ||
30 | using namespace lavidlib; | 28 | using namespace lavidlib; |
31 | 29 | ||
32 | - namespace sndesc { | ||
33 | - | ||
34 | - class PropertyHandler { | 30 | + class PropertyHandler { |
35 | public: | 31 | public: |
36 | - PropertyHandler(string filename); | 32 | + enum HandlerMode { |
33 | + READ, | ||
34 | + WRITE | ||
35 | + }; | ||
36 | + PropertyHandler(char* _filename, PropertyHandler::HandlerMode _handler_mode); | ||
37 | virtual ~PropertyHandler(); | 37 | virtual ~PropertyHandler(); |
38 | - char* getAttributeValue(string attr); | 38 | + |
39 | + int attr_exists(char* _attr); | ||
40 | + const char* get_attibute_value(char* _attr); | ||
41 | + void set_attribute_value(char* _attr_p, char* _value_p); | ||
42 | + void update_properties(); | ||
43 | + int remove_attribute(char* _attr_p); | ||
39 | 44 | ||
40 | private: | 45 | private: |
41 | - BufferedReader* rbuffer; | ||
42 | - FileIO* file_property; | ||
43 | - int checkFileExtension(string &filename); | ||
44 | 46 | ||
45 | - }; | ||
46 | - } | 47 | + std::string filename; |
48 | + File* file_p; | ||
49 | + FileIO* file_io_p; | ||
50 | + BufferedReader* buff_reader_p; | ||
51 | + HandlerMode handler_mode; | ||
52 | + | ||
53 | + std::map<std::string, std::string> * map_ppty_p; | ||
54 | + | ||
55 | + int check_file_extension(char* _filename); | ||
56 | + void format_line_str(std::string* _line_str); | ||
57 | + int load_properties(); | ||
58 | + void init_write_mode(); | ||
59 | + std::string get_key(std::string _ppty_line); | ||
60 | + std::string get_value(std::string _ppty_line); | ||
61 | + int write_properties_on_file(std::string _key, std::string _value, FILE* _file_output); | ||
62 | + }; | ||
63 | + | ||
47 | 64 | ||
48 | - #endif /* PROPERTY_H */ | ||
49 | \ No newline at end of file | 65 | \ No newline at end of file |
66 | + #endif /* PROPERTYHANDLER_H */ | ||
50 | \ No newline at end of file | 67 | \ No newline at end of file |
util/src/logger.cpp
@@ -53,7 +53,7 @@ namespace Util { | @@ -53,7 +53,7 @@ namespace Util { | ||
53 | 53 | ||
54 | void Logger::writeInfoLog(char* filepath ,char* infoLog){ | 54 | void Logger::writeInfoLog(char* filepath ,char* infoLog){ |
55 | this->openInfoLogFile(filepath); | 55 | this->openInfoLogFile(filepath); |
56 | - file << getTime(); | 56 | + file << "READY="; |
57 | file << infoLog << "\n\r"; | 57 | file << infoLog << "\n\r"; |
58 | this->closeLogFile(); | 58 | this->closeLogFile(); |
59 | } | 59 | } |
util/src/property.cpp
@@ -6,74 +6,231 @@ | @@ -6,74 +6,231 @@ | ||
6 | * João Pessoa - PB - Brasil * | 6 | * João Pessoa - PB - Brasil * |
7 | * * | 7 | * * |
8 | * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * | 8 | * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * |
9 | - * Date: Qui Nov 28 14:06:10 BRT 2013 * | 9 | + * Date: Mon Jun 1 19:29:50 BRT 2015 * |
10 | * * | 10 | * * |
11 | **************************************************************************/ | 11 | **************************************************************************/ |
12 | 12 | ||
13 | - #include "property.h" | 13 | +#include "property.h" |
14 | + | ||
15 | + | ||
16 | +PropertyHandler::PropertyHandler(char* _filename, PropertyHandler::HandlerMode _handler_mode) | ||
17 | +{ | ||
18 | + if ( check_file_extension(_filename) == -1 ) | ||
19 | + throw new RuntimeException("Format file not is supported"); | ||
20 | + | ||
21 | + filename = (std::string) _filename; | ||
22 | + handler_mode = _handler_mode; | ||
23 | + | ||
24 | + switch (handler_mode) | ||
25 | + { | ||
26 | + case READ: | ||
27 | + if ( load_properties() <= 0 ) | ||
28 | + throw new RuntimeException("Cannot to load properties of the file"); | ||
29 | + break; | ||
30 | + case WRITE: | ||
31 | + init_write_mode(); | ||
32 | + break; | ||
33 | + default: | ||
34 | + printf("Handler mode not supported"); | ||
35 | + exit(1); | ||
36 | + } | ||
37 | + | ||
38 | +} | ||
39 | + | ||
40 | + | ||
41 | +PropertyHandler::~PropertyHandler() | ||
42 | +{ | ||
43 | + if (handler_mode == WRITE) | ||
44 | + update_properties(); | ||
45 | + | ||
46 | + if (buff_reader_p) delete buff_reader_p; | ||
47 | + if (file_io_p) delete file_io_p; | ||
48 | + if (file_p) delete file_p; | ||
49 | + if (map_ppty_p) delete map_ppty_p; | ||
50 | + | ||
51 | +} | ||
52 | + | ||
53 | + | ||
54 | +int PropertyHandler::load_properties() | ||
55 | +{ | ||
56 | + std::string buff_str; | ||
57 | + int buff_index = 0; | ||
58 | + | ||
59 | + file_p = new File(filename); | ||
60 | + try { | ||
61 | + file_io_p = new FileIO(file_p->getPath(), FileIO::MODE_READ); | ||
62 | + } | ||
63 | + catch(IOException &ex) { | ||
64 | + printf("[ERROR] %s\n", ex.getMessage().c_str()); | ||
65 | + exit(1); | ||
66 | + } | ||
67 | + | ||
68 | + buff_reader_p = new BufferedReader(file_io_p); | ||
69 | + map_ppty_p = new std::map<std::string, std::string>(); | ||
70 | + | ||
71 | + try { | ||
72 | + buff_str = buff_reader_p->readLine(); | ||
73 | + | ||
74 | + while (buff_str.size() > 0) | ||
75 | + { | ||
76 | + buff_index++; | ||
77 | + format_line_str(&buff_str); | ||
78 | + | ||
79 | + map_ppty_p->insert(map_ppty_p->begin(), | ||
80 | + (std::pair<std::string, std::string>(get_key(buff_str), get_value(buff_str)))); | ||
81 | + | ||
82 | + /* get next line (key, value) */ | ||
83 | + buff_str = buff_reader_p->readLine(); | ||
84 | + } | ||
85 | + | ||
86 | + } catch (EOFException &ex) { | ||
87 | + printf("[ERROR] %s\n", ex.getMessage().c_str()); | ||
88 | + } | ||
89 | + | ||
90 | + return buff_index; | ||
91 | + | ||
92 | +} | ||
93 | + | ||
94 | + | ||
95 | +void PropertyHandler::init_write_mode() | ||
96 | +{ | ||
97 | + /* init map structure to manipulate the properties in WRITE mode */ | ||
98 | + map_ppty_p = new std::map<std::string, std::string>(); | ||
99 | +} | ||
100 | + | ||
101 | + | ||
102 | +int PropertyHandler::attr_exists(char* _attr) | ||
103 | +{ | ||
104 | + std::map<std::string, std::string>::iterator it; | ||
105 | + if ( (it = map_ppty_p->find((const char*) _attr)) != map_ppty_p->end() ) | ||
106 | + return 1; | ||
107 | + return 0; | ||
108 | +} | ||
109 | + | ||
110 | +const char* PropertyHandler::get_attibute_value(char* _attr) | ||
111 | +{ | ||
112 | + if (attr_exists(_attr)) | ||
113 | + { | ||
114 | + return (map_ppty_p->find((const char*) _attr)->second).c_str(); | ||
115 | + } | ||
116 | + return _attr; | ||
117 | +} | ||
14 | 118 | ||
15 | - using namespace std; | ||
16 | 119 | ||
17 | - namespace sndesc { | 120 | +void PropertyHandler::set_attribute_value(char* _attr_p, char* _value_p) |
121 | +{ | ||
122 | + if (handler_mode == PropertyHandler::READ) | ||
123 | + throw new RuntimeException("Cannot set properties in the READ mode"); | ||
124 | + | ||
125 | + if (attr_exists(_attr_p)) | ||
126 | + throw new RuntimeException("This attribute already exists"); | ||
127 | + | ||
128 | + map_ppty_p->insert(map_ppty_p->begin(), | ||
129 | + (std::pair<std::string, std::string>((std::string) _attr_p, (std::string) _value_p))); | ||
130 | +} | ||
131 | + | ||
132 | + | ||
133 | +void PropertyHandler::update_properties() | ||
134 | +{ | ||
135 | + FILE* file_output_p; | ||
136 | + file_output_p = fopen (filename.c_str(), "w"); | ||
137 | + if (file_output_p == NULL) | ||
138 | + throw new IOException("Cannot open file to write properties"); | ||
139 | + fseek(file_output_p, 0, SEEK_SET); | ||
140 | + | ||
141 | + std::string str_properties; | ||
142 | + | ||
143 | + std::map<std::string, std::string>::iterator it; | ||
144 | + for (it = map_ppty_p->begin(); it != map_ppty_p->end(); it++) | ||
145 | + if ( write_properties_on_file(it->first, it->second, file_output_p) == 0 ) | ||
146 | + throw new IOException("Error to write properties in the file"); | ||
147 | + | ||
148 | + fclose (file_output_p); | ||
149 | +} | ||
150 | + | ||
151 | + | ||
152 | +int PropertyHandler::write_properties_on_file(std::string _key, std::string _value, FILE* _file_output) | ||
153 | +{ | ||
154 | + std::string str_properties = _key; | ||
155 | + str_properties.append("="); | ||
156 | + str_properties.append(_value); | ||
157 | + | ||
158 | + int count_bytes = 0; | ||
159 | + | ||
160 | + count_bytes += fputs((char*) str_properties.c_str(), _file_output); | ||
161 | + count_bytes += fputs("\n", _file_output); | ||
162 | + | ||
163 | + return count_bytes; | ||
164 | +} | ||
165 | + | ||
166 | +//TODO | ||
167 | +int PropertyHandler::remove_attribute(char* _attr_p) | ||
168 | +{ | ||
169 | + | ||
170 | + if (attr_exists(_attr_p)) { | ||
171 | + | ||
172 | + if ( map_ppty_p->erase((const char*) _attr_p) != 1 ) | ||
173 | + throw new RuntimeException("Cannot remove attribute of the map structure"); | ||
174 | + | ||
175 | + /* if delete the attribute corretly, update the map of the properties */ | ||
176 | + update_properties(); | ||
177 | + return 1; | ||
178 | + } | ||
179 | + return 0; | ||
180 | +} | ||
181 | + | ||
182 | + | ||
183 | +#define CONF_FILE_EXTENSION ".conf" | ||
184 | +/** | ||
185 | + Verify if the file extension is valid. | ||
186 | +*/ | ||
187 | +int PropertyHandler::check_file_extension(char* _filename) | ||
188 | +{ | ||
189 | + return ((std::string) _filename).find(CONF_FILE_EXTENSION); | ||
190 | +} | ||
191 | + | ||
192 | +#undef CONF_FILE_EXTENSION /* .conf */ | ||
193 | + | ||
194 | + | ||
195 | +#define CHAR_TO_REMOVE " \t" | ||
196 | +/** | ||
197 | + Remove all whitespaces in the text line. | ||
198 | +*/ | ||
199 | +void PropertyHandler::format_line_str(std::string* _line_str) | ||
200 | +{ | ||
201 | + int index = -1; | ||
202 | + std::string chars_rm_str = (std::string) CHAR_TO_REMOVE; | ||
203 | + for (int i = 0; i < chars_rm_str.size(); i++) | ||
204 | + { | ||
205 | + while ( (index = (int) _line_str->find(chars_rm_str[i]) ) != std::string::npos) | ||
206 | + { | ||
207 | + _line_str->replace(index, 1, ""); // remove whitespaces (" ") replacing your position by "" | ||
208 | + } | ||
209 | + } | ||
210 | +} | ||
211 | +#undef CHAR_TO_REMOVE | ||
212 | + | ||
213 | +#define TOKEN_ATTR "=" | ||
214 | +std::string PropertyHandler::get_key(std::string _ppty_line) | ||
215 | +{ | ||
216 | + int target_pos = -1; | ||
217 | + target_pos = _ppty_line.find(TOKEN_ATTR); | ||
218 | + | ||
219 | + if (target_pos < 1) /* minimum lenght of a key (k=value) */ | ||
220 | + throw new RuntimeException("Bad format sentence"); | ||
221 | + | ||
222 | + return (std::string) _ppty_line.substr(0, target_pos); | ||
223 | +} | ||
18 | 224 | ||
19 | - PropertyHandler::PropertyHandler(string filename) { | ||
20 | - | ||
21 | - try { | ||
22 | - if (checkFileExtension(filename) != 1) | ||
23 | - throw new RuntimeException("Format file not is recognized!"); | ||
24 | - file_property = new FileIO(filename, FileIO::MODE_READ); | ||
25 | - } catch (IOException &ex) { | ||
26 | - printf("[FAILED] Can't open file %s\n%s\n", filename.c_str(), | ||
27 | - ex.getMessage().c_str()); | ||
28 | - } | ||
29 | - } | ||
30 | - | ||
31 | - PropertyHandler::~PropertyHandler() { | ||
32 | - if (rbuffer) | ||
33 | - delete rbuffer; | ||
34 | - if (file_property) | ||
35 | - delete file_property; | ||
36 | - } | ||
37 | - | ||
38 | - char* PropertyHandler::getAttributeValue(string attr) { | ||
39 | - | ||
40 | - char* value1; | ||
41 | - char* value2; | ||
42 | - | ||
43 | - rbuffer = new BufferedReader(file_property); | ||
44 | - string fline; | ||
45 | - try { | ||
46 | - int target_pos = -1, begin = 0; | ||
47 | - string attr_t, value_t; | ||
48 | - while((fline = rbuffer->readLine()).size() > 0) { | ||
49 | - target_pos = fline.find("="); | ||
50 | - if (target_pos < 2) | ||
51 | - throw new RuntimeException("The assignment symbol was not found."); | ||
52 | - | ||
53 | - attr_t = fline.substr(begin, target_pos); | ||
54 | - begin = target_pos+1; | ||
55 | - value_t = fline.substr(begin, fline.size()); | ||
56 | - | ||
57 | - if (attr.compare(attr_t) == 0) { | ||
58 | - file_property->seek(0); | ||
59 | - value1 = new char[value_t.length() + 1]; | ||
60 | - strcpy(value1, value_t.c_str()); | ||
61 | - return value1; | ||
62 | - } | ||
63 | - target_pos = -1; | ||
64 | - begin = 0; | ||
65 | - } | ||
66 | - } catch (lavidlib::EOFException &ex) { | ||
67 | - printf("[INFO] File is completed.\n%s\n", ex.getMessage().c_str()); | ||
68 | - } | ||
69 | - file_property->seek(0); | ||
70 | - strcpy(value2, fline.c_str()); | ||
71 | - return value2; | ||
72 | - } | ||
73 | - | ||
74 | - int PropertyHandler::checkFileExtension(string &filename) { | ||
75 | - | ||
76 | - return (filename.find(EXTENSION) > 0 && | ||
77 | - (filename.size() == (filename.find(EXTENSION) + strlen(EXTENSION)))) ? 1 : -1; | ||
78 | - } | ||
79 | - } | ||
80 | \ No newline at end of file | 225 | \ No newline at end of file |
226 | + | ||
227 | +std::string PropertyHandler::get_value(std::string _ppty_line) | ||
228 | +{ | ||
229 | + int target_pos = -1; | ||
230 | + target_pos = _ppty_line.find(TOKEN_ATTR); | ||
231 | + | ||
232 | + if (target_pos < 1) /* minimum lenght of a key (k=value) */ | ||
233 | + throw new RuntimeException("Bad format sentence"); | ||
234 | + | ||
235 | + return (std::string) _ppty_line.substr(target_pos+1, _ppty_line.size()); | ||
236 | +} | ||
237 | +#undef TOKEN_ATTR | ||
81 | \ No newline at end of file | 238 | \ No newline at end of file |