Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: media/midi/dynamically_initialized_midi_manager_win.h

Issue 2686043003: [not for review] Web MIDI: new backend to support dynamic instantiation on Windows (Closed)
Patch Set: not for review (rebase/rename/LazyInstance) Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/midi/BUILD.gn ('k') | media/midi/dynamically_initialized_midi_manager_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_
6 #define MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_
7
8 #include <memory>
9 #include <vector>
10
11 #include "base/callback_forward.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/system_monitor/system_monitor.h"
15 #include "media/midi/midi_manager.h"
16
17 namespace base {
18 class SingleThreadTaskRunner;
19 class TimeDelta;
20 } // namespace base
21
22 namespace midi {
23
24 // New backend for legacy Windows that support dynamic instantiation.
25 class DynamicallyInitializedMidiManagerWin final
26 : public MidiManager,
27 public base::SystemMonitor::DevicesChangedObserver {
28 public:
29 explicit DynamicallyInitializedMidiManagerWin(MidiService* service);
30 ~DynamicallyInitializedMidiManagerWin() override;
31
32 // Calculates event time from elapsed time that system provides.
33 base::TimeTicks CalculateInEventTime(size_t index, uint32_t elapsed_ms) const;
34
35 // Handles MIDI inport event posted from a thread system provides.
36 void ReceiveMidiData(uint32_t index,
37 const std::vector<uint8_t>& data,
38 base::TimeTicks time);
39
40 // Posts a reply task to the I/O thread that hosts MidiManager instance, runs
41 // it safely, and ensures that the instance keeps alive while the task is
42 // running.
43 void PostReplyTask(const base::Closure&);
44
45 // MidiManager overrides:
46 void StartInitialization() override;
47 void Finalize() override;
48 void DispatchSendMidiData(MidiManagerClient* client,
49 uint32_t port_index,
50 const std::vector<uint8_t>& data,
51 double timestamp) override;
52
53 // base::SystemMonitor::DevicesChangedObserver overrides:
54 void OnDevicesChanged(base::SystemMonitor::DeviceType device_type) override;
55
56 private:
57 class InPort;
58 class OutPort;
59
60 // Posts a task to TaskRunner, and ensures that the instance keeps alive while
61 // the task is running.
62 void PostTask(const base::Closure&);
63 void PostDelayedTask(const base::Closure&, base::TimeDelta delay);
64
65 // Initializes instance asynchronously on TaskRunner.
66 void InitializeOnTaskRunner();
67
68 // Updates device lists on TaskRunner.
69 // Returns true if device lists were changed.
70 void UpdateDeviceListOnTaskRunner();
71
72 // Sends MIDI data on TaskRunner.
73 void SendOnTaskRunner(MidiManagerClient* client,
74 uint32_t port_index,
75 const std::vector<uint8_t>& data);
76
77 // Holds an unique instance ID.
78 int instance_id_;
79
80 // Keeps a TaskRunner for the I/O thread.
81 scoped_refptr<base::SingleThreadTaskRunner> thread_runner_;
82
83 // Following members should be accessed only on TaskRunner.
84
85 // Holds all MIDI input or output ports connected once.
86 std::vector<std::unique_ptr<InPort>> input_ports_;
87 std::vector<std::unique_ptr<OutPort>> output_ports_;
88
89 DISALLOW_COPY_AND_ASSIGN(DynamicallyInitializedMidiManagerWin);
90 };
91
92 } // namespace midi
93
94 #endif // MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_
OLDNEW
« no previous file with comments | « media/midi/BUILD.gn ('k') | media/midi/dynamically_initialized_midi_manager_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698