<commit_before>#ifndef MS_RTC_CONSUMER_HPP
#define MS_RTC_CONSUMER_HPP

#include "common.hpp"
#include "Channel/Notifier.hpp"
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/ConsumerListener.hpp"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/FeedbackRtpNack.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/Sdes.hpp"
#include "RTC/RtpDataCounter.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpStreamSend.hpp"
#include "RTC/SeqManager.hpp"
#include "RTC/Transport.hpp"
#include <json/json.h>
#include <set>
#include <unordered_set>

namespace RTC
{
	class Consumer : public RtpStream::Listener
	{
	public:
		Consumer(
		  Channel::Notifier* notifier,
		  uint32_t consumerId,
		  RTC::Media::Kind kind,
		  uint32_t sourceProducerId);

	private:
		virtual ~Consumer();

	public:
		void Destroy();
		Json::Value ToJson() const;
		void AddListener(RTC::ConsumerListener* listener);
		void RemoveListener(RTC::ConsumerListener* listener);
		void Enable(RTC::Transport* transport, RTC::RtpParameters& rtpParameters);
		void Pause();
		void Resume();
		void SourcePause();
		void SourceResume();
		void AddProfile(const RTC::RtpEncodingParameters::Profile profile);
		void RemoveProfile(const RTC::RtpEncodingParameters::Profile profile);
		void SourceRtpParametersUpdated();
		void SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile);
		void Disable();
		bool IsEnabled() const;
		const RTC::RtpParameters& GetParameters() const;
		bool IsPaused() const;
		void SendRtpPacket(RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile);
		void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
		void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket);
		void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
		uint32_t GetTransmissionRate(uint64_t now);
		void RequestKeyFrame();

	private:
		void FillSupportedCodecPayloadTypes();
		void CreateRtpStream(RTC::RtpEncodingParameters& encoding);
		void RetransmitRtpPacket(RTC::RtpPacket* packet);
		void RecalculateTargetProfile();
		void SetEffectiveProfile(RTC::RtpEncodingParameters::Profile profile);

		/* Pure virtual methods inherited from RTC::RtpStream::Listener. */
	public:
		void OnRtpStreamDied(RTC::RtpStream* rtpStream) override;
		void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) override;
		void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) override;

	public:
		// Passed by argument.
		uint32_t consumerId{ 0 };
		RTC::Media::Kind kind;
		uint32_t sourceProducerId{ 0 };

	private:
		// Passed by argument.
		Channel::Notifier* notifier{ nullptr };
		RTC::Transport* transport{ nullptr };
		RTC::RtpParameters rtpParameters;
		std::unordered_set<RTC::ConsumerListener*> listeners;
		// Allocated by this.
		RTC::RtpStreamSend* rtpStream{ nullptr };
		// Others.
		std::unordered_set<uint8_t> supportedCodecPayloadTypes;
		bool paused{ false };
		bool sourcePaused{ false };
		// Timestamp when last RTCP was sent.
		uint64_t lastRtcpSentTime{ 0 };
		uint16_t maxRtcpInterval{ 0 };
		// RTP counters.
		RTC::RtpDataCounter retransmittedCounter;
		// RTP sequence number and timestamp.
		RTC::SeqManager<uint16_t> rtpSeqManager;
		RTC::SeqManager<uint32_t> rtpTimestampManager;
		bool syncRequired{ true };
		std::unique_ptr<RTC::Codecs::EncodingContext> encodingContext;

		// RTP profiles.
		std::set<RTC::RtpEncodingParameters::Profile> profiles;
		RTC::RtpEncodingParameters::Profile preferredProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
		RTC::RtpEncodingParameters::Profile targetProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
		RTC::RtpEncodingParameters::Profile effectiveProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
	};

	/* Inline methods. */

	inline void Consumer::AddListener(RTC::ConsumerListener* listener)
	{
		this->listeners.insert(listener);
	}

	inline void Consumer::RemoveListener(RTC::ConsumerListener* listener)
	{
		this->listeners.erase(listener);
	}

	inline bool Consumer::IsEnabled() const<commit_msg>Add missing comment<commit_after>#ifndef MS_RTC_CONSUMER_HPP
#define MS_RTC_CONSUMER_HPP

