setCodecPreferences method

bool setCodecPreferences(
  1. String kind,
  2. List? newCodecs
)

Implementation

bool setCodecPreferences(String kind, List<dynamic>? newCodecs) {
  if (newCodecs == null) {
    return false;
  }
  final newRtcpFb = <dynamic>[];
  final newFmtp = <dynamic>[];
  final newPayloads = <String>[];
  for (final element in newCodecs) {
    final orignPayload = element['orign_payload'] as int;
    final payload = element['payload'] as int;
    // change payload type
    if (payload != orignPayload) {
      newRtcpFb.addAll(
        rtcpFb.where((e) {
          if (e['payload'] == orignPayload) {
            e['payload'] = payload;
            return true;
          }
          return false;
        }).toList(),
      );
      newFmtp.addAll(
        fmtp.where((e) {
          if (e['payload'] == orignPayload) {
            e['payload'] = payload;
            return true;
          }
          return false;
        }).toList(),
      );
      if (payloads.contains('$orignPayload')) {
        newPayloads.add('$payload');
      }
    } else {
      newRtcpFb.addAll(rtcpFb.where((e) => e['payload'] == payload).toList());
      newFmtp.addAll(fmtp.where((e) => e['payload'] == payload).toList());
      newPayloads.addAll(payloads.where((e) => e == '$payload').toList());
    }
  }
  rtcpFb = newRtcpFb;
  fmtp = newFmtp;
  payloads = newPayloads;
  codecs = newCodecs;
  return true;
}