Commit 3b5f86ecafad51afe1eee52733feb079433eeb23
1 parent
094f6d33
Exists in
master
and in
1 other branch
Remoção do Sincronizador
Showing
10 changed files
with
11 additions
and
999 deletions
Show diff stats
servico/src/include/serviceWindowGeneration.h
... | ... | @@ -9,8 +9,6 @@ |
9 | 9 | #include "jthread.h" |
10 | 10 | #include "dprintf.h" |
11 | 11 | #include "Mixer.h" |
12 | -//#include "synchronizer.h" | |
13 | -//#include "listenerSynchronizer.h" | |
14 | 12 | #include "listenerTradutor.h" |
15 | 13 | #include "tradutorPortGlosa.h" |
16 | 14 | #include "serviceException.h" |
... | ... | @@ -23,11 +21,7 @@ |
23 | 21 | |
24 | 22 | #define DEVELOPER "devel" |
25 | 23 | #define PRODUCTION "prod" |
26 | -#define BASEDIR "vlibras_user/dicionario_libras/" | |
27 | -#define BASEDIRTRANSP "vlibras_user/dicionarioTransp_libras/" | |
28 | -#define VIDEO_POSE_NEUTRA "poseneutra" | |
29 | -#define EXTENSAO_DICIONARIO ".ts" | |
30 | -#define PATH_DEVEL "vlibras_user/vlibras-contents/videos/" | |
24 | +#define PATH_DEVEL_CONTENTS "vlibras_user/vlibras-contents/videos/" | |
31 | 25 | #define PATH_DEVEL_UPLOADS "vlibras_user/vlibras-contents/uploads/" |
32 | 26 | #define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-conf/uploads/" |
33 | 27 | #define PATH_CONF_FILE "vlibras_user/.vlibras-conf/param.json" |
... | ... | @@ -46,7 +40,6 @@ class ServiceWindowGeneration { |
46 | 40 | |
47 | 41 | protected: |
48 | 42 | TradutorPortGlosa* tradutor; |
49 | - //Synchronizer* sincronizador; | |
50 | 43 | Mixer* mixer; |
51 | 44 | StreamSocket* core_socket; |
52 | 45 | |
... | ... | @@ -59,7 +52,7 @@ protected: |
59 | 52 | bool parsingSuccessful; |
60 | 53 | |
61 | 54 | char* path_input; |
62 | - char* path_libras; | |
55 | + char* path_client; | |
63 | 56 | char* path_contents; |
64 | 57 | char* path_uploads; |
65 | 58 | char* client_type; |
... | ... | @@ -75,15 +68,10 @@ protected: |
75 | 68 | |
76 | 69 | virtual void setSizeOfSubtitles(int sub_size) = 0; |
77 | 70 | virtual void setPathContents() = 0; |
78 | - virtual void setPathLibras() = 0; | |
79 | - //virtual void setBackground() = 0; | |
80 | 71 | |
81 | 72 | virtual void connectToUnity() = 0; |
82 | 73 | virtual void sendGlosa(string glosa) = 0; |
83 | 74 | virtual void waitVideoGeneration() = 0; |
84 | - | |
85 | - //virtual void transcodeVideoToWebm(); | |
86 | - virtual void transcodeVideoToMp4() = 0; | |
87 | 75 | |
88 | 76 | public: |
89 | 77 | virtual void initialize() = 0; | ... | ... |
servico/src/include/serviceWindowGenerationFromRec.h
... | ... | @@ -16,15 +16,11 @@ private: |
16 | 16 | void addPTS(int64_t pts); |
17 | 17 | void setSizeOfSubtitles(int sub_size); |
18 | 18 | void setPathContents(); |
19 | - void setPathLibras(); | |
20 | - //void setBackground(); | |
21 | 19 | |
22 | 20 | void connectToUnity(); |
23 | 21 | void sendGlosa(string glosa); |
24 | 22 | void waitVideoGeneration(); |
25 | 23 | |
26 | - void transcodeVideoToMp4(); | |
27 | - void createThumbnail(); | |
28 | 24 | bool isRunning(); |
29 | 25 | public: |
30 | 26 | ServiceWindowGenerationFromRec(char* pathVideo, int sublanguage, int position, int size, |
... | ... | @@ -36,7 +32,6 @@ public: |
36 | 32 | void notifyTextRecognized(unsigned char* text, int64_t pts); |
37 | 33 | void notifyTranslation(vector<string>* glosas); |
38 | 34 | void notifyTranslator(unsigned char* text); |
39 | - //void notifyEndOfSynchronization(); | |
40 | 35 | void notifyEnd(int sentences_size); |
41 | 36 | |
42 | 37 | void initialize(); | ... | ... |
servico/src/include/serviceWindowGenerationFromSRT.h
... | ... | @@ -19,15 +19,11 @@ private: |
19 | 19 | void addPTS(int64_t pts); |
20 | 20 | void setSizeOfSubtitles(int sub_size); |
21 | 21 | void setPathContents(); |
22 | - void setPathLibras(); | |
23 | - //void setBackground(); | |
24 | 22 | |
25 | 23 | void connectToUnity(); |
26 | 24 | void sendGlosa(string glosa); |
27 | 25 | void waitVideoGeneration(); |
28 | 26 | |
29 | - void transcodeVideoToMp4(); | |
30 | - void createThumbnail(); | |
31 | 27 | bool isRunning(); |
32 | 28 | public: |
33 | 29 | //construtor de serviço de video e legenda |
... | ... | @@ -40,7 +36,6 @@ public: |
40 | 36 | void notifySubtitle(unsigned char* subtitle, int64_t pts); |
41 | 37 | void notifyTranslation(vector<string>* glosas); |
42 | 38 | void notifyTranslator(unsigned char* text); |
43 | - //void notifyEndOfSynchronization(); | |
44 | 39 | void notifyEnd(int sub_size); |
45 | 40 | |
46 | 41 | void initialize(); | ... | ... |
servico/src/include/serviceWindowGenerationFromText.h
... | ... | @@ -15,14 +15,11 @@ private: |
15 | 15 | |
16 | 16 | void setSizeOfSubtitles(int sub_size); |
17 | 17 | void setPathContents(); |
18 | - void setPathLibras(); | |
19 | - //void setBackground(); | |
20 | 18 | |
21 | 19 | void connectToUnity(); |
22 | 20 | void sendGlosa(string glosa); |
23 | 21 | void waitVideoGeneration(); |
24 | 22 | |
25 | - void transcodeVideoToMp4(); | |
26 | 23 | bool isRunning(); |
27 | 24 | public: |
28 | 25 | ServiceWindowGenerationFromText(char* pathFile, int transparency, char* id, char* client); |
... | ... | @@ -31,7 +28,6 @@ public: |
31 | 28 | void notifyLine(unsigned char* line); |
32 | 29 | void notifyTranslation(vector<string>* glosas); |
33 | 30 | void notifyTranslator(unsigned char* text); |
34 | - //void notifyEndOfSynchronization(); | |
35 | 31 | void notifyEnd(int line_size); |
36 | 32 | |
37 | 33 | void initialize(); | ... | ... |
servico/src/serviceWindowGenerationFromRec.cpp
... | ... | @@ -50,14 +50,13 @@ ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){ |
50 | 50 | free(vetor_pts); |
51 | 51 | if (tradutor) delete tradutor; |
52 | 52 | if (rec) delete rec; |
53 | - //if (sincronizador) delete sincronizador; | |
54 | 53 | if (mixer) delete mixer; |
55 | 54 | DDDPRINTF("Service Rec finished!\n"); |
56 | 55 | } |
57 | 56 | |
58 | 57 | void ServiceWindowGenerationFromRec::setPathContents(){ |
59 | 58 | if(strcmp(client_type,DEVELOPER) == 0){ |
60 | - this->path_contents = PATH_DEVEL; | |
59 | + this->path_contents = PATH_DEVEL_CONTENTS; | |
61 | 60 | this->path_uploads = PATH_DEVEL_UPLOADS; |
62 | 61 | rec->setPathAudioContents(path_uploads); |
63 | 62 | }else if(strcmp(client_type, PRODUCTION) == 0){ |
... | ... | @@ -78,40 +77,11 @@ void ServiceWindowGenerationFromRec::setPathContents(){ |
78 | 77 | } |
79 | 78 | } |
80 | 79 | |
81 | -void ServiceWindowGenerationFromRec::setPathLibras(){ | |
82 | - char* final_path = new char[MAX_SIZE_PATH]; | |
83 | - strcpy(final_path, this->path_uploads); | |
84 | - strcat(final_path, this->user_id); | |
85 | - strcat(final_path, "/video_libras.ts"); | |
86 | - | |
87 | - this->path_libras = final_path; | |
88 | -} | |
89 | - | |
90 | -// void ServiceWindowGenerationFromRec::setBackground(){ | |
91 | -// if(this->transparency == 0) { //pega dicionario com BackGround opaco | |
92 | -// char* dicPath; | |
93 | -// dicPath = getenv("DIC_LIBRAS"); | |
94 | -// if(dicPath != NULL) | |
95 | -// sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); | |
96 | -// else | |
97 | -// sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); | |
98 | - | |
99 | -// } else if(this->transparency == 1) { //pega dicionario com BackGround transparente | |
100 | -// char* dicTPath; | |
101 | -// dicTPath = getenv("DICTRANSP_LIBRAS"); | |
102 | -// if(dicTPath != NULL) | |
103 | -// sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); | |
104 | -// else | |
105 | -// sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); | |
106 | -// } | |
107 | -// } | |
108 | - | |
109 | 80 | void ServiceWindowGenerationFromRec::setSizeOfSubtitles(int sub_size){ |
110 | 81 | numero_legendas = sub_size; |
111 | 82 | if (legendas_enviadas >= numero_legendas){ |
112 | 83 | sendGlosa(END_NOTIFICATION); |
113 | 84 | waitVideoGeneration(); |
114 | - //sincronizador->stop(); | |
115 | 85 | } |
116 | 86 | } |
117 | 87 | |
... | ... | @@ -129,19 +99,6 @@ void ServiceWindowGenerationFromRec::notifyTextRecognized(unsigned char* text, i |
129 | 99 | notifyTranslator(text); |
130 | 100 | } |
131 | 101 | |
132 | -// //Quando o sincronizador termina, ele invoca esse método para avisar | |
133 | -// void ServiceWindowGenerationFromRec::notifyEndOfSynchronization() { | |
134 | -// if (this->service_type == SERVICE_TYPE_REC) { | |
135 | -// mixer = new Mixer(); | |
136 | -// mixer->initialize(this->path_input, this->path_libras,this->position,this->size, | |
137 | -// this->transparency, this->user_id, this->path_uploads, this->path_contents); | |
138 | -// createThumbnail(); | |
139 | -// }else{ | |
140 | -// transcodeVideoToMp4(); | |
141 | -// } | |
142 | -// this->running = false; | |
143 | -// } | |
144 | - | |
145 | 102 | void ServiceWindowGenerationFromRec::notifyTranslation(vector<string> * glosas) { |
146 | 103 | for (int i = 0; i < glosas->size(); i++) { |
147 | 104 | locale loc; |
... | ... | @@ -150,7 +107,6 @@ void ServiceWindowGenerationFromRec::notifyTranslation(vector<string> * glosas) |
150 | 107 | glosa_lower += std::tolower(glosas->at(i).at(k), loc); |
151 | 108 | } |
152 | 109 | //int64_t pts_notificado = vetor_pts->front(); |
153 | - //sincronizador->recebeglosa(glosa_lower, pts_notificado); | |
154 | 110 | sendGlosa(glosa_lower); |
155 | 111 | } |
156 | 112 | |
... | ... | @@ -174,43 +130,11 @@ bool ServiceWindowGenerationFromRec::isFinished(){ |
174 | 130 | |
175 | 131 | void ServiceWindowGenerationFromRec::initialize(){ |
176 | 132 | DPRINTF("Service REC Initialize.\n"); |
177 | - rec->addListener(this); | |
178 | - setPathLibras(); | |
179 | - | |
180 | - if(this->sub_language == 1) | |
181 | - tradutor->addListener(this); | |
182 | - | |
183 | - if(this->service_type != SERVICE_TYPE_REC_ONLY_AUDIO){ | |
184 | - vector<string> tokens; | |
185 | - char* pathtmp = this->path_input; | |
186 | - int size = strlen(pathtmp); | |
187 | - char vtemp [size]; | |
188 | - | |
189 | - strcpy(vtemp, pathtmp); | |
190 | - pathtmp = strtok(vtemp, "."); | |
191 | - while (pathtmp != NULL) { | |
192 | - tokens.push_back(string(pathtmp)); | |
193 | - pathtmp = strtok(NULL, "."); | |
194 | - } | |
195 | - | |
196 | - string buildstrpath = tokens[0] + "_libras" + EXTENSAO_DICIONARIO; | |
197 | - this->path_libras = new char[buildstrpath.size()]; | |
198 | - strcpy(this->path_libras, buildstrpath.c_str()); | |
199 | - //printf("O Serviço montou o seguinte path para o vídeo de Libras: %s\n", path_libras); | |
200 | - | |
201 | - }else{ | |
202 | - tradutor->addListener(this); | |
203 | - } | |
204 | 133 | |
134 | + rec->addListener(this); | |
135 | + tradutor->addListener(this); | |
205 | 136 | connectToUnity(); |
206 | 137 | |
207 | - // setBackground(); | |
208 | - | |
209 | - // uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro | |
210 | - // sincronizador->setPCRBase(pcr_base); | |
211 | - // sincronizador->addListener(this); | |
212 | - // sincronizador->Start(); | |
213 | - | |
214 | 138 | try{ |
215 | 139 | rec->initialize(); |
216 | 140 | } catch(RecognizeException ex){ |
... | ... | @@ -229,7 +153,6 @@ void ServiceWindowGenerationFromRec::sendGlosa(string glosa) { |
229 | 153 | |
230 | 154 | char* ok_core = new char[4]; |
231 | 155 | core_socket->read(ok_core, 4); //aguarda o unity confirmar o recebimento da glosa |
232 | - //cout << "Recebi: " << ok_core << endl; | |
233 | 156 | delete [] ok_core; |
234 | 157 | } |
235 | 158 | |
... | ... | @@ -250,7 +173,6 @@ void ServiceWindowGenerationFromRec::waitVideoGeneration() { |
250 | 173 | try{ |
251 | 174 | do{ |
252 | 175 | core_socket->read(endgeneration, sizeof(endgeneration)); |
253 | - //usleep(500000); | |
254 | 176 | }while(strcmp(endgeneration, END_NOTIFICATION) != 0); |
255 | 177 | core_socket->close(); |
256 | 178 | this->running = false; |
... | ... | @@ -259,25 +181,6 @@ void ServiceWindowGenerationFromRec::waitVideoGeneration() { |
259 | 181 | } |
260 | 182 | } |
261 | 183 | |
262 | -void ServiceWindowGenerationFromRec::transcodeVideoToMp4(){ | |
263 | - DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); | |
264 | - string command = "ffmpeg -i "; | |
265 | - command.append(path_libras) | |
266 | - .append(" -qscale 0 -strict experimental -vcodec libx264 -preset fast -r 30 ").append(" -v quiet ") | |
267 | - .append(path_contents).append(user_id).append(".mp4"); | |
268 | - //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); | |
269 | - system(command.c_str()); | |
270 | -} | |
271 | - | |
272 | -void ServiceWindowGenerationFromRec::createThumbnail(){ | |
273 | - string command = "ffmpeg -ss 10 -i "; | |
274 | - command.append(path_contents).append(user_id).append(".mp4") | |
275 | - .append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 ").append(" -v quiet ") | |
276 | - .append(path_contents).append(user_id).append(".png"); | |
277 | - //printf("[INFO]: Thumbnail command -> %s\n", command.c_str()); | |
278 | - system(command.c_str()); | |
279 | -} | |
280 | - | |
281 | 184 | void ServiceWindowGenerationFromRec::Run(){ |
282 | 185 | while(isRunning()){ |
283 | 186 | usleep(200000); | ... | ... |
servico/src/serviceWindowGenerationFromSRT.cpp
... | ... | @@ -53,7 +53,6 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { |
53 | 53 | free(vetor_pts); |
54 | 54 | if (mixer) delete mixer; |
55 | 55 | if (tradutor) delete tradutor; |
56 | - //if (sincronizador) delete sincronizador; | |
57 | 56 | if (extratorSRT)delete extratorSRT; |
58 | 57 | if (extrator_factory) delete extrator_factory; |
59 | 58 | DDDPRINTF("Service SRT finalized!\n"); |
... | ... | @@ -61,8 +60,7 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { |
61 | 60 | |
62 | 61 | void ServiceWindowGenerationFromSRT::setPathContents() { |
63 | 62 | if(strcmp(client_type,DEVELOPER) == 0){ |
64 | - this->path_contents = PATH_DEVEL; | |
65 | - this->path_uploads = PATH_DEVEL_UPLOADS; | |
63 | + this->path_contents = PATH_DEVEL_CONTENTS; | |
66 | 64 | }else if(strcmp(client_type, PRODUCTION) == 0){ |
67 | 65 | ifstream conf_file(PATH_CONF_FILE, ifstream::binary); |
68 | 66 | parsingSuccessful = reader.parse(conf_file, root); |
... | ... | @@ -73,47 +71,17 @@ void ServiceWindowGenerationFromSRT::setPathContents() { |
73 | 71 | string attr = root.get("storage", PATH_VBOX_UPLOADS).asString(); |
74 | 72 | this->path_contents = new char[MAX_SIZE_PATH]; |
75 | 73 | strcpy(this->path_contents, attr.c_str()); |
76 | - this->path_uploads = PATH_VBOX_UPLOADS; | |
77 | 74 | conf_file.close(); |
78 | 75 | }else{ |
79 | 76 | throw ServiceException("Invalid client!"); |
80 | 77 | } |
81 | 78 | } |
82 | 79 | |
83 | -void ServiceWindowGenerationFromSRT::setPathLibras() { | |
84 | - char* final_path = new char[MAX_SIZE_PATH]; | |
85 | - strcpy(final_path, this->path_uploads); | |
86 | - strcat(final_path, this->user_id); | |
87 | - strcat(final_path, "/video_libras.ts"); | |
88 | - | |
89 | - this->path_libras = final_path; | |
90 | -} | |
91 | - | |
92 | -// void ServiceWindowGenerationFromSRT::setBackground() { | |
93 | -// if(this->transparency == 0) { //pega dicionario com BackGround opaco | |
94 | -// char* dicPath; | |
95 | -// dicPath = getenv("DIC_LIBRAS"); | |
96 | -// if(dicPath != NULL) | |
97 | -// sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); | |
98 | -// else | |
99 | -// sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); | |
100 | - | |
101 | -// } else if(this->transparency == 1) { //pega dicionario com BackGround transparente | |
102 | -// char* dicTPath; | |
103 | -// dicTPath = getenv("DICTRANSP_LIBRAS"); | |
104 | -// if(dicTPath != NULL) | |
105 | -// sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); | |
106 | -// else | |
107 | -// sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); | |
108 | -// } | |
109 | -// } | |
110 | - | |
111 | 80 | void ServiceWindowGenerationFromSRT::setSizeOfSubtitles(int sub_size) { |
112 | 81 | numero_legendas = sub_size; |
113 | 82 | if (legendas_enviadas >= numero_legendas){ |
114 | 83 | sendGlosa(END_NOTIFICATION); |
115 | 84 | waitVideoGeneration(); |
116 | - //sincronizador->stop(); | |
117 | 85 | } |
118 | 86 | } |
119 | 87 | |
... | ... | @@ -134,18 +102,6 @@ void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int |
134 | 102 | notifyTranslator(subtitle); |
135 | 103 | } |
136 | 104 | |
137 | -// void ServiceWindowGenerationFromSRT::notifyEndOfSynchronization() { | |
138 | -// if (this->service_type == SERVICE_TYPE_SRT) { | |
139 | -// mixer = new Mixer(); | |
140 | -// mixer->initialize(this->path_input, this->path_libras,this->position,this->size, | |
141 | -// this->transparency, this->user_id, this->path_uploads, this->path_contents); | |
142 | -// createThumbnail(); | |
143 | -// }else{ | |
144 | -// transcodeVideoToMp4(); | |
145 | -// } | |
146 | -// this->running = false; | |
147 | -// } | |
148 | - | |
149 | 105 | void ServiceWindowGenerationFromSRT::notifyTranslation(vector<string> * glosas) { |
150 | 106 | for (int i = 0; i < glosas->size(); i++) { |
151 | 107 | locale loc; |
... | ... | @@ -155,7 +111,6 @@ void ServiceWindowGenerationFromSRT::notifyTranslation(vector<string> * glosas) |
155 | 111 | } |
156 | 112 | sendGlosa(glosa_lower); |
157 | 113 | //int64_t pts_notificado = vetor_pts->front(); |
158 | - //sincronizador->recebeglosa(glosa_lower, pts_notificado); | |
159 | 114 | } |
160 | 115 | |
161 | 116 | vetor_pts->erase(vetor_pts->begin()); |
... | ... | @@ -181,45 +136,14 @@ void ServiceWindowGenerationFromSRT::initialize() { |
181 | 136 | extratorSRT->addListener(this); |
182 | 137 | extratorSRT->setFilePath(path_srt); |
183 | 138 | |
184 | - setPathLibras(); | |
185 | - | |
186 | - if (this->sub_language == 1) | |
187 | - tradutor->addListener(this); | |
188 | - | |
189 | - if(this->service_type != SERVICE_TYPE_SRT_ONLY){ | |
190 | - vector<string> tokens; | |
191 | - char* pathtmp = this->path_input; | |
192 | - int size = strlen(pathtmp); | |
193 | - char vtemp [size]; | |
139 | + tradutor->addListener(this); | |
194 | 140 | |
195 | - strcpy(vtemp, pathtmp); | |
196 | - pathtmp = strtok(vtemp, "."); | |
197 | - while (pathtmp != NULL) { | |
198 | - tokens.push_back(string(pathtmp)); | |
199 | - pathtmp = strtok(NULL, "."); | |
200 | - } | |
201 | - | |
202 | - string buildstrpath = tokens[0] + "_libras" + EXTENSAO_DICIONARIO; | |
203 | - this->path_libras = new char[buildstrpath.size()]; | |
204 | - strcpy(this->path_libras, buildstrpath.c_str()); | |
205 | - //printf("O Serviço montou o seguinte path para o vídeo de Libras: %s\n", path_libras); | |
206 | - | |
207 | - }else{ | |
208 | - tradutor->addListener(this); | |
209 | - } | |
210 | - | |
211 | - //setBackground(); | |
212 | - | |
213 | - if (service_type != SERVICE_TYPE_SRT) { | |
214 | - uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro | |
215 | - //sincronizador->setPCRBase(pcr_base); | |
216 | - } | |
141 | + // if (service_type != SERVICE_TYPE_SRT) { | |
142 | + // uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro | |
143 | + // } | |
217 | 144 | |
218 | 145 | connectToUnity(); |
219 | 146 | |
220 | - // sincronizador->addListener(this); | |
221 | - // sincronizador->Start(); | |
222 | - | |
223 | 147 | try{ |
224 | 148 | extratorSRT->initialize(); |
225 | 149 | }catch(ExtratorException ex){ |
... | ... | @@ -238,7 +162,6 @@ void ServiceWindowGenerationFromSRT::sendGlosa(string glosa) { |
238 | 162 | |
239 | 163 | char* ok_core = new char[3]; |
240 | 164 | core_socket->read(ok_core, 3); //aguarda o unity confirmar o recebimento da glosa |
241 | - //cout << "Recebi: " << ok_core << endl; | |
242 | 165 | delete [] ok_core; |
243 | 166 | } |
244 | 167 | |
... | ... | @@ -259,7 +182,6 @@ void ServiceWindowGenerationFromSRT::waitVideoGeneration() { |
259 | 182 | try{ |
260 | 183 | do{ |
261 | 184 | core_socket->read(endgeneration, sizeof(endgeneration)); |
262 | - //usleep(500000); | |
263 | 185 | }while(strcmp(endgeneration, END_NOTIFICATION) != 0); |
264 | 186 | core_socket->close(); |
265 | 187 | this->running = false; |
... | ... | @@ -268,25 +190,6 @@ void ServiceWindowGenerationFromSRT::waitVideoGeneration() { |
268 | 190 | } |
269 | 191 | } |
270 | 192 | |
271 | -void ServiceWindowGenerationFromSRT::transcodeVideoToMp4(){ | |
272 | - DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); | |
273 | - string command = "ffmpeg -i "; | |
274 | - command.append(path_libras) | |
275 | - .append(" -qscale 0 -strict experimental -vcodec libx264 -preset fast -r 30 ").append(" -v quiet ") | |
276 | - .append(path_contents).append(user_id).append(".mp4"); | |
277 | - //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); | |
278 | - system(command.c_str()); | |
279 | -} | |
280 | - | |
281 | -void ServiceWindowGenerationFromSRT::createThumbnail(){ | |
282 | - string command = "ffmpeg -ss 10 -i "; | |
283 | - command.append(path_contents).append(user_id).append(".mp4") | |
284 | - .append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 ").append(" -v quiet ") | |
285 | - .append(path_contents).append(user_id).append(".png"); | |
286 | - //printf("[INFO]: Thumbnail command -> %s\n", command.c_str()); | |
287 | - system(command.c_str()); | |
288 | -} | |
289 | - | |
290 | 193 | void ServiceWindowGenerationFromSRT::Run() { |
291 | 194 | while(isRunning()){ |
292 | 195 | usleep(200000); | ... | ... |
servico/src/serviceWindowGenerationFromText.cpp
... | ... | @@ -25,7 +25,6 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, |
25 | 25 | ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { |
26 | 26 | free(vetor_pts); |
27 | 27 | if (tradutor) delete tradutor; |
28 | - //if (sincronizador) delete sincronizador; | |
29 | 28 | if (extratorTXT)delete extratorTXT; |
30 | 29 | if (extrator_factory) delete extrator_factory; |
31 | 30 | DDDPRINTF("Service Text finalized!\n"); |
... | ... | @@ -33,8 +32,7 @@ ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { |
33 | 32 | |
34 | 33 | void ServiceWindowGenerationFromText::setPathContents() { |
35 | 34 | if(strcmp(client_type,DEVELOPER) == 0){ |
36 | - this->path_contents = PATH_DEVEL; | |
37 | - this->path_uploads = PATH_DEVEL_UPLOADS; | |
35 | + this->path_contents = PATH_DEVEL_CONTENTS; | |
38 | 36 | }else if(strcmp(client_type, PRODUCTION) == 0){ |
39 | 37 | ifstream conf_file(PATH_CONF_FILE, ifstream::binary); |
40 | 38 | parsingSuccessful = reader.parse(conf_file, root); |
... | ... | @@ -44,47 +42,16 @@ void ServiceWindowGenerationFromText::setPathContents() { |
44 | 42 | string attr = root.get("storage", PATH_VBOX_UPLOADS).asString(); |
45 | 43 | this->path_contents = new char[MAX_SIZE_PATH]; |
46 | 44 | strcpy(this->path_contents, attr.c_str()); |
47 | - this->path_uploads = PATH_VBOX_UPLOADS; | |
48 | 45 | }else{ |
49 | 46 | throw ServiceException("Invalid client!"); |
50 | 47 | } |
51 | 48 | } |
52 | 49 | |
53 | -void ServiceWindowGenerationFromText::setPathLibras() { | |
54 | - char* final_path = new char[MAX_SIZE_PATH]; | |
55 | - strcpy(final_path, this->path_uploads); | |
56 | - strcat(final_path, this->user_id); | |
57 | - strcat(final_path, "/video_libras.ts"); | |
58 | - | |
59 | - this->path_libras = final_path; | |
60 | -} | |
61 | - | |
62 | -// void ServiceWindowGenerationFromText::setBackground() { | |
63 | -// if(this->transparency == 0) { //pega dicionario com BackGround opaco | |
64 | -// char* dicPath; | |
65 | -// dicPath = getenv("DIC_LIBRAS"); | |
66 | -// if(dicPath != NULL) | |
67 | -// sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); | |
68 | -// else | |
69 | -// sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); | |
70 | - | |
71 | -// } else if(this->transparency == 1) { //pega dicionario com BackGround transparente | |
72 | -// char* dicTPath; | |
73 | -// dicTPath = getenv("DICTRANSP_LIBRAS"); | |
74 | -// if(dicTPath != NULL) | |
75 | -// sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); | |
76 | -// else{ | |
77 | -// sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); | |
78 | -// } | |
79 | -// } | |
80 | -// } | |
81 | - | |
82 | 50 | void ServiceWindowGenerationFromText::setSizeOfSubtitles(int sub_size) { |
83 | 51 | numero_legendas = sub_size; |
84 | 52 | if (legendas_enviadas >= numero_legendas){ |
85 | 53 | sendGlosa(END_NOTIFICATION); |
86 | 54 | waitVideoGeneration(); |
87 | - //sincronizador->stop(); | |
88 | 55 | } |
89 | 56 | } |
90 | 57 | |
... | ... | @@ -96,11 +63,6 @@ void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { |
96 | 63 | notifyTranslator(line); |
97 | 64 | } |
98 | 65 | |
99 | -// void ServiceWindowGenerationFromText::notifyEndOfSynchronization() { | |
100 | -// transcodeVideoToMp4(); | |
101 | -// this->running = false; | |
102 | -// } | |
103 | - | |
104 | 66 | void ServiceWindowGenerationFromText::notifyTranslation(vector<string> * glosas) { |
105 | 67 | for (int i = 0; i < glosas->size(); i++) { |
106 | 68 | locale loc; |
... | ... | @@ -109,7 +71,6 @@ void ServiceWindowGenerationFromText::notifyTranslation(vector<string> * glosas) |
109 | 71 | glosa_lower += std::tolower(glosas->at(i).at(k), loc); |
110 | 72 | } |
111 | 73 | sendGlosa(glosa_lower); |
112 | - //sincronizador->recebeglosa(glosa_lower, 1000); | |
113 | 74 | } |
114 | 75 | legendas_enviadas++; |
115 | 76 | } |
... | ... | @@ -133,19 +94,10 @@ void ServiceWindowGenerationFromText::initialize() { |
133 | 94 | extratorTXT->addListener(this); |
134 | 95 | extratorTXT->setFilePath(path_input); |
135 | 96 | |
136 | - setPathLibras(); | |
137 | - | |
138 | 97 | tradutor->addListener(this); |
139 | 98 | |
140 | 99 | connectToUnity(); |
141 | 100 | |
142 | - //setBackground(); | |
143 | - | |
144 | - // uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro | |
145 | - // sincronizador->setPCRBase(pcr_base); | |
146 | - // sincronizador->addListener(this); | |
147 | - // sincronizador->Start(); | |
148 | - | |
149 | 101 | try{ |
150 | 102 | extratorTXT->initialize(); |
151 | 103 | }catch(ExtratorException ex){ |
... | ... | @@ -164,7 +116,6 @@ void ServiceWindowGenerationFromText::sendGlosa(string glosa) { |
164 | 116 | |
165 | 117 | char* ok_core = new char[3]; |
166 | 118 | core_socket->read(ok_core, 3); //aguarda o unity confirmar o recebimento da glosa |
167 | - //cout << "Recebi: " << ok_core << endl; | |
168 | 119 | delete [] ok_core; |
169 | 120 | } |
170 | 121 | |
... | ... | @@ -185,7 +136,6 @@ void ServiceWindowGenerationFromText::waitVideoGeneration() { |
185 | 136 | try{ |
186 | 137 | do{ |
187 | 138 | core_socket->read(endgeneration, sizeof(endgeneration)); |
188 | - //usleep(500000); | |
189 | 139 | }while(strcmp(endgeneration, END_NOTIFICATION) != 0); |
190 | 140 | core_socket->close(); |
191 | 141 | this->running = false; |
... | ... | @@ -194,16 +144,6 @@ void ServiceWindowGenerationFromText::waitVideoGeneration() { |
194 | 144 | } |
195 | 145 | } |
196 | 146 | |
197 | -void ServiceWindowGenerationFromText::transcodeVideoToMp4(){ | |
198 | - DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); | |
199 | - string command = "ffmpeg -i "; | |
200 | - command.append(path_libras) | |
201 | - .append(" -qscale 0 -strict experimental -vcodec libx264 -preset fast -r 30 ").append(" -v quiet ") | |
202 | - .append(path_contents).append(user_id).append(".mp4"); | |
203 | - //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); | |
204 | - system(command.c_str()); | |
205 | -} | |
206 | - | |
207 | 147 | void ServiceWindowGenerationFromText::Run(){ |
208 | 148 | while(isRunning()){ |
209 | 149 | usleep(200000); | ... | ... |
synchronizer/src/include/listenerSynchronizer.h
... | ... | @@ -1,14 +0,0 @@ |
1 | -#ifndef _LISTENER_SYNCHRONIZER_H | |
2 | -#define _LISTENER_SYNCHRONIZER_H | |
3 | - | |
4 | -#include <string> | |
5 | -#include <stdint.h> | |
6 | - | |
7 | -using namespace std; | |
8 | - | |
9 | -class ListenerSynchronizer { | |
10 | -public: | |
11 | - virtual void notifyEndOfSynchronization() = 0; | |
12 | -}; | |
13 | - | |
14 | -#endif | |
15 | 0 | \ No newline at end of file |
synchronizer/src/include/synchronizer.h
... | ... | @@ -1,126 +0,0 @@ |
1 | -#ifndef SYNCHRONIZER_H | |
2 | -#define SYNCHRONIZER_H | |
3 | - | |
4 | -#include <stdio.h> | |
5 | -#include <stdlib.h> | |
6 | -#include <string.h> | |
7 | -#include <errno.h> | |
8 | -#include <time.h> | |
9 | -#include <unistd.h> | |
10 | -#include <signal.h> | |
11 | -#include <fcntl.h> | |
12 | -#include <sys/time.h> | |
13 | -#include <arpa/inet.h> | |
14 | -#include <sys/socket.h> | |
15 | -#include <vector> | |
16 | -#include <list> | |
17 | -#include <iostream> | |
18 | -#include <fstream> | |
19 | -#include "dprintf.h" | |
20 | -#include "jmutex.h" | |
21 | -#include "jthread.h" | |
22 | -#include "listenerSynchronizer.h" | |
23 | -//#include "httpstreamer.h" | |
24 | - | |
25 | -#define VIDEO_PADRAO "vlibras_user/dicionario_libras/poseneutra.ts" | |
26 | -#define VIDEOTRANSP_PADRAO "vlibras_user/dicionarioTransp_libras/poseneutra.ts" | |
27 | - | |
28 | -//DICIONARIO 30 fps | |
29 | -#define PCRPID 256 | |
30 | -#define PESPID 256 | |
31 | - | |
32 | -//DICIONARIO 45 fps | |
33 | -//#define PCRPID 4097 | |
34 | -//#define PESPID 4113 | |
35 | - | |
36 | -using namespace jthread; | |
37 | -using namespace std; | |
38 | - | |
39 | -class Synchronizer : public jthread::Thread { | |
40 | - | |
41 | -private: | |
42 | - bool hastext; | |
43 | - int taxa; | |
44 | - int filefd; | |
45 | - vector <char*> *videos; | |
46 | - int devicetv; | |
47 | - | |
48 | - uint64_t pcrBaseGeral; | |
49 | - uint64_t ultimoPCRBase; | |
50 | - uint64_t ultimoPCRBaseMod; | |
51 | - int64_t pcr_inicial; | |
52 | - int mediaDiferencaPCR; | |
53 | - int contagemPCR; | |
54 | - | |
55 | - ofstream escreveAux; | |
56 | - char* extensao; | |
57 | - char* baseDir; | |
58 | - | |
59 | - int64_t tempo_poseneutra; | |
60 | - vector <int64_t> *vector_pts; | |
61 | - int flagPrimeiroArquivo; | |
62 | - | |
63 | - list<ListenerSynchronizer*> * listeners; | |
64 | - Mutex* mutex_sync; | |
65 | - Mutex* mutexi; | |
66 | - | |
67 | - char* path_libras; | |
68 | - int transparency; | |
69 | - | |
70 | - int count_tasks; | |
71 | - bool service_running; | |
72 | - | |
73 | - | |
74 | -public: | |
75 | - Synchronizer(); | |
76 | - Synchronizer(/*int64_t pcr_inicial, */char*baseDir, char* extensao, char* path_libras, int transparency); | |
77 | - virtual ~Synchronizer(); | |
78 | - | |
79 | - void setPCRBase(uint64_t pcr_base); | |
80 | - | |
81 | - void Run(); | |
82 | - void stop(); | |
83 | - | |
84 | - void soletraGlosa(string glosa, int64_t pts);//em fase de teste | |
85 | - void recebeglosa(char * video, int tam, int64_t pts); | |
86 | - void recebeglosa(string glosa, int64_t pts); | |
87 | - char * getproximoarquivo(); | |
88 | - | |
89 | - void msleep(long tsleep, long *desconto); | |
90 | - | |
91 | - int gettaxa(); | |
92 | - int64_t getMilisegundos(); | |
93 | - | |
94 | - void settaxa(int taxa); | |
95 | - | |
96 | - vector <char*> * getVideos(); | |
97 | - | |
98 | - void analisaPCR(unsigned char * pacote); | |
99 | - void analisaPTSDTS(unsigned char *pacote); | |
100 | - int getPid(unsigned char *pacote); | |
101 | - bool contemAF(unsigned char *pacote); | |
102 | - int getTamanhoAF(unsigned char *pacote); | |
103 | - bool contemPCR(unsigned char *pacote); | |
104 | - uint64_t retornaPCRBase(unsigned char *pacote); | |
105 | - void setPCRBase(unsigned char *pacote, uint64_t pcrbase); | |
106 | - bool contemPayloadStartIndicator(unsigned char *pacote); | |
107 | - bool contemPayloadData(unsigned char *pacote); | |
108 | - bool verificaPESStartCode(unsigned char *PESPacket); | |
109 | - bool verificaPESStreamID(unsigned char *PESPacket); | |
110 | - bool contemPTS(unsigned char *PESPacket); | |
111 | - bool contemDTS(unsigned char *PESPacket); | |
112 | - uint64_t retornaPTS(unsigned char *PESPacket); | |
113 | - uint64_t retornaDTS(unsigned char *PESPacket); | |
114 | - void setNovoPTS(unsigned char *pacote, uint64_t PTS); | |
115 | - void setNovoDTS(unsigned char *pacote, uint64_t DTS); | |
116 | - void escrevePacote(char *pacote); | |
117 | - int escrevePacote(int * descritor, char *pacote, int size); | |
118 | - | |
119 | - virtual void addListener(ListenerSynchronizer* listener); | |
120 | - virtual void removeListener(ListenerSynchronizer* listener); | |
121 | - virtual void notifyListeners(); | |
122 | - | |
123 | -}; | |
124 | - | |
125 | - | |
126 | -#endif /* SYNCHRONIZER_H */ |
synchronizer/src/synchronizer.cpp
... | ... | @@ -1,568 +0,0 @@ |
1 | -#include "synchronizer.h" | |
2 | - | |
3 | -Synchronizer::Synchronizer() { | |
4 | - baseDir = (char*) "vlibras_user/dicionario_libras/"; | |
5 | - extensao = (char*) ".ts"; | |
6 | - filefd = 0; | |
7 | - videos = new vector <char*> (); | |
8 | - vector_pts = new vector <int64_t > (); | |
9 | - this->mutexi = new Mutex(); | |
10 | - | |
11 | - this->baseDir = new char[strlen(baseDir) + 1]; | |
12 | - strcpy(this->baseDir, baseDir); | |
13 | - | |
14 | - this->extensao = new char[strlen(extensao) + 1]; | |
15 | - strcpy(this->extensao, extensao); | |
16 | - flagPrimeiroArquivo = 1; | |
17 | - listeners = new list<ListenerSynchronizer*>(); | |
18 | - this->path_libras = path_libras; | |
19 | - DPRINTF("Done!\n") | |
20 | -} | |
21 | - | |
22 | -Synchronizer::Synchronizer(/*int64_t pcr_inicial, */char* baseDir, char* extensao, char* path_libras, int transparency) { | |
23 | - | |
24 | - hastext = true; | |
25 | - count_tasks = 0; // Usado no teste de Eduardo! | |
26 | - service_running = true; | |
27 | - | |
28 | - this->pcr_inicial = -1; | |
29 | - this->tempo_poseneutra = 120000; | |
30 | - | |
31 | - this->transparency = transparency; | |
32 | - | |
33 | - //cout << "\n\nTransparencia: " << this->transparency << "\n"; | |
34 | - | |
35 | - this->baseDir = new char[strlen(baseDir) + 1]; | |
36 | - strcpy(this->baseDir, baseDir); | |
37 | - | |
38 | - //cout << "\n\n#######BASEDIR: " << this->baseDir << "\n"; | |
39 | - | |
40 | - this->extensao = new char[strlen(extensao) + 1]; | |
41 | - strcpy(this->extensao, extensao); | |
42 | - | |
43 | - filefd = 0; | |
44 | - videos = new vector <char*> (); | |
45 | - pcrBaseGeral = 0; | |
46 | - ultimoPCRBase = 0; | |
47 | - mediaDiferencaPCR = 0; | |
48 | - contagemPCR = 0; | |
49 | - vector_pts = new vector <int64_t > (); | |
50 | - flagPrimeiroArquivo = 1; | |
51 | - listeners = new list<ListenerSynchronizer*>(); | |
52 | - this->path_libras = new char[strlen(path_libras) + 1]; | |
53 | - strcpy(this->path_libras, path_libras); | |
54 | - //cout << "-> path libras sync: " << path_libras << endl; | |
55 | - this->mutex_sync = new Mutex(); | |
56 | - this->mutexi = new Mutex(); | |
57 | - | |
58 | - DPRINTF("Done!\n") | |
59 | -} | |
60 | - | |
61 | -Synchronizer::~Synchronizer() { | |
62 | - free(videos); | |
63 | - listeners->clear(); | |
64 | - delete listeners; | |
65 | - if (escreveAux.is_open()) escreveAux.close(); | |
66 | - DDDPRINTF("Synchronizer finalized!\n"); | |
67 | - | |
68 | -} | |
69 | - | |
70 | -string toLower(string strr) { | |
71 | - char str[100]; | |
72 | - string ret; | |
73 | - strcpy(str, strr.c_str()); | |
74 | - int differ = 'A' - 'a'; | |
75 | - char ch; | |
76 | - int ii = strlen(str); | |
77 | - for (int i = 0; i < ii; i++) { | |
78 | - strncpy(&ch, str + i, 1); | |
79 | - if (ch >= 'A' && ch <= 'Z') { | |
80 | - ch = ch - differ; | |
81 | - memcpy(str + i, &ch, 1); | |
82 | - } | |
83 | - } | |
84 | - ret = str; | |
85 | - return ret; | |
86 | -} | |
87 | - | |
88 | -void Synchronizer::setPCRBase(uint64_t pcr_base){ | |
89 | - this->pcr_inicial = pcr_base; | |
90 | -} | |
91 | - | |
92 | -char* converteString(string palavra) { | |
93 | - | |
94 | - const char* aux = new char[palavra.size()]; | |
95 | - aux = palavra.c_str(); | |
96 | - char * aux2 = (char*) aux; | |
97 | - | |
98 | - return aux2; | |
99 | -} | |
100 | - | |
101 | -/* Método utilizado pelos serviços (Services Generation) para informar que | |
102 | - este processo pode ser finalizado após a demanda atual, isto é, depois | |
103 | - que terminar de gerar os vídeos que estão na fila. | |
104 | - */ | |
105 | -void Synchronizer::stop() { | |
106 | - //printf("> O Synchronizer recebeu a mensagem de que pode terminar a execução\n"); | |
107 | - service_running = false; | |
108 | -} | |
109 | - | |
110 | -int Synchronizer::gettaxa() { | |
111 | - return taxa; | |
112 | -} | |
113 | - | |
114 | -void Synchronizer::settaxa(int taxa) { | |
115 | - this->taxa = taxa; | |
116 | -} | |
117 | - | |
118 | -vector <char*> * Synchronizer::getVideos() { | |
119 | - return videos; | |
120 | -} | |
121 | - | |
122 | -/* Trata a glosa de modo single, ou seja, havendo sinal ou soletrando, | |
123 | - este método é chamado individualmente em cada sinal correspondente. | |
124 | - */ | |
125 | -void Synchronizer::recebeglosa(char * video, int tam, int64_t pts) { | |
126 | - mutexi->Lock(); | |
127 | - char *video_copy = new char [tam + 1]; | |
128 | - strcpy(video_copy, video); | |
129 | - videos->push_back(video_copy); | |
130 | - count_tasks++; | |
131 | - vector_pts->push_back(pts); | |
132 | - mutexi->Unlock(); | |
133 | -} | |
134 | - | |
135 | -int64_t Synchronizer::getMilisegundos() { | |
136 | - struct timeval tempo; | |
137 | - gettimeofday(&tempo, NULL); | |
138 | - return (int64_t) tempo.tv_sec * 1000 + tempo.tv_usec / 1000; | |
139 | -} | |
140 | - | |
141 | -void Synchronizer::msleep(long tsleep, long *desconto) { | |
142 | - struct timeval tempo; | |
143 | - long deltaTAux = 0; | |
144 | - long tusleep = 0; | |
145 | - int64_t tAux = 0, tAux2 = 0; | |
146 | - | |
147 | - tsleep -= *desconto; | |
148 | - | |
149 | - tusleep = tsleep / 1000; | |
150 | - | |
151 | - gettimeofday(&tempo, NULL); | |
152 | - tAux = tempo.tv_sec * 1000 + tempo.tv_usec / 1000; | |
153 | - | |
154 | - while ((tsleep > 0) && (deltaTAux <= tsleep)) { | |
155 | - usleep(tusleep); | |
156 | - | |
157 | - gettimeofday(&tempo, NULL); | |
158 | - tAux2 = tempo.tv_sec * 1000 + tempo.tv_usec / 1000; | |
159 | - | |
160 | - deltaTAux = (tAux2 - tAux)*1000; | |
161 | - } | |
162 | - | |
163 | - //desconto = (deltaTAux - (tsleep/1000))*1000; | |
164 | - *desconto = (deltaTAux - tsleep); | |
165 | -} | |
166 | - | |
167 | -char* proximo = new char[1000]; | |
168 | -char* proximo2 = new char[1000]; | |
169 | - | |
170 | -char * Synchronizer::getproximoarquivo() { | |
171 | - char * video = new char[1000]; | |
172 | - string s1, s2, s3; | |
173 | - video = NULL; | |
174 | - list<char *>::iterator it; | |
175 | - //proximo = NULL; | |
176 | - | |
177 | - if (videos->size() == 0) { | |
178 | - if(this->transparency == 0){ | |
179 | - return VIDEO_PADRAO; | |
180 | - }else{ | |
181 | - return VIDEOTRANSP_PADRAO; | |
182 | - } | |
183 | - } | |
184 | - | |
185 | - mutexi->Lock(); | |
186 | - video = videos->front(); | |
187 | - | |
188 | - videos->erase(videos->begin()); | |
189 | - mutexi->Unlock(); | |
190 | - | |
191 | - if (video == NULL) { | |
192 | - if(this->transparency == 0){ | |
193 | - return VIDEO_PADRAO; | |
194 | - }else{ | |
195 | - return VIDEOTRANSP_PADRAO; | |
196 | - } | |
197 | - }else{ | |
198 | - return video; | |
199 | - } | |
200 | -} | |
201 | - | |
202 | -void Synchronizer::analisaPCR(unsigned char *pacote) { | |
203 | - // preciso ter o PID de PCR | |
204 | - if ((getPid(pacote) != PCRPID) || (!contemAF(pacote)) | |
205 | - //if ((!contemAF(pacote)) | |
206 | - || (getTamanhoAF(pacote) == 0) || (!contemPCR(pacote))) { | |
207 | - | |
208 | - | |
209 | - if (contemPCR(pacote)){ | |
210 | - //printf("Encontrei PCR - PID:%d\n", getPid(pacote)); | |
211 | - | |
212 | - } | |
213 | - return; | |
214 | - } | |
215 | - | |
216 | - uint64_t pcrBase = retornaPCRBase(pacote); | |
217 | - | |
218 | - if (mediaDiferencaPCR != 0 && contagemPCR == 0) { // nesse caso esse eh o primeiro PCR de um novo video | |
219 | - //printf("Encontrei o primeiro PCR de um video!\n"); | |
220 | - setPCRBase(pacote, pcrBaseGeral + mediaDiferencaPCR); // tem que multiplicar por 2 o mediaDiferencaPCR? | |
221 | - ultimoPCRBaseMod = pcrBaseGeral + mediaDiferencaPCR; | |
222 | - mediaDiferencaPCR = 0; | |
223 | - } else if (mediaDiferencaPCR == 0 && contagemPCR == 0 && flagPrimeiroArquivo == 1) { | |
224 | - flagPrimeiroArquivo = 0; | |
225 | - setPCRBase(pacote, pcr_inicial + mediaDiferencaPCR); // tem que multiplicar por 2 o mediaDiferencaPCR? | |
226 | - contagemPCR++; | |
227 | - sleep(1); | |
228 | - ultimoPCRBaseMod = pcr_inicial + mediaDiferencaPCR; | |
229 | - | |
230 | - } | |
231 | - else { | |
232 | - | |
233 | - mediaDiferencaPCR = (ultimoPCRBase > 0) ? pcrBase - ultimoPCRBase : 0; | |
234 | - contagemPCR++; | |
235 | - | |
236 | - //if (pcrBaseGeral != 0) { // se nao for o primeiro video //2 - Mudei para o serviço | |
237 | - setPCRBase(pacote, ultimoPCRBaseMod + mediaDiferencaPCR); | |
238 | - ultimoPCRBaseMod += mediaDiferencaPCR; | |
239 | - //} | |
240 | - } | |
241 | - | |
242 | - ultimoPCRBase = pcrBase; | |
243 | - | |
244 | -} | |
245 | - | |
246 | -void Synchronizer::analisaPTSDTS(unsigned char *pacote) { | |
247 | - int inicioPESData = 4; | |
248 | - if (contemAF(pacote)) inicioPESData += getTamanhoAF(pacote) + 1; | |
249 | - | |
250 | - if ((!verificaPESStartCode(pacote + inicioPESData)) || | |
251 | - (!verificaPESStreamID(pacote + inicioPESData)) || | |
252 | - (!contemPTS(pacote + inicioPESData))) { | |
253 | - | |
254 | - return; | |
255 | - } | |
256 | - | |
257 | - uint64_t PTS = retornaPTS(pacote + inicioPESData); | |
258 | - int diferenca = PTS - ultimoPCRBase; | |
259 | - // confirmar se isso aqui SEMPRE eh chamado depois de pelo menos um PCR ser encontrado, principalmente | |
260 | - // no inicio do video | |
261 | - if (ultimoPCRBaseMod != 0) | |
262 | - setNovoPTS(pacote + inicioPESData, ultimoPCRBaseMod + diferenca); | |
263 | - else | |
264 | - setNovoPTS(pacote + inicioPESData, pcrBaseGeral + diferenca); | |
265 | - | |
266 | - if (!contemDTS(pacote + inicioPESData)) return; | |
267 | - | |
268 | - uint64_t DTS = retornaDTS(pacote + inicioPESData); | |
269 | - diferenca = DTS - ultimoPCRBase; | |
270 | - | |
271 | - if (ultimoPCRBaseMod != 0) | |
272 | - setNovoDTS(pacote + inicioPESData, ultimoPCRBaseMod + diferenca); | |
273 | - else | |
274 | - setNovoDTS(pacote + inicioPESData, pcrBaseGeral + diferenca); | |
275 | -} | |
276 | - | |
277 | -int Synchronizer::getPid(unsigned char *pacote) { | |
278 | - return ((pacote[1] & 0x1F) << 8) | pacote[2]; | |
279 | -} | |
280 | - | |
281 | -bool Synchronizer::contemAF(unsigned char *pacote) { | |
282 | - return pacote[3] & 0x20; | |
283 | -} | |
284 | - | |
285 | -int Synchronizer::getTamanhoAF(unsigned char *pacote) { | |
286 | - return pacote[4]; | |
287 | -} | |
288 | - | |
289 | -bool Synchronizer::contemPCR(unsigned char *pacote) { | |
290 | - return pacote[5] & 0x10; | |
291 | -} | |
292 | - | |
293 | -uint64_t Synchronizer::retornaPCRBase(unsigned char *pacote) { | |
294 | - uint64_t pcrbase = 0; | |
295 | - | |
296 | - pcrbase = (uint64_t) pacote[6] << 25 | pacote[7] << 17 | pacote[8] << 9 | |
297 | - | pacote[9] << 1 | (pacote[10] & 0x80) >> 7; | |
298 | - | |
299 | - return pcrbase; | |
300 | -} | |
301 | - | |
302 | -void Synchronizer::setPCRBase(unsigned char *pacote, uint64_t pcrbase) { | |
303 | - pacote[6] = pcrbase >> 25; | |
304 | - pacote[7] = pcrbase >> 17; | |
305 | - pacote[8] = pcrbase >> 9; | |
306 | - pacote[9] = pcrbase >> 1; | |
307 | - if ((pcrbase << 63) != 0) | |
308 | - pacote[10] = pacote[10] | 0x80; | |
309 | - else | |
310 | - pacote[10] = pacote[10] & 0x7F; | |
311 | -} | |
312 | - | |
313 | -bool Synchronizer::contemPayloadStartIndicator(unsigned char *pacote) { | |
314 | - return pacote[1] & 0x40; | |
315 | -} | |
316 | - | |
317 | -bool Synchronizer::contemPayloadData(unsigned char *pacote) { | |
318 | - return pacote[3] & 0x10; | |
319 | -} | |
320 | - | |
321 | -bool Synchronizer::verificaPESStartCode(unsigned char *PESPacket) { | |
322 | - return (((PESPacket[0] << 16) | (PESPacket[1] << 8) | (PESPacket[2])) | |
323 | - == 0x000001) ? 1 : 0; | |
324 | -} | |
325 | - | |
326 | -bool Synchronizer::verificaPESStreamID(unsigned char *PESPacket) { | |
327 | - int stream_id = PESPacket[3]; | |
328 | - | |
329 | - return ((stream_id != 0xBC) && (stream_id != 0xBE) && (stream_id != 0xBF) | |
330 | - && (stream_id != 0xF0) && (stream_id != 0xF1) && (stream_id != 0xFF) | |
331 | - && (stream_id != 0xF2) && (stream_id != 0xF8)); | |
332 | -} | |
333 | - | |
334 | -bool Synchronizer::contemPTS(unsigned char *PESPacket) { | |
335 | - //printf("\nTem PTS: %d\n", PESPacket[7] & 0x80); | |
336 | - return PESPacket[7] & 0x80; | |
337 | -} | |
338 | - | |
339 | -bool Synchronizer::contemDTS(unsigned char *PESPacket) { | |
340 | - return PESPacket[7] & 0x40; | |
341 | -} | |
342 | - | |
343 | -uint64_t Synchronizer::retornaPTS(unsigned char *PESPacket) { | |
344 | - uint64_t PTS = (uint64_t) ((PESPacket[9] & 0x0E) >> 1) << 30 | | |
345 | - (PESPacket[10] << 22) | | |
346 | - (((PESPacket[11] & 0xFE) >> 1) << 15) | | |
347 | - (PESPacket[12] << 7) | | |
348 | - ((PESPacket[13] & 0xFE) >> 1); | |
349 | - return PTS; | |
350 | -} | |
351 | - | |
352 | -uint64_t Synchronizer::retornaDTS(unsigned char *PESPacket) { | |
353 | - uint64_t DTS = (uint64_t) ((PESPacket[14] & 0x0E) >> 1) << 30 | | |
354 | - (PESPacket[15] << 22) | | |
355 | - (((PESPacket[16] & 0xFE) >> 1) << 15) | | |
356 | - (PESPacket[17] << 7) | | |
357 | - ((PESPacket[18] & 0xFE) >> 1); | |
358 | - return DTS; | |
359 | -} | |
360 | - | |
361 | -void Synchronizer::setNovoPTS(unsigned char *pacote, uint64_t PTS) { | |
362 | - pacote[9] = pacote[9] & 0xF1; | |
363 | - pacote[9] = pacote[9] | ((PTS >> 30) << 1); | |
364 | - pacote[10] = PTS >> 22; | |
365 | - pacote[11] = pacote[11] & 0x1; | |
366 | - pacote[11] = pacote[11] | ((PTS >> 15) << 1); | |
367 | - pacote[12] = PTS >> 7; | |
368 | - pacote[13] = pacote[13] & 0x1; | |
369 | - pacote[13] = pacote[13] | PTS << 1; | |
370 | -} | |
371 | - | |
372 | -void Synchronizer::setNovoDTS(unsigned char *pacote, uint64_t DTS) { | |
373 | - pacote[14] = pacote[14] & 0xF1; | |
374 | - pacote[14] = pacote[14] | ((DTS >> 30) << 1); | |
375 | - pacote[15] = DTS >> 22; | |
376 | - pacote[16] = pacote[16] & 0x1; | |
377 | - pacote[16] = pacote[16] | ((DTS >> 15) << 1); | |
378 | - pacote[17] = DTS >> 7; | |
379 | - pacote[18] = pacote[18] & 0x1; | |
380 | - pacote[18] = pacote[18] | DTS << 1; | |
381 | -} | |
382 | - | |
383 | -void Synchronizer::escrevePacote(char *pacote) { | |
384 | - if (!escreveAux.is_open()) { | |
385 | - escreveAux.open(this->path_libras, ios::out | ios::binary); | |
386 | - | |
387 | - } | |
388 | - //printf("tamanho do pacote = %d\n\n", strlen(pacote)); | |
389 | - escreveAux.write(pacote, 188*70); | |
390 | - //printf(" OK!\n\n"); | |
391 | - | |
392 | -} | |
393 | - | |
394 | -int Synchronizer::escrevePacote(int * descritor, char *pacote, int size) { | |
395 | - if (*descritor < 0) {// ainda não abri | |
396 | - *descritor = open(this->path_libras, O_WRONLY | O_CREAT, 0660); | |
397 | - if (descritor < 0) { | |
398 | - printf("Can't open output file\n"); | |
399 | - return -1; | |
400 | - } | |
401 | - } | |
402 | - return write(*descritor, pacote, size); | |
403 | -} | |
404 | - | |
405 | -void ouch(int sig) { | |
406 | - printf("\nSinal Capturado %d", sig); | |
407 | - (void) signal(SIGPIPE, SIG_DFL); | |
408 | - | |
409 | -} | |
410 | - | |
411 | -void Synchronizer::soletraGlosa(string glosa, int64_t pts) { | |
412 | - | |
413 | - //string path = (string) baseDir + glosa + (string) extensao; | |
414 | - //cout << "\n***Glosa NAO ENCONTRADA: " << glosa << endl; | |
415 | - /*mutexi->Lock(); | |
416 | - int file = open(converteString(path), O_RDONLY); | |
417 | - mutexi->Unlock();*/ | |
418 | - //if (file != NULL) { | |
419 | - for (int i = 0; i < glosa.length(); i++) { | |
420 | - if (glosa[i] == '[') | |
421 | - return; | |
422 | - char c = glosa[i]; | |
423 | - if (c >= 97 && c <= 122) { | |
424 | - string path2 = (string) baseDir + glosa[i] + (string) extensao; | |
425 | - char* path2_char = converteString(path2); | |
426 | - recebeglosa(converteString(path2), strlen(path2_char), pts); | |
427 | - } | |
428 | - } | |
429 | - //close(file); | |
430 | - //} else { | |
431 | - // printf("*** ERRO ao abrir o arquivo."); | |
432 | - //} | |
433 | - | |
434 | -} | |
435 | - | |
436 | -/* Utilizado no teste de Eduardo */ | |
437 | -void Synchronizer::recebeglosa(string glosa, int64_t pts) { | |
438 | - glosa = toLower(glosa); | |
439 | - | |
440 | - size_t found; | |
441 | - found=glosa.rfind("dl"); | |
442 | - if (found == 0) | |
443 | - glosa = glosa.substr(2, glosa.length()); | |
444 | - | |
445 | - string path = (string) baseDir + glosa.c_str() + (string) extensao; | |
446 | - char* urlchar = converteString(path); | |
447 | - mutexi->Lock(); | |
448 | - FILE *f = fopen(urlchar, "r"); | |
449 | - mutexi->Unlock(); | |
450 | - if (f == NULL) { | |
451 | - soletraGlosa(glosa, pts); | |
452 | - } else { | |
453 | - fclose(f); | |
454 | - recebeglosa(urlchar, strlen(urlchar), pts); | |
455 | - } | |
456 | - | |
457 | -} | |
458 | - | |
459 | - | |
460 | -void Synchronizer::addListener(ListenerSynchronizer* listener) { | |
461 | - listeners->push_back(listener); | |
462 | -} | |
463 | - | |
464 | -void Synchronizer::removeListener(ListenerSynchronizer* listener) { | |
465 | - listeners->remove(listener); | |
466 | -} | |
467 | - | |
468 | -void Synchronizer::notifyListeners() { | |
469 | - for (list<ListenerSynchronizer*>::iterator i = listeners->begin(); i != listeners->end(); i++) { | |
470 | - (*i)->notifyEndOfSynchronization(); | |
471 | - } | |
472 | -} | |
473 | - | |
474 | -void Synchronizer::Run() { | |
475 | - | |
476 | - pcrBaseGeral = ultimoPCRBase = mediaDiferencaPCR = contagemPCR = ultimoPCRBaseMod = 0; | |
477 | - int64_t t0 = 0, tf = 0; | |
478 | - int64_t pts_run; | |
479 | - int cnt, finalcnt, bitrate = 1121600, deltaT = 0; | |
480 | - int bufferSize = 7 * 188; | |
481 | - char * buff = new char[bufferSize]; | |
482 | - | |
483 | - char * arquivo; | |
484 | - | |
485 | - while (videos->size() == 0){ | |
486 | - usleep(50000); //50ms | |
487 | - } | |
488 | - | |
489 | - if(this->transparency == 0) | |
490 | - arquivo = VIDEO_PADRAO; | |
491 | - else | |
492 | - arquivo = VIDEOTRANSP_PADRAO; | |
493 | - | |
494 | - mutexi->Lock(); | |
495 | - filefd = open(arquivo, O_RDONLY); | |
496 | - mutexi->Unlock(); | |
497 | - | |
498 | - if (filefd < 0) | |
499 | - cout << "NAO CONSEGUI ABRIR O ARQUIVO2 - " << arquivo << endl; | |
500 | - | |
501 | - (void) signal(SIGPIPE, ouch); | |
502 | - | |
503 | - int videos_processed = 0; | |
504 | - | |
505 | - int desc_out = -1; | |
506 | - | |
507 | - while (videos_processed <= count_tasks || service_running) { | |
508 | - | |
509 | - cnt = read(filefd, buff, bufferSize); | |
510 | - | |
511 | - // atualiza os valores de PCR e PTS/DTS para cada video | |
512 | - for (int i = 0; i < cnt / 188; i++) { | |
513 | - analisaPCR((unsigned char*) buff + (188 * i)); | |
514 | - analisaPTSDTS((unsigned char*) buff + (188 * i)); | |
515 | - } | |
516 | - | |
517 | - escrevePacote(&desc_out,buff,cnt); | |
518 | - free(buff); | |
519 | - buff = new char[bufferSize]; | |
520 | - | |
521 | - finalcnt = cnt; | |
522 | - if (finalcnt == 0) { | |
523 | - | |
524 | - while (videos->size() == 0 && service_running) { // esperando arquivos do serviço | |
525 | - usleep(10000); | |
526 | - } | |
527 | - | |
528 | - pts_run = vector_pts->front(); | |
529 | - if (ultimoPCRBaseMod + tempo_poseneutra < pts_run) { | |
530 | - if(this->transparency == 0){ | |
531 | - arquivo = VIDEO_PADRAO; | |
532 | - }else{ | |
533 | - arquivo = VIDEOTRANSP_PADRAO; | |
534 | - } | |
535 | - | |
536 | - }else { | |
537 | - if (vector_pts->size() > 0) { | |
538 | - vector_pts->erase(vector_pts->begin()); | |
539 | - arquivo = getproximoarquivo(); | |
540 | - } | |
541 | - videos_processed++; | |
542 | - } | |
543 | - | |
544 | - close(filefd); | |
545 | - filefd = open(arquivo, O_RDONLY); | |
546 | - if (ultimoPCRBase != 0) { | |
547 | - if (ultimoPCRBaseMod != 0) { | |
548 | - pcrBaseGeral = ultimoPCRBaseMod; | |
549 | - } else { | |
550 | - pcrBaseGeral = ultimoPCRBase; | |
551 | - } | |
552 | - contagemPCR = 0; | |
553 | - ultimoPCRBaseMod = 0; | |
554 | - } | |
555 | - } else if (finalcnt == -1) { | |
556 | - printf("Erro: Finalizando Sincronizador!\n"); | |
557 | - this->stop(); | |
558 | - } | |
559 | - } // Fim do while! | |
560 | - | |
561 | - //fsync(desc_out); | |
562 | - close(filefd); | |
563 | - close(desc_out); | |
564 | - notifyListeners(); | |
565 | - | |
566 | -} | |
567 | - | |
568 | - |