aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller
diff options
context:
space:
mode:
authorJoshua M. Boniface <joshua@boniface.me>2019-02-02 19:04:10 -0500
committerGitHub <noreply@github.com>2019-02-02 19:04:10 -0500
commit32f393d57fd634ed9771078b5fbf87d4466a927c (patch)
tree522825aab3eb32cf3707d158463d26959d76a6a9 /MediaBrowser.Controller
parent42d5a48491904ae4251e32c17da037a1a5ba77eb (diff)
parent1cdcace0618658d1e99e98c3f539baf3ae72ab14 (diff)
Merge pull request #764 from Bond-009/encoding
Remove dead code, made some functions properly async
Diffstat (limited to 'MediaBrowser.Controller')
-rw-r--r--MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs124
-rw-r--r--MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs22
2 files changed, 40 insertions, 106 deletions
diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs b/MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs
index 1fe8856cc..916d691b8 100644
--- a/MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs
+++ b/MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs
@@ -10,19 +10,13 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Session;
-using Microsoft.Extensions.Logging;
-using System.IO;
using MediaBrowser.Model.Net;
-using MediaBrowser.Controller.Library;
-using System.Threading.Tasks;
namespace MediaBrowser.Controller.MediaEncoding
{
// For now, a common base class until the API and MediaEncoding classes are unified
public class EncodingJobInfo
{
- protected readonly IMediaSourceManager MediaSourceManager;
-
public MediaStream VideoStream { get; set; }
public VideoType VideoType { get; set; }
public Dictionary<string, string> RemoteHttpHeaders { get; set; }
@@ -49,7 +43,6 @@ namespace MediaBrowser.Controller.MediaEncoding
public string OutputFilePath { get; set; }
public string MimeType { get; set; }
- public long? EncodingDurationTicks { get; set; }
public string GetMimeType(string outputPath, bool enableStreamDefault = true)
{
@@ -68,7 +61,12 @@ namespace MediaBrowser.Controller.MediaEncoding
{
if (_transcodeReasons == null)
{
- _transcodeReasons = (BaseRequest.TranscodeReasons ?? string.Empty)
+ if (BaseRequest.TranscodeReasons == null)
+ {
+ return Array.Empty<TranscodeReason>();
+ }
+
+ _transcodeReasons = BaseRequest.TranscodeReasons
.Split(',')
.Where(i => !string.IsNullOrEmpty(i))
.Select(v => (TranscodeReason)Enum.Parse(typeof(TranscodeReason), v, true))
@@ -98,7 +96,8 @@ namespace MediaBrowser.Controller.MediaEncoding
get
{
// For live tv + in progress recordings
- if (string.Equals(InputContainer, "mpegts", StringComparison.OrdinalIgnoreCase) || string.Equals(InputContainer, "ts", StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(InputContainer, "mpegts", StringComparison.OrdinalIgnoreCase)
+ || string.Equals(InputContainer, "ts", StringComparison.OrdinalIgnoreCase))
{
if (!MediaSource.RunTimeTicks.HasValue)
{
@@ -155,15 +154,7 @@ namespace MediaBrowser.Controller.MediaEncoding
}
}
- if (forceDeinterlaceIfSourceIsInterlaced)
- {
- if (isInputInterlaced)
- {
- return true;
- }
- }
-
- return false;
+ return forceDeinterlaceIfSourceIsInterlaced && isInputInterlaced;
}
public string[] GetRequestedProfiles(string codec)
@@ -211,7 +202,8 @@ namespace MediaBrowser.Controller.MediaEncoding
if (!string.IsNullOrEmpty(codec))
{
var value = BaseRequest.GetOption(codec, "maxrefframes");
- if (!string.IsNullOrEmpty(value) && int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
+ if (!string.IsNullOrEmpty(value)
+ && int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
{
return result;
}
@@ -230,7 +222,8 @@ namespace MediaBrowser.Controller.MediaEncoding
if (!string.IsNullOrEmpty(codec))
{
var value = BaseRequest.GetOption(codec, "videobitdepth");
- if (!string.IsNullOrEmpty(value) && int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
+ if (!string.IsNullOrEmpty(value)
+ && int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
{
return result;
}
@@ -249,7 +242,8 @@ namespace MediaBrowser.Controller.MediaEncoding
if (!string.IsNullOrEmpty(codec))
{
var value = BaseRequest.GetOption(codec, "audiobitdepth");
- if (!string.IsNullOrEmpty(value) && int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
+ if (!string.IsNullOrEmpty(value)
+ && int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
{
return result;
}
@@ -264,6 +258,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{
return BaseRequest.MaxAudioChannels;
}
+
if (BaseRequest.AudioChannels.HasValue)
{
return BaseRequest.AudioChannels;
@@ -272,7 +267,8 @@ namespace MediaBrowser.Controller.MediaEncoding
if (!string.IsNullOrEmpty(codec))
{
var value = BaseRequest.GetOption(codec, "audiochannels");
- if (!string.IsNullOrEmpty(value) && int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
+ if (!string.IsNullOrEmpty(value)
+ && int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
{
return result;
}
@@ -294,7 +290,8 @@ namespace MediaBrowser.Controller.MediaEncoding
SupportedSubtitleCodecs = Array.Empty<string>();
}
- public bool IsSegmentedLiveStream => TranscodingType != TranscodingJobType.Progressive && !RunTimeTicks.HasValue;
+ public bool IsSegmentedLiveStream
+ => TranscodingType != TranscodingJobType.Progressive && !RunTimeTicks.HasValue;
public bool EnableBreakOnNonKeyFrames(string videoCodec)
{
@@ -428,11 +425,12 @@ namespace MediaBrowser.Controller.MediaEncoding
{
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
- return VideoStream == null ? null : VideoStream.Level;
+ return VideoStream?.Level;
}
var level = GetRequestedLevel(ActualOutputVideoCodec);
- if (!string.IsNullOrEmpty(level) && double.TryParse(level, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
+ if (!string.IsNullOrEmpty(level)
+ && double.TryParse(level, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
{
return result;
}
@@ -450,7 +448,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
- return VideoStream == null ? null : VideoStream.BitDepth;
+ return VideoStream?.BitDepth;
}
return null;
@@ -467,7 +465,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
- return VideoStream == null ? null : VideoStream.RefFrames;
+ return VideoStream?.RefFrames;
}
return null;
@@ -494,13 +492,14 @@ namespace MediaBrowser.Controller.MediaEncoding
{
get
{
- var defaultValue = string.Equals(OutputContainer, "m2ts", StringComparison.OrdinalIgnoreCase) ?
+ if (BaseRequest.Static)
+ {
+ return InputTimestamp;
+ }
+
+ return string.Equals(OutputContainer, "m2ts", StringComparison.OrdinalIgnoreCase) ?
TransportStreamTimestamp.Valid :
TransportStreamTimestamp.None;
-
- return !BaseRequest.Static
- ? defaultValue
- : InputTimestamp;
}
}
@@ -513,7 +512,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
- return VideoStream == null ? null : VideoStream.PacketLength;
+ return VideoStream?.PacketLength;
}
return null;
@@ -529,7 +528,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
- return VideoStream == null ? null : VideoStream.Profile;
+ return VideoStream?.Profile;
}
var requestedProfile = GetRequestedProfiles(ActualOutputVideoCodec).FirstOrDefault();
@@ -542,42 +541,13 @@ namespace MediaBrowser.Controller.MediaEncoding
}
}
- /// <summary>
- /// Predicts the audio sample rate that will be in the output stream
- /// </summary>
- public string TargetVideoRange
- {
- get
- {
- if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
- {
- return VideoStream == null ? null : VideoStream.VideoRange;
- }
-
- return "SDR";
- }
- }
-
- public string TargetAudioProfile
- {
- get
- {
- if (BaseRequest.Static || string.Equals(OutputAudioCodec, "copy", StringComparison.OrdinalIgnoreCase))
- {
- return AudioStream == null ? null : AudioStream.Profile;
- }
-
- return null;
- }
- }
-
public string TargetVideoCodecTag
{
get
{
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
- return VideoStream == null ? null : VideoStream.CodecTag;
+ return VideoStream?.CodecTag;
}
return null;
@@ -590,7 +560,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
- return VideoStream == null ? null : VideoStream.IsAnamorphic;
+ return VideoStream?.IsAnamorphic;
}
return false;
@@ -605,14 +575,7 @@ namespace MediaBrowser.Controller.MediaEncoding
if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
{
- var stream = VideoStream;
-
- if (stream != null)
- {
- return stream.Codec;
- }
-
- return null;
+ return VideoStream?.Codec;
}
return codec;
@@ -627,14 +590,7 @@ namespace MediaBrowser.Controller.MediaEncoding
if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
{
- var stream = AudioStream;
-
- if (stream != null)
- {
- return stream.Codec;
- }
-
- return null;
+ return AudioStream?.Codec;
}
return codec;
@@ -647,7 +603,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
- return VideoStream == null ? (bool?)null : VideoStream.IsInterlaced;
+ return VideoStream?.IsInterlaced;
}
if (DeInterlace(ActualOutputVideoCodec, true))
@@ -655,7 +611,7 @@ namespace MediaBrowser.Controller.MediaEncoding
return false;
}
- return VideoStream == null ? (bool?)null : VideoStream.IsInterlaced;
+ return VideoStream?.IsInterlaced;
}
}
@@ -665,7 +621,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
- return VideoStream == null ? null : VideoStream.IsAVC;
+ return VideoStream?.IsAVC;
}
return false;
diff --git a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs
index 48055a37e..057e43910 100644
--- a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs
+++ b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs
@@ -82,28 +82,6 @@ namespace MediaBrowser.Controller.MediaEncoding
/// <returns>System.String.</returns>
string GetTimeParameter(long ticks);
- /// <summary>
- /// Encodes the audio.
- /// </summary>
- /// <param name="options">The options.</param>
- /// <param name="progress">The progress.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task.</returns>
- Task<string> EncodeAudio(EncodingJobOptions options,
- IProgress<double> progress,
- CancellationToken cancellationToken);
-
- /// <summary>
- /// Encodes the video.
- /// </summary>
- /// <param name="options">The options.</param>
- /// <param name="progress">The progress.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task&lt;System.String&gt;.</returns>
- Task<string> EncodeVideo(EncodingJobOptions options,
- IProgress<double> progress,
- CancellationToken cancellationToken);
-
Task ConvertImage(string inputPath, string outputPath);
/// <summary>