jellyfin/MediaBrowser.Controller/Channels/ChannelMediaInfo.cs

119 lines
3.6 KiB
C#
Raw Normal View History

2014-10-15 06:11:40 +02:00
using MediaBrowser.Common.Extensions;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
using System;
2014-06-02 21:32:41 +02:00
using System.Collections.Generic;
2014-10-15 06:11:40 +02:00
using System.Linq;
2014-05-12 01:02:28 +02: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 21:41:35 +02:00
public int? AudioSampleRate { get; set; }
2014-05-12 01:02:28 +02:00
2014-06-01 21:41:35 +02:00
public string VideoProfile { get; set; }
public float? VideoLevel { get; set; }
public float? Framerate { get; set; }
2014-06-23 18:05:19 +02:00
public bool? IsAnamorphic { get; set; }
public MediaProtocol Protocol { get; set; }
2014-07-13 23:03:57 +02:00
public long? RunTimeTicks { get; set; }
2014-10-15 06:11:40 +02:00
public string Id { get; set; }
2014-10-25 20:32:58 +02:00
public bool ReadAtNativeFramerate { get; set; }
2015-03-27 21:55:31 +01:00
public bool SupportsDirectPlay { get; set; }
2014-10-25 20:32:58 +02:00
2014-05-12 01:02:28 +02:00
public ChannelMediaInfo()
{
2014-06-02 21:32:41 +02:00
RequiredHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
// This is most common
Protocol = MediaProtocol.Http;
2015-03-27 21:55:31 +01:00
SupportsDirectPlay = true;
2014-05-12 01:02:28 +02:00
}
2014-10-15 06:11:40 +02:00
public MediaSourceInfo ToMediaSource()
{
var id = Path.GetMD5().ToString("N");
var source = new MediaSourceInfo
{
MediaStreams = GetMediaStreams(this).ToList(),
Container = Container,
Protocol = Protocol,
Path = Path,
RequiredHttpHeaders = RequiredHttpHeaders,
RunTimeTicks = RunTimeTicks,
Name = id,
2014-10-25 20:32:58 +02:00
Id = id,
ReadAtNativeFramerate = ReadAtNativeFramerate,
2016-04-05 21:35:00 +02:00
SupportsDirectStream = Protocol == MediaProtocol.File,
2015-03-27 21:55:31 +01:00
SupportsDirectPlay = SupportsDirectPlay
2014-10-15 06:11:40 +02:00
};
var bitrate = (AudioBitrate ?? 0) + (VideoBitrate ?? 0);
if (bitrate > 0)
{
source.Bitrate = bitrate;
}
return source;
}
private IEnumerable<MediaStream> GetMediaStreams(ChannelMediaInfo info)
{
var list = new List<MediaStream>();
if (!string.IsNullOrWhiteSpace(info.VideoCodec))
2014-10-15 06:11:40 +02: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 06:11:40 +02:00
if (!string.IsNullOrWhiteSpace(info.AudioCodec))
{
2014-10-15 06:11:40 +02: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-12 01:02:28 +02:00
}
}