DeviceProfile.cs 7.5 KB

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