Skip to content

Commit 6dab7ee

Browse files
check video profile with substring
1 parent af6d7da commit 6dab7ee

File tree

6 files changed

+72
-29
lines changed

6 files changed

+72
-29
lines changed

MediaBrowser.Dlna/DlnaManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private void DumpProfiles()
7979
new Windows81Profile(),
8080
//new WindowsMediaCenterProfile(),
8181
new WindowsPhoneProfile(),
82-
new AndroidProfile(),
82+
new AndroidProfile(true, true),
8383
new DirectTvProfile(),
8484
new DishHopperJoeyProfile(),
8585
new DefaultProfile()

MediaBrowser.Dlna/Ssdp/Datagram.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class Datagram
1616
/// The number of times to send the message
1717
/// </summary>
1818
public int TotalSendCount { get; private set; }
19+
public bool IgnoreBindFailure { get; private set; }
1920

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

2526
private readonly ILogger _logger;
2627

27-
public Datagram(EndPoint toEndPoint, EndPoint fromEndPoint, ILogger logger, string message, int totalSendCount)
28+
public Datagram(EndPoint toEndPoint, EndPoint fromEndPoint, ILogger logger, string message, int totalSendCount, bool ignoreBindFailure)
2829
{
2930
Message = message;
3031
_logger = logger;
32+
IgnoreBindFailure = ignoreBindFailure;
3133
TotalSendCount = totalSendCount;
3234
FromEndPoint = fromEndPoint;
3335
ToEndPoint = toEndPoint;
@@ -42,7 +44,14 @@ public void Send()
4244

4345
if (FromEndPoint != null)
4446
{
45-
client.Bind(FromEndPoint);
47+
try
48+
{
49+
client.Bind(FromEndPoint);
50+
}
51+
catch
52+
{
53+
if (!IgnoreBindFailure) throw;
54+
}
4655
}
4756

4857
client.BeginSendTo(msg, 0, msg.Length, SocketFlags.None, ToEndPoint, result =>
@@ -53,7 +62,10 @@ public void Send()
5362
}
5463
catch (Exception ex)
5564
{
56-
_logger.ErrorException("Error sending Datagram to {0} from {1}: " + Message, ex, ToEndPoint, FromEndPoint == null ? "" : FromEndPoint.ToString());
65+
if (!IgnoreBindFailure)
66+
{
67+
_logger.ErrorException("Error sending Datagram to {0} from {1}: " + Message, ex, ToEndPoint, FromEndPoint == null ? "" : FromEndPoint.ToString());
68+
}
5769
}
5870
finally
5971
{

MediaBrowser.Dlna/Ssdp/SsdpHandler.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,19 @@ public void SendDatagram(string header,
124124
EndPoint localAddress,
125125
int sendCount = 1)
126126
{
127-
SendDatagram(header, values, _ssdpEndp, localAddress, sendCount);
127+
SendDatagram(header, values, _ssdpEndp, localAddress, false, sendCount);
128128
}
129129

130130
public void SendDatagram(string header,
131131
Dictionary<string, string> values,
132132
EndPoint endpoint,
133133
EndPoint localAddress,
134+
bool ignoreBindFailure,
134135
int sendCount = 1)
135136
{
136137
var msg = new SsdpMessageBuilder().BuildMessage(header, values);
137138

138-
var dgram = new Datagram(endpoint, localAddress, _logger, msg, sendCount);
139+
var dgram = new Datagram(endpoint, localAddress, _logger, msg, sendCount, ignoreBindFailure);
139140

140141
if (_messageQueue.Count == 0)
141142
{
@@ -171,7 +172,8 @@ private void RespondToSearch(EndPoint endpoint, string deviceType)
171172
values["ST"] = d.Type;
172173
values["USN"] = d.USN;
173174

174-
SendDatagram(header, values, endpoint, new IPEndPoint(d.Address, 0));
175+
SendDatagram(header, values, endpoint, new IPEndPoint(d.Address, 0), true);
176+
//SendDatagram(header, values, endpoint, null, true);
175177

176178
if (_config.GetDlnaConfiguration().EnableDebugLogging)
177179
{

MediaBrowser.Model/Dlna/ConditionProcessor.cs

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ private bool IsConditionSatisfied(ProfileCondition condition, string currentValu
145145

146146
switch (condition.Condition)
147147
{
148+
case ProfileConditionType.SubstringOf:
149+
return StringHelper.IndexOfIgnoreCase(currentValue, expected) != -1;
148150
case ProfileConditionType.Equals:
149151
return StringHelper.EqualsIgnoreCase(currentValue, expected);
150152
case ProfileConditionType.NotEquals:

MediaBrowser.Model/Dlna/ProfileConditionType.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public enum ProfileConditionType
55
Equals = 0,
66
NotEquals = 1,
77
LessThanEqual = 2,
8-
GreaterThanEqual = 3
8+
GreaterThanEqual = 3,
9+
SubstringOf = 4
910
}
1011
}

MediaBrowser.Model/Dlna/Profiles/AndroidProfile.cs

+47-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1-
using System.Xml.Serialization;
1+
using System.Collections.Generic;
2+
using System.Xml.Serialization;
23

34
namespace MediaBrowser.Model.Dlna.Profiles
45
{
56
[XmlRoot("Profile")]
67
public class AndroidProfile : DefaultProfile
78
{
8-
public AndroidProfile()
9+
public AndroidProfile(bool supportsHls, bool supportsMpegDash)
910
{
1011
Name = "Android";
1112

12-
TranscodingProfiles = new[]
13+
List<TranscodingProfile> transcodingProfiles = new List<TranscodingProfile>();
14+
15+
transcodingProfiles.Add(new TranscodingProfile
1316
{
14-
new TranscodingProfile
15-
{
16-
Container = "mp3",
17-
AudioCodec = "mp3",
18-
Type = DlnaProfileType.Audio
19-
},
20-
new TranscodingProfile
17+
Container = "mp3",
18+
AudioCodec = "mp3",
19+
Type = DlnaProfileType.Audio
20+
});
21+
22+
if (supportsMpegDash)
23+
{
24+
25+
}
26+
if (supportsHls)
27+
{
28+
transcodingProfiles.Add(new TranscodingProfile
2129
{
2230
Protocol = "hls",
2331
Container = "ts",
@@ -26,17 +34,19 @@ public AndroidProfile()
2634
Type = DlnaProfileType.Video,
2735
VideoProfile = "Baseline",
2836
Context = EncodingContext.Streaming
29-
},
30-
new TranscodingProfile
31-
{
32-
Container = "mp4",
33-
VideoCodec = "h264",
34-
AudioCodec = "aac",
35-
Type = DlnaProfileType.Video,
36-
VideoProfile = "Baseline",
37-
Context = EncodingContext.Static
38-
}
39-
};
37+
});
38+
}
39+
transcodingProfiles.Add(new TranscodingProfile
40+
{
41+
Container = "mp4",
42+
VideoCodec = "h264",
43+
AudioCodec = "aac",
44+
Type = DlnaProfileType.Video,
45+
VideoProfile = "Baseline",
46+
Context = EncodingContext.Static
47+
});
48+
49+
TranscodingProfiles = transcodingProfiles.ToArray();
4050

4151
DirectPlayProfiles = new[]
4252
{
@@ -88,6 +98,22 @@ public AndroidProfile()
8898
new CodecProfile
8999
{
90100
Type = CodecType.Video,
101+
Codec= "h264",
102+
103+
Conditions = new []
104+
{
105+
new ProfileCondition(ProfileConditionType.SubstringOf, ProfileConditionValue.VideoProfile, "baseline"),
106+
new ProfileCondition(ProfileConditionType.LessThanEqual, ProfileConditionValue.Width, "1920"),
107+
new ProfileCondition(ProfileConditionType.LessThanEqual, ProfileConditionValue.Height, "1080"),
108+
new ProfileCondition(ProfileConditionType.LessThanEqual, ProfileConditionValue.VideoBitDepth, "8"),
109+
new ProfileCondition(ProfileConditionType.NotEquals, ProfileConditionValue.IsAnamorphic, "true")
110+
}
111+
},
112+
113+
new CodecProfile
114+
{
115+
Type = CodecType.Video,
116+
91117
Conditions = new []
92118
{
93119
new ProfileCondition(ProfileConditionType.LessThanEqual, ProfileConditionValue.Width, "1920"),

0 commit comments

Comments
 (0)