rework hdhr udp stream
This commit is contained in:
parent
2f93d4498b
commit
8b9e7e1f59
|
@ -422,7 +422,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
SupportsTranscoding = true,
|
SupportsTranscoding = true,
|
||||||
IsInfiniteStream = true,
|
IsInfiniteStream = true,
|
||||||
IgnoreDts = true,
|
IgnoreDts = true,
|
||||||
IgnoreIndex = true
|
//IgnoreIndex = true,
|
||||||
|
//ReadAtNativeFramerate = true
|
||||||
};
|
};
|
||||||
|
|
||||||
mediaSource.InferTotalBitrate();
|
mediaSource.InferTotalBitrate();
|
||||||
|
|
|
@ -101,9 +101,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
_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.Asynchronous | FileOpenOptions.SequentialScan))
|
using (var fileStream = FileSystem.GetFileStream(_tempFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, FileOpenOptions.Asynchronous))
|
||||||
{
|
{
|
||||||
ResolveAfterDelay(2000, openTaskCompletionSource);
|
ResolveAfterDelay(3000, openTaskCompletionSource);
|
||||||
|
|
||||||
await response.Content.CopyToAsync(fileStream, 81920, cancellationToken).ConfigureAwait(false);
|
await response.Content.CopyToAsync(fileStream, 81920, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,11 +121,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
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.Asynchronous | FileOpenOptions.SequentialScan))
|
using (var fileStream = FileSystem.GetFileStream(_tempFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, FileOpenOptions.Asynchronous))
|
||||||
{
|
{
|
||||||
ResolveAfterDelay(2000, openTaskCompletionSource);
|
await CopyTo(udpClient, fileStream, openTaskCompletionSource, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
await new UdpClientStream(udpClient).CopyToAsync(fileStream, 81920, cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,19 +157,36 @@ 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);
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task CopyToAsync(Stream stream, CancellationToken cancellationToken)
|
public Task CopyToAsync(Stream stream, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return CopyFileTo(_tempFilePath, false, stream, cancellationToken);
|
return CopyFileTo(_tempFilePath, false, stream, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int RtpHeaderBytes = 12;
|
||||||
|
private async Task CopyTo(ISocket udpClient, Stream outputStream, TaskCompletionSource<bool> openTaskCompletionSource, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var data = await udpClient.ReceiveAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
var bytesRead = data.ReceivedBytes - RtpHeaderBytes;
|
||||||
|
|
||||||
|
await outputStream.WriteAsync(data.Buffer, RtpHeaderBytes, bytesRead, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (openTaskCompletionSource != null)
|
||||||
|
{
|
||||||
|
Resolve(openTaskCompletionSource);
|
||||||
|
openTaskCompletionSource = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This handles the ReadAsync function only of a Stream object
|
// This handles the ReadAsync function only of a Stream object
|
||||||
|
|
Loading…
Reference in New Issue
Block a user