Skip to content

Commit 92a0149

Browse files
committed
wip
1 parent f7445e9 commit 92a0149

File tree

12 files changed

+113
-57
lines changed

12 files changed

+113
-57
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ permissionsDispatcher = "4.9.2"
1111
[libraries]
1212
kotlin-stdlib-js = { module = "org.jetbrains.kotlin:kotlin-stdlib-js", version.ref = "kotlin" }
1313
kotlinx-serialization-json = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0"
14-
kmpXlog = "com.piasy:kmp-xlog:1.3.5"
14+
kmpXlog = "com.piasy:kmp-xlog:1.4.1"
1515
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
1616

1717
androidx-appcompat = "androidx.appcompat:appcompat:1.7.0"

kmp-webrtc/build.gradle.kts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,33 @@ kotlin {
6767
binaries {
6868
all {
6969
linkerOpts.addAll(listOf("-L${rootProject.projectDir}/libs/windows/x64", "-lwin_pc_client.dll"))
70+
//freeCompilerArgs = listOf("-Xadd-light-debug=enable")
7071
}
7172
sharedLib {
7273
baseName = "kmp_webrtc"
7374
}
7475
}
7576
}
7677

77-
// linuxX64 {}
78+
linuxX64 {
79+
compilations.getByName("main").cinterops {
80+
val webrtc by creating {
81+
definitionFile.set(project.file("src/cppCommon/cinterop/WebRTC.def"))
82+
includeDirs {
83+
allHeaders("${rootProject.projectDir}/libs/windows_linux/include")
84+
}
85+
}
86+
}
87+
binaries {
88+
all {
89+
linkerOpts.addAll(listOf("-L${rootProject.projectDir}/libs/linux/x64", "-llinux_pc_client"))
90+
//freeCompilerArgs = listOf("-Xadd-light-debug=enable")
91+
}
92+
sharedLib {
93+
baseName = "kmp_webrtc"
94+
}
95+
}
96+
}
7897

7998
applyDefaultHierarchyTemplate()
8099
sourceSets {
@@ -116,9 +135,9 @@ kotlin {
116135
dependsOn(commonMain.get())
117136
}
118137

119-
// linuxMain {
120-
// dependsOn(cppCommon)
121-
// }
138+
linuxMain {
139+
dependsOn(cppCommon)
140+
}
122141
mingwMain {
123142
dependsOn(cppCommon)
124143
}

kmp-webrtc/src/androidMain/kotlin/com/piasy/kmp/webrtc/utils/Platform.android.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

kmp-webrtc/src/commonMain/kotlin/com/piasy/kmp/webrtc/utils/Platform.kt

Lines changed: 0 additions & 22 deletions
This file was deleted.

kmp-webrtc/src/cppCommon/kotlin/com/piasy/kmp/webrtc/CppPeerConnectionClient.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ private fun pcClientCallbackOnPreferCodecs(
3232
return null
3333
}
3434

35+
// this function is designed to be called from cpp code,
36+
// and cpp code needs to access the returned string,
37+
// so we need to make sure the cstr still lives after
38+
// the function returns, so we use nativeHeap.allocArray
39+
// and nativeHeap.free (in freeKString above).
40+
// but when kotlin code calls cpp code, when we want to pass
41+
// cstr to cpp code, we can just use memScoped, because the
42+
// whole cpp function call lifetime is inside the memScoped
43+
// block (in CppUtils.kt).
3544
val refinedSdp = opaque.asStableRef<PeerConnectionClientCallback>()
3645
.get()
3746
.onPreferCodecs(peerUid, sdp)

kmp-webrtc/src/iosMain/kotlin/com/piasy/kmp/webrtc/utils/Platform.ios.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

kmp-webrtc/src/jsMain/kotlin/com/piasy/kmp/webrtc/utils/Platform.js.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.piasy.kmp.webrtc
2+
3+
import kotlinx.cinterop.COpaquePointer
4+
5+
/**
6+
* Created by Piasy{github.com/Piasy} on 2025-03-02.
7+
*/
8+
class LinuxPeerConnectionClient(
9+
peerUid: String,
10+
dir: Int,
11+
needCaptureVideo: Boolean,
12+
videoMaxBitrate: Int,
13+
videoCaptureFps: Int,
14+
callback: PeerConnectionClientCallback
15+
) : CppPeerConnectionClient(peerUid, dir, needCaptureVideo, videoMaxBitrate, videoCaptureFps, callback) {
16+
17+
override fun addRemoteTrackRenderer(renderer: Any) {
18+
// if (renderer is COpaquePointer) {
19+
// WebRTC.PCClientAddRemoteRenderer(realClient, renderer)
20+
// }
21+
}
22+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.piasy.kmp.webrtc
2+
3+
import kotlinx.cinterop.COpaquePointer
4+
5+
/**
6+
* Created by Piasy{github.com/Piasy} on 2025-03-05.
7+
*/
8+
data class LinuxPrivateConfig(
9+
internal val hwnd: COpaquePointer,
10+
internal val disableEncryption: Boolean,
11+
) : PeerConnectionClientFactory.PrivateConfig()
12+
13+
class LinuxPeerConnectionClientFactory(
14+
config: Config,
15+
errorHandler: (Int, String) -> Unit,
16+
) : CppPeerConnectionClientFactory(config, errorHandler) {
17+
18+
override fun createPeerConnectionClient(
19+
peerUid: String, dir: Int, hasVideo: Boolean,
20+
videoMaxBitrateBps: Int, videoMaxFrameRate: Int,
21+
callback: PeerConnectionClientCallback
22+
) = LinuxPeerConnectionClient(peerUid, dir, hasVideo, videoMaxBitrateBps, videoMaxFrameRate, callback)
23+
}
24+
25+
actual fun createPeerConnectionClientFactory(
26+
config: PeerConnectionClientFactory.Config,
27+
errorHandler: (Int, String) -> Unit,
28+
): PeerConnectionClientFactory {
29+
val privateConfig = config.privateConfig as LinuxPrivateConfig
30+
val disableEncryption = if (privateConfig.disableEncryption) 1 else 0
31+
WebRTC.PCClientCreatePeerConnectionFactory(privateConfig.hwnd, disableEncryption, 0, 0)
32+
return LinuxPeerConnectionClientFactory(config, errorHandler)
33+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.piasy.kmp.webrtc.utils
2+
3+
import com.piasy.kmp.webrtc.PeerConnectionClient
4+
import com.piasy.kmp.webrtc.PeerConnectionClientFactory
5+
import com.piasy.kmp.webrtc.LinuxPrivateConfig
6+
import kotlinx.cinterop.COpaquePointer
7+
8+
/**
9+
* Created by Piasy{github.com/Piasy} on 2025-03-06.
10+
*
11+
* Utility functions used by cpp example code.
12+
*/
13+
14+
fun createPcClientFactoryConfig(
15+
config: PeerConnectionClientFactory.Config, privateConfig: LinuxPrivateConfig
16+
): PeerConnectionClientFactory.Config {
17+
return PeerConnectionClientFactory.Config(
18+
config.videoCaptureImpl, config.videoCaptureWidth, config.videoCaptureHeight, config.videoCaptureFps,
19+
config.initCameraFace, privateConfig
20+
)
21+
}
22+
23+
fun addRemoteTrackRenderer(client: PeerConnectionClient, renderer: COpaquePointer) {
24+
client.addRemoteTrackRenderer(renderer)
25+
}

0 commit comments

Comments
 (0)