提交 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 ...@@ -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`. 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` ### `make tidy`
......
...@@ -84,6 +84,11 @@ ...@@ -84,6 +84,11 @@
"directory": "PATH/out", "directory": "PATH/out",
"file": "PATH/src/Channel/UnixStreamSocket.cpp" "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", "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", "directory": "PATH/out",
...@@ -114,6 +119,16 @@ ...@@ -114,6 +119,16 @@
"directory": "PATH/out", "directory": "PATH/out",
"file": "PATH/src/RTC/NackGenerator.cpp" "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", "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", "directory": "PATH/out",
...@@ -139,6 +154,11 @@ ...@@ -139,6 +154,11 @@
"directory": "PATH/out", "directory": "PATH/out",
"file": "PATH/src/RTC/RtpListener.cpp" "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", "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", "directory": "PATH/out",
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "RTC/RtpHeaderExtensionIds.hpp" #include "RTC/RtpHeaderExtensionIds.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/RtpStream.hpp" #include "RTC/RtpStream.hpp"
#include <limits>
#include <string> #include <string>
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
...@@ -28,7 +27,7 @@ namespace RTC ...@@ -28,7 +27,7 @@ namespace RTC
virtual void OnConsumerSendRtpPacket(RTC::Consumer* consumer, RTC::RtpPacket* packet) = 0; virtual void OnConsumerSendRtpPacket(RTC::Consumer* consumer, RTC::RtpPacket* packet) = 0;
virtual void OnConsumerRetransmitRtpPacket(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 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; virtual void onConsumerProducerClosed(RTC::Consumer* consumer) = 0;
}; };
...@@ -50,10 +49,11 @@ namespace RTC ...@@ -50,10 +49,11 @@ namespace RTC
const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const; const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const;
RTC::RtpParameters::Type GetType() const; RTC::RtpParameters::Type GetType() const;
const std::vector<uint32_t>& GetMediaSsrcs() const; const std::vector<uint32_t>& GetMediaSsrcs() const;
bool IsActive() const; virtual bool IsActive() const;
void TransportConnected();
void TransportDisconnected();
bool IsPaused() const; bool IsPaused() const;
bool IsProducerPaused() const; bool IsProducerPaused() const;
virtual uint32_t UseBitrate(uint32_t availableBitrate = std::numeric_limits<uint32_t>::max()) = 0;
void ProducerPaused(); void ProducerPaused();
void ProducerResumed(); void ProducerResumed();
virtual void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) = 0; virtual void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) = 0;
...@@ -69,9 +69,11 @@ namespace RTC ...@@ -69,9 +69,11 @@ namespace RTC
virtual uint32_t GetTransmissionRate(uint64_t now) = 0; virtual uint32_t GetTransmissionRate(uint64_t now) = 0;
virtual float GetLossPercentage() const = 0; virtual float GetLossPercentage() const = 0;
protected: private:
virtual void Paused() = 0; virtual void UserOnTransportConnected() = 0;
virtual void Resumed() = 0; virtual void UserOnTransportDisconnected() = 0;
virtual void UserOnPaused() = 0;
virtual void UserOnResumed() = 0;
public: public:
// Passed by argument. // Passed by argument.
...@@ -93,6 +95,7 @@ namespace RTC ...@@ -93,6 +95,7 @@ namespace RTC
private: private:
// Others. // Others.
std::vector<uint32_t> mediaSsrcs; std::vector<uint32_t> mediaSsrcs;
bool transportConnected{ false };
bool paused{ false }; bool paused{ false };
bool producerPaused{ false }; bool producerPaused{ false };
bool producerClosed{ false }; bool producerClosed{ false };
...@@ -127,7 +130,10 @@ namespace RTC ...@@ -127,7 +130,10 @@ namespace RTC
inline bool Consumer::IsActive() const 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 inline bool Consumer::IsPaused() const
......
...@@ -17,7 +17,6 @@ namespace RTC ...@@ -17,7 +17,6 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override; void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override; void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override; void HandleRequest(Channel::Request* request) override;
uint32_t UseBitrate(uint32_t availableBitrate) override;
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override; void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(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; void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score) override;
...@@ -31,8 +30,10 @@ namespace RTC ...@@ -31,8 +30,10 @@ namespace RTC
float GetLossPercentage() const override; float GetLossPercentage() const override;
private: private:
void Paused() override; void UserOnTransportConnected() override;
void Resumed() override; void UserOnTransportDisconnected() override;
void UserOnPaused() override;
void UserOnResumed() override;
void CreateRtpStreams(); void CreateRtpStreams();
void RequestKeyFrame(); void RequestKeyFrame();
......
...@@ -42,7 +42,7 @@ namespace RTC ...@@ -42,7 +42,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Consumer::Listener. */ /* Pure virtual methods inherited from RTC::Consumer::Listener. */
public: public:
void OnConsumerNeedBitrate(RTC::Consumer* consumer) override; void OnConsumerNeedBitrateChange(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from RTC::UdpSocket::Listener. */ /* Pure virtual methods inherited from RTC::UdpSocket::Listener. */
public: public:
......
...@@ -42,7 +42,7 @@ namespace RTC ...@@ -42,7 +42,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Consumer::Listener. */ /* Pure virtual methods inherited from RTC::Consumer::Listener. */
public: public:
void OnConsumerNeedBitrate(RTC::Consumer* consumer) override; void OnConsumerNeedBitrateChange(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from RTC::UdpSocket::Listener. */ /* Pure virtual methods inherited from RTC::UdpSocket::Listener. */
public: public:
......
...@@ -15,32 +15,28 @@ namespace RTC ...@@ -15,32 +15,28 @@ namespace RTC
class Listener class Listener
{ {
public: public:
virtual void OnRembClientAvailableBitrate( virtual void OnRembClientIncreaseBitrate(RTC::RembClient* rembClient, uint32_t bitrate) = 0;
RTC::RembClient* rembClient, uint32_t availableBitrate) = 0; virtual void OnRembClientDecreaseBitrate(RTC::RembClient* rembClient, uint32_t bitrate) = 0;
virtual void OnRembClientExceedingBitrate(
RTC::RembClient* rembClient, uint32_t exceedingBitrate) = 0;
}; };
public: public:
RembClient(RTC::RembClient::Listener* listener); RembClient(RTC::RembClient::Listener* listener, uint32_t initialAvailableBitrate);
virtual ~RembClient(); virtual ~RembClient();
public: public:
void ReceiveRtpPacket(RTC::RtpPacket* packet); void ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRembFeedback(RTC::RTCP::FeedbackPsRembPacket* remb); void ReceiveRembFeedback(RTC::RTCP::FeedbackPsRembPacket* remb);
uint32_t GetAvailableBitrate(); uint32_t GetAvailableBitrate();
void AddExtraBitrate(uint32_t extraBitrate);
void RemoveExtraBitrate(uint32_t extraBitrate);
private: private:
bool HasRecentData() const; bool CheckStatus();
private: private:
Listener* listener; Listener* listener;
RTC::RtpDataCounter transmissionCounter; RTC::RtpDataCounter transmissionCounter;
uint32_t initialAvailableBitrate{ 0 };
uint32_t availableBitrate{ 0 };
uint64_t lastEventAt{ 0 }; uint64_t lastEventAt{ 0 };
uint32_t rembBitrate{ 0 };
uint32_t availableBitrate{ std::numeric_limits<uint32_t>::max() };
}; };
} // namespace RTC } // namespace RTC
......
...@@ -18,7 +18,7 @@ namespace RTC ...@@ -18,7 +18,7 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override; void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override; void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) 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 ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(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; void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score) override;
...@@ -32,8 +32,10 @@ namespace RTC ...@@ -32,8 +32,10 @@ namespace RTC
float GetLossPercentage() const override; float GetLossPercentage() const override;
private: private:
void Paused() override; void UserOnTransportConnected() override;
void Resumed() override; void UserOnTransportDisconnected() override;
void UserOnPaused() override;
void UserOnResumed() override;
void CreateRtpStream(); void CreateRtpStream();
void RequestKeyFrame(); void RequestKeyFrame();
void EmitScore() const; void EmitScore() const;
...@@ -48,11 +50,18 @@ namespace RTC ...@@ -48,11 +50,18 @@ namespace RTC
RTC::RtpStreamSend* rtpStream{ nullptr }; RTC::RtpStreamSend* rtpStream{ nullptr };
// Others. // Others.
bool keyFrameSupported{ false }; bool keyFrameSupported{ false };
bool syncRequired{ true }; bool syncRequired{ false };
RTC::SeqManager<uint16_t> rtpSeqManager; RTC::SeqManager<uint16_t> rtpSeqManager;
RTC::SeqManager<uint32_t> rtpTimestampManager; RTC::SeqManager<uint32_t> rtpTimestampManager;
RTC::RtpStream* producerRtpStream{ nullptr }; RTC::RtpStream* producerRtpStream{ nullptr };
}; };
/* Inline methods. */
inline bool SimpleConsumer::IsActive() const
{
return (RTC::Consumer::IsActive() && this->producerRtpStream);
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -19,7 +19,7 @@ namespace RTC ...@@ -19,7 +19,7 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override; void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override; void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) 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 ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(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; void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score) override;
...@@ -33,8 +33,10 @@ namespace RTC ...@@ -33,8 +33,10 @@ namespace RTC
float GetLossPercentage() const override; float GetLossPercentage() const override;
private: private:
void Paused() override; void UserOnTransportConnected() override;
void Resumed() override; void UserOnTransportDisconnected() override;
void UserOnPaused() override;
void UserOnResumed() override;
void CreateRtpStream(); void CreateRtpStream();
void RequestKeyFrame(); void RequestKeyFrame();
void RetransmitRtpPacket(RTC::RtpPacket* packet); void RetransmitRtpPacket(RTC::RtpPacket* packet);
...@@ -56,7 +58,7 @@ namespace RTC ...@@ -56,7 +58,7 @@ namespace RTC
std::vector<RTC::RtpStream*> producerRtpStreams; // Indexed by spatial layer. std::vector<RTC::RtpStream*> producerRtpStreams; // Indexed by spatial layer.
// Others. // Others.
bool keyFrameSupported{ false }; bool keyFrameSupported{ false };
bool syncRequired{ true }; bool syncRequired{ false };
RTC::SeqManager<uint16_t> rtpSeqManager; RTC::SeqManager<uint16_t> rtpSeqManager;
RTC::SeqManager<uint32_t> rtpTimestampManager; RTC::SeqManager<uint32_t> rtpTimestampManager;
std::unique_ptr<RTC::Codecs::EncodingContext> encodingContext; std::unique_ptr<RTC::Codecs::EncodingContext> encodingContext;
...@@ -67,6 +69,22 @@ namespace RTC ...@@ -67,6 +69,22 @@ namespace RTC
int16_t currentSpatialLayer{ -1 }; int16_t currentSpatialLayer{ -1 };
int16_t currentTemporalLayer{ -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 } // namespace RTC
#endif #endif
...@@ -114,7 +114,7 @@ namespace RTC ...@@ -114,7 +114,7 @@ namespace RTC
void OnConsumerSendRtpPacket(RTC::Consumer* consumer, RTC::RtpPacket* packet) override; void OnConsumerSendRtpPacket(RTC::Consumer* consumer, RTC::RtpPacket* packet) override;
void OnConsumerRetransmitRtpPacket(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; 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; void onConsumerProducerClosed(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
......
...@@ -62,7 +62,7 @@ namespace RTC ...@@ -62,7 +62,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Consumer::Listener. */ /* Pure virtual methods inherited from RTC::Consumer::Listener. */
public: public:
void OnConsumerNeedBitrate(RTC::Consumer* consumer) override; void OnConsumerNeedBitrateChange(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from RTC::UdpSocket::Listener. */ /* Pure virtual methods inherited from RTC::UdpSocket::Listener. */
public: public:
...@@ -107,8 +107,8 @@ namespace RTC ...@@ -107,8 +107,8 @@ namespace RTC
/* Pure virtual methods inherited from RTC::RembClient::Listener. */ /* Pure virtual methods inherited from RTC::RembClient::Listener. */
public: public:
void OnRembClientAvailableBitrate(RTC::RembClient* rembClient, uint32_t availableBitrate) override; void OnRembClientIncreaseBitrate(RTC::RembClient* rembClient, uint32_t bitrate) override;
void OnRembClientExceedingBitrate(RTC::RembClient* rembClient, uint32_t exceedingBitrate) override; void OnRembClientDecreaseBitrate(RTC::RembClient* rembClient, uint32_t bitrate) override;
/* Pure virtual methods inherited from RTC::RembServer::RemoteBitrateEstimator::Listener. */ /* Pure virtual methods inherited from RTC::RembServer::RemoteBitrateEstimator::Listener. */
public: public:
......
...@@ -157,7 +157,7 @@ namespace RTC ...@@ -157,7 +157,7 @@ namespace RTC
// Clear the map. // Clear the map.
ResetMapProducerDBovs(); ResetMapProducerDBovs();
if (mapDBovsProducer.size() > 0) if (!mapDBovsProducer.empty())
{ {
this->silence = false; this->silence = false;
......
...@@ -219,7 +219,7 @@ namespace RTC ...@@ -219,7 +219,7 @@ namespace RTC
MS_DEBUG_DEV("Consumer paused [consumerId:%s]", this->id.c_str()); MS_DEBUG_DEV("Consumer paused [consumerId:%s]", this->id.c_str());
if (wasActive) if (wasActive)
Paused(); UserOnPaused();
request->Accept(); request->Accept();
...@@ -240,7 +240,7 @@ namespace RTC ...@@ -240,7 +240,7 @@ namespace RTC
MS_DEBUG_DEV("Consumer resumed [consumerId:%s]", this->id.c_str()); MS_DEBUG_DEV("Consumer resumed [consumerId:%s]", this->id.c_str());
if (IsActive()) if (IsActive())
Resumed(); UserOnResumed();
request->Accept(); request->Accept();
...@@ -254,6 +254,28 @@ namespace RTC ...@@ -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() void Consumer::ProducerPaused()
{ {
MS_TRACE(); MS_TRACE();
...@@ -268,7 +290,7 @@ namespace RTC ...@@ -268,7 +290,7 @@ namespace RTC
MS_DEBUG_DEV("Producer paused [consumerId:%s]", this->id.c_str()); MS_DEBUG_DEV("Producer paused [consumerId:%s]", this->id.c_str());
if (wasActive) if (wasActive)
Paused(); UserOnPaused();
Channel::Notifier::Emit(this->id, "producerpause"); Channel::Notifier::Emit(this->id, "producerpause");
} }
...@@ -285,7 +307,7 @@ namespace RTC ...@@ -285,7 +307,7 @@ namespace RTC
MS_DEBUG_DEV("Producer resumed [consumerId:%s]", this->id.c_str()); MS_DEBUG_DEV("Producer resumed [consumerId:%s]", this->id.c_str());
if (IsActive()) if (IsActive())
Resumed(); UserOnResumed();
Channel::Notifier::Emit(this->id, "producerresume"); Channel::Notifier::Emit(this->id, "producerresume");
} }
......
...@@ -43,14 +43,14 @@ namespace RTC ...@@ -43,14 +43,14 @@ namespace RTC
RTC::Consumer::FillJson(jsonObject); RTC::Consumer::FillJson(jsonObject);
} }
void PipeConsumer::FillJsonStats(json& jsonArray) const void PipeConsumer::FillJsonStats(json& /*jsonArray*/) const
{ {
MS_TRACE(); MS_TRACE();
// Do nothing. // Do nothing.
} }
void PipeConsumer::FillJsonScore(json& jsonObject) const void PipeConsumer::FillJsonScore(json& /*jsonObject*/) const
{ {
MS_TRACE(); MS_TRACE();
...@@ -65,7 +65,8 @@ namespace RTC ...@@ -65,7 +65,8 @@ namespace RTC
{ {
case Channel::Request::MethodId::CONSUMER_REQUEST_KEY_FRAME: case Channel::Request::MethodId::CONSUMER_REQUEST_KEY_FRAME:
{ {
RequestKeyFrame(); if (IsActive())
RequestKeyFrame();
request->Accept(); request->Accept();
...@@ -80,16 +81,6 @@ namespace RTC ...@@ -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*/) void PipeConsumer::ProducerRtpStream(RTC::RtpStream* /*rtpStream*/, uint32_t /*mappedSsrc*/)
{ {
MS_TRACE(); MS_TRACE();
...@@ -187,11 +178,12 @@ namespace RTC ...@@ -187,11 +178,12 @@ namespace RTC
// Do nothing since we do not enable NACK. // 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(); MS_TRACE();
RequestKeyFrame(); if (IsActive())
RequestKeyFrame();
} }
void PipeConsumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report) void PipeConsumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
...@@ -216,6 +208,9 @@ namespace RTC ...@@ -216,6 +208,9 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (!IsActive())
return 0u;
uint32_t rate{ 0 }; uint32_t rate{ 0 };
for (auto& kv : this->mapMappedSsrcRtpStream) for (auto& kv : this->mapMappedSsrcRtpStream)
...@@ -236,7 +231,24 @@ namespace RTC ...@@ -236,7 +231,24 @@ namespace RTC
return 0u; 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(); MS_TRACE();
...@@ -248,7 +260,7 @@ namespace RTC ...@@ -248,7 +260,7 @@ namespace RTC
} }
} }
void PipeConsumer::Resumed() void PipeConsumer::UserOnPaused()
{ {
MS_TRACE(); MS_TRACE();
...@@ -256,12 +268,25 @@ namespace RTC ...@@ -256,12 +268,25 @@ namespace RTC
{ {
auto& rtpStream = kv.second; auto& rtpStream = kv.second;
rtpStream->Resume(); rtpStream->Pause();
} }
}
void PipeConsumer::UserOnResumed()
{
MS_TRACE();
// We need to ask the Transport for bitrate.
if (IsActive()) if (IsActive())
this->listener->OnConsumerNeedBitrate(this); {
for (auto& kv : this->mapMappedSsrcRtpStream)
{
auto& rtpStream = kv.second;
rtpStream->Resume();
}
RequestKeyFrame();
}
} }
void PipeConsumer::CreateRtpStreams() void PipeConsumer::CreateRtpStreams()
...@@ -352,7 +377,7 @@ namespace RTC ...@@ -352,7 +377,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (!IsActive() || this->kind != RTC::Media::Kind::VIDEO) if (this->kind != RTC::Media::Kind::VIDEO)
return; return;
for (auto& encoding : this->rtpParameters.encodings) for (auto& encoding : this->rtpParameters.encodings)
......
...@@ -236,15 +236,6 @@ namespace RTC ...@@ -236,15 +236,6 @@ namespace RTC
// and tell the parent class. // and tell the parent class.
RTC::Transport::Connected(); RTC::Transport::Connected();
// Tell all Consumers.
for (auto& kv : this->mapConsumers)
{
auto* consumer = kv.second;
if (consumer->IsActive())
consumer->UseBitrate();
}
break; break;
} }
...@@ -415,14 +406,9 @@ namespace RTC ...@@ -415,14 +406,9 @@ namespace RTC
// Do nothing. // Do nothing.
} }
void PipeTransport::UserOnNewConsumer(RTC::Consumer* consumer) void PipeTransport::UserOnNewConsumer(RTC::Consumer* /*consumer*/)
{ {
MS_TRACE(); 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*/) void PipeTransport::UserOnRembFeedback(RTC::RTCP::FeedbackPsRembPacket* /*remb*/)
...@@ -432,15 +418,11 @@ namespace RTC ...@@ -432,15 +418,11 @@ namespace RTC
// TODO // TODO
} }
inline void PipeTransport::OnConsumerNeedBitrate(RTC::Consumer* consumer) inline void PipeTransport::OnConsumerNeedBitrateChange(RTC::Consumer* /*consumer*/)
{ {
MS_TRACE(); MS_TRACE();
// Ignore if not connected. // TODO
if (!IsConnected())
return;
consumer->UseBitrate();
} }
inline void PipeTransport::OnPacketRecv( inline void PipeTransport::OnPacketRecv(
......
...@@ -413,15 +413,6 @@ namespace RTC ...@@ -413,15 +413,6 @@ namespace RTC
// and tell the parent class. // and tell the parent class.
RTC::Transport::Connected(); RTC::Transport::Connected();
// Tell all Consumers.
for (auto& kv : this->mapConsumers)
{
auto* consumer = kv.second;
if (consumer->IsActive())
consumer->UseBitrate();
}
break; break;
} }
...@@ -687,14 +678,9 @@ namespace RTC ...@@ -687,14 +678,9 @@ namespace RTC
// Do nothing. // Do nothing.
} }
void PlainRtpTransport::UserOnNewConsumer(RTC::Consumer* consumer) void PlainRtpTransport::UserOnNewConsumer(RTC::Consumer* /*consumer*/)
{ {
MS_TRACE(); 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*/) void PlainRtpTransport::UserOnRembFeedback(RTC::RTCP::FeedbackPsRembPacket* /*remb*/)
...@@ -704,15 +690,9 @@ namespace RTC ...@@ -704,15 +690,9 @@ namespace RTC
// TODO // TODO
} }
inline void PlainRtpTransport::OnConsumerNeedBitrate(RTC::Consumer* consumer) inline void PlainRtpTransport::OnConsumerNeedBitrateChange(RTC::Consumer* /*consumer*/)
{ {
MS_TRACE(); MS_TRACE();
// Ignore if not connected.
if (!IsConnected())
return;
consumer->UseBitrate();
} }
inline void PlainRtpTransport::OnPacketRecv( inline void PlainRtpTransport::OnPacketRecv(
......
...@@ -847,8 +847,6 @@ namespace RTC ...@@ -847,8 +847,6 @@ namespace RTC
static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL), static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL),
extenLen, extenLen,
bufferPtr); bufferPtr);
bufferPtr += extenLen;
} }
} }
} }
...@@ -897,8 +895,6 @@ namespace RTC ...@@ -897,8 +895,6 @@ namespace RTC
extensions.emplace_back( extensions.emplace_back(
static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::ABS_SEND_TIME), extenLen, bufferPtr); static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::ABS_SEND_TIME), extenLen, bufferPtr);
bufferPtr += extenLen;
} }
} }
......
...@@ -14,8 +14,9 @@ namespace RTC ...@@ -14,8 +14,9 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
RembClient::RembClient(RTC::RembClient::Listener* listener) RembClient::RembClient(RTC::RembClient::Listener* listener, uint32_t initialAvailableBitrate)
: listener(listener), lastEventAt(DepLibUV::GetTime()) : listener(listener), initialAvailableBitrate(initialAvailableBitrate),
availableBitrate(initialAvailableBitrate)
{ {
MS_TRACE(); MS_TRACE();
} }
...@@ -36,25 +37,20 @@ namespace RTC ...@@ -36,25 +37,20 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// Check if we should fire the event. MS_ERROR("remb:%" PRIu64, remb->GetBitrate());
uint64_t now = DepLibUV::GetTime(); 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. // Update last event time.
this->lastEventAt = now; 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; return;
} }
else if (now - this->lastEventAt < EventInterval) // Otherwise ensure EventInterval has happened.
else if (this->lastEventAt != 0 && (now - this->lastEventAt) < EventInterval)
{ {
return; return;
} }
...@@ -62,56 +58,52 @@ namespace RTC ...@@ -62,56 +58,52 @@ namespace RTC
// Update last event time. // Update last event time.
this->lastEventAt = now; this->lastEventAt = now;
uint32_t newRembBitrate = static_cast<uint32_t>(remb->GetBitrate()); auto previousAvailableBitrate = this->availableBitrate;
int64_t rembTrend =
static_cast<int64_t>(newRembBitrate) - static_cast<int64_t>(this->rembBitrate);
uint32_t bitrateInUse = this->transmissionCounter.GetRate(now);
// Update REMB bitrate. // Update available bitrate.
this->rembBitrate = newRembBitrate; 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( MS_DEBUG_TAG(
bwe, bwe,
"available bitrate [REMB:%" PRIu32 " >= bitrateInUse:%" PRIu32 ", availableBitrate:%" PRIu32 "usable bitrate [availableBitrate:%" PRIu32 " >= usedBitrate:%" PRIu32
"]", ", usableBitrate:%" PRIu32 "]",
this->rembBitrate, this->availableBitrate,
bitrateInUse, usedBitrate,
availableBitrate); usableBitrate);
this->availableBitrate = availableBitrate;
this->listener->OnRembClientAvailableBitrate(this, availableBitrate); this->listener->OnRembClientIncreaseBitrate(this, usableBitrate);
} }
else if (rembTrend > 0) else if (trend > 0)
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
bwe, bwe,
"positive REMB trend [REMB:%" PRIu32 " < bitrateInUse:%" PRIu32 ", trend:%" PRIi64 "]", "positive REMB trend [availableBitrate:%" PRIu32 " < usedBitrate:%" PRIu32
this->rembBitrate, ", trend:%" PRIi64 "]",
bitrateInUse, this->availableBitrate,
rembTrend); usedBitrate,
trend);
this->availableBitrate = 0;
} }
else else
{ {
uint32_t exceedingBitrate = bitrateInUse - this->rembBitrate; uint32_t exceedingBitrate = usedBitrate - this->availableBitrate;
MS_WARN_TAG( MS_WARN_TAG(
bwe, bwe,
"exceeding bitrate [REMB:%" PRIu32 " < bitrateInUse:%" PRIu32 ", exceedingBitrate:%" PRIu32 "exceeding bitrate [availableBitrate:%" PRIu32 " < usedBitrate:%" PRIu32
"]", ", exceedingBitrate:%" PRIu32 "]",
this->rembBitrate, this->availableBitrate,
bitrateInUse, usedBitrate,
exceedingBitrate); exceedingBitrate);
this->availableBitrate = 0; this->listener->OnRembClientDecreaseBitrate(this, exceedingBitrate);
this->listener->OnRembClientExceedingBitrate(this, exceedingBitrate);
} }
} }
...@@ -119,49 +111,26 @@ namespace RTC ...@@ -119,49 +111,26 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (!HasRecentData()) CheckStatus();
this->availableBitrate = std::numeric_limits<uint32_t>::max();
// TODO
MS_ERROR("--- availableBitrate:%" PRIu32, this->availableBitrate);
return this->availableBitrate; return this->availableBitrate;
} }
void RembClient::AddExtraBitrate(uint32_t extraBitrate) inline bool RembClient::CheckStatus()
{ {
MS_TRACE(); MS_TRACE();
// Update last event time. uint64_t now = DepLibUV::GetTime();
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();
if (!HasRecentData()) if (this->lastEventAt != 0 && (now - this->lastEventAt) < MaxEventInterval)
this->availableBitrate = std::numeric_limits<uint32_t>::max(); {
else if (std::numeric_limits<uint32_t>::max() - this->availableBitrate > extraBitrate) return true;
this->availableBitrate += extraBitrate; }
else else
this->availableBitrate = std::numeric_limits<uint32_t>::max(); {
} this->availableBitrate = this->initialAvailableBitrate;
inline bool RembClient::HasRecentData() const
{
MS_TRACE();
return (DepLibUV::GetTime() - this->lastEventAt < MaxEventInterval); return false;
}
} }
} // namespace RTC } // namespace RTC
...@@ -73,7 +73,7 @@ namespace RTC ...@@ -73,7 +73,7 @@ namespace RTC
std::regex_match(scalabilityMode, match, ScalabilityModeRegex); std::regex_match(scalabilityMode, match, ScalabilityModeRegex);
if (match.size() > 0) if (!match.empty())
{ {
this->scalabilityMode = scalabilityMode; this->scalabilityMode = scalabilityMode;
......
...@@ -330,7 +330,7 @@ namespace RTC ...@@ -330,7 +330,7 @@ namespace RTC
} }
} }
size_t paddedExtensionsTotalSize = auto paddedExtensionsTotalSize =
static_cast<size_t>(Utils::Byte::PadTo4Bytes(static_cast<uint16_t>(extensionsTotalSize))); static_cast<size_t>(Utils::Byte::PadTo4Bytes(static_cast<uint16_t>(extensionsTotalSize)));
size_t padding = paddedExtensionsTotalSize - extensionsTotalSize; size_t padding = paddedExtensionsTotalSize - extensionsTotalSize;
......
...@@ -89,10 +89,8 @@ namespace RTC ...@@ -89,10 +89,8 @@ namespace RTC
FillRetransmissionContainer(item->GetPacketId(), item->GetLostPacketBitmask()); FillRetransmissionContainer(item->GetPacketId(), item->GetLostPacketBitmask());
for (auto it2 = RetransmissionContainer.begin(); it2 != RetransmissionContainer.end(); ++it2) for (auto* bufferItem : RetransmissionContainer)
{ {
auto* bufferItem = *it2;
if (bufferItem == nullptr) if (bufferItem == nullptr)
break; break;
......
...@@ -84,7 +84,8 @@ namespace RTC ...@@ -84,7 +84,8 @@ namespace RTC
{ {
case Channel::Request::MethodId::CONSUMER_REQUEST_KEY_FRAME: case Channel::Request::MethodId::CONSUMER_REQUEST_KEY_FRAME:
{ {
RequestKeyFrame(); if (IsActive())
RequestKeyFrame();
request->Accept(); request->Accept();
...@@ -99,16 +100,6 @@ namespace RTC ...@@ -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*/) void SimpleConsumer::ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t /*mappedSsrc*/)
{ {
MS_TRACE(); MS_TRACE();
...@@ -125,13 +116,6 @@ namespace RTC ...@@ -125,13 +116,6 @@ namespace RTC
this->producerRtpStream = rtpStream; 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. // Emit the score event.
EmitScore(); EmitScore();
} }
...@@ -301,7 +285,8 @@ namespace RTC ...@@ -301,7 +285,8 @@ namespace RTC
this->rtpStream->ReceiveKeyFrameRequest(messageType); this->rtpStream->ReceiveKeyFrameRequest(messageType);
RequestKeyFrame(); if (IsActive())
RequestKeyFrame();
} }
void SimpleConsumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report) void SimpleConsumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
...@@ -325,7 +310,7 @@ namespace RTC ...@@ -325,7 +310,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (!IsActive() || !this->producerRtpStream) if (!IsActive())
return 0; return 0;
if (this->producerRtpStream->GetLossPercentage() >= this->rtpStream->GetLossPercentage()) if (this->producerRtpStream->GetLossPercentage() >= this->rtpStream->GetLossPercentage())
...@@ -338,26 +323,46 @@ namespace RTC ...@@ -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(); MS_TRACE();
this->rtpStream->Pause(); this->rtpStream->Pause();
} }
void SimpleConsumer::Resumed() void SimpleConsumer::UserOnPaused()
{ {
MS_TRACE(); 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; this->syncRequired = true;
// We need to ask the Transport for bitrate. if (IsActive())
if (IsActive() && this->producerRtpStream) {
this->listener->OnConsumerNeedBitrate(this); this->rtpStream->Resume();
RequestKeyFrame();
}
} }
void SimpleConsumer::CreateRtpStream() void SimpleConsumer::CreateRtpStream()
...@@ -446,7 +451,7 @@ namespace RTC ...@@ -446,7 +451,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (!IsActive() || !this->producerRtpStream || this->kind != RTC::Media::Kind::VIDEO) if (this->kind != RTC::Media::Kind::VIDEO)
return; return;
auto mappedSsrc = this->consumableRtpEncodings[0].ssrc; auto mappedSsrc = this->consumableRtpEncodings[0].ssrc;
......
...@@ -165,7 +165,8 @@ namespace RTC ...@@ -165,7 +165,8 @@ namespace RTC
{ {
case Channel::Request::MethodId::CONSUMER_REQUEST_KEY_FRAME: case Channel::Request::MethodId::CONSUMER_REQUEST_KEY_FRAME:
{ {
RequestKeyFrame(); if (IsActive())
RequestKeyFrame();
request->Accept(); request->Accept();
...@@ -174,6 +175,9 @@ namespace RTC ...@@ -174,6 +175,9 @@ namespace RTC
case Channel::Request::MethodId::CONSUMER_SET_PREFERRED_LAYERS: case Channel::Request::MethodId::CONSUMER_SET_PREFERRED_LAYERS:
{ {
auto previousPreferredSpatialLayer = this->preferredSpatialLayer;
auto previousPreferredTemporalLayer = this->preferredTemporalLayer;
auto jsonSpatialLayerIt = request->data.find("spatialLayer"); auto jsonSpatialLayerIt = request->data.find("spatialLayer");
auto jsonTemporalLayerIt = request->data.find("temporalLayer"); auto jsonTemporalLayerIt = request->data.find("temporalLayer");
...@@ -215,11 +219,18 @@ namespace RTC ...@@ -215,11 +219,18 @@ namespace RTC
this->preferredTemporalLayer, this->preferredTemporalLayer,
this->id.c_str()); this->id.c_str());
if (IsActive())
this->listener->OnConsumerNeedBitrate(this);
request->Accept(); request->Accept();
if (
IsActive() && (this->preferredSpatialLayer != previousPreferredSpatialLayer ||
this->preferredTemporalLayer != previousPreferredTemporalLayer))
{
this->listener->OnConsumerNeedBitrateChange(this);
// TODO: No.
RecalculateTargetSpatialLayer();
}
break; break;
} }
...@@ -231,21 +242,6 @@ namespace RTC ...@@ -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) void SimulcastConsumer::ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc)
{ {
MS_TRACE(); MS_TRACE();
...@@ -257,9 +253,6 @@ namespace RTC ...@@ -257,9 +253,6 @@ namespace RTC
int16_t spatialLayer = it->second; int16_t spatialLayer = it->second;
this->producerRtpStreams[spatialLayer] = rtpStream; this->producerRtpStreams[spatialLayer] = rtpStream;
// Emit the score event.
EmitScore();
} }
void SimulcastConsumer::ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) void SimulcastConsumer::ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc)
...@@ -274,25 +267,11 @@ namespace RTC ...@@ -274,25 +267,11 @@ namespace RTC
this->producerRtpStreams[spatialLayer] = rtpStream; this->producerRtpStreams[spatialLayer] = rtpStream;
// If the Consumer is active and this is the first Producer RtpStream, we if (IsActive())
// 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())
{ {
this->listener->OnConsumerNeedBitrateChange(this);
// TODO: No.
RecalculateTargetSpatialLayer(); RecalculateTargetSpatialLayer();
} }
...@@ -304,6 +283,14 @@ namespace RTC ...@@ -304,6 +283,14 @@ namespace RTC
{ {
MS_TRACE(); 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. // TODO: NO, we just can downgrade layers.
if (IsActive()) if (IsActive())
RecalculateTargetSpatialLayer(); RecalculateTargetSpatialLayer();
...@@ -515,7 +502,8 @@ namespace RTC ...@@ -515,7 +502,8 @@ namespace RTC
this->rtpStream->ReceiveKeyFrameRequest(messageType); this->rtpStream->ReceiveKeyFrameRequest(messageType);
RequestKeyFrame(); if (IsActive())
RequestKeyFrame();
} }
void SimulcastConsumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report) void SimulcastConsumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
...@@ -554,7 +542,23 @@ namespace RTC ...@@ -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(); MS_TRACE();
...@@ -574,19 +578,40 @@ namespace RTC ...@@ -574,19 +578,40 @@ namespace RTC
// TODO: Emit JS event? // TODO: Emit JS event?
} }
void SimulcastConsumer::Resumed() void SimulcastConsumer::UserOnPaused()
{ {
MS_TRACE(); 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; this->syncRequired = true;
// We need to ask the Transport for bitrate.
if (IsActive()) if (IsActive())
this->listener->OnConsumerNeedBitrate(this); {
this->rtpStream->Resume();
this->listener->OnConsumerNeedBitrateChange(this);
// TODO: No.
RecalculateTargetSpatialLayer();
}
} }
void SimulcastConsumer::CreateRtpStream() void SimulcastConsumer::CreateRtpStream()
...@@ -679,7 +704,7 @@ namespace RTC ...@@ -679,7 +704,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (!IsActive() || this->kind != RTC::Media::Kind::VIDEO) if (this->kind != RTC::Media::Kind::VIDEO)
return; return;
auto* producerTargetRtpStream = GetProducerTargetRtpStream(); auto* producerTargetRtpStream = GetProducerTargetRtpStream();
...@@ -860,7 +885,7 @@ namespace RTC ...@@ -860,7 +885,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// TODO: NO, we just can downgrade layers. // TODO: NO.
if (IsActive()) if (IsActive())
RecalculateTargetSpatialLayer(); RecalculateTargetSpatialLayer();
......
...@@ -338,6 +338,9 @@ namespace RTC ...@@ -338,6 +338,9 @@ namespace RTC
// Tell the subclass. // Tell the subclass.
UserOnNewConsumer(consumer); UserOnNewConsumer(consumer);
if (IsConnected())
consumer->TransportConnected();
break; break;
} }
...@@ -432,6 +435,14 @@ namespace RTC ...@@ -432,6 +435,14 @@ namespace RTC
// Start the RTCP timer. // Start the RTCP timer.
this->rtcpTimer->Start(static_cast<uint64_t>(RTC::RTCP::MaxVideoIntervalMs / 2)); 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() void Transport::Disconnected()
......
...@@ -747,7 +747,7 @@ namespace RTC ...@@ -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(); MS_TRACE();
...@@ -1137,19 +1137,8 @@ namespace RTC ...@@ -1137,19 +1137,8 @@ namespace RTC
{ {
MS_DEBUG_TAG(bwe, "enabling REMB client"); MS_DEBUG_TAG(bwe, "enabling REMB client");
this->rembClient = new RTC::RembClient(this); // TODO: Make this value configurable.
} this->rembClient = new RTC::RembClient(this, 300000);
// 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();
} }
} }
...@@ -1163,20 +1152,11 @@ namespace RTC ...@@ -1163,20 +1152,11 @@ namespace RTC
this->rembClient->ReceiveRembFeedback(remb); this->rembClient->ReceiveRembFeedback(remb);
} }
inline void WebRtcTransport::OnConsumerNeedBitrate(RTC::Consumer* consumer) inline void WebRtcTransport::OnConsumerNeedBitrateChange(RTC::Consumer* /*consumer*/)
{ {
MS_TRACE(); MS_TRACE();
// Ignore if not connected.
if (!IsConnected())
return;
// TODO // TODO
if (this->rembClient)
this->rembClient->GetAvailableBitrate();
// TODO
consumer->UseBitrate();
} }
inline void WebRtcTransport::OnPacketRecv( inline void WebRtcTransport::OnPacketRecv(
...@@ -1370,16 +1350,6 @@ namespace RTC ...@@ -1370,16 +1350,6 @@ namespace RTC
// Tell the parent class. // Tell the parent class.
RTC::Transport::Connected(); 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*/) inline void WebRtcTransport::OnDtlsFailed(const RTC::DtlsTransport* /*dtlsTransport*/)
...@@ -1438,16 +1408,16 @@ namespace RTC ...@@ -1438,16 +1408,16 @@ namespace RTC
// NOTE: No DataChannel support, si just ignore it. // NOTE: No DataChannel support, si just ignore it.
} }
inline void WebRtcTransport::OnRembClientAvailableBitrate( inline void WebRtcTransport::OnRembClientIncreaseBitrate(
RTC::RembClient* /*rembClient*/, uint32_t availableBitrate) RTC::RembClient* /*rembClient*/, uint32_t /*bitrate*/)
{ {
MS_TRACE(); MS_TRACE();
// TODO // TODO
} }
inline void WebRtcTransport::OnRembClientExceedingBitrate( inline void WebRtcTransport::OnRembClientDecreaseBitrate(
RTC::RembClient* /*rembClient*/, uint32_t exceedingBitrate) RTC::RembClient* /*rembClient*/, uint32_t /*bitrate*/)
{ {
MS_TRACE(); MS_TRACE();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论