MediaStream.cs 12 KB

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