aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2023-06-28 17:30:26 +0200
committerGitHub <noreply@github.com>2023-06-28 17:30:26 +0200
commit4ac07f6c76bf8eed3b99994410dd1481764ab9fc (patch)
treef2df90cc978d26adfc280bffafcef25d9bb741b5 /MediaBrowser.Model
parentf954dc5c969ef5654c31bec7a81b0b92b38637ae (diff)
parent20a4509991e7ba81414312f8a860917fd29b6702 (diff)
Merge pull request #9890 from Shadowghost/videorange-rework
Diffstat (limited to 'MediaBrowser.Model')
-rw-r--r--MediaBrowser.Model/Dlna/ConditionProcessor.cs93
-rw-r--r--MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs3
-rw-r--r--MediaBrowser.Model/Dlna/DeviceProfile.cs3
-rw-r--r--MediaBrowser.Model/Dlna/StreamBuilder.cs9
-rw-r--r--MediaBrowser.Model/Dlna/StreamInfo.cs12
-rw-r--r--MediaBrowser.Model/Entities/MediaStream.cs21
6 files changed, 119 insertions, 22 deletions
diff --git a/MediaBrowser.Model/Dlna/ConditionProcessor.cs b/MediaBrowser.Model/Dlna/ConditionProcessor.cs
index f5e1a3c49..af0787990 100644
--- a/MediaBrowser.Model/Dlna/ConditionProcessor.cs
+++ b/MediaBrowser.Model/Dlna/ConditionProcessor.cs
@@ -1,14 +1,38 @@
-#pragma warning disable CS1591
-
using System;
using System.Globalization;
+using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Model.MediaInfo;
namespace MediaBrowser.Model.Dlna
{
+ /// <summary>
+ /// The condition processor.
+ /// </summary>
public static class ConditionProcessor
{
+ /// <summary>
+ /// Checks if a video condition is satisfied.
+ /// </summary>
+ /// <param name="condition">The <see cref="ProfileCondition"/>.</param>
+ /// <param name="width">The width.</param>
+ /// <param name="height">The height.</param>
+ /// <param name="videoBitDepth">The bit depth.</param>
+ /// <param name="videoBitrate">The bitrate.</param>
+ /// <param name="videoProfile">The video profile.</param>
+ /// <param name="videoRangeType">The <see cref="VideoRangeType"/>.</param>
+ /// <param name="videoLevel">The video level.</param>
+ /// <param name="videoFramerate">The framerate.</param>
+ /// <param name="packetLength">The packet length.</param>
+ /// <param name="timestamp">The <see cref="TransportStreamTimestamp"/>.</param>
+ /// <param name="isAnamorphic">A value indicating whether tthe video is anamorphic.</param>
+ /// <param name="isInterlaced">A value indicating whether tthe video is interlaced.</param>
+ /// <param name="refFrames">The reference frames.</param>
+ /// <param name="numVideoStreams">The number of video streams.</param>
+ /// <param name="numAudioStreams">The number of audio streams.</param>
+ /// <param name="videoCodecTag">The video codec tag.</param>
+ /// <param name="isAvc">A value indicating whether the video is AVC.</param>
+ /// <returns><b>True</b> if the condition is satisfied.</returns>
public static bool IsVideoConditionSatisfied(
ProfileCondition condition,
int? width,
@@ -16,7 +40,7 @@ namespace MediaBrowser.Model.Dlna
int? videoBitDepth,
int? videoBitrate,
string? videoProfile,
- string? videoRangeType,
+ VideoRangeType? videoRangeType,
double? videoLevel,
float? videoFramerate,
int? packetLength,
@@ -70,6 +94,13 @@ namespace MediaBrowser.Model.Dlna
}
}
+ /// <summary>
+ /// Checks if a image condition is satisfied.
+ /// </summary>
+ /// <param name="condition">The <see cref="ProfileCondition"/>.</param>
+ /// <param name="width">The width.</param>
+ /// <param name="height">The height.</param>
+ /// <returns><b>True</b> if the condition is satisfied.</returns>
public static bool IsImageConditionSatisfied(ProfileCondition condition, int? width, int? height)
{
switch (condition.Property)
@@ -83,6 +114,15 @@ namespace MediaBrowser.Model.Dlna
}
}
+ /// <summary>
+ /// Checks if an audio condition is satisfied.
+ /// </summary>
+ /// <param name="condition">The <see cref="ProfileCondition"/>.</param>
+ /// <param name="audioChannels">The channel count.</param>
+ /// <param name="audioBitrate">The bitrate.</param>
+ /// <param name="audioSampleRate">The sample rate.</param>
+ /// <param name="audioBitDepth">The bit depth.</param>
+ /// <returns><b>True</b> if the condition is satisfied.</returns>
public static bool IsAudioConditionSatisfied(ProfileCondition condition, int? audioChannels, int? audioBitrate, int? audioSampleRate, int? audioBitDepth)
{
switch (condition.Property)
@@ -100,6 +140,17 @@ namespace MediaBrowser.Model.Dlna
}
}
+ /// <summary>
+ /// Checks if an audio condition is satisfied for a video.
+ /// </summary>
+ /// <param name="condition">The <see cref="ProfileCondition"/>.</param>
+ /// <param name="audioChannels">The channel count.</param>
+ /// <param name="audioBitrate">The bitrate.</param>
+ /// <param name="audioSampleRate">The sample rate.</param>
+ /// <param name="audioBitDepth">The bit depth.</param>
+ /// <param name="audioProfile">The profile.</param>
+ /// <param name="isSecondaryTrack">A value indicating whether the audio is a secondary track.</param>
+ /// <returns><b>True</b> if the condition is satisfied.</returns>
public static bool IsVideoAudioConditionSatisfied(
ProfileCondition condition,
int? audioChannels,
@@ -281,5 +332,41 @@ namespace MediaBrowser.Model.Dlna
throw new InvalidOperationException("Unexpected ProfileConditionType: " + condition.Condition);
}
}
+
+ private static bool IsConditionSatisfied(ProfileCondition condition, VideoRangeType? currentValue)
+ {
+ if (!currentValue.HasValue || currentValue.Equals(VideoRangeType.Unknown))
+ {
+ // If the value is unknown, it satisfies if not marked as required
+ return !condition.IsRequired;
+ }
+
+ var conditionType = condition.Condition;
+ if (conditionType == ProfileConditionType.EqualsAny)
+ {
+ foreach (var singleConditionString in condition.Value.AsSpan().Split('|'))
+ {
+ if (Enum.TryParse(singleConditionString, true, out VideoRangeType conditionValue)
+ && conditionValue.Equals(currentValue))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ if (Enum.TryParse(condition.Value, true, out VideoRangeType expected))
+ {
+ return conditionType switch
+ {
+ ProfileConditionType.Equals => currentValue.Value == expected,
+ ProfileConditionType.NotEquals => currentValue.Value != expected,
+ _ => throw new InvalidOperationException("Unexpected ProfileConditionType: " + condition.Condition)
+ };
+ }
+
+ return false;
+ }
}
}
diff --git a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs
index 1d5d0b1de..f29022b54 100644
--- a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs
+++ b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
+using Jellyfin.Data.Enums;
using MediaBrowser.Model.MediaInfo;
namespace MediaBrowser.Model.Dlna
@@ -128,7 +129,7 @@ namespace MediaBrowser.Model.Dlna
bool isDirectStream,
long? runtimeTicks,
string videoProfile,
- string videoRangeType,
+ VideoRangeType videoRangeType,
double? videoLevel,
float? videoFramerate,
int? packetLength,
diff --git a/MediaBrowser.Model/Dlna/DeviceProfile.cs b/MediaBrowser.Model/Dlna/DeviceProfile.cs
index 79ae95170..b7c23669d 100644
--- a/MediaBrowser.Model/Dlna/DeviceProfile.cs
+++ b/MediaBrowser.Model/Dlna/DeviceProfile.cs
@@ -2,6 +2,7 @@
using System;
using System.ComponentModel;
using System.Xml.Serialization;
+using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Model.MediaInfo;
@@ -445,7 +446,7 @@ namespace MediaBrowser.Model.Dlna
int? bitDepth,
int? videoBitrate,
string videoProfile,
- string videoRangeType,
+ VideoRangeType videoRangeType,
double? videoLevel,
float? videoFramerate,
int? packetLength,
diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs
index 0a955e917..2dbd14da4 100644
--- a/MediaBrowser.Model/Dlna/StreamBuilder.cs
+++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
+using Jellyfin.Data.Enums;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
@@ -889,7 +890,7 @@ namespace MediaBrowser.Model.Dlna
int? videoBitrate = videoStream?.BitRate;
double? videoLevel = videoStream?.Level;
string? videoProfile = videoStream?.Profile;
- string? videoRangeType = videoStream?.VideoRangeType;
+ VideoRangeType? videoRangeType = videoStream?.VideoRangeType;
float videoFramerate = videoStream is null ? 0 : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate ?? 0;
bool? isAnamorphic = videoStream?.IsAnamorphic;
bool? isInterlaced = videoStream?.IsInterlaced;
@@ -1144,7 +1145,7 @@ namespace MediaBrowser.Model.Dlna
int? videoBitrate = videoStream?.BitRate;
double? videoLevel = videoStream?.Level;
string? videoProfile = videoStream?.Profile;
- string? videoRangeType = videoStream?.VideoRangeType;
+ VideoRangeType? videoRangeType = videoStream?.VideoRangeType;
float videoFramerate = videoStream is null ? 0 : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate ?? 0;
bool? isAnamorphic = videoStream?.IsAnamorphic;
bool? isInterlaced = videoStream?.IsInterlaced;
@@ -1932,6 +1933,10 @@ namespace MediaBrowser.Model.Dlna
{
item.SetOption(qualifier, "rangetype", string.Join(',', values));
}
+ else if (condition.Condition == ProfileConditionType.NotEquals)
+ {
+ item.SetOption(qualifier, "rangetype", string.Join(',', Enum.GetNames(typeof(VideoRangeType)).Except(values)));
+ }
else if (condition.Condition == ProfileConditionType.EqualsAny)
{
var currentValue = item.GetOption(qualifier, "rangetype");
diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs
index a78a28e13..00543616d 100644
--- a/MediaBrowser.Model/Dlna/StreamInfo.cs
+++ b/MediaBrowser.Model/Dlna/StreamInfo.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
+using Jellyfin.Data.Enums;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
@@ -281,23 +282,24 @@ namespace MediaBrowser.Model.Dlna
/// <summary>
/// Gets the target video range type that will be in the output stream.
/// </summary>
- public string TargetVideoRangeType
+ public VideoRangeType TargetVideoRangeType
{
get
{
if (IsDirectStream)
{
- return TargetVideoStream?.VideoRangeType;
+ return TargetVideoStream?.VideoRangeType ?? VideoRangeType.Unknown;
}
var targetVideoCodecs = TargetVideoCodec;
var videoCodec = targetVideoCodecs.Length == 0 ? null : targetVideoCodecs[0];
- if (!string.IsNullOrEmpty(videoCodec))
+ if (!string.IsNullOrEmpty(videoCodec)
+ && Enum.TryParse(GetOption(videoCodec, "rangetype"), true, out VideoRangeType videoRangeType))
{
- return GetOption(videoCodec, "rangetype");
+ return videoRangeType;
}
- return TargetVideoStream?.VideoRangeType;
+ return TargetVideoStream?.VideoRangeType ?? VideoRangeType.Unknown;
}
}
diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs
index 47341f4e1..34642b83a 100644
--- a/MediaBrowser.Model/Entities/MediaStream.cs
+++ b/MediaBrowser.Model/Entities/MediaStream.cs
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
+using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Extensions;
@@ -148,7 +149,7 @@ namespace MediaBrowser.Model.Entities
/// Gets the video range.
/// </summary>
/// <value>The video range.</value>
- public string VideoRange
+ public VideoRange VideoRange
{
get
{
@@ -162,7 +163,7 @@ namespace MediaBrowser.Model.Entities
/// Gets the video range type.
/// </summary>
/// <value>The video range type.</value>
- public string VideoRangeType
+ public VideoRangeType VideoRangeType
{
get
{
@@ -306,9 +307,9 @@ namespace MediaBrowser.Model.Entities
attributes.Add(Codec.ToUpperInvariant());
}
- if (!string.IsNullOrEmpty(VideoRange))
+ if (VideoRange != VideoRange.Unknown)
{
- attributes.Add(VideoRange.ToUpperInvariant());
+ attributes.Add(VideoRange.ToString());
}
if (!string.IsNullOrEmpty(Title))
@@ -677,23 +678,23 @@ namespace MediaBrowser.Model.Entities
return true;
}
- public (string VideoRange, string VideoRangeType) GetVideoColorRange()
+ public (VideoRange VideoRange, VideoRangeType VideoRangeType) GetVideoColorRange()
{
if (Type != MediaStreamType.Video)
{
- return (null, null);
+ return (VideoRange.Unknown, VideoRangeType.Unknown);
}
var colorTransfer = ColorTransfer;
if (string.Equals(colorTransfer, "smpte2084", StringComparison.OrdinalIgnoreCase))
{
- return ("HDR", "HDR10");
+ return (VideoRange.HDR, VideoRangeType.HDR10);
}
if (string.Equals(colorTransfer, "arib-std-b67", StringComparison.OrdinalIgnoreCase))
{
- return ("HDR", "HLG");
+ return (VideoRange.HDR, VideoRangeType.HLG);
}
var codecTag = CodecTag;
@@ -711,10 +712,10 @@ namespace MediaBrowser.Model.Entities
|| string.Equals(codecTag, "dvhe", StringComparison.OrdinalIgnoreCase)
|| string.Equals(codecTag, "dav1", StringComparison.OrdinalIgnoreCase))
{
- return ("HDR", "DOVI");
+ return (VideoRange.HDR, VideoRangeType.DOVI);
}
- return ("SDR", "SDR");
+ return (VideoRange.SDR, VideoRangeType.SDR);
}
}
}