[feat] move rtp packet sender out of channel module

This commit is contained in:
dijunkun
2025-03-13 21:11:20 +08:00
parent 23df1f3b60
commit d2b45b91e7
32 changed files with 681 additions and 266 deletions

View File

@@ -44,9 +44,9 @@ void AudioChannelSend::Destroy() {
int AudioChannelSend::SendAudio(char *data, size_t size) {
if (rtp_audio_sender_ && rtp_packetizer_) {
std::vector<std::shared_ptr<RtpPacket>> rtp_packets =
std::vector<std::unique_ptr<RtpPacket>> rtp_packets =
rtp_packetizer_->Build((uint8_t *)data, (uint32_t)size, 0, true);
rtp_audio_sender_->Enqueue(rtp_packets);
rtp_audio_sender_->Enqueue(std::move(rtp_packets));
}
return 0;

View File

@@ -44,9 +44,9 @@ void DataChannelSend::Destroy() {
int DataChannelSend::SendData(const char *data, size_t size) {
if (rtp_data_sender_ && rtp_packetizer_) {
std::vector<std::shared_ptr<RtpPacket>> rtp_packets =
std::vector<std::unique_ptr<RtpPacket>> rtp_packets =
rtp_packetizer_->Build((uint8_t *)data, (uint32_t)size, 0, true);
rtp_data_sender_->Enqueue(rtp_packets);
rtp_data_sender_->Enqueue(std::move(rtp_packets));
}
return 0;

View File

@@ -48,6 +48,21 @@ void VideoChannelSend::Initialize(rtp::PAYLOAD_TYPE payload_type) {
rtp_video_sender_->Start();
}
void VideoChannelSend::SetEnqueuePacketsFunc(
std::function<void(std::vector<std::unique_ptr<webrtc::RtpPacketToSend>>&)>
enqueue_packets_func) {
rtp_video_sender_->SetEnqueuePacketsFunc(enqueue_packets_func);
}
std::vector<std::unique_ptr<RtpPacket>> VideoChannelSend::GeneratePadding(
uint32_t payload_size, int64_t capture_timestamp_ms) {
if (rtp_packetizer_) {
return rtp_packetizer_->BuildPadding(payload_size, capture_timestamp_ms,
true);
}
return std::vector<std::unique_ptr<RtpPacket>>{};
}
void VideoChannelSend::Destroy() {
if (rtp_video_sender_) {
rtp_video_sender_->Stop();
@@ -57,11 +72,12 @@ void VideoChannelSend::Destroy() {
int VideoChannelSend::SendVideo(
std::shared_ptr<VideoFrameWrapper> encoded_frame) {
if (rtp_video_sender_ && rtp_packetizer_) {
std::vector<std::shared_ptr<RtpPacket>> rtp_packets =
std::vector<std::unique_ptr<RtpPacket>> rtp_packets =
rtp_packetizer_->Build((uint8_t*)encoded_frame->Buffer(),
(uint32_t)encoded_frame->Size(),
encoded_frame->CaptureTimestamp(), true);
rtp_video_sender_->Enqueue(rtp_packets, encoded_frame->CaptureTimestamp());
rtp_video_sender_->Enqueue(std::move(rtp_packets),
encoded_frame->CaptureTimestamp());
}
return 0;

View File

@@ -28,6 +28,14 @@ class VideoChannelSend {
on_sent_packet_func_);
~VideoChannelSend();
void SetEnqueuePacketsFunc(
std::function<
void(std::vector<std::unique_ptr<webrtc::RtpPacketToSend>>&)>
enqueue_packets_func);
std::vector<std::unique_ptr<RtpPacket>> GeneratePadding(
uint32_t payload_size, int64_t capture_timestamp_ms);
public:
void Initialize(rtp::PAYLOAD_TYPE payload_type);
void Destroy();