@ -70,7 +70,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
try
{
await tcpClient . ConnectAsync ( remoteAddress , HdHomerunManager . HdHomeRunPort ) . ConfigureAwait ( false ) ;
localAddress = ( ( IPEndPoint ) tcpClient . Client . Remote EndPoint) . Address ;
localAddress = ( ( IPEndPoint ) tcpClient . Client . Local EndPoint) . Address ;
tcpClient . Close ( ) ;
}
catch ( Exception ex )
@ -80,6 +80,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
}
}
if ( localAddress . IsIPv4MappedToIPv6 ) {
localAddress = localAddress . MapToIPv4 ( ) ;
}
var udpClient = new UdpClient ( localPort , AddressFamily . InterNetwork ) ;
var hdHomerunManager = new HdHomerunManager ( ) ;
@ -110,12 +114,12 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
await StartStreaming (
StartStreaming (
udpClient ,
hdHomerunManager ,
remoteAddress ,
taskCompletionSource ,
LiveStreamCancellationTokenSource . Token ) .ConfigureAwait ( false ) ;
LiveStreamCancellationTokenSource . Token ) ;
// OpenedMediaSource.Protocol = MediaProtocol.File;
// OpenedMediaSource.Path = tempFile;
@ -131,33 +135,30 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
await taskCompletionSource . Task . ConfigureAwait ( false ) ;
}
private Task StartStreaming ( UdpClient udpClient , HdHomerunManager hdHomerunManager , IPAddress remoteAddress , TaskCompletionSource < bool > openTaskCompletionSource , CancellationToken cancellationToken )
private async void StartStreaming ( UdpClient udpClient , HdHomerunManager hdHomerunManager , IPAddress remoteAddress , TaskCompletionSource < bool > openTaskCompletionSource , CancellationToken cancellationToken )
{
return Task . Run ( async ( ) = >
using ( udpClient )
using ( hdHomerunManager )
{
using ( udpClient )
using ( hdHomerunManager )
try
{
try
{
await CopyTo ( udpClient , TempFilePath , openTaskCompletionSource , cancellationToken ) . ConfigureAwait ( false ) ;
}
catch ( OperationCanceledException ex )
{
Logger . LogInformation ( "HDHR UDP stream cancelled or timed out from {0}" , remoteAddress ) ;
openTaskCompletionSource . TrySetException ( ex ) ;
}
catch ( Exception ex )
{
Logger . LogError ( ex , "Error opening live stream:" ) ;
openTaskCompletionSource . TrySetException ( ex ) ;
}
EnableStreamSharing = false ;
await CopyTo ( udpClient , TempFilePath , openTaskCompletionSource , cancellationToken ) . ConfigureAwait ( false ) ;
}
catch ( OperationCanceledException ex )
{
Logger . LogInformation ( "HDHR UDP stream cancelled or timed out from {0}" , remoteAddress ) ;
openTaskCompletionSource . TrySetException ( ex ) ;
}
catch ( Exception ex )
{
Logger . LogError ( ex , "Error opening live stream:" ) ;
openTaskCompletionSource . TrySetException ( ex ) ;
}
EnableStreamSharing = false ;
}
await DeleteTempFiles ( new List < string > { TempFilePath } ) . ConfigureAwait ( false ) ;
} ) ;
await DeleteTempFiles ( new List < string > { TempFilePath } ) . ConfigureAwait ( false ) ;
}
private async Task CopyTo ( UdpClient udpClient , string file , TaskCompletionSource < bool > openTaskCompletionSource , CancellationToken cancellationToken )