DeviceProfile.cs 7.8 KB

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