Skip to content

Commit

Permalink
introduce SubtitleRenderResult
Browse files Browse the repository at this point in the history
Cleanup some more
  • Loading branch information
brabebhin committed Jan 15, 2025
1 parent 853b436 commit 4e3c694
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 2,805 deletions.
8 changes: 6 additions & 2 deletions Samples/MediaPlayerCS/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ private async void RenderSubtitleDispatcherTimer_Tick(object sender, object e)
{
if (FFmpegMSS != null && FFmpegMSS.SubtitleStreams.Count > 0 && selectedSubtitleStreamInfo != null && renderTarget != null)
{
var surfaceChanged = FFmpegMSS.RenderSubtitlesToDirectXSurface(renderTarget, selectedSubtitleStreamInfo, mediaPlayer.PlaybackSession.Position);
var renderResult = FFmpegMSS.RenderSubtitlesToDirectXSurface(renderTarget, selectedSubtitleStreamInfo, mediaPlayer.PlaybackSession.Position);
var surfaceChanged = renderResult.Succeeded;

if (!surfaceChanged) return;

using (var ds = bitmapSource.CreateDrawingSession(Colors.Transparent))
Expand All @@ -171,7 +173,9 @@ private async void RenderSubtitleTimer_Tick(object sender, object e)
await subtitleLock.WaitAsync();
try
{
var surfaceChanged = FFmpegMSS.RenderSubtitlesToDirectXSurface(renderTarget, selectedSubtitleStreamInfo, mediaPlayer.PlaybackSession.Position);
var renderResult = FFmpegMSS.RenderSubtitlesToDirectXSurface(renderTarget, selectedSubtitleStreamInfo, mediaPlayer.PlaybackSession.Position);
var surfaceChanged = renderResult.Succeeded;

if (!surfaceChanged) return;

await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
Expand Down
10 changes: 6 additions & 4 deletions Source/FFmpegInteropX.idl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ namespace FFmpegInteropX
Double DisplayAspectRatio{ get; };
};

runtimeclass SubtitleRenderResult
{
Boolean Succeeded {get; };
};

static runtimeclass CodecChecker
{
///<summary>This event is raised if a codec is required to improve playback experience.</summary>
Expand Down Expand Up @@ -568,10 +573,7 @@ namespace FFmpegInteropX
Windows.Foundation.TimeSpan GetStreamDelay(IStreamInfo stream);

///<summary>Renders subtitles from the given stream at the current video position. </summary>
Windows.Graphics.Imaging.SoftwareBitmap RenderSubtitles(SubtitleStreamInfo subtitle, Windows.Foundation.TimeSpan currentVideoPosition, Windows.Foundation.Size renderSize);

///<summary>Renders subtitles from the given stream at the current video position. </summary>
Boolean RenderSubtitlesToDirectXSurface(Windows.Graphics.DirectX.Direct3D11.IDirect3DSurface renderTarget, SubtitleStreamInfo subtitle, Windows.Foundation.TimeSpan position);
SubtitleRenderResult RenderSubtitlesToDirectXSurface(Windows.Graphics.DirectX.Direct3D11.IDirect3DSurface renderTarget, SubtitleStreamInfo subtitle, Windows.Foundation.TimeSpan position);
};

runtimeclass SubtitleParser : Windows.Foundation.IClosable
Expand Down
54 changes: 2 additions & 52 deletions Source/FFmpegInteropX.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
<ClInclude Include="SubtitleProviderBitmap.h" />
<ClInclude Include="SubtitleProviderLibass.h" />
<ClInclude Include="SubtitleProviderSsaAss.h" />
<ClInclude Include="SubtitleRenderResult.h" />
<ClInclude Include="SubtitlesConfig.h" />
<ClInclude Include="SubtitleStreamInfo.h" />
<ClInclude Include="TexturePool.h" />
Expand Down Expand Up @@ -292,6 +293,7 @@
<ClCompile Include="SubtitleProvider.cpp" />
<ClCompile Include="SubtitleProviderLibass.cpp" />
<ClCompile Include="SubtitleProviderSsaAss.cpp" />
<ClCompile Include="SubtitleRenderResult.cpp" />
<ClCompile Include="SubtitlesConfig.cpp" />
<ClCompile Include="SubtitleStreamInfo.cpp" />
<ClCompile Include="text_encoding_detect.cpp" />
Expand Down Expand Up @@ -342,58 +344,6 @@
<ItemGroup>
<ResourceCompile Include="FFmpegInteropX.rc" />
</ItemGroup>
<ItemGroup>
<FxCompile Include="LibassBlenderPixelShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release_UWP|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release_UWP|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release_UWP|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release_UWP|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug_Desktop|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug_Desktop|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug_Desktop|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug_Desktop|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release_Desktop|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release_Desktop|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release_Desktop|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release_Desktop|ARM64'">Pixel</ShaderType>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Debug_Desktop|Win32'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug_Desktop|Win32'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Release_UWP|Win32'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release_UWP|Win32'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Release_Desktop|Win32'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release_Desktop|Win32'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|Win32'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|Win32'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Debug_Desktop|ARM64'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug_Desktop|ARM64'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Release_UWP|ARM64'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release_UWP|ARM64'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Release_Desktop|ARM64'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release_Desktop|ARM64'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|ARM64'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|ARM64'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Debug_Desktop|ARM'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug_Desktop|ARM'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Release_UWP|ARM'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release_UWP|ARM'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Release_Desktop|ARM'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release_Desktop|ARM'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|ARM'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|ARM'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Debug_Desktop|x64'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug_Desktop|x64'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Release_UWP|x64'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release_UWP|x64'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Release_Desktop|x64'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release_Desktop|x64'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|x64'">LibassBlenderPixelShaderBlob</VariableName>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|x64'">LibassBlenderPixelShaderBlob.h</HeaderFileOutput>
</FxCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.756\build\Microsoft.Windows.SDK.BuildTools.targets" Condition="Exists('..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.756\build\Microsoft.Windows.SDK.BuildTools.targets')" />
Expand Down
21 changes: 3 additions & 18 deletions Source/FFmpegMediaSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,34 +212,19 @@ namespace winrt::FFmpegInteropX::implementation

FFmpegMediaSource(winrt::com_ptr<MediaSourceConfig> const& interopConfig, DispatcherQueue const& dispatcher, uint64_t windowId, bool useHdr);

winrt::Windows::Graphics::Imaging::SoftwareBitmap RenderSubtitles(winrt::FFmpegInteropX::SubtitleStreamInfo const& subtitle, winrt::Windows::Foundation::TimeSpan const& currentVideoPosition, winrt::Windows::Foundation::Size const& renderSize)
winrt::FFmpegInteropX::SubtitleRenderResult RenderSubtitlesToDirectXSurface(winrt::Windows::Graphics::DirectX::Direct3D11::IDirect3DSurface rendertarget, winrt::FFmpegInteropX::SubtitleStreamInfo const& subtitle, winrt::Windows::Foundation::TimeSpan const& position)
{
for (auto& subProvider : subtitleStreamProviders)
{
if (subProvider->SubtitleInfo() == subtitle)
{
return subProvider->RenderSubtitles(currentVideoPosition, renderSize);
return subProvider->RenderSubtitlesToDirectXSurface(rendertarget, position).as<winrt::FFmpegInteropX::SubtitleRenderResult>();
}
}

return nullptr;
return winrt::make_self<implementation::SubtitleRenderResult>(false).as<winrt::FFmpegInteropX::SubtitleRenderResult>();
}

bool RenderSubtitlesToDirectXSurface(winrt::Windows::Graphics::DirectX::Direct3D11::IDirect3DSurface rendertarget, winrt::FFmpegInteropX::SubtitleStreamInfo const& subtitle, winrt::Windows::Foundation::TimeSpan const& position)
{
for (auto& subProvider : subtitleStreamProviders)
{
if (subProvider->SubtitleInfo() == subtitle)
{
return subProvider->RenderSubtitlesToDirectXSurface(rendertarget, position);
}
}

return false;
}



private:

HRESULT CreateMediaStreamSource(IRandomAccessStream const& stream);
Expand Down
15 changes: 0 additions & 15 deletions Source/LibassBlenderPixelShader.hlsl

This file was deleted.

Loading

0 comments on commit 4e3c694

Please sign in to comment.