Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: media/midi/midi_manager_alsa.cc

Issue 2422163002: Web MIDI: use midi_service.mojom for media::midi::PortState (Closed)
Patch Set: gn --check fix Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/midi/midi_manager.cc ('k') | media/midi/midi_manager_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 9 #include <stddef.h>
10 #include <stdlib.h> 10 #include <stdlib.h>
(...skipping 14 matching lines...) Expand all
25 #include "base/strings/string_number_conversions.h" 25 #include "base/strings/string_number_conversions.h"
26 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
27 #include "base/time/time.h" 27 #include "base/time/time.h"
28 #include "crypto/sha2.h" 28 #include "crypto/sha2.h"
29 #include "media/midi/midi_port_info.h" 29 #include "media/midi/midi_port_info.h"
30 30
31 namespace midi { 31 namespace midi {
32 32
33 namespace { 33 namespace {
34 34
35 using midi::mojom::Result; 35 using mojom::PortState;
36 using mojom::Result;
36 37
37 // Per-output buffer. This can be smaller, but then large sysex messages 38 // Per-output buffer. This can be smaller, but then large sysex messages
38 // will be (harmlessly) split across multiple seq events. This should 39 // will be (harmlessly) split across multiple seq events. This should
39 // not have any real practical effect, except perhaps to slightly reorder 40 // not have any real practical effect, except perhaps to slightly reorder
40 // realtime messages with respect to sysex. 41 // realtime messages with respect to sysex.
41 const size_t kSendBufferSize = 256; 42 const size_t kSendBufferSize = 256;
42 43
43 // Minimum client id for which we will have ALSA card devices for. When we 44 // Minimum client id for which we will have ALSA card devices for. When we
44 // are searching for card devices (used to get the path, id, and manufacturer), 45 // are searching for card devices (used to get the path, id, and manufacturer),
45 // we don't want to get confused by kernel clients that do not have a card. 46 // we don't want to get confused by kernel clients that do not have a card.
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 // Disconnect any connected old ports that are now missing. 1196 // Disconnect any connected old ports that are now missing.
1196 for (auto& old_port : port_state_) { 1197 for (auto& old_port : port_state_) {
1197 if (old_port->connected() && 1198 if (old_port->connected() &&
1198 (new_port_state->FindConnected(*old_port) == new_port_state->end())) { 1199 (new_port_state->FindConnected(*old_port) == new_port_state->end())) {
1199 old_port->set_connected(false); 1200 old_port->set_connected(false);
1200 uint32_t web_port_index = old_port->web_port_index(); 1201 uint32_t web_port_index = old_port->web_port_index();
1201 switch (old_port->type()) { 1202 switch (old_port->type()) {
1202 case MidiPort::Type::kInput: 1203 case MidiPort::Type::kInput:
1203 source_map_.erase( 1204 source_map_.erase(
1204 AddrToInt(old_port->client_id(), old_port->port_id())); 1205 AddrToInt(old_port->client_id(), old_port->port_id()));
1205 SetInputPortState(web_port_index, MIDI_PORT_DISCONNECTED); 1206 SetInputPortState(web_port_index, PortState::DISCONNECTED);
1206 break; 1207 break;
1207 case MidiPort::Type::kOutput: 1208 case MidiPort::Type::kOutput:
1208 DeleteAlsaOutputPort(web_port_index); 1209 DeleteAlsaOutputPort(web_port_index);
1209 SetOutputPortState(web_port_index, MIDI_PORT_DISCONNECTED); 1210 SetOutputPortState(web_port_index, PortState::DISCONNECTED);
1210 break; 1211 break;
1211 } 1212 }
1212 } 1213 }
1213 } 1214 }
1214 1215
1215 // Reconnect or add new ports. 1216 // Reconnect or add new ports.
1216 auto it = new_port_state->begin(); 1217 auto it = new_port_state->begin();
1217 while (it != new_port_state->end()) { 1218 while (it != new_port_state->end()) {
1218 auto& new_port = *it; 1219 auto& new_port = *it;
1219 auto old_port = port_state_.Find(*new_port); 1220 auto old_port = port_state_.Find(*new_port);
1220 if (old_port == port_state_.end()) { 1221 if (old_port == port_state_.end()) {
1221 // Add new port. 1222 // Add new port.
1222 const auto& opaque_key = new_port->OpaqueKey(); 1223 const auto& opaque_key = new_port->OpaqueKey();
1223 const auto& manufacturer = new_port->manufacturer(); 1224 const auto& manufacturer = new_port->manufacturer();
1224 const auto& port_name = new_port->port_name(); 1225 const auto& port_name = new_port->port_name();
1225 const auto& version = new_port->version(); 1226 const auto& version = new_port->version();
1226 const auto& type = new_port->type(); 1227 const auto& type = new_port->type();
1227 const auto& client_id = new_port->client_id(); 1228 const auto& client_id = new_port->client_id();
1228 const auto& port_id = new_port->port_id(); 1229 const auto& port_id = new_port->port_id();
1229 1230
1230 uint32_t web_port_index = port_state_.push_back(std::move(new_port)); 1231 uint32_t web_port_index = port_state_.push_back(std::move(new_port));
1231 it = new_port_state->erase(it); 1232 it = new_port_state->erase(it);
1232 1233
1233 MidiPortInfo info(opaque_key, manufacturer, port_name, version, 1234 MidiPortInfo info(opaque_key, manufacturer, port_name, version,
1234 MIDI_PORT_OPENED); 1235 PortState::OPENED);
1235 switch (type) { 1236 switch (type) {
1236 case MidiPort::Type::kInput: 1237 case MidiPort::Type::kInput:
1237 if (Subscribe(web_port_index, client_id, port_id)) 1238 if (Subscribe(web_port_index, client_id, port_id))
1238 AddInputPort(info); 1239 AddInputPort(info);
1239 break; 1240 break;
1240 case MidiPort::Type::kOutput: 1241 case MidiPort::Type::kOutput:
1241 if (CreateAlsaOutputPort(web_port_index, client_id, port_id)) 1242 if (CreateAlsaOutputPort(web_port_index, client_id, port_id))
1242 AddOutputPort(info); 1243 AddOutputPort(info);
1243 break; 1244 break;
1244 } 1245 }
1245 } else if (!(*old_port)->connected()) { 1246 } else if (!(*old_port)->connected()) {
1246 // Reconnect. 1247 // Reconnect.
1247 uint32_t web_port_index = (*old_port)->web_port_index(); 1248 uint32_t web_port_index = (*old_port)->web_port_index();
1248 (*old_port)->Update(new_port->path(), new_port->client_id(), 1249 (*old_port)->Update(new_port->path(), new_port->client_id(),
1249 new_port->port_id(), new_port->client_name(), 1250 new_port->port_id(), new_port->client_name(),
1250 new_port->port_name(), new_port->manufacturer(), 1251 new_port->port_name(), new_port->manufacturer(),
1251 new_port->version()); 1252 new_port->version());
1252 switch ((*old_port)->type()) { 1253 switch ((*old_port)->type()) {
1253 case MidiPort::Type::kInput: 1254 case MidiPort::Type::kInput:
1254 if (Subscribe(web_port_index, (*old_port)->client_id(), 1255 if (Subscribe(web_port_index, (*old_port)->client_id(),
1255 (*old_port)->port_id())) 1256 (*old_port)->port_id()))
1256 SetInputPortState(web_port_index, MIDI_PORT_OPENED); 1257 SetInputPortState(web_port_index, PortState::OPENED);
1257 break; 1258 break;
1258 case MidiPort::Type::kOutput: 1259 case MidiPort::Type::kOutput:
1259 if (CreateAlsaOutputPort(web_port_index, (*old_port)->client_id(), 1260 if (CreateAlsaOutputPort(web_port_index, (*old_port)->client_id(),
1260 (*old_port)->port_id())) 1261 (*old_port)->port_id()))
1261 SetOutputPortState(web_port_index, MIDI_PORT_OPENED); 1262 SetOutputPortState(web_port_index, PortState::OPENED);
1262 break; 1263 break;
1263 } 1264 }
1264 (*old_port)->set_connected(true); 1265 (*old_port)->set_connected(true);
1265 ++it; 1266 ++it;
1266 } else { 1267 } else {
1267 ++it; 1268 ++it;
1268 } 1269 }
1269 } 1270 }
1270 } 1271 }
1271 1272
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 // Update our map. 1399 // Update our map.
1399 source_map_[AddrToInt(client_id, port_id)] = port_index; 1400 source_map_[AddrToInt(client_id, port_id)] = port_index;
1400 return true; 1401 return true;
1401 } 1402 }
1402 1403
1403 MidiManager* MidiManager::Create() { 1404 MidiManager* MidiManager::Create() {
1404 return new MidiManagerAlsa(); 1405 return new MidiManagerAlsa();
1405 } 1406 }
1406 1407
1407 } // namespace midi 1408 } // namespace midi
OLDNEW
« no previous file with comments | « media/midi/midi_manager.cc ('k') | media/midi/midi_manager_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698