Commit 54a15ec5efa5fe186ded45893d26560fa62cd01e
1 parent
a0edc914
Exists in
master
and in
1 other branch
Adicionado suporte para legenda webVTT
Showing
19 changed files
with
693 additions
and
401 deletions
Show diff stats
Makefile
... | ... | @@ -40,6 +40,7 @@ extratorOBJS = \ |
40 | 40 | extratorFactory.o \ |
41 | 41 | extratorSRT.o \ |
42 | 42 | extratorTXT.o \ |
43 | + extratorVTT.o \ | |
43 | 44 | subtitle.o |
44 | 45 | |
45 | 46 | inputOBJS = \ |
... | ... | @@ -63,7 +64,7 @@ servicoOBJS = \ |
63 | 64 | serviceException.o \ |
64 | 65 | serviceTester.o \ |
65 | 66 | serviceWindowGenerationFromRec.o \ |
66 | - serviceWindowGenerationFromSRT.o \ | |
67 | + serviceWindowGenerationFromSubtitle.o \ | |
67 | 68 | serviceWindowGenerationFromText.o |
68 | 69 | |
69 | 70 | tradutorOBJS = \ | ... | ... |
extrator/src/extratorFactory.cpp
... | ... | @@ -9,5 +9,8 @@ Extrator* ExtratorFactory::getExtrator(Extrator::ExtratorType extrator_type) { |
9 | 9 | case Extrator::TXT: |
10 | 10 | PRINTL(util::_DEBUG, "ExtratorTXT selected!\n"); |
11 | 11 | return new ExtratorTXT(); |
12 | + case Extrator::VTT: | |
13 | + PRINTL(util::_DEBUG, "ExtratorVTT selected!\n"); | |
14 | + return new ExtratorVTT(); | |
12 | 15 | } |
13 | 16 | } |
14 | 17 | \ No newline at end of file | ... | ... |
extrator/src/extratorSRT.cpp
1 | 1 | #include "extratorSRT.h" |
2 | 2 | |
3 | 3 | ExtratorSRT::ExtratorSRT(){ |
4 | - listeners = new list<ListenerSRT*>(); | |
4 | + listeners = new list<ListenerSub*>(); | |
5 | 5 | finish = false; |
6 | 6 | seek_pos = 0; |
7 | 7 | hasNextSub = true; |
... | ... | @@ -32,19 +32,19 @@ void ExtratorSRT::initialize(){ |
32 | 32 | } |
33 | 33 | |
34 | 34 | |
35 | -void ExtratorSRT::addListener(ListenerSRT* listener){ | |
35 | +void ExtratorSRT::addListener(ListenerSub* listener){ | |
36 | 36 | listeners->push_back(listener); |
37 | 37 | } |
38 | 38 | |
39 | 39 | void ExtratorSRT::notifyListeners(unsigned char* subtitle, int64_t pts) { |
40 | - for(list<ListenerSRT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
40 | + for(list<ListenerSub*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
41 | 41 | (*it)->notifySubtitle(subtitle, pts); |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | 45 | void ExtratorSRT::notifyEndExtraction(int size) { |
46 | 46 | PRINTL(util::_DEBUG, "Extrator SRT concluiu a extração: %d legendas.\n", size); |
47 | - for(list<ListenerSRT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
47 | + for(list<ListenerSub*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
48 | 48 | (*it)->notifyEnd(size); |
49 | 49 | } |
50 | 50 | } |
... | ... | @@ -136,15 +136,32 @@ Subtitle* ExtratorSRT::next() { |
136 | 136 | seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; |
137 | 137 | |
138 | 138 | } catch (lavidlib::EOFException &ex) { |
139 | - sub->setSubtitleText(text_sub); | |
139 | + sub->setSubtitleText(formatText(text_sub)); | |
140 | 140 | seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; |
141 | 141 | hasNextSub = false; |
142 | 142 | return sub; |
143 | 143 | } |
144 | - sub->setSubtitleText(text_sub); | |
144 | + sub->setSubtitleText(formatText(text_sub)); | |
145 | 145 | delete(bff_reader); |
146 | 146 | return sub; |
147 | 147 | } |
148 | + | |
149 | +string ExtratorSRT::formatText(string line){ | |
150 | + int lessThanPos; | |
151 | + int moreThanPos; | |
152 | + string f_line = line; | |
153 | + | |
154 | + lessThanPos = f_line.find_first_of(LESS_THAN); //pega a posição do simbolo '<' | |
155 | + moreThanPos = f_line.find_first_of(MORE_THAN); //pega a posição do simbolo '>' | |
156 | + | |
157 | + while(lessThanPos != string::npos && moreThanPos != string::npos){ | |
158 | + f_line = f_line.erase(lessThanPos, moreThanPos - (lessThanPos-1)); //remove o trecho '<string>' | |
159 | + lessThanPos = f_line.find_first_of(LESS_THAN); | |
160 | + moreThanPos = f_line.find_first_of(MORE_THAN); | |
161 | + } | |
162 | + | |
163 | + return f_line; | |
164 | +} | |
148 | 165 | |
149 | 166 | int64_t ExtratorSRT::str_to_time(string str_time) { |
150 | 167 | ... | ... |
... | ... | @@ -0,0 +1,148 @@ |
1 | +#include "extratorVTT.h" | |
2 | + | |
3 | +ExtratorVTT::ExtratorVTT() { | |
4 | + listeners = new list<ListenerSub*>(); | |
5 | + seekPos = 0; | |
6 | + this->finish = false; | |
7 | + hasNextCue = true; | |
8 | + PRINTL(util::_DEBUG, "ExtratorVTT Done!\n"); | |
9 | +} | |
10 | + | |
11 | +ExtratorVTT::~ExtratorVTT() { | |
12 | + listeners->clear(); | |
13 | + delete listeners; | |
14 | + if (bff_reader) delete bff_reader; | |
15 | + if (file_io) delete file_io; | |
16 | + PRINTL(util::_DEBUG, "ExtratorVTT finalized!\n"); | |
17 | +} | |
18 | + | |
19 | +void ExtratorVTT::setFilePath(char* path) { | |
20 | + this->filePath = path; | |
21 | +} | |
22 | + | |
23 | +bool ExtratorVTT::isFinished() { | |
24 | + return this->finish; | |
25 | +} | |
26 | + | |
27 | +void ExtratorVTT::addListener(ListenerSub* listener){ | |
28 | + listeners->push_back(listener); | |
29 | +} | |
30 | + | |
31 | +void ExtratorVTT::notifyListeners(unsigned char* subtitle, uint64_t pts) { | |
32 | + for(list<ListenerSub*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
33 | + (*it)->notifySubtitle(subtitle, pts); | |
34 | + } | |
35 | +} | |
36 | + | |
37 | +void ExtratorVTT::notifyEndExtraction(int size) { | |
38 | + PRINTL(util::_DEBUG, "Extrator webVTT concluiu a extração: %d legendas.\n", size); | |
39 | + for(list<ListenerSub*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
40 | + (*it)->notifyEnd(size); | |
41 | + } | |
42 | +} | |
43 | + | |
44 | +void ExtratorVTT::initialize() { | |
45 | + file = new lavidlib::File(this->filePath); | |
46 | + | |
47 | + try{ | |
48 | + file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); | |
49 | + bff_reader = new BufferedReader(file_io); | |
50 | + }catch(Exception &ex){ | |
51 | + finish = true; | |
52 | + Logging::instance()->writeLog("extratorVTT.cpp <Error>: Arquivo de legenda não encontrado."); | |
53 | + throw lavidlib::RuntimeException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.\n"); | |
54 | + } | |
55 | + this->Start(); | |
56 | +} | |
57 | + | |
58 | +Subtitle* ExtratorVTT::nextCue() { | |
59 | + string line; | |
60 | + string cueText = ""; | |
61 | + int target_pos; | |
62 | + int64_t time_in; | |
63 | + | |
64 | + Subtitle* cue = new Subtitle(); | |
65 | + | |
66 | + try{ | |
67 | + do{ | |
68 | + line = bff_reader->readLine(); | |
69 | + seekPos += line.size() + SIZE_SCAPE; | |
70 | + }while(line.find(TARGET_TIME) == string::npos); | |
71 | + | |
72 | + target_pos = line.find(TARGET_TIME); | |
73 | + time_in = str_to_time(line.substr(0, target_pos)); | |
74 | + cue->setTimeIn(time_in); | |
75 | + | |
76 | + while((line = bff_reader->readLine()) != ""){ | |
77 | + cueText += line; | |
78 | + cueText += " "; | |
79 | + } | |
80 | + | |
81 | + }catch(lavidlib::EOFException &ex){ | |
82 | + cue->setSubtitleText(formatText(cueText)); | |
83 | + seekPos += (int64_t) cueText.size() + SIZE_SCAPE; | |
84 | + hasNextCue =false; | |
85 | + return cue; | |
86 | + } | |
87 | + | |
88 | + cue->setSubtitleText(formatText(cueText)); | |
89 | + seekPos += (int64_t) cueText.size() + SIZE_SCAPE; | |
90 | + return cue; | |
91 | +} | |
92 | + | |
93 | +string ExtratorVTT::formatText(string line){ | |
94 | + int lessThanPos; | |
95 | + int moreThanPos; | |
96 | + string f_line = line; | |
97 | + | |
98 | + lessThanPos = f_line.find_first_of(LESS_THAN); //pega a posição do simbolo '<' | |
99 | + moreThanPos = f_line.find_first_of(MORE_THAN); //pega a posição do simbolo '>' | |
100 | + | |
101 | + while(lessThanPos != string::npos && moreThanPos != string::npos){ | |
102 | + f_line = f_line.erase(lessThanPos, moreThanPos - (lessThanPos-1)); //remove o trecho '<string>' | |
103 | + lessThanPos = f_line.find_first_of(LESS_THAN); | |
104 | + moreThanPos = f_line.find_first_of(MORE_THAN); | |
105 | + } | |
106 | + | |
107 | + return f_line; | |
108 | +} | |
109 | + | |
110 | +int64_t ExtratorVTT::str_to_time(string str_time) { | |
111 | + int64_t ttime = 0; | |
112 | + char* tokens = new char[4]; // hh, mm, ss, ms | |
113 | + strcpy(tokens, (char*)str_time.c_str()); | |
114 | + | |
115 | + int index = 0; | |
116 | + int values [4]; // hh, mm, ss, ms | |
117 | + char * str = strtok(tokens, ":,."); | |
118 | + while (str != NULL) { | |
119 | + values[index] = atoi(str); | |
120 | + str = strtok(NULL, ":,."); | |
121 | + index++; | |
122 | + } | |
123 | + delete(tokens); | |
124 | + | |
125 | + /* calculate time */ | |
126 | + ttime = /*hour to sec*/((((values[0] * 60) * 60) + | |
127 | + /*min to sec*/(values[1] * 60) +/*sec*/values[2])*1000) + values[3]; | |
128 | + | |
129 | + return ttime; | |
130 | +} | |
131 | + | |
132 | +void ExtratorVTT::Run() { | |
133 | + PRINTL(util::_INFO, "Extraindo Legendas...\n"); | |
134 | + | |
135 | + int sub_index = 0; | |
136 | + string cue_text = ""; | |
137 | + while(hasNextCue){ | |
138 | + subtitle = nextCue(); | |
139 | + cue_text = subtitle->getSubtitleText(); | |
140 | + notifyListeners((unsigned char*)cue_text.c_str(), (uint64_t) subtitle->getTimeIn()); | |
141 | + sub_index++; | |
142 | + free(subtitle); | |
143 | + } | |
144 | + if(sub_index == 0) | |
145 | + notifyListeners((unsigned char*)"ARQUIVO_INVALIDO", 0); | |
146 | + this->finish = true; | |
147 | + notifyEndExtraction(sub_index); | |
148 | +} | |
0 | 149 | \ No newline at end of file | ... | ... |
extrator/src/include/extrator.h
extrator/src/include/extratorFactory.h
extrator/src/include/extratorSRT.h
... | ... | @@ -16,11 +16,13 @@ |
16 | 16 | #include "jthread.h" |
17 | 17 | #include "extrator.h" |
18 | 18 | #include "subtitle.h" |
19 | -#include "listenerSRT.h" | |
19 | +#include "listenerSub.h" | |
20 | 20 | #include "extratorException.h" |
21 | 21 | |
22 | 22 | #define SIZE_CSCAPE 1 |
23 | 23 | #define TARGET_TIME "-->" |
24 | +#define LESS_THAN "<" | |
25 | +#define MORE_THAN ">" | |
24 | 26 | #define INPUT_SRT "vlibras_user/inputSRT.srt" |
25 | 27 | //#define MAX_LINE 1024 |
26 | 28 | |
... | ... | @@ -48,7 +50,7 @@ public: |
48 | 50 | * |
49 | 51 | * \param listener O ouvinte a ser registrado. |
50 | 52 | */ |
51 | - void addListener(ListenerSRT* listener); | |
53 | + void addListener(ListenerSub* listener); | |
52 | 54 | |
53 | 55 | /** Notifica os ouvintes sobre novas extrações realizadas. |
54 | 56 | * |
... | ... | @@ -98,12 +100,13 @@ public: |
98 | 100 | void Run(); |
99 | 101 | |
100 | 102 | private: |
101 | - list<ListenerSRT*> *listeners; | |
103 | + list<ListenerSub*> *listeners; | |
102 | 104 | |
103 | 105 | Subtitle *subtitle; |
104 | 106 | int64_t seek_pos; |
105 | 107 | bool hasNextSub; |
106 | - | |
108 | + | |
109 | + string formatText(string line); | |
107 | 110 | uint64_t calcula_pts(double msec); |
108 | 111 | int64_t str_to_time(std::string str_time); |
109 | 112 | }; | ... | ... |
... | ... | @@ -0,0 +1,52 @@ |
1 | +#ifndef EXTRATORVTT_H | |
2 | +#define EXTRATORVTT_H | |
3 | + | |
4 | +#include <list> | |
5 | +#include <string.h> | |
6 | +#include <stdlib.h> | |
7 | +#include <stdio.h> | |
8 | +#include "jthread.h" | |
9 | +#include "extrator.h" | |
10 | +#include "subtitle.h" | |
11 | +#include "listenerSub.h" | |
12 | +#include <iostream> | |
13 | + | |
14 | +#define SIGNATURE "WEBVTT" | |
15 | +#define TARGET_TIME "-->" | |
16 | +#define LESS_THAN "<" | |
17 | +#define MORE_THAN ">" | |
18 | +#define SIZE_SCAPE 1 | |
19 | + | |
20 | +using namespace std; | |
21 | +using namespace sndesc; | |
22 | +using namespace jthread; | |
23 | + | |
24 | +class ExtratorVTT: public Extrator, public Thread { | |
25 | + | |
26 | +public: | |
27 | + ExtratorVTT(); | |
28 | + ~ExtratorVTT(); | |
29 | + | |
30 | + void setFilePath(char* path); | |
31 | + void addListener(ListenerSub* listener); | |
32 | + | |
33 | + void initialize(); | |
34 | + bool isFinished(); | |
35 | + void Run(); | |
36 | + | |
37 | +private: | |
38 | + Subtitle* subtitle; | |
39 | + list<ListenerSub*> *listeners; | |
40 | + | |
41 | + int64_t seekPos; | |
42 | + bool hasNextCue; | |
43 | + | |
44 | + void notifyEndExtraction(int size); | |
45 | + void notifyListeners(unsigned char* subtitle, uint64_t pts); | |
46 | + | |
47 | + Subtitle* nextCue(); | |
48 | + string formatText(string line); | |
49 | + int64_t str_to_time(string str_time); | |
50 | +}; | |
51 | + | |
52 | +#endif /* EXTRATORVTT_H */ | |
0 | 53 | \ No newline at end of file | ... | ... |
extrator/src/include/listenerSRT.h
... | ... | @@ -1,17 +0,0 @@ |
1 | -/** | |
2 | - * \file listenerSRT.h | |
3 | - */ | |
4 | - | |
5 | -#ifndef LISTENERSRT_H | |
6 | -#define LISTENERSRT_H | |
7 | - | |
8 | -#include <stdint.h> | |
9 | - | |
10 | -class ListenerSRT{ | |
11 | - | |
12 | -public: | |
13 | - virtual void notifySubtitle(unsigned char* subtitle, int64_t pts) = 0; | |
14 | - virtual void notifyEnd(int sub_size) = 0; | |
15 | -}; | |
16 | - | |
17 | -#endif /* LISTENEREXTRATOR_H */ | |
18 | 0 | \ No newline at end of file |
... | ... | @@ -0,0 +1,17 @@ |
1 | +/** | |
2 | + * \file listenerSRT.h | |
3 | + */ | |
4 | + | |
5 | +#ifndef LISTENERSUB_H | |
6 | +#define LISTENERSUB_H | |
7 | + | |
8 | +#include <stdint.h> | |
9 | + | |
10 | +class ListenerSub{ | |
11 | + | |
12 | +public: | |
13 | + virtual void notifySubtitle(unsigned char* subtitle, uint64_t pts) = 0; | |
14 | + virtual void notifyEnd(int sub_size) = 0; | |
15 | +}; | |
16 | + | |
17 | +#endif /* LISTENERSUB_H */ | |
0 | 18 | \ No newline at end of file | ... | ... |
main.cpp
... | ... | @@ -18,7 +18,7 @@ |
18 | 18 | #include "argParser.h" |
19 | 19 | #include "serviceTester.h" |
20 | 20 | #include "serviceException.h" |
21 | -#include "serviceWindowGenerationFromSRT.h" | |
21 | +#include "serviceWindowGenerationFromSubtitle.h" | |
22 | 22 | #include "serviceWindowGenerationFromRec.h" |
23 | 23 | #include "serviceWindowGenerationFromText.h" |
24 | 24 | #include <lavidlib/base/RuntimeException.h> |
... | ... | @@ -184,8 +184,8 @@ void serviceSRT(int service, string path_video, string path_srt, int language, i |
184 | 184 | |
185 | 185 | setPathContents(mode, id); |
186 | 186 | |
187 | - ServiceWindowGenerationFromSRT* service_srt; | |
188 | - service_srt = new ServiceWindowGenerationFromSRT(video, srt, language, position, size, background, name, mode, service); | |
187 | + ServiceWindowGenerationFromSubtitle* service_srt; | |
188 | + service_srt = new ServiceWindowGenerationFromSubtitle(video, srt, language, position, size, background, name, mode, service); | |
189 | 189 | |
190 | 190 | try{ |
191 | 191 | service_srt->initialize(); |
... | ... | @@ -270,8 +270,8 @@ void serviceOnlySRT(int service, string path_srt, int language, int background, |
270 | 270 | |
271 | 271 | setPathContents(mode, id); |
272 | 272 | |
273 | - ServiceWindowGenerationFromSRT* service_srt; | |
274 | - service_srt = new ServiceWindowGenerationFromSRT(srt, language, background, name, mode, service); | |
273 | + ServiceWindowGenerationFromSubtitle* service_srt; | |
274 | + service_srt = new ServiceWindowGenerationFromSubtitle(srt, language, background, name, mode, service); | |
275 | 275 | try{ |
276 | 276 | service_srt->initialize(); |
277 | 277 | }catch(ServiceException ex){ | ... | ... |
renderer/src/include/renderer.h
renderer/src/renderer.cpp
... | ... | @@ -56,7 +56,7 @@ void Renderer::connectToUnityPlayer() { |
56 | 56 | i++; |
57 | 57 | sleep(1); |
58 | 58 | }catch(lavidlib::SocketException &ex){ |
59 | - if(i == 7){ // Numeros de tentativas (pode ser alterado) | |
59 | + if(i == 10){ // Numeros de tentativas (pode ser alterado) | |
60 | 60 | PRINTL(util::_ERROR, "Número de tentativas de conexão excedido!\n"); |
61 | 61 | throw lavidlib::RuntimeException(ex.getMessage().c_str()); |
62 | 62 | } |
... | ... | @@ -73,7 +73,7 @@ void Renderer::receiveGlosa(string glosa, int64_t pts) { |
73 | 73 | string formatedGlosa; //Formato da glosa que será enviada para o player: "glosa#pts" |
74 | 74 | |
75 | 75 | if(glosa == BADSENTENCE || glosa == BADTEXT) |
76 | - formatedGlosa = "_DEFAULT"; //O player entende "#pts" como pose neutra | |
76 | + formatedGlosa = ""; //O player entende "#pts" como pose neutra | |
77 | 77 | else |
78 | 78 | formatedGlosa = glosa; |
79 | 79 | |
... | ... | @@ -95,6 +95,8 @@ void Renderer::exportGlosa() { |
95 | 95 | glosaBff = new char[glosaSize]; |
96 | 96 | strcpy(glosaBff, glosaCpy.c_str()); |
97 | 97 | |
98 | + cout << "glosa: " << glosaBff << endl; | |
99 | + | |
98 | 100 | try { |
99 | 101 | cSocket->write(glosaBff, glosaSize); //Envia a glosa formatada p/ o player |
100 | 102 | }catch(lavidlib::IOException &ex){ | ... | ... |
servico/src/include/serviceTester.h
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | #include <lavidlib/io/FileIO.h> |
14 | 14 | #include "serviceException.h" |
15 | 15 | #include "serviceWindowGenerationFromRec.h" |
16 | -#include "serviceWindowGenerationFromSRT.h" | |
16 | +#include "serviceWindowGenerationFromSubtitle.h" | |
17 | 17 | #include "serviceWindowGenerationFromText.h" |
18 | 18 | |
19 | 19 | #define MODE_TEST 3 |
... | ... | @@ -69,7 +69,7 @@ private: |
69 | 69 | FileIO* fIO_out; |
70 | 70 | |
71 | 71 | ServiceWindowGenerationFromRec* service_rec; |
72 | - ServiceWindowGenerationFromSRT* service_srt; | |
72 | + ServiceWindowGenerationFromSubtitle* service_srt; | |
73 | 73 | ServiceWindowGenerationFromText* service_text; |
74 | 74 | |
75 | 75 | /** Checa o serviço de vídeo com legendas */ | ... | ... |
servico/src/include/serviceWindowGenerationFromSRT.h
... | ... | @@ -1,136 +0,0 @@ |
1 | -/** | |
2 | - * \file serviceWindowGenerationFromSRT.h | |
3 | - */ | |
4 | - | |
5 | -#ifndef SERVICEWINDOWGENERATIONFROMSRT_H | |
6 | -#define SERVICEWINDOWGENERATIONFROMSRT_H | |
7 | - | |
8 | -#include "listenerSRT.h" | |
9 | -#include "extratorFactory.h" | |
10 | -#include "serviceWindowGeneration.h" | |
11 | - | |
12 | -#define SERVICE_TYPE_SRT 1 | |
13 | -#define SERVICE_TYPE_SRT_ONLY 4 | |
14 | - | |
15 | -/** \brief Classe que implementa o serviço de extração de legendas. | |
16 | - * | |
17 | - * \headerfile servico/src/include/serviceWindowGenerationFromSRT.h | |
18 | - */ | |
19 | -class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public ListenerTradutor, public ListenerRenderer, public Thread { | |
20 | - | |
21 | -private: | |
22 | - ExtratorFactory* extrator_factory; | |
23 | - ExtratorSRT* extratorSRT; | |
24 | - | |
25 | - char* path_srt; | |
26 | - | |
27 | - /** Adiciona a etiqueta de tempo. | |
28 | - * | |
29 | - * Cada sentença conterá sua respectiva de tempo. | |
30 | - * \param pts A etiqueta de tempo. | |
31 | - */ | |
32 | - void addPTS(int64_t pts); | |
33 | - | |
34 | - /** Seta o número de legendas. | |
35 | - * | |
36 | - * \param A quantidade de legendas. | |
37 | - * \exception ServiceException Se houver algum erro durante a execução. | |
38 | - */ | |
39 | - void setSizeOfSubtitles(int sub_size); | |
40 | - | |
41 | - /** Define o path do vídeo de LIBRAS. */ | |
42 | - void setPathLibras(); | |
43 | - | |
44 | - /** Define o path dos arquivos de saída. | |
45 | - * | |
46 | - * \exception RuntimeException Se houver algum erro durante a execução. | |
47 | - */ | |
48 | - void setPathContents(); | |
49 | - | |
50 | - /** Indica se o serviço está sendo executado. | |
51 | - * | |
52 | - * \return O status do serviço. | |
53 | - */ | |
54 | - bool isRunning(); | |
55 | -public: | |
56 | - /** Construtor do serviço de vídeo com legendas. | |
57 | - * | |
58 | - * \param pathVideo Path do vídeo de entrada. | |
59 | - * \param pathSRT Path do arquivo de legendas. | |
60 | - * \param sublanguage Linguagem das legendas do arquivo. | |
61 | - * \param pos Posição do vídeo de LIBRAS em relação ao vídeo original. | |
62 | - * \param size Tamanho do vídeo de LIBRAS. | |
63 | - * \param transp Transparência do plano de fundo do vídeo. | |
64 | - * \param id Identificação do cliente. | |
65 | - * \param mode Modo de execução. | |
66 | - * \param serviceType Tipo do serviço. | |
67 | - */ | |
68 | - ServiceWindowGenerationFromSRT(char* pathVideo, char* pathSRT, int sublanguage, int pos, | |
69 | - int size, int transp, char* id, int mode, int serviceType); | |
70 | - | |
71 | - /** Construtor do serviço de legendas. | |
72 | - * | |
73 | - * \param pathSRT Path do arquivo de legendas. | |
74 | - * \param sublanguage Linguagem das legendas do arquivo. | |
75 | - * \param transparency Transparência do plano de fundo do vídeo. | |
76 | - * \param id Identificação do cliente. | |
77 | - * \param mode Modo de execução. | |
78 | - * \param serviceType Tipo do serviço. | |
79 | - */ | |
80 | - ServiceWindowGenerationFromSRT(char* pathSRT, int sublanguage, int transparency, char* id, int mode, int serviceType); | |
81 | - | |
82 | - /** Destrutor */ | |
83 | - ~ServiceWindowGenerationFromSRT(); | |
84 | - | |
85 | - /** Notifica novas legendas extraídas. | |
86 | - * | |
87 | - * \param subtitle A legenda extraída. | |
88 | - * \param pts A etiqueta de tempo da legenda. | |
89 | - */ | |
90 | - void notifySubtitle(unsigned char* subtitle, int64_t pts); | |
91 | - | |
92 | - /** Recebe a notificação do fim da renderização do vídeo */ | |
93 | - void notifyEndOfRenderization(); | |
94 | - | |
95 | - /** Recebe a notificação do fim da tradução da legenda. | |
96 | - * | |
97 | - * \param glosa A legenda traduzida. | |
98 | - */ | |
99 | - void notifyTranslation(char* glosas); | |
100 | - | |
101 | - /** Envia para a tradução a legenda obtida. | |
102 | - * | |
103 | - * \param text A legenda obtida. | |
104 | - */ | |
105 | - void notifyTranslator(unsigned char* text); | |
106 | - | |
107 | - /** Envia a glosa para o renderizador. | |
108 | - * | |
109 | - * \param glosa A glosa obtida. | |
110 | - * \exception ServiceException Se houver algum erro durante a execução. | |
111 | - */ | |
112 | - void notifyRenderer(string glosa); | |
113 | - | |
114 | - /** Notifica o fim da extração de legendas. | |
115 | - * | |
116 | - * \param sub_size O número de legendas extraídas. | |
117 | - */ | |
118 | - void notifyEnd(int sub_size); | |
119 | - | |
120 | - /** Inicia o serviço de extração de legendas. | |
121 | - * | |
122 | - * \exception ServiceException Se houver algum erro durante a execução. | |
123 | - */ | |
124 | - void initialize(); | |
125 | - | |
126 | - /** Indica o fim do processo do serviço. | |
127 | - * | |
128 | - * \return O status do processo. | |
129 | - */ | |
130 | - bool isFinished(); | |
131 | - | |
132 | - /** Este método é chamado quando a Thread for iniciada. */ | |
133 | - void Run(); | |
134 | -}; | |
135 | - | |
136 | -#endif /* SERVICEWINDOWGENERATIONFROMSRT_H_ */ | |
137 | 0 | \ No newline at end of file |
servico/src/include/serviceWindowGenerationFromSubtitle.h
0 → 100644
... | ... | @@ -0,0 +1,150 @@ |
1 | +/** | |
2 | + * \file ServiceWindowGenerationFromSubtitle.h | |
3 | + */ | |
4 | + | |
5 | +#ifndef SERVICEWINDOWGENERATIONFROMSUB_H | |
6 | +#define SERVICEWINDOWGENERATIONFROMSUB_H | |
7 | + | |
8 | +#include "listenerSub.h" | |
9 | +#include "extratorFactory.h" | |
10 | +#include "serviceWindowGeneration.h" | |
11 | +#include <lavidlib/io/File.h> | |
12 | +#include <lavidlib/io/FileIO.h> | |
13 | +#include <lavidlib/io/BufferedReader.h> | |
14 | +#include <lavidlib/io/IOException.h> | |
15 | +#include <lavidlib/io/EOFException.h> | |
16 | + | |
17 | +#define SIGNATURE "WEBVTT" | |
18 | +#define SERVICE_TYPE_SRT 1 | |
19 | +#define SERVICE_TYPE_SRT_ONLY 4 | |
20 | + | |
21 | +/** \brief Classe que implementa o serviço de extração de legendas. | |
22 | + * | |
23 | + * \headerfile servico/src/include/ServiceWindowGenerationFromSubtitle.h | |
24 | + */ | |
25 | +class ServiceWindowGenerationFromSubtitle : public ServiceWindowGeneration, public ListenerSub, public ListenerTradutor, public ListenerRenderer, public Thread { | |
26 | + | |
27 | +private: | |
28 | + char* path_srt; | |
29 | + | |
30 | + ExtratorFactory* extrator_factory; | |
31 | + ExtratorSRT* extratorSRT; | |
32 | + ExtratorVTT* extratorVTT; | |
33 | + | |
34 | + File* file; | |
35 | + FileIO* fileIO; | |
36 | + BufferedReader* bffReader; | |
37 | + | |
38 | + /** Adiciona a etiqueta de tempo. | |
39 | + * | |
40 | + * Cada sentença conterá sua respectiva de tempo. | |
41 | + * \param pts A etiqueta de tempo. | |
42 | + */ | |
43 | + void addPTS(int64_t pts); | |
44 | + | |
45 | + /** Seta o número de legendas. | |
46 | + * | |
47 | + * \param A quantidade de legendas. | |
48 | + * \exception ServiceException Se houver algum erro durante a execução. | |
49 | + */ | |
50 | + void setSizeOfSubtitles(int sub_size); | |
51 | + | |
52 | + /** Define o path do vídeo de LIBRAS. */ | |
53 | + void setPathLibras(); | |
54 | + | |
55 | + /** Define o path dos arquivos de saída. | |
56 | + * | |
57 | + * \exception RuntimeException Se houver algum erro durante a execução. | |
58 | + */ | |
59 | + void setPathContents(); | |
60 | + | |
61 | + /** Retorna o extrator espefifico do arquivo de legenda. */ | |
62 | + Extrator::ExtratorType getExtratorType(); | |
63 | + | |
64 | + /** Indica se o serviço está sendo executado. | |
65 | + * | |
66 | + * \return O status do serviço. | |
67 | + */ | |
68 | + bool isRunning(); | |
69 | +public: | |
70 | + /** Construtor do serviço de vídeo com legendas. | |
71 | + * | |
72 | + * \param pathVideo Path do vídeo de entrada. | |
73 | + * \param pathSRT Path do arquivo de legendas. | |
74 | + * \param sublanguage Linguagem das legendas do arquivo. | |
75 | + * \param pos Posição do vídeo de LIBRAS em relação ao vídeo original. | |
76 | + * \param size Tamanho do vídeo de LIBRAS. | |
77 | + * \param transp Transparência do plano de fundo do vídeo. | |
78 | + * \param id Identificação do cliente. | |
79 | + * \param mode Modo de execução. | |
80 | + * \param serviceType Tipo do serviço. | |
81 | + */ | |
82 | + ServiceWindowGenerationFromSubtitle(char* pathVideo, char* pathSRT, int sublanguage, int pos, | |
83 | + int size, int transp, char* id, int mode, int serviceType); | |
84 | + | |
85 | + /** Construtor do serviço de legendas. | |
86 | + * | |
87 | + * \param pathSRT Path do arquivo de legendas. | |
88 | + * \param sublanguage Linguagem das legendas do arquivo. | |
89 | + * \param transparency Transparência do plano de fundo do vídeo. | |
90 | + * \param id Identificação do cliente. | |
91 | + * \param mode Modo de execução. | |
92 | + * \param serviceType Tipo do serviço. | |
93 | + */ | |
94 | + ServiceWindowGenerationFromSubtitle(char* pathSRT, int sublanguage, int transparency, char* id, int mode, int serviceType); | |
95 | + | |
96 | + /** Destrutor */ | |
97 | + ~ServiceWindowGenerationFromSubtitle(); | |
98 | + | |
99 | + /** Notifica novas legendas extraídas. | |
100 | + * | |
101 | + * \param subtitle A legenda extraída. | |
102 | + * \param pts A etiqueta de tempo da legenda. | |
103 | + */ | |
104 | + void notifySubtitle(unsigned char* subtitle, uint64_t pts); | |
105 | + | |
106 | + /** Recebe a notificação do fim da renderização do vídeo */ | |
107 | + void notifyEndOfRenderization(); | |
108 | + | |
109 | + /** Recebe a notificação do fim da tradução da legenda. | |
110 | + * | |
111 | + * \param glosa A legenda traduzida. | |
112 | + */ | |
113 | + void notifyTranslation(char* glosas); | |
114 | + | |
115 | + /** Envia para a tradução a legenda obtida. | |
116 | + * | |
117 | + * \param text A legenda obtida. | |
118 | + */ | |
119 | + void notifyTranslator(unsigned char* text); | |
120 | + | |
121 | + /** Envia a glosa para o renderizador. | |
122 | + * | |
123 | + * \param glosa A glosa obtida. | |
124 | + * \exception ServiceException Se houver algum erro durante a execução. | |
125 | + */ | |
126 | + void notifyRenderer(string glosa); | |
127 | + | |
128 | + /** Notifica o fim da extração de legendas. | |
129 | + * | |
130 | + * \param sub_size O número de legendas extraídas. | |
131 | + */ | |
132 | + void notifyEnd(int sub_size); | |
133 | + | |
134 | + /** Inicia o serviço de extração de legendas. | |
135 | + * | |
136 | + * \exception ServiceException Se houver algum erro durante a execução. | |
137 | + */ | |
138 | + void initialize(); | |
139 | + | |
140 | + /** Indica o fim do processo do serviço. | |
141 | + * | |
142 | + * \return O status do processo. | |
143 | + */ | |
144 | + bool isFinished(); | |
145 | + | |
146 | + /** Este método é chamado quando a Thread for iniciada. */ | |
147 | + void Run(); | |
148 | +}; | |
149 | + | |
150 | +#endif /* SERVICEWINDOWGENERATIONFROMSUB_H_ */ | |
0 | 151 | \ No newline at end of file | ... | ... |
servico/src/serviceTester.cpp
... | ... | @@ -26,7 +26,7 @@ void ServiceTester::checkServiceSRT() { |
26 | 26 | PRINTL(util::_DEBUG, "Checando extração de legenda...\n"); |
27 | 27 | setPathContents(); |
28 | 28 | |
29 | - service_srt = new ServiceWindowGenerationFromSRT((char*)VID_FILE, (char*)SRT_FILE, 1, position, | |
29 | + service_srt = new ServiceWindowGenerationFromSubtitle((char*)VID_FILE, (char*)SRT_FILE, 1, position, | |
30 | 30 | resolution, background, (char*)TESTER_ID, MODE_TEST, 1); |
31 | 31 | |
32 | 32 | try{ | ... | ... |
servico/src/serviceWindowGenerationFromSRT.cpp
... | ... | @@ -1,223 +0,0 @@ |
1 | -#include "serviceWindowGenerationFromSRT.h" | |
2 | - | |
3 | -ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathVideo, char* pathSRT, int sublanguage, | |
4 | - int pos, int size, int transp, char* id, int mode, int serviceType) { | |
5 | - | |
6 | - this->path_input = pathVideo; | |
7 | - this->path_srt = pathSRT; | |
8 | - this->sub_language = sublanguage; | |
9 | - this->position = pos; | |
10 | - this->size = size; | |
11 | - this->transparency = transp; | |
12 | - this->user_id = id; | |
13 | - this->exec_mode = mode; | |
14 | - this->service_type = serviceType; | |
15 | - numero_legendas = INT_MAX; | |
16 | - legendas_enviadas = 0; | |
17 | - vetor_pts = new vector<int64_t >(); | |
18 | - extrator_factory = new ExtratorFactory(); | |
19 | - try{ | |
20 | - setPathContents(); | |
21 | - }catch(RuntimeException ex){ | |
22 | - throw ServiceException(ex.getMessage()); | |
23 | - } | |
24 | - running = true; | |
25 | - finish = false; | |
26 | - PRINTL(util::_DEBUG, "Service SRT Done!\n"); | |
27 | -} | |
28 | - | |
29 | -ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, int sublanguage, int transp, char* id, int mode, int serviceType) { | |
30 | - this->path_srt = pathSRT; | |
31 | - this->sub_language = sublanguage; | |
32 | - this->transparency = transp; | |
33 | - this->user_id = id; | |
34 | - this->exec_mode = mode; | |
35 | - this->service_type = serviceType; | |
36 | - numero_legendas = INT_MAX; | |
37 | - legendas_enviadas = 0; | |
38 | - vetor_pts = new vector<int64_t >(); | |
39 | - extrator_factory = new ExtratorFactory(); | |
40 | - try{ | |
41 | - setPathContents(); | |
42 | - }catch(RuntimeException ex){ | |
43 | - throw ServiceException(ex.getMessage()); | |
44 | - } | |
45 | - running = true; | |
46 | - finish = false; | |
47 | - PRINTL(util::_DEBUG, "Service SRT Done!\n"); | |
48 | -} | |
49 | - | |
50 | -ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { | |
51 | - free(vetor_pts); | |
52 | - if (tradutor) delete tradutor; | |
53 | - // if (mixer) delete mixer; | |
54 | - if (renderer) delete renderer; | |
55 | - if (extratorSRT)delete extratorSRT; | |
56 | - if (extrator_factory) delete extrator_factory; | |
57 | - PRINTL(util::_DEBUG, "Service SRT finalized!\n"); | |
58 | -} | |
59 | - | |
60 | -void ServiceWindowGenerationFromSRT::setPathContents() { | |
61 | - switch(exec_mode) { | |
62 | - case DEVELOPER: | |
63 | - { | |
64 | - char* vStorage; | |
65 | - char* vUploads; | |
66 | - vStorage = getenv("VLSTORAGE"); | |
67 | - vUploads = getenv("VLUPLOADS"); | |
68 | - | |
69 | - if(vStorage != NULL && vUploads != NULL){ | |
70 | - this->path_contents = vStorage; | |
71 | - this->path_uploads = vUploads; | |
72 | - PRINTL(util::_DEBUG, "Paths definidos pelo desenvolvedor:\n %s\n%s\n", path_contents, path_uploads); | |
73 | - }else{ | |
74 | - this->path_contents = (char*) PATH_DEVEL_CONTENTS; | |
75 | - this->path_uploads = (char*) PATH_DEVEL_UPLOADS; | |
76 | - } | |
77 | - }break; | |
78 | - | |
79 | - case PRODUCTION: | |
80 | - { | |
81 | - ifstream conf_file(PATH_CONF_FILE, ifstream::binary); | |
82 | - parsingSuccessful = reader.parse(conf_file, root); | |
83 | - | |
84 | - if(parsingSuccessful) { | |
85 | - string attr = "vlibras_user/"; | |
86 | - attr += root.get("storage", PATH_VBOX_UPLOADS).asString(); | |
87 | - this->path_contents = new char[MAX_SIZE_PATH]; | |
88 | - strcpy(this->path_contents, attr.c_str()); | |
89 | - this->path_uploads = (char*) PATH_VBOX_UPLOADS; | |
90 | - }else{ | |
91 | - conf_file.close(); | |
92 | - Logging::instance()->writeLog("Erro com a leitura do arquivo params.json"); | |
93 | - throw new RuntimeException("Fail to parsing params.json"); | |
94 | - } | |
95 | - conf_file.close(); | |
96 | - }break; | |
97 | - | |
98 | - case TESTER: | |
99 | - { | |
100 | - this->path_contents = (char*) PATH_TESTER_CONTENTS; | |
101 | - this->path_uploads = (char*) PATH_TESTER_UPLOADS; | |
102 | - }break; | |
103 | - | |
104 | - default: | |
105 | - throw ServiceException("Invalid execution mode!"); | |
106 | - } | |
107 | -} | |
108 | - | |
109 | -void ServiceWindowGenerationFromSRT::setPathLibras() { | |
110 | - string final_path = ""; | |
111 | - path_libras = new char[MAX_SIZE_PATH]; | |
112 | - | |
113 | - if(this->service_type == SERVICE_TYPE_SRT) | |
114 | - final_path.append(this->path_uploads).append("/").append(this->user_id); | |
115 | - else | |
116 | - final_path.append(this->path_contents); | |
117 | - | |
118 | - final_path.append("/").append(this->user_id).append(".mp4"); | |
119 | - strcpy(this->path_libras, final_path.c_str()); | |
120 | -} | |
121 | - | |
122 | -void ServiceWindowGenerationFromSRT::setSizeOfSubtitles(int sub_size) { | |
123 | - numero_legendas = sub_size; | |
124 | - if (legendas_enviadas >= numero_legendas){ | |
125 | - try{ | |
126 | - renderer->initialize(); | |
127 | - }catch(lavidlib::RuntimeException &ex){ | |
128 | - throw ServiceException(ex.getMessage().c_str()); | |
129 | - } | |
130 | - } | |
131 | -} | |
132 | - | |
133 | -void ServiceWindowGenerationFromSRT::addPTS(int64_t pts){ | |
134 | - vetor_pts->push_back(pts); | |
135 | -} | |
136 | - | |
137 | -void ServiceWindowGenerationFromSRT::notifyTranslator(unsigned char* subtitle) { | |
138 | - const char* constchar = (const char*) subtitle; | |
139 | - char* legenda_copy = new char[strlen(constchar)+1]; | |
140 | - strcpy(legenda_copy, constchar); | |
141 | - tradutor->traduz((unsigned char*) legenda_copy); | |
142 | - free(legenda_copy); | |
143 | -} | |
144 | - | |
145 | -void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int64_t pts){ | |
146 | - addPTS(pts); | |
147 | - if (sub_language == 1) | |
148 | - notifyTranslator(subtitle); | |
149 | - else{ | |
150 | - string glosa(reinterpret_cast<char*>(subtitle)); | |
151 | - notifyRenderer(glosa); | |
152 | - } | |
153 | -} | |
154 | - | |
155 | -void ServiceWindowGenerationFromSRT::notifyTranslation(char* glosa) { | |
156 | - string sGlosa(glosa); | |
157 | - notifyRenderer(sGlosa); | |
158 | -} | |
159 | - | |
160 | -void ServiceWindowGenerationFromSRT::notifyRenderer(string glosa) { | |
161 | - try{ | |
162 | - renderer->receiveGlosa(glosa, vetor_pts->front()); | |
163 | - legendas_enviadas++; | |
164 | - }catch(lavidlib::RuntimeException &ex){ | |
165 | - throw ServiceException(ex.getMessage().c_str()); | |
166 | - } | |
167 | - vetor_pts->erase(vetor_pts->begin()); | |
168 | -} | |
169 | - | |
170 | -void ServiceWindowGenerationFromSRT::notifyEndOfRenderization() { | |
171 | - if(this->service_type == SERVICE_TYPE_SRT){ | |
172 | - mixer = new Mixer(this->path_input, this->path_libras, this->size, this->position, | |
173 | - this->transparency, this->user_id, this->path_uploads, this->path_contents); | |
174 | - mixer->initialize(); | |
175 | - delete mixer; | |
176 | - } | |
177 | - this->running = false; | |
178 | -} | |
179 | - | |
180 | -void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { | |
181 | - PRINTL(util::_DEBUG, "Service SRT recebeu: %d legendas.\n", sub_size); | |
182 | - setSizeOfSubtitles(sub_size); | |
183 | -} | |
184 | - | |
185 | -bool ServiceWindowGenerationFromSRT::isRunning() { | |
186 | - return this->running; | |
187 | -} | |
188 | - | |
189 | -bool ServiceWindowGenerationFromSRT::isFinished() { | |
190 | - return this->finish; | |
191 | -} | |
192 | - | |
193 | -void ServiceWindowGenerationFromSRT::initialize() { | |
194 | - PRINTL(util::_DEBUG, "Service SRT Initialize.\n"); | |
195 | - setPathLibras(); | |
196 | - extratorSRT = (ExtratorSRT*) extrator_factory->getExtrator(Extrator::SRT); | |
197 | - extratorSRT->addListener(this); | |
198 | - extratorSRT->setFilePath(path_srt); | |
199 | - | |
200 | - tradutor = new TradutorPortGlosa(); | |
201 | - if (this->sub_language == 1) { | |
202 | - tradutor->addListener(this); | |
203 | - } | |
204 | - | |
205 | - renderer = new Renderer(this->path_libras ,this->user_id); | |
206 | - renderer->addListener(this); | |
207 | - | |
208 | - try{ | |
209 | - extratorSRT->initialize(); | |
210 | - }catch(ExtratorException ex){ | |
211 | - throw ServiceException(ex.getMessage()); | |
212 | - }catch(RuntimeException &ex){ | |
213 | - throw ServiceException(ex.getMessage().c_str()); | |
214 | - } | |
215 | - this->Start(); | |
216 | -} | |
217 | - | |
218 | -void ServiceWindowGenerationFromSRT::Run() { | |
219 | - while(isRunning()){ | |
220 | - usleep(200000); | |
221 | - } | |
222 | - finish = true; | |
223 | -} | |
224 | 0 | \ No newline at end of file |
... | ... | @@ -0,0 +1,276 @@ |
1 | +#include "serviceWindowGenerationFromSubtitle.h" | |
2 | + | |
3 | +ServiceWindowGenerationFromSubtitle::ServiceWindowGenerationFromSubtitle(char* pathVideo, char* pathSRT, int sublanguage, | |
4 | + int pos, int size, int transp, char* id, int mode, int serviceType) { | |
5 | + | |
6 | + this->path_input = pathVideo; | |
7 | + this->path_srt = pathSRT; | |
8 | + this->sub_language = sublanguage; | |
9 | + this->position = pos; | |
10 | + this->size = size; | |
11 | + this->transparency = transp; | |
12 | + this->user_id = id; | |
13 | + this->exec_mode = mode; | |
14 | + this->service_type = serviceType; | |
15 | + numero_legendas = INT_MAX; | |
16 | + legendas_enviadas = 0; | |
17 | + vetor_pts = new vector<int64_t >(); | |
18 | + extrator_factory = new ExtratorFactory(); | |
19 | + try{ | |
20 | + setPathContents(); | |
21 | + }catch(RuntimeException ex){ | |
22 | + throw ServiceException(ex.getMessage()); | |
23 | + } | |
24 | + running = true; | |
25 | + finish = false; | |
26 | + PRINTL(util::_DEBUG, "Service SRT Done!\n"); | |
27 | +} | |
28 | + | |
29 | +ServiceWindowGenerationFromSubtitle::ServiceWindowGenerationFromSubtitle(char* pathSRT, int sublanguage, int transp, char* id, int mode, int serviceType) { | |
30 | + this->path_srt = pathSRT; | |
31 | + this->sub_language = sublanguage; | |
32 | + this->transparency = transp; | |
33 | + this->user_id = id; | |
34 | + this->exec_mode = mode; | |
35 | + this->service_type = serviceType; | |
36 | + numero_legendas = INT_MAX; | |
37 | + legendas_enviadas = 0; | |
38 | + vetor_pts = new vector<int64_t >(); | |
39 | + extrator_factory = new ExtratorFactory(); | |
40 | + try{ | |
41 | + setPathContents(); | |
42 | + }catch(RuntimeException ex){ | |
43 | + throw ServiceException(ex.getMessage()); | |
44 | + } | |
45 | + running = true; | |
46 | + finish = false; | |
47 | + PRINTL(util::_DEBUG, "Service SRT Done!\n"); | |
48 | +} | |
49 | + | |
50 | +ServiceWindowGenerationFromSubtitle::~ServiceWindowGenerationFromSubtitle() { | |
51 | + free(vetor_pts); | |
52 | + if (tradutor) delete tradutor; | |
53 | + // if (mixer) delete mixer; | |
54 | + if (renderer) delete renderer; | |
55 | + if (extratorVTT)delete extratorVTT; | |
56 | + if (extrator_factory) delete extrator_factory; | |
57 | + PRINTL(util::_DEBUG, "Service SRT finalized!\n"); | |
58 | +} | |
59 | + | |
60 | +void ServiceWindowGenerationFromSubtitle::setPathContents() { | |
61 | + switch(exec_mode) { | |
62 | + case DEVELOPER: | |
63 | + { | |
64 | + char* vStorage; | |
65 | + char* vUploads; | |
66 | + vStorage = getenv("VLSTORAGE"); | |
67 | + vUploads = getenv("VLUPLOADS"); | |
68 | + | |
69 | + if(vStorage != NULL && vUploads != NULL){ | |
70 | + this->path_contents = vStorage; | |
71 | + this->path_uploads = vUploads; | |
72 | + PRINTL(util::_DEBUG, "Paths definidos pelo desenvolvedor:\n %s\n%s\n", path_contents, path_uploads); | |
73 | + }else{ | |
74 | + this->path_contents = (char*) PATH_DEVEL_CONTENTS; | |
75 | + this->path_uploads = (char*) PATH_DEVEL_UPLOADS; | |
76 | + } | |
77 | + }break; | |
78 | + | |
79 | + case PRODUCTION: | |
80 | + { | |
81 | + ifstream conf_file(PATH_CONF_FILE, ifstream::binary); | |
82 | + parsingSuccessful = reader.parse(conf_file, root); | |
83 | + | |
84 | + if(parsingSuccessful) { | |
85 | + string attr = "vlibras_user/"; | |
86 | + attr += root.get("storage", PATH_VBOX_UPLOADS).asString(); | |
87 | + this->path_contents = new char[MAX_SIZE_PATH]; | |
88 | + strcpy(this->path_contents, attr.c_str()); | |
89 | + this->path_uploads = (char*) PATH_VBOX_UPLOADS; | |
90 | + }else{ | |
91 | + conf_file.close(); | |
92 | + Logging::instance()->writeLog("Erro com a leitura do arquivo params.json"); | |
93 | + throw new RuntimeException("Fail to parsing params.json"); | |
94 | + } | |
95 | + conf_file.close(); | |
96 | + }break; | |
97 | + | |
98 | + case TESTER: | |
99 | + { | |
100 | + this->path_contents = (char*) PATH_TESTER_CONTENTS; | |
101 | + this->path_uploads = (char*) PATH_TESTER_UPLOADS; | |
102 | + }break; | |
103 | + | |
104 | + default: | |
105 | + throw ServiceException("Invalid execution mode!"); | |
106 | + } | |
107 | +} | |
108 | + | |
109 | +Extrator::ExtratorType ServiceWindowGenerationFromSubtitle::getExtratorType(){ | |
110 | + this->file = new lavidlib::File(this->path_srt); | |
111 | + try{ | |
112 | + this->fileIO = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); | |
113 | + this->bffReader = new BufferedReader(fileIO); | |
114 | + }catch(Exception &ex){ | |
115 | + Logging::instance()->writeLog("ServiceWindowGenerationFromSubtitle.cpp <Error>: Arquivo de legenda não encontrado."); | |
116 | + throw ServiceException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.\n"); | |
117 | + } | |
118 | + | |
119 | + string signature; | |
120 | + try{ | |
121 | + signature = bffReader->readLine(); | |
122 | + }catch(lavidlib::EOFException &ex){ | |
123 | + throw ServiceException("Arquivo sem conteúdo."); | |
124 | + } | |
125 | + | |
126 | + /* As verificações a seguir estão de acordo com o padrão | |
127 | + * definido pelo W3C Community Group. | |
128 | + */ | |
129 | + if(signature.size() < 6){ | |
130 | + return Extrator::SRT; | |
131 | + } | |
132 | + | |
133 | + if(signature.size() == 6 && strcmp(SIGNATURE, signature.c_str()) == 0){ | |
134 | + return Extrator::VTT; | |
135 | + } | |
136 | + | |
137 | + if(signature.size() > 6 && signature.find(SIGNATURE) == string::npos){ | |
138 | + return Extrator::SRT; | |
139 | + | |
140 | + }else if(!isspace(signature.at(6))){ | |
141 | + return Extrator::SRT; | |
142 | + } | |
143 | + | |
144 | + delete bffReader; | |
145 | + delete fileIO; | |
146 | + | |
147 | + return Extrator::VTT; | |
148 | +} | |
149 | + | |
150 | +void ServiceWindowGenerationFromSubtitle::setPathLibras() { | |
151 | + string final_path = ""; | |
152 | + path_libras = new char[MAX_SIZE_PATH]; | |
153 | + | |
154 | + if(this->service_type == SERVICE_TYPE_SRT) | |
155 | + final_path.append(this->path_uploads).append("/").append(this->user_id); | |
156 | + else | |
157 | + final_path.append(this->path_contents); | |
158 | + | |
159 | + final_path.append("/").append(this->user_id).append(".mp4"); | |
160 | + strcpy(this->path_libras, final_path.c_str()); | |
161 | +} | |
162 | + | |
163 | +void ServiceWindowGenerationFromSubtitle::setSizeOfSubtitles(int sub_size) { | |
164 | + numero_legendas = sub_size; | |
165 | + if (legendas_enviadas >= numero_legendas){ | |
166 | + try{ | |
167 | + renderer->initialize(); | |
168 | + }catch(lavidlib::RuntimeException &ex){ | |
169 | + throw ServiceException(ex.getMessage().c_str()); | |
170 | + } | |
171 | + } | |
172 | +} | |
173 | + | |
174 | +void ServiceWindowGenerationFromSubtitle::addPTS(int64_t pts){ | |
175 | + vetor_pts->push_back(pts); | |
176 | +} | |
177 | + | |
178 | +void ServiceWindowGenerationFromSubtitle::notifyTranslator(unsigned char* subtitle) { | |
179 | + const char* constchar = (const char*) subtitle; | |
180 | + char* legenda_copy = new char[strlen(constchar)+1]; | |
181 | + strcpy(legenda_copy, constchar); | |
182 | + tradutor->traduz((unsigned char*) legenda_copy); | |
183 | + free(legenda_copy); | |
184 | +} | |
185 | + | |
186 | +void ServiceWindowGenerationFromSubtitle::notifySubtitle(unsigned char *subtitle, uint64_t pts){ | |
187 | + addPTS(pts); | |
188 | + if (sub_language == 1) | |
189 | + notifyTranslator(subtitle); | |
190 | + else{ | |
191 | + string glosa(reinterpret_cast<char*>(subtitle)); | |
192 | + notifyRenderer(glosa); | |
193 | + } | |
194 | +} | |
195 | + | |
196 | +void ServiceWindowGenerationFromSubtitle::notifyTranslation(char* glosa) { | |
197 | + string sGlosa(glosa); | |
198 | + notifyRenderer(sGlosa); | |
199 | +} | |
200 | + | |
201 | +void ServiceWindowGenerationFromSubtitle::notifyRenderer(string glosa) { | |
202 | + try{ | |
203 | + renderer->receiveGlosa(glosa, vetor_pts->front()); | |
204 | + legendas_enviadas++; | |
205 | + }catch(lavidlib::RuntimeException &ex){ | |
206 | + throw ServiceException(ex.getMessage().c_str()); | |
207 | + } | |
208 | + vetor_pts->erase(vetor_pts->begin()); | |
209 | +} | |
210 | + | |
211 | +void ServiceWindowGenerationFromSubtitle::notifyEndOfRenderization() { | |
212 | + if(this->service_type == SERVICE_TYPE_SRT){ | |
213 | + mixer = new Mixer(this->path_input, this->path_libras, this->size, this->position, | |
214 | + this->transparency, this->user_id, this->path_uploads, this->path_contents); | |
215 | + mixer->initialize(); | |
216 | + delete mixer; | |
217 | + } | |
218 | + this->running = false; | |
219 | +} | |
220 | + | |
221 | +void ServiceWindowGenerationFromSubtitle::notifyEnd(int sub_size) { | |
222 | + PRINTL(util::_DEBUG, "Service SRT recebeu: %d legendas.\n", sub_size); | |
223 | + setSizeOfSubtitles(sub_size); | |
224 | +} | |
225 | + | |
226 | +bool ServiceWindowGenerationFromSubtitle::isRunning() { | |
227 | + return this->running; | |
228 | +} | |
229 | + | |
230 | +bool ServiceWindowGenerationFromSubtitle::isFinished() { | |
231 | + return this->finish; | |
232 | +} | |
233 | + | |
234 | +void ServiceWindowGenerationFromSubtitle::initialize() { | |
235 | + PRINTL(util::_DEBUG, "Service SRT Initialize.\n"); | |
236 | + setPathLibras(); | |
237 | + | |
238 | + Extrator::ExtratorType extrator_t = getExtratorType(); | |
239 | + | |
240 | + if(extrator_t == Extrator::SRT){ | |
241 | + extratorSRT = (ExtratorSRT*) extrator_factory->getExtrator(Extrator::SRT); | |
242 | + extratorSRT->addListener(this); | |
243 | + extratorSRT->setFilePath(path_srt); | |
244 | + }else{ | |
245 | + extratorVTT = (ExtratorVTT*) extrator_factory->getExtrator(Extrator::VTT); | |
246 | + extratorVTT->addListener(this); | |
247 | + extratorVTT->setFilePath(path_srt); | |
248 | + } | |
249 | + | |
250 | + tradutor = new TradutorPortGlosa(); | |
251 | + if (this->sub_language == 1) { | |
252 | + tradutor->addListener(this); | |
253 | + } | |
254 | + | |
255 | + renderer = new Renderer(this->path_libras ,this->user_id); | |
256 | + renderer->addListener(this); | |
257 | + | |
258 | + try{ | |
259 | + if(extrator_t == Extrator::SRT) | |
260 | + extratorSRT->initialize(); | |
261 | + else | |
262 | + extratorVTT->initialize(); | |
263 | + }catch(ExtratorException ex){ | |
264 | + throw ServiceException(ex.getMessage()); | |
265 | + }catch(RuntimeException &ex){ | |
266 | + throw ServiceException(ex.getMessage().c_str()); | |
267 | + } | |
268 | + this->Start(); | |
269 | +} | |
270 | + | |
271 | +void ServiceWindowGenerationFromSubtitle::Run() { | |
272 | + while(isRunning()){ | |
273 | + usleep(200000); | |
274 | + } | |
275 | + finish = true; | |
276 | +} | |
0 | 277 | \ No newline at end of file | ... | ... |