OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_alsa.h" | 5 #include "media/midi/midi_manager_alsa.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <poll.h> | 8 #include <poll.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <string> | 11 #include <string> |
| 12 #include <utility> |
12 | 13 |
13 #include "base/bind.h" | 14 #include "base/bind.h" |
14 #include "base/json/json_string_value_serializer.h" | 15 #include "base/json/json_string_value_serializer.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
17 #include "base/posix/eintr_wrapper.h" | 18 #include "base/posix/eintr_wrapper.h" |
18 #include "base/posix/safe_strerror.h" | 19 #include "base/posix/safe_strerror.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 } | 586 } |
586 | 587 |
587 MidiManagerAlsa::AlsaSeqState::AlsaSeqState() = default; | 588 MidiManagerAlsa::AlsaSeqState::AlsaSeqState() = default; |
588 | 589 |
589 MidiManagerAlsa::AlsaSeqState::~AlsaSeqState() = default; | 590 MidiManagerAlsa::AlsaSeqState::~AlsaSeqState() = default; |
590 | 591 |
591 void MidiManagerAlsa::AlsaSeqState::ClientStart(int client_id, | 592 void MidiManagerAlsa::AlsaSeqState::ClientStart(int client_id, |
592 const std::string& client_name, | 593 const std::string& client_name, |
593 snd_seq_client_type_t type) { | 594 snd_seq_client_type_t type) { |
594 ClientExit(client_id); | 595 ClientExit(client_id); |
595 clients_.insert(client_id, make_scoped_ptr(new Client(client_name, type))); | 596 clients_.insert(std::make_pair( |
| 597 client_id, make_scoped_ptr(new Client(client_name, type)))); |
596 if (IsCardClient(type, client_id)) | 598 if (IsCardClient(type, client_id)) |
597 ++card_client_count_; | 599 ++card_client_count_; |
598 } | 600 } |
599 | 601 |
600 bool MidiManagerAlsa::AlsaSeqState::ClientStarted(int client_id) { | 602 bool MidiManagerAlsa::AlsaSeqState::ClientStarted(int client_id) { |
601 return clients_.find(client_id) != clients_.end(); | 603 return clients_.find(client_id) != clients_.end(); |
602 } | 604 } |
603 | 605 |
604 void MidiManagerAlsa::AlsaSeqState::ClientExit(int client_id) { | 606 void MidiManagerAlsa::AlsaSeqState::ClientExit(int client_id) { |
605 auto it = clients_.find(client_id); | 607 auto it = clients_.find(client_id); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 | 640 |
639 scoped_ptr<MidiManagerAlsa::TemporaryMidiPortState> | 641 scoped_ptr<MidiManagerAlsa::TemporaryMidiPortState> |
640 MidiManagerAlsa::AlsaSeqState::ToMidiPortState(const AlsaCardMap& alsa_cards) { | 642 MidiManagerAlsa::AlsaSeqState::ToMidiPortState(const AlsaCardMap& alsa_cards) { |
641 scoped_ptr<MidiManagerAlsa::TemporaryMidiPortState> midi_ports( | 643 scoped_ptr<MidiManagerAlsa::TemporaryMidiPortState> midi_ports( |
642 new TemporaryMidiPortState); | 644 new TemporaryMidiPortState); |
643 auto card_it = alsa_cards.begin(); | 645 auto card_it = alsa_cards.begin(); |
644 | 646 |
645 int card_midi_device = -1; | 647 int card_midi_device = -1; |
646 for (const auto& client_pair : clients_) { | 648 for (const auto& client_pair : clients_) { |
647 int client_id = client_pair.first; | 649 int client_id = client_pair.first; |
648 const auto& client = client_pair.second; | 650 const auto& client = client_pair.second.get(); |
649 | 651 |
650 // Get client metadata. | 652 // Get client metadata. |
651 const std::string client_name = client->name(); | 653 const std::string client_name = client->name(); |
652 std::string manufacturer; | 654 std::string manufacturer; |
653 std::string driver; | 655 std::string driver; |
654 std::string path; | 656 std::string path; |
655 MidiPort::Id id; | 657 MidiPort::Id id; |
656 std::string card_name; | 658 std::string card_name; |
657 std::string card_longname; | 659 std::string card_longname; |
658 int midi_device = -1; | 660 int midi_device = -1; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 | 722 |
721 MidiManagerAlsa::AlsaSeqState::Client::Client(const std::string& name, | 723 MidiManagerAlsa::AlsaSeqState::Client::Client(const std::string& name, |
722 snd_seq_client_type_t type) | 724 snd_seq_client_type_t type) |
723 : name_(name), type_(type) { | 725 : name_(name), type_(type) { |
724 } | 726 } |
725 | 727 |
726 MidiManagerAlsa::AlsaSeqState::Client::~Client() = default; | 728 MidiManagerAlsa::AlsaSeqState::Client::~Client() = default; |
727 | 729 |
728 void MidiManagerAlsa::AlsaSeqState::Client::AddPort(int addr, | 730 void MidiManagerAlsa::AlsaSeqState::Client::AddPort(int addr, |
729 scoped_ptr<Port> port) { | 731 scoped_ptr<Port> port) { |
730 ports_.set(addr, port.Pass()); | 732 ports_[addr] = std::move(port); |
731 } | 733 } |
732 | 734 |
733 void MidiManagerAlsa::AlsaSeqState::Client::RemovePort(int addr) { | 735 void MidiManagerAlsa::AlsaSeqState::Client::RemovePort(int addr) { |
734 ports_.erase(addr); | 736 ports_.erase(addr); |
735 } | 737 } |
736 | 738 |
737 MidiManagerAlsa::AlsaSeqState::Client::PortMap::const_iterator | 739 MidiManagerAlsa::AlsaSeqState::Client::PortMap::const_iterator |
738 MidiManagerAlsa::AlsaSeqState::Client::begin() const { | 740 MidiManagerAlsa::AlsaSeqState::Client::begin() const { |
739 return ports_.begin(); | 741 return ports_.begin(); |
740 } | 742 } |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 snd_hwdep_iface_t iface = snd_hwdep_info_get_iface(hwdep); | 1114 snd_hwdep_iface_t iface = snd_hwdep_info_get_iface(hwdep); |
1113 if (iface == SND_HWDEP_IFACE_OPL2 || iface == SND_HWDEP_IFACE_OPL3 || | 1115 if (iface == SND_HWDEP_IFACE_OPL2 || iface == SND_HWDEP_IFACE_OPL3 || |
1114 iface == SND_HWDEP_IFACE_OPL4) | 1116 iface == SND_HWDEP_IFACE_OPL4) |
1115 ++midi_count; | 1117 ++midi_count; |
1116 } | 1118 } |
1117 snd_ctl_close(handle); | 1119 snd_ctl_close(handle); |
1118 | 1120 |
1119 if (midi_count > 0) { | 1121 if (midi_count > 0) { |
1120 scoped_ptr<AlsaCard> card( | 1122 scoped_ptr<AlsaCard> card( |
1121 new AlsaCard(dev, name, longname, driver, midi_count)); | 1123 new AlsaCard(dev, name, longname, driver, midi_count)); |
1122 alsa_cards_.insert(number, card.Pass()); | 1124 alsa_cards_.insert(std::make_pair(number, std::move(card))); |
1123 alsa_card_midi_count_ += midi_count; | 1125 alsa_card_midi_count_ += midi_count; |
1124 } | 1126 } |
1125 } | 1127 } |
1126 | 1128 |
1127 void MidiManagerAlsa::RemoveCard(int number) { | 1129 void MidiManagerAlsa::RemoveCard(int number) { |
1128 auto it = alsa_cards_.find(number); | 1130 auto it = alsa_cards_.find(number); |
1129 if (it == alsa_cards_.end()) | 1131 if (it == alsa_cards_.end()) |
1130 return; | 1132 return; |
1131 | 1133 |
1132 alsa_card_midi_count_ -= it->second->midi_device_count(); | 1134 alsa_card_midi_count_ -= it->second->midi_device_count(); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 source_map_[AddrToInt(client_id, port_id)] = port_index; | 1343 source_map_[AddrToInt(client_id, port_id)] = port_index; |
1342 return true; | 1344 return true; |
1343 } | 1345 } |
1344 | 1346 |
1345 MidiManager* MidiManager::Create() { | 1347 MidiManager* MidiManager::Create() { |
1346 return new MidiManagerAlsa(); | 1348 return new MidiManagerAlsa(); |
1347 } | 1349 } |
1348 | 1350 |
1349 } // namespace midi | 1351 } // namespace midi |
1350 } // namespace media | 1352 } // namespace media |
OLD | NEW |