Commit ccc268c5e3a235eca011e5bf07f9eda10fdb3a1d

Authored by Erickson Silva
1 parent d2ad080a
Exists in master and in 2 other branches api, devel

Service IOS Text adicionado. REC inicializando como nova Thread. Sincronizacao REC implementada.

extratorSRT/src/include/extratorSRT.h
... ... @@ -51,7 +51,6 @@ private:
51 51 ReaderSRT * reader;
52 52 Subtitle * subtitle;
53 53  
54   - double convert_pts(char* strtime);
55 54 uint64_t calcula_pts(double msec);
56 55  
57 56 };
... ...
main.cpp
... ... @@ -227,7 +227,7 @@ void serviceSRT(char* path_in, char* path_srt, char* sublanguage,
227 227 void serviceText(char* path_text, char* transparency, char* id, char* client_type){
228 228  
229 229 //filename = createFileToRespWeb(id);
230   -
  230 + if (strcmp(client_type, (char*)"WEB") == 0) {
231 231 ServiceWindowGenerationFromText *service_text;
232 232 service_text = new ServiceWindowGenerationFromText(path_text, id, (int) atoi(transparency), 4, client_type);
233 233 try{
... ... @@ -243,6 +243,26 @@ void serviceText(char* path_text, char* transparency, char* id, char* client_typ
243 243 }
244 244 //updateRequestStatusWeb(filename.c_str(), id, "true");
245 245 delete service_text;
  246 + } else {
  247 + printf("ServicoIOS\n");
  248 + ServiceWindowGenerationFromText *service_text;
  249 + service_text = new ServiceWindowGenerationFromText(path_text, id, (int) atoi(transparency), 4, (char*)"IOS");
  250 + try{
  251 + service_text->initialize();
  252 + }catch(ServiceException ex){
  253 + fail(ex.getMessage());
  254 + hasFailed();
  255 + return;
  256 + }
  257 +
  258 + while (service_text->isAlive()) {
  259 + usleep(100000); //100ms
  260 + }
  261 + //updateRequestStatusWeb(filename.c_str(), id, "true");
  262 + delete service_text;
  263 +
  264 +
  265 + }
246 266  
247 267 }
248 268  
... ...
mixer/src/Mixer.cpp
... ... @@ -130,7 +130,7 @@ void Mixer::mixVideos () {
130 130 ffmpeg -i videoDemoLibras.ts -vcodec libx264 -f flv -ar 22050 -ab 32 -sameq -threads 8 -y teste.flv
131 131 */
132 132  
133   - printf("\n\n%s\n\n", ffmpegSentence.c_str());
  133 + //printf("\n\n%s\n\n", ffmpegSentence.c_str());
134 134 system(ffmpegSentence.c_str());
135 135  
136 136 //string removeVideoCMD = "rm -rf "+nameOfMainVideo+".ts"; //removo o vídeo exemplo-45fps.ts
... ... @@ -258,7 +258,7 @@ void Mixer::setSize(int size){
258 258 string ffprobeSentence = "ffprobe -show_streams "+this->mainVideo+" 2> /dev/null | grep \"height=\" | cut -d'=' -f2 > "+temporaryTextFile;
259 259 system(ffprobeSentence.c_str());
260 260  
261   - printf("\n\n%s\n\n",ffprobeSentence.c_str());
  261 + //printf("\n\n%s\n\n",ffprobeSentence.c_str());
262 262  
263 263  
264 264 string heightStr = "324"; //se não conseguir ler do arquivo a altura será essa.. :(
... ... @@ -315,7 +315,7 @@ void Mixer::setMainVideo(string mainVideo){
315 315 this->temporaryTextFile = "vlibras_user/vlibras-web/public/uploads/videos/";
316 316 temporaryTextFile.append(this->user_id).append("/tamanho.txt");
317 317  
318   - printf("##########temporaryTextFile: %s\n", temporaryTextFile.c_str());
  318 + //printf("##########temporaryTextFile: %s\n", temporaryTextFile.c_str());
319 319  
320 320 }
321 321 string Mixer::getMainVideo(){
... ...
recognize/src/include/recognize.h
  1 +#include "jthread.h"
1 2 #include <iostream>
2 3 #include <stdlib.h>
3 4 #include <stdint.h>
... ... @@ -6,13 +7,16 @@
6 7 #include "dprintf.h"
7 8 #include "logger.h"
8 9  
  10 +#include "listenerMonitorPCRBase.h"
9 11 #include "recognizeListener.h"
10 12 #include "recognizeException.h"
11 13  
12 14  
  15 +using namespace jthread;
13 16 using namespace std;
14 17  
15   -class Recognize {
  18 +
  19 +class Recognize: public Thread, public ListenerMonitorPCRBase {
16 20  
17 21 public:
18 22  
... ... @@ -38,15 +42,24 @@ public:
38 42  
39 43 void addListener(RecognizeListener* listener);
40 44  
  45 + void notifyPCRBase(uint64_t pcrbase);
  46 +
41 47 bool isFinished();
42 48  
  49 + void Run();
  50 + int count_lines;
  51 +
43 52 private:
44 53  
  54 + int64_t pcr_base;
  55 + bool hasPCRBase;
45 56 char* pathVideo;
46 57 string id;
47 58 float confidenceRate;
48 59 bool finished;
49 60 vector<float> scores;
  61 + vector<int64_t> pts;
  62 +
50 63  
51 64 /** inputType: 1 = RawFile, 2 = Mic */
52 65 int inputType, frequency, sizeBlocs;
... ... @@ -63,8 +76,13 @@ private:
63 76 void filterOutputJulius();
64 77 void generateConfidence();
65 78 void notifyListeners(char* text);
  79 + void notifyEndExtraction(int sentences_size);
  80 +
66 81 void cleanFiles();
67 82 void createDir();
68   - bool getConfidence(int i);
  83 + bool getConfidence();
69 84  
  85 + int64_t calcula_pts(double msec);
  86 + int64_t convert_pts(string pts);
  87 +
70 88 };
... ...
recognize/src/include/recognizeListener.h
... ... @@ -14,7 +14,8 @@ class RecognizeListener {
14 14  
15 15 public:
16 16 virtual void notifyTextRecognized(unsigned char* text, int64_t pts) = 0;
17   -
  17 + virtual void notifyEnd(int sentences_size) = 0;
  18 +
18 19 };
19 20  
20 21 #endif /* RECOGNIZELISTENER_H */
... ...
recognize/src/recognize.cpp
... ... @@ -5,7 +5,7 @@
5 5 #include <algorithm>
6 6 #include <vector>
7 7 #include <iterator>
8   -
  8 +#include <stdlib.h>
9 9 #include <iostream>
10 10 #include <string>
11 11 #include <sys/stat.h>
... ... @@ -50,6 +50,8 @@ Recognize::Recognize(char* _pathVideo, char* _id) {
50 50 ss << _id;
51 51 ss >> id;
52 52 confidenceRate=CONFIDENCE_RATE;
  53 + pcr_base = 0;
  54 + hasPCRBase = false;
53 55 DPRINTF("Done!\n");
54 56 }
55 57  
... ... @@ -60,6 +62,8 @@ Recognize::Recognize(char* _pathVideo, char* _id, char* rate) {
60 62 inputType = INPUT_PATTERN;
61 63 frequency = FREQUENCY_PATTERN;
62 64 sizeBlocs = BLOCS_PATTERN;
  65 + pcr_base = 0;
  66 + hasPCRBase = false;
63 67 stringstream ss;
64 68 ss << _id;
65 69 ss >> id;
... ... @@ -77,6 +81,8 @@ Recognize::Recognize(char* _pathVideo, int _inputType, char* _id) {
77 81 frequency = FREQUENCY_PATTERN;
78 82 sizeBlocs = BLOCS_PATTERN;
79 83 id = _id;
  84 + pcr_base = 0;
  85 + hasPCRBase = false;
80 86 DPRINTF("Done!\n");
81 87 }
82 88  
... ... @@ -99,6 +105,10 @@ void Recognize::initialize() {
99 105 Util::Logger::Instance()->writeLog((char*) "[ERRO: recognize.cpp] Arquivo de vídeo não encontrado.");
100 106 throw RecognizeException("Falha ao abrir o arquivo de vídeo! Verifique se o mesmo existe.");
101 107 }
  108 + this->Start();
  109 +}
  110 +
  111 +void Recognize::Run(){
102 112  
103 113 finished = false;
104 114  
... ... @@ -111,10 +121,9 @@ void Recognize::initialize() {
111 121 cleanFiles();
112 122  
113 123 finished = true;
114   -
  124 + notifyEndExtraction(count_lines-1);
115 125 }
116 126  
117   -
118 127 void Recognize::setFrequency(int freq) {
119 128 frequency = freq;
120 129 }
... ... @@ -213,9 +222,12 @@ void Recognize::breakVideoParts(int timeTotal) {
213 222 sprintf(tmp, "%i", t);
214 223 t_str = tmp;
215 224 }
  225 +
216 226 sprintf(tmp, "%i", ss);
217 227 ss_str = tmp;
218 228  
  229 + pts.push_back(convert_pts(ss_str));
  230 +
219 231 command = "sox ";
220 232 command.append(PATH_GTAAAS_WEB).append(id).append(PATH_AUDIO_ORIGIN).append(" ").append(PATH_GTAAAS_WEB).append(id).append(PATH_AUDIO_PARTS);
221 233 sprintf(tmp, "%i", count++);
... ... @@ -255,7 +267,8 @@ void Recognize::executeJuliusEngine() {
255 267 append(PATH_GTAAAS_WEB).append(id).
256 268 append(FILENAME_RECOGNIZED_OUT);
257 269  
258   - printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str());
  270 + //Command of execute Julius
  271 + //printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str());
259 272 system(command.c_str());
260 273  
261 274 }
... ... @@ -267,7 +280,7 @@ void Recognize::generateConfidence() {
267 280 append(FIND_CONFIDENCE).append(" >> ").append(PATH_GTAAAS_WEB).append(id).append(FILENAME_CONFIDENCEOUT);
268 281  
269 282 system(command.c_str());
270   - printf("\n\n---> command: %s\n\n", command.c_str());
  283 + //printf("\n\n---> command: %s\n\n", command.c_str());
271 284  
272 285 string path;
273 286 path.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_CONFIDENCEOUT);
... ... @@ -316,9 +329,9 @@ void Recognize::generateConfidence() {
316 329 }
317 330 }
318 331  
319   -bool Recognize::getConfidence(int i){
  332 +bool Recognize::getConfidence(){
320 333 //cout << "CONFIDENCE: " << scores[i] << endl;
321   - if (scores[i] < confidenceRate)
  334 + if (scores.front() < confidenceRate)
322 335 return false;
323 336 return true;
324 337 }
... ... @@ -334,9 +347,9 @@ void Recognize::filterOutputJulius() {
334 347 append(FIND_SENTENCE).append(" >> ").append(PATH_GTAAAS_WEB).append(id).append(FILENAME_FILTEROUT);
335 348  
336 349 system(command.c_str());
337   - printf("\n\n---> command: %s\n\n", command.c_str());
  350 + //printf("\n\n---> command: %s\n\n", command.c_str());
338 351  
339   - int count_lines = 0;
  352 + count_lines = 0;
340 353  
341 354 string path;
342 355 path.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_FILTEROUT);
... ... @@ -356,10 +369,11 @@ void Recognize::filterOutputJulius() {
356 369 strFilter = line.substr(strlen(FIND_SENTENCE), sizeLine);
357 370 sentence_ptr = new char[strFilter.length()+1];
358 371 strcpy(sentence_ptr, (char*) strFilter.c_str());
359   - if(getConfidence(count_lines))
  372 + if(getConfidence())
360 373 notifyListeners(sentence_ptr);
361 374 else
362 375 notifyListeners((char*) "SENTENCA_COM_BAIXA_QUALIDADE");
  376 + scores.erase(scores.begin());
363 377 }
364 378 count_lines++;
365 379 } while (!in.eof());
... ... @@ -375,13 +389,39 @@ void Recognize::filterOutputJulius() {
375 389 void Recognize::notifyListeners(char* text) {
376 390 //cout << "NOTIFY: " << text << endl;
377 391  
378   - int64_t pts = PTS_PATTERN;
  392 + int64_t pts_run = pts.front();
379 393 for(list<RecognizeListener*>::iterator it = listeners->begin(); it != listeners->end(); it++){
380   - (*it)->notifyTextRecognized((unsigned char*) text, pts);
  394 + (*it)->notifyTextRecognized((unsigned char*) text, calcula_pts(pts_run));
  395 +
381 396 }
  397 + pts.erase(pts.begin());
382 398  
383 399 }
384 400  
  401 +void Recognize::notifyEndExtraction(int sentences_size) {
  402 + DDPRINTF("Recognizer concluiu o reconhecimento: %d sentenças.\n", sentences_size);
  403 + for(list<RecognizeListener*>::iterator it = listeners->begin(); it != listeners->end(); it++){
  404 + (*it)->notifyEnd(sentences_size);
  405 + }
  406 +}
  407 +
  408 +void Recognize::notifyPCRBase(uint64_t pcrbase){
  409 + //DDPRINTF("PCRBase = %ld\n", pcrbase);
  410 + this->pcr_base = pcrbase;
  411 + this->hasPCRBase = true;
  412 +}
  413 +
  414 +int64_t Recognize::calcula_pts(double msec) {
  415 + return (int64_t)(pcr_base + ((msec/1000) * 100000.0));
  416 +}
  417 +
  418 +int64_t Recognize::convert_pts(string pts){
  419 + int64_t ui64;
  420 + stringstream ss;
  421 + ss << pts;
  422 + ss >> ui64;
  423 + return ui64*1000;
  424 +}
385 425  
386 426 void Recognize::addListener(RecognizeListener* listener) {
387 427 listeners->push_back(listener);
... ... @@ -401,10 +441,10 @@ void Recognize::cleanFiles() {
401 441 }
402 442  
403 443 void Recognize::createDir(){
  444 +
404 445 string command = "mkdir ";
405 446 command.append(PATH_GTAAAS_WEB).append(id).append("/audio").append(" && mkdir ").
406 447 append(PATH_GTAAAS_WEB).append(id).append("/audio/parts").append(" && mkdir ").
407 448 append(PATH_GTAAAS_WEB).append(id).append("/audio/origin");
408   - printf("%s\n", command.c_str());
409 449 system(command.c_str());
410 450 }
... ...
servico/src/include/serviceWindowGenerationFromREC.h
... ... @@ -6,6 +6,8 @@
6 6 #include "jthread.h"
7 7 #include "serviceWindowGeneration.h"
8 8 #include "recognize.h"
  9 +#include "inputFile.h"
  10 +#include "monitor_pcr.h"
9 11  
10 12 using namespace std;
11 13 using namespace jthread;
... ... @@ -16,7 +18,7 @@ private:
16 18 Recognize *rec;
17 19  
18 20 public:
19   -
  21 +
20 22 ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType, char* rate);
21 23  
22 24 ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType);
... ... @@ -25,6 +27,8 @@ public:
25 27 void initialize();
26 28  
27 29 virtual void notifyTextRecognized(unsigned char* text, int64_t pts);
  30 + virtual void notifyEnd(int sentences_size);
  31 +
28 32  
29 33 void notifyTranslator(unsigned char *text);
30 34 void notifySynchWithoutTranslator(unsigned char *text, int64_t pts);
... ...
servico/src/include/serviceWindowGenerationFromText.h
... ... @@ -28,7 +28,7 @@ public:
28 28 bool isAlive();
29 29 void Run();
30 30 void transcodeVideoToWebm();
31   -
  31 + void transcodeVideoToAvi();
32 32 };
33 33  
34 34 #endif /* _SERVICEWINDOWGENERATIONFROMTEXT_H */
... ...
servico/src/serviceWindowGenerationFromREC.cpp
... ... @@ -36,11 +36,20 @@ ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() {
36 36 }
37 37  
38 38 void ServiceWindowGenerationFromREC::initialize() {
39   - rec->addListener(this);
40   -
  39 +
  40 + rec->addListener(this);
  41 +
  42 + inputfile = new InputFile(this->path_input);
  43 + monitor_pcr_base = new MonitorPCR();
  44 +
  45 + monitor_pcr_base->addListenerPCRBase(rec);
  46 + inputfile->registraOuvinte(monitor_pcr_base);
  47 +
41 48 ServiceWindowGeneration::initialize();
  49 +
42 50 try{
43   - rec->initialize();
  51 + rec->initialize();
  52 + inputfile->initialize();
44 53 }catch(RecognizeException ex){
45 54 throw ServiceException(ex.getMessage());
46 55 }
... ... @@ -60,6 +69,11 @@ void ServiceWindowGenerationFromREC::notifyTranslator(unsigned char *text) {
60 69 tradutor->traduz(text);
61 70 }
62 71  
  72 +void ServiceWindowGenerationFromREC::notifyEnd(int sentences_size) {
  73 + DDPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size);
  74 + setSizeOfSubtitles(sentences_size);
  75 +}
  76 +
63 77 void ServiceWindowGenerationFromREC::notifySynchWithoutTranslator(unsigned char *text, int64_t pts) {
64 78 char* pch = strtok((char*) text, " ");
65 79 while (pch != NULL) {
... ... @@ -75,5 +89,4 @@ void ServiceWindowGenerationFromREC::Run() {
75 89 while (!rec->isFinished()) {
76 90 sleep(2);
77 91 }
78   - sincronizador->stop();
79 92 }
... ...
servico/src/serviceWindowGenerationFromText.cpp
... ... @@ -67,6 +67,10 @@ void ServiceWindowGenerationFromText::Run() {
67 67 if (strcmp(client_type, (char*)"WEB") == 0) {
68 68 printf("[INFO]: A transcodificação para .webm está ativada!\n");
69 69 transcodeVideoToWebm();
  70 + } else if (strcmp(client_type, (char*)"IOS") == 0) {
  71 + printf("[INFO]: A transcodificação para .avi está ativada!\n");
  72 +
  73 + transcodeVideoToAvi();
70 74 }
71 75 else
72 76 transcodeVideoToFlv();
... ... @@ -86,4 +90,18 @@ void ServiceWindowGenerationFromText::transcodeVideoToWebm() {
86 90 .append(getPathLibras());
87 91 //printf("[INFO]: Transcodification command -> %s\n", command.c_str());
88 92 system(command.c_str());
89   -}
90 93 \ No newline at end of file
  94 +}
  95 +
  96 +void ServiceWindowGenerationFromText::transcodeVideoToAvi() {
  97 +
  98 + string command = "ffmpeg -i ";
  99 + command.append(getPathLibras())
  100 + .append(" -vcodec mjpeg -r 30 -pix_fmt yuvj422p ")
  101 + .append(PATH_LIBRAS)
  102 + .append(getUserId())
  103 + .append(".mp4")
  104 + .append(" && rm ")
  105 + .append(getPathLibras());
  106 + //printf("[INFO]: Transcodification command -> %s\n", command.c_str());
  107 + system(command.c_str());
  108 +}
... ...