Flutter Video Call SDK Plugin

A high-performance video call SDK for Flutter with advanced optimization algorithms implemented in Rust.

Features

πŸš€ Advanced Optimization Algorithms:

  • Kalman Filter Congestion Control - Predicts network conditions and adapts bitrate proactively
  • Reed-Solomon Forward Error Correction - Recovers lost packets without retransmission delay
  • Rate-Distortion Optimization - Maximizes video quality at any bitrate

⚑ High Performance:

  • Written in Rust for maximum performance
  • Low latency (<70ms total overhead)
  • Minimal CPU usage (8-23% depending on preset)
  • Small memory footprint (~111KB)

🎯 Easy to Use:

  • Simple Dart API
  • Automatic network adaptation
  • Real-time statistics
  • Cross-platform support (Android, iOS, Linux, macOS, Windows)

Installation

Add this to your pubspec.yaml:

dependencies:
  flutter_video_call_sdk_plugin: ^0.1.0

Then run:

flutter pub get

Quick Start

1. Initialize the SDK

import 'package:flutter_video_call_sdk_plugin/flutter_video_call_sdk_plugin.dart';

final sdk = FlutterVideoCallSdk.instance;

// Initialize (call once at app startup)
await sdk.initialize();

2. Create a Session

final sessionId = await sdk.createSession(
  initialBitrate: 1000000,  // 1 Mbps
  minBitrate: 300000,       // 300 kbps
  maxBitrate: 3000000,      // 3 Mbps
  enableFec: true,          // Enable packet loss recovery
);

print('Session created: $sessionId');

3. Update Network Feedback

// Update with current network conditions
await sdk.updateNetworkFeedback(
  sessionId,
  rttMs: 50,        // Round-trip time in milliseconds
  lossRate: 0.02,   // 2% packet loss
);

4. Get Statistics

final stats = await sdk.getSessionStats(sessionId);

print('Current bitrate: ${stats.bitrateMbps} Mbps');
print('FEC overhead: ${stats.fecOverhead}%');
print('Packet loss: ${stats.lossRatePercent}%');

5. Close Session

await sdk.closeSession(sessionId);

Complete Example

import 'package:flutter/material.dart';
import 'package:flutter_video_call_sdk_plugin/flutter_video_call_sdk_plugin.dart';

class VideoCallScreen extends StatefulWidget {
  @override
  _VideoCallScreenState createState() => _VideoCallScreenState();
}

class _VideoCallScreenState extends State<VideoCallScreen> {
  final sdk = FlutterVideoCallSdk.instance;
  String? sessionId;
  SessionStats? stats;

  @override
  void initState() {
    super.initState();
    _initializeSDK();
  }

  Future<void> _initializeSDK() async {
    await sdk.initialize();
    await _startCall();
  }

  Future<void> _startCall() async {
    // Create session
    sessionId = await sdk.createSession(
      initialBitrate: 1000000,
      minBitrate: 300000,
      maxBitrate: 3000000,
      enableFec: true,
    );

    // Start monitoring network
    _monitorNetwork();
  }

  Future<void> _monitorNetwork() async {
    // In real app, measure actual RTT and loss rate
    // For demo, simulate network conditions
    await sdk.updateNetworkFeedback(
      sessionId!,
      rttMs: 50,
      lossRate: 0.01,
    );

    // Update stats
    final newStats = await sdk.getSessionStats(sessionId!);
    setState(() {
      stats = newStats;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Video Call')),
      body: Center(
        child: stats != null
            ? Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('Bitrate: ${stats!.bitrateMbps.toStringAsFixed(2)} Mbps'),
                  Text('FEC Overhead: ${stats!.fecOverhead.toStringAsFixed(1)}%'),
                  Text('Loss Rate: ${stats!.lossRatePercent.toStringAsFixed(1)}%'),
                ],
              )
            : CircularProgressIndicator(),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          if (sessionId != null) {
            await sdk.closeSession(sessionId!);
            Navigator.pop(context);
          }
        },
        child: Icon(Icons.call_end),
        backgroundColor: Colors.red,
      ),
    );
  }

  @override
  void dispose() {
    if (sessionId != null) {
      sdk.closeSession(sessionId!);
    }
    super.dispose();
  }
}

API Reference

FlutterVideoCallSdk

Main SDK class (singleton).

Methods

  • initialize() - Initialize the SDK (call once)
  • createSession({...}) - Create a new video call session
  • getTargetBitrate(sessionId) - Get current target bitrate
  • updateNetworkFeedback(sessionId, {...}) - Update network conditions
  • getSessionStats(sessionId) - Get session statistics
  • closeSession(sessionId) - Close a session
  • dispose() - Dispose SDK resources

SessionStats

Statistics for a video call session.

Properties

  • sessionId - Session identifier
  • state - Current state (idle, connecting, connected, disconnected)
  • currentBitrate - Current bitrate in bps
  • bitrateMbps - Bitrate in Mbps (convenience getter)
  • bitrateKbps - Bitrate in kbps (convenience getter)
  • fecOverhead - FEC overhead percentage (0-100)
  • fecLossRate - Packet loss rate (0.0-1.0)
  • lossRatePercent - Loss rate as percentage (convenience getter)

NetworkQuality

Enum for network quality levels.

  • excellent - 0-1% loss, <50ms RTT
  • good - 1-3% loss, 50-100ms RTT
  • fair - 3-8% loss, 100-200ms RTT
  • poor - 8-15% loss, 200-500ms RTT
  • veryPoor - >15% loss, >500ms RTT

Performance

Latency Impact

Component Added Latency
Kalman Filter <1ms
RDO (Balanced) 10-15ms
FEC 10-50ms
Total 20-65ms

Resource Usage

Resource Usage
CPU 8-23%
Memory ~111KB
Network Overhead 10-50% (FEC)

Platform Support

  • βœ… Android (ARM64, ARMv7, x86_64)
  • βœ… iOS (ARM64, Simulator)
  • βœ… Linux (x86_64)
  • βœ… macOS (ARM64, x86_64)
  • βœ… Windows (x86_64)

Advanced Usage

Custom Configuration

// Create session with custom settings
final sessionId = await sdk.createSession(
  initialBitrate: 2000000,  // Start at 2 Mbps
  minBitrate: 500000,       // Allow down to 500 kbps
  maxBitrate: 5000000,      // Allow up to 5 Mbps
  enableFec: true,
);

Network Quality Detection

final quality = NetworkQuality.fromMetrics(
  rttMs: 75,
  lossRate: 0.02,
);

print('Network quality: ${quality.displayName}');
print('Recommended FEC: ${quality.recommendedFecOverhead}%');

Troubleshooting

High CPU Usage

Use lower quality preset or reduce max bitrate:

final sessionId = await sdk.createSession(
  initialBitrate: 500000,   // Lower initial bitrate
  maxBitrate: 1500000,      // Lower max bitrate
  enableFec: true,
);

High Latency

Reduce FEC overhead by setting higher loss tolerance:

// FEC will use less redundancy, reducing latency
// but may not recover as many lost packets

Poor Quality

Increase minimum bitrate:

final sessionId = await sdk.createSession(
  minBitrate: 500000,  // Higher minimum ensures better quality
  maxBitrate: 3000000,
  enableFec: true,
);

Contributing

Contributions are welcome! Please read our Contributing Guide.

License

MIT License - see LICENSE file for details.

Support

Acknowledgments

Built with: