Skip to content

Truly independent web browser

LibMedia: Don't use the thread pool for playback manager source init

Zaggy1024e60bdc4e1dbf
diff --git a/Libraries/LibMedia/PlaybackManager.cpp b/Libraries/LibMedia/PlaybackManager.cpp
index 2d5b183eba6..709de5cc894 100644
--- a/Libraries/LibMedia/PlaybackManager.cpp
+++ b/Libraries/LibMedia/PlaybackManager.cpp
@@ -22,7 +22,6 @@
#include <LibMedia/Track.h>
#include <LibMediaCodecs/VideoFrame.h>
#include <LibThreading/Thread.h>
-#include <LibThreading/ThreadPool.h>
#include "PlaybackManager.h"
@@ -209,18 +208,21 @@ NonnullRefPtr<PlaybackManager::AddMediaSourcePromise> PlaybackManager::add_media
auto& main_thread_event_loop = Core::EventLoop::current();
auto promise = AddMediaSourcePromise::construct();
- // The promise's reference count is not atomic, so the thread pool task must only ever move it.
- Threading::ThreadPool::the().submit([self = move(self), stream, &main_thread_event_loop, promise = promise] mutable {
+ // The promise's reference count is not atomic, so it must only be moved to and from the thread.
+ auto thread = Threading::Thread::construct("InitMediaSource"sv, [self = move(self), stream, &main_thread_event_loop, promise = promise] mutable -> intptr_t {
auto demuxer_or_error = create_demuxer(stream);
if (demuxer_or_error.is_error()) {
reject_media_source(move(self), move(promise), main_thread_event_loop, demuxer_or_error.release_error());
- return;
+ return 0;
}
auto maybe_error = prepare_playback_from_demuxer(self, demuxer_or_error.release_value(), main_thread_event_loop, promise);
if (maybe_error.is_error())
reject_media_source(move(self), move(promise), main_thread_event_loop, maybe_error.release_error());
+ return 0;
});
+ thread->start();
+ thread->detach();
return promise;
}
@@ -230,12 +232,15 @@ NonnullRefPtr<PlaybackManager::AddMediaSourcePromise> PlaybackManager::add_media
auto& main_thread_event_loop = Core::EventLoop::current();
auto promise = AddMediaSourcePromise::construct();
- // The promise's reference count is not atomic, so the thread pool task must only ever move it.
- Threading::ThreadPool::the().submit([self = move(self), demuxer, &main_thread_event_loop, promise = promise] mutable {
+ // The promise's reference count is not atomic, so it must only be moved to and from the thread.
+ auto thread = Threading::Thread::construct("InitMediaSource"sv, [self = move(self), demuxer, &main_thread_event_loop, promise = promise] mutable -> intptr_t {
auto maybe_error = prepare_playback_from_demuxer(self, demuxer, main_thread_event_loop, promise);
if (maybe_error.is_error())
reject_media_source(move(self), move(promise), main_thread_event_loop, maybe_error.release_error());
+ return 0;
});
+ thread->start();
+ thread->detach();
return promise;
}