videoFramesStream method

  1. @override
Stream<VideoFrame> videoFramesStream({
  1. double? maxFramesPerSecond,
})
override

Implementation

@override
Stream<VideoFrame> videoFramesStream({double? maxFramesPerSecond}) {
  final arguments = maxFramesPerSecond == null
      ? null
      : <String, dynamic>{'maxFramesPerSecond': maxFramesPerSecond};
  return videoFramesEventChannel.receiveBroadcastStream(arguments).map((
    dynamic event,
  ) {
    final map = Map<String, dynamic>.from(event as Map);
    final codecStr = map['codec'] as String? ?? 'raw';
    final codec = codecStr == 'hvc1' ? VideoCodec.hvc1 : VideoCodec.raw;
    final bytes = map['bytes'] as Uint8List;
    final bytesPerRow = (map['bytesPerRow'] as num?)?.toInt();
    return VideoFrame(
      codec: codec,
      bytes: bytes,
      width: (map['width'] as num).toInt(),
      height: (map['height'] as num).toInt(),
      presentationTimestampUs: (map['ptsUs'] as num).toInt(),
      isKeyframe: (map['isKeyframe'] as bool?) ?? true,
      bytesPerRow: bytesPerRow,
    );
  });
}