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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 scoped_ptr<InDeviceInfo> in_device(InDeviceInfo::Create(this, device_id)); | 511 scoped_ptr<InDeviceInfo> in_device(InDeviceInfo::Create(this, device_id)); |
512 if (!in_device) | 512 if (!in_device) |
513 continue; | 513 continue; |
514 MidiPortInfo info( | 514 MidiPortInfo info( |
515 base::IntToString(static_cast<int>(device_id)), | 515 base::IntToString(static_cast<int>(device_id)), |
516 "", | 516 "", |
517 base::WideToUTF8(caps.szPname), | 517 base::WideToUTF8(caps.szPname), |
518 base::IntToString(static_cast<int>(caps.vDriverVersion))); | 518 base::IntToString(static_cast<int>(caps.vDriverVersion))); |
519 AddInputPort(info); | 519 AddInputPort(info); |
520 in_device->set_port_index(inport_index++); | 520 in_device->set_port_index(inport_index++); |
521 in_devices_.push_back(in_device.Pass()); | 521 in_devices_.push_back(in_device.release()); |
522 } | 522 } |
523 | 523 |
524 const UINT num_out_devices = midiOutGetNumDevs(); | 524 const UINT num_out_devices = midiOutGetNumDevs(); |
525 out_devices_.reserve(num_out_devices); | 525 out_devices_.reserve(num_out_devices); |
526 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) { |
527 MIDIOUTCAPS caps = {}; | 527 MIDIOUTCAPS caps = {}; |
528 MMRESULT result = midiOutGetDevCaps(device_id, &caps, sizeof(caps)); | 528 MMRESULT result = midiOutGetDevCaps(device_id, &caps, sizeof(caps)); |
529 if (result != MMSYSERR_NOERROR) { | 529 if (result != MMSYSERR_NOERROR) { |
530 DLOG(ERROR) << "Failed to obtain output device info: " | 530 DLOG(ERROR) << "Failed to obtain output device info: " |
531 << GetOutErrorMessage(result); | 531 << GetOutErrorMessage(result); |
532 continue; | 532 continue; |
533 } | 533 } |
534 scoped_ptr<OutDeviceInfo> out_port(OutDeviceInfo::Create(device_id)); | 534 scoped_ptr<OutDeviceInfo> out_port(OutDeviceInfo::Create(device_id)); |
535 if (!out_port) | 535 if (!out_port) |
536 continue; | 536 continue; |
537 MidiPortInfo info( | 537 MidiPortInfo info( |
538 base::IntToString(static_cast<int>(device_id)), | 538 base::IntToString(static_cast<int>(device_id)), |
539 "", | 539 "", |
540 base::WideToUTF8(caps.szPname), | 540 base::WideToUTF8(caps.szPname), |
541 base::IntToString(static_cast<int>(caps.vDriverVersion))); | 541 base::IntToString(static_cast<int>(caps.vDriverVersion))); |
542 AddOutputPort(info); | 542 AddOutputPort(info); |
543 out_devices_.push_back(out_port.Pass()); | 543 out_devices_.push_back(out_port.release()); |
544 } | 544 } |
545 | 545 |
546 CompleteInitialization(MIDI_OK); | 546 CompleteInitialization(MIDI_OK); |
547 } | 547 } |
548 | 548 |
549 MidiManagerWin::~MidiManagerWin() { | 549 MidiManagerWin::~MidiManagerWin() { |
550 // Cleanup order is important. |send_thread_| must be stopped before | 550 // Cleanup order is important. |send_thread_| must be stopped before |
551 // |out_devices_| is cleared. | 551 // |out_devices_| is cleared. |
552 for (auto& device : out_devices_) | 552 for (auto& device : out_devices_) |
553 device->Quit(); | 553 device->Quit(); |
(...skipping 14 matching lines...) Expand all Loading... |
568 if (timestamp != 0.0) { | 568 if (timestamp != 0.0) { |
569 base::TimeTicks time_to_send = | 569 base::TimeTicks time_to_send = |
570 base::TimeTicks() + base::TimeDelta::FromMicroseconds( | 570 base::TimeTicks() + base::TimeDelta::FromMicroseconds( |
571 timestamp * base::Time::kMicrosecondsPerSecond); | 571 timestamp * base::Time::kMicrosecondsPerSecond); |
572 delay = std::max(time_to_send - base::TimeTicks::Now(), base::TimeDelta()); | 572 delay = std::max(time_to_send - base::TimeTicks::Now(), base::TimeDelta()); |
573 } | 573 } |
574 | 574 |
575 if (!send_thread_.IsRunning()) | 575 if (!send_thread_.IsRunning()) |
576 send_thread_.Start(); | 576 send_thread_.Start(); |
577 | 577 |
578 OutDeviceInfo* out_port = out_devices_[port_index].get(); | 578 OutDeviceInfo* out_port = out_devices_[port_index]; |
579 send_thread_.message_loop()->PostDelayedTask( | 579 send_thread_.message_loop()->PostDelayedTask( |
580 FROM_HERE, | 580 FROM_HERE, |
581 base::Bind(&OutDeviceInfo::Send, base::Unretained(out_port), data), | 581 base::Bind(&OutDeviceInfo::Send, base::Unretained(out_port), data), |
582 delay); | 582 delay); |
583 | 583 |
584 // Call back AccumulateMidiBytesSent() on |send_thread_| to emulate the | 584 // Call back AccumulateMidiBytesSent() on |send_thread_| to emulate the |
585 // behavior of MidiManagerMac::SendMidiData. | 585 // behavior of MidiManagerMac::SendMidiData. |
586 // TODO(yukawa): Do this task in a platform-independent way if possible. | 586 // TODO(yukawa): Do this task in a platform-independent way if possible. |
587 // See crbug.com/325810. | 587 // See crbug.com/325810. |
588 send_thread_.message_loop()->PostTask( | 588 send_thread_.message_loop()->PostTask( |
589 FROM_HERE, | 589 FROM_HERE, |
590 base::Bind(&MidiManagerClient::AccumulateMidiBytesSent, | 590 base::Bind(&MidiManagerClient::AccumulateMidiBytesSent, |
591 base::Unretained(client), data.size())); | 591 base::Unretained(client), data.size())); |
592 } | 592 } |
593 | 593 |
594 MidiManager* MidiManager::Create() { | 594 MidiManager* MidiManager::Create() { |
595 return new MidiManagerWin(); | 595 return new MidiManagerWin(); |
596 } | 596 } |
597 | 597 |
598 } // namespace media | 598 } // namespace media |
OLD | NEW |