diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index 95f7ef6944..a05d7d1b2e 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -1,7 +1,9 @@ using MediaBrowser.Api.Playback; -using MediaBrowser.Controller; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Session; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Session; using System; @@ -33,7 +35,7 @@ namespace MediaBrowser.Api /// /// The application paths /// - private readonly IServerApplicationPaths _appPaths; + private readonly IServerConfigurationManager _config; private readonly ISessionManager _sessionManager; @@ -43,13 +45,13 @@ namespace MediaBrowser.Api /// Initializes a new instance of the class. /// /// The logger. - /// The application paths. /// The session manager. - public ApiEntryPoint(ILogger logger, IServerApplicationPaths appPaths, ISessionManager sessionManager) + /// The configuration. + public ApiEntryPoint(ILogger logger, ISessionManager sessionManager, IServerConfigurationManager config) { Logger = logger; - _appPaths = appPaths; _sessionManager = sessionManager; + _config = config; Instance = this; } @@ -73,12 +75,17 @@ namespace MediaBrowser.Api } } + public EncodingOptions GetEncodingOptions() + { + return _config.GetConfiguration("encoding"); + } + /// /// Deletes the encoded media cache. /// private void DeleteEncodedMediaCache() { - foreach (var file in Directory.EnumerateFiles(_appPaths.TranscodingTempPath, "*", SearchOption.AllDirectories) + foreach (var file in Directory.EnumerateFiles(_config.ApplicationPaths.TranscodingTempPath, "*", SearchOption.AllDirectories) .ToList()) { File.Delete(file); diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 203a62dfcb..683a1f9622 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Configuration; @@ -249,7 +250,7 @@ namespace MediaBrowser.Api.Playback protected EncodingQuality GetQualitySetting() { - var quality = ServerConfigurationManager.Configuration.MediaEncodingQuality; + var quality = ApiEntryPoint.Instance.GetEncodingOptions().MediaEncodingQuality; if (quality == EncodingQuality.Auto) { @@ -310,7 +311,7 @@ namespace MediaBrowser.Api.Playback { get { - var lib = ServerConfigurationManager.Configuration.H264Encoder; + var lib = ApiEntryPoint.Instance.GetEncodingOptions().H264Encoder; if (!string.IsNullOrWhiteSpace(lib)) { @@ -461,7 +462,7 @@ namespace MediaBrowser.Api.Playback { if (state.AudioStream != null && state.AudioStream.Channels.HasValue && state.AudioStream.Channels.Value > 5) { - volParam = ",volume=" + ServerConfigurationManager.Configuration.DownMixAudioBoost.ToString(UsCulture); + volParam = ",volume=" + ApiEntryPoint.Instance.GetEncodingOptions().DownMixAudioBoost.ToString(UsCulture); } } @@ -953,7 +954,7 @@ namespace MediaBrowser.Api.Playback var transcodingId = Guid.NewGuid().ToString("N"); var commandLineArgs = GetCommandLineArguments(outputPath, transcodingId, state, true); - if (ServerConfigurationManager.Configuration.EnableDebugEncodingLogging) + if (ApiEntryPoint.Instance.GetEncodingOptions().EnableDebugLogging) { commandLineArgs = "-loglevel debug " + commandLineArgs; } diff --git a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs index a061420d73..093010124b 100644 --- a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs +++ b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs @@ -233,13 +233,22 @@ namespace MediaBrowser.Common.Implementations.Configuration public void SaveConfiguration(string key, object configuration) { - var configurationType = GetConfigurationType(key); + var configurationStore = GetConfigurationStore(key); + var configurationType = configurationStore.ConfigurationType; if (configuration.GetType() != configurationType) { throw new ArgumentException("Expected configuration type is " + configurationType.Name); } + var validatingStore = configurationStore as IValidatingConfiguration; + if (validatingStore != null) + { + var currentConfiguration = GetConfiguration(key); + + validatingStore.Validate(currentConfiguration, configuration); + } + EventHelper.FireEventIfNotNull(NamedConfigurationUpdating, this, new ConfigurationUpdateEventArgs { Key = key, @@ -267,9 +276,14 @@ namespace MediaBrowser.Common.Implementations.Configuration public Type GetConfigurationType(string key) { - return _configurationStores - .First(i => string.Equals(i.Key, key, StringComparison.OrdinalIgnoreCase)) + return GetConfigurationStore(key) .ConfigurationType; } + + private ConfigurationStore GetConfigurationStore(string key) + { + return _configurationStores + .First(i => string.Equals(i.Key, key, StringComparison.OrdinalIgnoreCase)); + } } } diff --git a/MediaBrowser.Common/Configuration/IConfigurationFactory.cs b/MediaBrowser.Common/Configuration/IConfigurationFactory.cs index d418d0a423..6ed6385360 100644 --- a/MediaBrowser.Common/Configuration/IConfigurationFactory.cs +++ b/MediaBrowser.Common/Configuration/IConfigurationFactory.cs @@ -14,4 +14,9 @@ namespace MediaBrowser.Common.Configuration public Type ConfigurationType { get; set; } } + + public interface IValidatingConfiguration + { + void Validate(object oldConfig, object newConfig); + } } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index c198a58d49..3b9f3a5b23 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -198,16 +198,13 @@ - - - diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingOptions.cs b/MediaBrowser.Controller/MediaEncoding/EncodingOptions.cs deleted file mode 100644 index 26182ebc47..0000000000 --- a/MediaBrowser.Controller/MediaEncoding/EncodingOptions.cs +++ /dev/null @@ -1,80 +0,0 @@ -using MediaBrowser.Controller.Dlna; -using MediaBrowser.Model.Dlna; - -namespace MediaBrowser.Controller.MediaEncoding -{ - public class EncodingOptions - { - /// - /// Gets or sets the item identifier. - /// - /// The item identifier. - public string ItemId { get; set; } - - /// - /// Gets or sets the media source identifier. - /// - /// The media source identifier. - public string MediaSourceId { get; set; } - - /// - /// Gets or sets the device profile. - /// - /// The device profile. - public DeviceProfile DeviceProfile { get; set; } - - /// - /// Gets or sets the output path. - /// - /// The output path. - public string OutputPath { get; set; } - - /// - /// Gets or sets the container. - /// - /// The container. - public string Container { get; set; } - - /// - /// Gets or sets the audio codec. - /// - /// The audio codec. - public string AudioCodec { get; set; } - - /// - /// Gets or sets the start time ticks. - /// - /// The start time ticks. - public long? StartTimeTicks { get; set; } - - /// - /// Gets or sets the maximum channels. - /// - /// The maximum channels. - public int? MaxAudioChannels { get; set; } - - /// - /// Gets or sets the channels. - /// - /// The channels. - public int? AudioChannels { get; set; } - - /// - /// Gets or sets the sample rate. - /// - /// The sample rate. - public int? AudioSampleRate { get; set; } - - /// - /// Gets or sets the bit rate. - /// - /// The bit rate. - public int? AudioBitRate { get; set; } - - /// - /// Gets or sets the maximum audio bit rate. - /// - /// The maximum audio bit rate. - public int? MaxAudioBitRate { get; set; } - } -} diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingResult.cs b/MediaBrowser.Controller/MediaEncoding/EncodingResult.cs deleted file mode 100644 index 75ee90e421..0000000000 --- a/MediaBrowser.Controller/MediaEncoding/EncodingResult.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MediaBrowser.Controller.MediaEncoding -{ - public class EncodingResult - { - public string OutputPath { get; set; } - } -} diff --git a/MediaBrowser.Controller/MediaEncoding/VideoEncodingOptions.cs b/MediaBrowser.Controller/MediaEncoding/VideoEncodingOptions.cs deleted file mode 100644 index 773f0ea462..0000000000 --- a/MediaBrowser.Controller/MediaEncoding/VideoEncodingOptions.cs +++ /dev/null @@ -1,26 +0,0 @@ - -namespace MediaBrowser.Controller.MediaEncoding -{ - public class VideoEncodingOptions : EncodingOptions - { - public string VideoCodec { get; set; } - - public string VideoProfile { get; set; } - - public double? VideoLevel { get; set; } - - public int? VideoStreamIndex { get; set; } - - public int? AudioStreamIndex { get; set; } - - public int? SubtitleStreamIndex { get; set; } - - public int? MaxWidth { get; set; } - - public int? MaxHeight { get; set; } - - public int? Height { get; set; } - - public int? Width { get; set; } - } -} diff --git a/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs b/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs new file mode 100644 index 0000000000..17470d2061 --- /dev/null +++ b/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs @@ -0,0 +1,45 @@ +using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Configuration; +using System.Collections.Generic; +using System.IO; + +namespace MediaBrowser.MediaEncoding.Configuration +{ + public class EncodingConfigurationFactory : IConfigurationFactory + { + public IEnumerable GetConfigurations() + { + return new[] + { + new EncodingConfigurationStore() + }; + } + } + + public class EncodingConfigurationStore : ConfigurationStore, IValidatingConfiguration + { + public EncodingConfigurationStore() + { + ConfigurationType = typeof(EncodingOptions); + Key = "encoding"; + } + + public void Validate(object oldConfig, object newConfig) + { + var oldEncodingConfig = (EncodingOptions)oldConfig; + var newEncodingConfig = (EncodingOptions)newConfig; + + var newPath = newEncodingConfig.TranscodingTempPath; + + if (!string.IsNullOrWhiteSpace(newPath) + && !string.Equals(oldEncodingConfig.TranscodingTempPath ?? string.Empty, newPath)) + { + // Validate + if (!Directory.Exists(newPath)) + { + throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath)); + } + } + } + } +} diff --git a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj index 6f59b7becf..5c472ebc8d 100644 --- a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj +++ b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj @@ -56,6 +56,7 @@ Properties\SharedVersion.cs + diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index f18c53cd36..9900484cdd 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -188,6 +188,9 @@ Configuration\DynamicDayOfWeek.cs + + Configuration\EncodingOptions.cs + Configuration\EncodingQuality.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index f17215988c..bd98b5b868 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -153,6 +153,9 @@ Configuration\DynamicDayOfWeek.cs + + Configuration\EncodingOptions.cs + Configuration\EncodingQuality.cs diff --git a/MediaBrowser.Model/Configuration/EncodingOptions.cs b/MediaBrowser.Model/Configuration/EncodingOptions.cs new file mode 100644 index 0000000000..f24367298e --- /dev/null +++ b/MediaBrowser.Model/Configuration/EncodingOptions.cs @@ -0,0 +1,19 @@ + +namespace MediaBrowser.Model.Configuration +{ + public class EncodingOptions + { + public EncodingQuality EncodingQuality { get; set; } + public string TranscodingTempPath { get; set; } + public double DownMixAudioBoost { get; set; } + public string H264Encoder { get; set; } + public bool EnableDebugLogging { get; set; } + + public EncodingOptions() + { + H264Encoder = "libx264"; + DownMixAudioBoost = 2; + EncodingQuality = EncodingQuality.Auto; + } + } +} diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 59dd04f338..0852e0a5c6 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -144,15 +144,8 @@ namespace MediaBrowser.Model.Configuration /// The image saving convention. public ImageSavingConvention ImageSavingConvention { get; set; } - /// - /// Gets or sets the encoding quality. - /// - /// The encoding quality. - public EncodingQuality MediaEncodingQuality { get; set; } - public MetadataOptions[] MetadataOptions { get; set; } - public bool EnableDebugEncodingLogging { get; set; } public string TranscodingTempPath { get; set; } public bool EnableAutomaticRestart { get; set; } @@ -165,15 +158,12 @@ namespace MediaBrowser.Model.Configuration public string UICulture { get; set; } - public double DownMixAudioBoost { get; set; } - public PeopleMetadataOptions PeopleMetadataOptions { get; set; } public bool FindInternetTrailers { get; set; } public string[] InsecureApps7 { get; set; } public bool SaveMetadataHidden { get; set; } - public string H264Encoder { get; set; } /// /// Initializes a new instance of the class. @@ -181,7 +171,6 @@ namespace MediaBrowser.Model.Configuration public ServerConfiguration() : base() { - MediaEncodingQuality = EncodingQuality.Auto; ImageSavingConvention = ImageSavingConvention.Compatible; PublicPort = 8096; HttpServerPortNumber = 8096; @@ -190,7 +179,6 @@ namespace MediaBrowser.Model.Configuration EnableAutomaticRestart = true; EnableUPnP = true; - DownMixAudioBoost = 2; MinResumePct = 5; MaxResumePct = 90; @@ -217,7 +205,6 @@ namespace MediaBrowser.Model.Configuration EnableRealtimeMonitor = true; UICulture = "en-us"; - H264Encoder = "libx264"; PeopleMetadataOptions = new PeopleMetadataOptions(); diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 759c671e93..e1f0e78f4c 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -96,6 +96,7 @@ + diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index b9896e9ce5..704bdea293 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -32,7 +32,6 @@ namespace MediaBrowser.Server.Implementations.Configuration : base(applicationPaths, logManager, xmlSerializer) { UpdateItemsByNamePath(); - UpdateTranscodingTempPath(); UpdateMetadataPath(); } @@ -71,7 +70,6 @@ namespace MediaBrowser.Server.Implementations.Configuration protected override void OnConfigurationUpdated() { UpdateItemsByNamePath(); - UpdateTranscodingTempPath(); UpdateMetadataPath(); base.OnConfigurationUpdated(); @@ -97,16 +95,6 @@ namespace MediaBrowser.Server.Implementations.Configuration Configuration.MetadataPath; } - /// - /// Updates the transcoding temporary path. - /// - private void UpdateTranscodingTempPath() - { - ((ServerApplicationPaths)ApplicationPaths).TranscodingTempPath = string.IsNullOrEmpty(Configuration.TranscodingTempPath) ? - null : - Configuration.TranscodingTempPath; - } - /// /// Replaces the configuration. /// @@ -117,7 +105,6 @@ namespace MediaBrowser.Server.Implementations.Configuration var newConfig = (ServerConfiguration)newConfiguration; ValidateItemByNamePath(newConfig); - ValidateTranscodingTempPath(newConfig); ValidatePathSubstitutions(newConfig); ValidateMetadataPath(newConfig); @@ -157,26 +144,6 @@ namespace MediaBrowser.Server.Implementations.Configuration } } - /// - /// Validates the transcoding temporary path. - /// - /// The new configuration. - /// - private void ValidateTranscodingTempPath(ServerConfiguration newConfig) - { - var newPath = newConfig.TranscodingTempPath; - - if (!string.IsNullOrWhiteSpace(newPath) - && !string.Equals(Configuration.TranscodingTempPath ?? string.Empty, newPath)) - { - // Validate - if (!Directory.Exists(newPath)) - { - throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath)); - } - } - } - /// /// Validates the metadata path. ///