Skip to content
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

Camera view updated to better respond to state #1437

Merged
merged 5 commits into from
Oct 6, 2024

Conversation

stephenjust
Copy link
Contributor

@stephenjust stephenjust commented Sep 28, 2024

In the previous camera view code, the frame didn't respond well to losses of connection, camera aspect ratio changes, etc.

Instead of changing the stream src, we can layer the camera view on top of the loading image, so that any time the camera signal is lost, even if it's because PhotonVision is restarting or you lose connection to the robot, the loading image is still in memory. This also fixes the responsiveness to connection loss.

This also only loads a stream if it is meant to be visible in the UI.

In the previous camera view code, the frame didn't respond well to
losses of connection, camera aspect ratio changes, etc.

Instead of changing the stream src, we can layer the camera view
on top of the loading image, so that any time the camera signal is lost,
even if it's because PhotonVision is restarting or you lose connection
to the robot, the loading image is still in memory. This also fixes the
responsiveness to connection loss.
@stephenjust stephenjust requested a review from a team as a code owner September 28, 2024 19:34
@mcm001
Copy link
Contributor

mcm001 commented Sep 28, 2024

Not blocking this PR: does this open the door to not trying to load both streams while looking only at one? Right now if you open devtools you can see both streams are being loaded even if only one is visible.

@stephenjust
Copy link
Contributor Author

Not blocking this PR: does this open the door to not trying to load both streams while looking only at one? Right now if you open devtools you can see both streams are being loaded even if only one is visible.

This PR as is doesn't solve that problem, but if it's something you want to solve, looks like a fairly simple change.

@stephenjust
Copy link
Contributor Author

Not blocking this PR: does this open the door to not trying to load both streams while looking only at one? Right now if you open devtools you can see both streams are being loaded even if only one is visible.

This PR as is doesn't solve that problem, but if it's something you want to solve, looks like a fairly simple change.

Latest commit fixes this.

@mcm001
Copy link
Contributor

mcm001 commented Sep 28, 2024

No way it was as simple as that, great stuff. I'm out this weekend but will try to draft someone else to try it out

@Alextopher
Copy link
Contributor

I can tonight ~5 hrs.

@Juniormunk
Copy link
Contributor

Juniormunk commented Sep 29, 2024

Looks good to me!

@mcm001
Copy link
Contributor

mcm001 commented Sep 29, 2024

Put your name on the approval button then :)

@@ -81,10 +81,10 @@ const performanceRecommendation = computed<string>(() => {
</v-row>
<v-divider style="border-color: white" />
<v-row class="stream-viewer-container pa-3">
<v-col v-show="value.includes(0)" class="stream-view">
Copy link
Member

@srimanachanta srimanachanta Sep 29, 2024

Choose a reason for hiding this comment

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

This should be v-show due to often dynamic rendering. Doing v-if adds more overhead and is incorrect for our use case. Image content can be lazy loaded based on if it is rendered though to avoid the double loading issue.

Copy link
Member

@srimanachanta srimanachanta Sep 29, 2024

Choose a reason for hiding this comment

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

Maybe use intersection API within photon-camera-stream itself and stop frame request cycle if notInView && backendConnected

Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion v-if seems fine given it just cleanly fixes the double load problem.

Alextopher added a commit that referenced this pull request Sep 29, 2024
This space is the root cause of failures in #1437
@Alextopher Alextopher mentioned this pull request Sep 29, 2024
@Alextopher
Copy link
Contributor

--- a/photon-client/src/components/app/photon-camera-stream.vue
+++ b/photon-client/src/components/app/photon-camera-stream.vue
@@ -1,5 +1,5 @@
 <script setup lang="ts">
-import { computed, inject, ref, onBeforeUnmount } from "vue";
+import { computed, inject, ref, onBeforeUnmount, watchEffect } from "vue";
 import { useCameraSettingsStore } from "@/stores/settings/CameraSettingsStore";
 import { useStateStore } from "@/stores/StateStore";
 import loadingImage from "@/assets/images/loading.svg";
@@ -73,6 +73,20 @@ onBeforeUnmount(() => {
   if (!mjpgStream.value) return;
   mjpgStream.value["src"] = emptyStreamSrc;
 });
+
+watchEffect((onCleanup) => {
+  if (!mjpgStream.value) return;
+
+  const observer = new IntersectionObserver(([entry]) => {
+    mjpgStream.value.src = entry.isIntersecting ? streamSrc.value : emptyStreamSrc;
+  });
+
+  observer.observe(mjpgStream.value);
+
+  onCleanup(() => {
+    observer.disconnect();
+  });
+});
 </script>
 
 <template>
--- a/photon-client/src/components/dashboard/CamerasCard.vue
+++ b/photon-client/src/components/dashboard/CamerasCard.vue
@@ -81,10 +81,10 @@ const performanceRecommendation = computed<string>(() => {
     </v-row>
     <v-divider style="border-color: white" />
     <v-row class="stream-viewer-container pa-3">
-      <v-col v-if="value.includes(0)" class="stream-view">
+      <v-col v-show="value.includes(0)" class="stream-view">
         <photon-camera-stream id="input-camera-stream" stream-type="Raw" style="width: 100%; height: auto" />
       </v-col>
-      <v-col v-if="value.includes(1)" class="stream-view">
+      <v-col v-show="value.includes(1)" class="stream-view">
         <photon-camera-stream id="output-camera-stream" stream-type="Processed" style="width: 100%; height: auto" />
       </v-col>
     </v-row>

@Alextopher
Copy link
Contributor

@stephenjust is this what you had in mind?

Copy link
Contributor

@Alextopher Alextopher left a comment

Choose a reason for hiding this comment

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

I'm happy with or without observability!

gerth2 pushed a commit that referenced this pull request Sep 29, 2024
This space is the root cause of failures in #1437.

RE: #1430
@stephenjust
Copy link
Contributor Author

@stephenjust is this what you had in mind?

Those diffs above do not fix the unnecessary stream loading, because the image is still in the DOM with a valid src value when you use v-show.

@GrahamSH-LLK
Copy link

GrahamSH-LLK commented Oct 5, 2024

@stephenjust is this what you had in mind?

Those diffs above do not fix the unnecessary stream loading, because the image is still in the DOM with a valid src value when you use v-show.

Browsers don't load images with display: none. https://web.dev/articles/browser-level-image-lazy-loading#carousel

@stephenjust
Copy link
Contributor Author

@stephenjust is this what you had in mind?

Those diffs above do not fix the unnecessary stream loading, because the image is still in the DOM with a valid src value when you use v-show.

Browsers don't load images with display: none. https://web.dev/articles/browser-level-image-lazy-loading#carousel

This may be true, but given that these images are mjpg streams, once they start loading, they keep loading until they are removed from the DOM or the image src is changed. So if I use v-show, when I show the second stream it will continue to load the stream even once it's hidden again. Using v-if forces it to be removed from the DOM so the browser knows it can stop loading new frames.

@mcm001
Copy link
Contributor

mcm001 commented Oct 6, 2024

So should we ship this? I'm good with it, just haven't tested yet

@mcm001 mcm001 merged commit cd9dd07 into PhotonVision:master Oct 6, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants