| | | 1 | | using System; |
| | | 2 | | using Jellyfin.MediaEncoding.Hls.Cache; |
| | | 3 | | using Jellyfin.MediaEncoding.Hls.Extractors; |
| | | 4 | | using Jellyfin.MediaEncoding.Hls.Playlist; |
| | | 5 | | using Microsoft.Extensions.DependencyInjection; |
| | | 6 | | |
| | | 7 | | namespace Jellyfin.MediaEncoding.Hls.Extensions; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Extensions for the <see cref="IServiceCollection"/> interface. |
| | | 11 | | /// </summary> |
| | | 12 | | public static class MediaEncodingHlsServiceCollectionExtensions |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Adds the hls playlist generators to the <see cref="IServiceCollection"/>. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <param name="serviceCollection">An instance of the <see cref="IServiceCollection"/> interface.</param> |
| | | 18 | | /// <returns>The updated service collection.</returns> |
| | | 19 | | public static IServiceCollection AddHlsPlaylistGenerator(this IServiceCollection serviceCollection) |
| | 21 | 20 | | { |
| | 21 | 21 | | serviceCollection.AddSingletonWithDecorator(typeof(FfProbeKeyframeExtractor)); |
| | 21 | 22 | | serviceCollection.AddSingletonWithDecorator(typeof(MatroskaKeyframeExtractor)); |
| | 21 | 23 | | serviceCollection.AddSingleton<IDynamicHlsPlaylistGenerator, DynamicHlsPlaylistGenerator>(); |
| | 21 | 24 | | return serviceCollection; |
| | 21 | 25 | | } |
| | | 26 | | |
| | | 27 | | private static void AddSingletonWithDecorator(this IServiceCollection serviceCollection, Type type) |
| | 42 | 28 | | { |
| | 42 | 29 | | serviceCollection.AddSingleton<IKeyframeExtractor>(serviceProvider => |
| | 42 | 30 | | { |
| | 42 | 31 | | var extractor = ActivatorUtilities.CreateInstance(serviceProvider, type); |
| | 42 | 32 | | var decorator = ActivatorUtilities.CreateInstance<CacheDecorator>(serviceProvider, extractor); |
| | 42 | 33 | | return decorator; |
| | 42 | 34 | | }); |
| | 42 | 35 | | } |
| | | 36 | | } |