MediaEncodingHlsServiceCollectionExtensions.cs 1.5 KB

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