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