Browse Source

创建m7s分支,用以播放m7s流,需要对应m7s v3扩展开发

m7s
zhangdongfang 2 years ago
parent
commit
fbd79c75f4
  1. 40
      test/main.html
  2. 92
      test/metaRTC.js
  3. 13
      test/styles/style.css
  4. 48
      test/video.js
  5. 13
      test/windows.js

40
test/main.html

@ -35,11 +35,12 @@
<option value="ws">WS</option> <option value="ws">WS</option>
<option value="httpFlv">HTTP-FLV</option> <option value="httpFlv">HTTP-FLV</option>
</select> </select>
<input type="text" id="inputUrl" value="webrtc://192.168.0.18:1988/live/livestream" style="width:240px"/> <!-- <input type="text" id="inputUrl" value="webrtc://192.168.0.18:1988/live/livestream" style="width:240px"/> -->
<select id="decodeType" onchange="onSelectDecode()"> <input type="text" id="inputUrl" value="http://127.0.0.1:8081/api/webrtc/playpro?streamPath=live/livestream" style="width:240px"/>
<!-- <select id="decodeType" onchange="onSelectDecode()">
<option value="H264">H264</option> <option value="H264">H264</option>
<option value="H265">H265</option> <option value="H265">H265</option>
</select> </select> -->
<select id="resolutionId" onchange="onSelectResolution()"> <select id="resolutionId" onchange="onSelectResolution()">
<option value="1080">F_1080</option> <option value="1080">F_1080</option>
<option value="720">F_720</option> <option value="720">F_720</option>
@ -62,38 +63,7 @@
<span></span> <span></span>
<span></span> <span></span>
</div> </div>
<!-- <canvas id="playCanvas" width="852" height="480"></canvas> <!-- <canvas id="playCanvas" width="1920" height="1080"></canvas> -->
-->
<!-- <div style="margin-top: 10px"> -->
<!-- <div class="video-main">
<br><video controlsList="nodownload noplaybackrate nofullscreen noremoteplayback"
disablePictureInPicture id="remote-video" autoplay class="m-0 p-0"
style="position: relative; top: 0; left: 0; z-index: 1;width:100%; height:100%;object-fit:fill">
<style type="text/css">
video::-webkit-media-controls {
display: none !important;
}
/*video隐藏全屏按钮*/
video::-webkit-media-controls-fullscreen-button {
display: none !important;
}
/*video隐藏音量控制*/
video::-webkit-media-controls-volume-control-container {
display: none !important;
}
video::-webkit-progress-bar {
display: none !important;
}
</style>
</video>
</div>
</div> -->
<!-- <video id="playCanvas" width="1920" height="1080"></video> -->
<canvas id="playCanvas" width="1920" height="1080"></canvas>
<!-- </div> -->
</div> </div>
<div class="sideBar"> <div class="sideBar">
<span class="no-padding"> <span class="no-padding">

92
test/metaRTC.js

