MediaSourceInfo.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using System;
  2. using MediaBrowser.Model.Entities;
  3. using MediaBrowser.Model.Extensions;
  4. using MediaBrowser.Model.MediaInfo;
  5. using System.Collections.Generic;
  6. using MediaBrowser.Model.Serialization;
  7. namespace MediaBrowser.Model.Dto
  8. {
  9. public class MediaSourceInfo
  10. {
  11. public MediaProtocol Protocol { get; set; }
  12. public string Id { get; set; }
  13. public string Path { get; set; }
  14. public MediaSourceType Type { get; set; }
  15. public string Container { get; set; }
  16. public long? Size { get; set; }
  17. public string Name { get; set; }
  18. /// <summary>
  19. /// Differentiate internet url vs local network
  20. /// </summary>
  21. public bool IsRemote { get; set; }
  22. public string ETag { get; set; }
  23. public long? RunTimeTicks { get; set; }
  24. public bool ReadAtNativeFramerate { get; set; }
  25. public bool SupportsTranscoding { get; set; }
  26. public bool SupportsDirectStream { get; set; }
  27. public bool SupportsDirectPlay { get; set; }
  28. public bool IsInfiniteStream { get; set; }
  29. public bool RequiresOpening { get; set; }
  30. public string OpenToken { get; set; }
  31. public bool RequiresClosing { get; set; }
  32. public bool SupportsProbing { get; set; }
  33. public string LiveStreamId { get; set; }
  34. public int? BufferMs { get; set; }
  35. public VideoType? VideoType { get; set; }
  36. public IsoType? IsoType { get; set; }
  37. public Video3DFormat? Video3DFormat { get; set; }
  38. public List<MediaStream> MediaStreams { get; set; }
  39. public List<string> PlayableStreamFileNames { get; set; }
  40. public List<string> Formats { get; set; }
  41. public int? Bitrate { get; set; }
  42. public TransportStreamTimestamp? Timestamp { get; set; }
  43. public Dictionary<string, string> RequiredHttpHeaders { get; set; }
  44. public string TranscodingUrl { get; set; }
  45. public string TranscodingSubProtocol { get; set; }
  46. public string TranscodingContainer { get; set; }
  47. public MediaSourceInfo()
  48. {
  49. Formats = new List<string>();
  50. MediaStreams = new List<MediaStream>();
  51. RequiredHttpHeaders = new Dictionary<string, string>();
  52. PlayableStreamFileNames = new List<string>();
  53. SupportsTranscoding = true;
  54. SupportsDirectStream = true;
  55. SupportsDirectPlay = true;
  56. SupportsProbing = true;
  57. }
  58. public int? DefaultAudioStreamIndex { get; set; }
  59. public int? DefaultSubtitleStreamIndex { get; set; }
  60. [IgnoreDataMember]
  61. public MediaStream DefaultAudioStream
  62. {
  63. get { return GetDefaultAudioStream(DefaultAudioStreamIndex); }
  64. }
  65. public MediaStream GetDefaultAudioStream(int? defaultIndex)
  66. {
  67. if (defaultIndex.HasValue)
  68. {
  69. var val = defaultIndex.Value;
  70. foreach (MediaStream i in MediaStreams)
  71. {
  72. if (i.Type == MediaStreamType.Audio && i.Index == val)
  73. {
  74. return i;
  75. }
  76. }
  77. }
  78. foreach (MediaStream i in MediaStreams)
  79. {
  80. if (i.Type == MediaStreamType.Audio && i.IsDefault)
  81. {
  82. return i;
  83. }
  84. }
  85. foreach (MediaStream i in MediaStreams)
  86. {
  87. if (i.Type == MediaStreamType.Audio)
  88. {
  89. return i;
  90. }
  91. }
  92. return null;
  93. }
  94. [IgnoreDataMember]
  95. public MediaStream VideoStream
  96. {
  97. get
  98. {
  99. foreach (MediaStream i in MediaStreams)
  100. {
  101. if (i.Type == MediaStreamType.Video && StringHelper.IndexOfIgnoreCase(i.Codec ?? string.Empty, "jpeg") == -1)
  102. {
  103. return i;
  104. }
  105. }
  106. return null;
  107. }
  108. }
  109. public MediaStream GetMediaStream(MediaStreamType type, int index)
  110. {
  111. foreach (MediaStream i in MediaStreams)
  112. {
  113. if (i.Type == type && i.Index == index)
  114. {
  115. return i;
  116. }
  117. }
  118. return null;
  119. }
  120. public int? GetStreamCount(MediaStreamType type)
  121. {
  122. int numMatches = 0;
  123. int numStreams = 0;
  124. foreach (MediaStream i in MediaStreams)
  125. {
  126. numStreams++;
  127. if (i.Type == type)
  128. {
  129. numMatches++;
  130. }
  131. }
  132. if (numStreams == 0)
  133. {
  134. return null;
  135. }
  136. return numMatches;
  137. }
  138. public bool? IsSecondaryAudio(MediaStream stream)
  139. {
  140. // Look for the first audio track marked as default
  141. foreach (MediaStream currentStream in MediaStreams)
  142. {
  143. if (currentStream.Type == MediaStreamType.Audio && currentStream.IsDefault)
  144. {
  145. return currentStream.Index != stream.Index;
  146. }
  147. }
  148. // Look for the first audio track
  149. foreach (MediaStream currentStream in MediaStreams)
  150. {
  151. if (currentStream.Type == MediaStreamType.Audio)
  152. {
  153. return currentStream.Index != stream.Index;
  154. }
  155. }
  156. return null;
  157. }
  158. }
  159. }