| 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 <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace media { | 23 namespace media { |
| 24 | 24 |
| 25 // A MidiManagerClient registers with the MidiManager to receive MIDI data. | 25 // A MidiManagerClient registers with the MidiManager to receive MIDI data. |
| 26 // See MidiManager::RequestAccess() and MidiManager::ReleaseAccess() | 26 // See MidiManager::RequestAccess() and MidiManager::ReleaseAccess() |
| 27 // for details. | 27 // for details. |
| 28 class MEDIA_EXPORT MidiManagerClient { | 28 class MEDIA_EXPORT MidiManagerClient { |
| 29 public: | 29 public: |
| 30 virtual ~MidiManagerClient() {} | 30 virtual ~MidiManagerClient() {} |
| 31 | 31 |
| 32 // AddInputPort() and AddOutputPort() are called before CompleteStartSession() |
| 33 // is called to notify existing MIDI ports, and also called after that to |
| 34 // notify new MIDI ports are added. |
| 35 virtual void AddInputPort(const MidiPortInfo& info) = 0; |
| 36 virtual void AddOutputPort(const MidiPortInfo& info) = 0; |
| 37 |
| 38 // TODO(toyoshim): DisableInputPort(const MidiPortInfo& info) and |
| 39 // DisableOutputPort(const MidiPortInfo& info) should be added. |
| 40 // On DisableInputPort(), internal states, e.g. received_messages_queues in |
| 41 // MidiHost, should be reset. |
| 42 |
| 32 // CompleteStartSession() is called when platform dependent preparation is | 43 // CompleteStartSession() is called when platform dependent preparation is |
| 33 // finished. | 44 // finished. |
| 34 virtual void CompleteStartSession(MidiResult result) = 0; | 45 virtual void CompleteStartSession(MidiResult result) = 0; |
| 35 | 46 |
| 36 // ReceiveMidiData() is called when MIDI data has been received from the | 47 // ReceiveMidiData() is called when MIDI data has been received from the |
| 37 // MIDI system. | 48 // MIDI system. |
| 38 // |port_index| represents the specific input port from input_ports(). | 49 // |port_index| represents the specific input port from input_ports(). |
| 39 // |data| represents a series of bytes encoding one or more MIDI messages. | 50 // |data| represents a series of bytes encoding one or more MIDI messages. |
| 40 // |length| is the number of bytes in |data|. | 51 // |length| is the number of bytes in |data|. |
| 41 // |timestamp| is the time the data was received, in seconds. | 52 // |timestamp| is the time the data was received, in seconds. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // |data| represents a series of bytes encoding one or more MIDI messages. | 93 // |data| represents a series of bytes encoding one or more MIDI messages. |
| 83 // |length| is the number of bytes in |data|. | 94 // |length| is the number of bytes in |data|. |
| 84 // |timestamp| is the time to send the data, in seconds. A value of 0 | 95 // |timestamp| is the time to send the data, in seconds. A value of 0 |
| 85 // means send "now" or as soon as possible. | 96 // means send "now" or as soon as possible. |
| 86 // The default implementation is for unsupported platforms. | 97 // The default implementation is for unsupported platforms. |
| 87 virtual void DispatchSendMidiData(MidiManagerClient* client, | 98 virtual void DispatchSendMidiData(MidiManagerClient* client, |
| 88 uint32 port_index, | 99 uint32 port_index, |
| 89 const std::vector<uint8>& data, | 100 const std::vector<uint8>& data, |
| 90 double timestamp); | 101 double timestamp); |
| 91 | 102 |
| 92 // input_ports() is a list of MIDI ports for receiving MIDI data. | |
| 93 // Each individual port in this list can be identified by its | |
| 94 // integer index into this list. | |
| 95 const MidiPortInfoList& input_ports() const { return input_ports_; } | |
| 96 | |
| 97 // output_ports() is a list of MIDI ports for sending MIDI data. | |
| 98 // Each individual port in this list can be identified by its | |
| 99 // integer index into this list. | |
| 100 const MidiPortInfoList& output_ports() const { return output_ports_; } | |
| 101 | |
| 102 protected: | 103 protected: |
| 103 friend class MidiManagerUsb; | 104 friend class MidiManagerUsb; |
| 104 | 105 |
| 105 // Initializes the platform dependent MIDI system. MidiManager class has a | 106 // Initializes the platform dependent MIDI system. MidiManager class has a |
| 106 // default implementation that synchronously calls CompleteInitialization() | 107 // default implementation that synchronously calls CompleteInitialization() |
| 107 // 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 |
| 108 // specific platform should override this method correctly. | 109 // specific platform should override this method correctly. |
| 109 // This method is called on Chrome_IOThread thread inside StartSession(). | 110 // This method is called on Chrome_IOThread thread inside StartSession(). |
| 110 // Platform dependent initialization can be processed synchronously or | 111 // Platform dependent initialization can be processed synchronously or |
| 111 // asynchronously. When the initialization is completed, | 112 // asynchronously. When the initialization is completed, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 138 (time - base::TimeTicks()).InSecondsF()); | 139 (time - base::TimeTicks()).InSecondsF()); |
| 139 } | 140 } |
| 140 | 141 |
| 141 size_t clients_size_for_testing() const { return clients_.size(); } | 142 size_t clients_size_for_testing() const { return clients_.size(); } |
| 142 size_t pending_clients_size_for_testing() const { | 143 size_t pending_clients_size_for_testing() const { |
| 143 return pending_clients_.size(); | 144 return pending_clients_.size(); |
| 144 } | 145 } |
| 145 | 146 |
| 146 private: | 147 private: |
| 147 void CompleteInitializationInternal(MidiResult result); | 148 void CompleteInitializationInternal(MidiResult result); |
| 149 void AddInitialPorts(MidiManagerClient* client); |
| 148 | 150 |
| 149 // Keeps track of all clients who wish to receive MIDI data. | 151 // Keeps track of all clients who wish to receive MIDI data. |
| 150 typedef std::set<MidiManagerClient*> ClientSet; | 152 typedef std::set<MidiManagerClient*> ClientSet; |
| 151 ClientSet clients_; | 153 ClientSet clients_; |
| 152 | 154 |
| 153 // Keeps track of all clients who are waiting for CompleteStartSession(). | 155 // Keeps track of all clients who are waiting for CompleteStartSession(). |
| 154 ClientSet pending_clients_; | 156 ClientSet pending_clients_; |
| 155 | 157 |
| 156 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in | 158 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in |
| 157 // order to invoke CompleteStartSession() on the thread. | 159 // order to invoke CompleteStartSession() on the thread. |
| 158 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; | 160 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; |
| 159 | 161 |
| 160 // Keeps true if platform dependent initialization is already completed. | 162 // Keeps true if platform dependent initialization is already completed. |
| 161 bool initialized_; | 163 bool initialized_; |
| 162 | 164 |
| 163 // Keeps the platform dependent initialization result if initialization is | 165 // Keeps the platform dependent initialization result if initialization is |
| 164 // completed. Otherwise keeps MIDI_NOT_SUPPORTED. | 166 // completed. Otherwise keeps MIDI_NOT_SUPPORTED. |
| 165 MidiResult result_; | 167 MidiResult result_; |
| 166 | 168 |
| 167 // Protects access to |clients_|, |pending_clients_|, |initialized_|, and | 169 // Keeps all MidiPortInfo. |
| 168 // |result_|. | |
| 169 base::Lock lock_; | |
| 170 | |
| 171 MidiPortInfoList input_ports_; | 170 MidiPortInfoList input_ports_; |
| 172 MidiPortInfoList output_ports_; | 171 MidiPortInfoList output_ports_; |
| 173 | 172 |
| 173 // Protects access to |clients_|, |pending_clients_|, |initialized_|, |
| 174 // |result_|, |input_ports_| and |output_ports_|. |
| 175 base::Lock lock_; |
| 176 |
| 174 DISALLOW_COPY_AND_ASSIGN(MidiManager); | 177 DISALLOW_COPY_AND_ASSIGN(MidiManager); |
| 175 }; | 178 }; |
| 176 | 179 |
| 177 } // namespace media | 180 } // namespace media |
| 178 | 181 |
| 179 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ | 182 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ |
| OLD | NEW |