<commit_before>/* 
 * File:   RTPData.h
 * Author: daniel
 *
 * Created on November 20, 2015, 10:46 AM
 */

#ifndef PARTICIPANT_DATABASE_H
#define	PARTICIPANT_DATABASE_H

#include <map>
#include <chrono>
#include <memory>
#include <vector>
#include <functional>
#include <mutex>
#include <string>

namespace ohmcomm
{
    namespace rtp
    {

        //Forward declaration for pointer to statistical and informational RTCP data
        struct RTCPData;

        /*!
         * Global data store for a single participant in an RTP session
         */
        struct Participant
        {
        private:
            //the last delay-value
            uint32_t lastDelay;
        public:
            const bool isLocalParticipant;
            //the SSRC of the participant
            const uint32_t ssrc;
            //the payload-type sent and received by this participant
            char payloadType;
            //the RTP timestamp of the first package sent by this participant
            uint32_t initialRTPTimestamp;
            //the currently highest sequence number sent by this participant
            uint32_t extendedHighestSequenceNumber;
            //the current estimated jitter between RTP packages sent by this participant, undefined for local participant
            double interarrivalJitter;
            //the timestamp of the reception of the last package (RTP/RTCP) sent by this participant, undefined for local user
            std::chrono::steady_clock::time_point lastPackageReceived;
            //the amount of packages lost originating from this participant
            uint32_t packagesLost;
            //the amount of packages received originating from this participant
            //equals the amount of packages sent for the local participant
            uint32_t totalPackages;
            //the total amount of octets/bytes sent/received for this participant
            uint32_t totalBytes;
            //the RTCP participant-data
            //we can't use reference/unique_ptr here, because RTCPData is incomplete at this point
            std::shared_ptr<RTCPData> rtcpData;

            Participant(const uint32_t ssrc, const bool localParticipant) : lastDelay(0), isLocalParticipant(localParticipant), ssrc(ssrc), payloadType(-1),
            initialRTPTimestamp(0), extendedHighestSequenceNumber(0), interarrivalJitter(0), lastPackageReceived(std::chrono::steady_clock::time_point::min()),
            packagesLost(0), totalPackages(0), totalBytes(0), rtcpData(nullptr)
            {

            }

            /*!
             * \return the fraction of packages lost in 1/256
             */
            inline uint8_t getFractionLost() const
            {
                return (long) (((double) packagesLost / (double) totalPackages) * 256);
            }

            /*!
             * Calculates and sets the new interarrival-jitter value
             * 
             * \param sentTimestamp The RTP timestamp (in remote clock) of the last package sent by this participant
             * 
             * \param receptionTimstamp The RTP timestamp (in local clock) of the reception of the last package sent by this participant
             * <commit_msg>Added Participant#firstPackageReceived to count duration of conversation Signed-off-by:doe300 <<EMAIL>><commit_after>/* 
 * File:   RTPData.h
 * Author: daniel
 *
 * Created on November 20, 2015, 10:46 AM
 */

#ifndef PARTICIPANT_DATABASE_H
#define	PARTICIPANT_DATABASE_H

#include <map>
#include <chrono>
#include <memory>
#include <vector>
#include <functional>
#include <mutex>
#include <string>

namespace ohmcomm
{
    namespace rtp
    {

        //Forward declaration for pointer to statistical and informational RTCP data
        struct RTCPData;

        /*!
         * Global data store for a single participant in an RTP session
         */
        struct Participant
        {
        private:
            //the last delay-value
            uint32_t lastDelay;
        public:
            const bool isLocalParticipant;
            //the SSRC of the participant
            const uint32_t ssrc;
            //the payload-type sent and received by this participant
            char payloadType;
            //the RTP timestamp of the first package sent by this participant
            uint32_t initialRTPTimestamp;
            //the currently highest sequence number sent by this participant
            uint32_t extendedHighestSequenceNumber;
            //the current estimated jitter between RTP packages sent by this participant, undefined for local participant
            double interarrivalJitter;
            //the timestamp of the reception of the last package (RTP/RTCP) sent by this participant, undefined for local user
            std::chrono::steady_clock::time_point lastPackageReceived;
            //the timestamp if the reception of the first package (RTP/RTCP) from this participant in the current session
            const std::chrono::steady_clock::time_point firstPackageReceived;
            //the amount of packages lost originating from this participant
            uint32_t packagesLost;
            //the amount of packages received originating from this participant
            //equals the amount of packages sent for the local participant
            uint32_t totalPackages;
            //the total amount of octets/bytes sent/received for this participant
            uint32_t totalBytes;
            //the RTCP participant-data
            //we can't use reference/unique_ptr here, because RTCPData is incomplete at this point
            std::shared_ptr<RTCPData> rtcpData;

            Participant(const uint32_t ssrc, const bool localParticipant) : lastDelay(0), isLocalParticipant(localParticipant), ssrc(ssrc), payloadType(-1),
            initialRTPTimestamp(0), extendedHighestSequenceNumber(0), interarrivalJitter(0), lastPackageReceived(std::chrono::steady_clock::time_point::min()),
            firstPackageReceived(std::chrono::steady_clock::now()), packagesLost(0), totalPackages(0), totalBytes(0), rtcpData(nullptr)
            {

            }

            /*!
             * \return the fraction of packages lost in 1/256
             */
            inline uint8_t getFractionLost() const
            {
                return (long) (((double) packagesLost / (double) totalPackages) * 256);
            }

            /*!
             * Calculates and sets the new interarrival-jitter value
             * 
             * \param sentTimestamp The RTP timestamp (in remote clock) of the last package sent by this participant
             * 
             * \param receptionTimstamp The RTP timestamp (in local clock) of the reception of the last package sent by this participant
             * 
{'fraction_non_alphanumeric': 0.06618300266508735, 'fraction_numerical': 0.012881255552265325, 'mean_word_length': 2.2617093191694835, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '7638743', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1636, 'n_words': 603}