1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_midirMIDIPlatformService_h
8 #define mozilla_dom_midirMIDIPlatformService_h
10 #include "mozilla/StaticMutex.h"
11 #include "mozilla/dom/MIDIPlatformService.h"
12 #include "mozilla/dom/MIDITypes.h"
13 #include "mozilla/dom/midi/midir_impl_ffi_generated.h"
18 namespace mozilla::dom
{
20 class MIDIPortInterface
;
23 * Platform service implementation using the midir crate.
25 class midirMIDIPlatformService
: public MIDIPlatformService
{
27 midirMIDIPlatformService();
28 virtual void Init() override
;
29 virtual void Open(MIDIPortParent
* aPort
) override
;
30 virtual void Stop() override
;
31 virtual void ScheduleSend(const nsAString
& aPort
) override
;
32 virtual void ScheduleClose(MIDIPortParent
* aPort
) override
;
34 void SendMessage(const nsAString
& aPort
, const MIDIMessage
& aMessage
);
37 virtual ~midirMIDIPlatformService();
39 static void AddPort(const nsString
* aId
, const nsString
* aName
, bool aInput
);
40 static void CheckAndReceive(const nsString
* aId
, const uint8_t* aData
,
41 size_t aLength
, const GeckoTimeStamp
* aTimeStamp
,
44 // Wrapper around the midir Rust implementation.
45 MidirWrapper
* mImplementation
;
47 // midir has its own internal threads and we can't execute jobs directly on
48 // them, instead we forward them to the background thread the service was
50 static StaticMutex gBackgroundThreadMutex
;
51 static nsCOMPtr
<nsIThread
> gBackgroundThread
;
54 } // namespace mozilla::dom
56 #endif // mozilla_dom_midirMIDIPlatformService_h