Skip to content

Commit

Permalink
check video profile with substring
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Oct 8, 2014
1 parent af6d7da commit 6dab7ee
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 29 deletions.
2 changes: 1 addition & 1 deletion MediaBrowser.Dlna/DlnaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void DumpProfiles()
new Windows81Profile(),
//new WindowsMediaCenterProfile(),
new WindowsPhoneProfile(),
new AndroidProfile(),
new AndroidProfile(true, true),
new DirectTvProfile(),
new DishHopperJoeyProfile(),
new DefaultProfile()
Expand Down
18 changes: 15 additions & 3 deletions MediaBrowser.Dlna/Ssdp/Datagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Datagram
/// The number of times to send the message
/// </summary>
public int TotalSendCount { get; private set; }
public bool IgnoreBindFailure { get; private set; }

/// <summary>
/// The number of times the message has been sent
Expand All @@ -24,10 +25,11 @@ public class Datagram

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;
Expand All @@ -42,7 +44,14 @@ public void Send()

if (FromEndPoint != null)
{
client.Bind(FromEndPoint);
try
{
client.Bind(FromEndPoint);
}
catch
{
if (!IgnoreBindFailure) throw;
}
}

client.BeginSendTo(msg, 0, msg.Length, SocketFlags.None, ToEndPoint, result =>
Expand All @@ -53,7 +62,10 @@ public void Send()
}
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
{
Expand Down
8 changes: 5 additions & 3 deletions MediaBrowser.Dlna/Ssdp/SsdpHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,19 @@ public void SendDatagram(string header,
EndPoint localAddress,
int sendCount = 1)
{
SendDatagram(header, values, _ssdpEndp, localAddress, sendCount);
SendDatagram(header, values, _ssdpEndp, localAddress, false, sendCount);
}

public void SendDatagram(string header,
Dictionary<string, string> 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)
{
Expand Down Expand Up @@ -171,7 +172,8 @@ private void RespondToSearch(EndPoint endpoint, string deviceType)
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)
{
Expand Down
2 changes: 2 additions & 0 deletions MediaBrowser.Model/Dlna/ConditionProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ private bool IsConditionSatisfied(ProfileCondition condition, string currentValu

switch (condition.Condition)
{
case ProfileConditionType.SubstringOf:
return StringHelper.IndexOfIgnoreCase(currentValue, expected) != -1;
case ProfileConditionType.Equals:
return StringHelper.EqualsIgnoreCase(currentValue, expected);
case ProfileConditionType.NotEquals:
Expand Down
3 changes: 2 additions & 1 deletion MediaBrowser.Model/Dlna/ProfileConditionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum ProfileConditionType
Equals = 0,
NotEquals = 1,
LessThanEqual = 2,
GreaterThanEqual = 3
GreaterThanEqual = 3,
SubstringOf = 4
}
}
68 changes: 47 additions & 21 deletions MediaBrowser.Model/Dlna/Profiles/AndroidProfile.cs
Original file line number Diff line number Diff line change
@@ -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<TranscodingProfile> transcodingProfiles = new List<TranscodingProfile>();

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",
Expand All @@ -26,17 +34,19 @@ public AndroidProfile()
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[]
{
Expand Down Expand Up @@ -88,6 +98,22 @@ public AndroidProfile()
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"),
Expand Down

0 comments on commit 6dab7ee

Please sign in to comment.