MediaSourceInfo.cs 4.9 KB

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