First draft fixing GPU preview toggling

This commit is contained in:
Joel Collins 2020-05-14 15:31:19 +01:00
parent 9f55085f20
commit 9623deece0
3 changed files with 49 additions and 19 deletions

View file

@ -374,7 +374,6 @@ export default {
this.$store.commit("changeSetting", ["trackWindow", state]); this.$store.commit("changeSetting", ["trackWindow", state]);
this.$store.commit("changeSetting", ["disableStream", state]); this.$store.commit("changeSetting", ["disableStream", state]);
this.$store.commit("changeSetting", ["autoGpuPreview", state]); this.$store.commit("changeSetting", ["autoGpuPreview", state]);
//this.$root.$emit('globalTogglePreview', state)
}, },
delSavedHost: function(host) { delSavedHost: function(host) {

View file

@ -5,7 +5,7 @@
class="stream-display uk-width-1-1 uk-height-1-1 scrollTarget" class="stream-display uk-width-1-1 uk-height-1-1 scrollTarget"
> >
<img <img
v-if="streamVisible" v-if="thisStreamOpen"
ref="click-frame" ref="click-frame"
class="uk-align-center uk-margin-remove-bottom" class="uk-align-center uk-margin-remove-bottom"
:hidden="!streamEnabled" :hidden="!streamEnabled"
@ -45,7 +45,6 @@ export default {
displaySize: [0, 0], displaySize: [0, 0],
displayPosition: [0, 0], displayPosition: [0, 0],
fov: [0, 0], fov: [0, 0],
GpuPreviewActive: false,
resizeTimeoutId: setTimeout(this.doneResizing, 500) resizeTimeoutId: setTimeout(this.doneResizing, 500)
}; };
}, },
@ -57,7 +56,7 @@ export default {
!this.$store.state.globalSettings.disableStream !this.$store.state.globalSettings.disableStream
); );
}, },
streamVisible: function() { thisStreamOpen: function() {
// Only a single MJPEG connection should be open at a time // Only a single MJPEG connection should be open at a time
return !(this.displaySize[0] == 0) && !(this.displaySize[1] == 0); return !(this.displaySize[0] == 0) && !(this.displaySize[1] == 0);
}, },
@ -76,9 +75,9 @@ export default {
}, },
mounted() { mounted() {
console.log(`${this._uid} mounted`);
// A global signal listener to change the GPU preview state // A global signal listener to change the GPU preview state
this.$root.$on("globalTogglePreview", state => { this.$root.$on("globalTogglePreview", state => {
console.log(`Toggling preview to ${state}`);
this.previewRequest(state); this.previewRequest(state);
}); });
// A global signal listener to flash the stream element // A global signal listener to flash the stream element
@ -97,6 +96,7 @@ export default {
}, },
created: function() { created: function() {
console.log(`${this._uid} created`);
// Send a request to start/stop GPU preview based on global setting // Send a request to start/stop GPU preview based on global setting
this.previewRequest(this.$store.state.globalSettings.autoGpuPreview); this.previewRequest(this.$store.state.globalSettings.autoGpuPreview);
// Get FOV from settings // Get FOV from settings
@ -104,12 +104,15 @@ export default {
}, },
beforeDestroy: function() { beforeDestroy: function() {
console.log(`${this._uid} being destroyed`);
// Remove global signal listener to change the GPU preview state // Remove global signal listener to change the GPU preview state
this.$root.$off("globalTogglePreview"); this.$root.$off("globalTogglePreview");
// Remove global signal listener to flash the stream element // Remove global signal listener to flash the stream element
this.$root.$off("globalFlashStream"); this.$root.$off("globalFlashStream");
// Disconnect the size observer // Disconnect the size observer
this.sizeObserver.disconnect(); this.sizeObserver.disconnect();
// Remove from the array of active streams
this.$store.commit("removeStream", this._uid);
}, },
methods: { methods: {
@ -151,18 +154,36 @@ export default {
handleDoneResize: function() { handleDoneResize: function() {
// Recalculate size // Recalculate size
console.log("Recalculating frame size"); console.log(`Recalculating frame size for ${this._uid}`);
this.recalculateSize(); this.recalculateSize();
if ( // Handle closed stream
this.$store.state.globalSettings.autoGpuPreview == true && if (this.displaySize[0] == 0 && this.displaySize[1] == 0) {
this.GpuPreviewActive == true console.log(`${this._uid} is zero`);
) { // If this stream was previously active
// Reload preview if (this.$store.state.activeStreams[this._uid] == true) {
this.$root.$emit("globalTogglePreview", true); console.log(`${this._uid} was active`);
console.log(`STREAM ${this._uid} CLOSED`);
this.$store.commit("removeStream", this._uid);
// If all streams are closed, request the GPU preview close
var a = Object.values(this.$store.state.activeStreams);
let allClosed = a.every(v => v === false);
if (allClosed) {
this.previewRequest(false);
}
}
// If resized to anything other than zero
} else {
console.log(`STREAM ${this._uid} OPEN`);
this.$store.commit("addStream", this._uid);
if (this.$store.state.globalSettings.autoGpuPreview == true) {
// Reload preview
this.previewRequest(true);
}
} }
}, },
recalculateSize: function() { recalculateSize: function() {
// Calculate stream size
let element = this.$refs.streamDisplay.parentNode; let element = this.$refs.streamDisplay.parentNode;
let bound = element.getBoundingClientRect(); let bound = element.getBoundingClientRect();
@ -183,20 +204,22 @@ export default {
this.displaySize = elementSize; this.displaySize = elementSize;
this.displayPosition = elementPositionOnDisplay; this.displayPosition = elementPositionOnDisplay;
console.log(`Size: ${this.displaySize}`);
console.log(`Position: ${this.displayPosition}`);
}, },
previewRequest: function(state) { previewRequest: function(state) {
// If all streams are closed, don't start GPU preview
var a = Object.values(this.$store.state.activeStreams);
let allClosed = a.every(v => v === false);
if (state === true && allClosed) {
return false;
}
// If requesting starting the stream, but this component is inactive, skip
if (this.$store.getters.ready == true) { if (this.$store.getters.ready == true) {
var requestUri = null; var requestUri = null;
// Create URI and set this.GpuPreviewActive depending on if starting or stopping preview // Create URI
if (state == true) { if (state == true) {
this.GpuPreviewActive = true;
requestUri = this.startPreviewUri; requestUri = this.startPreviewUri;
} else { } else {
this.GpuPreviewActive = false;
requestUri = this.stopPreviewUri; requestUri = this.stopPreviewUri;
} }
@ -220,6 +243,7 @@ export default {
} }
// Send preview request // Send preview request
console.log(`${this._uid} toggled preview to ${state}`);
axios axios
.post(requestUri, payload) .post(requestUri, payload)
.then(() => {}) .then(() => {})

View file

@ -15,7 +15,8 @@ export default new Vuex.Store({
autoGpuPreview: false, autoGpuPreview: false,
trackWindow: true, trackWindow: true,
appTheme: "system" appTheme: "system"
} },
activeStreams: {}
}, },
mutations: { mutations: {
@ -41,6 +42,12 @@ export default new Vuex.Store({
setError(state, msg) { setError(state, msg) {
state.waiting = false; state.waiting = false;
state.error = msg; state.error = msg;
},
addStream(state, id) {
state.activeStreams[id] = true;
},
removeStream(state, id) {
state.activeStreams[id] = false;
} }
}, },