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); 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) switch (options.DecompressionMethod)
{ {
@ -121,26 +130,6 @@ namespace Emby.Server.Implementations.HttpClientManager
return request; 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> /// <summary>
/// Gets the response internal. /// Gets the response internal.
/// </summary> /// </summary>

View File

@ -956,7 +956,10 @@ namespace MediaBrowser.Api.Playback
if (string.Equals(GetHeader("getMediaInfo.sec"), "1", StringComparison.OrdinalIgnoreCase)) if (string.Equals(GetHeader("getMediaInfo.sec"), "1", StringComparison.OrdinalIgnoreCase))
{ {
var ms = TimeSpan.FromTicks(state.RunTimeTicks.Value).TotalMilliseconds; 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) if (!isStaticallyStreamed && profile != null)
@ -974,8 +977,7 @@ namespace MediaBrowser.Api.Playback
if (state.VideoRequest == null) if (state.VideoRequest == null)
{ {
responseHeaders["contentFeatures.dlna.org"] = new ContentFeatureBuilder(profile) responseHeaders["contentFeatures.dlna.org"] = new ContentFeatureBuilder(profile).BuildAudioHeader(
.BuildAudioHeader(
state.OutputContainer, state.OutputContainer,
audioCodec, audioCodec,
state.OutputAudioBitrate, state.OutputAudioBitrate,
@ -984,15 +986,13 @@ namespace MediaBrowser.Api.Playback
state.OutputAudioBitDepth, state.OutputAudioBitDepth,
isStaticallyStreamed, isStaticallyStreamed,
state.RunTimeTicks, state.RunTimeTicks,
state.TranscodeSeekInfo state.TranscodeSeekInfo);
);
} }
else else
{ {
var videoCodec = state.ActualOutputVideoCodec; var videoCodec = state.ActualOutputVideoCodec;
responseHeaders["contentFeatures.dlna.org"] = new ContentFeatureBuilder(profile) responseHeaders["contentFeatures.dlna.org"] = new ContentFeatureBuilder(profile).BuildVideoHeader(
.BuildVideoHeader(
state.OutputContainer, state.OutputContainer,
videoCodec, videoCodec,
audioCodec, audioCodec,
@ -1014,9 +1014,7 @@ namespace MediaBrowser.Api.Playback
state.TargetVideoStreamCount, state.TargetVideoStreamCount,
state.TargetAudioStreamCount, state.TargetAudioStreamCount,
state.TargetVideoCodecTag, state.TargetVideoCodecTag,
state.IsTargetAVC state.IsTargetAVC).FirstOrDefault() ?? string.Empty;
).FirstOrDefault() ?? string.Empty;
} }
} }
@ -1025,8 +1023,16 @@ namespace MediaBrowser.Api.Playback
var runtimeSeconds = TimeSpan.FromTicks(state.RunTimeTicks.Value).TotalSeconds.ToString(CultureInfo.InvariantCulture); var runtimeSeconds = TimeSpan.FromTicks(state.RunTimeTicks.Value).TotalSeconds.ToString(CultureInfo.InvariantCulture);
var startSeconds = TimeSpan.FromTicks(state.Request.StartTimeTicks ?? 0).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["TimeSeekRange.dlna.org"] = string.Format(
responseHeaders["X-AvailableSeekRange"] = string.Format("1 npt={0}-{1}", startSeconds, runtimeSeconds); 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="isHeadRequest">if set to <c>true</c> [is head request].</param>
/// <param name="cancellationTokenSource">The cancellation token source.</param> /// <param name="cancellationTokenSource">The cancellation token source.</param>
/// <returns>Task{System.Object}.</returns> /// <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 var options = new HttpRequestOptions
{ {
Url = state.MediaPath, Url = state.MediaPath,
UserAgent = useragent,
BufferContent = false, BufferContent = false,
CancellationToken = cancellationTokenSource.Token CancellationToken = cancellationTokenSource.Token
}; };
if (state.RemoteHttpHeaders.TryGetValue(HeaderNames.UserAgent, out var useragent))
{
options.UserAgent = useragent;
}
var response = await HttpClient.GetResponse(options).ConfigureAwait(false); var response = await HttpClient.GetResponse(options).ConfigureAwait(false);
responseHeaders[HeaderNames.AcceptRanges] = "none"; responseHeaders[HeaderNames.AcceptRanges] = "none";
@ -306,7 +312,7 @@ namespace MediaBrowser.Api.Playback.Progressive
{ {
using (response) 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> /// <returns>System.String.</returns>
public string GetUserAgentParam(EncodingJobInfo state) public string GetUserAgentParam(EncodingJobInfo state)
{ {
state.RemoteHttpHeaders.TryGetValue("User-Agent", out string useragent); if (state.RemoteHttpHeaders.TryGetValue("User-Agent", out string useragent))
if (!string.IsNullOrEmpty(useragent))
{ {
return "-user_agent \"" + useragent + "\""; return "-user_agent \"" + useragent + "\"";
} }

View File

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