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

🐞 - VRCDN preview tile stealing RAM even when not playing #45

Closed
M1XZG opened this issue Nov 29, 2024 · 6 comments
Closed

🐞 - VRCDN preview tile stealing RAM even when not playing #45

M1XZG opened this issue Nov 29, 2024 · 6 comments
Assignees
Labels
Blocks Specific to blocks bug Something isn't working
Milestone

Comments

@M1XZG
Copy link

M1XZG commented Nov 29, 2024

Doras Username

wildwanderer_vr

What happened?

On my profile page I have my VRCDN live stream preview setup. This doesn't autoplay so one would assume it's doing nothing, but after couple of hours I notice that in chrome the tab is consuming a huge amount of RAM.

Image

Here you can watch it increase in size in real time

2024-11-29_14-15-27.mp4

Replication Steps

Nothing, just have VRCDN loaded in the profile as a tile.

User or Brand related

My acconut

What browsers are you seeing the problem on?

Chrome (or chrome based like Brave, Arc, etc)

@M1XZG M1XZG added the bug Something isn't working label Nov 29, 2024
@doras-to-admin
Copy link

Thank you for making Doras a better place 🚀

This has been added to our Public Project Board and our team will triage and action accordingly.

@tommerty tommerty added the Blocks Specific to blocks label Nov 29, 2024
@tommerty
Copy link
Contributor

The embeds source code on our end:

<video controls>
  <source
    src={`https://stream.vrcdn.live/live/${blockUpdate.url}.live.mp4`}
    type="video/mp4"
    />
</video>

Where ${blockUpdate.url} is the input of the VRCDN Username

The recommendation from @jazzy348 sent over from @M1XZG was:

<video autoplay muted>
  <source src="https://stream.vrcdn.live/live/${streamName}.mp4" type="video/mp4"/>
</video>

@jazzy348
Copy link

What's most likely happening here is the video embed is writing the recevied stream data to the buffer rather then discarding it after showing it.

@tommerty
Copy link
Contributor

Seems we need to implement some buffer management. After a very brief search, something like HLS.js can help.

Example:

const hls = new Hls({
  maxBufferSize: 0, // Prevent storing large amounts of data
  maxBufferLength: 1, // Keep only 1 second of forward buffer
  backBufferLength: 0, // Don't store any previous segments
  liveSyncDurationCount: 1, // Sync with only 1 segment of live stream
  enableWorker: false // Disable web worker to reduce memory usage
});

// Attach to video element
hls.loadSource(streamUrl);
hls.attachMedia(video);

// Force garbage collection of old segments
hls.on(Hls.Events.FRAG_LOADED, () => {
  hls.trigger(Hls.Events.BUFFER_FLUSHING);
});

@trent-001

@tommerty tommerty added this to the v0.3.4 milestone Dec 27, 2024
@tommerty tommerty moved this from Triage to Todo in Doras Public Roadmap Dec 27, 2024
@tommerty
Copy link
Contributor

tommerty commented Dec 30, 2024

Think I have a solution with VideoJS:

    const videoRef = React.useRef<HTMLVideoElement>(null);
    const playerRef = React.useRef<any>(null);

    React.useEffect(() => {
        // Wait for next tick to ensure DOM is ready
        const timer = setTimeout(() => {
            const videoElement = videoRef.current;
            if (!videoElement || !blockUpdate.url) return;

            const player = videojs(videoElement, {
                controls: true,
                fluid: true,
                preload: "none",
                liveui: true,
                liveTracker: false,
                controlBar: {
                    progressControl: false,
                },
                html5: {
                    nativeVideoTracks: true,
                    nativeAudioTracks: true,
                    nativeTextTracks: true,
                    vhs: {
                        overrideNative: true,
                        bufferSize: 1, // Minimal buffer size
                        maxBufferLength: 1, // Only buffer 1 second
                        // Add periodic buffer cleanup
                        cleanupBuffer: true,
                        cleanupBufferInterval: 30, // seconds
                    },
                },
            });

            playerRef.current = player;
        }, 0);

        return () => {
            clearTimeout(timer);
            if (playerRef.current) {
                playerRef.current.reset();
                playerRef.current.dispose();
                playerRef.current = null;
            }
        };
    }, [blockUpdate.url]);

...

<div data-vjs-player className="h-full w-full ">
<video
  ref={videoRef}
  className="video-js vjs-live vjs-live-display h-full w-full"
  playsInline
>
   <source
      src={`https://stream.vrcdn.live/live/${blockUpdate.url}.live.mp4`}
      type="video/mp4"
   />
</video>
</div>

Yes the code is ass, yes it could likely be better, but to get to this point took a good few hours of trying to understand VideoJS 😅

@tommerty tommerty self-assigned this Dec 30, 2024
@tommerty tommerty moved this from Todo to In reivew in Doras Public Roadmap Jan 4, 2025
@tommerty tommerty moved this from In reivew to Done in Doras Public Roadmap Jan 4, 2025
@tommerty tommerty closed this as completed by moving to Done in Doras Public Roadmap Jan 4, 2025
@tommerty
Copy link
Contributor

tommerty commented Jan 4, 2025

Merged into staging and will release with Doras v.0.3.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocks Specific to blocks bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

4 participants