调整监控控制

This commit is contained in:
Yutousama 2022-03-02 14:43:04 +08:00
parent a6660cdb6a
commit c1e8d1714c
7 changed files with 90 additions and 1941 deletions

View File

@ -20,6 +20,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -296,7 +297,7 @@ public class NasManager {
@RequestMapping("/nas/door/cctv.do") @RequestMapping("/nas/door/cctv.do")
public void getDoorCCTV(HttpServletResponse response){ public void getDoorCCTV(HttpServletResponse response){
try { try {
response.sendRedirect(UpdateIp.nas_ip+":9999/live/index.m3u8"); response.sendRedirect("http://"+UpdateIp.nas_ip+":9999/live/index.m3u8");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -307,9 +308,37 @@ public class NasManager {
if(!name.endsWith(".ts")){ if(!name.endsWith(".ts")){
return; return;
} }
response.sendRedirect(UpdateIp.nas_ip+":9999/live/"+request.getRequestURI().replace("/nas/door/","")); response.sendRedirect("http://"+UpdateIp.nas_ip+":9999/live/"+request.getRequestURI().replace("/nas/door/",""));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ResponseBody
@RequestMapping("/door/set.do")
public JSONObject setDoorConfig(String status){
JSONObject json=new JSONObject();
JSONObject data=JSONObject.parseObject(HttpTools.get("http://"+UpdateIp.nas_ip+":8000/door/data.do"));
BigDecimal zoom=new BigDecimal(Float.toString(data.getFloat("zoom")));
float _zoom=0;
switch (status){
case "reboot":
json.put("msg",HttpTools.https_get("http://"+UpdateIp.nas_ip+":8000/door/reboot.do",null));
break;
case "up":
_zoom=zoom.add(new BigDecimal("0.1")).floatValue();
json.put("msg","已设置焦距:"+_zoom);
HttpTools.get("http://"+UpdateIp.nas_ip+":8000/door/zoom.do?zoom="+_zoom);
break;
case "down":
_zoom=zoom.subtract(new BigDecimal("0.1")).floatValue();
json.put("msg","已设置焦距:"+_zoom);
HttpTools.get("http://"+UpdateIp.nas_ip+":8000/door/zoom.do?zoom="+_zoom);
break;
case "warning":
json.put("msg","已播放警告音频");
HttpTools.get("http://"+UpdateIp.nas_ip+":8000/door/audio_url.do?url=http%3A%2F%2F192.168.31.88%3A803%2Fwarning.mp3");
break;
}
return json;
}
} }

View File

@ -1,6 +1,7 @@
package com.yutou.tools.nas; package com.yutou.tools.nas;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yutou.tools.utils.ConfigTools;
import com.yutou.tools.utils.RedisTools; import com.yutou.tools.utils.RedisTools;
import com.yutou.tools.utils.Tools; import com.yutou.tools.utils.Tools;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -21,6 +22,11 @@ import java.util.regex.Pattern;
public class UpdateIp { public class UpdateIp {
private static List<String> keys = new ArrayList<>(); private static List<String> keys = new ArrayList<>();
public static String nas_ip=null; public static String nas_ip=null;
static {
if ("dev".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))) {
nas_ip="192.168.31.88";
}
}
/* static { /* static {
keys.add("nas.yutou233.cn;"); keys.add("nas.yutou233.cn;");
keys.add("bt.yutou233.cn;"); keys.add("bt.yutou233.cn;");

View File

@ -18,23 +18,38 @@
<div class="layui-body" style="left: 200px;overflow:auto;"> <div class="layui-body" style="left: 200px;overflow:auto;">
<div id="side"></div> <div id="side"></div>
<div class="myDiy"> <div class="myDiy">
<video id="myVideo" class="video-js vjs-default-skin vjs-big-play-centered" controls preload="auto" width="1080" <div class="myVideo">
<video id="myVideo" class="video-js vjs-default-skin vjs-big-play-centered" controls preload="auto"
width="1080"
height="708" data-setup='{}'> height="708" data-setup='{}'>
<source id="source" src="/nas/door/cctv.do" type="application/x-mpegURL"> <source id="source" src="/nas/door/cctv.do" type="application/x-mpegURL">
</video> </video>
<button id="myButton" type="button" class="button layui-btn-radius layui-btn layui-btn-lg layui-btn-normal"> </div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <div class="myButtons">
<button id="reboot" type="button"
class="button layui-btn layui-btn layui-btn-normal">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</button> </button>
<button id="myRecord" type="button" class="button layui-btn-radius layui-btn layui-btn-lg layui-btn-normal"> <button id="down" type="button"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class="button layui-btn layui-btn-normal">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</button> </button>
<button id="up" type="button" class="button layui-btn layui-btn-normal">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</button>
<div style="margin-top: 10px"></div>
<button id="warning" type="button" class="button layui-btn layui-btn-normal">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</button>
</div>
</div> </div>
<div id="footer"></div> <div id="footer"></div>
</div> </div>
</div> </div>
</body> </body>
<script src="/layui/layui.js"></script> <script src="/layui/layui.js"></script>
<script src="/js/jquery-3.2.1.js"></script> <script src="/js/jquery-3.2.1.js"></script>
@ -49,7 +64,7 @@
$('#side').load("/html/body/nas/side.html"); $('#side').load("/html/body/nas/side.html");
let token = getParam('token'); let token = getParam('token');
let myVideo= videojs('myVideo', { let myVideo = videojs('myVideo', {
bigPlayButton: true, bigPlayButton: true,
@ -62,38 +77,26 @@
}) })
$('#reboot').click(function () {
$('#myButton').click(function () { config('reboot')
$.get('/door/set.do?status=open', function (ret) {
if (ret === "1") {
let index = layer.load(2, {shade: [0.45, '#57606f']});
load(index)
}
}) })
$('#up').mousedown(function () {
config('up')
}) })
$('#myRecord').mousedown(function () { $('#down').mouseup(function () {
console.log("down") config('down')
startRecording()
}) })
$('#myRecord').mouseup(function () { $('#warning').mouseup(function () {
console.log("up") config('warning')
stopRecording()
}) })
function load(index) { function config(status) {
$.get("/door/status.do", function (ret) { $.post("/door/set.do", {status: status}, function (json) {
if (ret === "1") { layer.msg(json.msg)
layer.close(index)
layer.msg("已开门")
} else {
load(index)
}
}); });
} }
var audio_context; let audio_context;
var recorder;
function startUserMedia(stream) { function startUserMedia(stream) {
var input = audio_context.createMediaStreamSource(stream); var input = audio_context.createMediaStreamSource(stream);
@ -104,55 +107,9 @@
//input.connect(audio_context.destination); //input.connect(audio_context.destination);
__log('Input connected to audio context destination.'); __log('Input connected to audio context destination.');
recorder = new Recorder(input, {
numChannels: 1
});
__log('Recorder initialised.'); __log('Recorder initialised.');
} }
function startRecording() {
recorder && recorder.record();
__log('Recording...');
}
function stopRecording() {
recorder && recorder.stop();
__log('Stopped recording.');
// create WAV download link using audio data blob
createDownloadLink();
recorder.clear();
}
function createDownloadLink() {
console.log("check audio...")
recorder && recorder.exportWAV(function (blob) {
console.log('get vudio')
var formData = new FormData()
console.log(Object.prototype.toString.call(blob))
formData.append('audio', blob, new Date().toISOString() + '.wav')
$.ajax({
url: '/door/audio.do',
type: 'POST',
//contentType: 'application/octet-stream',
contentType: false,
processData: false, // 增加这一行,不处理参数
data: formData,
success: function (result) {
console.log(result)
}
})
// var url = URL.createObjectURL(blob);
// var hf = document.createElement('a');
// hf.href = url;
// hf.download = new Date().toISOString() + '.wav';
// hf.innerHTML = hf.download;
// hf.click()
// console.log(url)
});
}
function __log(log) { function __log(log) {
console.log(log) console.log(log)
@ -184,15 +141,25 @@
</script> </script>
<style> <style>
.myDiy { .myDiy {
width: 20%; width: 100%;
height: 300px; height: 300px;
margin-top: 10px; margin-top: 10px;
margin-left: 15%; margin-left: 15%;
float: left;
}
.myVideo {
width: 70%;
float: left;
}
.myButtons {
width: 30%;
float: right;
} }
.button { .button {
width: 100px;
height: 100px;
font-size: 1em; font-size: 1em;
} }
</style> </style>

1446
web/js/libmp3lame.min.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,41 +0,0 @@
importScripts('libmp3lame.min.js');
var mp3codec;
self.onmessage = function(e) {
switch (e.data.cmd) {
case 'init':
if (!e.data.config) {
e.data.config = { };
}
mp3codec = Lame.init();
Lame.set_mode(mp3codec, e.data.config.mode || Lame.JOINT_STEREO);
Lame.set_num_channels(mp3codec, e.data.config.channels || 2);
Lame.set_num_samples(mp3codec, e.data.config.samples || -1);
Lame.set_in_samplerate(mp3codec, e.data.config.samplerate || 44100);
Lame.set_out_samplerate(mp3codec, e.data.config.samplerate || 44100);
Lame.set_bitrate(mp3codec, e.data.config.bitrate || 128);
Lame.init_params(mp3codec);
console.log('Version :', Lame.get_version() + ' / ',
'Mode: '+Lame.get_mode(mp3codec) + ' / ',
'Samples: '+Lame.get_num_samples(mp3codec) + ' / ',
'Channels: '+Lame.get_num_channels(mp3codec) + ' / ',
'Input Samplate: '+ Lame.get_in_samplerate(mp3codec) + ' / ',
'Output Samplate: '+ Lame.get_in_samplerate(mp3codec) + ' / ',
'Bitlate :' +Lame.get_bitrate(mp3codec) + ' / ',
'VBR :' + Lame.get_VBR(mp3codec));
break;
case 'encode':
var mp3data = Lame.encode_buffer_ieee_float(mp3codec, e.data.buf, e.data.buf);
self.postMessage({cmd: 'data', buf: mp3data.data});
break;
case 'finish':
var mp3data = Lame.encode_flush(mp3codec);
self.postMessage({cmd: 'end', buf: mp3data.data});
Lame.close(mp3codec);
mp3codec = null;
break;
}
};

View File

@ -1,147 +0,0 @@
var recLength = 0,
recBuffers = [],
sampleRate,
numChannels;
this.onmessage = function(e){
switch(e.data.command){
case 'init':
init(e.data.config);
break;
case 'record':
record(e.data.buffer);
break;
case 'exportWAV':
exportWAV(e.data.type);
break;
case 'getBuffer':
getBuffer();
break;
case 'clear':
clear();
break;
}
};
function init(config){
sampleRate = config.sampleRate;
numChannels = config.numChannels;
initBuffers();
}
function record(inputBuffer){
for (var channel = 0; channel < numChannels; channel++){
recBuffers[channel].push(inputBuffer[channel]);
}
recLength += inputBuffer[0].length;
}
function exportWAV(type){
var buffers = [];
for (var channel = 0; channel < numChannels; channel++){
buffers.push(mergeBuffers(recBuffers[channel], recLength));
}
if (numChannels === 2){
var interleaved = interleave(buffers[0], buffers[1]);
} else {
var interleaved = buffers[0];
}
var dataview = encodeWAV(interleaved);
var audioBlob = new Blob([dataview], { type: type });
this.postMessage(audioBlob);
}
function getBuffer(){
var buffers = [];
for (var channel = 0; channel < numChannels; channel++){
buffers.push(mergeBuffers(recBuffers[channel], recLength));
}
this.postMessage(buffers);
}
function clear(){
recLength = 0;
recBuffers = [];
initBuffers();
}
function initBuffers(){
for (var channel = 0; channel < numChannels; channel++){
recBuffers[channel] = [];
}
}
function mergeBuffers(recBuffers, recLength){
var result = new Float32Array(recLength);
var offset = 0;
for (var i = 0; i < recBuffers.length; i++){
result.set(recBuffers[i], offset);
offset += recBuffers[i].length;
}
return result;
}
function interleave(inputL, inputR){
var length = inputL.length + inputR.length;
var result = new Float32Array(length);
var index = 0,
inputIndex = 0;
while (index < length){
result[index++] = inputL[inputIndex];
result[index++] = inputR[inputIndex];
inputIndex++;
}
return result;
}
function floatTo16BitPCM(output, offset, input){
for (var i = 0; i < input.length; i++, offset+=2){
var s = Math.max(-1, Math.min(1, input[i]));
output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);
}
}
function writeString(view, offset, string){
for (var i = 0; i < string.length; i++){
view.setUint8(offset + i, string.charCodeAt(i));
}
}
function encodeWAV(samples){
var buffer = new ArrayBuffer(44 + samples.length * 2);
var view = new DataView(buffer);
/* RIFF identifier */
writeString(view, 0, 'RIFF');
/* RIFF chunk length */
view.setUint32(4, 36 + samples.length * 2, true);
/* RIFF type */
writeString(view, 8, 'WAVE');
/* format chunk identifier */
writeString(view, 12, 'fmt ');
/* format chunk length */
view.setUint32(16, 16, true);
/* sample format (raw) */
view.setUint16(20, 1, true);
/* channel count */
view.setUint16(22, numChannels, true);
/* sample rate */
view.setUint32(24, sampleRate, true);
/* byte rate (sample rate * block align) */
view.setUint32(28, sampleRate * 4, true);
/* block align (channel count * bytes per sample) */
view.setUint16(32, numChannels * 2, true);
/* bits per sample */
view.setUint16(34, 16, true);
/* data chunk identifier */
writeString(view, 36, 'data');
/* data chunk length */
view.setUint32(40, samples.length * 2, true);
floatTo16BitPCM(view, 44, samples);
return view;
}

View File

@ -1,219 +0,0 @@
(function(window){
var WORKER_PATH = '/js/recorderWorker.js';
var encoderWorker = new Worker('/js/mp3Worker.js');
var Recorder = function(source, cfg){
var config = cfg || {};
var bufferLen = config.bufferLen || 4096;
var numChannels = config.numChannels || 2;
this.context = source.context;
this.node = (this.context.createScriptProcessor ||
this.context.createJavaScriptNode).call(this.context,
bufferLen, numChannels, numChannels);
var worker = new Worker(config.workerPath || WORKER_PATH);
worker.postMessage({
command: 'init',
config: {
sampleRate: this.context.sampleRate,
numChannels: numChannels
}
});
var recording = false,
currCallback;
this.node.onaudioprocess = function(e){
if (!recording) return;
var buffer = [];
for (var channel = 0; channel < numChannels; channel++){
buffer.push(e.inputBuffer.getChannelData(channel));
}
worker.postMessage({
command: 'record',
buffer: buffer
});
}
this.configure = function(cfg){
for (var prop in cfg){
if (cfg.hasOwnProperty(prop)){
config[prop] = cfg[prop];
}
}
}
this.record = function(){
recording = true;
}
this.stop = function(){
recording = false;
}
this.clear = function(){
worker.postMessage({ command: 'clear' });
}
this.getBuffer = function(cb) {
currCallback = cb || config.callback;
worker.postMessage({ command: 'getBuffer' })
}
this.exportWAV = function(cb, type){
currCallback = cb || config.callback;
type = type || config.type || 'audio/wav';
if (!currCallback) throw new Error('Callback not set');
worker.postMessage({
command: 'exportWAV',
type: type
});
}
//Mp3 conversion
worker.onmessage = function(e){
var blob = e.data;
//console.log("the blob " + blob + " " + blob.size + " " + blob.type);
var arrayBuffer;
var fileReader = new FileReader();
fileReader.onload = function(){
arrayBuffer = this.result;
var buffer = new Uint8Array(arrayBuffer),
data = parseWav(buffer);
console.log(data);
console.log("Converting to Mp3");
//log.innerHTML += "\n" + "Converting to Mp3";
encoderWorker.postMessage({ cmd: 'init', config:{
mode : 3,
channels:1,
samplerate: data.sampleRate,
bitrate: data.bitsPerSample
}});
encoderWorker.postMessage({ cmd: 'encode', buf: Uint8ArrayToFloat32Array(data.samples) });
encoderWorker.postMessage({ cmd: 'finish'});
encoderWorker.onmessage = function(e) {
if (e.data.cmd == 'data') {
console.log("Done converting to Mp3");
//log.innerHTML += "\n" + "Done converting to Mp3";
/*var audio = new Audio();
audio.src = 'data:audio/mp3;base64,'+encode64(e.data.buf);
audio.play();*/
//console.log ("The Mp3 data " + e.data.buf);
var mp3Blob = new Blob([new Uint8Array(e.data.buf)], {type: 'audio/mp3'});
uploadAudio(mp3Blob);
var url = 'data:audio/mp3;base64,'+encode64(e.data.buf);
var li = document.createElement('li');
var au = document.createElement('audio');
var hf = document.createElement('a');
au.controls = true;
au.src = url;
hf.href = url;
hf.download = 'audio_recording_' + new Date().getTime() + '.mp3';
hf.innerHTML = hf.download;
li.appendChild(au);
li.appendChild(hf);
recordingslist.appendChild(li);
}
};
};
fileReader.readAsArrayBuffer(blob);
currCallback(blob);
}
function encode64(buffer) {
var binary = '',
bytes = new Uint8Array( buffer ),
len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
}
return window.btoa( binary );
}
function parseWav(wav) {
function readInt(i, bytes) {
var ret = 0,
shft = 0;
while (bytes) {
ret += wav[i] << shft;
shft += 8;
i++;
bytes--;
}
return ret;
}
if (readInt(20, 2) != 1) throw 'Invalid compression code, not PCM';
if (readInt(22, 2) != 1) throw 'Invalid number of channels, not 1';
return {
sampleRate: readInt(24, 4),
bitsPerSample: readInt(34, 2),
samples: wav.subarray(44)
};
}
function Uint8ArrayToFloat32Array(u8a){
var f32Buffer = new Float32Array(u8a.length);
for (var i = 0; i < u8a.length; i++) {
var value = u8a[i<<1] + (u8a[(i<<1)+1]<<8);
if (value >= 0x8000) value |= ~0x7FFF;
f32Buffer[i] = value / 0x8000;
}
return f32Buffer;
}
function uploadAudio(mp3Data){
var reader = new FileReader();
reader.onload = function(event){
var fd = new FormData();
var mp3Name = encodeURIComponent('audio_recording_' + new Date().getTime() + '.mp3');
console.log("mp3name = " + mp3Name);
fd.append('fname', mp3Name);
fd.append('data', event.target.result);
$.ajax({
type: 'POST',
url: 'upload.php',
data: fd,
processData: false,
contentType: false
}).done(function(data) {
//console.log(data);
log.innerHTML += "\n" + data;
});
};
reader.readAsDataURL(mp3Data);
}
source.connect(this.node);
this.node.connect(this.context.destination); //this should not be necessary
};
/*Recorder.forceDownload = function(blob, filename){
console.log("Force download");
var url = (window.URL || window.webkitURL).createObjectURL(blob);
var link = window.document.createElement('a');
link.href = url;
link.download = filename || 'output.wav';
var click = document.createEvent("Event");
click.initEvent("click", true, true);
link.dispatchEvent(click);
}*/
window.Recorder = Recorder;
})(window);