Commit 18e68e96c055173db8df2e6ffdd7ba281717e9b0

Authored by Wesnydy Ribeiro
1 parent aaee27f6
Exists in master and in 1 other branch devel

(VLibras-Box) Serviço de Reconhecimento(video) OK

@@ -11,7 +11,6 @@ @@ -11,7 +11,6 @@
11 * 11 *
12 * Edit on 03 de Fevereiro de 2014 12 * Edit on 03 de Fevereiro de 2014
13 */ 13 */
14 -  
15 #include "serviceWindowGenerationFromSRT.h" 14 #include "serviceWindowGenerationFromSRT.h"
16 #include "serviceWindowGenerationFromREC.h" 15 #include "serviceWindowGenerationFromREC.h"
17 #include "serviceWindowGenerationFromText.h" 16 #include "serviceWindowGenerationFromText.h"
@@ -21,10 +20,6 @@ @@ -21,10 +20,6 @@
21 #include <sys/time.h> 20 #include <sys/time.h>
22 #include <stdlib.h> 21 #include <stdlib.h>
23 22
24 -#define BLOQUEANTE 1  
25 -#define NAO_BLOQUEANTE 2  
26 -#define BOTH 3  
27 -  
28 using namespace std; 23 using namespace std;
29 24
30 void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position, char* size, char* transparency, char* id, char* client_type); 25 void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position, char* size, char* transparency, char* id, char* client_type);
@@ -37,6 +32,7 @@ void serviceText(char* service, char* path_text, char* transparency, char* id, c @@ -37,6 +32,7 @@ void serviceText(char* service, char* path_text, char* transparency, char* id, c
37 32
38 void help(); 33 void help();
39 void serviceHelp(int service); 34 void serviceHelp(int service);
  35 +void setStatusOfReady(char* ready);
40 void fail(string msg); 36 void fail(string msg);
41 void hasFailed(); 37 void hasFailed();
42 void hasInvalid(); 38 void hasInvalid();
@@ -52,15 +48,6 @@ int main(int argc, char* argv[]) { @@ -52,15 +48,6 @@ int main(int argc, char* argv[]) {
52 gettimeofday(&tv1, NULL); 48 gettimeofday(&tv1, NULL);
53 t1 = (double)(tv1.tv_sec) + (double)(tv1.tv_usec)/ 1000000.00; 49 t1 = (double)(tv1.tv_sec) + (double)(tv1.tv_usec)/ 1000000.00;
54 50
55 - /*try{  
56 - PropertyHandler* reader = new PropertyHandler();  
57 - service-type = reader->getAttributeValue("SERVICE-TYPE");  
58 - }catch(RuntimeException &ex){  
59 - return; // escrever log aki  
60 - }*/  
61 -  
62 - //Util::Logger::Instance()->writeInfoLog("/home/wesnydy/.vlibras-conf/service/log-vbox", "VBox OK!");  
63 -  
64 printf("\n################## VLIBRAS : LAVID ##################\n\n"); 51 printf("\n################## VLIBRAS : LAVID ##################\n\n");
65 52
66 if(argc >= 2) { 53 if(argc >= 2) {
@@ -75,23 +62,25 @@ int main(int argc, char* argv[]) { @@ -75,23 +62,25 @@ int main(int argc, char* argv[]) {
75 hasInvalid(); 62 hasInvalid();
76 break; 63 break;
77 } 64 }
78 - if(argc == 9) 65 + if(argc == 9){
  66 + setStatusOfReady("0");
79 serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], "user"); 67 serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], "user");
80 - else 68 + setStatusOfReady("1");
  69 + }else
81 serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); 70 serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]);
82 71
83 break; 72 break;
84 case 2: 73 case 2:
85 - printf("[INFO] Serviço em manutenção!!!\n");  
86 - exit(0);  
87 if(argc < 8){ 74 if(argc < 8){
88 serviceHelp(2); 75 serviceHelp(2);
89 hasInvalid(); 76 hasInvalid();
90 break; 77 break;
91 } 78 }
92 - if(argc == 8) 79 + if(argc == 8){
  80 + setStatusOfReady("0");
93 serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], "user"); 81 serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], "user");
94 - else 82 + setStatusOfReady("1");
  83 + }else
