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

Side by Side Diff: content/renderer/media/midi_message_filter.h

Issue 16025005: Web MIDI API back-end (work-in-progress) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add stub for non-OSX MIDIManagers Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_RENDERER_MEDIA_MIDI_MESSAGE_FILTER_H_
6 #define CONTENT_RENDERER_MEDIA_MIDI_MESSAGE_FILTER_H_
7
8 #include <map>
9 #include <vector>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "content/common/content_export.h"
13 #include "ipc/ipc_channel_proxy.h"
14 #include "media/midi/midi_port_info.h"
15 #include "third_party/WebKit/public/platform/WebMIDIAccessor.h"
16 #include "third_party/WebKit/public/platform/WebMIDIAccessorClient.h"
17
18 namespace base {
19 class MessageLoopProxy;
20 }
21
22 namespace content {
23
24 // MessageFilter that handles MIDI messages.
25 class CONTENT_EXPORT MIDIMessageFilter
26 : public IPC::ChannelProxy::MessageFilter {
27 public:
28 explicit MIDIMessageFilter(
29 const scoped_refptr<base::MessageLoopProxy>& io_message_loop);
30
31 // Each client registers for MIDI access here.
32 // If permission is granted, then the client's
33 // addInputPort() and addOutputPort() methods will be called,
34 // giving the client access to receive and send data.
35 void RequestAccess(WebKit::WebMIDIAccessorClient* client, int access);
36 void RemoveClient(WebKit::WebMIDIAccessorClient* client);
37
38 // A client will only be able to call this method if it has a suitable
39 // output port (from addOutputPort()).
40 void SendMIDIData(int port_index,
41 const uint8* data,
42 size_t length,
43 double timestamp);
44
45 // IO message loop associated with this message filter.
46 scoped_refptr<base::MessageLoopProxy> io_message_loop() const {
47 return io_message_loop_;
48 }
49
50 protected:
51 virtual ~MIDIMessageFilter();
52
53 private:
54 // Sends an IPC message using |channel_|.
55 void Send(IPC::Message* message);
56
57 // IPC::ChannelProxy::MessageFilter override. Called on |io_message_loop|.
58 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
59 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
60 virtual void OnFilterRemoved() OVERRIDE;
61 virtual void OnChannelClosing() OVERRIDE;
62
63 // Called when the browser process has approved (or denied) access to
64 // MIDI hardware.
65 void OnAccessApproved(int client_id,
66 int access,
67 bool success,
68 media::MIDIPortInfoList inputs,
69 media::MIDIPortInfoList outputs);
70
71 // Called when the browser process has sent MIDI data containing one or
72 // more messages.
73 void OnDataReceived(int port,
74 const std::vector<uint8>& data,
75 double timestamp);
76
77 void HandleAccessApproved(int client_id,
78 int access,
79 bool success,
80 media::MIDIPortInfoList inputs,
81 media::MIDIPortInfoList outputs);
82
83 void HandleDataReceived(int port,
84 const std::vector<uint8>& data,
85 double timestamp);
86
87 WebKit::WebMIDIAccessorClient* GetClientFromId(int client_id);
88
89 // IPC channel for Send(); must only be accessed on |io_message_loop_|.
90 IPC::Channel* channel_;
91
92 // Message loop on which IPC calls are driven.
93 const scoped_refptr<base::MessageLoopProxy> io_message_loop_;
94
95 // Keeps track of all MIDI clients.
96 // We map client to "client id" used to track permission.
97 // When access has been approved, we add the input and output ports to
98 // the client, allowing it to actually receive and send MIDI data.
99 typedef std::map<WebKit::WebMIDIAccessorClient*, int> ClientsMap;
100 ClientsMap clients_;
101
102 // Dishes out client ids.
103 static int next_available_id_;
piman 2013/06/20 20:16:20 nit: does this need to be static?
Chris Rogers 2013/06/21 23:04:11 Done.
104
105 // Protects access to our clients.
106 base::Lock clients_lock_;
piman 2013/06/20 20:16:20 I think you can do away with the lock: channel_ is
Chris Rogers 2013/06/21 23:04:11 Yes you're right - removed it.
107
108 // Will normally be the JS main thread.
109 scoped_refptr<base::MessageLoopProxy> client_message_loop_;
110
111 DISALLOW_COPY_AND_ASSIGN(MIDIMessageFilter);
112 };
113
114 } // namespace content
115
116 #endif // CONTENT_RENDERER_MEDIA_MIDI_MESSAGE_FILTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698