| 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_mac.h" | 5 #include "media/midi/midi_manager_mac.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 157 |
| 158 void MidiManagerMac::InitializeCoreMIDI() { | 158 void MidiManagerMac::InitializeCoreMIDI() { |
| 159 DCHECK(client_thread_.task_runner()->BelongsToCurrentThread()); | 159 DCHECK(client_thread_.task_runner()->BelongsToCurrentThread()); |
| 160 | 160 |
| 161 // CoreMIDI registration. | 161 // CoreMIDI registration. |
| 162 DCHECK_EQ(0u, midi_client_); | 162 DCHECK_EQ(0u, midi_client_); |
| 163 OSStatus result = | 163 OSStatus result = |
| 164 MIDIClientCreate(CFSTR("Chrome"), ReceiveMidiNotifyDispatch, this, | 164 MIDIClientCreate(CFSTR("Chrome"), ReceiveMidiNotifyDispatch, this, |
| 165 &midi_client_); | 165 &midi_client_); |
| 166 if (result != noErr || midi_client_ == 0) | 166 if (result != noErr || midi_client_ == 0) |
| 167 return CompleteInitialization(Result::INITIALIZATION_ERROR); | 167 return CompleteInitialization(mojom::Result::INITIALIZATION_ERROR); |
| 168 | 168 |
| 169 // Create input and output port. | 169 // Create input and output port. |
| 170 DCHECK_EQ(0u, coremidi_input_); | 170 DCHECK_EQ(0u, coremidi_input_); |
| 171 result = MIDIInputPortCreate( | 171 result = MIDIInputPortCreate( |
| 172 midi_client_, | 172 midi_client_, |
| 173 CFSTR("MIDI Input"), | 173 CFSTR("MIDI Input"), |
| 174 ReadMidiDispatch, | 174 ReadMidiDispatch, |
| 175 this, | 175 this, |
| 176 &coremidi_input_); | 176 &coremidi_input_); |
| 177 if (result != noErr || coremidi_input_ == 0) | 177 if (result != noErr || coremidi_input_ == 0) |
| 178 return CompleteInitialization(Result::INITIALIZATION_ERROR); | 178 return CompleteInitialization(mojom::Result::INITIALIZATION_ERROR); |
| 179 | 179 |
| 180 DCHECK_EQ(0u, coremidi_output_); | 180 DCHECK_EQ(0u, coremidi_output_); |
| 181 result = MIDIOutputPortCreate( | 181 result = MIDIOutputPortCreate( |
| 182 midi_client_, | 182 midi_client_, |
| 183 CFSTR("MIDI Output"), | 183 CFSTR("MIDI Output"), |
| 184 &coremidi_output_); | 184 &coremidi_output_); |
| 185 if (result != noErr || coremidi_output_ == 0) | 185 if (result != noErr || coremidi_output_ == 0) |
| 186 return CompleteInitialization(Result::INITIALIZATION_ERROR); | 186 return CompleteInitialization(mojom::Result::INITIALIZATION_ERROR); |
| 187 | 187 |
| 188 // Following loop may miss some newly attached devices, but such device will | 188 // Following loop may miss some newly attached devices, but such device will |
| 189 // be captured by ReceiveMidiNotifyDispatch callback. | 189 // be captured by ReceiveMidiNotifyDispatch callback. |
| 190 uint32_t destination_count = MIDIGetNumberOfDestinations(); | 190 uint32_t destination_count = MIDIGetNumberOfDestinations(); |
| 191 destinations_.resize(destination_count); | 191 destinations_.resize(destination_count); |
| 192 for (uint32_t i = 0; i < destination_count; i++) { | 192 for (uint32_t i = 0; i < destination_count; i++) { |
| 193 MIDIEndpointRef destination = MIDIGetDestination(i); | 193 MIDIEndpointRef destination = MIDIGetDestination(i); |
| 194 if (destination == 0) { | 194 if (destination == 0) { |
| 195 // One ore more devices may be detached. | 195 // One ore more devices may be detached. |
| 196 destinations_.resize(i); | 196 destinations_.resize(i); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 220 // Keep track of all sources (known as inputs in Web MIDI API terminology). | 220 // Keep track of all sources (known as inputs in Web MIDI API terminology). |
| 221 source_map_[source] = i; | 221 source_map_[source] = i; |
| 222 | 222 |
| 223 MidiPortInfo info = GetPortInfoFromEndpoint(source); | 223 MidiPortInfo info = GetPortInfoFromEndpoint(source); |
| 224 AddInputPort(info); | 224 AddInputPort(info); |
| 225 } | 225 } |
| 226 | 226 |
| 227 // Allocate maximum size of buffer that CoreMIDI can handle. | 227 // Allocate maximum size of buffer that CoreMIDI can handle. |
| 228 midi_buffer_.resize(kCoreMIDIMaxPacketListSize); | 228 midi_buffer_.resize(kCoreMIDIMaxPacketListSize); |
| 229 | 229 |
| 230 CompleteInitialization(Result::OK); | 230 CompleteInitialization(mojom::Result::OK); |
| 231 } | 231 } |
| 232 | 232 |
| 233 // static | 233 // static |
| 234 void MidiManagerMac::ReceiveMidiNotifyDispatch(const MIDINotification* message, | 234 void MidiManagerMac::ReceiveMidiNotifyDispatch(const MIDINotification* message, |
| 235 void* refcon) { | 235 void* refcon) { |
| 236 // This callback function is invoked on |client_thread_|. | 236 // This callback function is invoked on |client_thread_|. |
| 237 MidiManagerMac* manager = static_cast<MidiManagerMac*>(refcon); | 237 MidiManagerMac* manager = static_cast<MidiManagerMac*>(refcon); |
| 238 manager->ReceiveMidiNotify(message); | 238 manager->ReceiveMidiNotify(message); |
| 239 } | 239 } |
| 240 | 240 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 &data[sent_size]); | 379 &data[sent_size]); |
| 380 DCHECK(midi_packet); | 380 DCHECK(midi_packet); |
| 381 | 381 |
| 382 MIDISend(coremidi_output_, destination, packet_list); | 382 MIDISend(coremidi_output_, destination, packet_list); |
| 383 } | 383 } |
| 384 | 384 |
| 385 AccumulateMidiBytesSent(client, data.size()); | 385 AccumulateMidiBytesSent(client, data.size()); |
| 386 } | 386 } |
| 387 | 387 |
| 388 } // namespace midi | 388 } // namespace midi |
| OLD | NEW |