MediaSourceInfo.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 System.Runtime.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. public string ETag { get; set; }
  19. public long? RunTimeTicks { get; set; }
  20. public bool ReadAtNativeFramerate { get; set; }
  21. public bool SupportsTranscoding { get; set; }
  22. public bool SupportsDirectStream { get; set; }
  23. public bool SupportsDirectPlay { get; set; }
  24. public bool RequiresOpening { get; set; }
  25. public string OpenToken { get; set; }
  26. public bool RequiresClosing { get; set; }
  27. public string LiveStreamId { get; set; }
  28. public int? BufferMs { get; set; }
  29. public VideoType? VideoType { get; set; }
  30. public IsoType? IsoType { get; set; }
  31. public Video3DFormat? Video3DFormat { get; set; }
  32. public List<MediaStream> MediaStreams { get; set; }
  33. public List<string> PlayableStreamFileNames { get; set; }
  34. public List<string> Formats { get; set; }
  35. public int? Bitrate { get; set; }
  36. public TransportStreamTimestamp? Timestamp { get; set; }
  37. public Dictionary<string, string> RequiredHttpHeaders { get; set; }
  38. public string TranscodingUrl { get; set; }
  39. public string TranscodingSubProtocol { get; set; }
  40. public string TranscodingContainer { get; set; }
  41. public DateTime? DateLiveStreamOpened { get; set; }
  42. public MediaSourceInfo()
  43. {
  44. Formats = new List<string>();
  45. MediaStreams = new List<MediaStream>();
  46. RequiredHttpHeaders = new Dictionary<string, string>();
  47. PlayableStreamFileNames = new List<string>();
  48. SupportsTranscoding = true;
  49. SupportsDirectStream = true;
  50. SupportsDirectPlay = true;
  51. }
  52. public int? DefaultAudioStreamIndex { get; set; }
  53. public int? DefaultSubtitleStreamIndex { get; set; }
  54. [IgnoreDataMember]
  55. public MediaStream DefaultAudioStream
  56. {
  57. get { return GetDefaultAudioStream(DefaultAudioStreamIndex); }
  58. }
  59. public MediaStream GetDefaultAudioStream(int? defaultIndex)
  60. {
  61. if (defaultIndex.HasValue)
  62. {
  63. var val = defaultIndex.Value;
  64. foreach (MediaStream i in MediaStreams)
  65. {
  66. if (i.Type == MediaStreamType.Audio && i.Index == val)
  67. {
  68. return i;
  69. }
  70. }
  71. }
  72. foreach (MediaStream i in MediaStreams)
  73. {
  74. if (i.Type == MediaStreamType.Audio && i.IsDefault)
  75. {
  76. return i;
  77. }
  78. }
  79. foreach (MediaStream i in MediaStreams)
  80. {
  81. if (i.Type == MediaStreamType.Audio)
  82. {
  83. return i;
  84. }
  85. }
  86. return null;
  87. }
  88. [IgnoreDataMember]
  89. public MediaStream VideoStream
  90. {
  91. get
  92. {
  93. foreach (MediaStream i in MediaStreams)
  94. {
  95. if (i.Type == MediaStreamType.Video && StringHelper.IndexOfIgnoreCase(i.Codec ?? string.Empty, "jpeg") == -1)
  96. {
  97. return i;
  98. }
  99. }
  100. return null;
  101. }
  102. }
  103. public MediaStream GetMediaStream(MediaStreamType type, int index)
  104. {
  105. foreach (MediaStream i in MediaStreams)
  106. {
  107. if (i.Type == type && i.Index == index)
  108. {
  109. return i;
  110. }
  111. }
  112. return null;
  113. }
  114. public int? GetStreamCount(MediaStreamType type)
  115. {
  116. int numMatches = 0;
  117. int numStreams = 0;
  118. foreach (MediaStream i in MediaStreams)
  119. {
  120. numStreams++;
  121. if (i.Type == type)
  122. {
  123. numMatches++;
  124. }
  125. }
  126. if (numStreams == 0)
  127. {
  128. return null;
  129. }
  130. return numMatches;
  131. }
  132. public bool? IsSecondaryAudio(MediaStream stream)
  133. {
  134. // Look for the first audio track marked as default
  135. foreach (MediaStream currentStream in MediaStreams)
  136. {
  137. if (currentStream.Type == MediaStreamType.Audio && currentStream.IsDefault)
  138. {
  139. return currentStream.Index != stream.Index;
  140. }
  141. }
  142. // Look for the first audio track
  143. foreach (MediaStream currentStream in MediaStreams)
  144. {
  145. if (currentStream.Type == MediaStreamType.Audio)
  146. {
  147. return currentStream.Index != stream.Index;
  148. }
  149. }
  150. return null;
  151. }
  152. }
  153. }