From f9db92d5e6064d37ed5c06cd5adf2dfbd75a80dc Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Thu, 7 Aug 2025 19:56:56 +0000 Subject: [PATCH] add content_total_seconds to watermark opacity expression (#2275) --- CHANGELOG.md | 1 + .../Interfaces/Streaming/IGraphicsElement.cs | 1 + ErsatzTV.Infrastructure/Streaming/GraphicsEngine.cs | 11 ++++++++++- ErsatzTV.Infrastructure/Streaming/WatermarkElement.cs | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 180965a46..d2cdeef9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - This allows specifying an expression that returns an opacity between 0.0 and 1.0 - The expression can use: - `content_seconds` - the total number of seconds the frame is into the content + - `content_total_seconds` - the total number of seconds in the content - `channel_seconds` - the total number of seconds the frame is from when the channel started/activated - `time_of_day_seconds` - the total number of seconds the frame is since midnight diff --git a/ErsatzTV.Core/Interfaces/Streaming/IGraphicsElement.cs b/ErsatzTV.Core/Interfaces/Streaming/IGraphicsElement.cs index e4fa26980..bef168987 100644 --- a/ErsatzTV.Core/Interfaces/Streaming/IGraphicsElement.cs +++ b/ErsatzTV.Core/Interfaces/Streaming/IGraphicsElement.cs @@ -12,6 +12,7 @@ public interface IGraphicsElement object context, TimeSpan timeOfDay, TimeSpan contentTime, + TimeSpan contentTotalTime, TimeSpan channelTime, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/ErsatzTV.Infrastructure/Streaming/GraphicsEngine.cs b/ErsatzTV.Infrastructure/Streaming/GraphicsEngine.cs index c02ca0670..393e41e33 100644 --- a/ErsatzTV.Infrastructure/Streaming/GraphicsEngine.cs +++ b/ErsatzTV.Infrastructure/Streaming/GraphicsEngine.cs @@ -35,6 +35,9 @@ public class GraphicsEngine(ILogger logger) : IGraphicsEngine try { + // `content_total_seconds` - the total number of seconds in the content + var contentTotalTime = context.Seek + context.Duration; + while (!cancellationToken.IsCancellationRequested && frameCount < totalFrames) { // seconds since this specific stream started @@ -64,7 +67,13 @@ public class GraphicsEngine(ILogger logger) : IGraphicsEngine { if (!element.IsFailed) { - element.Draw(ctx, frameTime.TimeOfDay, contentTime, channelTime, cancellationToken); + element.Draw( + ctx, + frameTime.TimeOfDay, + contentTime, + contentTotalTime, + channelTime, + cancellationToken); } } catch (Exception ex) diff --git a/ErsatzTV.Infrastructure/Streaming/WatermarkElement.cs b/ErsatzTV.Infrastructure/Streaming/WatermarkElement.cs index de6fcec2f..43ae401fc 100644 --- a/ErsatzTV.Infrastructure/Streaming/WatermarkElement.cs +++ b/ErsatzTV.Infrastructure/Streaming/WatermarkElement.cs @@ -121,6 +121,7 @@ public class WatermarkElement : IGraphicsElement, IDisposable object context, TimeSpan timeOfDay, TimeSpan contentTime, + TimeSpan contentTotalTime, TimeSpan channelTime, CancellationToken cancellationToken) { @@ -130,6 +131,7 @@ public class WatermarkElement : IGraphicsElement, IDisposable } _expression.Parameters["content_seconds"] = contentTime.TotalSeconds; + _expression.Parameters["content_total_seconds"] = contentTotalTime.TotalSeconds; _expression.Parameters["channel_seconds"] = channelTime.TotalSeconds; _expression.Parameters["time_of_day_seconds"] = timeOfDay.TotalSeconds;