DeviceProfile.cs 7.5 KB

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