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

main.cpp
... ... @@ -11,7 +11,6 @@
11 11 *
12 12 * Edit on 03 de Fevereiro de 2014
13 13 */
14   -
15 14 #include "serviceWindowGenerationFromSRT.h"
16 15 #include "serviceWindowGenerationFromREC.h"
17 16 #include "serviceWindowGenerationFromText.h"
... ... @@ -21,10 +20,6 @@
21 20 #include <sys/time.h>
22 21 #include <stdlib.h>
23 22  
24   -#define BLOQUEANTE 1
25   -#define NAO_BLOQUEANTE 2
26   -#define BOTH 3
27   -
28 23 using namespace std;
29 24  
30 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 32  
38 33 void help();
39 34 void serviceHelp(int service);
  35 +void setStatusOfReady(char* ready);
40 36 void fail(string msg);
41 37 void hasFailed();
42 38 void hasInvalid();
... ... @@ -52,15 +48,6 @@ int main(int argc, char* argv[]) {
52 48 gettimeofday(&tv1, NULL);
53 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 51 printf("\n################## VLIBRAS : LAVID ##################\n\n");
65 52  
66 53 if(argc >= 2) {
... ... @@ -75,23 +62,25 @@ int main(int argc, char* argv[]) {
75 62 hasInvalid();
76 63 break;
77 64 }
78   - if(argc == 9)
  65 + if(argc == 9){
  66 + setStatusOfReady("0");
79 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 70 serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]);
82 71  
83 72 break;
84 73 case 2:
85   - printf("[INFO] Serviço em manutenção!!!\n");
86   - exit(0);
87 74 if(argc < 8){
88 75 serviceHelp(2);
89 76 hasInvalid();
90 77 break;
91 78 }
92   - if(argc == 8)
  79 + if(argc == 8){
  80 + setStatusOfReady("0");
93 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 84 serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
96 85 break;
97 86 case 3:
... ... @@ -100,9 +89,11 @@ int main(int argc, char* argv[]) {
100 89 hasInvalid();
101 90 break;
102 91 }
103   - if(argc == 5)
  92 + if(argc == 5){
  93 + setStatusOfReady("0");
104 94 serviceText(argv[1], argv[2], argv[3], argv[4], "user");
105   - else
  95 + setStatusOfReady("1");
  96 + }else
106 97 serviceText(argv[1], argv[2], argv[3], argv[4], argv[5]);
107 98 break;
108 99 case 4:
... ... @@ -111,9 +102,11 @@ int main(int argc, char* argv[]) {
111 102 hasInvalid();
112 103 break;
113 104 }
114   - if(argc == 5 )
  105 + if(argc == 5 ){
  106 + setStatusOfReady("0");
115 107 serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], "user");
116   - else
  108 + setStatusOfReady("1");
  109 + }else
117 110 serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], argv[5]);
118 111 break;
119 112 case 5:
... ... @@ -124,9 +117,11 @@ int main(int argc, char* argv[]) {
124 117 hasInvalid();
125 118 break;
126 119 }
127   - if (argc == 5)
  120 + if (argc == 5){
  121 + setStatusOfReady("0");
128 122 serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], "user");
129   - else
  123 + setStatusOfReady("1");
  124 + }else
