Merge pull request #1723 from Bond-009/mrmc

Possible fix for MrMC
This commit is contained in:
Anthony Lavado 2019-09-08 18:10:47 -04:00 committed by GitHub
commit e6a1407786
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 45 deletions

View File

@ -83,7 +83,16 @@ namespace Emby.Server.Implementations.HttpClientManager
var request = new HttpRequestMessage(method, url);
AddRequestHeaders(request, options);
foreach (var header in options.RequestHeaders)
{
request.Headers.TryAddWithoutValidation(header.Key, header.Value);
}
if (options.EnableDefaultUserAgent
&& !request.Headers.TryGetValues(HeaderNames.UserAgent, out _))
{
request.Headers.Add(HeaderNames.UserAgent, _defaultUserAgentFn());
}
switch (options.DecompressionMethod)
{
@ -121,26 +130,6 @@ namespace Emby.Server.Implementations.HttpClientManager
return request;
}
private void AddRequestHeaders(HttpRequestMessage request, HttpRequestOptions options)
{
var hasUserAgent = false;
foreach (var header in options.RequestHeaders)
{
if (string.Equals(header.Key, HeaderNames.UserAgent, StringComparison.OrdinalIgnoreCase))
{
hasUserAgent = true;
}
request.Headers.Add(header.Key, header.Value);
}
if (!hasUserAgent && options.EnableDefaultUserAgent)
{
request.Headers.Add(HeaderNames.UserAgent, _defaultUserAgentFn());
}
}
/// <summary>
/// Gets the response internal.
/// </summary>

View File

@ -956,7 +956,10 @@ namespace MediaBrowser.Api.Playback
if (string.Equals(GetHeader("getMediaInfo.sec"), "1", StringComparison.OrdinalIgnoreCase))
{
var ms = TimeSpan.FromTicks(state.RunTimeTicks.Value).TotalMilliseconds;
responseHeaders["MediaInfo.sec"] = string.Format("SEC_Duration={0};", Convert.ToInt32(ms).ToString(CultureInfo.InvariantCulture));
responseHeaders["MediaInfo.sec"] = string.Format(
CultureInfo.InvariantCulture,
"SEC_Duration={0};",
Convert.ToInt32(ms));
}
if (!isStaticallyStreamed && profile != null)
@ -974,8 +977,7 @@ namespace MediaBrowser.Api.Playback
if (state.VideoRequest == null)
{
responseHeaders["contentFeatures.dlna.org"] = new ContentFeatureBuilder(profile)
.BuildAudioHeader(
responseHeaders["contentFeatures.dlna.org"] = new ContentFeatureBuilder(profile).BuildAudioHeader(
state.OutputContainer,
audioCodec,
state.OutputAudioBitrate,
@ -984,15 +986,13 @@ namespace MediaBrowser.Api.Playback
state.OutputAudioBitDepth,
isStaticallyStreamed,
state.RunTimeTicks,
state.TranscodeSeekInfo
);
state.TranscodeSeekInfo);
}
else
{
var videoCodec = state.ActualOutputVideoCodec;
responseHeaders["contentFeatures.dlna.org"] = new ContentFeatureBuilder(profile)
.BuildVideoHeader(
responseHeaders["contentFeatures.dlna.org"] = new ContentFeatureBuilder(profile).BuildVideoHeader(
state.OutputContainer,
videoCodec,
audioCodec,
@ -1014,9 +1014,7 @@ namespace MediaBrowser.Api.Playback
state.TargetVideoStreamCount,
state.TargetAudioStreamCount,
state.TargetVideoCodecTag,
state.IsTargetAVC
).FirstOrDefault() ?? string.Empty;
state.IsTargetAVC).FirstOrDefault() ?? string.Empty;
}
}
@ -1025,8 +1023,16 @@ namespace MediaBrowser.Api.Playback
var runtimeSeconds = TimeSpan.FromTicks(state.RunTimeTicks.Value).TotalSeconds.ToString(CultureInfo.InvariantCulture);
var startSeconds = TimeSpan.FromTicks(state.Request.StartTimeTicks ?? 0).TotalSeconds.ToString(CultureInfo.InvariantCulture);
responseHeaders["TimeSeekRange.dlna.org"] = string.Format("npt={0}-{1}/{1}", startSeconds, runtimeSeconds);
responseHeaders["X-AvailableSeekRange"] = string.Format("1 npt={0}-{1}", startSeconds, runtimeSeconds);
responseHeaders["TimeSeekRange.dlna.org"] = string.Format(
CultureInfo.InvariantCulture,
"npt={0}-{1}/{1}",
startSeconds,
runtimeSeconds);
responseHeaders["X-AvailableSeekRange"] = string.Format(
CultureInfo.InvariantCulture,
"1 npt={0}-{1}",
startSeconds,
runtimeSeconds);
}
}
}

