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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/synchronization/lock.h" |
14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
15 #include "content/public/browser/browser_message_filter.h" | 16 #include "content/public/browser/browser_message_filter.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "media/midi/midi_manager.h" | 18 #include "media/midi/midi_manager.h" |
18 | 19 |
19 namespace media { | 20 namespace media { |
20 class MidiManager; | 21 class MidiManager; |
21 class MidiMessageQueue; | 22 class MidiMessageQueue; |
22 } | 23 } |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 | 26 |
26 class CONTENT_EXPORT MidiHost | 27 class CONTENT_EXPORT MidiHost |
27 : public BrowserMessageFilter, | 28 : public BrowserMessageFilter, |
28 public media::MidiManagerClient { | 29 public media::MidiManagerClient { |
29 public: | 30 public: |
30 // Called from UI thread from the owner of this object. | 31 // Called from UI thread from the owner of this object. |
31 MidiHost(int renderer_process_id, media::MidiManager* midi_manager); | 32 MidiHost(int renderer_process_id, media::MidiManager* midi_manager); |
32 | 33 |
33 // BrowserMessageFilter implementation. | 34 // BrowserMessageFilter implementation. |
34 virtual void OnDestruct() const override; | 35 virtual void OnDestruct() const override; |
35 virtual bool OnMessageReceived(const IPC::Message& message) override; | 36 virtual bool OnMessageReceived(const IPC::Message& message) override; |
36 | 37 |
37 // MidiManagerClient implementation. | 38 // MidiManagerClient implementation. |
38 virtual void CompleteStartSession(int client_id, | 39 virtual void CompleteStartSession(media::MidiResult result) override; |
39 media::MidiResult result) override; | |
40 virtual void ReceiveMidiData(uint32 port, | 40 virtual void ReceiveMidiData(uint32 port, |
41 const uint8* data, | 41 const uint8* data, |
42 size_t length, | 42 size_t length, |
43 double timestamp) override; | 43 double timestamp) override; |
44 virtual void AccumulateMidiBytesSent(size_t n) override; | 44 virtual void AccumulateMidiBytesSent(size_t n) override; |
45 | 45 |
46 // Start session to access MIDI hardware. | 46 // Start session to access MIDI hardware. |
47 void OnStartSession(int client_id); | 47 void OnStartSession(); |
48 | 48 |
49 // Data to be sent to a MIDI output port. | 49 // Data to be sent to a MIDI output port. |
50 void OnSendData(uint32 port, | 50 void OnSendData(uint32 port, |
51 const std::vector<uint8>& data, | 51 const std::vector<uint8>& data, |
52 double timestamp); | 52 double timestamp); |
53 | 53 |
| 54 void OnEndSession(); |
| 55 |
54 private: | 56 private: |
55 FRIEND_TEST_ALL_PREFIXES(MidiHostTest, IsValidWebMIDIData); | 57 FRIEND_TEST_ALL_PREFIXES(MidiHostTest, IsValidWebMIDIData); |
56 friend class base::DeleteHelper<MidiHost>; | 58 friend class base::DeleteHelper<MidiHost>; |
57 friend class BrowserThread; | 59 friend class BrowserThread; |
58 | 60 |
59 virtual ~MidiHost(); | 61 virtual ~MidiHost(); |
60 | 62 |
61 // Returns true if |data| fulfills the requirements of MidiOutput.send API | 63 // Returns true if |data| fulfills the requirements of MidiOutput.send API |
62 // defined in the WebMIDI spec. | 64 // defined in the WebMIDI spec. |
63 // - |data| must be any number of complete MIDI messages (data abbreviation | 65 // - |data| must be any number of complete MIDI messages (data abbreviation |
64 // called "running status" is disallowed). | 66 // called "running status" is disallowed). |
65 // - 1-byte MIDI realtime messages can be placed at any position of |data|. | 67 // - 1-byte MIDI realtime messages can be placed at any position of |data|. |
66 static bool IsValidWebMIDIData(const std::vector<uint8>& data); | 68 static bool IsValidWebMIDIData(const std::vector<uint8>& data); |
67 | 69 |
68 int renderer_process_id_; | 70 int renderer_process_id_; |
69 | 71 |
70 // Represents if the renderer has a permission to send/receive MIDI SysEX | 72 // Represents if the renderer has a permission to send/receive MIDI SysEX |
71 // messages. | 73 // messages. |
72 bool has_sys_ex_permission_; | 74 bool has_sys_ex_permission_; |
73 | 75 |
| 76 // Represents if a session is requested to start. |
| 77 bool is_session_requested_; |
| 78 |
74 // |midi_manager_| talks to the platform-specific MIDI APIs. | 79 // |midi_manager_| talks to the platform-specific MIDI APIs. |
75 // It can be NULL if the platform (or our current implementation) | 80 // It can be NULL if the platform (or our current implementation) |
76 // does not support MIDI. If not supported then a call to | 81 // does not support MIDI. If not supported then a call to |
77 // OnRequestAccess() will always refuse access and a call to | 82 // OnRequestAccess() will always refuse access and a call to |
78 // OnSendData() will do nothing. | 83 // OnSendData() will do nothing. |
79 media::MidiManager* const midi_manager_; | 84 media::MidiManager* const midi_manager_; |
80 | 85 |
81 // Buffers where data sent from each MIDI input port is stored. | 86 // Buffers where data sent from each MIDI input port is stored. |
82 ScopedVector<media::MidiMessageQueue> received_messages_queues_; | 87 ScopedVector<media::MidiMessageQueue> received_messages_queues_; |
83 | 88 |
84 // The number of bytes sent to the platform-specific MIDI sending | 89 // The number of bytes sent to the platform-specific MIDI sending |
85 // system, but not yet completed. | 90 // system, but not yet completed. |
86 size_t sent_bytes_in_flight_; | 91 size_t sent_bytes_in_flight_; |
87 | 92 |
88 // The number of bytes successfully sent since the last time | 93 // The number of bytes successfully sent since the last time |
89 // we've acknowledged back to the renderer. | 94 // we've acknowledged back to the renderer. |
90 size_t bytes_sent_since_last_acknowledgement_; | 95 size_t bytes_sent_since_last_acknowledgement_; |
91 | 96 |
92 // Protects access to |sent_bytes_in_flight_|. | 97 // Protects access to |sent_bytes_in_flight_|. |
93 base::Lock in_flight_lock_; | 98 base::Lock in_flight_lock_; |
94 | 99 |
95 DISALLOW_COPY_AND_ASSIGN(MidiHost); | 100 DISALLOW_COPY_AND_ASSIGN(MidiHost); |
96 }; | 101 }; |
97 | 102 |
98 } // namespace content | 103 } // namespace content |
99 | 104 |
100 #endif // CONTENT_BROWSER_MEDIA_MIDI_HOST_H_ | 105 #endif // CONTENT_BROWSER_MEDIA_MIDI_HOST_H_ |
OLD | NEW |