Chromium Code Reviews| 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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "media/midi/midi_message_queue.h" | |
| 11 | 12 |
| 12 namespace media { | 13 namespace media { |
| 13 | 14 |
| 14 #if !defined(OS_MACOSX) | 15 #if !defined(OS_MACOSX) |
| 15 // TODO(crogers): implement MIDIManager for other platforms. | 16 // TODO(crogers): implement MIDIManager for other platforms. |
| 16 MIDIManager* MIDIManager::Create() { | 17 MIDIManager* MIDIManager::Create() { |
| 17 return NULL; | 18 return NULL; |
| 18 } | 19 } |
| 19 #endif | 20 #endif |
| 20 | 21 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 39 | 40 |
| 40 void MIDIManager::EndSession(MIDIManagerClient* client) { | 41 void MIDIManager::EndSession(MIDIManagerClient* client) { |
| 41 base::AutoLock auto_lock(clients_lock_); | 42 base::AutoLock auto_lock(clients_lock_); |
| 42 ClientList::iterator i = clients_.find(client); | 43 ClientList::iterator i = clients_.find(client); |
| 43 if (i != clients_.end()) | 44 if (i != clients_.end()) |
| 44 clients_.erase(i); | 45 clients_.erase(i); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void MIDIManager::AddInputPort(const MIDIPortInfo& info) { | 48 void MIDIManager::AddInputPort(const MIDIPortInfo& info) { |
| 48 input_ports_.push_back(info); | 49 input_ports_.push_back(info); |
| 50 input_message_queues_.push_back(new MIDIMessageQueue(true)); | |
| 49 } | 51 } |
| 50 | 52 |
| 51 void MIDIManager::AddOutputPort(const MIDIPortInfo& info) { | 53 void MIDIManager::AddOutputPort(const MIDIPortInfo& info) { |
| 52 output_ports_.push_back(info); | 54 output_ports_.push_back(info); |
| 53 } | 55 } |
| 54 | 56 |
| 55 void MIDIManager::ReceiveMIDIData( | 57 void MIDIManager::ReceiveMIDIData( |
| 56 uint32 port_index, | 58 uint32 port_index, |
| 57 const uint8* data, | 59 const uint8* data, |
| 58 size_t length, | 60 size_t length, |
| 59 double timestamp) { | 61 double timestamp) { |
| 60 base::AutoLock auto_lock(clients_lock_); | 62 base::AutoLock auto_lock(clients_lock_); |
| 61 | 63 |
|
Takashi Toyoshima
2013/11/12 21:59:36
This message queue introduces two additional memor
yukawa
2013/11/14 14:55:31
Thank you for the suggestion. I moved MIDIMessageQ
| |
| 62 for (ClientList::iterator i = clients_.begin(); i != clients_.end(); ++i) | 64 input_message_queues_[port_index]->Add(data, length); |
| 63 (*i)->ReceiveMIDIData(port_index, data, length, timestamp); | 65 std::vector<uint8> message; |
| 66 while (true) { | |
| 67 input_message_queues_[port_index]->Get(&message); | |
| 68 if (message.empty()) | |
| 69 return; | |
| 70 for (ClientList::iterator i = clients_.begin(); i != clients_.end(); ++i) | |
| 71 (*i)->ReceiveMIDIData(port_index, &message[0], message.size(), timestamp); | |
| 72 } | |
| 64 } | 73 } |
| 65 | 74 |
| 66 bool MIDIManager::CurrentlyOnMIDISendThread() { | 75 bool MIDIManager::CurrentlyOnMIDISendThread() { |
| 67 return send_thread_->message_loop() == base::MessageLoop::current(); | 76 return send_thread_->message_loop() == base::MessageLoop::current(); |
| 68 } | 77 } |
| 69 | 78 |
| 70 void MIDIManager::DispatchSendMIDIData(MIDIManagerClient* client, | 79 void MIDIManager::DispatchSendMIDIData(MIDIManagerClient* client, |
| 71 uint32 port_index, | 80 uint32 port_index, |
| 72 const std::vector<uint8>& data, | 81 const std::vector<uint8>& data, |
| 73 double timestamp) { | 82 double timestamp) { |
| 74 // Lazily create the thread when first needed. | 83 // Lazily create the thread when first needed. |
| 75 if (!send_thread_) { | 84 if (!send_thread_) { |
| 76 send_thread_.reset(new base::Thread("MIDISendThread")); | 85 send_thread_.reset(new base::Thread("MIDISendThread")); |
| 77 send_thread_->Start(); | 86 send_thread_->Start(); |
| 78 send_message_loop_ = send_thread_->message_loop_proxy(); | 87 send_message_loop_ = send_thread_->message_loop_proxy(); |
| 79 } | 88 } |
| 80 | 89 |
| 81 send_message_loop_->PostTask( | 90 send_message_loop_->PostTask( |
| 82 FROM_HERE, | 91 FROM_HERE, |
| 83 base::Bind(&MIDIManager::SendMIDIData, base::Unretained(this), | 92 base::Bind(&MIDIManager::SendMIDIData, base::Unretained(this), |
| 84 client, port_index, data, timestamp)); | 93 client, port_index, data, timestamp)); |
| 85 } | 94 } |
| 86 | 95 |
| 87 } // namespace media | 96 } // namespace media |
| OLD | NEW |