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

import org.jitsi.service.configuration.ConfigurationService;
import org.jitsi.service.libjitsi.LibJitsi;
import org.jitsi.service.neomedia.MediaType;
import org.jitsi.service.neomedia.control.*;
import org.jitsi.service.neomedia.recording.*;
import org.jitsi.util.*;

import javax.media.*;
import javax.media.datasink.*;
import javax.media.format.*;
import javax.media.protocol.*;
import java.io.*;

/**
 * A <tt>DataSink</tt> implementation which writes output in webm format.
 *
 * @author <NAME>
 */
public class WebmDataSink
    implements DataSink,
               BufferTransferHandler
{
    /**
     * The <tt>Logger</tt> used by the <tt>WebmDataSink</tt> class and its
     * instances for logging output.
     */
    private static final Logger logger
            = Logger.getLogger(WebmDataSink.class);

    /**
     * Whether to generate a RECORDING_ENDED event when closing.
     */
    private static final boolean USE_RECORDING_ENDED_EVENTS = false;

    /**
     * The <tt>WebmWriter</tt> which we use to write the frames to a file.
     */
    private WebmWriter writer = null;

    private RecorderEventHandler eventHandler;
    private long ssrc = -1;

    /**
     * Whether this <tt>DataSink</tt> is open and should write to its
     * <tt>WebmWriter</tt>.
     */
    private boolean open = false;
    private final Object openCloseSyncRoot = new Object();

    /**
     * Whether we are in a state of waiting for a keyframe and discarding
     * non-key frames.
     */
    private boolean waitingForKeyframe = true;

    /**
     * The height of the video. Initialized on the first received keyframe.
     */
    private int height = 0;

    /**
     * The height of the video. Initialized on the first received keyframe.
     */
    private int width = 0;

    /**
     * A <tt>Buffer</tt> used to transfer frames.
     */
    private Buffer buffer = new Buffer();

    private WebmWriter.FrameDescriptor fd = new WebmWriter.FrameDescriptor();

    /**
     * Our <tt>DataSource</tt>.
     */
    private DataSource dataSource = null;

    /**
     * The name of the file into which we will write.
     */
    private String filename;

    /**
     * The RTP time stamp of the first frame written to the output webm file.
     */
    private long firstFrameRtpTimestamp = -1;

    /**
     * The time as returned by <tt>System.currentTimeMillis()</tt> of the first
     * frame written to the output webm file.
     */
    private long firstFrameTime = -1;

    /**
     * The PTS (presentation timestamp) of the last frame written to the output
     * file. In milliseconds.
     */
    private long lastFramePts = -1;

    /**
     * The <tt>KeyFrameControl</tt> which we will use to request a keyframe.
     */
    private KeyFrameControl keyFrameControl = null;

    /**
     * Whether we have already requested a keyframe.
     */
    private boolean keyframeRequested = false;

    private int framesSinceLastKeyframeRequest = 0;
    private static int REREQUEST_KEYFRAME_INTERVAL = 100;

    /**
     * Property name to control auto requesting keyframes periodically
     * to improve recording quality over low quality connection (e.g. proper
     * network speed, but high packet loss)
     */
    private static String AUTO_REQUEST_KEYFRAME_PNAME =
            WebmDataSink.class.getCanonicalName() + ".AUTOKEYFRAME";
    private int autoKeyframeRequestInterval = 0;


    /**
     * Initialize a new <tt>WebmDataSink</tt> instance.
     * @param filename the name of the file into which to write.
     * @param dataSource the <tt>DataSource</tt> to use.
     */
    public WebmDataSink(String filename, DataSource dataSource)
    {
        ConfigurationService cfg = LibJitsi.getConfigurationService();
        this.autoKeyframeRequestInterval =
                cfg.getInt(AUTO_REQUEST_KEYFRAME_PNAME, this.autoKeyframeRequestInterval);<commit_msg>Fixing import format and comment<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.recording;

import org.jitsi.service.configuration.*;
import org.jitsi.service.libjitsi.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.service.neomedia.control.*;
import org.jitsi.service.neomedia.recording.*;
import org.jitsi.util.*;

import javax.media.*;
import javax.media.datasink.*;
import javax.media.format.*;
import javax.media.protocol.*;
import java.io.*;

/**
 * A <tt>DataSink</tt> implementation which writes output in webm format.
 *
 * @author <NAME>
 */
public class WebmDataSink
    implements DataSink,
               BufferTransferHandler
{
    /**
     * The <tt>Logger</tt> used by the <tt>WebmDataSink</tt> class and its
     * instances for logging output.
     */
    private static final Logger logger
            = Logger.getLogger(WebmDataSink.class);

    /**
     * Whether to generate a RECORDING_ENDED event when closing.
     */
    private static final boolean USE_RECORDING_ENDED_EVENTS = false;

    /**
     * The <tt>WebmWriter</tt> which we use to write the frames to a file.
     */
    private WebmWriter writer = null;

    private RecorderEventHandler eventHandler;
    private long ssrc = -1;

    /**
     * Whether this <tt>DataSink</tt> is open and should write to its
     * <tt>WebmWriter</tt>.
     */
    private boolean open = false;
    private final Object openCloseSyncRoot = new Object();

    /**
     * Whether we are in a state of waiting for a keyframe and discarding
     * non-key frames.
     */
    private boolean waitingForKeyframe = true;

    /**
     * The height of the video. Initialized on the first received keyframe.
     */
    private int height = 0;

    /**
     * The height of the video. Initialized on the first received keyframe.
     */
    private int width = 0;

    /**
     * A <tt>Buffer</tt> used to transfer frames.
     */
    private Buffer buffer = new Buffer();

    private WebmWriter.FrameDescriptor fd = new WebmWriter.FrameDescriptor();

    /**
     * Our <tt>DataSource</tt>.
     */
    private DataSource dataSource = null;

    /**
     * The name of the file into which we will write.
     */
    private String filename;

    /**
     * The RTP time stamp of the first frame written to the output webm file.
     */
    private long firstFrameRtpTimestamp = -1;

    /**
     * The time as returned by <tt>System.currentTimeMillis()</tt> of the first
     * frame written to the output webm file.
     */
    private long firstFrameTime = -1;

    /**
     * The PTS (presentation timestamp) of the last frame written to the output
     * file. In milliseconds.
     */
    private long lastFramePts = -1;

    /**
     * The <tt>KeyFrameControl</tt> which we will use to request a keyframe.
     */
    private KeyFrameControl keyFrameControl = null;

    /**
     * Whether we have already requested a keyframe.
     */
    private boolean keyframeRequested = false;

    private int framesSinceLastKeyframeRequest = 0;
    private static int REREQUEST_KEYFRAME_INTERVAL = 100;

    /**
     * Property name to control auto requesting keyframes periodically
     * to improve seeking speed without re-encoding the file
     */
    private static String AUTO_REQUEST_KEYFRAME_PNAME =
            WebmDataSink.class.getCanonicalName() + ".AUTOKEYFRAME";
    private int autoKeyframeRequestInterval = 0;


    /**
     * Initialize a new <tt>WebmDataSink</tt> instance.
     * @param filename the name of the file into which to write.
     * @param dataSource the <tt>DataSource</tt> to use.
     */
    public WebmDataSink(String filename, DataSource dataSource)
    {
        ConfigurationService cfg = LibJitsi.getConfigurationService();
        this.autoKeyframeRequestInterval =
                cfg.getInt(AUTO_REQUEST_KEYFRAME_PNAME, this.autoKeyframeRequestInterval);
{'fraction_non_alphanumeric': 0.09097969599467436, 'fraction_numerical': 0.004216132253411739, 'mean_word_length': 2.7810402684563758, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, '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': '7388112', 'n_tokens_mistral': 2550, 'n_tokens_neox': 2501, 'n_words': 883}