| 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 #include "media/midi/midi_manager.h" | 5 #include "media/midi/midi_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // CompleteInitialization() will be called asynchronously when platform | 70 // CompleteInitialization() will be called asynchronously when platform |
| 71 // dependent initialization is finished. | 71 // dependent initialization is finished. |
| 72 return; | 72 return; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Platform dependent initialization was already finished for previously | 75 // Platform dependent initialization was already finished for previously |
| 76 // initialized clients. | 76 // initialized clients. |
| 77 MidiResult result; | 77 MidiResult result; |
| 78 { | 78 { |
| 79 base::AutoLock auto_lock(lock_); | 79 base::AutoLock auto_lock(lock_); |
| 80 if (result_ == MIDI_OK) | 80 if (result_ == MIDI_OK) { |
| 81 AddInitialPorts(client); |
| 81 clients_.insert(client); | 82 clients_.insert(client); |
| 83 } |
| 82 result = result_; | 84 result = result_; |
| 83 } | 85 } |
| 84 client->CompleteStartSession(result); | 86 client->CompleteStartSession(result); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void MidiManager::EndSession(MidiManagerClient* client) { | 89 void MidiManager::EndSession(MidiManagerClient* client) { |
| 88 base::AutoLock auto_lock(lock_); | 90 base::AutoLock auto_lock(lock_); |
| 89 clients_.erase(client); | 91 clients_.erase(client); |
| 90 pending_clients_.erase(client); | 92 pending_clients_.erase(client); |
| 91 } | 93 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 106 // It is safe to post a task to the IO thread from here because the IO thread | 108 // It is safe to post a task to the IO thread from here because the IO thread |
| 107 // should have stopped if the MidiManager is going to be destructed. | 109 // should have stopped if the MidiManager is going to be destructed. |
| 108 session_thread_runner_->PostTask( | 110 session_thread_runner_->PostTask( |
| 109 FROM_HERE, | 111 FROM_HERE, |
| 110 base::Bind(&MidiManager::CompleteInitializationInternal, | 112 base::Bind(&MidiManager::CompleteInitializationInternal, |
| 111 base::Unretained(this), | 113 base::Unretained(this), |
| 112 result)); | 114 result)); |
| 113 } | 115 } |
| 114 | 116 |
| 115 void MidiManager::AddInputPort(const MidiPortInfo& info) { | 117 void MidiManager::AddInputPort(const MidiPortInfo& info) { |
| 118 base::AutoLock auto_lock(lock_); |
| 116 input_ports_.push_back(info); | 119 input_ports_.push_back(info); |
| 120 for (ClientSet::iterator it = clients_.begin(); it != clients_.end(); ++it) |
| 121 (*it)->AddInputPort(info); |
| 117 } | 122 } |
| 118 | 123 |
| 119 void MidiManager::AddOutputPort(const MidiPortInfo& info) { | 124 void MidiManager::AddOutputPort(const MidiPortInfo& info) { |
| 125 base::AutoLock auto_lock(lock_); |
| 120 output_ports_.push_back(info); | 126 output_ports_.push_back(info); |
| 127 for (ClientSet::iterator it = clients_.begin(); it != clients_.end(); ++it) |
| 128 (*it)->AddOutputPort(info); |
| 121 } | 129 } |
| 122 | 130 |
| 123 void MidiManager::ReceiveMidiData( | 131 void MidiManager::ReceiveMidiData( |
| 124 uint32 port_index, | 132 uint32 port_index, |
| 125 const uint8* data, | 133 const uint8* data, |
| 126 size_t length, | 134 size_t length, |
| 127 double timestamp) { | 135 double timestamp) { |
| 128 base::AutoLock auto_lock(lock_); | 136 base::AutoLock auto_lock(lock_); |
| 129 | 137 |
| 130 for (MidiManagerClient* client : clients_) | 138 for (MidiManagerClient* client : clients_) |
| 131 client->ReceiveMidiData(port_index, data, length, timestamp); | 139 client->ReceiveMidiData(port_index, data, length, timestamp); |
| 132 } | 140 } |
| 133 | 141 |
| 134 void MidiManager::CompleteInitializationInternal(MidiResult result) { | 142 void MidiManager::CompleteInitializationInternal(MidiResult result) { |
| 135 TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); | 143 TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); |
| 136 | 144 |
| 137 base::AutoLock auto_lock(lock_); | 145 base::AutoLock auto_lock(lock_); |
| 138 DCHECK(clients_.empty()); | 146 DCHECK(clients_.empty()); |
| 139 DCHECK(!initialized_); | 147 DCHECK(!initialized_); |
| 140 initialized_ = true; | 148 initialized_ = true; |
| 141 result_ = result; | 149 result_ = result; |
| 142 | 150 |
| 143 for (MidiManagerClient* client : pending_clients_) { | 151 for (MidiManagerClient* client : pending_clients_) { |
| 144 if (result_ == MIDI_OK) | 152 if (result_ == MIDI_OK) { |
| 153 AddInitialPorts(client); |
| 145 clients_.insert(client); | 154 clients_.insert(client); |
| 155 } |
| 146 client->CompleteStartSession(result_); | 156 client->CompleteStartSession(result_); |
| 147 } | 157 } |
| 148 pending_clients_.clear(); | 158 pending_clients_.clear(); |
| 149 } | 159 } |
| 150 | 160 |
| 161 void MidiManager::AddInitialPorts(MidiManagerClient* client) { |
| 162 lock_.AssertAcquired(); |
| 163 |
| 164 for (MidiPortInfoList::iterator it = input_ports_.begin(); |
| 165 it != input_ports_.end(); ++it) { |
| 166 client->AddInputPort(*it); |
| 167 } |
| 168 for (MidiPortInfoList::iterator it = output_ports_.begin(); |
| 169 it != output_ports_.end(); ++it) { |
| 170 client->AddOutputPort(*it); |
| 171 } |
| 172 } |
| 173 |
| 151 } // namespace media | 174 } // namespace media |
| OLD | NEW |