Skip to content

Using VideoDecoder for security camera app leads to codec reclaimation #889

Open
@dominic-p

Description

@dominic-p

As suggested in #121, I'm opening a new issue to discuss my use case.

I have just started using WebCodecs for a security camera application, and my VideoDecoders are getting reclaimed due to inactivity if the tab stays in the background for too long.

Use Case

The app is fairly simple, I spawn a single Worker which makes a WebSocket connection to the server. The server makes an RTSP connection to each of the configured cameras and then sends frames to the client through the WebSocket. The worker then uses VideoDecoders to draw the frames on canvases (essentially following this sample). It works really well until the I put the tab in the background. After a short while I get QuotaExceeded errors due to the "inactive" codecs being reclaimed.

I understand from these docs that the only way to keep an active VideoDecoder in the background from being reclaimed is to have an active VideoEncoder or an active AudioEncoder on the same global object. The problem for my use case is that these are security camera feeds that don't have audio (even if they did, I would only be decoding it).

You might ask what's the point of having a security camera app in a background tab? That's a good question. In common usage, you would expect to keep the app active all the time to view the video feeds. That said, in testing I have found that I often need to switch to another browser tab, and I imagine that will be the case at least some of the time in production.

Workarounds

Of course, there are a few workarounds I can implement. The simplest thing will be to watch for these errors and then attempt to restart the video streams when I run into them. The next idea is to run a dummy AudioEncoder of some kind in the Worker just to keep the VideoDecoders alive. But, it would be nice if there was a less hacky solution.

Solutions

I'm not sure what the best solution would be here. Maybe we can ask for user permission to run background video like we do for wake locks, location, etc.?

Also, it was suggested that I file a bug with Chromium since that's where I'm seeing this behavior. I'm happy to do that, but since the issue seems to be with the spec itself, I thought it would make sense to discuss it here first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions