Skip to content

Commit 960061e

Browse files
feat: test mobile virtual bg
1 parent 8ac18bf commit 960061e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3645
-2
lines changed

android/.idea/diskUsageState.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ dependencies {
5555
// implementation("io.getstream:stream-webrtc-android:1.1.3") // same WebRTC API, no code change required
5656
implementation("androidx.constraintlayout:constraintlayout:2.2.1")
5757
implementation("com.google.android.flexbox:flexbox:3.0.0")
58+
implementation("com.google.mediapipe:tasks-vision:latest.release")
5859

5960
}
244 KB
Binary file not shown.

android/app/src/main/java/com/example/myapplication/CallActivity.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class CallActivity : AppCompatActivity(), RtcListener {
9292
private var messageBottomSheet: BottomSheetDialog? = null
9393
private lateinit var btnChat: ImageButton
9494

95+
// val btnBackground = findViewById<ImageButton>(R.id.btn_background)
96+
var backgroundEnabled = false
97+
9598
// Activity Result API for screen capture
9699
private val screenCaptureLauncher = registerForActivityResult(
97100
ActivityResultContracts.StartActivityForResult()
@@ -419,6 +422,25 @@ class CallActivity : AppCompatActivity(), RtcListener {
419422
remoteView.layoutParams = remoteParams
420423
}
421424
}, 1F)
425+
426+
val btnBackground = findViewById<ImageButton>(R.id.btn_background)
427+
btnBackground.setOnClickListener {
428+
backgroundEnabled = !backgroundEnabled
429+
430+
// Toggle processing in PeerConnectionClient
431+
peerConnectionClient?.toggleVirtualBackground(backgroundEnabled)
432+
433+
// Highlight the button
434+
if (backgroundEnabled) {
435+
// btnBackground.setBackgroundResource(R.drawable.control_button_background_active) // Create a highlighted drawable
436+
btnBackground.setColorFilter(android.graphics.Color.GREEN)
437+
onStatusChanged("Virtual background on")
438+
} else {
439+
btnBackground.setBackgroundResource(R.drawable.secondary_control_button_background)
440+
btnBackground.clearColorFilter()
441+
onStatusChanged("Virtual background off")
442+
}
443+
}
422444
}
423445

424446
@SuppressLint("ClickableViewAccessibility")

android/app/src/main/java/com/example/myapplication/webrtc/PeerConnectionClient.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class PeerConnectionClient(
3333
private var peer: WebRtcPeer? = null
3434
private var useFrontCamera = true
3535

36+
private var backgroundProcessor: VirtualBackgroundProcessor? = null
37+
private var isBackgroundEnabled = false
38+
3639
companion object {
3740
private const val TAG = "PeerConnectionClient"
3841
}
@@ -266,6 +269,10 @@ class PeerConnectionClient(
266269
videoCapturer = null
267270
}
268271

272+
// Clean up virtual background processor
273+
backgroundProcessor?.cleanup()
274+
backgroundProcessor = null
275+
269276
cleanupMediaResources()
270277

271278
Log.d(TAG, "Closing peer connection.")
@@ -282,6 +289,20 @@ class PeerConnectionClient(
282289
Log.d(TAG, "Cleanup complete.")
283290
}
284291

292+
fun toggleVirtualBackground(enable: Boolean) {
293+
isBackgroundEnabled = enable
294+
if (enable) {
295+
if (backgroundProcessor == null) {
296+
backgroundProcessor = VirtualBackgroundProcessor(context, rootEglBase)
297+
}
298+
videoSource?.setVideoProcessor(backgroundProcessor)
299+
Log.d(TAG, "Virtual background enabled")
300+
} else {
301+
videoSource?.setVideoProcessor(null)
302+
Log.d(TAG, "Virtual background disabled")
303+
}
304+
}
305+
285306
// ========== Private Helper Methods ==========
286307

287308
private fun setupCamera() {

0 commit comments

Comments
 (0)