| 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_usb.h" | 5 #include "media/midi/midi_manager_usb.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 if (!AddPorts(devices_[i], i)) { | 117 if (!AddPorts(devices_[i], i)) { |
| 118 initialize_callback_.Run(MIDI_INITIALIZATION_ERROR); | 118 initialize_callback_.Run(MIDI_INITIALIZATION_ERROR); |
| 119 return; | 119 return; |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 initialize_callback_.Run(MIDI_OK); | 122 initialize_callback_.Run(MIDI_OK); |
| 123 } | 123 } |
| 124 | 124 |
| 125 bool MidiManagerUsb::AddPorts(UsbMidiDevice* device, int device_id) { | 125 bool MidiManagerUsb::AddPorts(UsbMidiDevice* device, int device_id) { |
| 126 UsbMidiDescriptorParser parser; | 126 UsbMidiDescriptorParser parser; |
| 127 std::vector<uint8> descriptor = device->GetDescriptor(); | 127 std::vector<uint8> descriptor = device->GetDescriptors(); |
| 128 const uint8* data = descriptor.size() > 0 ? &descriptor[0] : NULL; | 128 const uint8* data = descriptor.size() > 0 ? &descriptor[0] : NULL; |
| 129 std::vector<UsbMidiJack> jacks; | 129 std::vector<UsbMidiJack> jacks; |
| 130 bool parse_result = parser.Parse(device, | 130 bool parse_result = parser.Parse(device, |
| 131 data, | 131 data, |
| 132 descriptor.size(), | 132 descriptor.size(), |
| 133 &jacks); | 133 &jacks); |
| 134 if (!parse_result) | 134 if (!parse_result) |
| 135 return false; | 135 return false; |
| 136 | 136 |
| 137 std::string manufacturer(device->GetManufacturer()); |
| 138 std::string product_name(device->GetProductName()); |
| 139 std::string version(device->GetDeviceVersion()); |
| 140 |
| 137 for (size_t j = 0; j < jacks.size(); ++j) { | 141 for (size_t j = 0; j < jacks.size(); ++j) { |
| 142 // Port ID must be unique in a MIDI manager. This ID setting is |
| 143 // sufficiently unique although there is no user-friendly meaning. |
| 144 // TODO(yhirano): Use a hashed string as ID. |
| 145 std::string id( |
| 146 base::StringPrintf("port-%d-%ld", device_id, static_cast<long>(j))); |
| 138 if (jacks[j].direction() == UsbMidiJack::DIRECTION_OUT) { | 147 if (jacks[j].direction() == UsbMidiJack::DIRECTION_OUT) { |
| 139 output_streams_.push_back(new UsbMidiOutputStream(jacks[j])); | 148 output_streams_.push_back(new UsbMidiOutputStream(jacks[j])); |
| 140 // TODO(yhirano): Set appropriate properties. | 149 AddOutputPort(MidiPortInfo(id, manufacturer, product_name, version, |
| 141 // TODO(yhiran): Port ID should contain product ID / vendor ID. | 150 MIDI_PORT_OPENED)); |
| 142 // Port ID must be unique in a MIDI manager. This (and the below) ID | |
| 143 // setting is sufficiently unique although there is no user-friendly | |
| 144 // meaning. | |
| 145 MidiPortInfo port; | |
| 146 port.state = MIDI_PORT_OPENED; | |
| 147 port.id = base::StringPrintf("port-%d-%ld", | |
| 148 device_id, | |
| 149 static_cast<long>(j)); | |
| 150 AddOutputPort(port); | |
| 151 } else { | 151 } else { |
| 152 DCHECK_EQ(jacks[j].direction(), UsbMidiJack::DIRECTION_IN); | 152 DCHECK_EQ(jacks[j].direction(), UsbMidiJack::DIRECTION_IN); |
| 153 input_stream_->Add(jacks[j]); | 153 input_stream_->Add(jacks[j]); |
| 154 // TODO(yhirano): Set appropriate properties. | 154 AddInputPort(MidiPortInfo(id, manufacturer, product_name, version, |
| 155 MidiPortInfo port; | 155 MIDI_PORT_OPENED)); |
| 156 port.state = MIDI_PORT_OPENED; | |
| 157 port.id = base::StringPrintf("port-%d-%ld", | |
| 158 device_id, | |
| 159 static_cast<long>(j)); | |
| 160 AddInputPort(port); | |
| 161 } | 156 } |
| 162 } | 157 } |
| 163 return true; | 158 return true; |
| 164 } | 159 } |
| 165 | 160 |
| 166 } // namespace media | 161 } // namespace media |
| OLD | NEW |