add standalone EncodingOptions

This commit is contained in:
Luke Pulverenti 2014-12-21 14:40:37 -05:00
parent 74520804f8
commit 97ae93fe5e
16 changed files with 113 additions and 182 deletions

View File

@ -1,7 +1,9 @@
using MediaBrowser.Api.Playback; using MediaBrowser.Api.Playback;
using MediaBrowser.Controller; using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Session; using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Session; using MediaBrowser.Model.Session;
using System; using System;
@ -33,7 +35,7 @@ namespace MediaBrowser.Api
/// <summary> /// <summary>
/// The application paths /// The application paths
/// </summary> /// </summary>
private readonly IServerApplicationPaths _appPaths; private readonly IServerConfigurationManager _config;
private readonly ISessionManager _sessionManager; private readonly ISessionManager _sessionManager;
@ -43,13 +45,13 @@ namespace MediaBrowser.Api
/// Initializes a new instance of the <see cref="ApiEntryPoint" /> class. /// Initializes a new instance of the <see cref="ApiEntryPoint" /> class.
/// </summary> /// </summary>
/// <param name="logger">The logger.</param> /// <param name="logger">The logger.</param>
/// <param name="appPaths">The application paths.</param>
/// <param name="sessionManager">The session manager.</param> /// <param name="sessionManager">The session manager.</param>
public ApiEntryPoint(ILogger logger, IServerApplicationPaths appPaths, ISessionManager sessionManager) /// <param name="config">The configuration.</param>
public ApiEntryPoint(ILogger logger, ISessionManager sessionManager, IServerConfigurationManager config)
{ {
Logger = logger; Logger = logger;
_appPaths = appPaths;
_sessionManager = sessionManager; _sessionManager = sessionManager;
_config = config;
Instance = this; Instance = this;
} }
@ -73,12 +75,17 @@ namespace MediaBrowser.Api
} }
} }
public EncodingOptions GetEncodingOptions()
{
return _config.GetConfiguration<EncodingOptions>("encoding");
}
/// <summary> /// <summary>
/// Deletes the encoded media cache. /// Deletes the encoded media cache.
/// </summary> /// </summary>
private void DeleteEncodedMediaCache() 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()) .ToList())
{ {
File.Delete(file); File.Delete(file);

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO; using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
@ -249,7 +250,7 @@ namespace MediaBrowser.Api.Playback
protected EncodingQuality GetQualitySetting() protected EncodingQuality GetQualitySetting()
{ {
var quality = ServerConfigurationManager.Configuration.MediaEncodingQuality; var quality = ApiEntryPoint.Instance.GetEncodingOptions().MediaEncodingQuality;
if (quality == EncodingQuality.Auto) if (quality == EncodingQuality.Auto)
{ {
@ -310,7 +311,7 @@ namespace MediaBrowser.Api.Playback
{ {
get get
{ {
var lib = ServerConfigurationManager.Configuration.H264Encoder; var lib = ApiEntryPoint.Instance.GetEncodingOptions().H264Encoder;
if (!string.IsNullOrWhiteSpace(lib)) 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) 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 transcodingId = Guid.NewGuid().ToString("N");
var commandLineArgs = GetCommandLineArguments(outputPath, transcodingId, state, true); var commandLineArgs = GetCommandLineArguments(outputPath, transcodingId, state, true);
if (ServerConfigurationManager.Configuration.EnableDebugEncodingLogging) if (ApiEntryPoint.Instance.GetEncodingOptions().EnableDebugLogging)
{ {
commandLineArgs = "-loglevel debug " + commandLineArgs; commandLineArgs = "-loglevel debug " + commandLineArgs;
} }

View File

@ -233,13 +233,22 @@ namespace MediaBrowser.Common.Implementations.Configuration
public void SaveConfiguration(string key, object configuration) public void SaveConfiguration(string key, object configuration)
{ {
var configurationType = GetConfigurationType(key); var configurationStore = GetConfigurationStore(key);
var configurationType = configurationStore.ConfigurationType;
if (configuration.GetType() != configurationType) if (configuration.GetType() != configurationType)
{ {
throw new ArgumentException("Expected configuration type is " + configurationType.Name); 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 EventHelper.FireEventIfNotNull(NamedConfigurationUpdating, this, new ConfigurationUpdateEventArgs
{ {
Key = key, Key = key,
@ -267,9 +276,14 @@ namespace MediaBrowser.Common.Implementations.Configuration
public Type GetConfigurationType(string key) public Type GetConfigurationType(string key)
{ {
return _configurationStores return GetConfigurationStore(key)
.First(i => string.Equals(i.Key, key, StringComparison.OrdinalIgnoreCase))
.ConfigurationType; .ConfigurationType;
} }
private ConfigurationStore GetConfigurationStore(string key)
{
return _configurationStores
.First(i => string.Equals(i.Key, key, StringComparison.OrdinalIgnoreCase));
}
} }
} }

View File

@ -14,4 +14,9 @@ namespace MediaBrowser.Common.Configuration
public Type ConfigurationType { get; set; } public Type ConfigurationType { get; set; }
} }
public interface IValidatingConfiguration
{
void Validate(object oldConfig, object newConfig);
}
} }

View File

@ -198,16 +198,13 @@
<Compile Include="LiveTv\SeriesTimerInfo.cs" /> <Compile Include="LiveTv\SeriesTimerInfo.cs" />
<Compile Include="LiveTv\TimerInfo.cs" /> <Compile Include="LiveTv\TimerInfo.cs" />
<Compile Include="Localization\ILocalizationManager.cs" /> <Compile Include="Localization\ILocalizationManager.cs" />
<Compile Include="MediaEncoding\EncodingOptions.cs" />
<Compile Include="MediaEncoding\ChapterImageRefreshOptions.cs" /> <Compile Include="MediaEncoding\ChapterImageRefreshOptions.cs" />
<Compile Include="MediaEncoding\EncodingResult.cs" />
<Compile Include="MediaEncoding\IEncodingManager.cs" /> <Compile Include="MediaEncoding\IEncodingManager.cs" />
<Compile Include="MediaEncoding\ImageEncodingOptions.cs" /> <Compile Include="MediaEncoding\ImageEncodingOptions.cs" />
<Compile Include="MediaEncoding\IMediaEncoder.cs" /> <Compile Include="MediaEncoding\IMediaEncoder.cs" />
<Compile Include="MediaEncoding\InternalMediaInfoResult.cs" /> <Compile Include="MediaEncoding\InternalMediaInfoResult.cs" />
<Compile Include="MediaEncoding\ISubtitleEncoder.cs" /> <Compile Include="MediaEncoding\ISubtitleEncoder.cs" />
<Compile Include="MediaEncoding\MediaStreamSelector.cs" /> <Compile Include="MediaEncoding\MediaStreamSelector.cs" />
<Compile Include="MediaEncoding\VideoEncodingOptions.cs" />
<Compile Include="Net\AuthenticatedAttribute.cs" /> <Compile Include="Net\AuthenticatedAttribute.cs" />
<Compile Include="Net\AuthorizationInfo.cs" /> <Compile Include="Net\AuthorizationInfo.cs" />
<Compile Include="Net\IAuthorizationContext.cs" /> <Compile Include="Net\IAuthorizationContext.cs" />

View File

@ -1,80 +0,0 @@
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Model.Dlna;
namespace MediaBrowser.Controller.MediaEncoding
{
public class EncodingOptions
{
/// <summary>
/// Gets or sets the item identifier.
/// </summary>
/// <value>The item identifier.</value>
public string ItemId { get; set; }
/// <summary>
/// Gets or sets the media source identifier.
/// </summary>
/// <value>The media source identifier.</value>
public string MediaSourceId { get; set; }
/// <summary>
/// Gets or sets the device profile.
/// </summary>
/// <value>The device profile.</value>
public DeviceProfile DeviceProfile { get; set; }
/// <summary>
/// Gets or sets the output path.
/// </summary>
/// <value>The output path.</value>
public string OutputPath { get; set; }
/// <summary>
/// Gets or sets the container.
/// </summary>
/// <value>The container.</value>
public string Container { get; set; }
/// <summary>
/// Gets or sets the audio codec.
/// </summary>
/// <value>The audio codec.</value>
public string AudioCodec { get; set; }
/// <summary>
/// Gets or sets the start time ticks.
/// </summary>
/// <value>The start time ticks.</value>
public long? StartTimeTicks { get; set; }
/// <summary>
/// Gets or sets the maximum channels.
/// </summary>
/// <value>The maximum channels.</value>
public int? MaxAudioChannels { get; set; }
/// <summary>
/// Gets or sets the channels.
/// </summary>
/// <value>The channels.</value>
public int? AudioChannels { get; set; }
/// <summary>
/// Gets or sets the sample rate.
/// </summary>
/// <value>The sample rate.</value>
public int? AudioSampleRate { get; set; }
/// <summary>
/// Gets or sets the bit rate.
/// </summary>
/// <value>The bit rate.</value>
public int? AudioBitRate { get; set; }
/// <summary>
/// Gets or sets the maximum audio bit rate.
/// </summary>
/// <value>The maximum audio bit rate.</value>
public int? MaxAudioBitRate { get; set; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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<ConfigurationStore> 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));
}
}
}
}
}

View File

@ -56,6 +56,7 @@
<Link>Properties\SharedVersion.cs</Link> <Link>Properties\SharedVersion.cs</Link>
</Compile> </Compile>
<Compile Include="BdInfo\BdInfoExaminer.cs" /> <Compile Include="BdInfo\BdInfoExaminer.cs" />
<Compile Include="Configuration\EncodingConfigurationFactory.cs" />
<Compile Include="Encoder\EncodingUtils.cs" /> <Compile Include="Encoder\EncodingUtils.cs" />
<Compile Include="Encoder\MediaEncoder.cs" /> <Compile Include="Encoder\MediaEncoder.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -188,6 +188,9 @@
<Compile Include="..\MediaBrowser.Model\Configuration\DynamicDayOfWeek.cs"> <Compile Include="..\MediaBrowser.Model\Configuration\DynamicDayOfWeek.cs">
<Link>Configuration\DynamicDayOfWeek.cs</Link> <Link>Configuration\DynamicDayOfWeek.cs</Link>
</Compile> </Compile>
<Compile Include="..\MediaBrowser.Model\Configuration\EncodingOptions.cs">
<Link>Configuration\EncodingOptions.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Configuration\EncodingQuality.cs"> <Compile Include="..\MediaBrowser.Model\Configuration\EncodingQuality.cs">
<Link>Configuration\EncodingQuality.cs</Link> <Link>Configuration\EncodingQuality.cs</Link>
</Compile> </Compile>

View File

@ -153,6 +153,9 @@
<Compile Include="..\MediaBrowser.Model\Configuration\DynamicDayOfWeek.cs"> <Compile Include="..\MediaBrowser.Model\Configuration\DynamicDayOfWeek.cs">
<Link>Configuration\DynamicDayOfWeek.cs</Link> <Link>Configuration\DynamicDayOfWeek.cs</Link>
</Compile> </Compile>
<Compile Include="..\MediaBrowser.Model\Configuration\EncodingOptions.cs">
<Link>Configuration\EncodingOptions.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Configuration\EncodingQuality.cs"> <Compile Include="..\MediaBrowser.Model\Configuration\EncodingQuality.cs">
<Link>Configuration\EncodingQuality.cs</Link> <Link>Configuration\EncodingQuality.cs</Link>
</Compile> </Compile>

View File

@ -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;
}
}
}

View File

@ -144,15 +144,8 @@ namespace MediaBrowser.Model.Configuration
/// <value>The image saving convention.</value> /// <value>The image saving convention.</value>
public ImageSavingConvention ImageSavingConvention { get; set; } public ImageSavingConvention ImageSavingConvention { get; set; }
/// <summary>
/// Gets or sets the encoding quality.
/// </summary>
/// <value>The encoding quality.</value>
public EncodingQuality MediaEncodingQuality { get; set; }
public MetadataOptions[] MetadataOptions { get; set; } public MetadataOptions[] MetadataOptions { get; set; }
public bool EnableDebugEncodingLogging { get; set; }
public string TranscodingTempPath { get; set; } public string TranscodingTempPath { get; set; }
public bool EnableAutomaticRestart { get; set; } public bool EnableAutomaticRestart { get; set; }
@ -165,15 +158,12 @@ namespace MediaBrowser.Model.Configuration
public string UICulture { get; set; } public string UICulture { get; set; }
public double DownMixAudioBoost { get; set; }
public PeopleMetadataOptions PeopleMetadataOptions { get; set; } public PeopleMetadataOptions PeopleMetadataOptions { get; set; }
public bool FindInternetTrailers { get; set; } public bool FindInternetTrailers { get; set; }
public string[] InsecureApps7 { get; set; } public string[] InsecureApps7 { get; set; }
public bool SaveMetadataHidden { get; set; } public bool SaveMetadataHidden { get; set; }
public string H264Encoder { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ServerConfiguration" /> class. /// Initializes a new instance of the <see cref="ServerConfiguration" /> class.
@ -181,7 +171,6 @@ namespace MediaBrowser.Model.Configuration
public ServerConfiguration() public ServerConfiguration()
: base() : base()
{ {
MediaEncodingQuality = EncodingQuality.Auto;
ImageSavingConvention = ImageSavingConvention.Compatible; ImageSavingConvention = ImageSavingConvention.Compatible;
PublicPort = 8096; PublicPort = 8096;
HttpServerPortNumber = 8096; HttpServerPortNumber = 8096;
@ -190,7 +179,6 @@ namespace MediaBrowser.Model.Configuration
EnableAutomaticRestart = true; EnableAutomaticRestart = true;
EnableUPnP = true; EnableUPnP = true;
DownMixAudioBoost = 2;
MinResumePct = 5; MinResumePct = 5;
MaxResumePct = 90; MaxResumePct = 90;
@ -217,7 +205,6 @@ namespace MediaBrowser.Model.Configuration
EnableRealtimeMonitor = true; EnableRealtimeMonitor = true;
UICulture = "en-us"; UICulture = "en-us";
H264Encoder = "libx264";
PeopleMetadataOptions = new PeopleMetadataOptions(); PeopleMetadataOptions = new PeopleMetadataOptions();

View File

@ -96,6 +96,7 @@
<Compile Include="Configuration\ChannelOptions.cs" /> <Compile Include="Configuration\ChannelOptions.cs" />
<Compile Include="Configuration\ChapterOptions.cs" /> <Compile Include="Configuration\ChapterOptions.cs" />
<Compile Include="Configuration\CinemaModeConfiguration.cs" /> <Compile Include="Configuration\CinemaModeConfiguration.cs" />
<Compile Include="Configuration\EncodingOptions.cs" />
<Compile Include="Configuration\MetadataConfiguration.cs" /> <Compile Include="Configuration\MetadataConfiguration.cs" />
<Compile Include="Configuration\PeopleMetadataOptions.cs" /> <Compile Include="Configuration\PeopleMetadataOptions.cs" />
<Compile Include="Configuration\XbmcMetadataOptions.cs" /> <Compile Include="Configuration\XbmcMetadataOptions.cs" />

View File

@ -32,7 +32,6 @@ namespace MediaBrowser.Server.Implementations.Configuration
: base(applicationPaths, logManager, xmlSerializer) : base(applicationPaths, logManager, xmlSerializer)
{ {
UpdateItemsByNamePath(); UpdateItemsByNamePath();
UpdateTranscodingTempPath();
UpdateMetadataPath(); UpdateMetadataPath();
} }
@ -71,7 +70,6 @@ namespace MediaBrowser.Server.Implementations.Configuration
protected override void OnConfigurationUpdated() protected override void OnConfigurationUpdated()
{ {
UpdateItemsByNamePath(); UpdateItemsByNamePath();
UpdateTranscodingTempPath();
UpdateMetadataPath(); UpdateMetadataPath();
base.OnConfigurationUpdated(); base.OnConfigurationUpdated();
@ -97,16 +95,6 @@ namespace MediaBrowser.Server.Implementations.Configuration
Configuration.MetadataPath; Configuration.MetadataPath;
} }
/// <summary>
/// Updates the transcoding temporary path.
/// </summary>
private void UpdateTranscodingTempPath()
{
((ServerApplicationPaths)ApplicationPaths).TranscodingTempPath = string.IsNullOrEmpty(Configuration.TranscodingTempPath) ?
null :
Configuration.TranscodingTempPath;
}
/// <summary> /// <summary>
/// Replaces the configuration. /// Replaces the configuration.
/// </summary> /// </summary>
@ -117,7 +105,6 @@ namespace MediaBrowser.Server.Implementations.Configuration
var newConfig = (ServerConfiguration)newConfiguration; var newConfig = (ServerConfiguration)newConfiguration;
ValidateItemByNamePath(newConfig); ValidateItemByNamePath(newConfig);
ValidateTranscodingTempPath(newConfig);
ValidatePathSubstitutions(newConfig); ValidatePathSubstitutions(newConfig);
ValidateMetadataPath(newConfig); ValidateMetadataPath(newConfig);
@ -157,26 +144,6 @@ namespace MediaBrowser.Server.Implementations.Configuration
} }
} }
/// <summary>
/// Validates the transcoding temporary path.
/// </summary>
/// <param name="newConfig">The new configuration.</param>
/// <exception cref="DirectoryNotFoundException"></exception>
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));
}
}
}
/// <summary> /// <summary>
/// Validates the metadata path. /// Validates the metadata path.
/// </summary> /// </summary>