From 170ee55bd1f0858fdbad3147a72c0f185d49a9a6 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期四, 10 三月 2022 11:02:01 +0800 Subject: [PATCH] cameraPlayer 添加h265b播放功能 --- src/components/player/index.vue | 251 ++++++++++++++++++++++++------------------------- 1 files changed, 123 insertions(+), 128 deletions(-) diff --git a/src/components/player/index.vue b/src/components/player/index.vue index a1757a3..5962311 100644 --- a/src/components/player/index.vue +++ b/src/components/player/index.vue @@ -9,11 +9,11 @@ </div> </template> <script> -import Wfs from "./wfs"; -import VideoRuleData from "@/Pool/VideoRuleData"; -import TreeDataPool from "@/Pool/TreeData"; -import { getAllPolygon } from "@/api/polygon"; -import polygonCanvas from "@/components/canvas"; +import Wfs from "./wfs" +import VideoRuleData from "@/Pool/VideoRuleData" +import TreeDataPool from "@/Pool/TreeData" +import { getAllPolygon } from "@/api/polygon" +import polygonCanvas from "@/components/canvas" export default { name: "CameraPlayer", props: { @@ -76,35 +76,33 @@ canvasWidth: 0, canvasHeight: 0, algoDataSocket: null - }; + } }, watch: { - rtspUrl: function (newVal, oldVal) { + rtspUrl: function(newVal, oldVal) { if (newVal !== oldVal) { if (this.wfs.config) { - this.wfs.destroy(); + this.wfs.destroy() !!this.algoDataSocket && this.algoDataSocket.close() } this.$nextTick(() => { - this.clickStart(); - }); + this.clickStart() + }) } } }, mounted() { - this.clickStart(); + this.clickStart() this.$nextTick(() => { - this.canvas = this.$refs.areaCanvas; - this.ctx = this.canvas.getContext("2d"); - this.ctx.lineWidth = 1; - this.initArea(); - + this.canvas = this.$refs.areaCanvas + this.ctx = this.canvas.getContext("2d") + this.ctx.lineWidth = 1 + this.initArea() }) }, beforeDestroy() { - this.wfs.destroy(); - this.wfsId = ""; - + !!this.wfs && this.wfs.destroy() + this.wfsId = "" !!this.algoDataSocket && this.algoDataSocket.close() }, methods: { @@ -116,87 +114,86 @@ if (this.wfs.websocketLoader && this.wfs.websocketLoader.client) { if (this.wfs.websocketLoader.client.disconnected) { - this.clickStart(); + this.clickStart() console.log("瀹炴椂瑙嗛宸叉柇寮�锛屾鍦ㄩ噸杩�") return } } - let _this = this; + let _this = this setTimeout(() => { _this.checkConnect(id) }, 10000) }, clickStart() { if (this.rtspUrl == "") { - return; + return } - let cameraId = this.cameraID; + let cameraId = this.cameraID if (cameraId == "") { - cameraId = this.getUuid(); + cameraId = this.getUuid() } if (Wfs.isSupported()) { - let wsAddr = this.wsAddr; + let wsAddr = this.wsAddr let cameraInfo = { cameraID: cameraId, rtspUrl: this.rtspUrl, isRunning: this.isRunning, isGb28181: this.isGb - }; + } // let camera = document.getElementById(this.cameraID); - let camera = this.$refs.videoPlayer; - this.wfs = new Wfs(); - let randomId = this.getUuid(); - this.wfsId = randomId; - this.wfs.attachMedia(camera, "chX", "H264Raw", wsAddr, cameraInfo); + let camera = this.$refs.videoPlayer + this.wfs = new Wfs() + let randomId = this.getUuid() + this.wfsId = randomId + this.wfs.attachMedia(camera, "chX", "H264Raw", wsAddr, cameraInfo) this.checkConnect(randomId) } }, getUuid() { - var s = []; - var hexDigits = "0123456789abcdefghijkopqrst"; + var s = [] + var hexDigits = "0123456789abcdefghijkopqrst" for (var i = 0; i < 36; i++) { - s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); + s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1) } - s[14] = "4"; //聽bits聽12-15聽of聽the聽time_hi_and_version聽field聽to聽0010 - s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); //聽bits聽6-7聽of聽the聽clock_seq_hi_and_reserved聽to聽01 - s[8] = s[13] = s[18] = s[23] = "-"; - var uuid = s.join(""); - return uuid; + s[14] = "4" //聽bits聽12-15聽of聽the聽time_hi_and_version聽field聽to聽0010 + s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) //聽bits聽6-7聽of聽the聽clock_seq_hi_and_reserved聽to聽01 + s[8] = s[13] = s[18] = s[23] = "-" + var uuid = s.join("") + return uuid }, fullScreen() { - this.$refs.videoPlayer.webkitRequestFullScreen(); + this.$refs.videoPlayer.webkitRequestFullScreen() }, // 鍥炴樉cavas鏁版嵁 // 鐐瑰嚮閫変腑鍙樿壊 灏嗗綋鍓嶉〉闈㈡墍鏈夎矾寰勯噸缁樺垽鏂綋鍓嶉紶鏍囩殑鍧愭爣鍦ㄥ摢涓浘褰㈠唴 濡傛灉涓嶄紶鍧愭爣鍙傛暟灏辨槸鍥炴樉鐨勬柟娉� clickSelect(e) { - this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); - let _this = this; // 闆嗗悎涓亶鍘嗛渶瑕佸皢this杞瓨涓�涓嬩娇鐢� - _this.canvasData.line.forEach(function (v, i) { - _this.ctx.strokeStyle = "yellow"; - _this.ctx.beginPath(); - _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion); - _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion); - _this.ctx.stroke(); - _this.canvas.style.cursor = "default"; - }); - _this.canvasData.rect.forEach(function (v, i) { - _this.ctx.strokeStyle = "yellow"; - _this.ctx.beginPath(); - _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion); - _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion); - _this.ctx.lineTo(v.location[2].x / _this.showProportion, v.location[2].y / _this.showProportion); - _this.ctx.lineTo(v.location[3].x / _this.showProportion, v.location[3].y / _this.showProportion); - _this.ctx.lineTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion); - _this.ctx.stroke(); - _this.canvas.style.cursor = "default"; - - }); - _this.canvasData.arrow.forEach(function (v, i) { - _this.ctx.strokeStyle = "yellow"; + this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height) + let _this = this // 闆嗗悎涓亶鍘嗛渶瑕佸皢this杞瓨涓�涓嬩娇鐢� + _this.canvasData.line.forEach(function(v, i) { + _this.ctx.strokeStyle = "yellow" + _this.ctx.beginPath() + _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion) + _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion) + _this.ctx.stroke() + _this.canvas.style.cursor = "default" + }) + _this.canvasData.rect.forEach(function(v, i) { + _this.ctx.strokeStyle = "yellow" + _this.ctx.beginPath() + _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion) + _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion) + _this.ctx.lineTo(v.location[2].x / _this.showProportion, v.location[2].y / _this.showProportion) + _this.ctx.lineTo(v.location[3].x / _this.showProportion, v.location[3].y / _this.showProportion) + _this.ctx.lineTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion) + _this.ctx.stroke() + _this.canvas.style.cursor = "default" + }) + _this.canvasData.arrow.forEach(function(v, i) { + _this.ctx.strokeStyle = "yellow" _this.drawArrow( _this.ctx, v.location[0].x / _this.showProportion, @@ -206,25 +203,23 @@ 20, 30, "yellow" - ); - _this.canvas.style.cursor = "default"; - - }); - _this.canvasData.polygon.forEach(function (v, i) { + ) + _this.canvas.style.cursor = "default" + }) + _this.canvasData.polygon.forEach(function(v, i) { if (v.location.length === 0) { - return; + return } - _this.ctx.strokeStyle = "yellow"; - _this.ctx.beginPath(); - _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportionY); + _this.ctx.strokeStyle = "yellow" + _this.ctx.beginPath() + _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportionY) for (let i = 1; i < v.location.length; i++) { - _this.ctx.lineTo(v.location[i].x / _this.showProportion, v.location[i].y / _this.showProportionY); + _this.ctx.lineTo(v.location[i].x / _this.showProportion, v.location[i].y / _this.showProportionY) } - _this.ctx.closePath(); - _this.ctx.stroke(); - _this.canvas.style.cursor = "default"; - - }); + _this.ctx.closePath() + _this.ctx.stroke() + _this.canvas.style.cursor = "default" + }) }, // 绠ご缁樺埗鍑芥暟 @@ -241,68 +236,68 @@ // width = typeof width !== "undefined" ? width : 1; // color = typeof color !== "undefined" ? color : "yellow"; // 璁$畻鍚勮搴﹀拰瀵瑰簲鐨凱2,P3鍧愭爣 - let angle = (Math.atan2(fromY - toY, fromX - toX) * 180) / Math.PI; - let angle1 = ((angle + theta) * Math.PI) / 180; - let angle2 = ((angle - theta) * Math.PI) / 180; - let topX = headlen * Math.cos(angle1); - let topY = headlen * Math.sin(angle1); - let botX = headlen * Math.cos(angle2); - let botY = headlen * Math.sin(angle2); + let angle = (Math.atan2(fromY - toY, fromX - toX) * 180) / Math.PI + let angle1 = ((angle + theta) * Math.PI) / 180 + let angle2 = ((angle - theta) * Math.PI) / 180 + let topX = headlen * Math.cos(angle1) + let topY = headlen * Math.sin(angle1) + let botX = headlen * Math.cos(angle2) + let botY = headlen * Math.sin(angle2) - ctx.save(); - ctx.beginPath(); - let arrowX = fromX - topX; - let arrowY = fromY - topY; - ctx.moveTo(arrowX, arrowY); - ctx.moveTo(fromX, fromY); - ctx.lineTo(toX, toY); - arrowX = toX + topX; - arrowY = toY + topY; - ctx.moveTo(arrowX, arrowY); - ctx.lineTo(toX, toY); - arrowX = toX + botX; - arrowY = toY + botY; - ctx.lineTo(arrowX, arrowY); - ctx.strokeStyle = color; - ctx.lineWidth = width; - ctx.stroke(); - ctx.restore(); + ctx.save() + ctx.beginPath() + let arrowX = fromX - topX + let arrowY = fromY - topY + ctx.moveTo(arrowX, arrowY) + ctx.moveTo(fromX, fromY) + ctx.lineTo(toX, toY) + arrowX = toX + topX + arrowY = toY + topY + ctx.moveTo(arrowX, arrowY) + ctx.lineTo(toX, toY) + arrowX = toX + botX + arrowY = toY + botY + ctx.lineTo(arrowX, arrowY) + ctx.strokeStyle = color + ctx.lineWidth = width + ctx.stroke() + ctx.restore() }, // 鍥炴樉鍥惧舰澶囨敞 showRemarks(x, y, remarks) { - this.ctx.moveTo(x, y - 10); // 鍥犱负鏀惧ぇ涔嬪悗鏄痽-20锛屾墍浠ョ缉灏忕増鐨勪负y-10 - this.ctx.fillStyle = "green"; // 璁剧疆濉厖棰滆壊涓虹豢鑹� - this.ctx.font = '10px "寰蒋闆呴粦"'; // 璁剧疆瀛椾綋 - this.ctx.textBaseline = "bottom"; // 璁剧疆瀛椾綋搴曠嚎瀵归綈缁樺埗鍩虹嚎 - this.ctx.textAlign = "left"; // 璁剧疆瀛椾綋瀵归綈鐨勬柟寮� - this.ctx.fillText(remarks, x, y - 10); // 濉厖鏂囧瓧 + this.ctx.moveTo(x, y - 10) // 鍥犱负鏀惧ぇ涔嬪悗鏄痽-20锛屾墍浠ョ缉灏忕増鐨勪负y-10 + this.ctx.fillStyle = "green" // 璁剧疆濉厖棰滆壊涓虹豢鑹� + this.ctx.font = '10px "寰蒋闆呴粦"' // 璁剧疆瀛椾綋 + this.ctx.textBaseline = "bottom" // 璁剧疆瀛椾綋搴曠嚎瀵归綈缁樺埗鍩虹嚎 + this.ctx.textAlign = "left" // 璁剧疆瀛椾綋瀵归綈鐨勬柟寮� + this.ctx.fillText(remarks, x, y - 10) // 濉厖鏂囧瓧 }, getCanvasData(data) { - let polyon = { ...data }; - polyon.camera_id = this.Camera.cameraId; - savePolygon(polyon).then(rsp => { - this.Camera.getPolygon(); - this.Camera.getCameraTask(); - }); + let polyon = { ...data } + polyon.camera_id = this.Camera.cameraId + savePolygon(polyon).then((rsp) => { + this.Camera.getPolygon() + this.Camera.getCameraTask() + }) }, setWidthHeight() { - this.canvasWidth = this.$refs.videoPlayer.offsetWidth; - this.canvasHeight = this.$refs.videoPlayer.offsetHeight; + this.canvasWidth = this.$refs.videoPlayer.offsetWidth + this.canvasHeight = this.$refs.videoPlayer.offsetHeight console.log(this.canvasWidth, this.canvasHeight) }, async initArea() { - console.log('init') - const res = await getAllPolygon({ cameraId: this.TreeDataPool.selectedNode.id }); - this.canvasData.line = res.data.line; - this.canvasData.rect = res.data.rect; - this.canvasData.arrow = res.data.arrow; - this.canvasData.polygon = res.data.polygon; + console.log("init") + const res = await getAllPolygon({ cameraId: this.TreeDataPool.selectedNode.id }) + this.canvasData.line = res.data.line + this.canvasData.rect = res.data.rect + this.canvasData.arrow = res.data.arrow + this.canvasData.polygon = res.data.polygon console.log(this.canvasData) - this.clickSelect(this.canvasData); + this.clickSelect(this.canvasData) }, initAlgoDataWebScoket() { - if (typeof (WebSocket) === "undefined") { + if (typeof WebSocket === "undefined") { console.log("error,鎮ㄧ殑娴忚鍣ㄤ笉鏀寔socket") } else { this.algoDataSocket = new WebSocket() @@ -312,13 +307,13 @@ this.algoDataSocket.onerror = () => { console.log("杩炴帴閿欒") } - this.algoDataSocket.onmessage = msg => { + this.algoDataSocket.onmessage = (msg) => { console.log(msg) } } } } -}; +} </script> <style lang="scss"> -- Gitblit v1.8.0