jellyfin/MediaBrowser.Model/Dlna/DeviceProfile.cs

512 lines
17 KiB
C#
Raw Normal View History

#nullable disable
2020-09-13 05:49:11 -07:00
#pragma warning disable CA1819 // Properties should not return arrays
using System;
2020-05-01 07:48:33 -07:00
using System.Linq;
2018-12-27 16:27:57 -07:00
using System.Xml.Serialization;
using MediaBrowser.Model.MediaInfo;
2018-12-27 16:27:57 -07:00
namespace MediaBrowser.Model.Dlna
{
2020-09-13 05:49:11 -07:00
/// <summary>
/// Defines the <see cref="DeviceProfile" />.
/// </summary>
2018-12-27 16:27:57 -07:00
[XmlRoot("Profile")]
public class DeviceProfile
{
/// <summary>
2020-09-13 05:49:11 -07:00
/// Initializes a new instance of the <see cref="DeviceProfile"/> class.
/// </summary>
public DeviceProfile()
{
DirectPlayProfiles = Array.Empty<DirectPlayProfile>();
TranscodingProfiles = Array.Empty<TranscodingProfile>();
ResponseProfiles = Array.Empty<ResponseProfile>();
CodecProfiles = Array.Empty<CodecProfile>();
ContainerProfiles = Array.Empty<ContainerProfile>();
SubtitleProfiles = Array.Empty<SubtitleProfile>();
XmlRootAttributes = Array.Empty<XmlAttribute>();
SupportedMediaTypes = "Audio,Photo,Video";
MaxStreamingBitrate = 8000000;
MaxStaticBitrate = 8000000;
MusicStreamingTranscodingBitrate = 128000;
}
/// <summary>
/// Gets or sets the Name.
2018-12-27 16:27:57 -07:00
/// </summary>
public string Name { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the Id.
/// </summary>
2018-12-27 16:27:57 -07:00
[XmlIgnore]
public string Id { get; set; }
/// <summary>
2020-09-13 05:49:11 -07:00
/// Gets or sets the Identification.
2018-12-27 16:27:57 -07:00
/// </summary>
2019-01-13 13:37:13 -07:00
public DeviceIdentification Identification { get; set; }
2018-12-27 16:27:57 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the FriendlyName.
/// </summary>
2018-12-27 16:27:57 -07:00
public string FriendlyName { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the Manufacturer.
/// </summary>
2018-12-27 16:27:57 -07:00
public string Manufacturer { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the ManufacturerUrl.
/// </summary>
2018-12-27 16:27:57 -07:00
public string ManufacturerUrl { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the ModelName.
/// </summary>
2018-12-27 16:27:57 -07:00
public string ModelName { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the ModelDescription.
/// </summary>
2018-12-27 16:27:57 -07:00
public string ModelDescription { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the ModelNumber.
/// </summary>
2018-12-27 16:27:57 -07:00
public string ModelNumber { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the ModelUrl.
/// </summary>
2018-12-27 16:27:57 -07:00
public string ModelUrl { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the SerialNumber.
/// </summary>
2018-12-27 16:27:57 -07:00
public string SerialNumber { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets a value indicating whether EnableAlbumArtInDidl.
/// </summary>
2018-12-27 16:27:57 -07:00
public bool EnableAlbumArtInDidl { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets a value indicating whether EnableSingleAlbumArtLimit.
/// </summary>
2018-12-27 16:27:57 -07:00
public bool EnableSingleAlbumArtLimit { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets a value indicating whether EnableSingleSubtitleLimit.
/// </summary>
2018-12-27 16:27:57 -07:00
public bool EnableSingleSubtitleLimit { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the SupportedMediaTypes.
/// </summary>
2018-12-27 16:27:57 -07:00
public string SupportedMediaTypes { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the UserId.
/// </summary>
2018-12-27 16:27:57 -07:00
public string UserId { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the AlbumArtPn.
/// </summary>
2018-12-27 16:27:57 -07:00
public string AlbumArtPn { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the MaxAlbumArtWidth.
/// </summary>
2018-12-27 16:27:57 -07:00
public int MaxAlbumArtWidth { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the MaxAlbumArtHeight.
/// </summary>
2018-12-27 16:27:57 -07:00
public int MaxAlbumArtHeight { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the MaxIconWidth.
/// </summary>
2018-12-27 16:27:57 -07:00
public int? MaxIconWidth { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the MaxIconHeight.
/// </summary>
2018-12-27 16:27:57 -07:00
public int? MaxIconHeight { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the MaxStreamingBitrate.
/// </summary>
public int? MaxStreamingBitrate { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the MaxStaticBitrate.
/// </summary>
public int? MaxStaticBitrate { get; set; }
2018-12-27 16:27:57 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the MusicStreamingTranscodingBitrate.
/// </summary>
2018-12-27 16:27:57 -07:00
public int? MusicStreamingTranscodingBitrate { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the MaxStaticMusicBitrate.
/// </summary>
2018-12-27 16:27:57 -07:00
public int? MaxStaticMusicBitrate { get; set; }
/// <summary>
2020-09-13 05:49:11 -07:00
/// Gets or sets the content of the aggregationFlags element in the urn:schemas-sonycom:av namespace.
2018-12-27 16:27:57 -07:00
/// </summary>
public string SonyAggregationFlags { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the ProtocolInfo.
/// </summary>
2018-12-27 16:27:57 -07:00
public string ProtocolInfo { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the TimelineOffsetSeconds.
/// </summary>
2018-12-27 16:27:57 -07:00
public int TimelineOffsetSeconds { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets a value indicating whether RequiresPlainVideoItems.
/// </summary>
2018-12-27 16:27:57 -07:00
public bool RequiresPlainVideoItems { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets a value indicating whether RequiresPlainFolders.
/// </summary>
2018-12-27 16:27:57 -07:00
public bool RequiresPlainFolders { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets a value indicating whether EnableMSMediaReceiverRegistrar.
/// </summary>
2018-12-27 16:27:57 -07:00
public bool EnableMSMediaReceiverRegistrar { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets a value indicating whether IgnoreTranscodeByteRangeRequests.
/// </summary>
2018-12-27 16:27:57 -07:00
public bool IgnoreTranscodeByteRangeRequests { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the XmlRootAttributes.
/// </summary>
2018-12-27 16:27:57 -07:00
public XmlAttribute[] XmlRootAttributes { get; set; }
/// <summary>
/// Gets or sets the direct play profiles.
/// </summary>
public DirectPlayProfile[] DirectPlayProfiles { get; set; }
/// <summary>
/// Gets or sets the transcoding profiles.
/// </summary>
public TranscodingProfile[] TranscodingProfiles { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the ContainerProfiles.
/// </summary>
2018-12-27 16:27:57 -07:00
public ContainerProfile[] ContainerProfiles { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the CodecProfiles.
/// </summary>
2018-12-27 16:27:57 -07:00
public CodecProfile[] CodecProfiles { get; set; }
2020-06-15 14:43:52 -07:00
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the ResponseProfiles.
/// </summary>
2018-12-27 16:27:57 -07:00
public ResponseProfile[] ResponseProfiles { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets or sets the SubtitleProfiles.
/// </summary>
2018-12-27 16:27:57 -07:00
public SubtitleProfile[] SubtitleProfiles { get; set; }
2020-09-13 05:49:11 -07:00
/// <summary>
/// The GetSupportedMediaTypes.
/// </summary>
/// <returns>The .</returns>
2018-12-27 16:27:57 -07:00
public string[] GetSupportedMediaTypes()
{
return ContainerProfile.SplitValue(SupportedMediaTypes);
}
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets the audio transcoding profile.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="audioCodec">The audio Codec.</param>
/// <returns>A <see cref="TranscodingProfile"/>.</returns>
2018-12-27 16:27:57 -07:00
public TranscodingProfile GetAudioTranscodingProfile(string container, string audioCodec)
{
container = (container ?? string.Empty).TrimStart('.');
foreach (var i in TranscodingProfiles)
{
if (i.Type != MediaBrowser.Model.Dlna.DlnaProfileType.Audio)
{
continue;
}
2020-01-09 09:07:13 -07:00
if (!string.Equals(container, i.Container, StringComparison.OrdinalIgnoreCase))
2018-12-27 16:27:57 -07:00
{
continue;
}
2020-05-01 07:48:33 -07:00
if (!i.GetAudioCodecs().Contains(audioCodec ?? string.Empty, StringComparer.OrdinalIgnoreCase))
2018-12-27 16:27:57 -07:00
{
continue;
}
return i;
}
2020-05-01 07:48:33 -07:00
2018-12-27 16:27:57 -07:00
return null;
}
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets the video transcoding profile.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="audioCodec">The audio Codec.</param>
/// <param name="videoCodec">The video Codec.</param>
/// <returns>The <see cref="TranscodingProfile"/>.</returns>
2018-12-27 16:27:57 -07:00
public TranscodingProfile GetVideoTranscodingProfile(string container, string audioCodec, string videoCodec)
{
container = (container ?? string.Empty).TrimStart('.');
foreach (var i in TranscodingProfiles)
{
if (i.Type != MediaBrowser.Model.Dlna.DlnaProfileType.Video)
{
continue;
}
2020-01-09 09:07:13 -07:00
if (!string.Equals(container, i.Container, StringComparison.OrdinalIgnoreCase))
2018-12-27 16:27:57 -07:00
{
continue;
}
2020-05-01 07:48:33 -07:00
if (!i.GetAudioCodecs().Contains(audioCodec ?? string.Empty, StringComparer.OrdinalIgnoreCase))
2018-12-27 16:27:57 -07:00
{
continue;
}
2020-01-09 09:07:13 -07:00
if (!string.Equals(videoCodec, i.VideoCodec ?? string.Empty, StringComparison.OrdinalIgnoreCase))
2018-12-27 16:27:57 -07:00
{
continue;
}
return i;
}
2020-06-15 14:43:52 -07:00
2018-12-27 16:27:57 -07:00
return null;
}
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets the audio media profile.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="audioCodec">The audio codec.</param>
/// <param name="audioChannels">The audio channels.</param>
/// <param name="audioBitrate">The audio bitrate.</param>
/// <param name="audioSampleRate">The audio sample rate.</param>
/// <param name="audioBitDepth">The audio bit depth.</param>
/// <returns>The <see cref="ResponseProfile"/>.</returns>
2018-12-27 16:27:57 -07:00
public ResponseProfile GetAudioMediaProfile(string container, string audioCodec, int? audioChannels, int? audioBitrate, int? audioSampleRate, int? audioBitDepth)
{
foreach (var i in ResponseProfiles)
{
if (i.Type != DlnaProfileType.Audio)
{
continue;
}
if (!ContainerProfile.ContainsContainer(i.GetContainers(), container))
{
continue;
}
var audioCodecs = i.GetAudioCodecs();
2020-05-01 07:48:33 -07:00
if (audioCodecs.Length > 0 && !audioCodecs.Contains(audioCodec ?? string.Empty, StringComparer.OrdinalIgnoreCase))
2018-12-27 16:27:57 -07:00
{
continue;
}
var anyOff = false;
foreach (ProfileCondition c in i.Conditions)
2018-12-27 16:27:57 -07:00
{
2019-01-20 03:34:33 -07:00
if (!ConditionProcessor.IsAudioConditionSatisfied(GetModelProfileCondition(c), audioChannels, audioBitrate, audioSampleRate, audioBitDepth))
2018-12-27 16:27:57 -07:00
{
anyOff = true;
break;
}
}
if (anyOff)
{
continue;
}
return i;
}
2020-06-15 14:43:52 -07:00
2018-12-27 16:27:57 -07:00
return null;
}
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets the model profile condition.
/// </summary>
/// <param name="c">The c<see cref="ProfileCondition"/>.</param>
/// <returns>The <see cref="ProfileCondition"/>.</returns>
2018-12-27 16:27:57 -07:00
private ProfileCondition GetModelProfileCondition(ProfileCondition c)
{
return new ProfileCondition
{
Condition = c.Condition,
IsRequired = c.IsRequired,
Property = c.Property,
Value = c.Value
};
}
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets the image media profile.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <returns>The <see cref="ResponseProfile"/>.</returns>
2018-12-27 16:27:57 -07:00
public ResponseProfile GetImageMediaProfile(string container, int? width, int? height)
{
foreach (var i in ResponseProfiles)
{
if (i.Type != DlnaProfileType.Photo)
{
continue;
}
if (!ContainerProfile.ContainsContainer(i.GetContainers(), container))
{
continue;
}
var anyOff = false;
2019-01-13 13:37:13 -07:00
foreach (var c in i.Conditions)
2018-12-27 16:27:57 -07:00
{
2019-01-20 03:34:33 -07:00
if (!ConditionProcessor.IsImageConditionSatisfied(GetModelProfileCondition(c), width, height))
2018-12-27 16:27:57 -07:00
{
anyOff = true;
break;
}
}
if (anyOff)
{
continue;
}
return i;
}
2020-06-15 14:43:52 -07:00
2018-12-27 16:27:57 -07:00
return null;
}
2020-09-13 05:49:11 -07:00
/// <summary>
/// Gets the video media profile.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="audioCodec">The audio codec.</param>
/// <param name="videoCodec">The video codec.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="bitDepth">The bit depth.</param>
/// <param name="videoBitrate">The video bitrate.</param>
/// <param name="videoProfile">The video profile.</param>
/// <param name="videoLevel">The video level.</param>
/// <param name="videoFramerate">The video framerate.</param>
/// <param name="packetLength">The packet length.</param>
/// <param name="timestamp">The timestamp<see cref="TransportStreamTimestamp"/>.</param>
/// <param name="isAnamorphic">True if anamorphic.</param>
/// <param name="isInterlaced">True if interlaced.</param>
/// <param name="refFrames">The ref 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">True if Avc.</param>
/// <returns>The <see cref="ResponseProfile"/>.</returns>
public ResponseProfile GetVideoMediaProfile(
string container,
2018-12-27 16:27:57 -07:00
string audioCodec,
string videoCodec,
int? width,
int? height,
int? bitDepth,
int? videoBitrate,
string videoProfile,
double? videoLevel,
float? videoFramerate,
int? packetLength,
TransportStreamTimestamp timestamp,
bool? isAnamorphic,
bool? isInterlaced,
int? refFrames,
int? numVideoStreams,
int? numAudioStreams,
string videoCodecTag,
bool? isAvc)
{
foreach (var i in ResponseProfiles)
{
if (i.Type != DlnaProfileType.Video)
{
continue;
}
if (!ContainerProfile.ContainsContainer(i.GetContainers(), container))
{
continue;
}
var audioCodecs = i.GetAudioCodecs();
2020-05-01 07:48:33 -07:00
if (audioCodecs.Length > 0 && !audioCodecs.Contains(audioCodec ?? string.Empty, StringComparer.OrdinalIgnoreCase))
2018-12-27 16:27:57 -07:00
{
continue;
}
var videoCodecs = i.GetVideoCodecs();
2020-05-01 07:48:33 -07:00
if (videoCodecs.Length > 0 && !videoCodecs.Contains(videoCodec ?? string.Empty, StringComparer.OrdinalIgnoreCase))
2018-12-27 16:27:57 -07:00
{
continue;
}
var anyOff = false;
foreach (ProfileCondition c in i.Conditions)
2018-12-27 16:27:57 -07:00
{
2019-01-20 03:34:33 -07:00
if (!ConditionProcessor.IsVideoConditionSatisfied(GetModelProfileCondition(c), width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, isInterlaced, refFrames, numVideoStreams, numAudioStreams, videoCodecTag, isAvc))
2018-12-27 16:27:57 -07:00
{
anyOff = true;
break;
}
}
if (anyOff)
{
continue;
}
return i;
}
2020-06-15 14:43:52 -07:00
2018-12-27 16:27:57 -07:00
return null;
}
}
}