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

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

Issue 662853003: Manage MIDI related objects and sessions' lifecycles correctly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one line bug fix Created 6 years, 1 month 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 | « content/renderer/media/renderer_webmidiaccessor_impl.cc ('k') | media/midi/midi_manager.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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_H_ 5 #ifndef MEDIA_MIDI_MIDI_MANAGER_H_
6 #define MEDIA_MIDI_MIDI_MANAGER_H_ 6 #define MEDIA_MIDI_MIDI_MANAGER_H_
7 7
8 #include <map>
9 #include <set> 8 #include <set>
10 #include <vector> 9 #include <vector>
11 10
12 #include "base/basictypes.h" 11 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
14 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
15 #include "base/time/time.h" 14 #include "base/time/time.h"
16 #include "media/base/media_export.h" 15 #include "media/base/media_export.h"
17 #include "media/midi/midi_port_info.h" 16 #include "media/midi/midi_port_info.h"
18 #include "media/midi/midi_result.h" 17 #include "media/midi/midi_result.h"
19 18
20 namespace base { 19 namespace base {
21 class SingleThreadTaskRunner; 20 class SingleThreadTaskRunner;
22 } // namespace base 21 } // namespace base
23 22
24 namespace media { 23 namespace media {
25 24
26 // A MidiManagerClient registers with the MidiManager to receive MIDI data. 25 // A MidiManagerClient registers with the MidiManager to receive MIDI data.
27 // See MidiManager::RequestAccess() and MidiManager::ReleaseAccess() 26 // See MidiManager::RequestAccess() and MidiManager::ReleaseAccess()
28 // for details. 27 // for details.
29 class MEDIA_EXPORT MidiManagerClient { 28 class MEDIA_EXPORT MidiManagerClient {
30 public: 29 public:
31 virtual ~MidiManagerClient() {} 30 virtual ~MidiManagerClient() {}
32 31
33 // CompleteStartSession() is called when platform dependent preparation is 32 // CompleteStartSession() is called when platform dependent preparation is
34 // finished. 33 // finished.
35 virtual void CompleteStartSession(int client_id, MidiResult result) = 0; 34 virtual void CompleteStartSession(MidiResult result) = 0;
36 35
37 // ReceiveMidiData() is called when MIDI data has been received from the 36 // ReceiveMidiData() is called when MIDI data has been received from the
38 // MIDI system. 37 // MIDI system.
39 // |port_index| represents the specific input port from input_ports(). 38 // |port_index| represents the specific input port from input_ports().
40 // |data| represents a series of bytes encoding one or more MIDI messages. 39 // |data| represents a series of bytes encoding one or more MIDI messages.
41 // |length| is the number of bytes in |data|. 40 // |length| is the number of bytes in |data|.
42 // |timestamp| is the time the data was received, in seconds. 41 // |timestamp| is the time the data was received, in seconds.
43 virtual void ReceiveMidiData(uint32 port_index, 42 virtual void ReceiveMidiData(uint32 port_index,
44 const uint8* data, 43 const uint8* data,
45 size_t length, 44 size_t length,
(...skipping 18 matching lines...) Expand all
64 // thread. 63 // thread.
65 static MidiManager* Create(); 64 static MidiManager* Create();
66 65
67 // A client calls StartSession() to receive and send MIDI data. 66 // A client calls StartSession() to receive and send MIDI data.
68 // If the session is ready to start, the MIDI system is lazily initialized 67 // If the session is ready to start, the MIDI system is lazily initialized
69 // and the client is registered to receive MIDI data. 68 // and the client is registered to receive MIDI data.
70 // CompleteStartSession() is called with MIDI_OK if the session is started. 69 // CompleteStartSession() is called with MIDI_OK if the session is started.
71 // Otherwise CompleteStartSession() is called with proper MidiResult code. 70 // Otherwise CompleteStartSession() is called with proper MidiResult code.
72 // StartSession() and EndSession() can be called on the Chrome_IOThread. 71 // StartSession() and EndSession() can be called on the Chrome_IOThread.
73 // CompleteStartSession() will be invoked on the same Chrome_IOThread. 72 // CompleteStartSession() will be invoked on the same Chrome_IOThread.
74 void StartSession(MidiManagerClient* client, int client_id); 73 void StartSession(MidiManagerClient* client);
75 74
76 // A client calls EndSession() to stop receiving MIDI data. 75 // A client calls EndSession() to stop receiving MIDI data.
77 void EndSession(MidiManagerClient* client); 76 void EndSession(MidiManagerClient* client);
78 77
79 // DispatchSendMidiData() is called when MIDI data should be sent to the MIDI 78 // DispatchSendMidiData() is called when MIDI data should be sent to the MIDI
80 // system. 79 // system.
81 // This method is supposed to return immediately and should not block. 80 // This method is supposed to return immediately and should not block.
82 // |port_index| represents the specific output port from output_ports(). 81 // |port_index| represents the specific output port from output_ports().
83 // |data| represents a series of bytes encoding one or more MIDI messages. 82 // |data| represents a series of bytes encoding one or more MIDI messages.
84 // |length| is the number of bytes in |data|. 83 // |length| is the number of bytes in |data|.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 140
142 size_t clients_size_for_testing() const { return clients_.size(); } 141 size_t clients_size_for_testing() const { return clients_.size(); }
143 size_t pending_clients_size_for_testing() const { 142 size_t pending_clients_size_for_testing() const {
144 return pending_clients_.size(); 143 return pending_clients_.size();
145 } 144 }
146 145
147 private: 146 private:
148 void CompleteInitializationInternal(MidiResult result); 147 void CompleteInitializationInternal(MidiResult result);
149 148
150 // Keeps track of all clients who wish to receive MIDI data. 149 // Keeps track of all clients who wish to receive MIDI data.
151 typedef std::set<MidiManagerClient*> ClientList; 150 typedef std::set<MidiManagerClient*> ClientSet;
152 ClientList clients_; 151 ClientSet clients_;
153 152
154 // Keeps track of all clients who are waiting for CompleteStartSession(). 153 // Keeps track of all clients who are waiting for CompleteStartSession().
155 typedef std::multimap<MidiManagerClient*, int> PendingClientMap; 154 ClientSet pending_clients_;
156 PendingClientMap pending_clients_;
157 155
158 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in 156 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in
159 // order to invoke CompleteStartSession() on the thread. 157 // order to invoke CompleteStartSession() on the thread.
160 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; 158 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_;
161 159
162 // Keeps true if platform dependent initialization is already completed. 160 // Keeps true if platform dependent initialization is already completed.
163 bool initialized_; 161 bool initialized_;
164 162
165 // Keeps the platform dependent initialization result if initialization is 163 // Keeps the platform dependent initialization result if initialization is
166 // completed. Otherwise keeps MIDI_NOT_SUPPORTED. 164 // completed. Otherwise keeps MIDI_NOT_SUPPORTED.
167 MidiResult result_; 165 MidiResult result_;
168 166
169 // Protects access to |clients_|, |pending_clients_|, |initialized_|, and 167 // Protects access to |clients_|, |pending_clients_|, |initialized_|, and
170 // |result_|. 168 // |result_|.
171 base::Lock lock_; 169 base::Lock lock_;
172 170
173 MidiPortInfoList input_ports_; 171 MidiPortInfoList input_ports_;
174 MidiPortInfoList output_ports_; 172 MidiPortInfoList output_ports_;
175 173
176 DISALLOW_COPY_AND_ASSIGN(MidiManager); 174 DISALLOW_COPY_AND_ASSIGN(MidiManager);
177 }; 175 };
178 176
179 } // namespace media 177 } // namespace media
180 178
181 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ 179 #endif // MEDIA_MIDI_MIDI_MANAGER_H_
OLDNEW
« no previous file with comments | « content/renderer/media/renderer_webmidiaccessor_impl.cc ('k') | media/midi/midi_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698