From e53a6d3e6ae29cb05c55c7b8edf2d237a1f75c16 Mon Sep 17 00:00:00 2001 From: Speenah Date: Tue, 13 Oct 2026 13:43:53 -0400 Subject: Merge pull request #17299 from Speenah/fix/hls-subtitle-timing Fix fMP4 HLS subtitle timestamp map offset --- .../Controllers/SubtitleControllerTests.cs | 40 ++++++++++++++++++++++ .../Helpers/DynamicHlsHelperTests.cs | 26 ++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/Jellyfin.Api.Tests/Helpers/DynamicHlsHelperTests.cs (limited to 'tests') diff --git a/tests/Jellyfin.Api.Tests/Controllers/SubtitleControllerTests.cs b/tests/Jellyfin.Api.Tests/Controllers/SubtitleControllerTests.cs index 77321f0b05..36b4e7156e 100644 --- a/tests/Jellyfin.Api.Tests/Controllers/SubtitleControllerTests.cs +++ b/tests/Jellyfin.Api.Tests/Controllers/SubtitleControllerTests.cs @@ -134,4 +134,44 @@ public class SubtitleControllerTests fileSystem.Object, NullLogger.Instance); } + + [Theory] + [MemberData(nameof(GetVttTimestampMap_Success_TestData))] + public static void GetVttTimestampMap_Success(long mpegTimestamp, string expected) + { + Assert.Equal(expected, SubtitleController.GetVttTimestampMap(mpegTimestamp)); + } + + public static TheoryData GetVttTimestampMap_Success_TestData() + { + var data = new TheoryData(); + data.Add(900000, "X-TIMESTAMP-MAP=MPEGTS:900000,LOCAL:00:00:00.000"); + data.Add(0, "X-TIMESTAMP-MAP=MPEGTS:0,LOCAL:00:00:00.000"); + return data; + } + + [Theory] + [MemberData(nameof(GetSubtitleSegmentUrl_Success_TestData))] + public static void GetSubtitleSegmentUrl_Success(long positionTicks, long endPositionTicks, string accessToken, long vttTimestampMapMpegts, string expected) + { + Assert.Equal(expected, SubtitleController.GetSubtitleSegmentUrl(positionTicks, endPositionTicks, accessToken, vttTimestampMapMpegts)); + } + + public static TheoryData GetSubtitleSegmentUrl_Success_TestData() + { + var data = new TheoryData(); + data.Add( + 0, + 300000000, + "abc123", + 0, + "stream.vtt?CopyTimestamps=true&AddVttTimeMap=true&StartPositionTicks=0&EndPositionTicks=300000000&ApiKey=abc123&VttTimestampMapMpegts=0"); + data.Add( + 300000000, + 600000000, + "abc123", + 900000, + "stream.vtt?CopyTimestamps=true&AddVttTimeMap=true&StartPositionTicks=300000000&EndPositionTicks=600000000&ApiKey=abc123&VttTimestampMapMpegts=900000"); + return data; + } } diff --git a/tests/Jellyfin.Api.Tests/Helpers/DynamicHlsHelperTests.cs b/tests/Jellyfin.Api.Tests/Helpers/DynamicHlsHelperTests.cs new file mode 100644 index 0000000000..d17ce0f896 --- /dev/null +++ b/tests/Jellyfin.Api.Tests/Helpers/DynamicHlsHelperTests.cs @@ -0,0 +1,26 @@ +using Jellyfin.Api.Helpers; +using Xunit; + +namespace Jellyfin.Api.Tests.Helpers +{ + public static class DynamicHlsHelperTests + { + [Theory] + [MemberData(nameof(GetVttTimestampMapMpegts_Success_TestData))] + public static void GetVttTimestampMapMpegts_Success(string? segmentContainer, long expected) + { + Assert.Equal(expected, DynamicHlsHelper.GetVttTimestampMapMpegts(segmentContainer)); + } + + public static TheoryData GetVttTimestampMapMpegts_Success_TestData() + { + var data = new TheoryData(); + data.Add(null, 900000); + data.Add(string.Empty, 900000); + data.Add("ts", 900000); + data.Add("mp4", 0); + data.Add("MP4", 0); + return data; + } + } +} -- cgit v1.2.3