95 serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); 84 serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
96 break; 85 break;
97 case 3: 86 case 3:
@@ -100,9 +89,11 @@ int main(int argc, char* argv[]) { @@ -100,9 +89,11 @@ int main(int argc, char* argv[]) {
100 hasInvalid(); 89 hasInvalid();
101 break; 90 break;
102 } 91 }
103 - if(argc == 5) 92 + if(argc == 5){
  93 + setStatusOfReady("0");
104 serviceText(argv[1], argv[2], argv[3], argv[4], "user"); 94 serviceText(argv[1], argv[2], argv[3], argv[4], "user");
105 - else 95 + setStatusOfReady("1");
  96 + }else
106 serviceText(argv[1], argv[2], argv[3], argv[4], argv[5]); 97 serviceText(argv[1], argv[2], argv[3], argv[4], argv[5]);
107 break; 98 break;
108 case 4: 99 case 4:
@@ -111,9 +102,11 @@ int main(int argc, char* argv[]) { @@ -111,9 +102,11 @@ int main(int argc, char* argv[]) {
111 hasInvalid(); 102 hasInvalid();
112 break; 103 break;
113 } 104 }
114 - if(argc == 5 ) 105 + if(argc == 5 ){
  106 + setStatusOfReady("0");
115 serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], "user"); 107 serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], "user");
116 - else 108 + setStatusOfReady("1");
  109 + }else
117 serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], argv[5]); 110 serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], argv[5]);
118 break; 111 break;
119 case 5: 112 case 5:
@@ -124,9 +117,11 @@ int main(int argc, char* argv[]) { @@ -124,9 +117,11 @@ int main(int argc, char* argv[]) {
124 hasInvalid(); 117 hasInvalid();
125 break; 118 break;
126 } 119 }
127 - if (argc == 5) 120 + if (argc == 5){
  121 + setStatusOfReady("0");
128 serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], "user"); 122 serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], "user");
129 - else 123 + setStatusOfReady("1");
  124 + }else
130 serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], argv[5]); 125 serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], argv[5]);
131 break; 126 break;
132 default: 127 default:
@@ -154,6 +149,13 @@ int main(int argc, char* argv[]) { @@ -154,6 +149,13 @@ int main(int argc, char* argv[]) {
154 149
155 } 150 }
156 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 +}
  158 +
