Compare commits

...
Author SHA1 Message Date
Rejdukien 822a622d97 Change from websockets to regular pull-based approach 2021-02-14 19:45:46 +01:00
Rejdukien 1e7aba5297 PyImageStreamer websocket support 2021-02-14 17:41:26 +01:00
4 changed files with 111 additions and 11 deletions

No files matched your search

+1
View File
@@ -17,6 +17,7 @@
"vue-context": "^6.0.0",
"vue-github-api": "^0.1.7",
"vue-headful": "^2.1.0",
"vue-observe-visibility": "^1.0.0",
"vue-plotly": "^1.1.0",
"vue-prism-editor": "^1.2.2",
"vue-resource": "^1.5.1",
@@ -43,6 +43,16 @@
<v-switch v-model="boolNavi" hide-details label="Show in navigation" class="mt-0"></v-switch>
</v-col>
</v-row>
<v-row>
<v-col class="py-2">
<v-switch v-model="adaptiveFps" hide-details label="(Experimental) Adaptive FPS" class="mt-0"></v-switch>
</v-col>
</v-row>
<v-row v-if="adaptiveFps">
<v-col class="py-2">
<v-text-field v-model="targetFps" hide-details label="Target FPS" class="mt-0"></v-text-field>
</v-col>
</v-row>
</v-container>
</v-card-text>
</v-card>
@@ -64,6 +74,8 @@
return this.$store.state.gui.webcam.url;
},
set(url) {
if(this.$store.state.gui.webcam.adaptiveFps)
url = url.replace("action=stream", "action=snapshot");
return this.$store.dispatch('gui/setSettings', { webcam: { url } });
}
},
@@ -107,6 +119,22 @@
return this.$store.dispatch('gui/setSettings', { webcam: { bool: showNav } });
}
},
adaptiveFps: {
get() {
return this.$store.state.gui.webcam.adaptiveFps;
},
set(useAdaptiveFps) {
return this.$store.dispatch('gui/setSettings', { webcam: { adaptiveFps: useAdaptiveFps } });
}
},
targetFps: {
get() {
return this.$store.state.gui.webcam.targetFps;
},
set(fps) {
return this.$store.dispatch('gui/setSettings', { webcam: { targetFps: fps } });
}
}
},
methods: {
+80 -11
View File
@@ -5,14 +5,14 @@
</style>
<template>
<v-card>
<v-card v-observe-visibility="visibilityChanged">
<v-toolbar flat dense >
<v-toolbar-title>
<span class="subheading"><v-icon left>mdi-webcam</v-icon>Webcam</span>
<span class="subheading"><v-icon left>mdi-webcam</v-icon>{{subHeading}}</span>
</v-toolbar-title>
</v-toolbar>
<v-card-text class="px-0 py-0 content">
<img :src="url" class="webcamImage" :style="webcamStyle" alt="Webcam"/>
<img :src="url" class="webcamImage" :style="webcamStyle" @load="onLoad" alt="Webcam"/>
</v-card-text>
</v-card>
</template>
@@ -23,12 +23,27 @@
export default {
data: function() {
return {
refresh: Math.ceil(Math.random() * Math.pow(10, 12))
}
refresh: Math.ceil(Math.random() * Math.pow(10, 12)),
connection: "",
imageData: "",
request_start_time: performance.now(),
start_time: performance.now(),
time: 0,
request_time: 0,
time_smoothing: 0.6,
request_time_smoothing: 0.1,
isVisible: true,
};
},
created: function () {
document.addEventListener("focus", () => this.handleRefreshChange(), false);
document.addEventListener("visibilitychange", this.handleRefreshChange, false);
if(this.webcamConfig.adaptiveFps) {
this.requestMjpeg();
}
},
components: {
@@ -37,14 +52,28 @@
...mapState({
'webcamConfig': state => state.gui.webcam
}),
url() {
let basicUrl = this.webcamConfig.url
if (basicUrl && basicUrl.indexOf("?") === -1) basicUrl += "?"
const params = new URLSearchParams(basicUrl)
params.set('bypassCache', ""+this.refresh)
return decodeURIComponent(params.toString())
subHeading() {
return "Webcam" + (this.webcamConfig.adaptiveFps ? " - FPS: " + Math.round(1000 / this.time) : "");
},
url() {
if(!this.webcamConfig.adaptiveFps) {
let basicUrl = this.webcamConfig.url
if (basicUrl && basicUrl.indexOf("?") === -1) basicUrl += "?"
const params = new URLSearchParams(basicUrl)
params.set('bypassCache', ""+this.refresh)
return decodeURIComponent(params.toString())
} else {
return this.imageData;
/*return 'data:image/jpeg;base64,' + btoa(
new Uint8Array(this.blobData)
.reduce((data, byte) => data.String.fromCharCode(byte), '')
)*/
}
},
webcamStyle() {
let transforms = '';
if (this.webcamConfig.flipX) {
@@ -69,6 +98,46 @@
if (!document.hidden) {
this.refresh = Math.ceil(Math.random() * Math.pow(10, 12))
}
},
onLoad() {
var end_time = performance.now();
var current_time = end_time - this.start_time;
this.time = (this.time * this.time_smoothing) + (current_time * (1.0 - this.time_smoothing));
this.start_time = end_time;
var target_time = 1000/this.webcamConfig.targetFps
var current_request_time = performance.now() - this.request_start_time;
this.request_time = (this.request_time * this.request_time_smoothing) + (current_request_time * (1.0 - this.request_time_smoothing));
var timeout = Math.max(0, target_time - this.request_time);
this.$nextTick(() => {
console.log(end_time + " " + timeout);
setTimeout(this.requestMjpeg, timeout);
})
},
requestMjpeg() {
if(!this.isVisible)
return;
this.request_start_time = performance.now();
let basicUrl = this.webcamConfig.url
if (basicUrl && basicUrl.indexOf("?") === -1) basicUrl += "?"
const params = new URLSearchParams(basicUrl)
params.set('bypassCache', ""+ this.refresh + (Math.random() * 1000))
this.$nextTick(() => {
this.imageData = decodeURIComponent(params.toString())
})
},
visibilityChanged(isVisible, entry) {
this.isVisible = isVisible;
console.log(entry);
if(isVisible)
this.requestMjpeg();
}
}
}
+2
View File
@@ -7,10 +7,12 @@ import './components'
import store from './store'
import router from './plugins/router'
import vueHeadful from 'vue-headful';
import VueObserveVisibility from 'vue-observe-visibility';
Vue.config.productionTip = false;
Vue.use(VueResource);
Vue.use(VueObserveVisibility);
Vue.http.headers.common['Content-Type'] = 'application/json';
Vue.http.headers.common['Access-Control-Allow-Origin'] = '*';
Vue.http.headers.common['Accept'] = 'application/json, text/plain, */*';