Unverified 提交 bfbb839c authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Producer improvements (related to issue #235) (#238)

* - Producer.cpp: Remove UpdateRtpParameters(). It was broken since Consumers
  were not notified about profile removed and so on, so they may crash.
- Producer.cpp: Remove some maps and simplify streams handling by having a
  single mapSsrcRtpStreamInfo. Just keep mapActiveProfiles because
  GetActiveProfiles() method needs it.
- Producer::MayNeedNewStream(): Ignore new media streams with new SSRC if
  its RID is already in use by other media stream (should fix #235).
上级 b78b3682
......@@ -580,19 +580,6 @@ class Peer extends EnhancedEventEmitter
break;
}
case 'updateProducer':
{
const { id, rtpParameters } = notification;
const producer = this._producers.get(id);
if (!producer)
throw new Error('Producer not found');
producer.updateRtpParameters(rtpParameters);
break;
}
case 'pauseProducer':
{
const { id, appData } = notification;
......
......@@ -473,37 +473,6 @@ class Producer extends EnhancedEventEmitter
});
}
/**
* Change receiving RTP parameters.
*
* @private
*
* @param {RTCRtpParameters} rtpParameters - New RTP parameters.
*
* @return {Promise}
*/
updateRtpParameters(rtpParameters)
{
logger.debug('updateRtpParameters()');
if (this._closed)
return Promise.reject(new errors.InvalidStateError('Producer closed'));
return this._channel.request(
'producer.updateRtpParameters', this._internal, { rtpParameters })
.then(() =>
{
logger.debug('"producer.updateRtpParameters" request succeeded');
this._data.rtpParameters = rtpParameters;
})
.catch((error) =>
{
logger.error(
'"producer.updateRtpParameters" request failed: %s', String(error));
});
}
/**
* Get the Producer stats.
*
......
......@@ -39,7 +39,6 @@ namespace Channel
PRODUCER_CLOSE,
PRODUCER_DUMP,
PRODUCER_GET_STATS,
PRODUCER_UPDATE_RTP_PARAMETERS,
PRODUCER_PAUSE,
PRODUCER_RESUME,
PRODUCER_SET_PREFERRED_PROFILE,
......
......@@ -51,7 +51,6 @@ namespace RTC
void SourceResume();
void AddProfile(const RTC::RtpEncodingParameters::Profile profile, const RTC::RtpStream* rtpStream);
void RemoveProfile(const RTC::RtpEncodingParameters::Profile profile);
void SourceRtpParametersUpdated();
void SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile);
void SetSourcePreferredProfile(const RTC::RtpEncodingParameters::Profile profile);
void SetEncodingPreferences(const RTC::Codecs::EncodingContext::Preferences preferences);
......
......@@ -14,7 +14,6 @@
#include "handles/Timer.hpp"
#include <json/json.h>
#include <map>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>
......@@ -39,6 +38,16 @@ namespace RTC
uint8_t rid{ 0 }; // 0 means no RID id.
};
private:
struct RtpStreamInfo
{
RTC::RtpStreamRecv* rtpStream{ nullptr };
std::string rid{};
RTC::RtpEncodingParameters::Profile profile{ RTC::RtpEncodingParameters::Profile::NONE };
uint32_t rtxSsrc{ 0 };
bool active{ false };
};
public:
Producer(
Channel::Notifier* notifier,
......@@ -59,7 +68,6 @@ namespace RTC
Json::Value GetStats() const;
void AddListener(RTC::ProducerListener* listener);
void RemoveListener(RTC::ProducerListener* listener);
void UpdateRtpParameters(RTC::RtpParameters& rtpParameters);
void Pause();
void Resume();
void SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile);
......@@ -79,12 +87,10 @@ namespace RTC
void FillHeaderExtensionIds();
void MayNeedNewStream(RTC::RtpPacket* packet);
void CreateRtpStream(RTC::RtpEncodingParameters& encoding, uint32_t ssrc);
void ClearRtpStream(RTC::RtpStreamRecv* rtpStream);
void ClearRtpStreams();
void ApplyRtpMapping(RTC::RtpPacket* packet) const;
RTC::RtpEncodingParameters::Profile GetProfile(RTC::RtpStreamRecv* rtpStream, RTC::RtpPacket* packet);
void ActivateStreamProfiles(RTC::RtpStreamRecv* rtpStream);
void DeactivateStreamProfiles(RTC::RtpStreamRecv* rtpStream);
void ActivateStream(RTC::RtpStreamRecv* rtpStream);
void DeactivateStream(RTC::RtpStreamRecv* rtpStream);
// TODO: Remove?
bool IsStreamActive(const RTC::RtpStream* rtpStream) const;
/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
......@@ -112,9 +118,7 @@ namespace RTC
struct RtpMapping rtpMapping;
std::unordered_set<RTC::ProducerListener*> listeners;
// Allocated by this.
std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams;
std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams;
std::map<RTC::RtpStreamRecv*, std::set<RTC::RtpEncodingParameters::Profile>> mapRtpStreamProfiles;
std::map<uint32_t, RtpStreamInfo> mapSsrcRtpStreamInfo;
std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*> mapActiveProfiles;
Timer* keyFrameRequestBlockTimer{ nullptr };
// Others.
......@@ -169,11 +173,11 @@ namespace RTC
inline void Producer::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report)
{
auto it = this->rtpStreams.find(report->GetSsrc());
if (it != this->rtpStreams.end())
auto it = this->mapSsrcRtpStreamInfo.find(report->GetSsrc());
if (it != this->mapSsrcRtpStreamInfo.end())
{
auto rtpStream = it->second;
auto& info = it->second;
auto* rtpStream = info.rtpStream;
rtpStream->ReceiveRtcpSenderReport(report);
}
......
......@@ -13,10 +13,9 @@ namespace RTC
class ProducerListener
{
public:
virtual void OnProducerClosed(RTC::Producer* producer) = 0;
virtual void OnProducerRtpParametersUpdated(RTC::Producer* producer) = 0;
virtual void OnProducerPaused(RTC::Producer* producer) = 0;
virtual void OnProducerResumed(RTC::Producer* producer) = 0;
virtual void OnProducerClosed(RTC::Producer* producer) = 0;
virtual void OnProducerPaused(RTC::Producer* producer) = 0;
virtual void OnProducerResumed(RTC::Producer* producer) = 0;
virtual void OnProducerRtpPacket(
RTC::Producer* producer, RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile) = 0;
virtual void OnProducerProfileEnabled(
......
......@@ -64,7 +64,6 @@ namespace RTC
/* Pure virtual methods inherited from RTC::ProducerListener. */
public:
void OnProducerClosed(RTC::Producer* producer) override;
void OnProducerRtpParametersUpdated(RTC::Producer* producer) override;
void OnProducerPaused(RTC::Producer* producer) override;
void OnProducerResumed(RTC::Producer* producer) override;
void OnProducerRtpPacket(
......
......@@ -97,7 +97,6 @@ namespace RTC
/* Pure virtual methods inherited from RTC::ProducerListener. */
public:
void OnProducerClosed(RTC::Producer* producer) override;
void OnProducerRtpParametersUpdated(RTC::Producer* producer) override;
void OnProducerPaused(RTC::Producer* producer) override;
void OnProducerResumed(RTC::Producer* producer) override;
void OnProducerRtpPacket(
......
......@@ -34,7 +34,6 @@ namespace Channel
{ "producer.close", Request::MethodId::PRODUCER_CLOSE },
{ "producer.dump", Request::MethodId::PRODUCER_DUMP },
{ "producer.getStats", Request::MethodId::PRODUCER_GET_STATS },
{ "producer.updateRtpParameters", Request::MethodId::PRODUCER_UPDATE_RTP_PARAMETERS },
{ "producer.pause", Request::MethodId::PRODUCER_PAUSE },
{ "producer.resume" , Request::MethodId::PRODUCER_RESUME },
{ "producer.setPreferredProfile", Request::MethodId::PRODUCER_SET_PREFERRED_PROFILE },
......
......@@ -256,16 +256,6 @@ namespace RTC
}
}
void Consumer::SourceRtpParametersUpdated()
{
MS_TRACE();
if (!IsEnabled())
return;
this->syncRequired = true;
}
void Consumer::AddProfile(
const RTC::RtpEncodingParameters::Profile profile, const RTC::RtpStream* rtpStream)
{
......
......@@ -1052,52 +1052,6 @@ namespace RTC
break;
}
case Channel::Request::MethodId::PRODUCER_UPDATE_RTP_PARAMETERS:
{
static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" };
RTC::Producer* producer;
try
{
producer = GetProducerFromRequest(request);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (!request->data[JsonStringRtpParameters].isObject())
{
request->Reject("missing data.rtpParameters");
return;
}
RTC::RtpParameters rtpParameters;
try
{
// NOTE: This may throw.
rtpParameters = RTC::RtpParameters(request->data[JsonStringRtpParameters]);
// NOTE: This may throw.
producer->UpdateRtpParameters(rtpParameters);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
request->Accept();
break;
}
case Channel::Request::MethodId::PRODUCER_PAUSE:
{
RTC::Producer* producer;
......@@ -1692,20 +1646,6 @@ namespace RTC
this->mapProducerAudioLevelContainer.erase(producer);
}
void Router::OnProducerRtpParametersUpdated(RTC::Producer* producer)
{
MS_ASSERT(
this->mapProducerConsumers.find(producer) != this->mapProducerConsumers.end(),
"Producer not present in mapProducerConsumers");
auto& consumers = this->mapProducerConsumers[producer];
for (auto* consumer : consumers)
{
consumer->SourceRtpParametersUpdated();
}
}
void Router::OnProducerPaused(RTC::Producer* producer)
{
MS_TRACE();
......
......@@ -524,15 +524,6 @@ namespace RTC
this->rtpListener.RemoveProducer(producer);
}
void Transport::OnProducerRtpParametersUpdated(RTC::Producer* producer)
{
MS_TRACE();
// Update our RtpListener.
// NOTE: This may throw.
this->rtpListener.AddProducer(producer);
}
void Transport::OnProducerPaused(RTC::Producer* /*producer*/)
{
// Do nothing.
......
......@@ -255,7 +255,6 @@ void Worker::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::R
case Channel::Request::MethodId::PRODUCER_CLOSE:
case Channel::Request::MethodId::PRODUCER_DUMP:
case Channel::Request::MethodId::PRODUCER_GET_STATS:
case Channel::Request::MethodId::PRODUCER_UPDATE_RTP_PARAMETERS:
case Channel::Request::MethodId::PRODUCER_PAUSE:
case Channel::Request::MethodId::PRODUCER_RESUME:
case Channel::Request::MethodId::PRODUCER_SET_PREFERRED_PROFILE:
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论