提交 1a69e855 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Fix video not shown at Consumer start (fixes #288)

上级 26602ac3
......@@ -24,6 +24,7 @@ namespace RTC
class Listener
{
public:
virtual void OnConsumerNeedBandwidth(RTC::Consumer* consumer) = 0;
virtual void OnConsumerSendRtpPacket(RTC::Consumer* consumer, RTC::RtpPacket* packet) = 0;
virtual void OnConsumerRetransmitRtpPacket(RTC::Consumer* consumer, RTC::RtpPacket* packet) = 0;
virtual void OnConsumerKeyFrameRequested(RTC::Consumer* consumer, uint32_t mappedSsrc) = 0;
......@@ -51,7 +52,7 @@ namespace RTC
bool IsActive() const;
bool IsPaused() const;
bool IsProducerPaused() const;
virtual void UseBandwidth(uint32_t availableBandwidth) = 0;
virtual uint32_t UseBandwidth(uint32_t availableBandwidth) = 0;
void ProducerPaused();
void ProducerResumed();
virtual void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) = 0;
......@@ -68,8 +69,8 @@ namespace RTC
virtual float GetLossPercentage() const = 0;
protected:
virtual void Paused(bool wasProducer) = 0;
virtual void Resumed(bool wasProducer) = 0;
virtual void Paused() = 0;
virtual void Resumed() = 0;
public:
// Passed by argument.
......
......@@ -17,7 +17,7 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override;
void UseBandwidth(uint32_t availableBandwidth) override;
uint32_t UseBandwidth(uint32_t availableBandwidth) override;
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score) override;
......@@ -31,8 +31,8 @@ namespace RTC
float GetLossPercentage() const override;
private:
void Paused(bool wasProducer) override;
void Resumed(bool wasProducer) override;
void Paused() override;
void Resumed() override;
void CreateRtpStreams();
void RequestKeyFrame();
......
......@@ -40,6 +40,9 @@ namespace RTC
void UserOnNewConsumer(RTC::Consumer* consumer) override;
void UserOnRembFeedback(RTC::RTCP::FeedbackPsRembPacket* remb) override;
public:
void OnConsumerNeedBandwidth(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from RTC::UdpSocket::Listener. */
public:
void OnPacketRecv(
......
......@@ -40,6 +40,9 @@ namespace RTC
void UserOnNewConsumer(RTC::Consumer* consumer) override;
void UserOnRembFeedback(RTC::RTCP::FeedbackPsRembPacket* remb) override;
public:
void OnConsumerNeedBandwidth(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from RTC::UdpSocket::Listener. */
public:
void OnPacketRecv(
......
#ifndef MS_RTC_SIMPLE_CONSUMER_HPP
#define MS_RTC_SIMPLE_CONSUMER_HPP
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/Consumer.hpp"
#include "RTC/RtpStreamSend.hpp"
#include "RTC/SeqManager.hpp"
......@@ -19,7 +18,7 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override;
void UseBandwidth(uint32_t availableBandwidth) override;
uint32_t UseBandwidth(uint32_t availableBandwidth) override;
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score) override;
......@@ -33,8 +32,8 @@ namespace RTC
float GetLossPercentage() const override;
private:
void Paused(bool wasProducer) override;
void Resumed(bool wasProducer) override;
void Paused() override;
void Resumed() override;
void CreateRtpStream();
void RequestKeyFrame();
void EmitScore() const;
......@@ -52,7 +51,6 @@ namespace RTC
bool syncRequired{ true };
RTC::SeqManager<uint16_t> rtpSeqManager;
RTC::SeqManager<uint32_t> rtpTimestampManager;
std::unique_ptr<RTC::Codecs::EncodingContext> encodingContext;
RTC::RtpStream* producerRtpStream{ nullptr };
};
} // namespace RTC
......
......@@ -19,7 +19,7 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override;
void UseBandwidth(uint32_t availableBandwidth) override;
uint32_t UseBandwidth(uint32_t availableBandwidth) override;
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score) override;
......@@ -33,8 +33,8 @@ namespace RTC
float GetLossPercentage() const override;
private:
void Paused(bool wasProducer) override;
void Resumed(bool wasProducer) override;
void Paused() override;
void Resumed() override;
void CreateRtpStream();
void RequestKeyFrame();
void RetransmitRtpPacket(RTC::RtpPacket* packet);
......
......@@ -60,6 +60,9 @@ namespace RTC
void UserOnNewConsumer(RTC::Consumer* consumer) override;
void UserOnRembFeedback(RTC::RTCP::FeedbackPsRembPacket* remb) override;
public:
void OnConsumerNeedBandwidth(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from RTC::UdpSocket::Listener. */
public:
void OnPacketRecv(
......
......@@ -219,7 +219,7 @@ namespace RTC
MS_DEBUG_DEV("Consumer paused [consumerId:%s]", this->id.c_str());
if (wasActive)
Paused(false);
Paused();
request->Accept();
......@@ -240,7 +240,7 @@ namespace RTC
MS_DEBUG_DEV("Consumer resumed [consumerId:%s]", this->id.c_str());
if (IsActive())
Resumed(false);
Resumed();
request->Accept();
......@@ -268,7 +268,7 @@ namespace RTC
MS_DEBUG_DEV("Producer paused [consumerId:%s]", this->id.c_str());
if (wasActive)
Paused(true);
Paused();
Channel::Notifier::Emit(this->id, "producerpause");
}
......@@ -285,7 +285,7 @@ namespace RTC
MS_DEBUG_DEV("Producer resumed [consumerId:%s]", this->id.c_str());
if (IsActive())
Resumed(true);
Resumed();
Channel::Notifier::Emit(this->id, "producerresume");
}
......
......@@ -80,11 +80,14 @@ namespace RTC
}
}
void PipeConsumer::UseBandwidth(uint32_t availableBandwidth)
uint32_t PipeConsumer::UseBandwidth(uint32_t availableBandwidth)
{
MS_TRACE();
RequestKeyFrame();
// TODO.
return 0;
}
void PipeConsumer::ProducerRtpStream(RTC::RtpStream* /*rtpStream*/, uint32_t /*mappedSsrc*/)
......@@ -188,8 +191,6 @@ namespace RTC
{
MS_TRACE();
// TODO: Must call the corresponding rtpStream->ReceiveKeyFrameRequest(messageType);
RequestKeyFrame();
}
......@@ -235,7 +236,7 @@ namespace RTC
return 0u;
}
void PipeConsumer::Paused(bool /*wasProducer*/)
void PipeConsumer::Paused()
{
MS_TRACE();
......@@ -247,7 +248,7 @@ namespace RTC
}
}
void PipeConsumer::Resumed(bool wasProducer)
void PipeConsumer::Resumed()
{
MS_TRACE();
......@@ -258,10 +259,9 @@ namespace RTC
rtpStream->Resume();
}
// If we have been resumed due to the Producer becoming resumed, we don't
// need to request a key frame since the Producer already requested it.
if (!wasProducer)
RequestKeyFrame();
// We need to ask the Transport for bandwidth.
if (IsActive())
this->listener->OnConsumerNeedBandwidth(this);
}
void PipeConsumer::CreateRtpStreams()
......
......@@ -420,6 +420,19 @@ namespace RTC
// TODO
}
inline void PipeTransport::OnConsumerNeedBandwidth(RTC::Consumer* consumer)
{
MS_TRACE();
// Ignore if not connected.
if (!IsConnected())
return;
// TODO: Here we must check the available sending BWE and so on.
consumer->UseBandwidth(0);
}
inline void PipeTransport::OnPacketRecv(
RTC::UdpSocket* socket, const uint8_t* data, size_t len, const struct sockaddr* remoteAddr)
{
......
......@@ -692,6 +692,19 @@ namespace RTC
// TODO
}
inline void PlainRtpTransport::OnConsumerNeedBandwidth(RTC::Consumer* consumer)
{
MS_TRACE();
// Ignore if not connected.
if (!IsConnected())
return;
// TODO: Here we must check the available sending BWE and so on.
consumer->UseBandwidth(0);
}
inline void PlainRtpTransport::OnPacketRecv(
RTC::UdpSocket* socket, const uint8_t* data, size_t len, const struct sockaddr* remoteAddr)
{
......
......@@ -99,11 +99,14 @@ namespace RTC
}
}
void SimpleConsumer::UseBandwidth(uint32_t availableBandwidth)
uint32_t SimpleConsumer::UseBandwidth(uint32_t availableBandwidth)
{
MS_TRACE();
RequestKeyFrame();
// TODO.
return 0;
}
void SimpleConsumer::ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t /*mappedSsrc*/)
......@@ -122,6 +125,13 @@ namespace RTC
this->producerRtpStream = rtpStream;
if (IsActive())
{
// Since the Producer RtpStream has been created right now, we need to ask
// the Transport for bandwidth.
this->listener->OnConsumerNeedBandwidth(this);
}
// Emit the score event.
EmitScore();
}
......@@ -180,24 +190,9 @@ namespace RTC
this->rtpTimestampManager.Offset(diffTs);
}
if (this->encodingContext)
this->encodingContext->SyncRequired();
this->syncRequired = false;
}
// TODO: Not sure how to deal with it, but if this happens (and we drop the packet)
// we shouldn't have unset the syncRequired flag, etc.
//
// Rewrite payload if needed. Drop packet if necessary.
if (this->encodingContext && !packet->EncodePayload(this->encodingContext.get()))
{
this->rtpSeqManager.Drop(packet->GetSequenceNumber());
this->rtpTimestampManager.Drop(packet->GetTimestamp());
return;
}
// Update RTP seq number and timestamp.
uint16_t seq;
uint32_t timestamp;
......@@ -251,10 +246,6 @@ namespace RTC
packet->SetSsrc(origSsrc);
packet->SetSequenceNumber(origSeq);
packet->SetTimestamp(origTimestamp);
// Restore the original payload if needed.
if (this->encodingContext)
packet->RestorePayload();
}
void SimpleConsumer::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now)
......@@ -347,14 +338,14 @@ namespace RTC
}
}
void SimpleConsumer::Paused(bool /*wasProducer*/)
void SimpleConsumer::Paused()
{
MS_TRACE();
this->rtpStream->Pause();
}
void SimpleConsumer::Resumed(bool wasProducer)
void SimpleConsumer::Resumed()
{
MS_TRACE();
......@@ -364,10 +355,9 @@ namespace RTC
// receiver will request lot of NACKs due to unknown RTP packets.
this->syncRequired = true;
// If we have been resumed due to the Producer becoming resumed, we don't
// need to request a key frame since the Producer already requested it.
if (!wasProducer)
RequestKeyFrame();
// We need to ask the Transport for bandwidth.
if (IsActive() && this->producerRtpStream)
this->listener->OnConsumerNeedBandwidth(this);
}
void SimpleConsumer::CreateRtpStream()
......@@ -447,8 +437,6 @@ namespace RTC
this->rtpStream->SetRtx(rtxCodec->payloadType, encoding.rtx.ssrc);
this->keyFrameSupported = Codecs::CanBeKeyFrame(mediaCodec->mimeType);
this->encodingContext.reset(RTC::Codecs::GetEncodingContext(mediaCodec->mimeType));
}
void SimpleConsumer::RequestKeyFrame()
......
......@@ -179,7 +179,7 @@ namespace RTC
this->id.c_str());
if (IsActive())
RecalculateTargetSpatialLayer();
this->listener->OnConsumerNeedBandwidth(this);
request->Accept();
......@@ -194,12 +194,19 @@ namespace RTC
}
}
void SimulcastConsumer::UseBandwidth(uint32_t availableBandwidth)
uint32_t SimulcastConsumer::UseBandwidth(uint32_t availableBandwidth)
{
MS_TRACE();
if (IsActive())
{
// TODO: Here we should be able to use the best layer we can.
RecalculateTargetSpatialLayer();
}
// TODO.
return 0;
}
void SimulcastConsumer::ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc)
......@@ -230,9 +237,27 @@ namespace RTC
this->producerRtpStreams[spatialLayer] = rtpStream;
// Recalculate layers.
if (IsActive())
// If the Consumer is active and this is the first Producer RtpStream, we
// need to ask for bandwidth.
//
// clang-format off
if (
IsActive() &&
std::none_of(
this->producerRtpStreams.begin(), this->producerRtpStreams.end(), [](const RTC::RtpStream* rtpStream)
{
return rtpStream != nullptr;
})
)
// clang-format on
{
this->listener->OnConsumerNeedBandwidth(this);
}
// TODO: We should never upgrade layers by ourselves.
else if (IsActive())
{
RecalculateTargetSpatialLayer();
}
// Emit the score event.
EmitScore();
......@@ -242,7 +267,7 @@ namespace RTC
{
MS_TRACE();
// Recalculate layers.
// TODO: NO, we just can downgrade layers.
if (IsActive())
RecalculateTargetSpatialLayer();
......@@ -487,7 +512,7 @@ namespace RTC
}
}
void SimulcastConsumer::Paused(bool /*wasProducer*/)
void SimulcastConsumer::Paused()
{
MS_TRACE();
......@@ -498,7 +523,7 @@ namespace RTC
this->currentSpatialLayer = -1;
}
void SimulcastConsumer::Resumed(bool wasProducer)
void SimulcastConsumer::Resumed()
{
MS_TRACE();
......@@ -508,8 +533,9 @@ namespace RTC
// receiver will request lot of NACKs due to unknown RTP packets.
this->syncRequired = true;
// We need to ask the Transport for bandwidth.
if (IsActive())
RecalculateTargetSpatialLayer();
this->listener->OnConsumerNeedBandwidth(this);
}
void SimulcastConsumer::CreateRtpStream()
......@@ -786,6 +812,12 @@ namespace RTC
}
}
MS_DEBUG_TAG(
simulcast,
"newTargetSpatialLayer is %" PRIi16 " [consumerId:%s]",
newTargetSpatialLayer,
this->id.c_str());
if (newTargetSpatialLayer == -1)
{
MS_DEBUG_TAG(simulcast, "newTargetSpatialLayer remains unset");
......@@ -838,6 +870,7 @@ namespace RTC
{
MS_TRACE();
// TODO: NO, we just can downgrade layers.
if (IsActive())
RecalculateTargetSpatialLayer();
......
......@@ -901,7 +901,11 @@ namespace RTC
MS_TRACE();
if (!IsConnected())
{
MS_WARN_TAG(rtcp, "ignoring key rame request (transport not connected)");
return;
}
this->listener->OnTransportConsumerKeyFrameRequested(this, consumer, mappedSsrc);
}
......
......@@ -1151,6 +1151,19 @@ namespace RTC
this->rembClient->ReceiveRembFeedback(remb);
}
inline void WebRtcTransport::OnConsumerNeedBandwidth(RTC::Consumer* consumer)
{
MS_TRACE();
// Ignore if not connected.
if (!IsConnected())
return;
// TODO: Here we must check the available sending BWE and so on.
consumer->UseBandwidth(0);
}
inline void WebRtcTransport::OnPacketRecv(
RTC::UdpSocket* socket, const uint8_t* data, size_t len, const struct sockaddr* remoteAddr)
{
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论