Skip to content

Commit

Permalink
fix: back to URL.createObjectURL & URL.revokeObjectURL and skip frame…
Browse files Browse the repository at this point in the history
…s when not finished

Signed-off-by: Stefan Dej <[email protected]>
  • Loading branch information
meteyou committed Sep 5, 2024
1 parent 2d58b9f commit 51dcd75
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/components/webcams/streamers/Mjpegstreamer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ const SOI = new Uint8Array(2)
SOI[0] = 0xff
SOI[1] = 0xd8
function uint8ArrayToBase64(uint8Array: Uint8Array) {
let binary = ''
const len = uint8Array.byteLength
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(uint8Array[i])
}
return window.btoa(binary)
}
@Component
export default class Mjpegstreamer extends Mixins(BaseMixin, WebcamMixin) {
// current read stream frames counter
Expand Down Expand Up @@ -214,6 +205,7 @@ export default class Mjpegstreamer extends Mixins(BaseMixin, WebcamMixin) {
let contentLength = -1
let imageBuffer: Uint8Array = new Uint8Array(0)
let bytesRead = 0
let skipFrame = false
let done: boolean | null = null
let value
Expand Down Expand Up @@ -243,9 +235,16 @@ export default class Mjpegstreamer extends Mixins(BaseMixin, WebcamMixin) {
}
// we're done reading the jpeg. Time to render it.
if (this.image) {
this.image.src = 'data:image/jpeg;base64,' + uint8ArrayToBase64(imageBuffer)
}
if (this.image && !skipFrame) {
const objectURL = URL.createObjectURL(new Blob([imageBuffer], { type: 'image/jpeg' }))
this.image.src = objectURL
skipFrame = true
this.image.onload = () => {
URL.revokeObjectURL(objectURL)
skipFrame = false
}
} else this.log('Skipping frame')
this.frames++
contentLength = 0
bytesRead = 0
Expand Down

0 comments on commit 51dcd75

Please sign in to comment.