From 93e535d3a143d092effb37e529e5682c3d11802a Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Tue, 26 Mar 2019 22:56:05 +0100 Subject: Trying to make sense of the streaming code Mostly small changes as I was looking through the code. * async void -> async Task * Properly implemented dispose methods * Pass the logstream directly to the JobLogger * Style fixes --- MediaBrowser.Controller/MediaEncoding/JobLogger.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'MediaBrowser.Controller/MediaEncoding/JobLogger.cs') diff --git a/MediaBrowser.Controller/MediaEncoding/JobLogger.cs b/MediaBrowser.Controller/MediaEncoding/JobLogger.cs index 2755bf581..d0d5ebfd6 100644 --- a/MediaBrowser.Controller/MediaEncoding/JobLogger.cs +++ b/MediaBrowser.Controller/MediaEncoding/JobLogger.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.IO; using System.Linq; using System.Text; +using System.Threading.Tasks; using MediaBrowser.Model.Extensions; using Microsoft.Extensions.Logging; @@ -18,10 +19,11 @@ namespace MediaBrowser.Controller.MediaEncoding _logger = logger; } - public async void StartStreamingLog(EncodingJobInfo state, Stream source, Stream target) + public async Task StartStreamingLog(EncodingJobInfo state, Stream source, Stream target) { try { + using (target) using (var reader = new StreamReader(source)) { while (!reader.EndOfStream && reader.BaseStream.CanRead) @@ -97,8 +99,7 @@ namespace MediaBrowser.Controller.MediaEncoding { var currentMs = startMs + val.TotalMilliseconds; - var percentVal = currentMs / totalMs; - percent = 100 * percentVal; + percent = 100 * currentMs / totalMs; transcodingPosition = val; } -- cgit v1.2.3 From b647959ec41373c513ee55075e4c973bfb68dbcd Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 27 Mar 2019 16:26:33 +0100 Subject: Add EnableOutputInSubFolder back --- MediaBrowser.Api/Playback/BaseStreamingService.cs | 12 ++++++++++-- MediaBrowser.Controller/MediaEncoding/JobLogger.cs | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'MediaBrowser.Controller/MediaEncoding/JobLogger.cs') diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 674f3170e..cde6f725a 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -32,6 +32,8 @@ namespace MediaBrowser.Api.Playback { protected static readonly CultureInfo UsCulture = CultureInfo.ReadOnly(new CultureInfo("en-US")); + protected virtual bool EnableOutputInSubFolder => false; + /// /// Gets or sets the application paths. /// @@ -142,10 +144,16 @@ namespace MediaBrowser.Api.Playback data += "-" + (state.Request.DeviceId ?? string.Empty) + "-" + (state.Request.PlaySessionId ?? string.Empty); - var filename = data.GetMD5().ToString("N") + outputFileExtension.ToLowerInvariant(); + var filename = data.GetMD5().ToString("N"); + var ext = outputFileExtension.ToLowerInvariant(); var folder = ServerConfigurationManager.ApplicationPaths.TranscodingTempPath; - return Path.Combine(folder, filename); + if (EnableOutputInSubFolder) + { + return Path.Combine(folder, filename, filename + ext); + } + + return Path.Combine(folder, filename + ext); } protected virtual string GetDefaultH264Preset() => "superfast"; diff --git a/MediaBrowser.Controller/MediaEncoding/JobLogger.cs b/MediaBrowser.Controller/MediaEncoding/JobLogger.cs index d0d5ebfd6..ac989f6ba 100644 --- a/MediaBrowser.Controller/MediaEncoding/JobLogger.cs +++ b/MediaBrowser.Controller/MediaEncoding/JobLogger.cs @@ -99,7 +99,7 @@ namespace MediaBrowser.Controller.MediaEncoding { var currentMs = startMs + val.TotalMilliseconds; - percent = 100 * currentMs / totalMs; + percent = 100.0 * currentMs / totalMs; transcodingPosition = val; } -- cgit v1.2.3