Merge pull request #2683 from MediaBrowser/dev
update live stream buffers
This commit is contained in:
commit
a1074c7f3a
|
@ -513,7 +513,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
// The UDP method is not working reliably on OSX, and on BSD it hasn't been tested yet
|
// The UDP method is not working reliably on OSX, and on BSD it hasn't been tested yet
|
||||||
var enableHttpStream = _environment.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.OSX
|
var enableHttpStream = _environment.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.OSX
|
||||||
|| _environment.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.BSD;
|
|| _environment.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.BSD;
|
||||||
//enableHttpStream = true;
|
enableHttpStream = true;
|
||||||
if (enableHttpStream)
|
if (enableHttpStream)
|
||||||
{
|
{
|
||||||
mediaSource.Protocol = MediaProtocol.Http;
|
mediaSource.Protocol = MediaProtocol.Http;
|
||||||
|
|
|
@ -106,10 +106,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
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))
|
||||||
{
|
{
|
||||||
ResolveAfterDelay(3000, openTaskCompletionSource);
|
|
||||||
|
|
||||||
//await response.Content.CopyToAsync(fileStream, 81920, cancellationToken).ConfigureAwait(false);
|
//await response.Content.CopyToAsync(fileStream, 81920, cancellationToken).ConfigureAwait(false);
|
||||||
StreamHelper.CopyTo(response.Content, fileStream, 81920, cancellationToken);
|
StreamHelper.CopyTo(response.Content, fileStream, 81920, () => Resolve(openTaskCompletionSource), cancellationToken);
|
||||||
|
|
||||||
//await AsyncStreamCopier.CopyStream(response.Content, fileStream, 81920, 4, cancellationToken).ConfigureAwait(false);
|
//await AsyncStreamCopier.CopyStream(response.Content, fileStream, 81920, 4, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
@ -140,11 +138,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResolveAfterDelay(int delayMs, TaskCompletionSource<bool> openTaskCompletionSource)
|
private void Resolve(TaskCompletionSource<bool> openTaskCompletionSource)
|
||||||
{
|
{
|
||||||
Task.Run(async () =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
await Task.Delay(delayMs).ConfigureAwait(false);
|
|
||||||
openTaskCompletionSource.TrySetResult(true);
|
openTaskCompletionSource.TrySetResult(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,8 +126,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
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))
|
||||||
{
|
{
|
||||||
ResolveAfterDelay(3000, openTaskCompletionSource);
|
|
||||||
|
|
||||||
CopyTo(udpClient, fileStream, openTaskCompletionSource, cancellationToken);
|
CopyTo(udpClient, fileStream, openTaskCompletionSource, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,13 +168,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task CopyToAsync(Stream stream, CancellationToken cancellationToken)
|
public async Task CopyToAsync(Stream outputStream, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return CopyFileTo(_tempFilePath, stream, cancellationToken);
|
var path = _tempFilePath;
|
||||||
}
|
|
||||||
|
|
||||||
protected async Task CopyFileTo(string path, Stream outputStream, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
long startPosition = -20000;
|
long startPosition = -20000;
|
||||||
if (startPosition < 0)
|
if (startPosition < 0)
|
||||||
{
|
{
|
||||||
|
@ -221,15 +216,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResolveAfterDelay(int delayMs, TaskCompletionSource<bool> openTaskCompletionSource)
|
|
||||||
{
|
|
||||||
Task.Run(async () =>
|
|
||||||
{
|
|
||||||
await Task.Delay(delayMs).ConfigureAwait(false);
|
|
||||||
openTaskCompletionSource.TrySetResult(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -238,6 +224,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
|
|
||||||
byte[] buffer = new byte[bufferSize];
|
byte[] buffer = new byte[bufferSize];
|
||||||
int read;
|
int read;
|
||||||
|
var resolved = false;
|
||||||
|
|
||||||
while ((read = source.Read(buffer, 0, buffer.Length)) != 0)
|
while ((read = source.Read(buffer, 0, buffer.Length)) != 0)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
@ -248,6 +236,12 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
{
|
{
|
||||||
target.Write(buffer, RtpHeaderBytes, read);
|
target.Write(buffer, RtpHeaderBytes, read);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!resolved)
|
||||||
|
{
|
||||||
|
resolved = true;
|
||||||
|
Resolve(openTaskCompletionSource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//var copier = new AsyncStreamCopier(source, target, 0, cancellationToken, false, bufferSize, bufferCount);
|
//var copier = new AsyncStreamCopier(source, target, 0, cancellationToken, false, bufferSize, bufferCount);
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.IO
|
namespace MediaBrowser.Controller.IO
|
||||||
{
|
{
|
||||||
public static class StreamHelper
|
public static class StreamHelper
|
||||||
{
|
{
|
||||||
public static void CopyTo(Stream source, Stream destination, int bufferSize, CancellationToken cancellationToken)
|
public static void CopyTo(Stream source, Stream destination, int bufferSize, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
CopyTo(source, destination, bufferSize, null, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CopyTo(Stream source, Stream destination, int bufferSize, Action onStarted, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[bufferSize];
|
byte[] buffer = new byte[bufferSize];
|
||||||
int read;
|
int read;
|
||||||
|
@ -14,6 +20,12 @@ namespace MediaBrowser.Controller.IO
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
destination.Write(buffer, 0, read);
|
destination.Write(buffer, 0, read);
|
||||||
|
|
||||||
|
if (onStarted != null)
|
||||||
|
{
|
||||||
|
onStarted();
|
||||||
|
onStarted = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
[assembly: AssemblyVersion("3.2.18.2")]
|
[assembly: AssemblyVersion("3.2.18.3")]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user