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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 // means send "now" or as soon as possible. | 84 // means send "now" or as soon as possible. |
85 // The default implementation is for unsupported platforms. | 85 // The default implementation is for unsupported platforms. |
86 virtual void DispatchSendMidiData(MidiManagerClient* client, | 86 virtual void DispatchSendMidiData(MidiManagerClient* client, |
87 uint32 port_index, | 87 uint32 port_index, |
88 const std::vector<uint8>& data, | 88 const std::vector<uint8>& data, |
89 double timestamp); | 89 double timestamp); |
90 | 90 |
91 // input_ports() is a list of MIDI ports for receiving MIDI data. | 91 // input_ports() is a list of MIDI ports for receiving MIDI data. |
92 // Each individual port in this list can be identified by its | 92 // Each individual port in this list can be identified by its |
93 // integer index into this list. | 93 // integer index into this list. |
94 const MidiPortInfoList& input_ports() { return input_ports_; } | 94 const MidiPortInfoList& get_input_ports() { return input_ports_; } |
yukawa
2014/05/07 00:29:57
... const { ... }
BTW, |input_ports()| seems to b
Takashi Toyoshima
2014/05/07 02:28:26
Oh, that's misunderstanding. Fixed.
| |
95 | 95 |
96 // output_ports() is a list of MIDI ports for sending MIDI data. | 96 // output_ports() is a list of MIDI ports for sending MIDI data. |
97 // Each individual port in this list can be identified by its | 97 // Each individual port in this list can be identified by its |
98 // integer index into this list. | 98 // integer index into this list. |
99 const MidiPortInfoList& output_ports() { return output_ports_; } | 99 const MidiPortInfoList& get_output_ports() { return output_ports_; } |
yukawa
2014/05/07 00:29:57
... const { }
Takashi Toyoshima
2014/05/07 02:28:26
Thanks for catching them. I'm relatively lazy to f
| |
100 | 100 |
101 protected: | 101 protected: |
102 friend class MidiManagerUsb; | 102 friend class MidiManagerUsb; |
103 | 103 |
104 // Initializes the platform dependent MIDI system. MidiManager class has a | 104 // Initializes the platform dependent MIDI system. MidiManager class has a |
105 // default implementation that synchronously calls CompleteInitialization() | 105 // default implementation that synchronously calls CompleteInitialization() |
106 // with MIDI_NOT_SUPPORTED on the caller thread. A derived class for a | 106 // with MIDI_NOT_SUPPORTED on the caller thread. A derived class for a |
107 // specific platform should override this method correctly. | 107 // specific platform should override this method correctly. |
108 // This method is called on Chrome_IOThread thread inside StartSession(). | 108 // This method is called on Chrome_IOThread thread inside StartSession(). |
109 // Platform dependent initialization can be processed synchronously or | 109 // Platform dependent initialization can be processed synchronously or |
110 // asynchronously. When the initialization is completed, | 110 // asynchronously. When the initialization is completed, |
111 // CompleteInitialization() should be called with |result|. | 111 // CompleteInitialization() should be called with |result|. |
112 // |result| should be MIDI_OK on success, otherwise a proper MidiResult. | 112 // |result| should be MIDI_OK on success, otherwise a proper MidiResult. |
113 virtual void StartInitialization(); | 113 virtual void StartInitialization(); |
114 | 114 |
115 // Called from a platform dependent implementation of StartInitialization(). | 115 // Called from a platform dependent implementation of StartInitialization(). |
116 // It invokes CompleteInitializationInternal() on the thread that calls | 116 // It invokes CompleteInitializationInternal() on the thread that calls |
117 // StartSession() and distributes |result| to MIDIManagerClient objects in | 117 // StartSession() and distributes |result| to MIDIManagerClient objects in |
118 // |pending_clients_|. | 118 // |pending_clients_|. |
119 void CompleteInitialization(MidiResult result); | 119 void CompleteInitialization(MidiResult result); |
120 | 120 |
121 void AddInputPort(const MidiPortInfo& info); | 121 void AddInputPort(const MidiPortInfo& info); |
122 void AddOutputPort(const MidiPortInfo& info); | 122 void AddOutputPort(const MidiPortInfo& info); |
123 void ClearInputOutputPorts(); | |
123 | 124 |
124 // Dispatches to all clients. | 125 // Dispatches to all clients. |
125 // TODO(toyoshim): Fix the mac implementation to use | 126 // TODO(toyoshim): Fix the mac implementation to use |
126 // |ReceiveMidiData(..., base::TimeTicks)|. | 127 // |ReceiveMidiData(..., base::TimeTicks)|. |
127 void ReceiveMidiData(uint32 port_index, | 128 void ReceiveMidiData(uint32 port_index, |
128 const uint8* data, | 129 const uint8* data, |
129 size_t length, | 130 size_t length, |
130 double timestamp); | 131 double timestamp); |
131 | 132 |
132 void ReceiveMidiData(uint32 port_index, | 133 void ReceiveMidiData(uint32 port_index, |
133 const uint8* data, | 134 const uint8* data, |
134 size_t length, | 135 size_t length, |
135 base::TimeTicks time) { | 136 base::TimeTicks time) { |
136 ReceiveMidiData(port_index, data, length, | 137 ReceiveMidiData(port_index, data, length, |
137 (time - base::TimeTicks()).InSecondsF()); | 138 (time - base::TimeTicks()).InSecondsF()); |
138 } | 139 } |
139 | 140 |
140 size_t get_clients_size_for_testing() const { return clients_.size(); } | 141 size_t get_clients_size_for_testing() const { return clients_.size(); } |
141 size_t get_pending_clients_size_for_testing() const { | 142 size_t get_pending_clients_size_for_testing() const { |
142 return pending_clients_.size(); | 143 return pending_clients_.size(); |
143 } | 144 } |
144 | 145 |
145 // TODO(toyoshim): Make |input_ports_| and |output_ports_| private members. | |
146 MidiPortInfoList input_ports_; | |
147 MidiPortInfoList output_ports_; | |
148 | |
149 private: | 146 private: |
150 void CompleteInitializationInternal(MidiResult result); | 147 void CompleteInitializationInternal(MidiResult result); |
151 | 148 |
152 // Keeps track of all clients who wish to receive MIDI data. | 149 // Keeps track of all clients who wish to receive MIDI data. |
153 typedef std::set<MidiManagerClient*> ClientList; | 150 typedef std::set<MidiManagerClient*> ClientList; |
154 ClientList clients_; | 151 ClientList clients_; |
155 | 152 |
156 // Keeps track of all clients who are waiting for CompleteStartSession(). | 153 // Keeps track of all clients who are waiting for CompleteStartSession(). |
157 typedef std::map<int, MidiManagerClient*> PendingClientMap; | 154 typedef std::map<int, MidiManagerClient*> PendingClientMap; |
158 PendingClientMap pending_clients_; | 155 PendingClientMap pending_clients_; |
159 | 156 |
160 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in | 157 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in |
161 // order to invoke CompleteStartSession() on the thread. | 158 // order to invoke CompleteStartSession() on the thread. |
162 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; | 159 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; |
163 | 160 |
164 // Keeps true if platform dependent initialization is already completed. | 161 // Keeps true if platform dependent initialization is already completed. |
165 bool initialized_; | 162 bool initialized_; |
166 | 163 |
167 // Keeps the platform dependent initialization result if initialization is | 164 // Keeps the platform dependent initialization result if initialization is |
168 // completed. Otherwise keeps MIDI_NOT_SUPPORTED. | 165 // completed. Otherwise keeps MIDI_NOT_SUPPORTED. |
169 MidiResult result_; | 166 MidiResult result_; |
170 | 167 |
171 // Protects access to |clients_|, |pending_clients_|, |initialized_|, and | 168 // Protects access to |clients_|, |pending_clients_|, |initialized_|, and |
172 // |result_|. | 169 // |result_|. |
173 base::Lock lock_; | 170 base::Lock lock_; |
174 | 171 |
172 MidiPortInfoList input_ports_; | |
173 MidiPortInfoList output_ports_; | |
174 | |
175 DISALLOW_COPY_AND_ASSIGN(MidiManager); | 175 DISALLOW_COPY_AND_ASSIGN(MidiManager); |
176 }; | 176 }; |
177 | 177 |
178 } // namespace media | 178 } // namespace media |
179 | 179 |
180 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ | 180 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ |
OLD | NEW |