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#ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MIDI_HOST_H_ 6#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MIDI_HOST_H_ 7 8#include "base/memory/ref_counted.h" 9#include "base/memory/scoped_ptr.h" 10#include "content/common/content_export.h" 11#include "content/public/browser/browser_message_filter.h" 12#include "content/public/browser/browser_thread.h" 13#include "media/midi/midi_manager.h" 14 15namespace media { 16class MIDIManager; 17} 18 19namespace content { 20 21class CONTENT_EXPORT MIDIHost 22 : public BrowserMessageFilter, 23 public media::MIDIManagerClient { 24 public: 25 // Called from UI thread from the owner of this object. 26 MIDIHost(media::MIDIManager* midi_manager); 27 28 // BrowserMessageFilter implementation. 29 virtual void OnChannelClosing() OVERRIDE; 30 virtual void OnDestruct() const OVERRIDE; 31 virtual bool OnMessageReceived(const IPC::Message& message, 32 bool* message_was_ok) OVERRIDE; 33 34 // MIDIManagerClient implementation. 35 virtual void ReceiveMIDIData( 36 int port_index, 37 const uint8* data, 38 size_t length, 39 double timestamp) OVERRIDE; 40 virtual void AccumulateMIDIBytesSent(size_t n) OVERRIDE; 41 42 // Start session to access MIDI hardware. 43 void OnStartSession(int client_id); 44 45 // Data to be sent to a MIDI output port. 46 void OnSendData(int port, 47 const std::vector<uint8>& data, 48 double timestamp); 49 50 private: 51 friend class base::DeleteHelper<MIDIHost>; 52 friend class BrowserThread; 53 54 virtual ~MIDIHost(); 55 56 // |midi_manager_| talks to the platform-specific MIDI APIs. 57 // It can be NULL if the platform (or our current implementation) 58 // does not support MIDI. If not supported then a call to 59 // OnRequestAccess() will always refuse access and a call to 60 // OnSendData() will do nothing. 61 media::MIDIManager* const midi_manager_; 62 63 // The number of bytes sent to the platform-specific MIDI sending 64 // system, but not yet completed. 65 size_t sent_bytes_in_flight_; 66 67 // The number of bytes successfully sent since the last time 68 // we've acknowledged back to the renderer. 69 size_t bytes_sent_since_last_acknowledgement_; 70 71 // Protects access to |sent_bytes_in_flight_|. 72 base::Lock in_flight_lock_; 73 74 DISALLOW_COPY_AND_ASSIGN(MIDIHost); 75}; 76 77} // namespace content 78 79#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MIDI_HOST_H_ 80