fix overlapping recordings

This commit is contained in:
Luke Pulverenti 2017-09-21 16:15:44 -04:00
parent 8117d31d2f
commit 8e1e4fd04a
2 changed files with 35 additions and 33 deletions

View File

@ -96,7 +96,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
BufferContent = false,
// Increase a little bit
TimeoutMs = 30000
TimeoutMs = 30000,
EnableHttpCompression = false
}, "GET").ConfigureAwait(false))
{
@ -146,35 +148,35 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
});
}
public Task CopyToAsync(Stream stream, CancellationToken cancellationToken)
public async Task CopyToAsync(Stream stream, CancellationToken cancellationToken)
{
return CopyFileTo(_tempFilePath, stream, cancellationToken);
}
protected async Task CopyFileTo(string path, Stream outputStream, CancellationToken cancellationToken)
{
long startPosition = -20000;
_logger.Info("Live stream starting position is {0} bytes", startPosition.ToString(CultureInfo.InvariantCulture));
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(path, allowAsync))
using (var inputStream = (FileStream)GetInputStream(_tempFilePath, allowAsync))
{
if (startPosition > 0)
{
inputStream.Seek(-20000, SeekOrigin.End);
}
TrySeek(inputStream, -20000);
while (!cancellationToken.IsCancellationRequested)
{
StreamHelper.CopyTo(inputStream, outputStream, 81920, cancellationToken);
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);
}
}
}
}

View File

@ -168,30 +168,18 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
});
}
public Task CopyToAsync(Stream stream, CancellationToken cancellationToken)
public async Task CopyToAsync(Stream stream, CancellationToken cancellationToken)
{
return CopyFileTo(_tempFilePath, stream, cancellationToken);
}
protected async Task CopyFileTo(string path, Stream outputStream, CancellationToken cancellationToken)
{
long startPosition = -20000;
_logger.Info("Live stream starting position is {0} bytes", startPosition.ToString(CultureInfo.InvariantCulture));
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(path, allowAsync))
using (var inputStream = (FileStream)GetInputStream(_tempFilePath, allowAsync))
{
if (startPosition > 0)
{
inputStream.Seek(-20000, SeekOrigin.End);
}
TrySeek(inputStream, -20000);
while (!cancellationToken.IsCancellationRequested)
{
StreamHelper.CopyTo(inputStream, outputStream, 81920, cancellationToken);
StreamHelper.CopyTo(inputStream, stream, 81920, cancellationToken);
//var position = fs.Position;
//_logger.Debug("Streamed {0} bytes to position {1} from file {2}", bytesRead, position, path);
@ -199,6 +187,18 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
}
}
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 void CopyTo(ISocket udpClient, Stream target, TaskCompletionSource<bool> openTaskCompletionSource, CancellationToken cancellationToken)
{