detect anamorphic video

This commit is contained in:
Luke Pulverenti
2014-06-22 12:25:47 -04:00
parent 414b1251c7
commit 3b30a2aee0
23 changed files with 182 additions and 37 deletions

View File

@@ -17,7 +17,8 @@ namespace MediaBrowser.Model.Dlna
double? videoLevel,
double? videoFramerate,
int? packetLength,
TransportStreamTimestamp? timestamp)
TransportStreamTimestamp? timestamp,
bool? isAnamorphic)
{
switch (condition.Property)
{
@@ -27,6 +28,8 @@ namespace MediaBrowser.Model.Dlna
case ProfileConditionValue.Has64BitOffsets:
// TODO: Implement
return true;
case ProfileConditionValue.IsAnamorphic:
return IsConditionSatisfied(condition, isAnamorphic);
case ProfileConditionValue.VideoFramerate:
return IsConditionSatisfied(condition, videoFramerate);
case ProfileConditionValue.VideoLevel:
@@ -147,6 +150,31 @@ namespace MediaBrowser.Model.Dlna
throw new InvalidOperationException("Unexpected ProfileConditionType");
}
}
private bool IsConditionSatisfied(ProfileCondition condition, bool? currentValue)
{
if (!currentValue.HasValue)
{
// If the value is unknown, it satisfies if not marked as required
return !condition.IsRequired;
}
bool expected;
if (BoolHelper.TryParseCultureInvariant(condition.Value, out expected))
{
switch (condition.Condition)
{
case ProfileConditionType.Equals:
return currentValue.Value == expected;
case ProfileConditionType.NotEquals:
return currentValue.Value != expected;
default:
throw new InvalidOperationException("Unexpected ProfileConditionType");
}
}
return false;
}
private bool IsConditionSatisfied(ProfileCondition condition, double? currentValue)
{

View File

@@ -108,7 +108,8 @@ namespace MediaBrowser.Model.Dlna
double? videoLevel,
double? videoFramerate,
int? packetLength,
TranscodeSeekInfo transcodeSeekInfo)
TranscodeSeekInfo transcodeSeekInfo,
bool? isAnamorphic)
{
// first bit means Time based seek supported, second byte range seek supported (not sure about the order now), so 01 = only byte seek, 10 = time based, 11 = both, 00 = none
string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo);
@@ -145,7 +146,8 @@ namespace MediaBrowser.Model.Dlna
videoLevel,
videoFramerate,
packetLength,
timestamp);
timestamp,
isAnamorphic);
string orgPn = mediaProfile == null ? null : mediaProfile.OrgPn;

View File

@@ -269,7 +269,8 @@ namespace MediaBrowser.Model.Dlna
double? videoLevel,
double? videoFramerate,
int? packetLength,
TransportStreamTimestamp timestamp)
TransportStreamTimestamp timestamp,
bool? isAnamorphic)
{
container = (container ?? string.Empty).TrimStart('.');
@@ -303,7 +304,7 @@ namespace MediaBrowser.Model.Dlna
var anyOff = false;
foreach (ProfileCondition c in i.Conditions)
{
if (!conditionProcessor.IsVideoConditionSatisfied(c, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp))
if (!conditionProcessor.IsVideoConditionSatisfied(c, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic))
{
anyOff = true;
break;

View File

@@ -2,18 +2,19 @@
{
public enum ProfileConditionValue
{
AudioChannels,
AudioBitrate,
AudioProfile,
Width,
Height,
Has64BitOffsets,
PacketLength,
VideoBitDepth,
VideoBitrate,
VideoFramerate,
VideoLevel,
VideoProfile,
VideoTimestamp
AudioChannels = 0,
AudioBitrate = 1,
AudioProfile = 2,
Width = 3,
Height = 4,
Has64BitOffsets = 5,
PacketLength = 6,
VideoBitDepth = 7,
VideoBitrate = 8,
VideoFramerate = 9,
VideoLevel = 10,
VideoProfile = 11,
VideoTimestamp = 12,
IsAnamorphic = 13
}
}

View File

@@ -370,6 +370,7 @@ namespace MediaBrowser.Model.Dlna
double? videoLevel = videoStream == null ? null : videoStream.Level;
string videoProfile = videoStream == null ? null : videoStream.Profile;
float? videoFramerate = videoStream == null ? null : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate;
bool? isAnamorphic = videoStream == null ? null : videoStream.IsAnamorphic;
int? audioBitrate = audioStream == null ? null : audioStream.BitRate;
int? audioChannels = audioStream == null ? null : audioStream.Channels;
@@ -381,7 +382,7 @@ namespace MediaBrowser.Model.Dlna
// Check container conditions
foreach (ProfileCondition i in conditions)
{
if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp))
if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic))
{
return null;
}
@@ -403,7 +404,7 @@ namespace MediaBrowser.Model.Dlna
foreach (ProfileCondition i in conditions)
{
if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp))
if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic))
{
return null;
}
@@ -520,6 +521,7 @@ namespace MediaBrowser.Model.Dlna
break;
}
case ProfileConditionValue.AudioProfile:
case ProfileConditionValue.IsAnamorphic:
case ProfileConditionValue.Has64BitOffsets:
case ProfileConditionValue.PacketLength:
case ProfileConditionValue.VideoTimestamp:

View File

@@ -348,6 +348,19 @@ namespace MediaBrowser.Model.Dlna
}
}
public bool? IsTargetAnamorphic
{
get
{
if (IsDirectStream)
{
return TargetVideoStream == null ? null : TargetVideoStream.IsAnamorphic;
}
return false;
}
}
public int? TargetWidth
{
get

View File

@@ -33,7 +33,7 @@ namespace MediaBrowser.Model.Entities
/// </summary>
/// <value>The channel layout.</value>
public string ChannelLayout { get; set; }
/// <summary>
/// Gets or sets the bit rate.
/// </summary>
@@ -155,11 +155,17 @@ namespace MediaBrowser.Model.Entities
/// </summary>
/// <value>The pixel format.</value>
public string PixelFormat { get; set; }
/// <summary>
/// Gets or sets the level.
/// </summary>
/// <value>The level.</value>
public double? Level { get; set; }
/// <summary>
/// Gets a value indicating whether this instance is anamorphic.
/// </summary>
/// <value><c>true</c> if this instance is anamorphic; otherwise, <c>false</c>.</value>
public bool? IsAnamorphic { get; set; }
}
}

View File

@@ -18,4 +18,18 @@ namespace MediaBrowser.Model.Extensions
return double.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
}
}
public static class BoolHelper
{
/// <summary>
/// Tries the parse culture invariant.
/// </summary>
/// <param name="s">The s.</param>
/// <param name="result">The result.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
public static bool TryParseCultureInvariant(string s, out bool result)
{
return bool.TryParse(s, out result);
}
}
}