diff --git a/extratorSRT/src/include/extratorSRT.h b/extratorSRT/src/include/extratorSRT.h index 9de12de..e70477b 100644 --- a/extratorSRT/src/include/extratorSRT.h +++ b/extratorSRT/src/include/extratorSRT.h @@ -51,7 +51,6 @@ private: ReaderSRT * reader; Subtitle * subtitle; - double convert_pts(char* strtime); uint64_t calcula_pts(double msec); }; diff --git a/main.cpp b/main.cpp index 1d3d3c3..3665590 100644 --- a/main.cpp +++ b/main.cpp @@ -227,7 +227,7 @@ void serviceSRT(char* path_in, char* path_srt, char* sublanguage, void serviceText(char* path_text, char* transparency, char* id, char* client_type){ //filename = createFileToRespWeb(id); - + if (strcmp(client_type, (char*)"WEB") == 0) { ServiceWindowGenerationFromText *service_text; service_text = new ServiceWindowGenerationFromText(path_text, id, (int) atoi(transparency), 4, client_type); try{ @@ -243,6 +243,26 @@ void serviceText(char* path_text, char* transparency, char* id, char* client_typ } //updateRequestStatusWeb(filename.c_str(), id, "true"); delete service_text; + } else { + printf("ServicoIOS\n"); + ServiceWindowGenerationFromText *service_text; + service_text = new ServiceWindowGenerationFromText(path_text, id, (int) atoi(transparency), 4, (char*)"IOS"); + try{ + service_text->initialize(); + }catch(ServiceException ex){ + fail(ex.getMessage()); + hasFailed(); + return; + } + + while (service_text->isAlive()) { + usleep(100000); //100ms + } + //updateRequestStatusWeb(filename.c_str(), id, "true"); + delete service_text; + + + } } diff --git a/mixer/src/Mixer.cpp b/mixer/src/Mixer.cpp index 0338612..df8dce1 100644 --- a/mixer/src/Mixer.cpp +++ b/mixer/src/Mixer.cpp @@ -130,7 +130,7 @@ void Mixer::mixVideos () { ffmpeg -i videoDemoLibras.ts -vcodec libx264 -f flv -ar 22050 -ab 32 -sameq -threads 8 -y teste.flv */ - printf("\n\n%s\n\n", ffmpegSentence.c_str()); + //printf("\n\n%s\n\n", ffmpegSentence.c_str()); system(ffmpegSentence.c_str()); //string removeVideoCMD = "rm -rf "+nameOfMainVideo+".ts"; //removo o vídeo exemplo-45fps.ts @@ -258,7 +258,7 @@ void Mixer::setSize(int size){ string ffprobeSentence = "ffprobe -show_streams "+this->mainVideo+" 2> /dev/null | grep \"height=\" | cut -d'=' -f2 > "+temporaryTextFile; system(ffprobeSentence.c_str()); - printf("\n\n%s\n\n",ffprobeSentence.c_str()); + //printf("\n\n%s\n\n",ffprobeSentence.c_str()); string heightStr = "324"; //se não conseguir ler do arquivo a altura será essa.. :( @@ -315,7 +315,7 @@ void Mixer::setMainVideo(string mainVideo){ this->temporaryTextFile = "vlibras_user/vlibras-web/public/uploads/videos/"; temporaryTextFile.append(this->user_id).append("/tamanho.txt"); - printf("##########temporaryTextFile: %s\n", temporaryTextFile.c_str()); + //printf("##########temporaryTextFile: %s\n", temporaryTextFile.c_str()); } string Mixer::getMainVideo(){ diff --git a/recognize/src/include/recognize.h b/recognize/src/include/recognize.h index 2bd4f22..8e130b7 100644 --- a/recognize/src/include/recognize.h +++ b/recognize/src/include/recognize.h @@ -1,3 +1,4 @@ +#include "jthread.h" #include #include #include @@ -6,13 +7,16 @@ #include "dprintf.h" #include "logger.h" +#include "listenerMonitorPCRBase.h" #include "recognizeListener.h" #include "recognizeException.h" +using namespace jthread; using namespace std; -class Recognize { + +class Recognize: public Thread, public ListenerMonitorPCRBase { public: @@ -38,15 +42,24 @@ public: void addListener(RecognizeListener* listener); + void notifyPCRBase(uint64_t pcrbase); + bool isFinished(); + void Run(); + int count_lines; + private: + int64_t pcr_base; + bool hasPCRBase; char* pathVideo; string id; float confidenceRate; bool finished; vector scores; + vector pts; + /** inputType: 1 = RawFile, 2 = Mic */ int inputType, frequency, sizeBlocs; @@ -63,8 +76,13 @@ private: void filterOutputJulius(); void generateConfidence(); void notifyListeners(char* text); + void notifyEndExtraction(int sentences_size); + void cleanFiles(); void createDir(); - bool getConfidence(int i); + bool getConfidence(); + int64_t calcula_pts(double msec); + int64_t convert_pts(string pts); + }; diff --git a/recognize/src/include/recognizeListener.h b/recognize/src/include/recognizeListener.h index e6fb900..d63d4a8 100644 --- a/recognize/src/include/recognizeListener.h +++ b/recognize/src/include/recognizeListener.h @@ -14,7 +14,8 @@ class RecognizeListener { public: virtual void notifyTextRecognized(unsigned char* text, int64_t pts) = 0; - + virtual void notifyEnd(int sentences_size) = 0; + }; #endif /* RECOGNIZELISTENER_H */ diff --git a/recognize/src/recognize.cpp b/recognize/src/recognize.cpp index 3a5b0e6..6667fbe 100644 --- a/recognize/src/recognize.cpp +++ b/recognize/src/recognize.cpp @@ -5,7 +5,7 @@ #include #include #include - +#include #include #include #include @@ -50,6 +50,8 @@ Recognize::Recognize(char* _pathVideo, char* _id) { ss << _id; ss >> id; confidenceRate=CONFIDENCE_RATE; + pcr_base = 0; + hasPCRBase = false; DPRINTF("Done!\n"); } @@ -60,6 +62,8 @@ Recognize::Recognize(char* _pathVideo, char* _id, char* rate) { inputType = INPUT_PATTERN; frequency = FREQUENCY_PATTERN; sizeBlocs = BLOCS_PATTERN; + pcr_base = 0; + hasPCRBase = false; stringstream ss; ss << _id; ss >> id; @@ -77,6 +81,8 @@ Recognize::Recognize(char* _pathVideo, int _inputType, char* _id) { frequency = FREQUENCY_PATTERN; sizeBlocs = BLOCS_PATTERN; id = _id; + pcr_base = 0; + hasPCRBase = false; DPRINTF("Done!\n"); } @@ -99,6 +105,10 @@ void Recognize::initialize() { Util::Logger::Instance()->writeLog((char*) "[ERRO: recognize.cpp] Arquivo de vídeo não encontrado."); throw RecognizeException("Falha ao abrir o arquivo de vídeo! Verifique se o mesmo existe."); } + this->Start(); +} + +void Recognize::Run(){ finished = false; @@ -111,10 +121,9 @@ void Recognize::initialize() { cleanFiles(); finished = true; - + notifyEndExtraction(count_lines-1); } - void Recognize::setFrequency(int freq) { frequency = freq; } @@ -213,9 +222,12 @@ void Recognize::breakVideoParts(int timeTotal) { sprintf(tmp, "%i", t); t_str = tmp; } + sprintf(tmp, "%i", ss); ss_str = tmp; + pts.push_back(convert_pts(ss_str)); + command = "sox "; command.append(PATH_GTAAAS_WEB).append(id).append(PATH_AUDIO_ORIGIN).append(" ").append(PATH_GTAAAS_WEB).append(id).append(PATH_AUDIO_PARTS); sprintf(tmp, "%i", count++); @@ -255,7 +267,8 @@ void Recognize::executeJuliusEngine() { append(PATH_GTAAAS_WEB).append(id). append(FILENAME_RECOGNIZED_OUT); - printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str()); + //Command of execute Julius + //printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str()); system(command.c_str()); } @@ -267,7 +280,7 @@ void Recognize::generateConfidence() { append(FIND_CONFIDENCE).append(" >> ").append(PATH_GTAAAS_WEB).append(id).append(FILENAME_CONFIDENCEOUT); system(command.c_str()); - printf("\n\n---> command: %s\n\n", command.c_str()); + //printf("\n\n---> command: %s\n\n", command.c_str()); string path; path.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_CONFIDENCEOUT); @@ -316,9 +329,9 @@ void Recognize::generateConfidence() { } } -bool Recognize::getConfidence(int i){ +bool Recognize::getConfidence(){ //cout << "CONFIDENCE: " << scores[i] << endl; - if (scores[i] < confidenceRate) + if (scores.front() < confidenceRate) return false; return true; } @@ -334,9 +347,9 @@ void Recognize::filterOutputJulius() { append(FIND_SENTENCE).append(" >> ").append(PATH_GTAAAS_WEB).append(id).append(FILENAME_FILTEROUT); system(command.c_str()); - printf("\n\n---> command: %s\n\n", command.c_str()); + //printf("\n\n---> command: %s\n\n", command.c_str()); - int count_lines = 0; + count_lines = 0; string path; path.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_FILTEROUT); @@ -356,10 +369,11 @@ void Recognize::filterOutputJulius() { strFilter = line.substr(strlen(FIND_SENTENCE), sizeLine); sentence_ptr = new char[strFilter.length()+1]; strcpy(sentence_ptr, (char*) strFilter.c_str()); - if(getConfidence(count_lines)) + if(getConfidence()) notifyListeners(sentence_ptr); else notifyListeners((char*) "SENTENCA_COM_BAIXA_QUALIDADE"); + scores.erase(scores.begin()); } count_lines++; } while (!in.eof()); @@ -375,13 +389,39 @@ void Recognize::filterOutputJulius() { void Recognize::notifyListeners(char* text) { //cout << "NOTIFY: " << text << endl; - int64_t pts = PTS_PATTERN; + int64_t pts_run = pts.front(); for(list::iterator it = listeners->begin(); it != listeners->end(); it++){ - (*it)->notifyTextRecognized((unsigned char*) text, pts); + (*it)->notifyTextRecognized((unsigned char*) text, calcula_pts(pts_run)); + } + pts.erase(pts.begin()); } +void Recognize::notifyEndExtraction(int sentences_size) { + DDPRINTF("Recognizer concluiu o reconhecimento: %d sentenças.\n", sentences_size); + for(list::iterator it = listeners->begin(); it != listeners->end(); it++){ + (*it)->notifyEnd(sentences_size); + } +} + +void Recognize::notifyPCRBase(uint64_t pcrbase){ + //DDPRINTF("PCRBase = %ld\n", pcrbase); + this->pcr_base = pcrbase; + this->hasPCRBase = true; +} + +int64_t Recognize::calcula_pts(double msec) { + return (int64_t)(pcr_base + ((msec/1000) * 100000.0)); +} + +int64_t Recognize::convert_pts(string pts){ + int64_t ui64; + stringstream ss; + ss << pts; + ss >> ui64; + return ui64*1000; +} void Recognize::addListener(RecognizeListener* listener) { listeners->push_back(listener); @@ -401,10 +441,10 @@ void Recognize::cleanFiles() { } void Recognize::createDir(){ + string command = "mkdir "; command.append(PATH_GTAAAS_WEB).append(id).append("/audio").append(" && mkdir "). append(PATH_GTAAAS_WEB).append(id).append("/audio/parts").append(" && mkdir "). append(PATH_GTAAAS_WEB).append(id).append("/audio/origin"); - printf("%s\n", command.c_str()); system(command.c_str()); } diff --git a/servico/src/include/serviceWindowGenerationFromREC.h b/servico/src/include/serviceWindowGenerationFromREC.h index d92259b..07367cb 100644 --- a/servico/src/include/serviceWindowGenerationFromREC.h +++ b/servico/src/include/serviceWindowGenerationFromREC.h @@ -6,6 +6,8 @@ #include "jthread.h" #include "serviceWindowGeneration.h" #include "recognize.h" +#include "inputFile.h" +#include "monitor_pcr.h" using namespace std; using namespace jthread; @@ -16,7 +18,7 @@ private: Recognize *rec; public: - + ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType, char* rate); ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType); @@ -25,6 +27,8 @@ public: void initialize(); virtual void notifyTextRecognized(unsigned char* text, int64_t pts); + virtual void notifyEnd(int sentences_size); + void notifyTranslator(unsigned char *text); void notifySynchWithoutTranslator(unsigned char *text, int64_t pts); diff --git a/servico/src/include/serviceWindowGenerationFromText.h b/servico/src/include/serviceWindowGenerationFromText.h index 99f884e..60ac55a 100644 --- a/servico/src/include/serviceWindowGenerationFromText.h +++ b/servico/src/include/serviceWindowGenerationFromText.h @@ -28,7 +28,7 @@ public: bool isAlive(); void Run(); void transcodeVideoToWebm(); - + void transcodeVideoToAvi(); }; #endif /* _SERVICEWINDOWGENERATIONFROMTEXT_H */ diff --git a/servico/src/serviceWindowGenerationFromREC.cpp b/servico/src/serviceWindowGenerationFromREC.cpp index e561668..f95b7a3 100644 --- a/servico/src/serviceWindowGenerationFromREC.cpp +++ b/servico/src/serviceWindowGenerationFromREC.cpp @@ -36,11 +36,20 @@ ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() { } void ServiceWindowGenerationFromREC::initialize() { - rec->addListener(this); - + + rec->addListener(this); + + inputfile = new InputFile(this->path_input); + monitor_pcr_base = new MonitorPCR(); + + monitor_pcr_base->addListenerPCRBase(rec); + inputfile->registraOuvinte(monitor_pcr_base); + ServiceWindowGeneration::initialize(); + try{ - rec->initialize(); + rec->initialize(); + inputfile->initialize(); }catch(RecognizeException ex){ throw ServiceException(ex.getMessage()); } @@ -60,6 +69,11 @@ void ServiceWindowGenerationFromREC::notifyTranslator(unsigned char *text) { tradutor->traduz(text); } +void ServiceWindowGenerationFromREC::notifyEnd(int sentences_size) { + DDPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); + setSizeOfSubtitles(sentences_size); +} + void ServiceWindowGenerationFromREC::notifySynchWithoutTranslator(unsigned char *text, int64_t pts) { char* pch = strtok((char*) text, " "); while (pch != NULL) { @@ -75,5 +89,4 @@ void ServiceWindowGenerationFromREC::Run() { while (!rec->isFinished()) { sleep(2); } - sincronizador->stop(); } diff --git a/servico/src/serviceWindowGenerationFromText.cpp b/servico/src/serviceWindowGenerationFromText.cpp index 9fe6f16..6027f8e 100644 --- a/servico/src/serviceWindowGenerationFromText.cpp +++ b/servico/src/serviceWindowGenerationFromText.cpp @@ -67,6 +67,10 @@ void ServiceWindowGenerationFromText::Run() { if (strcmp(client_type, (char*)"WEB") == 0) { printf("[INFO]: A transcodificação para .webm está ativada!\n"); transcodeVideoToWebm(); + } else if (strcmp(client_type, (char*)"IOS") == 0) { + printf("[INFO]: A transcodificação para .avi está ativada!\n"); + + transcodeVideoToAvi(); } else transcodeVideoToFlv(); @@ -86,4 +90,18 @@ void ServiceWindowGenerationFromText::transcodeVideoToWebm() { .append(getPathLibras()); //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); system(command.c_str()); -} \ No newline at end of file +} + +void ServiceWindowGenerationFromText::transcodeVideoToAvi() { + + string command = "ffmpeg -i "; + command.append(getPathLibras()) + .append(" -vcodec mjpeg -r 30 -pix_fmt yuvj422p ") + .append(PATH_LIBRAS) + .append(getUserId()) + .append(".mp4") + .append(" && rm ") + .append(getPathLibras()); + //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); + system(command.c_str()); +} -- libgit2 0.21.2