forked from leehuitao/RemoteDesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabuffer_task_thread.cpp
More file actions
80 lines (74 loc) · 2.6 KB
/
databuffer_task_thread.cpp
File metadata and controls
80 lines (74 loc) · 2.6 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
#include "databuffer_task_thread.h"
#include "message_protocol_define.h"
DataBufferTaskThread::DataBufferTaskThread(QObject *parent) : QThread(parent)
{
}
void DataBufferTaskThread::addTask(webrtc::DataBuffer databuffer)
{
m_mutex.lock();
webrtc::DataBuffer child(databuffer);
m_taskList.append(&databuffer);
m_mutex.unlock();
m_Condition.notify_all();
}
void DataBufferTaskThread::popTask(webrtc::DataBuffer * databuffer)
{
m_mutex.lock();
if(m_taskList.size() == 0 )
return;
databuffer = m_taskList.first();
m_taskList.removeFirst();
m_mutex.unlock();
}
void DataBufferTaskThread::run()
{
QDir folder;
int size = 0;
int cmd = 0;
while(!m_ThreadStop){
m_mutex.lock();
if(m_taskList.size() <= 0)
{
m_Condition.wait(&m_mutex);
m_mutex.unlock();
}
webrtc::DataBuffer * databuffer = nullptr;
popTask(databuffer);
if(databuffer == nullptr)
continue;
auto buffer = databuffer->data;
const char * data = buffer.data<char>();
QByteArray arr(data);
QDataStream packet(arr);
packet >> size >> cmd;//解析包头
MsgDataBuffer msgDataBuffer(arr,size,cmd);
if(cmd == 1){
qDebug()<<"recv msg = "<<msgDataBuffer.body;
signRecvMsg(msgDataBuffer.body);
}else if(cmd == 10){
SingalingData data;
std::string str(msgDataBuffer.body);
QString newS = QString::fromStdString(str);
auto index = newS.lastIndexOf("}");
//auto index = str.find_first_of("}");
newS = newS.mid(0,index+1);
QByteArray response(newS.toLocal8Bit().data(),int(newS.size()));
m_dataPrase.parseResponse(response,data);
qDebug()<<"datachannel recive "<<newS <<"total ="<< newS.size()<<"index = "<<index;
if(data.data["type"].toInt() != MouseCursorChange){
Event event;
event.type = data.data["type"].toInt();
event.posx = data.data["posx"].toInt();
event.posy = data.data["posy"].toInt();
event.delta = data.data["delta"].toInt();
event.keyword = data.data["keyword"].toInt();
event.coursorShape = data.data["coursorShape"].toInt();
signRecvMouseEvent(event);
qDebug()<<"recv MouseEvent = "<<msgDataBuffer.body;
}else{
signCursorEvent(data.data["coursorShape"].toInt());
qDebug()<<"recv CursorEvent = "<<msgDataBuffer.body;
}
}
}
}