MediaOptions.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using MediaBrowser.Model.Dto;
  3. namespace MediaBrowser.Model.Dlna
  4. {
  5. /// <summary>
  6. /// Class MediaOptions.
  7. /// </summary>
  8. public class MediaOptions
  9. {
  10. /// <summary>
  11. /// Initializes a new instance of the <see cref="MediaOptions"/> class.
  12. /// </summary>
  13. public MediaOptions()
  14. {
  15. Context = EncodingContext.Streaming;
  16. EnableDirectPlay = true;
  17. EnableDirectStream = true;
  18. }
  19. /// <summary>
  20. /// Gets or sets a value indicating whether direct playback is allowed.
  21. /// </summary>
  22. public bool EnableDirectPlay { get; set; }
  23. /// <summary>
  24. /// Gets or sets a value indicating whether direct streaming is allowed.
  25. /// </summary>
  26. public bool EnableDirectStream { get; set; }
  27. /// <summary>
  28. /// Gets or sets a value indicating whether direct playback is forced.
  29. /// </summary>
  30. public bool ForceDirectPlay { get; set; }
  31. /// <summary>
  32. /// Gets or sets a value indicating whether direct streaming is forced.
  33. /// </summary>
  34. public bool ForceDirectStream { get; set; }
  35. /// <summary>
  36. /// Gets or sets a value indicating whether audio stream copy is allowed.
  37. /// </summary>
  38. public bool AllowAudioStreamCopy { get; set; }
  39. /// <summary>
  40. /// Gets or sets a value indicating whether video stream copy is allowed.
  41. /// </summary>
  42. public bool AllowVideoStreamCopy { get; set; }
  43. /// <summary>
  44. /// Gets or sets a value indicating whether always burn in subtitles when transcoding.
  45. /// </summary>
  46. public bool AlwaysBurnInSubtitleWhenTranscoding { get; set; }
  47. /// <summary>
  48. /// Gets or sets the item id.
  49. /// </summary>
  50. public Guid ItemId { get; set; }
  51. /// <summary>
  52. /// Gets or sets the media sources.
  53. /// </summary>
  54. public MediaSourceInfo[] MediaSources { get; set; } = Array.Empty<MediaSourceInfo>();
  55. /// <summary>
  56. /// Gets or sets the device profile.
  57. /// </summary>
  58. public required DeviceProfile Profile { get; set; }
  59. /// <summary>
  60. /// Gets or sets a media source id. Optional. Only needed if a specific AudioStreamIndex or SubtitleStreamIndex are requested.
  61. /// </summary>
  62. public string? MediaSourceId { get; set; }
  63. /// <summary>
  64. /// Gets or sets the device id.
  65. /// </summary>
  66. public string? DeviceId { get; set; }
  67. /// <summary>
  68. /// Gets or sets an override of supported number of audio channels
  69. /// Example: DeviceProfile supports five channel, but user only has stereo speakers.
  70. /// </summary>
  71. public int? MaxAudioChannels { get; set; }
  72. /// <summary>
  73. /// Gets or sets the application's configured maximum bitrate.
  74. /// </summary>
  75. public int? MaxBitrate { get; set; }
  76. /// <summary>
  77. /// Gets or sets the context.
  78. /// </summary>
  79. /// <value>The context.</value>
  80. public EncodingContext Context { get; set; }
  81. /// <summary>
  82. /// Gets or sets the audio transcoding bitrate.
  83. /// </summary>
  84. /// <value>The audio transcoding bitrate.</value>
  85. public int? AudioTranscodingBitrate { get; set; }
  86. /// <summary>
  87. /// Gets or sets an override for the audio stream index.
  88. /// </summary>
  89. public int? AudioStreamIndex { get; set; }
  90. /// <summary>
  91. /// Gets or sets an override for the subtitle stream index.
  92. /// </summary>
  93. public int? SubtitleStreamIndex { get; set; }
  94. /// <summary>
  95. /// Gets the maximum bitrate.
  96. /// </summary>
  97. /// <param name="isAudio">Whether or not this is audio.</param>
  98. /// <returns>System.Nullable&lt;System.Int32&gt;.</returns>
  99. public int? GetMaxBitrate(bool isAudio)
  100. {
  101. if (MaxBitrate.HasValue)
  102. {
  103. return MaxBitrate;
  104. }
  105. if (Profile is null)
  106. {
  107. return null;
  108. }
  109. if (Context == EncodingContext.Static)
  110. {
  111. if (isAudio && Profile.MaxStaticMusicBitrate.HasValue)
  112. {
  113. return Profile.MaxStaticMusicBitrate;
  114. }
  115. return Profile.MaxStaticBitrate;
  116. }
  117. return Profile.MaxStreamingBitrate;
  118. }
  119. }
  120. }