Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/Handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ namespace mediasoupclient
nlohmann::json GetSenderStats(const std::string& localId);
void RestartIce(const nlohmann::json& iceParameters) override;
DataChannel SendDataChannel(const std::string& label, webrtc::DataChannelInit dataChannelInit);
void PauseSending(const std::string& localId);
void ResumeSending(const std::string& localId);

private:
// Generic sending RTP parameters for audio and video.
Expand Down
2 changes: 2 additions & 0 deletions include/Producer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace mediasoupclient
const Producer* producer, webrtc::MediaStreamTrackInterface* newTrack) = 0;
virtual void OnSetMaxSpatialLayer(const Producer* producer, uint8_t maxSpatialLayer) = 0;
virtual nlohmann::json OnGetStats(const Producer* producer) = 0;
virtual void OnPause(Producer* producer) = 0;
virtual void OnResume(Producer* producer) = 0;
};

/* Public Listener API */
Expand Down
2 changes: 2 additions & 0 deletions include/Transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ namespace mediasoupclient
void OnReplaceTrack(const Producer* producer, webrtc::MediaStreamTrackInterface* track) override;
void OnSetMaxSpatialLayer(const Producer* producer, uint8_t maxSpatialLayer) override;
nlohmann::json OnGetStats(const Producer* producer) override;
void OnPause(Producer* producer);
void OnResume(Producer* producer);

private:
// Listener instance.
Expand Down
47 changes: 47 additions & 0 deletions src/Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,53 @@ namespace mediasoupclient
this->pc->SetRemoteDescription(PeerConnection::SdpType::ANSWER, answer);
}

void SendHandler::PauseSending(const std::string& localId)
{
MSC_DEBUG("[localId:%s]", localId.c_str());

auto locaIdIt = this->mapMidTransceiver.find(localId);

if (locaIdIt == this->mapMidTransceiver.end())
MSC_THROW_ERROR("associated RtpTransceiver not found");

auto* transceiver = locaIdIt->second;

transceiver->SetDirectionWithError(webrtc::RtpTransceiverDirection::kInactive);
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options;
std::string offer = this->pc->CreateOffer(options);

MSC_DEBUG("calling pc.setLocalDescription() [offer:%s]", offer.c_str());

this->pc->SetLocalDescription(PeerConnection::SdpType::OFFER, offer);

auto sdpAnswer = this->remoteSdp->GetSdp();
MSC_DEBUG("calling pc.setRemoteDescription() [answer:%s]", sdpAnswer.c_str());
this->pc->SetRemoteDescription(PeerConnection::SdpType::ANSWER, sdpAnswer);
}

void SendHandler::ResumeSending(const std::string& localId)
{
MSC_DEBUG("resumeSending() [localId:%s]", localId.c_str());

auto locaIdIt = this->mapMidTransceiver.find(localId);

if (locaIdIt == this->mapMidTransceiver.end())
MSC_THROW_ERROR("associated RtpTransceiver not found");

auto* transceiver = locaIdIt->second;

transceiver->SetDirectionWithError(webrtc::RtpTransceiverDirection::kSendOnly);
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options;
std::string offer = this->pc->CreateOffer(options);

MSC_DEBUG("calling pc.setLocalDescription() [offer:%s]", offer.c_str());
this->pc->SetLocalDescription(PeerConnection::SdpType::OFFER, offer);

auto sdpAnswer = this->remoteSdp->GetSdp();
MSC_DEBUG("calling pc.setRemoteDescription() [answer:%s]", sdpAnswer.c_str());
this->pc->SetRemoteDescription(PeerConnection::SdpType::ANSWER, sdpAnswer);
}

/* RecvHandler methods */

RecvHandler::RecvHandler(
Expand Down
4 changes: 4 additions & 0 deletions src/Producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ namespace mediasoupclient
}

this->track->set_enabled(false);

this->privateListener->OnPause(this);
}

/**
Expand All @@ -148,6 +150,8 @@ namespace mediasoupclient
}

this->track->set_enabled(true);

this->privateListener->OnResume(this);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,20 @@ namespace mediasoupclient
return this->sendHandler->GetSenderStats(producer->GetLocalId());
}

void SendTransport::OnPause(Producer* producer)
{
MSC_TRACE();
Comment thread
tdrz marked this conversation as resolved.

this->sendHandler->PauseSending(producer->GetLocalId());
}

void SendTransport::OnResume(Producer* producer)
{
MSC_TRACE();

this->sendHandler->ResumeSending(producer->GetLocalId());
}

/* RecvTransport */

RecvTransport::RecvTransport(
Expand Down