jellyfin/MediaBrowser.Model/Dto/MediaSourceInfo.cs

255 lines
6.4 KiB
C#
Raw Normal View History

#nullable disable
2020-02-04 00:49:27 +00:00
#pragma warning disable CS1591
using System;
2018-12-27 23:27:57 +00:00
using System.Collections.Generic;
2019-10-15 15:49:49 +00:00
using System.Text.Json.Serialization;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
2018-12-27 23:27:57 +00:00
using MediaBrowser.Model.Session;
namespace MediaBrowser.Model.Dto
{
public class MediaSourceInfo
{
public MediaSourceInfo()
{
Formats = Array.Empty<string>();
MediaStreams = new List<MediaStream>();
MediaAttachments = Array.Empty<MediaAttachment>();
RequiredHttpHeaders = new Dictionary<string, string>();
SupportsTranscoding = true;
SupportsDirectStream = true;
SupportsDirectPlay = true;
SupportsProbing = true;
}
2018-12-27 23:27:57 +00:00
public MediaProtocol Protocol { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public string Id { get; set; }
public string Path { get; set; }
public string EncoderPath { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public MediaProtocol? EncoderProtocol { get; set; }
public MediaSourceType Type { get; set; }
public string Container { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public long? Size { get; set; }
public string Name { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the media is remote.
/// Differentiate internet url vs local network.
2018-12-27 23:27:57 +00:00
/// </summary>
public bool IsRemote { get; set; }
public string ETag { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public long? RunTimeTicks { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public bool ReadAtNativeFramerate { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public bool IgnoreDts { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public bool IgnoreIndex { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public bool GenPtsInput { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public bool SupportsTranscoding { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public bool SupportsDirectStream { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public bool SupportsDirectPlay { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public bool IsInfiniteStream { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public bool RequiresOpening { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public string OpenToken { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public bool RequiresClosing { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public string LiveStreamId { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public int? BufferMs { get; set; }
public bool RequiresLooping { get; set; }
public bool SupportsProbing { get; set; }
public VideoType? VideoType { get; set; }
public IsoType? IsoType { get; set; }
public Video3DFormat? Video3DFormat { get; set; }
public List<MediaStream> MediaStreams { get; set; }
2019-12-26 22:20:31 +00:00
public IReadOnlyList<MediaAttachment> MediaAttachments { get; set; }
2018-12-27 23:27:57 +00:00
public string[] Formats { get; set; }
public int? Bitrate { get; set; }
public TransportStreamTimestamp? Timestamp { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public Dictionary<string, string> RequiredHttpHeaders { get; set; }
public string TranscodingUrl { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public string TranscodingSubProtocol { get; set; }
2020-06-15 21:43:52 +00:00
2018-12-27 23:27:57 +00:00
public string TranscodingContainer { get; set; }
public int? AnalyzeDurationMs { get; set; }
[JsonIgnore]
public TranscodeReason[] TranscodeReasons { get; set; }
public int? DefaultAudioStreamIndex { get; set; }
public int? DefaultSubtitleStreamIndex { get; set; }
[JsonIgnore]
public MediaStream VideoStream
2018-12-27 23:27:57 +00:00
{
get
{
foreach (var i in MediaStreams)
{
if (i.Type == MediaStreamType.Video)
{
return i;
}
}
return null;
}
2018-12-27 23:27:57 +00:00
}
public void InferTotalBitrate(bool force = false)
{
if (MediaStreams == null)
{
return;
}
if (!force && Bitrate.HasValue)
{
return;
}
var bitrate = 0;
foreach (var stream in MediaStreams)
{
if (!stream.IsExternal)
{
bitrate += stream.BitRate ?? 0;
}
}
if (bitrate > 0)
{
Bitrate = bitrate;
}
}
public MediaStream GetDefaultAudioStream(int? defaultIndex)
{
if (defaultIndex.HasValue)
{
var val = defaultIndex.Value;
2019-01-13 20:37:13 +00:00
foreach (var i in MediaStreams)
2018-12-27 23:27:57 +00:00
{
if (i.Type == MediaStreamType.Audio && i.Index == val)
{
return i;
}
}
}
2019-01-13 20:37:13 +00:00
foreach (var i in MediaStreams)
2018-12-27 23:27:57 +00:00
{
if (i.Type == MediaStreamType.Audio && i.IsDefault)
{
return i;
}
}
2019-01-13 20:37:13 +00:00
foreach (var i in MediaStreams)
2018-12-27 23:27:57 +00:00
{
if (i.Type == MediaStreamType.Audio)
{
return i;
}
}
return null;
}
public MediaStream GetMediaStream(MediaStreamType type, int index)
{
2019-01-13 20:37:13 +00:00
foreach (var i in MediaStreams)
2018-12-27 23:27:57 +00:00
{
if (i.Type == type && i.Index == index)
{
return i;
}
}
return null;
}
public int? GetStreamCount(MediaStreamType type)
{
int numMatches = 0;
int numStreams = 0;
2019-01-13 20:37:13 +00:00
foreach (var i in MediaStreams)
2018-12-27 23:27:57 +00:00
{
numStreams++;
if (i.Type == type)
{
numMatches++;
}
}
if (numStreams == 0)
{
return null;
}
return numMatches;
}
public bool? IsSecondaryAudio(MediaStream stream)
{
// Look for the first audio track marked as default
2019-01-13 20:37:13 +00:00
foreach (var currentStream in MediaStreams)
2018-12-27 23:27:57 +00:00
{
if (currentStream.Type == MediaStreamType.Audio && currentStream.IsDefault)
{
return currentStream.Index != stream.Index;
2018-12-27 23:27:57 +00:00
}
}
// Look for the first audio track
2019-01-13 20:37:13 +00:00
foreach (var currentStream in MediaStreams)
2018-12-27 23:27:57 +00:00
{
if (currentStream.Type == MediaStreamType.Audio)
{
return currentStream.Index != stream.Index;
}
}
return null;
}
}
}