-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
87 lines (74 loc) · 2.46 KB
/
main.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
#include <iostream>
#include <SDL2/SDL_stdinc.h>
#include "SocketConnection.h"
#include "SDL_Screen.h"
#include "FrameCache.h"
#include "FFmpegDecoder.h"
#include "EventCache.h"
#include "EventController.h"
int main() {
std::cout << "Hello, World!" << std::endl;
//先进行Socket连接
SocketConnection *socketConnection = new SocketConnection();
if (socketConnection->connect_server() == SDL_FALSE) {
return -1;
}
//连接成功。
printf("连接成功\n");
//从客户端接受屏幕数据
uint8_t size[4];
socketConnection->recv_from_(reinterpret_cast<uint8_t *>(size), 4);
//这里先写死,后面从客户端内接受
int width = (size[0] << 8) | (size[1]);
int height = (size[2] << 8) | (size[3]);
printf("width = %d , height = %d \n", width, height);
int scale =2;
char name[] = "as_remote";
// auto *screen = new SDL_Screen(name, static_cast<int>(width / scale), static_cast<int>(height / scale));
auto *screen = new SDL_Screen(name, static_cast<int>(width), static_cast<int>(height));
screen->init();
//开启编码器
FrameCache *cache = new FrameCache();
cache->init();
FFmpegDecoder *decoder = new FFmpegDecoder(socketConnection, cache, screen);
// decoder->init();
decoder->async_start();
EventController *controller = new EventController(screen, socketConnection);
controller->decoder = decoder;
controller->init();
controller->async_start();
//开启事件循环
printf("开启事件循环\n");
SDL_Event event;
//开启Event Loop
for (;;) {
SDL_WaitEvent(&event);
// printf("接到事件\n");
if (event.type == EVENT_NEW_FRAME) { //渲染
AVFrame *render = cache->render_frame;
screen->uploadTexture(
render->data[0], render->linesize[0],
render->data[1], render->linesize[1],
render->data[2], render->linesize[2]
);
cache->consume_render = SDL_TRUE;
} else if (event.type == SDL_QUIT) {
printf("rev event type=SDL_QUIT\n");
break;
} else {
controller->push_event(event);
}
}
controller->destroy();
decoder->stop();
decoder->destroy();
screen->destroy();
delete screen;
delete controller;
delete cache;
delete decoder;
close_conn:
socketConnection->close_client();
delete socketConnection;
return 0;
}