CoreAppHost.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using Emby.Drawing;
  5. using Emby.Server.Implementations;
  6. using Jellyfin.Drawing.Skia;
  7. using MediaBrowser.Common.Net;
  8. using MediaBrowser.Controller.Drawing;
  9. using MediaBrowser.Model.IO;
  10. using Microsoft.Extensions.DependencyInjection;
  11. using Microsoft.Extensions.Logging;
  12. namespace Jellyfin.Server
  13. {
  14. /// <summary>
  15. /// Implementation of the abstract <see cref="ApplicationHost" /> class.
  16. /// </summary>
  17. public class CoreAppHost : ApplicationHost
  18. {
  19. /// <summary>
  20. /// Initializes a new instance of the <see cref="CoreAppHost" /> class.
  21. /// </summary>
  22. /// <param name="applicationPaths">The <see cref="ServerApplicationPaths" /> to be used by the <see cref="CoreAppHost" />.</param>
  23. /// <param name="loggerFactory">The <see cref="ILoggerFactory" /> to be used by the <see cref="CoreAppHost" />.</param>
  24. /// <param name="options">The <see cref="StartupOptions" /> to be used by the <see cref="CoreAppHost" />.</param>
  25. /// <param name="fileSystem">The <see cref="IFileSystem" /> to be used by the <see cref="CoreAppHost" />.</param>
  26. /// <param name="networkManager">The <see cref="INetworkManager" /> to be used by the <see cref="CoreAppHost" />.</param>
  27. public CoreAppHost(
  28. ServerApplicationPaths applicationPaths,
  29. ILoggerFactory loggerFactory,
  30. StartupOptions options,
  31. IFileSystem fileSystem,
  32. INetworkManager networkManager)
  33. : base(
  34. applicationPaths,
  35. loggerFactory,
  36. options,
  37. fileSystem,
  38. networkManager)
  39. {
  40. }
  41. /// <inheritdoc/>
  42. protected override void RegisterServices(IServiceCollection serviceCollection)
  43. {
  44. // Register an image encoder
  45. bool useSkiaEncoder = SkiaEncoder.IsNativeLibAvailable();
  46. Type imageEncoderType = useSkiaEncoder
  47. ? typeof(SkiaEncoder)
  48. : typeof(NullImageEncoder);
  49. serviceCollection.AddSingleton(typeof(IImageEncoder), imageEncoderType);
  50. // Log a warning if the Skia encoder could not be used
  51. if (!useSkiaEncoder)
  52. {
  53. Logger.LogWarning($"Skia not available. Will fallback to {nameof(NullImageEncoder)}.");
  54. }
  55. base.RegisterServices(serviceCollection);
  56. }
  57. /// <inheritdoc />
  58. protected override void RestartInternal() => Program.Restart();
  59. /// <inheritdoc />
  60. protected override IEnumerable<Assembly> GetAssembliesWithPartsInternal()
  61. {
  62. yield return typeof(CoreAppHost).Assembly;
  63. }
  64. /// <inheritdoc />
  65. protected override void ShutdownInternal() => Program.Shutdown();
  66. }
  67. }