aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/MediaEncoding/TranscodingJob.cs
diff options
context:
space:
mode:
authorKGT1 <kilian.gamn@gmx.de>2026-10-17 16:51:55 +0200
committerGitHub <noreply@github.com>2026-10-17 16:51:55 +0200
commit292b13d1daf36316274211a8b3c13385c60efdb5 (patch)
tree1204df8423af2f317dbf3171aa7a42b1413b4e2e /MediaBrowser.Controller/MediaEncoding/TranscodingJob.cs
parent0be145c4e202bac0edc36b769f8b4db2232ad216 (diff)
parent08c2ba6e0b6499122822f1c5b18bc426104538b4 (diff)
Merge branch 'jellyfin:master' into removeGenericConfigurationEndpoint
Diffstat (limited to 'MediaBrowser.Controller/MediaEncoding/TranscodingJob.cs')
-rw-r--r--MediaBrowser.Controller/MediaEncoding/TranscodingJob.cs57
1 files changed, 56 insertions, 1 deletions
diff --git a/MediaBrowser.Controller/MediaEncoding/TranscodingJob.cs b/MediaBrowser.Controller/MediaEncoding/TranscodingJob.cs
index 56990d0b82..12600af384 100644
--- a/MediaBrowser.Controller/MediaEncoding/TranscodingJob.cs
+++ b/MediaBrowser.Controller/MediaEncoding/TranscodingJob.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Concurrent;
using System.Diagnostics;
using System.Threading;
using MediaBrowser.Model.Dto;
@@ -14,7 +15,9 @@ public sealed class TranscodingJob : IDisposable
private readonly ILogger<TranscodingJob> _logger;
private readonly Lock _processLock = new();
private readonly Lock _timerLock = new();
+ private readonly ConcurrentDictionary<int, long> _segmentEndPositionTicks = new();
+ private int _activeRequestCount;
private Timer? _killTimer;
/// <summary>
@@ -64,7 +67,11 @@ public sealed class TranscodingJob : IDisposable
/// <summary>
/// Gets or sets the active request count.
/// </summary>
- public int ActiveRequestCount { get; set; }
+ public int ActiveRequestCount
+ {
+ get => Volatile.Read(ref _activeRequestCount);
+ set => Volatile.Write(ref _activeRequestCount, value);
+ }
/// <summary>
/// Gets or sets device id.
@@ -152,6 +159,54 @@ public sealed class TranscodingJob : IDisposable
public int PingTimeout { get; set; }
/// <summary>
+ /// Records the end position of a served segment.
+ /// </summary>
+ /// <param name="segmentIndex">The segment index.</param>
+ /// <param name="segmentEndPositionTicks">The segment end position ticks.</param>
+ public void ReportSegmentDownloaded(int segmentIndex, long segmentEndPositionTicks)
+ {
+ if (segmentIndex < 0)
+ {
+ return;
+ }
+
+ _segmentEndPositionTicks[segmentIndex] = segmentEndPositionTicks;
+ }
+
+ /// <summary>
+ /// Gets the highest index among served segments whose end position is at or before the given position.
+ /// </summary>
+ /// <param name="positionTicks">The position ticks.</param>
+ /// <returns>The segment index, or <c>null</c> if there is none.</returns>
+ public int? GetHighestServedSegmentIndexEndingAtOrBefore(long positionTicks)
+ {
+ int? result = null;
+ foreach (var (index, endPositionTicks) in _segmentEndPositionTicks)
+ {
+ if (endPositionTicks <= positionTicks && (result is null || index > result))
+ {
+ result = index;
+ }
+ }
+
+ return result;
+ }
+
+ /// <summary>
+ /// Increments the active request count.
+ /// </summary>
+ /// <returns>The incremented count.</returns>
+ public int IncrementActiveRequestCount()
+ => Interlocked.Increment(ref _activeRequestCount);
+
+ /// <summary>
+ /// Decrements the active request count.
+ /// </summary>
+ /// <returns>The decremented count.</returns>
+ public int DecrementActiveRequestCount()
+ => Interlocked.Decrement(ref _activeRequestCount);
+
+ /// <summary>
/// Stop kill timer.
/// </summary>
public void StopKillTimer()