<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.transform;

import org.jitsi.impl.neomedia.*;
import org.jitsi.service.neomedia.rtp.*;
import org.jitsi.impl.neomedia.rtp.remotebitrateestimator.*;
import org.jitsi.util.*;

import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;

/**
 * Implements a cache of outgoing RTP packets.
 * @author <NAME>
 */
public class CachingTransformer
    extends SinglePacketTransformerAdapter
    implements RawPacketCache,
               TransformEngine,
               RecurringProcessible
{
    /**
     * The <tt>Logger</tt> used by the <tt>CachingTransformer</tt> class and
     * its instances to print debug information.
     */
    private static final Logger logger
            = Logger.getLogger(CachingTransformer.class);

    /**
     * The <tt>RecurringProcessibleExecutor</tt> to be utilized by the
     * <tt>CachingTransformer</tt> class and its instances.
     */
    private static final RecurringProcessibleExecutor
        recurringProcessibleExecutor = new RecurringProcessibleExecutor();

    /**
     * The period of time between calls to {@link #process} will be requested
     * if this {@link CachingTransformer} is enabled.
     */
    private static final int PROCESS_INTERVAL_MS = 10000;

    /**
     * Packets added to the cache more than <tt>SIZE_MILLIS</tt> ago might be
     * cleared from the cache.
     */
    private static int SIZE_MILLIS = 500;

    /**
     * Assumed rate of the RTP clock.
     */
    private static int RTP_CLOCK_RATE = 90000;

    /**
     * <tt>SIZE_MILLIS</tt> expressed as a number of ticks on the RTP clock.
     */
    private static int SIZE_RTP_CLOCK_TICKS
            = (RTP_CLOCK_RATE / 1000) * SIZE_MILLIS;

    /**
     * The maximum number of different SSRCs for which a cache will be created.
     */
    private static int MAX_SSRC_COUNT = 50;

    /**
     * The maximum number of packets cached for each SSRC.
     */
    private static int MAX_SIZE_PACKETS = 200;

    /**
     * The size of {@link #pool}.
     */
    private static int POOL_SIZE = 100;

    /**
     * The amount of time, after which the cache for an SSRC will be cleared,
     * unless new packets have been inserted.
     */
    private static int SSRC_TIMEOUT_MILLIS = SIZE_MILLIS + 50;

    /**
     * Returns <tt>true</tt> iff <tt>a</tt> is less than <tt>b</tt> modulo 2^32.
     */
    private static boolean lessThanTS(long a, long b)
    {
        if (a == b)
            return false;
        else if (a > b)
            return a - b >= (1L << 31);
        else //a < b
            return b - a < (1L << 31);
    }<commit_msg>Using ConfigurationService to read caching properties from config file<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.transform;

import org.jitsi.impl.neomedia.*;
import org.jitsi.service.configuration.ConfigurationService;
import org.jitsi.service.libjitsi.LibJitsi;
import org.jitsi.service.neomedia.rtp.*;
import org.jitsi.impl.neomedia.rtp.remotebitrateestimator.*;
import org.jitsi.util.*;

import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;

/**
 * Implements a cache of outgoing RTP packets.
 * @author <NAME>
 */
public class CachingTransformer
    extends SinglePacketTransformerAdapter
    implements RawPacketCache,
               TransformEngine,
               RecurringProcessible
{
    /**
     * The <tt>Logger</tt> used by the <tt>CachingTransformer</tt> class and
     * its instances to print debug information.
     */
    private static final Logger logger
            = Logger.getLogger(CachingTransformer.class);

    /**
     * The <tt>RecurringProcessibleExecutor</tt> to be utilized by the
     * <tt>CachingTransformer</tt> class and its instances.
     */
    private static final RecurringProcessibleExecutor
        recurringProcessibleExecutor = new RecurringProcessibleExecutor();

    /**
     * The <tt>ConfigurationService</tt> used to load caching configuration.
     */
    private static final ConfigurationService cfg = LibJitsi.getConfigurationService();

    /**
     * Configuration property for number of streams to cache
     */
    public final static String NACK_CACHE_SIZE_STREAMS
            = "net.java.sip.communicator.nack.CACHE_SIZE_STREAMS";

    /**
     * Configuration property number of packets to cache.
     */
    public final static String NACK_CACHE_SIZE_PACKETS
            = "net.java.sip.communicator.nack.CACHE_SIZE_PACKETS";

    /**
     * Configuration property for nack cache size in milliseconds.
     */
    public final static String NACK_CACHE_SIZE_MILLIS
            = "net.java.sip.communicator.nack.CACHE_SIZE_MILLIS";


    /**
     * The period of time between calls to {@link #process} will be requested
     * if this {@link CachingTransformer} is enabled.
     */
    private static final int PROCESS_INTERVAL_MS = 10000;

    /**
     * Packets added to the cache more than <tt>SIZE_MILLIS</tt> ago might be
     * cleared from the cache.
     */
    private static int SIZE_MILLIS = cfg.getInt(NACK_CACHE_SIZE_MILLIS, 500);

    /**
     * Assumed rate of the RTP clock.
     */
    private static int RTP_CLOCK_RATE = 90000;

    /**
     * <tt>SIZE_MILLIS</tt> expressed as a number of ticks on the RTP clock.
     */
    private static int SIZE_RTP_CLOCK_TICKS
            = (RTP_CLOCK_RATE / 1000) * SIZE_MILLIS;

    /**
     * The maximum number of different SSRCs for which a cache will be created.
     */
    private static int MAX_SSRC_COUNT = cfg.getInt(NACK_CACHE_SIZE_STREAMS, 50);

    /**
     * The maximum number of packets cached for each SSRC.
     */
    private static int MAX_SIZE_PACKETS = cfg.getInt(NACK_CACHE_SIZE_PACKETS, 200);

    /**
     * The size of {@link #pool}.
     */
    private static int POOL_SIZE = 100;

    /**
     * The amount of time, after which the cache for an SSRC will be cleared,
     * unless new packets have been inserted.
     */
    private static int SSRC_TIMEOUT_MILLIS = SIZE_MILLIS + 50;

    /**
     * Returns <tt>true</tt> iff <tt>a</tt> is less than <tt>b</tt> modulo 2^32.
     */
    private static boolean lessThanTS(long a, long b)
    {
        if (a == b)
            return false;
        else if (a > b)
            return a - b >= (1L << 31);
        else //a < b
            return b - a < (1L << 31);
    }
{'fraction_non_alphanumeric': 0.09288171473934903, 'fraction_numerical': 0.011643291876157714, 'mean_word_length': 2.672983479105928, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 47, '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': '6035099', 'n_tokens_mistral': 2318, 'n_tokens_neox': 2190, 'n_words': 743}