ChannelMediaInfo.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using MediaBrowser.Common.Extensions;
  2. using MediaBrowser.Model.Dto;
  3. using MediaBrowser.Model.Entities;
  4. using MediaBrowser.Model.MediaInfo;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. namespace MediaBrowser.Controller.Channels
  9. {
  10. public class ChannelMediaInfo
  11. {
  12. public string Path { get; set; }
  13. public Dictionary<string, string> RequiredHttpHeaders { get; set; }
  14. public string Container { get; set; }
  15. public string AudioCodec { get; set; }
  16. public string VideoCodec { get; set; }
  17. public int? AudioBitrate { get; set; }
  18. public int? VideoBitrate { get; set; }
  19. public int? Width { get; set; }
  20. public int? Height { get; set; }
  21. public int? AudioChannels { get; set; }
  22. public int? AudioSampleRate { get; set; }
  23. public string VideoProfile { get; set; }
  24. public float? VideoLevel { get; set; }
  25. public float? Framerate { get; set; }
  26. public bool? IsAnamorphic { get; set; }
  27. public MediaProtocol Protocol { get; set; }
  28. public long? RunTimeTicks { get; set; }
  29. public string Id { get; set; }
  30. public bool ReadAtNativeFramerate { get; set; }
  31. public bool SupportsDirectPlay { get; set; }
  32. public ChannelMediaInfo()
  33. {
  34. RequiredHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  35. // This is most common
  36. Protocol = MediaProtocol.Http;
  37. SupportsDirectPlay = true;
  38. }
  39. public MediaSourceInfo ToMediaSource(Guid itemId)
  40. {
  41. var id = string.IsNullOrWhiteSpace(Path) ?
  42. itemId.ToString("N") :
  43. Path.GetMD5().ToString("N");
  44. var source = new MediaSourceInfo
  45. {
  46. MediaStreams = GetMediaStreams(this).ToList(),
  47. Container = Container,
  48. Protocol = Protocol,
  49. Path = Path,
  50. RequiredHttpHeaders = RequiredHttpHeaders,
  51. RunTimeTicks = RunTimeTicks,
  52. Name = id,
  53. Id = id,
  54. ReadAtNativeFramerate = ReadAtNativeFramerate,
  55. SupportsDirectStream = false,
  56. SupportsDirectPlay = SupportsDirectPlay,
  57. IsRemote = true
  58. };
  59. var bitrate = (AudioBitrate ?? 0) + (VideoBitrate ?? 0);
  60. if (bitrate > 0)
  61. {
  62. source.Bitrate = bitrate;
  63. }
  64. return source;
  65. }
  66. private IEnumerable<MediaStream> GetMediaStreams(ChannelMediaInfo info)
  67. {
  68. var list = new List<MediaStream>();
  69. if (!string.IsNullOrWhiteSpace(info.VideoCodec))
  70. {
  71. list.Add(new MediaStream
  72. {
  73. Type = MediaStreamType.Video,
  74. Width = info.Width,
  75. RealFrameRate = info.Framerate,
  76. Profile = info.VideoProfile,
  77. Level = info.VideoLevel,
  78. Index = -1,
  79. Height = info.Height,
  80. Codec = info.VideoCodec,
  81. BitRate = info.VideoBitrate,
  82. AverageFrameRate = info.Framerate
  83. });
  84. }
  85. if (!string.IsNullOrWhiteSpace(info.AudioCodec))
  86. {
  87. list.Add(new MediaStream
  88. {
  89. Type = MediaStreamType.Audio,
  90. Index = -1,
  91. Codec = info.AudioCodec,
  92. BitRate = info.AudioBitrate,
  93. Channels = info.AudioChannels,
  94. SampleRate = info.AudioSampleRate
  95. });
  96. }
  97. return list;
  98. }
  99. }
  100. }