|
|
@ -94,17 +94,13 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private const int BufferSize = 81920;
|
|
|
|
private const int BufferSize = 81920;
|
|
|
|
public static Task CopyUntilCancelled(Stream source, Stream target, CancellationToken cancellationToken)
|
|
|
|
public static async Task CopyUntilCancelled(Stream source, Stream target, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
|
|
|
|
return CopyUntilCancelled(source, target, null, cancellationToken);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async Task CopyUntilCancelled(Stream source, Stream target, Action onStarted, CancellationToken cancellationToken)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
byte[] buffer = new byte[BufferSize];
|
|
|
|
|
|
|
|
|
|
|
|
while (!cancellationToken.IsCancellationRequested)
|
|
|
|
while (!cancellationToken.IsCancellationRequested)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var bytesRead = await CopyToAsyncInternal(source, target, BufferSize, onStarted, cancellationToken).ConfigureAwait(false);
|
|
|
|
var bytesRead = await CopyToAsyncInternal(source, target, buffer, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
onStarted = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var position = fs.Position;
|
|
|
|
//var position = fs.Position;
|
|
|
|
//_logger.Debug("Streamed {0} bytes to position {1} from file {2}", bytesRead, position, path);
|
|
|
|
//_logger.Debug("Streamed {0} bytes to position {1} from file {2}", bytesRead, position, path);
|
|
|
@ -116,23 +112,16 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static async Task<int> CopyToAsyncInternal(Stream source, Stream destination, Int32 bufferSize, Action onStarted, CancellationToken cancellationToken)
|
|
|
|
private static async Task<int> CopyToAsyncInternal(Stream source, Stream destination, byte[] buffer, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
byte[] buffer = new byte[bufferSize];
|
|
|
|
|
|
|
|
int bytesRead;
|
|
|
|
int bytesRead;
|
|
|
|
int totalBytesRead = 0;
|
|
|
|
int totalBytesRead = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while ((bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) != 0)
|
|
|
|
while ((bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await destination.WriteAsync(buffer, 0, bytesRead, cancellationToken).ConfigureAwait(false);
|
|
|
|
destination.Write(buffer, 0, bytesRead);
|
|
|
|
|
|
|
|
|
|
|
|
totalBytesRead += bytesRead;
|
|
|
|
totalBytesRead += bytesRead;
|
|
|
|
|
|
|
|
|
|
|
|
if (onStarted != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
onStarted();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
onStarted = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return totalBytesRead;
|
|
|
|
return totalBytesRead;
|
|
|
|