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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 void SendMidiData(uint32_t port, | 47 void SendMidiData(uint32_t port, |
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 midi::mojom::PortState ToBlinkState(midi::mojom::PortState state) { |
58 midi::MidiPortState state) { | |
59 // "open" status is separately managed by blink per MIDIAccess instance. | 58 // "open" status is separately managed by blink per MIDIAccess instance. |
60 if (state == midi::MIDI_PORT_OPENED) | 59 // TODO(toyoshim): Pass through the state as is, and have a logic to convert |
61 state = midi::MIDI_PORT_CONNECTED; | 60 // this state to JavaScript exposing state in Blink side. |
62 return static_cast<blink::WebMIDIAccessorClient::MIDIPortState>(state); | 61 if (state == midi::mojom::PortState::OPENED) |
| 62 return midi::mojom::PortState::CONNECTED; |
| 63 return state; |
63 } | 64 } |
64 | 65 |
65 protected: | 66 protected: |
66 ~MidiMessageFilter() override; | 67 ~MidiMessageFilter() override; |
67 | 68 |
68 private: | 69 private: |
69 void StartSessionOnIOThread(); | 70 void StartSessionOnIOThread(); |
70 | 71 |
71 void SendMidiDataOnIOThread(uint32_t port, | 72 void SendMidiDataOnIOThread(uint32_t port, |
72 const std::vector<uint8_t>& data, | 73 const std::vector<uint8_t>& data, |
(...skipping 18 matching lines...) Expand all Loading... |
91 // (1) Just before calling |OnSessionStarted|, to notify the recipient about | 92 // (1) Just before calling |OnSessionStarted|, to notify the recipient about |
92 // existing ports. | 93 // existing ports. |
93 // (2) To notify the recipient that a new device was connected and that new | 94 // (2) To notify the recipient that a new device was connected and that new |
94 // ports have been created. | 95 // ports have been created. |
95 void OnAddInputPort(midi::MidiPortInfo info); | 96 void OnAddInputPort(midi::MidiPortInfo info); |
96 void OnAddOutputPort(midi::MidiPortInfo info); | 97 void OnAddOutputPort(midi::MidiPortInfo info); |
97 | 98 |
98 // These functions are called to notify the recipient that a device that is | 99 // These functions are called to notify the recipient that a device that is |
99 // notified via OnAddInputPort() or OnAddOutputPort() gets disconnected, or | 100 // notified via OnAddInputPort() or OnAddOutputPort() gets disconnected, or |
100 // connected again. | 101 // connected again. |
101 void OnSetInputPortState(uint32_t port, midi::MidiPortState state); | 102 void OnSetInputPortState(uint32_t port, midi::mojom::PortState state); |
102 void OnSetOutputPortState(uint32_t port, midi::MidiPortState state); | 103 void OnSetOutputPortState(uint32_t port, midi::mojom::PortState state); |
103 | 104 |
104 // Called when the browser process has sent MIDI data containing one or | 105 // Called when the browser process has sent MIDI data containing one or |
105 // more messages. | 106 // more messages. |
106 void OnDataReceived(uint32_t port, | 107 void OnDataReceived(uint32_t port, |
107 const std::vector<uint8_t>& data, | 108 const std::vector<uint8_t>& data, |
108 double timestamp); | 109 double timestamp); |
109 | 110 |
110 // From time-to-time, the browser incrementally informs us of how many bytes | 111 // 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 | 112 // 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. | 113 // sending too much data before knowing how much has already been sent. |
113 void OnAcknowledgeSentData(size_t bytes_sent); | 114 void OnAcknowledgeSentData(size_t bytes_sent); |
114 | 115 |
115 // Following methods, Handle*, run on |main_task_runner_|. | 116 // Following methods, Handle*, run on |main_task_runner_|. |
116 void HandleClientAdded(midi::mojom::Result result); | 117 void HandleClientAdded(midi::mojom::Result result); |
117 | 118 |
118 void HandleAddInputPort(midi::MidiPortInfo info); | 119 void HandleAddInputPort(midi::MidiPortInfo info); |
119 void HandleAddOutputPort(midi::MidiPortInfo info); | 120 void HandleAddOutputPort(midi::MidiPortInfo info); |
120 void HandleSetInputPortState(uint32_t port, midi::MidiPortState state); | 121 void HandleSetInputPortState(uint32_t port, midi::mojom::PortState state); |
121 void HandleSetOutputPortState(uint32_t port, | 122 void HandleSetOutputPortState(uint32_t port, midi::mojom::PortState 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 27 matching lines...) Expand all Loading... |
160 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 |