Implementation for user data sending

This commit is contained in:
dijunkun
2023-09-13 17:31:02 +08:00
parent e2533d18e4
commit a0abb7455c
27 changed files with 513 additions and 233 deletions

View File

@@ -8,12 +8,16 @@
RtpVideoSender::RtpVideoSender() {}
RtpVideoSender::~RtpVideoSender() { rtp_video_send_statistics_->Stop(); }
RtpVideoSender::~RtpVideoSender() {
if (rtp_statistics_) {
rtp_statistics_->Stop();
}
}
void RtpVideoSender::Enqueue(std::vector<RtpPacket>& rtp_packets) {
if (!rtp_video_send_statistics_) {
rtp_video_send_statistics_ = std::make_unique<RtpVideoSendStatistics>();
rtp_video_send_statistics_->Start();
if (!rtp_statistics_) {
rtp_statistics_ = std::make_unique<RtpStatistics>();
rtp_statistics_->Start();
}
for (auto& rtp_packet : rtp_packets) {
@@ -21,20 +25,21 @@ void RtpVideoSender::Enqueue(std::vector<RtpPacket>& rtp_packets) {
}
}
void RtpVideoSender::SetUdpSender(
std::function<int(const char*, size_t)> udp_sender) {
udp_sender_ = udp_sender;
void RtpVideoSender::SetSendDataFunc(
std::function<int(const char*, size_t)> data_send_func) {
data_send_func_ = data_send_func;
}
int RtpVideoSender::SendRtpPacket(RtpPacket& rtp_packet) {
if (!udp_sender_) {
LOG_ERROR("udp_sender_ is nullptr");
if (!data_send_func_) {
LOG_ERROR("data_send_func_ is nullptr");
return -1;
}
int ret = 0;
if (0 != udp_sender_((const char*)rtp_packet.Buffer(), rtp_packet.Size())) {
if (0 !=
data_send_func_((const char*)rtp_packet.Buffer(), rtp_packet.Size())) {
LOG_ERROR("Send rtp packet failed");
return -1;
}
@@ -87,12 +92,12 @@ int RtpVideoSender::SendRtpPacket(RtpPacket& rtp_packet) {
}
int RtpVideoSender::SendRtcpSR(RtcpSenderReport& rtcp_sr) {
if (!udp_sender_) {
LOG_ERROR("udp_sender_ is nullptr");
if (!data_send_func_) {
LOG_ERROR("data_send_func_ is nullptr");
return -1;
}
if (udp_sender_((const char*)rtcp_sr.Buffer(), rtcp_sr.Size())) {
if (data_send_func_((const char*)rtcp_sr.Buffer(), rtcp_sr.Size())) {
LOG_ERROR("Send SR failed");
return -1;
}
@@ -126,8 +131,8 @@ bool RtpVideoSender::Process() {
SendRtpPacket(rtp_packet);
}
if (rtp_video_send_statistics_) {
rtp_video_send_statistics_->UpdateSentBytes(last_send_bytes_);
if (rtp_statistics_) {
rtp_statistics_->UpdateSentBytes(last_send_bytes_);
}
std::this_thread::sleep_for(std::chrono::milliseconds(5));