MediaStream.cs 11 KB

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