jellyfin-server/MediaBrowser.Controller/Channels/ChannelMediaInfo.cs

117 lines
3.7 KiB
C#
Raw Normal View History

2014-10-15 04:11:40 +00:00
using MediaBrowser.Common.Extensions;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
using System;
2014-06-02 19:32:41 +00:00
using System.Collections.Generic;
2014-10-15 04:11:40 +00:00
using System.Linq;
2014-05-11 23:02:28 +00:00
namespace MediaBrowser.Controller.Channels
{
public class ChannelMediaInfo
{
public string Path { get; set; }
public Dictionary<string, string> RequiredHttpHeaders { get; set; }
public string Container { get; set; }
public string AudioCodec { get; set; }
public string VideoCodec { get; set; }
public int? AudioBitrate { get; set; }
public int? VideoBitrate { get; set; }
public int? Width { get; set; }
public int? Height { get; set; }
public int? AudioChannels { get; set; }
2014-06-01 19:41:35 +00:00
public int? AudioSampleRate { get; set; }
2014-05-11 23:02:28 +00:00
2014-06-01 19:41:35 +00:00
public string VideoProfile { get; set; }
public float? VideoLevel { get; set; }
public float? Framerate { get; set; }
2014-06-23 16:05:19 +00:00
public bool? IsAnamorphic { get; set; }
public MediaProtocol Protocol { get; set; }
2014-07-13 21:03:57 +00:00
public long? RunTimeTicks { get; set; }
2014-10-15 04:11:40 +00:00
public string Id { get; set; }
2014-10-25 18:32:58 +00:00
public bool ReadAtNativeFramerate { get; set; }
2015-03-27 20:55:31 +00:00
public bool SupportsDirectPlay { get; set; }
2014-10-25 18:32:58 +00:00
2014-05-11 23:02:28 +00:00
public ChannelMediaInfo()
{
2014-06-02 19:32:41 +00:00
RequiredHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
// This is most common
Protocol = MediaProtocol.Http;
2015-03-27 20:55:31 +00:00
SupportsDirectPlay = true;
2014-05-11 23:02:28 +00:00
}
2014-10-15 04:11:40 +00:00
2017-01-19 07:32:39 +00:00
public MediaSourceInfo ToMediaSource(Guid itemId)
2014-10-15 04:11:40 +00:00
{
2017-01-19 07:32:39 +00:00
var id = string.IsNullOrWhiteSpace(Path) ?
itemId.ToString("N") :
Path.GetMD5().ToString("N");
2014-10-15 04:11:40 +00:00
var source = new MediaSourceInfo
{
MediaStreams = GetMediaStreams(this).ToList(),
Container = Container,
Protocol = Protocol,
Path = Path,
RequiredHttpHeaders = RequiredHttpHeaders,
RunTimeTicks = RunTimeTicks,
Name = id,
2014-10-25 18:32:58 +00:00
Id = id,
ReadAtNativeFramerate = ReadAtNativeFramerate,
2017-07-13 19:04:59 +00:00
SupportsDirectStream = Protocol == MediaProtocol.Http && !string.IsNullOrWhiteSpace(Container) && !string.Equals(Container, "hls", StringComparison.OrdinalIgnoreCase),
2017-01-20 17:53:48 +00:00
SupportsDirectPlay = SupportsDirectPlay,
IsRemote = true
2014-10-15 04:11:40 +00:00
};
2017-01-21 20:27:07 +00:00
source.InferTotalBitrate();
2014-10-15 04:11:40 +00:00
return source;
}
private IEnumerable<MediaStream> GetMediaStreams(ChannelMediaInfo info)
{
var list = new List<MediaStream>();
if (!string.IsNullOrWhiteSpace(info.VideoCodec))
2014-10-15 04:11:40 +00:00
{
list.Add(new MediaStream
{
Type = MediaStreamType.Video,
Width = info.Width,
RealFrameRate = info.Framerate,
Profile = info.VideoProfile,
Level = info.VideoLevel,
Index = -1,
Height = info.Height,
Codec = info.VideoCodec,
BitRate = info.VideoBitrate,
AverageFrameRate = info.Framerate
});
}
2014-10-15 04:11:40 +00:00
if (!string.IsNullOrWhiteSpace(info.AudioCodec))
{
2014-10-15 04:11:40 +00:00
list.Add(new MediaStream
{
Type = MediaStreamType.Audio,
Index = -1,
Codec = info.AudioCodec,
BitRate = info.AudioBitrate,
Channels = info.AudioChannels,
SampleRate = info.AudioSampleRate
});
}
return list;
}
2014-05-11 23:02:28 +00:00
}
}