[feat] update transport module and channel module

This commit is contained in:
dijunkun
2025-01-06 17:10:56 +08:00
parent eef35ff0d4
commit 0737eee95a
17 changed files with 927 additions and 605 deletions

View File

@@ -1 +1,55 @@
#include "audio_channel_send.h"
#include "audio_channel_send.h"
#include "log.h"
AudioChannelSend::AudioChannelSend() {}
AudioChannelSend::~AudioChannelSend() {}
AudioChannelSend::AudioChannelSend(
std::shared_ptr<IceAgent> ice_agent,
std::shared_ptr<IOStatistics> ice_io_statistics)
: ice_agent_(ice_agent), ice_io_statistics_(ice_io_statistics) {}
void AudioChannelSend::Initialize(RtpPacket::PAYLOAD_TYPE payload_type) {
audio_rtp_codec_ = std::make_unique<RtpCodec>(payload_type);
rtp_audio_sender_ = std::make_unique<RtpAudioSender>(ice_io_statistics_);
rtp_audio_sender_->SetSendDataFunc(
[this](const char *data, size_t size) -> int {
if (!ice_agent_) {
LOG_ERROR("ice_agent_ is nullptr");
return -1;
}
auto ice_state = ice_agent_->GetIceState();
if (ice_state != NICE_COMPONENT_STATE_CONNECTED &&
ice_state != NICE_COMPONENT_STATE_READY) {
LOG_ERROR("Ice is not connected, state = [{}]",
nice_component_state_to_string(ice_state));
return -2;
}
ice_io_statistics_->UpdateAudioOutboundBytes((uint32_t)size);
return ice_agent_->Send(data, size);
});
rtp_audio_sender_->Start();
}
void AudioChannelSend::Destroy() {
if (rtp_audio_sender_) {
rtp_audio_sender_->Stop();
}
}
int AudioChannelSend::SendAudio(char *data, size_t size) {
if (audio_rtp_codec_) {
std::vector<RtpPacket> packets;
audio_rtp_codec_->Encode((uint8_t *)data, (uint32_t)size, packets);
rtp_audio_sender_->Enqueue(packets);
}
return 0;
}