| OLD | NEW |
| 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 CONTENT_RENDERER_MEDIA_MIDI_MESSAGE_FILTER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MIDI_MESSAGE_FILTER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_MIDI_MESSAGE_FILTER_H_ | 6 #define CONTENT_RENDERER_MEDIA_MIDI_MESSAGE_FILTER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 const uint8_t* data, | 48 const uint8_t* data, |
| 49 size_t length, | 49 size_t length, |
| 50 double timestamp); | 50 double timestamp); |
| 51 | 51 |
| 52 // IO task runner associated with this message filter. | 52 // IO task runner associated with this message filter. |
| 53 base::SingleThreadTaskRunner* io_task_runner() const { | 53 base::SingleThreadTaskRunner* io_task_runner() const { |
| 54 return io_task_runner_.get(); | 54 return io_task_runner_.get(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 static blink::WebMIDIAccessorClient::MIDIPortState ToBlinkState( | 57 static blink::WebMIDIAccessorClient::MIDIPortState ToBlinkState( |
| 58 media::midi::MidiPortState state) { | 58 midi::MidiPortState state) { |
| 59 // "open" status is separately managed by blink per MIDIAccess instance. | 59 // "open" status is separately managed by blink per MIDIAccess instance. |
| 60 if (state == media::midi::MIDI_PORT_OPENED) | 60 if (state == midi::MIDI_PORT_OPENED) |
| 61 state = media::midi::MIDI_PORT_CONNECTED; | 61 state = midi::MIDI_PORT_CONNECTED; |
| 62 return static_cast<blink::WebMIDIAccessorClient::MIDIPortState>(state); | 62 return static_cast<blink::WebMIDIAccessorClient::MIDIPortState>(state); |
| 63 } | 63 } |
| 64 | 64 |
| 65 protected: | 65 protected: |
| 66 ~MidiMessageFilter() override; | 66 ~MidiMessageFilter() override; |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 void StartSessionOnIOThread(); | 69 void StartSessionOnIOThread(); |
| 70 | 70 |
| 71 void SendMidiDataOnIOThread(uint32_t port, | 71 void SendMidiDataOnIOThread(uint32_t port, |
| 72 const std::vector<uint8_t>& data, | 72 const std::vector<uint8_t>& data, |
| 73 double timestamp); | 73 double timestamp); |
| 74 | 74 |
| 75 void EndSessionOnIOThread(); | 75 void EndSessionOnIOThread(); |
| 76 | 76 |
| 77 // Sends an IPC message using |sender_|. | 77 // Sends an IPC message using |sender_|. |
| 78 void Send(IPC::Message* message); | 78 void Send(IPC::Message* message); |
| 79 | 79 |
| 80 // IPC::MessageFilter override. Called on |io_task_runner|. | 80 // IPC::MessageFilter override. Called on |io_task_runner|. |
| 81 bool OnMessageReceived(const IPC::Message& message) override; | 81 bool OnMessageReceived(const IPC::Message& message) override; |
| 82 void OnFilterAdded(IPC::Channel* channel) override; | 82 void OnFilterAdded(IPC::Channel* channel) override; |
| 83 void OnFilterRemoved() override; | 83 void OnFilterRemoved() override; |
| 84 void OnChannelClosing() override; | 84 void OnChannelClosing() override; |
| 85 | 85 |
| 86 // Called when the browser process has approved (or denied) access to | 86 // Called when the browser process has approved (or denied) access to |
| 87 // MIDI hardware. | 87 // MIDI hardware. |
| 88 void OnSessionStarted(media::midi::Result result); | 88 void OnSessionStarted(midi::Result result); |
| 89 | 89 |
| 90 // These functions are called in 2 cases: | 90 // These functions are called in 2 cases: |
| 91 // (1) Just before calling |OnSessionStarted|, to notify the recipient about | 91 // (1) Just before calling |OnSessionStarted|, to notify the recipient about |
| 92 // existing ports. | 92 // existing ports. |
| 93 // (2) To notify the recipient that a new device was connected and that new | 93 // (2) To notify the recipient that a new device was connected and that new |
| 94 // ports have been created. | 94 // ports have been created. |
| 95 void OnAddInputPort(media::midi::MidiPortInfo info); | 95 void OnAddInputPort(midi::MidiPortInfo info); |
| 96 void OnAddOutputPort(media::midi::MidiPortInfo info); | 96 void OnAddOutputPort(midi::MidiPortInfo info); |
| 97 | 97 |
| 98 // These functions are called to notify the recipient that a device that is | 98 // These functions are called to notify the recipient that a device that is |
| 99 // notified via OnAddInputPort() or OnAddOutputPort() gets disconnected, or | 99 // notified via OnAddInputPort() or OnAddOutputPort() gets disconnected, or |
| 100 // connected again. | 100 // connected again. |
| 101 void OnSetInputPortState(uint32_t port, media::midi::MidiPortState state); | 101 void OnSetInputPortState(uint32_t port, midi::MidiPortState state); |
| 102 void OnSetOutputPortState(uint32_t port, media::midi::MidiPortState state); | 102 void OnSetOutputPortState(uint32_t port, midi::MidiPortState state); |
| 103 | 103 |
| 104 // Called when the browser process has sent MIDI data containing one or | 104 // Called when the browser process has sent MIDI data containing one or |
| 105 // more messages. | 105 // more messages. |
| 106 void OnDataReceived(uint32_t port, | 106 void OnDataReceived(uint32_t port, |
| 107 const std::vector<uint8_t>& data, | 107 const std::vector<uint8_t>& data, |
| 108 double timestamp); | 108 double timestamp); |
| 109 | 109 |
| 110 // From time-to-time, the browser incrementally informs us of how many bytes | 110 // From time-to-time, the browser incrementally informs us of how many bytes |
| 111 // it has successfully sent. This is part of our throttling process to avoid | 111 // it has successfully sent. This is part of our throttling process to avoid |
| 112 // sending too much data before knowing how much has already been sent. | 112 // sending too much data before knowing how much has already been sent. |
| 113 void OnAcknowledgeSentData(size_t bytes_sent); | 113 void OnAcknowledgeSentData(size_t bytes_sent); |
| 114 | 114 |
| 115 // Following methods, Handle*, run on |main_task_runner_|. | 115 // Following methods, Handle*, run on |main_task_runner_|. |
| 116 void HandleClientAdded(media::midi::Result result); | 116 void HandleClientAdded(midi::Result result); |
| 117 | 117 |
| 118 void HandleAddInputPort(media::midi::MidiPortInfo info); | 118 void HandleAddInputPort(midi::MidiPortInfo info); |
| 119 void HandleAddOutputPort(media::midi::MidiPortInfo info); | 119 void HandleAddOutputPort(midi::MidiPortInfo info); |
| 120 void HandleSetInputPortState(uint32_t port, media::midi::MidiPortState state); | 120 void HandleSetInputPortState(uint32_t port, midi::MidiPortState state); |
| 121 void HandleSetOutputPortState(uint32_t port, | 121 void HandleSetOutputPortState(uint32_t port, |
| 122 media::midi::MidiPortState state); | 122 midi::MidiPortState state); |
| 123 | 123 |
| 124 void HandleDataReceived(uint32_t port, | 124 void HandleDataReceived(uint32_t port, |
| 125 const std::vector<uint8_t>& data, | 125 const std::vector<uint8_t>& data, |
| 126 double timestamp); | 126 double timestamp); |
| 127 | 127 |
| 128 void HandleAckknowledgeSentData(size_t bytes_sent); | 128 void HandleAckknowledgeSentData(size_t bytes_sent); |
| 129 | 129 |
| 130 // IPC sender for Send(); must only be accessed on |io_task_runner_|. | 130 // IPC sender for Send(); must only be accessed on |io_task_runner_|. |
| 131 IPC::Sender* sender_; | 131 IPC::Sender* sender_; |
| 132 | 132 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 146 typedef std::set<blink::WebMIDIAccessorClient*> ClientsSet; | 146 typedef std::set<blink::WebMIDIAccessorClient*> ClientsSet; |
| 147 ClientsSet clients_; | 147 ClientsSet clients_; |
| 148 | 148 |
| 149 // Represents clients that are waiting for a session being open. | 149 // Represents clients that are waiting for a session being open. |
| 150 // Note: std::vector is not safe to invoke callbacks inside iterator based | 150 // Note: std::vector is not safe to invoke callbacks inside iterator based |
| 151 // for-loops. | 151 // for-loops. |
| 152 typedef std::vector<blink::WebMIDIAccessorClient*> ClientsQueue; | 152 typedef std::vector<blink::WebMIDIAccessorClient*> ClientsQueue; |
| 153 ClientsQueue clients_waiting_session_queue_; | 153 ClientsQueue clients_waiting_session_queue_; |
| 154 | 154 |
| 155 // Represents a result on starting a session. Can be accessed only on | 155 // Represents a result on starting a session. Can be accessed only on |
| 156 media::midi::Result session_result_; | 156 midi::Result session_result_; |
| 157 | 157 |
| 158 // Holds MidiPortInfoList for input ports and output ports. | 158 // Holds MidiPortInfoList for input ports and output ports. |
| 159 media::midi::MidiPortInfoList inputs_; | 159 midi::MidiPortInfoList inputs_; |
| 160 media::midi::MidiPortInfoList outputs_; | 160 midi::MidiPortInfoList outputs_; |
| 161 | 161 |
| 162 size_t unacknowledged_bytes_sent_; | 162 size_t unacknowledged_bytes_sent_; |
| 163 | 163 |
| 164 DISALLOW_COPY_AND_ASSIGN(MidiMessageFilter); | 164 DISALLOW_COPY_AND_ASSIGN(MidiMessageFilter); |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 } // namespace content | 167 } // namespace content |
| 168 | 168 |
| 169 #endif // CONTENT_RENDERER_MEDIA_MIDI_MESSAGE_FILTER_H_ | 169 #endif // CONTENT_RENDERER_MEDIA_MIDI_MESSAGE_FILTER_H_ |
| OLD | NEW |