DeviceProfile.cs 7.1 KB

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