DeviceProfile.cs 7.4 KB

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