< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Streaming.StreamState
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Streaming/StreamState.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 42
Coverable lines: 42
Total lines: 183
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 32
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
get_Request()100%210%
set_Request(...)100%210%
get_VideoRequest()100%210%
get_IsOutputVideo()100%210%
get_SegmentLength()0%342180%
get_MinSegments()0%2040%
Dispose()100%210%
ReportTranscodingProgress(...)100%210%
Dispose(...)0%110100%

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/Streaming/StreamState.cs

#LineLine coverage
 1using System;
 2using MediaBrowser.Controller.Library;
 3using MediaBrowser.Controller.MediaEncoding;
 4using MediaBrowser.Model.Dlna;
 5
 6namespace MediaBrowser.Controller.Streaming;
 7
 8/// <summary>
 9/// The stream state dto.
 10/// </summary>
 11public class StreamState : EncodingJobInfo, IDisposable
 12{
 13    private readonly IMediaSourceManager _mediaSourceManager;
 14    private readonly ITranscodeManager _transcodeManager;
 15    private bool _disposed;
 16
 17    /// <summary>
 18    /// Initializes a new instance of the <see cref="StreamState" /> class.
 19    /// </summary>
 20    /// <param name="mediaSourceManager">Instance of the <see cref="IMediaSourceManager" /> interface.</param>
 21    /// <param name="transcodingType">The <see cref="TranscodingJobType" />.</param>
 22    /// <param name="transcodeManager">The <see cref="ITranscodeManager" /> singleton.</param>
 23    public StreamState(IMediaSourceManager mediaSourceManager, TranscodingJobType transcodingType, ITranscodeManager tra
 024        : base(transcodingType)
 25    {
 026        _mediaSourceManager = mediaSourceManager;
 027        _transcodeManager = transcodeManager;
 028    }
 29
 30    /// <summary>
 31    /// Gets or sets the requested url.
 32    /// </summary>
 33    public string? RequestedUrl { get; set; }
 34
 35    /// <summary>
 36    /// Gets or sets the request.
 37    /// </summary>
 38    public StreamingRequestDto Request
 39    {
 040        get => (StreamingRequestDto)BaseRequest;
 41        set
 42        {
 043            BaseRequest = value;
 044            IsVideoRequest = VideoRequest is not null;
 045        }
 46    }
 47
 48    /// <summary>
 49    /// Gets the video request.
 50    /// </summary>
 051    public VideoRequestDto? VideoRequest => Request as VideoRequestDto;
 52
 53    /// <summary>
 54    /// Gets or sets the direct stream provicer.
 55    /// </summary>
 56    /// <remarks>
 57    /// Deprecated.
 58    /// </remarks>
 59    public IDirectStreamProvider? DirectStreamProvider { get; set; }
 60
 61    /// <summary>
 62    /// Gets or sets the path to wait for.
 63    /// </summary>
 64    public string? WaitForPath { get; set; }
 65
 66    /// <summary>
 67    /// Gets a value indicating whether the request outputs video.
 68    /// </summary>
 069    public bool IsOutputVideo => Request is VideoRequestDto;
 70
 71    /// <summary>
 72    /// Gets the segment length.
 73    /// </summary>
 74    public int SegmentLength
 75    {
 76        get
 77        {
 078            if (Request.SegmentLength.HasValue)
 79            {
 080                return Request.SegmentLength.Value;
 81            }
 82
 083            if (EncodingHelper.IsCopyCodec(OutputVideoCodec))
 84            {
 085                var userAgent = UserAgent ?? string.Empty;
 86
 087                if (userAgent.Contains("AppleTV", StringComparison.OrdinalIgnoreCase)
 088                    || userAgent.Contains("cfnetwork", StringComparison.OrdinalIgnoreCase)
 089                    || userAgent.Contains("ipad", StringComparison.OrdinalIgnoreCase)
 090                    || userAgent.Contains("iphone", StringComparison.OrdinalIgnoreCase)
 091                    || userAgent.Contains("ipod", StringComparison.OrdinalIgnoreCase))
 92                {
 093                    return 6;
 94                }
 95
 096                if (IsSegmentedLiveStream)
 97                {
 098                    return 3;
 99                }
 100
 0101                return 6;
 102            }
 103
 0104            return 3;
 105        }
 106    }
 107
 108    /// <summary>
 109    /// Gets the minimum number of segments.
 110    /// </summary>
 111    public int MinSegments
 112    {
 113        get
 114        {
 0115            if (Request.MinSegments.HasValue)
 116            {
 0117                return Request.MinSegments.Value;
 118            }
 119
 0120            return SegmentLength >= 10 ? 2 : 3;
 121        }
 122    }
 123
 124    /// <summary>
 125    /// Gets or sets the user agent.
 126    /// </summary>
 127    public string? UserAgent { get; set; }
 128
 129    /// <summary>
 130    /// Gets or sets a value indicating whether to estimate the content length.
 131    /// </summary>
 132    public bool EstimateContentLength { get; set; }
 133
 134    /// <summary>
 135    /// Gets or sets the transcode seek info.
 136    /// </summary>
 137    public TranscodeSeekInfo TranscodeSeekInfo { get; set; }
 138
 139    /// <summary>
 140    /// Gets or sets the transcoding job.
 141    /// </summary>
 142    public TranscodingJob? TranscodingJob { get; set; }
 143
 144    /// <inheritdoc />
 145    public void Dispose()
 146    {
 0147        Dispose(true);
 0148        GC.SuppressFinalize(this);
 0149    }
 150
 151    /// <inheritdoc />
 152    public override void ReportTranscodingProgress(TimeSpan? transcodingPosition, float? framerate, double? percentCompl
 153    {
 0154        _transcodeManager.ReportTranscodingProgress(TranscodingJob!, this, transcodingPosition, framerate, percentComple
 0155    }
 156
 157    /// <summary>
 158    /// Disposes the stream state.
 159    /// </summary>
 160    /// <param name="disposing">Whether the object is currently being disposed.</param>
 161    protected virtual void Dispose(bool disposing)
 162    {
 0163        if (_disposed)
 164        {
 0165            return;
 166        }
 167
 0168        if (disposing)
 169        {
 170            // REVIEW: Is this the right place for this?
 0171            if (MediaSource.RequiresClosing
 0172                && string.IsNullOrWhiteSpace(Request.LiveStreamId)
 0173                && !string.IsNullOrWhiteSpace(MediaSource.LiveStreamId))
 174            {
 0175                _mediaSourceManager.CloseLiveStream(MediaSource.LiveStreamId).GetAwaiter().GetResult();
 176            }
 177        }
 178
 0179        TranscodingJob = null;
 180
 0181        _disposed = true;
 0182    }
 183}