Merge pull request #2794 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2017-08-04 16:30:15 -04:00 committed by GitHub
commit e169eaee6c
18 changed files with 194 additions and 111 deletions

View File

@ -131,6 +131,10 @@ namespace Emby.Server.Implementations.Data
{
queries.Add("PRAGMA temp_store = memory");
}
else
{
queries.Add("PRAGMA temp_store = file");
}
////foreach (var query in queries)
////{

View File

@ -779,7 +779,7 @@ namespace MediaBrowser.Api.Playback
if (string.IsNullOrEmpty(container))
{
container = request.Static ?
state.InputContainer :
StreamBuilder.NormalizeMediaSourceFormatIntoSingleContainer(state.InputContainer, null, DlnaProfileType.Audio) :
GetOutputFileExtension(state);
}

View File

@ -144,6 +144,11 @@ namespace MediaBrowser.Api.Playback
}
}
if (result.MediaSource != null)
{
NormalizeMediaSourceContainer(result.MediaSource, profile, DlnaProfileType.Video);
}
return result;
}
@ -207,9 +212,22 @@ namespace MediaBrowser.Api.Playback
}
}
if (info.MediaSources != null)
{
foreach (var mediaSource in info.MediaSources)
{
NormalizeMediaSourceContainer(mediaSource, profile, DlnaProfileType.Video);
}
}
return info;
}
private void NormalizeMediaSourceContainer(MediaSourceInfo mediaSource, DeviceProfile profile, DlnaProfileType type)
{
mediaSource.Container = StreamBuilder.NormalizeMediaSourceFormatIntoSingleContainer(mediaSource.Container, profile, type);
}
public async Task<object> Post(GetPostedPlaybackInfo request)
{
var result = await GetPlaybackInfo(request).ConfigureAwait(false);

View File

@ -167,7 +167,7 @@ namespace MediaBrowser.Api.Playback.Progressive
// Static stream
if (request.Static)
{
var contentType = state.GetMimeType(state.MediaPath);
var contentType = state.GetMimeType("." + state.OutputContainer, false) ?? state.GetMimeType(state.MediaPath);
using (state)
{

View File

@ -131,14 +131,14 @@ namespace MediaBrowser.Api.Playback
public long? EncodingDurationTicks { get; set; }
public string GetMimeType(string outputPath)
public string GetMimeType(string outputPath, bool enableStreamDefault = true)
{
if (!string.IsNullOrEmpty(MimeType))
{
return MimeType;
}
return MimeTypes.GetMimeType(outputPath);
return MimeTypes.GetMimeType(outputPath, enableStreamDefault);
}
public bool EnableDlnaHeaders { get; set; }

View File

@ -48,23 +48,20 @@ namespace MediaBrowser.Controller.LiveTv
return list;
}
private static string EmbyServiceName = "Emby";
public override double? GetDefaultPrimaryImageAspectRatio()
{
if (IsMovie)
var serviceName = ServiceName;
if (!IsMovie && !string.Equals(serviceName, EmbyServiceName, StringComparison.OrdinalIgnoreCase) || !string.IsNullOrWhiteSpace(serviceName))
{
return null;
}
double value = 2;
value /= 3;
return value;
}
else
{
double value = 2;
value /= 3;
return value;
}
}
[IgnoreDataMember]
public override SourceType SourceType

View File

@ -10,6 +10,7 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Extensions;
namespace MediaBrowser.Controller.MediaEncoding
{
@ -148,10 +149,13 @@ namespace MediaBrowser.Controller.MediaEncoding
public string GetInputFormat(string container)
{
if (string.Equals(container, "mkv", StringComparison.OrdinalIgnoreCase))
if (string.IsNullOrWhiteSpace(container))
{
return "matroska";
return null;
}
container = container.Replace("mkv", "matroska", StringComparison.OrdinalIgnoreCase);
if (string.Equals(container, "ts", StringComparison.OrdinalIgnoreCase))
{
return "mpegts";
@ -1694,7 +1698,8 @@ namespace MediaBrowser.Controller.MediaEncoding
state.InputAudioSync = "1";
}
if (string.Equals(mediaSource.Container, "wma", StringComparison.OrdinalIgnoreCase))
if (string.Equals(mediaSource.Container, "wma", StringComparison.OrdinalIgnoreCase) ||
string.Equals(mediaSource.Container, "asf", StringComparison.OrdinalIgnoreCase))
{
// Seeing some stuttering when transcoding wma to audio-only HLS
state.InputAudioSync = "1";

View File

@ -53,7 +53,7 @@ namespace MediaBrowser.MediaEncoding.Probing
if (data.format != null)
{
info.Container = data.format.format_name;
info.Container = NormalizeFormat(data.format.format_name);
if (!string.IsNullOrEmpty(data.format.bit_rate))
{
@ -195,6 +195,23 @@ namespace MediaBrowser.MediaEncoding.Probing
return info;
}
private string NormalizeFormat(string format)
{
if (string.IsNullOrWhiteSpace(format))
{
return null;
}
if (string.Equals(format, "mpegvideo", StringComparison.OrdinalIgnoreCase))
{
return "mpeg";
}
format = format.Replace("matroska", "mkv", StringComparison.OrdinalIgnoreCase);
return format;
}
private int? GetEstimatedAudioBitrate(string codec, int? channels)
{
if (!channels.HasValue)

View File

@ -42,16 +42,9 @@ namespace MediaBrowser.Model.Dlna
return SplitValue(Codec);
}
public List<string> GetContainers()
{
return SplitValue(Container);
}
private bool ContainsContainer(string container)
{
List<string> containers = GetContainers();
return containers.Count == 0 || ListHelper.ContainsIgnoreCase(containers, container ?? string.Empty);
return ContainerProfile.ContainsContainer(Container, container);
}
public bool ContainsCodec(string codec, string container)

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Extensions;
@ -21,10 +22,15 @@ namespace MediaBrowser.Model.Dlna
public List<string> GetContainers()
{
List<string> list = new List<string>();
foreach (string i in (Container ?? string.Empty).Split(','))
return SplitValue(Container);
}
public static List<string> SplitValue(string value)
{
if (!string.IsNullOrEmpty(i)) list.Add(i);
List<string> list = new List<string>();
foreach (string i in (value ?? string.Empty).Split(','))
{
if (!string.IsNullOrWhiteSpace(i)) list.Add(i);
}
return list;
}
@ -33,7 +39,32 @@ namespace MediaBrowser.Model.Dlna
{
List<string> containers = GetContainers();
return containers.Count == 0 || ListHelper.ContainsIgnoreCase(containers, container ?? string.Empty);
return ContainsContainer(containers, container);
}
public static bool ContainsContainer(string profileContainers, string inputContainer)
{
return ContainsContainer(SplitValue(profileContainers), inputContainer);
}
public static bool ContainsContainer(List<string> profileContainers, string inputContainer)
{
if (profileContainers.Count == 0)
{
return true;
}
var allInputContainers = SplitValue(inputContainer);
foreach (var container in allInputContainers)
{
if (ListHelper.ContainsIgnoreCase(profileContainers, container))
{
return true;
}
}
return false;
}
}
}

View File

@ -187,17 +187,14 @@ namespace MediaBrowser.Model.Dlna
public ResponseProfile GetAudioMediaProfile(string container, string audioCodec, int? audioChannels, int? audioBitrate, int? audioSampleRate, int? audioBitDepth)
{
container = StringHelper.TrimStart(container ?? string.Empty, '.');
foreach (var i in ResponseProfiles)
{
if (i.Type != MediaBrowser.Model.Dlna.DlnaProfileType.Audio)
if (i.Type != DlnaProfileType.Audio)
{
continue;
}
List<string> containers = i.GetContainers();
if (containers.Count > 0 && !ListHelper.ContainsIgnoreCase(containers, container))
if (!ContainerProfile.ContainsContainer(i.GetContainers(), container))
{
continue;
}
@ -208,7 +205,7 @@ namespace MediaBrowser.Model.Dlna
continue;
}
var conditionProcessor = new MediaBrowser.Model.Dlna.ConditionProcessor();
var conditionProcessor = new ConditionProcessor();
var anyOff = false;
foreach (ProfileCondition c in i.Conditions)
@ -230,9 +227,9 @@ namespace MediaBrowser.Model.Dlna
return null;
}
private MediaBrowser.Model.Dlna.ProfileCondition GetModelProfileCondition(ProfileCondition c)
private ProfileCondition GetModelProfileCondition(ProfileCondition c)
{
return new MediaBrowser.Model.Dlna.ProfileCondition
return new ProfileCondition
{
Condition = c.Condition,
IsRequired = c.IsRequired,
@ -243,22 +240,19 @@ namespace MediaBrowser.Model.Dlna
public ResponseProfile GetImageMediaProfile(string container, int? width, int? height)
{
container = StringHelper.TrimStart(container ?? string.Empty, '.');
foreach (var i in ResponseProfiles)
{
if (i.Type != MediaBrowser.Model.Dlna.DlnaProfileType.Photo)
if (i.Type != DlnaProfileType.Photo)
{
continue;
}
List<string> containers = i.GetContainers();
if (containers.Count > 0 && !ListHelper.ContainsIgnoreCase(containers, container))
if (!ContainerProfile.ContainsContainer(i.GetContainers(), container))
{
continue;
}
var conditionProcessor = new MediaBrowser.Model.Dlna.ConditionProcessor();
var conditionProcessor = new ConditionProcessor();
var anyOff = false;
foreach (ProfileCondition c in i.Conditions)
@ -300,17 +294,14 @@ namespace MediaBrowser.Model.Dlna
string videoCodecTag,
bool? isAvc)
{
container = StringHelper.TrimStart(container ?? string.Empty, '.');
foreach (var i in ResponseProfiles)
{
if (i.Type != MediaBrowser.Model.Dlna.DlnaProfileType.Video)
if (i.Type != DlnaProfileType.Video)
{
continue;
}
List<string> containers = i.GetContainers();
if (containers.Count > 0 && !ListHelper.ContainsIgnoreCase(containers, container ?? string.Empty))
if (!ContainerProfile.ContainsContainer(i.GetContainers(), container))
{
continue;
}
@ -327,7 +318,7 @@ namespace MediaBrowser.Model.Dlna
continue;
}
var conditionProcessor = new MediaBrowser.Model.Dlna.ConditionProcessor();
var conditionProcessor = new ConditionProcessor();
var anyOff = false;
foreach (ProfileCondition c in i.Conditions)

View File

@ -19,27 +19,9 @@ namespace MediaBrowser.Model.Dlna
[XmlAttribute("type")]
public DlnaProfileType Type { get; set; }
public List<string> GetContainers()
{
List<string> list = new List<string>();
foreach (string i in (Container ?? string.Empty).Split(','))
{
if (!string.IsNullOrEmpty(i)) list.Add(i);
}
return list;
}
public bool SupportsContainer(string container)
{
var all = GetContainers();
// Only allow unknown container if the profile is all inclusive
if (string.IsNullOrWhiteSpace(container))
{
return all.Count == 0;
}
return all.Count == 0 || all.Contains(container, StringComparer.OrdinalIgnoreCase);
return ContainerProfile.ContainsContainer(Container, container);
}
public List<string> GetAudioCodecs()

View File

@ -33,12 +33,7 @@ namespace MediaBrowser.Model.Dlna
public List<string> GetContainers()
{
List<string> list = new List<string>();
foreach (string i in (Container ?? string.Empty).Split(','))
{
if (!string.IsNullOrEmpty(i)) list.Add(i);
}
return list;
return ContainerProfile.SplitValue(Container);
}
public List<string> GetAudioCodecs()

View File

@ -197,6 +197,40 @@ namespace MediaBrowser.Model.Dlna
}
}
public static string NormalizeMediaSourceFormatIntoSingleContainer(string inputContainer, DeviceProfile profile, DlnaProfileType type)
{
if (string.IsNullOrWhiteSpace(inputContainer))
{
return null;
}
var formats = ContainerProfile.SplitValue(inputContainer);
if (formats.Count == 1)
{
return formats[0];
}
if (profile != null)
{
foreach (var format in formats)
{
foreach (var directPlayProfile in profile.DirectPlayProfiles)
{
if (directPlayProfile.Type == type)
{
if (directPlayProfile.SupportsContainer(format))
{
return format;
}
}
}
}
}
return formats[0];
}
private StreamInfo BuildAudioItem(MediaSourceInfo item, AudioOptions options)
{
List<TranscodeReason> transcodeReasons = new List<TranscodeReason>();
@ -214,14 +248,14 @@ namespace MediaBrowser.Model.Dlna
if (options.ForceDirectPlay)
{
playlistItem.PlayMethod = PlayMethod.DirectPlay;
playlistItem.Container = item.Container;
playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Audio);
return playlistItem;
}
if (options.ForceDirectStream)
{
playlistItem.PlayMethod = PlayMethod.DirectStream;
playlistItem.Container = item.Container;
playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Audio);
return playlistItem;
}
@ -295,7 +329,7 @@ namespace MediaBrowser.Model.Dlna
playlistItem.PlayMethod = PlayMethod.DirectStream;
}
playlistItem.Container = item.Container;
playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Audio);
return playlistItem;
}
@ -648,7 +682,7 @@ namespace MediaBrowser.Model.Dlna
if (directPlay != null)
{
playlistItem.PlayMethod = directPlay.Value;
playlistItem.Container = item.Container;
playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Video);
if (subtitleStream != null)
{
@ -1231,22 +1265,28 @@ namespace MediaBrowser.Model.Dlna
private static bool IsSubtitleEmbedSupported(MediaStream subtitleStream, SubtitleProfile subtitleProfile, string transcodingSubProtocol, string transcodingContainer)
{
if (string.Equals(transcodingContainer, "ts", StringComparison.OrdinalIgnoreCase))
if (!string.IsNullOrWhiteSpace(transcodingContainer))
{
var normalizedContainers = ContainerProfile.SplitValue(transcodingContainer);
if (ContainerProfile.ContainsContainer(normalizedContainers, "ts"))
{
return false;
}
if (string.Equals(transcodingContainer, "mpegts", StringComparison.OrdinalIgnoreCase))
if (ContainerProfile.ContainsContainer(normalizedContainers, "mpegts"))
{
return false;
}
if (string.Equals(transcodingContainer, "mp4", StringComparison.OrdinalIgnoreCase))
if (ContainerProfile.ContainsContainer(normalizedContainers, "mp4"))
{
return false;
}
if (string.Equals(transcodingContainer, "mkv", StringComparison.OrdinalIgnoreCase))
if (ContainerProfile.ContainsContainer(normalizedContainers, "mkv") ||
ContainerProfile.ContainsContainer(normalizedContainers, "matroska"))
{
return true;
}
}
return false;
}
@ -1572,6 +1612,8 @@ namespace MediaBrowser.Model.Dlna
}
// Check audio codec
if (audioStream != null)
{
List<string> audioCodecs = profile.GetAudioCodecs();
if (audioCodecs.Count > 0)
{
@ -1582,6 +1624,7 @@ namespace MediaBrowser.Model.Dlna
return false;
}
}
}
return true;
}

