public void Test4() { try { var hls_file_directory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "terminalno"); if (!File.Exists(hls_file_directory)) { Directory.CreateDirectory(hls_file_directory); } var m3u8_filename = Path.Combine(hls_file_directory, "live.m3u8"); TSEncoder tSEncoder = new TSEncoder(); var m3u8Manage = new M3U8FileManage(new Options.M3U8Option { HlsFileDirectory = hls_file_directory, M3U8FileName = m3u8_filename }, tSEncoder); var lines = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_3.txt")); foreach (var line in lines) { var data = line.Split(','); var bytes = data[6].ToHexBytes(); JT1078Package package = JT1078Serializer.Deserialize(bytes); JT1078Package fullpackage = JT1078Serializer.Merge(package); if (fullpackage != null) { m3u8Manage.CreateTsData(fullpackage); } } } catch (Exception ex) { //Assert.Throws<Exception>(() => { }); } }
protected override Task ExecuteAsync(CancellationToken stoppingToken) { PackageConsumer.OnMessage((Message) => { var merge = JT1078.Protocol.JT1078Serializer.Merge(Message.Data); if (merge != null) { var hasHttpSessionn = HttpSessionManager.GetAllHttpContextBySimAndChannelNo(merge.SIM, merge.LogicChannelNumber); if (hasHttpSessionn.Count > 0) { M3U8FileManage.CreateTsData(merge); } else { M3U8FileManage.Clear(merge.SIM, merge.LogicChannelNumber); } } }); return(Task.CompletedTask); }
protected async override Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { var data = await messageDispatchDataService.HlsChannel.Reader.ReadAsync(); logger.LogDebug($"设备{data.SIM},{data.LogicChannelNumber},session:{System.Text.Json.JsonSerializer.Serialize(HttpSessionManager)}"); var hasHttpSessionn = HttpSessionManager.GetAllHttpContextBySimAndChannelNo(data.SIM, data.LogicChannelNumber).Where(m => m.RTPVideoType == Metadata.RTPVideoType.Http_Hls).ToList(); if (hasHttpSessionn.Count > 0) { logger.LogDebug($"设备{data.SIM},{data.LogicChannelNumber}连上了"); M3U8FileManage.CreateTsData(data); } else { logger.LogDebug($"没有设备链接"); } } await Task.CompletedTask; }