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

BWE WIP

上级 882c21ee
......@@ -112,7 +112,7 @@ Generates the `worker/compile_commands_template.json` file which is a ["Clang co
It requires [jq](https://stedolan.github.io/jq/) command-line JSON processor. Install it in Debian/Ubuntu via `apt install jq` and in OSX via `brew install jq`.
**NOTE:** Before running `make bear` you must have mediasoup C/C++ dependencies already compiled. To be sure, run `make clean && make` before running `make bear`.
**NOTE:** Before running `make bear` you must have mediasoup C/C++ dependencies already compiled. To be sure, run `make clean-all && make` before running `make bear`.
### `make tidy`
......
......@@ -84,6 +84,11 @@
"directory": "PATH/out",
"file": "PATH/src/Channel/UnixStreamSocket.cpp"
},
{
"command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_INT16_T -DHAVE_INT32_T -DHAVE_INT8_T -DHAVE_UINT16_T -DHAVE_UINT32_T -DHAVE_UINT64_T -DHAVE_UINT8_T -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -DCPU_CISC -IPATH/include -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -std=c++11 -Wall -Wextra -Wno-unused-parameter -m64 -g -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/AudioLevelObserver.o PATH/src/RTC/AudioLevelObserver.cpp",
"directory": "PATH/out",
"file": "PATH/src/RTC/AudioLevelObserver.cpp"
},
{
"command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_INT16_T -DHAVE_INT32_T -DHAVE_INT8_T -DHAVE_UINT16_T -DHAVE_UINT32_T -DHAVE_UINT64_T -DHAVE_UINT8_T -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -DCPU_CISC -IPATH/include -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -std=c++11 -Wall -Wextra -Wno-unused-parameter -m64 -g -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/Consumer.o PATH/src/RTC/Consumer.cpp",
"directory": "PATH/out",
......@@ -114,6 +119,16 @@
"directory": "PATH/out",
"file": "PATH/src/RTC/NackGenerator.cpp"
},
{
"command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_INT16_T -DHAVE_INT32_T -DHAVE_INT8_T -DHAVE_UINT16_T -DHAVE_UINT32_T -DHAVE_UINT64_T -DHAVE_UINT8_T -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -DCPU_CISC -IPATH/include -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -std=c++11 -Wall -Wextra -Wno-unused-parameter -m64 -g -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/PipeConsumer.o PATH/src/RTC/PipeConsumer.cpp",
"directory": "PATH/out",
"file": "PATH/src/RTC/PipeConsumer.cpp"
},
{
"command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_INT16_T -DHAVE_INT32_T -DHAVE_INT8_T -DHAVE_UINT16_T -DHAVE_UINT32_T -DHAVE_UINT64_T -DHAVE_UINT8_T -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -DCPU_CISC -IPATH/include -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -std=c++11 -Wall -Wextra -Wno-unused-parameter -m64 -g -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/PipeTransport.o PATH/src/RTC/PipeTransport.cpp",
"directory": "PATH/out",
"file": "PATH/src/RTC/PipeTransport.cpp"
},
{
"command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_INT16_T -DHAVE_INT32_T -DHAVE_INT8_T -DHAVE_UINT16_T -DHAVE_UINT32_T -DHAVE_UINT64_T -DHAVE_UINT8_T -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -DCPU_CISC -IPATH/include -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -std=c++11 -Wall -Wextra -Wno-unused-parameter -m64 -g -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/PlainRtpTransport.o PATH/src/RTC/PlainRtpTransport.cpp",
"directory": "PATH/out",
......@@ -139,6 +154,11 @@
"directory": "PATH/out",
"file": "PATH/src/RTC/RtpListener.cpp"
},
{
"command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_INT16_T -DHAVE_INT32_T -DHAVE_INT8_T -DHAVE_UINT16_T -DHAVE_UINT32_T -DHAVE_UINT64_T -DHAVE_UINT8_T -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -DCPU_CISC -IPATH/include -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -std=c++11 -Wall -Wextra -Wno-unused-parameter -m64 -g -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/RtpObserver.o PATH/src/RTC/RtpObserver.cpp",
"directory": "PATH/out",
"file": "PATH/src/RTC/RtpObserver.cpp"
},
{
"command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_INT16_T -DHAVE_INT32_T -DHAVE_INT8_T -DHAVE_UINT16_T -DHAVE_UINT32_T -DHAVE_UINT64_T -DHAVE_UINT8_T -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -DCPU_CISC -IPATH/include -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -std=c++11 -Wall -Wextra -Wno-unused-parameter -m64 -g -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/RtpPacket.o PATH/src/RTC/RtpPacket.cpp",
"directory": "PATH/out",
......
......@@ -12,7 +12,6 @@
#include "RTC/RtpHeaderExtensionIds.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpStream.hpp"
#include <limits>
#include <string>
#include <unordered_set>
#include <vector>
......@@ -28,7 +27,7 @@ namespace RTC
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;
virtual void OnConsumerNeedBitrate(RTC::Consumer* consumer) = 0;
virtual void OnConsumerNeedBitrateChange(RTC::Consumer* consumer) = 0;
virtual void onConsumerProducerClosed(RTC::Consumer* consumer) = 0;
};
......@@ -50,10 +49,11 @@ namespace RTC
const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const;
RTC::RtpParameters::Type GetType() const;
const std::vector<uint32_t>& GetMediaSsrcs() const;
bool IsActive() const;
virtual bool IsActive() const;
void TransportConnected();
void TransportDisconnected();
bool IsPaused() const;
bool IsProducerPaused() const;
virtual uint32_t UseBitrate(uint32_t availableBitrate = std::numeric_limits<uint32_t>::max()) = 0;
void ProducerPaused();
void ProducerResumed();
virtual void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) = 0;
......@@ -69,9 +69,11 @@ namespace RTC
virtual uint32_t GetTransmissionRate(uint64_t now) = 0;
virtual float GetLossPercentage() const = 0;
protected:
virtual void Paused() = 0;
virtual void Resumed() = 0;
private:
virtual void UserOnTransportConnected() = 0;
virtual void UserOnTransportDisconnected() = 0;
virtual void UserOnPaused() = 0;
virtual void UserOnResumed() = 0;
public:
// Passed by argument.
......@@ -93,6 +95,7 @@ namespace RTC
private:
// Others.
std::vector<uint32_t> mediaSsrcs;
bool transportConnected{ false };
bool paused{ false };
bool producerPaused{ false };
bool producerClosed{ false };
......@@ -127,7 +130,10 @@ namespace RTC
inline bool Consumer::IsActive() const
{
return !this->paused && !this->producerPaused && !this->producerClosed;
// The parent Consumer just checks whether Consumer and Producer are
// not paused and the transport connected.
return (
this->transportConnected && !this->paused && !this->producerPaused && !this->producerClosed);
}
inline bool Consumer::IsPaused() const
......
......@@ -17,7 +17,6 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override;
uint32_t UseBitrate(uint32_t availableBitrate) 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 +30,10 @@ namespace RTC
float GetLossPercentage() const override;
private:
void Paused() override;
void Resumed() override;
void UserOnTransportConnected() override;
void UserOnTransportDisconnected() override;
void UserOnPaused() override;
void UserOnResumed() override;
void CreateRtpStreams();
void RequestKeyFrame();
......
......@@ -42,7 +42,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Consumer::Listener. */
public:
void OnConsumerNeedBitrate(RTC::Consumer* consumer) override;
void OnConsumerNeedBitrateChange(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from RTC::UdpSocket::Listener. */
public:
......
......@@ -42,7 +42,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Consumer::Listener. */
public:
void OnConsumerNeedBitrate(RTC::Consumer* consumer) override;
void OnConsumerNeedBitrateChange(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from RTC::UdpSocket::Listener. */
public:
......
......@@ -15,32 +15,28 @@ namespace RTC
class Listener
{
public:
virtual void OnRembClientAvailableBitrate(
RTC::RembClient* rembClient, uint32_t availableBitrate) = 0;
virtual void OnRembClientExceedingBitrate(
RTC::RembClient* rembClient, uint32_t exceedingBitrate) = 0;
virtual void OnRembClientIncreaseBitrate(RTC::RembClient* rembClient, uint32_t bitrate) = 0;
virtual void OnRembClientDecreaseBitrate(RTC::RembClient* rembClient, uint32_t bitrate) = 0;
};
public:
RembClient(RTC::RembClient::Listener* listener);
RembClient(RTC::RembClient::Listener* listener, uint32_t initialAvailableBitrate);
virtual ~RembClient();
public:
void ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRembFeedback(RTC::RTCP::FeedbackPsRembPacket* remb);
uint32_t GetAvailableBitrate();
void AddExtraBitrate(uint32_t extraBitrate);
void RemoveExtraBitrate(uint32_t extraBitrate);
private:
bool HasRecentData() const;
bool CheckStatus();
private:
Listener* listener;
RTC::RtpDataCounter transmissionCounter;
uint32_t initialAvailableBitrate{ 0 };
uint32_t availableBitrate{ 0 };
uint64_t lastEventAt{ 0 };
uint32_t rembBitrate{ 0 };
uint32_t availableBitrate{ std::numeric_limits<uint32_t>::max() };
};
} // namespace RTC
......
......@@ -18,7 +18,7 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override;
uint32_t UseBitrate(uint32_t availableBitrate) override;
bool IsActive() const 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;
......@@ -32,8 +32,10 @@ namespace RTC
float GetLossPercentage() const override;
private:
void Paused() override;
void Resumed() override;
void UserOnTransportConnected() override;
void UserOnTransportDisconnected() override;
void UserOnPaused() override;
void UserOnResumed() override;
void CreateRtpStream();
void RequestKeyFrame();
void EmitScore() const;
......@@ -48,11 +50,18 @@ namespace RTC
RTC::RtpStreamSend* rtpStream{ nullptr };
// Others.
bool keyFrameSupported{ false };
bool syncRequired{ true };
bool syncRequired{ false };
RTC::SeqManager<uint16_t> rtpSeqManager;
RTC::SeqManager<uint32_t> rtpTimestampManager;
RTC::RtpStream* producerRtpStream{ nullptr };
};
/* Inline methods. */
inline bool SimpleConsumer::IsActive() const
{
return (RTC::Consumer::IsActive() && this->producerRtpStream);
}
} // namespace RTC
#endif
......@@ -19,7 +19,7 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override;
uint32_t UseBitrate(uint32_t availableBitrate) override;
bool IsActive() const 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,10 @@ namespace RTC
float GetLossPercentage() const override;
private:
void Paused() override;
void Resumed() override;
void UserOnTransportConnected() override;
void UserOnTransportDisconnected() override;
void UserOnPaused() override;
void UserOnResumed() override;
void CreateRtpStream();
void RequestKeyFrame();
void RetransmitRtpPacket(RTC::RtpPacket* packet);
......@@ -56,7 +58,7 @@ namespace RTC
std::vector<RTC::RtpStream*> producerRtpStreams; // Indexed by spatial layer.
// Others.
bool keyFrameSupported{ false };
bool syncRequired{ true };
bool syncRequired{ false };
RTC::SeqManager<uint16_t> rtpSeqManager;
RTC::SeqManager<uint32_t> rtpTimestampManager;
std::unique_ptr<RTC::Codecs::EncodingContext> encodingContext;
......@@ -67,6 +69,22 @@ namespace RTC
int16_t currentSpatialLayer{ -1 };
int16_t currentTemporalLayer{ -1 };
};
/* Inline methods. */
inline bool SimulcastConsumer::IsActive() const
{
// clang-format off
return (
RTC::Consumer::IsActive() &&
std::any_of(
this->producerRtpStreams.begin(),
this->producerRtpStreams.end(),
[](const RTC::RtpStream* rtpStream) { return rtpStream != nullptr; }
)
);
// clang-format on
}
} // namespace RTC
#endif
......@@ -114,7 +114,7 @@ namespace RTC
void OnConsumerSendRtpPacket(RTC::Consumer* consumer, RTC::RtpPacket* packet) override;
void OnConsumerRetransmitRtpPacket(RTC::Consumer* consumer, RTC::RtpPacket* packet) override;
void OnConsumerKeyFrameRequested(RTC::Consumer* consumer, uint32_t mappedSsrc) override;
virtual void OnConsumerNeedBitrate(RTC::Consumer* consumer) override = 0;
virtual void OnConsumerNeedBitrateChange(RTC::Consumer* consumer) override = 0;
void onConsumerProducerClosed(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from Timer::Listener. */
......
......@@ -62,7 +62,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Consumer::Listener. */
public:
void OnConsumerNeedBitrate(RTC::Consumer* consumer) override;
void OnConsumerNeedBitrateChange(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from RTC::UdpSocket::Listener. */
public:
......@@ -107,8 +107,8 @@ namespace RTC
/* Pure virtual methods inherited from RTC::RembClient::Listener. */
public:
void OnRembClientAvailableBitrate(RTC::RembClient* rembClient, uint32_t availableBitrate) override;
void OnRembClientExceedingBitrate(RTC::RembClient* rembClient, uint32_t exceedingBitrate) override;
void OnRembClientIncreaseBitrate(RTC::RembClient* rembClient, uint32_t bitrate) override;
void OnRembClientDecreaseBitrate(RTC::RembClient* rembClient, uint32_t bitrate) override;
/* Pure virtual methods inherited from RTC::RembServer::RemoteBitrateEstimator::Listener. */
public:
......
......@@ -157,7 +157,7 @@ namespace RTC
// Clear the map.
ResetMapProducerDBovs();
if (mapDBovsProducer.size() > 0)
if (!mapDBovsProducer.empty())
{
this->silence = false;
......
......@@ -219,7 +219,7 @@ namespace RTC
MS_DEBUG_DEV("Consumer paused [consumerId:%s]", this->id.c_str());
if (wasActive)
Paused();
UserOnPaused();
request->Accept();
......@@ -240,7 +240,7 @@ namespace RTC
MS_DEBUG_DEV("Consumer resumed [consumerId:%s]", this->id.c_str());
if (IsActive())
Resumed();
UserOnResumed();
request->Accept();
......@@ -254,6 +254,28 @@ namespace RTC
}
}
void Consumer::TransportConnected()
{
MS_TRACE();
this->transportConnected = true;
MS_DEBUG_DEV("Transport connected [consumerId:%s]", this->id.c_str());
UserOnTransportConnected();
}
void Consumer::TransportDisconnected()
{
MS_TRACE();
this->transportConnected = false;
MS_DEBUG_DEV("Transport disconnected [consumerId:%s]", this->id.c_str());
UserOnTransportDisconnected();
}
void Consumer::ProducerPaused()
{
MS_TRACE();
......@@ -268,7 +290,7 @@ namespace RTC
MS_DEBUG_DEV("Producer paused [consumerId:%s]", this->id.c_str());
if (wasActive)
Paused();
UserOnPaused();
Channel::Notifier::Emit(this->id, "producerpause");
}
......@@ -285,7 +307,7 @@ namespace RTC
MS_DEBUG_DEV("Producer resumed [consumerId:%s]", this->id.c_str());
if (IsActive())
Resumed();
UserOnResumed();
Channel::Notifier::Emit(this->id, "producerresume");
}
......
......@@ -43,14 +43,14 @@ namespace RTC
RTC::Consumer::FillJson(jsonObject);
}
void PipeConsumer::FillJsonStats(json& jsonArray) const
void PipeConsumer::FillJsonStats(json& /*jsonArray*/) const
{
MS_TRACE();
// Do nothing.
}
void PipeConsumer::FillJsonScore(json& jsonObject) const
void PipeConsumer::FillJsonScore(json& /*jsonObject*/) const
{
MS_TRACE();
......@@ -65,7 +65,8 @@ namespace RTC
{
case Channel::Request::MethodId::CONSUMER_REQUEST_KEY_FRAME:
{
RequestKeyFrame();
if (IsActive())
RequestKeyFrame();
request->Accept();
......@@ -80,16 +81,6 @@ namespace RTC
}
}
uint32_t PipeConsumer::UseBitrate(uint32_t availableBitrate)
{
MS_TRACE();
RequestKeyFrame();
// TODO.
return 0;
}
void PipeConsumer::ProducerRtpStream(RTC::RtpStream* /*rtpStream*/, uint32_t /*mappedSsrc*/)
{
MS_TRACE();
......@@ -187,11 +178,12 @@ namespace RTC
// Do nothing since we do not enable NACK.
}
void PipeConsumer::ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType)
void PipeConsumer::ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType /*messageType*/)
{
MS_TRACE();
RequestKeyFrame();
if (IsActive())
RequestKeyFrame();
}
void PipeConsumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
......@@ -216,6 +208,9 @@ namespace RTC
{
MS_TRACE();
if (!IsActive())
return 0u;
uint32_t rate{ 0 };
for (auto& kv : this->mapMappedSsrcRtpStream)
......@@ -236,7 +231,24 @@ namespace RTC
return 0u;
}
void PipeConsumer::Paused()
void PipeConsumer::UserOnTransportConnected()
{
MS_TRACE();
if (IsActive())
{
for (auto& kv : this->mapMappedSsrcRtpStream)
{
auto& rtpStream = kv.second;
rtpStream->Resume();
}
RequestKeyFrame();
}
}
void PipeConsumer::UserOnTransportDisconnected()
{
MS_TRACE();
......@@ -248,7 +260,7 @@ namespace RTC
}
}
void PipeConsumer::Resumed()
void PipeConsumer::UserOnPaused()
{
MS_TRACE();
......@@ -256,12 +268,25 @@ namespace RTC
{
auto& rtpStream = kv.second;
rtpStream->Resume();
rtpStream->Pause();
}
}
void PipeConsumer::UserOnResumed()
{
MS_TRACE();
// We need to ask the Transport for bitrate.
if (IsActive())
this->listener->OnConsumerNeedBitrate(this);
{
for (auto& kv : this->mapMappedSsrcRtpStream)
{
auto& rtpStream = kv.second;
rtpStream->Resume();
}
RequestKeyFrame();
}
}
void PipeConsumer::CreateRtpStreams()
......@@ -352,7 +377,7 @@ namespace RTC
{
MS_TRACE();
if (!IsActive() || this->kind != RTC::Media::Kind::VIDEO)
if (this->kind != RTC::Media::Kind::VIDEO)
return;
for (auto& encoding : this->rtpParameters.encodings)
......
......@@ -236,15 +236,6 @@ namespace RTC
// and tell the parent class.
RTC::Transport::Connected();
// Tell all Consumers.
for (auto& kv : this->mapConsumers)
{
auto* consumer = kv.second;
if (consumer->IsActive())
consumer->UseBitrate();
}
break;
}
......@@ -415,14 +406,9 @@ namespace RTC
// Do nothing.
}
void PipeTransport::UserOnNewConsumer(RTC::Consumer* consumer)
void PipeTransport::UserOnNewConsumer(RTC::Consumer* /*consumer*/)
{
MS_TRACE();
// If the Transport is already connected and the Consumer is active, tell the
// new Consumer to use available bitrate.
if (IsConnected() && consumer->IsActive())
consumer->UseBitrate();
}
void PipeTransport::UserOnRembFeedback(RTC::RTCP::FeedbackPsRembPacket* /*remb*/)
......@@ -432,15 +418,11 @@ namespace RTC
// TODO
}
inline void PipeTransport::OnConsumerNeedBitrate(RTC::Consumer* consumer)
inline void PipeTransport::OnConsumerNeedBitrateChange(RTC::Consumer* /*consumer*/)
{
MS_TRACE();
// Ignore if not connected.
if (!IsConnected())
return;
consumer->UseBitrate();
// TODO
}
inline void PipeTransport::OnPacketRecv(
......
......@@ -413,15 +413,6 @@ namespace RTC
// and tell the parent class.
RTC::Transport::Connected();
// Tell all Consumers.
for (auto& kv : this->mapConsumers)
{
auto* consumer = kv.second;
if (consumer->IsActive())
consumer->UseBitrate();
}
break;
}
......@@ -687,14 +678,9 @@ namespace RTC
// Do nothing.
}
void PlainRtpTransport::UserOnNewConsumer(RTC::Consumer* consumer)
void PlainRtpTransport::UserOnNewConsumer(RTC::Consumer* /*consumer*/)
{
MS_TRACE();
// If the Transport is already connected and the Consumer is active, tell the
// new Consumer to use available bitrate.
if (IsConnected() && consumer->IsActive())
consumer->UseBitrate();
}
void PlainRtpTransport::UserOnRembFeedback(RTC::RTCP::FeedbackPsRembPacket* /*remb*/)
......@@ -704,15 +690,9 @@ namespace RTC
// TODO
}
inline void PlainRtpTransport::OnConsumerNeedBitrate(RTC::Consumer* consumer)
inline void PlainRtpTransport::OnConsumerNeedBitrateChange(RTC::Consumer* /*consumer*/)
{
MS_TRACE();
// Ignore if not connected.
if (!IsConnected())
return;
consumer->UseBitrate();
}
inline void PlainRtpTransport::OnPacketRecv(
......
......@@ -847,8 +847,6 @@ namespace RTC
static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL),
extenLen,
bufferPtr);
bufferPtr += extenLen;
}
}
}
......@@ -897,8 +895,6 @@ namespace RTC
extensions.emplace_back(
static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::ABS_SEND_TIME), extenLen, bufferPtr);
bufferPtr += extenLen;
}
}
......
......@@ -14,8 +14,9 @@ namespace RTC
/* Instance methods. */
RembClient::RembClient(RTC::RembClient::Listener* listener)
: listener(listener), lastEventAt(DepLibUV::GetTime())
RembClient::RembClient(RTC::RembClient::Listener* listener, uint32_t initialAvailableBitrate)
: listener(listener), initialAvailableBitrate(initialAvailableBitrate),
availableBitrate(initialAvailableBitrate)
{
MS_TRACE();
}
......@@ -36,25 +37,20 @@ namespace RTC
{
MS_TRACE();
// Check if we should fire the event.
MS_ERROR("remb:%" PRIu64, remb->GetBitrate());
uint64_t now = DepLibUV::GetTime();
if (!HasRecentData())
// If we don't have recent data yet, start from here.
if (!CheckStatus())
{
MS_DEBUG_DEV(bwe, "ignoring first REMB after inactivity");
// Update last event time.
this->lastEventAt = now;
// Set available bitrate to the maximum value.
this->availableBitrate = std::numeric_limits<uint32_t>::max();
// Update REMB bitrate.
this->rembBitrate = static_cast<uint32_t>(remb->GetBitrate());
return;
}
else if (now - this->lastEventAt < EventInterval)
// Otherwise ensure EventInterval has happened.
else if (this->lastEventAt != 0 && (now - this->lastEventAt) < EventInterval)
{
return;
}
......@@ -62,56 +58,52 @@ namespace RTC
// Update last event time.
this->lastEventAt = now;
uint32_t newRembBitrate = static_cast<uint32_t>(remb->GetBitrate());
int64_t rembTrend =
static_cast<int64_t>(newRembBitrate) - static_cast<int64_t>(this->rembBitrate);
uint32_t bitrateInUse = this->transmissionCounter.GetRate(now);
auto previousAvailableBitrate = this->availableBitrate;
// Update REMB bitrate.
this->rembBitrate = newRembBitrate;
// Update available bitrate.
this->availableBitrate = static_cast<uint32_t>(remb->GetBitrate());
if (this->rembBitrate >= bitrateInUse)
int64_t trend =
static_cast<int64_t>(this->availableBitrate) - static_cast<int64_t>(previousAvailableBitrate);
uint32_t usedBitrate = this->transmissionCounter.GetRate(now);
if (this->availableBitrate >= usedBitrate)
{
uint32_t availableBitrate = this->rembBitrate - bitrateInUse;
uint32_t usableBitrate = this->availableBitrate - usedBitrate;
MS_DEBUG_TAG(
bwe,
"available bitrate [REMB:%" PRIu32 " >= bitrateInUse:%" PRIu32 ", availableBitrate:%" PRIu32
"]",
this->rembBitrate,
bitrateInUse,
availableBitrate);
this->availableBitrate = availableBitrate;
"usable bitrate [availableBitrate:%" PRIu32 " >= usedBitrate:%" PRIu32
", usableBitrate:%" PRIu32 "]",
this->availableBitrate,
usedBitrate,
usableBitrate);
this->listener->OnRembClientAvailableBitrate(this, availableBitrate);
this->listener->OnRembClientIncreaseBitrate(this, usableBitrate);
}
else if (rembTrend > 0)
else if (trend > 0)
{
MS_DEBUG_TAG(
bwe,
"positive REMB trend [REMB:%" PRIu32 " < bitrateInUse:%" PRIu32 ", trend:%" PRIi64 "]",
this->rembBitrate,
bitrateInUse,
rembTrend);
this->availableBitrate = 0;
"positive REMB trend [availableBitrate:%" PRIu32 " < usedBitrate:%" PRIu32
", trend:%" PRIi64 "]",
this->availableBitrate,
usedBitrate,
trend);
}
else
{
uint32_t exceedingBitrate = bitrateInUse - this->rembBitrate;
uint32_t exceedingBitrate = usedBitrate - this->availableBitrate;
MS_WARN_TAG(
bwe,
"exceeding bitrate [REMB:%" PRIu32 " < bitrateInUse:%" PRIu32 ", exceedingBitrate:%" PRIu32
"]",
this->rembBitrate,
bitrateInUse,
"exceeding bitrate [availableBitrate:%" PRIu32 " < usedBitrate:%" PRIu32
", exceedingBitrate:%" PRIu32 "]",
this->availableBitrate,
usedBitrate,
exceedingBitrate);
this->availableBitrate = 0;
this->listener->OnRembClientExceedingBitrate(this, exceedingBitrate);
this->listener->OnRembClientDecreaseBitrate(this, exceedingBitrate);
}
}
......@@ -119,49 +111,26 @@ namespace RTC
{
MS_TRACE();
if (!HasRecentData())
this->availableBitrate = std::numeric_limits<uint32_t>::max();
// TODO
MS_ERROR("--- availableBitrate:%" PRIu32, this->availableBitrate);
CheckStatus();
return this->availableBitrate;
}
void RembClient::AddExtraBitrate(uint32_t extraBitrate)
inline bool RembClient::CheckStatus()
{
MS_TRACE();
// Update last event time.
this->lastEventAt = DepLibUV::GetTime();
if (!HasRecentData())
this->availableBitrate = std::numeric_limits<uint32_t>::max();
else if (this->availableBitrate > extraBitrate)
this->availableBitrate -= extraBitrate;
else
this->availableBitrate = 0;
}
void RembClient::RemoveExtraBitrate(uint32_t extraBitrate)
{
MS_TRACE();
// Update last event time.
this->lastEventAt = DepLibUV::GetTime();
uint64_t now = DepLibUV::GetTime();
if (!HasRecentData())
this->availableBitrate = std::numeric_limits<uint32_t>::max();
else if (std::numeric_limits<uint32_t>::max() - this->availableBitrate > extraBitrate)
this->availableBitrate += extraBitrate;
if (this->lastEventAt != 0 && (now - this->lastEventAt) < MaxEventInterval)
{
return true;
}
else
this->availableBitrate = std::numeric_limits<uint32_t>::max();
}
inline bool RembClient::HasRecentData() const
{
MS_TRACE();
{
this->availableBitrate = this->initialAvailableBitrate;
return (DepLibUV::GetTime() - this->lastEventAt < MaxEventInterval);
return false;
}
}
} // namespace RTC
......@@ -73,7 +73,7 @@ namespace RTC
std::regex_match(scalabilityMode, match, ScalabilityModeRegex);
if (match.size() > 0)
if (!match.empty())
{
this->scalabilityMode = scalabilityMode;
......
......@@ -330,7 +330,7 @@ namespace RTC
}
}
size_t paddedExtensionsTotalSize =
auto paddedExtensionsTotalSize =
static_cast<size_t>(Utils::Byte::PadTo4Bytes(static_cast<uint16_t>(extensionsTotalSize)));
size_t padding = paddedExtensionsTotalSize - extensionsTotalSize;
......
......@@ -89,10 +89,8 @@ namespace RTC
FillRetransmissionContainer(item->GetPacketId(), item->GetLostPacketBitmask());
for (auto it2 = RetransmissionContainer.begin(); it2 != RetransmissionContainer.end(); ++it2)
for (auto* bufferItem : RetransmissionContainer)
{
auto* bufferItem = *it2;
if (bufferItem == nullptr)
break;
......
......@@ -84,7 +84,8 @@ namespace RTC
{
case Channel::Request::MethodId::CONSUMER_REQUEST_KEY_FRAME:
{
RequestKeyFrame();
if (IsActive())
RequestKeyFrame();
request->Accept();
......@@ -99,16 +100,6 @@ namespace RTC
}
}
uint32_t SimpleConsumer::UseBitrate(uint32_t availableBitrate)
{
MS_TRACE();
RequestKeyFrame();
// TODO.
return 0;
}
void SimpleConsumer::ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t /*mappedSsrc*/)
{
MS_TRACE();
......@@ -125,13 +116,6 @@ namespace RTC
this->producerRtpStream = rtpStream;
if (IsActive())
{
// Since the Producer RtpStream has been created right now, we need to ask
// the Transport for bitrate.
this->listener->OnConsumerNeedBitrate(this);
}
// Emit the score event.
EmitScore();
}
......@@ -301,7 +285,8 @@ namespace RTC
this->rtpStream->ReceiveKeyFrameRequest(messageType);
RequestKeyFrame();
if (IsActive())
RequestKeyFrame();
}
void SimpleConsumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
......@@ -325,7 +310,7 @@ namespace RTC
{
MS_TRACE();
if (!IsActive() || !this->producerRtpStream)
if (!IsActive())
return 0;
if (this->producerRtpStream->GetLossPercentage() >= this->rtpStream->GetLossPercentage())
......@@ -338,26 +323,46 @@ namespace RTC
}
}
void SimpleConsumer::Paused()
void SimpleConsumer::UserOnTransportConnected()
{
MS_TRACE();
this->syncRequired = true;
if (IsActive())
{
this->rtpStream->Resume();
RequestKeyFrame();
}
}
void SimpleConsumer::UserOnTransportDisconnected()
{
MS_TRACE();
this->rtpStream->Pause();
}
void SimpleConsumer::Resumed()
void SimpleConsumer::UserOnPaused()
{
MS_TRACE();
this->rtpStream->Resume();
this->rtpStream->Pause();
}
void SimpleConsumer::UserOnResumed()
{
MS_TRACE();
// We need to sync and wait for a key frame (if supported). Otherwise the
// receiver will request lot of NACKs due to unknown RTP packets.
this->syncRequired = true;
// We need to ask the Transport for bitrate.
if (IsActive() && this->producerRtpStream)
this->listener->OnConsumerNeedBitrate(this);
if (IsActive())
{
this->rtpStream->Resume();
RequestKeyFrame();
}
}
void SimpleConsumer::CreateRtpStream()
......@@ -446,7 +451,7 @@ namespace RTC
{
MS_TRACE();
if (!IsActive() || !this->producerRtpStream || this->kind != RTC::Media::Kind::VIDEO)
if (this->kind != RTC::Media::Kind::VIDEO)
return;
auto mappedSsrc = this->consumableRtpEncodings[0].ssrc;
......
......@@ -165,7 +165,8 @@ namespace RTC
{
case Channel::Request::MethodId::CONSUMER_REQUEST_KEY_FRAME:
{
RequestKeyFrame();
if (IsActive())
RequestKeyFrame();
request->Accept();
......@@ -174,6 +175,9 @@ namespace RTC
case Channel::Request::MethodId::CONSUMER_SET_PREFERRED_LAYERS:
{
auto previousPreferredSpatialLayer = this->preferredSpatialLayer;
auto previousPreferredTemporalLayer = this->preferredTemporalLayer;
auto jsonSpatialLayerIt = request->data.find("spatialLayer");
auto jsonTemporalLayerIt = request->data.find("temporalLayer");
......@@ -215,11 +219,18 @@ namespace RTC
this->preferredTemporalLayer,
this->id.c_str());
if (IsActive())
this->listener->OnConsumerNeedBitrate(this);
request->Accept();
if (
IsActive() && (this->preferredSpatialLayer != previousPreferredSpatialLayer ||
this->preferredTemporalLayer != previousPreferredTemporalLayer))
{
this->listener->OnConsumerNeedBitrateChange(this);
// TODO: No.
RecalculateTargetSpatialLayer();
}
break;
}
......@@ -231,21 +242,6 @@ namespace RTC
}
}
uint32_t SimulcastConsumer::UseBitrate(uint32_t availableBitrate)
{
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)
{
MS_TRACE();
......@@ -257,9 +253,6 @@ namespace RTC
int16_t spatialLayer = it->second;
this->producerRtpStreams[spatialLayer] = rtpStream;
// Emit the score event.
EmitScore();
}
void SimulcastConsumer::ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc)
......@@ -274,25 +267,11 @@ namespace RTC
this->producerRtpStreams[spatialLayer] = rtpStream;
// If the Consumer is active and this is the first Producer RtpStream, we
// need to ask for bitrate.
//
// 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->OnConsumerNeedBitrate(this);
}
// TODO: We should never upgrade layers by ourselves.
else if (IsActive())
if (IsActive())
{
this->listener->OnConsumerNeedBitrateChange(this);
// TODO: No.
RecalculateTargetSpatialLayer();
}
......@@ -304,6 +283,14 @@ namespace RTC
{
MS_TRACE();
if (IsActive())
{
// TODO
// If score 0 (inactivity) and this is the Producer's RtpStream we are using,
// then we must recalculate our targets and notify the listener for
// redistribution.
}
// TODO: NO, we just can downgrade layers.
if (IsActive())
RecalculateTargetSpatialLayer();
......@@ -515,7 +502,8 @@ namespace RTC
this->rtpStream->ReceiveKeyFrameRequest(messageType);
RequestKeyFrame();
if (IsActive())
RequestKeyFrame();
}
void SimulcastConsumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
......@@ -554,7 +542,23 @@ namespace RTC
}
}
void SimulcastConsumer::Paused()
void SimulcastConsumer::UserOnTransportConnected()
{
MS_TRACE();
this->syncRequired = true;
if (IsActive())
{
this->rtpStream->Resume();
this->listener->OnConsumerNeedBitrateChange(this);
// TODO: No.
RecalculateTargetSpatialLayer();
}
}
void SimulcastConsumer::UserOnTransportDisconnected()
{
MS_TRACE();
......@@ -574,19 +578,40 @@ namespace RTC
// TODO: Emit JS event?
}
void SimulcastConsumer::Resumed()
void SimulcastConsumer::UserOnPaused()
{
MS_TRACE();
this->rtpStream->Resume();
this->rtpStream->Pause();
// Unset current and target layers.
this->targetSpatialLayer = -1;
this->currentSpatialLayer = -1;
this->targetTemporalLayer = -1;
this->currentTemporalLayer = -1;
if (this->encodingContext)
{
this->encodingContext->preferences.temporalLayer = this->rtpStream->GetTemporalLayers() - 1;
}
// TODO: Emit JS event?
}
void SimulcastConsumer::UserOnResumed()
{
MS_TRACE();
// We need to sync and wait for a key frame (if supported). Otherwise the
// receiver will request lot of NACKs due to unknown RTP packets.
this->syncRequired = true;
// We need to ask the Transport for bitrate.
if (IsActive())
this->listener->OnConsumerNeedBitrate(this);
{
this->rtpStream->Resume();
this->listener->OnConsumerNeedBitrateChange(this);
// TODO: No.
RecalculateTargetSpatialLayer();
}
}
void SimulcastConsumer::CreateRtpStream()
......@@ -679,7 +704,7 @@ namespace RTC
{
MS_TRACE();
if (!IsActive() || this->kind != RTC::Media::Kind::VIDEO)
if (this->kind != RTC::Media::Kind::VIDEO)
return;
auto* producerTargetRtpStream = GetProducerTargetRtpStream();
......@@ -860,7 +885,7 @@ namespace RTC
{
MS_TRACE();
// TODO: NO, we just can downgrade layers.
// TODO: NO.
if (IsActive())
RecalculateTargetSpatialLayer();
......
......@@ -338,6 +338,9 @@ namespace RTC
// Tell the subclass.
UserOnNewConsumer(consumer);
if (IsConnected())
consumer->TransportConnected();
break;
}
......@@ -432,6 +435,14 @@ namespace RTC
// Start the RTCP timer.
this->rtcpTimer->Start(static_cast<uint64_t>(RTC::RTCP::MaxVideoIntervalMs / 2));
// Tell all Consumers.
for (auto& kv : this->mapConsumers)
{
auto* consumer = kv.second;
consumer->TransportConnected();
}
}
void Transport::Disconnected()
......
......@@ -747,7 +747,7 @@ namespace RTC
}
}
void WebRtcTransport::SendRtpPacket(RTC::RtpPacket* packet, RTC::Consumer* consumer)
void WebRtcTransport::SendRtpPacket(RTC::RtpPacket* packet, RTC::Consumer* /*consumer*/)
{
MS_TRACE();
......@@ -1137,19 +1137,8 @@ namespace RTC
{
MS_DEBUG_TAG(bwe, "enabling REMB client");
this->rembClient = new RTC::RembClient(this);
}
// If the Transport is already connected and the Consumer is active, tell the
// new Consumer to use available bitrate.
if (IsConnected() && consumer->IsActive())
{
// TODO
if (this->rembClient)
this->rembClient->GetAvailableBitrate();
// TODO
consumer->UseBitrate();
// TODO: Make this value configurable.
this->rembClient = new RTC::RembClient(this, 300000);
}
}
......@@ -1163,20 +1152,11 @@ namespace RTC
this->rembClient->ReceiveRembFeedback(remb);
}
inline void WebRtcTransport::OnConsumerNeedBitrate(RTC::Consumer* consumer)
inline void WebRtcTransport::OnConsumerNeedBitrateChange(RTC::Consumer* /*consumer*/)
{
MS_TRACE();
// Ignore if not connected.
if (!IsConnected())
return;
// TODO
if (this->rembClient)
this->rembClient->GetAvailableBitrate();
// TODO
consumer->UseBitrate();
}
inline void WebRtcTransport::OnPacketRecv(
......@@ -1370,16 +1350,6 @@ namespace RTC
// Tell the parent class.
RTC::Transport::Connected();
// Tell all Consumers.
for (auto& kv : this->mapConsumers)
{
auto* consumer = kv.second;
// TODO
if (consumer->IsActive())
consumer->UseBitrate();
}
}
inline void WebRtcTransport::OnDtlsFailed(const RTC::DtlsTransport* /*dtlsTransport*/)
......@@ -1438,16 +1408,16 @@ namespace RTC
// NOTE: No DataChannel support, si just ignore it.
}
inline void WebRtcTransport::OnRembClientAvailableBitrate(
RTC::RembClient* /*rembClient*/, uint32_t availableBitrate)
inline void WebRtcTransport::OnRembClientIncreaseBitrate(
RTC::RembClient* /*rembClient*/, uint32_t /*bitrate*/)
{
MS_TRACE();
// TODO
}
inline void WebRtcTransport::OnRembClientExceedingBitrate(
RTC::RembClient* /*rembClient*/, uint32_t exceedingBitrate)
inline void WebRtcTransport::OnRembClientDecreaseBitrate(
RTC::RembClient* /*rembClient*/, uint32_t /*bitrate*/)
{
MS_TRACE();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论