Commit 4eeb9359f380ba016a464b50ce6d4df10c698b25

Authored by Wesnydy Ribeiro
1 parent cb055103
Exists in master and in 1 other branch devel

Adaptado o padrão de desenvolvimento dos componentes input, synchronizer e tradutor

Makefile
... ... @@ -20,7 +20,7 @@ logger.o
20 20 tradutorObjs = \
21 21 pyTradutor.o \
22 22 tradutorPortGlosa.o \
23   -ouvinteTradutor.o
  23 +#ouvinteTradutor.o
24 24  
25 25 extratorSRTObjs = \
26 26 extratorSRT.o \
... ... @@ -37,7 +37,6 @@ monitor_pcr.o
37 37 inputObjs = \
38 38 inputFile.o \
39 39 inputException.o \
40   -ouvinteInput.o
41 40  
42 41 servicoObjs = \
43 42 serviceWindowGeneration.o \
... ... @@ -48,7 +47,6 @@ serviceException.o
48 47  
49 48 synchronizerObjs = \
50 49 synchronizer.o \
51   -ouvinteSynchronizer.o
52 50  
53 51 mixerObjs = \
54 52 Mixer.o
... ...
extratorSRT/src/extratorSRT.cpp
1 1  
2   -
3 2 #include "extratorSRT.h"
4 3  
5   -using namespace std;
6 4  
7 5 ExtratorSRT::ExtratorSRT(){
8 6 listeners = new list<ListenerSRT*>();
... ... @@ -30,8 +28,8 @@ void ExtratorSRT::initialize(){
30 28 file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ);
31 29 }catch(Exception ex){
32 30 finish = true;
33   - Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorSRT.cpp] Arquivo de texto não encontrado.");
34   - throw ExtratorSrtException("Falha ao abrir o arquivo de texto! Verifique se o mesmo existe.\n");
  31 + Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorSRT.cpp] Arquivo de legenda não encontrado.");
  32 + throw ExtratorSrtException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.\n");
