main.cpp
9.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
* File: main.cpp
* Author: felipe
*
* Created on 15 de Outubro de 2009, 10:56
*/
/*
* File: main.cpp
* Author: Erickson
*
* Edit on 03 de Fevereiro de 2014
*/
#include "serviceWindowGenerationFromSRT.h"
#include "serviceWindowGenerationFromRec.h"
#include "serviceWindowGenerationFromText.h"
#include "serviceException.h"
#include <sys/time.h>
#include <stdlib.h>
using namespace std;
void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position, char* size, char* transparency, char* id, char* client_type);
void serviceOnlySRT(char* service, char* path_file, char* transparency, char* username, char* client_type);
//void serviceREC(char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* username, char* rate);
void serviceREC(char* service, char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* id, char* client_type);
//void serviceOnlyAudio(char* path_audio, char* transparency, char* username, char* rate);
void serviceOnlyAudio(char* service, char* path_audio, char* transparency, char* id, char* client_type);
void serviceText(char* service, char* path_text, char* transparency, char* id, char* client_type);
void help();
void serviceHelp(int service);
void fail(string msg);
void hasFailed();
void hasInvalid();
bool isFailed;
bool isInvalid;
int main(int argc, char* argv[]) {
struct timeval tv1, tv2;
double t1, t2;
gettimeofday(&tv1, NULL);
t1 = (double)(tv1.tv_sec) + (double)(tv1.tv_usec)/ 1000000.00;
if(argc > 2) {
printf("\n################## VLIBRAS : LAVID ##################\n\n");
DDPRINTF("Service Type: %s\n", argv[1]);
switch((int) atoi(argv[1])){
case 1:
if(argc <= 9){
serviceHelp(1);
hasInvalid();
}else{
serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]);
}
break;
case 2:
if(argc <= 8){
serviceHelp(2);
hasInvalid();
}else{
serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
}
break;
case 3:
if(argc <= 5){
serviceHelp(3);
hasInvalid();
}else{
serviceText(argv[1], argv[2], argv[3], argv[4], argv[5]);
}
break;
case 4:
if(argc <= 5){
serviceHelp(4);
hasInvalid();
}else{
serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], argv[5]);
}
break;
case 5:
if(argc <= 5){
serviceHelp(5);
hasInvalid();
}else{
serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], argv[5]);
}
break;
default:
cout << "\nFAIL VLibras: Serviço inválido! Tente --help" << endl;
hasInvalid();
break;
}
}else if(argc == 2 && (strcmp(argv[1], "--help")) == 0){
help();
exit(0);
}else{
cout << "\nFAIL VLibras: Tente --help para obter informações.\n" << endl;
hasInvalid();
}
if(isFailed)
exit(1);
else if(isInvalid)
exit(127);
gettimeofday(&tv2, NULL);
t2 = (double)(tv2.tv_sec) + (double)(tv2.tv_usec)/ 1000000.00;
DDPRINTF("Time: %lf\n", (t2-t1));
DDPRINTF("VLibras finalized!\n\n");
exit(0);
}
void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position,
char* size, char* transparency, char* id, char* client_type){
ServiceWindowGenerationFromSRT * service_srt;
service_srt = new ServiceWindowGenerationFromSRT(path_video, path_srt, (int) atoi(sublanguage),
(int) atoi(position), (int) atoi(size), (int) atoi(transparency), id, client_type, (int) atoi(service));
try{
service_srt->initialize();
}catch(ServiceException ex){
fail(ex.getMessage());
hasFailed();
return;
}
while(!service_srt->isFinished()){
sleep(5);
}
delete service_srt;
}
void serviceREC(char* service, char* path_video, char* sublanguage, char* position, char* size,
char* transparency, char* id, char* client_type){
ServiceWindowGenerationFromRec * service_rec;
service_rec = new ServiceWindowGenerationFromRec(path_video, (int) atoi(sublanguage),
(int) atoi(position), (int) atoi(size), (int) atoi(transparency), id, client_type, (int) atoi(service));
try{
service_rec->initialize();
}catch(ServiceException ex){
fail(ex.getMessage());
hasFailed();
return;
}
while(!service_rec->isFinished()){
sleep(2);
}
delete service_rec;
}
void serviceText(char* service, char* path_text, char* transparency, char* id, char* client_type){
ServiceWindowGenerationFromText *service_text;
service_text = new ServiceWindowGenerationFromText(path_text, (int) atoi(transparency), id, client_type);
try{
service_text->initialize();
}catch(ServiceException ex){
fail(ex.getMessage());
hasFailed();
return;
}
while (!service_text->isFinished()) {
usleep(100000); //100ms
}
delete service_text;
}
void serviceOnlySRT(char* service, char* path_file, char* transparency, char* id, char* client_type){
ServiceWindowGenerationFromSRT * service_srt;
service_srt = new ServiceWindowGenerationFromSRT(path_file, (int) atoi(transparency), id, client_type, (int) atoi(service));
try{
service_srt->initialize();
}catch(ServiceException ex){
fail(ex.getMessage());
hasFailed();
return;
}
while (!service_srt->isFinished()) {
usleep(100000); //100ms
}
delete service_srt;
}
void serviceOnlyAudio(char* service, char* path_audio, char* transparency, char* id, char* client_type){
ServiceWindowGenerationFromRec * service_rec;
service_rec = new ServiceWindowGenerationFromRec(path_audio, 0, 0, 0, (int) atoi(transparency), id, client_type, (int) atoi(service));
try{
service_rec->initialize();
}catch(ServiceException ex){
fail(ex.getMessage());
hasFailed();
return;
}
while(!service_rec->isFinished()){
sleep(2);
}
delete service_rec;
}
/*void serviceREC(char* path_video, char* sublanguage,
char* position, char* size, char* transparency, char* id, char* rate){
ServiceWindowGenerationFromREC * service_rec;
service_rec = new ServiceWindowGenerationFromREC(
path_video,
(int) atoi(sublanguage),
(int) atoi(position),
(int) atoi(size),
(int) atoi(transparency),
id, 2, rate);
try{
service_rec->initialize();
}catch(ServiceException ex){
fail(ex.getMessage());
hasFailed();
return;
}
while(!service_rec->isFinished()){
sleep(2);
}
delete service_rec;
}*/
/*void serviceOnlyAudio(char* path_audio, char* transparency, char* id, char* rate){
ServiceWindowGenerationFromREC * service_rec;
service_rec = new ServiceWindowGenerationFromREC(
path_audio,
0,
0,
0,
(int) atoi(transparency),
id, 5, rate);
try{
service_rec->initialize();
}catch(ServiceException ex){
fail(ex.getMessage());
hasFailed();
return;
}
while(!service_rec->isFinished()){
sleep(2);
}
delete service_rec;
}*/
void fail(string msg){
printf("\n");
DDDDPRINTF("Ops... Tivemos um problema! :(\n");
DDDDPRINTF("Possível causa do erro: %s\n\n", msg.c_str());
}
void hasFailed(){
isFailed = true;
}
void hasInvalid(){
isInvalid = true;
}
void serviceHelp(int service){
cout << "\nParâmetros inválidos! Tente novamente.\n";
switch(service){
case 1:
cout << "\nService Type: Video with Subtitles\n"
<< "./vlibras INPUT_VIDEO INPUT_SRT LANGUAGE(1: Portuguese, 2:Glosa) POSITION(1: Top_Left, 2: Top_Right, 3: Bottom_Right, 4: Bottom_Left) "
<< "SIZE(1: Small, 2: Medium, 3: Large) TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n";
break;
case 2:
cout << "\nService Type: Video Recognize\n"
<< "./vlibras INPUT_VIDEO LANGUAGE(1: Portuguese, 2:Glosa) POSITION(1: Top_Left, 2: Top_Right, 3: Bottom_Right, 4: Bottom_Left) "
<< "SIZE(1: Small, 2: Medium, 3: Large) TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n";
break;
case 3:
cout << "\nService Type: Text\n"
<< "./vlibras INPUT_TEXT_FILE TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n";
break;
case 4:
cout << "\nService Type: Subtitles only\n"
<< "./vlibras INPUT_SRT TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n";
break;
case 5:
cout << "\nService Type: Audio Recognize\n"
<< "./vlibras INPUT_AUDIO TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n";
break;
}
}
//Help do programa, explicando todos os parâmetros existentes...
void help() {
cout << endl
<< "Usage Summary: vlibras [SERVICE] [INPUT] ... [TRANSPARENCY] [ID] [CLIENT_TYPE]\n"
<< "\nSERVICE:\n"
<< "1 Video with Subtitles (SRT) - requires INPUT_VIDEO and INPUT_SRT\n"
<< "2 Video Recognize - requires INPUT_VIDEO\n"
<< "3 Text - requires INPUT_TEXT_FILE\n"
<< "4 Subtitles only (SRT) - requires INPUT_SRT\n"
<< "5 Audio Recognize - requires INPUT_AUDIO\n"
<< "\nSERVICES PARAMETERS:\n"
<< "Video with subtitles:\n"
<< " [INPUT_VIDEO] [INPUT_SRT] [LANGUAGE] [POSITION] [SIZE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n"
<< "\nVideo Recognize:\n"
<< " [INPUT_VIDEO] [LANGUAGE] [POSITION] [SIZE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n"
<< "\nText:\n"
<< " [INPUT_TEXT_FILE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n"
<< "\nSubtitles only:\n"
<< " [INPUT_SRT] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n"
<< "\nAudio Recognize\n"
<< " [INPUT_AUDIO] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n"
<< "\nPARAMETERS:\n"
<< "INPUT_VIDEO Path of the video file\n"
<< "INPUT_SRT Path of the subtitle file\n"
<< "INPUT_TEXT_FILE Path of the text file\n"
<< "INPUT_AUDIO Path of the audio file\n"
<< "LANGUAGE 1 - means Portuguese, 2 - means Glosa\n"
<< "POSITION 1 - means Top_Left, 2 - means Top_Right, 3 - means Bottom_Right, 4 - means Bottom_Left\n"
<< "SIZE 1 - means Small, 2 - means Medium, 3 - means Large\n"
<< "TRANSPARENCY 0 - means that the background is opaque , 1 - means that the background is transparent\n"
<< "ID Relative to the unique ID on the Database\n"
<< "CLIENT_TYPE prod - means that the client is web/cloud, devel - means that the client is developer\n"
<< endl;
}