Refactor and add scheduled task

This commit is contained in:
cvium
2022-01-11 23:30:30 +01:00
parent c658a883a2
commit 6ffa9539bb
24 changed files with 924 additions and 744 deletions

View File

@@ -1,21 +1,36 @@
using Jellyfin.MediaEncoding.Hls.Playlist;
using System;
using Jellyfin.MediaEncoding.Hls.Cache;
using Jellyfin.MediaEncoding.Hls.Extractors;
using Jellyfin.MediaEncoding.Hls.Playlist;
using Microsoft.Extensions.DependencyInjection;
namespace Jellyfin.MediaEncoding.Hls.Extensions
namespace Jellyfin.MediaEncoding.Hls.Extensions;
/// <summary>
/// Extensions for the <see cref="IServiceCollection"/> interface.
/// </summary>
public static class MediaEncodingHlsServiceCollectionExtensions
{
/// <summary>
/// Extensions for the <see cref="IServiceCollection"/> interface.
/// Adds the hls playlist generators to the <see cref="IServiceCollection"/>.
/// </summary>
public static class MediaEncodingHlsServiceCollectionExtensions
/// <param name="serviceCollection">An instance of the <see cref="IServiceCollection"/> interface.</param>
/// <returns>The updated service collection.</returns>
public static IServiceCollection AddHlsPlaylistGenerator(this IServiceCollection serviceCollection)
{
/// <summary>
/// Adds the hls playlist generators to the <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="serviceCollection">An instance of the <see cref="IServiceCollection"/> interface.</param>
/// <returns>The updated service collection.</returns>
public static IServiceCollection AddHlsPlaylistGenerator(this IServiceCollection serviceCollection)
serviceCollection.AddSingletonWithDecorator(typeof(FfProbeKeyframeExtractor));
serviceCollection.AddSingletonWithDecorator(typeof(MatroskaKeyframeExtractor));
serviceCollection.AddSingleton<IDynamicHlsPlaylistGenerator, DynamicHlsPlaylistGenerator>();
return serviceCollection;
}
private static void AddSingletonWithDecorator(this IServiceCollection serviceCollection, Type type)
{
serviceCollection.AddSingleton<IKeyframeExtractor>(serviceProvider =>
{
return serviceCollection.AddSingleton<IDynamicHlsPlaylistGenerator, DynamicHlsPlaylistGenerator>();
}
var extractor = ActivatorUtilities.CreateInstance(serviceProvider, type);
var decorator = ActivatorUtilities.CreateInstance<CacheDecorator>(serviceProvider, extractor);
return decorator;
});
}
}