2015-03-28 13:22:27 -07:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-04-01 15:23:07 -07:00
|
|
|
|
using MediaBrowser.Model.Dlna;
|
2014-04-22 17:50:47 -07:00
|
|
|
|
using MediaBrowser.Model.Drawing;
|
2015-03-28 13:22:27 -07:00
|
|
|
|
using MediaBrowser.Model.Dto;
|
2014-03-12 12:56:12 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-08-09 18:16:31 -07:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2014-04-05 08:02:50 -07:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2014-04-25 10:30:41 -07:00
|
|
|
|
using MediaBrowser.Model.MediaInfo;
|
2015-02-28 11:47:05 -07:00
|
|
|
|
using MediaBrowser.Model.Net;
|
2014-04-05 08:02:50 -07:00
|
|
|
|
using System;
|
2013-12-19 14:51:32 -07:00
|
|
|
|
using System.Collections.Generic;
|
2014-04-25 10:30:41 -07:00
|
|
|
|
using System.Globalization;
|
2013-12-19 14:51:32 -07:00
|
|
|
|
using System.IO;
|
2016-12-13 10:04:37 -07:00
|
|
|
|
using System.Linq;
|
2014-01-12 14:32:13 -07:00
|
|
|
|
using System.Threading;
|
2013-02-26 21:19:05 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.Playback
|
|
|
|
|
{
|
2014-04-05 08:02:50 -07:00
|
|
|
|
public class StreamState : IDisposable
|
2013-02-26 21:19:05 -07:00
|
|
|
|
{
|
2014-04-05 08:02:50 -07:00
|
|
|
|
private readonly ILogger _logger;
|
2015-03-28 13:22:27 -07:00
|
|
|
|
private readonly IMediaSourceManager _mediaSourceManager;
|
2014-04-05 08:02:50 -07:00
|
|
|
|
|
2013-12-19 14:51:32 -07:00
|
|
|
|
public string RequestedUrl { get; set; }
|
2013-02-26 21:19:05 -07:00
|
|
|
|
|
|
|
|
|
public StreamRequest Request { get; set; }
|
2015-02-28 11:47:05 -07:00
|
|
|
|
public TranscodingThrottler TranscodingThrottler { get; set; }
|
2013-02-26 21:19:05 -07:00
|
|
|
|
|
2013-03-08 19:34:54 -07:00
|
|
|
|
public VideoStreamRequest VideoRequest
|
|
|
|
|
{
|
2014-01-22 10:05:32 -07:00
|
|
|
|
get { return Request as VideoStreamRequest; }
|
2013-03-08 19:34:54 -07:00
|
|
|
|
}
|
2014-04-24 19:00:19 -07:00
|
|
|
|
|
2014-06-02 12:32:41 -07:00
|
|
|
|
public Dictionary<string, string> RemoteHttpHeaders { get; set; }
|
|
|
|
|
|
2013-02-26 21:19:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the log file stream.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The log file stream.</value>
|
|
|
|
|
public Stream LogFileStream { get; set; }
|
2016-10-05 00:15:29 -07:00
|
|
|
|
public IDirectStreamProvider DirectStreamProvider { get; set; }
|
2013-02-26 21:19:05 -07:00
|
|
|
|
|
2014-04-27 11:09:16 -07:00
|
|
|
|
public string InputContainer { get; set; }
|
2014-06-02 12:32:41 -07:00
|
|
|
|
|
2015-03-28 13:22:27 -07:00
|
|
|
|
public MediaSourceInfo MediaSource { get; set; }
|
2015-05-24 11:33:28 -07:00
|
|
|
|
|
2013-02-26 21:19:05 -07:00
|
|
|
|
public MediaStream AudioStream { get; set; }
|
|
|
|
|
public MediaStream VideoStream { get; set; }
|
|
|
|
|
public MediaStream SubtitleStream { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the iso mount.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The iso mount.</value>
|
|
|
|
|
public IIsoMount IsoMount { get; set; }
|
2013-12-19 14:51:32 -07:00
|
|
|
|
|
|
|
|
|
public string MediaPath { get; set; }
|
2015-03-17 23:02:22 -07:00
|
|
|
|
public string WaitForPath { get; set; }
|
2013-12-19 14:51:32 -07:00
|
|
|
|
|
2014-06-16 18:56:23 -07:00
|
|
|
|
public MediaProtocol InputProtocol { get; set; }
|
2013-12-19 14:51:32 -07:00
|
|
|
|
|
2015-05-24 11:33:28 -07:00
|
|
|
|
public bool IsOutputVideo
|
|
|
|
|
{
|
|
|
|
|
get { return Request is VideoStreamRequest; }
|
|
|
|
|
}
|
2013-12-19 14:51:32 -07:00
|
|
|
|
public bool IsInputVideo { get; set; }
|
|
|
|
|
|
|
|
|
|
public VideoType VideoType { get; set; }
|
|
|
|
|
public IsoType? IsoType { get; set; }
|
|
|
|
|
|
|
|
|
|
public List<string> PlayableStreamFileNames { get; set; }
|
2013-12-21 11:37:34 -07:00
|
|
|
|
|
2016-04-20 11:51:47 -07:00
|
|
|
|
public int SegmentLength
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2016-06-30 14:26:43 -07:00
|
|
|
|
var userAgent = UserAgent ?? string.Empty;
|
|
|
|
|
if (userAgent.IndexOf("AppleTV", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
|
{
|
|
|
|
|
return 10;
|
|
|
|
|
}
|
2016-08-04 22:12:25 -07:00
|
|
|
|
if (userAgent.IndexOf("cfnetwork", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
|
userAgent.IndexOf("ipad", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
|
userAgent.IndexOf("iphone", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
|
userAgent.IndexOf("ipod", StringComparison.OrdinalIgnoreCase) != -1)
|
2016-07-22 22:03:16 -07:00
|
|
|
|
{
|
|
|
|
|
return 10;
|
|
|
|
|
}
|
2016-06-30 14:26:43 -07:00
|
|
|
|
|
2017-01-07 01:09:24 -07:00
|
|
|
|
if (IsSegmentedLiveStream)
|
2016-09-25 11:39:13 -07:00
|
|
|
|
{
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
2017-01-07 01:09:24 -07:00
|
|
|
|
return 6;
|
2016-09-19 08:41:35 -07:00
|
|
|
|
}
|
2017-01-02 22:15:59 -07:00
|
|
|
|
|
2016-04-20 11:51:47 -07:00
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-07 01:09:24 -07:00
|
|
|
|
public bool IsSegmentedLiveStream
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return TranscodingType != TranscodingJobType.Progressive && !RunTimeTicks.HasValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 20:26:39 -07:00
|
|
|
|
public int HlsListSize
|
|
|
|
|
{
|
2014-11-10 20:41:55 -07:00
|
|
|
|
get
|
|
|
|
|
{
|
2015-09-09 10:49:44 -07:00
|
|
|
|
return 0;
|
2014-11-10 20:41:55 -07:00
|
|
|
|
}
|
2014-10-15 20:26:39 -07:00
|
|
|
|
}
|
2014-01-12 14:32:13 -07:00
|
|
|
|
|
|
|
|
|
public long? RunTimeTicks;
|
2014-01-14 22:05:19 -07:00
|
|
|
|
|
2014-08-29 05:14:41 -07:00
|
|
|
|
public long? InputBitrate { get; set; }
|
2014-09-01 13:10:54 -07:00
|
|
|
|
public long? InputFileSize { get; set; }
|
2014-08-29 05:14:41 -07:00
|
|
|
|
|
2014-04-22 17:50:47 -07:00
|
|
|
|
public string OutputAudioSync = "1";
|
2016-05-22 20:54:36 -07:00
|
|
|
|
public string OutputVideoSync = "-1";
|
2014-01-20 08:04:50 -07:00
|
|
|
|
|
2014-04-10 08:06:54 -07:00
|
|
|
|
public List<string> SupportedAudioCodecs { get; set; }
|
2016-09-04 22:39:14 -07:00
|
|
|
|
public List<string> SupportedVideoCodecs { get; set; }
|
2016-06-30 14:26:43 -07:00
|
|
|
|
public string UserAgent { get; set; }
|
2017-01-07 01:09:24 -07:00
|
|
|
|
public TranscodingJobType TranscodingType { get; set; }
|
2014-04-10 08:06:54 -07:00
|
|
|
|
|
2017-01-07 01:09:24 -07:00
|
|
|
|
public StreamState(IMediaSourceManager mediaSourceManager, ILogger logger, TranscodingJobType transcodingType)
|
2014-04-05 08:02:50 -07:00
|
|
|
|
{
|
2015-03-28 13:22:27 -07:00
|
|
|
|
_mediaSourceManager = mediaSourceManager;
|
2014-04-05 08:02:50 -07:00
|
|
|
|
_logger = logger;
|
2014-04-10 08:06:54 -07:00
|
|
|
|
SupportedAudioCodecs = new List<string>();
|
2016-09-04 22:39:14 -07:00
|
|
|
|
SupportedVideoCodecs = new List<string>();
|
2014-06-04 12:40:05 -07:00
|
|
|
|
PlayableStreamFileNames = new List<string>();
|
|
|
|
|
RemoteHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
2017-01-07 01:09:24 -07:00
|
|
|
|
TranscodingType = transcodingType;
|
2014-04-05 08:02:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-20 21:52:28 -07:00
|
|
|
|
public string InputAudioSync { get; set; }
|
|
|
|
|
public string InputVideoSync { get; set; }
|
2014-04-24 19:00:19 -07:00
|
|
|
|
|
2014-01-20 08:04:50 -07:00
|
|
|
|
public bool DeInterlace { get; set; }
|
2014-10-15 20:26:39 -07:00
|
|
|
|
|
2014-10-25 11:32:58 -07:00
|
|
|
|
public bool ReadInputAtNativeFramerate { get; set; }
|
2014-03-12 12:56:12 -07:00
|
|
|
|
|
2014-04-24 19:00:19 -07:00
|
|
|
|
public TransportStreamTimestamp InputTimestamp { get; set; }
|
|
|
|
|
|
2014-03-24 22:25:03 -07:00
|
|
|
|
public string MimeType { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool EstimateContentLength { get; set; }
|
|
|
|
|
public bool EnableMpegtsM2TsMode { get; set; }
|
|
|
|
|
public TranscodeSeekInfo TranscodeSeekInfo { get; set; }
|
2014-04-24 19:00:19 -07:00
|
|
|
|
|
2014-06-28 12:35:30 -07:00
|
|
|
|
public long? EncodingDurationTicks { get; set; }
|
|
|
|
|
|
2014-03-12 12:56:12 -07:00
|
|
|
|
public string GetMimeType(string outputPath)
|
|
|
|
|
{
|
2014-03-24 22:25:03 -07:00
|
|
|
|
if (!string.IsNullOrEmpty(MimeType))
|
|
|
|
|
{
|
|
|
|
|
return MimeType;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-12 12:56:12 -07:00
|
|
|
|
return MimeTypes.GetMimeType(outputPath);
|
|
|
|
|
}
|
2014-04-05 08:02:50 -07:00
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2015-02-28 11:47:05 -07:00
|
|
|
|
DisposeTranscodingThrottler();
|
2014-04-05 08:02:50 -07:00
|
|
|
|
DisposeLiveStream();
|
|
|
|
|
DisposeLogStream();
|
|
|
|
|
DisposeIsoMount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisposeLogStream()
|
|
|
|
|
{
|
|
|
|
|
if (LogFileStream != null)
|
|
|
|
|
{
|
2014-04-06 10:53:23 -07:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
LogFileStream.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error disposing log stream", ex);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-05 08:02:50 -07:00
|
|
|
|
LogFileStream = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-28 11:47:05 -07:00
|
|
|
|
private void DisposeTranscodingThrottler()
|
|
|
|
|
{
|
|
|
|
|
if (TranscodingThrottler != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
TranscodingThrottler.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error disposing TranscodingThrottler", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TranscodingThrottler = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-05 08:02:50 -07:00
|
|
|
|
private void DisposeIsoMount()
|
|
|
|
|
{
|
|
|
|
|
if (IsoMount != null)
|
|
|
|
|
{
|
2014-04-06 10:53:23 -07:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
IsoMount.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error disposing iso mount", ex);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-05 08:02:50 -07:00
|
|
|
|
IsoMount = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void DisposeLiveStream()
|
|
|
|
|
{
|
2016-07-27 23:29:14 -07:00
|
|
|
|
if (MediaSource.RequiresClosing && string.IsNullOrWhiteSpace(Request.LiveStreamId) && !string.IsNullOrWhiteSpace(MediaSource.LiveStreamId))
|
2014-04-05 08:02:50 -07:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-09-29 05:55:49 -07:00
|
|
|
|
await _mediaSourceManager.CloseLiveStream(MediaSource.LiveStreamId).ConfigureAwait(false);
|
2014-04-05 08:02:50 -07:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2015-03-28 13:22:27 -07:00
|
|
|
|
_logger.ErrorException("Error closing media source", ex);
|
2014-04-05 08:02:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-22 17:50:47 -07:00
|
|
|
|
|
2014-06-11 19:38:40 -07:00
|
|
|
|
public int InternalSubtitleStreamOffset { get; set; }
|
|
|
|
|
|
2014-06-05 17:39:02 -07:00
|
|
|
|
public string OutputFilePath { get; set; }
|
|
|
|
|
public string OutputVideoCodec { get; set; }
|
|
|
|
|
public string OutputAudioCodec { get; set; }
|
2014-04-22 17:50:47 -07:00
|
|
|
|
public int? OutputAudioChannels;
|
|
|
|
|
public int? OutputAudioSampleRate;
|
|
|
|
|
public int? OutputAudioBitrate;
|
|
|
|
|
public int? OutputVideoBitrate;
|
|
|
|
|
|
2014-10-19 20:04:45 -07:00
|
|
|
|
public string ActualOutputVideoCodec
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var codec = OutputVideoCodec;
|
|
|
|
|
|
|
|
|
|
if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var stream = VideoStream;
|
|
|
|
|
|
|
|
|
|
if (stream != null)
|
|
|
|
|
{
|
|
|
|
|
return stream.Codec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return codec;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ActualOutputAudioCodec
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var codec = OutputAudioCodec;
|
|
|
|
|
|
|
|
|
|
if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var stream = AudioStream;
|
|
|
|
|
|
|
|
|
|
if (stream != null)
|
|
|
|
|
{
|
|
|
|
|
return stream.Codec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return codec;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 17:50:47 -07:00
|
|
|
|
public string OutputContainer { get; set; }
|
|
|
|
|
|
2014-04-22 19:47:46 -07:00
|
|
|
|
public DeviceProfile DeviceProfile { get; set; }
|
|
|
|
|
|
2014-04-22 17:50:47 -07:00
|
|
|
|
public int? TotalOutputBitrate
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return (OutputAudioBitrate ?? 0) + (OutputVideoBitrate ?? 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int? OutputWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (VideoStream != null && VideoStream.Width.HasValue && VideoStream.Height.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var size = new ImageSize
|
|
|
|
|
{
|
|
|
|
|
Width = VideoStream.Width.Value,
|
|
|
|
|
Height = VideoStream.Height.Value
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var newSize = DrawingUtils.Resize(size,
|
|
|
|
|
VideoRequest.Width,
|
|
|
|
|
VideoRequest.Height,
|
|
|
|
|
VideoRequest.MaxWidth,
|
|
|
|
|
VideoRequest.MaxHeight);
|
|
|
|
|
|
|
|
|
|
return Convert.ToInt32(newSize.Width);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 10:14:02 -07:00
|
|
|
|
if (VideoRequest == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 17:50:47 -07:00
|
|
|
|
return VideoRequest.MaxWidth ?? VideoRequest.Width;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int? OutputHeight
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (VideoStream != null && VideoStream.Width.HasValue && VideoStream.Height.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var size = new ImageSize
|
|
|
|
|
{
|
|
|
|
|
Width = VideoStream.Width.Value,
|
|
|
|
|
Height = VideoStream.Height.Value
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var newSize = DrawingUtils.Resize(size,
|
|
|
|
|
VideoRequest.Width,
|
|
|
|
|
VideoRequest.Height,
|
|
|
|
|
VideoRequest.MaxWidth,
|
|
|
|
|
VideoRequest.MaxHeight);
|
|
|
|
|
|
|
|
|
|
return Convert.ToInt32(newSize.Height);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 10:14:02 -07:00
|
|
|
|
if (VideoRequest == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 17:50:47 -07:00
|
|
|
|
return VideoRequest.MaxHeight ?? VideoRequest.Height;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-23 22:08:10 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Predicts the audio sample rate that will be in the output stream
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int? TargetVideoBitDepth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var stream = VideoStream;
|
|
|
|
|
return stream == null || !Request.Static ? null : stream.BitDepth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-08 18:15:31 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the target reference frames.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The target reference frames.</value>
|
|
|
|
|
public int? TargetRefFrames
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var stream = VideoStream;
|
|
|
|
|
return stream == null || !Request.Static ? null : stream.RefFrames;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-30 09:16:34 -07:00
|
|
|
|
public int? TargetVideoStreamCount
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Request.Static)
|
|
|
|
|
{
|
|
|
|
|
return GetMediaStreamCount(MediaStreamType.Video, int.MaxValue);
|
|
|
|
|
}
|
|
|
|
|
return GetMediaStreamCount(MediaStreamType.Video, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int? TargetAudioStreamCount
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Request.Static)
|
|
|
|
|
{
|
|
|
|
|
return GetMediaStreamCount(MediaStreamType.Audio, int.MaxValue);
|
|
|
|
|
}
|
|
|
|
|
return GetMediaStreamCount(MediaStreamType.Audio, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int? GetMediaStreamCount(MediaStreamType type, int limit)
|
|
|
|
|
{
|
|
|
|
|
var count = MediaSource.GetStreamCount(type);
|
|
|
|
|
|
|
|
|
|
if (count.HasValue)
|
|
|
|
|
{
|
|
|
|
|
count = Math.Min(count.Value, limit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 22:08:10 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Predicts the audio sample rate that will be in the output stream
|
|
|
|
|
/// </summary>
|
2014-06-23 09:05:19 -07:00
|
|
|
|
public float? TargetFramerate
|
2014-04-23 22:08:10 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var stream = VideoStream;
|
|
|
|
|
var requestedFramerate = VideoRequest.MaxFramerate ?? VideoRequest.Framerate;
|
|
|
|
|
|
|
|
|
|
return requestedFramerate.HasValue && !Request.Static
|
|
|
|
|
? requestedFramerate
|
|
|
|
|
: stream == null ? null : stream.AverageFrameRate ?? stream.RealFrameRate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Predicts the audio sample rate that will be in the output stream
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double? TargetVideoLevel
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var stream = VideoStream;
|
|
|
|
|
return !string.IsNullOrEmpty(VideoRequest.Level) && !Request.Static
|
|
|
|
|
? double.Parse(VideoRequest.Level, CultureInfo.InvariantCulture)
|
|
|
|
|
: stream == null ? null : stream.Level;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TransportStreamTimestamp TargetTimestamp
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-06-02 12:32:41 -07:00
|
|
|
|
var defaultValue = string.Equals(OutputContainer, "m2ts", StringComparison.OrdinalIgnoreCase) ?
|
|
|
|
|
TransportStreamTimestamp.Valid :
|
2014-04-24 19:45:06 -07:00
|
|
|
|
TransportStreamTimestamp.None;
|
2014-04-23 22:08:10 -07:00
|
|
|
|
|
|
|
|
|
return !Request.Static
|
2014-04-24 19:00:19 -07:00
|
|
|
|
? defaultValue
|
|
|
|
|
: InputTimestamp;
|
2014-04-23 22:08:10 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Predicts the audio sample rate that will be in the output stream
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int? TargetPacketLength
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var stream = VideoStream;
|
|
|
|
|
return !Request.Static
|
|
|
|
|
? null
|
|
|
|
|
: stream == null ? null : stream.PacketLength;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Predicts the audio sample rate that will be in the output stream
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string TargetVideoProfile
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var stream = VideoStream;
|
|
|
|
|
return !string.IsNullOrEmpty(VideoRequest.Profile) && !Request.Static
|
|
|
|
|
? VideoRequest.Profile
|
|
|
|
|
: stream == null ? null : stream.Profile;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 09:05:03 -07:00
|
|
|
|
public string TargetVideoCodecTag
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var stream = VideoStream;
|
|
|
|
|
return !Request.Static
|
|
|
|
|
? null
|
|
|
|
|
: stream == null ? null : stream.CodecTag;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-22 09:25:47 -07:00
|
|
|
|
public bool? IsTargetAnamorphic
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Request.Static)
|
|
|
|
|
{
|
|
|
|
|
return VideoStream == null ? null : VideoStream.IsAnamorphic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-02 23:28:45 -07:00
|
|
|
|
|
|
|
|
|
public bool? IsTargetAVC
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Request.Static)
|
|
|
|
|
{
|
|
|
|
|
return VideoStream == null ? null : VideoStream.IsAVC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-26 21:19:05 -07:00
|
|
|
|
}
|
|
|
|
|
}
|