update behavior with restricted transcoding access

This commit is contained in:
Luke Pulverenti
2016-07-25 01:12:38 -04:00
parent b878dc1537
commit 8328f39834
12 changed files with 98 additions and 150 deletions

View File

@@ -18,6 +18,8 @@ namespace MediaBrowser.Model.Dlna
public bool EnableDirectPlay { get; set; }
public bool EnableDirectStream { get; set; }
public bool ForceDirectPlay { get; set; }
public bool ForceDirectStream { get; set; }
public string ItemId { get; set; }
public List<MediaSourceInfo> MediaSources { get; set; }

View File

@@ -1,39 +0,0 @@

namespace MediaBrowser.Model.Dlna
{
public interface ILocalPlayer
{
/// <summary>
/// Determines whether this instance [can access file] the specified path.
/// </summary>
/// <param name="path">The path.</param>
/// <returns><c>true</c> if this instance [can access file] the specified path; otherwise, <c>false</c>.</returns>
bool CanAccessFile(string path);
/// <summary>
/// Determines whether this instance [can access directory] the specified path.
/// </summary>
/// <param name="path">The path.</param>
/// <returns><c>true</c> if this instance [can access directory] the specified path; otherwise, <c>false</c>.</returns>
bool CanAccessDirectory(string path);
/// <summary>
/// Determines whether this instance [can access URL] the specified URL.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="requiresCustomRequestHeaders">if set to <c>true</c> [requires custom request headers].</param>
/// <returns><c>true</c> if this instance [can access URL] the specified URL; otherwise, <c>false</c>.</returns>
bool CanAccessUrl(string url, bool requiresCustomRequestHeaders);
}
public interface ITranscoderSupport
{
bool CanEncodeToAudioCodec(string codec);
}
public class FullTranscoderSupport : ITranscoderSupport
{
public bool CanEncodeToAudioCodec(string codec)
{
return true;
}
}
}

View File

@@ -0,0 +1,15 @@
namespace MediaBrowser.Model.Dlna
{
public interface ITranscoderSupport
{
bool CanEncodeToAudioCodec(string codec);
}
public class FullTranscoderSupport : ITranscoderSupport
{
public bool CanEncodeToAudioCodec(string codec)
{
return true;
}
}
}

View File

@@ -1,21 +0,0 @@

namespace MediaBrowser.Model.Dlna
{
public class NullLocalPlayer : ILocalPlayer
{
public bool CanAccessFile(string path)
{
return false;
}
public bool CanAccessDirectory(string path)
{
return false;
}
public bool CanAccessUrl(string url, bool requiresCustomRequestHeaders)
{
return false;
}
}
}

View File

