<commit_before>/*
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jitsi.impl.neomedia.rtp;

import org.jitsi.impl.neomedia.rtp.translator.*;
import org.jitsi.service.configuration.*;
import org.jitsi.service.libjitsi.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.util.*;

/**
 * Represents a collection of {@link RTPEncodingDesc}s that encode the same
 * media source. This specific implementation provides webrtc simulcast stream
 * suspension detection.
 *
 * @author <NAME>
 */
public class MediaStreamTrackDesc
{
    /**
     * The system property name that holds the maximum frequency (in millis) at
     * which the media engine generates key frame.
     *
     * We take that into account to identify batches of key frames which helps
     * us identify which simulcast flows are active/inactive.
     */
    public static final String MIN_KEY_FRAME_WAIT_MS_PNAME
        = "org.jitsi.impl.neomedia.rtp.MediaStreamTrackDesc" +
            ".MIN_KEY_FRAME_WAIT_MS";

    /**
     * The system property name that holds the maximum time interval (in millis)
     * an encoding can be considered active without new frames.
     */
    public static final String SUSPENSION_THRESHOLD_MS_PNAME
        = "org.jitsi.impl.neomedia.rtp.MediaStreamTrackDesc" +
            ".SUSPENSION_THRESHOLD_MS";

    /**
     * The default maximum frequency (in millis) at which the media engine
     * generates key frame.
     */
    private static final int MIN_KEY_FRAME_WAIT_MS_DEFAULT = 300;

    /**
     * The default maximum time interval (in millis) an encoding can be
     * considered active without new frames.
     */
    private static final int SUSPENSION_THRESHOLD_MS_DEFAULT = 600;

    /**
     * The {@link Logger} used by the {@link MediaStreamTrackDesc} class and its
     * instances for logging output.
     */
    private static final Logger logger
        = Logger.getLogger(MediaStreamTrackDesc.class);

    /**
     * The ConfigurationService to get config values from.
     */
    private static final ConfigurationService
        cfg = LibJitsi.getConfigurationService();

    /**
     * The minimum time (in millis) that is required for the media engine to
     * generate a new key frame (or, equivalently, the maximum frequency at
     * which the media engine generates key frame).
     */
    private static final int MIN_KEY_FRAME_WAIT_MS = cfg != null ? cfg.getInt(
        MIN_KEY_FRAME_WAIT_MS_PNAME, MIN_KEY_FRAME_WAIT_MS_DEFAULT)
        : MIN_KEY_FRAME_WAIT_MS_DEFAULT;

    /**
     * The maximum time interval (in millis) an encoding can be considered
     * active without new frames.
     */
    public static final int SUSPENSION_THRESHOLD_MS = cfg != null ? cfg.getInt(
        SUSPENSION_THRESHOLD_MS_PNAME, SUSPENSION_THRESHOLD_MS_DEFAULT)
        : SUSPENSION_THRESHOLD_MS_DEFAULT;

    /**
     * The {@link RTPEncodingDesc}s that this {@link MediaStreamTrackDesc}
     * possesses, ordered by their subjective quality from low to high.
     */
    private final RTPEncodingDesc[] rtpEncodings;

    /**
     * The {@link MediaStreamTrackReceiver} that receives this instance.
     */
    private final MediaStreamTrackReceiver mediaStreamTrackReceiver;

    /**
     * We have a bunch of code that is dealing with simulcast. Specifically,
     * we want to detect stream suspension so that we can switch to a lower
     * stream. If we're not using simulcast, we want to disable this code.
     */
    private final boolean simulcast;

    /**
     * Stats for this {@link MediaStreamTrackDesc} instance.
     */
    private final Statistics statistics = new Statistics();

    /**
     * Ctor.
     *
     * @param mediaStreamTrackReceiver The {@link MediaStreamTrackReceiver} that
     * receives this instance.
     * @param rtpEncodings The {@link RTPEncodingDesc}s that this instance
     * possesses.
     * @param simulcast true to enable simulcast logic, false otherwise
     */
    public MediaStreamTrackDesc(
        MediaStreamTrackReceiver mediaStreamTrackReceiver,
        RTPEncodingDesc[] rtpEncodings, boolean simulcast)
    {
        this.rtpEncodings = rtpEncodings;
        this.mediaStreamTrackReceiver = mediaStreamTrackReceiver;
        this.simulcast = simulcast;
    }

    /**
     * Gets the stats for this {@link MediaStreamTrackDesc} instance.
     *
     * @return gets the stats for this {@link MediaStreamTrackDesc} instance.
     */
    public Statistics getStatistics()
    {
        return statistics;
    }

