From ffd3101ac63d082e8086311b98db5b2ef3971c12 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 30 Jun 2016 17:04:26 -0400 Subject: [PATCH 1/8] Fixes for nvenc support marked as experimental, since more testing should be done on options --- MediaBrowser.Api/Playback/BaseStreamingService.cs | 14 +++++++------- MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs | 12 ++++++------ .../Encoder/EncoderValidator.cs | 2 +- .../Encoder/EncodingJobFactory.cs | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 01d959d70a..e3eb1e4ba0 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -292,9 +292,9 @@ namespace MediaBrowser.Api.Playback return "h264_qsv"; } - if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "libnvenc", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "nvenc", StringComparison.OrdinalIgnoreCase)) { - return "libnvenc"; + return "h264_nvenc"; } if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "h264_omx", StringComparison.OrdinalIgnoreCase)) { @@ -338,8 +338,8 @@ namespace MediaBrowser.Api.Playback } - // h264 (libnvenc) - else if (string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) + // h264 (h264_nvenc) + else if (string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) { param = "-preset high-performance"; } @@ -412,9 +412,9 @@ namespace MediaBrowser.Api.Playback if (!string.IsNullOrEmpty(state.VideoRequest.Level)) { - // h264_qsv and libnvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format + // h264_qsv and h264_nvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) || - string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) + string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) { switch (state.VideoRequest.Level) { @@ -458,7 +458,7 @@ namespace MediaBrowser.Api.Playback if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) && !string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) && - !string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) + !string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) { param = "-pix_fmt yuv420p " + param; } diff --git a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs index 77bd50b9b3..9eb796360e 100644 --- a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs @@ -607,10 +607,10 @@ namespace MediaBrowser.MediaEncoding.Encoder } - // h264 (libnvenc) - else if (string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) + // h264 (h264_nvenc) + else if (string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) { - param = "-preset high-performance"; + param = "-preset llhq"; } // webm @@ -683,9 +683,9 @@ namespace MediaBrowser.MediaEncoding.Encoder if (!string.IsNullOrEmpty(levelString)) { - // h264_qsv and libnvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format + // h264_qsv and h264_nvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) || - string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) + string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) { switch (levelString) { @@ -729,7 +729,7 @@ namespace MediaBrowser.MediaEncoding.Encoder if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) && !string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) && - !string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) + !string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) { param = "-pix_fmt yuv420p " + param; } diff --git a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs index 133cc8d70e..e2348e8df1 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs @@ -85,7 +85,7 @@ namespace MediaBrowser.MediaEncoding.Encoder "libopus", //"libvorbis", "srt", - "libnvenc", + "h264_nvenc", "h264_qsv" }; diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs index 1770093060..7c4b7fc2f6 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs @@ -562,9 +562,9 @@ namespace MediaBrowser.MediaEncoding.Encoder return "h264_qsv"; } - if (string.Equals(options.HardwareAccelerationType, "libnvenc", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(options.HardwareAccelerationType, "nvenc", StringComparison.OrdinalIgnoreCase)) { - return "libnvenc"; + return "h264_nvenc"; } if (string.Equals(options.HardwareAccelerationType, "h264_omx", StringComparison.OrdinalIgnoreCase)) { From 68df03b87292dca2a87a61fe9fac7ea3b441af74 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 30 Jun 2016 17:26:43 -0400 Subject: [PATCH 2/8] adjust segment length --- MediaBrowser.Api/Playback/BaseStreamingService.cs | 5 +++-- MediaBrowser.Api/Playback/StreamState.cs | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index e3eb1e4ba0..e6ac990bc7 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1645,9 +1645,10 @@ namespace MediaBrowser.Api.Playback var state = new StreamState(MediaSourceManager, Logger) { Request = request, - RequestedUrl = url + RequestedUrl = url, + UserAgent = Request.UserAgent }; - + //if ((Request.UserAgent ?? string.Empty).IndexOf("iphone", StringComparison.OrdinalIgnoreCase) != -1 || // (Request.UserAgent ?? string.Empty).IndexOf("ipad", StringComparison.OrdinalIgnoreCase) != -1 || // (Request.UserAgent ?? string.Empty).IndexOf("ipod", StringComparison.OrdinalIgnoreCase) != -1) diff --git a/MediaBrowser.Api/Playback/StreamState.cs b/MediaBrowser.Api/Playback/StreamState.cs index fbcccbaca2..d0d0337c26 100644 --- a/MediaBrowser.Api/Playback/StreamState.cs +++ b/MediaBrowser.Api/Playback/StreamState.cs @@ -75,7 +75,13 @@ namespace MediaBrowser.Api.Playback { if (string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase)) { - return 10; + var userAgent = UserAgent ?? string.Empty; + if (userAgent.IndexOf("AppleTV", StringComparison.OrdinalIgnoreCase) != -1) + { + return 10; + } + + return 6; } return 3; @@ -99,6 +105,7 @@ namespace MediaBrowser.Api.Playback public string OutputVideoSync = "-1"; public List SupportedAudioCodecs { get; set; } + public string UserAgent { get; set; } public StreamState(IMediaSourceManager mediaSourceManager, ILogger logger) { From c429947a3ce0036aa9d98ba7102ce1aad0c2d608 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 30 Jun 2016 17:30:54 -0400 Subject: [PATCH 3/8] 3.1.49 --- SharedVersion.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SharedVersion.cs b/SharedVersion.cs index b2cbfdebdb..d71611b02a 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,4 +1,4 @@ using System.Reflection; //[assembly: AssemblyVersion("3.1.*")] -[assembly: AssemblyVersion("3.1.48")] +[assembly: AssemblyVersion("3.1.49")] From edfd04129e58cd99441a6bbaa47de7071467f54a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 30 Jun 2016 17:56:14 -0400 Subject: [PATCH 4/8] update namespaces --- .../Networking/CertificateGenerator.cs | 2 +- MediaBrowser.Server.Mono/Security/ASN1.cs | 9 +- .../Security/ASN1Convert.cs | 10 +- .../Security/BitConverterLE.cs | 2 +- .../Security/CryptoConvert.cs | 148 ++++++++---------- MediaBrowser.Server.Mono/Security/PKCS1.cs | 9 +- MediaBrowser.Server.Mono/Security/PKCS12.cs | 51 +----- MediaBrowser.Server.Mono/Security/PKCS7.cs | 11 +- MediaBrowser.Server.Mono/Security/PKCS8.cs | 33 ++-- MediaBrowser.Server.Mono/Security/X501Name.cs | 12 +- .../Security/X509Builder.cs | 4 +- .../Security/X509Certificate.cs | 23 ++- .../Security/X509CertificateBuilder.cs | 2 +- .../Security/X509CertificateCollection.cs | 9 +- .../Security/X509Extension.cs | 11 +- .../Security/X509Extensions.cs | 11 +- .../Security/X520Attributes.cs | 12 +- 17 files changed, 117 insertions(+), 242 deletions(-) diff --git a/MediaBrowser.Server.Mono/Networking/CertificateGenerator.cs b/MediaBrowser.Server.Mono/Networking/CertificateGenerator.cs index 6e37322cbd..58c5bba2d2 100644 --- a/MediaBrowser.Server.Mono/Networking/CertificateGenerator.cs +++ b/MediaBrowser.Server.Mono/Networking/CertificateGenerator.cs @@ -1,8 +1,8 @@ using MediaBrowser.Model.Logging; -using Mono.Security.X509; using System; using System.Collections; using System.Security.Cryptography; +using MediaBrowser.Server.Mono.Security; namespace MediaBrowser.Server.Mono.Networking { diff --git a/MediaBrowser.Server.Mono/Security/ASN1.cs b/MediaBrowser.Server.Mono/Security/ASN1.cs index 751a2ece4e..2fcbde7c16 100644 --- a/MediaBrowser.Server.Mono/Security/ASN1.cs +++ b/MediaBrowser.Server.Mono/Security/ASN1.cs @@ -34,18 +34,13 @@ using System.Collections; using System.IO; using System.Text; -namespace Mono.Security { +namespace MediaBrowser.Server.Mono.Security { // References: // a. ITU ASN.1 standards (free download) // http://www.itu.int/ITU-T/studygroups/com17/languages/ -#if INSIDE_CORLIB - internal -#else - public -#endif - class ASN1 { + public class ASN1 { private byte m_nTag; private byte[] m_aValue; diff --git a/MediaBrowser.Server.Mono/Security/ASN1Convert.cs b/MediaBrowser.Server.Mono/Security/ASN1Convert.cs index 3a1cf93018..f25a5275af 100644 --- a/MediaBrowser.Server.Mono/Security/ASN1Convert.cs +++ b/MediaBrowser.Server.Mono/Security/ASN1Convert.cs @@ -30,23 +30,17 @@ // using System; -using System.Collections; using System.Globalization; using System.Security.Cryptography; using System.Text; -namespace Mono.Security { +namespace MediaBrowser.Server.Mono.Security { // References: // a. ITU ASN.1 standards (free download) // http://www.itu.int/ITU-T/studygroups/com17/languages/ -#if INSIDE_CORLIB - internal -#else - public -#endif - static class ASN1Convert { + public static class ASN1Convert { // RFC3280, section 4.2.1.5 // CAs conforming to this profile MUST always encode certificate // validity dates through the year 2049 as UTCTime; certificate validity diff --git a/MediaBrowser.Server.Mono/Security/BitConverterLE.cs b/MediaBrowser.Server.Mono/Security/BitConverterLE.cs index a787f5015c..29b6ee023b 100644 --- a/MediaBrowser.Server.Mono/Security/BitConverterLE.cs +++ b/MediaBrowser.Server.Mono/Security/BitConverterLE.cs @@ -29,7 +29,7 @@ using System; -namespace Mono.Security +namespace MediaBrowser.Server.Mono.Security { internal sealed class BitConverterLE { diff --git a/MediaBrowser.Server.Mono/Security/CryptoConvert.cs b/MediaBrowser.Server.Mono/Security/CryptoConvert.cs index 3f06114dd0..62c28bd27e 100644 --- a/MediaBrowser.Server.Mono/Security/CryptoConvert.cs +++ b/MediaBrowser.Server.Mono/Security/CryptoConvert.cs @@ -32,14 +32,9 @@ using System.Globalization; using System.Security.Cryptography; using System.Text; -namespace Mono.Security.Cryptography { +namespace MediaBrowser.Server.Mono.Security { -#if INSIDE_CORLIB - internal -#else - public -#endif - sealed class CryptoConvert { + public sealed class CryptoConvert { private CryptoConvert () { @@ -166,32 +161,31 @@ namespace Mono.Security.Cryptography { throw new CryptographicException ("Invalid blob.", e); } -#if INSIDE_CORLIB && MOBILE - RSA rsa = RSA.Create (); - rsa.ImportParameters (rsap); -#else - RSA rsa = null; - try { - rsa = RSA.Create (); - rsa.ImportParameters (rsap); - } - catch (CryptographicException ce) { - // this may cause problem when this code is run under - // the SYSTEM identity on Windows (e.g. ASP.NET). See - // http://bugzilla.ximian.com/show_bug.cgi?id=77559 - try { - CspParameters csp = new CspParameters (); - csp.Flags = CspProviderFlags.UseMachineKeyStore; - rsa = new RSACryptoServiceProvider (csp); - rsa.ImportParameters (rsap); - } - catch { - // rethrow original, not the later, exception if this fails - throw ce; - } - } -#endif - return rsa; + RSA rsa = null; + try + { + rsa = RSA.Create(); + rsa.ImportParameters(rsap); + } + catch (CryptographicException ce) + { + // this may cause problem when this code is run under + // the SYSTEM identity on Windows (e.g. ASP.NET). See + // http://bugzilla.ximian.com/show_bug.cgi?id=77559 + try + { + CspParameters csp = new CspParameters(); + csp.Flags = CspProviderFlags.UseMachineKeyStore; + rsa = new RSACryptoServiceProvider(csp); + rsa.ImportParameters(rsap); + } + catch + { + // rethrow original, not the later, exception if this fails + throw ce; + } + } + return rsa; } static public DSA FromCapiPrivateKeyBlobDSA (byte[] blob) @@ -251,32 +245,31 @@ namespace Mono.Security.Cryptography { throw new CryptographicException ("Invalid blob.", e); } -#if INSIDE_CORLIB && MOBILE - DSA dsa = (DSA)DSA.Create (); - dsa.ImportParameters (dsap); -#else - DSA dsa = null; - try { - dsa = (DSA)DSA.Create (); - dsa.ImportParameters (dsap); - } - catch (CryptographicException ce) { - // this may cause problem when this code is run under - // the SYSTEM identity on Windows (e.g. ASP.NET). See - // http://bugzilla.ximian.com/show_bug.cgi?id=77559 - try { - CspParameters csp = new CspParameters (); - csp.Flags = CspProviderFlags.UseMachineKeyStore; - dsa = new DSACryptoServiceProvider (csp); - dsa.ImportParameters (dsap); - } - catch { - // rethrow original, not the later, exception if this fails - throw ce; - } - } -#endif - return dsa; + DSA dsa = null; + try + { + dsa = (DSA)DSA.Create(); + dsa.ImportParameters(dsap); + } + catch (CryptographicException ce) + { + // this may cause problem when this code is run under + // the SYSTEM identity on Windows (e.g. ASP.NET). See + // http://bugzilla.ximian.com/show_bug.cgi?id=77559 + try + { + CspParameters csp = new CspParameters(); + csp.Flags = CspProviderFlags.UseMachineKeyStore; + dsa = new DSACryptoServiceProvider(csp); + dsa.ImportParameters(dsap); + } + catch + { + // rethrow original, not the later, exception if this fails + throw ce; + } + } + return dsa; } static public byte[] ToCapiPrivateKeyBlob (RSA rsa) @@ -444,26 +437,23 @@ namespace Mono.Security.Cryptography { rsap.Modulus = new byte [byteLen]; Buffer.BlockCopy (blob, pos, rsap.Modulus, 0, byteLen); Array.Reverse (rsap.Modulus); -#if INSIDE_CORLIB && MOBILE - RSA rsa = RSA.Create (); - rsa.ImportParameters (rsap); -#else - RSA rsa = null; - try { - rsa = RSA.Create (); - rsa.ImportParameters (rsap); - } - catch (CryptographicException) { - // this may cause problem when this code is run under - // the SYSTEM identity on Windows (e.g. ASP.NET). See - // http://bugzilla.ximian.com/show_bug.cgi?id=77559 - CspParameters csp = new CspParameters (); - csp.Flags = CspProviderFlags.UseMachineKeyStore; - rsa = new RSACryptoServiceProvider (csp); - rsa.ImportParameters (rsap); - } -#endif - return rsa; + RSA rsa = null; + try + { + rsa = RSA.Create(); + rsa.ImportParameters(rsap); + } + catch (CryptographicException) + { + // this may cause problem when this code is run under + // the SYSTEM identity on Windows (e.g. ASP.NET). See + // http://bugzilla.ximian.com/show_bug.cgi?id=77559 + CspParameters csp = new CspParameters(); + csp.Flags = CspProviderFlags.UseMachineKeyStore; + rsa = new RSACryptoServiceProvider(csp); + rsa.ImportParameters(rsap); + } + return rsa; } catch (Exception e) { throw new CryptographicException ("Invalid blob.", e); diff --git a/MediaBrowser.Server.Mono/Security/PKCS1.cs b/MediaBrowser.Server.Mono/Security/PKCS1.cs index 4e579eee94..86ed6f2d8f 100644 --- a/MediaBrowser.Server.Mono/Security/PKCS1.cs +++ b/MediaBrowser.Server.Mono/Security/PKCS1.cs @@ -31,18 +31,13 @@ using System; using System.Security.Cryptography; -namespace Mono.Security.Cryptography { +namespace MediaBrowser.Server.Mono.Security { // References: // a. PKCS#1: RSA Cryptography Standard // http://www.rsasecurity.com/rsalabs/pkcs/pkcs-1/index.html -#if INSIDE_CORLIB - internal -#else - public -#endif - sealed class PKCS1 { + public sealed class PKCS1 { private PKCS1 () { diff --git a/MediaBrowser.Server.Mono/Security/PKCS12.cs b/MediaBrowser.Server.Mono/Security/PKCS12.cs index fe39b70365..f6c32421e8 100644 --- a/MediaBrowser.Server.Mono/Security/PKCS12.cs +++ b/MediaBrowser.Server.Mono/Security/PKCS12.cs @@ -37,17 +37,9 @@ using System.IO; using System.Security.Cryptography; using System.Text; -using Mono.Security; -using Mono.Security.Cryptography; +namespace MediaBrowser.Server.Mono.Security { -namespace Mono.Security.X509 { - -#if INSIDE_CORLIB - internal -#else - public -#endif - class PKCS5 { + public class PKCS5 { public const string pbeWithMD2AndDESCBC = "1.2.840.113549.1.5.1"; public const string pbeWithMD5AndDESCBC = "1.2.840.113549.1.5.3"; @@ -59,12 +51,7 @@ namespace Mono.Security.X509 { public PKCS5 () {} } -#if INSIDE_CORLIB - internal -#else - public -#endif - class PKCS9 { + public class PKCS9 { public const string friendlyName = "1.2.840.113549.1.9.20"; public const string localKeyId = "1.2.840.113549.1.9.21"; @@ -92,12 +79,7 @@ namespace Mono.Security.X509 { } -#if INSIDE_CORLIB - internal -#else - public -#endif - class PKCS12 : ICloneable { + public class PKCS12 : ICloneable { public const string pbeWithSHAAnd128BitRC4 = "1.2.840.113549.1.12.1.1"; public const string pbeWithSHAAnd40BitRC4 = "1.2.840.113549.1.12.1.2"; @@ -657,29 +639,8 @@ namespace Mono.Security.X509 { } SymmetricAlgorithm sa = null; -#if INSIDE_CORLIB && FULL_AOT_RUNTIME - // we do not want CryptoConfig to bring the whole crypto stack - // in particular Rijndael which is not supported by CommonCrypto - switch (algorithm) { - case "DES": - sa = DES.Create (); - break; - case "RC2": - sa = RC2.Create (); - break; - case "TripleDES": - sa = TripleDES.Create (); - break; - case "RC4": - sa = RC4.Create (); - break; - default: - throw new NotSupportedException (algorithm); - } -#else - sa = SymmetricAlgorithm.Create (algorithm); -#endif - sa.Key = pd.DeriveKey (keyLength); + sa = SymmetricAlgorithm.Create(algorithm); + sa.Key = pd.DeriveKey (keyLength); // IV required only for block ciphers (not stream ciphers) if (ivLength > 0) { sa.IV = pd.DeriveIV (ivLength); diff --git a/MediaBrowser.Server.Mono/Security/PKCS7.cs b/MediaBrowser.Server.Mono/Security/PKCS7.cs index d7e93569d8..7a34580e9f 100644 --- a/MediaBrowser.Server.Mono/Security/PKCS7.cs +++ b/MediaBrowser.Server.Mono/Security/PKCS7.cs @@ -33,16 +33,9 @@ using System; using System.Collections; using System.Security.Cryptography; -using Mono.Security.X509; +namespace MediaBrowser.Server.Mono.Security { -namespace Mono.Security { - -#if INSIDE_CORLIB - internal -#else - public -#endif - sealed class PKCS7 { + public sealed class PKCS7 { public class Oid { // pkcs 1 diff --git a/MediaBrowser.Server.Mono/Security/PKCS8.cs b/MediaBrowser.Server.Mono/Security/PKCS8.cs index 352e4649b0..b2f28f3188 100644 --- a/MediaBrowser.Server.Mono/Security/PKCS8.cs +++ b/MediaBrowser.Server.Mono/Security/PKCS8.cs @@ -33,14 +33,9 @@ using System; using System.Collections; using System.Security.Cryptography; -using Mono.Security.X509; +namespace MediaBrowser.Server.Mono.Security { -namespace Mono.Security.Cryptography { - -#if !INSIDE_CORLIB - public -#endif - sealed class PKCS8 { + public sealed class PKCS8 { public enum KeyInfo { PrivateKey, @@ -277,21 +272,15 @@ namespace Mono.Security.Cryptography { rsa.ImportParameters (param); } catch (CryptographicException) { -#if MONOTOUCH - // there's no machine-wide store available for iOS so we can drop the dependency on - // CspParameters (which drops other things, like XML key persistance, unless used elsewhere) - throw; -#else - // this may cause problem when this code is run under - // the SYSTEM identity on Windows (e.g. ASP.NET). See - // http://bugzilla.ximian.com/show_bug.cgi?id=77559 - CspParameters csp = new CspParameters (); - csp.Flags = CspProviderFlags.UseMachineKeyStore; - rsa = new RSACryptoServiceProvider (csp); - rsa.ImportParameters (param); -#endif - } - return rsa; + // this may cause problem when this code is run under + // the SYSTEM identity on Windows (e.g. ASP.NET). See + // http://bugzilla.ximian.com/show_bug.cgi?id=77559 + CspParameters csp = new CspParameters(); + csp.Flags = CspProviderFlags.UseMachineKeyStore; + rsa = new RSACryptoServiceProvider(csp); + rsa.ImportParameters(param); + } + return rsa; } /* diff --git a/MediaBrowser.Server.Mono/Security/X501Name.cs b/MediaBrowser.Server.Mono/Security/X501Name.cs index 54279c1d25..d77158e450 100644 --- a/MediaBrowser.Server.Mono/Security/X501Name.cs +++ b/MediaBrowser.Server.Mono/Security/X501Name.cs @@ -31,10 +31,7 @@ using System; using System.Globalization; using System.Text; -using Mono.Security; -using Mono.Security.Cryptography; - -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { // References: // 1. Information technology - Open Systems Interconnection - The Directory: Models @@ -49,12 +46,7 @@ namespace Mono.Security.X509 { * * RelativeDistinguishedName ::= SET OF AttributeTypeAndValue */ -#if INSIDE_CORLIB - internal -#else - public -#endif - sealed class X501 { + public sealed class X501 { static byte[] countryName = { 0x55, 0x04, 0x06 }; static byte[] organizationName = { 0x55, 0x04, 0x0A }; diff --git a/MediaBrowser.Server.Mono/Security/X509Builder.cs b/MediaBrowser.Server.Mono/Security/X509Builder.cs index 95926ae3fd..4801f3d8a2 100644 --- a/MediaBrowser.Server.Mono/Security/X509Builder.cs +++ b/MediaBrowser.Server.Mono/Security/X509Builder.cs @@ -33,9 +33,7 @@ using System; using System.Globalization; using System.Security.Cryptography; -using Mono.Security; - -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { public abstract class X509Builder { diff --git a/MediaBrowser.Server.Mono/Security/X509Certificate.cs b/MediaBrowser.Server.Mono/Security/X509Certificate.cs index 5b356e2e2c..fa817d9597 100644 --- a/MediaBrowser.Server.Mono/Security/X509Certificate.cs +++ b/MediaBrowser.Server.Mono/Security/X509Certificate.cs @@ -31,26 +31,21 @@ using System; using System.Runtime.Serialization; using System.Security.Cryptography; -using SSCX = System.Security.Cryptography.X509Certificates; using System.Security.Permissions; using System.Text; -using Mono.Security.Cryptography; -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { - // References: - // a. Internet X.509 Public Key Infrastructure Certificate and CRL Profile - // http://www.ietf.org/rfc/rfc3280.txt - // b. ITU ASN.1 standards (free download) - // http://www.itu.int/ITU-T/studygroups/com17/languages/ + // References: + // a. Internet X.509 Public Key Infrastructure Certificate and CRL Profile + // http://www.ietf.org/rfc/rfc3280.txt + // b. ITU ASN.1 standards (free download) + // http://www.itu.int/ITU-T/studygroups/com17/languages/ -#if INSIDE_CORLIB - internal class X509Certificate : ISerializable { -#else - public class X509Certificate : ISerializable { -#endif + public class X509Certificate : ISerializable + { - private ASN1 decoder; + private ASN1 decoder; private byte[] m_encodedcert; private DateTime m_from; diff --git a/MediaBrowser.Server.Mono/Security/X509CertificateBuilder.cs b/MediaBrowser.Server.Mono/Security/X509CertificateBuilder.cs index 3ee2816283..9b51d9e4ec 100644 --- a/MediaBrowser.Server.Mono/Security/X509CertificateBuilder.cs +++ b/MediaBrowser.Server.Mono/Security/X509CertificateBuilder.cs @@ -32,7 +32,7 @@ using System; using System.Security.Cryptography; -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { // From RFC3280 /* * Certificate ::= SEQUENCE { diff --git a/MediaBrowser.Server.Mono/Security/X509CertificateCollection.cs b/MediaBrowser.Server.Mono/Security/X509CertificateCollection.cs index 3fd834b0cf..6bb465b283 100644 --- a/MediaBrowser.Server.Mono/Security/X509CertificateCollection.cs +++ b/MediaBrowser.Server.Mono/Security/X509CertificateCollection.cs @@ -31,15 +31,10 @@ using System; using System.Collections; -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { [Serializable] -#if INSIDE_CORLIB - internal -#else - public -#endif - class X509CertificateCollection : CollectionBase, IEnumerable { + public class X509CertificateCollection : CollectionBase, IEnumerable { public X509CertificateCollection () { diff --git a/MediaBrowser.Server.Mono/Security/X509Extension.cs b/MediaBrowser.Server.Mono/Security/X509Extension.cs index 202be51320..984c3542b4 100644 --- a/MediaBrowser.Server.Mono/Security/X509Extension.cs +++ b/MediaBrowser.Server.Mono/Security/X509Extension.cs @@ -31,9 +31,7 @@ using System; using System.Globalization; using System.Text; -using Mono.Security; - -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { /* * Extension ::= SEQUENCE { * extnID OBJECT IDENTIFIER, @@ -41,12 +39,7 @@ namespace Mono.Security.X509 { * extnValue OCTET STRING * } */ -#if INSIDE_CORLIB - internal -#else - public -#endif - class X509Extension { + public class X509Extension { protected string extnOid; protected bool extnCritical; diff --git a/MediaBrowser.Server.Mono/Security/X509Extensions.cs b/MediaBrowser.Server.Mono/Security/X509Extensions.cs index cb8e15defa..b86fe1c401 100644 --- a/MediaBrowser.Server.Mono/Security/X509Extensions.cs +++ b/MediaBrowser.Server.Mono/Security/X509Extensions.cs @@ -32,20 +32,13 @@ using System; using System.Collections; -using Mono.Security; - -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { /* * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension * * Note: 1..MAX -> There shouldn't be 0 Extensions in the ASN1 structure */ -#if INSIDE_CORLIB - internal -#else - public -#endif - sealed class X509ExtensionCollection : CollectionBase, IEnumerable { + public sealed class X509ExtensionCollection : CollectionBase, IEnumerable { private bool readOnly; diff --git a/MediaBrowser.Server.Mono/Security/X520Attributes.cs b/MediaBrowser.Server.Mono/Security/X520Attributes.cs index 53ad424b51..a61d31ad9f 100644 --- a/MediaBrowser.Server.Mono/Security/X520Attributes.cs +++ b/MediaBrowser.Server.Mono/Security/X520Attributes.cs @@ -28,12 +28,9 @@ // using System; -using System.Globalization; using System.Text; -using Mono.Security; - -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { // References: // 1. Information technology - Open Systems Interconnection - The Directory: Selected attribute types @@ -55,12 +52,7 @@ namespace Mono.Security.X509 { * * AttributeValue ::= ANY DEFINED BY AttributeType */ -#if INSIDE_CORLIB - internal -#else - public -#endif - class X520 { + public class X520 { public abstract class AttributeTypeAndValue { private string oid; From 106087b68508c0947a7073a97f6d65f1ca8ada32 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 30 Jun 2016 19:17:49 -0400 Subject: [PATCH 5/8] add logging --- .../Configuration/BaseConfigurationManager.cs | 1 + .../HttpClientManager/HttpClientManager.cs | 2 ++ .../Serialization/JsonSerializer.cs | 2 +- .../Serialization/XmlSerializer.cs | 3 +- .../Updates/InstallationManager.cs | 1 + .../Localization/LocalizationManager.cs | 10 +++++-- .../Persistence/SqliteItemRepository.cs | 2 +- MediaBrowser.Server.Mono/Security/PKCS12.cs | 29 ------------------- .../ApplicationHost.cs | 4 +-- 9 files changed, 18 insertions(+), 36 deletions(-) diff --git a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs index 7f9299ff2c..fa15023ca5 100644 --- a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs +++ b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs @@ -123,6 +123,7 @@ namespace MediaBrowser.Common.Implementations.Configuration /// public void SaveConfiguration() { + Logger.Info("Saving system configuration"); var path = CommonApplicationPaths.SystemConfigurationFilePath; Directory.CreateDirectory(Path.GetDirectoryName(path)); diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 5c70179a83..2b7cc10aab 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -296,6 +296,8 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager private async Task GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url) { + _logger.Info("Checking for cache file {0}", responseCachePath); + try { if (_fileSystem.GetLastWriteTimeUtc(responseCachePath).Add(cacheLength) > DateTime.UtcNow) diff --git a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs index 5dbbe53731..dfd4b02d01 100644 --- a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs +++ b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs @@ -68,7 +68,7 @@ namespace MediaBrowser.Common.Implementations.Serialization private Stream OpenFile(string path) { - _logger.Debug("Deserializing file {0}", path); + _logger.Info("Deserializing file {0}", path); return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 131072); } diff --git a/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs index 290524921e..5996f02d3c 100644 --- a/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs +++ b/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs @@ -80,6 +80,7 @@ namespace MediaBrowser.Common.Implementations.Serialization /// The file. public void SerializeToFile(object obj, string file) { + _logger.Info("Serializing to file {0}", file); using (var stream = new FileStream(file, FileMode.Create)) { SerializeToStream(obj, stream); @@ -94,7 +95,7 @@ namespace MediaBrowser.Common.Implementations.Serialization /// System.Object. public object DeserializeFromFile(Type type, string file) { - _logger.Debug("Deserializing file {0}", file); + _logger.Info("Deserializing file {0}", file); using (var stream = _fileSystem.OpenRead(file)) { return DeserializeFromStream(type, stream); diff --git a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs index 5c82ccb0e7..8c7646209c 100644 --- a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs @@ -193,6 +193,7 @@ namespace MediaBrowser.Common.Implementations.Updates /// Task{List{PackageInfo}}. public async Task> GetAvailablePackagesWithoutRegistrationInfo(CancellationToken cancellationToken) { + _logger.Info("Opening {0}", PackageCachePath); try { using (var stream = _fileSystem.OpenRead(PackageCachePath)) diff --git a/MediaBrowser.Server.Implementations/Localization/LocalizationManager.cs b/MediaBrowser.Server.Implementations/Localization/LocalizationManager.cs index 0c627d7519..ec544dd70c 100644 --- a/MediaBrowser.Server.Implementations/Localization/LocalizationManager.cs +++ b/MediaBrowser.Server.Implementations/Localization/LocalizationManager.cs @@ -12,6 +12,7 @@ using System.IO; using System.Linq; using System.Reflection; using CommonIO; +using MediaBrowser.Model.Logging; namespace MediaBrowser.Server.Implementations.Localization { @@ -35,6 +36,7 @@ namespace MediaBrowser.Server.Implementations.Localization private readonly IFileSystem _fileSystem; private readonly IJsonSerializer _jsonSerializer; + private readonly ILogger _logger; /// /// Initializes a new instance of the class. @@ -42,11 +44,12 @@ namespace MediaBrowser.Server.Implementations.Localization /// The configuration manager. /// The file system. /// The json serializer. - public LocalizationManager(IServerConfigurationManager configurationManager, IFileSystem fileSystem, IJsonSerializer jsonSerializer) + public LocalizationManager(IServerConfigurationManager configurationManager, IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger) { _configurationManager = configurationManager; _fileSystem = fileSystem; _jsonSerializer = jsonSerializer; + _logger = logger; ExtractAll(); } @@ -75,7 +78,10 @@ namespace MediaBrowser.Server.Implementations.Localization { using (var stream = type.Assembly.GetManifestResourceStream(resource)) { - using (var fs = _fileSystem.GetFileStream(Path.Combine(localizationPath, filename), FileMode.Create, FileAccess.Write, FileShare.Read)) + var target = Path.Combine(localizationPath, filename); + _logger.Info("Extracting ratings to {0}", target); + + using (var fs = _fileSystem.GetFileStream(target, FileMode.Create, FileAccess.Write, FileShare.Read)) { stream.CopyTo(fs); } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 5d017880ca..2a22fc537a 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -3862,7 +3862,7 @@ namespace MediaBrowser.Server.Implementations.Persistence ? (CommandBehavior.SequentialAccess | CommandBehavior.SingleResult) : CommandBehavior.SequentialAccess; - Logger.Debug("GetItemValues: " + cmd.CommandText); + //Logger.Debug("GetItemValues: " + cmd.CommandText); using (var reader = cmd.ExecuteReader(commandBehavior)) { diff --git a/MediaBrowser.Server.Mono/Security/PKCS12.cs b/MediaBrowser.Server.Mono/Security/PKCS12.cs index f6c32421e8..b5da09c630 100644 --- a/MediaBrowser.Server.Mono/Security/PKCS12.cs +++ b/MediaBrowser.Server.Mono/Security/PKCS12.cs @@ -1929,34 +1929,5 @@ namespace MediaBrowser.Server.Mono.Security { password_max_length = value; } } - - // static methods - - static private byte[] LoadFile (string filename) - { - byte[] data = null; - using (FileStream fs = File.OpenRead (filename)) { - data = new byte [fs.Length]; - fs.Read (data, 0, data.Length); - fs.Close (); - } - return data; - } - - static public PKCS12 LoadFromFile (string filename) - { - if (filename == null) - throw new ArgumentNullException ("filename"); - - return new PKCS12 (LoadFile (filename)); - } - - static public PKCS12 LoadFromFile (string filename, string password) - { - if (filename == null) - throw new ArgumentNullException ("filename"); - - return new PKCS12 (LoadFile (filename), password); - } } } diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 1e5c54d93c..755dec6da5 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -418,7 +418,7 @@ namespace MediaBrowser.Server.Startup.Common RegisterSingleInstance(ServerConfigurationManager); - LocalizationManager = new LocalizationManager(ServerConfigurationManager, FileSystemManager, JsonSerializer); + LocalizationManager = new LocalizationManager(ServerConfigurationManager, FileSystemManager, JsonSerializer, LogManager.GetLogger("LocalizationManager")); RegisterSingleInstance(LocalizationManager); RegisterSingleInstance(() => new BdInfoExaminer()); @@ -489,7 +489,7 @@ namespace MediaBrowser.Server.Startup.Common var encryptionManager = new EncryptionManager(); RegisterSingleInstance(encryptionManager); - ConnectManager = new ConnectManager(LogManager.GetLogger("Connect"), ApplicationPaths, JsonSerializer, encryptionManager, HttpClient, this, ServerConfigurationManager, UserManager, ProviderManager, SecurityManager, FileSystemManager); + ConnectManager = new ConnectManager(LogManager.GetLogger("ConnectManager"), ApplicationPaths, JsonSerializer, encryptionManager, HttpClient, this, ServerConfigurationManager, UserManager, ProviderManager, SecurityManager, FileSystemManager); RegisterSingleInstance(ConnectManager); DeviceManager = new DeviceManager(new DeviceRepository(ApplicationPaths, JsonSerializer, LogManager.GetLogger("DeviceManager"), FileSystemManager), UserManager, FileSystemManager, LibraryMonitor, ServerConfigurationManager, LogManager.GetLogger("DeviceManager"), NetworkManager); From 580a68d19c52a48792c0d714da98e99b08a51b1d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 30 Jun 2016 21:06:18 -0400 Subject: [PATCH 6/8] update startup tests --- .../Serialization/JsonSerializer.cs | 2 +- .../Serialization/XmlSerializer.cs | 4 ++-- .../Encoder/EncoderValidator.cs | 12 +++++++----- .../Subtitles/SubtitleEncoder.cs | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs index dfd4b02d01..5dbbe53731 100644 --- a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs +++ b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs @@ -68,7 +68,7 @@ namespace MediaBrowser.Common.Implementations.Serialization private Stream OpenFile(string path) { - _logger.Info("Deserializing file {0}", path); + _logger.Debug("Deserializing file {0}", path); return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 131072); } diff --git a/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs index 5996f02d3c..756741e0da 100644 --- a/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs +++ b/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs @@ -80,7 +80,7 @@ namespace MediaBrowser.Common.Implementations.Serialization /// The file. public void SerializeToFile(object obj, string file) { - _logger.Info("Serializing to file {0}", file); + _logger.Debug("Serializing to file {0}", file); using (var stream = new FileStream(file, FileMode.Create)) { SerializeToStream(obj, stream); @@ -95,7 +95,7 @@ namespace MediaBrowser.Common.Implementations.Serialization /// System.Object. public object DeserializeFromFile(Type type, string file) { - _logger.Info("Deserializing file {0}", file); + _logger.Debug("Deserializing file {0}", file); using (var stream = _fileSystem.OpenRead(file)) { return DeserializeFromStream(type, stream); diff --git a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs index e2348e8df1..23e3d0fa6e 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs @@ -78,17 +78,19 @@ namespace MediaBrowser.MediaEncoding.Encoder "libx265", "mpeg4", "msmpeg4", - //"libvpx", - //"libvpx-vp9", + "libvpx", + "libvpx-vp9", "aac", "libmp3lame", "libopus", - //"libvorbis", + "libvorbis", "srt", "h264_nvenc", "h264_qsv" }; + output = output ?? string.Empty; + foreach (var codec in required) { var srch = " " + codec + " "; @@ -116,7 +118,7 @@ namespace MediaBrowser.MediaEncoding.Encoder WindowStyle = ProcessWindowStyle.Hidden, ErrorDialog = false, RedirectStandardOutput = true, - RedirectStandardError = true + //RedirectStandardError = true } }; @@ -126,7 +128,7 @@ namespace MediaBrowser.MediaEncoding.Encoder try { - process.BeginErrorReadLine(); + //process.BeginErrorReadLine(); return process.StandardOutput.ReadToEnd(); } diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs index 25adbcdb0c..9a83aba88b 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs @@ -455,7 +455,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles throw; } - + var logTask = process.StandardError.BaseStream.CopyToAsync(logFileStream); var ranToCompletion = process.WaitForExit(60000); From 00634b62c53d145e3dc6ad707dfbe98cb21bfa5a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 30 Jun 2016 22:35:18 -0400 Subject: [PATCH 7/8] remove standard output redirect on image extractions --- .../MediaEncoding/IMediaEncoder.cs | 6 +-- .../Encoder/EncoderValidator.cs | 5 +-- .../Encoder/MediaEncoder.cs | 37 +++++++------------ .../MediaInfo/AudioImageProvider.cs | 15 +++++--- .../MediaInfo/VideoImageProvider.cs | 9 +++-- .../MediaEncoder/EncodingManager.cs | 14 ++++--- 6 files changed, 41 insertions(+), 45 deletions(-) diff --git a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs index 62377b19e0..c8a8caa917 100644 --- a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs +++ b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs @@ -35,7 +35,7 @@ namespace MediaBrowser.Controller.MediaEncoding /// Index of the image stream. /// The cancellation token. /// Task{Stream}. - Task ExtractAudioImage(string path, int? imageStreamIndex, CancellationToken cancellationToken); + Task ExtractAudioImage(string path, int? imageStreamIndex, CancellationToken cancellationToken); /// /// Extracts the video image. @@ -46,9 +46,9 @@ namespace MediaBrowser.Controller.MediaEncoding /// The offset. /// The cancellation token. /// Task{Stream}. - Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, CancellationToken cancellationToken); + Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, CancellationToken cancellationToken); - Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, int? imageStreamIndex, CancellationToken cancellationToken); + Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, int? imageStreamIndex, CancellationToken cancellationToken); /// /// Extracts the video images on interval. diff --git a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs index 23e3d0fa6e..859452362a 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs @@ -117,8 +117,7 @@ namespace MediaBrowser.MediaEncoding.Encoder Arguments = arguments, WindowStyle = ProcessWindowStyle.Hidden, ErrorDialog = false, - RedirectStandardOutput = true, - //RedirectStandardError = true + RedirectStandardOutput = true } }; @@ -128,8 +127,6 @@ namespace MediaBrowser.MediaEncoding.Encoder try { - //process.BeginErrorReadLine(); - return process.StandardOutput.ReadToEnd(); } catch diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 7264ad2d17..68113c0d12 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -767,22 +767,22 @@ namespace MediaBrowser.MediaEncoding.Encoder /// protected readonly CultureInfo UsCulture = new CultureInfo("en-US"); - public Task ExtractAudioImage(string path, int? imageStreamIndex, CancellationToken cancellationToken) + public Task ExtractAudioImage(string path, int? imageStreamIndex, CancellationToken cancellationToken) { return ExtractImage(new[] { path }, imageStreamIndex, MediaProtocol.File, true, null, null, cancellationToken); } - public Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, CancellationToken cancellationToken) + public Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, CancellationToken cancellationToken) { return ExtractImage(inputFiles, null, protocol, false, threedFormat, offset, cancellationToken); } - public Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, int? imageStreamIndex, CancellationToken cancellationToken) + public Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, int? imageStreamIndex, CancellationToken cancellationToken) { return ExtractImage(inputFiles, imageStreamIndex, protocol, false, null, null, cancellationToken); } - private async Task ExtractImage(string[] inputFiles, int? imageStreamIndex, MediaProtocol protocol, bool isAudio, + private async Task ExtractImage(string[] inputFiles, int? imageStreamIndex, MediaProtocol protocol, bool isAudio, Video3DFormat? threedFormat, TimeSpan? offset, CancellationToken cancellationToken) { var resourcePool = isAudio ? _audioImageResourcePool : _videoImageResourcePool; @@ -816,13 +816,16 @@ namespace MediaBrowser.MediaEncoding.Encoder return await ExtractImageInternal(inputArgument, imageStreamIndex, protocol, threedFormat, offset, false, resourcePool, cancellationToken).ConfigureAwait(false); } - private async Task ExtractImageInternal(string inputPath, int? imageStreamIndex, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, bool useIFrame, SemaphoreSlim resourcePool, CancellationToken cancellationToken) + private async Task ExtractImageInternal(string inputPath, int? imageStreamIndex, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, bool useIFrame, SemaphoreSlim resourcePool, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(inputPath)) { throw new ArgumentNullException("inputPath"); } + var tempExtractPath = Path.Combine(ConfigurationManager.ApplicationPaths.TempDirectory, Guid.NewGuid() + ".jpg"); + Directory.CreateDirectory(Path.GetDirectoryName(tempExtractPath)); + // apply some filters to thumbnail extracted below (below) crop any black lines that we made and get the correct ar then scale to width 600. // This filter chain may have adverse effects on recorded tv thumbnails if ar changes during presentation ex. commercials @ diff ar var vf = "scale=600:trunc(600/dar/2)*2"; @@ -855,8 +858,8 @@ namespace MediaBrowser.MediaEncoding.Encoder var mapArg = imageStreamIndex.HasValue ? (" -map 0:v:" + imageStreamIndex.Value.ToString(CultureInfo.InvariantCulture)) : string.Empty; // Use ffmpeg to sample 100 (we can drop this if required using thumbnail=50 for 50 frames) frames and pick the best thumbnail. Have a fall back just in case. - var args = useIFrame ? string.Format("-i {0}{3} -threads 1 -v quiet -vframes 1 -vf \"{2},thumbnail=30\" -f image2 \"{1}\"", inputPath, "-", vf, mapArg) : - string.Format("-i {0}{3} -threads 1 -v quiet -vframes 1 -vf \"{2}\" -f image2 \"{1}\"", inputPath, "-", vf, mapArg); + var args = useIFrame ? string.Format("-i {0}{3} -threads 1 -v quiet -vframes 1 -vf \"{2},thumbnail=30\" -f image2 \"{1}\"", inputPath, tempExtractPath, vf, mapArg) : + string.Format("-i {0}{3} -threads 1 -v quiet -vframes 1 -vf \"{2}\" -f image2 \"{1}\"", inputPath, tempExtractPath, vf, mapArg); var probeSize = GetProbeSizeArgument(new[] { inputPath }, protocol); @@ -880,8 +883,6 @@ namespace MediaBrowser.MediaEncoding.Encoder Arguments = args, WindowStyle = ProcessWindowStyle.Hidden, ErrorDialog = false, - RedirectStandardOutput = true, - RedirectStandardError = true, RedirectStandardInput = true } }; @@ -894,20 +895,10 @@ namespace MediaBrowser.MediaEncoding.Encoder bool ranToCompletion; - var memoryStream = new MemoryStream(); - try { StartProcess(processWrapper); -#pragma warning disable 4014 - // Important - don't await the log task or we won't be able to kill ffmpeg when the user stops playback - process.StandardOutput.BaseStream.CopyToAsync(memoryStream); -#pragma warning restore 4014 - - // MUST read both stdout and stderr asynchronously or a deadlock may occurr - process.BeginErrorReadLine(); - ranToCompletion = process.WaitForExit(10000); if (!ranToCompletion) @@ -922,11 +913,10 @@ namespace MediaBrowser.MediaEncoding.Encoder } var exitCode = ranToCompletion ? processWrapper.ExitCode ?? 0 : -1; + var file = new FileInfo(tempExtractPath); - if (exitCode == -1 || memoryStream.Length == 0) + if (exitCode == -1 || !file.Exists || file.Length == 0) { - memoryStream.Dispose(); - var msg = string.Format("ffmpeg image extraction failed for {0}", inputPath); _logger.Error(msg); @@ -934,8 +924,7 @@ namespace MediaBrowser.MediaEncoding.Encoder throw new ApplicationException(msg); } - memoryStream.Position = 0; - return memoryStream; + return tempExtractPath; } } diff --git a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs index 4b795a474a..bec9280b3a 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs @@ -83,12 +83,17 @@ namespace MediaBrowser.Providers.MediaInfo var imageStreamIndex = imageStream == null ? (int?)null : imageStream.Index; - using (var stream = await _mediaEncoder.ExtractAudioImage(item.Path, imageStreamIndex, cancellationToken).ConfigureAwait(false)) + var tempFile = await _mediaEncoder.ExtractAudioImage(item.Path, imageStreamIndex, cancellationToken).ConfigureAwait(false); + + File.Copy(tempFile, path, true); + + try { - using (var fileStream = _fileSystem.GetFileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, true)) - { - await stream.CopyToAsync(fileStream).ConfigureAwait(false); - } + File.Delete(tempFile); + } + catch + { + } } } diff --git a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs index ff6eef167a..9a1f072cd2 100644 --- a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs @@ -116,7 +116,7 @@ namespace MediaBrowser.Providers.MediaInfo imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("cover", StringComparison.OrdinalIgnoreCase) != -1) ?? imageStreams.FirstOrDefault(); - Stream stream; + string extractedImagePath; if (imageStream != null) { @@ -135,7 +135,7 @@ namespace MediaBrowser.Providers.MediaInfo } } - stream = await _mediaEncoder.ExtractVideoImage(inputPath, protocol, videoIndex, cancellationToken).ConfigureAwait(false); + extractedImagePath = await _mediaEncoder.ExtractVideoImage(inputPath, protocol, videoIndex, cancellationToken).ConfigureAwait(false); } else { @@ -146,14 +146,15 @@ namespace MediaBrowser.Providers.MediaInfo ? TimeSpan.FromTicks(Convert.ToInt64(item.RunTimeTicks.Value * .1)) : TimeSpan.FromSeconds(10); - stream = await _mediaEncoder.ExtractVideoImage(inputPath, protocol, item.Video3DFormat, imageOffset, cancellationToken).ConfigureAwait(false); + extractedImagePath = await _mediaEncoder.ExtractVideoImage(inputPath, protocol, item.Video3DFormat, imageOffset, cancellationToken).ConfigureAwait(false); } return new DynamicImageResponse { Format = ImageFormat.Jpg, HasImage = true, - Stream = stream + Path = extractedImagePath, + Protocol = MediaProtocol.File }; } finally diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs b/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs index a7b0d61c7c..b1b2072c44 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs @@ -139,12 +139,16 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder { _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); - using (var stream = await _encoder.ExtractVideoImage(inputPath, protocol, video.Video3DFormat, time, cancellationToken).ConfigureAwait(false)) + var tempFile = await _encoder.ExtractVideoImage(inputPath, protocol, video.Video3DFormat, time, cancellationToken).ConfigureAwait(false); + File.Copy(tempFile, path, true); + + try + { + File.Delete(tempFile); + } + catch { - using (var fileStream = _fileSystem.GetFileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, true)) - { - await stream.CopyToAsync(fileStream).ConfigureAwait(false); - } + } chapter.ImagePath = path; From 54884d1168a90198c7dcb8fbe7f15fd1e83b057e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 30 Jun 2016 23:06:53 -0400 Subject: [PATCH 8/8] 3.1.50 --- SharedVersion.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SharedVersion.cs b/SharedVersion.cs index d71611b02a..c4dd383324 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,4 +1,4 @@ using System.Reflection; //[assembly: AssemblyVersion("3.1.*")] -[assembly: AssemblyVersion("3.1.49")] +[assembly: AssemblyVersion("3.1.50")]