130 125 serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], argv[5]);
131 126 break;
132 127 default:
... ... @@ -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 159 void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position,
158 160 char* size, char* transparency, char* id, char* client_type){
159 161  
... ...
recognize/src/include/recognize.h
... ... @@ -23,7 +23,9 @@
23 23 #define SIZE_BUFFER 256
24 24 #define CONFIDENCE_RATE 0.10
25 25  
  26 +#define WEB_USER 1
26 27 #define PATH_API_UPLOADS "vlibras_user/vlibras-api/uploads/"
  28 +#define PATH_VBOX_CONTENTS "vlibras_user/.vlibras-conf/contents/"
27 29 #define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav"
28 30 #define PATH_AUDIO_PARTS "/audio/parts/"
29 31 #define FILENAME_RECOGNIZED_OUT "/audio/recognized.out"
... ... @@ -47,7 +49,7 @@ class Recognize: public Thread {
47 49  
48 50 public:
49 51  
50   - Recognize(char* _pathVideo, char* id);
  52 + Recognize(char* _pathVideo, char* id, int client_type);
51 53 Recognize(char* _pathVideo, char* id, char* rate);
52 54 Recognize(char* _pathVideo, int _inputType, char* id);
53 55 ~Recognize();
... ... @@ -76,6 +78,7 @@ public:
76 78  
77 79 private:
78 80  
  81 + char* path_contents;
79 82 char* pathVideo;
80 83 string id;
81 84 float confidenceRate;
... ...
recognize/src/recognize.cpp
1 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 5 listeners = new list<RecognizeListener*>();
6 6 pathVideo = _pathVideo;
... ... @@ -11,6 +11,12 @@ Recognize::Recognize(char* _pathVideo, char* _id) {
11 11 ss << _id;
12 12 ss >> id;
13 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 20 DPRINTF("Done!\n");
15 21 }
16 22  
... ... @@ -103,26 +109,22 @@ char* Recognize::extractAudioFromVideo() {
103 109 //command.append(strFreq).append(" -ac 1 -f wav ").append(PATH_AUDIO_ORIGIN).append(" &");
104 110 command.append(strFreq).
105 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 115 /*string tmp = "echo ";
113 116 tmp.append(PATH_AUDIO_ORIGIN).append(" >> ").append(FILENAME_AUDIOLIST);
114 117 system(tmp.c_str());*/
115   -
116 118 system(command.c_str());
117   -
118 119 }
119 120  
120 121  
121 122 int Recognize::getTimeMediaSec() {
122 123  
123 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 128 system(command.c_str());
127 129  
128 130 ifstream in("outfile");
... ... @@ -183,7 +185,9 @@ void Recognize::breakVideoParts(int timeTotal) {
183 185 pts.push_back(convert_pts(ss_str));
184 186  
185 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 191 sprintf(tmp, "%i", count++);
188 192 filename.append(tmp).append(".wav");
189 193 command.append(filename).append(" trim ").append(ss_str).append(" ").append(t_str);
... ... @@ -191,7 +195,10 @@ void Recognize::breakVideoParts(int timeTotal) {
191 195 system(command.c_str());
192 196  
193 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 202 system(apcomm.c_str());
196 203  
197 204 filename = FILENAME_AUDIOPART;
... ... @@ -208,19 +215,18 @@ void Recognize::executeJuliusEngine() {
208 215 char cfreq[10];
209 216  
210 217 command = "julius -C vlibras_user/vlibras-core/recognize/src/julius.jconf -input ";
211   - if (inputType == 1) {
  218 +
  219 + if (inputType == 1)
212 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 225 sprintf(cfreq, "%i", frequency);
218 226 command.append(" -smpFreq ").
219 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 230 //Command of execute Julius
225 231 //printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str());
226 232 system(command.c_str());
... ... @@ -230,14 +236,13 @@ void Recognize::executeJuliusEngine() {
230 236 void Recognize::generateConfidence() {
231 237  
232 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 241 system(command.c_str());
237 242 //printf("\n\n---> command: %s\n\n", command.c_str());
238 243  
239 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 246 ifstream in(path.c_str());
242 247  
243 248 if (!in) {
... ... @@ -307,16 +312,15 @@ void Recognize::filterOutputJulius() {
307 312 sentences = new std::list<char*>();
308 313  
309 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 317 system(command.c_str());
314 318 //printf("\n\n---> command: %s\n\n", command.c_str());
315 319  
316 320 count_lines = 0;
317 321  
318 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 324 ifstream in(path.c_str());
321 325 string strFilter;
322 326  
... ... @@ -398,15 +402,16 @@ bool Recognize::isFinished() {
398 402 void Recognize::cleanFiles() {
399 403  
400 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 406 system(command.c_str());
403 407 }
404 408  
405 409 void Recognize::createDir(){
406 410  
407 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 416 system(command.c_str());
412 417 }
... ...
servico/src/serviceWindowGenerationFromREC.cpp
... ... @@ -16,7 +16,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC(
16 16 }
17 17  
18 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 21 setPathInput(path_video);
22 22 setSubLanguage(sublanguage);
... ... @@ -26,7 +26,11 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC(
26 26 setServiceType(serviceType);
27 27 setClientType(client_type);
28 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 34 finish = false;
31 35 DPRINTF("Done!\n");
32 36 }
... ...