| OLD | NEW |
| (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, | |
| 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 void RequestAccessOnIOThread(int client_id, int access); | |
| 88 | |
| 89 void SendMIDIDataOnIOThread(int port, | |
| 90 const std::vector<uint8>& data, | |
| 91 double timestamp); | |
| 92 | |
| 93 WebKit::WebMIDIAccessorClient* GetClientFromId(int client_id); | |
| 94 | |
| 95 // IPC channel for Send(); must only be accessed on |io_message_loop_|. | |
| 96 IPC::Channel* channel_; | |
| 97 | |
| 98 // Message loop on which IPC calls are driven. | |
| 99 const scoped_refptr<base::MessageLoopProxy> io_message_loop_; | |
| 100 | |
| 101 // Keeps track of all MIDI clients. | |
| 102 // We map client to "client id" used to track permission. | |
| 103 // When access has been approved, we add the input and output ports to | |
| 104 // the client, allowing it to actually receive and send MIDI data. | |
| 105 typedef std::map<WebKit::WebMIDIAccessorClient*, int> ClientsMap; | |
| 106 ClientsMap clients_; | |
| 107 | |
| 108 // Dishes out client ids. | |
| 109 int next_available_id_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(MIDIMessageFilter); | |
| 112 }; | |
| 113 | |
| 114 } // namespace content | |
| 115 | |
| 116 #endif // CONTENT_RENDERER_MEDIA_MIDI_MESSAGE_FILTER_H_ | |
| OLD | NEW |