mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[feat] separate rtp send/receive module from ice transport module
This commit is contained in:
1
src/channel/audio_channel_receive.cpp
Normal file
1
src/channel/audio_channel_receive.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "audio_channel_receive.h"
|
||||
18
src/channel/audio_channel_receive.h
Normal file
18
src/channel/audio_channel_receive.h
Normal 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
|
||||
1
src/channel/audio_channel_send.cpp
Normal file
1
src/channel/audio_channel_send.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "audio_channel_send.h"
|
||||
18
src/channel/audio_channel_send.h
Normal file
18
src/channel/audio_channel_send.h
Normal 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
|
||||
1
src/channel/data_channel_receive.cpp
Normal file
1
src/channel/data_channel_receive.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "data_channel_receive.h"
|
||||
18
src/channel/data_channel_receive.h
Normal file
18
src/channel/data_channel_receive.h
Normal 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
|
||||
1
src/channel/data_channel_send.cpp
Normal file
1
src/channel/data_channel_send.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "data_channel_send.h"
|
||||
18
src/channel/data_channel_send.h
Normal file
18
src/channel/data_channel_send.h
Normal 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
|
||||
1
src/channel/video_channel_receive.cpp
Normal file
1
src/channel/video_channel_receive.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "video_channel_receive.h"
|
||||
18
src/channel/video_channel_receive.h
Normal file
18
src/channel/video_channel_receive.h
Normal 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
|
||||
50
src/channel/video_channel_send.cpp
Normal file
50
src/channel/video_channel_send.cpp
Normal 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;
|
||||
}
|
||||
29
src/channel/video_channel_send.h
Normal file
29
src/channel/video_channel_send.h
Normal 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
|
||||
Reference in New Issue
Block a user