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

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

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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
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 #ifndef MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ 5 #ifndef MEDIA_MIDI_MIDI_MANAGER_ALSA_H_
6 #define MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ 6 #define MEDIA_MIDI_MIDI_MANAGER_ALSA_H_
7 7
8 #include <alsa/asoundlib.h> 8 #include <alsa/asoundlib.h>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h"
13 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
15 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
16 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
17 #include "base/values.h" 16 #include "base/values.h"
18 #include "device/udev_linux/scoped_udev.h" 17 #include "device/udev_linux/scoped_udev.h"
19 #include "media/midi/midi_export.h" 18 #include "media/midi/midi_export.h"
20 #include "media/midi/midi_manager.h" 19 #include "media/midi/midi_manager.h"
21 20
22 namespace media { 21 namespace media {
23 namespace midi { 22 namespace midi {
24 23
25 class MIDI_EXPORT MidiManagerAlsa final : public MidiManager { 24 class MIDI_EXPORT MidiManagerAlsa final : public MidiManager {
26 public: 25 public:
27 MidiManagerAlsa(); 26 MidiManagerAlsa();
28 ~MidiManagerAlsa() override; 27 ~MidiManagerAlsa() override;
29 28
30 // MidiManager implementation. 29 // MidiManager implementation.
31 void StartInitialization() override; 30 void StartInitialization() override;
32 void Finalize() override; 31 void Finalize() override;
33 void DispatchSendMidiData(MidiManagerClient* client, 32 void DispatchSendMidiData(MidiManagerClient* client,
34 uint32 port_index, 33 uint32_t port_index,
35 const std::vector<uint8>& data, 34 const std::vector<uint8_t>& data,
36 double timestamp) override; 35 double timestamp) override;
37 36
38 private: 37 private:
39 friend class MidiManagerAlsaTest; 38 friend class MidiManagerAlsaTest;
40 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); 39 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer);
41 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ToMidiPortState); 40 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ToMidiPortState);
42 41
43 class AlsaCard; 42 class AlsaCard;
44 using AlsaCardMap = std::map<int, scoped_ptr<AlsaCard>>; 43 using AlsaCardMap = std::map<int, scoped_ptr<AlsaCard>>;
45 44
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 std::string path() const { return path_; } 116 std::string path() const { return path_; }
118 Id id() const { return id_; } 117 Id id() const { return id_; }
119 std::string client_name() const { return client_name_; } 118 std::string client_name() const { return client_name_; }
120 std::string port_name() const { return port_name_; } 119 std::string port_name() const { return port_name_; }
121 std::string manufacturer() const { return manufacturer_; } 120 std::string manufacturer() const { return manufacturer_; }
122 std::string version() const { return version_; } 121 std::string version() const { return version_; }
123 int client_id() const { return client_id_; } 122 int client_id() const { return client_id_; }
124 int port_id() const { return port_id_; } 123 int port_id() const { return port_id_; }
125 int midi_device() const { return midi_device_; } 124 int midi_device() const { return midi_device_; }
126 Type type() const { return type_; } 125 Type type() const { return type_; }
127 uint32 web_port_index() const { return web_port_index_; } 126 uint32_t web_port_index() const { return web_port_index_; }
128 bool connected() const { return connected_; } 127 bool connected() const { return connected_; }
129 128
130 // mutators 129 // mutators
131 void set_web_port_index(uint32 web_port_index) { 130 void set_web_port_index(uint32_t web_port_index) {
132 web_port_index_ = web_port_index; 131 web_port_index_ = web_port_index;
133 } 132 }
134 void set_connected(bool connected) { connected_ = connected; } 133 void set_connected(bool connected) { connected_ = connected; }
135 void Update(const std::string& path, 134 void Update(const std::string& path,
136 int client_id, 135 int client_id,
137 int port_id, 136 int port_id,
138 const std::string& client_name, 137 const std::string& client_name,
139 const std::string& port_name, 138 const std::string& port_name,
140 const std::string& manufacturer, 139 const std::string& manufacturer,
141 const std::string& version) { 140 const std::string& version) {
(...skipping 17 matching lines...) Expand all
159 // drivers change. 158 // drivers change.
160 std::string path_; 159 std::string path_;
161 int client_id_; 160 int client_id_;
162 int port_id_; 161 int port_id_;
163 std::string client_name_; 162 std::string client_name_;
164 std::string port_name_; 163 std::string port_name_;
165 std::string manufacturer_; 164 std::string manufacturer_;
166 std::string version_; 165 std::string version_;
167 166
168 // Index for MidiManager. 167 // Index for MidiManager.
169 uint32 web_port_index_ = 0; 168 uint32_t web_port_index_ = 0;
170 169
171 // Port is present in the ALSA system. 170 // Port is present in the ALSA system.
172 bool connected_ = true; 171 bool connected_ = true;
173 172
174 DISALLOW_COPY_AND_ASSIGN(MidiPort); 173 DISALLOW_COPY_AND_ASSIGN(MidiPort);
175 }; 174 };
176 175
177 class MidiPortStateBase { 176 class MidiPortStateBase {
178 public: 177 public:
179 typedef std::vector<scoped_ptr<MidiPort>>::iterator iterator; 178 typedef std::vector<scoped_ptr<MidiPort>>::iterator iterator;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 void push_back(scoped_ptr<MidiPort> port) { 210 void push_back(scoped_ptr<MidiPort> port) {
212 MidiPortStateBase::push_back(port.Pass()); 211 MidiPortStateBase::push_back(port.Pass());
213 } 212 }
214 }; 213 };
215 214
216 class MidiPortState final : public MidiPortStateBase { 215 class MidiPortState final : public MidiPortStateBase {
217 public: 216 public:
218 MidiPortState(); 217 MidiPortState();
219 218
220 // Inserts a port at the end. Returns web_port_index. 219 // Inserts a port at the end. Returns web_port_index.
221 uint32 push_back(scoped_ptr<MidiPort> port); 220 uint32_t push_back(scoped_ptr<MidiPort> port);
222 221
223 private: 222 private:
224 uint32 num_input_ports_ = 0; 223 uint32_t num_input_ports_ = 0;
225 uint32 num_output_ports_ = 0; 224 uint32_t num_output_ports_ = 0;
226 }; 225 };
227 226
228 class AlsaSeqState { 227 class AlsaSeqState {
229 public: 228 public:
230 enum class PortDirection { kInput, kOutput, kDuplex }; 229 enum class PortDirection { kInput, kOutput, kDuplex };
231 230
232 AlsaSeqState(); 231 AlsaSeqState();
233 ~AlsaSeqState(); 232 ~AlsaSeqState();
234 233
235 void ClientStart(int client_id, 234 void ClientStart(int client_id,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 struct SndSeqDeleter { 349 struct SndSeqDeleter {
351 void operator()(snd_seq_t* seq) const { snd_seq_close(seq); } 350 void operator()(snd_seq_t* seq) const { snd_seq_close(seq); }
352 }; 351 };
353 352
354 struct SndMidiEventDeleter { 353 struct SndMidiEventDeleter {
355 void operator()(snd_midi_event_t* coder) const { 354 void operator()(snd_midi_event_t* coder) const {
356 snd_midi_event_free(coder); 355 snd_midi_event_free(coder);
357 }; 356 };
358 }; 357 };
359 358
360 typedef base::hash_map<int, uint32> SourceMap; 359 typedef base::hash_map<int, uint32_t> SourceMap;
361 typedef base::hash_map<uint32, int> OutPortMap; 360 typedef base::hash_map<uint32_t, int> OutPortMap;
362 361
363 // An internal callback that runs on MidiSendThread. 362 // An internal callback that runs on MidiSendThread.
364 void SendMidiData(uint32 port_index, const std::vector<uint8>& data); 363 void SendMidiData(uint32_t port_index, const std::vector<uint8_t>& data);
365 364
366 void ScheduleEventLoop(); 365 void ScheduleEventLoop();
367 void EventLoop(); 366 void EventLoop();
368 void ProcessSingleEvent(snd_seq_event_t* event, double timestamp); 367 void ProcessSingleEvent(snd_seq_event_t* event, double timestamp);
369 void ProcessClientStartEvent(int client_id); 368 void ProcessClientStartEvent(int client_id);
370 void ProcessPortStartEvent(const snd_seq_addr_t& addr); 369 void ProcessPortStartEvent(const snd_seq_addr_t& addr);
371 void ProcessClientExitEvent(const snd_seq_addr_t& addr); 370 void ProcessClientExitEvent(const snd_seq_addr_t& addr);
372 void ProcessPortExitEvent(const snd_seq_addr_t& addr); 371 void ProcessPortExitEvent(const snd_seq_addr_t& addr);
373 void ProcessUdevEvent(udev_device* dev); 372 void ProcessUdevEvent(udev_device* dev);
374 void AddCard(udev_device* dev); 373 void AddCard(udev_device* dev);
375 void RemoveCard(int number); 374 void RemoveCard(int number);
376 375
377 // Updates port_state_ and Web MIDI state from alsa_seq_state_. 376 // Updates port_state_ and Web MIDI state from alsa_seq_state_.
378 void UpdatePortStateAndGenerateEvents(); 377 void UpdatePortStateAndGenerateEvents();
379 378
380 // Enumerates ports. Call once after subscribing to the announce port. 379 // Enumerates ports. Call once after subscribing to the announce port.
381 void EnumerateAlsaPorts(); 380 void EnumerateAlsaPorts();
382 // Enumerates udev cards. Call once after initializing the udev monitor. 381 // Enumerates udev cards. Call once after initializing the udev monitor.
383 bool EnumerateUdevCards(); 382 bool EnumerateUdevCards();
384 // Returns true if successful. 383 // Returns true if successful.
385 bool CreateAlsaOutputPort(uint32 port_index, int client_id, int port_id); 384 bool CreateAlsaOutputPort(uint32_t port_index, int client_id, int port_id);
386 void DeleteAlsaOutputPort(uint32 port_index); 385 void DeleteAlsaOutputPort(uint32_t port_index);
387 // Returns true if successful. 386 // Returns true if successful.
388 bool Subscribe(uint32 port_index, int client_id, int port_id); 387 bool Subscribe(uint32_t port_index, int client_id, int port_id);
389 388
390 AlsaSeqState alsa_seq_state_; 389 AlsaSeqState alsa_seq_state_;
391 MidiPortState port_state_; 390 MidiPortState port_state_;
392 391
393 // ALSA seq handles. 392 // ALSA seq handles.
394 scoped_ptr<snd_seq_t, SndSeqDeleter> in_client_; 393 scoped_ptr<snd_seq_t, SndSeqDeleter> in_client_;
395 int in_client_id_ = -1; 394 int in_client_id_ = -1;
396 scoped_ptr<snd_seq_t, SndSeqDeleter> out_client_; 395 scoped_ptr<snd_seq_t, SndSeqDeleter> out_client_;
397 int out_client_id_ = -1; 396 int out_client_id_ = -1;
398 397
(...skipping 27 matching lines...) Expand all
426 bool event_thread_shutdown_ = false; // guarded by shutdown_lock_ 425 bool event_thread_shutdown_ = false; // guarded by shutdown_lock_
427 base::Lock shutdown_lock_; // guards event_thread_shutdown_ 426 base::Lock shutdown_lock_; // guards event_thread_shutdown_
428 427
429 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa); 428 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa);
430 }; 429 };
431 430
432 } // namespace midi 431 } // namespace midi
433 } // namespace media 432 } // namespace media
434 433
435 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ 434 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698