MediaStream.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. string name = string.Join(" ", attributes.ToArray());
  69. if (IsDefault)
  70. {
  71. name += " (D)";
  72. }
  73. return name;
  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 (!string.IsNullOrEmpty(Codec))
  83. {
  84. attributes.Add(Codec);
  85. }
  86. string name = string.Join(" ", attributes.ToArray());
  87. if (IsDefault)
  88. {
  89. name += " (D)";
  90. }
  91. if (IsForced)
  92. {
  93. name += " (F)";
  94. }
  95. if (IsExternal)
  96. {
  97. name += " (EXT)";
  98. }
  99. return name;
  100. }
  101. if (Type == MediaStreamType.Video)
  102. {
  103. }
  104. return null;
  105. }
  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. }
  245. /// <summary>
  246. /// Gets or sets a value indicating whether [supports external stream].
  247. /// </summary>
  248. /// <value><c>true</c> if [supports external stream]; otherwise, <c>false</c>.</value>
  249. public bool SupportsExternalStream { get; set; }
  250. /// <summary>
  251. /// Gets or sets the filename.
  252. /// </summary>
  253. /// <value>The filename.</value>
  254. public string Path { get; set; }
  255. /// <summary>
  256. /// Gets or sets the external identifier.
  257. /// </summary>
  258. /// <value>The external identifier.</value>
  259. public string ExternalId { get; set; }
  260. /// <summary>
  261. /// Gets or sets the pixel format.
  262. /// </summary>
  263. /// <value>The pixel format.</value>
  264. public string PixelFormat { get; set; }
  265. /// <summary>
  266. /// Gets or sets the level.
  267. /// </summary>
  268. /// <value>The level.</value>
  269. public double? Level { get; set; }
  270. /// <summary>
  271. /// Gets a value indicating whether this instance is anamorphic.
  272. /// </summary>
  273. /// <value><c>true</c> if this instance is anamorphic; otherwise, <c>false</c>.</value>
  274. public bool? IsAnamorphic { get; set; }
  275. }
  276. }