@@ -11,29 +11,17 @@ namespace MediaBrowser.Model.Dlna
{
public class StreamBuilder
{
private readonly ILocalPlayer _localPlayer;
private readonly ILogger _logger;
private readonly ITranscoderSupport _transcoderSupport;
public StreamBuilder(ILocalPlayer localPlayer, ITranscoderSupport transcoderSupport, ILogger logger)
public StreamBuilder(ITranscoderSupport transcoderSupport, ILogger logger)
{
_transcoderSupport = transcoderSupport;
_localPlayer = localPlayer;
_logger = logger;
}
public StreamBuilder(ITranscoderSupport transcoderSupport, ILogger logger)
: this(new NullLocalPlayer(), transcoderSupport, logger)
{
}
public StreamBuilder(ILocalPlayer localPlayer, ILogger logger)
: this(localPlayer, new FullTranscoderSupport(), logger)
{
}
public StreamBuilder(ILogger logger)
: this(new NullLocalPlayer(), new FullTranscoderSupport(), logger)
: this(new FullTranscoderSupport(), logger)
{
}
@@ -127,6 +115,20 @@ namespace MediaBrowser.Model.Dlna
DeviceProfile = options.Profile
};
if (options.ForceDirectPlay)
{
playlistItem.PlayMethod = PlayMethod.DirectPlay;
playlistItem.Container = item.Container;
return playlistItem;
}
if (options.ForceDirectStream)
{
playlistItem.PlayMethod = PlayMethod.DirectStream;
playlistItem.Container = item.Container;
return playlistItem;
}
MediaStream audioStream = item.GetDefaultAudioStream(null);
List<PlayMethod> directPlayMethods = GetAudioDirectPlayMethods(item, audioStream, options);
@@ -182,19 +184,7 @@ namespace MediaBrowser.Model.Dlna
if (all)
{
if (item.Protocol == MediaProtocol.File &&
directPlayMethods.Contains(PlayMethod.DirectPlay) &&
_localPlayer.CanAccessFile(item.Path))
{
playlistItem.PlayMethod = PlayMethod.DirectPlay;
}
else if (item.Protocol == MediaProtocol.Http &&
directPlayMethods.Contains(PlayMethod.DirectPlay) &&
_localPlayer.CanAccessUrl(item.Path, item.RequiredHttpHeaders.Count > 0))
{
playlistItem.PlayMethod = PlayMethod.DirectPlay;
}
else if (directPlayMethods.Contains(PlayMethod.DirectStream))
if (directPlayMethods.Contains(PlayMethod.DirectStream))
{
playlistItem.PlayMethod = PlayMethod.DirectStream;
}
@@ -413,8 +403,8 @@ namespace MediaBrowser.Model.Dlna
MediaStream videoStream = item.VideoStream;
// TODO: This doesn't accout for situation of device being able to handle media bitrate, but wifi connection not fast enough
bool isEligibleForDirectPlay = options.EnableDirectPlay && IsEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options), subtitleStream, options, PlayMethod.DirectPlay);
bool isEligibleForDirectStream = options.EnableDirectStream && IsEligibleForDirectPlay(item, options.GetMaxBitrate(), subtitleStream, options, PlayMethod.DirectStream);
bool isEligibleForDirectPlay = options.EnableDirectPlay && (options.ForceDirectPlay || IsEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options), subtitleStream, options, PlayMethod.DirectPlay));
bool isEligibleForDirectStream = options.EnableDirectStream && (options.ForceDirectStream || IsEligibleForDirectPlay(item, options.GetMaxBitrate(), subtitleStream, options, PlayMethod.DirectStream));
_logger.Info("Profile: {0}, Path: {1}, isEligibleForDirectPlay: {2}, isEligibleForDirectStream: {3}",
options.Profile.Name ?? "Unknown Profile",
@@ -425,7 +415,7 @@ namespace MediaBrowser.Model.Dlna
if (isEligibleForDirectPlay || isEligibleForDirectStream)
{
// See if it can be direct played
PlayMethod? directPlay = GetVideoDirectPlayProfile(options.Profile, item, videoStream, audioStream, isEligibleForDirectPlay, isEligibleForDirectStream);
PlayMethod? directPlay = GetVideoDirectPlayProfile(options, item, videoStream, audioStream, isEligibleForDirectPlay, isEligibleForDirectStream);
if (directPlay != null)
{
@@ -645,13 +635,24 @@ namespace MediaBrowser.Model.Dlna
return Math.Min(defaultBitrate, encoderAudioBitrateLimit);
}
private PlayMethod? GetVideoDirectPlayProfile(DeviceProfile profile,
private PlayMethod? GetVideoDirectPlayProfile(VideoOptions options,
MediaSourceInfo mediaSource,
MediaStream videoStream,
MediaStream audioStream,
bool isEligibleForDirectPlay,
bool isEligibleForDirectStream)
{
DeviceProfile profile = options.Profile;
if (options.ForceDirectPlay)
{
return PlayMethod.DirectPlay;
}
if (options.ForceDirectStream)
{
return PlayMethod.DirectStream;
}
if (videoStream == null)
{
_logger.Info("Profile: {0}, Cannot direct stream with no known video stream. Path: {1}",
@@ -829,25 +830,6 @@ namespace MediaBrowser.Model.Dlna
}
}
if (isEligibleForDirectPlay && mediaSource.SupportsDirectPlay)
{
if (mediaSource.Protocol == MediaProtocol.Http)
{
if (_localPlayer.CanAccessUrl(mediaSource.Path, mediaSource.RequiredHttpHeaders.Count > 0))
{
return PlayMethod.DirectPlay;
}
}
else if (mediaSource.Protocol == MediaProtocol.File)
{
if (_localPlayer.CanAccessFile(mediaSource.Path))
{
return PlayMethod.DirectPlay;
}
}
}
if (isEligibleForDirectStream && mediaSource.SupportsDirectStream)
{
return PlayMethod.DirectStream;

View File

@@ -118,9 +118,8 @@
<Compile Include="Devices\DeviceInfo.cs" />
<Compile Include="Devices\DevicesOptions.cs" />
<Compile Include="Dlna\EncodingContext.cs" />
<Compile Include="Dlna\ILocalPlayer.cs" />
<Compile Include="Dlna\ITranscoderSupport.cs" />
<Compile Include="Dlna\StreamInfoSorter.cs" />
<Compile Include="Dlna\NullLocalPlayer.cs" />
<Compile Include="Dlna\PlaybackErrorCode.cs" />
<Compile Include="Dlna\PlaybackException.cs" />
<Compile Include="Dlna\ResolutionConfiguration.cs" />