shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 1 | // 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 Toyoshima | d4f37cd | 2018-10-01 07:43:39 +0000 | [diff] [blame] | 10 | #include "base/thread_annotations.h" |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 11 | #include "media/midi/midi_manager.h" |
| 12 | |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 13 | namespace midi { |
| 14 | |
toyoshim | f4d6152 | 2017-02-10 02:03:32 -0800 | [diff] [blame] | 15 | class MidiService; |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 16 | |
| 17 | class MIDI_EXPORT MidiManagerWinrt final : public MidiManager { |
| 18 | public: |
Takashi Toyoshima | 3f0ea8f | 2018-01-17 09:19:59 +0000 | [diff] [blame] | 19 | class MidiInPortManager; |
| 20 | class MidiOutPortManager; |
| 21 | |
toyoshim | f4d6152 | 2017-02-10 02:03:32 -0800 | [diff] [blame] | 22 | explicit MidiManagerWinrt(MidiService* service); |
Peter Boström | 5363403 | 2021-09-22 20:24:34 +0000 | [diff] [blame] | 23 | |
| 24 | MidiManagerWinrt(const MidiManagerWinrt&) = delete; |
| 25 | MidiManagerWinrt& operator=(const MidiManagerWinrt&) = delete; |
| 26 | |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 27 | ~MidiManagerWinrt() override; |
| 28 | |
| 29 | // MidiManager overrides: |
| 30 | void StartInitialization() final; |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 31 | void DispatchSendMidiData(MidiManagerClient* client, |
| 32 | uint32_t port_index, |
| 33 | const std::vector<uint8_t>& data, |
tzik | 925e2c6 | 2018-02-02 07:39:45 +0000 | [diff] [blame] | 34 | base::TimeTicks timestamp) final; |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 35 | |
| 36 | private: |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 37 | // Subclasses that access private/protected members of MidiManager. |
| 38 | template <typename InterfaceType, |
| 39 | typename RuntimeType, |
| 40 | typename StaticsInterfaceType, |
Peter Kasting | 2265777 | 2021-02-01 21:28:20 +0000 | [diff] [blame] | 41 | wchar_t const* runtime_class_id> |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 42 | class MidiPortManager; |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 43 | |
Takashi Toyoshima | 3f0ea8f | 2018-01-17 09:19:59 +0000 | [diff] [blame] | 44 | // Callbacks on kComTaskRunner. |
| 45 | void InitializeOnComRunner(); |
| 46 | void SendOnComRunner(uint32_t port_index, const std::vector<uint8_t>& data); |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 47 | |
Takashi Toyoshima | 3f0ea8f | 2018-01-17 09:19:59 +0000 | [diff] [blame] | 48 | // 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 |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 54 | // twice in the destructor. |
| 55 | base::Lock lazy_init_member_lock_; |
| 56 | |
Takashi Toyoshima | 3f0ea8f | 2018-01-17 09:19:59 +0000 | [diff] [blame] | 57 | // All operations to Midi{In|Out}PortManager should be done on kComTaskRunner. |
Takashi Toyoshima | d4f37cd | 2018-10-01 07:43:39 +0000 | [diff] [blame] | 58 | 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_); |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 62 | |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 63 | // Incremented when a MidiPortManager is ready. |
| 64 | uint8_t port_manager_ready_count_ = 0; |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | } // namespace midi |
shaochuan | e58f9c7 | 2016-08-30 22:27:08 -0700 | [diff] [blame] | 68 | |
| 69 | #endif // MEDIA_MIDI_MIDI_MANAGER_WINRT_H_ |