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; /// /// Extensions for the interface. /// public static class MediaEncodingHlsServiceCollectionExtensions { /// /// Adds the hls playlist generators to the . /// /// An instance of the interface. /// The updated service collection. public static IServiceCollection AddHlsPlaylistGenerator(this IServiceCollection serviceCollection) { serviceCollection.AddSingletonWithDecorator(typeof(FfProbeKeyframeExtractor)); serviceCollection.AddSingletonWithDecorator(typeof(MatroskaKeyframeExtractor)); serviceCollection.AddSingleton(); return serviceCollection; } private static void AddSingletonWithDecorator(this IServiceCollection serviceCollection, Type type) { serviceCollection.AddSingleton(serviceProvider => { var extractor = ActivatorUtilities.CreateInstance(serviceProvider, type); var decorator = ActivatorUtilities.CreateInstance(serviceProvider, extractor); return decorator; }); } }