<commit_before>package org.jitsi.jibri

import com.fasterxml.jackson.databind.util.JSONPObject
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.jitsi.jibri.capture.Capturer
import org.jitsi.jibri.capture.CapturerParams
import org.jitsi.jibri.util.ProcessMonitor
import org.jitsi.jibri.capture.ffmpeg.FfmpegCapturer
import org.jitsi.jibri.capture.pjsua.PjSuaCapturer
import org.jitsi.jibri.config.JibriConfig
import org.jitsi.jibri.health.JibriHealth
import org.jitsi.jibri.selenium.JibriSelenium
import org.jitsi.jibri.selenium.JibriSeleniumOptions
import org.jitsi.jibri.sink.Recording
import org.jitsi.jibri.sink.Stream
import java.io.File
import java.io.FileNotFoundException

/**
 * The main Jibri interface
 * Methods here are not thread safe, and should only be called from
 * the same thread
 */
class Jibri {
    private lateinit var jibriSelenium: JibriSelenium
    private lateinit var capturer: Capturer
    private lateinit var capturerMonitor: ProcessMonitor
    private lateinit var config: JibriConfig

    // TODO: force a (successful) call of this in ctor?
    fun loadConfig(configFilePath: String)
    {
        val mapper = jacksonObjectMapper()
        try {
            config = mapper.readValue<JibriConfig>(File(configFilePath))
        } catch (e: FileNotFoundException) {
            println("Unable to read config file ${configFilePath}")
            return
        }
        println("Read config: \n ${config}")
    }

    /**
     * Start a recording session
     */
    fun startRecording(jibriOptions: JibriOptions)
    {
        println("Starting a recording, options: $jibriOptions")
        val sink = if (jibriOptions.recordingMode == RecordingMode.STREAM) {
            Stream(jibriOptions.streamUrl!!, 2976, 2976 * 2)
        } else {
            Recording(recordingsDirectory = File(config.recordingDirectory), callName = jibriOptions.callName)
        }

        println("Starting selenium")
        //TODO: get url from somewhere
        jibriSelenium = JibriSelenium(JibriSeleniumOptions(baseUrl = "https://meet.jit.si"))
        println("joining call")
        jibriSelenium.joinCall(jibriOptions.callName)
        // start ffmpeg or pjsua (how does pjsua work here?)
        capturer = if(jibriOptions.useSipGateway) PjSuaCapturer() else FfmpegCapturer()
        println("Starting capturer")<commit_msg>add comment about handling null for lateinit-style members<commit_after>package org.jitsi.jibri

import com.fasterxml.jackson.databind.util.JSONPObject
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.jitsi.jibri.capture.Capturer
import org.jitsi.jibri.capture.CapturerParams
import org.jitsi.jibri.util.ProcessMonitor
import org.jitsi.jibri.capture.ffmpeg.FfmpegCapturer
import org.jitsi.jibri.capture.pjsua.PjSuaCapturer
import org.jitsi.jibri.config.JibriConfig
import org.jitsi.jibri.health.JibriHealth
import org.jitsi.jibri.selenium.JibriSelenium
import org.jitsi.jibri.selenium.JibriSeleniumOptions
import org.jitsi.jibri.sink.Recording
import org.jitsi.jibri.sink.Stream
import java.io.File
import java.io.FileNotFoundException

/**
 * The main Jibri interface
 * Methods here are not thread safe, and should only be called from
 * the same thread
 */
class Jibri {
    private lateinit var jibriSelenium: JibriSelenium
    private lateinit var capturer: Capturer
    private lateinit var capturerMonitor: ProcessMonitor
    private lateinit var config: JibriConfig

    // TODO: force a (successful) call of this in ctor?
    fun loadConfig(configFilePath: String)
    {
        val mapper = jacksonObjectMapper()
        try {
            config = mapper.readValue<JibriConfig>(File(configFilePath))
        } catch (e: FileNotFoundException) {
            println("Unable to read config file ${configFilePath}")
            return
        }
        println("Read config: \n ${config}")
    }

    /**
     * Start a recording session
     */
    fun startRecording(jibriOptions: JibriOptions)
    {
        println("Starting a recording, options: $jibriOptions")
        val sink = if (jibriOptions.recordingMode == RecordingMode.STREAM) {
            Stream(jibriOptions.streamUrl!!, 2976, 2976 * 2)
        } else {
            Recording(recordingsDirectory = File(config.recordingDirectory), callName = jibriOptions.callName)
        }

        println("Starting selenium")
        //TODO: get url from somewhere
        //TODO: how best to deal with jibriSelenium (and capturer and
        // captureMonitor)?  they are
        // member values and cannot be initialized right away so:
        // 1) could use lateinit, but other code might try to access it before it
        //  is initialized (like if stop was called before start)
        // 2) could mark every call with ?., but we do need to cover the 'else'
        //  case there (if the instance is null for some reason, we should just return)
        // 3) could introduce a new variable that we know is non-null
        //  and use that (introducing another variable is a bummer i think)
        // in every case, if we handle failure for one step we need to make sure
        //  to do any cleanup necessary
        jibriSelenium = JibriSelenium(JibriSeleniumOptions(baseUrl = "https://meet.jit.si"))
        println("joining call")
        jibriSelenium.joinCall(jibriOptions.callName)
        // start ffmpeg or pjsua (how does pjsua work here?)
        capturer = if(jibriOptions.useSipGateway) PjSuaCapturer() else FfmpegCapturer()
        println("Starting capturer")
{'fraction_non_alphanumeric': 0.0856637168141593, 'fraction_numerical': 0.0037168141592920354, 'mean_word_length': 3.2234678624813156, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '4654565', 'n_tokens_mistral': 1808, 'n_tokens_neox': 1738, 'n_words': 446}