Commit 7724541292051b57c62aad097466e0fcfbba2fee
1 parent
421fa204
Exists in
master
and in
1 other branch
Adaptado o padrão de desenvolvimento do componente servico
Showing
9 changed files
with
158 additions
and
175 deletions
Show diff stats
main.cpp
@@ -177,7 +177,7 @@ void serviceREC(char* path_video, char* sublanguage, | @@ -177,7 +177,7 @@ void serviceREC(char* path_video, char* sublanguage, | ||
177 | hasFailed(); | 177 | hasFailed(); |
178 | return; | 178 | return; |
179 | } | 179 | } |
180 | - while(service_rec->isRunning()){ | 180 | + while(!service_rec->isFinished()){ |
181 | sleep(2); | 181 | sleep(2); |
182 | } | 182 | } |
183 | delete service_rec; | 183 | delete service_rec; |
@@ -202,7 +202,7 @@ void serviceREC(char* path_video, char* sublanguage, | @@ -202,7 +202,7 @@ void serviceREC(char* path_video, char* sublanguage, | ||
202 | hasFailed(); | 202 | hasFailed(); |
203 | return; | 203 | return; |
204 | } | 204 | } |
205 | - while(service_rec->isRunning()){ | 205 | + while(!service_rec->isFinished()){ |
206 | sleep(2); | 206 | sleep(2); |
207 | } | 207 | } |
208 | delete service_rec; | 208 | delete service_rec; |
@@ -225,7 +225,7 @@ void serviceSRT(char* path_in, char* path_srt, char* sublanguage, | @@ -225,7 +225,7 @@ void serviceSRT(char* path_in, char* path_srt, char* sublanguage, | ||
225 | hasFailed(); | 225 | hasFailed(); |
226 | return; | 226 | return; |
227 | } | 227 | } |
228 | - while(service_srt->isRunning()){ | 228 | + while(!service_srt->isFinished()){ |
229 | sleep(5); | 229 | sleep(5); |
230 | } | 230 | } |
231 | 231 | ||
@@ -246,7 +246,7 @@ void serviceText(char* path_text, char* transparency, char* id, char* client_typ | @@ -246,7 +246,7 @@ void serviceText(char* path_text, char* transparency, char* id, char* client_typ | ||
246 | return; | 246 | return; |
247 | } | 247 | } |
248 | 248 | ||
249 | - while (service_text->isAlive()) { | 249 | + while (!service_text->isFinished()) { |
250 | usleep(100000); //100ms | 250 | usleep(100000); //100ms |
251 | } | 251 | } |
252 | delete service_text; | 252 | delete service_text; |
@@ -263,7 +263,7 @@ void serviceText(char* path_text, char* transparency, char* id, char* client_typ | @@ -263,7 +263,7 @@ void serviceText(char* path_text, char* transparency, char* id, char* client_typ | ||
263 | return; | 263 | return; |
264 | } | 264 | } |
265 | 265 | ||
266 | - while (service_text->isAlive()) { | 266 | + while (!service_text->isFinished()) { |
267 | usleep(100000); //100ms | 267 | usleep(100000); //100ms |
268 | } | 268 | } |
269 | delete service_text; | 269 | delete service_text; |
@@ -273,7 +273,6 @@ void serviceText(char* path_text, char* transparency, char* id, char* client_typ | @@ -273,7 +273,6 @@ void serviceText(char* path_text, char* transparency, char* id, char* client_typ | ||
273 | 273 | ||
274 | void serviceOnlySRT(char* path_file, char* transparency, char* id){ | 274 | void serviceOnlySRT(char* path_file, char* transparency, char* id){ |
275 | 275 | ||
276 | - | ||
277 | ServiceWindowGenerationFromSRT * service_srt; | 276 | ServiceWindowGenerationFromSRT * service_srt; |
278 | service_srt = new ServiceWindowGenerationFromSRT(path_file, (int) atoi(transparency), id, 5); | 277 | service_srt = new ServiceWindowGenerationFromSRT(path_file, (int) atoi(transparency), id, 5); |
279 | try{ | 278 | try{ |
@@ -284,7 +283,7 @@ void serviceOnlySRT(char* path_file, char* transparency, char* id){ | @@ -284,7 +283,7 @@ void serviceOnlySRT(char* path_file, char* transparency, char* id){ | ||
284 | return; | 283 | return; |
285 | } | 284 | } |
286 | 285 | ||
287 | - while (!service_srt->finished()) { | 286 | + while (!service_srt->isFinished()) { |
288 | usleep(100000); //100ms | 287 | usleep(100000); //100ms |
289 | } | 288 | } |
290 | delete service_srt; | 289 | delete service_srt; |
@@ -309,7 +308,7 @@ void serviceOnlyAudio(char* path_audio, char* transparency, char* id, char* rate | @@ -309,7 +308,7 @@ void serviceOnlyAudio(char* path_audio, char* transparency, char* id, char* rate | ||
309 | hasFailed(); | 308 | hasFailed(); |
310 | return; | 309 | return; |
311 | } | 310 | } |
312 | - while(service_rec->isRunning()){ | 311 | + while(!service_rec->isFinished()){ |
313 | sleep(2); | 312 | sleep(2); |
314 | } | 313 | } |
315 | delete service_rec; | 314 | delete service_rec; |
@@ -333,7 +332,7 @@ void serviceOnlyAudio(char* path_audio, char* transparency, char* id){ | @@ -333,7 +332,7 @@ void serviceOnlyAudio(char* path_audio, char* transparency, char* id){ | ||
333 | hasFailed(); | 332 | hasFailed(); |
334 | return; | 333 | return; |
335 | } | 334 | } |
336 | - while(service_rec->isRunning()){ | 335 | + while(!service_rec->isFinished()){ |
337 | sleep(2); | 336 | sleep(2); |
338 | } | 337 | } |
339 | delete service_rec; | 338 | delete service_rec; |
@@ -357,12 +356,12 @@ void hasInvalid(){ | @@ -357,12 +356,12 @@ void hasInvalid(){ | ||
357 | //Help do programa, explicando todos os parâmetros existentes... | 356 | //Help do programa, explicando todos os parâmetros existentes... |
358 | void help() { | 357 | void help() { |
359 | cout <<"\n##################################################################################\n" | 358 | cout <<"\n##################################################################################\n" |
360 | - <<"# SERVICE_TYPE: 1 - means Closed Caption - doesn't use INPUT_SRT #\n" | ||
361 | - <<"# 2 - means With Subtitles (SRT) - requires INPUT_SRT #\n" | ||
362 | - <<"# 3 - means Recognize - requires INPUT_VIDEO #\n" | 359 | + <<"# SERVICE_TYPE: 1 - means Closed Caption - doesn't use INPUT_SRT #\n" |
360 | + <<"# 2 - means With Subtitles (SRT) - requires INPUT_SRT #\n" | ||
361 | + <<"# 3 - means Recognize - requires INPUT_VIDEO #\n" | ||
363 | <<"# 4 - means Text - requires INPUT_FILE_TEXT #\n" | 362 | <<"# 4 - means Text - requires INPUT_FILE_TEXT #\n" |
364 | - <<"# 5 - means Subtitles ONLY (SRT) - requires INPUT_SRT #\n" | ||
365 | - <<"# 6 - means Audio - requires INPUT_AUDIO #\n" | 363 | + <<"# 5 - means Subtitles ONLY (SRT) - requires INPUT_SRT #\n" |
364 | + <<"# 6 - means Audio - requires INPUT_AUDIO #\n" | ||
366 | <<"####################################################################################\n\n" | 365 | <<"####################################################################################\n\n" |
367 | /*<<"# INPUT_VIDEO: Path of the video file #\n" | 366 | /*<<"# INPUT_VIDEO: Path of the video file #\n" |
368 | <<"#----------------------------------------------------------------------------------#\n" | 367 | <<"#----------------------------------------------------------------------------------#\n" |
servico/src/include/serviceWindowGeneration.h
@@ -57,12 +57,10 @@ protected: | @@ -57,12 +57,10 @@ protected: | ||
57 | char* path_audio; | 57 | char* path_audio; |
58 | char* path_libras; | 58 | char* path_libras; |
59 | char* client_type; | 59 | char* client_type; |
60 | - | ||
61 | - bool running; | ||
62 | - | ||
63 | - bool finish; | ||
64 | char* user_id; | 60 | char* user_id; |
65 | 61 | ||
62 | + bool running; | ||
63 | + | ||
66 | int size, position, transparency, sublanguage, serviceType, numero_legendas, legendas_enviadas; | 64 | int size, position, transparency, sublanguage, serviceType, numero_legendas, legendas_enviadas; |
67 | 65 | ||
68 | void setSize(int); | 66 | void setSize(int); |
@@ -82,12 +80,12 @@ public: | @@ -82,12 +80,12 @@ public: | ||
82 | 80 | ||
83 | ServiceWindowGeneration(); | 81 | ServiceWindowGeneration(); |
84 | ~ServiceWindowGeneration(); | 82 | ~ServiceWindowGeneration(); |
83 | + | ||
85 | virtual void notifyTranslation(vector<string>* glosas); | 84 | virtual void notifyTranslation(vector<string>* glosas); |
86 | virtual void notifyEndOfSynchronization(); | 85 | virtual void notifyEndOfSynchronization(); |
87 | //virtual void notifyPCRBase(uint64_t pcr_base); | 86 | //virtual void notifyPCRBase(uint64_t pcr_base); |
87 | + | ||
88 | void initialize(); | 88 | void initialize(); |
89 | - TradutorPortGlosa * getTradutor(); | ||
90 | - void adicionaPTS(int64_t pts); | ||
91 | bool isRunning(); | 89 | bool isRunning(); |
92 | 90 | ||
93 | char* getPathLibras(); | 91 | char* getPathLibras(); |
@@ -95,8 +93,11 @@ public: | @@ -95,8 +93,11 @@ public: | ||
95 | char* getClientType(); | 93 | char* getClientType(); |
96 | char* getPathInput(); | 94 | char* getPathInput(); |
97 | string getPathAPI(); | 95 | string getPathAPI(); |
96 | + TradutorPortGlosa * getTradutor(); | ||
97 | + | ||
98 | void setPathLibras(); | 98 | void setPathLibras(); |
99 | void setSizeOfSubtitles(int sub_size); | 99 | void setSizeOfSubtitles(int sub_size); |
100 | + void adicionaPTS(int64_t pts); | ||
100 | }; | 101 | }; |
101 | 102 | ||
102 | #endif /* SERVICEWINDOWGENERATION_H */ | 103 | #endif /* SERVICEWINDOWGENERATION_H */ |
servico/src/include/serviceWindowGenerationFromREC.h
@@ -16,25 +16,21 @@ class ServiceWindowGenerationFromREC : public ServiceWindowGeneration, public Re | @@ -16,25 +16,21 @@ class ServiceWindowGenerationFromREC : public ServiceWindowGeneration, public Re | ||
16 | 16 | ||
17 | private: | 17 | private: |
18 | Recognize *rec; | 18 | Recognize *rec; |
19 | + bool finish; | ||
19 | 20 | ||
20 | public: | 21 | public: |
21 | 22 | ||
22 | ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType, char* rate); | 23 | ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType, char* rate); |
23 | - | ||
24 | ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType); | 24 | ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType); |
25 | - | ||
26 | ~ServiceWindowGenerationFromREC(); | 25 | ~ServiceWindowGenerationFromREC(); |
27 | - void initialize(); | ||
28 | - | 26 | + |
29 | virtual void notifyTextRecognized(unsigned char* text, int64_t pts); | 27 | virtual void notifyTextRecognized(unsigned char* text, int64_t pts); |
30 | virtual void notifyEnd(int sentences_size); | 28 | virtual void notifyEnd(int sentences_size); |
31 | - | ||
32 | - | ||
33 | void notifyTranslator(unsigned char *text); | 29 | void notifyTranslator(unsigned char *text); |
34 | - void notifySynchWithoutTranslator(unsigned char *text, int64_t pts); | ||
35 | - | 30 | + |
31 | + void initialize(); | ||
32 | + bool isFinished(); | ||
36 | void Run(); | 33 | void Run(); |
37 | - | ||
38 | }; | 34 | }; |
39 | 35 | ||
40 | #endif /* SERVICEWINDOWGENERATIONFROMREC_H */ | 36 | #endif /* SERVICEWINDOWGENERATIONFROMREC_H */ |
servico/src/include/serviceWindowGenerationFromSRT.h
@@ -21,33 +21,27 @@ private: | @@ -21,33 +21,27 @@ private: | ||
21 | pthread_mutex_t *mutex_serviceSRT; | 21 | pthread_mutex_t *mutex_serviceSRT; |
22 | ExtratorSRT * extratorSRT; | 22 | ExtratorSRT * extratorSRT; |
23 | char* path_srt; | 23 | char* path_srt; |
24 | - bool finish_srt; | 24 | + bool finish; |
25 | 25 | ||
26 | public: | 26 | public: |
27 | 27 | ||
28 | /* Construtor 1 - legenda e vídeo */ | 28 | /* Construtor 1 - legenda e vídeo */ |
29 | - ServiceWindowGenerationFromSRT( | ||
30 | - char* path_video, char* path_srt, int sublanguage, | 29 | + ServiceWindowGenerationFromSRT(char* path_video, char* path_srt, int sublanguage, |
31 | int position, int size, int transparency, char* id, int _serviceType); | 30 | int position, int size, int transparency, char* id, int _serviceType); |
32 | - | ||
33 | /* Construtor 2 - só legenda */ | 31 | /* Construtor 2 - só legenda */ |
34 | ServiceWindowGenerationFromSRT(char* path_srt, int transparency, char* id, int _serviceType); | 32 | ServiceWindowGenerationFromSRT(char* path_srt, int transparency, char* id, int _serviceType); |
35 | - | ||
36 | - /* Destrutor */ | ||
37 | ~ServiceWindowGenerationFromSRT(); | 33 | ~ServiceWindowGenerationFromSRT(); |
38 | 34 | ||
39 | virtual void notifySubtitle(unsigned char* subtitle, int64_t pts); | 35 | virtual void notifySubtitle(unsigned char* subtitle, int64_t pts); |
40 | virtual void notifyEnd(int sub_size); | 36 | virtual void notifyEnd(int sub_size); |
41 | - | ||
42 | - void notificaTradutor(unsigned char *legenda); | ||
43 | - | ||
44 | - bool finished(); | 37 | + void notifyTranslator(unsigned char* subtitle); |
45 | 38 | ||
46 | - void notificaSincronizadorSemTradutor(unsigned char *legenda, int64_t pts); | ||
47 | void initialize(); | 39 | void initialize(); |
48 | - void setPathSRT(char* path_srt); | 40 | + bool isFinished(); |
49 | void Run(); | 41 | void Run(); |
50 | 42 | ||
43 | + void setPathSRT(char* path_srt); | ||
44 | + | ||
51 | }; | 45 | }; |
52 | 46 | ||
53 | #endif /* SERVICEWINDOWGENERATIONFROMSRT_H */ | 47 | #endif /* SERVICEWINDOWGENERATIONFROMSRT_H */ |
servico/src/include/serviceWindowGenerationFromText.h
@@ -12,17 +12,19 @@ | @@ -12,17 +12,19 @@ | ||
12 | class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public Thread { | 12 | class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public Thread { |
13 | 13 | ||
14 | private: | 14 | private: |
15 | - ExtratorTXT * extratorTXT; | ||
16 | - bool alive; | 15 | + ExtratorTXT * extratorTXT; |
16 | + bool finish; | ||
17 | 17 | ||
18 | public: | 18 | public: |
19 | ServiceWindowGenerationFromText (char* _path_file, char* _video_path_file, | 19 | ServiceWindowGenerationFromText (char* _path_file, char* _video_path_file, |
20 | int _transp, int _serviceType, char* _client_type); | 20 | int _transp, int _serviceType, char* _client_type); |
21 | ~ServiceWindowGenerationFromText (); | 21 | ~ServiceWindowGenerationFromText (); |
22 | + | ||
22 | void notifyLine(unsigned char* line); | 23 | void notifyLine(unsigned char* line); |
23 | void notifyEnd(int line_size); | 24 | void notifyEnd(int line_size); |
25 | + | ||
24 | void initialize(); | 26 | void initialize(); |
25 | - bool isAlive(); | 27 | + bool isFinished(); |
26 | void Run(); | 28 | void Run(); |
27 | }; | 29 | }; |
28 | 30 |
servico/src/serviceWindowGeneration.cpp
@@ -20,57 +20,13 @@ ServiceWindowGeneration::~ServiceWindowGeneration() { | @@ -20,57 +20,13 @@ ServiceWindowGeneration::~ServiceWindowGeneration() { | ||
20 | if (mixer) delete mixer; | 20 | if (mixer) delete mixer; |
21 | if (tradutor) delete tradutor; | 21 | if (tradutor) delete tradutor; |
22 | if (sincronizador) delete sincronizador; | 22 | if (sincronizador) delete sincronizador; |
23 | - | ||
24 | DDDPRINTF("Service finalized!\n"); | 23 | DDDPRINTF("Service finalized!\n"); |
25 | - | ||
26 | -} | ||
27 | - | ||
28 | -void ServiceWindowGeneration::adicionaPTS(int64_t pts) { | ||
29 | - vetor_pts->push_back(pts); | ||
30 | -} | ||
31 | - | ||
32 | -/* Checado pela subclasse para saber quando o sincronizador terminar. */ | ||
33 | -bool ServiceWindowGeneration::isRunning() { | ||
34 | - return this->running; | ||
35 | -} | ||
36 | - | ||
37 | -/* Quando o sincronizador termina, ele invoca esse método para avisar! */ | ||
38 | -void ServiceWindowGeneration::notifyEndOfSynchronization() { | ||
39 | - if (serviceType == SERVICE_TYPE_REC || serviceType == SERVICE_TYPE_SRT) { | ||
40 | - mixer = new Mixer(); | ||
41 | - mixer->initialize(this->path_input, this->path_libras,this->position,this->size,this->transparency, this->user_id); | ||
42 | - createThumbnail(); | ||
43 | - }else | ||
44 | - transcodeVideoToMp4(); | ||
45 | - this->running = false; | ||
46 | - | ||
47 | -} | ||
48 | - | ||
49 | -void ServiceWindowGeneration::setSizeOfSubtitles(int sub_size) { | ||
50 | - numero_legendas = sub_size; | ||
51 | - if (legendas_enviadas >= numero_legendas) { | ||
52 | - sincronizador->stop(); | ||
53 | - } | ||
54 | -} | ||
55 | - | ||
56 | -void ServiceWindowGeneration::setPathLibras() { | ||
57 | - char* final_path = new char[MAX_SIZE_PATH]; | ||
58 | - strcpy(final_path, "vlibras_user/vlibras-api/uploads/"); | ||
59 | - strcat(final_path, this->user_id); | ||
60 | - strcat(final_path, "/libras.ts"); | ||
61 | - | ||
62 | - this->path_libras = final_path; | ||
63 | - //DDPRINTF("Path TS File: %s\n", this->path_libras); | ||
64 | } | 24 | } |
65 | 25 | ||
66 | char* ServiceWindowGeneration::getPathLibras() { | 26 | char* ServiceWindowGeneration::getPathLibras() { |
67 | return path_libras; | 27 | return path_libras; |
68 | } | 28 | } |
69 | 29 | ||
70 | -void ServiceWindowGeneration::setPathInput(char* _path_input) { | ||
71 | - this->path_input = _path_input; | ||
72 | -} | ||
73 | - | ||
74 | char* ServiceWindowGeneration::getPathInput() { | 30 | char* ServiceWindowGeneration::getPathInput() { |
75 | return path_input; | 31 | return path_input; |
76 | } | 32 | } |
@@ -79,10 +35,6 @@ string ServiceWindowGeneration::getPathAPI() { | @@ -79,10 +35,6 @@ string ServiceWindowGeneration::getPathAPI() { | ||
79 | return PATH_API; | 35 | return PATH_API; |
80 | } | 36 | } |
81 | 37 | ||
82 | -void ServiceWindowGeneration::setUserId(char* _userId) { | ||
83 | - this->user_id = _userId; | ||
84 | -} | ||
85 | - | ||
86 | char* ServiceWindowGeneration::getClientType(){ | 38 | char* ServiceWindowGeneration::getClientType(){ |
87 | return client_type; | 39 | return client_type; |
88 | } | 40 | } |
@@ -91,14 +43,26 @@ char* ServiceWindowGeneration::getUserId() { | @@ -91,14 +43,26 @@ char* ServiceWindowGeneration::getUserId() { | ||
91 | return user_id; | 43 | return user_id; |
92 | } | 44 | } |
93 | 45 | ||
94 | -void ServiceWindowGeneration::setServiceType(int type) { | ||
95 | - serviceType = type; | 46 | +void ServiceWindowGeneration::setPathInput(char* _path_input) { |
47 | + this->path_input = _path_input; | ||
96 | } | 48 | } |
97 | 49 | ||
98 | void ServiceWindowGeneration::setClientType(char* client_type) { | 50 | void ServiceWindowGeneration::setClientType(char* client_type) { |
99 | this->client_type = client_type; | 51 | this->client_type = client_type; |
100 | } | 52 | } |
101 | 53 | ||
54 | +void ServiceWindowGeneration::setUserId(char* _userId) { | ||
55 | + this->user_id = _userId; | ||
56 | +} | ||
57 | + | ||
58 | +void ServiceWindowGeneration::setServiceType(int type) { | ||
59 | + serviceType = type; | ||
60 | +} | ||
61 | + | ||
62 | +void ServiceWindowGeneration::setSubLanguage(int sublang){ | ||
63 | + this->sublanguage = sublang; | ||
64 | +} | ||
65 | + | ||
102 | void ServiceWindowGeneration::setSize(int size){ | 66 | void ServiceWindowGeneration::setSize(int size){ |
103 | this->size = size; | 67 | this->size = size; |
104 | } | 68 | } |
@@ -111,15 +75,47 @@ void ServiceWindowGeneration::setTransparency(int transparency){ | @@ -111,15 +75,47 @@ void ServiceWindowGeneration::setTransparency(int transparency){ | ||
111 | this->transparency = transparency; | 75 | this->transparency = transparency; |
112 | } | 76 | } |
113 | 77 | ||
114 | -void ServiceWindowGeneration::setSubLanguage(int sublang){ | ||
115 | - this->sublanguage = sublang; | 78 | +void ServiceWindowGeneration::setPathLibras() { |
79 | + char* final_path = new char[MAX_SIZE_PATH]; | ||
80 | + strcpy(final_path, "vlibras_user/vlibras-api/uploads/"); | ||
81 | + strcat(final_path, this->user_id); | ||
82 | + strcat(final_path, "/libras.ts"); | ||
83 | + | ||
84 | + this->path_libras = final_path; | ||
85 | + //DDPRINTF("Path TS File: %s\n", this->path_libras); | ||
86 | +} | ||
87 | + | ||
88 | +void ServiceWindowGeneration::setSizeOfSubtitles(int sub_size) { | ||
89 | + numero_legendas = sub_size; | ||
90 | + if (legendas_enviadas >= numero_legendas) | ||
91 | + sincronizador->stop(); | ||
92 | +} | ||
93 | + | ||
94 | +void ServiceWindowGeneration::adicionaPTS(int64_t pts) { | ||
95 | + vetor_pts->push_back(pts); | ||
96 | +} | ||
97 | + | ||
98 | +/* Checado pela subclasse para saber quando o sincronizador terminar. */ | ||
99 | +bool ServiceWindowGeneration::isRunning() { | ||
100 | + return this->running; | ||
101 | +} | ||
102 | + | ||
103 | +/* Quando o sincronizador termina, ele invoca esse método para avisar! */ | ||
104 | +void ServiceWindowGeneration::notifyEndOfSynchronization() { | ||
105 | + if (serviceType == SERVICE_TYPE_REC || serviceType == SERVICE_TYPE_SRT) { | ||
106 | + mixer = new Mixer(); | ||
107 | + mixer->initialize(this->path_input, this->path_libras,this->position,this->size,this->transparency, this->user_id); | ||
108 | + createThumbnail(); | ||
109 | + }else{ | ||
110 | + transcodeVideoToMp4(); | ||
111 | + } | ||
112 | + this->running = false; | ||
116 | } | 113 | } |
117 | 114 | ||
118 | void ServiceWindowGeneration::initialize() { | 115 | void ServiceWindowGeneration::initialize() { |
119 | 116 | ||
120 | setPathLibras(); | 117 | setPathLibras(); |
121 | 118 | ||
122 | - this->finish = false; | ||
123 | if (this->sublanguage == 1) { | 119 | if (this->sublanguage == 1) { |
124 | tradutor->addListener(this); | 120 | tradutor->addListener(this); |
125 | } | 121 | } |
servico/src/serviceWindowGenerationFromREC.cpp
@@ -11,6 +11,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( | @@ -11,6 +11,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( | ||
11 | setServiceType(serviceType); | 11 | setServiceType(serviceType); |
12 | setUserId(id); | 12 | setUserId(id); |
13 | rec = new Recognize(path_video, id, rate); | 13 | rec = new Recognize(path_video, id, rate); |
14 | + finish = false; | ||
14 | DPRINTF("Done!\n"); | 15 | DPRINTF("Done!\n"); |
15 | } | 16 | } |
16 | 17 | ||
@@ -25,6 +26,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( | @@ -25,6 +26,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( | ||
25 | setServiceType(serviceType); | 26 | setServiceType(serviceType); |
26 | setUserId(id); | 27 | setUserId(id); |
27 | rec = new Recognize(path_video, id); | 28 | rec = new Recognize(path_video, id); |
29 | + finish = false; | ||
28 | DPRINTF("Done!\n"); | 30 | DPRINTF("Done!\n"); |
29 | } | 31 | } |
30 | 32 | ||
@@ -33,6 +35,24 @@ ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() { | @@ -33,6 +35,24 @@ ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() { | ||
33 | DDDPRINTF("Service REC finished!\n"); | 35 | DDDPRINTF("Service REC finished!\n"); |
34 | } | 36 | } |
35 | 37 | ||
38 | +void ServiceWindowGenerationFromREC::notifyTranslator(unsigned char *text) { | ||
39 | + tradutor->traduz(text); | ||
40 | +} | ||
41 | + | ||
42 | +void ServiceWindowGenerationFromREC::notifyTextRecognized(unsigned char* text, int64_t pts) { | ||
43 | + adicionaPTS(pts); | ||
44 | + notifyTranslator(text); | ||
45 | +} | ||
46 | + | ||
47 | +bool ServiceWindowGenerationFromREC::isFinished(){ | ||
48 | + return finish; | ||
49 | +} | ||
50 | + | ||
51 | +void ServiceWindowGenerationFromREC::notifyEnd(int sentences_size) { | ||
52 | + DDPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); | ||
53 | + setSizeOfSubtitles(sentences_size); | ||
54 | +} | ||
55 | + | ||
36 | void ServiceWindowGenerationFromREC::initialize() { | 56 | void ServiceWindowGenerationFromREC::initialize() { |
37 | 57 | ||
38 | rec->addListener(this); | 58 | rec->addListener(this); |
@@ -67,23 +87,10 @@ void ServiceWindowGenerationFromREC::initialize() { | @@ -67,23 +87,10 @@ void ServiceWindowGenerationFromREC::initialize() { | ||
67 | this->Start(); | 87 | this->Start(); |
68 | } | 88 | } |
69 | 89 | ||
70 | -void ServiceWindowGenerationFromREC::notifyTextRecognized(unsigned char* text, int64_t pts) { | ||
71 | - adicionaPTS(pts); | ||
72 | - notifyTranslator(text); | ||
73 | -} | ||
74 | - | ||
75 | -void ServiceWindowGenerationFromREC::notifyTranslator(unsigned char *text) { | ||
76 | - tradutor->traduz(text); | ||
77 | -} | ||
78 | - | ||
79 | -void ServiceWindowGenerationFromREC::notifyEnd(int sentences_size) { | ||
80 | - DDPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); | ||
81 | - setSizeOfSubtitles(sentences_size); | ||
82 | -} | ||
83 | - | ||
84 | void ServiceWindowGenerationFromREC::Run() { | 90 | void ServiceWindowGenerationFromREC::Run() { |
85 | 91 | ||
86 | - while (!rec->isFinished()) { | ||
87 | - sleep(200000); | 92 | + while (isRunning()) { |
93 | + usleep(200000); | ||
88 | } | 94 | } |
95 | + finish = true; | ||
89 | } | 96 | } |
servico/src/serviceWindowGenerationFromSRT.cpp
@@ -12,7 +12,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT( | @@ -12,7 +12,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT( | ||
12 | setSubLanguage(sublanguage); | 12 | setSubLanguage(sublanguage); |
13 | setServiceType(serviceType); | 13 | setServiceType(serviceType); |
14 | setUserId(id); | 14 | setUserId(id); |
15 | - this->finish = false; | 15 | + finish = false; |
16 | DPRINTF("Done!\n"); | 16 | DPRINTF("Done!\n"); |
17 | } | 17 | } |
18 | 18 | ||
@@ -22,7 +22,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* path_srt, i | @@ -22,7 +22,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* path_srt, i | ||
22 | setTransparency(transparency); | 22 | setTransparency(transparency); |
23 | setServiceType(serviceType); | 23 | setServiceType(serviceType); |
24 | setUserId(id); | 24 | setUserId(id); |
25 | - finish_srt = false; | 25 | + finish = false; |
26 | DPRINTF("Done!\n"); | 26 | DPRINTF("Done!\n"); |
27 | } | 27 | } |
28 | 28 | ||
@@ -32,29 +32,31 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { | @@ -32,29 +32,31 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { | ||
32 | DDDPRINTF("Service SRT finalized!\n"); | 32 | DDDPRINTF("Service SRT finalized!\n"); |
33 | } | 33 | } |
34 | 34 | ||
35 | -void ServiceWindowGenerationFromSRT::setPathSRT(char* path_srt) { | ||
36 | - this->path_srt = path_srt; | ||
37 | -} | 35 | +void ServiceWindowGenerationFromSRT::notifyTranslator(unsigned char* subtitle) { |
38 | 36 | ||
39 | -void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { | ||
40 | - DDPRINTF("Service SRT recebeu: %d legendas.\n", sub_size); | ||
41 | - setSizeOfSubtitles(sub_size); | 37 | + const char* constchar = (const char*) subtitle; |
38 | + char* legenda_copy = new char[strlen(constchar)+1]; | ||
39 | + strcpy(legenda_copy, constchar); | ||
40 | + tradutor->traduz((unsigned char*) legenda_copy); | ||
41 | + free(legenda_copy); | ||
42 | } | 42 | } |
43 | 43 | ||
44 | - | ||
45 | -void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *legenda, int64_t pts){ | 44 | +void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int64_t pts){ |
46 | adicionaPTS(pts); | 45 | adicionaPTS(pts); |
47 | - notificaTradutor(legenda); | ||
48 | - | 46 | + notifyTranslator(subtitle); |
49 | } | 47 | } |
50 | 48 | ||
51 | -void ServiceWindowGenerationFromSRT::notificaTradutor(unsigned char* legenda) { | 49 | +bool ServiceWindowGenerationFromSRT::isFinished(){ |
50 | + return finish; | ||
51 | +} | ||
52 | 52 | ||
53 | - const char* constchar = (const char*) legenda; | ||
54 | - char* legenda_copy = new char[strlen(constchar)+1]; | ||
55 | - strcpy(legenda_copy, constchar); | ||
56 | - tradutor->traduz((unsigned char*) legenda_copy); | ||
57 | - free(legenda_copy); | 53 | +void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { |
54 | + DDPRINTF("Service SRT recebeu: %d legendas.\n", sub_size); | ||
55 | + setSizeOfSubtitles(sub_size); | ||
56 | +} | ||
57 | + | ||
58 | +void ServiceWindowGenerationFromSRT::setPathSRT(char* path_srt) { | ||
59 | + this->path_srt = path_srt; | ||
58 | } | 60 | } |
59 | 61 | ||
60 | void ServiceWindowGenerationFromSRT::initialize() { | 62 | void ServiceWindowGenerationFromSRT::initialize() { |
@@ -62,29 +64,23 @@ void ServiceWindowGenerationFromSRT::initialize() { | @@ -62,29 +64,23 @@ void ServiceWindowGenerationFromSRT::initialize() { | ||
62 | DDPRINTF("Service SRT Initialize.\n"); | 64 | DDPRINTF("Service SRT Initialize.\n"); |
63 | 65 | ||
64 | if(serviceType == 2){ | 66 | if(serviceType == 2){ |
65 | - | ||
66 | - /* | ||
67 | - Este serviço utiliza o arquivo de vídeo (em formato TS) do usuário para | ||
68 | - capturar as informações referente ao relógio (PCR) para calcular as | ||
69 | - etiquetas de apresentação (PTS) dos sinais em Libras. | ||
70 | - */ | 67 | + /*Este serviço utiliza o arquivo de vídeo (em formato TS) do usuário para |
68 | + capturar as informações referente ao relógio (PCR) para calcular as | ||
69 | + etiquetas de apresentação (PTS) dos sinais em Libras.*/ | ||
71 | 70 | ||
72 | inputfile = new InputFile(this->path_input); | 71 | inputfile = new InputFile(this->path_input); |
73 | extratorSRT = new ExtratorSRT(); | 72 | extratorSRT = new ExtratorSRT(); |
73 | + monitor_pcr_base = new MonitorPCR(); | ||
74 | 74 | ||
75 | - monitor_pcr_base = new MonitorPCR(); | ||
76 | - | ||
77 | - /* [Temporário]: como o monitor do PCR não estava encontrando a extensão do | ||
78 | - vídeo, este está sendo analisado e infomado no trecho de código a seguir. | ||
79 | - */ | ||
80 | - if (strstr(path_input, "ts") != NULL) { | ||
81 | - char* format_video = new char[3]; | ||
82 | - strcpy(format_video, "ts"); | ||
83 | - monitor_pcr_base->setFormatVideo(format_video); | ||
84 | - } | 75 | + /* [Temporário]: como o monitor do PCR não estava encontrando a extensão do |
76 | + vídeo, este está sendo analisado e infomado no trecho de código a seguir.*/ | ||
77 | + if (strstr(path_input, "ts") != NULL) { | ||
78 | + char* format_video = new char[3]; | ||
79 | + strcpy(format_video, "ts"); | ||
80 | + monitor_pcr_base->setFormatVideo(format_video); | ||
81 | + } | ||
85 | 82 | ||
86 | monitor_pcr_base->addListenerPCRBase(extratorSRT); | 83 | monitor_pcr_base->addListenerPCRBase(extratorSRT); |
87 | - | ||
88 | inputfile->addListener(monitor_pcr_base); | 84 | inputfile->addListener(monitor_pcr_base); |
89 | extratorSRT->addListener(this); | 85 | extratorSRT->addListener(this); |
90 | extratorSRT->setFilePath((char*) path_srt); | 86 | extratorSRT->setFilePath((char*) path_srt); |
@@ -102,13 +98,9 @@ void ServiceWindowGenerationFromSRT::initialize() { | @@ -102,13 +98,9 @@ void ServiceWindowGenerationFromSRT::initialize() { | ||
102 | this->Start(); | 98 | this->Start(); |
103 | 99 | ||
104 | } else{ | 100 | } else{ |
105 | - | ||
106 | - /** | ||
107 | - Este serviço utiliza apenas o arquivo de legendas (SRT) como entrada, | ||
108 | - portanto, não é preciso monitorar as informações do PCR a partir do | ||
109 | - objeto InputFile(). | ||
110 | - */ | ||
111 | - | 101 | + /*Este serviço utiliza apenas o arquivo de legendas (SRT) como entrada, |
102 | + portanto, não é preciso monitorar as informações do PCR a partir do | ||
103 | + objeto InputFile().*/ | ||
112 | extratorSRT = new ExtratorSRT(); | 104 | extratorSRT = new ExtratorSRT(); |
113 | monitor_pcr_base = new MonitorPCR(); | 105 | monitor_pcr_base = new MonitorPCR(); |
114 | monitor_pcr_base->addListenerPCRBase(extratorSRT); | 106 | monitor_pcr_base->addListenerPCRBase(extratorSRT); |
@@ -128,13 +120,9 @@ void ServiceWindowGenerationFromSRT::initialize() { | @@ -128,13 +120,9 @@ void ServiceWindowGenerationFromSRT::initialize() { | ||
128 | 120 | ||
129 | } | 121 | } |
130 | 122 | ||
131 | -bool ServiceWindowGenerationFromSRT::finished() { | ||
132 | - return finish_srt; | ||
133 | -} | ||
134 | - | ||
135 | void ServiceWindowGenerationFromSRT::Run() { | 123 | void ServiceWindowGenerationFromSRT::Run() { |
136 | while (isRunning()) { | 124 | while (isRunning()) { |
137 | usleep(200000); //200ms | 125 | usleep(200000); //200ms |
138 | } | 126 | } |
139 | - finish_srt = true; | 127 | + finish = true; |
140 | } | 128 | } |
servico/src/serviceWindowGenerationFromText.cpp
@@ -8,7 +8,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText ( | @@ -8,7 +8,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText ( | ||
8 | setUserId(username); | 8 | setUserId(username); |
9 | setTransparency(transp); | 9 | setTransparency(transp); |
10 | setServiceType(serviceType); | 10 | setServiceType(serviceType); |
11 | - alive = true; | 11 | + finish = false; |
12 | DPRINTF("Done!\n"); | 12 | DPRINTF("Done!\n"); |
13 | } | 13 | } |
14 | 14 | ||
@@ -17,6 +17,19 @@ ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { | @@ -17,6 +17,19 @@ ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { | ||
17 | DDDPRINTF("Service Text finished!\n"); | 17 | DDDPRINTF("Service Text finished!\n"); |
18 | } | 18 | } |
19 | 19 | ||
20 | +void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { | ||
21 | + tradutor->traduz(line); | ||
22 | +} | ||
23 | + | ||
24 | +void ServiceWindowGenerationFromText::notifyEnd(int line_size) { | ||
25 | + DDPRINTF("Service TXT recebeu: %d linhas.\n", line_size); | ||
26 | + setSizeOfSubtitles(line_size); | ||
27 | +} | ||
28 | + | ||
29 | +bool ServiceWindowGenerationFromText::isFinished() { | ||
30 | + return finish; | ||
31 | +} | ||
32 | + | ||
20 | void ServiceWindowGenerationFromText::initialize() { | 33 | void ServiceWindowGenerationFromText::initialize() { |
21 | DDPRINTF("Service Text Initialize.\n"); | 34 | DDPRINTF("Service Text Initialize.\n"); |
22 | 35 | ||
@@ -34,22 +47,9 @@ void ServiceWindowGenerationFromText::initialize() { | @@ -34,22 +47,9 @@ void ServiceWindowGenerationFromText::initialize() { | ||
34 | this->Start(); | 47 | this->Start(); |
35 | } | 48 | } |
36 | 49 | ||
37 | -void ServiceWindowGenerationFromText::notifyEnd(int line_size) { | ||
38 | - DDPRINTF("Service TXT recebeu: %d linhas.\n", line_size); | ||
39 | - setSizeOfSubtitles(line_size); | ||
40 | -} | ||
41 | - | ||
42 | -void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { | ||
43 | - tradutor->traduz(line); | ||
44 | -} | ||
45 | - | ||
46 | -bool ServiceWindowGenerationFromText::isAlive() { | ||
47 | - return alive; | ||
48 | -} | ||
49 | - | ||
50 | void ServiceWindowGenerationFromText::Run() { | 50 | void ServiceWindowGenerationFromText::Run() { |
51 | while (isRunning()) { | 51 | while (isRunning()) { |
52 | usleep(200000); //200ms | 52 | usleep(200000); //200ms |
53 | } | 53 | } |
54 | - alive = false; | 54 | + finish = true; |
55 | } | 55 | } |