StreamBuilderTests.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using MediaBrowser.Model.Dlna;
  2. using MediaBrowser.Model.Dlna.Profiles;
  3. using MediaBrowser.Model.Dto;
  4. using MediaBrowser.Model.Entities;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. using System;
  7. using System.Collections.Generic;
  8. namespace MediaBrowser.Tests.Dlna
  9. {
  10. [TestClass]
  11. public class StreamBuilderTests
  12. {
  13. [TestMethod]
  14. public void TestVideoProfile()
  15. {
  16. var profile = new AndroidProfile(true, false, new[]
  17. {
  18. "high",
  19. "baseline",
  20. "constrained baseline"
  21. });
  22. var builder = new StreamBuilder();
  23. var mediaSources = new List<MediaSourceInfo>
  24. {
  25. new MediaSourceInfo
  26. {
  27. Bitrate = 6200000,
  28. Container = "mkv",
  29. Path= "\\server\\test.mkv",
  30. Protocol = Model.MediaInfo.MediaProtocol.File,
  31. RunTimeTicks = TimeSpan.FromMinutes(60).Ticks,
  32. VideoType = VideoType.VideoFile,
  33. Type = MediaSourceType.Default,
  34. MediaStreams = new List<MediaStream>
  35. {
  36. new MediaStream
  37. {
  38. Codec = "H264",
  39. Type = MediaStreamType.Video,
  40. Profile = "High",
  41. IsCabac = true
  42. },
  43. new MediaStream
  44. {
  45. Codec = "AC3",
  46. Type = MediaStreamType.Audio
  47. }
  48. }
  49. }
  50. };
  51. var options = new VideoOptions
  52. {
  53. Context = EncodingContext.Streaming,
  54. DeviceId = Guid.NewGuid().ToString(),
  55. ItemId = Guid.NewGuid().ToString(),
  56. Profile = profile,
  57. MediaSources = mediaSources
  58. };
  59. var streamInfo = builder.BuildVideoItem(options);
  60. var url = streamInfo.ToDlnaUrl("http://localhost:8096");
  61. var containsHighProfile = url.IndexOf(";high;", StringComparison.OrdinalIgnoreCase) != -1;
  62. var containsBaseline = url.IndexOf(";baseline;", StringComparison.OrdinalIgnoreCase) != -1;
  63. Assert.IsTrue(containsHighProfile);
  64. Assert.IsFalse(containsBaseline);
  65. var isHls = url.IndexOf("master.m3u8?", StringComparison.OrdinalIgnoreCase) != -1;
  66. Assert.IsTrue(isHls);
  67. }
  68. }
  69. }