aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Playback
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Api/Playback')
-rw-r--r--MediaBrowser.Api/Playback/BaseStreamingService.cs6
-rw-r--r--MediaBrowser.Api/Playback/Progressive/AudioService.cs8
-rw-r--r--MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs93
-rw-r--r--MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs10
-rw-r--r--MediaBrowser.Api/Playback/Progressive/VideoService.cs9
-rw-r--r--MediaBrowser.Api/Playback/UniversalAudioService.cs7
6 files changed, 34 insertions, 99 deletions
diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs
index a6be071b8..ae259a4f5 100644
--- a/MediaBrowser.Api/Playback/BaseStreamingService.cs
+++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs
@@ -609,12 +609,12 @@ namespace MediaBrowser.Api.Playback
{
foreach (var param in Request.QueryString)
{
- if (char.IsLower(param.Name[0]))
+ if (char.IsLower(param.Key[0]))
{
// This was probably not parsed initially and should be a StreamOptions
// TODO: This should be incorporated either in the lower framework for parsing requests
// or the generated URL should correctly serialize it
- request.StreamOptions[param.Name] = param.Value;
+ request.StreamOptions[param.Key] = param.Value;
}
}
}
@@ -867,7 +867,7 @@ namespace MediaBrowser.Api.Playback
private void ApplyDeviceProfileSettings(StreamState state)
{
- var headers = Request.Headers.ToDictionary();
+ var headers = Request.Headers;
if (!string.IsNullOrWhiteSpace(state.Request.DeviceProfileId))
{
diff --git a/MediaBrowser.Api/Playback/Progressive/AudioService.cs b/MediaBrowser.Api/Playback/Progressive/AudioService.cs
index 48b4e2f24..dfe4b2b8e 100644
--- a/MediaBrowser.Api/Playback/Progressive/AudioService.cs
+++ b/MediaBrowser.Api/Playback/Progressive/AudioService.cs
@@ -3,7 +3,6 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Dlna;
-using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net;
@@ -11,7 +10,6 @@ using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
-using MediaBrowser.Model.System;
namespace MediaBrowser.Api.Playback.Progressive
{
@@ -46,8 +44,7 @@ namespace MediaBrowser.Api.Playback.Progressive
IDeviceManager deviceManager,
IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer,
- IAuthorizationContext authorizationContext,
- IEnvironmentInfo environmentInfo)
+ IAuthorizationContext authorizationContext)
: base(httpClient,
serverConfig,
userManager,
@@ -60,8 +57,7 @@ namespace MediaBrowser.Api.Playback.Progressive
deviceManager,
mediaSourceManager,
jsonSerializer,
- authorizationContext,
- environmentInfo)
+ authorizationContext)
{
}
diff --git a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs
index 6a98c5e8a..a2c20e38f 100644
--- a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs
+++ b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
@@ -8,15 +7,13 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Dlna;
-using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization;
-using MediaBrowser.Model.Services;
-using MediaBrowser.Model.System;
+using Microsoft.Net.Http.Headers;
namespace MediaBrowser.Api.Playback.Progressive
{
@@ -25,7 +22,6 @@ namespace MediaBrowser.Api.Playback.Progressive
/// </summary>
public abstract class BaseProgressiveStreamingService : BaseStreamingService
{
- protected readonly IEnvironmentInfo EnvironmentInfo;
protected IHttpClient HttpClient { get; private set; }
public BaseProgressiveStreamingService(
@@ -41,8 +37,7 @@ namespace MediaBrowser.Api.Playback.Progressive
IDeviceManager deviceManager,
IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer,
- IAuthorizationContext authorizationContext,
- IEnvironmentInfo environmentInfo)
+ IAuthorizationContext authorizationContext)
: base(serverConfig,
userManager,
libraryManager,
@@ -56,7 +51,6 @@ namespace MediaBrowser.Api.Playback.Progressive
jsonSerializer,
authorizationContext)
{
- EnvironmentInfo = environmentInfo;
HttpClient = httpClient;
}
@@ -154,9 +148,9 @@ namespace MediaBrowser.Api.Playback.Progressive
var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
// TODO: Don't hardcode this
- outputHeaders["Content-Type"] = MediaBrowser.Model.Net.MimeTypes.GetMimeType("file.ts");
+ outputHeaders[HeaderNames.ContentType] = Model.Net.MimeTypes.GetMimeType("file.ts");
- return new ProgressiveFileCopier(state.DirectStreamProvider, outputHeaders, null, Logger, EnvironmentInfo, CancellationToken.None)
+ return new ProgressiveFileCopier(state.DirectStreamProvider, outputHeaders, null, Logger, CancellationToken.None)
{
AllowEndOfFile = false
};
@@ -196,11 +190,13 @@ namespace MediaBrowser.Api.Playback.Progressive
{
if (state.MediaSource.IsInfiniteStream)
{
- var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
+ var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
+ {
+ [HeaderNames.ContentType] = contentType
+ };
- outputHeaders["Content-Type"] = contentType;
- return new ProgressiveFileCopier(FileSystem, state.MediaPath, outputHeaders, null, Logger, EnvironmentInfo, CancellationToken.None)
+ return new ProgressiveFileCopier(FileSystem, state.MediaPath, outputHeaders, null, Logger, CancellationToken.None)
{
AllowEndOfFile = false
};
@@ -298,16 +294,16 @@ namespace MediaBrowser.Api.Playback.Progressive
if (trySupportSeek)
{
- if (!string.IsNullOrWhiteSpace(Request.QueryString["Range"]))
+ if (!string.IsNullOrWhiteSpace(Request.QueryString[HeaderNames.Range]))
{
- options.RequestHeaders["Range"] = Request.QueryString["Range"];
+ options.RequestHeaders[HeaderNames.Range] = Request.QueryString[HeaderNames.Range];
}
}
var response = await HttpClient.GetResponse(options).ConfigureAwait(false);
if (trySupportSeek)
{
- foreach (var name in new[] { "Content-Range", "Accept-Ranges" })
+ foreach (var name in new[] { HeaderNames.ContentRange, HeaderNames.AcceptRanges })
{
var val = response.Headers[name];
if (!string.IsNullOrWhiteSpace(val))
@@ -318,13 +314,7 @@ namespace MediaBrowser.Api.Playback.Progressive
}
else
{
- responseHeaders["Accept-Ranges"] = "none";
- }
-
- // Seeing cases of -1 here
- if (response.ContentLength.HasValue && response.ContentLength.Value >= 0)
- {
- responseHeaders["Content-Length"] = response.ContentLength.Value.ToString(UsCulture);
+ responseHeaders[HeaderNames.AcceptRanges] = "none";
}
if (isHeadRequest)
@@ -337,7 +327,7 @@ namespace MediaBrowser.Api.Playback.Progressive
var result = new StaticRemoteStreamWriter(response);
- result.Headers["Content-Type"] = response.ContentType;
+ result.Headers[HeaderNames.ContentType] = response.ContentType;
// Add the response headers to the result object
foreach (var header in responseHeaders)
@@ -361,41 +351,15 @@ namespace MediaBrowser.Api.Playback.Progressive
// Use the command line args with a dummy playlist path
var outputPath = state.OutputFilePath;
- responseHeaders["Accept-Ranges"] = "none";
+ responseHeaders[HeaderNames.AcceptRanges] = "none";
var contentType = state.GetMimeType(outputPath);
// TODO: The isHeadRequest is only here because ServiceStack will add Content-Length=0 to the response
- // What we really want to do is hunt that down and remove that
- var contentLength = state.EstimateContentLength || isHeadRequest ? GetEstimatedContentLength(state) : null;
-
- if (contentLength.HasValue)
- {
- responseHeaders["Content-Length"] = contentLength.Value.ToString(UsCulture);
- }
-
// Headers only
if (isHeadRequest)
{
- var streamResult = ResultFactory.GetResult(null, new byte[] { }, contentType, responseHeaders);
-
- var hasHeaders = streamResult as IHasHeaders;
- if (hasHeaders != null)
- {
- if (contentLength.HasValue)
- {
- hasHeaders.Headers["Content-Length"] = contentLength.Value.ToString(CultureInfo.InvariantCulture);
- }
- else
- {
- if (hasHeaders.Headers.ContainsKey("Content-Length"))
- {
- hasHeaders.Headers.Remove("Content-Length");
- }
- }
- }
-
- return streamResult;
+ return ResultFactory.GetResult(null, Array.Empty<byte>(), contentType, responseHeaders);
}
var transcodingLock = ApiEntryPoint.Instance.GetTranscodingLock(outputPath);
@@ -414,9 +378,11 @@ namespace MediaBrowser.Api.Playback.Progressive
state.Dispose();
}
- var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
+ var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
+ {
+ [HeaderNames.ContentType] = contentType
+ };
- outputHeaders["Content-Type"] = contentType;
// Add the response headers to the result object
foreach (var item in responseHeaders)
@@ -424,29 +390,12 @@ namespace MediaBrowser.Api.Playback.Progressive
outputHeaders[item.Key] = item.Value;
}
- return new ProgressiveFileCopier(FileSystem, outputPath, outputHeaders, job, Logger, EnvironmentInfo, CancellationToken.None);
+ return new ProgressiveFileCopier(FileSystem, outputPath, outputHeaders, job, Logger, CancellationToken.None);
}
finally
{
transcodingLock.Release();
}
}
-
- /// <summary>
- /// Gets the length of the estimated content.
- /// </summary>
- /// <param name="state">The state.</param>
- /// <returns>System.Nullable{System.Int64}.</returns>
- private long? GetEstimatedContentLength(StreamState state)
- {
- var totalBitrate = state.TotalOutputBitrate ?? 0;
-
- if (totalBitrate > 0 && state.RunTimeTicks.HasValue)
- {
- return Convert.ToInt64(totalBitrate * TimeSpan.FromTicks(state.RunTimeTicks.Value).TotalSeconds / 8);
- }
-
- return null;
- }
}
}
diff --git a/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs b/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs
index 3dd9de2a1..660912065 100644
--- a/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs
+++ b/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs
@@ -8,6 +8,7 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services;
using MediaBrowser.Model.System;
using Microsoft.Extensions.Logging;
+using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
namespace MediaBrowser.Api.Playback.Progressive
{
@@ -27,9 +28,8 @@ namespace MediaBrowser.Api.Playback.Progressive
public bool AllowEndOfFile = true;
private readonly IDirectStreamProvider _directStreamProvider;
- private readonly IEnvironmentInfo _environment;
- public ProgressiveFileCopier(IFileSystem fileSystem, string path, Dictionary<string, string> outputHeaders, TranscodingJob job, ILogger logger, IEnvironmentInfo environment, CancellationToken cancellationToken)
+ public ProgressiveFileCopier(IFileSystem fileSystem, string path, Dictionary<string, string> outputHeaders, TranscodingJob job, ILogger logger, CancellationToken cancellationToken)
{
_fileSystem = fileSystem;
_path = path;
@@ -37,17 +37,15 @@ namespace MediaBrowser.Api.Playback.Progressive
_job = job;
_logger = logger;
_cancellationToken = cancellationToken;
- _environment = environment;
}
- public ProgressiveFileCopier(IDirectStreamProvider directStreamProvider, Dictionary<string, string> outputHeaders, TranscodingJob job, ILogger logger, IEnvironmentInfo environment, CancellationToken cancellationToken)
+ public ProgressiveFileCopier(IDirectStreamProvider directStreamProvider, Dictionary<string, string> outputHeaders, TranscodingJob job, ILogger logger, CancellationToken cancellationToken)
{
_directStreamProvider = directStreamProvider;
_outputHeaders = outputHeaders;
_job = job;
_logger = logger;
_cancellationToken = cancellationToken;
- _environment = environment;
}
public IDictionary<string, string> Headers => _outputHeaders;
@@ -79,7 +77,7 @@ namespace MediaBrowser.Api.Playback.Progressive
var eofCount = 0;
// use non-async filestream along with read due to https://github.com/dotnet/corefx/issues/6039
- var allowAsyncFileRead = _environment.OperatingSystem != Model.System.OperatingSystem.Windows;
+ var allowAsyncFileRead = OperatingSystem.Id != OperatingSystemId.Windows;
using (var inputStream = GetInputStream(allowAsyncFileRead))
{
diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs
index 7aeb0e9e8..ab19fdc26 100644
--- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs
+++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs
@@ -3,7 +3,6 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Dlna;
-using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net;
@@ -11,7 +10,6 @@ using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
-using MediaBrowser.Model.System;
namespace MediaBrowser.Api.Playback.Progressive
{
@@ -37,6 +35,7 @@ namespace MediaBrowser.Api.Playback.Progressive
[Route("/Videos/{Id}/stream.mov", "GET")]
[Route("/Videos/{Id}/stream.iso", "GET")]
[Route("/Videos/{Id}/stream.flv", "GET")]
+ [Route("/Videos/{Id}/stream.rm", "GET")]
[Route("/Videos/{Id}/stream", "GET")]
[Route("/Videos/{Id}/stream.ts", "HEAD")]
[Route("/Videos/{Id}/stream.webm", "HEAD")]
@@ -82,8 +81,7 @@ namespace MediaBrowser.Api.Playback.Progressive
IDeviceManager deviceManager,
IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer,
- IAuthorizationContext authorizationContext,
- IEnvironmentInfo environmentInfo)
+ IAuthorizationContext authorizationContext)
: base(httpClient,
serverConfig,
userManager,
@@ -96,8 +94,7 @@ namespace MediaBrowser.Api.Playback.Progressive
deviceManager,
mediaSourceManager,
jsonSerializer,
- authorizationContext,
- environmentInfo)
+ authorizationContext)
{
}
diff --git a/MediaBrowser.Api/Playback/UniversalAudioService.cs b/MediaBrowser.Api/Playback/UniversalAudioService.cs
index f97e88e98..b3d8bfe59 100644
--- a/MediaBrowser.Api/Playback/UniversalAudioService.cs
+++ b/MediaBrowser.Api/Playback/UniversalAudioService.cs
@@ -18,7 +18,6 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
-using MediaBrowser.Model.System;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Playback
@@ -93,7 +92,6 @@ namespace MediaBrowser.Api.Playback
IAuthorizationContext authorizationContext,
IImageProcessor imageProcessor,
INetworkManager networkManager,
- IEnvironmentInfo environmentInfo,
ILoggerFactory loggerFactory)
{
HttpClient = httpClient;
@@ -112,7 +110,6 @@ namespace MediaBrowser.Api.Playback
AuthorizationContext = authorizationContext;
ImageProcessor = imageProcessor;
NetworkManager = networkManager;
- EnvironmentInfo = environmentInfo;
_loggerFactory = loggerFactory;
_logger = loggerFactory.CreateLogger(nameof(UniversalAudioService));
}
@@ -133,7 +130,6 @@ namespace MediaBrowser.Api.Playback
protected IAuthorizationContext AuthorizationContext { get; private set; }
protected IImageProcessor ImageProcessor { get; private set; }
protected INetworkManager NetworkManager { get; private set; }
- protected IEnvironmentInfo EnvironmentInfo { get; private set; }
private ILoggerFactory _loggerFactory;
private ILogger _logger;
@@ -338,8 +334,7 @@ namespace MediaBrowser.Api.Playback
DeviceManager,
MediaSourceManager,
JsonSerializer,
- AuthorizationContext,
- EnvironmentInfo)
+ AuthorizationContext)
{
Request = Request
};