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 #include "content/browser/renderer_host/media/midi_host.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
9 #include "base/debug/trace_event.h" | |
10 #include "base/process.h" | |
11 #include "content/browser/browser_main_loop.h" | |
12 #include "content/browser/media/media_internals.h" | |
13 #include "content/common/media/midi_messages.h" | |
14 #include "content/public/browser/content_browser_client.h" | |
15 #include "content/public/browser/media_observer.h" | |
16 #include "media/midi/midi_manager.h" | |
17 | |
18 using media::MIDIManager; | |
19 using media::MIDIPortInfoList; | |
20 | |
21 namespace content { | |
22 | |
23 MIDIHost::MIDIHost(media::MIDIManager* midi_manager) | |
24 : midi_manager_(midi_manager) { | |
scherkus (not reviewing)
2013/06/12 01:28:47
indent two more spaces
Chris Rogers
2013/06/12 20:34:35
Done.
| |
25 } | |
26 | |
27 MIDIHost::~MIDIHost() { | |
28 midi_manager_->ReleaseAccess(this); | |
29 } | |
30 | |
31 void MIDIHost::OnChannelClosing() { | |
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
33 | |
34 BrowserMessageFilter::OnChannelClosing(); | |
35 } | |
36 | |
37 void MIDIHost::OnDestruct() const { | |
38 BrowserThread::DeleteOnIOThread::Destruct(this); | |
39 } | |
40 | |
41 /////////////////////////////////////////////////////////////////////////////// | |
42 // IPC Messages handler | |
43 bool MIDIHost::OnMessageReceived(const IPC::Message& message, | |
44 bool* message_was_ok) { | |
45 bool handled = true; | |
46 IPC_BEGIN_MESSAGE_MAP_EX(MIDIHost, message, *message_was_ok) | |
47 IPC_MESSAGE_HANDLER(MIDIHostMsg_RequestAccess, OnRequestAccess) | |
48 IPC_MESSAGE_HANDLER(MIDIHostMsg_SendData, OnSendData) | |
49 | |
scherkus (not reviewing)
2013/06/12 01:28:47
nit: remove extra blank line
Chris Rogers
2013/06/12 20:34:35
Done.
| |
50 IPC_MESSAGE_UNHANDLED(handled = false) | |
51 IPC_END_MESSAGE_MAP_EX() | |
52 | |
53 return handled; | |
54 } | |
55 | |
56 void MIDIHost::OnRequestAccess(int client_id, int access) { | |
57 MIDIPortInfoList input_ports; | |
58 MIDIPortInfoList output_ports; | |
59 | |
60 // Ask permission and register to receive MIDI data. | |
61 bool approved = midi_manager_->RequestAccess(this, access); | |
62 | |
63 if (approved) { | |
64 input_ports = midi_manager_->input_ports(); | |
65 output_ports = midi_manager_->output_ports(); | |
66 } | |
67 | |
68 Send(new MIDIMsg_AccessApproved( | |
69 client_id, | |
70 access, | |
71 approved, | |
72 input_ports, | |
73 output_ports)); | |
74 } | |
75 | |
76 void MIDIHost::OnSendData(int port, | |
77 const std::vector<uint8>& data, | |
78 double timestamp) { | |
79 midi_manager_->SendMIDIData(port, data.data(), data.size(), timestamp); | |
80 } | |
81 | |
82 void MIDIHost::ReceiveMIDIData( | |
83 int port_index, | |
84 const uint8* data, | |
85 size_t length, | |
86 double timestamp) { | |
87 TRACE_EVENT0("midi", "MIDIHost::ReceiveMIDIData"); | |
88 // Send to the renderer | |
scherkus (not reviewing)
2013/06/12 01:28:47
nit: comments end w/ periods
Chris Rogers
2013/06/12 20:34:35
Done.
| |
89 std::vector<uint8> v(data, data + length); | |
90 Send(new MIDIMsg_DataReceived(port_index, v, timestamp)); | |
91 } | |
92 | |
93 } // namespace content | |
OLD | NEW |