Skip to content

Commit

Permalink
wip: Send mediajson over a websocket.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev committed Oct 9, 2024
1 parent 002a475 commit 146e887
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 192 deletions.
25 changes: 22 additions & 3 deletions jvb/src/main/kotlin/org/jitsi/videobridge/export/Exporter.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
package org.jitsi.videobridge.export

import org.eclipse.jetty.websocket.api.WebSocketAdapter
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest
import org.eclipse.jetty.websocket.client.WebSocketClient
import org.jitsi.nlj.PacketInfo
import org.jitsi.nlj.rtp.AudioRtpPacket
import org.jitsi.utils.logging2.createLogger
import org.jitsi.videobridge.PotentialPacketHandler
import org.jitsi.videobridge.colibri2.FeatureNotImplementedException
import org.jitsi.videobridge.exporter.MediaJsonEncoder
import org.jitsi.videobridge.recorder.MediaJsonRecorder
import org.jitsi.videobridge.util.ByteBufferPool
import org.jitsi.videobridge.websocket.config.WebsocketServiceConfig
import org.jitsi.xmpp.extensions.colibri2.Export

class Exporter : PotentialPacketHandler {
val logger = createLogger()
var started = false

private val encoder = MediaJsonEncoder { recorder.handleEvent(it) }
private val recorder = MediaJsonRecorder()
private val encoder = MediaJsonEncoder {
if (recorderWebSocket.isConnected) {
recorderWebSocket.remote?.sendString(it.toXml()) ?:
logger.info("Websocket is connected, but remote is null?")
} else {
logger.info("Can not send packet, websocket is not connected.")
}
}
private var recorderWebSocket = WebSocketAdapter()

fun setExports(exports: List<Export>) {
when {
Expand All @@ -40,10 +50,19 @@ class Exporter : PotentialPacketHandler {
fun stop() {
started = false
logger.info("Stopping.")
recorderWebSocket.session?.close(org.eclipse.jetty.websocket.core.CloseStatus.SHUTDOWN, "closing")
}

fun start(export: Export) {
logger.info("Starting with url=${export.url}")
webSocketClient.connect(recorderWebSocket, export.url, ClientUpgradeRequest())
started = true
}

companion object {
val webSocketClient = WebSocketClient().apply {
idleTimeout = WebsocketServiceConfig.config.idleTimeout
start()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jitsi.videobridge.exporter

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.jitsi.mediajson.Event
import org.jitsi.mediajson.Media
import org.jitsi.mediajson.MediaEvent
Expand Down Expand Up @@ -30,15 +29,14 @@ class MediaJsonEncoder(

private val ssrcsStarted = mutableSetOf<SsrcState>()
var seq = 0
val om = jacksonObjectMapper()

fun encode(p: AudioRtpPacket, epId: String) = synchronized(ssrcsStarted) {
if (ssrcsStarted.none { it.ssrc == p.ssrc } ) {
val offset: Long = ((Duration.between(ref, Clock.systemUTC().instant())).toNanos() * 48.0e-6).toLong()
val state = SsrcState(p.ssrc, p.timestamp, offset)
ssrcsStarted.add(state)
val e = StartEvent(
(++seq).toString(),
++seq,
Start(
"$epId-${p.ssrc}",
MediaFormat(
Expand All @@ -61,11 +59,11 @@ class MediaJsonEncoder(
val elapsedRtpTime = this.timestamp - ssrcState.initialRtpTs
val ts = elapsedRtpTime + ssrcState.offset
val p = MediaEvent(
seq.toString(),
seq,
media = Media(
"$epId-${this.ssrc}",
this.sequenceNumber.toString(),
ts.toString(),
this.sequenceNumber,
ts,
Base64.encode(this.buffer, this.payloadOffset, this.payloadOffset + this.payloadLength)
)
)
Expand Down

This file was deleted.

112 changes: 0 additions & 112 deletions jvb/src/main/kotlin/org/jitsi/videobridge/recorder/MkaRecorder.kt

This file was deleted.

38 changes: 0 additions & 38 deletions jvb/src/test/kotlin/org/jitsi/videobridge/recorder/RecorderTest.kt

This file was deleted.

0 comments on commit 146e887

Please sign in to comment.