From e77a0d5968b45555fb762e085b02f14663d2c2ed Mon Sep 17 00:00:00 2001 From: "SmallChi(Koike)" <564952747@qq.com> Date: Fri, 6 Aug 2021 18:07:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0fmp4=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JT1078FMp4NormalMsgHostedService.cs | 15 ++++++----- .../wwwroot/fmp4_demo/index.html | 25 +++++++++++-------- src/JT1078.Gateway/JT1078.Gateway.csproj | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/JT1078.Gateway.Tests/JT1078.Gateway.TestNormalHosting/Services/JT1078FMp4NormalMsgHostedService.cs b/src/JT1078.Gateway.Tests/JT1078.Gateway.TestNormalHosting/Services/JT1078FMp4NormalMsgHostedService.cs index 248e0ac..b464ce3 100644 --- a/src/JT1078.Gateway.Tests/JT1078.Gateway.TestNormalHosting/Services/JT1078FMp4NormalMsgHostedService.cs +++ b/src/JT1078.Gateway.Tests/JT1078.Gateway.TestNormalHosting/Services/JT1078FMp4NormalMsgHostedService.cs @@ -60,7 +60,7 @@ namespace JT1078.Gateway.TestNormalHosting.Services string key = $"{data.GetKey()}_{ikey}"; if (data.Label3.DataType == Protocol.Enums.JT1078DataType.视频I帧) { - var moovBuffer = FM4Encoder.EncoderMoovBox( + var moovBuffer = FM4Encoder.VideoMoovBox( nalus.FirstOrDefault(f => f.NALUHeader.NalUnitType == NalUnitType.SPS), nalus.FirstOrDefault(f => f.NALUHeader.NalUnitType == NalUnitType.PPS)); memoryCache.Set(key, moovBuffer); @@ -76,11 +76,10 @@ namespace JT1078.Gateway.TestNormalHosting.Services { try { - var ftyp = FM4Encoder.EncoderFtypBox(); + var ftyp = FM4Encoder.FtypBox(); foreach (var session in firstHttpSessions) { - HttpSessionManager.SendAVData(session, ftyp, true); - HttpSessionManager.SendAVData(session, moov, false); + HttpSessionManager.SendAVData(session, ftyp.Concat(moov).ToArray(), true); } } catch (Exception ex) @@ -100,8 +99,8 @@ namespace JT1078.Gateway.TestNormalHosting.Services { //foreach (var session in otherHttpSessions) //{ - // var fmp4VideoBuffer = FM4Encoder.EncoderOtherVideoBox(nalus); - // HttpSessionManager.SendAVData(session, fmp4VideoBuffer, false); + // var fmp4VideoBuffer = FM4Encoder.OtherVideoBox(nalus); + // HttpSessionManager.SendAVData(session, FM4Encoder.StypBox().Concat(fmp4VideoBuffer).ToArray(), false); //} var firstNALU = nalus.FirstOrDefault(); if (firstNALU == null) @@ -126,8 +125,8 @@ namespace JT1078.Gateway.TestNormalHosting.Services { foreach (var session in otherHttpSessions) { - var fmp4VideoBuffer = FM4Encoder.EncoderOtherVideoBox(cacheNALU); - HttpSessionManager.SendAVData(session, fmp4VideoBuffer, false); + var fmp4VideoBuffer = FM4Encoder.OtherVideoBox(cacheNALU); + HttpSessionManager.SendAVData(session, FM4Encoder.StypBox().Concat(fmp4VideoBuffer).ToArray(), false); } cacheNALU.Clear(); } diff --git a/src/JT1078.Gateway.Tests/JT1078.Gateway.TestNormalHosting/wwwroot/fmp4_demo/index.html b/src/JT1078.Gateway.Tests/JT1078.Gateway.TestNormalHosting/wwwroot/fmp4_demo/index.html index 5a06948..c9d89bf 100644 --- a/src/JT1078.Gateway.Tests/JT1078.Gateway.TestNormalHosting/wwwroot/fmp4_demo/index.html +++ b/src/JT1078.Gateway.Tests/JT1078.Gateway.TestNormalHosting/wwwroot/fmp4_demo/index.html @@ -18,7 +18,7 @@ // *** USER PARAMETERS *** var verbose = true; // var verbose = true; // enable for saturating the console .. - var buffering_sec = 3; // use some reasonable value + var buffering_sec = 1; // use some reasonable value var buffering_sec_seek = buffering_sec * 0.9; // ..seek the stream if it's this much away or // from the last available timestamp @@ -117,15 +117,15 @@ // return; // } // keep the latency to minimum - let latest = stream_live.duration; - if ((stream_live.duration >= buffering_sec) && ((latest - stream_live.currentTime) > buffering_sec_seek)) { - console.log("seek from ", stream_live.currentTime, " to ", latest); - df = (stream_live.duration - stream_live.currentTime); // this much away from the last available frame - if ((df > buffering_sec_seek)) { - seek_to = stream_live.duration - buffering_sec_seek_distance; - stream_live.currentTime = seek_to; - } - } + // let latest = stream_live.duration; + // if ((stream_live.duration >= buffering_sec) && ((latest - stream_live.currentTime) > buffering_sec_seek)) { + // console.log("seek from ", stream_live.currentTime, " to ", latest); + // df = (stream_live.duration - stream_live.currentTime); // this much away from the last available frame + // if ((df > buffering_sec_seek)) { + // seek_to = stream_live.duration - buffering_sec_seek_distance; + // stream_live.currentTime = seek_to; + // } + // } if (!source_buffer.updating) { if (verbose) { console.log("Streaming started: ", memview[0], memview[1], memview[2], memview[3], memview[4]); } stream_started = true; @@ -166,7 +166,10 @@ source_buffer.mode = 'sequence'; // source_buffer.mode = 'segments'; source_buffer.addEventListener("updateend", loadPacket); - ws = new WebSocket("ws://127.0.0.1:81/live/JT1078_7.live.mp4"); //创建WebSocket连接 + //ws = new WebSocket("ws://49.235.89.102:15555/live.mp4?sim=19019000001&channel=3&token=123456"); + + ws = new WebSocket("ws://49.235.89.102:15555/live.mp4?sim=1901305037&channel=2&token=123456"); + //ws = new WebSocket("ws://127.0.0.1:81/live/JT1078_8.live.mp4"); //创建WebSocket连接 ws.binaryType = 'arraybuffer'; ws.onmessage = function (e) { //当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据 diff --git a/src/JT1078.Gateway/JT1078.Gateway.csproj b/src/JT1078.Gateway/JT1078.Gateway.csproj index 39741a9..22e70e2 100644 --- a/src/JT1078.Gateway/JT1078.Gateway.csproj +++ b/src/JT1078.Gateway/JT1078.Gateway.csproj @@ -40,7 +40,7 @@ - +