2020-02-04 00:49:27 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
#pragma warning disable SA1600
|
|
|
|
|
2019-01-13 20:02:23 +00:00
|
|
|
using System;
|
2018-12-27 23:27:57 +00:00
|
|
|
using System.Collections.Generic;
|
2019-01-13 19:26:15 +00:00
|
|
|
using System.Globalization;
|
2019-03-14 21:31:51 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
2018-12-27 23:27:57 +00:00
|
|
|
using MediaBrowser.Model.Dlna;
|
|
|
|
using MediaBrowser.Model.Extensions;
|
|
|
|
using MediaBrowser.Model.MediaInfo;
|
|
|
|
|
|
|
|
namespace MediaBrowser.Model.Entities
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Class MediaStream
|
|
|
|
/// </summary>
|
|
|
|
public class MediaStream
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the codec.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The codec.</value>
|
|
|
|
public string Codec { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the codec tag.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The codec tag.</value>
|
|
|
|
public string CodecTag { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the language.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The language.</value>
|
|
|
|
public string Language { get; set; }
|
|
|
|
|
|
|
|
public string ColorTransfer { get; set; }
|
|
|
|
public string ColorPrimaries { get; set; }
|
|
|
|
public string ColorSpace { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the comment.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The comment.</value>
|
|
|
|
public string Comment { get; set; }
|
|
|
|
|
|
|
|
public string TimeBase { get; set; }
|
|
|
|
public string CodecTimeBase { get; set; }
|
|
|
|
|
|
|
|
public string Title { get; set; }
|
|
|
|
|
|
|
|
public string VideoRange
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (Type != MediaStreamType.Video)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var colorTransfer = ColorTransfer;
|
|
|
|
|
|
|
|
if (string.Equals(colorTransfer, "smpte2084", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return "HDR";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "SDR";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-14 21:31:51 +00:00
|
|
|
public string localizedUndefined { get; set; }
|
|
|
|
public string localizedDefault { get; set; }
|
|
|
|
public string localizedForced { get; set; }
|
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
public string DisplayTitle
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (Type == MediaStreamType.Audio)
|
|
|
|
{
|
|
|
|
//if (!string.IsNullOrEmpty(Title))
|
|
|
|
//{
|
|
|
|
// return AddLanguageIfNeeded(Title);
|
|
|
|
//}
|
|
|
|
|
2019-01-13 20:37:13 +00:00
|
|
|
var attributes = new List<string>();
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Language))
|
|
|
|
{
|
|
|
|
attributes.Add(StringHelper.FirstToUpper(Language));
|
|
|
|
}
|
2020-01-09 16:07:13 +00:00
|
|
|
if (!string.IsNullOrEmpty(Codec) && !string.Equals(Codec, "dca", StringComparison.OrdinalIgnoreCase))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
attributes.Add(AudioCodec.GetFriendlyName(Codec));
|
|
|
|
}
|
2020-01-09 16:07:13 +00:00
|
|
|
else if (!string.IsNullOrEmpty(Profile) && !string.Equals(Profile, "lc", StringComparison.OrdinalIgnoreCase))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
attributes.Add(Profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(ChannelLayout))
|
|
|
|
{
|
|
|
|
attributes.Add(ChannelLayout);
|
|
|
|
}
|
|
|
|
else if (Channels.HasValue)
|
|
|
|
{
|
|
|
|
attributes.Add(Channels.Value.ToString(CultureInfo.InvariantCulture) + " ch");
|
|
|
|
}
|
|
|
|
if (IsDefault)
|
|
|
|
{
|
|
|
|
attributes.Add("Default");
|
|
|
|
}
|
|
|
|
|
2019-01-27 11:03:43 +00:00
|
|
|
return string.Join(" ", attributes);
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Type == MediaStreamType.Video)
|
|
|
|
{
|
2019-01-13 20:37:13 +00:00
|
|
|
var attributes = new List<string>();
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
var resolutionText = GetResolutionText();
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(resolutionText))
|
|
|
|
{
|
|
|
|
attributes.Add(resolutionText);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Codec))
|
|
|
|
{
|
2019-01-27 11:03:43 +00:00
|
|
|
attributes.Add(Codec.ToUpperInvariant());
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 11:03:43 +00:00
|
|
|
return string.Join(" ", attributes);
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Type == MediaStreamType.Subtitle)
|
|
|
|
{
|
|
|
|
|
2019-01-13 20:37:13 +00:00
|
|
|
var attributes = new List<string>();
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Language))
|
|
|
|
{
|
|
|
|
attributes.Add(StringHelper.FirstToUpper(Language));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-14 21:31:51 +00:00
|
|
|
attributes.Add(string.IsNullOrEmpty(localizedUndefined) ? "Und" : localizedUndefined);
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsDefault)
|
|
|
|
{
|
2019-03-14 21:31:51 +00:00
|
|
|
attributes.Add(string.IsNullOrEmpty(localizedDefault) ? "Default" : localizedDefault);
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsForced)
|
|
|
|
{
|
2019-03-14 21:31:51 +00:00
|
|
|
attributes.Add(string.IsNullOrEmpty(localizedForced) ? "Forced" : localizedForced);
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 21:31:51 +00:00
|
|
|
if (!string.IsNullOrEmpty(Title))
|
|
|
|
{
|
|
|
|
return attributes.AsEnumerable()
|
|
|
|
// keep Tags that are not already in Title
|
|
|
|
.Where(tag => Title.IndexOf(tag, StringComparison.OrdinalIgnoreCase) == -1)
|
|
|
|
// attributes concatenation, starting with Title
|
|
|
|
.Aggregate(new StringBuilder(Title), (builder, attr) => builder.Append(" - ").Append(attr))
|
|
|
|
.ToString();
|
|
|
|
}
|
2018-12-27 23:27:57 +00:00
|
|
|
|
2019-03-14 21:31:51 +00:00
|
|
|
return string.Join(" - ", attributes.ToArray());
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Type == MediaStreamType.Video)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private string GetResolutionText()
|
|
|
|
{
|
|
|
|
var i = this;
|
|
|
|
|
|
|
|
if (i.Width.HasValue && i.Height.HasValue)
|
|
|
|
{
|
|
|
|
var width = i.Width.Value;
|
|
|
|
var height = i.Height.Value;
|
|
|
|
|
|
|
|
if (width >= 3800 || height >= 2000)
|
|
|
|
{
|
|
|
|
return "4K";
|
|
|
|
}
|
|
|
|
if (width >= 2500)
|
|
|
|
{
|
|
|
|
if (i.IsInterlaced)
|
|
|
|
{
|
|
|
|
return "1440I";
|
|
|
|
}
|
|
|
|
return "1440P";
|
|
|
|
}
|
|
|
|
if (width >= 1900 || height >= 1000)
|
|
|
|
{
|
|
|
|
if (i.IsInterlaced)
|
|
|
|
{
|
|
|
|
return "1080I";
|
|
|
|
}
|
|
|
|
return "1080P";
|
|
|
|
}
|
|
|
|
if (width >= 1260 || height >= 700)
|
|
|
|
{
|
|
|
|
if (i.IsInterlaced)
|
|
|
|
{
|
|
|
|
return "720I";
|
|
|
|
}
|
|
|
|
return "720P";
|
|
|
|
}
|
|
|
|
if (width >= 700 || height >= 440)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (i.IsInterlaced)
|
|
|
|
{
|
|
|
|
return "480I";
|
|
|
|
}
|
|
|
|
return "480P";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "SD";
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string NalLengthSize { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value indicating whether this instance is interlaced.
|
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if this instance is interlaced; otherwise, <c>false</c>.</value>
|
|
|
|
public bool IsInterlaced { get; set; }
|
|
|
|
|
|
|
|
public bool? IsAVC { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the channel layout.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The channel layout.</value>
|
|
|
|
public string ChannelLayout { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the bit rate.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The bit rate.</value>
|
|
|
|
public int? BitRate { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the bit depth.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The bit depth.</value>
|
|
|
|
public int? BitDepth { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the reference frames.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The reference frames.</value>
|
|
|
|
public int? RefFrames { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the length of the packet.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The length of the packet.</value>
|
|
|
|
public int? PacketLength { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the channels.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The channels.</value>
|
|
|
|
public int? Channels { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the sample rate.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The sample rate.</value>
|
|
|
|
public int? SampleRate { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value indicating whether this instance is default.
|
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if this instance is default; otherwise, <c>false</c>.</value>
|
|
|
|
public bool IsDefault { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value indicating whether this instance is forced.
|
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if this instance is forced; otherwise, <c>false</c>.</value>
|
|
|
|
public bool IsForced { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the height.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The height.</value>
|
|
|
|
public int? Height { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the width.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The width.</value>
|
|
|
|
public int? Width { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the average frame rate.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The average frame rate.</value>
|
|
|
|
public float? AverageFrameRate { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the real frame rate.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The real frame rate.</value>
|
|
|
|
public float? RealFrameRate { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the profile.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The profile.</value>
|
|
|
|
public string Profile { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the type.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The type.</value>
|
|
|
|
public MediaStreamType Type { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the aspect ratio.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The aspect ratio.</value>
|
|
|
|
public string AspectRatio { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the index.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The index.</value>
|
|
|
|
public int Index { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the score.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The score.</value>
|
|
|
|
public int? Score { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value indicating whether this instance is external.
|
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if this instance is external; otherwise, <c>false</c>.</value>
|
|
|
|
public bool IsExternal { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the method.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The method.</value>
|
|
|
|
public SubtitleDeliveryMethod? DeliveryMethod { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the delivery URL.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The delivery URL.</value>
|
|
|
|
public string DeliveryUrl { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value indicating whether this instance is external URL.
|
|
|
|
/// </summary>
|
|
|
|
/// <value><c>null</c> if [is external URL] contains no value, <c>true</c> if [is external URL]; otherwise, <c>false</c>.</value>
|
|
|
|
public bool? IsExternalUrl { get; set; }
|
|
|
|
|
|
|
|
public bool IsTextSubtitleStream
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (Type != MediaStreamType.Subtitle) return false;
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(Codec) && !IsExternal)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IsTextFormat(Codec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsTextFormat(string format)
|
|
|
|
{
|
|
|
|
string codec = format ?? string.Empty;
|
|
|
|
|
|
|
|
// sub = external .sub file
|
|
|
|
|
|
|
|
return codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) == -1 &&
|
|
|
|
codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) == -1 &&
|
|
|
|
codec.IndexOf("dvbsub", StringComparison.OrdinalIgnoreCase) == -1 &&
|
2020-01-09 16:07:13 +00:00
|
|
|
!string.Equals(codec, "sub", StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
!string.Equals(codec, "dvb_subtitle", StringComparison.OrdinalIgnoreCase);
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool SupportsSubtitleConversionTo(string toCodec)
|
|
|
|
{
|
|
|
|
if (!IsTextSubtitleStream)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var fromCodec = Codec;
|
|
|
|
|
2019-01-07 23:27:46 +00:00
|
|
|
// Can't convert from this
|
2020-01-09 16:07:13 +00:00
|
|
|
if (string.Equals(fromCodec, "ass", StringComparison.OrdinalIgnoreCase))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-09 16:07:13 +00:00
|
|
|
if (string.Equals(fromCodec, "ssa", StringComparison.OrdinalIgnoreCase))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:27:46 +00:00
|
|
|
// Can't convert to this
|
2020-01-09 16:07:13 +00:00
|
|
|
if (string.Equals(toCodec, "ass", StringComparison.OrdinalIgnoreCase))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-09 16:07:13 +00:00
|
|
|
if (string.Equals(toCodec, "ssa", StringComparison.OrdinalIgnoreCase))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value indicating whether [supports external stream].
|
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if [supports external stream]; otherwise, <c>false</c>.</value>
|
|
|
|
public bool SupportsExternalStream { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the filename.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The filename.</value>
|
|
|
|
public string Path { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the pixel format.
|
|
|
|
/// </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; }
|
|
|
|
}
|
|
|
|
}
|