From bebba65d6137125d459a911b695131c063524c56 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 7 Oct 2014 22:25:24 -0400 Subject: [PATCH] check video profile with substring --- MediaBrowser.Dlna/DlnaManager.cs | 2 +- MediaBrowser.Dlna/Ssdp/Datagram.cs | 18 ++++- MediaBrowser.Dlna/Ssdp/SsdpHandler.cs | 8 ++- MediaBrowser.Model/Dlna/ConditionProcessor.cs | 2 + .../Dlna/ProfileConditionType.cs | 3 +- .../Dlna/Profiles/AndroidProfile.cs | 68 +++++++++++++------ 6 files changed, 72 insertions(+), 29 deletions(-) diff --git a/MediaBrowser.Dlna/DlnaManager.cs b/MediaBrowser.Dlna/DlnaManager.cs index dc43b90b20..cd14571693 100644 --- a/MediaBrowser.Dlna/DlnaManager.cs +++ b/MediaBrowser.Dlna/DlnaManager.cs @@ -79,7 +79,7 @@ namespace MediaBrowser.Dlna new Windows81Profile(), //new WindowsMediaCenterProfile(), new WindowsPhoneProfile(), - new AndroidProfile(), + new AndroidProfile(true, true), new DirectTvProfile(), new DishHopperJoeyProfile(), new DefaultProfile() diff --git a/MediaBrowser.Dlna/Ssdp/Datagram.cs b/MediaBrowser.Dlna/Ssdp/Datagram.cs index 0432c35c16..f16464209b 100644 --- a/MediaBrowser.Dlna/Ssdp/Datagram.cs +++ b/MediaBrowser.Dlna/Ssdp/Datagram.cs @@ -16,6 +16,7 @@ namespace MediaBrowser.Dlna.Ssdp /// The number of times to send the message /// public int TotalSendCount { get; private set; } + public bool IgnoreBindFailure { get; private set; } /// /// The number of times the message has been sent @@ -24,10 +25,11 @@ namespace MediaBrowser.Dlna.Ssdp private readonly ILogger _logger; - public Datagram(EndPoint toEndPoint, EndPoint fromEndPoint, ILogger logger, string message, int totalSendCount) + public Datagram(EndPoint toEndPoint, EndPoint fromEndPoint, ILogger logger, string message, int totalSendCount, bool ignoreBindFailure) { Message = message; _logger = logger; + IgnoreBindFailure = ignoreBindFailure; TotalSendCount = totalSendCount; FromEndPoint = fromEndPoint; ToEndPoint = toEndPoint; @@ -42,7 +44,14 @@ namespace MediaBrowser.Dlna.Ssdp if (FromEndPoint != null) { - client.Bind(FromEndPoint); + try + { + client.Bind(FromEndPoint); + } + catch + { + if (!IgnoreBindFailure) throw; + } } client.BeginSendTo(msg, 0, msg.Length, SocketFlags.None, ToEndPoint, result => @@ -53,7 +62,10 @@ namespace MediaBrowser.Dlna.Ssdp } catch (Exception ex) { - _logger.ErrorException("Error sending Datagram to {0} from {1}: " + Message, ex, ToEndPoint, FromEndPoint == null ? "" : FromEndPoint.ToString()); + if (!IgnoreBindFailure) + { + _logger.ErrorException("Error sending Datagram to {0} from {1}: " + Message, ex, ToEndPoint, FromEndPoint == null ? "" : FromEndPoint.ToString()); + } } finally { diff --git a/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs b/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs index 35572f9907..15735746b4 100644 --- a/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs +++ b/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs @@ -124,18 +124,19 @@ namespace MediaBrowser.Dlna.Ssdp EndPoint localAddress, int sendCount = 1) { - SendDatagram(header, values, _ssdpEndp, localAddress, sendCount); + SendDatagram(header, values, _ssdpEndp, localAddress, false, sendCount); } public void SendDatagram(string header, Dictionary values, EndPoint endpoint, EndPoint localAddress, + bool ignoreBindFailure, int sendCount = 1) { var msg = new SsdpMessageBuilder().BuildMessage(header, values); - var dgram = new Datagram(endpoint, localAddress, _logger, msg, sendCount); + var dgram = new Datagram(endpoint, localAddress, _logger, msg, sendCount, ignoreBindFailure); if (_messageQueue.Count == 0) { @@ -171,7 +172,8 @@ namespace MediaBrowser.Dlna.Ssdp values["ST"] = d.Type; values["USN"] = d.USN; - SendDatagram(header, values, endpoint, new IPEndPoint(d.Address, 0)); + SendDatagram(header, values, endpoint, new IPEndPoint(d.Address, 0), true); + //SendDatagram(header, values, endpoint, null, true); if (_config.GetDlnaConfiguration().EnableDebugLogging) { diff --git a/MediaBrowser.Model/Dlna/ConditionProcessor.cs b/MediaBrowser.Model/Dlna/ConditionProcessor.cs index db004a65e8..dd9a49ec40 100644 --- a/MediaBrowser.Model/Dlna/ConditionProcessor.cs +++ b/MediaBrowser.Model/Dlna/ConditionProcessor.cs @@ -145,6 +145,8 @@ namespace MediaBrowser.Model.Dlna switch (condition.Condition) { + case ProfileConditionType.SubstringOf: + return StringHelper.IndexOfIgnoreCase(currentValue, expected) != -1; case ProfileConditionType.Equals: return StringHelper.EqualsIgnoreCase(currentValue, expected); case ProfileConditionType.NotEquals: diff --git a/MediaBrowser.Model/Dlna/ProfileConditionType.cs b/MediaBrowser.Model/Dlna/ProfileConditionType.cs index 22156c47d7..bfbd31f02b 100644 --- a/MediaBrowser.Model/Dlna/ProfileConditionType.cs +++ b/MediaBrowser.Model/Dlna/ProfileConditionType.cs @@ -5,6 +5,7 @@ Equals = 0, NotEquals = 1, LessThanEqual = 2, - GreaterThanEqual = 3 + GreaterThanEqual = 3, + SubstringOf = 4 } } \ No newline at end of file diff --git a/MediaBrowser.Model/Dlna/Profiles/AndroidProfile.cs b/MediaBrowser.Model/Dlna/Profiles/AndroidProfile.cs index 09c26cb1f8..1f0b9a2620 100644 --- a/MediaBrowser.Model/Dlna/Profiles/AndroidProfile.cs +++ b/MediaBrowser.Model/Dlna/Profiles/AndroidProfile.cs @@ -1,23 +1,31 @@ -using System.Xml.Serialization; +using System.Collections.Generic; +using System.Xml.Serialization; namespace MediaBrowser.Model.Dlna.Profiles { [XmlRoot("Profile")] public class AndroidProfile : DefaultProfile { - public AndroidProfile() + public AndroidProfile(bool supportsHls, bool supportsMpegDash) { Name = "Android"; - TranscodingProfiles = new[] + List transcodingProfiles = new List(); + + transcodingProfiles.Add(new TranscodingProfile { - new TranscodingProfile - { - Container = "mp3", - AudioCodec = "mp3", - Type = DlnaProfileType.Audio - }, - new TranscodingProfile + Container = "mp3", + AudioCodec = "mp3", + Type = DlnaProfileType.Audio + }); + + if (supportsMpegDash) + { + + } + if (supportsHls) + { + transcodingProfiles.Add(new TranscodingProfile { Protocol = "hls", Container = "ts", @@ -26,17 +34,19 @@ namespace MediaBrowser.Model.Dlna.Profiles Type = DlnaProfileType.Video, VideoProfile = "Baseline", Context = EncodingContext.Streaming - }, - new TranscodingProfile - { - Container = "mp4", - VideoCodec = "h264", - AudioCodec = "aac", - Type = DlnaProfileType.Video, - VideoProfile = "Baseline", - Context = EncodingContext.Static - } - }; + }); + } + transcodingProfiles.Add(new TranscodingProfile + { + Container = "mp4", + VideoCodec = "h264", + AudioCodec = "aac", + Type = DlnaProfileType.Video, + VideoProfile = "Baseline", + Context = EncodingContext.Static + }); + + TranscodingProfiles = transcodingProfiles.ToArray(); DirectPlayProfiles = new[] { @@ -88,6 +98,22 @@ namespace MediaBrowser.Model.Dlna.Profiles new CodecProfile { Type = CodecType.Video, + Codec= "h264", + + Conditions = new [] + { + new ProfileCondition(ProfileConditionType.SubstringOf, ProfileConditionValue.VideoProfile, "baseline"), + new ProfileCondition(ProfileConditionType.LessThanEqual, ProfileConditionValue.Width, "1920"), + new ProfileCondition(ProfileConditionType.LessThanEqual, ProfileConditionValue.Height, "1080"), + new ProfileCondition(ProfileConditionType.LessThanEqual, ProfileConditionValue.VideoBitDepth, "8"), + new ProfileCondition(ProfileConditionType.NotEquals, ProfileConditionValue.IsAnamorphic, "true") + } + }, + + new CodecProfile + { + Type = CodecType.Video, + Conditions = new [] { new ProfileCondition(ProfileConditionType.LessThanEqual, ProfileConditionValue.Width, "1920"),