ChannelMediaInfo.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 ChannelMediaInfo()
  32. {
  33. RequiredHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  34. // This is most common
  35. Protocol = MediaProtocol.Http;
  36. }
  37. public MediaSourceInfo ToMediaSource()
  38. {
  39. var id = Path.GetMD5().ToString("N");
  40. var source = new MediaSourceInfo
  41. {
  42. MediaStreams = GetMediaStreams(this).ToList(),
  43. Container = Container,
  44. Protocol = Protocol,
  45. Path = Path,
  46. RequiredHttpHeaders = RequiredHttpHeaders,
  47. RunTimeTicks = RunTimeTicks,
  48. Name = id,
  49. Id = id,
  50. ReadAtNativeFramerate = ReadAtNativeFramerate,
  51. SupportsDirectStream = Protocol == MediaProtocol.File || Protocol == MediaProtocol.Http
  52. };
  53. var bitrate = (AudioBitrate ?? 0) + (VideoBitrate ?? 0);
  54. if (bitrate > 0)
  55. {
  56. source.Bitrate = bitrate;
  57. }
  58. return source;
  59. }
  60. private IEnumerable<MediaStream> GetMediaStreams(ChannelMediaInfo info)
  61. {
  62. var list = new List<MediaStream>();
  63. if (!string.IsNullOrWhiteSpace(info.VideoCodec) &&
  64. !string.IsNullOrWhiteSpace(info.AudioCodec))
  65. {
  66. list.Add(new MediaStream
  67. {
  68. Type = MediaStreamType.Video,
  69. Width = info.Width,
  70. RealFrameRate = info.Framerate,
  71. Profile = info.VideoProfile,
  72. Level = info.VideoLevel,
  73. Index = -1,
  74. Height = info.Height,
  75. Codec = info.VideoCodec,
  76. BitRate = info.VideoBitrate,
  77. AverageFrameRate = info.Framerate
  78. });
  79. list.Add(new MediaStream
  80. {
  81. Type = MediaStreamType.Audio,
  82. Index = -1,
  83. Codec = info.AudioCodec,
  84. BitRate = info.AudioBitrate,
  85. Channels = info.AudioChannels,
  86. SampleRate = info.AudioSampleRate
  87. });
  88. }
  89. return list;
  90. }
  91. }
  92. }