Skip to content

fix(Cameras): always emit frame event #1621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 1 addition & 22 deletions src/components/widgets/camera/CameraItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@update:camera-name-menu-items="cameraNameMenuItems = $event"
@update:raw-camera-url="rawCameraUrl = $event"
@update:frames-per-second="framesPerSecond = $event"
@frame="$emit('frame', $event)"
/>
</template>
<div v-else>
Expand Down Expand Up @@ -138,28 +139,6 @@ export default class CameraItem extends Vue {
cameraName = ''
cameraNameMenuItems: CameraNameMenuItem[] = []

@Watch('status')
onStatus (value: CameraConnectionStatus) {
if (value === 'connected' && this.$listeners?.frame && this.componentInstance) {
if (this.componentInstance.streamingElement instanceof HTMLImageElement) {
this.handleFrame()
} else if (this.componentInstance.streamingElement instanceof HTMLVideoElement) {
this.handleFrame(true)
}
}
}

handleFrame (animate = false) {
const element = this.componentInstance?.streamingElement as HTMLImageElement | HTMLVideoElement
if (element) {
this.$emit('frame', element)
}

if (animate) {
requestAnimationFrame(() => this.handleFrame(this.componentInstance?.animating ?? false))
}
}

cameraNameMenuItemClick (item: CameraNameMenuItem) {
this.componentInstance.menuItemClick(item)
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/widgets/camera/services/IpstreamCamera.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default class IpstreamCamera extends Mixins(CameraMixin) {

cameraVideoSource = ''

get autoRaiseFrameEvent () {
return false
}

startPlayback () {
try {
this.updateStatus('connecting')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ export default class MjpegstreamerAdaptiveCamera extends Mixins(CameraMixin) {
timeSmoothing = 0.6
requestTimeSmoothing = 0.1

get autoRaiseFrameEvent () {
return false
}

handleImageLoad () {
this.updateStatus('connected')
this.$emit('frame')
this.$emit('frame', this.streamingElement)

const fpsTarget = (!document.hasFocus() && this.camera.target_fps_idle) || this.camera.target_fps || 10
const endTime = performance.now()
Expand Down
8 changes: 8 additions & 0 deletions src/mixins/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export default class CameraMixin extends Vue {
}
}

get autoRaiseFrameEvent () {
return true
}

createTransform (): string {
const element = this.streamingElement
const { rotation, flip_horizontal, flip_vertical } = this.camera
Expand Down Expand Up @@ -80,6 +84,10 @@ export default class CameraMixin extends Vue {

if (this.streamingElement) {
this.cameraTransformStyle = this.createTransform()

if (this.autoRaiseFrameEvent) {
this.$emit('frame', this.streamingElement)
}
}

this.updateCameraTransformStyle()
Expand Down