OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 MEDIA_MIDI_MIDI_MANAGER_USB_H_ | 5 #ifndef MEDIA_MIDI_MIDI_MANAGER_USB_H_ |
6 #define MEDIA_MIDI_MIDI_MANAGER_USB_H_ | 6 #define MEDIA_MIDI_MIDI_MANAGER_USB_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
| 11 #include <memory> |
11 #include <utility> | 12 #include <utility> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/bind.h" | 15 #include "base/bind.h" |
15 #include "base/callback.h" | 16 #include "base/callback.h" |
16 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
17 #include "base/containers/hash_tables.h" | 18 #include "base/containers/hash_tables.h" |
18 #include "base/macros.h" | 19 #include "base/macros.h" |
19 #include "base/memory/scoped_ptr.h" | |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "media/midi/midi_manager.h" | 21 #include "media/midi/midi_manager.h" |
22 #include "media/midi/usb_midi_device.h" | 22 #include "media/midi/usb_midi_device.h" |
23 #include "media/midi/usb_midi_export.h" | 23 #include "media/midi/usb_midi_export.h" |
24 #include "media/midi/usb_midi_input_stream.h" | 24 #include "media/midi/usb_midi_input_stream.h" |
25 #include "media/midi/usb_midi_jack.h" | 25 #include "media/midi/usb_midi_jack.h" |
26 #include "media/midi/usb_midi_output_stream.h" | 26 #include "media/midi/usb_midi_output_stream.h" |
27 | 27 |
28 namespace media { | 28 namespace media { |
29 namespace midi { | 29 namespace midi { |
30 | 30 |
31 class MidiScheduler; | 31 class MidiScheduler; |
32 | 32 |
33 // MidiManager for USB-MIDI. | 33 // MidiManager for USB-MIDI. |
34 class USB_MIDI_EXPORT MidiManagerUsb | 34 class USB_MIDI_EXPORT MidiManagerUsb |
35 : public MidiManager, | 35 : public MidiManager, |
36 public UsbMidiDeviceDelegate, | 36 public UsbMidiDeviceDelegate, |
37 NON_EXPORTED_BASE(public UsbMidiInputStream::Delegate) { | 37 NON_EXPORTED_BASE(public UsbMidiInputStream::Delegate) { |
38 public: | 38 public: |
39 explicit MidiManagerUsb(scoped_ptr<UsbMidiDevice::Factory> device_factory); | 39 explicit MidiManagerUsb( |
| 40 std::unique_ptr<UsbMidiDevice::Factory> device_factory); |
40 ~MidiManagerUsb() override; | 41 ~MidiManagerUsb() override; |
41 | 42 |
42 // MidiManager implementation. | 43 // MidiManager implementation. |
43 void StartInitialization() override; | 44 void StartInitialization() override; |
44 void DispatchSendMidiData(MidiManagerClient* client, | 45 void DispatchSendMidiData(MidiManagerClient* client, |
45 uint32_t port_index, | 46 uint32_t port_index, |
46 const std::vector<uint8_t>& data, | 47 const std::vector<uint8_t>& data, |
47 double timestamp) override; | 48 double timestamp) override; |
48 | 49 |
49 // UsbMidiDeviceDelegate implementation. | 50 // UsbMidiDeviceDelegate implementation. |
50 void ReceiveUsbMidiData(UsbMidiDevice* device, | 51 void ReceiveUsbMidiData(UsbMidiDevice* device, |
51 int endpoint_number, | 52 int endpoint_number, |
52 const uint8_t* data, | 53 const uint8_t* data, |
53 size_t size, | 54 size_t size, |
54 base::TimeTicks time) override; | 55 base::TimeTicks time) override; |
55 void OnDeviceAttached(scoped_ptr<UsbMidiDevice> device) override; | 56 void OnDeviceAttached(std::unique_ptr<UsbMidiDevice> device) override; |
56 void OnDeviceDetached(size_t index) override; | 57 void OnDeviceDetached(size_t index) override; |
57 | 58 |
58 // UsbMidiInputStream::Delegate implementation. | 59 // UsbMidiInputStream::Delegate implementation. |
59 void OnReceivedData(size_t jack_index, | 60 void OnReceivedData(size_t jack_index, |
60 const uint8_t* data, | 61 const uint8_t* data, |
61 size_t size, | 62 size_t size, |
62 base::TimeTicks time) override; | 63 base::TimeTicks time) override; |
63 | 64 |
64 const ScopedVector<UsbMidiOutputStream>& output_streams() const { | 65 const ScopedVector<UsbMidiOutputStream>& output_streams() const { |
65 return output_streams_; | 66 return output_streams_; |
66 } | 67 } |
67 const UsbMidiInputStream* input_stream() const { return input_stream_.get(); } | 68 const UsbMidiInputStream* input_stream() const { return input_stream_.get(); } |
68 | 69 |
69 // Initializes this object. | 70 // Initializes this object. |
70 // When the initialization finishes, |callback| will be called with the | 71 // When the initialization finishes, |callback| will be called with the |
71 // result. | 72 // result. |
72 // When this factory is destroyed during the operation, the operation | 73 // When this factory is destroyed during the operation, the operation |
73 // will be canceled silently (i.e. |callback| will not be called). | 74 // will be canceled silently (i.e. |callback| will not be called). |
74 // The function is public just for unit tests. Do not call this function | 75 // The function is public just for unit tests. Do not call this function |
75 // outside code for testing. | 76 // outside code for testing. |
76 void Initialize(base::Callback<void(Result result)> callback); | 77 void Initialize(base::Callback<void(Result result)> callback); |
77 | 78 |
78 private: | 79 private: |
79 void OnEnumerateDevicesDone(bool result, UsbMidiDevice::Devices* devices); | 80 void OnEnumerateDevicesDone(bool result, UsbMidiDevice::Devices* devices); |
80 bool AddPorts(UsbMidiDevice* device, int device_id); | 81 bool AddPorts(UsbMidiDevice* device, int device_id); |
81 | 82 |
82 scoped_ptr<UsbMidiDevice::Factory> device_factory_; | 83 std::unique_ptr<UsbMidiDevice::Factory> device_factory_; |
83 ScopedVector<UsbMidiDevice> devices_; | 84 ScopedVector<UsbMidiDevice> devices_; |
84 ScopedVector<UsbMidiOutputStream> output_streams_; | 85 ScopedVector<UsbMidiOutputStream> output_streams_; |
85 scoped_ptr<UsbMidiInputStream> input_stream_; | 86 std::unique_ptr<UsbMidiInputStream> input_stream_; |
86 | 87 |
87 base::Callback<void(Result result)> initialize_callback_; | 88 base::Callback<void(Result result)> initialize_callback_; |
88 | 89 |
89 // A map from <endpoint_number, cable_number> to the index of input jacks. | 90 // A map from <endpoint_number, cable_number> to the index of input jacks. |
90 base::hash_map<std::pair<int, int>, size_t> input_jack_dictionary_; | 91 base::hash_map<std::pair<int, int>, size_t> input_jack_dictionary_; |
91 | 92 |
92 scoped_ptr<MidiScheduler> scheduler_; | 93 std::unique_ptr<MidiScheduler> scheduler_; |
93 | 94 |
94 DISALLOW_COPY_AND_ASSIGN(MidiManagerUsb); | 95 DISALLOW_COPY_AND_ASSIGN(MidiManagerUsb); |
95 }; | 96 }; |
96 | 97 |
97 } // namespace midi | 98 } // namespace midi |
98 } // namespace media | 99 } // namespace media |
99 | 100 |
100 #endif // MEDIA_MIDI_MIDI_MANAGER_USB_H_ | 101 #endif // MEDIA_MIDI_MIDI_MANAGER_USB_H_ |
OLD | NEW |