| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_win.h" | 5 #include "media/midi/midi_manager_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 // Prevent unnecessary functions from being included from <mmsystem.h> | 9 // Prevent unnecessary functions from being included from <mmsystem.h> |
| 10 #define MMNODRV | 10 #define MMNODRV |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 DISALLOW_COPY_AND_ASSIGN(OutDeviceInfo); | 492 DISALLOW_COPY_AND_ASSIGN(OutDeviceInfo); |
| 493 }; | 493 }; |
| 494 | 494 |
| 495 MidiManagerWin::MidiManagerWin() | 495 MidiManagerWin::MidiManagerWin() |
| 496 : send_thread_("MidiSendThread") { | 496 : send_thread_("MidiSendThread") { |
| 497 } | 497 } |
| 498 | 498 |
| 499 void MidiManagerWin::StartInitialization() { | 499 void MidiManagerWin::StartInitialization() { |
| 500 const UINT num_in_devices = midiInGetNumDevs(); | 500 const UINT num_in_devices = midiInGetNumDevs(); |
| 501 in_devices_.reserve(num_in_devices); | 501 in_devices_.reserve(num_in_devices); |
| 502 int inport_index = 0; |
| 502 for (UINT device_id = 0; device_id < num_in_devices; ++device_id) { | 503 for (UINT device_id = 0; device_id < num_in_devices; ++device_id) { |
| 503 MIDIINCAPS caps = {}; | 504 MIDIINCAPS caps = {}; |
| 504 MMRESULT result = midiInGetDevCaps(device_id, &caps, sizeof(caps)); | 505 MMRESULT result = midiInGetDevCaps(device_id, &caps, sizeof(caps)); |
| 505 if (result != MMSYSERR_NOERROR) { | 506 if (result != MMSYSERR_NOERROR) { |
| 506 DLOG(ERROR) << "Failed to obtain input device info: " | 507 DLOG(ERROR) << "Failed to obtain input device info: " |
| 507 << GetInErrorMessage(result); | 508 << GetInErrorMessage(result); |
| 508 continue; | 509 continue; |
| 509 } | 510 } |
| 510 scoped_ptr<InDeviceInfo> in_device(InDeviceInfo::Create(this, device_id)); | 511 scoped_ptr<InDeviceInfo> in_device(InDeviceInfo::Create(this, device_id)); |
| 511 if (!in_device) | 512 if (!in_device) |
| 512 continue; | 513 continue; |
| 513 MidiPortInfo info( | 514 MidiPortInfo info( |
| 514 base::IntToString(static_cast<int>(device_id)), | 515 base::IntToString(static_cast<int>(device_id)), |
| 515 "", | 516 "", |
| 516 base::WideToUTF8(caps.szPname), | 517 base::WideToUTF8(caps.szPname), |
| 517 base::IntToString(static_cast<int>(caps.vDriverVersion))); | 518 base::IntToString(static_cast<int>(caps.vDriverVersion))); |
| 518 AddInputPort(info); | 519 AddInputPort(info); |
| 519 in_device->set_port_index(input_ports().size() - 1); | 520 in_device->set_port_index(inport_index++); |
| 520 in_devices_.push_back(in_device.Pass()); | 521 in_devices_.push_back(in_device.Pass()); |
| 521 } | 522 } |
| 522 | 523 |
| 523 const UINT num_out_devices = midiOutGetNumDevs(); | 524 const UINT num_out_devices = midiOutGetNumDevs(); |
| 524 out_devices_.reserve(num_out_devices); | 525 out_devices_.reserve(num_out_devices); |
| 525 for (UINT device_id = 0; device_id < num_out_devices; ++device_id) { | 526 for (UINT device_id = 0; device_id < num_out_devices; ++device_id) { |
| 526 MIDIOUTCAPS caps = {}; | 527 MIDIOUTCAPS caps = {}; |
| 527 MMRESULT result = midiOutGetDevCaps(device_id, &caps, sizeof(caps)); | 528 MMRESULT result = midiOutGetDevCaps(device_id, &caps, sizeof(caps)); |
| 528 if (result != MMSYSERR_NOERROR) { | 529 if (result != MMSYSERR_NOERROR) { |
| 529 DLOG(ERROR) << "Failed to obtain output device info: " | 530 DLOG(ERROR) << "Failed to obtain output device info: " |
| (...skipping 11 matching lines...) Expand all Loading... |
| 541 AddOutputPort(info); | 542 AddOutputPort(info); |
| 542 out_devices_.push_back(out_port.Pass()); | 543 out_devices_.push_back(out_port.Pass()); |
| 543 } | 544 } |
| 544 | 545 |
| 545 CompleteInitialization(MIDI_OK); | 546 CompleteInitialization(MIDI_OK); |
| 546 } | 547 } |
| 547 | 548 |
| 548 MidiManagerWin::~MidiManagerWin() { | 549 MidiManagerWin::~MidiManagerWin() { |
| 549 // Cleanup order is important. |send_thread_| must be stopped before | 550 // Cleanup order is important. |send_thread_| must be stopped before |
| 550 // |out_devices_| is cleared. | 551 // |out_devices_| is cleared. |
| 551 for (size_t i = 0; i < output_ports().size(); ++i) | 552 for (auto& device : out_devices_) |
| 552 out_devices_[i]->Quit(); | 553 device->Quit(); |
| 553 send_thread_.Stop(); | 554 send_thread_.Stop(); |
| 554 | 555 |
| 555 out_devices_.clear(); | 556 out_devices_.clear(); |
| 556 in_devices_.clear(); | 557 in_devices_.clear(); |
| 557 } | 558 } |
| 558 | 559 |
| 559 void MidiManagerWin::DispatchSendMidiData(MidiManagerClient* client, | 560 void MidiManagerWin::DispatchSendMidiData(MidiManagerClient* client, |
| 560 uint32 port_index, | 561 uint32 port_index, |
| 561 const std::vector<uint8>& data, | 562 const std::vector<uint8>& data, |
| 562 double timestamp) { | 563 double timestamp) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 588 FROM_HERE, | 589 FROM_HERE, |
| 589 base::Bind(&MidiManagerClient::AccumulateMidiBytesSent, | 590 base::Bind(&MidiManagerClient::AccumulateMidiBytesSent, |
| 590 base::Unretained(client), data.size())); | 591 base::Unretained(client), data.size())); |
| 591 } | 592 } |
| 592 | 593 |
| 593 MidiManager* MidiManager::Create() { | 594 MidiManager* MidiManager::Create() { |
| 594 return new MidiManagerWin(); | 595 return new MidiManagerWin(); |
| 595 } | 596 } |
| 596 | 597 |
| 597 } // namespace media | 598 } // namespace media |
| OLD | NEW |