mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
Fix ffmpeg link error on MacOS
This commit is contained in:
@@ -11,20 +11,16 @@ using nlohmann::json;
|
|||||||
|
|
||||||
PeerConnection::PeerConnection() {}
|
PeerConnection::PeerConnection() {}
|
||||||
|
|
||||||
PeerConnection::~PeerConnection()
|
PeerConnection::~PeerConnection() {
|
||||||
{
|
if (nv12_data_) {
|
||||||
if (nv12_data_)
|
|
||||||
{
|
|
||||||
delete nv12_data_;
|
delete nv12_data_;
|
||||||
nv12_data_ = nullptr;
|
nv12_data_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int PeerConnection::Init(PeerConnectionParams params,
|
int PeerConnection::Init(PeerConnectionParams params,
|
||||||
const std::string &user_id)
|
const std::string &user_id) {
|
||||||
{
|
if (inited_) {
|
||||||
if (inited_)
|
|
||||||
{
|
|
||||||
LOG_INFO("Peer already inited");
|
LOG_INFO("Peer already inited");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -56,8 +52,7 @@ int PeerConnection::Init(PeerConnectionParams params,
|
|||||||
|
|
||||||
if (!cfg_turn_server_ip_.empty() && 0 != turn_server_port_ &&
|
if (!cfg_turn_server_ip_.empty() && 0 != turn_server_port_ &&
|
||||||
!cfg_turn_server_username_.empty() &&
|
!cfg_turn_server_username_.empty() &&
|
||||||
!cfg_turn_server_password_.empty())
|
!cfg_turn_server_password_.empty()) {
|
||||||
{
|
|
||||||
LOG_INFO("turn server ip [{}] port [{}] username [{}] password [{}]",
|
LOG_INFO("turn server ip [{}] port [{}] username [{}] password [{}]",
|
||||||
cfg_turn_server_ip_, turn_server_port_, cfg_turn_server_username_,
|
cfg_turn_server_ip_, turn_server_port_, cfg_turn_server_username_,
|
||||||
cfg_turn_server_password_);
|
cfg_turn_server_password_);
|
||||||
@@ -73,47 +68,33 @@ int PeerConnection::Init(PeerConnectionParams params,
|
|||||||
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;
|
||||||
|
|
||||||
on_receive_ws_msg_ = [this](const std::string &msg)
|
on_receive_ws_msg_ = [this](const std::string &msg) { ProcessSignal(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);
|
||||||
}
|
} 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);
|
||||||
}
|
} 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);
|
||||||
}
|
} 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);
|
||||||
}
|
} 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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
on_receive_video_ = [this](const char *data, size_t size, const char *user_id,
|
on_receive_video_ = [this](const char *data, size_t size, const char *user_id,
|
||||||
size_t user_id_size)
|
size_t user_id_size) {
|
||||||
{
|
|
||||||
int num_frame_returned = video_decoder_->Decode(
|
int num_frame_returned = video_decoder_->Decode(
|
||||||
(uint8_t *)data, size,
|
(uint8_t *)data, size,
|
||||||
[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_)
|
|
||||||
{
|
|
||||||
// LOG_ERROR("Receive video, size {}", video_frame.Size());
|
// LOG_ERROR("Receive video, size {}", video_frame.Size());
|
||||||
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);
|
||||||
@@ -122,14 +103,11 @@ int PeerConnection::Init(PeerConnectionParams params,
|
|||||||
};
|
};
|
||||||
|
|
||||||
on_receive_audio_ = [this](const char *data, size_t size, const char *user_id,
|
on_receive_audio_ = [this](const char *data, size_t size, const char *user_id,
|
||||||
size_t user_id_size)
|
size_t user_id_size) {
|
||||||
{
|
|
||||||
int num_frame_returned = audio_decoder_->Decode(
|
int num_frame_returned = audio_decoder_->Decode(
|
||||||
(uint8_t *)data, size,
|
(uint8_t *)data, size,
|
||||||
[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);
|
||||||
}
|
}
|
||||||
@@ -137,40 +115,28 @@ 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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
||||||
}
|
} else if ("disconnected" == ice_status) {
|
||||||
else if ("disconnected" == ice_status)
|
|
||||||
{
|
|
||||||
on_connection_status_(ConnectionStatus::Disconnected);
|
on_connection_status_(ConnectionStatus::Disconnected);
|
||||||
}
|
} else if ("completed" == ice_status || "ready" == ice_status ||
|
||||||
else if ("completed" == ice_status || "ready" == ice_status ||
|
"connected" == ice_status) {
|
||||||
"connected" == ice_status)
|
|
||||||
{
|
|
||||||
ice_ready_ = true;
|
ice_ready_ = true;
|
||||||
on_connection_status_(ConnectionStatus::Connected);
|
on_connection_status_(ConnectionStatus::Connected);
|
||||||
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);
|
||||||
LOG_INFO("Ice closed");
|
LOG_INFO("Ice closed");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ice_ready_ = false;
|
ice_ready_ = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -178,8 +144,7 @@ int PeerConnection::Init(PeerConnectionParams params,
|
|||||||
ws_transport_ =
|
ws_transport_ =
|
||||||
std::make_shared<WsTransmission>(on_receive_ws_msg_, on_ws_status_);
|
std::make_shared<WsTransmission>(on_receive_ws_msg_, on_ws_status_);
|
||||||
uri_ = "ws://" + cfg_signal_server_ip_ + ":" + cfg_signal_server_port_;
|
uri_ = "ws://" + cfg_signal_server_ip_ + ":" + cfg_signal_server_port_;
|
||||||
if (ws_transport_)
|
if (ws_transport_) {
|
||||||
{
|
|
||||||
ws_transport_->Connect(uri_);
|
ws_transport_->Connect(uri_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,14 +153,12 @@ int PeerConnection::Init(PeerConnectionParams params,
|
|||||||
|
|
||||||
nv12_data_ = new char[1280 * 720 * 3 / 2];
|
nv12_data_ = new char[1280 * 720 * 3 / 2];
|
||||||
|
|
||||||
if (0 != CreateVideoCodec(hardware_acceleration_))
|
if (0 != CreateVideoCodec(hardware_acceleration_)) {
|
||||||
{
|
|
||||||
LOG_ERROR("Create video codec failed");
|
LOG_ERROR("Create video codec failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != CreateAudioCodec())
|
if (0 != CreateAudioCodec()) {
|
||||||
{
|
|
||||||
LOG_ERROR("Create audio codec failed");
|
LOG_ERROR("Create audio codec failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -204,11 +167,9 @@ int PeerConnection::Init(PeerConnectionParams params,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PeerConnection::CreateVideoCodec(bool hardware_acceleration)
|
int PeerConnection::CreateVideoCodec(bool hardware_acceleration) {
|
||||||
{
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
if (hardware_acceleration)
|
if (hardware_acceleration) {
|
||||||
{
|
|
||||||
hardware_acceleration = false;
|
hardware_acceleration = false;
|
||||||
LOG_WARN(
|
LOG_WARN(
|
||||||
"MacOS not support hardware acceleration, use default software codec");
|
"MacOS not support hardware acceleration, use default software codec");
|
||||||
@@ -218,25 +179,21 @@ int PeerConnection::CreateVideoCodec(bool hardware_acceleration)
|
|||||||
|
|
||||||
video_encoder_ =
|
video_encoder_ =
|
||||||
VideoEncoderFactory::CreateVideoEncoder(hardware_acceleration_);
|
VideoEncoderFactory::CreateVideoEncoder(hardware_acceleration_);
|
||||||
if (hardware_acceleration_ && !video_encoder_)
|
if (hardware_acceleration_ && !video_encoder_) {
|
||||||
{
|
|
||||||
LOG_WARN(
|
LOG_WARN(
|
||||||
"Hardware accelerated encoder not available, use default software "
|
"Hardware accelerated encoder not available, use default software "
|
||||||
"encoder");
|
"encoder");
|
||||||
video_encoder_ = VideoEncoderFactory::CreateVideoEncoder(false);
|
video_encoder_ = VideoEncoderFactory::CreateVideoEncoder(false);
|
||||||
if (!video_encoder_)
|
if (!video_encoder_) {
|
||||||
{
|
|
||||||
LOG_ERROR(
|
LOG_ERROR(
|
||||||
"Hardware accelerated encoder and software encoder both not "
|
"Hardware accelerated encoder and software encoder both not "
|
||||||
"available");
|
"available");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (0 != video_encoder_->Init())
|
if (0 != video_encoder_->Init()) {
|
||||||
{
|
|
||||||
video_encoder_ = VideoEncoderFactory::CreateVideoEncoder(false);
|
video_encoder_ = VideoEncoderFactory::CreateVideoEncoder(false);
|
||||||
if (!video_encoder_ || 0 != video_encoder_->Init())
|
if (!video_encoder_ || 0 != video_encoder_->Init()) {
|
||||||
{
|
|
||||||
LOG_ERROR("Encoder init failed");
|
LOG_ERROR("Encoder init failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -244,25 +201,21 @@ int PeerConnection::CreateVideoCodec(bool hardware_acceleration)
|
|||||||
|
|
||||||
video_decoder_ =
|
video_decoder_ =
|
||||||
VideoDecoderFactory::CreateVideoDecoder(hardware_acceleration_);
|
VideoDecoderFactory::CreateVideoDecoder(hardware_acceleration_);
|
||||||
if (hardware_acceleration_ && !video_decoder_)
|
if (hardware_acceleration_ && !video_decoder_) {
|
||||||
{
|
|
||||||
LOG_WARN(
|
LOG_WARN(
|
||||||
"Hardware accelerated decoder not available, use default software "
|
"Hardware accelerated decoder not available, use default software "
|
||||||
"decoder");
|
"decoder");
|
||||||
video_decoder_ = VideoDecoderFactory::CreateVideoDecoder(false);
|
video_decoder_ = VideoDecoderFactory::CreateVideoDecoder(false);
|
||||||
if (!video_decoder_)
|
if (!video_decoder_) {
|
||||||
{
|
|
||||||
LOG_ERROR(
|
LOG_ERROR(
|
||||||
"Hardware accelerated decoder and software decoder both not "
|
"Hardware accelerated decoder and software decoder both not "
|
||||||
"available");
|
"available");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (0 != video_decoder_->Init())
|
if (0 != video_decoder_->Init()) {
|
||||||
{
|
|
||||||
video_decoder_ = VideoDecoderFactory::CreateVideoDecoder(false);
|
video_decoder_ = VideoDecoderFactory::CreateVideoDecoder(false);
|
||||||
if (!video_decoder_ || video_decoder_->Init())
|
if (!video_decoder_ || video_decoder_->Init()) {
|
||||||
{
|
|
||||||
LOG_ERROR("Decoder init failed");
|
LOG_ERROR("Decoder init failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -270,18 +223,15 @@ int PeerConnection::CreateVideoCodec(bool hardware_acceleration)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PeerConnection::CreateAudioCodec()
|
int PeerConnection::CreateAudioCodec() {
|
||||||
{
|
|
||||||
audio_encoder_ = std::make_unique<AudioEncoder>(AudioEncoder(48000, 1, 480));
|
audio_encoder_ = std::make_unique<AudioEncoder>(AudioEncoder(48000, 1, 480));
|
||||||
if (!audio_encoder_ || 0 != audio_encoder_->Init())
|
if (!audio_encoder_ || 0 != audio_encoder_->Init()) {
|
||||||
{
|
|
||||||
LOG_ERROR("Audio encoder init failed");
|
LOG_ERROR("Audio encoder init failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
audio_decoder_ = std::make_unique<AudioDecoder>(AudioDecoder(48000, 1, 480));
|
audio_decoder_ = std::make_unique<AudioDecoder>(AudioDecoder(48000, 1, 480));
|
||||||
if (!audio_decoder_ || 0 != audio_decoder_->Init())
|
if (!audio_decoder_ || 0 != audio_decoder_->Init()) {
|
||||||
{
|
|
||||||
LOG_ERROR("Audio decoder init failed");
|
LOG_ERROR("Audio decoder init failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -291,10 +241,8 @@ int PeerConnection::CreateAudioCodec()
|
|||||||
|
|
||||||
int PeerConnection::Create(PeerConnectionParams params,
|
int PeerConnection::Create(PeerConnectionParams params,
|
||||||
const std::string &transmission_id,
|
const std::string &transmission_id,
|
||||||
const std::string &password)
|
const std::string &password) {
|
||||||
{
|
if (SignalStatus::SignalConnected != GetSignalStatus()) {
|
||||||
if (SignalStatus::SignalConnected != GetSignalStatus())
|
|
||||||
{
|
|
||||||
LOG_ERROR("Signal not connected");
|
LOG_ERROR("Signal not connected");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -308,8 +256,7 @@ int PeerConnection::Create(PeerConnectionParams params,
|
|||||||
{"transmission_id", transmission_id},
|
{"transmission_id", transmission_id},
|
||||||
{"password", password}};
|
{"password", password}};
|
||||||
|
|
||||||
if (ws_transport_)
|
if (ws_transport_) {
|
||||||
{
|
|
||||||
ws_transport_->Send(message.dump());
|
ws_transport_->Send(message.dump());
|
||||||
LOG_INFO("Send create transmission request, transmission_id [{}]",
|
LOG_INFO("Send create transmission request, transmission_id [{}]",
|
||||||
transmission_id);
|
transmission_id);
|
||||||
@@ -319,10 +266,8 @@ int PeerConnection::Create(PeerConnectionParams params,
|
|||||||
|
|
||||||
int PeerConnection::Join(PeerConnectionParams params,
|
int PeerConnection::Join(PeerConnectionParams params,
|
||||||
const std::string &transmission_id,
|
const std::string &transmission_id,
|
||||||
const std::string &password)
|
const std::string &password) {
|
||||||
{
|
if (SignalStatus::SignalConnected != GetSignalStatus()) {
|
||||||
if (SignalStatus::SignalConnected != GetSignalStatus())
|
|
||||||
{
|
|
||||||
LOG_ERROR("Signal not connected");
|
LOG_ERROR("Signal not connected");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -336,10 +281,8 @@ int PeerConnection::Join(PeerConnectionParams params,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PeerConnection::Leave()
|
int PeerConnection::Leave() {
|
||||||
{
|
if (SignalStatus::SignalConnected != GetSignalStatus()) {
|
||||||
if (SignalStatus::SignalConnected != GetSignalStatus())
|
|
||||||
{
|
|
||||||
LOG_ERROR("Signal not connected");
|
LOG_ERROR("Signal not connected");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -347,8 +290,7 @@ int PeerConnection::Leave()
|
|||||||
json message = {{"type", "leave_transmission"},
|
json message = {{"type", "leave_transmission"},
|
||||||
{"user_id", user_id_},
|
{"user_id", user_id_},
|
||||||
{"transmission_id", transmission_id_}};
|
{"transmission_id", transmission_id_}};
|
||||||
if (ws_transport_)
|
if (ws_transport_) {
|
||||||
{
|
|
||||||
ws_transport_->Send(message.dump());
|
ws_transport_->Send(message.dump());
|
||||||
LOG_INFO("[{}] sends leave transmission [{}] notification ", user_id_,
|
LOG_INFO("[{}] sends leave transmission [{}] notification ", user_id_,
|
||||||
transmission_id_);
|
transmission_id_);
|
||||||
@@ -356,74 +298,58 @@ int PeerConnection::Leave()
|
|||||||
|
|
||||||
ice_ready_ = false;
|
ice_ready_ = false;
|
||||||
|
|
||||||
for (auto &user_id_it : ice_transmission_list_)
|
for (auto &user_id_it : ice_transmission_list_) {
|
||||||
{
|
|
||||||
user_id_it.second->DestroyIceTransmission();
|
user_id_it.second->DestroyIceTransmission();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerConnection::ProcessSignal(const std::string &signal)
|
void PeerConnection::ProcessSignal(const std::string &signal) {
|
||||||
{
|
|
||||||
auto j = json::parse(signal);
|
auto j = json::parse(signal);
|
||||||
std::string type = j["type"];
|
std::string type = j["type"];
|
||||||
LOG_INFO("signal type: {}", type);
|
LOG_INFO("signal type: {}", type);
|
||||||
switch (HASH_STRING_PIECE(type.c_str()))
|
switch (HASH_STRING_PIECE(type.c_str())) {
|
||||||
{
|
case "ws_connection_id"_H: {
|
||||||
case "ws_connection_id"_H:
|
|
||||||
{
|
|
||||||
ws_connection_id_ = j["ws_connection_id"].get<unsigned int>();
|
ws_connection_id_ = j["ws_connection_id"].get<unsigned int>();
|
||||||
LOG_INFO("Receive local peer websocket connection id [{}]",
|
LOG_INFO("Receive local peer websocket connection id [{}]",
|
||||||
ws_connection_id_);
|
ws_connection_id_);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "transmission_id"_H:
|
case "transmission_id"_H: {
|
||||||
{
|
if (j["status"].get<std::string>() == "success") {
|
||||||
if (j["status"].get<std::string>() == "success")
|
|
||||||
{
|
|
||||||
transmission_id_ = j["transmission_id"].get<std::string>();
|
transmission_id_ = j["transmission_id"].get<std::string>();
|
||||||
LOG_INFO("Create transmission success with id [{}]", transmission_id_);
|
LOG_INFO("Create transmission success with id [{}]", transmission_id_);
|
||||||
}
|
} else if (j["status"].get<std::string>() == "fail") {
|
||||||
else if (j["status"].get<std::string>() == "fail")
|
|
||||||
{
|
|
||||||
LOG_WARN("Create transmission failed with id [{}], due to [{}]",
|
LOG_WARN("Create transmission failed with id [{}], due to [{}]",
|
||||||
transmission_id_, j["reason"].get<std::string>().c_str());
|
transmission_id_, j["reason"].get<std::string>().c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "user_id_list"_H:
|
case "user_id_list"_H: {
|
||||||
{
|
|
||||||
user_id_list_ = j["user_id_list"];
|
user_id_list_ = j["user_id_list"];
|
||||||
|
|
||||||
std::string transmission_id = j["transmission_id"].get<std::string>();
|
std::string transmission_id = j["transmission_id"].get<std::string>();
|
||||||
std::string status = j["status"].get<std::string>();
|
std::string status = j["status"].get<std::string>();
|
||||||
if (status == "failed")
|
if (status == "failed") {
|
||||||
{
|
|
||||||
std::string reason = j["reason"].get<std::string>();
|
std::string reason = j["reason"].get<std::string>();
|
||||||
LOG_ERROR("{}", reason);
|
LOG_ERROR("{}", reason);
|
||||||
on_connection_status_(ConnectionStatus::IncorrectPassword);
|
on_connection_status_(ConnectionStatus::IncorrectPassword);
|
||||||
}
|
} else {
|
||||||
else
|
if (user_id_list_.empty()) {
|
||||||
{
|
|
||||||
if (user_id_list_.empty())
|
|
||||||
{
|
|
||||||
LOG_WARN("Wait for host create transmission [{}]", transmission_id);
|
LOG_WARN("Wait for host create transmission [{}]", transmission_id);
|
||||||
RequestTransmissionMemberList(transmission_id, password_);
|
RequestTransmissionMemberList(transmission_id, password_);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("Transmission [{}] members: [", transmission_id);
|
LOG_INFO("Transmission [{}] members: [", transmission_id);
|
||||||
for (auto user_id : user_id_list_)
|
for (auto user_id : user_id_list_) {
|
||||||
{
|
|
||||||
LOG_INFO("{}", user_id);
|
LOG_INFO("{}", user_id);
|
||||||
}
|
}
|
||||||
LOG_INFO("]");
|
LOG_INFO("]");
|
||||||
|
|
||||||
for (auto &remote_user_id : user_id_list_)
|
for (auto &remote_user_id : user_id_list_) {
|
||||||
{
|
if (remote_user_id == user_id_) {
|
||||||
if (remote_user_id == user_id_)
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ice_transmission_list_[remote_user_id] =
|
ice_transmission_list_[remote_user_id] =
|
||||||
@@ -450,21 +376,18 @@ void PeerConnection::ProcessSignal(const std::string &signal)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "user_leave_transmission"_H:
|
case "user_leave_transmission"_H: {
|
||||||
{
|
|
||||||
std::string user_id = j["user_id"];
|
std::string user_id = j["user_id"];
|
||||||
LOG_INFO("Receive notification: user id [{}] leave transmission",
|
LOG_INFO("Receive notification: user id [{}] leave transmission",
|
||||||
user_id);
|
user_id);
|
||||||
auto user_id_it = ice_transmission_list_.find(user_id);
|
auto user_id_it = ice_transmission_list_.find(user_id);
|
||||||
if (user_id_it != ice_transmission_list_.end())
|
if (user_id_it != ice_transmission_list_.end()) {
|
||||||
{
|
|
||||||
user_id_it->second->DestroyIceTransmission();
|
user_id_it->second->DestroyIceTransmission();
|
||||||
ice_transmission_list_.erase(user_id_it);
|
ice_transmission_list_.erase(user_id_it);
|
||||||
ice_ready_ = false;
|
ice_ready_ = false;
|
||||||
LOG_INFO("Terminate transmission to user [{}]", user_id);
|
LOG_INFO("Terminate transmission to user [{}]", user_id);
|
||||||
|
|
||||||
if (std::string::npos != user_id.find("S-"))
|
if (std::string::npos != user_id.find("S-")) {
|
||||||
{
|
|
||||||
LOG_INFO("Server leaves, try to rejoin transmission");
|
LOG_INFO("Server leaves, try to rejoin transmission");
|
||||||
|
|
||||||
RequestTransmissionMemberList(transmission_id_, password_);
|
RequestTransmissionMemberList(transmission_id_, password_);
|
||||||
@@ -472,16 +395,12 @@ void PeerConnection::ProcessSignal(const std::string &signal)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "offer"_H:
|
case "offer"_H: {
|
||||||
{
|
|
||||||
std::string remote_sdp = j["sdp"].get<std::string>();
|
std::string remote_sdp = j["sdp"].get<std::string>();
|
||||||
|
|
||||||
if (remote_sdp.empty())
|
if (remote_sdp.empty()) {
|
||||||
{
|
|
||||||
LOG_INFO("Invalid remote sdp");
|
LOG_INFO("Invalid remote sdp");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
std::string transmission_id = j["transmission_id"].get<std::string>();
|
std::string transmission_id = j["transmission_id"].get<std::string>();
|
||||||
std::string sdp = j["sdp"].get<std::string>();
|
std::string sdp = j["sdp"].get<std::string>();
|
||||||
std::string remote_user_id = j["remote_user_id"].get<std::string>();
|
std::string remote_user_id = j["remote_user_id"].get<std::string>();
|
||||||
@@ -515,15 +434,11 @@ void PeerConnection::ProcessSignal(const std::string &signal)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "answer"_H:
|
case "answer"_H: {
|
||||||
{
|
|
||||||
std::string remote_sdp = j["sdp"].get<std::string>();
|
std::string remote_sdp = j["sdp"].get<std::string>();
|
||||||
if (remote_sdp.empty())
|
if (remote_sdp.empty()) {
|
||||||
{
|
|
||||||
LOG_INFO("remote_sdp is empty");
|
LOG_INFO("remote_sdp is empty");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
std::string transmission_id = j["transmission_id"].get<std::string>();
|
std::string transmission_id = j["transmission_id"].get<std::string>();
|
||||||
std::string sdp = j["sdp"].get<std::string>();
|
std::string sdp = j["sdp"].get<std::string>();
|
||||||
std::string remote_user_id = j["remote_user_id"].get<std::string>();
|
std::string remote_user_id = j["remote_user_id"].get<std::string>();
|
||||||
@@ -531,8 +446,7 @@ void PeerConnection::ProcessSignal(const std::string &signal)
|
|||||||
LOG_INFO("[{}] receive answer from [{}]", user_id_, remote_user_id);
|
LOG_INFO("[{}] receive answer from [{}]", user_id_, remote_user_id);
|
||||||
|
|
||||||
if (ice_transmission_list_.find(remote_user_id) !=
|
if (ice_transmission_list_.find(remote_user_id) !=
|
||||||
ice_transmission_list_.end())
|
ice_transmission_list_.end()) {
|
||||||
{
|
|
||||||
ice_transmission_list_[remote_user_id]->SetRemoteSdp(remote_sdp);
|
ice_transmission_list_[remote_user_id]->SetRemoteSdp(remote_sdp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,18 +454,15 @@ void PeerConnection::ProcessSignal(const std::string &signal)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int PeerConnection::RequestTransmissionMemberList(
|
int PeerConnection::RequestTransmissionMemberList(
|
||||||
const std::string &transmission_id, const std::string &password)
|
const std::string &transmission_id, const std::string &password) {
|
||||||
{
|
if (SignalStatus::SignalConnected != GetSignalStatus()) {
|
||||||
if (SignalStatus::SignalConnected != GetSignalStatus())
|
|
||||||
{
|
|
||||||
LOG_ERROR("Signal not connected");
|
LOG_ERROR("Signal not connected");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -562,8 +473,7 @@ int PeerConnection::RequestTransmissionMemberList(
|
|||||||
{"transmission_id", transmission_id_},
|
{"transmission_id", transmission_id_},
|
||||||
{"password", password}};
|
{"password", password}};
|
||||||
|
|
||||||
if (ws_transport_)
|
if (ws_transport_) {
|
||||||
{
|
|
||||||
ws_transport_->Send(message.dump());
|
ws_transport_->Send(message.dump());
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -571,43 +481,37 @@ int PeerConnection::RequestTransmissionMemberList(
|
|||||||
|
|
||||||
int PeerConnection::Destroy() { return 0; }
|
int PeerConnection::Destroy() { return 0; }
|
||||||
|
|
||||||
SignalStatus PeerConnection::GetSignalStatus()
|
SignalStatus PeerConnection::GetSignalStatus() {
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> l(signal_status_mutex_);
|
std::lock_guard<std::mutex> l(signal_status_mutex_);
|
||||||
return signal_status_;
|
return signal_status_;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PeerConnection::SendVideoData(const char *data, size_t size)
|
int PeerConnection::SendVideoData(const char *data, size_t size) {
|
||||||
{
|
if (!ice_ready_) {
|
||||||
if (!ice_ready_)
|
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ice_transmission_list_.empty())
|
if (ice_transmission_list_.empty()) {
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b_force_i_frame_)
|
if (b_force_i_frame_) {
|
||||||
{
|
|
||||||
video_encoder_->ForceIdr();
|
video_encoder_->ForceIdr();
|
||||||
LOG_INFO("Force I frame");
|
LOG_INFO("Force I frame");
|
||||||
b_force_i_frame_ = false;
|
b_force_i_frame_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = video_encoder_->Encode(
|
int ret = video_encoder_->Encode(
|
||||||
(uint8_t *)data, size, [this](char *encoded_frame, size_t size) -> int
|
(uint8_t *)data, size, [this](char *encoded_frame, size_t size) -> int {
|
||||||
{
|
|
||||||
for (auto &ice_trans : ice_transmission_list_) {
|
for (auto &ice_trans : ice_transmission_list_) {
|
||||||
LOG_ERROR("H264 frame size: [{}]", size);
|
// LOG_ERROR("H264 frame size: [{}]", size);
|
||||||
ice_trans.second->SendData(IceTransmission::DATA_TYPE::VIDEO,
|
ice_trans.second->SendData(IceTransmission::DATA_TYPE::VIDEO,
|
||||||
encoded_frame, size);
|
encoded_frame, size);
|
||||||
}
|
}
|
||||||
return 0; });
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
{
|
|
||||||
LOG_ERROR("Encode failed");
|
LOG_ERROR("Encode failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -615,14 +519,11 @@ int PeerConnection::SendVideoData(const char *data, size_t size)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PeerConnection::SendAudioData(const char *data, size_t size)
|
int PeerConnection::SendAudioData(const char *data, size_t size) {
|
||||||
{
|
|
||||||
int ret = audio_encoder_->Encode(
|
int ret = audio_encoder_->Encode(
|
||||||
(uint8_t *)data, size,
|
(uint8_t *)data, size,
|
||||||
[this](char *encoded_audio_buffer, size_t size) -> int
|
[this](char *encoded_audio_buffer, size_t size) -> int {
|
||||||
{
|
for (auto &ice_trans : ice_transmission_list_) {
|
||||||
for (auto &ice_trans : ice_transmission_list_)
|
|
||||||
{
|
|
||||||
// LOG_ERROR("opus frame size: [{}]", size);
|
// LOG_ERROR("opus frame size: [{}]", size);
|
||||||
ice_trans.second->SendData(IceTransmission::DATA_TYPE::AUDIO,
|
ice_trans.second->SendData(IceTransmission::DATA_TYPE::AUDIO,
|
||||||
encoded_audio_buffer, size);
|
encoded_audio_buffer, size);
|
||||||
@@ -633,10 +534,8 @@ int PeerConnection::SendAudioData(const char *data, size_t size)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PeerConnection::SendUserData(const char *data, size_t size)
|
int PeerConnection::SendUserData(const char *data, size_t size) {
|
||||||
{
|
for (auto &ice_trans : ice_transmission_list_) {
|
||||||
for (auto &ice_trans : ice_transmission_list_)
|
|
||||||
{
|
|
||||||
ice_trans.second->SendData(IceTransmission::DATA_TYPE::DATA, data, size);
|
ice_trans.second->SendData(IceTransmission::DATA_TYPE::DATA, data, size);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
2
thirdparty/xmake.lua
vendored
2
thirdparty/xmake.lua
vendored
@@ -2,4 +2,6 @@ includes("openfec")
|
|||||||
if is_plat("windows") then
|
if is_plat("windows") then
|
||||||
elseif is_plat("linux") then
|
elseif is_plat("linux") then
|
||||||
includes("ffmpeg")
|
includes("ffmpeg")
|
||||||
|
elseif is_plat("macosx") then
|
||||||
|
includes("ffmpeg")
|
||||||
end
|
end
|
||||||
19
xmake.lua
19
xmake.lua
@@ -33,9 +33,9 @@ elseif is_os("linux") then
|
|||||||
add_syslinks("pthread")
|
add_syslinks("pthread")
|
||||||
elseif is_os("macosx") then
|
elseif is_os("macosx") then
|
||||||
add_requires("ffmpeg 5.1.2", {system = false})
|
add_requires("ffmpeg 5.1.2", {system = false})
|
||||||
add_requires("brew::libnice")
|
add_requires("vcpkg::libnice", {configs = {shared = false}})
|
||||||
add_requires("brew::openh264", {configs = {shared = false}})
|
add_requires("brew::openh264", {configs = {shared = false}})
|
||||||
add_packages("ffmpeg", "brew::libnice", "brew::openh264")
|
add_packages("ffmpeg", "vcpkg::libnice", "brew::openh264")
|
||||||
add_ldflags("-Wl,-ld_classic")
|
add_ldflags("-Wl,-ld_classic")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -99,16 +99,7 @@ target("ice")
|
|||||||
add_includedirs(path.join(os.getenv("VCPKG_ROOT"),
|
add_includedirs(path.join(os.getenv("VCPKG_ROOT"),
|
||||||
"installed/x64-windows-static/lib/glib-2.0/include"), {public = true})
|
"installed/x64-windows-static/lib/glib-2.0/include"), {public = true})
|
||||||
elseif is_os("macosx") then
|
elseif is_os("macosx") then
|
||||||
add_includedirs(path.join("$(shell brew --cellar)",
|
|
||||||
"glib/2.78.0/include/glib-2.0"), {public = true})
|
|
||||||
add_includedirs(path.join("$(shell brew --cellar)",
|
|
||||||
"glib/2.78.0/lib/glib-2.0/include"), {public = true})
|
|
||||||
add_includedirs(path.join("$(shell brew --cellar)",
|
|
||||||
"glib/2.78.0/lib/glib-2.0/include"), {public = true})
|
|
||||||
add_includedirs(path.join("$(shell brew --cellar)",
|
|
||||||
"glib/2.78.0/include"), {public = true})
|
|
||||||
add_includedirs(path.join("$(shell brew --cellar)",
|
|
||||||
"libnice/0.1.21/include"), {public = true})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
target("ws")
|
target("ws")
|
||||||
@@ -215,9 +206,7 @@ target("projectx")
|
|||||||
add_linkdirs("thirdparty/nvcodec/Lib/x64")
|
add_linkdirs("thirdparty/nvcodec/Lib/x64")
|
||||||
add_links("cuda", "nvidia-encode", "nvcuvid")
|
add_links("cuda", "nvidia-encode", "nvcuvid")
|
||||||
elseif is_os("macosx") then
|
elseif is_os("macosx") then
|
||||||
add_linkdirs(path.join("$(shell brew --cellar)", "glib/2.78.0/lib"))
|
|
||||||
add_linkdirs(path.join("$(shell brew --cellar)", "libnice/0.1.21/lib"))
|
|
||||||
add_links("nice", "glib-2.0", "gio-2.0", "gobject-2.0")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_installfiles("src/interface/*.h", {prefixdir = "include"})
|
add_installfiles("src/interface/*.h", {prefixdir = "include"})
|
||||||
|
|||||||
Reference in New Issue
Block a user