setPublishingCodecs method

Future<List<String>> setPublishingCodecs(
  1. List<SubscribedCodec> codecs,
  2. LocalTrack track
)

Implementation

Future<List<String>> setPublishingCodecs(
    List<lk_rtc.SubscribedCodec> codecs, LocalTrack track) async {
  logger.fine('setPublishingCodecs $codecs');

  // only enable simulcast codec for preference codec setted
  if (codec == null && codecs.isNotEmpty) {
    await updatePublishingLayers(track, codecs[0].qualities);
    return [];
  }

  subscribedCodecs = codecs;

  List<String> newCodecs = [];

  for (var codec in codecs) {
    if (this.codec?.toLowerCase() == codec.codec.toLowerCase()) {
      await updatePublishingLayers(track, codec.qualities);
    } else {
      final simulcastCodecInfo = simulcastCodecs[codec.codec];
      logger.fine('setPublishingCodecs $codecs');
      if (simulcastCodecInfo == null) {
        for (var q in codec.qualities) {
          if (q.enabled) {
            newCodecs.add(codec.codec.toLowerCase());
            break;
          }
        }
      } else if (simulcastCodecInfo.encodings != null &&
          simulcastCodecInfo.sender != null) {
        logger.fine('setPublishingCodecs $codecs');
        await setPublishingLayersForSender(
          simulcastCodecInfo.sender!,
          simulcastCodecInfo.encodings!,
          codec.qualities,
        );
      }
    }
  }
  return newCodecs;
}