157 void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position, 159 void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position,
158 char* size, char* transparency, char* id, char* client_type){ 160 char* size, char* transparency, char* id, char* client_type){
159 161
recognize/src/include/recognize.h
@@ -23,7 +23,9 @@ @@ -23,7 +23,9 @@
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
26 #define PATH_API_UPLOADS "vlibras_user/vlibras-api/uploads/" 27 #define PATH_API_UPLOADS "vlibras_user/vlibras-api/uploads/"
  28 +#define PATH_VBOX_CONTENTS "vlibras_user/.vlibras-conf/contents/"
27 #define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav" 29 #define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav"
28 #define PATH_AUDIO_PARTS "/audio/parts/" 30 #define PATH_AUDIO_PARTS "/audio/parts/"
29 #define FILENAME_RECOGNIZED_OUT "/audio/recognized.out" 31 #define FILENAME_RECOGNIZED_OUT "/audio/recognized.out"
@@ -47,7 +49,7 @@ class Recognize: public Thread { @@ -47,7 +49,7 @@ class Recognize: public Thread {
47 49
48 public: 50 public:
49 51
50 - Recognize(char* _pathVideo, char* id); 52 + Recognize(char* _pathVideo, char* id, int client_type);
51 Recognize(char* _pathVideo, char* id, char* rate); 53 Recognize(char* _pathVideo, char* id, char* rate);
52 Recognize(char* _pathVideo, int _inputType, char* id); 54 Recognize(char* _pathVideo, int _inputType, char* id);
53 ~Recognize(); 55 ~Recognize();
@@ -76,6 +78,7 @@ public: @@ -76,6 +78,7 @@ public:
76 78
77 private: 79 private:
78 80
  81 + char* path_contents;
79 char* pathVideo; 82 char* pathVideo;
80 string id; 83 string id;
81 float confidenceRate; 84 float confidenceRate;
recognize/src/recognize.cpp
1 #include <recognize.h> 1 #include <recognize.h>
2 2
3 -Recognize::Recognize(char* _pathVideo, char* _id) { 3 +Recognize::Recognize(char* _pathVideo, char* _id, int client_type) {
4 4
5 listeners = new list<RecognizeListener*>(); 5 listeners = new list<RecognizeListener*>();
6 pathVideo = _pathVideo; 6 pathVideo = _pathVideo;
@@ -11,6 +11,12 @@ Recognize::Recognize(char* _pathVideo, char* _id) { @@ -11,6 +11,12 @@ Recognize::Recognize(char* _pathVideo, char* _id) {
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 +
14 DPRINTF("Done!\n"); 20 DPRINTF("Done!\n");
15 } 21 }
16 22
@@ -103,26 +109,22 @@ char* Recognize::extractAudioFromVideo() { @@ -103,26 +109,22 @@ char* Recognize::extractAudioFromVideo() {
103 //command.append(strFreq).append(" -ac 1 -f wav ").append(PATH_AUDIO_ORIGIN).append(" &"); 109 //command.append(strFreq).append(" -ac 1 -f wav ").append(PATH_AUDIO_ORIGIN).append(" &");
104 command.append(strFreq). 110 command.append(strFreq).
105 append(" -ac 1 -f wav "). 111 append(" -ac 1 -f wav ").
106 - append(PATH_API_UPLOADS).  
107 - append(id).  
108 - append(PATH_AUDIO_ORIGIN).  
109 -  
110 - append(" -v quiet"); 112 + append(path_contents).append(id).
  113 + append(PATH_AUDIO_ORIGIN).append(" -v quiet");
111 114
112 /*string tmp = "echo "; 115 /*string tmp = "echo ";
113 tmp.append(PATH_AUDIO_ORIGIN).append(" >> ").append(FILENAME_AUDIOLIST); 116 tmp.append(PATH_AUDIO_ORIGIN).append(" >> ").append(FILENAME_AUDIOLIST);
114 system(tmp.c_str());*/ 117 system(tmp.c_str());*/
115 -  
116 system(command.c_str()); 118 system(command.c_str());
117 -  
118 } 119 }
119 120
120 121
121 int Recognize::getTimeMediaSec() { 122 int Recognize::getTimeMediaSec() {
122 123
123 string command = PROGRAM; 124 string command = PROGRAM;
124 - command.append(" -i ").append(PATH_API_UPLOADS).append(id).append(PATH_AUDIO_ORIGIN);  
125 - command.append(" 2>&1 | grep Duration >> outfile"); 125 +
  126 + command.append(" -i ").append(path_contents).append(id).append(PATH_AUDIO_ORIGIN)
  127 + .append(" 2>&1 | grep Duration >> outfile");
126 system(command.c_str()); 128 system(command.c_str());
127 129
128 ifstream in("outfile"); 130 ifstream in("outfile");
@@ -183,7 +185,9 @@ void Recognize::breakVideoParts(int timeTotal) { @@ -183,7 +185,9 @@ void Recognize::breakVideoParts(int timeTotal) {
183 pts.push_back(convert_pts(ss_str)); 185 pts.push_back(convert_pts(ss_str));
184 186
185 command = "sox "; 187 command = "sox ";
186 - command.append(PATH_API_UPLOADS).append(id).append(PATH_AUDIO_ORIGIN).append(" ").append(PATH_API_UPLOADS).append(id).append(PATH_AUDIO_PARTS); 188 + command.append(path_contents).append(id).append(PATH_AUDIO_ORIGIN).append(" ")
  189 + .append(path_contents).append(id).append(PATH_AUDIO_PARTS);
  190 +
187 sprintf(tmp, "%i", count++); 191 sprintf(tmp, "%i", count++);
188 filename.append(tmp).append(".wav"); 192 filename.append(tmp).append(".wav");
189 command.append(filename).append(" trim ").append(ss_str).append(" ").append(t_str); 193 command.append(filename).append(" trim ").append(ss_str).append(" ").append(t_str);
@@ -191,7 +195,10 @@ void Recognize::breakVideoParts(int timeTotal) { @@ -191,7 +195,10 @@ void Recognize::breakVideoParts(int timeTotal) {
191 system(command.c_str()); 195 system(command.c_str());
192 196
193 string apcomm = "echo "; 197 string apcomm = "echo ";
194 - apcomm.append(PATH_API_UPLOADS).append(id).append(PATH_AUDIO_PARTS).append(filename).append(" >> ").append(PATH_API_UPLOADS).append(id).append(FILENAME_AUDIOLIST); 198 +
  199 + apcomm.append(path_contents).append(id).append(PATH_AUDIO_PARTS).append(filename).append(" >> ")
  200 + .append(path_contents).append(id).append(FILENAME_AUDIOLIST);
  201 +
195 system(apcomm.c_str()); 202 system(apcomm.c_str());
196 203
197 filename = FILENAME_AUDIOPART; 204 filename = FILENAME_AUDIOPART;
@@ -208,19 +215,18 @@ void Recognize::executeJuliusEngine() { @@ -208,19 +215,18 @@ void Recognize::executeJuliusEngine() {
208 char cfreq[10]; 215 char cfreq[10];
209 216
210 command = "julius -C vlibras_user/vlibras-core/recognize/src/julius.jconf -input "; 217 command = "julius -C vlibras_user/vlibras-core/recognize/src/julius.jconf -input ";
211 - if (inputType == 1) { 218 +
  219 + if (inputType == 1)
212 type = "rawfile"; 220 type = "rawfile";
213 - command.append(type).append(" -filelist ").append(PATH_API_UPLOADS).append(id).append(FILENAME_AUDIOLIST);  
214 - } else {  
215 - type = "mic";  
216 - } 221 + else
  222 + type = "mic";
  223 +
  224 + command.append(type).append(" -filelist ").append(path_contents).append(id).append(FILENAME_AUDIOLIST);
217 sprintf(cfreq, "%i", frequency); 225 sprintf(cfreq, "%i", frequency);
218 command.append(" -smpFreq "). 226 command.append(" -smpFreq ").
219 append(cfreq). 227 append(cfreq).
220 - append(" -nolog >> ").  
221 - append(PATH_API_UPLOADS).append(id).  
222 - append(FILENAME_RECOGNIZED_OUT);  
223 - 228 + append(" -nolog >> ");
  229 + command.append(path_contents).append(id).append(FILENAME_RECOGNIZED_OUT);
224 //Command of execute Julius 230 //Command of execute Julius
225 //printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str()); 231 //printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str());
226 system(command.c_str()); 232 system(command.c_str());
@@ -230,14 +236,13 @@ void Recognize::executeJuliusEngine() { @@ -230,14 +236,13 @@ void Recognize::executeJuliusEngine() {
230 void Recognize::generateConfidence() { 236 void Recognize::generateConfidence() {
231 237
232 string command = "cat "; 238 string command = "cat ";
233 - command.append(PATH_API_UPLOADS).append(id).append(FILENAME_RECOGNIZED_OUT).append(" | grep ").  
234 - append(FIND_CONFIDENCE).append(" >> ").append(PATH_API_UPLOADS).append(id).append(FILENAME_CONFIDENCEOUT);  
235 - 239 + command.append(path_contents).append(id).append(FILENAME_RECOGNIZED_OUT).append(" | grep ").
  240 + append(FIND_CONFIDENCE).append(" >> ").append(path_contents).append(id).append(FILENAME_CONFIDENCEOUT);
236 system(command.c_str()); 241 system(command.c_str());
237 //printf("\n\n---> command: %s\n\n", command.c_str()); 242 //printf("\n\n---> command: %s\n\n", command.c_str());
238 243
239 string path; 244 string path;
240 - path.append(PATH_API_UPLOADS).append(id).append(FILENAME_CONFIDENCEOUT); 245 + path.append(path_contents).append(id).append(FILENAME_CONFIDENCEOUT);
241 ifstream in(path.c_str()); 246 ifstream in(path.c_str());
242 247
243 if (!in) { 248 if (!in) {
@@ -307,16 +312,15 @@ void Recognize::filterOutputJulius() { @@ -307,16 +312,15 @@ void Recognize::filterOutputJulius() {
307 sentences = new std::list<char*>(); 312 sentences = new std::list<char*>();
308 313
309 string command = "cat "; 314 string command = "cat ";
310 - command.append(PATH_API_UPLOADS).append(id).append(FILENAME_RECOGNIZED_OUT).append(" | grep -e ").  
311 - append(FIND_SENTENCE).append(" -e \"").append(AUDIO_SILENT).append("\"").append(" >> ").append(PATH_API_UPLOADS).append(id).append(FILENAME_FILTEROUT);  
312 - 315 + command.append(path_contents).append(id).append(FILENAME_RECOGNIZED_OUT).append(" | grep -e ").
  316 + append(FIND_SENTENCE).append(" -e \"").append(AUDIO_SILENT).append("\"").append(" >> ").append(path_contents).append(id).append(FILENAME_FILTEROUT);
313 system(command.c_str()); 317 system(command.c_str());
314 //printf("\n\n---> command: %s\n\n", command.c_str()); 318 //printf("\n\n---> command: %s\n\n", command.c_str());
315 319
316 count_lines = 0; 320 count_lines = 0;
317 321
318 string path; 322 string path;
319 - path.append(PATH_API_UPLOADS).append(id).append(FILENAME_FILTEROUT); 323 + path.append(path_contents).append(id).append(FILENAME_FILTEROUT);
320 ifstream in(path.c_str()); 324 ifstream in(path.c_str());
321 string strFilter; 325 string strFilter;
322 326
@@ -398,15 +402,16 @@ bool Recognize::isFinished() { @@ -398,15 +402,16 @@ bool Recognize::isFinished() {
398 void Recognize::cleanFiles() { 402 void Recognize::cleanFiles() {
399 403
400 string command = "rm -r "; 404 string command = "rm -r ";
401 - command.append(PATH_API_UPLOADS).append(id).append("/audio"); 405 + command.append(path_contents).append(id).append("/audio");
402 system(command.c_str()); 406 system(command.c_str());
403 } 407 }
404 408
405 void Recognize::createDir(){ 409 void Recognize::createDir(){
406 410
407 string command = "mkdir "; 411 string command = "mkdir ";
408 - command.append(PATH_API_UPLOADS).append(id).append("/audio").append(" && mkdir ").  
409 - append(PATH_API_UPLOADS).append(id).append("/audio/parts").append(" && mkdir ").  
410 - append(PATH_API_UPLOADS).append(id).append("/audio/origin"); 412 + command.append(path_contents).append(id)
  413 + .append(" && mkdir ").append(path_contents).append(id).append("/audio")
  414 + .append(" && mkdir ").append(path_contents).append(id).append("/audio/parts")
  415 + .append(" && mkdir ").append(path_contents).append(id).append("/audio/origin");
411 system(command.c_str()); 416 system(command.c_str());
412 } 417 }
servico/src/serviceWindowGenerationFromREC.cpp
@@ -16,7 +16,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( @@ -16,7 +16,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC(
16 } 16 }
17 17
18 ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( 18 ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC(
19 - char* path_video, int sublanguage, int position, int size, int transparency, char* id, char* client_type, int _serviceType) { 19 + char* path_video, int sublanguage, int position, int size, int transparency, char* id, char* client_type, int serviceType) {
20 20
21 setPathInput(path_video); 21 setPathInput(path_video);
22 setSubLanguage(sublanguage); 22 setSubLanguage(sublanguage);
@@ -26,7 +26,11 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( @@ -26,7 +26,11 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC(
26 setServiceType(serviceType); 26 setServiceType(serviceType);
27 setClientType(client_type); 27 setClientType(client_type);
28 setUserId(id); 28 setUserId(id);
29 - rec = new Recognize(path_video, 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 +
30 finish = false; 34 finish = false;
31 DPRINTF("Done!\n"); 35 DPRINTF("Done!\n");
32 } 36 }