2014-03-12 19:56:12 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2014-04-05 15:02:50 +00:00
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
2014-04-01 22:23:07 +00:00
|
|
|
|
using MediaBrowser.Model.Dlna;
|
2014-03-12 19:56:12 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-08-10 01:16:31 +00:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2014-04-05 15:02:50 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
2013-12-19 21:51:32 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2014-01-12 21:32:13 +00:00
|
|
|
|
using System.Threading;
|
2013-02-27 04:19:05 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.Playback
|
|
|
|
|
{
|
2014-04-05 15:02:50 +00:00
|
|
|
|
public class StreamState : IDisposable
|
2013-02-27 04:19:05 +00:00
|
|
|
|
{
|
2014-04-05 15:02:50 +00:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly ILiveTvManager _liveTvManager;
|
|
|
|
|
|
2013-12-19 21:51:32 +00:00
|
|
|
|
public string RequestedUrl { get; set; }
|
2013-02-27 04:19:05 +00:00
|
|
|
|
|
|
|
|
|
public StreamRequest Request { get; set; }
|
|
|
|
|
|
2013-03-09 02:34:54 +00:00
|
|
|
|
public VideoStreamRequest VideoRequest
|
|
|
|
|
{
|
2014-01-22 17:05:32 +00:00
|
|
|
|
get { return Request as VideoStreamRequest; }
|
2013-03-09 02:34:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 04:19:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the log file stream.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The log file stream.</value>
|
|
|
|
|
public Stream LogFileStream { get; set; }
|
|
|
|
|
|
|
|
|
|
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 21:51:32 +00:00
|
|
|
|
|
|
|
|
|
public string MediaPath { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IsRemote { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IsInputVideo { get; set; }
|
|
|
|
|
|
|
|
|
|
public VideoType VideoType { get; set; }
|
|
|
|
|
|
|
|
|
|
public IsoType? IsoType { get; set; }
|
|
|
|
|
|
|
|
|
|
public List<string> PlayableStreamFileNames { get; set; }
|
2013-12-21 18:37:34 +00:00
|
|
|
|
|
|
|
|
|
public bool HasMediaStreams { get; set; }
|
2014-01-03 04:58:22 +00:00
|
|
|
|
|
2014-01-05 06:50:48 +00:00
|
|
|
|
public string LiveTvStreamId { get; set; }
|
2014-01-12 21:32:13 +00:00
|
|
|
|
|
|
|
|
|
public int SegmentLength = 10;
|
2014-03-04 04:58:19 +00:00
|
|
|
|
public int HlsListSize;
|
2014-01-12 21:32:13 +00:00
|
|
|
|
|
|
|
|
|
public long? RunTimeTicks;
|
2014-01-15 05:05:19 +00:00
|
|
|
|
|
2014-01-24 18:09:50 +00:00
|
|
|
|
public string AudioSync = "1";
|
|
|
|
|
public string VideoSync = "vfr";
|
2014-01-20 15:04:50 +00:00
|
|
|
|
|
2014-04-10 15:06:54 +00:00
|
|
|
|
public List<string> SupportedAudioCodecs { get; set; }
|
|
|
|
|
|
2014-04-05 15:02:50 +00:00
|
|
|
|
public StreamState(ILiveTvManager liveTvManager, ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
_liveTvManager = liveTvManager;
|
|
|
|
|
_logger = logger;
|
2014-04-10 15:06:54 +00:00
|
|
|
|
SupportedAudioCodecs = new List<string>();
|
2014-04-05 15:02:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-21 04:52:28 +00:00
|
|
|
|
public string InputAudioSync { get; set; }
|
|
|
|
|
public string InputVideoSync { get; set; }
|
|
|
|
|
|
2014-01-20 15:04:50 +00:00
|
|
|
|
public bool DeInterlace { get; set; }
|
2014-01-22 01:37:01 +00:00
|
|
|
|
|
|
|
|
|
public bool ReadInputAtNativeFramerate { get; set; }
|
|
|
|
|
|
|
|
|
|
public string InputFormat { get; set; }
|
|
|
|
|
|
|
|
|
|
public string InputVideoCodec { get; set; }
|
|
|
|
|
|
|
|
|
|
public string InputAudioCodec { get; set; }
|
2014-03-12 19:56:12 +00:00
|
|
|
|
|
2014-03-25 05:25:03 +00:00
|
|
|
|
public string MimeType { get; set; }
|
|
|
|
|
public string OrgPn { get; set; }
|
|
|
|
|
|
|
|
|
|
// DLNA Settings
|
|
|
|
|
public bool EstimateContentLength { get; set; }
|
|
|
|
|
public bool EnableMpegtsM2TsMode { get; set; }
|
|
|
|
|
public TranscodeSeekInfo TranscodeSeekInfo { get; set; }
|
|
|
|
|
|
2014-03-12 19:56:12 +00:00
|
|
|
|
public string GetMimeType(string outputPath)
|
|
|
|
|
{
|
2014-03-25 05:25:03 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(MimeType))
|
|
|
|
|
{
|
|
|
|
|
return MimeType;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-12 19:56:12 +00:00
|
|
|
|
return MimeTypes.GetMimeType(outputPath);
|
|
|
|
|
}
|
2014-04-05 15:02:50 +00:00
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
DisposeLiveStream();
|
|
|
|
|
DisposeLogStream();
|
|
|
|
|
DisposeIsoMount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisposeLogStream()
|
|
|
|
|
{
|
|
|
|
|
if (LogFileStream != null)
|
|
|
|
|
{
|
2014-04-06 17:53:23 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
LogFileStream.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error disposing log stream", ex);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-05 15:02:50 +00:00
|
|
|
|
LogFileStream = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisposeIsoMount()
|
|
|
|
|
{
|
|
|
|
|
if (IsoMount != null)
|
|
|
|
|
{
|
2014-04-06 17:53:23 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
IsoMount.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error disposing iso mount", ex);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-05 15:02:50 +00:00
|
|
|
|
IsoMount = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void DisposeLiveStream()
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(LiveTvStreamId))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _liveTvManager.CloseLiveStream(LiveTvStreamId, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error closing live tv stream", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-27 04:19:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|