Bug 2033697 - Cleanup MIDI IPC. r=gsvelto

Differential Revision: https://phabricator.services.mozilla.com/D295469
This commit is contained in:
Tom Schuster
2026-04-27 08:53:17 +00:00
committed by tschuster@mozilla.com
parent fdfe363775
commit c245754f13
13 changed files with 56 additions and 26 deletions
+1 -1
View File
@@ -142,7 +142,7 @@ void MIDIAccess::FireConnectionEvent(MIDIPort* aPort) {
void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo,
ErrorResult& aRv) {
nsAutoString id(aInfo.id());
MIDIPortType type = static_cast<MIDIPortType>(aInfo.type());
MIDIPortType type = aInfo.type();
RefPtr<MIDIPort> port;
if (type == MIDIPortType::Input) {
if (mInputMap->Has(id) || NS_WARN_IF(aRv.Failed())) {
+29
View File
@@ -0,0 +1,29 @@
/* 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 mozilla_dom_MIDIIPCUtils_h
#define mozilla_dom_MIDIIPCUtils_h
#include "mozilla/dom/BindingIPCUtils.h"
#include "mozilla/dom/MIDIPortBinding.h"
namespace IPC {
template <>
struct ParamTraits<mozilla::dom::MIDIPortType>
: public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::MIDIPortType> {};
template <>
struct ParamTraits<mozilla::dom::MIDIPortDeviceState>
: public mozilla::dom::WebIDLEnumSerializer<
mozilla::dom::MIDIPortDeviceState> {};
template <>
struct ParamTraits<mozilla::dom::MIDIPortConnectionState>
: public mozilla::dom::WebIDLEnumSerializer<
mozilla::dom::MIDIPortConnectionState> {};
} // namespace IPC
#endif // mozilla_dom_MIDIIPCUtils_h
+1 -2
View File
@@ -22,8 +22,7 @@ RefPtr<MIDIInput> MIDIInput::Create(nsPIDOMWindowInner* aWindow,
MIDIAccess* aMIDIAccessParent,
const MIDIPortInfo& aPortInfo,
const bool aSysexEnabled) {
MOZ_ASSERT(static_cast<MIDIPortType>(aPortInfo.type()) ==
MIDIPortType::Input);
MOZ_ASSERT(aPortInfo.type() == MIDIPortType::Input);
RefPtr<MIDIInput> port = new MIDIInput(aWindow);
if (!port->Initialize(aPortInfo, aSysexEnabled, aMIDIAccessParent)) {
return nullptr;
+1 -2
View File
@@ -24,8 +24,7 @@ RefPtr<MIDIOutput> MIDIOutput::Create(nsPIDOMWindowInner* aWindow,
MIDIAccess* aMIDIAccessParent,
const MIDIPortInfo& aPortInfo,
const bool aSysexEnabled) {
MOZ_ASSERT(static_cast<MIDIPortType>(aPortInfo.type()) ==
MIDIPortType::Output);
MOZ_ASSERT(aPortInfo.type() == MIDIPortType::Output);
RefPtr<MIDIOutput> port = new MIDIOutput(aWindow);
if (NS_WARN_IF(
!port->Initialize(aPortInfo, aSysexEnabled, aMIDIAccessParent))) {
+4 -3
View File
@@ -32,14 +32,15 @@ mozilla::ipc::IPCResult MIDIPortChild::RecvReceive(
}
mozilla::ipc::IPCResult MIDIPortChild::RecvUpdateStatus(
const uint32_t& aDeviceState, const uint32_t& aConnectionState) {
const MIDIPortDeviceState& aDeviceState,
const MIDIPortConnectionState& aConnectionState) {
// Either a device is connected, and can have any connection state, or a
// device is disconnected, and can only be closed or pending.
MOZ_ASSERT(mDeviceState == MIDIPortDeviceState::Connected ||
(mConnectionState == MIDIPortConnectionState::Closed ||
mConnectionState == MIDIPortConnectionState::Pending));
mDeviceState = static_cast<MIDIPortDeviceState>(aDeviceState);
mConnectionState = static_cast<MIDIPortConnectionState>(aConnectionState);
mDeviceState = aDeviceState;
mConnectionState = aConnectionState;
if (mDOMPort) {
RefPtr<MIDIPort> self(mDOMPort);
self->FireStateChangeEvent();
+3 -2
View File
@@ -26,8 +26,9 @@ class MIDIPortChild final : public PMIDIPortChild, public MIDIPortInterface {
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
mozilla::ipc::IPCResult RecvUpdateStatus(const uint32_t& aDeviceState,
const uint32_t& aConnectionState);
mozilla::ipc::IPCResult RecvUpdateStatus(
const MIDIPortDeviceState& aDeviceState,
const MIDIPortConnectionState& aConnectionState);
MIDIPortChild(const MIDIPortInfo& aPortInfo, bool aSysexEnabled,
MIDIPort* aPort);
+1 -1
View File
@@ -14,7 +14,7 @@ mozilla::dom::MIDIPortInterface::MIDIPortInterface(
mManufacturer(aPortInfo.manufacturer()),
mVersion(aPortInfo.version()),
mSysexEnabled(aSysexEnabled),
mType((MIDIPortType)aPortInfo.type()),
mType(aPortInfo.type()),
// We'll never initialize a port object that's not connected
mDeviceState(MIDIPortDeviceState::Connected),
mConnectionState(MIDIPortConnectionState::Closed),
+1 -3
View File
@@ -89,9 +89,7 @@ bool MIDIPortParent::SendUpdateStatus(
}
mMessageQueue.Clear();
}
return PMIDIPortParent::SendUpdateStatus(
static_cast<uint32_t>(mDeviceState),
static_cast<uint32_t>(mConnectionState));
return PMIDIPortParent::SendUpdateStatus(mDeviceState, mConnectionState);
}
MIDIPortParent::MIDIPortParent(const MIDIPortInfo& aPortInfo,
+6 -2
View File
@@ -2,7 +2,12 @@
* 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/. */
include "mozilla/dom/MIDIIPCUtils.h";
using mozilla::TimeStamp from "mozilla/TimeStamp.h";
using mozilla::dom::MIDIPortType from "mozilla/dom/MIDIPortBinding.h";
using mozilla::dom::MIDIPortDeviceState from "mozilla/dom/MIDIPortBinding.h";
using mozilla::dom::MIDIPortConnectionState from "mozilla/dom/MIDIPortBinding.h";
namespace mozilla {
namespace dom {
@@ -12,8 +17,7 @@ namespace dom {
nsString name;
nsString manufacturer;
nsString version;
//Actually a MIDIPortType enum
uint32_t type;
MIDIPortType type;
};
struct MIDIMessage {
+1 -3
View File
@@ -18,9 +18,7 @@ parent:
async Clear();
child:
async Receive(MIDIMessage[] msg);
// Actually takes a MIDIDeviceConnectionState and MIDIPortConnectionState
// respectively.
async UpdateStatus(uint32_t deviceState, uint32_t connectionState);
async UpdateStatus(MIDIPortDeviceState deviceState, MIDIPortConnectionState connectionState);
};
}
+5 -5
View File
@@ -68,23 +68,23 @@ TestMIDIPlatformService::TestMIDIPlatformService()
: mControlInputPort(u"b744eebe-f7d8-499b-872b-958f63c8f522"_ns,
u"Test Control MIDI Device Input Port"_ns,
u"Test Manufacturer"_ns, u"1.0.0"_ns,
static_cast<uint32_t>(MIDIPortType::Input)),
MIDIPortType::Input),
mControlOutputPort(u"ab8e7fe8-c4de-436a-a960-30898a7c9a3d"_ns,
u"Test Control MIDI Device Output Port"_ns,
u"Test Manufacturer"_ns, u"1.0.0"_ns,
static_cast<uint32_t>(MIDIPortType::Output)),
MIDIPortType::Output),
mStateTestInputPort(u"a9329677-8588-4460-a091-9d4a7f629a48"_ns,
u"Test State MIDI Device Input Port"_ns,
u"Test Manufacturer"_ns, u"1.0.0"_ns,
static_cast<uint32_t>(MIDIPortType::Input)),
MIDIPortType::Input),
mStateTestOutputPort(u"478fa225-b5fc-4fa6-a543-d32d9cb651e7"_ns,
u"Test State MIDI Device Output Port"_ns,
u"Test Manufacturer"_ns, u"1.0.0"_ns,
static_cast<uint32_t>(MIDIPortType::Output)),
MIDIPortType::Output),
mAlwaysClosedTestOutputPort(u"f87d0c76-3c68-49a9-a44f-700f1125c07a"_ns,
u"Always Closed MIDI Device Output Port"_ns,
u"Test Manufacturer"_ns, u"1.0.0"_ns,
static_cast<uint32_t>(MIDIPortType::Output)),
MIDIPortType::Output),
mDoRefresh(false),
mIsInitialized(false) {
MIDIPlatformService::AssertThread();
+2 -2
View File
@@ -75,7 +75,7 @@ midirMIDIPlatformService::~midirMIDIPlatformService() {
void midirMIDIPlatformService::AddPort(const nsString* aId,
const nsString* aName, bool aInput) {
MIDIPortType type = aInput ? MIDIPortType::Input : MIDIPortType::Output;
MIDIPortInfo port(*aId, *aName, u""_ns, u""_ns, static_cast<uint32_t>(type));
MIDIPortInfo port(*aId, *aName, u""_ns, u""_ns, type);
MIDIPlatformService::Get()->AddPortInfo(port);
}
@@ -83,7 +83,7 @@ void midirMIDIPlatformService::AddPort(const nsString* aId,
void midirMIDIPlatformService::RemovePort(const nsString* aId,
const nsString* aName, bool aInput) {
MIDIPortType type = aInput ? MIDIPortType::Input : MIDIPortType::Output;
MIDIPortInfo port(*aId, *aName, u""_ns, u""_ns, static_cast<uint32_t>(type));
MIDIPortInfo port(*aId, *aName, u""_ns, u""_ns, type);
MIDIPlatformService::Get()->RemovePortInfo(port);
}
+1
View File
@@ -16,6 +16,7 @@ EXPORTS.mozilla.dom += [
"MIDIAccessManager.h",
"MIDIInput.h",
"MIDIInputMap.h",
"MIDIIPCUtils.h",
"MIDIManagerChild.h",
"MIDIManagerParent.h",
"MIDIMessageEvent.h",