MediaSourceInfo.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 bool EnableHttpCredentials { get; set; }
  40. public MediaSourceInfo()
  41. {
  42. Formats = new List<string>();
  43. MediaStreams = new List<MediaStream>();
  44. RequiredHttpHeaders = new Dictionary<string, string>();
  45. PlayableStreamFileNames = new List<string>();
  46. SupportsTranscoding = true;
  47. SupportsDirectStream = true;
  48. SupportsDirectPlay = true;
  49. EnableHttpCredentials = true;
  50. }
  51. public int? DefaultAudioStreamIndex { get; set; }
  52. public int? DefaultSubtitleStreamIndex { get; set; }
  53. [IgnoreDataMember]
  54. public MediaStream DefaultAudioStream
  55. {
  56. get { return GetDefaultAudioStream(DefaultAudioStreamIndex); }
  57. }
  58. public MediaStream GetDefaultAudioStream(int? defaultIndex)
  59. {
  60. if (defaultIndex.HasValue)
  61. {
  62. var val = defaultIndex.Value;
  63. foreach (MediaStream i in MediaStreams)
  64. {
  65. if (i.Type == MediaStreamType.Audio && i.Index == val)
  66. {
  67. return i;
  68. }
  69. }
  70. }
  71. foreach (MediaStream i in MediaStreams)
  72. {
  73. if (i.Type == MediaStreamType.Audio && i.IsDefault)
  74. {
  75. return i;
  76. }
  77. }
  78. foreach (MediaStream i in MediaStreams)
  79. {
  80. if (i.Type == MediaStreamType.Audio)
  81. {
  82. return i;
  83. }
  84. }
  85. return null;
  86. }
  87. [IgnoreDataMember]
  88. public MediaStream VideoStream
  89. {
  90. get
  91. {
  92. foreach (MediaStream i in MediaStreams)
  93. {
  94. if (i.Type == MediaStreamType.Video && StringHelper.IndexOfIgnoreCase((i.Codec ?? string.Empty), "jpeg") == -1)
  95. {
  96. return i;
  97. }
  98. }
  99. return null;
  100. }
  101. }
  102. public MediaStream GetMediaStream(MediaStreamType type, int index)
  103. {
  104. foreach (MediaStream i in MediaStreams)
  105. {
  106. if (i.Type == type && i.Index == index)
  107. {
  108. return i;
  109. }
  110. }
  111. return null;
  112. }
  113. public int? GetStreamCount(MediaStreamType type)
  114. {
  115. int numMatches = 0;
  116. int numStreams = 0;
  117. foreach (MediaStream i in MediaStreams)
  118. {
  119. numStreams++;
  120. if (i.Type == type)
  121. {
  122. numMatches++;
  123. }
  124. }
  125. if (numStreams == 0)
  126. {
  127. return null;
  128. }
  129. return numMatches;
  130. }
  131. public bool? IsSecondaryAudio(MediaStream stream)
  132. {
  133. foreach (MediaStream currentStream in MediaStreams)
  134. {
  135. if (currentStream.Type == MediaStreamType.Audio)
  136. {
  137. return currentStream.Index != stream.Index;
  138. }
  139. }
  140. return null;
  141. }
  142. }
  143. }