Commit a219d957019a4d7e4d061e038ebe3d4e52d4199e
1 parent
8023976f
Exists in
master
and in
1 other branch
Remove a verificação de arquivo já lido do ExtratorSRT
Showing
3 changed files
with
32 additions
and
35 deletions
Show diff stats
extrator/src/extratorSRT.cpp
@@ -8,8 +8,8 @@ ExtratorSRT::ExtratorSRT(){ | @@ -8,8 +8,8 @@ ExtratorSRT::ExtratorSRT(){ | ||
8 | PRINTL(util::_DEBUG, "ExtratorSTR Done!\n"); | 8 | PRINTL(util::_DEBUG, "ExtratorSTR Done!\n"); |
9 | } | 9 | } |
10 | 10 | ||
11 | -ExtratorSRT::~ExtratorSRT(){ | ||
12 | - listeners->clear(); | 11 | +ExtratorSRT::~ExtratorSRT(){ |
12 | + listeners->clear(); | ||
13 | delete listeners; | 13 | delete listeners; |
14 | //if (bff_reader) delete bff_reader; | 14 | //if (bff_reader) delete bff_reader; |
15 | if (file_io) delete file_io; | 15 | if (file_io) delete file_io; |
@@ -22,12 +22,12 @@ void ExtratorSRT::initialize(){ | @@ -22,12 +22,12 @@ void ExtratorSRT::initialize(){ | ||
22 | 22 | ||
23 | try{ | 23 | try{ |
24 | file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); | 24 | file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); |
25 | - }catch(Exception ex){ | 25 | + }catch(Exception ex){ |
26 | finish = true; | 26 | finish = true; |
27 | Logging::instance()->writeLog("extratorSRT.cpp <Error>: Arquivo de legenda não encontrado."); | 27 | Logging::instance()->writeLog("extratorSRT.cpp <Error>: Arquivo de legenda não encontrado."); |
28 | throw ExtratorException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.\n"); | 28 | throw ExtratorException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.\n"); |
29 | } | 29 | } |
30 | - | 30 | + |
31 | this->Start(); | 31 | this->Start(); |
32 | } | 32 | } |
33 | 33 | ||
@@ -39,7 +39,7 @@ void ExtratorSRT::addListener(ListenerSub* listener){ | @@ -39,7 +39,7 @@ void ExtratorSRT::addListener(ListenerSub* listener){ | ||
39 | void ExtratorSRT::notifyListeners(unsigned char* subtitle, int64_t pts) { | 39 | void ExtratorSRT::notifyListeners(unsigned char* subtitle, int64_t pts) { |
40 | for(list<ListenerSub*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | 40 | for(list<ListenerSub*>::iterator it = listeners->begin(); it != listeners->end(); it++){ |
41 | (*it)->notifySubtitle(subtitle, pts); | 41 | (*it)->notifySubtitle(subtitle, pts); |
42 | - } | 42 | + } |
43 | } | 43 | } |
44 | 44 | ||
45 | void ExtratorSRT::notifyEndExtraction(int size) { | 45 | void ExtratorSRT::notifyEndExtraction(int size) { |
@@ -50,7 +50,7 @@ void ExtratorSRT::notifyEndExtraction(int size) { | @@ -50,7 +50,7 @@ void ExtratorSRT::notifyEndExtraction(int size) { | ||
50 | } | 50 | } |
51 | 51 | ||
52 | void ExtratorSRT::setFilePath(char* path){ | 52 | void ExtratorSRT::setFilePath(char* path){ |
53 | - filePath = (char*) path; | 53 | + filePath = (char*) path; |
54 | string command1 = "perl -p -e 's/\r$//' < "; | 54 | string command1 = "perl -p -e 's/\r$//' < "; |
55 | command1.append(filePath).append(" > ").append(INPUT_SRT); | 55 | command1.append(filePath).append(" > ").append(INPUT_SRT); |
56 | system(command1.c_str()); | 56 | system(command1.c_str()); |
@@ -78,7 +78,9 @@ void ExtratorSRT::Run(){ | @@ -78,7 +78,9 @@ void ExtratorSRT::Run(){ | ||
78 | while(hasNextSubtitle()){ | 78 | while(hasNextSubtitle()){ |
79 | try{ | 79 | try{ |
80 | subtitle = next(); | 80 | subtitle = next(); |
81 | - }catch(ExtratorException ex){ break; } | 81 | + }catch(ExtratorException ex){ |
82 | + break; | ||
83 | + } | ||
82 | sub_text = subtitle->getSubtitleText(); | 84 | sub_text = subtitle->getSubtitleText(); |
83 | notifyListeners((unsigned char*)sub_text.c_str(), calcula_pts((double) subtitle->getTimeIn())); | 85 | notifyListeners((unsigned char*)sub_text.c_str(), calcula_pts((double) subtitle->getTimeIn())); |
84 | sub_index++; | 86 | sub_index++; |
@@ -91,12 +93,7 @@ void ExtratorSRT::Run(){ | @@ -91,12 +93,7 @@ void ExtratorSRT::Run(){ | ||
91 | } | 93 | } |
92 | 94 | ||
93 | Subtitle* ExtratorSRT::next() { | 95 | Subtitle* ExtratorSRT::next() { |
94 | - | ||
95 | - if (seek_pos >= file_io->getSize()){ | ||
96 | - Logging::instance()->writeLog("extratorSRT.cpp <Error>: Arquivo de legenda já foi lido."); | ||
97 | - throw ExtratorException("Esse arquivo já foi lido."); | ||
98 | - } | ||
99 | - | 96 | + |
100 | file_io->seek(seek_pos); | 97 | file_io->seek(seek_pos); |
101 | try{ | 98 | try{ |
102 | bff_reader = new BufferedReader(file_io); | 99 | bff_reader = new BufferedReader(file_io); |
@@ -106,35 +103,35 @@ Subtitle* ExtratorSRT::next() { | @@ -106,35 +103,35 @@ Subtitle* ExtratorSRT::next() { | ||
106 | } | 103 | } |
107 | 104 | ||
108 | Subtitle* sub = new Subtitle(); | 105 | Subtitle* sub = new Subtitle(); |
109 | - string line = ""; | 106 | + string line = ""; |
110 | string text_sub = ""; | 107 | string text_sub = ""; |
111 | - | 108 | + |
112 | try { | 109 | try { |
113 | /* ID */ | 110 | /* ID */ |
114 | int id = 0; | 111 | int id = 0; |
115 | line = bff_reader->readLine(); | 112 | line = bff_reader->readLine(); |
116 | seek_pos += (int64_t) line.size() + SIZE_CSCAPE; | 113 | seek_pos += (int64_t) line.size() + SIZE_CSCAPE; |
117 | - id = atoi(line.c_str()); | 114 | + id = atoi(line.c_str()); |
118 | sub->setID(id); | 115 | sub->setID(id); |
119 | 116 | ||
120 | /* TimeIn and TimeOut */ | 117 | /* TimeIn and TimeOut */ |
121 | int64_t t_in = 0, t_out = 0; | 118 | int64_t t_in = 0, t_out = 0; |
122 | line = bff_reader->readLine(); | 119 | line = bff_reader->readLine(); |
123 | seek_pos += (int64_t) line.size() + SIZE_CSCAPE; | 120 | seek_pos += (int64_t) line.size() + SIZE_CSCAPE; |
124 | - | 121 | + |
125 | int target_pos = line.find(TARGET_TIME); | 122 | int target_pos = line.find(TARGET_TIME); |
126 | t_in = str_to_time(line.substr(0, target_pos)); | 123 | t_in = str_to_time(line.substr(0, target_pos)); |
127 | sub->setTimeIn(t_in); | 124 | sub->setTimeIn(t_in); |
128 | t_out = str_to_time(line.substr(target_pos + strlen(TARGET_TIME)+1, line.size())); | 125 | t_out = str_to_time(line.substr(target_pos + strlen(TARGET_TIME)+1, line.size())); |
129 | - sub->setTimeOut(t_out); | ||
130 | - | ||
131 | - /* Text: read until line be empty */ | 126 | + sub->setTimeOut(t_out); |
127 | + | ||
128 | + /* Text: read until line be empty */ | ||
132 | while ((line = bff_reader->readLine()).size() > 0) { | 129 | while ((line = bff_reader->readLine()).size() > 0) { |
133 | text_sub += line; | 130 | text_sub += line; |
134 | - text_sub.append(" "); | 131 | + text_sub.append(" "); |
135 | } | 132 | } |
136 | seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; | 133 | seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; |
137 | - | 134 | + |
138 | } catch (lavidlib::EOFException &ex) { | 135 | } catch (lavidlib::EOFException &ex) { |
139 | sub->setSubtitleText(formatText(text_sub)); | 136 | sub->setSubtitleText(formatText(text_sub)); |
140 | seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; | 137 | seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; |
@@ -162,7 +159,7 @@ string ExtratorSRT::formatText(string line){ | @@ -162,7 +159,7 @@ string ExtratorSRT::formatText(string line){ | ||
162 | 159 | ||
163 | return f_line; | 160 | return f_line; |
164 | } | 161 | } |
165 | - | 162 | + |
166 | int64_t ExtratorSRT::str_to_time(string str_time) { | 163 | int64_t ExtratorSRT::str_to_time(string str_time) { |
167 | 164 | ||
168 | int64_t ttime = 0; | 165 | int64_t ttime = 0; |
@@ -171,7 +168,7 @@ int64_t ExtratorSRT::str_to_time(string str_time) { | @@ -171,7 +168,7 @@ int64_t ExtratorSRT::str_to_time(string str_time) { | ||
171 | 168 | ||
172 | int index = 0; | 169 | int index = 0; |
173 | int values [4]; // hh, mm, ss, ms | 170 | int values [4]; // hh, mm, ss, ms |
174 | - char * str = strtok(tokens, ":,"); | 171 | + char * str = strtok(tokens, ":,"); |
175 | while (str != NULL) { | 172 | while (str != NULL) { |
176 | values[index] = atoi(str); | 173 | values[index] = atoi(str); |
177 | str = strtok(NULL, ":,"); | 174 | str = strtok(NULL, ":,"); |
@@ -180,7 +177,7 @@ int64_t ExtratorSRT::str_to_time(string str_time) { | @@ -180,7 +177,7 @@ int64_t ExtratorSRT::str_to_time(string str_time) { | ||
180 | delete(tokens); | 177 | delete(tokens); |
181 | 178 | ||
182 | /* calculate time */ | 179 | /* calculate time */ |
183 | - ttime = /*hour to sec*/((((values[0] * 60) * 60) + | 180 | + ttime = /*hour to sec*/((((values[0] * 60) * 60) + |
184 | /*min to sec*/(values[1] * 60) +/*sec*/values[2])*1000) + values[3]; | 181 | /*min to sec*/(values[1] * 60) +/*sec*/values[2])*1000) + values[3]; |
185 | 182 | ||
186 | return ttime; | 183 | return ttime; |
@@ -188,5 +185,5 @@ int64_t ExtratorSRT::str_to_time(string str_time) { | @@ -188,5 +185,5 @@ int64_t ExtratorSRT::str_to_time(string str_time) { | ||
188 | } | 185 | } |
189 | 186 | ||
190 | uint64_t ExtratorSRT::calcula_pts(double msec) { | 187 | uint64_t ExtratorSRT::calcula_pts(double msec) { |
191 | - return (uint64_t)msec; | 188 | + return (uint64_t)msec; |
192 | } | 189 | } |
renderer/src/renderer.cpp
@@ -9,7 +9,7 @@ Renderer::Renderer(char* path_Contents, char* id) { | @@ -9,7 +9,7 @@ Renderer::Renderer(char* path_Contents, char* id) { | ||
9 | } | 9 | } |
10 | 10 | ||
11 | Renderer::~Renderer() { | 11 | Renderer::~Renderer() { |
12 | - listeners->clear(); | 12 | + listeners->clear(); |
13 | delete listeners; | 13 | delete listeners; |
14 | if(cSocket) delete cSocket; | 14 | if(cSocket) delete cSocket; |
15 | PRINTL(util::_DEBUG, "Renderer finalized!\n"); | 15 | PRINTL(util::_DEBUG, "Renderer finalized!\n"); |
@@ -60,7 +60,7 @@ void Renderer::connectToUnityPlayer() { | @@ -60,7 +60,7 @@ void Renderer::connectToUnityPlayer() { | ||
60 | PRINTL(util::_ERROR, "Número de tentativas de conexão excedido!\n"); | 60 | PRINTL(util::_ERROR, "Número de tentativas de conexão excedido!\n"); |
61 | throw lavidlib::RuntimeException(ex.getMessage().c_str()); | 61 | throw lavidlib::RuntimeException(ex.getMessage().c_str()); |
62 | } | 62 | } |
63 | - } | 63 | + } |
64 | } | 64 | } |
65 | }catch(lavidlib::UnknownHostException &ex){ | 65 | }catch(lavidlib::UnknownHostException &ex){ |
66 | throw lavidlib::RuntimeException(ex.getMessage().c_str()); | 66 | throw lavidlib::RuntimeException(ex.getMessage().c_str()); |
@@ -71,7 +71,7 @@ void Renderer::connectToUnityPlayer() { | @@ -71,7 +71,7 @@ void Renderer::connectToUnityPlayer() { | ||
71 | void Renderer::receiveGlosa(string glosa, int64_t pts) { | 71 | void Renderer::receiveGlosa(string glosa, int64_t pts) { |
72 | ostringstream oss; | 72 | ostringstream oss; |
73 | string formatedGlosa; //Formato da glosa que será enviada para o player: "glosa#pts" | 73 | string formatedGlosa; //Formato da glosa que será enviada para o player: "glosa#pts" |
74 | - | 74 | + |
75 | if(glosa == BADSENTENCE || glosa == BADTEXT) | 75 | if(glosa == BADSENTENCE || glosa == BADTEXT) |
76 | formatedGlosa = ""; //O player entende "#pts" como pose neutra | 76 | formatedGlosa = ""; //O player entende "#pts" como pose neutra |
77 | else | 77 | else |
@@ -162,7 +162,7 @@ void Renderer::Run() { | @@ -162,7 +162,7 @@ void Renderer::Run() { | ||
162 | throw lavidlib::RuntimeException(ex.getMessage().c_str()); | 162 | throw lavidlib::RuntimeException(ex.getMessage().c_str()); |
163 | } | 163 | } |
164 | } | 164 | } |
165 | - | 165 | + |
166 | PRINTL(util::_INFO, "Gerando vídeo...\n"); | 166 | PRINTL(util::_INFO, "Gerando vídeo...\n"); |
167 | receiveGlosa(END_FLAG, -1); //Quando a fila estiver vazia, a flag "FINALIZE" será enviada | 167 | receiveGlosa(END_FLAG, -1); //Quando a fila estiver vazia, a flag "FINALIZE" será enviada |
168 | try{ | 168 | try{ |
@@ -180,4 +180,4 @@ void Renderer::cleanFiles() { | @@ -180,4 +180,4 @@ void Renderer::cleanFiles() { | ||
180 | string clean = "rm -rf "; | 180 | string clean = "rm -rf "; |
181 | clean.append(PATH_SCREENS).append(userID).append("/"); | 181 | clean.append(PATH_SCREENS).append(userID).append("/"); |
182 | system(clean.c_str()); | 182 | system(clean.c_str()); |
183 | -} | ||
184 | \ No newline at end of file | 183 | \ No newline at end of file |
184 | +} |
servico/src/serviceWindowGenerationFromSubtitle.cpp
@@ -127,7 +127,7 @@ Extrator::ExtratorType ServiceWindowGenerationFromSubtitle::getExtratorType(){ | @@ -127,7 +127,7 @@ Extrator::ExtratorType ServiceWindowGenerationFromSubtitle::getExtratorType(){ | ||
127 | * definido pelo W3C Community Group. | 127 | * definido pelo W3C Community Group. |
128 | */ | 128 | */ |
129 | if(signature.size() < 6){ | 129 | if(signature.size() < 6){ |
130 | - return Extrator::SRT; | 130 | + return Extrator::SRT; |
131 | } | 131 | } |
132 | 132 | ||
133 | if(signature.size() == 6 && strcmp(SIGNATURE, signature.c_str()) == 0){ | 133 | if(signature.size() == 6 && strcmp(SIGNATURE, signature.c_str()) == 0){ |
@@ -257,7 +257,7 @@ void ServiceWindowGenerationFromSubtitle::initialize() { | @@ -257,7 +257,7 @@ void ServiceWindowGenerationFromSubtitle::initialize() { | ||
257 | renderer->addListener(this); | 257 | renderer->addListener(this); |
258 | 258 | ||
259 | try{ | 259 | try{ |
260 | - if(extrator_t == Extrator::SRT) | 260 | + if(extrator_t == Extrator::SRT) |
261 | extratorSRT->initialize(); | 261 | extratorSRT->initialize(); |
262 | else | 262 | else |
263 | extratorVTT->initialize(); | 263 | extratorVTT->initialize(); |
@@ -273,5 +273,5 @@ void ServiceWindowGenerationFromSubtitle::Run() { | @@ -273,5 +273,5 @@ void ServiceWindowGenerationFromSubtitle::Run() { | ||
273 | while(isRunning()){ | 273 | while(isRunning()){ |
274 | usleep(200000); | 274 | usleep(200000); |
275 | } | 275 | } |
276 | - finish = true; | ||
277 | -} | ||
278 | \ No newline at end of file | 276 | \ No newline at end of file |
277 | + finish = true; | ||
278 | +} |