    /**
     * Returns an array of all the {@link RTPEncodingDesc}s for this instance,
     * in subjective quality ascending order.
     *
     * @return an array of all the {@link RTPEncodingDesc}s for this instance,
     * in subjective quality ascending order.
     */
    public RTPEncodingDesc[] getRTPEncodings()
    {
        return rtpEncodings;<commit_msg>feat: Adds an "owner" field to MediaStreamTrackDesc.<commit_after>/*
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jitsi.impl.neomedia.rtp;

import org.jitsi.impl.neomedia.rtp.translator.*;
import org.jitsi.service.configuration.*;
import org.jitsi.service.libjitsi.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.util.*;

/**
 * Represents a collection of {@link RTPEncodingDesc}s that encode the same
 * media source. This specific implementation provides webrtc simulcast stream
 * suspension detection.
 *
 * @author <NAME>
 */
public class MediaStreamTrackDesc
{
    /**
     * The system property name that holds the maximum frequency (in millis) at
     * which the media engine generates key frame.
     *
     * We take that into account to identify batches of key frames which helps
     * us identify which simulcast flows are active/inactive.
     */
    public static final String MIN_KEY_FRAME_WAIT_MS_PNAME
        = "org.jitsi.impl.neomedia.rtp.MediaStreamTrackDesc" +
            ".MIN_KEY_FRAME_WAIT_MS";

    /**
     * The system property name that holds the maximum time interval (in millis)
     * an encoding can be considered active without new frames.
     */
    public static final String SUSPENSION_THRESHOLD_MS_PNAME
        = "org.jitsi.impl.neomedia.rtp.MediaStreamTrackDesc" +
            ".SUSPENSION_THRESHOLD_MS";

    /**
     * The default maximum frequency (in millis) at which the media engine
     * generates key frame.
     */
    private static final int MIN_KEY_FRAME_WAIT_MS_DEFAULT = 300;

    /**
     * The default maximum time interval (in millis) an encoding can be
     * considered active without new frames.
     */
    private static final int SUSPENSION_THRESHOLD_MS_DEFAULT = 600;

    /**
     * The {@link Logger} used by the {@link MediaStreamTrackDesc} class and its
     * instances for logging output.
     */
    private static final Logger logger
        = Logger.getLogger(MediaStreamTrackDesc.class);

    /**
     * The ConfigurationService to get config values from.
     */
    private static final ConfigurationService
        cfg = LibJitsi.getConfigurationService();

    /**
     * The minimum time (in millis) that is required for the media engine to
     * generate a new key frame (or, equivalently, the maximum frequency at
     * which the media engine generates key frame).
     */
    private static final int MIN_KEY_FRAME_WAIT_MS = cfg != null ? cfg.getInt(
        MIN_KEY_FRAME_WAIT_MS_PNAME, MIN_KEY_FRAME_WAIT_MS_DEFAULT)
        : MIN_KEY_FRAME_WAIT_MS_DEFAULT;

    /**
     * The maximum time interval (in millis) an encoding can be considered
     * active without new frames.
     */
    public static final int SUSPENSION_THRESHOLD_MS = cfg != null ? cfg.getInt(
        SUSPENSION_THRESHOLD_MS_PNAME, SUSPENSION_THRESHOLD_MS_DEFAULT)
        : SUSPENSION_THRESHOLD_MS_DEFAULT;

    /**
     * The {@link RTPEncodingDesc}s that this {@link MediaStreamTrackDesc}
     * possesses, ordered by their subjective quality from low to high.
     */
    private final RTPEncodingDesc[] rtpEncodings;

    /**
     * The {@link MediaStreamTrackReceiver} that receives this instance.
     */
    private final MediaStreamTrackReceiver mediaStreamTrackReceiver;

    /**
     * We have a bunch of code that is dealing with simulcast. Specifically,
     * we want to detect stream suspension so that we can switch to a lower
     * stream. If we're not using simulcast, we want to disable this code.
     */
    private final boolean simulcast;

    /**
     * Stats for this {@link MediaStreamTrackDesc} instance.
     */
    private final Statistics statistics = new Statistics();

    /**
     * A string which identifies the owner of this track (e.g. the endpoint
     * which is the sender of the track).
     */
    private final String owner;

    /**
     * Ctor.
     *
     * @param mediaStreamTrackReceiver The {@link MediaStreamTrackReceiver} that
     * receives this instance.
     * @param rtpEncodings The {@link RTPEncodingDesc}s that this instance
     * possesses.
     * @param simulcast true to enable simulcast logic, false otherwise
     */
    public MediaStreamTrackDesc(
        MediaStreamTrackReceiver mediaStreamTrackReceiver,
        RTPEncodingDesc[] rtpEncodings,
        boolean simulcast)
    {
        this(mediaStreamTrackReceiver, rtpEncodings, simulcast, null);
    }

    /**
     * Ctor.
     *
     * @param mediaStreamTrackReceiver The {@link MediaStreamTrackReceiver} that
     * receives this instance.
     * @param rtpEncodings The {@link RTPEncodingDesc}s that this instance
     * possesses.
     * @param simulcast true to enable simulcast logic, false otherwise
     */
    public MediaStreamTrackDesc(
        MediaStreamTrackReceiver mediaStreamTrackReceiver,
        RTPEncodingDesc[] rtpEncodings,
        boolean simulcast,
        String owner)
    {
        this.rtpEncodings = rtpEncodings;
        this.mediaStreamTrackReceiver = mediaStreamTrackReceiver;
        this.simulcast = simulcast;
        this.owner = owner;
    }

    /**
     * @return the identifier of the owner of this track.
     */
    public String getOwner()
    {
        return owner;
    }

    /**
     * Gets the stats for this {@link MediaStreamTrackDesc} instance.
     *
     * @return gets the stats for this {@link MediaStreamTrackDesc} instance.
     */
    public Statistics getStatistics()
    {
        return statistics;
    }

    /**
     * Returns an array of all the {@link RTPEncodingDesc}s for this instance,
     * in subjective quality ascending order.
     *
     * @return an array of all the {@link RTPEncodingDesc}s for this instance,
     * in subjective quality ascending order.
     */
    public RTPEncodingDesc[] getRTPEncodings()
    {
        return rtpEncodings;
{'fraction_non_alphanumeric': 0.07411485685244791, 'fraction_numerical': 0.002371675419278333, 'mean_word_length': 2.901850627891606, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1214945', 'n_tokens_mistral': 3306, 'n_tokens_neox': 3233, 'n_words': 1140}