summaryrefslogtreecommitdiffstats
path: root/dom/media/ipc/RDDProcessManager.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/media/ipc/RDDProcessManager.h
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--dom/media/ipc/RDDProcessManager.h116
1 files changed, 116 insertions, 0 deletions
diff --git a/dom/media/ipc/RDDProcessManager.h b/dom/media/ipc/RDDProcessManager.h
new file mode 100644
index 0000000000..0204eba373
--- /dev/null
+++ b/dom/media/ipc/RDDProcessManager.h
@@ -0,0 +1,116 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef _include_dom_media_ipc_RDDProcessManager_h_
+#define _include_dom_media_ipc_RDDProcessManager_h_
+#include "mozilla/MozPromise.h"
+#include "mozilla/PRemoteDecoderManagerChild.h"
+#include "mozilla/RDDProcessHost.h"
+#include "mozilla/ipc/TaskFactory.h"
+#include "nsIObserver.h"
+
+namespace mozilla {
+
+class MemoryReportingProcess;
+class RDDChild;
+
+// The RDDProcessManager is a singleton responsible for creating RDD-bound
+// objects that may live in another process. Currently, it provides access
+// to the RDD process via ContentParent.
+class RDDProcessManager final : public RDDProcessHost::Listener {
+ friend class RDDChild;
+
+ public:
+ static void Initialize();
+ static void Shutdown();
+ static RDDProcessManager* Get();
+
+ ~RDDProcessManager();
+
+ using EnsureRDDPromise =
+ MozPromise<ipc::Endpoint<PRemoteDecoderManagerChild>, nsresult, true>;
+ // Launch a new RDD process asynchronously
+ RefPtr<GenericNonExclusivePromise> LaunchRDDProcess();
+ // If not using a RDD process, launch a new RDD process asynchronously and
+ // create a RemoteDecoderManager bridge
+ RefPtr<EnsureRDDPromise> EnsureRDDProcessAndCreateBridge(
+ base::ProcessId aOtherProcess);
+
+ void OnProcessUnexpectedShutdown(RDDProcessHost* aHost) override;
+
+ // Notify the RDDProcessManager that a top-level PRDD protocol has been
+ // terminated. This may be called from any thread.
+ void NotifyRemoteActorDestroyed(const uint64_t& aProcessToken);
+
+ // Returns -1 if there is no RDD process, or the platform pid for it.
+ base::ProcessId RDDProcessPid();
+
+ // If a RDD process is present, create a MemoryReportingProcess object.
+ // Otherwise, return null.
+ RefPtr<MemoryReportingProcess> GetProcessMemoryReporter();
+
+ // Returns access to the PRDD protocol if a RDD process is present.
+ RDDChild* GetRDDChild() { return mRDDChild; }
+
+ // Returns whether or not a RDD process was ever launched.
+ bool AttemptedRDDProcess() const { return mNumProcessAttempts > 0; }
+
+ // Returns the RDD Process
+ RDDProcessHost* Process() { return mProcess; }
+
+ private:
+ bool IsRDDProcessLaunching();
+ bool CreateVideoBridge();
+
+ // Called from our xpcom-shutdown observer.
+ void OnXPCOMShutdown();
+ void OnPreferenceChange(const char16_t* aData);
+
+ RDDProcessManager();
+
+ // Shutdown the RDD process.
+ void CleanShutdown();
+ void DestroyProcess();
+
+ DISALLOW_COPY_AND_ASSIGN(RDDProcessManager);
+
+ class Observer final : public nsIObserver {
+ public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIOBSERVER
+ explicit Observer(RDDProcessManager* aManager);
+
+ protected:
+ ~Observer() = default;
+
+ RDDProcessManager* mManager;
+ };
+ friend class Observer;
+
+ bool CreateContentBridge(
+ base::ProcessId aOtherProcess,
+ ipc::Endpoint<PRemoteDecoderManagerChild>* aOutRemoteDecoderManager);
+
+ const RefPtr<Observer> mObserver;
+ ipc::TaskFactory<RDDProcessManager> mTaskFactory;
+ uint32_t mNumProcessAttempts = 0;
+ uint32_t mNumUnexpectedCrashes = 0;
+
+ // Fields that are associated with the current RDD process.
+ RDDProcessHost* mProcess = nullptr;
+ uint64_t mProcessToken = 0;
+ RDDChild* mRDDChild = nullptr;
+ // Collects any pref changes that occur during process launch (after
+ // the initial map is passed in command-line arguments) to be sent
+ // when the process can receive IPC messages.
+ nsTArray<dom::Pref> mQueuedPrefs;
+ // Promise will be resolved when the RDD process has been fully started and
+ // VideoBridge configured. Only accessed on the main thread.
+ RefPtr<GenericNonExclusivePromise> mLaunchRDDPromise;
+};
+
+} // namespace mozilla
+
+#endif // _include_dom_media_ipc_RDDProcessManager_h_