mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-13 05:36:36 +00:00
add methods to get quality options
This commit is contained in:
@@ -8,7 +8,7 @@ using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Sync
|
||||
{
|
||||
public class AppSyncProvider : ISyncProvider, IHasUniqueTargetIds, IHasSyncProfile
|
||||
public class AppSyncProvider : ISyncProvider, IHasUniqueTargetIds, IHasSyncQuality
|
||||
{
|
||||
private readonly IDeviceManager _deviceManager;
|
||||
|
||||
@@ -55,5 +55,33 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
Name = i.Name
|
||||
});
|
||||
}
|
||||
|
||||
public IEnumerable<SyncQualityOption> GetQualityOptions(SyncTarget target)
|
||||
{
|
||||
return new List<SyncQualityOption>
|
||||
{
|
||||
new SyncQualityOption
|
||||
{
|
||||
Name = SyncQuality.Original.ToString(),
|
||||
Id = SyncQuality.Original.ToString()
|
||||
},
|
||||
new SyncQualityOption
|
||||
{
|
||||
Name = SyncQuality.High.ToString(),
|
||||
Id = SyncQuality.High.ToString(),
|
||||
IsDefault = true
|
||||
},
|
||||
new SyncQualityOption
|
||||
{
|
||||
Name = SyncQuality.Medium.ToString(),
|
||||
Id = SyncQuality.Medium.ToString()
|
||||
},
|
||||
new SyncQualityOption
|
||||
{
|
||||
Name = SyncQuality.Low.ToString(),
|
||||
Id = SyncQuality.Low.ToString()
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using MediaBrowser.Model.Dlna;
|
||||
using MediaBrowser.Model.Sync;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Sync
|
||||
{
|
||||
public interface IHasSyncProfile
|
||||
public interface IHasSyncQuality
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the device profile.
|
||||
@@ -11,5 +12,12 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
/// <param name="target">The target.</param>
|
||||
/// <returns>DeviceProfile.</returns>
|
||||
DeviceProfile GetDeviceProfile(SyncTarget target);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the quality options.
|
||||
/// </summary>
|
||||
/// <param name="target">The target.</param>
|
||||
/// <returns>IEnumerable<SyncQualityOption>.</returns>
|
||||
IEnumerable<SyncQualityOption> GetQualityOptions(SyncTarget target);
|
||||
}
|
||||
}
|
||||
@@ -450,15 +450,6 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceProfile = _syncManager.GetDeviceProfile(jobItem.TargetId);
|
||||
if (deviceProfile == null)
|
||||
{
|
||||
jobItem.Status = SyncJobItemStatus.Failed;
|
||||
_logger.Error("Unable to locate SyncTarget for JobItem {0}, SyncTargetId {1}", jobItem.Id, jobItem.TargetId);
|
||||
await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
jobItem.Progress = 0;
|
||||
|
||||
var user = _userManager.GetUserById(job.UserId);
|
||||
@@ -466,17 +457,17 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
var video = item as Video;
|
||||
if (video != null)
|
||||
{
|
||||
await Sync(jobItem, job, video, user, deviceProfile, enableConversion, progress, cancellationToken).ConfigureAwait(false);
|
||||
await Sync(jobItem, job, video, user, enableConversion, progress, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
else if (item is Audio)
|
||||
{
|
||||
await Sync(jobItem, job, (Audio)item, user, deviceProfile, enableConversion, progress, cancellationToken).ConfigureAwait(false);
|
||||
await Sync(jobItem, job, (Audio)item, user, enableConversion, progress, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
else if (item is Photo)
|
||||
{
|
||||
await Sync(jobItem, (Photo)item, deviceProfile, cancellationToken).ConfigureAwait(false);
|
||||
await Sync(jobItem, (Photo)item, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
else
|
||||
@@ -491,13 +482,12 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
string.Equals(job.Quality, "original", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private async Task Sync(SyncJobItem jobItem, SyncJob job, Video item, User user, DeviceProfile profile, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
|
||||
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);
|
||||
|
||||
options.DeviceId = jobItem.TargetId;
|
||||
options.Context = EncodingContext.Static;
|
||||
options.Profile = profile;
|
||||
options.ItemId = item.Id.ToString("N");
|
||||
options.MediaSources = _mediaSourceManager.GetStaticMediaSources(item, false, user).ToList();
|
||||
|
||||
@@ -548,7 +538,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
}
|
||||
});
|
||||
|
||||
jobItem.OutputPath = await _mediaEncoder.EncodeVideo(new EncodingJobOptions(streamInfo, profile)
|
||||
jobItem.OutputPath = await _mediaEncoder.EncodeVideo(new EncodingJobOptions(streamInfo, options.Profile)
|
||||
{
|
||||
OutputDirectory = jobItem.TemporaryPath
|
||||
|
||||
@@ -682,13 +672,12 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
|
||||
private const int DatabaseProgressUpdateIntervalSeconds = 2;
|
||||
|
||||
private async Task Sync(SyncJobItem jobItem, SyncJob job, Audio item, User user, DeviceProfile profile, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
|
||||
private async Task Sync(SyncJobItem jobItem, SyncJob job, Audio item, User user, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var options = _syncManager.GetAudioOptions(jobItem);
|
||||
var options = _syncManager.GetAudioOptions(jobItem, job);
|
||||
|
||||
options.DeviceId = jobItem.TargetId;
|
||||
options.Context = EncodingContext.Static;
|
||||
options.Profile = profile;
|
||||
options.ItemId = item.Id.ToString("N");
|
||||
options.MediaSources = _mediaSourceManager.GetStaticMediaSources(item, false, user).ToList();
|
||||
|
||||
@@ -725,7 +714,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
}
|
||||
});
|
||||
|
||||
jobItem.OutputPath = await _mediaEncoder.EncodeAudio(new EncodingJobOptions(streamInfo, profile)
|
||||
jobItem.OutputPath = await _mediaEncoder.EncodeAudio(new EncodingJobOptions(streamInfo, options.Profile)
|
||||
{
|
||||
OutputDirectory = jobItem.TemporaryPath
|
||||
|
||||
@@ -773,7 +762,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task Sync(SyncJobItem jobItem, Photo item, DeviceProfile profile, CancellationToken cancellationToken)
|
||||
private async Task Sync(SyncJobItem jobItem, Photo item, CancellationToken cancellationToken)
|
||||
{
|
||||
jobItem.OutputPath = item.Path;
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
|
||||
private readonly ConcurrentDictionary<string, ISyncDataProvider> _dataProviders =
|
||||
new ConcurrentDictionary<string, ISyncDataProvider>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
|
||||
public ISyncDataProvider GetDataProvider(IServerSyncProvider provider, SyncTarget target)
|
||||
{
|
||||
return _dataProviders.GetOrAdd(target.Id, key => new TargetDataProvider(provider, target, _appHost.SystemId, _logger, _json, _fileSystem, _config.CommonApplicationPaths));
|
||||
@@ -972,9 +972,9 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
return _repo.GetLibraryItemIds(query);
|
||||
}
|
||||
|
||||
public AudioOptions GetAudioOptions(SyncJobItem jobItem)
|
||||
public AudioOptions GetAudioOptions(SyncJobItem jobItem, SyncJob job)
|
||||
{
|
||||
var profile = GetDeviceProfile(jobItem.TargetId);
|
||||
var profile = GetDeviceProfile(jobItem.TargetId, job.Quality);
|
||||
|
||||
return new AudioOptions
|
||||
{
|
||||
@@ -984,16 +984,16 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
|
||||
public VideoOptions GetVideoOptions(SyncJobItem jobItem, SyncJob job)
|
||||
{
|
||||
var profile = GetDeviceProfile(jobItem.TargetId);
|
||||
var profile = GetDeviceProfile(jobItem.TargetId, job.Quality);
|
||||
var maxBitrate = profile.MaxStaticBitrate;
|
||||
|
||||
if (maxBitrate.HasValue)
|
||||
{
|
||||
if (string.Equals(job.Quality, "high", StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(job.Quality, "medium", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
maxBitrate = Convert.ToInt32(maxBitrate.Value * .75);
|
||||
}
|
||||
else if (string.Equals(job.Quality, "medium", StringComparison.OrdinalIgnoreCase))
|
||||
else if (string.Equals(job.Quality, "low", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
maxBitrate = Convert.ToInt32(maxBitrate.Value * .5);
|
||||
}
|
||||
@@ -1006,7 +1006,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
};
|
||||
}
|
||||
|
||||
public DeviceProfile GetDeviceProfile(string targetId)
|
||||
public DeviceProfile GetDeviceProfile(string targetId, string quality)
|
||||
{
|
||||
foreach (var provider in _providers)
|
||||
{
|
||||
@@ -1014,7 +1014,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
{
|
||||
if (string.Equals(target.Id, targetId, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return GetDeviceProfile(provider, target);
|
||||
return GetDeviceProfile(provider, target, quality);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1022,9 +1022,9 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
return null;
|
||||
}
|
||||
|
||||
public DeviceProfile GetDeviceProfile(ISyncProvider provider, SyncTarget target)
|
||||
private DeviceProfile GetDeviceProfile(ISyncProvider provider, SyncTarget target, string quality)
|
||||
{
|
||||
var hasProfile = provider as IHasSyncProfile;
|
||||
var hasProfile = provider as IHasSyncQuality;
|
||||
|
||||
if (hasProfile != null)
|
||||
{
|
||||
@@ -1033,5 +1033,56 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
|
||||
return new CloudSyncProfile(true, false);
|
||||
}
|
||||
|
||||
public IEnumerable<SyncQualityOption> GetQualityOptions(string targetId)
|
||||
{
|
||||
foreach (var provider in _providers)
|
||||
{
|
||||
foreach (var target in GetSyncTargets(provider))
|
||||
{
|
||||
if (string.Equals(target.Id, targetId, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return GetQualityOptions(provider, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new List<SyncQualityOption>();
|
||||
}
|
||||
|
||||
private IEnumerable<SyncQualityOption> GetQualityOptions(ISyncProvider provider, SyncTarget target)
|
||||
{
|
||||
var hasQuality = provider as IHasSyncQuality;
|
||||
if (hasQuality != null)
|
||||
{
|
||||
return hasQuality.GetQualityOptions(target);
|
||||
}
|
||||
|
||||
// Default options for providers that don't override
|
||||
return new List<SyncQualityOption>
|
||||
{
|
||||
new SyncQualityOption
|
||||
{
|
||||
Name = SyncQuality.Original.ToString(),
|
||||
Id = SyncQuality.Original.ToString()
|
||||
},
|
||||
new SyncQualityOption
|
||||
{
|
||||
Name = SyncQuality.High.ToString(),
|
||||
Id = SyncQuality.High.ToString(),
|
||||
IsDefault = true
|
||||
},
|
||||
new SyncQualityOption
|
||||
{
|
||||
Name = SyncQuality.Medium.ToString(),
|
||||
Id = SyncQuality.Medium.ToString()
|
||||
},
|
||||
new SyncQualityOption
|
||||
{
|
||||
Name = SyncQuality.Low.ToString(),
|
||||
Id = SyncQuality.Low.ToString()
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user