Skip to content

Commit d5ddd07

Browse files
authored
Merge branch 'master' into dependabot/gradle/camerax-1.5.1
2 parents d2bd9a1 + 6016c56 commit d5ddd07

4 files changed

Lines changed: 16 additions & 2 deletions

File tree

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dokka = "2.0.0"
99
appcompat = "1.6.1"
1010
#noinspection GradleDependency, version 2.2.0 need min sdk 21
1111
constraintlayout = "2.1.4"
12-
ktor = "3.3.0"
12+
ktor = "3.3.1"
1313
camerax = "1.5.1"
1414
multidex = "2.0.1"
1515
annotation = "1.9.1"

srt/src/main/java/com/pedro/srt/srt/SrtClient.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ class SrtClient(private val connectChecker: ConnectChecker) {
236236

237237
commandsManager.writeHandshake(socket, response.copy(
238238
encryption = commandsManager.getEncryptType(),
239+
extensionField = ExtensionField.calculateValue(response.extensionField),
239240
handshakeType = HandshakeType.CONCLUSION,
240241
handshakeExtension = HandshakeExtension(
241242
flags = ExtensionContentFlag.TSBPDSND.value or ExtensionContentFlag.TSBPDRCV.value or

srt/src/main/java/com/pedro/srt/srt/packets/control/handshake/ExtensionField.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ import java.io.IOException
2222
* Created by pedro on 22/8/23.
2323
*/
2424
enum class ExtensionField(val value: Int) {
25-
HS_REQ(1), KM_REQ(2), CONFIG(4), HS_V5_MAGIC(18967);
25+
HS_V5_FLAG(131072), HS_REQ(1), KM_REQ(2), CONFIG(4), HS_V5_MAGIC(18967);
2626

2727
companion object {
2828
infix fun from(value: Int): ExtensionField = entries.firstOrNull { it.value == value } ?: throw IOException("unknown extension field: $value")
29+
30+
fun calculateValue(value: Int): Int {
31+
val hsV5enabled = value and HS_V5_FLAG.value != 0
32+
val extensionField = HS_REQ.value or CONFIG.value
33+
return if (hsV5enabled) HS_V5_FLAG.value or KM_REQ.value or extensionField else extensionField
34+
}
2935
}
3036
}

srt/src/test/java/com/pedro/srt/srt/control/HandshakeTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.pedro.srt.srt.packets.control.handshake.Handshake
2222
import com.pedro.srt.srt.packets.control.handshake.HandshakeType
2323
import com.pedro.srt.srt.packets.control.handshake.extension.ExtensionContentFlag
2424
import com.pedro.srt.srt.packets.control.handshake.extension.HandshakeExtension
25+
import junit.framework.TestCase.assertEquals
2526
import org.junit.Assert.assertArrayEquals
2627
import org.junit.Test
2728
import java.io.ByteArrayInputStream
@@ -31,6 +32,12 @@ import java.io.ByteArrayInputStream
3132
*/
3233
class HandshakeTest {
3334

35+
@Test
36+
fun `test extension field calculation`() {
37+
assertEquals(131079, ExtensionField.calculateValue(150039))
38+
assertEquals(5, ExtensionField.calculateValue(18967))
39+
}
40+
3441
@Test
3542
fun `GIVEN a handshake packet WHEN write packet in a buffer THEN get expected buffer`() {
3643
val expectedData = byteArrayOf(-128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -60, 0, 0, 0, 64, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 5, -36, 0, 0, 32, 0, -1, -1, -1, -1, 45, 116, -9, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 3, 0, 1, 5, 3, 0, 0, 0, 63, 0, 120, 0, 0, 0, 5, 0, 1, 116, 115, 101, 116)

0 commit comments

Comments
 (0)