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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 if (!input_stream_) | 67 if (!input_stream_) |
68 return; | 68 return; |
69 input_stream_->OnReceivedData(device, | 69 input_stream_->OnReceivedData(device, |
70 endpoint_number, | 70 endpoint_number, |
71 data, | 71 data, |
72 size, | 72 size, |
73 time); | 73 time); |
74 } | 74 } |
75 | 75 |
76 void MidiManagerUsb::OnDeviceAttached(scoped_ptr<UsbMidiDevice> device) { | 76 void MidiManagerUsb::OnDeviceAttached(scoped_ptr<UsbMidiDevice> device) { |
77 int device_id = devices_.size(); | 77 int device_id = static_cast<int>(devices_.size()); |
78 devices_.push_back(device.release()); | 78 devices_.push_back(device.release()); |
79 AddPorts(devices_.back(), device_id); | 79 AddPorts(devices_.back(), device_id); |
80 } | 80 } |
81 | 81 |
82 void MidiManagerUsb::OnDeviceDetached(size_t index) { | 82 void MidiManagerUsb::OnDeviceDetached(size_t index) { |
83 if (index >= devices_.size()) { | 83 if (index >= devices_.size()) { |
84 return; | 84 return; |
85 } | 85 } |
86 UsbMidiDevice* device = devices_[index]; | 86 UsbMidiDevice* device = devices_[index]; |
87 for (size_t i = 0; i < output_streams_.size(); ++i) { | 87 for (size_t i = 0; i < output_streams_.size(); ++i) { |
88 if (output_streams_[i]->jack().device == device) { | 88 if (output_streams_[i]->jack().device == device) { |
89 SetOutputPortState(i, MIDI_PORT_DISCONNECTED); | 89 SetOutputPortState(static_cast<uint32>(i), MIDI_PORT_DISCONNECTED); |
90 } | 90 } |
91 } | 91 } |
92 const std::vector<UsbMidiJack>& input_jacks = input_stream_->jacks(); | 92 const std::vector<UsbMidiJack>& input_jacks = input_stream_->jacks(); |
93 for (size_t i = 0; i < input_jacks.size(); ++i) { | 93 for (size_t i = 0; i < input_jacks.size(); ++i) { |
94 if (input_jacks[i].device == device) { | 94 if (input_jacks[i].device == device) { |
95 SetInputPortState(i, MIDI_PORT_DISCONNECTED); | 95 SetInputPortState(static_cast<uint32>(i), MIDI_PORT_DISCONNECTED); |
96 } | 96 } |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 void MidiManagerUsb::OnReceivedData(size_t jack_index, | 100 void MidiManagerUsb::OnReceivedData(size_t jack_index, |
101 const uint8* data, | 101 const uint8* data, |
102 size_t size, | 102 size_t size, |
103 base::TimeTicks time) { | 103 base::TimeTicks time) { |
104 ReceiveMidiData(jack_index, data, size, time); | 104 ReceiveMidiData(static_cast<uint32>(jack_index), data, size, time); |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 void MidiManagerUsb::OnEnumerateDevicesDone(bool result, | 108 void MidiManagerUsb::OnEnumerateDevicesDone(bool result, |
109 UsbMidiDevice::Devices* devices) { | 109 UsbMidiDevice::Devices* devices) { |
110 if (!result) { | 110 if (!result) { |
111 initialize_callback_.Run(MIDI_INITIALIZATION_ERROR); | 111 initialize_callback_.Run(MIDI_INITIALIZATION_ERROR); |
112 return; | 112 return; |
113 } | 113 } |
114 input_stream_.reset(new UsbMidiInputStream(this)); | 114 input_stream_.reset(new UsbMidiInputStream(this)); |
115 devices->swap(devices_); | 115 devices->swap(devices_); |
116 for (size_t i = 0; i < devices_.size(); ++i) { | 116 for (size_t i = 0; i < devices_.size(); ++i) { |
117 if (!AddPorts(devices_[i], i)) { | 117 if (!AddPorts(devices_[i], static_cast<int>(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->GetDescriptors(); | 127 std::vector<uint8> descriptor = device->GetDescriptors(); |
(...skipping 24 matching lines...) Expand all Loading... |
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 AddInputPort(MidiPortInfo(id, manufacturer, product_name, version, | 154 AddInputPort(MidiPortInfo(id, manufacturer, product_name, version, |
155 MIDI_PORT_OPENED)); | 155 MIDI_PORT_OPENED)); |
156 } | 156 } |
157 } | 157 } |
158 return true; | 158 return true; |
159 } | 159 } |
160 | 160 |
161 } // namespace media | 161 } // namespace media |
OLD | NEW |