MediaStream.cs 10 KB

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