mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
Support user date in peer instance and callback functions
This commit is contained in:
@@ -37,13 +37,15 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct Peer PeerPtr;
|
typedef struct Peer PeerPtr;
|
||||||
|
|
||||||
typedef void (*OnReceiveBuffer)(const char*, size_t, const char*, size_t);
|
typedef void (*OnReceiveBuffer)(const char*, size_t, const char*, size_t,
|
||||||
|
void*);
|
||||||
|
|
||||||
typedef void (*OnSignalStatus)(SignalStatus status);
|
typedef void (*OnSignalStatus)(SignalStatus, void*);
|
||||||
|
|
||||||
typedef void (*OnConnectionStatus)(ConnectionStatus status);
|
typedef void (*OnConnectionStatus)(ConnectionStatus, void*);
|
||||||
|
|
||||||
typedef void (*NetStatusReport)(const unsigned short, const unsigned short);
|
typedef void (*NetStatusReport)(const unsigned short, const unsigned short,
|
||||||
|
void*);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char* cfg_path;
|
const char* cfg_path;
|
||||||
@@ -53,6 +55,7 @@ typedef struct {
|
|||||||
OnSignalStatus on_signal_status;
|
OnSignalStatus on_signal_status;
|
||||||
OnConnectionStatus on_connection_status;
|
OnConnectionStatus on_connection_status;
|
||||||
NetStatusReport net_status_report;
|
NetStatusReport net_status_report;
|
||||||
|
void* user_data;
|
||||||
} Params;
|
} Params;
|
||||||
|
|
||||||
DLLAPI PeerPtr* CreatePeer(const Params* params);
|
DLLAPI PeerPtr* CreatePeer(const Params* params);
|
||||||
|
|||||||
@@ -71,25 +71,26 @@ int PeerConnection::Init(PeerConnectionParams params,
|
|||||||
on_receive_data_buffer_ = params.on_receive_data_buffer;
|
on_receive_data_buffer_ = params.on_receive_data_buffer;
|
||||||
on_signal_status_ = params.on_signal_status;
|
on_signal_status_ = params.on_signal_status;
|
||||||
on_connection_status_ = params.on_connection_status;
|
on_connection_status_ = params.on_connection_status;
|
||||||
|
user_data_ = params.user_data;
|
||||||
|
|
||||||
on_receive_ws_msg_ = [this](const std::string &msg) { ProcessSignal(msg); };
|
on_receive_ws_msg_ = [this](const std::string &msg) { ProcessSignal(msg); };
|
||||||
|
|
||||||
on_ws_status_ = [this](WsStatus ws_status) {
|
on_ws_status_ = [this](WsStatus ws_status) {
|
||||||
if (WsStatus::WsOpening == ws_status) {
|
if (WsStatus::WsOpening == ws_status) {
|
||||||
signal_status_ = SignalStatus::SignalConnecting;
|
signal_status_ = SignalStatus::SignalConnecting;
|
||||||
on_signal_status_(SignalStatus::SignalConnecting);
|
on_signal_status_(SignalStatus::SignalConnecting, user_data_);
|
||||||
} else if (WsStatus::WsOpened == ws_status) {
|
} else if (WsStatus::WsOpened == ws_status) {
|
||||||
signal_status_ = SignalStatus::SignalConnected;
|
signal_status_ = SignalStatus::SignalConnected;
|
||||||
on_signal_status_(SignalStatus::SignalConnected);
|
on_signal_status_(SignalStatus::SignalConnected, user_data_);
|
||||||
} else if (WsStatus::WsFailed == ws_status) {
|
} else if (WsStatus::WsFailed == ws_status) {
|
||||||
signal_status_ = SignalStatus::SignalFailed;
|
signal_status_ = SignalStatus::SignalFailed;
|
||||||
on_signal_status_(SignalStatus::SignalFailed);
|
on_signal_status_(SignalStatus::SignalFailed, user_data_);
|
||||||
} else if (WsStatus::WsClosed == ws_status) {
|
} else if (WsStatus::WsClosed == ws_status) {
|
||||||
signal_status_ = SignalStatus::SignalClosed;
|
signal_status_ = SignalStatus::SignalClosed;
|
||||||
on_signal_status_(SignalStatus::SignalClosed);
|
on_signal_status_(SignalStatus::SignalClosed, user_data_);
|
||||||
} else if (WsStatus::WsReconnecting == ws_status) {
|
} else if (WsStatus::WsReconnecting == ws_status) {
|
||||||
signal_status_ = SignalStatus::SignalReconnecting;
|
signal_status_ = SignalStatus::SignalReconnecting;
|
||||||
on_signal_status_(SignalStatus::SignalReconnecting);
|
on_signal_status_(SignalStatus::SignalReconnecting, user_data_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -100,7 +101,8 @@ int PeerConnection::Init(PeerConnectionParams params,
|
|||||||
[this, user_id, user_id_size](VideoFrame video_frame) {
|
[this, user_id, user_id_size](VideoFrame video_frame) {
|
||||||
if (on_receive_video_buffer_) {
|
if (on_receive_video_buffer_) {
|
||||||
on_receive_video_buffer_((const char *)video_frame.Buffer(),
|
on_receive_video_buffer_((const char *)video_frame.Buffer(),
|
||||||
video_frame.Size(), user_id, user_id_size);
|
video_frame.Size(), user_id, user_id_size,
|
||||||
|
user_data_);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -112,7 +114,7 @@ int PeerConnection::Init(PeerConnectionParams params,
|
|||||||
[this, user_id, user_id_size](uint8_t *data, int size) {
|
[this, user_id, user_id_size](uint8_t *data, int size) {
|
||||||
if (on_receive_audio_buffer_) {
|
if (on_receive_audio_buffer_) {
|
||||||
on_receive_audio_buffer_((const char *)data, size, user_id,
|
on_receive_audio_buffer_((const char *)data, size, user_id,
|
||||||
user_id_size);
|
user_id_size, user_data_);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -120,23 +122,23 @@ int PeerConnection::Init(PeerConnectionParams params,
|
|||||||
on_receive_data_ = [this](const char *data, size_t size, const char *user_id,
|
on_receive_data_ = [this](const char *data, size_t size, const char *user_id,
|
||||||
size_t user_id_size) {
|
size_t user_id_size) {
|
||||||
if (on_receive_data_buffer_) {
|
if (on_receive_data_buffer_) {
|
||||||
on_receive_data_buffer_(data, size, user_id, user_id_size);
|
on_receive_data_buffer_(data, size, user_id, user_id_size, user_data_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
on_ice_status_change_ = [this](std::string ice_status) {
|
on_ice_status_change_ = [this](std::string ice_status) {
|
||||||
if ("connecting" == ice_status) {
|
if ("connecting" == ice_status) {
|
||||||
on_connection_status_(ConnectionStatus::Connecting);
|
on_connection_status_(ConnectionStatus::Connecting, user_data_);
|
||||||
} else if ("disconnected" == ice_status) {
|
} else if ("disconnected" == ice_status) {
|
||||||
on_connection_status_(ConnectionStatus::Disconnected);
|
on_connection_status_(ConnectionStatus::Disconnected, user_data_);
|
||||||
} else if ("ready" == ice_status) {
|
} else if ("ready" == ice_status) {
|
||||||
ice_ready_ = true;
|
ice_ready_ = true;
|
||||||
on_connection_status_(ConnectionStatus::Connected);
|
on_connection_status_(ConnectionStatus::Connected, user_data_);
|
||||||
b_force_i_frame_ = true;
|
b_force_i_frame_ = true;
|
||||||
LOG_INFO("Ice finish");
|
LOG_INFO("Ice finish");
|
||||||
} else if ("closed" == ice_status) {
|
} else if ("closed" == ice_status) {
|
||||||
ice_ready_ = false;
|
ice_ready_ = false;
|
||||||
on_connection_status_(ConnectionStatus::Closed);
|
on_connection_status_(ConnectionStatus::Closed, user_data_);
|
||||||
LOG_INFO("Ice closed");
|
LOG_INFO("Ice closed");
|
||||||
} else {
|
} else {
|
||||||
ice_ready_ = false;
|
ice_ready_ = false;
|
||||||
@@ -348,9 +350,11 @@ void PeerConnection::ProcessSignal(const std::string &signal) {
|
|||||||
std::string reason = j["reason"].get<std::string>();
|
std::string reason = j["reason"].get<std::string>();
|
||||||
LOG_ERROR("{}", reason);
|
LOG_ERROR("{}", reason);
|
||||||
if ("Incorrect password" == reason) {
|
if ("Incorrect password" == reason) {
|
||||||
on_connection_status_(ConnectionStatus::IncorrectPassword);
|
on_connection_status_(ConnectionStatus::IncorrectPassword,
|
||||||
|
user_data_);
|
||||||
} else if ("No such transmission id" == reason) {
|
} else if ("No such transmission id" == reason) {
|
||||||
on_connection_status_(ConnectionStatus::NoSuchTransmissionId);
|
on_connection_status_(ConnectionStatus::NoSuchTransmissionId,
|
||||||
|
user_data_);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (leave_) {
|
if (leave_) {
|
||||||
@@ -454,7 +458,7 @@ void PeerConnection::ProcessSignal(const std::string &signal) {
|
|||||||
|
|
||||||
ice_transmission_list_[remote_user_id]->GatherCandidates();
|
ice_transmission_list_[remote_user_id]->GatherCandidates();
|
||||||
|
|
||||||
on_connection_status_(ConnectionStatus::Connecting);
|
on_connection_status_(ConnectionStatus::Connecting, user_data_);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -474,7 +478,7 @@ void PeerConnection::ProcessSignal(const std::string &signal) {
|
|||||||
ice_transmission_list_[remote_user_id]->SetRemoteSdp(remote_sdp);
|
ice_transmission_list_[remote_user_id]->SetRemoteSdp(remote_sdp);
|
||||||
}
|
}
|
||||||
|
|
||||||
on_connection_status_(ConnectionStatus::Connecting);
|
on_connection_status_(ConnectionStatus::Connecting, user_data_);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,13 +14,14 @@
|
|||||||
#include "x.h"
|
#include "x.h"
|
||||||
|
|
||||||
typedef void (*OnReceiveBuffer)(const char *, size_t, const char *,
|
typedef void (*OnReceiveBuffer)(const char *, size_t, const char *,
|
||||||
const size_t);
|
const size_t, void *);
|
||||||
|
|
||||||
typedef void (*OnSignalStatus)(SignalStatus status);
|
typedef void (*OnSignalStatus)(SignalStatus status, void *);
|
||||||
|
|
||||||
typedef void (*OnConnectionStatus)(ConnectionStatus status);
|
typedef void (*OnConnectionStatus)(ConnectionStatus status, void *);
|
||||||
|
|
||||||
typedef void (*NetStatusReport)(const unsigned short, const unsigned short);
|
typedef void (*NetStatusReport)(const unsigned short, const unsigned short,
|
||||||
|
void *);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *cfg_path;
|
const char *cfg_path;
|
||||||
@@ -30,6 +31,7 @@ typedef struct {
|
|||||||
OnSignalStatus on_signal_status;
|
OnSignalStatus on_signal_status;
|
||||||
OnConnectionStatus on_connection_status;
|
OnConnectionStatus on_connection_status;
|
||||||
NetStatusReport net_status_report;
|
NetStatusReport net_status_report;
|
||||||
|
void *user_data;
|
||||||
} PeerConnectionParams;
|
} PeerConnectionParams;
|
||||||
|
|
||||||
class PeerConnection {
|
class PeerConnection {
|
||||||
@@ -112,6 +114,8 @@ class PeerConnection {
|
|||||||
OnReceiveBuffer on_receive_data_buffer_;
|
OnReceiveBuffer on_receive_data_buffer_;
|
||||||
OnSignalStatus on_signal_status_;
|
OnSignalStatus on_signal_status_;
|
||||||
OnConnectionStatus on_connection_status_;
|
OnConnectionStatus on_connection_status_;
|
||||||
|
void *user_data_;
|
||||||
|
|
||||||
char *nv12_data_ = nullptr;
|
char *nv12_data_ = nullptr;
|
||||||
bool inited_ = false;
|
bool inited_ = false;
|
||||||
std::string password_;
|
std::string password_;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ PeerPtr *CreatePeer(const Params *params) {
|
|||||||
peer_ptr->pc_params.on_signal_status = params->on_signal_status;
|
peer_ptr->pc_params.on_signal_status = params->on_signal_status;
|
||||||
peer_ptr->pc_params.on_connection_status = params->on_connection_status;
|
peer_ptr->pc_params.on_connection_status = params->on_connection_status;
|
||||||
peer_ptr->pc_params.net_status_report = params->net_status_report;
|
peer_ptr->pc_params.net_status_report = params->net_status_report;
|
||||||
|
peer_ptr->pc_params.user_data = params->user_data;
|
||||||
|
|
||||||
return peer_ptr;
|
return peer_ptr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user