MediaStream.cs 9.9 KB

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