| 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 |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 13 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 14 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 15 #include "media/midi/midi_export.h" | 14 #include "media/midi/midi_export.h" |
| 16 #include "media/midi/midi_port_info.h" | 15 #include "media/midi/midi_port_info.h" |
| 17 #include "media/midi/result.h" | 16 #include "media/midi/result.h" |
| 18 | 17 |
| 19 namespace base { | 18 namespace base { |
| 20 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
| 21 } // namespace base | 20 } // namespace base |
| 22 | 21 |
| 23 namespace media { | 22 namespace media { |
| 24 namespace midi { | 23 namespace midi { |
| 25 | 24 |
| 26 // A MidiManagerClient registers with the MidiManager to receive MIDI data. | 25 // A MidiManagerClient registers with the MidiManager to receive MIDI data. |
| 27 // See MidiManager::RequestAccess() and MidiManager::ReleaseAccess() | 26 // See MidiManager::RequestAccess() and MidiManager::ReleaseAccess() |
| 28 // for details. | 27 // for details. |
| 29 class MIDI_EXPORT MidiManagerClient { | 28 class MIDI_EXPORT MidiManagerClient { |
| 30 public: | 29 public: |
| 31 virtual ~MidiManagerClient() {} | 30 virtual ~MidiManagerClient() {} |
| 32 | 31 |
| 33 // AddInputPort() and AddOutputPort() are called before CompleteStartSession() | 32 // AddInputPort() and AddOutputPort() are called before CompleteStartSession() |
| 34 // is called to notify existing MIDI ports, and also called after that to | 33 // is called to notify existing MIDI ports, and also called after that to |
| 35 // notify new MIDI ports are added. | 34 // notify new MIDI ports are added. |
| 36 virtual void AddInputPort(const MidiPortInfo& info) = 0; | 35 virtual void AddInputPort(const MidiPortInfo& info) = 0; |
| 37 virtual void AddOutputPort(const MidiPortInfo& info) = 0; | 36 virtual void AddOutputPort(const MidiPortInfo& info) = 0; |
| 38 | 37 |
| 39 // SetInputPortState() and SetOutputPortState() are called to notify a known | 38 // SetInputPortState() and SetOutputPortState() are called to notify a known |
| 40 // device gets disconnected, or connected again. | 39 // device gets disconnected, or connected again. |
| 41 virtual void SetInputPortState(uint32 port_index, MidiPortState state) = 0; | 40 virtual void SetInputPortState(uint32_t port_index, MidiPortState state) = 0; |
| 42 virtual void SetOutputPortState(uint32 port_index, MidiPortState state) = 0; | 41 virtual void SetOutputPortState(uint32_t port_index, MidiPortState state) = 0; |
| 43 | 42 |
| 44 // CompleteStartSession() is called when platform dependent preparation is | 43 // CompleteStartSession() is called when platform dependent preparation is |
| 45 // finished. | 44 // finished. |
| 46 virtual void CompleteStartSession(Result result) = 0; | 45 virtual void CompleteStartSession(Result result) = 0; |
| 47 | 46 |
| 48 // ReceiveMidiData() is called when MIDI data has been received from the | 47 // ReceiveMidiData() is called when MIDI data has been received from the |
| 49 // MIDI system. | 48 // MIDI system. |
| 50 // |port_index| represents the specific input port from input_ports(). | 49 // |port_index| represents the specific input port from input_ports(). |
| 51 // |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. |
| 52 // |length| is the number of bytes in |data|. | 51 // |length| is the number of bytes in |data|. |
| 53 // |timestamp| is the time the data was received, in seconds. | 52 // |timestamp| is the time the data was received, in seconds. |
| 54 virtual void ReceiveMidiData(uint32 port_index, | 53 virtual void ReceiveMidiData(uint32_t port_index, |
| 55 const uint8* data, | 54 const uint8_t* data, |
| 56 size_t length, | 55 size_t length, |
| 57 double timestamp) = 0; | 56 double timestamp) = 0; |
| 58 | 57 |
| 59 // AccumulateMidiBytesSent() is called to acknowledge when bytes have | 58 // AccumulateMidiBytesSent() is called to acknowledge when bytes have |
| 60 // successfully been sent to the hardware. | 59 // successfully been sent to the hardware. |
| 61 // This happens as a result of the client having previously called | 60 // This happens as a result of the client having previously called |
| 62 // MidiManager::DispatchSendMidiData(). | 61 // MidiManager::DispatchSendMidiData(). |
| 63 virtual void AccumulateMidiBytesSent(size_t n) = 0; | 62 virtual void AccumulateMidiBytesSent(size_t n) = 0; |
| 64 | 63 |
| 65 // Detach() is called when MidiManager is going to shutdown immediately. | 64 // Detach() is called when MidiManager is going to shutdown immediately. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // DispatchSendMidiData() is called when MIDI data should be sent to the MIDI | 101 // DispatchSendMidiData() is called when MIDI data should be sent to the MIDI |
| 103 // system. | 102 // system. |
| 104 // This method is supposed to return immediately and should not block. | 103 // This method is supposed to return immediately and should not block. |
| 105 // |port_index| represents the specific output port from output_ports(). | 104 // |port_index| represents the specific output port from output_ports(). |
| 106 // |data| represents a series of bytes encoding one or more MIDI messages. | 105 // |data| represents a series of bytes encoding one or more MIDI messages. |
| 107 // |length| is the number of bytes in |data|. | 106 // |length| is the number of bytes in |data|. |
| 108 // |timestamp| is the time to send the data, in seconds. A value of 0 | 107 // |timestamp| is the time to send the data, in seconds. A value of 0 |
| 109 // means send "now" or as soon as possible. | 108 // means send "now" or as soon as possible. |
| 110 // The default implementation is for unsupported platforms. | 109 // The default implementation is for unsupported platforms. |
| 111 virtual void DispatchSendMidiData(MidiManagerClient* client, | 110 virtual void DispatchSendMidiData(MidiManagerClient* client, |
| 112 uint32 port_index, | 111 uint32_t port_index, |
| 113 const std::vector<uint8>& data, | 112 const std::vector<uint8_t>& data, |
| 114 double timestamp); | 113 double timestamp); |
| 115 | 114 |
| 116 protected: | 115 protected: |
| 117 friend class MidiManagerUsb; | 116 friend class MidiManagerUsb; |
| 118 | 117 |
| 119 // Initializes the platform dependent MIDI system. MidiManager class has a | 118 // Initializes the platform dependent MIDI system. MidiManager class has a |
| 120 // default implementation that synchronously calls CompleteInitialization() | 119 // default implementation that synchronously calls CompleteInitialization() |
| 121 // with Result::NOT_SUPPORTED on the caller thread. A derived class for a | 120 // with Result::NOT_SUPPORTED on the caller thread. A derived class for a |
| 122 // specific platform should override this method correctly. | 121 // specific platform should override this method correctly. |
| 123 // This method is called on Chrome_IOThread thread inside StartSession(). | 122 // This method is called on Chrome_IOThread thread inside StartSession(). |
| (...skipping 10 matching lines...) Expand all Loading... |
| 134 virtual void Finalize() {} | 133 virtual void Finalize() {} |
| 135 | 134 |
| 136 // Called from a platform dependent implementation of StartInitialization(). | 135 // Called from a platform dependent implementation of StartInitialization(). |
| 137 // It invokes CompleteInitializationInternal() on the thread that calls | 136 // It invokes CompleteInitializationInternal() on the thread that calls |
| 138 // StartSession() and distributes |result| to MIDIManagerClient objects in | 137 // StartSession() and distributes |result| to MIDIManagerClient objects in |
| 139 // |pending_clients_|. | 138 // |pending_clients_|. |
| 140 void CompleteInitialization(Result result); | 139 void CompleteInitialization(Result result); |
| 141 | 140 |
| 142 void AddInputPort(const MidiPortInfo& info); | 141 void AddInputPort(const MidiPortInfo& info); |
| 143 void AddOutputPort(const MidiPortInfo& info); | 142 void AddOutputPort(const MidiPortInfo& info); |
| 144 void SetInputPortState(uint32 port_index, MidiPortState state); | 143 void SetInputPortState(uint32_t port_index, MidiPortState state); |
| 145 void SetOutputPortState(uint32 port_index, MidiPortState state); | 144 void SetOutputPortState(uint32_t port_index, MidiPortState state); |
| 146 | 145 |
| 147 // Dispatches to all clients. | 146 // Dispatches to all clients. |
| 148 // TODO(toyoshim): Fix the mac implementation to use | 147 // TODO(toyoshim): Fix the mac implementation to use |
| 149 // |ReceiveMidiData(..., base::TimeTicks)|. | 148 // |ReceiveMidiData(..., base::TimeTicks)|. |
| 150 void ReceiveMidiData(uint32 port_index, | 149 void ReceiveMidiData(uint32_t port_index, |
| 151 const uint8* data, | 150 const uint8_t* data, |
| 152 size_t length, | 151 size_t length, |
| 153 double timestamp); | 152 double timestamp); |
| 154 | 153 |
| 155 void ReceiveMidiData(uint32 port_index, | 154 void ReceiveMidiData(uint32_t port_index, |
| 156 const uint8* data, | 155 const uint8_t* data, |
| 157 size_t length, | 156 size_t length, |
| 158 base::TimeTicks time) { | 157 base::TimeTicks time) { |
| 159 ReceiveMidiData(port_index, data, length, | 158 ReceiveMidiData(port_index, data, length, |
| 160 (time - base::TimeTicks()).InSecondsF()); | 159 (time - base::TimeTicks()).InSecondsF()); |
| 161 } | 160 } |
| 162 | 161 |
| 163 size_t clients_size_for_testing() const { return clients_.size(); } | 162 size_t clients_size_for_testing() const { return clients_.size(); } |
| 164 size_t pending_clients_size_for_testing() const { | 163 size_t pending_clients_size_for_testing() const { |
| 165 return pending_clients_.size(); | 164 return pending_clients_.size(); |
| 166 } | 165 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // |input_ports_| and |output_ports_|. | 202 // |input_ports_| and |output_ports_|. |
| 204 base::Lock lock_; | 203 base::Lock lock_; |
| 205 | 204 |
| 206 DISALLOW_COPY_AND_ASSIGN(MidiManager); | 205 DISALLOW_COPY_AND_ASSIGN(MidiManager); |
| 207 }; | 206 }; |
| 208 | 207 |
| 209 } // namespace midi | 208 } // namespace midi |
| 210 } // namespace media | 209 } // namespace media |
| 211 | 210 |
| 212 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ | 211 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ |
| OLD | NEW |