getConfiguredFormats method

  1. @override
Future<ScreenFormatDefaults> getConfiguredFormats()
override

Implementation

@override
Future<ScreenFormatDefaults> getConfiguredFormats() async {
  _ensureNotDestroyed();

  final videoFormatOutPtr = calloc<bindings.MiniAVVideoInfo>();
  final audioFormatOutPtr = calloc<bindings.MiniAVAudioInfo>();
  try {
    final result = bindings.MiniAV_Screen_GetConfiguredFormats(
      _context!.cast(),
      videoFormatOutPtr,
      audioFormatOutPtr,
    );
    if (result != bindings.MiniAVResultCode.MINIAV_SUCCESS) {
      throw Exception(
        'Failed to get configured screen formats: ${result.name}',
      );
    }
    final videoFormat = VideoFormatInfoFFIToPlatform.fromNative(
      videoFormatOutPtr.ref,
    ).toPlatformType();
    final audioFormat = AudioInfoFFIToPlatform.fromNative(
      audioFormatOutPtr.ref,
    ).toPlatformType();

    final bool isAudioFormatValid =
        audioFormat.sampleRate > 0 && audioFormat.channels > 0;

    return (videoFormat, isAudioFormatValid ? audioFormat : null);
  } finally {
    calloc.free(videoFormatOutPtr);
    calloc.free(audioFormatOutPtr);
  }
}