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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/histogram_macros.h" | |
| 9 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 10 | 11 |
| 11 namespace media { | 12 namespace media { |
| 12 namespace midi { | 13 namespace midi { |
| 13 | 14 |
| 15 namespace { | |
| 16 const char kMidiResultOnShutdown[] = "Midi.ResultOnShutdown"; | |
| 17 }; // namespace | |
| 18 | |
| 14 MidiManager::MidiManager() | 19 MidiManager::MidiManager() |
| 15 : initialized_(false), | 20 : initialized_(false), result_(Result::NOT_SUPPORTED) { |
|
yhirano
2015/07/07 07:05:21
Perhaps not related with this cl, but should this
Takashi Toyoshima
2015/07/09 05:02:54
Oh, good catch. MidiManager set NOT_SUPPORTED in S
| |
| 16 result_(MIDI_NOT_SUPPORTED) { | |
| 17 } | 21 } |
| 18 | 22 |
| 19 MidiManager::~MidiManager() { | 23 MidiManager::~MidiManager() { |
| 24 UMA_HISTOGRAM_ENUMERATION(kMidiResultOnShutdown, static_cast<int>(result_), | |
| 25 static_cast<int>(Result::MAX)); | |
| 20 } | 26 } |
| 21 | 27 |
| 22 #if !defined(OS_MACOSX) && !defined(OS_WIN) && \ | 28 #if !defined(OS_MACOSX) && !defined(OS_WIN) && \ |
| 23 !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID) | 29 !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID) |
| 24 MidiManager* MidiManager::Create() { | 30 MidiManager* MidiManager::Create() { |
| 25 return new MidiManager; | 31 return new MidiManager; |
| 26 } | 32 } |
| 27 #endif | 33 #endif |
| 28 | 34 |
| 29 void MidiManager::StartSession(MidiManagerClient* client) { | 35 void MidiManager::StartSession(MidiManagerClient* client) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 57 // Lazily initialize the MIDI back-end. | 63 // Lazily initialize the MIDI back-end. |
| 58 if (!session_is_ready) { | 64 if (!session_is_ready) { |
| 59 if (session_needs_initialization) { | 65 if (session_needs_initialization) { |
| 60 TRACE_EVENT0("midi", "MidiManager::StartInitialization"); | 66 TRACE_EVENT0("midi", "MidiManager::StartInitialization"); |
| 61 session_thread_runner_ = | 67 session_thread_runner_ = |
| 62 base::MessageLoop::current()->task_runner(); | 68 base::MessageLoop::current()->task_runner(); |
| 63 StartInitialization(); | 69 StartInitialization(); |
| 64 } | 70 } |
| 65 if (too_many_pending_clients_exist) { | 71 if (too_many_pending_clients_exist) { |
| 66 // Return an error immediately if there are too many requests. | 72 // Return an error immediately if there are too many requests. |
| 67 client->CompleteStartSession(MIDI_INITIALIZATION_ERROR); | 73 client->CompleteStartSession(Result::INITIALIZATION_ERROR); |
| 68 return; | 74 return; |
| 69 } | 75 } |
| 70 // CompleteInitialization() will be called asynchronously when platform | 76 // CompleteInitialization() will be called asynchronously when platform |
| 71 // dependent initialization is finished. | 77 // dependent initialization is finished. |
| 72 return; | 78 return; |
| 73 } | 79 } |
| 74 | 80 |
| 75 // Platform dependent initialization was already finished for previously | 81 // Platform dependent initialization was already finished for previously |
| 76 // initialized clients. | 82 // initialized clients. |
| 77 MidiResult result; | 83 Result result; |
| 78 { | 84 { |
| 79 base::AutoLock auto_lock(lock_); | 85 base::AutoLock auto_lock(lock_); |
| 80 if (result_ == MIDI_OK) { | 86 if (result_ == Result::OK) { |
| 81 AddInitialPorts(client); | 87 AddInitialPorts(client); |
| 82 clients_.insert(client); | 88 clients_.insert(client); |
| 83 } | 89 } |
| 84 result = result_; | 90 result = result_; |
| 85 } | 91 } |
| 86 client->CompleteStartSession(result); | 92 client->CompleteStartSession(result); |
| 87 } | 93 } |
| 88 | 94 |
| 89 void MidiManager::EndSession(MidiManagerClient* client) { | 95 void MidiManager::EndSession(MidiManagerClient* client) { |
| 90 // At this point, |client| can be in the destruction process, and calling | 96 // At this point, |client| can be in the destruction process, and calling |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 104 } | 110 } |
| 105 | 111 |
| 106 void MidiManager::DispatchSendMidiData(MidiManagerClient* client, | 112 void MidiManager::DispatchSendMidiData(MidiManagerClient* client, |
| 107 uint32 port_index, | 113 uint32 port_index, |
| 108 const std::vector<uint8>& data, | 114 const std::vector<uint8>& data, |
| 109 double timestamp) { | 115 double timestamp) { |
| 110 NOTREACHED(); | 116 NOTREACHED(); |
| 111 } | 117 } |
| 112 | 118 |
| 113 void MidiManager::StartInitialization() { | 119 void MidiManager::StartInitialization() { |
| 114 CompleteInitialization(MIDI_NOT_SUPPORTED); | 120 CompleteInitialization(Result::NOT_SUPPORTED); |
| 115 } | 121 } |
| 116 | 122 |
| 117 void MidiManager::CompleteInitialization(MidiResult result) { | 123 void MidiManager::CompleteInitialization(Result result) { |
| 118 DCHECK(session_thread_runner_.get()); | 124 DCHECK(session_thread_runner_.get()); |
| 119 // It is safe to post a task to the IO thread from here because the IO thread | 125 // It is safe to post a task to the IO thread from here because the IO thread |
| 120 // should have stopped if the MidiManager is going to be destructed. | 126 // should have stopped if the MidiManager is going to be destructed. |
| 121 session_thread_runner_->PostTask( | 127 session_thread_runner_->PostTask( |
| 122 FROM_HERE, | 128 FROM_HERE, |
| 123 base::Bind(&MidiManager::CompleteInitializationInternal, | 129 base::Bind(&MidiManager::CompleteInitializationInternal, |
| 124 base::Unretained(this), | 130 base::Unretained(this), |
| 125 result)); | 131 result)); |
| 126 } | 132 } |
| 127 | 133 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 uint32 port_index, | 165 uint32 port_index, |
| 160 const uint8* data, | 166 const uint8* data, |
| 161 size_t length, | 167 size_t length, |
| 162 double timestamp) { | 168 double timestamp) { |
| 163 base::AutoLock auto_lock(lock_); | 169 base::AutoLock auto_lock(lock_); |
| 164 | 170 |
| 165 for (auto client : clients_) | 171 for (auto client : clients_) |
| 166 client->ReceiveMidiData(port_index, data, length, timestamp); | 172 client->ReceiveMidiData(port_index, data, length, timestamp); |
| 167 } | 173 } |
| 168 | 174 |
| 169 void MidiManager::CompleteInitializationInternal(MidiResult result) { | 175 void MidiManager::CompleteInitializationInternal(Result result) { |
| 170 TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); | 176 TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); |
| 171 | 177 |
| 172 base::AutoLock auto_lock(lock_); | 178 base::AutoLock auto_lock(lock_); |
| 173 DCHECK(clients_.empty()); | 179 DCHECK(clients_.empty()); |
| 174 DCHECK(!initialized_); | 180 DCHECK(!initialized_); |
| 175 initialized_ = true; | 181 initialized_ = true; |
| 176 result_ = result; | 182 result_ = result; |
| 177 | 183 |
| 178 for (auto client : pending_clients_) { | 184 for (auto client : pending_clients_) { |
| 179 if (result_ == MIDI_OK) { | 185 if (result_ == Result::OK) { |
| 180 AddInitialPorts(client); | 186 AddInitialPorts(client); |
| 181 clients_.insert(client); | 187 clients_.insert(client); |
| 182 } | 188 } |
| 183 client->CompleteStartSession(result_); | 189 client->CompleteStartSession(result_); |
| 184 } | 190 } |
| 185 pending_clients_.clear(); | 191 pending_clients_.clear(); |
| 186 } | 192 } |
| 187 | 193 |
| 188 void MidiManager::AddInitialPorts(MidiManagerClient* client) { | 194 void MidiManager::AddInitialPorts(MidiManagerClient* client) { |
| 189 lock_.AssertAcquired(); | 195 lock_.AssertAcquired(); |
| 190 | 196 |
| 191 for (const auto& info : input_ports_) | 197 for (const auto& info : input_ports_) |
| 192 client->AddInputPort(info); | 198 client->AddInputPort(info); |
| 193 for (const auto& info : output_ports_) | 199 for (const auto& info : output_ports_) |
| 194 client->AddOutputPort(info); | 200 client->AddOutputPort(info); |
| 195 } | 201 } |
| 196 | 202 |
| 197 } // namespace midi | 203 } // namespace midi |
| 198 } // namespace media | 204 } // namespace media |
| OLD | NEW |