rework handling of original quality

This commit is contained in:
Luke Pulverenti 2015-03-15 13:50:47 -04:00
parent c8dc67d980
commit 72a5383c70
12 changed files with 103 additions and 76 deletions

View File

@ -135,6 +135,7 @@
<Compile Include="SearchService.cs" />
<Compile Include="Session\SessionsService.cs" />
<Compile Include="SimilarItemsHelper.cs" />
<Compile Include="Sync\SyncHelper.cs" />
<Compile Include="Sync\SyncJobWebSocketListener.cs" />
<Compile Include="Sync\SyncJobsWebSocketListener.cs" />
<Compile Include="Sync\SyncService.cs" />

View File

@ -1,7 +1,8 @@
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Sync;
using System.Collections.Generic;
namespace MediaBrowser.Model.Sync
namespace MediaBrowser.Api.Sync
{
public static class SyncHelper
{

View File

@ -397,6 +397,7 @@
<Compile Include="Sync\ISyncProvider.cs" />
<Compile Include="Sync\ISyncRepository.cs" />
<Compile Include="Sync\SendFileResult.cs" />
<Compile Include="Sync\SyncJobOptions.cs" />
<Compile Include="Themes\IAppThemeManager.cs" />
<Compile Include="Themes\InternalThemeImage.cs" />
<Compile Include="TV\ITVSeriesManager.cs" />

View File

@ -0,0 +1,19 @@
using MediaBrowser.Model.Dlna;
namespace MediaBrowser.Controller.Sync
{
public class SyncJobOptions<T>
where T : AudioOptions, new ()
{
/// <summary>
/// Gets or sets the conversion options.
/// </summary>
/// <value>The conversion options.</value>
public T ConversionOptions { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is converting.
/// </summary>
/// <value><c>true</c> if this instance is converting; otherwise, <c>false</c>.</value>
public bool IsConverting { get; set; }
}
}

View File

@ -1100,9 +1100,6 @@
<Compile Include="..\MediaBrowser.Model\Sync\SyncedItem.cs">
<Link>Sync\SyncedItem.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Sync\SyncHelper.cs">
<Link>Sync\SyncHelper.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Sync\SyncJob.cs">
<Link>Sync\SyncJob.cs</Link>
</Compile>

View File

@ -1059,9 +1059,6 @@
<Compile Include="..\MediaBrowser.Model\Sync\SyncedItem.cs">
<Link>Sync\SyncedItem.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Sync\SyncHelper.cs">
<Link>Sync\SyncHelper.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Sync\SyncJob.cs">
<Link>Sync\SyncJob.cs</Link>
</Compile>

View File

@ -387,7 +387,6 @@
<Compile Include="Sync\SyncDataResponse.cs" />
<Compile Include="Sync\SyncDialogOptions.cs" />
<Compile Include="Sync\SyncedItem.cs" />
<Compile Include="Sync\SyncHelper.cs" />
<Compile Include="Sync\SyncJob.cs" />
<Compile Include="Sync\SyncJobCreationResult.cs" />
<Compile Include="Sync\SyncJobItem.cs" />

View File

@ -231,6 +231,7 @@
<Compile Include="Localization\LocalizationManager.cs" />
<Compile Include="Logging\PatternsLogger.cs" />
<Compile Include="MediaEncoder\EncodingManager.cs" />
<Compile Include="Sync\SyncHelper.cs" />
<Compile Include="UserViews\DynamicImageProvider.cs" />
<Compile Include="News\NewsEntryPoint.cs" />
<Compile Include="News\NewsService.cs" />

View File

@ -3,7 +3,6 @@ using MediaBrowser.Controller.Sync;
using MediaBrowser.Model.Devices;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Sync;
using System;
using System.Collections.Generic;
using System.Linq;
@ -37,21 +36,7 @@ namespace MediaBrowser.Server.Implementations.Sync
var caps = _deviceManager.GetCapabilities(target.Id);
var deviceProfile = caps == null || caps.DeviceProfile == null ? new DeviceProfile() : caps.DeviceProfile;
var maxBitrate = deviceProfile.MaxStaticBitrate;
if (maxBitrate.HasValue)
{
if (string.Equals(quality, "medium", StringComparison.OrdinalIgnoreCase))
{
maxBitrate = Convert.ToInt32(maxBitrate.Value * .75);
}
else if (string.Equals(quality, "low", StringComparison.OrdinalIgnoreCase))
{
maxBitrate = Convert.ToInt32(maxBitrate.Value * .5);
}
deviceProfile.MaxStaticBitrate = maxBitrate;
}
deviceProfile.MaxStaticBitrate = SyncHelper.AdjustBitrate(deviceProfile.MaxStaticBitrate, quality);
return deviceProfile;
}

View File

@ -0,0 +1,33 @@
using System;
using System.Globalization;
namespace MediaBrowser.Server.Implementations.Sync
{
public class SyncHelper
{
public static int? AdjustBitrate(int? profileBitrate, string quality)
{
if (profileBitrate.HasValue)
{
if (string.Equals(quality, "medium", StringComparison.OrdinalIgnoreCase))
{
profileBitrate = Convert.ToInt32(profileBitrate.Value * .75);
}
else if (string.Equals(quality, "low", StringComparison.OrdinalIgnoreCase))
{
profileBitrate = Convert.ToInt32(profileBitrate.Value*.5);
}
else
{
int value;
if (int.TryParse(quality, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
{
profileBitrate = value;
}
}
}
return profileBitrate;
}
}
}

View File

@ -476,22 +476,17 @@ namespace MediaBrowser.Server.Implementations.Sync
}
}
private bool IsOriginalQuality(SyncJob job)
{
return string.IsNullOrWhiteSpace(job.Quality) ||
string.Equals(job.Quality, "original", StringComparison.OrdinalIgnoreCase);
}
private async Task Sync(SyncJobItem jobItem, SyncJob job, Video item, User user, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
{
var options = _syncManager.GetVideoOptions(jobItem, job);
var jobOptions = _syncManager.GetVideoOptions(jobItem, job);
var conversionOptions = jobOptions.ConversionOptions;
options.DeviceId = jobItem.TargetId;
options.Context = EncodingContext.Static;
options.ItemId = item.Id.ToString("N");
options.MediaSources = _mediaSourceManager.GetStaticMediaSources(item, false, user).ToList();
conversionOptions.DeviceId = jobItem.TargetId;
conversionOptions.Context = EncodingContext.Static;
conversionOptions.ItemId = item.Id.ToString("N");
conversionOptions.MediaSources = _mediaSourceManager.GetStaticMediaSources(item, false, user).ToList();
var streamInfo = new StreamBuilder().BuildVideoItem(options);
var streamInfo = new StreamBuilder().BuildVideoItem(conversionOptions);
var mediaSource = streamInfo.MediaSource;
// No sense creating external subs if we're already burning one into the video
@ -500,7 +495,7 @@ namespace MediaBrowser.Server.Implementations.Sync
streamInfo.GetExternalSubtitles(false);
// Mark as requiring conversion if transcoding the video, or if any subtitles need to be extracted
var requiresVideoTranscoding = streamInfo.PlayMethod == PlayMethod.Transcode && IsOriginalQuality(job);
var requiresVideoTranscoding = streamInfo.PlayMethod == PlayMethod.Transcode && jobOptions.IsConverting;
var requiresConversion = requiresVideoTranscoding || externalSubs.Any(i => RequiresExtraction(i, mediaSource));
if (requiresConversion && !enableConversion)
@ -538,7 +533,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}
});
jobItem.OutputPath = await _mediaEncoder.EncodeVideo(new EncodingJobOptions(streamInfo, options.Profile)
jobItem.OutputPath = await _mediaEncoder.EncodeVideo(new EncodingJobOptions(streamInfo, conversionOptions.Profile)
{
OutputDirectory = jobItem.TemporaryPath
@ -676,20 +671,21 @@ namespace MediaBrowser.Server.Implementations.Sync
private async Task Sync(SyncJobItem jobItem, SyncJob job, Audio item, User user, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
{
var options = _syncManager.GetAudioOptions(jobItem, job);
var jobOptions = _syncManager.GetAudioOptions(jobItem, job);
var conversionOptions = jobOptions.ConversionOptions;
options.DeviceId = jobItem.TargetId;
options.Context = EncodingContext.Static;
options.ItemId = item.Id.ToString("N");
options.MediaSources = _mediaSourceManager.GetStaticMediaSources(item, false, user).ToList();
conversionOptions.DeviceId = jobItem.TargetId;
conversionOptions.Context = EncodingContext.Static;
conversionOptions.ItemId = item.Id.ToString("N");
conversionOptions.MediaSources = _mediaSourceManager.GetStaticMediaSources(item, false, user).ToList();
var streamInfo = new StreamBuilder().BuildAudioItem(options);
var streamInfo = new StreamBuilder().BuildAudioItem(conversionOptions);
var mediaSource = streamInfo.MediaSource;
jobItem.MediaSourceId = streamInfo.MediaSourceId;
jobItem.TemporaryPath = GetTemporaryPath(jobItem);
if (streamInfo.PlayMethod == PlayMethod.Transcode && !IsOriginalQuality(job))
if (streamInfo.PlayMethod == PlayMethod.Transcode && jobOptions.IsConverting)
{
if (!enableConversion)
{
@ -716,7 +712,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}
});
jobItem.OutputPath = await _mediaEncoder.EncodeAudio(new EncodingJobOptions(streamInfo, options.Profile)
jobItem.OutputPath = await _mediaEncoder.EncodeAudio(new EncodingJobOptions(streamInfo, conversionOptions.Profile)
{
OutputDirectory = jobItem.TemporaryPath

View File

@ -982,23 +982,34 @@ namespace MediaBrowser.Server.Implementations.Sync
return _repo.GetLibraryItemIds(query);
}
public AudioOptions GetAudioOptions(SyncJobItem jobItem, SyncJob job)
private bool IsOriginalQuality(SyncJob job)
{
var profile = GetDeviceProfile(jobItem.TargetId, null, null);
return string.IsNullOrWhiteSpace(job.Quality) ||
string.Equals(job.Quality, "original", StringComparison.OrdinalIgnoreCase) ||
string.Equals(job.Profile, "original", StringComparison.OrdinalIgnoreCase);
}
return new AudioOptions
public SyncJobOptions<AudioOptions> GetAudioOptions(SyncJobItem jobItem, SyncJob job)
{
return new SyncJobOptions<AudioOptions>
{
Profile = profile
ConversionOptions = new AudioOptions
{
Profile = GetDeviceProfile(jobItem.TargetId, null, null)
},
IsConverting = !IsOriginalQuality(job)
};
}
public VideoOptions GetVideoOptions(SyncJobItem jobItem, SyncJob job)
public SyncJobOptions<VideoOptions> GetVideoOptions(SyncJobItem jobItem, SyncJob job)
{
var profile = GetDeviceProfile(jobItem.TargetId, job.Profile, job.Quality);
return new VideoOptions
return new SyncJobOptions<VideoOptions>
{
Profile = profile
ConversionOptions = new VideoOptions
{
Profile = GetDeviceProfile(jobItem.TargetId, job.Profile, job.Quality)
},
IsConverting = !IsOriginalQuality(job)
};
}
@ -1033,21 +1044,7 @@ namespace MediaBrowser.Server.Implementations.Sync
private DeviceProfile GetDeviceProfile(string profile, string quality)
{
var deviceProfile = new CloudSyncProfile(true, false);
var maxBitrate = deviceProfile.MaxStaticBitrate;
if (maxBitrate.HasValue)
{
if (string.Equals(quality, "medium", StringComparison.OrdinalIgnoreCase))
{
maxBitrate = Convert.ToInt32(maxBitrate.Value * .75);
}
else if (string.Equals(quality, "low", StringComparison.OrdinalIgnoreCase))
{
maxBitrate = Convert.ToInt32(maxBitrate.Value * .5);
}
deviceProfile.MaxStaticBitrate = maxBitrate;
}
deviceProfile.MaxStaticBitrate = SyncHelper.AdjustBitrate(deviceProfile.MaxStaticBitrate, quality);
return deviceProfile;
}
@ -1139,16 +1136,16 @@ namespace MediaBrowser.Server.Implementations.Sync
list.Add(new SyncProfileOption
{
Name = "Web - H264/AAC, MP3",
Id = "mobile",
Description = "Designed for compatibility with all devices, including web browsers."
Name = "Baseline",
Id = "baseline",
Description = "Designed for compatibility with all devices, including web browsers. Targets H264/AAC video and MP3 audio."
});
list.Add(new SyncProfileOption
{
Name = "General - H264/AAC/AC3, MP3",
Name = "General",
Id = "general",
Description = "Designed for compatibility with Chromecast, Roku, Smart TV's, and other similar devices.",
Description = "Designed for compatibility with Chromecast, Roku, Smart TV's, and other similar devices. Targets H264/AAC/AC3 video and MP3 audio.",
IsDefault = true
});