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.decoding = false;
this.webrtcplayerState = playerStateIdle;
this.decodeInterval = 5;
this.decodeInterval = 3; //编码定时器
this.urgent = false;
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) {
// var self = this;
var playFrame={
@ -165,12 +172,17 @@ Player.prototype.processReq = function (req) {
case kstartPlayerCoderReq:
this.startDecoder();
break;
case kendPlayerCoderReq:
this.stopDecoder();
break;
case kInitPlayerReq:
this.displayLoop();
break;
case ksendPlayerVideoFrameReq:
this.onFrameData(req.d,req.l);
break;
default:
this.logger.logError("Unsupport messsage " + req.t);
}

5
test/common.js

@ -32,4 +32,9 @@ const kstartPlayerCoderReq = 1;
const ksendPlayerVideoFrameReq = 2;
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);
// totalSize += size
// 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++)
if (cacheBuffer != null) {
Module._free(cacheBuffer);
cacheBuffer = null;
}
H265Frame.shift();
decodet1=new Date().getTime();
}
}
@ -84,7 +83,7 @@ Decoder.prototype.startDecoding = function (interval) {
if (this.decodeTimer) {
clearInterval(this.decodeTimer);
}
this.decodeTimer = setInterval(this.decode, interval);
this.decodeTimer = setInterval(this.decode, 0);//interval);
};
Decoder.prototype.pauseDecoding = function () {
@ -155,6 +154,9 @@ Decoder.prototype.decode_seq=function() {
d: obj
};
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);
});
@ -171,6 +173,7 @@ Decoder.prototype.decode_seq=function() {
};
self.postMessage(objData);
}
Decoder.prototype.sendVideoFrame = function(data,len){

2
test/h265.js

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

4
test/mqtt.js

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

9
test/video.js

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

Loading…
Cancel
Save