blob: ff0599584bd9bff5bce1c69f9704139d76e3dece [file] [log] [blame]
shaochuane58f9c72016-08-30 22:27:08 -07001// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef MEDIA_MIDI_MIDI_MANAGER_WINRT_H_
6#define MEDIA_MIDI_MIDI_MANAGER_WINRT_H_
7
8#include <memory>
9
Takashi Toyoshimad4f37cd2018-10-01 07:43:39 +000010#include "base/thread_annotations.h"
shaochuane58f9c72016-08-30 22:27:08 -070011#include "media/midi/midi_manager.h"
12
shaochuane58f9c72016-08-30 22:27:08 -070013namespace midi {
14
toyoshimf4d61522017-02-10 02:03:32 -080015class MidiService;
shaochuane58f9c72016-08-30 22:27:08 -070016
17class MIDI_EXPORT MidiManagerWinrt final : public MidiManager {
18 public:
Takashi Toyoshima3f0ea8f2018-01-17 09:19:59 +000019 class MidiInPortManager;
20 class MidiOutPortManager;
21
toyoshimf4d61522017-02-10 02:03:32 -080022 explicit MidiManagerWinrt(MidiService* service);
Peter Boström53634032021-09-22 20:24:34 +000023
24 MidiManagerWinrt(const MidiManagerWinrt&) = delete;
25 MidiManagerWinrt& operator=(const MidiManagerWinrt&) = delete;
26
shaochuane58f9c72016-08-30 22:27:08 -070027 ~MidiManagerWinrt() override;
28
29 // MidiManager overrides:
30 void StartInitialization() final;
shaochuane58f9c72016-08-30 22:27:08 -070031 void DispatchSendMidiData(MidiManagerClient* client,
32 uint32_t port_index,
33 const std::vector<uint8_t>& data,
tzik925e2c62018-02-02 07:39:45 +000034 base::TimeTicks timestamp) final;
shaochuane58f9c72016-08-30 22:27:08 -070035
36 private:
shaochuane58f9c72016-08-30 22:27:08 -070037 // Subclasses that access private/protected members of MidiManager.
38 template <typename InterfaceType,
39 typename RuntimeType,
40 typename StaticsInterfaceType,
Peter Kasting22657772021-02-01 21:28:20 +000041 wchar_t const* runtime_class_id>
shaochuane58f9c72016-08-30 22:27:08 -070042 class MidiPortManager;
shaochuane58f9c72016-08-30 22:27:08 -070043
Takashi Toyoshima3f0ea8f2018-01-17 09:19:59 +000044 // Callbacks on kComTaskRunner.
45 void InitializeOnComRunner();
46 void SendOnComRunner(uint32_t port_index, const std::vector<uint8_t>& data);
shaochuane58f9c72016-08-30 22:27:08 -070047
Takashi Toyoshima3f0ea8f2018-01-17 09:19:59 +000048 // Callback from MidiPortManager::OnEnumerationComplete on kComTaskRunner.
49 // Calls CompleteInitialization() when both MidiPortManagers are ready.
50 void OnPortManagerReady();
51
52 // Lock to ensure all smart pointers initialized in InitializeOnComRunner()
53 // and destroyed in FinalizeOnComRunner() will not be accidentally destructed
shaochuane58f9c72016-08-30 22:27:08 -070054 // twice in the destructor.
55 base::Lock lazy_init_member_lock_;
56
Takashi Toyoshima3f0ea8f2018-01-17 09:19:59 +000057 // All operations to Midi{In|Out}PortManager should be done on kComTaskRunner.
Takashi Toyoshimad4f37cd2018-10-01 07:43:39 +000058 std::unique_ptr<MidiInPortManager> port_manager_in_
59 GUARDED_BY(lazy_init_member_lock_);
60 std::unique_ptr<MidiOutPortManager> port_manager_out_
61 GUARDED_BY(lazy_init_member_lock_);
shaochuane58f9c72016-08-30 22:27:08 -070062
shaochuane58f9c72016-08-30 22:27:08 -070063 // Incremented when a MidiPortManager is ready.
64 uint8_t port_manager_ready_count_ = 0;
shaochuane58f9c72016-08-30 22:27:08 -070065};
66
67} // namespace midi
shaochuane58f9c72016-08-30 22:27:08 -070068
69#endif // MEDIA_MIDI_MIDI_MANAGER_WINRT_H_