[feat] separate rtp send/receive module from ice transport module

This commit is contained in:
dijunkun
2025-01-03 17:34:46 +08:00
parent 7ddcca53e4
commit eef35ff0d4
18 changed files with 384 additions and 218 deletions

View File

@@ -0,0 +1 @@
#include "audio_channel_receive.h"

View File

@@ -0,0 +1,18 @@
/*
* @Author: DI JUNKUN
* @Date: 2025-01-03
* Copyright (c) 2025 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _AUDIO_CHANNEL_RECEIVE_H_
#define _AUDIO_CHANNEL_RECEIVE_H_
class AudioChannelReceive {
public:
AudioChannelReceive();
~AudioChannelReceive();
public:
};
#endif

View File

@@ -0,0 +1 @@
#include "audio_channel_send.h"

View File

@@ -0,0 +1,18 @@
/*
* @Author: DI JUNKUN
* @Date: 2025-01-03
* Copyright (c) 2025 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _AUDIO_CHANNEL_SEND_H_
#define _AUDIO_CHANNEL_SEND_H_
class AudioChannelSend {
public:
AudioChannelSend();
~AudioChannelSend();
public:
};
#endif

View File

@@ -0,0 +1 @@
#include "data_channel_receive.h"

View File

@@ -0,0 +1,18 @@
/*
* @Author: DI JUNKUN
* @Date: 2025-01-03
* Copyright (c) 2025 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _DATA_CHANNEL_RECEIVE_H_
#define _DATA_CHANNEL_RECEIVE_H_
class DataChannelReceive {
public:
DataChannelReceive();
~DataChannelReceive();
public:
};
#endif

View File

@@ -0,0 +1 @@
#include "data_channel_send.h"

View File

@@ -0,0 +1,18 @@
/*
* @Author: DI JUNKUN
* @Date: 2025-01-03
* Copyright (c) 2025 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _DATA_CHANNEL_SEND_H_
#define _DATA_CHANNEL_SEND_H_
class DataChannelSend {
public:
DataChannelSend();
~DataChannelSend();
public:
};
#endif

View File

@@ -0,0 +1 @@
#include "video_channel_receive.h"

View File

@@ -0,0 +1,18 @@
/*
* @Author: DI JUNKUN
* @Date: 2025-01-03
* Copyright (c) 2025 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _VIDEO_CHANNEL_RECEIVE_H_
#define _VIDEO_CHANNEL_RECEIVE_H_
class VideoChannelReceive {
public:
VideoChannelReceive();
~VideoChannelReceive();
public:
};
#endif

View File

@@ -0,0 +1,50 @@
#include "video_channel_send.h"
VideoChannelSend::VideoChannelSend() {}
VideoChannelSend::~VideoChannelSend() {}
void VideoChannelSend::Initialize(RtpPacket::PAYLOAD_TYPE negotiated_video_pt) {
video_rtp_codec_ = std::make_unique<RtpCodec>(negotiated_video_pt);
rtp_video_sender_ = std::make_unique<RtpVideoSender>(ice_io_statistics_);
rtp_video_sender_->SetSendDataFunc(
[this](const char *data, size_t size) -> int {
if (!ice_agent_) {
LOG_ERROR("ice_agent_ is nullptr");
return -1;
}
if (state_ != NICE_COMPONENT_STATE_CONNECTED &&
state_ != NICE_COMPONENT_STATE_READY) {
LOG_ERROR("Ice is not connected, state = [{}]",
nice_component_state_to_string(state_));
return -2;
}
ice_io_statistics_->UpdateVideoOutboundBytes((uint32_t)size);
return ice_agent_->Send(data, size);
});
rtp_video_sender_->Start();
}
void VideoChannelSend::Destroy() {
if (rtp_video_sender_) {
rtp_video_sender_->Stop();
}
}
int VideoChannelSend::SendVideo(char *encoded_frame, size_t size) {
std::vector<RtpPacket> packets;
if (rtp_video_sender_) {
if (video_rtp_codec_) {
video_rtp_codec_->Encode(
static_cast<RtpCodec::VideoFrameType>(frame_type),
(uint8_t *)encoded_frame, (uint32_t)size, packets);
}
rtp_video_sender_->Enqueue(packets);
}
return 0;
}

View File

@@ -0,0 +1,29 @@
/*
* @Author: DI JUNKUN
* @Date: 2025-01-03
* Copyright (c) 2025 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _VIDEO_CHANNEL_SEND_H_
#define _VIDEO_CHANNEL_SEND_H_
#include "rtp_codec.h"
#include "rtp_video_sender.h"
class VideoChannelSend {
public:
VideoChannelSend();
~VideoChannelSend();
public:
void Initialize(RtpPacket::PAYLOAD_TYPE negotiated_video_pt);
void Destroy();
int SendVideo(char *encoded_frame, size_t size);
private:
std::unique_ptr<RtpCodec> video_rtp_codec_ = nullptr;
std::unique_ptr<RtpVideoSender> rtp_video_sender_ = nullptr;
};
#endif