DeviceProfile.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using MediaBrowser.Model.Entities;
  2. using System;
  3. using System.Linq;
  4. namespace MediaBrowser.Controller.Dlna
  5. {
  6. public class DeviceProfile
  7. {
  8. /// <summary>
  9. /// Gets or sets the name.
  10. /// </summary>
  11. /// <value>The name.</value>
  12. public string Name { get; set; }
  13. /// <summary>
  14. /// Gets or sets the transcoding profiles.
  15. /// </summary>
  16. /// <value>The transcoding profiles.</value>
  17. public TranscodingProfile[] TranscodingProfiles { get; set; }
  18. /// <summary>
  19. /// Gets or sets the direct play profiles.
  20. /// </summary>
  21. /// <value>The direct play profiles.</value>
  22. public DirectPlayProfile[] DirectPlayProfiles { get; set; }
  23. public ContainerProfile[] ContainerProfiles { get; set; }
  24. /// <summary>
  25. /// Gets or sets the identification.
  26. /// </summary>
  27. /// <value>The identification.</value>
  28. public DeviceIdentification Identification { get; set; }
  29. public string FriendlyName { get; set; }
  30. public string Manufacturer { get; set; }
  31. public string ManufacturerUrl { get; set; }
  32. public string ModelName { get; set; }
  33. public string ModelDescription { get; set; }
  34. public string ModelNumber { get; set; }
  35. public string ModelUrl { get; set; }
  36. public bool IgnoreTranscodeByteRangeRequests { get; set; }
  37. public bool SupportsAlbumArtInDidl { get; set; }
  38. /// <summary>
  39. /// Controls the content of the X_DLNADOC element in the urn:schemas-dlna-org:device-1-0 namespace.
  40. /// </summary>
  41. public string XDlnaDoc { get; set; }
  42. /// <summary>
  43. /// Controls the content of the X_DLNACAP element in the urn:schemas-dlna-org:device-1-0 namespace.
  44. /// </summary>
  45. public string XDlnaCap { get; set; }
  46. /// <summary>
  47. /// Controls the content of the aggregationFlags element in the urn:schemas-sonycom:av.
  48. /// </summary>
  49. public string SonyAggregationFlags { get; set; }
  50. public string ProtocolInfo { get; set; }
  51. public MediaProfile[] MediaProfiles { get; set; }
  52. public CodecProfile[] CodecProfiles { get; set; }
  53. public int TimelineOffsetSeconds { get; set; }
  54. public bool RequiresPlainVideoItems { get; set; }
  55. public bool RequiresPlainFolders { get; set; }
  56. public DeviceProfile()
  57. {
  58. DirectPlayProfiles = new DirectPlayProfile[] { };
  59. TranscodingProfiles = new TranscodingProfile[] { };
  60. MediaProfiles = new MediaProfile[] { };
  61. CodecProfiles = new CodecProfile[] { };
  62. ContainerProfiles = new ContainerProfile[] { };
  63. }
  64. public TranscodingProfile GetAudioTranscodingProfile(string container, string audioCodec)
  65. {
  66. container = (container ?? string.Empty).TrimStart('.');
  67. return TranscodingProfiles.FirstOrDefault(i =>
  68. {
  69. if (i.Type != DlnaProfileType.Audio)
  70. {
  71. return false;
  72. }
  73. if (!string.Equals(container, i.Container, StringComparison.OrdinalIgnoreCase))
  74. {
  75. return false;
  76. }
  77. if (!i.GetAudioCodecs().Contains(audioCodec ?? string.Empty))
  78. {
  79. return false;
  80. }
  81. return true;
  82. });
  83. }
  84. public TranscodingProfile GetVideoTranscodingProfile(string container, string audioCodec, string videoCodec)
  85. {
  86. container = (container ?? string.Empty).TrimStart('.');
  87. return TranscodingProfiles.FirstOrDefault(i =>
  88. {
  89. if (i.Type != DlnaProfileType.Video)
  90. {
  91. return false;
  92. }
  93. if (!string.Equals(container, i.Container, StringComparison.OrdinalIgnoreCase))
  94. {
  95. return false;
  96. }
  97. if (!i.GetAudioCodecs().Contains(audioCodec ?? string.Empty))
  98. {
  99. return false;
  100. }
  101. if (!string.Equals(videoCodec, i.VideoCodec, StringComparison.OrdinalIgnoreCase))
  102. {
  103. return false;
  104. }
  105. return true;
  106. });
  107. }
  108. public MediaProfile GetAudioMediaProfile(string container, string audioCodec, MediaStream audioStream)
  109. {
  110. container = (container ?? string.Empty).TrimStart('.');
  111. return MediaProfiles.FirstOrDefault(i =>
  112. {
  113. if (i.Type != DlnaProfileType.Audio)
  114. {
  115. return false;
  116. }
  117. var containers = i.GetContainers().ToList();
  118. if (containers.Count > 0 && !containers.Contains(container))
  119. {
  120. return false;
  121. }
  122. var audioCodecs = i.GetAudioCodecs().ToList();
  123. if (audioCodecs.Count > 0 && !audioCodecs.Contains(audioCodec ?? string.Empty))
  124. {
  125. return false;
  126. }
  127. return true;
  128. });
  129. }
  130. public MediaProfile GetVideoMediaProfile(string container, string audioCodec, string videoCodec, MediaStream audioStream, MediaStream videoStream)
  131. {
  132. container = (container ?? string.Empty).TrimStart('.');
  133. return MediaProfiles.FirstOrDefault(i =>
  134. {
  135. if (i.Type != DlnaProfileType.Video)
  136. {
  137. return false;
  138. }
  139. var containers = i.GetContainers().ToList();
  140. if (containers.Count > 0 && !containers.Contains(container))
  141. {
  142. return false;
  143. }
  144. var audioCodecs = i.GetAudioCodecs().ToList();
  145. if (audioCodecs.Count > 0 && !audioCodecs.Contains(audioCodec ?? string.Empty))
  146. {
  147. return false;
  148. }
  149. var videoCodecs = i.GetVideoCodecs().ToList();
  150. if (videoCodecs.Count > 0 && !videoCodecs.Contains(videoCodec ?? string.Empty))
  151. {
  152. return false;
  153. }
  154. return true;
  155. });
  156. }
  157. public MediaProfile GetPhotoMediaProfile(string container)
  158. {
  159. container = (container ?? string.Empty).TrimStart('.');
  160. return MediaProfiles.FirstOrDefault(i =>
  161. {
  162. if (i.Type != DlnaProfileType.Photo)
  163. {
  164. return false;
  165. }
  166. var containers = i.GetContainers().ToList();
  167. if (containers.Count > 0 && !containers.Contains(container))
  168. {
  169. return false;
  170. }
  171. return true;
  172. });
  173. }
  174. }
  175. }