35 33 }
36 34  
37 35 this->Start();
... ... @@ -93,13 +91,13 @@ void ExtratorSRT::Run(){
93 91 Subtitle* ExtratorSRT::next() {
94 92  
95 93 if (seek_pos >= file_io->getSize())
96   - throw ExtratorSrtException("[ERRO: reader_srt.cpp] Esse arquivo já foi lido.");
  94 + throw ExtratorSrtException("[ERRO: extratorSRT.cpp] Esse arquivo já foi lido.");
97 95  
98 96 file_io->seek(seek_pos);
99 97 try{
100 98 bff_reader = new BufferedReader(file_io);
101 99 }catch(Exception &ex){
102   - throw ExtratorSrtException("[ERRO: reader_srt.cpp] O BufferedReader não foi inicializado.");
  100 + throw ExtratorSrtException("[ERRO: extratorSRT.cpp] O BufferedReader não foi inicializado.");
103 101 }
104 102  
105 103 Subtitle* sub = new Subtitle();
... ...
extratorSRT/src/include/extratorSRT.h
... ... @@ -8,10 +8,6 @@
8 8 #ifndef EXTRATORSRT_H
9 9 #define EXTRATORSRT_H
10 10  
11   -//#define MAX_LINE 1024
12   -#define SIZE_CSCAPE 1
13   -#define TARGET_TIME "-->"
14   -
15 11 #include <string.h>
16 12 #include <stdlib.h>
17 13 #include <fstream>
... ... @@ -30,6 +26,10 @@
30 26 #include "listenerMonitorPCRBase.h"
31 27 #include "extratorSRT_exception.h"
32 28  
  29 +#define SIZE_CSCAPE 1
  30 +#define TARGET_TIME "-->"
  31 +//#define MAX_LINE 1024
  32 +
33 33 using namespace jthread;
34 34 using namespace std;
35 35 using namespace sndesc;
... ... @@ -51,7 +51,6 @@ public:
51 51 void initialize();
52 52 void Run();
53 53  
54   - /* @Override: reader.h */
55 54 Subtitle* next();
56 55  
57 56 void notifyPCRBase(uint64_t pcrbase);
... ... @@ -59,12 +58,12 @@ public:
59 58 private:
60 59  
61 60 list<ListenerSRT*> *listeners;
62   - char* filepath;
  61 + char *filepath;
63 62 bool finish;
64   - File* file;
  63 + File *file;
65 64 FileIO *file_io;
66 65 BufferedReader *bff_reader;
67   - Subtitle * subtitle;
  66 + Subtitle *subtitle;
68 67  
69 68 uint64_t pcr_base;
70 69 int64_t seek_pos;
... ...
extratorSRT/src/include/subtitle.h
... ... @@ -13,12 +13,12 @@
13 13 #ifndef SUBTITLE_H
14 14 #define SUBTITLE_H
15 15  
16   - #define MAX_FIELD 64
17   -
18 16 #include <string>
19 17 #include <stdint.h>
20 18 #include <stdio.h>
21 19  
  20 + #define MAX_FIELD 64
  21 +
22 22 namespace sndesc {
23 23  
24 24 class Subtitle {
... ...
extratorTXT/src/extratorTXT.cpp
... ... @@ -11,8 +11,6 @@
11 11  
12 12 #include "extratorTXT.h"
13 13  
14   -using namespace std;
15   -
16 14 ExtratorTXT::ExtratorTXT(){
17 15 listeners = new list<ListenerTXT*>();
18 16 finish = false;
... ... @@ -25,7 +23,7 @@ ExtratorTXT::~ExtratorTXT(){
25 23 delete file;
26 24 delete file_io;
27 25 delete bff_reader;
28   - DDDPRINTF("Extractor Text finalized!\n");
  26 + DDDPRINTF("Extractor TXT finalized!\n");
29 27 }
30 28  
31 29 void ExtratorTXT::initialize(){
... ... @@ -45,16 +43,16 @@ void ExtratorTXT::addListener(ListenerTXT* listener){
45 43 listeners->push_back(listener);
46 44 }
47 45  
48   -void ExtratorTXT::notifyListeners(unsigned char* subtitle) {
  46 +void ExtratorTXT::notifyListeners(unsigned char* line) {
49 47 for(list<ListenerTXT*>::iterator it = listeners->begin(); it != listeners->end(); it++){
50   - (*it)->notificaTradutor(subtitle);
  48 + (*it)->notifyLine(line);
51 49 }
52 50 }
53 51  
54   -void ExtratorTXT::notifyEndExtraction(int sub_size) {
55   - DDPRINTF("Extrator Text concluiu a extração: %d linhas.\n", sub_size);
  52 +void ExtratorTXT::notifyEndExtraction(int line_size) {
  53 + DDPRINTF("ExtratorTXT concluiu a extração: %d linhas.\n", line_size);
56 54 for(list<ListenerTXT*>::iterator it = listeners->begin(); it != listeners->end(); it++){
57   - (*it)->notifyEnd(sub_size);
  55 + (*it)->notifyEnd(line_size);
58 56 }
59 57 }
60 58  
... ...
extratorTXT/src/include/extratorTXT.h
... ... @@ -34,8 +34,8 @@ public:
34 34 ~ExtratorTXT();
35 35  
36 36 void addListener(ListenerTXT* listener);
37   - void notifyListeners(unsigned char* subtitle);
38   - void notifyEndExtraction(int sub_size);
  37 + void notifyListeners(unsigned char* line);
  38 + void notifyEndExtraction(int line_size);
39 39  
40 40 void setFilePath(char* path);
41 41 bool isFinished();
... ...
extratorTXT/src/include/listenerTXT.h
... ... @@ -17,7 +17,7 @@
17 17 class ListenerTXT {
18 18  
19 19 public:
20   - virtual void notificaTradutor(unsigned char* line) = 0;
  20 + virtual void notifyLine(unsigned char* line) = 0;
21 21 virtual void notifyEnd(int line_size) = 0;
22 22 };
23 23  
... ...
input/src/include/inputFile.h
... ... @@ -8,36 +8,37 @@
8 8 #ifndef INPUTFILE_H
9 9 #define INPUTFILE_H
10 10  
  11 +#include <stdio.h>
  12 +#include <list>
  13 +#include <stdlib.h>
11 14 #include <fstream>
12 15 #include <string.h>
13 16 #include "logger.h"
14   -#include "ouvinteInput.h"
  17 +#include "listenerInput.h"
15 18 #include "inputException.h"
16 19 #include "dprintf.h"
17 20  
  21 +#define MAX_SIZE_PACKET 188
18 22  
19 23 using namespace std;
20 24  
21 25 class InputFile {
22 26  
23   -public:
24   - static const int MAX_SIZE_PACKET = 188;
25   - bool finished;
26   -
  27 +public:
27 28 InputFile(char* path);
28 29 ~InputFile();
29 30 void initialize();
30   - void registraOuvinte(OuvinteInput *ouvinte);
31   - void removeOuvinte(OuvinteInput *ouvinte);
32   - void notificaOuvintes(unsigned char * pacote);
  31 + void addListener(ListenerInput* listener);
  32 + void removeListener(ListenerInput* listener);
  33 + void notifyListeners(unsigned char* pack);
33 34 bool isFinished();
34 35  
35 36 //void notificaQuantidadeGlosas(int quantidade);
36 37  
37 38 private:
38   -
39   - char * path;
40   - list<OuvinteInput*> *ouvintes;
  39 + list<ListenerInput*> *listeners;
  40 + char *path;
  41 + bool finish;
41 42  
42 43 };
43 44  
... ...
input/src/include/listenerInput.h 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +/*
  2 + * File: ouvinteInput.h
  3 + * Author: derzu
  4 + *
  5 + * Created on 8 de Fevereiro de 2010, 18:19
  6 + */
  7 +
  8 +#ifndef _LISTENERINPUT_H
  9 +#define _LISTENERINPUT_H
  10 +
  11 +class ListenerInput {
  12 +public:
  13 + virtual void notifyInput(unsigned char *pack)=0;
  14 + //virtual void finalizouInput()=0;
  15 +
  16 +};
  17 +
  18 +#endif /* _LISTENERINPUT_H */
  19 +
... ...
input/src/include/ouvinteInput.h
... ... @@ -1,23 +0,0 @@
1   -/*
2   - * File: ouvinteInput.h
3   - * Author: derzu
4   - *
5   - * Created on 8 de Fevereiro de 2010, 18:19
6   - */
7   -
8   -#ifndef _OUVINTEINPUT_H
9   -#define _OUVINTEINPUT_H
10   -
11   -class OuvinteInput {
12   -public:
13   - OuvinteInput();
14   - virtual ~OuvinteInput();
15   - virtual void chegouInput(unsigned char *pacote)=0;
16   - //virtual void finalizouInput()=0;
17   -
18   -private:
19   -
20   -};
21   -
22   -#endif /* _OUVINTEINPUT_H */
23   -
input/src/inputFile.cpp
1   -#include <stdio.h>
2   -#include <list>
3   -#include <stdlib.h>
4 1  
5 2 #include "inputFile.h"
6   -#include "ouvinteInput.h"
7 3  
8 4 InputFile::InputFile(char* path) {
9 5 this->path = path;
10   - this->ouvintes = new list<OuvinteInput*>();
11   - finished = false;
  6 + this->listeners = new list<ListenerInput*>();
  7 + finish = false;
12 8 DPRINTF("Done!\n");
13 9 }
14 10  
15 11 InputFile::~InputFile(){
16   - ouvintes->clear();
17   - delete ouvintes;
  12 + listeners->clear();
  13 + delete listeners;
18 14 DDDPRINTF("Input finalized!\n");
19 15 }
20 16  
... ... @@ -28,36 +24,36 @@ void InputFile::initialize(){
28 24 while (!filein.eof()) {
29 25 filein.read(buffer, MAX_SIZE_PACKET);
30 26 unsigned char* packet = (unsigned char*) buffer;
31   - notificaOuvintes(packet);
  27 + notifyListeners(packet);
32 28 }
33 29 printf("\n");
34 30 filein.close();
35 31 //finished = true;
36 32 } else {
37   - finished = true;
  33 + finish = true;
38 34 Util::Logger::Instance()->writeLog((char*) "[ERRO: inputFile.cpp] Arquivo de vídeo não encontrado.");
39 35 throw InputException("Falha ao abrir o arquivo de vídeo! Verifique se o mesmo existe.");
40 36 }
41 37 }
42   - finished = true;
  38 + finish = true;
43 39  
44 40 }
45 41  
46 42 bool InputFile::isFinished(){
47   - return this->finished;
  43 + return this->finish;
48 44 }
49 45  
50   -void InputFile::registraOuvinte(OuvinteInput* ouvinte){
51   - this->ouvintes->push_back(ouvinte);
  46 +void InputFile::addListener(ListenerInput* listener){
  47 + this->listeners->push_back(listener);
52 48 }
53 49  
54   -void InputFile::removeOuvinte(OuvinteInput* ouvinte) {
55   - this->ouvintes->remove(ouvinte);
  50 +void InputFile::removeListener(ListenerInput* listener) {
  51 + this->listeners->remove(listener);
56 52 }
57 53  
58   -void InputFile::notificaOuvintes(unsigned char* pacote){
59   - for(list<OuvinteInput*>::iterator it = this->ouvintes->begin(); it != this->ouvintes->end(); it++){
60   - (*it)->chegouInput(pacote);
  54 +void InputFile::notifyListeners(unsigned char* pack){
  55 + for(list<ListenerInput*>::iterator it = this->listeners->begin(); it != this->listeners->end(); it++){
  56 + (*it)->notifyInput(pack);
61 57 }
62 58 }
63 59  
... ...
input/src/ouvinteInput.cpp
... ... @@ -1,14 +0,0 @@
1   -/*
2   - * File: ouvinteInput.cpp
3   - * Author: derzu
4   - *
5   - * Created on 8 de Fevereiro de 2010, 18:19
6   - */
7   -
8   -#include "ouvinteInput.h"
9   -
10   -OuvinteInput::OuvinteInput() {
11   -}
12   -
13   -OuvinteInput::~OuvinteInput() {
14   -}
mixer/src/Mixer.cpp
... ... @@ -4,11 +4,7 @@
4 4 *
5 5 * Created on 17 de Janeiro de 2012, 15:28
6 6 */
7   -
8 7 #include "Mixer.h"
9   -#define PATH_API "vlibras_user/vlibras-api/videos/"
10   -
11   -using namespace std;
12 8  
13 9 /* Construtores e destrutores...*/
14 10 Mixer::Mixer() {
... ...
mixer/src/include/Mixer.h
... ... @@ -5,13 +5,9 @@
5 5 * Created on 17 de Janeiro de 2012, 15:28
6 6 */
7 7  
8   -
9   -
10   -
11 8 #ifndef MIXER_H
12 9 #define MIXER_H
13 10  
14   -
15 11 #include "string.h"
16 12 #include <cstdlib>
17 13 #include <iostream>
... ... @@ -30,7 +26,6 @@ using namespace std;
30 26 #define TOP_RIGHT 2
31 27 #define BOTTOM_RIGHT 3
32 28 #define BOTTOM_LEFT 4
33   -
34 29 //SL Video Size
35 30 #define SMALL 1
36 31 #define MEDIUM 2
... ... @@ -40,7 +35,9 @@ using namespace std;
40 35 #define MEDIUM_HEIGHT 432 //0,4*1080
41 36 #define LARGE_HEIGHT 540 //0.5*1080
42 37  
  38 +#define PATH_API "vlibras_user/vlibras-api/videos/"
43 39  
  40 +using namespace std;
44 41  
45 42 class Mixer {
46 43 public:
... ...
monitorPCR/src/include/monitor_pcr.h
... ... @@ -8,20 +8,24 @@
8 8 #ifndef MONITOR_PCR_H
9 9 #define MONITOR_PCR_H
10 10  
  11 +#include <stdio.h>
  12 +#include <string.h>
  13 +#include <locale>
11 14 #include <stdint.h>
12   -#include "ouvinteInput.h"
13   -#include "listenerMonitorPCRBase.h"
14 15 #include <list>
  16 +#include "listenerInput.h"
  17 +#include "listenerMonitorPCRBase.h"
15 18 #include "dprintf.h"
16 19  
  20 +#define PCRBASE_PADRAO 1000000
17 21  
18 22 using namespace std;
19 23  
20   -class MonitorPCR: public OuvinteInput {
  24 +class MonitorPCR: public ListenerInput {
21 25  
22 26 public:
23 27  
24   - char* extvideo;
  28 + char* extvideo;
25 29  
26 30 MonitorPCR();
27 31 ~MonitorPCR();
... ... @@ -29,7 +33,7 @@ class MonitorPCR: public OuvinteInput {
29 33 void addListenerPCRBase(ListenerMonitorPCRBase * listener);
30 34 void notifyListenersWithPCRBase(uint64_t pcrbase);
31 35 uint64_t getPCRBase();
32   - void chegouInput(unsigned char* packet);
  36 + void notifyInput(unsigned char* packet);
33 37  
34 38 /**
35 39 * Informa para o monitor o formato do vídeo que está sendo manipulado.
... ...
monitorPCR/src/monitor_pcr.cpp
1   -#include <stdio.h>
2   -#include <string.h>
3   -#include <locale>
4 1 #include "monitor_pcr.h"
5   -#define PCRBASE_PADRAO 1000000
6   -using namespace std;
7 2  
8 3 MonitorPCR::MonitorPCR(){
9 4 pcr_base = 0;
... ... @@ -29,7 +24,7 @@ void MonitorPCR::setFormatVideo(char* format) {
29 24 }
30 25  
31 26  
32   -void MonitorPCR::chegouInput(unsigned char* packet) {
  27 +void MonitorPCR::notifyInput(unsigned char* packet) {
33 28  
34 29 if (!find) { // verifica se o PCRBase já foi encontrado
35 30 *extvideo = tolower(*extvideo);
... ...
recognize/src/include/recognize.h
... ... @@ -4,18 +4,46 @@
4 4 #include <stdint.h>
5 5 #include <string.h>
6 6 #include <list>
  7 +#include <fstream>
  8 +#include <stdio.h>
  9 +#include <sstream>
  10 +#include <algorithm>
  11 +#include <vector>
  12 +#include <iterator>
  13 +#include <sys/stat.h>
  14 +#include <lavidlib/io/FileIO.h>
7 15 #include "dprintf.h"
8 16 #include "logger.h"
9   -
10 17 #include "listenerMonitorPCRBase.h"
11 18 #include "recognizeListener.h"
12 19 #include "recognizeException.h"
13 20  
  21 +#define FREQUENCY_PATTERN 22050
  22 +#define INPUT_PATTERN 1 /* 1 = Raw file, 2 = Mic */
  23 +#define BLOCS_PATTERN 10
  24 +#define SIZE_BUFFER 256
  25 +#define CONFIDENCE_RATE 0.45
  26 +
  27 +#define PATH_API_UPLOADS "vlibras_user/vlibras-api/uploads/"
  28 +#define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav"
  29 +#define PATH_AUDIO_PARTS "/audio/parts/"
  30 +#define FILENAME_RECOGNIZED_OUT "/audio/recognized.out"
  31 +#define FILENAME_AUDIOLIST "/audio/audiolist"
  32 +#define FILENAME_FILTEROUT "/audio/filter"
  33 +#define FILENAME_CONFIDENCEOUT "/audio/confidence"
  34 +
  35 +#define FIND_CONFIDENCE "\"cmscore1:\""
  36 +#define FIND_SENTENCE "\"sentence1:\""
  37 +
  38 +#define FILENAME_AUDIOPART "audio00"
  39 +#define AUDIO_SILENT "<input rejected by short input>"
  40 +
  41 +#define PROGRAM "ffmpeg" // ffmpeg
  42 +#define PTS_PATTERN 1000
14 43  
15 44 using namespace jthread;
16 45 using namespace std;
17 46  
18   -
19 47 class Recognize: public Thread, public ListenerMonitorPCRBase {
20 48  
21 49 public:
... ... @@ -56,7 +84,7 @@ private:
56 84 char* pathVideo;
57 85 string id;
58 86 float confidenceRate;
59   - bool finished;
  87 + bool finish;
60 88 vector<float> scores;
61 89 vector<int64_t> pts;
62 90  
... ...
recognize/src/recognize.cpp
1   -#include <fstream>
2   -#include <stdio.h>
3   -#include <sstream>
4   -#include <stdlib.h>
5   -#include <algorithm>
6   -#include <vector>
7   -#include <iterator>
8   -#include <stdlib.h>
9   -#include <iostream>
10   -#include <string>
11   -#include <sys/stat.h>
12   -
13   -#include <lavidlib/io/FileIO.h>
14   -
15 1 #include <recognize.h>
16 2  
17   -#define FREQUENCY_PATTERN 22050
18   -#define INPUT_PATTERN 1 /* 1 = Raw file, 2 = Mic */
19   -#define BLOCS_PATTERN 10
20   -#define SIZE_BUFFER 256
21   -#define CONFIDENCE_RATE 0.45
22   -
23   -#define PATH_API_UPLOADS "vlibras_user/vlibras-api/uploads/"
24   -#define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav"
25   -#define PATH_AUDIO_PARTS "/audio/parts/"
26   -#define FILENAME_RECOGNIZED_OUT "/audio/recognized.out"
27   -#define FILENAME_AUDIOLIST "/audio/audiolist"
28   -#define FILENAME_FILTEROUT "/audio/filter"
29   -#define FILENAME_CONFIDENCEOUT "/audio/confidence"
30   -
31   -#define FIND_CONFIDENCE "\"cmscore1:\""
32   -#define FIND_SENTENCE "\"sentence1:\""
33   -
34   -#define FILENAME_AUDIOPART "audio00"
35   -#define AUDIO_SILENT "<input rejected by short input>"
36   -
37   -#define PROGRAM "ffmpeg" // ffmpeg
38   -#define PTS_PATTERN 1000
39   -
40   -using namespace std;
41   -
42   -
43 3 Recognize::Recognize(char* _pathVideo, char* _id) {
44 4  
45 5 listeners = new list<RecognizeListener*>();
... ... @@ -102,7 +62,7 @@ void Recognize::initialize() {
102 62  
103 63 ifstream file(pathVideo, ifstream::binary);
104 64 if(!file.is_open()){
105   - finished = true;
  65 + finish = true;
106 66 Util::Logger::Instance()->writeLog((char*) "[ERRO: recognize.cpp] Arquivo não encontrado.");
107 67 throw RecognizeException("Falha ao abrir o arquivo! Verifique se o mesmo existe.");
108 68 }
... ... @@ -111,7 +71,7 @@ void Recognize::initialize() {
111 71  
112 72 void Recognize::Run(){
113 73  
114   - finished = false;
  74 + finish = false;
115 75 createDir();
116 76 extractAudioFromVideo();
117 77 breakVideoParts(getTimeMediaSec());
... ... @@ -120,7 +80,7 @@ void Recognize::Run(){
120 80 filterOutputJulius();
121 81 //cleanFiles();
122 82  
123   - finished = true;
  83 + finish = true;
124 84 notifyEndExtraction(count_lines);
125 85 }
126 86  
... ... @@ -429,7 +389,7 @@ void Recognize::addListener(RecognizeListener* listener) {
429 389  
430 390  
431 391 bool Recognize::isFinished() {
432   - return finished;
  392 + return finish;
433 393 }
434 394  
435 395  
... ...
servico/src/include/serviceWindowGeneration.h
... ... @@ -5,13 +5,13 @@
5 5 #include <locale>
6 6 #include <string>
7 7 #include "dprintf.h"
8   -#include "ouvinteTradutor.h"
  8 +#include "listenerTradutor.h"
9 9 #include "tradutorPortGlosa.h"
10 10 #include <iostream>
11 11 #include <vector>
12 12 //#include "httpstreamer.h"
13 13 #include "synchronizer.h"
14   -#include "ouvinteSynchronizer.h"
  14 +#include "listenerSynchronizer.h"
15 15 #include "Mixer.h"
16 16 #include <fcntl.h>
17 17 #include "listenerMonitorPCRBase.h"
... ... @@ -23,6 +23,13 @@
23 23 #include "serviceException.h"
24 24 #include <lavidlib/base/RuntimeException.h>
25 25  
  26 +#define VIDEO_POSE_NEUTRA "poseneutra"
  27 +#define BASEDIR "vlibras_user/dicionario_libras/"
  28 +#define BASEDIRTRANSP "vlibras_user/dicionarioTransp_libras/"
  29 +#define EXTENSAO_DICIONARIO ".ts"
  30 +#define PATH_API "vlibras_user/vlibras-api/videos/"
  31 +#define MAX_SIZE_PATH 256
  32 +
26 33 /*#define SERVICE_TYPE_CC 1 /* Closed Caption */
27 34 #define SERVICE_TYPE_SRT 2 /* Subtitle SRT */
28 35 #define SERVICE_TYPE_REC 3 /* Reconhecimento de Voz */
... ... @@ -34,7 +41,7 @@ using namespace Tradutor;
34 41 using namespace Util;
35 42 using namespace std;
36 43  
37   -class ServiceWindowGeneration : public OuvinteTradutor, public OuvinteSynchronizer{
  44 +class ServiceWindowGeneration : public ListenerTradutor, public ListenerSynchronizer{
38 45  
39 46 protected:
40 47  
... ... @@ -76,9 +83,8 @@ public:
76 83  
77 84 ServiceWindowGeneration();
78 85 ~ServiceWindowGeneration();
79   - //virtual void notificaGlosaTraduzida( vector<string> * glosas);
80   - virtual void codifica(vector<string> * glosas);
81   - virtual void finalizouSincronizacao();
  86 + virtual void notifyTranslation(vector<string>* glosas);
  87 + virtual void notifyEndOfSynchronization();
82 88 //virtual void notifyPCRBase(uint64_t pcr_base);
83 89 void initialize();
84 90 TradutorPortGlosa * getTradutor();
... ...
servico/src/include/serviceWindowGenerationFromText.h
... ... @@ -19,7 +19,7 @@ public:
19 19 ServiceWindowGenerationFromText (char* _path_file, char* _video_path_file,
20 20 int _transp, int _serviceType, char* _client_type);
21 21 ~ServiceWindowGenerationFromText ();
22   - void notificaTradutor(unsigned char* legenda);
  22 + void notifyLine(unsigned char* line);
23 23 void notifyEnd(int line_size);
24 24 void initialize();
25 25 bool isAlive();
... ...
servico/src/serviceWindowGeneration.cpp
1 1  
2 2 #include "serviceWindowGeneration.h"
3 3  
4   -#define VIDEO_POSE_NEUTRA "poseneutra"
5   -#define BASEDIR "vlibras_user/dicionario_libras/"
6   -#define BASEDIRTRANSP "vlibras_user/dicionarioTransp_libras/"
7   -#define EXTENSAO_DICIONARIO ".ts"
8   -#define PATH_API "vlibras_user/vlibras-api/videos/"
9   -#define MAX_SIZE_PATH 256
10   -
11   -
12 4 ServiceWindowGeneration::ServiceWindowGeneration() {
13 5 if (getRunningOption() != '3') {
14 6 tradutor = new TradutorPortGlosa();
... ... @@ -45,7 +37,7 @@ bool ServiceWindowGeneration::isRunning() {
45 37 }
46 38  
47 39 /* Quando o sincronizador termina, ele invoca esse método para avisar! */
48   -void ServiceWindowGeneration::finalizouSincronizacao() {
  40 +void ServiceWindowGeneration::notifyEndOfSynchronization() {
49 41 if (getRunningOption() != '2' && serviceType == SERVICE_TYPE_REC || serviceType == SERVICE_TYPE_SRT) {
50 42 mixer = new Mixer();
51 43 mixer->initialize(this->path_input, this->path_libras,this->position,this->size,this->transparency, this->user_id);
... ... @@ -141,7 +133,7 @@ void ServiceWindowGeneration::initialize() {
141 133  
142 134 this->finish = false;
143 135 if (getRunningOption() != '3' && this->sublanguage == 1) {
144   - tradutor->registraOuvinte(this);
  136 + tradutor->addListener(this);
145 137 }
146 138  
147 139 // o path do arquivo só poderá conter um "."(ponto), esse identifica a extensão.
... ... @@ -165,7 +157,7 @@ void ServiceWindowGeneration::initialize() {
165 157 //printf("O ServiceWGeneration montou o seguinte path para o vídeo de Libras: %s\n", path_libras);
166 158  
167 159 } else {
168   - tradutor->registraOuvinte(this);
  160 + tradutor->addListener(this);
169 161 }
170 162  
171 163 if(this->transparency == 0) { //pega dicionario com BackGround opaco
... ... @@ -194,13 +186,12 @@ void ServiceWindowGeneration::initialize() {
194 186 }
195 187 }
196 188  
197   - sincronizador->registraOuvinte(this);
  189 + sincronizador->addListener(this);
198 190 sincronizador->Start();
199 191 }
200 192  
201 193 /* Método utilizado pelo Tradutor para notificar o texto traduzido. */
202   -void ServiceWindowGeneration::codifica(vector<string> * glosas) {
203   -
  194 +void ServiceWindowGeneration::notifyTranslation(vector<string> * glosas) {
204 195 if (serviceType != SERVICE_TYPE_TEXT) {
205 196 for (int i = 0; i < glosas->size(); i++) {
206 197 std::locale loc;
... ... @@ -237,9 +228,7 @@ void ServiceWindowGeneration::codifica(vector&lt;string&gt; * glosas) {
237 228 }
238 229  
239 230 void ServiceWindowGeneration::transcodeVideoToWebm() {
240   -
241 231 //printf("[INFO]: A transcodificação para .webm está ativada!\n");
242   -
243 232 string command = "ffmpeg -i ";
244 233 command.append(path_libras)
245 234 .append(" -vcodec libvpx -acodec libvorbis ")
... ... @@ -251,11 +240,9 @@ void ServiceWindowGeneration::transcodeVideoToWebm() {
251 240 }
252 241  
253 242 void ServiceWindowGeneration::transcodeVideoToMp4() {
254   -
255 243 if (serviceType == SERVICE_TYPE_TEXT && strcmp(client_type, (char*)"WEB") == 0)
256 244 transcodeVideoToWebm();
257 245 else{
258   -
259 246 //printf("[INFO]: A transcodificação para .mp4 está ativada!\n");
260 247 string command = "ffmpeg -i ";
261 248 command.append(path_libras)
... ... @@ -268,12 +255,10 @@ void ServiceWindowGeneration::transcodeVideoToMp4() {
268 255  
269 256 //.append(" -strict experimental -vcodec mjpeg -r 30 -pix_fmt yuvj422p ")
270 257 //.append(" -strict experimental -vcodec mpeg2video -r 30 ")
271   -
272 258 }
273 259 }
274 260  
275 261 void ServiceWindowGeneration::createThumbnail(){
276   -
277 262 string command = "ffmpeg -ss 10 -i ";
278 263 command.append(PATH_API).append(user_id).append(".mp4")
279 264 .append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 ")
... ...
servico/src/serviceWindowGenerationFromREC.cpp
1 1 #include "serviceWindowGenerationFromREC.h"
2 2  
3   -using namespace std;
4   -
5 3 ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC(
6 4 char* path_video, int sublanguage, int position, int size, int transparency, char* id, int serviceType, char* rate) {
7 5  
... ... @@ -51,7 +49,7 @@ void ServiceWindowGenerationFromREC::initialize() {
51 49 }
52 50  
53 51 monitor_pcr_base->addListenerPCRBase(rec);
54   - inputfile->registraOuvinte(monitor_pcr_base);
  52 + inputfile->addListener(monitor_pcr_base);
55 53 try{
56 54 inputfile->initialize();
57 55 } catch(InputException ex){
... ...
servico/src/serviceWindowGenerationFromSRT.cpp
1 1 #include "serviceWindowGenerationFromSRT.h"
2 2  
3   -using namespace std;
4 3  
5 4 //Construtor Service 2
6 5 ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(
... ... @@ -103,7 +102,7 @@ void ServiceWindowGenerationFromSRT::initialize() {
103 102  
104 103 monitor_pcr_base->addListenerPCRBase(extratorSRT);
105 104  
106   - inputfile->registraOuvinte(monitor_pcr_base);
  105 + inputfile->addListener(monitor_pcr_base);
107 106 extratorSRT->addListener(this);
108 107 extratorSRT->setFilePath((char*) path_srt);
109 108  
... ...
servico/src/serviceWindowGenerationFromText.cpp
... ... @@ -35,11 +35,11 @@ void ServiceWindowGenerationFromText::initialize() {
35 35 }
36 36  
37 37 void ServiceWindowGenerationFromText::notifyEnd(int line_size) {
38   - DDPRINTF("Service SRT recebeu: %d linhas.\n", line_size);
  38 + DDPRINTF("Service TXT recebeu: %d linhas.\n", line_size);
39 39 setSizeOfSubtitles(line_size);
40 40 }
41 41  
42   -void ServiceWindowGenerationFromText::notificaTradutor(unsigned char* line) {
  42 +void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) {
43 43 tradutor->traduz(line);
44 44 }
45 45  
... ...
synchronizer/src/include/listenerSynchronizer.h 0 → 100644
... ... @@ -0,0 +1,14 @@
  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
0 15 \ No newline at end of file
... ...
synchronizer/src/include/ouvinteSynchronizer.h
... ... @@ -1,20 +0,0 @@
1   -#ifndef _OUVINTE_SYNCHRONIZER_H
2   -#define _OUVINTE_SYNCHRONIZER_H
3   -
4   -#include <string>
5   -#include <stdint.h>
6   -
7   -using namespace std;
8   -
9   -class OuvinteSynchronizer {
10   -public:
11   - OuvinteSynchronizer();
12   - virtual ~OuvinteSynchronizer();
13   -
14   - // inclusão do parâmetro "long int pts"
15   - virtual void finalizouSincronizacao() = 0;
16   -private:
17   -
18   -};
19   -
20   -#endif
21 0 \ No newline at end of file
synchronizer/src/include/synchronizer.h
1 1 #ifndef SYNCHRONIZER_H
2 2 #define SYNCHRONIZER_H
3 3  
4   -#include "jthread.h"
5 4 #include <stdio.h>
6 5 #include <stdlib.h>
7 6 #include <string.h>
8 7 #include <errno.h>
9   -#include <arpa/inet.h>
10   -#include <sys/socket.h>
11   -#include <fcntl.h>
12   -#include <sys/time.h>
13 8 #include <time.h>
14 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>
15 18 #include <fstream>
  19 +#include "dprintf.h"
16 20 #include "jmutex.h"
17   -#include <signal.h>
18   -#include "ouvinteSynchronizer.h"
  21 +#include "jthread.h"
  22 +#include "listenerSynchronizer.h"
19 23 #include "listenerMonitorPCRBase.h"
  24 +//#include "httpstreamer.h"
20 25  
21   -#include <vector>
22   -#include <list>
  26 +#define VIDEO_PADRAO "vlibras_user/dicionario_libras/poseneutra.ts"
  27 +#define VIDEOTRANSP_PADRAO "vlibras_user/dicionarioTransp_libras/poseneutra.ts"
  28 +
  29 +//DICIONARIO 30 fps
  30 +#define PCRPID 256
  31 +#define PESPID 256
  32 +
  33 +//DICIONARIO 45 fps
  34 +//#define PCRPID 4097
  35 +//#define PESPID 4113
23 36  
24 37 using namespace jthread;
25 38 using namespace std;
26 39  
27 40 class Synchronizer : public jthread::Thread, public ListenerMonitorPCRBase {
  41 +
28 42 private:
29 43 bool hastext;
30 44 int taxa;
31 45 int filefd;
32 46 vector <char*> *videos;
33 47 int devicetv;
  48 +
34 49 uint64_t pcrBaseGeral;
35 50 uint64_t ultimoPCRBase;
36 51 uint64_t ultimoPCRBaseMod;
  52 + int64_t pcr_inicial;
37 53 int mediaDiferencaPCR;
38 54 int contagemPCR;
  55 +
39 56 ofstream escreveAux;
40 57 char* extensao;
41 58 char* baseDir;
42   - int64_t pcr_inicial;
  59 +
43 60 int64_t tempo_poseneutra;
44 61 vector <int64_t> *vector_pts;
45 62 int flagPrimeiroArquivo;
46   - list<OuvinteSynchronizer*> * ouvintes;
47   - char* path_libras;
  63 +
  64 + list<ListenerSynchronizer*> * listeners;
48 65 Mutex* mutex_sync;
  66 + Mutex* mutexi;
49 67  
  68 + char* path_libras;
50 69 int transparency;
51 70  
52 71 int count_tasks;
... ... @@ -57,13 +76,14 @@ public:
57 76 Synchronizer();
58 77 Synchronizer(/*int64_t pcr_inicial, */char*baseDir, char* extensao, char* path_libras, int transparency);
59 78 virtual ~Synchronizer();
  79 +
60 80 virtual void notifyPCRBase(uint64_t pcr_base);
61 81 void setPCRBase(uint64_t pcr_base);
62   - //em fase de teste
63   - void soletraGlosa(string glosa, int64_t pts);
64 82  
65 83 void Run();
66 84 void stop();
  85 +
  86 + void soletraGlosa(string glosa, int64_t pts);//em fase de teste
67 87 void recebeglosa(char * video, int tam, int64_t pts);
68 88 void recebeglosa(string glosa, int64_t pts);
69 89 char * getproximoarquivo();
... ... @@ -98,9 +118,9 @@ public:
98 118 void escrevePacote(char *pacote);
99 119 int escrevePacote(int * descritor, char *pacote, int size);
100 120  
101   - virtual void registraOuvinte(OuvinteSynchronizer * ouvinte);
102   - virtual void removeOuvinte(OuvinteSynchronizer * ouvinte);
103   - virtual void notificaOuvintes();
  121 + virtual void addListener(ListenerSynchronizer* listener);
  122 + virtual void removeListener(ListenerSynchronizer* listener);
  123 + virtual void notifyListeners();
104 124  
105 125 };
106 126  
... ...
synchronizer/src/ouvinteSynchronizer.cpp
... ... @@ -1,7 +0,0 @@
1   -#include "ouvinteSynchronizer.h"
2   -
3   -OuvinteSynchronizer::OuvinteSynchronizer() {
4   -}
5   -
6   -OuvinteSynchronizer::~OuvinteSynchronizer() {
7   -}
synchronizer/src/synchronizer.cpp
1   -#include <stdio.h>
2   -#include <iostream>
3   -#include "dprintf.h"
4 1 #include "synchronizer.h"
5   -//#include "httpstreamer.h"
6   -#include "jmutex.h"
7   -#define VIDEO_PADRAO "vlibras_user/dicionario_libras/poseneutra.ts"
8   -#define VIDEOTRANSP_PADRAO "vlibras_user/dicionarioTransp_libras/poseneutra.ts"
9   -
10   -//DICIONARIO 45 fps
11   -//#define PCRPID 4097
12   -//#define PESPID 4113
13   -
14   -
15   -//DICIONARIO 30 fps
16   -#define PCRPID 256
17   -#define PESPID 256
18   -
19   -Mutex* mutexi = new Mutex();
20 2  
21 3 Synchronizer::Synchronizer() {
22 4 baseDir = (char*) "vlibras_user/dicionario_libras/";
... ... @@ -24,6 +6,7 @@ Synchronizer::Synchronizer() {
24 6 filefd = 0;
25 7 videos = new vector <char*> ();
26 8 vector_pts = new vector <int64_t > ();
  9 + this->mutexi = new Mutex();
27 10  
28 11 this->baseDir = new char[strlen(baseDir) + 1];
29 12 strcpy(this->baseDir, baseDir);
... ... @@ -31,7 +14,7 @@ Synchronizer::Synchronizer() {
31 14 this->extensao = new char[strlen(extensao) + 1];
32 15 strcpy(this->extensao, extensao);
33 16 flagPrimeiroArquivo = 1;
34   - ouvintes = new list<OuvinteSynchronizer*>();
  17 + listeners = new list<ListenerSynchronizer*>();
35 18 this->path_libras = path_libras;
36 19 DPRINTF("Done!\n")
37 20 }
... ... @@ -50,7 +33,6 @@ Synchronizer::Synchronizer(/*int64_t pcr_inicial, */char* baseDir, char* extensa
50 33  
51 34 //cout << "\n\nTransparencia: " << this->transparency << "\n";
52 35  
53   -
54 36 this->baseDir = new char[strlen(baseDir) + 1];
55 37 strcpy(this->baseDir, baseDir);
56 38  
... ... @@ -67,22 +49,22 @@ Synchronizer::Synchronizer(/*int64_t pcr_inicial, */char* baseDir, char* extensa
67 49 contagemPCR = 0;
68 50 vector_pts = new vector <int64_t > ();
69 51 flagPrimeiroArquivo = 1;
70   - ouvintes = new list<OuvinteSynchronizer*>();
  52 + listeners = new list<ListenerSynchronizer*>();
71 53 this->path_libras = new char[strlen(path_libras) + 1];
72 54 strcpy(this->path_libras, path_libras);
73 55 //cout << "-> path libras sync: " << path_libras << endl;
74 56 this->mutex_sync = new Mutex();
  57 + this->mutexi = new Mutex();
75 58  
76 59 DPRINTF("Done!\n")
77   -
78 60 }
79 61  
80 62 Synchronizer::~Synchronizer() {
81 63 free(videos);
82   - ouvintes->clear();
83   - delete ouvintes;
  64 + listeners->clear();
  65 + delete listeners;
84 66 if (escreveAux.is_open()) escreveAux.close();
85   - DDDPRINTF("Synchronized finalized!\n");
  67 + DDDPRINTF("Synchronizer finalized!\n");
86 68  
87 69 }
88 70  
... ... @@ -108,12 +90,10 @@ string toLower(string strr) {
108 90 return ret;
109 91 }
110 92  
111   -
112 93 void Synchronizer::setPCRBase(uint64_t pcr_base){
113 94 this->pcr_inicial = pcr_base;
114 95 }
115 96  
116   -
117 97 char* converteString(string palavra) {
118 98  
119 99 const char* aux = new char[palavra.size()];
... ... @@ -123,9 +103,6 @@ char* converteString(string palavra) {
123 103 return aux2;
124 104 }
125 105  
126   -
127   -
128   -
129 106 /* Método utilizado pelos serviços (Services Generation) para informar que
130 107 este processo pode ser finalizado após a demanda atual, isto é, depois
131 108 que terminar de gerar os vídeos que estão na fila.
... ... @@ -226,7 +203,6 @@ char * Synchronizer::getproximoarquivo() {
226 203  
227 204 }
228 205  
229   -
230 206 void Synchronizer::analisaPCR(unsigned char *pacote) {
231 207 // preciso ter o PID de PCR
232 208 if ((getPid(pacote) != PCRPID) || (!contemAF(pacote))
... ... @@ -272,8 +248,6 @@ void Synchronizer::analisaPCR(unsigned char *pacote) {
272 248 }
273 249  
274 250 void Synchronizer::analisaPTSDTS(unsigned char *pacote) {
275   -
276   -
277 251 int inicioPESData = 4;
278 252 if (contemAF(pacote)) inicioPESData += getTamanhoAF(pacote) + 1;
279 253  
... ... @@ -488,17 +462,17 @@ void Synchronizer::recebeglosa(string glosa, int64_t pts) {
488 462 }
489 463  
490 464  
491   -void Synchronizer::registraOuvinte(OuvinteSynchronizer * ouvinte) {
492   - ouvintes->push_back(ouvinte);
  465 +void Synchronizer::addListener(ListenerSynchronizer* listener) {
  466 + listeners->push_back(listener);
493 467 }
494 468  
495   -void Synchronizer::removeOuvinte(OuvinteSynchronizer * ouvinte) {
496   - ouvintes->remove(ouvinte);
  469 +void Synchronizer::removeListener(ListenerSynchronizer* listener) {
  470 + listeners->remove(listener);
497 471 }
498 472  
499   -void Synchronizer::notificaOuvintes() {
500   - for (list<OuvinteSynchronizer*>::iterator i = ouvintes->begin(); i != ouvintes->end(); i++) {
501   - (*i)->finalizouSincronizacao();
  473 +void Synchronizer::notifyListeners() {
  474 + for (list<ListenerSynchronizer*>::iterator i = listeners->begin(); i != listeners->end(); i++) {
  475 + (*i)->notifyEndOfSynchronization();
502 476 }
503 477 }
504 478  
... ... @@ -592,7 +566,7 @@ void Synchronizer::Run() {
592 566 //fsync(desc_out);
593 567 close(filefd);
594 568 close(desc_out);
595   - notificaOuvintes();
  569 + notifyListeners();
596 570  
597 571 }
598 572  
... ...
tradutor/src/include/listenerTradutor.h 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +/*
  2 + * File: ouvinteTradutor.h
  3 + * Author: derzu
  4 + *
  5 + * Created on 2 de Fevereiro de 2010, 15:48
  6 + */
  7 +#ifndef _LISTENERTRADUTOR_H
  8 +#define _LISTENERTRADUTOR_H
  9 +
  10 +#include <string>
  11 +#include <vector>
  12 +
  13 +namespace Tradutor {
  14 +
  15 + class ListenerTradutor {
  16 + public:
  17 + //OuvinteTradutor();
  18 + //virtual ~OuvinteTradutor();
  19 +
  20 + // Metodo que vai ser chamado quando chegar a traducao
  21 + virtual void notifyTranslation(std::vector<std::string> * glosas) = 0;
  22 + };
  23 +
  24 +}
  25 +
  26 +#endif /* _LISTENERTRADUTOR_H */
... ...
tradutor/src/include/ouvinteTradutor.h
... ... @@ -1,27 +0,0 @@
1   -/*
2   - * File: ouvinteTradutor.h
3   - * Author: derzu
4   - *
5   - * Created on 2 de Fevereiro de 2010, 15:48
6   - */
7   -
8   -#ifndef _OUVINTETRADUTOR_H
9   -#define _OUVINTETRADUTOR_H
10   -
11   -#include <string>
12   -#include <vector>
13   -
14   -namespace Tradutor {
15   -
16   - class OuvinteTradutor {
17   - public:
18   - OuvinteTradutor();
19   - virtual ~OuvinteTradutor();
20   -
21   - // Metodo que vai ser chamado quando chegar a traducao
22   - virtual void codifica(std::vector<std::string> * glosas)=0;
23   - };
24   -
25   -}
26   -
27   -#endif /* _OUVINTETRADUTOR_H */
tradutor/src/include/pyTradutor.h
... ... @@ -11,18 +11,19 @@
11 11 #define _PYTRADUTOR_H
12 12  
13 13 namespace Tradutor {
  14 +
14 15 class PyTradutor{
15   - public:
16   - PyTradutor();
17   - ~PyTradutor();
18   - char * convertStringToGlosa(const char * input);
19   - PyObject * pName;
20   - PyObject * pModule;
21   - PyObject * pDict;
22   - PyObject * pFunc;
23   - PyObject * pArgs;
24   - PyObject * pResult;
25   - bool isRunning;
  16 + public:
  17 + PyTradutor();
  18 + ~PyTradutor();
  19 + char * convertStringToGlosa(const char * input);
  20 + PyObject * pName;
  21 + PyObject * pModule;
  22 + PyObject * pDict;
  23 + PyObject * pFunc;
  24 + PyObject * pArgs;
  25 + PyObject * pResult;
  26 + bool isRunning;
26 27 };
27 28 }
28 29  
... ...
tradutor/src/include/tradutorPortGlosa.h
... ... @@ -12,44 +12,45 @@
12 12 * @date 21/10/2009
13 13 *
14 14 */
15   -
16 15 #include <iostream>
17 16 #include <list>
18 17 #include <pthread.h>
19   -#include "ouvinteTradutor.h"
  18 +#include "listenerTradutor.h"
20 19 #include "pyTradutor.h"
21   -#include "ouvinteInput.h"
  20 +#include "listenerInput.h"
22 21 #include "dprintf.h"
23 22  
24 23 #ifndef _GERADOR_GLOSA_H_
25 24 #define _GERADOR_GLOSA_H_
26 25  
  26 +using namespace std;
  27 +
27 28 namespace Tradutor {
28 29  
29   - class TradutorPortGlosa : public OuvinteInput{
  30 + class TradutorPortGlosa : public ListenerInput{
30 31 public:
31   - TradutorPortGlosa();
32   - virtual ~TradutorPortGlosa();
33   - std::vector<std::string> * portuguesToGlosaVector(const char * input);
34   - std::vector<std::string> * portuguesToGlosaVectorSplit(char * pGlosa);
  32 + TradutorPortGlosa();
  33 + virtual ~TradutorPortGlosa();
  34 + std::vector<std::string> * portuguesToGlosaVector(const char * input);
  35 + std::vector<std::string> * portuguesToGlosaVectorSplit(char * pGlosa);
35 36  
36   - // Adiciona
37   - void registraOuvinte(OuvinteTradutor * ouvinte);
38   - // Remove
39   - void removeOuvinte(OuvinteTradutor * ouvinte);
  37 + // Adiciona
  38 + void addListener(ListenerTradutor * listener);
  39 + // Remove
  40 + void removeListener(ListenerTradutor * listener);
40 41  
41   - void traduz(unsigned char * texto);
42   - virtual void chegouInput(unsigned char * texto);
43   - //virtual void notificaCC(unsigned char * cc, int64_t pts);
  42 + void traduz(unsigned char * texto);
  43 + virtual void notifyInput(unsigned char * texto);
  44 + //virtual void notificaCC(unsigned char * cc, int64_t pts);
44 45  
45 46  
46 47 private:
47   - void notificaOuvintes(std::vector<std::string> * traducao);
  48 + void notifyListeners(std::vector<std::string> * traducao);
48 49  
49   - std::list<OuvinteTradutor*> * ouvintes;
50   - PyTradutor * pyTradutor;
51   - // Mutex para evitar mutiplas chamadas de notificadores
52   - pthread_mutex_t *mutex;
  50 + std::list<ListenerTradutor*> * listeners;
  51 + PyTradutor * pyTradutor;
  52 + // Mutex para evitar mutiplas chamadas de notificadores
  53 + pthread_mutex_t *mutex;
53 54  
54 55 };
55 56 }
... ...
tradutor/src/ouvinteTradutor.cpp
... ... @@ -1,18 +0,0 @@
1   -/*
2   - * File: ouvinteTradutor.cpp
3   - * Author: derzu
4   - *
5   - * Created on 2 de Fevereiro de 2010, 15:48
6   - */
7   -
8   -#include "ouvinteTradutor.h"
9   -
10   -namespace Tradutor {
11   -
12   - OuvinteTradutor::OuvinteTradutor() {
13   - }
14   -
15   - OuvinteTradutor::~OuvinteTradutor() {
16   - }
17   -
18   -}
tradutor/src/tradutorPortGlosa.cpp
... ... @@ -12,27 +12,21 @@
12 12 * @date 21/10/2009
13 13 *
14 14 */
15   -
16 15 #include "tradutorPortGlosa.h"
17 16  
18   -using namespace std;
19   -
20   -
21 17 namespace Tradutor {
22 18 TradutorPortGlosa::TradutorPortGlosa() {
23   - ouvintes = new list<OuvinteTradutor*>();
24   - pyTradutor = new PyTradutor();
25   -
  19 + listeners = new list<ListenerTradutor*>();
  20 + pyTradutor = new PyTradutor();
26 21 // Inicia o mutex
27 22 mutex = (pthread_mutex_t *) malloc( sizeof(pthread_mutex_t) );
28 23 pthread_mutex_init(mutex, NULL);
29 24 DPRINTF("Done!\n")
30   -
31 25 }
32 26  
33 27  
34 28 TradutorPortGlosa::~TradutorPortGlosa() {
35   - delete ouvintes;
  29 + delete listeners;
36 30 delete pyTradutor;
37 31 if (mutex) {
38 32 int ret = pthread_mutex_destroy(mutex);
... ... @@ -44,93 +38,93 @@ namespace Tradutor {
44 38  
45 39 }
46 40  
47   - void TradutorPortGlosa::registraOuvinte(OuvinteTradutor * ouvinte) {
48   - ouvintes->push_back(ouvinte);
49   - }
  41 + void TradutorPortGlosa::addListener(ListenerTradutor* listener) {
  42 + listeners->push_back(listener);
  43 + }
50 44  
51 45  
52   - void TradutorPortGlosa::removeOuvinte(OuvinteTradutor * ouvinte) {
53   - ouvintes->remove(ouvinte);
54   - }
  46 + void TradutorPortGlosa::removeListener(ListenerTradutor* listener) {
  47 + listeners->remove(listener);
  48 + }
55 49  
56 50  
57   - void TradutorPortGlosa::notificaOuvintes(vector<string> * traducao) {
58   - for (list<OuvinteTradutor*>::iterator i=ouvintes->begin() ; i!= ouvintes->end() ; i++){
59   - (*i)->codifica(traducao);
60   - }
61   - }
  51 + void TradutorPortGlosa::notifyListeners(vector<string> * traducao) {
  52 + for (list<ListenerTradutor*>::iterator i = listeners->begin() ; i != listeners->end() ; i++){
  53 + (*i)->notifyTranslation(traducao);
  54 + }
  55 + }
62 56  
63   - /*
64   - // Implemento o metodo da classe que estou ouvindo, classe ExtratorCC
65   - void TradutorPortGlosa::notificaCC(unsigned char * cc, int64_t pts) {
66   - // Mutex para evitar bug multiplas chamadas dos notificadores
67   - pthread_mutex_lock(mutex);
68   - traduz(cc);
69   - pthread_mutex_unlock(mutex);
70   - }*/
71   -
72   - // Implemento o metodo da classe que estou ouvindo, classe ExtratorCC
73   - void TradutorPortGlosa::chegouInput(unsigned char * texto) {
74   - // Mutex para evitar bug multiplas chamadas dos notificadores
75   - pthread_mutex_lock(mutex);
76   - traduz(texto);
77   - pthread_mutex_unlock(mutex);
78   - }
79   -
80   - void TradutorPortGlosa::traduz(unsigned char * texto) {
81   - vector<string> * vGlosa = portuguesToGlosaVector((const char *)texto);
82   - if (vGlosa->size() > 0)
83   - notificaOuvintes(vGlosa);
84   - free(vGlosa);
85   - }
  57 + /*
  58 + // Implemento o metodo da classe que estou ouvindo, classe ExtratorCC
  59 + void TradutorPortGlosa::notificaCC(unsigned char * cc, int64_t pts) {
  60 + // Mutex para evitar bug multiplas chamadas dos notificadores
  61 + pthread_mutex_lock(mutex);
  62 + traduz(cc);
  63 + pthread_mutex_unlock(mutex);
  64 + }*/
  65 +
  66 + // Implemento o metodo da classe que estou ouvindo.
  67 + void TradutorPortGlosa::notifyInput(unsigned char * texto) {
  68 + // Mutex para evitar bug multiplas chamadas dos notificadores
  69 + pthread_mutex_lock(mutex);
  70 + traduz(texto);
  71 + pthread_mutex_unlock(mutex);
  72 + }
  73 +
  74 + void TradutorPortGlosa::traduz(unsigned char * texto) {
  75 + vector<string> * vGlosa = portuguesToGlosaVector((const char *)texto);
  76 + if (vGlosa->size() > 0)
  77 + notifyListeners(vGlosa);
  78 + free(vGlosa);
  79 + }
86 80  
87 81  
88   - /**
89   - * Traduz um texto (char * input) para um vetor de tokens<string> contendo a
90   - * traducao para glosa
91   - *
92   - * @param input texto de entrada
93   - * @return vetor de string contendo os tokens em glosa traduzidos.
94   - **/
95   - vector<string> * TradutorPortGlosa::portuguesToGlosaVector(const char * input) {
96   - char * sGlosa;
97   - vector<string> * vGlosa;
  82 + /**
  83 + * Traduz um texto (char * input) para um vetor de tokens<string> contendo a
  84 + * traducao para glosa
  85 + *
  86 + * @param input texto de entrada
  87 + * @return vetor de string contendo os tokens em glosa traduzidos.
  88 + **/
  89 + vector<string> * TradutorPortGlosa::portuguesToGlosaVector(const char * input) {
  90 + char * sGlosa;
  91 + vector<string> * vGlosa;
98 92  
99   - // Faz a tradução de portugues para glosa
100   - sGlosa = pyTradutor->convertStringToGlosa(input);
  93 + // Faz a tradução de portugues para glosa
  94 + sGlosa = pyTradutor->convertStringToGlosa(input);
101 95  
102   - // Cria vetor de string contendo os tokens da glosa já traduzidos
103   - vGlosa = portuguesToGlosaVectorSplit(sGlosa);
104   -
105   - return vGlosa;
106   - }
  96 + // Cria vetor de string contendo os tokens da glosa já traduzidos
  97 + vGlosa = portuguesToGlosaVectorSplit(sGlosa);
107 98  
  99 + return vGlosa;
  100 + }
108 101  
109   - /**
110   - * Faz split de uma string (char * sGlosa) para um vector<string> contendo os
111   - * tokens da glosa
112   - *
113   - * @param sGlosa string de glosa
114   - * @return vetor de string contendo os tokens em glosa.
115   - **/
116   - vector<string> * TradutorPortGlosa::portuguesToGlosaVectorSplit(char * sGlosa) {
  102 + /**
  103 + * Faz split de uma string (char * sGlosa) para um vector<string> contendo os
  104 + * tokens da glosa
  105 + *
  106 + * @param sGlosa string de glosa
  107 + * @return vetor de string contendo os tokens em glosa.
  108 + **/
  109 + vector<string> * TradutorPortGlosa::portuguesToGlosaVectorSplit(char * sGlosa) {
117 110  
118   - //printf("[INFO] Glosa: %s\n", sGlosa);
  111 + //printf("[INFO] Glosa: %s\n", sGlosa);
119 112  
120   - vector<string> * vGlosa = new vector<string>();
121   - string str(reinterpret_cast<char*>(sGlosa));
  113 + vector<string> * vGlosa = new vector<string>();
  114 + string str(reinterpret_cast<char*>(sGlosa));
122 115  
123   - int cutAt;
124   - while((cutAt = str.find_first_of(" ")) != str.npos){
125   - if(cutAt > 0) {
126   - vGlosa->push_back(str.substr(0,cutAt));
127   - }
128   - str = str.substr(cutAt+1);
129   - }
130   - if(str.length() > 0) {
131   - vGlosa->push_back(str);
  116 + int cutAt;
  117 + while((cutAt = str.find_first_of(" ")) != str.npos){
  118 + if(cutAt > 0){
  119 + vGlosa->push_back(str.substr(0,cutAt));
132 120 }
  121 + str = str.substr(cutAt+1);
  122 + }
133 123  
134   - return vGlosa;
  124 + if(str.length() > 0) {
  125 + vGlosa->push_back(str);
135 126 }
  127 +
  128 + return vGlosa;
  129 + }
136 130 }
... ...
util/src/include/logger.h
... ... @@ -25,7 +25,6 @@
25 25  
26 26 using namespace std;
27 27  
28   -
29 28 namespace Util {
30 29  
31 30 class Logger {
... ...
util/src/logger.cpp
... ... @@ -11,8 +11,6 @@
11 11  
12 12 #include "logger.h"
13 13  
14   -using namespace std;
15   -
16 14 namespace Util {
17 15  
18 16 Logger* Logger::m_pInstance = NULL;
... ...