Webcam grab: SharedReadOnly mode, VideoPreview/VideoRecord source fallback, name the blocking app in the error (NVIDIA Broadcast finding)
This commit is contained in:
@@ -43,14 +43,21 @@ public sealed class MediaCaptureFrameSource : ICameraFrameSource
|
||||
VideoDeviceId = _deviceId,
|
||||
StreamingCaptureMode = StreamingCaptureMode.Video,
|
||||
MemoryPreference = MediaCaptureMemoryPreference.Cpu,
|
||||
SharingMode = MediaCaptureSharingMode.SharedReadOnly,
|
||||
};
|
||||
await capture.InitializeAsync(settings);
|
||||
|
||||
var colorSource = capture.FrameSources
|
||||
.FirstOrDefault(pair => pair.Value.Info.MediaStreamType == MediaStreamType.VideoPreview)
|
||||
.Value;
|
||||
var colorSource = capture.FrameSources.Values
|
||||
.OrderBy(s => s.Info.MediaStreamType == MediaStreamType.VideoPreview ? 0 : 1)
|
||||
.FirstOrDefault(s => s.Info.MediaStreamType is MediaStreamType.VideoPreview or MediaStreamType.VideoRecord);
|
||||
if (colorSource == null)
|
||||
throw new InvalidOperationException($"No video preview source on camera '{_deviceId}'.");
|
||||
{
|
||||
var kinds = string.Join(", ", capture.FrameSources.Values
|
||||
.Select(s => s.Info.MediaStreamType).Distinct());
|
||||
throw new InvalidOperationException(
|
||||
$"Camera '{_deviceId}' exposes no video source (found: {kinds}). " +
|
||||
"It may be locked by another app (e.g. NVIDIA Broadcast).");
|
||||
}
|
||||
|
||||
reader = await capture.CreateFrameReaderAsync(colorSource, MediaEncodingSubtypes.Bgra8);
|
||||
reader.FrameArrived += OnFrameArrived;
|
||||
|
||||
Reference in New Issue
Block a user