You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Model/Dto/MediaSourceInfo.cs

251 lines
6.2 KiB

#nullable disable
#pragma warning disable CS1591
using System;
6 years ago
using System.Collections.Generic;
using System.Text.Json.Serialization;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
6 years ago
using MediaBrowser.Model.Session;
namespace MediaBrowser.Model.Dto
{
public class MediaSourceInfo
{
public MediaSourceInfo()
{
Formats = Array.Empty<string>();
MediaStreams = Array.Empty<MediaStream>();
MediaAttachments = Array.Empty<MediaAttachment>();
RequiredHttpHeaders = new Dictionary<string, string>();
SupportsTranscoding = true;
SupportsDirectStream = true;
SupportsDirectPlay = true;
SupportsProbing = true;
}
6 years ago
public MediaProtocol Protocol { get; set; }
6 years ago
public string Id { get; set; }
public string Path { get; set; }
public string EncoderPath { get; set; }
6 years ago
public MediaProtocol? EncoderProtocol { get; set; }
public MediaSourceType Type { get; set; }
public string Container { get; set; }
6 years ago
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.
6 years ago
/// </summary>
public bool IsRemote { get; set; }
public string ETag { get; set; }
6 years ago
public long? RunTimeTicks { get; set; }
6 years ago
public bool ReadAtNativeFramerate { get; set; }
6 years ago
public bool IgnoreDts { get; set; }
6 years ago
public bool IgnoreIndex { get; set; }
6 years ago
public bool GenPtsInput { get; set; }
6 years ago
public bool SupportsTranscoding { get; set; }
6 years ago
public bool SupportsDirectStream { get; set; }
6 years ago
public bool SupportsDirectPlay { get; set; }
6 years ago
public bool IsInfiniteStream { get; set; }
6 years ago
public bool RequiresOpening { get; set; }
6 years ago
public string OpenToken { get; set; }
6 years ago
public bool RequiresClosing { get; set; }
6 years ago
public string LiveStreamId { get; set; }
6 years ago
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 IReadOnlyList<MediaStream> MediaStreams { get; set; }
6 years ago
public IReadOnlyList<MediaAttachment> MediaAttachments { get; set; }
6 years ago
public string[] Formats { get; set; }
public int? Bitrate { get; set; }
public TransportStreamTimestamp? Timestamp { get; set; }
6 years ago
public Dictionary<string, string> RequiredHttpHeaders { get; set; }
public string TranscodingUrl { get; set; }
6 years ago
public string TranscodingSubProtocol { get; set; }
6 years ago
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
6 years ago
{
get
{
foreach (var i in MediaStreams)
{
if (i.Type == MediaStreamType.Video)
{
return i;
}
}
return null;
}
6 years ago
}
public void InferTotalBitrate(bool force = false)
{
if (MediaStreams is null)
6 years ago
{
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 && defaultIndex != -1)
6 years ago
{
var val = defaultIndex.Value;
foreach (var i in MediaStreams)
6 years ago
{
if (i.Type == MediaStreamType.Audio && i.Index == val)
{
return i;
}
}
}
foreach (var i in MediaStreams)
6 years ago
{
if (i.Type == MediaStreamType.Audio && i.IsDefault)
{
return i;
}
}
foreach (var i in MediaStreams)
6 years ago
{
if (i.Type == MediaStreamType.Audio)
{
return i;
}
}
return null;
}
public MediaStream GetMediaStream(MediaStreamType type, int index)
{
foreach (var i in MediaStreams)
6 years ago
{
if (i.Type == type && i.Index == index)
{
return i;
}
}
return null;
}
public int? GetStreamCount(MediaStreamType type)
{
int numMatches = 0;
int numStreams = 0;
foreach (var i in MediaStreams)
6 years ago
{
numStreams++;
if (i.Type == type)
{
numMatches++;
}
}
if (numStreams == 0)
{
return null;
}
return numMatches;
}
public bool? IsSecondaryAudio(MediaStream stream)
{
if (stream.IsExternal)
6 years ago
{
return false;
6 years ago
}
// Look for the first audio track
foreach (var currentStream in MediaStreams)
6 years ago
{
if (currentStream.Type == MediaStreamType.Audio && !currentStream.IsExternal)
6 years ago
{
return currentStream.Index != stream.Index;
}
}
return null;
}
}
}