View File

@ -280,18 +280,24 @@ namespace MediaBrowser.Api.Playback.Progressive
/// <param name="isHeadRequest">if set to <c>true</c> [is head request].</param>
/// <param name="cancellationTokenSource">The cancellation token source.</param>
/// <returns>Task{System.Object}.</returns>
private async Task<object> GetStaticRemoteStreamResult(StreamState state, Dictionary<string, string> responseHeaders, bool isHeadRequest, CancellationTokenSource cancellationTokenSource)
private async Task<object> GetStaticRemoteStreamResult(
StreamState state,
Dictionary<string, string> responseHeaders,
bool isHeadRequest,
CancellationTokenSource cancellationTokenSource)
{
state.RemoteHttpHeaders.TryGetValue(HeaderNames.UserAgent, out var useragent);
var options = new HttpRequestOptions
{
Url = state.MediaPath,
UserAgent = useragent,
BufferContent = false,
CancellationToken = cancellationTokenSource.Token
};
if (state.RemoteHttpHeaders.TryGetValue(HeaderNames.UserAgent, out var useragent))
{
options.UserAgent = useragent;
}
var response = await HttpClient.GetResponse(options).ConfigureAwait(false);
responseHeaders[HeaderNames.AcceptRanges] = "none";
@ -306,7 +312,7 @@ namespace MediaBrowser.Api.Playback.Progressive
{
using (response)
{
return ResultFactory.GetResult(null, new byte[] { }, response.ContentType, responseHeaders);
return ResultFactory.GetResult(null, Array.Empty<byte>(), response.ContentType, responseHeaders);
}
}

View File

@ -168,9 +168,7 @@ namespace MediaBrowser.Controller.MediaEncoding
/// <returns>System.String.</returns>
public string GetUserAgentParam(EncodingJobInfo state)
{
state.RemoteHttpHeaders.TryGetValue("User-Agent", out string useragent);
if (!string.IsNullOrEmpty(useragent))
if (state.RemoteHttpHeaders.TryGetValue("User-Agent", out string useragent))
{
return "-user_agent \"" + useragent + "\"";
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using MediaBrowser.Model.MediaInfo;
namespace MediaBrowser.Model.Dlna
@ -81,17 +82,20 @@ namespace MediaBrowser.Model.Dlna
// flagValue = flagValue | DlnaFlags.TimeBasedSeek;
//}
string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}",
string dlnaflags = string.Format(
CultureInfo.InvariantCulture,
";DLNA.ORG_FLAGS={0}",
DlnaMaps.FlagsToString(flagValue));
ResponseProfile mediaProfile = _profile.GetAudioMediaProfile(container,
ResponseProfile mediaProfile = _profile.GetAudioMediaProfile(
container,
audioCodec,
audioChannels,
audioBitrate,
audioSampleRate,
audioBitDepth);
string orgPn = mediaProfile == null ? null : mediaProfile.OrgPn;
string orgPn = mediaProfile?.OrgPn;
if (string.IsNullOrEmpty(orgPn))
{