aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Playback/StreamState.cs
diff options
context:
space:
mode:
authortikuf <admin@nyalindee.com>2014-04-07 12:43:29 +1000
committertikuf <admin@nyalindee.com>2014-04-07 12:43:29 +1000
commit8ae71b75fb024815e165eba9b3d00ca8307caab3 (patch)
tree54274881bca0834c2ab518c51bc65160fc320db1 /MediaBrowser.Api/Playback/StreamState.cs
parent161e1af0eaa69e828f64d33311e3bc462852d6c4 (diff)
parent56c0d491f4c05a2c0c4f21c20e3530c039b33148 (diff)
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
Diffstat (limited to 'MediaBrowser.Api/Playback/StreamState.cs')
-rw-r--r--MediaBrowser.Api/Playback/StreamState.cs72
1 files changed, 69 insertions, 3 deletions
diff --git a/MediaBrowser.Api/Playback/StreamState.cs b/MediaBrowser.Api/Playback/StreamState.cs
index bde5fe30d..ce7d79917 100644
--- a/MediaBrowser.Api/Playback/StreamState.cs
+++ b/MediaBrowser.Api/Playback/StreamState.cs
@@ -1,15 +1,21 @@
using MediaBrowser.Common.Net;
+using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
+using MediaBrowser.Model.Logging;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
namespace MediaBrowser.Api.Playback
{
- public class StreamState
+ public class StreamState : IDisposable
{
+ private readonly ILogger _logger;
+ private readonly ILiveTvManager _liveTvManager;
+
public string RequestedUrl { get; set; }
public StreamRequest Request { get; set; }
@@ -51,8 +57,6 @@ namespace MediaBrowser.Api.Playback
public bool HasMediaStreams { get; set; }
- public CancellationTokenSource StandardInputCancellationTokenSource { get; set; }
-
public string LiveTvStreamId { get; set; }
public int SegmentLength = 10;
@@ -63,6 +67,12 @@ namespace MediaBrowser.Api.Playback
public string AudioSync = "1";
public string VideoSync = "vfr";
+ public StreamState(ILiveTvManager liveTvManager, ILogger logger)
+ {
+ _liveTvManager = liveTvManager;
+ _logger = logger;
+ }
+
public string InputAudioSync { get; set; }
public string InputVideoSync { get; set; }
@@ -93,5 +103,61 @@ namespace MediaBrowser.Api.Playback
return MimeTypes.GetMimeType(outputPath);
}
+
+ public void Dispose()
+ {
+ DisposeLiveStream();
+ DisposeLogStream();
+ DisposeIsoMount();
+ }
+
+ private void DisposeLogStream()
+ {
+ if (LogFileStream != null)
+ {
+ try
+ {
+ LogFileStream.Dispose();
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error disposing log stream", ex);
+ }
+
+ LogFileStream = null;
+ }
+ }
+
+ private void DisposeIsoMount()
+ {
+ if (IsoMount != null)
+ {
+ try
+ {
+ IsoMount.Dispose();
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error disposing iso mount", ex);
+ }
+
+ 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);
+ }
+ }
+ }
}
}