Browse Source

add stop play

m7s
xiangxud 2 years ago
parent
commit
31c9470dab
  1. 16
      test/Player.js
  2. 5
      test/common.js
  3. 11
      test/decoder.js
  4. 2
      test/h265.js
  5. 4
      test/mqtt.js
  6. 9
      test/video.js

16
test/Player.js

@ -14,7 +14,7 @@ function Player(){
this.decoder_type = DECODER_H265; this.decoder_type = DECODER_H265;
this.decoding = false; this.decoding = false;
this.webrtcplayerState = playerStateIdle; this.webrtcplayerState = playerStateIdle;
this.decodeInterval = 5; this.decodeInterval = 3; //编码定时器
this.urgent = false; this.urgent = false;
this.frameBuffer = []; this.frameBuffer = [];
@ -129,7 +129,14 @@ Player.prototype.displayLoop = function() {
} }
} }
}; };
Player.prototype.stopDecoder = function() {
var req={
t: kPauseDecodingReq,
}
this.decoderworker.postMessage(req);
// this.stopBuffering();
this.webrtcplayerState=playerStateIdle;
};
Player.prototype.renderVideoFrame = function (data) { Player.prototype.renderVideoFrame = function (data) {
// var self = this; // var self = this;
var playFrame={ var playFrame={
@ -165,12 +172,17 @@ Player.prototype.processReq = function (req) {
case kstartPlayerCoderReq: case kstartPlayerCoderReq:
this.startDecoder(); this.startDecoder();
break; break;
case kendPlayerCoderReq:
this.stopDecoder();
break;
case kInitPlayerReq: case kInitPlayerReq:
this.displayLoop(); this.displayLoop();
break; break;
case ksendPlayerVideoFrameReq: case ksendPlayerVideoFrameReq:
this.onFrameData(req.d,req.l); this.onFrameData(req.d,req.l);
break; break;
default: default:
this.logger.logError("Unsupport messsage " + req.t); this.logger.logError("Unsupport messsage " + req.t);
} }

5
test/common.js

@ -32,4 +32,9 @@ const kstartPlayerCoderReq = 1;
const ksendPlayerVideoFrameReq = 2; const ksendPlayerVideoFrameReq = 2;
const kplayeVideoFrame = 3; const kplayeVideoFrame = 3;
const kendPlayerCoderReq = 4;
//H265Transferreq
const kstartH265TransferReq = 0;
const kendH265TransferReq = 1;

11
test/decoder.js

@ -67,15 +67,14 @@ Decoder.prototype.decode=function(){
Module.HEAPU8.set(typedArray, cacheBuffer); Module.HEAPU8.set(typedArray, cacheBuffer);
// totalSize += size // totalSize += size
// console.log("[" + (++readerIndex) + "] Read len = ", size + ", Total size = " + totalSize) // console.log("[" + (++readerIndex) + "] Read len = ", size + ", Total size = " + totalSize)
const t2 = new Date().getTime()-decodet1;
console.log("decode time:"+t2+" len:"+size);//+" data:"+typedArray.toString(16));
Module._decodeData(cacheBuffer, size, pts++) Module._decodeData(cacheBuffer, size, pts++)
if (cacheBuffer != null) { if (cacheBuffer != null) {
Module._free(cacheBuffer); Module._free(cacheBuffer);
cacheBuffer = null; cacheBuffer = null;
} }
H265Frame.shift(); H265Frame.shift();
decodet1=new Date().getTime();
} }
} }
@ -84,7 +83,7 @@ Decoder.prototype.startDecoding = function (interval) {
if (this.decodeTimer) { if (this.decodeTimer) {
clearInterval(this.decodeTimer); clearInterval(this.decodeTimer);
} }
this.decodeTimer = setInterval(this.decode, interval); this.decodeTimer = setInterval(this.decode, 0);//interval);
}; };
Decoder.prototype.pauseDecoding = function () { Decoder.prototype.pauseDecoding = function () {
@ -155,6 +154,9 @@ Decoder.prototype.decode_seq=function() {
d: obj d: obj
}; };
self.postMessage(objData, [objData.d.data.buffer]); self.postMessage(objData, [objData.d.data.buffer]);
const t2 = new Date().getTime()-decodet1;
console.log("decode time:"+t2+" len:"+size);//+" data:"+typedArray.toString(16));
decodet1=new Date().getTime();
// displayVideoFrame(obj); // displayVideoFrame(obj);
}); });
@ -171,6 +173,7 @@ Decoder.prototype.decode_seq=function() {
}; };
self.postMessage(objData); self.postMessage(objData);
} }
Decoder.prototype.sendVideoFrame = function(data,len){ Decoder.prototype.sendVideoFrame = function(data,len){

2
test/h265.js

@ -69,7 +69,7 @@ function stopH265(){
} }
var receivet1=new Date().getTime(); var receivet1=new Date().getTime();
function initH265DC(pc,player) { function initH265DC(pc,player) {
console.log("initH265DC",Date());
h265DC = pc.createDataChannel("h265"); h265DC = pc.createDataChannel("h265");
let bRecH265=false; let bRecH265=false;
// var ctx = canvas.getContext("2d"); // var ctx = canvas.getContext("2d");

4
test/mqtt.js

@ -14,6 +14,7 @@ function getStreamWebrtc(player) {
pc = new RTCPeerConnection({ pc = new RTCPeerConnection({
iceServers: ICEServerkvm,//ICEServer iceServers: ICEServerkvm,//ICEServer
}); });
// initH265Transfer(pc,player);
initH265DC(pc,player); initH265DC(pc,player);
// Populate SDP field when finished gathering // Populate SDP field when finished gathering
pc.oniceconnectionstatechange = e => log(pc.iceConnectionState) pc.oniceconnectionstatechange = e => log(pc.iceConnectionState)
@ -104,7 +105,7 @@ initMqtt = function(player) {
break; break;
case "error": case "error":
console.log("msg:",input.msg); console.log("msg:",input.msg);
stopSession(); // stopSession();
break; break;
case "answer": case "answer":
var remoteSessionDescription = input.data; var remoteSessionDescription = input.data;
@ -143,6 +144,7 @@ function endMqtt() {
} }
function endWebrtc(){ function endWebrtc(){
stopH265(); stopH265();
// endH265Transfer();
pc.close(); pc.close();
} }
function sendCmdMsg(topic,cmdmsgtype,deviceid,msg,cmdmsg){ function sendCmdMsg(topic,cmdmsgtype,deviceid,msg,cmdmsg){

9
test/video.js

@ -4,6 +4,8 @@ var player=null;
function handleVideo() { function handleVideo() {
player = new Worker("Player.js"); player = new Worker("Player.js");
// H265transferworker = new Worker ("")
startDeviceSession(player); startDeviceSession(player);
player.onmessage = function (evt){ player.onmessage = function (evt){
var objData = evt.data; var objData = evt.data;
@ -21,7 +23,14 @@ function handleVideo() {
player.postMessage(req); player.postMessage(req);
} }
function stopDecoder(){
var req = {
t: kendPlayerCoderReq,
};
player.postMessage(req);
}
function stopVideo(){ function stopVideo(){
stopDecoder();
endWebrtc(); endWebrtc();
endMqtt(); endMqtt();
} }

Loading…
Cancel
Save