You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
184 lines
5.3 KiB
184 lines
5.3 KiB
4 years ago
|
using System;
|
||
|
using MediaBrowser.Controller.Library;
|
||
|
using MediaBrowser.Controller.MediaEncoding;
|
||
|
using MediaBrowser.Model.Dlna;
|
||
|
|
||
1 year ago
|
namespace MediaBrowser.Controller.Streaming;
|
||
2 years ago
|
|
||
|
/// <summary>
|
||
|
/// The stream state dto.
|
||
|
/// </summary>
|
||
|
public class StreamState : EncodingJobInfo, IDisposable
|
||
4 years ago
|
{
|
||
2 years ago
|
private readonly IMediaSourceManager _mediaSourceManager;
|
||
1 year ago
|
private readonly ITranscodeManager _transcodeManager;
|
||
2 years ago
|
private bool _disposed;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Initializes a new instance of the <see cref="StreamState" /> class.
|
||
|
/// </summary>
|
||
|
/// <param name="mediaSourceManager">Instance of the <see cref="IMediaSourceManager" /> interface.</param>
|
||
|
/// <param name="transcodingType">The <see cref="TranscodingJobType" />.</param>
|
||
1 year ago
|
/// <param name="transcodeManager">The <see cref="ITranscodeManager" /> singleton.</param>
|
||
|
public StreamState(IMediaSourceManager mediaSourceManager, TranscodingJobType transcodingType, ITranscodeManager transcodeManager)
|
||
2 years ago
|
: base(transcodingType)
|
||
|
{
|
||
|
_mediaSourceManager = mediaSourceManager;
|
||
1 year ago
|
_transcodeManager = transcodeManager;
|
||
2 years ago
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Gets or sets the requested url.
|
||
|
/// </summary>
|
||
|
public string? RequestedUrl { get; set; }
|
||
|
|
||
4 years ago
|
/// <summary>
|
||
2 years ago
|
/// Gets or sets the request.
|
||
4 years ago
|
/// </summary>
|
||
2 years ago
|
public StreamingRequestDto Request
|
||
4 years ago
|
{
|
||
2 years ago
|
get => (StreamingRequestDto)BaseRequest;
|
||
|
set
|
||
4 years ago
|
{
|
||
2 years ago
|
BaseRequest = value;
|
||
|
IsVideoRequest = VideoRequest is not null;
|
||
4 years ago
|
}
|
||
2 years ago
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Gets the video request.
|
||
|
/// </summary>
|
||
|
public VideoRequestDto? VideoRequest => Request as VideoRequestDto;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Gets or sets the direct stream provicer.
|
||
|
/// </summary>
|
||
|
/// <remarks>
|
||
|
/// Deprecated.
|
||
|
/// </remarks>
|
||
|
public IDirectStreamProvider? DirectStreamProvider { get; set; }
|
||
|
|
||
|
/// <summary>
|
||
|
/// Gets or sets the path to wait for.
|
||
|
/// </summary>
|
||
|
public string? WaitForPath { get; set; }
|
||
4 years ago
|
|
||
2 years ago
|
/// <summary>
|
||
|
/// Gets a value indicating whether the request outputs video.
|
||
|
/// </summary>
|
||
|
public bool IsOutputVideo => Request is VideoRequestDto;
|
||
4 years ago
|
|
||
2 years ago
|
/// <summary>
|
||
|
/// Gets the segment length.
|
||
|
/// </summary>
|
||
|
public int SegmentLength
|
||
|
{
|
||
|
get
|
||
4 years ago
|
{
|
||
2 years ago
|
if (Request.SegmentLength.HasValue)
|
||
4 years ago
|
{
|
||
2 years ago
|
return Request.SegmentLength.Value;
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
2 years ago
|
if (EncodingHelper.IsCopyCodec(OutputVideoCodec))
|
||
4 years ago
|
{
|
||
2 years ago
|
var userAgent = UserAgent ?? string.Empty;
|
||
|
|
||
1 year ago
|
if (userAgent.Contains("AppleTV", StringComparison.OrdinalIgnoreCase)
|
||
|
|| userAgent.Contains("cfnetwork", StringComparison.OrdinalIgnoreCase)
|
||
|
|| userAgent.Contains("ipad", StringComparison.OrdinalIgnoreCase)
|
||
|
|| userAgent.Contains("iphone", StringComparison.OrdinalIgnoreCase)
|
||
|
|| userAgent.Contains("ipod", StringComparison.OrdinalIgnoreCase))
|
||
4 years ago
|
{
|
||
2 years ago
|
return 6;
|
||
4 years ago
|
}
|
||
|
|
||
2 years ago
|
if (IsSegmentedLiveStream)
|
||
4 years ago
|
{
|
||
2 years ago
|
return 3;
|
||
4 years ago
|
}
|
||
|
|
||
2 years ago
|
return 6;
|
||
4 years ago
|
}
|
||
2 years ago
|
|
||
|
return 3;
|
||
4 years ago
|
}
|
||
2 years ago
|
}
|
||
4 years ago
|
|
||
2 years ago
|
/// <summary>
|
||
|
/// Gets the minimum number of segments.
|
||
|
/// </summary>
|
||
|
public int MinSegments
|
||
|
{
|
||
|
get
|
||
4 years ago
|
{
|
||
2 years ago
|
if (Request.MinSegments.HasValue)
|
||
4 years ago
|
{
|
||
2 years ago
|
return Request.MinSegments.Value;
|
||
4 years ago
|
}
|
||
|
|
||
2 years ago
|
return SegmentLength >= 10 ? 2 : 3;
|
||
4 years ago
|
}
|
||
2 years ago
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Gets or sets the user agent.
|
||
|
/// </summary>
|
||
|
public string? UserAgent { get; set; }
|
||
|
|
||
|
/// <summary>
|
||
|
/// Gets or sets a value indicating whether to estimate the content length.
|
||
|
/// </summary>
|
||
|
public bool EstimateContentLength { get; set; }
|
||
|
|
||
|
/// <summary>
|
||
|
/// Gets or sets the transcode seek info.
|
||
|
/// </summary>
|
||
|
public TranscodeSeekInfo TranscodeSeekInfo { get; set; }
|
||
|
|
||
|
/// <summary>
|
||
|
/// Gets or sets the transcoding job.
|
||
|
/// </summary>
|
||
1 year ago
|
public TranscodingJob? TranscodingJob { get; set; }
|
||
2 years ago
|
|
||
|
/// <inheritdoc />
|
||
|
public void Dispose()
|
||
|
{
|
||
|
Dispose(true);
|
||
|
GC.SuppressFinalize(this);
|
||
|
}
|
||
|
|
||
|
/// <inheritdoc />
|
||
|
public override void ReportTranscodingProgress(TimeSpan? transcodingPosition, float? framerate, double? percentComplete, long? bytesTranscoded, int? bitRate)
|
||
|
{
|
||
1 year ago
|
_transcodeManager.ReportTranscodingProgress(TranscodingJob!, this, transcodingPosition, framerate, percentComplete, bytesTranscoded, bitRate);
|
||
2 years ago
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Disposes the stream state.
|
||
|
/// </summary>
|
||
|
/// <param name="disposing">Whether the object is currently being disposed.</param>
|
||
|
protected virtual void Dispose(bool disposing)
|
||
|
{
|
||
|
if (_disposed)
|
||
4 years ago
|
{
|
||
2 years ago
|
return;
|
||
4 years ago
|
}
|
||
|
|
||
2 years ago
|
if (disposing)
|
||
4 years ago
|
{
|
||
2 years ago
|
// REVIEW: Is this the right place for this?
|
||
|
if (MediaSource.RequiresClosing
|
||
|
&& string.IsNullOrWhiteSpace(Request.LiveStreamId)
|
||
|
&& !string.IsNullOrWhiteSpace(MediaSource.LiveStreamId))
|
||
4 years ago
|
{
|
||
2 years ago
|
_mediaSourceManager.CloseLiveStream(MediaSource.LiveStreamId).GetAwaiter().GetResult();
|
||
4 years ago
|
}
|
||
2 years ago
|
}
|
||
4 years ago
|
|
||
2 years ago
|
TranscodingJob = null;
|
||
4 years ago
|
|
||
2 years ago
|
_disposed = true;
|
||
4 years ago
|
}
|
||
|
}
|