#include "common.hpp"
#include "Channel/Notifier.hpp"
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/ConsumerListener.hpp"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/FeedbackRtpNack.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/Sdes.hpp"
#include "RTC/RtpDataCounter.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpStreamSend.hpp"
#include "RTC/SeqManager.hpp"
#include "RTC/Transport.hpp"
#include <json/json.h>
#include <set>
#include <unordered_set>

namespace RTC
{
	class Consumer : public RtpStream::Listener
	{
	public:
		Consumer(
		  Channel::Notifier* notifier,
		  uint32_t consumerId,
		  RTC::Media::Kind kind,
		  uint32_t sourceProducerId);

	private:
		virtual ~Consumer();

	public:
		void Destroy();
		Json::Value ToJson() const;
		void AddListener(RTC::ConsumerListener* listener);
		void RemoveListener(RTC::ConsumerListener* listener);
		void Enable(RTC::Transport* transport, RTC::RtpParameters& rtpParameters);
		void Pause();
		void Resume();
		void SourcePause();
		void SourceResume();
		void AddProfile(const RTC::RtpEncodingParameters::Profile profile);
		void RemoveProfile(const RTC::RtpEncodingParameters::Profile profile);
		void SourceRtpParametersUpdated();
		void SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile);
		void Disable();
		bool IsEnabled() const;
		const RTC::RtpParameters& GetParameters() const;
		bool IsPaused() const;
		void SendRtpPacket(RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile);
		void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
		void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket);
		void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
		uint32_t GetTransmissionRate(uint64_t now);
		void RequestKeyFrame();

	private:
		void FillSupportedCodecPayloadTypes();
		void CreateRtpStream(RTC::RtpEncodingParameters& encoding);
		void RetransmitRtpPacket(RTC::RtpPacket* packet);
		void RecalculateTargetProfile();
		void SetEffectiveProfile(RTC::RtpEncodingParameters::Profile profile);

		/* Pure virtual methods inherited from RTC::RtpStream::Listener. */
	public:
		void OnRtpStreamDied(RTC::RtpStream* rtpStream) override;
		void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) override;
		void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) override;

	public:
		// Passed by argument.
		uint32_t consumerId{ 0 };
		RTC::Media::Kind kind;
		uint32_t sourceProducerId{ 0 };

	private:
		// Passed by argument.
		Channel::Notifier* notifier{ nullptr };
		RTC::Transport* transport{ nullptr };
		RTC::RtpParameters rtpParameters;
		std::unordered_set<RTC::ConsumerListener*> listeners;
		// Allocated by this.
		RTC::RtpStreamSend* rtpStream{ nullptr };
		// Others.
		std::unordered_set<uint8_t> supportedCodecPayloadTypes;
		bool paused{ false };
		bool sourcePaused{ false };
		// Timestamp when last RTCP was sent.
		uint64_t lastRtcpSentTime{ 0 };
		uint16_t maxRtcpInterval{ 0 };
		// RTP counters.
		RTC::RtpDataCounter retransmittedCounter;
		// RTP sequence number and timestamp.
		RTC::SeqManager<uint16_t> rtpSeqManager;
		RTC::SeqManager<uint32_t> rtpTimestampManager;
		bool syncRequired{ true };
		// RTP payload descriptor encoding.
		std::unique_ptr<RTC::Codecs::EncodingContext> encodingContext;

		// RTP profiles.
		std::set<RTC::RtpEncodingParameters::Profile> profiles;
		RTC::RtpEncodingParameters::Profile preferredProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
		RTC::RtpEncodingParameters::Profile targetProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
		RTC::RtpEncodingParameters::Profile effectiveProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
	};

	/* Inline methods. */

	inline void Consumer::AddListener(RTC::ConsumerListener* listener)
	{
		this->listeners.insert(listener);
	}

	inline void Consumer::RemoveListener(RTC::ConsumerListener* listener)
	{
		this->listeners.erase(listener);
	}

	inline bool Consumer::IsEnabled() const
{'fraction_non_alphanumeric': 0.11989733561476412, 'fraction_numerical': 0.0065998533365925205, 'mean_word_length': 6.473059360730594, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6865099', 'n_tokens_mistral': 2887, 'n_tokens_neox': 2551, 'n_words': 529}