ChannelMediaInfo.cs 3.3 KB

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