Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use a shared cache between different VideoBackground instances
Before the cache for blurred video backgrounds was local to each
VideoBackground instance. During a call different VideoBackground
instances can be mounted and destroyed for the same participant (for
example, when switching between speaker mode and grid view, or when a
promoted speaker changes), so the cache was lost and the blurred
background had to be recalculated every time that happened.

Now the cache is global and shared between VideoBackground instances,
so previously cached backgrounds can be used by new VideoBackground
instances.

The global cache is lazily initialized when needed and cleared each time
a call ends.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Jan 5, 2021
commit 208b820e67e90e1f60e2bd02f00a5e2a0c8347a4
14 changes: 11 additions & 3 deletions src/components/CallView/shared/VideoBackground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ import { getBuilder } from '@nextcloud/browser-storage'
import browserCheck from '../../../mixins/browserCheck'
import blur from '../../../utils/imageBlurrer'

const LRU = require('lru-cache')

const browserStorage = getBuilder('nextcloud').persist().build()

// note: this info is shared with the Avatar component
Expand Down Expand Up @@ -99,7 +97,6 @@ export default {
useCssBlurFilter: true,
blur: 0,
blurredBackgroundImage: null,
blurredBackgroundImageCache: new LRU({ max: 5 }),
blurredBackgroundImageSource: null,
pendingGenerateBlurredBackgroundImageCount: 0,
isDestroyed: false,
Expand Down Expand Up @@ -152,6 +149,17 @@ export default {

return this.backgroundBlur
},
blurredBackgroundImageCache() {
if (!this.user) {
return null
}

if (!this.$store.getters.getBlurredBackgroundImageCache(this.user)) {
this.$store.dispatch('initializeBlurredBackgroundImageCache', this.user)
}

return this.$store.getters.getBlurredBackgroundImageCache(this.user)
},
},

watch: {
Expand Down
20 changes: 20 additions & 0 deletions src/store/callViewStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
CONVERSATION,
} from '../constants'

const LRU = require('lru-cache')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normally we use import? not require?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library does not support import, only require 🤷


const state = {
isGrid: false,
isStripeOpen: true,
Expand All @@ -35,6 +37,7 @@ const state = {
selectedVideoPeerId: null,
videoBackgroundBlur: 1,
participantRaisedHands: {},
blurredBackgroundImageCache: {},
}

const getters = {
Expand All @@ -54,6 +57,7 @@ const getters = {
return (width * height * state.videoBackgroundBlur) / 1000
},
isParticipantRaisedHand: (state) => (peerId) => !!state.participantRaisedHands[peerId],
getBlurredBackgroundImageCache: (state) => (videoBackgroundId) => state.blurredBackgroundImageCache[videoBackgroundId],
}

const mutations = {
Expand Down Expand Up @@ -86,6 +90,16 @@ const mutations = {
clearParticipantHandRaised(state) {
state.participantRaisedHands = {}
},
initializeBlurredBackgroundImageCache(state, videoBackgroundId) {
if (state.blurredBackgroundImageCache[videoBackgroundId]) {
return
}

Vue.set(state.blurredBackgroundImageCache, videoBackgroundId, new LRU({ max: 10 }))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what happens in a call with 12 users and they speak all one sentence after another, it will have to calculate again and again?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, each participant has (or should :-P ) its own cache; 10 is the number of backgrounds for each participant (as the blurred backgrounds are different depending on the size of the video background).

},
clearBlurredBackgroundImageCache(state) {
state.blurredBackgroundImageCache = {}
},
}

const actions = {
Expand Down Expand Up @@ -116,6 +130,8 @@ const actions = {
leaveCall(context) {
// clear raised hands as they were specific to the call
context.commit('clearParticipantHandRaised')

context.commit('clearBlurredBackgroundImageCache')
},

/**
Expand Down Expand Up @@ -197,6 +213,10 @@ const actions = {
})
context.commit('presentationStarted', false)
},

initializeBlurredBackgroundImageCache(context, videoBackgroundId) {
context.commit('initializeBlurredBackgroundImageCache', videoBackgroundId)
},
}

export default { state, mutations, getters, actions }