appSink.NewSample += Update;
public void Update(object sender, NewSampleArgs args)
{
var sink = (Gst.App.AppSink)sender;
using var sample = sink?.PullSample();
if (sample == null) return;
using var buffer = sample?.Buffer;
if (buffer == null) return;
MapInfo map;
if (!buffer.Map(out map, MapFlags.Read)) return;
if (!_cts.Token.IsCancellationRequested && !_window.Dispatcher.HasShutdownStarted
&& !_window.Dispatcher.HasShutdownFinished)
{
// _window is the window hosting the <Image>
_window.Dispatcher.BeginInvoke(() =>
{
_imageSource.WritePixels(rect, buffer, stride, 0, 0); // error here after _window closes
// _imageSource is the <Image>'s Source
});
}
buffer.Unmap(map);
}
public void Stop()
{
_cts.Cancel();
}
appSink.NewSample += Update;
public void Update(object sender, NewSampleArgs args)
{
var sink = (Gst.App.AppSink)sender;
using var sample = sink?.PullSample();
if (sample == null) return;
using var buffer = sample?.Buffer;
if (buffer == null) return;
MapInfo map;
if (!buffer.Map(out map, MapFlags.Read)) return;
if (!_cts.Token.IsCancellationRequested && !_window.Dispatcher.HasShutdownStarted
&& !_window.Dispatcher.HasShutdownFinished)
{
// _window is the window hosting the <Image>
_window.Dispatcher.BeginInvoke(() =>
{
_imageSource.WritePixels(rect, buffer, stride, 0, 0); // error here after _window closes
// _imageSource is the <Image>'s Source
});
}
buffer.Unmap(map);
}
public void Stop()
{
_cts.Cancel();
}