Skip to content

Commit

Permalink
feat: Add an endpoint_id tag to mka tracks. (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev authored Oct 23, 2024
1 parent c051836 commit 28e046e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<kotlin.version>2.0.21</kotlin.version>
<exec.mainClass>org.jitsi.recorder.MainKt</exec.mainClass>
<kotest.version>5.9.1</kotest.version>
<jicoco.version>1.1-143-g175c44b</jicoco.version>
<jicoco.version>1.1-144-ga2c5ec1</jicoco.version>
<ktor.version>3.0.0</ktor.version>
<ktlint.version>3.0.0</ktlint.version>
<surefire.version>3.5.1</surefire.version>
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/org/jitsi/recorder/MediaJsonRecorder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import java.time.Clock
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi

sealed class MediaJsonRecorder(directory: File) {
sealed class MediaJsonRecorder {
abstract fun addEvent(event: Event)
abstract fun stop()
}

class MediaJsonJsonRecorder(directory: File) : MediaJsonRecorder(directory) {
class MediaJsonJsonRecorder(directory: File) : MediaJsonRecorder() {
private val file: File = File(directory, "recording.json")
private val writer: BufferedWriter = BufferedWriter(FileWriter(file, true))

Expand All @@ -54,7 +54,7 @@ enum class RecordingFormat {
JSON
}

class MediaJsonMkaRecorder(directory: File) : MediaJsonRecorder(directory) {
class MediaJsonMkaRecorder(directory: File) : MediaJsonRecorder() {
private val logger = createLogger()

init {
Expand All @@ -77,7 +77,7 @@ class MediaJsonMkaRecorder(directory: File) : MediaJsonRecorder(directory) {
// split, buffer, generate silence. thread model? queue. metrics?
is StartEvent -> {
logger.info("Start new stream: $event")
mkaRecorder.startTrack(event.start.tag)
mkaRecorder.startTrack(event.start.tag, event.start.customParameters?.endpointId)
}

is MediaEvent -> {
Expand Down
20 changes: 18 additions & 2 deletions src/main/kotlin/org/jitsi/recorder/MkaRecorder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package org.jitsi.recorder

import org.ebml.io.FileDataWriter
import org.ebml.matroska.MatroskaFileFrame
import org.ebml.matroska.MatroskaFileSimpleTag
import org.ebml.matroska.MatroskaFileTagEntry
import org.ebml.matroska.MatroskaFileTrack
import org.ebml.matroska.MatroskaFileTrack.TrackType
import org.ebml.matroska.MatroskaFileWriter
Expand All @@ -37,8 +39,8 @@ class MkaRecorder(directory: File) {
private val tracks = mutableMapOf<String, MatroskaFileTrack>()
private var initialTimestampMs = -1L

fun startTrack(name: String) {
logger.info("Starting new track")
fun startTrack(name: String, endpointId: String? = null) {
logger.info("Starting new track $name, endpointId=$endpointId")
val track = MatroskaFileTrack().apply {
trackNo = tracks.size + 1
trackUID = trackNo.toLong()
Expand All @@ -56,6 +58,20 @@ class MkaRecorder(directory: File) {
}
tracks[name] = track
writer.addTrack(track)

if (endpointId != null) {
writer.addTag(
MatroskaFileTagEntry().apply {
trackUID.add(track.trackUID)
simpleTags.add(
MatroskaFileSimpleTag().apply {
this.name = "endpoint_id"
value = endpointId
}
)
}
)
}
}

fun addFrame(trackName: String, timestampRtp: Long, payload: ByteArray) {
Expand Down

0 comments on commit 28e046e

Please sign in to comment.