1 // Copyright 2014 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.
5 #ifndef MEDIA_MIDI_MIDI_MANAGER_USB_H_
6 #define MEDIA_MIDI_MIDI_MANAGER_USB_H_
11 #include "base/basictypes.h"
12 #include "base/bind.h"
13 #include "base/callback.h"
14 #include "base/compiler_specific.h"
15 #include "base/containers/hash_tables.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/time/time.h"
18 #include "media/midi/midi_manager.h"
19 #include "media/midi/usb_midi_device.h"
20 #include "media/midi/usb_midi_export.h"
21 #include "media/midi/usb_midi_input_stream.h"
22 #include "media/midi/usb_midi_jack.h"
23 #include "media/midi/usb_midi_output_stream.h"
30 // MidiManager for USB-MIDI.
31 class USB_MIDI_EXPORT MidiManagerUsb
33 public UsbMidiDeviceDelegate
,
34 NON_EXPORTED_BASE(public UsbMidiInputStream::Delegate
) {
36 explicit MidiManagerUsb(scoped_ptr
<UsbMidiDevice::Factory
> device_factory
);
37 ~MidiManagerUsb() override
;
39 // MidiManager implementation.
40 void StartInitialization() override
;
41 void DispatchSendMidiData(MidiManagerClient
* client
,
43 const std::vector
<uint8
>& data
,
44 double timestamp
) override
;
46 // UsbMidiDeviceDelegate implementation.
47 void ReceiveUsbMidiData(UsbMidiDevice
* device
,
51 base::TimeTicks time
) override
;
52 void OnDeviceAttached(scoped_ptr
<UsbMidiDevice
> device
) override
;
53 void OnDeviceDetached(size_t index
) override
;
55 // UsbMidiInputStream::Delegate implementation.
56 void OnReceivedData(size_t jack_index
,
59 base::TimeTicks time
) override
;
61 const ScopedVector
<UsbMidiOutputStream
>& output_streams() const {
62 return output_streams_
;
64 const UsbMidiInputStream
* input_stream() const { return input_stream_
.get(); }
66 // Initializes this object.
67 // When the initialization finishes, |callback| will be called with the
69 // When this factory is destroyed during the operation, the operation
70 // will be canceled silently (i.e. |callback| will not be called).
71 // The function is public just for unit tests. Do not call this function
72 // outside code for testing.
73 void Initialize(base::Callback
<void(Result result
)> callback
);
76 void OnEnumerateDevicesDone(bool result
, UsbMidiDevice::Devices
* devices
);
77 bool AddPorts(UsbMidiDevice
* device
, int device_id
);
79 scoped_ptr
<UsbMidiDevice::Factory
> device_factory_
;
80 ScopedVector
<UsbMidiDevice
> devices_
;
81 ScopedVector
<UsbMidiOutputStream
> output_streams_
;
82 scoped_ptr
<UsbMidiInputStream
> input_stream_
;
84 base::Callback
<void(Result result
)> initialize_callback_
;
86 // A map from <endpoint_number, cable_number> to the index of input jacks.
87 base::hash_map
<std::pair
<int, int>, size_t> input_jack_dictionary_
;
89 scoped_ptr
<MidiScheduler
> scheduler_
;
91 DISALLOW_COPY_AND_ASSIGN(MidiManagerUsb
);
97 #endif // MEDIA_MIDI_MIDI_MANAGER_USB_H_