Skip to content

Commit

Permalink
Disable subtitle rendering
Browse files Browse the repository at this point in the history
Currently causes crashes
  • Loading branch information
dotMorten committed Jul 10, 2022
1 parent 56f35a8 commit 4ad8524
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/WinUIEx/MediaPlayerPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,28 @@ private unsafe void MediaPlayer_VideoFrameAvailable(MediaPlayer sender, object a
Windows.Win32.PInvoke.CreateDirect3D11SurfaceFromDXGISurface(surface, out var isurface);
var d3dSurface = WinRT.MarshalInterface<Windows.Graphics.DirectX.Direct3D11.IDirect3DSurface>.FromAbi(Marshal.GetIUnknownForObject(isurface));
MediaPlayer.CopyFrameToVideoSurface(d3dSurface);
if (hassubtitles) // TODO: This'll only render on one frame until next text. Crash if repeating without this flag getting set.
{
hassubtitles = false;
MediaPlayer.RenderSubtitlesToSurface(d3dSurface);
}
Windows.Win32.Graphics.Dxgi.DXGI_PRESENT_PARAMETERS presentParam = new Windows.Win32.Graphics.Dxgi.DXGI_PRESENT_PARAMETERS(); // { 0, nullptr, nullptr, nullptr };
presentParam.DirtyRectsCount = 0;
m_swapchain.Present1(1, 0, &presentParam);
});
}

private bool hassubtitles = false;

private unsafe void MediaPlayer_SubtitleFrameChanged(MediaPlayer sender, object args)
{
hassubtitles = true;
if (m_swapchain is null)
return;
swapchainPanel?.DispatcherQueue?.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
{
Guid g = IID_IDXGISurface;
m_swapchain.GetBuffer(0, &g, out var surfaceobj);
var surface = surfaceobj.As<Windows.Win32.Graphics.Dxgi.IDXGISurface>();
Windows.Win32.PInvoke.CreateDirect3D11SurfaceFromDXGISurface(surface, out var isurface);
var d3dSurface = WinRT.MarshalInterface<Windows.Graphics.DirectX.Direct3D11.IDirect3DSurface>.FromAbi(Marshal.GetIUnknownForObject(isurface));
MediaPlayer.RenderSubtitlesToSurface(d3dSurface);
Windows.Win32.Graphics.Dxgi.DXGI_PRESENT_PARAMETERS presentParam = new Windows.Win32.Graphics.Dxgi.DXGI_PRESENT_PARAMETERS(); // { 0, nullptr, nullptr, nullptr };
presentParam.DirtyRectsCount = 0;
m_swapchain.Present1(1, 0, &presentParam);
});
}

private unsafe void CreateSwapChain()
Expand Down Expand Up @@ -199,7 +205,7 @@ private void OnMediaPlayerPropertyChanged(DependencyPropertyChangedEventArgs e)
{
if(e.OldValue is MediaPlayer oldPlayer)
{
oldPlayer.SubtitleFrameChanged -= MediaPlayer_SubtitleFrameChanged;
//oldPlayer.SubtitleFrameChanged -= MediaPlayer_SubtitleFrameChanged;
oldPlayer.VideoFrameAvailable -= MediaPlayer_VideoFrameAvailable;
oldPlayer.Dispose();
}
Expand All @@ -209,7 +215,7 @@ private void OnMediaPlayerPropertyChanged(DependencyPropertyChangedEventArgs e)
newPlayer.SetSurfaceSize(new Windows.Foundation.Size(ActualWidth, ActualHeight));
newPlayer.IsVideoFrameServerEnabled = true;
newPlayer.VideoFrameAvailable += MediaPlayer_VideoFrameAvailable;
newPlayer.SubtitleFrameChanged += MediaPlayer_SubtitleFrameChanged;
//newPlayer.SubtitleFrameChanged += MediaPlayer_SubtitleFrameChanged;
}
}

Expand Down

0 comments on commit 4ad8524

Please sign in to comment.