OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_MIDI_MIDI_MANAGER_H_ | 5 #ifndef MEDIA_MIDI_MIDI_MANAGER_H_ |
6 #define MEDIA_MIDI_MIDI_MANAGER_H_ | 6 #define MEDIA_MIDI_MIDI_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // means send "now" or as soon as possible. | 86 // means send "now" or as soon as possible. |
87 // The default implementation is for unsupported platforms. | 87 // The default implementation is for unsupported platforms. |
88 virtual void DispatchSendMidiData(MidiManagerClient* client, | 88 virtual void DispatchSendMidiData(MidiManagerClient* client, |
89 uint32 port_index, | 89 uint32 port_index, |
90 const std::vector<uint8>& data, | 90 const std::vector<uint8>& data, |
91 double timestamp); | 91 double timestamp); |
92 | 92 |
93 // input_ports() is a list of MIDI ports for receiving MIDI data. | 93 // input_ports() is a list of MIDI ports for receiving MIDI data. |
94 // Each individual port in this list can be identified by its | 94 // Each individual port in this list can be identified by its |
95 // integer index into this list. | 95 // integer index into this list. |
96 const MidiPortInfoList& input_ports() { return input_ports_; } | 96 const MidiPortInfoList& input_ports() const { return input_ports_; } |
97 | 97 |
98 // output_ports() is a list of MIDI ports for sending MIDI data. | 98 // output_ports() is a list of MIDI ports for sending MIDI data. |
99 // Each individual port in this list can be identified by its | 99 // Each individual port in this list can be identified by its |
100 // integer index into this list. | 100 // integer index into this list. |
101 const MidiPortInfoList& output_ports() { return output_ports_; } | 101 const MidiPortInfoList& output_ports() const { return output_ports_; } |
102 | 102 |
103 protected: | 103 protected: |
104 friend class MidiManagerUsb; | 104 friend class MidiManagerUsb; |
105 | 105 |
106 // Initializes the platform dependent MIDI system. MidiManager class has a | 106 // Initializes the platform dependent MIDI system. MidiManager class has a |
107 // default implementation that synchronously calls CompleteInitialization() | 107 // default implementation that synchronously calls CompleteInitialization() |
108 // with MIDI_NOT_SUPPORTED on the caller thread. A derived class for a | 108 // with MIDI_NOT_SUPPORTED on the caller thread. A derived class for a |
109 // specific platform should override this method correctly. | 109 // specific platform should override this method correctly. |
110 // This method is called on Chrome_IOThread thread inside StartSession(). | 110 // This method is called on Chrome_IOThread thread inside StartSession(). |
111 // Platform dependent initialization can be processed synchronously or | 111 // Platform dependent initialization can be processed synchronously or |
(...skipping 20 matching lines...) Expand all Loading... |
132 double timestamp); | 132 double timestamp); |
133 | 133 |
134 void ReceiveMidiData(uint32 port_index, | 134 void ReceiveMidiData(uint32 port_index, |
135 const uint8* data, | 135 const uint8* data, |
136 size_t length, | 136 size_t length, |
137 base::TimeTicks time) { | 137 base::TimeTicks time) { |
138 ReceiveMidiData(port_index, data, length, | 138 ReceiveMidiData(port_index, data, length, |
139 (time - base::TimeTicks()).InSecondsF()); | 139 (time - base::TimeTicks()).InSecondsF()); |
140 } | 140 } |
141 | 141 |
142 size_t get_clients_size_for_testing() const { return clients_.size(); } | 142 size_t clients_size_for_testing() const { return clients_.size(); } |
143 size_t get_pending_clients_size_for_testing() const { | 143 size_t pending_clients_size_for_testing() const { |
144 return pending_clients_.size(); | 144 return pending_clients_.size(); |
145 } | 145 } |
146 | 146 |
147 // TODO(toyoshim): Make |input_ports_| and |output_ports_| private members. | |
148 MidiPortInfoList input_ports_; | |
149 MidiPortInfoList output_ports_; | |
150 | |
151 private: | 147 private: |
152 void CompleteInitializationInternal(MidiResult result); | 148 void CompleteInitializationInternal(MidiResult result); |
153 | 149 |
154 // Keeps track of all clients who wish to receive MIDI data. | 150 // Keeps track of all clients who wish to receive MIDI data. |
155 typedef std::set<MidiManagerClient*> ClientList; | 151 typedef std::set<MidiManagerClient*> ClientList; |
156 ClientList clients_; | 152 ClientList clients_; |
157 | 153 |
158 // Keeps track of all clients who are waiting for CompleteStartSession(). | 154 // Keeps track of all clients who are waiting for CompleteStartSession(). |
159 typedef std::map<int, MidiManagerClient*> PendingClientMap; | 155 typedef std::map<int, MidiManagerClient*> PendingClientMap; |
160 PendingClientMap pending_clients_; | 156 PendingClientMap pending_clients_; |
161 | 157 |
162 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in | 158 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in |
163 // order to invoke CompleteStartSession() on the thread. | 159 // order to invoke CompleteStartSession() on the thread. |
164 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; | 160 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; |
165 | 161 |
166 // Keeps true if platform dependent initialization is already completed. | 162 // Keeps true if platform dependent initialization is already completed. |
167 bool initialized_; | 163 bool initialized_; |
168 | 164 |
169 // Keeps the platform dependent initialization result if initialization is | 165 // Keeps the platform dependent initialization result if initialization is |
170 // completed. Otherwise keeps MIDI_NOT_SUPPORTED. | 166 // completed. Otherwise keeps MIDI_NOT_SUPPORTED. |
171 MidiResult result_; | 167 MidiResult result_; |
172 | 168 |
173 // Protects access to |clients_|, |pending_clients_|, |initialized_|, and | 169 // Protects access to |clients_|, |pending_clients_|, |initialized_|, and |
174 // |result_|. | 170 // |result_|. |
175 base::Lock lock_; | 171 base::Lock lock_; |
176 | 172 |
| 173 MidiPortInfoList input_ports_; |
| 174 MidiPortInfoList output_ports_; |
| 175 |
177 DISALLOW_COPY_AND_ASSIGN(MidiManager); | 176 DISALLOW_COPY_AND_ASSIGN(MidiManager); |
178 }; | 177 }; |
179 | 178 |
180 } // namespace media | 179 } // namespace media |
181 | 180 |
182 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ | 181 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ |
OLD | NEW |