LibMedia: Don't lock the main loop while initializing a media source

We only need to take a strong reference to the main event loop when
an error occurred in order to invoke the callback on the main thread.
By taking this lock for the entire duration of the thread, we were
preventing the main thread from exiting if the init thread hangs.
This commit is contained in:
Zaggy1024 2026-02-13 13:09:48 -06:00 committed by Gregory Bertilson
parent 7dd0c70ee5
commit af2ac67be3

View file

@ -135,9 +135,9 @@ PlaybackManager::~PlaybackManager()
void PlaybackManager::add_media_source(NonnullRefPtr<IncrementallyPopulatedStream> const& stream)
{
auto thread = Threading::Thread::construct("Media Init"sv, [playback_manager = NonnullRefPtr { *this }, stream = stream, main_thread_event_loop_reference = Core::EventLoop::current_weak()] -> int {
auto main_thread_event_loop = main_thread_event_loop_reference->take();
auto maybe_error = playback_manager->prepare_playback_from_media_data(stream, main_thread_event_loop_reference);
if (maybe_error.is_error()) {
auto main_thread_event_loop = main_thread_event_loop_reference->take();
main_thread_event_loop->deferred_invoke([playback_manager, error = maybe_error.release_error()] mutable {
if (playback_manager->on_unsupported_format_error)
playback_manager->on_unsupported_format_error(move(error));