davidliu
Committed by GitHub

Guard against malformed server response and fix server codec handling (#312)

@@ -363,13 +363,13 @@ internal constructor( @@ -363,13 +363,13 @@ internal constructor(
363 363
364 if (primaryCodecMime != null) { 364 if (primaryCodecMime != null) {
365 val updatedCodec = primaryCodecMime.mimeTypeToVideoCodec() 365 val updatedCodec = primaryCodecMime.mimeTypeToVideoCodec()
366 - if (updatedCodec != options.videoCodec) { 366 + if (updatedCodec != null && updatedCodec != options.videoCodec) {
367 LKLog.d { "falling back to server selected codec: $updatedCodec" } 367 LKLog.d { "falling back to server selected codec: $updatedCodec" }
368 - }  
369 - options = options.copy(videoCodec = updatedCodec) 368 + options = options.copy(videoCodec = updatedCodec)
370 369
371 - // recompute encodings since bitrates/etc could have changed  
372 - encodings = computeVideoEncodings((track as LocalVideoTrack).dimensions, options) 370 + // recompute encodings since bitrates/etc could have changed
  371 + encodings = computeVideoEncodings((track as LocalVideoTrack).dimensions, options)
  372 + }
373 } 373 }
374 } 374 }
375 375
@@ -850,6 +850,13 @@ abstract class BaseVideoTrackPublishOptions { @@ -850,6 +850,13 @@ abstract class BaseVideoTrackPublishOptions {
850 */ 850 */
851 abstract val scalabilityMode: String? 851 abstract val scalabilityMode: String?
852 852
  853 + /**
  854 + * Multi-codec Simulcast
  855 + *
  856 + * Codecs such as VP9 and AV1 are not supported by all clients. When backupCodec is
  857 + * set, when an incompatible client attempts to subscribe to the track, LiveKit
  858 + * will automatically publish a secondary track encoded with the backup codec.
  859 + */
853 abstract val backupCodec: BackupVideoCodec? 860 abstract val backupCodec: BackupVideoCodec?
854 } 861 }
855 862
@@ -16,6 +16,9 @@ @@ -16,6 +16,9 @@
16 16
17 package io.livekit.android.room.participant 17 package io.livekit.android.room.participant
18 18
19 -fun String.mimeTypeToVideoCodec(): String {  
20 - return split("/")[1].lowercase() 19 +fun String.mimeTypeToVideoCodec(): String? {
  20 + return split("/")
  21 + .takeIf { length > 1 }
  22 + ?.get(1)
  23 + ?.lowercase()
21 } 24 }