2019-01-13 20:01:16 +00:00
|
|
|
using System;
|
2019-01-13 19:24:58 +00:00
|
|
|
using MediaBrowser.Controller.Library;
|
2018-12-14 09:40:55 +00:00
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
2019-01-13 19:24:58 +00:00
|
|
|
using MediaBrowser.Model.Dlna;
|
2018-12-14 09:40:55 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.Api.Playback
|
|
|
|
{
|
|
|
|
public class StreamState : EncodingJobInfo, IDisposable
|
|
|
|
{
|
|
|
|
private readonly IMediaSourceManager _mediaSourceManager;
|
2019-03-26 21:56:05 +00:00
|
|
|
private bool _disposed = false;
|
2018-12-14 09:40:55 +00:00
|
|
|
|
|
|
|
public string RequestedUrl { get; set; }
|
|
|
|
|
|
|
|
public StreamRequest Request
|
|
|
|
{
|
2019-01-13 20:31:14 +00:00
|
|
|
get => (StreamRequest)BaseRequest;
|
2018-12-14 09:40:55 +00:00
|
|
|
set
|
|
|
|
{
|
|
|
|
BaseRequest = value;
|
|
|
|
|
|
|
|
IsVideoRequest = VideoRequest != null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public TranscodingThrottler TranscodingThrottler { get; set; }
|
|
|
|
|
2019-01-13 20:31:14 +00:00
|
|
|
public VideoStreamRequest VideoRequest => Request as VideoStreamRequest;
|
2018-12-14 09:40:55 +00:00
|
|
|
|
|
|
|
public IDirectStreamProvider DirectStreamProvider { get; set; }
|
|
|
|
|
|
|
|
public string WaitForPath { get; set; }
|
|
|
|
|
2019-01-13 20:31:14 +00:00
|
|
|
public bool IsOutputVideo => Request is VideoStreamRequest;
|
2018-12-14 09:40:55 +00:00
|
|
|
|
|
|
|
public int SegmentLength
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (Request.SegmentLength.HasValue)
|
|
|
|
{
|
|
|
|
return Request.SegmentLength.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
var userAgent = UserAgent ?? string.Empty;
|
|
|
|
|
|
|
|
if (userAgent.IndexOf("AppleTV", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
userAgent.IndexOf("cfnetwork", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
userAgent.IndexOf("ipad", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
userAgent.IndexOf("iphone", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
userAgent.IndexOf("ipod", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
{
|
|
|
|
if (IsSegmentedLiveStream)
|
|
|
|
{
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsSegmentedLiveStream)
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
2019-03-26 21:56:05 +00:00
|
|
|
|
2018-12-14 09:40:55 +00:00
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int MinSegments
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (Request.MinSegments.HasValue)
|
|
|
|
{
|
|
|
|
return Request.MinSegments.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SegmentLength >= 10 ? 2 : 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string UserAgent { get; set; }
|
|
|
|
|
2019-03-26 21:56:05 +00:00
|
|
|
public bool EstimateContentLength { get; set; }
|
|
|
|
|
|
|
|
public TranscodeSeekInfo TranscodeSeekInfo { get; set; }
|
|
|
|
|
|
|
|
public bool EnableDlnaHeaders { get; set; }
|
|
|
|
|
|
|
|
public DeviceProfile DeviceProfile { get; set; }
|
|
|
|
|
|
|
|
public TranscodingJob TranscodingJob { get; set; }
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
public StreamState(IMediaSourceManager mediaSourceManager, TranscodingJobType transcodingType)
|
2019-01-13 01:06:59 +00:00
|
|
|
: base(transcodingType)
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
|
|
|
_mediaSourceManager = mediaSourceManager;
|
|
|
|
}
|
|
|
|
|
2019-03-26 21:56:05 +00:00
|
|
|
public override void ReportTranscodingProgress(TimeSpan? transcodingPosition, float framerate, double? percentComplete, long bytesTranscoded, int? bitRate)
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
2019-03-26 21:56:05 +00:00
|
|
|
ApiEntryPoint.Instance.ReportTranscodingProgress(TranscodingJob, this, transcodingPosition, framerate, percentComplete, bytesTranscoded, bitRate);
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 21:56:05 +00:00
|
|
|
public void Dispose()
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
2019-03-26 21:56:05 +00:00
|
|
|
Dispose(true);
|
|
|
|
GC.SuppressFinalize(this);
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 21:56:05 +00:00
|
|
|
protected virtual void Dispose(bool disposing)
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
2019-03-26 21:56:05 +00:00
|
|
|
if (_disposed)
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
2019-03-26 21:56:05 +00:00
|
|
|
return;
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 21:56:05 +00:00
|
|
|
if (disposing)
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
2019-03-26 21:56:05 +00:00
|
|
|
// REVIEW: Is this the right place for this?
|
|
|
|
if (MediaSource.RequiresClosing
|
|
|
|
&& string.IsNullOrWhiteSpace(Request.LiveStreamId)
|
|
|
|
&& !string.IsNullOrWhiteSpace(MediaSource.LiveStreamId))
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
2019-03-26 21:56:05 +00:00
|
|
|
_mediaSourceManager.CloseLiveStream(MediaSource.LiveStreamId).GetAwaiter().GetResult();
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
2019-03-26 21:56:05 +00:00
|
|
|
|
|
|
|
TranscodingThrottler?.Dispose();
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 21:56:05 +00:00
|
|
|
TranscodingThrottler = null;
|
|
|
|
TranscodingJob = null;
|
2018-12-14 09:40:55 +00:00
|
|
|
|
2019-03-26 21:56:05 +00:00
|
|
|
_disposed = true;
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|