mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-19 11:59:02 -07:00
fix merge conflicts
This commit is contained in:
parent
27868803d8
commit
f651fd6ffb
@ -19,27 +19,21 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
{
|
{
|
||||||
public class HdHomerunHttpStream : LiveStream, IDirectStreamProvider
|
public class HdHomerunHttpStream : LiveStream, IDirectStreamProvider
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClient _httpClient;
|
||||||
private readonly IServerApplicationHost _appHost;
|
private readonly IServerApplicationHost _appHost;
|
||||||
|
|
||||||
private readonly CancellationTokenSource _liveStreamCancellationTokenSource = new CancellationTokenSource();
|
private readonly CancellationTokenSource _liveStreamCancellationTokenSource = new CancellationTokenSource();
|
||||||
private readonly TaskCompletionSource<bool> _liveStreamTaskCompletionSource = new TaskCompletionSource<bool>();
|
private readonly TaskCompletionSource<bool> _liveStreamTaskCompletionSource = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
private readonly string _tempFilePath;
|
|
||||||
|
|
||||||
public HdHomerunHttpStream(MediaSourceInfo mediaSource, string originalStreamId, IFileSystem fileSystem, IHttpClient httpClient, ILogger logger, IServerApplicationPaths appPaths, IServerApplicationHost appHost, IEnvironmentInfo environment)
|
public HdHomerunHttpStream(MediaSourceInfo mediaSource, string originalStreamId, IFileSystem fileSystem, IHttpClient httpClient, ILogger logger, IServerApplicationPaths appPaths, IServerApplicationHost appHost, IEnvironmentInfo environment)
|
||||||
: base(mediaSource, environment, fileSystem)
|
: base(mediaSource, environment, fileSystem, logger, appPaths)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
_logger = logger;
|
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
OriginalStreamId = originalStreamId;
|
OriginalStreamId = originalStreamId;
|
||||||
|
|
||||||
_tempFilePath = Path.Combine(appPaths.TranscodingTempPath, UniqueId + ".ts");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task OpenInternal(CancellationToken openCancellationToken)
|
protected override Task OpenInternal(CancellationToken openCancellationToken)
|
||||||
{
|
{
|
||||||
_liveStreamCancellationTokenSource.Token.ThrowIfCancellationRequested();
|
_liveStreamCancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
@ -47,7 +41,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
|
|
||||||
var url = mediaSource.Path;
|
var url = mediaSource.Path;
|
||||||
|
|
||||||
_logger.Info("Opening HDHR Live stream from {0}", url);
|
Logger.Info("Opening HDHR Live stream from {0}", url);
|
||||||
|
|
||||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
@ -66,14 +60,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
//OpenedMediaSource.SupportsDirectStream = true;
|
//OpenedMediaSource.SupportsDirectStream = true;
|
||||||
//OpenedMediaSource.SupportsTranscoding = true;
|
//OpenedMediaSource.SupportsTranscoding = true;
|
||||||
|
|
||||||
await taskCompletionSource.Task.ConfigureAwait(false);
|
return taskCompletionSource.Task;
|
||||||
|
|
||||||
//await Task.Delay(5000).ConfigureAwait(false);
|
//await Task.Delay(5000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task Close()
|
public override Task Close()
|
||||||
{
|
{
|
||||||
_logger.Info("Closing HDHR live stream");
|
Logger.Info("Closing HDHR live stream");
|
||||||
_liveStreamCancellationTokenSource.Cancel();
|
_liveStreamCancellationTokenSource.Cancel();
|
||||||
|
|
||||||
return _liveStreamTaskCompletionSource.Task;
|
return _liveStreamTaskCompletionSource.Task;
|
||||||
@ -102,14 +96,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
|
|
||||||
}, "GET").ConfigureAwait(false))
|
}, "GET").ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
_logger.Info("Opened HDHR stream from {0}", url);
|
Logger.Info("Opened HDHR stream from {0}", url);
|
||||||
|
|
||||||
if (!cancellationToken.IsCancellationRequested)
|
if (!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
_logger.Info("Beginning multicastStream.CopyUntilCancelled");
|
Logger.Info("Beginning multicastStream.CopyUntilCancelled");
|
||||||
|
|
||||||
FileSystem.CreateDirectory(FileSystem.GetDirectoryName(_tempFilePath));
|
FileSystem.CreateDirectory(FileSystem.GetDirectoryName(TempFilePath));
|
||||||
using (var fileStream = FileSystem.GetFileStream(_tempFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, FileOpenOptions.None))
|
using (var fileStream = FileSystem.GetFileStream(TempFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, FileOpenOptions.None))
|
||||||
{
|
{
|
||||||
StreamHelper.CopyTo(response.Content, fileStream, 81920, () => Resolve(openTaskCompletionSource), cancellationToken);
|
StreamHelper.CopyTo(response.Content, fileStream, 81920, () => Resolve(openTaskCompletionSource), cancellationToken);
|
||||||
}
|
}
|
||||||
@ -124,19 +118,19 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
{
|
{
|
||||||
if (isFirstAttempt)
|
if (isFirstAttempt)
|
||||||
{
|
{
|
||||||
_logger.ErrorException("Error opening live stream:", ex);
|
Logger.ErrorException("Error opening live stream:", ex);
|
||||||
openTaskCompletionSource.TrySetException(ex);
|
openTaskCompletionSource.TrySetException(ex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.ErrorException("Error copying live stream, will reopen", ex);
|
Logger.ErrorException("Error copying live stream, will reopen", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
isFirstAttempt = false;
|
isFirstAttempt = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_liveStreamTaskCompletionSource.TrySetResult(true);
|
_liveStreamTaskCompletionSource.TrySetResult(true);
|
||||||
await DeleteTempFile(_tempFilePath).ConfigureAwait(false);
|
await DeleteTempFile(TempFilePath).ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,36 +141,5 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
openTaskCompletionSource.TrySetResult(true);
|
openTaskCompletionSource.TrySetResult(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CopyToAsync(Stream stream, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var allowAsync = false;//Environment.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows;
|
|
||||||
// use non-async filestream along with read due to https://github.com/dotnet/corefx/issues/6039
|
|
||||||
|
|
||||||
using (var inputStream = (FileStream)GetInputStream(_tempFilePath, allowAsync))
|
|
||||||
{
|
|
||||||
TrySeek(inputStream, -20000);
|
|
||||||
|
|
||||||
while (!cancellationToken.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
StreamHelper.CopyTo(inputStream, stream, 81920, cancellationToken);
|
|
||||||
|
|
||||||
//var position = fs.Position;
|
|
||||||
//_logger.Debug("Streamed {0} bytes to position {1} from file {2}", bytesRead, position, path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void TrySeek(FileStream stream, long offset)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
stream.Seek(offset, SeekOrigin.End);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.ErrorException("Error seeking stream", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
{
|
{
|
||||||
public class HdHomerunUdpStream : LiveStream, IDirectStreamProvider
|
public class HdHomerunUdpStream : LiveStream, IDirectStreamProvider
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
|
||||||
private readonly IServerApplicationHost _appHost;
|
private readonly IServerApplicationHost _appHost;
|
||||||
private readonly ISocketFactory _socketFactory;
|
private readonly ISocketFactory _socketFactory;
|
||||||
|
|
||||||
@ -33,22 +32,18 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
private readonly int _numTuners;
|
private readonly int _numTuners;
|
||||||
private readonly INetworkManager _networkManager;
|
private readonly INetworkManager _networkManager;
|
||||||
|
|
||||||
private readonly string _tempFilePath;
|
|
||||||
|
|
||||||
public HdHomerunUdpStream(MediaSourceInfo mediaSource, string originalStreamId, IHdHomerunChannelCommands channelCommands, int numTuners, IFileSystem fileSystem, IHttpClient httpClient, ILogger logger, IServerApplicationPaths appPaths, IServerApplicationHost appHost, ISocketFactory socketFactory, INetworkManager networkManager, IEnvironmentInfo environment)
|
public HdHomerunUdpStream(MediaSourceInfo mediaSource, string originalStreamId, IHdHomerunChannelCommands channelCommands, int numTuners, IFileSystem fileSystem, IHttpClient httpClient, ILogger logger, IServerApplicationPaths appPaths, IServerApplicationHost appHost, ISocketFactory socketFactory, INetworkManager networkManager, IEnvironmentInfo environment)
|
||||||
: base(mediaSource, environment, fileSystem)
|
: base(mediaSource, environment, fileSystem, logger, appPaths)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
_socketFactory = socketFactory;
|
_socketFactory = socketFactory;
|
||||||
_networkManager = networkManager;
|
_networkManager = networkManager;
|
||||||
OriginalStreamId = originalStreamId;
|
OriginalStreamId = originalStreamId;
|
||||||
_channelCommands = channelCommands;
|
_channelCommands = channelCommands;
|
||||||
_numTuners = numTuners;
|
_numTuners = numTuners;
|
||||||
_tempFilePath = Path.Combine(appPaths.TranscodingTempPath, UniqueId + ".ts");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task OpenInternal(CancellationToken openCancellationToken)
|
protected override Task OpenInternal(CancellationToken openCancellationToken)
|
||||||
{
|
{
|
||||||
_liveStreamCancellationTokenSource.Token.ThrowIfCancellationRequested();
|
_liveStreamCancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
@ -57,7 +52,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
var uri = new Uri(mediaSource.Path);
|
var uri = new Uri(mediaSource.Path);
|
||||||
var localPort = _networkManager.GetRandomUnusedUdpPort();
|
var localPort = _networkManager.GetRandomUnusedUdpPort();
|
||||||
|
|
||||||
_logger.Info("Opening HDHR UDP Live stream from {0}", uri.Host);
|
Logger.Info("Opening HDHR UDP Live stream from {0}", uri.Host);
|
||||||
|
|
||||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
@ -73,14 +68,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
//OpenedMediaSource.SupportsDirectStream = true;
|
//OpenedMediaSource.SupportsDirectStream = true;
|
||||||
//OpenedMediaSource.SupportsTranscoding = true;
|
//OpenedMediaSource.SupportsTranscoding = true;
|
||||||
|
|
||||||
await taskCompletionSource.Task.ConfigureAwait(false);
|
return taskCompletionSource.Task;
|
||||||
|
|
||||||
//await Task.Delay(5000).ConfigureAwait(false);
|
//await Task.Delay(5000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task Close()
|
public override Task Close()
|
||||||
{
|
{
|
||||||
_logger.Info("Closing HDHR UDP live stream");
|
Logger.Info("Closing HDHR UDP live stream");
|
||||||
_liveStreamCancellationTokenSource.Cancel();
|
_liveStreamCancellationTokenSource.Cancel();
|
||||||
|
|
||||||
return _liveStreamTaskCompletionSource.Task;
|
return _liveStreamTaskCompletionSource.Task;
|
||||||
@ -107,7 +102,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
_logger.Error("Unable to determine local ip address for Legacy HDHomerun stream.");
|
Logger.Error("Unable to determine local ip address for Legacy HDHomerun stream.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,12 +114,12 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
// send url to start streaming
|
// send url to start streaming
|
||||||
await hdHomerunManager.StartStreaming(remoteAddress, localAddress, localPort, _channelCommands, _numTuners, cancellationToken).ConfigureAwait(false);
|
await hdHomerunManager.StartStreaming(remoteAddress, localAddress, localPort, _channelCommands, _numTuners, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.Info("Opened HDHR UDP stream from {0}", remoteAddress);
|
Logger.Info("Opened HDHR UDP stream from {0}", remoteAddress);
|
||||||
|
|
||||||
if (!cancellationToken.IsCancellationRequested)
|
if (!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
FileSystem.CreateDirectory(FileSystem.GetDirectoryName(_tempFilePath));
|
FileSystem.CreateDirectory(FileSystem.GetDirectoryName(TempFilePath));
|
||||||
using (var fileStream = FileSystem.GetFileStream(_tempFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, FileOpenOptions.None))
|
using (var fileStream = FileSystem.GetFileStream(TempFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, FileOpenOptions.None))
|
||||||
{
|
{
|
||||||
CopyTo(udpClient, fileStream, openTaskCompletionSource, cancellationToken);
|
CopyTo(udpClient, fileStream, openTaskCompletionSource, cancellationToken);
|
||||||
}
|
}
|
||||||
@ -132,7 +127,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
}
|
}
|
||||||
catch (OperationCanceledException ex)
|
catch (OperationCanceledException ex)
|
||||||
{
|
{
|
||||||
_logger.Info("HDHR UDP stream cancelled or timed out from {0}", remoteAddress);
|
Logger.Info("HDHR UDP stream cancelled or timed out from {0}", remoteAddress);
|
||||||
openTaskCompletionSource.TrySetException(ex);
|
openTaskCompletionSource.TrySetException(ex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -140,12 +135,12 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
{
|
{
|
||||||
if (isFirstAttempt)
|
if (isFirstAttempt)
|
||||||
{
|
{
|
||||||
_logger.ErrorException("Error opening live stream:", ex);
|
Logger.ErrorException("Error opening live stream:", ex);
|
||||||
openTaskCompletionSource.TrySetException(ex);
|
openTaskCompletionSource.TrySetException(ex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.ErrorException("Error copying live stream, will reopen", ex);
|
Logger.ErrorException("Error copying live stream, will reopen", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
isFirstAttempt = false;
|
isFirstAttempt = false;
|
||||||
@ -156,7 +151,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await DeleteTempFile(_tempFilePath).ConfigureAwait(false);
|
await DeleteTempFile(TempFilePath).ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,37 +163,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CopyToAsync(Stream stream, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var allowAsync = false;//Environment.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows;
|
|
||||||
// use non-async filestream along with read due to https://github.com/dotnet/corefx/issues/6039
|
|
||||||
|
|
||||||
using (var inputStream = (FileStream)GetInputStream(_tempFilePath, allowAsync))
|
|
||||||
{
|
|
||||||
TrySeek(inputStream, -20000);
|
|
||||||
|
|
||||||
while (!cancellationToken.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
StreamHelper.CopyTo(inputStream, stream, 81920, cancellationToken);
|
|
||||||
|
|
||||||
//var position = fs.Position;
|
|
||||||
//_logger.Debug("Streamed {0} bytes to position {1} from file {2}", bytesRead, position, path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void TrySeek(FileStream stream, long offset)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
stream.Seek(offset, SeekOrigin.End);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.ErrorException("Error seeking stream", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int RtpHeaderBytes = 12;
|
private static int RtpHeaderBytes = 12;
|
||||||
private void CopyTo(ISocket udpClient, Stream target, TaskCompletionSource<bool> openTaskCompletionSource, CancellationToken cancellationToken)
|
private void CopyTo(ISocket udpClient, Stream target, TaskCompletionSource<bool> openTaskCompletionSource, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
@ -226,30 +190,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
Resolve(openTaskCompletionSource);
|
Resolve(openTaskCompletionSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//var copier = new AsyncStreamCopier(source, target, 0, cancellationToken, false, bufferSize, bufferCount);
|
|
||||||
//copier.IndividualReadOffset = RtpHeaderBytes;
|
|
||||||
|
|
||||||
//var taskCompletion = new TaskCompletionSource<long>();
|
|
||||||
|
|
||||||
//copier.TaskCompletionSource = taskCompletion;
|
|
||||||
|
|
||||||
//var result = copier.BeginCopy(StreamCopyCallback, copier);
|
|
||||||
|
|
||||||
//if (openTaskCompletionSource != null)
|
|
||||||
//{
|
|
||||||
// Resolve(openTaskCompletionSource);
|
|
||||||
// openTaskCompletionSource = null;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//if (result.CompletedSynchronously)
|
|
||||||
//{
|
|
||||||
// StreamCopyCallback(result);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//cancellationToken.Register(() => taskCompletion.TrySetCanceled());
|
|
||||||
|
|
||||||
//return taskCompletion.Task;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UdpClientStream : Stream
|
public class UdpClientStream : Stream
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
[assembly: AssemblyVersion("3.2.32")]
|
[assembly: AssemblyVersion("3.2.32.16")]
|
||||||
|
Loading…
Reference in New Issue
Block a user