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

cefsrc: fix CefInitialize crashing the second time #90

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

MathieuDuponchelle
Copy link
Collaborator

Calling CefInitialize multiple times during a process lifetime is not supported:

Prior to #83 we used to have a ShutdownEnforcer class, but as it was causing issues on OSX we will simply no longer shut down CEF at all.

We can revisit if needed, but this is preferable to crashing.

See #88 (comment) and below

Calling CefInitialize multiple times during a process lifetime is not
supported:

* https://magpcss.org/ceforum/viewtopic.php?f=6&t=16430
* https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=466
* https://stackoverflow.com/questions/73172139/cef-can-only-be-initialized-once-per-process-this-is-a-limitation-of-the-underl

Prior to #83 we used to have a ShutdownEnforcer class, but as it
was causing issues on OSX we will simply no longer shut down CEF at
all.

We can revisit if needed, but this is preferable to crashing.

See #88 (comment)
and below
@MathieuDuponchelle
Copy link
Collaborator Author

cc @aiden-jeffrey :)

@aiden-jeffrey
Copy link
Contributor

aiden-jeffrey commented Oct 4, 2024

Moving comment from other PR:

Multiple pipelines just aren't really supported the way this element is currently written. If you run two cefsrc elements at the same time (without calling CefShutdown), Initialize never gets acalled, which means that the second cefsrc just has the properties of the first.

@aiden-jeffrey
Copy link
Contributor

To be clearer - OnBeforeCommandLineProcessing doesn't get called - which is what maps many (or all, not checked) of the gst properties into cef land.

@MathieuDuponchelle
Copy link
Collaborator Author

Oh, OnBeforeCommandLineProcessing is only called once too ok, annoying. I suppose all affected properties should be turned into environment variables instead, to make it clearer that they are per process.

@aiden-jeffrey
Copy link
Contributor

I suppose all affected properties should be turned into environment variables instead, to make it clearer that they are per process.

I'm happy to take that PR if you need.

Copy link
Contributor

@aiden-jeffrey aiden-jeffrey left a comment

Choose a reason for hiding this comment

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

This LGTM from my perspective and specific issue.

@MathieuDuponchelle
Copy link
Collaborator Author

I'm happy to take that PR if you need.

That'd be nice yes, by the way the idea would be to simply deprecate the properties, so if they're set and the environment variable is not the property value should still be used :)

@amyspark
Copy link
Collaborator

amyspark commented Oct 4, 2024

@MathieuDuponchelle Some lingering questions now that I've caught up on this:

  • are there any global properties that can be changed between CEF "initializations"?
  • I think that there was an event in Gst land that was triggered on loop exit, on which we hook the CefShutdown task. How are pipelines being created after the loop's exited?

I think the issue here is CefShutdown is getting called, which according to the header should only be called on application exit. I've removed that, but now can't get the MakeBrowser CefTask to run in the second pipeline.

If the app's marked as "to be shut down", then the element will not respond to the second pipeline, which leads me to item (2) above.

@aiden-jeffrey
Copy link
Contributor

Just noticing now, but when you have multiple pipelines, it looks like the first frame on subsequent runs has some data left over in the buffer from the previous instance.

@aiden-jeffrey
Copy link
Contributor

I'm happy to take that PR if you need.

#91

@amyspark
Copy link
Collaborator

amyspark commented Oct 4, 2024

@aiden-jeffrey Hi, one question. In which operating system are you experiencing the crash? I've looked in the comments across the PRs but can't find the specifics on how to reproduce the issue you've been facing.

@aiden-jeffrey
Copy link
Contributor

@aiden-jeffrey Hi, one question. In which operating system are you experiencing the crash? I've looked in the comments across the PRs but can't find the specifics on how to reproduce the issue you've been facing.

Ubuntu 24.04.

@MathieuDuponchelle
Copy link
Collaborator Author

@amyspark yes unfortunately, many of the properties only matter at CefInitialize time, which is why we'll be moving to environment variables in #91 . Even if initialize / shutdown / initialize again worked, the problem still existed for concurrent instances anyway.

@amyspark
Copy link
Collaborator

amyspark commented Oct 8, 2024

@MathieuDuponchelle All good. Maybe we should report these upstream (Google), it's clear that the engine as-is does not have a clean lifecycle.

@aiden-jeffrey
Copy link
Contributor

@MathieuDuponchelle All good. Maybe we should report these upstream (Google), it's clear that the engine as-is does not have a clean lifecycle.

It's part of CEF's architecture that just one CefInitialize and one CefShutdown is allowed.

https://magpcss.org/ceforum/viewtopic.php?t=14648
https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=19421
https://magpcss.org/ceforum/viewtopic.php?f=6&t=19158

I think the only way to support multiple CEF instances would be by re-writing cefbin to use something like https://gstreamer.freedesktop.org/documentation/ipcpipeline/index.html?gi-language=c.

@MathieuDuponchelle
Copy link
Collaborator Author

@MathieuDuponchelle All good. Maybe we should report these upstream (Google), it's clear that the engine as-is does not have a clean lifecycle.

It's part of CEF's architecture that just one CefInitialize and one CefShutdown is allowed.

https://magpcss.org/ceforum/viewtopic.php?t=14648 https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=19421 https://magpcss.org/ceforum/viewtopic.php?f=6&t=19158

I think the only way to support multiple CEF instances would be by re-writing cefbin to use something like https://gstreamer.freedesktop.org/documentation/ipcpipeline/index.html?gi-language=c.

Realistically, this would be up to the application that needs multiple instances to spawn one process per cefsrc and use some ipc mechanism to bring their output into a common pipeline if needed, I don't think we want to take on that complexity in gstcef :)

@MathieuDuponchelle MathieuDuponchelle merged commit 5425330 into master Oct 14, 2024
1 check 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.

3 participants