Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/producer transceiver inactive on pause #176

Open
wants to merge 12 commits into
base: v3
Choose a base branch
from
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;
copiltembel marked this conversation as resolved.
Show resolved Hide resolved
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
44 changes: 44 additions & 0 deletions src/Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,50 @@ 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
10 changes: 10 additions & 0 deletions src/Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,16 @@ namespace mediasoupclient
return this->sendHandler->GetSenderStats(producer->GetLocalId());
}

void SendTransport::OnPause(Producer* producer) {
MSC_TRACE();
copiltembel marked this conversation as resolved.
Show resolved Hide resolved
this->sendHandler->PauseSending(producer->GetLocalId());
}

void SendTransport::OnResume(Producer* producer) {
MSC_TRACE();
this->sendHandler->ResumeSending(producer->GetLocalId());
}

/* RecvTransport */

RecvTransport::RecvTransport(
Expand Down