Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: content/browser/renderer_host/media/midi_host.cc

Issue 16025005: Web MIDI API back-end (work-in-progress) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add stub for non-OSX MIDIManagers Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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) {
25 }
26
27 MIDIHost::~MIDIHost() {
28 if (midi_manager_)
29 midi_manager_->ReleaseAccess(this);
30 }
31
32 void MIDIHost::OnChannelClosing() {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
34
35 BrowserMessageFilter::OnChannelClosing();
36 }
37
38 void MIDIHost::OnDestruct() const {
39 BrowserThread::DeleteOnIOThread::Destruct(this);
40 }
41
42 ///////////////////////////////////////////////////////////////////////////////
43 // IPC Messages handler
44 bool MIDIHost::OnMessageReceived(const IPC::Message& message,
45 bool* message_was_ok) {
46 bool handled = true;
47 IPC_BEGIN_MESSAGE_MAP_EX(MIDIHost, message, *message_was_ok)
48 IPC_MESSAGE_HANDLER(MIDIHostMsg_RequestAccess, OnRequestAccess)
49 IPC_MESSAGE_HANDLER(MIDIHostMsg_SendData, OnSendData)
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 = false;
62 if (midi_manager_) {
63 approved = midi_manager_->RequestAccess(this, access);
64 if (approved) {
65 input_ports = midi_manager_->input_ports();
66 output_ports = midi_manager_->output_ports();
67 }
68 }
69
70 Send(new MIDIMsg_AccessApproved(
71 client_id,
palmer 2013/06/19 21:39:15 Nit: Indent one more space to align with (.
Chris Rogers 2013/06/20 17:41:33 Done.
72 access,
73 approved,
74 input_ports,
75 output_ports));
76 }
77
78 void MIDIHost::OnSendData(int port,
79 const std::vector<uint8>& data,
80 double timestamp) {
81 if (midi_manager_)
82 midi_manager_->SendMIDIData(port, data.data(), data.size(), timestamp);
piman 2013/06/20 20:16:20 High-level question: this runs on the IO thread. C
Chris Rogers 2013/06/21 23:04:11 According to our offline discussion, For now, I'm
83 }
84
85 void MIDIHost::ReceiveMIDIData(
86 int port_index,
87 const uint8* data,
88 size_t length,
89 double timestamp) {
90 TRACE_EVENT0("midi", "MIDIHost::ReceiveMIDIData");
91 // Send to the renderer.
92 std::vector<uint8> v(data, data + length);
palmer 2013/06/19 21:39:15 Yeah, it would seem good to avoid this copy, if po
Chris Rogers 2013/06/20 17:41:33 At the earliest stages, we start with a pointer to
93 Send(new MIDIMsg_DataReceived(port_index, v, timestamp));
94 }
95
96 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698