mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[fix] fix the issue where the media payload type parsing failed
This commit is contained in:
@@ -194,7 +194,7 @@ const char *IceAgent::GenerateLocalSdp() {
|
|||||||
local_sdp_ += data_stream_sdp_;
|
local_sdp_ += data_stream_sdp_;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("Generate local sdp:[\n{}]", local_sdp_.c_str());
|
// LOG_INFO("Generate local sdp:[\n{}]", local_sdp_.c_str());
|
||||||
|
|
||||||
return local_sdp_.c_str();
|
return local_sdp_.c_str();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -380,12 +380,7 @@ int IceTransmission::GatherCandidates() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int IceTransmission::SetRemoteSdp(const std::string &remote_sdp) {
|
int IceTransmission::SetRemoteSdp(const std::string &remote_sdp) {
|
||||||
// GetAceptedVideoPayloadType(remote_sdp);
|
std::string media_stream_sdp = GetRemoteCapabilities(remote_sdp);
|
||||||
// GetAceptedAudioPayloadType(remote_sdp);
|
|
||||||
|
|
||||||
std::string media_stream_sdp = GetLocalCapabilitiesToSdp(remote_sdp);
|
|
||||||
LOG_ERROR("media_stream_sdp: [{}] [{}]", media_stream_sdp, remote_sdp);
|
|
||||||
|
|
||||||
ice_agent_->SetRemoteSdp(media_stream_sdp.c_str());
|
ice_agent_->SetRemoteSdp(media_stream_sdp.c_str());
|
||||||
// LOG_INFO("[{}] set remote sdp", user_id_);
|
// LOG_INFO("[{}] set remote sdp", user_id_);
|
||||||
|
|
||||||
@@ -395,9 +390,7 @@ int IceTransmission::SetRemoteSdp(const std::string &remote_sdp) {
|
|||||||
|
|
||||||
int IceTransmission::SendOffer() {
|
int IceTransmission::SendOffer() {
|
||||||
local_sdp_ = ice_agent_->GenerateLocalSdp();
|
local_sdp_ = ice_agent_->GenerateLocalSdp();
|
||||||
|
AppendLocalCapabilities(local_sdp_);
|
||||||
AppendLocalCapabilitiesToSdp(local_sdp_);
|
|
||||||
|
|
||||||
json message = {{"type", "offer"},
|
json message = {{"type", "offer"},
|
||||||
{"transmission_id", transmission_id_},
|
{"transmission_id", transmission_id_},
|
||||||
{"user_id", user_id_},
|
{"user_id", user_id_},
|
||||||
@@ -413,6 +406,7 @@ int IceTransmission::SendOffer() {
|
|||||||
|
|
||||||
int IceTransmission::SendAnswer() {
|
int IceTransmission::SendAnswer() {
|
||||||
local_sdp_ = ice_agent_->GenerateLocalSdp();
|
local_sdp_ = ice_agent_->GenerateLocalSdp();
|
||||||
|
AppendLocalCapabilities(local_sdp_);
|
||||||
json message = {{"type", "answer"},
|
json message = {{"type", "answer"},
|
||||||
{"transmission_id", transmission_id_},
|
{"transmission_id", transmission_id_},
|
||||||
{"user_id", user_id_},
|
{"user_id", user_id_},
|
||||||
@@ -427,7 +421,7 @@ int IceTransmission::SendAnswer() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IceTransmission::AppendLocalCapabilitiesToSdp(std::string &remote_sdp) {
|
int IceTransmission::AppendLocalCapabilities(std::string &remote_sdp) {
|
||||||
std::string to_replace = "ICE/SDP";
|
std::string to_replace = "ICE/SDP";
|
||||||
std::string video_capabilities = "UDP/TLS/RTP/SAVPF 96 97 98 99";
|
std::string video_capabilities = "UDP/TLS/RTP/SAVPF 96 97 98 99";
|
||||||
std::string audio_capabilities = "UDP/TLS/RTP/SAVPF 111";
|
std::string audio_capabilities = "UDP/TLS/RTP/SAVPF 111";
|
||||||
@@ -465,7 +459,7 @@ int IceTransmission::AppendLocalCapabilitiesToSdp(std::string &remote_sdp) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string IceTransmission::GetLocalCapabilitiesToSdp(
|
std::string IceTransmission::GetRemoteCapabilities(
|
||||||
const std::string &remote_sdp) {
|
const std::string &remote_sdp) {
|
||||||
std::string media_stream_sdp;
|
std::string media_stream_sdp;
|
||||||
std::size_t video_start = remote_sdp.find("m=video");
|
std::size_t video_start = remote_sdp.find("m=video");
|
||||||
@@ -476,6 +470,10 @@ std::string IceTransmission::GetLocalCapabilitiesToSdp(
|
|||||||
std::size_t data_end = remote_sdp.find("a=candidate");
|
std::size_t data_end = remote_sdp.find("a=candidate");
|
||||||
std::size_t candidate_start = data_end;
|
std::size_t candidate_start = data_end;
|
||||||
|
|
||||||
|
GetAceptedVideoPayloadType(remote_sdp);
|
||||||
|
GetAceptedAudioPayloadType(remote_sdp);
|
||||||
|
GetAceptedDataPayloadType(remote_sdp);
|
||||||
|
|
||||||
if ((video_start != std::string::npos && video_end != std::string::npos) ||
|
if ((video_start != std::string::npos && video_end != std::string::npos) ||
|
||||||
(audio_start != std::string::npos && audio_end != std::string::npos) ||
|
(audio_start != std::string::npos && audio_end != std::string::npos) ||
|
||||||
(data_start != std::string::npos && data_end != std::string::npos)) {
|
(data_start != std::string::npos && data_end != std::string::npos)) {
|
||||||
@@ -542,6 +540,27 @@ RtpPacket::PAYLOAD_TYPE IceTransmission::GetAceptedAudioPayloadType(
|
|||||||
return RtpPacket::PAYLOAD_TYPE::OPUS;
|
return RtpPacket::PAYLOAD_TYPE::OPUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RtpPacket::PAYLOAD_TYPE IceTransmission::GetAceptedDataPayloadType(
|
||||||
|
const std::string &remote_sdp) {
|
||||||
|
if (!data_pt_.empty()) {
|
||||||
|
return RtpPacket::PAYLOAD_TYPE::H264;
|
||||||
|
}
|
||||||
|
std::size_t start =
|
||||||
|
remote_sdp.find("m=data") + std::string("m=data").length();
|
||||||
|
if (start != std::string::npos) {
|
||||||
|
std::size_t end = remote_sdp.find("\n", start);
|
||||||
|
std::string::size_type pos1 = remote_sdp.find(' ', start);
|
||||||
|
std::string::size_type pos2 = remote_sdp.find(' ', pos1 + 1);
|
||||||
|
std::string::size_type pos3 = remote_sdp.find(' ', pos2 + 1);
|
||||||
|
if (end != std::string::npos && pos1 != std::string::npos &&
|
||||||
|
pos2 != std::string::npos && pos3 != std::string::npos) {
|
||||||
|
data_pt_ = remote_sdp.substr(pos3 + 1, end - pos3 - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG_INFO("data pt [{}]", data_pt_.c_str());
|
||||||
|
return RtpPacket::PAYLOAD_TYPE::DATA;
|
||||||
|
}
|
||||||
|
|
||||||
int IceTransmission::SendData(DATA_TYPE type, const char *data, size_t size) {
|
int IceTransmission::SendData(DATA_TYPE type, const char *data, size_t size) {
|
||||||
if (state_ != NICE_COMPONENT_STATE_CONNECTED &&
|
if (state_ != NICE_COMPONENT_STATE_CONNECTED &&
|
||||||
state_ != NICE_COMPONENT_STATE_READY) {
|
state_ != NICE_COMPONENT_STATE_READY) {
|
||||||
|
|||||||
@@ -104,13 +104,15 @@ class IceTransmission {
|
|||||||
int SendAnswer();
|
int SendAnswer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int AppendLocalCapabilitiesToSdp(std::string &remote_sdp);
|
int AppendLocalCapabilities(std::string &remote_sdp);
|
||||||
std::string GetLocalCapabilitiesToSdp(const std::string &remote_sdp);
|
std::string GetRemoteCapabilities(const std::string &remote_sdp);
|
||||||
|
|
||||||
RtpPacket::PAYLOAD_TYPE GetAceptedVideoPayloadType(
|
RtpPacket::PAYLOAD_TYPE GetAceptedVideoPayloadType(
|
||||||
const std::string &remote_sdp);
|
const std::string &remote_sdp);
|
||||||
RtpPacket::PAYLOAD_TYPE GetAceptedAudioPayloadType(
|
RtpPacket::PAYLOAD_TYPE GetAceptedAudioPayloadType(
|
||||||
const std::string &remote_sdp);
|
const std::string &remote_sdp);
|
||||||
|
RtpPacket::PAYLOAD_TYPE GetAceptedDataPayloadType(
|
||||||
|
const std::string &remote_sdp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t CheckIsRtcpPacket(const char *buffer, size_t size);
|
uint8_t CheckIsRtcpPacket(const char *buffer, size_t size);
|
||||||
@@ -176,6 +178,7 @@ class IceTransmission {
|
|||||||
private:
|
private:
|
||||||
std::string video_pt_;
|
std::string video_pt_;
|
||||||
std::string audio_pt_;
|
std::string audio_pt_;
|
||||||
|
std::string data_pt_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user