2020-04-05 09:10:56 -07:00
|
|
|
#nullable disable
|
2020-02-03 17:49:27 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 13:02:23 -07:00
|
|
|
using System;
|
2018-12-27 16:27:57 -07:00
|
|
|
using System.Collections.Generic;
|
2024-09-07 20:08:54 -07:00
|
|
|
using System.ComponentModel;
|
2019-10-15 08:49:49 -07:00
|
|
|
using System.Text.Json.Serialization;
|
2024-03-04 16:44:54 -07:00
|
|
|
using Jellyfin.Data.Enums;
|
|
|
|
using MediaBrowser.Model.Dlna;
|
2019-01-13 12:26:15 -07:00
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.MediaInfo;
|
2018-12-27 16:27:57 -07:00
|
|
|
using MediaBrowser.Model.Session;
|
|
|
|
|
|
|
|
namespace MediaBrowser.Model.Dto
|
|
|
|
{
|
|
|
|
public class MediaSourceInfo
|
|
|
|
{
|
2021-02-20 15:13:04 -07:00
|
|
|
public MediaSourceInfo()
|
|
|
|
{
|
|
|
|
Formats = Array.Empty<string>();
|
2022-01-22 07:40:05 -07:00
|
|
|
MediaStreams = Array.Empty<MediaStream>();
|
2021-02-20 15:13:04 -07:00
|
|
|
MediaAttachments = Array.Empty<MediaAttachment>();
|
|
|
|
RequiredHttpHeaders = new Dictionary<string, string>();
|
|
|
|
SupportsTranscoding = true;
|
|
|
|
SupportsDirectStream = true;
|
|
|
|
SupportsDirectPlay = true;
|
|
|
|
SupportsProbing = true;
|
2024-09-07 20:08:54 -07:00
|
|
|
UseMostCompatibleTranscodingProfile = false;
|
2021-02-20 15:13:04 -07:00
|
|
|
}
|
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public MediaProtocol Protocol { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
public string Path { get; set; }
|
|
|
|
|
|
|
|
public string EncoderPath { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public MediaProtocol? EncoderProtocol { get; set; }
|
|
|
|
|
|
|
|
public MediaSourceType Type { get; set; }
|
|
|
|
|
|
|
|
public string Container { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public long? Size { get; set; }
|
|
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
2021-02-20 15:13:04 -07:00
|
|
|
/// Gets or sets a value indicating whether the media is remote.
|
2020-06-15 15:37:52 -07:00
|
|
|
/// Differentiate internet url vs local network.
|
2018-12-27 16:27:57 -07:00
|
|
|
/// </summary>
|
|
|
|
public bool IsRemote { get; set; }
|
|
|
|
|
|
|
|
public string ETag { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public long? RunTimeTicks { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public bool ReadAtNativeFramerate { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public bool IgnoreDts { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public bool IgnoreIndex { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public bool GenPtsInput { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public bool SupportsTranscoding { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public bool SupportsDirectStream { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public bool SupportsDirectPlay { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public bool IsInfiniteStream { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2024-09-07 20:08:54 -07:00
|
|
|
[DefaultValue(false)]
|
|
|
|
public bool UseMostCompatibleTranscodingProfile { get; set; }
|
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public bool RequiresOpening { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public string OpenToken { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public bool RequiresClosing { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public string LiveStreamId { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07: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; }
|
|
|
|
|
2022-01-22 07:40:05 -07:00
|
|
|
public IReadOnlyList<MediaStream> MediaStreams { get; set; }
|
2018-12-27 16:27:57 -07:00
|
|
|
|
2019-12-26 15:20:31 -07:00
|
|
|
public IReadOnlyList<MediaAttachment> MediaAttachments { get; set; }
|
2019-10-03 08:51:28 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public string[] Formats { get; set; }
|
|
|
|
|
|
|
|
public int? Bitrate { get; set; }
|
|
|
|
|
2024-09-07 20:08:54 -07:00
|
|
|
public int? FallbackMaxStreamingBitrate { get; set; }
|
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public TransportStreamTimestamp? Timestamp { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public Dictionary<string, string> RequiredHttpHeaders { get; set; }
|
|
|
|
|
|
|
|
public string TranscodingUrl { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2024-03-04 16:44:54 -07:00
|
|
|
public MediaStreamProtocol TranscodingSubProtocol { get; set; }
|
2020-06-15 14:43:52 -07:00
|
|
|
|
2018-12-27 16:27:57 -07:00
|
|
|
public string TranscodingContainer { get; set; }
|
|
|
|
|
|
|
|
public int? AnalyzeDurationMs { get; set; }
|
|
|
|
|
2021-02-20 15:13:04 -07:00
|
|
|
[JsonIgnore]
|
2022-01-23 09:37:52 -07:00
|
|
|
public TranscodeReason TranscodeReasons { get; set; }
|
2021-02-20 15:13:04 -07:00
|
|
|
|
|
|
|
public int? DefaultAudioStreamIndex { get; set; }
|
|
|
|
|
|
|
|
public int? DefaultSubtitleStreamIndex { get; set; }
|
|
|
|
|
2024-08-05 05:20:27 -07:00
|
|
|
public bool HasSegments { get; set; }
|
|
|
|
|
2021-02-20 15:13:04 -07:00
|
|
|
[JsonIgnore]
|
|
|
|
public MediaStream VideoStream
|
2018-12-27 16:27:57 -07:00
|
|
|
{
|
2021-02-20 15:13:04 -07:00
|
|
|
get
|
|
|
|
{
|
|
|
|
foreach (var i in MediaStreams)
|
|
|
|
{
|
|
|
|
if (i.Type == MediaStreamType.Video)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2018-12-27 16:27:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void InferTotalBitrate(bool force = false)
|
|
|
|
{
|
2022-12-05 07:00:20 -07:00
|
|
|
if (MediaStreams is null)
|
2018-12-27 16:27:57 -07:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2022-01-23 16:49:14 -07:00
|
|
|
if (defaultIndex.HasValue && defaultIndex != -1)
|
2018-12-27 16:27:57 -07:00
|
|
|
{
|
|
|
|
var val = defaultIndex.Value;
|
|
|
|
|
2019-01-13 13:37:13 -07:00
|
|
|
foreach (var i in MediaStreams)
|
2018-12-27 16:27:57 -07:00
|
|
|
{
|
|
|
|
if (i.Type == MediaStreamType.Audio && i.Index == val)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 13:37:13 -07:00
|
|
|
foreach (var i in MediaStreams)
|
2018-12-27 16:27:57 -07:00
|
|
|
{
|
|
|
|
if (i.Type == MediaStreamType.Audio && i.IsDefault)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 13:37:13 -07:00
|
|
|
foreach (var i in MediaStreams)
|
2018-12-27 16:27:57 -07:00
|
|
|
{
|
|
|
|
if (i.Type == MediaStreamType.Audio)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public MediaStream GetMediaStream(MediaStreamType type, int index)
|
|
|
|
{
|
2019-01-13 13:37:13 -07:00
|
|
|
foreach (var i in MediaStreams)
|
2018-12-27 16:27:57 -07: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 13:37:13 -07:00
|
|
|
foreach (var i in MediaStreams)
|
2018-12-27 16:27:57 -07:00
|
|
|
{
|
|
|
|
numStreams++;
|
|
|
|
if (i.Type == type)
|
|
|
|
{
|
|
|
|
numMatches++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numStreams == 0)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return numMatches;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool? IsSecondaryAudio(MediaStream stream)
|
|
|
|
{
|
2022-10-31 02:50:53 -07:00
|
|
|
if (stream.IsExternal)
|
2018-12-27 16:27:57 -07:00
|
|
|
{
|
2022-10-31 02:50:53 -07:00
|
|
|
return false;
|
2018-12-27 16:27:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Look for the first audio track
|
2019-01-13 13:37:13 -07:00
|
|
|
foreach (var currentStream in MediaStreams)
|
2018-12-27 16:27:57 -07:00
|
|
|
{
|
2022-10-31 02:50:53 -07:00
|
|
|
if (currentStream.Type == MediaStreamType.Audio && !currentStream.IsExternal)
|
2018-12-27 16:27:57 -07:00
|
|
|
{
|
|
|
|
return currentStream.Index != stream.Index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|