aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Model')
-rw-r--r--MediaBrowser.Model/Configuration/LibraryOptions.cs2
-rw-r--r--MediaBrowser.Model/Configuration/ServerConfiguration.cs19
-rw-r--r--MediaBrowser.Model/Cryptography/PasswordHash.cs7
-rw-r--r--MediaBrowser.Model/Dlna/ContainerProfile.cs4
-rw-r--r--MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs2
-rw-r--r--MediaBrowser.Model/Dlna/MediaOptions.cs (renamed from MediaBrowser.Model/Dlna/AudioOptions.cs)56
-rw-r--r--MediaBrowser.Model/Dlna/ResolutionNormalizer.cs2
-rw-r--r--MediaBrowser.Model/Dlna/SearchCriteria.cs5
-rw-r--r--MediaBrowser.Model/Dlna/StreamBuilder.cs474
-rw-r--r--MediaBrowser.Model/Dlna/StreamInfo.cs18
-rw-r--r--MediaBrowser.Model/Dlna/VideoOptions.cs16
-rw-r--r--MediaBrowser.Model/Drawing/DrawingUtils.cs8
-rw-r--r--MediaBrowser.Model/Drawing/ImageResolution.cs52
-rw-r--r--MediaBrowser.Model/Dto/BaseItemPerson.cs2
-rw-r--r--MediaBrowser.Model/Dto/MediaSourceInfo.cs2
-rw-r--r--MediaBrowser.Model/Entities/MediaStream.cs11
-rw-r--r--MediaBrowser.Model/Entities/ProviderIdsExtensions.cs2
-rw-r--r--MediaBrowser.Model/Extensions/EnumerableExtensions.cs17
-rw-r--r--MediaBrowser.Model/MediaBrowser.Model.csproj8
-rw-r--r--MediaBrowser.Model/Net/MimeTypes.cs10
-rw-r--r--MediaBrowser.Model/Notifications/NotificationOptions.cs8
-rw-r--r--MediaBrowser.Model/Querying/ItemSortBy.cs5
-rw-r--r--MediaBrowser.Model/Updates/VersionInfo.cs2
23 files changed, 421 insertions, 311 deletions
diff --git a/MediaBrowser.Model/Configuration/LibraryOptions.cs b/MediaBrowser.Model/Configuration/LibraryOptions.cs
index c4d313bdba..81f2f02bc5 100644
--- a/MediaBrowser.Model/Configuration/LibraryOptions.cs
+++ b/MediaBrowser.Model/Configuration/LibraryOptions.cs
@@ -45,6 +45,8 @@ namespace MediaBrowser.Model.Configuration
public bool EnableEmbeddedTitles { get; set; }
+ public bool EnableEmbeddedExtrasTitles { get; set; }
+
public bool EnableEmbeddedEpisodeInfos { get; set; }
public int AutomaticRefreshIntervalDays { get; set; }
diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs
index e61b896b9d..a07ab7121e 100644
--- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs
+++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Updates;
@@ -240,5 +241,23 @@ namespace MediaBrowser.Model.Configuration
/// Gets or sets a value indicating whether clients should be allowed to upload logs.
/// </summary>
public bool AllowClientLogUpload { get; set; } = true;
+
+ /// <summary>
+ /// Gets or sets the dummy chapters duration in seconds.
+ /// </summary>
+ /// <value>The dummy chapters duration.</value>
+ public int DummyChapterDuration { get; set; } = 300;
+
+ /// <summary>
+ /// Gets or sets the dummy chapter count.
+ /// </summary>
+ /// <value>The dummy chapter count.</value>
+ public int DummyChapterCount { get; set; } = 100;
+
+ /// <summary>
+ /// Gets or sets the chapter image resolution.
+ /// </summary>
+ /// <value>The chapter image resolution.</value>
+ public ImageResolution ChapterImageResolution { get; set; } = ImageResolution.MatchSource;
}
}
diff --git a/MediaBrowser.Model/Cryptography/PasswordHash.cs b/MediaBrowser.Model/Cryptography/PasswordHash.cs
index 32a34d23c1..80a30684ab 100644
--- a/MediaBrowser.Model/Cryptography/PasswordHash.cs
+++ b/MediaBrowser.Model/Cryptography/PasswordHash.cs
@@ -29,12 +29,7 @@ namespace MediaBrowser.Model.Cryptography
public PasswordHash(string id, byte[] hash, byte[] salt, Dictionary<string, string> parameters)
{
- ArgumentNullException.ThrowIfNull(id);
-
- if (id.Length == 0)
- {
- throw new ArgumentException("String can't be empty", nameof(id));
- }
+ ArgumentException.ThrowIfNullOrEmpty(id);
Id = id;
_hash = hash;
diff --git a/MediaBrowser.Model/Dlna/ContainerProfile.cs b/MediaBrowser.Model/Dlna/ContainerProfile.cs
index c6befdd857..927df8e4ef 100644
--- a/MediaBrowser.Model/Dlna/ContainerProfile.cs
+++ b/MediaBrowser.Model/Dlna/ContainerProfile.cs
@@ -36,7 +36,7 @@ namespace MediaBrowser.Model.Dlna
public static bool ContainsContainer(string? profileContainers, string? inputContainer)
{
var isNegativeList = false;
- if (profileContainers != null && profileContainers.StartsWith('-'))
+ if (profileContainers is not null && profileContainers.StartsWith('-'))
{
isNegativeList = true;
profileContainers = profileContainers.Substring(1);
@@ -52,7 +52,7 @@ namespace MediaBrowser.Model.Dlna
public static bool ContainsContainer(string[]? profileContainers, bool isNegativeList, string? inputContainer)
{
- if (profileContainers == null || profileContainers.Length == 0)
+ if (profileContainers is null || profileContainers.Length == 0)
{
// Empty profiles always support all containers/codecs
return true;
diff --git a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs
index 1a95763610..1d5d0b1de3 100644
--- a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs
+++ b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs
@@ -192,7 +192,7 @@ namespace MediaBrowser.Model.Dlna
var orgPnValues = new List<string>();
- if (mediaProfile != null && !string.IsNullOrEmpty(mediaProfile.OrgPn))
+ if (mediaProfile is not null && !string.IsNullOrEmpty(mediaProfile.OrgPn))
{
orgPnValues.AddRange(mediaProfile.OrgPn.Split(',', StringSplitOptions.RemoveEmptyEntries));
}
diff --git a/MediaBrowser.Model/Dlna/AudioOptions.cs b/MediaBrowser.Model/Dlna/MediaOptions.cs
index 33755e7462..29aecf97fc 100644
--- a/MediaBrowser.Model/Dlna/AudioOptions.cs
+++ b/MediaBrowser.Model/Dlna/MediaOptions.cs
@@ -1,5 +1,4 @@
#nullable disable
-#pragma warning disable CS1591
using System;
using MediaBrowser.Model.Dto;
@@ -7,11 +6,14 @@ using MediaBrowser.Model.Dto;
namespace MediaBrowser.Model.Dlna
{
/// <summary>
- /// Class AudioOptions.
+ /// Class MediaOptions.
/// </summary>
- public class AudioOptions
+ public class MediaOptions
{
- public AudioOptions()
+ /// <summary>
+ /// Initializes a new instance of the <see cref="MediaOptions"/> class.
+ /// </summary>
+ public MediaOptions()
{
Context = EncodingContext.Streaming;
@@ -19,20 +21,49 @@ namespace MediaBrowser.Model.Dlna
EnableDirectStream = true;
}
+ /// <summary>
+ /// Gets or sets a value indicating whether direct playback is allowed.
+ /// </summary>
public bool EnableDirectPlay { get; set; }
+ /// <summary>
+ /// Gets or sets a value indicating whether direct streaming is allowed.
+ /// </summary>
public bool EnableDirectStream { get; set; }
+ /// <summary>
+ /// Gets or sets a value indicating whether direct playback is forced.
+ /// </summary>
public bool ForceDirectPlay { get; set; }
+ /// <summary>
+ /// Gets or sets a value indicating whether direct streaming is forced.
+ /// </summary>
public bool ForceDirectStream { get; set; }
+ /// <summary>
+ /// Gets or sets a value indicating whether audio stream copy is allowed.
+ /// </summary>
public bool AllowAudioStreamCopy { get; set; }
+ /// <summary>
+ /// Gets or sets a value indicating whether video stream copy is allowed.
+ /// </summary>
+ public bool AllowVideoStreamCopy { get; set; }
+
+ /// <summary>
+ /// Gets or sets the item id.
+ /// </summary>
public Guid ItemId { get; set; }
+ /// <summary>
+ /// Gets or sets the media sources.
+ /// </summary>
public MediaSourceInfo[] MediaSources { get; set; }
+ /// <summary>
+ /// Gets or sets the device profile.
+ /// </summary>
public DeviceProfile Profile { get; set; }
/// <summary>
@@ -40,6 +71,9 @@ namespace MediaBrowser.Model.Dlna
/// </summary>
public string MediaSourceId { get; set; }
+ /// <summary>
+ /// Gets or sets the device id.
+ /// </summary>
public string DeviceId { get; set; }
/// <summary>
@@ -49,7 +83,7 @@ namespace MediaBrowser.Model.Dlna
public int? MaxAudioChannels { get; set; }
/// <summary>
- /// Gets or sets the application's configured quality setting.
+ /// Gets or sets the application's configured maximum bitrate.
/// </summary>
public int? MaxBitrate { get; set; }
@@ -66,6 +100,16 @@ namespace MediaBrowser.Model.Dlna
public int? AudioTranscodingBitrate { get; set; }
/// <summary>
+ /// Gets or sets an override for the audio stream index.
+ /// </summary>
+ public int? AudioStreamIndex { get; set; }
+
+ /// <summary>
+ /// Gets or sets an override for the subtitle stream index.
+ /// </summary>
+ public int? SubtitleStreamIndex { get; set; }
+
+ /// <summary>
/// Gets the maximum bitrate.
/// </summary>
/// <param name="isAudio">Whether or not this is audio.</param>
@@ -77,7 +121,7 @@ namespace MediaBrowser.Model.Dlna
return MaxBitrate;
}
- if (Profile == null)
+ if (Profile is null)
{
return null;
}
diff --git a/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs b/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
index 94071b4196..ce422a2288 100644
--- a/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
+++ b/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
@@ -39,7 +39,7 @@ namespace MediaBrowser.Model.Dlna
}
var resolutionConfig = GetResolutionConfiguration(outputBitrate);
- if (resolutionConfig != null)
+ if (resolutionConfig is not null)
{
var originvalValue = maxWidth;
diff --git a/MediaBrowser.Model/Dlna/SearchCriteria.cs b/MediaBrowser.Model/Dlna/SearchCriteria.cs
index b1fc48c087..77d6a55eaf 100644
--- a/MediaBrowser.Model/Dlna/SearchCriteria.cs
+++ b/MediaBrowser.Model/Dlna/SearchCriteria.cs
@@ -9,10 +9,7 @@ namespace MediaBrowser.Model.Dlna
{
public SearchCriteria(string search)
{
- if (search.Length == 0)
- {
- throw new ArgumentException("String can't be empty.", nameof(search));
- }
+ ArgumentException.ThrowIfNullOrEmpty(search);
SearchType = SearchType.Unknown;
diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs
index 6e9b943f74..bb41c99795 100644
--- a/MediaBrowser.Model/Dlna/StreamBuilder.cs
+++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs
@@ -1,5 +1,4 @@
#nullable disable
-#pragma warning disable CS1591
using System;
using System.Collections.Generic;
@@ -13,6 +12,9 @@ using Microsoft.Extensions.Logging;
namespace MediaBrowser.Model.Dlna
{
+ /// <summary>
+ /// Class StreamBuilder.
+ /// </summary>
public class StreamBuilder
{
// Aliases
@@ -24,42 +26,56 @@ namespace MediaBrowser.Model.Dlna
private readonly ILogger _logger;
private readonly ITranscoderSupport _transcoderSupport;
+ /// <summary>
+ /// Initializes a new instance of the <see cref="StreamBuilder"/> class.
+ /// </summary>
+ /// <param name="transcoderSupport">The <see cref="ITranscoderSupport"/> object.</param>
+ /// <param name="logger">The <see cref="ILogger"/> object.</param>
public StreamBuilder(ITranscoderSupport transcoderSupport, ILogger logger)
{
_transcoderSupport = transcoderSupport;
_logger = logger;
}
+ /// <summary>
+ /// Initializes a new instance of the <see cref="StreamBuilder"/> class.
+ /// </summary>
+ /// <param name="logger">The <see cref="ILogger"/> object.</param>
public StreamBuilder(ILogger<StreamBuilder> logger)
: this(new FullTranscoderSupport(), logger)
{
}
- public StreamInfo BuildAudioItem(AudioOptions options)
+ /// <summary>
+ /// Gets the optimal audio stream.
+ /// </summary>
+ /// <param name="options">The <see cref="MediaOptions"/> object to get the audio stream from.</param>
+ /// <returns>The <see cref="StreamInfo"/> of the optimal audio stream.</returns>
+ public StreamInfo GetOptimalAudioStream(MediaOptions options)
{
- ValidateAudioInput(options);
+ ValidateMediaOptions(options, false);
var mediaSources = new List<MediaSourceInfo>();
- foreach (MediaSourceInfo i in options.MediaSources)
+ foreach (var mediaSource in options.MediaSources)
{
if (string.IsNullOrEmpty(options.MediaSourceId) ||
- string.Equals(i.Id, options.MediaSourceId, StringComparison.OrdinalIgnoreCase))
+ string.Equals(mediaSource.Id, options.MediaSourceId, StringComparison.OrdinalIgnoreCase))
{
- mediaSources.Add(i);
+ mediaSources.Add(mediaSource);
}
}
var streams = new List<StreamInfo>();
- foreach (MediaSourceInfo i in mediaSources)
+ foreach (var mediaSourceInfo in mediaSources)
{
- StreamInfo streamInfo = BuildAudioItem(i, options);
- if (streamInfo != null)
+ StreamInfo streamInfo = GetOptimalAudioStream(mediaSourceInfo, options);
+ if (streamInfo is not null)
{
streams.Add(streamInfo);
}
}
- foreach (StreamInfo stream in streams)
+ foreach (var stream in streams)
{
stream.DeviceId = options.DeviceId;
stream.DeviceProfileId = options.Profile.Id;
@@ -68,31 +84,137 @@ namespace MediaBrowser.Model.Dlna
return GetOptimalStream(streams, options.GetMaxBitrate(true) ?? 0);
}
- public StreamInfo BuildVideoItem(VideoOptions options)
+ private StreamInfo GetOptimalAudioStream(MediaSourceInfo item, MediaOptions options)
{
- ValidateInput(options);
+ var playlistItem = new StreamInfo
+ {
+ ItemId = options.ItemId,
+ MediaType = DlnaProfileType.Audio,
+ MediaSource = item,
+ RunTimeTicks = item.RunTimeTicks,
+ Context = options.Context,
+ DeviceProfile = options.Profile
+ };
+
+ if (options.ForceDirectPlay)
+ {
+ playlistItem.PlayMethod = PlayMethod.DirectPlay;
+ playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Audio);
+ return playlistItem;
+ }
+
+ if (options.ForceDirectStream)
+ {
+ playlistItem.PlayMethod = PlayMethod.DirectStream;
+ playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Audio);
+ return playlistItem;
+ }
+
+ MediaStream audioStream = item.GetDefaultAudioStream(null);
+
+ var directPlayInfo = GetAudioDirectPlayProfile(item, audioStream, options);
+
+ var directPlayMethod = directPlayInfo.PlayMethod;
+ var transcodeReasons = directPlayInfo.TranscodeReasons;
+
+ var inputAudioChannels = audioStream?.Channels;
+ var inputAudioBitrate = audioStream?.BitDepth;
+ var inputAudioSampleRate = audioStream?.SampleRate;
+ var inputAudioBitDepth = audioStream?.BitDepth;
+
+ if (directPlayMethod.HasValue)
+ {
+ var profile = options.Profile;
+ var audioFailureConditions = GetProfileConditionsForAudio(profile.CodecProfiles, item.Container, audioStream?.Codec, inputAudioChannels, inputAudioBitrate, inputAudioSampleRate, inputAudioBitDepth, true);
+ var audioFailureReasons = AggregateFailureConditions(item, profile, "AudioCodecProfile", audioFailureConditions);
+ transcodeReasons |= audioFailureReasons;
+
+ if (audioFailureReasons == 0)
+ {
+ playlistItem.PlayMethod = directPlayMethod.Value;
+ playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Audio, directPlayInfo.Profile);
+
+ return playlistItem;
+ }
+ }
+
+ TranscodingProfile transcodingProfile = null;
+ foreach (var tcProfile in options.Profile.TranscodingProfiles)
+ {
+ if (tcProfile.Type == playlistItem.MediaType
+ && tcProfile.Context == options.Context
+ && _transcoderSupport.CanEncodeToAudioCodec(transcodingProfile.AudioCodec ?? tcProfile.Container))
+ {
+ transcodingProfile = tcProfile;
+ break;
+ }
+ }
+
+ if (transcodingProfile != null)
+ {
+ if (!item.SupportsTranscoding)
+ {
+ return null;
+ }
+
+ SetStreamInfoOptionsFromTranscodingProfile(item, playlistItem, transcodingProfile);
+
+ var audioTranscodingConditions = GetProfileConditionsForAudio(options.Profile.CodecProfiles, transcodingProfile.Container, transcodingProfile.AudioCodec, inputAudioChannels, inputAudioBitrate, inputAudioSampleRate, inputAudioBitDepth, false).ToArray();
+ ApplyTranscodingConditions(playlistItem, audioTranscodingConditions, null, true, true);
+
+ // Honor requested max channels
+ playlistItem.GlobalMaxAudioChannels = options.MaxAudioChannels;
+
+ var configuredBitrate = options.GetMaxBitrate(true);
+
+ long transcodingBitrate = options.AudioTranscodingBitrate
+ ?? (options.Context == EncodingContext.Streaming ? options.Profile.MusicStreamingTranscodingBitrate : null)
+ ?? configuredBitrate
+ ?? 128000;
+
+ if (configuredBitrate.HasValue)
+ {
+ transcodingBitrate = Math.Min(configuredBitrate.Value, transcodingBitrate);
+ }
+
+ var longBitrate = Math.Min(transcodingBitrate, playlistItem.AudioBitrate ?? transcodingBitrate);
+ playlistItem.AudioBitrate = longBitrate > int.MaxValue ? int.MaxValue : Convert.ToInt32(longBitrate);
+ }
+
+ playlistItem.TranscodeReasons = transcodeReasons;
+ return playlistItem;
+ }
+
+ /// <summary>
+ /// Gets the optimal video stream.
+ /// </summary>
+ /// <param name="options">The <see cref="MediaOptions"/> object to get the video stream from.</param>
+ /// <returns>The <see cref="StreamInfo"/> of the optimal video stream.</returns>
+ public StreamInfo GetOptimalVideoStream(MediaOptions options)
+ {
+ ValidateMediaOptions(options, true);
var mediaSources = new List<MediaSourceInfo>();
- foreach (MediaSourceInfo i in options.MediaSources)
+ foreach (var mediaSourceInfo in options.MediaSources)
{
if (string.IsNullOrEmpty(options.MediaSourceId) ||
- string.Equals(i.Id, options.MediaSourceId, StringComparison.OrdinalIgnoreCase))
+ string.Equals(mediaSourceInfo.Id, options.MediaSourceId, StringComparison.OrdinalIgnoreCase))
{
- mediaSources.Add(i);
+ mediaSources.Add(mediaSourceInfo);
}
}
var streams = new List<StreamInfo>();
- foreach (MediaSourceInfo i in mediaSources)
+ foreach (var mediaSourceInfo in mediaSources)
{
- var streamInfo = BuildVideoItem(i, options);
- if (streamInfo != null)
+ var streamInfo = BuildVideoItem(mediaSourceInfo, options);
+ if (streamInfo is not null)
{
streams.Add(streamInfo);
}
}
- foreach (StreamInfo stream in streams)
+ foreach (var stream in streams)
{
stream.DeviceId = options.DeviceId;
stream.DeviceProfileId = options.Profile.Id;
@@ -236,6 +358,14 @@ namespace MediaBrowser.Model.Dlna
}
}
+ /// <summary>
+ /// Normalizes input container.
+ /// </summary>
+ /// <param name="inputContainer">The input container.</param>
+ /// <param name="profile">The <see cref="DeviceProfile"/>.</param>
+ /// <param name="type">The <see cref="DlnaProfileType"/>.</param>
+ /// <param name="playProfile">The <see cref="DirectPlayProfile"/> object to get the video stream from.</param>
+ /// <returns>The the normalized input container.</returns>
public static string NormalizeMediaSourceFormatIntoSingleContainer(string inputContainer, DeviceProfile profile, DlnaProfileType type, DirectPlayProfile playProfile = null)
{
if (string.IsNullOrEmpty(inputContainer))
@@ -245,9 +375,9 @@ namespace MediaBrowser.Model.Dlna
var formats = ContainerProfile.SplitValue(inputContainer);
- if (profile != null)
+ if (profile is not null)
{
- var playProfiles = playProfile == null ? profile.DirectPlayProfiles : new[] { playProfile };
+ var playProfiles = playProfile is null ? profile.DirectPlayProfiles : new[] { playProfile };
foreach (var format in formats)
{
foreach (var directPlayProfile in playProfiles)
@@ -264,113 +394,12 @@ namespace MediaBrowser.Model.Dlna
return formats[0];
}
- private StreamInfo BuildAudioItem(MediaSourceInfo item, AudioOptions options)
- {
- StreamInfo playlistItem = new StreamInfo
- {
- ItemId = options.ItemId,
- MediaType = DlnaProfileType.Audio,
- MediaSource = item,
- RunTimeTicks = item.RunTimeTicks,
- Context = options.Context,
- DeviceProfile = options.Profile
- };
-
- if (options.ForceDirectPlay)
- {
- playlistItem.PlayMethod = PlayMethod.DirectPlay;
- playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Audio);
- return playlistItem;
- }
-
- if (options.ForceDirectStream)
- {
- playlistItem.PlayMethod = PlayMethod.DirectStream;
- playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Audio);
- return playlistItem;
- }
-
- var audioStream = item.GetDefaultAudioStream(null);
-
- var directPlayInfo = GetAudioDirectPlayProfile(item, audioStream, options);
-
- var directPlayMethod = directPlayInfo.PlayMethod;
- var transcodeReasons = directPlayInfo.TranscodeReasons;
-
- int? inputAudioChannels = audioStream?.Channels;
- int? inputAudioBitrate = audioStream?.BitDepth;
- int? inputAudioSampleRate = audioStream?.SampleRate;
- int? inputAudioBitDepth = audioStream?.BitDepth;
-
- if (directPlayMethod.HasValue)
- {
- var profile = options.Profile;
- var audioFailureConditions = GetProfileConditionsForAudio(profile.CodecProfiles, item.Container, audioStream?.Codec, inputAudioChannels, inputAudioBitrate, inputAudioSampleRate, inputAudioBitDepth, true);
- var audioFailureReasons = AggregateFailureConditions(item, profile, "AudioCodecProfile", audioFailureConditions);
- transcodeReasons |= audioFailureReasons;
-
- if (audioFailureReasons == 0)
- {
- playlistItem.PlayMethod = directPlayMethod.Value;
- playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Audio, directPlayInfo.Profile);
-
- return playlistItem;
- }
- }
-
- TranscodingProfile transcodingProfile = null;
- foreach (var i in options.Profile.TranscodingProfiles)
- {
- if (i.Type == playlistItem.MediaType
- && i.Context == options.Context
- && _transcoderSupport.CanEncodeToAudioCodec(i.AudioCodec ?? i.Container))
- {
- transcodingProfile = i;
- break;
- }
- }
-
- if (transcodingProfile != null)
- {
- if (!item.SupportsTranscoding)
- {
- return null;
- }
-
- SetStreamInfoOptionsFromTranscodingProfile(item, playlistItem, transcodingProfile);
-
- var audioTranscodingConditions = GetProfileConditionsForAudio(options.Profile.CodecProfiles, transcodingProfile.Container, transcodingProfile.AudioCodec, inputAudioChannels, inputAudioBitrate, inputAudioSampleRate, inputAudioBitDepth, false).ToArray();
- ApplyTranscodingConditions(playlistItem, audioTranscodingConditions, null, true, true);
-
- // Honor requested max channels
- playlistItem.GlobalMaxAudioChannels = options.MaxAudioChannels;
-
- var configuredBitrate = options.GetMaxBitrate(true);
-
- long transcodingBitrate = options.AudioTranscodingBitrate ??
- (options.Context == EncodingContext.Streaming ? options.Profile.MusicStreamingTranscodingBitrate : null) ??
- configuredBitrate ??
- 128000;
-
- if (configuredBitrate.HasValue)
- {
- transcodingBitrate = Math.Min(configuredBitrate.Value, transcodingBitrate);
- }
-
- var longBitrate = Math.Min(transcodingBitrate, playlistItem.AudioBitrate ?? transcodingBitrate);
- playlistItem.AudioBitrate = longBitrate > int.MaxValue ? int.MaxValue : Convert.ToInt32(longBitrate);
- }
-
- playlistItem.TranscodeReasons = transcodeReasons;
- return playlistItem;
- }
-
- private (DirectPlayProfile Profile, PlayMethod? PlayMethod, TranscodeReason TranscodeReasons) GetAudioDirectPlayProfile(MediaSourceInfo item, MediaStream audioStream, AudioOptions options)
+ private (DirectPlayProfile Profile, PlayMethod? PlayMethod, TranscodeReason TranscodeReasons) GetAudioDirectPlayProfile(MediaSourceInfo item, MediaStream audioStream, MediaOptions options)
{
var directPlayProfile = options.Profile.DirectPlayProfiles
.FirstOrDefault(x => x.Type == DlnaProfileType.Audio && IsAudioDirectPlaySupported(x, item, audioStream));
- if (directPlayProfile == null)
+ if (directPlayProfile is null)
{
_logger.LogDebug(
"Profile: {0}, No audio direct play profiles found for {1} with codec {2}",
@@ -388,7 +417,7 @@ namespace MediaBrowser.Model.Dlna
// If device requirements are satisfied then allow both direct stream and direct play
if (item.SupportsDirectPlay)
{
- if (IsItemBitrateEligibleForDirectPlayback(item, options.GetMaxBitrate(true) ?? 0, PlayMethod.DirectPlay))
+ if (!IsBitrateLimitExceeded(item, options.GetMaxBitrate(true) ?? 0))
{
if (options.EnableDirectPlay)
{
@@ -404,7 +433,7 @@ namespace MediaBrowser.Model.Dlna
// While options takes the network and other factors into account. Only applies to direct stream
if (item.SupportsDirectStream)
{
- if (IsItemBitrateEligibleForDirectPlayback(item, options.GetMaxBitrate(true) ?? 0, PlayMethod.DirectStream))
+ if (!IsBitrateLimitExceeded(item, options.GetMaxBitrate(true) ?? 0))
{
if (options.EnableDirectStream)
{
@@ -422,12 +451,11 @@ namespace MediaBrowser.Model.Dlna
private static TranscodeReason GetTranscodeReasonsFromDirectPlayProfile(MediaSourceInfo item, MediaStream videoStream, MediaStream audioStream, IEnumerable<DirectPlayProfile> directPlayProfiles)
{
- var mediaType = videoStream == null ? DlnaProfileType.Audio : DlnaProfileType.Video;
+ var mediaType = videoStream is null ? DlnaProfileType.Audio : DlnaProfileType.Video;
var containerSupported = false;
var audioSupported = false;
var videoSupported = false;
- TranscodeReason reasons = 0;
foreach (var profile in directPlayProfiles)
{
@@ -436,9 +464,9 @@ namespace MediaBrowser.Model.Dlna
{
containerSupported = true;
- videoSupported = videoStream == null || profile.SupportsVideoCodec(videoStream.Codec);
+ videoSupported = videoStream is null || profile.SupportsVideoCodec(videoStream.Codec);
- audioSupported = audioStream == null || profile.SupportsAudioCodec(audioStream.Codec);
+ audioSupported = audioStream is null || profile.SupportsAudioCodec(audioStream.Codec);
if (videoSupported && audioSupported)
{
@@ -447,6 +475,7 @@ namespace MediaBrowser.Model.Dlna
}
}
+ TranscodeReason reasons = 0;
if (!containerSupported)
{
reasons |= TranscodeReason.ContainerNotSupported;
@@ -547,7 +576,7 @@ namespace MediaBrowser.Model.Dlna
}
}
- private static void SetStreamInfoOptionsFromDirectPlayProfile(VideoOptions options, MediaSourceInfo item, StreamInfo playlistItem, DirectPlayProfile directPlayProfile)
+ private static void SetStreamInfoOptionsFromDirectPlayProfile(MediaOptions options, MediaSourceInfo item, StreamInfo playlistItem, DirectPlayProfile directPlayProfile)
{
var container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Video, directPlayProfile);
var protocol = "http";
@@ -562,7 +591,7 @@ namespace MediaBrowser.Model.Dlna
playlistItem.AudioCodecs = ContainerProfile.SplitValue(directPlayProfile.AudioCodec);
}
- private StreamInfo BuildVideoItem(MediaSourceInfo item, VideoOptions options)
+ private StreamInfo BuildVideoItem(MediaSourceInfo item, MediaOptions options)
{
ArgumentNullException.ThrowIfNull(item);
@@ -580,13 +609,13 @@ namespace MediaBrowser.Model.Dlna
var subtitleStream = playlistItem.SubtitleStreamIndex.HasValue ? item.GetMediaStream(MediaStreamType.Subtitle, playlistItem.SubtitleStreamIndex.Value) : null;
var audioStream = item.GetDefaultAudioStream(options.AudioStreamIndex ?? item.DefaultAudioStreamIndex);
- if (audioStream != null)
+ if (audioStream is not null)
{
playlistItem.AudioStreamIndex = audioStream.Index;
}
// Collect candidate audio streams
- ICollection<MediaStream> candidateAudioStreams = audioStream == null ? Array.Empty<MediaStream>() : new[] { audioStream };
+ ICollection<MediaStream> candidateAudioStreams = audioStream is null ? Array.Empty<MediaStream>() : new[] { audioStream };
if (!options.AudioStreamIndex.HasValue || options.AudioStreamIndex < 0)
{
if (audioStream?.IsDefault == true)
@@ -601,11 +630,15 @@ namespace MediaBrowser.Model.Dlna
var videoStream = item.VideoStream;
- var directPlayBitrateEligibility = IsBitrateEligibleForDirectPlayback(item, options.GetMaxBitrate(false) ?? 0, options, PlayMethod.DirectPlay);
- var directStreamBitrateEligibility = IsBitrateEligibleForDirectPlayback(item, options.GetMaxBitrate(false) ?? 0, options, PlayMethod.DirectStream);
- bool isEligibleForDirectPlay = options.EnableDirectPlay && (options.ForceDirectPlay || directPlayBitrateEligibility == 0);
- bool isEligibleForDirectStream = options.EnableDirectStream && (options.ForceDirectStream || directStreamBitrateEligibility == 0);
- var transcodeReasons = directPlayBitrateEligibility | directStreamBitrateEligibility;
+ var bitrateLimitExceeded = IsBitrateLimitExceeded(item, options.GetMaxBitrate(false) ?? 0);
+ var isEligibleForDirectPlay = options.EnableDirectPlay && (options.ForceDirectPlay || !bitrateLimitExceeded);
+ var isEligibleForDirectStream = options.EnableDirectStream && (options.ForceDirectStream || !bitrateLimitExceeded);
+ TranscodeReason transcodeReasons = 0;
+
+ if (bitrateLimitExceeded)
+ {
+ transcodeReasons = TranscodeReason.ContainerBitrateExceedsLimit;
+ }
_logger.LogDebug(
"Profile: {0}, Path: {1}, isEligibleForDirectPlay: {2}, isEligibleForDirectStream: {3}",
@@ -643,7 +676,7 @@ namespace MediaBrowser.Model.Dlna
else if (directPlay == PlayMethod.DirectStream)
{
playlistItem.AudioStreamIndex = audioStream?.Index;
- if (audioStream != null)
+ if (audioStream is not null)
{
playlistItem.AudioCodecs = ContainerProfile.SplitValue(directPlayProfile.AudioCodec);
}
@@ -652,7 +685,7 @@ namespace MediaBrowser.Model.Dlna
BuildStreamVideoItem(playlistItem, options, item, videoStream, audioStream, candidateAudioStreams, directPlayProfile.Container, directPlayProfile.VideoCodec, directPlayProfile.AudioCodec);
}
- if (subtitleStream != null)
+ if (subtitleStream is not null)
{
var subtitleProfile = GetSubtitleProfile(item, subtitleStream, options.Profile.SubtitleProfiles, directPlay.Value, _transcoderSupport, directPlayProfile.Container, null);
@@ -678,7 +711,7 @@ namespace MediaBrowser.Model.Dlna
// Can't direct play, find the transcoding profile
// If we do this for direct-stream we will overwrite the info
var transcodingProfile = GetVideoTranscodeProfile(item, options, videoStream, audioStream, candidateAudioStreams, subtitleStream, playlistItem);
- if (transcodingProfile != null)
+ if (transcodingProfile is not null)
{
SetStreamInfoOptionsFromTranscodingProfile(item, playlistItem, transcodingProfile);
@@ -686,7 +719,7 @@ namespace MediaBrowser.Model.Dlna
playlistItem.PlayMethod = PlayMethod.Transcode;
- if (subtitleStream != null)
+ if (subtitleStream is not null)
{
var subtitleProfile = GetSubtitleProfile(item, subtitleStream, options.Profile.SubtitleProfiles, PlayMethod.Transcode, _transcoderSupport, transcodingProfile.Container, transcodingProfile.Protocol);
@@ -702,7 +735,7 @@ namespace MediaBrowser.Model.Dlna
}
}
- _logger.LogInformation(
+ _logger.LogDebug(
"StreamBuilder.BuildVideoItem( Profile={0}, Path={1}, AudioStreamIndex={2}, SubtitleStreamIndex={3} ) => ( PlayMethod={4}, TranscodeReason={5} ) {6}",
options.Profile.Name ?? "Anonymous Profile",
item.Path ?? "Unknown path",
@@ -716,7 +749,7 @@ namespace MediaBrowser.Model.Dlna
return playlistItem;
}
- private TranscodingProfile GetVideoTranscodeProfile(MediaSourceInfo item, VideoOptions options, MediaStream videoStream, MediaStream audioStream, IEnumerable<MediaStream> candidateAudioStreams, MediaStream subtitleStream, StreamInfo playlistItem)
+ private TranscodingProfile GetVideoTranscodeProfile(MediaSourceInfo item, MediaOptions options, MediaStream videoStream, MediaStream audioStream, IEnumerable<MediaStream> candidateAudioStreams, MediaStream subtitleStream, StreamInfo playlistItem)
{
if (!(item.SupportsTranscoding || item.SupportsDirectStream))
{
@@ -729,8 +762,8 @@ namespace MediaBrowser.Model.Dlna
if (options.AllowVideoStreamCopy)
{
// prefer direct copy profile
- float videoFramerate = videoStream == null ? 0 : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate ?? 0;
- TransportStreamTimestamp? timestamp = videoStream == null ? TransportStreamTimestamp.None : item.Timestamp;
+ float videoFramerate = videoStream is null ? 0 : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate ?? 0;
+ TransportStreamTimestamp? timestamp = videoStream is null ? TransportStreamTimestamp.None : item.Timestamp;
int? numAudioStreams = item.GetStreamCount(MediaStreamType.Audio);
int? numVideoStreams = item.GetStreamCount(MediaStreamType.Video);
@@ -763,12 +796,12 @@ namespace MediaBrowser.Model.Dlna
return transcodingProfiles.FirstOrDefault();
}
- private void BuildStreamVideoItem(StreamInfo playlistItem, VideoOptions options, MediaSourceInfo item, MediaStream videoStream, MediaStream audioStream, IEnumerable<MediaStream> candidateAudioStreams, string container, string videoCodec, string audioCodec)
+ private void BuildStreamVideoItem(StreamInfo playlistItem, MediaOptions options, MediaSourceInfo item, MediaStream videoStream, MediaStream audioStream, IEnumerable<MediaStream> candidateAudioStreams, string container, string videoCodec, string audioCodec)
{
// Prefer matching video codecs
var videoCodecs = ContainerProfile.SplitValue(videoCodec);
var directVideoCodec = ContainerProfile.ContainsContainer(videoCodecs, videoStream?.Codec) ? videoStream?.Codec : null;
- if (directVideoCodec != null)
+ if (directVideoCodec is not null)
{
// merge directVideoCodec to videoCodecs
Array.Resize(ref videoCodecs, videoCodecs.Length + 1);
@@ -780,12 +813,12 @@ namespace MediaBrowser.Model.Dlna
// Copy video codec options as a starting point, this applies to transcode and direct-stream
playlistItem.MaxFramerate = videoStream?.AverageFrameRate;
var qualifier = videoStream?.Codec;
- if (videoStream?.Level != null)
+ if (videoStream?.Level is not null)
{
playlistItem.SetOption(qualifier, "level", videoStream.Level.Value.ToString(CultureInfo.InvariantCulture));
}
- if (videoStream?.BitDepth != null)
+ if (videoStream?.BitDepth is not null)
{
playlistItem.SetOption(qualifier, "videobitdepth", videoStream.BitDepth.Value.ToString(CultureInfo.InvariantCulture));
}
@@ -795,7 +828,7 @@ namespace MediaBrowser.Model.Dlna
playlistItem.SetOption(qualifier, "profile", videoStream.Profile.ToLowerInvariant());
}
- if (videoStream != null && videoStream.Level != 0)
+ if (videoStream is not null && videoStream.Level != 0)
{
playlistItem.SetOption(qualifier, "level", videoStream.Level.ToString());
}
@@ -804,7 +837,7 @@ namespace MediaBrowser.Model.Dlna
var audioCodecs = ContainerProfile.SplitValue(audioCodec);
var directAudioStream = candidateAudioStreams.FirstOrDefault(stream => ContainerProfile.ContainsContainer(audioCodecs, stream.Codec));
playlistItem.AudioCodecs = audioCodecs;
- if (directAudioStream != null)
+ if (directAudioStream is not null)
{
audioStream = directAudioStream;
playlistItem.AudioStreamIndex = audioStream.Index;
@@ -832,13 +865,13 @@ namespace MediaBrowser.Model.Dlna
double? videoLevel = videoStream?.Level;
string videoProfile = videoStream?.Profile;
string videoRangeType = videoStream?.VideoRangeType;
- float videoFramerate = videoStream == null ? 0 : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate ?? 0;
+ float videoFramerate = videoStream is null ? 0 : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate ?? 0;
bool? isAnamorphic = videoStream?.IsAnamorphic;
bool? isInterlaced = videoStream?.IsInterlaced;
string videoCodecTag = videoStream?.CodecTag;
bool? isAvc = videoStream?.IsAVC;
- TransportStreamTimestamp? timestamp = videoStream == null ? TransportStreamTimestamp.None : item.Timestamp;
+ TransportStreamTimestamp? timestamp = videoStream is null ? TransportStreamTimestamp.None : item.Timestamp;
int? packetLength = videoStream?.PacketLength;
int? refFrames = videoStream?.RefFrames;
@@ -867,29 +900,29 @@ namespace MediaBrowser.Model.Dlna
// Honor requested max channels
playlistItem.GlobalMaxAudioChannels = options.MaxAudioChannels;
- int audioBitrate = GetAudioBitrate(options.GetMaxBitrate(false) ?? 0, playlistItem.TargetAudioCodec, audioStream, playlistItem);
+ int audioBitrate = GetAudioBitrate(options.GetMaxBitrate(true) ?? 0, playlistItem.TargetAudioCodec, audioStream, playlistItem);
playlistItem.AudioBitrate = Math.Min(playlistItem.AudioBitrate ?? audioBitrate, audioBitrate);
- bool? isSecondaryAudio = audioStream == null ? null : item.IsSecondaryAudio(audioStream);
- int? inputAudioBitrate = audioStream == null ? null : audioStream.BitRate;
- int? audioChannels = audioStream == null ? null : audioStream.Channels;
- string audioProfile = audioStream == null ? null : audioStream.Profile;
- int? inputAudioSampleRate = audioStream == null ? null : audioStream.SampleRate;
- int? inputAudioBitDepth = audioStream == null ? null : audioStream.BitDepth;
+ bool? isSecondaryAudio = audioStream is null ? null : item.IsSecondaryAudio(audioStream);
+ int? inputAudioBitrate = audioStream is null ? null : audioStream.BitRate;
+ int? audioChannels = audioStream is null ? null : audioStream.Channels;
+ string audioProfile = audioStream is null ? null : audioStream.Profile;
+ int? inputAudioSampleRate = audioStream is null ? null : audioStream.SampleRate;
+ int? inputAudioBitDepth = audioStream is null ? null : audioStream.BitDepth;
var appliedAudioConditions = options.Profile.CodecProfiles
.Where(i => i.Type == CodecType.VideoAudio &&
i.ContainsAnyCodec(audioCodec, container) &&
i.ApplyConditions.All(applyCondition => ConditionProcessor.IsVideoAudioConditionSatisfied(applyCondition, audioChannels, inputAudioBitrate, inputAudioSampleRate, inputAudioBitDepth, audioProfile, isSecondaryAudio)));
isFirstAppliedCodecProfile = true;
- foreach (var i in appliedAudioConditions)
+ foreach (var codecProfile in appliedAudioConditions)
{
var transcodingAudioCodecs = ContainerProfile.SplitValue(audioCodec);
foreach (var transcodingAudioCodec in transcodingAudioCodecs)
{
- if (i.ContainsAnyCodec(transcodingAudioCodec, container))
+ if (codecProfile.ContainsAnyCodec(transcodingAudioCodec, container))
{
- ApplyTranscodingConditions(playlistItem, i.Conditions, transcodingAudioCodec, true, isFirstAppliedCodecProfile);
+ ApplyTranscodingConditions(playlistItem, codecProfile.Conditions, transcodingAudioCodec, true, isFirstAppliedCodecProfile);
isFirstAppliedCodecProfile = false;
break;
}
@@ -965,7 +998,7 @@ namespace MediaBrowser.Model.Dlna
int defaultBitrate;
int encoderAudioBitrateLimit = int.MaxValue;
- if (audioStream == null)
+ if (audioStream is null)
{
defaultBitrate = 192000;
}
@@ -982,7 +1015,7 @@ namespace MediaBrowser.Model.Dlna
&& audioStream.Channels.HasValue
&& audioStream.Channels.Value <= targetAudioChannels.Value
&& !string.IsNullOrEmpty(audioStream.Codec)
- && targetAudioCodecs != null
+ && targetAudioCodecs is not null
&& targetAudioCodecs.Length > 0
&& !Array.Exists(targetAudioCodecs, elem => string.Equals(audioStream.Codec, elem, StringComparison.OrdinalIgnoreCase)))
{
@@ -1050,7 +1083,7 @@ namespace MediaBrowser.Model.Dlna
}
private (DirectPlayProfile Profile, PlayMethod? PlayMethod, int? AudioStreamIndex, TranscodeReason TranscodeReasons) GetVideoDirectPlayProfile(
- VideoOptions options,
+ MediaOptions options,
MediaSourceInfo mediaSource,
MediaStream videoStream,
MediaStream audioStream,
@@ -1080,13 +1113,13 @@ namespace MediaBrowser.Model.Dlna
double? videoLevel = videoStream?.Level;
string videoProfile = videoStream?.Profile;
string videoRangeType = videoStream?.VideoRangeType;
- float videoFramerate = videoStream == null ? 0 : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate ?? 0;
+ float videoFramerate = videoStream is null ? 0 : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate ?? 0;
bool? isAnamorphic = videoStream?.IsAnamorphic;
bool? isInterlaced = videoStream?.IsInterlaced;
string videoCodecTag = videoStream?.CodecTag;
bool? isAvc = videoStream?.IsAVC;
- TransportStreamTimestamp? timestamp = videoStream == null ? TransportStreamTimestamp.None : mediaSource.Timestamp;
+ TransportStreamTimestamp? timestamp = videoStream is null ? TransportStreamTimestamp.None : mediaSource.Timestamp;
int? packetLength = videoStream?.PacketLength;
int? refFrames = videoStream?.RefFrames;
@@ -1119,7 +1152,7 @@ namespace MediaBrowser.Model.Dlna
var audioStreamMatches = candidateAudioStreams.ToDictionary(s => s, audioStream => CheckVideoAudioStreamDirectPlay(options, mediaSource, container, audioStream));
TranscodeReason subtitleProfileReasons = 0;
- if (subtitleStream != null)
+ if (subtitleStream is not null)
{
var subtitleProfile = GetSubtitleProfile(mediaSource, subtitleStream, options.Profile.SubtitleProfiles, PlayMethod.DirectPlay, _transcoderSupport, container, null);
@@ -1177,7 +1210,7 @@ namespace MediaBrowser.Model.Dlna
if (candidateAudioStreams.Any())
{
selectedAudioStream = candidateAudioStreams.FirstOrDefault(audioStream => directPlayProfile.SupportsAudioCodec(audioStream.Codec));
- if (selectedAudioStream == null)
+ if (selectedAudioStream is null)
{
directPlayProfileReasons |= TranscodeReason.AudioCodecNotSupported;
}
@@ -1206,7 +1239,7 @@ namespace MediaBrowser.Model.Dlna
{
playMethod = PlayMethod.DirectPlay;
}
- else if (directStreamFailureReasons == 0 && isEligibleForDirectStream && mediaSource.SupportsDirectStream && directPlayProfile != null)
+ else if (directStreamFailureReasons == 0 && isEligibleForDirectStream && mediaSource.SupportsDirectStream && directPlayProfile is not null)
{
playMethod = PlayMethod.DirectStream;
}
@@ -1218,12 +1251,12 @@ namespace MediaBrowser.Model.Dlna
.ThenByDescending(analysis => analysis.Rank)
.ThenBy(analysis => analysis.Order)
.ToArray()
- .ToLookup(analysis => analysis.Result.PlayMethod != null);
+ .ToLookup(analysis => analysis.Result.PlayMethod is not null);
var profileMatch = analyzedProfiles[true]
.Select(analysis => analysis.Result)
.FirstOrDefault();
- if (profileMatch.Profile != null)
+ if (profileMatch.Profile is not null)
{
return profileMatch;
}
@@ -1237,7 +1270,7 @@ namespace MediaBrowser.Model.Dlna
return (Profile: null, PlayMethod: null, AudioStreamIndex: null, TranscodeReasons: failureReasons);
}
- private TranscodeReason CheckVideoAudioStreamDirectPlay(VideoOptions options, MediaSourceInfo mediaSource, string container, MediaStream audioStream)
+ private TranscodeReason CheckVideoAudioStreamDirectPlay(MediaOptions options, MediaSourceInfo mediaSource, string container, MediaStream audioStream)
{
var profile = options.Profile;
var audioFailureConditions = GetProfileConditionsForVideoAudio(profile.CodecProfiles, container, audioStream.Codec, audioStream.Channels, audioStream.BitRate, audioStream.SampleRate, audioStream.BitDepth, audioStream.Profile, mediaSource.IsSecondaryAudio(audioStream));
@@ -1274,23 +1307,17 @@ namespace MediaBrowser.Model.Dlna
mediaSource.Path ?? "Unknown path");
}
- private TranscodeReason IsBitrateEligibleForDirectPlayback(
- MediaSourceInfo item,
- long maxBitrate,
- VideoOptions options,
- PlayMethod playMethod)
- {
- bool result = IsItemBitrateEligibleForDirectPlayback(item, maxBitrate, playMethod);
- if (!result)
- {
- return TranscodeReason.ContainerBitrateExceedsLimit;
- }
- else
- {
- return 0;
- }
- }
-
+ /// <summary>
+ /// Normalizes input container.
+ /// </summary>
+ /// <param name="mediaSource">The <see cref="MediaSourceInfo"/>.</param>
+ /// <param name="subtitleStream">The <see cref="MediaStream"/> of the subtitle stream.</param>
+ /// <param name="subtitleProfiles">The list of supported <see cref="SubtitleProfile"/>s.</param>
+ /// <param name="playMethod">The <see cref="PlayMethod"/>.</param>
+ /// <param name="transcoderSupport">The <see cref="ITranscoderSupport"/>.</param>
+ /// <param name="outputContainer">The output container.</param>
+ /// <param name="transcodingSubProtocol">The subtitle transoding protocol.</param>
+ /// <returns>The the normalized input container.</returns>
public static SubtitleProfile GetSubtitleProfile(
MediaSourceInfo mediaSource,
MediaStream subtitleStream,
@@ -1448,67 +1475,60 @@ namespace MediaBrowser.Model.Dlna
return null;
}
- private bool IsItemBitrateEligibleForDirectPlayback(MediaSourceInfo item, long maxBitrate, PlayMethod playMethod)
+ private bool IsBitrateLimitExceeded(MediaSourceInfo item, long maxBitrate)
{
- // Don't restrict by bitrate if coming from an external domain
+ // Don't restrict bitrate if item is remote.
if (item.IsRemote)
{
- return true;
+ return false;
}
- long requestedMaxBitrate = maxBitrate > 0 ? maxBitrate : 1000000;
+ // If no maximum bitrate is set, default to no maximum bitrate.
+ long requestedMaxBitrate = maxBitrate > 0 ? maxBitrate : int.MaxValue;
- // If we don't know the bitrate, then force a transcode if requested max bitrate is under 40 mbps
+ // If we don't know the item bitrate, then force a transcode if requested max bitrate is under 40 mbps
int itemBitrate = item.Bitrate ?? 40000000;
if (itemBitrate > requestedMaxBitrate)
{
_logger.LogDebug(
- "Bitrate exceeds {PlayBackMethod} limit: media bitrate: {MediaBitrate}, max bitrate: {MaxBitrate}",
- playMethod,
+ "Bitrate exceeds limit: media bitrate: {MediaBitrate}, max bitrate: {MaxBitrate}",
itemBitrate,
requestedMaxBitrate);
- return false;
- }
-
- return true;
- }
-
- private static void ValidateInput(VideoOptions options)
- {
- ValidateAudioInput(options);
-
- if (options.AudioStreamIndex.HasValue && string.IsNullOrEmpty(options.MediaSourceId))
- {
- throw new ArgumentException("MediaSourceId is required when a specific audio stream is requested");
+ return true;
}
- if (options.SubtitleStreamIndex.HasValue && string.IsNullOrEmpty(options.MediaSourceId))
- {
- throw new ArgumentException("MediaSourceId is required when a specific subtitle stream is requested");
- }
+ return false;
}
- private static void ValidateAudioInput(AudioOptions options)
+ private static void ValidateMediaOptions(MediaOptions options, bool isMediaSource)
{
if (options.ItemId.Equals(default))
{
- throw new ArgumentException("ItemId is required");
+ ArgumentException.ThrowIfNullOrEmpty(options.DeviceId);
}
- if (string.IsNullOrEmpty(options.DeviceId))
+ if (options.Profile is null)
{
- throw new ArgumentException("DeviceId is required");
+ throw new ArgumentException("Profile is required");
}
- if (options.Profile == null)
+ if (options.MediaSources is null)
{
- throw new ArgumentException("Profile is required");
+ throw new ArgumentException("MediaSources is required");
}
- if (options.MediaSources == null)
+ if (isMediaSource)
{
- throw new ArgumentException("MediaSources is required");
+ if (options.AudioStreamIndex.HasValue && string.IsNullOrEmpty(options.MediaSourceId))
+ {
+ throw new ArgumentException("MediaSourceId is required when a specific audio stream is requested");
+ }
+
+ if (options.SubtitleStreamIndex.HasValue && string.IsNullOrEmpty(options.MediaSourceId))
+ {
+ throw new ArgumentException("MediaSourceId is required when a specific subtitle stream is requested");
+ }
}
}
@@ -1827,8 +1847,8 @@ namespace MediaBrowser.Model.Dlna
continue;
}
- // change from split by | to comma
- // strip spaces to avoid having to encode
+ // Change from split by | to comma
+ // Strip spaces to avoid having to encode
var values = value
.Split('|', StringSplitOptions.RemoveEmptyEntries);
diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs
index 5cfa2e7e3c..3b55099079 100644
--- a/MediaBrowser.Model/Dlna/StreamInfo.cs
+++ b/MediaBrowser.Model/Dlna/StreamInfo.cs
@@ -215,7 +215,7 @@ namespace MediaBrowser.Model.Dlna
var stream = TargetVideoStream;
return MaxFramerate.HasValue && !IsDirectStream
? MaxFramerate
- : stream == null ? null : stream.AverageFrameRate ?? stream.RealFrameRate;
+ : stream is null ? null : stream.AverageFrameRate ?? stream.RealFrameRate;
}
}
@@ -460,7 +460,7 @@ namespace MediaBrowser.Model.Dlna
return !IsDirectStream
? defaultValue
- : MediaSource == null ? defaultValue : MediaSource.Timestamp ?? TransportStreamTimestamp.None;
+ : MediaSource is null ? defaultValue : MediaSource.Timestamp ?? TransportStreamTimestamp.None;
}
}
@@ -521,7 +521,7 @@ namespace MediaBrowser.Model.Dlna
{
var videoStream = TargetVideoStream;
- if (videoStream != null && videoStream.Width.HasValue && videoStream.Height.HasValue)
+ if (videoStream is not null && videoStream.Width.HasValue && videoStream.Height.HasValue)
{
ImageDimensions size = new ImageDimensions(videoStream.Width.Value, videoStream.Height.Value);
@@ -540,7 +540,7 @@ namespace MediaBrowser.Model.Dlna
{
var videoStream = TargetVideoStream;
- if (videoStream != null && videoStream.Width.HasValue && videoStream.Height.HasValue)
+ if (videoStream is not null && videoStream.Width.HasValue && videoStream.Height.HasValue)
{
ImageDimensions size = new ImageDimensions(videoStream.Width.Value, videoStream.Height.Value);
@@ -620,10 +620,7 @@ namespace MediaBrowser.Model.Dlna
public string ToUrl(string baseUrl, string accessToken)
{
- if (string.IsNullOrEmpty(baseUrl))
- {
- throw new ArgumentNullException(nameof(baseUrl));
- }
+ ArgumentException.ThrowIfNullOrEmpty(baseUrl);
var list = new List<string>();
foreach (NameValuePair pair in BuildParams(this, accessToken))
@@ -664,10 +661,7 @@ namespace MediaBrowser.Model.Dlna
private string GetUrl(string baseUrl, string queryString)
{
- if (string.IsNullOrEmpty(baseUrl))
- {
- throw new ArgumentNullException(nameof(baseUrl));
- }
+ ArgumentException.ThrowIfNullOrEmpty(baseUrl);
string extension = string.IsNullOrEmpty(Container) ? string.Empty : "." + Container;
diff --git a/MediaBrowser.Model/Dlna/VideoOptions.cs b/MediaBrowser.Model/Dlna/VideoOptions.cs
deleted file mode 100644
index 0cb80af544..0000000000
--- a/MediaBrowser.Model/Dlna/VideoOptions.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-#pragma warning disable CS1591
-
-namespace MediaBrowser.Model.Dlna
-{
- /// <summary>
- /// Class VideoOptions.
- /// </summary>
- public class VideoOptions : AudioOptions
- {
- public int? AudioStreamIndex { get; set; }
-
- public int? SubtitleStreamIndex { get; set; }
-
- public bool AllowVideoStreamCopy { get; set; }
- }
-}
diff --git a/MediaBrowser.Model/Drawing/DrawingUtils.cs b/MediaBrowser.Model/Drawing/DrawingUtils.cs
index 5567927682..2040d26bbb 100644
--- a/MediaBrowser.Model/Drawing/DrawingUtils.cs
+++ b/MediaBrowser.Model/Drawing/DrawingUtils.cs
@@ -71,18 +71,18 @@ namespace MediaBrowser.Model.Drawing
int? fillHeight)
{
// Return original size if input is invalid.
- if ((fillWidth == null || fillWidth == 0)
- && (fillHeight == null || fillHeight == 0))
+ if ((fillWidth is null || fillWidth == 0)
+ && (fillHeight is null || fillHeight == 0))
{
return size;
}
- if (fillWidth == null || fillWidth == 0)
+ if (fillWidth is null || fillWidth == 0)
{
fillWidth = 1;
}
- if (fillHeight == null || fillHeight == 0)
+ if (fillHeight is null || fillHeight == 0)
{
fillHeight = 1;
}
diff --git a/MediaBrowser.Model/Drawing/ImageResolution.cs b/MediaBrowser.Model/Drawing/ImageResolution.cs
new file mode 100644
index 0000000000..34738b7990
--- /dev/null
+++ b/MediaBrowser.Model/Drawing/ImageResolution.cs
@@ -0,0 +1,52 @@
+namespace MediaBrowser.Model.Drawing;
+
+/// <summary>
+/// Enum ImageResolution.
+/// </summary>
+public enum ImageResolution
+{
+ /// <summary>
+ /// MatchSource.
+ /// </summary>
+ MatchSource = 0,
+
+ /// <summary>
+ /// 144p.
+ /// </summary>
+ P144 = 1,
+
+ /// <summary>
+ /// 240p.
+ /// </summary>
+ P240 = 2,
+
+ /// <summary>
+ /// 360p.
+ /// </summary>
+ P360 = 3,
+
+ /// <summary>
+ /// 480p.
+ /// </summary>
+ P480 = 4,
+
+ /// <summary>
+ /// 720p.
+ /// </summary>
+ P720 = 5,
+
+ /// <summary>
+ /// 1080p.
+ /// </summary>
+ P1080 = 6,
+
+ /// <summary>
+ /// 1440p.
+ /// </summary>
+ P1440 = 7,
+
+ /// <summary>
+ /// 2160p.
+ /// </summary>
+ P2160 = 8
+}
diff --git a/MediaBrowser.Model/Dto/BaseItemPerson.cs b/MediaBrowser.Model/Dto/BaseItemPerson.cs
index 6b920b0efb..9c65a2308d 100644
--- a/MediaBrowser.Model/Dto/BaseItemPerson.cs
+++ b/MediaBrowser.Model/Dto/BaseItemPerson.cs
@@ -52,6 +52,6 @@ namespace MediaBrowser.Model.Dto
/// </summary>
/// <value><c>true</c> if this instance has primary image; otherwise, <c>false</c>.</value>
[JsonIgnore]
- public bool HasPrimaryImage => PrimaryImageTag != null;
+ public bool HasPrimaryImage => PrimaryImageTag is not null;
}
}
diff --git a/MediaBrowser.Model/Dto/MediaSourceInfo.cs b/MediaBrowser.Model/Dto/MediaSourceInfo.cs
index c348e83ae5..520832aeee 100644
--- a/MediaBrowser.Model/Dto/MediaSourceInfo.cs
+++ b/MediaBrowser.Model/Dto/MediaSourceInfo.cs
@@ -134,7 +134,7 @@ namespace MediaBrowser.Model.Dto
public void InferTotalBitrate(bool force = false)
{
- if (MediaStreams == null)
+ if (MediaStreams is null)
{
return;
}
diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs
index 344ebaf808..47341f4e17 100644
--- a/MediaBrowser.Model/Entities/MediaStream.cs
+++ b/MediaBrowser.Model/Entities/MediaStream.cs
@@ -635,11 +635,12 @@ namespace MediaBrowser.Model.Entities
// sub = external .sub file
- return !codec.Contains("pgs", StringComparison.OrdinalIgnoreCase) &&
- !codec.Contains("dvd", StringComparison.OrdinalIgnoreCase) &&
- !codec.Contains("dvbsub", StringComparison.OrdinalIgnoreCase) &&
- !string.Equals(codec, "sub", StringComparison.OrdinalIgnoreCase) &&
- !string.Equals(codec, "dvb_subtitle", StringComparison.OrdinalIgnoreCase);
+ return !codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
+ && !codec.Contains("dvd", StringComparison.OrdinalIgnoreCase)
+ && !codec.Contains("dvbsub", StringComparison.OrdinalIgnoreCase)
+ && !string.Equals(codec, "sub", StringComparison.OrdinalIgnoreCase)
+ && !string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase)
+ && !string.Equals(codec, "dvb_subtitle", StringComparison.OrdinalIgnoreCase);
}
public bool SupportsSubtitleConversionTo(string toCodec)
diff --git a/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs b/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs
index d3b8400f34..cf453d62cb 100644
--- a/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs
+++ b/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs
@@ -55,7 +55,7 @@ namespace MediaBrowser.Model.Entities
{
ArgumentNullException.ThrowIfNull(instance);
- if (instance.ProviderIds == null)
+ if (instance.ProviderIds is null)
{
id = null;
return false;
diff --git a/MediaBrowser.Model/Extensions/EnumerableExtensions.cs b/MediaBrowser.Model/Extensions/EnumerableExtensions.cs
index a5a6b18aa8..c6d1f3900a 100644
--- a/MediaBrowser.Model/Extensions/EnumerableExtensions.cs
+++ b/MediaBrowser.Model/Extensions/EnumerableExtensions.cs
@@ -24,24 +24,27 @@ namespace MediaBrowser.Model.Extensions
requestedLanguage = "en";
}
- var isRequestedLanguageEn = string.Equals(requestedLanguage, "en", StringComparison.OrdinalIgnoreCase);
-
return remoteImageInfos.OrderByDescending(i =>
{
+ // Image priority ordering:
+ // - Images that match the requested language
+ // - Images with no language
+ // - TODO: Images that match the original language
+ // - Images in English
+ // - Images that don't match the requested language
+
if (string.Equals(requestedLanguage, i.Language, StringComparison.OrdinalIgnoreCase))
{
- return 3;
+ return 4;
}
if (string.IsNullOrEmpty(i.Language))
{
- // Assume empty image language is likely to be English.
- return isRequestedLanguageEn ? 3 : 2;
+ return 3;
}
- if (!isRequestedLanguageEn && string.Equals(i.Language, "en", StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(i.Language, "en", StringComparison.OrdinalIgnoreCase))
{
- // Prioritize English over non-requested languages.
return 2;
}
diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj
index 4172e9825e..284e89f1cb 100644
--- a/MediaBrowser.Model/MediaBrowser.Model.csproj
+++ b/MediaBrowser.Model/MediaBrowser.Model.csproj
@@ -14,7 +14,7 @@
</PropertyGroup>
<PropertyGroup>
- <TargetFramework>net6.0</TargetFramework>
+ <TargetFramework>net7.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
@@ -24,7 +24,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
- <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
+ <CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Stability)'=='Unstable'">
@@ -34,13 +34,13 @@
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
- <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.3" />
+ <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="MimeTypes" Version="2.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Globalization" Version="4.3.0" />
- <PackageReference Include="System.Text.Json" Version="6.0.7" />
+ <PackageReference Include="System.Text.Json" Version="7.0.1" />
</ItemGroup>
<ItemGroup>
diff --git a/MediaBrowser.Model/Net/MimeTypes.cs b/MediaBrowser.Model/Net/MimeTypes.cs
index 3b03466e9d..8157dc0c24 100644
--- a/MediaBrowser.Model/Net/MimeTypes.cs
+++ b/MediaBrowser.Model/Net/MimeTypes.cs
@@ -140,10 +140,7 @@ namespace MediaBrowser.Model.Net
[return: NotNullIfNotNull("defaultValue")]
public static string? GetMimeType(string filename, string? defaultValue = null)
{
- if (filename.Length == 0)
- {
- throw new ArgumentException("String can't be empty.", nameof(filename));
- }
+ ArgumentException.ThrowIfNullOrEmpty(filename);
var ext = Path.GetExtension(filename);
@@ -168,10 +165,7 @@ namespace MediaBrowser.Model.Net
public static string? ToExtension(string mimeType)
{
- if (mimeType.Length == 0)
- {
- throw new ArgumentException("String can't be empty.", nameof(mimeType));
- }
+ ArgumentException.ThrowIfNullOrEmpty(mimeType);
// handle text/html; charset=UTF-8
mimeType = mimeType.AsSpan().LeftPart(';').ToString();
diff --git a/MediaBrowser.Model/Notifications/NotificationOptions.cs b/MediaBrowser.Model/Notifications/NotificationOptions.cs
index d1b5491bd1..804f51e166 100644
--- a/MediaBrowser.Model/Notifications/NotificationOptions.cs
+++ b/MediaBrowser.Model/Notifications/NotificationOptions.cs
@@ -86,14 +86,14 @@ namespace MediaBrowser.Model.Notifications
{
NotificationOption opt = GetOptions(type);
- return opt != null && opt.Enabled;
+ return opt is not null && opt.Enabled;
}
public bool IsServiceEnabled(string service, string notificationType)
{
NotificationOption opt = GetOptions(notificationType);
- return opt == null
+ return opt is null
|| !opt.DisabledServices.Contains(service, StringComparison.OrdinalIgnoreCase);
}
@@ -101,7 +101,7 @@ namespace MediaBrowser.Model.Notifications
{
NotificationOption opt = GetOptions(type);
- return opt != null
+ return opt is not null
&& opt.Enabled
&& !opt.DisabledMonitorUsers.Contains(userId.ToString("N"), StringComparison.OrdinalIgnoreCase);
}
@@ -110,7 +110,7 @@ namespace MediaBrowser.Model.Notifications
{
NotificationOption opt = GetOptions(type);
- if (opt != null && opt.Enabled)
+ if (opt is not null && opt.Enabled)
{
if (opt.SendToUserMode == SendToUserType.All)
{
diff --git a/MediaBrowser.Model/Querying/ItemSortBy.cs b/MediaBrowser.Model/Querying/ItemSortBy.cs
index 470507c530..1a7c9a63b0 100644
--- a/MediaBrowser.Model/Querying/ItemSortBy.cs
+++ b/MediaBrowser.Model/Querying/ItemSortBy.cs
@@ -154,5 +154,10 @@ namespace MediaBrowser.Model.Querying
/// The similarity score.
/// </summary>
public const string SimilarityScore = "SimilarityScore";
+
+ /// <summary>
+ /// The search score.
+ /// </summary>
+ public const string SearchScore = "SearchScore";
}
}
diff --git a/MediaBrowser.Model/Updates/VersionInfo.cs b/MediaBrowser.Model/Updates/VersionInfo.cs
index 03a540dde2..320199f984 100644
--- a/MediaBrowser.Model/Updates/VersionInfo.cs
+++ b/MediaBrowser.Model/Updates/VersionInfo.cs
@@ -17,7 +17,7 @@ namespace MediaBrowser.Model.Updates
[JsonPropertyName("version")]
public string Version
{
- get => _version == null ? string.Empty : _version.ToString();
+ get => _version is null ? string.Empty : _version.ToString();
set => _version = SysVersion.Parse(value);
}