-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemoRTP.cpp
223 lines (187 loc) · 5.23 KB
/
demoRTP.cpp
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
/*
* main.cpp
*
* Created on: Sep 3, 2010
* Author: caioviel
*/
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/gl.h>
#include <string>
using namespace std;
#include "include/Puppet.h"
#include "include/SimpleScenario.h"
#include "include/Camera.h"
#include "include/EventHandler.h"
#include "include/Color.h"
using namespace ::br::ufscar::lince::xpta::demo;
#include <streaming/SharedBuffer.h>
#include <streaming/AVEncoder.h>
#include <streaming/RTPStream.h>
#include <streaming/UDPMpegTS.h>
#include <streaming/WowzaUDPInput.h>
#include <streaming/DeviceInterface.h>
#include <libffmpeg/libffmpeg.h>
using namespace ::br::ufscar::lince::streaming;
#include <cpputil/Thread.h>
using namespace cpputil;
#include <cpputil/logger/Logger.h>
using namespace cpputil::logger;
string ipAdd = "127.0.0.1";
int portNo = 4006;
class StreamGenerator : public Thread {
void run();
};
void StreamGenerator::run() {
FFMpeg_init();
FFMpeg_setFramerate((char*) "24");
FFMpeg_setFormat((char*) "shmgrab");
FFMpeg_setInputFile((char*) ":0.0");
FFMpeg_setVideoCodec((char*) "libx264");
FFMpeg_setVideoPreset((char*) "default");
FFMpeg_setVideoPreset((char*) "baseline");
FFMpeg_setOther((char*) "g", (char*) "60");
FFMpeg_setVideoBitrate((char*) "150000");
FFMpeg_setAudioCodec((char*) "libaac");
FFMpeg_setAudioBitrate((char*) "128000");
FFMpeg_setAudioRate(48000);
FFMpeg_setAudioChannels(2);
FFMpeg_setVideoBsf((char*) "h264_mp4toannexb");
FFMpeg_setFormat((char*) "mpegts");
FFMpeg_setOutputFile((char*) "udp://200.18.98.27:10000?pkt_size=1316");
FFMpeg_transcode();
}
//Objetos estáticos globais
Puppet* puppet;
Puppet* puppet2;
SimpleScenario* scenario;
Camera* camera;
int windowHeight, windowWidth;
unsigned char* bufferByte;
DeviceInterface* device;
//Definições das funções
static void draw();
static void animation(int parametro);
static void initStreaming();
void saveFrame();
//Implementaçõa das funções
void animation(int parametro) {
puppet->move();
//puppet2->move();
glutPostRedisplay();
glutTimerFunc(16, animation, 0);
}
void draw() {
glClearColor(0.5f, 0.5f, 1.0f, 1.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera->point();
puppet->draw();
//puppet2->draw();
scenario->draw();
saveFrame();
glutSwapBuffers();
}
void processNormalKeys(unsigned char key, int x, int y) {
if (key == 'c' || key == 'C') {
camera->changeTypeUp();
}
glutPostRedisplay();
}
void processSpecialKeys(int key, int x, int y) {
static GLPiece* clone = NULL;
switch(key) {
case GLUT_KEY_LEFT:
puppet->move(Puppet::TURNING_LEFT);
break;
case GLUT_KEY_RIGHT:
puppet->move(Puppet::TURNING_RIGHT);
break;
case GLUT_KEY_UP:
puppet->move(Puppet::WALKING);
break;
case GLUT_KEY_DOWN:
puppet->move(GLPiece::GENERIC_MOVE);
break;
case GLUT_KEY_F1:
cout << "Memorizar State" << endl;
clone = puppet->cloneState();
break;
case GLUT_KEY_F2:
if (clone != NULL) {
cout << "Recuperar State" << endl;
puppet->recoverState(clone);
}
break;
}
//animation(0);
}
void saveFrame() {
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, windowWidth, windowHeight, GL_RGBA, GL_UNSIGNED_BYTE, bufferByte);
GLenum error = glGetError();
if (error != GL_NO_ERROR) {
cout<<"Erro ao salvar o frame."<<endl;
}
device->putBuffer2(bufferByte);
}
void initStreaming() {
AVSource* source = new SharedBuffer();
AVEncoder* encoder = new AVEncoder(source);
encoder->setVideoCodec(H264);
encoder->setVideoPreset("default");
//Streaming* streammer = new WowzaUDPInput(ipAdd, portNo);
Streaming* streammer = new RTPStream(ipAdd, portNo);
streammer->addStream(encoder);
streammer->start();
}
/*
ffmpeg -s 400 -re -vcodec libx264
-vpre default -vpre baseline -g 60
-vb 150000 -strict experimental -acodec aac
-ab 128000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb
-f mpegts udp://200.18.98.27:10000?pkt_size=1316
*/
int main(int argc, char** argv) {
cout << argc << endl;
if (argc > 2) {
ipAdd = argv[1];
}
if (argc > 3) {
portNo = atoi(argv[2]);
}
windowHeight = 800;
windowWidth = 800;
//Inicia o Buffer Compartilhado
device = DeviceInterface::getInstance();
device->mount(windowWidth, windowHeight, 32, 25);
bufferByte = new unsigned char[windowHeight*windowWidth*4];
initStreaming();
//Inicia Janela
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize (windowWidth, windowHeight);
glutInitWindowPosition (0, 0);
glutCreateWindow ("Demo XPTA-Streaming (RTP)");
//Seta forma do mundo
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60,1,0.5,500);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
////Inicializa os Objetos Gráficos
puppet = new Puppet("Boneco1", 0.6, 0, 0);
Color** pallet = new Color*[3];
pallet[0] = (Color*) Color::SKIN_COLOR;
pallet[1] = new Color("lightred", 0.65490,0.13333,0.16863);
pallet[2] = new Color("darkred", 0.96471,0.78039,0.45490);
//puppet2 = new Puppet("Boneco2", 0, 0, 0.7, pallet);
scenario = new SimpleScenario("light_texture.raw");
camera = new Camera(puppet);
EventHandler* eventHandler = new EventHandler(puppet, camera);
glutDisplayFunc(draw);
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(processSpecialKeys);
glutTimerFunc(16, animation, 0);
glutMainLoop();
return EXIT_SUCCESS;
}