@ -1,6 +1,7 @@
// Internal APIs. // Internal APIs.
var __internal = { var __internal = {
defaultPath: '/rtc/v1/play/', defaultPath: '/rtc/v1/play/',
// defaultPath: '/api/webrtc/playpro',
prepareUrl: function (webrtcUrl) { prepareUrl: function (webrtcUrl) {
var urlObject = self.__internal.parse(webrtcUrl); var urlObject = self.__internal.parse(webrtcUrl);
var schema="http:"; var schema="http:";
@ -136,47 +137,75 @@
}; };
var datachannel=null; var datachannel=null;
function StartMetaRTC(url){ function StartMetaRTC(url,player){
var conf = __internal.prepareUrl(url); var conf = __internal.prepareUrl(url);
pc = new RTCPeerConnection({
iceServers: ICEServermetaRTC
});
if(bAudio) { pc = new RTCPeerConnection(null);
const { receiveraudio } = pc.addTransceiver('audio', { direction: 'recvonly' }); // if(bAudio) {
OnTrack(pc)
}
if(bVideo) {
const { receivervideo } = pc.addTransceiver('video', { direction: 'recvonly' }); // const { receiveraudio } = pc.addTransceiver('audio', { direction: 'recvonly' });
OnTrack(pc) // OnTrack(pc)
// }
if(bVideo) {
initH265DC(pc,player);
if(!bDecodeH264){
media_mode= "h265";
// H265transferworker = new Worker ("")
}else{
media_mode= "h264";
}
const { receivervideo } = pc.addTransceiver('video', { direction: 'recvonly' });
// OnTrack(pc)
}
}
// Populate SDP field when finished gathering
pc.oniceconnectionstatechange = e => {
log(pc.iceConnectionState)
}
pc.onicecandidate = event => { // Populate SDP field when finished gathering
pc.oniceconnectionstatechange = e => {
log(pc.iceConnectionState)
if(!bDecodeH264){
var state ={
t: kconnectStatusResponse,
s: pc.connectionState
}
player.postMessage(state)
}
}
pc.onicecandidate = event => {
if (event.candidate === null) { if (event.candidate === null) {
var offer=pc.localDescription var offer=pc.localDescription
var data = { var data = {
api: conf.apiUrl, tid: conf.tid, streamurl: conf.streamUrl, api: conf.apiUrl,
clientip: null, sdp: offer.sdp tid: conf.tid,
streamurl: conf.streamUrl,
clientip: null,
sdp: offer.sdp,
// type: "answer"
type: "offer"
}; };
console.log("Generated offer: ", data); console.log("Generated offer: ", data);
console.log("Generated conf: ", conf);
ajax({ ajax({
type:"POST", type:"POST",
url:conf.apiUrl, // url:conf.apiUrl+conf.urlObject.app+"/"+conf.urlObject.stream,
url:conf.streamUrl,
dataType:"json", dataType:"json",
data:offer.sdp+"}", data:JSON.stringify(data),
beforeSend:function(){ beforeSend:function(){
//some js code //some js code
}, },
success:function(msg){ success:function(msg){
console.log(msg) if(!msg.isH265){
media_mode= "h264";
bDecodeH264 = true
stopH265()
OnTrack(pc)
}else{
CreateCanvas()
}
pc.setRemoteDescription(new RTCSessionDescription({type: 'answer', sdp: msg.sdp})); pc.setRemoteDescription(new RTCSessionDescription({type: 'answer', sdp: msg.sdp}));
}, },
error:function(){ error:function(){
@ -186,22 +215,9 @@ pc.onicecandidate = event => {
} }
} }
datachannel=self.pc.createDataChannel('chat');
pc.createOffer().then(d => pc.setLocalDescription(d)).catch(log)
datachannel.onopen = function(event) {
console.log("datachannel onopen: ", event);
}
datachannel.onmessage = function(event) {
console.log("receive message: ", event.data);
// $('#datachannel_recv').val(event.data);
}
datachannel.onerror=function(event) {
console.log("datachannel error: ", event.data);
}
datachannel.onclose=function(event) {
console.log("datachannel close: ");
}
pc.createOffer().then(d => pc.setLocalDescription(d)).catch(log)
} }

13
test/styles/style.css

@ -29,7 +29,7 @@
display: block; display: block;
} }
.webrtcPlayer { /*.webrtcPlayer {
width: 848px; width: 848px;
height: 448px; height: 448px;
background-color: rgb(14, 13, 13); background-color: rgb(14, 13, 13);
@ -39,6 +39,17 @@
top: 51.5%; top: 51.5%;
transform: translate(-50%,-50%); transform: translate(-50%,-50%);
z-index: 10; z-index: 10;
}*/
.webrtcPlayer {
width: 852px;
height: 480px;
background-color: rgb(14, 13, 13);
border: 2px solid rgba(0, 0, 0, 0.9);
/* position: absolute; */
/* left: 50%; */
/* top: 51.5%; */
/* transform: translate(-50%,-50%); */
z-index: 10;
} }
#videoPlayer { #videoPlayer {
width: 852px; width: 852px;

48
test/video.js

@ -6,21 +6,43 @@ var sdk = null; // Global handler to do cleanup when replaying.
// var DECODER_TYPE = kDecoder_prod_h265_wasm_combine_js; // var DECODER_TYPE = kDecoder_prod_h265_wasm_combine_js;
function startPlay(url) { function startPlay(url) {
if(url===undefined||url.value===""){ if(url===undefined||url.value===""){
alert("url is null") alert("url is null")
return; return;
} }
StartMetaRTC(url) player = new Worker("Player.js");
var el = document.getElementById("btnPlayVideo");
StartMetaRTC(url,player)
};
function onSelectDecode(){ player.onmessage = function (evt){
var decodetype=document.getElementById("decodeType"); var objData = evt.data;
if(decodetype.value==="H264"){ switch (objData.t) {
bDecodeH264=true; case kplayeVideoFrame:
}else{ if(DECODER_TYPE===kDecoder_missile_decoder_js){
bDecodeH264=false; missle_renderFrame(objData.d)
}else{
webgldisplayVideoFrame(objData.d);
}
break;
case kplaterNetStatus:
netstatus(objData.s)
break;
default:
break;
}
} }
} var req = {
t: kstartPlayerCoderReq,
decoder_type: DECODER_TYPE
};
player.postMessage(req);
el.src = "img/pause.png";
};
function onSelectResolution() { function onSelectResolution() {
// switch resolution { // switch resolution {
// case "1080": // case "1080":

13
test/windows.js

@ -9,8 +9,19 @@ function CreateVideoDiv(el){
// el.offsetTop=parentDiv.offsetTop+50; // el.offsetTop=parentDiv.offsetTop+50;
el.setAttribute("id","remote-video"); el.setAttribute("id","remote-video");
parentDiv.appendChild(el); parentDiv.appendChild(el);
window.document.body.appendChild(parentDiv); body = document.getElementsByClassName("canvasDiv")[0]
// window.document.body.appendChild(parentDiv);
body.appendChild(parentDiv);
} }
function CreateCanvas(){
var parentDiv = document.createElement("canvas");//创建父div
parentDiv.setAttribute("width",1920)
parentDiv.setAttribute("height",1080)
parentDiv.id = "playCanvas"
body = document.getElementsByClassName("canvasDiv")[0]
body.appendChild(parentDiv);
}
function FullScreen() { function FullScreen() {
var ele = document.getElementById("remote-video"); var ele = document.getElementById("remote-video");

Loading…
Cancel
Save