getDefaultFormats method
Get default formats for display and loopback devices.
Implementation
@override
Future<ScreenFormatDefaults> getDefaultFormats(String displayId) async {
final displayIdPtr = displayId.toNativeUtf8();
final videoFormatOutPtr = calloc<bindings.MiniAVVideoInfo>();
final audioFormatOutPtr = calloc<bindings.MiniAVAudioInfo>();
try {
final result = bindings.MiniAV_Screen_GetDefaultFormats(
displayIdPtr.cast<ffi.Char>(),
videoFormatOutPtr,
audioFormatOutPtr,
);
if (result != bindings.MiniAVResultCode.MINIAV_SUCCESS) {
throw Exception(
'Failed to get default formats for display $displayId: ${result.name}',
);
}
final videoFormat = VideoFormatInfoFFIToPlatform.fromNative(
videoFormatOutPtr.ref,
).toPlatformType();
// Audio might not be supported or returned, check for zeroed struct or specific values if needed
final audioFormat = AudioInfoFFIToPlatform.fromNative(
audioFormatOutPtr.ref,
).toPlatformType();
// Determine if audioFormat is valid (e.g. sampleRate > 0 or format != UNKNOWN)
// For simplicity, we'll assume if C API returns success, audioFormat might be valid or zeroed.
// A more robust check would be to see if audioFormat.sampleRate > 0 or similar.
final bool isAudioFormatValid =
audioFormat.sampleRate > 0 && audioFormat.channels > 0;
return (videoFormat, isAudioFormatValid ? audioFormat : null);
} finally {
calloc.free(displayIdPtr);
calloc.free(videoFormatOutPtr);
calloc.free(audioFormatOutPtr);
}
}