| 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 | 8 |
| 9 namespace media { | 9 namespace media { |
| 10 | 10 |
| 11 #if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(USE_ALSA) && \ | |
| 12 !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | |
| 13 MidiManager* MidiManager::Create() { | |
| 14 return new MidiManager; | |
| 15 } | |
| 16 #endif | |
| 17 | |
| 18 MidiManager::MidiManager() | 11 MidiManager::MidiManager() |
| 19 : initialized_(false), | 12 : initialized_(false), |
| 20 result_(MIDI_NOT_SUPPORTED) { | 13 result_(MIDI_NOT_SUPPORTED) { |
| 21 } | 14 } |
| 22 | 15 |
| 23 MidiManager::~MidiManager() { | 16 MidiManager::~MidiManager() { |
| 24 } | 17 } |
| 25 | 18 |
| 19 #if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(USE_ALSA) && \ |
| 20 !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 21 MidiManager* MidiManager::Create() { |
| 22 return new MidiManager; |
| 23 } |
| 24 #endif |
| 25 |
| 26 void MidiManager::StartSession(MidiManagerClient* client, int client_id) { | 26 void MidiManager::StartSession(MidiManagerClient* client, int client_id) { |
| 27 bool session_is_ready; | 27 bool session_is_ready; |
| 28 bool session_needs_initialization = false; | 28 bool session_needs_initialization = false; |
| 29 bool too_many_pending_clients_exist = false; |
| 29 | 30 |
| 30 { | 31 { |
| 31 base::AutoLock auto_lock(clients_lock_); | 32 base::AutoLock auto_lock(clients_lock_); |
| 32 session_is_ready = initialized_; | 33 session_is_ready = initialized_; |
| 33 if (!session_is_ready) { | 34 if (!session_is_ready) { |
| 34 // Call StartInitialization() only for the first request. | 35 // Return an error if the pending client list contains too many clients. |
| 35 session_needs_initialization = pending_clients_.empty(); | 36 too_many_pending_clients_exist = |
| 36 pending_clients_.insert( | 37 pending_clients_.size() >= kMaxPendingClientCount; |
| 37 std::pair<int, MidiManagerClient*>(client_id, client)); | 38 |
| 39 if (!too_many_pending_clients_exist) { |
| 40 // Call StartInitialization() only for the first request. |
| 41 session_needs_initialization = pending_clients_.empty(); |
| 42 pending_clients_.insert( |
| 43 std::pair<int, MidiManagerClient*>(client_id, client)); |
| 44 } |
| 38 } | 45 } |
| 39 } | 46 } |
| 40 | 47 |
| 41 // Lazily initialize the MIDI back-end. | 48 // Lazily initialize the MIDI back-end. |
| 42 if (!session_is_ready) { | 49 if (!session_is_ready) { |
| 43 if (session_needs_initialization) { | 50 if (session_needs_initialization) { |
| 44 TRACE_EVENT0("midi", "MidiManager::StartInitialization"); | 51 TRACE_EVENT0("midi", "MidiManager::StartInitialization"); |
| 45 StartInitialization(); | 52 StartInitialization(); |
| 46 } | 53 } |
| 54 if (too_many_pending_clients_exist) { |
| 55 client->CompleteStartSession(client_id, MIDI_INITIALIZATION_ERROR); |
| 56 return; |
| 57 } |
| 47 // CompleteInitialization() will be called asynchronously when platform | 58 // CompleteInitialization() will be called asynchronously when platform |
| 48 // dependent initialization is finished. | 59 // dependent initialization is finished. |
| 49 return; | 60 return; |
| 50 } | 61 } |
| 51 | 62 |
| 52 // Platform dependent initialization was already finished for previously | 63 // Platform dependent initialization was already finished for previously |
| 53 // initialized clients. | 64 // initialized clients. |
| 54 MidiResult result; | 65 MidiResult result; |
| 55 { | 66 { |
| 56 base::AutoLock auto_lock(clients_lock_); | 67 base::AutoLock auto_lock(clients_lock_); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 const uint8* data, | 123 const uint8* data, |
| 113 size_t length, | 124 size_t length, |
| 114 double timestamp) { | 125 double timestamp) { |
| 115 base::AutoLock auto_lock(clients_lock_); | 126 base::AutoLock auto_lock(clients_lock_); |
| 116 | 127 |
| 117 for (ClientList::iterator i = clients_.begin(); i != clients_.end(); ++i) | 128 for (ClientList::iterator i = clients_.begin(); i != clients_.end(); ++i) |
| 118 (*i)->ReceiveMidiData(port_index, data, length, timestamp); | 129 (*i)->ReceiveMidiData(port_index, data, length, timestamp); |
| 119 } | 130 } |
| 120 | 131 |
| 121 } // namespace media | 132 } // namespace media |
| OLD | NEW |