From 4ce87feac15e591ac0ec955eb2e23b90ddeeae98 Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Sat, 17 Jan 2026 08:15:43 -0600 Subject: [PATCH] log graphics element z index (#2785) --- ErsatzTV.Core/Graphics/BaseGraphicsElement.cs | 7 +++++++ .../Streaming/Graphics/GraphicsElement.cs | 2 ++ .../Streaming/Graphics/GraphicsElementLoader.cs | 16 +++++++++++----- .../Streaming/Graphics/GraphicsEngine.cs | 8 ++++++++ .../Streaming/Graphics/IGraphicsElement.cs | 3 ++- .../Streaming/Graphics/Image/ImageElement.cs | 2 ++ .../Streaming/Graphics/Image/WatermarkElement.cs | 4 ++++ .../Streaming/Graphics/Motion/MotionElement.cs | 2 ++ .../Streaming/Graphics/Script/ScriptElement.cs | 2 ++ .../Graphics/Subtitle/SubtitleElement.cs | 2 ++ .../Streaming/Graphics/Text/TextElement.cs | 2 ++ 11 files changed, 44 insertions(+), 6 deletions(-) diff --git a/ErsatzTV.Core/Graphics/BaseGraphicsElement.cs b/ErsatzTV.Core/Graphics/BaseGraphicsElement.cs index 634f5d2ab..2487872f8 100644 --- a/ErsatzTV.Core/Graphics/BaseGraphicsElement.cs +++ b/ErsatzTV.Core/Graphics/BaseGraphicsElement.cs @@ -1,6 +1,13 @@ +using YamlDotNet.Serialization; + namespace ErsatzTV.Core.Graphics; public class BaseGraphicsElement { public string Name { get; set; } + + [YamlIgnore] + public string SourceFileName { get; set; } + + public string DebugName() => string.IsNullOrEmpty(Name) ? SourceFileName : Name; } diff --git a/ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsElement.cs b/ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsElement.cs index fa95a2b9e..ce913ee05 100644 --- a/ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsElement.cs +++ b/ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsElement.cs @@ -9,6 +9,8 @@ public abstract class GraphicsElement : IGraphicsElement { public abstract int ZIndex { get; } + public abstract string DebugKey { get; } + public bool IsFinished { get; set; } public abstract Task InitializeAsync(GraphicsEngineContext context, CancellationToken cancellationToken); diff --git a/ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsElementLoader.cs b/ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsElementLoader.cs index 754ad7d61..19b2e4871 100644 --- a/ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsElementLoader.cs +++ b/ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsElementLoader.cs @@ -281,7 +281,7 @@ public partial class GraphicsElementLoader( return result; } - private async Task> GetTemplatedYaml(string fileName, Dictionary variables) + private async Task> GetTemplatedYaml(string fileName, Dictionary variables) { string yaml = await fileSystem.File.ReadAllTextAsync(fileName); try @@ -295,16 +295,18 @@ public partial class GraphicsElementLoader( var context = new TemplateContext { MemberRenamer = member => member.Name }; context.PushGlobal(scriptObject); - return await Template.Parse(yaml).RenderAsync(context); + return new TemplatedYaml( + fileSystem.Path.GetFileName(fileName), + await Template.Parse(yaml).RenderAsync(context)); } catch (Exception ex) { logger.LogWarning(ex, "Failed to render graphics element YAML definition as scriban template"); - return Option.None; + return Option.None; } } - private Option FromYaml(string yaml) + private Option FromYaml(TemplatedYaml yaml) where T : BaseGraphicsElement { try { @@ -318,7 +320,9 @@ public partial class GraphicsElementLoader( .WithNamingConvention(CamelCaseNamingConvention.Instance) .Build(); - return deserializer.Deserialize(yaml); + var result = deserializer.Deserialize(yaml.Yaml); + result.SourceFileName = yaml.SourceFileName; + return result; } catch (Exception ex) { @@ -346,4 +350,6 @@ public partial class GraphicsElementLoader( [GeneratedRegex(@"epg_entries:\s*(\d+)")] private static partial Regex EpgEntriesRegex(); + + private record TemplatedYaml(string SourceFileName, string Yaml); } diff --git a/ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsEngine.cs b/ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsEngine.cs index deb3a6a35..5a05c9d14 100644 --- a/ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsEngine.cs +++ b/ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsEngine.cs @@ -99,6 +99,14 @@ public class GraphicsEngine( var prepareTasks = new List>>(elements.Count); + foreach (IGraphicsElement element in elements.OrderBy(e => e.ZIndex)) + { + logger.LogDebug( + "Graphics element {Element} will draw with ZIndex {ZIndex}", + element.DebugKey, + element.ZIndex); + } + try { // `content_total_seconds` - the total number of seconds in the content diff --git a/ErsatzTV.Infrastructure/Streaming/Graphics/IGraphicsElement.cs b/ErsatzTV.Infrastructure/Streaming/Graphics/IGraphicsElement.cs index d98b03806..5af1dc1b4 100644 --- a/ErsatzTV.Infrastructure/Streaming/Graphics/IGraphicsElement.cs +++ b/ErsatzTV.Infrastructure/Streaming/Graphics/IGraphicsElement.cs @@ -1,4 +1,3 @@ -using ErsatzTV.Core.Domain; using ErsatzTV.Core.Interfaces.Streaming; namespace ErsatzTV.Infrastructure.Streaming.Graphics; @@ -7,6 +6,8 @@ public interface IGraphicsElement { int ZIndex { get; } + string DebugKey { get; } + bool IsFinished { get; set; } Task InitializeAsync(GraphicsEngineContext context, CancellationToken cancellationToken); diff --git a/ErsatzTV.Infrastructure/Streaming/Graphics/Image/ImageElement.cs b/ErsatzTV.Infrastructure/Streaming/Graphics/Image/ImageElement.cs index 127205a56..1a8d3bb82 100644 --- a/ErsatzTV.Infrastructure/Streaming/Graphics/Image/ImageElement.cs +++ b/ErsatzTV.Infrastructure/Streaming/Graphics/Image/ImageElement.cs @@ -13,6 +13,8 @@ public class ImageElement(ImageGraphicsElement imageGraphicsElement, ILogger log public override int ZIndex { get; } = imageGraphicsElement.ZIndex ?? 0; + public override string DebugKey { get; } = $"Image {imageGraphicsElement.DebugName()}"; + public override async Task InitializeAsync(GraphicsEngineContext context, CancellationToken cancellationToken) { try diff --git a/ErsatzTV.Infrastructure/Streaming/Graphics/Image/WatermarkElement.cs b/ErsatzTV.Infrastructure/Streaming/Graphics/Image/WatermarkElement.cs index 44eedcec6..e32e6ef2e 100644 --- a/ErsatzTV.Infrastructure/Streaming/Graphics/Image/WatermarkElement.cs +++ b/ErsatzTV.Infrastructure/Streaming/Graphics/Image/WatermarkElement.cs @@ -24,13 +24,17 @@ public class WatermarkElement : ImageElementBase _imagePath = watermarkOptions.ImagePath; _watermark = watermarkOptions.Watermark; + ZIndex = watermarkOptions.Watermark.ZIndex; + DebugKey = $"Watermark {watermarkOptions.Watermark.Name}"; } public bool IsValid => _imagePath != null && _watermark != null; public override int ZIndex { get; } + public override string DebugKey { get; } + public override async Task InitializeAsync(GraphicsEngineContext context, CancellationToken cancellationToken) { try diff --git a/ErsatzTV.Infrastructure/Streaming/Graphics/Motion/MotionElement.cs b/ErsatzTV.Infrastructure/Streaming/Graphics/Motion/MotionElement.cs index 87598aa79..dd33f3e08 100644 --- a/ErsatzTV.Infrastructure/Streaming/Graphics/Motion/MotionElement.cs +++ b/ErsatzTV.Infrastructure/Streaming/Graphics/Motion/MotionElement.cs @@ -32,6 +32,8 @@ public class MotionElement( public override int ZIndex { get; } = motionElement.ZIndex ?? 0; + public override string DebugKey { get; } = $"Motion {motionElement.DebugName()}"; + public void Dispose() { GC.SuppressFinalize(this); diff --git a/ErsatzTV.Infrastructure/Streaming/Graphics/Script/ScriptElement.cs b/ErsatzTV.Infrastructure/Streaming/Graphics/Script/ScriptElement.cs index 51c5e632a..8b2c000a2 100644 --- a/ErsatzTV.Infrastructure/Streaming/Graphics/Script/ScriptElement.cs +++ b/ErsatzTV.Infrastructure/Streaming/Graphics/Script/ScriptElement.cs @@ -29,6 +29,8 @@ public class ScriptElement(ScriptGraphicsElement scriptElement, ILogger logger) public override int ZIndex { get; } = scriptElement.ZIndex ?? 0; + public override string DebugKey { get; } = $"Script {scriptElement.DebugName()}"; + public void Dispose() { logger.LogDebug( diff --git a/ErsatzTV.Infrastructure/Streaming/Graphics/Subtitle/SubtitleElement.cs b/ErsatzTV.Infrastructure/Streaming/Graphics/Subtitle/SubtitleElement.cs index 43d1e9ed5..eea8face9 100644 --- a/ErsatzTV.Infrastructure/Streaming/Graphics/Subtitle/SubtitleElement.cs +++ b/ErsatzTV.Infrastructure/Streaming/Graphics/Subtitle/SubtitleElement.cs @@ -32,6 +32,8 @@ public class SubtitleElement( public override int ZIndex { get; } = subtitleElement.ZIndex ?? 0; + public override string DebugKey { get; } = $"Subtitle {subtitleElement.DebugName()}"; + public void Dispose() { GC.SuppressFinalize(this); diff --git a/ErsatzTV.Infrastructure/Streaming/Graphics/Text/TextElement.cs b/ErsatzTV.Infrastructure/Streaming/Graphics/Text/TextElement.cs index 0d3b47133..70ecf9b7c 100644 --- a/ErsatzTV.Infrastructure/Streaming/Graphics/Text/TextElement.cs +++ b/ErsatzTV.Infrastructure/Streaming/Graphics/Text/TextElement.cs @@ -23,6 +23,8 @@ public partial class TextElement( public override int ZIndex { get; } = textElement.ZIndex ?? 0; + public override string DebugKey { get; } = $"Text {textElement.DebugName()}"; + public void Dispose() { GC.SuppressFinalize(this);