From a219d957019a4d7e4d061e038ebe3d4e52d4199e Mon Sep 17 00:00:00 2001 From: Wesnydy Ribeiro Date: Thu, 17 Mar 2016 11:13:35 -0300 Subject: [PATCH] Remove a verificação de arquivo já lido do ExtratorSRT --- extrator/src/extratorSRT.cpp | 49 +++++++++++++++++++++++-------------------------- renderer/src/renderer.cpp | 10 +++++----- servico/src/serviceWindowGenerationFromSubtitle.cpp | 8 ++++---- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/extrator/src/extratorSRT.cpp b/extrator/src/extratorSRT.cpp index d549ed8..893487a 100644 --- a/extrator/src/extratorSRT.cpp +++ b/extrator/src/extratorSRT.cpp @@ -8,8 +8,8 @@ ExtratorSRT::ExtratorSRT(){ PRINTL(util::_DEBUG, "ExtratorSTR Done!\n"); } -ExtratorSRT::~ExtratorSRT(){ - listeners->clear(); +ExtratorSRT::~ExtratorSRT(){ + listeners->clear(); delete listeners; //if (bff_reader) delete bff_reader; if (file_io) delete file_io; @@ -22,12 +22,12 @@ void ExtratorSRT::initialize(){ try{ file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); - }catch(Exception ex){ + }catch(Exception ex){ finish = true; Logging::instance()->writeLog("extratorSRT.cpp : Arquivo de legenda não encontrado."); throw ExtratorException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.\n"); } - + this->Start(); } @@ -39,7 +39,7 @@ void ExtratorSRT::addListener(ListenerSub* listener){ void ExtratorSRT::notifyListeners(unsigned char* subtitle, int64_t pts) { for(list::iterator it = listeners->begin(); it != listeners->end(); it++){ (*it)->notifySubtitle(subtitle, pts); - } + } } void ExtratorSRT::notifyEndExtraction(int size) { @@ -50,7 +50,7 @@ void ExtratorSRT::notifyEndExtraction(int size) { } void ExtratorSRT::setFilePath(char* path){ - filePath = (char*) path; + filePath = (char*) path; string command1 = "perl -p -e 's/\r$//' < "; command1.append(filePath).append(" > ").append(INPUT_SRT); system(command1.c_str()); @@ -78,7 +78,9 @@ void ExtratorSRT::Run(){ while(hasNextSubtitle()){ try{ subtitle = next(); - }catch(ExtratorException ex){ break; } + }catch(ExtratorException ex){ + break; + } sub_text = subtitle->getSubtitleText(); notifyListeners((unsigned char*)sub_text.c_str(), calcula_pts((double) subtitle->getTimeIn())); sub_index++; @@ -91,12 +93,7 @@ void ExtratorSRT::Run(){ } Subtitle* ExtratorSRT::next() { - - if (seek_pos >= file_io->getSize()){ - Logging::instance()->writeLog("extratorSRT.cpp : Arquivo de legenda já foi lido."); - throw ExtratorException("Esse arquivo já foi lido."); - } - + file_io->seek(seek_pos); try{ bff_reader = new BufferedReader(file_io); @@ -106,35 +103,35 @@ Subtitle* ExtratorSRT::next() { } Subtitle* sub = new Subtitle(); - string line = ""; + string line = ""; string text_sub = ""; - + try { /* ID */ int id = 0; line = bff_reader->readLine(); seek_pos += (int64_t) line.size() + SIZE_CSCAPE; - id = atoi(line.c_str()); + id = atoi(line.c_str()); sub->setID(id); /* TimeIn and TimeOut */ int64_t t_in = 0, t_out = 0; line = bff_reader->readLine(); seek_pos += (int64_t) line.size() + SIZE_CSCAPE; - + int target_pos = line.find(TARGET_TIME); t_in = str_to_time(line.substr(0, target_pos)); sub->setTimeIn(t_in); t_out = str_to_time(line.substr(target_pos + strlen(TARGET_TIME)+1, line.size())); - sub->setTimeOut(t_out); - - /* Text: read until line be empty */ + sub->setTimeOut(t_out); + + /* Text: read until line be empty */ while ((line = bff_reader->readLine()).size() > 0) { text_sub += line; - text_sub.append(" "); + text_sub.append(" "); } seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; - + } catch (lavidlib::EOFException &ex) { sub->setSubtitleText(formatText(text_sub)); seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; @@ -162,7 +159,7 @@ string ExtratorSRT::formatText(string line){ return f_line; } - + int64_t ExtratorSRT::str_to_time(string str_time) { int64_t ttime = 0; @@ -171,7 +168,7 @@ int64_t ExtratorSRT::str_to_time(string str_time) { int index = 0; int values [4]; // hh, mm, ss, ms - char * str = strtok(tokens, ":,"); + char * str = strtok(tokens, ":,"); while (str != NULL) { values[index] = atoi(str); str = strtok(NULL, ":,"); @@ -180,7 +177,7 @@ int64_t ExtratorSRT::str_to_time(string str_time) { delete(tokens); /* calculate time */ - ttime = /*hour to sec*/((((values[0] * 60) * 60) + + ttime = /*hour to sec*/((((values[0] * 60) * 60) + /*min to sec*/(values[1] * 60) +/*sec*/values[2])*1000) + values[3]; return ttime; @@ -188,5 +185,5 @@ int64_t ExtratorSRT::str_to_time(string str_time) { } uint64_t ExtratorSRT::calcula_pts(double msec) { - return (uint64_t)msec; + return (uint64_t)msec; } diff --git a/renderer/src/renderer.cpp b/renderer/src/renderer.cpp index 9014745..df701ed 100644 --- a/renderer/src/renderer.cpp +++ b/renderer/src/renderer.cpp @@ -9,7 +9,7 @@ Renderer::Renderer(char* path_Contents, char* id) { } Renderer::~Renderer() { - listeners->clear(); + listeners->clear(); delete listeners; if(cSocket) delete cSocket; PRINTL(util::_DEBUG, "Renderer finalized!\n"); @@ -60,7 +60,7 @@ void Renderer::connectToUnityPlayer() { PRINTL(util::_ERROR, "Número de tentativas de conexão excedido!\n"); throw lavidlib::RuntimeException(ex.getMessage().c_str()); } - } + } } }catch(lavidlib::UnknownHostException &ex){ throw lavidlib::RuntimeException(ex.getMessage().c_str()); @@ -71,7 +71,7 @@ void Renderer::connectToUnityPlayer() { void Renderer::receiveGlosa(string glosa, int64_t pts) { ostringstream oss; string formatedGlosa; //Formato da glosa que será enviada para o player: "glosa#pts" - + if(glosa == BADSENTENCE || glosa == BADTEXT) formatedGlosa = ""; //O player entende "#pts" como pose neutra else @@ -162,7 +162,7 @@ void Renderer::Run() { throw lavidlib::RuntimeException(ex.getMessage().c_str()); } } - + PRINTL(util::_INFO, "Gerando vídeo...\n"); receiveGlosa(END_FLAG, -1); //Quando a fila estiver vazia, a flag "FINALIZE" será enviada try{ @@ -180,4 +180,4 @@ void Renderer::cleanFiles() { string clean = "rm -rf "; clean.append(PATH_SCREENS).append(userID).append("/"); system(clean.c_str()); -} \ No newline at end of file +} diff --git a/servico/src/serviceWindowGenerationFromSubtitle.cpp b/servico/src/serviceWindowGenerationFromSubtitle.cpp index b785ad7..17c16af 100644 --- a/servico/src/serviceWindowGenerationFromSubtitle.cpp +++ b/servico/src/serviceWindowGenerationFromSubtitle.cpp @@ -127,7 +127,7 @@ Extrator::ExtratorType ServiceWindowGenerationFromSubtitle::getExtratorType(){ * definido pelo W3C Community Group. */ if(signature.size() < 6){ - return Extrator::SRT; + return Extrator::SRT; } if(signature.size() == 6 && strcmp(SIGNATURE, signature.c_str()) == 0){ @@ -257,7 +257,7 @@ void ServiceWindowGenerationFromSubtitle::initialize() { renderer->addListener(this); try{ - if(extrator_t == Extrator::SRT) + if(extrator_t == Extrator::SRT) extratorSRT->initialize(); else extratorVTT->initialize(); @@ -273,5 +273,5 @@ void ServiceWindowGenerationFromSubtitle::Run() { while(isRunning()){ usleep(200000); } - finish = true; -} \ No newline at end of file + finish = true; +} -- libgit2 0.21.2