MediaStream.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. if (IsDefault)
  83. {
  84. attributes.Add("Default");
  85. }
  86. if (IsForced)
  87. {
  88. attributes.Add("Forced");
  89. }
  90. string name = string.Join(" ", attributes.ToArray());
  91. return name;
  92. }
  93. if (Type == MediaStreamType.Video)
  94. {
  95. }
  96. return null;
  97. }
  98. }
  99. private string AddLanguageIfNeeded(string title)
  100. {
  101. if (!string.IsNullOrEmpty(Language) && !string.Equals(Language, "und", StringComparison.OrdinalIgnoreCase) && title.IndexOf(Language, StringComparison.OrdinalIgnoreCase) == -1)
  102. {
  103. title = StringHelper.FirstToUpper(Language) + " " + title;
  104. }
  105. return title;
  106. }
  107. public string NalLengthSize { get; set; }
  108. /// <summary>
  109. /// Gets or sets a value indicating whether this instance is interlaced.
  110. /// </summary>
  111. /// <value><c>true</c> if this instance is interlaced; otherwise, <c>false</c>.</value>
  112. public bool IsInterlaced { get; set; }
  113. public bool? IsAVC { get; set; }
  114. /// <summary>
  115. /// Gets or sets the channel layout.
  116. /// </summary>
  117. /// <value>The channel layout.</value>
  118. public string ChannelLayout { get; set; }
  119. /// <summary>
  120. /// Gets or sets the bit rate.
  121. /// </summary>
  122. /// <value>The bit rate.</value>
  123. public int? BitRate { get; set; }
  124. /// <summary>
  125. /// Gets or sets the bit depth.
  126. /// </summary>
  127. /// <value>The bit depth.</value>
  128. public int? BitDepth { get; set; }
  129. /// <summary>
  130. /// Gets or sets the reference frames.
  131. /// </summary>
  132. /// <value>The reference frames.</value>
  133. public int? RefFrames { get; set; }
  134. /// <summary>
  135. /// Gets or sets the length of the packet.
  136. /// </summary>
  137. /// <value>The length of the packet.</value>
  138. public int? PacketLength { get; set; }
  139. /// <summary>
  140. /// Gets or sets the channels.
  141. /// </summary>
  142. /// <value>The channels.</value>
  143. public int? Channels { get; set; }
  144. /// <summary>
  145. /// Gets or sets the sample rate.
  146. /// </summary>
  147. /// <value>The sample rate.</value>
  148. public int? SampleRate { get; set; }
  149. /// <summary>
  150. /// Gets or sets a value indicating whether this instance is default.
  151. /// </summary>
  152. /// <value><c>true</c> if this instance is default; otherwise, <c>false</c>.</value>
  153. public bool IsDefault { get; set; }
  154. /// <summary>
  155. /// Gets or sets a value indicating whether this instance is forced.
  156. /// </summary>
  157. /// <value><c>true</c> if this instance is forced; otherwise, <c>false</c>.</value>
  158. public bool IsForced { get; set; }
  159. /// <summary>
  160. /// Gets or sets the height.
  161. /// </summary>
  162. /// <value>The height.</value>
  163. public int? Height { get; set; }
  164. /// <summary>
  165. /// Gets or sets the width.
  166. /// </summary>
  167. /// <value>The width.</value>
  168. public int? Width { get; set; }
  169. /// <summary>
  170. /// Gets or sets the average frame rate.
  171. /// </summary>
  172. /// <value>The average frame rate.</value>
  173. public float? AverageFrameRate { get; set; }
  174. /// <summary>
  175. /// Gets or sets the real frame rate.
  176. /// </summary>
  177. /// <value>The real frame rate.</value>
  178. public float? RealFrameRate { get; set; }
  179. /// <summary>
  180. /// Gets or sets the profile.
  181. /// </summary>
  182. /// <value>The profile.</value>
  183. public string Profile { get; set; }
  184. /// <summary>
  185. /// Gets or sets the type.
  186. /// </summary>
  187. /// <value>The type.</value>
  188. public MediaStreamType Type { get; set; }
  189. /// <summary>
  190. /// Gets or sets the aspect ratio.
  191. /// </summary>
  192. /// <value>The aspect ratio.</value>
  193. public string AspectRatio { get; set; }
  194. /// <summary>
  195. /// Gets or sets the index.
  196. /// </summary>
  197. /// <value>The index.</value>
  198. public int Index { get; set; }
  199. /// <summary>
  200. /// Gets or sets the score.
  201. /// </summary>
  202. /// <value>The score.</value>
  203. public int? Score { get; set; }
  204. /// <summary>
  205. /// Gets or sets a value indicating whether this instance is external.
  206. /// </summary>
  207. /// <value><c>true</c> if this instance is external; otherwise, <c>false</c>.</value>
  208. public bool IsExternal { get; set; }
  209. /// <summary>
  210. /// Gets or sets the method.
  211. /// </summary>
  212. /// <value>The method.</value>
  213. public SubtitleDeliveryMethod? DeliveryMethod { get; set; }
  214. /// <summary>
  215. /// Gets or sets the delivery URL.
  216. /// </summary>
  217. /// <value>The delivery URL.</value>
  218. public string DeliveryUrl { get; set; }
  219. /// <summary>
  220. /// Gets or sets a value indicating whether this instance is external URL.
  221. /// </summary>
  222. /// <value><c>null</c> if [is external URL] contains no value, <c>true</c> if [is external URL]; otherwise, <c>false</c>.</value>
  223. public bool? IsExternalUrl { get; set; }
  224. public bool IsTextSubtitleStream
  225. {
  226. get
  227. {
  228. if (Type != MediaStreamType.Subtitle) return false;
  229. if (string.IsNullOrEmpty(Codec) && !IsExternal)
  230. {
  231. return false;
  232. }
  233. return IsTextFormat(Codec);
  234. }
  235. }
  236. public static bool IsTextFormat(string format)
  237. {
  238. string codec = format ?? string.Empty;
  239. // sub = external .sub file
  240. return StringHelper.IndexOfIgnoreCase(codec, "pgs") == -1 &&
  241. StringHelper.IndexOfIgnoreCase(codec, "dvd") == -1 &&
  242. StringHelper.IndexOfIgnoreCase(codec, "dvbsub") == -1 &&
  243. !StringHelper.EqualsIgnoreCase(codec, "sub") &&
  244. !StringHelper.EqualsIgnoreCase(codec, "dvb_subtitle");
  245. }
  246. public bool SupportsSubtitleConversionTo(string codec)
  247. {
  248. if (!IsTextSubtitleStream)
  249. {
  250. return false;
  251. }
  252. // Can't convert from this
  253. if (StringHelper.EqualsIgnoreCase(Codec, "ass"))
  254. {
  255. return false;
  256. }
  257. if (StringHelper.EqualsIgnoreCase(Codec, "ssa"))
  258. {
  259. return false;
  260. }
  261. // Can't convert to this
  262. if (StringHelper.EqualsIgnoreCase(codec, "ass"))
  263. {
  264. return false;
  265. }
  266. if (StringHelper.EqualsIgnoreCase(codec, "ssa"))
  267. {
  268. return false;
  269. }
  270. return true;
  271. }
  272. /// <summary>
  273. /// Gets or sets a value indicating whether [supports external stream].
  274. /// </summary>
  275. /// <value><c>true</c> if [supports external stream]; otherwise, <c>false</c>.</value>
  276. public bool SupportsExternalStream { get; set; }
  277. /// <summary>
  278. /// Gets or sets the filename.
  279. /// </summary>
  280. /// <value>The filename.</value>
  281. public string Path { get; set; }
  282. /// <summary>
  283. /// Gets or sets the external identifier.
  284. /// </summary>
  285. /// <value>The external identifier.</value>
  286. public string ExternalId { get; set; }
  287. /// <summary>
  288. /// Gets or sets the pixel format.
  289. /// </summary>
  290. /// <value>The pixel format.</value>
  291. public string PixelFormat { get; set; }
  292. /// <summary>
  293. /// Gets or sets the level.
  294. /// </summary>
  295. /// <value>The level.</value>
  296. public double? Level { get; set; }
  297. /// <summary>
  298. /// Gets a value indicating whether this instance is anamorphic.
  299. /// </summary>
  300. /// <value><c>true</c> if this instance is anamorphic; otherwise, <c>false</c>.</value>
  301. public bool? IsAnamorphic { get; set; }
  302. }
  303. }