Browse Source

update DirectRecorder

Luke Pulverenti 8 years ago
parent
commit
0f1d253278
1 changed files with 6 additions and 17 deletions
  1. 6 17
      Emby.Server.Implementations/LiveTv/EmbyTV/DirectRecorder.cs

+ 6 - 17
Emby.Server.Implementations/LiveTv/EmbyTV/DirectRecorder.cs

@@ -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)
-        {
-            return CopyUntilCancelled(source, target, null, cancellationToken);
-        }
-        public static async Task CopyUntilCancelled(Stream source, Stream target, Action onStarted, CancellationToken cancellationToken)
+        public static async Task CopyUntilCancelled(Stream source, Stream target, CancellationToken cancellationToken)
         {
         {
+            byte[] buffer = new byte[BufferSize];
+
             while (!cancellationToken.IsCancellationRequested)
             while (!cancellationToken.IsCancellationRequested)
             {
             {
-                var bytesRead = await CopyToAsyncInternal(source, target, BufferSize, onStarted, cancellationToken).ConfigureAwait(false);
-
-                onStarted = null;
+                var bytesRead = await CopyToAsyncInternal(source, target, buffer, cancellationToken).ConfigureAwait(false);
 
 
                 //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;