No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

83 líneas
3.0 KiB

  1. using JT1078.Protocol;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Text;
  6. using Xunit;
  7. using JT1078.Protocol.Extensions;
  8. using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
  9. using System.Net.Sockets;
  10. using System.Threading;
  11. namespace JT1078.Hls.Test
  12. {
  13. public class M3U8_Test
  14. {
  15. /// <summary>
  16. /// 模拟发送视频数据
  17. /// </summary>
  18. [Fact]
  19. public void Test1()
  20. {
  21. try
  22. {
  23. var lines = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "jt1078_5.txt"));
  24. Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  25. clientSocket.Connect("127.0.0.1",1078);
  26. long lasttime = 0;
  27. foreach (var line in lines)
  28. {
  29. var temp = line.Split(',');
  30. if (lasttime == 0)
  31. {
  32. lasttime = long.Parse(temp[0]);
  33. }
  34. else {
  35. var ts = long.Parse(temp[0]) - lasttime;
  36. if (ts > 3) ts = 3;
  37. Thread.Sleep(TimeSpan.FromSeconds(ts));
  38. lasttime = long.Parse(temp[0]);
  39. }
  40. var data= temp[1].ToHexBytes();
  41. clientSocket.Send(data);
  42. }
  43. }
  44. catch (Exception ex)
  45. {
  46. //Assert.Throws<Exception>(() => { });
  47. }
  48. }
  49. /// <summary>
  50. /// 生成m3u8索引文件
  51. /// </summary>
  52. [Fact]
  53. public void Test4()
  54. {
  55. try
  56. {
  57. var hls_file_directory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "terminalno");
  58. if (!File.Exists(hls_file_directory)) Directory.CreateDirectory(hls_file_directory);
  59. var m3u8_filename = Path.Combine(hls_file_directory, "live.m3u8");
  60. TSEncoder tSEncoder = new TSEncoder();
  61. var m3u8Manage = new M3U8FileManage(new Options.M3U8Option { HlsFileDirectory = hls_file_directory, M3U8FileName = m3u8_filename }, tSEncoder);
  62. var lines = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_3.txt"));
  63. foreach (var line in lines)
  64. {
  65. var data = line.Split(',');
  66. var bytes = data[6].ToHexBytes();
  67. JT1078Package package = JT1078Serializer.Deserialize(bytes);
  68. JT1078Package fullpackage = JT1078Serializer.Merge(package);
  69. if (fullpackage != null)
  70. {
  71. m3u8Manage.CreateTsData(fullpackage);
  72. }
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. //Assert.Throws<Exception>(() => { });
  78. }
  79. }
  80. }
  81. }