jellyfin-server/MediaBrowser.Model/Entities/MediaStream.cs

383 lines
12 KiB
C#
Raw Normal View History

2016-10-15 22:12:16 +00:00
using System;
using System.Collections.Generic;
2016-05-14 18:02:06 +00:00
using MediaBrowser.Model.Dlna;
2015-03-30 19:57:37 +00:00
using MediaBrowser.Model.Extensions;
using System.Diagnostics;
2016-05-18 21:46:56 +00:00
using MediaBrowser.Model.MediaInfo;
2014-01-12 06:31:21 +00:00
2013-02-21 01:33:05 +00:00
namespace MediaBrowser.Model.Entities
{
/// <summary>
/// Class MediaStream
/// </summary>
[DebuggerDisplay("StreamType = {Type}")]
2013-02-21 01:33:05 +00:00
public class MediaStream
{
/// <summary>
/// Gets or sets the codec.
/// </summary>
/// <value>The codec.</value>
public string Codec { get; set; }
2015-10-19 16:05:03 +00:00
/// <summary>
/// Gets or sets the codec tag.
/// </summary>
/// <value>The codec tag.</value>
public string CodecTag { get; set; }
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets or sets the language.
/// </summary>
/// <value>The language.</value>
public string Language { get; set; }
2016-01-11 16:52:22 +00:00
/// <summary>
/// Gets or sets the comment.
/// </summary>
/// <value>The comment.</value>
public string Comment { get; set; }
2016-04-18 03:50:44 +00:00
2016-06-06 21:13:00 +00:00
public string TimeBase { get; set; }
public string CodecTimeBase { get; set; }
2016-05-14 18:02:06 +00:00
public string Title { get; set; }
public string DisplayTitle
{
get
{
if (!string.IsNullOrEmpty(Title))
{
2016-10-15 22:12:16 +00:00
return AddLanguageIfNeeded(Title);
2016-05-14 18:02:06 +00:00
}
if (Type == MediaStreamType.Audio)
{
List<string> attributes = new List<string>();
if (!string.IsNullOrEmpty(Language))
{
2016-05-18 21:46:56 +00:00
attributes.Add(StringHelper.FirstToUpper(Language));
2016-05-14 18:02:06 +00:00
}
if (!string.IsNullOrEmpty(Codec) && !StringHelper.EqualsIgnoreCase(Codec, "dca"))
{
2016-05-18 21:46:56 +00:00
attributes.Add(AudioCodec.GetFriendlyName(Codec));
2016-05-18 18:23:46 +00:00
}
else if (!string.IsNullOrEmpty(Profile) && !StringHelper.EqualsIgnoreCase(Profile, "lc"))
2016-05-14 18:02:06 +00:00
{
attributes.Add(Profile);
}
2016-05-18 18:23:46 +00:00
if (!string.IsNullOrEmpty(ChannelLayout))
{
attributes.Add(ChannelLayout);
}
else if (Channels.HasValue)
2016-05-14 18:02:06 +00:00
{
attributes.Add(StringHelper.ToStringCultureInvariant(Channels.Value) + " ch");
}
if (IsDefault)
{
2016-06-18 17:27:13 +00:00
attributes.Add("Default");
2016-05-14 18:02:06 +00:00
}
return string.Join(" ", attributes.ToArray(attributes.Count));
2016-05-14 18:02:06 +00:00
}
if (Type == MediaStreamType.Subtitle)
{
List<string> attributes = new List<string>();
if (!string.IsNullOrEmpty(Language))
{
2016-05-22 15:26:47 +00:00
attributes.Add(StringHelper.FirstToUpper(Language));
2016-05-14 18:02:06 +00:00
}
2017-01-20 17:53:48 +00:00
else
{
attributes.Add("Und");
}
2016-05-14 18:02:06 +00:00
if (IsDefault)
{
2016-06-18 17:27:13 +00:00
attributes.Add("Default");
2016-05-14 18:02:06 +00:00
}
if (IsForced)
{
2016-06-18 17:27:13 +00:00
attributes.Add("Forced");
2016-05-14 18:02:06 +00:00
}
string name = string.Join(" ", attributes.ToArray(attributes.Count));
2016-05-14 18:02:06 +00:00
return name;
}
if (Type == MediaStreamType.Video)
{
}
return null;
}
}
2016-10-15 22:12:16 +00:00
private string AddLanguageIfNeeded(string title)
{
2016-12-03 07:58:48 +00:00
if (!string.IsNullOrEmpty(Language) &&
!string.Equals(Language, "und", StringComparison.OrdinalIgnoreCase) &&
!IsLanguageInTitle(title, Language))
2016-10-15 22:12:16 +00:00
{
title = StringHelper.FirstToUpper(Language) + " " + title;
}
return title;
}
2016-12-03 07:58:48 +00:00
private bool IsLanguageInTitle(string title, string language)
{
if (title.IndexOf(Language, StringComparison.OrdinalIgnoreCase) != -1)
{
return true;
}
return false;
}
2016-04-18 03:50:44 +00:00
public string NalLengthSize { get; set; }
2013-04-18 19:57:28 +00:00
/// <summary>
2013-12-06 03:39:44 +00:00
/// Gets or sets a value indicating whether this instance is interlaced.
2013-04-18 19:57:28 +00:00
/// </summary>
2013-12-06 03:39:44 +00:00
/// <value><c>true</c> if this instance is interlaced; otherwise, <c>false</c>.</value>
public bool IsInterlaced { get; set; }
2013-11-12 16:08:23 +00:00
2016-04-27 19:23:05 +00:00
public bool? IsAVC { get; set; }
2013-11-12 16:08:23 +00:00
/// <summary>
/// Gets or sets the channel layout.
/// </summary>
/// <value>The channel layout.</value>
public string ChannelLayout { get; set; }
2014-06-22 16:25:47 +00:00
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets or sets the bit rate.
/// </summary>
/// <value>The bit rate.</value>
public int? BitRate { get; set; }
2014-04-24 05:08:10 +00:00
/// <summary>
/// Gets or sets the bit depth.
/// </summary>
/// <value>The bit depth.</value>
public int? BitDepth { get; set; }
2014-09-09 01:15:31 +00:00
/// <summary>
/// Gets or sets the reference frames.
/// </summary>
/// <value>The reference frames.</value>
public int? RefFrames { get; set; }
2014-04-24 05:08:10 +00:00
/// <summary>
/// Gets or sets the length of the packet.
/// </summary>
/// <value>The length of the packet.</value>
public int? PacketLength { get; set; }
2015-04-10 19:08:09 +00:00
2013-02-21 01:33:05 +00:00
/// <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; }
2015-03-31 16:24:16 +00:00
/// <summary>
/// Gets or sets the score.
/// </summary>
/// <value>The score.</value>
public int? Score { get; set; }
2015-04-02 02:47:59 +00:00
2013-02-21 01:33:05 +00:00
/// <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; }
2015-03-30 19:57:37 +00:00
/// <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; }
2015-04-02 02:47:59 +00:00
/// <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; }
2015-03-30 19:57:37 +00:00
2014-06-11 20:57:18 +00:00
public bool IsTextSubtitleStream
{
get
{
2014-06-11 20:57:18 +00:00
if (Type != MediaStreamType.Subtitle) return false;
2015-03-28 20:22:27 +00:00
if (string.IsNullOrEmpty(Codec) && !IsExternal)
{
return false;
}
2015-02-02 18:14:02 +00:00
return IsTextFormat(Codec);
}
}
2015-02-02 18:14:02 +00:00
public static bool IsTextFormat(string format)
{
string codec = format ?? string.Empty;
// sub = external .sub file
return StringHelper.IndexOfIgnoreCase(codec, "pgs") == -1 &&
StringHelper.IndexOfIgnoreCase(codec, "dvd") == -1 &&
2016-01-23 01:35:43 +00:00
StringHelper.IndexOfIgnoreCase(codec, "dvbsub") == -1 &&
2016-10-29 17:58:08 +00:00
!StringHelper.EqualsIgnoreCase(codec, "sub") &&
!StringHelper.EqualsIgnoreCase(codec, "dvb_subtitle");
2015-02-02 18:14:02 +00:00
}
2014-06-11 20:57:18 +00:00
2017-01-29 20:00:29 +00:00
public bool SupportsSubtitleConversionTo(string toCodec)
2016-06-25 05:16:54 +00:00
{
if (!IsTextSubtitleStream)
{
return false;
}
2017-01-29 20:00:29 +00:00
var fromCodec = Codec;
2016-06-25 05:16:54 +00:00
// Can't convert from this
2017-01-29 20:00:29 +00:00
if (StringHelper.EqualsIgnoreCase(fromCodec, "ass"))
2016-06-25 05:16:54 +00:00
{
return false;
}
2017-01-29 20:00:29 +00:00
if (StringHelper.EqualsIgnoreCase(fromCodec, "ssa"))
2016-06-25 05:16:54 +00:00
{
return false;
}
// Can't convert to this
2017-01-29 20:00:29 +00:00
if (StringHelper.EqualsIgnoreCase(toCodec, "ass"))
2016-06-25 05:16:54 +00:00
{
return false;
}
2017-01-29 20:00:29 +00:00
if (StringHelper.EqualsIgnoreCase(toCodec, "ssa"))
2016-06-25 05:16:54 +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; }
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets or sets the filename.
/// </summary>
/// <value>The filename.</value>
public string Path { get; set; }
2013-04-03 12:03:37 +00:00
2015-03-28 02:19:20 +00:00
/// <summary>
/// Gets or sets the external identifier.
/// </summary>
/// <value>The external identifier.</value>
public string ExternalId { get; set; }
2013-04-03 12:03:37 +00:00
/// <summary>
2014-03-26 19:21:29 +00:00
/// Gets or sets the pixel format.
/// </summary>
/// <value>The pixel format.</value>
public string PixelFormat { get; set; }
2014-06-22 16:25:47 +00:00
2014-03-26 19:21:29 +00:00
/// <summary>
2013-04-03 12:03:37 +00:00
/// Gets or sets the level.
/// </summary>
/// <value>The level.</value>
2013-04-03 22:45:04 +00:00
public double? Level { get; set; }
2014-06-22 16:25:47 +00:00
/// <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; }
2013-02-21 01:33:05 +00:00
}
}