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_BROWSER_MEDIA_MIDI_HOST_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_MIDI_HOST_H_ |
6 #define CONTENT_BROWSER_MEDIA_MIDI_HOST_H_ | 6 #define CONTENT_BROWSER_MEDIA_MIDI_HOST_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
20 #include "content/public/browser/browser_message_filter.h" | 20 #include "content/public/browser/browser_message_filter.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "media/midi/midi_manager.h" | 22 #include "media/midi/midi_manager.h" |
23 #include "media/midi/midi_port_info.h" | 23 #include "media/midi/midi_port_info.h" |
24 | 24 |
25 namespace media { | |
26 namespace midi { | 25 namespace midi { |
27 class MidiManager; | 26 class MidiManager; |
28 class MidiMessageQueue; | 27 class MidiMessageQueue; |
29 } | 28 } // namespace midi |
30 } | |
31 | 29 |
32 namespace content { | 30 namespace content { |
33 | 31 |
34 class CONTENT_EXPORT MidiHost : public BrowserMessageFilter, | 32 class CONTENT_EXPORT MidiHost : public BrowserMessageFilter, |
35 public media::midi::MidiManagerClient { | 33 public midi::MidiManagerClient { |
36 public: | 34 public: |
37 // Called from UI thread from the owner of this object. | 35 // Called from UI thread from the owner of this object. |
38 MidiHost(int renderer_process_id, media::midi::MidiManager* midi_manager); | 36 MidiHost(int renderer_process_id, midi::MidiManager* midi_manager); |
39 | 37 |
40 // BrowserMessageFilter implementation. | 38 // BrowserMessageFilter implementation. |
41 void OnChannelClosing() override; | 39 void OnChannelClosing() override; |
42 void OnDestruct() const override; | 40 void OnDestruct() const override; |
43 bool OnMessageReceived(const IPC::Message& message) override; | 41 bool OnMessageReceived(const IPC::Message& message) override; |
44 | 42 |
45 // MidiManagerClient implementation. | 43 // MidiManagerClient implementation. |
46 void CompleteStartSession(media::midi::Result result) override; | 44 void CompleteStartSession(midi::Result result) override; |
47 void AddInputPort(const media::midi::MidiPortInfo& info) override; | 45 void AddInputPort(const midi::MidiPortInfo& info) override; |
48 void AddOutputPort(const media::midi::MidiPortInfo& info) override; | 46 void AddOutputPort(const midi::MidiPortInfo& info) override; |
49 void SetInputPortState(uint32_t port, | 47 void SetInputPortState(uint32_t port, |
50 media::midi::MidiPortState state) override; | 48 midi::MidiPortState state) override; |
51 void SetOutputPortState(uint32_t port, | 49 void SetOutputPortState(uint32_t port, |
52 media::midi::MidiPortState state) override; | 50 midi::MidiPortState state) override; |
53 void ReceiveMidiData(uint32_t port, | 51 void ReceiveMidiData(uint32_t port, |
54 const uint8_t* data, | 52 const uint8_t* data, |
55 size_t length, | 53 size_t length, |
56 double timestamp) override; | 54 double timestamp) override; |
57 void AccumulateMidiBytesSent(size_t n) override; | 55 void AccumulateMidiBytesSent(size_t n) override; |
58 void Detach() override; | 56 void Detach() override; |
59 | 57 |
60 // Start session to access MIDI hardware. | 58 // Start session to access MIDI hardware. |
61 void OnStartSession(); | 59 void OnStartSession(); |
62 | 60 |
(...skipping 26 matching lines...) Expand all Loading... |
89 bool has_sys_ex_permission_; | 87 bool has_sys_ex_permission_; |
90 | 88 |
91 // Represents if a session is requested to start. | 89 // Represents if a session is requested to start. |
92 bool is_session_requested_; | 90 bool is_session_requested_; |
93 | 91 |
94 // |midi_manager_| talks to the platform-specific MIDI APIs. | 92 // |midi_manager_| talks to the platform-specific MIDI APIs. |
95 // It can be NULL if the platform (or our current implementation) | 93 // It can be NULL if the platform (or our current implementation) |
96 // does not support MIDI. If not supported then a call to | 94 // does not support MIDI. If not supported then a call to |
97 // OnRequestAccess() will always refuse access and a call to | 95 // OnRequestAccess() will always refuse access and a call to |
98 // OnSendData() will do nothing. | 96 // OnSendData() will do nothing. |
99 media::midi::MidiManager* midi_manager_; | 97 midi::MidiManager* midi_manager_; |
100 | 98 |
101 // Buffers where data sent from each MIDI input port is stored. | 99 // Buffers where data sent from each MIDI input port is stored. |
102 ScopedVector<media::midi::MidiMessageQueue> received_messages_queues_; | 100 ScopedVector<midi::MidiMessageQueue> received_messages_queues_; |
103 | 101 |
104 // Protects access to |received_messages_queues_|; | 102 // Protects access to |received_messages_queues_|; |
105 base::Lock messages_queues_lock_; | 103 base::Lock messages_queues_lock_; |
106 | 104 |
107 // The number of bytes sent to the platform-specific MIDI sending | 105 // The number of bytes sent to the platform-specific MIDI sending |
108 // system, but not yet completed. | 106 // system, but not yet completed. |
109 size_t sent_bytes_in_flight_; | 107 size_t sent_bytes_in_flight_; |
110 | 108 |
111 // The number of bytes successfully sent since the last time | 109 // The number of bytes successfully sent since the last time |
112 // we've acknowledged back to the renderer. | 110 // we've acknowledged back to the renderer. |
113 size_t bytes_sent_since_last_acknowledgement_; | 111 size_t bytes_sent_since_last_acknowledgement_; |
114 | 112 |
115 // Protects access to |sent_bytes_in_flight_|. | 113 // Protects access to |sent_bytes_in_flight_|. |
116 base::Lock in_flight_lock_; | 114 base::Lock in_flight_lock_; |
117 | 115 |
118 // How many output port exists. | 116 // How many output port exists. |
119 uint32_t output_port_count_; | 117 uint32_t output_port_count_; |
120 | 118 |
121 // Protects access to |output_port_count_|. | 119 // Protects access to |output_port_count_|. |
122 base::Lock output_port_count_lock_; | 120 base::Lock output_port_count_lock_; |
123 | 121 |
124 DISALLOW_COPY_AND_ASSIGN(MidiHost); | 122 DISALLOW_COPY_AND_ASSIGN(MidiHost); |
125 }; | 123 }; |
126 | 124 |
127 } // namespace content | 125 } // namespace content |
128 | 126 |
129 #endif // CONTENT_BROWSER_MEDIA_MIDI_HOST_H_ | 127 #endif // CONTENT_BROWSER_MEDIA_MIDI_HOST_H_ |
OLD | NEW |