forked from F5OEO/avc2ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvncclient.cpp
More file actions
124 lines (96 loc) · 2.48 KB
/
Copy pathvncclient.cpp
File metadata and controls
124 lines (96 loc) · 2.48 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
#include <getopt.h>
#include <math.h>
#include <png.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "vncclient.h"
char* MyPassword;
//http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk/src/osgPlugins/vnc/ReaderWriterVNC.cpp
rfbBool VncClient::resize(rfbClient* client) {
/* VncClient::DisplayWidth = (client->width>>5)<<5;
VncClient::DisplayHeight = (client->height>>4)<<4;
*/
return TRUE;
}
void VncClient::update(rfbClient* client,int x,int y,int w,int h)
{
}
char* VncClient::GetPassword(rfbClient* client)
{
char* Password=(char*)malloc(255);
strcpy(Password,MyPassword);
return Password;
}
VncClient::VncClient(char *IP,char* Password)
{
client = rfbGetClient(8,3,4);
DisplayWidth=0;
DisplayHeight=0;
//client->MallocFrameBuffer=&VncClient::resize;
client->GotFrameBufferUpdate=update;
client->GetPassword=GetPassword;
MyPassword=Password;
char *argv[2];
argv[0]="rpidatv";
argv[1]=IP;
int argc=2;
if(!rfbInitClient(client,&argc,argv))
{
printf("InitClient Failed\n");
};
}
VncClient::~VncClient()
{
printf("VNC Clean todo\n");
//rfbClientCleanup(client);
}
void VncClient::GetDisplaySize(int& Width,int& Height,int& Rotate)
{
//printf("Enter DisplaySize\n");
while(DisplayWidth==0)
{ sleep(1);
if(!WaitForMessage(client,50000)) continue;
if(!HandleRFBServerMessage(client)) printf("Handle Error");
if((client->width!=0)&&(client->height!=0))
{
DisplayWidth = ((client->width>>5))<<5;
DisplayHeight = ((client->height>>4)+1)<<4;
client->width=DisplayWidth;
client->height=DisplayHeight;
}
}
printf("Origin FB = %d * %d\n",client->width,client->height);
Width=DisplayWidth;
Height=DisplayHeight;
}
void VncClient::SetOmxBuffer(unsigned char* Buffer)
{
client->frameBuffer=Buffer;
}
int VncClient::GetPicture(int fps=25)
{
int result;
struct timespec gettime_now,last_time;
long time_difference;
clock_gettime(CLOCK_REALTIME, &last_time);
result=WaitForMessage(client,500000);
if(result<0) {printf("Message Failed\n");return 0;}
if(result==0)
{
return 0;
}
else
{
if(!HandleRFBServerMessage(client)) printf("VNC KAPUT\n");
}
clock_gettime(CLOCK_REALTIME, &gettime_now);
time_difference = gettime_now.tv_nsec - last_time.tv_nsec;
if(time_difference<0) time_difference+=1E9;
int FrameDiff=(int)((time_difference/1000)/(1000000/fps));
//printf("Diff=%ld us Frame %d\n",time_difference/1000,FrameDiff);
//int FrameDiff=0;
return FrameDiff;
}