|
@@ -3,7 +3,6 @@
|
|
#pragma warning disable CS1591
|
|
#pragma warning disable CS1591
|
|
|
|
|
|
using System;
|
|
using System;
|
|
-using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Net.Http;
|
|
using System.Net.Http;
|
|
@@ -55,39 +54,26 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|
Directory.CreateDirectory(Path.GetDirectoryName(TempFilePath));
|
|
Directory.CreateDirectory(Path.GetDirectoryName(TempFilePath));
|
|
|
|
|
|
var typeName = GetType().Name;
|
|
var typeName = GetType().Name;
|
|
- Logger.LogInformation("Opening " + typeName + " Live stream from {0}", url);
|
|
|
|
|
|
+ Logger.LogInformation("Opening {StreamType} Live stream from {Url}", typeName, url);
|
|
|
|
|
|
// Response stream is disposed manually.
|
|
// Response stream is disposed manually.
|
|
var response = await _httpClientFactory.CreateClient(NamedClient.Default)
|
|
var response = await _httpClientFactory.CreateClient(NamedClient.Default)
|
|
.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, CancellationToken.None)
|
|
.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, CancellationToken.None)
|
|
.ConfigureAwait(false);
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
- var extension = "ts";
|
|
|
|
- var requiresRemux = false;
|
|
|
|
-
|
|
|
|
var contentType = response.Content.Headers.ContentType?.ToString() ?? string.Empty;
|
|
var contentType = response.Content.Headers.ContentType?.ToString() ?? string.Empty;
|
|
- if (contentType.IndexOf("matroska", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
- {
|
|
|
|
- requiresRemux = true;
|
|
|
|
- }
|
|
|
|
- else if (contentType.IndexOf("mp4", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
- contentType.IndexOf("dash", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
- contentType.IndexOf("mpegURL", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
- contentType.IndexOf("text/", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
- {
|
|
|
|
- requiresRemux = true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Close the stream without any sharing features
|
|
|
|
- if (requiresRemux)
|
|
|
|
|
|
+ if (contentType.Contains("matroska", StringComparison.OrdinalIgnoreCase)
|
|
|
|
+ || contentType.Contains("mp4", StringComparison.OrdinalIgnoreCase)
|
|
|
|
+ || contentType.Contains("dash", StringComparison.OrdinalIgnoreCase)
|
|
|
|
+ || contentType.Contains("mpegURL", StringComparison.OrdinalIgnoreCase)
|
|
|
|
+ || contentType.Contains("text/", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
- using (response)
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ // Close the stream without any sharing features
|
|
|
|
+ response.Dispose();
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
- SetTempFilePath(extension);
|
|
|
|
|
|
+ SetTempFilePath("ts");
|
|
|
|
|
|
var taskCompletionSource = new TaskCompletionSource<bool>();
|
|
var taskCompletionSource = new TaskCompletionSource<bool>();
|
|
|
|
|
|
@@ -117,16 +103,11 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|
|
|
|
|
if (!taskCompletionSource.Task.Result)
|
|
if (!taskCompletionSource.Task.Result)
|
|
{
|
|
{
|
|
- Logger.LogWarning("Zero bytes copied from stream {0} to {1} but no exception raised", GetType().Name, TempFilePath);
|
|
|
|
|
|
+ Logger.LogWarning("Zero bytes copied from stream {StreamType} to {FilePath} but no exception raised", GetType().Name, TempFilePath);
|
|
throw new EndOfStreamException(string.Format(CultureInfo.InvariantCulture, "Zero bytes copied from stream {0}", GetType().Name));
|
|
throw new EndOfStreamException(string.Format(CultureInfo.InvariantCulture, "Zero bytes copied from stream {0}", GetType().Name));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public string GetFilePath()
|
|
|
|
- {
|
|
|
|
- return TempFilePath;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private Task StartStreaming(HttpResponseMessage response, TaskCompletionSource<bool> openTaskCompletionSource, CancellationToken cancellationToken)
|
|
private Task StartStreaming(HttpResponseMessage response, TaskCompletionSource<bool> openTaskCompletionSource, CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
return Task.Run(
|
|
return Task.Run(
|
|
@@ -134,7 +115,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- Logger.LogInformation("Beginning {0} stream to {1}", GetType().Name, TempFilePath);
|
|
|
|
|
|
+ Logger.LogInformation("Beginning {StreamType} stream to {FilePath}", GetType().Name, TempFilePath);
|
|
using var message = response;
|
|
using var message = response;
|
|
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
|
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
|
await using var fileStream = new FileStream(TempFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, AsyncFile.UseAsyncIO);
|
|
await using var fileStream = new FileStream(TempFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, AsyncFile.UseAsyncIO);
|
|
@@ -147,19 +128,19 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|
}
|
|
}
|
|
catch (OperationCanceledException ex)
|
|
catch (OperationCanceledException ex)
|
|
{
|
|
{
|
|
- Logger.LogInformation("Copying of {0} to {1} was canceled", GetType().Name, TempFilePath);
|
|
|
|
|
|
+ Logger.LogInformation("Copying of {StreamType} to {FilePath} was canceled", GetType().Name, TempFilePath);
|
|
openTaskCompletionSource.TrySetException(ex);
|
|
openTaskCompletionSource.TrySetException(ex);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
- Logger.LogError(ex, "Error copying live stream {0} to {1}.", GetType().Name, TempFilePath);
|
|
|
|
|
|
+ Logger.LogError(ex, "Error copying live stream {StreamType} to {FilePath}", GetType().Name, TempFilePath);
|
|
openTaskCompletionSource.TrySetException(ex);
|
|
openTaskCompletionSource.TrySetException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
openTaskCompletionSource.TrySetResult(false);
|
|
openTaskCompletionSource.TrySetResult(false);
|
|
|
|
|
|
EnableStreamSharing = false;
|
|
EnableStreamSharing = false;
|
|
- await DeleteTempFiles(new List<string> { TempFilePath }).ConfigureAwait(false);
|
|
|
|
|
|
+ await DeleteTempFiles(TempFilePath).ConfigureAwait(false);
|
|
},
|
|
},
|
|
CancellationToken.None);
|
|
CancellationToken.None);
|
|
}
|
|
}
|