View File

@ -106,14 +106,15 @@ namespace MediaBrowser.Model.Net
return dict;
}
public static string GetMimeType(string path)
{
return GetMimeType(path, true);
}
/// <summary>
/// Gets the type of the MIME.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>System.String.</returns>
/// <exception cref="ArgumentNullException">path</exception>
/// <exception cref="InvalidOperationException">Argument not supported: + path</exception>
public static string GetMimeType(string path)
public static string GetMimeType(string path, bool enableStreamDefault)
{
if (string.IsNullOrEmpty(path))
{
@ -329,9 +330,14 @@ namespace MediaBrowser.Model.Net
return "application/ttml+xml";
}
if (enableStreamDefault)
{
return "application/octet-stream";
}
return null;
}
public static string ToExtension(string mimeType)
{
if (string.IsNullOrEmpty(mimeType))

View File

@ -95,14 +95,14 @@ namespace MediaBrowser.Providers.MediaInfo
{
var mediaStreams = mediaInfo.MediaStreams;
//audio.FormatName = mediaInfo.Container;
audio.Container = mediaInfo.Container;
audio.TotalBitrate = mediaInfo.Bitrate;
audio.RunTimeTicks = mediaInfo.RunTimeTicks;
audio.Size = mediaInfo.Size;
var extension = (Path.GetExtension(audio.Path) ?? string.Empty).TrimStart('.');
audio.Container = extension;
//audio.Container = extension;
await FetchDataFromTags(audio, mediaInfo).ConfigureAwait(false);

View File

@ -187,6 +187,7 @@ namespace MediaBrowser.Providers.MediaInfo
{
video.Container = null;
}
video.Container = mediaInfo.Container;
var chapters = mediaInfo.Chapters ?? new List<ChapterInfo>();
if (blurayInfo != null)

View File

@ -1,3 +1,3 @@
using System.Reflection;
[assembly: AssemblyVersion("3.2.26.13")]
[assembly: AssemblyVersion("3.2.26.14")]