MediaStream.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. using System;
  2. using System.Collections.Generic;
  3. using MediaBrowser.Model.Dlna;
  4. using MediaBrowser.Model.Extensions;
  5. using System.Diagnostics;
  6. using MediaBrowser.Model.MediaInfo;
  7. namespace MediaBrowser.Model.Entities
  8. {
  9. /// <summary>
  10. /// Class MediaStream
  11. /// </summary>
  12. [DebuggerDisplay("StreamType = {Type}")]
  13. public class MediaStream
  14. {
  15. /// <summary>
  16. /// Gets or sets the codec.
  17. /// </summary>
  18. /// <value>The codec.</value>
  19. public string Codec { get; set; }
  20. /// <summary>
  21. /// Gets or sets the codec tag.
  22. /// </summary>
  23. /// <value>The codec tag.</value>
  24. public string CodecTag { get; set; }
  25. /// <summary>
  26. /// Gets or sets the language.
  27. /// </summary>
  28. /// <value>The language.</value>
  29. public string Language { get; set; }
  30. /// <summary>
  31. /// Gets or sets the comment.
  32. /// </summary>
  33. /// <value>The comment.</value>
  34. public string Comment { get; set; }
  35. public string TimeBase { get; set; }
  36. public string CodecTimeBase { get; set; }
  37. public string Title { get; set; }
  38. public string DisplayTitle
  39. {
  40. get
  41. {
  42. if (!string.IsNullOrEmpty(Title))
  43. {
  44. return AddLanguageIfNeeded(Title);
  45. }
  46. if (Type == MediaStreamType.Audio)
  47. {
  48. List<string> attributes = new List<string>();
  49. if (!string.IsNullOrEmpty(Language))
  50. {
  51. attributes.Add(StringHelper.FirstToUpper(Language));
  52. }
  53. if (!string.IsNullOrEmpty(Codec) && !StringHelper.EqualsIgnoreCase(Codec, "dca"))
  54. {
  55. attributes.Add(AudioCodec.GetFriendlyName(Codec));
  56. }
  57. else if (!string.IsNullOrEmpty(Profile) && !StringHelper.EqualsIgnoreCase(Profile, "lc"))
  58. {
  59. attributes.Add(Profile);
  60. }
  61. if (!string.IsNullOrEmpty(ChannelLayout))
  62. {
  63. attributes.Add(ChannelLayout);
  64. }
  65. else if (Channels.HasValue)
  66. {
  67. attributes.Add(StringHelper.ToStringCultureInvariant(Channels.Value) + " ch");
  68. }
  69. if (IsDefault)
  70. {
  71. attributes.Add("Default");
  72. }
  73. return string.Join(" ", attributes.ToArray());
  74. }
  75. if (Type == MediaStreamType.Subtitle)
  76. {
  77. List<string> attributes = new List<string>();
  78. if (!string.IsNullOrEmpty(Language))
  79. {
  80. attributes.Add(StringHelper.FirstToUpper(Language));
  81. }
  82. else
  83. {
  84. attributes.Add("Und");
  85. }
  86. if (IsDefault)
  87. {
  88. attributes.Add("Default");
  89. }
  90. if (IsForced)
  91. {
  92. attributes.Add("Forced");
  93. }
  94. string name = string.Join(" ", attributes.ToArray());
  95. return name;
  96. }
  97. if (Type == MediaStreamType.Video)
  98. {
  99. }
  100. return null;
  101. }
  102. }
  103. private string AddLanguageIfNeeded(string title)
  104. {
  105. if (!string.IsNullOrEmpty(Language) &&
  106. !string.Equals(Language, "und", StringComparison.OrdinalIgnoreCase) &&
  107. !IsLanguageInTitle(title, Language))
  108. {
  109. title = StringHelper.FirstToUpper(Language) + " " + title;
  110. }
  111. return title;
  112. }
  113. private bool IsLanguageInTitle(string title, string language)
  114. {
  115. if (title.IndexOf(Language, StringComparison.OrdinalIgnoreCase) != -1)
  116. {
  117. return true;
  118. }
  119. return false;
  120. }
  121. public string NalLengthSize { get; set; }
  122. /// <summary>
  123. /// Gets or sets a value indicating whether this instance is interlaced.
  124. /// </summary>
  125. /// <value><c>true</c> if this instance is interlaced; otherwise, <c>false</c>.</value>
  126. public bool IsInterlaced { get; set; }
  127. public bool? IsAVC { get; set; }
  128. /// <summary>
  129. /// Gets or sets the channel layout.
  130. /// </summary>
  131. /// <value>The channel layout.</value>
  132. public string ChannelLayout { get; set; }
  133. /// <summary>
  134. /// Gets or sets the bit rate.
  135. /// </summary>
  136. /// <value>The bit rate.</value>
  137. public int? BitRate { get; set; }
  138. /// <summary>
  139. /// Gets or sets the bit depth.
  140. /// </summary>
  141. /// <value>The bit depth.</value>
  142. public int? BitDepth { get; set; }
  143. /// <summary>
  144. /// Gets or sets the reference frames.
  145. /// </summary>
  146. /// <value>The reference frames.</value>
  147. public int? RefFrames { get; set; }
  148. /// <summary>
  149. /// Gets or sets the length of the packet.
  150. /// </summary>
  151. /// <value>The length of the packet.</value>
  152. public int? PacketLength { get; set; }
  153. /// <summary>
  154. /// Gets or sets the channels.
  155. /// </summary>
  156. /// <value>The channels.</value>
  157. public int? Channels { get; set; }
  158. /// <summary>
  159. /// Gets or sets the sample rate.
  160. /// </summary>
  161. /// <value>The sample rate.</value>
  162. public int? SampleRate { get; set; }
  163. /// <summary>
  164. /// Gets or sets a value indicating whether this instance is default.
  165. /// </summary>
  166. /// <value><c>true</c> if this instance is default; otherwise, <c>false</c>.</value>
  167. public bool IsDefault { get; set; }
  168. /// <summary>
  169. /// Gets or sets a value indicating whether this instance is forced.
  170. /// </summary>
  171. /// <value><c>true</c> if this instance is forced; otherwise, <c>false</c>.</value>
  172. public bool IsForced { get; set; }
  173. /// <summary>
  174. /// Gets or sets the height.
  175. /// </summary>
  176. /// <value>The height.</value>
  177. public int? Height { get; set; }
  178. /// <summary>
  179. /// Gets or sets the width.
  180. /// </summary>
  181. /// <value>The width.</value>
  182. public int? Width { get; set; }
  183. /// <summary>
  184. /// Gets or sets the average frame rate.
  185. /// </summary>
  186. /// <value>The average frame rate.</value>
  187. public float? AverageFrameRate { get; set; }
  188. /// <summary>
  189. /// Gets or sets the real frame rate.
  190. /// </summary>
  191. /// <value>The real frame rate.</value>
  192. public float? RealFrameRate { get; set; }
  193. /// <summary>
  194. /// Gets or sets the profile.
  195. /// </summary>
  196. /// <value>The profile.</value>
  197. public string Profile { get; set; }
  198. /// <summary>
  199. /// Gets or sets the type.
  200. /// </summary>
  201. /// <value>The type.</value>
  202. public MediaStreamType Type { get; set; }
  203. /// <summary>
  204. /// Gets or sets the aspect ratio.
  205. /// </summary>
  206. /// <value>The aspect ratio.</value>
  207. public string AspectRatio { get; set; }
  208. /// <summary>
  209. /// Gets or sets the index.
  210. /// </summary>
  211. /// <value>The index.</value>
  212. public int Index { get; set; }
  213. /// <summary>
  214. /// Gets or sets the score.
  215. /// </summary>
  216. /// <value>The score.</value>
  217. public int? Score { get; set; }
  218. /// <summary>
  219. /// Gets or sets a value indicating whether this instance is external.
  220. /// </summary>
  221. /// <value><c>true</c> if this instance is external; otherwise, <c>false</c>.</value>
  222. public bool IsExternal { get; set; }
  223. /// <summary>
  224. /// Gets or sets the method.
  225. /// </summary>
  226. /// <value>The method.</value>
  227. public SubtitleDeliveryMethod? DeliveryMethod { get; set; }
  228. /// <summary>
  229. /// Gets or sets the delivery URL.
  230. /// </summary>
  231. /// <value>The delivery URL.</value>
  232. public string DeliveryUrl { get; set; }
  233. /// <summary>
  234. /// Gets or sets a value indicating whether this instance is external URL.
  235. /// </summary>
  236. /// <value><c>null</c> if [is external URL] contains no value, <c>true</c> if [is external URL]; otherwise, <c>false</c>.</value>
  237. public bool? IsExternalUrl { get; set; }
  238. public bool IsTextSubtitleStream
  239. {
  240. get
  241. {
  242. if (Type != MediaStreamType.Subtitle) return false;
  243. if (string.IsNullOrEmpty(Codec) && !IsExternal)
  244. {
  245. return false;
  246. }
  247. return IsTextFormat(Codec);
  248. }
  249. }
  250. public static bool IsTextFormat(string format)
  251. {
  252. string codec = format ?? string.Empty;
  253. // sub = external .sub file
  254. return StringHelper.IndexOfIgnoreCase(codec, "pgs") == -1 &&
  255. StringHelper.IndexOfIgnoreCase(codec, "dvd") == -1 &&
  256. StringHelper.IndexOfIgnoreCase(codec, "dvbsub") == -1 &&
  257. !StringHelper.EqualsIgnoreCase(codec, "sub") &&
  258. !StringHelper.EqualsIgnoreCase(codec, "dvb_subtitle");
  259. }
  260. public bool SupportsSubtitleConversionTo(string toCodec)
  261. {
  262. if (!IsTextSubtitleStream)
  263. {
  264. return false;
  265. }
  266. var fromCodec = Codec;
  267. // Can't convert from this
  268. if (StringHelper.EqualsIgnoreCase(fromCodec, "ass"))
  269. {
  270. return false;
  271. }
  272. if (StringHelper.EqualsIgnoreCase(fromCodec, "ssa"))
  273. {
  274. return false;
  275. }
  276. // Can't convert to this
  277. if (StringHelper.EqualsIgnoreCase(toCodec, "ass"))
  278. {
  279. return false;
  280. }
  281. if (StringHelper.EqualsIgnoreCase(toCodec, "ssa"))
  282. {
  283. return false;
  284. }
  285. return true;
  286. }
  287. /// <summary>
  288. /// Gets or sets a value indicating whether [supports external stream].
  289. /// </summary>
  290. /// <value><c>true</c> if [supports external stream]; otherwise, <c>false</c>.</value>
  291. public bool SupportsExternalStream { get; set; }
  292. /// <summary>
  293. /// Gets or sets the filename.
  294. /// </summary>
  295. /// <value>The filename.</value>
  296. public string Path { get; set; }
  297. /// <summary>
  298. /// Gets or sets the external identifier.
  299. /// </summary>
  300. /// <value>The external identifier.</value>
  301. public string ExternalId { get; set; }
  302. /// <summary>
  303. /// Gets or sets the pixel format.
  304. /// </summary>
  305. /// <value>The pixel format.</value>
  306. public string PixelFormat { get; set; }
  307. /// <summary>
  308. /// Gets or sets the level.
  309. /// </summary>
  310. /// <value>The level.</value>
  311. public double? Level { get; set; }
  312. /// <summary>
  313. /// Gets a value indicating whether this instance is anamorphic.
  314. /// </summary>
  315. /// <value><c>true</c> if this instance is anamorphic; otherwise, <c>false</c>.</value>
  316. public bool? IsAnamorphic { get; set; }
  317. }
  318. }